From af33408a2bf2067f055eae4d5e321f6832247092 Mon Sep 17 00:00:00 2001 From: Diljit Singh Date: Fri, 20 Nov 2026 15:00:54 -0500 Subject: [PATCH] drm: apple: dcp: V27 sleep: take messages that come during the settle On the J714s the panel's display processor (48ae00000.dcp) refused a deep sleep with -EBUSY and no reason in the log, 3 times in 40 sleeps that came after a replug of a display's port. Each refused sleep then left a GPU "firmware never stopped" line, and one an external display's link timeout, in the aborted resume. The refusal is the settle's last check. After the endpoint checks it took a snapshot of the RTKit receive side and refused the sleep if anything was in flight. Each refusal came ~5 ms after the panel's firmware logged a brightness change. It logs one each time an external display processor, suspending at the same time, releases its display, so a syslog line in flight at that instant was enough. macOS answers what the firmware sends during its display sleep and goes on. In a trace with three displays attached, its first stop request to the panel follows its answer to the panel's last syslog line by 31 us. The settle now does the same: when a message came during the checks, it is taken and all of them run again, including the inventory of messages left unhandled. A processor that still sends after 1 s, or a check that times out after such a message, refuses the sleep with -EBUSY as before, so the refusal is still undone cleanly. A refused sleep of the internal processor also logs its steps now, as the external ones' always do; a step's refusal there was silent. Signed-off-by: Diljit Singh Co-Authored-By: Claude Opus 5.5 --- drivers/gpu/drm/apple/dcp-v27-sleep.inc | 86 +++++++++++++++++++------ 1 file changed, 65 insertions(+), 21 deletions(-) diff --git a/drivers/gpu/drm/apple/dcp-v27-sleep.inc b/drivers/gpu/drm/apple/dcp-v27-sleep.inc index 5357249a46edb..bf63098f2d61a 100644 --- a/drivers/gpu/drm/apple/dcp-v27-sleep.inc +++ b/drivers/gpu/drm/apple/dcp-v27-sleep.inc @@ -808,33 +808,70 @@ static int dcp_v27_sleep_inventory(struct apple_dcp *dcp) return 0; } +/* + * The firmware keeps sending while the other display processors suspend: the panel's logs + * the brightness it takes each time an external display is released, and that line, or any + * other message, can land between the checks below. macOS answers what comes and goes on + * with its sleep calls: with three displays attached, the panel's first stop request follows + * its answer to the last syslog line by 31 us. So when a message came during the checks, it + * is taken and all of them run again, the inventory of unhandled messages included; the + * sleep is no longer refused on that snapshot. A processor that never goes quiet within + * the limit, or a check that times out after such a message, refuses the sleep as before. + */ +#define V27_SETTLE_MS 1000 + static int dcp_v27_sleep_settle(struct apple_dcp *dcp) { + ktime_t start = ktime_get(), deadline = ktime_add_ms(start, V27_SETTLE_MS); + unsigned int late = 0; int i, ret, check; bool drained; - ret = dcp_v27_sleep_inventory(dcp); - if (ret) - return ret; - ret = read_poll_timeout(apple_rtkit_v27_rx_drained, drained, drained, - 1000, 250000, false, dcp->rtk); - if (ret) - return ret; - ret = iomfb_queue_settle(dcp, msecs_to_jiffies(1000)); - if (ret) - return ret; - for (i = 0; i < ARRAY_SIZE(v27_sleep_endpoints); i++) { - struct apple_dcp_afkep *ep = dcp->sleep_v27_ep[v27_sleep_endpoints[i] - 0x20]; + for (;;) { + ret = dcp_v27_sleep_inventory(dcp); + if (ret) + return ret; + ret = read_poll_timeout(apple_rtkit_v27_rx_drained, drained, drained, + 1000, 250000, false, dcp->rtk); + if (ret) + goto timed_out; + ret = iomfb_queue_settle(dcp, msecs_to_jiffies(1000)); + if (ret) + goto timed_out; + for (i = 0; i < ARRAY_SIZE(v27_sleep_endpoints); i++) { + struct apple_dcp_afkep *ep = dcp->sleep_v27_ep[v27_sleep_endpoints[i] - 0x20]; - ret = read_poll_timeout(afk_v27_sleep_check, check, check != -EBUSY, - 1000, 250000, false, ep); - if (ret || check) - return ret ?: check; + ret = read_poll_timeout(afk_v27_sleep_check, check, check != -EBUSY, + 1000, 250000, false, ep); + if (ret) + goto timed_out; + if (check) + return check; + } + /* Before IDLE this is a snapshot; after mailbox_off RX is detached and + * synchronized. The same check then closes the accepted-callback lifetime. + */ + if (apple_rtkit_v27_rx_drained(dcp->rtk)) { + /* What the last messages' handlers left unhandled, read after they returned. */ + ret = dcp_v27_sleep_inventory(dcp); + if (ret) + return ret; + break; + } + late++; + if (ktime_after(ktime_get(), deadline)) { + dev_warn(dcp->dev, "V27 sleep: the processor still sends %lld ms into the settle (%u rounds): sleep refused\n", + ktime_ms_delta(ktime_get(), start), late); + return -EBUSY; + } } - /* Before IDLE this is a snapshot; after mailbox_off RX is detached and - * synchronized. The same check then closes the accepted-callback lifetime. - */ - return apple_rtkit_v27_rx_drained(dcp->rtk) ? 0 : -EBUSY; + if (late) + dev_info(dcp->dev, "V27 sleep: a message came during the settle in %u round(s): taken, quiet after %lld us\n", + late, ktime_us_delta(ktime_get(), start)); + return 0; +timed_out: + /* After a message came, a timeout refuses as the snapshot did: -EBUSY, undone cleanly. */ + return late && ret == -ETIMEDOUT ? -EBUSY : ret; } /* @@ -1611,11 +1648,18 @@ static int dcp_v27_sleep_suspend(struct apple_dcp *dcp) if (dcp->sleep_v27) dcp->sleep_v27->steps_len = 0; ret = dcp_v27_sleep_prepare(dcp); - /* Every external processor's step on one line, "call result@ms". */ + /* + * Every external processor's step on one line, "call result@ms", and the internal + * one's when it refuses the sleep: a step's refusal there is otherwise silent. + */ if (dcp_v27_external(dcp)) dev_info(dcp->dev, "ext %u: sleep step:%s; result %d\n", dcp_v27_ext_nr(dcp), dcp->sleep_v27 && dcp->sleep_v27->steps_len ? dcp->sleep_v27->steps : " refused before its calls", ret); + else if (ret) + dev_info(dcp->dev, "internal: sleep step:%s; result %d\n", + dcp->sleep_v27 && dcp->sleep_v27->steps_len ? + dcp->sleep_v27->steps : " refused before its calls", ret); /* A device whose suspend fails gets no resume: its ports are let go here. */ if (ret) dcp_v27_ext_replug(dcp, false);