qemu-devel
[Top][All Lists]
Advanced

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

[PATCH 25/27] vhost-user-gpu: implement register_dbus_listener()


From: marcandre . lureau
Subject: [PATCH 25/27] vhost-user-gpu: implement register_dbus_listener()
Date: Fri, 12 Mar 2021 14:01:06 +0400

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

Send the listener fd over the vhost-user connection if the backend
supports it.

Signed-off-by: Marc-André Lureau <marcandre.lureau@redhat.com>
---
 include/hw/virtio/virtio-gpu.h |  1 +
 hw/display/vhost-user-gpu.c    | 33 +++++++++++++++++++++++++++++++++
 hw/display/virtio-gpu-base.c   | 14 ++++++++++++++
 hw/display/virtio-vga.c        | 10 ++++++++++
 4 files changed, 58 insertions(+)

diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index fae149235c..bf33c05121 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -122,6 +122,7 @@ struct VirtIOGPUBaseClass {
     VirtioDeviceClass parent;
 
     void (*gl_flushed)(VirtIOGPUBase *g);
+    bool (*register_dbus_listener)(VirtIOGPUBase *g, QemuConsole *con, int fd);
 };
 
 #define VIRTIO_GPU_BASE_PROPERTIES(_state, _conf)                       \
diff --git a/hw/display/vhost-user-gpu.c b/hw/display/vhost-user-gpu.c
index a2a011e9cc..b48ddabcc8 100644
--- a/hw/display/vhost-user-gpu.c
+++ b/hw/display/vhost-user-gpu.c
@@ -370,6 +370,38 @@ vhost_user_gpu_gl_flushed(VirtIOGPUBase *b)
     vhost_user_gpu_update_blocked(VHOST_USER_GPU(g), false);
 }
 
+static bool
+vhost_user_gpu_scanout_idx(VirtIOGPUBase *b, QemuConsole *con, uint8_t *idx)
+{
+    VhostUserGPU *g = VHOST_USER_GPU(b);
+    struct virtio_gpu_scanout *s;
+    uint8_t i;
+
+    for (i = 0; i < G_N_ELEMENTS(g->parent_obj.scanout); i++) {
+        s = &g->parent_obj.scanout[i];
+        if (s->con == con) {
+            *idx = i;
+            return true;
+        }
+    }
+
+    return false;
+}
+
+static bool
+vhost_user_gpu_do_register_dbus_listener(VirtIOGPUBase *b, QemuConsole *con, 
int fd)
+{
+    VhostUserGPU *g = VHOST_USER_GPU(b);
+    uint8_t idx = 0;
+
+    if (!vhost_user_gpu_scanout_idx(b, con, &idx)) {
+        error_report("Failed to find attached console %p", con);
+        return false;
+    }
+
+    return vhost_user_gpu_register_dbus_listener(&g->vhost->dev, idx, fd) == 0;
+}
+
 static bool
 vhost_user_gpu_do_set_socket(VhostUserGPU *g, Error **errp)
 {
@@ -577,6 +609,7 @@ vhost_user_gpu_class_init(ObjectClass *klass, void *data)
     VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_CLASS(klass);
 
     vgc->gl_flushed = vhost_user_gpu_gl_flushed;
+    vgc->register_dbus_listener = vhost_user_gpu_do_register_dbus_listener;
 
     vdc->realize = vhost_user_gpu_device_realize;
     vdc->reset = vhost_user_gpu_reset;
diff --git a/hw/display/virtio-gpu-base.c b/hw/display/virtio-gpu-base.c
index ee2753001a..392719a830 100644
--- a/hw/display/virtio-gpu-base.c
+++ b/hw/display/virtio-gpu-base.c
@@ -141,6 +141,19 @@ virtio_gpu_get_flags(void *opaque)
     return flags;
 }
 
+static bool
+virtio_gpu_register_dbus_listener(void *opaque, QemuConsole *con, int fd)
+{
+    VirtIOGPUBase *g = opaque;
+    VirtIOGPUBaseClass *vgc = VIRTIO_GPU_BASE_GET_CLASS(g);
+
+    if (vgc->register_dbus_listener) {
+        return vgc->register_dbus_listener(g, con, fd);
+    }
+
+    return false;
+}
+
 static const GraphicHwOps virtio_gpu_ops = {
     .get_flags = virtio_gpu_get_flags,
     .invalidate = virtio_gpu_invalidate_display,
@@ -148,6 +161,7 @@ static const GraphicHwOps virtio_gpu_ops = {
     .text_update = virtio_gpu_text_update,
     .ui_info = virtio_gpu_ui_info,
     .gl_block = virtio_gpu_gl_block,
+    .register_dbus_listener = virtio_gpu_register_dbus_listener,
 };
 
 bool
diff --git a/hw/display/virtio-vga.c b/hw/display/virtio-vga.c
index b071909b68..777c7fc409 100644
--- a/hw/display/virtio-vga.c
+++ b/hw/display/virtio-vga.c
@@ -76,6 +76,15 @@ static int virtio_vga_base_get_flags(void *opaque)
     return g->hw_ops->get_flags(g);
 }
 
+static bool virtio_vga_base_register_dbus_listener(void *opaque,
+                                                   QemuConsole *con, int fd)
+{
+    VirtIOVGABase *vvga = opaque;
+    VirtIOGPUBase *g = vvga->vgpu;
+
+    return g->hw_ops->register_dbus_listener(g, con, fd);
+}
+
 static const GraphicHwOps virtio_vga_base_ops = {
     .get_flags = virtio_vga_base_get_flags,
     .invalidate = virtio_vga_base_invalidate_display,
@@ -83,6 +92,7 @@ static const GraphicHwOps virtio_vga_base_ops = {
     .text_update = virtio_vga_base_text_update,
     .ui_info = virtio_vga_base_ui_info,
     .gl_block = virtio_vga_base_gl_block,
+    .register_dbus_listener = virtio_vga_base_register_dbus_listener,
 };
 
 static const VMStateDescription vmstate_virtio_vga_base = {
-- 
2.29.0




reply via email to

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