Skip to content

Commit

Permalink
drm/i915: Check whitelist registers across resets
Browse files Browse the repository at this point in the history
Add a selftest to ensure that we restore the whitelisted registers after
rewrite the registers everytime they might be scrubbed, e.g. module
load, reset and resume. For the other volatile workaround registers, we
export their presence via debugfs and check in igt/gem_workarounds.
However, we don't export the whitelist and rather than do so, let's test
them directly in the kernel.

The test we use is to read the registers back from the CS (this helps us
be sure that the registers will be valid for MI_LRI etc). In order to
generate the expected list, we split intel_whitelist_workarounds_emit
into two phases, the first to build the list and the second to apply.
Inside the test, we only build the list and then check that list against
the hw.

v2: Filter out pre-gen8 as they do not have RING_NONPRIV.
v3: Drop unused engine parameter, no plans to use it now or future.

Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Oscar Mateo <oscar.mateo@intel.com>
Cc: Mika Kuoppala <mika.kuoppala@linux.intel.com>
Cc: Joonas Lahtinen <joonas.lahtinen@linux.intel.com>
Reviewed-by: Oscar Mateo <oscar.mateo@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20180414122754.569-1-chris@chris-wilson.co.uk
  • Loading branch information
Chris Wilson committed Apr 14, 2018
1 parent 5bbed0b commit f4ecfbf
Show file tree
Hide file tree
Showing 8 changed files with 380 additions and 140 deletions.
14 changes: 1 addition & 13 deletions drivers/gpu/drm/i915/i915_debugfs.c
Original file line number Diff line number Diff line change
Expand Up @@ -3304,24 +3304,13 @@ static int i915_shared_dplls_info(struct seq_file *m, void *unused)

static int i915_wa_registers(struct seq_file *m, void *unused)
{
int i;
int ret;
struct intel_engine_cs *engine;
struct drm_i915_private *dev_priv = node_to_i915(m->private);
struct drm_device *dev = &dev_priv->drm;
struct i915_workarounds *workarounds = &dev_priv->workarounds;
enum intel_engine_id id;

ret = mutex_lock_interruptible(&dev->struct_mutex);
if (ret)
return ret;
int i;

intel_runtime_pm_get(dev_priv);

seq_printf(m, "Workarounds applied: %d\n", workarounds->count);
for_each_engine(engine, dev_priv, id)
seq_printf(m, "HW whitelist count for %s: %d\n",
engine->name, workarounds->hw_whitelist_count[id]);
for (i = 0; i < workarounds->count; ++i) {
i915_reg_t addr;
u32 mask, value, read;
Expand All @@ -3337,7 +3326,6 @@ static int i915_wa_registers(struct seq_file *m, void *unused)
}

intel_runtime_pm_put(dev_priv);
mutex_unlock(&dev->struct_mutex);

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion drivers/gpu/drm/i915/i915_drv.h
Original file line number Diff line number Diff line change
Expand Up @@ -1297,7 +1297,6 @@ struct i915_wa_reg {
struct i915_workarounds {
struct i915_wa_reg reg[I915_MAX_WA_REGS];
u32 count;
u32 hw_whitelist_count[I915_NUM_ENGINES];
};

struct i915_virtual_gpu {
Expand Down
8 changes: 2 additions & 6 deletions drivers/gpu/drm/i915/intel_lrc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1744,9 +1744,7 @@ static int gen8_init_render_ring(struct intel_engine_cs *engine)
if (ret)
return ret;

ret = intel_whitelist_workarounds_apply(engine);
if (ret)
return ret;
intel_whitelist_workarounds_apply(engine);

/* We need to disable the AsyncFlip performance optimisations in order
* to use MI_WAIT_FOR_EVENT within the CS. It should already be
Expand All @@ -1769,9 +1767,7 @@ static int gen9_init_render_ring(struct intel_engine_cs *engine)
if (ret)
return ret;

ret = intel_whitelist_workarounds_apply(engine);
if (ret)
return ret;
intel_whitelist_workarounds_apply(engine);

return 0;
}
Expand Down
4 changes: 1 addition & 3 deletions drivers/gpu/drm/i915/intel_ringbuffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -618,9 +618,7 @@ static int init_render_ring(struct intel_engine_cs *engine)
if (ret)
return ret;

ret = intel_whitelist_workarounds_apply(engine);
if (ret)
return ret;
intel_whitelist_workarounds_apply(engine);

/* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */
if (IS_GEN(dev_priv, 4, 6))
Expand Down
206 changes: 90 additions & 116 deletions drivers/gpu/drm/i915/intel_workarounds.c
Original file line number Diff line number Diff line change
Expand Up @@ -687,170 +687,144 @@ void intel_gt_workarounds_apply(struct drm_i915_private *dev_priv)
MISSING_CASE(INTEL_GEN(dev_priv));
}

static int wa_ring_whitelist_reg(struct intel_engine_cs *engine,
i915_reg_t reg)
{
struct drm_i915_private *dev_priv = engine->i915;
struct i915_workarounds *wa = &dev_priv->workarounds;
const unsigned int index = wa->hw_whitelist_count[engine->id];

if (WARN_ON(index >= RING_MAX_NONPRIV_SLOTS))
return -EINVAL;
struct whitelist {
i915_reg_t reg[RING_MAX_NONPRIV_SLOTS];
unsigned int count;
u32 nopid;
};

I915_WRITE(RING_FORCE_TO_NONPRIV(engine->mmio_base, index),
i915_mmio_reg_offset(reg));
wa->hw_whitelist_count[engine->id]++;
static void whitelist_reg(struct whitelist *w, i915_reg_t reg)
{
if (GEM_WARN_ON(w->count >= RING_MAX_NONPRIV_SLOTS))
return;

return 0;
w->reg[w->count++] = reg;
}

static int bdw_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void bdw_whitelist_build(struct whitelist *w)
{
return 0;
}

static int chv_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void chv_whitelist_build(struct whitelist *w)
{
return 0;
}

static int gen9_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void gen9_whitelist_build(struct whitelist *w)
{
int ret;

/* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */
ret = wa_ring_whitelist_reg(engine, GEN9_CTX_PREEMPT_REG);
if (ret)
return ret;
whitelist_reg(w, GEN9_CTX_PREEMPT_REG);

/* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl,cfl,[cnl] */
ret = wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1);
if (ret)
return ret;
whitelist_reg(w, GEN8_CS_CHICKEN1);

/* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */
ret = wa_ring_whitelist_reg(engine, GEN8_HDC_CHICKEN1);
if (ret)
return ret;

return 0;
whitelist_reg(w, GEN8_HDC_CHICKEN1);
}

static int skl_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void skl_whitelist_build(struct whitelist *w)
{
int ret;

ret = gen9_whitelist_workarounds_apply(engine);
if (ret)
return ret;
gen9_whitelist_build(w);

/* WaDisableLSQCROPERFforOCL:skl */
ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
if (ret)
return ret;

return 0;
whitelist_reg(w, GEN8_L3SQCREG4);
}

static int bxt_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void bxt_whitelist_build(struct whitelist *w)
{
int ret;

ret = gen9_whitelist_workarounds_apply(engine);
if (ret)
return ret;

return 0;
gen9_whitelist_build(w);
}

static int kbl_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void kbl_whitelist_build(struct whitelist *w)
{
int ret;

ret = gen9_whitelist_workarounds_apply(engine);
if (ret)
return ret;
gen9_whitelist_build(w);

/* WaDisableLSQCROPERFforOCL:kbl */
ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4);
if (ret)
return ret;

return 0;
whitelist_reg(w, GEN8_L3SQCREG4);
}

static int glk_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void glk_whitelist_build(struct whitelist *w)
{
int ret;

ret = gen9_whitelist_workarounds_apply(engine);
if (ret)
return ret;
gen9_whitelist_build(w);

/* WA #0862: Userspace has to set "Barrier Mode" to avoid hangs. */
ret = wa_ring_whitelist_reg(engine, GEN9_SLICE_COMMON_ECO_CHICKEN1);
if (ret)
return ret;

return 0;
whitelist_reg(w, GEN9_SLICE_COMMON_ECO_CHICKEN1);
}

static int cfl_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void cfl_whitelist_build(struct whitelist *w)
{
int ret;

ret = gen9_whitelist_workarounds_apply(engine);
if (ret)
return ret;

return 0;
gen9_whitelist_build(w);
}

static int cnl_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void cnl_whitelist_build(struct whitelist *w)
{
int ret;

/* WaEnablePreemptionGranularityControlByUMD:cnl */
ret = wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1);
if (ret)
return ret;
whitelist_reg(w, GEN8_CS_CHICKEN1);
}

static struct whitelist *whitelist_build(struct intel_engine_cs *engine,
struct whitelist *w)
{
struct drm_i915_private *i915 = engine->i915;

GEM_BUG_ON(engine->id != RCS);

w->count = 0;
w->nopid = i915_mmio_reg_offset(RING_NOPID(engine->mmio_base));

if (INTEL_GEN(i915) < 8)
return NULL;
else if (IS_BROADWELL(i915))
bdw_whitelist_build(w);
else if (IS_CHERRYVIEW(i915))
chv_whitelist_build(w);
else if (IS_SKYLAKE(i915))
skl_whitelist_build(w);
else if (IS_BROXTON(i915))
bxt_whitelist_build(w);
else if (IS_KABYLAKE(i915))
kbl_whitelist_build(w);
else if (IS_GEMINILAKE(i915))
glk_whitelist_build(w);
else if (IS_COFFEELAKE(i915))
cfl_whitelist_build(w);
else if (IS_CANNONLAKE(i915))
cnl_whitelist_build(w);
else
MISSING_CASE(INTEL_GEN(i915));

return 0;
return w;
}

int intel_whitelist_workarounds_apply(struct intel_engine_cs *engine)
static void whitelist_apply(struct intel_engine_cs *engine,
const struct whitelist *w)
{
struct drm_i915_private *dev_priv = engine->i915;
int err = 0;
const u32 base = engine->mmio_base;
unsigned int i;

if (!w)
return;

WARN_ON(engine->id != RCS);
intel_uncore_forcewake_get(engine->i915, FORCEWAKE_ALL);

dev_priv->workarounds.hw_whitelist_count[engine->id] = 0;
for (i = 0; i < w->count; i++)
I915_WRITE_FW(RING_FORCE_TO_NONPRIV(base, i),
i915_mmio_reg_offset(w->reg[i]));

if (INTEL_GEN(dev_priv) < 8)
err = 0;
else if (IS_BROADWELL(dev_priv))
err = bdw_whitelist_workarounds_apply(engine);
else if (IS_CHERRYVIEW(dev_priv))
err = chv_whitelist_workarounds_apply(engine);
else if (IS_SKYLAKE(dev_priv))
err = skl_whitelist_workarounds_apply(engine);
else if (IS_BROXTON(dev_priv))
err = bxt_whitelist_workarounds_apply(engine);
else if (IS_KABYLAKE(dev_priv))
err = kbl_whitelist_workarounds_apply(engine);
else if (IS_GEMINILAKE(dev_priv))
err = glk_whitelist_workarounds_apply(engine);
else if (IS_COFFEELAKE(dev_priv))
err = cfl_whitelist_workarounds_apply(engine);
else if (IS_CANNONLAKE(dev_priv))
err = cnl_whitelist_workarounds_apply(engine);
else
MISSING_CASE(INTEL_GEN(dev_priv));
if (err)
return err;
/* And clear the rest just in case of garbage */
for (; i < RING_MAX_NONPRIV_SLOTS; i++)
I915_WRITE_FW(RING_FORCE_TO_NONPRIV(base, i), w->nopid);

DRM_DEBUG_DRIVER("%s: Number of whitelist w/a: %d\n", engine->name,
dev_priv->workarounds.hw_whitelist_count[engine->id]);
return 0;
intel_uncore_forcewake_put(engine->i915, FORCEWAKE_ALL);
}

void intel_whitelist_workarounds_apply(struct intel_engine_cs *engine)
{
struct whitelist w;

whitelist_apply(engine, whitelist_build(engine, &w));
}

#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
#include "selftests/intel_workarounds.c"
#endif
2 changes: 1 addition & 1 deletion drivers/gpu/drm/i915/intel_workarounds.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ int intel_ctx_workarounds_emit(struct i915_request *rq);

void intel_gt_workarounds_apply(struct drm_i915_private *dev_priv);

int intel_whitelist_workarounds_apply(struct intel_engine_cs *engine);
void intel_whitelist_workarounds_apply(struct intel_engine_cs *engine);

#endif
1 change: 1 addition & 0 deletions drivers/gpu/drm/i915/selftests/i915_live_selftests.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
*/
selftest(sanitycheck, i915_live_sanitycheck) /* keep first (igt selfcheck) */
selftest(uncore, intel_uncore_live_selftests)
selftest(workarounds, intel_workarounds_live_selftests)
selftest(requests, i915_request_live_selftests)
selftest(objects, i915_gem_object_live_selftests)
selftest(dmabuf, i915_gem_dmabuf_live_selftests)
Expand Down
Loading

0 comments on commit f4ecfbf

Please sign in to comment.