virtio_gpu.h 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316
  1. /*
  2. * Virtio GPU Device
  3. *
  4. * Copyright Red Hat, Inc. 2013-2014
  5. *
  6. * Authors:
  7. * Dave Airlie <airlied@redhat.com>
  8. * Gerd Hoffmann <kraxel@redhat.com>
  9. *
  10. * This header is BSD licensed so anyone can use the definitions
  11. * to implement compatible drivers/servers:
  12. *
  13. * Redistribution and use in source and binary forms, with or without
  14. * modification, are permitted provided that the following conditions
  15. * are met:
  16. * 1. Redistributions of source code must retain the above copyright
  17. * notice, this list of conditions and the following disclaimer.
  18. * 2. Redistributions in binary form must reproduce the above copyright
  19. * notice, this list of conditions and the following disclaimer in the
  20. * documentation and/or other materials provided with the distribution.
  21. * 3. Neither the name of IBM nor the names of its contributors
  22. * may be used to endorse or promote products derived from this software
  23. * without specific prior written permission.
  24. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  25. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  26. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  27. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL IBM OR
  28. * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  29. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  30. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
  31. * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
  32. * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  33. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
  34. * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  35. * SUCH DAMAGE.
  36. */
  37. #ifndef VIRTIO_GPU_HW_H
  38. #define VIRTIO_GPU_HW_H
  39. #include <linux/types.h>
  40. #define VIRTIO_GPU_F_VIRGL 0
  41. enum virtio_gpu_ctrl_type {
  42. VIRTIO_GPU_UNDEFINED = 0,
  43. /* 2d commands */
  44. VIRTIO_GPU_CMD_GET_DISPLAY_INFO = 0x0100,
  45. VIRTIO_GPU_CMD_RESOURCE_CREATE_2D,
  46. VIRTIO_GPU_CMD_RESOURCE_UNREF,
  47. VIRTIO_GPU_CMD_SET_SCANOUT,
  48. VIRTIO_GPU_CMD_RESOURCE_FLUSH,
  49. VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D,
  50. VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING,
  51. VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING,
  52. VIRTIO_GPU_CMD_GET_CAPSET_INFO,
  53. VIRTIO_GPU_CMD_GET_CAPSET,
  54. /* 3d commands */
  55. VIRTIO_GPU_CMD_CTX_CREATE = 0x0200,
  56. VIRTIO_GPU_CMD_CTX_DESTROY,
  57. VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE,
  58. VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE,
  59. VIRTIO_GPU_CMD_RESOURCE_CREATE_3D,
  60. VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D,
  61. VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D,
  62. VIRTIO_GPU_CMD_SUBMIT_3D,
  63. /* cursor commands */
  64. VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
  65. VIRTIO_GPU_CMD_MOVE_CURSOR,
  66. /* success responses */
  67. VIRTIO_GPU_RESP_OK_NODATA = 0x1100,
  68. VIRTIO_GPU_RESP_OK_DISPLAY_INFO,
  69. VIRTIO_GPU_RESP_OK_CAPSET_INFO,
  70. VIRTIO_GPU_RESP_OK_CAPSET,
  71. /* error responses */
  72. VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
  73. VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY,
  74. VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID,
  75. VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID,
  76. VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID,
  77. VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER,
  78. };
  79. #define VIRTIO_GPU_FLAG_FENCE (1 << 0)
  80. struct virtio_gpu_ctrl_hdr {
  81. __le32 type;
  82. __le32 flags;
  83. __le64 fence_id;
  84. __le32 ctx_id;
  85. __le32 padding;
  86. };
  87. /* data passed in the cursor vq */
  88. struct virtio_gpu_cursor_pos {
  89. __le32 scanout_id;
  90. __le32 x;
  91. __le32 y;
  92. __le32 padding;
  93. };
  94. /* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */
  95. struct virtio_gpu_update_cursor {
  96. struct virtio_gpu_ctrl_hdr hdr;
  97. struct virtio_gpu_cursor_pos pos; /* update & move */
  98. __le32 resource_id; /* update only */
  99. __le32 hot_x; /* update only */
  100. __le32 hot_y; /* update only */
  101. __le32 padding;
  102. };
  103. /* data passed in the control vq, 2d related */
  104. struct virtio_gpu_rect {
  105. __le32 x;
  106. __le32 y;
  107. __le32 width;
  108. __le32 height;
  109. };
  110. /* VIRTIO_GPU_CMD_RESOURCE_UNREF */
  111. struct virtio_gpu_resource_unref {
  112. struct virtio_gpu_ctrl_hdr hdr;
  113. __le32 resource_id;
  114. __le32 padding;
  115. };
  116. /* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */
  117. struct virtio_gpu_resource_create_2d {
  118. struct virtio_gpu_ctrl_hdr hdr;
  119. __le32 resource_id;
  120. __le32 format;
  121. __le32 width;
  122. __le32 height;
  123. };
  124. /* VIRTIO_GPU_CMD_SET_SCANOUT */
  125. struct virtio_gpu_set_scanout {
  126. struct virtio_gpu_ctrl_hdr hdr;
  127. struct virtio_gpu_rect r;
  128. __le32 scanout_id;
  129. __le32 resource_id;
  130. };
  131. /* VIRTIO_GPU_CMD_RESOURCE_FLUSH */
  132. struct virtio_gpu_resource_flush {
  133. struct virtio_gpu_ctrl_hdr hdr;
  134. struct virtio_gpu_rect r;
  135. __le32 resource_id;
  136. __le32 padding;
  137. };
  138. /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */
  139. struct virtio_gpu_transfer_to_host_2d {
  140. struct virtio_gpu_ctrl_hdr hdr;
  141. struct virtio_gpu_rect r;
  142. __le64 offset;
  143. __le32 resource_id;
  144. __le32 padding;
  145. };
  146. struct virtio_gpu_mem_entry {
  147. __le64 addr;
  148. __le32 length;
  149. __le32 padding;
  150. };
  151. /* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */
  152. struct virtio_gpu_resource_attach_backing {
  153. struct virtio_gpu_ctrl_hdr hdr;
  154. __le32 resource_id;
  155. __le32 nr_entries;
  156. };
  157. /* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */
  158. struct virtio_gpu_resource_detach_backing {
  159. struct virtio_gpu_ctrl_hdr hdr;
  160. __le32 resource_id;
  161. __le32 padding;
  162. };
  163. /* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */
  164. #define VIRTIO_GPU_MAX_SCANOUTS 16
  165. struct virtio_gpu_resp_display_info {
  166. struct virtio_gpu_ctrl_hdr hdr;
  167. struct virtio_gpu_display_one {
  168. struct virtio_gpu_rect r;
  169. __le32 enabled;
  170. __le32 flags;
  171. } pmodes[VIRTIO_GPU_MAX_SCANOUTS];
  172. };
  173. /* data passed in the control vq, 3d related */
  174. struct virtio_gpu_box {
  175. __le32 x, y, z;
  176. __le32 w, h, d;
  177. };
  178. /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D */
  179. struct virtio_gpu_transfer_host_3d {
  180. struct virtio_gpu_ctrl_hdr hdr;
  181. struct virtio_gpu_box box;
  182. __le64 offset;
  183. __le32 resource_id;
  184. __le32 level;
  185. __le32 stride;
  186. __le32 layer_stride;
  187. };
  188. /* VIRTIO_GPU_CMD_RESOURCE_CREATE_3D */
  189. #define VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP (1 << 0)
  190. struct virtio_gpu_resource_create_3d {
  191. struct virtio_gpu_ctrl_hdr hdr;
  192. __le32 resource_id;
  193. __le32 target;
  194. __le32 format;
  195. __le32 bind;
  196. __le32 width;
  197. __le32 height;
  198. __le32 depth;
  199. __le32 array_size;
  200. __le32 last_level;
  201. __le32 nr_samples;
  202. __le32 flags;
  203. __le32 padding;
  204. };
  205. /* VIRTIO_GPU_CMD_CTX_CREATE */
  206. struct virtio_gpu_ctx_create {
  207. struct virtio_gpu_ctrl_hdr hdr;
  208. __le32 nlen;
  209. __le32 padding;
  210. char debug_name[64];
  211. };
  212. /* VIRTIO_GPU_CMD_CTX_DESTROY */
  213. struct virtio_gpu_ctx_destroy {
  214. struct virtio_gpu_ctrl_hdr hdr;
  215. };
  216. /* VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE */
  217. struct virtio_gpu_ctx_resource {
  218. struct virtio_gpu_ctrl_hdr hdr;
  219. __le32 resource_id;
  220. __le32 padding;
  221. };
  222. /* VIRTIO_GPU_CMD_SUBMIT_3D */
  223. struct virtio_gpu_cmd_submit {
  224. struct virtio_gpu_ctrl_hdr hdr;
  225. __le32 size;
  226. __le32 padding;
  227. };
  228. #define VIRTIO_GPU_CAPSET_VIRGL 1
  229. /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */
  230. struct virtio_gpu_get_capset_info {
  231. struct virtio_gpu_ctrl_hdr hdr;
  232. __le32 capset_index;
  233. __le32 padding;
  234. };
  235. /* VIRTIO_GPU_RESP_OK_CAPSET_INFO */
  236. struct virtio_gpu_resp_capset_info {
  237. struct virtio_gpu_ctrl_hdr hdr;
  238. __le32 capset_id;
  239. __le32 capset_max_version;
  240. __le32 capset_max_size;
  241. __le32 padding;
  242. };
  243. /* VIRTIO_GPU_CMD_GET_CAPSET */
  244. struct virtio_gpu_get_capset {
  245. struct virtio_gpu_ctrl_hdr hdr;
  246. __le32 capset_id;
  247. __le32 capset_version;
  248. };
  249. /* VIRTIO_GPU_RESP_OK_CAPSET */
  250. struct virtio_gpu_resp_capset {
  251. struct virtio_gpu_ctrl_hdr hdr;
  252. uint8_t capset_data[];
  253. };
  254. #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0)
  255. struct virtio_gpu_config {
  256. __u32 events_read;
  257. __u32 events_clear;
  258. __u32 num_scanouts;
  259. __u32 num_capsets;
  260. };
  261. /* simple formats for fbcon/X use */
  262. enum virtio_gpu_formats {
  263. VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM = 1,
  264. VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM = 2,
  265. VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM = 3,
  266. VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM = 4,
  267. VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM = 67,
  268. VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM = 68,
  269. VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM = 121,
  270. VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM = 134,
  271. };
  272. #endif