[PATCH v8 3/7] drm/xe: Return number of written dwords from workaround batch buffer emission

Lucas De Marchi lucas.demarchi at intel.com
Tue Jul 8 22:11:23 UTC 2025


On Thu, Jul 03, 2025 at 09:20:55AM +0100, Tvrtko Ursulin wrote:
>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.
>
>Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin at igalia.com>
>Cc: Lucas De Marchi <lucas.demarchi at intel.com>
>---
> drivers/gpu/drm/xe/xe_lrc.c | 16 +++++++++++-----
> 1 file changed, 11 insertions(+), 5 deletions(-)
>
>diff --git a/drivers/gpu/drm/xe/xe_lrc.c b/drivers/gpu/drm/xe/xe_lrc.c
>index edd8751b164a..7f8911a10cc9 100644
>--- a/drivers/gpu/drm/xe/xe_lrc.c
>+++ b/drivers/gpu/drm/xe/xe_lrc.c
>@@ -985,7 +985,8 @@ setup_bo(struct xe_lrc *lrc,
> 	 unsigned int offset,
> 	 const struct bo_setup *funcs,
> 	 unsigned int num_funcs,
>-	 u32 **free)
>+	 u32 **free,
>+	 unsigned int *written)
> {
> 	u32 *cmd, *buf = NULL;
> 	ssize_t remain;
>@@ -1016,6 +1017,8 @@ setup_bo(struct xe_lrc *lrc,
> 			goto fail;
>
> 		cmd += len;
>+		if (written)
>+			*written += len;
> 	}
>
> 	return cmd;
>@@ -1026,13 +1029,14 @@ setup_bo(struct xe_lrc *lrc,
> }
>
> static void
>-finish_bo(struct xe_lrc *lrc, unsigned int offset, u32 *cmd, u32 *free)
>+finish_bo(struct xe_lrc *lrc, unsigned int offset, unsigned int written,
>+	  u32 *free)
> {
> 	if (!free)
> 		return;
>
> 	xe_map_memcpy_to(gt_to_xe(lrc->gt), &lrc->bo->vmap, offset, free,
>-			 (cmd - free) * sizeof(*cmd));
>+			 written * sizeof(u32));
> 	kfree(free);
> }
>
>@@ -1042,16 +1046,18 @@ static int setup_wa_bb(struct xe_lrc *lrc, struct xe_hw_engine *hwe)
> 		{ .setup = setup_utilization_wa },
> 	};
> 	unsigned int offset = __xe_lrc_wa_bb_offset(lrc);
>+	unsigned int written = 0;
> 	u32 *cmd, *buf = NULL;
>
> 	cmd = setup_bo(lrc, hwe, LRC_WA_BB_SIZE, offset, 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_bo(lrc, offset, cmd, buf);
>+	finish_bo(lrc, offset, written, buf);

we should still have cmd in this call, right? But in the next patch the
cmd should be gone as it's then unused.

Lucas De Marchi

>
> 	xe_lrc_write_ctx_reg(lrc, CTX_BB_PER_CTX_PTR,
> 			     xe_bo_ggtt_addr(lrc->bo) + offset + 1);
>-- 
>2.48.0
>


More information about the Intel-xe mailing list