4 * Copyright Red Hat, Inc. 2013-2014
7 * Dave Airlie <airlied@redhat.com>
8 * Gerd Hoffmann <kraxel@redhat.com>
10 * This header is BSD licensed so anyone can use the definitions
11 * to implement compatible drivers/servers:
13 * Redistribution and use in source and binary forms, with or without
14 * modification, are permitted provided that the following conditions
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
38 #ifndef VIRTIO_GPU_HW_H
39 #define VIRTIO_GPU_HW_H
41 #include "standard-headers/linux/types.h"
44 * VIRTIO_GPU_CMD_CTX_*
47 #define VIRTIO_GPU_F_VIRGL 0
50 * VIRTIO_GPU_CMD_GET_EDID
52 #define VIRTIO_GPU_F_EDID 1
54 * VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID
56 #define VIRTIO_GPU_F_RESOURCE_UUID 2
59 * VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB
61 #define VIRTIO_GPU_F_RESOURCE_BLOB 3
63 * VIRTIO_GPU_CMD_CREATE_CONTEXT with
64 * context_init and multiple timelines
66 #define VIRTIO_GPU_F_CONTEXT_INIT 4
68 enum virtio_gpu_ctrl_type
{
69 VIRTIO_GPU_UNDEFINED
= 0,
72 VIRTIO_GPU_CMD_GET_DISPLAY_INFO
= 0x0100,
73 VIRTIO_GPU_CMD_RESOURCE_CREATE_2D
,
74 VIRTIO_GPU_CMD_RESOURCE_UNREF
,
75 VIRTIO_GPU_CMD_SET_SCANOUT
,
76 VIRTIO_GPU_CMD_RESOURCE_FLUSH
,
77 VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D
,
78 VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING
,
79 VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING
,
80 VIRTIO_GPU_CMD_GET_CAPSET_INFO
,
81 VIRTIO_GPU_CMD_GET_CAPSET
,
82 VIRTIO_GPU_CMD_GET_EDID
,
83 VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID
,
84 VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB
,
85 VIRTIO_GPU_CMD_SET_SCANOUT_BLOB
,
88 VIRTIO_GPU_CMD_CTX_CREATE
= 0x0200,
89 VIRTIO_GPU_CMD_CTX_DESTROY
,
90 VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE
,
91 VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE
,
92 VIRTIO_GPU_CMD_RESOURCE_CREATE_3D
,
93 VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D
,
94 VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D
,
95 VIRTIO_GPU_CMD_SUBMIT_3D
,
96 VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB
,
97 VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB
,
100 VIRTIO_GPU_CMD_UPDATE_CURSOR
= 0x0300,
101 VIRTIO_GPU_CMD_MOVE_CURSOR
,
103 /* success responses */
104 VIRTIO_GPU_RESP_OK_NODATA
= 0x1100,
105 VIRTIO_GPU_RESP_OK_DISPLAY_INFO
,
106 VIRTIO_GPU_RESP_OK_CAPSET_INFO
,
107 VIRTIO_GPU_RESP_OK_CAPSET
,
108 VIRTIO_GPU_RESP_OK_EDID
,
109 VIRTIO_GPU_RESP_OK_RESOURCE_UUID
,
110 VIRTIO_GPU_RESP_OK_MAP_INFO
,
112 /* error responses */
113 VIRTIO_GPU_RESP_ERR_UNSPEC
= 0x1200,
114 VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY
,
115 VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID
,
116 VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID
,
117 VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID
,
118 VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER
,
121 enum virtio_gpu_shm_id
{
122 VIRTIO_GPU_SHM_ID_UNDEFINED
= 0,
124 * VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB
125 * VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB
127 VIRTIO_GPU_SHM_ID_HOST_VISIBLE
= 1
130 #define VIRTIO_GPU_FLAG_FENCE (1 << 0)
132 * If the following flag is set, then ring_idx contains the index
133 * of the command ring that needs to used when creating the fence
135 #define VIRTIO_GPU_FLAG_INFO_RING_IDX (1 << 1)
137 struct virtio_gpu_ctrl_hdr
{
146 /* data passed in the cursor vq */
148 struct virtio_gpu_cursor_pos
{
155 /* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */
156 struct virtio_gpu_update_cursor
{
157 struct virtio_gpu_ctrl_hdr hdr
;
158 struct virtio_gpu_cursor_pos pos
; /* update & move */
159 uint32_t resource_id
; /* update only */
160 uint32_t hot_x
; /* update only */
161 uint32_t hot_y
; /* update only */
165 /* data passed in the control vq, 2d related */
167 struct virtio_gpu_rect
{
174 /* VIRTIO_GPU_CMD_RESOURCE_UNREF */
175 struct virtio_gpu_resource_unref
{
176 struct virtio_gpu_ctrl_hdr hdr
;
177 uint32_t resource_id
;
181 /* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */
182 struct virtio_gpu_resource_create_2d
{
183 struct virtio_gpu_ctrl_hdr hdr
;
184 uint32_t resource_id
;
190 /* VIRTIO_GPU_CMD_SET_SCANOUT */
191 struct virtio_gpu_set_scanout
{
192 struct virtio_gpu_ctrl_hdr hdr
;
193 struct virtio_gpu_rect r
;
195 uint32_t resource_id
;
198 /* VIRTIO_GPU_CMD_RESOURCE_FLUSH */
199 struct virtio_gpu_resource_flush
{
200 struct virtio_gpu_ctrl_hdr hdr
;
201 struct virtio_gpu_rect r
;
202 uint32_t resource_id
;
206 /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */
207 struct virtio_gpu_transfer_to_host_2d
{
208 struct virtio_gpu_ctrl_hdr hdr
;
209 struct virtio_gpu_rect r
;
211 uint32_t resource_id
;
215 struct virtio_gpu_mem_entry
{
221 /* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */
222 struct virtio_gpu_resource_attach_backing
{
223 struct virtio_gpu_ctrl_hdr hdr
;
224 uint32_t resource_id
;
228 /* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */
229 struct virtio_gpu_resource_detach_backing
{
230 struct virtio_gpu_ctrl_hdr hdr
;
231 uint32_t resource_id
;
235 /* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */
236 #define VIRTIO_GPU_MAX_SCANOUTS 16
237 struct virtio_gpu_resp_display_info
{
238 struct virtio_gpu_ctrl_hdr hdr
;
239 struct virtio_gpu_display_one
{
240 struct virtio_gpu_rect r
;
243 } pmodes
[VIRTIO_GPU_MAX_SCANOUTS
];
246 /* data passed in the control vq, 3d related */
248 struct virtio_gpu_box
{
253 /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D */
254 struct virtio_gpu_transfer_host_3d
{
255 struct virtio_gpu_ctrl_hdr hdr
;
256 struct virtio_gpu_box box
;
258 uint32_t resource_id
;
261 uint32_t layer_stride
;
264 /* VIRTIO_GPU_CMD_RESOURCE_CREATE_3D */
265 #define VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP (1 << 0)
266 struct virtio_gpu_resource_create_3d
{
267 struct virtio_gpu_ctrl_hdr hdr
;
268 uint32_t resource_id
;
282 /* VIRTIO_GPU_CMD_CTX_CREATE */
283 #define VIRTIO_GPU_CONTEXT_INIT_CAPSET_ID_MASK 0x000000ff
284 struct virtio_gpu_ctx_create
{
285 struct virtio_gpu_ctrl_hdr hdr
;
287 uint32_t context_init
;
291 /* VIRTIO_GPU_CMD_CTX_DESTROY */
292 struct virtio_gpu_ctx_destroy
{
293 struct virtio_gpu_ctrl_hdr hdr
;
296 /* VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE */
297 struct virtio_gpu_ctx_resource
{
298 struct virtio_gpu_ctrl_hdr hdr
;
299 uint32_t resource_id
;
303 /* VIRTIO_GPU_CMD_SUBMIT_3D */
304 struct virtio_gpu_cmd_submit
{
305 struct virtio_gpu_ctrl_hdr hdr
;
310 #define VIRTIO_GPU_CAPSET_VIRGL 1
311 #define VIRTIO_GPU_CAPSET_VIRGL2 2
313 /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */
314 struct virtio_gpu_get_capset_info
{
315 struct virtio_gpu_ctrl_hdr hdr
;
316 uint32_t capset_index
;
320 /* VIRTIO_GPU_RESP_OK_CAPSET_INFO */
321 struct virtio_gpu_resp_capset_info
{
322 struct virtio_gpu_ctrl_hdr hdr
;
324 uint32_t capset_max_version
;
325 uint32_t capset_max_size
;
329 /* VIRTIO_GPU_CMD_GET_CAPSET */
330 struct virtio_gpu_get_capset
{
331 struct virtio_gpu_ctrl_hdr hdr
;
333 uint32_t capset_version
;
336 /* VIRTIO_GPU_RESP_OK_CAPSET */
337 struct virtio_gpu_resp_capset
{
338 struct virtio_gpu_ctrl_hdr hdr
;
339 uint8_t capset_data
[];
342 /* VIRTIO_GPU_CMD_GET_EDID */
343 struct virtio_gpu_cmd_get_edid
{
344 struct virtio_gpu_ctrl_hdr hdr
;
349 /* VIRTIO_GPU_RESP_OK_EDID */
350 struct virtio_gpu_resp_edid
{
351 struct virtio_gpu_ctrl_hdr hdr
;
357 #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0)
359 struct virtio_gpu_config
{
360 uint32_t events_read
;
361 uint32_t events_clear
;
362 uint32_t num_scanouts
;
363 uint32_t num_capsets
;
366 /* simple formats for fbcon/X use */
367 enum virtio_gpu_formats
{
368 VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM
= 1,
369 VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM
= 2,
370 VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM
= 3,
371 VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM
= 4,
373 VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM
= 67,
374 VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM
= 68,
376 VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM
= 121,
377 VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM
= 134,
380 /* VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID */
381 struct virtio_gpu_resource_assign_uuid
{
382 struct virtio_gpu_ctrl_hdr hdr
;
383 uint32_t resource_id
;
387 /* VIRTIO_GPU_RESP_OK_RESOURCE_UUID */
388 struct virtio_gpu_resp_resource_uuid
{
389 struct virtio_gpu_ctrl_hdr hdr
;
393 /* VIRTIO_GPU_CMD_RESOURCE_CREATE_BLOB */
394 struct virtio_gpu_resource_create_blob
{
395 struct virtio_gpu_ctrl_hdr hdr
;
396 uint32_t resource_id
;
397 #define VIRTIO_GPU_BLOB_MEM_GUEST 0x0001
398 #define VIRTIO_GPU_BLOB_MEM_HOST3D 0x0002
399 #define VIRTIO_GPU_BLOB_MEM_HOST3D_GUEST 0x0003
401 #define VIRTIO_GPU_BLOB_FLAG_USE_MAPPABLE 0x0001
402 #define VIRTIO_GPU_BLOB_FLAG_USE_SHAREABLE 0x0002
403 #define VIRTIO_GPU_BLOB_FLAG_USE_CROSS_DEVICE 0x0004
404 /* zero is invalid blob mem */
411 * sizeof(nr_entries * virtio_gpu_mem_entry) bytes follow
415 /* VIRTIO_GPU_CMD_SET_SCANOUT_BLOB */
416 struct virtio_gpu_set_scanout_blob
{
417 struct virtio_gpu_ctrl_hdr hdr
;
418 struct virtio_gpu_rect r
;
420 uint32_t resource_id
;
429 /* VIRTIO_GPU_CMD_RESOURCE_MAP_BLOB */
430 struct virtio_gpu_resource_map_blob
{
431 struct virtio_gpu_ctrl_hdr hdr
;
432 uint32_t resource_id
;
437 /* VIRTIO_GPU_RESP_OK_MAP_INFO */
438 #define VIRTIO_GPU_MAP_CACHE_MASK 0x0f
439 #define VIRTIO_GPU_MAP_CACHE_NONE 0x00
440 #define VIRTIO_GPU_MAP_CACHE_CACHED 0x01
441 #define VIRTIO_GPU_MAP_CACHE_UNCACHED 0x02
442 #define VIRTIO_GPU_MAP_CACHE_WC 0x03
443 struct virtio_gpu_resp_map_info
{
444 struct virtio_gpu_ctrl_hdr hdr
;
449 /* VIRTIO_GPU_CMD_RESOURCE_UNMAP_BLOB */
450 struct virtio_gpu_resource_unmap_blob
{
451 struct virtio_gpu_ctrl_hdr hdr
;
452 uint32_t resource_id
;