drm/amd/display: Retry link detection when it fails
Subsystems (3)
cover drm/amd/display: Retry link detection when it fails
When dc_link_detect_connection_type thinks that a display is connected, but dc_link_detect failed, enqueue delayed work to retry the link detection again.
Useful when eg. HPD pin is high but the display isn't ready and didn't respond to DDC. Typically this may happen when the HPD pins make contact before the DDC pins, or when the display is "slow to wake up" and doesn't respond on DDC.
The first few patches are just a slight refactor to de-duplicate some code and do some cleanup necessary for the retry. This is to avoid adding even more duplicated code.
Timur Kristóf (5):
drm/amd/display: Add detect reason to handle_hpd_irq_helper drm/amd/display: Use handle_hpd_irq_helper for HPD RX drm/amd/display: Always create delayed HPD work queue drm/amd/display: Retry link detection on hotplug drm/amd/display: Retry link detection on resume and boot
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 216 +++++++++++++----- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 16 ++ 2 files changed, 179 insertions(+), 53 deletions(-)
Signature · 1 line
2.54.0
PATCH 1/5 drm/amd/display: Add detect reason to handle_hpd_irq_helper
This makes it possible to reuse the function for other purposes in the next few commits, such as HPD RX.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +11 -7
@@ -239,7 +239,8 @@ static void amdgpu_dm_atomic_commit_tail(struct drm_atomic_state *state);static int amdgpu_dm_atomic_check (struct drm_device *dev,struct drm_atomic_state *state); -static void handle_hpd_irq_helper (struct amdgpu_dm_connector *aconnector); +static void handle_hpd_irq_helper (struct amdgpu_dm_connector *aconnector, +enum dc_detect_reason reason);static void handle_hpd_rx_irq (void *param); static void amdgpu_dm_backlight_set_level(struct amdgpu_display_manager *dm,
@@ -887,7 +888,7 @@ static void dmub_hpd_callback(struct amdgpu_device *adev,if (notify->type ==DMUB_NOTIFICATION_HPD ) {if (hpd_aconnector->dc_link->hpd_status == (notify->hpd_status ==DP_HPD_PLUG ))drm_warn (adev_to_drm (adev),"DMUB reported hpd status unchanged. link_index=%u\n" , link_index); -handle_hpd_irq_helper (hpd_aconnector); +handle_hpd_irq_helper (hpd_aconnector,DETECT_REASON_HPD ); }else if (notify->type ==DMUB_NOTIFICATION_HPD_IRQ ) {handle_hpd_rx_irq (hpd_aconnector); }
@@ -4300,7 +4301,8 @@ static void hdmi_hpd_debounce_work(struct work_struct *work) } } -static void handle_hpd_irq_helper (struct amdgpu_dm_connector *aconnector) +static void handle_hpd_irq_helper (struct amdgpu_dm_connector *aconnector, +enum dc_detect_reason reason) {struct drm_connector *connector = &aconnector->base;struct drm_device *dev = connector->dev;
@@ -4347,7 +4349,8 @@ static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector)dm_restore_drm_connector_state (dev, connector);drm_modeset_unlock_all (dev); -if (aconnector->base.force ==DRM_FORCE_UNSPECIFIED ) +if (aconnector->base.force ==DRM_FORCE_UNSPECIFIED || + reason ==DETECT_REASON_HPDRX )drm_kms_helper_connector_hotplug_event (connector); }else if (debounce_required) {/*
@@ -4379,7 +4382,7 @@ static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector) scoped_guard(mutex, &adev->dm.dc_lock) {dc_exit_ips_for_hw_access (dc); - ret =dc_link_detect (aconnector->dc_link,DETECT_REASON_HPD ); + ret =dc_link_detect (aconnector->dc_link, reason); }if (ret) {/* w/a delay for certain panels */
@@ -4390,7 +4393,8 @@ static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector)dm_restore_drm_connector_state (dev, connector);drm_modeset_unlock_all (dev); -if (aconnector->base.force ==DRM_FORCE_UNSPECIFIED ) +if (aconnector->base.force ==DRM_FORCE_UNSPECIFIED || + reason ==DETECT_REASON_HPDRX )drm_kms_helper_connector_hotplug_event (connector); } }
@@ -4400,7 +4404,7 @@ static void handle_hpd_irq(void *param) {struct amdgpu_dm_connector *aconnector = (struct amdgpu_dm_connector *)param; -handle_hpd_irq_helper (aconnector); +handle_hpd_irq_helper (aconnector,DETECT_REASON_HPD ); }
Signature · 1 line
2.54.0
PATCH 2/5 drm/amd/display: Use handle_hpd_irq_helper for HPD RX
In reply to Timur KristófRemove duplicated code and just call handle_hpd_irq_helper with the appropriate detect reason.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 41 +------------------ 1 file changed, 1 insertion(+), 40 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +1 -40
@@ -4436,14 +4436,12 @@ static void handle_hpd_rx_irq(void *param)struct dc_link *dc_link = aconnector->dc_link;bool is_mst_root_connector = aconnector->mst_mgr.mst_state;bool result = false; -enum dc_connection_type new_connection_type = dc_connection_none;struct amdgpu_device *adev =drm_to_adev (dev);union hpd_irq_data hpd_irq_data;bool link_loss = false;bool has_left_work = false;int idx = dc_link->link_index;struct hpd_rx_irq_offload_work_queue *offload_wq = &adev->dm.hpd_rx_offload_wq[idx]; -struct dc *dc = aconnector->dc_link->ctx->dc;memset (&hpd_irq_data,0 ,sizeof (hpd_irq_data));
@@ -4512,44 +4510,7 @@ static void handle_hpd_rx_irq(void *param) out:if (result && !is_mst_root_connector) {/* Downstream Port status changed. */ -if (!dc_link_detect_connection_type (dc_link, &new_connection_type)) -drm_err (adev_to_drm (adev),"KMS: Failed to detect connector\n" ); - -if (aconnector->base.force && new_connection_type == dc_connection_none) { -emulated_link_detect (dc_link); - -if (aconnector->fake_enable) - aconnector->fake_enable = false; - -amdgpu_dm_update_connector_after_detect (aconnector); - - -drm_modeset_lock_all (dev); -dm_restore_drm_connector_state (dev, connector); -drm_modeset_unlock_all (dev); - -drm_kms_helper_connector_hotplug_event (connector); - }else { -bool ret = false; - -mutex_lock (&adev->dm.dc_lock); -dc_exit_ips_for_hw_access (dc); - ret =dc_link_detect (dc_link,DETECT_REASON_HPDRX ); -mutex_unlock (&adev->dm.dc_lock); - -if (ret) { -if (aconnector->fake_enable) - aconnector->fake_enable = false; - -amdgpu_dm_update_connector_after_detect (aconnector); - -drm_modeset_lock_all (dev); -dm_restore_drm_connector_state (dev, connector); -drm_modeset_unlock_all (dev); - -drm_kms_helper_connector_hotplug_event (connector); - } - } +handle_hpd_irq_helper (aconnector,DETECT_REASON_HPDRX ); }if (hpd_irq_data.bytes.device_service_irq.bits.CP_IRQ) {if (adev->dm.hdcp_workqueue)
Signature · 1 line
2.54.0
PATCH 3/5 drm/amd/display: Always create delayed HPD work queue
In reply to Timur KristófNot just when DMUB outbox is supported.
It will be used for normal HPD events too.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6 -6
@@ -2197,6 +2197,12 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)create_singlethread_workqueue ("dm_vblank_control_workqueue" );if (!adev->dm.vblank_control_workqueue)drm_err (adev_to_drm (adev),"failed to initialize vblank_workqueue.\n" ); + + adev->dm.delayed_hpd_wq =create_singlethread_workqueue ("amdgpu_dm_hpd_wq" ); +if (!adev->dm.delayed_hpd_wq) { +drm_err (adev_to_drm (adev),"failed to create hpd offload workqueue.\n" ); + goto error; + } } if (adev->dm.dc->caps.ips_support &&
@@ -2223,12 +2229,6 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) goto error; } - adev->dm.delayed_hpd_wq =create_singlethread_workqueue ("amdgpu_dm_hpd_wq" ); -if (!adev->dm.delayed_hpd_wq) { -drm_err (adev_to_drm (adev),"failed to create hpd offload workqueue.\n" ); - goto error; - } -amdgpu_dm_outbox_init (adev);if (!register_dmub_notify_callback (adev,DMUB_NOTIFICATION_AUX_REPLY , dmub_aux_setconfig_callback, false)) {
Signature · 1 line
2.54.0
Re: [PATCH 3/5] drm/amd/display: Always create delayed HPD work queue
Quoted 28 lines · Timur Kristóf
Not just when DMUB outbox is supported.
It will be used for normal HPD events too.Signed-off-by Timur Kristóf <[email protected]>--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +6
-0@@ -2197,6 +2197,12 @@ static int amdgpu_dm_init(struct amdgpu_device *adev)create_singlethread_workqueue ("dm_vblank_control_workqueue" );if (!adev->dm.vblank_control_workqueue)drm_err (adev_to_drm (adev),"failed to initialize vblank_workqueue.\n" ); + + adev->dm.delayed_hpd_wq =create_singlethread_workqueue ("amdgpu_dm_hpd_wq" ); +if (!adev->dm.delayed_hpd_wq) { +drm_err (adev_to_drm (adev),"failed to create hpd offload workqueue.\n" ); + goto error; + } } if (adev->dm.dc->caps.ips_support &&@@ -2223,12 +2229,6 @@ static int amdgpu_dm_init(struct amdgpu_device *adev) goto error; }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c static int amdgpu_dm_init(struct amdgpu_device *adev) · line 2234
Quoted 10 lines
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +0
-6- adev->dm.delayed_hpd_wq =create_singlethread_workqueue ("amdgpu_dm_hpd_wq" ); -if (!adev->dm.delayed_hpd_wq) { -drm_err (adev_to_drm (adev),"failed to create hpd offload workqueue.\n" ); - goto error; - } -amdgpu_dm_outbox_init (adev);if (!register_dmub_notify_callback (adev,DMUB_NOTIFICATION_AUX_REPLY , dmub_aux_setconfig_callback, false)) {
Hi Timur,
We'll drop this patch as well, since its logically related to the two other patches being dropped. When we have a fix, we'll merge all 3 of them together.
PATCH 4/5 drm/amd/display: Retry link detection on hotplug
In reply to Timur KristófWhen dc_link_detect_connection_type thinks that a display is connected, but dc_link_detect failed, enqueue delayed work to retry the link detection again.
Useful when eg. HPD pin is high but the display isn't ready and didn't respond to DDC.
- The display is "slow to wake up", ie. DDC isn't ready, for example we couldn't read EDID. Can happen with any connector type with certain "slow" displays. Some displays may take up to 15~20 sec or more to wake up.
- On hotplug, the HPD pin may make contact before the DDC pins, so we couldn't read the EDID. This most often happens with DVI connectors, rarely with HDMI. It is not impossible but extremely rare with other connector types.
--- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 137 ++++++++++++++++++ .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 16 ++ 2 files changed, 153 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +137 -0
@@ -158,6 +158,16 @@ MODULE_FIRMWARE(FIRMWARE_DCN_401_DMUB);#define FIRMWARE_DCN_42_DMUB "amdgpu/dcn_4_2_dmcub.bin"MODULE_FIRMWARE (FIRMWARE_DCN_42_DMUB ); +/** +* define AMDGPU_DM_HPD_MAX_NUM_RETRIES - maximum amount of retries for hotplug detection +*/ +#define AMDGPU_DM_HPD_MAX_NUM_RETRIES 5 + +/** +* define AMDGPU_DM_HPD_RETRY_DELAY_MSEC - millisecond delay between hotplug detection retries +*/ +#define AMDGPU_DM_HPD_RETRY_DELAY_MSEC 1500 +/** * DOC: overview *
@@ -956,6 +966,125 @@ static void dm_handle_hpd_work(struct work_struct *work) } +/** +* dm_handle_delayed_hpd_work() - Handle delayed HPD (hotplug detection) +* +* @w: Base work item structure +* +* Used for retrying HPD after a delay. Just calls the normal HPD helper. +*/ +static void dm_handle_delayed_hpd_work (struct work_struct *work) +{ + struct delayed_work *dw = container_of(work, struct delayed_work, work); + struct delayed_hpd_work *w = container_of(dw, struct delayed_hpd_work, work); +struct amdgpu_dm_connector *aconn = w->aconn; +enum dc_detect_reason reason = w->reason; + +kfree (w); +handle_hpd_irq_helper (aconn, reason); +} + +/** +* dm_cancel_delayed_hpd_work() - Cancel pending hotplug detection work for a connector +* +* @aconnector: Connector on which the HPD event occurred +*/ +static void dm_cancel_delayed_hpd_work (struct amdgpu_dm_connector *aconnector) +{ +if (!aconnector || !aconnector->delayed_hpd_work) +return ; + +cancel_delayed_work (&aconnector->delayed_hpd_work->work); + aconnector->delayed_hpd_work =NULL ; +} + +/** +* dm_cancel_all_delayed_hpd_work() - Cancel all pending hotplug detection work on the device +* +* @dev: DRM device pointer +*/ +static void dm_cancel_all_delayed_hpd_work (struct drm_device *dev) +{ +struct drm_connector *connector; +struct drm_connector_list_iter iter; + +drm_connector_list_iter_begin (dev, &iter); +drm_for_each_connector_iter (connector, &iter) { +if (connector->connector_type ==DRM_MODE_CONNECTOR_WRITEBACK ) +continue ; + +dm_cancel_delayed_hpd_work (to_amdgpu_dm_connector (connector)); + } +drm_connector_list_iter_end (&iter); +} + +/** +* dm_queue_delayed_hpd_work() - Enqueue delayed work to handle hotplug detection +* +* @aconnector: Connector on which the HPD event occurred +* @reason: Reason why we are attempting the HPD +* @msecs: Millisecond delay after which the delayed work is going to happen +* +* When dc_link_detect_connection_type thinks that a display is connected, +* but dc_link_detect failed, enqueue delayed work to retry the link +* detection again. +* +* Useful when eg. HPD pin is high but the display isn't ready and +* didn't respond to DDC. +* +* - On boot or suspend/resume, the display is "slow to wake up", +* ie. DDC isn't ready, for example we couldn't read DP link caps or EDID. +* Can happen to any connector with certain "slow" displays. +* +* - On hotplug, the HPD pin may make contact before the DDC pins, +* so we couldn't read the EDID. Can happen to any connector but +* most often to DVI and sometimes to HDMI (rarely to DP). +* +*/ +static void dm_queue_delayed_hpd_work (struct amdgpu_dm_connector *aconnector, +const enum dc_detect_reason reason, +const unsigned int msecs) +{ +struct drm_device *dev = aconnector->base.dev; +struct amdgpu_device *adev =drm_to_adev (dev); +struct delayed_hpd_work *w; + +if (!aconnector || !aconnector->dc_link || + aconnector->dc_link->type == dc_connection_none) +return ; + +/* Don't retry polled connectors, the polling is going to detect it. */ +if (aconnector->base.polled !=DRM_CONNECTOR_POLL_HPD ) +return ; + + ++aconnector->num_hpd_retries; + +drm_dbg (dev,"Can't detect link on %s on try %d\n" , + aconnector->base.name, aconnector->num_hpd_retries); + +if (aconnector->num_hpd_retries >AMDGPU_DM_HPD_MAX_NUM_RETRIES ) { +drm_warn (dev,"Too many retries on %s: %d, giving up\n" , + aconnector->base.name, aconnector->num_hpd_retries); + aconnector->num_hpd_retries =0 ; +return ; + } + + w =kzalloc (sizeof (*w),GFP_ATOMIC ); + +if (!w) +return ; + +INIT_DELAYED_WORK (&w->work, dm_handle_delayed_hpd_work); + w->aconn = aconnector; + w->reason = reason; + aconnector->delayed_hpd_work = w; + +drm_warn (dev,"Enqueueing next retry on %s\n" , + aconnector->base.name); +queue_delayed_work (adev->dm.delayed_hpd_wq, &w->work, +msecs_to_jiffies (msecs)); +} +static const char *dmub_notification_type_str (enum dmub_notification_type e) {switch (e) {
@@ -3194,6 +3323,7 @@ static int dm_hw_fini(struct amdgpu_ip_block *ip_block) {struct amdgpu_device *adev = ip_block->adev; +dm_cancel_all_delayed_hpd_work (&adev->ddev);amdgpu_dm_hpd_fini (adev);amdgpu_dm_irq_fini (adev);
@@ -3367,6 +3497,8 @@ static int dm_suspend(struct amdgpu_ip_block *ip_block)struct amdgpu_device *adev = ip_block->adev;struct amdgpu_display_manager *dm = &adev->dm; +dm_cancel_all_delayed_hpd_work (&adev->ddev); +if (amdgpu_in_reset (adev)) {enum dc_status res;
@@ -4396,6 +4528,9 @@ static void handle_hpd_irq_helper(struct amdgpu_dm_connector *aconnector,if (aconnector->base.force ==DRM_FORCE_UNSPECIFIED || reason ==DETECT_REASON_HPDRX )drm_kms_helper_connector_hotplug_event (connector); + }else { +dm_queue_delayed_hpd_work (aconnector, reason, +AMDGPU_DM_HPD_RETRY_DELAY_MSEC ); } } }
@@ -4404,6 +4539,8 @@ static void handle_hpd_irq(void *param) {struct amdgpu_dm_connector *aconnector = (struct amdgpu_dm_connector *)param; +/* Cancel any pending work */ +dm_cancel_delayed_hpd_work (aconnector);handle_hpd_irq_helper (aconnector,DETECT_REASON_HPD ); }
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h +16 -0
@@ -136,6 +136,18 @@ struct dmub_hpd_work {struct amdgpu_device *adev; }; +/** +* struct delayed_hpd_work - Handle delayed HPD (hot plug detection) work +* +* @work: Base structure, kernel work data for the work event +* @aconn: Pointer to connector where the HPD event happened +*/ +struct delayed_hpd_work { +struct delayed_work work; +struct amdgpu_dm_connector *aconn; +enum dc_detect_reason reason; +}; +/** * struct vblank_control_work - Work data for vblank control * @work: Kernel work data for the work event
@@ -793,6 +805,10 @@ struct amdgpu_dm_connector {/* number of modes generated from EDID at 'dc_sink' */ int num_modes; +/* number of retries on hot plug detection */ +int num_hpd_retries; +struct delayed_hpd_work *delayed_hpd_work; +/* The 'old' sink - before an HPD. * The 'current' sink is in dc_link->sink. */ struct dc_sink *dc_sink;
Signature · 1 line
2.54.0
PATCH 5/5 drm/amd/display: Retry link detection on resume and boot
In reply to Timur KristófLink detection may fail after suspend/resume when the display is "slow to wake up", and it may happen on boot as well.
Let's retry link detection in those cases too.
--- drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 8 ++++++++ 1 file changed, 8 insertions(+)
drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c +8 -0
@@ -3954,6 +3954,10 @@ static int dm_resume(struct amdgpu_ip_block *ip_block)if (ret) {/* w/a delay for certain panels */ apply_delay_after_dpcd_poweroff (adev, aconnector->dc_sink); + }else { +dm_queue_delayed_hpd_work (aconnector, +DETECT_REASON_RESUMEFROMS3S4 , +AMDGPU_DM_HPD_RETRY_DELAY_MSEC ); } }
@@ -5979,6 +5983,10 @@ static int amdgpu_dm_initialize_drm_device(struct amdgpu_device *adev) link->dpcd_caps.psr_info.psr_dpcd_caps.raw, link->dpcd_caps.psr_info.psr2_su_y_granularity_cap); } + }else { +dm_queue_delayed_hpd_work (aconnector, +DETECT_REASON_BOOT , +AMDGPU_DM_HPD_RETRY_DELAY_MSEC ); } }amdgpu_set_panel_orientation (&aconnector->base);
Signature · 1 line
2.54.0
Quoted 9 lines · Timur Kristóf
When
dc_link_detect_connection_typethinks that a display is connected, butdc_link_detectfailed, enqueue delayed work to retry the link detection again.Useful when eg. HPD pin is high but the display isn't ready and didn't respond to DDC. Typically this may happen when the HPD pins make contact before the DDC pins, or when the display is "slow to wake up" and doesn't respond on DDC.
Quoted 4 lines
The first few patches are just a slight refactor to de-duplicate some code and do some cleanup necessary for the retry. This is to avoid adding even more duplicated code.
Series is
Dan, can we queue this for testing in the next promotion cycle before merging?
Harry
Quoted 12 lines
Timur Kristóf (5):
drm/amd/display: Add detect reason tohandle_hpd_irq_helperdrm/amd/display: Usehandle_hpd_irq_helperfor HPD RX drm/amd/display: Always create delayed HPD work queue drm/amd/display: Retry link detection on hotplug drm/amd/display: Retry link detection on resume and boot.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c | 216 +++++++++++++----- .../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h | 16 ++ 2 files changed, 179 insertions(+), 53 deletions(-)
Quoted 17 lines · Harry Wentland
Quoted 9 lines · Timur Kristóf
When
dc_link_detect_connection_typethinks that a display is connected, butdc_link_detectfailed, enqueue delayed work to retry the link detection again.Useful when eg. HPD pin is high but the display isn't ready and didn't respond to DDC. Typically this may happen when the HPD pins make contact before the DDC pins, or when the display is "slow to wake up" and doesn't respond on DDC.
Quoted 4 lines
The first few patches are just a slight refactor to de-duplicate some code and do some cleanup necessary for the retry. This is to avoid adding even more duplicated code.
Quoted 7 lines
Series is
Reviewed-by Harry Wentland <[email protected]>Dan, can we queue this for testing in the next promotion cycle before merging?
Harry
I will add it to this week's candidate.
Quoted 13 lines
Quoted 12 lines
Timur Kristóf (5):
drm/amd/display: Add detect reason tohandle_hpd_irq_helperdrm/amd/display: Usehandle_hpd_irq_helperfor HPD RX drm/amd/display: Always create delayed HPD work queue drm/amd/display: Retry link detection on hotplug drm/amd/display: Retry link detection on resume and boot
.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c| 216 +++++++++++++-----.../gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h| 16 ++2 files changed, 179 insertions(+), 53 deletions(-)