Skip to contentSkip to conversation

More missing XeLP workarounds

PATCH Superseded Tvrtko Ursulin 1 participant 10 messages Jun 13, 2025

Subsystems (2)

v3 of 25 Superseded Latest is v25 →

lore
Share & tools
lore
#0 lore raw

v3 cover More missing XeLP workarounds

Some more missing XeLP workarounds. This time including some which need to go into indirect context, which also means some plumbing had to be added.

Includes a fix to use iosys helpers for existing wa bb emission since there is a code dependency on it.

v2:
* Use iosys helpers.
* Split indirect context plumbing as a separate patch.
* Tweak where and how Wa_16010904313 is emitted.
* Move Wa_18022495364 into the wa_bb.

v3:
* Rewrite on top of Lucas' wa bb changes - use same infrastructure.

Cc Lucas De Marchi <[email protected]>
Cc Matt Roper <[email protected]>

Tvrtko Ursulin (8):
drm/xe: Clarify LRC size when allocating
drm/xe: Generalize wa bb emission code
drm/xe: Support writing at offset in workaround batch buffer emission drm/xe: Return number of written dwords from workaround batch buffer
emission
drm/xe: Allow specifying number of extra dwords at the end of wa bb
emission
drm/xe: Add plumbing for indirect context workarounds drm/xe/xelp: Implement Wa_16010904313
drm/xe/xelp: Add Wa_18022495364

 .../gpu/drm/xe/instructions/xe_mi_commands.h  |   1 +
 drivers/gpu/drm/xe/regs/xe_engine_regs.h      |   3 +
 drivers/gpu/drm/xe/regs/xe_lrc_layout.h       |   4 +
 drivers/gpu/drm/xe/xe_lrc.c                   | 231 +++++++++++++++---
 drivers/gpu/drm/xe/xe_lrc_types.h             |   5 +-
 drivers/gpu/drm/xe/xe_wa_oob.rules            |   2 +
 6 files changed, 212 insertions(+), 34 deletions(-)
Signature · 1 line
2.48.0
#1 lore raw

PATCH v3 1/8 drm/xe: Clarify LRC size when allocating

Clarify in code and kerneldoc that lrc->size is the size of the kernel object backing both the ringbuffer and LRC in one block of memory.

---
 drivers/gpu/drm/xe/xe_lrc.c       | 17 +++++++----------
 drivers/gpu/drm/xe/xe_lrc_types.h |  2 +-
 2 files changed, 8 insertions(+), 11 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +7 -10
index 529c6a972a55..9841384cacd5 100644
@@ -1034,19 +1034,21 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 		       u32 init_flags)
 {
 	struct xe_gt *gt = hwe->gt;
+	const u32 lrc_size = xe_gt_lrc_size(gt, hwe->class);
 	struct xe_tile *tile = gt_to_tile(gt);
 	struct xe_device *xe = gt_to_xe(gt);
 	struct iosys_map map;
 	void *init_data = NULL;
 	u32 arb_enable;
-	u32 lrc_size;
 	u32 bo_flags;
 	int err;
 
 	kref_init(&lrc->refcount);
 	lrc->gt = gt;
 	lrc->flags = 0;
-	lrc_size = ring_size + xe_gt_lrc_size(gt, hwe->class);
+	lrc->size = ring_size + lrc_size;
+	lrc->ring.size = ring_size;
+	lrc->ring.tail = 0;
 	if (xe_gt_has_indirect_ring_state(gt))
 		lrc->flags |= XE_LRC_FLAG_INDIRECT_RING_STATE;
 
@@ -1059,7 +1061,7 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 	 * FIXME: Perma-pinning LRC as we don't yet support moving GGTT address
 	 * via VM bind calls.
 	 */
-	lrc->bo = xe_bo_create_pin_map(xe, tile, NULL, lrc_size,
+	lrc->bo = xe_bo_create_pin_map(xe, tile, NULL, lrc->size,
 				       ttm_bo_type_kernel,
 				       bo_flags);
 	if (IS_ERR(lrc->bo))
@@ -1073,10 +1075,6 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 		goto err_lrc_finish;
 	}
 
-	lrc->size = lrc_size;
-	lrc->ring.size = ring_size;
-	lrc->ring.tail = 0;
-
 	xe_hw_fence_ctx_init(&lrc->fence_ctx, hwe->gt,
 			     hwe->fence_irq, hwe->name);
 
@@ -1097,10 +1095,9 @@ static int xe_lrc_init(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 		xe_map_memset(xe, &map, 0, 0, LRC_PPHWSP_SIZE);	/* PPHWSP */
 		xe_map_memcpy_to(xe, &map, LRC_PPHWSP_SIZE,
 				 gt->default_lrc[hwe->class] + LRC_PPHWSP_SIZE,
-				 xe_gt_lrc_size(gt, hwe->class) - LRC_PPHWSP_SIZE);
+				 lrc_size - LRC_PPHWSP_SIZE);
 	} else {
-		xe_map_memcpy_to(xe, &map, 0, init_data,
-				 xe_gt_lrc_size(gt, hwe->class));
+		xe_map_memcpy_to(xe, &map, 0, init_data, lrc_size);
 		kfree(init_data);
 	}
 
drivers/gpu/drm/xe/xe_lrc_types.h +1 -1
index ae24cf6f8dd9..559c7c831212 100644
@@ -22,7 +22,7 @@ struct xe_lrc {
 	 */
 	struct xe_bo *bo;
 
-	/** @size: size of lrc including any indirect ring state page */
+	/** @size: size of the ring, lrc and optional indirect ring state */
 	u32 size;
 
 	/** @gt: gt which this LRC belongs to */
Signature · 1 line
2.48.0
#2 lore raw

PATCH v3 2/8 drm/xe: Generalize wa bb emission code

In reply to Tvrtko Ursulin

Generalize the wa bb emission by splitting it into three phases - setup, emit and finish, and extract setup and finish steps into helpers.

This will enable using the same infrastructure for emitting the indirect context workarounds.

---
 drivers/gpu/drm/xe/xe_lrc.c | 70 ++++++++++++++++++++++++++-----------
 1 file changed, 50 insertions(+), 20 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +50 -20
index 9841384cacd5..75dc29d261f9 100644
@@ -968,32 +968,37 @@ static ssize_t wa_bb_setup_utilization(struct xe_lrc *lrc, struct xe_hw_engine *
 	return cmd - batch;
 }
 
-struct wa_bb_setup {
+struct wa_bo_setup {
 	ssize_t (*setup)(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 			 u32 *batch, size_t max_size);
 };
 
-static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
+static u32 *
+setup_wa_bo(struct xe_lrc *lrc,
+	    struct xe_hw_engine *hwe,
+	    struct xe_bo *bo,
+	    const struct wa_bo_setup *funcs,
+	    unsigned int num_funcs,
+	    u32 **free)
 {
-	const size_t max_size = lrc->bb_per_ctx_bo->size;
-	static const struct wa_bb_setup funcs[] = {
-		{ .setup = wa_bb_setup_utilization },
-	};
+	const size_t max_size = bo->size;
+	u32 *cmd, *buf = NULL;
 	ssize_t remain;
-	u32 *cmd, *buf = NULL;
 
-	if (lrc->bb_per_ctx_bo->vmap.is_iomem) {
+	if (bo->vmap.is_iomem) {
 		buf = kmalloc(max_size, GFP_KERNEL);
 		if (!buf)
-			return -ENOMEM;
+			return ERR_PTR(-ENOMEM);
 		cmd = buf;
+		*free = buf;
 	} else {
-		cmd = lrc->bb_per_ctx_bo->vmap.vaddr;
+		cmd = bo->vmap.vaddr;
+		*free =  NULL;
 	}
 
 	remain = max_size / sizeof(*cmd);
 
-	for (size_t i = 0; i < ARRAY_SIZE(funcs); i++) {
+	for (size_t i = 0; i < num_funcs; i++) {
 		ssize_t len = funcs[i].setup(lrc, hwe, cmd, remain);
 
 		remain -= len;
@@ -1008,22 +1013,47 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
 		cmd += len;
 	}
 
+	return cmd;
+
+fail:
+	kfree(buf);
+	return ERR_PTR(-ENOSPC);
+}
+
+static void finish_wa_bo(struct xe_lrc *lrc,
+			 struct xe_hw_engine *hwe,
+			 struct xe_bo *bo,
+			 u32 *cmd,
+			 u32 *free)
+{
+	if (!free)
+		return;
+
+	xe_map_memcpy_to(gt_to_xe(lrc->gt), &bo->vmap, 0, free,
+			 (cmd - free) * sizeof(*cmd));
+	kfree(free);
+}
+
+static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
+{
+	static const struct wa_bo_setup funcs[] = {
+		{ .setup = wa_bb_setup_utilization },
+	};
+	u32 *cmd, *buf = NULL;
+
+	cmd = setup_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, funcs,
+			  ARRAY_SIZE(funcs), &buf);
+	if (IS_ERR(cmd))
+		return PTR_ERR(cmd);
+
 	*cmd++ = MI_BATCH_BUFFER_END;
 
-	if (buf) {
-		xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bb_per_ctx_bo->vmap, 0,
-				 buf, (cmd - buf) * sizeof(*cmd));
-		kfree(buf);
-	}
+	finish_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, cmd, buf);
 
 	xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
 			     xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
 
 	return 0;
-
-fail:
-	kfree(buf);
-	return -ENOSPC;
 }
 
 #define PVC_CTX_ASID		(0x2e + 1)
Signature · 1 line
2.48.0
#3 lore raw

PATCH v3 3/8 drm/xe: Support writing at offset in workaround batch buffer emission

In reply to Tvrtko Ursulin

Indirect context setup will need the ability to write its payload into an arbitrary offset.

---
 drivers/gpu/drm/xe/xe_lrc.c | 9 ++++++---
 1 file changed, 6 insertions(+), 3 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +6 -3
index 75dc29d261f9..37d4e2a3f5f0 100644
@@ -977,6 +977,7 @@ static u32 *
 setup_wa_bo(struct xe_lrc *lrc,
 	    struct xe_hw_engine *hwe,
 	    struct xe_bo *bo,
+	    unsigned int offset,
 	    const struct wa_bo_setup *funcs,
 	    unsigned int num_funcs,
 	    u32 **free)
@@ -993,6 +994,7 @@ setup_wa_bo(struct xe_lrc *lrc,
 		*free = buf;
 	} else {
 		cmd = bo->vmap.vaddr;
+		cmd += offset / sizeof(u32);
 		*free =  NULL;
 	}
 
@@ -1023,13 +1025,14 @@ setup_wa_bo(struct xe_lrc *lrc,
 static void finish_wa_bo(struct xe_lrc *lrc,
 			 struct xe_hw_engine *hwe,
 			 struct xe_bo *bo,
+			 unsigned int offset,
 			 u32 *cmd,
 			 u32 *free)
 {
 	if (!free)
 		return;
 
-	xe_map_memcpy_to(gt_to_xe(lrc->gt), &bo->vmap, 0, free,
+	xe_map_memcpy_to(gt_to_xe(lrc->gt), &bo->vmap, offset, free,
 			 (cmd - free) * sizeof(*cmd));
 	kfree(free);
 }
@@ -1041,14 +1044,14 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
 	};
 	u32 *cmd, *buf = NULL;
 
-	cmd = setup_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, funcs,
+	cmd = setup_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 0, funcs,
 			  ARRAY_SIZE(funcs), &buf);
 	if (IS_ERR(cmd))
 		return PTR_ERR(cmd);
 
 	*cmd++ = MI_BATCH_BUFFER_END;
 
-	finish_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, cmd, buf);
+	finish_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 0, cmd, buf);
 
 	xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
 			     xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
Signature · 1 line
2.48.0
#4 lore raw

PATCH v3 4/8 drm/xe: Return number of written dwords from workaround batch buffer emission

In reply to Tvrtko Ursulin

Indirect context setup will need to get to the number of written dwords. Lets add it as an output parameter so it can be accessed from the caller regardless of whether code is writing directly or via an shadow buffer.

---
 drivers/gpu/drm/xe/xe_lrc.c | 15 ++++++++++-----
 1 file changed, 10 insertions(+), 5 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +10 -5
index 37d4e2a3f5f0..dbeba7419cb0 100644
@@ -980,7 +980,8 @@ setup_wa_bo(struct xe_lrc *lrc,
 	    unsigned int offset,
 	    const struct wa_bo_setup *funcs,
 	    unsigned int num_funcs,
-	    u32 **free)
+	    u32 **free,
+	    unsigned int *written)
 {
 	const size_t max_size = bo->size;
 	u32 *cmd, *buf = NULL;
@@ -1004,6 +1005,8 @@ setup_wa_bo(struct xe_lrc *lrc,
 		ssize_t len = funcs[i].setup(lrc, hwe, cmd, remain);
 
 		remain -= len;
+		if (written)
+			*written += len;
 
 		/*
 		 * There should always be at least 1 additional dword for
@@ -1026,14 +1029,14 @@ static void finish_wa_bo(struct xe_lrc *lrc,
 			 struct xe_hw_engine *hwe,
 			 struct xe_bo *bo,
 			 unsigned int offset,
-			 u32 *cmd,
+			 unsigned int written,
 			 u32 *free)
 {
 	if (!free)
 		return;
 
 	xe_map_memcpy_to(gt_to_xe(lrc->gt), &bo->vmap, offset, free,
-			 (cmd - free) * sizeof(*cmd));
+			 written * sizeof(u32));
 	kfree(free);
 }
 
@@ -1042,16 +1045,18 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
 	static const struct wa_bo_setup funcs[] = {
 		{ .setup = wa_bb_setup_utilization },
 	};
+	unsigned int written = 0;
 	u32 *cmd, *buf = NULL;
 
 	cmd = setup_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 0, funcs,
-			  ARRAY_SIZE(funcs), &buf);
+			  ARRAY_SIZE(funcs), &buf, &written);
 	if (IS_ERR(cmd))
 		return PTR_ERR(cmd);
 
 	*cmd++ = MI_BATCH_BUFFER_END;
+	written++;
 
-	finish_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 0, cmd, buf);
+	finish_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 0, written, buf);
 
 	xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
 			     xe_bo_ggtt_addr(lrc->bb_per_ctx_bo) | 1);
Signature · 1 line
2.48.0
#5 lore raw

PATCH v3 5/8 drm/xe: Allow specifying number of extra dwords at the end of wa bb emission

In reply to Tvrtko Ursulin

Indirect context setup will need more than one.

---
 drivers/gpu/drm/xe/xe_lrc.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
drivers/gpu/drm/xe/xe_lrc.c +4 -4
index dbeba7419cb0..146e9fd7e575 100644
@@ -977,6 +977,7 @@ static u32 *
 setup_wa_bo(struct xe_lrc *lrc,
 	    struct xe_hw_engine *hwe,
 	    struct xe_bo *bo,
+	    unsigned int reserve_dw,
 	    unsigned int offset,
 	    const struct wa_bo_setup *funcs,
 	    unsigned int num_funcs,
@@ -1009,10 +1010,9 @@ setup_wa_bo(struct xe_lrc *lrc,
 			*written += len;
 
 		/*
-		 * There should always be at least 1 additional dword for
-		 * the end marker
+		 * Caller has asked for at least reserve_dw to remain unused.
 		 */
-		if (len < 0 || xe_gt_WARN_ON(lrc->gt, remain < 1))
+		if (len < 0 || xe_gt_WARN_ON(lrc->gt, remain < reserve_dw))
 			goto fail;
 
 		cmd += len;
@@ -1048,7 +1048,7 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
 	unsigned int written = 0;
 	u32 *cmd, *buf = NULL;
 
-	cmd = setup_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 0, funcs,
+	cmd = setup_wa_bo(lrc, hwe, lrc->bb_per_ctx_bo, 1, 0, funcs,
 			  ARRAY_SIZE(funcs), &buf, &written);
 	if (IS_ERR(cmd))
 		return PTR_ERR(cmd);
Signature · 1 line
2.48.0
#6 lore raw

PATCH v3 6/8 drm/xe: Add plumbing for indirect context workarounds

In reply to Tvrtko Ursulin

Some upcoming workarounds need to be emitted from the indirect workaround context so lets add some plumbing where they will be able to easily slot in.

No functional changes for now since everything is still deactivated.

Cc Lucas De Marchi <[email protected]>
Cc Matt Roper <[email protected]>
---
 drivers/gpu/drm/xe/regs/xe_lrc_layout.h |  4 ++
 drivers/gpu/drm/xe/xe_lrc.c             | 66 +++++++++++++++++++++++++
 drivers/gpu/drm/xe/xe_lrc_types.h       |  3 +-
 3 files changed, 72 insertions(+), 1 deletion(-)
drivers/gpu/drm/xe/regs/xe_lrc_layout.h +4 -0
index 994af591a2e8..06c3a24ac381 100644
@@ -12,6 +12,8 @@
 #define CTX_RING_START			(0x08 + 1)
 #define CTX_RING_CTL			(0x0a + 1)
 #define CTX_BB_PER_CTX_PTR		(0x12 + 1)
+#define CTX_CS_INDIRECT_CTX		(0x14 + 1)
+#define CTX_CS_INDIRECT_CTX_OFFSET	(0x16 + 1)
 #define CTX_TIMESTAMP			(0x22 + 1)
 #define CTX_TIMESTAMP_UDW		(0x24 + 1)
 #define CTX_INDIRECT_RING_STATE		(0x26 + 1)
@@ -36,4 +38,6 @@
 #define INDIRECT_CTX_RING_START_UDW	(0x08 + 1)
 #define INDIRECT_CTX_RING_CTL		(0x0a + 1)
 
+#define XELP_CTX_RCS_INDIRECT_CTX_OFFSET_DEFAULT	0xd
+
 #endif
drivers/gpu/drm/xe/xe_lrc.c +66 -0

102 lines not on this page · raw message

drivers/gpu/drm/xe/xe_lrc_types.h +2 -1
index 559c7c831212..9ce7d02ef210 100644
@@ -29,7 +29,8 @@ struct xe_lrc {
 	struct xe_gt *gt;
 
 	/** @flags: LRC flags */
-#define XE_LRC_FLAG_INDIRECT_RING_STATE		0x1
+#define XE_LRC_FLAG_INDIRECT_CTX		0x1
+#define XE_LRC_FLAG_INDIRECT_RING_STATE		0x2
 	u32 flags;
 
 	/** @refcount: ref count of this lrc */
Signature · 1 line
2.48.0
#7 lore raw

PATCH v3 7/8 drm/xe/xelp: Implement Wa_16010904313

In reply to Tvrtko Ursulin

Add XeLP workaround 16010904313.

The description calls for it to be emitted as the indirect context buffer workaround for render and compute, and from the workaround batch buffer for the other engines. Therefore we plug into the previously added respective top level emission functions.

The actual command streamer programming sequence differs from what is described in the PRM, in that it assumes the listed LRCA offset was supposed to actually refer to the location of the CTX_TIMESTAMP register instead of LRCA + 0x180c (which is in GPR space). Latter appears to make more sense under the assumption that multiple writes are helping with restoring the CTX_TIMESTAMP register content from the saved context state.

Cc Lucas De Marchi <[email protected]>
Cc Matt Roper <[email protected]>
---
 .../gpu/drm/xe/instructions/xe_mi_commands.h  |  1 +
 drivers/gpu/drm/xe/xe_lrc.c                   | 45 +++++++++++++++++++
 drivers/gpu/drm/xe/xe_wa_oob.rules            |  1 +
 3 files changed, 47 insertions(+)
drivers/gpu/drm/xe/instructions/xe_mi_commands.h +1 -0
index e3f5e8bb3ebc..c47b290e0e9f 100644
@@ -65,6 +65,7 @@
 
 #define MI_LOAD_REGISTER_MEM		(__MI_INSTR(0x29) | XE_INSTR_NUM_DW(4))
 #define   MI_LRM_USE_GGTT		REG_BIT(22)
+#define   MI_LRM_ASYNC			REG_BIT(21)
 
 #define MI_LOAD_REGISTER_REG		(__MI_INSTR(0x2a) | XE_INSTR_NUM_DW(3))
 #define   MI_LRR_DST_CS_MMIO		REG_BIT(19)
drivers/gpu/drm/xe/xe_lrc.c +45 -0

69 lines not on this page · raw message

drivers/gpu/drm/xe/xe_wa_oob.rules +1 -0
index 425cb401c276..e88398ac3da9 100644
@@ -1,4 +1,5 @@
 1607983814	GRAPHICS_VERSION_RANGE(1200, 1210)
+16010904313	GRAPHICS_VERSION_RANGE(1200, 1210)
 22012773006	GRAPHICS_VERSION_RANGE(1200, 1250)
 14014475959	GRAPHICS_VERSION_RANGE(1270, 1271), GRAPHICS_STEP(A0, B0)
 		PLATFORM(DG2)
Signature · 1 line
2.48.0
#8 lore raw

PATCH v3 8/8 drm/xe/xelp: Add Wa_18022495364

In reply to Tvrtko Ursulin

Add Wa_18022495364 as a context workaround batch buffer workaround.

Cc Lucas De Marchi <[email protected]>
Cc Matt Roper <[email protected]>
---
 drivers/gpu/drm/xe/regs/xe_engine_regs.h |  3 +++
 drivers/gpu/drm/xe/xe_lrc.c              | 21 +++++++++++++++++++++
 drivers/gpu/drm/xe/xe_wa_oob.rules       |  1 +
 3 files changed, 25 insertions(+)
drivers/gpu/drm/xe/regs/xe_engine_regs.h +3 -0
index 7ade41e2b7b3..f4c3e1187a00 100644
@@ -111,6 +111,9 @@
 #define   PPHWSP_CSB_AND_TIMESTAMP_REPORT_DIS	REG_BIT(14)
 #define   CS_PRIORITY_MEM_READ			REG_BIT(7)
 
+#define CS_DEBUG_MODE2(base)			XE_REG((base) + 0xd8, XE_REG_OPTION_MASKED)
+#define   INSTRUCTION_STATE_CACHE_INVALIDATE	REG_BIT(6)
+
 #define FF_SLICE_CS_CHICKEN1(base)		XE_REG((base) + 0xe0, XE_REG_OPTION_MASKED)
 #define   FFSC_PERCTX_PREEMPT_CTRL		REG_BIT(14)
 
drivers/gpu/drm/xe/xe_lrc.c +21 -0
index 6c3f6fab465a..53ac54f77691 100644
@@ -1021,6 +1021,26 @@ xelp_emit_timestamp_wa(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 	return cmd - batch;
 }
 
+static ssize_t
+xelp_invalidate_state_cache(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
+			    u32 *batch, size_t max_len)
+{
+	u32 *cmd = batch;
+
+	if (!XE_WA(lrc->gt, 18022495364) ||
+	    hwe->class != XE_ENGINE_CLASS_RENDER)
+		return 0;
+
+	if (xe_gt_WARN_ON(lrc->gt, max_len < 3))
+		return -ENOSPC;
+
+	*cmd++ = MI_LOAD_REGISTER_IMM | MI_LRI_NUM_REGS(1);
+	*cmd++ = CS_DEBUG_MODE1(0).addr;
+	*cmd++ = _MASKED_BIT_ENABLE(INSTRUCTION_STATE_CACHE_INVALIDATE);
+
+	return cmd - batch;
+}
+
 struct wa_bo_setup {
 	ssize_t (*setup)(struct xe_lrc *lrc, struct xe_hw_engine *hwe,
 			 u32 *batch, size_t max_size);
@@ -1097,6 +1117,7 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
 {
 	static const struct wa_bo_setup funcs[] = {
 		{ .setup = xelp_emit_timestamp_wa },
+		{ .setup = xelp_invalidate_state_cache },
 		{ .setup = wa_bb_setup_utilization },
 	};
 	unsigned int written = 0;
drivers/gpu/drm/xe/xe_wa_oob.rules +1 -0
index e88398ac3da9..8b7f1495cc78 100644
@@ -1,5 +1,6 @@
 1607983814	GRAPHICS_VERSION_RANGE(1200, 1210)
 16010904313	GRAPHICS_VERSION_RANGE(1200, 1210)
+18022495364	GRAPHICS_VERSION_RANGE(1200, 1210)
 22012773006	GRAPHICS_VERSION_RANGE(1200, 1250)
 14014475959	GRAPHICS_VERSION_RANGE(1270, 1271), GRAPHICS_STEP(A0, B0)
 		PLATFORM(DG2)
Signature · 1 line
2.48.0
#9 lore raw
In reply to Tvrtko Ursulin
Quoted 6 lines · Tvrtko Ursulin

Some more missing XeLP workarounds. This time including some which need to go into indirect context, which also means some plumbing had to be added.

Includes a fix to use iosys helpers for existing wa bb emission since there is a code dependency on it.

Quoted 8 lines

v2:
* Use iosys helpers.
* Split indirect context plumbing as a separate patch.
* Tweak where and how Wa_16010904313 is emitted.
* Move Wa_18022495364 into the wa_bb.

v3:
* Rewrite on top of Lucas' wa bb changes - use same infrastructure.

Scratch this, I did not spot 3a1edef8f4b5 ("drm/xe: Make WA BB part of LRC BO") has sneaked in while I was reworking this. Stay tuned for v4.

Regards,

Tvrtko

Quoted 24 lines
Cc Lucas De Marchi <[email protected]>
Cc Matt Roper <[email protected]>

Tvrtko Ursulin (8):
drm/xe: Clarify LRC size when allocating
drm/xe: Generalize wa bb emission code
drm/xe: Support writing at offset in workaround batch buffer emission drm/xe: Return number of written dwords from workaround batch buffer
emission
drm/xe: Allow specifying number of extra dwords at the end of wa bb
emission
drm/xe: Add plumbing for indirect context workarounds drm/xe/xelp: Implement Wa_16010904313
drm/xe/xelp: Add Wa_18022495364

  .../gpu/drm/xe/instructions/xe_mi_commands.h  |   1 +
  drivers/gpu/drm/xe/regs/xe_engine_regs.h      |   3 +
  drivers/gpu/drm/xe/regs/xe_lrc_layout.h       |   4 +
  drivers/gpu/drm/xe/xe_lrc.c                   | 231 +++++++++++++++---
  drivers/gpu/drm/xe/xe_lrc_types.h             |   5 +-
  drivers/gpu/drm/xe/xe_wa_oob.rules            |   2 +
  6 files changed, 212 insertions(+), 34 deletions(-)