blob: aca1fb1a9af8ddd2f3e7ba954ad3f51a1efa1e40 [file] [log] [blame]
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
Stepan Moskovchenko964e1032012-01-06 18:16:10 -08004 * Copyright (c) 2010-2012, Code Aurora Forum. 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
45static DEFINE_SPINLOCK(boot_lock);
46
47void __cpuinit platform_secondary_init(unsigned int cpu)
48{
Steve Mucklef132c6c2012-06-06 18:30:57 -070049 WARN_ON(msm_platform_secondary_init(cpu));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080050
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 Ohlsteine14411d2010-11-30 13:06:36 -080059 * Synchronise with the boot thread.
60 */
61 spin_lock(&boot_lock);
62 spin_unlock(&boot_lock);
63}
64
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080065static int __cpuinit scorpion_release_secondary(void)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080066{
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080067 void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
68 if (!base_ptr)
69 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070070
Steve Mucklef132c6c2012-06-06 18:30:57 -070071 writel_relaxed(0, base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080072 dmb();
Steve Mucklef132c6c2012-06-06 18:30:57 -070073 writel_relaxed(0, base_ptr + SCSS_CPU1CORE_RESET);
74 writel_relaxed(3, base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080075 mb();
76 iounmap(base_ptr);
77
78 return 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080079}
80
Sathish Ambley576a6972012-03-20 12:38:45 -070081static int __cpuinit krait_release_secondary_sim(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080082{
Sathish Ambley576a6972012-03-20 12:38:45 -070083 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080084 if (!base_ptr)
85 return -ENODEV;
86
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -070087 if (machine_is_msm8974_sim()) {
Sathish Ambleycf591972012-04-26 16:24:15 -070088 writel_relaxed(0x800, base_ptr+0x04);
89 writel_relaxed(0x3FFF, base_ptr+0x14);
90 }
Sathish Ambley576a6972012-03-20 12:38:45 -070091
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080092 mb();
93 iounmap(base_ptr);
94 return 0;
95}
96
Sathish Ambley576a6972012-03-20 12:38:45 -070097static int __cpuinit krait_release_secondary(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080098{
Sathish Ambley576a6972012-03-20 12:38:45 -070099 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800100 if (!base_ptr)
101 return -ENODEV;
102
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -0800103 msm_spm_turn_on_cpu_rail(cpu);
104
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800105 writel_relaxed(0x109, base_ptr+0x04);
106 writel_relaxed(0x101, base_ptr+0x04);
107 mb();
108 ndelay(300);
109
110 writel_relaxed(0x121, base_ptr+0x04);
Stepan Moskovchenkob1c9ba22012-08-16 21:10:13 -0700111 mb();
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800112 udelay(2);
113
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800114 writel_relaxed(0x120, base_ptr+0x04);
Stepan Moskovchenkob1c9ba22012-08-16 21:10:13 -0700115 mb();
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800116 udelay(2);
117
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800118 writel_relaxed(0x100, base_ptr+0x04);
Stepan Moskovchenkob1c9ba22012-08-16 21:10:13 -0700119 mb();
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800120 udelay(100);
121
Stepan Moskovchenkod4109b12012-12-11 18:33:07 -0800122 writel_relaxed(0x180, base_ptr+0x04);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800123 mb();
124 iounmap(base_ptr);
125 return 0;
126}
127
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700128static int __cpuinit krait_release_secondary_p3(unsigned long base, int cpu)
129{
130 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
131 if (!base_ptr)
132 return -ENODEV;
133
Stepan Moskovchenko6b1d5df2012-08-11 22:33:20 -0700134 secondary_cpu_hs_init(base_ptr);
135
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700136 writel_relaxed(0x021, base_ptr+0x04);
137 mb();
138 udelay(2);
139
140 writel_relaxed(0x020, base_ptr+0x04);
141 mb();
142 udelay(2);
143
144 writel_relaxed(0x000, base_ptr+0x04);
145 mb();
146
147 writel_relaxed(0x080, base_ptr+0x04);
148 mb();
149 iounmap(base_ptr);
150 return 0;
151}
152
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800153static int __cpuinit release_secondary(unsigned int cpu)
154{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700155 BUG_ON(cpu >= get_core_count());
156
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800157 if (cpu_is_msm8x60())
158 return scorpion_release_secondary();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700159
Abhimanyu Kapur90ced6e2012-06-26 17:41:25 -0700160 if (machine_is_msm8974_sim())
Sathish Ambley576a6972012-03-20 12:38:45 -0700161 return krait_release_secondary_sim(0xf9088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162
Stepan Moskovchenkoc6a603a2012-09-21 20:32:17 -0700163 if (soc_class_is_msm8960() || soc_class_is_msm8930() ||
164 soc_class_is_apq8064())
Sathish Ambley576a6972012-03-20 12:38:45 -0700165 return krait_release_secondary(0x02088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700166
Stepan Moskovchenko25173722012-08-09 13:43:02 -0700167 if (cpu_is_msm8974())
168 return krait_release_secondary_p3(0xf9088000, cpu);
169
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800170 WARN(1, "unknown CPU case in release_secondary\n");
171 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700172}
173
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700174DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800175static int cold_boot_flags[] = {
176 0,
177 SCM_FLAG_COLDBOOT_CPU1,
178 SCM_FLAG_COLDBOOT_CPU2,
179 SCM_FLAG_COLDBOOT_CPU3,
180};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700181
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800182int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
183{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184 int ret;
Stephen Boyd37139282012-08-08 15:22:04 -0700185 unsigned int flag = 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800186 unsigned long timeout;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800187
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700188 pr_debug("Starting secondary CPU %d\n", cpu);
189
190 /* Set preset_lpj to avoid subsequent lpj recalculations */
191 preset_lpj = loops_per_jiffy;
192
Joel King274621c2011-12-05 06:18:20 -0800193 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
194 flag = cold_boot_flags[cpu];
195 else
196 __WARN();
197
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700198 if (per_cpu(cold_boot_done, cpu) == false) {
Stephen Boyd37139282012-08-08 15:22:04 -0700199 ret = scm_set_boot_addr(virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800200 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700201 if (ret == 0)
202 release_secondary(cpu);
203 else
204 printk(KERN_DEBUG "Failed to set secondary core boot "
205 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700206 per_cpu(cold_boot_done, cpu) = true;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800207 }
208
209 /*
210 * set synchronisation state between this boot processor
211 * and the secondary one
212 */
213 spin_lock(&boot_lock);
214
215 /*
216 * The secondary processor is waiting to be released from
217 * the holding pen - release it, then wait for it to flag
218 * that it has been released by resetting pen_release.
219 *
220 * Note that "pen_release" is the hardware CPU ID, whereas
221 * "cpu" is Linux's internal ID.
222 */
Will Deacon1d3cfb32011-08-09 12:02:27 +0100223 pen_release = cpu_logical_map(cpu);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800224 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
225 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
226
227 /*
228 * Send the secondary CPU a soft interrupt, thereby causing
229 * the boot monitor to read the system wide flags register,
230 * and branch to the address found there.
231 */
Russell King0f7b3322011-04-03 13:01:30 +0100232 gic_raise_softirq(cpumask_of(cpu), 1);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800233
234 timeout = jiffies + (1 * HZ);
235 while (time_before(jiffies, timeout)) {
236 smp_rmb();
237 if (pen_release == -1)
238 break;
239
Stephen Boyda812be82012-08-07 19:24:56 -0700240 dmac_inv_range((char *)&pen_release,
241 (char *)&pen_release + sizeof(pen_release));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800242 udelay(10);
243 }
244
245 /*
246 * now the secondary core is starting up let it run its
247 * calibrations, then wait for it to finish
248 */
249 spin_unlock(&boot_lock);
250
251 return pen_release != -1 ? -ENOSYS : 0;
252}
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800253/*
254 * Initialise the CPU possible map early - this describes the CPUs
Steve Mucklef132c6c2012-06-06 18:30:57 -0700255 * which may be present or become present in the system.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800256 */
257void __init smp_init_cpus(void)
258{
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700259 unsigned int i, ncores = get_core_count();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800260
Russell Kinga06f9162011-10-20 22:04:18 +0100261 if (ncores > nr_cpu_ids) {
262 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
263 ncores, nr_cpu_ids);
264 ncores = nr_cpu_ids;
265 }
266
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700267 for (i = 0; i < ncores; i++)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800268 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100269
Steve Mucklef132c6c2012-06-06 18:30:57 -0700270 set_smp_cross_call(gic_raise_softirq);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800271}
272
273void __init platform_smp_prepare_cpus(unsigned int max_cpus)
274{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800275}