Skip to contentSkip to conversation

drm/i915: Engine relative MMIO

PATCH In review [email protected] 4 participants 9 messages Sep 23, 2019 – Sep 24, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover drm/i915: Engine relative MMIO

From: John Harrison <[email protected]>

Newer hardware has support for making LRI accesses to MMIO registers relative to the engine that is executing the LRI instruction. This is required for things like hardware based load balancing across engines.

John Harrison (2):
drm/i915: Engine relative MMIO
drm/i915: Engine relative MMIO for Gen12

 drivers/gpu/drm/i915/gem/i915_gem_context.c  |  7 ++--
 drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 43 ++++++++++++++++++++
 drivers/gpu/drm/i915/gt/intel_engine_types.h |  4 ++
 drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  8 +++-
 drivers/gpu/drm/i915/gt/intel_lrc.c          | 40 +++++++++---------
 drivers/gpu/drm/i915/gt/intel_mocs.c         | 12 +++---
 drivers/gpu/drm/i915/gt/intel_ringbuffer.c   | 12 +++---
 drivers/gpu/drm/i915/i915_perf.c             |  9 +++-
 drivers/gpu/drm/i915/intel_device_info.c     | 14 +++++++
 drivers/gpu/drm/i915/intel_device_info.h     |  1 +
 10 files changed, 113 insertions(+), 37 deletions(-)
Signature · 6 lines
2.21.0.5.gaeb582a983

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#1 lore raw

PATCH 1/2 drm/i915: Engine relative MMIO

From: John Harrison <[email protected]>

With virtual engines, it is no longer possible to know which specific physical engine a given request will be executed on at the time that request is generated. This means that the request itself must be engine agnostic - any direct register writes must be relative to the engine and not absolute addresses.

The LRI command has support for engine relative addressing. However, the mechanism is not transparent to the driver. The scheme for Gen11 (MI_LRI_ADD_CS_MMIO_START) requires the LRI address to have no absolute engine base component. The hardware then adds on the correct engine offset at execution time.

Due to the non-trivial and differing schemes on different hardware, it is not possible to simply update the code that creates the LRI commands to set a remap flag and let the hardware get on with it. Instead, this patch adds function wrappers for generating the LRI command itself and then for constructing the correct address to use with the LRI.

v2: Fix build break in GVT. Remove flags parameter [review feedback from Chris W].

v3: Fix build break in selftest. Rebase to newer base tree and fix merge conflict.

v4: More rebasing. Rmoved relative addressing support from Gen7-9 only code paths [review feedback from Chris W].

v5: More rebasing (new 'gt' directory). Fix white space issue. Use COPY class rather than BCS0 id for checking against BCS engine.

v6: Change to MI_LRI for generic code and __MI_LRI for legacy code. MI_LRI is now a macro wrapper around an engine function pointer to reduce runtime checks on LRI relative support. [review feedback from Tvrtko]

v7: Replace engine function pointer with a per engine flags field that is added by a common function. [Daniele]

v8: Re-write on top of patch series by Mika.

v9: Fix workaround IGT failure. Not sure why but my local test runs were passing by claiming no workarounds whereas the pre-commit check failed. As all the workaround registers are currently engine independent, it is safe to simply not add the engine relative flag (which is what the selftest was expecting).

Bspec: 45606

CC Rodrigo Vivi <[email protected]>
CC Tvrtko Ursulin <[email protected]>
CC Chris P Wilson <[email protected]>
CC Daniele Ceraolo Spurio <[email protected]>
---
 drivers/gpu/drm/i915/gem/i915_gem_context.c  |  7 ++--
 drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 24 ++++++++++++
 drivers/gpu/drm/i915/gt/intel_engine_types.h |  3 ++
 drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  7 +++-
 drivers/gpu/drm/i915/gt/intel_lrc.c          | 40 ++++++++++----------
 drivers/gpu/drm/i915/gt/intel_mocs.c         |  6 +--
 drivers/gpu/drm/i915/gt/intel_ringbuffer.c   | 12 +++---
 drivers/gpu/drm/i915/i915_perf.c             |  8 +++-
 8 files changed, 73 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +4 -3
index 4a34c4f62065..c8d7075a481d 100644
@@ -980,7 +980,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
 {
 	struct i915_address_space *vm = rq->hw_context->vm;
 	struct intel_engine_cs *engine = rq->engine;
-	u32 base = engine->mmio_base;
+	u32 base = engine->lri_mmio_base;
 	u32 *cs;
 	int i;
 
@@ -992,7 +992,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
 		if (IS_ERR(cs))
 			return PTR_ERR(cs);
 
-		*cs++ = MI_LOAD_REGISTER_IMM(2);
+		*cs++ = MI_LOAD_REGISTER_IMM(2) | engine->lri_cmd_mode;
 
 		*cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_UDW(base, 0));
 		*cs++ = upper_32_bits(pd_daddr);
@@ -1014,7 +1014,8 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
 		if (IS_ERR(cs))
 			return PTR_ERR(cs);
 
-		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) | MI_LRI_FORCE_POSTED;
+		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) |
+			MI_LRI_FORCE_POSTED | engine->lri_cmd_mode;
 		for (i = GEN8_3LVL_PDPES; i--; ) {
 			const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i);
 
drivers/gpu/drm/i915/gt/intel_engine_cs.c +24 -0
index f451d5076bde..5aa58e069806 100644
@@ -236,6 +236,28 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,
 	return bases[i].base;
 }
 
+static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
+{
+	if (INTEL_GEN(engine->i915) < 11)
+		return false;
+
+	if (engine->class == COPY_ENGINE_CLASS)
+		return false;
+
+	return true;
+}
+
+static void lri_init(struct intel_engine_cs *engine)
+{
+	if (i915_engine_has_relative_lri(engine)) {
+		engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
+		engine->lri_mmio_base = 0;
+	} else {
+		engine->lri_cmd_mode = 0;
+		engine->lri_mmio_base = engine->mmio_base;
+	}
+}
+
 static void __sprint_engine_name(struct intel_engine_cs *engine)
 {
 	/*
@@ -320,6 +342,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
 	/* Nothing to do here, execute in order of dependencies */
 	engine->schedule = NULL;
 
+	lri_init(engine);
+
 	seqlock_init(&engine->stats.lock);
 
 	ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
index 943f0663837e..38f486f7f7e3 100644
@@ -306,6 +306,9 @@ struct intel_engine_cs {
 	u32 context_size;
 	u32 mmio_base;
 
+	u32 lri_mmio_base;
+	u32 lri_cmd_mode;
+
 	u32 uabi_capabilities;
 
 	struct rb_node uabi_node;
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +6 -1
index f78b13d74e17..bfb51d8d7ce2 100644
@@ -133,11 +133,16 @@
  *   simply ignores the register load under certain conditions.
  * - One can actually load arbitrary many arbitrary registers: Simply issue x
  *   address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
+ * - Newer hardware supports engine relative addressing but older hardware does
+ *   not. This is required for hw engine load balancing. Hence the MI_LRI
+ *   instruction itself is prefixed with '__' and should only be used on
+ *   legacy hardware code paths. Generic code must always use the MI_LRI
+ *   and i915_get_lri_reg() helper functions instead.
  */
 #define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
 /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
-#define   MI_LRI_CS_MMIO		(1<<19)
 #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_ADD_CS_MMIO_START_GEN11	BIT(19)
 #define MI_STORE_REGISTER_MEM        MI_INSTR(0x24, 1)
 #define MI_STORE_REGISTER_MEM_GEN8   MI_INSTR(0x24, 2)
 #define   MI_SRM_LRM_GLOBAL_GTT		(1<<22)
drivers/gpu/drm/i915/gt/intel_lrc.c +20 -20
index 6cfdc0f9f2b9..7cd59d29c4e4 100644
@@ -2010,11 +2010,12 @@ struct lri {
 	u32 value;
 };
 
-static u32 *emit_lri(u32 *batch, const struct lri *lri, unsigned int count)
+static u32 *emit_lri(struct intel_engine_cs *engine, u32 *batch,
+		     const struct lri *lri, unsigned int count)
 {
 	GEM_BUG_ON(!count || count > 63);
 
-	*batch++ = MI_LOAD_REGISTER_IMM(count);
+	*batch++ = MI_LOAD_REGISTER_IMM(count) | engine->lri_cmd_mode;
 	do {
 		*batch++ = i915_mmio_reg_offset(lri->reg);
 		*batch++ = lri->value;
@@ -2054,7 +2055,7 @@ static u32 *gen9_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)
 	/* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */
 	batch = gen8_emit_flush_coherentl3_wa(engine, batch);
 
-	batch = emit_lri(batch, lri, ARRAY_SIZE(lri));
+	batch = emit_lri(engine, batch, lri, ARRAY_SIZE(lri));
 
 	/* WaMediaPoolStateCmdInWABB:bxt,glk */
 	if (HAS_POOLED_EU(engine->i915)) {
@@ -3282,7 +3283,7 @@ static void init_common_reg_state(u32 * const regs,
 				  struct intel_engine_cs *engine,
 				  struct intel_ring *ring)
 {
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
 
 	CTX_REG(regs, CTX_CONTEXT_CONTROL, RING_CONTEXT_CONTROL(base),
 		_MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT) |
@@ -3307,7 +3308,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
 				 u32 pos_bb_per_ctx)
 {
 	struct i915_ctx_workarounds * const wa_ctx = &engine->wa_ctx;
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
 	const u32 pos_indirect_ctx = pos_bb_per_ctx + 2;
 	const u32 pos_indirect_ctx_offset = pos_indirect_ctx + 2;
 
@@ -3335,6 +3336,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
 }
 
 static void init_ppgtt_reg_state(u32 *regs, u32 base,
+				 struct intel_engine_cs *engine,
 				 struct i915_ppgtt *ppgtt)
 {
 	/* PDP values well be assigned later if needed */
@@ -3376,14 +3378,12 @@ static void gen8_init_reg_state(u32 * const regs,
 {
 	struct i915_ppgtt * const ppgtt = vm_alias(ce->vm);
 	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
 
 	regs[CTX_LRI_HEADER_0] =
 		MI_LOAD_REGISTER_IMM(rcs ? 14 : 11) |
 		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
 	init_common_reg_state(regs, ppgtt, engine, ring);
 	CTX_REG(regs, CTX_SECOND_BB_HEAD_U, RING_SBBADDR_UDW(base), 0);
@@ -3395,15 +3395,17 @@ static void gen8_init_reg_state(u32 * const regs,
 	regs[CTX_LRI_HEADER_1] =
 		MI_LOAD_REGISTER_IMM(9) |
 		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
 	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
 
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
 
 	if (rcs) {
-		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) | lri_base;
-		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
+		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) |
+					 engine->lri_cmd_mode;
+		CTX_REG(regs, CTX_R_PWR_CLK_STATE,
+			GEN8_R_PWR_CLK_STATE, 0);
 	}
 
 	regs[CTX_END] = MI_BATCH_BUFFER_END;
@@ -3418,14 +3420,12 @@ static void gen12_init_reg_state(u32 * const regs,
 {
 	struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(ce->vm);
 	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
 
 	regs[CTX_LRI_HEADER_0] =
 		MI_LOAD_REGISTER_IMM(rcs ? 11 : 9) |
 		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
 	init_common_reg_state(regs, ppgtt, engine, ring);
 
@@ -3435,15 +3435,15 @@ static void gen12_init_reg_state(u32 * const regs,
 	regs[CTX_LRI_HEADER_1] =
 		MI_LOAD_REGISTER_IMM(9) |
 		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
 	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
 
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
 
 	if (rcs) {
 		regs[GEN12_CTX_LRI_HEADER_3] =
-			MI_LOAD_REGISTER_IMM(1) | lri_base;
+			MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
 		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
 
 		/* TODO: oa_init_reg_state ? */
drivers/gpu/drm/i915/gt/intel_mocs.c +2 -4
index 728704bbbe18..8e8fe3deb95c 100644
@@ -368,9 +368,6 @@ static u32 get_entry_control(const struct drm_i915_mocs_table *table,
 /**
  * intel_mocs_init_engine() - emit the mocs control table
  * @engine:	The engine for whom to emit the registers.
- *
- * This function simply emits a MI_LOAD_REGISTER_IMM command for the
- * given table starting at the given address.
  */
 void intel_mocs_init_engine(struct intel_engine_cs *engine)
 {
@@ -456,7 +453,8 @@ static int emit_mocs_control_table(struct i915_request *rq,
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries);
+	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries) |
+		rq->engine->lri_cmd_mode;
 
 	for (index = 0; index < table->size; index++) {
 		u32 value = get_entry_control(table, index);
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +7 -5
index 0747b8c9f768..7027367b1f1a 100644
@@ -1536,12 +1536,13 @@ static int load_pd_dir(struct i915_request *rq, const struct i915_ppgtt *ppgtt)
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->mmio_base));
+	/* Can these not be merged into a single LRI??? */
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->lri_mmio_base));
 	*cs++ = PP_DIR_DCLV_2G;
 
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->mmio_base));
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->lri_mmio_base));
 	*cs++ = px_base(ppgtt->pd)->ggtt_offset << 10;
 
 	intel_ring_advance(rq, cs);
@@ -1709,7 +1710,8 @@ static int remap_l3_slice(struct i915_request *rq, int slice)
 	 * here because no other code should access these registers other than
 	 * at initialization time.
 	 */
-	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
+	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE / 4) |
+		rq->engine->lri_cmd_mode;
 	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
 		*cs++ = i915_mmio_reg_offset(GEN7_L3LOG(slice, i));
 		*cs++ = remap_info[i];
drivers/gpu/drm/i915/i915_perf.c +7 -1
index c1b764233761..8b85cdfada21 100644
@@ -1693,6 +1693,11 @@ gen8_update_reg_state_unlocked(struct i915_perf_stream *stream,
 	};
 	int i;
 
+	/*
+	 * NB: The LRI instruction is generated by the hardware.
+	 * Should we read it in and assert that the offset flag is set?
+	 */
+
 	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
 		(stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
 		(stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |
@@ -1752,8 +1757,9 @@ gen8_load_flex(struct i915_request *rq,
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(count);
+	*cs++ = MI_LOAD_REGISTER_IMM(count) | rq->engine->lri_cmd_mode;
 	do {
+		/* FIXME: Is this table LRI remap/offset friendly? */
 		*cs++ = i915_mmio_reg_offset(flex->reg);
 		*cs++ = flex->value;
 	} while (flex++, --count);
Signature · 6 lines
2.21.0.5.gaeb582a983

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw
Quoted 80 lines · On 24/09/2019 00:51, [email protected] wrote:

From: John Harrison <[email protected]>

With virtual engines, it is no longer possible to know which specific physical engine a given request will be executed on at the time that request is generated. This means that the request itself must be engine agnostic - any direct register writes must be relative to the engine and not absolute addresses.

The LRI command has support for engine relative addressing. However, the mechanism is not transparent to the driver. The scheme for Gen11 (MI_LRI_ADD_CS_MMIO_START) requires the LRI address to have no absolute engine base component. The hardware then adds on the correct engine offset at execution time.

Due to the non-trivial and differing schemes on different hardware, it is not possible to simply update the code that creates the LRI commands to set a remap flag and let the hardware get on with it. Instead, this patch adds function wrappers for generating the LRI command itself and then for constructing the correct address to use with the LRI.

v2: Fix build break in GVT. Remove flags parameter [review feedback from Chris W].

v3: Fix build break in selftest. Rebase to newer base tree and fix merge conflict.

v4: More rebasing. Rmoved relative addressing support from Gen7-9 only code paths [review feedback from Chris W].

v5: More rebasing (new 'gt' directory). Fix white space issue. Use COPY class rather than BCS0 id for checking against BCS engine.

v6: Change to MI_LRI for generic code and __MI_LRI for legacy code. MI_LRI is now a macro wrapper around an engine function pointer to reduce runtime checks on LRI relative support. [review feedback from Tvrtko]

v7: Replace engine function pointer with a per engine flags field that is added by a common function. [Daniele]

v8: Re-write on top of patch series by Mika.

v9: Fix workaround IGT failure. Not sure why but my local test runs were passing by claiming no workarounds whereas the pre-commit check failed. As all the workaround registers are currently engine independent, it is safe to simply not add the engine relative flag (which is what the selftest was expecting).

Bspec: 45606

CC Rodrigo Vivi <[email protected]>
CC Tvrtko Ursulin <[email protected]>
CC Chris P Wilson <[email protected]>
CC Daniele Ceraolo Spurio <[email protected]>
---
  drivers/gpu/drm/i915/gem/i915_gem_context.c  |  7 ++--
  drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 24 ++++++++++++
  drivers/gpu/drm/i915/gt/intel_engine_types.h |  3 ++
  drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  7 +++-
  drivers/gpu/drm/i915/gt/intel_lrc.c          | 40 ++++++++++----------
  drivers/gpu/drm/i915/gt/intel_mocs.c         |  6 +--
  drivers/gpu/drm/i915/gt/intel_ringbuffer.c   | 12 +++---
  drivers/gpu/drm/i915/i915_perf.c             |  8 +++-
  8 files changed, 73 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index 4a34c4f62065..c8d7075a481d 100644
@@ -980,7 +980,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  {
  	struct i915_address_space *vm = rq->hw_context->vm;
  	struct intel_engine_cs *engine = rq->engine;
-	u32 base = engine->mmio_base;
+	u32 base = engine->lri_mmio_base;
  	u32 *cs;
  	int i;
 

drivers/gpu/drm/i915/gem/i915_gem_context.c static int emit_ppgtt_update(struct i915_request *rq, void *data) · line 995

Quoted 5 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
@@ -992,7 +992,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  		if (IS_ERR(cs))
  			return PTR_ERR(cs);
 
-		*cs++ = MI_LOAD_REGISTER_IMM(2);
+		*cs++ = MI_LOAD_REGISTER_IMM(2) | engine->lri_cmd_mode;

I missed the part where we ended up with this new flavour and I can't say I am a fan.

What's the point in having to remember to or-in the flags at so many call sites? Are you now touching all mi_lri, or most, or how many? If all or most then why not MI_LOAD_REGISTER_IMM(engine, 2)? If not most then the same with _REL suffix as discussed before and leave the legacy untouched.

Don't know really on all the details since I lost track, but the current option leaves me concerned.

Regards,

Tvrtko

Quoted 294 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +2 -1
  		*cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_UDW(base, 0));
  		*cs++ = upper_32_bits(pd_daddr);
@@ -1014,7 +1014,8 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  		if (IS_ERR(cs))
  			return PTR_ERR(cs);
 
-		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) | MI_LRI_FORCE_POSTED;
+		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) |
+			MI_LRI_FORCE_POSTED | engine->lri_cmd_mode;
  		for (i = GEN8_3LVL_PDPES; i--; ) {
  			const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i);
 
drivers/gpu/drm/i915/gt/intel_engine_cs.c +24 -0
index f451d5076bde..5aa58e069806 100644
@@ -236,6 +236,28 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,
  	return bases[i].base;
  }
 
+static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
+{
+	if (INTEL_GEN(engine->i915) < 11)
+		return false;
+
+	if (engine->class == COPY_ENGINE_CLASS)
+		return false;
+
+	return true;
+}
+
+static void lri_init(struct intel_engine_cs *engine)
+{
+	if (i915_engine_has_relative_lri(engine)) {
+		engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
+		engine->lri_mmio_base = 0;
+	} else {
+		engine->lri_cmd_mode = 0;
+		engine->lri_mmio_base = engine->mmio_base;
+	}
+}
+
  static void __sprint_engine_name(struct intel_engine_cs *engine)
  {
  	/*
@@ -320,6 +342,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
  	/* Nothing to do here, execute in order of dependencies */
  	engine->schedule = NULL;
 
+	lri_init(engine);
+
  	seqlock_init(&engine->stats.lock);
 
  	ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
index 943f0663837e..38f486f7f7e3 100644
@@ -306,6 +306,9 @@ struct intel_engine_cs {
  	u32 context_size;
  	u32 mmio_base;
 
+	u32 lri_mmio_base;
+	u32 lri_cmd_mode;
+
  	u32 uabi_capabilities;
 
  	struct rb_node uabi_node;
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +6 -1
index f78b13d74e17..bfb51d8d7ce2 100644
@@ -133,11 +133,16 @@
   *   simply ignores the register load under certain conditions.
   * - One can actually load arbitrary many arbitrary registers: Simply issue x
   *   address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
+ * - Newer hardware supports engine relative addressing but older hardware does
+ *   not. This is required for hw engine load balancing. Hence the MI_LRI
+ *   instruction itself is prefixed with '__' and should only be used on
+ *   legacy hardware code paths. Generic code must always use the MI_LRI
+ *   and i915_get_lri_reg() helper functions instead.
   */
  #define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
  /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
-#define   MI_LRI_CS_MMIO		(1<<19)
  #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_ADD_CS_MMIO_START_GEN11	BIT(19)
  #define MI_STORE_REGISTER_MEM        MI_INSTR(0x24, 1)
  #define MI_STORE_REGISTER_MEM_GEN8   MI_INSTR(0x24, 2)
  #define   MI_SRM_LRM_GLOBAL_GTT		(1<<22)
drivers/gpu/drm/i915/gt/intel_lrc.c +20 -20
index 6cfdc0f9f2b9..7cd59d29c4e4 100644
@@ -2010,11 +2010,12 @@ struct lri {
  	u32 value;
  };
 
-static u32 *emit_lri(u32 *batch, const struct lri *lri, unsigned int count)
+static u32 *emit_lri(struct intel_engine_cs *engine, u32 *batch,
+		     const struct lri *lri, unsigned int count)
  {
  	GEM_BUG_ON(!count || count > 63);
 
-	*batch++ = MI_LOAD_REGISTER_IMM(count);
+	*batch++ = MI_LOAD_REGISTER_IMM(count) | engine->lri_cmd_mode;
  	do {
  		*batch++ = i915_mmio_reg_offset(lri->reg);
  		*batch++ = lri->value;
@@ -2054,7 +2055,7 @@ static u32 *gen9_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)
  	/* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */
  	batch = gen8_emit_flush_coherentl3_wa(engine, batch);
 
-	batch = emit_lri(batch, lri, ARRAY_SIZE(lri));
+	batch = emit_lri(engine, batch, lri, ARRAY_SIZE(lri));
 
  	/* WaMediaPoolStateCmdInWABB:bxt,glk */
  	if (HAS_POOLED_EU(engine->i915)) {
@@ -3282,7 +3283,7 @@ static void init_common_reg_state(u32 * const regs,
  				  struct intel_engine_cs *engine,
  				  struct intel_ring *ring)
  {
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
 
  	CTX_REG(regs, CTX_CONTEXT_CONTROL, RING_CONTEXT_CONTROL(base),
  		_MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT) |
@@ -3307,7 +3308,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
  				 u32 pos_bb_per_ctx)
  {
  	struct i915_ctx_workarounds * const wa_ctx = &engine->wa_ctx;
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
  	const u32 pos_indirect_ctx = pos_bb_per_ctx + 2;
  	const u32 pos_indirect_ctx_offset = pos_indirect_ctx + 2;
 
@@ -3335,6 +3336,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
  }
 
  static void init_ppgtt_reg_state(u32 *regs, u32 base,
+				 struct intel_engine_cs *engine,
  				 struct i915_ppgtt *ppgtt)
  {
  	/* PDP values well be assigned later if needed */
@@ -3376,14 +3378,12 @@ static void gen8_init_reg_state(u32 * const regs,
  {
  	struct i915_ppgtt * const ppgtt = vm_alias(ce->vm);
  	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
 
  	regs[CTX_LRI_HEADER_0] =
  		MI_LOAD_REGISTER_IMM(rcs ? 14 : 11) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	init_common_reg_state(regs, ppgtt, engine, ring);
  	CTX_REG(regs, CTX_SECOND_BB_HEAD_U, RING_SBBADDR_UDW(base), 0);
@@ -3395,15 +3395,17 @@ static void gen8_init_reg_state(u32 * const regs,
  	regs[CTX_LRI_HEADER_1] =
  		MI_LOAD_REGISTER_IMM(9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
 
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
 
  	if (rcs) {
-		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) | lri_base;
-		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
+		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) |
+					 engine->lri_cmd_mode;
+		CTX_REG(regs, CTX_R_PWR_CLK_STATE,
+			GEN8_R_PWR_CLK_STATE, 0);
  	}
 
  	regs[CTX_END] = MI_BATCH_BUFFER_END;
@@ -3418,14 +3420,12 @@ static void gen12_init_reg_state(u32 * const regs,
  {
  	struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(ce->vm);
  	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
 
  	regs[CTX_LRI_HEADER_0] =
  		MI_LOAD_REGISTER_IMM(rcs ? 11 : 9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	init_common_reg_state(regs, ppgtt, engine, ring);
 
@@ -3435,15 +3435,15 @@ static void gen12_init_reg_state(u32 * const regs,
  	regs[CTX_LRI_HEADER_1] =
  		MI_LOAD_REGISTER_IMM(9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
 
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
 
  	if (rcs) {
  		regs[GEN12_CTX_LRI_HEADER_3] =
-			MI_LOAD_REGISTER_IMM(1) | lri_base;
+			MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
  		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
 
  		/* TODO: oa_init_reg_state ? */
drivers/gpu/drm/i915/gt/intel_mocs.c +2 -4
index 728704bbbe18..8e8fe3deb95c 100644
@@ -368,9 +368,6 @@ static u32 get_entry_control(const struct drm_i915_mocs_table *table,
  /**
   * intel_mocs_init_engine() - emit the mocs control table
   * @engine:	The engine for whom to emit the registers.
- *
- * This function simply emits a MI_LOAD_REGISTER_IMM command for the
- * given table starting at the given address.
   */
  void intel_mocs_init_engine(struct intel_engine_cs *engine)
  {
@@ -456,7 +453,8 @@ static int emit_mocs_control_table(struct i915_request *rq,
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries);
+	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries) |
+		rq->engine->lri_cmd_mode;
 
  	for (index = 0; index < table->size; index++) {
  		u32 value = get_entry_control(table, index);
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +7 -5
index 0747b8c9f768..7027367b1f1a 100644
@@ -1536,12 +1536,13 @@ static int load_pd_dir(struct i915_request *rq, const struct i915_ppgtt *ppgtt)
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->mmio_base));
+	/* Can these not be merged into a single LRI??? */
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->lri_mmio_base));
  	*cs++ = PP_DIR_DCLV_2G;
 
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->mmio_base));
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->lri_mmio_base));
  	*cs++ = px_base(ppgtt->pd)->ggtt_offset << 10;
 
  	intel_ring_advance(rq, cs);
@@ -1709,7 +1710,8 @@ static int remap_l3_slice(struct i915_request *rq, int slice)
  	 * here because no other code should access these registers other than
  	 * at initialization time.
  	 */
-	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
+	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE / 4) |
+		rq->engine->lri_cmd_mode;
  	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
  		*cs++ = i915_mmio_reg_offset(GEN7_L3LOG(slice, i));
  		*cs++ = remap_info[i];
drivers/gpu/drm/i915/i915_perf.c +5 -0
index c1b764233761..8b85cdfada21 100644
@@ -1693,6 +1693,11 @@ gen8_update_reg_state_unlocked(struct i915_perf_stream *stream,
  	};
  	int i;
 
+	/*
+	 * NB: The LRI instruction is generated by the hardware.
+	 * Should we read it in and assert that the offset flag is set?
+	 */
+
  	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
  		(stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
  		(stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |

drivers/gpu/drm/i915/i915_perf.c gen8_load_flex(struct i915_request *rq, · line 1765

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +2 -1
@@ -1752,8 +1757,9 @@ gen8_load_flex(struct i915_request *rq,
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(count);
+	*cs++ = MI_LOAD_REGISTER_IMM(count) | rq->engine->lri_cmd_mode;
  	do {
+		/* FIXME: Is this table LRI remap/offset friendly? */
  		*cs++ = i915_mmio_reg_offset(flex->reg);
  		*cs++ = flex->value;
  	} while (flex++, --count);

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

maintainer
#3 lore raw
Quoted 89 lines · Tvrtko Ursulin
Quoted 79 lines · On 24/09/2019 00:51, [email protected] wrote:

From: John Harrison <[email protected]>

With virtual engines, it is no longer possible to know which specific physical engine a given request will be executed on at the time that request is generated. This means that the request itself must be engine agnostic - any direct register writes must be relative to the engine and not absolute addresses.

The LRI command has support for engine relative addressing. However, the mechanism is not transparent to the driver. The scheme for Gen11 (MI_LRI_ADD_CS_MMIO_START) requires the LRI address to have no absolute engine base component. The hardware then adds on the correct engine offset at execution time.

Due to the non-trivial and differing schemes on different hardware, it is not possible to simply update the code that creates the LRI commands to set a remap flag and let the hardware get on with it. Instead, this patch adds function wrappers for generating the LRI command itself and then for constructing the correct address to use with the LRI.

v2: Fix build break in GVT. Remove flags parameter [review feedback from Chris W].

v3: Fix build break in selftest. Rebase to newer base tree and fix merge conflict.

v4: More rebasing. Rmoved relative addressing support from Gen7-9 only code paths [review feedback from Chris W].

v5: More rebasing (new 'gt' directory). Fix white space issue. Use COPY class rather than BCS0 id for checking against BCS engine.

v6: Change to MI_LRI for generic code and __MI_LRI for legacy code. MI_LRI is now a macro wrapper around an engine function pointer to reduce runtime checks on LRI relative support. [review feedback from Tvrtko]

v7: Replace engine function pointer with a per engine flags field that is added by a common function. [Daniele]

v8: Re-write on top of patch series by Mika.

v9: Fix workaround IGT failure. Not sure why but my local test runs were passing by claiming no workarounds whereas the pre-commit check failed. As all the workaround registers are currently engine independent, it is safe to simply not add the engine relative flag (which is what the selftest was expecting).

Bspec: 45606

CC Rodrigo Vivi <[email protected]>
CC Tvrtko Ursulin <[email protected]>
CC Chris P Wilson <[email protected]>
CC Daniele Ceraolo Spurio <[email protected]>
---
  drivers/gpu/drm/i915/gem/i915_gem_context.c  |  7 ++--
  drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 24 ++++++++++++
  drivers/gpu/drm/i915/gt/intel_engine_types.h |  3 ++
  drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  7 +++-
  drivers/gpu/drm/i915/gt/intel_lrc.c          | 40 ++++++++++----------
  drivers/gpu/drm/i915/gt/intel_mocs.c         |  6 +--
  drivers/gpu/drm/i915/gt/intel_ringbuffer.c   | 12 +++---
  drivers/gpu/drm/i915/i915_perf.c             |  8 +++-
  8 files changed, 73 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
index 4a34c4f62065..c8d7075a481d 100644
@@ -980,7 +980,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  {
  	struct i915_address_space *vm = rq->hw_context->vm;
  	struct intel_engine_cs *engine = rq->engine;
-	u32 base = engine->mmio_base;
+	u32 base = engine->lri_mmio_base;
  	u32 *cs;
  	int i;

drivers/gpu/drm/i915/gem/i915_gem_context.c static int emit_ppgtt_update(struct i915_request *rq, void *data) · line 994

Quoted 4 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +1 -1
@@ -992,7 +992,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  		if (IS_ERR(cs))
  			return PTR_ERR(cs);
-		*cs++ = MI_LOAD_REGISTER_IMM(2);
+		*cs++ = MI_LOAD_REGISTER_IMM(2) | engine->lri_cmd_mode;

I missed the part where we ended up with this new flavour and I can't say I am a fan.

Quoted 4 lines

What's the point in having to remember to or-in the flags at so many call sites? Are you now touching all mi_lri, or most, or how many? If all or most then why not MI_LOAD_REGISTER_IMM(engine, 2)? If not most then the same with _REL suffix as discussed before and leave the legacy untouched.

Yeap, I also believe that it is better to not touch legacy and create the new one only with new cases. The real change gets much clear.

Quoted 273 lines

Don't know really on all the details since I lost track, but the current option leaves me concerned.

Regards,

Tvrtko

Quoted 265 lines
drivers/gpu/drm/i915/gem/i915_gem_context.c +2 -1
  		*cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_UDW(base, 0));
  		*cs++ = upper_32_bits(pd_daddr);
@@ -1014,7 +1014,8 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  		if (IS_ERR(cs))
  			return PTR_ERR(cs);
-		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) | MI_LRI_FORCE_POSTED;
+		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) |
+			MI_LRI_FORCE_POSTED | engine->lri_cmd_mode;
  		for (i = GEN8_3LVL_PDPES; i--; ) {
  			const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i);
drivers/gpu/drm/i915/gt/intel_engine_cs.c +24 -0
index f451d5076bde..5aa58e069806 100644
@@ -236,6 +236,28 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,
  	return bases[i].base;
  }
+static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
+{
+	if (INTEL_GEN(engine->i915) < 11)
+		return false;
+
+	if (engine->class == COPY_ENGINE_CLASS)
+		return false;
+
+	return true;
+}
+
+static void lri_init(struct intel_engine_cs *engine)
+{
+	if (i915_engine_has_relative_lri(engine)) {
+		engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
+		engine->lri_mmio_base = 0;
+	} else {
+		engine->lri_cmd_mode = 0;
+		engine->lri_mmio_base = engine->mmio_base;
+	}
+}
+
  static void __sprint_engine_name(struct intel_engine_cs *engine)
  {
  	/*
@@ -320,6 +342,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
  	/* Nothing to do here, execute in order of dependencies */
  	engine->schedule = NULL;
+	lri_init(engine);
+
  	seqlock_init(&engine->stats.lock);
  	ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
index 943f0663837e..38f486f7f7e3 100644
@@ -306,6 +306,9 @@ struct intel_engine_cs {
  	u32 context_size;
  	u32 mmio_base;
+	u32 lri_mmio_base;
+	u32 lri_cmd_mode;
+
  	u32 uabi_capabilities;
  	struct rb_node uabi_node;
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +6 -1
index f78b13d74e17..bfb51d8d7ce2 100644
@@ -133,11 +133,16 @@
   *   simply ignores the register load under certain conditions.
   * - One can actually load arbitrary many arbitrary registers: Simply issue x
   *   address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
+ * - Newer hardware supports engine relative addressing but older hardware does
+ *   not. This is required for hw engine load balancing. Hence the MI_LRI
+ *   instruction itself is prefixed with '__' and should only be used on
+ *   legacy hardware code paths. Generic code must always use the MI_LRI
+ *   and i915_get_lri_reg() helper functions instead.
   */
  #define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
  /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
-#define   MI_LRI_CS_MMIO		(1<<19)
  #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_ADD_CS_MMIO_START_GEN11	BIT(19)
  #define MI_STORE_REGISTER_MEM        MI_INSTR(0x24, 1)
  #define MI_STORE_REGISTER_MEM_GEN8   MI_INSTR(0x24, 2)
  #define   MI_SRM_LRM_GLOBAL_GTT		(1<<22)
drivers/gpu/drm/i915/gt/intel_lrc.c +20 -20
index 6cfdc0f9f2b9..7cd59d29c4e4 100644
@@ -2010,11 +2010,12 @@ struct lri {
  	u32 value;
  };
-static u32 *emit_lri(u32 *batch, const struct lri *lri, unsigned int count)
+static u32 *emit_lri(struct intel_engine_cs *engine, u32 *batch,
+		     const struct lri *lri, unsigned int count)
  {
  	GEM_BUG_ON(!count || count > 63);
-	*batch++ = MI_LOAD_REGISTER_IMM(count);
+	*batch++ = MI_LOAD_REGISTER_IMM(count) | engine->lri_cmd_mode;
  	do {
  		*batch++ = i915_mmio_reg_offset(lri->reg);
  		*batch++ = lri->value;
@@ -2054,7 +2055,7 @@ static u32 *gen9_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)
  	/* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */
  	batch = gen8_emit_flush_coherentl3_wa(engine, batch);
-	batch = emit_lri(batch, lri, ARRAY_SIZE(lri));
+	batch = emit_lri(engine, batch, lri, ARRAY_SIZE(lri));
  	/* WaMediaPoolStateCmdInWABB:bxt,glk */
  	if (HAS_POOLED_EU(engine->i915)) {
@@ -3282,7 +3283,7 @@ static void init_common_reg_state(u32 * const regs,
  				  struct intel_engine_cs *engine,
  				  struct intel_ring *ring)
  {
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
  	CTX_REG(regs, CTX_CONTEXT_CONTROL, RING_CONTEXT_CONTROL(base),
  		_MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT) |
@@ -3307,7 +3308,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
  				 u32 pos_bb_per_ctx)
  {
  	struct i915_ctx_workarounds * const wa_ctx = &engine->wa_ctx;
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
  	const u32 pos_indirect_ctx = pos_bb_per_ctx + 2;
  	const u32 pos_indirect_ctx_offset = pos_indirect_ctx + 2;
@@ -3335,6 +3336,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
  }
  static void init_ppgtt_reg_state(u32 *regs, u32 base,
+				 struct intel_engine_cs *engine,
  				 struct i915_ppgtt *ppgtt)
  {
  	/* PDP values well be assigned later if needed */
@@ -3376,14 +3378,12 @@ static void gen8_init_reg_state(u32 * const regs,
  {
  	struct i915_ppgtt * const ppgtt = vm_alias(ce->vm);
  	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
  	regs[CTX_LRI_HEADER_0] =
  		MI_LOAD_REGISTER_IMM(rcs ? 14 : 11) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
  	init_common_reg_state(regs, ppgtt, engine, ring);
  	CTX_REG(regs, CTX_SECOND_BB_HEAD_U, RING_SBBADDR_UDW(base), 0);
@@ -3395,15 +3395,17 @@ static void gen8_init_reg_state(u32 * const regs,
  	regs[CTX_LRI_HEADER_1] =
  		MI_LOAD_REGISTER_IMM(9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
  	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
  	if (rcs) {
-		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) | lri_base;
-		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
+		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) |
+					 engine->lri_cmd_mode;
+		CTX_REG(regs, CTX_R_PWR_CLK_STATE,
+			GEN8_R_PWR_CLK_STATE, 0);
  	}
  	regs[CTX_END] = MI_BATCH_BUFFER_END;
@@ -3418,14 +3420,12 @@ static void gen12_init_reg_state(u32 * const regs,
  {
  	struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(ce->vm);
  	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
  	regs[CTX_LRI_HEADER_0] =
  		MI_LOAD_REGISTER_IMM(rcs ? 11 : 9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
  	init_common_reg_state(regs, ppgtt, engine, ring);
@@ -3435,15 +3435,15 @@ static void gen12_init_reg_state(u32 * const regs,
  	regs[CTX_LRI_HEADER_1] =
  		MI_LOAD_REGISTER_IMM(9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
  	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
  	if (rcs) {
  		regs[GEN12_CTX_LRI_HEADER_3] =
-			MI_LOAD_REGISTER_IMM(1) | lri_base;
+			MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
  		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
  		/* TODO: oa_init_reg_state ? */
drivers/gpu/drm/i915/gt/intel_mocs.c +2 -4
index 728704bbbe18..8e8fe3deb95c 100644
@@ -368,9 +368,6 @@ static u32 get_entry_control(const struct drm_i915_mocs_table *table,
  /**
   * intel_mocs_init_engine() - emit the mocs control table
   * @engine:	The engine for whom to emit the registers.
- *
- * This function simply emits a MI_LOAD_REGISTER_IMM command for the
- * given table starting at the given address.
   */
  void intel_mocs_init_engine(struct intel_engine_cs *engine)
  {
@@ -456,7 +453,8 @@ static int emit_mocs_control_table(struct i915_request *rq,
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
-	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries);
+	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries) |
+		rq->engine->lri_cmd_mode;
  	for (index = 0; index < table->size; index++) {
  		u32 value = get_entry_control(table, index);
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +7 -5
index 0747b8c9f768..7027367b1f1a 100644
@@ -1536,12 +1536,13 @@ static int load_pd_dir(struct i915_request *rq, const struct i915_ppgtt *ppgtt)
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->mmio_base));
+	/* Can these not be merged into a single LRI??? */
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->lri_mmio_base));
  	*cs++ = PP_DIR_DCLV_2G;
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->mmio_base));
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->lri_mmio_base));
  	*cs++ = px_base(ppgtt->pd)->ggtt_offset << 10;
  	intel_ring_advance(rq, cs);
@@ -1709,7 +1710,8 @@ static int remap_l3_slice(struct i915_request *rq, int slice)
  	 * here because no other code should access these registers other than
  	 * at initialization time.
  	 */
-	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
+	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE / 4) |
+		rq->engine->lri_cmd_mode;
  	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
  		*cs++ = i915_mmio_reg_offset(GEN7_L3LOG(slice, i));
  		*cs++ = remap_info[i];
drivers/gpu/drm/i915/i915_perf.c +7 -1
index c1b764233761..8b85cdfada21 100644
@@ -1693,6 +1693,11 @@ gen8_update_reg_state_unlocked(struct i915_perf_stream *stream,
  	};
  	int i;
+	/*
+	 * NB: The LRI instruction is generated by the hardware.
+	 * Should we read it in and assert that the offset flag is set?
+	 */
+
  	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
  		(stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
  		(stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |
@@ -1752,8 +1757,9 @@ gen8_load_flex(struct i915_request *rq,
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
-	*cs++ = MI_LOAD_REGISTER_IMM(count);
+	*cs++ = MI_LOAD_REGISTER_IMM(count) | rq->engine->lri_cmd_mode;
  	do {
+		/* FIXME: Is this table LRI remap/offset friendly? */
Quoted 8 lines

drivers/gpu/drm/i915/i915_perf.c gen8_load_flex(struct i915_request *rq,

Quoted 4 lines
drivers/gpu/drm/i915/i915_perf.c +0 -0
  		*cs++ = i915_mmio_reg_offset(flex->reg);
  		*cs++ = flex->value;
  	} while (flex++, --count);
 

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#4 lore raw
In reply to [email protected]
Quoted 248 lines · On 24/09/2019 00:51, [email protected] wrote:

From: John Harrison <[email protected]>

With virtual engines, it is no longer possible to know which specific physical engine a given request will be executed on at the time that request is generated. This means that the request itself must be engine agnostic - any direct register writes must be relative to the engine and not absolute addresses.

The LRI command has support for engine relative addressing. However, the mechanism is not transparent to the driver. The scheme for Gen11 (MI_LRI_ADD_CS_MMIO_START) requires the LRI address to have no absolute engine base component. The hardware then adds on the correct engine offset at execution time.

Due to the non-trivial and differing schemes on different hardware, it is not possible to simply update the code that creates the LRI commands to set a remap flag and let the hardware get on with it. Instead, this patch adds function wrappers for generating the LRI command itself and then for constructing the correct address to use with the LRI.

v2: Fix build break in GVT. Remove flags parameter [review feedback from Chris W].

v3: Fix build break in selftest. Rebase to newer base tree and fix merge conflict.

v4: More rebasing. Rmoved relative addressing support from Gen7-9 only code paths [review feedback from Chris W].

v5: More rebasing (new 'gt' directory). Fix white space issue. Use COPY class rather than BCS0 id for checking against BCS engine.

v6: Change to MI_LRI for generic code and __MI_LRI for legacy code. MI_LRI is now a macro wrapper around an engine function pointer to reduce runtime checks on LRI relative support. [review feedback from Tvrtko]

v7: Replace engine function pointer with a per engine flags field that is added by a common function. [Daniele]

v8: Re-write on top of patch series by Mika.

v9: Fix workaround IGT failure. Not sure why but my local test runs were passing by claiming no workarounds whereas the pre-commit check failed. As all the workaround registers are currently engine independent, it is safe to simply not add the engine relative flag (which is what the selftest was expecting).

Bspec: 45606

CC Rodrigo Vivi <[email protected]>
CC Tvrtko Ursulin <[email protected]>
CC Chris P Wilson <[email protected]>
CC Daniele Ceraolo Spurio <[email protected]>
---
  drivers/gpu/drm/i915/gem/i915_gem_context.c  |  7 ++--
  drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 24 ++++++++++++
  drivers/gpu/drm/i915/gt/intel_engine_types.h |  3 ++
  drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  7 +++-
  drivers/gpu/drm/i915/gt/intel_lrc.c          | 40 ++++++++++----------
  drivers/gpu/drm/i915/gt/intel_mocs.c         |  6 +--
  drivers/gpu/drm/i915/gt/intel_ringbuffer.c   | 12 +++---
  drivers/gpu/drm/i915/i915_perf.c             |  8 +++-
  8 files changed, 73 insertions(+), 34 deletions(-)
drivers/gpu/drm/i915/gem/i915_gem_context.c +4 -3
index 4a34c4f62065..c8d7075a481d 100644
@@ -980,7 +980,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  {
  	struct i915_address_space *vm = rq->hw_context->vm;
  	struct intel_engine_cs *engine = rq->engine;
-	u32 base = engine->mmio_base;
+	u32 base = engine->lri_mmio_base;
  	u32 *cs;
  	int i;
 
@@ -992,7 +992,7 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  		if (IS_ERR(cs))
  			return PTR_ERR(cs);
 
-		*cs++ = MI_LOAD_REGISTER_IMM(2);
+		*cs++ = MI_LOAD_REGISTER_IMM(2) | engine->lri_cmd_mode;
 
  		*cs++ = i915_mmio_reg_offset(GEN8_RING_PDP_UDW(base, 0));
  		*cs++ = upper_32_bits(pd_daddr);
@@ -1014,7 +1014,8 @@ static int emit_ppgtt_update(struct i915_request *rq, void *data)
  		if (IS_ERR(cs))
  			return PTR_ERR(cs);
 
-		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) | MI_LRI_FORCE_POSTED;
+		*cs++ = MI_LOAD_REGISTER_IMM(2 * GEN8_3LVL_PDPES) |
+			MI_LRI_FORCE_POSTED | engine->lri_cmd_mode;
  		for (i = GEN8_3LVL_PDPES; i--; ) {
  			const dma_addr_t pd_daddr = i915_page_dir_dma_addr(ppgtt, i);
 
drivers/gpu/drm/i915/gt/intel_engine_cs.c +24 -0
index f451d5076bde..5aa58e069806 100644
@@ -236,6 +236,28 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,
  	return bases[i].base;
  }
 
+static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
+{
+	if (INTEL_GEN(engine->i915) < 11)
+		return false;
+
+	if (engine->class == COPY_ENGINE_CLASS)
+		return false;
+
+	return true;
+}
+
+static void lri_init(struct intel_engine_cs *engine)
+{
+	if (i915_engine_has_relative_lri(engine)) {
+		engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
+		engine->lri_mmio_base = 0;
+	} else {
+		engine->lri_cmd_mode = 0;
+		engine->lri_mmio_base = engine->mmio_base;
+	}
+}
+
  static void __sprint_engine_name(struct intel_engine_cs *engine)
  {
  	/*
@@ -320,6 +342,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
  	/* Nothing to do here, execute in order of dependencies */
  	engine->schedule = NULL;
 
+	lri_init(engine);
+
  	seqlock_init(&engine->stats.lock);
 
  	ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier);
drivers/gpu/drm/i915/gt/intel_engine_types.h +3 -0
index 943f0663837e..38f486f7f7e3 100644
@@ -306,6 +306,9 @@ struct intel_engine_cs {
  	u32 context_size;
  	u32 mmio_base;
 
+	u32 lri_mmio_base;
+	u32 lri_cmd_mode;
+
  	u32 uabi_capabilities;
 
  	struct rb_node uabi_node;
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +6 -1
index f78b13d74e17..bfb51d8d7ce2 100644
@@ -133,11 +133,16 @@
   *   simply ignores the register load under certain conditions.
   * - One can actually load arbitrary many arbitrary registers: Simply issue x
   *   address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
+ * - Newer hardware supports engine relative addressing but older hardware does
+ *   not. This is required for hw engine load balancing. Hence the MI_LRI
+ *   instruction itself is prefixed with '__' and should only be used on
+ *   legacy hardware code paths. Generic code must always use the MI_LRI
+ *   and i915_get_lri_reg() helper functions instead.
   */
  #define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
  /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
-#define   MI_LRI_CS_MMIO		(1<<19)
  #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_ADD_CS_MMIO_START_GEN11	BIT(19)
  #define MI_STORE_REGISTER_MEM        MI_INSTR(0x24, 1)
  #define MI_STORE_REGISTER_MEM_GEN8   MI_INSTR(0x24, 2)
  #define   MI_SRM_LRM_GLOBAL_GTT		(1<<22)
drivers/gpu/drm/i915/gt/intel_lrc.c +9 -9
index 6cfdc0f9f2b9..7cd59d29c4e4 100644
@@ -2010,11 +2010,12 @@ struct lri {
  	u32 value;
  };
 
-static u32 *emit_lri(u32 *batch, const struct lri *lri, unsigned int count)
+static u32 *emit_lri(struct intel_engine_cs *engine, u32 *batch,
+		     const struct lri *lri, unsigned int count)
  {
  	GEM_BUG_ON(!count || count > 63);
 
-	*batch++ = MI_LOAD_REGISTER_IMM(count);
+	*batch++ = MI_LOAD_REGISTER_IMM(count) | engine->lri_cmd_mode;
  	do {
  		*batch++ = i915_mmio_reg_offset(lri->reg);
  		*batch++ = lri->value;
@@ -2054,7 +2055,7 @@ static u32 *gen9_init_indirectctx_bb(struct intel_engine_cs *engine, u32 *batch)
  	/* WaFlushCoherentL3CacheLinesAtContextSwitch:skl,bxt,glk */
  	batch = gen8_emit_flush_coherentl3_wa(engine, batch);
 
-	batch = emit_lri(batch, lri, ARRAY_SIZE(lri));
+	batch = emit_lri(engine, batch, lri, ARRAY_SIZE(lri));
 
  	/* WaMediaPoolStateCmdInWABB:bxt,glk */
  	if (HAS_POOLED_EU(engine->i915)) {
@@ -3282,7 +3283,7 @@ static void init_common_reg_state(u32 * const regs,
  				  struct intel_engine_cs *engine,
  				  struct intel_ring *ring)
  {
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
 
  	CTX_REG(regs, CTX_CONTEXT_CONTROL, RING_CONTEXT_CONTROL(base),
  		_MASKED_BIT_DISABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT) |
@@ -3307,7 +3308,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
  				 u32 pos_bb_per_ctx)
  {
  	struct i915_ctx_workarounds * const wa_ctx = &engine->wa_ctx;
-	const u32 base = engine->mmio_base;
+	const u32 base = engine->lri_mmio_base;
  	const u32 pos_indirect_ctx = pos_bb_per_ctx + 2;
  	const u32 pos_indirect_ctx_offset = pos_indirect_ctx + 2;
 
@@ -3335,6 +3336,7 @@ static void init_wa_bb_reg_state(u32 * const regs,
  }
 
  static void init_ppgtt_reg_state(u32 *regs, u32 base,
+				 struct intel_engine_cs *engine,
  				 struct i915_ppgtt *ppgtt)
  {
  	/* PDP values well be assigned later if needed */
@@ -3376,14 +3378,12 @@ static void gen8_init_reg_state(u32 * const regs,
  {
  	struct i915_ppgtt * const ppgtt = vm_alias(ce->vm);
  	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
 
  	regs[CTX_LRI_HEADER_0] =
  		MI_LOAD_REGISTER_IMM(rcs ? 14 : 11) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	init_common_reg_state(regs, ppgtt, engine, ring);
  	CTX_REG(regs, CTX_SECOND_BB_HEAD_U, RING_SBBADDR_UDW(base), 0);

drivers/gpu/drm/i915/gt/intel_lrc.c static void gen8_init_reg_state(u32 * const regs, · line 3402

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +2 -2
@@ -3395,15 +3395,17 @@ static void gen8_init_reg_state(u32 * const regs,
  	regs[CTX_LRI_HEADER_1] =
  		MI_LOAD_REGISTER_IMM(9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
 
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);

Is passed in base always equal to engine->mmio_base? If so then there is redundancy and you could drop this change.

Regards,

Tvrtko

Quoted 121 lines
drivers/gpu/drm/i915/gt/intel_lrc.c +9 -9
  	if (rcs) {
-		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) | lri_base;
-		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
+		regs[CTX_LRI_HEADER_2] = MI_LOAD_REGISTER_IMM(1) |
+					 engine->lri_cmd_mode;
+		CTX_REG(regs, CTX_R_PWR_CLK_STATE,
+			GEN8_R_PWR_CLK_STATE, 0);
  	}
 
  	regs[CTX_END] = MI_BATCH_BUFFER_END;
@@ -3418,14 +3420,12 @@ static void gen12_init_reg_state(u32 * const regs,
  {
  	struct i915_ppgtt * const ppgtt = i915_vm_to_ppgtt(ce->vm);
  	const bool rcs = engine->class == RENDER_CLASS;
-	const u32 base = engine->mmio_base;
-	const u32 lri_base =
-		intel_engine_has_relative_mmio(engine) ? MI_LRI_CS_MMIO : 0;
+	const u32 base = engine->lri_mmio_base;
 
  	regs[CTX_LRI_HEADER_0] =
  		MI_LOAD_REGISTER_IMM(rcs ? 11 : 9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	init_common_reg_state(regs, ppgtt, engine, ring);
 
@@ -3435,15 +3435,15 @@ static void gen12_init_reg_state(u32 * const regs,
  	regs[CTX_LRI_HEADER_1] =
  		MI_LOAD_REGISTER_IMM(9) |
  		MI_LRI_FORCE_POSTED |
-		lri_base;
+		engine->lri_cmd_mode;
 
  	CTX_REG(regs, CTX_CTX_TIMESTAMP, RING_CTX_TIMESTAMP(base), 0);
 
-	init_ppgtt_reg_state(regs, base, ppgtt);
+	init_ppgtt_reg_state(regs, base, engine, ppgtt);
 
  	if (rcs) {
  		regs[GEN12_CTX_LRI_HEADER_3] =
-			MI_LOAD_REGISTER_IMM(1) | lri_base;
+			MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
  		CTX_REG(regs, CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE, 0);
 
  		/* TODO: oa_init_reg_state ? */
drivers/gpu/drm/i915/gt/intel_mocs.c +2 -4
index 728704bbbe18..8e8fe3deb95c 100644
@@ -368,9 +368,6 @@ static u32 get_entry_control(const struct drm_i915_mocs_table *table,
  /**
   * intel_mocs_init_engine() - emit the mocs control table
   * @engine:	The engine for whom to emit the registers.
- *
- * This function simply emits a MI_LOAD_REGISTER_IMM command for the
- * given table starting at the given address.
   */
  void intel_mocs_init_engine(struct intel_engine_cs *engine)
  {
@@ -456,7 +453,8 @@ static int emit_mocs_control_table(struct i915_request *rq,
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries);
+	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries) |
+		rq->engine->lri_cmd_mode;
 
  	for (index = 0; index < table->size; index++) {
  		u32 value = get_entry_control(table, index);
drivers/gpu/drm/i915/gt/intel_ringbuffer.c +7 -5
index 0747b8c9f768..7027367b1f1a 100644
@@ -1536,12 +1536,13 @@ static int load_pd_dir(struct i915_request *rq, const struct i915_ppgtt *ppgtt)
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->mmio_base));
+	/* Can these not be merged into a single LRI??? */
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_DCLV(engine->lri_mmio_base));
  	*cs++ = PP_DIR_DCLV_2G;
 
-	*cs++ = MI_LOAD_REGISTER_IMM(1);
-	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->mmio_base));
+	*cs++ = MI_LOAD_REGISTER_IMM(1) | engine->lri_cmd_mode;
+	*cs++ = i915_mmio_reg_offset(RING_PP_DIR_BASE(engine->lri_mmio_base));
  	*cs++ = px_base(ppgtt->pd)->ggtt_offset << 10;
 
  	intel_ring_advance(rq, cs);
@@ -1709,7 +1710,8 @@ static int remap_l3_slice(struct i915_request *rq, int slice)
  	 * here because no other code should access these registers other than
  	 * at initialization time.
  	 */
-	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE/4);
+	*cs++ = MI_LOAD_REGISTER_IMM(GEN7_L3LOG_SIZE / 4) |
+		rq->engine->lri_cmd_mode;
  	for (i = 0; i < GEN7_L3LOG_SIZE/4; i++) {
  		*cs++ = i915_mmio_reg_offset(GEN7_L3LOG(slice, i));
  		*cs++ = remap_info[i];
drivers/gpu/drm/i915/i915_perf.c +5 -0
index c1b764233761..8b85cdfada21 100644
@@ -1693,6 +1693,11 @@ gen8_update_reg_state_unlocked(struct i915_perf_stream *stream,
  	};
  	int i;
 
+	/*
+	 * NB: The LRI instruction is generated by the hardware.
+	 * Should we read it in and assert that the offset flag is set?
+	 */
+
  	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
  		(stream->period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
  		(stream->periodic ? GEN8_OA_TIMER_ENABLE : 0) |

drivers/gpu/drm/i915/i915_perf.c gen8_load_flex(struct i915_request *rq, · line 1765

Quoted 10 lines
drivers/gpu/drm/i915/i915_perf.c +2 -1
@@ -1752,8 +1757,9 @@ gen8_load_flex(struct i915_request *rq,
  	if (IS_ERR(cs))
  		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(count);
+	*cs++ = MI_LOAD_REGISTER_IMM(count) | rq->engine->lri_cmd_mode;
  	do {
+		/* FIXME: Is this table LRI remap/offset friendly? */
  		*cs++ = i915_mmio_reg_offset(flex->reg);
  		*cs++ = flex->value;
  	} while (flex++, --count);

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#5 lore raw

PATCH 2/2 drm/i915: Engine relative MMIO for Gen12

In reply to [email protected]

From: John Harrison <[email protected]>

Gen12 introduces a completely new and different scheme for implementing engine relative MMIO accesses - MI_LRI_MMIO_REMAP. This requires using the base address of instance zero of the relevant engine class. And then, it is only valid if the register in question falls within a certain range as specified by a table.

v2: Add support for fused parts where instance zero of a given engine class may be missing. Make aux_tables presence a device flag rather than just hard coded. Pre-calculate the correct LRI base address rather than using a per-instance base and then adding on a delta to the correct base later. Make all the table range checking a debug only feature - the theory is that all driver access should be within the remap ranges. [Daniele]

v3: Re-base on Mika's changes. This removes all the abstraction layer. Which also means there is no common code path that all LRI accesses go via. Thus it is not possible to implement the range check. However, as noted in v2, the range check should not be necessary anyway.

CC Daniele Ceraolo Spurio <[email protected]>
---
 drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 27 +++++++++++++++++---
 drivers/gpu/drm/i915/gt/intel_engine_types.h |  1 +
 drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  9 ++++---
 drivers/gpu/drm/i915/gt/intel_mocs.c         |  6 ++---
 drivers/gpu/drm/i915/i915_perf.c             |  3 ++-
 drivers/gpu/drm/i915/intel_device_info.c     | 14 ++++++++++
 drivers/gpu/drm/i915/intel_device_info.h     |  1 +
 7 files changed, 49 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +23 -4
index 5aa58e069806..09fbbffce419 100644
@@ -247,14 +247,32 @@ static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
 	return true;
 }
 
-static void lri_init(struct intel_engine_cs *engine)
+static void lri_init(struct intel_engine_cs *engine, u32 first_instance)
 {
 	if (i915_engine_has_relative_lri(engine)) {
-		engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
-		engine->lri_mmio_base = 0;
+		if (INTEL_GEN(engine->i915) < 12) {
+			engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
+			engine->lri_mmio_base = 0;//engine->mmio_base;
+			engine->lri_engine = engine;
+		} else {
+			engine->lri_cmd_mode = MI_LRI_MMIO_REMAP_GEN12;
+
+			engine->lri_engine = engine->gt->engine_class
+						[engine->class][first_instance];
+			GEM_BUG_ON(!engine->lri_engine);
+			engine->lri_mmio_base = engine->lri_engine->mmio_base;
+
+			/* According to the bspec, accesses should be compared
+			 * against the remap table and remapping only enabled
+			 * if found. In practice, all driver accesses should be
+			 * to remap registers. So, no need for the complication
+			 * of checking against any device specific tables.
+			 */
+		}
 	} else {
 		engine->lri_cmd_mode = 0;
 		engine->lri_mmio_base = engine->mmio_base;
+		engine->lri_engine = engine;
 	}
 }
 
@@ -342,7 +360,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
 	/* Nothing to do here, execute in order of dependencies */
 	engine->schedule = NULL;
 
-	lri_init(engine);
+	lri_init(engine,
+		 INTEL_INFO(engine->i915)->first_instance[engine->class]);
 
 	seqlock_init(&engine->stats.lock);
 
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -0
index 38f486f7f7e3..62caa74e8558 100644
@@ -308,6 +308,7 @@ struct intel_engine_cs {
 
 	u32 lri_mmio_base;
 	u32 lri_cmd_mode;
+	struct intel_engine_cs *lri_engine;
 
 	u32 uabi_capabilities;
 
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +5 -4
index bfb51d8d7ce2..9c5be384026f 100644
@@ -133,15 +133,16 @@
  *   simply ignores the register load under certain conditions.
  * - One can actually load arbitrary many arbitrary registers: Simply issue x
  *   address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
- * - Newer hardware supports engine relative addressing but older hardware does
- *   not. This is required for hw engine load balancing. Hence the MI_LRI
- *   instruction itself is prefixed with '__' and should only be used on
- *   legacy hardware code paths. Generic code must always use the MI_LRI
+ * - Newer hardware supports engine relative addressing but using multiple
+ *   incompatible schemes. This is required for hw engine load balancing. Hence
+ *   the MI_LRI instruction itself is prefixed with '__' and should only be
+ *   used on legacy hardware code paths. Generic code must always use the MI_LRI
  *   and i915_get_lri_reg() helper functions instead.
  */
 #define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
 /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
 #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_MMIO_REMAP_GEN12		BIT(17)
 #define   MI_LRI_ADD_CS_MMIO_START_GEN11	BIT(19)
 #define MI_STORE_REGISTER_MEM        MI_INSTR(0x24, 1)
 #define MI_STORE_REGISTER_MEM_GEN8   MI_INSTR(0x24, 2)
drivers/gpu/drm/i915/gt/intel_mocs.c +3 -3
index 8e8fe3deb95c..e121fea5b33c 100644
@@ -438,7 +438,7 @@ static void intel_mocs_init_global(struct intel_gt *gt)
 static int emit_mocs_control_table(struct i915_request *rq,
 				   const struct drm_i915_mocs_table *table)
 {
-	enum intel_engine_id engine = rq->engine->id;
+	enum intel_engine_id engine_id = rq->engine->lri_engine->id;
 	unsigned int index;
 	u32 unused_value;
 	u32 *cs;
@@ -459,13 +459,13 @@ static int emit_mocs_control_table(struct i915_request *rq,
 	for (index = 0; index < table->size; index++) {
 		u32 value = get_entry_control(table, index);
 
-		*cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
+		*cs++ = i915_mmio_reg_offset(mocs_register(engine_id, index));
 		*cs++ = value;
 	}
 
 	/* All remaining entries are also unused */
 	for (; index < table->n_entries; index++) {
-		*cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
+		*cs++ = i915_mmio_reg_offset(mocs_register(engine_id, index));
 		*cs++ = unused_value;
 	}
 
drivers/gpu/drm/i915/i915_perf.c +2 -1
index 8b85cdfada21..fd628ae12343 100644
@@ -1695,7 +1695,8 @@ gen8_update_reg_state_unlocked(struct i915_perf_stream *stream,
 
 	/*
 	 * NB: The LRI instruction is generated by the hardware.
-	 * Should we read it in and assert that the offset flag is set?
+	 * Should we read it in and assert that the appropriate
+	 * offset flag is set?
 	 */
 
 	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
drivers/gpu/drm/i915/intel_device_info.c +14 -0
index 85e480bdc673..dece012d3ad4 100644
@@ -1030,6 +1030,7 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
 	u32 media_fuse;
 	u16 vdbox_mask;
 	u16 vebox_mask;
+	bool found;
 
 	if (INTEL_GEN(dev_priv) < 11)
 		return;
@@ -1040,6 +1041,7 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
 	vebox_mask = (media_fuse & GEN11_GT_VEBOX_DISABLE_MASK) >>
 		      GEN11_GT_VEBOX_DISABLE_SHIFT;
 
+	found = false;
 	for (i = 0; i < I915_MAX_VCS; i++) {
 		if (!HAS_ENGINE(dev_priv, _VCS(i))) {
 			vdbox_mask &= ~BIT(i);
@@ -1059,11 +1061,17 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
 		 */
 		if (IS_TIGERLAKE(dev_priv) || logical_vdbox++ % 2 == 0)
 			RUNTIME_INFO(dev_priv)->vdbox_sfc_access |= BIT(i);
+
+		if (!found) {
+			found = true;
+			info->first_instance[VIDEO_DECODE_CLASS] = i;
+		}
 	}
 	DRM_DEBUG_DRIVER("vdbox enable: %04x, instances: %04lx\n",
 			 vdbox_mask, VDBOX_MASK(dev_priv));
 	GEM_BUG_ON(vdbox_mask != VDBOX_MASK(dev_priv));
 
+	found = false;
 	for (i = 0; i < I915_MAX_VECS; i++) {
 		if (!HAS_ENGINE(dev_priv, _VECS(i))) {
 			vebox_mask &= ~BIT(i);
@@ -1073,6 +1081,12 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
 		if (!(BIT(i) & vebox_mask)) {
 			info->engine_mask &= ~BIT(_VECS(i));
 			DRM_DEBUG_DRIVER("vecs%u fused off\n", i);
+			continue;
+		}
+
+		if (!found) {
+			found = true;
+			info->first_instance[VIDEO_ENHANCEMENT_CLASS] = i;
 		}
 	}
 	DRM_DEBUG_DRIVER("vebox enable: %04x, instances: %04lx\n",
drivers/gpu/drm/i915/intel_device_info.h +1 -0
index 0cdc2465534b..75a9950969fb 100644
@@ -152,6 +152,7 @@ struct intel_device_info {
 	u8 gen;
 	u8 gt; /* GT number, 0 if undefined */
 	intel_engine_mask_t engine_mask; /* Engines supported by the HW */
+	u32 first_instance[MAX_ENGINE_CLASS]; /* instance 0 might be fused */
 
 	enum intel_platform platform;
 
Signature · 6 lines
2.21.0.5.gaeb582a983

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#6 lore raw

Re: [PATCH 2/2] drm/i915: Engine relative MMIO for Gen12

Quoted 40 lines · On 24/09/2019 00:51, [email protected] wrote:

From: John Harrison <[email protected]>

Gen12 introduces a completely new and different scheme for implementing engine relative MMIO accesses - MI_LRI_MMIO_REMAP. This requires using the base address of instance zero of the relevant engine class. And then, it is only valid if the register in question falls within a certain range as specified by a table.

v2: Add support for fused parts where instance zero of a given engine class may be missing. Make aux_tables presence a device flag rather than just hard coded. Pre-calculate the correct LRI base address rather than using a per-instance base and then adding on a delta to the correct base later. Make all the table range checking a debug only feature - the theory is that all driver access should be within the remap ranges. [Daniele]

v3: Re-base on Mika's changes. This removes all the abstraction layer. Which also means there is no common code path that all LRI accesses go via. Thus it is not possible to implement the range check. However, as noted in v2, the range check should not be necessary anyway.

CC Daniele Ceraolo Spurio <[email protected]>
---
  drivers/gpu/drm/i915/gt/intel_engine_cs.c    | 27 +++++++++++++++++---
  drivers/gpu/drm/i915/gt/intel_engine_types.h |  1 +
  drivers/gpu/drm/i915/gt/intel_gpu_commands.h |  9 ++++---
  drivers/gpu/drm/i915/gt/intel_mocs.c         |  6 ++---
  drivers/gpu/drm/i915/i915_perf.c             |  3 ++-
  drivers/gpu/drm/i915/intel_device_info.c     | 14 ++++++++++
  drivers/gpu/drm/i915/intel_device_info.h     |  1 +
  7 files changed, 49 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/gt/intel_engine_cs.c +0 -0
index 5aa58e069806..09fbbffce419 100644
@@ -247,14 +247,32 @@ static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
  	return true;
  }

drivers/gpu/drm/i915/gt/intel_engine_cs.c static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine) · line 255

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +4 -3
 
-static void lri_init(struct intel_engine_cs *engine)
+static void lri_init(struct intel_engine_cs *engine, u32 first_instance)
  {
  	if (i915_engine_has_relative_lri(engine)) {
-		engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
-		engine->lri_mmio_base = 0;
+		if (INTEL_GEN(engine->i915) < 12) {
+			engine->lri_cmd_mode = MI_LRI_ADD_CS_MMIO_START_GEN11;
+			engine->lri_mmio_base = 0;//engine->mmio_base;

No C++ style comments please.

drivers/gpu/drm/i915/gt/intel_engine_cs.c static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine) · line 265

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +10 -0
+			engine->lri_engine = engine;
+		} else {
+			engine->lri_cmd_mode = MI_LRI_MMIO_REMAP_GEN12;
+
+			engine->lri_engine = engine->gt->engine_class
+						[engine->class][first_instance];
+			GEM_BUG_ON(!engine->lri_engine);
+			engine->lri_mmio_base = engine->lri_engine->mmio_base;
+
+			/* According to the bspec, accesses should be compared

Preferred style:

/*
* Blah
*/

drivers/gpu/drm/i915/gt/intel_engine_cs.c static bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine) · line 276

Quoted 11 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +7 -0
+			 * against the remap table and remapping only enabled
+			 * if found. In practice, all driver accesses should be
+			 * to remap registers. So, no need for the complication
+			 * of checking against any device specific tables.
+			 */
+		}
  	} else {
  		engine->lri_cmd_mode = 0;
  		engine->lri_mmio_base = engine->mmio_base;
+		engine->lri_engine = engine;
  	}

If it helps at all you could save one indentation level by doing:

if (!supports_lri) {

} else if (GEN == 11) {

} else {

}

Quoted 29 lines
drivers/gpu/drm/i915/gt/intel_engine_cs.c +2 -1
  }
 
@@ -342,7 +360,8 @@ static int intel_engine_setup(struct intel_gt *gt, enum intel_engine_id id)
  	/* Nothing to do here, execute in order of dependencies */
  	engine->schedule = NULL;
 
-	lri_init(engine);
+	lri_init(engine,
+		 INTEL_INFO(engine->i915)->first_instance[engine->class]);
 
  	seqlock_init(&engine->stats.lock);
 
drivers/gpu/drm/i915/gt/intel_engine_types.h +1 -0
index 38f486f7f7e3..62caa74e8558 100644
@@ -308,6 +308,7 @@ struct intel_engine_cs {
 
  	u32 lri_mmio_base;
  	u32 lri_cmd_mode;
+	struct intel_engine_cs *lri_engine;
 
  	u32 uabi_capabilities;
 
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +0 -0
index bfb51d8d7ce2..9c5be384026f 100644

drivers/gpu/drm/i915/gt/intel_gpu_commands.h line 138

Quoted 10 lines
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +3 -4
@@ -133,15 +133,16 @@
   *   simply ignores the register load under certain conditions.
   * - One can actually load arbitrary many arbitrary registers: Simply issue x
   *   address/value pairs. Don't overdue it, though, x <= 2^4 must hold!
- * - Newer hardware supports engine relative addressing but older hardware does
- *   not. This is required for hw engine load balancing. Hence the MI_LRI
- *   instruction itself is prefixed with '__' and should only be used on
- *   legacy hardware code paths. Generic code must always use the MI_LRI
+ * - Newer hardware supports engine relative addressing but using multiple
+ *   incompatible schemes. This is required for hw engine load balancing. Hence
+ *   the MI_LRI instruction itself is prefixed with '__' and should only be

Is the double underscore reference out of date now?

Quoted 15 lines
drivers/gpu/drm/i915/gt/intel_gpu_commands.h +2 -0
+ *   used on legacy hardware code paths. Generic code must always use the MI_LRI
   *   and i915_get_lri_reg() helper functions instead.
   */
  #define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
  /* Gen11+. addr = base + (ctx_restore ? offset & GENMASK(12,2) : offset) */
  #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_MMIO_REMAP_GEN12		BIT(17)
  #define   MI_LRI_ADD_CS_MMIO_START_GEN11	BIT(19)
  #define MI_STORE_REGISTER_MEM        MI_INSTR(0x24, 1)
  #define MI_STORE_REGISTER_MEM_GEN8   MI_INSTR(0x24, 2)
drivers/gpu/drm/i915/gt/intel_mocs.c +0 -0
index 8e8fe3deb95c..e121fea5b33c 100644

drivers/gpu/drm/i915/gt/intel_mocs.c static void intel_mocs_init_global(struct intel_gt *gt) · line 441

Quoted 5 lines
drivers/gpu/drm/i915/gt/intel_mocs.c +1 -1
@@ -438,7 +438,7 @@ static void intel_mocs_init_global(struct intel_gt *gt)
  static int emit_mocs_control_table(struct i915_request *rq,
  				   const struct drm_i915_mocs_table *table)
  {
-	enum intel_engine_id engine = rq->engine->id;
+	enum intel_engine_id engine_id = rq->engine->lri_engine->id;

Observation: If you don't rename the local diff is smaller.

Quoted 89 lines
drivers/gpu/drm/i915/gt/intel_mocs.c +2 -2
  	unsigned int index;
  	u32 unused_value;
  	u32 *cs;
@@ -459,13 +459,13 @@ static int emit_mocs_control_table(struct i915_request *rq,
  	for (index = 0; index < table->size; index++) {
  		u32 value = get_entry_control(table, index);
 
-		*cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
+		*cs++ = i915_mmio_reg_offset(mocs_register(engine_id, index));
  		*cs++ = value;
  	}
 
  	/* All remaining entries are also unused */
  	for (; index < table->n_entries; index++) {
-		*cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
+		*cs++ = i915_mmio_reg_offset(mocs_register(engine_id, index));
  		*cs++ = unused_value;
  	}
 
drivers/gpu/drm/i915/i915_perf.c +2 -1
index 8b85cdfada21..fd628ae12343 100644
@@ -1695,7 +1695,8 @@ gen8_update_reg_state_unlocked(struct i915_perf_stream *stream,
 
  	/*
  	 * NB: The LRI instruction is generated by the hardware.
-	 * Should we read it in and assert that the offset flag is set?
+	 * Should we read it in and assert that the appropriate
+	 * offset flag is set?
  	 */
 
  	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
drivers/gpu/drm/i915/intel_device_info.c +14 -0
index 85e480bdc673..dece012d3ad4 100644
@@ -1030,6 +1030,7 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
  	u32 media_fuse;
  	u16 vdbox_mask;
  	u16 vebox_mask;
+	bool found;
 
  	if (INTEL_GEN(dev_priv) < 11)
  		return;
@@ -1040,6 +1041,7 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
  	vebox_mask = (media_fuse & GEN11_GT_VEBOX_DISABLE_MASK) >>
  		      GEN11_GT_VEBOX_DISABLE_SHIFT;
 
+	found = false;
  	for (i = 0; i < I915_MAX_VCS; i++) {
  		if (!HAS_ENGINE(dev_priv, _VCS(i))) {
  			vdbox_mask &= ~BIT(i);
@@ -1059,11 +1061,17 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
  		 */
  		if (IS_TIGERLAKE(dev_priv) || logical_vdbox++ % 2 == 0)
  			RUNTIME_INFO(dev_priv)->vdbox_sfc_access |= BIT(i);
+
+		if (!found) {
+			found = true;
+			info->first_instance[VIDEO_DECODE_CLASS] = i;
+		}
  	}
  	DRM_DEBUG_DRIVER("vdbox enable: %04x, instances: %04lx\n",
  			 vdbox_mask, VDBOX_MASK(dev_priv));
  	GEM_BUG_ON(vdbox_mask != VDBOX_MASK(dev_priv));
 
+	found = false;
  	for (i = 0; i < I915_MAX_VECS; i++) {
  		if (!HAS_ENGINE(dev_priv, _VECS(i))) {
  			vebox_mask &= ~BIT(i);
@@ -1073,6 +1081,12 @@ void intel_device_info_init_mmio(struct drm_i915_private *dev_priv)
  		if (!(BIT(i) & vebox_mask)) {
  			info->engine_mask &= ~BIT(_VECS(i));
  			DRM_DEBUG_DRIVER("vecs%u fused off\n", i);
+			continue;
+		}
+
+		if (!found) {
+			found = true;
+			info->first_instance[VIDEO_ENHANCEMENT_CLASS] = i;
  		}
  	}
  	DRM_DEBUG_DRIVER("vebox enable: %04x, instances: %04lx\n",
drivers/gpu/drm/i915/intel_device_info.h +0 -0
index 0cdc2465534b..75a9950969fb 100644

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info { · line 155

Quoted 4 lines
drivers/gpu/drm/i915/intel_device_info.h +1 -0
@@ -152,6 +152,7 @@ struct intel_device_info {
  	u8 gen;
  	u8 gt; /* GT number, 0 if undefined */
  	intel_engine_mask_t engine_mask; /* Engines supported by the HW */
+	u32 first_instance[MAX_ENGINE_CLASS]; /* instance 0 might be fused */

u32 is overkill however do you even need to store this persistently? Looks like all that is needed at runtime is engine->lri_engine? So you could lookup the first instance from intel_engine_setup. Or if I missed something and you do need it at runtime, then should go to runtime info since we want to avoid dependencies on mkwrite_device_info where possible.

drivers/gpu/drm/i915/intel_device_info.h struct intel_device_info {

Quoted 4 lines
drivers/gpu/drm/i915/intel_device_info.h +0 -0
  	enum intel_platform platform;
 
 

Regards,

Tvrtko

P.S. Just a superficial scan, not a normal review.
_______________________________________________
Intel-gfx mailing list [email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

✓ Fi.CI.BAT: success for drm/i915: Engine relative MMIO (rev9)

In reply to [email protected]
== Series Details ==

== Series Details ==

Series: drm/i915: Engine relative MMIO (rev9)
URL : https://patchwork.freedesktop.org/series/57117/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_6945 -> Patchwork_14509
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/

Known issues
------------

Here are the changes found in Patchwork_14509 that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_mmap_gtt@basic-write-cpu-read-gtt:
- fi-icl-u3: [PASS][1] -> [DMESG-WARN][2] ([fdo#107724]) +1 similar issue
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/fi-icl-u3/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/fi-icl-u3/igt@[email protected]

#### Possible fixes ####

* igt@gem_mmap_gtt@basic-read-write-distinct:
- fi-icl-u3: [DMESG-WARN][3] ([fdo#107724]) -> [PASS][4] +1 similar issue
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/fi-icl-u3/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/fi-icl-u3/igt@[email protected]

* igt@i915_module_load@reload:
- fi-icl-u3: [DMESG-WARN][5] ([fdo#107724] / [fdo#111214]) -> [PASS][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/fi-icl-u3/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/fi-icl-u3/igt@[email protected]

* igt@i915_selftest@live_execlists:
- fi-icl-u2: [DMESG-FAIL][7] ([fdo#111108]) -> [PASS][8]
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/fi-icl-u2/igt@i915_selftest@live_execlists.html
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/fi-icl-u2/igt@i915_selftest@live_execlists.html

* igt@i915_selftest@live_hangcheck:
- fi-kbl-7500u: [INCOMPLETE][9] ([fdo#108744]) -> [PASS][10]
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/fi-kbl-7500u/igt@i915_selftest@live_hangcheck.html
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/fi-kbl-7500u/igt@i915_selftest@live_hangcheck.html

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#107724]: https://bugs.freedesktop.org/show_bug.cgi?id=107724
[fdo#108744]: https://bugs.freedesktop.org/show_bug.cgi?id=108744
[fdo#111045]: https://bugs.freedesktop.org/show_bug.cgi?id=111045
[fdo#111096]: https://bugs.freedesktop.org/show_bug.cgi?id=111096
[fdo#111108]: https://bugs.freedesktop.org/show_bug.cgi?id=111108
[fdo#111214]: https://bugs.freedesktop.org/show_bug.cgi?id=111214

Participating hosts (54 -> 45)
------------------------------

Missing (9): fi-ilk-m540 fi-tgl-u fi-hsw-4200u fi-tgl-u2 fi-byt-squawks fi-bsw-cyan fi-icl-y fi-byt-clapper fi-bdw-samus

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_6945 -> Patchwork_14509

CI-20190529: 20190529
CI_DRM_6945: f11d819264a3fab210498a4920ef34a891da39e0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5197: aa534ff47fd2f455c8be9e59eae807695b87fcdd @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14509: 4f9d4f7b382c34dfd5f4ced2e713a225f9745878 @ git://anongit.freedesktop.org/gfx-ci/linux

== Linux commits ==

4f9d4f7b382c drm/i915: Engine relative MMIO for Gen12 d7d175dc43cd drm/i915: Engine relative MMIO

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/index.html
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

✗ Fi.CI.IGT: failure for drm/i915: Engine relative MMIO (rev9)

In reply to [email protected]
== Series Details ==

== Series Details ==

Series: drm/i915: Engine relative MMIO (rev9)
URL : https://patchwork.freedesktop.org/series/57117/
State : failure

== Summary ==

CI Bug Log - changes from CI_DRM_6945_full -> Patchwork_14509_full
====================================================

Summary
-------

**FAILURE**

Serious unknown changes coming with Patchwork_14509_full absolutely need to be verified manually.

If you think the reported changes have nothing to do with the changes introduced in Patchwork_14509_full, please notify your bug team to allow them to document this new failure mode, which will reduce false positives in CI.

Possible new issues
-------------------

Here are the unknown changes that may have been introduced in Patchwork_14509_full:

### IGT changes ###

#### Possible regressions ####

* igt@perf@blocking:
- shard-iclb: [PASS][1] -> [TIMEOUT][2] +2 similar issues
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb3/igt@[email protected]
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb6/igt@[email protected]

* igt@perf@oa-formats:
- shard-iclb: [PASS][3] -> [FAIL][4] +1 similar issue
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb8/igt@[email protected]
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb1/igt@[email protected]

* igt@prime_busy@basic-wait-after-default:
- shard-apl: [PASS][5] -> [WARN][6]
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-apl6/igt@[email protected]
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-apl8/igt@[email protected]

Known issues
------------

Here are the changes found in Patchwork_14509_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@gem_exec_schedule@in-order-bsd:
- shard-iclb: [PASS][7] -> [SKIP][8] ([fdo#111325]) +3 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb5/igt@[email protected]
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb4/igt@[email protected]

* igt@gem_exec_schedule@independent-bsd2:
- shard-iclb: [PASS][9] -> [SKIP][10] ([fdo#109276]) +12 similar issues
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb4/igt@[email protected]
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb5/igt@[email protected]

* igt@i915_suspend@sysfs-reader:
- shard-apl: [PASS][11] -> [DMESG-WARN][12] ([fdo#108566]) +4 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-apl4/igt@[email protected]
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-apl1/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-256x85-sliding:
- shard-apl: [PASS][13] -> [INCOMPLETE][14] ([fdo#103927]) +1 similar issue
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-apl1/igt@[email protected]
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-apl3/igt@[email protected]

* igt@kms_cursor_crc@pipe-a-cursor-suspend:
- shard-kbl: [PASS][15] -> [INCOMPLETE][16] ([fdo#103665])
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-kbl2/igt@[email protected]
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-kbl4/igt@[email protected]

* igt@kms_cursor_crc@pipe-b-cursor-128x42-random:
- shard-iclb: [PASS][17] -> [INCOMPLETE][18] ([fdo#107713])
[17]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb3/igt@[email protected]
[18]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb1/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-pwrite:
- shard-iclb: [PASS][19] -> [FAIL][20] ([fdo#103167]) +4 similar issues
[19]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb3/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-pwrite.html
[20]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb6/igt@kms_frontbuffer_tracking@fbcpsr-1p-primscrn-pri-indfb-draw-pwrite.html

* igt@kms_plane_alpha_blend@pipe-b-coverage-7efc:
- shard-skl: [PASS][21] -> [FAIL][22] ([fdo#108145] / [fdo#110403])
[21]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-skl2/igt@[email protected]
[22]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-skl2/igt@[email protected]

* igt@kms_psr@psr2_primary_page_flip:
- shard-iclb: [PASS][23] -> [SKIP][24] ([fdo#109441]) +1 similar issue
[23]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb2/igt@kms_psr@psr2_primary_page_flip.html
[24]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb7/igt@kms_psr@psr2_primary_page_flip.html

* igt@tools_test@tools_test:
- shard-hsw: [PASS][25] -> [SKIP][26] ([fdo#109271])
[25]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-hsw7/igt@tools_test@tools_test.html
[26]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-hsw5/igt@tools_test@tools_test.html

#### Possible fixes ####

* igt@gem_ctx_isolation@bcs0-s3:
- shard-apl: [DMESG-WARN][27] ([fdo#108566]) -> [PASS][28] +4 similar issues
[27]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-apl7/igt@[email protected]
[28]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-apl2/igt@[email protected]

* igt@gem_exec_capture@capture-bsd2:
- shard-iclb: [SKIP][29] ([fdo#109276]) -> [PASS][30] +12 similar issues
[29]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb6/igt@[email protected]
[30]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb1/igt@[email protected]

* igt@gem_exec_schedule@preempt-other-chain-bsd:
- shard-iclb: [SKIP][31] ([fdo#111325]) -> [PASS][32]
[31]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb1/igt@[email protected]
[32]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb8/igt@[email protected]

* igt@kms_flip@modeset-vs-vblank-race:
- shard-skl: [FAIL][33] ([fdo#111609]) -> [PASS][34]
[33]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-skl5/igt@[email protected]
[34]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-skl8/igt@[email protected]

* igt@kms_frontbuffer_tracking@fbc-1p-pri-indfb-multidraw:
- shard-iclb: [FAIL][35] ([fdo#103167]) -> [PASS][36] +3 similar issues
[35]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb7/igt@[email protected]
[36]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb8/igt@[email protected]

* igt@kms_plane_alpha_blend@pipe-c-coverage-7efc:
- shard-skl: [FAIL][37] ([fdo#108145] / [fdo#110403]) -> [PASS][38]
[37]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-skl10/igt@[email protected]
[38]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-skl10/igt@[email protected]

* igt@kms_psr@psr2_primary_blt:
- shard-iclb: [SKIP][39] ([fdo#109441]) -> [PASS][40] +1 similar issue
[39]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb7/igt@kms_psr@psr2_primary_blt.html
[40]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb2/igt@kms_psr@psr2_primary_blt.html

#### Warnings ####

* igt@gem_ctx_isolation@vcs1-nonpriv:
- shard-iclb: [FAIL][41] ([fdo#111329]) -> [SKIP][42] ([fdo#109276])
[41]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb1/igt@[email protected]
[42]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb8/igt@[email protected]

* igt@gem_mocs_settings@mocs-isolation-bsd2:
- shard-iclb: [SKIP][43] ([fdo#109276]) -> [FAIL][44] ([fdo#111330])
[43]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-iclb6/igt@[email protected]
[44]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-iclb1/igt@[email protected]

* igt@i915_suspend@forcewake:
- shard-apl: [DMESG-WARN][45] ([fdo#108566]) -> [INCOMPLETE][46] ([fdo#103927])
[45]: https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_6945/shard-apl7/igt@[email protected]
[46]: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/shard-apl1/igt@[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#103167]: https://bugs.freedesktop.org/show_bug.cgi?id=103167
[fdo#103665]: https://bugs.freedesktop.org/show_bug.cgi?id=103665
[fdo#103927]: https://bugs.freedesktop.org/show_bug.cgi?id=103927
[fdo#107713]: https://bugs.freedesktop.org/show_bug.cgi?id=107713
[fdo#108145]: https://bugs.freedesktop.org/show_bug.cgi?id=108145
[fdo#108566]: https://bugs.freedesktop.org/show_bug.cgi?id=108566
[fdo#109271]: https://bugs.freedesktop.org/show_bug.cgi?id=109271
[fdo#109276]: https://bugs.freedesktop.org/show_bug.cgi?id=109276
[fdo#109441]: https://bugs.freedesktop.org/show_bug.cgi?id=109441
[fdo#110403]: https://bugs.freedesktop.org/show_bug.cgi?id=110403
[fdo#110548]: https://bugs.freedesktop.org/show_bug.cgi?id=110548
[fdo#111325]: https://bugs.freedesktop.org/show_bug.cgi?id=111325
[fdo#111329]: https://bugs.freedesktop.org/show_bug.cgi?id=111329
[fdo#111330]: https://bugs.freedesktop.org/show_bug.cgi?id=111330
[fdo#111609]: https://bugs.freedesktop.org/show_bug.cgi?id=111609

Participating hosts (9 -> 9)
------------------------------

No changes in participating hosts

Build changes
-------------

* CI: CI-20190529 -> None
* Linux: CI_DRM_6945 -> Patchwork_14509

CI-20190529: 20190529
CI_DRM_6945: f11d819264a3fab210498a4920ef34a891da39e0 @ git://anongit.freedesktop.org/gfx-ci/linux
IGT_5197: aa534ff47fd2f455c8be9e59eae807695b87fcdd @ git://anongit.freedesktop.org/xorg/app/intel-gpu-tools
Patchwork_14509: 4f9d4f7b382c34dfd5f4ced2e713a225f9745878 @ git://anongit.freedesktop.org/gfx-ci/linux
piglit_4509: fdc5a4ca11124ab8413c7988896eec4c97336694 @ git://anongit.freedesktop.org/piglit

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_14509/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx