All of lore.kernel.org
 help / color / mirror / Atom feed
From: Dave Airlie <airlied@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: christian.koenig@amd.com
Subject: [PATCH 6/7] drm/ttm: move ghost object creation to a common function
Date: Thu, 17 Sep 2020 14:30:39 +1000	[thread overview]
Message-ID: <20200917043040.146575-7-airlied@gmail.com> (raw)
In-Reply-To: <20200917043040.146575-1-airlied@gmail.com>

From: Dave Airlie <airlied@redhat.com>

Both accel cleanup and pipeline move had the same code, make
a single function for it.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo_util.c | 105 ++++++++++++------------------
 1 file changed, 43 insertions(+), 62 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 5a8d77ef504f..3c16e303d2e2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -526,6 +526,47 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
 }
 EXPORT_SYMBOL(ttm_bo_kunmap);
 
+static int ttm_bo_move_to_ghost(struct ttm_buffer_object *bo,
+				struct dma_fence *fence,
+				bool dst_use_tt)
+{
+	struct ttm_buffer_object *ghost_obj;
+	int ret;
+
+	/**
+	 * This should help pipeline ordinary buffer moves.
+	 *
+	 * Hang old buffer memory on a new buffer object,
+	 * and leave it to be released when the GPU
+	 * operation has completed.
+	 */
+
+	dma_fence_put(bo->moving);
+	bo->moving = dma_fence_get(fence);
+
+	ret = ttm_buffer_object_transfer(bo, &ghost_obj);
+	if (ret)
+		return ret;
+
+	dma_resv_add_excl_fence(&ghost_obj->base._resv, fence);
+
+	/**
+	 * If we're not moving to fixed memory, the TTM object
+	 * needs to stay alive. Otherwhise hang it on the ghost
+	 * bo to be unbound and destroyed.
+	 */
+
+	if (dst_use_tt) {
+		ghost_obj->ttm = NULL;
+	} else {
+		bo->ttm = NULL;
+	}
+
+	dma_resv_unlock(&ghost_obj->base._resv);
+	ttm_bo_put(ghost_obj);
+	return 0;
+}
+
 int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 			      struct dma_fence *fence,
 			      bool evict,
@@ -534,7 +575,6 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 	struct ttm_bo_device *bdev = bo->bdev;
 	struct ttm_resource_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
 	int ret;
-	struct ttm_buffer_object *ghost_obj;
 
 	dma_resv_add_excl_fence(bo->base.resv, fence);
 	if (evict) {
@@ -546,37 +586,9 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 			ttm_bo_tt_destroy(bo);
 		ttm_bo_free_old_node(bo);
 	} else {
-		/**
-		 * This should help pipeline ordinary buffer moves.
-		 *
-		 * Hang old buffer memory on a new buffer object,
-		 * and leave it to be released when the GPU
-		 * operation has completed.
-		 */
-
-		dma_fence_put(bo->moving);
-		bo->moving = dma_fence_get(fence);
-
-		ret = ttm_buffer_object_transfer(bo, &ghost_obj);
+		ret = ttm_bo_move_to_ghost(bo, fence, man->use_tt);
 		if (ret)
 			return ret;
-
-		dma_resv_add_excl_fence(&ghost_obj->base._resv, fence);
-
-		/**
-		 * If we're not moving to fixed memory, the TTM object
-		 * needs to stay alive. Otherwhise hang it on the ghost
-		 * bo to be unbound and destroyed.
-		 */
-
-		if (man->use_tt) {
-			ghost_obj->ttm = NULL;
-		} else {
-			bo->ttm = NULL;
-		}
-
-		dma_resv_unlock(&ghost_obj->base._resv);
-		ttm_bo_put(ghost_obj);
 	}
 
 	ttm_bo_assign_mem(bo, new_mem);
@@ -599,40 +611,9 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 	dma_resv_add_excl_fence(bo->base.resv, fence);
 
 	if (!evict) {
-		struct ttm_buffer_object *ghost_obj;
-
-		/**
-		 * This should help pipeline ordinary buffer moves.
-		 *
-		 * Hang old buffer memory on a new buffer object,
-		 * and leave it to be released when the GPU
-		 * operation has completed.
-		 */
-
-		dma_fence_put(bo->moving);
-		bo->moving = dma_fence_get(fence);
-
-		ret = ttm_buffer_object_transfer(bo, &ghost_obj);
+		ret = ttm_bo_move_to_ghost(bo, fence, to->use_tt);
 		if (ret)
 			return ret;
-
-		dma_resv_add_excl_fence(&ghost_obj->base._resv, fence);
-
-		/**
-		 * If we're not moving to fixed memory, the TTM object
-		 * needs to stay alive. Otherwhise hang it on the ghost
-		 * bo to be unbound and destroyed.
-		 */
-
-		if (to->use_tt) {
-			ghost_obj->ttm = NULL;
-		} else {
-			bo->ttm = NULL;
-		}
-
-		dma_resv_unlock(&ghost_obj->base._resv);
-		ttm_bo_put(ghost_obj);
-
 	} else if (!from->use_tt) {
 
 		/**
-- 
2.27.0

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

  parent reply	other threads:[~2020-09-17  4:32 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-09-17  4:30 [PATCH 0/7] drm/ttm: bind/unbind + cleanups Dave Airlie
2020-09-17  4:30 ` [PATCH 1/7] drm/ttm: protect against reentrant bind in the drivers Dave Airlie
2020-09-17  7:45   ` Christian König
2020-09-17  4:30 ` [PATCH 2/7] drm/ttm: flip tt destroy ordering Dave Airlie
2020-09-17  7:47   ` Christian König
2020-09-17  4:30 ` [PATCH 3/7] drm/ttm: move unbind into the tt destroy Dave Airlie
2020-09-17  7:48   ` Christian König
2020-09-17  4:30 ` [PATCH 4/7] drm/ttm/drivers: call the bind function directly Dave Airlie
2020-09-17  7:49   ` Christian König
2020-09-17  4:30 ` [PATCH 5/7] drm/ttm: add a simple assign mem to bo wrapper Dave Airlie
2020-09-17  7:50   ` Christian König
2020-09-17  4:30 ` Dave Airlie [this message]
2020-09-17  7:55   ` [PATCH 6/7] drm/ttm: move ghost object creation to a common function Christian König
2020-09-17  4:30 ` [PATCH 7/7] drm/ttm: make common function for wait/free node path Dave Airlie
2020-09-17  7:57   ` Christian König

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=20200917043040.146575-7-airlied@gmail.com \
    --to=airlied@gmail.com \
    --cc=christian.koenig@amd.com \
    --cc=dri-devel@lists.freedesktop.org \
    /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.