]> git.proxmox.com Git - mirror_qemu.git/blob - hw/display/virtio-gpu-gl.c
virtio-gpu: move virgl process_cmd
[mirror_qemu.git] / hw / display / virtio-gpu-gl.c
1 /*
2 * Virtio GPU Device
3 *
4 * Copyright Red Hat, Inc. 2013-2014
5 *
6 * Authors:
7 * Dave Airlie <airlied@redhat.com>
8 * Gerd Hoffmann <kraxel@redhat.com>
9 *
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.
12 */
13
14 #include "qemu/osdep.h"
15 #include "qemu/iov.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"
25
26 static void virtio_gpu_gl_process_cmd(VirtIOGPU *g,
27 struct virtio_gpu_ctrl_command *cmd)
28 {
29 if (g->parent_obj.use_virgl_renderer) {
30 virtio_gpu_virgl_process_cmd(g, cmd);
31 return;
32 }
33 virtio_gpu_simple_process_cmd(g, cmd);
34 }
35
36 static void virtio_gpu_gl_flushed(VirtIOGPUBase *b)
37 {
38 VirtIOGPU *g = VIRTIO_GPU(b);
39
40 if (g->renderer_reset) {
41 g->renderer_reset = false;
42 virtio_gpu_virgl_reset(g);
43 }
44 virtio_gpu_process_cmdq(g);
45 }
46
47 static void virtio_gpu_gl_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
48 {
49 VirtIOGPU *g = VIRTIO_GPU(vdev);
50 struct virtio_gpu_ctrl_command *cmd;
51
52 if (!virtio_queue_ready(vq)) {
53 return;
54 }
55
56 if (!g->renderer_inited && g->parent_obj.use_virgl_renderer) {
57 virtio_gpu_virgl_init(g);
58 g->renderer_inited = true;
59 }
60
61 cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
62 while (cmd) {
63 cmd->vq = vq;
64 cmd->error = 0;
65 cmd->finished = false;
66 QTAILQ_INSERT_TAIL(&g->cmdq, cmd, next);
67 cmd = virtqueue_pop(vq, sizeof(struct virtio_gpu_ctrl_command));
68 }
69
70 virtio_gpu_process_cmdq(g);
71
72 if (g->parent_obj.use_virgl_renderer) {
73 virtio_gpu_virgl_fence_poll(g);
74 }
75 }
76
77 static void virtio_gpu_gl_reset(VirtIODevice *vdev)
78 {
79 VirtIOGPU *g = VIRTIO_GPU(vdev);
80
81 virtio_gpu_reset(vdev);
82
83 if (g->parent_obj.use_virgl_renderer) {
84 if (g->parent_obj.renderer_blocked) {
85 g->renderer_reset = true;
86 } else {
87 virtio_gpu_virgl_reset(g);
88 }
89 g->parent_obj.use_virgl_renderer = false;
90 }
91 }
92
93 static void virtio_gpu_gl_device_realize(DeviceState *qdev, Error **errp)
94 {
95 VirtIOGPU *g = VIRTIO_GPU(qdev);
96
97 #if defined(HOST_WORDS_BIGENDIAN)
98 error_setg(errp, "virgl is not supported on bigendian platforms");
99 return;
100 #endif
101
102 if (!display_opengl) {
103 error_setg(errp, "opengl is not available");
104 return;
105 }
106
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);
110
111 virtio_gpu_device_realize(qdev, errp);
112 }
113
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(),
118 };
119
120 static void virtio_gpu_gl_class_init(ObjectClass *klass, void *data)
121 {
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);
126
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;
130
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);
134 }
135
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,
141 };
142
143 static void virtio_register_types(void)
144 {
145 type_register_static(&virtio_gpu_gl_info);
146 }
147
148 type_init(virtio_register_types)