Skip to contentSkip to conversation

drm/atomic: Add helper for hw_done and fix suspend.

PATCH Superseded Maarten Lankhorst 3 participants 11 messages Jan 9, 2017 – Feb 9, 2017

Subsystems (4)

v1 of 2 Superseded Latest is v2 →

lore
Share & tools
lore

Maarten Lankhorst

author maintainer
#0 lore raw

cover drm/atomic: Add helper for hw_done and fix suspend.

Fix hw_done in i915 and make nouveau use drm_atomic_helper_disable_all() after fixing it to properly disable everything.

Maarten Lankhorst (3):
drm/atomic: move waiting for hw_done to a helper drm/i915: Wait for pending modesets to complete before trying link
training
drm/atomic: Make disable_all helper fully disable the crtc.

 drivers/gpu/drm/drm_atomic_helper.c       | 102 +++++++++++++++++++--------
 drivers/gpu/drm/i915/intel_dp.c           |  51 ++++++++++----
 drivers/gpu/drm/nouveau/nouveau_display.c | 113 +-----------------------------
 include/drm/drm_atomic_helper.h           |   1 +
 4 files changed, 115 insertions(+), 152 deletions(-)
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
author maintainer
#1 lore raw

PATCH 1/3 drm/atomic: move waiting for hw_done to a helper

This will allow i915 to perform a wait on pending modeset using the same code.

---
 drivers/gpu/drm/drm_atomic_helper.c | 51 +++++++++++++++++++++++++++----------
 include/drm/drm_atomic_helper.h     |  1 +
 2 files changed, 38 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +37 -14
index 7b71ac48b8a4..3a8a46510c36 100644
@@ -1936,6 +1936,41 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
 
 /**
+ * drm_atomic_helper_wait_for_hw_done - wait for all previous hw updates to complete.
+ * @crtc: crtc to wait on.
+ *
+ * This function waits for all previous hardware updates queued on @crtc
+ * to complete.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure.
+ */
+int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc)
+{
+	struct drm_crtc_commit *commit;
+	long ret;
+
+	spin_lock(&crtc->commit_lock);
+	commit = list_first_entry_or_null(&crtc->commit_list,
+			struct drm_crtc_commit, commit_entry);
+	if (commit)
+		drm_crtc_commit_get(commit);
+	spin_unlock(&crtc->commit_lock);
+
+	if (!commit)
+		return 0;
+
+	ret = wait_for_completion_timeout(&commit->hw_done, 10 * HZ);
+	drm_crtc_commit_put(commit);
+
+	if (ret == 0)
+		return -EBUSY;
+
+	return ret > 0 ? 0 : ret;
+}
+EXPORT_SYMBOL(drm_atomic_helper_wait_for_hw_done);
+
+/**
  * drm_atomic_helper_swap_state - store atomic state into current sw state
  * @state: atomic state
  * @stall: stall for proceeding commits
@@ -1976,26 +2011,14 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
 	struct drm_crtc_state *crtc_state;
 	struct drm_plane *plane;
 	struct drm_plane_state *plane_state;
-	struct drm_crtc_commit *commit;
 
 	if (stall) {
 		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			spin_lock(&crtc->commit_lock);
-			commit = list_first_entry_or_null(&crtc->commit_list,
-					struct drm_crtc_commit, commit_entry);
-			if (commit)
-				drm_crtc_commit_get(commit);
-			spin_unlock(&crtc->commit_lock);
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
 
-			if (!commit)
-				continue;
-
-			ret = wait_for_completion_timeout(&commit->hw_done,
-							  10*HZ);
-			if (ret == 0)
+			if (ret < 0)
 				DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n",
 					  crtc->base.id, crtc->name);
-			drm_crtc_commit_put(commit);
 		}
 	}
 
include/drm/drm_atomic_helper.h +1 -0
index 4b2353dc34ba..e15d2fe7b274 100644
@@ -77,6 +77,7 @@ void
 drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state,
 					 bool atomic);
 
+int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc);
 void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
 				  bool stall);
 
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#2 lore raw

Re: [PATCH 1/3] drm/atomic: move waiting for hw_done to a helper

Quoted 2 lines · Maarten Lankhorst

This will allow i915 to perform a wait on pending modeset using the same code.

I don't like commit messages that refer to the subject like this. I can't even see the subject when I'm replying so I have approximately zero idea what's being said here.

Quoted 38 lines
---
 drivers/gpu/drm/drm_atomic_helper.c | 51 +++++++++++++++++++++++++++----------
 include/drm/drm_atomic_helper.h     |  1 +
 2 files changed, 38 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +23 -0
index 7b71ac48b8a4..3a8a46510c36 100644
@@ -1936,6 +1936,41 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
 
 /**
+ * drm_atomic_helper_wait_for_hw_done - wait for all previous hw updates to complete.
+ * @crtc: crtc to wait on.
+ *
+ * This function waits for all previous hardware updates queued on @crtc
+ * to complete.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure.
+ */
+int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc)
+{
+	struct drm_crtc_commit *commit;
+	long ret;
+
+	spin_lock(&crtc->commit_lock);
+	commit = list_first_entry_or_null(&crtc->commit_list,
+			struct drm_crtc_commit, commit_entry);
+	if (commit)
+		drm_crtc_commit_get(commit);
+	spin_unlock(&crtc->commit_lock);
+
+	if (!commit)
+		return 0;

drivers/gpu/drm/drm_atomic_helper.c void drm_atomic_helper_cleanup_planes(struct drm_device *dev, · line 1971

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +10 -0
+
+	ret = wait_for_completion_timeout(&commit->hw_done, 10 * HZ);
+	drm_crtc_commit_put(commit);
+
+	if (ret == 0)
+		return -EBUSY;
+
+	return ret > 0 ? 0 : ret;
+}
+EXPORT_SYMBOL(drm_atomic_helper_wait_for_hw_done);

Seems sane enough. I was pondering if we could share the code with the other hw_done wait as well. But it grabs a different commit from the list, so not sure if we'd end up with less code or not.

Hmm. maybe pass the commit index from the caller all the way from the caller to preceeding_commit() (which would obviously need a rename)?

Quoted 53 lines
drivers/gpu/drm/drm_atomic_helper.c +4 -14
+
+/**
  * drm_atomic_helper_swap_state - store atomic state into current sw state
  * @state: atomic state
  * @stall: stall for proceeding commits
@@ -1976,26 +2011,14 @@ void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
 	struct drm_crtc_state *crtc_state;
 	struct drm_plane *plane;
 	struct drm_plane_state *plane_state;
-	struct drm_crtc_commit *commit;
 
 	if (stall) {
 		for_each_crtc_in_state(state, crtc, crtc_state, i) {
-			spin_lock(&crtc->commit_lock);
-			commit = list_first_entry_or_null(&crtc->commit_list,
-					struct drm_crtc_commit, commit_entry);
-			if (commit)
-				drm_crtc_commit_get(commit);
-			spin_unlock(&crtc->commit_lock);
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
 
-			if (!commit)
-				continue;
-
-			ret = wait_for_completion_timeout(&commit->hw_done,
-							  10*HZ);
-			if (ret == 0)
+			if (ret < 0)
 				DRM_ERROR("[CRTC:%d:%s] hw_done timed out\n",
 					  crtc->base.id, crtc->name);
-			drm_crtc_commit_put(commit);
 		}
 	}
 
include/drm/drm_atomic_helper.h +1 -0
index 4b2353dc34ba..e15d2fe7b274 100644
@@ -77,6 +77,7 @@ void
 drm_atomic_helper_disable_planes_on_crtc(struct drm_crtc_state *old_crtc_state,
 					 bool atomic);
 
+int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc);
 void drm_atomic_helper_swap_state(struct drm_atomic_state *state,
 				  bool stall);
 
Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#3 lore raw

Re: [Intel-gfx] [PATCH 1/3] drm/atomic: move waiting for hw_done to a helper

Op 26-01-17 om 19:29 schreef Ville Syrjälä:

Quoted 58 lines · Maarten Lankhorst
Quoted 2 lines

This will allow i915 to perform a wait on pending modeset using the same code.

I don't like commit messages that refer to the subject like this. I can't even see the subject when I'm replying so I have approximately zero idea what's being said here.

Quoted 37 lines
---
 drivers/gpu/drm/drm_atomic_helper.c | 51 +++++++++++++++++++++++++++----------
 include/drm/drm_atomic_helper.h     |  1 +
 2 files changed, 38 insertions(+), 14 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +23 -0
index 7b71ac48b8a4..3a8a46510c36 100644
@@ -1936,6 +1936,41 @@ void drm_atomic_helper_cleanup_planes(struct drm_device *dev,
 EXPORT_SYMBOL(drm_atomic_helper_cleanup_planes);
 
 /**
+ * drm_atomic_helper_wait_for_hw_done - wait for all previous hw updates to complete.
+ * @crtc: crtc to wait on.
+ *
+ * This function waits for all previous hardware updates queued on @crtc
+ * to complete.
+ *
+ * Returns:
+ * 0 on success, negative error code on failure.
+ */
+int drm_atomic_helper_wait_for_hw_done(struct drm_crtc *crtc)
+{
+	struct drm_crtc_commit *commit;
+	long ret;
+
+	spin_lock(&crtc->commit_lock);
+	commit = list_first_entry_or_null(&crtc->commit_list,
+			struct drm_crtc_commit, commit_entry);
+	if (commit)
+		drm_crtc_commit_get(commit);
+	spin_unlock(&crtc->commit_lock);
+
+	if (!commit)
+		return 0;

drivers/gpu/drm/drm_atomic_helper.c void drm_atomic_helper_cleanup_planes(struct drm_device *dev, · line 1971

Quoted 10 lines
drivers/gpu/drm/drm_atomic_helper.c +10 -0
+
+	ret = wait_for_completion_timeout(&commit->hw_done, 10 * HZ);
+	drm_crtc_commit_put(commit);
+
+	if (ret == 0)
+		return -EBUSY;
+
+	return ret > 0 ? 0 : ret;
+}
+EXPORT_SYMBOL(drm_atomic_helper_wait_for_hw_done);

Seems sane enough. I was pondering if we could share the code with the other hw_done wait as well. But it grabs a different commit from the list, so not sure if we'd end up with less code or not.

Quoted 2 lines

Hmm. maybe pass the commit index from the caller all the way from the caller to preceeding_commit() (which would obviously need a rename)?

I think this helper is useful for waiting for crtc idle, I'm not sure it's useful in general to wait for other commits, since we probably want to wait for all previous commits to be completed.

~Maarten

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#4 lore raw

PATCH 2/3 drm/i915: Wait for pending modesets to complete before trying link training

In reply to Maarten Lankhorst

We're protected by the connection_mutex lock against blocking modesets, but nonblocking modesets are performed without any locking. This is causing WARN in drm_wait_for_vblank and in general it's better to wait before modeset completes before trying anything.

---
 drivers/gpu/drm/i915/intel_dp.c | 51 +++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +39 -12
index fb12896bafee..71882d887393 100644
@@ -4080,24 +4080,38 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 link_status[DP_LINK_STATUS_SIZE];
+	struct drm_modeset_acquire_ctx ctx;
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	int ret;
+	struct drm_crtc *crtc;
 
-	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
+	if (ret)
+		goto out;
 
 	if (!intel_dp_get_link_status(intel_dp, link_status)) {
 		DRM_ERROR("Failed to get link status\n");
-		return;
+		goto out;
 	}
 
-	if (!intel_encoder->base.crtc)
-		return;
+	crtc = intel_connector->base.state->crtc;
+	if (!crtc)
+		goto out;
 
-	if (!to_intel_crtc(intel_encoder->base.crtc)->active)
-		return;
+	ret = drm_modeset_lock(&crtc->mutex, &ctx);
+	if (ret)
+		goto out;
+
+	if (!crtc->state->active)
+		goto out;
 
 	/* FIXME: we need to synchronize this sort of stuff with hardware
 	 * readout. Currently fast link training doesn't work on boot-up. */
 	if (!intel_dp->lane_count)
-		return;
+		goto out;
 
 	/* if link training is requested we should perform it always */
 	if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
@@ -4105,8 +4119,26 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
 			      intel_encoder->base.name);
 
+		if (drm_atomic_crtc_needs_modeset(crtc->state)) {
+			/* wait for atomic modeset to complete */
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
+			if (ret < 0)
+				DRM_ERROR("Waiting for hw_done timed out\n");
+		}
+
 		intel_dp_retrain_link(intel_dp);
 	}
+
+out:
+	if (ret == -EDEADLK) {
+		drm_modeset_backoff(&ctx);
+		goto retry;
+	}
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+	if (ret)
+		DRM_ERROR("Locking failed with %i\n", ret);
 }
 
 /*
@@ -4125,7 +4157,6 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 static bool
 intel_dp_short_pulse(struct intel_dp *intel_dp)
 {
-	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 sink_irq_vector = 0;
 	u8 old_sink_count = intel_dp->sink_count;
 	bool ret;
@@ -4164,9 +4195,7 @@ intel_dp_short_pulse(struct intel_dp *intel_dp)
 			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
 	}
 
-	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 	intel_dp_check_link_status(intel_dp);
-	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 
 	return true;
 }
@@ -4499,9 +4528,7 @@ intel_dp_long_pulse(struct intel_connector *intel_connector)
 		 * check links status, there has been known issues of
 		 * link loss triggerring long pulse!!!!
 		 */
-		drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 		intel_dp_check_link_status(intel_dp);
-		drm_modeset_unlock(&dev->mode_config.connection_mutex);
 		goto out;
 	}
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

Re: [PATCH 2/3] drm/i915: Wait for pending modesets to complete before trying link training

Quoted 61 lines · Maarten Lankhorst

We're protected by the connection_mutex lock against blocking modesets, but nonblocking modesets are performed without any locking. This is causing WARN in drm_wait_for_vblank and in general it's better to wait before modeset completes before trying anything.

---
 drivers/gpu/drm/i915/intel_dp.c | 51 +++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +21 -7
index fb12896bafee..71882d887393 100644
@@ -4080,24 +4080,38 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 link_status[DP_LINK_STATUS_SIZE];
+	struct drm_modeset_acquire_ctx ctx;
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	int ret;
+	struct drm_crtc *crtc;
 
-	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
+	if (ret)
+		goto out;
 
 	if (!intel_dp_get_link_status(intel_dp, link_status)) {
 		DRM_ERROR("Failed to get link status\n");
-		return;
+		goto out;
 	}
 
-	if (!intel_encoder->base.crtc)
-		return;
+	crtc = intel_connector->base.state->crtc;
+	if (!crtc)
+		goto out;
 
-	if (!to_intel_crtc(intel_encoder->base.crtc)->active)
-		return;
+	ret = drm_modeset_lock(&crtc->mutex, &ctx);
+	if (ret)
+		goto out;
+
+	if (!crtc->state->active)
+		goto out;
 
 	/* FIXME: we need to synchronize this sort of stuff with hardware
 	 * readout. Currently fast link training doesn't work on boot-up. */
 	if (!intel_dp->lane_count)
-		return;
+		goto out;
 
 	/* if link training is requested we should perform it always */
 	if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4126

Quoted 8 lines
drivers/gpu/drm/i915/intel_dp.c +5 -0
@@ -4105,8 +4119,26 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
 			      intel_encoder->base.name);
 
+		if (drm_atomic_crtc_needs_modeset(crtc->state)) {
+			/* wait for atomic modeset to complete */
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
+			if (ret < 0)
+				DRM_ERROR("Waiting for hw_done timed out\n");

I wonder if we should just skip the hw frobbing in this case. I guess it might still restore the link if the commit just somehow got stuck somewhere non-critical.

Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +3 -0
+		}
+
 		intel_dp_retrain_link(intel_dp);
 	}
+

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4141

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+out:
+	if (ret == -EDEADLK) {
+		drm_modeset_backoff(&ctx);
+		goto retry;
+	}
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+	if (ret)
+		DRM_ERROR("Locking failed with %i\n", ret);

This seems incorrect if we timed out on the wait. Maybe just clear ret after the hw_done wait?

Quoted 38 lines
drivers/gpu/drm/i915/intel_dp.c +0 -5
 }
 
 /*
@@ -4125,7 +4157,6 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 static bool
 intel_dp_short_pulse(struct intel_dp *intel_dp)
 {
-	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 sink_irq_vector = 0;
 	u8 old_sink_count = intel_dp->sink_count;
 	bool ret;
@@ -4164,9 +4195,7 @@ intel_dp_short_pulse(struct intel_dp *intel_dp)
 			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
 	}
 
-	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 	intel_dp_check_link_status(intel_dp);
-	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 
 	return true;
 }
@@ -4499,9 +4528,7 @@ intel_dp_long_pulse(struct intel_connector *intel_connector)
 		 * check links status, there has been known issues of
 		 * link loss triggerring long pulse!!!!
 		 */
-		drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 		intel_dp_check_link_status(intel_dp);
-		drm_modeset_unlock(&dev->mode_config.connection_mutex);
 		goto out;
 	}
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#6 lore raw

Re: [PATCH 2/3] drm/i915: Wait for pending modesets to complete before trying link training

Op 26-01-17 om 19:31 schreef Ville Syrjälä:

Quoted 65 lines · Maarten Lankhorst
Quoted 64 lines

We're protected by the connection_mutex lock against blocking modesets, but nonblocking modesets are performed without any locking. This is causing WARN in drm_wait_for_vblank and in general it's better to wait before modeset completes before trying anything.

---
 drivers/gpu/drm/i915/intel_dp.c | 51 +++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +21 -7
index fb12896bafee..71882d887393 100644
@@ -4080,24 +4080,38 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 link_status[DP_LINK_STATUS_SIZE];
+	struct drm_modeset_acquire_ctx ctx;
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	int ret;
+	struct drm_crtc *crtc;
 
-	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
+	if (ret)
+		goto out;
 
 	if (!intel_dp_get_link_status(intel_dp, link_status)) {
 		DRM_ERROR("Failed to get link status\n");
-		return;
+		goto out;
 	}
 
-	if (!intel_encoder->base.crtc)
-		return;
+	crtc = intel_connector->base.state->crtc;
+	if (!crtc)
+		goto out;
 
-	if (!to_intel_crtc(intel_encoder->base.crtc)->active)
-		return;
+	ret = drm_modeset_lock(&crtc->mutex, &ctx);
+	if (ret)
+		goto out;
+
+	if (!crtc->state->active)
+		goto out;
 
 	/* FIXME: we need to synchronize this sort of stuff with hardware
 	 * readout. Currently fast link training doesn't work on boot-up. */
 	if (!intel_dp->lane_count)
-		return;
+		goto out;
 
 	/* if link training is requested we should perform it always */
 	if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
@@ -4105,8 +4119,26 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
 			      intel_encoder->base.name);
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4126

Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +5 -0
+		if (drm_atomic_crtc_needs_modeset(crtc->state)) {
+			/* wait for atomic modeset to complete */
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
+			if (ret < 0)
+				DRM_ERROR("Waiting for hw_done timed out\n");

I wonder if we should just skip the hw frobbing in this case. I guess it might still restore the link if the commit just somehow got stuck somewhere non-critical.

Hm, we could check if the link training is still required after the wait. Maybe even do the wait unlocked, since it might take an arbitrary amount of time and then retry?

Quoted 49 lines
Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +3 -0
+		}
+
 		intel_dp_retrain_link(intel_dp);
 	}
+

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4141

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+out:
+	if (ret == -EDEADLK) {
+		drm_modeset_backoff(&ctx);
+		goto retry;
+	}
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+	if (ret)
+		DRM_ERROR("Locking failed with %i\n", ret);

This seems incorrect if we timed out on the wait. Maybe just clear ret after the hw_done wait?

Quoted 31 lines
drivers/gpu/drm/i915/intel_dp.c +0 -5
 }
 
 /*
@@ -4125,7 +4157,6 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 static bool
 intel_dp_short_pulse(struct intel_dp *intel_dp)
 {
-	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 sink_irq_vector = 0;
 	u8 old_sink_count = intel_dp->sink_count;
 	bool ret;
@@ -4164,9 +4195,7 @@ intel_dp_short_pulse(struct intel_dp *intel_dp)
 			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
 	}
 
-	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 	intel_dp_check_link_status(intel_dp);
-	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 
 	return true;
 }
@@ -4499,9 +4528,7 @@ intel_dp_long_pulse(struct intel_connector *intel_connector)
 		 * check links status, there has been known issues of
 		 * link loss triggerring long pulse!!!!
 		 */
-		drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 		intel_dp_check_link_status(intel_dp);
-		drm_modeset_unlock(&dev->mode_config.connection_mutex);
 		goto out;
 	}
 
Quoted 7 lines
Quoted 7 lines
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx

#7 lore raw

Re: [PATCH 2/3] drm/i915: Wait for pending modesets to complete before trying link training

Quoted 74 lines · Maarten Lankhorst

Op 26-01-17 om 19:31 schreef Ville Syrjälä:

Quoted 65 lines · Maarten Lankhorst
Quoted 64 lines

We're protected by the connection_mutex lock against blocking modesets, but nonblocking modesets are performed without any locking. This is causing WARN in drm_wait_for_vblank and in general it's better to wait before modeset completes before trying anything.

---
 drivers/gpu/drm/i915/intel_dp.c | 51 +++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +21 -7
index fb12896bafee..71882d887393 100644
@@ -4080,24 +4080,38 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 link_status[DP_LINK_STATUS_SIZE];
+	struct drm_modeset_acquire_ctx ctx;
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	int ret;
+	struct drm_crtc *crtc;
 
-	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
+	if (ret)
+		goto out;
 
 	if (!intel_dp_get_link_status(intel_dp, link_status)) {
 		DRM_ERROR("Failed to get link status\n");
-		return;
+		goto out;
 	}
 
-	if (!intel_encoder->base.crtc)
-		return;
+	crtc = intel_connector->base.state->crtc;
+	if (!crtc)
+		goto out;
 
-	if (!to_intel_crtc(intel_encoder->base.crtc)->active)
-		return;
+	ret = drm_modeset_lock(&crtc->mutex, &ctx);
+	if (ret)
+		goto out;
+
+	if (!crtc->state->active)
+		goto out;
 
 	/* FIXME: we need to synchronize this sort of stuff with hardware
 	 * readout. Currently fast link training doesn't work on boot-up. */
 	if (!intel_dp->lane_count)
-		return;
+		goto out;
 
 	/* if link training is requested we should perform it always */
 	if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||
@@ -4105,8 +4119,26 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
 			      intel_encoder->base.name);
 
Quoted 8 lines

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4126

Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +5 -0
+		if (drm_atomic_crtc_needs_modeset(crtc->state)) {
+			/* wait for atomic modeset to complete */
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
+			if (ret < 0)
+				DRM_ERROR("Waiting for hw_done timed out\n");

I wonder if we should just skip the hw frobbing in this case. I guess it might still restore the link if the commit just somehow got stuck somewhere non-critical.

Quoted 3 lines

Hm, we could check if the link training is still required after the wait. Maybe even do the wait unlocked, since it might take an arbitrary amount of time and then retry?

I'm not sure there's much point in trying to make this fancy. Link problems should not happen with any regularity.

Quoted 57 lines
Quoted 56 lines
Quoted 5 lines
drivers/gpu/drm/i915/intel_dp.c +3 -0
+		}
+
 		intel_dp_retrain_link(intel_dp);
 	}
+

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4141

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +10 -0
+out:
+	if (ret == -EDEADLK) {
+		drm_modeset_backoff(&ctx);
+		goto retry;
+	}
+
+	drm_modeset_drop_locks(&ctx);
+	drm_modeset_acquire_fini(&ctx);
+	if (ret)
+		DRM_ERROR("Locking failed with %i\n", ret);

This seems incorrect if we timed out on the wait. Maybe just clear ret after the hw_done wait?

Quoted 38 lines
drivers/gpu/drm/i915/intel_dp.c +0 -5
 }
 
 /*
@@ -4125,7 +4157,6 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 static bool
 intel_dp_short_pulse(struct intel_dp *intel_dp)
 {
-	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 sink_irq_vector = 0;
 	u8 old_sink_count = intel_dp->sink_count;
 	bool ret;
@@ -4164,9 +4195,7 @@ intel_dp_short_pulse(struct intel_dp *intel_dp)
 			DRM_DEBUG_DRIVER("CP or sink specific irq unhandled\n");
 	}
 
-	drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 	intel_dp_check_link_status(intel_dp);
-	drm_modeset_unlock(&dev->mode_config.connection_mutex);
 
 	return true;
 }
@@ -4499,9 +4528,7 @@ intel_dp_long_pulse(struct intel_connector *intel_connector)
 		 * check links status, there has been known issues of
 		 * link loss triggerring long pulse!!!!
 		 */
-		drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
 		intel_dp_check_link_status(intel_dp);
-		drm_modeset_unlock(&dev->mode_config.connection_mutex);
 		goto out;
 	}
 
Signature · 6 lines
2.7.4

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Signature · 6 lines
Ville Syrjälä
Intel OTC
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
author maintainer
#8 lore raw

Re: [PATCH 2/3] drm/i915: Wait for pending modesets to complete before trying link training

Op 09-02-17 om 13:34 schreef Ville Syrjälä:

Quoted 75 lines · Maarten Lankhorst
Quoted 74 lines

Op 26-01-17 om 19:31 schreef Ville Syrjälä:

Quoted 73 lines · Maarten Lankhorst
Quoted 61 lines

We're protected by the connection_mutex lock against blocking modesets, but nonblocking modesets are performed without any locking. This is causing WARN in drm_wait_for_vblank and in general it's better to wait before modeset completes before trying anything.

---
 drivers/gpu/drm/i915/intel_dp.c | 51 +++++++++++++++++++++++++++++++----------
 1 file changed, 39 insertions(+), 12 deletions(-)
drivers/gpu/drm/i915/intel_dp.c +21 -7
index fb12896bafee..71882d887393 100644
@@ -4080,24 +4080,38 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 	struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
 	struct drm_device *dev = intel_dp_to_dev(intel_dp);
 	u8 link_status[DP_LINK_STATUS_SIZE];
+	struct drm_modeset_acquire_ctx ctx;
+	struct intel_connector *intel_connector = intel_dp->attached_connector;
+	int ret;
+	struct drm_crtc *crtc;
 
-	WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+	drm_modeset_acquire_init(&ctx, 0);
+
+retry:
+	ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
+	if (ret)
+		goto out;
 
 	if (!intel_dp_get_link_status(intel_dp, link_status)) {
 		DRM_ERROR("Failed to get link status\n");
-		return;
+		goto out;
 	}
 
-	if (!intel_encoder->base.crtc)
-		return;
+	crtc = intel_connector->base.state->crtc;
+	if (!crtc)
+		goto out;
 
-	if (!to_intel_crtc(intel_encoder->base.crtc)->active)
-		return;
+	ret = drm_modeset_lock(&crtc->mutex, &ctx);
+	if (ret)
+		goto out;
+
+	if (!crtc->state->active)
+		goto out;
 
 	/* FIXME: we need to synchronize this sort of stuff with hardware
 	 * readout. Currently fast link training doesn't work on boot-up. */
 	if (!intel_dp->lane_count)
-		return;
+		goto out;
 
 	/* if link training is requested we should perform it always */
 	if ((intel_dp->compliance.test_type == DP_TEST_LINK_TRAINING) ||

drivers/gpu/drm/i915/intel_dp.c intel_dp_check_link_status(struct intel_dp *intel_dp) · line 4126

Quoted 8 lines
drivers/gpu/drm/i915/intel_dp.c +5 -0
@@ -4105,8 +4119,26 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
 		DRM_DEBUG_KMS("%s: channel EQ not ok, retraining\n",
 			      intel_encoder->base.name);
 
+		if (drm_atomic_crtc_needs_modeset(crtc->state)) {
+			/* wait for atomic modeset to complete */
+			ret = drm_atomic_helper_wait_for_hw_done(crtc);
+			if (ret < 0)
+				DRM_ERROR("Waiting for hw_done timed out\n");

I wonder if we should just skip the hw frobbing in this case. I guess it might still restore the link if the commit just somehow got stuck somewhere non-critical.

Quoted 5 lines
Quoted 3 lines

Hm, we could check if the link training is still required after the wait. Maybe even do the wait unlocked, since it might take an arbitrary amount of time and then retry?

I'm not sure there's much point in trying to make this fancy. Link problems should not happen with any regularity.

Indeed, lets just do the simple thing then.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

author maintainer
#9 lore raw

PATCH 3/3 drm/atomic: Make disable_all helper fully disable the crtc.

In reply to Maarten Lankhorst

It seems that nouveau requires this, so best to do this in the helper. This allows nouveau to use the atomic suspend helper.

---
 drivers/gpu/drm/drm_atomic_helper.c       |  51 ++++++++++----
 drivers/gpu/drm/nouveau/nouveau_display.c | 113 +-----------------------------
 2 files changed, 38 insertions(+), 126 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +37 -14
index 3a8a46510c36..f010a11874b9 100644
@@ -2436,9 +2436,13 @@ int drm_atomic_helper_disable_all(struct drm_device *dev,
 				  struct drm_modeset_acquire_ctx *ctx)
 {
 	struct drm_atomic_state *state;
+	struct drm_connector_state *conn_state;
 	struct drm_connector *conn;
-	struct drm_connector_list_iter conn_iter;
-	int err;
+	struct drm_plane_state *plane_state;
+	struct drm_plane *plane;
+	struct drm_crtc_state *crtc_state;
+	struct drm_crtc *crtc;
+	int ret, i;
 
 	state = drm_atomic_state_alloc(dev);
 	if (!state)
@@ -2446,29 +2450,48 @@ int drm_atomic_helper_disable_all(struct drm_device *dev,
 
 	state->acquire_ctx = ctx;
 
-	drm_connector_list_iter_get(dev, &conn_iter);
-	drm_for_each_connector_iter(conn, &conn_iter) {
-		struct drm_crtc *crtc = conn->state->crtc;
-		struct drm_crtc_state *crtc_state;
-
-		if (!crtc || conn->dpms != DRM_MODE_DPMS_ON)
-			continue;
-
+	drm_for_each_crtc(crtc, dev) {
 		crtc_state = drm_atomic_get_crtc_state(state, crtc);
 		if (IS_ERR(crtc_state)) {
-			err = PTR_ERR(crtc_state);
+			ret = PTR_ERR(crtc_state);
 			goto free;
 		}
 
 		crtc_state->active = false;
+
+		ret = drm_atomic_set_mode_prop_for_crtc(crtc_state, NULL);
+		if (ret < 0)
+			goto free;
+
+		ret = drm_atomic_add_affected_planes(state, crtc);
+		if (ret < 0)
+			goto free;
+
+		ret = drm_atomic_add_affected_connectors(state, crtc);
+		if (ret < 0)
+			goto free;
 	}
 
-	err = drm_atomic_commit(state);
+	for_each_connector_in_state(state, conn, conn_state, i) {
+		ret = drm_atomic_set_crtc_for_connector(conn_state, NULL);
+		if (ret < 0)
+			goto free;
+	}
+
+	for_each_plane_in_state(state, plane, plane_state, i) {
+		ret = drm_atomic_set_crtc_for_plane(plane_state, NULL);
+		if (ret < 0)
+			goto free;
+
+		drm_atomic_set_fb_for_plane(plane_state, NULL);
+	}
+
+	ret = drm_atomic_commit(state);
 free:
-	drm_connector_list_iter_put(&conn_iter);
 	drm_atomic_state_put(state);
-	return err;
+	return ret;
 }
+
 EXPORT_SYMBOL(drm_atomic_helper_disable_all);
 
 /**
drivers/gpu/drm/nouveau/nouveau_display.c +1 -112

125 lines not on this page · raw message

Signature · 6 lines
2.7.4

_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx
#10 lore raw

✓ Fi.CI.BAT: success for drm/atomic: Add helper for hw_done and fix suspend.

In reply to Maarten Lankhorst
== Series Details ==

== Series Details ==

Series: drm/atomic: Add helper for hw_done and fix suspend.
URL : https://patchwork.freedesktop.org/series/17712/
State : success

== Summary ==

Series 17712v1 drm/atomic: Add helper for hw_done and fix suspend.
https://patchwork.freedesktop.org/api/1.0/series/17712/revisions/1/mbox/

Test kms_force_connector_basic:

        Subgroup force-connector-state:
                dmesg-warn -> PASS       (fi-snb-2520m)
        Subgroup prune-stale-modes:
                skip       -> PASS       (fi-ivb-3520m)
fi-bdw-5557u     total:246  pass:232  dwarn:0   dfail:0   fail:0   skip:14 
fi-bsw-n3050     total:246  pass:207  dwarn:0   dfail:0   fail:0   skip:39 
fi-bxt-j4205     total:246  pass:224  dwarn:0   dfail:0   fail:0   skip:22 
fi-bxt-t5700     total:82   pass:69   dwarn:0   dfail:0   fail:0   skip:12 
fi-byt-j1900     total:246  pass:219  dwarn:0   dfail:0   fail:0   skip:27 
fi-byt-n2820     total:246  pass:215  dwarn:0   dfail:0   fail:0   skip:31 
fi-hsw-4770      total:246  pass:227  dwarn:0   dfail:0   fail:0   skip:19 
fi-hsw-4770r     total:246  pass:227  dwarn:0   dfail:0   fail:0   skip:19 
fi-ivb-3520m     total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-ivb-3770      total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-kbl-7500u     total:246  pass:225  dwarn:0   dfail:0   fail:0   skip:21 
fi-skl-6260u     total:246  pass:233  dwarn:0   dfail:0   fail:0   skip:13 
fi-skl-6700hq    total:246  pass:226  dwarn:0   dfail:0   fail:0   skip:20 
fi-skl-6700k     total:246  pass:222  dwarn:3   dfail:0   fail:0   skip:21 
fi-skl-6770hq    total:246  pass:233  dwarn:0   dfail:0   fail:0   skip:13 
fi-snb-2520m     total:246  pass:215  dwarn:0   dfail:0   fail:0   skip:31 
fi-snb-2600      total:246  pass:214  dwarn:0   dfail:0   fail:0   skip:32 

9ea6a075c23ea914695d57944c0e74cff0c6bff4 drm-tip: 2017y-01m-09d-16h-11m-21s UTC integration manifest 3e39051 drm/atomic: Make disable_all helper fully disable the crtc.
644e019 drm/i915: Wait for pending modesets to complete before trying link training 89362fc drm/atomic: move waiting for hw_done to a helper

== Logs ==

For more details see: https://intel-gfx-ci.01.org/CI/Patchwork_3458/
_______________________________________________
Intel-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/intel-gfx