Commit 85c83ea9 authored by Gurchetan Singh's avatar Gurchetan Singh Committed by Gerd Hoffmann

drm/virtio: implement context init: allocate an array of fence contexts

We don't want fences from different 3D contexts (virgl, gfxstream,
venus) to be on the same timeline.  With explicit context creation,
we can specify the number of ring each context wants.

Execbuffer can specify which ring to use.
Signed-off-by: default avatarGurchetan Singh <gurchetansingh@chromium.org>
Acked-by: default avatarLingfeng Yang <lfy@google.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20210921232024.817-10-gurchetansingh@chromium.orgSigned-off-by: default avatarGerd Hoffmann <kraxel@redhat.com>
parent bbf588d7
...@@ -56,6 +56,7 @@ ...@@ -56,6 +56,7 @@
#define STATE_ERR 2 #define STATE_ERR 2
#define MAX_CAPSET_ID 63 #define MAX_CAPSET_ID 63
#define MAX_RINGS 64
struct virtio_gpu_object_params { struct virtio_gpu_object_params {
unsigned long size; unsigned long size;
...@@ -263,6 +264,8 @@ struct virtio_gpu_fpriv { ...@@ -263,6 +264,8 @@ struct virtio_gpu_fpriv {
uint32_t ctx_id; uint32_t ctx_id;
uint32_t context_init; uint32_t context_init;
bool context_created; bool context_created;
uint32_t num_rings;
uint64_t base_fence_ctx;
struct mutex context_lock; struct mutex context_lock;
}; };
......
...@@ -99,6 +99,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, ...@@ -99,6 +99,11 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
int in_fence_fd = exbuf->fence_fd; int in_fence_fd = exbuf->fence_fd;
int out_fence_fd = -1; int out_fence_fd = -1;
void *buf; void *buf;
uint64_t fence_ctx;
uint32_t ring_idx;
fence_ctx = vgdev->fence_drv.context;
ring_idx = 0;
if (vgdev->has_virgl_3d == false) if (vgdev->has_virgl_3d == false)
return -ENOSYS; return -ENOSYS;
...@@ -106,6 +111,17 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, ...@@ -106,6 +111,17 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS)) if ((exbuf->flags & ~VIRTGPU_EXECBUF_FLAGS))
return -EINVAL; return -EINVAL;
if ((exbuf->flags & VIRTGPU_EXECBUF_RING_IDX)) {
if (exbuf->ring_idx >= vfpriv->num_rings)
return -EINVAL;
if (!vfpriv->base_fence_ctx)
return -EINVAL;
fence_ctx = vfpriv->base_fence_ctx;
ring_idx = exbuf->ring_idx;
}
exbuf->fence_fd = -1; exbuf->fence_fd = -1;
virtio_gpu_create_context(dev, file); virtio_gpu_create_context(dev, file);
...@@ -173,7 +189,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data, ...@@ -173,7 +189,7 @@ static int virtio_gpu_execbuffer_ioctl(struct drm_device *dev, void *data,
goto out_memdup; goto out_memdup;
} }
out_fence = virtio_gpu_fence_alloc(vgdev, vgdev->fence_drv.context, 0); out_fence = virtio_gpu_fence_alloc(vgdev, fence_ctx, ring_idx);
if(!out_fence) { if(!out_fence) {
ret = -ENOMEM; ret = -ENOMEM;
goto out_unresv; goto out_unresv;
...@@ -691,7 +707,7 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev, ...@@ -691,7 +707,7 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
return -EINVAL; return -EINVAL;
/* Number of unique parameters supported at this time. */ /* Number of unique parameters supported at this time. */
if (num_params > 1) if (num_params > 2)
return -EINVAL; return -EINVAL;
ctx_set_params = memdup_user(u64_to_user_ptr(args->ctx_set_params), ctx_set_params = memdup_user(u64_to_user_ptr(args->ctx_set_params),
...@@ -731,6 +747,20 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev, ...@@ -731,6 +747,20 @@ static int virtio_gpu_context_init_ioctl(struct drm_device *dev,
vfpriv->context_init |= value; vfpriv->context_init |= value;
break; break;
case VIRTGPU_CONTEXT_PARAM_NUM_RINGS:
if (vfpriv->base_fence_ctx) {
ret = -EINVAL;
goto out_unlock;
}
if (value > MAX_RINGS) {
ret = -EINVAL;
goto out_unlock;
}
vfpriv->base_fence_ctx = dma_fence_context_alloc(value);
vfpriv->num_rings = value;
break;
default: default:
ret = -EINVAL; ret = -EINVAL;
goto out_unlock; goto out_unlock;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment