1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 3 * Author: Huacai Chen <chenhuacai@loongson.cn> 4 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited 5 */ 6 #ifndef __ASM_SMP_H 7 #define __ASM_SMP_H 8 9 #ifdef CONFIG_SMP 10 11 #include <linux/atomic.h> 12 #include <linux/bitops.h> 13 #include <linux/linkage.h> 14 #include <linux/threads.h> 15 #include <linux/cpumask.h> 16 17 extern int smp_num_siblings; 18 extern int num_processors; 19 extern int disabled_cpus; 20 extern cpumask_t cpu_sibling_map[]; 21 extern cpumask_t cpu_core_map[]; 22 extern cpumask_t cpu_foreign_map[]; 23 24 void loongson_smp_setup(void); 25 void loongson_prepare_cpus(unsigned int max_cpus); 26 void loongson_boot_secondary(int cpu, struct task_struct *idle); 27 void loongson_init_secondary(void); 28 void loongson_smp_finish(void); 29 void loongson_send_ipi_single(int cpu, unsigned int action); 30 void loongson_send_ipi_mask(const struct cpumask *mask, unsigned int action); 31 #ifdef CONFIG_HOTPLUG_CPU 32 int loongson_cpu_disable(void); 33 void loongson_cpu_die(unsigned int cpu); 34 #endif 35 36 static inline void plat_smp_setup(void) 37 { 38 loongson_smp_setup(); 39 } 40 41 static inline int raw_smp_processor_id(void) 42 { 43 #if defined(__VDSO__) 44 extern int vdso_smp_processor_id(void) 45 __compiletime_error("VDSO should not call smp_processor_id()"); 46 return vdso_smp_processor_id(); 47 #else 48 return current_thread_info()->cpu; 49 #endif 50 } 51 #define raw_smp_processor_id raw_smp_processor_id 52 53 /* Map from cpu id to sequential logical cpu number. This will only 54 * not be idempotent when cpus failed to come on-line. */ 55 extern int __cpu_number_map[NR_CPUS]; 56 #define cpu_number_map(cpu) __cpu_number_map[cpu] 57 58 /* The reverse map from sequential logical cpu number to cpu id. */ 59 extern int __cpu_logical_map[NR_CPUS]; 60 #define cpu_logical_map(cpu) __cpu_logical_map[cpu] 61 62 #define cpu_physical_id(cpu) cpu_logical_map(cpu) 63 64 #define SMP_BOOT_CPU 0x1 65 #define SMP_RESCHEDULE 0x2 66 #define SMP_CALL_FUNCTION 0x4 67 68 struct secondary_data { 69 unsigned long stack; 70 unsigned long thread_info; 71 }; 72 extern struct secondary_data cpuboot_data; 73 74 extern asmlinkage void smpboot_entry(void); 75 extern asmlinkage void start_secondary(void); 76 77 extern void calculate_cpu_foreign_map(void); 78 79 /* 80 * Generate IPI list text 81 */ 82 extern void show_ipi_list(struct seq_file *p, int prec); 83 84 static inline void arch_send_call_function_single_ipi(int cpu) 85 { 86 loongson_send_ipi_single(cpu, SMP_CALL_FUNCTION); 87 } 88 89 static inline void arch_send_call_function_ipi_mask(const struct cpumask *mask) 90 { 91 loongson_send_ipi_mask(mask, SMP_CALL_FUNCTION); 92 } 93 94 #ifdef CONFIG_HOTPLUG_CPU 95 static inline int __cpu_disable(void) 96 { 97 return loongson_cpu_disable(); 98 } 99 100 static inline void __cpu_die(unsigned int cpu) 101 { 102 loongson_cpu_die(cpu); 103 } 104 #endif 105 106 #else /* !CONFIG_SMP */ 107 #define cpu_logical_map(cpu) 0 108 #endif /* CONFIG_SMP */ 109 110 #endif /* __ASM_SMP_H */ 111