1 #ifndef __LINUX_KVM_PARA_H
2 #define __LINUX_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
14 /* Return values for hypercalls */
15 #define KVM_ENOSYS 1000
18 #include <asm/processor.h>
20 /* This instruction is vmcall. On non-VT architectures, it will generate a
21 * trap that we will then rewrite to the appropriate instruction.
23 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
25 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
26 * instruction. The hypervisor may replace it with something else but only the
27 * instructions are guaranteed to be supported.
29 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
30 * The hypercall number should be placed in rax and the return value will be
31 * placed in rax. No other registers will be clobbered unless explicited
32 * noted by the particular hypercall.
35 static inline long kvm_hypercall0(unsigned int nr)
38 asm volatile(KVM_HYPERCALL
44 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
47 asm volatile(KVM_HYPERCALL
53 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
57 asm volatile(KVM_HYPERCALL
59 : "a"(nr), "b"(p1), "c"(p2));
63 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
64 unsigned long p2, unsigned long p3)
67 asm volatile(KVM_HYPERCALL
69 : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
73 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
74 unsigned long p2, unsigned long p3,
78 asm volatile(KVM_HYPERCALL
80 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
84 static inline int kvm_para_available(void)
86 unsigned int eax, ebx, ecx, edx;
89 cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
90 memcpy(signature + 0, &ebx, 4);
91 memcpy(signature + 4, &ecx, 4);
92 memcpy(signature + 8, &edx, 4);
95 if (strcmp(signature, "KVMKVMKVM") == 0)
101 static inline int kvm_para_has_feature(unsigned int feature)
103 if (cpuid_eax(KVM_CPUID_FEATURES) & (1UL << feature))