Subject: linux-next: manual merge of the drm tree with Linus' tree

From: Stephen Rothwell <[email-masked]>
Date: Fri, 6 Jun 2025 12:08:51 +1000

Hi all,

Today's linux-next merge of the drm tree got a conflict in:

  drivers/gpu/drm/xe/xe_lrc.c

between commit:

  617d824c5323 ("drm/xe: Add WA BB to capture active context utilization")

from Linus' tree and commit:

  2b0a0ce0c20b ("drm/xe: Create LRC BO without VM")

from the drm tree.

I fixed it up (maybe? - see below) and can carry the fix as
necessary. This is now fixed as far as linux-next is concerned, but any
non trivial conflicts should be mentioned to your upstream maintainer
when your tree is submitted for merging.  You may also want to consider
cooperating with the maintainer of the conflicting tree to minimise any
particularly complex conflicts.

-- 
Cheers,
Stephen Rothwell

diff --cc drivers/gpu/drm/xe/xe_lrc.c
index 61a2e87990a9,e1db6f2a1ad0..000000000000
--- a/drivers/gpu/drm/xe/xe_lrc.c
+++ b/drivers/gpu/drm/xe/xe_lrc.c
@@@ -909,69 -876,7 +909,66 @@@ static void xe_lrc_set_ppgtt(struct xe_
  static void xe_lrc_finish(struct xe_lrc *lrc)
  {
  	xe_hw_fence_ctx_finish(&lrc->fence_ctx);
- 	xe_bo_lock(lrc->bo, false);
- 	xe_bo_unpin(lrc->bo);
- 	xe_bo_unlock(lrc->bo);
- 	xe_bo_put(lrc->bo);
+ 	xe_bo_unpin_map_no_vm(lrc->bo);
 +	xe_bo_unpin_map_no_vm(lrc->bb_per_ctx_bo);
 +}
 +
 +/*
 + * xe_lrc_setup_utilization() - Setup wa bb to assist in calculating active
 + * context run ticks.
 + * @lrc: Pointer to the lrc.
 + *
 + * Context Timestamp (CTX_TIMESTAMP) in the LRC accumulates the run ticks of the
 + * context, but only gets updated when the context switches out. In order to
 + * check how long a context has been active before it switches out, two things
 + * are required:
 + *
 + * (1) Determine if the context is running:
 + * To do so, we program the WA BB to set an initial value for CTX_TIMESTAMP in
 + * the LRC. The value chosen is 1 since 0 is the initial value when the LRC is
 + * initialized. During a query, we just check for this value to determine if the
 + * context is active. If the context switched out, it would overwrite this
 + * location with the actual CTX_TIMESTAMP MMIO value. Note that WA BB runs as
 + * the last part of context restore, so reusing this LRC location will not
 + * clobber anything.
 + *
 + * (2) Calculate the time that the context has been active for:
 + * The CTX_TIMESTAMP ticks only when the context is active. If a context is
 + * active, we just use the CTX_TIMESTAMP MMIO as the new value of utilization.
 + * While doing so, we need to read the CTX_TIMESTAMP MMIO for the specific
 + * engine instance. Since we do not know which instance the context is running
 + * on until it is scheduled, we also read the ENGINE_ID MMIO in the WA BB and
 + * store it in the PPHSWP.
 + */
 +#define CONTEXT_ACTIVE 1ULL
 +static void xe_lrc_setup_utilization(struct xe_lrc *lrc)
 +{
 +	u32 *cmd;
 +
 +	cmd = lrc->bb_per_ctx_bo->vmap.vaddr;
 +
 +	*cmd++ = MI_STORE_REGISTER_MEM | MI_SRM_USE_GGTT | MI_SRM_ADD_CS_OFFSET;
 +	*cmd++ = ENGINE_ID(0).addr;
 +	*cmd++ = __xe_lrc_engine_id_ggtt_addr(lrc);
 +	*cmd++ = 0;
 +
 +	*cmd++ = MI_STORE_DATA_IMM | MI_SDI_GGTT | MI_SDI_NUM_DW(1);
 +	*cmd++ = __xe_lrc_ctx_timestamp_ggtt_addr(lrc);
 +	*cmd++ = 0;
 +	*cmd++ = lower_32_bits(CONTEXT_ACTIVE);
 +
 +	if (lrc_to_xe(lrc)->info.has_64bit_timestamp) {
 +		*cmd++ = MI_STORE_DATA_IMM | MI_SDI_GGTT | MI_SDI_NUM_DW(1);
 +		*cmd++ = __xe_lrc_ctx_timestamp_udw_ggtt_addr(lrc);
 +		*cmd++ = 0;
 +		*cmd++ = upper_32_bits(CONTEXT_ACTIVE);
 +	}
 +
 +	*cmd++ = 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);
 +
  }
  
  #define PVC_CTX_ASID		(0x2e + 1)