Kyle McMartin 973b532
From bea96046b4245e9abd65ed7acfed9adfd5f6c639 Mon Sep 17 00:00:00 2001
Kyle McMartin 973b532
From: Chris Wilson <chris@chris-wilson.co.uk>
Kyle McMartin 973b532
Date: Thu, 3 Mar 2011 23:43:02 +0000
Kyle McMartin 973b532
Subject: [PATCH] drm/i915: Gen4+ has non-power-of-two strides
Kyle McMartin 973b532
Kyle McMartin 973b532
In c2e0eb16707, we started checking that the buffer was the correct size
Kyle McMartin 973b532
for tiled access by ensuring that the size was a multiple of tiles.
Kyle McMartin 973b532
However, gen4+ complicates the issue by allowing any multiple of 4096
Kyle McMartin 973b532
bytes for the stride and so the simple check based on a power-of-two
Kyle McMartin 973b532
stride was failing for valid bo.
Kyle McMartin 973b532
Kyle McMartin 973b532
Reported-by: Dan Williams <dcbw@redhat.com>
Kyle McMartin 973b532
Reported-by: Robert Hooker <sarvatt@gmail.com>
Kyle McMartin 973b532
Cc: Daniel Vetter <daniel.vetter@ffwll.ch>
Kyle McMartin 973b532
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
Kyle McMartin 973b532
---
Kyle McMartin 973b532
 drivers/gpu/drm/i915/i915_gem_tiling.c |   29 ++++++++++++++---------------
Kyle McMartin 973b532
 1 files changed, 14 insertions(+), 15 deletions(-)
Kyle McMartin 973b532
Kyle McMartin 973b532
diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c
Kyle McMartin 973b532
index 79a04fd..654f350 100644
Kyle McMartin 973b532
--- a/drivers/gpu/drm/i915/i915_gem_tiling.c
Kyle McMartin 973b532
+++ b/drivers/gpu/drm/i915/i915_gem_tiling.c
Kyle McMartin 973b532
@@ -215,6 +215,19 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode)
Kyle McMartin 973b532
 		}
Kyle McMartin 973b532
 	}
Kyle McMartin 973b532
 
Kyle McMartin 973b532
+	if (INTEL_INFO(dev)->gen >= 4) {
Kyle McMartin 973b532
+		/* 965+ just needs multiples of tile width */
Kyle McMartin 973b532
+		if (stride & (tile_width - 1))
Kyle McMartin 973b532
+			return false;
Kyle McMartin 973b532
+	} else {
Kyle McMartin 973b532
+		/* Pre-965 needs power of two tile widths */
Kyle McMartin 973b532
+		if (stride < tile_width)
Kyle McMartin 973b532
+			return false;
Kyle McMartin 973b532
+
Kyle McMartin 973b532
+		if (stride & (stride - 1))
Kyle McMartin 973b532
+			return false;
Kyle McMartin 973b532
+	}
Kyle McMartin 973b532
+
Kyle McMartin 973b532
 	if (IS_GEN2(dev) ||
Kyle McMartin 973b532
 	    (tiling_mode == I915_TILING_Y && HAS_128_BYTE_Y_TILING(dev)))
Kyle McMartin 973b532
 		tile_height = 32;
Kyle McMartin 973b532
@@ -226,21 +239,7 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode)
Kyle McMartin 973b532
 		tile_height *= 2;
Kyle McMartin 973b532
 
Kyle McMartin 973b532
 	/* Size needs to be aligned to a full tile row */
Kyle McMartin 973b532
-	if (size & (tile_height * stride - 1))
Kyle McMartin 973b532
-		return false;
Kyle McMartin 973b532
-
Kyle McMartin 973b532
-	/* 965+ just needs multiples of tile width */
Kyle McMartin 973b532
-	if (INTEL_INFO(dev)->gen >= 4) {
Kyle McMartin 973b532
-		if (stride & (tile_width - 1))
Kyle McMartin 973b532
-			return false;
Kyle McMartin 973b532
-		return true;
Kyle McMartin 973b532
-	}
Kyle McMartin 973b532
-
Kyle McMartin 973b532
-	/* Pre-965 needs power of two tile widths */
Kyle McMartin 973b532
-	if (stride < tile_width)
Kyle McMartin 973b532
-		return false;
Kyle McMartin 973b532
-
Kyle McMartin 973b532
-	if (stride & (stride - 1))
Kyle McMartin 973b532
+	if (size % (tile_height * stride))
Kyle McMartin 973b532
 		return false;
Kyle McMartin 973b532
 
Kyle McMartin 973b532
 	return true;
Kyle McMartin 973b532
-- 
Kyle McMartin 973b532
1.7.4.1
Kyle McMartin 973b532