x86, kvm: Switch to use hypervisor_cpuid_base()
[deliverable/linux.git] / arch / x86 / include / asm / kvm_para.h
CommitLineData
1965aae3
PA
1#ifndef _ASM_X86_KVM_PARA_H
2#define _ASM_X86_KVM_PARA_H
5f43238d 3
5f43238d 4#include <asm/processor.h>
af170c50 5#include <uapi/asm/kvm_para.h>
5f43238d 6
18068523 7extern void kvmclock_init(void);
ca3f1017 8extern int kvm_register_clock(char *txt);
18068523 9
90993cdd 10#ifdef CONFIG_KVM_GUEST
3b5d56b9
EM
11bool kvm_check_and_clear_guest_paused(void);
12#else
13static inline bool kvm_check_and_clear_guest_paused(void)
14{
15 return false;
16}
90993cdd 17#endif /* CONFIG_KVM_GUEST */
18068523 18
5f43238d
CB
19/* This instruction is vmcall. On non-VT architectures, it will generate a
20 * trap that we will then rewrite to the appropriate instruction.
21 */
22#define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
23
e423ca15 24/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
5f43238d
CB
25 * instruction. The hypervisor may replace it with something else but only the
26 * instructions are guaranteed to be supported.
27 *
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
11393a07 30 * placed in rax. No other registers will be clobbered unless explicitly
5f43238d
CB
31 * noted by the particular hypercall.
32 */
33
34static inline long kvm_hypercall0(unsigned int nr)
35{
36 long ret;
37 asm volatile(KVM_HYPERCALL
38 : "=a"(ret)
ca373932
AL
39 : "a"(nr)
40 : "memory");
5f43238d
CB
41 return ret;
42}
43
44static inline long kvm_hypercall1(unsigned int nr, unsigned long p1)
45{
46 long ret;
47 asm volatile(KVM_HYPERCALL
48 : "=a"(ret)
ca373932
AL
49 : "a"(nr), "b"(p1)
50 : "memory");
5f43238d
CB
51 return ret;
52}
53
54static inline long kvm_hypercall2(unsigned int nr, unsigned long p1,
55 unsigned long p2)
56{
57 long ret;
58 asm volatile(KVM_HYPERCALL
59 : "=a"(ret)
ca373932
AL
60 : "a"(nr), "b"(p1), "c"(p2)
61 : "memory");
5f43238d
CB
62 return ret;
63}
64
65static inline long kvm_hypercall3(unsigned int nr, unsigned long p1,
66 unsigned long p2, unsigned long p3)
67{
68 long ret;
69 asm volatile(KVM_HYPERCALL
70 : "=a"(ret)
ca373932
AL
71 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
72 : "memory");
5f43238d
CB
73 return ret;
74}
75
76static inline long kvm_hypercall4(unsigned int nr, unsigned long p1,
77 unsigned long p2, unsigned long p3,
78 unsigned long p4)
79{
80 long ret;
81 asm volatile(KVM_HYPERCALL
82 : "=a"(ret)
ca373932
AL
83 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
84 : "memory");
5f43238d
CB
85 return ret;
86}
87
1085ba7f 88static inline uint32_t kvm_cpuid_base(void)
5f43238d 89{
c3709e67 90 if (boot_cpu_data.cpuid_level < 0)
1085ba7f 91 return 0; /* So we don't blow up on old processors */
c3709e67 92
1085ba7f
JW
93 if (cpu_has_hypervisor)
94 return hypervisor_cpuid_base("KVMKVMKVM\0\0\0", 0);
5f43238d 95
1085ba7f
JW
96 return 0;
97}
5f43238d 98
1085ba7f
JW
99static inline bool kvm_para_available(void)
100{
101 return kvm_cpuid_base() != 0;
5f43238d
CB
102}
103
104static inline unsigned int kvm_arch_para_features(void)
105{
106 return cpuid_eax(KVM_CPUID_FEATURES);
107}
108
ba492962
AG
109#ifdef CONFIG_KVM_GUEST
110void __init kvm_guest_init(void);
631bc487
GN
111void kvm_async_pf_task_wait(u32 token);
112void kvm_async_pf_task_wake(u32 token);
113u32 kvm_read_and_reset_pf_reason(void);
d910f5c1 114extern void kvm_disable_steal_time(void);
ba492962
AG
115#else
116#define kvm_guest_init() do { } while (0)
631bc487
GN
117#define kvm_async_pf_task_wait(T) do {} while(0)
118#define kvm_async_pf_task_wake(T) do {} while(0)
d4c90b00 119static inline u32 kvm_read_and_reset_pf_reason(void)
631bc487
GN
120{
121 return 0;
122}
d910f5c1
GC
123
124static inline void kvm_disable_steal_time(void)
125{
126 return;
127}
5f43238d
CB
128#endif
129
1965aae3 130#endif /* _ASM_X86_KVM_PARA_H */
This page took 0.402117 seconds and 5 git commands to generate.