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