1 #ifndef __X86_KVM_PARA_H
2 #define __X86_KVM_PARA_H
4 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
5 * should be used to determine that a VM is running under KVM.
7 #define KVM_CPUID_SIGNATURE 0x40000000
9 /* This CPUID returns a feature bitmap in eax. Before enabling a particular
10 * paravirtualization, the appropriate feature bit should be checked.
12 #define KVM_CPUID_FEATURES 0x40000001
13 #define KVM_FEATURE_CLOCKSOURCE 0
14 #define KVM_FEATURE_NOP_IO_DELAY 1
15 #define KVM_FEATURE_MMU_OP 2
17 #define MSR_KVM_WALL_CLOCK 0x11
18 #define MSR_KVM_SYSTEM_TIME 0x12
20 #define KVM_MAX_MMU_OP_BATCH 32
22 /* Operations for KVM_HC_MMU_OP */
23 #define KVM_MMU_OP_WRITE_PTE 1
24 #define KVM_MMU_OP_FLUSH_TLB 2
25 #define KVM_MMU_OP_RELEASE_PT 3
27 /* Payload for KVM_HC_MMU_OP */
28 struct kvm_mmu_op_header {
33 struct kvm_mmu_op_write_pte {
34 struct kvm_mmu_op_header header;
39 struct kvm_mmu_op_flush_tlb {
40 struct kvm_mmu_op_header header;
43 struct kvm_mmu_op_release_pt {
44 struct kvm_mmu_op_header header;
49 #include <asm/processor.h>
51 /* xen binary-compatible interface. See xen headers for details */
52 struct kvm_vcpu_time_info {
55 uint64_t tsc_timestamp;
57 uint32_t tsc_to_system_mul;
60 } __attribute__((__packed__)); /* 32 bytes */
62 struct kvm_wall_clock {
66 } __attribute__((__packed__));
69 extern void kvmclock_init(void);
72 /* This instruction is vmcall. On non-VT architectures, it will generate a
73 * trap that we will then rewrite to the appropriate instruction.
75 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
77 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
78 * instruction. The hypervisor may replace it with something else but only the
79 * instructions are guaranteed to be supported.
81 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
82 * The hypercall number should be placed in rax and the return value will be
83 * placed in rax. No other registers will be clobbered unless explicited
84 * noted by the particular hypercall.
87 static inline long kvm_hypercall0(unsigned int nr)
90 asm volatile(KVM_HYPERCALL
96 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
99 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));
115 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
116 unsigned long p2, unsigned long p3)
119 asm volatile(KVM_HYPERCALL
121 : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
125 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
126 unsigned long p2, unsigned long p3,
130 asm volatile(KVM_HYPERCALL
132 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
136 static inline int kvm_para_available(void)
138 unsigned int eax, ebx, ecx, edx;
141 cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
142 memcpy(signature + 0, &ebx, 4);
143 memcpy(signature + 4, &ecx, 4);
144 memcpy(signature + 8, &edx, 4);
147 if (strcmp(signature, "KVMKVMKVM") == 0)
153 static inline unsigned int kvm_arch_para_features(void)
155 return cpuid_eax(KVM_CPUID_FEATURES);