[PATCH 13/17] drm/i915: populate ttm_placement per object

Matthew Auld matthew.auld at intel.com
Wed May 12 11:34:20 UTC 2021


We need to be able set the place.flags per object, in the next patch.

Signed-off-by: Matthew Auld <matthew.auld at intel.com>
---
 .../gpu/drm/i915/gem/i915_gem_object_types.h  |  4 ++
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c       | 37 ++++++++++++++++++-
 2 files changed, 40 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
index b350765e1935..f3efc104cf52 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
+++ b/drivers/gpu/drm/i915/gem/i915_gem_object_types.h
@@ -11,6 +11,7 @@
 
 #include <drm/drm_gem.h>
 #include <drm/ttm/ttm_bo_api.h>
+#include <drm/ttm/ttm_placement.h>
 #include <uapi/drm/i915_drm.h>
 
 #include "i915_active.h"
@@ -262,6 +263,9 @@ struct drm_i915_gem_object {
 		 */
 		void *st_mm_node;
 
+		struct ttm_place ttm_place;
+		struct ttm_placement ttm_placement;
+
 		/**
 		 * Element within memory_region->objects or region->purgeable
 		 * if the object is marked as DONTNEED. Access is protected by
diff --git a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
index eb36256b79f7..aa142677c44b 100644
--- a/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
+++ b/drivers/gpu/drm/i915/gem/i915_gem_ttm.c
@@ -367,6 +367,40 @@ struct ttm_device_funcs i915_ttm_bo_driver = {
 	.delete_mem_notify = i915_ttm_delete_mem_notify,
 };
 
+
+static void i915_gem_object_ttm_placement(struct drm_i915_gem_object *obj)
+{
+	struct ttm_placement *placement = &obj->mm.ttm_placement;
+	struct ttm_place *place = &obj->mm.ttm_place;
+
+	/* TODO: should loop through the mm.placements */
+	if (i915_gem_object_has_struct_page(obj)) {
+		place->fpfn = 0;
+		place->lpfn = 0;
+		place->mem_type = I915_PL_SYSTEM;
+		place->flags = 0;
+	} else if (i915_gem_object_is_stolen(obj)) {
+		place->fpfn = 0;
+		place->lpfn = 0;
+		place->mem_type = I915_PL_STOLEN;
+		place->flags = TTM_PL_FLAG_CONTIGUOUS;
+	} else if (i915_gem_object_is_lmem(obj)) {
+		place->fpfn = 0;
+		place->lpfn = 0;
+		place->mem_type = I915_PL_LMEM0;
+		place->flags = 0;
+		if (obj->flags & I915_BO_ALLOC_CONTIGUOUS)
+			place->flags = TTM_PL_FLAG_CONTIGUOUS;
+	} else {
+		GEM_BUG_ON(1);
+	}
+
+	placement->num_placement = 1;
+	placement->placement = place;
+	placement->num_busy_placement = 1;
+	placement->busy_placement = place;
+}
+
 static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
 {
 	struct ttm_buffer_object *bo = i915_gem_to_ttm(obj);
@@ -385,7 +419,8 @@ static int i915_ttm_get_pages(struct drm_i915_gem_object *obj)
 	}
 
 	/* Move to the requested placement. */
-	ret = ttm_bo_validate(bo, &i915_lmem0_placement, &ctx);
+	i915_gem_object_ttm_placement(obj);
+	ret = ttm_bo_validate(bo, &obj->mm.ttm_placement, &ctx);
 	if (ret)
 		return ret;
 
-- 
2.26.3



More information about the Intel-gfx-trybot mailing list