[PATCH 03/49] drm/ttm: split the mm manager init code

Dave Airlie airlied at gmail.com
Fri Jul 31 04:04:34 UTC 2020


From: Dave Airlie <airlied at 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 at 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



More information about the dri-devel mailing list