Sravan Kumar Ambapuram | b22cf4d | 2012-01-02 21:45:04 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2011-2012, Code Aurora Forum. All rights reserved. |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 2 | * |
| 3 | * This program is free software; you can redistribute it and/or modify |
| 4 | * it under the terms of the GNU General Public License version 2 and |
| 5 | * only version 2 as published by the Free Software Foundation. |
| 6 | * |
| 7 | * This program is distributed in the hope that it will be useful, |
| 8 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 10 | * GNU General Public License for more details. |
| 11 | * |
| 12 | */ |
| 13 | |
| 14 | #include <linux/module.h> |
| 15 | #include <linux/kernel.h> |
| 16 | #include <linux/init.h> |
| 17 | #include <linux/io.h> |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 18 | #include <mach/msm_iomap.h> |
| 19 | #include <mach/socinfo.h> |
| 20 | #include <asm/mach-types.h> |
| 21 | #include <asm/sizes.h> |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 22 | #include "scm-boot.h" |
| 23 | #include "idle.h" |
| 24 | #include "pm-boot.h" |
| 25 | |
| 26 | static uint32_t *msm_pm_reset_vector; |
| 27 | static uint32_t saved_vector[2]; |
| 28 | static void (*msm_pm_boot_before_pc)(unsigned int cpu, unsigned long entry); |
| 29 | static void (*msm_pm_boot_after_pc)(unsigned int cpu); |
| 30 | |
| 31 | #ifdef CONFIG_MSM_SCM |
| 32 | static int __init msm_pm_tz_boot_init(void) |
| 33 | { |
| 34 | int flag = 0; |
| 35 | if (num_possible_cpus() == 1) |
| 36 | flag = SCM_FLAG_WARMBOOT_CPU0; |
| 37 | else if (num_possible_cpus() == 2) |
| 38 | flag = SCM_FLAG_WARMBOOT_CPU0 | SCM_FLAG_WARMBOOT_CPU1; |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 39 | else if (num_possible_cpus() == 4) |
| 40 | flag = SCM_FLAG_WARMBOOT_CPU0 | SCM_FLAG_WARMBOOT_CPU1 | |
| 41 | SCM_FLAG_WARMBOOT_CPU2 | SCM_FLAG_WARMBOOT_CPU3; |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 42 | else |
| 43 | __WARN(); |
| 44 | |
| 45 | return scm_set_boot_addr((void *)virt_to_phys(msm_pm_boot_entry), flag); |
| 46 | } |
| 47 | |
| 48 | static void msm_pm_config_tz_before_pc(unsigned int cpu, |
| 49 | unsigned long entry) |
| 50 | { |
| 51 | msm_pm_write_boot_vector(cpu, entry); |
| 52 | } |
| 53 | #else |
| 54 | static int __init msm_pm_tz_boot_init(void) |
| 55 | { |
| 56 | return 0; |
| 57 | }; |
| 58 | |
| 59 | static inline void msm_pm_config_tz_before_pc(unsigned int cpu, |
| 60 | unsigned long entry) {} |
| 61 | #endif |
| 62 | |
| 63 | static int __init msm_pm_boot_reset_vector_init(uint32_t *reset_vector) |
| 64 | { |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 65 | if (!reset_vector) |
| 66 | return -ENODEV; |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 67 | msm_pm_reset_vector = reset_vector; |
| 68 | mb(); |
| 69 | |
| 70 | return 0; |
| 71 | } |
| 72 | |
| 73 | static void msm_pm_config_rst_vector_before_pc(unsigned int cpu, |
| 74 | unsigned long entry) |
| 75 | { |
| 76 | saved_vector[0] = msm_pm_reset_vector[0]; |
| 77 | saved_vector[1] = msm_pm_reset_vector[1]; |
| 78 | msm_pm_reset_vector[0] = 0xE51FF004; /* ldr pc, 4 */ |
| 79 | msm_pm_reset_vector[1] = entry; |
| 80 | } |
| 81 | |
| 82 | static void msm_pm_config_rst_vector_after_pc(unsigned int cpu) |
| 83 | { |
| 84 | msm_pm_reset_vector[0] = saved_vector[0]; |
| 85 | msm_pm_reset_vector[1] = saved_vector[1]; |
| 86 | } |
| 87 | |
| 88 | void msm_pm_boot_config_before_pc(unsigned int cpu, unsigned long entry) |
| 89 | { |
| 90 | if (msm_pm_boot_before_pc) |
| 91 | msm_pm_boot_before_pc(cpu, entry); |
| 92 | } |
| 93 | |
| 94 | void msm_pm_boot_config_after_pc(unsigned int cpu) |
| 95 | { |
| 96 | if (msm_pm_boot_after_pc) |
| 97 | msm_pm_boot_after_pc(cpu); |
| 98 | } |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 99 | #define BOOT_REMAP_ENABLE BIT(0) |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 100 | |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 101 | int __init msm_pm_boot_init(struct msm_pm_boot_platform_data *pdata) |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 102 | { |
| 103 | int ret = 0; |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 104 | unsigned long entry; |
Murali Nalajala | feedeae | 2012-03-28 16:15:32 +0530 | [diff] [blame] | 105 | void __iomem *warm_boot_ptr; |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 106 | |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 107 | switch (pdata->mode) { |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 108 | case MSM_PM_BOOT_CONFIG_TZ: |
| 109 | ret = msm_pm_tz_boot_init(); |
| 110 | msm_pm_boot_before_pc = msm_pm_config_tz_before_pc; |
| 111 | msm_pm_boot_after_pc = NULL; |
| 112 | break; |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 113 | case MSM_PM_BOOT_CONFIG_RESET_VECTOR_PHYS: |
Maheshkumar Sivasubramanian | c6c5503 | 2011-10-25 16:01:32 -0600 | [diff] [blame] | 114 | pdata->v_addr = ioremap(pdata->p_addr, PAGE_SIZE); |
| 115 | /* Fall through */ |
| 116 | case MSM_PM_BOOT_CONFIG_RESET_VECTOR_VIRT: |
| 117 | |
| 118 | if (!pdata->v_addr) |
| 119 | return -ENODEV; |
| 120 | |
| 121 | ret = msm_pm_boot_reset_vector_init(pdata->v_addr); |
| 122 | msm_pm_boot_before_pc |
| 123 | = msm_pm_config_rst_vector_before_pc; |
| 124 | msm_pm_boot_after_pc |
| 125 | = msm_pm_config_rst_vector_after_pc; |
| 126 | break; |
| 127 | case MSM_PM_BOOT_CONFIG_REMAP_BOOT_ADDR: |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 128 | if (!cpu_is_msm8625()) { |
Olav Haugan | e6a0acd | 2012-04-05 09:29:12 -0700 | [diff] [blame^] | 129 | void *remapped; |
| 130 | |
Murali Nalajala | feedeae | 2012-03-28 16:15:32 +0530 | [diff] [blame] | 131 | /* |
| 132 | * Set the boot remap address and enable remapping of |
| 133 | * reset vector |
| 134 | */ |
| 135 | if (!pdata->p_addr || !pdata->v_addr) |
| 136 | return -ENODEV; |
| 137 | |
Olav Haugan | e6a0acd | 2012-04-05 09:29:12 -0700 | [diff] [blame^] | 138 | remapped = ioremap_nocache(pdata->p_addr, SZ_8); |
| 139 | ret = msm_pm_boot_reset_vector_init(remapped); |
Murali Nalajala | feedeae | 2012-03-28 16:15:32 +0530 | [diff] [blame] | 140 | |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 141 | __raw_writel((pdata->p_addr | BOOT_REMAP_ENABLE), |
| 142 | pdata->v_addr); |
| 143 | |
| 144 | msm_pm_boot_before_pc |
| 145 | = msm_pm_config_rst_vector_before_pc; |
| 146 | msm_pm_boot_after_pc |
| 147 | = msm_pm_config_rst_vector_after_pc; |
| 148 | } else { |
Murali Nalajala | feedeae | 2012-03-28 16:15:32 +0530 | [diff] [blame] | 149 | warm_boot_ptr = ioremap_nocache( |
| 150 | MSM8625_WARM_BOOT_PHYS, SZ_64); |
| 151 | ret = msm_pm_boot_reset_vector_init(warm_boot_ptr); |
| 152 | |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 153 | entry = virt_to_phys(msm_pm_boot_entry); |
| 154 | |
Murali Nalajala | b99ce12 | 2012-03-21 00:40:40 +0530 | [diff] [blame] | 155 | /* Below sequence is a work around for cores |
| 156 | * to come out of GDFS properly on 8625 target. |
| 157 | * On 8625 while cores coming out of GDFS observed |
| 158 | * the memory corruption at very first memory read. |
| 159 | */ |
| 160 | msm_pm_reset_vector[0] = 0xE59F000C; /* ldr r0, 0x14 */ |
| 161 | msm_pm_reset_vector[1] = 0xE59F1008; /* ldr r1, 0x14 */ |
| 162 | msm_pm_reset_vector[2] = 0xE1500001; /* cmp r0, r1 */ |
| 163 | msm_pm_reset_vector[3] = 0x1AFFFFFB; /* bne 0x0 */ |
| 164 | msm_pm_reset_vector[4] = 0xE12FFF10; /* bx r0 */ |
| 165 | msm_pm_reset_vector[5] = entry; /* 0x14 */ |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 166 | |
| 167 | /* Here upper 16bits[16:31] used by CORE1 |
| 168 | * lower 16bits[0:15] used by CORE0 |
| 169 | */ |
Murali Nalajala | feedeae | 2012-03-28 16:15:32 +0530 | [diff] [blame] | 170 | entry = (MSM8625_WARM_BOOT_PHYS | |
| 171 | ((MSM8625_WARM_BOOT_PHYS & 0xFFFF0000) >> 16)); |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 172 | |
| 173 | /* write 'entry' to boot remapper register */ |
| 174 | __raw_writel(entry, (pdata->v_addr + |
| 175 | MPA5_BOOT_REMAP_ADDR)); |
| 176 | |
| 177 | /* Enable boot remapper for C0 [bit:25th] */ |
| 178 | __raw_writel(readl_relaxed(pdata->v_addr + |
| 179 | MPA5_CFG_CTL_REG) | BIT(25), |
| 180 | pdata->v_addr + MPA5_CFG_CTL_REG); |
| 181 | |
| 182 | /* Enable boot remapper for C1 [bit:26th] */ |
| 183 | __raw_writel(readl_relaxed(pdata->v_addr + |
| 184 | MPA5_CFG_CTL_REG) | BIT(26), |
| 185 | pdata->v_addr + MPA5_CFG_CTL_REG); |
Murali Nalajala | 41786ab | 2012-03-06 10:47:32 +0530 | [diff] [blame] | 186 | } |
Maheshkumar Sivasubramanian | 8ccc16e | 2011-10-25 15:59:57 -0600 | [diff] [blame] | 187 | break; |
| 188 | default: |
| 189 | __WARN(); |
| 190 | } |
| 191 | |
| 192 | return ret; |
| 193 | } |