1 /* SPDX-License-Identifier: GPL-2.0 or MIT */
2 #ifndef _ASM_X86_VMWARE_H
3 #define _ASM_X86_VMWARE_H
4 
5 #include <asm/cpufeatures.h>
6 #include <asm/alternative.h>
7 #include <linux/stringify.h>
8 
9 /*
10  * The hypercall definitions differ in the low word of the %edx argument
11  * in the following way: the old port base interface uses the port
12  * number to distinguish between high- and low bandwidth versions.
13  *
14  * The new vmcall interface instead uses a set of flags to select
15  * bandwidth mode and transfer direction. The flags should be loaded
16  * into %dx by any user and are automatically replaced by the port
17  * number if the VMWARE_HYPERVISOR_PORT method is used.
18  *
19  * In short, new driver code should strictly use the new definition of
20  * %dx content.
21  */
22 
23 /* Old port-based version */
24 #define VMWARE_HYPERVISOR_PORT    0x5658
25 #define VMWARE_HYPERVISOR_PORT_HB 0x5659
26 
27 /* Current vmcall / vmmcall version */
28 #define VMWARE_HYPERVISOR_HB   BIT(0)
29 #define VMWARE_HYPERVISOR_OUT  BIT(1)
30 
31 /* The low bandwidth call. The low word of edx is presumed clear. */
32 #define VMWARE_HYPERCALL						\
33 	ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT) ", %%dx; " \
34 		      "inl (%%dx), %%eax",				\
35 		      "vmcall", X86_FEATURE_VMCALL,			\
36 		      "vmmcall", X86_FEATURE_VMW_VMMCALL)
37 
38 /*
39  * The high bandwidth out call. The low word of edx is presumed to have the
40  * HB and OUT bits set.
41  */
42 #define VMWARE_HYPERCALL_HB_OUT						\
43 	ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \
44 		      "rep outsb",					\
45 		      "vmcall", X86_FEATURE_VMCALL,			\
46 		      "vmmcall", X86_FEATURE_VMW_VMMCALL)
47 
48 /*
49  * The high bandwidth in call. The low word of edx is presumed to have the
50  * HB bit set.
51  */
52 #define VMWARE_HYPERCALL_HB_IN						\
53 	ALTERNATIVE_2("movw $" __stringify(VMWARE_HYPERVISOR_PORT_HB) ", %%dx; " \
54 		      "rep insb",					\
55 		      "vmcall", X86_FEATURE_VMCALL,			\
56 		      "vmmcall", X86_FEATURE_VMW_VMMCALL)
57 #endif
58