Skip to content

arm: apple: stop the T8140 MTP with an RTKit sleep at OS entry - #37

Draft
DjDeveloperr wants to merge 1 commit into
aurora-wipfrom
t8140/mtp-sleep-stop
Draft

DjDeveloperr wants to merge 1 commit into
aurora-wipfrom
t8140/mtp-sleep-stop

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 7, 2026 •

Copy link
Copy Markdown
Contributor

On T8140 (J700, the Neo) U-Boot starts the MTP for its own keyboard. Until now it handed the running session to the OS at boot: no-map reservations for the firmware's DRAM buffers, the DART stream kept in bypass, and apple,rtkit-handoff = "mtp-live-v1". Linux had to adopt that session and could never restart it.

This PR stops the MTP before the OS instead, so Linux starts it as its own.

  • rtkit_helper_stop() asks a T8140 MTP for an RTKit sleep (APPLE_RTKIT_PWR_STATE_SLEEP) instead of QUIESCED. It then clears the run bit, frees the RTKit state and releases the DART bypass, as before. A failed stop is now logged.
  • apple_rtkit_helper_fdt_fixup() skips the T8140 helper, so the OS tree gets no reservations, no apple,bypass-handoff-streams and no apple,rtkit-handoff.
  • U-Boot's keyboard, GRUB's input through EFI ConIn, and the INIT replay into the DockChannel FIFO stay as they were.
  • J713, J614s and every other helper keep their handoff and the QUIESCED stop. rtkit_helper_fdt_publish() is untouched, so arm: apple: enable J613 keyboard input with a live MTP handoff #30 (J613) still has it.

A firmware stopped for a sleep only comes back from its reset vector, and the run bit alone doesn't put it there. The matching Linux change resets the MTP's CPU through its always-on PMGR word, then sets the run bit and wakes RTKit. A kernel without that change loses the internal keyboard and trackpad with this U-Boot, so the kernel has to ship first. Kernels with it still adopt a live session from an older U-Boot.

Tests

  • apple_m1_defconfig with CONFIG_WERROR=y, GCC 16.1.1 (aarch64): builds with no warnings.
  • test_apple_helper_handoff.py gains two checks: the fixup leaves a T8140 tree byte-for-byte unchanged and stops nothing, and the stop asks for SLEEP on T8140 and QUIESCED elsewhere. Both fail if the T8140 branch is taken out. All 9 tests in test_apple_helper_handoff.py and test_apple_mtp_keyboard.py pass on aarch64 Linux.

On hardware (J700, 2026-11-08): not working yet

With this U-Boot and a kernel carrying aurora-silicon/linux-aurora#63:

  • U-Boot's own keyboard works. version typed on the built-in keyboard at the prompt ran, and GRUB then booted the kernel through EFI. The stop at OS entry logged no error.
  • Linux can't start the MTP after this stop. Linux resets the CPU (CPU reset in place: 0x1f0003ff before, 0x9f0007ff held, 0x1f0003ff after, SRAM 0x1f0002ff), sets the run bit and sends INIT. The firmware never reads that message: it stays in the inbox, the outbox stays empty, and CPU status reads 0x48 (running, not idle). RTKit gives up with endpoint discovery failed: -62. So this U-Boot as it stands loses the internal keyboard and trackpad in Linux.
  • Linux's own RTKit sleep fails the same way: start the MTP in Linux, unload the module (sleep, run bit off), then load it again. So the problem is the firmware's sleep state, not something specific to U-Boot's stop.
  • A firmware nobody has run starts fine with the same Linux code (U-Boot built with APPLE_MTP_KEYB off): MTP Says Hello, keyboard ready, and the firmware announces its interfaces itself.
  • The cause, from SRAM reads (0x314c00000, 1 MiB, the reset vector's target): the firmware's code (0x0–0x4ffff) doesn't change while it runs, but its data (0x50000–0x5ffff) and runtime areas do. After a run, MTP_CPU also has AUTO_ENABLE set and shows it was power-gated (0x1f0003ff, against 0x0f0000ff before any run).
  • Tried: keeping a copy of the SRAM before the first start and writing it back at OS entry, so the OS gets an image nobody ran. U-Boot took an SError while doing it, right after the CPU reset's last PMGR write and before any SRAM write. That work isn't pushed.

Older U-Boot (#32) with the same kernel still adopts the live session, and the keyboard and trackpad work.

🤖 Generated with Claude Code

U-Boot starts the T8140 MTP for its own keyboard and used to hand the
running session to the OS. It reserved the firmware's DRAM buffers, left
the DART stream in bypass and set apple,rtkit-handoff = "mtp-live-v1".
Linux then had to adopt that session and could never restart it.

Stop it before the OS instead. The remove path now asks for an RTKit
sleep rather than QUIESCED, clears the run bit and releases the DART
bypass, and the OS device tree fixup publishes nothing for this helper.
A firmware stopped for a sleep starts again from its reset vector, so
the OS can reset the MTP's CPU and run it as its own.

U-Boot's keyboard and its INIT replay into the FIFO don't change. J713,
J614s and the other helpers keep their handoffs and the QUIESCED stop.
A failed stop is now logged.

A kernel without the matching rtkit-helper restart loses the internal
keyboard and trackpad, as the Kconfig help says.

Signed-off-by: Diljit Singh <[email protected]>
@aeries0x

Copy link
Copy Markdown

Same behaviour on the J604 (T8132), in case it helps here: U-Boot's stdio probe starts the MTP, the QUIESCED stop at OS
entry follows, and Linux's start then crashes the firmware in its IOReport path (details and the mailbox history in
#44). A firmware nobody ran starts fine there too.

One measurement that may be useful for the save-and-restore idea: on the J604 I dumped the MTP's three segments before
any start, once behind aura's Mach-O Stage 1 and once behind a chainloaded m1n1. Text (0x5e000 bytes) and the DRAM
segment (0x3000) were identical between the two boots, and the data segment (0x6c000) differed only in two per-boot
random values iBoot writes (tagged STKG and PACE). So a pristine copy has to come from the same boot; one saved from
an earlier boot would carry the wrong values.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2. Recommend closing this in favour of #49.

  1. arch/arm/mach-apple/rtkit_helper.c:293 and :611: with this head a T8140 MTP is put to SLEEP at OS entry and nothing is published, but by the PR's own J700 run (2026-11-08) Linux cannot restart a firmware stopped this way (INIT never read, endpoint discovery failed: -62), and the Linux module sleep/reload shows the same failure. Merging it loses the internal keyboard and trackpad on J700 with every kernel, including ones carrying the CPU-reset restart. The stop has to leave the OS a firmware it can start (the pristine-image park in arm: apple: park the T8140 MTP at OS entry with its pristine image #49, which already carries this commit unchanged) or keep the live handoff.
  2. arch/arm/mach-apple/rtkit_helper.c:83-86: rtkit_helper_sleeps() picks the stop policy from the T8140 helper compatible. Since arm: apple: hand an MTP over running when its device tree says its firmware cannot be restarted #67 (11bf692) the handoff choice is carried by the board DT (apple,rtkit-keep-running on the helper node), and this branch predates it: a rebase must select sleep-vs-handoff through that DT path rather than a second compatible check in the fixup, otherwise a T8140 tree that sets keep-running is silently skipped at :611.
    Nit: the PR body ends with a "Generated with Claude Code" line; replace it with Assisted-by: LLM (<Vendor>:<Model>).
    HW row: J700, U-Boot at the rebased head plus the matching kernel: built-in keyboard at the U-Boot prompt, then in Linux MTP Says Hello, keyboard and trackpad events on 3 cold boots and after an s2idle cycle; 0 AVC, 0 failed units, no new kernel errors.
    Assisted-by: LLM (Claude:Opus 5.5)

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.

3 participants