Skip to content

arm: apple: bring PCIe up only when USB is started at boot - #65

Draft
RyanTheTide wants to merge 2 commits into
aurora-wipfrom
bootrace/apple-pcie-on-demand
Draft

RyanTheTide wants to merge 2 commits into
aurora-wipfrom
bootrace/apple-pcie-on-demand

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 19, 2026 •

Copy link
Copy Markdown
Contributor

Problem

On an M1 Pro with #58, board_init_r() still takes 0.62 s, and bootstage marks after every initcall put all but 36 ms of it in one initcall: initr_env() (554 ms; this config has no MMC/NAND/OneNAND between it and efi_init_early()).

env_fat_load() calls pci_init() before it scans NVMe whenever CONFIG_PCI is on. On Apple Silicon NVMe is a platform device, so this only brings up every PCIe port. Each enabled port costs a fixed 100 ms after PERST# (apple_pcie_setup_port()), then a ready poll and a link poll of up to 100 ms. The 14"/16" MacBook Pro has two such ports (Wi-Fi and the SD card reader). PCI_INIT_R would bring them up a moment later anyway. Nothing in U-Boot uses them on these machines, and the OS resets every port again.

Change

  • env: fat, ext4: enumerate PCI before an NVMe scan only with CONFIG_NVME_PCI, the only case where an NVMe controller can be on PCI.
  • arm: apple: drop PCI_INIT_R from apple_m1_defconfig. board_late_init() runs pci_init() only if preboot starts USB. The PCIe xHCI behind the USB-A ports of machines without a built-in keyboard is the only PCIe device U-Boot drives here, and preboot keeps usb start exactly there (apple_typec_late_init()), or wherever a saved environment asks for it. pci enum still works by hand.

Desktops keep today's behaviour: PCIe still comes up before preboot runs usb start. Laptops skip it. The A18 Pro already skips PCIe in the driver.

Testing

Still to run

aura-try U-Boot trials (Stage 2 with only the U-Boot payload swapped, trial guard, dead-man), stacked on #58, 3 boots each:

  • M1 Pro: board_init_r -> main_loop drops from 0.62 s by 0.2 to 0.4 s.
  • M2: 0.1 to 0.2 s.
  • M4 Pro (t6041-pcie): similar.

In Linux on each trial boot: Wi-Fi associates, Bluetooth is present, the SD reader enumerates (M1 Pro), and there are no pcie-apple errors, 0 failed units and 0 AVC. A desktop row (Mac mini: USB-A keyboard at the U-Boot prompt) is owed before merge.

What else is in the 554 ms

After PCIe, initr_env() also cold-boots the ANS (the boot loader resets it before handing over on pre-M4 machines), enables the controller, identifies the namespaces, scans the GPT, finds the ESP (FAT mount, fs_exists()), and reads uboot.env. An instrumented build with marks inside those steps (and an NVMe command counter) is part of the trial set, to size each piece before touching any of them. No fixed delays are on that path in the source: the RTKit handshake waits on mailbox messages, and the ready polls (ANS_BOOT_STATUS, CSTS.RDY) poll registers.

Loading the environment from a file system on NVMe enumerated every PCI
bus first, so that a PCI-attached controller is found. With
CONFIG_NVME_PCI off no NVMe controller can be on PCI, and the
enumeration only brings up buses that have nothing to do with the
environment. On Apple Silicon, where NVMe is a platform device, this
trained the links of every PCIe port (100 ms after PERST# each, plus
the link wait) while loading uboot.env.

Signed-off-by: Ryan Murray <[email protected]>
PCI_INIT_R enumerated every PCIe port after relocation on every boot.
Each enabled port costs 100 ms after PERST# deassertion plus the wait
for its link, so the Wi-Fi and SD card ports of a 14"/16" MacBook Pro
cost U-Boot a few hundred milliseconds, and the OS resets every port
again anyway. The only PCIe devices U-Boot drives on these machines
are the PCIe xHCI controllers behind the USB-A ports of machines
without a built-in keyboard, and USB is started at boot only there
(preboot "usb start", see apple_typec_late_init()).

Drop PCI_INIT_R and enumerate PCI in board_late_init() when preboot
starts USB, which keeps the desktops as they are and also honours a
saved environment that starts USB. "pci enum" still works by hand.

Signed-off-by: Ryan Murray <[email protected]>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Looks good; approve once the laptop and desktop rows below have run.

What I checked:

  • env/fat.c:143 and env/ext4.c:163: with CONFIG_NVME_PCI off, no NVMe controller can sit on PCI (drivers/nvme/Kconfig: NVME_PCI depends on PCI). So skipping pci_init() there is correct on every board, including non-Apple ones.
  • arch/arm/mach-apple/board.c:1731-1732 runs before main_loop() runs preboot. A desktop whose preboot keeps usb start (apple_typec_late_init(), :1676-1686) still has PCIe up before USB starts, the same as with PCI_INIT_R.
  • On the apple_efi_late_init() machines (:1714-1719) preboot is already cleared (:1593-1594), so PCIe was brought up there without anything using it. Skipping it loses nothing.
  • Both commits carry only a human Signed-off-by, and CI builds.
  1. Nit, board.c:1731: the trigger is a substring match on an environment variable. A saved preboot such as echo no usb start also brings PCIe up, and a desktop whose saved preboot drops usb start now needs pci enum before a hand-typed usb start finds the USB-A ports. That second case used to work. Mention it in the doc next to the pci enum note, or key the bring-up on the presence of an enabled PCI xHCI node in the DT.

This changes when PCIe trains on every Mac, so it needs a run before merge.

HW row: aura-try U-Boot trials on this head (stacked on #58 is fine), 3 boots each:

  • M1 Pro J316s: board_init_r to main_loop drops by 0.2-0.4 s. In Linux, Wi-Fi associates, Bluetooth is present, the SD reader enumerates, and there are no pcie-apple errors.
  • M2 J413 and J616s: the same Linux checks.
  • One desktop (Mac mini or Studio): a USB-A keyboard works at the U-Boot prompt, and usb start by hand still finds it.

All with 0 AVC, 0 failed units and 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.

1 participant