[PATCH 08/13] drm/i915: Use proper locking for intel_dp_check_link_status.

Maarten Lankhorst
2015-07-16T09:01:08Z

To look at encoder->crtc->state the crtc mutex is required.
Get rid of connectors_active, and only check crtc state.

Signed-off-by: Maarten Lankhorst <maarten.lankhorst@linux.intel.com>
---
drivers/gpu/drm/i915/intel_dp.c | 34 +++++++++++++++++++++++++---------
1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
index cea7d1785d13..4b16023fffd0 100644
--- a/drivers/gpu/drm/i915/intel_dp.c
+++ b/drivers/gpu/drm/i915/intel_dp.c
@@ -4235,19 +4235,17 @@ intel_dp_check_link_status(struct intel_dp *intel_dp)
{
struct drm_device *dev = intel_dp_to_dev(intel_dp);
struct intel_encoder *intel_encoder = &dp_to_dig_port(intel_dp)->base;
+ struct drm_crtc *crtc;
u8 sink_irq_vector;
u8 link_status[DP_LINK_STATUS_SIZE];

- WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
-
- if (!intel_encoder->connectors_active)
- return;

- if (WARN_ON(!intel_encoder->base.crtc))
+ crtc = intel_encoder->base.crtc;
+ if (!crtc || !crtc->state->active)
return;

- if (!to_intel_crtc(intel_encoder->base.crtc)->active)
- return;
+ WARN_ON(!drm_modeset_is_locked(&dev->mode_config.connection_mutex));
+ WARN_ON(!drm_modeset_is_locked(&crtc->mutex));

/* Try to read receiver status if the link appears to be up */
if (!intel_dp_get_link_status(intel_dp, link_status)) {
@@ -4906,13 +4904,31 @@ intel_dp_hpd_pulse(struct intel_digital_port *intel_dig_port, bool long_hpd)
}

if (!intel_dp->is_mst) {
+ struct drm_modeset_acquire_ctx ctx;
+
+ drm_modeset_acquire_init(&ctx, 0);
+
+ while (1) {
+ int ret;
+
+ ret = drm_modeset_lock(&dev->mode_config.connection_mutex, &ctx);
+ if (!ret && intel_encoder->base.crtc)
+ ret = drm_modeset_lock(&intel_encoder->base.crtc->mutex, &ctx);
+
+ if (!ret || WARN_ON(ret != -EDEADLK))
+ break;
+
+ drm_modeset_backoff(&ctx);
+ }
+
/*
* we'll check the link status via the normal hot plug path later -
* but for short hpds we should check it now
*/
- drm_modeset_lock(&dev->mode_config.connection_mutex, NULL);
intel_dp_check_link_status(intel_dp);
- drm_modeset_unlock(&dev->mode_config.connection_mutex);
+
+ drm_modeset_drop_locks(&ctx);
+ drm_modeset_acquire_fini(&ctx);
}
}

--
2.1.0