Skip to content

kboot: hand over the T6021 (M2 Max) encoders, with a CRC on each reservation - #341

Closed
ludagoo wants to merge 2 commits into
aurora-silicon:mainfrom
ludagoo:ave/t6021-fw
Closed

ludagoo wants to merge 2 commits into
aurora-silicon:mainfrom
ludagoo:ave/t6021-fw

Conversation

@ludagoo

@ludagoo ludagoo commented Nov 19, 2026 •

Copy link
Copy Markdown

Stacked on #334. Base: #334's head 0421b4e0 (on main 3d517e63). One commit, 0f591198bf7b, +41/-24 in src/kboot.c and +94/-10 in tests/python/test_ave_handoff.py. The Linux side is aurora-silicon/linux#2374 (it reads what this publishes).

iBoot preloads AppleAVE2FW_H14C for both M2 Max encoders. The two share one TEXT image (0xf0000 bytes) and each has its own DATA (0x134000 bytes). On top of #334's handoff of every encoder:

No disabled-node skip. #334 hands over every encoder node and leaves its status as the device tree has it, except on T8140, whose tree leaves both encoders off and where it enables the one the ADT has; any failure disables the node. A skip of disabled nodes on every SoC would break T8140, so there is none. Which M2 Max encoders Linux uses is therefore the device tree's choice: aurora-silicon/linux#2376 enables them in t6021-peripherals.dtsi, for J414c, J416c and J475c. The handoff test covers both encoders with the nodes enabled and with them disabled.

On a SoC with one encoder the only DT change is the new property on its two reservations, with the same values as in /chosen.

Tested

Not done yet

🤖 Generated with Claude Code

…ode by address

dt_set_ave() handed over the first DT node of the first matching encoder
compatible and returned. Only T8140 walked all of its nodes and matched
each to an ADT node by address; every other SoC took ADT /arm-io/ave or
/arm-io/ave0 for that one node. The M1 Max has two encoders (ADT ave0 and
ave1) and the M1 Ultra four, one pair per die, and iBoot preloads a
firmware copy for each, so encoders after the first were never handed
over. dapf.c likewise admitted the preloaded __TEXT only through
dart-ave0.

Hand over every encoder node of every compatible in ave_compatibles. Each
node is matched to the /arm-io child named "ave" or "ave<N>" whose first
register range is at the node's translated DT address (the T8140 matcher,
now used everywhere, with dt_get_address() so that die 1's die-local
addresses on the M1 Ultra resolve to die 1's encoders). A lone node is
handled exactly as before; several nodes sharing a compatible are found
again by phandle, as T8140's already were. The DART whose vm-base the M2
handoff reads is now named after the matched encoder (dart-ave for ave).

Fail closed per encoder, as before: a node whose ADT twin is absent, not
preloaded or has invalid segments is disabled. The driver checks every
encoder against the one set of firmware CRCs in /chosen, so an encoder
whose preloaded copy differs from one already handed over is disabled
rather than overwrite them.

dapf_preload_text() now admits encoder N's __TEXT through dart-ave<N>.
dart-ave0 stays in dapf_entries; after the DT is final, kboot programs
dart-ave<N> (N >= 1) for each encoder the DT still enables and disables
the encoder if its filter cannot be programmed.

Kept for T8140 only, with its hardware reason in the comment: an A18 Pro
has one of its two encoders and only the ADT says which, so the DT leaves
both off and aura enables the one handed over with its DARTs and power
chain. T8140's inherited DAPF state stays untouched. The remap and DART
window bases stay selected by compatible as before.

A host test runs the handoff on every kernel DTB with an ADT modelled
from it: the DT edits on T6000, T6041, T8112, T8132, T8140 and T8142 are
byte-identical to before; only the multi-encoder T6001, T6002 and T6050
trees change.

The address matcher and the phandle walk generalized here are Diljit
Singh's T8140 handoff (f57127a).

Fixes: 0954fe3 ("kboot: hand off the AVE firmware on the M4 Pro too")
Fixes: 5933427 ("dapf: admit the preloaded AVE TEXT on the M1 Pro/Max CPU DART")
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, handing both encoders over through dt_set_ave_node and pairing each with its DART by MMIO address reads right, and it is selected by the encoder's compatible. Since the vm-base path is shared with T8112, we'll run a no-regression encode row on an M2 (T8112) and a J616s. The M2 Max row itself (both encoders bound, an H.264 encode per encoder, no DART faults) will need an owner's machine; a boot log from one would complete it.

@RyanTheTide

Copy link
Copy Markdown
Contributor

Thanks, and for the clear J475c write-up. The per-reservation aurora,crc32 is what any SoC with several encoders was missing, so we would like it on every SoC, not only T6021.

#334 hands over every encoder of every compatible, matched to ave/ave<N> by address, with dart-ave<N> by name, including the 4-encoder parts. Could you rebase onto it and keep:

  1. apple,t6021-ave in ave_compatibles.
  2. aurora,crc32 on each AVE reservation for every SoC (/chosen kept for the first encoder as fallback), replacing kboot, dapf: hand over every video encoder, each matched to its ADT node by address #334's disable-on-differing-copy.
  3. No t6021 bool in dt_set_ave_node(): drop dt_ave_paired_dart() and the phandles[2] cap (t6022-peripherals.dtsi has four nodes). The disabled-node skip should apply to every SoC or go, without board names.

We will move #334 forward so you have a base. After the rebase, one J475c boot with your earlier checks is enough: both encoders handed over, three reservations each with its CRC, both bound, one H.264 and one HEVC session per encoder. We will run M1 Pro and M2 no-regression boots for the single encoder.

@RyanTheTide

Copy link
Copy Markdown
Contributor

No-regression row on an M2 (T8112, J413) with this PR stacked on current main, as an aura-try Stage 2 trial: Enforcing, 0 kernel errors, 8/8 CPUs, s2idle 3/3, H.264 and HEVC 120-frame encodes byte-identical to the production Stage 2 (md5 f83a1801 / f05ab7ce), 0 DART faults. So the shared vm-base path is unchanged on T8112. The M2 Max row (both encoders) still needs an owner's machine.

…rvation

iBoot preloads AppleAVE2FW_H14C for both M2 Max encoders. Add
apple,t6021-ave to ave_compatibles: dt_set_aves() then finds both nodes
by phandle and matches each to ADT ave0 or ave1 by address, as for the
other multi-encoder SoCs. Like T8112, the T6021 firmware runs at its
DART's vm-base plus the segment iova; the DART is the one named after
the matched encoder (dart-ave0, dart-ave1). The two encoders share one
TEXT image, so the second appends its iommu-addresses tuple and
memory-region phandle to the first's TEXT reservation.

Their DATA images differ (on a J475c, CRC 7ae71157 for ave0 and
c1d56196 for ave1), so one set of CRCs in /chosen cannot describe both,
and refusing an encoder whose copy differs from the first would always
leave the second M2 Max encoder off. Instead, on every SoC, each
firmware reservation now carries aurora,crc32, the CRC of its own
segment, and /chosen keeps the first encoder's values for a kernel that
reads only /chosen. Such a kernel checks a later encoder against the
first encoder's CRCs and refuses it if they differ, so it still fails
closed. A shared reservation keeps the first value.

Every SoC's reservations gain the property; nothing else in the DT
changes for a SoC with one encoder.

Assisted-by: Grok 4.7
Assisted-by: Claude Opus 5.5
Signed-off-by: Lucas Goossen <lucas.goossen@hey.com>
@ludagoo ludagoo changed the title kboot: hand both T6021 (M2 Max) encoders their preloaded firmware kboot: hand over the T6021 (M2 Max) encoders, with a CRC on each reservation Nov 19, 2026
@ludagoo

ludagoo commented Nov 19, 2026 •

Copy link
Copy Markdown
Author

Thanks for the review. The updates are pushed; replies to each of your comments below.

Re: vm-base path shared with T8112; the M2 Max row needs an owner's machine

Thanks. The J475c is my Mac Studio, so I ran the M2 Max row on it (OS FW 13.5 / System FW 14.5, Stage 2 1.0.0b13-g0f591198-r4, kernel r4/t6021-j475c 4001510ea360):

Loader (mtd1 stage2.log):

[  7.151990] FDT: AVE /soc/video-codec@40d100000 handed over from ADT /arm-io/ave0
[  7.182118] FDT: AVE /soc/video-codec@507100000 handed over from ADT /arm-io/ave1
[  8.500741] dapf: /arm-io/dart-ave0 uses dapf-instance-1
[  8.500999] dapf: Initialized /arm-io/dart-ave0
[  8.511386] dapf: /arm-io/dart-ave1 uses dapf-instance-1
[  8.511646] dapf: Initialized /arm-io/dart-ave1

No FDT: AVE ... disabled: line and no CRC mismatch line.

Reservations (/proc/device-tree/reserved-memory/asc-firmware@* and /chosen):

  • asc-firmware@10000f04000 (shared TEXT, reg 0x10000f04000 0xf0000): aurora,crc32 = 6fbc7f77, iommu-addresses 40 bytes (phandle=0x17d and 0x17e, both iova=0x10000000000 size=0xf0000).
  • asc-firmware@100014fc000 (ave0 DATA, reg 0x100014fc000 0x134000): aurora,crc32 = 9e559ea2, phandle=0x17d, iova=0x100000f0000 size=0x134000.
  • asc-firmware@10001630000 (ave1 DATA, reg 0x10001630000 0x134000): aurora,crc32 = d142e9b5, phandle=0x17e, iova=0x100000f0000 size=0x134000.
  • /chosen/aurora,ave-data-crc32 = 9e559ea2, /chosen/aurora,ave-text-crc32 = 6fbc7f77.

Bind and encodes: both encoders bound (/dev/video11 = 40d100000.video-codec, /dev/video12 = 507100000.video-codec), every VENC domain (venc_* and venc1_*) off-0 at idle, 0 DART faults. 720p CQ 300f is byte-identical across encoders (H.264 md5 dc475ee7eca930731bcb0cb42d07d714, r_frame_rate=60/1, all 290 P slices references; HEVC md5 36ed04cc04166e7a8dad4b8d86324f06, r_frame_rate=30/1).


Re: rebase onto #334; the three points

Rebased onto #334 as it is now (0421b4e0, on main 3d517e63); one commit on top, 0f591198bf7b. I will rebase again when #334 moves.

  1. apple,t6021-ave is in ave_compatibles. kboot, dapf: hand over every video encoder, each matched to its ADT node by address #334's dt_set_aves() then finds both nodes and matches them to ADT ave0/ave1 by address and to dart-ave0/dart-ave1 by name; this PR adds nothing to that walk.
  2. Every AVE reservation now gets aurora,crc32 (its own segment's CRC), on every SoC. /chosen keeps the first encoder's values. kboot, dapf: hand over every video encoder, each matched to its ADT node by address #334's refusal of an encoder whose copy differs is removed: on the J475c the two DATA images differ (9e559ea2 and d142e9b5 on 13.5/14.5; 7ae71157 and c1d56196 on the earlier macOS firmware), so it would always disable the second M2 Max encoder. A kernel that reads only /chosen still fails closed: it checks the second encoder against the first encoder's CRC and does not bind it. The shared TEXT reservation keeps the first value and logs a line if a later encoder's TEXT differs.
  3. No t6021 bool in dt_set_ave_node(), no dt_ave_paired_dart(), no phandles[2] cap; the per-encoder TEXT iommu-addresses tuples and phandles come from kboot, dapf: hand over every video encoder, each matched to its ADT node by address #334. The disabled-node skip is gone rather than made general: kboot, dapf: hand over every video encoder, each matched to its ADT node by address #334 hands over every node and leaves its status as the DT has it, except on T8140, whose DT leaves both encoders off and where aura enables the one the ADT has. A skip on every SoC would break that. So the DT decides which M2 Max encoders Linux uses, which is what #2376 now does in t6021-peripherals.dtsi. The handoff test runs the M2 Max case with the nodes enabled and disabled.

The one T6021-specific line left is the vm-base choice, by compatible as in #334 (apple,t8112-ave or apple,t6021-ave): the T6021 firmware, like T8112's, runs at its DART's vm-base plus the segment iova. New on T6021 with #334: dt_set_ave_dapf() now also programs dart-ave1; on the J475c boot above both initialized cleanly (dapf: Initialized /arm-io/dart-ave0 and dapf: Initialized /arm-io/dart-ave1).

Tests (aarch64 build host): tests/python/test_ave_handoff.py 4/4 at #334 and at this commit. The case for two encoders now expects a CRC on every reservation and the second encoder handed over with differing DATA. The full pytest run gives the same result at both commits: 699 passed, 8 failed, 9 collection errors, the same tests in each, none in kboot. format-check shows no diff in kboot.c (clang-format 23.1.3; I did not have CI's 20.1.8).


Re: M2 J413 no-regression result

Thanks for running it. On T8112 the rebase adds only aurora,crc32 on the two reservations, with the same values as in /chosen; the kernel prefers the reservation's value, so the encode path is the same. The M1 Pro and M2 boots you mentioned would confirm that on the rebased branch.

One thing to expect on #2375, not this PR: with its settings moved to the 6070.11.1 layout, T8112's encodes change by design (B-frames default to 0 for both codecs; H.264 P pictures become references and the lambdas change), so the production Stage 2 md5s (f83a1801 / f05ab7ce) will not match once #2375 is in. This PR alone does not change them.

@DjDeveloperr DjDeveloperr 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.

Thanks, and for running the M2 Max row on your own J475c. Your commit (0f59119) reads right on top of #334:

  • apple,t6021-ave joins ave_compatibles, and the vm-base choice is made by compatible, as for T8112.
  • Every reservation gets its own aurora,crc32, and /chosen keeps the first encoder's values. A kernel that reads only /chosen still refuses a second encoder whose DATA differs, so it fails closed.
  • The disabled-node skip is dropped instead of made general, which keeps the T8140 path working.

It can't merge yet. It's stacked on #334, which is a draft, and while the branch conflicts with main no CI runs on it. Once #334 lands, it needs only a rebase onto main and green CI. The J475c boot on the rebased head and Ryan's single-encoder M1 Pro and M2 rows can then come after the merge, with a revert ready.

@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 in the top commit (0f59119). It can't merge until #334 (still a draft) lands. The branch conflicts with main today, so CI has not run.

Our 11-19 points:

  1. apple,t6021-ave in ave_compatibles: resolved.
  2. aurora,crc32 on each AVE reservation on every SoC, /chosen kept for the first encoder, #334's disable-on-differing-copy removed: resolved (src/kboot.c:4544-4563, :4691-4711). A kernel that reads only /chosen still refuses a second encoder whose DATA differs, so it fails closed.
  3. No t6021 bool, no dt_ave_paired_dart(), no phandles[2] cap, no disabled-node skip: resolved. Dropping the skip instead of generalising it is right, given the T8140 path.
  4. J475c boot of the rebased head: resolved by your 11-19 20:43 comment (Stage 2 g0f591198: both encoders handed over, both DARTs' DAPF initialised, three reservations each with its own CRC, both bound, H.264 and HEVC on each, 0 DART faults).

Findings:

  1. The description still says "This rebased version has not booted on the J475c", but your comment shows it did. Please update the "Not done yet" list so the merge commit's record matches.
  2. src/kboot.c:4699 rebuilds the reservation name as asc-firmware@%lx to find it again. That matches dt_reserve_asc_firmware() today (:4299). If the two ever drift, dt_ave_stamp_crc() fails and every encoder on every SoC is disabled: it fails closed, but it would be a silent regression everywhere. Having the reserve step return the node name (or offset), or a shared helper for the name format, would keep them in step. Not blocking.
  3. Minor: when a later encoder fails after it has appended its tuple to the shared TEXT reservation (src/kboot.c:4702 goto disable), its phandle stays in that reservation's iommu-addresses/memory-region while the node is disabled. That's harmless to the kernel, but it's worth a test case if #334's disable path is meant to leave the tree as if the encoder were never handed over.

Hardware rows we will run on the rebased head once #334 is in, as offered earlier:

  • M2 (T8112) and M1 Pro (T6000): this head as a one-shot Stage 2. Pass if the AVE reservations carry aurora,crc32 equal to /chosen/aurora,ave-{text,data}-crc32, there is no AVE ... disabled line, H.264 and HEVC 120-frame encodes are byte-identical to the production Stage 2 (before #2375 changes the settings), and there are 0 DART faults.
  • J616s (T6040, remap-address path): same pass criteria for its encoder.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

Blockers: 2.

The per-reservation aurora,crc32 is still needed: aura#420, which carries #334's commit rebased onto main, keeps the refusal of an encoder whose DATA differs from the first (src/kboot.c:4761-4770 at 40d111e). With that refusal the second M2 Max encoder is always disabled. The three points from 11-19 and the J475c row are settled, and the two notes from 11-20 (the rebuilt asc-firmware@%lx name, and the stale TEXT tuple after a late failure) still apply.

  1. Base: this branch is stacked on kboot, dapf: hand over every video encoder, each matched to its ADT node by address #334, which is still a draft and is superseded by kboot: hand over every video encoder by its block (M3 generation), rebased on main #420. The branch conflicts with main, so no CI has run on it. Please rebase onto kboot: hand over every video encoder by its block (M3 generation), rebased on main #420, or onto main once kboot: hand over every video encoder by its block (M3 generation), rebased on main #420 lands. After kboot: hand over every video encoder by its block (M3 generation), rebased on main #420 two hunks become unnecessary. apple,t6021-ave in ave_compatibles goes, because kboot: hand over every video encoder by its block (M3 generation), rebased on main #420 matches any apple,t<SoC>-ave and lists no SoCs. The vm-base choice by apple,t8112-ave/apple,t6021-ave compatible also goes, because kboot: hand over every video encoder by its block (M3 generation), rebased on main #420 uses the DART's vm-base on every encoder and checks it against each segment's remap. So the rebased commit is only the per-reservation CRC plus the removal of the differing-copy refusal. On the J475c, kboot: hand over every video encoder by its block (M3 generation), rebased on main #420's remap check must pass for both dart-ave0 and dart-ave1, so the boot row has to be rerun after the rebase.
  2. Attribution: commit 0f59119 carries Assisted-by: Grok 4.7 and Assisted-by: Claude Opus 5.5 trailers. Commits should carry only the human Signed-off-by. Please move the tool credit to the last line of the PR body, as Assisted-by: LLM (<Vendor>:<Model>), in place of the current "Generated with Claude Code" line.

The DT ABI is fine to land first. aurora,crc32 on the reservation is read only by linux#2374, which is still open. Kernels without it keep using /chosen and still refuse a second encoder whose CRC differs, so this fails closed.

HW row: a J475c on the rebased head, as in the 11-19 row. Pass criteria: both FDT: AVE ... handed over lines, with no "ADT remap disagrees" or "firmware differs" line; three reservations, each with its own aurora,crc32; both DARTs' DAPF initialised; both encoders bound, with an H.264 and an HEVC run on each and 0 DART faults. Add an M2 (T8112) no-regression encode, byte-identical to production.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor

#420 is merged on main (07e90bb) and #334 is closed. This branch conflicts with main 4a6a093 in src/dapf.c, src/kboot.c, tests/python/test_ave_handoff.py and tests/python/test_t8140_ave_enable.py; it needs a rebase onto main. After #420, the apple,t6021-ave entry in ave_compatibles and the vm-base choice by compatible are no longer needed; the per-reservation aurora,crc32 is what remains.

@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.

Review at 0f59119. The reservation-local CRC avoids selecting the wrong firmware copy when two encoders share a compatible. The first /chosen value remains a legacy fallback. Please verify handoff plus encode on both T6021 engines, and check the T8112 single-encoder path with an older consumer. Also add a refusal row that confirms a segment/CRC conflict cannot leave reachable stale memory-region references when only the second encoder fails.

@github-actions github-actions Bot added merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks required sections (bot) labels Nov 24, 2026
@RyanTheTide

Copy link
Copy Markdown
Contributor

@ludagoo a status note, since this has been waiting on the rebase since 11-22. main has moved under this PR twice:

So this is no longer a mechanical merge of main (45 conflicting hunks in src/dapf.c, src/kboot.c and two tests), and part of it may already be on main. The open question is the M2 Max case #538 was not written for: the TEXT segment both T6021 encoders share. Could you boot current main on your J475c and post whether both encoders are handed over and encode, as in your 11-19 row? If they are, this PR can close as superseded by #420 + #538. If one is still refused, the fix left is a small change on top of main, and a fresh branch is easier than this rebase.

@github-actions

Copy link
Copy Markdown
Contributor

Merge readiness at 0f591198: not ready yet

Check Detail
CI at head ok no CI for this change (the hardware row is the gate)
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head no no line with the head SHA 0f591198, a Mac and a result in the PR body or a comment
Conflicts no merge conflicts with main: merge it in (no force push)
PR text adopt when you next edit add a 'Risk:' line (door and Macs) (guide)

Areas: none matched in CODEOWNERS

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@RyanTheTide

Copy link
Copy Markdown
Contributor

@ludagoo the 24 h window from the 11-27 status note has passed, so I'm closing this as superseded by #420 + #538. Here is why, so it's easy to reopen if I'm wrong:

  • Encoder matching: kboot: hand over every video encoder by its block (M3 generation), rebased on main #420 (07e90bb) carries this branch's first commit. dt_ave_compatibles() reads the encoder compatibles from the DT, so the apple,t6021-ave entry and the vm-base choice by compatible are no longer needed.
  • Per-encoder CRCs: kboot, dapf: hand off second AVE encoder (ave1) with per-encoder firmware CRCs #538 (5522f10) removed the refusal of an encoder whose DATA CRC differs from the first one. It exports aurora,ave-<seg>-crc32 on each encoder's own node and mirrors the first encoder into /chosen. That is what the top commit's per-reservation aurora,crc32 was for.
  • The shared TEXT segment of the two T6021 encoders: on main, dt_reserve_asc_segments_at() gets the reservation through dt_get_or_add_reserved_mem() with the segment's asc-firmware@<phys> name. The second encoder therefore reuses the same reserved-memory node and appends its own memory-region and IOVA mapping, instead of failing.

What I couldn't check without an M2 Max: a boot of current main on your J475c. If it shows the second encoder refused or not encoding, please open a small fresh branch on top of main with that one fix (and your 11-19 style row), and link it here. That will be much easier than rebasing the 45 conflicting hunks here. Thanks for the original work, which is what #420 landed.

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

Labels

merge-conflict Conflicts with the base branch (bot) needs-hw-row No hardware row at the PR head (bot) needs-template PR body lacks required sections (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants