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