kvm_para.h 3.2 KB
Newer Older
H
H. Peter Anvin 已提交
1 2
#ifndef _ASM_X86_KVM_PARA_H
#define _ASM_X86_KVM_PARA_H
3 4

#include <asm/processor.h>
5
#include <uapi/asm/kvm_para.h>
6

7
extern void kvmclock_init(void);
8
extern int kvm_register_clock(char *txt);
9

10
#ifdef CONFIG_KVM_GUEST
11 12 13 14 15 16
bool kvm_check_and_clear_guest_paused(void);
#else
static inline bool kvm_check_and_clear_guest_paused(void)
{
	return false;
}
17
#endif /* CONFIG_KVM_GUEST */
18

19 20 21 22 23
/* 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"

24
/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
25 26 27 28 29 30 31 32 33 34 35 36 37 38
 * 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)
39 40
		     : "a"(nr)
		     : "memory");
41 42 43 44 45 46 47 48
	return ret;
}

static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
49 50
		     : "a"(nr), "b"(p1)
		     : "memory");
51 52 53 54 55 56 57 58 59
	return ret;
}

static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
				  unsigned long p2)
{
	long ret;
	asm volatile(KVM_HYPERCALL
		     : "=a"(ret)
60 61
		     : "a"(nr), "b"(p1), "c"(p2)
		     : "memory");
62 63 64 65 66 67 68 69 70
	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)
71 72
		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
		     : "memory");
73 74 75 76 77 78 79 80 81 82
	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)
83 84
		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
		     : "memory");
85 86 87
	return ret;
}

88
static inline bool kvm_para_available(void)
89 90 91 92
{
	unsigned int eax, ebx, ecx, edx;
	char signature[13];

93
	if (boot_cpu_data.cpuid_level < 0)
94
		return false;	/* So we don't blow up on old processors */
95

96 97 98 99 100 101
	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;
102

103
		if (strcmp(signature, "KVMKVMKVM") == 0)
104
			return true;
105
	}
106

107
	return false;
108 109 110 111 112 113 114
}

static inline unsigned int kvm_arch_para_features(void)
{
	return cpuid_eax(KVM_CPUID_FEATURES);
}

115 116
#ifdef CONFIG_KVM_GUEST
void __init kvm_guest_init(void);
G
Gleb Natapov 已提交
117 118 119
void kvm_async_pf_task_wait(u32 token);
void kvm_async_pf_task_wake(u32 token);
u32 kvm_read_and_reset_pf_reason(void);
120
extern void kvm_disable_steal_time(void);
121 122
#else
#define kvm_guest_init() do { } while (0)
G
Gleb Natapov 已提交
123 124
#define kvm_async_pf_task_wait(T) do {} while(0)
#define kvm_async_pf_task_wake(T) do {} while(0)
125
static inline u32 kvm_read_and_reset_pf_reason(void)
G
Gleb Natapov 已提交
126 127 128
{
	return 0;
}
129 130 131 132 133

static inline void kvm_disable_steal_time(void)
{
	return;
}
134 135
#endif

H
H. Peter Anvin 已提交
136
#endif /* _ASM_X86_KVM_PARA_H */