vhost-user-gpu.rst 6.2 KB

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