drm/amd/display: turn DPMS off on mst connector unplug
Subsystems (3)
PATCH 1/1 drm/amd/display: turn DPMS off on mst connector unplug
[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.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +62 -1
@@ -1984,6 +1984,64 @@ static void dm_gpureset_commit_state(struct dc_state *dc_state,return ; } +static void dm_set_dpms_off (struct dc_link *link) +{ +struct { +struct dc_surface_update surface_updates[MAX_SURFACES ]; +struct dc_stream_update stream_update; + } * bundle; +struct dc_stream_state *stream_state; +struct dc_context *dc_ctx = link->ctx; +int i; + + bundle =kzalloc (sizeof (*bundle),GFP_KERNEL ); + +if (!bundle) { +dm_error ("Failed to allocate update bundle\n" ); +return ; + } + + bundle->stream_update.dpms_off =kzalloc (sizeof (bool ),GFP_KERNEL ); + +if (!bundle->stream_update.dpms_off) { +dm_error ("Failed to allocate update bundle\n" ); + goto cleanup; + } + + *bundle->stream_update.dpms_off = true; + +for (i =0 ; i<MAX_PIPES ; i++) { +if (dc_ctx->dc->current_state->streams[i] ==NULL ) +continue ; + +if (dc_ctx->dc->current_state->streams[i]->link == link) { + stream_state = dc_ctx->dc->current_state->streams[i]; + goto link_found; + } + } + +dm_error ("Cannot find link associated with the stream to be disabled\n" ); +return ; + +link_found: +if (stream_state ==NULL ) { +dm_error ("Stream state associated with the link is NULL\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); + +kfree (bundle->stream_update.dpms_off); +cleanup: +kfree (bundle); + +return ; +} +static int dm_resume (void *handle) {struct amdgpu_device *adev = handle;
@@ -2434,8 +2492,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);
Signature · 6 lines
2.25.1 _______________________________________________ amd-gfx mailing list [email protected] https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 27 lines · Aurabindo Pillai
[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 <[email protected]>Signed-off-by Eryk Brol <[email protected]>--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 63 ++++++++++++++++++- 1 file changed, 62 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8
-0@@ -1984,6 +1984,64 @@ static void dm_gpureset_commit_state(struct dc_state *dc_state,return ; } +static void dm_set_dpms_off (struct dc_link *link) +{ +struct { +struct dc_surface_update surface_updates[MAX_SURFACES ]; +struct dc_stream_update stream_update; + } * bundle; +struct dc_stream_state *stream_state; +struct dc_context *dc_ctx = link->ctx;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void dm_gpureset_commit_state(struct dc_state *dc_state, · line 2004
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10
-0+int i; + + bundle =kzalloc (sizeof (*bundle),GFP_KERNEL ); + +if (!bundle) { +dm_error ("Failed to allocate update bundle\n" ); +return ; + } + + bundle->stream_update.dpms_off =kzalloc (sizeof (bool ),GFP_KERNEL );
You don't need to allocate memory for the bool. You can just use a local here, DC doesn't need it after the call ends.
I think the same should apply to the surface updates as well. I'm not entirely sure how much stack the bundle takes up for a single stream here but it should be small enough that we can leave it on the stack.
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7
-0+ +if (!bundle->stream_update.dpms_off) { +dm_error ("Failed to allocate update bundle\n" ); + goto cleanup; + } + + *bundle->stream_update.dpms_off = true;
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void dm_gpureset_commit_state(struct dc_state *dc_state, · line 2021
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10
-0+ +for (i =0 ; i<MAX_PIPES ; i++) { +if (dc_ctx->dc->current_state->streams[i] ==NULL ) +continue ; + +if (dc_ctx->dc->current_state->streams[i]->link == link) { + stream_state = dc_ctx->dc->current_state->streams[i]; + goto link_found; + } + }
We shouldn't be reading from dc->current_state directly in DM, it's essentially private state.
I think we should actually have a new helper here in dc_stream.h that's like:
struct dc_stream_state *dc_stream_find_from_link(const struct dc_link *link);
to replace this block of code.
Note that any time we touch current_state we also need to be locking - it looks like this function is missing the appropriate calls to:
mutex_lock(&adev->dm.dc_lock);mutex_unlock(&adev->dm.dc_lock);
Regards,
Nicholas Kazlauskas
Quoted 30 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +23
-0+ +dm_error ("Cannot find link associated with the stream to be disabled\n" ); +return ; + +link_found: +if (stream_state ==NULL ) { +dm_error ("Stream state associated with the link is NULL\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); + +kfree (bundle->stream_update.dpms_off); +cleanup: +kfree (bundle); + +return ; +} +static int dm_resume (void *handle) {struct amdgpu_device *adev = handle;@@ -2434,8 +2492,11 @@ static void handle_hpd_irq(void *param)drm_kms_helper_hotplug_event (dev);
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void handle_hpd_irq(void *param) · line 2502
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +4
-1}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);
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx
Quoted 77 lines · Nicholas
Quoted 29 lines · Aurabindo Pillai
[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 <[email protected]>Signed-off-by Eryk Brol <[email protected]>---
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 63 ++++++++++++++++++-1 file changed, 62 insertions(+), 1 deletion(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7
-0@@ -1984,6 +1984,64 @@ static void dm_gpureset_commit_state(structdc_state *dc_state, return; } +static void dm_set_dpms_off(struct dc_link *link) +{ + struct { + struct dc_surface_update surface_updates[MAX_SURFACES]; + struct dc_stream_update stream_update; + } * bundle; + struct dc_stream_state *stream_state; + struct dc_context *dc_ctx = link->ctx;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void dm_gpureset_commit_state(struct · line 2004
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10
-0+ int i; + + bundle = kzalloc(sizeof(*bundle), GFP_KERNEL); + + if (!bundle) { + dm_error("Failed to allocate update bundle\n"); + return; + } + + bundle->stream_update.dpms_off = kzalloc(sizeof(bool), GFP_KERNEL);You don't need to allocate memory for the bool. You can just use a local here, DC doesn't need it after the call ends.
I think the same should apply to the surface updates as well. I'm not entirely sure how much stack the bundle takes up for a single stream here but it should be small enough that we can leave it on the stack.
Quoted 7 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +7
-0+ + if (!bundle->stream_update.dpms_off) { + dm_error("Failed to allocate update bundle\n"); + goto cleanup; + } + + *bundle->stream_update.dpms_off = true;drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static void dm_gpureset_commit_state(struct dc_state *dc_state, · line 2021
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +10
-0+ + for (i = 0; i< MAX_PIPES; i++) { + if (dc_ctx->dc->current_state->streams[i] == NULL) + continue; + + if (dc_ctx->dc->current_state->streams[i]->link == link) { + stream_state = dc_ctx->dc->current_state->streams[i]; + goto link_found; + } + }We shouldn't be reading from
dc->current_statedirectly in DM, it's essentially private state.I think we should actually have a new helper here in
dc_stream.hthat's like:struct
dc_stream_state*dc_stream_find_from_link(const structdc_link*link);to replace this block of code.
Quoted 10 lines
Note that any time we touch
current_statewe also need to be locking - it looks like this function is missing the appropriate calls to:
mutex_lock(&adev->dm.dc_lock);mutex_unlock(&adev->dm.dc_lock);Regards,
Nicholas Kazlauskas
Thank you for the review. Sent a v2
_______________________________________________
amd-gfx mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/amd-gfx