18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */
28c2ecf20Sopenharmony_ci#ifndef _ASM_X86_SMP_H
38c2ecf20Sopenharmony_ci#define _ASM_X86_SMP_H
48c2ecf20Sopenharmony_ci#ifndef __ASSEMBLY__
58c2ecf20Sopenharmony_ci#include <linux/cpumask.h>
68c2ecf20Sopenharmony_ci#include <asm/percpu.h>
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_ci#include <asm/thread_info.h>
98c2ecf20Sopenharmony_ci#include <asm/cpumask.h>
108c2ecf20Sopenharmony_ci
118c2ecf20Sopenharmony_ciextern int smp_num_siblings;
128c2ecf20Sopenharmony_ciextern unsigned int num_processors;
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_sibling_map);
158c2ecf20Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
168c2ecf20Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_die_map);
178c2ecf20Sopenharmony_ci/* cpus sharing the last level cache: */
188c2ecf20Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
198c2ecf20Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
208c2ecf20Sopenharmony_ciDECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_cistatic inline struct cpumask *cpu_llc_shared_mask(int cpu)
238c2ecf20Sopenharmony_ci{
248c2ecf20Sopenharmony_ci	return per_cpu(cpu_llc_shared_map, cpu);
258c2ecf20Sopenharmony_ci}
268c2ecf20Sopenharmony_ci
278c2ecf20Sopenharmony_ciDECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_cpu_to_apicid);
288c2ecf20Sopenharmony_ciDECLARE_EARLY_PER_CPU_READ_MOSTLY(u32, x86_cpu_to_acpiid);
298c2ecf20Sopenharmony_ciDECLARE_EARLY_PER_CPU_READ_MOSTLY(u16, x86_bios_cpu_apicid);
308c2ecf20Sopenharmony_ci#if defined(CONFIG_X86_LOCAL_APIC) && defined(CONFIG_X86_32)
318c2ecf20Sopenharmony_ciDECLARE_EARLY_PER_CPU_READ_MOSTLY(int, x86_cpu_to_logical_apicid);
328c2ecf20Sopenharmony_ci#endif
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_cistruct task_struct;
358c2ecf20Sopenharmony_ci
368c2ecf20Sopenharmony_cistruct smp_ops {
378c2ecf20Sopenharmony_ci	void (*smp_prepare_boot_cpu)(void);
388c2ecf20Sopenharmony_ci	void (*smp_prepare_cpus)(unsigned max_cpus);
398c2ecf20Sopenharmony_ci	void (*smp_cpus_done)(unsigned max_cpus);
408c2ecf20Sopenharmony_ci
418c2ecf20Sopenharmony_ci	void (*stop_other_cpus)(int wait);
428c2ecf20Sopenharmony_ci	void (*crash_stop_other_cpus)(void);
438c2ecf20Sopenharmony_ci	void (*smp_send_reschedule)(int cpu);
448c2ecf20Sopenharmony_ci
458c2ecf20Sopenharmony_ci	int (*cpu_up)(unsigned cpu, struct task_struct *tidle);
468c2ecf20Sopenharmony_ci	int (*cpu_disable)(void);
478c2ecf20Sopenharmony_ci	void (*cpu_die)(unsigned int cpu);
488c2ecf20Sopenharmony_ci	void (*play_dead)(void);
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci	void (*send_call_func_ipi)(const struct cpumask *mask);
518c2ecf20Sopenharmony_ci	void (*send_call_func_single_ipi)(int cpu);
528c2ecf20Sopenharmony_ci};
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci/* Globals due to paravirt */
558c2ecf20Sopenharmony_ciextern void set_cpu_sibling_map(int cpu);
568c2ecf20Sopenharmony_ci
578c2ecf20Sopenharmony_ci#ifdef CONFIG_SMP
588c2ecf20Sopenharmony_ciextern struct smp_ops smp_ops;
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_cistatic inline void smp_send_stop(void)
618c2ecf20Sopenharmony_ci{
628c2ecf20Sopenharmony_ci	smp_ops.stop_other_cpus(0);
638c2ecf20Sopenharmony_ci}
648c2ecf20Sopenharmony_ci
658c2ecf20Sopenharmony_cistatic inline void stop_other_cpus(void)
668c2ecf20Sopenharmony_ci{
678c2ecf20Sopenharmony_ci	smp_ops.stop_other_cpus(1);
688c2ecf20Sopenharmony_ci}
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_cistatic inline void smp_prepare_boot_cpu(void)
718c2ecf20Sopenharmony_ci{
728c2ecf20Sopenharmony_ci	smp_ops.smp_prepare_boot_cpu();
738c2ecf20Sopenharmony_ci}
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_cistatic inline void smp_prepare_cpus(unsigned int max_cpus)
768c2ecf20Sopenharmony_ci{
778c2ecf20Sopenharmony_ci	smp_ops.smp_prepare_cpus(max_cpus);
788c2ecf20Sopenharmony_ci}
798c2ecf20Sopenharmony_ci
808c2ecf20Sopenharmony_cistatic inline void smp_cpus_done(unsigned int max_cpus)
818c2ecf20Sopenharmony_ci{
828c2ecf20Sopenharmony_ci	smp_ops.smp_cpus_done(max_cpus);
838c2ecf20Sopenharmony_ci}
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_cistatic inline int __cpu_up(unsigned int cpu, struct task_struct *tidle)
868c2ecf20Sopenharmony_ci{
878c2ecf20Sopenharmony_ci	return smp_ops.cpu_up(cpu, tidle);
888c2ecf20Sopenharmony_ci}
898c2ecf20Sopenharmony_ci
908c2ecf20Sopenharmony_cistatic inline int __cpu_disable(void)
918c2ecf20Sopenharmony_ci{
928c2ecf20Sopenharmony_ci	return smp_ops.cpu_disable();
938c2ecf20Sopenharmony_ci}
948c2ecf20Sopenharmony_ci
958c2ecf20Sopenharmony_cistatic inline void __cpu_die(unsigned int cpu)
968c2ecf20Sopenharmony_ci{
978c2ecf20Sopenharmony_ci	smp_ops.cpu_die(cpu);
988c2ecf20Sopenharmony_ci}
998c2ecf20Sopenharmony_ci
1008c2ecf20Sopenharmony_cistatic inline void play_dead(void)
1018c2ecf20Sopenharmony_ci{
1028c2ecf20Sopenharmony_ci	smp_ops.play_dead();
1038c2ecf20Sopenharmony_ci}
1048c2ecf20Sopenharmony_ci
1058c2ecf20Sopenharmony_cistatic inline void smp_send_reschedule(int cpu)
1068c2ecf20Sopenharmony_ci{
1078c2ecf20Sopenharmony_ci	smp_ops.smp_send_reschedule(cpu);
1088c2ecf20Sopenharmony_ci}
1098c2ecf20Sopenharmony_ci
1108c2ecf20Sopenharmony_cistatic inline void arch_send_call_function_single_ipi(int cpu)
1118c2ecf20Sopenharmony_ci{
1128c2ecf20Sopenharmony_ci	smp_ops.send_call_func_single_ipi(cpu);
1138c2ecf20Sopenharmony_ci}
1148c2ecf20Sopenharmony_ci
1158c2ecf20Sopenharmony_cistatic inline void arch_send_call_function_ipi_mask(const struct cpumask *mask)
1168c2ecf20Sopenharmony_ci{
1178c2ecf20Sopenharmony_ci	smp_ops.send_call_func_ipi(mask);
1188c2ecf20Sopenharmony_ci}
1198c2ecf20Sopenharmony_ci
1208c2ecf20Sopenharmony_civoid cpu_disable_common(void);
1218c2ecf20Sopenharmony_civoid native_smp_prepare_boot_cpu(void);
1228c2ecf20Sopenharmony_civoid native_smp_prepare_cpus(unsigned int max_cpus);
1238c2ecf20Sopenharmony_civoid calculate_max_logical_packages(void);
1248c2ecf20Sopenharmony_civoid native_smp_cpus_done(unsigned int max_cpus);
1258c2ecf20Sopenharmony_ciint common_cpu_up(unsigned int cpunum, struct task_struct *tidle);
1268c2ecf20Sopenharmony_ciint native_cpu_up(unsigned int cpunum, struct task_struct *tidle);
1278c2ecf20Sopenharmony_ciint native_cpu_disable(void);
1288c2ecf20Sopenharmony_ciint common_cpu_die(unsigned int cpu);
1298c2ecf20Sopenharmony_civoid native_cpu_die(unsigned int cpu);
1308c2ecf20Sopenharmony_civoid hlt_play_dead(void);
1318c2ecf20Sopenharmony_civoid native_play_dead(void);
1328c2ecf20Sopenharmony_civoid play_dead_common(void);
1338c2ecf20Sopenharmony_civoid wbinvd_on_cpu(int cpu);
1348c2ecf20Sopenharmony_ciint wbinvd_on_all_cpus(void);
1358c2ecf20Sopenharmony_civoid cond_wakeup_cpu0(void);
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_civoid native_smp_send_reschedule(int cpu);
1388c2ecf20Sopenharmony_civoid native_send_call_func_ipi(const struct cpumask *mask);
1398c2ecf20Sopenharmony_civoid native_send_call_func_single_ipi(int cpu);
1408c2ecf20Sopenharmony_civoid x86_idle_thread_init(unsigned int cpu, struct task_struct *idle);
1418c2ecf20Sopenharmony_ci
1428c2ecf20Sopenharmony_civoid smp_store_boot_cpu_info(void);
1438c2ecf20Sopenharmony_civoid smp_store_cpu_info(int id);
1448c2ecf20Sopenharmony_ci
1458c2ecf20Sopenharmony_ciasmlinkage __visible void smp_reboot_interrupt(void);
1468c2ecf20Sopenharmony_ci__visible void smp_reschedule_interrupt(struct pt_regs *regs);
1478c2ecf20Sopenharmony_ci__visible void smp_call_function_interrupt(struct pt_regs *regs);
1488c2ecf20Sopenharmony_ci__visible void smp_call_function_single_interrupt(struct pt_regs *r);
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#define cpu_physical_id(cpu)	per_cpu(x86_cpu_to_apicid, cpu)
1518c2ecf20Sopenharmony_ci#define cpu_acpi_id(cpu)	per_cpu(x86_cpu_to_acpiid, cpu)
1528c2ecf20Sopenharmony_ci
1538c2ecf20Sopenharmony_ci/*
1548c2ecf20Sopenharmony_ci * This function is needed by all SMP systems. It must _always_ be valid
1558c2ecf20Sopenharmony_ci * from the initial startup. We map APIC_BASE very early in page_setup(),
1568c2ecf20Sopenharmony_ci * so this is correct in the x86 case.
1578c2ecf20Sopenharmony_ci */
1588c2ecf20Sopenharmony_ci#define raw_smp_processor_id()  this_cpu_read(cpu_number)
1598c2ecf20Sopenharmony_ci#define __smp_processor_id() __this_cpu_read(cpu_number)
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_32
1628c2ecf20Sopenharmony_ciextern int safe_smp_processor_id(void);
1638c2ecf20Sopenharmony_ci#else
1648c2ecf20Sopenharmony_ci# define safe_smp_processor_id()	smp_processor_id()
1658c2ecf20Sopenharmony_ci#endif
1668c2ecf20Sopenharmony_ci
1678c2ecf20Sopenharmony_ci#else /* !CONFIG_SMP */
1688c2ecf20Sopenharmony_ci#define wbinvd_on_cpu(cpu)     wbinvd()
1698c2ecf20Sopenharmony_cistatic inline int wbinvd_on_all_cpus(void)
1708c2ecf20Sopenharmony_ci{
1718c2ecf20Sopenharmony_ci	wbinvd();
1728c2ecf20Sopenharmony_ci	return 0;
1738c2ecf20Sopenharmony_ci}
1748c2ecf20Sopenharmony_ci#endif /* CONFIG_SMP */
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ciextern unsigned disabled_cpus;
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ci#ifdef CONFIG_X86_LOCAL_APIC
1798c2ecf20Sopenharmony_ciextern int hard_smp_processor_id(void);
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci#else /* CONFIG_X86_LOCAL_APIC */
1828c2ecf20Sopenharmony_ci#define hard_smp_processor_id()	0
1838c2ecf20Sopenharmony_ci#endif /* CONFIG_X86_LOCAL_APIC */
1848c2ecf20Sopenharmony_ci
1858c2ecf20Sopenharmony_ci#ifdef CONFIG_DEBUG_NMI_SELFTEST
1868c2ecf20Sopenharmony_ciextern void nmi_selftest(void);
1878c2ecf20Sopenharmony_ci#else
1888c2ecf20Sopenharmony_ci#define nmi_selftest() do { } while (0)
1898c2ecf20Sopenharmony_ci#endif
1908c2ecf20Sopenharmony_ci
1918c2ecf20Sopenharmony_ci#endif /* __ASSEMBLY__ */
1928c2ecf20Sopenharmony_ci#endif /* _ASM_X86_SMP_H */
193