153476e07SGerd Hoffmann /*
253476e07SGerd Hoffmann  * Virtio GPU Device
353476e07SGerd Hoffmann  *
453476e07SGerd Hoffmann  * Copyright Red Hat, Inc. 2013-2014
553476e07SGerd Hoffmann  *
653476e07SGerd Hoffmann  * Authors:
753476e07SGerd Hoffmann  *     Dave Airlie <airlied@redhat.com>
853476e07SGerd Hoffmann  *     Gerd Hoffmann <kraxel@redhat.com>
953476e07SGerd Hoffmann  *
1053476e07SGerd Hoffmann  * This header is BSD licensed so anyone can use the definitions
1153476e07SGerd Hoffmann  * to implement compatible drivers/servers:
1253476e07SGerd Hoffmann  *
1353476e07SGerd Hoffmann  * Redistribution and use in source and binary forms, with or without
1453476e07SGerd Hoffmann  * modification, are permitted provided that the following conditions
1553476e07SGerd Hoffmann  * are met:
1653476e07SGerd Hoffmann  * 1. Redistributions of source code must retain the above copyright
1753476e07SGerd Hoffmann  *    notice, this list of conditions and the following disclaimer.
1853476e07SGerd Hoffmann  * 2. Redistributions in binary form must reproduce the above copyright
1953476e07SGerd Hoffmann  *    notice, this list of conditions and the following disclaimer in the
2053476e07SGerd Hoffmann  *    documentation and/or other materials provided with the distribution.
2153476e07SGerd Hoffmann  * 3. Neither the name of IBM nor the names of its contributors
2253476e07SGerd Hoffmann  *    may be used to endorse or promote products derived from this software
2353476e07SGerd Hoffmann  *    without specific prior written permission.
2453476e07SGerd Hoffmann  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
2553476e07SGerd Hoffmann  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
2653476e07SGerd Hoffmann  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
2753476e07SGerd Hoffmann  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR
2853476e07SGerd Hoffmann  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2953476e07SGerd Hoffmann  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
3053476e07SGerd Hoffmann  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
3153476e07SGerd Hoffmann  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
3253476e07SGerd Hoffmann  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
3353476e07SGerd Hoffmann  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
3453476e07SGerd Hoffmann  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3553476e07SGerd Hoffmann  * SUCH DAMAGE.
3653476e07SGerd Hoffmann  */
3753476e07SGerd Hoffmann 
3853476e07SGerd Hoffmann #ifndef VIRTIO_GPU_HW_H
3953476e07SGerd Hoffmann #define VIRTIO_GPU_HW_H
4053476e07SGerd Hoffmann 
41*25b8b39bSAlexey Kardashevskiy #include "standard-headers/linux/types.h"
42*25b8b39bSAlexey Kardashevskiy 
4353476e07SGerd Hoffmann enum virtio_gpu_ctrl_type {
4453476e07SGerd Hoffmann 	VIRTIO_GPU_UNDEFINED = 0,
4553476e07SGerd Hoffmann 
4653476e07SGerd Hoffmann 	/* 2d commands */
4753476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_GET_DISPLAY_INFO = 0x0100,
4853476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_CREATE_2D,
4953476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_UNREF,
5053476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_SET_SCANOUT,
5153476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_FLUSH,
5253476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D,
5353476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING,
5453476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING,
5553476e07SGerd Hoffmann 
5653476e07SGerd Hoffmann 	/* cursor commands */
5753476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
5853476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_MOVE_CURSOR,
5953476e07SGerd Hoffmann 
6053476e07SGerd Hoffmann 	/* success responses */
6153476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_OK_NODATA = 0x1100,
6253476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_OK_DISPLAY_INFO,
6353476e07SGerd Hoffmann 
6453476e07SGerd Hoffmann 	/* error responses */
6553476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
6653476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY,
6753476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID,
6853476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID,
6953476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID,
7053476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER,
7153476e07SGerd Hoffmann };
7253476e07SGerd Hoffmann 
7353476e07SGerd Hoffmann #define VIRTIO_GPU_FLAG_FENCE (1 << 0)
7453476e07SGerd Hoffmann 
7553476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr {
7653476e07SGerd Hoffmann 	uint32_t type;
7753476e07SGerd Hoffmann 	uint32_t flags;
7853476e07SGerd Hoffmann 	uint64_t fence_id;
7953476e07SGerd Hoffmann 	uint32_t ctx_id;
8053476e07SGerd Hoffmann 	uint32_t padding;
8153476e07SGerd Hoffmann };
8253476e07SGerd Hoffmann 
8353476e07SGerd Hoffmann /* data passed in the cursor vq */
8453476e07SGerd Hoffmann 
8553476e07SGerd Hoffmann struct virtio_gpu_cursor_pos {
8653476e07SGerd Hoffmann 	uint32_t scanout_id;
8753476e07SGerd Hoffmann 	uint32_t x;
8853476e07SGerd Hoffmann 	uint32_t y;
8953476e07SGerd Hoffmann 	uint32_t padding;
9053476e07SGerd Hoffmann };
9153476e07SGerd Hoffmann 
9253476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */
9353476e07SGerd Hoffmann struct virtio_gpu_update_cursor {
9453476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
9553476e07SGerd Hoffmann 	struct virtio_gpu_cursor_pos pos;  /* update & move */
9653476e07SGerd Hoffmann 	uint32_t resource_id;           /* update only */
9753476e07SGerd Hoffmann 	uint32_t hot_x;                 /* update only */
9853476e07SGerd Hoffmann 	uint32_t hot_y;                 /* update only */
9953476e07SGerd Hoffmann 	uint32_t padding;
10053476e07SGerd Hoffmann };
10153476e07SGerd Hoffmann 
10253476e07SGerd Hoffmann /* data passed in the control vq, 2d related */
10353476e07SGerd Hoffmann 
10453476e07SGerd Hoffmann struct virtio_gpu_rect {
10553476e07SGerd Hoffmann 	uint32_t x;
10653476e07SGerd Hoffmann 	uint32_t y;
10753476e07SGerd Hoffmann 	uint32_t width;
10853476e07SGerd Hoffmann 	uint32_t height;
10953476e07SGerd Hoffmann };
11053476e07SGerd Hoffmann 
11153476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_UNREF */
11253476e07SGerd Hoffmann struct virtio_gpu_resource_unref {
11353476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
11453476e07SGerd Hoffmann 	uint32_t resource_id;
11553476e07SGerd Hoffmann 	uint32_t padding;
11653476e07SGerd Hoffmann };
11753476e07SGerd Hoffmann 
11853476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */
11953476e07SGerd Hoffmann struct virtio_gpu_resource_create_2d {
12053476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
12153476e07SGerd Hoffmann 	uint32_t resource_id;
12253476e07SGerd Hoffmann 	uint32_t format;
12353476e07SGerd Hoffmann 	uint32_t width;
12453476e07SGerd Hoffmann 	uint32_t height;
12553476e07SGerd Hoffmann };
12653476e07SGerd Hoffmann 
12753476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_SET_SCANOUT */
12853476e07SGerd Hoffmann struct virtio_gpu_set_scanout {
12953476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
13053476e07SGerd Hoffmann 	struct virtio_gpu_rect r;
13153476e07SGerd Hoffmann 	uint32_t scanout_id;
13253476e07SGerd Hoffmann 	uint32_t resource_id;
13353476e07SGerd Hoffmann };
13453476e07SGerd Hoffmann 
13553476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_FLUSH */
13653476e07SGerd Hoffmann struct virtio_gpu_resource_flush {
13753476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
13853476e07SGerd Hoffmann 	struct virtio_gpu_rect r;
13953476e07SGerd Hoffmann 	uint32_t resource_id;
14053476e07SGerd Hoffmann 	uint32_t padding;
14153476e07SGerd Hoffmann };
14253476e07SGerd Hoffmann 
14353476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */
14453476e07SGerd Hoffmann struct virtio_gpu_transfer_to_host_2d {
14553476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
14653476e07SGerd Hoffmann 	struct virtio_gpu_rect r;
14753476e07SGerd Hoffmann 	uint64_t offset;
14853476e07SGerd Hoffmann 	uint32_t resource_id;
14953476e07SGerd Hoffmann 	uint32_t padding;
15053476e07SGerd Hoffmann };
15153476e07SGerd Hoffmann 
15253476e07SGerd Hoffmann struct virtio_gpu_mem_entry {
15353476e07SGerd Hoffmann 	uint64_t addr;
15453476e07SGerd Hoffmann 	uint32_t length;
15553476e07SGerd Hoffmann 	uint32_t padding;
15653476e07SGerd Hoffmann };
15753476e07SGerd Hoffmann 
15853476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */
15953476e07SGerd Hoffmann struct virtio_gpu_resource_attach_backing {
16053476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
16153476e07SGerd Hoffmann 	uint32_t resource_id;
16253476e07SGerd Hoffmann 	uint32_t nr_entries;
16353476e07SGerd Hoffmann };
16453476e07SGerd Hoffmann 
16553476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */
16653476e07SGerd Hoffmann struct virtio_gpu_resource_detach_backing {
16753476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
16853476e07SGerd Hoffmann 	uint32_t resource_id;
16953476e07SGerd Hoffmann 	uint32_t padding;
17053476e07SGerd Hoffmann };
17153476e07SGerd Hoffmann 
17253476e07SGerd Hoffmann /* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */
17353476e07SGerd Hoffmann #define VIRTIO_GPU_MAX_SCANOUTS 16
17453476e07SGerd Hoffmann struct virtio_gpu_resp_display_info {
17553476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
17653476e07SGerd Hoffmann 	struct virtio_gpu_display_one {
17753476e07SGerd Hoffmann 		struct virtio_gpu_rect r;
17853476e07SGerd Hoffmann 		uint32_t enabled;
17953476e07SGerd Hoffmann 		uint32_t flags;
18053476e07SGerd Hoffmann 	} pmodes[VIRTIO_GPU_MAX_SCANOUTS];
18153476e07SGerd Hoffmann };
18253476e07SGerd Hoffmann 
18353476e07SGerd Hoffmann #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0)
18453476e07SGerd Hoffmann 
18553476e07SGerd Hoffmann struct virtio_gpu_config {
18653476e07SGerd Hoffmann 	uint32_t events_read;
18753476e07SGerd Hoffmann 	uint32_t events_clear;
18853476e07SGerd Hoffmann 	uint32_t num_scanouts;
18953476e07SGerd Hoffmann 	uint32_t reserved;
19053476e07SGerd Hoffmann };
19153476e07SGerd Hoffmann 
19253476e07SGerd Hoffmann /* simple formats for fbcon/X use */
19353476e07SGerd Hoffmann enum virtio_gpu_formats {
19453476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM  = 1,
19553476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM  = 2,
19653476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM  = 3,
19753476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM  = 4,
19853476e07SGerd Hoffmann 
19953476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM  = 67,
20053476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM  = 68,
20153476e07SGerd Hoffmann 
20253476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM  = 121,
20353476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM  = 134,
20453476e07SGerd Hoffmann };
20553476e07SGerd Hoffmann 
20653476e07SGerd Hoffmann #endif
207