[PATCH v2 3/4] drm/xe: Add xe_bo_tt_has_data helper

Matthew Brost matthew.brost at intel.com
Mon Jun 23 14:45:47 UTC 2025


Add xe_bo_tt_has_data helper which determines if a BO has TT data (i.e.,
a BO has SRAM or swap backing store).

Signed-off-by: Matthew Brost <matthew.brost at intel.com>
---
 drivers/gpu/drm/xe/xe_bo.c | 21 ++++++++++++++++++---
 drivers/gpu/drm/xe/xe_bo.h |  2 ++
 2 files changed, 20 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_bo.c b/drivers/gpu/drm/xe/xe_bo.c
index c93381fa4858..7a412121477e 100644
--- a/drivers/gpu/drm/xe/xe_bo.c
+++ b/drivers/gpu/drm/xe/xe_bo.c
@@ -766,6 +766,23 @@ static int xe_bo_move_notify(struct xe_bo *bo,
 	return 0;
 }
 
+/**
+ * xe_bo_tt_has_data() - Xe BO has TT data (i.e., Xe BO has SRAM or swap backing
+ * store)
+ *
+ * Helper to determine if a BO has TT data. Useful to determine if copies or
+ * clears are needed on BO when it is moving.
+ *
+ * Return: True if a BO has TT data, False otherwise
+ */
+bool xe_bo_tt_has_data(struct xe_bo *bo)
+{
+	struct ttm_tt *ttm = bo->ttm.ttm;
+
+	return ttm && (ttm_tt_is_populated(ttm) ||
+		       (ttm->page_flags & TTM_TT_FLAG_SWAPPED));
+}
+
 static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
 		      struct ttm_operation_ctx *ctx,
 		      struct ttm_resource *new_mem,
@@ -801,9 +818,7 @@ static int xe_bo_move(struct ttm_buffer_object *ttm_bo, bool evict,
 		return ret;
 	}
 
-	tt_has_data = ttm && (ttm_tt_is_populated(ttm) ||
-			      (ttm->page_flags & TTM_TT_FLAG_SWAPPED));
-
+	tt_has_data = xe_bo_tt_has_data(bo);
 	move_lacks_source = !old_mem || (handle_system_ccs ? (!bo->ccs_cleared) :
 					 (!mem_type_is_vram(old_mem_type) && !tt_has_data));
 
diff --git a/drivers/gpu/drm/xe/xe_bo.h b/drivers/gpu/drm/xe/xe_bo.h
index 02ada1fb8a23..150e98ce6fac 100644
--- a/drivers/gpu/drm/xe/xe_bo.h
+++ b/drivers/gpu/drm/xe/xe_bo.h
@@ -374,6 +374,8 @@ void xe_bo_dev_fini(struct xe_bo_dev *bo_device);
 
 struct sg_table *xe_bo_sg(struct xe_bo *bo);
 
+bool xe_bo_tt_has_data(struct xe_bo *bo);
+
 /*
  * xe_sg_segment_size() - Provides upper limit for sg segment size.
  * @dev: device pointer
-- 
2.34.1



More information about the Intel-xe mailing list