xref: /openbmc/linux/arch/riscv/include/asm/smp.h (revision dd5b2498)
1 /*
2  * Copyright (C) 2012 Regents of the University of California
3  *
4  *   This program is free software; you can redistribute it and/or
5  *   modify it under the terms of the GNU General Public License
6  *   as published by the Free Software Foundation, version 2.
7  *
8  *   This program is distributed in the hope that it will be useful,
9  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  *   GNU General Public License for more details.
12  */
13 
14 #ifndef _ASM_RISCV_SMP_H
15 #define _ASM_RISCV_SMP_H
16 
17 #include <linux/cpumask.h>
18 #include <linux/irqreturn.h>
19 #include <linux/thread_info.h>
20 
21 #define INVALID_HARTID ULONG_MAX
22 
23 struct seq_file;
24 extern unsigned long boot_cpu_hartid;
25 
26 #ifdef CONFIG_SMP
27 /*
28  * Mapping between linux logical cpu index and hartid.
29  */
30 extern unsigned long __cpuid_to_hartid_map[NR_CPUS];
31 #define cpuid_to_hartid_map(cpu)    __cpuid_to_hartid_map[cpu]
32 
33 /* print IPI stats */
34 void show_ipi_stats(struct seq_file *p, int prec);
35 
36 /* SMP initialization hook for setup_arch */
37 void __init setup_smp(void);
38 
39 /* Hook for the generic smp_call_function_many() routine. */
40 void arch_send_call_function_ipi_mask(struct cpumask *mask);
41 
42 /* Hook for the generic smp_call_function_single() routine. */
43 void arch_send_call_function_single_ipi(int cpu);
44 
45 int riscv_hartid_to_cpuid(int hartid);
46 void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
47 
48 /*
49  * Obtains the hart ID of the currently executing task.  This relies on
50  * THREAD_INFO_IN_TASK, but we define that unconditionally.
51  */
52 #define raw_smp_processor_id() (current_thread_info()->cpu)
53 
54 #else
55 
56 static inline void show_ipi_stats(struct seq_file *p, int prec)
57 {
58 }
59 
60 static inline int riscv_hartid_to_cpuid(int hartid)
61 {
62 	if (hartid == boot_cpu_hartid)
63 		return 0;
64 
65 	return -1;
66 }
67 static inline unsigned long cpuid_to_hartid_map(int cpu)
68 {
69 	return boot_cpu_hartid;
70 }
71 
72 static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
73 					      struct cpumask *out)
74 {
75 	cpumask_set_cpu(cpuid_to_hartid_map(0), out);
76 }
77 
78 #endif /* CONFIG_SMP */
79 #endif /* _ASM_RISCV_SMP_H */
80