xref: /openbmc/linux/arch/riscv/include/asm/smp.h (revision 15e3ae36)
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 /*
3  * Copyright (C) 2012 Regents of the University of California
4  */
5 
6 #ifndef _ASM_RISCV_SMP_H
7 #define _ASM_RISCV_SMP_H
8 
9 #include <linux/cpumask.h>
10 #include <linux/irqreturn.h>
11 #include <linux/thread_info.h>
12 
13 #define INVALID_HARTID ULONG_MAX
14 
15 struct seq_file;
16 extern unsigned long boot_cpu_hartid;
17 
18 #ifdef CONFIG_SMP
19 /*
20  * Mapping between linux logical cpu index and hartid.
21  */
22 extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
23 #define cpuid_to_hartid_map(cpu)    __cpuid_to_hartid_map[cpu]
24 
25 /* print IPI stats */
26 void show_ipi_stats(struct seq_file *p, int prec);
27 
28 /* SMP initialization hook for setup_arch */
29 void __init setup_smp(void);
30 
31 /* Hook for the generic smp_call_function_many() routine. */
32 void arch_send_call_function_ipi_mask(struct cpumask *mask);
33 
34 /* Hook for the generic smp_call_function_single() routine. */
35 void arch_send_call_function_single_ipi(int cpu);
36 
37 int riscv_hartid_to_cpuid(int hartid);
38 void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
39 
40 /*
41  * Obtains the hart ID of the currently executing task.  This relies on
42  * THREAD_INFO_IN_TASK, but we define that unconditionally.
43  */
44 #define raw_smp_processor_id() (current_thread_info()->cpu)
45 
46 #if defined CONFIG_HOTPLUG_CPU
47 int __cpu_disable(void);
48 void __cpu_die(unsigned int cpu);
49 void cpu_stop(void);
50 #else
51 #endif /* CONFIG_HOTPLUG_CPU */
52 
53 #else
54 
55 static inline void show_ipi_stats(struct seq_file *p, int prec)
56 {
57 }
58 
59 static inline int riscv_hartid_to_cpuid(int hartid)
60 {
61 	if (hartid == boot_cpu_hartid)
62 		return 0;
63 
64 	return -1;
65 }
66 static inline unsigned long cpuid_to_hartid_map(int cpu)
67 {
68 	return boot_cpu_hartid;
69 }
70 
71 static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
72 					      struct cpumask *out)
73 {
74 	cpumask_clear(out);
75 	cpumask_set_cpu(boot_cpu_hartid, out);
76 }
77 
78 #endif /* CONFIG_SMP */
79 
80 #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
81 bool cpu_has_hotplug(unsigned int cpu);
82 #else
83 static inline bool cpu_has_hotplug(unsigned int cpu)
84 {
85 	return false;
86 }
87 #endif
88 
89 #endif /* _ASM_RISCV_SMP_H */
90