[PATCH v2 3/6] drm/xe: Prepare workaround batch buffer setup for more users

Tvrtko Ursulin tvrtko.ursulin at igalia.com
Mon Jun 2 11:19:53 UTC 2025


We need to emit some more workarounds from the workaround batch buffer so
lets introduce a new top level function and move the existing context
utilisation workaround to be separate.

Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at igalia.com>
Cc: Lucas De Marchi <lucas.demarchi at intel.com>
Cc: Matt Roper <matthew.d.roper at intel.com>
---
 drivers/gpu/drm/xe/xe_lrc.c | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
index ca7ffc7bbdc8..a627e4503518 100644
--- a/drivers/gpu/drm/xe/xe_lrc.c
+++ b/drivers/gpu/drm/xe/xe_lrc.c
@@ -941,7 +941,10 @@ static void xe_lrc_finish(struct xe_lrc *lrc)
  * store it in the PPHSWP.
  */
 #define CONTEXT_ACTIVE 1ULL
-static void xe_lrc_setup_utilization(struct xe_lrc *lrc)
+static unsigned int
+xe_lrc_setup_utilization(struct xe_lrc *lrc,
+			 struct iosys_map *map,
+			 unsigned int offset)
 {
 	struct xe_device *xe = lrc_to_xe(lrc);
 	unsigned int num_dw;
@@ -965,13 +968,24 @@ static void xe_lrc_setup_utilization(struct xe_lrc *lrc)
 		*cmd++ = upper_32_bits(CONTEXT_ACTIVE);
 	}
 
-	*cmd++ = MI_BATCH_BUFFER_END;
-
 	num_dw = cmd - batch;
-	xe_map_memcpy_to(xe, &lrc->bb_per_ctx_bo->vmap, 0, batch,
-			 num_dw * sizeof(u32));
+	xe_map_memcpy_to(xe, map, 0, batch, num_dw * sizeof(u32));
+	iosys_map_incr(map, num_dw * sizeof(u32));
 
-	xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
+	return offset + num_dw;
+}
+
+static void xe_lrc_setup_wa_bb(struct xe_lrc *lrc)
+{
+	struct iosys_map map = lrc->bb_per_ctx_bo->vmap;
+	unsigned int offset = 0;
+
+	offset = xe_lrc_setup_utilization(lrc, &map, offset);
+
+	xe_map_write32(lrc_to_xe(lrc), &map, MI_BATCH_BUFFER_END);
+
+	xe_lrc_write_ctx_reg(lrc,
+			     CTX_BB_PER_CTX_PTR,
 			     xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
 }
 
@@ -1126,7 +1140,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 	map = __xe_lrc_start_seqno_map(lrc);
 	xe_map_write32(lrc_to_xe(lrc), &map, lrc->fence_ctx.next_seqno - 1);
 
-	xe_lrc_setup_utilization(lrc);
+	xe_lrc_setup_wa_bb(lrc);
 
 	return 0;
 
-- 
2.48.0



More information about the Intel-xe mailing list