dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [00/23] ttm tt refactoring.
@ 2020-08-26  1:44 Dave Airlie
  2020-08-26  1:44 ` [PATCH 01/23] drm/amdgpu/ttm: remove unused parameter to move blit Dave Airlie
                   ` (23 more replies)
  0 siblings, 24 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

This is based on top of misc-next with Christians io rework for nouveau.

https://github.com/airlied/linux/tree/ttm-tt-cleanup (is a complete tree)

The idea is to move towards ttm_tt being just a backing store for system
allocated pages + dma info, and not be anything to do with a global TT.

First is a couple of minor cleanups, then drops bdev from ttm_tt,
and moves the func table into the bdev driver table instead, makes
drivers deal with the agp differences, then cleans up the mess.

It tries to cleanup ttm_tt a bit more as well, in the end ttm_tt
is getting to what I'd like it to represent, the next step is tackling
the whole bind/unbind/move stuff I think.

Dave.


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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* [PATCH 01/23] drm/amdgpu/ttm: remove unused parameter to move blit
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 02/23] drm/radeon/ttm: don't store driver copy of device pointer Dave Airlie
                   ` (22 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d7f668dbc9e0..00b2c0359735 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -455,7 +455,7 @@ int amdgpu_ttm_copy_mem_to_mem(struct amdgpu_device *adev,
  * help move buffers to and from VRAM.
  */
 static int amdgpu_move_blit(struct ttm_buffer_object *bo,
-			    bool evict, bool no_wait_gpu,
+			    bool evict,
 			    struct ttm_resource *new_mem,
 			    struct ttm_resource *old_mem)
 {
@@ -553,7 +553,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
 	}
 
 	/* blit VRAM to GTT */
-	r = amdgpu_move_blit(bo, evict, ctx->no_wait_gpu, &tmp_mem, old_mem);
+	r = amdgpu_move_blit(bo, evict, &tmp_mem, old_mem);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
@@ -603,7 +603,7 @@ static int amdgpu_move_ram_vram(struct ttm_buffer_object *bo, bool evict,
 	}
 
 	/* copy to VRAM */
-	r = amdgpu_move_blit(bo, evict, ctx->no_wait_gpu, new_mem, old_mem);
+	r = amdgpu_move_blit(bo, evict, new_mem, old_mem);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
@@ -692,7 +692,7 @@ static int amdgpu_bo_move(struct ttm_buffer_object *bo, bool evict,
 		   new_mem->mem_type == TTM_PL_VRAM) {
 		r = amdgpu_move_ram_vram(bo, evict, ctx, new_mem);
 	} else {
-		r = amdgpu_move_blit(bo, evict, ctx->no_wait_gpu,
+		r = amdgpu_move_blit(bo, evict,
 				     new_mem, old_mem);
 	}
 
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 02/23] drm/radeon/ttm: don't store driver copy of device pointer.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
  2020-08-26  1:44 ` [PATCH 01/23] drm/amdgpu/ttm: remove unused parameter to move blit Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-09-01 11:53   ` Daniel Vetter
  2020-08-26  1:44 ` [PATCH 03/23] drm/ttm: remove bdev from ttm_tt Dave Airlie
                   ` (21 subsequent siblings)
  23 siblings, 1 reply; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

This can be gotten back from bdev.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/radeon/radeon_ttm.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index f6311f404db8..0923a8601112 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -412,7 +412,6 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
  */
 struct radeon_ttm_tt {
 	struct ttm_dma_tt		ttm;
-	struct radeon_device		*rdev;
 	u64				offset;
 
 	uint64_t			userptr;
@@ -515,6 +514,7 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
 				   struct ttm_resource *bo_mem)
 {
 	struct radeon_ttm_tt *gtt = (void*)ttm;
+	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
 	uint32_t flags = RADEON_GART_PAGE_VALID | RADEON_GART_PAGE_READ |
 		RADEON_GART_PAGE_WRITE;
 	int r;
@@ -531,7 +531,7 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
 	}
 	if (ttm->caching_state == tt_cached)
 		flags |= RADEON_GART_PAGE_SNOOP;
-	r = radeon_gart_bind(gtt->rdev, gtt->offset, ttm->num_pages,
+	r = radeon_gart_bind(rdev, gtt->offset, ttm->num_pages,
 			     ttm->pages, gtt->ttm.dma_address, flags);
 	if (r) {
 		DRM_ERROR("failed to bind %lu pages at 0x%08X\n",
@@ -544,8 +544,9 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
 static void radeon_ttm_backend_unbind(struct ttm_tt *ttm)
 {
 	struct radeon_ttm_tt *gtt = (void *)ttm;
+	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
 
-	radeon_gart_unbind(gtt->rdev, gtt->offset, ttm->num_pages);
+	radeon_gart_unbind(rdev, gtt->offset, ttm->num_pages);
 
 	if (gtt->userptr)
 		radeon_ttm_tt_unpin_userptr(ttm);
@@ -584,7 +585,6 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
 		return NULL;
 	}
 	gtt->ttm.ttm.func = &radeon_backend_func;
-	gtt->rdev = rdev;
 	if (ttm_dma_tt_init(&gtt->ttm, bo, page_flags)) {
 		kfree(gtt);
 		return NULL;
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 03/23] drm/ttm: remove bdev from ttm_tt
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
  2020-08-26  1:44 ` [PATCH 01/23] drm/amdgpu/ttm: remove unused parameter to move blit Dave Airlie
  2020-08-26  1:44 ` [PATCH 02/23] drm/radeon/ttm: don't store driver copy of device pointer Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 04/23] drm/ttm: add optional bind/unbind via driver Dave Airlie
                   ` (20 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

I want to split this structure up and use it differently,
step one remove bdev pointer from it and pass it explicitly.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    | 40 +++++++++++--------
 drivers/gpu/drm/drm_gem_vram_helper.c      |  2 +-
 drivers/gpu/drm/nouveau/nouveau_bo.c       | 16 ++++----
 drivers/gpu/drm/nouveau/nouveau_sgdma.c    |  8 ++--
 drivers/gpu/drm/qxl/qxl_ttm.c              |  9 +++--
 drivers/gpu/drm/radeon/radeon_ttm.c        | 40 ++++++++++---------
 drivers/gpu/drm/ttm/ttm_agp_backend.c      | 17 +++++---
 drivers/gpu/drm/ttm/ttm_bo.c               |  8 ++--
 drivers/gpu/drm/ttm/ttm_bo_util.c          | 14 +++----
 drivers/gpu/drm/ttm/ttm_bo_vm.c            |  2 +-
 drivers/gpu/drm/ttm/ttm_tt.c               | 45 ++++++++++++----------
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c       |  4 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 16 +++++---
 include/drm/ttm/ttm_bo_driver.h            |  7 ++--
 include/drm/ttm/ttm_tt.h                   | 25 ++++++------
 15 files changed, 139 insertions(+), 114 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 00b2c0359735..9592505563bf 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -547,7 +547,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
 	}
 
 	/* Bind the memory to the GTT space */
-	r = ttm_tt_bind(bo->ttm, &tmp_mem, ctx);
+	r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem, ctx);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
@@ -973,9 +973,10 @@ void amdgpu_ttm_tt_set_user_pages(struct ttm_tt *ttm, struct page **pages)
  *
  * Called by amdgpu_ttm_backend_bind()
  **/
-static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm)
+static int amdgpu_ttm_tt_pin_userptr(struct ttm_bo_device *bdev,
+				     struct ttm_tt *ttm)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	int r;
 
@@ -1009,9 +1010,10 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_tt *ttm)
 /**
  * amdgpu_ttm_tt_unpin_userptr - Unpin and unmap userptr pages
  */
-static void amdgpu_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
+static void amdgpu_ttm_tt_unpin_userptr(struct ttm_bo_device *bdev,
+					struct ttm_tt *ttm)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 
 	int write = !(gtt->userflags & AMDGPU_GEM_USERPTR_READONLY);
@@ -1092,16 +1094,17 @@ static int amdgpu_ttm_gart_bind(struct amdgpu_device *adev,
  * Called by ttm_tt_bind() on behalf of ttm_bo_handle_move_mem().
  * This handles binding GTT memory to the device address space.
  */
-static int amdgpu_ttm_backend_bind(struct ttm_tt *ttm,
+static int amdgpu_ttm_backend_bind(struct ttm_bo_device *bdev,
+				   struct ttm_tt *ttm,
 				   struct ttm_resource *bo_mem)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
 	struct amdgpu_ttm_tt *gtt = (void*)ttm;
 	uint64_t flags;
 	int r = 0;
 
 	if (gtt->userptr) {
-		r = amdgpu_ttm_tt_pin_userptr(ttm);
+		r = amdgpu_ttm_tt_pin_userptr(bdev, ttm);
 		if (r) {
 			DRM_ERROR("failed to pin userptr\n");
 			return r;
@@ -1219,15 +1222,16 @@ int amdgpu_ttm_recover_gart(struct ttm_buffer_object *tbo)
  * Called by ttm_tt_unbind() on behalf of ttm_bo_move_ttm() and
  * ttm_tt_destroy().
  */
-static void amdgpu_ttm_backend_unbind(struct ttm_tt *ttm)
+static void amdgpu_ttm_backend_unbind(struct ttm_bo_device *bdev,
+				      struct ttm_tt *ttm)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	int r;
 
 	/* if the pages have userptr pinning then clear that first */
 	if (gtt->userptr)
-		amdgpu_ttm_tt_unpin_userptr(ttm);
+		amdgpu_ttm_tt_unpin_userptr(bdev, ttm);
 
 	if (gtt->offset == AMDGPU_BO_INVALID_OFFSET)
 		return;
@@ -1239,7 +1243,8 @@ static void amdgpu_ttm_backend_unbind(struct ttm_tt *ttm)
 			  gtt->ttm.ttm.num_pages, gtt->offset);
 }
 
-static void amdgpu_ttm_backend_destroy(struct ttm_tt *ttm)
+static void amdgpu_ttm_backend_destroy(struct ttm_bo_device *bdev,
+				       struct ttm_tt *ttm)
 {
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 
@@ -1289,10 +1294,11 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo,
  * Map the pages of a ttm_tt object to an address space visible
  * to the underlying device.
  */
-static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
-			struct ttm_operation_ctx *ctx)
+static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
+				  struct ttm_tt *ttm,
+				  struct ttm_operation_ctx *ctx)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(ttm->bdev);
+	struct amdgpu_device *adev = amdgpu_ttm_adev(bdev);
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 
 	/* user pages are bound by amdgpu_ttm_tt_pin_userptr() */
@@ -1343,7 +1349,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_tt *ttm,
  * Unmaps pages of a ttm_tt object from the device address space and
  * unpopulates the page array backing it.
  */
-static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
+static void amdgpu_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct amdgpu_ttm_tt *gtt = (void *)ttm;
 	struct amdgpu_device *adev;
@@ -1367,7 +1373,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	if (ttm->page_flags & TTM_PAGE_FLAG_SG)
 		return;
 
-	adev = amdgpu_ttm_adev(ttm->bdev);
+	adev = amdgpu_ttm_adev(bdev);
 
 #ifdef CONFIG_SWIOTLB
 	if (adev->need_swiotlb && swiotlb_nr_tbl()) {
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 545a877406f4..788557bc5c01 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -967,7 +967,7 @@ static const struct drm_gem_object_funcs drm_gem_vram_object_funcs = {
  * TTM TT
  */
 
-static void backend_func_destroy(struct ttm_tt *tt)
+static void backend_func_destroy(struct ttm_bo_device *bdev, struct ttm_tt *tt)
 {
 	ttm_tt_fini(tt);
 	kfree(tt);
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 90bd66ff8dc7..9e6425a0cb3f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -848,7 +848,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
 	if (ret)
 		return ret;
 
-	ret = ttm_tt_bind(bo->ttm, &tmp_reg, &ctx);
+	ret = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_reg, &ctx);
 	if (ret)
 		goto out;
 
@@ -1228,7 +1228,8 @@ nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
 }
 
 static int
-nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
+nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
+			struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
 	struct ttm_dma_tt *ttm_dma = (void *)ttm;
 	struct nouveau_drm *drm;
@@ -1246,12 +1247,12 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 		return 0;
 	}
 
-	drm = nouveau_bdev(ttm->bdev);
+	drm = nouveau_bdev(bdev);
 	dev = drm->dev->dev;
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (drm->agp.bridge) {
-		return ttm_agp_tt_populate(ttm, ctx);
+		return ttm_agp_tt_populate(bdev, ttm, ctx);
 	}
 #endif
 
@@ -1264,7 +1265,8 @@ nouveau_ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 }
 
 static void
-nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
+nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev,
+			  struct ttm_tt *ttm)
 {
 	struct ttm_dma_tt *ttm_dma = (void *)ttm;
 	struct nouveau_drm *drm;
@@ -1274,12 +1276,12 @@ nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	if (slave)
 		return;
 
-	drm = nouveau_bdev(ttm->bdev);
+	drm = nouveau_bdev(bdev);
 	dev = drm->dev->dev;
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (drm->agp.bridge) {
-		ttm_agp_tt_unpopulate(ttm);
+		ttm_agp_tt_unpopulate(bdev, ttm);
 		return;
 	}
 #endif
diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
index eef75c53a197..6000c650b105 100644
--- a/drivers/gpu/drm/nouveau/nouveau_sgdma.c
+++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
@@ -15,7 +15,7 @@ struct nouveau_sgdma_be {
 };
 
 static void
-nouveau_sgdma_destroy(struct ttm_tt *ttm)
+nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
 
@@ -26,7 +26,7 @@ nouveau_sgdma_destroy(struct ttm_tt *ttm)
 }
 
 static int
-nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_resource *reg)
+nv04_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
 	struct nouveau_mem *mem = nouveau_mem(reg);
@@ -47,7 +47,7 @@ nv04_sgdma_bind(struct ttm_tt *ttm, struct ttm_resource *reg)
 }
 
 static void
-nv04_sgdma_unbind(struct ttm_tt *ttm)
+nv04_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
 	nouveau_mem_fini(nvbe->mem);
@@ -60,7 +60,7 @@ static struct ttm_backend_func nv04_sgdma_backend = {
 };
 
 static int
-nv50_sgdma_bind(struct ttm_tt *ttm, struct ttm_resource *reg)
+nv50_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
 	struct nouveau_mem *mem = nouveau_mem(reg);
diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index d0889df989e6..c3530c6e46bd 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -104,7 +104,8 @@ struct qxl_ttm_tt {
 	u64				offset;
 };
 
-static int qxl_ttm_backend_bind(struct ttm_tt *ttm,
+static int qxl_ttm_backend_bind(struct ttm_bo_device *bdev,
+				struct ttm_tt *ttm,
 				struct ttm_resource *bo_mem)
 {
 	struct qxl_ttm_tt *gtt = (void *)ttm;
@@ -118,12 +119,14 @@ static int qxl_ttm_backend_bind(struct ttm_tt *ttm,
 	return -1;
 }
 
-static void qxl_ttm_backend_unbind(struct ttm_tt *ttm)
+static void qxl_ttm_backend_unbind(struct ttm_bo_device *bdev,
+				   struct ttm_tt *ttm)
 {
 	/* Not implemented */
 }
 
-static void qxl_ttm_backend_destroy(struct ttm_tt *ttm)
+static void qxl_ttm_backend_destroy(struct ttm_bo_device *bdev,
+				    struct ttm_tt *ttm)
 {
 	struct qxl_ttm_tt *gtt = (void *)ttm;
 
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 0923a8601112..1d3e8bb69f8e 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -234,7 +234,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
 		goto out_cleanup;
 	}
 
-	r = ttm_tt_bind(bo->ttm, &tmp_mem, &ctx);
+	r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem, &ctx);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
@@ -420,9 +420,9 @@ struct radeon_ttm_tt {
 };
 
 /* prepare the sg table with the user pages */
-static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
+static int radeon_ttm_tt_pin_userptr(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
 	struct radeon_ttm_tt *gtt = (void *)ttm;
 	unsigned pinned = 0;
 	int r;
@@ -481,9 +481,9 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_tt *ttm)
 	return r;
 }
 
-static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
+static void radeon_ttm_tt_unpin_userptr(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
 	struct radeon_ttm_tt *gtt = (void *)ttm;
 	struct sg_page_iter sg_iter;
 
@@ -510,17 +510,18 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_tt *ttm)
 	sg_free_table(ttm->sg);
 }
 
-static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
+static int radeon_ttm_backend_bind(struct ttm_bo_device *bdev,
+				   struct ttm_tt *ttm,
 				   struct ttm_resource *bo_mem)
 {
 	struct radeon_ttm_tt *gtt = (void*)ttm;
-	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
 	uint32_t flags = RADEON_GART_PAGE_VALID | RADEON_GART_PAGE_READ |
 		RADEON_GART_PAGE_WRITE;
 	int r;
 
 	if (gtt->userptr) {
-		radeon_ttm_tt_pin_userptr(ttm);
+		radeon_ttm_tt_pin_userptr(bdev, ttm);
 		flags &= ~RADEON_GART_PAGE_WRITE;
 	}
 
@@ -541,18 +542,18 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
 	return 0;
 }
 
-static void radeon_ttm_backend_unbind(struct ttm_tt *ttm)
+static void radeon_ttm_backend_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct radeon_ttm_tt *gtt = (void *)ttm;
-	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
 
 	radeon_gart_unbind(rdev, gtt->offset, ttm->num_pages);
 
 	if (gtt->userptr)
-		radeon_ttm_tt_unpin_userptr(ttm);
+		radeon_ttm_tt_unpin_userptr(bdev, ttm);
 }
 
-static void radeon_ttm_backend_destroy(struct ttm_tt *ttm)
+static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct radeon_ttm_tt *gtt = (void *)ttm;
 
@@ -599,8 +600,9 @@ static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)
 	return (struct radeon_ttm_tt *)ttm;
 }
 
-static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
-			struct ttm_operation_ctx *ctx)
+static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
+				  struct ttm_tt *ttm,
+				  struct ttm_operation_ctx *ctx)
 {
 	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
 	struct radeon_device *rdev;
@@ -623,10 +625,10 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
 		return 0;
 	}
 
-	rdev = radeon_get_rdev(ttm->bdev);
+	rdev = radeon_get_rdev(bdev);
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
-		return ttm_agp_tt_populate(ttm, ctx);
+		return ttm_agp_tt_populate(bdev, ttm, ctx);
 	}
 #endif
 
@@ -639,7 +641,7 @@ static int radeon_ttm_tt_populate(struct ttm_tt *ttm,
 	return ttm_populate_and_map_pages(rdev->dev, &gtt->ttm, ctx);
 }
 
-static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
+static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct radeon_device *rdev;
 	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
@@ -654,10 +656,10 @@ static void radeon_ttm_tt_unpopulate(struct ttm_tt *ttm)
 	if (slave)
 		return;
 
-	rdev = radeon_get_rdev(ttm->bdev);
+	rdev = radeon_get_rdev(bdev);
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
-		ttm_agp_tt_unpopulate(ttm);
+		ttm_agp_tt_unpopulate(bdev, ttm);
 		return;
 	}
 #endif
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 09fe80e215c5..934a69491547 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -48,7 +48,8 @@ struct ttm_agp_backend {
 	struct agp_bridge_data *bridge;
 };
 
-static int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem)
+static int ttm_agp_bind(struct ttm_bo_device *bdev,
+			struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 	struct page *dummy_read_page = ttm_bo_glob.dummy_read_page;
@@ -82,7 +83,8 @@ static int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 	return ret;
 }
 
-static void ttm_agp_unbind(struct ttm_tt *ttm)
+static void ttm_agp_unbind(struct ttm_bo_device *bdev,
+			   struct ttm_tt *ttm)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 
@@ -96,12 +98,13 @@ static void ttm_agp_unbind(struct ttm_tt *ttm)
 	}
 }
 
-static void ttm_agp_destroy(struct ttm_tt *ttm)
+static void ttm_agp_destroy(struct ttm_bo_device *bdev,
+			    struct ttm_tt *ttm)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 
 	if (agp_be->mem)
-		ttm_agp_unbind(ttm);
+		ttm_agp_unbind(bdev, ttm);
 	ttm_tt_fini(ttm);
 	kfree(agp_be);
 }
@@ -135,7 +138,8 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 }
 EXPORT_SYMBOL(ttm_agp_tt_create);
 
-int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
+int ttm_agp_tt_populate(struct ttm_bo_device *bdev,
+			struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
 	if (ttm->state != tt_unpopulated)
 		return 0;
@@ -144,7 +148,8 @@ int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 }
 EXPORT_SYMBOL(ttm_agp_tt_populate);
 
-void ttm_agp_tt_unpopulate(struct ttm_tt *ttm)
+void ttm_agp_tt_unpopulate(struct ttm_bo_device *bdev,
+			   struct ttm_tt *ttm)
 {
 	ttm_pool_unpopulate(ttm);
 }
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 8257421fc9a0..fa9012c8d11a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -282,7 +282,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 			goto out_err;
 
 		if (mem->mem_type != TTM_PL_SYSTEM) {
-			ret = ttm_tt_bind(bo->ttm, mem, ctx);
+			ret = ttm_tt_bind(bdev, bo->ttm, mem, ctx);
 			if (ret)
 				goto out_err;
 		}
@@ -324,7 +324,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 out_err:
 	new_man = ttm_manager_type(bdev, bo->mem.mem_type);
 	if (!new_man->use_tt) {
-		ttm_tt_destroy(bo->ttm);
+		ttm_tt_destroy(bdev, bo->ttm);
 		bo->ttm = NULL;
 	}
 
@@ -344,7 +344,7 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
 	if (bo->bdev->driver->move_notify)
 		bo->bdev->driver->move_notify(bo, false, NULL);
 
-	ttm_tt_destroy(bo->ttm);
+	ttm_tt_destroy(bo->bdev, bo->ttm);
 	bo->ttm = NULL;
 	ttm_resource_free(bo, &bo->mem);
 }
@@ -1653,7 +1653,7 @@ int ttm_bo_swapout(struct ttm_bo_global *glob, struct ttm_operation_ctx *ctx)
 	if (bo->bdev->driver->swap_notify)
 		bo->bdev->driver->swap_notify(bo);
 
-	ret = ttm_tt_swapout(bo->ttm, bo->persistent_swap_storage);
+	ret = ttm_tt_swapout(bo->bdev, bo->ttm, bo->persistent_swap_storage);
 out:
 
 	/**
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 72a353d5c3a7..3b17fe3cb57a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -67,7 +67,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 			return ret;
 		}
 
-		ttm_tt_unbind(ttm);
+		ttm_tt_unbind(bo->bdev, ttm);
 		ttm_bo_free_old_node(bo);
 		ttm_flag_masked(&old_mem->placement, TTM_PL_FLAG_SYSTEM,
 				TTM_PL_MASK_MEM);
@@ -79,7 +79,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 		return ret;
 
 	if (new_mem->mem_type != TTM_PL_SYSTEM) {
-		ret = ttm_tt_bind(ttm, new_mem, ctx);
+		ret = ttm_tt_bind(bo->bdev, ttm, new_mem, ctx);
 		if (unlikely(ret != 0))
 			return ret;
 	}
@@ -261,7 +261,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 	 * TTM might be null for moves within the same region.
 	 */
 	if (ttm) {
-		ret = ttm_tt_populate(ttm, ctx);
+		ret = ttm_tt_populate(bdev, ttm, ctx);
 		if (ret)
 			goto out1;
 	}
@@ -300,7 +300,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 	new_mem->mm_node = NULL;
 
 	if (!man->use_tt) {
-		ttm_tt_destroy(ttm);
+		ttm_tt_destroy(bdev, ttm);
 		bo->ttm = NULL;
 	}
 
@@ -451,7 +451,7 @@ static int ttm_bo_kmap_ttm(struct ttm_buffer_object *bo,
 
 	BUG_ON(!ttm);
 
-	ret = ttm_tt_populate(ttm, &ctx);
+	ret = ttm_tt_populate(bo->bdev, ttm, &ctx);
 	if (ret)
 		return ret;
 
@@ -547,7 +547,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 			return ret;
 
 		if (!man->use_tt) {
-			ttm_tt_destroy(bo->ttm);
+			ttm_tt_destroy(bdev, bo->ttm);
 			bo->ttm = NULL;
 		}
 		ttm_bo_free_old_node(bo);
@@ -670,7 +670,7 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 			return ret;
 
 		if (!to->use_tt) {
-			ttm_tt_destroy(bo->ttm);
+			ttm_tt_destroy(bdev, bo->ttm);
 			bo->ttm = NULL;
 		}
 		ttm_bo_free_old_node(bo);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index d3dc0682425c..bb96f819f607 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -341,7 +341,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
 		};
 
 		ttm = bo->ttm;
-		if (ttm_tt_populate(bo->ttm, &ctx))
+		if (ttm_tt_populate(bdev, bo->ttm, &ctx))
 			return VM_FAULT_OOM;
 	} else {
 		/* Iomem should not be marked encrypted */
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 1ccf1ef050d6..50a899104022 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -207,29 +207,28 @@ int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement)
 }
 EXPORT_SYMBOL(ttm_tt_set_placement_caching);
 
-void ttm_tt_destroy(struct ttm_tt *ttm)
+void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	if (ttm == NULL)
 		return;
 
-	ttm_tt_unbind(ttm);
+	ttm_tt_unbind(bdev, ttm);
 
 	if (ttm->state == tt_unbound)
-		ttm_tt_unpopulate(ttm);
+		ttm_tt_unpopulate(bdev, ttm);
 
 	if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
 	    ttm->swap_storage)
 		fput(ttm->swap_storage);
 
 	ttm->swap_storage = NULL;
-	ttm->func->destroy(ttm);
+	ttm->func->destroy(bdev, ttm);
 }
 
 static void ttm_tt_init_fields(struct ttm_tt *ttm,
 			       struct ttm_buffer_object *bo,
 			       uint32_t page_flags)
 {
-	ttm->bdev = bo->bdev;
 	ttm->num_pages = bo->num_pages;
 	ttm->caching_state = tt_cached;
 	ttm->page_flags = page_flags;
@@ -308,15 +307,16 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma)
 }
 EXPORT_SYMBOL(ttm_dma_tt_fini);
 
-void ttm_tt_unbind(struct ttm_tt *ttm)
+void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	if (ttm->state == tt_bound) {
-		ttm->func->unbind(ttm);
+		ttm->func->unbind(bdev, ttm);
 		ttm->state = tt_unbound;
 	}
 }
 
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem,
+int ttm_tt_bind(struct ttm_bo_device *bdev,
+		struct ttm_tt *ttm, struct ttm_resource *bo_mem,
 		struct ttm_operation_ctx *ctx)
 {
 	int ret = 0;
@@ -327,11 +327,11 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem,
 	if (ttm->state == tt_bound)
 		return 0;
 
-	ret = ttm_tt_populate(ttm, ctx);
+	ret = ttm_tt_populate(bdev, ttm, ctx);
 	if (ret)
 		return ret;
 
-	ret = ttm->func->bind(ttm, bo_mem);
+	ret = ttm->func->bind(bdev, ttm, bo_mem);
 	if (unlikely(ret != 0))
 		return ret;
 
@@ -383,7 +383,8 @@ int ttm_tt_swapin(struct ttm_tt *ttm)
 	return ret;
 }
 
-int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
+int ttm_tt_swapout(struct ttm_bo_device *bdev,
+		   struct ttm_tt *ttm, struct file *persistent_swap_storage)
 {
 	struct address_space *swap_space;
 	struct file *swap_storage;
@@ -429,7 +430,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 		put_page(to_page);
 	}
 
-	ttm_tt_unpopulate(ttm);
+	ttm_tt_unpopulate(bdev, ttm);
 	ttm->swap_storage = swap_storage;
 	ttm->page_flags |= TTM_PAGE_FLAG_SWAPPED;
 	if (persistent_swap_storage)
@@ -443,7 +444,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage)
 	return ret;
 }
 
-static void ttm_tt_add_mapping(struct ttm_tt *ttm)
+static void ttm_tt_add_mapping(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	pgoff_t i;
 
@@ -451,22 +452,23 @@ static void ttm_tt_add_mapping(struct ttm_tt *ttm)
 		return;
 
 	for (i = 0; i < ttm->num_pages; ++i)
-		ttm->pages[i]->mapping = ttm->bdev->dev_mapping;
+		ttm->pages[i]->mapping = bdev->dev_mapping;
 }
 
-int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
+int ttm_tt_populate(struct ttm_bo_device *bdev,
+		    struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
 	int ret;
 
 	if (ttm->state != tt_unpopulated)
 		return 0;
 
-	if (ttm->bdev->driver->ttm_tt_populate)
-		ret = ttm->bdev->driver->ttm_tt_populate(ttm, ctx);
+	if (bdev->driver->ttm_tt_populate)
+		ret = bdev->driver->ttm_tt_populate(bdev, ttm, ctx);
 	else
 		ret = ttm_pool_populate(ttm, ctx);
 	if (!ret)
-		ttm_tt_add_mapping(ttm);
+		ttm_tt_add_mapping(bdev, ttm);
 	return ret;
 }
 
@@ -484,14 +486,15 @@ static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
 	}
 }
 
-void ttm_tt_unpopulate(struct ttm_tt *ttm)
+void ttm_tt_unpopulate(struct ttm_bo_device *bdev,
+		       struct ttm_tt *ttm)
 {
 	if (ttm->state == tt_unpopulated)
 		return;
 
 	ttm_tt_clear_mapping(ttm);
-	if (ttm->bdev->driver->ttm_tt_unpopulate)
-		ttm->bdev->driver->ttm_tt_unpopulate(ttm);
+	if (bdev->driver->ttm_tt_unpopulate)
+		bdev->driver->ttm_tt_unpopulate(bdev, ttm);
 	else
 		ttm_pool_unpopulate(ttm);
 }
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index 1629427d5734..0cd21590ded9 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -465,13 +465,13 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
 		dma_resv_assert_held(src->base.resv);
 
 	if (dst->ttm->state == tt_unpopulated) {
-		ret = dst->ttm->bdev->driver->ttm_tt_populate(dst->ttm, &ctx);
+		ret = dst->bdev->driver->ttm_tt_populate(dst->bdev, dst->ttm, &ctx);
 		if (ret)
 			return ret;
 	}
 
 	if (src->ttm->state == tt_unpopulated) {
-		ret = src->ttm->bdev->driver->ttm_tt_populate(src->ttm, &ctx);
+		ret = src->bdev->driver->ttm_tt_populate(src->bdev, src->ttm, &ctx);
 		if (ret)
 			return ret;
 	}
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index c7f10b2c93d2..a76a7f542dd8 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -539,7 +539,8 @@ const struct vmw_sg_table *vmw_bo_sg_table(struct ttm_buffer_object *bo)
 }
 
 
-static int vmw_ttm_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem)
+static int vmw_ttm_bind(struct ttm_bo_device *bdev,
+			struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 {
 	struct vmw_ttm_tt *vmw_be =
 		container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
@@ -573,7 +574,8 @@ static int vmw_ttm_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 	return 0;
 }
 
-static void vmw_ttm_unbind(struct ttm_tt *ttm)
+static void vmw_ttm_unbind(struct ttm_bo_device *bdev,
+			   struct ttm_tt *ttm)
 {
 	struct vmw_ttm_tt *vmw_be =
 		container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
@@ -594,7 +596,7 @@ static void vmw_ttm_unbind(struct ttm_tt *ttm)
 }
 
 
-static void vmw_ttm_destroy(struct ttm_tt *ttm)
+static void vmw_ttm_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct vmw_ttm_tt *vmw_be =
 		container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
@@ -612,7 +614,8 @@ static void vmw_ttm_destroy(struct ttm_tt *ttm)
 }
 
 
-static int vmw_ttm_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
+static int vmw_ttm_populate(struct ttm_bo_device *bdev,
+			    struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 {
 	struct vmw_ttm_tt *vmw_tt =
 		container_of(ttm, struct vmw_ttm_tt, dma_ttm.ttm);
@@ -640,7 +643,8 @@ static int vmw_ttm_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 	return ret;
 }
 
-static void vmw_ttm_unpopulate(struct ttm_tt *ttm)
+static void vmw_ttm_unpopulate(struct ttm_bo_device *bdev,
+			       struct ttm_tt *ttm)
 {
 	struct vmw_ttm_tt *vmw_tt = container_of(ttm, struct vmw_ttm_tt,
 						 dma_ttm.ttm);
@@ -796,7 +800,7 @@ int vmw_bo_create_and_populate(struct vmw_private *dev_priv,
 
 	ret = ttm_bo_reserve(bo, false, true, NULL);
 	BUG_ON(ret != 0);
-	ret = vmw_ttm_populate(bo->ttm, &ctx);
+	ret = vmw_ttm_populate(bo->bdev, bo->ttm, &ctx);
 	if (likely(ret == 0)) {
 		struct vmw_ttm_tt *vmw_tt =
 			container_of(bo->ttm, struct vmw_ttm_tt, dma_ttm.ttm);
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index af1f39b77144..ebba282667ba 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -77,8 +77,9 @@ struct ttm_bo_driver {
 	 * Returns:
 	 * -ENOMEM: Out of memory.
 	 */
-	int (*ttm_tt_populate)(struct ttm_tt *ttm,
-			struct ttm_operation_ctx *ctx);
+	int (*ttm_tt_populate)(struct ttm_bo_device *bdev,
+			       struct ttm_tt *ttm,
+			       struct ttm_operation_ctx *ctx);
 
 	/**
 	 * ttm_tt_unpopulate
@@ -87,7 +88,7 @@ struct ttm_bo_driver {
 	 *
 	 * Free all backing page
 	 */
-	void (*ttm_tt_unpopulate)(struct ttm_tt *ttm);
+	void (*ttm_tt_unpopulate)(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
 	/**
 	 * struct ttm_bo_driver member eviction_valuable
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 241cc40839ed..6bda88f8da46 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -60,7 +60,7 @@ struct ttm_backend_func {
 	 * indicated by @bo_mem. This function should be able to handle
 	 * differences between aperture and system page sizes.
 	 */
-	int (*bind) (struct ttm_tt *ttm, struct ttm_resource *bo_mem);
+	int (*bind) (struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem);
 
 	/**
 	 * struct ttm_backend_func member unbind
@@ -70,7 +70,7 @@ struct ttm_backend_func {
 	 * Unbind previously bound backend pages. This function should be
 	 * able to handle differences between aperture and system page sizes.
 	 */
-	void (*unbind) (struct ttm_tt *ttm);
+	void (*unbind) (struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
 	/**
 	 * struct ttm_backend_func member destroy
@@ -80,13 +80,12 @@ struct ttm_backend_func {
 	 * Destroy the backend. This will be call back from ttm_tt_destroy so
 	 * don't call ttm_tt_destroy from the callback or infinite loop.
 	 */
-	void (*destroy) (struct ttm_tt *ttm);
+	void (*destroy) (struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 };
 
 /**
  * struct ttm_tt
  *
- * @bdev: Pointer to a struct ttm_bo_device.
  * @func: Pointer to a struct ttm_backend_func that describes
  * the backend methods.
  * pointer.
@@ -103,7 +102,6 @@ struct ttm_backend_func {
  * memory.
  */
 struct ttm_tt {
-	struct ttm_bo_device *bdev;
 	struct ttm_backend_func *func;
 	struct page **pages;
 	uint32_t page_flags;
@@ -183,7 +181,8 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
  *
  * Bind the pages of @ttm to an aperture location identified by @bo_mem
  */
-int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem,
+int ttm_tt_bind(struct ttm_bo_device *bdev,
+		struct ttm_tt *ttm, struct ttm_resource *bo_mem,
 		struct ttm_operation_ctx *ctx);
 
 /**
@@ -193,7 +192,7 @@ int ttm_tt_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem,
  *
  * Unbind, unpopulate and destroy common struct ttm_tt.
  */
-void ttm_tt_destroy(struct ttm_tt *ttm);
+void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
 /**
  * ttm_ttm_unbind:
@@ -202,7 +201,7 @@ void ttm_tt_destroy(struct ttm_tt *ttm);
  *
  * Unbind a struct ttm_tt.
  */
-void ttm_tt_unbind(struct ttm_tt *ttm);
+void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
 /**
  * ttm_tt_swapin:
@@ -227,7 +226,7 @@ int ttm_tt_swapin(struct ttm_tt *ttm);
  * and cache flushes and potential page splitting / combining.
  */
 int ttm_tt_set_placement_caching(struct ttm_tt *ttm, uint32_t placement);
-int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage);
+int ttm_tt_swapout(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct file *persistent_swap_storage);
 
 /**
  * ttm_tt_populate - allocate pages for a ttm
@@ -236,7 +235,7 @@ int ttm_tt_swapout(struct ttm_tt *ttm, struct file *persistent_swap_storage);
  *
  * Calls the driver method to allocate pages for a ttm
  */
-int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
+int ttm_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
 
 /**
  * ttm_tt_unpopulate - free pages from a ttm
@@ -245,7 +244,7 @@ int ttm_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
  *
  * Calls the driver method to free all pages from a ttm
  */
-void ttm_tt_unpopulate(struct ttm_tt *ttm);
+void ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
 #if IS_ENABLED(CONFIG_AGP)
 #include <linux/agp_backend.h>
@@ -265,8 +264,8 @@ void ttm_tt_unpopulate(struct ttm_tt *ttm);
 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 				 struct agp_bridge_data *bridge,
 				 uint32_t page_flags);
-int ttm_agp_tt_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
-void ttm_agp_tt_unpopulate(struct ttm_tt *ttm);
+int ttm_agp_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
+void ttm_agp_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 #endif
 
 #endif
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 04/23] drm/ttm: add optional bind/unbind via driver.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (2 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 03/23] drm/ttm: remove bdev from ttm_tt Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 05/23] drm/qxl: move bind/unbind/destroy to the driver function table Dave Airlie
                   ` (19 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

I want to remove the backend funcs

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_tt.c    | 15 +++++++++++---
 include/drm/ttm/ttm_bo_driver.h | 36 +++++++++++++++++++++++++++++++++
 2 files changed, 48 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 50a899104022..73c97dcfa512 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -222,7 +222,10 @@ void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 		fput(ttm->swap_storage);
 
 	ttm->swap_storage = NULL;
-	ttm->func->destroy(bdev, ttm);
+	if (bdev->driver->ttm_tt_destroy)
+		bdev->driver->ttm_tt_destroy(bdev, ttm);
+	else
+		ttm->func->destroy(bdev, ttm);
 }
 
 static void ttm_tt_init_fields(struct ttm_tt *ttm,
@@ -310,7 +313,10 @@ EXPORT_SYMBOL(ttm_dma_tt_fini);
 void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	if (ttm->state == tt_bound) {
-		ttm->func->unbind(bdev, ttm);
+		if (bdev->driver->ttm_tt_unbind)
+			bdev->driver->ttm_tt_unbind(bdev, ttm);
+		else
+			ttm->func->unbind(bdev, ttm);
 		ttm->state = tt_unbound;
 	}
 }
@@ -331,7 +337,10 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	if (ret)
 		return ret;
 
-	ret = ttm->func->bind(bdev, ttm, bo_mem);
+	if (bdev->driver->ttm_tt_bind)
+		ret = bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
+	else
+		ret = ttm->func->bind(bdev, ttm, bo_mem);
 	if (unlikely(ret != 0))
 		return ret;
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index ebba282667ba..32c0651cc0fd 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -90,6 +90,42 @@ struct ttm_bo_driver {
 	 */
 	void (*ttm_tt_unpopulate)(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
+	/**
+	 * ttm_tt_bind
+	 *
+	 * @bdev: Pointer to a ttm device
+	 * @ttm: Pointer to a struct ttm_tt.
+	 * @bo_mem: Pointer to a struct ttm_resource describing the
+	 * memory type and location for binding.
+	 *
+	 * Bind the backend pages into the aperture in the location
+	 * indicated by @bo_mem. This function should be able to handle
+	 * differences between aperture and system page sizes.
+	 */
+	int (*ttm_tt_bind)(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem);
+
+	/**
+	 * ttm_tt_unbind
+	 *
+	 * @bdev: Pointer to a ttm device
+	 * @ttm: Pointer to a struct ttm_tt.
+	 *
+	 * Unbind previously bound backend pages. This function should be
+	 * able to handle differences between aperture and system page sizes.
+	 */
+	void (*ttm_tt_unbind)(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
+
+	/**
+	 * ttm_tt_destroy
+	 *
+	 * @bdev: Pointer to a ttm device
+	 * @ttm: Pointer to a struct ttm_tt.
+	 *
+	 * Destroy the backend. This will be call back from ttm_tt_destroy so
+	 * don't call ttm_tt_destroy from the callback or infinite loop.
+	 */
+	void (*ttm_tt_destroy)(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
+
 	/**
 	 * struct ttm_bo_driver member eviction_valuable
 	 *
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 05/23] drm/qxl: move bind/unbind/destroy to the driver function table.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (3 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 04/23] drm/ttm: add optional bind/unbind via driver Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 06/23] drm/ttm/agp: export bind/unbind/destroy for drivers to use Dave Airlie
                   ` (18 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/qxl/qxl_ttm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index c3530c6e46bd..4970c3450e88 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -134,12 +134,6 @@ static void qxl_ttm_backend_destroy(struct ttm_bo_device *bdev,
 	kfree(gtt);
 }
 
-static struct ttm_backend_func qxl_backend_func = {
-	.bind = &qxl_ttm_backend_bind,
-	.unbind = &qxl_ttm_backend_unbind,
-	.destroy = &qxl_ttm_backend_destroy,
-};
-
 static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo,
 					uint32_t page_flags)
 {
@@ -150,7 +144,6 @@ static struct ttm_tt *qxl_ttm_tt_create(struct ttm_buffer_object *bo,
 	gtt = kzalloc(sizeof(struct qxl_ttm_tt), GFP_KERNEL);
 	if (gtt == NULL)
 		return NULL;
-	gtt->ttm.func = &qxl_backend_func;
 	gtt->qdev = qdev;
 	if (ttm_tt_init(&gtt->ttm, bo, page_flags)) {
 		kfree(gtt);
@@ -195,6 +188,9 @@ static void qxl_bo_move_notify(struct ttm_buffer_object *bo,
 
 static struct ttm_bo_driver qxl_bo_driver = {
 	.ttm_tt_create = &qxl_ttm_tt_create,
+	.ttm_tt_bind = &qxl_ttm_backend_bind,
+	.ttm_tt_destroy = &qxl_ttm_backend_destroy,
+	.ttm_tt_unbind = &qxl_ttm_backend_unbind,
 	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = &qxl_evict_flags,
 	.move = &qxl_bo_move,
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 06/23] drm/ttm/agp: export bind/unbind/destroy for drivers to use.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (4 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 05/23] drm/qxl: move bind/unbind/destroy to the driver function table Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 07/23] drm/radeon/ttm: move to driver binding/destroy functions Dave Airlie
                   ` (17 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_agp_backend.c | 15 +++++++++------
 include/drm/ttm/ttm_tt.h              |  6 ++++++
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 934a69491547..fbf98cd1a3e5 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -48,8 +48,8 @@ struct ttm_agp_backend {
 	struct agp_bridge_data *bridge;
 };
 
-static int ttm_agp_bind(struct ttm_bo_device *bdev,
-			struct ttm_tt *ttm, struct ttm_resource *bo_mem)
+int ttm_agp_bind(struct ttm_bo_device *bdev,
+		 struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 	struct page *dummy_read_page = ttm_bo_glob.dummy_read_page;
@@ -82,9 +82,10 @@ static int ttm_agp_bind(struct ttm_bo_device *bdev,
 
 	return ret;
 }
+EXPORT_SYMBOL(ttm_agp_bind);
 
-static void ttm_agp_unbind(struct ttm_bo_device *bdev,
-			   struct ttm_tt *ttm)
+void ttm_agp_unbind(struct ttm_bo_device *bdev,
+		    struct ttm_tt *ttm)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 
@@ -97,9 +98,10 @@ static void ttm_agp_unbind(struct ttm_bo_device *bdev,
 		agp_be->mem = NULL;
 	}
 }
+EXPORT_SYMBOL(ttm_agp_unbind);
 
-static void ttm_agp_destroy(struct ttm_bo_device *bdev,
-			    struct ttm_tt *ttm)
+void ttm_agp_destroy(struct ttm_bo_device *bdev,
+		     struct ttm_tt *ttm)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 
@@ -108,6 +110,7 @@ static void ttm_agp_destroy(struct ttm_bo_device *bdev,
 	ttm_tt_fini(ttm);
 	kfree(agp_be);
 }
+EXPORT_SYMBOL(ttm_agp_destroy);
 
 static struct ttm_backend_func ttm_agp_func = {
 	.bind = ttm_agp_bind,
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 6bda88f8da46..5a34f1640865 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -266,6 +266,12 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 				 uint32_t page_flags);
 int ttm_agp_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
 void ttm_agp_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
+int ttm_agp_bind(struct ttm_bo_device *bdev,
+		 struct ttm_tt *ttm, struct ttm_resource *bo_mem);
+void ttm_agp_unbind(struct ttm_bo_device *bdev,
+		    struct ttm_tt *ttm);
+void ttm_agp_destroy(struct ttm_bo_device *bdev,
+		     struct ttm_tt *ttm);
 #endif
 
 #endif
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 07/23] drm/radeon/ttm: move to driver binding/destroy functions.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (5 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 06/23] drm/ttm/agp: export bind/unbind/destroy for drivers to use Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-27 11:42   ` Christian König
  2020-08-26  1:44 ` [PATCH 08/23] drm/nouveau/ttm: use driver bind/unbind/destroy functions Dave Airlie
                   ` (16 subsequent siblings)
  23 siblings, 1 reply; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Do agp decision in the driver, instead of special binding funcs

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/radeon/radeon.h        |  7 +-
 drivers/gpu/drm/radeon/radeon_cs.c     |  2 +-
 drivers/gpu/drm/radeon/radeon_gem.c    |  6 +-
 drivers/gpu/drm/radeon/radeon_object.c |  2 +-
 drivers/gpu/drm/radeon/radeon_prime.c  |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c    | 92 ++++++++++++++++++++------
 drivers/gpu/drm/radeon/radeon_vm.c     |  2 +-
 7 files changed, 81 insertions(+), 32 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
index cc4f58d16589..df6f0b49836b 100644
--- a/drivers/gpu/drm/radeon/radeon.h
+++ b/drivers/gpu/drm/radeon/radeon.h
@@ -2815,10 +2815,11 @@ extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enabl
 extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
 extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
 extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
-extern int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
+extern int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
+				     struct ttm_tt *ttm, uint64_t addr,
 				     uint32_t flags);
-extern bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm);
-extern bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm);
+extern bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev, struct ttm_tt *ttm);
+extern bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev, struct ttm_tt *ttm);
 extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
 extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
 extern int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
index 33ae1b883268..21ce2f9502c0 100644
--- a/drivers/gpu/drm/radeon/radeon_cs.c
+++ b/drivers/gpu/drm/radeon/radeon_cs.c
@@ -160,7 +160,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
 			p->relocs[i].allowed_domains = domain;
 		}
 
-		if (radeon_ttm_tt_has_userptr(p->relocs[i].robj->tbo.ttm)) {
+		if (radeon_ttm_tt_has_userptr(p->rdev, p->relocs[i].robj->tbo.ttm)) {
 			uint32_t domain = p->relocs[i].preferred_domains;
 			if (!(domain & RADEON_GEM_DOMAIN_GTT)) {
 				DRM_ERROR("Only RADEON_GEM_DOMAIN_GTT is "
diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index 7f5dfe04789e..e5c4271e64ed 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -331,7 +331,7 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data,
 		goto handle_lockup;
 
 	bo = gem_to_radeon_bo(gobj);
-	r = radeon_ttm_tt_set_userptr(bo->tbo.ttm, args->addr, args->flags);
+	r = radeon_ttm_tt_set_userptr(rdev, bo->tbo.ttm, args->addr, args->flags);
 	if (r)
 		goto release_object;
 
@@ -420,7 +420,7 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
 		return -ENOENT;
 	}
 	robj = gem_to_radeon_bo(gobj);
-	if (radeon_ttm_tt_has_userptr(robj->tbo.ttm)) {
+	if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm)) {
 		drm_gem_object_put(gobj);
 		return -EPERM;
 	}
@@ -721,7 +721,7 @@ int radeon_gem_op_ioctl(struct drm_device *dev, void *data,
 	robj = gem_to_radeon_bo(gobj);
 
 	r = -EPERM;
-	if (radeon_ttm_tt_has_userptr(robj->tbo.ttm))
+	if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm))
 		goto out;
 
 	r = radeon_bo_reserve(robj, false);
diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
index bb7582afd803..3fcd15d21ddc 100644
--- a/drivers/gpu/drm/radeon/radeon_object.c
+++ b/drivers/gpu/drm/radeon/radeon_object.c
@@ -331,7 +331,7 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
 	struct ttm_operation_ctx ctx = { false, false };
 	int r, i;
 
-	if (radeon_ttm_tt_has_userptr(bo->tbo.ttm))
+	if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
 		return -EPERM;
 
 	if (bo->pin_count) {
diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c
index b906e8fbd5f3..d6d9c8b46ab4 100644
--- a/drivers/gpu/drm/radeon/radeon_prime.c
+++ b/drivers/gpu/drm/radeon/radeon_prime.c
@@ -121,7 +121,7 @@ struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
 					int flags)
 {
 	struct radeon_bo *bo = gem_to_radeon_bo(gobj);
-	if (radeon_ttm_tt_has_userptr(bo->tbo.ttm))
+	if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
 		return ERR_PTR(-EPERM);
 	return drm_gem_prime_export(gobj, flags);
 }
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 1d3e8bb69f8e..af5479ea154c 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -141,8 +141,9 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
 static int radeon_verify_access(struct ttm_buffer_object *bo, struct file *filp)
 {
 	struct radeon_bo *rbo = container_of(bo, struct radeon_bo, tbo);
+	struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
 
-	if (radeon_ttm_tt_has_userptr(bo->ttm))
+	if (radeon_ttm_tt_has_userptr(rdev, bo->ttm))
 		return -EPERM;
 	return drm_vma_node_verify_access(&rbo->tbo.base.vma_node,
 					  filp->private_data);
@@ -561,12 +562,6 @@ static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_tt
 	kfree(gtt);
 }
 
-static struct ttm_backend_func radeon_backend_func = {
-	.bind = &radeon_ttm_backend_bind,
-	.unbind = &radeon_ttm_backend_unbind,
-	.destroy = &radeon_ttm_backend_destroy,
-};
-
 static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
 					   uint32_t page_flags)
 {
@@ -585,7 +580,6 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
 	if (gtt == NULL) {
 		return NULL;
 	}
-	gtt->ttm.ttm.func = &radeon_backend_func;
 	if (ttm_dma_tt_init(&gtt->ttm, bo, page_flags)) {
 		kfree(gtt);
 		return NULL;
@@ -593,9 +587,16 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
 	return &gtt->ttm.ttm;
 }
 
-static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)
+static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct radeon_device *rdev,
+						  struct ttm_tt *ttm)
 {
-	if (!ttm || ttm->func != &radeon_backend_func)
+#if IS_ENABLED(CONFIG_AGP)
+	if (rdev->flags & RADEON_IS_AGP) {
+		return NULL;
+	}
+#endif
+
+	if (!ttm)
 		return NULL;
 	return (struct radeon_ttm_tt *)ttm;
 }
@@ -604,8 +605,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 				  struct ttm_tt *ttm,
 				  struct ttm_operation_ctx *ctx)
 {
-	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
-	struct radeon_device *rdev;
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
+	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (gtt && gtt->userptr) {
@@ -625,7 +626,6 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 		return 0;
 	}
 
-	rdev = radeon_get_rdev(bdev);
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
 		return ttm_agp_tt_populate(bdev, ttm, ctx);
@@ -643,8 +643,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 
 static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-	struct radeon_device *rdev;
-	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
+	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (gtt && gtt->userptr) {
@@ -656,7 +656,6 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 	if (slave)
 		return;
 
-	rdev = radeon_get_rdev(bdev);
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
 		ttm_agp_tt_unpopulate(bdev, ttm);
@@ -674,10 +673,11 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 	ttm_unmap_and_unpopulate_pages(rdev->dev, &gtt->ttm);
 }
 
-int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
+int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
+			      struct ttm_tt *ttm, uint64_t addr,
 			      uint32_t flags)
 {
-	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
+	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
 
 	if (gtt == NULL)
 		return -EINVAL;
@@ -688,9 +688,53 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
 	return 0;
 }
 
-bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
+static int radeon_ttm_tt_bind(struct ttm_bo_device *bdev,
+			      struct ttm_tt *ttm,
+			      struct ttm_resource *bo_mem)
+{
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
+
+#if IS_ENABLED(CONFIG_AGP)
+	if (rdev->flags & RADEON_IS_AGP) {
+		return ttm_agp_bind(bdev, ttm, bo_mem);
+	}
+#endif
+
+	return radeon_ttm_backend_bind(bdev, ttm, bo_mem);
+}
+
+static void radeon_ttm_tt_unbind(struct ttm_bo_device *bdev,
+				 struct ttm_tt *ttm)
+{
+#if IS_ENABLED(CONFIG_AGP)
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
+
+	if (rdev->flags & RADEON_IS_AGP) {
+		ttm_agp_unbind(bdev, ttm);
+		return;
+	}
+#endif
+	radeon_ttm_backend_unbind(bdev, ttm);
+}
+
+static void radeon_ttm_tt_destroy(struct ttm_bo_device *bdev,
+				  struct ttm_tt *ttm)
+{
+#if IS_ENABLED(CONFIG_AGP)
+	struct radeon_device *rdev = radeon_get_rdev(bdev);
+
+	if (rdev->flags & RADEON_IS_AGP) {
+		ttm_agp_destroy(bdev, ttm);
+		return;
+	}
+#endif
+	radeon_ttm_backend_destroy(bdev, ttm);
+}
+
+bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev,
+			       struct ttm_tt *ttm)
 {
-	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
+	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
 
 	if (gtt == NULL)
 		return false;
@@ -698,9 +742,10 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
 	return !!gtt->userptr;
 }
 
-bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm)
+bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev,
+			       struct ttm_tt *ttm)
 {
-	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
+	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
 
 	if (gtt == NULL)
 		return false;
@@ -712,6 +757,9 @@ static struct ttm_bo_driver radeon_bo_driver = {
 	.ttm_tt_create = &radeon_ttm_tt_create,
 	.ttm_tt_populate = &radeon_ttm_tt_populate,
 	.ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
+	.ttm_tt_bind = &radeon_ttm_tt_bind,
+	.ttm_tt_unbind = &radeon_ttm_tt_unbind,
+	.ttm_tt_destroy = &radeon_ttm_tt_destroy,
 	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = &radeon_evict_flags,
 	.move = &radeon_bo_move,
diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
index 71e2c3785ab9..ebad27c91a0d 100644
--- a/drivers/gpu/drm/radeon/radeon_vm.c
+++ b/drivers/gpu/drm/radeon/radeon_vm.c
@@ -942,7 +942,7 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
 	bo_va->flags &= ~RADEON_VM_PAGE_VALID;
 	bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM;
 	bo_va->flags &= ~RADEON_VM_PAGE_SNOOPED;
-	if (bo_va->bo && radeon_ttm_tt_is_readonly(bo_va->bo->tbo.ttm))
+	if (bo_va->bo && radeon_ttm_tt_is_readonly(rdev, bo_va->bo->tbo.ttm))
 		bo_va->flags &= ~RADEON_VM_PAGE_WRITEABLE;
 
 	if (mem) {
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 08/23] drm/nouveau/ttm: use driver bind/unbind/destroy functions.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (6 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 07/23] drm/radeon/ttm: move to driver binding/destroy functions Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 09/23] drm/vmwgfx: move to driver binding functions Dave Airlie
                   ` (15 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c    | 45 +++++++++++++++++++++
 drivers/gpu/drm/nouveau/nouveau_sgdma.c | 54 ++++++-------------------
 drivers/gpu/drm/nouveau/nouveau_ttm.h   |  3 ++
 3 files changed, 60 insertions(+), 42 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 9e6425a0cb3f..f16401feb965 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -668,6 +668,34 @@ nouveau_ttm_tt_create(struct ttm_buffer_object *bo, uint32_t page_flags)
 	return nouveau_sgdma_create_ttm(bo, page_flags);
 }
 
+static int
+nouveau_ttm_tt_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm,
+		    struct ttm_resource *reg)
+{
+#if IS_ENABLED(CONFIG_AGP)
+	struct nouveau_drm *drm = nouveau_bdev(bdev);
+
+	if (drm->agp.bridge) {
+		return ttm_agp_bind(bdev, ttm, reg);
+	}
+#endif
+	return nouveau_sgdma_bind(bdev, ttm, reg);
+}
+
+static void
+nouveau_ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
+{
+#if IS_ENABLED(CONFIG_AGP)
+	struct nouveau_drm *drm = nouveau_bdev(bdev);
+
+	if (drm->agp.bridge) {
+		ttm_agp_unbind(bdev, ttm);
+		return;
+	}
+#endif
+	nouveau_sgdma_unbind(bdev, ttm);
+}
+
 static void
 nouveau_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl)
 {
@@ -1296,6 +1324,20 @@ nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev,
 	ttm_unmap_and_unpopulate_pages(dev, ttm_dma);
 }
 
+static void
+nouveau_ttm_tt_destroy(struct ttm_bo_device *bdev,
+		       struct ttm_tt *ttm)
+{
+#if IS_ENABLED(CONFIG_AGP)
+	struct nouveau_drm *drm = nouveau_bdev(bdev);
+	if (drm->agp.bridge) {
+		ttm_agp_destroy(bdev, ttm);
+		return;
+	}
+#endif
+	nouveau_sgdma_destroy(bdev, ttm);
+}
+
 void
 nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence, bool exclusive)
 {
@@ -1311,6 +1353,9 @@ struct ttm_bo_driver nouveau_bo_driver = {
 	.ttm_tt_create = &nouveau_ttm_tt_create,
 	.ttm_tt_populate = &nouveau_ttm_tt_populate,
 	.ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate,
+	.ttm_tt_bind = &nouveau_ttm_tt_bind,
+	.ttm_tt_unbind = &nouveau_ttm_tt_unbind,
+	.ttm_tt_destroy = &nouveau_ttm_tt_destroy,
 	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = nouveau_bo_evict_flags,
 	.move_notify = nouveau_bo_move_ntfy,
diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
index 6000c650b105..05e542254e1f 100644
--- a/drivers/gpu/drm/nouveau/nouveau_sgdma.c
+++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c
@@ -14,7 +14,7 @@ struct nouveau_sgdma_be {
 	struct nouveau_mem *mem;
 };
 
-static void
+void
 nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
@@ -25,10 +25,11 @@ nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 	}
 }
 
-static int
-nv04_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
+int
+nouveau_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
+	struct nouveau_drm *drm = nouveau_bdev(bdev);
 	struct nouveau_mem *mem = nouveau_mem(reg);
 	int ret;
 
@@ -36,65 +37,34 @@ nv04_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resou
 	if (ret)
 		return ret;
 
-	ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
-	if (ret) {
-		nouveau_mem_fini(mem);
-		return ret;
+	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA) {
+		ret = nouveau_mem_map(mem, &mem->cli->vmm.vmm, &mem->vma[0]);
+		if (ret) {
+			nouveau_mem_fini(mem);
+			return ret;
+		}
 	}
 
 	nvbe->mem = mem;
 	return 0;
 }
 
-static void
-nv04_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
+void
+nouveau_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
 	nouveau_mem_fini(nvbe->mem);
 }
 
-static struct ttm_backend_func nv04_sgdma_backend = {
-	.bind			= nv04_sgdma_bind,
-	.unbind			= nv04_sgdma_unbind,
-	.destroy		= nouveau_sgdma_destroy
-};
-
-static int
-nv50_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg)
-{
-	struct nouveau_sgdma_be *nvbe = (struct nouveau_sgdma_be *)ttm;
-	struct nouveau_mem *mem = nouveau_mem(reg);
-	int ret;
-
-	ret = nouveau_mem_host(reg, &nvbe->ttm);
-	if (ret)
-		return ret;
-
-	nvbe->mem = mem;
-	return 0;
-}
-
-static struct ttm_backend_func nv50_sgdma_backend = {
-	.bind			= nv50_sgdma_bind,
-	.unbind			= nv04_sgdma_unbind,
-	.destroy		= nouveau_sgdma_destroy
-};
-
 struct ttm_tt *
 nouveau_sgdma_create_ttm(struct ttm_buffer_object *bo, uint32_t page_flags)
 {
-	struct nouveau_drm *drm = nouveau_bdev(bo->bdev);
 	struct nouveau_sgdma_be *nvbe;
 
 	nvbe = kzalloc(sizeof(*nvbe), GFP_KERNEL);
 	if (!nvbe)
 		return NULL;
 
-	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA)
-		nvbe->ttm.ttm.func = &nv04_sgdma_backend;
-	else
-		nvbe->ttm.ttm.func = &nv50_sgdma_backend;
-
 	if (ttm_dma_tt_init(&nvbe->ttm, bo, page_flags)) {
 		kfree(nvbe);
 		return NULL;
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.h b/drivers/gpu/drm/nouveau/nouveau_ttm.h
index eaf25461cd91..69552049bb96 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.h
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.h
@@ -22,4 +22,7 @@ int  nouveau_ttm_mmap(struct file *, struct vm_area_struct *);
 int  nouveau_ttm_global_init(struct nouveau_drm *);
 void nouveau_ttm_global_release(struct nouveau_drm *);
 
+int nouveau_sgdma_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *reg);
+void nouveau_sgdma_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
+void nouveau_sgdma_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 #endif
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 09/23] drm/vmwgfx: move to driver binding functions
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (7 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 08/23] drm/nouveau/ttm: use driver bind/unbind/destroy functions Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 10/23] drm/amdgpu/ttm: move to driver backend binding funcs Dave Airlie
                   ` (14 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index a76a7f542dd8..6757be98be14 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -668,12 +668,6 @@ static void vmw_ttm_unpopulate(struct ttm_bo_device *bdev,
 		ttm_pool_unpopulate(ttm);
 }
 
-static struct ttm_backend_func vmw_ttm_func = {
-	.bind = vmw_ttm_bind,
-	.unbind = vmw_ttm_unbind,
-	.destroy = vmw_ttm_destroy,
-};
-
 static struct ttm_tt *vmw_ttm_tt_create(struct ttm_buffer_object *bo,
 					uint32_t page_flags)
 {
@@ -684,7 +678,6 @@ static struct ttm_tt *vmw_ttm_tt_create(struct ttm_buffer_object *bo,
 	if (!vmw_be)
 		return NULL;
 
-	vmw_be->dma_ttm.ttm.func = &vmw_ttm_func;
 	vmw_be->dev_priv = container_of(bo->bdev, struct vmw_private, bdev);
 	vmw_be->mob = NULL;
 
@@ -770,6 +763,9 @@ struct ttm_bo_driver vmw_bo_driver = {
 	.ttm_tt_create = &vmw_ttm_tt_create,
 	.ttm_tt_populate = &vmw_ttm_populate,
 	.ttm_tt_unpopulate = &vmw_ttm_unpopulate,
+	.ttm_tt_bind = &vmw_ttm_bind,
+	.ttm_tt_unbind = &vmw_ttm_unbind,
+	.ttm_tt_destroy = &vmw_ttm_destroy,
 	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = vmw_evict_flags,
 	.move = NULL,
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 10/23] drm/amdgpu/ttm: move to driver backend binding funcs
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (8 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 09/23] drm/vmwgfx: move to driver binding functions Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 11/23] drm/gem_vram/ttm: move to driver backend destroy function Dave Airlie
                   ` (13 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 9592505563bf..f07e7121bcc5 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1255,12 +1255,6 @@ static void amdgpu_ttm_backend_destroy(struct ttm_bo_device *bdev,
 	kfree(gtt);
 }
 
-static struct ttm_backend_func amdgpu_backend_func = {
-	.bind = &amdgpu_ttm_backend_bind,
-	.unbind = &amdgpu_ttm_backend_unbind,
-	.destroy = &amdgpu_ttm_backend_destroy,
-};
-
 /**
  * amdgpu_ttm_tt_create - Create a ttm_tt object for a given BO
  *
@@ -1277,7 +1271,6 @@ static struct ttm_tt *amdgpu_ttm_tt_create(struct ttm_buffer_object *bo,
 	if (gtt == NULL) {
 		return NULL;
 	}
-	gtt->ttm.ttm.func = &amdgpu_backend_func;
 	gtt->gobj = &bo->base;
 
 	/* allocate space for the uninitialized page entries */
@@ -1679,6 +1672,9 @@ static struct ttm_bo_driver amdgpu_bo_driver = {
 	.ttm_tt_create = &amdgpu_ttm_tt_create,
 	.ttm_tt_populate = &amdgpu_ttm_tt_populate,
 	.ttm_tt_unpopulate = &amdgpu_ttm_tt_unpopulate,
+	.ttm_tt_bind = &amdgpu_ttm_backend_bind,
+	.ttm_tt_unbind = &amdgpu_ttm_backend_unbind,
+	.ttm_tt_destroy = &amdgpu_ttm_backend_destroy,
 	.eviction_valuable = amdgpu_ttm_bo_eviction_valuable,
 	.evict_flags = &amdgpu_evict_flags,
 	.move = &amdgpu_bo_move,
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 11/23] drm/gem_vram/ttm: move to driver backend destroy function.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (9 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 10/23] drm/amdgpu/ttm: move to driver backend binding funcs Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  5:14   ` Thomas Zimmermann
  2020-08-26  1:44 ` [PATCH 12/23] drm/ttm/agp: drop back end bindings from agp Dave Airlie
                   ` (12 subsequent siblings)
  23 siblings, 1 reply; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/drm_gem_vram_helper.c | 7 +------
 1 file changed, 1 insertion(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 788557bc5c01..93586a310971 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -973,10 +973,6 @@ static void backend_func_destroy(struct ttm_bo_device *bdev, struct ttm_tt *tt)
 	kfree(tt);
 }
 
-static struct ttm_backend_func backend_func = {
-	.destroy = backend_func_destroy
-};
-
 /*
  * TTM BO device
  */
@@ -991,8 +987,6 @@ static struct ttm_tt *bo_driver_ttm_tt_create(struct ttm_buffer_object *bo,
 	if (!tt)
 		return NULL;
 
-	tt->func = &backend_func;
-
 	ret = ttm_tt_init(tt, bo, page_flags);
 	if (ret < 0)
 		goto err_ttm_tt_init;
@@ -1055,6 +1049,7 @@ static int bo_driver_io_mem_reserve(struct ttm_bo_device *bdev,
 
 static struct ttm_bo_driver bo_driver = {
 	.ttm_tt_create = bo_driver_ttm_tt_create,
+	.ttm_tt_destroy = backend_func_destroy,
 	.eviction_valuable = ttm_bo_eviction_valuable,
 	.evict_flags = bo_driver_evict_flags,
 	.move_notify = bo_driver_move_notify,
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 12/23] drm/ttm/agp: drop back end bindings from agp
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (10 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 11/23] drm/gem_vram/ttm: move to driver backend destroy function Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 13/23] drm/ttm: get rid of agp specific populate/unpopulate paths Dave Airlie
                   ` (11 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

These aren't used anymore.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_agp_backend.c | 7 -------
 1 file changed, 7 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index fbf98cd1a3e5..8072fb7c5bc8 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -112,12 +112,6 @@ void ttm_agp_destroy(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_agp_destroy);
 
-static struct ttm_backend_func ttm_agp_func = {
-	.bind = ttm_agp_bind,
-	.unbind = ttm_agp_unbind,
-	.destroy = ttm_agp_destroy,
-};
-
 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 				 struct agp_bridge_data *bridge,
 				 uint32_t page_flags)
@@ -130,7 +124,6 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 
 	agp_be->mem = NULL;
 	agp_be->bridge = bridge;
-	agp_be->ttm.func = &ttm_agp_func;
 
 	if (ttm_tt_init(&agp_be->ttm, bo, page_flags)) {
 		kfree(agp_be);
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 13/23] drm/ttm: get rid of agp specific populate/unpopulate paths.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (11 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 12/23] drm/ttm/agp: drop back end bindings from agp Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 14/23] drm/ttm/agp: remove bdev from agp helpers Dave Airlie
                   ` (10 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c  |  4 ++--
 drivers/gpu/drm/radeon/radeon_ttm.c   |  4 ++--
 drivers/gpu/drm/ttm/ttm_agp_backend.c | 17 -----------------
 include/drm/ttm/ttm_tt.h              |  2 --
 4 files changed, 4 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index f16401feb965..08499e1a56c2 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1280,7 +1280,7 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (drm->agp.bridge) {
-		return ttm_agp_tt_populate(bdev, ttm, ctx);
+		return ttm_pool_populate(ttm, ctx);
 	}
 #endif
 
@@ -1309,7 +1309,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev,
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (drm->agp.bridge) {
-		ttm_agp_tt_unpopulate(bdev, ttm);
+		ttm_pool_unpopulate(ttm);
 		return;
 	}
 #endif
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index af5479ea154c..eacfc591bf79 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -628,7 +628,7 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
-		return ttm_agp_tt_populate(bdev, ttm, ctx);
+		return ttm_pool_populate(ttm, ctx);
 	}
 #endif
 
@@ -658,7 +658,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
-		ttm_agp_tt_unpopulate(bdev, ttm);
+		ttm_pool_unpopulate(ttm);
 		return;
 	}
 #endif
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 8072fb7c5bc8..3d0a5e9f4c5f 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -133,20 +133,3 @@ struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 	return &agp_be->ttm;
 }
 EXPORT_SYMBOL(ttm_agp_tt_create);
-
-int ttm_agp_tt_populate(struct ttm_bo_device *bdev,
-			struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
-{
-	if (ttm->state != tt_unpopulated)
-		return 0;
-
-	return ttm_pool_populate(ttm, ctx);
-}
-EXPORT_SYMBOL(ttm_agp_tt_populate);
-
-void ttm_agp_tt_unpopulate(struct ttm_bo_device *bdev,
-			   struct ttm_tt *ttm)
-{
-	ttm_pool_unpopulate(ttm);
-}
-EXPORT_SYMBOL(ttm_agp_tt_unpopulate);
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 5a34f1640865..591d4927d501 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -264,8 +264,6 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 				 struct agp_bridge_data *bridge,
 				 uint32_t page_flags);
-int ttm_agp_tt_populate(struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_operation_ctx *ctx);
-void ttm_agp_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 int ttm_agp_bind(struct ttm_bo_device *bdev,
 		 struct ttm_tt *ttm, struct ttm_resource *bo_mem);
 void ttm_agp_unbind(struct ttm_bo_device *bdev,
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 14/23] drm/ttm/agp: remove bdev from agp helpers
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (12 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 13/23] drm/ttm: get rid of agp specific populate/unpopulate paths Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 15/23] drm/ttm: drop the tt backend function paths Dave Airlie
                   ` (9 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Since the agp bind/unbind/destroy are now getting called from drivers
rather than via the func table, drop the bdev parameter.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c  |  6 +++---
 drivers/gpu/drm/radeon/radeon_ttm.c   |  6 +++---
 drivers/gpu/drm/ttm/ttm_agp_backend.c | 11 ++++-------
 include/drm/ttm/ttm_tt.h              |  9 +++------
 4 files changed, 13 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 08499e1a56c2..0a8c092e0f2e 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -676,7 +676,7 @@ nouveau_ttm_tt_bind(struct ttm_bo_device *bdev, struct ttm_tt *ttm,
 	struct nouveau_drm *drm = nouveau_bdev(bdev);
 
 	if (drm->agp.bridge) {
-		return ttm_agp_bind(bdev, ttm, reg);
+		return ttm_agp_bind(ttm, reg);
 	}
 #endif
 	return nouveau_sgdma_bind(bdev, ttm, reg);
@@ -689,7 +689,7 @@ nouveau_ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 	struct nouveau_drm *drm = nouveau_bdev(bdev);
 
 	if (drm->agp.bridge) {
-		ttm_agp_unbind(bdev, ttm);
+		ttm_agp_unbind(ttm);
 		return;
 	}
 #endif
@@ -1331,7 +1331,7 @@ nouveau_ttm_tt_destroy(struct ttm_bo_device *bdev,
 #if IS_ENABLED(CONFIG_AGP)
 	struct nouveau_drm *drm = nouveau_bdev(bdev);
 	if (drm->agp.bridge) {
-		ttm_agp_destroy(bdev, ttm);
+		ttm_agp_destroy(ttm);
 		return;
 	}
 #endif
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index eacfc591bf79..6b7af313389d 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -696,7 +696,7 @@ static int radeon_ttm_tt_bind(struct ttm_bo_device *bdev,
 
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
-		return ttm_agp_bind(bdev, ttm, bo_mem);
+		return ttm_agp_bind(ttm, bo_mem);
 	}
 #endif
 
@@ -710,7 +710,7 @@ static void radeon_ttm_tt_unbind(struct ttm_bo_device *bdev,
 	struct radeon_device *rdev = radeon_get_rdev(bdev);
 
 	if (rdev->flags & RADEON_IS_AGP) {
-		ttm_agp_unbind(bdev, ttm);
+		ttm_agp_unbind(ttm);
 		return;
 	}
 #endif
@@ -724,7 +724,7 @@ static void radeon_ttm_tt_destroy(struct ttm_bo_device *bdev,
 	struct radeon_device *rdev = radeon_get_rdev(bdev);
 
 	if (rdev->flags & RADEON_IS_AGP) {
-		ttm_agp_destroy(bdev, ttm);
+		ttm_agp_destroy(ttm);
 		return;
 	}
 #endif
diff --git a/drivers/gpu/drm/ttm/ttm_agp_backend.c b/drivers/gpu/drm/ttm/ttm_agp_backend.c
index 3d0a5e9f4c5f..7b36fdaab766 100644
--- a/drivers/gpu/drm/ttm/ttm_agp_backend.c
+++ b/drivers/gpu/drm/ttm/ttm_agp_backend.c
@@ -48,8 +48,7 @@ struct ttm_agp_backend {
 	struct agp_bridge_data *bridge;
 };
 
-int ttm_agp_bind(struct ttm_bo_device *bdev,
-		 struct ttm_tt *ttm, struct ttm_resource *bo_mem)
+int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 	struct page *dummy_read_page = ttm_bo_glob.dummy_read_page;
@@ -84,8 +83,7 @@ int ttm_agp_bind(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_agp_bind);
 
-void ttm_agp_unbind(struct ttm_bo_device *bdev,
-		    struct ttm_tt *ttm)
+void ttm_agp_unbind(struct ttm_tt *ttm)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 
@@ -100,13 +98,12 @@ void ttm_agp_unbind(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_agp_unbind);
 
-void ttm_agp_destroy(struct ttm_bo_device *bdev,
-		     struct ttm_tt *ttm)
+void ttm_agp_destroy(struct ttm_tt *ttm)
 {
 	struct ttm_agp_backend *agp_be = container_of(ttm, struct ttm_agp_backend, ttm);
 
 	if (agp_be->mem)
-		ttm_agp_unbind(bdev, ttm);
+		ttm_agp_unbind(ttm);
 	ttm_tt_fini(ttm);
 	kfree(agp_be);
 }
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 591d4927d501..bdc8aadf3246 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -264,12 +264,9 @@ void ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 struct ttm_tt *ttm_agp_tt_create(struct ttm_buffer_object *bo,
 				 struct agp_bridge_data *bridge,
 				 uint32_t page_flags);
-int ttm_agp_bind(struct ttm_bo_device *bdev,
-		 struct ttm_tt *ttm, struct ttm_resource *bo_mem);
-void ttm_agp_unbind(struct ttm_bo_device *bdev,
-		    struct ttm_tt *ttm);
-void ttm_agp_destroy(struct ttm_bo_device *bdev,
-		     struct ttm_tt *ttm);
+int ttm_agp_bind(struct ttm_tt *ttm, struct ttm_resource *bo_mem);
+void ttm_agp_unbind(struct ttm_tt *ttm);
+void ttm_agp_destroy(struct ttm_tt *ttm);
 #endif
 
 #endif
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 15/23] drm/ttm: drop the tt backend function paths.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (13 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 14/23] drm/ttm/agp: remove bdev from agp helpers Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 16/23] drm/ttm: move sg pointer into ttm_dma_tt Dave Airlie
                   ` (8 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

These are now driver side.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_tt.c | 15 +++-----------
 include/drm/ttm/ttm_tt.h     | 39 ------------------------------------
 2 files changed, 3 insertions(+), 51 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 73c97dcfa512..67aa7fe39432 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -222,10 +222,7 @@ void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 		fput(ttm->swap_storage);
 
 	ttm->swap_storage = NULL;
-	if (bdev->driver->ttm_tt_destroy)
-		bdev->driver->ttm_tt_destroy(bdev, ttm);
-	else
-		ttm->func->destroy(bdev, ttm);
+	bdev->driver->ttm_tt_destroy(bdev, ttm);
 }
 
 static void ttm_tt_init_fields(struct ttm_tt *ttm,
@@ -313,10 +310,7 @@ EXPORT_SYMBOL(ttm_dma_tt_fini);
 void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
 	if (ttm->state == tt_bound) {
-		if (bdev->driver->ttm_tt_unbind)
-			bdev->driver->ttm_tt_unbind(bdev, ttm);
-		else
-			ttm->func->unbind(bdev, ttm);
+		bdev->driver->ttm_tt_unbind(bdev, ttm);
 		ttm->state = tt_unbound;
 	}
 }
@@ -337,10 +331,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	if (ret)
 		return ret;
 
-	if (bdev->driver->ttm_tt_bind)
-		ret = bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
-	else
-		ret = ttm->func->bind(bdev, ttm, bo_mem);
+	ret = bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
 	if (unlikely(ret != 0))
 		return ret;
 
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index bdc8aadf3246..146544ba1c10 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -48,47 +48,9 @@ enum ttm_caching_state {
 	tt_cached
 };
 
-struct ttm_backend_func {
-	/**
-	 * struct ttm_backend_func member bind
-	 *
-	 * @ttm: Pointer to a struct ttm_tt.
-	 * @bo_mem: Pointer to a struct ttm_resource describing the
-	 * memory type and location for binding.
-	 *
-	 * Bind the backend pages into the aperture in the location
-	 * indicated by @bo_mem. This function should be able to handle
-	 * differences between aperture and system page sizes.
-	 */
-	int (*bind) (struct ttm_bo_device *bdev, struct ttm_tt *ttm, struct ttm_resource *bo_mem);
-
-	/**
-	 * struct ttm_backend_func member unbind
-	 *
-	 * @ttm: Pointer to a struct ttm_tt.
-	 *
-	 * Unbind previously bound backend pages. This function should be
-	 * able to handle differences between aperture and system page sizes.
-	 */
-	void (*unbind) (struct ttm_bo_device *bdev, struct ttm_tt *ttm);
-
-	/**
-	 * struct ttm_backend_func member destroy
-	 *
-	 * @ttm: Pointer to a struct ttm_tt.
-	 *
-	 * Destroy the backend. This will be call back from ttm_tt_destroy so
-	 * don't call ttm_tt_destroy from the callback or infinite loop.
-	 */
-	void (*destroy) (struct ttm_bo_device *bdev, struct ttm_tt *ttm);
-};
-
 /**
  * struct ttm_tt
  *
- * @func: Pointer to a struct ttm_backend_func that describes
- * the backend methods.
- * pointer.
  * @pages: Array of pages backing the data.
  * @num_pages: Number of pages in the page array.
  * @bdev: Pointer to the current struct ttm_bo_device.
@@ -102,7 +64,6 @@ struct ttm_backend_func {
  * memory.
  */
 struct ttm_tt {
-	struct ttm_backend_func *func;
 	struct page **pages;
 	uint32_t page_flags;
 	unsigned long num_pages;
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 16/23] drm/ttm: move sg pointer into ttm_dma_tt
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (14 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 15/23] drm/ttm: drop the tt backend function paths Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 17/23] drm/ttm: split populated/bound state flags Dave Airlie
                   ` (7 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

This is only used by drivers that have a dma tt backing store.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 .../gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c  |  3 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c       | 32 +++++++++----------
 drivers/gpu/drm/nouveau/nouveau_bo.c          |  4 +--
 drivers/gpu/drm/nouveau/nouveau_mem.c         |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c           | 26 +++++++--------
 drivers/gpu/drm/ttm/ttm_tt.c                  |  4 ++-
 include/drm/ttm/ttm_tt.h                      |  2 +-
 7 files changed, 38 insertions(+), 35 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
index aa2b328c6202..b2faa02c0263 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd_gpuvm.c
@@ -1231,8 +1231,9 @@ int amdgpu_amdkfd_gpuvm_alloc_memory_of_gpu(
 		goto err_bo_create;
 	}
 	if (bo_type == ttm_bo_type_sg) {
+		struct ttm_dma_tt *dma_ttm = (struct ttm_dma_tt *)bo->tbo.ttm;
 		bo->tbo.sg = sg;
-		bo->tbo.ttm->sg = sg;
+		dma_ttm->sg = sg;
 	}
 	bo->kfd_bo = *mem;
 	(*mem)->bo = bo;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index f07e7121bcc5..adac24625191 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -985,25 +985,25 @@ static int amdgpu_ttm_tt_pin_userptr(struct ttm_bo_device *bdev,
 		DMA_BIDIRECTIONAL : DMA_TO_DEVICE;
 
 	/* Allocate an SG array and squash pages into it */
-	r = sg_alloc_table_from_pages(ttm->sg, ttm->pages, ttm->num_pages, 0,
+	r = sg_alloc_table_from_pages(gtt->ttm.sg, ttm->pages, ttm->num_pages, 0,
 				      ttm->num_pages << PAGE_SHIFT,
 				      GFP_KERNEL);
 	if (r)
 		goto release_sg;
 
 	/* Map SG to device */
-	r = dma_map_sgtable(adev->dev, ttm->sg, direction, 0);
+	r = dma_map_sgtable(adev->dev, gtt->ttm.sg, direction, 0);
 	if (r)
 		goto release_sg;
 
 	/* convert SG to linear array of pages and dma addresses */
-	drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages,
+	drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 					 gtt->ttm.dma_address, ttm->num_pages);
 
 	return 0;
 
 release_sg:
-	kfree(ttm->sg);
+	kfree(gtt->ttm.sg);
 	return r;
 }
 
@@ -1021,12 +1021,12 @@ static void amdgpu_ttm_tt_unpin_userptr(struct ttm_bo_device *bdev,
 		DMA_BIDIRECTIONAL : DMA_TO_DEVICE;
 
 	/* double check that we don't free the table twice */
-	if (!ttm->sg->sgl)
+	if (!gtt->ttm.sg->sgl)
 		return;
 
 	/* unmap the pages mapped to the device */
-	dma_unmap_sgtable(adev->dev, ttm->sg, direction, 0);
-	sg_free_table(ttm->sg);
+	dma_unmap_sgtable(adev->dev, gtt->ttm.sg, direction, 0);
+	sg_free_table(gtt->ttm.sg);
 
 #if IS_ENABLED(CONFIG_DRM_AMDGPU_USERPTR)
 	if (gtt->range) {
@@ -1296,8 +1296,8 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 
 	/* user pages are bound by amdgpu_ttm_tt_pin_userptr() */
 	if (gtt && gtt->userptr) {
-		ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
-		if (!ttm->sg)
+		gtt->ttm.sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
+		if (!gtt->ttm.sg)
 			return -ENOMEM;
 
 		ttm->page_flags |= TTM_PAGE_FLAG_SG;
@@ -1306,7 +1306,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 	}
 
 	if (ttm->page_flags & TTM_PAGE_FLAG_SG) {
-		if (!ttm->sg) {
+		if (!gtt->ttm.sg) {
 			struct dma_buf_attachment *attach;
 			struct sg_table *sgt;
 
@@ -1315,10 +1315,10 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 			if (IS_ERR(sgt))
 				return PTR_ERR(sgt);
 
-			ttm->sg = sgt;
+			gtt->ttm.sg = sgt;
 		}
 
-		drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages,
+		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 						 gtt->ttm.dma_address,
 						 ttm->num_pages);
 		ttm->state = tt_unbound;
@@ -1349,17 +1349,17 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 
 	if (gtt && gtt->userptr) {
 		amdgpu_ttm_tt_set_user_pages(ttm, NULL);
-		kfree(ttm->sg);
+		kfree(gtt->ttm.sg);
 		ttm->page_flags &= ~TTM_PAGE_FLAG_SG;
 		return;
 	}
 
-	if (ttm->sg && gtt->gobj->import_attach) {
+	if (gtt->ttm.sg && gtt->gobj->import_attach) {
 		struct dma_buf_attachment *attach;
 
 		attach = gtt->gobj->import_attach;
-		dma_buf_unmap_attachment(attach, ttm->sg, DMA_BIDIRECTIONAL);
-		ttm->sg = NULL;
+		dma_buf_unmap_attachment(attach, gtt->ttm.sg, DMA_BIDIRECTIONAL);
+		gtt->ttm.sg = NULL;
 		return;
 	}
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 0a8c092e0f2e..478e498da965 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1267,9 +1267,9 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
 	if (ttm->state != tt_unpopulated)
 		return 0;
 
-	if (slave && ttm->sg) {
+	if (slave && ttm_dma->sg) {
 		/* make userspace faulting work */
-		drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages,
+		drm_prime_sg_to_page_addr_arrays(ttm_dma->sg, ttm->pages,
 						 ttm_dma->dma_address, ttm->num_pages);
 		ttm->state = tt_unbound;
 		return 0;
diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c
index 269d8707acc3..b98eed6039b1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_mem.c
+++ b/drivers/gpu/drm/nouveau/nouveau_mem.c
@@ -116,7 +116,7 @@ nouveau_mem_host(struct ttm_resource *reg, struct ttm_dma_tt *tt)
 		mem->comp = 0;
 	}
 
-	if (tt->ttm.sg) args.sgl = tt->ttm.sg->sgl;
+	if (tt->sg) args.sgl = tt->sg->sgl;
 	else            args.dma = tt->dma_address;
 
 	mutex_lock(&drm->master.lock);
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 6b7af313389d..f5cbe5d13d33 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -459,23 +459,23 @@ static int radeon_ttm_tt_pin_userptr(struct ttm_bo_device *bdev, struct ttm_tt *
 
 	} while (pinned < ttm->num_pages);
 
-	r = sg_alloc_table_from_pages(ttm->sg, ttm->pages, ttm->num_pages, 0,
+	r = sg_alloc_table_from_pages(gtt->ttm.sg, ttm->pages, ttm->num_pages, 0,
 				      ttm->num_pages << PAGE_SHIFT,
 				      GFP_KERNEL);
 	if (r)
 		goto release_sg;
 
-	r = dma_map_sgtable(rdev->dev, ttm->sg, direction, 0);
+	r = dma_map_sgtable(rdev->dev, gtt->ttm.sg, direction, 0);
 	if (r)
 		goto release_sg;
 
-	drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages,
+	drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 					 gtt->ttm.dma_address, ttm->num_pages);
 
 	return 0;
 
 release_sg:
-	kfree(ttm->sg);
+	kfree(gtt->ttm.sg);
 
 release_pages:
 	release_pages(ttm->pages, pinned);
@@ -493,13 +493,13 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_bo_device *bdev, struct ttm_t
 		DMA_BIDIRECTIONAL : DMA_TO_DEVICE;
 
 	/* double check that we don't free the table twice */
-	if (!ttm->sg->sgl)
+	if (!gtt->ttm.sg->sgl)
 		return;
 
 	/* free the sg table and pages again */
-	dma_unmap_sgtable(rdev->dev, ttm->sg, direction, 0);
+	dma_unmap_sgtable(rdev->dev, gtt->ttm.sg, direction, 0);
 
-	for_each_sgtable_page(ttm->sg, &sg_iter, 0) {
+	for_each_sgtable_page(gtt->ttm.sg, &sg_iter, 0) {
 		struct page *page = sg_page_iter_page(&sg_iter);
 		if (!(gtt->userflags & RADEON_GEM_USERPTR_READONLY))
 			set_page_dirty(page);
@@ -508,7 +508,7 @@ static void radeon_ttm_tt_unpin_userptr(struct ttm_bo_device *bdev, struct ttm_t
 		put_page(page);
 	}
 
-	sg_free_table(ttm->sg);
+	sg_free_table(gtt->ttm.sg);
 }
 
 static int radeon_ttm_backend_bind(struct ttm_bo_device *bdev,
@@ -610,8 +610,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (gtt && gtt->userptr) {
-		ttm->sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
-		if (!ttm->sg)
+		gtt->ttm.sg = kzalloc(sizeof(struct sg_table), GFP_KERNEL);
+		if (!gtt->ttm.sg)
 			return -ENOMEM;
 
 		ttm->page_flags |= TTM_PAGE_FLAG_SG;
@@ -619,8 +619,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 		return 0;
 	}
 
-	if (slave && ttm->sg) {
-		drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages,
+	if (slave && gtt->ttm.sg) {
+		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 						 gtt->ttm.dma_address, ttm->num_pages);
 		ttm->state = tt_unbound;
 		return 0;
@@ -648,7 +648,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
 	if (gtt && gtt->userptr) {
-		kfree(ttm->sg);
+		kfree(gtt->ttm.sg);
 		ttm->page_flags &= ~TTM_PAGE_FLAG_SG;
 		return;
 	}
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 67aa7fe39432..1b9960085d11 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -234,7 +234,6 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
 	ttm->page_flags = page_flags;
 	ttm->state = tt_unpopulated;
 	ttm->swap_storage = NULL;
-	ttm->sg = bo->sg;
 }
 
 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
@@ -263,6 +262,7 @@ int ttm_dma_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
 	struct ttm_tt *ttm = &ttm_dma->ttm;
 
 	ttm_tt_init_fields(ttm, bo, page_flags);
+	ttm_dma->sg = bo->sg;
 
 	INIT_LIST_HEAD(&ttm_dma->pages_list);
 	if (ttm_dma_tt_alloc_page_directory(ttm_dma)) {
@@ -282,6 +282,8 @@ int ttm_sg_tt_init(struct ttm_dma_tt *ttm_dma, struct ttm_buffer_object *bo,
 	ttm_tt_init_fields(ttm, bo, page_flags);
 
 	INIT_LIST_HEAD(&ttm_dma->pages_list);
+	ttm_dma->sg = bo->sg;
+
 	if (page_flags & TTM_PAGE_FLAG_SG)
 		ret = ttm_sg_tt_alloc_page_directory(ttm_dma);
 	else
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 146544ba1c10..534d0ef24072 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -67,7 +67,6 @@ struct ttm_tt {
 	struct page **pages;
 	uint32_t page_flags;
 	unsigned long num_pages;
-	struct sg_table *sg; /* for SG objects via dma-buf */
 	struct file *swap_storage;
 	enum ttm_caching_state caching_state;
 	enum {
@@ -90,6 +89,7 @@ struct ttm_tt {
  */
 struct ttm_dma_tt {
 	struct ttm_tt ttm;
+	struct sg_table *sg; /* for SG objects via dma-buf */
 	dma_addr_t *dma_address;
 	struct list_head pages_list;
 };
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 17/23] drm/ttm: split populated/bound state flags.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (15 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 16/23] drm/ttm: move sg pointer into ttm_dma_tt Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-27 11:52   ` Christian König
  2020-08-26  1:44 ` [PATCH 18/23] drm/ttm: move bound flag and use a utility wrapper Dave Airlie
                   ` (6 subsequent siblings)
  23 siblings, 1 reply; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Get bound out is the next step.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_bo.c       |  4 ++--
 drivers/gpu/drm/radeon/radeon_mn.c         |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c        |  4 ++--
 drivers/gpu/drm/ttm/ttm_bo_util.c          |  2 +-
 drivers/gpu/drm/ttm/ttm_page_alloc.c       |  6 +++---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c   |  6 +++---
 drivers/gpu/drm/ttm/ttm_tt.c               | 19 +++++++++----------
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c       |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  2 +-
 include/drm/ttm/ttm_tt.h                   | 10 ++++------
 11 files changed, 30 insertions(+), 33 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index adac24625191..c1c3691c3b9f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1301,7 +1301,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 			return -ENOMEM;
 
 		ttm->page_flags |= TTM_PAGE_FLAG_SG;
-		ttm->state = tt_unbound;
+		ttm->populated = true;
 		return 0;
 	}
 
@@ -1321,7 +1321,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 						 gtt->ttm.dma_address,
 						 ttm->num_pages);
-		ttm->state = tt_unbound;
+		ttm->populated = true;
 		return 0;
 	}
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 478e498da965..e9de922ae921 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1264,14 +1264,14 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
 	struct device *dev;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
-	if (ttm->state != tt_unpopulated)
+	if (ttm->populated)
 		return 0;
 
 	if (slave && ttm_dma->sg) {
 		/* make userspace faulting work */
 		drm_prime_sg_to_page_addr_arrays(ttm_dma->sg, ttm->pages,
 						 ttm_dma->dma_address, ttm->num_pages);
-		ttm->state = tt_unbound;
+		ttm->populated = true;
 		return 0;
 	}
 
diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index f93829f08a4d..5f57df7e6f08 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -53,7 +53,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,
 	struct ttm_operation_ctx ctx = { false, false };
 	long r;
 
-	if (!bo->tbo.ttm || bo->tbo.ttm->state != tt_bound)
+	if (!bo->tbo.ttm || bo->tbo.ttm->bound == false)
 		return true;
 
 	if (!mmu_notifier_range_blockable(range))
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index f5cbe5d13d33..f9e4e64a6d64 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -615,14 +615,14 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 			return -ENOMEM;
 
 		ttm->page_flags |= TTM_PAGE_FLAG_SG;
-		ttm->state = tt_unbound;
+		ttm->populated = true;
 		return 0;
 	}
 
 	if (slave && gtt->ttm.sg) {
 		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 						 gtt->ttm.dma_address, ttm->num_pages);
-		ttm->state = tt_unbound;
+		ttm->populated = true;
 		return 0;
 	}
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 3b17fe3cb57a..d5d841270e38 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -251,7 +251,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 	 * Don't move nonexistent data. Clear destination instead.
 	 */
 	if (old_iomap == NULL &&
-	    (ttm == NULL || (ttm->state == tt_unpopulated &&
+	    (ttm == NULL || (!ttm->populated &&
 			     !(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)))) {
 		memset_io(new_iomap, 0, new_mem->num_pages*PAGE_SIZE);
 		goto out2;
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index b40a4678c296..2d30a2deadb5 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1044,7 +1044,7 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
 put_pages:
 	ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
 		      ttm->caching_state);
-	ttm->state = tt_unpopulated;
+	ttm->populated = false;
 }
 
 int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
@@ -1053,7 +1053,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 	unsigned i;
 	int ret;
 
-	if (ttm->state != tt_unpopulated)
+	if (ttm->populated)
 		return 0;
 
 	if (ttm_check_under_lowerlimit(mem_glob, ttm->num_pages, ctx))
@@ -1083,7 +1083,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 		}
 	}
 
-	ttm->state = tt_unbound;
+	ttm->populated = true;
 	return 0;
 }
 EXPORT_SYMBOL(ttm_pool_populate);
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index faefaaef7909..9a3b7145d9cb 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -894,7 +894,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 	unsigned i;
 	int ret;
 
-	if (ttm->state != tt_unpopulated)
+	if (ttm->populated)
 		return 0;
 
 	if (ttm_check_under_lowerlimit(mem_glob, num_pages, ctx))
@@ -982,7 +982,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 		}
 	}
 
-	ttm->state = tt_unbound;
+	ttm->populated = true;
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ttm_dma_populate);
@@ -1076,7 +1076,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
 	/* shrink pool if necessary (only on !is_cached pools)*/
 	if (npages)
 		ttm_dma_page_pool_free(pool, npages, false);
-	ttm->state = tt_unpopulated;
+	ttm->populated = false;
 }
 EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
 
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 1b9960085d11..ee6fda175da6 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -156,7 +156,7 @@ static int ttm_tt_set_caching(struct ttm_tt *ttm,
 	if (ttm->caching_state == c_state)
 		return 0;
 
-	if (ttm->state == tt_unpopulated) {
+	if (!ttm->populated) {
 		/* Change caching but don't populate */
 		ttm->caching_state = c_state;
 		return 0;
@@ -214,7 +214,7 @@ void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 
 	ttm_tt_unbind(bdev, ttm);
 
-	if (ttm->state == tt_unbound)
+	if (ttm->populated)
 		ttm_tt_unpopulate(bdev, ttm);
 
 	if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
@@ -232,8 +232,8 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
 	ttm->num_pages = bo->num_pages;
 	ttm->caching_state = tt_cached;
 	ttm->page_flags = page_flags;
-	ttm->state = tt_unpopulated;
 	ttm->swap_storage = NULL;
+	ttm->populated = false;
 }
 
 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
@@ -311,9 +311,9 @@ EXPORT_SYMBOL(ttm_dma_tt_fini);
 
 void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-	if (ttm->state == tt_bound) {
+	if (ttm->bound) {
 		bdev->driver->ttm_tt_unbind(bdev, ttm);
-		ttm->state = tt_unbound;
+		ttm->bound = false;
 	}
 }
 
@@ -326,7 +326,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	if (!ttm)
 		return -EINVAL;
 
-	if (ttm->state == tt_bound)
+	if (ttm->bound)
 		return 0;
 
 	ret = ttm_tt_populate(bdev, ttm, ctx);
@@ -337,7 +337,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	if (unlikely(ret != 0))
 		return ret;
 
-	ttm->state = tt_bound;
+	ttm->bound = true;
 
 	return 0;
 }
@@ -395,7 +395,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev,
 	int i;
 	int ret = -ENOMEM;
 
-	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
 	BUG_ON(ttm->caching_state != tt_cached);
 
 	if (!persistent_swap_storage) {
@@ -462,7 +461,7 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
 {
 	int ret;
 
-	if (ttm->state != tt_unpopulated)
+	if (ttm->populated)
 		return 0;
 
 	if (bdev->driver->ttm_tt_populate)
@@ -491,7 +490,7 @@ static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
 void ttm_tt_unpopulate(struct ttm_bo_device *bdev,
 		       struct ttm_tt *ttm)
 {
-	if (ttm->state == tt_unpopulated)
+	if (!ttm->populated)
 		return;
 
 	ttm_tt_clear_mapping(ttm);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index 0cd21590ded9..77205f92bc9b 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -464,13 +464,13 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
 	if (!(src->mem.placement & TTM_PL_FLAG_NO_EVICT))
 		dma_resv_assert_held(src->base.resv);
 
-	if (dst->ttm->state == tt_unpopulated) {
+	if (dst->ttm->populated == false) {
 		ret = dst->bdev->driver->ttm_tt_populate(dst->bdev, dst->ttm, &ctx);
 		if (ret)
 			return ret;
 	}
 
-	if (src->ttm->state == tt_unpopulated) {
+	if (src->ttm->populated == false) {
 		ret = src->bdev->driver->ttm_tt_populate(src->bdev, src->ttm, &ctx);
 		if (ret)
 			return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index 6757be98be14..1925c41d2bda 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -623,7 +623,7 @@ static int vmw_ttm_populate(struct ttm_bo_device *bdev,
 	struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
 	int ret;
 
-	if (ttm->state != tt_unpopulated)
+	if (ttm->populated)
 		return 0;
 
 	if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 534d0ef24072..c6e88f01062e 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -57,7 +57,8 @@ enum ttm_caching_state {
  * @be: Pointer to the ttm backend.
  * @swap_storage: Pointer to shmem struct file for swap storage.
  * @caching_state: The current caching state of the pages.
- * @state: The current binding state of the pages.
+ * @populated: if the backing store is populated
+ * @bound: if this object has been bound to a global table.
  *
  * This is a structure holding the pages, caching- and aperture binding
  * status for a buffer object that isn't backed by fixed (VRAM / AGP)
@@ -69,11 +70,8 @@ struct ttm_tt {
 	unsigned long num_pages;
 	struct file *swap_storage;
 	enum ttm_caching_state caching_state;
-	enum {
-		tt_bound,
-		tt_unbound,
-		tt_unpopulated,
-	} state;
+	bool populated;
+	bool bound;
 };
 
 /**
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 18/23] drm/ttm: move bound flag and use a utility wrapper
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (16 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 17/23] drm/ttm: split populated/bound state flags Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 19/23] drm/ttm: split bind and populate out Dave Airlie
                   ` (5 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

If we move the bound flag out then the tt destroy is much
cleaner in a bo level wrapper, the code is in a few places,
leave the ttm_tt_destroy just about destroying the backing store.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  1 +
 drivers/gpu/drm/nouveau/nouveau_bo.c    |  1 +
 drivers/gpu/drm/radeon/radeon_mn.c      |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c     |  1 +
 drivers/gpu/drm/ttm/ttm_bo.c            | 15 +++++++-------
 drivers/gpu/drm/ttm/ttm_bo_util.c       | 27 ++++++++++++++++++-------
 drivers/gpu/drm/ttm/ttm_tt.c            | 19 +----------------
 include/drm/ttm/ttm_bo_api.h            |  1 +
 include/drm/ttm/ttm_bo_driver.h         |  1 +
 include/drm/ttm/ttm_tt.h                |  4 +---
 10 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index c1c3691c3b9f..116407c77f02 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -551,6 +551,7 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
+	bo->ttm_bound = true;
 
 	/* blit VRAM to GTT */
 	r = amdgpu_move_blit(bo, evict, &tmp_mem, old_mem);
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index e9de922ae921..9ac4b37aed87 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -879,6 +879,7 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
 	ret = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_reg, &ctx);
 	if (ret)
 		goto out;
+	bo->ttm_bound = true;
 
 	ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_gpu, &tmp_reg);
 	if (ret)
diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
index 5f57df7e6f08..e1f0d6ab4c86 100644
--- a/drivers/gpu/drm/radeon/radeon_mn.c
+++ b/drivers/gpu/drm/radeon/radeon_mn.c
@@ -53,7 +53,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,
 	struct ttm_operation_ctx ctx = { false, false };
 	long r;
 
-	if (!bo->tbo.ttm || bo->tbo.ttm->bound == false)
+	if (!bo->tbo.ttm || bo->tbo.ttm_bound == false)
 		return true;
 
 	if (!mmu_notifier_range_blockable(range))
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index f9e4e64a6d64..71c2a78911cd 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -239,6 +239,7 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
+	bo->ttm_bound = true;
 	r = radeon_move_blit(bo, true, no_wait_gpu, &tmp_mem, old_mem);
 	if (unlikely(r)) {
 		goto out_cleanup;
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index fa9012c8d11a..bf27d185c23f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -282,9 +282,12 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 			goto out_err;
 
 		if (mem->mem_type != TTM_PL_SYSTEM) {
-			ret = ttm_tt_bind(bdev, bo->ttm, mem, ctx);
-			if (ret)
-				goto out_err;
+			if (bo->ttm_bound == false) {
+				ret = ttm_tt_bind(bdev, bo->ttm, mem, ctx);
+				if (ret)
+					goto out_err;
+				bo->ttm_bound = true;
+			}
 		}
 
 		if (bo->mem.mem_type == TTM_PL_SYSTEM) {
@@ -324,8 +327,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 out_err:
 	new_man = ttm_manager_type(bdev, bo->mem.mem_type);
 	if (!new_man->use_tt) {
-		ttm_tt_destroy(bdev, bo->ttm);
-		bo->ttm = NULL;
+		ttm_bo_tt_destroy(bo, bo->ttm);
 	}
 
 	return ret;
@@ -344,8 +346,7 @@ static void ttm_bo_cleanup_memtype_use(struct ttm_buffer_object *bo)
 	if (bo->bdev->driver->move_notify)
 		bo->bdev->driver->move_notify(bo, false, NULL);
 
-	ttm_tt_destroy(bo->bdev, bo->ttm);
-	bo->ttm = NULL;
+	ttm_bo_tt_destroy(bo, bo->ttm);
 	ttm_resource_free(bo, &bo->mem);
 }
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index d5d841270e38..8b50b250da0c 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -51,7 +51,7 @@ void ttm_bo_free_old_node(struct ttm_buffer_object *bo)
 }
 
 int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
-		   struct ttm_operation_ctx *ctx,
+		    struct ttm_operation_ctx *ctx,
 		    struct ttm_resource *new_mem)
 {
 	struct ttm_tt *ttm = bo->ttm;
@@ -68,6 +68,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 		}
 
 		ttm_tt_unbind(bo->bdev, ttm);
+		bo->ttm_bound = false;
 		ttm_bo_free_old_node(bo);
 		ttm_flag_masked(&old_mem->placement, TTM_PL_FLAG_SYSTEM,
 				TTM_PL_MASK_MEM);
@@ -82,6 +83,7 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 		ret = ttm_tt_bind(bo->bdev, ttm, new_mem, ctx);
 		if (unlikely(ret != 0))
 			return ret;
+		bo->ttm_bound = true;
 	}
 
 	*old_mem = *new_mem;
@@ -300,8 +302,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 	new_mem->mm_node = NULL;
 
 	if (!man->use_tt) {
-		ttm_tt_destroy(bdev, ttm);
-		bo->ttm = NULL;
+		ttm_bo_tt_destroy(bo, ttm);
 	}
 
 out1:
@@ -547,8 +548,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 			return ret;
 
 		if (!man->use_tt) {
-			ttm_tt_destroy(bdev, bo->ttm);
-			bo->ttm = NULL;
+			ttm_bo_tt_destroy(bo, bo->ttm);
 		}
 		ttm_bo_free_old_node(bo);
 	} else {
@@ -670,8 +670,7 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 			return ret;
 
 		if (!to->use_tt) {
-			ttm_tt_destroy(bdev, bo->ttm);
-			bo->ttm = NULL;
+			ttm_bo_tt_destroy(bo, bo->ttm);
 		}
 		ttm_bo_free_old_node(bo);
 	}
@@ -706,3 +705,17 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo)
 
 	return 0;
 }
+
+void ttm_bo_tt_destroy(struct ttm_buffer_object *bo, struct ttm_tt *ttm)
+{
+	if (ttm == NULL)
+		return;
+
+	if (bo->ttm_bound)
+		ttm_tt_unbind(bo->bdev, ttm);
+
+	ttm_tt_unpopulate(bo->bdev, ttm);
+	ttm_tt_destroy(bo->bdev, ttm);
+	bo->ttm_bound = false;
+	bo->ttm = NULL;
+}
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index ee6fda175da6..8d4f946cd9e0 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -209,14 +209,6 @@ EXPORT_SYMBOL(ttm_tt_set_placement_caching);
 
 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-	if (ttm == NULL)
-		return;
-
-	ttm_tt_unbind(bdev, ttm);
-
-	if (ttm->populated)
-		ttm_tt_unpopulate(bdev, ttm);
-
 	if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
 	    ttm->swap_storage)
 		fput(ttm->swap_storage);
@@ -311,10 +303,7 @@ EXPORT_SYMBOL(ttm_dma_tt_fini);
 
 void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 {
-	if (ttm->bound) {
-		bdev->driver->ttm_tt_unbind(bdev, ttm);
-		ttm->bound = false;
-	}
+	bdev->driver->ttm_tt_unbind(bdev, ttm);
 }
 
 int ttm_tt_bind(struct ttm_bo_device *bdev,
@@ -326,9 +315,6 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	if (!ttm)
 		return -EINVAL;
 
-	if (ttm->bound)
-		return 0;
-
 	ret = ttm_tt_populate(bdev, ttm, ctx);
 	if (ret)
 		return ret;
@@ -336,9 +322,6 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	ret = bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
 	if (unlikely(ret != 0))
 		return ret;
-
-	ttm->bound = true;
-
 	return 0;
 }
 EXPORT_SYMBOL(ttm_tt_bind);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 36ff64e2736c..1d20a7f15a7a 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -141,6 +141,7 @@ struct ttm_buffer_object {
 	struct ttm_resource mem;
 	struct file *persistent_swap_storage;
 	struct ttm_tt *ttm;
+	bool ttm_bound;
 	bool evicted;
 	bool deleted;
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 32c0651cc0fd..a1a903771922 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -732,4 +732,5 @@ int ttm_range_man_init(struct ttm_bo_device *bdev,
 int ttm_range_man_fini(struct ttm_bo_device *bdev,
 		       unsigned type);
 
+void ttm_bo_tt_destroy(struct ttm_buffer_object *bo, struct ttm_tt *tt);
 #endif
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index c6e88f01062e..5d10abb1419b 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -58,7 +58,6 @@ enum ttm_caching_state {
  * @swap_storage: Pointer to shmem struct file for swap storage.
  * @caching_state: The current caching state of the pages.
  * @populated: if the backing store is populated
- * @bound: if this object has been bound to a global table.
  *
  * This is a structure holding the pages, caching- and aperture binding
  * status for a buffer object that isn't backed by fixed (VRAM / AGP)
@@ -71,7 +70,6 @@ struct ttm_tt {
 	struct file *swap_storage;
 	enum ttm_caching_state caching_state;
 	bool populated;
-	bool bound;
 };
 
 /**
@@ -149,7 +147,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
  *
  * @ttm: The struct ttm_tt.
  *
- * Unbind, unpopulate and destroy common struct ttm_tt.
+ * Destroy common struct ttm_tt.
  */
 void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm);
 
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 19/23] drm/ttm: split bind and populate out.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (17 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 18/23] drm/ttm: move bound flag and use a utility wrapper Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 20/23] drm/ttm: add populated accessors Dave Airlie
                   ` (4 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Make populating the backing store an explicit separate step

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c |  7 ++++++-
 drivers/gpu/drm/nouveau/nouveau_bo.c    |  6 +++++-
 drivers/gpu/drm/radeon/radeon_ttm.c     |  7 ++++++-
 drivers/gpu/drm/ttm/ttm_bo.c            |  5 ++++-
 drivers/gpu/drm/ttm/ttm_bo_util.c       |  6 +++++-
 drivers/gpu/drm/ttm/ttm_tt.c            | 16 +++++-----------
 include/drm/ttm/ttm_tt.h                |  3 +--
 7 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 116407c77f02..e8a56e64bc38 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -546,8 +546,13 @@ static int amdgpu_move_vram_ram(struct ttm_buffer_object *bo, bool evict,
 		goto out_cleanup;
 	}
 
+	r = ttm_tt_populate(bo->bdev, bo->ttm, ctx);
+	if (unlikely(r)) {
+		goto out_cleanup;
+	}
+
 	/* Bind the memory to the GTT space */
-	r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem, ctx);
+	r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 9ac4b37aed87..f6b6ef7a8868 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -876,7 +876,11 @@ nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr,
 	if (ret)
 		return ret;
 
-	ret = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_reg, &ctx);
+	ret = ttm_tt_populate(bo->bdev, bo->ttm, &ctx);
+	if (ret)
+		goto out;
+
+	ret = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_reg);
 	if (ret)
 		goto out;
 	bo->ttm_bound = true;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 71c2a78911cd..6f64f949c202 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -235,7 +235,12 @@ static int radeon_move_vram_ram(struct ttm_buffer_object *bo,
 		goto out_cleanup;
 	}
 
-	r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem, &ctx);
+	r = ttm_tt_populate(bo->bdev, bo->ttm, &ctx);
+	if (unlikely(r)) {
+		goto out_cleanup;
+	}
+
+	r = ttm_tt_bind(bo->bdev, bo->ttm, &tmp_mem);
 	if (unlikely(r)) {
 		goto out_cleanup;
 	}
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bf27d185c23f..bf5f31d9996a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -282,8 +282,11 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 			goto out_err;
 
 		if (mem->mem_type != TTM_PL_SYSTEM) {
+			ret = ttm_tt_populate(bdev, bo->ttm, ctx);
+			if (ret)
+				goto out_err;
 			if (bo->ttm_bound == false) {
-				ret = ttm_tt_bind(bdev, bo->ttm, mem, ctx);
+				ret = ttm_tt_bind(bdev, bo->ttm, mem);
 				if (ret)
 					goto out_err;
 				bo->ttm_bound = true;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 8b50b250da0c..c6262fda1fb8 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -80,7 +80,11 @@ int ttm_bo_move_ttm(struct ttm_buffer_object *bo,
 		return ret;
 
 	if (new_mem->mem_type != TTM_PL_SYSTEM) {
-		ret = ttm_tt_bind(bo->bdev, ttm, new_mem, ctx);
+		ret = ttm_tt_populate(bo->bdev, ttm, ctx);
+		if (unlikely(ret != 0))
+			return ret;
+
+		ret = ttm_tt_bind(bo->bdev, ttm, new_mem);
 		if (unlikely(ret != 0))
 			return ret;
 		bo->ttm_bound = true;
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 8d4f946cd9e0..288fd952bdbe 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -307,22 +307,15 @@ void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
 }
 
 int ttm_tt_bind(struct ttm_bo_device *bdev,
-		struct ttm_tt *ttm, struct ttm_resource *bo_mem,
-		struct ttm_operation_ctx *ctx)
+		struct ttm_tt *ttm, struct ttm_resource *bo_mem)
 {
-	int ret = 0;
-
 	if (!ttm)
 		return -EINVAL;
 
-	ret = ttm_tt_populate(bdev, ttm, ctx);
-	if (ret)
-		return ret;
+	if (WARN_ON(!ttm->populated))
+		return -EINVAL;
 
-	ret = bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
-	if (unlikely(ret != 0))
-		return ret;
-	return 0;
+	return bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
 }
 EXPORT_SYMBOL(ttm_tt_bind);
 
@@ -455,6 +448,7 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
 		ttm_tt_add_mapping(bdev, ttm);
 	return ret;
 }
+EXPORT_SYMBOL(ttm_tt_populate);
 
 static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
 {
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 5d10abb1419b..4b35d0e4b9c5 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -139,8 +139,7 @@ void ttm_dma_tt_fini(struct ttm_dma_tt *ttm_dma);
  * Bind the pages of @ttm to an aperture location identified by @bo_mem
  */
 int ttm_tt_bind(struct ttm_bo_device *bdev,
-		struct ttm_tt *ttm, struct ttm_resource *bo_mem,
-		struct ttm_operation_ctx *ctx);
+		struct ttm_tt *ttm, struct ttm_resource *bo_mem);
 
 /**
  * ttm_ttm_destroy:
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 20/23] drm/ttm: add populated accessors
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (18 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 19/23] drm/ttm: split bind and populate out Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 21/23] drm/ttm: store populated status in upper page flag bits Dave Airlie
                   ` (3 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

next step move populated into upper page flag bits

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_bo.c       |  4 ++--
 drivers/gpu/drm/radeon/radeon_ttm.c        |  4 ++--
 drivers/gpu/drm/ttm/ttm_bo_util.c          |  2 +-
 drivers/gpu/drm/ttm/ttm_page_alloc.c       |  6 +++---
 drivers/gpu/drm/ttm/ttm_page_alloc_dma.c   |  6 +++---
 drivers/gpu/drm/ttm/ttm_tt.c               | 10 +++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_blit.c       |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  2 +-
 include/drm/ttm/ttm_tt.h                   | 12 +++++++++++-
 10 files changed, 32 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index e8a56e64bc38..9eb243ff2ba6 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1307,7 +1307,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 			return -ENOMEM;
 
 		ttm->page_flags |= TTM_PAGE_FLAG_SG;
-		ttm->populated = true;
+		ttm_tt_set_populated(ttm, true);
 		return 0;
 	}
 
@@ -1327,7 +1327,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 						 gtt->ttm.dma_address,
 						 ttm->num_pages);
-		ttm->populated = true;
+		ttm_tt_set_populated(ttm, true);
 		return 0;
 	}
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index f6b6ef7a8868..644f15412dce 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1269,14 +1269,14 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
 	struct device *dev;
 	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
 
-	if (ttm->populated)
+	if (ttm_tt_is_populated(ttm))
 		return 0;
 
 	if (slave && ttm_dma->sg) {
 		/* make userspace faulting work */
 		drm_prime_sg_to_page_addr_arrays(ttm_dma->sg, ttm->pages,
 						 ttm_dma->dma_address, ttm->num_pages);
-		ttm->populated = true;
+		ttm_tt_set_populated(ttm, true);
 		return 0;
 	}
 
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 6f64f949c202..c9f7fc112a84 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -621,14 +621,14 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 			return -ENOMEM;
 
 		ttm->page_flags |= TTM_PAGE_FLAG_SG;
-		ttm->populated = true;
+		ttm_tt_set_populated(ttm, true);
 		return 0;
 	}
 
 	if (slave && gtt->ttm.sg) {
 		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
 						 gtt->ttm.dma_address, ttm->num_pages);
-		ttm->populated = true;
+		ttm_tt_set_populated(ttm, true);
 		return 0;
 	}
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index c6262fda1fb8..33146953141a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -257,7 +257,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 	 * Don't move nonexistent data. Clear destination instead.
 	 */
 	if (old_iomap == NULL &&
-	    (ttm == NULL || (!ttm->populated &&
+	    (ttm == NULL || (!ttm_tt_is_populated(ttm) &&
 			     !(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)))) {
 		memset_io(new_iomap, 0, new_mem->num_pages*PAGE_SIZE);
 		goto out2;
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index 2d30a2deadb5..028ba94d7824 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1044,7 +1044,7 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
 put_pages:
 	ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
 		      ttm->caching_state);
-	ttm->populated = false;
+	ttm_tt_set_populated(ttm, false);
 }
 
 int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
@@ -1053,7 +1053,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 	unsigned i;
 	int ret;
 
-	if (ttm->populated)
+	if (ttm_tt_is_populated(ttm))
 		return 0;
 
 	if (ttm_check_under_lowerlimit(mem_glob, ttm->num_pages, ctx))
@@ -1083,7 +1083,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
 		}
 	}
 
-	ttm->populated = true;
+	ttm_tt_set_populated(ttm, true);
 	return 0;
 }
 EXPORT_SYMBOL(ttm_pool_populate);
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
index 9a3b7145d9cb..e8191d3afce2 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
@@ -894,7 +894,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 	unsigned i;
 	int ret;
 
-	if (ttm->populated)
+	if (ttm_tt_is_populated(ttm))
 		return 0;
 
 	if (ttm_check_under_lowerlimit(mem_glob, num_pages, ctx))
@@ -982,7 +982,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
 		}
 	}
 
-	ttm->populated = true;
+	ttm_tt_set_populated(ttm, true);
 	return 0;
 }
 EXPORT_SYMBOL_GPL(ttm_dma_populate);
@@ -1076,7 +1076,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
 	/* shrink pool if necessary (only on !is_cached pools)*/
 	if (npages)
 		ttm_dma_page_pool_free(pool, npages, false);
-	ttm->populated = false;
+	ttm_tt_set_populated(ttm, false);
 }
 EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
 
diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
index 288fd952bdbe..17a1e3490650 100644
--- a/drivers/gpu/drm/ttm/ttm_tt.c
+++ b/drivers/gpu/drm/ttm/ttm_tt.c
@@ -156,7 +156,7 @@ static int ttm_tt_set_caching(struct ttm_tt *ttm,
 	if (ttm->caching_state == c_state)
 		return 0;
 
-	if (!ttm->populated) {
+	if (!ttm_tt_is_populated(ttm)) {
 		/* Change caching but don't populate */
 		ttm->caching_state = c_state;
 		return 0;
@@ -225,7 +225,7 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
 	ttm->caching_state = tt_cached;
 	ttm->page_flags = page_flags;
 	ttm->swap_storage = NULL;
-	ttm->populated = false;
+	ttm_tt_set_populated(ttm, false);
 }
 
 int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
@@ -312,7 +312,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
 	if (!ttm)
 		return -EINVAL;
 
-	if (WARN_ON(!ttm->populated))
+	if (WARN_ON(!ttm_tt_is_populated(ttm)))
 		return -EINVAL;
 
 	return bdev->driver->ttm_tt_bind(bdev, ttm, bo_mem);
@@ -437,7 +437,7 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
 {
 	int ret;
 
-	if (ttm->populated)
+	if (ttm_tt_is_populated(ttm))
 		return 0;
 
 	if (bdev->driver->ttm_tt_populate)
@@ -467,7 +467,7 @@ static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
 void ttm_tt_unpopulate(struct ttm_bo_device *bdev,
 		       struct ttm_tt *ttm)
 {
-	if (!ttm->populated)
+	if (!ttm_tt_is_populated(ttm))
 		return;
 
 	ttm_tt_clear_mapping(ttm);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
index 77205f92bc9b..62ec1a7f4102 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
@@ -464,13 +464,13 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
 	if (!(src->mem.placement & TTM_PL_FLAG_NO_EVICT))
 		dma_resv_assert_held(src->base.resv);
 
-	if (dst->ttm->populated == false) {
+	if (ttm_tt_is_populated(dst->ttm) == false) {
 		ret = dst->bdev->driver->ttm_tt_populate(dst->bdev, dst->ttm, &ctx);
 		if (ret)
 			return ret;
 	}
 
-	if (src->ttm->populated == false) {
+	if (ttm_tt_is_populated(src->ttm) == false) {
 		ret = src->bdev->driver->ttm_tt_populate(src->bdev, src->ttm, &ctx);
 		if (ret)
 			return ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
index 1925c41d2bda..461c5945740d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
@@ -623,7 +623,7 @@ static int vmw_ttm_populate(struct ttm_bo_device *bdev,
 	struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
 	int ret;
 
-	if (ttm->populated)
+	if (ttm_tt_is_populated(ttm))
 		return 0;
 
 	if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 4b35d0e4b9c5..2aa4cd7d6451 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -69,9 +69,19 @@ struct ttm_tt {
 	unsigned long num_pages;
 	struct file *swap_storage;
 	enum ttm_caching_state caching_state;
-	bool populated;
+	bool _populated;
 };
 
+static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
+{
+	return tt->_populated;
+}
+
+static inline void ttm_tt_set_populated(struct ttm_tt *tt, bool flag)
+{
+	tt->_populated = flag;
+}
+
 /**
  * struct ttm_dma_tt
  *
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 21/23] drm/ttm: store populated status in upper page flag bits.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (19 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 20/23] drm/ttm: add populated accessors Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 22/23] drm/ttm: two minor struct reorgs to fill holes Dave Airlie
                   ` (2 subsequent siblings)
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 include/drm/ttm/ttm_tt.h | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 2aa4cd7d6451..3b87ce43864a 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -42,6 +42,8 @@ struct ttm_operation_ctx;
 #define TTM_PAGE_FLAG_SG              (1 << 8)
 #define TTM_PAGE_FLAG_NO_RETRY	      (1 << 9)
 
+#define TTM_PAGE_FLAG_PRIV_POPULATED  (1 << 31)
+
 enum ttm_caching_state {
 	tt_uncached,
 	tt_wc,
@@ -69,17 +71,19 @@ struct ttm_tt {
 	unsigned long num_pages;
 	struct file *swap_storage;
 	enum ttm_caching_state caching_state;
-	bool _populated;
 };
 
 static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
 {
-	return tt->_populated;
+	return tt->page_flags & TTM_PAGE_FLAG_PRIV_POPULATED;
 }
 
 static inline void ttm_tt_set_populated(struct ttm_tt *tt, bool flag)
 {
-	tt->_populated = flag;
+	if (flag)
+		tt->page_flags |= TTM_PAGE_FLAG_PRIV_POPULATED;
+	else
+		tt->page_flags &= ~TTM_PAGE_FLAG_PRIV_POPULATED;
 }
 
 /**
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 22/23] drm/ttm: two minor struct reorgs to fill holes.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (20 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 21/23] drm/ttm: store populated status in upper page flag bits Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-26  1:44 ` [PATCH 23/23] drm/ttm: change ordering of args to map/unmap helpers Dave Airlie
  2020-08-27 11:55 ` [00/23] ttm tt refactoring Christian König
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

These are just minor changes that fill some obvious holes.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 include/drm/ttm/ttm_placement.h | 2 +-
 include/drm/ttm/ttm_tt.h        | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/include/drm/ttm/ttm_placement.h b/include/drm/ttm/ttm_placement.h
index e88a8e39767b..ded0f42a143c 100644
--- a/include/drm/ttm/ttm_placement.h
+++ b/include/drm/ttm/ttm_placement.h
@@ -100,8 +100,8 @@ struct ttm_place {
  */
 struct ttm_placement {
 	unsigned		num_placement;
-	const struct ttm_place	*placement;
 	unsigned		num_busy_placement;
+	const struct ttm_place	*placement;
 	const struct ttm_place	*busy_placement;
 };
 
diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
index 3b87ce43864a..573254930a3f 100644
--- a/include/drm/ttm/ttm_tt.h
+++ b/include/drm/ttm/ttm_tt.h
@@ -68,9 +68,9 @@ enum ttm_caching_state {
 struct ttm_tt {
 	struct page **pages;
 	uint32_t page_flags;
+	enum ttm_caching_state caching_state;
 	unsigned long num_pages;
 	struct file *swap_storage;
-	enum ttm_caching_state caching_state;
 };
 
 static inline bool ttm_tt_is_populated(struct ttm_tt *tt)
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* [PATCH 23/23] drm/ttm: change ordering of args to map/unmap helpers.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (21 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 22/23] drm/ttm: two minor struct reorgs to fill holes Dave Airlie
@ 2020-08-26  1:44 ` Dave Airlie
  2020-08-27 11:55 ` [00/23] ttm tt refactoring Christian König
  23 siblings, 0 replies; 29+ messages in thread
From: Dave Airlie @ 2020-08-26  1:44 UTC (permalink / raw)
  To: dri-devel; +Cc: kraxel, sroland, bskeggs, christian.koenig

From: Dave Airlie <airlied@redhat.com>

These tooks the same args in a different order to the dma
ones, just make things look nicer.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 4 ++--
 drivers/gpu/drm/nouveau/nouveau_bo.c    | 4 ++--
 drivers/gpu/drm/radeon/radeon_ttm.c     | 4 ++--
 drivers/gpu/drm/ttm/ttm_page_alloc.c    | 8 +++++---
 include/drm/ttm/ttm_page_alloc.h        | 8 +++++---
 5 files changed, 16 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 9eb243ff2ba6..c03093828112 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -1339,7 +1339,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
 
 	/* fall back to generic helper to populate the page array
 	 * and map them to the device */
-	return ttm_populate_and_map_pages(adev->dev, &gtt->ttm, ctx);
+	return ttm_populate_and_map_pages(&gtt->ttm, adev->dev, ctx);
 }
 
 /**
@@ -1382,7 +1382,7 @@ static void amdgpu_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 #endif
 
 	/* fall back to generic helper to unmap and unpopulate array */
-	ttm_unmap_and_unpopulate_pages(adev->dev, &gtt->ttm);
+	ttm_unmap_and_unpopulate_pages(&gtt->ttm, adev->dev);
 }
 
 /**
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 644f15412dce..9988c7572e77 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -1294,7 +1294,7 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
 		return ttm_dma_populate((void *)ttm, dev, ctx);
 	}
 #endif
-	return ttm_populate_and_map_pages(dev, ttm_dma, ctx);
+	return ttm_populate_and_map_pages(ttm_dma, dev, ctx);
 }
 
 static void
@@ -1326,7 +1326,7 @@ nouveau_ttm_tt_unpopulate(struct ttm_bo_device *bdev,
 	}
 #endif
 
-	ttm_unmap_and_unpopulate_pages(dev, ttm_dma);
+	ttm_unmap_and_unpopulate_pages(ttm_dma, dev);
 }
 
 static void
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index c9f7fc112a84..8e3f3da08bff 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -644,7 +644,7 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
 	}
 #endif
 
-	return ttm_populate_and_map_pages(rdev->dev, &gtt->ttm, ctx);
+	return ttm_populate_and_map_pages(&gtt->ttm, rdev->dev, ctx);
 }
 
 static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
@@ -676,7 +676,7 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
 	}
 #endif
 
-	ttm_unmap_and_unpopulate_pages(rdev->dev, &gtt->ttm);
+	ttm_unmap_and_unpopulate_pages(&gtt->ttm, rdev->dev);
 }
 
 int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
index 028ba94d7824..726ea4893a20 100644
--- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
+++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
@@ -1094,8 +1094,9 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm)
 }
 EXPORT_SYMBOL(ttm_pool_unpopulate);
 
-int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
-					struct ttm_operation_ctx *ctx)
+int ttm_populate_and_map_pages(struct ttm_dma_tt *tt,
+			       struct device *dev,
+			       struct ttm_operation_ctx *ctx)
 {
 	unsigned i, j;
 	int r;
@@ -1137,7 +1138,8 @@ int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
 }
 EXPORT_SYMBOL(ttm_populate_and_map_pages);
 
-void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt)
+void ttm_unmap_and_unpopulate_pages(struct ttm_dma_tt *tt,
+				    struct device *dev)
 {
 	unsigned i, j;
 
diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
index a6b6ef5f9bf4..b786ce75920b 100644
--- a/include/drm/ttm/ttm_page_alloc.h
+++ b/include/drm/ttm/ttm_page_alloc.h
@@ -61,13 +61,15 @@ void ttm_pool_unpopulate(struct ttm_tt *ttm);
 /**
  * Populates and DMA maps pages to fullfil a ttm_dma_populate() request
  */
-int ttm_populate_and_map_pages(struct device *dev, struct ttm_dma_tt *tt,
-				struct ttm_operation_ctx *ctx);
+int ttm_populate_and_map_pages(struct ttm_dma_tt *tt,
+			       struct device *dev,
+			       struct ttm_operation_ctx *ctx);
 
 /**
  * Unpopulates and DMA unmaps pages as part of a
  * ttm_dma_unpopulate() request */
-void ttm_unmap_and_unpopulate_pages(struct device *dev, struct ttm_dma_tt *tt);
+void ttm_unmap_and_unpopulate_pages(struct ttm_dma_tt *tt,
+				    struct device *dev);
 
 /**
  * Output the state of pools to debugfs file
-- 
2.27.0

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

^ permalink raw reply related	[flat|nested] 29+ messages in thread

* Re: [PATCH 11/23] drm/gem_vram/ttm: move to driver backend destroy function.
  2020-08-26  1:44 ` [PATCH 11/23] drm/gem_vram/ttm: move to driver backend destroy function Dave Airlie
@ 2020-08-26  5:14   ` Thomas Zimmermann
  0 siblings, 0 replies; 29+ messages in thread
From: Thomas Zimmermann @ 2020-08-26  5:14 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: christian.koenig, sroland, kraxel, bskeggs


[-- Attachment #1.1.1: Type: text/plain, Size: 1762 bytes --]

Hi

Am 26.08.20 um 03:44 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/drm_gem_vram_helper.c | 7 +------
>  1 file changed, 1 insertion(+), 6 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index 788557bc5c01..93586a310971 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -973,10 +973,6 @@ static void backend_func_destroy(struct ttm_bo_device *bdev, struct ttm_tt *tt)
>  	kfree(tt);
>  }
>  
> -static struct ttm_backend_func backend_func = {
> -	.destroy = backend_func_destroy
> -};
> -
>  /*
>   * TTM BO device
>   */
> @@ -991,8 +987,6 @@ static struct ttm_tt *bo_driver_ttm_tt_create(struct ttm_buffer_object *bo,
>  	if (!tt)
>  		return NULL;
>  
> -	tt->func = &backend_func;
> -
>  	ret = ttm_tt_init(tt, bo, page_flags);
>  	if (ret < 0)
>  		goto err_ttm_tt_init;
> @@ -1055,6 +1049,7 @@ static int bo_driver_io_mem_reserve(struct ttm_bo_device *bdev,
>  
>  static struct ttm_bo_driver bo_driver = {
>  	.ttm_tt_create = bo_driver_ttm_tt_create,
> +	.ttm_tt_destroy = backend_func_destroy,

Please rename backend_func_destroy to bo_driver_ttm_tt_destroy. With
this change

Acked-by: Thomas Zimmermann <tzimmermann@suse.de>

Best regards
Thomas

>  	.eviction_valuable = ttm_bo_eviction_valuable,
>  	.evict_flags = bo_driver_evict_flags,
>  	.move_notify = bo_driver_move_notify,
> 

-- 
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Maxfeldstr. 5, 90409 Nürnberg, Germany
(HRB 36809, AG Nürnberg)
Geschäftsführer: Felix Imendörffer


[-- Attachment #1.2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 516 bytes --]

[-- Attachment #2: Type: text/plain, Size: 160 bytes --]

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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 07/23] drm/radeon/ttm: move to driver binding/destroy functions.
  2020-08-26  1:44 ` [PATCH 07/23] drm/radeon/ttm: move to driver binding/destroy functions Dave Airlie
@ 2020-08-27 11:42   ` Christian König
  0 siblings, 0 replies; 29+ messages in thread
From: Christian König @ 2020-08-27 11:42 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 26.08.20 um 03:44 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Do agp decision in the driver, instead of special binding funcs
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/radeon/radeon.h        |  7 +-
>   drivers/gpu/drm/radeon/radeon_cs.c     |  2 +-
>   drivers/gpu/drm/radeon/radeon_gem.c    |  6 +-
>   drivers/gpu/drm/radeon/radeon_object.c |  2 +-
>   drivers/gpu/drm/radeon/radeon_prime.c  |  2 +-
>   drivers/gpu/drm/radeon/radeon_ttm.c    | 92 ++++++++++++++++++++------
>   drivers/gpu/drm/radeon/radeon_vm.c     |  2 +-
>   7 files changed, 81 insertions(+), 32 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h
> index cc4f58d16589..df6f0b49836b 100644
> --- a/drivers/gpu/drm/radeon/radeon.h
> +++ b/drivers/gpu/drm/radeon/radeon.h
> @@ -2815,10 +2815,11 @@ extern void radeon_legacy_set_clock_gating(struct radeon_device *rdev, int enabl
>   extern void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable);
>   extern void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain);
>   extern bool radeon_ttm_bo_is_radeon_bo(struct ttm_buffer_object *bo);
> -extern int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
> +extern int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
> +				     struct ttm_tt *ttm, uint64_t addr,
>   				     uint32_t flags);
> -extern bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm);
> -extern bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm);
> +extern bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev, struct ttm_tt *ttm);
> +extern bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev, struct ttm_tt *ttm);
>   extern void radeon_vram_location(struct radeon_device *rdev, struct radeon_mc *mc, u64 base);
>   extern void radeon_gtt_location(struct radeon_device *rdev, struct radeon_mc *mc);
>   extern int radeon_resume_kms(struct drm_device *dev, bool resume, bool fbcon);
> diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c
> index 33ae1b883268..21ce2f9502c0 100644
> --- a/drivers/gpu/drm/radeon/radeon_cs.c
> +++ b/drivers/gpu/drm/radeon/radeon_cs.c
> @@ -160,7 +160,7 @@ static int radeon_cs_parser_relocs(struct radeon_cs_parser *p)
>   			p->relocs[i].allowed_domains = domain;
>   		}
>   
> -		if (radeon_ttm_tt_has_userptr(p->relocs[i].robj->tbo.ttm)) {
> +		if (radeon_ttm_tt_has_userptr(p->rdev, p->relocs[i].robj->tbo.ttm)) {
>   			uint32_t domain = p->relocs[i].preferred_domains;
>   			if (!(domain & RADEON_GEM_DOMAIN_GTT)) {
>   				DRM_ERROR("Only RADEON_GEM_DOMAIN_GTT is "
> diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
> index 7f5dfe04789e..e5c4271e64ed 100644
> --- a/drivers/gpu/drm/radeon/radeon_gem.c
> +++ b/drivers/gpu/drm/radeon/radeon_gem.c
> @@ -331,7 +331,7 @@ int radeon_gem_userptr_ioctl(struct drm_device *dev, void *data,
>   		goto handle_lockup;
>   
>   	bo = gem_to_radeon_bo(gobj);
> -	r = radeon_ttm_tt_set_userptr(bo->tbo.ttm, args->addr, args->flags);
> +	r = radeon_ttm_tt_set_userptr(rdev, bo->tbo.ttm, args->addr, args->flags);
>   	if (r)
>   		goto release_object;
>   
> @@ -420,7 +420,7 @@ int radeon_mode_dumb_mmap(struct drm_file *filp,
>   		return -ENOENT;
>   	}
>   	robj = gem_to_radeon_bo(gobj);
> -	if (radeon_ttm_tt_has_userptr(robj->tbo.ttm)) {
> +	if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm)) {
>   		drm_gem_object_put(gobj);
>   		return -EPERM;
>   	}
> @@ -721,7 +721,7 @@ int radeon_gem_op_ioctl(struct drm_device *dev, void *data,
>   	robj = gem_to_radeon_bo(gobj);
>   
>   	r = -EPERM;
> -	if (radeon_ttm_tt_has_userptr(robj->tbo.ttm))
> +	if (radeon_ttm_tt_has_userptr(robj->rdev, robj->tbo.ttm))
>   		goto out;
>   
>   	r = radeon_bo_reserve(robj, false);
> diff --git a/drivers/gpu/drm/radeon/radeon_object.c b/drivers/gpu/drm/radeon/radeon_object.c
> index bb7582afd803..3fcd15d21ddc 100644
> --- a/drivers/gpu/drm/radeon/radeon_object.c
> +++ b/drivers/gpu/drm/radeon/radeon_object.c
> @@ -331,7 +331,7 @@ int radeon_bo_pin_restricted(struct radeon_bo *bo, u32 domain, u64 max_offset,
>   	struct ttm_operation_ctx ctx = { false, false };
>   	int r, i;
>   
> -	if (radeon_ttm_tt_has_userptr(bo->tbo.ttm))
> +	if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
>   		return -EPERM;
>   
>   	if (bo->pin_count) {
> diff --git a/drivers/gpu/drm/radeon/radeon_prime.c b/drivers/gpu/drm/radeon/radeon_prime.c
> index b906e8fbd5f3..d6d9c8b46ab4 100644
> --- a/drivers/gpu/drm/radeon/radeon_prime.c
> +++ b/drivers/gpu/drm/radeon/radeon_prime.c
> @@ -121,7 +121,7 @@ struct dma_buf *radeon_gem_prime_export(struct drm_gem_object *gobj,
>   					int flags)
>   {
>   	struct radeon_bo *bo = gem_to_radeon_bo(gobj);
> -	if (radeon_ttm_tt_has_userptr(bo->tbo.ttm))
> +	if (radeon_ttm_tt_has_userptr(bo->rdev, bo->tbo.ttm))
>   		return ERR_PTR(-EPERM);
>   	return drm_gem_prime_export(gobj, flags);
>   }
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index 1d3e8bb69f8e..af5479ea154c 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -141,8 +141,9 @@ static void radeon_evict_flags(struct ttm_buffer_object *bo,
>   static int radeon_verify_access(struct ttm_buffer_object *bo, struct file *filp)
>   {
>   	struct radeon_bo *rbo = container_of(bo, struct radeon_bo, tbo);
> +	struct radeon_device *rdev = radeon_get_rdev(bo->bdev);
>   
> -	if (radeon_ttm_tt_has_userptr(bo->ttm))
> +	if (radeon_ttm_tt_has_userptr(rdev, bo->ttm))
>   		return -EPERM;
>   	return drm_vma_node_verify_access(&rbo->tbo.base.vma_node,
>   					  filp->private_data);
> @@ -561,12 +562,6 @@ static void radeon_ttm_backend_destroy(struct ttm_bo_device *bdev, struct ttm_tt
>   	kfree(gtt);
>   }
>   
> -static struct ttm_backend_func radeon_backend_func = {
> -	.bind = &radeon_ttm_backend_bind,
> -	.unbind = &radeon_ttm_backend_unbind,
> -	.destroy = &radeon_ttm_backend_destroy,
> -};
> -
>   static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
>   					   uint32_t page_flags)
>   {
> @@ -585,7 +580,6 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
>   	if (gtt == NULL) {
>   		return NULL;
>   	}
> -	gtt->ttm.ttm.func = &radeon_backend_func;
>   	if (ttm_dma_tt_init(&gtt->ttm, bo, page_flags)) {
>   		kfree(gtt);
>   		return NULL;
> @@ -593,9 +587,16 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
>   	return &gtt->ttm.ttm;
>   }
>   
> -static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct ttm_tt *ttm)
> +static struct radeon_ttm_tt *radeon_ttm_tt_to_gtt(struct radeon_device *rdev,
> +						  struct ttm_tt *ttm)
>   {
> -	if (!ttm || ttm->func != &radeon_backend_func)
> +#if IS_ENABLED(CONFIG_AGP)
> +	if (rdev->flags & RADEON_IS_AGP) {
> +		return NULL;
> +	}

Style nit: You can drop the {}.

> +#endif
> +
> +	if (!ttm)
>   		return NULL;
>   	return (struct radeon_ttm_tt *)ttm;

Maybe turn this into a container_of while at it.

Apart from that looks good to me,
Christian.

>   }
> @@ -604,8 +605,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
>   				  struct ttm_tt *ttm,
>   				  struct ttm_operation_ctx *ctx)
>   {
> -	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
> -	struct radeon_device *rdev;
> +	struct radeon_device *rdev = radeon_get_rdev(bdev);
> +	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
>   	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>   
>   	if (gtt && gtt->userptr) {
> @@ -625,7 +626,6 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
>   		return 0;
>   	}
>   
> -	rdev = radeon_get_rdev(bdev);
>   #if IS_ENABLED(CONFIG_AGP)
>   	if (rdev->flags & RADEON_IS_AGP) {
>   		return ttm_agp_tt_populate(bdev, ttm, ctx);
> @@ -643,8 +643,8 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
>   
>   static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>   {
> -	struct radeon_device *rdev;
> -	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
> +	struct radeon_device *rdev = radeon_get_rdev(bdev);
> +	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
>   	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>   
>   	if (gtt && gtt->userptr) {
> @@ -656,7 +656,6 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
>   	if (slave)
>   		return;
>   
> -	rdev = radeon_get_rdev(bdev);
>   #if IS_ENABLED(CONFIG_AGP)
>   	if (rdev->flags & RADEON_IS_AGP) {
>   		ttm_agp_tt_unpopulate(bdev, ttm);
> @@ -674,10 +673,11 @@ static void radeon_ttm_tt_unpopulate(struct ttm_bo_device *bdev, struct ttm_tt *
>   	ttm_unmap_and_unpopulate_pages(rdev->dev, &gtt->ttm);
>   }
>   
> -int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
> +int radeon_ttm_tt_set_userptr(struct radeon_device *rdev,
> +			      struct ttm_tt *ttm, uint64_t addr,
>   			      uint32_t flags)
>   {
> -	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
> +	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
>   
>   	if (gtt == NULL)
>   		return -EINVAL;
> @@ -688,9 +688,53 @@ int radeon_ttm_tt_set_userptr(struct ttm_tt *ttm, uint64_t addr,
>   	return 0;
>   }
>   
> -bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
> +static int radeon_ttm_tt_bind(struct ttm_bo_device *bdev,
> +			      struct ttm_tt *ttm,
> +			      struct ttm_resource *bo_mem)
> +{
> +	struct radeon_device *rdev = radeon_get_rdev(bdev);
> +
> +#if IS_ENABLED(CONFIG_AGP)
> +	if (rdev->flags & RADEON_IS_AGP) {
> +		return ttm_agp_bind(bdev, ttm, bo_mem);
> +	}
> +#endif
> +
> +	return radeon_ttm_backend_bind(bdev, ttm, bo_mem);
> +}
> +
> +static void radeon_ttm_tt_unbind(struct ttm_bo_device *bdev,
> +				 struct ttm_tt *ttm)
> +{
> +#if IS_ENABLED(CONFIG_AGP)
> +	struct radeon_device *rdev = radeon_get_rdev(bdev);
> +
> +	if (rdev->flags & RADEON_IS_AGP) {
> +		ttm_agp_unbind(bdev, ttm);
> +		return;
> +	}
> +#endif
> +	radeon_ttm_backend_unbind(bdev, ttm);
> +}
> +
> +static void radeon_ttm_tt_destroy(struct ttm_bo_device *bdev,
> +				  struct ttm_tt *ttm)
> +{
> +#if IS_ENABLED(CONFIG_AGP)
> +	struct radeon_device *rdev = radeon_get_rdev(bdev);
> +
> +	if (rdev->flags & RADEON_IS_AGP) {
> +		ttm_agp_destroy(bdev, ttm);
> +		return;
> +	}
> +#endif
> +	radeon_ttm_backend_destroy(bdev, ttm);
> +}
> +
> +bool radeon_ttm_tt_has_userptr(struct radeon_device *rdev,
> +			       struct ttm_tt *ttm)
>   {
> -	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
> +	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
>   
>   	if (gtt == NULL)
>   		return false;
> @@ -698,9 +742,10 @@ bool radeon_ttm_tt_has_userptr(struct ttm_tt *ttm)
>   	return !!gtt->userptr;
>   }
>   
> -bool radeon_ttm_tt_is_readonly(struct ttm_tt *ttm)
> +bool radeon_ttm_tt_is_readonly(struct radeon_device *rdev,
> +			       struct ttm_tt *ttm)
>   {
> -	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(ttm);
> +	struct radeon_ttm_tt *gtt = radeon_ttm_tt_to_gtt(rdev, ttm);
>   
>   	if (gtt == NULL)
>   		return false;
> @@ -712,6 +757,9 @@ static struct ttm_bo_driver radeon_bo_driver = {
>   	.ttm_tt_create = &radeon_ttm_tt_create,
>   	.ttm_tt_populate = &radeon_ttm_tt_populate,
>   	.ttm_tt_unpopulate = &radeon_ttm_tt_unpopulate,
> +	.ttm_tt_bind = &radeon_ttm_tt_bind,
> +	.ttm_tt_unbind = &radeon_ttm_tt_unbind,
> +	.ttm_tt_destroy = &radeon_ttm_tt_destroy,
>   	.eviction_valuable = ttm_bo_eviction_valuable,
>   	.evict_flags = &radeon_evict_flags,
>   	.move = &radeon_bo_move,
> diff --git a/drivers/gpu/drm/radeon/radeon_vm.c b/drivers/gpu/drm/radeon/radeon_vm.c
> index 71e2c3785ab9..ebad27c91a0d 100644
> --- a/drivers/gpu/drm/radeon/radeon_vm.c
> +++ b/drivers/gpu/drm/radeon/radeon_vm.c
> @@ -942,7 +942,7 @@ int radeon_vm_bo_update(struct radeon_device *rdev,
>   	bo_va->flags &= ~RADEON_VM_PAGE_VALID;
>   	bo_va->flags &= ~RADEON_VM_PAGE_SYSTEM;
>   	bo_va->flags &= ~RADEON_VM_PAGE_SNOOPED;
> -	if (bo_va->bo && radeon_ttm_tt_is_readonly(bo_va->bo->tbo.ttm))
> +	if (bo_va->bo && radeon_ttm_tt_is_readonly(rdev, bo_va->bo->tbo.ttm))
>   		bo_va->flags &= ~RADEON_VM_PAGE_WRITEABLE;
>   
>   	if (mem) {

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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 17/23] drm/ttm: split populated/bound state flags.
  2020-08-26  1:44 ` [PATCH 17/23] drm/ttm: split populated/bound state flags Dave Airlie
@ 2020-08-27 11:52   ` Christian König
  0 siblings, 0 replies; 29+ messages in thread
From: Christian König @ 2020-08-27 11:52 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 26.08.20 um 03:44 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Get bound out is the next step.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c    |  4 ++--
>   drivers/gpu/drm/nouveau/nouveau_bo.c       |  4 ++--
>   drivers/gpu/drm/radeon/radeon_mn.c         |  2 +-
>   drivers/gpu/drm/radeon/radeon_ttm.c        |  4 ++--
>   drivers/gpu/drm/ttm/ttm_bo_util.c          |  2 +-
>   drivers/gpu/drm/ttm/ttm_page_alloc.c       |  6 +++---
>   drivers/gpu/drm/ttm/ttm_page_alloc_dma.c   |  6 +++---
>   drivers/gpu/drm/ttm/ttm_tt.c               | 19 +++++++++----------
>   drivers/gpu/drm/vmwgfx/vmwgfx_blit.c       |  4 ++--
>   drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c |  2 +-
>   include/drm/ttm/ttm_tt.h                   | 10 ++++------
>   11 files changed, 30 insertions(+), 33 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index adac24625191..c1c3691c3b9f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -1301,7 +1301,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
>   			return -ENOMEM;
>   
>   		ttm->page_flags |= TTM_PAGE_FLAG_SG;
> -		ttm->state = tt_unbound;
> +		ttm->populated = true;
>   		return 0;
>   	}
>   
> @@ -1321,7 +1321,7 @@ static int amdgpu_ttm_tt_populate(struct ttm_bo_device *bdev,
>   		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
>   						 gtt->ttm.dma_address,
>   						 ttm->num_pages);
> -		ttm->state = tt_unbound;
> +		ttm->populated = true;
>   		return 0;
>   	}
>   
> diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
> index 478e498da965..e9de922ae921 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_bo.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
> @@ -1264,14 +1264,14 @@ nouveau_ttm_tt_populate(struct ttm_bo_device *bdev,
>   	struct device *dev;
>   	bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG);
>   
> -	if (ttm->state != tt_unpopulated)
> +	if (ttm->populated)
>   		return 0;
>   
>   	if (slave && ttm_dma->sg) {
>   		/* make userspace faulting work */
>   		drm_prime_sg_to_page_addr_arrays(ttm_dma->sg, ttm->pages,
>   						 ttm_dma->dma_address, ttm->num_pages);
> -		ttm->state = tt_unbound;
> +		ttm->populated = true;
>   		return 0;
>   	}
>   
> diff --git a/drivers/gpu/drm/radeon/radeon_mn.c b/drivers/gpu/drm/radeon/radeon_mn.c
> index f93829f08a4d..5f57df7e6f08 100644
> --- a/drivers/gpu/drm/radeon/radeon_mn.c
> +++ b/drivers/gpu/drm/radeon/radeon_mn.c
> @@ -53,7 +53,7 @@ static bool radeon_mn_invalidate(struct mmu_interval_notifier *mn,
>   	struct ttm_operation_ctx ctx = { false, false };
>   	long r;
>   
> -	if (!bo->tbo.ttm || bo->tbo.ttm->state != tt_bound)
> +	if (!bo->tbo.ttm || bo->tbo.ttm->bound == false)

I think using ! instead of "== false" would look better here.

Christian.

>   		return true;
>   
>   	if (!mmu_notifier_range_blockable(range))
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index f5cbe5d13d33..f9e4e64a6d64 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -615,14 +615,14 @@ static int radeon_ttm_tt_populate(struct ttm_bo_device *bdev,
>   			return -ENOMEM;
>   
>   		ttm->page_flags |= TTM_PAGE_FLAG_SG;
> -		ttm->state = tt_unbound;
> +		ttm->populated = true;
>   		return 0;
>   	}
>   
>   	if (slave && gtt->ttm.sg) {
>   		drm_prime_sg_to_page_addr_arrays(gtt->ttm.sg, ttm->pages,
>   						 gtt->ttm.dma_address, ttm->num_pages);
> -		ttm->state = tt_unbound;
> +		ttm->populated = true;
>   		return 0;
>   	}
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index 3b17fe3cb57a..d5d841270e38 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -251,7 +251,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
>   	 * Don't move nonexistent data. Clear destination instead.
>   	 */
>   	if (old_iomap == NULL &&
> -	    (ttm == NULL || (ttm->state == tt_unpopulated &&
> +	    (ttm == NULL || (!ttm->populated &&
>   			     !(ttm->page_flags & TTM_PAGE_FLAG_SWAPPED)))) {
>   		memset_io(new_iomap, 0, new_mem->num_pages*PAGE_SIZE);
>   		goto out2;
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> index b40a4678c296..2d30a2deadb5 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
> @@ -1044,7 +1044,7 @@ ttm_pool_unpopulate_helper(struct ttm_tt *ttm, unsigned mem_count_update)
>   put_pages:
>   	ttm_put_pages(ttm->pages, ttm->num_pages, ttm->page_flags,
>   		      ttm->caching_state);
> -	ttm->state = tt_unpopulated;
> +	ttm->populated = false;
>   }
>   
>   int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
> @@ -1053,7 +1053,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>   	unsigned i;
>   	int ret;
>   
> -	if (ttm->state != tt_unpopulated)
> +	if (ttm->populated)
>   		return 0;
>   
>   	if (ttm_check_under_lowerlimit(mem_glob, ttm->num_pages, ctx))
> @@ -1083,7 +1083,7 @@ int ttm_pool_populate(struct ttm_tt *ttm, struct ttm_operation_ctx *ctx)
>   		}
>   	}
>   
> -	ttm->state = tt_unbound;
> +	ttm->populated = true;
>   	return 0;
>   }
>   EXPORT_SYMBOL(ttm_pool_populate);
> diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> index faefaaef7909..9a3b7145d9cb 100644
> --- a/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> +++ b/drivers/gpu/drm/ttm/ttm_page_alloc_dma.c
> @@ -894,7 +894,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
>   	unsigned i;
>   	int ret;
>   
> -	if (ttm->state != tt_unpopulated)
> +	if (ttm->populated)
>   		return 0;
>   
>   	if (ttm_check_under_lowerlimit(mem_glob, num_pages, ctx))
> @@ -982,7 +982,7 @@ int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev,
>   		}
>   	}
>   
> -	ttm->state = tt_unbound;
> +	ttm->populated = true;
>   	return 0;
>   }
>   EXPORT_SYMBOL_GPL(ttm_dma_populate);
> @@ -1076,7 +1076,7 @@ void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev)
>   	/* shrink pool if necessary (only on !is_cached pools)*/
>   	if (npages)
>   		ttm_dma_page_pool_free(pool, npages, false);
> -	ttm->state = tt_unpopulated;
> +	ttm->populated = false;
>   }
>   EXPORT_SYMBOL_GPL(ttm_dma_unpopulate);
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c
> index 1b9960085d11..ee6fda175da6 100644
> --- a/drivers/gpu/drm/ttm/ttm_tt.c
> +++ b/drivers/gpu/drm/ttm/ttm_tt.c
> @@ -156,7 +156,7 @@ static int ttm_tt_set_caching(struct ttm_tt *ttm,
>   	if (ttm->caching_state == c_state)
>   		return 0;
>   
> -	if (ttm->state == tt_unpopulated) {
> +	if (!ttm->populated) {
>   		/* Change caching but don't populate */
>   		ttm->caching_state = c_state;
>   		return 0;
> @@ -214,7 +214,7 @@ void ttm_tt_destroy(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>   
>   	ttm_tt_unbind(bdev, ttm);
>   
> -	if (ttm->state == tt_unbound)
> +	if (ttm->populated)
>   		ttm_tt_unpopulate(bdev, ttm);
>   
>   	if (!(ttm->page_flags & TTM_PAGE_FLAG_PERSISTENT_SWAP) &&
> @@ -232,8 +232,8 @@ static void ttm_tt_init_fields(struct ttm_tt *ttm,
>   	ttm->num_pages = bo->num_pages;
>   	ttm->caching_state = tt_cached;
>   	ttm->page_flags = page_flags;
> -	ttm->state = tt_unpopulated;
>   	ttm->swap_storage = NULL;
> +	ttm->populated = false;
>   }
>   
>   int ttm_tt_init(struct ttm_tt *ttm, struct ttm_buffer_object *bo,
> @@ -311,9 +311,9 @@ EXPORT_SYMBOL(ttm_dma_tt_fini);
>   
>   void ttm_tt_unbind(struct ttm_bo_device *bdev, struct ttm_tt *ttm)
>   {
> -	if (ttm->state == tt_bound) {
> +	if (ttm->bound) {
>   		bdev->driver->ttm_tt_unbind(bdev, ttm);
> -		ttm->state = tt_unbound;
> +		ttm->bound = false;
>   	}
>   }
>   
> @@ -326,7 +326,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
>   	if (!ttm)
>   		return -EINVAL;
>   
> -	if (ttm->state == tt_bound)
> +	if (ttm->bound)
>   		return 0;
>   
>   	ret = ttm_tt_populate(bdev, ttm, ctx);
> @@ -337,7 +337,7 @@ int ttm_tt_bind(struct ttm_bo_device *bdev,
>   	if (unlikely(ret != 0))
>   		return ret;
>   
> -	ttm->state = tt_bound;
> +	ttm->bound = true;
>   
>   	return 0;
>   }
> @@ -395,7 +395,6 @@ int ttm_tt_swapout(struct ttm_bo_device *bdev,
>   	int i;
>   	int ret = -ENOMEM;
>   
> -	BUG_ON(ttm->state != tt_unbound && ttm->state != tt_unpopulated);
>   	BUG_ON(ttm->caching_state != tt_cached);
>   
>   	if (!persistent_swap_storage) {
> @@ -462,7 +461,7 @@ int ttm_tt_populate(struct ttm_bo_device *bdev,
>   {
>   	int ret;
>   
> -	if (ttm->state != tt_unpopulated)
> +	if (ttm->populated)
>   		return 0;
>   
>   	if (bdev->driver->ttm_tt_populate)
> @@ -491,7 +490,7 @@ static void ttm_tt_clear_mapping(struct ttm_tt *ttm)
>   void ttm_tt_unpopulate(struct ttm_bo_device *bdev,
>   		       struct ttm_tt *ttm)
>   {
> -	if (ttm->state == tt_unpopulated)
> +	if (!ttm->populated)
>   		return;
>   
>   	ttm_tt_clear_mapping(ttm);
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
> index 0cd21590ded9..77205f92bc9b 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_blit.c
> @@ -464,13 +464,13 @@ int vmw_bo_cpu_blit(struct ttm_buffer_object *dst,
>   	if (!(src->mem.placement & TTM_PL_FLAG_NO_EVICT))
>   		dma_resv_assert_held(src->base.resv);
>   
> -	if (dst->ttm->state == tt_unpopulated) {
> +	if (dst->ttm->populated == false) {
>   		ret = dst->bdev->driver->ttm_tt_populate(dst->bdev, dst->ttm, &ctx);
>   		if (ret)
>   			return ret;
>   	}
>   
> -	if (src->ttm->state == tt_unpopulated) {
> +	if (src->ttm->populated == false) {
>   		ret = src->bdev->driver->ttm_tt_populate(src->bdev, src->ttm, &ctx);
>   		if (ret)
>   			return ret;
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> index 6757be98be14..1925c41d2bda 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ttm_buffer.c
> @@ -623,7 +623,7 @@ static int vmw_ttm_populate(struct ttm_bo_device *bdev,
>   	struct ttm_mem_global *glob = vmw_mem_glob(dev_priv);
>   	int ret;
>   
> -	if (ttm->state != tt_unpopulated)
> +	if (ttm->populated)
>   		return 0;
>   
>   	if (dev_priv->map_mode == vmw_dma_alloc_coherent) {
> diff --git a/include/drm/ttm/ttm_tt.h b/include/drm/ttm/ttm_tt.h
> index 534d0ef24072..c6e88f01062e 100644
> --- a/include/drm/ttm/ttm_tt.h
> +++ b/include/drm/ttm/ttm_tt.h
> @@ -57,7 +57,8 @@ enum ttm_caching_state {
>    * @be: Pointer to the ttm backend.
>    * @swap_storage: Pointer to shmem struct file for swap storage.
>    * @caching_state: The current caching state of the pages.
> - * @state: The current binding state of the pages.
> + * @populated: if the backing store is populated
> + * @bound: if this object has been bound to a global table.
>    *
>    * This is a structure holding the pages, caching- and aperture binding
>    * status for a buffer object that isn't backed by fixed (VRAM / AGP)
> @@ -69,11 +70,8 @@ struct ttm_tt {
>   	unsigned long num_pages;
>   	struct file *swap_storage;
>   	enum ttm_caching_state caching_state;
> -	enum {
> -		tt_bound,
> -		tt_unbound,
> -		tt_unpopulated,
> -	} state;
> +	bool populated;
> +	bool bound;
>   };
>   
>   /**

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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [00/23] ttm tt refactoring.
  2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
                   ` (22 preceding siblings ...)
  2020-08-26  1:44 ` [PATCH 23/23] drm/ttm: change ordering of args to map/unmap helpers Dave Airlie
@ 2020-08-27 11:55 ` Christian König
  23 siblings, 0 replies; 29+ messages in thread
From: Christian König @ 2020-08-27 11:55 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

A repeating style nit pick that {} can be dropped on single line if and 
empty line between declaration and code.

Apart from that looks mostly good to me :)

Patches #1-#4, #6, #10, #12-#15 are Reviewed-by: Christian König 
<christian.koenig@amd.com>

Patch #5, #8, #9, #11 are Acked-by: Christian König 
<christian.koenig@amd.com>

A few nits on patch #7.

Regarding patch #16 I'm not sure if the sub-classing into ttm_tt and 
ttm_dma_tt is really worth it. I mean we can provide allocation helpers 
for drivers which don't need the DMA address array. But apart from that 
I'm pretty sure keeping the all fields in ttm_tt is the way to go.

Patch #17 has one little style comment.

I really need to take an in deep look at patches #18-#23, but the 
general approach sounds like the right thing to do.

Christian.

Am 26.08.20 um 03:44 schrieb Dave Airlie:
> This is based on top of misc-next with Christians io rework for nouveau.
>
> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Fgithub.com%2Fairlied%2Flinux%2Ftree%2Fttm-tt-cleanup&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7C84fd18e47b124259c45a08d849619a9a%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637340030838885795&amp;sdata=WyDLcpJp07bSNxYPWovsnDkUIRDDmK3OlakW%2Fwy9HX4%3D&amp;reserved=0 (is a complete tree)
>
> The idea is to move towards ttm_tt being just a backing store for system
> allocated pages + dma info, and not be anything to do with a global TT.
>
> First is a couple of minor cleanups, then drops bdev from ttm_tt,
> and moves the func table into the bdev driver table instead, makes
> drivers deal with the agp differences, then cleans up the mess.
>
> It tries to cleanup ttm_tt a bit more as well, in the end ttm_tt
> is getting to what I'd like it to represent, the next step is tackling
> the whole bind/unbind/move stuff I think.
>
> Dave.
>
>

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

^ permalink raw reply	[flat|nested] 29+ messages in thread

* Re: [PATCH 02/23] drm/radeon/ttm: don't store driver copy of device pointer.
  2020-08-26  1:44 ` [PATCH 02/23] drm/radeon/ttm: don't store driver copy of device pointer Dave Airlie
@ 2020-09-01 11:53   ` Daniel Vetter
  0 siblings, 0 replies; 29+ messages in thread
From: Daniel Vetter @ 2020-09-01 11:53 UTC (permalink / raw)
  To: Dave Airlie; +Cc: christian.koenig, sroland, kraxel, dri-devel, bskeggs

On Wed, Aug 26, 2020 at 11:44:07AM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> This can be gotten back from bdev.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/radeon/radeon_ttm.c | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index f6311f404db8..0923a8601112 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -412,7 +412,6 @@ static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_reso
>   */
>  struct radeon_ttm_tt {
>  	struct ttm_dma_tt		ttm;
> -	struct radeon_device		*rdev;

At least for amdgpu the drm_device embedding stuff landed, so I think we
can drop a lot more of these all over because upcasting from a struct
drm_device * to tha adev is just a container_of.

Entirely separate bikeshed cleanup, but I think it'd help to make ttm feel
a bit more like a helper for gpu drivers than it's entirely separate world
:-)

Cheers, Daniel

>  	u64				offset;
>  
>  	uint64_t			userptr;
> @@ -515,6 +514,7 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
>  				   struct ttm_resource *bo_mem)
>  {
>  	struct radeon_ttm_tt *gtt = (void*)ttm;
> +	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
>  	uint32_t flags = RADEON_GART_PAGE_VALID | RADEON_GART_PAGE_READ |
>  		RADEON_GART_PAGE_WRITE;
>  	int r;
> @@ -531,7 +531,7 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
>  	}
>  	if (ttm->caching_state == tt_cached)
>  		flags |= RADEON_GART_PAGE_SNOOP;
> -	r = radeon_gart_bind(gtt->rdev, gtt->offset, ttm->num_pages,
> +	r = radeon_gart_bind(rdev, gtt->offset, ttm->num_pages,
>  			     ttm->pages, gtt->ttm.dma_address, flags);
>  	if (r) {
>  		DRM_ERROR("failed to bind %lu pages at 0x%08X\n",
> @@ -544,8 +544,9 @@ static int radeon_ttm_backend_bind(struct ttm_tt *ttm,
>  static void radeon_ttm_backend_unbind(struct ttm_tt *ttm)
>  {
>  	struct radeon_ttm_tt *gtt = (void *)ttm;
> +	struct radeon_device *rdev = radeon_get_rdev(ttm->bdev);
>  
> -	radeon_gart_unbind(gtt->rdev, gtt->offset, ttm->num_pages);
> +	radeon_gart_unbind(rdev, gtt->offset, ttm->num_pages);
>  
>  	if (gtt->userptr)
>  		radeon_ttm_tt_unpin_userptr(ttm);
> @@ -584,7 +585,6 @@ static struct ttm_tt *radeon_ttm_tt_create(struct ttm_buffer_object *bo,
>  		return NULL;
>  	}
>  	gtt->ttm.ttm.func = &radeon_backend_func;
> -	gtt->rdev = rdev;
>  	if (ttm_dma_tt_init(&gtt->ttm, bo, page_flags)) {
>  		kfree(gtt);
>  		return NULL;
> -- 
> 2.27.0
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 29+ messages in thread

end of thread, other threads:[~2020-09-01 11:53 UTC | newest]

Thread overview: 29+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-26  1:44 [00/23] ttm tt refactoring Dave Airlie
2020-08-26  1:44 ` [PATCH 01/23] drm/amdgpu/ttm: remove unused parameter to move blit Dave Airlie
2020-08-26  1:44 ` [PATCH 02/23] drm/radeon/ttm: don't store driver copy of device pointer Dave Airlie
2020-09-01 11:53   ` Daniel Vetter
2020-08-26  1:44 ` [PATCH 03/23] drm/ttm: remove bdev from ttm_tt Dave Airlie
2020-08-26  1:44 ` [PATCH 04/23] drm/ttm: add optional bind/unbind via driver Dave Airlie
2020-08-26  1:44 ` [PATCH 05/23] drm/qxl: move bind/unbind/destroy to the driver function table Dave Airlie
2020-08-26  1:44 ` [PATCH 06/23] drm/ttm/agp: export bind/unbind/destroy for drivers to use Dave Airlie
2020-08-26  1:44 ` [PATCH 07/23] drm/radeon/ttm: move to driver binding/destroy functions Dave Airlie
2020-08-27 11:42   ` Christian König
2020-08-26  1:44 ` [PATCH 08/23] drm/nouveau/ttm: use driver bind/unbind/destroy functions Dave Airlie
2020-08-26  1:44 ` [PATCH 09/23] drm/vmwgfx: move to driver binding functions Dave Airlie
2020-08-26  1:44 ` [PATCH 10/23] drm/amdgpu/ttm: move to driver backend binding funcs Dave Airlie
2020-08-26  1:44 ` [PATCH 11/23] drm/gem_vram/ttm: move to driver backend destroy function Dave Airlie
2020-08-26  5:14   ` Thomas Zimmermann
2020-08-26  1:44 ` [PATCH 12/23] drm/ttm/agp: drop back end bindings from agp Dave Airlie
2020-08-26  1:44 ` [PATCH 13/23] drm/ttm: get rid of agp specific populate/unpopulate paths Dave Airlie
2020-08-26  1:44 ` [PATCH 14/23] drm/ttm/agp: remove bdev from agp helpers Dave Airlie
2020-08-26  1:44 ` [PATCH 15/23] drm/ttm: drop the tt backend function paths Dave Airlie
2020-08-26  1:44 ` [PATCH 16/23] drm/ttm: move sg pointer into ttm_dma_tt Dave Airlie
2020-08-26  1:44 ` [PATCH 17/23] drm/ttm: split populated/bound state flags Dave Airlie
2020-08-27 11:52   ` Christian König
2020-08-26  1:44 ` [PATCH 18/23] drm/ttm: move bound flag and use a utility wrapper Dave Airlie
2020-08-26  1:44 ` [PATCH 19/23] drm/ttm: split bind and populate out Dave Airlie
2020-08-26  1:44 ` [PATCH 20/23] drm/ttm: add populated accessors Dave Airlie
2020-08-26  1:44 ` [PATCH 21/23] drm/ttm: store populated status in upper page flag bits Dave Airlie
2020-08-26  1:44 ` [PATCH 22/23] drm/ttm: two minor struct reorgs to fill holes Dave Airlie
2020-08-26  1:44 ` [PATCH 23/23] drm/ttm: change ordering of args to map/unmap helpers Dave Airlie
2020-08-27 11:55 ` [00/23] ttm tt refactoring Christian König

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).