xref: /linux/arch/riscv/include/asm/smp.h (revision 6e7fd890f1d6ac83805409e9c346240de2705584)
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);
53 
54 /* Check other CPUs stop or not */
55 bool smp_crash_stop_failed(void);
56 
57 /* Secondary hart entry */
58 asmlinkage void smp_callin(void);
59 
60 /*
61  * Obtains the hart ID of the currently executing task.  This relies on
62  * THREAD_INFO_IN_TASK, but we define that unconditionally.
63  */
64 #define raw_smp_processor_id() (current_thread_info()->cpu)
65 
66 #if defined CONFIG_HOTPLUG_CPU
67 int __cpu_disable(void);
68 static inline void __cpu_die(unsigned int cpu) { }
69 #endif /* CONFIG_HOTPLUG_CPU */
70 
71 #else
72 
73 static inline void show_ipi_stats(struct seq_file *p, int prec)
74 {
75 }
76 
77 static inline int riscv_hartid_to_cpuid(unsigned long hartid)
78 {
79 	if (hartid == boot_cpu_hartid)
80 		return 0;
81 
82 	return -1;
83 }
84 static inline unsigned long cpuid_to_hartid_map(int cpu)
85 {
86 	return boot_cpu_hartid;
87 }
88 
89 static inline void riscv_ipi_enable(void)
90 {
91 }
92 
93 static inline void riscv_ipi_disable(void)
94 {
95 }
96 
97 static inline bool riscv_ipi_have_virq_range(void)
98 {
99 	return false;
100 }
101 
102 static inline void riscv_ipi_set_virq_range(int virq, int nr)
103 {
104 }
105 
106 #endif /* CONFIG_SMP */
107 
108 #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
109 bool cpu_has_hotplug(unsigned int cpu);
110 #else
111 static inline bool cpu_has_hotplug(unsigned int cpu)
112 {
113 	return false;
114 }
115 #endif
116 
117 #endif /* _ASM_RISCV_SMP_H */
118