Skip to contentSkip to conversation

drm/i915: Engine relative MMIO

PATCH New [email protected] 3 participants 3 messages Mar 19, 2019 – Mar 20, 2019

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

PATCH 1/1 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].

---
 drivers/gpu/drm/i915/gvt/mmio_context.c    | 16 ++++--
 drivers/gpu/drm/i915/i915_cmd_parser.c     |  4 +-
 drivers/gpu/drm/i915/i915_gem_execbuffer.c |  4 +-
 drivers/gpu/drm/i915/i915_perf.c           | 19 ++++---
 drivers/gpu/drm/i915/intel_engine_cs.c     | 11 ++++
 drivers/gpu/drm/i915/intel_gpu_commands.h  |  6 ++-
 drivers/gpu/drm/i915/intel_lrc.c           | 80 ++++++++++++++++--------------
 drivers/gpu/drm/i915/intel_lrc_reg.h       |  4 +-
 drivers/gpu/drm/i915/intel_mocs.c          | 17 ++++---
 drivers/gpu/drm/i915/intel_ringbuffer.c    | 45 ++++++++++++++---
 drivers/gpu/drm/i915/intel_ringbuffer.h    |  4 ++
 drivers/gpu/drm/i915/intel_workarounds.c   |  4 +-
 12 files changed, 143 insertions(+), 71 deletions(-)
drivers/gpu/drm/i915/gvt/mmio_context.c +12 -4
index f64c76dd11d4..a62f4214ad32 100644
@@ -199,14 +199,14 @@ restore_context_mmio_for_inhibit(struct intel_vgpu *vgpu,
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(count);
+	*cs++ = i915_get_lri_cmd(req->engine, count);
 	for (mmio = gvt->engine_mmio_list.mmio;
 	     i915_mmio_reg_valid(mmio->reg); mmio++) {
 		if (mmio->ring_id != ring_id ||
 		    !mmio->in_context)
 			continue;
 
-		*cs++ = i915_mmio_reg_offset(mmio->reg);
+		*cs++ = i915_get_lri_reg(req->engine, mmio->reg);
 		*cs++ = vgpu_vreg_t(vgpu, mmio->reg) |
 				(mmio->mask << 16);
 		gvt_dbg_core("add lri reg pair 0x%x:0x%x in inhibit ctx, vgpu:%d, rind_id:%d\n",
@@ -234,7 +234,11 @@ restore_render_mocs_control_for_inhibit(struct intel_vgpu *vgpu,
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(GEN9_MOCS_SIZE);
+	/*
+	 * GEN9_GFX_MOCS is not engine relative, therefore there is no
+	 * need for relative addressing.
+	 */
+	*cs++ = __MI_LOAD_REGISTER_IMM(GEN9_MOCS_SIZE);
 
 	for (index = 0; index < GEN9_MOCS_SIZE; index++) {
 		*cs++ = i915_mmio_reg_offset(GEN9_GFX_MOCS(index));
@@ -261,7 +265,11 @@ restore_render_mocs_l3cc_for_inhibit(struct intel_vgpu *vgpu,
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(GEN9_MOCS_SIZE / 2);
+	/*
+	 * GEN9_LNCFCMOCS is not engine relative, therefore there is no
+	 * need for relative addressing.
+	 */
+	*cs++ = __MI_LOAD_REGISTER_IMM(GEN9_MOCS_SIZE / 2);
 
 	for (index = 0; index < GEN9_MOCS_SIZE / 2; index++) {
 		*cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(index));
drivers/gpu/drm/i915/i915_cmd_parser.c +2 -2
index 503d548a55f7..91ebe18aacc6 100644
@@ -220,7 +220,7 @@ static const struct drm_i915_cmd_descriptor common_cmds[] = {
 	CMD(  MI_SUSPEND_FLUSH,                 SMI,    F,  1,      S  ),
 	CMD(  MI_SEMAPHORE_MBOX,                SMI,   !F,  0xFF,   R  ),
 	CMD(  MI_STORE_DWORD_INDEX,             SMI,   !F,  0xFF,   R  ),
-	CMD(  MI_LOAD_REGISTER_IMM(1),          SMI,   !F,  0xFF,   W,
+	CMD(  __MI_LOAD_REGISTER_IMM(1),        SMI,   !F,  0xFF,   W,
 	      .reg = { .offset = 1, .mask = 0x007FFFFC, .step = 2 }    ),
 	CMD(  MI_STORE_REGISTER_MEM,            SMI,    F,  3,     W | B,
 	      .reg = { .offset = 1, .mask = 0x007FFFFC },
@@ -1182,7 +1182,7 @@ static bool check_cmd(const struct intel_engine_cs *engine,
 					return false;
 				}
 
-				if (desc->cmd.value == MI_LOAD_REGISTER_IMM(1) &&
+				if (desc->cmd.value == __MI_LOAD_REGISTER_IMM(1) &&
 				    (offset + 2 > length ||
 				     (cmd[offset + 1] & reg->mask) != reg->value)) {
 					DRM_DEBUG_DRIVER("CMD: Rejected LRI to masked register 0x%08X\n",
drivers/gpu/drm/i915/i915_gem_execbuffer.c +2 -2
index ee6d301a9627..a16363e59935 100644
@@ -1966,9 +1966,9 @@ static int i915_reset_gen7_sol_offsets(struct i915_request *rq)
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(4);
+	*cs++ = i915_get_lri_cmd(rq->engine, 4);
 	for (i = 0; i < 4; i++) {
-		*cs++ = i915_mmio_reg_offset(GEN7_SO_WRITE_OFFSET(i));
+		*cs++ = i915_get_lri_reg(rq->engine, GEN7_SO_WRITE_OFFSET(i));
 		*cs++ = 0;
 	}
 	*cs++ = MI_NOOP;
drivers/gpu/drm/i915/i915_perf.c +13 -6
index 9b0292a38865..9f25b5972e19 100644
@@ -1630,7 +1630,8 @@ static void hsw_disable_metric_set(struct drm_i915_private *dev_priv)
  * in the case that the OA unit has been disabled.
  */
 static void
-gen8_update_reg_state_unlocked(struct intel_context *ce,
+gen8_update_reg_state_unlocked(struct intel_engine_cs *engine,
+			       struct intel_context *ce,
 			       u32 *reg_state,
 			       const struct i915_oa_config *oa_config)
 {
@@ -1649,7 +1650,12 @@ gen8_update_reg_state_unlocked(struct intel_context *ce,
 	};
 	int i;
 
-	CTX_REG(reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
+	/*
+	 * NB: The LRI instruction is generated by the hardware.
+	 * Should we read it in and assert that the offset flag is set?
+	 */
+
+	CTX_REG(engine, reg_state, ctx_oactxctrl, GEN8_OACTXCONTROL,
 		(i915->perf.oa.period_exponent << GEN8_OA_TIMER_PERIOD_SHIFT) |
 		(i915->perf.oa.periodic ? GEN8_OA_TIMER_ENABLE : 0) |
 		GEN8_OA_COUNTER_RESUME);
@@ -1676,10 +1682,10 @@ gen8_update_reg_state_unlocked(struct intel_context *ce,
 			}
 		}
 
-		CTX_REG(reg_state, state_offset, flex_regs[i], value);
+		CTX_REG(engine, reg_state, state_offset, flex_regs[i], value);
 	}
 
-	CTX_REG(reg_state,
+	CTX_REG(engine, reg_state,
 		CTX_R_PWR_CLK_STATE, GEN8_R_PWR_CLK_STATE,
 		gen8_make_rpcs(i915, &ce->sseu));
 }
@@ -1754,7 +1760,7 @@ static int gen8_configure_all_contexts(struct drm_i915_private *dev_priv,
 		ce->state->obj->mm.dirty = true;
 		regs += LRC_STATE_PN * PAGE_SIZE / sizeof(*regs);
 
-		gen8_update_reg_state_unlocked(ce, regs, oa_config);
+		gen8_update_reg_state_unlocked(engine, ce, regs, oa_config);
 
 		i915_gem_object_unpin_map(ce->state->obj);
 	}
@@ -2148,7 +2154,8 @@ void i915_oa_init_reg_state(struct intel_engine_cs *engine,
 
 	stream = engine->i915->perf.oa.exclusive_stream;
 	if (stream)
-		gen8_update_reg_state_unlocked(ce, regs, stream->oa_config);
+		gen8_update_reg_state_unlocked(engine, ce, regs,
+					       stream->oa_config);
 }
 
 /**
drivers/gpu/drm/i915/intel_engine_cs.c +11 -0
index 652c1b3ba190..ba9d86a463d1 100644
@@ -246,6 +246,17 @@ static u32 __engine_mmio_base(struct drm_i915_private *i915,
 	return bases[i].base;
 }
 
+bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine)
+{
+	if (INTEL_GEN(engine->i915) < 11)
+		return false;
+
+	if (engine->id == BCS0)
+		return false;
+
+	return true;
+}
+
 static void __sprint_engine_name(char *name, const struct engine_info *info)
 {
 	WARN_ON(snprintf(name, INTEL_ENGINE_CS_MAX_NAME, "%s%u",
drivers/gpu/drm/i915/intel_gpu_commands.h +5 -1
index a34ece53a771..97c2cfd1d38f 100644
@@ -123,9 +123,13 @@
  *   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 addresses but older hardware does
+ *   not. So never call MI_LRI directly, always use the i915_get_lri_cmd()
+ *   and i915_get_lri_reg() helper functions.
  */
-#define MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
+#define __MI_LOAD_REGISTER_IMM(x)	MI_INSTR(0x22, 2*(x)-1)
 #define   MI_LRI_FORCE_POSTED		(1<<12)
+#define   MI_LRI_ADD_CS_MMIO_START	(1<<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/intel_lrc.c +43 -37

149 lines not on this page · raw message

drivers/gpu/drm/i915/intel_lrc_reg.h +2 -2
index 5ef932d810a7..40b1142d0d74 100644
@@ -39,10 +39,10 @@
 #define CTX_R_PWR_CLK_STATE		0x42
 #define CTX_END				0x44
 
-#define CTX_REG(reg_state, pos, reg, val) do { \
+#define CTX_REG(engine, reg_state, pos, reg, val) do { \
 	u32 *reg_state__ = (reg_state); \
 	const u32 pos__ = (pos); \
-	(reg_state__)[(pos__) + 0] = i915_mmio_reg_offset(reg); \
+	(reg_state__)[(pos__) + 0] = i915_get_lri_reg((engine), (reg)); \
 	(reg_state__)[(pos__) + 1] = (val); \
 } while (0)
 
drivers/gpu/drm/i915/intel_mocs.c +10 -7
index 274ba78500c0..bb11d0f68bba 100644
@@ -322,9 +322,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)
 {
@@ -378,18 +375,20 @@ 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++ = i915_get_lri_cmd(rq->engine, table->n_entries);
 
 	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_get_lri_reg(rq->engine,
+					 mocs_register(engine, 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_get_lri_reg(rq->engine,
+					 mocs_register(engine, index));
 		*cs++ = unused_value;
 	}
 
@@ -447,7 +446,11 @@ static int emit_mocs_l3cc_table(struct i915_request *rq,
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(table->n_entries / 2);
+	/*
+	 * GEN9_LNCFCMOCS is not engine relative, therefore there is no
+	 * need for relative addressing?
+	 */
+	*cs++ = __MI_LOAD_REGISTER_IMM(table->n_entries / 2);
 
 	for (i = 0; i < table->size / 2; i++) {
 		u16 low = get_entry_l3cc(table, 2 * i);
drivers/gpu/drm/i915/intel_ringbuffer.c +37 -8

75 lines not on this page · raw message

drivers/gpu/drm/i915/intel_ringbuffer.h +4 -0
index e612bdca9fd9..a4dfed253edd 100644
@@ -549,4 +549,8 @@ intel_engine_get_hangcheck_seqno(struct intel_engine_cs *engine)
 	return intel_read_status_page(engine, I915_GEM_HWS_HANGCHECK);
 }
 
+bool i915_engine_has_relative_lri(const struct intel_engine_cs *engine);
+u32 i915_get_lri_cmd(const struct intel_engine_cs *engine, u32 word_count);
+u32 i915_get_lri_reg(const struct intel_engine_cs *engine, i915_reg_t reg);
+
 #endif /* _INTEL_RINGBUFFER_H_ */
drivers/gpu/drm/i915/intel_workarounds.c +2 -2
index 283e9a4ef3ca..53b7109e286d 100644
@@ -614,9 +614,9 @@ int intel_engine_emit_ctx_wa(struct i915_request *rq)
 	if (IS_ERR(cs))
 		return PTR_ERR(cs);
 
-	*cs++ = MI_LOAD_REGISTER_IMM(wal->count);
+	*cs++ = i915_get_lri_cmd(rq->engine, wal->count);
 	for (i = 0, wa = wal->list; i < wal->count; i++, wa++) {
-		*cs++ = i915_mmio_reg_offset(wa->reg);
+		*cs++ = i915_get_lri_reg(rq->engine, wa->reg);
 		*cs++ = wa->val;
 	}
 	*cs++ = MI_NOOP;
Signature · 6 lines
2.16.1

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

✗ Fi.CI.BAT: failure for drm/i915: Engine relative MMIO (rev2)

== Series Details ==

== Series Details ==

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

== Summary ==

CALL scripts/checksyscalls.sh
CALL scripts/atomic/check-atomics.sh
DESCEND objtool
CHK include/generated/compile.h
CC [M] drivers/gpu/drm/i915/intel_workarounds.o
In file included from drivers/gpu/drm/i915/intel_workarounds.c:1260:0:
drivers/gpu/drm/i915/selftests/intel_workarounds.c: In function ‘check_dirty_whitelist’:
drivers/gpu/drm/i915/selftests/intel_workarounds.c:520:12: error: implicit declaration of function ‘MI_LOAD_REGISTER_IMM’; did you mean ‘__MI_LOAD_REGISTER_IMM’? [-Werror=implicit-function-declaration]

    *cs++ = MI_LOAD_REGISTER_IMM(1);
            ^~~~~~~~~~~~~~~~~~~~
            __MI_LOAD_REGISTER_IMM

cc1: all warnings being treated as errors
scripts/Makefile.build:278: recipe for target 'drivers/gpu/drm/i915/intel_workarounds.o' failed make[5]: *** [drivers/gpu/drm/i915/intel_workarounds.o] Error 1 scripts/Makefile.build:489: recipe for target 'drivers/gpu/drm/i915' failed make[4]: *** [drivers/gpu/drm/i915] Error 2
scripts/Makefile.build:489: recipe for target 'drivers/gpu/drm' failed
make[3]: *** [drivers/gpu/drm] Error 2
scripts/Makefile.build:489: recipe for target 'drivers/gpu' failed
make[2]: *** [drivers/gpu] Error 2
/home/cidrm/kernel/Makefile:1046: recipe for target 'drivers' failed
make[1]: *** [drivers] Error 2
Makefile:170: recipe for target 'sub-make' failed
make: *** [sub-make] Error 2

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

#2 lore raw
In reply to [email protected]
Thank you for the patch! Yet something to improve:

Hi,

Thank you for the patch! Yet something to improve:

[auto build test ERROR on drm-intel/for-linux-next]
[also build test ERROR on next-20190320]
[cannot apply to v5.1-rc1]
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system]

url:    https://github.com/0day-ci/linux/commits/John-C-Harrison-Intel-com/drm-i915-Engine-relative-MMIO/20190320-141647
base:   git://anongit.freedesktop.org/drm-intel for-linux-next
config: i386-randconfig-s0-201911 (attached as .config)
compiler: gcc-6 (Debian 6.4.0-9) 6.4.0 20171026
reproduce:
        # save the attached .config to linux build tree
        make ARCH=i386 

All errors (new ones prefixed by >>):

In file included from drivers/gpu/drm/i915/intel_workarounds.c:1260:0:
drivers/gpu/drm/i915/selftests/intel_workarounds.c: In function 'check_dirty_whitelist':

>> drivers/gpu/drm/i915/selftests/intel_workarounds.c:520:12: error: implicit declaration of function 'MI_LOAD_REGISTER_IMM' [-Werror=implicit-function-declaration]
       *cs++ = MI_LOAD_REGISTER_IMM(1);
               ^~~~~~~~~~~~~~~~~~~~

cc1: some warnings being treated as errors

vim +/MI_LOAD_REGISTER_IMM +520 drivers/gpu/drm/i915/selftests/intel_workarounds.c

34ae8455 Chris Wilson 2019-03-01  441  
34ae8455 Chris Wilson 2019-03-01  442  static int check_dirty_whitelist(struct i915_gem_context *ctx,
34ae8455 Chris Wilson 2019-03-01  443  				 struct intel_engine_cs *engine)
34ae8455 Chris Wilson 2019-03-01  444  {
34ae8455 Chris Wilson 2019-03-01  445  	const u32 values[] = {
34ae8455 Chris Wilson 2019-03-01  446  		0x00000000,
34ae8455 Chris Wilson 2019-03-01  447  		0x01010101,
34ae8455 Chris Wilson 2019-03-01  448  		0x10100101,
34ae8455 Chris Wilson 2019-03-01  449  		0x03030303,
34ae8455 Chris Wilson 2019-03-01  450  		0x30300303,
34ae8455 Chris Wilson 2019-03-01  451  		0x05050505,
34ae8455 Chris Wilson 2019-03-01  452  		0x50500505,
34ae8455 Chris Wilson 2019-03-01  453  		0x0f0f0f0f,
34ae8455 Chris Wilson 2019-03-01  454  		0xf00ff00f,
34ae8455 Chris Wilson 2019-03-01  455  		0x10101010,
34ae8455 Chris Wilson 2019-03-01  456  		0xf0f01010,
34ae8455 Chris Wilson 2019-03-01  457  		0x30303030,
34ae8455 Chris Wilson 2019-03-01  458  		0xa0a03030,
34ae8455 Chris Wilson 2019-03-01  459  		0x50505050,
34ae8455 Chris Wilson 2019-03-01  460  		0xc0c05050,
34ae8455 Chris Wilson 2019-03-01  461  		0xf0f0f0f0,
34ae8455 Chris Wilson 2019-03-01  462  		0x11111111,
34ae8455 Chris Wilson 2019-03-01  463  		0x33333333,
34ae8455 Chris Wilson 2019-03-01  464  		0x55555555,
34ae8455 Chris Wilson 2019-03-01  465  		0x0000ffff,
34ae8455 Chris Wilson 2019-03-01  466  		0x00ff00ff,
34ae8455 Chris Wilson 2019-03-01  467  		0xff0000ff,
34ae8455 Chris Wilson 2019-03-01  468  		0xffff00ff,
34ae8455 Chris Wilson 2019-03-01  469  		0xffffffff,
34ae8455 Chris Wilson 2019-03-01  470  	};
34ae8455 Chris Wilson 2019-03-01  471  	struct i915_vma *scratch;
34ae8455 Chris Wilson 2019-03-01  472  	struct i915_vma *batch;
34ae8455 Chris Wilson 2019-03-01  473  	int err = 0, i, v;
34ae8455 Chris Wilson 2019-03-01  474  	u32 *cs, *results;
34ae8455 Chris Wilson 2019-03-01  475  
34ae8455 Chris Wilson 2019-03-01  476  	scratch = create_scratch(ctx);
34ae8455 Chris Wilson 2019-03-01  477  	if (IS_ERR(scratch))
34ae8455 Chris Wilson 2019-03-01  478  		return PTR_ERR(scratch);
34ae8455 Chris Wilson 2019-03-01  479  
34ae8455 Chris Wilson 2019-03-01  480  	batch = create_batch(ctx);
34ae8455 Chris Wilson 2019-03-01  481  	if (IS_ERR(batch)) {
34ae8455 Chris Wilson 2019-03-01  482  		err = PTR_ERR(batch);
34ae8455 Chris Wilson 2019-03-01  483  		goto out_scratch;
34ae8455 Chris Wilson 2019-03-01  484  	}
34ae8455 Chris Wilson 2019-03-01  485  
34ae8455 Chris Wilson 2019-03-01  486  	for (i = 0; i < engine->whitelist.count; i++) {
34ae8455 Chris Wilson 2019-03-01  487  		u32 reg = i915_mmio_reg_offset(engine->whitelist.list[i].reg);
34ae8455 Chris Wilson 2019-03-01  488  		u64 addr = scratch->node.start;
34ae8455 Chris Wilson 2019-03-01  489  		struct i915_request *rq;
34ae8455 Chris Wilson 2019-03-01  490  		u32 srm, lrm, rsvd;
34ae8455 Chris Wilson 2019-03-01  491  		u32 expect;
34ae8455 Chris Wilson 2019-03-01  492  		int idx;
34ae8455 Chris Wilson 2019-03-01  493  
34ae8455 Chris Wilson 2019-03-01  494  		if (wo_register(engine, reg))
34ae8455 Chris Wilson 2019-03-01  495  			continue;
34ae8455 Chris Wilson 2019-03-01  496  
34ae8455 Chris Wilson 2019-03-01  497  		srm = MI_STORE_REGISTER_MEM;
34ae8455 Chris Wilson 2019-03-01  498  		lrm = MI_LOAD_REGISTER_MEM;
34ae8455 Chris Wilson 2019-03-01  499  		if (INTEL_GEN(ctx->i915) >= 8)
34ae8455 Chris Wilson 2019-03-01  500  			lrm++, srm++;
34ae8455 Chris Wilson 2019-03-01  501  
34ae8455 Chris Wilson 2019-03-01  502  		pr_debug("%s: Writing garbage to %x\n",
34ae8455 Chris Wilson 2019-03-01  503  			 engine->name, reg);
34ae8455 Chris Wilson 2019-03-01  504  
34ae8455 Chris Wilson 2019-03-01  505  		cs = i915_gem_object_pin_map(batch->obj, I915_MAP_WC);
34ae8455 Chris Wilson 2019-03-01  506  		if (IS_ERR(cs)) {
34ae8455 Chris Wilson 2019-03-01  507  			err = PTR_ERR(cs);
34ae8455 Chris Wilson 2019-03-01  508  			goto out_batch;
34ae8455 Chris Wilson 2019-03-01  509  		}
34ae8455 Chris Wilson 2019-03-01  510  
34ae8455 Chris Wilson 2019-03-01  511  		/* SRM original */
34ae8455 Chris Wilson 2019-03-01  512  		*cs++ = srm;
34ae8455 Chris Wilson 2019-03-01  513  		*cs++ = reg;
34ae8455 Chris Wilson 2019-03-01  514  		*cs++ = lower_32_bits(addr);
34ae8455 Chris Wilson 2019-03-01  515  		*cs++ = upper_32_bits(addr);
34ae8455 Chris Wilson 2019-03-01  516  
34ae8455 Chris Wilson 2019-03-01  517  		idx = 1;
34ae8455 Chris Wilson 2019-03-01  518  		for (v = 0; v < ARRAY_SIZE(values); v++) {
34ae8455 Chris Wilson 2019-03-01  519  			/* LRI garbage */
34ae8455 Chris Wilson 2019-03-01 @520  			*cs++ = MI_LOAD_REGISTER_IMM(1);
34ae8455 Chris Wilson 2019-03-01  521  			*cs++ = reg;
34ae8455 Chris Wilson 2019-03-01  522  			*cs++ = values[v];
34ae8455 Chris Wilson 2019-03-01  523  
34ae8455 Chris Wilson 2019-03-01  524  			/* SRM result */
34ae8455 Chris Wilson 2019-03-01  525  			*cs++ = srm;
34ae8455 Chris Wilson 2019-03-01  526  			*cs++ = reg;
34ae8455 Chris Wilson 2019-03-01  527  			*cs++ = lower_32_bits(addr + sizeof(u32) * idx);
34ae8455 Chris Wilson 2019-03-01  528  			*cs++ = upper_32_bits(addr + sizeof(u32) * idx);
34ae8455 Chris Wilson 2019-03-01  529  			idx++;
34ae8455 Chris Wilson 2019-03-01  530  		}
34ae8455 Chris Wilson 2019-03-01  531  		for (v = 0; v < ARRAY_SIZE(values); v++) {
34ae8455 Chris Wilson 2019-03-01  532  			/* LRI garbage */
34ae8455 Chris Wilson 2019-03-01  533  			*cs++ = MI_LOAD_REGISTER_IMM(1);
34ae8455 Chris Wilson 2019-03-01  534  			*cs++ = reg;
34ae8455 Chris Wilson 2019-03-01  535  			*cs++ = ~values[v];
34ae8455 Chris Wilson 2019-03-01  536  
34ae8455 Chris Wilson 2019-03-01  537  			/* SRM result */
34ae8455 Chris Wilson 2019-03-01  538  			*cs++ = srm;
34ae8455 Chris Wilson 2019-03-01  539  			*cs++ = reg;
34ae8455 Chris Wilson 2019-03-01  540  			*cs++ = lower_32_bits(addr + sizeof(u32) * idx);
34ae8455 Chris Wilson 2019-03-01  541  			*cs++ = upper_32_bits(addr + sizeof(u32) * idx);
34ae8455 Chris Wilson 2019-03-01  542  			idx++;
34ae8455 Chris Wilson 2019-03-01  543  		}
34ae8455 Chris Wilson 2019-03-01  544  		GEM_BUG_ON(idx * sizeof(u32) > scratch->size);
34ae8455 Chris Wilson 2019-03-01  545  
34ae8455 Chris Wilson 2019-03-01  546  		/* LRM original -- don't leave garbage in the context! */
34ae8455 Chris Wilson 2019-03-01  547  		*cs++ = lrm;
34ae8455 Chris Wilson 2019-03-01  548  		*cs++ = reg;
34ae8455 Chris Wilson 2019-03-01  549  		*cs++ = lower_32_bits(addr);
34ae8455 Chris Wilson 2019-03-01  550  		*cs++ = upper_32_bits(addr);
34ae8455 Chris Wilson 2019-03-01  551  
34ae8455 Chris Wilson 2019-03-01  552  		*cs++ = MI_BATCH_BUFFER_END;
34ae8455 Chris Wilson 2019-03-01  553  
34ae8455 Chris Wilson 2019-03-01  554  		i915_gem_object_unpin_map(batch->obj);
34ae8455 Chris Wilson 2019-03-01  555  		i915_gem_chipset_flush(ctx->i915);
34ae8455 Chris Wilson 2019-03-01  556  
34ae8455 Chris Wilson 2019-03-01  557  		rq = i915_request_alloc(engine, ctx);
34ae8455 Chris Wilson 2019-03-01  558  		if (IS_ERR(rq)) {
34ae8455 Chris Wilson 2019-03-01  559  			err = PTR_ERR(rq);
34ae8455 Chris Wilson 2019-03-01  560  			goto out_batch;
34ae8455 Chris Wilson 2019-03-01  561  		}
34ae8455 Chris Wilson 2019-03-01  562  
34ae8455 Chris Wilson 2019-03-01  563  		if (engine->emit_init_breadcrumb) { /* Be nice if we hang */
34ae8455 Chris Wilson 2019-03-01  564  			err = engine->emit_init_breadcrumb(rq);
34ae8455 Chris Wilson 2019-03-01  565  			if (err)
34ae8455 Chris Wilson 2019-03-01  566  				goto err_request;
34ae8455 Chris Wilson 2019-03-01  567  		}
34ae8455 Chris Wilson 2019-03-01  568  
34ae8455 Chris Wilson 2019-03-01  569  		err = engine->emit_bb_start(rq,
34ae8455 Chris Wilson 2019-03-01  570  					    batch->node.start, PAGE_SIZE,
34ae8455 Chris Wilson 2019-03-01  571  					    0);
34ae8455 Chris Wilson 2019-03-01  572  		if (err)
34ae8455 Chris Wilson 2019-03-01  573  			goto err_request;
34ae8455 Chris Wilson 2019-03-01  574  
34ae8455 Chris Wilson 2019-03-01  575  err_request:
34ae8455 Chris Wilson 2019-03-01  576  		i915_request_add(rq);
34ae8455 Chris Wilson 2019-03-01  577  		if (err)
34ae8455 Chris Wilson 2019-03-01  578  			goto out_batch;
34ae8455 Chris Wilson 2019-03-01  579  
34ae8455 Chris Wilson 2019-03-01  580  		if (i915_request_wait(rq, I915_WAIT_LOCKED, HZ / 5) < 0) {
34ae8455 Chris Wilson 2019-03-01  581  			pr_err("%s: Futzing %x timedout; cancelling test\n",
34ae8455 Chris Wilson 2019-03-01  582  			       engine->name, reg);
34ae8455 Chris Wilson 2019-03-01  583  			i915_gem_set_wedged(ctx->i915);
34ae8455 Chris Wilson 2019-03-01  584  			err = -EIO;
34ae8455 Chris Wilson 2019-03-01  585  			goto out_batch;
34ae8455 Chris Wilson 2019-03-01  586  		}
34ae8455 Chris Wilson 2019-03-01  587  
34ae8455 Chris Wilson 2019-03-01  588  		results = i915_gem_object_pin_map(scratch->obj, I915_MAP_WB);
34ae8455 Chris Wilson 2019-03-01  589  		if (IS_ERR(results)) {
34ae8455 Chris Wilson 2019-03-01  590  			err = PTR_ERR(results);
34ae8455 Chris Wilson 2019-03-01  591  			goto out_batch;
34ae8455 Chris Wilson 2019-03-01  592  		}
34ae8455 Chris Wilson 2019-03-01  593  
34ae8455 Chris Wilson 2019-03-01  594  		GEM_BUG_ON(values[ARRAY_SIZE(values) - 1] != 0xffffffff);
34ae8455 Chris Wilson 2019-03-01  595  		rsvd = results[ARRAY_SIZE(values)]; /* detect write masking */
34ae8455 Chris Wilson 2019-03-01  596  		if (!rsvd) {
34ae8455 Chris Wilson 2019-03-01  597  			pr_err("%s: Unable to write to whitelisted register %x\n",
34ae8455 Chris Wilson 2019-03-01  598  			       engine->name, reg);
34ae8455 Chris Wilson 2019-03-01  599  			err = -EINVAL;
34ae8455 Chris Wilson 2019-03-01  600  			goto out_unpin;
34ae8455 Chris Wilson 2019-03-01  601  		}
34ae8455 Chris Wilson 2019-03-01  602  
34ae8455 Chris Wilson 2019-03-01  603  		expect = results[0];
34ae8455 Chris Wilson 2019-03-01  604  		idx = 1;
34ae8455 Chris Wilson 2019-03-01  605  		for (v = 0; v < ARRAY_SIZE(values); v++) {
34ae8455 Chris Wilson 2019-03-01  606  			expect = reg_write(expect, values[v], rsvd);
34ae8455 Chris Wilson 2019-03-01  607  			if (results[idx] != expect)
34ae8455 Chris Wilson 2019-03-01  608  				err++;
34ae8455 Chris Wilson 2019-03-01  609  			idx++;
34ae8455 Chris Wilson 2019-03-01  610  		}
34ae8455 Chris Wilson 2019-03-01  611  		for (v = 0; v < ARRAY_SIZE(values); v++) {
34ae8455 Chris Wilson 2019-03-01  612  			expect = reg_write(expect, ~values[v], rsvd);
34ae8455 Chris Wilson 2019-03-01  613  			if (results[idx] != expect)
34ae8455 Chris Wilson 2019-03-01  614  				err++;
34ae8455 Chris Wilson 2019-03-01  615  			idx++;
34ae8455 Chris Wilson 2019-03-01  616  		}
34ae8455 Chris Wilson 2019-03-01  617  		if (err) {
34ae8455 Chris Wilson 2019-03-01  618  			pr_err("%s: %d mismatch between values written to whitelisted register [%x], and values read back!\n",
34ae8455 Chris Wilson 2019-03-01  619  			       engine->name, err, reg);
34ae8455 Chris Wilson 2019-03-01  620  
34ae8455 Chris Wilson 2019-03-01  621  			pr_info("%s: Whitelisted register: %x, original value %08x, rsvd %08x\n",
34ae8455 Chris Wilson 2019-03-01  622  				engine->name, reg, results[0], rsvd);
34ae8455 Chris Wilson 2019-03-01  623  
34ae8455 Chris Wilson 2019-03-01  624  			expect = results[0];
34ae8455 Chris Wilson 2019-03-01  625  			idx = 1;
34ae8455 Chris Wilson 2019-03-01  626  			for (v = 0; v < ARRAY_SIZE(values); v++) {
34ae8455 Chris Wilson 2019-03-01  627  				u32 w = values[v];
34ae8455 Chris Wilson 2019-03-01  628  
34ae8455 Chris Wilson 2019-03-01  629  				expect = reg_write(expect, w, rsvd);
34ae8455 Chris Wilson 2019-03-01  630  				pr_info("Wrote %08x, read %08x, expect %08x\n",
34ae8455 Chris Wilson 2019-03-01  631  					w, results[idx], expect);
34ae8455 Chris Wilson 2019-03-01  632  				idx++;
34ae8455 Chris Wilson 2019-03-01  633  			}
34ae8455 Chris Wilson 2019-03-01  634  			for (v = 0; v < ARRAY_SIZE(values); v++) {
34ae8455 Chris Wilson 2019-03-01  635  				u32 w = ~values[v];
34ae8455 Chris Wilson 2019-03-01  636  
34ae8455 Chris Wilson 2019-03-01  637  				expect = reg_write(expect, w, rsvd);
34ae8455 Chris Wilson 2019-03-01  638  				pr_info("Wrote %08x, read %08x, expect %08x\n",
34ae8455 Chris Wilson 2019-03-01  639  					w, results[idx], expect);
34ae8455 Chris Wilson 2019-03-01  640  				idx++;
34ae8455 Chris Wilson 2019-03-01  641  			}
34ae8455 Chris Wilson 2019-03-01  642  
34ae8455 Chris Wilson 2019-03-01  643  			err = -EINVAL;
34ae8455 Chris Wilson 2019-03-01  644  		}
34ae8455 Chris Wilson 2019-03-01  645  out_unpin:
34ae8455 Chris Wilson 2019-03-01  646  		i915_gem_object_unpin_map(scratch->obj);
34ae8455 Chris Wilson 2019-03-01  647  		if (err)
34ae8455 Chris Wilson 2019-03-01  648  			break;
34ae8455 Chris Wilson 2019-03-01  649  	}
34ae8455 Chris Wilson 2019-03-01  650  
34ae8455 Chris Wilson 2019-03-01  651  	if (igt_flush_test(ctx->i915, I915_WAIT_LOCKED))
34ae8455 Chris Wilson 2019-03-01  652  		err = -EIO;
34ae8455 Chris Wilson 2019-03-01  653  out_batch:
34ae8455 Chris Wilson 2019-03-01  654  	i915_vma_unpin_and_release(&batch, 0);
34ae8455 Chris Wilson 2019-03-01  655  out_scratch:
34ae8455 Chris Wilson 2019-03-01  656  	i915_vma_unpin_and_release(&scratch, 0);
34ae8455 Chris Wilson 2019-03-01  657  	return err;
34ae8455 Chris Wilson 2019-03-01  658  }
34ae8455 Chris Wilson 2019-03-01  659  

:::::: The code at line 520 was first introduced by commit
:::::: 34ae8455f4d30ddc7c26d914d0f246de37488a99 drm/i915/selftests: Check that whitelisted registers are accessible

:::::: TO: Chris Wilson <[email protected]> :::::: CC: Chris Wilson <[email protected]>

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/pipermail/kbuild-all Intel Corporation

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