[Intel-gfx] [PATCH v5 2/2] drm/i915: Simplify i915_reg_read_ioctl
Chris Wilson
chris at chris-wilson.co.uk
Mon Sep 11 10:47:36 UTC 2017
Quoting Joonas Lahtinen (2017-09-11 10:59:01)
> 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)
>
> Signed-off-by: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
> Cc: Tvrtko Ursulin <tvrtko.ursulin at intel.com>
> Cc: Chris Wilson <chris at chris-wilson.co.uk>
> Reviewed-by: Chris Wilson <chris at chris-wilson.co.uk>
> ---
> drivers/gpu/drm/i915/intel_uncore.c | 95 +++++++++++++++++--------------------
> include/uapi/drm/i915_drm.h | 6 ++-
> 2 files changed, 48 insertions(+), 53 deletions(-)
>
> diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
> index 1b38eb94d461..92420e0efa04 100644
> --- a/drivers/gpu/drm/i915/intel_uncore.c
> +++ b/drivers/gpu/drm/i915/intel_uncore.c
> @@ -1292,72 +1292,65 @@ void intel_uncore_fini(struct drm_i915_private *dev_priv)
> intel_uncore_forcewake_reset(dev_priv, false);
> }
>
> -#define GEN_RANGE(l, h) GENMASK((h) - 1, (l) - 1)
> -
> -static const struct register_whitelist {
> - i915_reg_t offset_ldw, offset_udw;
> - uint32_t size;
> - /* supported gens, 0x10 for 4, 0x30 for 4 and 5, etc. */
> - uint32_t gen_bitmask;
> -} whitelist[] = {
> - { .offset_ldw = RING_TIMESTAMP(RENDER_RING_BASE),
> - .offset_udw = RING_TIMESTAMP_UDW(RENDER_RING_BASE),
> - .size = 8, .gen_bitmask = GEN_RANGE(4, 10) },
> -};
> +static const struct reg_whitelist {
> + i915_reg_t offset_ldw;
> + i915_reg_t offset_udw;
> + unsigned long gen_mask;
> + u8 size;
> +} reg_read_whitelist[] = {{
> + .offset_ldw = RING_TIMESTAMP(RENDER_RING_BASE),
> + .offset_udw = RING_TIMESTAMP_UDW(RENDER_RING_BASE),
> + .gen_mask = INTEL_GEN_MASK(4, 10),
> + .size = 8
> +}};
>
> int i915_reg_read_ioctl(struct drm_device *dev,
> void *data, struct drm_file *file)
> {
> struct drm_i915_private *dev_priv = to_i915(dev);
> struct drm_i915_reg_read *reg = data;
> - struct register_whitelist const *entry = whitelist;
> - unsigned size;
> - i915_reg_t offset_ldw, offset_udw;
> - int i, ret = 0;
> -
> - for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) {
> - if (i915_mmio_reg_offset(entry->offset_ldw) == (reg->offset & -entry->size) &&
> - (INTEL_INFO(dev_priv)->gen_mask & entry->gen_bitmask))
> + struct reg_whitelist const *entry;
> + unsigned flags;
> + int remain;
> + int ret = 0;
> +
> + entry = reg_read_whitelist;
> + remain = ARRAY_SIZE(reg_read_whitelist);
> + 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;
> + entry++;
> + remain--;
> }
>
> - if (i == ARRAY_SIZE(whitelist))
> + if (!remain)
> return -EINVAL;
Thinking about the abi this would be nicer if it was ENOENT (continuing
our abuse) show that the caller can distinguish between a register not
existing. Bonus marks for -ENODEV.
e.g.:
ret = -ENOENT;
while (remain) {
if (entry_offset != (reg->offset & -entry->size))
continue;
if (!INTEL_INFO(dev_priv)->gen_mask & entry->gem_mask) {
ret = -ENODEV; /* known register, but bad gen */
continue;
}
ret = 0;
break;
}
if (ret)
return ret;
Just thinking how to write an agnostic igt, you would start with
igt_require(read_timestamp(fd) != -ENODEV);
so the test would naturally only run on the right hw. But there may be
some subtlety if registers are reassigned between gen...
-Chris
More information about the Intel-gfx
mailing list