2014-09-10 16:12:28 +04:00
|
|
|
/*
|
|
|
|
* Virtio GPU Device
|
|
|
|
*
|
|
|
|
* Copyright Red Hat, Inc. 2013-2014
|
|
|
|
*
|
|
|
|
* Authors:
|
|
|
|
* Dave Airlie <airlied@redhat.com>
|
|
|
|
* Gerd Hoffmann <kraxel@redhat.com>
|
|
|
|
*
|
|
|
|
* This work is licensed under the terms of the GNU GPL, version 2.
|
|
|
|
* See the COPYING file in the top-level directory.
|
|
|
|
*/
|
|
|
|
|
2016-06-29 11:12:57 +03:00
|
|
|
#ifndef HW_VIRTIO_GPU_H
|
|
|
|
#define HW_VIRTIO_GPU_H
|
2014-09-10 16:12:28 +04:00
|
|
|
|
|
|
|
#include "qemu/queue.h"
|
|
|
|
#include "ui/qemu-pixman.h"
|
|
|
|
#include "ui/console.h"
|
|
|
|
#include "hw/virtio/virtio.h"
|
2016-08-08 12:31:40 +03:00
|
|
|
#include "qemu/log.h"
|
2019-05-24 16:09:46 +03:00
|
|
|
#include "sysemu/vhost-user-backend.h"
|
2014-09-10 16:12:28 +04:00
|
|
|
|
|
|
|
#include "standard-headers/linux/virtio_gpu.h"
|
2020-09-03 23:43:22 +03:00
|
|
|
#include "qom/object.h"
|
2018-05-25 16:27:50 +03:00
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
#define TYPE_VIRTIO_GPU_BASE "virtio-gpu-base"
|
2020-09-01 00:07:37 +03:00
|
|
|
OBJECT_DECLARE_TYPE(VirtIOGPUBase, VirtIOGPUBaseClass,
|
qom: Remove module_obj_name parameter from OBJECT_DECLARE* macros
One of the goals of having less boilerplate on QOM declarations
is to avoid human error. Requiring an extra argument that is
never used is an opportunity for mistakes.
Remove the unused argument from OBJECT_DECLARE_TYPE and
OBJECT_DECLARE_SIMPLE_TYPE.
Coccinelle patch used to convert all users of the macros:
@@
declarer name OBJECT_DECLARE_TYPE;
identifier InstanceType, ClassType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_TYPE(InstanceType, ClassType,
- lowercase,
UPPERCASE);
@@
declarer name OBJECT_DECLARE_SIMPLE_TYPE;
identifier InstanceType, lowercase, UPPERCASE;
@@
OBJECT_DECLARE_SIMPLE_TYPE(InstanceType,
- lowercase,
UPPERCASE);
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
Reviewed-by: Cédric Le Goater <clg@kaod.org>
Acked-by: Cornelia Huck <cohuck@redhat.com>
Acked-by: Igor Mammedov <imammedo@redhat.com>
Acked-by: Paul Durrant <paul@xen.org>
Acked-by: Thomas Huth <thuth@redhat.com>
Message-Id: <20200916182519.415636-4-ehabkost@redhat.com>
Signed-off-by: Eduardo Habkost <ehabkost@redhat.com>
2020-09-16 21:25:17 +03:00
|
|
|
VIRTIO_GPU_BASE)
|
2019-05-24 16:09:44 +03:00
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
#define TYPE_VIRTIO_GPU "virtio-gpu-device"
|
2021-04-30 14:35:36 +03:00
|
|
|
OBJECT_DECLARE_TYPE(VirtIOGPU, VirtIOGPUClass, VIRTIO_GPU)
|
2014-09-10 16:12:28 +04:00
|
|
|
|
2021-04-30 14:35:33 +03:00
|
|
|
#define TYPE_VIRTIO_GPU_GL "virtio-gpu-gl-device"
|
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VirtIOGPUGL, VIRTIO_GPU_GL)
|
|
|
|
|
2019-05-24 16:09:46 +03:00
|
|
|
#define TYPE_VHOST_USER_GPU "vhost-user-gpu"
|
2020-09-16 21:25:19 +03:00
|
|
|
OBJECT_DECLARE_SIMPLE_TYPE(VhostUserGPU, VHOST_USER_GPU)
|
2019-05-24 16:09:46 +03:00
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
#define VIRTIO_ID_GPU 16
|
|
|
|
|
|
|
|
struct virtio_gpu_simple_resource {
|
|
|
|
uint32_t resource_id;
|
|
|
|
uint32_t width;
|
|
|
|
uint32_t height;
|
|
|
|
uint32_t format;
|
2016-05-23 16:22:07 +03:00
|
|
|
uint64_t *addrs;
|
2014-09-10 16:12:28 +04:00
|
|
|
struct iovec *iov;
|
|
|
|
unsigned int iov_cnt;
|
|
|
|
uint32_t scanout_bitmask;
|
|
|
|
pixman_image_t *image;
|
2016-11-29 15:42:36 +03:00
|
|
|
uint64_t hostmem;
|
2021-05-27 02:14:18 +03:00
|
|
|
|
|
|
|
uint64_t blob_size;
|
|
|
|
void *blob;
|
|
|
|
int dmabuf_fd;
|
|
|
|
uint8_t *remapped;
|
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
QTAILQ_ENTRY(virtio_gpu_simple_resource) next;
|
|
|
|
};
|
|
|
|
|
2021-05-27 02:14:21 +03:00
|
|
|
struct virtio_gpu_framebuffer {
|
|
|
|
pixman_format_code_t format;
|
|
|
|
uint32_t bytes_pp;
|
|
|
|
uint32_t width, height;
|
|
|
|
uint32_t stride;
|
|
|
|
uint32_t offset;
|
|
|
|
};
|
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
struct virtio_gpu_scanout {
|
|
|
|
QemuConsole *con;
|
|
|
|
DisplaySurface *ds;
|
|
|
|
uint32_t width, height;
|
|
|
|
int x, y;
|
|
|
|
int invalidate;
|
|
|
|
uint32_t resource_id;
|
2016-05-23 16:22:07 +03:00
|
|
|
struct virtio_gpu_update_cursor cursor;
|
2014-09-10 16:12:28 +04:00
|
|
|
QEMUCursor *current_cursor;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct virtio_gpu_requested_state {
|
2020-09-27 17:57:51 +03:00
|
|
|
uint16_t width_mm, height_mm;
|
2014-09-10 16:12:28 +04:00
|
|
|
uint32_t width, height;
|
|
|
|
int x, y;
|
|
|
|
};
|
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
enum virtio_gpu_base_conf_flags {
|
2014-07-11 14:51:43 +04:00
|
|
|
VIRTIO_GPU_FLAG_VIRGL_ENABLED = 1,
|
|
|
|
VIRTIO_GPU_FLAG_STATS_ENABLED,
|
2019-02-21 11:10:54 +03:00
|
|
|
VIRTIO_GPU_FLAG_EDID_ENABLED,
|
2021-02-04 13:52:22 +03:00
|
|
|
VIRTIO_GPU_FLAG_DMABUF_ENABLED,
|
2021-05-27 02:14:23 +03:00
|
|
|
VIRTIO_GPU_FLAG_BLOB_ENABLED,
|
2014-07-11 14:51:43 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
#define virtio_gpu_virgl_enabled(_cfg) \
|
|
|
|
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED))
|
|
|
|
#define virtio_gpu_stats_enabled(_cfg) \
|
|
|
|
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_STATS_ENABLED))
|
2019-02-21 11:10:54 +03:00
|
|
|
#define virtio_gpu_edid_enabled(_cfg) \
|
|
|
|
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_EDID_ENABLED))
|
2021-02-04 13:52:22 +03:00
|
|
|
#define virtio_gpu_dmabuf_enabled(_cfg) \
|
|
|
|
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_DMABUF_ENABLED))
|
2021-05-27 02:14:23 +03:00
|
|
|
#define virtio_gpu_blob_enabled(_cfg) \
|
|
|
|
(_cfg.flags & (1 << VIRTIO_GPU_FLAG_BLOB_ENABLED))
|
2014-07-11 14:51:43 +04:00
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
struct virtio_gpu_base_conf {
|
2014-09-10 16:12:28 +04:00
|
|
|
uint32_t max_outputs;
|
2014-07-11 14:51:43 +04:00
|
|
|
uint32_t flags;
|
2017-04-21 12:22:14 +03:00
|
|
|
uint32_t xres;
|
|
|
|
uint32_t yres;
|
2014-09-10 16:12:28 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
struct virtio_gpu_ctrl_command {
|
|
|
|
VirtQueueElement elem;
|
|
|
|
VirtQueue *vq;
|
|
|
|
struct virtio_gpu_ctrl_hdr cmd_hdr;
|
|
|
|
uint32_t error;
|
|
|
|
bool finished;
|
|
|
|
QTAILQ_ENTRY(virtio_gpu_ctrl_command) next;
|
|
|
|
};
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtIOGPUBase {
|
2014-09-10 16:12:28 +04:00
|
|
|
VirtIODevice parent_obj;
|
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
Error *migration_blocker;
|
|
|
|
|
|
|
|
struct virtio_gpu_base_conf conf;
|
|
|
|
struct virtio_gpu_config virtio_config;
|
2020-09-14 16:42:23 +03:00
|
|
|
const GraphicHwOps *hw_ops;
|
2019-05-24 16:09:44 +03:00
|
|
|
|
|
|
|
int renderer_blocked;
|
|
|
|
int enable;
|
|
|
|
|
|
|
|
struct virtio_gpu_scanout scanout[VIRTIO_GPU_MAX_SCANOUTS];
|
|
|
|
|
|
|
|
int enabled_output_bitmask;
|
|
|
|
struct virtio_gpu_requested_state req_state[VIRTIO_GPU_MAX_SCANOUTS];
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-05-24 16:09:44 +03:00
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtIOGPUBaseClass {
|
2019-05-24 16:09:44 +03:00
|
|
|
VirtioDeviceClass parent;
|
|
|
|
|
2021-02-04 13:52:30 +03:00
|
|
|
void (*gl_flushed)(VirtIOGPUBase *g);
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-05-24 16:09:44 +03:00
|
|
|
|
|
|
|
#define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf) \
|
|
|
|
DEFINE_PROP_UINT32("max_outputs", _state, _conf.max_outputs, 1), \
|
|
|
|
DEFINE_PROP_BIT("edid", _state, _conf.flags, \
|
2019-06-07 11:34:44 +03:00
|
|
|
VIRTIO_GPU_FLAG_EDID_ENABLED, true), \
|
2019-05-24 16:09:44 +03:00
|
|
|
DEFINE_PROP_UINT32("xres", _state, _conf.xres, 1024), \
|
|
|
|
DEFINE_PROP_UINT32("yres", _state, _conf.yres, 768)
|
|
|
|
|
2021-05-27 02:14:26 +03:00
|
|
|
typedef struct VGPUDMABuf {
|
|
|
|
QemuDmaBuf buf;
|
|
|
|
uint32_t scanout_id;
|
|
|
|
QTAILQ_ENTRY(VGPUDMABuf) next;
|
|
|
|
} VGPUDMABuf;
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VirtIOGPU {
|
2019-05-24 16:09:44 +03:00
|
|
|
VirtIOGPUBase parent_obj;
|
|
|
|
|
|
|
|
uint64_t conf_max_hostmem;
|
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
VirtQueue *ctrl_vq;
|
|
|
|
VirtQueue *cursor_vq;
|
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
QEMUBH *ctrl_bh;
|
|
|
|
QEMUBH *cursor_bh;
|
2014-09-10 16:12:28 +04:00
|
|
|
|
|
|
|
QTAILQ_HEAD(, virtio_gpu_simple_resource) reslist;
|
2015-12-01 14:05:14 +03:00
|
|
|
QTAILQ_HEAD(, virtio_gpu_ctrl_command) cmdq;
|
2014-09-10 16:12:28 +04:00
|
|
|
QTAILQ_HEAD(, virtio_gpu_ctrl_command) fenceq;
|
|
|
|
|
2016-11-29 15:42:36 +03:00
|
|
|
uint64_t hostmem;
|
2014-09-10 16:12:28 +04:00
|
|
|
|
2021-02-04 13:52:29 +03:00
|
|
|
bool processing_cmdq;
|
2014-09-10 16:12:28 +04:00
|
|
|
QEMUTimer *fence_poll;
|
|
|
|
QEMUTimer *print_stats;
|
|
|
|
|
2014-07-11 14:51:43 +04:00
|
|
|
uint32_t inflight;
|
2014-09-10 16:12:28 +04:00
|
|
|
struct {
|
|
|
|
uint32_t max_inflight;
|
|
|
|
uint32_t requests;
|
|
|
|
uint32_t req_3d;
|
|
|
|
uint32_t bytes_3d;
|
|
|
|
} stats;
|
2021-05-27 02:14:26 +03:00
|
|
|
|
|
|
|
struct {
|
|
|
|
QTAILQ_HEAD(, VGPUDMABuf) bufs;
|
2021-11-04 09:51:52 +03:00
|
|
|
VGPUDMABuf *primary[VIRTIO_GPU_MAX_SCANOUTS];
|
2021-05-27 02:14:26 +03:00
|
|
|
} dmabuf;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2014-09-10 16:12:28 +04:00
|
|
|
|
2021-04-30 14:35:36 +03:00
|
|
|
struct VirtIOGPUClass {
|
|
|
|
VirtIOGPUBaseClass parent;
|
|
|
|
|
|
|
|
void (*handle_ctrl)(VirtIODevice *vdev, VirtQueue *vq);
|
2021-04-30 14:35:39 +03:00
|
|
|
void (*process_cmd)(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd);
|
2021-04-30 14:35:40 +03:00
|
|
|
void (*update_cursor_data)(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_scanout *s,
|
|
|
|
uint32_t resource_id);
|
2021-04-30 14:35:36 +03:00
|
|
|
};
|
|
|
|
|
2021-04-30 14:35:33 +03:00
|
|
|
struct VirtIOGPUGL {
|
|
|
|
struct VirtIOGPU parent_obj;
|
2021-04-30 14:35:44 +03:00
|
|
|
|
|
|
|
bool renderer_inited;
|
|
|
|
bool renderer_reset;
|
2021-04-30 14:35:33 +03:00
|
|
|
};
|
|
|
|
|
2020-09-03 23:43:22 +03:00
|
|
|
struct VhostUserGPU {
|
2019-05-24 16:09:46 +03:00
|
|
|
VirtIOGPUBase parent_obj;
|
2014-09-10 16:12:28 +04:00
|
|
|
|
2019-05-24 16:09:46 +03:00
|
|
|
VhostUserBackend *vhost;
|
|
|
|
int vhost_gpu_fd; /* closed by the chardev */
|
|
|
|
CharBackend vhost_chr;
|
|
|
|
QemuDmaBuf dmabuf[VIRTIO_GPU_MAX_SCANOUTS];
|
|
|
|
bool backend_blocked;
|
2020-09-03 23:43:22 +03:00
|
|
|
};
|
2019-05-24 16:09:46 +03:00
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
#define VIRTIO_GPU_FILL_CMD(out) do { \
|
|
|
|
size_t s; \
|
|
|
|
s = iov_to_buf(cmd->elem.out_sg, cmd->elem.out_num, 0, \
|
|
|
|
&out, sizeof(out)); \
|
|
|
|
if (s != sizeof(out)) { \
|
|
|
|
qemu_log_mask(LOG_GUEST_ERROR, \
|
|
|
|
"%s: command size incorrect %zu vs %zu\n", \
|
|
|
|
__func__, s, sizeof(out)); \
|
|
|
|
return; \
|
|
|
|
} \
|
|
|
|
} while (0)
|
|
|
|
|
2019-05-24 16:09:44 +03:00
|
|
|
/* virtio-gpu-base.c */
|
|
|
|
bool virtio_gpu_base_device_realize(DeviceState *qdev,
|
|
|
|
VirtIOHandleOutput ctrl_cb,
|
|
|
|
VirtIOHandleOutput cursor_cb,
|
|
|
|
Error **errp);
|
|
|
|
void virtio_gpu_base_reset(VirtIOGPUBase *g);
|
|
|
|
void virtio_gpu_base_fill_display_info(VirtIOGPUBase *g,
|
|
|
|
struct virtio_gpu_resp_display_info *dpy_info);
|
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
/* virtio-gpu.c */
|
|
|
|
void virtio_gpu_ctrl_response(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_ctrl_command *cmd,
|
|
|
|
struct virtio_gpu_ctrl_hdr *resp,
|
|
|
|
size_t resp_len);
|
|
|
|
void virtio_gpu_ctrl_response_nodata(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_ctrl_command *cmd,
|
|
|
|
enum virtio_gpu_ctrl_type type);
|
|
|
|
void virtio_gpu_get_display_info(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_ctrl_command *cmd);
|
2019-02-21 11:10:54 +03:00
|
|
|
void virtio_gpu_get_edid(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_ctrl_command *cmd);
|
2018-08-29 15:21:00 +03:00
|
|
|
int virtio_gpu_create_mapping_iov(VirtIOGPU *g,
|
2021-05-27 02:14:22 +03:00
|
|
|
uint32_t nr_entries, uint32_t offset,
|
2014-09-10 16:12:28 +04:00
|
|
|
struct virtio_gpu_ctrl_command *cmd,
|
2021-05-06 12:10:01 +03:00
|
|
|
uint64_t **addr, struct iovec **iov,
|
|
|
|
uint32_t *niov);
|
2018-08-29 15:21:00 +03:00
|
|
|
void virtio_gpu_cleanup_mapping_iov(VirtIOGPU *g,
|
|
|
|
struct iovec *iov, uint32_t count);
|
2015-12-01 15:18:38 +03:00
|
|
|
void virtio_gpu_process_cmdq(VirtIOGPU *g);
|
2021-04-30 14:35:34 +03:00
|
|
|
void virtio_gpu_device_realize(DeviceState *qdev, Error **errp);
|
2021-04-30 14:35:35 +03:00
|
|
|
void virtio_gpu_reset(VirtIODevice *vdev);
|
2021-04-30 14:35:39 +03:00
|
|
|
void virtio_gpu_simple_process_cmd(VirtIOGPU *g, struct virtio_gpu_ctrl_command *cmd);
|
2021-04-30 14:35:40 +03:00
|
|
|
void virtio_gpu_update_cursor_data(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_scanout *s,
|
|
|
|
uint32_t resource_id);
|
2014-09-10 16:12:28 +04:00
|
|
|
|
2021-05-27 02:14:18 +03:00
|
|
|
/* virtio-gpu-udmabuf.c */
|
|
|
|
bool virtio_gpu_have_udmabuf(void);
|
|
|
|
void virtio_gpu_init_udmabuf(struct virtio_gpu_simple_resource *res);
|
|
|
|
void virtio_gpu_fini_udmabuf(struct virtio_gpu_simple_resource *res);
|
2021-05-27 02:14:26 +03:00
|
|
|
int virtio_gpu_update_dmabuf(VirtIOGPU *g,
|
|
|
|
uint32_t scanout_id,
|
|
|
|
struct virtio_gpu_simple_resource *res,
|
2021-11-04 09:51:52 +03:00
|
|
|
struct virtio_gpu_framebuffer *fb,
|
|
|
|
struct virtio_gpu_rect *r);
|
2021-05-27 02:14:18 +03:00
|
|
|
|
2014-07-11 14:51:43 +04:00
|
|
|
/* virtio-gpu-3d.c */
|
|
|
|
void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
|
|
|
|
struct virtio_gpu_ctrl_command *cmd);
|
|
|
|
void virtio_gpu_virgl_fence_poll(VirtIOGPU *g);
|
2021-07-02 15:32:21 +03:00
|
|
|
void virtio_gpu_virgl_reset_scanout(VirtIOGPU *g);
|
2014-07-11 14:51:43 +04:00
|
|
|
void virtio_gpu_virgl_reset(VirtIOGPU *g);
|
|
|
|
int virtio_gpu_virgl_init(VirtIOGPU *g);
|
2018-02-23 05:38:14 +03:00
|
|
|
int virtio_gpu_virgl_get_num_capsets(VirtIOGPU *g);
|
2019-05-24 16:09:44 +03:00
|
|
|
|
2014-09-10 16:12:28 +04:00
|
|
|
#endif
|