blob: dbb641ea90dd6105324ad53844cee8b800c594ce [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>
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>
29
30#include <asm/ptrace.h>
31#include <asm/atomic.h>
32#include <asm/irq.h>
33#include <asm/page.h>
34#include <asm/pgtable.h>
35#include <asm/io.h>
36#include <asm/prom.h>
37#include <asm/smp.h>
38#include <asm/paca.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050039#include <asm/machdep.h>
40#include <asm/cputable.h>
41#include <asm/firmware.h>
42#include <asm/system.h>
43#include <asm/rtas.h>
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +100044#include <asm/cputhreads.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050045
46#include "interrupt.h"
will schmidtaa39be02007-10-30 06:24:19 +110047#include <asm/udbg.h>
Arnd Bergmann19fe0472005-10-31 20:08:38 -050048
49#ifdef DEBUG
50#define DBG(fmt...) udbg_printf(fmt)
51#else
52#define DBG(fmt...)
53#endif
54
55/*
Milton Miller6a75a6b2008-10-20 15:37:03 +000056 * The Primary thread of each non-boot processor was started from the OF client
57 * interface by prom_hold_cpus and is spinning on secondary_hold_spinloop.
Arnd Bergmann19fe0472005-10-31 20:08:38 -050058 */
59static cpumask_t of_spin_map;
60
Arnd Bergmann19fe0472005-10-31 20:08:38 -050061/**
62 * smp_startup_cpu() - start the given cpu
63 *
64 * At boot time, there is nothing to do for primary threads which were
65 * started from Open Firmware. For anything else, call RTAS with the
66 * appropriate start location.
67 *
68 * Returns:
69 * 0 - failure
70 * 1 - success
71 */
72static inline int __devinit smp_startup_cpu(unsigned int lcpu)
73{
74 int status;
75 unsigned long start_here = __pa((u32)*((unsigned long *)
Olof Johanssonf39b7a52006-08-11 00:07:08 -050076 generic_secondary_smp_init));
Arnd Bergmann19fe0472005-10-31 20:08:38 -050077 unsigned int pcpu;
78 int start_cpu;
79
KOSAKI Motohiro104699c2011-04-28 05:07:23 +000080 if (cpumask_test_cpu(lcpu, &of_spin_map))
Arnd Bergmann19fe0472005-10-31 20:08:38 -050081 /* Already started by OF and sitting in spin loop */
82 return 1;
83
84 pcpu = get_hard_smp_processor_id(lcpu);
85
86 /* Fixup atomic count: it exited inside IRQ handler. */
Al Virob5e2fc12006-01-12 01:06:01 -080087 task_thread_info(paca[lcpu].__current)->preempt_count = 0;
Arnd Bergmann19fe0472005-10-31 20:08:38 -050088
89 /*
90 * If the RTAS start-cpu token does not exist then presume the
91 * cpu is already spinning.
92 */
93 start_cpu = rtas_token("start-cpu");
94 if (start_cpu == RTAS_UNKNOWN_SERVICE)
95 return 1;
96
97 status = rtas_call(start_cpu, 3, 1, NULL, pcpu, start_here, lcpu);
98 if (status != 0) {
99 printk(KERN_ERR "start-cpu failed: %i\n", status);
100 return 0;
101 }
102
103 return 1;
104}
105
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500106static int __init smp_iic_probe(void)
107{
108 iic_request_IPIs();
109
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000110 return cpumask_weight(cpu_possible_mask);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500111}
112
Arnd Bergmann960cedb2008-11-28 09:51:24 +0000113static void __devinit smp_cell_setup_cpu(int cpu)
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500114{
115 if (cpu != boot_cpuid)
116 iic_setup_cpu();
Arnd Bergmann960cedb2008-11-28 09:51:24 +0000117
118 /*
119 * change default DABRX to allow user watchpoints
120 */
121 mtspr(SPRN_DABRX, DABRX_KERNEL | DABRX_USER);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500122}
123
Michael Ellermande300972011-04-11 21:46:19 +0000124static int __devinit smp_cell_kick_cpu(int nr)
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500125{
126 BUG_ON(nr < 0 || nr >= NR_CPUS);
127
128 if (!smp_startup_cpu(nr))
Michael Ellermande300972011-04-11 21:46:19 +0000129 return -ENOENT;
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500130
131 /*
132 * The processor is currently spinning, waiting for the
133 * cpu_start field to become non-zero After we set cpu_start,
134 * the processor will continue on to secondary_start
135 */
136 paca[nr].cpu_start = 1;
Michael Ellermande300972011-04-11 21:46:19 +0000137
138 return 0;
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500139}
140
141static int smp_cell_cpu_bootable(unsigned int nr)
142{
143 /* Special case - we inhibit secondary thread startup
144 * during boot if the user requests it. Odd-numbered
145 * cpus are assumed to be secondary threads.
146 */
147 if (system_state < SYSTEM_RUNNING &&
148 cpu_has_feature(CPU_FTR_SMT) &&
Benjamin Herrenschmidt8d089082007-10-25 15:27:44 +1000149 !smt_enabled_at_boot && cpu_thread_in_core(nr) != 0)
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500150 return 0;
151
152 return 1;
153}
154static struct smp_ops_t bpa_iic_smp_ops = {
Milton Millerd5a1c192011-05-24 20:34:18 +0000155 .message_pass = iic_message_pass,
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500156 .probe = smp_iic_probe,
157 .kick_cpu = smp_cell_kick_cpu,
Arnd Bergmann960cedb2008-11-28 09:51:24 +0000158 .setup_cpu = smp_cell_setup_cpu,
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500159 .cpu_bootable = smp_cell_cpu_bootable,
160};
161
162/* This is called very early */
163void __init smp_init_cell(void)
164{
165 int i;
166
167 DBG(" -> smp_init_cell()\n");
168
169 smp_ops = &bpa_iic_smp_ops;
170
171 /* Mark threads which are still spinning in hold loops. */
172 if (cpu_has_feature(CPU_FTR_SMT)) {
173 for_each_present_cpu(i) {
Milton Miller6a75a6b2008-10-20 15:37:03 +0000174 if (cpu_thread_in_core(i) == 0)
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000175 cpumask_set_cpu(i, &of_spin_map);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500176 }
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000177 } else
178 cpumask_copy(&of_spin_map, cpu_present_mask);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500179
KOSAKI Motohiro104699c2011-04-28 05:07:23 +0000180 cpumask_clear_cpu(boot_cpuid, &of_spin_map);
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500181
182 /* Non-lpar has additional take/give timebase */
183 if (rtas_token("freeze-time-base") != RTAS_UNKNOWN_SERVICE) {
Benjamin Herrenschmidtc4007a22009-06-16 16:42:50 +0000184 smp_ops->give_timebase = rtas_give_timebase;
185 smp_ops->take_timebase = rtas_take_timebase;
Arnd Bergmann19fe0472005-10-31 20:08:38 -0500186 }
187
188 DBG(" <- smp_init_cell()\n");
189}