1 /* SPDX-License-Identifier: GPL-2.0-only */ 2 3 #ifndef ASM__RISCV__CURRENT_H 4 #define ASM__RISCV__CURRENT_H 5 6 #include <xen/bug.h> 7 #include <xen/cache.h> 8 #include <xen/percpu.h> 9 10 #include <asm/processor.h> 11 12 #ifndef __ASSEMBLY__ 13 14 register struct pcpu_info *tp asm ( "tp" ); 15 16 struct pcpu_info { 17 unsigned int processor_id; /* Xen CPU id */ 18 unsigned long hart_id; /* physical CPU id */ 19 } __cacheline_aligned; 20 21 /* tp points to one of these */ 22 extern struct pcpu_info pcpu_info[NR_CPUS]; 23 24 #define set_processor_id(id) do { \ 25 tp->processor_id = (id); \ 26 } while (0) 27 smp_processor_id(void)28static inline unsigned int smp_processor_id(void) 29 { 30 unsigned int id = tp->processor_id; 31 32 BUG_ON(id >= NR_CPUS); 33 34 return id; 35 } 36 37 /* Which VCPU is "current" on this PCPU. */ 38 DECLARE_PER_CPU(struct vcpu *, curr_vcpu); 39 40 #define current this_cpu(curr_vcpu) 41 #define set_current(vcpu) do { current = (vcpu); } while (0) 42 #define get_cpu_current(cpu) per_cpu(curr_vcpu, cpu) 43 44 #define guest_cpu_user_regs() ({ BUG_ON("unimplemented"); NULL; }) 45 46 #define switch_stack_and_jump(stack, fn) do { \ 47 asm volatile ( \ 48 "mv sp, %0\n" \ 49 "j " #fn :: "r" (stack), "X" (fn) : "memory" ); \ 50 unreachable(); \ 51 } while ( false ) 52 53 #define get_per_cpu_offset() __per_cpu_offset[smp_processor_id()] 54 55 #endif /* __ASSEMBLY__ */ 56 57 #endif /* ASM__RISCV__CURRENT_H */ 58