[i-g-t v2 20/27] lib/intel_batchbuffer: Add support for VM bind mode

Bhanuprakash Modem bhanuprakash.modem at intel.com
Tue Jan 24 07:35:04 UTC 2023


Add support to create a bb with context passed in @ctx and @cfg configuration
(when working with custom engines layout) to work in vm_bind mode.

Credits-to: Niranjana Vishwanathapura <niranjana.vishwanathapura at intel.com>
Signed-off-by: Bhanuprakash Modem <bhanuprakash.modem at intel.com>
---
 lib/intel_batchbuffer.c | 61 ++++++++++++++++++++++++++++++++---------
 lib/intel_batchbuffer.h |  3 ++
 2 files changed, 51 insertions(+), 13 deletions(-)

diff --git a/lib/intel_batchbuffer.c b/lib/intel_batchbuffer.c
index 59c788e6..8311b69e 100644
--- a/lib/intel_batchbuffer.c
+++ b/lib/intel_batchbuffer.c
@@ -36,6 +36,8 @@
 #include "drm.h"
 #include "drmtest.h"
 #include "i915/gem_create.h"
+#include "i915/gem_vm.h"
+#include "i915/i915_vm_bind.h"
 #include "intel_batchbuffer.h"
 #include "intel_bufops.h"
 #include "intel_chipset.h"
@@ -804,7 +806,7 @@ static inline uint64_t __intel_bb_get_offset(struct intel_bb *ibb,
  */
 static struct intel_bb *
 __intel_bb_create(int i915, uint32_t ctx, const intel_ctx_cfg_t *cfg,
-		  uint32_t size, bool do_relocs,
+		  uint32_t size, bool do_relocs, bool vm_bind_mode,
 		  uint64_t start, uint64_t end,
 		  uint8_t allocator_type, enum allocator_strategy strategy)
 {
@@ -825,6 +827,11 @@ __intel_bb_create(int i915, uint32_t ctx, const intel_ctx_cfg_t *cfg,
 	if (!ibb->uses_full_ppgtt)
 		do_relocs = true;
 
+	if (vm_bind_mode) {
+		igt_assert(i915_vm_bind_version(i915) == 1);
+		igt_assert(!do_relocs);
+	}
+
 	/*
 	 * For softpin mode allocator has full control over offsets allocation
 	 * so we want kernel to not interfere with this.
@@ -854,7 +861,7 @@ __intel_bb_create(int i915, uint32_t ctx, const intel_ctx_cfg_t *cfg,
 	ibb->size = size;
 	ibb->alignment = gem_detect_safe_alignment(i915);
 	ibb->ctx = ctx;
-	ibb->vm_id = 0;
+	ibb->vm_id = vm_bind_mode ? gem_context_get_vm(i915, ctx) : 0;
 	ibb->batch = calloc(1, size);
 	igt_assert(ibb->batch);
 	ibb->ptr = ibb->batch;
@@ -916,7 +923,7 @@ struct intel_bb *intel_bb_create_full(int i915, uint32_t ctx,
 				      uint8_t allocator_type,
 				      enum allocator_strategy strategy)
 {
-	return __intel_bb_create(i915, ctx, cfg, size, false, start, end,
+	return __intel_bb_create(i915, ctx, cfg, size, false, false, start, end,
 				 allocator_type, strategy);
 }
 
@@ -941,7 +948,7 @@ struct intel_bb *intel_bb_create_with_allocator(int i915, uint32_t ctx,
 						uint32_t size,
 						uint8_t allocator_type)
 {
-	return __intel_bb_create(i915, ctx, cfg, size, false, 0, 0,
+	return __intel_bb_create(i915, ctx, cfg, size, false, false, 0, 0,
 				 allocator_type, ALLOC_STRATEGY_HIGH_TO_LOW);
 }
 
@@ -980,8 +987,8 @@ struct intel_bb *intel_bb_create(int i915, uint32_t size)
 	bool relocs = gem_has_relocations(i915);
 
 	return __intel_bb_create(i915, 0, NULL, size,
-				 relocs && !aux_needs_softpin(i915), 0, 0,
-				 INTEL_ALLOCATOR_SIMPLE,
+				 relocs && !aux_needs_softpin(i915),
+				 false, 0, 0, INTEL_ALLOCATOR_SIMPLE,
 				 ALLOC_STRATEGY_HIGH_TO_LOW);
 }
 
@@ -1006,8 +1013,31 @@ intel_bb_create_with_context(int i915, uint32_t ctx,
 	bool relocs = gem_has_relocations(i915);
 
 	return __intel_bb_create(i915, ctx, cfg, size,
-				 relocs && !aux_needs_softpin(i915), 0, 0,
-				 INTEL_ALLOCATOR_SIMPLE,
+				 relocs && !aux_needs_softpin(i915),
+				 false, 0, 0, INTEL_ALLOCATOR_SIMPLE,
+				 ALLOC_STRATEGY_HIGH_TO_LOW);
+}
+
+/**
+ * intel_bb_create_for_vm_bind_mode:
+ * @i915: drm fd
+ * @ctx: context id
+ * @cfg: intel_ctx configuration, NULL for default context or legacy mode
+ * @size: size of the batchbuffer
+ *
+ * Creates bb with context passed in @ctx and @cfg configuration (when
+ * working with custom engines layout) to work in vm_bind mode.
+ *
+ * Returns:
+ *
+ * Pointer the intel_bb, asserts on failure.
+ */
+struct intel_bb *
+intel_bb_create_for_vm_bind_mode(int i915, uint32_t ctx,
+				 const intel_ctx_cfg_t *cfg, uint32_t size)
+{
+	return __intel_bb_create(i915, ctx, cfg, size, false, true,
+				 0, 0, INTEL_ALLOCATOR_SIMPLE,
 				 ALLOC_STRATEGY_HIGH_TO_LOW);
 }
 
@@ -1027,7 +1057,7 @@ struct intel_bb *intel_bb_create_with_relocs(int i915, uint32_t size)
 {
 	igt_require(gem_has_relocations(i915));
 
-	return __intel_bb_create(i915, 0, NULL, size, true, 0, 0,
+	return __intel_bb_create(i915, 0, NULL, size, true, false, 0, 0,
 				 INTEL_ALLOCATOR_NONE, ALLOC_STRATEGY_NONE);
 }
 
@@ -1052,7 +1082,7 @@ intel_bb_create_with_relocs_and_context(int i915, uint32_t ctx,
 {
 	igt_require(gem_has_relocations(i915));
 
-	return __intel_bb_create(i915, ctx, cfg, size, true, 0, 0,
+	return __intel_bb_create(i915, ctx, cfg, size, true, false, 0, 0,
 				 INTEL_ALLOCATOR_NONE, ALLOC_STRATEGY_NONE);
 }
 
@@ -1072,8 +1102,8 @@ struct intel_bb *intel_bb_create_no_relocs(int i915, uint32_t size)
 {
 	igt_require(gem_uses_full_ppgtt(i915));
 
-	return __intel_bb_create(i915, 0, NULL, size, false, 0, 0,
-				 INTEL_ALLOCATOR_SIMPLE,
+	return __intel_bb_create(i915, 0, NULL, size, false, false,
+				 0, 0, INTEL_ALLOCATOR_SIMPLE,
 				 ALLOC_STRATEGY_HIGH_TO_LOW);
 }
 
@@ -1152,6 +1182,9 @@ void intel_bb_destroy(struct intel_bb *ibb)
 	if (ibb->fence >= 0)
 		close(ibb->fence);
 
+	if (ibb->vm_id)
+		gem_vm_destroy(ibb->i915, ibb->vm_id);
+
 	free(ibb->batch);
 	free(ibb->cfg);
 	free(ibb);
@@ -1501,6 +1534,8 @@ intel_bb_add_object(struct intel_bb *ibb, uint32_t handle, uint64_t size,
 	}
 
 	object->offset = offset;
+	if (ibb->vm_id)
+		object->rsvd2 = size;
 
 	if (write)
 		object->flags |= EXEC_OBJECT_WRITE;
@@ -1568,7 +1603,7 @@ __intel_bb_add_intel_buf(struct intel_bb *ibb, struct intel_buf *buf,
 		}
 	}
 
-	obj = intel_bb_add_object(ibb, buf->handle, intel_buf_bo_size(buf),
+	obj = intel_bb_add_object(ibb, buf->handle, ALIGN(intel_buf_bo_size(buf), 0x1000),
 				  buf->addr.offset, alignment, write);
 	buf->addr.offset = obj->offset;
 
diff --git a/lib/intel_batchbuffer.h b/lib/intel_batchbuffer.h
index 37db0ffa..59eda50a 100644
--- a/lib/intel_batchbuffer.h
+++ b/lib/intel_batchbuffer.h
@@ -281,6 +281,9 @@ struct intel_bb *intel_bb_create(int i915, uint32_t size);
 struct intel_bb *
 intel_bb_create_with_context(int i915, uint32_t ctx, const intel_ctx_cfg_t *cfg,
 			     uint32_t size);
+struct intel_bb *
+intel_bb_create_for_vm_bind_mode(int i915, uint32_t ctx,
+			     const intel_ctx_cfg_t *cfg, uint32_t size);
 struct intel_bb *intel_bb_create_with_relocs(int i915, uint32_t size);
 struct intel_bb *
 intel_bb_create_with_relocs_and_context(int i915, uint32_t ctx,
-- 
2.39.0



More information about the Intel-gfx-trybot mailing list