qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH 2/2] hw/display: fail early when multiple virgl devices are reque


From: marcandre . lureau
Subject: [PATCH 2/2] hw/display: fail early when multiple virgl devices are requested
Date: Thu, 1 Jul 2021 11:18:37 +0400

From: Marc-André Lureau <marcandre.lureau@redhat.com>

This avoids failing to initialize virgl and crashing later on, and clear
the user expectations.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 hw/display/virtio-gpu-gl.c | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index d971b48080..c973d4824b 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -25,6 +25,8 @@
 
 #include <virglrenderer.h>
 
+static int virgl_count = 0;
+
 static void virtio_gpu_gl_update_cursor_data(VirtIOGPU *g,
                                              struct virtio_gpu_scanout *s,
                                              uint32_t resource_id)
@@ -113,6 +115,11 @@ static void virtio_gpu_gl_device_realize(DeviceState 
*qdev, Error **errp)
     return;
 #endif
 
+    if (virgl_count++ > 0) {
+        error_setg(errp, "multiple virgl devices aren't supported yet");
+        return;
+    }
+
     if (!display_opengl) {
         error_setg(errp, "opengl is not available");
         return;
@@ -124,6 +131,10 @@ static void virtio_gpu_gl_device_realize(DeviceState 
*qdev, Error **errp)
 
     virtio_gpu_device_realize(qdev, errp);
 }
+static void virtio_gpu_gl_device_unrealize(DeviceState *dev)
+{
+    virgl_count--;
+}
 
 static Property virtio_gpu_gl_properties[] = {
     DEFINE_PROP_BIT("stats", VirtIOGPU, parent_obj.conf.flags,
@@ -144,6 +155,7 @@ static void virtio_gpu_gl_class_init(ObjectClass *klass, 
void *data)
     vgc->update_cursor_data = virtio_gpu_gl_update_cursor_data;
 
     vdc->realize = virtio_gpu_gl_device_realize;
+    vdc->unrealize = virtio_gpu_gl_device_unrealize;
     vdc->reset = virtio_gpu_gl_reset;
     device_class_set_props(dc, virtio_gpu_gl_properties);
 }
-- 
2.29.0




reply via email to

[Prev in Thread] Current Thread [Next in Thread]