Linux 3.11-rc3
[cris-mirror.git] / arch / x86 / include / asm / kvm_para.h
blob695399f2d5eb315a62823a9fb8b1673a90447b04
1 #ifndef _ASM_X86_KVM_PARA_H
2 #define _ASM_X86_KVM_PARA_H
4 #include <asm/processor.h>
5 #include <uapi/asm/kvm_para.h>
7 extern void kvmclock_init(void);
8 extern int kvm_register_clock(char *txt);
10 #ifdef CONFIG_KVM_GUEST
11 bool kvm_check_and_clear_guest_paused(void);
12 #else
13 static inline bool kvm_check_and_clear_guest_paused(void)
15 return false;
17 #endif /* CONFIG_KVM_GUEST */
19 /* This instruction is vmcall. On non-VT architectures, it will generate a
20 * trap that we will then rewrite to the appropriate instruction.
22 #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
24 /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
25 * instruction. The hypervisor may replace it with something else but only the
26 * instructions are guaranteed to be supported.
28 * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively.
29 * The hypercall number should be placed in rax and the return value will be
30 * placed in rax. No other registers will be clobbered unless explicitly
31 * noted by the particular hypercall.
34 static inline long kvm_hypercall0(unsigned int nr)
36 long ret;
37 asm volatile(KVM_HYPERCALL
38 : "=a"(ret)
39 : "a"(nr)
40 : "memory");
41 return ret;
44 static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
46 long ret;
47 asm volatile(KVM_HYPERCALL
48 : "=a"(ret)
49 : "a"(nr), "b"(p1)
50 : "memory");
51 return ret;
54 static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
55 unsigned long p2)
57 long ret;
58 asm volatile(KVM_HYPERCALL
59 : "=a"(ret)
60 : "a"(nr), "b"(p1), "c"(p2)
61 : "memory");
62 return ret;
65 static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
66 unsigned long p2, unsigned long p3)
68 long ret;
69 asm volatile(KVM_HYPERCALL
70 : "=a"(ret)
71 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
72 : "memory");
73 return ret;
76 static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
77 unsigned long p2, unsigned long p3,
78 unsigned long p4)
80 long ret;
81 asm volatile(KVM_HYPERCALL
82 : "=a"(ret)
83 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
84 : "memory");
85 return ret;
88 static inline bool kvm_para_available(void)
90 unsigned int eax, ebx, ecx, edx;
91 char signature[13];
93 if (boot_cpu_data.cpuid_level < 0)
94 return false; /* So we don't blow up on old processors */
96 if (cpu_has_hypervisor) {
97 cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx);
98 memcpy(signature + 0, &ebx, 4);
99 memcpy(signature + 4, &ecx, 4);
100 memcpy(signature + 8, &edx, 4);
101 signature[12] = 0;
103 if (strcmp(signature, "KVMKVMKVM") == 0)
104 return true;
107 return false;
110 static inline unsigned int kvm_arch_para_features(void)
112 return cpuid_eax(KVM_CPUID_FEATURES);
115 #ifdef CONFIG_KVM_GUEST
116 void __init kvm_guest_init(void);
117 void kvm_async_pf_task_wait(u32 token);
118 void kvm_async_pf_task_wake(u32 token);
119 u32 kvm_read_and_reset_pf_reason(void);
120 extern void kvm_disable_steal_time(void);
121 #else
122 #define kvm_guest_init() do { } while (0)
123 #define kvm_async_pf_task_wait(T) do {} while(0)
124 #define kvm_async_pf_task_wake(T) do {} while(0)
125 static inline u32 kvm_read_and_reset_pf_reason(void)
127 return 0;
130 static inline void kvm_disable_steal_time(void)
132 return;
134 #endif
136 #endif /* _ASM_X86_KVM_PARA_H */