blob: 534fc0ed7609dffbc0880b636d750d8f0e27c1dc [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>
20
21#include <asm/cacheflush.h>
22#include <asm/hardware/gic.h>
23#include <asm/hardware/cache-l2x0.h>
24#include <asm/smp_scu.h>
25#include <asm/unified.h>
26#include <mach/msm_iomap.h>
27#include <mach/smp.h>
28#include "pm.h"
29
30#define MSM_CORE1_RESET 0xA8600590
31/*
32 * control for which core is the next to come out of the secondary
33 * boot "holding pen"
34 */
35int pen_release = -1;
36
37static bool cold_boot_done;
38
39static uint32_t *msm8625_boot_vector;
40
41/*
42 * Write pen_release in a way that is guaranteed to be visible to all
43 * observers, irrespective of whether they're taking part in coherency
44 * or not. This is necessary for the hotplug code to work reliably.
45 */
46static void __cpuinit write_pen_release(int val)
47{
48 pen_release = val;
49 smp_wmb();
50 __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
51 outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
52}
53
54static void __iomem *scu_base_addr(void)
55{
56 return MSM_SCU_BASE;
57}
58
59static DEFINE_SPINLOCK(boot_lock);
60
61void __cpuinit platform_secondary_init(unsigned int cpu)
62{
63 /*
64 * if any interrupts are already enabled for the primary
65 * core (e.g. timer irq), then they will not have been enabled
66 * for us: do so
67 */
68 gic_secondary_init(0);
69
70 /*
71 * let the primary processor know we're out of the
72 * pen, then head off into the C entry point
73 */
74 write_pen_release(-1);
75
76 /*
77 * Synchronise with the boot thread.
78 */
79 spin_lock(&boot_lock);
80 spin_unlock(&boot_lock);
81}
82
83int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
84{
85 unsigned long timeout;
86 void __iomem *base_ptr;
87
88 if (cold_boot_done == false) {
89 base_ptr = ioremap_nocache(MSM_CORE1_RESET, SZ_4);
90 if (!base_ptr)
91 return -ENODEV;
92 /* Reset core 1 out of reset */
93 __raw_writel(0x0, base_ptr);
94 mb();
95 cold_boot_done = true;
96 iounmap(base_ptr);
97 }
98
99 /*
100 * Set synchronisation state between this boot processor
101 * and the secondary one
102 */
103 spin_lock(&boot_lock);
104
105 /*
106 * This is really belt and braces; we hold unintended secondary
107 * CPUs in the holding pen until we're ready for them. However,
108 * since we haven't sent them a soft interrupt, they shouldn't
109 * be there.
110 */
111 write_pen_release(cpu);
112
113 /*
114 * Send the secondary CPU a soft interrupt, thereby causing
115 * the boot monitor to read the system wide flags register,
116 * and branch to the address found there.
117 */
118 gic_raise_softirq(cpumask_of(cpu), 1);
119
120 timeout = jiffies + (1 * HZ);
121 while (time_before(jiffies, timeout)) {
122 smp_rmb();
123 if (pen_release == -1)
124 break;
125
126 udelay(10);
127 }
128
129 /*
130 * now the secondary core is starting up let it run its
131 * calibrations, then wait for it to finish
132 */
133 spin_unlock(&boot_lock);
134
135 return 0;
136}
137
138/*
139 * Initialise the CPU possible map early - this describes the CPUs
140 * which may be present or become present in the system.
141 */
142void __init smp_init_cpus(void)
143{
144 void __iomem *scu_base = scu_base_addr();
145
146 unsigned int i, ncores;
147
148 ncores = scu_base ? scu_get_core_count(scu_base) : 1;
149
150 for (i = 0; i < ncores; i++)
151 set_cpu_possible(i, true);
152
153 set_smp_cross_call(gic_raise_softirq);
154}
155
156static void __init msm8625_boot_vector_init(uint32_t *boot_vector,
157 unsigned long entry)
158{
159 if (!boot_vector)
160 return;
161 msm8625_boot_vector = boot_vector;
162
163 msm8625_boot_vector[0] = 0xE51FF004; /* ldr pc, 4 */
164 msm8625_boot_vector[1] = entry;
165}
166
167void __init platform_smp_prepare_cpus(unsigned int max_cpus)
168{
169 int i, value;
170 void __iomem *second_ptr;
171
172 /*
173 * Initialise the present map, which describes the set of CPUs
174 * actually populated at the present time.
175 */
176 for (i = 0; i < max_cpus; i++)
177 set_cpu_present(i, true);
178
179 scu_enable(scu_base_addr());
180
181 /*
182 * Write the address of secondary startup into the
183 * boot remapper register. The secondary CPU branches to this address.
184 */
185 __raw_writel(MSM8625_SECONDARY_PHYS, (MSM_CFG_CTL_BASE + 0x34));
186 mb();
187
188 second_ptr = ioremap_nocache(MSM8625_SECONDARY_PHYS, SZ_8);
189 if (!second_ptr) {
190 pr_err("failed to ioremap for secondary core\n");
191 return;
192 }
193
194 msm8625_boot_vector_init(second_ptr,
195 virt_to_phys(msm_secondary_startup));
196 iounmap(second_ptr);
197
198 /* Enable boot remapper address: bit 26 for core1 */
199 value = __raw_readl(MSM_CFG_CTL_BASE + 0x30);
200 __raw_writel(value | (0x4 << 24), MSM_CFG_CTL_BASE + 0x30) ;
201 mb();
202}