vhost-user-gpu.rst 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. =======================
  2. Vhost-user-gpu Protocol
  3. =======================
  4. ..
  5. Licence: This work is licensed under the terms of the GNU GPL,
  6. version 2 or later. See the COPYING file in the top-level
  7. directory.
  8. .. contents:: Table of Contents
  9. Introduction
  10. ============
  11. The vhost-user-gpu protocol is aiming at sharing the rendering result
  12. of a virtio-gpu, done from a vhost-user back-end process to a vhost-user
  13. front-end process (such as QEMU). It bears a resemblance to a display
  14. server protocol, if you consider QEMU as the display server and the
  15. back-end as the client, but in a very limited way. Typically, it will
  16. work by setting a scanout/display configuration, before sending flush
  17. events for the display updates. It will also update the cursor shape
  18. and position.
  19. The protocol is sent over a UNIX domain stream socket, since it uses
  20. socket ancillary data to share opened file descriptors (DMABUF fds or
  21. shared memory). The socket is usually obtained via
  22. ``VHOST_USER_GPU_SET_SOCKET``.
  23. Requests are sent by the *back-end*, and the optional replies by the
  24. *front-end*.
  25. Wire format
  26. ===========
  27. Unless specified differently, numbers are in the machine native byte
  28. order.
  29. A vhost-user-gpu message (request and reply) consists of 3 header
  30. fields and a payload.
  31. +---------+-------+------+---------+
  32. | request | flags | size | payload |
  33. +---------+-------+------+---------+
  34. Header
  35. ------
  36. :request: ``u32``, type of the request
  37. :flags: ``u32``, 32-bit bit field:
  38. - Bit 2 is the reply flag - needs to be set on each reply
  39. :size: ``u32``, size of the payload
  40. Payload types
  41. -------------
  42. Depending on the request type, **payload** can be:
  43. VhostUserGpuCursorPos
  44. ^^^^^^^^^^^^^^^^^^^^^
  45. +------------+---+---+
  46. | scanout-id | x | y |
  47. +------------+---+---+
  48. :scanout-id: ``u32``, the scanout where the cursor is located
  49. :x/y: ``u32``, the cursor position
  50. VhostUserGpuCursorUpdate
  51. ^^^^^^^^^^^^^^^^^^^^^^^^
  52. +-----+-------+-------+--------+
  53. | pos | hot_x | hot_y | cursor |
  54. +-----+-------+-------+--------+
  55. :pos: a ``VhostUserGpuCursorPos``, the cursor location
  56. :hot_x/hot_y: ``u32``, the cursor hot location
  57. :cursor: ``[u32; 64 * 64]``, 64x64 RGBA cursor data (PIXMAN_a8r8g8b8 format)
  58. VhostUserGpuScanout
  59. ^^^^^^^^^^^^^^^^^^^
  60. +------------+---+---+
  61. | scanout-id | w | h |
  62. +------------+---+---+
  63. :scanout-id: ``u32``, the scanout configuration to set
  64. :w/h: ``u32``, the scanout width/height size
  65. VhostUserGpuUpdate
  66. ^^^^^^^^^^^^^^^^^^
  67. +------------+---+---+---+---+------+
  68. | scanout-id | x | y | w | h | data |
  69. +------------+---+---+---+---+------+
  70. :scanout-id: ``u32``, the scanout content to update
  71. :x/y/w/h: ``u32``, region of the update
  72. :data: RGB data (PIXMAN_x8r8g8b8 format)
  73. VhostUserGpuDMABUFScanout
  74. ^^^^^^^^^^^^^^^^^^^^^^^^^
  75. +------------+---+---+---+---+-----+-----+--------+-------+--------+
  76. | scanout-id | x | y | w | h | fdw | fwh | stride | flags | fourcc |
  77. +------------+---+---+---+---+-----+-----+--------+-------+--------+
  78. :scanout-id: ``u32``, the scanout configuration to set
  79. :x/y: ``u32``, the location of the scanout within the DMABUF
  80. :w/h: ``u32``, the scanout width/height size
  81. :fdw/fdh/stride/flags: ``u32``, the DMABUF width/height/stride/flags
  82. :fourcc: ``i32``, the DMABUF fourcc
  83. C structure
  84. -----------
  85. In QEMU the vhost-user-gpu message is implemented with the following struct:
  86. .. code:: c
  87. typedef struct VhostUserGpuMsg {
  88. uint32_t request; /* VhostUserGpuRequest */
  89. uint32_t flags;
  90. uint32_t size; /* the following payload size */
  91. union {
  92. VhostUserGpuCursorPos cursor_pos;
  93. VhostUserGpuCursorUpdate cursor_update;
  94. VhostUserGpuScanout scanout;
  95. VhostUserGpuUpdate update;
  96. VhostUserGpuDMABUFScanout dmabuf_scanout;
  97. struct virtio_gpu_resp_display_info display_info;
  98. uint64_t u64;
  99. } payload;
  100. } QEMU_PACKED VhostUserGpuMsg;
  101. Protocol features
  102. -----------------
  103. None yet.
  104. As the protocol may need to evolve, new messages and communication
  105. changes are negotiated thanks to preliminary
  106. ``VHOST_USER_GPU_GET_PROTOCOL_FEATURES`` and
  107. ``VHOST_USER_GPU_SET_PROTOCOL_FEATURES`` requests.
  108. Communication
  109. =============
  110. Message types
  111. -------------
  112. ``VHOST_USER_GPU_GET_PROTOCOL_FEATURES``
  113. :id: 1
  114. :request payload: N/A
  115. :reply payload: ``u64``
  116. Get the supported protocol features bitmask.
  117. ``VHOST_USER_GPU_SET_PROTOCOL_FEATURES``
  118. :id: 2
  119. :request payload: ``u64``
  120. :reply payload: N/A
  121. Enable protocol features using a bitmask.
  122. ``VHOST_USER_GPU_GET_DISPLAY_INFO``
  123. :id: 3
  124. :request payload: N/A
  125. :reply payload: ``struct virtio_gpu_resp_display_info`` (from virtio specification)
  126. Get the preferred display configuration.
  127. ``VHOST_USER_GPU_CURSOR_POS``
  128. :id: 4
  129. :request payload: ``VhostUserGpuCursorPos``
  130. :reply payload: N/A
  131. Set/show the cursor position.
  132. ``VHOST_USER_GPU_CURSOR_POS_HIDE``
  133. :id: 5
  134. :request payload: ``VhostUserGpuCursorPos``
  135. :reply payload: N/A
  136. Set/hide the cursor.
  137. ``VHOST_USER_GPU_CURSOR_UPDATE``
  138. :id: 6
  139. :request payload: ``VhostUserGpuCursorUpdate``
  140. :reply payload: N/A
  141. Update the cursor shape and location.
  142. ``VHOST_USER_GPU_SCANOUT``
  143. :id: 7
  144. :request payload: ``VhostUserGpuScanout``
  145. :reply payload: N/A
  146. Set the scanout resolution. To disable a scanout, the dimensions
  147. width/height are set to 0.
  148. ``VHOST_USER_GPU_UPDATE``
  149. :id: 8
  150. :request payload: ``VhostUserGpuUpdate``
  151. :reply payload: N/A
  152. Update the scanout content. The data payload contains the graphical bits.
  153. The display should be flushed and presented.
  154. ``VHOST_USER_GPU_DMABUF_SCANOUT``
  155. :id: 9
  156. :request payload: ``VhostUserGpuDMABUFScanout``
  157. :reply payload: N/A
  158. Set the scanout resolution/configuration, and share a DMABUF file
  159. descriptor for the scanout content, which is passed as ancillary
  160. data. To disable a scanout, the dimensions width/height are set
  161. to 0, there is no file descriptor passed.
  162. ``VHOST_USER_GPU_DMABUF_UPDATE``
  163. :id: 10
  164. :request payload: ``VhostUserGpuUpdate``
  165. :reply payload: empty payload
  166. The display should be flushed and presented according to updated
  167. region from ``VhostUserGpuUpdate``.
  168. Note: there is no data payload, since the scanout is shared thanks
  169. to DMABUF, that must have been set previously with
  170. ``VHOST_USER_GPU_DMABUF_SCANOUT``.