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/sched.h>
19 #include <linux/smp.h>
20 #include <linux/interrupt.h>
21 #include <linux/delay.h>
22 #include <linux/init.h>
23 #include <linux/spinlock.h>
24 #include <linux/cache.h>
25 #include <linux/err.h>
26 #include <linux/device.h>
27 #include <linux/cpu.h>
29 #include <asm/ptrace.h>
30 #include <linux/atomic.h>
33 #include <asm/pgtable.h>
38 #include <asm/machdep.h>
39 #include <asm/cputable.h>
40 #include <asm/firmware.h>
42 #include <asm/cputhreads.h>
43 #include <asm/code-patching.h>
45 #include "interrupt.h"
49 #define DBG(fmt...) udbg_printf(fmt)
55 * The Primary thread of each non-boot processor was started from the OF client
56 * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
58 static cpumask_t of_spin_map
;
61 * smp_startup_cpu() - start the given cpu
63 * At boot time, there is nothing to do for primary threads which were
64 * started from Open Firmware. For anything else, call RTAS with the
65 * appropriate start location.
71 static inline int smp_startup_cpu(unsigned int lcpu
)
74 unsigned long start_here
=
75 __pa(ppc_function_entry(generic_secondary_smp_init
));
79 if (cpumask_test_cpu(lcpu
, &of_spin_map
))
80 /* Already started by OF and sitting in spin loop */
83 pcpu
= get_hard_smp_processor_id(lcpu
);
85 /* Fixup atomic count: it exited inside IRQ handler. */
86 task_thread_info(paca
[lcpu
].__current
)->preempt_count
= 0;
89 * If the RTAS start-cpu token does not exist then presume the
90 * cpu is already spinning.
92 start_cpu
= rtas_token("start-cpu");
93 if (start_cpu
== RTAS_UNKNOWN_SERVICE
)
96 status
= rtas_call(start_cpu
, 3, 1, NULL
, pcpu
, start_here
, lcpu
);
98 printk(KERN_ERR
"start-cpu failed: %i\n", status
);
105 static void smp_cell_setup_cpu(int cpu
)
107 if (cpu
!= boot_cpuid
)
111 * change default DABRX to allow user watchpoints
113 mtspr(SPRN_DABRX
, DABRX_KERNEL
| DABRX_USER
);
116 static int smp_cell_kick_cpu(int nr
)
118 BUG_ON(nr
< 0 || nr
>= NR_CPUS
);
120 if (!smp_startup_cpu(nr
))
124 * The processor is currently spinning, waiting for the
125 * cpu_start field to become non-zero After we set cpu_start,
126 * the processor will continue on to secondary_start
128 paca
[nr
].cpu_start
= 1;
133 static struct smp_ops_t bpa_iic_smp_ops
= {
134 .message_pass
= iic_message_pass
,
135 .probe
= iic_request_IPIs
,
136 .kick_cpu
= smp_cell_kick_cpu
,
137 .setup_cpu
= smp_cell_setup_cpu
,
138 .cpu_bootable
= smp_generic_cpu_bootable
,
141 /* This is called very early */
142 void __init
smp_init_cell(void)
146 DBG(" -> smp_init_cell()\n");
148 smp_ops
= &bpa_iic_smp_ops
;
150 /* Mark threads which are still spinning in hold loops. */
151 if (cpu_has_feature(CPU_FTR_SMT
)) {
152 for_each_present_cpu(i
) {
153 if (cpu_thread_in_core(i
) == 0)
154 cpumask_set_cpu(i
, &of_spin_map
);
157 cpumask_copy(&of_spin_map
, cpu_present_mask
);
159 cpumask_clear_cpu(boot_cpuid
, &of_spin_map
);
161 /* Non-lpar has additional take/give timebase */
162 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE
) {
163 smp_ops
->give_timebase
= rtas_give_timebase
;
164 smp_ops
->take_timebase
= rtas_take_timebase
;
167 DBG(" <- smp_init_cell()\n");