blob: 915047a380c253799af00fd67a93e7ce1f0f01bb [file] [log] [blame]
Taniya Das137dc8e2011-12-02 14:50:00 +05301/* Copyright (c) 2012, Code Aurora Forum. All rights reserved.
2 *
3 * This program is free software; you can redistribute it and/or modify
4 * it under the terms of the GNU General Public License version 2 and
5 * only version 2 as published by the Free Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 */
12
13#include <linux/init.h>
14#include <linux/errno.h>
15#include <linux/delay.h>
16#include <linux/device.h>
17#include <linux/jiffies.h>
18#include <linux/smp.h>
19#include <linux/io.h>
Taniya Dase30a6b22012-03-20 11:37:45 +053020#include <linux/interrupt.h>
Taniya Das137dc8e2011-12-02 14:50:00 +053021
22#include <asm/cacheflush.h>
23#include <asm/hardware/gic.h>
24#include <asm/hardware/cache-l2x0.h>
25#include <asm/smp_scu.h>
26#include <asm/unified.h>
27#include <mach/msm_iomap.h>
Taniya Das137dc8e2011-12-02 14:50:00 +053028#include "pm.h"
29
30#define MSM_CORE1_RESET 0xA8600590
Taniya Das63da6462012-02-27 17:22:11 +053031#define MSM_CORE1_STATUS_MSK 0x02800000
32
Taniya Das137dc8e2011-12-02 14:50:00 +053033/*
34 * control for which core is the next to come out of the secondary
35 * boot "holding pen"
36 */
37int pen_release = -1;
38
39static bool cold_boot_done;
40
41static uint32_t *msm8625_boot_vector;
Taniya Das94b8ecb2012-05-17 18:14:37 +053042static void __iomem *reset_core1_base;
Taniya Das137dc8e2011-12-02 14:50:00 +053043
44/*
45 * Write pen_release in a way that is guaranteed to be visible to all
46 * observers, irrespective of whether they're taking part in coherency
47 * or not. This is necessary for the hotplug code to work reliably.
48 */
49static void __cpuinit write_pen_release(int val)
50{
51 pen_release = val;
52 smp_wmb();
53 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
54 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
55}
56
57static void __iomem *scu_base_addr(void)
58{
59 return MSM_SCU_BASE;
60}
61
62static DEFINE_SPINLOCK(boot_lock);
Taniya Dase30a6b22012-03-20 11:37:45 +053063
64/*
65 * MP_CORE_IPC will be used to generate interrupt and can be used by either
66 * of core.
67 * To bring core1 out of GDFS we need to raise the SPI using the MP_CORE_IPC.
68 */
69static void raise_clear_spi(unsigned int cpu, bool set)
70{
71 int value;
72
73 value = __raw_readl(MSM_CSR_BASE + 0x54);
74 if (set)
75 __raw_writel(value | BIT(cpu), MSM_CSR_BASE + 0x54);
76 else
77 __raw_writel(value & ~BIT(cpu), MSM_CSR_BASE + 0x54);
78 mb();
79}
80
Murali Nalajalaa30aad02012-04-17 16:20:14 +053081static void clear_pending_spi(unsigned int irq)
Taniya Dase30a6b22012-03-20 11:37:45 +053082{
Taniya Das1816eb42012-05-01 19:13:11 +053083 struct irq_data *d = irq_get_irq_data(irq);
84 struct irq_chip *c = irq_data_get_irq_chip(d);
85
86 c->irq_mask(d);
Taniya Dase30a6b22012-03-20 11:37:45 +053087 local_irq_disable();
Taniya Das1816eb42012-05-01 19:13:11 +053088 /* Clear the IRQ from the ENABLE_SET */
Taniya Dase30a6b22012-03-20 11:37:45 +053089 gic_clear_spi_pending(irq);
Taniya Dase30a6b22012-03-20 11:37:45 +053090 local_irq_enable();
91}
Taniya Das137dc8e2011-12-02 14:50:00 +053092
93void __cpuinit platform_secondary_init(unsigned int cpu)
94{
Murali Nalajalaa7efba12012-02-23 18:13:52 +053095 pr_debug("CPU%u: Booted secondary processor\n", cpu);
96
97 WARN_ON(msm_platform_secondary_init(cpu));
98
Taniya Das137dc8e2011-12-02 14:50:00 +053099 /*
100 * if any interrupts are already enabled for the primary
101 * core (e.g. timer irq), then they will not have been enabled
102 * for us: do so
103 */
104 gic_secondary_init(0);
105
106 /*
107 * let the primary processor know we're out of the
108 * pen, then head off into the C entry point
109 */
110 write_pen_release(-1);
111
Murali Nalajalaa30aad02012-04-17 16:20:14 +0530112 /* clear the IPC1(SPI-8) pending SPI */
113 if (power_collapsed) {
114 raise_clear_spi(1, false);
115 clear_pending_spi(MSM8625_INT_ACSR_MP_CORE_IPC1);
116 power_collapsed = 0;
117 }
118
Taniya Das137dc8e2011-12-02 14:50:00 +0530119 /*
120 * Synchronise with the boot thread.
121 */
122 spin_lock(&boot_lock);
123 spin_unlock(&boot_lock);
124}
125
Taniya Das63da6462012-02-27 17:22:11 +0530126static int __cpuinit msm8625_release_secondary(void)
127{
128 void __iomem *base_ptr;
129 int value = 0;
130 unsigned long timeout;
131
132 /*
133 * loop to ensure that the GHS_STATUS_CORE1 bit in the
134 * MPA5_STATUS_REG(0x3c) is set. The timeout for the while
135 * loop can be set as 20us as of now
136 */
137 timeout = jiffies + usecs_to_jiffies(20);
138 while (time_before(jiffies, timeout)) {
139 value = __raw_readl(MSM_CFG_CTL_BASE + 0x3c);
140 if ((value & MSM_CORE1_STATUS_MSK) ==
141 MSM_CORE1_STATUS_MSK)
142 break;
143 udelay(1);
144 }
145
146 if (!value) {
147 pr_err("Core 1 cannot be brought out of Reset!!!\n");
148 return -ENODEV;
149 }
150
151 base_ptr = ioremap_nocache(MSM_CORE1_RESET, SZ_4);
152 if (!base_ptr)
153 return -ENODEV;
154 /* Reset core 1 out of reset */
155 __raw_writel(0x0, base_ptr);
156 mb();
157
Taniya Das94b8ecb2012-05-17 18:14:37 +0530158 reset_core1_base = base_ptr;
Taniya Das63da6462012-02-27 17:22:11 +0530159
160 return 0;
161}
162
Taniya Das94b8ecb2012-05-17 18:14:37 +0530163void __iomem *core1_reset_base(void)
164{
165 return reset_core1_base;
166}
167
Taniya Das137dc8e2011-12-02 14:50:00 +0530168int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
169{
170 unsigned long timeout;
Taniya Das137dc8e2011-12-02 14:50:00 +0530171
Krishna Vankafef8e2b2012-05-24 18:00:20 +0530172 preset_lpj = loops_per_jiffy;
173
Taniya Das137dc8e2011-12-02 14:50:00 +0530174 if (cold_boot_done == false) {
Taniya Das63da6462012-02-27 17:22:11 +0530175 if (msm8625_release_secondary()) {
176 pr_err("Failed to release secondary core\n");
Taniya Das137dc8e2011-12-02 14:50:00 +0530177 return -ENODEV;
Taniya Das63da6462012-02-27 17:22:11 +0530178 }
Taniya Das137dc8e2011-12-02 14:50:00 +0530179 cold_boot_done = true;
Taniya Das137dc8e2011-12-02 14:50:00 +0530180 }
181
182 /*
183 * Set synchronisation state between this boot processor
184 * and the secondary one
185 */
186 spin_lock(&boot_lock);
187
188 /*
189 * This is really belt and braces; we hold unintended secondary
190 * CPUs in the holding pen until we're ready for them. However,
191 * since we haven't sent them a soft interrupt, they shouldn't
192 * be there.
193 */
194 write_pen_release(cpu);
195
196 /*
197 * Send the secondary CPU a soft interrupt, thereby causing
198 * the boot monitor to read the system wide flags register,
199 * and branch to the address found there.
Taniya Dase30a6b22012-03-20 11:37:45 +0530200 *
201 * power_collapsed is the flag which will be updated for Powercollapse.
202 * Once we are out of PC, as Core1 will be in the state of GDFS which
203 * needs to be brought out by raising an SPI.
Taniya Das137dc8e2011-12-02 14:50:00 +0530204 */
Taniya Dase30a6b22012-03-20 11:37:45 +0530205
Taniya Dasbc9248a2012-04-30 19:59:11 +0530206 if (power_collapsed) {
Taniya Dase30a6b22012-03-20 11:37:45 +0530207 core1_gic_configure_and_raise();
Taniya Dasbc9248a2012-04-30 19:59:11 +0530208 raise_clear_spi(1, true);
209 } else {
Taniya Dase30a6b22012-03-20 11:37:45 +0530210 gic_raise_softirq(cpumask_of(cpu), 1);
Taniya Dasbc9248a2012-04-30 19:59:11 +0530211 }
Taniya Das137dc8e2011-12-02 14:50:00 +0530212
213 timeout = jiffies + (1 * HZ);
214 while (time_before(jiffies, timeout)) {
215 smp_rmb();
216 if (pen_release == -1)
217 break;
218
219 udelay(10);
220 }
221
222 /*
223 * now the secondary core is starting up let it run its
224 * calibrations, then wait for it to finish
225 */
226 spin_unlock(&boot_lock);
227
228 return 0;
229}
230
231/*
232 * Initialise the CPU possible map early - this describes the CPUs
233 * which may be present or become present in the system.
234 */
235void __init smp_init_cpus(void)
236{
237 void __iomem *scu_base = scu_base_addr();
238
239 unsigned int i, ncores;
240
241 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
242
243 for (i = 0; i < ncores; i++)
244 set_cpu_possible(i, true);
245
246 set_smp_cross_call(gic_raise_softirq);
247}
248
249static void __init msm8625_boot_vector_init(uint32_t *boot_vector,
250 unsigned long entry)
251{
252 if (!boot_vector)
253 return;
254 msm8625_boot_vector = boot_vector;
255
256 msm8625_boot_vector[0] = 0xE51FF004; /* ldr pc, 4 */
257 msm8625_boot_vector[1] = entry;
258}
259
260void __init platform_smp_prepare_cpus(unsigned int max_cpus)
261{
262 int i, value;
Taniya Dasfe04d4f2012-03-14 11:13:21 +0530263 void __iomem *second_ptr;
Taniya Das137dc8e2011-12-02 14:50:00 +0530264
265 /*
266 * Initialise the present map, which describes the set of CPUs
267 * actually populated at the present time.
268 */
269 for (i = 0; i < max_cpus; i++)
270 set_cpu_present(i, true);
271
272 scu_enable(scu_base_addr());
273
274 /*
275 * Write the address of secondary startup into the
276 * boot remapper register. The secondary CPU branches to this address.
277 */
Taniya Dasfe04d4f2012-03-14 11:13:21 +0530278 __raw_writel(MSM8625_SECONDARY_PHYS, (MSM_CFG_CTL_BASE + 0x34));
Taniya Das137dc8e2011-12-02 14:50:00 +0530279 mb();
280
Taniya Dasfe04d4f2012-03-14 11:13:21 +0530281 second_ptr = ioremap_nocache(MSM8625_SECONDARY_PHYS, SZ_8);
282 if (!second_ptr) {
283 pr_err("failed to ioremap for secondary core\n");
284 return;
285 }
Taniya Das137dc8e2011-12-02 14:50:00 +0530286
Taniya Dasfe04d4f2012-03-14 11:13:21 +0530287 msm8625_boot_vector_init(second_ptr,
288 virt_to_phys(msm_secondary_startup));
289 iounmap(second_ptr);
Taniya Das137dc8e2011-12-02 14:50:00 +0530290
291 /* Enable boot remapper address: bit 26 for core1 */
292 value = __raw_readl(MSM_CFG_CTL_BASE + 0x30);
293 __raw_writel(value | (0x4 << 24), MSM_CFG_CTL_BASE + 0x30) ;
294 mb();
295}