Commit f8c0c77b authored by Chris Wilson's avatar Chris Wilson Committed by Luis Henriques

xdrm/i915: Use two 32bit reads for select 64bit REG_READ ioctls

commit 648a9bc5 upstream.

Since the hardware sometimes mysteriously totally flummoxes the 64bit
read of a 64bit register when read using a single instruction, split the
read into two instructions. Since the read here is of automatically
incrementing timestamp counters, we also have to be very careful in
order to make sure that it does not increment between the two
instructions.

However, since userspace tried to workaround this issue and so enshrined
this ABI for a broken hardware read and in the process neglected that
the read only fails in some environments, we have to introduce a new
uABI flag for userspace to request the 2x32 bit accurate read of the
timestamp.

v2: Fix alignment check and include details of the workaround for
userspace.
Reported-by: default avatarKarol Herbst <freedesktop@karolherbst.de>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91317
Testcase: igt/gem_reg_read
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Tested-by: default avatarMichał Winiarski <michal.winiarski@intel.com>
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
[ luis: backported to 3.16: adjusted context ]
Signed-off-by: default avatarLuis Henriques <luis.henriques@canonical.com>
parent 69e84dc0
...@@ -863,10 +863,12 @@ int i915_reg_read_ioctl(struct drm_device *dev, ...@@ -863,10 +863,12 @@ int i915_reg_read_ioctl(struct drm_device *dev,
struct drm_i915_private *dev_priv = dev->dev_private; struct drm_i915_private *dev_priv = dev->dev_private;
struct drm_i915_reg_read *reg = data; struct drm_i915_reg_read *reg = data;
struct register_whitelist const *entry = whitelist; struct register_whitelist const *entry = whitelist;
unsigned size;
u64 offset;
int i, ret = 0; int i, ret = 0;
for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) { for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) {
if (entry->offset == reg->offset && if (entry->offset == (reg->offset & -entry->size) &&
(1 << INTEL_INFO(dev)->gen & entry->gen_bitmask)) (1 << INTEL_INFO(dev)->gen & entry->gen_bitmask))
break; break;
} }
...@@ -874,23 +876,33 @@ int i915_reg_read_ioctl(struct drm_device *dev, ...@@ -874,23 +876,33 @@ int i915_reg_read_ioctl(struct drm_device *dev,
if (i == ARRAY_SIZE(whitelist)) if (i == ARRAY_SIZE(whitelist))
return -EINVAL; return -EINVAL;
/* We use the low bits to encode extra flags as the register should
* be naturally aligned (and those that are not so aligned merely
* limit the available flags for that register).
*/
offset = entry->offset;
size = entry->size;
size |= reg->offset ^ offset;
intel_runtime_pm_get(dev_priv); intel_runtime_pm_get(dev_priv);
switch (entry->size) { switch (size) {
case 8 | 1:
reg->val = I915_READ64_2x32(offset, offset+4);
break;
case 8: case 8:
reg->val = I915_READ64(reg->offset); reg->val = I915_READ64(offset);
break; break;
case 4: case 4:
reg->val = I915_READ(reg->offset); reg->val = I915_READ(offset);
break; break;
case 2: case 2:
reg->val = I915_READ16(reg->offset); reg->val = I915_READ16(offset);
break; break;
case 1: case 1:
reg->val = I915_READ8(reg->offset); reg->val = I915_READ8(offset);
break; break;
default: default:
WARN_ON(1);
ret = -EINVAL; ret = -EINVAL;
goto out; goto out;
} }
......
...@@ -1035,6 +1035,14 @@ struct drm_i915_reg_read { ...@@ -1035,6 +1035,14 @@ struct drm_i915_reg_read {
__u64 offset; __u64 offset;
__u64 val; /* Return value */ __u64 val; /* Return value */
}; };
/* Known registers:
*
* Render engine timestamp - 0x2358 + 64bit - gen7+
* - Note this register returns an invalid value if using the default
* single instruction 8byte read, in order to workaround that use
* offset (0x2538 | 1) instead.
*
*/
struct drm_i915_reset_stats { struct drm_i915_reset_stats {
__u32 ctx_id; __u32 ctx_id;
......
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