Commit | Line | Data |
---|---|---|
1da177e4 LT |
1 | /* |
2 | * arch/s390/kernel/smp.c | |
3 | * | |
255acee7 | 4 | * Copyright (C) IBM Corp. 1999,2006 |
1da177e4 LT |
5 | * Author(s): Denis Joseph Barrow (djbarrow@de.ibm.com,barrow_dj@yahoo.com), |
6 | * Martin Schwidefsky (schwidefsky@de.ibm.com) | |
7 | * Heiko Carstens (heiko.carstens@de.ibm.com) | |
8 | * | |
9 | * based on other smp stuff by | |
10 | * (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> | |
25 | ||
26 | #include <linux/mm.h> | |
27 | #include <linux/spinlock.h> | |
28 | #include <linux/kernel_stat.h> | |
29 | #include <linux/smp_lock.h> | |
30 | ||
31 | #include <linux/delay.h> | |
32 | #include <linux/cache.h> | |
33 | #include <linux/interrupt.h> | |
34 | #include <linux/cpu.h> | |
35 | ||
36 | #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> | |
42 | ||
1da177e4 LT |
43 | extern volatile int __cpu_logical_map[]; |
44 | ||
45 | /* | |
46 | * An array with a pointer the lowcore of every CPU. | |
47 | */ | |
48 | ||
49 | struct _lowcore *lowcore_ptr[NR_CPUS]; | |
50 | ||
255acee7 HC |
51 | cpumask_t cpu_online_map = CPU_MASK_NONE; |
52 | cpumask_t cpu_possible_map = CPU_MASK_NONE; | |
1da177e4 LT |
53 | |
54 | static struct task_struct *current_set[NR_CPUS]; | |
55 | ||
1da177e4 LT |
56 | /* |
57 | * Reboot, halt and power_off routines for SMP. | |
58 | */ | |
59 | extern char vmhalt_cmd[]; | |
60 | extern char vmpoff_cmd[]; | |
61 | ||
1da177e4 LT |
62 | static void smp_ext_bitcall(int, ec_bit_sig); |
63 | static void smp_ext_bitcall_others(ec_bit_sig); | |
64 | ||
65 | /* | |
94c12cc7 | 66 | 5B * Structure and data for smp_call_function(). This is designed to minimise |
1da177e4 LT |
67 | * static memory requirements. It also looks cleaner. |
68 | */ | |
69 | static DEFINE_SPINLOCK(call_lock); | |
70 | ||
71 | struct call_data_struct { | |
72 | void (*func) (void *info); | |
73 | void *info; | |
74 | atomic_t started; | |
75 | atomic_t finished; | |
76 | int wait; | |
77 | }; | |
78 | ||
79 | static struct call_data_struct * call_data; | |
80 | ||
81 | /* | |
82 | * 'Call function' interrupt callback | |
83 | */ | |
84 | static void do_call_function(void) | |
85 | { | |
86 | void (*func) (void *info) = call_data->func; | |
87 | void *info = call_data->info; | |
88 | int wait = call_data->wait; | |
89 | ||
90 | atomic_inc(&call_data->started); | |
91 | (*func)(info); | |
92 | if (wait) | |
93 | atomic_inc(&call_data->finished); | |
94 | } | |
95 | ||
96 | /* | |
97 | * this function sends a 'generic call function' IPI to all other CPUs | |
98 | * in the system. | |
99 | */ | |
100 | ||
101 | int smp_call_function (void (*func) (void *info), void *info, int nonatomic, | |
102 | int wait) | |
103 | /* | |
104 | * [SUMMARY] Run a function on all other CPUs. | |
105 | * <func> The function to run. This must be fast and non-blocking. | |
106 | * <info> An arbitrary pointer to pass to the function. | |
107 | * <nonatomic> currently unused. | |
108 | * <wait> If true, wait (atomically) until function has completed on other CPUs. | |
109 | * [RETURNS] 0 on success, else a negative status code. Does not return until | |
110 | * remote CPUs are nearly ready to execute <<func>> or are or have executed. | |
111 | * | |
112 | * You must not call this function with disabled interrupts or from a | |
113 | * hardware interrupt handler or from a bottom half handler. | |
114 | */ | |
115 | { | |
116 | struct call_data_struct data; | |
117 | int cpus = num_online_cpus()-1; | |
118 | ||
119 | if (cpus <= 0) | |
120 | return 0; | |
121 | ||
122 | /* Can deadlock when called with interrupts disabled */ | |
123 | WARN_ON(irqs_disabled()); | |
124 | ||
125 | data.func = func; | |
126 | data.info = info; | |
127 | atomic_set(&data.started, 0); | |
128 | data.wait = wait; | |
129 | if (wait) | |
130 | atomic_set(&data.finished, 0); | |
131 | ||
132 | spin_lock(&call_lock); | |
133 | call_data = &data; | |
134 | /* Send a message to all other CPUs and wait for them to respond */ | |
135 | smp_ext_bitcall_others(ec_call_function); | |
136 | ||
137 | /* Wait for response */ | |
138 | while (atomic_read(&data.started) != cpus) | |
139 | cpu_relax(); | |
140 | ||
141 | if (wait) | |
142 | while (atomic_read(&data.finished) != cpus) | |
143 | cpu_relax(); | |
144 | spin_unlock(&call_lock); | |
145 | ||
146 | return 0; | |
147 | } | |
148 | ||
149 | /* | |
150 | * Call a function on one CPU | |
151 | * cpu : the CPU the function should be executed on | |
152 | * | |
153 | * You must not call this function with disabled interrupts or from a | |
154 | * hardware interrupt handler. You may call it from a bottom half. | |
155 | * | |
156 | * It is guaranteed that the called function runs on the specified CPU, | |
157 | * preemption is disabled. | |
158 | */ | |
159 | int smp_call_function_on(void (*func) (void *info), void *info, | |
160 | int nonatomic, int wait, int cpu) | |
161 | { | |
162 | struct call_data_struct data; | |
163 | int curr_cpu; | |
164 | ||
165 | if (!cpu_online(cpu)) | |
166 | return -EINVAL; | |
167 | ||
168 | /* disable preemption for local function call */ | |
169 | curr_cpu = get_cpu(); | |
170 | ||
171 | if (curr_cpu == cpu) { | |
172 | /* direct call to function */ | |
173 | func(info); | |
174 | put_cpu(); | |
175 | return 0; | |
176 | } | |
177 | ||
178 | data.func = func; | |
179 | data.info = info; | |
180 | atomic_set(&data.started, 0); | |
181 | data.wait = wait; | |
182 | if (wait) | |
183 | atomic_set(&data.finished, 0); | |
184 | ||
185 | spin_lock_bh(&call_lock); | |
186 | call_data = &data; | |
187 | smp_ext_bitcall(cpu, ec_call_function); | |
188 | ||
189 | /* Wait for response */ | |
190 | while (atomic_read(&data.started) != 1) | |
191 | cpu_relax(); | |
192 | ||
193 | if (wait) | |
194 | while (atomic_read(&data.finished) != 1) | |
195 | cpu_relax(); | |
196 | ||
197 | spin_unlock_bh(&call_lock); | |
198 | put_cpu(); | |
199 | return 0; | |
200 | } | |
201 | EXPORT_SYMBOL(smp_call_function_on); | |
202 | ||
203 | static inline void do_send_stop(void) | |
204 | { | |
205 | int cpu, rc; | |
206 | ||
207 | /* stop all processors */ | |
208 | for_each_online_cpu(cpu) { | |
209 | if (cpu == smp_processor_id()) | |
210 | continue; | |
211 | do { | |
212 | rc = signal_processor(cpu, sigp_stop); | |
213 | } while (rc == sigp_busy); | |
214 | } | |
215 | } | |
216 | ||
217 | static inline void do_store_status(void) | |
218 | { | |
219 | int cpu, rc; | |
220 | ||
221 | /* store status of all processors in their lowcores (real 0) */ | |
222 | for_each_online_cpu(cpu) { | |
223 | if (cpu == smp_processor_id()) | |
224 | continue; | |
225 | do { | |
226 | rc = signal_processor_p( | |
227 | (__u32)(unsigned long) lowcore_ptr[cpu], cpu, | |
228 | sigp_store_status_at_address); | |
229 | } while(rc == sigp_busy); | |
230 | } | |
231 | } | |
232 | ||
c6b5b847 HC |
233 | static inline void do_wait_for_stop(void) |
234 | { | |
235 | int cpu; | |
236 | ||
237 | /* Wait for all other cpus to enter stopped state */ | |
238 | for_each_online_cpu(cpu) { | |
239 | if (cpu == smp_processor_id()) | |
240 | continue; | |
241 | while(!smp_cpu_not_running(cpu)) | |
242 | cpu_relax(); | |
243 | } | |
244 | } | |
245 | ||
1da177e4 LT |
246 | /* |
247 | * this function sends a 'stop' sigp to all other CPUs in the system. | |
248 | * it goes straight through. | |
249 | */ | |
250 | void smp_send_stop(void) | |
251 | { | |
c6b5b847 HC |
252 | /* Disable all interrupts/machine checks */ |
253 | __load_psw_mask(PSW_KERNEL_BITS & ~PSW_MASK_MCHECK); | |
254 | ||
1da177e4 LT |
255 | /* write magic number to zero page (absolute 0) */ |
256 | lowcore_ptr[smp_processor_id()]->panic_magic = __PANIC_MAGIC; | |
257 | ||
258 | /* stop other processors. */ | |
259 | do_send_stop(); | |
260 | ||
c6b5b847 HC |
261 | /* wait until other processors are stopped */ |
262 | do_wait_for_stop(); | |
263 | ||
1da177e4 LT |
264 | /* store status of other processors. */ |
265 | do_store_status(); | |
266 | } | |
267 | ||
268 | /* | |
269 | * Reboot, halt and power_off routines for SMP. | |
270 | */ | |
271 | ||
1da177e4 LT |
272 | void machine_restart_smp(char * __unused) |
273 | { | |
c6b5b847 HC |
274 | smp_send_stop(); |
275 | do_reipl(); | |
1da177e4 LT |
276 | } |
277 | ||
278 | void machine_halt_smp(void) | |
279 | { | |
c6b5b847 HC |
280 | smp_send_stop(); |
281 | if (MACHINE_IS_VM && strlen(vmhalt_cmd) > 0) | |
282 | __cpcmd(vmhalt_cmd, NULL, 0, NULL); | |
283 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); | |
284 | for (;;); | |
1da177e4 LT |
285 | } |
286 | ||
287 | void machine_power_off_smp(void) | |
288 | { | |
c6b5b847 HC |
289 | smp_send_stop(); |
290 | if (MACHINE_IS_VM && strlen(vmpoff_cmd) > 0) | |
291 | __cpcmd(vmpoff_cmd, NULL, 0, NULL); | |
292 | signal_processor(smp_processor_id(), sigp_stop_and_store_status); | |
293 | for (;;); | |
1da177e4 LT |
294 | } |
295 | ||
296 | /* | |
297 | * This is the main routine where commands issued by other | |
298 | * cpus are handled. | |
299 | */ | |
300 | ||
5a489b98 | 301 | void do_ext_call_interrupt(__u16 code) |
1da177e4 LT |
302 | { |
303 | unsigned long bits; | |
304 | ||
305 | /* | |
306 | * handle bit signal external calls | |
307 | * | |
308 | * For the ec_schedule signal we have to do nothing. All the work | |
309 | * is done automatically when we return from the interrupt. | |
310 | */ | |
311 | bits = xchg(&S390_lowcore.ext_call_fast, 0); | |
312 | ||
313 | if (test_bit(ec_call_function, &bits)) | |
314 | do_call_function(); | |
315 | } | |
316 | ||
317 | /* | |
318 | * Send an external call sigp to another cpu and return without waiting | |
319 | * for its completion. | |
320 | */ | |
321 | static void smp_ext_bitcall(int cpu, ec_bit_sig sig) | |
322 | { | |
323 | /* | |
324 | * Set signaling bit in lowcore of target cpu and kick it | |
325 | */ | |
326 | set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast); | |
99b2d8df | 327 | while(signal_processor(cpu, sigp_emergency_signal) == sigp_busy) |
1da177e4 LT |
328 | udelay(10); |
329 | } | |
330 | ||
331 | /* | |
332 | * Send an external call sigp to every other cpu in the system and | |
333 | * return without waiting for its completion. | |
334 | */ | |
335 | static void smp_ext_bitcall_others(ec_bit_sig sig) | |
336 | { | |
337 | int cpu; | |
338 | ||
339 | for_each_online_cpu(cpu) { | |
340 | if (cpu == smp_processor_id()) | |
341 | continue; | |
342 | /* | |
343 | * Set signaling bit in lowcore of target cpu and kick it | |
344 | */ | |
345 | set_bit(sig, (unsigned long *) &lowcore_ptr[cpu]->ext_call_fast); | |
99b2d8df | 346 | while (signal_processor(cpu, sigp_emergency_signal) == sigp_busy) |
1da177e4 LT |
347 | udelay(10); |
348 | } | |
349 | } | |
350 | ||
347a8dc3 | 351 | #ifndef CONFIG_64BIT |
1da177e4 LT |
352 | /* |
353 | * this function sends a 'purge tlb' signal to another CPU. | |
354 | */ | |
355 | void smp_ptlb_callback(void *info) | |
356 | { | |
357 | local_flush_tlb(); | |
358 | } | |
359 | ||
360 | void smp_ptlb_all(void) | |
361 | { | |
362 | on_each_cpu(smp_ptlb_callback, NULL, 0, 1); | |
363 | } | |
364 | EXPORT_SYMBOL(smp_ptlb_all); | |
347a8dc3 | 365 | #endif /* ! CONFIG_64BIT */ |
1da177e4 LT |
366 | |
367 | /* | |
368 | * this function sends a 'reschedule' IPI to another CPU. | |
369 | * it goes straight through and wastes no time serializing | |
370 | * anything. Worst case is that we lose a reschedule ... | |
371 | */ | |
372 | void smp_send_reschedule(int cpu) | |
373 | { | |
374 | smp_ext_bitcall(cpu, ec_schedule); | |
375 | } | |
376 | ||
377 | /* | |
378 | * parameter area for the set/clear control bit callbacks | |
379 | */ | |
94c12cc7 | 380 | struct ec_creg_mask_parms { |
1da177e4 LT |
381 | unsigned long orvals[16]; |
382 | unsigned long andvals[16]; | |
94c12cc7 | 383 | }; |
1da177e4 LT |
384 | |
385 | /* | |
386 | * callback for setting/clearing control bits | |
387 | */ | |
388 | void smp_ctl_bit_callback(void *info) { | |
94c12cc7 | 389 | struct ec_creg_mask_parms *pp = info; |
1da177e4 LT |
390 | unsigned long cregs[16]; |
391 | int i; | |
392 | ||
94c12cc7 MS |
393 | __ctl_store(cregs, 0, 15); |
394 | for (i = 0; i <= 15; i++) | |
1da177e4 | 395 | cregs[i] = (cregs[i] & pp->andvals[i]) | pp->orvals[i]; |
94c12cc7 | 396 | __ctl_load(cregs, 0, 15); |
1da177e4 LT |
397 | } |
398 | ||
399 | /* | |
400 | * Set a bit in a control register of all cpus | |
401 | */ | |
94c12cc7 MS |
402 | void smp_ctl_set_bit(int cr, int bit) |
403 | { | |
404 | struct ec_creg_mask_parms parms; | |
1da177e4 | 405 | |
94c12cc7 MS |
406 | memset(&parms.orvals, 0, sizeof(parms.orvals)); |
407 | memset(&parms.andvals, 0xff, sizeof(parms.andvals)); | |
1da177e4 | 408 | parms.orvals[cr] = 1 << bit; |
94c12cc7 | 409 | on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1); |
1da177e4 LT |
410 | } |
411 | ||
412 | /* | |
413 | * Clear a bit in a control register of all cpus | |
414 | */ | |
94c12cc7 MS |
415 | void smp_ctl_clear_bit(int cr, int bit) |
416 | { | |
417 | struct ec_creg_mask_parms parms; | |
1da177e4 | 418 | |
94c12cc7 MS |
419 | memset(&parms.orvals, 0, sizeof(parms.orvals)); |
420 | memset(&parms.andvals, 0xff, sizeof(parms.andvals)); | |
1da177e4 | 421 | parms.andvals[cr] = ~(1L << bit); |
94c12cc7 | 422 | on_each_cpu(smp_ctl_bit_callback, &parms, 0, 1); |
1da177e4 LT |
423 | } |
424 | ||
425 | /* | |
426 | * Lets check how many CPUs we have. | |
427 | */ | |
428 | ||
255acee7 HC |
429 | static unsigned int |
430 | __init smp_count_cpus(void) | |
1da177e4 | 431 | { |
255acee7 | 432 | unsigned int cpu, num_cpus; |
1da177e4 LT |
433 | __u16 boot_cpu_addr; |
434 | ||
435 | /* | |
436 | * cpu 0 is the boot cpu. See smp_prepare_boot_cpu. | |
437 | */ | |
438 | ||
439 | boot_cpu_addr = S390_lowcore.cpu_data.cpu_addr; | |
440 | current_thread_info()->cpu = 0; | |
441 | num_cpus = 1; | |
255acee7 | 442 | for (cpu = 0; cpu <= 65535; cpu++) { |
1da177e4 LT |
443 | if ((__u16) cpu == boot_cpu_addr) |
444 | continue; | |
255acee7 HC |
445 | __cpu_logical_map[1] = (__u16) cpu; |
446 | if (signal_processor(1, sigp_sense) == | |
1da177e4 LT |
447 | sigp_not_operational) |
448 | continue; | |
1da177e4 LT |
449 | num_cpus++; |
450 | } | |
451 | ||
1da177e4 LT |
452 | printk("Detected %d CPU's\n",(int) num_cpus); |
453 | printk("Boot cpu address %2X\n", boot_cpu_addr); | |
255acee7 HC |
454 | |
455 | return num_cpus; | |
1da177e4 LT |
456 | } |
457 | ||
458 | /* | |
459 | * Activate a secondary processor. | |
460 | */ | |
461 | extern void init_cpu_timer(void); | |
462 | extern void init_cpu_vtimer(void); | |
463 | extern int pfault_init(void); | |
464 | extern void pfault_fini(void); | |
465 | ||
466 | int __devinit start_secondary(void *cpuvoid) | |
467 | { | |
468 | /* Setup the cpu */ | |
469 | cpu_init(); | |
5bfb5d69 | 470 | preempt_disable(); |
1da177e4 LT |
471 | /* init per CPU timer */ |
472 | init_cpu_timer(); | |
473 | #ifdef CONFIG_VIRT_TIMER | |
474 | init_cpu_vtimer(); | |
475 | #endif | |
476 | #ifdef CONFIG_PFAULT | |
477 | /* Enable pfault pseudo page faults on this cpu. */ | |
5d3f229f HC |
478 | if (MACHINE_IS_VM) |
479 | pfault_init(); | |
1da177e4 LT |
480 | #endif |
481 | /* Mark this cpu as online */ | |
482 | cpu_set(smp_processor_id(), cpu_online_map); | |
483 | /* Switch on interrupts */ | |
484 | local_irq_enable(); | |
485 | /* Print info about this processor */ | |
486 | print_cpu_info(&S390_lowcore.cpu_data); | |
487 | /* cpu_idle will call schedule for us */ | |
488 | cpu_idle(); | |
489 | return 0; | |
490 | } | |
491 | ||
492 | static void __init smp_create_idle(unsigned int cpu) | |
493 | { | |
494 | struct task_struct *p; | |
495 | ||
496 | /* | |
497 | * don't care about the psw and regs settings since we'll never | |
498 | * reschedule the forked task. | |
499 | */ | |
500 | p = fork_idle(cpu); | |
501 | if (IS_ERR(p)) | |
502 | panic("failed fork for CPU %u: %li", cpu, PTR_ERR(p)); | |
503 | current_set[cpu] = p; | |
504 | } | |
505 | ||
506 | /* Reserving and releasing of CPUs */ | |
507 | ||
508 | static DEFINE_SPINLOCK(smp_reserve_lock); | |
509 | static int smp_cpu_reserved[NR_CPUS]; | |
510 | ||
511 | int | |
512 | smp_get_cpu(cpumask_t cpu_mask) | |
513 | { | |
514 | unsigned long flags; | |
515 | int cpu; | |
516 | ||
517 | spin_lock_irqsave(&smp_reserve_lock, flags); | |
518 | /* Try to find an already reserved cpu. */ | |
519 | for_each_cpu_mask(cpu, cpu_mask) { | |
520 | if (smp_cpu_reserved[cpu] != 0) { | |
521 | smp_cpu_reserved[cpu]++; | |
522 | /* Found one. */ | |
523 | goto out; | |
524 | } | |
525 | } | |
526 | /* Reserve a new cpu from cpu_mask. */ | |
527 | for_each_cpu_mask(cpu, cpu_mask) { | |
528 | if (cpu_online(cpu)) { | |
529 | smp_cpu_reserved[cpu]++; | |
530 | goto out; | |
531 | } | |
532 | } | |
533 | cpu = -ENODEV; | |
534 | out: | |
535 | spin_unlock_irqrestore(&smp_reserve_lock, flags); | |
536 | return cpu; | |
537 | } | |
538 | ||
539 | void | |
540 | smp_put_cpu(int cpu) | |
541 | { | |
542 | unsigned long flags; | |
543 | ||
544 | spin_lock_irqsave(&smp_reserve_lock, flags); | |
545 | smp_cpu_reserved[cpu]--; | |
546 | spin_unlock_irqrestore(&smp_reserve_lock, flags); | |
547 | } | |
548 | ||
549 | static inline int | |
550 | cpu_stopped(int cpu) | |
551 | { | |
552 | __u32 status; | |
553 | ||
554 | /* Check for stopped state */ | |
555 | if (signal_processor_ps(&status, 0, cpu, sigp_sense) == sigp_status_stored) { | |
556 | if (status & 0x40) | |
557 | return 1; | |
558 | } | |
559 | return 0; | |
560 | } | |
561 | ||
562 | /* Upping and downing of CPUs */ | |
563 | ||
564 | int | |
565 | __cpu_up(unsigned int cpu) | |
566 | { | |
567 | struct task_struct *idle; | |
568 | struct _lowcore *cpu_lowcore; | |
569 | struct stack_frame *sf; | |
570 | sigp_ccode ccode; | |
571 | int curr_cpu; | |
572 | ||
573 | for (curr_cpu = 0; curr_cpu <= 65535; curr_cpu++) { | |
574 | __cpu_logical_map[cpu] = (__u16) curr_cpu; | |
575 | if (cpu_stopped(cpu)) | |
576 | break; | |
577 | } | |
578 | ||
579 | if (!cpu_stopped(cpu)) | |
580 | return -ENODEV; | |
581 | ||
582 | ccode = signal_processor_p((__u32)(unsigned long)(lowcore_ptr[cpu]), | |
583 | cpu, sigp_set_prefix); | |
584 | if (ccode){ | |
585 | printk("sigp_set_prefix failed for cpu %d " | |
586 | "with condition code %d\n", | |
587 | (int) cpu, (int) ccode); | |
588 | return -EIO; | |
589 | } | |
590 | ||
591 | idle = current_set[cpu]; | |
592 | cpu_lowcore = lowcore_ptr[cpu]; | |
593 | cpu_lowcore->kernel_stack = (unsigned long) | |
30af7120 | 594 | task_stack_page(idle) + (THREAD_SIZE); |
1da177e4 LT |
595 | sf = (struct stack_frame *) (cpu_lowcore->kernel_stack |
596 | - sizeof(struct pt_regs) | |
597 | - sizeof(struct stack_frame)); | |
598 | memset(sf, 0, sizeof(struct stack_frame)); | |
599 | sf->gprs[9] = (unsigned long) sf; | |
600 | cpu_lowcore->save_area[15] = (unsigned long) sf; | |
601 | __ctl_store(cpu_lowcore->cregs_save_area[0], 0, 15); | |
94c12cc7 MS |
602 | asm volatile( |
603 | " stam 0,15,0(%0)" | |
604 | : : "a" (&cpu_lowcore->access_regs_save_area) : "memory"); | |
1da177e4 LT |
605 | cpu_lowcore->percpu_offset = __per_cpu_offset[cpu]; |
606 | cpu_lowcore->current_task = (unsigned long) idle; | |
607 | cpu_lowcore->cpu_data.cpu_nr = cpu; | |
608 | eieio(); | |
699ff13f MR |
609 | |
610 | while (signal_processor(cpu,sigp_restart) == sigp_busy) | |
611 | udelay(10); | |
1da177e4 LT |
612 | |
613 | while (!cpu_online(cpu)) | |
614 | cpu_relax(); | |
615 | return 0; | |
616 | } | |
617 | ||
255acee7 | 618 | static unsigned int __initdata additional_cpus; |
37a33026 | 619 | static unsigned int __initdata possible_cpus; |
255acee7 HC |
620 | |
621 | void __init smp_setup_cpu_possible_map(void) | |
622 | { | |
54330456 | 623 | unsigned int phy_cpus, pos_cpus, cpu; |
255acee7 | 624 | |
54330456 HC |
625 | phy_cpus = smp_count_cpus(); |
626 | pos_cpus = min(phy_cpus + additional_cpus, (unsigned int) NR_CPUS); | |
255acee7 | 627 | |
37a33026 | 628 | if (possible_cpus) |
54330456 | 629 | pos_cpus = min(possible_cpus, (unsigned int) NR_CPUS); |
255acee7 | 630 | |
54330456 | 631 | for (cpu = 0; cpu < pos_cpus; cpu++) |
255acee7 HC |
632 | cpu_set(cpu, cpu_possible_map); |
633 | ||
54330456 HC |
634 | phy_cpus = min(phy_cpus, pos_cpus); |
635 | ||
636 | for (cpu = 0; cpu < phy_cpus; cpu++) | |
637 | cpu_set(cpu, cpu_present_map); | |
255acee7 HC |
638 | } |
639 | ||
640 | #ifdef CONFIG_HOTPLUG_CPU | |
641 | ||
642 | static int __init setup_additional_cpus(char *s) | |
643 | { | |
644 | additional_cpus = simple_strtoul(s, NULL, 0); | |
645 | return 0; | |
646 | } | |
647 | early_param("additional_cpus", setup_additional_cpus); | |
648 | ||
37a33026 HC |
649 | static int __init setup_possible_cpus(char *s) |
650 | { | |
651 | possible_cpus = simple_strtoul(s, NULL, 0); | |
652 | return 0; | |
653 | } | |
654 | early_param("possible_cpus", setup_possible_cpus); | |
655 | ||
1da177e4 LT |
656 | int |
657 | __cpu_disable(void) | |
658 | { | |
659 | unsigned long flags; | |
94c12cc7 | 660 | struct ec_creg_mask_parms cr_parms; |
f3705136 | 661 | int cpu = smp_processor_id(); |
1da177e4 LT |
662 | |
663 | spin_lock_irqsave(&smp_reserve_lock, flags); | |
f3705136 | 664 | if (smp_cpu_reserved[cpu] != 0) { |
1da177e4 LT |
665 | spin_unlock_irqrestore(&smp_reserve_lock, flags); |
666 | return -EBUSY; | |
667 | } | |
f3705136 | 668 | cpu_clear(cpu, cpu_online_map); |
1da177e4 LT |
669 | |
670 | #ifdef CONFIG_PFAULT | |
671 | /* Disable pfault pseudo page faults on this cpu. */ | |
5d3f229f HC |
672 | if (MACHINE_IS_VM) |
673 | pfault_fini(); | |
1da177e4 LT |
674 | #endif |
675 | ||
94c12cc7 MS |
676 | memset(&cr_parms.orvals, 0, sizeof(cr_parms.orvals)); |
677 | memset(&cr_parms.andvals, 0xff, sizeof(cr_parms.andvals)); | |
1da177e4 | 678 | |
94c12cc7 | 679 | /* disable all external interrupts */ |
1da177e4 LT |
680 | cr_parms.orvals[0] = 0; |
681 | cr_parms.andvals[0] = ~(1<<15 | 1<<14 | 1<<13 | 1<<12 | | |
682 | 1<<11 | 1<<10 | 1<< 6 | 1<< 4); | |
1da177e4 | 683 | /* disable all I/O interrupts */ |
1da177e4 LT |
684 | cr_parms.orvals[6] = 0; |
685 | cr_parms.andvals[6] = ~(1<<31 | 1<<30 | 1<<29 | 1<<28 | | |
686 | 1<<27 | 1<<26 | 1<<25 | 1<<24); | |
1da177e4 | 687 | /* disable most machine checks */ |
1da177e4 LT |
688 | cr_parms.orvals[14] = 0; |
689 | cr_parms.andvals[14] = ~(1<<28 | 1<<27 | 1<<26 | 1<<25 | 1<<24); | |
94c12cc7 | 690 | |
1da177e4 LT |
691 | smp_ctl_bit_callback(&cr_parms); |
692 | ||
693 | spin_unlock_irqrestore(&smp_reserve_lock, flags); | |
694 | return 0; | |
695 | } | |
696 | ||
697 | void | |
698 | __cpu_die(unsigned int cpu) | |
699 | { | |
700 | /* Wait until target cpu is down */ | |
701 | while (!smp_cpu_not_running(cpu)) | |
702 | cpu_relax(); | |
703 | printk("Processor %d spun down\n", cpu); | |
704 | } | |
705 | ||
706 | void | |
707 | cpu_die(void) | |
708 | { | |
709 | idle_task_exit(); | |
710 | signal_processor(smp_processor_id(), sigp_stop); | |
711 | BUG(); | |
712 | for(;;); | |
713 | } | |
714 | ||
255acee7 HC |
715 | #endif /* CONFIG_HOTPLUG_CPU */ |
716 | ||
1da177e4 LT |
717 | /* |
718 | * Cycle through the processors and setup structures. | |
719 | */ | |
720 | ||
721 | void __init smp_prepare_cpus(unsigned int max_cpus) | |
722 | { | |
723 | unsigned long stack; | |
724 | unsigned int cpu; | |
725 | int i; | |
726 | ||
99b2d8df HC |
727 | /* request the 0x1201 emergency signal external interrupt */ |
728 | if (register_external_interrupt(0x1201, do_ext_call_interrupt) != 0) | |
729 | panic("Couldn't request external interrupt 0x1201"); | |
1da177e4 LT |
730 | memset(lowcore_ptr,0,sizeof(lowcore_ptr)); |
731 | /* | |
732 | * Initialize prefix pages and stacks for all possible cpus | |
733 | */ | |
734 | print_cpu_info(&S390_lowcore.cpu_data); | |
735 | ||
97db7fbf | 736 | for_each_possible_cpu(i) { |
1da177e4 LT |
737 | lowcore_ptr[i] = (struct _lowcore *) |
738 | __get_free_pages(GFP_KERNEL|GFP_DMA, | |
739 | sizeof(void*) == 8 ? 1 : 0); | |
740 | stack = __get_free_pages(GFP_KERNEL,ASYNC_ORDER); | |
741 | if (lowcore_ptr[i] == NULL || stack == 0ULL) | |
742 | panic("smp_boot_cpus failed to allocate memory\n"); | |
743 | ||
744 | *(lowcore_ptr[i]) = S390_lowcore; | |
745 | lowcore_ptr[i]->async_stack = stack + (ASYNC_SIZE); | |
1da177e4 LT |
746 | stack = __get_free_pages(GFP_KERNEL,0); |
747 | if (stack == 0ULL) | |
748 | panic("smp_boot_cpus failed to allocate memory\n"); | |
749 | lowcore_ptr[i]->panic_stack = stack + (PAGE_SIZE); | |
347a8dc3 | 750 | #ifndef CONFIG_64BIT |
77fa2245 HC |
751 | if (MACHINE_HAS_IEEE) { |
752 | lowcore_ptr[i]->extended_save_area_addr = | |
753 | (__u32) __get_free_pages(GFP_KERNEL,0); | |
754 | if (lowcore_ptr[i]->extended_save_area_addr == 0) | |
755 | panic("smp_boot_cpus failed to " | |
756 | "allocate memory\n"); | |
757 | } | |
1da177e4 LT |
758 | #endif |
759 | } | |
347a8dc3 | 760 | #ifndef CONFIG_64BIT |
77fa2245 HC |
761 | if (MACHINE_HAS_IEEE) |
762 | ctl_set_bit(14, 29); /* enable extended save area */ | |
763 | #endif | |
1da177e4 LT |
764 | set_prefix((u32)(unsigned long) lowcore_ptr[smp_processor_id()]); |
765 | ||
97db7fbf | 766 | for_each_possible_cpu(cpu) |
1da177e4 LT |
767 | if (cpu != smp_processor_id()) |
768 | smp_create_idle(cpu); | |
769 | } | |
770 | ||
771 | void __devinit smp_prepare_boot_cpu(void) | |
772 | { | |
773 | BUG_ON(smp_processor_id() != 0); | |
774 | ||
775 | cpu_set(0, cpu_online_map); | |
1da177e4 LT |
776 | S390_lowcore.percpu_offset = __per_cpu_offset[0]; |
777 | current_set[0] = current; | |
778 | } | |
779 | ||
780 | void smp_cpus_done(unsigned int max_cpus) | |
781 | { | |
54330456 | 782 | cpu_present_map = cpu_possible_map; |
1da177e4 LT |
783 | } |
784 | ||
785 | /* | |
786 | * the frequency of the profiling timer can be changed | |
787 | * by writing a multiplier value into /proc/profile. | |
788 | * | |
789 | * usually you want to run this on all CPUs ;) | |
790 | */ | |
791 | int setup_profiling_timer(unsigned int multiplier) | |
792 | { | |
793 | return 0; | |
794 | } | |
795 | ||
796 | static DEFINE_PER_CPU(struct cpu, cpu_devices); | |
797 | ||
798 | static int __init topology_init(void) | |
799 | { | |
800 | int cpu; | |
801 | int ret; | |
802 | ||
97db7fbf | 803 | for_each_possible_cpu(cpu) { |
76b67ed9 | 804 | ret = register_cpu(&per_cpu(cpu_devices, cpu), cpu); |
1da177e4 LT |
805 | if (ret) |
806 | printk(KERN_WARNING "topology_init: register_cpu %d " | |
807 | "failed (%d)\n", cpu, ret); | |
808 | } | |
809 | return 0; | |
810 | } | |
811 | ||
812 | subsys_initcall(topology_init); | |
813 | ||
255acee7 | 814 | EXPORT_SYMBOL(cpu_online_map); |
1da177e4 LT |
815 | EXPORT_SYMBOL(cpu_possible_map); |
816 | EXPORT_SYMBOL(lowcore_ptr); | |
817 | EXPORT_SYMBOL(smp_ctl_set_bit); | |
818 | EXPORT_SYMBOL(smp_ctl_clear_bit); | |
819 | EXPORT_SYMBOL(smp_call_function); | |
820 | EXPORT_SYMBOL(smp_get_cpu); | |
821 | EXPORT_SYMBOL(smp_put_cpu); |