From f3fb6f3ffad1858c1c9055dfb021d0e3db49dd03 Mon Sep 17 00:00:00 2001 From: Satya Benson Date: Sat, 28 Nov 2026 22:49:53 -0500 Subject: [PATCH] drm/apple: dcp: leave the piodma DART alone at shutdown after DPMS off With an S2R-capable internal panel, drm_atomic_helper_shutdown() turns the display off as DPMS off does: the firmware is stopped and the display power domains, display DART included, are lowered. The component unbind that follows then destroys the piodma device, which detaches it from that DART. Its registers no longer answer, and the restart hangs in device_shutdown() until a watchdog resets the machine. On a J413 (M2 Air, firmware 27.2) this hung every reboot after a deep sleep for 2 minutes, until the hardware watchdog reset it. At shutdown, once DPMS off has powered the display down, leave the piodma device as it is: the system is going down. The unbind also asked every AFK endpoint of the stopped firmware to shut down. RTKit refuses each message to a stopped coprocessor, so each shutdown only waited out its timeout. Complete their stopped completions instead. afk_shutdown() timeout message gains its missing newline, which kept it in the printk continuation buffer. During shutdown the unbind logs each step, so a hang names the step it is in. Signed-off-by: Satya Benson --- drivers/gpu/drm/apple/afk.c | 3 ++- drivers/gpu/drm/apple/dcp.c | 43 ++++++++++++++++++++++++++++++++++++- 2 files changed, 44 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/apple/afk.c b/drivers/gpu/drm/apple/afk.c index 7ad9bb7d1fc58..c23ee21f4dcc6 100644 --- a/drivers/gpu/drm/apple/afk.c +++ b/drivers/gpu/drm/apple/afk.c @@ -203,7 +203,8 @@ void afk_shutdown(struct apple_dcp_afkep *afkep) ret = wait_for_completion_timeout(&afkep->stopped, msecs_to_jiffies(afk_timeout_ms(afkep))); if (ret <= 0) { - dev_err(afkep->dcp->dev, "Timed out shutting down AFK endpoint %02x", afkep->endpoint); + dev_err(afkep->dcp->dev, "Timed out shutting down AFK endpoint %02x\n", + afkep->endpoint); } spin_lock_irqsave(&afkep->lock, flags); diff --git a/drivers/gpu/drm/apple/dcp.c b/drivers/gpu/drm/apple/dcp.c index b11eb205801df..3010357fb409c 100644 --- a/drivers/gpu/drm/apple/dcp.c +++ b/drivers/gpu/drm/apple/dcp.c @@ -7771,6 +7771,29 @@ static void dcp_v27_dpms_handoff(struct apple_dcp *dcp); static void dcp_v27_dpms_off_locked(struct apple_dcp *dcp); static int dcp_v27_dpms_on_locked(struct apple_dcp *dcp, bool present); +/* + * Unbind after an S2R-style stop (DPMS off, or a sleep): the firmware no longer runs + * and RTKit refuses every message to it, so asking an endpoint to shut down only waits + * out its timeout. Let each shutdown below find it stopped. + */ +static void dcp_unbind_stopped_fw(struct apple_dcp *dcp) +{ + struct apple_dcp_afkep *eps[] = { dcp->avep, dcp->dptx_controller_ep, dcp->ibootep, + dcp->systemep, dcp->dcpavservep }; + + dev_info(dcp->dev, "unbind: firmware stopped, endpoints not asked to shut down\n"); + for (int i = 0; i < ARRAY_SIZE(eps); i++) + if (!IS_ERR_OR_NULL(eps[i])) + complete_all(&eps[i]->stopped); +} + +/* Shutdown breadcrumbs, so the console names the step a hang is in. */ +static void dcp_unbind_step(struct apple_dcp *dcp, const char *step) +{ + if (system_state > SYSTEM_RUNNING) + dev_info(dcp->dev, "unbind: %s\n", step); +} + VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, void *data) { struct apple_dcp *dcp = dev_get_drvdata(dev); @@ -7915,12 +7938,16 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v } } + if (READ_ONCE(dcp->s2r_fw_down)) + dcp_unbind_stopped_fw(dcp); + dcp_unbind_step(dcp, "av"); if (!IS_ERR_OR_NULL(dcp->avep)) { av_service_disconnect(dcp); afk_shutdown(dcp->avep); dcp->avep = NULL; } + dcp_unbind_step(dcp, "dptx"); dcp_fabric_shutdown_dptx(dcp); if (!IS_ERR_OR_NULL(dcp->dptx_controller_ep)) { @@ -7933,6 +7960,7 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v dcp->ibootep = NULL; } + dcp_unbind_step(dcp, "systemep"); if (dcp->systemep) { afk_shutdown(dcp->systemep); dcp->systemep = NULL; @@ -7957,12 +7985,25 @@ VISIBLE_IF_KUNIT void dcp_comp_unbind(struct device *dev, struct device *main, v dcp->dcpavservep = NULL; } + dcp_unbind_step(dcp, "iomfb"); if (dcp->shmem) iomfb_shutdown(dcp); iomfb_queue_stop(dcp); - dcp_release_piodma_iommu_dev(dcp); + dcp_unbind_step(dcp, "piodma"); + /* + * At shutdown, DPMS off has already stopped the firmware and powered the display + * domains off, display DART included: destroying the piodma device detaches it + * from that DART, whose registers no longer answer, and the restart hangs there. + * The system is going down; leave the device as it is. + */ + if (system_state > SYSTEM_RUNNING && dcp->dpms_powered_off && + READ_ONCE(dcp->s2r_fw_down)) + dev_info(dcp->dev, "unbind: display powered off, piodma DART left for the restart\n"); + else + dcp_release_piodma_iommu_dev(dcp); + dcp_unbind_step(dcp, "backlight"); cancel_delayed_work_sync(&dcp->bl_fallback_wq); dcp_backlight_stop(dcp); if (dcp->connector_type == DRM_MODE_CONNECTOR_eDP) {