public inbox for intel-gfx@lists.freedesktop.org
 help / color / mirror / Atom feed
* [PATCH v2] drm/i915: Use two 32bit reads for select 64bit REG_READ ioctls
@ 2015-07-15 13:17 Chris Wilson
  2015-07-16  9:06 ` [PATCH] tests/gem_reg_read: Extend and check for valid 36b counter Michał Winiarski
  0 siblings, 1 reply; 16+ messages in thread
From: Chris Wilson @ 2015-07-15 13:17 UTC (permalink / raw)
  To: intel-gfx; +Cc: Chris Wilson, Michał Winiarski, stable

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.

Reported-by: Karol Herbst <freedesktop@karolherbst.de>
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=91317
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Cc: Michał Winiarski <michal.winiarski@intel.com>
Cc: stable@vger.kernel.org
---
 drivers/gpu/drm/i915/intel_uncore.c | 26 +++++++++++++++++++-------
 1 file changed, 19 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_uncore.c b/drivers/gpu/drm/i915/intel_uncore.c
index 2c477663d378..925b02d1125f 100644
--- a/drivers/gpu/drm/i915/intel_uncore.c
+++ b/drivers/gpu/drm/i915/intel_uncore.c
@@ -1310,10 +1310,12 @@ int i915_reg_read_ioctl(struct drm_device *dev,
 	struct drm_i915_private *dev_priv = dev->dev_private;
 	struct drm_i915_reg_read *reg = data;
 	struct register_whitelist const *entry = whitelist;
+	unsigned size;
+	u64 offset;
 	int i, ret = 0;
 
 	for (i = 0; i < ARRAY_SIZE(whitelist); i++, entry++) {
-		if (entry->offset == reg->offset &&
+		if (entry->offset == (reg->offset & -(1 << entry->size)) &&
 		    (1 << INTEL_INFO(dev)->gen & entry->gen_bitmask))
 			break;
 	}
@@ -1321,23 +1323,33 @@ int i915_reg_read_ioctl(struct drm_device *dev,
 	if (i == ARRAY_SIZE(whitelist))
 		return -EINVAL;
 
+	/* We use the low bits to encode extra flags as the register should
+	 * be naturally aligned (and that aren't limit the available flags
+	 * for that register).
+	 */
+	offset = entry->offset;
+	size = entry->size;
+	size |= reg->offset ^ offset;
+
 	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:
-		reg->val = I915_READ64(reg->offset);
+		reg->val = I915_READ64(offset);
 		break;
 	case 4:
-		reg->val = I915_READ(reg->offset);
+		reg->val = I915_READ(offset);
 		break;
 	case 2:
-		reg->val = I915_READ16(reg->offset);
+		reg->val = I915_READ16(offset);
 		break;
 	case 1:
-		reg->val = I915_READ8(reg->offset);
+		reg->val = I915_READ8(offset);
 		break;
 	default:
-		MISSING_CASE(entry->size);
 		ret = -EINVAL;
 		goto out;
 	}
-- 
2.1.4

^ permalink raw reply related	[flat|nested] 16+ messages in thread

end of thread, other threads:[~2015-07-21  9:47 UTC | newest]

Thread overview: 16+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-07-15 13:17 [PATCH v2] drm/i915: Use two 32bit reads for select 64bit REG_READ ioctls Chris Wilson
2015-07-16  9:06 ` [PATCH] tests/gem_reg_read: Extend and check for valid 36b counter Michał Winiarski
2015-07-16  9:53   ` Chris Wilson
2015-07-16 10:37   ` [PATCH v2] " Michał Winiarski
2015-07-16 10:53     ` Chris Wilson
2015-07-16 11:19     ` [PATCH v3] " Michał Winiarski
2015-07-16 11:24       ` Chris Wilson
2015-07-16 12:04         ` Damien Lespiau
2015-07-21  6:48           ` Daniel Vetter
2015-07-21  7:10             ` Damien Lespiau
2015-07-16 11:37       ` [PATCH v3] drm/i915: Use two 32bit reads for select 64bit REG_READ ioctls Chris Wilson
2015-07-17 15:10         ` Michał Winiarski
2015-07-21  6:49           ` [Intel-gfx] " Daniel Vetter
2015-07-21  9:45             ` Chris Wilson
2015-07-21  9:49               ` Daniel Vetter
2015-07-19 22:05         ` shuang.he

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox