2008-10-23 05:26:29 +00:00
|
|
|
#ifndef _ASM_X86_KVM_PARA_H
|
|
|
|
#define _ASM_X86_KVM_PARA_H
|
2007-10-11 13:34:17 +00:00
|
|
|
|
2009-08-16 12:31:33 +00:00
|
|
|
#include <linux/types.h>
|
2010-01-17 13:51:22 +00:00
|
|
|
#include <asm/hyperv.h>
|
2009-08-16 12:31:33 +00:00
|
|
|
|
2007-10-11 13:34:17 +00:00
|
|
|
/* This CPUID returns the signature 'KVMKVMKVM' in ebx, ecx, and edx. It
|
|
|
|
* should be used to determine that a VM is running under KVM.
|
|
|
|
*/
|
|
|
|
#define KVM_CPUID_SIGNATURE 0x40000000
|
|
|
|
|
|
|
|
/* This CPUID returns a feature bitmap in eax. Before enabling a particular
|
|
|
|
* paravirtualization, the appropriate feature bit should be checked.
|
|
|
|
*/
|
|
|
|
#define KVM_CPUID_FEATURES 0x40000001
|
2008-02-22 17:21:36 +00:00
|
|
|
#define KVM_FEATURE_CLOCKSOURCE 0
|
|
|
|
#define KVM_FEATURE_NOP_IO_DELAY 1
|
2008-02-22 17:21:37 +00:00
|
|
|
#define KVM_FEATURE_MMU_OP 2
|
2010-05-11 16:17:42 +00:00
|
|
|
/* This indicates that the new set of kvmclock msrs
|
|
|
|
* are available. The use of 0x11 and 0x12 is deprecated
|
|
|
|
*/
|
|
|
|
#define KVM_FEATURE_CLOCKSOURCE2 3
|
2008-02-15 19:52:47 +00:00
|
|
|
|
|
|
|
#define MSR_KVM_WALL_CLOCK 0x11
|
|
|
|
#define MSR_KVM_SYSTEM_TIME 0x12
|
2007-10-11 13:34:17 +00:00
|
|
|
|
2010-05-11 16:17:41 +00:00
|
|
|
/* Custom MSRs falls in the range 0x4b564d00-0x4b564dff */
|
|
|
|
#define MSR_KVM_WALL_CLOCK_NEW 0x4b564d00
|
|
|
|
#define MSR_KVM_SYSTEM_TIME_NEW 0x4b564d01
|
|
|
|
|
2008-02-22 17:21:37 +00:00
|
|
|
#define KVM_MAX_MMU_OP_BATCH 32
|
|
|
|
|
|
|
|
/* Operations for KVM_HC_MMU_OP */
|
|
|
|
#define KVM_MMU_OP_WRITE_PTE 1
|
|
|
|
#define KVM_MMU_OP_FLUSH_TLB 2
|
|
|
|
#define KVM_MMU_OP_RELEASE_PT 3
|
|
|
|
|
|
|
|
/* Payload for KVM_HC_MMU_OP */
|
|
|
|
struct kvm_mmu_op_header {
|
|
|
|
__u32 op;
|
|
|
|
__u32 pad;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kvm_mmu_op_write_pte {
|
|
|
|
struct kvm_mmu_op_header header;
|
|
|
|
__u64 pte_phys;
|
|
|
|
__u64 pte_val;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kvm_mmu_op_flush_tlb {
|
|
|
|
struct kvm_mmu_op_header header;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct kvm_mmu_op_release_pt {
|
|
|
|
struct kvm_mmu_op_header header;
|
|
|
|
__u64 pt_phys;
|
|
|
|
};
|
|
|
|
|
2007-10-11 13:34:17 +00:00
|
|
|
#ifdef __KERNEL__
|
|
|
|
#include <asm/processor.h>
|
|
|
|
|
2008-02-15 19:52:47 +00:00
|
|
|
extern void kvmclock_init(void);
|
|
|
|
|
|
|
|
|
2007-10-11 13:34:17 +00:00
|
|
|
/* This instruction is vmcall. On non-VT architectures, it will generate a
|
|
|
|
* trap that we will then rewrite to the appropriate instruction.
|
|
|
|
*/
|
|
|
|
#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
|
|
|
|
|
|
|
|
/* For KVM hypercalls, a three-byte sequence of either the vmrun or the vmmrun
|
|
|
|
* instruction. The hypervisor may replace it with something else but only the
|
|
|
|
* instructions are guaranteed to be supported.
|
|
|
|
*
|
|
|
|
* Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
|
|
|
|
* The hypercall number should be placed in rax and the return value will be
|
|
|
|
* placed in rax. No other registers will be clobbered unless explicited
|
|
|
|
* noted by the particular hypercall.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline long kvm_hypercall0(unsigned int nr)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile(KVM_HYPERCALL
|
|
|
|
: "=a"(ret)
|
2008-07-03 16:02:36 +00:00
|
|
|
: "a"(nr)
|
|
|
|
: "memory");
|
2007-10-11 13:34:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile(KVM_HYPERCALL
|
|
|
|
: "=a"(ret)
|
2008-07-03 16:02:36 +00:00
|
|
|
: "a"(nr), "b"(p1)
|
|
|
|
: "memory");
|
2007-10-11 13:34:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
|
|
|
|
unsigned long p2)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile(KVM_HYPERCALL
|
|
|
|
: "=a"(ret)
|
2008-07-03 16:02:36 +00:00
|
|
|
: "a"(nr), "b"(p1), "c"(p2)
|
|
|
|
: "memory");
|
2007-10-11 13:34:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
|
|
|
|
unsigned long p2, unsigned long p3)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile(KVM_HYPERCALL
|
|
|
|
: "=a"(ret)
|
2008-07-03 16:02:36 +00:00
|
|
|
: "a"(nr), "b"(p1), "c"(p2), "d"(p3)
|
|
|
|
: "memory");
|
2007-10-11 13:34:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
|
|
|
|
unsigned long p2, unsigned long p3,
|
|
|
|
unsigned long p4)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile(KVM_HYPERCALL
|
|
|
|
: "=a"(ret)
|
2008-07-03 16:02:36 +00:00
|
|
|
: "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
|
|
|
|
: "memory");
|
2007-10-11 13:34:17 +00:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline int kvm_para_available(void)
|
|
|
|
{
|
|
|
|
unsigned int eax, ebx, ecx, edx;
|
|
|
|
char signature[13];
|
|
|
|
|
|
|
|
cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
|
|
|
|
memcpy(signature + 0, &ebx, 4);
|
|
|
|
memcpy(signature + 4, &ecx, 4);
|
|
|
|
memcpy(signature + 8, &edx, 4);
|
|
|
|
signature[12] = 0;
|
|
|
|
|
|
|
|
if (strcmp(signature, "KVMKVMKVM") == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int kvm_arch_para_features(void)
|
|
|
|
{
|
|
|
|
return cpuid_eax(KVM_CPUID_FEATURES);
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2008-10-23 05:26:29 +00:00
|
|
|
#endif /* _ASM_X86_KVM_PARA_H */
|