Repository navigation
ASoC: apple: aop-spkr: keep speaker TX DMA fed via driver-owned ring - #3474
AxxzyWasTaken wants to merge 1 commit into
Conversation
The AOP `spkr` firmware service (MCA cluster 0, base-ns ADMAC1 TX0/RX0)
crashes with RTKit global IRQ status 0x1 whenever the serializer sits in
`pwrd` while host playback DMA (TX0) is stopped or starved. Previously,
driving the `j616-pcm-1` playback front-end directly with
`snd_dmaengine_pcm` left four windows where `spkr` stayed in `pwrd`
without TX0 running:
1. Playback STOP / DROP / XRUN / speakerguard lease withdrawal until
`be_hw_free` muted all six SN012776 amps (~60 ms) and sent `pw1`.
2. System suspend between `TRIGGER_STOP`/`TRIGGER_SUSPEND` and
`spkr_suspend`.
3. `be_prepare` (`pwrd`) until `TRIGGER_START` (including `-EPERM` lease
waits in macaudio).
4. `spkr_resume` (`pwrd`) until userspace prepared and started again.
In addition, because stopping TX0 on `STOP` broke slot alignment with the
running serializer, `Service::run()` unconditionally muted all six amps
sequentially (~60 ms synchronously inside `prepare()`), sent `pw1`, and
restarted `SenseRing` and `pwrd`, pushing PipeWire past speakerguard's
heartbeat window and dropping sense frames.
Mirror `SenseRing` with a driver-owned `TxRing` on ADMAC1 TX0:
- `Service` now owns `SpeakerRings { sense, tx }`. `start_with_rings()`
prepares a zeroed 36 KiB coherent cyclic TX ring (32 x 1.0 ms periods
of 48 6-channel S24_LE frames, 12.0 ms / 576-frame lookahead), arms
`SenseRing`, requests `pwrd` (rolling back to `pw1` on error),
immediately issues TX0 on digital silence, and then verifies `pwrd`.
- Teardown (`stop_locked`, `put`, `suspend`) always transitions `spkr`
to `pw1` and verifies it before terminating TX0 and RX0 (leaving rings
running if `pw1` fails in `stop_locked` so a later retry recovers);
`resume()` brings both rings and `pwrd` back together.
- `j616-pcm-1` uses a `SNDRV_DMA_TYPE_VMALLOC` buffer with
`SNDRV_PCM_INFO_NO_REWINDS | SNDRV_PCM_INFO_SYNC_APPLPTR` and an `ack`
callback. `TRIGGER_STOP` and `TRIGGER_SUSPEND` detach audio by zeroing
only the queued lookahead slice ahead of `dma_now + 2` first (with
`dma_mb(Write)` for non-coherent arm64 NC buffers) while TX0 keeps
streaming digital silence.
- Because both TX0 and RX0 stay continuously frame-aligned across stops,
XRUNs, and resumes, `Service::run()` returns immediately when `spkr`
is already running, both rings report healthy `DMA_IN_PROGRESS` status
(with a fresh TX callback timestamp), and AOP still reports `pwrd`,
falling back to `quiesce()` + restart only on a DMA fault or
unexpected power state.
- Replace `SenseRing`'s `fence(SeqCst)` with `dma_mb(Read)` and track
DMA faults on both rings.
- Extract pure ring geometry and cursor arithmetic into `aop_spkr_ring.rs`
with shared KUnit and host (`tools/asahi/aop-spkr-ring-tests.rs`)
unit test coverage.
Signed-off-by: AxxzyWasTaken <[email protected]>
There was a problem hiding this comment.
Verdict: FINISH, then merge at f043d55d
Blockers:
- CI has not finished yet (
host-tests,pr-text,readinessare queued; full build + KUnit + host-tests must be green atf043d55d). - Confirm that the J616C
7.3.0-j616c-parity5+integrated boot row carriesf043d55dbyte-identically (or run an exact-head boot), and add a second-board / suspend-resume verification row for the modifiedspkr_suspend()/spkr_resume()error-propagation andTxRingrestart paths (plus protected playback verification when applicable).
Checked: no Apple material, no AI attribution, no chip/board/firmware gates, no cmdline hacks, human Signed-off-by, speaker protection integrity (keeps SenseRing continuous and never weakens protection or touches amp limits), TxRing clean-ring silence invariant and dma_mb(Write) barriers, Service::start_with_rings() / stop_locked() / suspend() ordering (pw1 before DMA teardown, pwrd followed immediately by TX0 issue), tx_ring_advance()/tx_ring_live_progress()/tx_ring_silence_plan() wrap and glitch clamping, and j616-jack-pcm-0 isolation.
Evidence
- Inspected
sound/soc/apple/aop_audio.rs,sound/soc/apple/aop_spkr.rs, andsound/soc/apple/aop_spkr_ring.rs. - Verified
TxRinglifecycle:prepare()zeroes coherent DMA ring +dma_mb(Write)while channel is stopped;start_with_rings()armsSenseRing, sendspwrd, issues cyclic TX0 immediately, and rolls back (pw1-> stop TX0 -> stop RX0) on any failure;stop_locked()transitions topw1before stopping TX0/RX0. - Verified
Service::run()fast path checksrings.tx.is_healthy()(faulted flag,DMA_IN_PROGRESS, residue bounds,done_atstaleness <= 20 ms),rings.sense.is_healthy(), and livepower_state() == STATE_PWRDbefore skippingquiesce()+ restart. - Verified
tx_ring_advance()handles wrap, backward-wrap glitch clamping (>= TX_RING_FRAMES - TX_PERIOD_FRAMES), underrun/drain overtake resynchronization, andtx_ring_silence_plan()zeroes ahead ofdma_now + 2frames before the prefix. - J616C integrated boot row (
7.3.0-j616c-parity5+, digital silence): 60/60 rapidaplaycycles and 50/50snd_pcm_drop -> snd_pcm_prepare -> snd_pcm_writeicycles with liveSenseRingcapture passed with 0 AOP crashes andreprepare_mean = 0.006 ms.
|
Confirmed against the booted |
|
Merge readiness at
Areas: Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels. |
|
Converting to draft. On J616C, steady playback with this patch applied produces audible pops, some of them loud even at low volume. PipeWire reports no xruns and the browser's output stream is clean, so the glitch is added below PipeWire, in the TX path. My earlier verification only used silent cycles, which could not catch this. Until I've found and fixed it, please don't merge this or try it on speakers. J616C is back on the pre-patch driver meanwhile. |
Fixes #2188
What: Replace direct
snd_dmaengine_pcmTX0 ownership onj616-pcm-1insound/soc/apple/aop_spkr.rswith a symmetric driver-ownedTxRing(matchingSenseRing, pure ring state machine extracted toaop_spkr_ring.rs) that keeps cyclic TX0 continuously fed with digital silence wheneverspkris inpwrd. This closes all fourpwrd-without-TX0 windows that crash AOP RTKit firmware (initial prepare rollback,TRIGGER_STOP/TRIGGER_SUSPEND,stop_locked/put/suspend, andresume), and fast-paths healthy already-running streams inService::run()(with livepower_state() == STATE_PWRDreadback andDMA_IN_PROGRESS+ 20 ms callback freshness checks) to eliminate the 60 msmute_codecs()stall inbe_prepare. Leavesj616-jack-pcm-0(cout/cin) untouched.Tested:
rustfmt --checkclean; host unit testsrun-host-tests.py --only aop-spkr-ring-tests:12/12PASS (ring wrap, silence planning, live pointer/delay, backward-wrap glitch clamp, 10 ms softirq stall survival).ARCH=arm64 LLVM=1):sound/soc/apple/aop_audio.oandsnd-soc-aop.obuild with0warnings /0errors under bothCONFIG_KUNIT=nandCONFIG_KUNIT=y;scripts/checkpatch.pl --strict:0errors.AppleJ616hw:1,1S24_LE6-ch +hw:1,2S16_LE12-chSpeaker Sense) integrated boot (7.3.0-j616c-parity5+carrying this commit, strict/dev/zerodigital silence):60/60rapidaplayopen/prepare/play-zeros/close cycles (hw:1,1): PASS,0AOP crashes.50/50rapidsnd_pcm_drop -> snd_pcm_prepare -> snd_pcm_writeicycles onhw:1,1concurrently reading24,000liveSenseRingframes fromhw:1,2(12-chS16_LE): PASS,prepare_first = 0.003 ms,reprepare_mean = 0.006 ms(min 0.005 ms,max 0.012 ms, down from~60 ms),0AOP crashes,0kernel warnings/errors.Risk: two-way · Apple AOP speaker playback path (
sound/soc/apple/aop_spkr.rs,aop_spkr_ring.rs); headphone jack path (j616-jack-pcm-0) is unchanged.Not yet: Standalone exact-head bare-metal boot row on
f043d55dda9c, audible playback check, and second-board / suspend-resume speaker verification.