blob: 03674fbe598f3064932e4e14236ad9329076cc07 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * arch/s390/kernel/smp.c
3 *
Heiko Carstens39ce0102007-04-27 16:02:00 +02004 * Copyright IBM Corp. 1999,2007
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com),
Heiko Carstens39ce0102007-04-27 16:02:00 +02006 * Martin Schwidefsky (schwidefsky@de.ibm.com)
7 * Heiko Carstens (heiko.carstens@de.ibm.com)
Linus Torvalds1da177e2005-04-16 15:20:36 -07008 *
Heiko Carstens39ce0102007-04-27 16:02:00 +02009 * based on other smp stuff by
Linus Torvalds1da177e2005-04-16 15:20:36 -070010 * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
11 * (c) 1998 Ingo Molnar
12 *
13 * We work with logical cpu numbering everywhere we can. The only
14 * functions using the real cpu address (got from STAP) are the sigp
15 * functions. For all other functions we use the identity mapping.
16 * That means that cpu_number_map[i] == i for every cpu. cpu_number_map is
17 * used e.g. to find the idle task belonging to a logical cpu. Every array
18 * in the kernel is sorted by the logical cpu number and not by the physical
19 * one which is causing all the confusion with __cpu_logical_map and
20 * cpu_number_map in other architectures.
21 */
22
23#include <linux/module.h>
24#include <linux/init.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025#include <linux/mm.h>
26#include <linux/spinlock.h>
27#include <linux/kernel_stat.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070028#include <linux/delay.h>
29#include <linux/cache.h>
30#include <linux/interrupt.h>
31#include <linux/cpu.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010032#include <linux/timex.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020033#include <linux/bootmem.h>
Michael Holzheu46b05d22007-02-21 10:55:21 +010034#include <asm/ipl.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010035#include <asm/setup.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070036#include <asm/sigp.h>
37#include <asm/pgalloc.h>
38#include <asm/irq.h>
39#include <asm/s390_ext.h>
40#include <asm/cpcmd.h>
41#include <asm/tlbflush.h>
Heiko Carstens2b67fc42007-02-05 21:16:47 +010042#include <asm/timer.h>
Michael Holzheu411ed322007-04-27 16:01:49 +020043#include <asm/lowcore.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070044
Linus Torvalds1da177e2005-04-16 15:20:36 -070045/*
46 * An array with a pointer the lowcore of every CPU.
47 */
Linus Torvalds1da177e2005-04-16 15:20:36 -070048struct _lowcore *lowcore_ptr[NR_CPUS];
Heiko Carstens39ce0102007-04-27 16:02:00 +020049EXPORT_SYMBOL(lowcore_ptr);
Linus Torvalds1da177e2005-04-16 15:20:36 -070050
Heiko Carstens255acee2006-02-17 13:52:46 -080051cpumask_t cpu_online_map = CPU_MASK_NONE;
Heiko Carstens39ce0102007-04-27 16:02:00 +020052EXPORT_SYMBOL(cpu_online_map);
53
Heiko Carstens255acee2006-02-17 13:52:46 -080054cpumask_t cpu_possible_map = CPU_MASK_NONE;
Heiko Carstens39ce0102007-04-27 16:02:00 +020055EXPORT_SYMBOL(cpu_possible_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -070056
57static struct task_struct *current_set[NR_CPUS];
58
Linus Torvalds1da177e2005-04-16 15:20:36 -070059static void smp_ext_bitcall(int, ec_bit_sig);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060
61/*
Jan Glauber63db6e82007-02-21 10:55:06 +010062 * Structure and data for __smp_call_function_map(). This is designed to
63 * minimise static memory requirements. It also looks cleaner.
Linus Torvalds1da177e2005-04-16 15:20:36 -070064 */
65static DEFINE_SPINLOCK(call_lock);
66
67struct call_data_struct {
68 void (*func) (void *info);
69 void *info;
Jan Glauber63db6e82007-02-21 10:55:06 +010070 cpumask_t started;
71 cpumask_t finished;
Linus Torvalds1da177e2005-04-16 15:20:36 -070072 int wait;
73};
74
Heiko Carstens39ce0102007-04-27 16:02:00 +020075static struct call_data_struct *call_data;
Linus Torvalds1da177e2005-04-16 15:20:36 -070076
77/*
78 * 'Call function' interrupt callback
79 */
80static void do_call_function(void)
81{
82 void (*func) (void *info) = call_data->func;
83 void *info = call_data->info;
84 int wait = call_data->wait;
85
Jan Glauber63db6e82007-02-21 10:55:06 +010086 cpu_set(smp_processor_id(), call_data->started);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 (*func)(info);
88 if (wait)
Jan Glauber63db6e82007-02-21 10:55:06 +010089 cpu_set(smp_processor_id(), call_data->finished);;
Linus Torvalds1da177e2005-04-16 15:20:36 -070090}
91
Jan Glauber63db6e82007-02-21 10:55:06 +010092static void __smp_call_function_map(void (*func) (void *info), void *info,
93 int nonatomic, int wait, cpumask_t map)
Linus Torvalds1da177e2005-04-16 15:20:36 -070094{
95 struct call_data_struct data;
Jan Glauber63db6e82007-02-21 10:55:06 +010096 int cpu, local = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -070097
Jan Glauber63db6e82007-02-21 10:55:06 +010098 /*
Heiko Carstens25864162007-03-05 23:35:41 +010099 * Can deadlock when interrupts are disabled or if in wrong context.
Jan Glauber63db6e82007-02-21 10:55:06 +0100100 */
Heiko Carstens25864162007-03-05 23:35:41 +0100101 WARN_ON(irqs_disabled() || in_irq());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Jan Glauber63db6e82007-02-21 10:55:06 +0100103 /*
104 * Check for local function call. We have to have the same call order
105 * as in on_each_cpu() because of machine_restart_smp().
106 */
107 if (cpu_isset(smp_processor_id(), map)) {
108 local = 1;
109 cpu_clear(smp_processor_id(), map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110 }
111
Jan Glauber63db6e82007-02-21 10:55:06 +0100112 cpus_and(map, map, cpu_online_map);
113 if (cpus_empty(map))
114 goto out;
115
Linus Torvalds1da177e2005-04-16 15:20:36 -0700116 data.func = func;
117 data.info = info;
Jan Glauber63db6e82007-02-21 10:55:06 +0100118 data.started = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119 data.wait = wait;
120 if (wait)
Jan Glauber63db6e82007-02-21 10:55:06 +0100121 data.finished = CPU_MASK_NONE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700122
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200123 spin_lock(&call_lock);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700124 call_data = &data;
Jan Glauber63db6e82007-02-21 10:55:06 +0100125
126 for_each_cpu_mask(cpu, map)
127 smp_ext_bitcall(cpu, ec_call_function);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700128
129 /* Wait for response */
Jan Glauber63db6e82007-02-21 10:55:06 +0100130 while (!cpus_equal(map, data.started))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700131 cpu_relax();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700132 if (wait)
Jan Glauber63db6e82007-02-21 10:55:06 +0100133 while (!cpus_equal(map, data.finished))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134 cpu_relax();
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200135 spin_unlock(&call_lock);
Jan Glauber63db6e82007-02-21 10:55:06 +0100136out:
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200137 if (local) {
138 local_irq_disable();
Jan Glauber63db6e82007-02-21 10:55:06 +0100139 func(info);
Heiko Carstens8da1aec2007-07-27 12:29:09 +0200140 local_irq_enable();
141 }
Jan Glauber63db6e82007-02-21 10:55:06 +0100142}
143
144/*
145 * smp_call_function:
146 * @func: the function to run; this must be fast and non-blocking
147 * @info: an arbitrary pointer to pass to the function
148 * @nonatomic: unused
149 * @wait: if true, wait (atomically) until function has completed on other CPUs
150 *
151 * Run a function on all other CPUs.
152 *
Heiko Carstens39ce0102007-04-27 16:02:00 +0200153 * You must not call this function with disabled interrupts, from a
154 * hardware interrupt handler or from a bottom half.
Jan Glauber63db6e82007-02-21 10:55:06 +0100155 */
156int smp_call_function(void (*func) (void *info), void *info, int nonatomic,
157 int wait)
158{
159 cpumask_t map;
160
Heiko Carstens25864162007-03-05 23:35:41 +0100161 preempt_disable();
Jan Glauber63db6e82007-02-21 10:55:06 +0100162 map = cpu_online_map;
163 cpu_clear(smp_processor_id(), map);
164 __smp_call_function_map(func, info, nonatomic, wait, map);
Heiko Carstens25864162007-03-05 23:35:41 +0100165 preempt_enable();
Jan Glauber63db6e82007-02-21 10:55:06 +0100166 return 0;
167}
168EXPORT_SYMBOL(smp_call_function);
169
170/*
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200171 * smp_call_function_single:
172 * @cpu: the CPU where func should run
Jan Glauber63db6e82007-02-21 10:55:06 +0100173 * @func: the function to run; this must be fast and non-blocking
174 * @info: an arbitrary pointer to pass to the function
175 * @nonatomic: unused
176 * @wait: if true, wait (atomically) until function has completed on other CPUs
Jan Glauber63db6e82007-02-21 10:55:06 +0100177 *
178 * Run a function on one processor.
179 *
Heiko Carstens39ce0102007-04-27 16:02:00 +0200180 * You must not call this function with disabled interrupts, from a
181 * hardware interrupt handler or from a bottom half.
Jan Glauber63db6e82007-02-21 10:55:06 +0100182 */
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200183int smp_call_function_single(int cpu, void (*func) (void *info), void *info,
184 int nonatomic, int wait)
Jan Glauber63db6e82007-02-21 10:55:06 +0100185{
Heiko Carstens25864162007-03-05 23:35:41 +0100186 preempt_disable();
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200187 __smp_call_function_map(func, info, nonatomic, wait,
188 cpumask_of_cpu(cpu));
Heiko Carstens25864162007-03-05 23:35:41 +0100189 preempt_enable();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700190 return 0;
191}
Heiko Carstens3bb447f2007-07-27 12:29:08 +0200192EXPORT_SYMBOL(smp_call_function_single);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700193
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100194static void do_send_stop(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700195{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200196 int cpu, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700197
Heiko Carstens39ce0102007-04-27 16:02:00 +0200198 /* stop all processors */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700199 for_each_online_cpu(cpu) {
200 if (cpu == smp_processor_id())
201 continue;
202 do {
203 rc = signal_processor(cpu, sigp_stop);
204 } while (rc == sigp_busy);
205 }
206}
207
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100208static void do_store_status(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700209{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200210 int cpu, rc;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Heiko Carstens39ce0102007-04-27 16:02:00 +0200212 /* store status of all processors in their lowcores (real 0) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700213 for_each_online_cpu(cpu) {
214 if (cpu == smp_processor_id())
215 continue;
216 do {
217 rc = signal_processor_p(
218 (__u32)(unsigned long) lowcore_ptr[cpu], cpu,
219 sigp_store_status_at_address);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200220 } while (rc == sigp_busy);
221 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700222}
223
Heiko Carstens4d284ca2007-02-05 21:18:53 +0100224static void do_wait_for_stop(void)
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100225{
226 int cpu;
227
228 /* Wait for all other cpus to enter stopped state */
229 for_each_online_cpu(cpu) {
230 if (cpu == smp_processor_id())
231 continue;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200232 while (!smp_cpu_not_running(cpu))
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100233 cpu_relax();
234 }
235}
236
Linus Torvalds1da177e2005-04-16 15:20:36 -0700237/*
238 * this function sends a 'stop' sigp to all other CPUs in the system.
239 * it goes straight through.
240 */
241void smp_send_stop(void)
242{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100243 /* Disable all interrupts/machine checks */
Gerald Schaeferc1821c22007-02-05 21:18:17 +0100244 __load_psw_mask(psw_kernel_bits & ~PSW_MASK_MCHECK);
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100245
Heiko Carstens39ce0102007-04-27 16:02:00 +0200246 /* write magic number to zero page (absolute 0) */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700247 lowcore_ptr[smp_processor_id()]->panic_magic = __PANIC_MAGIC;
248
249 /* stop other processors. */
250 do_send_stop();
251
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100252 /* wait until other processors are stopped */
253 do_wait_for_stop();
254
Linus Torvalds1da177e2005-04-16 15:20:36 -0700255 /* store status of other processors. */
256 do_store_status();
257}
258
259/*
260 * Reboot, halt and power_off routines for SMP.
261 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200262void machine_restart_smp(char *__unused)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700263{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100264 smp_send_stop();
265 do_reipl();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700266}
267
268void machine_halt_smp(void)
269{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100270 smp_send_stop();
271 if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0)
272 __cpcmd(vmhalt_cmd, NULL, 0, NULL);
273 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
274 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275}
276
277void machine_power_off_smp(void)
278{
Heiko Carstensc6b5b842006-12-04 15:40:33 +0100279 smp_send_stop();
280 if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0)
281 __cpcmd(vmpoff_cmd, NULL, 0, NULL);
282 signal_processor(smp_processor_id(), sigp_stop_and_store_status);
283 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700284}
285
286/*
287 * This is the main routine where commands issued by other
288 * cpus are handled.
289 */
290
Heiko Carstens2b67fc42007-02-05 21:16:47 +0100291static void do_ext_call_interrupt(__u16 code)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700292{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200293 unsigned long bits;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700294
Heiko Carstens39ce0102007-04-27 16:02:00 +0200295 /*
296 * handle bit signal external calls
297 *
298 * For the ec_schedule signal we have to do nothing. All the work
299 * is done automatically when we return from the interrupt.
300 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 bits = xchg(&S390_lowcore.ext_call_fast, 0);
302
Heiko Carstens39ce0102007-04-27 16:02:00 +0200303 if (test_bit(ec_call_function, &bits))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700304 do_call_function();
305}
306
307/*
308 * Send an external call sigp to another cpu and return without waiting
309 * for its completion.
310 */
311static void smp_ext_bitcall(int cpu, ec_bit_sig sig)
312{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200313 /*
314 * Set signaling bit in lowcore of target cpu and kick it
315 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700316 set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200317 while (signal_processor(cpu, sigp_emergency_signal) == sigp_busy)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318 udelay(10);
319}
320
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800321#ifndef CONFIG_64BIT
Linus Torvalds1da177e2005-04-16 15:20:36 -0700322/*
323 * this function sends a 'purge tlb' signal to another CPU.
324 */
325void smp_ptlb_callback(void *info)
326{
327 local_flush_tlb();
328}
329
330void smp_ptlb_all(void)
331{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200332 on_each_cpu(smp_ptlb_callback, NULL, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700333}
334EXPORT_SYMBOL(smp_ptlb_all);
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800335#endif /* ! CONFIG_64BIT */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336
337/*
338 * this function sends a 'reschedule' IPI to another CPU.
339 * it goes straight through and wastes no time serializing
340 * anything. Worst case is that we lose a reschedule ...
341 */
342void smp_send_reschedule(int cpu)
343{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200344 smp_ext_bitcall(cpu, ec_schedule);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700345}
346
347/*
348 * parameter area for the set/clear control bit callbacks
349 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200350struct ec_creg_mask_parms {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351 unsigned long orvals[16];
352 unsigned long andvals[16];
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200353};
Linus Torvalds1da177e2005-04-16 15:20:36 -0700354
355/*
356 * callback for setting/clearing control bits
357 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200358static void smp_ctl_bit_callback(void *info)
359{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200360 struct ec_creg_mask_parms *pp = info;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700361 unsigned long cregs[16];
362 int i;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200363
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200364 __ctl_store(cregs, 0, 15);
365 for (i = 0; i <= 15; i++)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700366 cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i];
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200367 __ctl_load(cregs, 0, 15);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368}
369
370/*
371 * Set a bit in a control register of all cpus
372 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200373void smp_ctl_set_bit(int cr, int bit)
374{
375 struct ec_creg_mask_parms parms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700376
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200377 memset(&parms.orvals, 0, sizeof(parms.orvals));
378 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700379 parms.orvals[cr] = 1 << bit;
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200380 on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700381}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200382EXPORT_SYMBOL(smp_ctl_set_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700383
384/*
385 * Clear a bit in a control register of all cpus
386 */
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200387void smp_ctl_clear_bit(int cr, int bit)
388{
389 struct ec_creg_mask_parms parms;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700390
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200391 memset(&parms.orvals, 0, sizeof(parms.orvals));
392 memset(&parms.andvals, 0xff, sizeof(parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 parms.andvals[cr] = ~(1L << bit);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200394 on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395}
Heiko Carstens39ce0102007-04-27 16:02:00 +0200396EXPORT_SYMBOL(smp_ctl_clear_bit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700397
Michael Holzheu411ed322007-04-27 16:01:49 +0200398#if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_ZFCPDUMP_MODULE)
399
400/*
401 * zfcpdump_prefix_array holds prefix registers for the following scenario:
402 * 64 bit zfcpdump kernel and 31 bit kernel which is to be dumped. We have to
403 * save its prefix registers, since they get lost, when switching from 31 bit
404 * to 64 bit.
405 */
406unsigned int zfcpdump_prefix_array[NR_CPUS + 1] \
407 __attribute__((__section__(".data")));
408
Heiko Carstens285f6722007-07-10 11:24:13 +0200409static void __init smp_get_save_area(unsigned int cpu, unsigned int phy_cpu)
Michael Holzheu411ed322007-04-27 16:01:49 +0200410{
Michael Holzheu411ed322007-04-27 16:01:49 +0200411 if (ipl_info.type != IPL_TYPE_FCP_DUMP)
412 return;
Heiko Carstens285f6722007-07-10 11:24:13 +0200413 if (cpu >= NR_CPUS) {
414 printk(KERN_WARNING "Registers for cpu %i not saved since dump "
415 "kernel was compiled with NR_CPUS=%i\n", cpu, NR_CPUS);
416 return;
Michael Holzheu411ed322007-04-27 16:01:49 +0200417 }
Heiko Carstens285f6722007-07-10 11:24:13 +0200418 zfcpdump_save_areas[cpu] = alloc_bootmem(sizeof(union save_area));
419 __cpu_logical_map[1] = (__u16) phy_cpu;
420 while (signal_processor(1, sigp_stop_and_store_status) == sigp_busy)
421 cpu_relax();
422 memcpy(zfcpdump_save_areas[cpu],
423 (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE,
424 SAVE_AREA_SIZE);
425#ifdef CONFIG_64BIT
426 /* copy original prefix register */
427 zfcpdump_save_areas[cpu]->s390x.pref_reg = zfcpdump_prefix_array[cpu];
428#endif
Michael Holzheu411ed322007-04-27 16:01:49 +0200429}
430
431union save_area *zfcpdump_save_areas[NR_CPUS + 1];
432EXPORT_SYMBOL_GPL(zfcpdump_save_areas);
433
434#else
Heiko Carstens285f6722007-07-10 11:24:13 +0200435
436static inline void smp_get_save_area(unsigned int cpu, unsigned int phy_cpu) { }
437
438#endif /* CONFIG_ZFCPDUMP || CONFIG_ZFCPDUMP_MODULE */
Michael Holzheu411ed322007-04-27 16:01:49 +0200439
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440/*
441 * Lets check how many CPUs we have.
442 */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200443static unsigned int __init smp_count_cpus(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700444{
Heiko Carstens255acee2006-02-17 13:52:46 -0800445 unsigned int cpu, num_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446 __u16 boot_cpu_addr;
447
448 /*
449 * cpu 0 is the boot cpu. See smp_prepare_boot_cpu.
450 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700451 boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr;
452 current_thread_info()->cpu = 0;
453 num_cpus = 1;
Heiko Carstens255acee2006-02-17 13:52:46 -0800454 for (cpu = 0; cpu <= 65535; cpu++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700455 if ((__u16) cpu == boot_cpu_addr)
456 continue;
Heiko Carstens255acee2006-02-17 13:52:46 -0800457 __cpu_logical_map[1] = (__u16) cpu;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200458 if (signal_processor(1, sigp_sense) == sigp_not_operational)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700459 continue;
Heiko Carstens285f6722007-07-10 11:24:13 +0200460 smp_get_save_area(num_cpus, cpu);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700461 num_cpus++;
462 }
Heiko Carstens39ce0102007-04-27 16:02:00 +0200463 printk("Detected %d CPU's\n", (int) num_cpus);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700464 printk("Boot cpu address %2X\n", boot_cpu_addr);
Heiko Carstens255acee2006-02-17 13:52:46 -0800465 return num_cpus;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700466}
467
468/*
Heiko Carstens39ce0102007-04-27 16:02:00 +0200469 * Activate a secondary processor.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700470 */
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200471int __cpuinit start_secondary(void *cpuvoid)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700472{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200473 /* Setup the cpu */
474 cpu_init();
Nick Piggin5bfb5d62005-11-08 21:39:01 -0800475 preempt_disable();
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100476 /* Enable TOD clock interrupts on the secondary cpu. */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200477 init_cpu_timer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478#ifdef CONFIG_VIRT_TIMER
Martin Schwidefskyd54853e2007-02-05 21:18:19 +0100479 /* Enable cpu timer interrupts on the secondary cpu. */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200480 init_cpu_vtimer();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700481#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 /* Enable pfault pseudo page faults on this cpu. */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100483 pfault_init();
484
Linus Torvalds1da177e2005-04-16 15:20:36 -0700485 /* Mark this cpu as online */
486 cpu_set(smp_processor_id(), cpu_online_map);
487 /* Switch on interrupts */
488 local_irq_enable();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200489 /* Print info about this processor */
490 print_cpu_info(&S390_lowcore.cpu_data);
491 /* cpu_idle will call schedule for us */
492 cpu_idle();
493 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494}
495
496static void __init smp_create_idle(unsigned int cpu)
497{
498 struct task_struct *p;
499
500 /*
501 * don't care about the psw and regs settings since we'll never
502 * reschedule the forked task.
503 */
504 p = fork_idle(cpu);
505 if (IS_ERR(p))
506 panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p));
507 current_set[cpu] = p;
508}
509
Heiko Carstens39ce0102007-04-27 16:02:00 +0200510static int cpu_stopped(int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700511{
512 __u32 status;
513
514 /* Check for stopped state */
Heiko Carstens39ce0102007-04-27 16:02:00 +0200515 if (signal_processor_ps(&status, 0, cpu, sigp_sense) ==
516 sigp_status_stored) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700517 if (status & 0x40)
518 return 1;
519 }
520 return 0;
521}
522
523/* Upping and downing of CPUs */
524
Heiko Carstens39ce0102007-04-27 16:02:00 +0200525int __cpu_up(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526{
527 struct task_struct *idle;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200528 struct _lowcore *cpu_lowcore;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700529 struct stack_frame *sf;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200530 sigp_ccode ccode;
531 int curr_cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700532
533 for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) {
534 __cpu_logical_map[cpu] = (__u16) curr_cpu;
535 if (cpu_stopped(cpu))
536 break;
537 }
538
539 if (!cpu_stopped(cpu))
540 return -ENODEV;
541
542 ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]),
543 cpu, sigp_set_prefix);
Heiko Carstens39ce0102007-04-27 16:02:00 +0200544 if (ccode) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700545 printk("sigp_set_prefix failed for cpu %d "
546 "with condition code %d\n",
547 (int) cpu, (int) ccode);
548 return -EIO;
549 }
550
551 idle = current_set[cpu];
Heiko Carstens39ce0102007-04-27 16:02:00 +0200552 cpu_lowcore = lowcore_ptr[cpu];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700553 cpu_lowcore->kernel_stack = (unsigned long)
Heiko Carstens39ce0102007-04-27 16:02:00 +0200554 task_stack_page(idle) + THREAD_SIZE;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700555 sf = (struct stack_frame *) (cpu_lowcore->kernel_stack
556 - sizeof(struct pt_regs)
557 - sizeof(struct stack_frame));
558 memset(sf, 0, sizeof(struct stack_frame));
559 sf->gprs[9] = (unsigned long) sf;
560 cpu_lowcore->save_area[15] = (unsigned long) sf;
561 __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200562 asm volatile(
563 " stam 0,15,0(%0)"
564 : : "a" (&cpu_lowcore->access_regs_save_area) : "memory");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700565 cpu_lowcore->percpu_offset = __per_cpu_offset[cpu];
Heiko Carstens39ce0102007-04-27 16:02:00 +0200566 cpu_lowcore->current_task = (unsigned long) idle;
567 cpu_lowcore->cpu_data.cpu_nr = cpu;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700568 eieio();
Michael Ryan699ff132006-03-24 03:15:17 -0800569
Heiko Carstens39ce0102007-04-27 16:02:00 +0200570 while (signal_processor(cpu, sigp_restart) == sigp_busy)
Michael Ryan699ff132006-03-24 03:15:17 -0800571 udelay(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700572
573 while (!cpu_online(cpu))
574 cpu_relax();
575 return 0;
576}
577
Heiko Carstens255acee2006-02-17 13:52:46 -0800578static unsigned int __initdata additional_cpus;
Heiko Carstens37a33022006-02-17 13:52:47 -0800579static unsigned int __initdata possible_cpus;
Heiko Carstens255acee2006-02-17 13:52:46 -0800580
581void __init smp_setup_cpu_possible_map(void)
582{
Heiko Carstens54330452006-02-17 13:52:48 -0800583 unsigned int phy_cpus, pos_cpus, cpu;
Heiko Carstens255acee2006-02-17 13:52:46 -0800584
Heiko Carstens54330452006-02-17 13:52:48 -0800585 phy_cpus = smp_count_cpus();
586 pos_cpus = min(phy_cpus + additional_cpus, (unsigned int) NR_CPUS);
Heiko Carstens255acee2006-02-17 13:52:46 -0800587
Heiko Carstens37a33022006-02-17 13:52:47 -0800588 if (possible_cpus)
Heiko Carstens54330452006-02-17 13:52:48 -0800589 pos_cpus = min(possible_cpus, (unsigned int) NR_CPUS);
Heiko Carstens255acee2006-02-17 13:52:46 -0800590
Heiko Carstens54330452006-02-17 13:52:48 -0800591 for (cpu = 0; cpu < pos_cpus; cpu++)
Heiko Carstens255acee2006-02-17 13:52:46 -0800592 cpu_set(cpu, cpu_possible_map);
593
Heiko Carstens54330452006-02-17 13:52:48 -0800594 phy_cpus = min(phy_cpus, pos_cpus);
595
596 for (cpu = 0; cpu < phy_cpus; cpu++)
597 cpu_set(cpu, cpu_present_map);
Heiko Carstens255acee2006-02-17 13:52:46 -0800598}
599
600#ifdef CONFIG_HOTPLUG_CPU
601
602static int __init setup_additional_cpus(char *s)
603{
604 additional_cpus = simple_strtoul(s, NULL, 0);
605 return 0;
606}
607early_param("additional_cpus", setup_additional_cpus);
608
Heiko Carstens37a33022006-02-17 13:52:47 -0800609static int __init setup_possible_cpus(char *s)
610{
611 possible_cpus = simple_strtoul(s, NULL, 0);
612 return 0;
613}
614early_param("possible_cpus", setup_possible_cpus);
615
Heiko Carstens39ce0102007-04-27 16:02:00 +0200616int __cpu_disable(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700617{
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200618 struct ec_creg_mask_parms cr_parms;
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700619 int cpu = smp_processor_id();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700620
Zwane Mwaikambof3705132005-06-25 14:54:50 -0700621 cpu_clear(cpu, cpu_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622
Linus Torvalds1da177e2005-04-16 15:20:36 -0700623 /* Disable pfault pseudo page faults on this cpu. */
Heiko Carstens29b08d22006-12-04 15:40:40 +0100624 pfault_fini();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200626 memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals));
627 memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700628
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200629 /* disable all external interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 cr_parms.orvals[0] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200631 cr_parms.andvals[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 12 |
632 1 << 11 | 1 << 10 | 1 << 6 | 1 << 4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700633 /* disable all I/O interrupts */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634 cr_parms.orvals[6] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200635 cr_parms.andvals[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
636 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700637 /* disable most machine checks */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700638 cr_parms.orvals[14] = 0;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200639 cr_parms.andvals[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
640 1 << 25 | 1 << 24);
Martin Schwidefsky94c12cc2006-09-28 16:56:43 +0200641
Linus Torvalds1da177e2005-04-16 15:20:36 -0700642 smp_ctl_bit_callback(&cr_parms);
643
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 return 0;
645}
646
Heiko Carstens39ce0102007-04-27 16:02:00 +0200647void __cpu_die(unsigned int cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700648{
649 /* Wait until target cpu is down */
650 while (!smp_cpu_not_running(cpu))
651 cpu_relax();
652 printk("Processor %d spun down\n", cpu);
653}
654
Heiko Carstens39ce0102007-04-27 16:02:00 +0200655void cpu_die(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700656{
657 idle_task_exit();
658 signal_processor(smp_processor_id(), sigp_stop);
659 BUG();
Heiko Carstens39ce0102007-04-27 16:02:00 +0200660 for (;;);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661}
662
Heiko Carstens255acee2006-02-17 13:52:46 -0800663#endif /* CONFIG_HOTPLUG_CPU */
664
Linus Torvalds1da177e2005-04-16 15:20:36 -0700665/*
666 * Cycle through the processors and setup structures.
667 */
668
669void __init smp_prepare_cpus(unsigned int max_cpus)
670{
671 unsigned long stack;
672 unsigned int cpu;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200673 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700674
Heiko Carstens39ce0102007-04-27 16:02:00 +0200675 /* request the 0x1201 emergency signal external interrupt */
676 if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0)
677 panic("Couldn't request external interrupt 0x1201");
678 memset(lowcore_ptr, 0, sizeof(lowcore_ptr));
679 /*
680 * Initialize prefix pages and stacks for all possible cpus
681 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700682 print_cpu_info(&S390_lowcore.cpu_data);
683
Heiko Carstens39ce0102007-04-27 16:02:00 +0200684 for_each_possible_cpu(i) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700685 lowcore_ptr[i] = (struct _lowcore *)
Heiko Carstens39ce0102007-04-27 16:02:00 +0200686 __get_free_pages(GFP_KERNEL | GFP_DMA,
687 sizeof(void*) == 8 ? 1 : 0);
688 stack = __get_free_pages(GFP_KERNEL, ASYNC_ORDER);
689 if (!lowcore_ptr[i] || !stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700690 panic("smp_boot_cpus failed to allocate memory\n");
691
692 *(lowcore_ptr[i]) = S390_lowcore;
Heiko Carstens39ce0102007-04-27 16:02:00 +0200693 lowcore_ptr[i]->async_stack = stack + ASYNC_SIZE;
694 stack = __get_free_pages(GFP_KERNEL, 0);
695 if (!stack)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700696 panic("smp_boot_cpus failed to allocate memory\n");
Heiko Carstens39ce0102007-04-27 16:02:00 +0200697 lowcore_ptr[i]->panic_stack = stack + PAGE_SIZE;
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800698#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700699 if (MACHINE_HAS_IEEE) {
700 lowcore_ptr[i]->extended_save_area_addr =
Heiko Carstens39ce0102007-04-27 16:02:00 +0200701 (__u32) __get_free_pages(GFP_KERNEL, 0);
702 if (!lowcore_ptr[i]->extended_save_area_addr)
Heiko Carstens77fa2242005-06-25 14:55:30 -0700703 panic("smp_boot_cpus failed to "
704 "allocate memory\n");
705 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700706#endif
707 }
Martin Schwidefsky347a8dc2006-01-06 00:19:28 -0800708#ifndef CONFIG_64BIT
Heiko Carstens77fa2242005-06-25 14:55:30 -0700709 if (MACHINE_HAS_IEEE)
710 ctl_set_bit(14, 29); /* enable extended save area */
711#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]);
713
KAMEZAWA Hiroyuki97db7fb2006-03-31 02:30:26 -0800714 for_each_possible_cpu(cpu)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700715 if (cpu != smp_processor_id())
716 smp_create_idle(cpu);
717}
718
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200719void __init smp_prepare_boot_cpu(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700720{
721 BUG_ON(smp_processor_id() != 0);
722
723 cpu_set(0, cpu_online_map);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700724 S390_lowcore.percpu_offset = __per_cpu_offset[0];
725 current_set[0] = current;
726}
727
Heiko Carstensea1f4ee2007-05-31 17:38:05 +0200728void __init smp_cpus_done(unsigned int max_cpus)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700729{
Heiko Carstens54330452006-02-17 13:52:48 -0800730 cpu_present_map = cpu_possible_map;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731}
732
733/*
734 * the frequency of the profiling timer can be changed
735 * by writing a multiplier value into /proc/profile.
736 *
737 * usually you want to run this on all CPUs ;)
738 */
739int setup_profiling_timer(unsigned int multiplier)
740{
Heiko Carstens39ce0102007-04-27 16:02:00 +0200741 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742}
743
744static DEFINE_PER_CPU(struct cpu, cpu_devices);
745
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200746static ssize_t show_capability(struct sys_device *dev, char *buf)
747{
748 unsigned int capability;
749 int rc;
750
751 rc = get_cpu_capability(&capability);
752 if (rc)
753 return rc;
754 return sprintf(buf, "%u\n", capability);
755}
756static SYSDEV_ATTR(capability, 0444, show_capability, NULL);
757
758static int __cpuinit smp_cpu_notify(struct notifier_block *self,
759 unsigned long action, void *hcpu)
760{
761 unsigned int cpu = (unsigned int)(long)hcpu;
762 struct cpu *c = &per_cpu(cpu_devices, cpu);
763 struct sys_device *s = &c->sysdev;
764
765 switch (action) {
766 case CPU_ONLINE:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700767 case CPU_ONLINE_FROZEN:
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200768 if (sysdev_create_file(s, &attr_capability))
769 return NOTIFY_BAD;
770 break;
771 case CPU_DEAD:
Rafael J. Wysocki8bb78442007-05-09 02:35:10 -0700772 case CPU_DEAD_FROZEN:
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200773 sysdev_remove_file(s, &attr_capability);
774 break;
775 }
776 return NOTIFY_OK;
777}
778
779static struct notifier_block __cpuinitdata smp_cpu_nb = {
Heiko Carstens39ce0102007-04-27 16:02:00 +0200780 .notifier_call = smp_cpu_notify,
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200781};
782
Linus Torvalds1da177e2005-04-16 15:20:36 -0700783static int __init topology_init(void)
784{
785 int cpu;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200786
787 register_cpu_notifier(&smp_cpu_nb);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
KAMEZAWA Hiroyuki97db7fb2006-03-31 02:30:26 -0800789 for_each_possible_cpu(cpu) {
Heiko Carstens6721f772007-01-09 10:18:44 +0100790 struct cpu *c = &per_cpu(cpu_devices, cpu);
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200791 struct sys_device *s = &c->sysdev;
Heiko Carstens6721f772007-01-09 10:18:44 +0100792
793 c->hotpluggable = 1;
Heiko Carstens2fc2d1e2007-04-27 16:01:56 +0200794 register_cpu(c, cpu);
795 if (!cpu_online(cpu))
796 continue;
797 s = &c->sysdev;
798 sysdev_create_file(s, &attr_capability);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700799 }
800 return 0;
801}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700802subsys_initcall(topology_init);