[PATCH 3/6] drm/lima: use drm_gem_objects_lookup

Qiang Yu yuq825 at gmail.com
Thu Sep 26 14:10:42 UTC 2019


Signed-off-by: Qiang Yu <yuq825 at gmail.com>
---
 drivers/gpu/drm/lima/lima_drv.c |  5 ++-
 drivers/gpu/drm/lima/lima_gem.c | 73 +++++++++++++++++++--------------
 2 files changed, 46 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/lima/lima_drv.c b/drivers/gpu/drm/lima/lima_drv.c
index 75ec703d22e0..cc850a522fac 100644
--- a/drivers/gpu/drm/lima/lima_drv.c
+++ b/drivers/gpu/drm/lima/lima_drv.c
@@ -108,7 +108,7 @@ static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_
 	if (args->frame_size != pipe->frame_size)
 		return -EINVAL;
 
-	bos = kvcalloc(args->nr_bos, sizeof(*submit.bos) + sizeof(*submit.lbos), GFP_KERNEL);
+	bos = kvcalloc(args->nr_bos, sizeof(*submit.bos), GFP_KERNEL);
 	if (!bos)
 		return -ENOMEM;
 
@@ -142,7 +142,6 @@ static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_
 
 	submit.pipe = args->pipe;
 	submit.bos = bos;
-	submit.lbos = (void *)bos + size;
 	submit.nr_bos = args->nr_bos;
 	submit.task = task;
 	submit.ctx = ctx;
@@ -159,6 +158,8 @@ static int lima_ioctl_gem_submit(struct drm_device *dev, void *data, struct drm_
 		kmem_cache_free(pipe->task_slab, task);
 out0:
 	kvfree(bos);
+	if (submit.lbos)
+		kvfree(submit.lbos);
 	return err;
 }
 
diff --git a/drivers/gpu/drm/lima/lima_gem.c b/drivers/gpu/drm/lima/lima_gem.c
index ff3d9acc24fc..f5aeaa1f61c8 100644
--- a/drivers/gpu/drm/lima/lima_gem.c
+++ b/drivers/gpu/drm/lima/lima_gem.c
@@ -130,6 +130,25 @@ int lima_gem_mmap(struct file *filp, struct vm_area_struct *vma)
 	return 0;
 }
 
+static int lima_gem_lookup_bos(struct drm_file *file, struct lima_submit *submit)
+{
+	int i, ret;
+	u32 *handles;
+
+	handles = kvmalloc_array(submit->nr_bos, sizeof(u32), GFP_KERNEL);
+	if (!handles)
+		return -ENOMEM;
+
+	for (i = 0; i < submit->nr_bos; i++)
+		handles[i] = submit->bos[i].handle;
+
+	ret = drm_gem_objects_lookup(file, handles, submit->nr_bos,
+				     (struct drm_gem_object ***)&submit->lbos);
+
+	kvfree(handles);
+	return ret;
+}
+
 static int lima_gem_sync_bo(struct lima_sched_task *task, struct lima_bo *bo,
 			    bool write, bool explicit)
 {
@@ -236,7 +255,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
 	struct lima_vm *vm = priv->vm;
 	struct drm_syncobj *out_sync = NULL;
 	struct dma_fence *fence;
-	struct lima_bo **bos = submit->lbos;
+	struct lima_bo **bos;
 
 	if (submit->out_sync) {
 		out_sync = drm_syncobj_find(file, submit->out_sync);
@@ -244,43 +263,37 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
 			return -ENOENT;
 	}
 
-	for (i = 0; i < submit->nr_bos; i++) {
-		struct drm_gem_object *obj;
-		struct lima_bo *bo;
-
-		obj = drm_gem_object_lookup(file, submit->bos[i].handle);
-		if (!obj) {
-			err = -ENOENT;
-			goto err_out0;
-		}
+	err = lima_gem_lookup_bos(file, submit);
+	if (err)
+		goto err_out0;
 
-		bo = to_lima_bo(obj);
+	bos = submit->lbos;
 
-		/* increase refcnt of gpu va map to prevent unmapped when executing,
-		 * will be decreased when task done
-		 */
-		err = lima_vm_bo_add(vm, bo, false);
+	/* increase refcnt of gpu va map to prevent unmapped when executing,
+	 * will be decreased when task done
+	 */
+	for (i = 0; i < submit->nr_bos; i++) {
+		err = lima_vm_bo_add(vm, bos[i], false);
 		if (err) {
-			drm_gem_object_put_unlocked(obj);
-			goto err_out0;
+			for (i--; i >= 0; i--)
+				lima_vm_bo_del(vm, bos[i]);
+			goto err_out1;
 		}
-
-		bos[i] = bo;
 	}
 
 	err = lima_gem_lock_bos(bos, submit->nr_bos, &ctx);
 	if (err)
-		goto err_out0;
+		goto err_out2;
 
 	err = lima_sched_task_init(
 		submit->task, submit->ctx->context + submit->pipe,
 		bos, submit->nr_bos, vm);
 	if (err)
-		goto err_out1;
+		goto err_out3;
 
 	err = lima_gem_add_deps(file, submit);
 	if (err)
-		goto err_out2;
+		goto err_out4;
 
 	for (i = 0; i < submit->nr_bos; i++) {
 		err = lima_gem_sync_bo(
@@ -288,7 +301,7 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
 			submit->bos[i].flags & LIMA_SUBMIT_BO_WRITE,
 			submit->flags & LIMA_SUBMIT_FLAG_EXPLICIT_FENCE);
 		if (err)
-			goto err_out2;
+			goto err_out4;
 	}
 
 	fence = lima_sched_context_queue_task(
@@ -315,17 +328,17 @@ int lima_gem_submit(struct drm_file *file, struct lima_submit *submit)
 
 	return 0;
 
-err_out2:
+err_out4:
 	lima_sched_task_fini(submit->task);
-err_out1:
+err_out3:
 	lima_gem_unlock_bos(bos, submit->nr_bos, &ctx);
-err_out0:
-	for (i = 0; i < submit->nr_bos; i++) {
-		if (!bos[i])
-			break;
+err_out2:
+	for (i = 0; i < submit->nr_bos; i++)
 		lima_vm_bo_del(vm, bos[i]);
+err_out1:
+	for (i = 0; i < submit->nr_bos; i++)
 		drm_gem_object_put_unlocked(&bos[i]->gem);
-	}
+err_out0:
 	if (out_sync)
 		drm_syncobj_put(out_sync);
 	return err;
-- 
2.17.1



More information about the dri-devel mailing list