Blob Blame History Raw
From 1e1bb8710e6018e932d18f9064d815634e3179f8 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Ville=20Syrj=C3=A4l=C3=A4?= <ville.syrjala@linux.intel.com>
Date: Mon, 27 Mar 2017 21:55:41 +0300
Subject: [PATCH] drm/i915: Use fb->pitches[0] in cursor code
Mime-version: 1.0
Content-type: text/plain; charset=UTF-8
Content-transfer-encoding: 8bit
Git-commit: 1e1bb8710e6018e932d18f9064d815634e3179f8
Patch-mainline: v4.13-rc1
References: FATE#322643 bsc#1055900

The cursor code currently ignores fb->pitches[0] (except when creating
the fb itself), and just uses the cursor_width*4 as the stride. Let's
make sure fb->pitches[0] actually matches what we expect it to be.

We can also relax the stride vs. cursor width relationship on 845/865
since the stride is programmed separately. The only constraint is that
width*cpp doesn't exceed the stride, and that's already been checked
by the core since it makes sure the entire plane fits within the fb.

We can also drop the bo size check as that's already checked when
we create the fb. That is the fb is guaranteed to fit within the bo.

V2: Rebase due to i845_cursor_ctl() and i9xx_cursor_ctl()

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> #v1
Link: http://patchwork.freedesktop.org/patch/msgid/20170327185546.2977-11-ville.syrjala@linux.intel.com
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/gpu/drm/i915/intel_display.c |   48 +++++++++++++----------------------
 1 file changed, 18 insertions(+), 30 deletions(-)

--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -9227,26 +9227,12 @@ static int intel_check_cursor(struct int
 static u32 i845_cursor_ctl(const struct intel_crtc_state *crtc_state,
 			   const struct intel_plane_state *plane_state)
 {
-	unsigned int width = plane_state->base.crtc_w;
-	unsigned int stride = roundup_pow_of_two(width) * 4;
-
-	switch (stride) {
-	default:
-		WARN_ONCE(1, "Invalid cursor width/stride, width=%u, stride=%u\n",
-			  width, stride);
-		stride = 256;
-		/* fallthrough */
-	case 256:
-	case 512:
-	case 1024:
-	case 2048:
-		break;
-	}
+	const struct drm_framebuffer *fb = plane_state->base.fb;
 
 	return CURSOR_ENABLE |
 		CURSOR_GAMMA_ENABLE |
 		CURSOR_FORMAT_ARGB |
-		CURSOR_STRIDE(stride);
+		CURSOR_STRIDE(fb->pitches[0]);
 }
 
 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
@@ -9265,8 +9251,6 @@ static int i845_check_cursor(struct inte
 			     struct intel_plane_state *plane_state)
 {
 	const struct drm_framebuffer *fb = plane_state->base.fb;
-	const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
-	unsigned int stride;
 	int ret;
 
 	ret = intel_check_cursor(crtc_state, plane_state);
@@ -9274,7 +9258,7 @@ static int i845_check_cursor(struct inte
 		return ret;
 
 	/* if we want to turn off the cursor ignore width and height */
-	if (!obj)
+	if (!fb)
 		return 0;
 
 	/* Check for which cursor types we support */
@@ -9285,10 +9269,16 @@ static int i845_check_cursor(struct inte
 		return -EINVAL;
 	}
 
-	stride = roundup_pow_of_two(plane_state->base.crtc_w) * 4;
-	if (obj->base.size < stride * plane_state->base.crtc_h) {
-		DRM_DEBUG_KMS("buffer is too small\n");
-		return -ENOMEM;
+	switch (fb->pitches[0]) {
+	case 256:
+	case 512:
+	case 1024:
+	case 2048:
+		break;
+	default:
+		DRM_DEBUG_KMS("Invalid cursor stride (%u)\n",
+			      fb->pitches[0]);
+		return -EINVAL;
 	}
 
 	plane_state->ctl = i845_cursor_ctl(crtc_state, plane_state);
@@ -9421,9 +9411,7 @@ static int i9xx_check_cursor(struct inte
 {
 	struct drm_i915_private *dev_priv = to_i915(plane->base.dev);
 	const struct drm_framebuffer *fb = plane_state->base.fb;
-	const struct drm_i915_gem_object *obj = intel_fb_obj(fb);
 	enum pipe pipe = plane->pipe;
-	unsigned int stride;
 	int ret;
 
 	ret = intel_check_cursor(crtc_state, plane_state);
@@ -9431,7 +9419,7 @@ static int i9xx_check_cursor(struct inte
 		return ret;
 
 	/* if we want to turn off the cursor ignore width and height */
-	if (!obj)
+	if (!fb)
 		return 0;
 
 	/* Check for which cursor types we support */
@@ -9442,10 +9430,10 @@ static int i9xx_check_cursor(struct inte
 		return -EINVAL;
 	}
 
-	stride = roundup_pow_of_two(plane_state->base.crtc_w) * 4;
-	if (obj->base.size < stride * plane_state->base.crtc_h) {
-		DRM_DEBUG_KMS("buffer is too small\n");
-		return -ENOMEM;
+	if (fb->pitches[0] != plane_state->base.crtc_w * fb->format->cpp[0]) {
+		DRM_DEBUG_KMS("Invalid cursor stride (%u) (cursor width %d)\n",
+			      fb->pitches[0], plane_state->base.crtc_w);
+		return -EINVAL;
 	}
 
 	/*