4 * Copyright Red Hat, Inc. 2013-2014
10 * This work is licensed under the terms of the GNU GPL, version 2.
11 * See the COPYING file in the top-level directory.
14 #ifndef HW_VIRTIO_GPU_H
15 #define HW_VIRTIO_GPU_H
17 #include "qemu/queue.h"
18 #include "ui/qemu-pixman.h"
19 #include "ui/console.h"
20 #include "hw/virtio/virtio.h"
23 #include "standard-headers/linux/virtio_gpu.h"
25 #define TYPE_VIRTIO_GPU "virtio-gpu-device"
26 #define VIRTIO_GPU(obj) \
27 OBJECT_CHECK(VirtIOGPU, (obj), TYPE_VIRTIO_GPU)
29 #define VIRTIO_ID_GPU 16
31 struct virtio_gpu_simple_resource {
39 uint32_t scanout_bitmask;
40 pixman_image_t *image;
42 QTAILQ_ENTRY(virtio_gpu_simple_resource) next;
45 struct virtio_gpu_scanout {
48 uint32_t width, height;
52 struct virtio_gpu_update_cursor cursor;
53 QEMUCursor *current_cursor;
56 struct virtio_gpu_requested_state {
57 uint32_t width, height;
61 enum virtio_gpu_conf_flags {
62 VIRTIO_GPU_FLAG_VIRGL_ENABLED = 1,
63 VIRTIO_GPU_FLAG_STATS_ENABLED,
66 #define virtio_gpu_virgl_enabled(_cfg) \
67 (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED))
68 #define virtio_gpu_stats_enabled(_cfg) \
69 (_cfg.flags & (1 << VIRTIO_GPU_FLAG_STATS_ENABLED))
71 struct virtio_gpu_conf {
79 struct virtio_gpu_ctrl_command {
80 VirtQueueElement elem;
82 struct virtio_gpu_ctrl_hdr cmd_hdr;
86 QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
89 typedef struct VirtIOGPU {
90 VirtIODevice parent_obj;
99 QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist;
100 QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq;
101 QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
103 struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS];
104 struct virtio_gpu_requested_state req_state[VIRTIO_GPU_MAX_SCANOUTS];
106 struct virtio_gpu_conf conf;
108 int enabled_output_bitmask;
109 struct virtio_gpu_config virtio_config;
111 bool use_virgl_renderer;
112 bool renderer_inited;
113 int renderer_blocked;
114 QEMUTimer *fence_poll;
115 QEMUTimer *print_stats;
119 uint32_t max_inflight;
125 Error *migration_blocker;
128 extern const GraphicHwOps virtio_gpu_ops;
130 /* to share between PCI and VGA */
131 #define DEFINE_VIRTIO_GPU_PCI_PROPERTIES(_state) \
132 DEFINE_PROP_BIT("ioeventfd", _state, flags, \
133 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), \
134 DEFINE_PROP_UINT32("vectors", _state, nvectors, 3)
136 #define VIRTIO_GPU_FILL_CMD(out) do { \
138 s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
139 &out, sizeof(out)); \
140 if (s != sizeof(out)) { \
141 qemu_log_mask(LOG_GUEST_ERROR, \
142 "%s: command size incorrect %zu vs %zu\n", \
143 __func__, s, sizeof(out)); \
149 void virtio_gpu_reset(VirtIODevice *vdev);
150 void virtio_gpu_ctrl_response(VirtIOGPU *g,
151 struct virtio_gpu_ctrl_command *cmd,
152 struct virtio_gpu_ctrl_hdr *resp,
154 void virtio_gpu_ctrl_response_nodata(VirtIOGPU *g,
155 struct virtio_gpu_ctrl_command *cmd,
156 enum virtio_gpu_ctrl_type type);
157 void virtio_gpu_get_display_info(VirtIOGPU *g,
158 struct virtio_gpu_ctrl_command *cmd);
159 int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
160 struct virtio_gpu_resource_attach_backing *ab,
161 struct virtio_gpu_ctrl_command *cmd,
162 uint64_t **addr, struct iovec **iov);
163 void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
164 struct iovec *iov, uint32_t count);
165 void virtio_gpu_process_cmdq(VirtIOGPU *g);
167 /* virtio-gpu-3d.c */
168 void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
169 struct virtio_gpu_ctrl_command *cmd);
170 void virtio_gpu_virgl_fence_poll(VirtIOGPU *g);
171 void virtio_gpu_virgl_reset(VirtIOGPU *g);
172 int virtio_gpu_virgl_init(VirtIOGPU *g);
173 int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g);