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 work is licensed under the terms of the GNU GPL, version 2. 11 * See the COPYING file in the top-level directory. 12 */ 13 14 #ifndef _QEMU_VIRTIO_VGA_H 15 #define _QEMU_VIRTIO_VGA_H 16 17 #include "qemu/queue.h" 18 #include "ui/qemu-pixman.h" 19 #include "ui/console.h" 20 #include "hw/virtio/virtio.h" 21 #include "hw/pci/pci.h" 22 23 #include "standard-headers/linux/virtio_gpu.h" 24 #define TYPE_VIRTIO_GPU "virtio-gpu-device" 25 #define VIRTIO_GPU(obj) \ 26 OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU) 27 28 #define VIRTIO_ID_GPU 16 29 30 #define VIRTIO_GPU_MAX_SCANOUT 4 31 32 struct virtio_gpu_simple_resource { 33 uint32_t resource_id; 34 uint32_t width; 35 uint32_t height; 36 uint32_t format; 37 struct iovec *iov; 38 unsigned int iov_cnt; 39 uint32_t scanout_bitmask; 40 pixman_image_t *image; 41 QTAILQ_ENTRY(virtio_gpu_simple_resource) next; 42 }; 43 44 struct virtio_gpu_scanout { 45 QemuConsole *con; 46 DisplaySurface *ds; 47 uint32_t width, height; 48 int x, y; 49 int invalidate; 50 uint32_t resource_id; 51 QEMUCursor *current_cursor; 52 }; 53 54 struct virtio_gpu_requested_state { 55 uint32_t width, height; 56 int x, y; 57 }; 58 59 struct virtio_gpu_conf { 60 uint32_t max_outputs; 61 }; 62 63 struct virtio_gpu_ctrl_command { 64 VirtQueueElement elem; 65 VirtQueue *vq; 66 struct virtio_gpu_ctrl_hdr cmd_hdr; 67 uint32_t error; 68 bool finished; 69 QTAILQ_ENTRY(virtio_gpu_ctrl_command) next; 70 }; 71 72 typedef struct VirtIOGPU { 73 VirtIODevice parent_obj; 74 75 QEMUBH *ctrl_bh; 76 QEMUBH *cursor_bh; 77 VirtQueue *ctrl_vq; 78 VirtQueue *cursor_vq; 79 80 int enable; 81 82 int config_size; 83 DeviceState *qdev; 84 85 QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist; 86 QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq; 87 88 struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUT]; 89 struct virtio_gpu_requested_state req_state[VIRTIO_GPU_MAX_SCANOUT]; 90 91 struct virtio_gpu_conf conf; 92 int enabled_output_bitmask; 93 struct virtio_gpu_config virtio_config; 94 95 QEMUTimer *fence_poll; 96 QEMUTimer *print_stats; 97 98 struct { 99 uint32_t inflight; 100 uint32_t max_inflight; 101 uint32_t requests; 102 uint32_t req_3d; 103 uint32_t bytes_3d; 104 } stats; 105 } VirtIOGPU; 106 107 extern const GraphicHwOps virtio_gpu_ops; 108 109 /* to share between PCI and VGA */ 110 #define DEFINE_VIRTIO_GPU_PCI_PROPERTIES(_state) \ 111 DEFINE_PROP_BIT("ioeventfd", _state, flags, \ 112 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), \ 113 DEFINE_PROP_UINT32("vectors", _state, nvectors, 3) 114 115 #define DEFINE_VIRTIO_GPU_PROPERTIES(_state, _conf_field) \ 116 DEFINE_PROP_UINT32("max_outputs", _state, _conf_field.max_outputs, 1) 117 118 #define VIRTIO_GPU_FILL_CMD(out) do { \ 119 size_t s; \ 120 s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \ 121 &out, sizeof(out)); \ 122 if (s != sizeof(out)) { \ 123 qemu_log_mask(LOG_GUEST_ERROR, \ 124 "%s: command size incorrect %zu vs %zu\n", \ 125 __func__, s, sizeof(out)); \ 126 return; \ 127 } \ 128 } while (0) 129 130 /* virtio-gpu.c */ 131 void virtio_gpu_ctrl_response(VirtIOGPU *g, 132 struct virtio_gpu_ctrl_command *cmd, 133 struct virtio_gpu_ctrl_hdr *resp, 134 size_t resp_len); 135 void virtio_gpu_ctrl_response_nodata(VirtIOGPU *g, 136 struct virtio_gpu_ctrl_command *cmd, 137 enum virtio_gpu_ctrl_type type); 138 void virtio_gpu_get_display_info(VirtIOGPU *g, 139 struct virtio_gpu_ctrl_command *cmd); 140 int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing *ab, 141 struct virtio_gpu_ctrl_command *cmd, 142 struct iovec **iov); 143 void virtio_gpu_cleanup_mapping_iov(struct iovec *iov, uint32_t count); 144 145 #endif 146