Skip to content

kboot, dapf: hand over every video encoder, each matched to its ADT node by address - #334

Closed
RyanTheTide wants to merge 1 commit into
mainfrom
spec12/ave-multi
Closed

RyanTheTide wants to merge 1 commit into
mainfrom
spec12/ave-multi

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Problem

dt_set_ave() handed over only the first DT node of the first matching encoder compatible. For every SoC except T8140 it took ADT /arm-io/ave or /arm-io/ave0 for that node. The M1 Max has two encoders (ADT ave0 and ave1) and the M1 Ultra four. iBoot preloads a firmware copy for each, but the encoders after the first were never handed over. dapf.c likewise admitted the preloaded __TEXT only through dart-ave0.

Change

  • 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 is at the node's translated DT address. This is the T8140 matcher, now generic as dt_ave_adt_path(). It uses dt_get_address(), so 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 one compatible are found again by phandle, as T8140's already were (dt_set_aves(), formerly dt_set_t8140_aves()).
  • The M2's DART window base is read from the DART 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 CRCs in /chosen. An encoder whose preloaded copy differs from one already handed over is disabled instead of overwriting those CRCs.
  • DAPF: dapf_preload_text() admits encoder N's __TEXT through dart-ave. dart-ave0 stays in dapf_entries. After the DT is final, dt_set_ave_dapf() programs dart-ave for N >= 1 for each encoder the DT still enables. It disables the encoder if its filter fails.
  • Kept for T8140 only, with the hardware reason in the comment: an A18 Pro has one of two encoders and only the ADT says which, so its DT leaves both off and aura enables the one handed over, together with its DART and power chain. T8140's inherited DAPF state is untouched. The remap and DART-window selection by compatible is unchanged.

Testing

  • make is clean. kboot.c has no new warnings, and dapf.c loses one existing maybe-uninitialized warning.
  • New tests/python/test_ave_handoff.py has 18 scenarios: M1 Pro, M1 Max, M1 Ultra, M2, fail-closed cases, CRC conflicts and DAPF. test_t8140_ave_enable.py and test_ave_text_dapf.py are updated, and test_smp_handoff_gate.py gets a stub.
  • Full pytest tests/python: 700 passed. The same 8 tests fail before and after (test_run_guest_sptm, which depends on the environment).
  • Old and new handoff, run on all 137 kernel DTBs against an ADT modelled from each, in 4 ADT states each:
    • byte-identical on T6000, T6041, T8112, T8132, T8140 and T8142;
    • changes only on T6001, T6002 and T6050, the SoCs whose DTs describe more than one encoder.

Still to run

  • M1 Pro J316s and M2 J413, as one aura-try Stage 2 trial each: encoder 0 still handed over, apple-ave bound, one HEVC encode.
  • M1 Max and M1 Ultra: pending, needs a board owner.
Old gate
  • src/kboot.c dt_set_ave(): it returned after the first compatible with a node, and only apple,t8140-ave went to the all-nodes walk. dt_set_ave_node() picked ave or ave0 by name for every other SoC (0954fe3).
  • The address matcher and phandle walk were T8140-only (f57127a, Diljit Singh's T8140 handoff, generalized here).
  • src/dapf.c: dapf_preload_text() handled only /arm-io/dart-ave0 and /arm-io/ave0 (5933427).
Why each SoC is safe
  • Single-encoder DTs (T6000, T6040/T6041, T8112, T8132, T8142) have one node, so they take the unchanged lone-node path. The DT address of every encoder equals the address of the ADT node the old code picked by name. I checked this against live ADTs for M1 Pro, M2, M4, M4 Pro/Max, A18 Pro, M5 and M5 Pro/Max. The host harness confirms the DT edits are byte-identical.
  • T8140: two nodes, as before. Same matcher result, same phandle walk, same enable path, and DAPF is skipped. Byte-identical.
  • T6050 (M5 Pro/Max): its DTs describe ave1, disabled. ave1 is now also matched and its preload reserved if the ADT has one. It stays disabled in the DT and Linux does not bind it. The only change for ave0 is phandle numbering. dart-ave1 is not programmed because ave1 is disabled.
  • T6001/T6002: see the kernel change below.
Hardware rows for the lead
  • J316s (T6000) and J413 (T8112), with this aura in Stage 2:
    • aura log: no "FDT: AVE ... disabled" line;
    • /proc/device-tree/soc/video-codec@*/memory-region has 2 entries, and /proc/device-tree/chosen/aurora,ave-text-crc32 is unchanged from production;
    • dmesg | grep -i ave: apple-ave bound;
    • fleet HEVC row, gst-launch-1.0 videotestsrc num-buffers=300 ! video/x-raw,format=NV12,width=1920,height=1080 ! v4l2h265enc ! h265parse ! fakesink: rc=0, about 158 fps on J316s and about 124 fps on J413.
  • M1 Max/Ultra owners: aura log shows "AVE ... handed over from ADT /arm-io/ave1" (and ave2/ave3 on the Ultra), plus "dapf: Initialized /arm-io/dart-ave1". Both or all four encoders are bound, with one encode each.

Kernel side: aurora-silicon/linux #2295 enables encoders 1 to 3 on t6001/t6002 and fixes encoder 1's pmgr range. This PR should land first.

Assisted-by: LLM (Claude:Opus 5.5)

…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 Author

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

  1. src/kboot.c:4808 (dt_set_ave_dapf()): the new if (chip_id == T8140) return 0; is a SoC gate. Decide from the state the filter is in instead. For example, skip a dart-ave whose filter the previous stage already programmed (the inherited state dapf_init_fdt() keeps), or one the ADT does not list. If the gate really can't be avoided, give the hardware reason in the commit message, as the T8140 enable path already does.

Assisted-by: LLM (Claude:Opus 5.5)

@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Superseded by #420, which landed this encoder handoff together with #354, rebased on main.

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