1 /* SPDX-License-Identifier: GPL-2.0 */
3 * Author: Huacai Chen <chenhuacai@loongson.cn>
4 * Copyright (C) 2020-2022 Loongson Technology Corporation Limited
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>
18 void (*init_ipi
)(void);
19 void (*send_ipi_single
)(int cpu
, unsigned int action
);
20 void (*send_ipi_mask
)(const struct cpumask
*mask
, unsigned int action
);
22 extern struct smp_ops mp_ops
;
24 extern int smp_num_siblings
;
25 extern int num_processors
;
26 extern int disabled_cpus
;
27 extern cpumask_t cpu_sibling_map
[];
28 extern cpumask_t cpu_core_map
[];
29 extern cpumask_t cpu_foreign_map
[];
31 void loongson_smp_setup(void);
32 void loongson_prepare_cpus(unsigned int max_cpus
);
33 void loongson_boot_secondary(int cpu
, struct task_struct
*idle
);
34 void loongson_init_secondary(void);
35 void loongson_smp_finish(void);
36 #ifdef CONFIG_HOTPLUG_CPU
37 int loongson_cpu_disable(void);
38 void loongson_cpu_die(unsigned int cpu
);
41 static inline void plat_smp_setup(void)
46 static inline int raw_smp_processor_id(void)
49 extern int vdso_smp_processor_id(void)
50 __compiletime_error("VDSO should not call smp_processor_id()");
51 return vdso_smp_processor_id();
53 return current_thread_info()->cpu
;
56 #define raw_smp_processor_id raw_smp_processor_id
58 /* Map from cpu id to sequential logical cpu number. This will only
59 * not be idempotent when cpus failed to come on-line. */
60 extern int __cpu_number_map
[NR_CPUS
];
61 #define cpu_number_map(cpu) __cpu_number_map[cpu]
63 /* The reverse map from sequential logical cpu number to cpu id. */
64 extern int __cpu_logical_map
[NR_CPUS
];
65 #define cpu_logical_map(cpu) __cpu_logical_map[cpu]
67 #define cpu_physical_id(cpu) cpu_logical_map(cpu)
69 #define ACTION_BOOT_CPU 0
70 #define ACTION_RESCHEDULE 1
71 #define ACTION_CALL_FUNCTION 2
72 #define ACTION_IRQ_WORK 3
73 #define ACTION_CLEAR_VECTOR 4
74 #define SMP_BOOT_CPU BIT(ACTION_BOOT_CPU)
75 #define SMP_RESCHEDULE BIT(ACTION_RESCHEDULE)
76 #define SMP_CALL_FUNCTION BIT(ACTION_CALL_FUNCTION)
77 #define SMP_IRQ_WORK BIT(ACTION_IRQ_WORK)
78 #define SMP_CLEAR_VECTOR BIT(ACTION_CLEAR_VECTOR)
80 struct secondary_data
{
82 unsigned long thread_info
;
84 extern struct secondary_data cpuboot_data
;
86 extern asmlinkage
void smpboot_entry(void);
87 extern asmlinkage
void start_secondary(void);
89 extern void calculate_cpu_foreign_map(void);
92 * Generate IPI list text
94 extern void show_ipi_list(struct seq_file
*p
, int prec
);
96 static inline void arch_send_call_function_single_ipi(int cpu
)
98 mp_ops
.send_ipi_single(cpu
, ACTION_CALL_FUNCTION
);
101 static inline void arch_send_call_function_ipi_mask(const struct cpumask
*mask
)
103 mp_ops
.send_ipi_mask(mask
, ACTION_CALL_FUNCTION
);
106 #ifdef CONFIG_HOTPLUG_CPU
107 static inline int __cpu_disable(void)
109 return loongson_cpu_disable();
112 static inline void __cpu_die(unsigned int cpu
)
114 loongson_cpu_die(cpu
);
118 #else /* !CONFIG_SMP */
119 #define cpu_logical_map(cpu) 0
120 #endif /* CONFIG_SMP */
122 #endif /* __ASM_SMP_H */