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_handle_ctrl(VirtIODevice
*vdev
, VirtQueue
*vq
)
28 VirtIOGPU
*g
= VIRTIO_GPU(vdev
);
29 struct virtio_gpu_ctrl_command
*cmd
;
31 if (!virtio_queue_ready(vq
)) {
35 if (!g
->renderer_inited
&& g
->parent_obj
.use_virgl_renderer
) {
36 virtio_gpu_virgl_init(g
);
37 g
->renderer_inited
= true;
40 cmd
= virtqueue_pop(vq
, sizeof(struct virtio_gpu_ctrl_command
));
44 cmd
->finished
= false;
45 QTAILQ_INSERT_TAIL(&g
->cmdq
, cmd
, next
);
46 cmd
= virtqueue_pop(vq
, sizeof(struct virtio_gpu_ctrl_command
));
49 virtio_gpu_process_cmdq(g
);
51 if (g
->parent_obj
.use_virgl_renderer
) {
52 virtio_gpu_virgl_fence_poll(g
);
56 static void virtio_gpu_gl_reset(VirtIODevice
*vdev
)
58 VirtIOGPU
*g
= VIRTIO_GPU(vdev
);
60 virtio_gpu_reset(vdev
);
62 if (g
->parent_obj
.use_virgl_renderer
) {
63 if (g
->parent_obj
.renderer_blocked
) {
64 g
->renderer_reset
= true;
66 virtio_gpu_virgl_reset(g
);
68 g
->parent_obj
.use_virgl_renderer
= false;
72 static void virtio_gpu_gl_device_realize(DeviceState
*qdev
, Error
**errp
)
74 VirtIOGPU
*g
= VIRTIO_GPU(qdev
);
76 #if defined(HOST_WORDS_BIGENDIAN)
77 error_setg(errp
, "virgl is not supported on bigendian platforms");
81 if (!display_opengl
) {
82 error_setg(errp
, "opengl is not available");
86 g
->parent_obj
.conf
.flags
|= (1 << VIRTIO_GPU_FLAG_VIRGL_ENABLED
);
87 VIRTIO_GPU_BASE(g
)->virtio_config
.num_capsets
=
88 virtio_gpu_virgl_get_num_capsets(g
);
90 virtio_gpu_device_realize(qdev
, errp
);
93 static Property virtio_gpu_gl_properties
[] = {
94 DEFINE_PROP_BIT("stats", VirtIOGPU
, parent_obj
.conf
.flags
,
95 VIRTIO_GPU_FLAG_STATS_ENABLED
, false),
96 DEFINE_PROP_END_OF_LIST(),
99 static void virtio_gpu_gl_class_init(ObjectClass
*klass
, void *data
)
101 DeviceClass
*dc
= DEVICE_CLASS(klass
);
102 VirtioDeviceClass
*vdc
= VIRTIO_DEVICE_CLASS(klass
);
103 VirtIOGPUClass
*vgc
= VIRTIO_GPU_CLASS(klass
);
105 vgc
->handle_ctrl
= virtio_gpu_gl_handle_ctrl
;
107 vdc
->realize
= virtio_gpu_gl_device_realize
;
108 vdc
->reset
= virtio_gpu_gl_reset
;
109 device_class_set_props(dc
, virtio_gpu_gl_properties
);
112 static const TypeInfo virtio_gpu_gl_info
= {
113 .name
= TYPE_VIRTIO_GPU_GL
,
114 .parent
= TYPE_VIRTIO_GPU
,
115 .instance_size
= sizeof(VirtIOGPUGL
),
116 .class_init
= virtio_gpu_gl_class_init
,
119 static void virtio_register_types(void)
121 type_register_static(&virtio_gpu_gl_info
);
124 type_init(virtio_register_types
)