Skip to content

media: apple: ave-dma: bind every SoC's apertures and let the domain idle - #3871

Merged
RyanTheTide merged 3 commits into
mainfrom
fix/ave-dma-t8103-runtime-pm
Dec 2, 2026
Merged

RyanTheTide merged 3 commits into
mainfrom
fix/ave-dma-t8103-runtime-pm

Conversation

@RyanTheTide

@RyanTheTide RyanTheTide commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

What: Fix the root cause of the J313 (M1, T8103) deep-sleep wake regression from #3551. ewb's split showed &ave_dma alone causes it: disabling only that node passes S2R. apple-ave-dma matched only apple,t6000-ave-dma, so the T8103 node (apple,t8103-ave-dma, apple,ave-dma) never bound. PMGR sync_state() then stayed pending and held ps_venc_sys on permanently. This PR matches the generic apple,ave-dma that every node carries and enables runtime PM without ever resuming the device. The apertures only report faults, through the interrupt they share with the encoder DARTs, so only the encoder and its DARTs decide when ps_venc_sys is on. The same change also lets ps_venc_sys power off on T6000/T6001/T6002, where the driver bound with no runtime PM and so held the domain on. That was the "power cycle the firmware needs between sessions" that d8e9754 worked around by disabling the node. The DT nodes stay enabled.

Tested: J313 M1 Air (T8103) at e5dd49e7 (ewb, unmodified main DTB): 2/2 S2R pass (boot object resumes 0 -> 1 -> 2), apple-ave-dma bound runtime-suspended, venc_sys off-0 idle, rmmod/modprobe clean. Head 6e5f9224 adds the IRQ power guard (genpd notifier + raw spinlock shared with PRE_OFF, so threaded handlers are covered too): arm64 W=1 build with CONFIG_DEBUG_SHIRQ=y clean, checkpatch --strict clean. J313 row at 6e5f9224: requested.

Risk: two-way · M1 (J313, J293, J274, J456, J457) and M1 Pro/Max/Ultra (T6000/T6001/T6002). This only changes when ps_venc_sys can power off: it binds one fault-reporting driver and lets its domain idle. Reverts in one commit.

Not yet: J313 row at 6e5f9224 (S2R + rmmod/modprobe with DEBUG_SHIRQ + one encode session) (ewb). T600x encoder row (any M1 Pro/Max).

…idle

The auxiliary DMA aperture driver matched only apple,t6000-ave-dma, so
the T8103 node that linux #3551 enabled stayed unbound. Its PMGR
sync_state() then stayed pending and held ps_venc_sys on for good, and
J313 deep sleep stopped waking. On T6000 the driver binds but has no
runtime PM, so genpd counts the device as active and ps_venc_sys never
goes off there either. The encoder firmware needs that domain
power-cycled between sessions.

Match the generic apple,ave-dma compatible that every node carries, and
enable runtime PM without ever resuming the device. The apertures only
report faults through the interrupt they share with the encoder DARTs,
which can only fire while the domain is on, so the encoder and its DARTs
alone decide when ps_venc_sys is powered. The DT nodes stay enabled.

Signed-off-by: Ryan Murray <ryan@aurorasilicon.org>
erikwb
erikwb previously approved these changes Dec 2, 2026

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

Verdict: MERGE at e5dd49e7ab07
Blockers: none
Checked: no Apple material, no chip/board/firmware gates (matches generic apple,ave-dma), J313 M1 Air (T8103) hardware row at e5dd49e7ab07, CI green (apple-build, KUnit ave, host-tests passing; pr-text/readiness queued)

Evidence

Tested on J313 (M1 MacBook Air, T8103) at e5dd49e7ab07 with the unmodified t8103-j313.dtb (ave_dma enabled, CONFIG_VIDEO_APPLE_AVE=m):

  • Clean boot, 0 failed systemd units, boot_id unchanged (6e135ce4-e83c-4984-911a-c731f6ffcac9).
  • 267020000.dma bound to apple-ave-dma with power/runtime_status = suspended and venc_sys at off-0 in pm_genpd_summary.
  • rtcwake -d /dev/rtc1 -m mem -s 10: 2/2 PASS (CYCLE=1 RC=0 ELAPSED=11s, boot object resumes 0 -> 1; CYCLE=2 RC=0 ELAPSED=14s, boot object resumes 1 -> 2), 0 errors/warnings.
  • rmmod apple_ave_dma && modprobe apple_ave_dma: rebinds cleanly with runtime_status = suspended and venc_sys staying off-0.

Non-blocking follow-up note: apple_ave_dma_irq() (drivers/media/platform/apple/ave/apple-ave-dma.c:28) unconditionally reads dma->base + AVE_DMA_ERROR_STATUS on IRQF_SHARED (shared with ave_dart1). Under CONFIG_DEBUG_SHIRQ=y (e.g. free_irq() on module unload while ps_venc_sys is off) or a spurious shared IRQ when idle, that read would hit a powered-off block; worth guarding in a follow-up if DEBUG_SHIRQ testing is needed.

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

Verdict Request changes at e5dd49e7ab07.

drivers/media/platform/apple/ave/apple-ave-dma.c:30 needs a power-safe shared IRQ path. The J313 row confirms venc_sys can be off while this handler is installed. aurora_defconfig enables CONFIG_DEBUG_SHIRQ, and kernel/irq/manage.c invokes the shared handler during IRQ teardown even when the hardware did not signal an interrupt. The handler immediately reads the powered-off aperture in that path.

Please keep fault handling working during encoder activity and ensure the handler can return before MMIO when the aperture is off or IRQ teardown has started. The DMA device stays logically suspended even during real encoder activity, so its runtime-PM status alone cannot distinguish those cases. The generic compatible matches the affected DT nodes, and the exact-head J313 deep-sleep result covers the intended idle behavior.

With the device kept runtime-suspended, ps_venc_sys can be off while
the shared interrupt handler is installed. A sharer's or a spurious
interrupt, or the extra call CONFIG_DEBUG_SHIRQ makes in free_irq(),
would then read a powered-off block. The device's own runtime-PM
status cannot tell an idle encoder from a running one, since it stays
suspended either way.

Track the domain through its genpd on/off notifications instead,
registered while runtime PM is still disabled and the domain is known
to be on, and wait out a handler already past the check before the
domain goes off. Stop reading before free_irq() too. Fault reports
still come through while the encoder powers the domain.

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

Copy link
Copy Markdown
Contributor Author

Addressed at f1d42e29 (new commit on top, no force push). The handler now returns IRQ_NONE before any MMIO unless ps_venc_sys is on and teardown has not started:

  • powered follows the domain's own genpd notifications through dev_pm_genpd_add_notifier(): GENPD_NOTIFY_ON sets it, and GENPD_NOTIFY_PRE_OFF clears it, then calls synchronize_hardirq() so a handler already past the check on another CPU finishes before the domain goes off. The notifier is registered while runtime PM is still disabled, so genpd counts the device as active and the domain is known to be on when powered starts out true. This tracks real encoder activity even though the DMA device itself stays suspended.
  • stopping is set by a devm action registered after devm_request_irq(), so it runs before free_irq() and its CONFIG_DEBUG_SHIRQ call.

Build: arm64 W=1 with CONFIG_DEBUG_SHIRQ=y clean; checkpatch --strict clean. This also covers #3875.

@erikwb, could you repeat the J313 row at f1d42e29? Please run 2x rtcwake -m mem, then rmmod apple_ave_dma && modprobe apple_ave_dma (aurora_defconfig has DEBUG_SHIRQ) while venc_sys is off, plus one encode session if you can.

DjDeveloperr
DjDeveloperr previously approved these changes Dec 2, 2026

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

Rechecked f1d42e2 against the shared-IRQ finding. The handler now skips MMIO after PRE_OFF, and the notifier drains hard handlers before genpd powers the domain down. The genpd core sends ON again if power-off fails. The last devres action sets stopping before free_irq invokes the DEBUG_SHIRQ probe. Fault reporting remains active when the powered encoder uses the shared line. This addresses my code review. Landing still needs the refreshed J313 idle/unload/encode/wake row, one T600x encoder control, and relevant CI.

@RyanTheTide RyanTheTide left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The teardown guard covers DEBUG_SHIRQ. On arm64 with threadirqs, irq_setup_forced_threading moves this IRQF_SHARED handler into thread_fn. If that thread passes the powered check and is preempted before readl, PRE_OFF clears powered and synchronize_hardirq returns false with the thread still active. The callback ignores that result and the domain can power off before the thread resumes into readl. I reproduced the interleaving with the two exact driver functions and a stubbed IRQ core (one MMIO read after off). Please make the powered check and MMIO mutually exclusive with PRE_OFF in the threaded case too.

synchronize_hardirq() only waits for hard interrupt handlers. Under
threadirqs the shared handler runs in a thread, which can be preempted
after its powered check and resume into a read once ps_venc_sys is
off.

Hold a raw spinlock in the handler from the check through its last
register access, and take it in the PRE_OFF/ON notification and the
teardown action, so neither can pass a reader in either case. The
registers are copied under the lock and the fault is printed after.

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

Copy link
Copy Markdown
Contributor Author

Fixed the threadirqs interleaving at 6e5f92248d5a. synchronize_hardirq() is gone. The handler now holds a raw_spinlock_t from its stopping/powered check through its last register access (the reads, the write-one-to-clear and the read-back). The PRE_OFF/ON notification and the teardown action take the same lock to change the flags, so whether the handler is a hard IRQ or a forced thread, PRE_OFF cannot return while a reader is inside, and a reader that starts later sees powered == false. The lock is raw because the notification arrives under the irq-safe PMGR domain's lock. The registers are copied under the lock and dev_err_ratelimited() runs after unlock.

Build: arm64 W=1 with CONFIG_DEBUG_SHIRQ=y clean; checkpatch --strict clean.

@erikwb, the J313 row is now wanted at 6e5f92248d5a instead of f1d42e29, with the same steps: 2x rtcwake -m mem, then rmmod/modprobe apple_ave_dma while venc_sys is off, plus an encode session if you can.

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

Rechecked the threadirqs follow-up at 6e5f922. The raw lock now serializes the complete MMIO transaction with PRE_OFF and teardown for both hard and threaded handlers. No regulator or domain transition runs under the handler lock. The log runs after unlock, and genpd ON rolls the flag back on a failed power-off. This addresses the remaining code finding. The exact-head J313 wake/unload/encode and T600x encode controls are still in flight.

@RyanTheTide
RyanTheTide merged commit 13c7f69 into main Dec 2, 2026
9 of 14 checks passed
@RyanTheTide
RyanTheTide deleted the fix/ave-dma-t8103-runtime-pm branch December 2, 2026 06:27
@malik-na

malik-na commented Dec 2, 2026

Copy link
Copy Markdown
Member

J313 (M1 Air) on aurora-silicon/linux main 5a870d0 (with #3870 and #3871)

  • Board: J313, macOS 27.2 stub. Stage 1 1.0.0b17, Stage 2 1.0.0b17-gf5ddfff2, U-Boot 2026.07-g84382f65f672
  • Kernel: 7.3.0-lab5a870d0f-1945 (lab build b1202-193351-961e, the Air's config, CONFIG_APPLE_SEP=m)
  • One boot, lab job j1202-193932-eb87

Deep (rtcwake -d /dev/rtc1 -m mem -s 90): PASS

  • rtcwake rc 0 after 92 s, "Timekeeping suspended for 91.281 seconds", suspend_stats success 1 -> 2, no reset
  • wake IRQ 63 (apple_spmi hwirq 2), "wake source: NUB.SPMI0Sw3IRQ", "boot object resumes 0 -> 1"
  • Wi-Fi and BT logged "Unable to change power state from D3hot to D0" at resume, then recovered on their own (brcmfmac "L1.2 off on the link set up again", hci_bcm4377 hardware reset recovery). 20 s later wlan0 was up with its address and hci0 was powered.

s2idle, run after deep (rtcwake -m mem -s 30): PASS

  • rtcwake rc 0 after 32 s, success 2 -> 3, wake IRQ 63, no reset

Before sleep: no "sync_state() pending" lines. apple_sep loads by itself on main and was bound at 4.4 s.

ave-dma: apple_ave_dma was not loaded at boot. rmmod rc 1 (not loaded), modprobe rc 0, but no device bound and no ave-dma lines in dmesg. This DT seems to have no enabled ave-dma node, so the rebind with venc_sys off couldn't be checked here.

New warnings vs the known-good kernel: "PS fpwm1: Failed to reach power state 0xf" (after pm_test and after each wake), apple-dcp "AFK[ep:20]: failed to extract init props: -2", one drm in-fence not signalled after 1000 ms, and apple_sep identity-keybag provisioning failed.

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.

media: apple: ave-dma: guard the shared IRQ handler's register read when ps_venc_sys is off

4 participants