upload tizen1.0 source
[kernel/linux-2.6.36.git] / arch / arm / mach-s5pv310 / platsmp.c
1 /* linux/arch/arm/mach-s5pv310/platsmp.c
2  *
3  * Copyright (c) 2010 Samsung Electronics Co., Ltd.
4  *              http://www.samsung.com/
5  *
6  * Based on linux/arch/arm/mach-vexpress/platsmp.c
7  *
8  *  Copyright (C) 2002 ARM Ltd.
9  *  All Rights Reserved
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License version 2 as
13  * published by the Free Software Foundation.
14 */
15
16 #include <linux/init.h>
17 #include <linux/errno.h>
18 #include <linux/delay.h>
19 #include <linux/device.h>
20 #include <linux/jiffies.h>
21 #include <linux/smp.h>
22 #include <linux/io.h>
23
24 #include <asm/cacheflush.h>
25 #include <asm/localtimer.h>
26 #include <asm/smp_scu.h>
27 #include <asm/unified.h>
28
29 #include <plat/s5pv310.h>
30
31 #include <mach/hardware.h>
32 #include <mach/regs-clock.h>
33 #include <mach/cpu_revision.h>
34
35 #define SCU_CTRL                0x00
36 #define   IC_STANDBY_EN         (1 << 6)
37 #define   SCU_STANDBY_EN        (1 << 5)
38
39 extern void s5pv310_secondary_startup(void);
40 extern inline void platform_do_lowpower(unsigned int cpu);
41
42 #define CPU1_BOOT_REG (s5pv310_subrev() == 0 ? S5P_VA_SYSRAM : S5P_INFORM5)
43
44 /*
45  * control for which core is the next to come out of the secondary
46  * boot "holding pen"
47  */
48
49 volatile int pen_release = -1;
50
51 /*
52  * Write pen_release in a way that is guaranteed to be visible to all
53  * observers, irrespective of whether they're taking part in coherency
54  * or not.  This is necessary for the hotplug code to work reliably.
55  */
56 static void write_pen_release(int val)
57 {
58         pen_release = val;
59         smp_wmb();
60         __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
61         outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
62 }
63
64 static void __iomem *scu_base_addr(void)
65 {
66         return (void __iomem *)(S5P_VA_SCU);
67 }
68
69 static DEFINE_SPINLOCK(boot_lock);
70
71 #ifdef CONFIG_VFP
72 static void vfp_enable(void *unused)
73 {
74         u32 access = get_copro_access();
75
76         /*
77          * Enable full access to VFP (cp10 and cp11)
78          */
79         set_copro_access(access | CPACC_FULL(10) | CPACC_FULL(11));
80 }
81 #endif
82
83 void __cpuinit platform_secondary_init(unsigned int cpu)
84 {
85 #ifdef CONFIG_VFP
86         unsigned int cpu_arch = cpu_architecture();
87
88         if (cpu_arch >= CPU_ARCH_ARMv6)
89                 vfp_enable(NULL);
90 #endif
91
92         trace_hardirqs_off();
93
94         /*
95          * if any interrupts are already enabled for the primary
96          * core (e.g. timer irq), then they will not have been enabled
97          * for us: do so
98          */
99         gic_cpu_init(0, gic_cpu_base_addr);
100
101         /*
102          * let the primary processor know we're out of the
103          * pen, then head off into the C entry point
104          */
105         write_pen_release(-1);
106
107         /*
108          * Synchronise with the boot thread.
109          */
110         spin_lock(&boot_lock);
111         spin_unlock(&boot_lock);
112 }
113
114 int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
115 {
116         unsigned long timeout;
117
118         /*
119          * Set synchronisation state between this boot processor
120          * and the secondary one
121          */
122         spin_lock(&boot_lock);
123
124         /*
125          * The secondary processor is waiting to be released from
126          * the holding pen - release it, then wait for it to flag
127          * that it has been released by resetting pen_release.
128          *
129          * Note that "pen_release" is the hardware CPU ID, whereas
130          * "cpu" is Linux's internal ID.
131          */
132         write_pen_release(cpu);
133
134         if (!(__raw_readl(S5P_ARM_CORE1_STATUS) & S5P_CORE_LOCAL_PWR_EN)) {
135                 __raw_writel(S5P_CORE_LOCAL_PWR_EN,
136                              S5P_ARM_CORE1_CONFIGURATION);
137
138                 timeout = 10;
139
140                 /* wait max 10 ms until cpu1 is on */
141                 while ((__raw_readl(S5P_ARM_CORE1_STATUS)
142                         & S5P_CORE_LOCAL_PWR_EN) != S5P_CORE_LOCAL_PWR_EN) {
143                         if (timeout-- == 0)
144                                 break;
145
146                         mdelay(1);
147                 }
148
149                 if (timeout == 0) {
150                         printk(KERN_ERR "cpu1 power enable failed");
151                         spin_unlock(&boot_lock);
152
153                         return -ETIMEDOUT;
154                 }
155         }
156
157         /*
158          * Send the secondary CPU a soft interrupt, thereby causing
159          * the boot monitor to read the system ram, and branch to
160          * the address found there.
161          */
162         smp_cross_call(cpumask_of(cpu));
163
164         timeout = jiffies + (1 * HZ);
165         while (time_before(jiffies, timeout)) {
166                 smp_rmb();
167
168                 if (!__raw_readl(CPU1_BOOT_REG)) {
169                         __raw_writel(BSYM(virt_to_phys(s5pv310_secondary_startup)),
170                                      CPU1_BOOT_REG);
171                         smp_cross_call(cpumask_of(cpu));
172                 }
173
174                 if (pen_release == -1)
175                         break;
176
177                 udelay(10);
178         }
179
180         /*
181          * now the secondary core is starting up let it run its
182          * calibrations, then wait for it to finish
183          */
184         spin_unlock(&boot_lock);
185
186         return pen_release != -1 ? -ENOSYS : 0;
187 }
188
189 /*
190  * Initialise the CPU possible map early - this describes the CPUs
191  * which may be present or become present in the system.
192  */
193
194 void __init smp_init_cpus(void)
195 {
196         void __iomem *scu_base = scu_base_addr();
197         unsigned int i, ncores;
198
199         ncores = scu_base ? scu_get_core_count(scu_base) : 1;
200
201         /* sanity check */
202         if (ncores == 0) {
203                 printk(KERN_ERR
204                        "S5PV310: strange CM count of 0? Default to 1\n");
205
206                 ncores = 1;
207         }
208
209         if (ncores > NR_CPUS) {
210                 printk(KERN_WARNING
211                        "S5PV310: no. of cores (%d) greater than configured "
212                        "maximum of %d - clipping\n",
213                        ncores, NR_CPUS);
214                 ncores = NR_CPUS;
215         }
216
217         for (i = 0; i < ncores; i++)
218                 set_cpu_possible(i, true);
219 }
220
221 void __init smp_prepare_cpus(unsigned int max_cpus)
222 {
223         unsigned int ncores = num_possible_cpus();
224         unsigned int cpu = smp_processor_id();
225         int i;
226
227         smp_store_cpu_info(cpu);
228
229         /* are we trying to boot more cores than exist? */
230         if (max_cpus > ncores)
231                 max_cpus = ncores;
232
233         /*
234          * Initialise the present map, which describes the set of CPUs
235          * actually populated at the present time.
236          */
237         for (i = 0; i < ncores; i++)
238                 set_cpu_present(i, true);
239
240         /*
241          * Initialise the SCU if there are more than one CPU and let
242          * them know where to start.
243          */
244         if (ncores > 1) {
245                 for (i = max_cpus; i < ncores; i++)
246                         platform_do_lowpower(i);
247
248                 /*
249                  * Enable the local timer or broadcast device for the
250                  * boot CPU, but only if we have more than one CPU.
251                  */
252                 percpu_timer_setup();
253
254                 i = __raw_readl(scu_base_addr() + SCU_CTRL);
255                 i |= SCU_STANDBY_EN;
256                 __raw_writel(i, scu_base_addr() + SCU_CTRL);
257
258                 scu_enable(scu_base_addr());
259
260                 if (max_cpus > 1) {
261                         /*
262                          * Write the address of secondary startup into the
263                          * system-wide flags register. The boot monitor waits
264                          * until it receives a soft interrupt, and then the
265                          * secondary CPU branches to this address.
266                          */
267                         __raw_writel(BSYM(virt_to_phys(s5pv310_secondary_startup)),
268                                      CPU1_BOOT_REG);
269                 }
270         }
271 }