4 * Copyright Red Hat, Inc. 2013-2014
7 * Dave Airlie <airlied@redhat.com>
8 * Gerd Hoffmann <kraxel@redhat.com>
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"
21 #include "hw/pci/pci.h"
24 #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
;
41 QTAILQ_ENTRY(virtio_gpu_simple_resource
) next
;
44 struct virtio_gpu_scanout
{
47 uint32_t width
, height
;
51 struct virtio_gpu_update_cursor cursor
;
52 QEMUCursor
*current_cursor
;
55 struct virtio_gpu_requested_state
{
56 uint32_t width
, height
;
60 enum virtio_gpu_conf_flags
{
61 VIRTIO_GPU_FLAG_VIRGL_ENABLED
= 1,
62 VIRTIO_GPU_FLAG_STATS_ENABLED
,
65 #define virtio_gpu_virgl_enabled(_cfg) \
66 (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED))
67 #define virtio_gpu_stats_enabled(_cfg) \
68 (_cfg.flags & (1 << VIRTIO_GPU_FLAG_STATS_ENABLED))
70 struct virtio_gpu_conf
{
75 struct virtio_gpu_ctrl_command
{
76 VirtQueueElement elem
;
78 struct virtio_gpu_ctrl_hdr cmd_hdr
;
82 QTAILQ_ENTRY(virtio_gpu_ctrl_command
) next
;
85 typedef struct VirtIOGPU
{
86 VirtIODevice parent_obj
;
98 QTAILQ_HEAD(, virtio_gpu_simple_resource
) reslist
;
99 QTAILQ_HEAD(, virtio_gpu_ctrl_command
) cmdq
;
100 QTAILQ_HEAD(, virtio_gpu_ctrl_command
) fenceq
;
102 struct virtio_gpu_scanout scanout
[VIRTIO_GPU_MAX_SCANOUTS
];
103 struct virtio_gpu_requested_state req_state
[VIRTIO_GPU_MAX_SCANOUTS
];
105 struct virtio_gpu_conf conf
;
106 int enabled_output_bitmask
;
107 struct virtio_gpu_config virtio_config
;
109 bool use_virgl_renderer
;
110 bool renderer_inited
;
111 int renderer_blocked
;
112 QEMUTimer
*fence_poll
;
113 QEMUTimer
*print_stats
;
117 uint32_t max_inflight
;
123 Error
*migration_blocker
;
126 extern const GraphicHwOps virtio_gpu_ops
;
128 /* to share between PCI and VGA */
129 #define DEFINE_VIRTIO_GPU_PCI_PROPERTIES(_state) \
130 DEFINE_PROP_BIT("ioeventfd", _state, flags, \
131 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), \
132 DEFINE_PROP_UINT32("vectors", _state, nvectors, 3)
134 #define VIRTIO_GPU_FILL_CMD(out) do { \
136 s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
137 &out, sizeof(out)); \
138 if (s != sizeof(out)) { \
139 qemu_log_mask(LOG_GUEST_ERROR, \
140 "%s: command size incorrect %zu vs %zu\n", \
141 __func__, s, sizeof(out)); \
147 void virtio_gpu_ctrl_response(VirtIOGPU
*g
,
148 struct virtio_gpu_ctrl_command
*cmd
,
149 struct virtio_gpu_ctrl_hdr
*resp
,
151 void virtio_gpu_ctrl_response_nodata(VirtIOGPU
*g
,
152 struct virtio_gpu_ctrl_command
*cmd
,
153 enum virtio_gpu_ctrl_type type
);
154 void virtio_gpu_get_display_info(VirtIOGPU
*g
,
155 struct virtio_gpu_ctrl_command
*cmd
);
156 int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing
*ab
,
157 struct virtio_gpu_ctrl_command
*cmd
,
158 uint64_t **addr
, struct iovec
**iov
);
159 void virtio_gpu_cleanup_mapping_iov(struct iovec
*iov
, uint32_t count
);
160 void virtio_gpu_process_cmdq(VirtIOGPU
*g
);
162 /* virtio-gpu-3d.c */
163 void virtio_gpu_virgl_process_cmd(VirtIOGPU
*g
,
164 struct virtio_gpu_ctrl_command
*cmd
);
165 void virtio_gpu_virgl_fence_poll(VirtIOGPU
*g
);
166 void virtio_gpu_virgl_reset(VirtIOGPU
*g
);
167 int virtio_gpu_virgl_init(VirtIOGPU
*g
);