drm/virtio: factor out context create hypercall
authorGurchetan Singh <gurchetansingh@chromium.org>
Tue, 25 Feb 2020 00:07:58 +0000 (16:07 -0800)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 25 Feb 2020 08:48:41 +0000 (09:48 +0100)
We currently create an OpenGL context when opening the DRM fd
if 3D is available.

We may need other context types (VK,..) in the future, and the plan
is to have explicit initialization for that.

For explicit initialization to work, we need to factor out
virtio_gpu_create_context from driver initialization.

v2: Move context handle initialization too (olv)
v6: Remove redundant 3D check (emil.velikov)

Reviewed-by: Chia-I Wu <olvaffe@gmail.com>
Reviewed-by: Emil Velikov <emil.velikov@collabora.com>
Signed-off-by: Gurchetan Singh <gurchetansingh@chromium.org>
Link: http://patchwork.freedesktop.org/patch/msgid/20200225000800.2966-2-gurchetansingh@chromium.org
Signed-off-by: Gerd Hoffmann <kraxel@redhat.com>
drivers/gpu/drm/virtio/virtgpu_drv.h
drivers/gpu/drm/virtio/virtgpu_ioctl.c
drivers/gpu/drm/virtio/virtgpu_kms.c

index 2f6c4ccbfd14581508adfc338fe5bd12b8b2abcd..72c1d9b59dfe10823309d8c39778ebcdbe944b87 100644 (file)
@@ -214,6 +214,8 @@ struct virtio_gpu_fpriv {
 /* virtio_ioctl.c */
 #define DRM_VIRTIO_NUM_IOCTLS 10
 extern struct drm_ioctl_desc virtio_gpu_ioctls[DRM_VIRTIO_NUM_IOCTLS];
+void virtio_gpu_create_context(struct drm_device *dev,
+                              struct drm_file *file);
 
 /* virtio_kms.c */
 int virtio_gpu_init(struct drm_device *dev);
index baad7e1c95051a720ddae146f3c902c558f126eb..00ef9fd3fbf6e647ee8326af46b0e321c06d34ca 100644 (file)
 
 #include "virtgpu_drv.h"
 
+void virtio_gpu_create_context(struct drm_device *dev,
+                              struct drm_file *file)
+{
+       struct virtio_gpu_device *vgdev = dev->dev_private;
+       struct virtio_gpu_fpriv *vfpriv = file->driver_priv;
+       char dbgname[TASK_COMM_LEN];
+
+       get_task_comm(dbgname, current);
+       virtio_gpu_cmd_context_create(vgdev, vfpriv->ctx_id,
+                                     strlen(dbgname), dbgname);
+       virtio_gpu_notify(vgdev);
+}
+
 static int virtio_gpu_map_ioctl(struct drm_device *dev, void *data,
                                struct drm_file *file)
 {
index ad3b673f5796e8791d9dc3f30b7fd24c38d0ebab..f7e3712502ca2531ffe49c72c734cdfe2ea8ff45 100644 (file)
@@ -52,19 +52,6 @@ static void virtio_gpu_config_changed_work_func(struct work_struct *work)
                      events_clear, &events_clear);
 }
 
-static int virtio_gpu_context_create(struct virtio_gpu_device *vgdev,
-                                     uint32_t nlen, const char *name)
-{
-       int handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL);
-
-       if (handle < 0)
-               return handle;
-       handle += 1;
-       virtio_gpu_cmd_context_create(vgdev, handle, nlen, name);
-       virtio_gpu_notify(vgdev);
-       return handle;
-}
-
 static void virtio_gpu_context_destroy(struct virtio_gpu_device *vgdev,
                                      uint32_t ctx_id)
 {
@@ -260,8 +247,7 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
 {
        struct virtio_gpu_device *vgdev = dev->dev_private;
        struct virtio_gpu_fpriv *vfpriv;
-       int id;
-       char dbgname[TASK_COMM_LEN];
+       int handle;
 
        /* can't create contexts without 3d renderer */
        if (!vgdev->has_virgl_3d)
@@ -272,15 +258,15 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
        if (!vfpriv)
                return -ENOMEM;
 
-       get_task_comm(dbgname, current);
-       id = virtio_gpu_context_create(vgdev, strlen(dbgname), dbgname);
-       if (id < 0) {
+       handle = ida_alloc(&vgdev->ctx_id_ida, GFP_KERNEL);
+       if (handle < 0) {
                kfree(vfpriv);
-               return id;
+               return handle;
        }
 
-       vfpriv->ctx_id = id;
+       vfpriv->ctx_id = handle + 1;
        file->driver_priv = vfpriv;
+       virtio_gpu_create_context(dev, file);
        return 0;
 }