1 #ifndef __ARM_CURRENT_H__ 2 #define __ARM_CURRENT_H__ 3 4 #include <xen/percpu.h> 5 6 #include <asm/processor.h> 7 8 /* Tell whether the guest vCPU enabled Workaround 2 (i.e variant 4) */ 9 #define CPUINFO_WORKAROUND_2_FLAG_SHIFT 0 10 #define CPUINFO_WORKAROUND_2_FLAG (_AC(1, U) << CPUINFO_WORKAROUND_2_FLAG_SHIFT) 11 12 #ifndef __ASSEMBLY__ 13 14 struct vcpu; 15 16 /* Which VCPU is "current" on this PCPU. */ 17 DECLARE_PER_CPU(struct vcpu *, curr_vcpu); 18 19 #define current (this_cpu(curr_vcpu)) 20 #define set_current(vcpu) do { current = (vcpu); } while (0) 21 #define get_cpu_current(cpu) (per_cpu(curr_vcpu, cpu)) 22 23 /* Per-VCPU state that lives at the top of the stack */ 24 struct cpu_info { 25 struct cpu_user_regs guest_cpu_user_regs; 26 unsigned long elr; 27 uint32_t flags; 28 }; 29 get_cpu_info(void)30static inline struct cpu_info *get_cpu_info(void) 31 { 32 #ifdef __clang__ 33 unsigned long sp; 34 35 asm ("mov %0, sp" : "=r" (sp)); 36 #else 37 register unsigned long sp asm ("sp"); 38 #endif 39 40 return (struct cpu_info *)((sp & ~(STACK_SIZE - 1)) + 41 STACK_SIZE - sizeof(struct cpu_info)); 42 } 43 44 #define guest_cpu_user_regs() (&get_cpu_info()->guest_cpu_user_regs) 45 46 #define switch_stack_and_jump(stack, fn) \ 47 asm volatile ("mov sp,%0; b " STR(fn) : : "r" (stack) : "memory" ) 48 49 #define reset_stack_and_jump(fn) switch_stack_and_jump(get_cpu_info(), fn) 50 51 DECLARE_PER_CPU(unsigned int, cpu_id); 52 53 #define get_processor_id() this_cpu(cpu_id) 54 #define set_processor_id(id) \ 55 do { \ 56 WRITE_SYSREG(__per_cpu_offset[(id)], TPIDR_EL2); \ 57 this_cpu(cpu_id) = (id); \ 58 } while ( 0 ) 59 60 #endif 61 62 #endif /* __ARM_CURRENT_H__ */ 63 /* 64 * Local variables: 65 * mode: C 66 * c-file-style: "BSD" 67 * c-basic-offset: 4 68 * indent-tabs-mode: nil 69 * End: 70 */ 71