| 
									
										
										
										
											2008-10-22 22:26:29 -07:00
										 |  |  | #ifndef _ASM_X86_KVM_PARA_H
 | 
					
						
							|  |  |  | #define _ASM_X86_KVM_PARA_H
 | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | #include <asm/processor.h>
 | 
					
						
							| 
									
										
										
										
											2012-12-14 22:37:13 +00:00
										 |  |  | #include <uapi/asm/kvm_para.h>
 | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-02-15 17:52:47 -02:00
										 |  |  | extern void kvmclock_init(void); | 
					
						
							| 
									
										
										
										
											2010-10-14 11:22:49 +02:00
										 |  |  | extern int kvm_register_clock(char *txt); | 
					
						
							| 
									
										
										
										
											2008-02-15 17:52:47 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-16 17:00:19 -03:00
										 |  |  | #ifdef CONFIG_KVM_GUEST
 | 
					
						
							| 
									
										
										
										
											2012-03-10 14:37:26 -05:00
										 |  |  | bool kvm_check_and_clear_guest_paused(void); | 
					
						
							|  |  |  | #else
 | 
					
						
							|  |  |  | static inline bool kvm_check_and_clear_guest_paused(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return false; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2012-08-16 17:00:19 -03:00
										 |  |  | #endif /* CONFIG_KVM_GUEST */
 | 
					
						
							| 
									
										
										
										
											2008-02-15 17:52:47 -02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | /* This instruction is vmcall.  On non-VT architectures, it will generate a
 | 
					
						
							|  |  |  |  * trap that we will then rewrite to the appropriate instruction. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | #define KVM_HYPERCALL ".byte 0x0f,0x01,0xc1"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-08-07 13:10:13 +05:30
										 |  |  | /* For KVM hypercalls, a three-byte sequence of either the vmcall or the vmmcall
 | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  |  * instruction.  The hypervisor may replace it with something else but only the | 
					
						
							|  |  |  |  * instructions are guaranteed to be supported. | 
					
						
							|  |  |  |  * | 
					
						
							|  |  |  |  * Up to four arguments may be passed in rbx, rcx, rdx, and rsi respectively. | 
					
						
							|  |  |  |  * The hypercall number should be placed in rax and the return value will be | 
					
						
							| 
									
										
										
										
											2012-12-10 15:31:51 -06:00
										 |  |  |  * placed in rax.  No other registers will be clobbered unless explicitly | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  |  * noted by the particular hypercall. | 
					
						
							|  |  |  |  */ | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline long kvm_hypercall0(unsigned int nr) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long ret; | 
					
						
							|  |  |  | 	asm volatile(KVM_HYPERCALL | 
					
						
							|  |  |  | 		     : "=a"(ret) | 
					
						
							| 
									
										
										
										
											2008-07-03 19:02:36 +03:00
										 |  |  | 		     : "a"(nr) | 
					
						
							|  |  |  | 		     : "memory"); | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline long kvm_hypercall1(unsigned int nr, unsigned long p1) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long ret; | 
					
						
							|  |  |  | 	asm volatile(KVM_HYPERCALL | 
					
						
							|  |  |  | 		     : "=a"(ret) | 
					
						
							| 
									
										
										
										
											2008-07-03 19:02:36 +03:00
										 |  |  | 		     : "a"(nr), "b"(p1) | 
					
						
							|  |  |  | 		     : "memory"); | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline long kvm_hypercall2(unsigned int nr, unsigned long p1, | 
					
						
							|  |  |  | 				  unsigned long p2) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long ret; | 
					
						
							|  |  |  | 	asm volatile(KVM_HYPERCALL | 
					
						
							|  |  |  | 		     : "=a"(ret) | 
					
						
							| 
									
										
										
										
											2008-07-03 19:02:36 +03:00
										 |  |  | 		     : "a"(nr), "b"(p1), "c"(p2) | 
					
						
							|  |  |  | 		     : "memory"); | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline long kvm_hypercall3(unsigned int nr, unsigned long p1, | 
					
						
							|  |  |  | 				  unsigned long p2, unsigned long p3) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long ret; | 
					
						
							|  |  |  | 	asm volatile(KVM_HYPERCALL | 
					
						
							|  |  |  | 		     : "=a"(ret) | 
					
						
							| 
									
										
										
										
											2008-07-03 19:02:36 +03:00
										 |  |  | 		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3) | 
					
						
							|  |  |  | 		     : "memory"); | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline long kvm_hypercall4(unsigned int nr, unsigned long p1, | 
					
						
							|  |  |  | 				  unsigned long p2, unsigned long p3, | 
					
						
							|  |  |  | 				  unsigned long p4) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	long ret; | 
					
						
							|  |  |  | 	asm volatile(KVM_HYPERCALL | 
					
						
							|  |  |  | 		     : "=a"(ret) | 
					
						
							| 
									
										
										
										
											2008-07-03 19:02:36 +03:00
										 |  |  | 		     : "a"(nr), "b"(p1), "c"(p2), "d"(p3), "S"(p4) | 
					
						
							|  |  |  | 		     : "memory"); | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 	return ret; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 18:59:12 -08:00
										 |  |  | static inline bool kvm_para_available(void) | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	unsigned int eax, ebx, ecx, edx; | 
					
						
							|  |  |  | 	char signature[13]; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-05-14 18:41:09 +01:00
										 |  |  | 	if (boot_cpu_data.cpuid_level < 0) | 
					
						
							| 
									
										
										
										
											2013-01-28 18:59:12 -08:00
										 |  |  | 		return false;	/* So we don't blow up on old processors */ | 
					
						
							| 
									
										
										
										
											2012-05-14 18:41:09 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-30 14:45:49 +03:00
										 |  |  | 	if (cpu_has_hypervisor) { | 
					
						
							|  |  |  | 		cpuid(KVM_CPUID_SIGNATURE, &eax, &ebx, &ecx, &edx); | 
					
						
							|  |  |  | 		memcpy(signature + 0, &ebx, 4); | 
					
						
							|  |  |  | 		memcpy(signature + 4, &ecx, 4); | 
					
						
							|  |  |  | 		memcpy(signature + 8, &edx, 4); | 
					
						
							|  |  |  | 		signature[12] = 0; | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2012-04-30 14:45:49 +03:00
										 |  |  | 		if (strcmp(signature, "KVMKVMKVM") == 0) | 
					
						
							| 
									
										
										
										
											2013-01-28 18:59:12 -08:00
										 |  |  | 			return true; | 
					
						
							| 
									
										
										
										
											2012-04-30 14:45:49 +03:00
										 |  |  | 	} | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2013-01-28 18:59:12 -08:00
										 |  |  | 	return false; | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | static inline unsigned int kvm_arch_para_features(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return cpuid_eax(KVM_CPUID_FEATURES); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2010-07-29 14:47:56 +02:00
										 |  |  | #ifdef CONFIG_KVM_GUEST
 | 
					
						
							|  |  |  | void __init kvm_guest_init(void); | 
					
						
							| 
									
										
										
										
											2010-10-14 11:22:52 +02:00
										 |  |  | void kvm_async_pf_task_wait(u32 token); | 
					
						
							|  |  |  | void kvm_async_pf_task_wake(u32 token); | 
					
						
							|  |  |  | u32 kvm_read_and_reset_pf_reason(void); | 
					
						
							| 
									
										
										
										
											2011-07-11 15:28:19 -04:00
										 |  |  | extern void kvm_disable_steal_time(void); | 
					
						
							| 
									
										
										
										
											2010-07-29 14:47:56 +02:00
										 |  |  | #else
 | 
					
						
							|  |  |  | #define kvm_guest_init() do { } while (0)
 | 
					
						
							| 
									
										
										
										
											2010-10-14 11:22:52 +02:00
										 |  |  | #define kvm_async_pf_task_wait(T) do {} while(0)
 | 
					
						
							|  |  |  | #define kvm_async_pf_task_wake(T) do {} while(0)
 | 
					
						
							| 
									
										
										
										
											2010-10-20 18:34:54 +02:00
										 |  |  | static inline u32 kvm_read_and_reset_pf_reason(void) | 
					
						
							| 
									
										
										
										
											2010-10-14 11:22:52 +02:00
										 |  |  | { | 
					
						
							|  |  |  | 	return 0; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2011-07-11 15:28:19 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | static inline void kvm_disable_steal_time(void) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	return; | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2007-10-11 15:34:17 +02:00
										 |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2008-10-22 22:26:29 -07:00
										 |  |  | #endif /* _ASM_X86_KVM_PARA_H */
 |