Repository navigation
nvme: apple: start a post-M4 ANS a boot stage powered off - #48
Draft
RyanTheTide wants to merge 9 commits into
Draft
RyanTheTide wants to merge 9 commits into
RyanTheTide wants to merge 9 commits into
Conversation
A coprocessor's SART loses its entries with the coprocessor's power. An earlier owner that powered it off can pass the entries on, and sart_set_entry() writes one back at its index and keeps it, as sart_init() keeps the entries it finds. Signed-off-by: Diljit Singh <[email protected]>
…e state After a power cycle, firmware that kept its state in DRAM says HELLO by itself once the run bit is set, and keeps the buffers it was given. apple_rtkit_boot_warm() is the existing boot with a flag: no INIT, the endpoint map answered as macOS does after a wake (bit 1 added to every part but the last, the last masked by the caller), no endpoint started again, then AP power on. Such firmware can report its power state before HELLO or between the endpoint map's parts: the handshake records that, and drops what other endpoints send meanwhile. Firmware that reports its power on and then says no HELLO picked its kept session back up: AP power goes on and the session carries on. Signed-off-by: Diljit Singh <[email protected]>
aura now shuts ANS down after its own use, as on M1-M3, instead of handing its running session on. It powers ANS's PCIe block off and back on before U-Boot, so U-Boot finds ANS powered with its CPU stopped, and the SART entries the firmware's buffers need in the nvme node's apple,sart-entries: per entry (index << 8 | flags), address and size, 64 bits each. With that property, apple_nvme_probe() writes the entries back, enables the mailbox's receive side as macOS does after a sleep, sets the run bit and starts the firmware as after a power loss, then sets the controller up as before. Linux still adopts a running ANS, so U-Boot hands it on running, as before, and drops the property from the OS's tree. A post-M4 session straight from iBoot, which no stage has set up, gets its one-time RTKit handshake on every post-M4 controller, not only on T6040. A running session from an older aura is adopted as before. Pre-M4 controllers boot ANS as before. Signed-off-by: Diljit Singh <[email protected]>
The warm start took an IOP power report of "on" followed by no HELLO for a session the firmware had picked back up, and turned AP power on without a handshake. That came from reading a CPU status of 0x6a as "kept its idle state". On the J700 the start that failed (ANS-chain-kit-08) did get HELLO: this branch, built with DEBUG, didn't print, and both mailbox controls read their reset value. The firmware had restarted, and what it never sent was the endpoint map after HELLO. The boot loader stage now disables the controller before it powers ANS off, which leaves no case for this branch. Log HELLO and each endpoint map part as debug lines, so a failed start says how far the handshake got. Signed-off-by: Diljit Singh <[email protected]>
The warm start answers the last part of the endpoint map with that part's bitmap masked by last_mask. For ANS that is bit 0, endpoint 0x20, as macOS answers after a wake. The loop then tested its own reply for APPLE_RTKIT_MGMT_EPMAP_REPLY_MORE, which is bit 0 too, so it went back to wait for a part the firmware never sends. The firmware's IOP power report came in that wait, and the start failed with -110 a second later. On the J700 (ANS-chain-kit-09) U-Boot logged HELLO, map base 0, map base 1 (the last part), then the IOP power report and -110. aura's three starts from off in the same boot passed: they end the map on the message's last bit. The "unexpected message type 7" of kits 05 and 06 was the same report, read where the next map part was expected. End the loop on the reply's LAST bit, which is set exactly when the firmware's part was the last. Signed-off-by: Diljit Singh <[email protected]>
… the run bit On a J700, 3 of 116 starts from off failed: no HELLO after the run bit, and none later. The traced one read CPU status 0x62 before the run bit; every working start read 0x6a, the status right after a reset of ANS. Its CPU had been stopped without a reset since it last ran, and such a CPU doesn't start again from the run bit. Reset ANS (its PMGR reset, which takes the SART entries with it) when the status lacks the reset bit, then write the entries and start it. When the firmware still doesn't answer, stop the CPU, reset ANS, write the entries again and start it once more with a new RTKit instance. Print the status before the run bit and any reset, for a Mac without a serial console. Signed-off-by: Diljit Singh <[email protected]>
A start from off that is retried frees its RTKit instance first. That instance's buffers came from LMB through nvme_handoff_shmem_setup(), but it had no destroy callback, so apple_rtkit_free() passed them to free(): heap corruption once the firmware had asked for any. They also stayed in the handoff list, published to the OS as reserved memory. Take them out of the SART, return them to LMB and drop them from the list instead. Signed-off-by: Diljit Singh <[email protected]>
… cycle A power cycle leaves ANS's CPU in its reset state and the firmware's boot status cleared. In a start from off that later failed on a J700, the CPU status read 0x62 and the boot status 0xde71ce55 before the run bit. In 117 starts that worked, the boot status read 0 every time. A CPU stopped since it last ran doesn't start again from the run bit. Reset ANS before the run bit when either the CPU isn't in its reset state or the boot status still reads OK, and print both. Also bring the comment above struct apple_nvme_hw up to date: a stage done with a post-M4 ANS powers it off, and the next starts it warm. Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
This was referenced Nov 13, 2026
U-Boot hands a post-M4 ANS to the OS with its RTKit session live and the controller enabled, which Linux adopts. A kernel that can start ANS from apple,sart-entries doesn't need that, and a live handoff leaves the OS a session it never set up. When the boot loader before U-Boot asks for it with /chosen/aurora,nvme-handoff = "off", hand ANS over the way aura hands it to U-Boot: - the OS tree's fixup writes the SART entries ANS runs with into the nvme node's apple,sart-entries; - at device removal, the I/O queues are deleted, the controller is disabled, the firmware is put to sleep (an adopted session gets an RTKit instance for that), and ANS is reset through its PMGR reset, which takes the SART entries with it. The firmware's buffers stay reserved as before. If the entries can't be passed on, ANS goes to the OS running, as without the property. Without the property nothing changes. Add sart_get_entries() for the fixup. Assisted-by: LLM Co-Authored-By: Claude Opus 5.5 <[email protected]> Signed-off-by: Ryan Murray <[email protected]>
This was referenced Nov 19, 2026
Contributor
Author
|
Early note on this draft (no full review yet):
Assisted-by: LLM (Claude:Opus 5.5) |
Contributor
Author
|
Besides the two points in the earlier note, commits c8193b9 and cfebc31 carry Co-Authored-By and Assisted-by trailers in the commit message; they need replacing with commits that carry only the author's Signed-off-by. Once the start-from-off is fixed without the second attempt, this needs a boot-loop row on a post-M4 Mac (for example J700 or J616s) showing every chain boot finds the SSD on the first run bit. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Starts a post-M4 ANS (M4, M4 Pro/Max, T8140, T8142, T6050) that the previous boot stage idled and powered off, instead of only adopting a running session. This is #38's series rebased onto the current
aurora-wip(25cbb0f), with its seven commits carried unchanged, plus one commit on top.What it does
apple_nvme_probe()on a post-M4 controller:apple,sart-entrieson thenvmenode (written by aura when ANS is off at the payload's start)apple_rtkit_boot_warm()), then sets the controller up. If the firmware doesn't answer, it resets ANS once and tries again with a new RTKit instance whose buffers go back to LMB.The fixup drops
apple,sart-entriesfrom the OS's tree when U-Boot started ANS itself.Commit on top: reset when the boot status survived
A power cycle leaves ANS's CPU in its reset state (status bit 3) and the firmware's boot status at 0. One failed start from off on a J700 read CPU status
0x62and boot status0xde71ce55before the run bit, and the firmware never answered it. 117 starts that worked all read0x6aand boot status 0. The carried check looks only at bit 3. This commit also resets when the boot status still reads OK, and prints both values. It also updates the comment abovestruct apple_nvme_hw, which still said a post-M4 ANS can't be restarted.Commit on top: hand ANS to the OS powered off when asked
With
/chosen/aurora,nvme-handoff = "off"(aura writes it when its configuration hasnvme.handoff=off, aurora-silicon/aura#218), U-Boot hands ANS to the OS the way aura hands it to U-Boot. It doesn't hand the session on live:nvmenode'sapple,sart-entries;ps_ans, which clears the SART.The OS starts it from those entries (aurora-silicon/linux#1808). If the entries can't be passed on, ANS goes to the OS running. Without the property nothing changes. This adds
sart_get_entries().Rebase
Two conflicts, both with work merged since #38's base:
rtkit.c: T6050's endpoint start (apple_rtkit_boot_t6050()) is kept and used for cold boots only. A warm start starts no endpoints, as on every other SoC.nvme_apple.c:wake_disabledis gone, because the handshake check is now generic. T6050 keepskeep_cc_fieldsand its/chosenadoption check.Tested
apple_m1_defconfigwithCONFIG_WERROR=y, GCC (aarch64-linux-gnu): builds with no warnings.93f108a0, and in 50 of 50 at430b64e8. The forced reset path ran 10 of 10, and resetting a stopped ANS with its firmware resident (0x6eto0x6a) ran 20 of 20 with no SError. A J773g (T8132) started it from off on 3 native boots.