69f65af
From d40a5938a10a3ba73bce6395729fefd8b8bb1c07 Mon Sep 17 00:00:00 2001
e782766
From: Peter Robinson <pbrobinson@gmail.com>
69f65af
Date: Thu, 29 Jun 2017 10:05:05 +0100
69f65af
Subject: [PATCH] drm/vc4: Fix VBLANK handling in crtc->enable() path
e782766
e782766
When we are enabling a CRTC, drm_crtc_vblank_get() is called before
e782766
drm_crtc_vblank_on(), which is not supposed to happen (hence the
e782766
WARN_ON() in the code). To solve the problem, we delay the 'update
e782766
display list' operation after the CRTC is actually enabled.
e782766
e782766
Signed-off-by: Boris Brezillon <boris.brezillon@free-electrons.com>
e782766
---
e782766
 drivers/gpu/drm/vc4/vc4_crtc.c | 66 +++++++++++++++++++++++++++---------------
e782766
 1 file changed, 43 insertions(+), 23 deletions(-)
e782766
e782766
diff --git a/drivers/gpu/drm/vc4/vc4_crtc.c b/drivers/gpu/drm/vc4/vc4_crtc.c
69f65af
index d86c8cce3182..316bd6210d69 100644
e782766
--- a/drivers/gpu/drm/vc4/vc4_crtc.c
e782766
+++ b/drivers/gpu/drm/vc4/vc4_crtc.c
69f65af
@@ -530,6 +530,34 @@ static void vc4_crtc_disable(struct drm_crtc *crtc)
69f65af
 		     SCALER_DISPSTATX_EMPTY);
e782766
 }
e782766
 
e782766
+static void vc4_crtc_update_dlist(struct drm_crtc *crtc)
e782766
+{
e782766
+	struct drm_device *dev = crtc->dev;
e782766
+	struct vc4_dev *vc4 = to_vc4_dev(dev);
e782766
+	struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
e782766
+	struct vc4_crtc_state *vc4_state = to_vc4_crtc_state(crtc->state);
e782766
+
e782766
+	if (crtc->state->event) {
e782766
+		unsigned long flags;
e782766
+
e782766
+		crtc->state->event->pipe = drm_crtc_index(crtc);
e782766
+
e782766
+		WARN_ON(drm_crtc_vblank_get(crtc) != 0);
e782766
+
e782766
+		spin_lock_irqsave(&dev->event_lock, flags);
e782766
+		vc4_crtc->event = crtc->state->event;
e782766
+		crtc->state->event = NULL;
e782766
+
e782766
+		HVS_WRITE(SCALER_DISPLISTX(vc4_crtc->channel),
e782766
+			  vc4_state->mm.start);
e782766
+
e782766
+		spin_unlock_irqrestore(&dev->event_lock, flags);
e782766
+	} else {
e782766
+		HVS_WRITE(SCALER_DISPLISTX(vc4_crtc->channel),
e782766
+			  vc4_state->mm.start);
e782766
+	}
e782766
+}
e782766
+
e782766
 static void vc4_crtc_enable(struct drm_crtc *crtc)
e782766
 {
e782766
 	struct drm_device *dev = crtc->dev;
69f65af
@@ -540,6 +568,12 @@ static void vc4_crtc_enable(struct drm_crtc *crtc)
e782766
 
e782766
 	require_hvs_enabled(dev);
e782766
 
e782766
+	/* Enable vblank irq handling before crtc is started otherwise
e782766
+	 * drm_crtc_get_vblank() fails in vc4_crtc_update_dlist().
e782766
+	 */
e782766
+	drm_crtc_vblank_on(crtc);
e782766
+	vc4_crtc_update_dlist(crtc);
e782766
+
e782766
 	/* Turn on the scaler, which will wait for vstart to start
e782766
 	 * compositing.
e782766
 	 */
69f65af
@@ -551,9 +585,6 @@ static void vc4_crtc_enable(struct drm_crtc *crtc)
e782766
 	/* Turn on the pixel valve, which will emit the vstart signal. */
e782766
 	CRTC_WRITE(PV_V_CONTROL,
e782766
 		   CRTC_READ(PV_V_CONTROL) | PV_VCONTROL_VIDEN);
e782766
-
e782766
-	/* Enable vblank irq handling after crtc is started. */
e782766
-	drm_crtc_vblank_on(crtc);
e782766
 }
e782766
 
e782766
 static bool vc4_crtc_mode_fixup(struct drm_crtc *crtc,
69f65af
@@ -608,7 +639,6 @@ static void vc4_crtc_atomic_flush(struct drm_crtc *crtc,
e782766
 {
e782766
 	struct drm_device *dev = crtc->dev;
e782766
 	struct vc4_dev *vc4 = to_vc4_dev(dev);
e782766
-	struct vc4_crtc *vc4_crtc = to_vc4_crtc(crtc);
e782766
 	struct vc4_crtc_state *vc4_state = to_vc4_crtc_state(crtc->state);
e782766
 	struct drm_plane *plane;
e782766
 	bool debug_dump_regs = false;
69f65af
@@ -630,25 +660,15 @@ static void vc4_crtc_atomic_flush(struct drm_crtc *crtc,
e782766
 
e782766
 	WARN_ON_ONCE(dlist_next - dlist_start != vc4_state->mm.size);
e782766
 
e782766
-	if (crtc->state->event) {
e782766
-		unsigned long flags;
e782766
-
e782766
-		crtc->state->event->pipe = drm_crtc_index(crtc);
e782766
-
e782766
-		WARN_ON(drm_crtc_vblank_get(crtc) != 0);
e782766
-
e782766
-		spin_lock_irqsave(&dev->event_lock, flags);
e782766
-		vc4_crtc->event = crtc->state->event;
e782766
-		crtc->state->event = NULL;
e782766
-
e782766
-		HVS_WRITE(SCALER_DISPLISTX(vc4_crtc->channel),
e782766
-			  vc4_state->mm.start);
e782766
-
e782766
-		spin_unlock_irqrestore(&dev->event_lock, flags);
e782766
-	} else {
e782766
-		HVS_WRITE(SCALER_DISPLISTX(vc4_crtc->channel),
e782766
-			  vc4_state->mm.start);
e782766
-	}
e782766
+	/* Only update DISPLIST if the CRTC was already running and is not
e782766
+	 * being disabled.
e782766
+	 * vc4_crtc_enable() takes care of updating the dlist just after
e782766
+	 * re-enabling VBLANK interrupts and before enabling the engine.
e782766
+	 * If the CRTC is being disabled, there's no point in updating this
e782766
+	 * information.
e782766
+	 */
e782766
+	if (crtc->state->active && old_state->active)
e782766
+		vc4_crtc_update_dlist(crtc);
e782766
 
e782766
 	if (debug_dump_regs) {
e782766
 		DRM_INFO("CRTC %d HVS after:\n", drm_crtc_index(crtc));
e782766
-- 
e782766
2.13.0
e782766