2 * SMP related functions
4 * Copyright IBM Corp. 1999, 2012
5 * Author(s): Denis Joseph Barrow,
6 * Martin Schwidefsky <schwidefsky@de.ibm.com>,
7 * Heiko Carstens <heiko.carstens@de.ibm.com>,
9 * based on other smp stuff by
10 * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
11 * (c) 1998 Ingo Molnar
13 * The code outside of smp.c uses logical cpu numbers, only smp.c does
14 * the translation of logical to physical cpu ids. All new code that
15 * operates on physical cpu numbers needs to go into smp.c.
18 #define KMSG_COMPONENT "cpu"
19 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
21 #include <linux/workqueue.h>
22 #include <linux/module.h>
23 #include <linux/init.h>
25 #include <linux/err.h>
26 #include <linux/spinlock.h>
27 #include <linux/kernel_stat.h>
28 #include <linux/delay.h>
29 #include <linux/interrupt.h>
30 #include <linux/irqflags.h>
31 #include <linux/cpu.h>
32 #include <linux/slab.h>
33 #include <linux/crash_dump.h>
34 #include <asm/asm-offsets.h>
35 #include <asm/switch_to.h>
36 #include <asm/facility.h>
38 #include <asm/setup.h>
40 #include <asm/tlbflush.h>
41 #include <asm/vtimer.h>
42 #include <asm/lowcore.h>
45 #include <asm/debug.h>
46 #include <asm/os_info.h>
53 ec_call_function_single
,
64 struct _lowcore
*lowcore
; /* lowcore page(s) for the cpu */
65 unsigned long async_stack
; /* async stack for the cpu */
66 unsigned long panic_stack
; /* panic stack for the cpu */
67 unsigned long ec_mask
; /* bit mask for ec_xxx functions */
68 int state
; /* physical cpu state */
69 int polarization
; /* physical polarization */
70 u16 address
; /* physical cpu address */
73 static u8 boot_cpu_type
;
74 static u16 boot_cpu_address
;
75 static struct pcpu pcpu_devices
[NR_CPUS
];
78 * The smp_cpu_state_mutex must be held when changing the state or polarization
79 * member of a pcpu data structure within the pcpu_devices arreay.
81 DEFINE_MUTEX(smp_cpu_state_mutex
);
84 * Signal processor helper functions.
86 static inline int __pcpu_sigp(u16 addr
, u8 order
, u32 parm
, u32
*status
)
88 register unsigned int reg1
asm ("1") = parm
;
95 : "=d" (cc
), "+d" (reg1
) : "d" (addr
), "a" (order
) : "cc");
96 if (status
&& cc
== 1)
101 static inline int __pcpu_sigp_relax(u16 addr
, u8 order
, u32 parm
, u32
*status
)
106 cc
= __pcpu_sigp(addr
, order
, parm
, NULL
);
107 if (cc
!= SIGP_CC_BUSY
)
113 static int pcpu_sigp_retry(struct pcpu
*pcpu
, u8 order
, u32 parm
)
117 for (retry
= 0; ; retry
++) {
118 cc
= __pcpu_sigp(pcpu
->address
, order
, parm
, NULL
);
119 if (cc
!= SIGP_CC_BUSY
)
127 static inline int pcpu_stopped(struct pcpu
*pcpu
)
129 u32
uninitialized_var(status
);
131 if (__pcpu_sigp(pcpu
->address
, SIGP_SENSE
,
132 0, &status
) != SIGP_CC_STATUS_STORED
)
134 return !!(status
& (SIGP_STATUS_CHECK_STOP
|SIGP_STATUS_STOPPED
));
137 static inline int pcpu_running(struct pcpu
*pcpu
)
139 if (__pcpu_sigp(pcpu
->address
, SIGP_SENSE_RUNNING
,
140 0, NULL
) != SIGP_CC_STATUS_STORED
)
142 /* Status stored condition code is equivalent to cpu not running. */
147 * Find struct pcpu by cpu address.
149 static struct pcpu
*pcpu_find_address(const struct cpumask
*mask
, int address
)
153 for_each_cpu(cpu
, mask
)
154 if (pcpu_devices
[cpu
].address
== address
)
155 return pcpu_devices
+ cpu
;
159 static void pcpu_ec_call(struct pcpu
*pcpu
, int ec_bit
)
163 set_bit(ec_bit
, &pcpu
->ec_mask
);
164 order
= pcpu_running(pcpu
) ?
165 SIGP_EXTERNAL_CALL
: SIGP_EMERGENCY_SIGNAL
;
166 pcpu_sigp_retry(pcpu
, order
, 0);
169 static int __cpuinit
pcpu_alloc_lowcore(struct pcpu
*pcpu
, int cpu
)
173 if (pcpu
!= &pcpu_devices
[0]) {
174 pcpu
->lowcore
= (struct _lowcore
*)
175 __get_free_pages(GFP_KERNEL
| GFP_DMA
, LC_ORDER
);
176 pcpu
->async_stack
= __get_free_pages(GFP_KERNEL
, ASYNC_ORDER
);
177 pcpu
->panic_stack
= __get_free_page(GFP_KERNEL
);
178 if (!pcpu
->lowcore
|| !pcpu
->panic_stack
|| !pcpu
->async_stack
)
182 memcpy(lc
, &S390_lowcore
, 512);
183 memset((char *) lc
+ 512, 0, sizeof(*lc
) - 512);
184 lc
->async_stack
= pcpu
->async_stack
+ ASYNC_SIZE
185 - STACK_FRAME_OVERHEAD
- sizeof(struct pt_regs
);
186 lc
->panic_stack
= pcpu
->panic_stack
+ PAGE_SIZE
187 - STACK_FRAME_OVERHEAD
- sizeof(struct pt_regs
);
190 if (MACHINE_HAS_IEEE
) {
191 lc
->extended_save_area_addr
= get_zeroed_page(GFP_KERNEL
);
192 if (!lc
->extended_save_area_addr
)
196 if (vdso_alloc_per_cpu(lc
))
199 lowcore_ptr
[cpu
] = lc
;
200 pcpu_sigp_retry(pcpu
, SIGP_SET_PREFIX
, (u32
)(unsigned long) lc
);
203 if (pcpu
!= &pcpu_devices
[0]) {
204 free_page(pcpu
->panic_stack
);
205 free_pages(pcpu
->async_stack
, ASYNC_ORDER
);
206 free_pages((unsigned long) pcpu
->lowcore
, LC_ORDER
);
211 #ifdef CONFIG_HOTPLUG_CPU
213 static void pcpu_free_lowcore(struct pcpu
*pcpu
)
215 pcpu_sigp_retry(pcpu
, SIGP_SET_PREFIX
, 0);
216 lowcore_ptr
[pcpu
- pcpu_devices
] = NULL
;
218 if (MACHINE_HAS_IEEE
) {
219 struct _lowcore
*lc
= pcpu
->lowcore
;
221 free_page((unsigned long) lc
->extended_save_area_addr
);
222 lc
->extended_save_area_addr
= 0;
225 vdso_free_per_cpu(pcpu
->lowcore
);
227 if (pcpu
!= &pcpu_devices
[0]) {
228 free_page(pcpu
->panic_stack
);
229 free_pages(pcpu
->async_stack
, ASYNC_ORDER
);
230 free_pages((unsigned long) pcpu
->lowcore
, LC_ORDER
);
234 #endif /* CONFIG_HOTPLUG_CPU */
236 static void pcpu_prepare_secondary(struct pcpu
*pcpu
, int cpu
)
238 struct _lowcore
*lc
= pcpu
->lowcore
;
240 atomic_inc(&init_mm
.context
.attach_count
);
242 lc
->percpu_offset
= __per_cpu_offset
[cpu
];
243 lc
->kernel_asce
= S390_lowcore
.kernel_asce
;
244 lc
->machine_flags
= S390_lowcore
.machine_flags
;
245 lc
->ftrace_func
= S390_lowcore
.ftrace_func
;
246 lc
->user_timer
= lc
->system_timer
= lc
->steal_timer
= 0;
247 __ctl_store(lc
->cregs_save_area
, 0, 15);
248 save_access_regs((unsigned int *) lc
->access_regs_save_area
);
249 memcpy(lc
->stfle_fac_list
, S390_lowcore
.stfle_fac_list
,
253 static void pcpu_attach_task(struct pcpu
*pcpu
, struct task_struct
*tsk
)
255 struct _lowcore
*lc
= pcpu
->lowcore
;
256 struct thread_info
*ti
= task_thread_info(tsk
);
258 lc
->kernel_stack
= (unsigned long) task_stack_page(tsk
)
259 + THREAD_SIZE
- STACK_FRAME_OVERHEAD
- sizeof(struct pt_regs
);
260 lc
->thread_info
= (unsigned long) task_thread_info(tsk
);
261 lc
->current_task
= (unsigned long) tsk
;
262 lc
->user_timer
= ti
->user_timer
;
263 lc
->system_timer
= ti
->system_timer
;
267 static void pcpu_start_fn(struct pcpu
*pcpu
, void (*func
)(void *), void *data
)
269 struct _lowcore
*lc
= pcpu
->lowcore
;
271 lc
->restart_stack
= lc
->kernel_stack
;
272 lc
->restart_fn
= (unsigned long) func
;
273 lc
->restart_data
= (unsigned long) data
;
274 lc
->restart_source
= -1UL;
275 pcpu_sigp_retry(pcpu
, SIGP_RESTART
, 0);
279 * Call function via PSW restart on pcpu and stop the current cpu.
281 static void pcpu_delegate(struct pcpu
*pcpu
, void (*func
)(void *),
282 void *data
, unsigned long stack
)
284 struct _lowcore
*lc
= lowcore_ptr
[pcpu
- pcpu_devices
];
285 unsigned long source_cpu
= stap();
287 __load_psw_mask(psw_kernel_bits
);
288 if (pcpu
->address
== source_cpu
)
289 func(data
); /* should not return */
290 /* Stop target cpu (if func returns this stops the current cpu). */
291 pcpu_sigp_retry(pcpu
, SIGP_STOP
, 0);
292 /* Restart func on the target cpu and stop the current cpu. */
293 mem_assign_absolute(lc
->restart_stack
, stack
);
294 mem_assign_absolute(lc
->restart_fn
, (unsigned long) func
);
295 mem_assign_absolute(lc
->restart_data
, (unsigned long) data
);
296 mem_assign_absolute(lc
->restart_source
, source_cpu
);
298 "0: sigp 0,%0,%2 # sigp restart to target cpu\n"
299 " brc 2,0b # busy, try again\n"
300 "1: sigp 0,%1,%3 # sigp stop to current cpu\n"
301 " brc 2,1b # busy, try again\n"
302 : : "d" (pcpu
->address
), "d" (source_cpu
),
303 "K" (SIGP_RESTART
), "K" (SIGP_STOP
)
309 * Call function on an online CPU.
311 void smp_call_online_cpu(void (*func
)(void *), void *data
)
315 /* Use the current cpu if it is online. */
316 pcpu
= pcpu_find_address(cpu_online_mask
, stap());
318 /* Use the first online cpu. */
319 pcpu
= pcpu_devices
+ cpumask_first(cpu_online_mask
);
320 pcpu_delegate(pcpu
, func
, data
, (unsigned long) restart_stack
);
324 * Call function on the ipl CPU.
326 void smp_call_ipl_cpu(void (*func
)(void *), void *data
)
328 pcpu_delegate(&pcpu_devices
[0], func
, data
,
329 pcpu_devices
->panic_stack
+ PAGE_SIZE
);
332 int smp_find_processor_id(u16 address
)
336 for_each_present_cpu(cpu
)
337 if (pcpu_devices
[cpu
].address
== address
)
342 int smp_vcpu_scheduled(int cpu
)
344 return pcpu_running(pcpu_devices
+ cpu
);
349 if (MACHINE_HAS_DIAG44
)
350 asm volatile("diag 0,0,0x44");
353 void smp_yield_cpu(int cpu
)
355 if (MACHINE_HAS_DIAG9C
)
356 asm volatile("diag %0,0,0x9c"
357 : : "d" (pcpu_devices
[cpu
].address
));
358 else if (MACHINE_HAS_DIAG44
)
359 asm volatile("diag 0,0,0x44");
363 * Send cpus emergency shutdown signal. This gives the cpus the
364 * opportunity to complete outstanding interrupts.
366 void smp_emergency_stop(cpumask_t
*cpumask
)
371 end
= get_tod_clock() + (1000000UL << 12);
372 for_each_cpu(cpu
, cpumask
) {
373 struct pcpu
*pcpu
= pcpu_devices
+ cpu
;
374 set_bit(ec_stop_cpu
, &pcpu
->ec_mask
);
375 while (__pcpu_sigp(pcpu
->address
, SIGP_EMERGENCY_SIGNAL
,
376 0, NULL
) == SIGP_CC_BUSY
&&
377 get_tod_clock() < end
)
380 while (get_tod_clock() < end
) {
381 for_each_cpu(cpu
, cpumask
)
382 if (pcpu_stopped(pcpu_devices
+ cpu
))
383 cpumask_clear_cpu(cpu
, cpumask
);
384 if (cpumask_empty(cpumask
))
391 * Stop all cpus but the current one.
393 void smp_send_stop(void)
398 /* Disable all interrupts/machine checks */
399 __load_psw_mask(psw_kernel_bits
| PSW_MASK_DAT
);
400 trace_hardirqs_off();
402 debug_set_critical();
403 cpumask_copy(&cpumask
, cpu_online_mask
);
404 cpumask_clear_cpu(smp_processor_id(), &cpumask
);
406 if (oops_in_progress
)
407 smp_emergency_stop(&cpumask
);
409 /* stop all processors */
410 for_each_cpu(cpu
, &cpumask
) {
411 struct pcpu
*pcpu
= pcpu_devices
+ cpu
;
412 pcpu_sigp_retry(pcpu
, SIGP_STOP
, 0);
413 while (!pcpu_stopped(pcpu
))
419 * Stop the current cpu.
421 void smp_stop_cpu(void)
423 pcpu_sigp_retry(pcpu_devices
+ smp_processor_id(), SIGP_STOP
, 0);
428 * This is the main routine where commands issued by other
431 static void smp_handle_ext_call(void)
435 /* handle bit signal external calls */
436 bits
= xchg(&pcpu_devices
[smp_processor_id()].ec_mask
, 0);
437 if (test_bit(ec_stop_cpu
, &bits
))
439 if (test_bit(ec_schedule
, &bits
))
441 if (test_bit(ec_call_function
, &bits
))
442 generic_smp_call_function_interrupt();
443 if (test_bit(ec_call_function_single
, &bits
))
444 generic_smp_call_function_single_interrupt();
447 static void do_ext_call_interrupt(struct ext_code ext_code
,
448 unsigned int param32
, unsigned long param64
)
450 inc_irq_stat(ext_code
.code
== 0x1202 ? IRQEXT_EXC
: IRQEXT_EMS
);
451 smp_handle_ext_call();
454 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
458 for_each_cpu(cpu
, mask
)
459 pcpu_ec_call(pcpu_devices
+ cpu
, ec_call_function
);
462 void arch_send_call_function_single_ipi(int cpu
)
464 pcpu_ec_call(pcpu_devices
+ cpu
, ec_call_function_single
);
469 * this function sends a 'purge tlb' signal to another CPU.
471 static void smp_ptlb_callback(void *info
)
476 void smp_ptlb_all(void)
478 on_each_cpu(smp_ptlb_callback
, NULL
, 1);
480 EXPORT_SYMBOL(smp_ptlb_all
);
481 #endif /* ! CONFIG_64BIT */
484 * this function sends a 'reschedule' IPI to another CPU.
485 * it goes straight through and wastes no time serializing
486 * anything. Worst case is that we lose a reschedule ...
488 void smp_send_reschedule(int cpu
)
490 pcpu_ec_call(pcpu_devices
+ cpu
, ec_schedule
);
494 * parameter area for the set/clear control bit callbacks
496 struct ec_creg_mask_parms
{
498 unsigned long andval
;
503 * callback for setting/clearing control bits
505 static void smp_ctl_bit_callback(void *info
)
507 struct ec_creg_mask_parms
*pp
= info
;
508 unsigned long cregs
[16];
510 __ctl_store(cregs
, 0, 15);
511 cregs
[pp
->cr
] = (cregs
[pp
->cr
] & pp
->andval
) | pp
->orval
;
512 __ctl_load(cregs
, 0, 15);
516 * Set a bit in a control register of all cpus
518 void smp_ctl_set_bit(int cr
, int bit
)
520 struct ec_creg_mask_parms parms
= { 1UL << bit
, -1UL, cr
};
522 on_each_cpu(smp_ctl_bit_callback
, &parms
, 1);
524 EXPORT_SYMBOL(smp_ctl_set_bit
);
527 * Clear a bit in a control register of all cpus
529 void smp_ctl_clear_bit(int cr
, int bit
)
531 struct ec_creg_mask_parms parms
= { 0, ~(1UL << bit
), cr
};
533 on_each_cpu(smp_ctl_bit_callback
, &parms
, 1);
535 EXPORT_SYMBOL(smp_ctl_clear_bit
);
537 #if defined(CONFIG_ZFCPDUMP) || defined(CONFIG_CRASH_DUMP)
539 struct save_area
*zfcpdump_save_areas
[NR_CPUS
+ 1];
540 EXPORT_SYMBOL_GPL(zfcpdump_save_areas
);
542 static void __init
smp_get_save_area(int cpu
, u16 address
)
544 void *lc
= pcpu_devices
[0].lowcore
;
545 struct save_area
*save_area
;
547 if (is_kdump_kernel())
549 if (!OLDMEM_BASE
&& (address
== boot_cpu_address
||
550 ipl_info
.type
!= IPL_TYPE_FCP_DUMP
))
552 if (cpu
>= NR_CPUS
) {
553 pr_warning("CPU %i exceeds the maximum %i and is excluded "
554 "from the dump\n", cpu
, NR_CPUS
- 1);
557 save_area
= kmalloc(sizeof(struct save_area
), GFP_KERNEL
);
559 panic("could not allocate memory for save area\n");
560 zfcpdump_save_areas
[cpu
] = save_area
;
561 #ifdef CONFIG_CRASH_DUMP
562 if (address
== boot_cpu_address
) {
563 /* Copy the registers of the boot cpu. */
564 copy_oldmem_page(1, (void *) save_area
, sizeof(*save_area
),
565 SAVE_AREA_BASE
- PAGE_SIZE
, 0);
569 /* Get the registers of a non-boot cpu. */
570 __pcpu_sigp_relax(address
, SIGP_STOP_AND_STORE_STATUS
, 0, NULL
);
571 memcpy_real(save_area
, lc
+ SAVE_AREA_BASE
, sizeof(*save_area
));
574 int smp_store_status(int cpu
)
578 pcpu
= pcpu_devices
+ cpu
;
579 if (__pcpu_sigp_relax(pcpu
->address
, SIGP_STOP_AND_STORE_STATUS
,
580 0, NULL
) != SIGP_CC_ORDER_CODE_ACCEPTED
)
585 #else /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */
587 static inline void smp_get_save_area(int cpu
, u16 address
) { }
589 #endif /* CONFIG_ZFCPDUMP || CONFIG_CRASH_DUMP */
591 void smp_cpu_set_polarization(int cpu
, int val
)
593 pcpu_devices
[cpu
].polarization
= val
;
596 int smp_cpu_get_polarization(int cpu
)
598 return pcpu_devices
[cpu
].polarization
;
601 static struct sclp_cpu_info
*smp_get_cpu_info(void)
603 static int use_sigp_detection
;
604 struct sclp_cpu_info
*info
;
607 info
= kzalloc(sizeof(*info
), GFP_KERNEL
);
608 if (info
&& (use_sigp_detection
|| sclp_get_cpu_info(info
))) {
609 use_sigp_detection
= 1;
610 for (address
= 0; address
<= MAX_CPU_ADDRESS
; address
++) {
611 if (__pcpu_sigp_relax(address
, SIGP_SENSE
, 0, NULL
) ==
612 SIGP_CC_NOT_OPERATIONAL
)
614 info
->cpu
[info
->configured
].address
= address
;
617 info
->combined
= info
->configured
;
622 static int __cpuinit
smp_add_present_cpu(int cpu
);
624 static int __cpuinit
__smp_rescan_cpus(struct sclp_cpu_info
*info
,
632 cpumask_xor(&avail
, cpu_possible_mask
, cpu_present_mask
);
633 cpu
= cpumask_first(&avail
);
634 for (i
= 0; (i
< info
->combined
) && (cpu
< nr_cpu_ids
); i
++) {
635 if (info
->has_cpu_type
&& info
->cpu
[i
].type
!= boot_cpu_type
)
637 if (pcpu_find_address(cpu_present_mask
, info
->cpu
[i
].address
))
639 pcpu
= pcpu_devices
+ cpu
;
640 pcpu
->address
= info
->cpu
[i
].address
;
641 pcpu
->state
= (i
>= info
->configured
) ?
642 CPU_STATE_STANDBY
: CPU_STATE_CONFIGURED
;
643 smp_cpu_set_polarization(cpu
, POLARIZATION_UNKNOWN
);
644 set_cpu_present(cpu
, true);
645 if (sysfs_add
&& smp_add_present_cpu(cpu
) != 0)
646 set_cpu_present(cpu
, false);
649 cpu
= cpumask_next(cpu
, &avail
);
654 static void __init
smp_detect_cpus(void)
656 unsigned int cpu
, c_cpus
, s_cpus
;
657 struct sclp_cpu_info
*info
;
659 info
= smp_get_cpu_info();
661 panic("smp_detect_cpus failed to allocate memory\n");
662 if (info
->has_cpu_type
) {
663 for (cpu
= 0; cpu
< info
->combined
; cpu
++) {
664 if (info
->cpu
[cpu
].address
!= boot_cpu_address
)
666 /* The boot cpu dictates the cpu type. */
667 boot_cpu_type
= info
->cpu
[cpu
].type
;
672 for (cpu
= 0; cpu
< info
->combined
; cpu
++) {
673 if (info
->has_cpu_type
&& info
->cpu
[cpu
].type
!= boot_cpu_type
)
675 if (cpu
< info
->configured
) {
676 smp_get_save_area(c_cpus
, info
->cpu
[cpu
].address
);
681 pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus
, s_cpus
);
683 __smp_rescan_cpus(info
, 0);
689 * Activate a secondary processor.
691 static void __cpuinit
smp_start_secondary(void *cpuvoid
)
693 S390_lowcore
.last_update_clock
= get_tod_clock();
694 S390_lowcore
.restart_stack
= (unsigned long) restart_stack
;
695 S390_lowcore
.restart_fn
= (unsigned long) do_restart
;
696 S390_lowcore
.restart_data
= 0;
697 S390_lowcore
.restart_source
= -1UL;
698 restore_access_regs(S390_lowcore
.access_regs_save_area
);
699 __ctl_load(S390_lowcore
.cregs_save_area
, 0, 15);
700 __load_psw_mask(psw_kernel_bits
| PSW_MASK_DAT
);
706 notify_cpu_starting(smp_processor_id());
707 set_cpu_online(smp_processor_id(), true);
708 inc_irq_stat(CPU_RST
);
710 cpu_startup_entry(CPUHP_ONLINE
);
713 /* Upping and downing of CPUs */
714 int __cpuinit
__cpu_up(unsigned int cpu
, struct task_struct
*tidle
)
719 pcpu
= pcpu_devices
+ cpu
;
720 if (pcpu
->state
!= CPU_STATE_CONFIGURED
)
722 if (pcpu_sigp_retry(pcpu
, SIGP_INITIAL_CPU_RESET
, 0) !=
723 SIGP_CC_ORDER_CODE_ACCEPTED
)
726 rc
= pcpu_alloc_lowcore(pcpu
, cpu
);
729 pcpu_prepare_secondary(pcpu
, cpu
);
730 pcpu_attach_task(pcpu
, tidle
);
731 pcpu_start_fn(pcpu
, smp_start_secondary
, NULL
);
732 while (!cpu_online(cpu
))
737 static int __init
setup_possible_cpus(char *s
)
741 if (kstrtoint(s
, 0, &max
) < 0)
743 init_cpu_possible(cpumask_of(0));
744 for (cpu
= 1; cpu
< max
&& cpu
< nr_cpu_ids
; cpu
++)
745 set_cpu_possible(cpu
, true);
748 early_param("possible_cpus", setup_possible_cpus
);
750 #ifdef CONFIG_HOTPLUG_CPU
752 int __cpu_disable(void)
754 unsigned long cregs
[16];
756 /* Handle possible pending IPIs */
757 smp_handle_ext_call();
758 set_cpu_online(smp_processor_id(), false);
759 /* Disable pseudo page faults on this cpu. */
761 /* Disable interrupt sources via control register. */
762 __ctl_store(cregs
, 0, 15);
763 cregs
[0] &= ~0x0000ee70UL
; /* disable all external interrupts */
764 cregs
[6] &= ~0xff000000UL
; /* disable all I/O interrupts */
765 cregs
[14] &= ~0x1f000000UL
; /* disable most machine checks */
766 __ctl_load(cregs
, 0, 15);
770 void __cpu_die(unsigned int cpu
)
774 /* Wait until target cpu is down */
775 pcpu
= pcpu_devices
+ cpu
;
776 while (!pcpu_stopped(pcpu
))
778 pcpu_free_lowcore(pcpu
);
779 atomic_dec(&init_mm
.context
.attach_count
);
782 void __noreturn
cpu_die(void)
785 pcpu_sigp_retry(pcpu_devices
+ smp_processor_id(), SIGP_STOP
, 0);
789 #endif /* CONFIG_HOTPLUG_CPU */
791 void __init
smp_prepare_cpus(unsigned int max_cpus
)
793 /* request the 0x1201 emergency signal external interrupt */
794 if (register_external_interrupt(0x1201, do_ext_call_interrupt
) != 0)
795 panic("Couldn't request external interrupt 0x1201");
796 /* request the 0x1202 external call external interrupt */
797 if (register_external_interrupt(0x1202, do_ext_call_interrupt
) != 0)
798 panic("Couldn't request external interrupt 0x1202");
802 void __init
smp_prepare_boot_cpu(void)
804 struct pcpu
*pcpu
= pcpu_devices
;
806 boot_cpu_address
= stap();
807 pcpu
->state
= CPU_STATE_CONFIGURED
;
808 pcpu
->address
= boot_cpu_address
;
809 pcpu
->lowcore
= (struct _lowcore
*)(unsigned long) store_prefix();
810 pcpu
->async_stack
= S390_lowcore
.async_stack
- ASYNC_SIZE
811 + STACK_FRAME_OVERHEAD
+ sizeof(struct pt_regs
);
812 pcpu
->panic_stack
= S390_lowcore
.panic_stack
- PAGE_SIZE
813 + STACK_FRAME_OVERHEAD
+ sizeof(struct pt_regs
);
814 S390_lowcore
.percpu_offset
= __per_cpu_offset
[0];
815 smp_cpu_set_polarization(0, POLARIZATION_UNKNOWN
);
816 set_cpu_present(0, true);
817 set_cpu_online(0, true);
820 void __init
smp_cpus_done(unsigned int max_cpus
)
824 void __init
smp_setup_processor_id(void)
826 S390_lowcore
.cpu_nr
= 0;
830 * the frequency of the profiling timer can be changed
831 * by writing a multiplier value into /proc/profile.
833 * usually you want to run this on all CPUs ;)
835 int setup_profiling_timer(unsigned int multiplier
)
840 #ifdef CONFIG_HOTPLUG_CPU
841 static ssize_t
cpu_configure_show(struct device
*dev
,
842 struct device_attribute
*attr
, char *buf
)
846 mutex_lock(&smp_cpu_state_mutex
);
847 count
= sprintf(buf
, "%d\n", pcpu_devices
[dev
->id
].state
);
848 mutex_unlock(&smp_cpu_state_mutex
);
852 static ssize_t
cpu_configure_store(struct device
*dev
,
853 struct device_attribute
*attr
,
854 const char *buf
, size_t count
)
860 if (sscanf(buf
, "%d %c", &val
, &delim
) != 1)
862 if (val
!= 0 && val
!= 1)
865 mutex_lock(&smp_cpu_state_mutex
);
867 /* disallow configuration changes of online cpus and cpu 0 */
869 if (cpu_online(cpu
) || cpu
== 0)
871 pcpu
= pcpu_devices
+ cpu
;
875 if (pcpu
->state
!= CPU_STATE_CONFIGURED
)
877 rc
= sclp_cpu_deconfigure(pcpu
->address
);
880 pcpu
->state
= CPU_STATE_STANDBY
;
881 smp_cpu_set_polarization(cpu
, POLARIZATION_UNKNOWN
);
882 topology_expect_change();
885 if (pcpu
->state
!= CPU_STATE_STANDBY
)
887 rc
= sclp_cpu_configure(pcpu
->address
);
890 pcpu
->state
= CPU_STATE_CONFIGURED
;
891 smp_cpu_set_polarization(cpu
, POLARIZATION_UNKNOWN
);
892 topology_expect_change();
898 mutex_unlock(&smp_cpu_state_mutex
);
900 return rc
? rc
: count
;
902 static DEVICE_ATTR(configure
, 0644, cpu_configure_show
, cpu_configure_store
);
903 #endif /* CONFIG_HOTPLUG_CPU */
905 static ssize_t
show_cpu_address(struct device
*dev
,
906 struct device_attribute
*attr
, char *buf
)
908 return sprintf(buf
, "%d\n", pcpu_devices
[dev
->id
].address
);
910 static DEVICE_ATTR(address
, 0444, show_cpu_address
, NULL
);
912 static struct attribute
*cpu_common_attrs
[] = {
913 #ifdef CONFIG_HOTPLUG_CPU
914 &dev_attr_configure
.attr
,
916 &dev_attr_address
.attr
,
920 static struct attribute_group cpu_common_attr_group
= {
921 .attrs
= cpu_common_attrs
,
924 static ssize_t
show_idle_count(struct device
*dev
,
925 struct device_attribute
*attr
, char *buf
)
927 struct s390_idle_data
*idle
= &per_cpu(s390_idle
, dev
->id
);
928 unsigned long long idle_count
;
929 unsigned int sequence
;
932 sequence
= ACCESS_ONCE(idle
->sequence
);
933 idle_count
= ACCESS_ONCE(idle
->idle_count
);
934 if (ACCESS_ONCE(idle
->clock_idle_enter
))
936 } while ((sequence
& 1) || (idle
->sequence
!= sequence
));
937 return sprintf(buf
, "%llu\n", idle_count
);
939 static DEVICE_ATTR(idle_count
, 0444, show_idle_count
, NULL
);
941 static ssize_t
show_idle_time(struct device
*dev
,
942 struct device_attribute
*attr
, char *buf
)
944 struct s390_idle_data
*idle
= &per_cpu(s390_idle
, dev
->id
);
945 unsigned long long now
, idle_time
, idle_enter
, idle_exit
;
946 unsigned int sequence
;
949 now
= get_tod_clock();
950 sequence
= ACCESS_ONCE(idle
->sequence
);
951 idle_time
= ACCESS_ONCE(idle
->idle_time
);
952 idle_enter
= ACCESS_ONCE(idle
->clock_idle_enter
);
953 idle_exit
= ACCESS_ONCE(idle
->clock_idle_exit
);
954 } while ((sequence
& 1) || (idle
->sequence
!= sequence
));
955 idle_time
+= idle_enter
? ((idle_exit
? : now
) - idle_enter
) : 0;
956 return sprintf(buf
, "%llu\n", idle_time
>> 12);
958 static DEVICE_ATTR(idle_time_us
, 0444, show_idle_time
, NULL
);
960 static struct attribute
*cpu_online_attrs
[] = {
961 &dev_attr_idle_count
.attr
,
962 &dev_attr_idle_time_us
.attr
,
966 static struct attribute_group cpu_online_attr_group
= {
967 .attrs
= cpu_online_attrs
,
970 static int __cpuinit
smp_cpu_notify(struct notifier_block
*self
,
971 unsigned long action
, void *hcpu
)
973 unsigned int cpu
= (unsigned int)(long)hcpu
;
974 struct cpu
*c
= &pcpu_devices
[cpu
].cpu
;
975 struct device
*s
= &c
->dev
;
978 switch (action
& ~CPU_TASKS_FROZEN
) {
980 err
= sysfs_create_group(&s
->kobj
, &cpu_online_attr_group
);
983 sysfs_remove_group(&s
->kobj
, &cpu_online_attr_group
);
986 return notifier_from_errno(err
);
989 static int __cpuinit
smp_add_present_cpu(int cpu
)
991 struct cpu
*c
= &pcpu_devices
[cpu
].cpu
;
992 struct device
*s
= &c
->dev
;
996 rc
= register_cpu(c
, cpu
);
999 rc
= sysfs_create_group(&s
->kobj
, &cpu_common_attr_group
);
1002 if (cpu_online(cpu
)) {
1003 rc
= sysfs_create_group(&s
->kobj
, &cpu_online_attr_group
);
1007 rc
= topology_cpu_init(c
);
1013 if (cpu_online(cpu
))
1014 sysfs_remove_group(&s
->kobj
, &cpu_online_attr_group
);
1016 sysfs_remove_group(&s
->kobj
, &cpu_common_attr_group
);
1018 #ifdef CONFIG_HOTPLUG_CPU
1025 #ifdef CONFIG_HOTPLUG_CPU
1027 int __ref
smp_rescan_cpus(void)
1029 struct sclp_cpu_info
*info
;
1032 info
= smp_get_cpu_info();
1036 mutex_lock(&smp_cpu_state_mutex
);
1037 nr
= __smp_rescan_cpus(info
, 1);
1038 mutex_unlock(&smp_cpu_state_mutex
);
1042 topology_schedule_update();
1046 static ssize_t __ref
rescan_store(struct device
*dev
,
1047 struct device_attribute
*attr
,
1053 rc
= smp_rescan_cpus();
1054 return rc
? rc
: count
;
1056 static DEVICE_ATTR(rescan
, 0200, NULL
, rescan_store
);
1057 #endif /* CONFIG_HOTPLUG_CPU */
1059 static int __init
s390_smp_init(void)
1063 hotcpu_notifier(smp_cpu_notify
, 0);
1064 #ifdef CONFIG_HOTPLUG_CPU
1065 rc
= device_create_file(cpu_subsys
.dev_root
, &dev_attr_rescan
);
1069 for_each_present_cpu(cpu
) {
1070 rc
= smp_add_present_cpu(cpu
);
1076 subsys_initcall(s390_smp_init
);