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