6 #define CONFIG_X86_32 1
12 #define CONFIG_X86_64 1
16 #if defined(__i386__) || defined (__x86_64__)
41 #ifndef _ASM_X86_KVM_PARA_H
42 #define _ASM_X86_KVM_PARA_H
44 /* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
45 * should be used to determine that a VM is running under KVM.
47 #define KVM_CPUID_SIGNATURE 0x40000000
49 /* This CPUID returns a feature bitmap in eax. Before enabling a particular
50 * paravirtualization, the appropriate feature bit should be checked.
52 #define KVM_CPUID_FEATURES 0x40000001
53 #define KVM_FEATURE_CLOCKSOURCE 0
54 #define KVM_FEATURE_NOP_IO_DELAY 1
55 #define KVM_FEATURE_MMU_OP 2
57 #define MSR_KVM_WALL_CLOCK 0x11
58 #define MSR_KVM_SYSTEM_TIME 0x12
60 #define KVM_MAX_MMU_OP_BATCH 32
62 /* Operations for KVM_HC_MMU_OP */
63 #define KVM_MMU_OP_WRITE_PTE 1
64 #define KVM_MMU_OP_FLUSH_TLB 2
65 #define KVM_MMU_OP_RELEASE_PT 3
67 /* Payload for KVM_HC_MMU_OP */
68 struct kvm_mmu_op_header
{
73 struct kvm_mmu_op_write_pte
{
74 struct kvm_mmu_op_header header
;
79 struct kvm_mmu_op_flush_tlb
{
80 struct kvm_mmu_op_header header
;
83 struct kvm_mmu_op_release_pt
{
84 struct kvm_mmu_op_header header
;
89 #include <asm/processor.h>
91 extern void kvmclock_init(void);
94 /* This instruction is vmcall. On non-VT architectures, it will generate a
95 * trap that we will then rewrite to the appropriate instruction.
97 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
99 /* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
100 * instruction. The hypervisor may replace it with something else but only the
101 * instructions are guaranteed to be supported.
103 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
104 * The hypercall number should be placed in rax and the return value will be
105 * placed in rax. No other registers will be clobbered unless explicited
106 * noted by the particular hypercall.
109 static inline long kvm_hypercall0(unsigned int nr
)
112 asm volatile(KVM_HYPERCALL
119 static inline long kvm_hypercall1(unsigned int nr
, unsigned long p1
)
122 asm volatile(KVM_HYPERCALL
129 static inline long kvm_hypercall2(unsigned int nr
, unsigned long p1
,
133 asm volatile(KVM_HYPERCALL
135 : "a"(nr
), "b"(p1
), "c"(p2
)
140 static inline long kvm_hypercall3(unsigned int nr
, unsigned long p1
,
141 unsigned long p2
, unsigned long p3
)
144 asm volatile(KVM_HYPERCALL
146 : "a"(nr
), "b"(p1
), "c"(p2
), "d"(p3
)
151 static inline long kvm_hypercall4(unsigned int nr
, unsigned long p1
,
152 unsigned long p2
, unsigned long p3
,
156 asm volatile(KVM_HYPERCALL
158 : "a"(nr
), "b"(p1
), "c"(p2
), "d"(p3
), "S"(p4
)
163 static inline int kvm_para_available(void)
165 unsigned int eax
, ebx
, ecx
, edx
;
168 cpuid(KVM_CPUID_SIGNATURE
, &eax
, &ebx
, &ecx
, &edx
);
169 memcpy(signature
+ 0, &ebx
, 4);
170 memcpy(signature
+ 4, &ecx
, 4);
171 memcpy(signature
+ 8, &edx
, 4);
174 if (strcmp(signature
, "KVMKVMKVM") == 0)
180 static inline unsigned int kvm_arch_para_features(void)
182 return cpuid_eax(KVM_CPUID_FEATURES
);
187 #endif /* _ASM_X86_KVM_PARA_H */