Skip to content

nvme: apple: start a post-M4 ANS a boot stage powered off - #48

Draft
RyanTheTide wants to merge 9 commits into
aurora-wipfrom
fix/nvme-apple-post-m4-restart
Draft

RyanTheTide wants to merge 9 commits into
aurora-wipfrom
fix/nvme-apple-post-m4-restart

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 13, 2026 •

Copy link
Copy Markdown
Contributor

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:

What U-Boot finds What it does
apple,sart-entries on the nvme node (written by aura when ANS is off at the payload's start) Resets ANS if the power cycle didn't (see below), writes the SART entries back, enables the mailbox's receive side, sets the run bit and starts the firmware warm (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.
iBoot's session, which no stage has handshaken The one-time RTKit handshake, now on every post-M4 controller.
A running session that an older boot loader handed on Adopted as before.

The fixup drops apple,sart-entries from 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 0x62 and boot status 0xde71ce55 before the run bit, and the firmware never answered it. 117 starts that worked all read 0x6a and 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 above struct 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 has nvme.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:

  • 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 and the firmware is put to sleep (an adopted session gets an RTKit instance for that). Then ANS is reset through 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_disabled is gone, because the handshake check is now generic. T6050 keeps keep_cc_fields and its /chosen adoption check.

Tested

  • apple_m1_defconfig with CONFIG_WERROR=y, GCC (aarch64-linux-gnu): builds with no warnings.
  • On hardware, from nvme: apple: start a post-M4 ANS the boot loader powered off #38's series as carried here: a J700 started ANS from off in 113 of 116 chain boots at 93f108a0, and in 50 of 50 at 430b64e8. The forced reset path ran 10 of 10, and resetting a stopped ANS with its firmware resident (0x6e to 0x6a) ran 20 of 20 with no SError. A J773g (T8132) started it from off on 3 native boots.
  • This head hasn't run on hardware yet. Rows for a J616s (T6040), plus an M1 Pro and M2 regression boot, are next.

DjDeveloperr and others added 8 commits November 13, 2026 21:03
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]>
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]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Early note on this draft (no full review yet):

  1. drivers/nvme/nvme_apple.c:884-916: when the firmware does not answer the run bit, the start from off resets ANS and tries once more. This is a retry over an unexplained failure (the description reports 3 of 116 chain boots failing at one head). Please find what leaves ANS in the state that does not start (the boot status surviving the power cycle is one candidate) and handle that state directly before the first run bit, then drop the second attempt.
  2. drivers/nvme/nvme_apple.c:1034-1040 and :1121: handing ANS to the OS powered off only happens when /chosen/aurora,nvme-handoff = "off" is set from the loader's configuration. That makes the new handoff an opt-in setting. Once it is proven, make it the default behaviour whenever the OS side can start ANS from the passed SART entries, rather than keying it on a configuration switch.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants