18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0+ OR MIT */
28c2ecf20Sopenharmony_ci/**************************************************************************
38c2ecf20Sopenharmony_ci *
48c2ecf20Sopenharmony_ci * Copyright 2016 VMware, Inc., Palo Alto, CA., USA
58c2ecf20Sopenharmony_ci *
68c2ecf20Sopenharmony_ci * Permission is hereby granted, free of charge, to any person obtaining a
78c2ecf20Sopenharmony_ci * copy of this software and associated documentation files (the
88c2ecf20Sopenharmony_ci * "Software"), to deal in the Software without restriction, including
98c2ecf20Sopenharmony_ci * without limitation the rights to use, copy, modify, merge, publish,
108c2ecf20Sopenharmony_ci * distribute, sub license, and/or sell copies of the Software, and to
118c2ecf20Sopenharmony_ci * permit persons to whom the Software is furnished to do so, subject to
128c2ecf20Sopenharmony_ci * the following conditions:
138c2ecf20Sopenharmony_ci *
148c2ecf20Sopenharmony_ci * The above copyright notice and this permission notice (including the
158c2ecf20Sopenharmony_ci * next paragraph) shall be included in all copies or substantial portions
168c2ecf20Sopenharmony_ci * of the Software.
178c2ecf20Sopenharmony_ci *
188c2ecf20Sopenharmony_ci * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
198c2ecf20Sopenharmony_ci * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
208c2ecf20Sopenharmony_ci * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL
218c2ecf20Sopenharmony_ci * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM,
228c2ecf20Sopenharmony_ci * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
238c2ecf20Sopenharmony_ci * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
248c2ecf20Sopenharmony_ci * USE OR OTHER DEALINGS IN THE SOFTWARE.
258c2ecf20Sopenharmony_ci *
268c2ecf20Sopenharmony_ci **************************************************************************
278c2ecf20Sopenharmony_ci *
288c2ecf20Sopenharmony_ci * Based on code from vmware.c and vmmouse.c.
298c2ecf20Sopenharmony_ci * Author:
308c2ecf20Sopenharmony_ci *   Sinclair Yeh <syeh@vmware.com>
318c2ecf20Sopenharmony_ci */
328c2ecf20Sopenharmony_ci#ifndef _VMWGFX_MSG_H
338c2ecf20Sopenharmony_ci#define _VMWGFX_MSG_H
348c2ecf20Sopenharmony_ci
358c2ecf20Sopenharmony_ci#include <asm/vmware.h>
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci/**
388c2ecf20Sopenharmony_ci * Hypervisor-specific bi-directional communication channel.  Should never
398c2ecf20Sopenharmony_ci * execute on bare metal hardware.  The caller must make sure to check for
408c2ecf20Sopenharmony_ci * supported hypervisor before using these macros.
418c2ecf20Sopenharmony_ci *
428c2ecf20Sopenharmony_ci * The last two parameters are both input and output and must be initialized.
438c2ecf20Sopenharmony_ci *
448c2ecf20Sopenharmony_ci * @cmd: [IN] Message Cmd
458c2ecf20Sopenharmony_ci * @in_ebx: [IN] Message Len, through EBX
468c2ecf20Sopenharmony_ci * @in_si: [IN] Input argument through SI, set to 0 if not used
478c2ecf20Sopenharmony_ci * @in_di: [IN] Input argument through DI, set ot 0 if not used
488c2ecf20Sopenharmony_ci * @flags: [IN] hypercall flags + [channel id]
498c2ecf20Sopenharmony_ci * @magic: [IN] hypervisor magic value
508c2ecf20Sopenharmony_ci * @eax: [OUT] value of EAX register
518c2ecf20Sopenharmony_ci * @ebx: [OUT] e.g. status from an HB message status command
528c2ecf20Sopenharmony_ci * @ecx: [OUT] e.g. status from a non-HB message status command
538c2ecf20Sopenharmony_ci * @edx: [OUT] e.g. channel id
548c2ecf20Sopenharmony_ci * @si:  [OUT]
558c2ecf20Sopenharmony_ci * @di:  [OUT]
568c2ecf20Sopenharmony_ci */
578c2ecf20Sopenharmony_ci#define VMW_PORT(cmd, in_ebx, in_si, in_di,	\
588c2ecf20Sopenharmony_ci		 flags, magic,		\
598c2ecf20Sopenharmony_ci		 eax, ebx, ecx, edx, si, di)	\
608c2ecf20Sopenharmony_ci({						\
618c2ecf20Sopenharmony_ci	asm volatile (VMWARE_HYPERCALL :	\
628c2ecf20Sopenharmony_ci		"=a"(eax),			\
638c2ecf20Sopenharmony_ci		"=b"(ebx),			\
648c2ecf20Sopenharmony_ci		"=c"(ecx),			\
658c2ecf20Sopenharmony_ci		"=d"(edx),			\
668c2ecf20Sopenharmony_ci		"=S"(si),			\
678c2ecf20Sopenharmony_ci		"=D"(di) :			\
688c2ecf20Sopenharmony_ci		"a"(magic),			\
698c2ecf20Sopenharmony_ci		"b"(in_ebx),			\
708c2ecf20Sopenharmony_ci		"c"(cmd),			\
718c2ecf20Sopenharmony_ci		"d"(flags),			\
728c2ecf20Sopenharmony_ci		"S"(in_si),			\
738c2ecf20Sopenharmony_ci		"D"(in_di) :			\
748c2ecf20Sopenharmony_ci		"memory");			\
758c2ecf20Sopenharmony_ci})
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci
788c2ecf20Sopenharmony_ci/**
798c2ecf20Sopenharmony_ci * Hypervisor-specific bi-directional communication channel.  Should never
808c2ecf20Sopenharmony_ci * execute on bare metal hardware.  The caller must make sure to check for
818c2ecf20Sopenharmony_ci * supported hypervisor before using these macros.
828c2ecf20Sopenharmony_ci *
838c2ecf20Sopenharmony_ci * The last 3 parameters are both input and output and must be initialized.
848c2ecf20Sopenharmony_ci *
858c2ecf20Sopenharmony_ci * @cmd: [IN] Message Cmd
868c2ecf20Sopenharmony_ci * @in_ecx: [IN] Message Len, through ECX
878c2ecf20Sopenharmony_ci * @in_si: [IN] Input argument through SI, set to 0 if not used
888c2ecf20Sopenharmony_ci * @in_di: [IN] Input argument through DI, set to 0 if not used
898c2ecf20Sopenharmony_ci * @flags: [IN] hypercall flags + [channel id]
908c2ecf20Sopenharmony_ci * @magic: [IN] hypervisor magic value
918c2ecf20Sopenharmony_ci * @bp:  [IN]
928c2ecf20Sopenharmony_ci * @eax: [OUT] value of EAX register
938c2ecf20Sopenharmony_ci * @ebx: [OUT] e.g. status from an HB message status command
948c2ecf20Sopenharmony_ci * @ecx: [OUT] e.g. status from a non-HB message status command
958c2ecf20Sopenharmony_ci * @edx: [OUT] e.g. channel id
968c2ecf20Sopenharmony_ci * @si:  [OUT]
978c2ecf20Sopenharmony_ci * @di:  [OUT]
988c2ecf20Sopenharmony_ci */
998c2ecf20Sopenharmony_ci#ifdef __x86_64__
1008c2ecf20Sopenharmony_ci
1018c2ecf20Sopenharmony_ci#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,	\
1028c2ecf20Sopenharmony_ci			flags, magic, bp,		\
1038c2ecf20Sopenharmony_ci			eax, ebx, ecx, edx, si, di)	\
1048c2ecf20Sopenharmony_ci({							\
1058c2ecf20Sopenharmony_ci	asm volatile ("push %%rbp;"			\
1068c2ecf20Sopenharmony_ci		"mov %12, %%rbp;"			\
1078c2ecf20Sopenharmony_ci		VMWARE_HYPERCALL_HB_OUT			\
1088c2ecf20Sopenharmony_ci		"pop %%rbp;" :				\
1098c2ecf20Sopenharmony_ci		"=a"(eax),				\
1108c2ecf20Sopenharmony_ci		"=b"(ebx),				\
1118c2ecf20Sopenharmony_ci		"=c"(ecx),				\
1128c2ecf20Sopenharmony_ci		"=d"(edx),				\
1138c2ecf20Sopenharmony_ci		"=S"(si),				\
1148c2ecf20Sopenharmony_ci		"=D"(di) :				\
1158c2ecf20Sopenharmony_ci		"a"(magic),				\
1168c2ecf20Sopenharmony_ci		"b"(cmd),				\
1178c2ecf20Sopenharmony_ci		"c"(in_ecx),				\
1188c2ecf20Sopenharmony_ci		"d"(flags),				\
1198c2ecf20Sopenharmony_ci		"S"(in_si),				\
1208c2ecf20Sopenharmony_ci		"D"(in_di),				\
1218c2ecf20Sopenharmony_ci		"r"(bp) :				\
1228c2ecf20Sopenharmony_ci		"memory", "cc");			\
1238c2ecf20Sopenharmony_ci})
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci
1268c2ecf20Sopenharmony_ci#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,	\
1278c2ecf20Sopenharmony_ci		       flags, magic, bp,		\
1288c2ecf20Sopenharmony_ci		       eax, ebx, ecx, edx, si, di)	\
1298c2ecf20Sopenharmony_ci({							\
1308c2ecf20Sopenharmony_ci	asm volatile ("push %%rbp;"			\
1318c2ecf20Sopenharmony_ci		"mov %12, %%rbp;"			\
1328c2ecf20Sopenharmony_ci		VMWARE_HYPERCALL_HB_IN			\
1338c2ecf20Sopenharmony_ci		"pop %%rbp" :				\
1348c2ecf20Sopenharmony_ci		"=a"(eax),				\
1358c2ecf20Sopenharmony_ci		"=b"(ebx),				\
1368c2ecf20Sopenharmony_ci		"=c"(ecx),				\
1378c2ecf20Sopenharmony_ci		"=d"(edx),				\
1388c2ecf20Sopenharmony_ci		"=S"(si),				\
1398c2ecf20Sopenharmony_ci		"=D"(di) :				\
1408c2ecf20Sopenharmony_ci		"a"(magic),				\
1418c2ecf20Sopenharmony_ci		"b"(cmd),				\
1428c2ecf20Sopenharmony_ci		"c"(in_ecx),				\
1438c2ecf20Sopenharmony_ci		"d"(flags),				\
1448c2ecf20Sopenharmony_ci		"S"(in_si),				\
1458c2ecf20Sopenharmony_ci		"D"(in_di),				\
1468c2ecf20Sopenharmony_ci		"r"(bp) :				\
1478c2ecf20Sopenharmony_ci		"memory", "cc");			\
1488c2ecf20Sopenharmony_ci})
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ci#else
1518c2ecf20Sopenharmony_ci
1528c2ecf20Sopenharmony_ci/*
1538c2ecf20Sopenharmony_ci * In the 32-bit version of this macro, we store bp in a memory location
1548c2ecf20Sopenharmony_ci * because we've ran out of registers.
1558c2ecf20Sopenharmony_ci * Now we can't reference that memory location while we've modified
1568c2ecf20Sopenharmony_ci * %esp or %ebp, so we first push it on the stack, just before we push
1578c2ecf20Sopenharmony_ci * %ebp, and then when we need it we read it from the stack where we
1588c2ecf20Sopenharmony_ci * just pushed it.
1598c2ecf20Sopenharmony_ci */
1608c2ecf20Sopenharmony_ci#define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di,	\
1618c2ecf20Sopenharmony_ci			flags, magic, bp,		\
1628c2ecf20Sopenharmony_ci			eax, ebx, ecx, edx, si, di)	\
1638c2ecf20Sopenharmony_ci({							\
1648c2ecf20Sopenharmony_ci	asm volatile ("push %12;"			\
1658c2ecf20Sopenharmony_ci		"push %%ebp;"				\
1668c2ecf20Sopenharmony_ci		"mov 0x04(%%esp), %%ebp;"		\
1678c2ecf20Sopenharmony_ci		VMWARE_HYPERCALL_HB_OUT			\
1688c2ecf20Sopenharmony_ci		"pop %%ebp;"				\
1698c2ecf20Sopenharmony_ci		"add $0x04, %%esp;" :			\
1708c2ecf20Sopenharmony_ci		"=a"(eax),				\
1718c2ecf20Sopenharmony_ci		"=b"(ebx),				\
1728c2ecf20Sopenharmony_ci		"=c"(ecx),				\
1738c2ecf20Sopenharmony_ci		"=d"(edx),				\
1748c2ecf20Sopenharmony_ci		"=S"(si),				\
1758c2ecf20Sopenharmony_ci		"=D"(di) :				\
1768c2ecf20Sopenharmony_ci		"a"(magic),				\
1778c2ecf20Sopenharmony_ci		"b"(cmd),				\
1788c2ecf20Sopenharmony_ci		"c"(in_ecx),				\
1798c2ecf20Sopenharmony_ci		"d"(flags),				\
1808c2ecf20Sopenharmony_ci		"S"(in_si),				\
1818c2ecf20Sopenharmony_ci		"D"(in_di),				\
1828c2ecf20Sopenharmony_ci		"m"(bp) :				\
1838c2ecf20Sopenharmony_ci		"memory", "cc");			\
1848c2ecf20Sopenharmony_ci})
1858c2ecf20Sopenharmony_ci
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci#define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di,	\
1888c2ecf20Sopenharmony_ci		       flags, magic, bp,		\
1898c2ecf20Sopenharmony_ci		       eax, ebx, ecx, edx, si, di)	\
1908c2ecf20Sopenharmony_ci({							\
1918c2ecf20Sopenharmony_ci	asm volatile ("push %12;"			\
1928c2ecf20Sopenharmony_ci		"push %%ebp;"				\
1938c2ecf20Sopenharmony_ci		"mov 0x04(%%esp), %%ebp;"		\
1948c2ecf20Sopenharmony_ci		VMWARE_HYPERCALL_HB_IN			\
1958c2ecf20Sopenharmony_ci		"pop %%ebp;"				\
1968c2ecf20Sopenharmony_ci		"add $0x04, %%esp;" :			\
1978c2ecf20Sopenharmony_ci		"=a"(eax),				\
1988c2ecf20Sopenharmony_ci		"=b"(ebx),				\
1998c2ecf20Sopenharmony_ci		"=c"(ecx),				\
2008c2ecf20Sopenharmony_ci		"=d"(edx),				\
2018c2ecf20Sopenharmony_ci		"=S"(si),				\
2028c2ecf20Sopenharmony_ci		"=D"(di) :				\
2038c2ecf20Sopenharmony_ci		"a"(magic),				\
2048c2ecf20Sopenharmony_ci		"b"(cmd),				\
2058c2ecf20Sopenharmony_ci		"c"(in_ecx),				\
2068c2ecf20Sopenharmony_ci		"d"(flags),				\
2078c2ecf20Sopenharmony_ci		"S"(in_si),				\
2088c2ecf20Sopenharmony_ci		"D"(in_di),				\
2098c2ecf20Sopenharmony_ci		"m"(bp) :				\
2108c2ecf20Sopenharmony_ci		"memory", "cc");			\
2118c2ecf20Sopenharmony_ci})
2128c2ecf20Sopenharmony_ci#endif /* #if __x86_64__ */
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci#endif
215