2 * SMP support for BPA 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>
41 #include <asm/cputable.h>
42 #include <asm/firmware.h>
43 #include <asm/system.h>
45 #include <asm/cputhreads.h>
47 #include "interrupt.h"
51 #define DBG(fmt...) udbg_printf(fmt)
57 * The primary thread of each non-boot processor is recorded here before
60 static cpumask_t of_spin_map
;
62 extern void generic_secondary_smp_init(unsigned long);
65 * smp_startup_cpu() - start the given cpu
67 * At boot time, there is nothing to do for primary threads which were
68 * started from Open Firmware. For anything else, call RTAS with the
69 * appropriate start location.
75 static inline int __devinit
smp_startup_cpu(unsigned int lcpu
)
78 unsigned long start_here
= __pa((u32
)*((unsigned long *)
79 generic_secondary_smp_init
));
83 if (cpu_isset(lcpu
, of_spin_map
))
84 /* Already started by OF and sitting in spin loop */
87 pcpu
= get_hard_smp_processor_id(lcpu
);
89 /* Fixup atomic count: it exited inside IRQ handler. */
90 task_thread_info(paca
[lcpu
].__current
)->preempt_count
= 0;
93 * If the RTAS start-cpu token does not exist then presume the
94 * cpu is already spinning.
96 start_cpu
= rtas_token("start-cpu");
97 if (start_cpu
== RTAS_UNKNOWN_SERVICE
)
100 status
= rtas_call(start_cpu
, 3, 1, NULL
, pcpu
, start_here
, lcpu
);
102 printk(KERN_ERR
"start-cpu failed: %i\n", status
);
109 static void smp_iic_message_pass(int target
, int msg
)
113 if (target
< NR_CPUS
) {
114 iic_cause_IPI(target
, msg
);
116 for_each_online_cpu(i
) {
117 if (target
== MSG_ALL_BUT_SELF
118 && i
== smp_processor_id())
120 iic_cause_IPI(i
, msg
);
125 static int __init
smp_iic_probe(void)
129 return cpus_weight(cpu_possible_map
);
132 static void __devinit
smp_iic_setup_cpu(int cpu
)
134 if (cpu
!= boot_cpuid
)
138 static DEFINE_SPINLOCK(timebase_lock
);
139 static unsigned long timebase
= 0;
141 static void __devinit
cell_give_timebase(void)
143 spin_lock(&timebase_lock
);
144 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL
);
146 spin_unlock(&timebase_lock
);
150 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL
);
153 static void __devinit
cell_take_timebase(void)
157 spin_lock(&timebase_lock
);
158 set_tb(timebase
>> 32, timebase
& 0xffffffff);
160 spin_unlock(&timebase_lock
);
163 static void __devinit
smp_cell_kick_cpu(int nr
)
165 BUG_ON(nr
< 0 || nr
>= NR_CPUS
);
167 if (!smp_startup_cpu(nr
))
171 * The processor is currently spinning, waiting for the
172 * cpu_start field to become non-zero After we set cpu_start,
173 * the processor will continue on to secondary_start
175 paca
[nr
].cpu_start
= 1;
178 static int smp_cell_cpu_bootable(unsigned int nr
)
180 /* Special case - we inhibit secondary thread startup
181 * during boot if the user requests it. Odd-numbered
182 * cpus are assumed to be secondary threads.
184 if (system_state
< SYSTEM_RUNNING
&&
185 cpu_has_feature(CPU_FTR_SMT
) &&
186 !smt_enabled_at_boot
&& cpu_thread_in_core(nr
) != 0)
191 static struct smp_ops_t bpa_iic_smp_ops
= {
192 .message_pass
= smp_iic_message_pass
,
193 .probe
= smp_iic_probe
,
194 .kick_cpu
= smp_cell_kick_cpu
,
195 .setup_cpu
= smp_iic_setup_cpu
,
196 .cpu_bootable
= smp_cell_cpu_bootable
,
199 /* This is called very early */
200 void __init
smp_init_cell(void)
204 DBG(" -> smp_init_cell()\n");
206 smp_ops
= &bpa_iic_smp_ops
;
208 /* Mark threads which are still spinning in hold loops. */
209 if (cpu_has_feature(CPU_FTR_SMT
)) {
210 for_each_present_cpu(i
) {
213 * Even-numbered logical cpus correspond to
216 cpu_set(i
, of_spin_map
);
219 of_spin_map
= cpu_present_map
;
222 cpu_clear(boot_cpuid
, of_spin_map
);
224 /* Non-lpar has additional take/give timebase */
225 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE
) {
226 smp_ops
->give_timebase
= cell_give_timebase
;
227 smp_ops
->take_timebase
= cell_take_timebase
;
230 DBG(" <- smp_init_cell()\n");