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/config.h>
18 #include <linux/kernel.h>
19 #include <linux/module.h>
20 #include <linux/sched.h>
21 #include <linux/smp.h>
22 #include <linux/interrupt.h>
23 #include <linux/delay.h>
24 #include <linux/init.h>
25 #include <linux/spinlock.h>
26 #include <linux/cache.h>
27 #include <linux/err.h>
28 #include <linux/sysdev.h>
29 #include <linux/cpu.h>
31 #include <asm/ptrace.h>
32 #include <asm/atomic.h>
35 #include <asm/pgtable.h>
41 #include <asm/machdep.h>
42 #include <asm/cputable.h>
43 #include <asm/firmware.h>
44 #include <asm/system.h>
47 #include "interrupt.h"
50 #define DBG(fmt...) udbg_printf(fmt)
56 * The primary thread of each non-boot processor is recorded here before
59 static cpumask_t of_spin_map
;
61 extern void pSeries_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 pSeries_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 paca
[lcpu
].__current
->thread_info
->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
, lcpu
);
101 printk(KERN_ERR
"start-cpu failed: %i\n", status
);
108 static void smp_iic_message_pass(int target
, int msg
)
112 if (target
< NR_CPUS
) {
113 iic_cause_IPI(target
, msg
);
115 for_each_online_cpu(i
) {
116 if (target
== MSG_ALL_BUT_SELF
117 && i
== smp_processor_id())
119 iic_cause_IPI(i
, msg
);
124 static int __init
smp_iic_probe(void)
128 return cpus_weight(cpu_possible_map
);
131 static void __devinit
smp_iic_setup_cpu(int cpu
)
133 if (cpu
!= boot_cpuid
)
137 static DEFINE_SPINLOCK(timebase_lock
);
138 static unsigned long timebase
= 0;
140 static void __devinit
cell_give_timebase(void)
142 spin_lock(&timebase_lock
);
143 rtas_call(rtas_token("freeze-time-base"), 0, 1, NULL
);
145 spin_unlock(&timebase_lock
);
149 rtas_call(rtas_token("thaw-time-base"), 0, 1, NULL
);
152 static void __devinit
cell_take_timebase(void)
156 spin_lock(&timebase_lock
);
157 set_tb(timebase
>> 32, timebase
& 0xffffffff);
159 spin_unlock(&timebase_lock
);
162 static void __devinit
smp_cell_kick_cpu(int nr
)
164 BUG_ON(nr
< 0 || nr
>= NR_CPUS
);
166 if (!smp_startup_cpu(nr
))
170 * The processor is currently spinning, waiting for the
171 * cpu_start field to become non-zero After we set cpu_start,
172 * the processor will continue on to secondary_start
174 paca
[nr
].cpu_start
= 1;
177 static int smp_cell_cpu_bootable(unsigned int nr
)
179 /* Special case - we inhibit secondary thread startup
180 * during boot if the user requests it. Odd-numbered
181 * cpus are assumed to be secondary threads.
183 if (system_state
< SYSTEM_RUNNING
&&
184 cpu_has_feature(CPU_FTR_SMT
) &&
185 !smt_enabled_at_boot
&& nr
% 2 != 0)
190 static struct smp_ops_t bpa_iic_smp_ops
= {
191 .message_pass
= smp_iic_message_pass
,
192 .probe
= smp_iic_probe
,
193 .kick_cpu
= smp_cell_kick_cpu
,
194 .setup_cpu
= smp_iic_setup_cpu
,
195 .cpu_bootable
= smp_cell_cpu_bootable
,
198 /* This is called very early */
199 void __init
smp_init_cell(void)
203 DBG(" -> smp_init_cell()\n");
205 smp_ops
= &bpa_iic_smp_ops
;
207 /* Mark threads which are still spinning in hold loops. */
208 if (cpu_has_feature(CPU_FTR_SMT
)) {
209 for_each_present_cpu(i
) {
212 * Even-numbered logical cpus correspond to
215 cpu_set(i
, of_spin_map
);
218 of_spin_map
= cpu_present_map
;
221 cpu_clear(boot_cpuid
, of_spin_map
);
223 /* Non-lpar has additional take/give timebase */
224 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE
) {
225 smp_ops
->give_timebase
= cell_give_timebase
;
226 smp_ops
->take_timebase
= cell_take_timebase
;
229 DBG(" <- smp_init_cell()\n");