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 38 #ifndef VIRTIO_GPU_HW_H 39 #define VIRTIO_GPU_HW_H 40 41 #include "standard-headers/linux/types.h" 42 43 /* 44 * VIRTIO_GPU_CMD_CTX_* 45 * VIRTIO_GPU_CMD_*_3D 46 */ 47 #define VIRTIO_GPU_F_VIRGL 0 48 49 /* 50 * VIRTIO_GPU_CMD_GET_EDID 51 */ 52 #define VIRTIO_GPU_F_EDID 1 53 /* 54 * VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID 55 */ 56 #define VIRTIO_GPU_F_RESOURCE_UUID 2 57 58 enum virtio_gpu_ctrl_type { 59 VIRTIO_GPU_UNDEFINED = 0, 60 61 /* 2d commands */ 62 VIRTIO_GPU_CMD_GET_DISPLAY_INFO = 0x0100, 63 VIRTIO_GPU_CMD_RESOURCE_CREATE_2D, 64 VIRTIO_GPU_CMD_RESOURCE_UNREF, 65 VIRTIO_GPU_CMD_SET_SCANOUT, 66 VIRTIO_GPU_CMD_RESOURCE_FLUSH, 67 VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D, 68 VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING, 69 VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING, 70 VIRTIO_GPU_CMD_GET_CAPSET_INFO, 71 VIRTIO_GPU_CMD_GET_CAPSET, 72 VIRTIO_GPU_CMD_GET_EDID, 73 VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID, 74 75 /* 3d commands */ 76 VIRTIO_GPU_CMD_CTX_CREATE = 0x0200, 77 VIRTIO_GPU_CMD_CTX_DESTROY, 78 VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, 79 VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE, 80 VIRTIO_GPU_CMD_RESOURCE_CREATE_3D, 81 VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, 82 VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D, 83 VIRTIO_GPU_CMD_SUBMIT_3D, 84 85 /* cursor commands */ 86 VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300, 87 VIRTIO_GPU_CMD_MOVE_CURSOR, 88 89 /* success responses */ 90 VIRTIO_GPU_RESP_OK_NODATA = 0x1100, 91 VIRTIO_GPU_RESP_OK_DISPLAY_INFO, 92 VIRTIO_GPU_RESP_OK_CAPSET_INFO, 93 VIRTIO_GPU_RESP_OK_CAPSET, 94 VIRTIO_GPU_RESP_OK_EDID, 95 VIRTIO_GPU_RESP_OK_RESOURCE_UUID, 96 97 /* error responses */ 98 VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200, 99 VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY, 100 VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID, 101 VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID, 102 VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID, 103 VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER, 104 }; 105 106 #define VIRTIO_GPU_FLAG_FENCE (1 << 0) 107 108 struct virtio_gpu_ctrl_hdr { 109 uint32_t type; 110 uint32_t flags; 111 uint64_t fence_id; 112 uint32_t ctx_id; 113 uint32_t padding; 114 }; 115 116 /* data passed in the cursor vq */ 117 118 struct virtio_gpu_cursor_pos { 119 uint32_t scanout_id; 120 uint32_t x; 121 uint32_t y; 122 uint32_t padding; 123 }; 124 125 /* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */ 126 struct virtio_gpu_update_cursor { 127 struct virtio_gpu_ctrl_hdr hdr; 128 struct virtio_gpu_cursor_pos pos; /* update & move */ 129 uint32_t resource_id; /* update only */ 130 uint32_t hot_x; /* update only */ 131 uint32_t hot_y; /* update only */ 132 uint32_t padding; 133 }; 134 135 /* data passed in the control vq, 2d related */ 136 137 struct virtio_gpu_rect { 138 uint32_t x; 139 uint32_t y; 140 uint32_t width; 141 uint32_t height; 142 }; 143 144 /* VIRTIO_GPU_CMD_RESOURCE_UNREF */ 145 struct virtio_gpu_resource_unref { 146 struct virtio_gpu_ctrl_hdr hdr; 147 uint32_t resource_id; 148 uint32_t padding; 149 }; 150 151 /* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */ 152 struct virtio_gpu_resource_create_2d { 153 struct virtio_gpu_ctrl_hdr hdr; 154 uint32_t resource_id; 155 uint32_t format; 156 uint32_t width; 157 uint32_t height; 158 }; 159 160 /* VIRTIO_GPU_CMD_SET_SCANOUT */ 161 struct virtio_gpu_set_scanout { 162 struct virtio_gpu_ctrl_hdr hdr; 163 struct virtio_gpu_rect r; 164 uint32_t scanout_id; 165 uint32_t resource_id; 166 }; 167 168 /* VIRTIO_GPU_CMD_RESOURCE_FLUSH */ 169 struct virtio_gpu_resource_flush { 170 struct virtio_gpu_ctrl_hdr hdr; 171 struct virtio_gpu_rect r; 172 uint32_t resource_id; 173 uint32_t padding; 174 }; 175 176 /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */ 177 struct virtio_gpu_transfer_to_host_2d { 178 struct virtio_gpu_ctrl_hdr hdr; 179 struct virtio_gpu_rect r; 180 uint64_t offset; 181 uint32_t resource_id; 182 uint32_t padding; 183 }; 184 185 struct virtio_gpu_mem_entry { 186 uint64_t addr; 187 uint32_t length; 188 uint32_t padding; 189 }; 190 191 /* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */ 192 struct virtio_gpu_resource_attach_backing { 193 struct virtio_gpu_ctrl_hdr hdr; 194 uint32_t resource_id; 195 uint32_t nr_entries; 196 }; 197 198 /* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */ 199 struct virtio_gpu_resource_detach_backing { 200 struct virtio_gpu_ctrl_hdr hdr; 201 uint32_t resource_id; 202 uint32_t padding; 203 }; 204 205 /* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */ 206 #define VIRTIO_GPU_MAX_SCANOUTS 16 207 struct virtio_gpu_resp_display_info { 208 struct virtio_gpu_ctrl_hdr hdr; 209 struct virtio_gpu_display_one { 210 struct virtio_gpu_rect r; 211 uint32_t enabled; 212 uint32_t flags; 213 } pmodes[VIRTIO_GPU_MAX_SCANOUTS]; 214 }; 215 216 /* data passed in the control vq, 3d related */ 217 218 struct virtio_gpu_box { 219 uint32_t x, y, z; 220 uint32_t w, h, d; 221 }; 222 223 /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D */ 224 struct virtio_gpu_transfer_host_3d { 225 struct virtio_gpu_ctrl_hdr hdr; 226 struct virtio_gpu_box box; 227 uint64_t offset; 228 uint32_t resource_id; 229 uint32_t level; 230 uint32_t stride; 231 uint32_t layer_stride; 232 }; 233 234 /* VIRTIO_GPU_CMD_RESOURCE_CREATE_3D */ 235 #define VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP (1 << 0) 236 struct virtio_gpu_resource_create_3d { 237 struct virtio_gpu_ctrl_hdr hdr; 238 uint32_t resource_id; 239 uint32_t target; 240 uint32_t format; 241 uint32_t bind; 242 uint32_t width; 243 uint32_t height; 244 uint32_t depth; 245 uint32_t array_size; 246 uint32_t last_level; 247 uint32_t nr_samples; 248 uint32_t flags; 249 uint32_t padding; 250 }; 251 252 /* VIRTIO_GPU_CMD_CTX_CREATE */ 253 struct virtio_gpu_ctx_create { 254 struct virtio_gpu_ctrl_hdr hdr; 255 uint32_t nlen; 256 uint32_t padding; 257 char debug_name[64]; 258 }; 259 260 /* VIRTIO_GPU_CMD_CTX_DESTROY */ 261 struct virtio_gpu_ctx_destroy { 262 struct virtio_gpu_ctrl_hdr hdr; 263 }; 264 265 /* VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE */ 266 struct virtio_gpu_ctx_resource { 267 struct virtio_gpu_ctrl_hdr hdr; 268 uint32_t resource_id; 269 uint32_t padding; 270 }; 271 272 /* VIRTIO_GPU_CMD_SUBMIT_3D */ 273 struct virtio_gpu_cmd_submit { 274 struct virtio_gpu_ctrl_hdr hdr; 275 uint32_t size; 276 uint32_t padding; 277 }; 278 279 #define VIRTIO_GPU_CAPSET_VIRGL 1 280 #define VIRTIO_GPU_CAPSET_VIRGL2 2 281 282 /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */ 283 struct virtio_gpu_get_capset_info { 284 struct virtio_gpu_ctrl_hdr hdr; 285 uint32_t capset_index; 286 uint32_t padding; 287 }; 288 289 /* VIRTIO_GPU_RESP_OK_CAPSET_INFO */ 290 struct virtio_gpu_resp_capset_info { 291 struct virtio_gpu_ctrl_hdr hdr; 292 uint32_t capset_id; 293 uint32_t capset_max_version; 294 uint32_t capset_max_size; 295 uint32_t padding; 296 }; 297 298 /* VIRTIO_GPU_CMD_GET_CAPSET */ 299 struct virtio_gpu_get_capset { 300 struct virtio_gpu_ctrl_hdr hdr; 301 uint32_t capset_id; 302 uint32_t capset_version; 303 }; 304 305 /* VIRTIO_GPU_RESP_OK_CAPSET */ 306 struct virtio_gpu_resp_capset { 307 struct virtio_gpu_ctrl_hdr hdr; 308 uint8_t capset_data[]; 309 }; 310 311 /* VIRTIO_GPU_CMD_GET_EDID */ 312 struct virtio_gpu_cmd_get_edid { 313 struct virtio_gpu_ctrl_hdr hdr; 314 uint32_t scanout; 315 uint32_t padding; 316 }; 317 318 /* VIRTIO_GPU_RESP_OK_EDID */ 319 struct virtio_gpu_resp_edid { 320 struct virtio_gpu_ctrl_hdr hdr; 321 uint32_t size; 322 uint32_t padding; 323 uint8_t edid[1024]; 324 }; 325 326 #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0) 327 328 struct virtio_gpu_config { 329 uint32_t events_read; 330 uint32_t events_clear; 331 uint32_t num_scanouts; 332 uint32_t num_capsets; 333 }; 334 335 /* simple formats for fbcon/X use */ 336 enum virtio_gpu_formats { 337 VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM = 1, 338 VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM = 2, 339 VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM = 3, 340 VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM = 4, 341 342 VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM = 67, 343 VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM = 68, 344 345 VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM = 121, 346 VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM = 134, 347 }; 348 349 /* VIRTIO_GPU_CMD_RESOURCE_ASSIGN_UUID */ 350 struct virtio_gpu_resource_assign_uuid { 351 struct virtio_gpu_ctrl_hdr hdr; 352 uint32_t resource_id; 353 uint32_t padding; 354 }; 355 356 /* VIRTIO_GPU_RESP_OK_RESOURCE_UUID */ 357 struct virtio_gpu_resp_resource_uuid { 358 struct virtio_gpu_ctrl_hdr hdr; 359 uint8_t uuid[16]; 360 }; 361 362 #endif 363