Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 */
0002 #ifndef _ASM_X86_SMP_H
0003 #define _ASM_X86_SMP_H
0004 #ifndef __ASSEMBLY__
0005 #include <linux/cpumask.h>
0006 #include <asm/percpu.h>
0007 
0008 #include <asm/thread_info.h>
0009 #include <asm/cpumask.h>
0010 
0011 extern int smp_num_siblings;
0012 extern unsigned int num_processors;
0013 
0014 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
0015 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
0016 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
0017 /* cpus sharing the last level cache: */
0018 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
0019 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_l2c_shared_map);
0020 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
0021 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_l2c_id);
0022 DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
0023 
0024 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
0025 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid);
0026 DECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
0027 #if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
0028 DECLARE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid);
0029 #endif
0030 
0031 struct task_struct;
0032 
0033 struct smp_ops {
0034     void (*smp_prepare_boot_cpu)(void);
0035     void (*smp_prepare_cpus)(unsigned max_cpus);
0036     void (*smp_cpus_done)(unsigned max_cpus);
0037 
0038     void (*stop_other_cpus)(int wait);
0039     void (*crash_stop_other_cpus)(void);
0040     void (*smp_send_reschedule)(int cpu);
0041 
0042     int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
0043     int (*cpu_disable)(void);
0044     void (*cpu_die)(unsigned int cpu);
0045     void (*play_dead)(void);
0046 
0047     void (*send_call_func_ipi)(const struct cpumask *mask);
0048     void (*send_call_func_single_ipi)(int cpu);
0049 };
0050 
0051 /* Globals due to paravirt */
0052 extern void set_cpu_sibling_map(int cpu);
0053 
0054 #ifdef CONFIG_SMP
0055 extern struct smp_ops smp_ops;
0056 
0057 static inline void smp_send_stop(void)
0058 {
0059     smp_ops.stop_other_cpus(0);
0060 }
0061 
0062 static inline void stop_other_cpus(void)
0063 {
0064     smp_ops.stop_other_cpus(1);
0065 }
0066 
0067 static inline void smp_prepare_boot_cpu(void)
0068 {
0069     smp_ops.smp_prepare_boot_cpu();
0070 }
0071 
0072 static inline void smp_prepare_cpus(unsigned int max_cpus)
0073 {
0074     smp_ops.smp_prepare_cpus(max_cpus);
0075 }
0076 
0077 static inline void smp_cpus_done(unsigned int max_cpus)
0078 {
0079     smp_ops.smp_cpus_done(max_cpus);
0080 }
0081 
0082 static inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
0083 {
0084     return smp_ops.cpu_up(cpu, tidle);
0085 }
0086 
0087 static inline int __cpu_disable(void)
0088 {
0089     return smp_ops.cpu_disable();
0090 }
0091 
0092 static inline void __cpu_die(unsigned int cpu)
0093 {
0094     smp_ops.cpu_die(cpu);
0095 }
0096 
0097 static inline void play_dead(void)
0098 {
0099     smp_ops.play_dead();
0100 }
0101 
0102 static inline void smp_send_reschedule(int cpu)
0103 {
0104     smp_ops.smp_send_reschedule(cpu);
0105 }
0106 
0107 static inline void arch_send_call_function_single_ipi(int cpu)
0108 {
0109     smp_ops.send_call_func_single_ipi(cpu);
0110 }
0111 
0112 static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
0113 {
0114     smp_ops.send_call_func_ipi(mask);
0115 }
0116 
0117 void cpu_disable_common(void);
0118 void native_smp_prepare_boot_cpu(void);
0119 void smp_prepare_cpus_common(void);
0120 void native_smp_prepare_cpus(unsigned int max_cpus);
0121 void calculate_max_logical_packages(void);
0122 void native_smp_cpus_done(unsigned int max_cpus);
0123 int common_cpu_up(unsigned int cpunum, struct task_struct *tidle);
0124 int native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
0125 int native_cpu_disable(void);
0126 int common_cpu_die(unsigned int cpu);
0127 void native_cpu_die(unsigned int cpu);
0128 void hlt_play_dead(void);
0129 void native_play_dead(void);
0130 void play_dead_common(void);
0131 void wbinvd_on_cpu(int cpu);
0132 int wbinvd_on_all_cpus(void);
0133 void cond_wakeup_cpu0(void);
0134 
0135 void native_smp_send_reschedule(int cpu);
0136 void native_send_call_func_ipi(const struct cpumask *mask);
0137 void native_send_call_func_single_ipi(int cpu);
0138 void x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
0139 
0140 void smp_store_boot_cpu_info(void);
0141 void smp_store_cpu_info(int id);
0142 
0143 asmlinkage __visible void smp_reboot_interrupt(void);
0144 __visible void smp_reschedule_interrupt(struct pt_regs *regs);
0145 __visible void smp_call_function_interrupt(struct pt_regs *regs);
0146 __visible void smp_call_function_single_interrupt(struct pt_regs *r);
0147 
0148 #define cpu_physical_id(cpu)    per_cpu(x86_cpu_to_apicid, cpu)
0149 #define cpu_acpi_id(cpu)    per_cpu(x86_cpu_to_acpiid, cpu)
0150 
0151 /*
0152  * This function is needed by all SMP systems. It must _always_ be valid
0153  * from the initial startup. We map APIC_BASE very early in page_setup(),
0154  * so this is correct in the x86 case.
0155  */
0156 #define raw_smp_processor_id()  this_cpu_read(cpu_number)
0157 #define __smp_processor_id() __this_cpu_read(cpu_number)
0158 
0159 #ifdef CONFIG_X86_32
0160 extern int safe_smp_processor_id(void);
0161 #else
0162 # define safe_smp_processor_id()    smp_processor_id()
0163 #endif
0164 
0165 static inline struct cpumask *cpu_llc_shared_mask(int cpu)
0166 {
0167     return per_cpu(cpu_llc_shared_map, cpu);
0168 }
0169 
0170 static inline struct cpumask *cpu_l2c_shared_mask(int cpu)
0171 {
0172     return per_cpu(cpu_l2c_shared_map, cpu);
0173 }
0174 
0175 #else /* !CONFIG_SMP */
0176 #define wbinvd_on_cpu(cpu)     wbinvd()
0177 static inline int wbinvd_on_all_cpus(void)
0178 {
0179     wbinvd();
0180     return 0;
0181 }
0182 
0183 static inline struct cpumask *cpu_llc_shared_mask(int cpu)
0184 {
0185     return (struct cpumask *)cpumask_of(0);
0186 }
0187 #endif /* CONFIG_SMP */
0188 
0189 extern unsigned disabled_cpus;
0190 
0191 #ifdef CONFIG_X86_LOCAL_APIC
0192 extern int hard_smp_processor_id(void);
0193 
0194 #else /* CONFIG_X86_LOCAL_APIC */
0195 #define hard_smp_processor_id() 0
0196 #endif /* CONFIG_X86_LOCAL_APIC */
0197 
0198 #ifdef CONFIG_DEBUG_NMI_SELFTEST
0199 extern void nmi_selftest(void);
0200 #else
0201 #define nmi_selftest() do { } while (0)
0202 #endif
0203 
0204 #endif /* __ASSEMBLY__ */
0205 #endif /* _ASM_X86_SMP_H */