2 * arch/s390/kernel/smp.c
4 * Copyright IBM Corp. 1999, 2009
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)
9 * based on other smp stuff by
10 * (c) 1995 Alan Cox, CymruNET Ltd <alan@cymru.net>
11 * (c) 1998 Ingo Molnar
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.
23 #define KMSG_COMPONENT "cpu"
24 #define pr_fmt(fmt) KMSG_COMPONENT ": " fmt
26 #include <linux/workqueue.h>
27 #include <linux/module.h>
28 #include <linux/init.h>
30 #include <linux/err.h>
31 #include <linux/spinlock.h>
32 #include <linux/kernel_stat.h>
33 #include <linux/delay.h>
34 #include <linux/cache.h>
35 #include <linux/interrupt.h>
36 #include <linux/irqflags.h>
37 #include <linux/cpu.h>
38 #include <linux/timex.h>
39 #include <linux/bootmem.h>
40 #include <linux/slab.h>
41 #include <asm/asm-offsets.h>
43 #include <asm/setup.h>
45 #include <asm/pgalloc.h>
47 #include <asm/cpcmd.h>
48 #include <asm/tlbflush.h>
49 #include <asm/timer.h>
50 #include <asm/lowcore.h>
52 #include <asm/cputime.h>
57 /* logical cpu to cpu address */
58 unsigned short __cpu_logical_map
[NR_CPUS
];
60 static struct task_struct
*current_set
[NR_CPUS
];
62 static u8 smp_cpu_type
;
63 static int smp_use_sigp_detection
;
70 DEFINE_MUTEX(smp_cpu_state_mutex
);
71 int smp_cpu_polarization
[NR_CPUS
];
72 static int smp_cpu_state
[NR_CPUS
];
73 static int cpu_management
;
75 static DEFINE_PER_CPU(struct cpu
, cpu_devices
);
77 static void smp_ext_bitcall(int, int);
79 static int raw_cpu_stopped(int cpu
)
83 switch (raw_sigp_ps(&status
, 0, cpu
, sigp_sense
)) {
84 case sigp_status_stored
:
85 /* Check for stopped and check stop state */
95 static inline int cpu_stopped(int cpu
)
97 return raw_cpu_stopped(cpu_logical_map(cpu
));
101 * Ensure that PSW restart is done on an online CPU
103 void smp_restart_with_online_cpu(void)
107 for_each_online_cpu(cpu
) {
108 if (stap() == __cpu_logical_map
[cpu
]) {
109 /* We are online: Enable DAT again and return */
110 __load_psw_mask(psw_kernel_bits
& ~PSW_MASK_MCHECK
);
114 /* We are not online: Do PSW restart on an online CPU */
115 while (sigp(cpu
, sigp_restart
) == sigp_busy
)
117 /* And stop ourself */
118 while (raw_sigp(stap(), sigp_stop
) == sigp_busy
)
123 void smp_switch_to_ipl_cpu(void (*func
)(void *), void *data
)
125 struct _lowcore
*lc
, *current_lc
;
126 struct stack_frame
*sf
;
127 struct pt_regs
*regs
;
130 if (smp_processor_id() == 0)
132 __load_psw_mask(PSW_BASE_BITS
| PSW_DEFAULT_KEY
);
133 /* Disable lowcore protection */
134 __ctl_clear_bit(0, 28);
135 current_lc
= lowcore_ptr
[smp_processor_id()];
139 lc
->restart_psw
.mask
= PSW_BASE_BITS
| PSW_DEFAULT_KEY
;
140 lc
->restart_psw
.addr
= PSW_ADDR_AMODE
| (unsigned long) smp_restart_cpu
;
142 smp_switch_to_cpu(func
, data
, 0, stap(), __cpu_logical_map
[0]);
143 while (sigp(0, sigp_stop_and_store_status
) == sigp_busy
)
145 sp
= lc
->panic_stack
;
146 sp
-= sizeof(struct pt_regs
);
147 regs
= (struct pt_regs
*) sp
;
148 memcpy(®s
->gprs
, ¤t_lc
->gpregs_save_area
, sizeof(regs
->gprs
));
149 regs
->psw
= lc
->psw_save_area
;
150 sp
-= STACK_FRAME_OVERHEAD
;
151 sf
= (struct stack_frame
*) sp
;
152 sf
->back_chain
= regs
->gprs
[15];
153 smp_switch_to_cpu(func
, data
, sp
, stap(), __cpu_logical_map
[0]);
156 void smp_send_stop(void)
160 /* Disable all interrupts/machine checks */
161 __load_psw_mask(psw_kernel_bits
& ~PSW_MASK_MCHECK
);
162 trace_hardirqs_off();
164 /* stop all processors */
165 for_each_online_cpu(cpu
) {
166 if (cpu
== smp_processor_id())
169 rc
= sigp(cpu
, sigp_stop
);
170 } while (rc
== sigp_busy
);
172 while (!cpu_stopped(cpu
))
178 * This is the main routine where commands issued by other
182 static void do_ext_call_interrupt(unsigned int ext_int_code
,
183 unsigned int param32
, unsigned long param64
)
187 kstat_cpu(smp_processor_id()).irqs
[EXTINT_IPI
]++;
189 * handle bit signal external calls
191 bits
= xchg(&S390_lowcore
.ext_call_fast
, 0);
193 if (test_bit(ec_schedule
, &bits
))
196 if (test_bit(ec_call_function
, &bits
))
197 generic_smp_call_function_interrupt();
199 if (test_bit(ec_call_function_single
, &bits
))
200 generic_smp_call_function_single_interrupt();
204 * Send an external call sigp to another cpu and return without waiting
205 * for its completion.
207 static void smp_ext_bitcall(int cpu
, int sig
)
210 * Set signaling bit in lowcore of target cpu and kick it
212 set_bit(sig
, (unsigned long *) &lowcore_ptr
[cpu
]->ext_call_fast
);
213 while (sigp(cpu
, sigp_emergency_signal
) == sigp_busy
)
217 void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
221 for_each_cpu(cpu
, mask
)
222 smp_ext_bitcall(cpu
, ec_call_function
);
225 void arch_send_call_function_single_ipi(int cpu
)
227 smp_ext_bitcall(cpu
, ec_call_function_single
);
232 * this function sends a 'purge tlb' signal to another CPU.
234 static void smp_ptlb_callback(void *info
)
239 void smp_ptlb_all(void)
241 on_each_cpu(smp_ptlb_callback
, NULL
, 1);
243 EXPORT_SYMBOL(smp_ptlb_all
);
244 #endif /* ! CONFIG_64BIT */
247 * this function sends a 'reschedule' IPI to another CPU.
248 * it goes straight through and wastes no time serializing
249 * anything. Worst case is that we lose a reschedule ...
251 void smp_send_reschedule(int cpu
)
253 smp_ext_bitcall(cpu
, ec_schedule
);
257 * parameter area for the set/clear control bit callbacks
259 struct ec_creg_mask_parms
{
260 unsigned long orvals
[16];
261 unsigned long andvals
[16];
265 * callback for setting/clearing control bits
267 static void smp_ctl_bit_callback(void *info
)
269 struct ec_creg_mask_parms
*pp
= info
;
270 unsigned long cregs
[16];
273 __ctl_store(cregs
, 0, 15);
274 for (i
= 0; i
<= 15; i
++)
275 cregs
[i
] = (cregs
[i
] & pp
->andvals
[i
]) | pp
->orvals
[i
];
276 __ctl_load(cregs
, 0, 15);
280 * Set a bit in a control register of all cpus
282 void smp_ctl_set_bit(int cr
, int bit
)
284 struct ec_creg_mask_parms parms
;
286 memset(&parms
.orvals
, 0, sizeof(parms
.orvals
));
287 memset(&parms
.andvals
, 0xff, sizeof(parms
.andvals
));
288 parms
.orvals
[cr
] = 1UL << bit
;
289 on_each_cpu(smp_ctl_bit_callback
, &parms
, 1);
291 EXPORT_SYMBOL(smp_ctl_set_bit
);
294 * Clear a bit in a control register of all cpus
296 void smp_ctl_clear_bit(int cr
, int bit
)
298 struct ec_creg_mask_parms parms
;
300 memset(&parms
.orvals
, 0, sizeof(parms
.orvals
));
301 memset(&parms
.andvals
, 0xff, sizeof(parms
.andvals
));
302 parms
.andvals
[cr
] = ~(1UL << bit
);
303 on_each_cpu(smp_ctl_bit_callback
, &parms
, 1);
305 EXPORT_SYMBOL(smp_ctl_clear_bit
);
307 #ifdef CONFIG_ZFCPDUMP
309 static void __init
smp_get_save_area(unsigned int cpu
, unsigned int phy_cpu
)
311 if (ipl_info
.type
!= IPL_TYPE_FCP_DUMP
)
313 if (cpu
>= NR_CPUS
) {
314 pr_warning("CPU %i exceeds the maximum %i and is excluded from "
315 "the dump\n", cpu
, NR_CPUS
- 1);
318 zfcpdump_save_areas
[cpu
] = kmalloc(sizeof(struct save_area
), GFP_KERNEL
);
319 while (raw_sigp(phy_cpu
, sigp_stop_and_store_status
) == sigp_busy
)
321 memcpy_real(zfcpdump_save_areas
[cpu
],
322 (void *)(unsigned long) store_prefix() + SAVE_AREA_BASE
,
323 sizeof(struct save_area
));
326 struct save_area
*zfcpdump_save_areas
[NR_CPUS
+ 1];
327 EXPORT_SYMBOL_GPL(zfcpdump_save_areas
);
331 static inline void smp_get_save_area(unsigned int cpu
, unsigned int phy_cpu
) { }
333 #endif /* CONFIG_ZFCPDUMP */
335 static int cpu_known(int cpu_id
)
339 for_each_present_cpu(cpu
) {
340 if (__cpu_logical_map
[cpu
] == cpu_id
)
346 static int smp_rescan_cpus_sigp(cpumask_t avail
)
348 int cpu_id
, logical_cpu
;
350 logical_cpu
= cpumask_first(&avail
);
351 if (logical_cpu
>= nr_cpu_ids
)
353 for (cpu_id
= 0; cpu_id
<= MAX_CPU_ADDRESS
; cpu_id
++) {
354 if (cpu_known(cpu_id
))
356 __cpu_logical_map
[logical_cpu
] = cpu_id
;
357 smp_cpu_polarization
[logical_cpu
] = POLARIZATION_UNKNWN
;
358 if (!cpu_stopped(logical_cpu
))
360 set_cpu_present(logical_cpu
, true);
361 smp_cpu_state
[logical_cpu
] = CPU_STATE_CONFIGURED
;
362 logical_cpu
= cpumask_next(logical_cpu
, &avail
);
363 if (logical_cpu
>= nr_cpu_ids
)
369 static int smp_rescan_cpus_sclp(cpumask_t avail
)
371 struct sclp_cpu_info
*info
;
372 int cpu_id
, logical_cpu
, cpu
;
375 logical_cpu
= cpumask_first(&avail
);
376 if (logical_cpu
>= nr_cpu_ids
)
378 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
381 rc
= sclp_get_cpu_info(info
);
384 for (cpu
= 0; cpu
< info
->combined
; cpu
++) {
385 if (info
->has_cpu_type
&& info
->cpu
[cpu
].type
!= smp_cpu_type
)
387 cpu_id
= info
->cpu
[cpu
].address
;
388 if (cpu_known(cpu_id
))
390 __cpu_logical_map
[logical_cpu
] = cpu_id
;
391 smp_cpu_polarization
[logical_cpu
] = POLARIZATION_UNKNWN
;
392 set_cpu_present(logical_cpu
, true);
393 if (cpu
>= info
->configured
)
394 smp_cpu_state
[logical_cpu
] = CPU_STATE_STANDBY
;
396 smp_cpu_state
[logical_cpu
] = CPU_STATE_CONFIGURED
;
397 logical_cpu
= cpumask_next(logical_cpu
, &avail
);
398 if (logical_cpu
>= nr_cpu_ids
)
406 static int __smp_rescan_cpus(void)
410 cpumask_xor(&avail
, cpu_possible_mask
, cpu_present_mask
);
411 if (smp_use_sigp_detection
)
412 return smp_rescan_cpus_sigp(avail
);
414 return smp_rescan_cpus_sclp(avail
);
417 static void __init
smp_detect_cpus(void)
419 unsigned int cpu
, c_cpus
, s_cpus
;
420 struct sclp_cpu_info
*info
;
421 u16 boot_cpu_addr
, cpu_addr
;
425 boot_cpu_addr
= __cpu_logical_map
[0];
426 info
= kmalloc(sizeof(*info
), GFP_KERNEL
);
428 panic("smp_detect_cpus failed to allocate memory\n");
429 /* Use sigp detection algorithm if sclp doesn't work. */
430 if (sclp_get_cpu_info(info
)) {
431 smp_use_sigp_detection
= 1;
432 for (cpu
= 0; cpu
<= MAX_CPU_ADDRESS
; cpu
++) {
433 if (cpu
== boot_cpu_addr
)
435 if (!raw_cpu_stopped(cpu
))
437 smp_get_save_area(c_cpus
, cpu
);
443 if (info
->has_cpu_type
) {
444 for (cpu
= 0; cpu
< info
->combined
; cpu
++) {
445 if (info
->cpu
[cpu
].address
== boot_cpu_addr
) {
446 smp_cpu_type
= info
->cpu
[cpu
].type
;
452 for (cpu
= 0; cpu
< info
->combined
; cpu
++) {
453 if (info
->has_cpu_type
&& info
->cpu
[cpu
].type
!= smp_cpu_type
)
455 cpu_addr
= info
->cpu
[cpu
].address
;
456 if (cpu_addr
== boot_cpu_addr
)
458 if (!raw_cpu_stopped(cpu_addr
)) {
462 smp_get_save_area(c_cpus
, cpu_addr
);
467 pr_info("%d configured CPUs, %d standby CPUs\n", c_cpus
, s_cpus
);
474 * Activate a secondary processor.
476 int __cpuinit
start_secondary(void *cpuvoid
)
484 notify_cpu_starting(smp_processor_id());
486 set_cpu_online(smp_processor_id(), true);
488 __ctl_clear_bit(0, 28); /* Disable lowcore protection */
489 S390_lowcore
.restart_psw
.mask
= PSW_BASE_BITS
| PSW_DEFAULT_KEY
;
490 S390_lowcore
.restart_psw
.addr
=
491 PSW_ADDR_AMODE
| (unsigned long) psw_restart_int_handler
;
492 __ctl_set_bit(0, 28); /* Enable lowcore protection */
494 * Wait until the cpu which brought this one up marked it
495 * active before enabling interrupts.
497 while (!cpumask_test_cpu(smp_processor_id(), cpu_active_mask
))
500 /* cpu_idle will call schedule for us */
506 struct work_struct work
;
507 struct task_struct
*idle
;
508 struct completion done
;
512 static void __cpuinit
smp_fork_idle(struct work_struct
*work
)
514 struct create_idle
*c_idle
;
516 c_idle
= container_of(work
, struct create_idle
, work
);
517 c_idle
->idle
= fork_idle(c_idle
->cpu
);
518 complete(&c_idle
->done
);
521 static int __cpuinit
smp_alloc_lowcore(int cpu
)
523 unsigned long async_stack
, panic_stack
;
524 struct _lowcore
*lowcore
;
526 lowcore
= (void *) __get_free_pages(GFP_KERNEL
| GFP_DMA
, LC_ORDER
);
529 async_stack
= __get_free_pages(GFP_KERNEL
, ASYNC_ORDER
);
530 panic_stack
= __get_free_page(GFP_KERNEL
);
531 if (!panic_stack
|| !async_stack
)
533 memcpy(lowcore
, &S390_lowcore
, 512);
534 memset((char *)lowcore
+ 512, 0, sizeof(*lowcore
) - 512);
535 lowcore
->async_stack
= async_stack
+ ASYNC_SIZE
;
536 lowcore
->panic_stack
= panic_stack
+ PAGE_SIZE
;
537 lowcore
->restart_psw
.mask
= PSW_BASE_BITS
| PSW_DEFAULT_KEY
;
538 lowcore
->restart_psw
.addr
=
539 PSW_ADDR_AMODE
| (unsigned long) restart_int_handler
;
540 if (user_mode
!= HOME_SPACE_MODE
)
541 lowcore
->restart_psw
.mask
|= PSW_ASC_HOME
;
543 if (MACHINE_HAS_IEEE
) {
544 unsigned long save_area
;
546 save_area
= get_zeroed_page(GFP_KERNEL
);
549 lowcore
->extended_save_area_addr
= (u32
) save_area
;
552 if (vdso_alloc_per_cpu(cpu
, lowcore
))
555 lowcore_ptr
[cpu
] = lowcore
;
559 free_page(panic_stack
);
560 free_pages(async_stack
, ASYNC_ORDER
);
561 free_pages((unsigned long) lowcore
, LC_ORDER
);
565 static void smp_free_lowcore(int cpu
)
567 struct _lowcore
*lowcore
;
569 lowcore
= lowcore_ptr
[cpu
];
571 if (MACHINE_HAS_IEEE
)
572 free_page((unsigned long) lowcore
->extended_save_area_addr
);
574 vdso_free_per_cpu(cpu
, lowcore
);
576 free_page(lowcore
->panic_stack
- PAGE_SIZE
);
577 free_pages(lowcore
->async_stack
- ASYNC_SIZE
, ASYNC_ORDER
);
578 free_pages((unsigned long) lowcore
, LC_ORDER
);
579 lowcore_ptr
[cpu
] = NULL
;
582 /* Upping and downing of CPUs */
583 int __cpuinit
__cpu_up(unsigned int cpu
)
585 struct _lowcore
*cpu_lowcore
;
586 struct create_idle c_idle
;
587 struct task_struct
*idle
;
588 struct stack_frame
*sf
;
592 if (smp_cpu_state
[cpu
] != CPU_STATE_CONFIGURED
)
594 idle
= current_set
[cpu
];
596 c_idle
.done
= COMPLETION_INITIALIZER_ONSTACK(c_idle
.done
);
597 INIT_WORK_ONSTACK(&c_idle
.work
, smp_fork_idle
);
599 schedule_work(&c_idle
.work
);
600 wait_for_completion(&c_idle
.done
);
601 if (IS_ERR(c_idle
.idle
))
602 return PTR_ERR(c_idle
.idle
);
604 current_set
[cpu
] = c_idle
.idle
;
606 init_idle(idle
, cpu
);
607 if (smp_alloc_lowcore(cpu
))
610 ccode
= sigp(cpu
, sigp_initial_cpu_reset
);
611 if (ccode
== sigp_busy
)
613 if (ccode
== sigp_not_operational
)
615 } while (ccode
== sigp_busy
);
617 lowcore
= (u32
)(unsigned long)lowcore_ptr
[cpu
];
618 while (sigp_p(lowcore
, cpu
, sigp_set_prefix
) == sigp_busy
)
621 cpu_lowcore
= lowcore_ptr
[cpu
];
622 cpu_lowcore
->kernel_stack
= (unsigned long)
623 task_stack_page(idle
) + THREAD_SIZE
;
624 cpu_lowcore
->thread_info
= (unsigned long) task_thread_info(idle
);
625 sf
= (struct stack_frame
*) (cpu_lowcore
->kernel_stack
626 - sizeof(struct pt_regs
)
627 - sizeof(struct stack_frame
));
628 memset(sf
, 0, sizeof(struct stack_frame
));
629 sf
->gprs
[9] = (unsigned long) sf
;
630 cpu_lowcore
->save_area
[15] = (unsigned long) sf
;
631 __ctl_store(cpu_lowcore
->cregs_save_area
, 0, 15);
632 atomic_inc(&init_mm
.context
.attach_count
);
635 : : "a" (&cpu_lowcore
->access_regs_save_area
) : "memory");
636 cpu_lowcore
->percpu_offset
= __per_cpu_offset
[cpu
];
637 cpu_lowcore
->current_task
= (unsigned long) idle
;
638 cpu_lowcore
->cpu_nr
= cpu
;
639 cpu_lowcore
->kernel_asce
= S390_lowcore
.kernel_asce
;
640 cpu_lowcore
->machine_flags
= S390_lowcore
.machine_flags
;
641 cpu_lowcore
->ftrace_func
= S390_lowcore
.ftrace_func
;
642 memcpy(cpu_lowcore
->stfle_fac_list
, S390_lowcore
.stfle_fac_list
,
646 while (sigp(cpu
, sigp_restart
) == sigp_busy
)
649 while (!cpu_online(cpu
))
654 smp_free_lowcore(cpu
);
658 static int __init
setup_possible_cpus(char *s
)
662 pcpus
= simple_strtoul(s
, NULL
, 0);
663 init_cpu_possible(cpumask_of(0));
664 for (cpu
= 1; cpu
< pcpus
&& cpu
< nr_cpu_ids
; cpu
++)
665 set_cpu_possible(cpu
, true);
668 early_param("possible_cpus", setup_possible_cpus
);
670 #ifdef CONFIG_HOTPLUG_CPU
672 int __cpu_disable(void)
674 struct ec_creg_mask_parms cr_parms
;
675 int cpu
= smp_processor_id();
677 set_cpu_online(cpu
, false);
679 /* Disable pfault pseudo page faults on this cpu. */
682 memset(&cr_parms
.orvals
, 0, sizeof(cr_parms
.orvals
));
683 memset(&cr_parms
.andvals
, 0xff, sizeof(cr_parms
.andvals
));
685 /* disable all external interrupts */
686 cr_parms
.orvals
[0] = 0;
687 cr_parms
.andvals
[0] = ~(1 << 15 | 1 << 14 | 1 << 13 | 1 << 11 |
688 1 << 10 | 1 << 9 | 1 << 6 | 1 << 5 |
690 /* disable all I/O interrupts */
691 cr_parms
.orvals
[6] = 0;
692 cr_parms
.andvals
[6] = ~(1 << 31 | 1 << 30 | 1 << 29 | 1 << 28 |
693 1 << 27 | 1 << 26 | 1 << 25 | 1 << 24);
694 /* disable most machine checks */
695 cr_parms
.orvals
[14] = 0;
696 cr_parms
.andvals
[14] = ~(1 << 28 | 1 << 27 | 1 << 26 |
699 smp_ctl_bit_callback(&cr_parms
);
704 void __cpu_die(unsigned int cpu
)
706 /* Wait until target cpu is down */
707 while (!cpu_stopped(cpu
))
709 while (sigp_p(0, cpu
, sigp_set_prefix
) == sigp_busy
)
711 smp_free_lowcore(cpu
);
712 atomic_dec(&init_mm
.context
.attach_count
);
715 void __noreturn
cpu_die(void)
718 while (sigp(smp_processor_id(), sigp_stop
) == sigp_busy
)
723 #endif /* CONFIG_HOTPLUG_CPU */
725 void __init
smp_prepare_cpus(unsigned int max_cpus
)
728 unsigned long save_area
= 0;
730 unsigned long async_stack
, panic_stack
;
731 struct _lowcore
*lowcore
;
735 /* request the 0x1201 emergency signal external interrupt */
736 if (register_external_interrupt(0x1201, do_ext_call_interrupt
) != 0)
737 panic("Couldn't request external interrupt 0x1201");
739 /* Reallocate current lowcore, but keep its contents. */
740 lowcore
= (void *) __get_free_pages(GFP_KERNEL
| GFP_DMA
, LC_ORDER
);
741 panic_stack
= __get_free_page(GFP_KERNEL
);
742 async_stack
= __get_free_pages(GFP_KERNEL
, ASYNC_ORDER
);
743 BUG_ON(!lowcore
|| !panic_stack
|| !async_stack
);
745 if (MACHINE_HAS_IEEE
)
746 save_area
= get_zeroed_page(GFP_KERNEL
);
749 local_mcck_disable();
750 lowcore_ptr
[smp_processor_id()] = lowcore
;
751 *lowcore
= S390_lowcore
;
752 lowcore
->panic_stack
= panic_stack
+ PAGE_SIZE
;
753 lowcore
->async_stack
= async_stack
+ ASYNC_SIZE
;
755 if (MACHINE_HAS_IEEE
)
756 lowcore
->extended_save_area_addr
= (u32
) save_area
;
758 set_prefix((u32
)(unsigned long) lowcore
);
762 if (vdso_alloc_per_cpu(smp_processor_id(), &S390_lowcore
))
767 void __init
smp_prepare_boot_cpu(void)
769 BUG_ON(smp_processor_id() != 0);
771 current_thread_info()->cpu
= 0;
772 set_cpu_present(0, true);
773 set_cpu_online(0, true);
774 S390_lowcore
.percpu_offset
= __per_cpu_offset
[0];
775 current_set
[0] = current
;
776 smp_cpu_state
[0] = CPU_STATE_CONFIGURED
;
777 smp_cpu_polarization
[0] = POLARIZATION_UNKNWN
;
780 void __init
smp_cpus_done(unsigned int max_cpus
)
784 void __init
smp_setup_processor_id(void)
786 S390_lowcore
.cpu_nr
= 0;
787 __cpu_logical_map
[0] = stap();
791 * the frequency of the profiling timer can be changed
792 * by writing a multiplier value into /proc/profile.
794 * usually you want to run this on all CPUs ;)
796 int setup_profiling_timer(unsigned int multiplier
)
801 #ifdef CONFIG_HOTPLUG_CPU
802 static ssize_t
cpu_configure_show(struct sys_device
*dev
,
803 struct sysdev_attribute
*attr
, char *buf
)
807 mutex_lock(&smp_cpu_state_mutex
);
808 count
= sprintf(buf
, "%d\n", smp_cpu_state
[dev
->id
]);
809 mutex_unlock(&smp_cpu_state_mutex
);
813 static ssize_t
cpu_configure_store(struct sys_device
*dev
,
814 struct sysdev_attribute
*attr
,
815 const char *buf
, size_t count
)
821 if (sscanf(buf
, "%d %c", &val
, &delim
) != 1)
823 if (val
!= 0 && val
!= 1)
827 mutex_lock(&smp_cpu_state_mutex
);
829 /* disallow configuration changes of online cpus and cpu 0 */
830 if (cpu_online(cpu
) || cpu
== 0)
835 if (smp_cpu_state
[cpu
] == CPU_STATE_CONFIGURED
) {
836 rc
= sclp_cpu_deconfigure(__cpu_logical_map
[cpu
]);
838 smp_cpu_state
[cpu
] = CPU_STATE_STANDBY
;
839 smp_cpu_polarization
[cpu
] = POLARIZATION_UNKNWN
;
844 if (smp_cpu_state
[cpu
] == CPU_STATE_STANDBY
) {
845 rc
= sclp_cpu_configure(__cpu_logical_map
[cpu
]);
847 smp_cpu_state
[cpu
] = CPU_STATE_CONFIGURED
;
848 smp_cpu_polarization
[cpu
] = POLARIZATION_UNKNWN
;
856 mutex_unlock(&smp_cpu_state_mutex
);
858 return rc
? rc
: count
;
860 static SYSDEV_ATTR(configure
, 0644, cpu_configure_show
, cpu_configure_store
);
861 #endif /* CONFIG_HOTPLUG_CPU */
863 static ssize_t
cpu_polarization_show(struct sys_device
*dev
,
864 struct sysdev_attribute
*attr
, char *buf
)
869 mutex_lock(&smp_cpu_state_mutex
);
870 switch (smp_cpu_polarization
[cpu
]) {
871 case POLARIZATION_HRZ
:
872 count
= sprintf(buf
, "horizontal\n");
874 case POLARIZATION_VL
:
875 count
= sprintf(buf
, "vertical:low\n");
877 case POLARIZATION_VM
:
878 count
= sprintf(buf
, "vertical:medium\n");
880 case POLARIZATION_VH
:
881 count
= sprintf(buf
, "vertical:high\n");
884 count
= sprintf(buf
, "unknown\n");
887 mutex_unlock(&smp_cpu_state_mutex
);
890 static SYSDEV_ATTR(polarization
, 0444, cpu_polarization_show
, NULL
);
892 static ssize_t
show_cpu_address(struct sys_device
*dev
,
893 struct sysdev_attribute
*attr
, char *buf
)
895 return sprintf(buf
, "%d\n", __cpu_logical_map
[dev
->id
]);
897 static SYSDEV_ATTR(address
, 0444, show_cpu_address
, NULL
);
900 static struct attribute
*cpu_common_attrs
[] = {
901 #ifdef CONFIG_HOTPLUG_CPU
902 &attr_configure
.attr
,
905 &attr_polarization
.attr
,
909 static struct attribute_group cpu_common_attr_group
= {
910 .attrs
= cpu_common_attrs
,
913 static ssize_t
show_capability(struct sys_device
*dev
,
914 struct sysdev_attribute
*attr
, char *buf
)
916 unsigned int capability
;
919 rc
= get_cpu_capability(&capability
);
922 return sprintf(buf
, "%u\n", capability
);
924 static SYSDEV_ATTR(capability
, 0444, show_capability
, NULL
);
926 static ssize_t
show_idle_count(struct sys_device
*dev
,
927 struct sysdev_attribute
*attr
, char *buf
)
929 struct s390_idle_data
*idle
;
930 unsigned long long idle_count
;
931 unsigned int sequence
;
933 idle
= &per_cpu(s390_idle
, dev
->id
);
935 sequence
= idle
->sequence
;
939 idle_count
= idle
->idle_count
;
940 if (idle
->idle_enter
)
943 if (idle
->sequence
!= sequence
)
945 return sprintf(buf
, "%llu\n", idle_count
);
947 static SYSDEV_ATTR(idle_count
, 0444, show_idle_count
, NULL
);
949 static ssize_t
show_idle_time(struct sys_device
*dev
,
950 struct sysdev_attribute
*attr
, char *buf
)
952 struct s390_idle_data
*idle
;
953 unsigned long long now
, idle_time
, idle_enter
;
954 unsigned int sequence
;
956 idle
= &per_cpu(s390_idle
, dev
->id
);
959 sequence
= idle
->sequence
;
963 idle_time
= idle
->idle_time
;
964 idle_enter
= idle
->idle_enter
;
965 if (idle_enter
!= 0ULL && idle_enter
< now
)
966 idle_time
+= now
- idle_enter
;
968 if (idle
->sequence
!= sequence
)
970 return sprintf(buf
, "%llu\n", idle_time
>> 12);
972 static SYSDEV_ATTR(idle_time_us
, 0444, show_idle_time
, NULL
);
974 static struct attribute
*cpu_online_attrs
[] = {
975 &attr_capability
.attr
,
976 &attr_idle_count
.attr
,
977 &attr_idle_time_us
.attr
,
981 static struct attribute_group cpu_online_attr_group
= {
982 .attrs
= cpu_online_attrs
,
985 static int __cpuinit
smp_cpu_notify(struct notifier_block
*self
,
986 unsigned long action
, void *hcpu
)
988 unsigned int cpu
= (unsigned int)(long)hcpu
;
989 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
990 struct sys_device
*s
= &c
->sysdev
;
991 struct s390_idle_data
*idle
;
996 case CPU_ONLINE_FROZEN
:
997 idle
= &per_cpu(s390_idle
, cpu
);
998 memset(idle
, 0, sizeof(struct s390_idle_data
));
999 err
= sysfs_create_group(&s
->kobj
, &cpu_online_attr_group
);
1002 case CPU_DEAD_FROZEN
:
1003 sysfs_remove_group(&s
->kobj
, &cpu_online_attr_group
);
1006 return notifier_from_errno(err
);
1009 static struct notifier_block __cpuinitdata smp_cpu_nb
= {
1010 .notifier_call
= smp_cpu_notify
,
1013 static int __devinit
smp_add_present_cpu(int cpu
)
1015 struct cpu
*c
= &per_cpu(cpu_devices
, cpu
);
1016 struct sys_device
*s
= &c
->sysdev
;
1019 c
->hotpluggable
= 1;
1020 rc
= register_cpu(c
, cpu
);
1023 rc
= sysfs_create_group(&s
->kobj
, &cpu_common_attr_group
);
1026 if (!cpu_online(cpu
))
1028 rc
= sysfs_create_group(&s
->kobj
, &cpu_online_attr_group
);
1031 sysfs_remove_group(&s
->kobj
, &cpu_common_attr_group
);
1033 #ifdef CONFIG_HOTPLUG_CPU
1040 #ifdef CONFIG_HOTPLUG_CPU
1042 int __ref
smp_rescan_cpus(void)
1049 mutex_lock(&smp_cpu_state_mutex
);
1050 cpumask_copy(&newcpus
, cpu_present_mask
);
1051 rc
= __smp_rescan_cpus();
1054 cpumask_andnot(&newcpus
, cpu_present_mask
, &newcpus
);
1055 for_each_cpu(cpu
, &newcpus
) {
1056 rc
= smp_add_present_cpu(cpu
);
1058 set_cpu_present(cpu
, false);
1062 mutex_unlock(&smp_cpu_state_mutex
);
1064 if (!cpumask_empty(&newcpus
))
1065 topology_schedule_update();
1069 static ssize_t __ref
rescan_store(struct sysdev_class
*class,
1070 struct sysdev_class_attribute
*attr
,
1076 rc
= smp_rescan_cpus();
1077 return rc
? rc
: count
;
1079 static SYSDEV_CLASS_ATTR(rescan
, 0200, NULL
, rescan_store
);
1080 #endif /* CONFIG_HOTPLUG_CPU */
1082 static ssize_t
dispatching_show(struct sysdev_class
*class,
1083 struct sysdev_class_attribute
*attr
,
1088 mutex_lock(&smp_cpu_state_mutex
);
1089 count
= sprintf(buf
, "%d\n", cpu_management
);
1090 mutex_unlock(&smp_cpu_state_mutex
);
1094 static ssize_t
dispatching_store(struct sysdev_class
*dev
,
1095 struct sysdev_class_attribute
*attr
,
1102 if (sscanf(buf
, "%d %c", &val
, &delim
) != 1)
1104 if (val
!= 0 && val
!= 1)
1108 mutex_lock(&smp_cpu_state_mutex
);
1109 if (cpu_management
== val
)
1111 rc
= topology_set_cpu_management(val
);
1113 cpu_management
= val
;
1115 mutex_unlock(&smp_cpu_state_mutex
);
1117 return rc
? rc
: count
;
1119 static SYSDEV_CLASS_ATTR(dispatching
, 0644, dispatching_show
,
1122 static int __init
topology_init(void)
1127 register_cpu_notifier(&smp_cpu_nb
);
1129 #ifdef CONFIG_HOTPLUG_CPU
1130 rc
= sysdev_class_create_file(&cpu_sysdev_class
, &attr_rescan
);
1134 rc
= sysdev_class_create_file(&cpu_sysdev_class
, &attr_dispatching
);
1137 for_each_present_cpu(cpu
) {
1138 rc
= smp_add_present_cpu(cpu
);
1144 subsys_initcall(topology_init
);