[PATCH] drm/dp: add a hw mutex around the transfer functions.

Daniel Vetter daniel at ffwll.ch
Wed Jun 4 02:26:37 PDT 2014


On Wed, Jun 04, 2014 at 04:04:25PM +1000, Dave Airlie wrote:
> From: Dave Airlie <airlied at redhat.com>
> 
> This should avoid races between connector probing and HPD
> irqs in the future, currently mode_config.mutex blocks this
> possibility.
> 
> Signed-off-by: Dave Airlie <airlied at redhat.com>
> ---
>  drivers/gpu/drm/drm_dp_helper.c      | 15 +++++++++++++++
>  drivers/gpu/drm/i915/intel_dp.c      |  1 +
>  drivers/gpu/drm/radeon/atombios_dp.c |  2 ++
>  drivers/gpu/drm/tegra/dpaux.c        |  1 +
>  include/drm/drm_dp_helper.h          |  3 ++-
>  5 files changed, 21 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/drm_dp_helper.c b/drivers/gpu/drm/drm_dp_helper.c
> index 494219c..cb687f4 100644
> --- a/drivers/gpu/drm/drm_dp_helper.c
> +++ b/drivers/gpu/drm/drm_dp_helper.c
> @@ -382,7 +382,10 @@ static int drm_dp_dpcd_access(struct drm_dp_aux *aux, u8 request,
>  	 * transactions.
>  	 */
>  	for (retry = 0; retry < 7; retry++) {
> +
> +		mutex_lock(&aux->hw_mutex);
>  		err = aux->transfer(aux, &msg);
> +		mutex_unlock(&aux->hw_mutex);
>  		if (err < 0) {
>  			if (err == -EBUSY)
>  				continue;
> @@ -596,7 +599,9 @@ static int drm_dp_i2c_do_msg(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
>  	 * before giving up the AUX transaction.
>  	 */
>  	for (retry = 0; retry < 7; retry++) {
> +		mutex_lock(&aux->hw_mutex);
>  		err = aux->transfer(aux, msg);
> +		mutex_unlock(&aux->hw_mutex);
>  		if (err < 0) {
>  			if (err == -EBUSY)
>  				continue;
> @@ -761,3 +766,13 @@ void drm_dp_aux_unregister_i2c_bus(struct drm_dp_aux *aux)
>  	i2c_del_adapter(&aux->ddc);
>  }
>  EXPORT_SYMBOL(drm_dp_aux_unregister_i2c_bus);
> +
> +/**
> + * drm_dp_aux_init() - init a DP aux internal structure.
> + * @aux: DisplayPort AUX channel
> + */
> +void drm_dp_aux_init(struct drm_dp_aux *aux)
> +{
> +	mutex_init(&aux->hw_mutex);
> +}

Imo we should merge this with drm_dp_aux_register (and drop the i2c_bus
part of it since it'll be more generic) - no driver should call one
without the other.

With that address this is Reviewed-by: Daniel Vetter <daniel.vetter at ffwll.ch>

> +EXPORT_SYMBOL(drm_dp_aux_init);
> diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c
> index c4d8839..aa99dcb 100644
> --- a/drivers/gpu/drm/i915/intel_dp.c
> +++ b/drivers/gpu/drm/i915/intel_dp.c
> @@ -698,6 +698,7 @@ intel_dp_aux_init(struct intel_dp *intel_dp, struct intel_connector *connector)
>  	intel_dp->aux.name = name;
>  	intel_dp->aux.dev = dev->dev;
>  	intel_dp->aux.transfer = intel_dp_aux_transfer;
> +	drm_dp_aux_init(&intel_dp->aux);
>  
>  	DRM_DEBUG_KMS("registering %s bus for %s\n", name,
>  		      connector->base.kdev->kobj.name);
> diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c
> index 225f6c6..12d8784 100644
> --- a/drivers/gpu/drm/radeon/atombios_dp.c
> +++ b/drivers/gpu/drm/radeon/atombios_dp.c
> @@ -222,6 +222,8 @@ void radeon_dp_aux_init(struct radeon_connector *radeon_connector)
>  	radeon_connector->ddc_bus->rec.hpd = radeon_connector->hpd.hpd;
>  	radeon_connector->ddc_bus->aux.dev = radeon_connector->base.kdev;
>  	radeon_connector->ddc_bus->aux.transfer = radeon_dp_aux_transfer;
> +
> +	drm_dp_aux_init(&radeon_connector->ddc_bus->aux);
>  	ret = drm_dp_aux_register_i2c_bus(&radeon_connector->ddc_bus->aux);
>  	if (!ret)
>  		radeon_connector->ddc_bus->has_aux = true;
> diff --git a/drivers/gpu/drm/tegra/dpaux.c b/drivers/gpu/drm/tegra/dpaux.c
> index 005c19b..98cd70b 100644
> --- a/drivers/gpu/drm/tegra/dpaux.c
> +++ b/drivers/gpu/drm/tegra/dpaux.c
> @@ -331,6 +331,7 @@ static int tegra_dpaux_probe(struct platform_device *pdev)
>  
>  	dpaux->aux.transfer = tegra_dpaux_transfer;
>  	dpaux->aux.dev = &pdev->dev;
> +	drm_dp_aux_init(&dpaux->aux);
>  
>  	err = drm_dp_aux_register_i2c_bus(&dpaux->aux);
>  	if (err < 0)
> diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h
> index 488b416..09eee36 100644
> --- a/include/drm/drm_dp_helper.h
> +++ b/include/drm/drm_dp_helper.h
> @@ -546,7 +546,7 @@ struct drm_dp_aux {
>  	const char *name;
>  	struct i2c_adapter ddc;
>  	struct device *dev;
> -
> +	struct mutex hw_mutex;
>  	ssize_t (*transfer)(struct drm_dp_aux *aux,
>  			    struct drm_dp_aux_msg *msg);
>  };
> @@ -607,5 +607,6 @@ int drm_dp_link_configure(struct drm_dp_aux *aux, struct drm_dp_link *link);
>  
>  int drm_dp_aux_register_i2c_bus(struct drm_dp_aux *aux);
>  void drm_dp_aux_unregister_i2c_bus(struct drm_dp_aux *aux);
> +void drm_dp_aux_init(struct drm_dp_aux *aux);
>  
>  #endif /* _DRM_DP_HELPER_H_ */
> -- 
> 1.9.3
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/dri-devel

-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch


More information about the dri-devel mailing list