Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 1 | /* Copyright (c) 2012, Code Aurora Forum. All rights reserved. |
| 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 | #include <linux/init.h> |
| 14 | #include <linux/errno.h> |
| 15 | #include <linux/delay.h> |
| 16 | #include <linux/device.h> |
| 17 | #include <linux/jiffies.h> |
| 18 | #include <linux/smp.h> |
| 19 | #include <linux/io.h> |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 20 | #include <linux/interrupt.h> |
Michael Bohan | bb6b30f | 2012-06-01 13:33:51 -0700 | [diff] [blame] | 21 | #include <linux/irq.h> |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 22 | |
| 23 | #include <asm/cacheflush.h> |
| 24 | #include <asm/hardware/gic.h> |
| 25 | #include <asm/hardware/cache-l2x0.h> |
| 26 | #include <asm/smp_scu.h> |
| 27 | #include <asm/unified.h> |
| 28 | #include <mach/msm_iomap.h> |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 29 | #include "pm.h" |
| 30 | |
| 31 | #define MSM_CORE1_RESET 0xA8600590 |
Taniya Das | 63da646 | 2012-02-27 17:22:11 +0530 | [diff] [blame] | 32 | #define MSM_CORE1_STATUS_MSK 0x02800000 |
| 33 | |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 34 | /* |
| 35 | * control for which core is the next to come out of the secondary |
| 36 | * boot "holding pen" |
| 37 | */ |
| 38 | int pen_release = -1; |
| 39 | |
| 40 | static bool cold_boot_done; |
| 41 | |
| 42 | static uint32_t *msm8625_boot_vector; |
Taniya Das | 94b8ecb | 2012-05-17 18:14:37 +0530 | [diff] [blame] | 43 | static void __iomem *reset_core1_base; |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 44 | |
| 45 | /* |
| 46 | * Write pen_release in a way that is guaranteed to be visible to all |
| 47 | * observers, irrespective of whether they're taking part in coherency |
| 48 | * or not. This is necessary for the hotplug code to work reliably. |
| 49 | */ |
| 50 | static void __cpuinit write_pen_release(int val) |
| 51 | { |
| 52 | pen_release = val; |
| 53 | smp_wmb(); |
| 54 | __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release)); |
| 55 | outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1)); |
| 56 | } |
| 57 | |
| 58 | static void __iomem *scu_base_addr(void) |
| 59 | { |
| 60 | return MSM_SCU_BASE; |
| 61 | } |
| 62 | |
| 63 | static DEFINE_SPINLOCK(boot_lock); |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 64 | |
| 65 | /* |
| 66 | * MP_CORE_IPC will be used to generate interrupt and can be used by either |
| 67 | * of core. |
| 68 | * To bring core1 out of GDFS we need to raise the SPI using the MP_CORE_IPC. |
| 69 | */ |
| 70 | static void raise_clear_spi(unsigned int cpu, bool set) |
| 71 | { |
| 72 | int value; |
| 73 | |
| 74 | value = __raw_readl(MSM_CSR_BASE + 0x54); |
| 75 | if (set) |
| 76 | __raw_writel(value | BIT(cpu), MSM_CSR_BASE + 0x54); |
| 77 | else |
| 78 | __raw_writel(value & ~BIT(cpu), MSM_CSR_BASE + 0x54); |
| 79 | mb(); |
| 80 | } |
| 81 | |
Murali Nalajala | a30aad0 | 2012-04-17 16:20:14 +0530 | [diff] [blame] | 82 | static void clear_pending_spi(unsigned int irq) |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 83 | { |
Taniya Das | 1816eb4 | 2012-05-01 19:13:11 +0530 | [diff] [blame] | 84 | struct irq_data *d = irq_get_irq_data(irq); |
| 85 | struct irq_chip *c = irq_data_get_irq_chip(d); |
| 86 | |
| 87 | c->irq_mask(d); |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 88 | local_irq_disable(); |
Taniya Das | 1816eb4 | 2012-05-01 19:13:11 +0530 | [diff] [blame] | 89 | /* Clear the IRQ from the ENABLE_SET */ |
Trilok Soni | 01dbb61 | 2012-05-28 19:23:53 +0530 | [diff] [blame] | 90 | gic_clear_irq_pending(irq); |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 91 | local_irq_enable(); |
| 92 | } |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 93 | |
| 94 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 95 | { |
Murali Nalajala | a7efba1 | 2012-02-23 18:13:52 +0530 | [diff] [blame] | 96 | pr_debug("CPU%u: Booted secondary processor\n", cpu); |
| 97 | |
| 98 | WARN_ON(msm_platform_secondary_init(cpu)); |
| 99 | |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 100 | /* |
| 101 | * if any interrupts are already enabled for the primary |
| 102 | * core (e.g. timer irq), then they will not have been enabled |
| 103 | * for us: do so |
| 104 | */ |
| 105 | gic_secondary_init(0); |
| 106 | |
| 107 | /* |
| 108 | * let the primary processor know we're out of the |
| 109 | * pen, then head off into the C entry point |
| 110 | */ |
| 111 | write_pen_release(-1); |
| 112 | |
Murali Nalajala | a30aad0 | 2012-04-17 16:20:14 +0530 | [diff] [blame] | 113 | /* clear the IPC1(SPI-8) pending SPI */ |
| 114 | if (power_collapsed) { |
| 115 | raise_clear_spi(1, false); |
| 116 | clear_pending_spi(MSM8625_INT_ACSR_MP_CORE_IPC1); |
| 117 | power_collapsed = 0; |
| 118 | } |
| 119 | |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 120 | /* |
| 121 | * Synchronise with the boot thread. |
| 122 | */ |
| 123 | spin_lock(&boot_lock); |
| 124 | spin_unlock(&boot_lock); |
| 125 | } |
| 126 | |
Taniya Das | 63da646 | 2012-02-27 17:22:11 +0530 | [diff] [blame] | 127 | static int __cpuinit msm8625_release_secondary(void) |
| 128 | { |
| 129 | void __iomem *base_ptr; |
| 130 | int value = 0; |
| 131 | unsigned long timeout; |
| 132 | |
| 133 | /* |
| 134 | * loop to ensure that the GHS_STATUS_CORE1 bit in the |
| 135 | * MPA5_STATUS_REG(0x3c) is set. The timeout for the while |
| 136 | * loop can be set as 20us as of now |
| 137 | */ |
| 138 | timeout = jiffies + usecs_to_jiffies(20); |
| 139 | while (time_before(jiffies, timeout)) { |
| 140 | value = __raw_readl(MSM_CFG_CTL_BASE + 0x3c); |
| 141 | if ((value & MSM_CORE1_STATUS_MSK) == |
| 142 | MSM_CORE1_STATUS_MSK) |
| 143 | break; |
| 144 | udelay(1); |
| 145 | } |
| 146 | |
| 147 | if (!value) { |
| 148 | pr_err("Core 1 cannot be brought out of Reset!!!\n"); |
| 149 | return -ENODEV; |
| 150 | } |
| 151 | |
| 152 | base_ptr = ioremap_nocache(MSM_CORE1_RESET, SZ_4); |
| 153 | if (!base_ptr) |
| 154 | return -ENODEV; |
| 155 | /* Reset core 1 out of reset */ |
| 156 | __raw_writel(0x0, base_ptr); |
| 157 | mb(); |
| 158 | |
Taniya Das | 94b8ecb | 2012-05-17 18:14:37 +0530 | [diff] [blame] | 159 | reset_core1_base = base_ptr; |
Taniya Das | 63da646 | 2012-02-27 17:22:11 +0530 | [diff] [blame] | 160 | |
| 161 | return 0; |
| 162 | } |
| 163 | |
Taniya Das | 94b8ecb | 2012-05-17 18:14:37 +0530 | [diff] [blame] | 164 | void __iomem *core1_reset_base(void) |
| 165 | { |
| 166 | return reset_core1_base; |
| 167 | } |
| 168 | |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 169 | int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 170 | { |
| 171 | unsigned long timeout; |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 172 | |
Krishna Vanka | fef8e2b | 2012-05-24 18:00:20 +0530 | [diff] [blame] | 173 | preset_lpj = loops_per_jiffy; |
| 174 | |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 175 | if (cold_boot_done == false) { |
Taniya Das | 63da646 | 2012-02-27 17:22:11 +0530 | [diff] [blame] | 176 | if (msm8625_release_secondary()) { |
| 177 | pr_err("Failed to release secondary core\n"); |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 178 | return -ENODEV; |
Taniya Das | 63da646 | 2012-02-27 17:22:11 +0530 | [diff] [blame] | 179 | } |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 180 | cold_boot_done = true; |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /* |
| 184 | * Set synchronisation state between this boot processor |
| 185 | * and the secondary one |
| 186 | */ |
| 187 | spin_lock(&boot_lock); |
| 188 | |
| 189 | /* |
| 190 | * This is really belt and braces; we hold unintended secondary |
| 191 | * CPUs in the holding pen until we're ready for them. However, |
| 192 | * since we haven't sent them a soft interrupt, they shouldn't |
| 193 | * be there. |
| 194 | */ |
| 195 | write_pen_release(cpu); |
| 196 | |
| 197 | /* |
| 198 | * Send the secondary CPU a soft interrupt, thereby causing |
| 199 | * the boot monitor to read the system wide flags register, |
| 200 | * and branch to the address found there. |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 201 | * |
| 202 | * power_collapsed is the flag which will be updated for Powercollapse. |
| 203 | * Once we are out of PC, as Core1 will be in the state of GDFS which |
| 204 | * needs to be brought out by raising an SPI. |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 205 | */ |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 206 | |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 207 | if (power_collapsed) { |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 208 | core1_gic_configure_and_raise(); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 209 | raise_clear_spi(1, true); |
| 210 | } else { |
Taniya Das | e30a6b2 | 2012-03-20 11:37:45 +0530 | [diff] [blame] | 211 | gic_raise_softirq(cpumask_of(cpu), 1); |
Taniya Das | bc9248a | 2012-04-30 19:59:11 +0530 | [diff] [blame] | 212 | } |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 213 | |
| 214 | timeout = jiffies + (1 * HZ); |
| 215 | while (time_before(jiffies, timeout)) { |
| 216 | smp_rmb(); |
| 217 | if (pen_release == -1) |
| 218 | break; |
| 219 | |
| 220 | udelay(10); |
| 221 | } |
| 222 | |
| 223 | /* |
| 224 | * now the secondary core is starting up let it run its |
| 225 | * calibrations, then wait for it to finish |
| 226 | */ |
| 227 | spin_unlock(&boot_lock); |
| 228 | |
| 229 | return 0; |
| 230 | } |
| 231 | |
| 232 | /* |
| 233 | * Initialise the CPU possible map early - this describes the CPUs |
| 234 | * which may be present or become present in the system. |
| 235 | */ |
| 236 | void __init smp_init_cpus(void) |
| 237 | { |
| 238 | void __iomem *scu_base = scu_base_addr(); |
| 239 | |
| 240 | unsigned int i, ncores; |
| 241 | |
| 242 | ncores = scu_base ? scu_get_core_count(scu_base) : 1; |
| 243 | |
| 244 | for (i = 0; i < ncores; i++) |
| 245 | set_cpu_possible(i, true); |
| 246 | |
| 247 | set_smp_cross_call(gic_raise_softirq); |
| 248 | } |
| 249 | |
| 250 | static void __init msm8625_boot_vector_init(uint32_t *boot_vector, |
| 251 | unsigned long entry) |
| 252 | { |
| 253 | if (!boot_vector) |
| 254 | return; |
| 255 | msm8625_boot_vector = boot_vector; |
| 256 | |
| 257 | msm8625_boot_vector[0] = 0xE51FF004; /* ldr pc, 4 */ |
| 258 | msm8625_boot_vector[1] = entry; |
| 259 | } |
| 260 | |
| 261 | void __init platform_smp_prepare_cpus(unsigned int max_cpus) |
| 262 | { |
| 263 | int i, value; |
Taniya Das | fe04d4f | 2012-03-14 11:13:21 +0530 | [diff] [blame] | 264 | void __iomem *second_ptr; |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 265 | |
| 266 | /* |
| 267 | * Initialise the present map, which describes the set of CPUs |
| 268 | * actually populated at the present time. |
| 269 | */ |
| 270 | for (i = 0; i < max_cpus; i++) |
| 271 | set_cpu_present(i, true); |
| 272 | |
| 273 | scu_enable(scu_base_addr()); |
| 274 | |
| 275 | /* |
| 276 | * Write the address of secondary startup into the |
| 277 | * boot remapper register. The secondary CPU branches to this address. |
| 278 | */ |
Taniya Das | fe04d4f | 2012-03-14 11:13:21 +0530 | [diff] [blame] | 279 | __raw_writel(MSM8625_SECONDARY_PHYS, (MSM_CFG_CTL_BASE + 0x34)); |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 280 | mb(); |
| 281 | |
Taniya Das | fe04d4f | 2012-03-14 11:13:21 +0530 | [diff] [blame] | 282 | second_ptr = ioremap_nocache(MSM8625_SECONDARY_PHYS, SZ_8); |
| 283 | if (!second_ptr) { |
| 284 | pr_err("failed to ioremap for secondary core\n"); |
| 285 | return; |
| 286 | } |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 287 | |
Taniya Das | fe04d4f | 2012-03-14 11:13:21 +0530 | [diff] [blame] | 288 | msm8625_boot_vector_init(second_ptr, |
| 289 | virt_to_phys(msm_secondary_startup)); |
| 290 | iounmap(second_ptr); |
Taniya Das | 137dc8e | 2011-12-02 14:50:00 +0530 | [diff] [blame] | 291 | |
| 292 | /* Enable boot remapper address: bit 26 for core1 */ |
| 293 | value = __raw_readl(MSM_CFG_CTL_BASE + 0x30); |
| 294 | __raw_writel(value | (0x4 << 24), MSM_CFG_CTL_BASE + 0x30) ; |
| 295 | mb(); |
| 296 | } |