Blob Blame History Raw
From 3637ecf095c80f3d19947d8af41869289f71ef1c 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:40 +0300
Subject: [PATCH] drm/i915: Generalize cursor size checks a bit
Mime-version: 1.0
Content-type: text/plain; charset=UTF-8
Content-transfer-encoding: 8bit
Git-commit: 3637ecf095c80f3d19947d8af41869289f71ef1c
Patch-mainline: v4.13-rc1
References: FATE#322643 bsc#1055900

We have the maximum cursor dimensions stored in the mode_config, so
let's just consult that information instead of hardcoding the same
information in multiple places.

We still need to keep some per-platform checks as the limitations are
quite diverse.

Signed-off-by: Ville Syrjälä <ville.syrjala@linux.intel.com>
Link: http://patchwork.freedesktop.org/patch/msgid/20170327185546.2977-10-ville.syrjala@linux.intel.com
Reviewed-by: Imre Deak <imre.deak@intel.com>
Acked-by: Takashi Iwai <tiwai@suse.de>

---
 drivers/gpu/drm/i915/intel_display.c |   34 +++++++++++++---------------------
 1 file changed, 13 insertions(+), 21 deletions(-)

--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -9188,6 +9188,17 @@ static u32 intel_cursor_position(const s
 	return pos;
 }
 
+static bool intel_cursor_size_ok(const struct intel_plane_state *plane_state)
+{
+	const struct drm_mode_config *config =
+		&plane_state->base.plane->dev->mode_config;
+	int width = plane_state->base.crtc_w;
+	int height = plane_state->base.crtc_h;
+
+	return width > 0 && width <= config->cursor_width &&
+		height > 0 && height <= config->cursor_height;
+}
+
 static int intel_check_cursor(struct intel_crtc_state *crtc_state,
 			      struct intel_plane_state *plane_state)
 {
@@ -9240,28 +9251,13 @@ static u32 i845_cursor_ctl(const struct
 
 static bool i845_cursor_size_ok(const struct intel_plane_state *plane_state)
 {
-	struct drm_i915_private *dev_priv =
-		to_i915(plane_state->base.plane->dev);
 	int width = plane_state->base.crtc_w;
-	int height = plane_state->base.crtc_h;
-
-	if (width == 0 || height == 0)
-		return false;
 
 	/*
 	 * 845g/865g are only limited by the width of their cursors,
 	 * the height is arbitrary up to the precision of the register.
 	 */
-	if (!IS_ALIGNED(width, 64))
-		return false;
-
-	if (width > (IS_I845G(dev_priv) ? 64 : 512))
-		return false;
-
-	if (height > 1023)
-		return false;
-
-	return true;
+	return intel_cursor_size_ok(plane_state) && IS_ALIGNED(width, 64);
 }
 
 static int i845_check_cursor(struct intel_plane *plane,
@@ -9397,12 +9393,10 @@ static u32 i9xx_cursor_ctl(const struct
 
 static bool i9xx_cursor_size_ok(const struct intel_plane_state *plane_state)
 {
-	struct drm_i915_private *dev_priv =
-		to_i915(plane_state->base.plane->dev);
 	int width = plane_state->base.crtc_w;
 	int height = plane_state->base.crtc_h;
 
-	if (width == 0 || height == 0)
+	if (!intel_cursor_size_ok(plane_state))
 		return false;
 
 	/*
@@ -9412,8 +9406,6 @@ static bool i9xx_cursor_size_ok(const st
 	switch (width | height) {
 	case 256:
 	case 128:
-		if (IS_GEN2(dev_priv))
-			return false;
 	case 64:
 		break;
 	default: