blob: d3c77972c7597168893284b74825ce1b11feecf1 [file] [log] [blame]
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
Duy Truonge833aca2013-02-12 13:35:08 -08004 * Copyright (c) 2010-2012, The Linux Foundation. All rights reserved.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08005 *
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 King274621c2011-12-05 06:18:20 -080011#include <linux/kernel.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080012#include <linux/init.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070013#include <linux/cpumask.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080014#include <linux/delay.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070015#include <linux/interrupt.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080016#include <linux/io.h>
Stepan Moskovchenko6b1d5df2012-08-11 22:33:20 -070017#include <linux/regulator/krait-regulator.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080018
19#include <asm/hardware/gic.h>
20#include <asm/cacheflush.h>
Jeff Ohlstein41ff4452011-04-07 17:41:09 -070021#include <asm/cputype.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080022#include <asm/mach-types.h>
Will Deaconeb504392012-01-20 12:01:12 +010023#include <asm/smp_plat.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080024
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070026#include <mach/hardware.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080027#include <mach/msm_iomap.h>
28
Matt Wagantall7cca4642012-02-01 16:43:24 -080029#include "pm.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080030#include "scm-boot.h"
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -080031#include "spm.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080032
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 Ohlsteine14411d2010-11-30 13:06:36 -080037extern void msm_secondary_startup(void);
Steve Mucklef132c6c2012-06-06 18:30:57 -070038
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080039/*
40 * control for which core is the next to come out of the secondary
41 * boot "holding pen".
42 */
43volatile int pen_release = -1;
44
Stephen Boyd3cfde2b2012-08-08 13:36:15 -070045/*
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 */
50static 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 Ohlsteine14411d2010-11-30 13:06:36 -080058static DEFINE_SPINLOCK(boot_lock);
59
60void __cpuinit platform_secondary_init(unsigned int cpu)
61{
Steve Mucklef132c6c2012-06-06 18:30:57 -070062 WARN_ON(msm_platform_secondary_init(cpu));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080063
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 Boyd3cfde2b2012-08-08 13:36:15 -070072 * 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 Ohlsteine14411d2010-11-30 13:06:36 -080078 * Synchronise with the boot thread.
79 */
80 spin_lock(&boot_lock);
81 spin_unlock(&boot_lock);
82}
83
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080084static int __cpuinit scorpion_release_secondary(void)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080085{
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080086 void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
87 if (!base_ptr)
88 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070089
Steve Mucklef132c6c2012-06-06 18:30:57 -070090 writel_relaxed(0, base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080091 dmb();
Steve Mucklef132c6c2012-06-06 18:30:57 -070092 writel_relaxed(0, base_ptr + SCSS_CPU1CORE_RESET);
93 writel_relaxed(3, base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080094 mb();
95 iounmap(base_ptr);
96
97 return 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080098}
99
Sathish Ambley576a6972012-03-20 12:38:45 -0700100static int __cpuinit krait_release_secondary_sim(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800101{
Sathish Ambley576a6972012-03-20 12:38:45 -0700102 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800103 if (!base_ptr)
104 return -ENODEV;
105
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700106 if (machine_is_msm8974_sim()) {
Sathish Ambleycf591972012-04-26 16:24:15 -0700107 writel_relaxed(0x800, base_ptr+0x04);
108 writel_relaxed(0x3FFF, base_ptr+0x14);
109 }
Sathish Ambley576a6972012-03-20 12:38:45 -0700110
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800111 mb();
112 iounmap(base_ptr);
113 return 0;
114}
115
Sathish Ambley576a6972012-03-20 12:38:45 -0700116static int __cpuinit krait_release_secondary(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800117{
Sathish Ambley576a6972012-03-20 12:38:45 -0700118 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800119 if (!base_ptr)
120 return -ENODEV;
121
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -0800122 msm_spm_turn_on_cpu_rail(cpu);
123
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800124 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 Moskovchenkob1c9ba22012-08-16 21:10:13 -0700130 mb();
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800131 udelay(2);
132
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800133 writel_relaxed(0x120, base_ptr+0x04);
Stepan Moskovchenkob1c9ba22012-08-16 21:10:13 -0700134 mb();
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800135 udelay(2);
136
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800137 writel_relaxed(0x100, base_ptr+0x04);
Stepan Moskovchenkob1c9ba22012-08-16 21:10:13 -0700138 mb();
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800139 udelay(100);
140
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800141 writel_relaxed(0x180, base_ptr+0x04);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800142 mb();
143 iounmap(base_ptr);
144 return 0;
145}
146
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700147static 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 Moskovchenko6b1d5df2012-08-11 22:33:20 -0700153 secondary_cpu_hs_init(base_ptr);
154
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700155 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 Moskovchenko964e1032012-01-06 18:16:10 -0800172static int __cpuinit release_secondary(unsigned int cpu)
173{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700174 BUG_ON(cpu >= get_core_count());
175
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800176 if (cpu_is_msm8x60())
177 return scorpion_release_secondary();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700178
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700179 if (machine_is_msm8974_sim())
Sathish Ambley576a6972012-03-20 12:38:45 -0700180 return krait_release_secondary_sim(0xf9088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700181
Stepan Moskovchenkoc6a603a2012-09-21 20:32:17 -0700182 if (soc_class_is_msm8960() || soc_class_is_msm8930() ||
183 soc_class_is_apq8064())
Sathish Ambley576a6972012-03-20 12:38:45 -0700184 return krait_release_secondary(0x02088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700185
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700186 if (cpu_is_msm8974())
187 return krait_release_secondary_p3(0xf9088000, cpu);
188
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800189 WARN(1, "unknown CPU case in release_secondary\n");
190 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700191}
192
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700193DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800194static int cold_boot_flags[] = {
195 0,
196 SCM_FLAG_COLDBOOT_CPU1,
197 SCM_FLAG_COLDBOOT_CPU2,
198 SCM_FLAG_COLDBOOT_CPU3,
199};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700200
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800201int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
202{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203 int ret;
Stephen Boyd37139282012-08-08 15:22:04 -0700204 unsigned int flag = 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800205 unsigned long timeout;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800206
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700207 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 King274621c2011-12-05 06:18:20 -0800212 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
213 flag = cold_boot_flags[cpu];
214 else
215 __WARN();
216
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700217 if (per_cpu(cold_boot_done, cpu) == false) {
Stephen Boyd37139282012-08-08 15:22:04 -0700218 ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800219 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700220 if (ret == 0)
221 release_secondary(cpu);
222 else
223 printk(KERN_DEBUG "Failed to set secondary core boot "
224 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700225 per_cpu(cold_boot_done, cpu) = true;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800226 }
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 Boyd3cfde2b2012-08-08 13:36:15 -0700242 write_pen_release(cpu_logical_map(cpu));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800243
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 King0f7b3322011-04-03 13:01:30 +0100249 gic_raise_softirq(cpumask_of(cpu), 1);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800250
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 Ohlsteine14411d2010-11-30 13:06:36 -0800268/*
269 * Initialise the CPU possible map early - this describes the CPUs
Steve Mucklef132c6c2012-06-06 18:30:57 -0700270 * which may be present or become present in the system.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800271 */
272void __init smp_init_cpus(void)
273{
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700274 unsigned int i, ncores = get_core_count();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800275
Russell Kinga06f9162011-10-20 22:04:18 +0100276 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 Ohlstein41ff4452011-04-07 17:41:09 -0700282 for (i = 0; i < ncores; i++)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800283 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100284
Steve Mucklef132c6c2012-06-06 18:30:57 -0700285 set_smp_cross_call(gic_raise_softirq);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800286}
287
288void __init platform_smp_prepare_cpus(unsigned int max_cpus)
289{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800290}