blob: 4a255cf8cd17498f791befb5f1eee24db8c2ca8a [file] [log] [blame]
Arnd Bergmann19fe0472005-10-31 20:08:38 -05001/*
2 * SMP support for BPA machines.
3 *
4 * Dave Engebretsen, Peter Bergner, and
5 * Mike Corrigan {engebret|bergner|mikec}@us.ibm.com
6 *
7 * Plus various changes from other IBM teams...
8 *
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.
13 */
14
15#undef DEBUG
16
Arnd Bergmann19fe0472005-10-31 20:08:38 -050017#include <linux/kernel.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050018#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>
Kay Sieversedbaa602011-12-21 16:26:03 -080026#include <linux/device.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050027#include <linux/cpu.h>
28
29#include <asm/ptrace.h>
Arun Sharma60063492011-07-26 16:09:06 -070030#include <linux/atomic.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050031#include <asm/irq.h>
32#include <asm/page.h>
33#include <asm/pgtable.h>
34#include <asm/io.h>
35#include <asm/prom.h>
36#include <asm/smp.h>
37#include <asm/paca.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050038#include <asm/machdep.h>
39#include <asm/cputable.h>
40#include <asm/firmware.h>
41#include <asm/system.h>
42#include <asm/rtas.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100043#include <asm/cputhreads.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050044
45#include "interrupt.h"
will schmidtaa39be02007-10-30 06:24:19 +110046#include <asm/udbg.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050047
48#ifdef DEBUG
49#define DBG(fmt...) udbg_printf(fmt)
50#else
51#define DBG(fmt...)
52#endif
53
54/*
Milton Miller6a75a6b2008-10-20 15:37:03 +000055 * 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.
Arnd Bergmann19fe0472005-10-31 20:08:38 -050057 */
58static cpumask_t of_spin_map;
59
Arnd Bergmann19fe0472005-10-31 20:08:38 -050060/**
61 * smp_startup_cpu() - start the given cpu
62 *
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.
66 *
67 * Returns:
68 * 0 - failure
69 * 1 - success
70 */
71static inline int __devinit smp_startup_cpu(unsigned int lcpu)
72{
73 int status;
74 unsigned long start_here = __pa((u32)*((unsigned long *)
Olof Johanssonf39b7a52006-08-11 00:07:08 -050075 generic_secondary_smp_init));
Arnd Bergmann19fe0472005-10-31 20:08:38 -050076 unsigned int pcpu;
77 int start_cpu;
78
KOSAKI Motohiro104699c2011-04-28 05:07:23 +000079 if (cpumask_test_cpu(lcpu, &of_spin_map))
Arnd Bergmann19fe0472005-10-31 20:08:38 -050080 /* Already started by OF and sitting in spin loop */
81 return 1;
82
83 pcpu = get_hard_smp_processor_id(lcpu);
84
85 /* Fixup atomic count: it exited inside IRQ handler. */
Al Virob5e2fc12006-01-12 01:06:01 -080086 task_thread_info(paca[lcpu].__current)->preempt_count = 0;
Arnd Bergmann19fe0472005-10-31 20:08:38 -050087
88 /*
89 * If the RTAS start-cpu token does not exist then presume the
90 * cpu is already spinning.
91 */
92 start_cpu = rtas_token("start-cpu");
93 if (start_cpu == RTAS_UNKNOWN_SERVICE)
94 return 1;
95
96 status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
97 if (status != 0) {
98 printk(KERN_ERR "start-cpu failed: %i\n", status);
99 return 0;
100 }
101
102 return 1;
103}
104
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500105static int __init smp_iic_probe(void)
106{
107 iic_request_IPIs();
108
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000109 return cpumask_weight(cpu_possible_mask);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500110}
111
Arnd Bergmann960cedb2008-11-28 09:51:24 +0000112static void __devinit smp_cell_setup_cpu(int cpu)
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500113{
114 if (cpu != boot_cpuid)
115 iic_setup_cpu();
Arnd Bergmann960cedb2008-11-28 09:51:24 +0000116
117 /*
118 * change default DABRX to allow user watchpoints
119 */
120 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500121}
122
Michael Ellermande300972011-04-11 21:46:19 +0000123static int __devinit smp_cell_kick_cpu(int nr)
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500124{
125 BUG_ON(nr < 0 || nr >= NR_CPUS);
126
127 if (!smp_startup_cpu(nr))
Michael Ellermande300972011-04-11 21:46:19 +0000128 return -ENOENT;
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500129
130 /*
131 * The processor is currently spinning, waiting for the
132 * cpu_start field to become non-zero After we set cpu_start,
133 * the processor will continue on to secondary_start
134 */
135 paca[nr].cpu_start = 1;
Michael Ellermande300972011-04-11 21:46:19 +0000136
137 return 0;
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500138}
139
140static int smp_cell_cpu_bootable(unsigned int nr)
141{
142 /* Special case - we inhibit secondary thread startup
143 * during boot if the user requests it. Odd-numbered
144 * cpus are assumed to be secondary threads.
145 */
146 if (system_state < SYSTEM_RUNNING &&
147 cpu_has_feature(CPU_FTR_SMT) &&
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000148 !smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500149 return 0;
150
151 return 1;
152}
153static struct smp_ops_t bpa_iic_smp_ops = {
Milton Millerd5a1c192011-05-24 20:34:18 +0000154 .message_pass = iic_message_pass,
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500155 .probe = smp_iic_probe,
156 .kick_cpu = smp_cell_kick_cpu,
Arnd Bergmann960cedb2008-11-28 09:51:24 +0000157 .setup_cpu = smp_cell_setup_cpu,
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500158 .cpu_bootable = smp_cell_cpu_bootable,
159};
160
161/* This is called very early */
162void __init smp_init_cell(void)
163{
164 int i;
165
166 DBG(" -> smp_init_cell()\n");
167
168 smp_ops = &bpa_iic_smp_ops;
169
170 /* Mark threads which are still spinning in hold loops. */
171 if (cpu_has_feature(CPU_FTR_SMT)) {
172 for_each_present_cpu(i) {
Milton Miller6a75a6b2008-10-20 15:37:03 +0000173 if (cpu_thread_in_core(i) == 0)
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000174 cpumask_set_cpu(i, &of_spin_map);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500175 }
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000176 } else
177 cpumask_copy(&of_spin_map, cpu_present_mask);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500178
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000179 cpumask_clear_cpu(boot_cpuid, &of_spin_map);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500180
181 /* Non-lpar has additional take/give timebase */
182 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
Benjamin Herrenschmidtc4007a22009-06-16 16:42:50 +0000183 smp_ops->give_timebase = rtas_give_timebase;
184 smp_ops->take_timebase = rtas_take_timebase;
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500185 }
186
187 DBG(" <- smp_init_cell()\n");
188}