qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] virtio-gpu: create drm fd based on specified render node path
@ 2025-12-05 18:49 Luqmaan Irshad
  2025-12-08  0:49 ` Dmitry Osipenko
  0 siblings, 1 reply; 7+ messages in thread
From: Luqmaan Irshad @ 2025-12-05 18:49 UTC (permalink / raw)
  To: qemu-devel
  Cc: mst, alex.bennee, odaki, dmitry.osipenko,
	pierre-eric.pelloux-prayer, luckmaan21, Luqmaan Irshad

Added a special callback function called virtio_get_drm_fd to create
a render node based on the path specified by the user via QEMU command
line.  This function is called during the virglrenderer callback sequence
where we specify the get_drm_fd function pointer to call back our
new function, allowing us to pass the fd of our created render node.

Based-on: 20251116125641.2255794-1-dmitry.osipenko@collabora.com

Signed-off-by: Luqmaan Irshad <luirshad@amd.com>
---
 hw/display/virtio-gpu-gl.c     |  4 ++++
 hw/display/virtio-gpu-virgl.c  | 17 ++++++++++++++++-
 include/hw/virtio/virtio-gpu.h |  1 +
 3 files changed, 21 insertions(+), 1 deletion(-)

diff --git a/hw/display/virtio-gpu-gl.c b/hw/display/virtio-gpu-gl.c
index b640900fc6..c0587929e4 100644
--- a/hw/display/virtio-gpu-gl.c
+++ b/hw/display/virtio-gpu-gl.c
@@ -161,6 +161,10 @@ static const Property virtio_gpu_gl_properties[] = {
                     VIRTIO_GPU_FLAG_VENUS_ENABLED, false),
     DEFINE_PROP_BIT("drm_native_context", VirtIOGPU, parent_obj.conf.flags,
                     VIRTIO_GPU_FLAG_DRM_ENABLED, false),
+#if VIRGL_RENDERER_CALLBACKS_VERSION >= 2s
+    DEFINE_PROP_STRING("drm_render_node", VirtIOGPU,
+                       parent_obj.drm_render_node),
+#endif
 };
 
 static void virtio_gpu_gl_device_unrealize(DeviceState *qdev)
diff --git a/hw/display/virtio-gpu-virgl.c b/hw/display/virtio-gpu-virgl.c
index 6ad3b46066..c271194260 100644
--- a/hw/display/virtio-gpu-virgl.c
+++ b/hw/display/virtio-gpu-virgl.c
@@ -1016,6 +1016,15 @@ void virtio_gpu_virgl_process_cmd(VirtIOGPU *g,
     }
 }
 
+#if VIRGL_RENDERER_CALLBACKS_VERSION >= 2
+static int virtio_get_drm_fd(void *opaque)
+{
+    VirtIOGPU *g = opaque;
+    int fd = open(g->parent_obj.drm_render_node, O_RDWR);
+    return fd;
+}
+#endif
+
 static void virgl_write_fence(void *opaque, uint32_t fence)
 {
     VirtIOGPU *g = opaque;
@@ -1300,7 +1309,13 @@ int virtio_gpu_virgl_init(VirtIOGPU *g)
     }
     if (virtio_gpu_drm_enabled(g->parent_obj.conf)) {
         flags |= VIRGL_RENDERER_DRM;
-
+#if VIRGL_RENDERER_CALLBACKS_VERSION >= 2
+        if (g->parent_obj.drm_render_node) {
+            if (virtio_gpu_3d_cbs.version < 2)
+                virtio_gpu_3d_cbs.version = 2;
+            virtio_gpu_3d_cbs.get_drm_fd = virtio_get_drm_fd;
+        }
+#endif
         if (!(flags & VIRGL_RENDERER_ASYNC_FENCE_CB)) {
             /*
              * Virglrenderer skips enabling DRM context support without
diff --git a/include/hw/virtio/virtio-gpu.h b/include/hw/virtio/virtio-gpu.h
index a4963508a4..aba8343848 100644
--- a/include/hw/virtio/virtio-gpu.h
+++ b/include/hw/virtio/virtio-gpu.h
@@ -152,6 +152,7 @@ struct VirtIOGPUBase {
     struct virtio_gpu_base_conf conf;
     struct virtio_gpu_config virtio_config;
     const GraphicHwOps *hw_ops;
+    char *drm_render_node;
 
     int renderer_blocked;
     int enable;
-- 
2.43.0



^ permalink raw reply related	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2025-12-12  3:25 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-12-05 18:49 [PATCH] virtio-gpu: create drm fd based on specified render node path Luqmaan Irshad
2025-12-08  0:49 ` Dmitry Osipenko
2025-12-09 18:57   ` Irshad, Luqmaan
2025-12-10 15:26     ` Dmitry Osipenko
2025-12-11 14:18   ` Akihiko Odaki
2025-12-11 16:30     ` Irshad, Luqmaan
2025-12-12  3:24       ` Akihiko Odaki

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).