path: root/drivers/gpu/drm/virtio/virtgpu_gem.c
diff options
authorGerd Hoffmann <>2019-03-18 12:33:32 +0100
committerGerd Hoffmann <>2019-03-28 12:11:56 +0100
commit530b28426a94b822b3c03491cde5c9a961d80e7f (patch)
tree36c5318d00ff7c3d8903d929dea99ce26cd4e4b8 /drivers/gpu/drm/virtio/virtgpu_gem.c
parentfd4d6a4277713b647885f68543b4216150540fca (diff)
drm/virtio: rework resource creation workflow.
This patch moves the virtio_gpu_cmd_create_resource() call (which notifies the host about the new resource created) into the virtio_gpu_object_create() function. That way we can call virtio_gpu_cmd_create_resource() before ttm_bo_init(), so the host already knows about the object when ttm initializes the object and calls our driver callbacks. Specifically the object is already created when the virtio_gpu_ttm_tt_bind() callback invokes virtio_gpu_object_attach(), so the extra virtio_gpu_object_attach() calls done after virtio_gpu_object_create() are not needed any more. The fence support for the create ioctl becomes a bit more tricky though. The code moved into virtio_gpu_object_create() too. We first submit the (fenced) virtio_gpu_cmd_create_resource() command, then initialize the ttm object, and finally attach just created object to the fence for the command in case it didn't finish yet. Signed-off-by: Gerd Hoffmann <> Acked-by: Noralf Trønnes <> Link:
Diffstat (limited to 'drivers/gpu/drm/virtio/virtgpu_gem.c')
1 files changed, 5 insertions, 14 deletions
diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c
index ac15863643e7..1e49e08dd545 100644
--- a/drivers/gpu/drm/virtio/virtgpu_gem.c
+++ b/drivers/gpu/drm/virtio/virtgpu_gem.c
@@ -36,13 +36,14 @@ void virtio_gpu_gem_free_object(struct drm_gem_object *gem_obj)
struct virtio_gpu_object*
virtio_gpu_alloc_object(struct drm_device *dev,
- struct virtio_gpu_object_params *params)
+ struct virtio_gpu_object_params *params,
+ struct virtio_gpu_fence *fence)
struct virtio_gpu_device *vgdev = dev->dev_private;
struct virtio_gpu_object *obj;
int ret;
- ret = virtio_gpu_object_create(vgdev, params, &obj);
+ ret = virtio_gpu_object_create(vgdev, params, &obj, fence);
if (ret)
return ERR_PTR(ret);
@@ -59,7 +60,7 @@ int virtio_gpu_gem_create(struct drm_file *file,
int ret;
u32 handle;
- obj = virtio_gpu_alloc_object(dev, params);
+ obj = virtio_gpu_alloc_object(dev, params, NULL);
if (IS_ERR(obj))
return PTR_ERR(obj);
@@ -82,9 +83,7 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
struct drm_device *dev,
struct drm_mode_create_dumb *args)
- struct virtio_gpu_device *vgdev = dev->dev_private;
struct drm_gem_object *gobj;
- struct virtio_gpu_object *obj;
struct virtio_gpu_object_params params = { 0 };
int ret;
uint32_t pitch;
@@ -100,20 +99,12 @@ int virtio_gpu_mode_dumb_create(struct drm_file *file_priv,
params.width = args->width;
params.height = args->height;
params.size = args->size;
+ params.dumb = true;
ret = virtio_gpu_gem_create(file_priv, dev, &params, &gobj,
if (ret)
goto fail;
- obj = gem_to_virtio_gpu_obj(gobj);
- virtio_gpu_cmd_create_resource(vgdev, obj, &params);
- /* attach the object to the resource */
- ret = virtio_gpu_object_attach(vgdev, obj, NULL);
- if (ret)
- goto fail;
- obj->dumb = true;
args->pitch = pitch;
return ret;