upload tizen1.0 source
[kernel/linux-2.6.36.git] / arch / arm / mach-ux500 / platsmp.c
1 /*
2  * Copyright (C) 2002 ARM Ltd.
3  * Copyright (C) 2008 STMicroelctronics.
4  * Copyright (C) 2009 ST-Ericsson.
5  * Author: Srinidhi Kasagar <srinidhi.kasagar@stericsson.com>
6  *
7  * This file is based on arm realview platform
8  *
9  * This program is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License version 2 as
11  * published by the Free Software Foundation.
12  */
13 #include <linux/init.h>
14 #include <linux/errno.h>
15 #include <linux/delay.h>
16 #include <linux/device.h>
17 #include <linux/smp.h>
18 #include <linux/io.h>
19
20 #include <asm/cacheflush.h>
21 #include <asm/localtimer.h>
22 #include <asm/smp_scu.h>
23 #include <mach/hardware.h>
24
25 /*
26  * control for which core is the next to come out of the secondary
27  * boot "holding pen"
28  */
29 volatile int __cpuinitdata pen_release = -1;
30
31 static unsigned int __init get_core_count(void)
32 {
33         return scu_get_core_count(__io_address(UX500_SCU_BASE));
34 }
35
36 /*
37  * Write pen_release in a way that is guaranteed to be visible to all
38  * observers, irrespective of whether they're taking part in coherency
39  * or not.  This is necessary for the hotplug code to work reliably.
40  */
41 static void write_pen_release(int val)
42 {
43         pen_release = val;
44         smp_wmb();
45         __cpuc_flush_dcache_area((void *)&pen_release, sizeof(pen_release));
46         outer_clean_range(__pa(&pen_release), __pa(&pen_release + 1));
47 }
48
49 static DEFINE_SPINLOCK(boot_lock);
50
51 void __cpuinit platform_secondary_init(unsigned int cpu)
52 {
53         trace_hardirqs_off();
54
55         /*
56          * if any interrupts are already enabled for the primary
57          * core (e.g. timer irq), then they will not have been enabled
58          * for us: do so
59          */
60         gic_cpu_init(0, __io_address(UX500_GIC_CPU_BASE));
61
62         /*
63          * let the primary processor know we're out of the
64          * pen, then head off into the C entry point
65          */
66         write_pen_release(-1);
67
68         /*
69          * Synchronise with the boot thread.
70          */
71         spin_lock(&boot_lock);
72         spin_unlock(&boot_lock);
73 }
74
75 int __cpuinit boot_secondary(unsigned int cpu, struct task_struct *idle)
76 {
77         unsigned long timeout;
78
79         /*
80          * set synchronisation state between this boot processor
81          * and the secondary one
82          */
83         spin_lock(&boot_lock);
84
85         /*
86          * The secondary processor is waiting to be released from
87          * the holding pen - release it, then wait for it to flag
88          * that it has been released by resetting pen_release.
89          */
90         write_pen_release(cpu);
91
92         timeout = jiffies + (1 * HZ);
93         while (time_before(jiffies, timeout)) {
94                 if (pen_release == -1)
95                         break;
96         }
97
98         /*
99          * now the secondary core is starting up let it run its
100          * calibrations, then wait for it to finish
101          */
102         spin_unlock(&boot_lock);
103
104         return pen_release != -1 ? -ENOSYS : 0;
105 }
106
107 static void __init wakeup_secondary(void)
108 {
109         /*
110          * write the address of secondary startup into the backup ram register
111          * at offset 0x1FF4, then write the magic number 0xA1FEED01 to the
112          * backup ram register at offset 0x1FF0, which is what boot rom code
113          * is waiting for. This would wake up the secondary core from WFE
114          */
115 #define U8500_CPU1_JUMPADDR_OFFSET 0x1FF4
116         __raw_writel(virt_to_phys(u8500_secondary_startup),
117                 __io_address(UX500_BACKUPRAM0_BASE) +
118                 U8500_CPU1_JUMPADDR_OFFSET);
119
120 #define U8500_CPU1_WAKEMAGIC_OFFSET 0x1FF0
121         __raw_writel(0xA1FEED01,
122                 __io_address(UX500_BACKUPRAM0_BASE) +
123                 U8500_CPU1_WAKEMAGIC_OFFSET);
124
125         /* make sure write buffer is drained */
126         mb();
127 }
128
129 /*
130  * Initialise the CPU possible map early - this describes the CPUs
131  * which may be present or become present in the system.
132  */
133 void __init smp_init_cpus(void)
134 {
135         unsigned int i, ncores = get_core_count();
136
137         for (i = 0; i < ncores; i++)
138                 set_cpu_possible(i, true);
139 }
140
141 void __init smp_prepare_cpus(unsigned int max_cpus)
142 {
143         unsigned int ncores = get_core_count();
144         unsigned int cpu = smp_processor_id();
145         int i;
146
147         /* sanity check */
148         if (ncores == 0) {
149                 printk(KERN_ERR
150                        "U8500: strange CM count of 0? Default to 1\n");
151                 ncores = 1;
152         }
153
154         if (ncores > num_possible_cpus())       {
155                 printk(KERN_WARNING
156                        "U8500: no. of cores (%d) greater than configured "
157                        "maximum of %d - clipping\n",
158                        ncores, num_possible_cpus());
159                 ncores = num_possible_cpus();
160         }
161
162         smp_store_cpu_info(cpu);
163
164         /*
165          * are we trying to boot more cores than exist?
166          */
167         if (max_cpus > ncores)
168                 max_cpus = ncores;
169
170         /*
171          * Initialise the present map, which describes the set of CPUs
172          * actually populated at the present time.
173          */
174         for (i = 0; i < max_cpus; i++)
175                 set_cpu_present(i, true);
176
177         if (max_cpus > 1) {
178                 /*
179                  * Enable the local timer or broadcast device for the
180                  * boot CPU, but only if we have more than one CPU.
181                  */
182                 percpu_timer_setup();
183                 scu_enable(__io_address(UX500_SCU_BASE));
184                 wakeup_secondary();
185         }
186 }