1 /* SPDX-License-Identifier: GPL-2.0-only */
2 #ifndef ASM__RISCV__SMP_H
3 #define ASM__RISCV__SMP_H
4 
5 #include <xen/cpumask.h>
6 #include <xen/macros.h>
7 #include <xen/percpu.h>
8 
9 #include <asm/current.h>
10 
11 DECLARE_PER_CPU(cpumask_var_t, cpu_sibling_mask);
12 DECLARE_PER_CPU(cpumask_var_t, cpu_core_mask);
13 
14 /*
15  * Mapping between Xen logical cpu index and hartid.
16  */
cpuid_to_hartid(unsigned long cpuid)17 static inline unsigned long cpuid_to_hartid(unsigned long cpuid)
18 {
19     return pcpu_info[cpuid].hart_id;
20 }
21 
hartid_to_cpuid(unsigned long hartid)22 static inline unsigned int hartid_to_cpuid(unsigned long hartid)
23 {
24     for ( unsigned int cpu = 0; cpu < ARRAY_SIZE(pcpu_info); cpu++ )
25     {
26         if ( hartid == cpuid_to_hartid(cpu) )
27             return cpu;
28     }
29 
30     /* hartid isn't valid for some reason */
31     return NR_CPUS;
32 }
33 
set_cpuid_to_hartid(unsigned long cpuid,unsigned long hartid)34 static inline void set_cpuid_to_hartid(unsigned long cpuid,
35                                        unsigned long hartid)
36 {
37     pcpu_info[cpuid].hart_id = hartid;
38 }
39 
40 void setup_tp(unsigned int cpuid);
41 
42 struct dt_device_node;
43 int dt_processor_hartid(const struct dt_device_node *node,
44                         unsigned long *hartid);
45 
46 #endif
47 
48 /*
49  * Local variables:
50  * mode: C
51  * c-file-style: "BSD"
52  * c-basic-offset: 4
53  * indent-tabs-mode: nil
54  * End:
55  */
56