1 #ifndef _ASM_X86_KVM_PARA_H
2 #define _ASM_X86_KVM_PARA_H
4 #include <linux/types.h>
5 #include <asm/hyperv.h>
7 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
8 * should be used to determine that a VM is running under KVM.
10 #define KVM_CPUID_SIGNATURE 0x40000000
12 /* This CPUID returns a feature bitmap in eax. Before enabling a particular
13 * paravirtualization, the appropriate feature bit should be checked.
15 #define KVM_CPUID_FEATURES 0x40000001
16 #define KVM_FEATURE_CLOCKSOURCE 0
17 #define KVM_FEATURE_NOP_IO_DELAY 1
18 #define KVM_FEATURE_MMU_OP 2
19 /* This indicates that the new set of kvmclock msrs
20 * are available. The use of 0x11 and 0x12 is deprecated
22 #define KVM_FEATURE_CLOCKSOURCE2 3
24 /* The last 8 bits are used to indicate how to interpret the flags field
25 * in pvclock structure. If no bits are set, all flags are ignored.
27 #define KVM_FEATURE_CLOCKSOURCE_STABLE_BIT 24
29 #define MSR_KVM_WALL_CLOCK 0x11
30 #define MSR_KVM_SYSTEM_TIME 0x12
32 /* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */
33 #define MSR_KVM_WALL_CLOCK_NEW 0x4b564d00
34 #define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
36 #define KVM_MAX_MMU_OP_BATCH 32
38 /* Operations for KVM_HC_MMU_OP */
39 #define KVM_MMU_OP_WRITE_PTE 1
40 #define KVM_MMU_OP_FLUSH_TLB 2
41 #define KVM_MMU_OP_RELEASE_PT 3
43 /* Payload for KVM_HC_MMU_OP */
44 struct kvm_mmu_op_header
{
49 struct kvm_mmu_op_write_pte
{
50 struct kvm_mmu_op_header header
;
55 struct kvm_mmu_op_flush_tlb
{
56 struct kvm_mmu_op_header header
;
59 struct kvm_mmu_op_release_pt
{
60 struct kvm_mmu_op_header header
;
65 #include <asm/processor.h>
67 extern void kvmclock_init(void);
70 /* This instruction is vmcall. On non-VT architectures, it will generate a
71 * trap that we will then rewrite to the appropriate instruction.
73 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
75 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
76 * instruction. The hypervisor may replace it with something else but only the
77 * instructions are guaranteed to be supported.
79 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
80 * The hypercall number should be placed in rax and the return value will be
81 * placed in rax. No other registers will be clobbered unless explicited
82 * noted by the particular hypercall.
85 static inline long kvm_hypercall0(unsigned int nr
)
88 asm volatile(KVM_HYPERCALL
95 static inline long kvm_hypercall1(unsigned int nr
, unsigned long p1
)
98 asm volatile(KVM_HYPERCALL
105 static inline long kvm_hypercall2(unsigned int nr
, unsigned long p1
,
109 asm volatile(KVM_HYPERCALL
111 : "a"(nr
), "b"(p1
), "c"(p2
)
116 static inline long kvm_hypercall3(unsigned int nr
, unsigned long p1
,
117 unsigned long p2
, unsigned long p3
)
120 asm volatile(KVM_HYPERCALL
122 : "a"(nr
), "b"(p1
), "c"(p2
), "d"(p3
)
127 static inline long kvm_hypercall4(unsigned int nr
, unsigned long p1
,
128 unsigned long p2
, unsigned long p3
,
132 asm volatile(KVM_HYPERCALL
134 : "a"(nr
), "b"(p1
), "c"(p2
), "d"(p3
), "S"(p4
)
139 static inline int kvm_para_available(void)
141 unsigned int eax
, ebx
, ecx
, edx
;
144 cpuid(KVM_CPUID_SIGNATURE
, &eax
, &ebx
, &ecx
, &edx
);
145 memcpy(signature
+ 0, &ebx
, 4);
146 memcpy(signature
+ 4, &ecx
, 4);
147 memcpy(signature
+ 8, &edx
, 4);
150 if (strcmp(signature
, "KVMKVMKVM") == 0)
156 static inline unsigned int kvm_arch_para_features(void)
158 return cpuid_eax(KVM_CPUID_FEATURES
);
161 #ifdef CONFIG_KVM_GUEST
162 void __init
kvm_guest_init(void);
164 #define kvm_guest_init() do { } while (0)
167 #endif /* __KERNEL__ */
169 #endif /* _ASM_X86_KVM_PARA_H */