4adbe9d
From: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
4adbe9d
Date: Wed, 20 May 2015 16:32:34 +0300
4adbe9d
Subject: [PATCH] drm/i915: Fix ilk watermarks calculation when primary plane
4adbe9d
 is disabled
4adbe9d
4adbe9d
On Fedora 21 or 22, when the transition from the X server to the wayland
4adbe9d
compositor is done, the CRTC with the login screen is left active with a
4adbe9d
disabled fb. A cursor ioctl after the transition causes the watermarks
4adbe9d
to be updated, but due to the logic in intel_crtc_active() checking for
4adbe9d
the primary plane fb, the update considers all planes to be disabled,
4adbe9d
untimately setting the wrong watermark values and causing screen
4adbe9d
flicker. Since the crtc is active, a modeset done later is skipped and
4adbe9d
replaced with a flip, which doesn't update the watermarks.
4adbe9d
4adbe9d
This regression was introduced somewhere between v3.16 and v3.17.
4adbe9d
Another issue prevented me from doing a full bisect, but the issue was
4adbe9d
introduced in one of the following skipped commits:
4adbe9d
4adbe9d
    commit 7707e6535f43328e05e4729ac96eee864b90e8a4
4adbe9d
    Author: Rob Clark <robdclark@gmail.com>
4adbe9d
    Date:   Thu Jul 17 23:30:04 2014 -0400
4adbe9d
4adbe9d
        drm/i915: use helpers
4adbe9d
4adbe9d
    commit ca5a1b9ba0fb5291b555a23b76dbe5f6c30bfd7a
4adbe9d
    Merge: c7dbc6c 3488229
4adbe9d
    Author: Dave Airlie <airlied@redhat.com>
4adbe9d
    Date:   Wed Jul 9 10:38:42 2014 +1000
4adbe9d
4adbe9d
        Merge tag 'drm-intel-next-2014-06-20' of git://anongit.freedesktop.org/drm-intel into drm-next
4adbe9d
4adbe9d
    commit c51f71679042a5f388d9580ffbede14c897f1e86
4adbe9d
    Merge: b957f45 7b3c29f
4adbe9d
    Author: Dave Airlie <airlied@redhat.com>
4adbe9d
    Date:   Sat Jul 19 16:43:41 2014 +1000
4adbe9d
4adbe9d
        Merge tag 'drm-intel-next-2014-07-11' of git://anongit.freedesktop.org/drm-intel into drm-next
4adbe9d
4adbe9d
This patch is a simplified version of the following commits:
4adbe9d
4adbe9d
    commit 3dd512fbda0d87d1c3fb44bf878b262baee98fb6
4adbe9d
    Author: Matt Roper <matthew.d.roper@intel.com>
4adbe9d
    Date:   Fri Feb 27 10:12:00 2015 -0800
4adbe9d
4adbe9d
        drm/i915: Kill intel_crtc->cursor_{width, height} (v2)
4adbe9d
4adbe9d
    commit 54da691deb123c045259ebf4f5c67381244f58f1
4adbe9d
    Author: Thomas Gummerer <t.gummerer@gmail.com>
4adbe9d
    Date:   Thu May 14 09:16:39 2015 +0200
4adbe9d
4adbe9d
        drm/i915: fix screen flickering
4adbe9d
4adbe9d
    commit 3ef00284e6a48f7deb0784ccca0478ebb7d4bcfc
4adbe9d
    Author: Matt Roper <matthew.d.roper@intel.com>
4adbe9d
    Date:   Mon Mar 9 10:19:24 2015 -0700
4adbe9d
4adbe9d
        drm/i915: Use crtc->state->active in ilk/skl watermark calculations (v3)
4adbe9d
4adbe9d
Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=90508
4adbe9d
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=1218688
4adbe9d
Cc: stable@vger.kernel.org
4adbe9d
Cc: Dave Airlie <airlied@gmail.com>
4adbe9d
Cc: Jani Nikula <jani.nikula@intel.com>
4adbe9d
Signed-off-by: Ander Conselvan de Oliveira <ander.conselvan.de.oliveira@intel.com>
4adbe9d
---
4adbe9d
 drivers/gpu/drm/i915/intel_pm.c | 14 +++++++++++---
4adbe9d
 1 file changed, 11 insertions(+), 3 deletions(-)
4adbe9d
4adbe9d
diff --git a/drivers/gpu/drm/i915/intel_pm.c b/drivers/gpu/drm/i915/intel_pm.c
4adbe9d
index 24d77ddcc5f4..3d67f8e496de 100644
4adbe9d
--- a/drivers/gpu/drm/i915/intel_pm.c
4adbe9d
+++ b/drivers/gpu/drm/i915/intel_pm.c
4adbe9d
@@ -1898,16 +1898,24 @@ static void ilk_compute_wm_parameters(struct drm_crtc *crtc,
4adbe9d
 	enum pipe pipe = intel_crtc->pipe;
4adbe9d
 	struct drm_plane *plane;
4adbe9d
 
4adbe9d
-	if (!intel_crtc_active(crtc))
4adbe9d
+	if (!intel_crtc->active)
4adbe9d
 		return;
4adbe9d
 
4adbe9d
 	p->active = true;
4adbe9d
 	p->pipe_htotal = intel_crtc->config->base.adjusted_mode.crtc_htotal;
4adbe9d
 	p->pixel_rate = ilk_pipe_pixel_rate(dev, crtc);
4adbe9d
-	p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8;
4adbe9d
+
4adbe9d
+
4adbe9d
+	if (crtc->primary->fb)
4adbe9d
+		p->pri.bytes_per_pixel = crtc->primary->fb->bits_per_pixel / 8;
4adbe9d
+	else
4adbe9d
+		p->pri.bytes_per_pixel = 4;
4adbe9d
+
4adbe9d
 	p->cur.bytes_per_pixel = 4;
4adbe9d
+
4adbe9d
 	p->pri.horiz_pixels = intel_crtc->config->pipe_src_w;
4adbe9d
-	p->cur.horiz_pixels = intel_crtc->cursor_width;
4adbe9d
+	p->cur.horiz_pixels = intel_crtc->base.cursor->state->crtc_w;
4adbe9d
+
4adbe9d
 	/* TODO: for now, assume primary and cursor planes are always enabled. */
4adbe9d
 	p->pri.enabled = true;
4adbe9d
 	p->cur.enabled = true;