2008-10-23 12:26:29 +07:00
|
|
|
#ifndef _ASM_X86_KVM_PARA_H
|
|
|
|
#define _ASM_X86_KVM_PARA_H
|
2007-10-11 20:34:17 +07:00
|
|
|
|
|
|
|
#include <asm/processor.h>
|
2012-12-15 05:37:13 +07:00
|
|
|
#include <uapi/asm/kvm_para.h>
|
2007-10-11 20:34:17 +07:00
|
|
|
|
2008-02-16 02:52:47 +07:00
|
|
|
extern void kvmclock_init(void);
|
2010-10-14 16:22:49 +07:00
|
|
|
extern int kvm_register_clock(char *txt);
|
2008-02-16 02:52:47 +07:00
|
|
|
|
2012-08-17 03:00:19 +07:00
|
|
|
#ifdef CONFIG_KVM_GUEST
|
2012-03-11 02:37:26 +07:00
|
|
|
bool kvm_check_and_clear_guest_paused(void);
|
|
|
|
#else
|
|
|
|
static inline bool kvm_check_and_clear_guest_paused(void)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2012-08-17 03:00:19 +07:00
|
|
|
#endif /* CONFIG_KVM_GUEST */
|
2008-02-16 02:52:47 +07:00
|
|
|
|
2007-10-11 20:34:17 +07: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"
|
|
|
|
|
2012-08-07 14:40:13 +07:00
|
|
|
/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
|
2007-10-11 20:34:17 +07:00
|
|
|
* 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
|
2012-12-11 04:31:51 +07:00
|
|
|
* placed in rax. No other registers will be clobbered unless explicitly
|
2007-10-11 20:34:17 +07:00
|
|
|
* noted by the particular hypercall.
|
|
|
|
*/
|
|
|
|
|
|
|
|
static inline long kvm_hypercall0(unsigned int nr)
|
|
|
|
{
|
|
|
|
long ret;
|
|
|
|
asm volatile(KVM_HYPERCALL
|
|
|
|
: "=a"(ret)
|
2008-07-03 23:02:36 +07:00
|
|
|
: "a"(nr)
|
|
|
|
: "memory");
|
2007-10-11 20:34:17 +07: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 23:02:36 +07:00
|
|
|
: "a"(nr), "b"(p1)
|
|
|
|
: "memory");
|
2007-10-11 20:34:17 +07: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 23:02:36 +07:00
|
|
|
: "a"(nr), "b"(p1), "c"(p2)
|
|
|
|
: "memory");
|
2007-10-11 20:34:17 +07: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 23:02:36 +07:00
|
|
|
: "a"(nr), "b"(p1), "c"(p2), "d"(p3)
|
|
|
|
: "memory");
|
2007-10-11 20:34:17 +07: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 23:02:36 +07:00
|
|
|
: "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
|
|
|
|
: "memory");
|
2007-10-11 20:34:17 +07:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-01-29 09:59:12 +07:00
|
|
|
static inline bool kvm_para_available(void)
|
2007-10-11 20:34:17 +07:00
|
|
|
{
|
|
|
|
unsigned int eax, ebx, ecx, edx;
|
|
|
|
char signature[13];
|
|
|
|
|
2012-05-15 00:41:09 +07:00
|
|
|
if (boot_cpu_data.cpuid_level < 0)
|
2013-01-29 09:59:12 +07:00
|
|
|
return false; /* So we don't blow up on old processors */
|
2012-05-15 00:41:09 +07:00
|
|
|
|
2012-04-30 18:45:49 +07:00
|
|
|
if (cpu_has_hypervisor) {
|
|
|
|
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;
|
2007-10-11 20:34:17 +07:00
|
|
|
|
2012-04-30 18:45:49 +07:00
|
|
|
if (strcmp(signature, "KVMKVMKVM") == 0)
|
2013-01-29 09:59:12 +07:00
|
|
|
return true;
|
2012-04-30 18:45:49 +07:00
|
|
|
}
|
2007-10-11 20:34:17 +07:00
|
|
|
|
2013-01-29 09:59:12 +07:00
|
|
|
return false;
|
2007-10-11 20:34:17 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline unsigned int kvm_arch_para_features(void)
|
|
|
|
{
|
|
|
|
return cpuid_eax(KVM_CPUID_FEATURES);
|
|
|
|
}
|
|
|
|
|
2010-07-29 19:47:56 +07:00
|
|
|
#ifdef CONFIG_KVM_GUEST
|
|
|
|
void __init kvm_guest_init(void);
|
2010-10-14 16:22:52 +07:00
|
|
|
void kvm_async_pf_task_wait(u32 token);
|
|
|
|
void kvm_async_pf_task_wake(u32 token);
|
|
|
|
u32 kvm_read_and_reset_pf_reason(void);
|
2011-07-12 02:28:19 +07:00
|
|
|
extern void kvm_disable_steal_time(void);
|
2010-07-29 19:47:56 +07:00
|
|
|
#else
|
|
|
|
#define kvm_guest_init() do { } while (0)
|
2010-10-14 16:22:52 +07:00
|
|
|
#define kvm_async_pf_task_wait(T) do {} while(0)
|
|
|
|
#define kvm_async_pf_task_wake(T) do {} while(0)
|
2010-10-20 23:34:54 +07:00
|
|
|
static inline u32 kvm_read_and_reset_pf_reason(void)
|
2010-10-14 16:22:52 +07:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2011-07-12 02:28:19 +07:00
|
|
|
|
|
|
|
static inline void kvm_disable_steal_time(void)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2007-10-11 20:34:17 +07:00
|
|
|
#endif
|
|
|
|
|
2008-10-23 12:26:29 +07:00
|
|
|
#endif /* _ASM_X86_KVM_PARA_H */
|