1*53476e07SGerd Hoffmann /*
2*53476e07SGerd Hoffmann  * Virtio GPU Device
3*53476e07SGerd Hoffmann  *
4*53476e07SGerd Hoffmann  * Copyright Red Hat, Inc. 2013-2014
5*53476e07SGerd Hoffmann  *
6*53476e07SGerd Hoffmann  * Authors:
7*53476e07SGerd Hoffmann  *     Dave Airlie <airlied@redhat.com>
8*53476e07SGerd Hoffmann  *     Gerd Hoffmann <kraxel@redhat.com>
9*53476e07SGerd Hoffmann  *
10*53476e07SGerd Hoffmann  * This header is BSD licensed so anyone can use the definitions
11*53476e07SGerd Hoffmann  * to implement compatible drivers/servers:
12*53476e07SGerd Hoffmann  *
13*53476e07SGerd Hoffmann  * Redistribution and use in source and binary forms, with or without
14*53476e07SGerd Hoffmann  * modification, are permitted provided that the following conditions
15*53476e07SGerd Hoffmann  * are met:
16*53476e07SGerd Hoffmann  * 1. Redistributions of source code must retain the above copyright
17*53476e07SGerd Hoffmann  *    notice, this list of conditions and the following disclaimer.
18*53476e07SGerd Hoffmann  * 2. Redistributions in binary form must reproduce the above copyright
19*53476e07SGerd Hoffmann  *    notice, this list of conditions and the following disclaimer in the
20*53476e07SGerd Hoffmann  *    documentation and/or other materials provided with the distribution.
21*53476e07SGerd Hoffmann  * 3. Neither the name of IBM nor the names of its contributors
22*53476e07SGerd Hoffmann  *    may be used to endorse or promote products derived from this software
23*53476e07SGerd Hoffmann  *    without specific prior written permission.
24*53476e07SGerd Hoffmann  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
25*53476e07SGerd Hoffmann  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
26*53476e07SGerd Hoffmann  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
27*53476e07SGerd Hoffmann  * FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL IBM OR
28*53476e07SGerd Hoffmann  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
29*53476e07SGerd Hoffmann  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
30*53476e07SGerd Hoffmann  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
31*53476e07SGerd Hoffmann  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32*53476e07SGerd Hoffmann  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
33*53476e07SGerd Hoffmann  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
34*53476e07SGerd Hoffmann  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35*53476e07SGerd Hoffmann  * SUCH DAMAGE.
36*53476e07SGerd Hoffmann  */
37*53476e07SGerd Hoffmann 
38*53476e07SGerd Hoffmann #ifndef VIRTIO_GPU_HW_H
39*53476e07SGerd Hoffmann #define VIRTIO_GPU_HW_H
40*53476e07SGerd Hoffmann 
41*53476e07SGerd Hoffmann enum virtio_gpu_ctrl_type {
42*53476e07SGerd Hoffmann 	VIRTIO_GPU_UNDEFINED = 0,
43*53476e07SGerd Hoffmann 
44*53476e07SGerd Hoffmann 	/* 2d commands */
45*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_GET_DISPLAY_INFO = 0x0100,
46*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_CREATE_2D,
47*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_UNREF,
48*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_SET_SCANOUT,
49*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_FLUSH,
50*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D,
51*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING,
52*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING,
53*53476e07SGerd Hoffmann 
54*53476e07SGerd Hoffmann 	/* cursor commands */
55*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300,
56*53476e07SGerd Hoffmann 	VIRTIO_GPU_CMD_MOVE_CURSOR,
57*53476e07SGerd Hoffmann 
58*53476e07SGerd Hoffmann 	/* success responses */
59*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_OK_NODATA = 0x1100,
60*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_OK_DISPLAY_INFO,
61*53476e07SGerd Hoffmann 
62*53476e07SGerd Hoffmann 	/* error responses */
63*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200,
64*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY,
65*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID,
66*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID,
67*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID,
68*53476e07SGerd Hoffmann 	VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER,
69*53476e07SGerd Hoffmann };
70*53476e07SGerd Hoffmann 
71*53476e07SGerd Hoffmann #define VIRTIO_GPU_FLAG_FENCE (1 << 0)
72*53476e07SGerd Hoffmann 
73*53476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr {
74*53476e07SGerd Hoffmann 	uint32_t type;
75*53476e07SGerd Hoffmann 	uint32_t flags;
76*53476e07SGerd Hoffmann 	uint64_t fence_id;
77*53476e07SGerd Hoffmann 	uint32_t ctx_id;
78*53476e07SGerd Hoffmann 	uint32_t padding;
79*53476e07SGerd Hoffmann };
80*53476e07SGerd Hoffmann 
81*53476e07SGerd Hoffmann /* data passed in the cursor vq */
82*53476e07SGerd Hoffmann 
83*53476e07SGerd Hoffmann struct virtio_gpu_cursor_pos {
84*53476e07SGerd Hoffmann 	uint32_t scanout_id;
85*53476e07SGerd Hoffmann 	uint32_t x;
86*53476e07SGerd Hoffmann 	uint32_t y;
87*53476e07SGerd Hoffmann 	uint32_t padding;
88*53476e07SGerd Hoffmann };
89*53476e07SGerd Hoffmann 
90*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */
91*53476e07SGerd Hoffmann struct virtio_gpu_update_cursor {
92*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
93*53476e07SGerd Hoffmann 	struct virtio_gpu_cursor_pos pos;  /* update & move */
94*53476e07SGerd Hoffmann 	uint32_t resource_id;           /* update only */
95*53476e07SGerd Hoffmann 	uint32_t hot_x;                 /* update only */
96*53476e07SGerd Hoffmann 	uint32_t hot_y;                 /* update only */
97*53476e07SGerd Hoffmann 	uint32_t padding;
98*53476e07SGerd Hoffmann };
99*53476e07SGerd Hoffmann 
100*53476e07SGerd Hoffmann /* data passed in the control vq, 2d related */
101*53476e07SGerd Hoffmann 
102*53476e07SGerd Hoffmann struct virtio_gpu_rect {
103*53476e07SGerd Hoffmann 	uint32_t x;
104*53476e07SGerd Hoffmann 	uint32_t y;
105*53476e07SGerd Hoffmann 	uint32_t width;
106*53476e07SGerd Hoffmann 	uint32_t height;
107*53476e07SGerd Hoffmann };
108*53476e07SGerd Hoffmann 
109*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_UNREF */
110*53476e07SGerd Hoffmann struct virtio_gpu_resource_unref {
111*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
112*53476e07SGerd Hoffmann 	uint32_t resource_id;
113*53476e07SGerd Hoffmann 	uint32_t padding;
114*53476e07SGerd Hoffmann };
115*53476e07SGerd Hoffmann 
116*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */
117*53476e07SGerd Hoffmann struct virtio_gpu_resource_create_2d {
118*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
119*53476e07SGerd Hoffmann 	uint32_t resource_id;
120*53476e07SGerd Hoffmann 	uint32_t format;
121*53476e07SGerd Hoffmann 	uint32_t width;
122*53476e07SGerd Hoffmann 	uint32_t height;
123*53476e07SGerd Hoffmann };
124*53476e07SGerd Hoffmann 
125*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_SET_SCANOUT */
126*53476e07SGerd Hoffmann struct virtio_gpu_set_scanout {
127*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
128*53476e07SGerd Hoffmann 	struct virtio_gpu_rect r;
129*53476e07SGerd Hoffmann 	uint32_t scanout_id;
130*53476e07SGerd Hoffmann 	uint32_t resource_id;
131*53476e07SGerd Hoffmann };
132*53476e07SGerd Hoffmann 
133*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_FLUSH */
134*53476e07SGerd Hoffmann struct virtio_gpu_resource_flush {
135*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
136*53476e07SGerd Hoffmann 	struct virtio_gpu_rect r;
137*53476e07SGerd Hoffmann 	uint32_t resource_id;
138*53476e07SGerd Hoffmann 	uint32_t padding;
139*53476e07SGerd Hoffmann };
140*53476e07SGerd Hoffmann 
141*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */
142*53476e07SGerd Hoffmann struct virtio_gpu_transfer_to_host_2d {
143*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
144*53476e07SGerd Hoffmann 	struct virtio_gpu_rect r;
145*53476e07SGerd Hoffmann 	uint64_t offset;
146*53476e07SGerd Hoffmann 	uint32_t resource_id;
147*53476e07SGerd Hoffmann 	uint32_t padding;
148*53476e07SGerd Hoffmann };
149*53476e07SGerd Hoffmann 
150*53476e07SGerd Hoffmann struct virtio_gpu_mem_entry {
151*53476e07SGerd Hoffmann 	uint64_t addr;
152*53476e07SGerd Hoffmann 	uint32_t length;
153*53476e07SGerd Hoffmann 	uint32_t padding;
154*53476e07SGerd Hoffmann };
155*53476e07SGerd Hoffmann 
156*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */
157*53476e07SGerd Hoffmann struct virtio_gpu_resource_attach_backing {
158*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
159*53476e07SGerd Hoffmann 	uint32_t resource_id;
160*53476e07SGerd Hoffmann 	uint32_t nr_entries;
161*53476e07SGerd Hoffmann };
162*53476e07SGerd Hoffmann 
163*53476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */
164*53476e07SGerd Hoffmann struct virtio_gpu_resource_detach_backing {
165*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
166*53476e07SGerd Hoffmann 	uint32_t resource_id;
167*53476e07SGerd Hoffmann 	uint32_t padding;
168*53476e07SGerd Hoffmann };
169*53476e07SGerd Hoffmann 
170*53476e07SGerd Hoffmann /* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */
171*53476e07SGerd Hoffmann #define VIRTIO_GPU_MAX_SCANOUTS 16
172*53476e07SGerd Hoffmann struct virtio_gpu_resp_display_info {
173*53476e07SGerd Hoffmann 	struct virtio_gpu_ctrl_hdr hdr;
174*53476e07SGerd Hoffmann 	struct virtio_gpu_display_one {
175*53476e07SGerd Hoffmann 		struct virtio_gpu_rect r;
176*53476e07SGerd Hoffmann 		uint32_t enabled;
177*53476e07SGerd Hoffmann 		uint32_t flags;
178*53476e07SGerd Hoffmann 	} pmodes[VIRTIO_GPU_MAX_SCANOUTS];
179*53476e07SGerd Hoffmann };
180*53476e07SGerd Hoffmann 
181*53476e07SGerd Hoffmann #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0)
182*53476e07SGerd Hoffmann 
183*53476e07SGerd Hoffmann struct virtio_gpu_config {
184*53476e07SGerd Hoffmann 	uint32_t events_read;
185*53476e07SGerd Hoffmann 	uint32_t events_clear;
186*53476e07SGerd Hoffmann 	uint32_t num_scanouts;
187*53476e07SGerd Hoffmann 	uint32_t reserved;
188*53476e07SGerd Hoffmann };
189*53476e07SGerd Hoffmann 
190*53476e07SGerd Hoffmann /* simple formats for fbcon/X use */
191*53476e07SGerd Hoffmann enum virtio_gpu_formats {
192*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM  = 1,
193*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM  = 2,
194*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM  = 3,
195*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM  = 4,
196*53476e07SGerd Hoffmann 
197*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM  = 67,
198*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM  = 68,
199*53476e07SGerd Hoffmann 
200*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM  = 121,
201*53476e07SGerd Hoffmann 	VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM  = 134,
202*53476e07SGerd Hoffmann };
203*53476e07SGerd Hoffmann 
204*53476e07SGerd Hoffmann #endif
205