blob: 1679cc799b2621ff2cba187ee80dffc9fa0ba055 [file] [log] [blame]
H. Peter Anvin1965aae2008-10-22 22:26:29 -07001#ifndef _ASM_X86_KVM_PARA_H
2#define _ASM_X86_KVM_PARA_H
Christian Borntraeger5f432382007-10-11 15:34:17 +02003
Christian Borntraeger5f432382007-10-11 15:34:17 +02004#include <asm/processor.h>
David Howellsaf170c52012-12-14 22:37:13 +00005#include <uapi/asm/kvm_para.h>
Christian Borntraeger5f432382007-10-11 15:34:17 +02006
Glauber de Oliveira Costa18068522008-02-15 17:52:47 -02007extern void kvmclock_init(void);
Gleb Natapovca3f1012010-10-14 11:22:49 +02008extern int kvm_register_clock(char *txt);
Glauber de Oliveira Costa18068522008-02-15 17:52:47 -02009
Marcelo Tosatti90993cd2012-08-16 17:00:19 -030010#ifdef CONFIG_KVM_GUEST
Eric B Munson3b5d56b2012-03-10 14:37:26 -050011bool kvm_check_and_clear_guest_paused(void);
12#else
13static inline bool kvm_check_and_clear_guest_paused(void)
14{
15 return false;
16}
Marcelo Tosatti90993cd2012-08-16 17:00:19 -030017#endif /* CONFIG_KVM_GUEST */
Glauber de Oliveira Costa18068522008-02-15 17:52:47 -020018
Christian Borntraeger5f432382007-10-11 15:34:17 +020019/* 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
Raghavendra K Te423ca12012-08-07 13:10:13 +053024/* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
Christian Borntraeger5f432382007-10-11 15:34:17 +020025 * 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
Jesse Larrew11393a02012-12-10 15:31:51 -060030 * placed in rax. No other registers will be clobbered unless explicitly
Christian Borntraeger5f432382007-10-11 15:34:17 +020031 * 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)
Anthony Liguorica373932008-07-03 19:02:36 +030039 : "a"(nr)
40 : "memory");
Christian Borntraeger5f432382007-10-11 15:34:17 +020041 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)
Anthony Liguorica373932008-07-03 19:02:36 +030049 : "a"(nr), "b"(p1)
50 : "memory");
Christian Borntraeger5f432382007-10-11 15:34:17 +020051 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)
Anthony Liguorica373932008-07-03 19:02:36 +030060 : "a"(nr), "b"(p1), "c"(p2)
61 : "memory");
Christian Borntraeger5f432382007-10-11 15:34:17 +020062 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)
Anthony Liguorica373932008-07-03 19:02:36 +030071 : "a"(nr), "b"(p1), "c"(p2), "d"(p3)
72 : "memory");
Christian Borntraeger5f432382007-10-11 15:34:17 +020073 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)
Anthony Liguorica373932008-07-03 19:02:36 +030083 : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4)
84 : "memory");
Christian Borntraeger5f432382007-10-11 15:34:17 +020085 return ret;
86}
87
Christian Borntraeger5f432382007-10-11 15:34:17 +020088static inline unsigned int kvm_arch_para_features(void)
89{
90 return cpuid_eax(KVM_CPUID_FEATURES);
91}
92
Alexander Grafba492962010-07-29 14:47:56 +020093#ifdef CONFIG_KVM_GUEST
Paolo Bonzini1c300a42014-01-27 14:49:40 +010094bool kvm_para_available(void);
Alexander Grafba492962010-07-29 14:47:56 +020095void __init kvm_guest_init(void);
Gleb Natapov631bc482010-10-14 11:22:52 +020096void kvm_async_pf_task_wait(u32 token);
97void kvm_async_pf_task_wake(u32 token);
98u32 kvm_read_and_reset_pf_reason(void);
Glauber Costad910f5c2011-07-11 15:28:19 -040099extern void kvm_disable_steal_time(void);
Srivatsa Vaddagiri92b75202013-08-06 14:55:41 +0530100
101#ifdef CONFIG_PARAVIRT_SPINLOCKS
102void __init kvm_spinlock_init(void);
103#else /* !CONFIG_PARAVIRT_SPINLOCKS */
104static inline void kvm_spinlock_init(void)
105{
106}
107#endif /* CONFIG_PARAVIRT_SPINLOCKS */
108
109#else /* CONFIG_KVM_GUEST */
110#define kvm_guest_init() do {} while (0)
Gleb Natapov631bc482010-10-14 11:22:52 +0200111#define kvm_async_pf_task_wait(T) do {} while(0)
112#define kvm_async_pf_task_wake(T) do {} while(0)
Srivatsa Vaddagiri92b75202013-08-06 14:55:41 +0530113
Paolo Bonzini1c300a42014-01-27 14:49:40 +0100114static inline bool kvm_para_available(void)
115{
116 return 0;
117}
118
Jan Kiszkad4c90b02010-10-20 18:34:54 +0200119static inline u32 kvm_read_and_reset_pf_reason(void)
Gleb Natapov631bc482010-10-14 11:22:52 +0200120{
121 return 0;
122}
Glauber Costad910f5c2011-07-11 15:28:19 -0400123
124static inline void kvm_disable_steal_time(void)
125{
126 return;
127}
Christian Borntraeger5f432382007-10-11 15:34:17 +0200128#endif
129
H. Peter Anvin1965aae2008-10-22 22:26:29 -0700130#endif /* _ASM_X86_KVM_PARA_H */