[PATCH 4/5] drm/nouveau: switch to using new placement flags

Christian König ckoenig.leichtzumerken at gmail.com
Tue Aug 31 11:21:09 UTC 2021


This simplifies the handling quite a bit, but needs extensive testing.

Signed-off-by: Christian König <christian.koenig at amd.com>
---
 drivers/gpu/drm/nouveau/nouveau_bo.c | 61 ++++++++++------------------
 drivers/gpu/drm/nouveau/nouveau_bo.h |  1 -
 2 files changed, 22 insertions(+), 40 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c
index 33dca2565cca..d46e87f1c9c3 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.c
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.c
@@ -344,33 +344,41 @@ nouveau_bo_new(struct nouveau_cli *cli, u64 size, int align,
 	return 0;
 }
 
-static void
-set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t domain)
+void
+nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
+			 uint32_t busy)
 {
-	*n = 0;
+	struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
+	u64 vram_size = drm->client.device.info.ram_size;
+	unsigned *n = &nvbo->placement.num_placement;
+	struct ttm_place *pl = nvbo->placements;
+	unsigned i, fpfn, lpfn;
 
+	nvbo->placement.placement = pl;
+	nvbo->placement.busy_placement = pl;
+	busy &= ~domain;
+	domain |= busy;
+
+	*n = 0;
 	if (domain & NOUVEAU_GEM_DOMAIN_VRAM) {
 		pl[*n].mem_type = TTM_PL_VRAM;
-		pl[*n].flags = 0;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_VRAM ?
+			TTM_PL_FLAG_BUSY : 0;
 		(*n)++;
 	}
 	if (domain & NOUVEAU_GEM_DOMAIN_GART) {
 		pl[*n].mem_type = TTM_PL_TT;
-		pl[*n].flags = 0;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_GART ?
+			TTM_PL_FLAG_BUSY : 0;
 		(*n)++;
 	}
 	if (domain & NOUVEAU_GEM_DOMAIN_CPU) {
 		pl[*n].mem_type = TTM_PL_SYSTEM;
-		pl[(*n)++].flags = 0;
+		pl[*n].flags = busy & NOUVEAU_GEM_DOMAIN_CPU ?
+			TTM_PL_FLAG_BUSY : 0;
+		(*n)++;
 	}
-}
-
-static void
-set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
-{
-	struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev);
-	u64 vram_size = drm->client.device.info.ram_size;
-	unsigned i, fpfn, lpfn;
+	nvbo->placement.num_busy_placement = *n;
 
 	if (drm->client.device.info.family == NV_DEVICE_INFO_V0_CELSIUS &&
 	    nvbo->mode && (domain & NOUVEAU_GEM_DOMAIN_VRAM) &&
@@ -392,29 +400,9 @@ set_placement_range(struct nouveau_bo *nvbo, uint32_t domain)
 			nvbo->placements[i].fpfn = fpfn;
 			nvbo->placements[i].lpfn = lpfn;
 		}
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = fpfn;
-			nvbo->busy_placements[i].lpfn = lpfn;
-		}
 	}
 }
 
-void
-nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t domain,
-			 uint32_t busy)
-{
-	struct ttm_placement *pl = &nvbo->placement;
-
-	pl->placement = nvbo->placements;
-	set_placement_list(nvbo->placements, &pl->num_placement, domain);
-
-	pl->busy_placement = nvbo->busy_placements;
-	set_placement_list(nvbo->busy_placements, &pl->num_busy_placement,
-			   domain | busy);
-
-	set_placement_range(nvbo, domain);
-}
-
 int
 nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t domain, bool contig)
 {
@@ -1224,11 +1212,6 @@ vm_fault_t nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo)
 			nvbo->placements[i].lpfn = mappable;
 		}
 
-		for (i = 0; i < nvbo->placement.num_busy_placement; ++i) {
-			nvbo->busy_placements[i].fpfn = 0;
-			nvbo->busy_placements[i].lpfn = mappable;
-		}
-
 		nouveau_bo_placement_set(nvbo, NOUVEAU_GEM_DOMAIN_VRAM, 0);
 	}
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.h b/drivers/gpu/drm/nouveau/nouveau_bo.h
index c2d3f9c48eba..9c29cf716d21 100644
--- a/drivers/gpu/drm/nouveau/nouveau_bo.h
+++ b/drivers/gpu/drm/nouveau/nouveau_bo.h
@@ -14,7 +14,6 @@ struct nouveau_bo {
 	struct ttm_placement placement;
 	u32 valid_domains;
 	struct ttm_place placements[3];
-	struct ttm_place busy_placements[3];
 	bool force_coherent;
 	struct ttm_bo_kmap_obj kmap;
 	struct list_head head;
-- 
2.25.1



More information about the dri-devel mailing list