From d5ebf70c762099acbccda1d7962222799bc0fd65 Mon Sep 17 00:00:00 2001 From: hci-kitten <341972264+hci-kitten@users.noreply.github.com> Date: Mon, 16 Nov 2026 10:56:39 -0500 Subject: [PATCH 1/2] nvme: T6040/T6041: hand the ANS session on fully live and adopt it On J614c (T6041) the ANS firmware answers neither an RTKit power transition (rtkit_quiesce times out with "IOP power transition timed out") nor a start after power-off (no HELLO, ASC CPU running, pmgr domains on), so every handoff since adf5580 leaves Stage 2 without NVMe. A session left running with the controller enabled is adopted by the next nvme_init(), as T6050 already does: hand it on with RTKit untouched and only the I/O queue registers cleared, and let T6040/T6041 take the T6050 adopt path. Tested on J614c from the proxy, read-only: init from the iBoot session, read LBA 0, hand on, adopt, read again, 3/3 cycles with identical data; and a Stage 2 built with this change, chainloaded raw, booted through to the installed system. [erikwb: rebased onto main; the adopt condition, which main now spells nvme_ans_storage_gated(), resolves as nvme_ans_storage_gated() || nvme_post_m4_keeps_live(), so T6050 and T8142 are unchanged] Signed-off-by: Erik Bourget --- src/nvme.c | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) diff --git a/src/nvme.c b/src/nvme.c index cdc3ac253..b44369c3c 100644 --- a/src/nvme.c +++ b/src/nvme.c @@ -451,6 +451,21 @@ static bool nvme_own_rtkit(void) (nvme_rtkit = rtkit_init("nvme", nvme_asc, NULL, NULL, nvme_sart, false)) != NULL; } +/* + * T6040/T6041 (M4 Pro/Max): a cold start of ANS after the generic power-off gets no RTKit HELLO + * (ASC CPU running, pmgr domains on), and an RTKit quiesce times out. Keep ANS live between + * stages and adopt it in the next stage, as T6050 does. + */ +static bool nvme_post_m4_keeps_live(void) +{ + return chip_id == T6040 || chip_id == T6041; +} + +static bool nvme_post_m4_hands_on_live(void) +{ + return nvme_ans_storage_gated() || nvme_post_m4_keeps_live(); +} + /* * Post-M4, done with ANS: stop the controller, idle the firmware as macOS does before a sleep, * keep the SART entries, then power ANS and the PCIe block it runs on off. Every later stage that @@ -667,7 +682,7 @@ bool nvme_init(void) * window), its firmware no longer acknowledged the idle, and ANS didn't start from off. * T8142 does the same with a session an older stage handed on running. */ - adopted = earlier && nvme_ans_storage_gated() && + adopted = earlier && nvme_post_m4_hands_on_live() && read32(nvme_base + NVME_BOOT_STATUS) == NVME_BOOT_STATUS_OK && !(read32(nvme_base + NVME_CSTS) & NVME_CSTS_CFS); from_off = !running || (earlier && !adopted); @@ -940,6 +955,21 @@ bool nvme_shutdown(void) goto out_preserve; } + /* + * T6040/T6041: the firmware acknowledges neither an RTKit power transition (quiesce times out) + * nor a start after power-off (no HELLO), but a session left fully running is adopted by the + * next nvme_init() and reads correctly (J614c, 3/3 cycles). Hand it on with the controller + * enabled and RTKit untouched; only the I/O queue registers are cleared. + */ + if (nvme_type == NVME_T8132 && nvme_post_m4_keeps_live()) { + write64_lo_hi(nvme_qreg(NVME_IOQ_CMDS), 0); + write64_lo_hi(nvme_qreg(NVME_IOQ_CQES), 0); + nvme_initialized = false; + printf("nvme: handing the live ANS session on: CC=0x%x CSTS=0x%x BOOT_STATUS=0x%x\n", + read32(nvme_base + NVME_CC), read32(nvme_base + NVME_CSTS), + read32(nvme_base + NVME_BOOT_STATUS)); + return true; + } if (nvme_type == NVME_T8132 && !nvme_secure_regs && !nvme_quiesce_for_next) { write64_lo_hi(nvme_qreg(NVME_IOQ_CMDS), 0); write64_lo_hi(nvme_qreg(NVME_IOQ_CQES), 0); From 4935120b1b703e6aeceaeda137cdd20e3cd5091e Mon Sep 17 00:00:00 2001 From: Erik Bourget Date: Wed, 18 Nov 2026 22:44:03 -0500 Subject: [PATCH 2/2] nvme: T8132: hand the ANS session on live and adopt it On the M4 MacBook Air (J713, T8132), Stage 1 powers ANS off after loading Stage 2 and Stage 2 starts it again from off. After a warm reboot that cold start intermittently gets nowhere, and Stage 2 is left without NVMe until a forced restart. Give T8132 the T6040/T6041 handling: Stage 1 hands its ANS session on running, with only the I/O queue registers cleared, and Stage 2 adopts it instead of starting ANS from off. A stage that asks for a quiesced ANS (nvme_quiesce_for_next) still gets one, on every chip that hands on live. Tested on a J713 with Stage 1 and Stage 2 built from this change on 1.0.0b13.1: every boot logs "handing the live ANS session on" in Stage 1 and "adopting the live post-M4 ANS session" in Stage 2, with no cold start. Linux takes the controller over as before, nvme0n1 and all partitions are present, and nine consecutive warm reboots came up the same way. Signed-off-by: Erik Bourget --- src/nvme.c | 18 ++++++++++++------ tests/python/test_nvme_adoption.py | 7 +++++-- 2 files changed, 17 insertions(+), 8 deletions(-) diff --git a/src/nvme.c b/src/nvme.c index b44369c3c..032d12f93 100644 --- a/src/nvme.c +++ b/src/nvme.c @@ -453,12 +453,17 @@ static bool nvme_own_rtkit(void) /* * T6040/T6041 (M4 Pro/Max): a cold start of ANS after the generic power-off gets no RTKit HELLO - * (ASC CPU running, pmgr domains on), and an RTKit quiesce times out. Keep ANS live between - * stages and adopt it in the next stage, as T6050 does. + * (ASC CPU running, pmgr domains on), and an RTKit quiesce times out. T8132 (M4): the same cold + * start intermittently leaves the next stage without NVMe after a warm reboot. Keep ANS live + * between stages and adopt it in the next stage, as T6050 does. + * + * Not every post-M4 ANS (nvme_post_m4()) is listed. T8152 stays quiesced: its Linux driver wakes + * ANS with a fresh RTKit handshake and neither adopts a live session nor restarts a stopped one. + * T8140 keeps the power-off path, which works there; live adoption by the next stage is untested. */ static bool nvme_post_m4_keeps_live(void) { - return chip_id == T6040 || chip_id == T6041; + return chip_id == T6040 || chip_id == T6041 || chip_id == T8132; } static bool nvme_post_m4_hands_on_live(void) @@ -958,10 +963,11 @@ bool nvme_shutdown(void) /* * T6040/T6041: the firmware acknowledges neither an RTKit power transition (quiesce times out) * nor a start after power-off (no HELLO), but a session left fully running is adopted by the - * next nvme_init() and reads correctly (J614c, 3/3 cycles). Hand it on with the controller - * enabled and RTKit untouched; only the I/O queue registers are cleared. + * next nvme_init() and reads correctly (J614c, 3/3 cycles). T8132 is handed on the same way + * (J713). Hand it on with the controller enabled and RTKit untouched; only the I/O queue + * registers are cleared. A next stage that asks for a quiesced ANS still gets one. */ - if (nvme_type == NVME_T8132 && nvme_post_m4_keeps_live()) { + if (nvme_type == NVME_T8132 && nvme_post_m4_keeps_live() && !nvme_quiesce_for_next) { write64_lo_hi(nvme_qreg(NVME_IOQ_CMDS), 0); write64_lo_hi(nvme_qreg(NVME_IOQ_CQES), 0); nvme_initialized = false; diff --git a/tests/python/test_nvme_adoption.py b/tests/python/test_nvme_adoption.py index 26f069220..08e0bc956 100644 --- a/tests/python/test_nvme_adoption.py +++ b/tests/python/test_nvme_adoption.py @@ -341,8 +341,11 @@ def test_adopted_queue_lifetime(tmp_path): assert(nvme_initialized); assert(nvme_shutdown()); assert(!nvme_initialized); - /* Powered off, post-M4 frees its queues too; only Linux's live handoff keeps them. */ - assert(queue_frees == (failure == 9 ? 0 : 2)); + /* + * Powered off, post-M4 frees its queues too. Linux's live handoff keeps them, and so does + * T8132 (23, 26), which hands its session on live to the next stage. + */ + assert(queue_frees == (failure == 9 || failure == 23 || failure == 26 ? 0 : 2)); assert(resets == (legacy ? 2 : 0)); /* A healthy shutdown still allows reinitialization. */ assert(nvme_init());