Commit 5029537f authored by Lucas De Marchi's avatar Lucas De Marchi

drm/i915: cache number of MOCS entries

Instead of checking the gen number every time we need to know the max
number of entries, just save it into the table struct so we don't need
extra branches throughout the code. This will be useful for Ice Lake
that has 64 rather than 62 defined entries. Ice Lake changes will be
added in a follow up.

v2: make size and n_entries `unsigned int` and introduce changes as a
    pre-work for the Ice Lake changes (Tvrtko)
Suggested-by: default avatarTvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: default avatarLucas De Marchi <lucas.demarchi@intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Reviewed-by: default avatarTomasz Lis <tomasz.lis@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20190124000604.18861-7-lucas.demarchi@intel.com
parent 1878fce8
...@@ -32,7 +32,8 @@ struct drm_i915_mocs_entry { ...@@ -32,7 +32,8 @@ struct drm_i915_mocs_entry {
}; };
struct drm_i915_mocs_table { struct drm_i915_mocs_table {
u32 size; unsigned int size;
unsigned int n_entries;
const struct drm_i915_mocs_entry *table; const struct drm_i915_mocs_entry *table;
}; };
...@@ -144,10 +145,12 @@ static bool get_mocs_settings(struct drm_i915_private *dev_priv, ...@@ -144,10 +145,12 @@ static bool get_mocs_settings(struct drm_i915_private *dev_priv,
if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv) || if (IS_GEN9_BC(dev_priv) || IS_CANNONLAKE(dev_priv) ||
IS_ICELAKE(dev_priv)) { IS_ICELAKE(dev_priv)) {
table->size = ARRAY_SIZE(skylake_mocs_table); table->size = ARRAY_SIZE(skylake_mocs_table);
table->n_entries = GEN9_NUM_MOCS_ENTRIES;
table->table = skylake_mocs_table; table->table = skylake_mocs_table;
result = true; result = true;
} else if (IS_GEN9_LP(dev_priv)) { } else if (IS_GEN9_LP(dev_priv)) {
table->size = ARRAY_SIZE(broxton_mocs_table); table->size = ARRAY_SIZE(broxton_mocs_table);
table->n_entries = GEN9_NUM_MOCS_ENTRIES;
table->table = broxton_mocs_table; table->table = broxton_mocs_table;
result = true; result = true;
} else { } else {
...@@ -219,8 +222,6 @@ void intel_mocs_init_engine(struct intel_engine_cs *engine) ...@@ -219,8 +222,6 @@ void intel_mocs_init_engine(struct intel_engine_cs *engine)
if (!get_mocs_settings(dev_priv, &table)) if (!get_mocs_settings(dev_priv, &table))
return; return;
GEM_BUG_ON(table.size > GEN9_NUM_MOCS_ENTRIES);
/* Set unused values to PTE */ /* Set unused values to PTE */
unused_value = table.table[I915_MOCS_PTE].control_value; unused_value = table.table[I915_MOCS_PTE].control_value;
...@@ -231,7 +232,7 @@ void intel_mocs_init_engine(struct intel_engine_cs *engine) ...@@ -231,7 +232,7 @@ void intel_mocs_init_engine(struct intel_engine_cs *engine)
} }
/* All remaining entries are also unused */ /* All remaining entries are also unused */
for (; index < GEN9_NUM_MOCS_ENTRIES; index++) for (; index < table.n_entries; index++)
I915_WRITE(mocs_register(engine->id, index), unused_value); I915_WRITE(mocs_register(engine->id, index), unused_value);
} }
...@@ -253,17 +254,17 @@ static int emit_mocs_control_table(struct i915_request *rq, ...@@ -253,17 +254,17 @@ static int emit_mocs_control_table(struct i915_request *rq,
u32 unused_value; u32 unused_value;
u32 *cs; u32 *cs;
if (WARN_ON(table->size > GEN9_NUM_MOCS_ENTRIES)) if (GEM_WARN_ON(table->size > table->n_entries))
return -ENODEV; return -ENODEV;
/* Set unused values to PTE */ /* Set unused values to PTE */
unused_value = table->table[I915_MOCS_PTE].control_value; unused_value = table->table[I915_MOCS_PTE].control_value;
cs = intel_ring_begin(rq, 2 + 2 * GEN9_NUM_MOCS_ENTRIES); cs = intel_ring_begin(rq, 2 + 2 * table->n_entries);
if (IS_ERR(cs)) if (IS_ERR(cs))
return PTR_ERR(cs); return PTR_ERR(cs);
*cs++ = MI_LOAD_REGISTER_IMM(GEN9_NUM_MOCS_ENTRIES); *cs++ = MI_LOAD_REGISTER_IMM(table->n_entries);
for (index = 0; index < table->size; index++) { for (index = 0; index < table->size; index++) {
u32 value = get_entry_control(table, index); u32 value = get_entry_control(table, index);
...@@ -273,7 +274,7 @@ static int emit_mocs_control_table(struct i915_request *rq, ...@@ -273,7 +274,7 @@ static int emit_mocs_control_table(struct i915_request *rq,
} }
/* All remaining entries are also unused */ /* All remaining entries are also unused */
for (; index < GEN9_NUM_MOCS_ENTRIES; index++) { for (; index < table->n_entries; index++) {
*cs++ = i915_mmio_reg_offset(mocs_register(engine, index)); *cs++ = i915_mmio_reg_offset(mocs_register(engine, index));
*cs++ = unused_value; *cs++ = unused_value;
} }
...@@ -322,17 +323,17 @@ static int emit_mocs_l3cc_table(struct i915_request *rq, ...@@ -322,17 +323,17 @@ static int emit_mocs_l3cc_table(struct i915_request *rq,
unsigned int i; unsigned int i;
u32 *cs; u32 *cs;
if (WARN_ON(table->size > GEN9_NUM_MOCS_ENTRIES)) if (GEM_WARN_ON(table->size > table->n_entries))
return -ENODEV; return -ENODEV;
/* Set unused values to PTE */ /* Set unused values to PTE */
unused_value = table->table[I915_MOCS_PTE].l3cc_value; unused_value = table->table[I915_MOCS_PTE].l3cc_value;
cs = intel_ring_begin(rq, 2 + GEN9_NUM_MOCS_ENTRIES); cs = intel_ring_begin(rq, 2 + table->n_entries);
if (IS_ERR(cs)) if (IS_ERR(cs))
return PTR_ERR(cs); return PTR_ERR(cs);
*cs++ = MI_LOAD_REGISTER_IMM(GEN9_NUM_MOCS_ENTRIES / 2); *cs++ = MI_LOAD_REGISTER_IMM(table->n_entries / 2);
for (i = 0; i < table->size / 2; i++) { for (i = 0; i < table->size / 2; i++) {
u16 low = get_entry_l3cc(table, 2 * i); u16 low = get_entry_l3cc(table, 2 * i);
...@@ -352,7 +353,7 @@ static int emit_mocs_l3cc_table(struct i915_request *rq, ...@@ -352,7 +353,7 @@ static int emit_mocs_l3cc_table(struct i915_request *rq,
} }
/* All remaining entries are also unused */ /* All remaining entries are also unused */
for (; i < GEN9_NUM_MOCS_ENTRIES / 2; i++) { for (; i < table->n_entries / 2; i++) {
*cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(i)); *cs++ = i915_mmio_reg_offset(GEN9_LNCFCMOCS(i));
*cs++ = l3cc_combine(table, unused_value, unused_value); *cs++ = l3cc_combine(table, unused_value, unused_value);
} }
...@@ -407,7 +408,7 @@ void intel_mocs_init_l3cc_table(struct drm_i915_private *dev_priv) ...@@ -407,7 +408,7 @@ void intel_mocs_init_l3cc_table(struct drm_i915_private *dev_priv)
} }
/* All remaining entries are also unused */ /* All remaining entries are also unused */
for (; i < (GEN9_NUM_MOCS_ENTRIES / 2); i++) for (; i < table.n_entries / 2; i++)
I915_WRITE(GEN9_LNCFCMOCS(i), I915_WRITE(GEN9_LNCFCMOCS(i),
l3cc_combine(&table, unused_value, unused_value)); l3cc_combine(&table, unused_value, unused_value));
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment