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 _QEMU_VIRTIO_VGA_H
15 #define _QEMU_VIRTIO_VGA_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"
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)
28 #define VIRTIO_ID_GPU 16
30 #define VIRTIO_GPU_MAX_SCANOUT 4
32 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 QEMUCursor
*current_cursor
;
54 struct virtio_gpu_requested_state
{
55 uint32_t width
, height
;
59 enum virtio_gpu_conf_flags
{
60 VIRTIO_GPU_FLAG_VIRGL_ENABLED
= 1,
61 VIRTIO_GPU_FLAG_STATS_ENABLED
,
64 #define virtio_gpu_virgl_enabled(_cfg) \
65 (_cfg.flags & (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED))
66 #define virtio_gpu_stats_enabled(_cfg) \
67 (_cfg.flags & (1 << VIRTIO_GPU_FLAG_STATS_ENABLED))
69 struct virtio_gpu_conf
{
74 struct virtio_gpu_ctrl_command
{
75 VirtQueueElement elem
;
77 struct virtio_gpu_ctrl_hdr cmd_hdr
;
80 QTAILQ_ENTRY(virtio_gpu_ctrl_command
) next
;
83 typedef struct VirtIOGPU
{
84 VirtIODevice parent_obj
;
96 QTAILQ_HEAD(, virtio_gpu_simple_resource
) reslist
;
97 QTAILQ_HEAD(, virtio_gpu_ctrl_command
) cmdq
;
98 QTAILQ_HEAD(, virtio_gpu_ctrl_command
) fenceq
;
100 struct virtio_gpu_scanout scanout
[VIRTIO_GPU_MAX_SCANOUT
];
101 struct virtio_gpu_requested_state req_state
[VIRTIO_GPU_MAX_SCANOUT
];
103 struct virtio_gpu_conf conf
;
104 int enabled_output_bitmask
;
105 struct virtio_gpu_config virtio_config
;
107 bool use_virgl_renderer
;
108 bool renderer_inited
;
109 QEMUTimer
*fence_poll
;
110 QEMUTimer
*print_stats
;
114 uint32_t max_inflight
;
121 extern const GraphicHwOps virtio_gpu_ops
;
123 /* to share between PCI and VGA */
124 #define DEFINE_VIRTIO_GPU_PCI_PROPERTIES(_state) \
125 DEFINE_PROP_BIT("ioeventfd", _state, flags, \
126 VIRTIO_PCI_FLAG_USE_IOEVENTFD_BIT, false), \
127 DEFINE_PROP_UINT32("vectors", _state, nvectors, 3)
129 #define VIRTIO_GPU_FILL_CMD(out) do { \
131 s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
132 &out, sizeof(out)); \
133 if (s != sizeof(out)) { \
134 qemu_log_mask(LOG_GUEST_ERROR, \
135 "%s: command size incorrect %zu vs %zu\n", \
136 __func__, s, sizeof(out)); \
142 void virtio_gpu_ctrl_response(VirtIOGPU
*g
,
143 struct virtio_gpu_ctrl_command
*cmd
,
144 struct virtio_gpu_ctrl_hdr
*resp
,
146 void virtio_gpu_ctrl_response_nodata(VirtIOGPU
*g
,
147 struct virtio_gpu_ctrl_command
*cmd
,
148 enum virtio_gpu_ctrl_type type
);
149 void virtio_gpu_get_display_info(VirtIOGPU
*g
,
150 struct virtio_gpu_ctrl_command
*cmd
);
151 int virtio_gpu_create_mapping_iov(struct virtio_gpu_resource_attach_backing
*ab
,
152 struct virtio_gpu_ctrl_command
*cmd
,
154 void virtio_gpu_cleanup_mapping_iov(struct iovec
*iov
, uint32_t count
);
156 /* virtio-gpu-3d.c */
157 void virtio_gpu_virgl_process_cmd(VirtIOGPU
*g
,
158 struct virtio_gpu_ctrl_command
*cmd
);
159 void virtio_gpu_virgl_fence_poll(VirtIOGPU
*g
);
160 void virtio_gpu_virgl_reset(VirtIOGPU
*g
);
161 int virtio_gpu_virgl_init(VirtIOGPU
*g
);