Skip to content

media: apple: isp / accel/ane: enable MLVNR on T8142 (J813) - #4466

Draft
sithglan wants to merge 14 commits into
mainfrom
feat/t8142-mlvnr
Draft

sithglan wants to merge 14 commits into
mainfrom
feat/t8142-mlvnr

Conversation

@sithglan

@sithglan sithglan commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

What: Stacked follow-up on #4445 (commits e22360f6fe0d..336dcaaa5435 on top of #4445 c9e775b7f51f) extending ISP↔ANE MLVNR to M5 (T8142: J813/J815/J704) on the H17 cold-boot ANE backend (ane_fw_cold), guarding against configuring MLVNR on 2×2 binned IMX958 1520x1440 presets, restoring full-resolution config 7 (3040x2880) sensor presets in t8142-j813-isp.dtsi with centred two-thirds-width crops inside the ultra-wide IMX958 lens circle (matching J714s, eliminating dark outer corners while keeping every preset >= 1920×1080), and lowering the IMX958 MLVNR thresholds from 3584/2816 to 200/100 so MLVNR stays active in indoor daylight as well as low light.

Tested: J813 M5 MacBook Air (aura 1.0.0b18-100-g99488019 Stage 1 → Stage 2 ESP_STAGE2=1, 7.3.0-aurora-j813-mlvnr+, apple/ispane-j813.afpp 12,951,616 bytes):

  • Live boot with cropped config-7 DTB + always-on MLVNR (200/100) active from boot (appledrm DCP + apple,ane-cold-boot = raw-no-xnu-ane-untouched-v1):
    • All 12 V4L2 NV12 sizes enumerated cleanly (1280x720, 1440x1080, 1080x1080, 1920x1080, 640x480, 1080x1920, 1760x1328, 1328x1760, 1552x1552, 1280x960, 960x1280, 2024x2024).
    • Centred 2/3 crop (<508 870 2024 1140> for 16:9) eliminated dark circular lens corners on live 1080p capture (50×50 corner luma mean: TL=130.1, TR=179.0, BL=198.7, BR=115.9 vs TL=29.1, TR=38.1, BL=15.8, BR=15.7 on full-width <0 584 3040 1710>).
    • Peer endpoint bring-up/teardown on ane_fw_cold (mcache 0x300000, SHAREDMALLOC surface map/unmap, clean H17 peer endpoint unset + ANE idle park/unpark, 0 DART/ANE/ISP/DCP faults).
    • Active 1080p 30 fps streaming with 200/100 thresholds: 29.96 fps, ANE IRQs +199 over 50 frames (~120 IRQs/s), measured system power delta (macsmc_hwmon Total System Power, ABA): 7.35 W / 7.94 W (mean 7.65 W) ON vs 6.98 W OFF (~0.65 W while streaming, 0 W once closed and ANE parks).
  • Live same-scene A/B (1280x720 NV12, 60 frames) on config 7 (3040x2880) and config 5 (1920x1080):
    • cfg 7 MLVNR ON: luma_std=1.071, chroma_std=0.227, ANE IRQs +229, Load Program 0.6–0.7 ms, 0 asserts (5/5 consecutive start/stop cycles clean).
    • cfg 7 MLVNR OFF: luma_std=4.113, chroma_std=1.053, ANE IRQs +0.
    • cfg 5 MLVNR ON: luma_std=1.674, chroma_std=0.341, ANE IRQs +150, 0 asserts vs OFF luma_std=3.285, chroma_std=0.957.
    • cfg 8 (1520x1440 binned) OFF: luma_std=1.694, chroma_std=0.533.
  • Confirmed on live hardware that enabling MLVNR on 1520x1440 (config 8) hits NetInputCheck, 1046: wrong input buffer size: actual: 3072, 1440 → ASSERT: CMLVNRProcImp.cpp:1046 once gain crosses enter_gain, and that #4445's forced-stop restart cleanly recovers the camera and turns off the indicator light.
  • Local verification at 336dcaaa5435: make W=1 clean on drivers/accel/ane/, drivers/media/platform/apple/isp/, and all three T8142 DTBs (t8142-j813.dtb, t8142-j815.dtb, t8142-j704.dtb); KUnit (arm64 QEMU): apple-isp 67/67 PASS (including isp_test_mlvnr_binned_disabled), accel/ane (transport.kunitconfig) 343/343 PASS; checkpatch --strict 0 errors, 0 warnings, 0 checks across all 4 commits.

Risk: two-way — T8142-only platform data + shared t8142-j813-isp.dtsi (J813, J815, J704; all three DTBs compile cleanly, hardware verified on J813, boards without ispane-<board>.afpp still stream on config 7 without the ANE endpoint), an additive IMX958 1520x1440 MLVNR disable guard in isp-cam.c, and lowering the IMX958 threshold from 3584/2816 to 200/100 (~0.65 W extra power while streaming, 0 W idle).

Not yet: Rebase onto main after #4445 merges and collect live J815/J704 confirmation (or confirm ispane-j815.afpp / ispane-j704.afpp once aurora-silicon/aurora-installer#355 lands).

jgoyvaerts and others added 11 commits December 5, 2026 04:12
With the ISP's endpoint set, the H16 firmware asks the host to map the
ISP's surfaces into its domain by the ID the ISP firmware got for each
of them: a SHAREDMALLOC request with zero DVA and size, and the ID in
the third word. The host answers with the DVA (bit 0 set), the size and
the ID. The firmware gives a surface back with an ordinary FREE of its
DVA, answered 1, 0, 0.

Add optional peer_map and peer_unmap transport ops for that. A FREE of
a DVA the peer does not know stays an ordinary FREE.

The request and answer shapes come from a written summary of a
hypervisor trace of macOS 27.0 starting the camera on a J616s.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
On the J616s the ISP firmware runs its ML video noise reduction (MLVNR)
on the ANE. When the camera starts, macOS gives the ANE firmware the
ISP's endpoint with these IO commands, each answered in place:

  MCACHE_SIZE_GET (0x0026)     the firmware answers the mcache size it
                               wants (0x300000)
  MCACHE_DSID_SET (0x002e)     a count of 2, then (3, 0) for the
                               prefetch and (4, 0xe) for the
                               intermediate spill of the networks
  LOAD_AFPP (0x0205)           the ISP's networks, one buffer
  IPC_ENDPOINT_SET2 (0x002a)   endpoint index, the ring the engine
                               reads, the ring it writes, the ISP's
                               doorbell and its value

and when it stops, IPC_ENDPOINT_UNSET2 (0x002b), after which the
firmware asks to unmap the ISP's surfaces, then UNLOAD_AFPP (0x0206).

Add the commands and the session calls for them. Gating stays off while
an endpoint is set, since the ISP hands the firmware work on its own.
The firmware is served outside any request, as the ISP's work runs while
no host request waits: SHAREDMALLOC for the ISP's surfaces, and its
reports on IO_T2H, each of which holds one of its command slots until
read. A failed command logs its ID and prints the firmware's log before
the recovery boots it again.

The command names are from macOS's ANE driver log (27.2.1, request and
teardown lines), the layouts from written summaries of hypervisor traces
of macOS 27.0 starting the camera on a J616s. Three facts are from runs
on the J616s, through the firmware's own log: the networks must be
loaded before SET2 (it asserts "AFPPLoaded" otherwise), the spill DSID
must be set (it asserts "afppInterSpillDsid != (0xFF)" on the first
frame otherwise), and its reports must be read while the ISP runs (it
asserts "out of command cache" within seconds otherwise). The ring
order is from the same runs: with the ring the engine writes first, the
firmware takes the ISP's doorbell but never reads its ring.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Add <linux/soc/apple/ane.h> for the ISP driver: it finds the engine by
its apple,ane phandle and attaches its two rings, its doorbell and its
networks file. The engine then stays up (a runtime PM reference), the
rings and the networks are mapped, the endpoint is set up with the
spill DSID from the platform data, and the engine's doorbell for the
ISP goes back to the ISP: engine window + 0x1660000, value 1 on the
J616s, as macOS gives them to the ISP firmware there.

The firmware's map requests and reports come while nothing waits, so
with a peer attached the channel IRQ queues a work item that serves
them. Peer surfaces come from the program window and are unmapped when
the firmware frees them or the peer detaches, which also unmaps the
rings and the networks. A device link orders system sleep: the ISP
suspends first.

The doorbells and the spill DSID are those macOS uses on the J616s
(its camera and ANE driver logs, and a written summary of a hypervisor
trace of macOS 27.0 there).

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
The ISP firmware runs its ML noise reduction on the Neural Engine; the
ADT links the two (isp0's function-ane_ep_control, -data_param_set and
-data_param_get point at ane0). Describe that link.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
A crashed firmware is forced off: the stop command times out ("coproc
not in WFI"), so the firmware never sends the camera module its
power-down. The sensor stays powered, and its green status light stays
on until the next camera use. Seen on J815 (2026-11-21) after an ISP
firmware assert.

On hardware whose firmware starts again (hw->fw_restart), a halt after
an IPC error now schedules fw_recover_work. It boots the firmware once
more and stops it the normal way, which
powers the module down. It runs once: a second crash is left as it is.
On J815 the light went off after the crash, and the log said "crashed
firmware: restarted and stopped it to power the camera down".

Signed-off-by: Nick <nekreshen@yandex.ru>
(cherry picked from commit 69dc771)
The ISP firmware runs MLVNR, its ML video noise reduction, on the
Neural Engine. When the camera starts, macOS loads the camera's
networks into the ANE, gives the ANE firmware the ISP's two 16 KiB rings
and the ISP's doorbell, and then gives the ISP firmware the same rings
and the ANE's doorbell (CISP_CMD_IPC_ENDPOINT_SET2). Without it the ISP
firmware's ANE client is never set up, and MLVNR asserts in its
allocator.

Do the same after START when the device tree links the ISP to an ANE
that is up (apple,ane) and the networks are installed:
apple/ispane-<board>.afpp, macOS's /System/Library/Isp/afpp/<board>/
ispane.afpp from the Mac's own install, read once. On T604x the ANE may
write the ISP's doorbell (t604x.dtsi). Without the file, the link or the
ANE, one line says so and the camera runs as before.

- The ANE firmware names the ISP's surfaces by the ID the ISP firmware
  got for each at SHAREDMALLOC, which macOS hands out there; hand out
  IDs too. A surface the ANE still maps is freed only once it lets go.
- Before the firmware stops, it unsets the endpoint, and the ANE
  detaches while the ISP is still powered: until then the ANE firmware
  may ring the ISP's doorbell, and an access to the powered-down block
  would hang the fabric.
- The camera must work without MLVNR: a stream that fails to start with
  an endpoint no stream has used yet, or a firmware that has to be
  stopped by force with the endpoint attached, ends the endpoint until
  the driver loads again.

The sequence and the values are from macOS's camera and ANE driver logs
on the J616s (27.2.1) and the ISP firmware's own log of the commands it
receives, on macOS and on Linux.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
The restart that powers the camera module down after a crash only ran
when an IPC error was set at the halt. A firmware that hangs without
one is forced off too: on J616s, with the ISP firmware's ANE client
stalled, the stop command timed out ("IO: failed to send OPCODE
0x0101", "firmware did not stop, stopping the coprocessor") and the
camera light stayed on until the next camera use. No IPC error was
set, so no restart followed.

Schedule the restart whenever the stop was forced. That covers the IPC
error case too: a firmware with an IPC error takes no stop command, so
its stop is always forced.

The restart work was cancelled before the last halt in remove, the
failed probe and shutdown, and before the halt in
apple_isp_firmware_flush(): a forced stop there left it queued, to
boot firmware on a removed device. Cancel it after those halts.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
macOS configures MLVNR on the J616s before each stream with
APPLE_CH_MLVNR_MODE_CONFIG_SET (0xc11f): automatic (2), entering at a
total gain of 3584 and leaving below 2816, at 30 fps either way, fading
out over 30 frames. The ISP firmware logs these words under those names
when it receives them.

Send the same when the ANE endpoint is set, with the thresholds per
sensor (the IMX958), whichever setfile is loaded.

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
The ISP firmware runs MLVNR on the Neural Engine (ADT isp0's
function-ane_ep_control, -data_param_set and -data_param_get point at
ane0). The ANE's address filter already lets it ring the ISP's doorbell
(0x581668000), and the ISP's the ANE's (0x485660000).

Signed-off-by: Jonathan Goyvaerts <jonathan.goyvaerts@gmail.com>
Extend the H17 cold-boot ANE backend (ane_fw_cold) with the same ISP
peer endpoint support that ane_h16_backend provides for T604x:

- Implement ane_fw_cold_peer_find(), ane_fw_cold_peer_attach(), and
  ane_fw_cold_peer_detach(), mapping the ISP's rings, AFPP networks,
  and SHAREDMALLOC peer surfaces into the ANE DART window and draining
  IO_T2H reports via peer_work while attached.
- Dispatch apple_ane_get()/put()/peer_attach()/peer_detach() across
  both ane_h16_backend and ane_fw_cold.
- Populate T8142 platform data (irq_role = ANE_FW_IRQ_CHANNELS,
  peer_doorbell = 0x1660000 from J813 ADT dart-isp dapf-instance-0
  0x421660000..0x421660003, peer_doorbell_value = 0x1,
  peer_spill_dsid = 0xe).

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Wire the T8142 ISP-side peer doorbell (0x4a1668000, value 0x10,
matching J813 ADT dart-ane dapf-instance-0 0x4a1668000..0x4a1668003)
into apple_isp_hw_t8142.

On J813, the IMX958 ispane-j813.afpp archive contains 11 compiled MLVNR
networks covering full-resolution sensor modes (including 3040x2880 and
1920x1080) and none for the 2x2 binned 1520x1440 mode. Configuring
MLVNR on a 1520x1440 preset triggers a NetInputCheck firmware assert
(actual: 3072, 1440; CMLVNRProcImp.cpp:1046) as soon as gain crosses
enter_gain. Explicitly disable MLVNR (mode 0) when streaming IMX958 at
1520x1440 and add a KUnit test covering the guard.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
…ig 7

Link the J813 ISP node to the H17 ANE (apple,ane = <&ane>) and restore
the full-resolution config 7 (3040x2880) sensor presets so the ISP
firmware can run MLVNR on the ANE, with centred two-thirds-width crops
inside the ultra-wide IMX958 lens's illuminated circle (matching J714s
and avoiding dark outer corners while keeping every preset >= 1920x1080).

J813 previously switched from config 7 to 2x2 binned config 8
(1520x1440) to reduce indoor noise without MLVNR, but ispane-j813.afpp
has no network for 1520x1440. With MLVNR active on config 7, J813
achieves lower luma and chroma temporal noise than binned config 8
(1.07 vs 1.69 luma std, 0.23 vs 0.53 chroma std) while keeping full
3040x2880 sensor resolution.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
Lower the IMX958 MLVNR enter/exit gain thresholds from 3584/2816 (14x/11x
gain) to 200/100 (below 256 = 1x unity gain) so MLVNR runs in indoor
daylight as well as low light.

On J813 config 7 (3040x2880), normal indoor lighting stays below 3584,
leaving unbinned frames visibly grainier (luma_std 4.11, chroma_std 1.05)
than binned config 8 (1.69 / 0.53). Keeping MLVNR active reduces noise to
luma_std 1.07 / chroma_std 0.23 across all lighting at a measured system
power cost of ~0.65 W while streaming (7.65 W vs 6.98 W on macsmc_hwmon
Total System Power; 0 W once closed and the ANE parks).

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>
@m0d16l14n1

m0d16l14n1 commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

@sithglan, J815 notes for this stack. They come from our own J815 ISP↔ANE driver (same T8142 H17 cold-boot ANE), not from your head. I can't boot your head on the J815 today, and I'll post a Tested row for it when I can.

J815 data (our driver, 7.3 nightly):

  • ispane-j815.afpp is 12,951,616 bytes, the same size as your j813 file.
  • The doorbells match your platform data: ISP 0x4a1668000/0x10, ANE 0x421660000/1. The mcache size is 0x300000.
  • Open/close today at 3584/2816 (auto mode): the link came up on the first stream, 33 ISP surfaces mapped, 33 freed, 0 refused, peak 252 MiB in the ANE window, 0 DART errors. The ANE parked 3 s after close.
  • Earlier runs with MLVNR forced on (thresholds 256/256): 966 ANE programs (~2 per frame) in one stream with 0 stalls, and a 300 s soak with 15,070 firmware requests served and 0 stalls.
  • On the J815, MLVNR runs on config 6 (3040x2880, the SIFR mode). We haven't run config 7 with MLVNR.

In the ane_fw_cold peer path, from reading the code. None of this is reproduced on your head:

  1. System sleep while streaming. ane_fw_pm_event() cycles the engine at PM_SUSPEND_PREPARE, before any device suspends. The device link only orders the device callbacks, so between that point and the ISP's .suspend, the ISP firmware keeps handing MLVNR work to an engine that is off. After that, ane_fw_cold_peer_detach() finds the session asleep, so the UNSET is skipped (fine). But ane_fw_peer_unmap_all() still calls iommu_unmap() on the ANE DARTs while they may be off. On our stack, a detach with the engine off keeps the stale ring and surface mappings and drops them at the next attach. Could you add a row for systemctl suspend with the camera streaming, then resume with the stream restarting?
  2. ANE recovery under a live endpoint. ane_h16_session_restart() clears s->peer, but peer_on and the ISP side are left as they were. The new firmware never gets SET2 while the ISP firmware keeps using the rings, so this ends in the ISP's forced stop, and MLVNR stays off until the module reloads. Our stack counts ANE firmware boots, and the ISP checks the count before each stream, so the next stream sets the endpoint up again.
  3. When the mcache set-up is sent. On our J815 stack, sending MCACHE_SIZE_GET + the spill DSID at link time, after another ANE client had already created a process on the woken engine, left the DSID command unanswered and quarantined the session. Sending them once at each ANE firmware start, before any process exists, fixed it: 0 quarantines in a 300 s soak with both clients. To reproduce on your head: start any ANE client that creates a process, then open the camera.
  4. Thresholds. { 0x958, 200, 100 } is keyed by sensor, so it also moves J616s off media: apple: isp: run MLVNR noise reduction on the ANE for T604x #4445's values. Writable module parameters (we use mlvnr_gain_enter/mlvnr_gain_exit, defaults 3584/2816) would let J813/J815 run always-on without changing the default.
  5. Without the afpp. Until Collect the camera's ANE networks (ispane.afpp) for T604x MLVNR aurora-installer#355 lands, most J813/J815 installs have no ispane-<board>.afpp, so they would now stream config 7 without MLVNR. Your own numbers make that the noisiest of the three cases (luma_std 4.11, against 1.69 for binned config 8). A suggestion: keep the binned presets as the default and let the DT name the sensor config that MLVNR switches to. Our driver uses apple,mlvnr-sensor-config = <8 6> on the J815; it switches with the mlvnr module parameter, which our setup only sets once the afpp is installed. Switching when the endpoint actually comes up would be better still. Either way, the DT, not a 1520x1440 check in the driver, decides which presets MLVNR gets.

Would you rather fold 1, 3 and 5 into this PR, or have me send them as patches on top once I've run them on the J815?

Document the optional apple,ane phandle property on T8140/T8142 ISP nodes
so CHECK_DTBS passes for t8142 boards linking the ISP to the ANE for
MLVNR, matching Documentation/devicetree/bindings/media/apple,isp.yaml.

Signed-off-by: Thomas Glanzmann <thomas@glanzmann.de>

This branch has not been deployed

No deployments
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.

3 participants