vmwgfx_msg.h 5.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  1. /* SPDX-License-Identifier: GPL-2.0+ OR MIT */
  2. /**************************************************************************
  3. *
  4. * Copyright 2016 VMware, Inc., Palo Alto, CA., USA
  5. *
  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:
  13. *
  14. * The above copyright notice and this permission notice (including the
  15. * next paragraph) shall be included in all copies or substantial portions
  16. * of the Software.
  17. *
  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.
  25. *
  26. **************************************************************************
  27. *
  28. * Based on code from vmware.c and vmmouse.c.
  29. * Author:
  30. * Sinclair Yeh <syeh@vmware.com>
  31. */
  32. #ifndef _VMWGFX_MSG_H
  33. #define _VMWGFX_MSG_H
  34. #include <asm/vmware.h>
  35. /**
  36. * Hypervisor-specific bi-directional communication channel. Should never
  37. * execute on bare metal hardware. The caller must make sure to check for
  38. * supported hypervisor before using these macros.
  39. *
  40. * The last two parameters are both input and output and must be initialized.
  41. *
  42. * @cmd: [IN] Message Cmd
  43. * @in_ebx: [IN] Message Len, through EBX
  44. * @in_si: [IN] Input argument through SI, set to 0 if not used
  45. * @in_di: [IN] Input argument through DI, set ot 0 if not used
  46. * @flags: [IN] hypercall flags + [channel id]
  47. * @magic: [IN] hypervisor magic value
  48. * @eax: [OUT] value of EAX register
  49. * @ebx: [OUT] e.g. status from an HB message status command
  50. * @ecx: [OUT] e.g. status from a non-HB message status command
  51. * @edx: [OUT] e.g. channel id
  52. * @si: [OUT]
  53. * @di: [OUT]
  54. */
  55. #define VMW_PORT(cmd, in_ebx, in_si, in_di, \
  56. flags, magic, \
  57. eax, ebx, ecx, edx, si, di) \
  58. ({ \
  59. asm volatile (VMWARE_HYPERCALL : \
  60. "=a"(eax), \
  61. "=b"(ebx), \
  62. "=c"(ecx), \
  63. "=d"(edx), \
  64. "=S"(si), \
  65. "=D"(di) : \
  66. "a"(magic), \
  67. "b"(in_ebx), \
  68. "c"(cmd), \
  69. "d"(flags), \
  70. "S"(in_si), \
  71. "D"(in_di) : \
  72. "memory"); \
  73. })
  74. /**
  75. * Hypervisor-specific bi-directional communication channel. Should never
  76. * execute on bare metal hardware. The caller must make sure to check for
  77. * supported hypervisor before using these macros.
  78. *
  79. * The last 3 parameters are both input and output and must be initialized.
  80. *
  81. * @cmd: [IN] Message Cmd
  82. * @in_ecx: [IN] Message Len, through ECX
  83. * @in_si: [IN] Input argument through SI, set to 0 if not used
  84. * @in_di: [IN] Input argument through DI, set to 0 if not used
  85. * @flags: [IN] hypercall flags + [channel id]
  86. * @magic: [IN] hypervisor magic value
  87. * @bp: [IN]
  88. * @eax: [OUT] value of EAX register
  89. * @ebx: [OUT] e.g. status from an HB message status command
  90. * @ecx: [OUT] e.g. status from a non-HB message status command
  91. * @edx: [OUT] e.g. channel id
  92. * @si: [OUT]
  93. * @di: [OUT]
  94. */
  95. #ifdef __x86_64__
  96. #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
  97. flags, magic, bp, \
  98. eax, ebx, ecx, edx, si, di) \
  99. ({ \
  100. asm volatile ("push %%rbp;" \
  101. "mov %12, %%rbp;" \
  102. VMWARE_HYPERCALL_HB_OUT \
  103. "pop %%rbp;" : \
  104. "=a"(eax), \
  105. "=b"(ebx), \
  106. "=c"(ecx), \
  107. "=d"(edx), \
  108. "=S"(si), \
  109. "=D"(di) : \
  110. "a"(magic), \
  111. "b"(cmd), \
  112. "c"(in_ecx), \
  113. "d"(flags), \
  114. "S"(in_si), \
  115. "D"(in_di), \
  116. "r"(bp) : \
  117. "memory", "cc"); \
  118. })
  119. #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
  120. flags, magic, bp, \
  121. eax, ebx, ecx, edx, si, di) \
  122. ({ \
  123. asm volatile ("push %%rbp;" \
  124. "mov %12, %%rbp;" \
  125. VMWARE_HYPERCALL_HB_IN \
  126. "pop %%rbp" : \
  127. "=a"(eax), \
  128. "=b"(ebx), \
  129. "=c"(ecx), \
  130. "=d"(edx), \
  131. "=S"(si), \
  132. "=D"(di) : \
  133. "a"(magic), \
  134. "b"(cmd), \
  135. "c"(in_ecx), \
  136. "d"(flags), \
  137. "S"(in_si), \
  138. "D"(in_di), \
  139. "r"(bp) : \
  140. "memory", "cc"); \
  141. })
  142. #else
  143. /*
  144. * In the 32-bit version of this macro, we store bp in a memory location
  145. * because we've ran out of registers.
  146. * Now we can't reference that memory location while we've modified
  147. * %esp or %ebp, so we first push it on the stack, just before we push
  148. * %ebp, and then when we need it we read it from the stack where we
  149. * just pushed it.
  150. */
  151. #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
  152. flags, magic, bp, \
  153. eax, ebx, ecx, edx, si, di) \
  154. ({ \
  155. asm volatile ("push %12;" \
  156. "push %%ebp;" \
  157. "mov 0x04(%%esp), %%ebp;" \
  158. VMWARE_HYPERCALL_HB_OUT \
  159. "pop %%ebp;" \
  160. "add $0x04, %%esp;" : \
  161. "=a"(eax), \
  162. "=b"(ebx), \
  163. "=c"(ecx), \
  164. "=d"(edx), \
  165. "=S"(si), \
  166. "=D"(di) : \
  167. "a"(magic), \
  168. "b"(cmd), \
  169. "c"(in_ecx), \
  170. "d"(flags), \
  171. "S"(in_si), \
  172. "D"(in_di), \
  173. "m"(bp) : \
  174. "memory", "cc"); \
  175. })
  176. #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
  177. flags, magic, bp, \
  178. eax, ebx, ecx, edx, si, di) \
  179. ({ \
  180. asm volatile ("push %12;" \
  181. "push %%ebp;" \
  182. "mov 0x04(%%esp), %%ebp;" \
  183. VMWARE_HYPERCALL_HB_IN \
  184. "pop %%ebp;" \
  185. "add $0x04, %%esp;" : \
  186. "=a"(eax), \
  187. "=b"(ebx), \
  188. "=c"(ecx), \
  189. "=d"(edx), \
  190. "=S"(si), \
  191. "=D"(di) : \
  192. "a"(magic), \
  193. "b"(cmd), \
  194. "c"(in_ecx), \
  195. "d"(flags), \
  196. "S"(in_si), \
  197. "D"(in_di), \
  198. "m"(bp) : \
  199. "memory", "cc"); \
  200. })
  201. #endif /* #if __x86_64__ */
  202. #endif