Skip to content

Commit 0e744b5

Browse files
committed
drm/i915/gt: Refactor l3cc/mocs availability
On dgfx, we only use l3cc and not mocs, but we share the table containing both register definitions with Tigerlake. This confuses our selftest that verifies that both sets of registers do contain the values in our tables after various events (idling, reset, activity etc). When constructing the table of register definitions, also include the flags for which registers are valid so that information is computed centrally and available to all callers. Signed-off-by: Chris Wilson <[email protected]> Cc: Brian Welty <[email protected]> Cc: Daniele Ceraolo Spurio <[email protected]> Reviewed-by: Daniele Ceraolo Spurio <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent f20a60f commit 0e744b5

File tree

2 files changed

+67
-29
lines changed

2 files changed

+67
-29
lines changed

drivers/gpu/drm/i915/gt/intel_mocs.c

Lines changed: 49 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -280,9 +280,32 @@ static const struct drm_i915_mocs_entry icl_mocs_table[] = {
280280
GEN11_MOCS_ENTRIES
281281
};
282282

283-
static bool get_mocs_settings(const struct drm_i915_private *i915,
284-
struct drm_i915_mocs_table *table)
283+
enum {
284+
HAS_GLOBAL_MOCS = BIT(0),
285+
HAS_ENGINE_MOCS = BIT(1),
286+
HAS_RENDER_L3CC = BIT(2),
287+
};
288+
289+
static bool has_l3cc(const struct drm_i915_private *i915)
285290
{
291+
return true;
292+
}
293+
294+
static bool has_global_mocs(const struct drm_i915_private *i915)
295+
{
296+
return HAS_GLOBAL_MOCS_REGISTERS(i915);
297+
}
298+
299+
static bool has_mocs(const struct drm_i915_private *i915)
300+
{
301+
return !IS_DGFX(i915);
302+
}
303+
304+
static unsigned int get_mocs_settings(const struct drm_i915_private *i915,
305+
struct drm_i915_mocs_table *table)
306+
{
307+
unsigned int flags;
308+
286309
if (INTEL_GEN(i915) >= 12) {
287310
table->size = ARRAY_SIZE(tgl_mocs_table);
288311
table->table = tgl_mocs_table;
@@ -302,11 +325,11 @@ static bool get_mocs_settings(const struct drm_i915_private *i915,
302325
} else {
303326
drm_WARN_ONCE(&i915->drm, INTEL_GEN(i915) >= 9,
304327
"Platform that should have a MOCS table does not.\n");
305-
return false;
328+
return 0;
306329
}
307330

308331
if (GEM_DEBUG_WARN_ON(table->size > table->n_entries))
309-
return false;
332+
return 0;
310333

311334
/* WaDisableSkipCaching:skl,bxt,kbl,glk */
312335
if (IS_GEN(i915, 9)) {
@@ -315,10 +338,20 @@ static bool get_mocs_settings(const struct drm_i915_private *i915,
315338
for (i = 0; i < table->size; i++)
316339
if (GEM_DEBUG_WARN_ON(table->table[i].l3cc_value &
317340
(L3_ESC(1) | L3_SCC(0x7))))
318-
return false;
341+
return 0;
319342
}
320343

321-
return true;
344+
flags = 0;
345+
if (has_mocs(i915)) {
346+
if (has_global_mocs(i915))
347+
flags |= HAS_GLOBAL_MOCS;
348+
else
349+
flags |= HAS_ENGINE_MOCS;
350+
}
351+
if (has_l3cc(i915))
352+
flags |= HAS_RENDER_L3CC;
353+
354+
return flags;
322355
}
323356

324357
/*
@@ -411,18 +444,20 @@ static void init_l3cc_table(struct intel_engine_cs *engine,
411444
void intel_mocs_init_engine(struct intel_engine_cs *engine)
412445
{
413446
struct drm_i915_mocs_table table;
447+
unsigned int flags;
414448

415449
/* Called under a blanket forcewake */
416450
assert_forcewakes_active(engine->uncore, FORCEWAKE_ALL);
417451

418-
if (!get_mocs_settings(engine->i915, &table))
452+
flags = get_mocs_settings(engine->i915, &table);
453+
if (!flags)
419454
return;
420455

421456
/* Platforms with global MOCS do not need per-engine initialization. */
422-
if (!HAS_GLOBAL_MOCS_REGISTERS(engine->i915))
457+
if (flags & HAS_ENGINE_MOCS)
423458
init_mocs_table(engine, &table);
424459

425-
if (engine->class == RENDER_CLASS)
460+
if (flags & HAS_RENDER_L3CC && engine->class == RENDER_CLASS)
426461
init_l3cc_table(engine, &table);
427462
}
428463

@@ -431,26 +466,17 @@ static u32 global_mocs_offset(void)
431466
return i915_mmio_reg_offset(GEN12_GLOBAL_MOCS(0));
432467
}
433468

434-
static void init_global_mocs(struct intel_gt *gt)
469+
void intel_mocs_init(struct intel_gt *gt)
435470
{
436471
struct drm_i915_mocs_table table;
472+
unsigned int flags;
437473

438474
/*
439475
* LLC and eDRAM control values are not applicable to dgfx
440476
*/
441-
if (IS_DGFX(gt->i915))
442-
return;
443-
444-
if (!get_mocs_settings(gt->i915, &table))
445-
return;
446-
447-
__init_mocs_table(gt->uncore, &table, global_mocs_offset());
448-
}
449-
450-
void intel_mocs_init(struct intel_gt *gt)
451-
{
452-
if (HAS_GLOBAL_MOCS_REGISTERS(gt->i915))
453-
init_global_mocs(gt);
477+
flags = get_mocs_settings(gt->i915, &table);
478+
if (flags & HAS_GLOBAL_MOCS)
479+
__init_mocs_table(gt->uncore, &table, global_mocs_offset());
454480
}
455481

456482
#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)

drivers/gpu/drm/i915/gt/selftest_mocs.c

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include "selftests/igt_spinner.h"
1313

1414
struct live_mocs {
15-
struct drm_i915_mocs_table table;
15+
struct drm_i915_mocs_table mocs;
16+
struct drm_i915_mocs_table l3cc;
1617
struct i915_vma *scratch;
1718
void *vaddr;
1819
};
@@ -70,11 +71,22 @@ static struct i915_vma *create_scratch(struct intel_gt *gt)
7071

7172
static int live_mocs_init(struct live_mocs *arg, struct intel_gt *gt)
7273
{
74+
struct drm_i915_mocs_table table;
75+
unsigned int flags;
7376
int err;
7477

75-
if (!get_mocs_settings(gt->i915, &arg->table))
78+
memset(arg, 0, sizeof(*arg));
79+
80+
flags = get_mocs_settings(gt->i915, &table);
81+
if (!flags)
7682
return -EINVAL;
7783

84+
if (flags & HAS_RENDER_L3CC)
85+
arg->l3cc = table;
86+
87+
if (flags & (HAS_GLOBAL_MOCS | HAS_ENGINE_MOCS))
88+
arg->mocs = table;
89+
7890
arg->scratch = create_scratch(gt);
7991
if (IS_ERR(arg->scratch))
8092
return PTR_ERR(arg->scratch);
@@ -223,9 +235,9 @@ static int check_mocs_engine(struct live_mocs *arg,
223235
/* Read the mocs tables back using SRM */
224236
offset = i915_ggtt_offset(vma);
225237
if (!err)
226-
err = read_mocs_table(rq, &arg->table, &offset);
238+
err = read_mocs_table(rq, &arg->mocs, &offset);
227239
if (!err && ce->engine->class == RENDER_CLASS)
228-
err = read_l3cc_table(rq, &arg->table, &offset);
240+
err = read_l3cc_table(rq, &arg->l3cc, &offset);
229241
offset -= i915_ggtt_offset(vma);
230242
GEM_BUG_ON(offset > PAGE_SIZE);
231243

@@ -236,9 +248,9 @@ static int check_mocs_engine(struct live_mocs *arg,
236248
/* Compare the results against the expected tables */
237249
vaddr = arg->vaddr;
238250
if (!err)
239-
err = check_mocs_table(ce->engine, &arg->table, &vaddr);
251+
err = check_mocs_table(ce->engine, &arg->mocs, &vaddr);
240252
if (!err && ce->engine->class == RENDER_CLASS)
241-
err = check_l3cc_table(ce->engine, &arg->table, &vaddr);
253+
err = check_l3cc_table(ce->engine, &arg->l3cc, &vaddr);
242254
if (err)
243255
return err;
244256

0 commit comments

Comments
 (0)