From 66355a0fd2550542821985cf68e4e62b08032cb3 Mon Sep 17 00:00:00 2001 From: Thomas Glanzmann Date: Sat, 28 Nov 2026 18:07:07 +0100 Subject: [PATCH] display: hand a lit external AFKv2 DCP on running MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On M1 Mac mini (J274, T8103) running macOS 27.2.1 firmware, /arm-io/dcp drives HDMI directly (display_is_external = true, display_is_dptx = false) over an AFKv2 disp0-service iBoot interface. Once the display has been powered on and modeset, rtkit_sleep() times out waiting for the AP power transition ("rtkit(dcp): AP power transition timed out"), leaving dcp_running = true so subsequent handoff fails ("Display handoff failed; returning to proxy") — the same 27.2 firmware behaviour handled for AFKv2 dptx-port controllers in #451. Without a connected display (headless, connected:0), display_configure() returns before powering on the display and rtkit_sleep() still succeeds in <1 ms, so the headless path keeps sleeping the DCP. Add dcp_ib_is_afkv2() and generalize display_dptx_hands_on() into display_dcp_hands_on() so a lit external AFKv2 display is handed on running via dcp_hand_on() and published to Linux through apple,rtkit-handoff ("dcp-live-v1"). Evaluate display_dcp_hands_on() before dcp_ib_shutdown() frees iboot. Tested: - J274 (M1 Mac mini, T8103, macOS 27.2.1 main OS): - Cold boot with HDMI (1920x1200@60) plugged in via enrolled Stage 1: modeset succeeded, "display: handing the DCP on running (external AFKv2 display)", published live RTKit session v12 (3 buffers, epmap 0000051f 00821fff), Linux 7.3.0 apple-dcp adopted dcp-live-v1 seamlessly (fb0 appledrmfb, 1920x1200@60, 0 DART faults, 0 failed units). - Headless boot (HDMI unplugged) on patched Stage 2: connected:0, slept DCP cleanly in 0.4 ms ("pmgr: resetting device 0.DISP0_CPU0"). - Host: clang-format clean, Stage 1 builds cleanly (12,296 B headroom, no __TEXT_BOOT_EXEC), Stage 2 ESP build links cleanly, full pytest tests/python: 1251 passed, 26 skipped. Risk: low — only applies to external displays on an AFKv2 iBoot interface after power-on; headless external boots, AFKv1 (13.5) external displays, internal panels, and existing AFKv2 dptx-port displays keep their previous behaviour. Signed-off-by: Thomas Glanzmann --- src/dcp_iboot.c | 5 ++ src/dcp_iboot.h | 1 + src/display.c | 37 ++++++++++---- tests/python/test_display_dptx_hand_on.py | 51 +++++++++++++------ tests/python/test_t8103_iboot_power_status.py | 2 +- 5 files changed, 68 insertions(+), 28 deletions(-) diff --git a/src/dcp_iboot.c b/src/dcp_iboot.c index dfeb7b73b..86960da5c 100644 --- a/src/dcp_iboot.c +++ b/src/dcp_iboot.c @@ -165,6 +165,11 @@ int dcp_ib_shutdown(dcp_iboot_if_t *iboot) return 0; } +bool dcp_ib_is_afkv2(const dcp_iboot_if_t *iboot) +{ + return iboot && afk_epic_is_v2(iboot->epic); +} + static int dcp_ib_cmd(dcp_iboot_if_t *iboot, int op, size_t in_size) { size_t rxsize = RXBUF_LEN; diff --git a/src/dcp_iboot.h b/src/dcp_iboot.h index c0fc5225d..67244d745 100644 --- a/src/dcp_iboot.h +++ b/src/dcp_iboot.h @@ -97,6 +97,7 @@ typedef struct { dcp_iboot_if_t *dcp_ib_init(dcp_dev_t *dcp); int dcp_ib_shutdown(dcp_iboot_if_t *iboot); +bool dcp_ib_is_afkv2(const dcp_iboot_if_t *iboot); int dcp_ib_set_surface(dcp_iboot_if_t *iboot, dcp_layer_t *layer); int dcp_ib_set_power(dcp_iboot_if_t *iboot, bool power); diff --git a/src/display.c b/src/display.c index eefadcddf..00f8759d7 100644 --- a/src/display.c +++ b/src/display.c @@ -37,6 +37,7 @@ bool has_dcp; bool display_is_external; bool display_is_dptx; bool display_needs_power_cycle; +static bool display_external_lit; static const display_config_t display_config_m1 = { .dcp = "/arm-io/dcp", @@ -456,6 +457,7 @@ int display_start_dcp(void) } display_is_dptx = !!disp_cfg->dptx_phy[0]; + display_external_lit = false; display_afk_restart(disp_cfg->dcp); dcp = dcp_init(disp_cfg); @@ -669,6 +671,8 @@ int display_configure(const char *config) printf("display: failed to set power\n"); return ret; } + if (display_is_external) + display_external_lit = true; // Sonoma bug workaround mdelay(100); @@ -1250,27 +1254,35 @@ static int display_handoff_t8152(void) } /* - * Once a dptx-port that speaks AFKv2 has been connected, its DCP acknowledges no power request: - * on the M2 Mac mini with the 27.2 firmware neither AP QUIESCED or IDLE nor IOP SLEEP is answered, - * even after the display is released and powered off. It cannot be slept or quiesced, so it is - * handed on running, as the T8152 and T8132 displays are, with the display left lit: the next - * stage keeps showing the framebuffer. + * Once a dptx-port that speaks AFKv2 has been connected (M2 Mac mini on 27.2 firmware), or an + * external display on an AFKv2 iBoot interface has been powered on (M1 Mac mini J274 HDMI on 27.2 + * firmware), its DCP acknowledges no power request: neither AP QUIESCED or IDLE nor IOP SLEEP is + * answered. It cannot be slept or quiesced, so it is handed on running, as the T8152 and T8132 + * displays are, with the display left lit: the next stage keeps showing the framebuffer and Linux + * adopts the live RTKit session via apple,rtkit-handoff ("dcp-live-v1"). + * + * Without an attached display (headless), a direct external AFKv2 DCP never powers on or modesets + * and still sleeps cleanly, so it keeps the sleep path. */ -static bool display_dptx_hands_on(void) +static bool display_dcp_hands_on(void) { - return display_is_dptx && dcp && dcp_dptx_is_afkv2(dcp->dptx_ep); + if (!dcp) + return false; + if (display_is_dptx && dcp_dptx_is_afkv2(dcp->dptx_ep)) + return true; + return display_is_external && display_external_lit && dcp_ib_is_afkv2(iboot); } bool display_needs_live_receiver(void) { return dcp_handed_on_live() || display_inherited_live_heap(NULL) || - (iboot && display_dptx_hands_on() && !display_hands_on_live()); + (iboot && display_dcp_hands_on() && !display_hands_on_live()); } /* Stop the endpoints before callers lay out the next image or measure its reservations. */ int display_prepare_live_handoff(void) { - if (!iboot || !display_dptx_hands_on()) + if (!iboot || !display_dcp_hands_on()) return 0; return display_shutdown(DCP_SLEEP_IF_EXTERNAL); @@ -1382,11 +1394,14 @@ int display_shutdown(dcp_shutdown_mode mode) return 0; if (iboot) { + bool hands_on = display_dcp_hands_on(); /* An endpoint that does not stop stays registered, so dcp_shutdown() * retries it with the rest and reports the DCP as still running. */ dcp_ib_shutdown(iboot); - if (display_dptx_hands_on()) { - printf("display: handing the DCP on running (its dptx-port speaks AFKv2)\n"); + display_external_lit = false; + if (hands_on) { + printf("display: handing the DCP on running (%s)\n", + display_is_dptx ? "its dptx-port speaks AFKv2" : "external AFKv2 display"); iboot = NULL; return dcp_hand_on(dcp) < 0 ? -1 : 0; } diff --git a/tests/python/test_display_dptx_hand_on.py b/tests/python/test_display_dptx_hand_on.py index 4cb81170d..55d6f90fc 100644 --- a/tests/python/test_display_dptx_hand_on.py +++ b/tests/python/test_display_dptx_hand_on.py @@ -38,9 +38,9 @@ def function(text, signature): typedef enum { DCP_QUIESCED, DCP_SLEEP_IF_EXTERNAL, DCP_SLEEP, DCP_HANDOFF } dcp_shutdown_mode; typedef struct { bool afkv2; } dcp_dptx_if_t; typedef struct { dcp_dptx_if_t *dptx_ep; bool endpoint_fails; } dcp_dev_t; -typedef struct { int unused; } dcp_iboot_if_t; +typedef struct { bool afkv2; } dcp_iboot_if_t; static unsigned chip_id = T8112; -static bool has_dcp = true, display_is_external = true, display_is_dptx; +static bool has_dcp = true, display_is_external = true, display_is_dptx, display_external_lit; static dcp_dev_t *dcp; static dcp_iboot_if_t *iboot; static bool running, handed_on; @@ -49,6 +49,7 @@ def function(text, signature): static bool display_hands_on_live(void) { return chip_id == T8140 || chip_id == T8132 || chip_id == T8152; } static int display_handoff_t8152(void) { call("t8152"); return 0; } static bool dcp_dptx_is_afkv2(const dcp_dptx_if_t *ep) { return ep && ep->afkv2; } +static bool dcp_ib_is_afkv2(const dcp_iboot_if_t *ib) { return ib && ib->afkv2; } static int dcp_ib_shutdown(dcp_iboot_if_t *ib) { (void)ib; call("ib"); return 0; } static int dcp_shutdown(dcp_dev_t *d, bool sleep) { (void)d; call(sleep ? "sleep" : "quiesce"); return 0; } static int dcp_hand_on(dcp_dev_t *d) @@ -64,47 +65,65 @@ def function(text, signature): """ MAIN = r""" -static void reset(dcp_dev_t *d, dcp_iboot_if_t *ib, bool dptx, bool external) +static void reset(dcp_dev_t *d, dcp_iboot_if_t *ib, bool dptx, bool external, bool lit) { dcp = d; iboot = ib; display_is_dptx = dptx; display_is_external = external; + display_external_lit = lit; running = handed_on = false; calls[0] = 0; } int main(void) { dcp_dptx_if_t v2 = {true}, v1 = {false}; - dcp_dev_t d2 = {&v2, false}, d1 = {&v1, false}, internal = {NULL, false}, stuck = {&v2, true}; - dcp_iboot_if_t ib; + dcp_dev_t d2 = {&v2, false}, d1 = {&v1, false}, direct = {NULL, false}, stuck = {&v2, true}; + dcp_iboot_if_t ib_v1 = {false}, ib_v2 = {true}; /* AFKv2 dptx-port: iBoot interface stopped, then handed on running; no sleep. */ - reset(&d2, &ib, true, true); + reset(&d2, &ib_v2, true, true, true); assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0); - assert(!strcmp(calls, "ib hand-on ") && !iboot); + assert(!strcmp(calls, "ib hand-on ") && !iboot && !display_external_lit); /* The Linux boundary asks again: nothing more to do, and still no failure. */ calls[0] = 0; assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !calls[0]); - /* The pre-AFKv2 format (13.5 firmware) keeps the sleep. */ - reset(&d1, &ib, true, true); + /* Direct external HDMI on AFKv2 (J274 27.2) after power-on: handed on running. */ + reset(&direct, &ib_v2, false, true, true); + assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0); + assert(!strcmp(calls, "ib hand-on ") && !iboot && !display_external_lit); + + /* Direct external HDMI on AFKv2 headless (no display lit): still sleeps cleanly. */ + reset(&direct, &ib_v2, false, true, false); assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib sleep ")); - /* An internal panel without a dptx-port keeps the quiesce. */ - reset(&internal, &ib, false, false); + /* Direct external HDMI on AFKv1 (J274 13.5): keeps the sleep. */ + reset(&direct, &ib_v1, false, true, true); + assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib sleep ")); + + /* The pre-AFKv2 dptx-port format (13.5 firmware) keeps the sleep. */ + reset(&d1, &ib_v1, true, true, true); + assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib sleep ")); + + /* An internal panel without a dptx-port keeps the quiesce, even on AFKv2. */ + reset(&direct, &ib_v2, false, false, false); assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == 0 && !strcmp(calls, "ib quiesce ")); /* A modeset after main's initial shutdown still hands off before kboot measures the heap. */ - reset(&d2, &ib, true, true); + reset(&d2, &ib_v2, true, true, true); + assert(!handed_on); + assert(display_prepare_live_handoff() == 0); + assert(handed_on && !iboot && !strcmp(calls, "ib hand-on ")); + reset(&direct, &ib_v2, false, true, true); assert(!handed_on); assert(display_prepare_live_handoff() == 0); assert(handed_on && !iboot && !strcmp(calls, "ib hand-on ")); - reset(&d1, &ib, true, true); + reset(&d1, &ib_v1, true, true, true); assert(display_prepare_live_handoff() == 0 && !handed_on && !calls[0]); /* An endpoint that does not stop fails the hand-on, then and at the next boundary. */ - reset(&stuck, &ib, true, true); + reset(&stuck, &ib_v2, true, true, true); assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == -1 && !strcmp(calls, "ib hand-on ")); assert(display_shutdown(DCP_SLEEP_IF_EXTERNAL) == -1); puts("ok"); @@ -116,7 +135,7 @@ def function(text, signature): def test_afkv2_dptx_dcp_is_handed_on_running(tmp_path): disp = (SOURCE / "src/display.c").read_text() source = HARNESS + "".join(function(disp, signature) for signature in ( - "static bool display_dptx_hands_on(", + "static bool display_dcp_hands_on(", "int display_prepare_live_handoff(void)", "int display_shutdown(dcp_shutdown_mode mode)\n", )) + MAIN @@ -124,5 +143,5 @@ def test_afkv2_dptx_dcp_is_handed_on_running(tmp_path): subprocess.run(["cc", "-std=gnu11", "-Wall", "-Wextra", "-Werror", "-Wno-unused-function", "-Wno-switch", "-x", "c", "-", "-o", str(exe)], input=source, text=True, check=True) out = subprocess.run([str(exe)], capture_output=True, text=True, check=True).stdout - assert out.count("handing the DCP on running") == 3 + assert out.count("handing the DCP on running") == 5 assert out.endswith("ok\n") diff --git a/tests/python/test_t8103_iboot_power_status.py b/tests/python/test_t8103_iboot_power_status.py index 20d73cb19..14b49c767 100644 --- a/tests/python/test_t8103_iboot_power_status.py +++ b/tests/python/test_t8103_iboot_power_status.py @@ -161,7 +161,7 @@ def unit(): static dcp_dev_t dcp_storage, *dcp = &dcp_storage; static struct dcp_iboot_if iboot_storage, *iboot = &iboot_storage; static u64 fb_dva, fb_size; -static bool display_is_external, display_is_dptx, display_needs_power_cycle; +static bool display_is_external, display_is_dptx, display_needs_power_cycle, display_external_lit; static bool display_mode_max, fb_dva_allocated; static struct { struct { u64 base, stride, width, height, depth; } video; } cur_boot_args; static u64 boot_args_addr;