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 4125b8b39bSAlexey Kardashevskiy #include "standard-headers/linux/types.h" 4225b8b39bSAlexey Kardashevskiy 43*bc79e964SGerd Hoffmann #define VIRTIO_GPU_FEATURE_VIRGL 0 44*bc79e964SGerd Hoffmann 4553476e07SGerd Hoffmann enum virtio_gpu_ctrl_type { 4653476e07SGerd Hoffmann VIRTIO_GPU_UNDEFINED = 0, 4753476e07SGerd Hoffmann 4853476e07SGerd Hoffmann /* 2d commands */ 4953476e07SGerd Hoffmann VIRTIO_GPU_CMD_GET_DISPLAY_INFO = 0x0100, 5053476e07SGerd Hoffmann VIRTIO_GPU_CMD_RESOURCE_CREATE_2D, 5153476e07SGerd Hoffmann VIRTIO_GPU_CMD_RESOURCE_UNREF, 5253476e07SGerd Hoffmann VIRTIO_GPU_CMD_SET_SCANOUT, 5353476e07SGerd Hoffmann VIRTIO_GPU_CMD_RESOURCE_FLUSH, 5453476e07SGerd Hoffmann VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D, 5553476e07SGerd Hoffmann VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING, 5653476e07SGerd Hoffmann VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING, 57*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_GET_CAPSET_INFO, 58*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_GET_CAPSET, 59*bc79e964SGerd Hoffmann 60*bc79e964SGerd Hoffmann /* 3d commands */ 61*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_CTX_CREATE = 0x0200, 62*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_CTX_DESTROY, 63*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, 64*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE, 65*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_RESOURCE_CREATE_3D, 66*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, 67*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D, 68*bc79e964SGerd Hoffmann VIRTIO_GPU_CMD_SUBMIT_3D, 6953476e07SGerd Hoffmann 7053476e07SGerd Hoffmann /* cursor commands */ 7153476e07SGerd Hoffmann VIRTIO_GPU_CMD_UPDATE_CURSOR = 0x0300, 7253476e07SGerd Hoffmann VIRTIO_GPU_CMD_MOVE_CURSOR, 7353476e07SGerd Hoffmann 7453476e07SGerd Hoffmann /* success responses */ 7553476e07SGerd Hoffmann VIRTIO_GPU_RESP_OK_NODATA = 0x1100, 7653476e07SGerd Hoffmann VIRTIO_GPU_RESP_OK_DISPLAY_INFO, 77*bc79e964SGerd Hoffmann VIRTIO_GPU_RESP_OK_CAPSET_INFO, 78*bc79e964SGerd Hoffmann VIRTIO_GPU_RESP_OK_CAPSET, 7953476e07SGerd Hoffmann 8053476e07SGerd Hoffmann /* error responses */ 8153476e07SGerd Hoffmann VIRTIO_GPU_RESP_ERR_UNSPEC = 0x1200, 8253476e07SGerd Hoffmann VIRTIO_GPU_RESP_ERR_OUT_OF_MEMORY, 8353476e07SGerd Hoffmann VIRTIO_GPU_RESP_ERR_INVALID_SCANOUT_ID, 8453476e07SGerd Hoffmann VIRTIO_GPU_RESP_ERR_INVALID_RESOURCE_ID, 8553476e07SGerd Hoffmann VIRTIO_GPU_RESP_ERR_INVALID_CONTEXT_ID, 8653476e07SGerd Hoffmann VIRTIO_GPU_RESP_ERR_INVALID_PARAMETER, 8753476e07SGerd Hoffmann }; 8853476e07SGerd Hoffmann 8953476e07SGerd Hoffmann #define VIRTIO_GPU_FLAG_FENCE (1 << 0) 9053476e07SGerd Hoffmann 9153476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr { 9253476e07SGerd Hoffmann uint32_t type; 9353476e07SGerd Hoffmann uint32_t flags; 9453476e07SGerd Hoffmann uint64_t fence_id; 9553476e07SGerd Hoffmann uint32_t ctx_id; 9653476e07SGerd Hoffmann uint32_t padding; 9753476e07SGerd Hoffmann }; 9853476e07SGerd Hoffmann 9953476e07SGerd Hoffmann /* data passed in the cursor vq */ 10053476e07SGerd Hoffmann 10153476e07SGerd Hoffmann struct virtio_gpu_cursor_pos { 10253476e07SGerd Hoffmann uint32_t scanout_id; 10353476e07SGerd Hoffmann uint32_t x; 10453476e07SGerd Hoffmann uint32_t y; 10553476e07SGerd Hoffmann uint32_t padding; 10653476e07SGerd Hoffmann }; 10753476e07SGerd Hoffmann 10853476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_UPDATE_CURSOR, VIRTIO_GPU_CMD_MOVE_CURSOR */ 10953476e07SGerd Hoffmann struct virtio_gpu_update_cursor { 11053476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 11153476e07SGerd Hoffmann struct virtio_gpu_cursor_pos pos; /* update & move */ 11253476e07SGerd Hoffmann uint32_t resource_id; /* update only */ 11353476e07SGerd Hoffmann uint32_t hot_x; /* update only */ 11453476e07SGerd Hoffmann uint32_t hot_y; /* update only */ 11553476e07SGerd Hoffmann uint32_t padding; 11653476e07SGerd Hoffmann }; 11753476e07SGerd Hoffmann 11853476e07SGerd Hoffmann /* data passed in the control vq, 2d related */ 11953476e07SGerd Hoffmann 12053476e07SGerd Hoffmann struct virtio_gpu_rect { 12153476e07SGerd Hoffmann uint32_t x; 12253476e07SGerd Hoffmann uint32_t y; 12353476e07SGerd Hoffmann uint32_t width; 12453476e07SGerd Hoffmann uint32_t height; 12553476e07SGerd Hoffmann }; 12653476e07SGerd Hoffmann 12753476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_UNREF */ 12853476e07SGerd Hoffmann struct virtio_gpu_resource_unref { 12953476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 13053476e07SGerd Hoffmann uint32_t resource_id; 13153476e07SGerd Hoffmann uint32_t padding; 13253476e07SGerd Hoffmann }; 13353476e07SGerd Hoffmann 13453476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_CREATE_2D: create a 2d resource with a format */ 13553476e07SGerd Hoffmann struct virtio_gpu_resource_create_2d { 13653476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 13753476e07SGerd Hoffmann uint32_t resource_id; 13853476e07SGerd Hoffmann uint32_t format; 13953476e07SGerd Hoffmann uint32_t width; 14053476e07SGerd Hoffmann uint32_t height; 14153476e07SGerd Hoffmann }; 14253476e07SGerd Hoffmann 14353476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_SET_SCANOUT */ 14453476e07SGerd Hoffmann struct virtio_gpu_set_scanout { 14553476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 14653476e07SGerd Hoffmann struct virtio_gpu_rect r; 14753476e07SGerd Hoffmann uint32_t scanout_id; 14853476e07SGerd Hoffmann uint32_t resource_id; 14953476e07SGerd Hoffmann }; 15053476e07SGerd Hoffmann 15153476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_FLUSH */ 15253476e07SGerd Hoffmann struct virtio_gpu_resource_flush { 15353476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 15453476e07SGerd Hoffmann struct virtio_gpu_rect r; 15553476e07SGerd Hoffmann uint32_t resource_id; 15653476e07SGerd Hoffmann uint32_t padding; 15753476e07SGerd Hoffmann }; 15853476e07SGerd Hoffmann 15953476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_2D: simple transfer to_host */ 16053476e07SGerd Hoffmann struct virtio_gpu_transfer_to_host_2d { 16153476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 16253476e07SGerd Hoffmann struct virtio_gpu_rect r; 16353476e07SGerd Hoffmann uint64_t offset; 16453476e07SGerd Hoffmann uint32_t resource_id; 16553476e07SGerd Hoffmann uint32_t padding; 16653476e07SGerd Hoffmann }; 16753476e07SGerd Hoffmann 16853476e07SGerd Hoffmann struct virtio_gpu_mem_entry { 16953476e07SGerd Hoffmann uint64_t addr; 17053476e07SGerd Hoffmann uint32_t length; 17153476e07SGerd Hoffmann uint32_t padding; 17253476e07SGerd Hoffmann }; 17353476e07SGerd Hoffmann 17453476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_ATTACH_BACKING */ 17553476e07SGerd Hoffmann struct virtio_gpu_resource_attach_backing { 17653476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 17753476e07SGerd Hoffmann uint32_t resource_id; 17853476e07SGerd Hoffmann uint32_t nr_entries; 17953476e07SGerd Hoffmann }; 18053476e07SGerd Hoffmann 18153476e07SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_DETACH_BACKING */ 18253476e07SGerd Hoffmann struct virtio_gpu_resource_detach_backing { 18353476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 18453476e07SGerd Hoffmann uint32_t resource_id; 18553476e07SGerd Hoffmann uint32_t padding; 18653476e07SGerd Hoffmann }; 18753476e07SGerd Hoffmann 18853476e07SGerd Hoffmann /* VIRTIO_GPU_RESP_OK_DISPLAY_INFO */ 18953476e07SGerd Hoffmann #define VIRTIO_GPU_MAX_SCANOUTS 16 19053476e07SGerd Hoffmann struct virtio_gpu_resp_display_info { 19153476e07SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 19253476e07SGerd Hoffmann struct virtio_gpu_display_one { 19353476e07SGerd Hoffmann struct virtio_gpu_rect r; 19453476e07SGerd Hoffmann uint32_t enabled; 19553476e07SGerd Hoffmann uint32_t flags; 19653476e07SGerd Hoffmann } pmodes[VIRTIO_GPU_MAX_SCANOUTS]; 19753476e07SGerd Hoffmann }; 19853476e07SGerd Hoffmann 199*bc79e964SGerd Hoffmann /* data passed in the control vq, 3d related */ 200*bc79e964SGerd Hoffmann 201*bc79e964SGerd Hoffmann struct virtio_gpu_box { 202*bc79e964SGerd Hoffmann uint32_t x, y, z; 203*bc79e964SGerd Hoffmann uint32_t w, h, d; 204*bc79e964SGerd Hoffmann }; 205*bc79e964SGerd Hoffmann 206*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_TRANSFER_TO_HOST_3D, VIRTIO_GPU_CMD_TRANSFER_FROM_HOST_3D */ 207*bc79e964SGerd Hoffmann struct virtio_gpu_transfer_host_3d { 208*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 209*bc79e964SGerd Hoffmann struct virtio_gpu_box box; 210*bc79e964SGerd Hoffmann uint64_t offset; 211*bc79e964SGerd Hoffmann uint32_t resource_id; 212*bc79e964SGerd Hoffmann uint32_t level; 213*bc79e964SGerd Hoffmann uint32_t stride; 214*bc79e964SGerd Hoffmann uint32_t layer_stride; 215*bc79e964SGerd Hoffmann }; 216*bc79e964SGerd Hoffmann 217*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_RESOURCE_CREATE_3D */ 218*bc79e964SGerd Hoffmann #define VIRTIO_GPU_RESOURCE_FLAG_Y_0_TOP (1 << 0) 219*bc79e964SGerd Hoffmann struct virtio_gpu_resource_create_3d { 220*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 221*bc79e964SGerd Hoffmann uint32_t resource_id; 222*bc79e964SGerd Hoffmann uint32_t target; 223*bc79e964SGerd Hoffmann uint32_t format; 224*bc79e964SGerd Hoffmann uint32_t bind; 225*bc79e964SGerd Hoffmann uint32_t width; 226*bc79e964SGerd Hoffmann uint32_t height; 227*bc79e964SGerd Hoffmann uint32_t depth; 228*bc79e964SGerd Hoffmann uint32_t array_size; 229*bc79e964SGerd Hoffmann uint32_t last_level; 230*bc79e964SGerd Hoffmann uint32_t nr_samples; 231*bc79e964SGerd Hoffmann uint32_t flags; 232*bc79e964SGerd Hoffmann uint32_t padding; 233*bc79e964SGerd Hoffmann }; 234*bc79e964SGerd Hoffmann 235*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_CTX_CREATE */ 236*bc79e964SGerd Hoffmann struct virtio_gpu_ctx_create { 237*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 238*bc79e964SGerd Hoffmann uint32_t nlen; 239*bc79e964SGerd Hoffmann uint32_t padding; 240*bc79e964SGerd Hoffmann char debug_name[64]; 241*bc79e964SGerd Hoffmann }; 242*bc79e964SGerd Hoffmann 243*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_CTX_DESTROY */ 244*bc79e964SGerd Hoffmann struct virtio_gpu_ctx_destroy { 245*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 246*bc79e964SGerd Hoffmann }; 247*bc79e964SGerd Hoffmann 248*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_CTX_ATTACH_RESOURCE, VIRTIO_GPU_CMD_CTX_DETACH_RESOURCE */ 249*bc79e964SGerd Hoffmann struct virtio_gpu_ctx_resource { 250*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 251*bc79e964SGerd Hoffmann uint32_t resource_id; 252*bc79e964SGerd Hoffmann uint32_t padding; 253*bc79e964SGerd Hoffmann }; 254*bc79e964SGerd Hoffmann 255*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_SUBMIT_3D */ 256*bc79e964SGerd Hoffmann struct virtio_gpu_cmd_submit { 257*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 258*bc79e964SGerd Hoffmann uint32_t size; 259*bc79e964SGerd Hoffmann uint32_t padding; 260*bc79e964SGerd Hoffmann }; 261*bc79e964SGerd Hoffmann 262*bc79e964SGerd Hoffmann #define VIRTIO_GPU_CAPSET_VIRGL 1 263*bc79e964SGerd Hoffmann 264*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_GET_CAPSET_INFO */ 265*bc79e964SGerd Hoffmann struct virtio_gpu_get_capset_info { 266*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 267*bc79e964SGerd Hoffmann uint32_t capset_index; 268*bc79e964SGerd Hoffmann uint32_t padding; 269*bc79e964SGerd Hoffmann }; 270*bc79e964SGerd Hoffmann 271*bc79e964SGerd Hoffmann /* VIRTIO_GPU_RESP_OK_CAPSET_INFO */ 272*bc79e964SGerd Hoffmann struct virtio_gpu_resp_capset_info { 273*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 274*bc79e964SGerd Hoffmann uint32_t capset_id; 275*bc79e964SGerd Hoffmann uint32_t capset_max_version; 276*bc79e964SGerd Hoffmann uint32_t capset_max_size; 277*bc79e964SGerd Hoffmann uint32_t padding; 278*bc79e964SGerd Hoffmann }; 279*bc79e964SGerd Hoffmann 280*bc79e964SGerd Hoffmann /* VIRTIO_GPU_CMD_GET_CAPSET */ 281*bc79e964SGerd Hoffmann struct virtio_gpu_get_capset { 282*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 283*bc79e964SGerd Hoffmann uint32_t capset_id; 284*bc79e964SGerd Hoffmann uint32_t capset_version; 285*bc79e964SGerd Hoffmann }; 286*bc79e964SGerd Hoffmann 287*bc79e964SGerd Hoffmann /* VIRTIO_GPU_RESP_OK_CAPSET */ 288*bc79e964SGerd Hoffmann struct virtio_gpu_resp_capset { 289*bc79e964SGerd Hoffmann struct virtio_gpu_ctrl_hdr hdr; 290*bc79e964SGerd Hoffmann uint8_t capset_data[]; 291*bc79e964SGerd Hoffmann }; 292*bc79e964SGerd Hoffmann 29353476e07SGerd Hoffmann #define VIRTIO_GPU_EVENT_DISPLAY (1 << 0) 29453476e07SGerd Hoffmann 29553476e07SGerd Hoffmann struct virtio_gpu_config { 29653476e07SGerd Hoffmann uint32_t events_read; 29753476e07SGerd Hoffmann uint32_t events_clear; 29853476e07SGerd Hoffmann uint32_t num_scanouts; 299*bc79e964SGerd Hoffmann uint32_t num_capsets; 30053476e07SGerd Hoffmann }; 30153476e07SGerd Hoffmann 30253476e07SGerd Hoffmann /* simple formats for fbcon/X use */ 30353476e07SGerd Hoffmann enum virtio_gpu_formats { 30453476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_B8G8R8A8_UNORM = 1, 30553476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_B8G8R8X8_UNORM = 2, 30653476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_A8R8G8B8_UNORM = 3, 30753476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_X8R8G8B8_UNORM = 4, 30853476e07SGerd Hoffmann 30953476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_R8G8B8A8_UNORM = 67, 31053476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_X8B8G8R8_UNORM = 68, 31153476e07SGerd Hoffmann 31253476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_A8B8G8R8_UNORM = 121, 31353476e07SGerd Hoffmann VIRTIO_GPU_FORMAT_R8G8B8X8_UNORM = 134, 31453476e07SGerd Hoffmann }; 31553476e07SGerd Hoffmann 31653476e07SGerd Hoffmann #endif 317