2 * SMP support for pSeries machines.
4 * Dave Engebretsen, Peter Bergner, and
5 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
7 * Plus various changes from other IBM teams...
9 * This program is free software; you can redistribute it and/or
10 * modify it under the terms of the GNU General Public License
11 * as published by the Free Software Foundation; either version
12 * 2 of the License, or (at your option) any later version.
17 #include <linux/kernel.h>
18 #include <linux/module.h>
19 #include <linux/sched.h>
20 #include <linux/smp.h>
21 #include <linux/interrupt.h>
22 #include <linux/delay.h>
23 #include <linux/init.h>
24 #include <linux/spinlock.h>
25 #include <linux/cache.h>
26 #include <linux/err.h>
27 #include <linux/sysdev.h>
28 #include <linux/cpu.h>
30 #include <asm/ptrace.h>
31 #include <asm/atomic.h>
34 #include <asm/pgtable.h>
40 #include <asm/machdep.h>
42 #include <asm/cputable.h>
43 #include <asm/firmware.h>
44 #include <asm/system.h>
46 #include <asm/pSeries_reconfig.h>
48 #include <asm/vdso_datapage.h>
49 #include <asm/cputhreads.h>
51 #include "plpar_wrappers.h"
56 * The primary thread of each non-boot processor is recorded here before
59 static cpumask_t of_spin_map;
61 extern void generic_secondary_smp_init(unsigned long);
64 * smp_startup_cpu() - start the given cpu
66 * At boot time, there is nothing to do for primary threads which were
67 * started from Open Firmware. For anything else, call RTAS with the
68 * appropriate start location.
74 static inline int __devinit smp_startup_cpu(unsigned int lcpu)
77 unsigned long start_here = __pa((u32)*((unsigned long *)
78 generic_secondary_smp_init));
82 if (cpu_isset(lcpu, of_spin_map))
83 /* Already started by OF and sitting in spin loop */
86 pcpu = get_hard_smp_processor_id(lcpu);
88 /* Fixup atomic count: it exited inside IRQ handler. */
89 task_thread_info(paca[lcpu].__current)->preempt_count = 0;
92 * If the RTAS start-cpu token does not exist then presume the
93 * cpu is already spinning.
95 start_cpu = rtas_token("start-cpu");
96 if (start_cpu == RTAS_UNKNOWN_SERVICE)
99 status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, pcpu);
101 printk(KERN_ERR "start-cpu failed: %i\n", status);
109 static inline void smp_xics_do_message(int cpu, int msg)
111 set_bit(msg, &xics_ipi_message[cpu].value);
116 static void smp_xics_message_pass(int target, int msg)
120 if (target < NR_CPUS) {
121 smp_xics_do_message(target, msg);
123 for_each_online_cpu(i) {
124 if (target == MSG_ALL_BUT_SELF
125 && i == smp_processor_id())
127 smp_xics_do_message(i, msg);
132 static int __init smp_xics_probe(void)
136 return cpus_weight(cpu_possible_map);
139 static void __devinit smp_xics_setup_cpu(int cpu)
141 if (cpu != boot_cpuid)
144 if (firmware_has_feature(FW_FEATURE_SPLPAR))
147 cpu_clear(cpu, of_spin_map);
150 #endif /* CONFIG_XICS */
152 static DEFINE_SPINLOCK(timebase_lock);
153 static unsigned long timebase = 0;
155 static void __devinit pSeries_give_timebase(void)
157 spin_lock(&timebase_lock);
158 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL);
160 spin_unlock(&timebase_lock);
164 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL);
167 static void __devinit pSeries_take_timebase(void)
171 spin_lock(&timebase_lock);
172 set_tb(timebase >> 32, timebase & 0xffffffff);
174 spin_unlock(&timebase_lock);
177 static void __devinit smp_pSeries_kick_cpu(int nr)
179 BUG_ON(nr < 0 || nr >= NR_CPUS);
181 if (!smp_startup_cpu(nr))
185 * The processor is currently spinning, waiting for the
186 * cpu_start field to become non-zero After we set cpu_start,
187 * the processor will continue on to secondary_start
189 paca[nr].cpu_start = 1;
192 static int smp_pSeries_cpu_bootable(unsigned int nr)
194 /* Special case - we inhibit secondary thread startup
195 * during boot if the user requests it. Odd-numbered
196 * cpus are assumed to be secondary threads.
198 if (system_state < SYSTEM_RUNNING &&
199 cpu_has_feature(CPU_FTR_SMT) &&
200 !smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
206 static struct smp_ops_t pSeries_mpic_smp_ops = {
207 .message_pass = smp_mpic_message_pass,
208 .probe = smp_mpic_probe,
209 .kick_cpu = smp_pSeries_kick_cpu,
210 .setup_cpu = smp_mpic_setup_cpu,
214 static struct smp_ops_t pSeries_xics_smp_ops = {
215 .message_pass = smp_xics_message_pass,
216 .probe = smp_xics_probe,
217 .kick_cpu = smp_pSeries_kick_cpu,
218 .setup_cpu = smp_xics_setup_cpu,
219 .cpu_bootable = smp_pSeries_cpu_bootable,
223 /* This is called very early */
224 static void __init smp_init_pseries(void)
228 pr_debug(" -> smp_init_pSeries()\n");
230 /* Mark threads which are still spinning in hold loops. */
231 if (cpu_has_feature(CPU_FTR_SMT)) {
232 for_each_present_cpu(i) {
235 * Even-numbered logical cpus correspond to
238 cpu_set(i, of_spin_map);
241 of_spin_map = cpu_present_map;
244 cpu_clear(boot_cpuid, of_spin_map);
246 /* Non-lpar has additional take/give timebase */
247 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
248 smp_ops->give_timebase = pSeries_give_timebase;
249 smp_ops->take_timebase = pSeries_take_timebase;
252 pr_debug(" <- smp_init_pSeries()\n");
256 void __init smp_init_pseries_mpic(void)
258 smp_ops = &pSeries_mpic_smp_ops;
264 void __init smp_init_pseries_xics(void)
266 smp_ops = &pSeries_xics_smp_ops;