blob: 3c422009dc1ad0e21b762f62cc281d7625ab7f7a [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>
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070020#include <asm/cputype.h>
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080021#include <asm/mach-types.h>
22
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070023#include <mach/socinfo.h>
24#include <mach/smp.h>
25#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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070032int pen_release = -1;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080033
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080034void __init platform_smp_prepare_cpus(unsigned int max_cpus)
35{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070036}
37
38void __init smp_init_cpus(void)
39{
40 unsigned int i, ncores = get_core_count();
41
42 for (i = 0; i < ncores; i++)
43 cpu_set(i, cpu_possible_map);
44
45 set_smp_cross_call(gic_raise_softirq);
46}
47
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080048static int __cpuinit scorpion_release_secondary(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070049{
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080050 void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
51 if (!base_ptr)
52 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070053
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080054 writel_relaxed(0x0, base_ptr+0x15A0);
55 dmb();
56 writel_relaxed(0x0, base_ptr+0xD80);
57 writel_relaxed(0x3, base_ptr+0xE64);
58 mb();
59 iounmap(base_ptr);
60
61 return 0;
62}
63
64static int __cpuinit krait_release_secondary_sim(int cpu)
65{
66 void *base_ptr = ioremap_nocache(0x02088000 + (cpu * 0x10000), SZ_4K);
67 if (!base_ptr)
68 return -ENODEV;
69
70 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3()) {
71 writel_relaxed(0x10, base_ptr+0x04);
72 writel_relaxed(0x80, base_ptr+0x04);
73 }
74
75 if (machine_is_apq8064_sim())
76 writel_relaxed(0xf0000, base_ptr+0x04);
77
78 mb();
79 iounmap(base_ptr);
80 return 0;
81}
82
83static int __cpuinit krait_release_secondary(int cpu)
84{
85 void *base_ptr = ioremap_nocache(0x02088000 + (cpu * 0x10000), SZ_4K);
86 if (!base_ptr)
87 return -ENODEV;
88
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -080089 msm_spm_turn_on_cpu_rail(cpu);
90
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080091 writel_relaxed(0x109, base_ptr+0x04);
92 writel_relaxed(0x101, base_ptr+0x04);
93 ndelay(300);
94
95 writel_relaxed(0x121, base_ptr+0x04);
96 udelay(2);
97
98 writel_relaxed(0x020, base_ptr+0x04);
99 udelay(2);
100
101 writel_relaxed(0x000, base_ptr+0x04);
102 udelay(100);
103
104 writel_relaxed(0x080, base_ptr+0x04);
105 mb();
106 iounmap(base_ptr);
107 return 0;
108}
109
110static int __cpuinit release_secondary(unsigned int cpu)
111{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700112 BUG_ON(cpu >= get_core_count());
113
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800114 if (cpu_is_msm8x60())
115 return scorpion_release_secondary();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700116
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800117 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3() ||
118 machine_is_apq8064_sim())
119 return krait_release_secondary_sim(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700120
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800121 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_apq8064())
122 return krait_release_secondary(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700123
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800124 WARN(1, "unknown CPU case in release_secondary\n");
125 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700126}
127
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700128DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800129static int cold_boot_flags[] = {
130 0,
131 SCM_FLAG_COLDBOOT_CPU1,
132 SCM_FLAG_COLDBOOT_CPU2,
133 SCM_FLAG_COLDBOOT_CPU3,
134};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700135
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700136/* Executed by primary CPU, brings other CPUs out of reset. Called at boot
137 as well as when a CPU is coming out of shutdown induced by echo 0 >
138 /sys/devices/.../cpuX.
139*/
140int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
141{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700142 int cnt = 0;
143 int ret;
Joel King274621c2011-12-05 06:18:20 -0800144 int flag = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700145
146 pr_debug("Starting secondary CPU %d\n", cpu);
147
148 /* Set preset_lpj to avoid subsequent lpj recalculations */
149 preset_lpj = loops_per_jiffy;
150
Joel King274621c2011-12-05 06:18:20 -0800151 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
152 flag = cold_boot_flags[cpu];
153 else
154 __WARN();
155
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700156 if (per_cpu(cold_boot_done, cpu) == false) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700157 ret = scm_set_boot_addr((void *)
158 virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800159 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700160 if (ret == 0)
161 release_secondary(cpu);
162 else
163 printk(KERN_DEBUG "Failed to set secondary core boot "
164 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700165 per_cpu(cold_boot_done, cpu) = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700166 }
167
168 pen_release = cpu;
169 dmac_flush_range((void *)&pen_release,
170 (void *)(&pen_release + sizeof(pen_release)));
171 __asm__("sev");
172 mb();
173
174 /* Use smp_cross_call() to send a soft interrupt to wake up
175 * the other core.
176 */
177 gic_raise_softirq(cpumask_of(cpu), 1);
178
179 while (pen_release != 0xFFFFFFFF) {
180 dmac_inv_range((void *)&pen_release,
181 (void *)(&pen_release+sizeof(pen_release)));
Maya Spivak0a42d692011-08-02 14:42:04 -0700182 usleep(500);
183 if (cnt++ >= 10)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700184 break;
185 }
186
187 return 0;
188}
189
190/* Initialization routine for secondary CPUs after they are brought out of
191 * reset.
192*/
193void __cpuinit platform_secondary_init(unsigned int cpu)
194{
195 pr_debug("CPU%u: Booted secondary processor\n", cpu);
196
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700197 WARN_ON(msm_platform_secondary_init(cpu));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700198
199 trace_hardirqs_off();
200
201 /* Edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */
202 writel(0xFFFFD7FF, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4);
203
204 /* RUMI does not adhere to GIC spec by enabling STIs by default.
205 * Enable/clear is supposed to be RO for STIs, but is RW on RUMI.
206 */
207 if (!machine_is_msm8x60_sim())
208 writel(0x0000FFFF, MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_SET);
209
210 gic_secondary_init(0);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800211}