xref: /openbmc/linux/arch/riscv/include/asm/smp.h (revision 26cfd12b)
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 /* Called from C code, this handles an IPI. */
32 void handle_IPI(struct pt_regs *regs);
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(int hartid);
41 void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
42 
43 /*
44  * Obtains the hart ID of the currently executing task.  This relies on
45  * THREAD_INFO_IN_TASK, but we define that unconditionally.
46  */
47 #define raw_smp_processor_id() (current_thread_info()->cpu)
48 
49 #if defined CONFIG_HOTPLUG_CPU
50 int __cpu_disable(void);
51 void __cpu_die(unsigned int cpu);
52 void cpu_stop(void);
53 #else
54 #endif /* CONFIG_HOTPLUG_CPU */
55 
56 #else
57 
58 static inline void show_ipi_stats(struct seq_file *p, int prec)
59 {
60 }
61 
62 static inline int riscv_hartid_to_cpuid(int hartid)
63 {
64 	if (hartid == boot_cpu_hartid)
65 		return 0;
66 
67 	return -1;
68 }
69 static inline unsigned long cpuid_to_hartid_map(int cpu)
70 {
71 	return boot_cpu_hartid;
72 }
73 
74 static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
75 					      struct cpumask *out)
76 {
77 	cpumask_clear(out);
78 	cpumask_set_cpu(boot_cpu_hartid, out);
79 }
80 
81 #endif /* CONFIG_SMP */
82 
83 #if defined(CONFIG_HOTPLUG_CPU) && (CONFIG_SMP)
84 bool cpu_has_hotplug(unsigned int cpu);
85 #else
86 static inline bool cpu_has_hotplug(unsigned int cpu)
87 {
88 	return false;
89 }
90 #endif
91 
92 #endif /* _ASM_RISCV_SMP_H */
93