blob: 8085b82167c304183fd855097aa787579f59e471 [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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070028#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
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070034/* Initialize the present map (cpu_set(i, cpu_present_map)). */
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080035void __init platform_smp_prepare_cpus(unsigned int max_cpus)
36{
37 int i;
38
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080039 for (i = 0; i < max_cpus; i++)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070040 cpu_set(i, cpu_present_map);
41}
42
43void __init smp_init_cpus(void)
44{
45 unsigned int i, ncores = get_core_count();
46
47 for (i = 0; i < ncores; i++)
48 cpu_set(i, cpu_possible_map);
49
50 set_smp_cross_call(gic_raise_softirq);
51}
52
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080053static int __cpuinit scorpion_release_secondary(void)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070054{
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080055 void *base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
56 if (!base_ptr)
57 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070058
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080059 writel_relaxed(0x0, base_ptr+0x15A0);
60 dmb();
61 writel_relaxed(0x0, base_ptr+0xD80);
62 writel_relaxed(0x3, base_ptr+0xE64);
63 mb();
64 iounmap(base_ptr);
65
66 return 0;
67}
68
69static int __cpuinit krait_release_secondary_sim(int cpu)
70{
71 void *base_ptr = ioremap_nocache(0x02088000 + (cpu * 0x10000), SZ_4K);
72 if (!base_ptr)
73 return -ENODEV;
74
75 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3()) {
76 writel_relaxed(0x10, base_ptr+0x04);
77 writel_relaxed(0x80, base_ptr+0x04);
78 }
79
80 if (machine_is_apq8064_sim())
81 writel_relaxed(0xf0000, base_ptr+0x04);
82
83 mb();
84 iounmap(base_ptr);
85 return 0;
86}
87
88static int __cpuinit krait_release_secondary(int cpu)
89{
90 void *base_ptr = ioremap_nocache(0x02088000 + (cpu * 0x10000), SZ_4K);
91 if (!base_ptr)
92 return -ENODEV;
93
Stepan Moskovchenko9bbe5852012-01-09 13:28:28 -080094 msm_spm_turn_on_cpu_rail(cpu);
95
Stepan Moskovchenko964e1032012-01-06 18:16:10 -080096 writel_relaxed(0x109, base_ptr+0x04);
97 writel_relaxed(0x101, base_ptr+0x04);
98 ndelay(300);
99
100 writel_relaxed(0x121, base_ptr+0x04);
101 udelay(2);
102
103 writel_relaxed(0x020, base_ptr+0x04);
104 udelay(2);
105
106 writel_relaxed(0x000, base_ptr+0x04);
107 udelay(100);
108
109 writel_relaxed(0x080, base_ptr+0x04);
110 mb();
111 iounmap(base_ptr);
112 return 0;
113}
114
115static int __cpuinit release_secondary(unsigned int cpu)
116{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117 BUG_ON(cpu >= get_core_count());
118
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800119 if (cpu_is_msm8x60())
120 return scorpion_release_secondary();
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700121
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800122 if (machine_is_msm8960_sim() || machine_is_msm8960_rumi3() ||
123 machine_is_apq8064_sim())
124 return krait_release_secondary_sim(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700125
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800126 if (cpu_is_msm8960() || cpu_is_msm8930() || cpu_is_apq8064())
127 return krait_release_secondary(cpu);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700128
Stepan Moskovchenko964e1032012-01-06 18:16:10 -0800129 WARN(1, "unknown CPU case in release_secondary\n");
130 return -EINVAL;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700131}
132
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700133DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800134static int cold_boot_flags[] = {
135 0,
136 SCM_FLAG_COLDBOOT_CPU1,
137 SCM_FLAG_COLDBOOT_CPU2,
138 SCM_FLAG_COLDBOOT_CPU3,
139};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700140
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700141/* Executed by primary CPU, brings other CPUs out of reset. Called at boot
142 as well as when a CPU is coming out of shutdown induced by echo 0 >
143 /sys/devices/.../cpuX.
144*/
145int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
146{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700147 int cnt = 0;
148 int ret;
Joel King274621c2011-12-05 06:18:20 -0800149 int flag = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700150
151 pr_debug("Starting secondary CPU %d\n", cpu);
152
153 /* Set preset_lpj to avoid subsequent lpj recalculations */
154 preset_lpj = loops_per_jiffy;
155
Joel King274621c2011-12-05 06:18:20 -0800156 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
157 flag = cold_boot_flags[cpu];
158 else
159 __WARN();
160
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700161 if (per_cpu(cold_boot_done, cpu) == false) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700162 ret = scm_set_boot_addr((void *)
163 virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800164 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700165 if (ret == 0)
166 release_secondary(cpu);
167 else
168 printk(KERN_DEBUG "Failed to set secondary core boot "
169 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700170 per_cpu(cold_boot_done, cpu) = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700171 }
172
173 pen_release = cpu;
174 dmac_flush_range((void *)&pen_release,
175 (void *)(&pen_release + sizeof(pen_release)));
176 __asm__("sev");
177 mb();
178
179 /* Use smp_cross_call() to send a soft interrupt to wake up
180 * the other core.
181 */
182 gic_raise_softirq(cpumask_of(cpu), 1);
183
184 while (pen_release != 0xFFFFFFFF) {
185 dmac_inv_range((void *)&pen_release,
186 (void *)(&pen_release+sizeof(pen_release)));
Maya Spivak0a42d692011-08-02 14:42:04 -0700187 usleep(500);
188 if (cnt++ >= 10)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700189 break;
190 }
191
192 return 0;
193}
194
195/* Initialization routine for secondary CPUs after they are brought out of
196 * reset.
197*/
198void __cpuinit platform_secondary_init(unsigned int cpu)
199{
200 pr_debug("CPU%u: Booted secondary processor\n", cpu);
201
Mahesh Sivasubramaniand23add12011-11-18 14:30:11 -0700202 WARN_ON(msm_platform_secondary_init(cpu));
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700203
204 trace_hardirqs_off();
205
206 /* Edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */
207 writel(0xFFFFD7FF, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4);
208
209 /* RUMI does not adhere to GIC spec by enabling STIs by default.
210 * Enable/clear is supposed to be RO for STIs, but is RW on RUMI.
211 */
212 if (!machine_is_msm8x60_sim())
213 writel(0x0000FFFF, MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_SET);
214
215 gic_secondary_init(0);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800216}