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> |
David Howells | af170c5 | 2012-12-14 22:37:13 +0000 | [diff] [blame] | 5 | #include <uapi/asm/kvm_para.h> |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 6 | |
Glauber de Oliveira Costa | 1806852 | 2008-02-15 17:52:47 -0200 | [diff] [blame] | 7 | extern void kvmclock_init(void); |
Gleb Natapov | ca3f101 | 2010-10-14 11:22:49 +0200 | [diff] [blame] | 8 | extern int kvm_register_clock(char *txt); |
Glauber de Oliveira Costa | 1806852 | 2008-02-15 17:52:47 -0200 | [diff] [blame] | 9 | |
Marcelo Tosatti | 90993cd | 2012-08-16 17:00:19 -0300 | [diff] [blame] | 10 | #ifdef CONFIG_KVM_GUEST |
Eric B Munson | 3b5d56b | 2012-03-10 14:37:26 -0500 | [diff] [blame] | 11 | bool kvm_check_and_clear_guest_paused(void); |
| 12 | #else |
| 13 | static inline bool kvm_check_and_clear_guest_paused(void) |
| 14 | { |
| 15 | return false; |
| 16 | } |
Marcelo Tosatti | 90993cd | 2012-08-16 17:00:19 -0300 | [diff] [blame] | 17 | #endif /* CONFIG_KVM_GUEST */ |
Glauber de Oliveira Costa | 1806852 | 2008-02-15 17:52:47 -0200 | [diff] [blame] | 18 | |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 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 | |
Raghavendra K T | e423ca1 | 2012-08-07 13:10:13 +0530 | [diff] [blame] | 24 | /* 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] | 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 |
Jesse Larrew | 11393a0 | 2012-12-10 15:31:51 -0600 | [diff] [blame] | 30 | * placed in rax. No other registers will be clobbered unless explicitly |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 31 | * noted by the particular hypercall. |
| 32 | */ |
| 33 | |
| 34 | static inline long kvm_hypercall0(unsigned int nr) |
| 35 | { |
| 36 | long ret; |
| 37 | asm volatile(KVM_HYPERCALL |
| 38 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 39 | : "a"(nr) |
| 40 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 41 | return ret; |
| 42 | } |
| 43 | |
| 44 | static inline long kvm_hypercall1(unsigned int nr, unsigned long p1) |
| 45 | { |
| 46 | long ret; |
| 47 | asm volatile(KVM_HYPERCALL |
| 48 | : "=a"(ret) |
Anthony Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 49 | : "a"(nr), "b"(p1) |
| 50 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 51 | return ret; |
| 52 | } |
| 53 | |
| 54 | static 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 Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 60 | : "a"(nr), "b"(p1), "c"(p2) |
| 61 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 62 | return ret; |
| 63 | } |
| 64 | |
| 65 | static 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 Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 71 | : "a"(nr), "b"(p1), "c"(p2), "d"(p3) |
| 72 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 73 | return ret; |
| 74 | } |
| 75 | |
| 76 | static 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 Liguori | ca37393 | 2008-07-03 19:02:36 +0300 | [diff] [blame] | 83 | : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4) |
| 84 | : "memory"); |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 85 | return ret; |
| 86 | } |
| 87 | |
Alexander Graf | ba49296 | 2010-07-29 14:47:56 +0200 | [diff] [blame] | 88 | #ifdef CONFIG_KVM_GUEST |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 89 | bool kvm_para_available(void); |
Paolo Bonzini | 77f01bd | 2014-01-27 14:51:44 +0100 | [diff] [blame] | 90 | unsigned int kvm_arch_para_features(void); |
Alexander Graf | ba49296 | 2010-07-29 14:47:56 +0200 | [diff] [blame] | 91 | void __init kvm_guest_init(void); |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 92 | void kvm_async_pf_task_wait(u32 token); |
| 93 | void kvm_async_pf_task_wake(u32 token); |
| 94 | u32 kvm_read_and_reset_pf_reason(void); |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 95 | extern void kvm_disable_steal_time(void); |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 96 | |
| 97 | #ifdef CONFIG_PARAVIRT_SPINLOCKS |
| 98 | void __init kvm_spinlock_init(void); |
| 99 | #else /* !CONFIG_PARAVIRT_SPINLOCKS */ |
| 100 | static inline void kvm_spinlock_init(void) |
| 101 | { |
| 102 | } |
| 103 | #endif /* CONFIG_PARAVIRT_SPINLOCKS */ |
| 104 | |
| 105 | #else /* CONFIG_KVM_GUEST */ |
| 106 | #define kvm_guest_init() do {} while (0) |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 107 | #define kvm_async_pf_task_wait(T) do {} while(0) |
| 108 | #define kvm_async_pf_task_wake(T) do {} while(0) |
Srivatsa Vaddagiri | 92b7520 | 2013-08-06 14:55:41 +0530 | [diff] [blame] | 109 | |
Paolo Bonzini | 1c300a4 | 2014-01-27 14:49:40 +0100 | [diff] [blame] | 110 | static inline bool kvm_para_available(void) |
| 111 | { |
| 112 | return 0; |
| 113 | } |
| 114 | |
Paolo Bonzini | 77f01bd | 2014-01-27 14:51:44 +0100 | [diff] [blame] | 115 | static inline unsigned int kvm_arch_para_features(void) |
| 116 | { |
| 117 | return 0; |
| 118 | } |
| 119 | |
Jan Kiszka | d4c90b0 | 2010-10-20 18:34:54 +0200 | [diff] [blame] | 120 | static inline u32 kvm_read_and_reset_pf_reason(void) |
Gleb Natapov | 631bc48 | 2010-10-14 11:22:52 +0200 | [diff] [blame] | 121 | { |
| 122 | return 0; |
| 123 | } |
Glauber Costa | d910f5c | 2011-07-11 15:28:19 -0400 | [diff] [blame] | 124 | |
| 125 | static inline void kvm_disable_steal_time(void) |
| 126 | { |
| 127 | return; |
| 128 | } |
Christian Borntraeger | 5f43238 | 2007-10-11 15:34:17 +0200 | [diff] [blame] | 129 | #endif |
| 130 | |
H. Peter Anvin | 1965aae | 2008-10-22 22:26:29 -0700 | [diff] [blame] | 131 | #endif /* _ASM_X86_KVM_PARA_H */ |