1 #ifndef _ASM_X86_KVM_PARA_H
2 #define _ASM_X86_KVM_PARA_H
4 #include <asm/processor.h>
5 #include <uapi/asm/kvm_para.h>
7 extern void kvmclock_init(void);
8 extern int kvm_register_clock(char *txt);
10 #ifdef CONFIG_KVM_GUEST
11 bool kvm_check_and_clear_guest_paused(void);
13 static inline bool kvm_check_and_clear_guest_paused(void)
17 #endif /* CONFIG_KVM_GUEST */
19 /* This instruction is vmcall. On non-VT architectures, it will generate a
20 * trap that we will then rewrite to the appropriate instruction.
22 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
24 /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
25 * instruction. The hypervisor may replace it with something else but only the
26 * instructions are guaranteed to be supported.
28 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
29 * The hypercall number should be placed in rax and the return value will be
30 * placed in rax. No other registers will be clobbered unless explicitly
31 * noted by the particular hypercall.
34 static inline long kvm_hypercall0(unsigned int nr)
37 asm volatile(KVM_HYPERCALL
44 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
47 asm volatile(KVM_HYPERCALL
54 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
58 asm volatile(KVM_HYPERCALL
60 : "a"(nr), "b"(p1), "c"(p2)
65 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
66 unsigned long p2, unsigned long p3)
69 asm volatile(KVM_HYPERCALL
71 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
76 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
77 unsigned long p2, unsigned long p3,
81 asm volatile(KVM_HYPERCALL
83 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
88 static inline uint32_t kvm_cpuid_base(void)
90 if (boot_cpu_data.cpuid_level < 0)
91 return 0; /* So we don't blow up on old processors */
93 if (cpu_has_hypervisor)
94 return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0);
99 static inline bool kvm_para_available(void)
101 return kvm_cpuid_base() != 0;
104 static inline unsigned int kvm_arch_para_features(void)
106 return cpuid_eax(KVM_CPUID_FEATURES);
109 #ifdef CONFIG_KVM_GUEST
110 void __init kvm_guest_init(void);
111 void kvm_async_pf_task_wait(u32 token);
112 void kvm_async_pf_task_wake(u32 token);
113 u32 kvm_read_and_reset_pf_reason(void);
114 extern void kvm_disable_steal_time(void);
116 #ifdef CONFIG_PARAVIRT_SPINLOCKS
117 void __init kvm_spinlock_init(void);
118 #else /* !CONFIG_PARAVIRT_SPINLOCKS */
119 static inline void kvm_spinlock_init(void)
122 #endif /* CONFIG_PARAVIRT_SPINLOCKS */
124 #else /* CONFIG_KVM_GUEST */
125 #define kvm_guest_init() do {} while (0)
126 #define kvm_async_pf_task_wait(T) do {} while(0)
127 #define kvm_async_pf_task_wake(T) do {} while(0)
129 static inline u32 kvm_read_and_reset_pf_reason(void)
134 static inline void kvm_disable_steal_time(void)
140 #endif /* _ASM_X86_KVM_PARA_H */