Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (C) 2002 ARM Ltd. |
| 3 | * All Rights Reserved |
Duy Truong | e833aca | 2013-02-12 13:35:08 -0800 | [diff] [blame] | 4 | * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved. |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License version 2 as |
| 8 | * published by the Free Software Foundation. |
| 9 | */ |
| 10 | |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 11 | #include <linux/kernel.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 12 | #include <linux/init.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 13 | #include <linux/cpumask.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 14 | #include <linux/delay.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 15 | #include <linux/interrupt.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 16 | #include <linux/io.h> |
Stepan Moskovchenko | 6b1d5df | 2012-08-11 22:33:20 -0700 | [diff] [blame] | 17 | #include <linux/regulator/krait-regulator.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 18 | |
| 19 | #include <asm/hardware/gic.h> |
| 20 | #include <asm/cacheflush.h> |
Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 21 | #include <asm/cputype.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 22 | #include <asm/mach-types.h> |
Will Deacon | eb50439 | 2012-01-20 12:01:12 +0100 | [diff] [blame] | 23 | #include <asm/smp_plat.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 24 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 25 | #include <mach/socinfo.h> |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 26 | #include <mach/hardware.h> |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 27 | #include <mach/msm_iomap.h> |
| 28 | |
Matt Wagantall | 7cca464 | 2012-02-01 16:43:24 -0800 | [diff] [blame] | 29 | #include "pm.h" |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 30 | #include "scm-boot.h" |
Stepan Moskovchenko | 9bbe585 | 2012-01-09 13:28:28 -0800 | [diff] [blame] | 31 | #include "spm.h" |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 32 | |
| 33 | #define VDD_SC1_ARRAY_CLAMP_GFS_CTL 0x15A0 |
| 34 | #define SCSS_CPU1CORE_RESET 0xD80 |
| 35 | #define SCSS_DBG_STATUS_CORE_PWRDUP 0xE64 |
| 36 | |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 37 | extern void msm_secondary_startup(void); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 38 | |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 39 | /* |
| 40 | * control for which core is the next to come out of the secondary |
| 41 | * boot "holding pen". |
| 42 | */ |
| 43 | volatile int pen_release = -1; |
| 44 | |
Stephen Boyd | 3cfde2b | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 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 | |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 58 | static DEFINE_SPINLOCK(boot_lock); |
| 59 | |
| 60 | void __cpuinit platform_secondary_init(unsigned int cpu) |
| 61 | { |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 62 | WARN_ON(msm_platform_secondary_init(cpu)); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 63 | |
| 64 | /* |
| 65 | * if any interrupts are already enabled for the primary |
| 66 | * core (e.g. timer irq), then they will not have been enabled |
| 67 | * for us: do so |
| 68 | */ |
| 69 | gic_secondary_init(0); |
| 70 | |
| 71 | /* |
Stephen Boyd | 3cfde2b | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 72 | * let the primary processor know we're out of the |
| 73 | * pen, then head off into the C entry point |
| 74 | */ |
| 75 | write_pen_release(-1); |
| 76 | |
| 77 | /* |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 78 | * Synchronise with the boot thread. |
| 79 | */ |
| 80 | spin_lock(&boot_lock); |
| 81 | spin_unlock(&boot_lock); |
| 82 | } |
| 83 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 84 | static int __cpuinit scorpion_release_secondary(void) |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 85 | { |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 86 | void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2); |
| 87 | if (!base_ptr) |
| 88 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 89 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 90 | writel_relaxed(0, base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 91 | dmb(); |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 92 | writel_relaxed(0, base_ptr + SCSS_CPU1CORE_RESET); |
| 93 | writel_relaxed(3, base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 94 | mb(); |
| 95 | iounmap(base_ptr); |
| 96 | |
| 97 | return 0; |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 98 | } |
| 99 | |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 100 | static int __cpuinit krait_release_secondary_sim(unsigned long base, int cpu) |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 101 | { |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 102 | void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 103 | if (!base_ptr) |
| 104 | return -ENODEV; |
| 105 | |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 106 | if (machine_is_msm8974_sim()) { |
Sathish Ambley | cf59197 | 2012-04-26 16:24:15 -0700 | [diff] [blame] | 107 | writel_relaxed(0x800, base_ptr+0x04); |
| 108 | writel_relaxed(0x3FFF, base_ptr+0x14); |
| 109 | } |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 110 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 111 | mb(); |
| 112 | iounmap(base_ptr); |
| 113 | return 0; |
| 114 | } |
| 115 | |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 116 | static int __cpuinit krait_release_secondary(unsigned long base, int cpu) |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 117 | { |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 118 | void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 119 | if (!base_ptr) |
| 120 | return -ENODEV; |
| 121 | |
Stepan Moskovchenko | 9bbe585 | 2012-01-09 13:28:28 -0800 | [diff] [blame] | 122 | msm_spm_turn_on_cpu_rail(cpu); |
| 123 | |
Stepan Moskovchenko | d4109b1 | 2012-12-11 18:33:07 -0800 | [diff] [blame] | 124 | writel_relaxed(0x109, base_ptr+0x04); |
| 125 | writel_relaxed(0x101, base_ptr+0x04); |
| 126 | mb(); |
| 127 | ndelay(300); |
| 128 | |
| 129 | writel_relaxed(0x121, base_ptr+0x04); |
Stepan Moskovchenko | b1c9ba2 | 2012-08-16 21:10:13 -0700 | [diff] [blame] | 130 | mb(); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 131 | udelay(2); |
| 132 | |
Stepan Moskovchenko | d4109b1 | 2012-12-11 18:33:07 -0800 | [diff] [blame] | 133 | writel_relaxed(0x120, base_ptr+0x04); |
Stepan Moskovchenko | b1c9ba2 | 2012-08-16 21:10:13 -0700 | [diff] [blame] | 134 | mb(); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 135 | udelay(2); |
| 136 | |
Stepan Moskovchenko | d4109b1 | 2012-12-11 18:33:07 -0800 | [diff] [blame] | 137 | writel_relaxed(0x100, base_ptr+0x04); |
Stepan Moskovchenko | b1c9ba2 | 2012-08-16 21:10:13 -0700 | [diff] [blame] | 138 | mb(); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 139 | udelay(100); |
| 140 | |
Stepan Moskovchenko | d4109b1 | 2012-12-11 18:33:07 -0800 | [diff] [blame] | 141 | writel_relaxed(0x180, base_ptr+0x04); |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 142 | mb(); |
| 143 | iounmap(base_ptr); |
| 144 | return 0; |
| 145 | } |
| 146 | |
Stepan Moskovchenko | 2517372 | 2012-08-09 13:43:02 -0700 | [diff] [blame] | 147 | static int __cpuinit krait_release_secondary_p3(unsigned long base, int cpu) |
| 148 | { |
| 149 | void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K); |
| 150 | if (!base_ptr) |
| 151 | return -ENODEV; |
| 152 | |
Stepan Moskovchenko | 6b1d5df | 2012-08-11 22:33:20 -0700 | [diff] [blame] | 153 | secondary_cpu_hs_init(base_ptr); |
| 154 | |
Stepan Moskovchenko | 2517372 | 2012-08-09 13:43:02 -0700 | [diff] [blame] | 155 | writel_relaxed(0x021, base_ptr+0x04); |
| 156 | mb(); |
| 157 | udelay(2); |
| 158 | |
| 159 | writel_relaxed(0x020, base_ptr+0x04); |
| 160 | mb(); |
| 161 | udelay(2); |
| 162 | |
| 163 | writel_relaxed(0x000, base_ptr+0x04); |
| 164 | mb(); |
| 165 | |
| 166 | writel_relaxed(0x080, base_ptr+0x04); |
| 167 | mb(); |
| 168 | iounmap(base_ptr); |
| 169 | return 0; |
| 170 | } |
| 171 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 172 | static int __cpuinit release_secondary(unsigned int cpu) |
| 173 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 174 | BUG_ON(cpu >= get_core_count()); |
| 175 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 176 | if (cpu_is_msm8x60()) |
| 177 | return scorpion_release_secondary(); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 178 | |
Abhimanyu Kapur | 90ced6e | 2012-06-26 17:41:25 -0700 | [diff] [blame] | 179 | if (machine_is_msm8974_sim()) |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 180 | return krait_release_secondary_sim(0xf9088000, cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 181 | |
Stepan Moskovchenko | c6a603a | 2012-09-21 20:32:17 -0700 | [diff] [blame] | 182 | if (soc_class_is_msm8960() || soc_class_is_msm8930() || |
| 183 | soc_class_is_apq8064()) |
Sathish Ambley | 576a697 | 2012-03-20 12:38:45 -0700 | [diff] [blame] | 184 | return krait_release_secondary(0x02088000, cpu); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 185 | |
Stepan Moskovchenko | 2517372 | 2012-08-09 13:43:02 -0700 | [diff] [blame] | 186 | if (cpu_is_msm8974()) |
| 187 | return krait_release_secondary_p3(0xf9088000, cpu); |
| 188 | |
Stepan Moskovchenko | 964e103 | 2012-01-06 18:16:10 -0800 | [diff] [blame] | 189 | WARN(1, "unknown CPU case in release_secondary\n"); |
| 190 | return -EINVAL; |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 193 | DEFINE_PER_CPU(int, cold_boot_done); |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 194 | static int cold_boot_flags[] = { |
| 195 | 0, |
| 196 | SCM_FLAG_COLDBOOT_CPU1, |
| 197 | SCM_FLAG_COLDBOOT_CPU2, |
| 198 | SCM_FLAG_COLDBOOT_CPU3, |
| 199 | }; |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 200 | |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 201 | int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle) |
| 202 | { |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 203 | int ret; |
Stephen Boyd | 3713928 | 2012-08-08 15:22:04 -0700 | [diff] [blame] | 204 | unsigned int flag = 0; |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 205 | unsigned long timeout; |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 206 | |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 207 | pr_debug("Starting secondary CPU %d\n", cpu); |
| 208 | |
| 209 | /* Set preset_lpj to avoid subsequent lpj recalculations */ |
| 210 | preset_lpj = loops_per_jiffy; |
| 211 | |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 212 | if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags)) |
| 213 | flag = cold_boot_flags[cpu]; |
| 214 | else |
| 215 | __WARN(); |
| 216 | |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 217 | if (per_cpu(cold_boot_done, cpu) == false) { |
Stephen Boyd | 3713928 | 2012-08-08 15:22:04 -0700 | [diff] [blame] | 218 | ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup), |
Joel King | 274621c | 2011-12-05 06:18:20 -0800 | [diff] [blame] | 219 | flag); |
Bryan Huntsman | 3f2bc4d | 2011-08-16 17:27:22 -0700 | [diff] [blame] | 220 | if (ret == 0) |
| 221 | release_secondary(cpu); |
| 222 | else |
| 223 | printk(KERN_DEBUG "Failed to set secondary core boot " |
| 224 | "address\n"); |
Stepan Moskovchenko | 20a1233 | 2011-09-13 13:54:59 -0700 | [diff] [blame] | 225 | per_cpu(cold_boot_done, cpu) = true; |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 226 | } |
| 227 | |
| 228 | /* |
| 229 | * set synchronisation state between this boot processor |
| 230 | * and the secondary one |
| 231 | */ |
| 232 | spin_lock(&boot_lock); |
| 233 | |
| 234 | /* |
| 235 | * The secondary processor is waiting to be released from |
| 236 | * the holding pen - release it, then wait for it to flag |
| 237 | * that it has been released by resetting pen_release. |
| 238 | * |
| 239 | * Note that "pen_release" is the hardware CPU ID, whereas |
| 240 | * "cpu" is Linux's internal ID. |
| 241 | */ |
Stephen Boyd | 3cfde2b | 2012-08-08 13:36:15 -0700 | [diff] [blame] | 242 | write_pen_release(cpu_logical_map(cpu)); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 243 | |
| 244 | /* |
| 245 | * Send the secondary CPU a soft interrupt, thereby causing |
| 246 | * the boot monitor to read the system wide flags register, |
| 247 | * and branch to the address found there. |
| 248 | */ |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 249 | gic_raise_softirq(cpumask_of(cpu), 1); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 250 | |
| 251 | timeout = jiffies + (1 * HZ); |
| 252 | while (time_before(jiffies, timeout)) { |
| 253 | smp_rmb(); |
| 254 | if (pen_release == -1) |
| 255 | break; |
| 256 | |
| 257 | udelay(10); |
| 258 | } |
| 259 | |
| 260 | /* |
| 261 | * now the secondary core is starting up let it run its |
| 262 | * calibrations, then wait for it to finish |
| 263 | */ |
| 264 | spin_unlock(&boot_lock); |
| 265 | |
| 266 | return pen_release != -1 ? -ENOSYS : 0; |
| 267 | } |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 268 | /* |
| 269 | * Initialise the CPU possible map early - this describes the CPUs |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 270 | * which may be present or become present in the system. |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 271 | */ |
| 272 | void __init smp_init_cpus(void) |
| 273 | { |
Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 274 | unsigned int i, ncores = get_core_count(); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 275 | |
Russell King | a06f916 | 2011-10-20 22:04:18 +0100 | [diff] [blame] | 276 | if (ncores > nr_cpu_ids) { |
| 277 | pr_warn("SMP: %u cores greater than maximum (%u), clipping\n", |
| 278 | ncores, nr_cpu_ids); |
| 279 | ncores = nr_cpu_ids; |
| 280 | } |
| 281 | |
Jeff Ohlstein | 41ff445 | 2011-04-07 17:41:09 -0700 | [diff] [blame] | 282 | for (i = 0; i < ncores; i++) |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 283 | set_cpu_possible(i, true); |
Russell King | 0f7b332 | 2011-04-03 13:01:30 +0100 | [diff] [blame] | 284 | |
Steve Muckle | f132c6c | 2012-06-06 18:30:57 -0700 | [diff] [blame] | 285 | set_smp_cross_call(gic_raise_softirq); |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 286 | } |
| 287 | |
| 288 | void __init platform_smp_prepare_cpus(unsigned int max_cpus) |
| 289 | { |
Jeff Ohlstein | e14411d | 2010-11-30 13:06:36 -0800 | [diff] [blame] | 290 | } |