xref: /openbmc/linux/arch/riscv/include/asm/smp.h (revision 58f9d806)
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  * 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 struct seq_file;
29 
30 #ifdef CONFIG_SMP
31 
32 /* print IPI stats */
33 void show_ipi_stats(struct seq_file *p, int prec);
34 
35 /* SMP initialization hook for setup_arch */
36 void __init setup_smp(void);
37 
38 /* Hook for the generic smp_call_function_many() routine. */
39 void arch_send_call_function_ipi_mask(struct cpumask *mask);
40 
41 /* Hook for the generic smp_call_function_single() routine. */
42 void arch_send_call_function_single_ipi(int cpu);
43 
44 int riscv_hartid_to_cpuid(int hartid);
45 void riscv_cpuid_to_hartid_mask(const struct cpumask *in, struct cpumask *out);
46 
47 /*
48  * Obtains the hart ID of the currently executing task.  This relies on
49  * THREAD_INFO_IN_TASK, but we define that unconditionally.
50  */
51 #define raw_smp_processor_id() (current_thread_info()->cpu)
52 
53 #else
54 
55 static inline void show_ipi_stats(struct seq_file *p, int prec)
56 {
57 }
58 
59 static inline int riscv_hartid_to_cpuid(int hartid)
60 {
61 	return 0;
62 }
63 
64 static inline void riscv_cpuid_to_hartid_mask(const struct cpumask *in,
65 					      struct cpumask *out)
66 {
67 	cpumask_set_cpu(cpuid_to_hartid_map(0), out);
68 }
69 
70 #endif /* CONFIG_SMP */
71 #endif /* _ASM_RISCV_SMP_H */
72