vmwgfx_msg.h 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. /*
  2. * Copyright (C) 2016, VMware, Inc.
  3. *
  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.
  8. *
  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
  13. * details.
  14. *
  15. * Based on code from vmware.c and vmmouse.c.
  16. * Author:
  17. * Sinclair Yeh <syeh@vmware.com>
  18. */
  19. #ifndef _VMWGFX_MSG_H
  20. #define _VMWGFX_MSG_H
  21. /**
  22. * Hypervisor-specific bi-directional communication channel. Should never
  23. * execute on bare metal hardware. The caller must make sure to check for
  24. * supported hypervisor before using these macros.
  25. *
  26. * The last two parameters are both input and output and must be initialized.
  27. *
  28. * @cmd: [IN] Message Cmd
  29. * @in_ebx: [IN] Message Len, through EBX
  30. * @in_si: [IN] Input argument through SI, set to 0 if not used
  31. * @in_di: [IN] Input argument through DI, set ot 0 if not used
  32. * @port_num: [IN] port number + [channel id]
  33. * @magic: [IN] hypervisor magic value
  34. * @eax: [OUT] value of EAX register
  35. * @ebx: [OUT] e.g. status from an HB message status command
  36. * @ecx: [OUT] e.g. status from a non-HB message status command
  37. * @edx: [OUT] e.g. channel id
  38. * @si: [OUT]
  39. * @di: [OUT]
  40. */
  41. #define VMW_PORT(cmd, in_ebx, in_si, in_di, \
  42. port_num, magic, \
  43. eax, ebx, ecx, edx, si, di) \
  44. ({ \
  45. asm volatile ("inl %%dx, %%eax;" : \
  46. "=a"(eax), \
  47. "=b"(ebx), \
  48. "=c"(ecx), \
  49. "=d"(edx), \
  50. "=S"(si), \
  51. "=D"(di) : \
  52. "a"(magic), \
  53. "b"(in_ebx), \
  54. "c"(cmd), \
  55. "d"(port_num), \
  56. "S"(in_si), \
  57. "D"(in_di) : \
  58. "memory"); \
  59. })
  60. /**
  61. * Hypervisor-specific bi-directional communication channel. Should never
  62. * execute on bare metal hardware. The caller must make sure to check for
  63. * supported hypervisor before using these macros.
  64. *
  65. * The last 3 parameters are both input and output and must be initialized.
  66. *
  67. * @cmd: [IN] Message Cmd
  68. * @in_ecx: [IN] Message Len, through ECX
  69. * @in_si: [IN] Input argument through SI, set to 0 if not used
  70. * @in_di: [IN] Input argument through DI, set to 0 if not used
  71. * @port_num: [IN] port number + [channel id]
  72. * @magic: [IN] hypervisor magic value
  73. * @bp: [IN]
  74. * @eax: [OUT] value of EAX register
  75. * @ebx: [OUT] e.g. status from an HB message status command
  76. * @ecx: [OUT] e.g. status from a non-HB message status command
  77. * @edx: [OUT] e.g. channel id
  78. * @si: [OUT]
  79. * @di: [OUT]
  80. */
  81. #ifdef __x86_64__
  82. #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
  83. port_num, magic, bp, \
  84. eax, ebx, ecx, edx, si, di) \
  85. ({ \
  86. asm volatile ("push %%rbp;" \
  87. "mov %12, %%rbp;" \
  88. "rep outsb;" \
  89. "pop %%rbp;" : \
  90. "=a"(eax), \
  91. "=b"(ebx), \
  92. "=c"(ecx), \
  93. "=d"(edx), \
  94. "=S"(si), \
  95. "=D"(di) : \
  96. "a"(magic), \
  97. "b"(cmd), \
  98. "c"(in_ecx), \
  99. "d"(port_num), \
  100. "S"(in_si), \
  101. "D"(in_di), \
  102. "r"(bp) : \
  103. "memory", "cc"); \
  104. })
  105. #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
  106. port_num, magic, bp, \
  107. eax, ebx, ecx, edx, si, di) \
  108. ({ \
  109. asm volatile ("push %%rbp;" \
  110. "mov %12, %%rbp;" \
  111. "rep insb;" \
  112. "pop %%rbp" : \
  113. "=a"(eax), \
  114. "=b"(ebx), \
  115. "=c"(ecx), \
  116. "=d"(edx), \
  117. "=S"(si), \
  118. "=D"(di) : \
  119. "a"(magic), \
  120. "b"(cmd), \
  121. "c"(in_ecx), \
  122. "d"(port_num), \
  123. "S"(in_si), \
  124. "D"(in_di), \
  125. "r"(bp) : \
  126. "memory", "cc"); \
  127. })
  128. #else
  129. /* In the 32-bit version of this macro, we use "m" because there is no
  130. * more register left for bp
  131. */
  132. #define VMW_PORT_HB_OUT(cmd, in_ecx, in_si, in_di, \
  133. port_num, magic, bp, \
  134. eax, ebx, ecx, edx, si, di) \
  135. ({ \
  136. asm volatile ("push %%ebp;" \
  137. "mov %12, %%ebp;" \
  138. "rep outsb;" \
  139. "pop %%ebp;" : \
  140. "=a"(eax), \
  141. "=b"(ebx), \
  142. "=c"(ecx), \
  143. "=d"(edx), \
  144. "=S"(si), \
  145. "=D"(di) : \
  146. "a"(magic), \
  147. "b"(cmd), \
  148. "c"(in_ecx), \
  149. "d"(port_num), \
  150. "S"(in_si), \
  151. "D"(in_di), \
  152. "m"(bp) : \
  153. "memory", "cc"); \
  154. })
  155. #define VMW_PORT_HB_IN(cmd, in_ecx, in_si, in_di, \
  156. port_num, magic, bp, \
  157. eax, ebx, ecx, edx, si, di) \
  158. ({ \
  159. asm volatile ("push %%ebp;" \
  160. "mov %12, %%ebp;" \
  161. "rep insb;" \
  162. "pop %%ebp" : \
  163. "=a"(eax), \
  164. "=b"(ebx), \
  165. "=c"(ecx), \
  166. "=d"(edx), \
  167. "=S"(si), \
  168. "=D"(di) : \
  169. "a"(magic), \
  170. "b"(cmd), \
  171. "c"(in_ecx), \
  172. "d"(port_num), \
  173. "S"(in_si), \
  174. "D"(in_di), \
  175. "m"(bp) : \
  176. "memory", "cc"); \
  177. })
  178. #endif /* #if __x86_64__ */
  179. #endif