Skip to content

media: apple: ave: encode on the M4 Pro and enable it in the J616s DT - #740

Closed
RyanTheTide wants to merge 8 commits into
aurora-wipfrom
ave/t6040-encode-2
Closed

RyanTheTide wants to merge 8 commits into
aurora-wipfrom
ave/t6040-encode-2

Conversation

@RyanTheTide

Copy link
Copy Markdown
Contributor

Enables the AVE H.264/HEVC encoder on the M4 Pro (J616s). Stacked on #739 (the 4 GiB window and buffer sizes); the first six commits here are #739's and drop out once it merges.

The M4 Pro boots Linux from a 26.6.2 (25G83) stub, so iBoot preloads the 25G83 AVE firmware built for its chip (TEXT 0x14c000, CRC 0x68d5f9f6). It is the same firmware build as the A18 Pro's and takes the same command layout. What differs is the chip identity: AVE device 27, device type 25. The coprocessor registers and start sequence match the A18 Pro.

Commits:

  • media: select the 9003.78.0 layout for CRC 0x68d5f9f6 and complete the T6041 match data (coprocessor registers, device ID and type, boot argument, timebase, VCBAR encoding, boot qualified). Other firmware builds, including macOS 27.0's, are still refused.
  • J616s DT: enable the six VENC power domains, both AVE DARTs with a 4 GiB window, and the encoder. The loader still disables the node if the firmware is not preloaded or cannot be reserved (aura#25, in aura main).

Testing

J616s results: pending the rerun on the rebased series (Stage 2 with this DTB, kernel tt3, module from this branch). They'll be added here before merge.

Earlier J616s run of the same driver and DT commits on the previous base (fleet12e, aura#25 Stage 2): 1080p H.264 99.5-100.0, HEVC 91.3-92.5; 4K H.264 27.0-29.6, HEVC 25.7-26.0; 2 sessions 50.7 + 50.3; 12-rep 4K fault hunt 24/24 clean, 0 DART faults; GStreamer v4l2h264enc 1080p 120/120 frames decoded by ffprobe.

Neo (J700) regression with this branch, tt3, 4 GiB DT trial, 3 reps: 1080p H.264 109.5-110.5, HEVC 100.6-100.7; 4K H.264 30.2, HEVC 28.7 (240/240); 2 sessions 55.0 + 54.9; 0 DART faults.

The aurora-wip t6040-j616s.dtb with this series differs from the current one in exactly the 11 AVE lines (6 power domains, 2 DARTs, 2 DMA windows, the encoder). W=1 AVE build 0 warnings; t6040-j616s.dtb and t8140-j700.dtb clean.

Both chips encode at about 43% (M4 Pro) and 62% (A18 Pro) of macOS on the same machine. Encoder performance votes are being worked on separately and are not part of this PR.

🤖 Generated with Claude Code

Every encoder buffer (session working buffers, both V4L2 queues and the
IPC area) is mapped through the two AVE DARTs, and the DMA layer aligns
each mapping to its power-of-two size. A 4K session needs about 180 MiB
of working buffers alone, which does not fit the 256 MiB window.

The ADT gives these DARTs a 0x100_0000_0000 + 0x300_0000_0000 VM range,
and macOS keeps every encoder address in 0x100_xxxx_xxxx. Widen the
window to 4 GiB above the firmware. Tested on the J700 at 1080p and
2560x1600 with no DART faults.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The 2560x1600 limit kept sessions inside the 256 MiB DMA window. With a
4 GiB window, allow up to 4096x2304, the largest size the encoder
accepts for real-time H.264 on these chips, so 3840x2160 and 4096x2160
work.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The 25G83 macOS driver gives Process commands a 46.4 second firmware
timeout. Open, Start, Complete, Stop and Close use 94.4 seconds, and
Config and Halt 3 seconds. The 9003.78.0 layout sent 94.4 seconds on
Process too. Use the macOS value.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The HEVC row buffer at Start +0x1350 holds one 0x180-byte neighbour
record per 64 pixels of picture width. The driver gave it a fixed 16 KiB,
which is what a 1920 wide picture needs. At 3840 and 4096 the firmware
needs 0x5a00 and 0x6000 bytes and wrote past the end: on the M4 Pro a 4K
HEVC session hit DART write faults at the next page and the firmware
stopped answering, and where the next page was mapped it silently
overwrote another buffer (HEVC 4K sessions lost a frame on both the
M4 Pro and the A18 Pro).

Size it as macOS does: 0x180 bytes per 64 pixels, at least 16 KiB,
rounded up to 16 KiB.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The H.264 per-frame buffer at Process +0x58c8 was cut to one page to fit
sessions in the old 256 MiB DMA window, on the grounds that no bit-rate
session on hardware wrote to it. macOS sizes it from the macroblock
count, 432 bytes per macroblock rounded up to 16 KiB (0x360000 at 1080p),
and tells the firmware that size. A firmware that does write it, in a
mode not yet exercised, would run past a single page. The window is now
4 GiB, so allocate the macOS size.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The OUTPUT and CAPTURE budgets (80 and 40 MiB) were sized for the old
256 MiB window. At 3840x2160 a raw frame maps as 16 MiB, so the OUTPUT
queue was held to six buffers, and GStreamer's v4l2h265enc failed to set
up its pool at 4K.

With a 4 GiB window, allow 256 MiB for OUTPUT (16 frames at 4K) and
128 MiB for CAPTURE.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
The M4 Pro boots Linux from a 26.6.2 (25G83) stub, so iBoot preloads the
25G83 build of the AVE firmware for its chip: TEXT 0x14c000, CRC
0x68d5f9f6. That is the build the A18 Pro runs (0x69c54454), compiled
for the M4 Pro, and its command parser takes the same Config, Open,
Start and Process layout. The macOS 25G83 driver builds identical
commands for both chips.

What differs is the chip identity. The M4 Pro is AVE device 27 with
device type 25 (the A18 Pro is 29 and 27). Its coprocessor uses the same
registers and start sequence as the A18 Pro.

Select the existing layout for this CRC, and give the T6041 match data
the coprocessor registers, device ID, device type, the A18 Pro boot
argument, timebase and VCBAR encoding, and the qualified boot flag.
Other firmware builds are still refused, the macOS 27.0 one included
(TEXT 0x154000), whose commands are laid out differently.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
Enable the AVE encoder on the J616s together with its two DARTs and the
six VENC power domains it sits in. The loader disables the node again
when the firmware is not preloaded or cannot be reserved.

Both AVE DARTs get a 4 GiB DMA window above the firmware at
0x100_0000_0000. The ADT gives these DARTs a 0x100_0000_0000 +
0x300_0000_0000 VM range, and macOS keeps every encoder address in
0x100_xxxx_xxxx. A 4K session needs about 180 MiB of encoder buffers
before its frame queues, so the 256 MiB the A18 Pro DT uses is not
enough.

Assisted-by: LLM
Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
@RyanTheTide

Copy link
Copy Markdown
Contributor Author

Replaced by #748, the same two commits rebased onto aurora-wip after #739 merged (no force push).

@RyanTheTide
RyanTheTide deleted the ave/t6040-encode-2 branch October 31, 2026 23:37
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