Commit 3fd3a6ff authored by Joonas Lahtinen's avatar Joonas Lahtinen

drm/i915: Simplify i915_reg_read_ioctl

Convert to use the freshly available made INTEL_GEN_MASK for easier
grepping and improve function readability and clarify the UABI
documentation.

No functional changes.

v2:
- Lift GEM_BUG_ONs and use is_power_of_2 (Chris)
- Retain -EINVAL on bad flags behavior (Chris)

v3:
- Extract flags with 'entry->size - 1' (Chris)

v4:
- Add GEM_BUG_ON on for flags vs entry offset (Chris)

v5:
- Use 'u16' to match 'dev_priv' (Ville)

v6:
- Fix checkpatch.pl errors
Signed-off-by: default avatarJoonas Lahtinen <joonas.lahtinen@linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Cc: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Link: https://patchwork.freedesktop.org/patch/msgid/20170913115255.13851-2-joonas.lahtinen@linux.intel.com
parent fe52e597
...@@ -1292,72 +1292,65 @@ void intel_uncore_fini(struct drm_i915_private *dev_priv) ...@@ -1292,72 +1292,65 @@ void intel_uncore_fini(struct drm_i915_private *dev_priv)
intel_uncore_forcewake_reset(dev_priv, false); intel_uncore_forcewake_reset(dev_priv, false);
} }
#define GEN_RANGE(l, h) GENMASK((h) - 1, (l) - 1) static const struct reg_whitelist {
i915_reg_t offset_ldw;
static const struct register_whitelist { i915_reg_t offset_udw;
i915_reg_t offset_ldw, offset_udw; u16 gen_mask;
uint32_t size; u8 size;
/* supported gens, 0x10 for 4, 0x30 for 4 and 5, etc. */ } reg_read_whitelist[] = { {
uint32_t gen_bitmask; .offset_ldw = RING_TIMESTAMP(RENDER_RING_BASE),
} whitelist[] = { .offset_udw = RING_TIMESTAMP_UDW(RENDER_RING_BASE),
{ .offset_ldw = RING_TIMESTAMP(RENDER_RING_BASE), .gen_mask = INTEL_GEN_MASK(4, 10),
.offset_udw = RING_TIMESTAMP_UDW(RENDER_RING_BASE), .size = 8
.size = 8, .gen_bitmask = GEN_RANGE(4, 10) }, } };
};
int i915_reg_read_ioctl(struct drm_device *dev, int i915_reg_read_ioctl(struct drm_device *dev,
void *data, struct drm_file *file) void *data, struct drm_file *file)
{ {
struct drm_i915_private *dev_priv = to_i915(dev); struct drm_i915_private *dev_priv = to_i915(dev);
struct drm_i915_reg_read *reg = data; struct drm_i915_reg_read *reg = data;
struct register_whitelist const *entry = whitelist; struct reg_whitelist const *entry;
unsigned size; unsigned int flags;
i915_reg_t offset_ldw, offset_udw; int remain;
int i, ret = 0; int ret = 0;
for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) { entry = reg_read_whitelist;
if (i915_mmio_reg_offset(entry->offset_ldw) == (reg->offset & -entry->size) && remain = ARRAY_SIZE(reg_read_whitelist);
(INTEL_INFO(dev_priv)->gen_mask & entry->gen_bitmask)) while (remain) {
u32 entry_offset = i915_mmio_reg_offset(entry->offset_ldw);
GEM_BUG_ON(!is_power_of_2(entry->size));
GEM_BUG_ON(entry->size > 8);
GEM_BUG_ON(entry_offset & (entry->size - 1));
if (INTEL_INFO(dev_priv)->gen_mask & entry->gen_mask &&
entry_offset == (reg->offset & -entry->size))
break; break;
entry++;
remain--;
} }
if (i == ARRAY_SIZE(whitelist)) if (!remain)
return -EINVAL; return -EINVAL;
/* We use the low bits to encode extra flags as the register should flags = reg->offset & (entry->size - 1);
* be naturally aligned (and those that are not so aligned merely
* limit the available flags for that register).
*/
offset_ldw = entry->offset_ldw;
offset_udw = entry->offset_udw;
size = entry->size;
size |= reg->offset ^ i915_mmio_reg_offset(offset_ldw);
intel_runtime_pm_get(dev_priv); intel_runtime_pm_get(dev_priv);
if (entry->size == 8 && flags == I915_REG_READ_8B_WA)
switch (size) { reg->val = I915_READ64_2x32(entry->offset_ldw,
case 8 | 1: entry->offset_udw);
reg->val = I915_READ64_2x32(offset_ldw, offset_udw); else if (entry->size == 8 && flags == 0)
break; reg->val = I915_READ64(entry->offset_ldw);
case 8: else if (entry->size == 4 && flags == 0)
reg->val = I915_READ64(offset_ldw); reg->val = I915_READ(entry->offset_ldw);
break; else if (entry->size == 2 && flags == 0)
case 4: reg->val = I915_READ16(entry->offset_ldw);
reg->val = I915_READ(offset_ldw); else if (entry->size == 1 && flags == 0)
break; reg->val = I915_READ8(entry->offset_ldw);
case 2: else
reg->val = I915_READ16(offset_ldw);
break;
case 1:
reg->val = I915_READ8(offset_ldw);
break;
default:
ret = -EINVAL; ret = -EINVAL;
goto out;
}
out:
intel_runtime_pm_put(dev_priv); intel_runtime_pm_put(dev_priv);
return ret; return ret;
} }
......
...@@ -1308,14 +1308,16 @@ struct drm_i915_reg_read { ...@@ -1308,14 +1308,16 @@ struct drm_i915_reg_read {
* be specified * be specified
*/ */
__u64 offset; __u64 offset;
#define I915_REG_READ_8B_WA BIT(0)
__u64 val; /* Return value */ __u64 val; /* Return value */
}; };
/* Known registers: /* Known registers:
* *
* Render engine timestamp - 0x2358 + 64bit - gen7+ * Render engine timestamp - 0x2358 + 64bit - gen7+
* - Note this register returns an invalid value if using the default * - Note this register returns an invalid value if using the default
* single instruction 8byte read, in order to workaround that use * single instruction 8byte read, in order to workaround that pass
* offset (0x2538 | 1) instead. * flag I915_REG_READ_8B_WA in offset field.
* *
*/ */
......
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