blob: b40c0c70415e7366cfd257a100b5bc28d8cd9f18 [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>
17
18#include <asm/hardware/gic.h>
19#include <asm/cacheflush.h>
Jeff Ohlstein41ff4452011-04-07 17:41:09 -070020#include <asm/cputype.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080021#include <asm/mach-types.h>
Will Deaconeb504392012-01-20 12:01:12 +010022#include <asm/smp_plat.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080023
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070024#include <mach/socinfo.h>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070025#include <mach/hardware.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080026#include <mach/msm_iomap.h>
27
Matt Wagantall7cca4642012-02-01 16:43:24 -080028#include "pm.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080029#include "scm-boot.h"
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -080030#include "spm.h"
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080031
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 Ohlsteine14411d2010-11-30 13:06:36 -080036extern void msm_secondary_startup(void);
Steve Mucklef132c6c2012-06-06 18:30:57 -070037
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080038/*
39 * control for which core is the next to come out of the secondary
40 * boot "holding pen".
41 */
42volatile int pen_release = -1;
43
44static DEFINE_SPINLOCK(boot_lock);
45
46void __cpuinit platform_secondary_init(unsigned int cpu)
47{
Steve Mucklef132c6c2012-06-06 18:30:57 -070048 WARN_ON(msm_platform_secondary_init(cpu));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080049
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 Ohlsteine14411d2010-11-30 13:06:36 -080058 * Synchronise with the boot thread.
59 */
60 spin_lock(&boot_lock);
61 spin_unlock(&boot_lock);
62}
63
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080064static int __cpuinit scorpion_release_secondary(void)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080065{
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080066 void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
67 if (!base_ptr)
68 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070069
Steve Mucklef132c6c2012-06-06 18:30:57 -070070 writel_relaxed(0, base_ptr + VDD_SC1_ARRAY_CLAMP_GFS_CTL);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080071 dmb();
Steve Mucklef132c6c2012-06-06 18:30:57 -070072 writel_relaxed(0, base_ptr + SCSS_CPU1CORE_RESET);
73 writel_relaxed(3, base_ptr + SCSS_DBG_STATUS_CORE_PWRDUP);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080074 mb();
75 iounmap(base_ptr);
76
77 return 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080078}
79
Sathish Ambley576a6972012-03-20 12:38:45 -070080static int __cpuinit krait_release_secondary_sim(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080081{
Sathish Ambley576a6972012-03-20 12:38:45 -070082 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080083 if (!base_ptr)
84 return -ENODEV;
85
86 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3()) {
87 writel_relaxed(0x10, base_ptr+0x04);
88 writel_relaxed(0x80, base_ptr+0x04);
89 }
90
91 if (machine_is_apq8064_sim())
92 writel_relaxed(0xf0000, base_ptr+0x04);
93
Sathish Ambleycf591972012-04-26 16:24:15 -070094 if (machine_is_copper_sim()) {
95 writel_relaxed(0x800, base_ptr+0x04);
96 writel_relaxed(0x3FFF, base_ptr+0x14);
97 }
Sathish Ambley576a6972012-03-20 12:38:45 -070098
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080099 mb();
100 iounmap(base_ptr);
101 return 0;
102}
103
Sathish Ambley576a6972012-03-20 12:38:45 -0700104static int __cpuinit krait_release_secondary(unsigned long base, int cpu)
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800105{
Sathish Ambley576a6972012-03-20 12:38:45 -0700106 void *base_ptr = ioremap_nocache(base + (cpu * 0x10000), SZ_4K);
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800107 if (!base_ptr)
108 return -ENODEV;
109
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -0800110 msm_spm_turn_on_cpu_rail(cpu);
111
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800112 writel_relaxed(0x109, base_ptr+0x04);
113 writel_relaxed(0x101, base_ptr+0x04);
114 ndelay(300);
115
116 writel_relaxed(0x121, base_ptr+0x04);
117 udelay(2);
118
119 writel_relaxed(0x020, base_ptr+0x04);
120 udelay(2);
121
122 writel_relaxed(0x000, base_ptr+0x04);
123 udelay(100);
124
125 writel_relaxed(0x080, base_ptr+0x04);
126 mb();
127 iounmap(base_ptr);
128 return 0;
129}
130
131static int __cpuinit release_secondary(unsigned int cpu)
132{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700133 BUG_ON(cpu >= get_core_count());
134
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800135 if (cpu_is_msm8x60())
136 return scorpion_release_secondary();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700137
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800138 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3() ||
139 machine_is_apq8064_sim())
Sathish Ambley576a6972012-03-20 12:38:45 -0700140 return krait_release_secondary_sim(0x02088000, cpu);
141
142 if (machine_is_copper_sim())
143 return krait_release_secondary_sim(0xf9088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700144
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800145 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_apq8064())
Sathish Ambley576a6972012-03-20 12:38:45 -0700146 return krait_release_secondary(0x02088000, cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800148 WARN(1, "unknown CPU case in release_secondary\n");
149 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150}
151
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700152DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800153static int cold_boot_flags[] = {
154 0,
155 SCM_FLAG_COLDBOOT_CPU1,
156 SCM_FLAG_COLDBOOT_CPU2,
157 SCM_FLAG_COLDBOOT_CPU3,
158};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700159
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800160int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
161{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162 int ret;
Joel King274621c2011-12-05 06:18:20 -0800163 int flag = 0;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800164 unsigned long timeout;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800165
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700166 pr_debug("Starting secondary CPU %d\n", cpu);
167
168 /* Set preset_lpj to avoid subsequent lpj recalculations */
169 preset_lpj = loops_per_jiffy;
170
Joel King274621c2011-12-05 06:18:20 -0800171 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
172 flag = cold_boot_flags[cpu];
173 else
174 __WARN();
175
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700176 if (per_cpu(cold_boot_done, cpu) == false) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700177 ret = scm_set_boot_addr((void *)
178 virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800179 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700180 if (ret == 0)
181 release_secondary(cpu);
182 else
183 printk(KERN_DEBUG "Failed to set secondary core boot "
184 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700185 per_cpu(cold_boot_done, cpu) = true;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800186 }
187
188 /*
189 * set synchronisation state between this boot processor
190 * and the secondary one
191 */
192 spin_lock(&boot_lock);
193
194 /*
195 * The secondary processor is waiting to be released from
196 * the holding pen - release it, then wait for it to flag
197 * that it has been released by resetting pen_release.
198 *
199 * Note that "pen_release" is the hardware CPU ID, whereas
200 * "cpu" is Linux's internal ID.
201 */
Will Deacon1d3cfb32011-08-09 12:02:27 +0100202 pen_release = cpu_logical_map(cpu);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800203 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
204 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700205 __asm__("sev");
206 mb();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800207
208 /*
209 * Send the secondary CPU a soft interrupt, thereby causing
210 * the boot monitor to read the system wide flags register,
211 * and branch to the address found there.
212 */
Russell King0f7b3322011-04-03 13:01:30 +0100213 gic_raise_softirq(cpumask_of(cpu), 1);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800214
215 timeout = jiffies + (1 * HZ);
216 while (time_before(jiffies, timeout)) {
217 smp_rmb();
218 if (pen_release == -1)
219 break;
220
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700221 dmac_inv_range((void *)&pen_release,
222 (void *)(&pen_release+sizeof(pen_release)));
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800223 udelay(10);
224 }
225
226 /*
227 * now the secondary core is starting up let it run its
228 * calibrations, then wait for it to finish
229 */
230 spin_unlock(&boot_lock);
231
232 return pen_release != -1 ? -ENOSYS : 0;
233}
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800234/*
235 * Initialise the CPU possible map early - this describes the CPUs
Steve Mucklef132c6c2012-06-06 18:30:57 -0700236 * which may be present or become present in the system.
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800237 */
238void __init smp_init_cpus(void)
239{
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700240 unsigned int i, ncores = get_core_count();
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800241
Russell Kinga06f9162011-10-20 22:04:18 +0100242 if (ncores > nr_cpu_ids) {
243 pr_warn("SMP: %u cores greater than maximum (%u), clipping\n",
244 ncores, nr_cpu_ids);
245 ncores = nr_cpu_ids;
246 }
247
Jeff Ohlstein41ff4452011-04-07 17:41:09 -0700248 for (i = 0; i < ncores; i++)
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800249 set_cpu_possible(i, true);
Russell King0f7b3322011-04-03 13:01:30 +0100250
Steve Mucklef132c6c2012-06-06 18:30:57 -0700251 set_smp_cross_call(gic_raise_softirq);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800252}
253
254void __init platform_smp_prepare_cpus(unsigned int max_cpus)
255{
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800256}