dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/49] ttm mem manager refactoring.
@ 2020-07-31  4:04 Dave Airlie
  2020-07-31  4:04 ` [PATCH 01/49] drm/qxl/ttm: call ttm manager debug Dave Airlie
                   ` (49 more replies)
  0 siblings, 50 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

I started pulling on a thread, and it led me down a hole.

This series refactors the ttm ttm_mem_type_manager object into
a driver owned, allocated, subclassaed object.

It starts with two minor fixes for some bad assumptions in two drivers.

Enables a new init path, ports all the drivers to the new init
path, and cleans up the old init path.
Enables a new takedown path, ports all the drivers to the new takedown
path, and cleans up the old takedown path
Wraps all access to the memory managers in the bo_device in a wrapper
across all drivers.
Make debug callback optional
Enables driver to provide their own mem manager objects
Subclasses the objects in all drivers and makes them into driver owned object
Drops the bo_device arrays of pointers, and some unneeded links and
struct members
Cleans up one api.

I think I'd probably want to merge all this via drm-misc, so if I can collect
acks/r-b from driver maintainers that would be good.

This is also based on Chrisitan's work to remove init_mem_type, so it won't
apply until he's finished getting all of that into drm-misc.

https://cgit.freedesktop.org/~airlied/linux/log/?h=ttm-refactor-mem-manager
is the tree I've built this on top off, so it's probably going to get rebased
but the code should stay mostly the same.

I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
amdgpu soon.

Dave.


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

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

* [PATCH 01/49] drm/qxl/ttm: call ttm manager debug
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 02/49] drm/vram-helper: call the ttm manager debug function Dave Airlie
                   ` (48 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This code was poking inside a struct and assuming it was a drm_mm
at the start. Call the proper API.

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

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index 759c9d601072..59478761efe8 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -279,12 +279,10 @@ void qxl_ttm_fini(struct qxl_device *qdev)
 static int qxl_mm_dump_table(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *)m->private;
-	struct drm_mm *mm = (struct drm_mm *)node->info_ent->data;
+	struct ttm_mem_type_manager *man = (struct ttm_mem_type_manager *)node->info_ent->data;
 	struct drm_printer p = drm_seq_file_printer(m);
 
-	spin_lock(&ttm_bo_glob.lru_lock);
-	drm_mm_print(mm, &p);
-	spin_unlock(&ttm_bo_glob.lru_lock);
+	man->func->debug(man, &p);
 	return 0;
 }
 #endif
@@ -305,9 +303,9 @@ void qxl_ttm_debugfs_init(struct qxl_device *qdev)
 		qxl_mem_types_list[i].show = &qxl_mm_dump_table;
 		qxl_mem_types_list[i].driver_features = 0;
 		if (i == 0)
-			qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
+			qxl_mem_types_list[i].data = &qdev->mman.bdev.man[TTM_PL_VRAM];
 		else
-			qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV].priv;
+			qxl_mem_types_list[i].data = &qdev->mman.bdev.man[TTM_PL_PRIV];
 
 	}
 	qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
-- 
2.26.2

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

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

* [PATCH 02/49] drm/vram-helper: call the ttm manager debug function
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
  2020-07-31  4:04 ` [PATCH 01/49] drm/qxl/ttm: call ttm manager debug Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  6:43   ` Thomas Zimmermann
  2020-07-31  4:04 ` [PATCH 03/49] drm/ttm: split the mm manager init code Dave Airlie
                   ` (47 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This code was assuming there was a drm_mm here, don't do
that call the correct API.

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

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index a93a00966f3a..b6f158ab0f5a 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1075,12 +1075,10 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
-	struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv;
+	struct ttm_mem_type_manager *man = &vmm->bdev.man[TTM_PL_VRAM];
 	struct drm_printer p = drm_seq_file_printer(m);
 
-	spin_lock(&ttm_bo_glob.lru_lock);
-	drm_mm_print(mm, &p);
-	spin_unlock(&ttm_bo_glob.lru_lock);
+	man->func->debug(man, &p);
 	return 0;
 }
 
-- 
2.26.2

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

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

* [PATCH 03/49] drm/ttm: split the mm manager init code
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
  2020-07-31  4:04 ` [PATCH 01/49] drm/qxl/ttm: call ttm manager debug Dave Airlie
  2020-07-31  4:04 ` [PATCH 02/49] drm/vram-helper: call the ttm manager debug function Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  5:44   ` Sam Ravnborg
  2020-07-31  9:12   ` Christian König
  2020-07-31  4:04 ` [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager Dave Airlie
                   ` (46 subsequent siblings)
  49 siblings, 2 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This will allow the driver to control the ordering here better.

Eventually the old path will be removed.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
 include/drm/ttm/ttm_bo_api.h    |  4 ++++
 include/drm/ttm/ttm_bo_driver.h |  6 ++++++
 3 files changed, 30 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 041a0e73cd1b..a658fd584c6d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-			unsigned long p_size)
+void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
+			 struct ttm_mem_type_manager *man,
+			 unsigned long p_size)
 {
-	int ret;
-	struct ttm_mem_type_manager *man;
 	unsigned i;
 
-	BUG_ON(type >= TTM_NUM_MEM_TYPES);
-	man = &bdev->man[type];
 	BUG_ON(man->has_type);
 	man->use_io_reserve_lru = false;
 	mutex_init(&man->io_reserve_mutex);
 	spin_lock_init(&man->move_lock);
 	INIT_LIST_HEAD(&man->io_reserve_lru);
 	man->bdev = bdev;
-
-	if (type != TTM_PL_SYSTEM) {
-		ret = (*man->func->init)(man, p_size);
-		if (ret)
-			return ret;
-	}
-	man->has_type = true;
-	man->use_type = true;
 	man->size = p_size;
 
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
 		INIT_LIST_HEAD(&man->lru[i]);
 	man->move = NULL;
+}
+EXPORT_SYMBOL(ttm_bo_init_mm_base);
 
+int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
+			unsigned long p_size)
+{
+	int ret;
+	struct ttm_mem_type_manager *man;
+
+	BUG_ON(type >= TTM_NUM_MEM_TYPES);
+	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
+
+	if (type != TTM_PL_SYSTEM) {
+		ret = (*man->func->init)(man, p_size);
+		if (ret)
+			return ret;
+	}
+	ttm_bo_use_mm(man);
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_init_mm);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index a9e13b252820..0060925f507a 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
  * -ENOMEM: Not enough memory.
  * May also return driver-specified errors.
  */
+struct ttm_mem_type_manager;
+void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
+			 struct ttm_mem_type_manager *man,
+			 unsigned long p_size);
 int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
 		   unsigned long p_size);
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 7958e411269a..68e75c3b8c7a 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 	dma_resv_unlock(bo->base.resv);
 }
 
+static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
+{
+	man->has_type = true;
+	man->use_type = true;
+}
+
 /*
  * ttm_bo_util.c
  */
-- 
2.26.2

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

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

* [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (2 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 03/49] drm/ttm: split the mm manager init code Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  6:57   ` Thomas Zimmermann
  2020-07-31 13:00   ` Christian König
  2020-07-31  4:04 ` [PATCH 05/49] drm/amdgpu/ttm: init managers from the driver side Dave Airlie
                   ` (45 subsequent siblings)
  49 siblings, 2 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This lets the generic mm manager be initialised by the driver.

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

diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index facd3049c3aa..64234e5caee3 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -104,8 +104,8 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
 	}
 }
 
-static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
-			   unsigned long p_size)
+static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
+		    unsigned long p_size)
 {
 	struct ttm_range_manager *rman;
 
@@ -119,6 +119,23 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
 	return 0;
 }
 
+int ttm_bo_man_init(struct ttm_bo_device *bdev,
+		    struct ttm_mem_type_manager *man,
+		    unsigned long p_size)
+{
+	int ret;
+
+	man->func = &ttm_bo_manager_func;
+
+	ttm_bo_init_mm_base(bdev, man, p_size);
+	ret = ttm_bo_man_init_private(man, p_size);
+	if (ret)
+		return ret;
+	ttm_bo_use_mm(man);
+	return 0;
+}
+EXPORT_SYMBOL(ttm_bo_man_init);
+
 static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
 {
 	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
@@ -147,7 +164,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-	.init = ttm_bo_man_init,
+	.init = ttm_bo_man_init_private,
 	.takedown = ttm_bo_man_takedown,
 	.get_node = ttm_bo_man_get_node,
 	.put_node = ttm_bo_man_put_node,
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 68e75c3b8c7a..5c4ccefd5393 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -799,6 +799,9 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
  */
 pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 
+int ttm_bo_man_init(struct ttm_bo_device *bdev,
+		    struct ttm_mem_type_manager *man,
+		    unsigned long p_size);
 extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
 #endif
-- 
2.26.2

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

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

* [PATCH 05/49] drm/amdgpu/ttm: init managers from the driver side.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (3 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 06/49] drm/radeon: use new ttm man init path Dave Airlie
                   ` (44 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Use new init calls to unwrap manager init

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 19 ++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      | 37 +++-----------------
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h      |  4 +--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 19 ++++++----
 4 files changed, 33 insertions(+), 46 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 77fae40197ab..5f58aa2eac4a 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -76,6 +76,7 @@ static DEVICE_ATTR(mem_info_gtt_total, S_IRUGO,
 static DEVICE_ATTR(mem_info_gtt_used, S_IRUGO,
 	           amdgpu_mem_info_gtt_used_show, NULL);
 
+static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
 /**
  * amdgpu_gtt_mgr_init - init GTT manager and DRM MM
  *
@@ -84,14 +85,20 @@ static DEVICE_ATTR(mem_info_gtt_used, S_IRUGO,
  *
  * Allocate and initialize the GTT manager.
  */
-static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
-			       unsigned long p_size)
+int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
 	struct amdgpu_gtt_mgr *mgr;
 	uint64_t start, size;
 	int ret;
 
+	man->use_tt = true;
+	man->func = &amdgpu_gtt_mgr_func;
+	man->available_caching = TTM_PL_MASK_CACHING;
+	man->default_caching = TTM_PL_FLAG_CACHED;
+
+	ttm_bo_init_mm_base(&adev->mman.bdev, man, gtt_size >> PAGE_SHIFT);
+
 	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
 	if (!mgr)
 		return -ENOMEM;
@@ -100,7 +107,7 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
 	size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
 	drm_mm_init(&mgr->mm, start, size);
 	spin_lock_init(&mgr->lock);
-	atomic64_set(&mgr->available, p_size);
+	atomic64_set(&mgr->available, gtt_size >> PAGE_SHIFT);
 	man->priv = mgr;
 
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_gtt_total);
@@ -114,6 +121,7 @@ static int amdgpu_gtt_mgr_init(struct ttm_mem_type_manager *man,
 		return ret;
 	}
 
+	ttm_bo_use_mm(man);
 	return 0;
 }
 
@@ -298,8 +306,7 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
 		   amdgpu_gtt_mgr_usage(man) >> 20);
 }
 
-const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
-	.init = amdgpu_gtt_mgr_init,
+static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
 	.takedown = amdgpu_gtt_mgr_fini,
 	.get_node = amdgpu_gtt_mgr_new,
 	.put_node = amdgpu_gtt_mgr_del,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index d3e3cad4d0cb..f1bf86b8de14 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -63,43 +63,16 @@
 
 #define AMDGPU_TTM_VRAM_MAX_DW_READ	(size_t)128
 
-static int amdgpu_ttm_init_vram(struct amdgpu_device *adev)
-{
-
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
-
-	man->func = &amdgpu_vram_mgr_func;
-	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-	man->default_caching = TTM_PL_FLAG_WC;
-
-	return ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_VRAM,
-			      adev->gmc.real_vram_size >> PAGE_SHIFT);
-}
-
-static int amdgpu_ttm_init_gtt(struct amdgpu_device *adev, uint64_t gtt_size)
-{
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
-
-	man->use_tt = true;
-	man->func = &amdgpu_gtt_mgr_func;
-	man->available_caching = TTM_PL_MASK_CACHING;
-	man->default_caching = TTM_PL_FLAG_CACHED;
-
-	return ttm_bo_init_mm(&adev->mman.bdev, TTM_PL_TT,
-			      gtt_size >> PAGE_SHIFT);
-}
-
 static int amdgpu_ttm_init_on_chip(struct amdgpu_device *adev,
-				   unsigned int type,
-				   uint64_t size)
+				    unsigned int type,
+				    uint64_t size)
 {
 	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[type];
 
-	man->func = &ttm_bo_manager_func;
 	man->available_caching = TTM_PL_FLAG_UNCACHED;
 	man->default_caching = TTM_PL_FLAG_UNCACHED;
 
-	return ttm_bo_init_mm(&adev->mman.bdev, type, size);
+	return ttm_bo_man_init(&adev->mman.bdev, man, size >> PAGE_SHIFT);
 }
 
 /**
@@ -1915,7 +1888,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 	adev->mman.bdev.no_retry = true;
 
 	/* Initialize VRAM pool with all of VRAM divided into pages */
-	r = amdgpu_ttm_init_vram(adev);
+	r = amdgpu_vram_mgr_init(adev);
 	if (r) {
 		DRM_ERROR("Failed initializing VRAM heap.\n");
 		return r;
@@ -1982,7 +1955,7 @@ int amdgpu_ttm_init(struct amdgpu_device *adev)
 		gtt_size = (uint64_t)amdgpu_gtt_size << 20;
 
 	/* Initialize GTT memory pool */
-	r = amdgpu_ttm_init_gtt(adev, gtt_size);
+	r = amdgpu_gtt_mgr_init(adev, gtt_size);
 	if (r) {
 		DRM_ERROR("Failed initializing GTT heap.\n");
 		return r;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index 17c8d0d7bcc3..fb45c0a323b0 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -67,8 +67,8 @@ struct amdgpu_copy_mem {
 	unsigned long			offset;
 };
 
-extern const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
-extern const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
+int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size);
+int amdgpu_vram_mgr_init(struct amdgpu_device *adev);
 
 bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 134cc36e30c5..1bc04835c24f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -158,6 +158,8 @@ static const struct attribute *amdgpu_vram_mgr_attributes[] = {
 	NULL
 };
 
+static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
+
 /**
  * amdgpu_vram_mgr_init - init VRAM manager and DRM MM
  *
@@ -166,18 +168,23 @@ static const struct attribute *amdgpu_vram_mgr_attributes[] = {
  *
  * Allocate and initialize the VRAM manager.
  */
-static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
-				unsigned long p_size)
+int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
 	struct amdgpu_vram_mgr *mgr;
 	int ret;
 
+	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
+	man->default_caching = TTM_PL_FLAG_WC;
+
+	ttm_bo_init_mm_base(&adev->mman.bdev, man, adev->gmc.real_vram_size >> PAGE_SHIFT);
+
+	man->func = &amdgpu_vram_mgr_func;
 	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
 	if (!mgr)
 		return -ENOMEM;
 
-	drm_mm_init(&mgr->mm, 0, p_size);
+	drm_mm_init(&mgr->mm, 0, man->size);
 	spin_lock_init(&mgr->lock);
 	man->priv = mgr;
 
@@ -186,6 +193,7 @@ static int amdgpu_vram_mgr_init(struct ttm_mem_type_manager *man,
 	if (ret)
 		DRM_ERROR("Failed to register sysfs\n");
 
+	ttm_bo_use_mm(man);
 	return 0;
 }
 
@@ -587,8 +595,7 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
 		   amdgpu_vram_mgr_vis_usage(man) >> 20);
 }
 
-const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func = {
-	.init		= amdgpu_vram_mgr_init,
+static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func = {
 	.takedown	= amdgpu_vram_mgr_fini,
 	.get_node	= amdgpu_vram_mgr_new,
 	.put_node	= amdgpu_vram_mgr_del,
-- 
2.26.2

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

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

* [PATCH 06/49] drm/radeon: use new ttm man init path
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (4 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 05/49] drm/amdgpu/ttm: init managers from the driver side Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 07/49] drm/qxl/ttm: use new init path for manager Dave Airlie
                   ` (43 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Use the new common manager init path.

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

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index dbd1d2766279..a5043a5b7d89 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -70,19 +70,17 @@ static int radeon_ttm_init_vram(struct radeon_device *rdev)
 {
 	struct ttm_mem_type_manager *man = &rdev->mman.bdev.man[TTM_PL_VRAM];
 
-	man->func = &ttm_bo_manager_func;
 	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
 	man->default_caching = TTM_PL_FLAG_WC;
 
-	return ttm_bo_init_mm(&rdev->mman.bdev, TTM_PL_VRAM,
-			      rdev->mc.real_vram_size >> PAGE_SHIFT);
+	return ttm_bo_man_init(&rdev->mman.bdev, man,
+			       rdev->mc.real_vram_size >> PAGE_SHIFT);
 }
 
 static int radeon_ttm_init_gtt(struct radeon_device *rdev)
 {
 	struct ttm_mem_type_manager *man = &rdev->mman.bdev.man[TTM_PL_TT];
 
-	man->func = &ttm_bo_manager_func;
 	man->available_caching = TTM_PL_MASK_CACHING;
 	man->default_caching = TTM_PL_FLAG_CACHED;
 	man->use_tt = true;
@@ -98,7 +96,7 @@ static int radeon_ttm_init_gtt(struct radeon_device *rdev)
 	}
 #endif
 
-	return ttm_bo_init_mm(&rdev->mman.bdev, TTM_PL_TT,
+	return ttm_bo_man_init(&rdev->mman.bdev, man,
 			      rdev->mc.gtt_size >> PAGE_SHIFT);
 }
 
-- 
2.26.2

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

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

* [PATCH 07/49] drm/qxl/ttm: use new init path for manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (5 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 06/49] drm/radeon: use new ttm man init path Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 08/49] drm/vram_helper: use new ttm manager init function Dave Airlie
                   ` (42 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index 59478761efe8..ac22971cd20b 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -221,11 +221,10 @@ static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
 {
 	struct ttm_mem_type_manager *man = &qdev->mman.bdev.man[type];
 
-	man->func = &ttm_bo_manager_func;
 	man->available_caching = TTM_PL_MASK_CACHING;
 	man->default_caching = TTM_PL_FLAG_CACHED;
 
-	return ttm_bo_init_mm(&qdev->mman.bdev, type, size);
+	return ttm_bo_man_init(&qdev->mman.bdev, man, size);
 }
 
 int qxl_ttm_init(struct qxl_device *qdev)
-- 
2.26.2

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

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

* [PATCH 08/49] drm/vram_helper: use new ttm manager init function
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (6 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 07/49] drm/qxl/ttm: use new init path for manager Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 09/49] drm/nouveau: use new memory manager init paths Dave Airlie
                   ` (41 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index b6f158ab0f5a..8a5d45a55ac7 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1116,10 +1116,9 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 	if (ret)
 		return ret;
 
-	man->func = &ttm_bo_manager_func;
 	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
 	man->default_caching = TTM_PL_FLAG_WC;
-	ret = ttm_bo_init_mm(&vmm->bdev, TTM_PL_VRAM, vram_size >> PAGE_SHIFT);
+	ret = ttm_bo_man_init(&vmm->bdev, man, vram_size >> PAGE_SHIFT);
 	if (ret)
 		return ret;
 
-- 
2.26.2

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

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

* [PATCH 09/49] drm/nouveau: use new memory manager init paths
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (7 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 08/49] drm/vram_helper: use new ttm manager init function Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 10/49] drm/vmwgfx/ttm: convert vram mm init to new code paths Dave Airlie
                   ` (40 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 43 ++++++++++++---------------
 1 file changed, 19 insertions(+), 24 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index b0012021ae12..e3c57c612765 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -31,12 +31,6 @@
 
 #include <core/tegra.h>
 
-static int
-nouveau_manager_init(struct ttm_mem_type_manager *man, unsigned long psize)
-{
-	return 0;
-}
-
 static int
 nouveau_manager_fini(struct ttm_mem_type_manager *man)
 {
@@ -82,7 +76,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
-	.init = nouveau_manager_init,
 	.takedown = nouveau_manager_fini,
 	.get_node = nouveau_vram_manager_new,
 	.put_node = nouveau_manager_del,
@@ -108,7 +101,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
-	.init = nouveau_manager_init,
 	.takedown = nouveau_manager_fini,
 	.get_node = nouveau_gart_manager_new,
 	.put_node = nouveau_manager_del,
@@ -143,7 +135,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nv04_gart_manager = {
-	.init = nouveau_manager_init,
 	.takedown = nouveau_manager_fini,
 	.get_node = nv04_gart_manager_new,
 	.put_node = nouveau_manager_del,
@@ -200,27 +191,21 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 
 		man->func = &nouveau_vram_manager;
 		man->use_io_reserve_lru = true;
+		ttm_bo_init_mm_base(&drm->ttm.bdev, man,
+				    drm->gem.vram_available >> PAGE_SHIFT);
+		ttm_bo_use_mm(man);
+		return 0;
 	} else {
-		man->func = &ttm_bo_manager_func;
+		return ttm_bo_man_init(&drm->ttm.bdev, man,
+				       drm->gem.vram_available >> PAGE_SHIFT);
 	}
-
-	return ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_VRAM,
-			      drm->gem.vram_available >> PAGE_SHIFT);
 }
 
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
 	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_TT];
-
-	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
-		man->func = &nouveau_gart_manager;
-	else
-	if (!drm->agp.bridge)
-		man->func = &nv04_gart_manager;
-	else
-		man->func = &ttm_bo_manager_func;
-
+	unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
 	man->use_tt = true;
 	if (drm->agp.bridge) {
 		man->available_caching = TTM_PL_FLAG_UNCACHED |
@@ -231,8 +216,18 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 		man->default_caching = TTM_PL_FLAG_CACHED;
 	}
 
-	return ttm_bo_init_mm(&drm->ttm.bdev, TTM_PL_TT,
-			      drm->gem.gart_available >> PAGE_SHIFT);
+	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
+		man->func = &nouveau_gart_manager;
+	else if (!drm->agp.bridge)
+		man->func = &nv04_gart_manager;
+	else
+		return ttm_bo_man_init(&drm->ttm.bdev, man,
+				       size_pages);
+
+	ttm_bo_init_mm_base(&drm->ttm.bdev, man,
+			    size_pages);
+	ttm_bo_use_mm(man);
+	return 0;
 }
 
 int
-- 
2.26.2

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

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

* [PATCH 10/49] drm/vmwgfx/ttm: convert vram mm init to new code paths
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (8 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 09/49] drm/nouveau: use new memory manager init paths Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 11/49] drm/vmwgfx/ttm: switch gmrid allocator to new init paths Dave Airlie
                   ` (39 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Split out the vram thp init path vs the range manager init.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 25 +++++++++++++++++++------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  4 +---
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 12 ++++++++----
 3 files changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e43f887cafb5..e11c20150ff6 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -620,6 +620,23 @@ static int vmw_dma_masks(struct vmw_private *dev_priv)
 	return ret;
 }
 
+static int vmw_init_vram_manager(struct vmw_private *dev_priv)
+{
+	int ret;
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	ret = vmw_thp_init(dev_priv);
+#else
+	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
+
+	man->available_caching = TTM_PL_FLAG_CACHED;
+	man->default_caching = TTM_PL_FLAG_CACHED;
+
+	ret = ttm_bo_man_init(&dev_priv->bdev, man,
+			      dev_priv->vram_size >> PAGE_SHIFT);
+#endif
+	dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+	return ret;
+}
 static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 {
 	struct vmw_private *dev_priv;
@@ -864,16 +881,12 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 	 * Enable VRAM, but initially don't use it until SVGA is enabled and
 	 * unhidden.
 	 */
-	dev_priv->bdev.man[TTM_PL_VRAM].func = &vmw_thp_func;
-	dev_priv->bdev.man[TTM_PL_VRAM].available_caching = TTM_PL_FLAG_CACHED;
-	dev_priv->bdev.man[TTM_PL_VRAM].default_caching = TTM_PL_FLAG_CACHED;
-	ret = ttm_bo_init_mm(&dev_priv->bdev, TTM_PL_VRAM,
-			     (dev_priv->vram_size >> PAGE_SHIFT));
+
+	ret = vmw_init_vram_manager(dev_priv);
 	if (unlikely(ret != 0)) {
 		DRM_ERROR("Failed initializing memory manager for VRAM.\n");
 		goto out_no_vram;
 	}
-	dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
 
 	/*
 	 * "Guest Memory Regions" is an aperture like feature with
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 65c414f119c0..10b681725a53 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1520,9 +1520,7 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
 
 /* Transparent hugepage support - vmwgfx_thp.c */
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
-extern const struct ttm_mem_type_manager_func vmw_thp_func;
-#else
-#define vmw_thp_func ttm_bo_manager_func
+extern int vmw_thp_init(struct vmw_private *dev_priv);
 #endif
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index b7c816ba7166..c4a9bee932c9 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -115,18 +115,23 @@ static void vmw_thp_put_node(struct ttm_mem_type_manager *man,
 	}
 }
 
-static int vmw_thp_init(struct ttm_mem_type_manager *man,
-			unsigned long p_size)
+int vmw_thp_init(struct vmw_private *dev_priv)
 {
+	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
 	struct vmw_thp_manager *rman;
+	man->available_caching = TTM_PL_FLAG_CACHED;
+	man->default_caching = TTM_PL_FLAG_CACHED;
 
+	ttm_bo_init_mm_base(&dev_priv->bdev, man,
+			    dev_priv->vram_size >> PAGE_SHIFT);
 	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
 	if (!rman)
 		return -ENOMEM;
 
-	drm_mm_init(&rman->mm, 0, p_size);
+	drm_mm_init(&rman->mm, 0, man->size);
 	spin_lock_init(&rman->lock);
 	man->priv = rman;
+	ttm_bo_use_mm(man);
 	return 0;
 }
 
@@ -158,7 +163,6 @@ static void vmw_thp_debug(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func vmw_thp_func = {
-	.init = vmw_thp_init,
 	.takedown = vmw_thp_takedown,
 	.get_node = vmw_thp_get_node,
 	.put_node = vmw_thp_put_node,
-- 
2.26.2

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

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

* [PATCH 11/49] drm/vmwgfx/ttm: switch gmrid allocator to new init paths.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (9 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 10/49] drm/vmwgfx/ttm: convert vram mm init to new code paths Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 12/49] drm/ttm: convert system manager init to new code Dave Airlie
                   ` (38 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 17 ++++-------------
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 19 ++++++++++++-------
 3 files changed, 17 insertions(+), 21 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index e11c20150ff6..5ee5aa0aaa6a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -894,14 +894,10 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 	 *  slots as well as the bo size.
 	 */
 	dev_priv->has_gmr = true;
-	dev_priv->bdev.man[VMW_PL_GMR].func = &vmw_gmrid_manager_func;
-	dev_priv->bdev.man[VMW_PL_GMR].available_caching = TTM_PL_FLAG_CACHED;
-	dev_priv->bdev.man[VMW_PL_GMR].default_caching = TTM_PL_FLAG_CACHED;
 	/* TODO: This is most likely not correct */
-	dev_priv->bdev.man[VMW_PL_GMR].use_tt = true;
 	if (((dev_priv->capabilities & (SVGA_CAP_GMR | SVGA_CAP_GMR2)) == 0) ||
-	    refuse_dma || ttm_bo_init_mm(&dev_priv->bdev, VMW_PL_GMR,
-					 VMW_PL_GMR) != 0) {
+	    refuse_dma ||
+	    vmw_gmrid_man_init(dev_priv, VMW_PL_GMR) != 0) {
 		DRM_INFO("No GMR memory available. "
 			 "Graphics memory resources are very limited.\n");
 		dev_priv->has_gmr = false;
@@ -909,13 +905,8 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 
 	if (dev_priv->capabilities & SVGA_CAP_GBOBJECTS && !refuse_dma) {
 		dev_priv->has_mob = true;
-		dev_priv->bdev.man[VMW_PL_MOB].func = &vmw_gmrid_manager_func;
-		dev_priv->bdev.man[VMW_PL_MOB].available_caching = TTM_PL_FLAG_CACHED;
-		dev_priv->bdev.man[VMW_PL_MOB].default_caching = TTM_PL_FLAG_CACHED;
-		/* TODO: This is most likely not correct */
-		dev_priv->bdev.man[VMW_PL_MOB].use_tt = true;
-		if (ttm_bo_init_mm(&dev_priv->bdev, VMW_PL_MOB,
-				   VMW_PL_MOB) != 0) {
+
+		if (vmw_gmrid_man_init(dev_priv, VMW_PL_MOB) != 0) {
 			DRM_INFO("No MOB memory available. "
 				 "3D will be disabled.\n");
 			dev_priv->has_mob = false;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 10b681725a53..8f319dd6cdb4 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1221,7 +1221,7 @@ int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  * GMR Id manager
  */
 
-extern const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
+int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
 
 /**
  * Prime - vmwgfx_prime.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 4a76fc7114ad..e79d2c8abad2 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -94,22 +94,28 @@ static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man,
 	}
 }
 
-static int vmw_gmrid_man_init(struct ttm_mem_type_manager *man,
-			      unsigned long p_size)
+static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
+
+int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 {
-	struct vmw_private *dev_priv =
-		container_of(man->bdev, struct vmw_private, bdev);
+	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[type];
 	struct vmwgfx_gmrid_man *gman =
 		kzalloc(sizeof(*gman), GFP_KERNEL);
 
 	if (unlikely(!gman))
 		return -ENOMEM;
 
+	man->func = &vmw_gmrid_manager_func;
+	man->available_caching = TTM_PL_FLAG_CACHED;
+	man->default_caching = TTM_PL_FLAG_CACHED;
+	/* TODO: This is most likely not correct */
+	man->use_tt = true;
+	ttm_bo_init_mm_base(&dev_priv->bdev, man, 0);
 	spin_lock_init(&gman->lock);
 	gman->used_gmr_pages = 0;
 	ida_init(&gman->gmr_ida);
 
-	switch (p_size) {
+	switch (type) {
 	case VMW_PL_GMR:
 		gman->max_gmr_ids = dev_priv->max_gmr_ids;
 		gman->max_gmr_pages = dev_priv->max_gmr_pages;
@@ -143,8 +149,7 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
 	drm_printf(printer, "No debug info available for the GMR id manager\n");
 }
 
-const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
-	.init = vmw_gmrid_man_init,
+static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
 	.takedown = vmw_gmrid_man_takedown,
 	.get_node = vmw_gmrid_man_get_node,
 	.put_node = vmw_gmrid_man_put_node,
-- 
2.26.2

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

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

* [PATCH 12/49] drm/ttm: convert system manager init to new code.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (10 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 11/49] drm/vmwgfx/ttm: switch gmrid allocator to new init paths Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 12:57   ` Christian König
  2020-07-31  4:04 ` [PATCH 13/49] drm/ttm: purge old manager init path Dave Airlie
                   ` (37 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Remove the exit path, since this can't fail now.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 30 +++++++++++++++++-------------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index a658fd584c6d..476e768c5bd2 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1644,6 +1644,22 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 }
 EXPORT_SYMBOL(ttm_bo_device_release);
 
+static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
+{
+	struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_SYSTEM];
+
+	/*
+	 * Initialize the system memory buffer type.
+	 * Other types need to be driver / IOCTL initialized.
+	 */
+	man->use_tt = true;
+	man->available_caching = TTM_PL_MASK_CACHING;
+	man->default_caching = TTM_PL_FLAG_CACHED;
+
+	ttm_bo_init_mm_base(bdev, man, 0);
+	ttm_bo_use_mm(man);
+}
+
 int ttm_bo_device_init(struct ttm_bo_device *bdev,
 		       struct ttm_bo_driver *driver,
 		       struct address_space *mapping,
@@ -1664,16 +1680,7 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 
 	memset(bdev->man, 0, sizeof(bdev->man));
 
-	/*
-	 * Initialize the system memory buffer type.
-	 * Other types need to be driver / IOCTL initialized.
-	 */
-	bdev->man[TTM_PL_SYSTEM].use_tt = true;
-	bdev->man[TTM_PL_SYSTEM].available_caching = TTM_PL_MASK_CACHING;
-	bdev->man[TTM_PL_SYSTEM].default_caching = TTM_PL_FLAG_CACHED;
-	ret = ttm_bo_init_mm(bdev, TTM_PL_SYSTEM, 0);
-	if (unlikely(ret != 0))
-		goto out_no_sys;
+	ttm_bo_init_sysman(bdev);
 
 	bdev->vma_manager = vma_manager;
 	INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue);
@@ -1685,9 +1692,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 	mutex_unlock(&ttm_global_mutex);
 
 	return 0;
-out_no_sys:
-	ttm_bo_global_release();
-	return ret;
 }
 EXPORT_SYMBOL(ttm_bo_device_init);
 
-- 
2.26.2

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

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

* [PATCH 13/49] drm/ttm: purge old manager init path.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (11 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 12/49] drm/ttm: convert system manager init to new code Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 12:58   ` Christian König
  2020-07-31  4:04 ` [PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places Dave Airlie
                   ` (36 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c         | 19 -------------------
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 27 +++++++++------------------
 include/drm/ttm/ttm_bo_api.h         |  2 --
 include/drm/ttm/ttm_bo_driver.h      | 14 --------------
 4 files changed, 9 insertions(+), 53 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 476e768c5bd2..101a7910f9f7 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1523,25 +1523,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_init_mm_base);
 
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-			unsigned long p_size)
-{
-	int ret;
-	struct ttm_mem_type_manager *man;
-
-	BUG_ON(type >= TTM_NUM_MEM_TYPES);
-	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
-
-	if (type != TTM_PL_SYSTEM) {
-		ret = (*man->func->init)(man, p_size);
-		if (ret)
-			return ret;
-	}
-	ttm_bo_use_mm(man);
-	return 0;
-}
-EXPORT_SYMBOL(ttm_bo_init_mm);
-
 static void ttm_bo_global_kobj_release(struct kobject *kobj)
 {
 	struct ttm_bo_global *glob =
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 64234e5caee3..1877425abdf0 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -104,11 +104,18 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
 	}
 }
 
-static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
+static const struct ttm_mem_type_manager_func ttm_bo_manager_func;
+
+int ttm_bo_man_init(struct ttm_bo_device *bdev,
+		    struct ttm_mem_type_manager *man,
 		    unsigned long p_size)
 {
 	struct ttm_range_manager *rman;
 
+	man->func = &ttm_bo_manager_func;
+
+	ttm_bo_init_mm_base(bdev, man, p_size);
+
 	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
 	if (!rman)
 		return -ENOMEM;
@@ -116,21 +123,7 @@ static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
 	drm_mm_init(&rman->mm, 0, p_size);
 	spin_lock_init(&rman->lock);
 	man->priv = rman;
-	return 0;
-}
 
-int ttm_bo_man_init(struct ttm_bo_device *bdev,
-		    struct ttm_mem_type_manager *man,
-		    unsigned long p_size)
-{
-	int ret;
-
-	man->func = &ttm_bo_manager_func;
-
-	ttm_bo_init_mm_base(bdev, man, p_size);
-	ret = ttm_bo_man_init_private(man, p_size);
-	if (ret)
-		return ret;
 	ttm_bo_use_mm(man);
 	return 0;
 }
@@ -163,11 +156,9 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 	spin_unlock(&rman->lock);
 }
 
-const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-	.init = ttm_bo_man_init_private,
+static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
 	.takedown = ttm_bo_man_takedown,
 	.get_node = ttm_bo_man_get_node,
 	.put_node = ttm_bo_man_put_node,
 	.debug = ttm_bo_man_debug
 };
-EXPORT_SYMBOL(ttm_bo_manager_func);
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 0060925f507a..6562d1c5ac59 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -550,8 +550,6 @@ struct ttm_mem_type_manager;
 void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 			 struct ttm_mem_type_manager *man,
 			 unsigned long p_size);
-int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
-		   unsigned long p_size);
 
 /**
  * ttm_bo_clean_mm
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 5c4ccefd5393..d0f1a6cdfba7 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -48,19 +48,6 @@
 struct ttm_mem_type_manager;
 
 struct ttm_mem_type_manager_func {
-	/**
-	 * struct ttm_mem_type_manager member init
-	 *
-	 * @man: Pointer to a memory type manager.
-	 * @p_size: Implementation dependent, but typically the size of the
-	 * range to be managed in pages.
-	 *
-	 * Called to initialize a private range manager. The function is
-	 * expected to initialize the man::priv member.
-	 * Returns 0 on success, negative error code on failure.
-	 */
-	int  (*init)(struct ttm_mem_type_manager *man, unsigned long p_size);
-
 	/**
 	 * struct ttm_mem_type_manager member takedown
 	 *
@@ -802,6 +789,5 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 int ttm_bo_man_init(struct ttm_bo_device *bdev,
 		    struct ttm_mem_type_manager *man,
 		    unsigned long p_size);
-extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
 #endif
-- 
2.26.2

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

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

* [PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (12 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 13/49] drm/ttm: purge old manager init path Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:04   ` Christian König
  2020-07-31  4:04 ` [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths Dave Airlie
                   ` (35 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This makes it easier to cleanup things

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

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 101a7910f9f7..84e399395e4f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -763,13 +763,12 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
 }
 
 static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
-			       uint32_t mem_type,
+			       struct ttm_mem_type_manager *man,
 			       const struct ttm_place *place,
 			       struct ttm_operation_ctx *ctx,
 			       struct ww_acquire_ctx *ticket)
 {
 	struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
-	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 	bool locked = false;
 	unsigned i;
 	int ret;
@@ -918,7 +917,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
 			break;
 		if (unlikely(ret != -ENOSPC))
 			return ret;
-		ret = ttm_mem_evict_first(bdev, mem->mem_type, place, ctx,
+		ret = ttm_mem_evict_first(bdev, man, place, ctx,
 					  ticket);
 		if (unlikely(ret != 0))
 			return ret;
@@ -1403,14 +1402,13 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 EXPORT_SYMBOL(ttm_bo_create);
 
 static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-				   unsigned mem_type)
+				   struct ttm_mem_type_manager *man)
 {
 	struct ttm_operation_ctx ctx = {
 		.interruptible = false,
 		.no_wait_gpu = false,
 		.flags = TTM_OPT_FLAG_FORCE_ALLOC
 	};
-	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
 	struct ttm_bo_global *glob = &ttm_bo_glob;
 	struct dma_fence *fence;
 	int ret;
@@ -1424,7 +1422,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
 		while (!list_empty(&man->lru[i])) {
 			spin_unlock(&glob->lru_lock);
-			ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx,
+			ret = ttm_mem_evict_first(bdev, man, NULL, &ctx,
 						  NULL);
 			if (ret)
 				return ret;
@@ -1469,7 +1467,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 
 	ret = 0;
 	if (mem_type > 0) {
-		ret = ttm_bo_force_list_clean(bdev, mem_type);
+		ret = ttm_bo_force_list_clean(bdev, man);
 		if (ret) {
 			pr_err("Cleanup eviction failed\n");
 			return ret;
@@ -1499,7 +1497,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 		return 0;
 	}
 
-	return ttm_bo_force_list_clean(bdev, mem_type);
+	return ttm_bo_force_list_clean(bdev, man);
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-- 
2.26.2

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

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

* [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (13 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:07   ` Christian König
  2020-07-31  4:04 ` [PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path Dave Airlie
                   ` (34 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 84e399395e4f..f584e5e94383 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1462,8 +1462,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 		return ret;
 	}
 
-	man->use_type = false;
-	man->has_type = false;
+	ttm_bo_disable_mm(man);
 
 	ret = 0;
 	if (mem_type > 0) {
@@ -1476,8 +1475,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 		ret = (*man->func->takedown)(man);
 	}
 
-	dma_fence_put(man->move);
-	man->move = NULL;
+	ttm_bo_man_cleanup(man);
 
 	return ret;
 }
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index d0f1a6cdfba7..92bb54cce633 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -671,6 +671,18 @@ static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
 	man->use_type = true;
 }
 
+static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
+{
+	man->has_type = false;
+	man->use_type = false;
+}
+
+static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
+{
+	dma_fence_put(man->move);
+	man->move = NULL;
+}
+
 /*
  * ttm_bo_util.c
  */
-- 
2.26.2

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

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

* [PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (14 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:09   ` Christian König
  2020-07-31  4:04 ` [PATCH 17/49] drm/amdgpu/ttm: " Dave Airlie
                   ` (33 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Allow the takedown path callback to be optional as well.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c         |  8 +++++---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 21 +++++++++++++++++++--
 include/drm/ttm/ttm_bo_driver.h      |  5 ++++-
 3 files changed, 28 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f584e5e94383..f0f0f3101bd1 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1401,8 +1401,8 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_create);
 
-static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
-				   struct ttm_mem_type_manager *man)
+int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
+			    struct ttm_mem_type_manager *man)
 {
 	struct ttm_operation_ctx ctx = {
 		.interruptible = false,
@@ -1444,6 +1444,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 
 	return 0;
 }
+EXPORT_SYMBOL(ttm_bo_force_list_clean);
 
 int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 {
@@ -1472,7 +1473,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 			return ret;
 		}
 
-		ret = (*man->func->takedown)(man);
+		if (man->func->takedown)
+			ret = (*man->func->takedown)(man);
 	}
 
 	ttm_bo_man_cleanup(man);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 1877425abdf0..1127868274b3 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -129,7 +129,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_man_init);
 
-static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
+static int ttm_bo_man_takedown_private(struct ttm_mem_type_manager *man)
 {
 	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
 	struct drm_mm *mm = &rman->mm;
@@ -146,6 +146,23 @@ static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
 	return -EBUSY;
 }
 
+int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
+			struct ttm_mem_type_manager *man)
+{
+	int ret;
+
+	ttm_bo_disable_mm(man);
+
+	ret = ttm_bo_force_list_clean(bdev, man);
+	if (ret)
+		return ret;
+
+	ttm_bo_man_takedown_private(man);
+	ttm_bo_man_cleanup(man);
+	return 0;
+}
+EXPORT_SYMBOL(ttm_bo_man_takedown);
+
 static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 			     struct drm_printer *printer)
 {
@@ -157,7 +174,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-	.takedown = ttm_bo_man_takedown,
+	.takedown = ttm_bo_man_takedown_private,
 	.get_node = ttm_bo_man_get_node,
 	.put_node = ttm_bo_man_put_node,
 	.debug = ttm_bo_man_debug
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 92bb54cce633..2ef33b407167 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -683,6 +683,8 @@ static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
 	man->move = NULL;
 }
 
+int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
+			    struct ttm_mem_type_manager *man);
 /*
  * ttm_bo_util.c
  */
@@ -801,5 +803,6 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 int ttm_bo_man_init(struct ttm_bo_device *bdev,
 		    struct ttm_mem_type_manager *man,
 		    unsigned long p_size);
-
+int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
+			struct ttm_mem_type_manager *man);
 #endif
-- 
2.26.2

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

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

* [PATCH 17/49] drm/amdgpu/ttm: use new takedown path
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (15 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:08   ` Christian König
  2020-07-31  4:04 ` [PATCH 18/49] drm/vmwgfx: takedown vram manager Dave Airlie
                   ` (32 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 15 +++++++++++----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      | 10 +++++-----
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h      |  2 ++
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 15 +++++++++++----
 4 files changed, 29 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 5f58aa2eac4a..f4c870b2f348 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -133,10 +133,18 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
  * Destroy and free the GTT manager, returns -EBUSY if ranges are still
  * allocated inside it.
  */
-static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
+void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
 	struct amdgpu_gtt_mgr *mgr = man->priv;
+	int ret;
+
+	ttm_bo_disable_mm(man);
+
+	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
+	if (ret)
+		return;
+
 	spin_lock(&mgr->lock);
 	drm_mm_takedown(&mgr->mm);
 	spin_unlock(&mgr->lock);
@@ -146,7 +154,7 @@ static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
 	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_total);
 	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_used);
 
-	return 0;
+	ttm_bo_man_cleanup(man);
 }
 
 /**
@@ -307,7 +315,6 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
-	.takedown = amdgpu_gtt_mgr_fini,
 	.get_node = amdgpu_gtt_mgr_new,
 	.put_node = amdgpu_gtt_mgr_del,
 	.debug = amdgpu_gtt_mgr_debug
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index f1bf86b8de14..b1452df8fce9 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -2012,11 +2012,11 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 		iounmap(adev->mman.aper_base_kaddr);
 	adev->mman.aper_base_kaddr = NULL;
 
-	ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM);
-	ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT);
-	ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GDS);
-	ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GWS);
-	ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_OA);
+	amdgpu_vram_mgr_fini(adev);
+	amdgpu_gtt_mgr_fini(adev);
+	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GDS]);
+	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GWS]);
+	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_OA]);
 	ttm_bo_device_release(&adev->mman.bdev);
 	adev->mman.initialized = false;
 	DRM_INFO("amdgpu: ttm finalized\n");
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
index fb45c0a323b0..c01fdb3f0458 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
@@ -68,7 +68,9 @@ struct amdgpu_copy_mem {
 };
 
 int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size);
+void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev);
 int amdgpu_vram_mgr_init(struct amdgpu_device *adev);
+void amdgpu_vram_mgr_fini(struct amdgpu_device *adev);
 
 bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 1bc04835c24f..cc45be8ccb0f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -205,10 +205,17 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
  * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
  * allocated inside it.
  */
-static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
+void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
+	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
 	struct amdgpu_vram_mgr *mgr = man->priv;
+	int ret;
+
+	ttm_bo_disable_mm(man);
+
+	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
+	if (ret)
+		return;
 
 	spin_lock(&mgr->lock);
 	drm_mm_takedown(&mgr->mm);
@@ -216,7 +223,8 @@ static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
 	kfree(mgr);
 	man->priv = NULL;
 	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
-	return 0;
+
+	ttm_bo_man_cleanup(man);
 }
 
 /**
@@ -596,7 +604,6 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func = {
-	.takedown	= amdgpu_vram_mgr_fini,
 	.get_node	= amdgpu_vram_mgr_new,
 	.put_node	= amdgpu_vram_mgr_del,
 	.debug		= amdgpu_vram_mgr_debug
-- 
2.26.2

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

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

* [PATCH 18/49] drm/vmwgfx: takedown vram manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (16 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 17/49] drm/amdgpu/ttm: " Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 19/49] drm/vram_helper: call explicit mm takedown Dave Airlie
                   ` (31 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Don't bother returning EBUSY, nobody cares enough,
if the driver has a problem, it should deal with it.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c | 13 ++++++++++++-
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 23 +++++++++++++----------
 3 files changed, 26 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 5ee5aa0aaa6a..7d65f9121cd7 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -637,6 +637,17 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
 	dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
 	return ret;
 }
+
+static void vmw_takedown_vram_manager(struct vmw_private *dev_priv)
+{
+#ifdef CONFIG_TRANSPARENT_HUGEPAGE
+	vmw_thp_takedown(dev_priv);
+#else
+	ttm_bo_man_takedown(&dev_priv->bdev,
+			    &dev_priv->bdev.man[TTM_PL_VRAM]);
+#endif
+}
+
 static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 {
 	struct vmw_private *dev_priv;
@@ -986,7 +997,7 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 		(void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_MOB);
 	if (dev_priv->has_gmr)
 		(void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
-	(void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM);
+	vmw_takedown_vram_manager(dev_priv);
 out_no_vram:
 	(void)ttm_bo_device_release(&dev_priv->bdev);
 out_no_bdev:
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index 8f319dd6cdb4..b20056fdd042 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1521,6 +1521,7 @@ vm_fault_t vmw_bo_vm_huge_fault(struct vm_fault *vmf,
 /* Transparent hugepage support - vmwgfx_thp.c */
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 extern int vmw_thp_init(struct vmw_private *dev_priv);
+void vmw_thp_takedown(struct vmw_private *dev_priv);
 #endif
 
 /**
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index c4a9bee932c9..3591a93dad37 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -135,21 +135,25 @@ int vmw_thp_init(struct vmw_private *dev_priv)
 	return 0;
 }
 
-static int vmw_thp_takedown(struct ttm_mem_type_manager *man)
+void vmw_thp_takedown(struct vmw_private *dev_priv)
 {
+	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
 	struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
 	struct drm_mm *mm = &rman->mm;
+	int ret;
+
+	ttm_bo_disable_mm(man);
 
+	ret = ttm_bo_force_list_clean(&dev_priv->bdev, man);
+	if (ret)
+		return;
 	spin_lock(&rman->lock);
-	if (drm_mm_clean(mm)) {
-		drm_mm_takedown(mm);
-		spin_unlock(&rman->lock);
-		kfree(rman);
-		man->priv = NULL;
-		return 0;
-	}
+	drm_mm_clean(mm);
+	drm_mm_takedown(mm);
 	spin_unlock(&rman->lock);
-	return -EBUSY;
+	kfree(rman);
+	man->priv = NULL;
+	ttm_bo_man_cleanup(man);
 }
 
 static void vmw_thp_debug(struct ttm_mem_type_manager *man,
@@ -163,7 +167,6 @@ static void vmw_thp_debug(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func vmw_thp_func = {
-	.takedown = vmw_thp_takedown,
 	.get_node = vmw_thp_get_node,
 	.put_node = vmw_thp_put_node,
 	.debug = vmw_thp_debug
-- 
2.26.2

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

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

* [PATCH 19/49] drm/vram_helper: call explicit mm takedown
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (17 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 18/49] drm/vmwgfx: takedown vram manager Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 20/49] drm/nouveau: use new cleanup paths Dave Airlie
                   ` (30 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 8a5d45a55ac7..c6cc90d42f56 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1127,6 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 
 static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
 {
+	ttm_bo_man_takedown(&vmm->bdev, &vmm->bdev.man[TTM_PL_VRAM]);
 	ttm_bo_device_release(&vmm->bdev);
 }
 
-- 
2.26.2

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

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

* [PATCH 20/49] drm/nouveau: use new cleanup paths
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (18 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 19/49] drm/vram_helper: call explicit mm takedown Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 21/49] drm/radeon/ttm: use new takedown paths Dave Airlie
                   ` (29 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 41 ++++++++++++++++++++-------
 1 file changed, 30 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index e3c57c612765..2ccfdf203c52 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -31,12 +31,6 @@
 
 #include <core/tegra.h>
 
-static int
-nouveau_manager_fini(struct ttm_mem_type_manager *man)
-{
-	return 0;
-}
-
 static void
 nouveau_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *reg)
 {
@@ -76,7 +70,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
-	.takedown = nouveau_manager_fini,
 	.get_node = nouveau_vram_manager_new,
 	.put_node = nouveau_manager_del,
 	.debug = nouveau_manager_debug,
@@ -101,7 +94,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
-	.takedown = nouveau_manager_fini,
 	.get_node = nouveau_gart_manager_new,
 	.put_node = nouveau_manager_del,
 	.debug = nouveau_manager_debug
@@ -135,7 +127,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
 }
 
 const struct ttm_mem_type_manager_func nv04_gart_manager = {
-	.takedown = nouveau_manager_fini,
 	.get_node = nv04_gart_manager_new,
 	.put_node = nouveau_manager_del,
 	.debug = nouveau_manager_debug
@@ -201,6 +192,19 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 	}
 }
 
+static void
+nouveau_ttm_fini_vram(struct nouveau_drm *drm)
+{
+	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_VRAM];
+
+	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
+		ttm_bo_disable_mm(man);
+		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
+		ttm_bo_man_cleanup(man);
+	} else
+		ttm_bo_man_takedown(&drm->ttm.bdev, man);
+}
+
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
@@ -230,6 +234,21 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 	return 0;
 }
 
+static void
+nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
+{
+	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_TT];
+
+	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
+	    drm->agp.bridge)
+		ttm_bo_man_takedown(&drm->ttm.bdev, man);
+	else {
+		ttm_bo_disable_mm(man);
+		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
+		ttm_bo_man_cleanup(man);
+	}
+}
+
 int
 nouveau_ttm_init(struct nouveau_drm *drm)
 {
@@ -319,8 +338,8 @@ nouveau_ttm_fini(struct nouveau_drm *drm)
 {
 	struct nvkm_device *device = nvxx_device(&drm->client.device);
 
-	ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_VRAM);
-	ttm_bo_clean_mm(&drm->ttm.bdev, TTM_PL_TT);
+	nouveau_ttm_fini_vram(drm);
+	nouveau_ttm_fini_gtt(drm);
 
 	ttm_bo_device_release(&drm->ttm.bdev);
 
-- 
2.26.2

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

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

* [PATCH 21/49] drm/radeon/ttm: use new takedown paths
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (19 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 20/49] drm/nouveau: use new cleanup paths Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:10   ` Christian König
  2020-07-31  4:04 ` [PATCH 22/49] drm/qxl/ttm: use new takedown path Dave Airlie
                   ` (28 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index a5043a5b7d89..e65297b4b678 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -826,8 +826,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
 		}
 		radeon_bo_unref(&rdev->stolen_vga_memory);
 	}
-	ttm_bo_clean_mm(&rdev->mman.bdev, TTM_PL_VRAM);
-	ttm_bo_clean_mm(&rdev->mman.bdev, TTM_PL_TT);
+	ttm_bo_man_takedown(&rdev->mman.bdev, &rdev->mman.bdev.man[TTM_PL_VRAM]);
+	ttm_bo_man_takedown(&rdev->mman.bdev, &rdev->mman.bdev.man[TTM_PL_TT]);
 	ttm_bo_device_release(&rdev->mman.bdev);
 	radeon_gart_fini(rdev);
 	rdev->mman.initialized = false;
-- 
2.26.2

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

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

* [PATCH 22/49] drm/qxl/ttm: use new takedown path
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (20 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 21/49] drm/radeon/ttm: use new takedown paths Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 23/49] drm/vmwgfx: fix gmrid takedown paths to new interface Dave Airlie
                   ` (27 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index ac22971cd20b..acc4497887a6 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -266,8 +266,8 @@ int qxl_ttm_init(struct qxl_device *qdev)
 
 void qxl_ttm_fini(struct qxl_device *qdev)
 {
-	ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_VRAM);
-	ttm_bo_clean_mm(&qdev->mman.bdev, TTM_PL_PRIV);
+	ttm_bo_man_takedown(&qdev->mman.bdev, &qdev->mman.bdev.man[TTM_PL_VRAM]);
+	ttm_bo_man_takedown(&qdev->mman.bdev, &qdev->mman.bdev.man[TTM_PL_PRIV]);
 	ttm_bo_device_release(&qdev->mman.bdev);
 	DRM_INFO("qxl: ttm finalized\n");
 }
-- 
2.26.2

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

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

* [PATCH 23/49] drm/vmwgfx: fix gmrid takedown paths to new interface
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (21 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 22/49] drm/qxl/ttm: use new takedown path Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 24/49] drm/ttm: remove range manager legacy takedown path Dave Airlie
                   ` (26 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 10 +++++-----
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.h           |  1 +
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 11 ++++++++---
 3 files changed, 14 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 7d65f9121cd7..b27f8b3699cf 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -994,9 +994,9 @@ static int vmw_driver_load(struct drm_device *dev, unsigned long chipset)
 	vmw_kms_close(dev_priv);
 out_no_kms:
 	if (dev_priv->has_mob)
-		(void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_MOB);
+		vmw_gmrid_man_takedown(dev_priv, VMW_PL_MOB);
 	if (dev_priv->has_gmr)
-		(void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
+		vmw_gmrid_man_takedown(dev_priv, VMW_PL_GMR);
 	vmw_takedown_vram_manager(dev_priv);
 out_no_vram:
 	(void)ttm_bo_device_release(&dev_priv->bdev);
@@ -1045,12 +1045,12 @@ static void vmw_driver_unload(struct drm_device *dev)
 	vmw_overlay_close(dev_priv);
 
 	if (dev_priv->has_gmr)
-		(void)ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_GMR);
-	(void)ttm_bo_clean_mm(&dev_priv->bdev, TTM_PL_VRAM);
+		vmw_gmrid_man_takedown(dev_priv, VMW_PL_GMR);
+	vmw_takedown_vram_manager(dev_priv);
 
 	vmw_release_device_early(dev_priv);
 	if (dev_priv->has_mob)
-		(void) ttm_bo_clean_mm(&dev_priv->bdev, VMW_PL_MOB);
+		vmw_gmrid_man_takedown(dev_priv, VMW_PL_MOB);
 	(void) ttm_bo_device_release(&dev_priv->bdev);
 	drm_vma_offset_manager_destroy(&dev_priv->vma_manager);
 	vmw_release_device_late(dev_priv);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
index b20056fdd042..d37af7929189 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
@@ -1222,6 +1222,7 @@ int vmw_overlay_num_free_overlays(struct vmw_private *dev_priv);
  */
 
 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type);
+void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type);
 
 /**
  * Prime - vmwgfx_prime.c
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index e79d2c8abad2..2522927b75da 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -131,16 +131,22 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 	return 0;
 }
 
-static int vmw_gmrid_man_takedown(struct ttm_mem_type_manager *man)
+void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 {
+	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[type];
 	struct vmwgfx_gmrid_man *gman =
 		(struct vmwgfx_gmrid_man *)man->priv;
 
+	ttm_bo_disable_mm(man);
+
+	ttm_bo_force_list_clean(&dev_priv->bdev, man);
+
 	if (gman) {
 		ida_destroy(&gman->gmr_ida);
 		kfree(gman);
 	}
-	return 0;
+
+	ttm_bo_man_cleanup(man);
 }
 
 static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
@@ -150,7 +156,6 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
-	.takedown = vmw_gmrid_man_takedown,
 	.get_node = vmw_gmrid_man_get_node,
 	.put_node = vmw_gmrid_man_put_node,
 	.debug = vmw_gmrid_man_debug
-- 
2.26.2

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

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

* [PATCH 24/49] drm/ttm: remove range manager legacy takedown path
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (22 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 23/49] drm/vmwgfx: fix gmrid takedown paths to new interface Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:11   ` Christian König
  2020-07-31  4:04 ` [PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only Dave Airlie
                   ` (25 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Now no drivers have been converted, drop the non-driver path.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 28 +++++++++-------------------
 1 file changed, 9 insertions(+), 19 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 1127868274b3..f60a9a5d429d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -129,26 +129,11 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_man_init);
 
-static int ttm_bo_man_takedown_private(struct ttm_mem_type_manager *man)
-{
-	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
-	struct drm_mm *mm = &rman->mm;
-
-	spin_lock(&rman->lock);
-	if (drm_mm_clean(mm)) {
-		drm_mm_takedown(mm);
-		spin_unlock(&rman->lock);
-		kfree(rman);
-		man->priv = NULL;
-		return 0;
-	}
-	spin_unlock(&rman->lock);
-	return -EBUSY;
-}
-
 int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
 			struct ttm_mem_type_manager *man)
 {
+	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+	struct drm_mm *mm = &rman->mm;
 	int ret;
 
 	ttm_bo_disable_mm(man);
@@ -157,7 +142,13 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
 	if (ret)
 		return ret;
 
-	ttm_bo_man_takedown_private(man);
+	spin_lock(&rman->lock);
+	drm_mm_clean(mm);
+	drm_mm_takedown(mm);
+	spin_unlock(&rman->lock);
+	kfree(rman);
+	man->priv = NULL;
+
 	ttm_bo_man_cleanup(man);
 	return 0;
 }
@@ -174,7 +165,6 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 }
 
 static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
-	.takedown = ttm_bo_man_takedown_private,
 	.get_node = ttm_bo_man_get_node,
 	.put_node = ttm_bo_man_put_node,
 	.debug = ttm_bo_man_debug
-- 
2.26.2

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

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

* [PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (23 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 24/49] drm/ttm: remove range manager legacy takedown path Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31 13:19   ` Christian König
  2020-07-31  4:04 ` [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev Dave Airlie
                   ` (24 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

drivers should all be cleaning up their memory managers
themselves now, so let the core just clean the system one up.

Remove the legacy cleaning interface.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c    | 55 +++------------------------------
 include/drm/ttm/ttm_bo_api.h    | 28 -----------------
 include/drm/ttm/ttm_bo_driver.h | 10 ------
 3 files changed, 4 insertions(+), 89 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f0f0f3101bd1..07c653374f15 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1446,43 +1446,6 @@ int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
 }
 EXPORT_SYMBOL(ttm_bo_force_list_clean);
 
-int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
-{
-	struct ttm_mem_type_manager *man;
-	int ret = -EINVAL;
-
-	if (mem_type >= TTM_NUM_MEM_TYPES) {
-		pr_err("Illegal memory type %d\n", mem_type);
-		return ret;
-	}
-	man = &bdev->man[mem_type];
-
-	if (!man->has_type) {
-		pr_err("Trying to take down uninitialized memory manager type %u\n",
-		       mem_type);
-		return ret;
-	}
-
-	ttm_bo_disable_mm(man);
-
-	ret = 0;
-	if (mem_type > 0) {
-		ret = ttm_bo_force_list_clean(bdev, man);
-		if (ret) {
-			pr_err("Cleanup eviction failed\n");
-			return ret;
-		}
-
-		if (man->func->takedown)
-			ret = (*man->func->takedown)(man);
-	}
-
-	ttm_bo_man_cleanup(man);
-
-	return ret;
-}
-EXPORT_SYMBOL(ttm_bo_clean_mm);
-
 int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 {
 	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
@@ -1585,21 +1548,11 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 {
 	struct ttm_bo_global *glob = &ttm_bo_glob;
 	int ret = 0;
-	unsigned i = TTM_NUM_MEM_TYPES;
+	unsigned i;
 	struct ttm_mem_type_manager *man;
 
-	while (i--) {
-		man = &bdev->man[i];
-		if (man->has_type) {
-			man->use_type = false;
-			if ((i != TTM_PL_SYSTEM) && ttm_bo_clean_mm(bdev, i)) {
-				ret = -EBUSY;
-				pr_err("DRM memory manager type %d is not clean\n",
-				       i);
-			}
-			man->has_type = false;
-		}
-	}
+	man = &bdev->man[TTM_PL_SYSTEM];
+	ttm_bo_disable_mm(man);
 
 	mutex_lock(&ttm_global_mutex);
 	list_del(&bdev->device_list);
@@ -1612,7 +1565,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 
 	spin_lock(&glob->lru_lock);
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
-		if (list_empty(&bdev->man[0].lru[0]))
+		if (list_empty(&man->lru[0]))
 			pr_debug("Swap list %d was clean\n", i);
 	spin_unlock(&glob->lru_lock);
 
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 6562d1c5ac59..27dde1371376 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -551,34 +551,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 			 struct ttm_mem_type_manager *man,
 			 unsigned long p_size);
 
-/**
- * ttm_bo_clean_mm
- *
- * @bdev: Pointer to a ttm_bo_device struct.
- * @mem_type: The memory type.
- *
- * Take down a manager for a given memory type after first walking
- * the LRU list to evict any buffers left alive.
- *
- * Normally, this function is part of lastclose() or unload(), and at that
- * point there shouldn't be any buffers left created by user-space, since
- * there should've been removed by the file descriptor release() method.
- * However, before this function is run, make sure to signal all sync objects,
- * and verify that the delayed delete queue is empty. The driver must also
- * make sure that there are no NO_EVICT buffers present in this memory type
- * when the call is made.
- *
- * If this function is part of a VT switch, the caller must make sure that
- * there are no appications currently validating buffers before this
- * function is called. The caller can do that by first taking the
- * struct ttm_bo_device::ttm_lock in write mode.
- *
- * Returns:
- * -EINVAL: invalid or uninitialized memory type.
- * -EBUSY: There are still buffers left in this memory type.
- */
-int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
-
 /**
  * ttm_bo_evict_mm
  *
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 2ef33b407167..9d066529ca61 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -48,16 +48,6 @@
 struct ttm_mem_type_manager;
 
 struct ttm_mem_type_manager_func {
-	/**
-	 * struct ttm_mem_type_manager member takedown
-	 *
-	 * @man: Pointer to a memory type manager.
-	 *
-	 * Called to undo the setup done in init. All allocated resources
-	 * should be freed.
-	 */
-	int  (*takedown)(struct ttm_mem_type_manager *man);
-
 	/**
 	 * struct ttm_mem_type_manager member get_node
 	 *
-- 
2.26.2

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

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

* [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (24 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  7:14   ` Thomas Zimmermann
  2020-07-31 13:23   ` Christian König
  2020-07-31  4:04 ` [PATCH 27/49] drm/amdgfx/ttm: use wrapper to get ttm memory managers Dave Airlie
                   ` (23 subsequent siblings)
  49 siblings, 2 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This will allow different abstractions later.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c      | 34 +++++++++++++++----------------
 drivers/gpu/drm/ttm/ttm_bo_util.c | 20 +++++++++---------
 drivers/gpu/drm/ttm/ttm_bo_vm.c   |  2 +-
 include/drm/ttm/ttm_bo_driver.h   |  6 ++++++
 4 files changed, 34 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 07c653374f15..7c6389ea067f 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -80,7 +80,7 @@ static inline int ttm_mem_type_from_place(const struct ttm_place *place,
 static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p,
 			       int mem_type)
 {
-	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
 
 	drm_printf(p, "    has_type: %d\n", man->has_type);
 	drm_printf(p, "    use_type: %d\n", man->use_type);
@@ -156,7 +156,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
 	if (mem->placement & TTM_PL_FLAG_NO_EVICT)
 		return;
 
-	man = &bdev->man[mem->mem_type];
+	man = ttm_manager_type(bdev, mem->mem_type);
 	list_add_tail(&bo->lru, &man->lru[bo->priority]);
 
 	if (man->use_tt && bo->ttm &&
@@ -231,7 +231,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
 		dma_resv_assert_held(pos->first->base.resv);
 		dma_resv_assert_held(pos->last->base.resv);
 
-		man = &pos->first->bdev->man[TTM_PL_TT];
+		man = ttm_manager_type(pos->first->bdev, TTM_PL_TT);
 		list_bulk_move_tail(&man->lru[i], &pos->first->lru,
 				    &pos->last->lru);
 	}
@@ -246,7 +246,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
 		dma_resv_assert_held(pos->first->base.resv);
 		dma_resv_assert_held(pos->last->base.resv);
 
-		man = &pos->first->bdev->man[TTM_PL_VRAM];
+		man = ttm_manager_type(pos->first->bdev, TTM_PL_VRAM);
 		list_bulk_move_tail(&man->lru[i], &pos->first->lru,
 				    &pos->last->lru);
 	}
@@ -272,8 +272,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 				  struct ttm_operation_ctx *ctx)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_mem_type_manager *old_man = &bdev->man[bo->mem.mem_type];
-	struct ttm_mem_type_manager *new_man = &bdev->man[mem->mem_type];
+	struct ttm_mem_type_manager *old_man = ttm_manager_type(bdev, bo->mem.mem_type);
+	struct ttm_mem_type_manager *new_man = ttm_manager_type(bdev, mem->mem_type);
 	int ret;
 
 	ret = ttm_mem_io_lock(old_man, true);
@@ -338,7 +338,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
 	return 0;
 
 out_err:
-	new_man = &bdev->man[bo->mem.mem_type];
+	new_man = ttm_manager_type(bdev, bo->mem.mem_type);
 	if (!new_man->use_tt) {
 		ttm_tt_destroy(bo->ttm);
 		bo->ttm = NULL;
@@ -550,7 +550,7 @@ static void ttm_bo_release(struct kref *kref)
 	struct ttm_buffer_object *bo =
 	    container_of(kref, struct ttm_buffer_object, kref);
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, bo->mem.mem_type);
 	size_t acc_size = bo->acc_size;
 	int ret;
 
@@ -838,7 +838,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
 			  const struct ttm_place *place,
 			  struct ttm_mem_reg *mem)
 {
-	struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
 
 	mem->mm_node = NULL;
 	if (!man->func || !man->func->get_node)
@@ -849,7 +849,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
 
 void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
 {
-	struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
 
 	if (!man->func || !man->func->put_node)
 		return;
@@ -906,7 +906,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
 				  struct ttm_operation_ctx *ctx)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
 	struct ww_acquire_ctx *ticket;
 	int ret;
 
@@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
 	if (ret)
 		return ret;
 
-	man = &bdev->man[mem_type];
+	man = ttm_manager_type(bdev, mem_type);
 	if (!man->has_type || !man->use_type)
 		return -EBUSY;
 
@@ -1059,7 +1059,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
 		if (unlikely(ret))
 			goto error;
 
-		man = &bdev->man[mem->mem_type];
+		man = ttm_manager_type(bdev, mem->mem_type);
 		ret = ttm_bo_add_move_fence(bo, man, mem, ctx->no_wait_gpu);
 		if (unlikely(ret)) {
 			ttm_bo_mem_put(bo, mem);
@@ -1448,7 +1448,7 @@ EXPORT_SYMBOL(ttm_bo_force_list_clean);
 
 int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 {
-	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
 
 	if (mem_type == 0 || mem_type >= TTM_NUM_MEM_TYPES) {
 		pr_err("Illegal memory manager memory type %u\n", mem_type);
@@ -1551,7 +1551,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 	unsigned i;
 	struct ttm_mem_type_manager *man;
 
-	man = &bdev->man[TTM_PL_SYSTEM];
+	man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
 	ttm_bo_disable_mm(man);
 
 	mutex_lock(&ttm_global_mutex);
@@ -1578,7 +1578,7 @@ EXPORT_SYMBOL(ttm_bo_device_release);
 
 static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
 {
-	struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_SYSTEM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
 
 	/*
 	 * Initialize the system memory buffer type.
@@ -1642,7 +1642,7 @@ void ttm_bo_unmap_virtual_locked(struct ttm_buffer_object *bo)
 void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, bo->mem.mem_type);
 
 	ttm_mem_io_lock(man, false);
 	ttm_bo_unmap_virtual_locked(bo);
diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
index 1f502be0b646..879c8ded0cd8 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_util.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
@@ -129,7 +129,7 @@ static int ttm_mem_io_evict(struct ttm_mem_type_manager *man)
 int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
 		       struct ttm_mem_reg *mem)
 {
-	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
 	int ret;
 
 	if (mem->bus.io_reserved_count++)
@@ -162,7 +162,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
 
 int ttm_mem_io_reserve_vm(struct ttm_buffer_object *bo)
 {
-	struct ttm_mem_type_manager *man = &bo->bdev->man[bo->mem.mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, bo->mem.mem_type);
 	struct ttm_mem_reg *mem = &bo->mem;
 	int ret;
 
@@ -195,7 +195,7 @@ static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev,
 			       struct ttm_mem_reg *mem,
 			       void **virtual)
 {
-	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
 	int ret;
 	void *addr;
 
@@ -232,7 +232,7 @@ static void ttm_mem_reg_iounmap(struct ttm_bo_device *bdev,
 {
 	struct ttm_mem_type_manager *man;
 
-	man = &bdev->man[mem->mem_type];
+	man = ttm_manager_type(bdev, mem->mem_type);
 
 	if (virtual && mem->bus.addr == NULL)
 		iounmap(virtual);
@@ -303,7 +303,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
 		       struct ttm_mem_reg *new_mem)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
 	struct ttm_tt *ttm = bo->ttm;
 	struct ttm_mem_reg *old_mem = &bo->mem;
 	struct ttm_mem_reg old_copy = *old_mem;
@@ -571,7 +571,7 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo,
 		struct ttm_bo_kmap_obj *map)
 {
 	struct ttm_mem_type_manager *man =
-		&bo->bdev->man[bo->mem.mem_type];
+		ttm_manager_type(bo->bdev, bo->mem.mem_type);
 	unsigned long offset, size;
 	int ret;
 
@@ -601,7 +601,7 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
 {
 	struct ttm_buffer_object *bo = map->bo;
 	struct ttm_mem_type_manager *man =
-		&bo->bdev->man[bo->mem.mem_type];
+		ttm_manager_type(bo->bdev, bo->mem.mem_type);
 
 	if (!map->virtual)
 		return;
@@ -634,7 +634,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
 			      struct ttm_mem_reg *new_mem)
 {
 	struct ttm_bo_device *bdev = bo->bdev;
-	struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
 	struct ttm_mem_reg *old_mem = &bo->mem;
 	int ret;
 	struct ttm_buffer_object *ghost_obj;
@@ -697,8 +697,8 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
 	struct ttm_bo_device *bdev = bo->bdev;
 	struct ttm_mem_reg *old_mem = &bo->mem;
 
-	struct ttm_mem_type_manager *from = &bdev->man[old_mem->mem_type];
-	struct ttm_mem_type_manager *to = &bdev->man[new_mem->mem_type];
+	struct ttm_mem_type_manager *from = ttm_manager_type(bdev, old_mem->mem_type);
+	struct ttm_mem_type_manager *to = ttm_manager_type(bdev, new_mem->mem_type);
 
 	int ret;
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
index 468a0eb9e632..5ae679184eb5 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
@@ -282,7 +282,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
 	vm_fault_t ret = VM_FAULT_NOPAGE;
 	unsigned long address = vmf->address;
 	struct ttm_mem_type_manager *man =
-		&bdev->man[bo->mem.mem_type];
+		ttm_manager_type(bdev, bo->mem.mem_type);
 
 	/*
 	 * Refuse to fault imported pages. This should be handled
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 9d066529ca61..ec25451b503f 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -444,6 +444,12 @@ struct ttm_bo_device {
 	bool no_retry;
 };
 
+static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
+							    int mem_type)
+{
+	return &bdev->man[mem_type];
+}
+
 /**
  * struct ttm_lru_bulk_move_pos
  *
-- 
2.26.2

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

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

* [PATCH 27/49] drm/amdgfx/ttm: use wrapper to get ttm memory managers
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (25 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:04 ` [PATCH 28/49] drm/vram-helper: use wrapper to access " Dave Airlie
                   ` (22 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c   |  3 ++-
 drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c       |  6 +++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_device.c   |  5 ++---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 12 +++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c      | 21 +++++++++++---------
 drivers/gpu/drm/amd/amdgpu/amdgpu_object.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      | 12 +++++------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 12 +++++------
 8 files changed, 39 insertions(+), 36 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
index 1b865fed74ca..e24f421e5553 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_amdkfd.c
@@ -517,8 +517,9 @@ int amdgpu_amdkfd_get_dmabuf_info(struct kgd_dev *kgd, int dma_buf_fd,
 uint64_t amdgpu_amdkfd_get_vram_usage(struct kgd_dev *kgd)
 {
 	struct amdgpu_device *adev = (struct amdgpu_device *)kgd;
+	struct ttm_mem_type_manager *vram_man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 
-	return amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+	return amdgpu_vram_mgr_usage(vram_man);
 }
 
 uint64_t amdgpu_amdkfd_get_hive_id(struct kgd_dev *kgd)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
index a512ccbc4dea..9829640e1769 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_cs.c
@@ -299,7 +299,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,
 {
 	s64 time_us, increment_us;
 	u64 free_vram, total_vram, used_vram;
-
+	struct ttm_mem_type_manager *vram_man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 	/* Allow a maximum of 200 accumulated ms. This is basically per-IB
 	 * throttling.
 	 *
@@ -316,7 +316,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,
 	}
 
 	total_vram = adev->gmc.real_vram_size - atomic64_read(&adev->vram_pin_size);
-	used_vram = amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+	used_vram = amdgpu_vram_mgr_usage(vram_man);
 	free_vram = used_vram >= total_vram ? 0 : total_vram - used_vram;
 
 	spin_lock(&adev->mm_stats.lock);
@@ -363,7 +363,7 @@ static void amdgpu_cs_get_threshold_for_moves(struct amdgpu_device *adev,
 	if (!amdgpu_gmc_vram_full_visible(&adev->gmc)) {
 		u64 total_vis_vram = adev->gmc.visible_vram_size;
 		u64 used_vis_vram =
-			amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+		  amdgpu_vram_mgr_vis_usage(vram_man);
 
 		if (used_vis_vram < total_vis_vram) {
 			u64 free_vis_vram = total_vis_vram - used_vis_vram;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
index aa5b54e5a1d7..d551e7c5e69d 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_device.c
@@ -3880,7 +3880,7 @@ static int amdgpu_device_reset_sriov(struct amdgpu_device *adev,
 
 	amdgpu_virt_init_data_exchange(adev);
 	/* we need recover gart prior to run SMC/CP/SDMA resume */
-	amdgpu_gtt_mgr_recover(&adev->mman.bdev.man[TTM_PL_TT]);
+	amdgpu_gtt_mgr_recover(ttm_manager_type(&adev->mman.bdev, TTM_PL_TT));
 
 	r = amdgpu_device_fw_loading(adev);
 	if (r)
@@ -4079,8 +4079,7 @@ static int amdgpu_do_asic_reset(struct amdgpu_hive_info *hive,
 					amdgpu_inc_vram_lost(tmp_adev);
 				}
 
-				r = amdgpu_gtt_mgr_recover(
-					&tmp_adev->mman.bdev.man[TTM_PL_TT]);
+				r = amdgpu_gtt_mgr_recover(ttm_manager_type(&tmp_adev->mman.bdev, TTM_PL_TT));
 				if (r)
 					goto out;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index f4c870b2f348..0b0d09d19b4f 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -48,9 +48,9 @@ static ssize_t amdgpu_mem_info_gtt_total_show(struct device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = ddev->dev_private;
-
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 	return snprintf(buf, PAGE_SIZE, "%llu\n",
-			(adev->mman.bdev.man[TTM_PL_TT].size) * PAGE_SIZE);
+			man->size * PAGE_SIZE);
 }
 
 /**
@@ -66,9 +66,9 @@ static ssize_t amdgpu_mem_info_gtt_used_show(struct device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = ddev->dev_private;
-
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 	return snprintf(buf, PAGE_SIZE, "%llu\n",
-			amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]));
+			amdgpu_gtt_mgr_usage(man));
 }
 
 static DEVICE_ATTR(mem_info_gtt_total, S_IRUGO,
@@ -87,7 +87,7 @@ static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
  */
 int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 {
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 	struct amdgpu_gtt_mgr *mgr;
 	uint64_t start, size;
 	int ret;
@@ -135,7 +135,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
  */
 void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 {
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 	struct amdgpu_gtt_mgr *mgr = man->priv;
 	int ret;
 
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
index a8c47aecd342..594687cc99ac 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_kms.c
@@ -594,13 +594,13 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 		ui64 = atomic64_read(&adev->num_vram_cpu_page_faults);
 		return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
 	case AMDGPU_INFO_VRAM_USAGE:
-		ui64 = amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+		ui64 = amdgpu_vram_mgr_usage(ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM));
 		return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
 	case AMDGPU_INFO_VIS_VRAM_USAGE:
-		ui64 = amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+		ui64 = amdgpu_vram_mgr_vis_usage(ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM));
 		return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
 	case AMDGPU_INFO_GTT_USAGE:
-		ui64 = amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]);
+		ui64 = amdgpu_gtt_mgr_usage(ttm_manager_type(&adev->mman.bdev, TTM_PL_TT));
 		return copy_to_user(out, &ui64, min(size, 8u)) ? -EFAULT : 0;
 	case AMDGPU_INFO_GDS_CONFIG: {
 		struct drm_amdgpu_info_gds gds_info;
@@ -623,7 +623,7 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			min(adev->gmc.visible_vram_size -
 			    atomic64_read(&adev->visible_pin_size),
 			    vram_gtt.vram_size);
-		vram_gtt.gtt_size = adev->mman.bdev.man[TTM_PL_TT].size;
+		vram_gtt.gtt_size = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT)->size;
 		vram_gtt.gtt_size *= PAGE_SIZE;
 		vram_gtt.gtt_size -= atomic64_read(&adev->gart_pin_size);
 		return copy_to_user(out, &vram_gtt,
@@ -631,14 +631,17 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 	}
 	case AMDGPU_INFO_MEMORY: {
 		struct drm_amdgpu_memory_info mem;
-
+		struct ttm_mem_type_manager *vram_man =
+			ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
+		struct ttm_mem_type_manager *gtt_man =
+			ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 		memset(&mem, 0, sizeof(mem));
 		mem.vram.total_heap_size = adev->gmc.real_vram_size;
 		mem.vram.usable_heap_size = adev->gmc.real_vram_size -
 			atomic64_read(&adev->vram_pin_size) -
 			AMDGPU_VM_RESERVED_VRAM;
 		mem.vram.heap_usage =
-			amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+			amdgpu_vram_mgr_usage(vram_man);
 		mem.vram.max_allocation = mem.vram.usable_heap_size * 3 / 4;
 
 		mem.cpu_accessible_vram.total_heap_size =
@@ -648,16 +651,16 @@ static int amdgpu_info_ioctl(struct drm_device *dev, void *data, struct drm_file
 			    atomic64_read(&adev->visible_pin_size),
 			    mem.vram.usable_heap_size);
 		mem.cpu_accessible_vram.heap_usage =
-			amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]);
+			amdgpu_vram_mgr_vis_usage(vram_man);
 		mem.cpu_accessible_vram.max_allocation =
 			mem.cpu_accessible_vram.usable_heap_size * 3 / 4;
 
-		mem.gtt.total_heap_size = adev->mman.bdev.man[TTM_PL_TT].size;
+		mem.gtt.total_heap_size = gtt_man->size;
 		mem.gtt.total_heap_size *= PAGE_SIZE;
 		mem.gtt.usable_heap_size = mem.gtt.total_heap_size -
 			atomic64_read(&adev->gart_pin_size);
 		mem.gtt.heap_usage =
-			amdgpu_gtt_mgr_usage(&adev->mman.bdev.man[TTM_PL_TT]);
+			amdgpu_gtt_mgr_usage(gtt_man);
 		mem.gtt.max_allocation = mem.gtt.usable_heap_size * 3 / 4;
 
 		return copy_to_user(out, &mem,
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
index 5ac7b5561475..ced418cba2f7 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_object.c
@@ -449,7 +449,7 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 	 * allow fall back to GTT
 	 */
 	if (domain & AMDGPU_GEM_DOMAIN_GTT) {
-		man = &adev->mman.bdev.man[TTM_PL_TT];
+		man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
 
 		if (size < (man->size << PAGE_SHIFT))
 			return true;
@@ -458,7 +458,7 @@ static bool amdgpu_bo_validate_size(struct amdgpu_device *adev,
 	}
 
 	if (domain & AMDGPU_GEM_DOMAIN_VRAM) {
-		man = &adev->mman.bdev.man[TTM_PL_VRAM];
+		man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 
 		if (size < (man->size << PAGE_SHIFT))
 			return true;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index b1452df8fce9..4beec1c4e037 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -67,7 +67,7 @@ static int amdgpu_ttm_init_on_chip(struct amdgpu_device *adev,
 				    unsigned int type,
 				    uint64_t size)
 {
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, type);
 
 	man->available_caching = TTM_PL_FLAG_UNCACHED;
 	man->default_caching = TTM_PL_FLAG_UNCACHED;
@@ -2014,9 +2014,9 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 
 	amdgpu_vram_mgr_fini(adev);
 	amdgpu_gtt_mgr_fini(adev);
-	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GDS]);
-	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GWS]);
-	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_OA]);
+	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_GDS));
+	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_GWS));
+	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_OA));
 	ttm_bo_device_release(&adev->mman.bdev);
 	adev->mman.initialized = false;
 	DRM_INFO("amdgpu: ttm finalized\n");
@@ -2033,7 +2033,7 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
  */
 void amdgpu_ttm_set_buffer_funcs_status(struct amdgpu_device *adev, bool enable)
 {
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 	uint64_t size;
 	int r;
 
@@ -2255,7 +2255,7 @@ static int amdgpu_mm_dump_table(struct seq_file *m, void *data)
 	unsigned ttm_pl = (uintptr_t)node->info_ent->data;
 	struct drm_device *dev = node->minor->dev;
 	struct amdgpu_device *adev = dev->dev_private;
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[ttm_pl];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, ttm_pl);
 	struct drm_printer p = drm_seq_file_printer(m);
 
 	man->func->debug(man, &p);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index cc45be8ccb0f..d33a750e07a8 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -82,9 +82,9 @@ static ssize_t amdgpu_mem_info_vram_used_show(struct device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = ddev->dev_private;
-
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 	return snprintf(buf, PAGE_SIZE, "%llu\n",
-		amdgpu_vram_mgr_usage(&adev->mman.bdev.man[TTM_PL_VRAM]));
+			amdgpu_vram_mgr_usage(man));
 }
 
 /**
@@ -100,9 +100,9 @@ static ssize_t amdgpu_mem_info_vis_vram_used_show(struct device *dev,
 {
 	struct drm_device *ddev = dev_get_drvdata(dev);
 	struct amdgpu_device *adev = ddev->dev_private;
-
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 	return snprintf(buf, PAGE_SIZE, "%llu\n",
-		amdgpu_vram_mgr_vis_usage(&adev->mman.bdev.man[TTM_PL_VRAM]));
+			amdgpu_vram_mgr_vis_usage(man));
 }
 
 static ssize_t amdgpu_mem_info_vram_vendor(struct device *dev,
@@ -170,7 +170,7 @@ static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
  */
 int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 {
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 	struct amdgpu_vram_mgr *mgr;
 	int ret;
 
@@ -207,7 +207,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
  */
 void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 {
-	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
 	struct amdgpu_vram_mgr *mgr = man->priv;
 	int ret;
 
-- 
2.26.2

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

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

* [PATCH 28/49] drm/vram-helper: use wrapper to access memory managers
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (26 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 27/49] drm/amdgfx/ttm: use wrapper to get ttm memory managers Dave Airlie
@ 2020-07-31  4:04 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 29/49] drm/nouveau/ttm: " Dave Airlie
                   ` (21 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:04 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index c6cc90d42f56..08fbfa32540a 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1075,7 +1075,7 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
 {
 	struct drm_info_node *node = (struct drm_info_node *) m->private;
 	struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
-	struct ttm_mem_type_manager *man = &vmm->bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
 	struct drm_printer p = drm_seq_file_printer(m);
 
 	man->func->debug(man, &p);
@@ -1103,7 +1103,7 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init);
 static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 			    uint64_t vram_base, size_t vram_size)
 {
-	struct ttm_mem_type_manager *man = &vmm->bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
 	int ret;
 
 	vmm->vram_base = vram_base;
@@ -1127,7 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 
 static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
 {
-	ttm_bo_man_takedown(&vmm->bdev, &vmm->bdev.man[TTM_PL_VRAM]);
+	ttm_bo_man_takedown(&vmm->bdev, ttm_manager_type(&vmm->bdev, TTM_PL_VRAM));
 	ttm_bo_device_release(&vmm->bdev);
 }
 
-- 
2.26.2

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

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

* [PATCH 29/49] drm/nouveau/ttm: use wrapper to access memory managers
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (27 preceding siblings ...)
  2020-07-31  4:04 ` [PATCH 28/49] drm/vram-helper: use wrapper to access " Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 30/49] drm/qxl/ttm: use wrapper to access memory manager Dave Airlie
                   ` (20 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 2ccfdf203c52..ed651d7679fe 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -165,7 +165,7 @@ nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
 static int
 nouveau_ttm_init_vram(struct nouveau_drm *drm)
 {
-	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
 	struct nvif_mmu *mmu = &drm->client.mmu;
 
 	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
@@ -195,7 +195,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 static void
 nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 {
-	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
 
 	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
 		ttm_bo_disable_mm(man);
@@ -208,7 +208,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
-	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_TT];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_TT);
 	unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
 	man->use_tt = true;
 	if (drm->agp.bridge) {
@@ -237,7 +237,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 static void
 nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 {
-	struct ttm_mem_type_manager *man = &drm->ttm.bdev.man[TTM_PL_TT];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_TT);
 
 	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
 	    drm->agp.bridge)
-- 
2.26.2

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

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

* [PATCH 30/49] drm/qxl/ttm: use wrapper to access memory manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (28 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 29/49] drm/nouveau/ttm: " Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 31/49] drm/radeon/ttm: " Dave Airlie
                   ` (19 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

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, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index acc4497887a6..9aea35a66e25 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -219,7 +219,7 @@ static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
 				 unsigned int type,
 				 uint64_t size)
 {
-	struct ttm_mem_type_manager *man = &qdev->mman.bdev.man[type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&qdev->mman.bdev, type);
 
 	man->available_caching = TTM_PL_MASK_CACHING;
 	man->default_caching = TTM_PL_FLAG_CACHED;
@@ -266,8 +266,8 @@ int qxl_ttm_init(struct qxl_device *qdev)
 
 void qxl_ttm_fini(struct qxl_device *qdev)
 {
-	ttm_bo_man_takedown(&qdev->mman.bdev, &qdev->mman.bdev.man[TTM_PL_VRAM]);
-	ttm_bo_man_takedown(&qdev->mman.bdev, &qdev->mman.bdev.man[TTM_PL_PRIV]);
+	ttm_bo_man_takedown(&qdev->mman.bdev, ttm_manager_type(&qdev->mman.bdev, TTM_PL_VRAM));
+	ttm_bo_man_takedown(&qdev->mman.bdev, ttm_manager_type(&qdev->mman.bdev, TTM_PL_PRIV));
 	ttm_bo_device_release(&qdev->mman.bdev);
 	DRM_INFO("qxl: ttm finalized\n");
 }
@@ -302,9 +302,9 @@ void qxl_ttm_debugfs_init(struct qxl_device *qdev)
 		qxl_mem_types_list[i].show = &qxl_mm_dump_table;
 		qxl_mem_types_list[i].driver_features = 0;
 		if (i == 0)
-			qxl_mem_types_list[i].data = &qdev->mman.bdev.man[TTM_PL_VRAM];
+			qxl_mem_types_list[i].data = ttm_manager_type(&qdev->mman.bdev, TTM_PL_VRAM);
 		else
-			qxl_mem_types_list[i].data = &qdev->mman.bdev.man[TTM_PL_PRIV];
+			qxl_mem_types_list[i].data = ttm_manager_type(&qdev->mman.bdev, TTM_PL_PRIV);
 
 	}
 	qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
-- 
2.26.2

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

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

* [PATCH 31/49] drm/radeon/ttm: use wrapper to access memory manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (29 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 30/49] drm/qxl/ttm: use wrapper to access memory manager Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 32/49] drm/vmwgfx/ttm: " Dave Airlie
                   ` (18 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/radeon/radeon_gem.c |  2 +-
 drivers/gpu/drm/radeon/radeon_ttm.c | 13 ++++++-------
 2 files changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c
index 44157ada9b0e..3ec028dba739 100644
--- a/drivers/gpu/drm/radeon/radeon_gem.c
+++ b/drivers/gpu/drm/radeon/radeon_gem.c
@@ -226,7 +226,7 @@ int radeon_gem_info_ioctl(struct drm_device *dev, void *data,
 	struct drm_radeon_gem_info *args = data;
 	struct ttm_mem_type_manager *man;
 
-	man = &rdev->mman.bdev.man[TTM_PL_VRAM];
+	man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
 
 	args->vram_size = (u64)man->size << PAGE_SHIFT;
 	args->vram_visible = rdev->mc.visible_vram_size;
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index e65297b4b678..3849d0e852bc 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -68,7 +68,7 @@ struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
 
 static int radeon_ttm_init_vram(struct radeon_device *rdev)
 {
-	struct ttm_mem_type_manager *man = &rdev->mman.bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
 
 	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
 	man->default_caching = TTM_PL_FLAG_WC;
@@ -79,7 +79,7 @@ static int radeon_ttm_init_vram(struct radeon_device *rdev)
 
 static int radeon_ttm_init_gtt(struct radeon_device *rdev)
 {
-	struct ttm_mem_type_manager *man = &rdev->mman.bdev.man[TTM_PL_TT];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_TT);
 
 	man->available_caching = TTM_PL_MASK_CACHING;
 	man->default_caching = TTM_PL_FLAG_CACHED;
@@ -379,7 +379,6 @@ static int radeon_bo_move(struct ttm_buffer_object *bo, bool evict,
 
 static int radeon_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem)
 {
-	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
 	struct radeon_device *rdev = radeon_get_rdev(bdev);
 
 	mem->bus.addr = NULL;
@@ -826,8 +825,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
 		}
 		radeon_bo_unref(&rdev->stolen_vga_memory);
 	}
-	ttm_bo_man_takedown(&rdev->mman.bdev, &rdev->mman.bdev.man[TTM_PL_VRAM]);
-	ttm_bo_man_takedown(&rdev->mman.bdev, &rdev->mman.bdev.man[TTM_PL_TT]);
+	ttm_bo_man_takedown(&rdev->mman.bdev, ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM));
+	ttm_bo_man_takedown(&rdev->mman.bdev, ttm_manager_type(&rdev->mman.bdev, TTM_PL_TT));
 	ttm_bo_device_release(&rdev->mman.bdev);
 	radeon_gart_fini(rdev);
 	rdev->mman.initialized = false;
@@ -843,7 +842,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
 	if (!rdev->mman.initialized)
 		return;
 
-	man = &rdev->mman.bdev.man[TTM_PL_VRAM];
+	man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
 	/* this just adjusts TTM size idea, which sets lpfn to the correct value */
 	man->size = size >> PAGE_SHIFT;
 }
@@ -897,7 +896,7 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
 	unsigned ttm_pl = *(int*)node->info_ent->data;
 	struct drm_device *dev = node->minor->dev;
 	struct radeon_device *rdev = dev->dev_private;
-	struct ttm_mem_type_manager *man = &rdev->mman.bdev.man[ttm_pl];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, ttm_pl);
 	struct drm_printer p = drm_seq_file_printer(m);
 
 	man->func->debug(man, &p);
-- 
2.26.2

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

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

* [PATCH 32/49] drm/vmwgfx/ttm: use wrapper to access memory manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (30 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 31/49] drm/radeon/ttm: " Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 33/49] drm/ttm: rename manager variable to make sure wrapper is used Dave Airlie
                   ` (17 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 21 ++++++++++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           |  4 ++--
 3 files changed, 17 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index b27f8b3699cf..dff6990ff9ed 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -634,7 +634,7 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
 	ret = ttm_bo_man_init(&dev_priv->bdev, man,
 			      dev_priv->vram_size >> PAGE_SHIFT);
 #endif
-	dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+	ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM)->use_type = false;
 	return ret;
 }
 
@@ -644,7 +644,7 @@ static void vmw_takedown_vram_manager(struct vmw_private *dev_priv)
 	vmw_thp_takedown(dev_priv);
 #else
 	ttm_bo_man_takedown(&dev_priv->bdev,
-			    &dev_priv->bdev.man[TTM_PL_VRAM]);
+			    ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM));
 #endif
 }
 
@@ -1192,10 +1192,12 @@ static void vmw_master_drop(struct drm_device *dev,
  */
 static void __vmw_svga_enable(struct vmw_private *dev_priv)
 {
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
+
 	spin_lock(&dev_priv->svga_lock);
-	if (!dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
+	if (!man->use_type) {
 		vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE);
-		dev_priv->bdev.man[TTM_PL_VRAM].use_type = true;
+		man->use_type = true;
 	}
 	spin_unlock(&dev_priv->svga_lock);
 }
@@ -1221,9 +1223,11 @@ void vmw_svga_enable(struct vmw_private *dev_priv)
  */
 static void __vmw_svga_disable(struct vmw_private *dev_priv)
 {
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
+
 	spin_lock(&dev_priv->svga_lock);
-	if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
-		dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+	if (man->use_type) {
+		man->use_type = false;
 		vmw_write(dev_priv, SVGA_REG_ENABLE,
 			  SVGA_REG_ENABLE_HIDE |
 			  SVGA_REG_ENABLE_ENABLE);
@@ -1240,6 +1244,7 @@ static void __vmw_svga_disable(struct vmw_private *dev_priv)
  */
 void vmw_svga_disable(struct vmw_private *dev_priv)
 {
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
 	/*
 	 * Disabling SVGA will turn off device modesetting capabilities, so
 	 * notify KMS about that so that it doesn't cache atomic state that
@@ -1255,8 +1260,8 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
 	vmw_kms_lost_device(dev_priv->dev);
 	ttm_write_lock(&dev_priv->reservation_sem, false);
 	spin_lock(&dev_priv->svga_lock);
-	if (dev_priv->bdev.man[TTM_PL_VRAM].use_type) {
-		dev_priv->bdev.man[TTM_PL_VRAM].use_type = false;
+	if (man->use_type) {
+		man->use_type = false;
 		spin_unlock(&dev_priv->svga_lock);
 		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
 			DRM_ERROR("Failed evicting VRAM buffers.\n");
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 2522927b75da..3fa809b5e3bd 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -98,7 +98,7 @@ static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
 
 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 {
-	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
 	struct vmwgfx_gmrid_man *gman =
 		kzalloc(sizeof(*gman), GFP_KERNEL);
 
@@ -133,7 +133,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 
 void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 {
-	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[type];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
 	struct vmwgfx_gmrid_man *gman =
 		(struct vmwgfx_gmrid_man *)man->priv;
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index 3591a93dad37..0dd619c9d207 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -117,7 +117,7 @@ static void vmw_thp_put_node(struct ttm_mem_type_manager *man,
 
 int vmw_thp_init(struct vmw_private *dev_priv)
 {
-	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
 	struct vmw_thp_manager *rman;
 	man->available_caching = TTM_PL_FLAG_CACHED;
 	man->default_caching = TTM_PL_FLAG_CACHED;
@@ -137,7 +137,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
 
 void vmw_thp_takedown(struct vmw_private *dev_priv)
 {
-	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
+	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
 	struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
 	struct drm_mm *mm = &rman->mm;
 	int ret;
-- 
2.26.2

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

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

* [PATCH 33/49] drm/ttm: rename manager variable to make sure wrapper is used.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (31 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 32/49] drm/vmwgfx/ttm: " Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 34/49] drm/ttm: make manager debug function optional Dave Airlie
                   ` (16 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Other users of this should notice this change and switch to wrapper.

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

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 7c6389ea067f..92de8a6d7647 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1610,7 +1610,7 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 
 	bdev->driver = driver;
 
-	memset(bdev->man, 0, sizeof(bdev->man));
+	memset(bdev->man_priv, 0, sizeof(bdev->man_priv));
 
 	ttm_bo_init_sysman(bdev);
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index ec25451b503f..419b088253cf 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -415,7 +415,10 @@ struct ttm_bo_device {
 	 */
 	struct list_head device_list;
 	struct ttm_bo_driver *driver;
-	struct ttm_mem_type_manager man[TTM_NUM_MEM_TYPES];
+	/*
+	 * access via ttm_manager_type.
+	 */
+	struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
 
 	/*
 	 * Protected by internal locks.
@@ -447,7 +450,7 @@ struct ttm_bo_device {
 static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
 							    int mem_type)
 {
-	return &bdev->man[mem_type];
+	return &bdev->man_priv[mem_type];
 }
 
 /**
-- 
2.26.2

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

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

* [PATCH 34/49] drm/ttm: make manager debug function optional
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (32 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 33/49] drm/ttm: rename manager variable to make sure wrapper is used Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  9:46   ` daniel
  2020-07-31 13:24   ` Christian König
  2020-07-31  4:05 ` [PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback Dave Airlie
                   ` (15 subsequent siblings)
  49 siblings, 2 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 92de8a6d7647..1e8fda1c9b3a 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -88,7 +88,7 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p
 	drm_printf(p, "    size: %llu\n", man->size);
 	drm_printf(p, "    available_caching: 0x%08X\n", man->available_caching);
 	drm_printf(p, "    default_caching: 0x%08X\n", man->default_caching);
-	if (mem_type != TTM_PL_SYSTEM)
+	if (mem_type != TTM_PL_SYSTEM && man->func->debug)
 		(*man->func->debug)(man, p);
 }
 
-- 
2.26.2

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

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

* [PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (33 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 34/49] drm/ttm: make manager debug function optional Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 13:25   ` Christian König
  2020-07-31  4:05 ` [PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless " Dave Airlie
                   ` (14 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index ed651d7679fe..1b9d9362132d 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -37,12 +37,6 @@ nouveau_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *reg)
 	nouveau_mem_del(reg);
 }
 
-static void
-nouveau_manager_debug(struct ttm_mem_type_manager *man,
-		      struct drm_printer *printer)
-{
-}
-
 static int
 nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 			 struct ttm_buffer_object *bo,
@@ -72,7 +66,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
 	.get_node = nouveau_vram_manager_new,
 	.put_node = nouveau_manager_del,
-	.debug = nouveau_manager_debug,
 };
 
 static int
@@ -96,7 +89,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
 	.get_node = nouveau_gart_manager_new,
 	.put_node = nouveau_manager_del,
-	.debug = nouveau_manager_debug
 };
 
 static int
@@ -129,7 +121,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
 const struct ttm_mem_type_manager_func nv04_gart_manager = {
 	.get_node = nv04_gart_manager_new,
 	.put_node = nouveau_manager_del,
-	.debug = nouveau_manager_debug
 };
 
 int
-- 
2.26.2

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

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

* [PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless ttm debug callback
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (34 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 13:26   ` Christian König
  2020-07-31  4:05 ` [PATCH 37/49] drm/ttm: allow drivers to provide their own manager subclasses Dave Airlie
                   ` (13 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

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

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 3fa809b5e3bd..2db99f0449b0 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -149,14 +149,7 @@ void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 	ttm_bo_man_cleanup(man);
 }
 
-static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
-				struct drm_printer *printer)
-{
-	drm_printf(printer, "No debug info available for the GMR id manager\n");
-}
-
 static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
 	.get_node = vmw_gmrid_man_get_node,
 	.put_node = vmw_gmrid_man_put_node,
-	.debug = vmw_gmrid_man_debug
 };
-- 
2.26.2

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

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

* [PATCH 37/49] drm/ttm: allow drivers to provide their own manager subclasses
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (35 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless " Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs Dave Airlie
                   ` (12 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This will get removed eventually and all drivers will use this.

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

diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 419b088253cf..723171fd94da 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -419,7 +419,7 @@ struct ttm_bo_device {
 	 * access via ttm_manager_type.
 	 */
 	struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
-
+	struct ttm_mem_type_manager *man_drv[TTM_NUM_MEM_TYPES];
 	/*
 	 * Protected by internal locks.
 	 */
@@ -450,9 +450,18 @@ struct ttm_bo_device {
 static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
 							    int mem_type)
 {
+	if (bdev->man_drv[mem_type])
+		return bdev->man_drv[mem_type];
 	return &bdev->man_priv[mem_type];
 }
 
+static inline void ttm_set_driver_manager(struct ttm_bo_device *bdev,
+					  int type,
+					  struct ttm_mem_type_manager *manager)
+{
+	bdev->man_drv[type] = manager;
+}
+
 /**
  * struct ttm_lru_bulk_move_pos
  *
-- 
2.26.2

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

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

* [PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (36 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 37/49] drm/ttm: allow drivers to provide their own manager subclasses Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 13:29   ` Christian König
  2020-07-31  4:05 ` [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args Dave Airlie
                   ` (11 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 35 +++++++++++--------
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 36 +++++++++++++-------
 2 files changed, 44 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 0b0d09d19b4f..83d88ee73468 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -25,11 +25,17 @@
 #include "amdgpu.h"
 
 struct amdgpu_gtt_mgr {
+	struct ttm_mem_type_manager manager;
 	struct drm_mm mm;
 	spinlock_t lock;
 	atomic64_t available;
 };
 
+static inline struct amdgpu_gtt_mgr *to_gtt_mgr(struct ttm_mem_type_manager *man)
+{
+	return container_of(man, struct amdgpu_gtt_mgr, manager);
+}
+
 struct amdgpu_gtt_node {
 	struct drm_mm_node node;
 	struct ttm_buffer_object *tbo;
@@ -87,11 +93,16 @@ static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
  */
 int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
+	struct ttm_mem_type_manager *man;
 	struct amdgpu_gtt_mgr *mgr;
 	uint64_t start, size;
 	int ret;
 
+	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
+	if (!mgr)
+		return -ENOMEM;
+
+	man = &mgr->manager;
 	man->use_tt = true;
 	man->func = &amdgpu_gtt_mgr_func;
 	man->available_caching = TTM_PL_MASK_CACHING;
@@ -99,16 +110,11 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 
 	ttm_bo_init_mm_base(&adev->mman.bdev, man, gtt_size >> PAGE_SHIFT);
 
-	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-	if (!mgr)
-		return -ENOMEM;
-
 	start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
 	size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
 	drm_mm_init(&mgr->mm, start, size);
 	spin_lock_init(&mgr->lock);
 	atomic64_set(&mgr->available, gtt_size >> PAGE_SHIFT);
-	man->priv = mgr;
 
 	ret = device_create_file(adev->dev, &dev_attr_mem_info_gtt_total);
 	if (ret) {
@@ -121,6 +127,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 		return ret;
 	}
 
+	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager);
 	ttm_bo_use_mm(man);
 	return 0;
 }
@@ -136,7 +143,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 {
 	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
-	struct amdgpu_gtt_mgr *mgr = man->priv;
+	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 	int ret;
 
 	ttm_bo_disable_mm(man);
@@ -148,13 +155,13 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 	spin_lock(&mgr->lock);
 	drm_mm_takedown(&mgr->mm);
 	spin_unlock(&mgr->lock);
-	kfree(mgr);
-	man->priv = NULL;
 
 	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_total);
 	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_used);
 
 	ttm_bo_man_cleanup(man);
+	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, NULL);
+	kfree(mgr);
 }
 
 /**
@@ -184,7 +191,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager *man,
 			      const struct ttm_place *place,
 			      struct ttm_mem_reg *mem)
 {
-	struct amdgpu_gtt_mgr *mgr = man->priv;
+	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 	struct amdgpu_gtt_node *node;
 	int r;
 
@@ -245,7 +252,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager *man,
 static void amdgpu_gtt_mgr_del(struct ttm_mem_type_manager *man,
 			       struct ttm_mem_reg *mem)
 {
-	struct amdgpu_gtt_mgr *mgr = man->priv;
+	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 	struct amdgpu_gtt_node *node = mem->mm_node;
 
 	if (node) {
@@ -267,7 +274,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_mem_type_manager *man,
  */
 uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man)
 {
-	struct amdgpu_gtt_mgr *mgr = man->priv;
+	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 	s64 result = man->size - atomic64_read(&mgr->available);
 
 	return (result > 0 ? result : 0) * PAGE_SIZE;
@@ -275,7 +282,7 @@ uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man)
 
 int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man)
 {
-	struct amdgpu_gtt_mgr *mgr = man->priv;
+	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 	struct amdgpu_gtt_node *node;
 	struct drm_mm_node *mm_node;
 	int r = 0;
@@ -303,7 +310,7 @@ int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man)
 static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
 				 struct drm_printer *printer)
 {
-	struct amdgpu_gtt_mgr *mgr = man->priv;
+	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 
 	spin_lock(&mgr->lock);
 	drm_mm_print(&mgr->mm, printer);
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index d33a750e07a8..9d4a13926b8c 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -29,12 +29,18 @@
 #include "atom.h"
 
 struct amdgpu_vram_mgr {
+	struct ttm_mem_type_manager manager;
 	struct drm_mm mm;
 	spinlock_t lock;
 	atomic64_t usage;
 	atomic64_t vis_usage;
 };
 
+static inline struct amdgpu_vram_mgr *to_vram_mgr(struct ttm_mem_type_manager *man)
+{
+	return container_of(man, struct amdgpu_vram_mgr, manager);
+}
+
 /**
  * DOC: mem_info_vram_total
  *
@@ -170,29 +176,32 @@ static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
  */
 int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
+	struct ttm_mem_type_manager *man;
 	struct amdgpu_vram_mgr *mgr;
 	int ret;
 
+	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
+	if (!mgr)
+		return -ENOMEM;
+
+	man = &mgr->manager;
+
 	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
 	man->default_caching = TTM_PL_FLAG_WC;
 
 	ttm_bo_init_mm_base(&adev->mman.bdev, man, adev->gmc.real_vram_size >> PAGE_SHIFT);
 
 	man->func = &amdgpu_vram_mgr_func;
-	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
-	if (!mgr)
-		return -ENOMEM;
 
 	drm_mm_init(&mgr->mm, 0, man->size);
 	spin_lock_init(&mgr->lock);
-	man->priv = mgr;
 
 	/* Add the two VRAM-related sysfs files */
 	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 	if (ret)
 		DRM_ERROR("Failed to register sysfs\n");
 
+	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
 	ttm_bo_use_mm(man);
 	return 0;
 }
@@ -208,7 +217,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 {
 	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
-	struct amdgpu_vram_mgr *mgr = man->priv;
+	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 	int ret;
 
 	ttm_bo_disable_mm(man);
@@ -220,11 +229,12 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 	spin_lock(&mgr->lock);
 	drm_mm_takedown(&mgr->mm);
 	spin_unlock(&mgr->lock);
-	kfree(mgr);
-	man->priv = NULL;
+
 	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 
 	ttm_bo_man_cleanup(man);
+	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
+	kfree(mgr);
 }
 
 /**
@@ -314,7 +324,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
 			       struct ttm_mem_reg *mem)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
-	struct amdgpu_vram_mgr *mgr = man->priv;
+	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 	struct drm_mm *mm = &mgr->mm;
 	struct drm_mm_node *nodes;
 	enum drm_mm_insert_mode mode;
@@ -430,7 +440,7 @@ static void amdgpu_vram_mgr_del(struct ttm_mem_type_manager *man,
 				struct ttm_mem_reg *mem)
 {
 	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
-	struct amdgpu_vram_mgr *mgr = man->priv;
+	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 	struct drm_mm_node *nodes = mem->mm_node;
 	uint64_t usage = 0, vis_usage = 0;
 	unsigned pages = mem->num_pages;
@@ -562,7 +572,7 @@ void amdgpu_vram_mgr_free_sgt(struct amdgpu_device *adev,
  */
 uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man)
 {
-	struct amdgpu_vram_mgr *mgr = man->priv;
+	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 
 	return atomic64_read(&mgr->usage);
 }
@@ -576,7 +586,7 @@ uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man)
  */
 uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man)
 {
-	struct amdgpu_vram_mgr *mgr = man->priv;
+	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 
 	return atomic64_read(&mgr->vis_usage);
 }
@@ -592,7 +602,7 @@ uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man)
 static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
 				  struct drm_printer *printer)
 {
-	struct amdgpu_vram_mgr *mgr = man->priv;
+	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 
 	spin_lock(&mgr->lock);
 	drm_mm_print(&mgr->mm, printer);
-- 
2.26.2

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

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

* [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (37 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 13:32   ` Christian König
  2020-07-31  4:05 ` [PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation Dave Airlie
                   ` (10 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This makes it easier to move these to a driver allocated system

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 15 +++++------
 drivers/gpu/drm/drm_gem_vram_helper.c   | 10 ++++----
 drivers/gpu/drm/nouveau/nouveau_ttm.c   | 21 ++++++++++------
 drivers/gpu/drm/qxl/qxl_ttm.c           | 12 +++------
 drivers/gpu/drm/radeon/radeon_ttm.c     | 33 ++++++++++++-------------
 drivers/gpu/drm/ttm/ttm_bo_manager.c    | 19 ++++++++++----
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c     | 13 +++-------
 include/drm/ttm/ttm_bo_driver.h         |  7 ++++--
 8 files changed, 67 insertions(+), 63 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
index 4beec1c4e037..d4d81f808b01 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
@@ -67,12 +67,9 @@ static int amdgpu_ttm_init_on_chip(struct amdgpu_device *adev,
 				    unsigned int type,
 				    uint64_t size)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, type);
-
-	man->available_caching = TTM_PL_FLAG_UNCACHED;
-	man->default_caching = TTM_PL_FLAG_UNCACHED;
-
-	return ttm_bo_man_init(&adev->mman.bdev, man, size >> PAGE_SHIFT);
+	return ttm_bo_man_init(&adev->mman.bdev, type,
+			       TTM_PL_FLAG_UNCACHED, TTM_PL_FLAG_UNCACHED,
+			       false, size >> PAGE_SHIFT);
 }
 
 /**
@@ -2014,9 +2011,9 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
 
 	amdgpu_vram_mgr_fini(adev);
 	amdgpu_gtt_mgr_fini(adev);
-	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_GDS));
-	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_GWS));
-	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_OA));
+	ttm_bo_man_takedown(&adev->mman.bdev, AMDGPU_PL_GDS);
+	ttm_bo_man_takedown(&adev->mman.bdev, AMDGPU_PL_GWS);
+	ttm_bo_man_takedown(&adev->mman.bdev, AMDGPU_PL_OA);
 	ttm_bo_device_release(&adev->mman.bdev);
 	adev->mman.initialized = false;
 	DRM_INFO("amdgpu: ttm finalized\n");
diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
index 08fbfa32540a..b98af8daa540 100644
--- a/drivers/gpu/drm/drm_gem_vram_helper.c
+++ b/drivers/gpu/drm/drm_gem_vram_helper.c
@@ -1103,7 +1103,6 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init);
 static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 			    uint64_t vram_base, size_t vram_size)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
 	int ret;
 
 	vmm->vram_base = vram_base;
@@ -1116,9 +1115,10 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 	if (ret)
 		return ret;
 
-	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-	man->default_caching = TTM_PL_FLAG_WC;
-	ret = ttm_bo_man_init(&vmm->bdev, man, vram_size >> PAGE_SHIFT);
+	ret = ttm_bo_man_init(&vmm->bdev, TTM_PL_VRAM,
+			      TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
+			      TTM_PL_FLAG_WC, false,
+			      vram_size >> PAGE_SHIFT);
 	if (ret)
 		return ret;
 
@@ -1127,7 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
 
 static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
 {
-	ttm_bo_man_takedown(&vmm->bdev, ttm_manager_type(&vmm->bdev, TTM_PL_VRAM));
+	ttm_bo_man_takedown(&vmm->bdev, TTM_PL_VRAM);
 	ttm_bo_device_release(&vmm->bdev);
 }
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 1b9d9362132d..225f9af2eaa1 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -156,16 +156,17 @@ nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
 static int
 nouveau_ttm_init_vram(struct nouveau_drm *drm)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
 	struct nvif_mmu *mmu = &drm->client.mmu;
 
-	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-	man->default_caching = TTM_PL_FLAG_WC;
-
 	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
+		struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
+
 		/* Some BARs do not support being ioremapped WC */
 		const u8 type = mmu->type[drm->ttm.type_vram].type;
 
+		man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
+		man->default_caching = TTM_PL_FLAG_WC;
+
 		if (type & NVIF_MEM_UNCACHED) {
 			man->available_caching = TTM_PL_FLAG_UNCACHED;
 			man->default_caching = TTM_PL_FLAG_UNCACHED;
@@ -178,7 +179,9 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 		ttm_bo_use_mm(man);
 		return 0;
 	} else {
-		return ttm_bo_man_init(&drm->ttm.bdev, man,
+		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_VRAM,
+				       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
+				       TTM_PL_FLAG_WC, false,
 				       drm->gem.vram_available >> PAGE_SHIFT);
 	}
 }
@@ -193,7 +196,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
 		ttm_bo_man_cleanup(man);
 	} else
-		ttm_bo_man_takedown(&drm->ttm.bdev, man);
+		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_VRAM);
 }
 
 static int
@@ -216,7 +219,9 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 	else if (!drm->agp.bridge)
 		man->func = &nv04_gart_manager;
 	else
-		return ttm_bo_man_init(&drm->ttm.bdev, man,
+		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_TT,
+				       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
+				       TTM_PL_FLAG_WC, true,
 				       size_pages);
 
 	ttm_bo_init_mm_base(&drm->ttm.bdev, man,
@@ -232,7 +237,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 
 	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
 	    drm->agp.bridge)
-		ttm_bo_man_takedown(&drm->ttm.bdev, man);
+		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_TT);
 	else {
 		ttm_bo_disable_mm(man);
 		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
index 9aea35a66e25..5b569415854e 100644
--- a/drivers/gpu/drm/qxl/qxl_ttm.c
+++ b/drivers/gpu/drm/qxl/qxl_ttm.c
@@ -219,12 +219,8 @@ static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
 				 unsigned int type,
 				 uint64_t size)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&qdev->mman.bdev, type);
-
-	man->available_caching = TTM_PL_MASK_CACHING;
-	man->default_caching = TTM_PL_FLAG_CACHED;
-
-	return ttm_bo_man_init(&qdev->mman.bdev, man, size);
+	return ttm_bo_man_init(&qdev->mman.bdev, type, TTM_PL_MASK_CACHING,
+			       TTM_PL_FLAG_CACHED, false, size);
 }
 
 int qxl_ttm_init(struct qxl_device *qdev)
@@ -266,8 +262,8 @@ int qxl_ttm_init(struct qxl_device *qdev)
 
 void qxl_ttm_fini(struct qxl_device *qdev)
 {
-	ttm_bo_man_takedown(&qdev->mman.bdev, ttm_manager_type(&qdev->mman.bdev, TTM_PL_VRAM));
-	ttm_bo_man_takedown(&qdev->mman.bdev, ttm_manager_type(&qdev->mman.bdev, TTM_PL_PRIV));
+	ttm_bo_man_takedown(&qdev->mman.bdev, TTM_PL_VRAM);
+	ttm_bo_man_takedown(&qdev->mman.bdev, TTM_PL_PRIV);
 	ttm_bo_device_release(&qdev->mman.bdev);
 	DRM_INFO("qxl: ttm finalized\n");
 }
diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
index 3849d0e852bc..793031bb9bd2 100644
--- a/drivers/gpu/drm/radeon/radeon_ttm.c
+++ b/drivers/gpu/drm/radeon/radeon_ttm.c
@@ -68,36 +68,35 @@ struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
 
 static int radeon_ttm_init_vram(struct radeon_device *rdev)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
-
-	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
-	man->default_caching = TTM_PL_FLAG_WC;
-
-	return ttm_bo_man_init(&rdev->mman.bdev, man,
+	return ttm_bo_man_init(&rdev->mman.bdev, TTM_PL_VRAM,
+			       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
+			       TTM_PL_FLAG_WC, false,
 			       rdev->mc.real_vram_size >> PAGE_SHIFT);
 }
 
 static int radeon_ttm_init_gtt(struct radeon_device *rdev)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_TT);
+	uint32_t available_caching, default_caching;
+
+	available_caching = TTM_PL_MASK_CACHING;
+	default_caching = TTM_PL_FLAG_CACHED;
 
-	man->available_caching = TTM_PL_MASK_CACHING;
-	man->default_caching = TTM_PL_FLAG_CACHED;
-	man->use_tt = true;
 #if IS_ENABLED(CONFIG_AGP)
 	if (rdev->flags & RADEON_IS_AGP) {
 		if (!rdev->ddev->agp) {
 			DRM_ERROR("AGP is not enabled\n");
 			return -EINVAL;
 		}
-		man->available_caching = TTM_PL_FLAG_UNCACHED |
-					 TTM_PL_FLAG_WC;
-		man->default_caching = TTM_PL_FLAG_WC;
+		available_caching = TTM_PL_FLAG_UNCACHED |
+			TTM_PL_FLAG_WC;
+		default_caching = TTM_PL_FLAG_WC;
 	}
 #endif
 
-	return ttm_bo_man_init(&rdev->mman.bdev, man,
-			      rdev->mc.gtt_size >> PAGE_SHIFT);
+	return ttm_bo_man_init(&rdev->mman.bdev, TTM_PL_TT,
+			       available_caching,
+			       default_caching, true,
+			       rdev->mc.gtt_size >> PAGE_SHIFT);
 }
 
 static void radeon_evict_flags(struct ttm_buffer_object *bo,
@@ -825,8 +824,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
 		}
 		radeon_bo_unref(&rdev->stolen_vga_memory);
 	}
-	ttm_bo_man_takedown(&rdev->mman.bdev, ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM));
-	ttm_bo_man_takedown(&rdev->mman.bdev, ttm_manager_type(&rdev->mman.bdev, TTM_PL_TT));
+	ttm_bo_man_takedown(&rdev->mman.bdev, TTM_PL_VRAM);
+	ttm_bo_man_takedown(&rdev->mman.bdev, TTM_PL_TT);
 	ttm_bo_device_release(&rdev->mman.bdev);
 	radeon_gart_fini(rdev);
 	rdev->mman.initialized = false;
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index f60a9a5d429d..2f5fa44b6474 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -107,19 +107,27 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
 static const struct ttm_mem_type_manager_func ttm_bo_manager_func;
 
 int ttm_bo_man_init(struct ttm_bo_device *bdev,
-		    struct ttm_mem_type_manager *man,
+		    unsigned type,
+		    uint32_t available_caching,
+		    uint32_t default_caching,
+		    bool use_tt,
 		    unsigned long p_size)
 {
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
 	struct ttm_range_manager *rman;
 
-	man->func = &ttm_bo_manager_func;
-
-	ttm_bo_init_mm_base(bdev, man, p_size);
+	man->available_caching = available_caching;
+	man->default_caching = default_caching;
+	man->use_tt = use_tt;
 
 	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
 	if (!rman)
 		return -ENOMEM;
 
+	man->func = &ttm_bo_manager_func;
+
+	ttm_bo_init_mm_base(bdev, man, p_size);
+
 	drm_mm_init(&rman->mm, 0, p_size);
 	spin_lock_init(&rman->lock);
 	man->priv = rman;
@@ -130,8 +138,9 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 EXPORT_SYMBOL(ttm_bo_man_init);
 
 int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
-			struct ttm_mem_type_manager *man)
+			unsigned type)
 {
+	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
 	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
 	struct drm_mm *mm = &rman->mm;
 	int ret;
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index dff6990ff9ed..1849d913d521 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -626,13 +626,9 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	ret = vmw_thp_init(dev_priv);
 #else
-	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
-
-	man->available_caching = TTM_PL_FLAG_CACHED;
-	man->default_caching = TTM_PL_FLAG_CACHED;
-
-	ret = ttm_bo_man_init(&dev_priv->bdev, man,
-			      dev_priv->vram_size >> PAGE_SHIFT);
+	ret = ttm_bo_man_init(&dev_priv->bdev, TTM_PL_VRAM,
+			      TTM_PL_FLAG_CACHED, TTM_PL_FLAG_CACHED,
+			      false, dev_priv->vram_size >> PAGE_SHIFT);
 #endif
 	ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM)->use_type = false;
 	return ret;
@@ -643,8 +639,7 @@ static void vmw_takedown_vram_manager(struct vmw_private *dev_priv)
 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
 	vmw_thp_takedown(dev_priv);
 #else
-	ttm_bo_man_takedown(&dev_priv->bdev,
-			    ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM));
+	ttm_bo_man_takedown(&dev_priv->bdev, TTM_PL_VRAM);
 #endif
 }
 
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 723171fd94da..6319d85d7270 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -809,8 +809,11 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
 pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
 
 int ttm_bo_man_init(struct ttm_bo_device *bdev,
-		    struct ttm_mem_type_manager *man,
+		    unsigned type,
+		    uint32_t available_caching,
+		    uint32_t default_caching,
+		    bool use_tt,
 		    unsigned long p_size);
 int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
-			struct ttm_mem_type_manager *man);
+			unsigned type);
 #endif
-- 
2.26.2

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

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

* [PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (38 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 13:33   ` Christian König
  2020-07-31  4:05 ` [PATCH 41/49] drm/vmwgfx/ttm: move thp to driver managed Dave Airlie
                   ` (9 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/ttm/ttm_bo_manager.c | 32 +++++++++++++++++-----------
 1 file changed, 20 insertions(+), 12 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 2f5fa44b6474..2782ccff9b66 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -44,16 +44,22 @@
  */
 
 struct ttm_range_manager {
+	struct ttm_mem_type_manager manager;
 	struct drm_mm mm;
 	spinlock_t lock;
 };
 
+static inline struct ttm_range_manager *to_range_manager(struct ttm_mem_type_manager *man)
+{
+	return container_of(man, struct ttm_range_manager, manager);
+}
+
 static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
 			       struct ttm_buffer_object *bo,
 			       const struct ttm_place *place,
 			       struct ttm_mem_reg *mem)
 {
-	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+	struct ttm_range_manager *rman = to_range_manager(man);
 	struct drm_mm *mm = &rman->mm;
 	struct drm_mm_node *node;
 	enum drm_mm_insert_mode mode;
@@ -92,7 +98,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
 static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
 				struct ttm_mem_reg *mem)
 {
-	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+	struct ttm_range_manager *rman = to_range_manager(man);
 
 	if (mem->mm_node) {
 		spin_lock(&rman->lock);
@@ -113,25 +119,26 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 		    bool use_tt,
 		    unsigned long p_size)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
+	struct ttm_mem_type_manager *man;
 	struct ttm_range_manager *rman;
 
-	man->available_caching = available_caching;
-	man->default_caching = default_caching;
-	man->use_tt = use_tt;
-
 	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
 	if (!rman)
 		return -ENOMEM;
 
+	man = &rman->manager;
+	man->available_caching = available_caching;
+	man->default_caching = default_caching;
+	man->use_tt = use_tt;
+
 	man->func = &ttm_bo_manager_func;
 
 	ttm_bo_init_mm_base(bdev, man, p_size);
 
 	drm_mm_init(&rman->mm, 0, p_size);
 	spin_lock_init(&rman->lock);
-	man->priv = rman;
 
+	ttm_set_driver_manager(bdev, type, &rman->manager);
 	ttm_bo_use_mm(man);
 	return 0;
 }
@@ -141,7 +148,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
 			unsigned type)
 {
 	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
-	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+	struct ttm_range_manager *rman = to_range_manager(man);
 	struct drm_mm *mm = &rman->mm;
 	int ret;
 
@@ -155,10 +162,11 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
 	drm_mm_clean(mm);
 	drm_mm_takedown(mm);
 	spin_unlock(&rman->lock);
-	kfree(rman);
-	man->priv = NULL;
 
 	ttm_bo_man_cleanup(man);
+	ttm_set_driver_manager(bdev, type, NULL);
+	kfree(rman);
+
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_man_takedown);
@@ -166,7 +174,7 @@ EXPORT_SYMBOL(ttm_bo_man_takedown);
 static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
 			     struct drm_printer *printer)
 {
-	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
+	struct ttm_range_manager *rman = to_range_manager(man);
 
 	spin_lock(&rman->lock);
 	drm_mm_print(&rman->mm, printer);
-- 
2.26.2

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

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

* [PATCH 41/49] drm/vmwgfx/ttm: move thp to driver managed
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (39 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 42/49] drm/vmwgfx/gmrid: convert to driver controlled allocation Dave Airlie
                   ` (8 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c | 33 +++++++++++++++++++----------
 1 file changed, 22 insertions(+), 11 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index 0dd619c9d207..d2dde8159c3d 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -16,10 +16,16 @@
  * @lock: Manager lock.
  */
 struct vmw_thp_manager {
+	struct ttm_mem_type_manager manager;
 	struct drm_mm mm;
 	spinlock_t lock;
 };
 
+static struct vmw_thp_manager *to_thp_manager(struct ttm_mem_type_manager *man)
+{
+	return container_of(man, struct vmw_thp_manager, manager);
+}
+
 static int vmw_thp_insert_aligned(struct drm_mm *mm, struct drm_mm_node *node,
 				  unsigned long align_pages,
 				  const struct ttm_place *place,
@@ -43,7 +49,7 @@ static int vmw_thp_get_node(struct ttm_mem_type_manager *man,
 			    const struct ttm_place *place,
 			    struct ttm_mem_reg *mem)
 {
-	struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+	struct vmw_thp_manager *rman = to_thp_manager(man);
 	struct drm_mm *mm = &rman->mm;
 	struct drm_mm_node *node;
 	unsigned long align_pages;
@@ -103,7 +109,7 @@ static int vmw_thp_get_node(struct ttm_mem_type_manager *man,
 static void vmw_thp_put_node(struct ttm_mem_type_manager *man,
 			     struct ttm_mem_reg *mem)
 {
-	struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+	struct vmw_thp_manager *rman = to_thp_manager(man);
 
 	if (mem->mm_node) {
 		spin_lock(&rman->lock);
@@ -117,20 +123,25 @@ static void vmw_thp_put_node(struct ttm_mem_type_manager *man,
 
 int vmw_thp_init(struct vmw_private *dev_priv)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
+	struct ttm_mem_type_manager *man;
 	struct vmw_thp_manager *rman;
+
+	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
+	if (!rman)
+		return -ENOMEM;
+
+	man = &rman->manager;
 	man->available_caching = TTM_PL_FLAG_CACHED;
 	man->default_caching = TTM_PL_FLAG_CACHED;
 
 	ttm_bo_init_mm_base(&dev_priv->bdev, man,
 			    dev_priv->vram_size >> PAGE_SHIFT);
-	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
-	if (!rman)
-		return -ENOMEM;
+
 
 	drm_mm_init(&rman->mm, 0, man->size);
 	spin_lock_init(&rman->lock);
-	man->priv = rman;
+
+	ttm_set_driver_manager(&dev_priv->bdev, TTM_PL_VRAM, &rman->manager);
 	ttm_bo_use_mm(man);
 	return 0;
 }
@@ -138,7 +149,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
 void vmw_thp_takedown(struct vmw_private *dev_priv)
 {
 	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
-	struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+	struct vmw_thp_manager *rman = to_thp_manager(man);
 	struct drm_mm *mm = &rman->mm;
 	int ret;
 
@@ -151,15 +162,15 @@ void vmw_thp_takedown(struct vmw_private *dev_priv)
 	drm_mm_clean(mm);
 	drm_mm_takedown(mm);
 	spin_unlock(&rman->lock);
-	kfree(rman);
-	man->priv = NULL;
 	ttm_bo_man_cleanup(man);
+	ttm_set_driver_manager(&dev_priv->bdev, TTM_PL_VRAM, NULL);
+	kfree(rman);
 }
 
 static void vmw_thp_debug(struct ttm_mem_type_manager *man,
 			  struct drm_printer *printer)
 {
-	struct vmw_thp_manager *rman = (struct vmw_thp_manager *) man->priv;
+	struct vmw_thp_manager *rman = to_thp_manager(man);
 
 	spin_lock(&rman->lock);
 	drm_mm_print(&rman->mm, printer);
-- 
2.26.2

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

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

* [PATCH 42/49] drm/vmwgfx/gmrid: convert to driver controlled allocation.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (40 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 41/49] drm/vmwgfx/ttm: move thp to driver managed Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 43/49] drm/nouveau/ttm: move to driver allocated manager Dave Airlie
                   ` (7 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 33 +++++++++++--------
 1 file changed, 20 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 2db99f0449b0..14430c243ce5 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -37,6 +37,7 @@
 #include <linux/kernel.h>
 
 struct vmwgfx_gmrid_man {
+	struct ttm_mem_type_manager manager;
 	spinlock_t lock;
 	struct ida gmr_ida;
 	uint32_t max_gmr_ids;
@@ -44,13 +45,17 @@ struct vmwgfx_gmrid_man {
 	uint32_t used_gmr_pages;
 };
 
+static struct vmwgfx_gmrid_man *to_gmrid_manager(struct ttm_mem_type_manager *man)
+{
+	return container_of(man, struct vmwgfx_gmrid_man, manager);
+}
+
 static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
 				  struct ttm_buffer_object *bo,
 				  const struct ttm_place *place,
 				  struct ttm_mem_reg *mem)
 {
-	struct vmwgfx_gmrid_man *gman =
-		(struct vmwgfx_gmrid_man *)man->priv;
+	struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
 	int id;
 
 	id = ida_alloc_max(&gman->gmr_ida, gman->max_gmr_ids - 1, GFP_KERNEL);
@@ -82,8 +87,7 @@ static int vmw_gmrid_man_get_node(struct ttm_mem_type_manager *man,
 static void vmw_gmrid_man_put_node(struct ttm_mem_type_manager *man,
 				   struct ttm_mem_reg *mem)
 {
-	struct vmwgfx_gmrid_man *gman =
-		(struct vmwgfx_gmrid_man *)man->priv;
+	struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
 
 	if (mem->mm_node) {
 		ida_free(&gman->gmr_ida, mem->start);
@@ -98,13 +102,15 @@ static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func;
 
 int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
+	struct ttm_mem_type_manager *man;
 	struct vmwgfx_gmrid_man *gman =
 		kzalloc(sizeof(*gman), GFP_KERNEL);
 
 	if (unlikely(!gman))
 		return -ENOMEM;
 
+	man = &gman->manager;
+
 	man->func = &vmw_gmrid_manager_func;
 	man->available_caching = TTM_PL_FLAG_CACHED;
 	man->default_caching = TTM_PL_FLAG_CACHED;
@@ -127,26 +133,27 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 	default:
 		BUG();
 	}
-	man->priv = (void *) gman;
+
+	ttm_set_driver_manager(&dev_priv->bdev, type, &gman->manager);
+	ttm_bo_use_mm(man);
 	return 0;
 }
 
 void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 {
 	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
-	struct vmwgfx_gmrid_man *gman =
-		(struct vmwgfx_gmrid_man *)man->priv;
+	struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
 
 	ttm_bo_disable_mm(man);
 
 	ttm_bo_force_list_clean(&dev_priv->bdev, man);
 
-	if (gman) {
-		ida_destroy(&gman->gmr_ida);
-		kfree(gman);
-	}
-
 	ttm_bo_man_cleanup(man);
+
+	ttm_set_driver_manager(&dev_priv->bdev, type, NULL);
+	ida_destroy(&gman->gmr_ida);
+	kfree(gman);
+
 }
 
 static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
-- 
2.26.2

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

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

* [PATCH 43/49] drm/nouveau/ttm: move to driver allocated manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (41 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 42/49] drm/vmwgfx/gmrid: convert to driver controlled allocation Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 44/49] drm/ttm: drop priv pointer in memory manager Dave Airlie
                   ` (6 subsequent siblings)
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/nouveau/nouveau_ttm.c | 41 ++++++++++++++++++---------
 1 file changed, 28 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 225f9af2eaa1..5b0af2065ad9 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -157,12 +157,12 @@ static int
 nouveau_ttm_init_vram(struct nouveau_drm *drm)
 {
 	struct nvif_mmu *mmu = &drm->client.mmu;
-
 	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
-		struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
-
 		/* Some BARs do not support being ioremapped WC */
 		const u8 type = mmu->type[drm->ttm.type_vram].type;
+		struct ttm_mem_type_manager *man = kzalloc(sizeof(struct ttm_mem_type_manager), GFP_KERNEL);
+		if (!man)
+			return -ENOMEM;
 
 		man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
 		man->default_caching = TTM_PL_FLAG_WC;
@@ -176,6 +176,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 		man->use_io_reserve_lru = true;
 		ttm_bo_init_mm_base(&drm->ttm.bdev, man,
 				    drm->gem.vram_available >> PAGE_SHIFT);
+		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
 		ttm_bo_use_mm(man);
 		return 0;
 	} else {
@@ -195,6 +196,8 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 		ttm_bo_disable_mm(man);
 		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
 		ttm_bo_man_cleanup(man);
+		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, NULL);
+		kfree(man);
 	} else
 		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_VRAM);
 }
@@ -202,30 +205,40 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 static int
 nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 {
-	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_TT);
+	struct ttm_mem_type_manager *man;
 	unsigned long size_pages = drm->gem.gart_available >> PAGE_SHIFT;
-	man->use_tt = true;
+	unsigned available_caching, default_caching;
+	const struct ttm_mem_type_manager_func *func = NULL;
 	if (drm->agp.bridge) {
-		man->available_caching = TTM_PL_FLAG_UNCACHED |
+		available_caching = TTM_PL_FLAG_UNCACHED |
 			TTM_PL_FLAG_WC;
-		man->default_caching = TTM_PL_FLAG_WC;
+		default_caching = TTM_PL_FLAG_WC;
 	} else {
-		man->available_caching = TTM_PL_MASK_CACHING;
-		man->default_caching = TTM_PL_FLAG_CACHED;
+		available_caching = TTM_PL_MASK_CACHING;
+		default_caching = TTM_PL_FLAG_CACHED;
 	}
 
 	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA)
-		man->func = &nouveau_gart_manager;
+		func = &nouveau_gart_manager;
 	else if (!drm->agp.bridge)
-		man->func = &nv04_gart_manager;
+		func = &nv04_gart_manager;
 	else
 		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_TT,
-				       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
-				       TTM_PL_FLAG_WC, true,
+				       available_caching, default_caching,
+				       true,
 				       size_pages);
 
+	man = kzalloc(sizeof(struct ttm_mem_type_manager), GFP_KERNEL);
+	if (!man)
+		return -ENOMEM;
+
+	man->func = func;
+	man->available_caching = available_caching;
+	man->default_caching = default_caching;
+	man->use_tt = true;
 	ttm_bo_init_mm_base(&drm->ttm.bdev, man,
 			    size_pages);
+	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
 	ttm_bo_use_mm(man);
 	return 0;
 }
@@ -242,6 +255,8 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 		ttm_bo_disable_mm(man);
 		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
 		ttm_bo_man_cleanup(man);
+		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, NULL);
+		kfree(man);
 	}
 }
 
-- 
2.26.2

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

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

* [PATCH 44/49] drm/ttm: drop priv pointer in memory manager
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (42 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 43/49] drm/nouveau/ttm: move to driver allocated manager Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 13:33   ` Christian König
  2020-07-31  4:05 ` [PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references Dave Airlie
                   ` (5 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This isn't needed anymore by any drivers.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 include/drm/ttm/ttm_bo_driver.h | 2 --
 1 file changed, 2 deletions(-)

diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 6319d85d7270..a38704fe0737 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -123,7 +123,6 @@ struct ttm_mem_type_manager_func {
  * @default_caching: The default caching policy used for a buffer object
  * placed in this memory type if the user doesn't provide one.
  * @func: structure pointer implementing the range manager. See above
- * @priv: Driver private closure for @func.
  * @io_reserve_mutex: Mutex optionally protecting shared io_reserve structures
  * @use_io_reserve_lru: Use an lru list to try to unreserve io_mem_regions
  * reserved by the TTM vm system.
@@ -152,7 +151,6 @@ struct ttm_mem_type_manager {
 	uint32_t available_caching;
 	uint32_t default_caching;
 	const struct ttm_mem_type_manager_func *func;
-	void *priv;
 	struct mutex io_reserve_mutex;
 	bool use_io_reserve_lru;
 	spinlock_t move_lock;
-- 
2.26.2

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

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

* [PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (43 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 44/49] drm/ttm: drop priv pointer in memory manager Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 14:55   ` Christian König
  2020-07-31  4:05 ` [PATCH 46/49] drm/ttm: drop man->bdev link Dave Airlie
                   ` (4 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

Just store the device in the private so the link
can be removed from the manager

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

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index 9d4a13926b8c..d451851c8689 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -34,6 +34,7 @@ struct amdgpu_vram_mgr {
 	spinlock_t lock;
 	atomic64_t usage;
 	atomic64_t vis_usage;
+	struct amdgpu_device *adev;
 };
 
 static inline struct amdgpu_vram_mgr *to_vram_mgr(struct ttm_mem_type_manager *man)
@@ -196,6 +197,8 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 	drm_mm_init(&mgr->mm, 0, man->size);
 	spin_lock_init(&mgr->lock);
 
+	mgr->adev = adev;
+
 	/* Add the two VRAM-related sysfs files */
 	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
 	if (ret)
@@ -323,8 +326,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
 			       const struct ttm_place *place,
 			       struct ttm_mem_reg *mem)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
 	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
+	struct amdgpu_device *adev = mgr->adev;
 	struct drm_mm *mm = &mgr->mm;
 	struct drm_mm_node *nodes;
 	enum drm_mm_insert_mode mode;
@@ -439,8 +442,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
 static void amdgpu_vram_mgr_del(struct ttm_mem_type_manager *man,
 				struct ttm_mem_reg *mem)
 {
-	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
 	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
+	struct amdgpu_device *adev = mgr->adev;
 	struct drm_mm_node *nodes = mem->mm_node;
 	uint64_t usage = 0, vis_usage = 0;
 	unsigned pages = mem->num_pages;
-- 
2.26.2

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

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

* [PATCH 46/49] drm/ttm: drop man->bdev link.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (44 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31 14:54   ` Christian König
  2020-07-31  4:05 ` [PATCH 47/49] drm/ttm: drop list of memory managers from device Dave Airlie
                   ` (3 subsequent siblings)
  49 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This link isn't needed anymore, drop it from the init interface.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   | 2 +-
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  | 2 +-
 drivers/gpu/drm/nouveau/nouveau_ttm.c         | 6 ++----
 drivers/gpu/drm/ttm/ttm_bo.c                  | 6 ++----
 drivers/gpu/drm/ttm/ttm_bo_manager.c          | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 2 +-
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           | 2 +-
 include/drm/ttm/ttm_bo_api.h                  | 3 +--
 include/drm/ttm/ttm_bo_driver.h               | 2 --
 9 files changed, 10 insertions(+), 17 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index 83d88ee73468..b4480ca30988 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -108,7 +108,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 	man->available_caching = TTM_PL_MASK_CACHING;
 	man->default_caching = TTM_PL_FLAG_CACHED;
 
-	ttm_bo_init_mm_base(&adev->mman.bdev, man, gtt_size >> PAGE_SHIFT);
+	ttm_bo_init_mm_base(man, gtt_size >> PAGE_SHIFT);
 
 	start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
 	size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index d451851c8689..f0e65a6fdf88 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -190,7 +190,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
 	man->default_caching = TTM_PL_FLAG_WC;
 
-	ttm_bo_init_mm_base(&adev->mman.bdev, man, adev->gmc.real_vram_size >> PAGE_SHIFT);
+	ttm_bo_init_mm_base(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
 
 	man->func = &amdgpu_vram_mgr_func;
 
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 5b0af2065ad9..89521d3ed9da 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -174,8 +174,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 
 		man->func = &nouveau_vram_manager;
 		man->use_io_reserve_lru = true;
-		ttm_bo_init_mm_base(&drm->ttm.bdev, man,
-				    drm->gem.vram_available >> PAGE_SHIFT);
+		ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
 		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
 		ttm_bo_use_mm(man);
 		return 0;
@@ -236,8 +235,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 	man->available_caching = available_caching;
 	man->default_caching = default_caching;
 	man->use_tt = true;
-	ttm_bo_init_mm_base(&drm->ttm.bdev, man,
-			    size_pages);
+	ttm_bo_init_mm_base(man, size_pages);
 	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
 	ttm_bo_use_mm(man);
 	return 0;
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index 1e8fda1c9b3a..f2b41c4d7d51 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1464,8 +1464,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 }
 EXPORT_SYMBOL(ttm_bo_evict_mm);
 
-void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
-			 struct ttm_mem_type_manager *man,
+void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
 			 unsigned long p_size)
 {
 	unsigned i;
@@ -1475,7 +1474,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
 	mutex_init(&man->io_reserve_mutex);
 	spin_lock_init(&man->move_lock);
 	INIT_LIST_HEAD(&man->io_reserve_lru);
-	man->bdev = bdev;
 	man->size = p_size;
 
 	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
@@ -1588,7 +1586,7 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
 	man->available_caching = TTM_PL_MASK_CACHING;
 	man->default_caching = TTM_PL_FLAG_CACHED;
 
-	ttm_bo_init_mm_base(bdev, man, 0);
+	ttm_bo_init_mm_base(man, 0);
 	ttm_bo_use_mm(man);
 }
 
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 2782ccff9b66..6c6eedf84ca6 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -133,7 +133,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 
 	man->func = &ttm_bo_manager_func;
 
-	ttm_bo_init_mm_base(bdev, man, p_size);
+	ttm_bo_init_mm_base(man, p_size);
 
 	drm_mm_init(&rman->mm, 0, p_size);
 	spin_lock_init(&rman->lock);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 14430c243ce5..2b60957f7c4a 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -116,7 +116,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 	man->default_caching = TTM_PL_FLAG_CACHED;
 	/* TODO: This is most likely not correct */
 	man->use_tt = true;
-	ttm_bo_init_mm_base(&dev_priv->bdev, man, 0);
+	ttm_bo_init_mm_base(man, 0);
 	spin_lock_init(&gman->lock);
 	gman->used_gmr_pages = 0;
 	ida_init(&gman->gmr_ida);
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index d2dde8159c3d..d5a3eb709384 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -134,7 +134,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
 	man->available_caching = TTM_PL_FLAG_CACHED;
 	man->default_caching = TTM_PL_FLAG_CACHED;
 
-	ttm_bo_init_mm_base(&dev_priv->bdev, man,
+	ttm_bo_init_mm_base(man,
 			    dev_priv->vram_size >> PAGE_SHIFT);
 
 
diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
index 27dde1371376..d6938133535a 100644
--- a/include/drm/ttm/ttm_bo_api.h
+++ b/include/drm/ttm/ttm_bo_api.h
@@ -547,8 +547,7 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
  * May also return driver-specified errors.
  */
 struct ttm_mem_type_manager;
-void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
-			 struct ttm_mem_type_manager *man,
+void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
 			 unsigned long p_size);
 
 /**
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index a38704fe0737..bfc549782775 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -138,8 +138,6 @@ struct ttm_mem_type_manager_func {
 
 
 struct ttm_mem_type_manager {
-	struct ttm_bo_device *bdev;
-
 	/*
 	 * No protection. Constant from start.
 	 */
-- 
2.26.2

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

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

* [PATCH 47/49] drm/ttm: drop list of memory managers from device.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (45 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 46/49] drm/ttm: drop man->bdev link Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  9:55   ` daniel
  2020-07-31 14:57   ` Christian König
  2020-07-31  4:05 ` [PATCH 48/49] drm/ttm: drop type manager has_type Dave Airlie
                   ` (2 subsequent siblings)
  49 siblings, 2 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

The driver now controls these, the core just controls the system
memory one.

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

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f2b41c4d7d51..f35548ff17e8 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -1608,8 +1608,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
 
 	bdev->driver = driver;
 
-	memset(bdev->man_priv, 0, sizeof(bdev->man_priv));
-
 	ttm_bo_init_sysman(bdev);
 
 	bdev->vma_manager = vma_manager;
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index bfc549782775..b2ffeaed94e7 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -414,7 +414,7 @@ struct ttm_bo_device {
 	/*
 	 * access via ttm_manager_type.
 	 */
-	struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
+	struct ttm_mem_type_manager sysman; /* move to global */
 	struct ttm_mem_type_manager *man_drv[TTM_NUM_MEM_TYPES];
 	/*
 	 * Protected by internal locks.
@@ -446,9 +446,11 @@ struct ttm_bo_device {
 static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
 							    int mem_type)
 {
+	if (mem_type == TTM_PL_SYSTEM)
+		return &bdev->sysman;
 	if (bdev->man_drv[mem_type])
 		return bdev->man_drv[mem_type];
-	return &bdev->man_priv[mem_type];
+	return NULL;
 }
 
 static inline void ttm_set_driver_manager(struct ttm_bo_device *bdev,
-- 
2.26.2

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

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

* [PATCH 48/49] drm/ttm: drop type manager has_type
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (46 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 47/49] drm/ttm: drop list of memory managers from device Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  4:05 ` [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get Dave Airlie
  2020-07-31  9:17 ` [PATCH 00/49] ttm mem manager refactoring Christian König
  49 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

under driver control, this flag isn't needed anymore

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

diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index f35548ff17e8..bfc20cb27ed6 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -82,7 +82,6 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p
 {
 	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
 
-	drm_printf(p, "    has_type: %d\n", man->has_type);
 	drm_printf(p, "    use_type: %d\n", man->use_type);
 	drm_printf(p, "    use_tt: %d\n", man->use_tt);
 	drm_printf(p, "    size: %llu\n", man->size);
@@ -997,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
 		return ret;
 
 	man = ttm_manager_type(bdev, mem_type);
-	if (!man->has_type || !man->use_type)
+	if (!man || !man->use_type)
 		return -EBUSY;
 
 	if (!ttm_bo_mt_compatible(man, mem_type, place, &cur_flags))
@@ -1455,7 +1454,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
 		return -EINVAL;
 	}
 
-	if (!man->has_type) {
+	if (!man) {
 		pr_err("Memory type %u has not been initialized\n", mem_type);
 		return 0;
 	}
@@ -1469,7 +1468,6 @@ void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
 {
 	unsigned i;
 
-	BUG_ON(man->has_type);
 	man->use_io_reserve_lru = false;
 	mutex_init(&man->io_reserve_mutex);
 	spin_lock_init(&man->move_lock);
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index b2ffeaed94e7..702b3b056eda 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -111,7 +111,6 @@ struct ttm_mem_type_manager_func {
 /**
  * struct ttm_mem_type_manager
  *
- * @has_type: The memory type has been initialized.
  * @use_type: The memory type is enabled.
  * @flags: TTM_MEMTYPE_XX flags identifying the traits of the memory
  * managed by this memory type.
@@ -141,8 +140,6 @@ struct ttm_mem_type_manager {
 	/*
 	 * No protection. Constant from start.
 	 */
-
-	bool has_type;
 	bool use_type;
 	bool use_tt;
 	uint64_t size;
@@ -673,13 +670,11 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 
 static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
 {
-	man->has_type = true;
 	man->use_type = true;
 }
 
 static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
 {
-	man->has_type = false;
 	man->use_type = false;
 }
 
-- 
2.26.2

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

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

* [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (47 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 48/49] drm/ttm: drop type manager has_type Dave Airlie
@ 2020-07-31  4:05 ` Dave Airlie
  2020-07-31  9:51   ` daniel
  2020-07-31 14:59   ` Christian König
  2020-07-31  9:17 ` [PATCH 00/49] ttm mem manager refactoring Christian König
  49 siblings, 2 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  4:05 UTC (permalink / raw)
  To: dri-devel; +Cc: christian.koenig, sroland, bskeggs, kraxel

From: Dave Airlie <airlied@redhat.com>

This is probably something we could consider removing, vmwgfx
is the only user, and we might be able to faciliate it another way

but for now just consolidate it all into accessors.

Signed-off-by: Dave Airlie <airlied@redhat.com>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   |  4 ++--
 drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  |  4 ++--
 drivers/gpu/drm/nouveau/nouveau_ttm.c         |  8 ++++----
 drivers/gpu/drm/ttm/ttm_bo.c                  |  6 +++---
 drivers/gpu/drm/ttm/ttm_bo_manager.c          |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 14 +++++++-------
 drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
 drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           |  4 ++--
 include/drm/ttm/ttm_bo_driver.h               |  8 ++++----
 9 files changed, 28 insertions(+), 28 deletions(-)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
index b4480ca30988..7e84aa2c0064 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
@@ -128,7 +128,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
 	}
 
 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 	return 0;
 }
 
@@ -146,7 +146,7 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
 	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
 	int ret;
 
-	ttm_bo_disable_mm(man);
+	ttm_mm_set_use(man, false);
 
 	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
 	if (ret)
diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
index f0e65a6fdf88..50949aa968fd 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
@@ -205,7 +205,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
 		DRM_ERROR("Failed to register sysfs\n");
 
 	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 	return 0;
 }
 
@@ -223,7 +223,7 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
 	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
 	int ret;
 
-	ttm_bo_disable_mm(man);
+	ttm_mm_set_use(man, false);
 
 	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
 	if (ret)
diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
index 89521d3ed9da..32ce930d1bd8 100644
--- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
+++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
@@ -176,7 +176,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
 		man->use_io_reserve_lru = true;
 		ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
 		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
-		ttm_bo_use_mm(man);
+		ttm_mm_set_use(man, true);
 		return 0;
 	} else {
 		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_VRAM,
@@ -192,7 +192,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
 	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
 
 	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
-		ttm_bo_disable_mm(man);
+		ttm_mm_set_use(man, false);
 		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
 		ttm_bo_man_cleanup(man);
 		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, NULL);
@@ -237,7 +237,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
 	man->use_tt = true;
 	ttm_bo_init_mm_base(man, size_pages);
 	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 	return 0;
 }
 
@@ -250,7 +250,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
 	    drm->agp.bridge)
 		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_TT);
 	else {
-		ttm_bo_disable_mm(man);
+		ttm_mm_set_use(man, false);
 		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
 		ttm_bo_man_cleanup(man);
 		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, NULL);
diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
index bfc20cb27ed6..3bec6e4bc87d 100644
--- a/drivers/gpu/drm/ttm/ttm_bo.c
+++ b/drivers/gpu/drm/ttm/ttm_bo.c
@@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
 		return ret;
 
 	man = ttm_manager_type(bdev, mem_type);
-	if (!man || !man->use_type)
+	if (!man || !ttm_mm_used(man))
 		return -EBUSY;
 
 	if (!ttm_bo_mt_compatible(man, mem_type, place, &cur_flags))
@@ -1548,7 +1548,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
 	struct ttm_mem_type_manager *man;
 
 	man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
-	ttm_bo_disable_mm(man);
+	ttm_mm_set_use(man, false);
 
 	mutex_lock(&ttm_global_mutex);
 	list_del(&bdev->device_list);
@@ -1585,7 +1585,7 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
 	man->default_caching = TTM_PL_FLAG_CACHED;
 
 	ttm_bo_init_mm_base(man, 0);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 }
 
 int ttm_bo_device_init(struct ttm_bo_device *bdev,
diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
index 6c6eedf84ca6..5ed4e4317789 100644
--- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
+++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
@@ -139,7 +139,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
 	spin_lock_init(&rman->lock);
 
 	ttm_set_driver_manager(bdev, type, &rman->manager);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 	return 0;
 }
 EXPORT_SYMBOL(ttm_bo_man_init);
@@ -152,7 +152,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
 	struct drm_mm *mm = &rman->mm;
 	int ret;
 
-	ttm_bo_disable_mm(man);
+	ttm_mm_set_use(man, false);
 
 	ret = ttm_bo_force_list_clean(bdev, man);
 	if (ret)
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
index 1849d913d521..9b9cc3b57a24 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
@@ -630,7 +630,7 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
 			      TTM_PL_FLAG_CACHED, TTM_PL_FLAG_CACHED,
 			      false, dev_priv->vram_size >> PAGE_SHIFT);
 #endif
-	ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM)->use_type = false;
+	ttm_mm_set_use(ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM), false);
 	return ret;
 }
 
@@ -1190,9 +1190,9 @@ static void __vmw_svga_enable(struct vmw_private *dev_priv)
 	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
 
 	spin_lock(&dev_priv->svga_lock);
-	if (!man->use_type) {
+	if (!ttm_mm_used(man)) {
 		vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE);
-		man->use_type = true;
+		ttm_mm_set_use(man, true);
 	}
 	spin_unlock(&dev_priv->svga_lock);
 }
@@ -1221,8 +1221,8 @@ static void __vmw_svga_disable(struct vmw_private *dev_priv)
 	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
 
 	spin_lock(&dev_priv->svga_lock);
-	if (man->use_type) {
-		man->use_type = false;
+	if (ttm_mm_used(man)) {
+		ttm_mm_set_use(man, false);
 		vmw_write(dev_priv, SVGA_REG_ENABLE,
 			  SVGA_REG_ENABLE_HIDE |
 			  SVGA_REG_ENABLE_ENABLE);
@@ -1255,8 +1255,8 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
 	vmw_kms_lost_device(dev_priv->dev);
 	ttm_write_lock(&dev_priv->reservation_sem, false);
 	spin_lock(&dev_priv->svga_lock);
-	if (man->use_type) {
-		man->use_type = false;
+	if (ttm_mm_used(man)) {
+		ttm_mm_set_use(man, false);
 		spin_unlock(&dev_priv->svga_lock);
 		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
 			DRM_ERROR("Failed evicting VRAM buffers.\n");
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
index 2b60957f7c4a..aff7767762ed 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
@@ -135,7 +135,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
 	}
 
 	ttm_set_driver_manager(&dev_priv->bdev, type, &gman->manager);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 	return 0;
 }
 
@@ -144,7 +144,7 @@ void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
 	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
 	struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
 
-	ttm_bo_disable_mm(man);
+	ttm_mm_set_use(man, false);
 
 	ttm_bo_force_list_clean(&dev_priv->bdev, man);
 
diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
index d5a3eb709384..5a7b9b09785c 100644
--- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
+++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
@@ -142,7 +142,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
 	spin_lock_init(&rman->lock);
 
 	ttm_set_driver_manager(&dev_priv->bdev, TTM_PL_VRAM, &rman->manager);
-	ttm_bo_use_mm(man);
+	ttm_mm_set_use(man, true);
 	return 0;
 }
 
@@ -153,7 +153,7 @@ void vmw_thp_takedown(struct vmw_private *dev_priv)
 	struct drm_mm *mm = &rman->mm;
 	int ret;
 
-	ttm_bo_disable_mm(man);
+	ttm_mm_set_use(man, false);
 
 	ret = ttm_bo_force_list_clean(&dev_priv->bdev, man);
 	if (ret)
diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
index 702b3b056eda..6210acd5c651 100644
--- a/include/drm/ttm/ttm_bo_driver.h
+++ b/include/drm/ttm/ttm_bo_driver.h
@@ -668,14 +668,14 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
 	dma_resv_unlock(bo->base.resv);
 }
 
-static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
+static inline void ttm_mm_set_use(struct ttm_mem_type_manager *man, bool use)
 {
-	man->use_type = true;
+	man->use_type = use;
 }
 
-static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
+static inline bool ttm_mm_used(struct ttm_mem_type_manager *man)
 {
-	man->use_type = false;
+	return man->use_type;
 }
 
 static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
-- 
2.26.2

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

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

* Re: [PATCH 03/49] drm/ttm: split the mm manager init code
  2020-07-31  4:04 ` [PATCH 03/49] drm/ttm: split the mm manager init code Dave Airlie
@ 2020-07-31  5:44   ` Sam Ravnborg
  2020-07-31  5:51     ` Dave Airlie
  2020-07-31  9:12   ` Christian König
  1 sibling, 1 reply; 99+ messages in thread
From: Sam Ravnborg @ 2020-07-31  5:44 UTC (permalink / raw)
  To: Dave Airlie; +Cc: kraxel, sroland, christian.koenig, dri-devel, bskeggs

Hi Dave.

On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> This will allow the driver to control the ordering here better.
> 
> Eventually the old path will be removed.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
>  include/drm/ttm/ttm_bo_api.h    |  4 ++++
>  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
>  3 files changed, 30 insertions(+), 14 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 041a0e73cd1b..a658fd584c6d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>  }
>  EXPORT_SYMBOL(ttm_bo_evict_mm);
>  
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> -			unsigned long p_size)
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size)
>  {

General comment for all the ttm/* changes.
It would be very nice with some nice explanations for the exported
functions, preferably in kernel-doc style.
In case someone that are more or less clueless (like me) would like
to understand how a function is to be used or maybe reviewing some
random code.

	Sam


> -	int ret;
> -	struct ttm_mem_type_manager *man;
>  	unsigned i;
>  
> -	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> -	man = &bdev->man[type];
>  	BUG_ON(man->has_type);
>  	man->use_io_reserve_lru = false;
>  	mutex_init(&man->io_reserve_mutex);
>  	spin_lock_init(&man->move_lock);
>  	INIT_LIST_HEAD(&man->io_reserve_lru);
>  	man->bdev = bdev;
> -
> -	if (type != TTM_PL_SYSTEM) {
> -		ret = (*man->func->init)(man, p_size);
> -		if (ret)
> -			return ret;
> -	}
> -	man->has_type = true;
> -	man->use_type = true;
>  	man->size = p_size;
>  
>  	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
>  		INIT_LIST_HEAD(&man->lru[i]);
>  	man->move = NULL;
> +}
> +EXPORT_SYMBOL(ttm_bo_init_mm_base);
>  
> +int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> +			unsigned long p_size)
> +{
> +	int ret;
> +	struct ttm_mem_type_manager *man;
> +
> +	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> +	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
> +
> +	if (type != TTM_PL_SYSTEM) {
> +		ret = (*man->func->init)(man, p_size);
> +		if (ret)
> +			return ret;
> +	}
> +	ttm_bo_use_mm(man);
>  	return 0;
>  }
>  EXPORT_SYMBOL(ttm_bo_init_mm);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index a9e13b252820..0060925f507a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
>   * -ENOMEM: Not enough memory.
>   * May also return driver-specified errors.
>   */
> +struct ttm_mem_type_manager;
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size);
>  int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
>  		   unsigned long p_size);
>  
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 7958e411269a..68e75c3b8c7a 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>  	dma_resv_unlock(bo->base.resv);
>  }
>  
> +static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +{
> +	man->has_type = true;
> +	man->use_type = true;
> +}
> +
>  /*
>   * ttm_bo_util.c
>   */
> -- 
> 2.26.2
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH 03/49] drm/ttm: split the mm manager init code
  2020-07-31  5:44   ` Sam Ravnborg
@ 2020-07-31  5:51     ` Dave Airlie
  2020-07-31  6:26       ` Dave Airlie
  0 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  5:51 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Gerd Hoffmann, Roland Scheidegger, Koenig, Christian, dri-devel,
	Ben Skeggs

On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg <sam@ravnborg.org> wrote:
>
> Hi Dave.
>
> On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > This will allow the driver to control the ordering here better.
> >
> > Eventually the old path will be removed.
> >
> > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > ---
> >  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
> >  include/drm/ttm/ttm_bo_api.h    |  4 ++++
> >  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
> >  3 files changed, 30 insertions(+), 14 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 041a0e73cd1b..a658fd584c6d 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> >  }
> >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> >
> > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > -                     unsigned long p_size)
> > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > +                      struct ttm_mem_type_manager *man,
> > +                      unsigned long p_size)
> >  {
>
> General comment for all the ttm/* changes.
> It would be very nice with some nice explanations for the exported
> functions, preferably in kernel-doc style.
> In case someone that are more or less clueless (like me) would like
> to understand how a function is to be used or maybe reviewing some
> random code.

Good point, I just need to make sure I don't add anything for
something I remove later, but I should definitely add some for the new
interfaces.

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

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

* Re: [PATCH 03/49] drm/ttm: split the mm manager init code
  2020-07-31  5:51     ` Dave Airlie
@ 2020-07-31  6:26       ` Dave Airlie
  2020-07-31  6:43         ` Sam Ravnborg
  0 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  6:26 UTC (permalink / raw)
  To: Sam Ravnborg
  Cc: Gerd Hoffmann, Roland Scheidegger, Koenig, Christian, dri-devel,
	Ben Skeggs

On Fri, 31 Jul 2020 at 15:51, Dave Airlie <airlied@gmail.com> wrote:
>
> On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg <sam@ravnborg.org> wrote:
> >
> > Hi Dave.
> >
> > On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > > From: Dave Airlie <airlied@redhat.com>
> > >
> > > This will allow the driver to control the ordering here better.
> > >
> > > Eventually the old path will be removed.
> > >
> > > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > > ---
> > >  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
> > >  include/drm/ttm/ttm_bo_api.h    |  4 ++++
> > >  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
> > >  3 files changed, 30 insertions(+), 14 deletions(-)
> > >
> > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > > index 041a0e73cd1b..a658fd584c6d 100644
> > > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> > >  }
> > >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> > >
> > > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > > -                     unsigned long p_size)
> > > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > > +                      struct ttm_mem_type_manager *man,
> > > +                      unsigned long p_size)
> > >  {
> >
> > General comment for all the ttm/* changes.
> > It would be very nice with some nice explanations for the exported
> > functions, preferably in kernel-doc style.
> > In case someone that are more or less clueless (like me) would like
> > to understand how a function is to be used or maybe reviewing some
> > random code.
>
> Good point, I just need to make sure I don't add anything for
> something I remove later, but I should definitely add some for the new
> interfaces.

The version in my git branch has docs for all the new apis now.

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

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

* Re: [PATCH 03/49] drm/ttm: split the mm manager init code
  2020-07-31  6:26       ` Dave Airlie
@ 2020-07-31  6:43         ` Sam Ravnborg
  0 siblings, 0 replies; 99+ messages in thread
From: Sam Ravnborg @ 2020-07-31  6:43 UTC (permalink / raw)
  To: Dave Airlie
  Cc: Gerd Hoffmann, Roland Scheidegger, Koenig, Christian, dri-devel,
	Ben Skeggs

On Fri, Jul 31, 2020 at 04:26:08PM +1000, Dave Airlie wrote:
> On Fri, 31 Jul 2020 at 15:51, Dave Airlie <airlied@gmail.com> wrote:
> >
> > On Fri, 31 Jul 2020 at 15:44, Sam Ravnborg <sam@ravnborg.org> wrote:
> > >
> > > Hi Dave.
> > >
> > > On Fri, Jul 31, 2020 at 02:04:34PM +1000, Dave Airlie wrote:
> > > > From: Dave Airlie <airlied@redhat.com>
> > > >
> > > > This will allow the driver to control the ordering here better.
> > > >
> > > > Eventually the old path will be removed.
> > > >
> > > > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > > > ---
> > > >  drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
> > > >  include/drm/ttm/ttm_bo_api.h    |  4 ++++
> > > >  include/drm/ttm/ttm_bo_driver.h |  6 ++++++
> > > >  3 files changed, 30 insertions(+), 14 deletions(-)
> > > >
> > > > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > > > index 041a0e73cd1b..a658fd584c6d 100644
> > > > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > > > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > > > @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> > > >  }
> > > >  EXPORT_SYMBOL(ttm_bo_evict_mm);
> > > >
> > > > -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> > > > -                     unsigned long p_size)
> > > > +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> > > > +                      struct ttm_mem_type_manager *man,
> > > > +                      unsigned long p_size)
> > > >  {
> > >
> > > General comment for all the ttm/* changes.
> > > It would be very nice with some nice explanations for the exported
> > > functions, preferably in kernel-doc style.
> > > In case someone that are more or less clueless (like me) would like
> > > to understand how a function is to be used or maybe reviewing some
> > > random code.
> >
> > Good point, I just need to make sure I don't add anything for
> > something I remove later, but I should definitely add some for the new
> > interfaces.
> 
> The version in my git branch has docs for all the new apis now.
Thanks!

And now I am more or less oblieged to read/review the docs when you
submit v2 - yeah, more reviews.

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

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

* Re: [PATCH 02/49] drm/vram-helper: call the ttm manager debug function
  2020-07-31  4:04 ` [PATCH 02/49] drm/vram-helper: call the ttm manager debug function Dave Airlie
@ 2020-07-31  6:43   ` Thomas Zimmermann
  0 siblings, 0 replies; 99+ messages in thread
From: Thomas Zimmermann @ 2020-07-31  6:43 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: kraxel, sroland, christian.koenig, bskeggs


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

Hi

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
> 
> This code was assuming there was a drm_mm here, don't do
> that call the correct API.

Maybe put a semicolon after 'that' for readability.

> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>

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

> ---
>  drivers/gpu/drm/drm_gem_vram_helper.c | 6 ++----
>  1 file changed, 2 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index a93a00966f3a..b6f158ab0f5a 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -1075,12 +1075,10 @@ static int drm_vram_mm_debugfs(struct seq_file *m, void *data)
>  {
>  	struct drm_info_node *node = (struct drm_info_node *) m->private;
>  	struct drm_vram_mm *vmm = node->minor->dev->vram_mm;
> -	struct drm_mm *mm = vmm->bdev.man[TTM_PL_VRAM].priv;
> +	struct ttm_mem_type_manager *man = &vmm->bdev.man[TTM_PL_VRAM];
>  	struct drm_printer p = drm_seq_file_printer(m);
>  
> -	spin_lock(&ttm_bo_glob.lru_lock);
> -	drm_mm_print(mm, &p);
> -	spin_unlock(&ttm_bo_glob.lru_lock);
> +	man->func->debug(man, &p);
>  	return 0;
>  }
>  
> 

-- 
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] 99+ messages in thread

* Re: [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager.
  2020-07-31  4:04 ` [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager Dave Airlie
@ 2020-07-31  6:57   ` Thomas Zimmermann
  2020-07-31  7:03     ` Thomas Zimmermann
  2020-07-31  7:20     ` Dave Airlie
  2020-07-31 13:00   ` Christian König
  1 sibling, 2 replies; 99+ messages in thread
From: Thomas Zimmermann @ 2020-07-31  6:57 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: kraxel, sroland, christian.koenig, bskeggs


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

Hi

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
> 
> This lets the generic mm manager be initialised by the driver.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo_manager.c | 23 ++++++++++++++++++++---
>  include/drm/ttm/ttm_bo_driver.h      |  3 +++
>  2 files changed, 23 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index facd3049c3aa..64234e5caee3 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -104,8 +104,8 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
>  	}
>  }
>  
> -static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
> -			   unsigned long p_size)
> +static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
> +		    unsigned long p_size)
>  {
>  	struct ttm_range_manager *rman;
>  
> @@ -119,6 +119,23 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
>  	return 0;
>  }
>  
> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
> +		    struct ttm_mem_type_manager *man,
> +		    unsigned long p_size)
> +{
> +	int ret;
> +
> +	man->func = &ttm_bo_manager_func;

Overriding man->func is the only reason for drivers to call
ttm_bo_man_init_mm_base and ttm_bo_use_mm directly (e.g., as in nouveau)?

If so, Wouldn't it be better to do

  if (!man->func)
      man->func = &ttm_bo_manager_func;

in ttm_bo_man_init and forget about the other fucntions?

Best regards
Thomas

> +
> +	ttm_bo_init_mm_base(bdev, man, p_size);
> +	ret = ttm_bo_man_init_private(man, p_size);
> +	if (ret)
> +		return ret;
> +	ttm_bo_use_mm(man);
> +	return 0;
> +}
> +EXPORT_SYMBOL(ttm_bo_man_init);
> +
>  static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
>  {
>  	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> @@ -147,7 +164,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>  }
>  
>  const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
> -	.init = ttm_bo_man_init,
> +	.init = ttm_bo_man_init_private,
>  	.takedown = ttm_bo_man_takedown,
>  	.get_node = ttm_bo_man_get_node,
>  	.put_node = ttm_bo_man_put_node,
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 68e75c3b8c7a..5c4ccefd5393 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -799,6 +799,9 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
>   */
>  pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
>  
> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
> +		    struct ttm_mem_type_manager *man,
> +		    unsigned long p_size);
>  extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
>  
>  #endif
> 

-- 
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] 99+ messages in thread

* Re: [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager.
  2020-07-31  6:57   ` Thomas Zimmermann
@ 2020-07-31  7:03     ` Thomas Zimmermann
  2020-07-31  7:20     ` Dave Airlie
  1 sibling, 0 replies; 99+ messages in thread
From: Thomas Zimmermann @ 2020-07-31  7:03 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: kraxel, sroland, christian.koenig, bskeggs


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



Am 31.07.20 um 08:57 schrieb Thomas Zimmermann:
> Hi
> 
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
>> From: Dave Airlie <airlied@redhat.com>
>>
>> This lets the generic mm manager be initialised by the driver.
>>
>> Signed-off-by: Dave Airlie <airlied@redhat.com>
>> ---
>>  drivers/gpu/drm/ttm/ttm_bo_manager.c | 23 ++++++++++++++++++++---
>>  include/drm/ttm/ttm_bo_driver.h      |  3 +++
>>  2 files changed, 23 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
>> index facd3049c3aa..64234e5caee3 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
>> @@ -104,8 +104,8 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
>>  	}
>>  }
>>  
>> -static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
>> -			   unsigned long p_size)
>> +static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
>> +		    unsigned long p_size)
>>  {
>>  	struct ttm_range_manager *rman;
>>  
>> @@ -119,6 +119,23 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
>>  	return 0;
>>  }
>>  
>> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
>> +		    struct ttm_mem_type_manager *man,
>> +		    unsigned long p_size)
>> +{
>> +	int ret;
>> +
>> +	man->func = &ttm_bo_manager_func;
> 
> Overriding man->func is the only reason for drivers to call
> ttm_bo_man_init_mm_base and ttm_bo_use_mm directly (e.g., as in nouveau)?
> 
> If so, Wouldn't it be better to do
> 
>   if (!man->func)
>       man->func = &ttm_bo_manager_func;
> 
> in ttm_bo_man_init and forget about the other fucntions?
> 
> Best regards
> Thomas
> 
>> +
>> +	ttm_bo_init_mm_base(bdev, man, p_size);
>> +	ret = ttm_bo_man_init_private(man, p_size);

Oh, I just realized that this line's also missing in nouveau.

>> +	if (ret)
>> +		return ret;
>> +	ttm_bo_use_mm(man);
>> +	return 0;
>> +}
>> +EXPORT_SYMBOL(ttm_bo_man_init);
>> +
>>  static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
>>  {
>>  	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
>> @@ -147,7 +164,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>>  }
>>  
>>  const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
>> -	.init = ttm_bo_man_init,
>> +	.init = ttm_bo_man_init_private,
>>  	.takedown = ttm_bo_man_takedown,
>>  	.get_node = ttm_bo_man_get_node,
>>  	.put_node = ttm_bo_man_put_node,
>> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
>> index 68e75c3b8c7a..5c4ccefd5393 100644
>> --- a/include/drm/ttm/ttm_bo_driver.h
>> +++ b/include/drm/ttm/ttm_bo_driver.h
>> @@ -799,6 +799,9 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
>>   */
>>  pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
>>  
>> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
>> +		    struct ttm_mem_type_manager *man,
>> +		    unsigned long p_size);
>>  extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
>>  
>>  #endif
>>
> 

-- 
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] 99+ messages in thread

* Re: [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.
  2020-07-31  4:04 ` [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev Dave Airlie
@ 2020-07-31  7:14   ` Thomas Zimmermann
  2020-07-31  7:21     ` Dave Airlie
  2020-07-31 13:23   ` Christian König
  1 sibling, 1 reply; 99+ messages in thread
From: Thomas Zimmermann @ 2020-07-31  7:14 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: kraxel, sroland, christian.koenig, bskeggs


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

Hi

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
> 
> This will allow different abstractions later.

You should consider moving this patch to the beginning of the series, so
that patches 1 to 25 can benefit from it.

Best regards
Thomas

> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c      | 34 +++++++++++++++----------------
>  drivers/gpu/drm/ttm/ttm_bo_util.c | 20 +++++++++---------
>  drivers/gpu/drm/ttm/ttm_bo_vm.c   |  2 +-
>  include/drm/ttm/ttm_bo_driver.h   |  6 ++++++
>  4 files changed, 34 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 07c653374f15..7c6389ea067f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -80,7 +80,7 @@ static inline int ttm_mem_type_from_place(const struct ttm_place *place,
>  static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p,
>  			       int mem_type)
>  {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
>  
>  	drm_printf(p, "    has_type: %d\n", man->has_type);
>  	drm_printf(p, "    use_type: %d\n", man->use_type);
> @@ -156,7 +156,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
>  	if (mem->placement & TTM_PL_FLAG_NO_EVICT)
>  		return;
>  
> -	man = &bdev->man[mem->mem_type];
> +	man = ttm_manager_type(bdev, mem->mem_type);
>  	list_add_tail(&bo->lru, &man->lru[bo->priority]);
>  
>  	if (man->use_tt && bo->ttm &&
> @@ -231,7 +231,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
>  		dma_resv_assert_held(pos->first->base.resv);
>  		dma_resv_assert_held(pos->last->base.resv);
>  
> -		man = &pos->first->bdev->man[TTM_PL_TT];
> +		man = ttm_manager_type(pos->first->bdev, TTM_PL_TT);
>  		list_bulk_move_tail(&man->lru[i], &pos->first->lru,
>  				    &pos->last->lru);
>  	}
> @@ -246,7 +246,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
>  		dma_resv_assert_held(pos->first->base.resv);
>  		dma_resv_assert_held(pos->last->base.resv);
>  
> -		man = &pos->first->bdev->man[TTM_PL_VRAM];
> +		man = ttm_manager_type(pos->first->bdev, TTM_PL_VRAM);
>  		list_bulk_move_tail(&man->lru[i], &pos->first->lru,
>  				    &pos->last->lru);
>  	}
> @@ -272,8 +272,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>  				  struct ttm_operation_ctx *ctx)
>  {
>  	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *old_man = &bdev->man[bo->mem.mem_type];
> -	struct ttm_mem_type_manager *new_man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *old_man = ttm_manager_type(bdev, bo->mem.mem_type);
> +	struct ttm_mem_type_manager *new_man = ttm_manager_type(bdev, mem->mem_type);
>  	int ret;
>  
>  	ret = ttm_mem_io_lock(old_man, true);
> @@ -338,7 +338,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>  	return 0;
>  
>  out_err:
> -	new_man = &bdev->man[bo->mem.mem_type];
> +	new_man = ttm_manager_type(bdev, bo->mem.mem_type);
>  	if (!new_man->use_tt) {
>  		ttm_tt_destroy(bo->ttm);
>  		bo->ttm = NULL;
> @@ -550,7 +550,7 @@ static void ttm_bo_release(struct kref *kref)
>  	struct ttm_buffer_object *bo =
>  	    container_of(kref, struct ttm_buffer_object, kref);
>  	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, bo->mem.mem_type);
>  	size_t acc_size = bo->acc_size;
>  	int ret;
>  
> @@ -838,7 +838,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
>  			  const struct ttm_place *place,
>  			  struct ttm_mem_reg *mem)
>  {
> -	struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
>  
>  	mem->mm_node = NULL;
>  	if (!man->func || !man->func->get_node)
> @@ -849,7 +849,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
>  
>  void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
>  {
> -	struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
>  
>  	if (!man->func || !man->func->put_node)
>  		return;
> @@ -906,7 +906,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
>  				  struct ttm_operation_ctx *ctx)
>  {
>  	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
>  	struct ww_acquire_ctx *ticket;
>  	int ret;
>  
> @@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
>  	if (ret)
>  		return ret;
>  
> -	man = &bdev->man[mem_type];
> +	man = ttm_manager_type(bdev, mem_type);
>  	if (!man->has_type || !man->use_type)
>  		return -EBUSY;
>  
> @@ -1059,7 +1059,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>  		if (unlikely(ret))
>  			goto error;
>  
> -		man = &bdev->man[mem->mem_type];
> +		man = ttm_manager_type(bdev, mem->mem_type);
>  		ret = ttm_bo_add_move_fence(bo, man, mem, ctx->no_wait_gpu);
>  		if (unlikely(ret)) {
>  			ttm_bo_mem_put(bo, mem);
> @@ -1448,7 +1448,7 @@ EXPORT_SYMBOL(ttm_bo_force_list_clean);
>  
>  int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>  {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
>  
>  	if (mem_type == 0 || mem_type >= TTM_NUM_MEM_TYPES) {
>  		pr_err("Illegal memory manager memory type %u\n", mem_type);
> @@ -1551,7 +1551,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>  	unsigned i;
>  	struct ttm_mem_type_manager *man;
>  
> -	man = &bdev->man[TTM_PL_SYSTEM];
> +	man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
>  	ttm_bo_disable_mm(man);
>  
>  	mutex_lock(&ttm_global_mutex);
> @@ -1578,7 +1578,7 @@ EXPORT_SYMBOL(ttm_bo_device_release);
>  
>  static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
>  {
> -	struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_SYSTEM];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
>  
>  	/*
>  	 * Initialize the system memory buffer type.
> @@ -1642,7 +1642,7 @@ void ttm_bo_unmap_virtual_locked(struct ttm_buffer_object *bo)
>  void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)
>  {
>  	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, bo->mem.mem_type);
>  
>  	ttm_mem_io_lock(man, false);
>  	ttm_bo_unmap_virtual_locked(bo);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index 1f502be0b646..879c8ded0cd8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -129,7 +129,7 @@ static int ttm_mem_io_evict(struct ttm_mem_type_manager *man)
>  int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
>  		       struct ttm_mem_reg *mem)
>  {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
>  	int ret;
>  
>  	if (mem->bus.io_reserved_count++)
> @@ -162,7 +162,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
>  
>  int ttm_mem_io_reserve_vm(struct ttm_buffer_object *bo)
>  {
> -	struct ttm_mem_type_manager *man = &bo->bdev->man[bo->mem.mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, bo->mem.mem_type);
>  	struct ttm_mem_reg *mem = &bo->mem;
>  	int ret;
>  
> @@ -195,7 +195,7 @@ static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev,
>  			       struct ttm_mem_reg *mem,
>  			       void **virtual)
>  {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
>  	int ret;
>  	void *addr;
>  
> @@ -232,7 +232,7 @@ static void ttm_mem_reg_iounmap(struct ttm_bo_device *bdev,
>  {
>  	struct ttm_mem_type_manager *man;
>  
> -	man = &bdev->man[mem->mem_type];
> +	man = ttm_manager_type(bdev, mem->mem_type);
>  
>  	if (virtual && mem->bus.addr == NULL)
>  		iounmap(virtual);
> @@ -303,7 +303,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
>  		       struct ttm_mem_reg *new_mem)
>  {
>  	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
>  	struct ttm_tt *ttm = bo->ttm;
>  	struct ttm_mem_reg *old_mem = &bo->mem;
>  	struct ttm_mem_reg old_copy = *old_mem;
> @@ -571,7 +571,7 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo,
>  		struct ttm_bo_kmap_obj *map)
>  {
>  	struct ttm_mem_type_manager *man =
> -		&bo->bdev->man[bo->mem.mem_type];
> +		ttm_manager_type(bo->bdev, bo->mem.mem_type);
>  	unsigned long offset, size;
>  	int ret;
>  
> @@ -601,7 +601,7 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
>  {
>  	struct ttm_buffer_object *bo = map->bo;
>  	struct ttm_mem_type_manager *man =
> -		&bo->bdev->man[bo->mem.mem_type];
> +		ttm_manager_type(bo->bdev, bo->mem.mem_type);
>  
>  	if (!map->virtual)
>  		return;
> @@ -634,7 +634,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
>  			      struct ttm_mem_reg *new_mem)
>  {
>  	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
>  	struct ttm_mem_reg *old_mem = &bo->mem;
>  	int ret;
>  	struct ttm_buffer_object *ghost_obj;
> @@ -697,8 +697,8 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
>  	struct ttm_bo_device *bdev = bo->bdev;
>  	struct ttm_mem_reg *old_mem = &bo->mem;
>  
> -	struct ttm_mem_type_manager *from = &bdev->man[old_mem->mem_type];
> -	struct ttm_mem_type_manager *to = &bdev->man[new_mem->mem_type];
> +	struct ttm_mem_type_manager *from = ttm_manager_type(bdev, old_mem->mem_type);
> +	struct ttm_mem_type_manager *to = ttm_manager_type(bdev, new_mem->mem_type);
>  
>  	int ret;
>  
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index 468a0eb9e632..5ae679184eb5 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -282,7 +282,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
>  	vm_fault_t ret = VM_FAULT_NOPAGE;
>  	unsigned long address = vmf->address;
>  	struct ttm_mem_type_manager *man =
> -		&bdev->man[bo->mem.mem_type];
> +		ttm_manager_type(bdev, bo->mem.mem_type);
>  
>  	/*
>  	 * Refuse to fault imported pages. This should be handled
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 9d066529ca61..ec25451b503f 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -444,6 +444,12 @@ struct ttm_bo_device {
>  	bool no_retry;
>  };
>  
> +static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
> +							    int mem_type)
> +{
> +	return &bdev->man[mem_type];
> +}
> +
>  /**
>   * struct ttm_lru_bulk_move_pos
>   *
> 

-- 
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] 99+ messages in thread

* Re: [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager.
  2020-07-31  6:57   ` Thomas Zimmermann
  2020-07-31  7:03     ` Thomas Zimmermann
@ 2020-07-31  7:20     ` Dave Airlie
  1 sibling, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  7:20 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: Gerd Hoffmann, Roland Scheidegger, Koenig, Christian, dri-devel,
	Ben Skeggs

On Fri, 31 Jul 2020 at 16:57, Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Hi
>
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > This lets the generic mm manager be initialised by the driver.
> >
> > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > ---
> >  drivers/gpu/drm/ttm/ttm_bo_manager.c | 23 ++++++++++++++++++++---
> >  include/drm/ttm/ttm_bo_driver.h      |  3 +++
> >  2 files changed, 23 insertions(+), 3 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> > index facd3049c3aa..64234e5caee3 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> > @@ -104,8 +104,8 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
> >       }
> >  }
> >
> > -static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
> > -                        unsigned long p_size)
> > +static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
> > +                 unsigned long p_size)
> >  {
> >       struct ttm_range_manager *rman;
> >
> > @@ -119,6 +119,23 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
> >       return 0;
> >  }
> >
> > +int ttm_bo_man_init(struct ttm_bo_device *bdev,
> > +                 struct ttm_mem_type_manager *man,
> > +                 unsigned long p_size)
> > +{
> > +     int ret;
> > +
> > +     man->func = &ttm_bo_manager_func;
>
> Overriding man->func is the only reason for drivers to call
> ttm_bo_man_init_mm_base and ttm_bo_use_mm directly (e.g., as in nouveau)?
>
> If so, Wouldn't it be better to do
>
>   if (!man->func)
>       man->func = &ttm_bo_manager_func;
>
> in ttm_bo_man_init and forget about the other fucntions?

No ttm_bo_man_init, is just for the range manager, if you want to use
it, it's not generic code for driver manager that want to use a
different manager class (like nouveau).

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

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

* Re: [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.
  2020-07-31  7:14   ` Thomas Zimmermann
@ 2020-07-31  7:21     ` Dave Airlie
  2020-07-31 13:18       ` daniel
  0 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-07-31  7:21 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: Gerd Hoffmann, Roland Scheidegger, Koenig, Christian, dri-devel,
	Ben Skeggs

On Fri, 31 Jul 2020 at 17:14, Thomas Zimmermann <tzimmermann@suse.de> wrote:
>
> Hi
>
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > This will allow different abstractions later.
>
> You should consider moving this patch to the beginning of the series, so
> that patches 1 to 25 can benefit from it.

I did consider it, but I'd have to move all the follow on patches as
well, and it got messy in rebase land, and I started introducing
errors, so I left it alone, and it's not necessary until the patch
that changes it's definition anyways.

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

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

* Re: [PATCH 03/49] drm/ttm: split the mm manager init code
  2020-07-31  4:04 ` [PATCH 03/49] drm/ttm: split the mm manager init code Dave Airlie
  2020-07-31  5:44   ` Sam Ravnborg
@ 2020-07-31  9:12   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31  9:12 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This will allow the driver to control the ordering here better.
>
> Eventually the old path will be removed.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    | 34 +++++++++++++++++++--------------
>   include/drm/ttm/ttm_bo_api.h    |  4 ++++
>   include/drm/ttm/ttm_bo_driver.h |  6 ++++++
>   3 files changed, 30 insertions(+), 14 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 041a0e73cd1b..a658fd584c6d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1503,35 +1503,41 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   }
>   EXPORT_SYMBOL(ttm_bo_evict_mm);
>   
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> -			unsigned long p_size)
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size)
>   {
> -	int ret;
> -	struct ttm_mem_type_manager *man;
>   	unsigned i;
>   
> -	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> -	man = &bdev->man[type];
>   	BUG_ON(man->has_type);
>   	man->use_io_reserve_lru = false;
>   	mutex_init(&man->io_reserve_mutex);
>   	spin_lock_init(&man->move_lock);
>   	INIT_LIST_HEAD(&man->io_reserve_lru);
>   	man->bdev = bdev;
> -
> -	if (type != TTM_PL_SYSTEM) {
> -		ret = (*man->func->init)(man, p_size);
> -		if (ret)
> -			return ret;
> -	}
> -	man->has_type = true;
> -	man->use_type = true;
>   	man->size = p_size;
>   
>   	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
>   		INIT_LIST_HEAD(&man->lru[i]);
>   	man->move = NULL;
> +}
> +EXPORT_SYMBOL(ttm_bo_init_mm_base);
>   
> +int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> +			unsigned long p_size)
> +{
> +	int ret;
> +	struct ttm_mem_type_manager *man;
> +
> +	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> +	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
> +
> +	if (type != TTM_PL_SYSTEM) {
> +		ret = (*man->func->init)(man, p_size);
> +		if (ret)
> +			return ret;
> +	}
> +	ttm_bo_use_mm(man);
>   	return 0;
>   }
>   EXPORT_SYMBOL(ttm_bo_init_mm);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index a9e13b252820..0060925f507a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -546,6 +546,10 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
>    * -ENOMEM: Not enough memory.
>    * May also return driver-specified errors.
>    */
> +struct ttm_mem_type_manager;
> +void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> +			 struct ttm_mem_type_manager *man,
> +			 unsigned long p_size);

As I wrote before I would completely rename the backend functions to 
ttm_resource_* since this is not related to the buffer objects in any way.

Moving a good bunch of the handling into a separate file might be a good 
idea as well. But that can obviously come later as well.

Christian.

>   int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
>   		   unsigned long p_size);
>   
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 7958e411269a..68e75c3b8c7a 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -678,6 +678,12 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>   	dma_resv_unlock(bo->base.resv);
>   }
>   
> +static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +{
> +	man->has_type = true;
> +	man->use_type = true;
> +}
> +
>   /*
>    * ttm_bo_util.c
>    */

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

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

* Re: [PATCH 00/49] ttm mem manager refactoring.
  2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
                   ` (48 preceding siblings ...)
  2020-07-31  4:05 ` [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get Dave Airlie
@ 2020-07-31  9:17 ` Christian König
  2020-07-31  9:29   ` daniel
  2020-08-03  7:12   ` Dave Airlie
  49 siblings, 2 replies; 99+ messages in thread
From: Christian König @ 2020-07-31  9:17 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> I started pulling on a thread, and it led me down a hole.

We might want to make that hole even bigger :)

How about we rename the ttm_mem_reg into ttm_resource and 
ttm_mem_type_manager into ttm_resource_manager.

Neither amdgpu's OA/GWS resources nor the IDs in VMGFX are really memory.

In the long term I also want to move the whole address handling into 
each backend.

Going to send comments on the individual patches as well.

> This series refactors the ttm ttm_mem_type_manager object into
> a driver owned, allocated, subclassaed object.
>
> It starts with two minor fixes for some bad assumptions in two drivers.
>
> Enables a new init path, ports all the drivers to the new init
> path, and cleans up the old init path.
> Enables a new takedown path, ports all the drivers to the new takedown
> path, and cleans up the old takedown path
> Wraps all access to the memory managers in the bo_device in a wrapper
> across all drivers.
> Make debug callback optional
> Enables driver to provide their own mem manager objects
> Subclasses the objects in all drivers and makes them into driver owned object
> Drops the bo_device arrays of pointers, and some unneeded links and
> struct members
> Cleans up one api.
>
> I think I'd probably want to merge all this via drm-misc, so if I can collect
> acks/r-b from driver maintainers that would be good.
>
> This is also based on Chrisitan's work to remove init_mem_type, so it won't
> apply until he's finished getting all of that into drm-misc.

Preparing to push that to drm-misc-next just now.

Regards,
Christian.

>
> https://nam11.safelinks.protection.outlook.com/?url=https:%2F%2Fcgit.freedesktop.org%2F~airlied%2Flinux%2Flog%2F%3Fh%3Dttm-refactor-mem-manager&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Caa32512acf9f4bf455ef08d83506f9d2%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637317651361302583&amp;sdata=2sQt4A48ODl0Nq4P21YG3vRNdhkDZcZp0XHkQ930SAI%3D&amp;reserved=0
> is the tree I've built this on top off, so it's probably going to get rebased
> but the code should stay mostly the same.
>
> I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
> amdgpu soon.
>
> Dave.
>
>

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

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

* Re: [PATCH 00/49] ttm mem manager refactoring.
  2020-07-31  9:17 ` [PATCH 00/49] ttm mem manager refactoring Christian König
@ 2020-07-31  9:29   ` daniel
  2020-07-31 13:01     ` Christian König
  2020-08-03  7:12   ` Dave Airlie
  1 sibling, 1 reply; 99+ messages in thread
From: daniel @ 2020-07-31  9:29 UTC (permalink / raw)
  Cc: sroland, bskeggs, dri-devel, kraxel

On Fri, Jul 31, 2020 at 11:17:26AM +0200, Christian König wrote:
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > I started pulling on a thread, and it led me down a hole.
> 
> We might want to make that hole even bigger :)
> 
> How about we rename the ttm_mem_reg into ttm_resource and
> ttm_mem_type_manager into ttm_resource_manager.

+1 on names I can understand, I alwas get confused about what exactly ttm
means with mem_reg and mem_type_manager.
-Daniel

> 
> Neither amdgpu's OA/GWS resources nor the IDs in VMGFX are really memory.
> 
> In the long term I also want to move the whole address handling into each
> backend.
> 
> Going to send comments on the individual patches as well.
> 
> > This series refactors the ttm ttm_mem_type_manager object into
> > a driver owned, allocated, subclassaed object.
> > 
> > It starts with two minor fixes for some bad assumptions in two drivers.
> > 
> > Enables a new init path, ports all the drivers to the new init
> > path, and cleans up the old init path.
> > Enables a new takedown path, ports all the drivers to the new takedown
> > path, and cleans up the old takedown path
> > Wraps all access to the memory managers in the bo_device in a wrapper
> > across all drivers.
> > Make debug callback optional
> > Enables driver to provide their own mem manager objects
> > Subclasses the objects in all drivers and makes them into driver owned object
> > Drops the bo_device arrays of pointers, and some unneeded links and
> > struct members
> > Cleans up one api.
> > 
> > I think I'd probably want to merge all this via drm-misc, so if I can collect
> > acks/r-b from driver maintainers that would be good.
> > 
> > This is also based on Chrisitan's work to remove init_mem_type, so it won't
> > apply until he's finished getting all of that into drm-misc.
> 
> Preparing to push that to drm-misc-next just now.
> 
> Regards,
> Christian.
> 
> > 
> > https://nam11.safelinks.protection.outlook.com/?url=https:%2F%2Fcgit.freedesktop.org%2F~airlied%2Flinux%2Flog%2F%3Fh%3Dttm-refactor-mem-manager&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Caa32512acf9f4bf455ef08d83506f9d2%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637317651361302583&amp;sdata=2sQt4A48ODl0Nq4P21YG3vRNdhkDZcZp0XHkQ930SAI%3D&amp;reserved=0
> > is the tree I've built this on top off, so it's probably going to get rebased
> > but the code should stay mostly the same.
> > 
> > I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
> > amdgpu soon.
> > 
> > Dave.
> > 
> > 
> 
> _______________________________________________
> 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] 99+ messages in thread

* Re: [PATCH 34/49] drm/ttm: make manager debug function optional
  2020-07-31  4:05 ` [PATCH 34/49] drm/ttm: make manager debug function optional Dave Airlie
@ 2020-07-31  9:46   ` daniel
  2020-07-31 13:03     ` Christian König
  2020-07-31 13:24   ` Christian König
  1 sibling, 1 reply; 99+ messages in thread
From: daniel @ 2020-07-31  9:46 UTC (permalink / raw)
  Cc: kraxel, sroland, christian.koenig, dri-devel, bskeggs

On Fri, Jul 31, 2020 at 02:05:05PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 92de8a6d7647..1e8fda1c9b3a 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -88,7 +88,7 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p
>  	drm_printf(p, "    size: %llu\n", man->size);
>  	drm_printf(p, "    available_caching: 0x%08X\n", man->available_caching);
>  	drm_printf(p, "    default_caching: 0x%08X\n", man->default_caching);
> -	if (mem_type != TTM_PL_SYSTEM)
> +	if (mem_type != TTM_PL_SYSTEM && man->func->debug)
>  		(*man->func->debug)(man, p);
>  }

Bit a bikeshed, but what about exporting this function (maybe with the man
as argument, not the bdev, mem_type pair) and using it in the first 2
patches? Avoids surprises with optional func->debug.
-Daniel

>  
> -- 
> 2.26.2
> 
> _______________________________________________
> 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] 99+ messages in thread

* Re: [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get.
  2020-07-31  4:05 ` [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get Dave Airlie
@ 2020-07-31  9:51   ` daniel
  2020-07-31 14:59   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: daniel @ 2020-07-31  9:51 UTC (permalink / raw)
  Cc: kraxel, sroland, christian.koenig, dri-devel, bskeggs

On Fri, Jul 31, 2020 at 02:05:20PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> This is probably something we could consider removing, vmwgfx
> is the only user, and we might be able to faciliate it another way
> 
> but for now just consolidate it all into accessors.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Maybe I'm missing something, but doesn't this boild down to:

tmm_mm_used(type) = (bool) ttm_manager_type(type)

now that all resource managers are explicitly registered? I think there's
nothing else left, your ttm_set_driver_manager essentially replaces
ttm_mm_set_use.
-Daniel

> ---
>  drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   |  4 ++--
>  drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  |  4 ++--
>  drivers/gpu/drm/nouveau/nouveau_ttm.c         |  8 ++++----
>  drivers/gpu/drm/ttm/ttm_bo.c                  |  6 +++---
>  drivers/gpu/drm/ttm/ttm_bo_manager.c          |  4 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 14 +++++++-------
>  drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
>  drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           |  4 ++--
>  include/drm/ttm/ttm_bo_driver.h               |  8 ++++----
>  9 files changed, 28 insertions(+), 28 deletions(-)
> 
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index b4480ca30988..7e84aa2c0064 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -128,7 +128,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>  	}
>  
>  	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  	return 0;
>  }
>  
> @@ -146,7 +146,7 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
>  	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>  	int ret;
>  
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>  
>  	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
>  	if (ret)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index f0e65a6fdf88..50949aa968fd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -205,7 +205,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>  		DRM_ERROR("Failed to register sysfs\n");
>  
>  	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  	return 0;
>  }
>  
> @@ -223,7 +223,7 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
>  	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>  	int ret;
>  
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>  
>  	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
>  	if (ret)
> diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> index 89521d3ed9da..32ce930d1bd8 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> @@ -176,7 +176,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
>  		man->use_io_reserve_lru = true;
>  		ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
>  		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
> -		ttm_bo_use_mm(man);
> +		ttm_mm_set_use(man, true);
>  		return 0;
>  	} else {
>  		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_VRAM,
> @@ -192,7 +192,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
>  	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
>  
>  	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
> -		ttm_bo_disable_mm(man);
> +		ttm_mm_set_use(man, false);
>  		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
>  		ttm_bo_man_cleanup(man);
>  		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, NULL);
> @@ -237,7 +237,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
>  	man->use_tt = true;
>  	ttm_bo_init_mm_base(man, size_pages);
>  	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  	return 0;
>  }
>  
> @@ -250,7 +250,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
>  	    drm->agp.bridge)
>  		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_TT);
>  	else {
> -		ttm_bo_disable_mm(man);
> +		ttm_mm_set_use(man, false);
>  		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
>  		ttm_bo_man_cleanup(man);
>  		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, NULL);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index bfc20cb27ed6..3bec6e4bc87d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
>  		return ret;
>  
>  	man = ttm_manager_type(bdev, mem_type);
> -	if (!man || !man->use_type)
> +	if (!man || !ttm_mm_used(man))
>  		return -EBUSY;
>  
>  	if (!ttm_bo_mt_compatible(man, mem_type, place, &cur_flags))
> @@ -1548,7 +1548,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>  	struct ttm_mem_type_manager *man;
>  
>  	man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>  
>  	mutex_lock(&ttm_global_mutex);
>  	list_del(&bdev->device_list);
> @@ -1585,7 +1585,7 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
>  	man->default_caching = TTM_PL_FLAG_CACHED;
>  
>  	ttm_bo_init_mm_base(man, 0);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  }
>  
>  int ttm_bo_device_init(struct ttm_bo_device *bdev,
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 6c6eedf84ca6..5ed4e4317789 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -139,7 +139,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>  	spin_lock_init(&rman->lock);
>  
>  	ttm_set_driver_manager(bdev, type, &rman->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  	return 0;
>  }
>  EXPORT_SYMBOL(ttm_bo_man_init);
> @@ -152,7 +152,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
>  	struct drm_mm *mm = &rman->mm;
>  	int ret;
>  
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>  
>  	ret = ttm_bo_force_list_clean(bdev, man);
>  	if (ret)
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 1849d913d521..9b9cc3b57a24 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -630,7 +630,7 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
>  			      TTM_PL_FLAG_CACHED, TTM_PL_FLAG_CACHED,
>  			      false, dev_priv->vram_size >> PAGE_SHIFT);
>  #endif
> -	ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM)->use_type = false;
> +	ttm_mm_set_use(ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM), false);
>  	return ret;
>  }
>  
> @@ -1190,9 +1190,9 @@ static void __vmw_svga_enable(struct vmw_private *dev_priv)
>  	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
>  
>  	spin_lock(&dev_priv->svga_lock);
> -	if (!man->use_type) {
> +	if (!ttm_mm_used(man)) {
>  		vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE);
> -		man->use_type = true;
> +		ttm_mm_set_use(man, true);
>  	}
>  	spin_unlock(&dev_priv->svga_lock);
>  }
> @@ -1221,8 +1221,8 @@ static void __vmw_svga_disable(struct vmw_private *dev_priv)
>  	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
>  
>  	spin_lock(&dev_priv->svga_lock);
> -	if (man->use_type) {
> -		man->use_type = false;
> +	if (ttm_mm_used(man)) {
> +		ttm_mm_set_use(man, false);
>  		vmw_write(dev_priv, SVGA_REG_ENABLE,
>  			  SVGA_REG_ENABLE_HIDE |
>  			  SVGA_REG_ENABLE_ENABLE);
> @@ -1255,8 +1255,8 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
>  	vmw_kms_lost_device(dev_priv->dev);
>  	ttm_write_lock(&dev_priv->reservation_sem, false);
>  	spin_lock(&dev_priv->svga_lock);
> -	if (man->use_type) {
> -		man->use_type = false;
> +	if (ttm_mm_used(man)) {
> +		ttm_mm_set_use(man, false);
>  		spin_unlock(&dev_priv->svga_lock);
>  		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
>  			DRM_ERROR("Failed evicting VRAM buffers.\n");
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> index 2b60957f7c4a..aff7767762ed 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> @@ -135,7 +135,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
>  	}
>  
>  	ttm_set_driver_manager(&dev_priv->bdev, type, &gman->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  	return 0;
>  }
>  
> @@ -144,7 +144,7 @@ void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
>  	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
>  	struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
>  
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>  
>  	ttm_bo_force_list_clean(&dev_priv->bdev, man);
>  
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> index d5a3eb709384..5a7b9b09785c 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> @@ -142,7 +142,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
>  	spin_lock_init(&rman->lock);
>  
>  	ttm_set_driver_manager(&dev_priv->bdev, TTM_PL_VRAM, &rman->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>  	return 0;
>  }
>  
> @@ -153,7 +153,7 @@ void vmw_thp_takedown(struct vmw_private *dev_priv)
>  	struct drm_mm *mm = &rman->mm;
>  	int ret;
>  
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>  
>  	ret = ttm_bo_force_list_clean(&dev_priv->bdev, man);
>  	if (ret)
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 702b3b056eda..6210acd5c651 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -668,14 +668,14 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>  	dma_resv_unlock(bo->base.resv);
>  }
>  
> -static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +static inline void ttm_mm_set_use(struct ttm_mem_type_manager *man, bool use)
>  {
> -	man->use_type = true;
> +	man->use_type = use;
>  }
>  
> -static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
> +static inline bool ttm_mm_used(struct ttm_mem_type_manager *man)
>  {
> -	man->use_type = false;
> +	return man->use_type;
>  }
>  
>  static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
> -- 
> 2.26.2
> 
> _______________________________________________
> 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] 99+ messages in thread

* Re: [PATCH 47/49] drm/ttm: drop list of memory managers from device.
  2020-07-31  4:05 ` [PATCH 47/49] drm/ttm: drop list of memory managers from device Dave Airlie
@ 2020-07-31  9:55   ` daniel
  2020-07-31 14:57   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: daniel @ 2020-07-31  9:55 UTC (permalink / raw)
  Cc: kraxel, sroland, christian.koenig, dri-devel, bskeggs

On Fri, Jul 31, 2020 at 02:05:18PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied@redhat.com>
> 
> The driver now controls these, the core just controls the system
> memory one.
> 
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>  drivers/gpu/drm/ttm/ttm_bo.c    | 2 --
>  include/drm/ttm/ttm_bo_driver.h | 6 ++++--
>  2 files changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index f2b41c4d7d51..f35548ff17e8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1608,8 +1608,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
>  
>  	bdev->driver = driver;
>  
> -	memset(bdev->man_priv, 0, sizeof(bdev->man_priv));
> -
>  	ttm_bo_init_sysman(bdev);
>  
>  	bdev->vma_manager = vma_manager;
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index bfc549782775..b2ffeaed94e7 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -414,7 +414,7 @@ struct ttm_bo_device {
>  	/*
>  	 * access via ttm_manager_type.
>  	 */
> -	struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
> +	struct ttm_mem_type_manager sysman; /* move to global */

Not sure we want to move this to global. With the shrinker rework ideas I
discussed with Christian somewhere (I think) we could easily do a
per-device shrinker. And then global kinda completely disappears (minus
maybe a drm-global limit on how much crap you can permanently pin in
system memory for scanout, but that's a different thing I think).
-Daniel

>  	struct ttm_mem_type_manager *man_drv[TTM_NUM_MEM_TYPES];
>  	/*
>  	 * Protected by internal locks.
> @@ -446,9 +446,11 @@ struct ttm_bo_device {
>  static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
>  							    int mem_type)
>  {
> +	if (mem_type == TTM_PL_SYSTEM)
> +		return &bdev->sysman;
>  	if (bdev->man_drv[mem_type])
>  		return bdev->man_drv[mem_type];
> -	return &bdev->man_priv[mem_type];
> +	return NULL;
>  }
>  
>  static inline void ttm_set_driver_manager(struct ttm_bo_device *bdev,
> -- 
> 2.26.2
> 
> _______________________________________________
> 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] 99+ messages in thread

* Re: [PATCH 12/49] drm/ttm: convert system manager init to new code.
  2020-07-31  4:04 ` [PATCH 12/49] drm/ttm: convert system manager init to new code Dave Airlie
@ 2020-07-31 12:57   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 12:57 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Remove the exit path, since this can't fail now.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 30 +++++++++++++++++-------------
>   1 file changed, 17 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index a658fd584c6d..476e768c5bd2 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1644,6 +1644,22 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>   }
>   EXPORT_SYMBOL(ttm_bo_device_release);
>   
> +static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
> +{
> +	struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_SYSTEM];
> +
> +	/*
> +	 * Initialize the system memory buffer type.
> +	 * Other types need to be driver / IOCTL initialized.
> +	 */
> +	man->use_tt = true;
> +	man->available_caching = TTM_PL_MASK_CACHING;
> +	man->default_caching = TTM_PL_FLAG_CACHED;
> +
> +	ttm_bo_init_mm_base(bdev, man, 0);
> +	ttm_bo_use_mm(man);
> +}
> +
>   int ttm_bo_device_init(struct ttm_bo_device *bdev,
>   		       struct ttm_bo_driver *driver,
>   		       struct address_space *mapping,
> @@ -1664,16 +1680,7 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
>   
>   	memset(bdev->man, 0, sizeof(bdev->man));
>   
> -	/*
> -	 * Initialize the system memory buffer type.
> -	 * Other types need to be driver / IOCTL initialized.
> -	 */
> -	bdev->man[TTM_PL_SYSTEM].use_tt = true;
> -	bdev->man[TTM_PL_SYSTEM].available_caching = TTM_PL_MASK_CACHING;
> -	bdev->man[TTM_PL_SYSTEM].default_caching = TTM_PL_FLAG_CACHED;
> -	ret = ttm_bo_init_mm(bdev, TTM_PL_SYSTEM, 0);
> -	if (unlikely(ret != 0))
> -		goto out_no_sys;
> +	ttm_bo_init_sysman(bdev);
>   
>   	bdev->vma_manager = vma_manager;
>   	INIT_DELAYED_WORK(&bdev->wq, ttm_bo_delayed_workqueue);
> @@ -1685,9 +1692,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
>   	mutex_unlock(&ttm_global_mutex);
>   
>   	return 0;
> -out_no_sys:
> -	ttm_bo_global_release();
> -	return ret;
>   }
>   EXPORT_SYMBOL(ttm_bo_device_init);
>   

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

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

* Re: [PATCH 13/49] drm/ttm: purge old manager init path.
  2020-07-31  4:04 ` [PATCH 13/49] drm/ttm: purge old manager init path Dave Airlie
@ 2020-07-31 12:58   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 12:58 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c         | 19 -------------------
>   drivers/gpu/drm/ttm/ttm_bo_manager.c | 27 +++++++++------------------
>   include/drm/ttm/ttm_bo_api.h         |  2 --
>   include/drm/ttm/ttm_bo_driver.h      | 14 --------------
>   4 files changed, 9 insertions(+), 53 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 476e768c5bd2..101a7910f9f7 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1523,25 +1523,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
>   }
>   EXPORT_SYMBOL(ttm_bo_init_mm_base);
>   
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> -			unsigned long p_size)
> -{
> -	int ret;
> -	struct ttm_mem_type_manager *man;
> -
> -	BUG_ON(type >= TTM_NUM_MEM_TYPES);
> -	ttm_bo_init_mm_base(bdev, &bdev->man[type], p_size);
> -
> -	if (type != TTM_PL_SYSTEM) {
> -		ret = (*man->func->init)(man, p_size);
> -		if (ret)
> -			return ret;
> -	}
> -	ttm_bo_use_mm(man);
> -	return 0;
> -}
> -EXPORT_SYMBOL(ttm_bo_init_mm);
> -
>   static void ttm_bo_global_kobj_release(struct kobject *kobj)
>   {
>   	struct ttm_bo_global *glob =
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 64234e5caee3..1877425abdf0 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -104,11 +104,18 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
>   	}
>   }
>   
> -static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
> +static const struct ttm_mem_type_manager_func ttm_bo_manager_func;
> +
> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
> +		    struct ttm_mem_type_manager *man,
>   		    unsigned long p_size)
>   {
>   	struct ttm_range_manager *rman;
>   
> +	man->func = &ttm_bo_manager_func;
> +
> +	ttm_bo_init_mm_base(bdev, man, p_size);
> +
>   	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
>   	if (!rman)
>   		return -ENOMEM;
> @@ -116,21 +123,7 @@ static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
>   	drm_mm_init(&rman->mm, 0, p_size);
>   	spin_lock_init(&rman->lock);
>   	man->priv = rman;
> -	return 0;
> -}
>   
> -int ttm_bo_man_init(struct ttm_bo_device *bdev,
> -		    struct ttm_mem_type_manager *man,
> -		    unsigned long p_size)
> -{
> -	int ret;
> -
> -	man->func = &ttm_bo_manager_func;
> -
> -	ttm_bo_init_mm_base(bdev, man, p_size);
> -	ret = ttm_bo_man_init_private(man, p_size);
> -	if (ret)
> -		return ret;
>   	ttm_bo_use_mm(man);
>   	return 0;
>   }
> @@ -163,11 +156,9 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>   	spin_unlock(&rman->lock);
>   }
>   
> -const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
> -	.init = ttm_bo_man_init_private,
> +static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
>   	.takedown = ttm_bo_man_takedown,
>   	.get_node = ttm_bo_man_get_node,
>   	.put_node = ttm_bo_man_put_node,
>   	.debug = ttm_bo_man_debug
>   };
> -EXPORT_SYMBOL(ttm_bo_manager_func);
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 0060925f507a..6562d1c5ac59 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -550,8 +550,6 @@ struct ttm_mem_type_manager;
>   void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
>   			 struct ttm_mem_type_manager *man,
>   			 unsigned long p_size);
> -int ttm_bo_init_mm(struct ttm_bo_device *bdev, unsigned type,
> -		   unsigned long p_size);
>   
>   /**
>    * ttm_bo_clean_mm
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 5c4ccefd5393..d0f1a6cdfba7 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -48,19 +48,6 @@
>   struct ttm_mem_type_manager;
>   
>   struct ttm_mem_type_manager_func {
> -	/**
> -	 * struct ttm_mem_type_manager member init
> -	 *
> -	 * @man: Pointer to a memory type manager.
> -	 * @p_size: Implementation dependent, but typically the size of the
> -	 * range to be managed in pages.
> -	 *
> -	 * Called to initialize a private range manager. The function is
> -	 * expected to initialize the man::priv member.
> -	 * Returns 0 on success, negative error code on failure.
> -	 */
> -	int  (*init)(struct ttm_mem_type_manager *man, unsigned long p_size);
> -
>   	/**
>   	 * struct ttm_mem_type_manager member takedown
>   	 *
> @@ -802,6 +789,5 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
>   int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   		    struct ttm_mem_type_manager *man,
>   		    unsigned long p_size);
> -extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
>   
>   #endif

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

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

* Re: [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager.
  2020-07-31  4:04 ` [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager Dave Airlie
  2020-07-31  6:57   ` Thomas Zimmermann
@ 2020-07-31 13:00   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:00 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This lets the generic mm manager be initialised by the driver.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo_manager.c | 23 ++++++++++++++++++++---
>   include/drm/ttm/ttm_bo_driver.h      |  3 +++
>   2 files changed, 23 insertions(+), 3 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index facd3049c3aa..64234e5caee3 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -104,8 +104,8 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
>   	}
>   }
>   
> -static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
> -			   unsigned long p_size)
> +static int ttm_bo_man_init_private(struct ttm_mem_type_manager *man,
> +		    unsigned long p_size)
>   {
>   	struct ttm_range_manager *rman;
>   
> @@ -119,6 +119,23 @@ static int ttm_bo_man_init(struct ttm_mem_type_manager *man,
>   	return 0;
>   }
>   
> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
> +		    struct ttm_mem_type_manager *man,
> +		    unsigned long p_size)
> +{
> +	int ret;
> +
> +	man->func = &ttm_bo_manager_func;
> +
> +	ttm_bo_init_mm_base(bdev, man, p_size);
> +	ret = ttm_bo_man_init_private(man, p_size);
> +	if (ret)
> +		return ret;
> +	ttm_bo_use_mm(man);
> +	return 0;
> +}
> +EXPORT_SYMBOL(ttm_bo_man_init);
> +
>   static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
>   {
>   	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> @@ -147,7 +164,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>   }
>   
>   const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
> -	.init = ttm_bo_man_init,
> +	.init = ttm_bo_man_init_private,
>   	.takedown = ttm_bo_man_takedown,
>   	.get_node = ttm_bo_man_get_node,
>   	.put_node = ttm_bo_man_put_node,
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 68e75c3b8c7a..5c4ccefd5393 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -799,6 +799,9 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
>    */
>   pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
>   
> +int ttm_bo_man_init(struct ttm_bo_device *bdev,
> +		    struct ttm_mem_type_manager *man,
> +		    unsigned long p_size);
>   extern const struct ttm_mem_type_manager_func ttm_bo_manager_func;
>   
>   #endif

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

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

* Re: [PATCH 00/49] ttm mem manager refactoring.
  2020-07-31  9:29   ` daniel
@ 2020-07-31 13:01     ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:01 UTC (permalink / raw)
  To: daniel; +Cc: sroland, bskeggs, dri-devel, kraxel

Am 31.07.20 um 11:29 schrieb daniel@ffwll.ch:
> On Fri, Jul 31, 2020 at 11:17:26AM +0200, Christian König wrote:
>> Am 31.07.20 um 06:04 schrieb Dave Airlie:
>>> I started pulling on a thread, and it led me down a hole.
>> We might want to make that hole even bigger :)
>>
>> How about we rename the ttm_mem_reg into ttm_resource and
>> ttm_mem_type_manager into ttm_resource_manager.
> +1 on names I can understand, I alwas get confused about what exactly ttm
> means with mem_reg and mem_type_manager.

Well mem_type_manager was obvious, but to be honest I never figured out 
what _reg meant either :)

Christian.

> -Daniel
>
>> Neither amdgpu's OA/GWS resources nor the IDs in VMGFX are really memory.
>>
>> In the long term I also want to move the whole address handling into each
>> backend.
>>
>> Going to send comments on the individual patches as well.
>>
>>> This series refactors the ttm ttm_mem_type_manager object into
>>> a driver owned, allocated, subclassaed object.
>>>
>>> It starts with two minor fixes for some bad assumptions in two drivers.
>>>
>>> Enables a new init path, ports all the drivers to the new init
>>> path, and cleans up the old init path.
>>> Enables a new takedown path, ports all the drivers to the new takedown
>>> path, and cleans up the old takedown path
>>> Wraps all access to the memory managers in the bo_device in a wrapper
>>> across all drivers.
>>> Make debug callback optional
>>> Enables driver to provide their own mem manager objects
>>> Subclasses the objects in all drivers and makes them into driver owned object
>>> Drops the bo_device arrays of pointers, and some unneeded links and
>>> struct members
>>> Cleans up one api.
>>>
>>> I think I'd probably want to merge all this via drm-misc, so if I can collect
>>> acks/r-b from driver maintainers that would be good.
>>>
>>> This is also based on Chrisitan's work to remove init_mem_type, so it won't
>>> apply until he's finished getting all of that into drm-misc.
>> Preparing to push that to drm-misc-next just now.
>>
>> Regards,
>> Christian.
>>
>>> https://nam11.safelinks.protection.outlook.com/?url=https:%2F%2Fcgit.freedesktop.org%2F~airlied%2Flinux%2Flog%2F%3Fh%3Dttm-refactor-mem-manager&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7C7966b55d1dfd4ffd393908d835343faf%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637317846121673630&amp;sdata=mqjdwhu9o3LfYSa%2FgW3GDDv2AABddmIPMZiAXoaNv6M%3D&amp;reserved=0
>>> is the tree I've built this on top off, so it's probably going to get rebased
>>> but the code should stay mostly the same.
>>>
>>> I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
>>> amdgpu soon.
>>>
>>> Dave.
>>>
>>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7C7966b55d1dfd4ffd393908d835343faf%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637317846121673630&amp;sdata=%2BiZVquH6tc7FwEubwDmqkU6PcwdsdCCzDm1leuwOIa4%3D&amp;reserved=0

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

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

* Re: [PATCH 34/49] drm/ttm: make manager debug function optional
  2020-07-31  9:46   ` daniel
@ 2020-07-31 13:03     ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:03 UTC (permalink / raw)
  To: daniel; +Cc: sroland, bskeggs, dri-devel, kraxel

Am 31.07.20 um 11:46 schrieb daniel@ffwll.ch:
> On Fri, Jul 31, 2020 at 02:05:05PM +1000, Dave Airlie wrote:
>> From: Dave Airlie <airlied@redhat.com>
>>
>> Signed-off-by: Dave Airlie <airlied@redhat.com>
>> ---
>>   drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
>>   1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
>> index 92de8a6d7647..1e8fda1c9b3a 100644
>> --- a/drivers/gpu/drm/ttm/ttm_bo.c
>> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
>> @@ -88,7 +88,7 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p
>>   	drm_printf(p, "    size: %llu\n", man->size);
>>   	drm_printf(p, "    available_caching: 0x%08X\n", man->available_caching);
>>   	drm_printf(p, "    default_caching: 0x%08X\n", man->default_caching);
>> -	if (mem_type != TTM_PL_SYSTEM)
>> +	if (mem_type != TTM_PL_SYSTEM && man->func->debug)
>>   		(*man->func->debug)(man, p);
>>   }
> Bit a bikeshed, but what about exporting this function (maybe with the man
> as argument, not the bdev, mem_type pair) and using it in the first 2
> patches? Avoids surprises with optional func->debug.

+1 for that. That's no bikeshed at all but just clean design.

And we should rename all those backend related functions and move them 
into a separate [ch] file.

E.g. let's just have a backend resource object TTM works with.

Christian.

> -Daniel
>
>>   
>> -- 
>> 2.26.2
>>
>> _______________________________________________
>> dri-devel mailing list
>> dri-devel@lists.freedesktop.org
>> https://nam11.safelinks.protection.outlook.com/?url=https%3A%2F%2Flists.freedesktop.org%2Fmailman%2Flistinfo%2Fdri-devel&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7C8540e6d1e99547722b2c08d83536929d%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637317855794189396&amp;sdata=GpkfEetygk53dJ1qWiF%2FucNVRc9%2FxWLzKc2BGuG9bLg%3D&amp;reserved=0

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

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

* Re: [PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places
  2020-07-31  4:04 ` [PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places Dave Airlie
@ 2020-07-31 13:04   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:04 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This makes it easier to cleanup things
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 14 ++++++--------
>   1 file changed, 6 insertions(+), 8 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 101a7910f9f7..84e399395e4f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -763,13 +763,12 @@ static int ttm_mem_evict_wait_busy(struct ttm_buffer_object *busy_bo,
>   }
>   
>   static int ttm_mem_evict_first(struct ttm_bo_device *bdev,
> -			       uint32_t mem_type,
> +			       struct ttm_mem_type_manager *man,
>   			       const struct ttm_place *place,
>   			       struct ttm_operation_ctx *ctx,
>   			       struct ww_acquire_ctx *ticket)
>   {
>   	struct ttm_buffer_object *bo = NULL, *busy_bo = NULL;
> -	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
>   	bool locked = false;
>   	unsigned i;
>   	int ret;
> @@ -918,7 +917,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
>   			break;
>   		if (unlikely(ret != -ENOSPC))
>   			return ret;
> -		ret = ttm_mem_evict_first(bdev, mem->mem_type, place, ctx,
> +		ret = ttm_mem_evict_first(bdev, man, place, ctx,
>   					  ticket);
>   		if (unlikely(ret != 0))
>   			return ret;
> @@ -1403,14 +1402,13 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
>   EXPORT_SYMBOL(ttm_bo_create);
>   
>   static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
> -				   unsigned mem_type)
> +				   struct ttm_mem_type_manager *man)
>   {
>   	struct ttm_operation_ctx ctx = {
>   		.interruptible = false,
>   		.no_wait_gpu = false,
>   		.flags = TTM_OPT_FLAG_FORCE_ALLOC
>   	};
> -	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
>   	struct ttm_bo_global *glob = &ttm_bo_glob;
>   	struct dma_fence *fence;
>   	int ret;
> @@ -1424,7 +1422,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
>   	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i) {
>   		while (!list_empty(&man->lru[i])) {
>   			spin_unlock(&glob->lru_lock);
> -			ret = ttm_mem_evict_first(bdev, mem_type, NULL, &ctx,
> +			ret = ttm_mem_evict_first(bdev, man, NULL, &ctx,
>   						  NULL);
>   			if (ret)
>   				return ret;
> @@ -1469,7 +1467,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   
>   	ret = 0;
>   	if (mem_type > 0) {
> -		ret = ttm_bo_force_list_clean(bdev, mem_type);
> +		ret = ttm_bo_force_list_clean(bdev, man);
>   		if (ret) {
>   			pr_err("Cleanup eviction failed\n");
>   			return ret;
> @@ -1499,7 +1497,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   		return 0;
>   	}
>   
> -	return ttm_bo_force_list_clean(bdev, mem_type);
> +	return ttm_bo_force_list_clean(bdev, man);
>   }
>   EXPORT_SYMBOL(ttm_bo_evict_mm);
>   

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

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

* Re: [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths.
  2020-07-31  4:04 ` [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths Dave Airlie
@ 2020-07-31 13:07   ` Christian König
  2020-08-04  2:28     ` Dave Airlie
  0 siblings, 1 reply; 99+ messages in thread
From: Christian König @ 2020-07-31 13:07 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    |  6 ++----
>   include/drm/ttm/ttm_bo_driver.h | 12 ++++++++++++
>   2 files changed, 14 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 84e399395e4f..f584e5e94383 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1462,8 +1462,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   		return ret;
>   	}
>   
> -	man->use_type = false;
> -	man->has_type = false;
> +	ttm_bo_disable_mm(man);
>   
>   	ret = 0;
>   	if (mem_type > 0) {
> @@ -1476,8 +1475,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   		ret = (*man->func->takedown)(man);
>   	}
>   
> -	dma_fence_put(man->move);
> -	man->move = NULL;
> +	ttm_bo_man_cleanup(man);
>   
>   	return ret;
>   }
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index d0f1a6cdfba7..92bb54cce633 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -671,6 +671,18 @@ static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
>   	man->use_type = true;
>   }
>   
> +static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
> +{
> +	man->has_type = false;
> +	man->use_type = false;
> +}
> +
> +static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
> +{
> +	dma_fence_put(man->move);
> +	man->move = NULL;
> +}
> +

What's the value in making those inline? This is not performance 
critical at all.

Christian.

>   /*
>    * ttm_bo_util.c
>    */

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

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

* Re: [PATCH 17/49] drm/amdgpu/ttm: use new takedown path
  2020-07-31  4:04 ` [PATCH 17/49] drm/amdgpu/ttm: " Dave Airlie
@ 2020-07-31 13:08   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:08 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 15 +++++++++++----
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c      | 10 +++++-----
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h      |  2 ++
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 15 +++++++++++----
>   4 files changed, 29 insertions(+), 13 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index 5f58aa2eac4a..f4c870b2f348 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -133,10 +133,18 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>    * Destroy and free the GTT manager, returns -EBUSY if ranges are still
>    * allocated inside it.
>    */
> -static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
> +void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
>   {
> -	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
> +	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_TT];
>   	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	int ret;
> +
> +	ttm_bo_disable_mm(man);
> +
> +	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
> +	if (ret)
> +		return;
> +
>   	spin_lock(&mgr->lock);
>   	drm_mm_takedown(&mgr->mm);
>   	spin_unlock(&mgr->lock);
> @@ -146,7 +154,7 @@ static int amdgpu_gtt_mgr_fini(struct ttm_mem_type_manager *man)
>   	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_total);
>   	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_used);
>   
> -	return 0;
> +	ttm_bo_man_cleanup(man);
>   }
>   
>   /**
> @@ -307,7 +315,6 @@ static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
>   }
>   
>   static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func = {
> -	.takedown = amdgpu_gtt_mgr_fini,
>   	.get_node = amdgpu_gtt_mgr_new,
>   	.put_node = amdgpu_gtt_mgr_del,
>   	.debug = amdgpu_gtt_mgr_debug
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index f1bf86b8de14..b1452df8fce9 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -2012,11 +2012,11 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
>   		iounmap(adev->mman.aper_base_kaddr);
>   	adev->mman.aper_base_kaddr = NULL;
>   
> -	ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_VRAM);
> -	ttm_bo_clean_mm(&adev->mman.bdev, TTM_PL_TT);
> -	ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GDS);
> -	ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_GWS);
> -	ttm_bo_clean_mm(&adev->mman.bdev, AMDGPU_PL_OA);
> +	amdgpu_vram_mgr_fini(adev);
> +	amdgpu_gtt_mgr_fini(adev);
> +	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GDS]);
> +	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_GWS]);
> +	ttm_bo_man_takedown(&adev->mman.bdev, &adev->mman.bdev.man[AMDGPU_PL_OA]);
>   	ttm_bo_device_release(&adev->mman.bdev);
>   	adev->mman.initialized = false;
>   	DRM_INFO("amdgpu: ttm finalized\n");
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> index fb45c0a323b0..c01fdb3f0458 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.h
> @@ -68,7 +68,9 @@ struct amdgpu_copy_mem {
>   };
>   
>   int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size);
> +void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev);
>   int amdgpu_vram_mgr_init(struct amdgpu_device *adev);
> +void amdgpu_vram_mgr_fini(struct amdgpu_device *adev);
>   
>   bool amdgpu_gtt_mgr_has_gart_addr(struct ttm_mem_reg *mem);
>   uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 1bc04835c24f..cc45be8ccb0f 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -205,10 +205,17 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>    * Destroy and free the VRAM manager, returns -EBUSY if ranges are still
>    * allocated inside it.
>    */
> -static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
> +void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
>   {
> -	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
> +	struct ttm_mem_type_manager *man = &adev->mman.bdev.man[TTM_PL_VRAM];
>   	struct amdgpu_vram_mgr *mgr = man->priv;
> +	int ret;
> +
> +	ttm_bo_disable_mm(man);
> +
> +	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
> +	if (ret)
> +		return;
>   
>   	spin_lock(&mgr->lock);
>   	drm_mm_takedown(&mgr->mm);
> @@ -216,7 +223,8 @@ static int amdgpu_vram_mgr_fini(struct ttm_mem_type_manager *man)
>   	kfree(mgr);
>   	man->priv = NULL;
>   	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
> -	return 0;
> +
> +	ttm_bo_man_cleanup(man);
>   }
>   
>   /**
> @@ -596,7 +604,6 @@ static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
>   }
>   
>   static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func = {
> -	.takedown	= amdgpu_vram_mgr_fini,
>   	.get_node	= amdgpu_vram_mgr_new,
>   	.put_node	= amdgpu_vram_mgr_del,
>   	.debug		= amdgpu_vram_mgr_debug

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

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

* Re: [PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path
  2020-07-31  4:04 ` [PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path Dave Airlie
@ 2020-07-31 13:09   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:09 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Allow the takedown path callback to be optional as well.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c         |  8 +++++---
>   drivers/gpu/drm/ttm/ttm_bo_manager.c | 21 +++++++++++++++++++--
>   include/drm/ttm/ttm_bo_driver.h      |  5 ++++-
>   3 files changed, 28 insertions(+), 6 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index f584e5e94383..f0f0f3101bd1 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1401,8 +1401,8 @@ int ttm_bo_create(struct ttm_bo_device *bdev,
>   }
>   EXPORT_SYMBOL(ttm_bo_create);
>   
> -static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
> -				   struct ttm_mem_type_manager *man)
> +int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
> +			    struct ttm_mem_type_manager *man)
>   {
>   	struct ttm_operation_ctx ctx = {
>   		.interruptible = false,
> @@ -1444,6 +1444,7 @@ static int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
>   
>   	return 0;
>   }
> +EXPORT_SYMBOL(ttm_bo_force_list_clean);
>   
>   int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   {
> @@ -1472,7 +1473,8 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   			return ret;
>   		}
>   
> -		ret = (*man->func->takedown)(man);
> +		if (man->func->takedown)
> +			ret = (*man->func->takedown)(man);
>   	}
>   
>   	ttm_bo_man_cleanup(man);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 1877425abdf0..1127868274b3 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -129,7 +129,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   }
>   EXPORT_SYMBOL(ttm_bo_man_init);
>   
> -static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
> +static int ttm_bo_man_takedown_private(struct ttm_mem_type_manager *man)
>   {
>   	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
>   	struct drm_mm *mm = &rman->mm;
> @@ -146,6 +146,23 @@ static int ttm_bo_man_takedown(struct ttm_mem_type_manager *man)
>   	return -EBUSY;
>   }
>   
> +int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
> +			struct ttm_mem_type_manager *man)

Regarding naming I prefer init() and fini() as functions for object 
initialization and destruction in C.

Christian.

> +{
> +	int ret;
> +
> +	ttm_bo_disable_mm(man);
> +
> +	ret = ttm_bo_force_list_clean(bdev, man);
> +	if (ret)
> +		return ret;
> +
> +	ttm_bo_man_takedown_private(man);
> +	ttm_bo_man_cleanup(man);
> +	return 0;
> +}
> +EXPORT_SYMBOL(ttm_bo_man_takedown);
> +
>   static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>   			     struct drm_printer *printer)
>   {
> @@ -157,7 +174,7 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>   }
>   
>   static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
> -	.takedown = ttm_bo_man_takedown,
> +	.takedown = ttm_bo_man_takedown_private,
>   	.get_node = ttm_bo_man_get_node,
>   	.put_node = ttm_bo_man_put_node,
>   	.debug = ttm_bo_man_debug
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 92bb54cce633..2ef33b407167 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -683,6 +683,8 @@ static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
>   	man->move = NULL;
>   }
>   
> +int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
> +			    struct ttm_mem_type_manager *man);
>   /*
>    * ttm_bo_util.c
>    */
> @@ -801,5 +803,6 @@ pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
>   int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   		    struct ttm_mem_type_manager *man,
>   		    unsigned long p_size);
> -
> +int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
> +			struct ttm_mem_type_manager *man);
>   #endif

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

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

* Re: [PATCH 21/49] drm/radeon/ttm: use new takedown paths
  2020-07-31  4:04 ` [PATCH 21/49] drm/radeon/ttm: use new takedown paths Dave Airlie
@ 2020-07-31 13:10   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:10 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/radeon/radeon_ttm.c | 4 ++--
>   1 file changed, 2 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index a5043a5b7d89..e65297b4b678 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -826,8 +826,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
>   		}
>   		radeon_bo_unref(&rdev->stolen_vga_memory);
>   	}
> -	ttm_bo_clean_mm(&rdev->mman.bdev, TTM_PL_VRAM);
> -	ttm_bo_clean_mm(&rdev->mman.bdev, TTM_PL_TT);
> +	ttm_bo_man_takedown(&rdev->mman.bdev, &rdev->mman.bdev.man[TTM_PL_VRAM]);
> +	ttm_bo_man_takedown(&rdev->mman.bdev, &rdev->mman.bdev.man[TTM_PL_TT]);
>   	ttm_bo_device_release(&rdev->mman.bdev);
>   	radeon_gart_fini(rdev);
>   	rdev->mman.initialized = false;

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

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

* Re: [PATCH 24/49] drm/ttm: remove range manager legacy takedown path
  2020-07-31  4:04 ` [PATCH 24/49] drm/ttm: remove range manager legacy takedown path Dave Airlie
@ 2020-07-31 13:11   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:11 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Now no drivers have been converted, drop the non-driver path.

I'm not a native speak, but that sounds odd.

Apart from that patch is Reviewed-by: Christian König 
<christian.koenig@amd.com>

>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo_manager.c | 28 +++++++++-------------------
>   1 file changed, 9 insertions(+), 19 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 1127868274b3..f60a9a5d429d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -129,26 +129,11 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   }
>   EXPORT_SYMBOL(ttm_bo_man_init);
>   
> -static int ttm_bo_man_takedown_private(struct ttm_mem_type_manager *man)
> -{
> -	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> -	struct drm_mm *mm = &rman->mm;
> -
> -	spin_lock(&rman->lock);
> -	if (drm_mm_clean(mm)) {
> -		drm_mm_takedown(mm);
> -		spin_unlock(&rman->lock);
> -		kfree(rman);
> -		man->priv = NULL;
> -		return 0;
> -	}
> -	spin_unlock(&rman->lock);
> -	return -EBUSY;
> -}
> -
>   int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
>   			struct ttm_mem_type_manager *man)
>   {
> +	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> +	struct drm_mm *mm = &rman->mm;
>   	int ret;
>   
>   	ttm_bo_disable_mm(man);
> @@ -157,7 +142,13 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
>   	if (ret)
>   		return ret;
>   
> -	ttm_bo_man_takedown_private(man);
> +	spin_lock(&rman->lock);
> +	drm_mm_clean(mm);
> +	drm_mm_takedown(mm);
> +	spin_unlock(&rman->lock);
> +	kfree(rman);
> +	man->priv = NULL;
> +
>   	ttm_bo_man_cleanup(man);
>   	return 0;
>   }
> @@ -174,7 +165,6 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>   }
>   
>   static const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
> -	.takedown = ttm_bo_man_takedown_private,
>   	.get_node = ttm_bo_man_get_node,
>   	.put_node = ttm_bo_man_put_node,
>   	.debug = ttm_bo_man_debug

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

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

* Re: [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.
  2020-07-31  7:21     ` Dave Airlie
@ 2020-07-31 13:18       ` daniel
  0 siblings, 0 replies; 99+ messages in thread
From: daniel @ 2020-07-31 13:18 UTC (permalink / raw)
  Cc: Roland Scheidegger, dri-devel, Ben Skeggs, Thomas Zimmermann,
	Koenig, Christian, Gerd Hoffmann

On Fri, Jul 31, 2020 at 05:21:38PM +1000, Dave Airlie wrote:
> On Fri, 31 Jul 2020 at 17:14, Thomas Zimmermann <tzimmermann@suse.de> wrote:
> >
> > Hi
> >
> > Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > > From: Dave Airlie <airlied@redhat.com>
> > >
> > > This will allow different abstractions later.
> >
> > You should consider moving this patch to the beginning of the series, so
> > that patches 1 to 25 can benefit from it.
> 
> I did consider it, but I'd have to move all the follow on patches as
> well, and it got messy in rebase land, and I started introducing
> errors, so I left it alone, and it's not necessary until the patch
> that changes it's definition anyways.

I like this ordering a lot better, it gives a clear separation between the
different steps. Some code gets touched multiple times, but interleaving
the demidlayering would only make this worse I think.
-Daniel
> 
> Dave.
> _______________________________________________
> 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] 99+ messages in thread

* Re: [PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only.
  2020-07-31  4:04 ` [PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only Dave Airlie
@ 2020-07-31 13:19   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:19 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> drivers should all be cleaning up their memory managers
> themselves now, so let the core just clean the system one up.
>
> Remove the legacy cleaning interface.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    | 55 +++------------------------------
>   include/drm/ttm/ttm_bo_api.h    | 28 -----------------
>   include/drm/ttm/ttm_bo_driver.h | 10 ------
>   3 files changed, 4 insertions(+), 89 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index f0f0f3101bd1..07c653374f15 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1446,43 +1446,6 @@ int ttm_bo_force_list_clean(struct ttm_bo_device *bdev,
>   }
>   EXPORT_SYMBOL(ttm_bo_force_list_clean);
>   
> -int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> -{
> -	struct ttm_mem_type_manager *man;
> -	int ret = -EINVAL;
> -
> -	if (mem_type >= TTM_NUM_MEM_TYPES) {
> -		pr_err("Illegal memory type %d\n", mem_type);
> -		return ret;
> -	}
> -	man = &bdev->man[mem_type];
> -
> -	if (!man->has_type) {
> -		pr_err("Trying to take down uninitialized memory manager type %u\n",
> -		       mem_type);
> -		return ret;
> -	}
> -
> -	ttm_bo_disable_mm(man);
> -
> -	ret = 0;
> -	if (mem_type > 0) {
> -		ret = ttm_bo_force_list_clean(bdev, man);
> -		if (ret) {
> -			pr_err("Cleanup eviction failed\n");
> -			return ret;
> -		}
> -
> -		if (man->func->takedown)
> -			ret = (*man->func->takedown)(man);
> -	}
> -
> -	ttm_bo_man_cleanup(man);
> -
> -	return ret;
> -}
> -EXPORT_SYMBOL(ttm_bo_clean_mm);
> -
>   int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   {
>   	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> @@ -1585,21 +1548,11 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>   {
>   	struct ttm_bo_global *glob = &ttm_bo_glob;
>   	int ret = 0;
> -	unsigned i = TTM_NUM_MEM_TYPES;
> +	unsigned i;
>   	struct ttm_mem_type_manager *man;
>   
> -	while (i--) {
> -		man = &bdev->man[i];
> -		if (man->has_type) {
> -			man->use_type = false;
> -			if ((i != TTM_PL_SYSTEM) && ttm_bo_clean_mm(bdev, i)) {
> -				ret = -EBUSY;
> -				pr_err("DRM memory manager type %d is not clean\n",
> -				       i);
> -			}
> -			man->has_type = false;
> -		}
> -	}
> +	man = &bdev->man[TTM_PL_SYSTEM];
> +	ttm_bo_disable_mm(man);
>   
>   	mutex_lock(&ttm_global_mutex);
>   	list_del(&bdev->device_list);
> @@ -1612,7 +1565,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>   
>   	spin_lock(&glob->lru_lock);
>   	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
> -		if (list_empty(&bdev->man[0].lru[0]))
> +		if (list_empty(&man->lru[0]))
>   			pr_debug("Swap list %d was clean\n", i);
>   	spin_unlock(&glob->lru_lock);
>   
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 6562d1c5ac59..27dde1371376 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -551,34 +551,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
>   			 struct ttm_mem_type_manager *man,
>   			 unsigned long p_size);
>   
> -/**
> - * ttm_bo_clean_mm
> - *
> - * @bdev: Pointer to a ttm_bo_device struct.
> - * @mem_type: The memory type.
> - *
> - * Take down a manager for a given memory type after first walking
> - * the LRU list to evict any buffers left alive.
> - *
> - * Normally, this function is part of lastclose() or unload(), and at that
> - * point there shouldn't be any buffers left created by user-space, since
> - * there should've been removed by the file descriptor release() method.
> - * However, before this function is run, make sure to signal all sync objects,
> - * and verify that the delayed delete queue is empty. The driver must also
> - * make sure that there are no NO_EVICT buffers present in this memory type
> - * when the call is made.
> - *
> - * If this function is part of a VT switch, the caller must make sure that
> - * there are no appications currently validating buffers before this
> - * function is called. The caller can do that by first taking the
> - * struct ttm_bo_device::ttm_lock in write mode.
> - *
> - * Returns:
> - * -EINVAL: invalid or uninitialized memory type.
> - * -EBUSY: There are still buffers left in this memory type.
> - */
> -int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type);
> -
>   /**
>    * ttm_bo_evict_mm
>    *
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 2ef33b407167..9d066529ca61 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -48,16 +48,6 @@
>   struct ttm_mem_type_manager;
>   
>   struct ttm_mem_type_manager_func {
> -	/**
> -	 * struct ttm_mem_type_manager member takedown
> -	 *
> -	 * @man: Pointer to a memory type manager.
> -	 *
> -	 * Called to undo the setup done in init. All allocated resources
> -	 * should be freed.
> -	 */
> -	int  (*takedown)(struct ttm_mem_type_manager *man);
> -
>   	/**
>   	 * struct ttm_mem_type_manager member get_node
>   	 *

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

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

* Re: [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.
  2020-07-31  4:04 ` [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev Dave Airlie
  2020-07-31  7:14   ` Thomas Zimmermann
@ 2020-07-31 13:23   ` Christian König
  2020-07-31 21:06     ` Dave Airlie
  1 sibling, 1 reply; 99+ messages in thread
From: Christian König @ 2020-07-31 13:23 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:04 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This will allow different abstractions later.

Mhm, I'm questioning if this is really worth it and not just overkill.

Running "sed -i 's/&bdev->man/bdev->man/'" on all drivers when we make 
the switch to a pointer should do it as well.

Christian.

>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c      | 34 +++++++++++++++----------------
>   drivers/gpu/drm/ttm/ttm_bo_util.c | 20 +++++++++---------
>   drivers/gpu/drm/ttm/ttm_bo_vm.c   |  2 +-
>   include/drm/ttm/ttm_bo_driver.h   |  6 ++++++
>   4 files changed, 34 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 07c653374f15..7c6389ea067f 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -80,7 +80,7 @@ static inline int ttm_mem_type_from_place(const struct ttm_place *place,
>   static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p,
>   			       int mem_type)
>   {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
>   
>   	drm_printf(p, "    has_type: %d\n", man->has_type);
>   	drm_printf(p, "    use_type: %d\n", man->use_type);
> @@ -156,7 +156,7 @@ static void ttm_bo_add_mem_to_lru(struct ttm_buffer_object *bo,
>   	if (mem->placement & TTM_PL_FLAG_NO_EVICT)
>   		return;
>   
> -	man = &bdev->man[mem->mem_type];
> +	man = ttm_manager_type(bdev, mem->mem_type);
>   	list_add_tail(&bo->lru, &man->lru[bo->priority]);
>   
>   	if (man->use_tt && bo->ttm &&
> @@ -231,7 +231,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
>   		dma_resv_assert_held(pos->first->base.resv);
>   		dma_resv_assert_held(pos->last->base.resv);
>   
> -		man = &pos->first->bdev->man[TTM_PL_TT];
> +		man = ttm_manager_type(pos->first->bdev, TTM_PL_TT);
>   		list_bulk_move_tail(&man->lru[i], &pos->first->lru,
>   				    &pos->last->lru);
>   	}
> @@ -246,7 +246,7 @@ void ttm_bo_bulk_move_lru_tail(struct ttm_lru_bulk_move *bulk)
>   		dma_resv_assert_held(pos->first->base.resv);
>   		dma_resv_assert_held(pos->last->base.resv);
>   
> -		man = &pos->first->bdev->man[TTM_PL_VRAM];
> +		man = ttm_manager_type(pos->first->bdev, TTM_PL_VRAM);
>   		list_bulk_move_tail(&man->lru[i], &pos->first->lru,
>   				    &pos->last->lru);
>   	}
> @@ -272,8 +272,8 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>   				  struct ttm_operation_ctx *ctx)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *old_man = &bdev->man[bo->mem.mem_type];
> -	struct ttm_mem_type_manager *new_man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *old_man = ttm_manager_type(bdev, bo->mem.mem_type);
> +	struct ttm_mem_type_manager *new_man = ttm_manager_type(bdev, mem->mem_type);
>   	int ret;
>   
>   	ret = ttm_mem_io_lock(old_man, true);
> @@ -338,7 +338,7 @@ static int ttm_bo_handle_move_mem(struct ttm_buffer_object *bo,
>   	return 0;
>   
>   out_err:
> -	new_man = &bdev->man[bo->mem.mem_type];
> +	new_man = ttm_manager_type(bdev, bo->mem.mem_type);
>   	if (!new_man->use_tt) {
>   		ttm_tt_destroy(bo->ttm);
>   		bo->ttm = NULL;
> @@ -550,7 +550,7 @@ static void ttm_bo_release(struct kref *kref)
>   	struct ttm_buffer_object *bo =
>   	    container_of(kref, struct ttm_buffer_object, kref);
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, bo->mem.mem_type);
>   	size_t acc_size = bo->acc_size;
>   	int ret;
>   
> @@ -838,7 +838,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
>   			  const struct ttm_place *place,
>   			  struct ttm_mem_reg *mem)
>   {
> -	struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
>   
>   	mem->mm_node = NULL;
>   	if (!man->func || !man->func->get_node)
> @@ -849,7 +849,7 @@ static int ttm_bo_mem_get(struct ttm_buffer_object *bo,
>   
>   void ttm_bo_mem_put(struct ttm_buffer_object *bo, struct ttm_mem_reg *mem)
>   {
> -	struct ttm_mem_type_manager *man = &bo->bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, mem->mem_type);
>   
>   	if (!man->func || !man->func->put_node)
>   		return;
> @@ -906,7 +906,7 @@ static int ttm_bo_mem_force_space(struct ttm_buffer_object *bo,
>   				  struct ttm_operation_ctx *ctx)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
>   	struct ww_acquire_ctx *ticket;
>   	int ret;
>   
> @@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
>   	if (ret)
>   		return ret;
>   
> -	man = &bdev->man[mem_type];
> +	man = ttm_manager_type(bdev, mem_type);
>   	if (!man->has_type || !man->use_type)
>   		return -EBUSY;
>   
> @@ -1059,7 +1059,7 @@ int ttm_bo_mem_space(struct ttm_buffer_object *bo,
>   		if (unlikely(ret))
>   			goto error;
>   
> -		man = &bdev->man[mem->mem_type];
> +		man = ttm_manager_type(bdev, mem->mem_type);
>   		ret = ttm_bo_add_move_fence(bo, man, mem, ctx->no_wait_gpu);
>   		if (unlikely(ret)) {
>   			ttm_bo_mem_put(bo, mem);
> @@ -1448,7 +1448,7 @@ EXPORT_SYMBOL(ttm_bo_force_list_clean);
>   
>   int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem_type);
>   
>   	if (mem_type == 0 || mem_type >= TTM_NUM_MEM_TYPES) {
>   		pr_err("Illegal memory manager memory type %u\n", mem_type);
> @@ -1551,7 +1551,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>   	unsigned i;
>   	struct ttm_mem_type_manager *man;
>   
> -	man = &bdev->man[TTM_PL_SYSTEM];
> +	man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
>   	ttm_bo_disable_mm(man);
>   
>   	mutex_lock(&ttm_global_mutex);
> @@ -1578,7 +1578,7 @@ EXPORT_SYMBOL(ttm_bo_device_release);
>   
>   static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
>   {
> -	struct ttm_mem_type_manager *man = &bdev->man[TTM_PL_SYSTEM];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
>   
>   	/*
>   	 * Initialize the system memory buffer type.
> @@ -1642,7 +1642,7 @@ void ttm_bo_unmap_virtual_locked(struct ttm_buffer_object *bo)
>   void ttm_bo_unmap_virtual(struct ttm_buffer_object *bo)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[bo->mem.mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, bo->mem.mem_type);
>   
>   	ttm_mem_io_lock(man, false);
>   	ttm_bo_unmap_virtual_locked(bo);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_util.c b/drivers/gpu/drm/ttm/ttm_bo_util.c
> index 1f502be0b646..879c8ded0cd8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_util.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_util.c
> @@ -129,7 +129,7 @@ static int ttm_mem_io_evict(struct ttm_mem_type_manager *man)
>   int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
>   		       struct ttm_mem_reg *mem)
>   {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
>   	int ret;
>   
>   	if (mem->bus.io_reserved_count++)
> @@ -162,7 +162,7 @@ void ttm_mem_io_free(struct ttm_bo_device *bdev,
>   
>   int ttm_mem_io_reserve_vm(struct ttm_buffer_object *bo)
>   {
> -	struct ttm_mem_type_manager *man = &bo->bdev->man[bo->mem.mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bo->bdev, bo->mem.mem_type);
>   	struct ttm_mem_reg *mem = &bo->mem;
>   	int ret;
>   
> @@ -195,7 +195,7 @@ static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev,
>   			       struct ttm_mem_reg *mem,
>   			       void **virtual)
>   {
> -	struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, mem->mem_type);
>   	int ret;
>   	void *addr;
>   
> @@ -232,7 +232,7 @@ static void ttm_mem_reg_iounmap(struct ttm_bo_device *bdev,
>   {
>   	struct ttm_mem_type_manager *man;
>   
> -	man = &bdev->man[mem->mem_type];
> +	man = ttm_manager_type(bdev, mem->mem_type);
>   
>   	if (virtual && mem->bus.addr == NULL)
>   		iounmap(virtual);
> @@ -303,7 +303,7 @@ int ttm_bo_move_memcpy(struct ttm_buffer_object *bo,
>   		       struct ttm_mem_reg *new_mem)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
>   	struct ttm_tt *ttm = bo->ttm;
>   	struct ttm_mem_reg *old_mem = &bo->mem;
>   	struct ttm_mem_reg old_copy = *old_mem;
> @@ -571,7 +571,7 @@ int ttm_bo_kmap(struct ttm_buffer_object *bo,
>   		struct ttm_bo_kmap_obj *map)
>   {
>   	struct ttm_mem_type_manager *man =
> -		&bo->bdev->man[bo->mem.mem_type];
> +		ttm_manager_type(bo->bdev, bo->mem.mem_type);
>   	unsigned long offset, size;
>   	int ret;
>   
> @@ -601,7 +601,7 @@ void ttm_bo_kunmap(struct ttm_bo_kmap_obj *map)
>   {
>   	struct ttm_buffer_object *bo = map->bo;
>   	struct ttm_mem_type_manager *man =
> -		&bo->bdev->man[bo->mem.mem_type];
> +		ttm_manager_type(bo->bdev, bo->mem.mem_type);
>   
>   	if (!map->virtual)
>   		return;
> @@ -634,7 +634,7 @@ int ttm_bo_move_accel_cleanup(struct ttm_buffer_object *bo,
>   			      struct ttm_mem_reg *new_mem)
>   {
>   	struct ttm_bo_device *bdev = bo->bdev;
> -	struct ttm_mem_type_manager *man = &bdev->man[new_mem->mem_type];
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, new_mem->mem_type);
>   	struct ttm_mem_reg *old_mem = &bo->mem;
>   	int ret;
>   	struct ttm_buffer_object *ghost_obj;
> @@ -697,8 +697,8 @@ int ttm_bo_pipeline_move(struct ttm_buffer_object *bo,
>   	struct ttm_bo_device *bdev = bo->bdev;
>   	struct ttm_mem_reg *old_mem = &bo->mem;
>   
> -	struct ttm_mem_type_manager *from = &bdev->man[old_mem->mem_type];
> -	struct ttm_mem_type_manager *to = &bdev->man[new_mem->mem_type];
> +	struct ttm_mem_type_manager *from = ttm_manager_type(bdev, old_mem->mem_type);
> +	struct ttm_mem_type_manager *to = ttm_manager_type(bdev, new_mem->mem_type);
>   
>   	int ret;
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_vm.c b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> index 468a0eb9e632..5ae679184eb5 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_vm.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_vm.c
> @@ -282,7 +282,7 @@ vm_fault_t ttm_bo_vm_fault_reserved(struct vm_fault *vmf,
>   	vm_fault_t ret = VM_FAULT_NOPAGE;
>   	unsigned long address = vmf->address;
>   	struct ttm_mem_type_manager *man =
> -		&bdev->man[bo->mem.mem_type];
> +		ttm_manager_type(bdev, bo->mem.mem_type);
>   
>   	/*
>   	 * Refuse to fault imported pages. This should be handled
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 9d066529ca61..ec25451b503f 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -444,6 +444,12 @@ struct ttm_bo_device {
>   	bool no_retry;
>   };
>   
> +static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
> +							    int mem_type)
> +{
> +	return &bdev->man[mem_type];
> +}
> +
>   /**
>    * struct ttm_lru_bulk_move_pos
>    *

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

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

* Re: [PATCH 34/49] drm/ttm: make manager debug function optional
  2020-07-31  4:05 ` [PATCH 34/49] drm/ttm: make manager debug function optional Dave Airlie
  2020-07-31  9:46   ` daniel
@ 2020-07-31 13:24   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:24 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 92de8a6d7647..1e8fda1c9b3a 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -88,7 +88,7 @@ static void ttm_mem_type_debug(struct ttm_bo_device *bdev, struct drm_printer *p
>   	drm_printf(p, "    size: %llu\n", man->size);
>   	drm_printf(p, "    available_caching: 0x%08X\n", man->available_caching);
>   	drm_printf(p, "    default_caching: 0x%08X\n", man->default_caching);
> -	if (mem_type != TTM_PL_SYSTEM)
> +	if (mem_type != TTM_PL_SYSTEM && man->func->debug)
>   		(*man->func->debug)(man, p);
>   }
>   

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

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

* Re: [PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback
  2020-07-31  4:05 ` [PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback Dave Airlie
@ 2020-07-31 13:25   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:25 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Acked-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/nouveau/nouveau_ttm.c | 9 ---------
>   1 file changed, 9 deletions(-)
>
> diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> index ed651d7679fe..1b9d9362132d 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> @@ -37,12 +37,6 @@ nouveau_manager_del(struct ttm_mem_type_manager *man, struct ttm_mem_reg *reg)
>   	nouveau_mem_del(reg);
>   }
>   
> -static void
> -nouveau_manager_debug(struct ttm_mem_type_manager *man,
> -		      struct drm_printer *printer)
> -{
> -}
> -
>   static int
>   nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
>   			 struct ttm_buffer_object *bo,
> @@ -72,7 +66,6 @@ nouveau_vram_manager_new(struct ttm_mem_type_manager *man,
>   const struct ttm_mem_type_manager_func nouveau_vram_manager = {
>   	.get_node = nouveau_vram_manager_new,
>   	.put_node = nouveau_manager_del,
> -	.debug = nouveau_manager_debug,
>   };
>   
>   static int
> @@ -96,7 +89,6 @@ nouveau_gart_manager_new(struct ttm_mem_type_manager *man,
>   const struct ttm_mem_type_manager_func nouveau_gart_manager = {
>   	.get_node = nouveau_gart_manager_new,
>   	.put_node = nouveau_manager_del,
> -	.debug = nouveau_manager_debug
>   };
>   
>   static int
> @@ -129,7 +121,6 @@ nv04_gart_manager_new(struct ttm_mem_type_manager *man,
>   const struct ttm_mem_type_manager_func nv04_gart_manager = {
>   	.get_node = nv04_gart_manager_new,
>   	.put_node = nouveau_manager_del,
> -	.debug = nouveau_manager_debug
>   };
>   
>   int

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

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

* Re: [PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless ttm debug callback
  2020-07-31  4:05 ` [PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless " Dave Airlie
@ 2020-07-31 13:26   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:26 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Acked-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 7 -------
>   1 file changed, 7 deletions(-)
>
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> index 3fa809b5e3bd..2db99f0449b0 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> @@ -149,14 +149,7 @@ void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
>   	ttm_bo_man_cleanup(man);
>   }
>   
> -static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
> -				struct drm_printer *printer)
> -{
> -	drm_printf(printer, "No debug info available for the GMR id manager\n");
> -}
> -
>   static const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
>   	.get_node = vmw_gmrid_man_get_node,
>   	.put_node = vmw_gmrid_man_put_node,
> -	.debug = vmw_gmrid_man_debug
>   };

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

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

* Re: [PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs
  2020-07-31  4:05 ` [PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs Dave Airlie
@ 2020-07-31 13:29   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:29 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c  | 35 +++++++++++--------
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 36 +++++++++++++-------
>   2 files changed, 44 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index 0b0d09d19b4f..83d88ee73468 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -25,11 +25,17 @@
>   #include "amdgpu.h"
>   
>   struct amdgpu_gtt_mgr {
> +	struct ttm_mem_type_manager manager;
>   	struct drm_mm mm;
>   	spinlock_t lock;
>   	atomic64_t available;
>   };
>   
> +static inline struct amdgpu_gtt_mgr *to_gtt_mgr(struct ttm_mem_type_manager *man)
> +{
> +	return container_of(man, struct amdgpu_gtt_mgr, manager);
> +}
> +
>   struct amdgpu_gtt_node {
>   	struct drm_mm_node node;
>   	struct ttm_buffer_object *tbo;
> @@ -87,11 +93,16 @@ static const struct ttm_mem_type_manager_func amdgpu_gtt_mgr_func;
>    */
>   int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
> +	struct ttm_mem_type_manager *man;
>   	struct amdgpu_gtt_mgr *mgr;
>   	uint64_t start, size;
>   	int ret;
>   
> +	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
> +	if (!mgr)
> +		return -ENOMEM;
> +
> +	man = &mgr->manager;
>   	man->use_tt = true;
>   	man->func = &amdgpu_gtt_mgr_func;
>   	man->available_caching = TTM_PL_MASK_CACHING;
> @@ -99,16 +110,11 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>   
>   	ttm_bo_init_mm_base(&adev->mman.bdev, man, gtt_size >> PAGE_SHIFT);
>   
> -	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
> -	if (!mgr)
> -		return -ENOMEM;
> -
>   	start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
>   	size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
>   	drm_mm_init(&mgr->mm, start, size);
>   	spin_lock_init(&mgr->lock);
>   	atomic64_set(&mgr->available, gtt_size >> PAGE_SHIFT);
> -	man->priv = mgr;
>   
>   	ret = device_create_file(adev->dev, &dev_attr_mem_info_gtt_total);
>   	if (ret) {
> @@ -121,6 +127,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>   		return ret;
>   	}
>   
> +	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager);
>   	ttm_bo_use_mm(man);
>   	return 0;
>   }
> @@ -136,7 +143,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>   void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
>   {
>   	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_TT);
> -	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   	int ret;
>   
>   	ttm_bo_disable_mm(man);
> @@ -148,13 +155,13 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
>   	spin_lock(&mgr->lock);
>   	drm_mm_takedown(&mgr->mm);
>   	spin_unlock(&mgr->lock);
> -	kfree(mgr);
> -	man->priv = NULL;
>   
>   	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_total);
>   	device_remove_file(adev->dev, &dev_attr_mem_info_gtt_used);
>   
>   	ttm_bo_man_cleanup(man);
> +	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, NULL);
> +	kfree(mgr);
>   }
>   
>   /**
> @@ -184,7 +191,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager *man,
>   			      const struct ttm_place *place,
>   			      struct ttm_mem_reg *mem)
>   {
> -	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   	struct amdgpu_gtt_node *node;
>   	int r;
>   
> @@ -245,7 +252,7 @@ static int amdgpu_gtt_mgr_new(struct ttm_mem_type_manager *man,
>   static void amdgpu_gtt_mgr_del(struct ttm_mem_type_manager *man,
>   			       struct ttm_mem_reg *mem)
>   {
> -	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   	struct amdgpu_gtt_node *node = mem->mm_node;
>   
>   	if (node) {
> @@ -267,7 +274,7 @@ static void amdgpu_gtt_mgr_del(struct ttm_mem_type_manager *man,
>    */
>   uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man)
>   {
> -	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   	s64 result = man->size - atomic64_read(&mgr->available);
>   
>   	return (result > 0 ? result : 0) * PAGE_SIZE;
> @@ -275,7 +282,7 @@ uint64_t amdgpu_gtt_mgr_usage(struct ttm_mem_type_manager *man)
>   
>   int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man)
>   {
> -	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   	struct amdgpu_gtt_node *node;
>   	struct drm_mm_node *mm_node;
>   	int r = 0;
> @@ -303,7 +310,7 @@ int amdgpu_gtt_mgr_recover(struct ttm_mem_type_manager *man)
>   static void amdgpu_gtt_mgr_debug(struct ttm_mem_type_manager *man,
>   				 struct drm_printer *printer)
>   {
> -	struct amdgpu_gtt_mgr *mgr = man->priv;
> +	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   
>   	spin_lock(&mgr->lock);
>   	drm_mm_print(&mgr->mm, printer);
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index d33a750e07a8..9d4a13926b8c 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -29,12 +29,18 @@
>   #include "atom.h"
>   
>   struct amdgpu_vram_mgr {
> +	struct ttm_mem_type_manager manager;
>   	struct drm_mm mm;
>   	spinlock_t lock;
>   	atomic64_t usage;
>   	atomic64_t vis_usage;
>   };
>   
> +static inline struct amdgpu_vram_mgr *to_vram_mgr(struct ttm_mem_type_manager *man)
> +{
> +	return container_of(man, struct amdgpu_vram_mgr, manager);
> +}
> +
>   /**
>    * DOC: mem_info_vram_total
>    *
> @@ -170,29 +176,32 @@ static const struct ttm_mem_type_manager_func amdgpu_vram_mgr_func;
>    */
>   int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
> +	struct ttm_mem_type_manager *man;
>   	struct amdgpu_vram_mgr *mgr;
>   	int ret;
>   
> +	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
> +	if (!mgr)
> +		return -ENOMEM;
> +
> +	man = &mgr->manager;
> +
>   	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
>   	man->default_caching = TTM_PL_FLAG_WC;
>   
>   	ttm_bo_init_mm_base(&adev->mman.bdev, man, adev->gmc.real_vram_size >> PAGE_SHIFT);
>   
>   	man->func = &amdgpu_vram_mgr_func;
> -	mgr = kzalloc(sizeof(*mgr), GFP_KERNEL);
> -	if (!mgr)
> -		return -ENOMEM;
>   
>   	drm_mm_init(&mgr->mm, 0, man->size);
>   	spin_lock_init(&mgr->lock);
> -	man->priv = mgr;
>   
>   	/* Add the two VRAM-related sysfs files */
>   	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
>   	if (ret)
>   		DRM_ERROR("Failed to register sysfs\n");
>   
> +	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
>   	ttm_bo_use_mm(man);
>   	return 0;
>   }
> @@ -208,7 +217,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>   void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
>   {
>   	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, TTM_PL_VRAM);
> -	struct amdgpu_vram_mgr *mgr = man->priv;
> +	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   	int ret;
>   
>   	ttm_bo_disable_mm(man);
> @@ -220,11 +229,12 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
>   	spin_lock(&mgr->lock);
>   	drm_mm_takedown(&mgr->mm);
>   	spin_unlock(&mgr->lock);
> -	kfree(mgr);
> -	man->priv = NULL;
> +
>   	sysfs_remove_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
>   
>   	ttm_bo_man_cleanup(man);
> +	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, NULL);
> +	kfree(mgr);
>   }
>   
>   /**
> @@ -314,7 +324,7 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
>   			       struct ttm_mem_reg *mem)
>   {
>   	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
> -	struct amdgpu_vram_mgr *mgr = man->priv;
> +	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   	struct drm_mm *mm = &mgr->mm;
>   	struct drm_mm_node *nodes;
>   	enum drm_mm_insert_mode mode;
> @@ -430,7 +440,7 @@ static void amdgpu_vram_mgr_del(struct ttm_mem_type_manager *man,
>   				struct ttm_mem_reg *mem)
>   {
>   	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
> -	struct amdgpu_vram_mgr *mgr = man->priv;
> +	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   	struct drm_mm_node *nodes = mem->mm_node;
>   	uint64_t usage = 0, vis_usage = 0;
>   	unsigned pages = mem->num_pages;
> @@ -562,7 +572,7 @@ void amdgpu_vram_mgr_free_sgt(struct amdgpu_device *adev,
>    */
>   uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man)
>   {
> -	struct amdgpu_vram_mgr *mgr = man->priv;
> +	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   
>   	return atomic64_read(&mgr->usage);
>   }
> @@ -576,7 +586,7 @@ uint64_t amdgpu_vram_mgr_usage(struct ttm_mem_type_manager *man)
>    */
>   uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man)
>   {
> -	struct amdgpu_vram_mgr *mgr = man->priv;
> +	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   
>   	return atomic64_read(&mgr->vis_usage);
>   }
> @@ -592,7 +602,7 @@ uint64_t amdgpu_vram_mgr_vis_usage(struct ttm_mem_type_manager *man)
>   static void amdgpu_vram_mgr_debug(struct ttm_mem_type_manager *man,
>   				  struct drm_printer *printer)
>   {
> -	struct amdgpu_vram_mgr *mgr = man->priv;
> +	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   
>   	spin_lock(&mgr->lock);
>   	drm_mm_print(&mgr->mm, printer);

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

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

* Re: [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args
  2020-07-31  4:05 ` [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args Dave Airlie
@ 2020-07-31 13:32   ` Christian König
  2020-08-04  1:42     ` Dave Airlie
  0 siblings, 1 reply; 99+ messages in thread
From: Christian König @ 2020-07-31 13:32 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This makes it easier to move these to a driver allocated system

No, sorry that looks like going into the wrong direction to me.

I already wanted to suggest to get rid of the size argument instead.

Christian.

>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c | 15 +++++------
>   drivers/gpu/drm/drm_gem_vram_helper.c   | 10 ++++----
>   drivers/gpu/drm/nouveau/nouveau_ttm.c   | 21 ++++++++++------
>   drivers/gpu/drm/qxl/qxl_ttm.c           | 12 +++------
>   drivers/gpu/drm/radeon/radeon_ttm.c     | 33 ++++++++++++-------------
>   drivers/gpu/drm/ttm/ttm_bo_manager.c    | 19 ++++++++++----
>   drivers/gpu/drm/vmwgfx/vmwgfx_drv.c     | 13 +++-------
>   include/drm/ttm/ttm_bo_driver.h         |  7 ++++--
>   8 files changed, 67 insertions(+), 63 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> index 4beec1c4e037..d4d81f808b01 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ttm.c
> @@ -67,12 +67,9 @@ static int amdgpu_ttm_init_on_chip(struct amdgpu_device *adev,
>   				    unsigned int type,
>   				    uint64_t size)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&adev->mman.bdev, type);
> -
> -	man->available_caching = TTM_PL_FLAG_UNCACHED;
> -	man->default_caching = TTM_PL_FLAG_UNCACHED;
> -
> -	return ttm_bo_man_init(&adev->mman.bdev, man, size >> PAGE_SHIFT);
> +	return ttm_bo_man_init(&adev->mman.bdev, type,
> +			       TTM_PL_FLAG_UNCACHED, TTM_PL_FLAG_UNCACHED,
> +			       false, size >> PAGE_SHIFT);
>   }
>   
>   /**
> @@ -2014,9 +2011,9 @@ void amdgpu_ttm_fini(struct amdgpu_device *adev)
>   
>   	amdgpu_vram_mgr_fini(adev);
>   	amdgpu_gtt_mgr_fini(adev);
> -	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_GDS));
> -	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_GWS));
> -	ttm_bo_man_takedown(&adev->mman.bdev, ttm_manager_type(&adev->mman.bdev, AMDGPU_PL_OA));
> +	ttm_bo_man_takedown(&adev->mman.bdev, AMDGPU_PL_GDS);
> +	ttm_bo_man_takedown(&adev->mman.bdev, AMDGPU_PL_GWS);
> +	ttm_bo_man_takedown(&adev->mman.bdev, AMDGPU_PL_OA);
>   	ttm_bo_device_release(&adev->mman.bdev);
>   	adev->mman.initialized = false;
>   	DRM_INFO("amdgpu: ttm finalized\n");
> diff --git a/drivers/gpu/drm/drm_gem_vram_helper.c b/drivers/gpu/drm/drm_gem_vram_helper.c
> index 08fbfa32540a..b98af8daa540 100644
> --- a/drivers/gpu/drm/drm_gem_vram_helper.c
> +++ b/drivers/gpu/drm/drm_gem_vram_helper.c
> @@ -1103,7 +1103,6 @@ EXPORT_SYMBOL(drm_vram_mm_debugfs_init);
>   static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
>   			    uint64_t vram_base, size_t vram_size)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&vmm->bdev, TTM_PL_VRAM);
>   	int ret;
>   
>   	vmm->vram_base = vram_base;
> @@ -1116,9 +1115,10 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
>   	if (ret)
>   		return ret;
>   
> -	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
> -	man->default_caching = TTM_PL_FLAG_WC;
> -	ret = ttm_bo_man_init(&vmm->bdev, man, vram_size >> PAGE_SHIFT);
> +	ret = ttm_bo_man_init(&vmm->bdev, TTM_PL_VRAM,
> +			      TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
> +			      TTM_PL_FLAG_WC, false,
> +			      vram_size >> PAGE_SHIFT);
>   	if (ret)
>   		return ret;
>   
> @@ -1127,7 +1127,7 @@ static int drm_vram_mm_init(struct drm_vram_mm *vmm, struct drm_device *dev,
>   
>   static void drm_vram_mm_cleanup(struct drm_vram_mm *vmm)
>   {
> -	ttm_bo_man_takedown(&vmm->bdev, ttm_manager_type(&vmm->bdev, TTM_PL_VRAM));
> +	ttm_bo_man_takedown(&vmm->bdev, TTM_PL_VRAM);
>   	ttm_bo_device_release(&vmm->bdev);
>   }
>   
> diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> index 1b9d9362132d..225f9af2eaa1 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> @@ -156,16 +156,17 @@ nouveau_ttm_init_host(struct nouveau_drm *drm, u8 kind)
>   static int
>   nouveau_ttm_init_vram(struct nouveau_drm *drm)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
>   	struct nvif_mmu *mmu = &drm->client.mmu;
>   
> -	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
> -	man->default_caching = TTM_PL_FLAG_WC;
> -
>   	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
> +		struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
> +
>   		/* Some BARs do not support being ioremapped WC */
>   		const u8 type = mmu->type[drm->ttm.type_vram].type;
>   
> +		man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
> +		man->default_caching = TTM_PL_FLAG_WC;
> +
>   		if (type & NVIF_MEM_UNCACHED) {
>   			man->available_caching = TTM_PL_FLAG_UNCACHED;
>   			man->default_caching = TTM_PL_FLAG_UNCACHED;
> @@ -178,7 +179,9 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
>   		ttm_bo_use_mm(man);
>   		return 0;
>   	} else {
> -		return ttm_bo_man_init(&drm->ttm.bdev, man,
> +		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_VRAM,
> +				       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
> +				       TTM_PL_FLAG_WC, false,
>   				       drm->gem.vram_available >> PAGE_SHIFT);
>   	}
>   }
> @@ -193,7 +196,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
>   		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
>   		ttm_bo_man_cleanup(man);
>   	} else
> -		ttm_bo_man_takedown(&drm->ttm.bdev, man);
> +		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_VRAM);
>   }
>   
>   static int
> @@ -216,7 +219,9 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
>   	else if (!drm->agp.bridge)
>   		man->func = &nv04_gart_manager;
>   	else
> -		return ttm_bo_man_init(&drm->ttm.bdev, man,
> +		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_TT,
> +				       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
> +				       TTM_PL_FLAG_WC, true,
>   				       size_pages);
>   
>   	ttm_bo_init_mm_base(&drm->ttm.bdev, man,
> @@ -232,7 +237,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
>   
>   	if (drm->client.device.info.family < NV_DEVICE_INFO_V0_TESLA &&
>   	    drm->agp.bridge)
> -		ttm_bo_man_takedown(&drm->ttm.bdev, man);
> +		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_TT);
>   	else {
>   		ttm_bo_disable_mm(man);
>   		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
> diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
> index 9aea35a66e25..5b569415854e 100644
> --- a/drivers/gpu/drm/qxl/qxl_ttm.c
> +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
> @@ -219,12 +219,8 @@ static int qxl_ttm_init_mem_type(struct qxl_device *qdev,
>   				 unsigned int type,
>   				 uint64_t size)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&qdev->mman.bdev, type);
> -
> -	man->available_caching = TTM_PL_MASK_CACHING;
> -	man->default_caching = TTM_PL_FLAG_CACHED;
> -
> -	return ttm_bo_man_init(&qdev->mman.bdev, man, size);
> +	return ttm_bo_man_init(&qdev->mman.bdev, type, TTM_PL_MASK_CACHING,
> +			       TTM_PL_FLAG_CACHED, false, size);
>   }
>   
>   int qxl_ttm_init(struct qxl_device *qdev)
> @@ -266,8 +262,8 @@ int qxl_ttm_init(struct qxl_device *qdev)
>   
>   void qxl_ttm_fini(struct qxl_device *qdev)
>   {
> -	ttm_bo_man_takedown(&qdev->mman.bdev, ttm_manager_type(&qdev->mman.bdev, TTM_PL_VRAM));
> -	ttm_bo_man_takedown(&qdev->mman.bdev, ttm_manager_type(&qdev->mman.bdev, TTM_PL_PRIV));
> +	ttm_bo_man_takedown(&qdev->mman.bdev, TTM_PL_VRAM);
> +	ttm_bo_man_takedown(&qdev->mman.bdev, TTM_PL_PRIV);
>   	ttm_bo_device_release(&qdev->mman.bdev);
>   	DRM_INFO("qxl: ttm finalized\n");
>   }
> diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
> index 3849d0e852bc..793031bb9bd2 100644
> --- a/drivers/gpu/drm/radeon/radeon_ttm.c
> +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
> @@ -68,36 +68,35 @@ struct radeon_device *radeon_get_rdev(struct ttm_bo_device *bdev)
>   
>   static int radeon_ttm_init_vram(struct radeon_device *rdev)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM);
> -
> -	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
> -	man->default_caching = TTM_PL_FLAG_WC;
> -
> -	return ttm_bo_man_init(&rdev->mman.bdev, man,
> +	return ttm_bo_man_init(&rdev->mman.bdev, TTM_PL_VRAM,
> +			       TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC,
> +			       TTM_PL_FLAG_WC, false,
>   			       rdev->mc.real_vram_size >> PAGE_SHIFT);
>   }
>   
>   static int radeon_ttm_init_gtt(struct radeon_device *rdev)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(&rdev->mman.bdev, TTM_PL_TT);
> +	uint32_t available_caching, default_caching;
> +
> +	available_caching = TTM_PL_MASK_CACHING;
> +	default_caching = TTM_PL_FLAG_CACHED;
>   
> -	man->available_caching = TTM_PL_MASK_CACHING;
> -	man->default_caching = TTM_PL_FLAG_CACHED;
> -	man->use_tt = true;
>   #if IS_ENABLED(CONFIG_AGP)
>   	if (rdev->flags & RADEON_IS_AGP) {
>   		if (!rdev->ddev->agp) {
>   			DRM_ERROR("AGP is not enabled\n");
>   			return -EINVAL;
>   		}
> -		man->available_caching = TTM_PL_FLAG_UNCACHED |
> -					 TTM_PL_FLAG_WC;
> -		man->default_caching = TTM_PL_FLAG_WC;
> +		available_caching = TTM_PL_FLAG_UNCACHED |
> +			TTM_PL_FLAG_WC;
> +		default_caching = TTM_PL_FLAG_WC;
>   	}
>   #endif
>   
> -	return ttm_bo_man_init(&rdev->mman.bdev, man,
> -			      rdev->mc.gtt_size >> PAGE_SHIFT);
> +	return ttm_bo_man_init(&rdev->mman.bdev, TTM_PL_TT,
> +			       available_caching,
> +			       default_caching, true,
> +			       rdev->mc.gtt_size >> PAGE_SHIFT);
>   }
>   
>   static void radeon_evict_flags(struct ttm_buffer_object *bo,
> @@ -825,8 +824,8 @@ void radeon_ttm_fini(struct radeon_device *rdev)
>   		}
>   		radeon_bo_unref(&rdev->stolen_vga_memory);
>   	}
> -	ttm_bo_man_takedown(&rdev->mman.bdev, ttm_manager_type(&rdev->mman.bdev, TTM_PL_VRAM));
> -	ttm_bo_man_takedown(&rdev->mman.bdev, ttm_manager_type(&rdev->mman.bdev, TTM_PL_TT));
> +	ttm_bo_man_takedown(&rdev->mman.bdev, TTM_PL_VRAM);
> +	ttm_bo_man_takedown(&rdev->mman.bdev, TTM_PL_TT);
>   	ttm_bo_device_release(&rdev->mman.bdev);
>   	radeon_gart_fini(rdev);
>   	rdev->mman.initialized = false;
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index f60a9a5d429d..2f5fa44b6474 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -107,19 +107,27 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
>   static const struct ttm_mem_type_manager_func ttm_bo_manager_func;
>   
>   int ttm_bo_man_init(struct ttm_bo_device *bdev,
> -		    struct ttm_mem_type_manager *man,
> +		    unsigned type,
> +		    uint32_t available_caching,
> +		    uint32_t default_caching,
> +		    bool use_tt,
>   		    unsigned long p_size)
>   {
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
>   	struct ttm_range_manager *rman;
>   
> -	man->func = &ttm_bo_manager_func;
> -
> -	ttm_bo_init_mm_base(bdev, man, p_size);
> +	man->available_caching = available_caching;
> +	man->default_caching = default_caching;
> +	man->use_tt = use_tt;
>   
>   	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
>   	if (!rman)
>   		return -ENOMEM;
>   
> +	man->func = &ttm_bo_manager_func;
> +
> +	ttm_bo_init_mm_base(bdev, man, p_size);
> +
>   	drm_mm_init(&rman->mm, 0, p_size);
>   	spin_lock_init(&rman->lock);
>   	man->priv = rman;
> @@ -130,8 +138,9 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   EXPORT_SYMBOL(ttm_bo_man_init);
>   
>   int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
> -			struct ttm_mem_type_manager *man)
> +			unsigned type)
>   {
> +	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
>   	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
>   	struct drm_mm *mm = &rman->mm;
>   	int ret;
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index dff6990ff9ed..1849d913d521 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -626,13 +626,9 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>   	ret = vmw_thp_init(dev_priv);
>   #else
> -	struct ttm_mem_type_manager *man = &dev_priv->bdev.man[TTM_PL_VRAM];
> -
> -	man->available_caching = TTM_PL_FLAG_CACHED;
> -	man->default_caching = TTM_PL_FLAG_CACHED;
> -
> -	ret = ttm_bo_man_init(&dev_priv->bdev, man,
> -			      dev_priv->vram_size >> PAGE_SHIFT);
> +	ret = ttm_bo_man_init(&dev_priv->bdev, TTM_PL_VRAM,
> +			      TTM_PL_FLAG_CACHED, TTM_PL_FLAG_CACHED,
> +			      false, dev_priv->vram_size >> PAGE_SHIFT);
>   #endif
>   	ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM)->use_type = false;
>   	return ret;
> @@ -643,8 +639,7 @@ static void vmw_takedown_vram_manager(struct vmw_private *dev_priv)
>   #ifdef CONFIG_TRANSPARENT_HUGEPAGE
>   	vmw_thp_takedown(dev_priv);
>   #else
> -	ttm_bo_man_takedown(&dev_priv->bdev,
> -			    ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM));
> +	ttm_bo_man_takedown(&dev_priv->bdev, TTM_PL_VRAM);
>   #endif
>   }
>   
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 723171fd94da..6319d85d7270 100644
> --- a/include/drm/ttm/ttm_bo_driver.hA r
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -809,8 +809,11 @@ int ttm_bo_pipeline_gutting(struct ttm_buffer_object *bo);
>   pgprot_t ttm_io_prot(uint32_t caching_flags, pgprot_t tmp);
>   
>   int ttm_bo_man_init(struct ttm_bo_device *bdev,
> -		    struct ttm_mem_type_manager *man,
> +		    unsigned type,
> +		    uint32_t available_caching,
> +		    uint32_t default_caching,
> +		    bool use_tt,
>   		    unsigned long p_size);
>   int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
> -			struct ttm_mem_type_manager *man);
> +			unsigned type);
>   #endif

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

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

* Re: [PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation
  2020-07-31  4:05 ` [PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation Dave Airlie
@ 2020-07-31 13:33   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:33 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/ttm/ttm_bo_manager.c | 32 +++++++++++++++++-----------
>   1 file changed, 20 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 2f5fa44b6474..2782ccff9b66 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -44,16 +44,22 @@
>    */
>   
>   struct ttm_range_manager {
> +	struct ttm_mem_type_manager manager;
>   	struct drm_mm mm;
>   	spinlock_t lock;
>   };
>   
> +static inline struct ttm_range_manager *to_range_manager(struct ttm_mem_type_manager *man)
> +{
> +	return container_of(man, struct ttm_range_manager, manager);
> +}
> +
>   static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
>   			       struct ttm_buffer_object *bo,
>   			       const struct ttm_place *place,
>   			       struct ttm_mem_reg *mem)
>   {
> -	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> +	struct ttm_range_manager *rman = to_range_manager(man);
>   	struct drm_mm *mm = &rman->mm;
>   	struct drm_mm_node *node;
>   	enum drm_mm_insert_mode mode;
> @@ -92,7 +98,7 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
>   static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
>   				struct ttm_mem_reg *mem)
>   {
> -	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> +	struct ttm_range_manager *rman = to_range_manager(man);
>   
>   	if (mem->mm_node) {
>   		spin_lock(&rman->lock);
> @@ -113,25 +119,26 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   		    bool use_tt,
>   		    unsigned long p_size)
>   {
> -	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
> +	struct ttm_mem_type_manager *man;
>   	struct ttm_range_manager *rman;
>   
> -	man->available_caching = available_caching;
> -	man->default_caching = default_caching;
> -	man->use_tt = use_tt;
> -
>   	rman = kzalloc(sizeof(*rman), GFP_KERNEL);
>   	if (!rman)
>   		return -ENOMEM;
>   
> +	man = &rman->manager;
> +	man->available_caching = available_caching;
> +	man->default_caching = default_caching;
> +	man->use_tt = use_tt;
> +
>   	man->func = &ttm_bo_manager_func;
>   
>   	ttm_bo_init_mm_base(bdev, man, p_size);
>   
>   	drm_mm_init(&rman->mm, 0, p_size);
>   	spin_lock_init(&rman->lock);
> -	man->priv = rman;
>   
> +	ttm_set_driver_manager(bdev, type, &rman->manager);
>   	ttm_bo_use_mm(man);
>   	return 0;
>   }
> @@ -141,7 +148,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
>   			unsigned type)
>   {
>   	struct ttm_mem_type_manager *man = ttm_manager_type(bdev, type);
> -	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> +	struct ttm_range_manager *rman = to_range_manager(man);
>   	struct drm_mm *mm = &rman->mm;
>   	int ret;
>   
> @@ -155,10 +162,11 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
>   	drm_mm_clean(mm);
>   	drm_mm_takedown(mm);
>   	spin_unlock(&rman->lock);
> -	kfree(rman);
> -	man->priv = NULL;
>   
>   	ttm_bo_man_cleanup(man);
> +	ttm_set_driver_manager(bdev, type, NULL);
> +	kfree(rman);
> +
>   	return 0;
>   }
>   EXPORT_SYMBOL(ttm_bo_man_takedown);
> @@ -166,7 +174,7 @@ EXPORT_SYMBOL(ttm_bo_man_takedown);
>   static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
>   			     struct drm_printer *printer)
>   {
> -	struct ttm_range_manager *rman = (struct ttm_range_manager *) man->priv;
> +	struct ttm_range_manager *rman = to_range_manager(man);
>   
>   	spin_lock(&rman->lock);
>   	drm_mm_print(&rman->mm, printer);

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

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

* Re: [PATCH 44/49] drm/ttm: drop priv pointer in memory manager
  2020-07-31  4:05 ` [PATCH 44/49] drm/ttm: drop priv pointer in memory manager Dave Airlie
@ 2020-07-31 13:33   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 13:33 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This isn't needed anymore by any drivers.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   include/drm/ttm/ttm_bo_driver.h | 2 --
>   1 file changed, 2 deletions(-)
>
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 6319d85d7270..a38704fe0737 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -123,7 +123,6 @@ struct ttm_mem_type_manager_func {
>    * @default_caching: The default caching policy used for a buffer object
>    * placed in this memory type if the user doesn't provide one.
>    * @func: structure pointer implementing the range manager. See above
> - * @priv: Driver private closure for @func.
>    * @io_reserve_mutex: Mutex optionally protecting shared io_reserve structures
>    * @use_io_reserve_lru: Use an lru list to try to unreserve io_mem_regions
>    * reserved by the TTM vm system.
> @@ -152,7 +151,6 @@ struct ttm_mem_type_manager {
>   	uint32_t available_caching;
>   	uint32_t default_caching;
>   	const struct ttm_mem_type_manager_func *func;
> -	void *priv;
>   	struct mutex io_reserve_mutex;
>   	bool use_io_reserve_lru;
>   	spinlock_t move_lock;

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

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

* Re: [PATCH 46/49] drm/ttm: drop man->bdev link.
  2020-07-31  4:05 ` [PATCH 46/49] drm/ttm: drop man->bdev link Dave Airlie
@ 2020-07-31 14:54   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 14:54 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This link isn't needed anymore, drop it from the init interface.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   | 2 +-
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  | 2 +-
>   drivers/gpu/drm/nouveau/nouveau_ttm.c         | 6 ++----
>   drivers/gpu/drm/ttm/ttm_bo.c                  | 6 ++----
>   drivers/gpu/drm/ttm/ttm_bo_manager.c          | 2 +-
>   drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c | 2 +-
>   drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           | 2 +-
>   include/drm/ttm/ttm_bo_api.h                  | 3 +--
>   include/drm/ttm/ttm_bo_driver.h               | 2 --
>   9 files changed, 10 insertions(+), 17 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index 83d88ee73468..b4480ca30988 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -108,7 +108,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>   	man->available_caching = TTM_PL_MASK_CACHING;
>   	man->default_caching = TTM_PL_FLAG_CACHED;
>   
> -	ttm_bo_init_mm_base(&adev->mman.bdev, man, gtt_size >> PAGE_SHIFT);
> +	ttm_bo_init_mm_base(man, gtt_size >> PAGE_SHIFT);
>   
>   	start = AMDGPU_GTT_MAX_TRANSFER_SIZE * AMDGPU_GTT_NUM_TRANSFER_WINDOWS;
>   	size = (adev->gmc.gart_size >> PAGE_SHIFT) - start;
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index d451851c8689..f0e65a6fdf88 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -190,7 +190,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>   	man->available_caching = TTM_PL_FLAG_UNCACHED | TTM_PL_FLAG_WC;
>   	man->default_caching = TTM_PL_FLAG_WC;
>   
> -	ttm_bo_init_mm_base(&adev->mman.bdev, man, adev->gmc.real_vram_size >> PAGE_SHIFT);
> +	ttm_bo_init_mm_base(man, adev->gmc.real_vram_size >> PAGE_SHIFT);
>   
>   	man->func = &amdgpu_vram_mgr_func;
>   
> diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> index 5b0af2065ad9..89521d3ed9da 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> @@ -174,8 +174,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
>   
>   		man->func = &nouveau_vram_manager;
>   		man->use_io_reserve_lru = true;
> -		ttm_bo_init_mm_base(&drm->ttm.bdev, man,
> -				    drm->gem.vram_available >> PAGE_SHIFT);
> +		ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
>   		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
>   		ttm_bo_use_mm(man);
>   		return 0;
> @@ -236,8 +235,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
>   	man->available_caching = available_caching;
>   	man->default_caching = default_caching;
>   	man->use_tt = true;
> -	ttm_bo_init_mm_base(&drm->ttm.bdev, man,
> -			    size_pages);
> +	ttm_bo_init_mm_base(man, size_pages);
>   	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
>   	ttm_bo_use_mm(man);
>   	return 0;
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index 1e8fda1c9b3a..f2b41c4d7d51 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1464,8 +1464,7 @@ int ttm_bo_evict_mm(struct ttm_bo_device *bdev, unsigned mem_type)
>   }
>   EXPORT_SYMBOL(ttm_bo_evict_mm);
>   
> -void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> -			 struct ttm_mem_type_manager *man,
> +void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
>   			 unsigned long p_size)
>   {
>   	unsigned i;
> @@ -1475,7 +1474,6 @@ void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
>   	mutex_init(&man->io_reserve_mutex);
>   	spin_lock_init(&man->move_lock);
>   	INIT_LIST_HEAD(&man->io_reserve_lru);
> -	man->bdev = bdev;
>   	man->size = p_size;
>   
>   	for (i = 0; i < TTM_MAX_BO_PRIORITY; ++i)
> @@ -1588,7 +1586,7 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
>   	man->available_caching = TTM_PL_MASK_CACHING;
>   	man->default_caching = TTM_PL_FLAG_CACHED;
>   
> -	ttm_bo_init_mm_base(bdev, man, 0);
> +	ttm_bo_init_mm_base(man, 0);
>   	ttm_bo_use_mm(man);
>   }
>   
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 2782ccff9b66..6c6eedf84ca6 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -133,7 +133,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   
>   	man->func = &ttm_bo_manager_func;
>   
> -	ttm_bo_init_mm_base(bdev, man, p_size);
> +	ttm_bo_init_mm_base(man, p_size);
>   
>   	drm_mm_init(&rman->mm, 0, p_size);
>   	spin_lock_init(&rman->lock);
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> index 14430c243ce5..2b60957f7c4a 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> @@ -116,7 +116,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
>   	man->default_caching = TTM_PL_FLAG_CACHED;
>   	/* TODO: This is most likely not correct */
>   	man->use_tt = true;
> -	ttm_bo_init_mm_base(&dev_priv->bdev, man, 0);
> +	ttm_bo_init_mm_base(man, 0);
>   	spin_lock_init(&gman->lock);
>   	gman->used_gmr_pages = 0;
>   	ida_init(&gman->gmr_ida);
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> index d2dde8159c3d..d5a3eb709384 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> @@ -134,7 +134,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
>   	man->available_caching = TTM_PL_FLAG_CACHED;
>   	man->default_caching = TTM_PL_FLAG_CACHED;
>   
> -	ttm_bo_init_mm_base(&dev_priv->bdev, man,
> +	ttm_bo_init_mm_base(man,
>   			    dev_priv->vram_size >> PAGE_SHIFT);
>   
>   
> diff --git a/include/drm/ttm/ttm_bo_api.h b/include/drm/ttm/ttm_bo_api.h
> index 27dde1371376..d6938133535a 100644
> --- a/include/drm/ttm/ttm_bo_api.h
> +++ b/include/drm/ttm/ttm_bo_api.h
> @@ -547,8 +547,7 @@ int ttm_bo_create(struct ttm_bo_device *bdev, unsigned long size,
>    * May also return driver-specified errors.
>    */
>   struct ttm_mem_type_manager;
> -void ttm_bo_init_mm_base(struct ttm_bo_device *bdev,
> -			 struct ttm_mem_type_manager *man,
> +void ttm_bo_init_mm_base(struct ttm_mem_type_manager *man,
>   			 unsigned long p_size);
>   
>   /**
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index a38704fe0737..bfc549782775 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -138,8 +138,6 @@ struct ttm_mem_type_manager_func {
>   
>   
>   struct ttm_mem_type_manager {
> -	struct ttm_bo_device *bdev;
> -
>   	/*
>   	 * No protection. Constant from start.
>   	 */

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

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

* Re: [PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references.
  2020-07-31  4:05 ` [PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references Dave Airlie
@ 2020-07-31 14:55   ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 14:55 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> Just store the device in the private so the link
> can be removed from the manager
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>

Reviewed-by: Christian König <christian.koenig@amd.com>

> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c | 7 +++++--
>   1 file changed, 5 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index 9d4a13926b8c..d451851c8689 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -34,6 +34,7 @@ struct amdgpu_vram_mgr {
>   	spinlock_t lock;
>   	atomic64_t usage;
>   	atomic64_t vis_usage;
> +	struct amdgpu_device *adev;
>   };
>   
>   static inline struct amdgpu_vram_mgr *to_vram_mgr(struct ttm_mem_type_manager *man)
> @@ -196,6 +197,8 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>   	drm_mm_init(&mgr->mm, 0, man->size);
>   	spin_lock_init(&mgr->lock);
>   
> +	mgr->adev = adev;
> +
>   	/* Add the two VRAM-related sysfs files */
>   	ret = sysfs_create_files(&adev->dev->kobj, amdgpu_vram_mgr_attributes);
>   	if (ret)
> @@ -323,8 +326,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
>   			       const struct ttm_place *place,
>   			       struct ttm_mem_reg *mem)
>   {
> -	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
>   	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
> +	struct amdgpu_device *adev = mgr->adev;
>   	struct drm_mm *mm = &mgr->mm;
>   	struct drm_mm_node *nodes;
>   	enum drm_mm_insert_mode mode;
> @@ -439,8 +442,8 @@ static int amdgpu_vram_mgr_new(struct ttm_mem_type_manager *man,
>   static void amdgpu_vram_mgr_del(struct ttm_mem_type_manager *man,
>   				struct ttm_mem_reg *mem)
>   {
> -	struct amdgpu_device *adev = amdgpu_ttm_adev(man->bdev);
>   	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
> +	struct amdgpu_device *adev = mgr->adev;
>   	struct drm_mm_node *nodes = mem->mm_node;
>   	uint64_t usage = 0, vis_usage = 0;
>   	unsigned pages = mem->num_pages;

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

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

* Re: [PATCH 47/49] drm/ttm: drop list of memory managers from device.
  2020-07-31  4:05 ` [PATCH 47/49] drm/ttm: drop list of memory managers from device Dave Airlie
  2020-07-31  9:55   ` daniel
@ 2020-07-31 14:57   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 14:57 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> The driver now controls these, the core just controls the system
> memory one.
>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/ttm/ttm_bo.c    | 2 --
>   include/drm/ttm/ttm_bo_driver.h | 6 ++++--
>   2 files changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index f2b41c4d7d51..f35548ff17e8 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -1608,8 +1608,6 @@ int ttm_bo_device_init(struct ttm_bo_device *bdev,
>   
>   	bdev->driver = driver;
>   
> -	memset(bdev->man_priv, 0, sizeof(bdev->man_priv));
> -
>   	ttm_bo_init_sysman(bdev);
>   
>   	bdev->vma_manager = vma_manager;
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index bfc549782775..b2ffeaed94e7 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -414,7 +414,7 @@ struct ttm_bo_device {
>   	/*
>   	 * access via ttm_manager_type.
>   	 */
> -	struct ttm_mem_type_manager man_priv[TTM_NUM_MEM_TYPES];
> +	struct ttm_mem_type_manager sysman; /* move to global */
>   	struct ttm_mem_type_manager *man_drv[TTM_NUM_MEM_TYPES];
>   	/*
>   	 * Protected by internal locks.
> @@ -446,9 +446,11 @@ struct ttm_bo_device {
>   static inline struct ttm_mem_type_manager *ttm_manager_type(struct ttm_bo_device *bdev,
>   							    int mem_type)
>   {
> +	if (mem_type == TTM_PL_SYSTEM)
> +		return &bdev->sysman;
>   	if (bdev->man_drv[mem_type])
>   		return bdev->man_drv[mem_type];
> -	return &bdev->man_priv[mem_type];
> +	return NULL;

Could be simplified to "return bdev->man_drv[mem_type];" if we just 
assign bdev->man_drv[TTM_PL_SYSTEM] during driver init.

Christian.

>   }
>   
>   static inline void ttm_set_driver_manager(struct ttm_bo_device *bdev,

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

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

* Re: [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get.
  2020-07-31  4:05 ` [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get Dave Airlie
  2020-07-31  9:51   ` daniel
@ 2020-07-31 14:59   ` Christian König
  1 sibling, 0 replies; 99+ messages in thread
From: Christian König @ 2020-07-31 14:59 UTC (permalink / raw)
  To: Dave Airlie, dri-devel; +Cc: sroland, bskeggs, kraxel

Am 31.07.20 um 06:05 schrieb Dave Airlie:
> From: Dave Airlie <airlied@redhat.com>
>
> This is probably something we could consider removing, vmwgfx
> is the only user, and we might be able to faciliate it another way
>
> but for now just consolidate it all into accessors.

I always found the "use_type" wording confusing and this set_use() name 
even more confusing.

Why not call it "enabled"?

Christian.

>
> Signed-off-by: Dave Airlie <airlied@redhat.com>
> ---
>   drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c   |  4 ++--
>   drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c  |  4 ++--
>   drivers/gpu/drm/nouveau/nouveau_ttm.c         |  8 ++++----
>   drivers/gpu/drm/ttm/ttm_bo.c                  |  6 +++---
>   drivers/gpu/drm/ttm/ttm_bo_manager.c          |  4 ++--
>   drivers/gpu/drm/vmwgfx/vmwgfx_drv.c           | 14 +++++++-------
>   drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c |  4 ++--
>   drivers/gpu/drm/vmwgfx/vmwgfx_thp.c           |  4 ++--
>   include/drm/ttm/ttm_bo_driver.h               |  8 ++++----
>   9 files changed, 28 insertions(+), 28 deletions(-)
>
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> index b4480ca30988..7e84aa2c0064 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_gtt_mgr.c
> @@ -128,7 +128,7 @@ int amdgpu_gtt_mgr_init(struct amdgpu_device *adev, uint64_t gtt_size)
>   	}
>   
>   	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_TT, &mgr->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   	return 0;
>   }
>   
> @@ -146,7 +146,7 @@ void amdgpu_gtt_mgr_fini(struct amdgpu_device *adev)
>   	struct amdgpu_gtt_mgr *mgr = to_gtt_mgr(man);
>   	int ret;
>   
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>   
>   	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
>   	if (ret)
> diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> index f0e65a6fdf88..50949aa968fd 100644
> --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_vram_mgr.c
> @@ -205,7 +205,7 @@ int amdgpu_vram_mgr_init(struct amdgpu_device *adev)
>   		DRM_ERROR("Failed to register sysfs\n");
>   
>   	ttm_set_driver_manager(&adev->mman.bdev, TTM_PL_VRAM, &mgr->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   	return 0;
>   }
>   
> @@ -223,7 +223,7 @@ void amdgpu_vram_mgr_fini(struct amdgpu_device *adev)
>   	struct amdgpu_vram_mgr *mgr = to_vram_mgr(man);
>   	int ret;
>   
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>   
>   	ret = ttm_bo_force_list_clean(&adev->mman.bdev, man);
>   	if (ret)
> diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> index 89521d3ed9da..32ce930d1bd8 100644
> --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
> +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
> @@ -176,7 +176,7 @@ nouveau_ttm_init_vram(struct nouveau_drm *drm)
>   		man->use_io_reserve_lru = true;
>   		ttm_bo_init_mm_base(man, drm->gem.vram_available >> PAGE_SHIFT);
>   		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, man);
> -		ttm_bo_use_mm(man);
> +		ttm_mm_set_use(man, true);
>   		return 0;
>   	} else {
>   		return ttm_bo_man_init(&drm->ttm.bdev, TTM_PL_VRAM,
> @@ -192,7 +192,7 @@ nouveau_ttm_fini_vram(struct nouveau_drm *drm)
>   	struct ttm_mem_type_manager *man = ttm_manager_type(&drm->ttm.bdev, TTM_PL_VRAM);
>   
>   	if (drm->client.device.info.family >= NV_DEVICE_INFO_V0_TESLA) {
> -		ttm_bo_disable_mm(man);
> +		ttm_mm_set_use(man, false);
>   		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
>   		ttm_bo_man_cleanup(man);
>   		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_VRAM, NULL);
> @@ -237,7 +237,7 @@ nouveau_ttm_init_gtt(struct nouveau_drm *drm)
>   	man->use_tt = true;
>   	ttm_bo_init_mm_base(man, size_pages);
>   	ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, man);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   	return 0;
>   }
>   
> @@ -250,7 +250,7 @@ nouveau_ttm_fini_gtt(struct nouveau_drm *drm)
>   	    drm->agp.bridge)
>   		ttm_bo_man_takedown(&drm->ttm.bdev, TTM_PL_TT);
>   	else {
> -		ttm_bo_disable_mm(man);
> +		ttm_mm_set_use(man, false);
>   		ttm_bo_force_list_clean(&drm->ttm.bdev, man);
>   		ttm_bo_man_cleanup(man);
>   		ttm_set_driver_manager(&drm->ttm.bdev, TTM_PL_TT, NULL);
> diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> index bfc20cb27ed6..3bec6e4bc87d 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> @@ -996,7 +996,7 @@ static int ttm_bo_mem_placement(struct ttm_buffer_object *bo,
>   		return ret;
>   
>   	man = ttm_manager_type(bdev, mem_type);
> -	if (!man || !man->use_type)
> +	if (!man || !ttm_mm_used(man))
>   		return -EBUSY;
>   
>   	if (!ttm_bo_mt_compatible(man, mem_type, place, &cur_flags))
> @@ -1548,7 +1548,7 @@ int ttm_bo_device_release(struct ttm_bo_device *bdev)
>   	struct ttm_mem_type_manager *man;
>   
>   	man = ttm_manager_type(bdev, TTM_PL_SYSTEM);
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>   
>   	mutex_lock(&ttm_global_mutex);
>   	list_del(&bdev->device_list);
> @@ -1585,7 +1585,7 @@ static void ttm_bo_init_sysman(struct ttm_bo_device *bdev)
>   	man->default_caching = TTM_PL_FLAG_CACHED;
>   
>   	ttm_bo_init_mm_base(man, 0);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   }
>   
>   int ttm_bo_device_init(struct ttm_bo_device *bdev,
> diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> index 6c6eedf84ca6..5ed4e4317789 100644
> --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
> +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
> @@ -139,7 +139,7 @@ int ttm_bo_man_init(struct ttm_bo_device *bdev,
>   	spin_lock_init(&rman->lock);
>   
>   	ttm_set_driver_manager(bdev, type, &rman->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   	return 0;
>   }
>   EXPORT_SYMBOL(ttm_bo_man_init);
> @@ -152,7 +152,7 @@ int ttm_bo_man_takedown(struct ttm_bo_device *bdev,
>   	struct drm_mm *mm = &rman->mm;
>   	int ret;
>   
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>   
>   	ret = ttm_bo_force_list_clean(bdev, man);
>   	if (ret)
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> index 1849d913d521..9b9cc3b57a24 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.c
> @@ -630,7 +630,7 @@ static int vmw_init_vram_manager(struct vmw_private *dev_priv)
>   			      TTM_PL_FLAG_CACHED, TTM_PL_FLAG_CACHED,
>   			      false, dev_priv->vram_size >> PAGE_SHIFT);
>   #endif
> -	ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM)->use_type = false;
> +	ttm_mm_set_use(ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM), false);
>   	return ret;
>   }
>   
> @@ -1190,9 +1190,9 @@ static void __vmw_svga_enable(struct vmw_private *dev_priv)
>   	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
>   
>   	spin_lock(&dev_priv->svga_lock);
> -	if (!man->use_type) {
> +	if (!ttm_mm_used(man)) {
>   		vmw_write(dev_priv, SVGA_REG_ENABLE, SVGA_REG_ENABLE);
> -		man->use_type = true;
> +		ttm_mm_set_use(man, true);
>   	}
>   	spin_unlock(&dev_priv->svga_lock);
>   }
> @@ -1221,8 +1221,8 @@ static void __vmw_svga_disable(struct vmw_private *dev_priv)
>   	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, TTM_PL_VRAM);
>   
>   	spin_lock(&dev_priv->svga_lock);
> -	if (man->use_type) {
> -		man->use_type = false;
> +	if (ttm_mm_used(man)) {
> +		ttm_mm_set_use(man, false);
>   		vmw_write(dev_priv, SVGA_REG_ENABLE,
>   			  SVGA_REG_ENABLE_HIDE |
>   			  SVGA_REG_ENABLE_ENABLE);
> @@ -1255,8 +1255,8 @@ void vmw_svga_disable(struct vmw_private *dev_priv)
>   	vmw_kms_lost_device(dev_priv->dev);
>   	ttm_write_lock(&dev_priv->reservation_sem, false);
>   	spin_lock(&dev_priv->svga_lock);
> -	if (man->use_type) {
> -		man->use_type = false;
> +	if (ttm_mm_used(man)) {
> +		ttm_mm_set_use(man, false);
>   		spin_unlock(&dev_priv->svga_lock);
>   		if (ttm_bo_evict_mm(&dev_priv->bdev, TTM_PL_VRAM))
>   			DRM_ERROR("Failed evicting VRAM buffers.\n");
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> index 2b60957f7c4a..aff7767762ed 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
> @@ -135,7 +135,7 @@ int vmw_gmrid_man_init(struct vmw_private *dev_priv, int type)
>   	}
>   
>   	ttm_set_driver_manager(&dev_priv->bdev, type, &gman->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   	return 0;
>   }
>   
> @@ -144,7 +144,7 @@ void vmw_gmrid_man_takedown(struct vmw_private *dev_priv, int type)
>   	struct ttm_mem_type_manager *man = ttm_manager_type(&dev_priv->bdev, type);
>   	struct vmwgfx_gmrid_man *gman = to_gmrid_manager(man);
>   
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>   
>   	ttm_bo_force_list_clean(&dev_priv->bdev, man);
>   
> diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> index d5a3eb709384..5a7b9b09785c 100644
> --- a/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_thp.c
> @@ -142,7 +142,7 @@ int vmw_thp_init(struct vmw_private *dev_priv)
>   	spin_lock_init(&rman->lock);
>   
>   	ttm_set_driver_manager(&dev_priv->bdev, TTM_PL_VRAM, &rman->manager);
> -	ttm_bo_use_mm(man);
> +	ttm_mm_set_use(man, true);
>   	return 0;
>   }
>   
> @@ -153,7 +153,7 @@ void vmw_thp_takedown(struct vmw_private *dev_priv)
>   	struct drm_mm *mm = &rman->mm;
>   	int ret;
>   
> -	ttm_bo_disable_mm(man);
> +	ttm_mm_set_use(man, false);
>   
>   	ret = ttm_bo_force_list_clean(&dev_priv->bdev, man);
>   	if (ret)
> diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> index 702b3b056eda..6210acd5c651 100644
> --- a/include/drm/ttm/ttm_bo_driver.h
> +++ b/include/drm/ttm/ttm_bo_driver.h
> @@ -668,14 +668,14 @@ static inline void ttm_bo_unreserve(struct ttm_buffer_object *bo)
>   	dma_resv_unlock(bo->base.resv);
>   }
>   
> -static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> +static inline void ttm_mm_set_use(struct ttm_mem_type_manager *man, bool use)
>   {
> -	man->use_type = true;
> +	man->use_type = use;
>   }
>   
> -static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
> +static inline bool ttm_mm_used(struct ttm_mem_type_manager *man)
>   {
> -	man->use_type = false;
> +	return man->use_type;
>   }
>   
>   static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)

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

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

* Re: [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev.
  2020-07-31 13:23   ` Christian König
@ 2020-07-31 21:06     ` Dave Airlie
  0 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-07-31 21:06 UTC (permalink / raw)
  To: Christian König
  Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

On Fri, 31 Jul 2020 at 23:23, Christian König <christian.koenig@amd.com> wrote:
>
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > This will allow different abstractions later.
>
> Mhm, I'm questioning if this is really worth it and not just overkill.
>
> Running "sed -i 's/&bdev->man/bdev->man/'" on all drivers when we make
> the switch to a pointer should do it as well.
>

It's a good place to hook debugging in if you get something rogue
accessing unregistered bdev->man ptrs as well.

I'd rather not sed the interface later, it's nice to transition things
cleanly between states.

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

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

* Re: [PATCH 00/49] ttm mem manager refactoring.
  2020-07-31  9:17 ` [PATCH 00/49] ttm mem manager refactoring Christian König
  2020-07-31  9:29   ` daniel
@ 2020-08-03  7:12   ` Dave Airlie
  2020-08-03 11:13     ` Christian König
  1 sibling, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-08-03  7:12 UTC (permalink / raw)
  To: Christian König
  Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

On Fri, 31 Jul 2020 at 19:17, Christian König <christian.koenig@amd.com> wrote:
>
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > I started pulling on a thread, and it led me down a hole.
>
> We might want to make that hole even bigger :)
>
> How about we rename the ttm_mem_reg into ttm_resource and
> ttm_mem_type_manager into ttm_resource_manager.
>

https://cgit.freedesktop.org/~airlied/linux/log/?h=ttm-refactor-mem-manager-rename

has the series with some stuff moved around but 3 added rename patches
at the end.

ttm_bo_manager -> ttm_range_manager
ttm_mem_type_manager -> ttm_resource_manager
ttm_mem_reg -> ttm_resource.

The one slightly messy one is we have a lot of ttm_mem_reg *mem
(*old_mem or *new_mem).
 I didn't try and rename those, but I could probably do it if we
decided it was really necessary.

I've got to go back and fold in some review comments from people yet
and add r-bs I'll try and get to that tomorrow.

Dave.

> Neither amdgpu's OA/GWS resources nor the IDs in VMGFX are really memory.
>
> In the long term I also want to move the whole address handling into
> each backend.
>
> Going to send comments on the individual patches as well.
>
> > This series refactors the ttm ttm_mem_type_manager object into
> > a driver owned, allocated, subclassaed object.
> >
> > It starts with two minor fixes for some bad assumptions in two drivers.
> >
> > Enables a new init path, ports all the drivers to the new init
> > path, and cleans up the old init path.
> > Enables a new takedown path, ports all the drivers to the new takedown
> > path, and cleans up the old takedown path
> > Wraps all access to the memory managers in the bo_device in a wrapper
> > across all drivers.
> > Make debug callback optional
> > Enables driver to provide their own mem manager objects
> > Subclasses the objects in all drivers and makes them into driver owned object
> > Drops the bo_device arrays of pointers, and some unneeded links and
> > struct members
> > Cleans up one api.
> >
> > I think I'd probably want to merge all this via drm-misc, so if I can collect
> > acks/r-b from driver maintainers that would be good.
> >
> > This is also based on Chrisitan's work to remove init_mem_type, so it won't
> > apply until he's finished getting all of that into drm-misc.
>
> Preparing to push that to drm-misc-next just now.
>
> Regards,
> Christian.
>
> >
> > https://nam11.safelinks.protection.outlook.com/?url=https:%2F%2Fcgit.freedesktop.org%2F~airlied%2Flinux%2Flog%2F%3Fh%3Dttm-refactor-mem-manager&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Caa32512acf9f4bf455ef08d83506f9d2%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637317651361302583&amp;sdata=2sQt4A48ODl0Nq4P21YG3vRNdhkDZcZp0XHkQ930SAI%3D&amp;reserved=0
> > is the tree I've built this on top off, so it's probably going to get rebased
> > but the code should stay mostly the same.
> >
> > I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
> > amdgpu soon.
> >
> > Dave.
> >
> >
>
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

* Re: [PATCH 00/49] ttm mem manager refactoring.
  2020-08-03  7:12   ` Dave Airlie
@ 2020-08-03 11:13     ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-08-03 11:13 UTC (permalink / raw)
  To: Dave Airlie; +Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

Am 03.08.20 um 09:12 schrieb Dave Airlie:
> On Fri, 31 Jul 2020 at 19:17, Christian König <christian.koenig@amd.com> wrote:
>> Am 31.07.20 um 06:04 schrieb Dave Airlie:
>>> I started pulling on a thread, and it led me down a hole.
>> We might want to make that hole even bigger :)
>>
>> How about we rename the ttm_mem_reg into ttm_resource and
>> ttm_mem_type_manager into ttm_resource_manager.
>>
> https://nam11.safelinks.protection.outlook.com/?url=https:%2F%2Fcgit.freedesktop.org%2F~airlied%2Flinux%2Flog%2F%3Fh%3Dttm-refactor-mem-manager-rename&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Cc1498ce352be4c56b30908d8377cae61%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637320355926010223&amp;sdata=qXhKP8gmv6QsJiS%2BPprtM%2BVn8uE1XAFbZC0DI00zol8%3D&amp;reserved=0
>
> has the series with some stuff moved around but 3 added rename patches
> at the end.
>
> ttm_bo_manager -> ttm_range_manager
> ttm_mem_type_manager -> ttm_resource_manager
> ttm_mem_reg -> ttm_resource.
>
> The one slightly messy one is we have a lot of ttm_mem_reg *mem
> (*old_mem or *new_mem).
>   I didn't try and rename those, but I could probably do it if we
> decided it was really necessary.

I really want to reduce the usage of those in the long term from the 
driver anyway.

> I've got to go back and fold in some review comments from people yet
> and add r-bs I'll try and get to that tomorrow.

Feel free to add my Acked-by to the ones where I haven't given an 
explicit rb so for.

Going to prepare more cleanups on top of this series.

Christian.

>
> Dave.
>
>> Neither amdgpu's OA/GWS resources nor the IDs in VMGFX are really memory.
>>
>> In the long term I also want to move the whole address handling into
>> each backend.
>>
>> Going to send comments on the individual patches as well.
>>
>>> This series refactors the ttm ttm_mem_type_manager object into
>>> a driver owned, allocated, subclassaed object.
>>>
>>> It starts with two minor fixes for some bad assumptions in two drivers.
>>>
>>> Enables a new init path, ports all the drivers to the new init
>>> path, and cleans up the old init path.
>>> Enables a new takedown path, ports all the drivers to the new takedown
>>> path, and cleans up the old takedown path
>>> Wraps all access to the memory managers in the bo_device in a wrapper
>>> across all drivers.
>>> Make debug callback optional
>>> Enables driver to provide their own mem manager objects
>>> Subclasses the objects in all drivers and makes them into driver owned object
>>> Drops the bo_device arrays of pointers, and some unneeded links and
>>> struct members
>>> Cleans up one api.
>>>
>>> I think I'd probably want to merge all this via drm-misc, so if I can collect
>>> acks/r-b from driver maintainers that would be good.
>>>
>>> This is also based on Chrisitan's work to remove init_mem_type, so it won't
>>> apply until he's finished getting all of that into drm-misc.
>> Preparing to push that to drm-misc-next just now.
>>
>> Regards,
>> Christian.
>>
>>> https://nam11.safelinks.protection.outlook.com/?url=https:%2F%2Fcgit.freedesktop.org%2F~airlied%2Flinux%2Flog%2F%3Fh%3Dttm-refactor-mem-manager&amp;data=02%7C01%7Cchristian.koenig%40amd.com%7Cc1498ce352be4c56b30908d8377cae61%7C3dd8961fe4884e608e11a82d994e183d%7C0%7C0%7C637320355926010223&amp;sdata=zrVYgyObEI8auSZ4AS7dDO%2BJ6WHYMITmuDQ%2F0lCxt1I%3D&amp;reserved=0
>>> is the tree I've built this on top off, so it's probably going to get rebased
>>> but the code should stay mostly the same.
>>>
>>> I've done some boot testing on nouveau, and I hope to test it on vmwgfx and
>>> amdgpu soon.
>>>
>>> Dave.
>>>
>>>

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

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

* Re: [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args
  2020-07-31 13:32   ` Christian König
@ 2020-08-04  1:42     ` Dave Airlie
  2020-08-04 10:26       ` Christian König
  0 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-08-04  1:42 UTC (permalink / raw)
  To: Christian König
  Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

On Fri, 31 Jul 2020 at 23:32, Christian König <christian.koenig@amd.com> wrote:
>
> Am 31.07.20 um 06:05 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > This makes it easier to move these to a driver allocated system
>
> No, sorry that looks like going into the wrong direction to me.
>
> I already wanted to suggest to get rid of the size argument instead.

I'm not sure how it should look then, I don't want the driver poking
around inside the range manager code, the range manager should be a
generic object that driver inits and leaves alone,

I definitely don't want the driver to be poking caching and size
values into the man objects for it, since it isn't a driver object.

Do you have some other view on how the generic range manager should work?

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

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

* Re: [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths.
  2020-07-31 13:07   ` Christian König
@ 2020-08-04  2:28     ` Dave Airlie
  0 siblings, 0 replies; 99+ messages in thread
From: Dave Airlie @ 2020-08-04  2:28 UTC (permalink / raw)
  To: Christian König
  Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

On Fri, 31 Jul 2020 at 23:07, Christian König <christian.koenig@amd.com> wrote:
>
> Am 31.07.20 um 06:04 schrieb Dave Airlie:
> > From: Dave Airlie <airlied@redhat.com>
> >
> > Signed-off-by: Dave Airlie <airlied@redhat.com>
> > ---
> >   drivers/gpu/drm/ttm/ttm_bo.c    |  6 ++----
> >   include/drm/ttm/ttm_bo_driver.h | 12 ++++++++++++
> >   2 files changed, 14 insertions(+), 4 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c
> > index 84e399395e4f..f584e5e94383 100644
> > --- a/drivers/gpu/drm/ttm/ttm_bo.c
> > +++ b/drivers/gpu/drm/ttm/ttm_bo.c
> > @@ -1462,8 +1462,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> >               return ret;
> >       }
> >
> > -     man->use_type = false;
> > -     man->has_type = false;
> > +     ttm_bo_disable_mm(man);
> >
> >       ret = 0;
> >       if (mem_type > 0) {
> > @@ -1476,8 +1475,7 @@ int ttm_bo_clean_mm(struct ttm_bo_device *bdev, unsigned mem_type)
> >               ret = (*man->func->takedown)(man);
> >       }
> >
> > -     dma_fence_put(man->move);
> > -     man->move = NULL;
> > +     ttm_bo_man_cleanup(man);
> >
> >       return ret;
> >   }
> > diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h
> > index d0f1a6cdfba7..92bb54cce633 100644
> > --- a/include/drm/ttm/ttm_bo_driver.h
> > +++ b/include/drm/ttm/ttm_bo_driver.h
> > @@ -671,6 +671,18 @@ static inline void ttm_bo_use_mm(struct ttm_mem_type_manager *man)
> >       man->use_type = true;
> >   }
> >
> > +static inline void ttm_bo_disable_mm(struct ttm_mem_type_manager *man)
> > +{
> > +     man->has_type = false;
> > +     man->use_type = false;
> > +}
> > +
> > +static inline void ttm_bo_man_cleanup(struct ttm_mem_type_manager *man)
> > +{
> > +     dma_fence_put(man->move);
> > +     man->move = NULL;
> > +}
> > +
>
> What's the value in making those inline? This is not performance
> critical at all.
>

Not for performance, but they were too trivial to bother putting in
real functions, if there was more going on I'd probably have put them
into functions, but setting two bits, and putting a fence didn't seem
worth adding function call overhead where there was none before.

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

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

* Re: [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args
  2020-08-04  1:42     ` Dave Airlie
@ 2020-08-04 10:26       ` Christian König
  2020-08-06  3:46         ` Dave Airlie
  0 siblings, 1 reply; 99+ messages in thread
From: Christian König @ 2020-08-04 10:26 UTC (permalink / raw)
  To: Dave Airlie; +Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

Am 04.08.20 um 03:42 schrieb Dave Airlie:
> On Fri, 31 Jul 2020 at 23:32, Christian König <christian.koenig@amd.com> wrote:
>> Am 31.07.20 um 06:05 schrieb Dave Airlie:
>>> From: Dave Airlie <airlied@redhat.com>
>>>
>>> This makes it easier to move these to a driver allocated system
>> No, sorry that looks like going into the wrong direction to me.
>>
>> I already wanted to suggest to get rid of the size argument instead.
> I'm not sure how it should look then, I don't want the driver poking
> around inside the range manager code, the range manager should be a
> generic object that driver inits and leaves alone,
>
> I definitely don't want the driver to be poking caching and size
> values into the man objects for it, since it isn't a driver object.
>
> Do you have some other view on how the generic range manager should work?

That was not what I was talking about. Take a look at what those fields 
are used for :)


As far as I see the only usage of the size is in 
ttm_resource_manager_debug(). But this size is actually totally opaque 
to TTM, it could be pages, bytes, fried chicken wings or whatever. In 
other words it would be much better to print it in the debug callback of 
each resource manager.


The available_caching is completely superfluous as well. The original 
idea what that a driver could specify multiple placements as flags in 
one entry, but no driver ever used that as far as I know and it became 
completely deprecated in 2014 when I moved the lpfn and fpfn into each 
place.


The default_caching is used in ttm_bo_select_caching(), but this is 
complete utterly nonsense. It just results in multiple possible cache 
behaviors being selected, which are then fortunately ignored by 
ttm_tt_set_placement_caching :)


To be honest I think just removing those parameters and the associated 
caching flags all together is the next logical step.

Regards,
Christian.

>
> Dave.

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

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

* Re: [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args
  2020-08-04 10:26       ` Christian König
@ 2020-08-06  3:46         ` Dave Airlie
  2020-08-06  8:24           ` Christian König
  0 siblings, 1 reply; 99+ messages in thread
From: Dave Airlie @ 2020-08-06  3:46 UTC (permalink / raw)
  To: Christian König
  Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

> That was not what I was talking about. Take a look at what those fields
> are used for :)
>
>
> As far as I see the only usage of the size is in
> ttm_resource_manager_debug(). But this size is actually totally opaque
> to TTM, it could be pages, bytes, fried chicken wings or whatever. In
> other words it would be much better to print it in the debug callback of
> each resource manager.

Size is a bit trickier as the drivers use in a couple of funky places, radeon
pokes inside the range manager and adjust its size post init, and amdgpu
uses size to validate a bunch of bo sizing. These shouldn't be too messy to
workaround.

> The available_caching is completely superfluous as well. The original
> idea what that a driver could specify multiple placements as flags in
> one entry, but no driver ever used that as far as I know and it became
> completely deprecated in 2014 when I moved the lpfn and fpfn into each
> place.
>
>
> The default_caching is used in ttm_bo_select_caching(), but this is
> complete utterly nonsense. It just results in multiple possible cache
> behaviors being selected, which are then fortunately ignored by
> ttm_tt_set_placement_caching :)
>
>
> To be honest I think just removing those parameters and the associated
> caching flags all together is the next logical step.

Definitely something to burn down alright.

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

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

* Re: [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args
  2020-08-06  3:46         ` Dave Airlie
@ 2020-08-06  8:24           ` Christian König
  0 siblings, 0 replies; 99+ messages in thread
From: Christian König @ 2020-08-06  8:24 UTC (permalink / raw)
  To: Dave Airlie; +Cc: Roland Scheidegger, Ben Skeggs, dri-devel, Gerd Hoffmann

Am 06.08.20 um 05:46 schrieb Dave Airlie:
>> That was not what I was talking about. Take a look at what those fields
>> are used for :)
>>
>>
>> As far as I see the only usage of the size is in
>> ttm_resource_manager_debug(). But this size is actually totally opaque
>> to TTM, it could be pages, bytes, fried chicken wings or whatever. In
>> other words it would be much better to print it in the debug callback of
>> each resource manager.
> Size is a bit trickier as the drivers use in a couple of funky places, radeon
> pokes inside the range manager and adjust its size post init, and amdgpu
> uses size to validate a bunch of bo sizing. These shouldn't be too messy to
> workaround.

Yeah, I already wanted o clean that up in radeon for years now :)

Amdgpu should be easy to fix, most likely we just don't store the gtt 
size anywhere else.

But yes, those are TTM internals which drivers should not touch.

>> The available_caching is completely superfluous as well. The original
>> idea what that a driver could specify multiple placements as flags in
>> one entry, but no driver ever used that as far as I know and it became
>> completely deprecated in 2014 when I moved the lpfn and fpfn into each
>> place.
>>
>>
>> The default_caching is used in ttm_bo_select_caching(), but this is
>> complete utterly nonsense. It just results in multiple possible cache
>> behaviors being selected, which are then fortunately ignored by
>> ttm_tt_set_placement_caching :)
>>
>>
>> To be honest I think just removing those parameters and the associated
>> caching flags all together is the next logical step.
> Definitely something to burn down alright.

IIRC we have a bit of dead AGP code in radeon which still tries to use this.

Nouveau might have something as well, going to take a look now.

But in general I think that drivers should just say I want caching X for 
this BO instead of TTM making an educated guess based on some flags set 
in different places.

Christian.

>
> Dave.

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

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

end of thread, other threads:[~2020-08-06 12:00 UTC | newest]

Thread overview: 99+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-07-31  4:04 [PATCH 00/49] ttm mem manager refactoring Dave Airlie
2020-07-31  4:04 ` [PATCH 01/49] drm/qxl/ttm: call ttm manager debug Dave Airlie
2020-07-31  4:04 ` [PATCH 02/49] drm/vram-helper: call the ttm manager debug function Dave Airlie
2020-07-31  6:43   ` Thomas Zimmermann
2020-07-31  4:04 ` [PATCH 03/49] drm/ttm: split the mm manager init code Dave Airlie
2020-07-31  5:44   ` Sam Ravnborg
2020-07-31  5:51     ` Dave Airlie
2020-07-31  6:26       ` Dave Airlie
2020-07-31  6:43         ` Sam Ravnborg
2020-07-31  9:12   ` Christian König
2020-07-31  4:04 ` [PATCH 04/49] drm/ttm: provide a driver-led init path for generic mm manager Dave Airlie
2020-07-31  6:57   ` Thomas Zimmermann
2020-07-31  7:03     ` Thomas Zimmermann
2020-07-31  7:20     ` Dave Airlie
2020-07-31 13:00   ` Christian König
2020-07-31  4:04 ` [PATCH 05/49] drm/amdgpu/ttm: init managers from the driver side Dave Airlie
2020-07-31  4:04 ` [PATCH 06/49] drm/radeon: use new ttm man init path Dave Airlie
2020-07-31  4:04 ` [PATCH 07/49] drm/qxl/ttm: use new init path for manager Dave Airlie
2020-07-31  4:04 ` [PATCH 08/49] drm/vram_helper: use new ttm manager init function Dave Airlie
2020-07-31  4:04 ` [PATCH 09/49] drm/nouveau: use new memory manager init paths Dave Airlie
2020-07-31  4:04 ` [PATCH 10/49] drm/vmwgfx/ttm: convert vram mm init to new code paths Dave Airlie
2020-07-31  4:04 ` [PATCH 11/49] drm/vmwgfx/ttm: switch gmrid allocator to new init paths Dave Airlie
2020-07-31  4:04 ` [PATCH 12/49] drm/ttm: convert system manager init to new code Dave Airlie
2020-07-31 12:57   ` Christian König
2020-07-31  4:04 ` [PATCH 13/49] drm/ttm: purge old manager init path Dave Airlie
2020-07-31 12:58   ` Christian König
2020-07-31  4:04 ` [PATCH 14/49] drm/ttm: pass man around instead of mem_type in some places Dave Airlie
2020-07-31 13:04   ` Christian König
2020-07-31  4:04 ` [PATCH 15/49] drm/ttm: make some inline helper functions for cleanup paths Dave Airlie
2020-07-31 13:07   ` Christian König
2020-08-04  2:28     ` Dave Airlie
2020-07-31  4:04 ` [PATCH 16/49] drm/ttm: start allowing drivers to use new takedown path Dave Airlie
2020-07-31 13:09   ` Christian König
2020-07-31  4:04 ` [PATCH 17/49] drm/amdgpu/ttm: " Dave Airlie
2020-07-31 13:08   ` Christian König
2020-07-31  4:04 ` [PATCH 18/49] drm/vmwgfx: takedown vram manager Dave Airlie
2020-07-31  4:04 ` [PATCH 19/49] drm/vram_helper: call explicit mm takedown Dave Airlie
2020-07-31  4:04 ` [PATCH 20/49] drm/nouveau: use new cleanup paths Dave Airlie
2020-07-31  4:04 ` [PATCH 21/49] drm/radeon/ttm: use new takedown paths Dave Airlie
2020-07-31 13:10   ` Christian König
2020-07-31  4:04 ` [PATCH 22/49] drm/qxl/ttm: use new takedown path Dave Airlie
2020-07-31  4:04 ` [PATCH 23/49] drm/vmwgfx: fix gmrid takedown paths to new interface Dave Airlie
2020-07-31  4:04 ` [PATCH 24/49] drm/ttm: remove range manager legacy takedown path Dave Airlie
2020-07-31 13:11   ` Christian König
2020-07-31  4:04 ` [PATCH 25/49] drm/ttm: make TTM responsible for cleaning system only Dave Airlie
2020-07-31 13:19   ` Christian König
2020-07-31  4:04 ` [PATCH 26/49] drm/ttm: add wrapper to get manager from bdev Dave Airlie
2020-07-31  7:14   ` Thomas Zimmermann
2020-07-31  7:21     ` Dave Airlie
2020-07-31 13:18       ` daniel
2020-07-31 13:23   ` Christian König
2020-07-31 21:06     ` Dave Airlie
2020-07-31  4:04 ` [PATCH 27/49] drm/amdgfx/ttm: use wrapper to get ttm memory managers Dave Airlie
2020-07-31  4:04 ` [PATCH 28/49] drm/vram-helper: use wrapper to access " Dave Airlie
2020-07-31  4:05 ` [PATCH 29/49] drm/nouveau/ttm: " Dave Airlie
2020-07-31  4:05 ` [PATCH 30/49] drm/qxl/ttm: use wrapper to access memory manager Dave Airlie
2020-07-31  4:05 ` [PATCH 31/49] drm/radeon/ttm: " Dave Airlie
2020-07-31  4:05 ` [PATCH 32/49] drm/vmwgfx/ttm: " Dave Airlie
2020-07-31  4:05 ` [PATCH 33/49] drm/ttm: rename manager variable to make sure wrapper is used Dave Airlie
2020-07-31  4:05 ` [PATCH 34/49] drm/ttm: make manager debug function optional Dave Airlie
2020-07-31  9:46   ` daniel
2020-07-31 13:03     ` Christian König
2020-07-31 13:24   ` Christian König
2020-07-31  4:05 ` [PATCH 35/49] drm/nouveau/ttm: don't fill in blank ttm debug callback Dave Airlie
2020-07-31 13:25   ` Christian König
2020-07-31  4:05 ` [PATCH 36/49] drm/vmwgfx/gmrid: don't provide pointless " Dave Airlie
2020-07-31 13:26   ` Christian König
2020-07-31  4:05 ` [PATCH 37/49] drm/ttm: allow drivers to provide their own manager subclasses Dave Airlie
2020-07-31  4:05 ` [PATCH 38/49] drm/amdgpu/ttm: use bo manager subclassing for vram/gtt mgrs Dave Airlie
2020-07-31 13:29   ` Christian König
2020-07-31  4:05 ` [PATCH 39/49] drm/ttm: make ttm_bo_man_init/takedown take type + args Dave Airlie
2020-07-31 13:32   ` Christian König
2020-08-04  1:42     ` Dave Airlie
2020-08-04 10:26       ` Christian König
2020-08-06  3:46         ` Dave Airlie
2020-08-06  8:24           ` Christian König
2020-07-31  4:05 ` [PATCH 40/49] drm/ttm: move range manager to subclassed driver allocation Dave Airlie
2020-07-31 13:33   ` Christian König
2020-07-31  4:05 ` [PATCH 41/49] drm/vmwgfx/ttm: move thp to driver managed Dave Airlie
2020-07-31  4:05 ` [PATCH 42/49] drm/vmwgfx/gmrid: convert to driver controlled allocation Dave Airlie
2020-07-31  4:05 ` [PATCH 43/49] drm/nouveau/ttm: move to driver allocated manager Dave Airlie
2020-07-31  4:05 ` [PATCH 44/49] drm/ttm: drop priv pointer in memory manager Dave Airlie
2020-07-31 13:33   ` Christian König
2020-07-31  4:05 ` [PATCH 45/49] drm/amdgpu/ttm: remove man->bdev references Dave Airlie
2020-07-31 14:55   ` Christian König
2020-07-31  4:05 ` [PATCH 46/49] drm/ttm: drop man->bdev link Dave Airlie
2020-07-31 14:54   ` Christian König
2020-07-31  4:05 ` [PATCH 47/49] drm/ttm: drop list of memory managers from device Dave Airlie
2020-07-31  9:55   ` daniel
2020-07-31 14:57   ` Christian König
2020-07-31  4:05 ` [PATCH 48/49] drm/ttm: drop type manager has_type Dave Airlie
2020-07-31  4:05 ` [PATCH 49/49] drm/ttm: consolidate manager used apis into a set and get Dave Airlie
2020-07-31  9:51   ` daniel
2020-07-31 14:59   ` Christian König
2020-07-31  9:17 ` [PATCH 00/49] ttm mem manager refactoring Christian König
2020-07-31  9:29   ` daniel
2020-07-31 13:01     ` Christian König
2020-08-03  7:12   ` Dave Airlie
2020-08-03 11:13     ` 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).