1 /* SPDX-License-Identifier: GPL-2.0+ OR MIT */
2 /**************************************************************************
4 * Copyright 2016 VMware, Inc., Palo Alto, CA., USA
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the
8 * "Software"), to deal in the Software without restriction, including
9 * without limitation the rights to use, copy, modify, merge, publish,
10 * distribute, sub license, and/or sell copies of the Software, and to
11 * permit persons to whom the Software is furnished to do so, subject to
12 * the following conditions:
14 * The above copyright notice and this permission notice (including the
15 * next paragraph) shall be included in all copies or substantial portions
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
21 * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
22 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
23 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
24 * USE OR OTHER DEALINGS IN THE SOFTWARE.
26 **************************************************************************
28 * Based on code from vmware.c and vmmouse.c.
30 * Sinclair Yeh <syeh@vmware.com>
37 * Hypervisor-specific bi-directional communication channel. Should never
38 * execute on bare metal hardware. The caller must make sure to check for
39 * supported hypervisor before using these macros.
41 * The last two parameters are both input and output and must be initialized.
43 * @cmd: [IN] Message Cmd
44 * @in_ebx: [IN] Message Len, through EBX
45 * @in_si: [IN] Input argument through SI, set to 0 if not used
46 * @in_di: [IN] Input argument through DI, set ot 0 if not used
47 * @port_num: [IN] port number + [channel id]
48 * @magic: [IN] hypervisor magic value
49 * @eax: [OUT] value of EAX register
50 * @ebx: [OUT] e.g. status from an HB message status command
51 * @ecx: [OUT] e.g. status from a non-HB message status command
52 * @edx: [OUT] e.g. channel id
56 #define VMW_PORT(cmd, in_ebx, in_si, in_di, \
58 eax, ebx, ecx, edx, si, di) \
60 asm volatile ("inl %%dx, %%eax;" : \
78 * Hypervisor-specific bi-directional communication channel. Should never
79 * execute on bare metal hardware. The caller must make sure to check for
80 * supported hypervisor before using these macros.
82 * The last 3 parameters are both input and output and must be initialized.
84 * @cmd: [IN] Message Cmd
85 * @in_ecx: [IN] Message Len, through ECX
86 * @in_si: [IN] Input argument through SI, set to 0 if not used
87 * @in_di: [IN] Input argument through DI, set to 0 if not used
88 * @port_num: [IN] port number + [channel id]
89 * @magic: [IN] hypervisor magic value
91 * @eax: [OUT] value of EAX register
92 * @ebx: [OUT] e.g. status from an HB message status command
93 * @ecx: [OUT] e.g. status from a non-HB message status command
94 * @edx: [OUT] e.g. channel id
100 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
101 port_num, magic, bp, \
102 eax, ebx, ecx, edx, si, di) \
104 asm volatile ("push %%rbp;" \
125 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
126 port_num, magic, bp, \
127 eax, ebx, ecx, edx, si, di) \
129 asm volatile ("push %%rbp;" \
152 * In the 32-bit version of this macro, we store bp in a memory location
153 * because we've ran out of registers.
154 * Now we can't reference that memory location while we've modified
155 * %esp or %ebp, so we first push it on the stack, just before we push
156 * %ebp, and then when we need it we read it from the stack where we
159 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
160 port_num, magic, bp, \
161 eax, ebx, ecx, edx, si, di) \
163 asm volatile ("push %12;" \
165 "mov 0x04(%%esp), %%ebp;" \
168 "add $0x04, %%esp;" : \
186 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
187 port_num, magic, bp, \
188 eax, ebx, ecx, edx, si, di) \
190 asm volatile ("push %12;" \
192 "mov 0x04(%%esp), %%ebp;" \
195 "add $0x04, %%esp;" : \
211 #endif /* #if __x86_64__ */