2 * Copyright (C) 2016, VMware, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
12 * NON INFRINGEMENT. See the GNU General Public License for more
15 * Based on code from vmware.c and vmmouse.c.
17 * Sinclair Yeh <syeh@vmware.com>
24 * Hypervisor-specific bi-directional communication channel. Should never
25 * execute on bare metal hardware. The caller must make sure to check for
26 * supported hypervisor before using these macros.
28 * The last two parameters are both input and output and must be initialized.
30 * @cmd: [IN] Message Cmd
31 * @in_ebx: [IN] Message Len, through EBX
32 * @in_si: [IN] Input argument through SI, set to 0 if not used
33 * @in_di: [IN] Input argument through DI, set ot 0 if not used
34 * @port_num: [IN] port number + [channel id]
35 * @magic: [IN] hypervisor magic value
36 * @eax: [OUT] value of EAX register
37 * @ebx: [OUT] e.g. status from an HB message status command
38 * @ecx: [OUT] e.g. status from a non-HB message status command
39 * @edx: [OUT] e.g. channel id
43 #define VMW_PORT(cmd, in_ebx, in_si, in_di, \
45 eax, ebx, ecx, edx, si, di) \
47 asm volatile ("inl %%dx, %%eax;" : \
65 * Hypervisor-specific bi-directional communication channel. Should never
66 * execute on bare metal hardware. The caller must make sure to check for
67 * supported hypervisor before using these macros.
69 * The last 3 parameters are both input and output and must be initialized.
71 * @cmd: [IN] Message Cmd
72 * @in_ecx: [IN] Message Len, through ECX
73 * @in_si: [IN] Input argument through SI, set to 0 if not used
74 * @in_di: [IN] Input argument through DI, set to 0 if not used
75 * @port_num: [IN] port number + [channel id]
76 * @magic: [IN] hypervisor magic value
78 * @eax: [OUT] value of EAX register
79 * @ebx: [OUT] e.g. status from an HB message status command
80 * @ecx: [OUT] e.g. status from a non-HB message status command
81 * @edx: [OUT] e.g. channel id
87 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
88 port_num, magic, bp, \
89 eax, ebx, ecx, edx, si, di) \
91 asm volatile ("push %%rbp;" \
112 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
113 port_num, magic, bp, \
114 eax, ebx, ecx, edx, si, di) \
116 asm volatile ("push %%rbp;" \
139 * In the 32-bit version of this macro, we store bp in a memory location
140 * because we've ran out of registers.
141 * Now we can't reference that memory location while we've modified
142 * %esp or %ebp, so we first push it on the stack, just before we push
143 * %ebp, and then when we need it we read it from the stack where we
146 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
147 port_num, magic, bp, \
148 eax, ebx, ecx, edx, si, di) \
150 asm volatile ("push %12;" \
152 "mov 0x04(%%esp), %%ebp;" \
155 "add $0x04, %%esp;" : \
173 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
174 port_num, magic, bp, \
175 eax, ebx, ecx, edx, si, di) \
177 asm volatile ("push %12;" \
179 "mov 0x04(%%esp), %%ebp;" \
182 "add $0x04, %%esp;" : \
198 #endif /* #if __x86_64__ */