1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Copyright IBM Corp. 1999, 2012 4 * Author(s): Denis Joseph Barrow, 5 * Martin Schwidefsky <schwidefsky@de.ibm.com>, 6 */ 7 #ifndef __ASM_SMP_H 8 #define __ASM_SMP_H 9 10 #include <asm/processor.h> 11 #include <asm/lowcore.h> 12 #include <asm/machine.h> 13 #include <asm/sigp.h> 14 15 static __always_inline unsigned int raw_smp_processor_id(void) 16 { 17 unsigned long lc_cpu_nr; 18 unsigned int cpu; 19 20 BUILD_BUG_ON(sizeof_field(struct lowcore, cpu_nr) != sizeof(cpu)); 21 lc_cpu_nr = offsetof(struct lowcore, cpu_nr); 22 asm_inline( 23 ALTERNATIVE(" ly %[cpu],%[offzero](%%r0)\n", 24 " ly %[cpu],%[offalt](%%r0)\n", 25 ALT_FEATURE(MFEATURE_LOWCORE)) 26 : [cpu] "=d" (cpu) 27 : [offzero] "i" (lc_cpu_nr), 28 [offalt] "i" (lc_cpu_nr + LOWCORE_ALT_ADDRESS), 29 "m" (((struct lowcore *)0)->cpu_nr)); 30 return cpu; 31 } 32 33 #define arch_scale_cpu_capacity smp_cpu_get_capacity 34 35 extern struct mutex smp_cpu_state_mutex; 36 extern unsigned int smp_cpu_mt_shift; 37 extern unsigned int smp_cpu_mtid; 38 extern __vector128 __initdata boot_cpu_vector_save_area[__NUM_VXRS]; 39 extern cpumask_t cpu_setup_mask; 40 41 extern int __cpu_up(unsigned int cpu, struct task_struct *tidle); 42 43 extern void arch_send_call_function_single_ipi(int cpu); 44 extern void arch_send_call_function_ipi_mask(const struct cpumask *mask); 45 46 extern void smp_call_ipl_cpu(void (*func)(void *), void *); 47 extern void smp_emergency_stop(void); 48 49 extern int smp_find_processor_id(u16 address); 50 extern int smp_store_status(int cpu); 51 extern void smp_save_dump_ipl_cpu(void); 52 extern void smp_save_dump_secondary_cpus(void); 53 extern void smp_yield_cpu(int cpu); 54 extern void smp_cpu_set_polarization(int cpu, int val); 55 extern int smp_cpu_get_polarization(int cpu); 56 extern void smp_cpu_set_capacity(int cpu, unsigned long val); 57 extern void smp_set_core_capacity(int cpu, unsigned long val); 58 extern unsigned long smp_cpu_get_capacity(int cpu); 59 extern int smp_cpu_get_cpu_address(int cpu); 60 extern void smp_fill_possible_mask(void); 61 extern void smp_detect_cpus(void); 62 63 static inline void smp_stop_cpu(void) 64 { 65 u16 pcpu = stap(); 66 67 for (;;) { 68 __pcpu_sigp(pcpu, SIGP_STOP, 0, NULL); 69 cpu_relax(); 70 } 71 } 72 73 /* Return thread 0 CPU number as base CPU */ 74 static inline int smp_get_base_cpu(int cpu) 75 { 76 return cpu - (cpu % (smp_cpu_mtid + 1)); 77 } 78 79 static inline void smp_cpus_done(unsigned int max_cpus) 80 { 81 } 82 83 extern int smp_rescan_cpus(bool early); 84 extern void __noreturn cpu_die(void); 85 extern void __cpu_die(unsigned int cpu); 86 extern int __cpu_disable(void); 87 extern void schedule_mcck_handler(void); 88 void notrace smp_yield_cpu(int cpu); 89 90 #endif /* __ASM_SMP_H */ 91