xref: /openbmc/linux/arch/riscv/include/asm/smp.h (revision 724ba675)
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 #include <linux/jump_label.h>
21 
22 /*
23  * Mapping between linux logical cpu index and hartid.
24  */
25 extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
26 #define cpuid_to_hartid_map(cpu)    __cpuid_to_hartid_map[cpu]
27 
28 /* print IPI stats */
29 void show_ipi_stats(struct seq_file *p, int prec);
30 
31 /* SMP initialization hook for setup_arch */
32 void __init setup_smp(void);
33 
34 /* Hook for the generic smp_call_function_many() routine. */
35 void arch_send_call_function_ipi_mask(struct cpumask *mask);
36 
37 /* Hook for the generic smp_call_function_single() routine. */
38 void arch_send_call_function_single_ipi(int cpu);
39 
40 int riscv_hartid_to_cpuid(unsigned long hartid);
41 
42 /* Enable IPI for CPU hotplug */
43 void riscv_ipi_enable(void);
44 
45 /* Disable IPI for CPU hotplug */
46 void riscv_ipi_disable(void);
47 
48 /* Check if IPI interrupt numbers are available */
49 bool riscv_ipi_have_virq_range(void);
50 
51 /* Set the IPI interrupt numbers for arch (called by irqchip drivers) */
52 void riscv_ipi_set_virq_range(int virq, int nr, bool use_for_rfence);
53 
54 /* Check if we can use IPIs for remote FENCEs */
55 DECLARE_STATIC_KEY_FALSE(riscv_ipi_for_rfence);
56 #define riscv_use_ipi_for_rfence() \
57 	static_branch_unlikely(&riscv_ipi_for_rfence)
58 
59 /* Check other CPUs stop or not */
60 bool smp_crash_stop_failed(void);
61 
62 /* Secondary hart entry */
63 asmlinkage void smp_callin(void);
64 
65 /*
66  * Obtains the hart ID of the currently executing task.  This relies on
67  * THREAD_INFO_IN_TASK, but we define that unconditionally.
68  */
69 #define raw_smp_processor_id() (current_thread_info()->cpu)
70 
71 #if defined CONFIG_HOTPLUG_CPU
72 int __cpu_disable(void);
73 void __cpu_die(unsigned int cpu);
74 #endif /* CONFIG_HOTPLUG_CPU */
75 
76 #else
77 
78 static inline void show_ipi_stats(struct seq_file *p, int prec)
79 {
80 }
81 
82 static inline int riscv_hartid_to_cpuid(unsigned long hartid)
83 {
84 	if (hartid == boot_cpu_hartid)
85 		return 0;
86 
87 	return -1;
88 }
89 static inline unsigned long cpuid_to_hartid_map(int cpu)
90 {
91 	return boot_cpu_hartid;
92 }
93 
94 static inline void riscv_ipi_enable(void)
95 {
96 }
97 
98 static inline void riscv_ipi_disable(void)
99 {
100 }
101 
102 static inline bool riscv_ipi_have_virq_range(void)
103 {
104 	return false;
105 }
106 
107 static inline void riscv_ipi_set_virq_range(int virq, int nr,
108 					    bool use_for_rfence)
109 {
110 }
111 
112 static inline bool riscv_use_ipi_for_rfence(void)
113 {
114 	return false;
115 }
116 
117 #endif /* CONFIG_SMP */
118 
119 #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
120 bool cpu_has_hotplug(unsigned int cpu);
121 #else
122 static inline bool cpu_has_hotplug(unsigned int cpu)
123 {
124 	return false;
125 }
126 #endif
127 
128 #endif /* _ASM_RISCV_SMP_H */
129