Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0+ OR MIT */
0002 /**************************************************************************
0003  *
0004  * Copyright 2016-2021 VMware, Inc., Palo Alto, CA., USA
0005  *
0006  * Permission is hereby granted, free of charge, to any person obtaining a
0007  * copy of this software and associated documentation files (the
0008  * "Software"), to deal in the Software without restriction, including
0009  * without limitation the rights to use, copy, modify, merge, publish,
0010  * distribute, sub license, and/or sell copies of the Software, and to
0011  * permit persons to whom the Software is furnished to do so, subject to
0012  * the following conditions:
0013  *
0014  * The above copyright notice and this permission notice (including the
0015  * next paragraph) shall be included in all copies or substantial portions
0016  * of the Software.
0017  *
0018  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
0019  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
0020  * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
0021  * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
0022  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
0023  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
0024  * USE OR OTHER DEALINGS IN THE SOFTWARE.
0025  *
0026  **************************************************************************
0027  *
0028  * Based on code from vmware.c and vmmouse.c.
0029  * Author:
0030  *   Sinclair Yeh <syeh@vmware.com>
0031  */
0032 #ifndef _VMWGFX_MSG_X86_H
0033 #define _VMWGFX_MSG_X86_H
0034 
0035 
0036 #if defined(__i386__) || defined(__x86_64__)
0037 
0038 #include <asm/vmware.h>
0039 
0040 /**
0041  * Hypervisor-specific bi-directional communication channel.  Should never
0042  * execute on bare metal hardware.  The caller must make sure to check for
0043  * supported hypervisor before using these macros.
0044  *
0045  * The last two parameters are both input and output and must be initialized.
0046  *
0047  * @cmd: [IN] Message Cmd
0048  * @in_ebx: [IN] Message Len, through EBX
0049  * @in_si: [IN] Input argument through SI, set to 0 if not used
0050  * @in_di: [IN] Input argument through DI, set ot 0 if not used
0051  * @flags: [IN] hypercall flags + [channel id]
0052  * @magic: [IN] hypervisor magic value
0053  * @eax: [OUT] value of EAX register
0054  * @ebx: [OUT] e.g. status from an HB message status command
0055  * @ecx: [OUT] e.g. status from a non-HB message status command
0056  * @edx: [OUT] e.g. channel id
0057  * @si:  [OUT]
0058  * @di:  [OUT]
0059  */
0060 #define VMW_PORT(cmd, in_ebx, in_si, in_di, \
0061                  flags, magic,      \
0062                  eax, ebx, ecx, edx, si, di)    \
0063 ({                      \
0064         asm volatile (VMWARE_HYPERCALL :    \
0065                 "=a"(eax),          \
0066                 "=b"(ebx),          \
0067                 "=c"(ecx),          \
0068                 "=d"(edx),          \
0069                 "=S"(si),           \
0070                 "=D"(di) :          \
0071                 "a"(magic),         \
0072                 "b"(in_ebx),            \
0073                 "c"(cmd),           \
0074                 "d"(flags),         \
0075                 "S"(in_si),         \
0076                 "D"(in_di) :            \
0077                 "memory");          \
0078 })
0079 
0080 
0081 /**
0082  * Hypervisor-specific bi-directional communication channel.  Should never
0083  * execute on bare metal hardware.  The caller must make sure to check for
0084  * supported hypervisor before using these macros.
0085  *
0086  * The last 3 parameters are both input and output and must be initialized.
0087  *
0088  * @cmd: [IN] Message Cmd
0089  * @in_ecx: [IN] Message Len, through ECX
0090  * @in_si: [IN] Input argument through SI, set to 0 if not used
0091  * @in_di: [IN] Input argument through DI, set to 0 if not used
0092  * @flags: [IN] hypercall flags + [channel id]
0093  * @magic: [IN] hypervisor magic value
0094  * @bp:  [IN]
0095  * @eax: [OUT] value of EAX register
0096  * @ebx: [OUT] e.g. status from an HB message status command
0097  * @ecx: [OUT] e.g. status from a non-HB message status command
0098  * @edx: [OUT] e.g. channel id
0099  * @si:  [OUT]
0100  * @di:  [OUT]
0101  */
0102 #ifdef __x86_64__
0103 
0104 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,  \
0105                         flags, magic, bp,       \
0106                         eax, ebx, ecx, edx, si, di) \
0107 ({                          \
0108         asm volatile ("push %%rbp;"         \
0109                 "mov %12, %%rbp;"           \
0110                 VMWARE_HYPERCALL_HB_OUT         \
0111                 "pop %%rbp;" :              \
0112                 "=a"(eax),              \
0113                 "=b"(ebx),              \
0114                 "=c"(ecx),              \
0115                 "=d"(edx),              \
0116                 "=S"(si),               \
0117                 "=D"(di) :              \
0118                 "a"(magic),             \
0119                 "b"(cmd),               \
0120                 "c"(in_ecx),                \
0121                 "d"(flags),             \
0122                 "S"(in_si),             \
0123                 "D"(in_di),             \
0124                 "r"(bp) :               \
0125                 "memory", "cc");            \
0126 })
0127 
0128 
0129 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,   \
0130                        flags, magic, bp,        \
0131                        eax, ebx, ecx, edx, si, di)  \
0132 ({                          \
0133         asm volatile ("push %%rbp;"         \
0134                 "mov %12, %%rbp;"           \
0135                 VMWARE_HYPERCALL_HB_IN          \
0136                 "pop %%rbp" :               \
0137                 "=a"(eax),              \
0138                 "=b"(ebx),              \
0139                 "=c"(ecx),              \
0140                 "=d"(edx),              \
0141                 "=S"(si),               \
0142                 "=D"(di) :              \
0143                 "a"(magic),             \
0144                 "b"(cmd),               \
0145                 "c"(in_ecx),                \
0146                 "d"(flags),             \
0147                 "S"(in_si),             \
0148                 "D"(in_di),             \
0149                 "r"(bp) :               \
0150                 "memory", "cc");            \
0151 })
0152 
0153 #elif defined(__i386__)
0154 
0155 /*
0156  * In the 32-bit version of this macro, we store bp in a memory location
0157  * because we've ran out of registers.
0158  * Now we can't reference that memory location while we've modified
0159  * %esp or %ebp, so we first push it on the stack, just before we push
0160  * %ebp, and then when we need it we read it from the stack where we
0161  * just pushed it.
0162  */
0163 #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,  \
0164                         flags, magic, bp,       \
0165                         eax, ebx, ecx, edx, si, di) \
0166 ({                          \
0167         asm volatile ("push %12;"           \
0168                 "push %%ebp;"               \
0169                 "mov 0x04(%%esp), %%ebp;"       \
0170                 VMWARE_HYPERCALL_HB_OUT         \
0171                 "pop %%ebp;"                \
0172                 "add $0x04, %%esp;" :           \
0173                 "=a"(eax),              \
0174                 "=b"(ebx),              \
0175                 "=c"(ecx),              \
0176                 "=d"(edx),              \
0177                 "=S"(si),               \
0178                 "=D"(di) :              \
0179                 "a"(magic),             \
0180                 "b"(cmd),               \
0181                 "c"(in_ecx),                \
0182                 "d"(flags),             \
0183                 "S"(in_si),             \
0184                 "D"(in_di),             \
0185                 "m"(bp) :               \
0186                 "memory", "cc");            \
0187 })
0188 
0189 
0190 #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,   \
0191                        flags, magic, bp,        \
0192                        eax, ebx, ecx, edx, si, di)  \
0193 ({                          \
0194         asm volatile ("push %12;"           \
0195                 "push %%ebp;"               \
0196                 "mov 0x04(%%esp), %%ebp;"       \
0197                 VMWARE_HYPERCALL_HB_IN          \
0198                 "pop %%ebp;"                \
0199                 "add $0x04, %%esp;" :           \
0200                 "=a"(eax),              \
0201                 "=b"(ebx),              \
0202                 "=c"(ecx),              \
0203                 "=d"(edx),              \
0204                 "=S"(si),               \
0205                 "=D"(di) :              \
0206                 "a"(magic),             \
0207                 "b"(cmd),               \
0208                 "c"(in_ecx),                \
0209                 "d"(flags),             \
0210                 "S"(in_si),             \
0211                 "D"(in_di),             \
0212                 "m"(bp) :               \
0213                 "memory", "cc");            \
0214 })
0215 #endif /* defined(__i386__) */
0216 
0217 #endif /* defined(__i386__) || defined(__x86_64__) */
0218 
0219 #endif /* _VMWGFX_MSG_X86_H */