[PATCH v2] drm/amd/display: turn DPMS off on mst connector unplug

Kazlauskas, Nicholas nicholas.kazlauskas at amd.com
Thu Nov 26 22:00:21 UTC 2020


On 2020-11-26 4:45 p.m., Aurabindo Pillai wrote:
> [Why&How]
> 
> Set dpms off on the MST connector that was unplugged, for the side effect of
> releasing some references held through deallocation of mst payload.
> 
> Signed-off-by: Aurabindo Pillai <aurabindo.pillai at amd.com>
> Signed-off-by: Eryk Brol <eryk.brol at amd.com>
> ---
>   .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 33 ++++++++++++++++++-
>   drivers/gpu/drm/amd/display/dc/core/dc.c      | 17 ++++++++++
>   drivers/gpu/drm/amd/display/dc/dc_stream.h    |  1 +
>   3 files changed, 50 insertions(+), 1 deletion(-)
> 
> diff --git a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> index e213246e3f04..6203cbf3ee33 100644
> --- a/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> +++ b/drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
> @@ -1984,6 +1984,34 @@ static void dm_gpureset_commit_state(struct dc_state *dc_state,
>   	return;
>   }
>   
> +static void dm_set_dpms_off(struct dc_link *link)
> +{
> +	struct dc_stream_state *stream_state;
> +	struct amdgpu_dm_connector *aconnector = link->priv;
> +	struct amdgpu_device *adev = drm_to_adev(aconnector->base.dev);
> +	struct {
> +		struct dc_surface_update surface_updates[MAX_SURFACES];

Let's remove the bundle and drop the surface_updates here. A 
surface_count of 0 should be sufficient to guard against NULL 
surface_updates array.

> +		struct dc_stream_update stream_update;
> +	} bundle = {0};
> +	bool dpms_off = true;
> +
> +	bundle.stream_update.dpms_off = &dpms_off;
> +
> +	mutex_lock(&adev->dm.dc_lock);
> +	stream_state = dc_stream_find_from_link(link);
> +	mutex_unlock(&adev->dm.dc_lock);

This needs to be move under dc_commit_updates_for_stream(). It's not 
safe to call dc_commit_updates_for_stream while unlocked since it 
modifies global state.

> +
> +	if (stream_state == NULL) {
> +		dm_error("Error finding stream state associated with link!\n");
> +		return;
> +	}
> +
> +	bundle.stream_update.stream = stream_state;
> +	dc_commit_updates_for_stream(stream_state->ctx->dc, bundle.surface_updates, 0,
> +				     stream_state, &bundle.stream_update,
> +				     stream_state->ctx->dc->current_state);
> +}
> +
>   static int dm_resume(void *handle)
>   {
>   	struct amdgpu_device *adev = handle;
> @@ -2434,8 +2462,11 @@ static void handle_hpd_irq(void *param)
>   			drm_kms_helper_hotplug_event(dev);
>   
>   	} else if (dc_link_detect(aconnector->dc_link, DETECT_REASON_HPD)) {
> -		amdgpu_dm_update_connector_after_detect(aconnector);
> +		if (new_connection_type == dc_connection_none &&
> +		    aconnector->dc_link->type == dc_connection_none)
> +			dm_set_dpms_off(aconnector->dc_link);
>   
> +		amdgpu_dm_update_connector_after_detect(aconnector);
>   
>   		drm_modeset_lock_all(dev);
>   		dm_restore_drm_connector_state(dev, connector);
> diff --git a/drivers/gpu/drm/amd/display/dc/core/dc.c b/drivers/gpu/drm/amd/display/dc/core/dc.c
> index 903353389edb..7a2b2802faa2 100644
> --- a/drivers/gpu/drm/amd/display/dc/core/dc.c
> +++ b/drivers/gpu/drm/amd/display/dc/core/dc.c
> @@ -2798,6 +2798,23 @@ struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i)
>   	return NULL;
>   }
>   
> +struct dc_stream_state *dc_stream_find_from_link(const struct dc_link *link)
> +{
> +	uint8_t i;
> +	struct dc_context *ctx = link->ctx;
> +
> +	for (i = 0; i< MAX_PIPES; i++) {
> +		if (ctx->dc->current_state->streams[i] == NULL)
> +			continue;

Drop the NULL check above and change MAX_PIPES to 
dc->current_state->stream_count.

Regards,
Nicholas Kazlauskas

> +
> +		if (ctx->dc->current_state->streams[i]->link == link) {
> +			return ctx->dc->current_state->streams[i];
> +		}
> +	}
> +
> +	return NULL;
> +}
> +
>   enum dc_irq_source dc_interrupt_to_irq_source(
>   		struct dc *dc,
>   		uint32_t src_id,
> diff --git a/drivers/gpu/drm/amd/display/dc/dc_stream.h b/drivers/gpu/drm/amd/display/dc/dc_stream.h
> index bf090afc2f70..b7910976b81a 100644
> --- a/drivers/gpu/drm/amd/display/dc/dc_stream.h
> +++ b/drivers/gpu/drm/amd/display/dc/dc_stream.h
> @@ -292,6 +292,7 @@ void dc_stream_log(const struct dc *dc, const struct dc_stream_state *stream);
>   
>   uint8_t dc_get_current_stream_count(struct dc *dc);
>   struct dc_stream_state *dc_get_stream_at_index(struct dc *dc, uint8_t i);
> +struct dc_stream_state *dc_stream_find_from_link(const struct dc_link *link);
>   
>   /*
>    * Return the current frame counter.
> 



More information about the amd-gfx mailing list