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
15 #define MSR_KVM_WALL_CLOCK 0x11
16 #define MSR_KVM_SYSTEM_TIME 0x12
19 #include <asm/processor.h>
21 /* xen binary-compatible interface. See xen headers for details */
22 struct kvm_vcpu_time_info {
25 uint64_t tsc_timestamp;
27 uint32_t tsc_to_system_mul;
30 } __attribute__((__packed__)); /* 32 bytes */
32 struct kvm_wall_clock {
36 } __attribute__((__packed__));
39 extern void kvmclock_init(void);
42 /* This instruction is vmcall. On non-VT architectures, it will generate a
43 * trap that we will then rewrite to the appropriate instruction.
45 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
47 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
48 * instruction. The hypervisor may replace it with something else but only the
49 * instructions are guaranteed to be supported.
51 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
52 * The hypercall number should be placed in rax and the return value will be
53 * placed in rax. No other registers will be clobbered unless explicited
54 * noted by the particular hypercall.
57 static inline long kvm_hypercall0(unsigned int nr)
60 asm volatile(KVM_HYPERCALL
66 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
69 asm volatile(KVM_HYPERCALL
75 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
79 asm volatile(KVM_HYPERCALL
81 : "a"(nr), "b"(p1), "c"(p2));
85 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
86 unsigned long p2, unsigned long p3)
89 asm volatile(KVM_HYPERCALL
91 : "a"(nr), "b"(p1), "c"(p2), "d"(p3));
95 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
96 unsigned long p2, unsigned long p3,
100 asm volatile(KVM_HYPERCALL
102 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4));
106 static inline int kvm_para_available(void)
108 unsigned int eax, ebx, ecx, edx;
111 cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
112 memcpy(signature + 0, &ebx, 4);
113 memcpy(signature + 4, &ecx, 4);
114 memcpy(signature + 8, &edx, 4);
117 if (strcmp(signature, "KVMKVMKVM") == 0)
123 static inline unsigned int kvm_arch_para_features(void)
125 return cpuid_eax(KVM_CPUID_FEATURES);