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 or later.
11 * See the COPYING file in the top-level directory.
14 #include "qemu/osdep.h"
16 #include "qemu/module.h"
17 #include "qemu/error-report.h"
18 #include "qapi/error.h"
19 #include "sysemu/sysemu.h"
20 #include "hw/virtio/virtio.h"
21 #include "hw/virtio/virtio-gpu.h"
22 #include "hw/virtio/virtio-gpu-bswap.h"
23 #include "hw/virtio/virtio-gpu-pixman.h"
24 #include "hw/qdev-properties.h"
26 static void virtio_gpu_gl_process_cmd(VirtIOGPU
*g
,
27 struct virtio_gpu_ctrl_command
*cmd
)
29 if (g
->parent_obj
.use_virgl_renderer
) {
30 virtio_gpu_virgl_process_cmd(g
, cmd
);
33 virtio_gpu_simple_process_cmd(g
, cmd
);
36 static void virtio_gpu_gl_flushed(VirtIOGPUBase
*b
)
38 VirtIOGPU
*g
= VIRTIO_GPU(b
);
40 if (g
->renderer_reset
) {
41 g
->renderer_reset
= false;
42 virtio_gpu_virgl_reset(g
);
44 virtio_gpu_process_cmdq(g
);
47 static void virtio_gpu_gl_handle_ctrl(VirtIODevice
*vdev
, VirtQueue
*vq
)
49 VirtIOGPU
*g
= VIRTIO_GPU(vdev
);
50 struct virtio_gpu_ctrl_command
*cmd
;
52 if (!virtio_queue_ready(vq
)) {
56 if (!g
->renderer_inited
&& g
->parent_obj
.use_virgl_renderer
) {
57 virtio_gpu_virgl_init(g
);
58 g
->renderer_inited
= true;
61 cmd
= virtqueue_pop(vq
, sizeof(struct virtio_gpu_ctrl_command
));
65 cmd
->finished
= false;
66 QTAILQ_INSERT_TAIL(&g
->cmdq
, cmd
, next
);
67 cmd
= virtqueue_pop(vq
, sizeof(struct virtio_gpu_ctrl_command
));
70 virtio_gpu_process_cmdq(g
);
72 if (g
->parent_obj
.use_virgl_renderer
) {
73 virtio_gpu_virgl_fence_poll(g
);
77 static void virtio_gpu_gl_reset(VirtIODevice
*vdev
)
79 VirtIOGPU
*g
= VIRTIO_GPU(vdev
);
81 virtio_gpu_reset(vdev
);
83 if (g
->parent_obj
.use_virgl_renderer
) {
84 if (g
->parent_obj
.renderer_blocked
) {
85 g
->renderer_reset
= true;
87 virtio_gpu_virgl_reset(g
);
89 g
->parent_obj
.use_virgl_renderer
= false;
93 static void virtio_gpu_gl_device_realize(DeviceState
*qdev
, Error
**errp
)
95 VirtIOGPU
*g
= VIRTIO_GPU(qdev
);
97 #if defined(HOST_WORDS_BIGENDIAN)
98 error_setg(errp
, "virgl is not supported on bigendian platforms");
102 if (!display_opengl
) {
103 error_setg(errp
, "opengl is not available");
107 g
->parent_obj
.conf
.flags
|= (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED
);
108 VIRTIO_GPU_BASE(g
)->virtio_config
.num_capsets
=
109 virtio_gpu_virgl_get_num_capsets(g
);
111 virtio_gpu_device_realize(qdev
, errp
);
114 static Property virtio_gpu_gl_properties
[] = {
115 DEFINE_PROP_BIT("stats", VirtIOGPU
, parent_obj
.conf
.flags
,
116 VIRTIO_GPU_FLAG_STATS_ENABLED
, false),
117 DEFINE_PROP_END_OF_LIST(),
120 static void virtio_gpu_gl_class_init(ObjectClass
*klass
, void *data
)
122 DeviceClass
*dc
= DEVICE_CLASS(klass
);
123 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_CLASS(klass
);
124 VirtIOGPUBaseClass
*vbc
= VIRTIO_GPU_BASE_CLASS(klass
);
125 VirtIOGPUClass
*vgc
= VIRTIO_GPU_CLASS(klass
);
127 vbc
->gl_flushed
= virtio_gpu_gl_flushed
;
128 vgc
->handle_ctrl
= virtio_gpu_gl_handle_ctrl
;
129 vgc
->process_cmd
= virtio_gpu_gl_process_cmd
;
131 vdc
->realize
= virtio_gpu_gl_device_realize
;
132 vdc
->reset
= virtio_gpu_gl_reset
;
133 device_class_set_props(dc
, virtio_gpu_gl_properties
);
136 static const TypeInfo virtio_gpu_gl_info
= {
137 .name
= TYPE_VIRTIO_GPU_GL
,
138 .parent
= TYPE_VIRTIO_GPU
,
139 .instance_size
= sizeof(VirtIOGPUGL
),
140 .class_init
= virtio_gpu_gl_class_init
,
143 static void virtio_register_types(void)
145 type_register_static(&virtio_gpu_gl_info
);
148 type_init(virtio_register_types
)