blob: 93624a3ce2a7730d19485e59101f1ff60aed3a86 [file] [log] [blame]
Jeff Ohlsteine14411d2010-11-30 13:06:36 -08001/*
2 * Copyright (C) 2002 ARM Ltd.
3 * All Rights Reserved
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07004 * Copyright (c) 2010-2011, 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"
30
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070031int pen_release = -1;
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080032
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070033/* Initialize the present map (cpu_set(i, cpu_present_map)). */
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080034void __init platform_smp_prepare_cpus(unsigned int max_cpus)
35{
36 int i;
37
Jeff Ohlsteine14411d2010-11-30 13:06:36 -080038 for (i = 0; i < max_cpus; i++)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070039 cpu_set(i, cpu_present_map);
40}
41
42void __init smp_init_cpus(void)
43{
44 unsigned int i, ncores = get_core_count();
45
46 for (i = 0; i < ncores; i++)
47 cpu_set(i, cpu_possible_map);
48
49 set_smp_cross_call(gic_raise_softirq);
50}
51
52static void __cpuinit release_secondary(unsigned int cpu)
53{
54 void *base_ptr;
55
56 BUG_ON(cpu >= get_core_count());
57
58 /* KraitMP or ScorpionMP ? */
59 if ((read_cpuid_id() & 0xFF0) >> 4 != 0x2D) {
Joel King274621c2011-12-05 06:18:20 -080060 base_ptr = ioremap_nocache(0x02088000 + (cpu * 0x10000), SZ_4K);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070061 if (base_ptr) {
62 if (machine_is_msm8960_sim() ||
63 machine_is_msm8960_rumi3()) {
64 writel_relaxed(0x10, base_ptr+0x04);
65 writel_relaxed(0x80, base_ptr+0x04);
Joel King274621c2011-12-05 06:18:20 -080066 } else if (machine_is_apq8064_sim()) {
67 writel_relaxed(0xf0000, base_ptr+0x04);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070068 } else if (get_core_count() == 2) {
69 writel_relaxed(0x109, base_ptr+0x04);
70 writel_relaxed(0x101, base_ptr+0x04);
71 ndelay(300);
72
73 writel_relaxed(0x121, base_ptr+0x04);
74 udelay(2);
75
76 writel_relaxed(0x020, base_ptr+0x04);
77 udelay(2);
78
79 writel_relaxed(0x000, base_ptr+0x04);
80 udelay(100);
81
82 writel_relaxed(0x080, base_ptr+0x04);
83 }
84 mb();
85 iounmap(base_ptr);
86 }
87 } else {
88 base_ptr = ioremap_nocache(0x00902000, SZ_4K*2);
89 if (base_ptr) {
90 writel_relaxed(0x0, base_ptr+0x15A0);
91 dmb();
92 writel_relaxed(0x0, base_ptr+0xD80);
93 writel_relaxed(0x3, base_ptr+0xE64);
94 mb();
95 iounmap(base_ptr);
96 }
97 }
98}
99
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700100DEFINE_PER_CPU(int, cold_boot_done);
Joel King274621c2011-12-05 06:18:20 -0800101static int cold_boot_flags[] = {
102 0,
103 SCM_FLAG_COLDBOOT_CPU1,
104 SCM_FLAG_COLDBOOT_CPU2,
105 SCM_FLAG_COLDBOOT_CPU3,
106};
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700107
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700108/* Executed by primary CPU, brings other CPUs out of reset. Called at boot
109 as well as when a CPU is coming out of shutdown induced by echo 0 >
110 /sys/devices/.../cpuX.
111*/
112int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
113{
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700114 int cnt = 0;
115 int ret;
Joel King274621c2011-12-05 06:18:20 -0800116 int flag = 0;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700117
118 pr_debug("Starting secondary CPU %d\n", cpu);
119
120 /* Set preset_lpj to avoid subsequent lpj recalculations */
121 preset_lpj = loops_per_jiffy;
122
Joel King274621c2011-12-05 06:18:20 -0800123 if (cpu > 0 && cpu < ARRAY_SIZE(cold_boot_flags))
124 flag = cold_boot_flags[cpu];
125 else
126 __WARN();
127
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700128 if (per_cpu(cold_boot_done, cpu) == false) {
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700129 ret = scm_set_boot_addr((void *)
130 virt_to_phys(msm_secondary_startup),
Joel King274621c2011-12-05 06:18:20 -0800131 flag);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700132 if (ret == 0)
133 release_secondary(cpu);
134 else
135 printk(KERN_DEBUG "Failed to set secondary core boot "
136 "address\n");
Stepan Moskovchenko20a12332011-09-13 13:54:59 -0700137 per_cpu(cold_boot_done, cpu) = true;
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700138 }
139
140 pen_release = cpu;
141 dmac_flush_range((void *)&pen_release,
142 (void *)(&pen_release + sizeof(pen_release)));
143 __asm__("sev");
144 mb();
145
146 /* Use smp_cross_call() to send a soft interrupt to wake up
147 * the other core.
148 */
149 gic_raise_softirq(cpumask_of(cpu), 1);
150
151 while (pen_release != 0xFFFFFFFF) {
152 dmac_inv_range((void *)&pen_release,
153 (void *)(&pen_release+sizeof(pen_release)));
Maya Spivak0a42d692011-08-02 14:42:04 -0700154 usleep(500);
155 if (cnt++ >= 10)
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -0700156 break;
157 }
158
159 return 0;
160}
161
162/* Initialization routine for secondary CPUs after they are brought out of
163 * reset.
164*/
165void __cpuinit platform_secondary_init(unsigned int cpu)
166{
167 pr_debug("CPU%u: Booted secondary processor\n", cpu);
168
169#ifdef CONFIG_HOTPLUG_CPU
170 WARN_ON(msm_pm_platform_secondary_init(cpu));
171#endif
172
173 trace_hardirqs_off();
174
175 /* Edge trigger PPIs except AVS_SVICINT and AVS_SVICINTSWDONE */
176 writel(0xFFFFD7FF, MSM_QGIC_DIST_BASE + GIC_DIST_CONFIG + 4);
177
178 /* RUMI does not adhere to GIC spec by enabling STIs by default.
179 * Enable/clear is supposed to be RO for STIs, but is RW on RUMI.
180 */
181 if (!machine_is_msm8x60_sim())
182 writel(0x0000FFFF, MSM_QGIC_DIST_BASE + GIC_DIST_ENABLE_SET);
183
184 gic_secondary_init(0);
Jeff Ohlsteine14411d2010-11-30 13:06:36 -0800185}