drm/virtio: enqueue virtio_gpu_create_context after the first 3D ioctl
authorGurchetan Singh <gurchetansingh@chromium.org>
Tue, 25 Feb 2020 00:08:00 +0000 (16:08 -0800)
committerGerd Hoffmann <kraxel@redhat.com>
Tue, 25 Feb 2020 08:48:42 +0000 (09:48 +0100)
For old userspace, initialization will still be implicit.

For backwards compatibility, enqueue virtio_gpu_cmd_context_create after
the first 3D ioctl.

v3: staticify virtio_gpu_create_context
    remove notify to batch vm-exit
v6: Remove nested 3D checks (emil.velikov):
      - unify 3D check in resource create
v7: Remove check when getting capabilities

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-4-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 76b7b7c30e104a21fe9ccbd2b4a0784a220e3961..95a7443baaba795eb2a49075f4099337abf7721d 100644 (file)
@@ -216,8 +216,6 @@ 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 ec38cf5573aab1a3d93c8b8f8276e8ae38c0881a..336cc9143205de921c4307f076903530abe58e97 100644 (file)
@@ -33,8 +33,8 @@
 
 #include "virtgpu_drv.h"
 
-void virtio_gpu_create_context(struct drm_device *dev,
-                              struct drm_file *file)
+static 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;
@@ -95,6 +95,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
 
        exbuf->fence_fd = -1;
 
+       virtio_gpu_create_context(dev, file);
        if (exbuf->flags & VIRTGPU_EXECBUF_FENCE_FD_IN) {
                struct dma_fence *in_fence;
 
@@ -233,7 +234,17 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
        uint32_t handle = 0;
        struct virtio_gpu_object_params params = { 0 };
 
-       if (vgdev->has_virgl_3d == false) {
+       if (vgdev->has_virgl_3d) {
+               virtio_gpu_create_context(dev, file);
+               params.virgl = true;
+               params.target = rc->target;
+               params.bind = rc->bind;
+               params.depth = rc->depth;
+               params.array_size = rc->array_size;
+               params.last_level = rc->last_level;
+               params.nr_samples = rc->nr_samples;
+               params.flags = rc->flags;
+       } else {
                if (rc->depth > 1)
                        return -EINVAL;
                if (rc->nr_samples > 1)
@@ -250,16 +261,6 @@ static int virtio_gpu_resource_create_ioctl(struct drm_device *dev, void *data,
        params.width = rc->width;
        params.height = rc->height;
        params.size = rc->size;
-       if (vgdev->has_virgl_3d) {
-               params.virgl = true;
-               params.target = rc->target;
-               params.bind = rc->bind;
-               params.depth = rc->depth;
-               params.array_size = rc->array_size;
-               params.last_level = rc->last_level;
-               params.nr_samples = rc->nr_samples;
-               params.flags = rc->flags;
-       }
        /* allocate a single page size object */
        if (params.size == 0)
                params.size = PAGE_SIZE;
@@ -319,6 +320,7 @@ static int virtio_gpu_transfer_from_host_ioctl(struct drm_device *dev,
        if (vgdev->has_virgl_3d == false)
                return -ENOSYS;
 
+       virtio_gpu_create_context(dev, file);
        objs = virtio_gpu_array_from_handles(file, &args->bo_handle, 1);
        if (objs == NULL)
                return -ENOENT;
@@ -367,6 +369,7 @@ static int virtio_gpu_transfer_to_host_ioctl(struct drm_device *dev, void *data,
                         args->box.w, args->box.h, args->box.x, args->box.y,
                         objs, NULL);
        } else {
+               virtio_gpu_create_context(dev, file);
                ret = virtio_gpu_array_lock_resv(objs);
                if (ret != 0)
                        goto err_put_free;
index 424729cb81d118a287d3a63a6bb0ef1252cac6cd..023a030ca7b99e7cba5d2fea111df0d434df852f 100644 (file)
@@ -268,7 +268,6 @@ int virtio_gpu_driver_open(struct drm_device *dev, struct drm_file *file)
 
        vfpriv->ctx_id = handle + 1;
        file->driver_priv = vfpriv;
-       virtio_gpu_create_context(dev, file);
        return 0;
 }