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