Skip to content

kboot: gpu: hand the M4 (T8132) GPU to Linux on the 27.2 firmware - #379

Merged
DjDeveloperr merged 3 commits into
mainfrom
djdev/t8132-gpu-272
Nov 21, 2026
Merged

DjDeveloperr merged 3 commits into
mainfrom
djdev/t8132-gpu-272

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Nov 20, 2026 •

Copy link
Copy Markdown
Contributor

The M4 (T8132, G16G) GPU handoff now works with the macOS 27.2 (26B123) firmware layout as well as 26.6.2. Until now, Linux booted from a 27.2 volume on a J773g (Mac mini) got no GPU. The Linux G16 driver is moving to the 26B123 firmware ABI; this is the boot side.

What changed in 27.2

On 27.2, iBoot loads the G16G firmware as three /arm-io/gfx-asc segments instead of two. The extra one is a 32 KiB __DATA_SHARED_RO placed right after __DATA, which /arm-io/sgx describes as gfx-data-shared-ro-{base,size}. This is the same shape T6041 has on 27.2 (#373). From the J773g's own iBoot ADT on 26B123:

segment size firmware VA flags
__TEXT 0x64000 (was 0x60000) 0xfffffc0000000000 1
__DATA 0xd0000 (was 0x13c000) 0xfffffc0000064000 0x10 (was 0)
__DATA_SHARED_RO 0x8000 (new) 0xfffffc0000134000 0

segment-names is __TEXT;__DATA;__DATA_SHARED_RO, and gfx-data-shared-rw-{base,size} are 0. The UAT regions, the sgx and gfx-asc register windows and the IRQs are the same as on 26.6.2.

What this does

  1. One shared helper. t604x_gpu_fw_segments() becomes gpu_fw_layout(), declared in kboot.h. It also returns the segment list and its count. T6040, T6041 and now T8132 all use it, and its checks and the T6040/T6041 fills are unchanged.
  2. T8132 handoff (kboot_gpu_m4.c) takes its layout from that helper, so the ADT's shape chooses it:
    • Two segments, as before: names __TEXT;__DATA, flags <1 0>, gpu-fw-data = __DATA, apple,g16-handoff-version = 1.
    • Three segments: names __TEXT;__DATA;__DATA_SHARED_RO, flags <1 0x10 0>. gpu-fw-data covers __DATA and the shared-RO tail, as on T6041. apple,firmware-segment-vas and apple,firmware-segment-flags get three entries, and apple,g16-handoff-version = 2. A version-1 driver refuses this contract before it maps anything.
    • Both layouts keep the identity remap, firmware VAs that run on from 0xfffffc0000000000, 16 KiB alignment, the 42-bit bound and the pairwise overlap checks with the UAT regions.
  3. No board or release gate. The handoff is selected by what the machine describes: a GPU node compatible with apple,agx-t8132, and a /arm-io/gfx-asc firmware layout that gpu_fw_layout() accepts. Any other shape keeps the GPU off and the Mac on its framebuffer. The earlier chip, J713 and OS-release (26.6.2/27.2) clauses are gone. A DT whose GPU node is not the T8132 GPU is left untouched for its own handoff.

Why the ADT shape decides: as Ryan asked on #373, the layout follows the hardware description (the segment count and the sgx gfx-data-shared-ro pair), not the machine or the release it was tested on. A two-segment ADT on 27.2 still gets version 1, and a three-segment ADT on the J713 gets version 2.

What Linux sees on a J773g on 27.2 (live ADT values):

  • /gpu: apple,g16-handoff-version = <2>, apple,firmware-segment-vas = <0xfffffc0000000000 0xfffffc0000064000 0xfffffc0000134000>, apple,firmware-segment-flags = <1 0x10 0>
  • /reserved-memory/gpu-fw-text: 0x10000d04000 + 0x64000
  • /reserved-memory/gpu-fw-data: 0x100011a4000 + 0xd8000 (__DATA 0xd0000 + __DATA_SHARED_RO 0x8000)
  • uat-ttbs, uat-pagetables, uat-handoff, uat-shared-l2: unchanged. There are no new nodes or memory-region-names, and the six memreserves match.

Tests

  • New tests/python/test_t8132_gpu_fill.py, 28 cases, with the failure model written down first. It fails on main, where the 27.2 layout is refused, and passes here. Vectors:
    • 26.6.2: the regions aura published on a J773g from its ADT.
    • 27.2: the J773g's 26B123 iBoot ADT, captured from Stage 1's proxy on the 27.2 volume before any chainload. The vector was cross-checked against the capture mechanically. The raw capture stays out of the repo.
    • Accepted cases: both layouts, the two segment counts crossed with the release, the J713 and the J773g on 27.0, an unknown release with a two-segment ADT, and 26.6.2 ADTs that carry zero shared-RO/RW properties.
    • Refused cases: the wrong segment count; names that don't match the count; a missing or disagreeing sgx pair; a tail that is apart, unaligned, not identity-mapped or at the wrong VA; non-zero shared RW; the other layout's flags; a UAT region overlapping the tail; the 42-bit bound; unknown ADT shapes on 27.0 and on an unknown release.
    • A mutation check (dropping the tail, the version or the flags check) fails it each time.
  • test_m4_gpu_handoff.py, test_t6040_gpu_fill.py and test_t6041_gpu_fill.py now take the helper and its struct from the source. In test_m4_gpu_handoff.py, the J715-on-26.6 refusal is now an unknown-ADT-shape refusal, and a GPU node of another GPU is left untouched. All pass, as do the G15 and T6031 host runners that include this file.
  • The reservation lookup takes uint64_t, as fdt_get_mem_rsv() does, for the macOS host build where u64 is not unsigned long long.

Checks (run locally: Actions macOS runners are out)

Each check below was run on this head, rebased on main c879917, and on c879917 itself.

  • make format-check with clang-format 20.1.8: clean. make rustfmt-check: clean.
  • tools/stage1_size.sh with clang (USE_CLANG=1 BUILDSTD=1 BUILTIN_LOGO=aurora, 4 flavours): all link. Shipping Stage 1 headroom is 16608 B (main 16624 B, so this costs 16 B; the floor is 4096). secure-audit and secure-enforce: 147800 B. dev-audit: 16416 B.
  • stage1-clang pair (RELEASE=1 CHAINLOADING=1 BUILTIN_LOGO=aurora, then ESP_STAGE2=1): both build. aura.bin is 1638400 / 3997696 B, the same as main.
  • ESP Stage 2 size job, both configs: both build. The ESP vital region is 745480 B with a 434168 B margin, identical to main (the macOS ESP image compiles the Linux handoff out).
  • The four GPU host tests (test_t8132_gpu_fill, test_m4_gpu_handoff, test_t6040_gpu_fill, test_t6041_gpu_fill) pass with gcc and clang, and also on the first commit alone.
  • Full pytest with clang: 815 passed, 13 failed. Main gives 814 passed and the same 13 failures (test_m3_defaults_optout x7, test_smp_legacy_rvbar x2, test_chainload_run_base, test_payload_cpu_policy, test_siliconforest_handoff, test_smp_timeouts). Those are host-only: clang 23 warnings and an updater-script path.
  • Not reproducible here: the gcc build jobs (host gcc 16 cannot link aura, even on main).

Hardware

  • J713 (MacBook Air M4), 27.2: boots with the GPU on by default with this handoff as Stage 2 and the G16 26B123 driver: GNOME on the GPU, dEQP-VK smoke 6125/0, glmark2-es2 1341, vkmark 1751, 21 min with 0 stalls, 3/3 warm reboots, 0 faults. That run predates the selection change in this head, so a re-run on this head is requested.
  • J773g (Mac mini M4), 27.2: the G16 driver runs on this handoff's version-2 contract (vk-smoke, dEQP-VK smoke 13,032/0/0/0). A row on this head's Stage 2 image is pending.

Assisted-by: LLM (Claude:Opus 5.5)

t604x_gpu_fw_segments() picks the GPU firmware layout from the ADT's
shape: gfx-asc segment-ranges __TEXT and __DATA, or those and a
__DATA_SHARED_RO right after __DATA that /arm-io/sgx
gfx-data-shared-ro-{base,size} describe (the 27.2 firmware). Nothing in
it is T604x-specific, and the M4 (T8132) handoff needs the same choice.

Rename it gpu_fw_layout(), declare it and its result in kboot.h, and
also return the segment list and count, which the T8132 handoff
publishes per segment. The checks and the T6040/T6041 fills are
unchanged; their host tests take the struct from kboot.h.

Signed-off-by: Diljit Singh <hey@djdev.me>
On macOS 27.2 (26B123) iBoot loads the G16G firmware as three gfx-asc
segments: __TEXT (0x64000), __DATA (0xd0000) and a 32 KiB
__DATA_SHARED_RO right after __DATA, which /arm-io/sgx describes as
gfx-data-shared-ro-{base,size}. The J773g's ADT gives them the flags 1,
0x10 and 0. The M4 handoff required exactly two segments named
__TEXT;__DATA and admitted boards other than the J713 only on 26.6.2,
so Linux booted from a 27.2 volume got no GPU.

Take the layout from gpu_fw_layout(), the helper the T6040/T6041 fills
use, so the ADT's shape chooses it:
- Two segments, as before: names __TEXT;__DATA, flags 1 and 0, two
  firmware segment VAs and flags, apple,g16-handoff-version 1.
- Three segments: names __TEXT;__DATA;__DATA_SHARED_RO, flags 1, 0x10
  and 0, gpu-fw-data covering __DATA and the shared-RO tail (as on
  T6041), three firmware segment VAs and flags,
  apple,g16-handoff-version 2.
Both keep the identity remap, consecutive firmware VAs from
0xfffffc0000000000, 16 KiB alignment, the 42-bit bound and the pairwise
overlap checks. Boards other than the J713 now also take the handoff on
27.2; the J713 still takes it on any release.

The new host test runs both layouts with one J773g's values: on 26.6.2
the regions aura published from its ADT, on 27.2 its iBoot ADT.

Signed-off-by: Diljit Singh <hey@djdev.me>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Hardware row from the 13" M4 MacBook Air (J713, Mac16,12, 8-core G16G, macOS 27.2 / mBoot-20457.41.3): the 27.2 handoff in this PR works.

ESP Stage 2 built from djdev/t8132-gpu-272 (897ec66), plus two things this Air needs: our ANS start-from-off fix, and your T8132 MCC stopgap from #374. Without the stopgap, any Stage 2 on this base resets the Air in mcc_init() (this ADT has a 4-byte amcc_aperture_count too). Four boots as an aura-try trial (Stage 1 unchanged), all with the same result:

  • aura logs FDT: GPU: published M4 G16 memory resources (3 firmware segments) without starting the GPU.
  • Linux sees apple,g16-handoff-version = 2, segment VAs 0xfffffc0000000000 / +0x64000 / +0x134000, flags 1 / 0x10 / 0, gpu-fw-text 0x64000 and gpu-fw-data 0xd8000 (__DATA plus the __DATA_SHARED_RO tail), and all four UAT regions.
  • The G16 driver (djdev/g16-272-wip + linux#2543) accepts it: GPU firmware build: Apple GFX 26B123 (build b000, iBoot-filled ranges zeroed), admitted, 8 cores, UAT self-check passed. So the generic 26B123 entry covers the 8-core J713.

How far the GPU itself gets is kernel-side and tracked on djdev/g16-272-wip: with 255f7f31 the firmware accepts InitData and then crashes on the first device-control doorbell. That part is unrelated to this handoff.

Details
  • Stage 2: aura lab/j713-gpu-ans-drain 36d1f22 = 897ec66 + ANS reset/drain/6 s warm wait (see nvme, rtkit: post-M4 ANS warm start: drop stale messages, wait 6 s for the IOP power report #394) + cherry-pick of b89bdac. RELEASE=1 CHAINLOADING=1 ESP_STAGE2=1, composed with the J713 DTB and U-Boot.
  • Kernel: 7.3.0 lab build (integration + linux#2533 + djdev/g16-272-wip + linux#2543) as a non-default one-shot; aurora.ko loaded by hand.
  • J713 ADT /arm-io/mcc: amcc_aperture_count 4 bytes (2), dcs-count-per-amcc 4 bytes (4), plane-count-per-amcc 4 bytes (2).
  • Display stays on simpledrm on 27.2: aura doesn't hand over the T8132 display subsystem, so G16 starts on the boot framebuffer without waiting for it.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The Pytest (macos-15 + llvm-brew) failure is real: test_t8132_gpu_fill stops compiling the host fixture on macOS. The new typedef unsigned long u64; makes u64 a different type from the host's uint64_t there (unsigned long long), so fdt_get_mem_rsv(dt, i, &base, &size) at lines 179 and 446 of the generated t8132-gpu-fill.c fails -Werror,-Wincompatible-pointer-types. Declaring those two base/size locals as uint64_t (or casting through temporaries) keeps the aarch64 u64 match and builds on both hosts. Linux runners are unaffected.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One point under the project's pre-PR checklist (no model or firmware-version gating), not raised so far:

src/kboot_gpu_m4.c:66-68 still admits the handoff by board and OS release. Boards other than the J713 get it only when os_firmware.version is V26_6_2 or V27_2, and the J713 (apple,j713) gets it on any release. Everything else in this PR already selects by the hardware description. gpu_fw_layout() takes the layout from the ADT's shape and refuses any other shape, the segment names and flags are checked per layout, and a driver that doesn't know apple,g16-handoff-version refuses before it maps anything. So the release check adds no safety. It only means every new release, and every board other than the J713, needs another entry here.

Please drop the os_firmware.version clause and the apple,j713 exception. Select the handoff by the apple,agx-t8132 GPU node (already checked on the same line) and an ADT /arm-io/gfx-asc layout that gpu_fw_layout() accepts. When either is missing or the shape is unknown, keep today's return -1: no GPU handoff is published and the Mac boots on the framebuffer. The host test's "27.0 on the J773g" and "unknown release" refusals would then become "unknown ADT shape" refusals.

Assisted-by: LLM (Claude:Opus 5.5)

…yout

The M4 handoff was selected by chip, by board (J713) and by the OS
release (26.6.2 or 27.2). Select it by what the machine describes
instead: a GPU node compatible with apple,agx-t8132, and a gfx-asc
firmware layout that gpu_fw_layout() accepts. Any other shape keeps the
GPU off and the Mac on its framebuffer. A DT whose GPU node is not the
T8132 GPU is left untouched for its own handoff.

The host tests now publish the 27.2 layout on 27.0 and the 26.6.2 layout
on an unknown release, and refuse unknown ADT shapes on either. The
reservation lookup takes uint64_t, as fdt_get_mem_rsv() does, so it
builds where u64 is not unsigned long long.

Signed-off-by: Diljit Singh <hey@djdev.me>

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No blockers. Re-review of b2ba5cd against 897ec66.

The point from our last review is resolved. src/kboot_gpu_m4.c:70 and :183 now select the handoff only by the apple,agx-t8132 GPU node, and gpu_fw_layout() plus the per-layout segment names and flags (:115-138) pick the contract. The chip, apple,j713 and os_firmware.version clauses are gone, and a missing node or an unknown shape still ends in return -1: no handoff properties, GPU disabled, framebuffer boot. The host tests now cover that: 27.0 and an unknown release are published when their ADT shape is valid, and refused when it isn't. The uint64_t change for fdt_get_mem_rsv() fixes the macOS host build we reported.

Also checked on this head. Short or missing ADT props all fail closed: read_exact() needs the exact length, segment-names must match byte for byte, segment-ranges must be 2 or 3 entries, and the shared-RO/RW pair goes through ADT_GETPROP size checks. The stale apple,g16-handoff-version is deleted before any refusal path can return. This handoff publishes no perf states or voltages, so it adds no safety constants. A GPU node for a different GPU is now left untouched (fault 12) and doesn't get disabled; that's correct, since that GPU's own fill owns it.

Two non-blocking nits:

  1. src/kboot_gpu_m4.c:84-91 still compares the sgx/gfx-asc register windows and the four IRQs to fixed values. This fails closed and isn't a selection gate, but it is the last per-chip table in this path. If you touch it again, compare the ADT values with the DT /gpu node's own reg and interrupts instead of constants.
  2. tests/python/test_m4_gpu_handoff.py:78-79: the comment says gpu_fw_layout() rejects fault 11. It's the per-layout flags check in publish_gpu_m4() that refuses it, because two segments with <1 0x10> pass gpu_fw_layout().

Hardware row: the J713 run in the body predates this head. Re-run it on a Stage 2 built from b2ba5cd on the J713, 27.2, default cmdline. Pass if the boot log shows "published M4 G16 memory resources (3 firmware segments)", /gpu has apple,g16-handoff-version = <2>, dEQP-VK smoke has 0 failures, and 3/3 warm reboots come up with 0 GPU faults.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Row on the M4 Air (J713, macOS 27.2 stub) for b2ba5cd: one aura-try Stage 2 one-shot of the J713's configured aura plus only this commit (so the gate is the only change against its default), default kernel, stock command line.

  • Stage 2 1.0.0b13-ga8d25a59 booted; /soc/gpu@302600000 carries apple,g16-handoff-version = <2> and the uat-handoff reservation is present.
  • G16G admitted, the 27.2 boot pair retired in 132 us, firmware READY, backend started.
  • dEQP-VK smoke 5/5 Pass, 0 firmware crash lines, 0 AVC, Enforcing; a 60 s off-screen glmark2 heat run stayed crash-free with the cooling limiter stepping as designed.
  • Back on the production default afterwards (Stage 2 b7f07c4, no trial left).

Not covered by this row: warm reboots on this head (a one-shot boots once), and the Stage 2 console line itself (Linux sees its result, the DT property above).

Assisted-by: LLM (Claude:Opus 5.5)

@DjDeveloperr

Copy link
Copy Markdown
Contributor Author

J773g (Mac mini M4, macOS 27.2 / 26B123 firmware) row on head b2ba5cd: PASS

  • Stage: the current J773g test stage plus b2ba5cd (the PR's other two commits were already in it, byte-identical).
  • Console: FDT: GPU: published M4 G16 memory resources (3 firmware segments) without starting the GPU
  • Linux (default J773g test kernel + G16 27.2 kit): GPU READY, Vulkan smoke PASS.
  • CI: all 15 checks green on b2ba5cd.

Still pending: the J713 re-run on b2ba5cd and review.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

The J713 re-run on b2ba5cd is the row in our comment just above (10:49Z): PASS, apple,g16-handoff-version = <2>, G16 READY, dEQP-VK smoke 5/5, 0 firmware crashes; your J773g row covers the Stage 2 console line.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving b2ba5cd. The handoff is now chosen only by the apple,agx-t8132 GPU node and an ADT firmware layout gpu_fw_layout() accepts (no chip, board or OS-release gate), anything else boots on the framebuffer, and missing or short ADT properties fail safe. Proven on two Macs on 27.2: our J713 one-shot (gate the only change against its default: apple,g16-handoff-version = <2>, G16 READY, dEQP-VK smoke 5/5, 0 firmware crashes) and the J773g row (console published M4 G16 memory resources (3 firmware segments), Vulkan smoke PASS); CI green. Non-blocking nits from our earlier comment still stand (fixed sgx/gfx-asc register values at kboot_gpu_m4.c:84-91, the fault-11 test comment).

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.

2 participants