[igt-dev] [PATCH i-g-t v3 13/23] lib/intel_aux_pgtable: Get addresses for aux table from an allocator

Zbigniew Kempczyński zbigniew.kempczynski at intel.com
Fri Oct 23 12:42:02 UTC 2020


Use intel_buf which now allows passing expected alignment required
for aux table and acquire appropriate address from an allocator.

With simple allocator we try to use high offsets from default
to exercise canonizing/decanonizing is working properly.
Alter pgtable to allow proper calculation on such offsets.

Signed-off-by: Zbigniew Kempczyński <zbigniew.kempczynski at intel.com>
Cc: Dominik Grzegorzek <dominik.grzegorzek at intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
---
 lib/intel_aux_pgtable.c | 45 ++++++++++++++++++++++-------------------
 1 file changed, 24 insertions(+), 21 deletions(-)

diff --git a/lib/intel_aux_pgtable.c b/lib/intel_aux_pgtable.c
index ef6a9fef..a970b708 100644
--- a/lib/intel_aux_pgtable.c
+++ b/lib/intel_aux_pgtable.c
@@ -68,7 +68,7 @@ static uint64_t last_buf_surface_end(struct intel_buf *buf)
 	int i;
 
 	for (i = 0; i < num_surfaces; i++) {
-		uint64_t surface_end = buf->surface[i].offset +
+		uint64_t surface_end = DECANONICAL(buf->surface[i].offset) +
 				       buf->surface[i].size;
 
 		if (surface_end > end_offset)
@@ -89,18 +89,20 @@ pgt_table_count(int address_bits, struct intel_buf **bufs, int buf_count)
 	end = 0;
 	for (i = 0; i < buf_count; i++) {
 		struct intel_buf *buf = bufs[i];
-		uint64_t start;
+		uint64_t start, offset;
+
+		offset = DECANONICAL(buf->addr.offset);
 
 		/* We require bufs to be sorted. */
 		igt_assert(i == 0 ||
-			   buf->addr.offset >= bufs[i - 1]->addr.offset +
-					       intel_buf_bo_size(bufs[i - 1]));
+			   offset >= DECANONICAL(bufs[i - 1]->addr.offset) +
+				intel_buf_bo_size(bufs[i - 1]));
+		start = ALIGN_DOWN(offset, 1UL << address_bits);
 
-		start = ALIGN_DOWN(buf->addr.offset, 1UL << address_bits);
 		/* Avoid double counting for overlapping aligned bufs. */
 		start = max(start, end);
 
-		end = ALIGN(buf->addr.offset + last_buf_surface_end(buf),
+		end = ALIGN(offset + last_buf_surface_end(buf),
 			    1UL << address_bits);
 		igt_assert(end >= start);
 
@@ -180,11 +182,11 @@ pgt_get_child_table(struct pgtable *pgt, uint64_t parent_table,
 		uint32_t offset;
 
 		child_table = pgt_alloc_table(pgt, level - 1);
-		igt_assert(!((child_table + pgt->buf->addr.offset) &
+		igt_assert(!((child_table + DECANONICAL(pgt->buf->addr.offset)) &
 			     ~ptr_mask(pgt, level)));
 
 		pte = child_table | flags;
-		*child_entry_ptr = pgt->buf->addr.offset + pte;
+		*child_entry_ptr = DECANONICAL(pgt->buf->addr.offset) + pte;
 
 		igt_assert(pte <= INT32_MAX);
 
@@ -197,7 +199,7 @@ pgt_get_child_table(struct pgtable *pgt, uint64_t parent_table,
 						pgt->buf->addr.offset);
 	} else {
 		child_table = (*child_entry_ptr & ptr_mask(pgt, level)) -
-			      pgt->buf->addr.offset;
+			      DECANONICAL(pgt->buf->addr.offset);
 	}
 
 	return child_table;
@@ -346,11 +348,11 @@ pgt_populate_entries_for_buf(struct pgtable *pgt,
 			     uint64_t top_table,
 			     int surface_idx)
 {
-	uint64_t surface_addr = buf->addr.offset +
+	uint64_t surface_addr = DECANONICAL(buf->addr.offset) +
 				buf->surface[surface_idx].offset;
 	uint64_t surface_end = surface_addr +
 			       buf->surface[surface_idx].size;
-	uint64_t aux_addr = buf->addr.offset + buf->ccs[surface_idx].offset;
+	uint64_t aux_addr = DECANONICAL(buf->addr.offset) + buf->ccs[surface_idx].offset;
 	uint64_t l1_flags = pgt_get_l1_flags(buf, surface_idx);
 	uint64_t lx_flags = pgt_get_lx_flags();
 
@@ -441,7 +443,6 @@ struct intel_buf *
 intel_aux_pgtable_create(struct intel_bb *ibb,
 			 struct intel_buf **bufs, int buf_count)
 {
-	struct drm_i915_gem_exec_object2 *obj;
 	static const struct pgtable_level_desc level_desc[] = {
 		{
 			.idx_shift = 16,
@@ -465,7 +466,6 @@ intel_aux_pgtable_create(struct intel_bb *ibb,
 	struct pgtable *pgt;
 	struct buf_ops *bops;
 	struct intel_buf *buf;
-	uint64_t prev_alignment;
 
 	igt_assert(buf_count);
 	bops = bufs[0]->bops;
@@ -476,11 +476,8 @@ intel_aux_pgtable_create(struct intel_bb *ibb,
 				    I915_COMPRESSION_NONE);
 
 	/* We need to use pgt->max_align for aux table */
-	prev_alignment = intel_bb_set_default_object_alignment(ibb,
-							       pgt->max_align);
-	obj = intel_bb_add_intel_buf(ibb, pgt->buf, false);
-	intel_bb_set_default_object_alignment(ibb, prev_alignment);
-	obj->alignment = pgt->max_align;
+	intel_bb_add_intel_buf_with_alignment(ibb, pgt->buf,
+					      pgt->max_align, false);
 
 	pgt_map(ibb->i915, pgt);
 	pgt_populate_entries(pgt, bufs, buf_count);
@@ -496,11 +493,15 @@ static void
 aux_pgtable_reserve_buf_slot(struct intel_buf **bufs, int buf_count,
 			     struct intel_buf *new_buf)
 {
+	uint64_t curr, newone;
 	int i;
 
-	for (i = 0; i < buf_count; i++)
-		if (bufs[i]->addr.offset > new_buf->addr.offset)
+	for (i = 0; i < buf_count; i++) {
+		curr = DECANONICAL(bufs[i]->addr.offset);
+		newone = DECANONICAL(new_buf->addr.offset);
+		if (curr > newone)
 			break;
+	}
 
 	memmove(&bufs[i + 1], &bufs[i], sizeof(bufs[0]) * (buf_count - i));
 
@@ -591,8 +592,10 @@ gen12_aux_pgtable_cleanup(struct intel_bb *ibb, struct aux_pgtable_info *info)
 		igt_assert_eq_u64(addr, info->buf_pin_offsets[i]);
 	}
 
-	if (info->pgtable_buf)
+	if (info->pgtable_buf) {
+		intel_bb_remove_intel_buf(ibb, info->pgtable_buf);
 		intel_buf_destroy(info->pgtable_buf);
+	}
 }
 
 uint32_t
-- 
2.26.0



More information about the igt-dev mailing list