Skip to content

media: apple: ave: H.264 encoding on the M1 Pro and M2 - #1550

Merged
RyanTheTide merged 4 commits into
integration/aurorafrom
averef/ave-enable-t6000-t8112
Nov 11, 2026
Merged

RyanTheTide merged 4 commits into
integration/aurorafrom
averef/ave-enable-t6000-t8112

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Nov 11, 2026 •

Copy link
Copy Markdown
Contributor

Turns on hardware H.264 encoding for M1 Pro (T6000) and M2 (T8112) users. Both chips run the 6070 encoder firmware. The driver's encode path was already merged (#1440, #1484), but the encoder was still disabled in the device trees, and three driver problems showed up as soon as it ran outside lab boots.

  • Unanswered restart. Every few dozen firmware restarts on the 6070, the core reaches RUN and never posts its hello. The boot error path marked the firmware broken, and runtime suspend never powers down a broken 6070 firmware, so encoding stayed dead until reboot. The core is now stopped, and once CTRL reads back zero it is handled like a confirmed Halt: the attach cycles VENC power and boots it again.
  • Memory leak. Each closed session's buffers go into a quarantine, which only the 9003 restart path ever freed. On the 6070 every session kept its DMA memory, and an 8 GB M2 ran out of memory and stopped after about a hundred short encodes. The 6070 restart path now frees the quarantine after the confirmed Halt and the power cycle.
  • Default rate control. The bitrate-mode control defaulted to VBR, which the 6070 path refuses, so GStreamer and FFmpeg failed with their default settings. On the 6070 the menu now offers constant quality only, and that is the default.
  • DT. Enable the encoder and both of its DARTs on T6000 and T8112. This needs the bootloader handoff from AVE on the M1 Pro and M2: hand over the preloaded encoder firmware aura#161 (merged as 2af438d2). With an older bootloader the driver finds the firmware outside its DART window and does not probe.

HEVC stays refused on the 6070 for now. The parameter sets are fixed on a separate branch, but the slice headers still do not decode.

Tests

  • KUnit (apple-ave, arm64 QEMU): 42/42.
  • M2 (aura#161 image + these DTBs, fleet62 kernel with this driver), restart stress of short 1080p sessions with gaps around the 2 s autosuspend:
    • before: session 14 hit the unanswered start, and every later session failed until reboot (13/80 OK);
    • with the recovery alone: the M2 ran out of memory after about 100 sessions;
    • with this series: 120/120 sessions OK, 5 unanswered starts all recovered, MemAvailable 5680 → 5507 MiB, 512 MiB userspace canary unchanged, 0 DART faults, 0 SELinux denials.
  • M2 encode rows: H.264 1080p 300/300 at 157 fps (Y 38.18 dB vs. software decode), 4K 120/120 at 40.9 fps (Y 38.33 dB), Main and High with B pictures 1080p at 150-152 fps, High-B 4K at 39.9 fps, 0 decode errors.
  • Qualification with exactly this branch (module built for the fleet62 kernel, aura#161, these DTBs):
    • M2: 150/150 stress sessions (10 unanswered starts, all recovered), MemAvailable 5707 → 5653 MiB, the rows above unchanged, 20 consecutive 1080p encodes bit-identical, canary unchanged, 0 DART faults, 0 SELinux denials.
    • M1 Pro: 150/150 stress sessions (16 unanswered starts, all recovered), MemAvailable 13184 → 12953 MiB, H.264 1080p at 113-201 fps (Y 38.19 dB), High with B pictures 4K at 50 fps, 20 consecutive encodes bit-identical, canary unchanged, 0 DART faults, 0 SELinux denials.
    • Both: gst-launch-1.0 ... ! v4l2h264enc ! h264parse ! mp4mux with no extra controls and ffmpeg -c:v h264_v4l2m2m produce 300/300 frames; hevc_v4l2m2m gets EOPNOTSUPP as intended.
  • M1 Pro with the older aura (bd9f3e82) and these DTBs: the driver refuses the firmware ("firmware must start its DART window"). The VENC power domains then wait on the encoder for sync_state, so the kernel should not reach a Mac before its bootloader carries aura#161.

🤖 Generated with Claude Code

…ycle

A 6070 restart (M1 Pro, M2) now and then reaches RUN without the
firmware posting its hello: on the M2 a stress run of short sessions hit
it on the 14th restart, right after a gap that matched the 2 s
autosuspend. The boot error path then marked the firmware broken, and
runtime suspend refuses to power down a broken 6070 firmware, so every
later session failed until reboot.

Such a firmware has no rings, no session and no command in flight. Stop
the core, and once CTRL reads back zero treat it like a confirmed Halt:
return -EAGAIN so the session attach cycles the VENC power and boots it
again from reset. If the core does not stop, keep the old behaviour.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
The 6070 path refuses every rate-control mode but constant quality, yet
the bitrate-mode control still defaulted to VBR. A client that keeps
the defaults, such as GStreamer's v4l2h264enc without extra-controls or
FFmpeg's h264_v4l2m2m, therefore got EOPNOTSUPP at stream start. On the
6070 register the menu with constant quality as its only and default
entry.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Every session the firmware saw is quarantined with its buffers when it
closes, and is meant to be freed once the coprocessor provably went
through reset. Only the 9003 restart path ever reaped the quarantine, so
on the 6070 (M1 Pro, M2) each session kept its DMA buffers until the
module was removed. On an 8 GB M2 a run of short 1080p sessions used up
the memory after about a hundred encodes and the machine stopped.

Reap in the 6070 restart path: the firmware confirmed its Halt through
scratch0, the core read back stopped, and runtime PM cycled the VENC
power before the state left HALTED.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Enable the AVE encoder and its two DARTs on the M1 Pro (T6000) and the
M2 (T8112). The bootloader hands over the firmware iBoot preloads, at
the start of the encoder's DART window, and admits the preloaded code
in the M1 Pro's CPU DART filter. With an older bootloader the driver
finds the firmware outside its window and refuses to probe, so the
encoder stays off.

Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
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