All of lore.kernel.org
 help / color / mirror / Atom feed
From: Qiang Yu <yuq825@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: lima@lists.freedesktop.org,
	Maxime Ripard <maxime.ripard@bootlin.com>,
	David Airlie <airlied@linux.ie>, Qiang Yu <yuq825@gmail.com>,
	Sean Paul <sean@poorly.run>
Subject: [PATCH 3/6] drm/lima: use drm_gem_objects_lookup
Date: Thu, 26 Sep 2019 22:10:42 +0800	[thread overview]
Message-ID: <20190926141046.30758-5-yuq825@gmail.com> (raw)
In-Reply-To: <20190926141046.30758-1-yuq825@gmail.com>

Signed-off-by: Qiang Yu <yuq825@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

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-09-26 14:10 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-26 14:10 [PATCH 0/6] drm/lima: simplify driver by using more drm helpers Qiang Yu
2019-09-26 14:10 ` [PATCH 1/6] drm/gem: refine drm_gem_objects_lookup Qiang Yu
2019-09-26 15:01   ` Rob Herring
2019-09-27  0:09     ` Qiang Yu
2019-10-09 14:57       ` Daniel Vetter
2019-10-10  2:02         ` Qiang Yu
2019-10-10 13:42           ` Daniel Vetter
2019-09-26 14:10 ` [PATCH 2/6] drm/v3d: use drm_gem_objects_lookup Qiang Yu
2019-09-26 14:10 ` Qiang Yu [this message]
2019-09-26 14:10 ` [PATCH 4/6] drm/lima: use drm_gem_shmem_helpers Qiang Yu
2019-09-26 14:10 ` [PATCH 5/6] drm/lima: use drm_gem_(un)lock_reservations Qiang Yu
2019-09-26 14:10 ` [PATCH 6/6] drm/lima: add __GFP_NOWARN flag to all dma_alloc_wc Qiang Yu
2019-09-26 15:00 ` [PATCH 0/6] drm/lima: simplify driver by using more drm helpers Steven Price

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190926141046.30758-5-yuq825@gmail.com \
    --to=yuq825@gmail.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=lima@lists.freedesktop.org \
    --cc=maxime.ripard@bootlin.com \
    --cc=sean@poorly.run \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.