H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 1 | #ifndef _ASM_X86_KVM_PARA_H |
| 2 | #define _ASM_X86_KVM_PARA_H |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 3 | |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 4 | #include <asm/processor.h> |
Paolo Bonzini | c1118b3 | 2014-09-22 13:17:48 +0200 | [diff] [blame] | 5 | #include <asm/alternative.h> |
David Howells | af170c5 | 2012-12-14 22:37:13 +0000 | [diff] [blame] | 6 | #include <uapi/asm/kvm_para.h> |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 7 | |
Glauber de Oliveira Costa | 1806852 | 2008-02-15 17:52:47 -0200 | [diff] [blame] | 8 | extern void kvmclock_init(void); |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 9 | extern int kvm_register_clock(char *txt); |
Glauber de Oliveira Costa | 1806852 | 2008-02-15 17:52:47 -0200 | [diff] [blame] | 10 | |
Marcelo Tosatti | 90993cd | 2012-08-16 17:00:19 -0300 | [diff] [blame] | 11 | #ifdef CONFIG_KVM_GUEST |
Eric B Munson | 3b5d56b | 2012-03-10 14:37:26 -0500 | [diff] [blame] | 12 | bool kvm_check_and_clear_guest_paused(void); |
| 13 | #else |
| 14 | static inline bool kvm_check_and_clear_guest_paused(void) |
| 15 | { |
| 16 | return false; |
| 17 | } |
Marcelo Tosatti | 90993cd | 2012-08-16 17:00:19 -0300 | [diff] [blame] | 18 | #endif /* CONFIG_KVM_GUEST */ |
Glauber de Oliveira Costa | 1806852 | 2008-02-15 17:52:47 -0200 | [diff] [blame] | 19 | |
Paolo Bonzini | c1118b3 | 2014-09-22 13:17:48 +0200 | [diff] [blame] | 20 | #ifdef CONFIG_DEBUG_RODATA |
| 21 | #define KVM_HYPERCALL \ |
| 22 | ALTERNATIVE(".byte 0x0f,0x01,0xc1", ".byte 0x0f,0x01,0xd9", X86_FEATURE_VMMCALL) |
| 23 | #else |
| 24 | /* On AMD processors, vmcall will generate a trap that we will |
| 25 | * then rewrite to the appropriate instruction. |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 26 | */ |
| 27 | #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1" |
Paolo Bonzini | c1118b3 | 2014-09-22 13:17:48 +0200 | [diff] [blame] | 28 | #endif |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 29 | |
Raghavendra K T | e423ca1 | 2012-08-07 13:10:13 +0530 | [diff] [blame] | 30 | /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 31 | * instruction. The hypervisor may replace it with something else but only the |
| 32 | * instructions are guaranteed to be supported. |
| 33 | * |
| 34 | * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively. |
| 35 | * The hypercall number should be placed in rax and the return value will be |
Jesse Larrew | 11393a0 | 2012-12-10 15:31:51 -0600 | [diff] [blame] | 36 | * placed in rax. No other registers will be clobbered unless explicitly |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 37 | * noted by the particular hypercall. |
| 38 | */ |
| 39 | |
| 40 | static inline long kvm_hypercall0(unsigned int nr) |
| 41 | { |
| 42 | long ret; |
| 43 | asm volatile(KVM_HYPERCALL |
| 44 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 45 | : "a"(nr) |
| 46 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 47 | return ret; |
| 48 | } |
| 49 | |
| 50 | static inline long kvm_hypercall1(unsigned int nr, unsigned long p1) |
| 51 | { |
| 52 | long ret; |
| 53 | asm volatile(KVM_HYPERCALL |
| 54 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 55 | : "a"(nr), "b"(p1) |
| 56 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 57 | return ret; |
| 58 | } |
| 59 | |
| 60 | static inline long kvm_hypercall2(unsigned int nr, unsigned long p1, |
| 61 | unsigned long p2) |
| 62 | { |
| 63 | long ret; |
| 64 | asm volatile(KVM_HYPERCALL |
| 65 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 66 | : "a"(nr), "b"(p1), "c"(p2) |
| 67 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 68 | return ret; |
| 69 | } |
| 70 | |
| 71 | static inline long kvm_hypercall3(unsigned int nr, unsigned long p1, |
| 72 | unsigned long p2, unsigned long p3) |
| 73 | { |
| 74 | long ret; |
| 75 | asm volatile(KVM_HYPERCALL |
| 76 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 77 | : "a"(nr), "b"(p1), "c"(p2), "d"(p3) |
| 78 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 79 | return ret; |
| 80 | } |
| 81 | |
| 82 | static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, |
| 83 | unsigned long p2, unsigned long p3, |
| 84 | unsigned long p4) |
| 85 | { |
| 86 | long ret; |
| 87 | asm volatile(KVM_HYPERCALL |
| 88 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 89 | : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4) |
| 90 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 91 | return ret; |
| 92 | } |
| 93 | |
Alexander Graf | ba49296 | 2010-07-29 14:47:56 +0200 | [diff] [blame] | 94 | #ifdef CONFIG_KVM_GUEST |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 95 | bool kvm_para_available(void); |
Paolo Bonzini | 77f01bd | 2014-01-27 14:51:44 +0100 | [diff] [blame] | 96 | unsigned int kvm_arch_para_features(void); |
Alexander Graf | ba49296 | 2010-07-29 14:47:56 +0200 | [diff] [blame] | 97 | void __init kvm_guest_init(void); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 98 | void kvm_async_pf_task_wait(u32 token); |
| 99 | void kvm_async_pf_task_wake(u32 token); |
| 100 | u32 kvm_read_and_reset_pf_reason(void); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 101 | extern void kvm_disable_steal_time(void); |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 102 | |
| 103 | #ifdef CONFIG_PARAVIRT_SPINLOCKS |
| 104 | void __init kvm_spinlock_init(void); |
| 105 | #else /* !CONFIG_PARAVIRT_SPINLOCKS */ |
| 106 | static inline void kvm_spinlock_init(void) |
| 107 | { |
| 108 | } |
| 109 | #endif /* CONFIG_PARAVIRT_SPINLOCKS */ |
| 110 | |
| 111 | #else /* CONFIG_KVM_GUEST */ |
| 112 | #define kvm_guest_init() do {} while (0) |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 113 | #define kvm_async_pf_task_wait(T) do {} while(0) |
| 114 | #define kvm_async_pf_task_wake(T) do {} while(0) |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 115 | |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 116 | static inline bool kvm_para_available(void) |
| 117 | { |
Joe Perches | 1d804d0 | 2015-03-30 16:46:09 -0700 | [diff] [blame] | 118 | return false; |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 119 | } |
| 120 | |
Paolo Bonzini | 77f01bd | 2014-01-27 14:51:44 +0100 | [diff] [blame] | 121 | static inline unsigned int kvm_arch_para_features(void) |
| 122 | { |
| 123 | return 0; |
| 124 | } |
| 125 | |
Jan Kiszka | d4c90b0 | 2010-10-20 18:34:54 +0200 | [diff] [blame] | 126 | static inline u32 kvm_read_and_reset_pf_reason(void) |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 127 | { |
| 128 | return 0; |
| 129 | } |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 130 | |
| 131 | static inline void kvm_disable_steal_time(void) |
| 132 | { |
| 133 | return; |
| 134 | } |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 135 | #endif |
| 136 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 137 | #endif /* _ASM_X86_KVM_PARA_H */ |