diff mbox

drm/i915: add tons of modeset state checks

Message ID 1342028763-4244-1-git-send-email-daniel.vetter@ffwll.ch (mailing list archive)
State Superseded
Headers show

Commit Message

Daniel Vetter July 11, 2012, 5:46 p.m. UTC
... let's see how whether this catches anything earlier and I can
track down a few bugs.

v2: Add more checks and also add DRM_DEBUG_KMS output so that it's
clear which connector/encoder/crtc is being checked atm. Which proved
rather useful for debugging ...

v3: Add a WARN in the common encoder dpms function, now that also
modeset changes properly update the dpms state ...

Signed-Off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
---
 drivers/gpu/drm/i915/intel_display.c |   75 +++++++++++++++++++++++++++++++++-
 1 files changed, 74 insertions(+), 1 deletions(-)
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
index f5e8b10..779994d 100644
--- a/drivers/gpu/drm/i915/intel_display.c
+++ b/drivers/gpu/drm/i915/intel_display.c
@@ -3625,7 +3625,7 @@  void intel_connector_dpms(struct drm_connector *connector, int mode)
 	if (encoder->base.crtc)
 		intel_encoder_dpms(encoder, mode);
 	else
-		encoder->connectors_active = false;
+		WARN_ON(encoder->connectors_active != false);
 
 	intel_connector_check_state(to_intel_connector(connector));
 }
@@ -6823,6 +6823,75 @@  static bool intel_crtc_in_use(struct drm_crtc *crtc)
 			    base.head) \
 		if (mask & (1 <<(intel_crtc)->pipe)) \
 
+static void
+intel_modeset_check_state(struct drm_device *dev)
+{
+	struct intel_crtc *crtc;
+	struct intel_encoder *encoder;
+	struct intel_connector *connector;
+
+	list_for_each_entry(connector, &dev->mode_config.connector_list,
+			    base.head) {
+		/* This also checks the encoder/connector hw state with the
+		 * ->get_hw_state callbacks. */
+		intel_connector_check_state(connector);
+
+		WARN_ON(&connector->new_encoder->base != connector->base.encoder);
+	}
+
+	list_for_each_entry(encoder, &dev->mode_config.encoder_list,
+			    base.head) {
+		bool enabled = false;
+		bool active = false;
+		enum pipe pipe;
+
+		DRM_DEBUG_KMS("[ENCODER:%d:%s]\n",
+			      encoder->base.base.id,
+			      drm_get_encoder_name(&encoder->base));
+
+		WARN_ON(&encoder->new_crtc->base != encoder->base.crtc);
+		WARN_ON(encoder->connectors_active && !encoder->base.crtc);
+
+		list_for_each_entry(connector, &dev->mode_config.connector_list,
+				    base.head) {
+			if (connector->base.encoder != &encoder->base)
+				continue;
+			enabled = true;
+			if (connector->base.dpms == DRM_MODE_DPMS_ON)
+				active = true;
+		}
+		WARN_ON(!!encoder->base.crtc != enabled);
+		/* dpms on only implies active. */
+		WARN_ON(active && !encoder->base.crtc);
+		WARN_ON(encoder->get_hw_state(encoder, &pipe)
+			&& !encoder->base.crtc);
+	}
+
+	list_for_each_entry(crtc, &dev->mode_config.crtc_list,
+			    base.head) {
+		bool enabled = false;
+		bool active = false;
+
+		DRM_DEBUG_KMS("[CRTC:%d]\n",
+			      crtc->base.base.id);
+
+		WARN_ON(crtc->active && !crtc->base.enabled);
+
+		list_for_each_entry(encoder, &dev->mode_config.encoder_list,
+				    base.head) {
+			if (encoder->base.crtc != &crtc->base)
+				continue;
+			enabled = true;
+			if (encoder->connectors_active)
+				active = true;
+		}
+		WARN_ON(active != crtc->active);
+		WARN_ON(enabled != crtc->base.enabled);
+
+		assert_pipe(dev->dev_private, crtc->pipe, crtc->active);
+	}
+}
+
 bool intel_crtc_set_mode(struct drm_crtc *crtc,
 			 struct drm_display_mode *mode,
 			 int x, int y,
@@ -6942,6 +7011,8 @@  done:
 		crtc->mode = saved_mode;
 	}
 
+	intel_modeset_check_state(dev);
+
 	return ret;
 }
 
@@ -8160,6 +8231,8 @@  void intel_modeset_setup_hw_state(struct drm_device *dev)
 	}
 
 	intel_modeset_update_staged_output_state(dev);
+
+	intel_modeset_check_state(dev);
 }
 
 void intel_modeset_gem_init(struct drm_device *dev)