Skip to content

drm/apple: audio: release idle TX DMA channel on PCM close - #3712

Merged
DjDeveloperr merged 1 commit into
mainfrom
fix/dcpaud-release-idle-dma
Dec 1, 2026
Merged

DjDeveloperr merged 1 commit into
mainfrom
fix/dcpaud-release-idle-dma

Conversation

@sithglan

Copy link
Copy Markdown
Contributor

What: Guard snd_pcm_set_managed_buffer() so re-opening reuses the managed buffer, and release dcpaud->chan (and its silence buffer if allocated) in dcp_pcm_close(), dcp_pcm_native_close(), dcp_pcm_open() error paths, and dcpaud_before_modeset() failure paths whenever no native silence link is active. Previously, userspace's initial unplugged probe of audio-controller-* left the display ADMAC TX channel allocated until driver removal, pinning admac_dispext*, its ISOC DART, and dispext*_adma powered on continuously even with no external display connected.

Tested:

  • J813 (13-inch M5 MacBook Air, T8142, fw 27.2) in combined trial kernel 7.3.0-aurora-j813-power+ (exact cherry-pick of a864160fdcc1 on main b158a197adc9 alongside independent CLPC and cpufreq commits):
    • After desktop login (PipeWire probe), both dispext0_adma and dispext1_adma dropped from on to off-0 with 0 in-use ADMAC channels in /sys/kernel/debug/dmaengine/summary.
    • Explicit open/close cycles on /dev/snd/pcmC0D0p and /dev/snd/pcmC1D0p succeeded cleanly and both domains returned immediately to off-0; 0 failed units, 0 new kernel warnings/errors.
  • Host / offline checks: tools/asahi/dcpaud-open-fallback-tests.py PASS + all 5 mutations killed (no-retry, wait-any, gone-fails, keep-cookie, mask-all), tools/asahi/dcpaud-sleep-hold-tests.py (128/128), ARCH=arm64 LLVM=-19 W=1 drivers/gpu/drm/apple/audio.o (0 warnings), scripts/checkpatch.pl --strict (0/0/0).

Risk: two-way door · Apple Silicon Macs using apple-dpaudio (drivers/gpu/drm/apple/audio.c).
Revert: git revert restores keeping dcpaud->chan allocated across closes.
Not yet: Live plugged external DisplayPort/HDMI audio playback + unplug cycle on J813 or J873g; standalone single-PR boot without companion commits.

dcp_pcm_open() requests the display audio TX ADMAC channel on the first
open (including userspace's initial unplugged probe) and previously kept
that channel allocated until driver removal. Because apple-admac holds a
runtime PM reference while any channel is allocated, idle external
display ADMAC controllers, their ISOC DARTs, and their DISPEXT*_ADMA
power domains stayed powered continuously even with no external display
attached.

Guard snd_pcm_set_managed_buffer() so re-opening reuses the managed
buffer, and release dcpaud->chan (and its silence buffer if allocated)
when a PCM closes or fails to open and no native link silence transfer
is active. On T8142/T6050/T8152 machines with idle external displays,
this lets admac_dispext* and their ISOC DARTs autosuspend and power off
dispext*_adma.

Signed-off-by: Thomas Glanzmann <[email protected]>
@sithglan
sithglan requested review from a team and DjDeveloperr as code owners November 30, 2026 21:23
@github-actions github-actions Bot added area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 30, 2026
@github-actions

github-actions Bot commented Nov 30, 2026 •

Copy link
Copy Markdown

Merge readiness at a864160f: not ready yet

Check Detail
CI at head no failing: KUnit asahi, KUnit spi-hid-apple, KUnit avd, KUnit ave, KUnit isp, KUnit jpeg
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes ok none
Hardware row at head no no line with the head SHA a864160f, a Mac and a result in the PR body or a comment
Conflicts ok none
PR text ok Risk: two-way · Apple Silicon Macs using apple-dpaudio (drivers/gpu/drm/apple/audio.c). Revert: git revert restores keeping dcpaud->chan allocated across closes.

Areas: area:display, area:gpu

Updated by pr-readiness on pushes, edits, reviews and comments, and on a schedule. Rules: merge policy · labels.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: HOLD at a864160f

Blockers:

  • Queued CI at a864160f (2P/0F/19Q): Hosted CI (kunit, apple-build, host-tests, KUnit suites) is still running.
  • Live plugged external DP/HDMI audio playback + unplug cycle missing (noted in PR body Not yet:): Current J813 (T8142) evidence covers unplugged PipeWire probing and /dev/snd/pcmC*D0p open/close cycles only. Because this PR modifies dcpaud_before_modeset(), dcp_pcm_native_close(), and snd_pcm_set_managed_buffer() reuse across channel release/re-acquire, please post a live plugged external DisplayPort/HDMI audio playback + close + reopen + unplug pass on J813 (plus a second Mac generation row covering apple-dpaudio if available).

Checked:

  • Audited full diff (+96/-27 across drivers/gpu/drm/apple/audio.c and tools/asahi/dcpaud-open-fallback-tests.py):
    • Lock ordering is consistent (open_mutex -> link_lock -> data_lock) across dcp_pcm_open(), dcp_pcm_close(), dcp_pcm_native_close(), and dcpaud_before_modeset().
    • dcpaud_release_dma_locked() safely refuses release whenever silence_running || idle_set || link_prepared || link_started || READ_ONCE(stream_dma) is active, clears dcpaud->chan/dcpaud->silence under data_lock, and frees the silence buffer and DMA channel outside data_lock.
    • Guarding snd_pcm_set_managed_buffer() with if (!dcpaud->substream->dma_buffer.dev.dev) prevents re-allocating the managed buffer on subsequent opens while preserving the stable admac device reference.
    • dcpaud-open-fallback-tests.py verifies dma_releases across all error and success paths.
Evidence
  • Head commit: a864160fdcc18c5e3acfe6815f0a41a357dfde7b (MERGEABLE into main).
  • CI snapshot: 2P/0F/19Q.
  • Non-blocking note: when a monitor is unplugged while a native silence link was held without a subsequent PCM close, dcpaud_release_link() stops silence and tears down the link without releasing dcpaud->chan (safe since open_mutex is not held there; the channel is released on the next PCM close or driver remove).

@sithglan

Copy link
Copy Markdown
Contributor Author

Hardware verification at exact patch (a864160fdcc1) across two Mac generations:

1. J813 (MacBook Air 13" M5, T8142, fw 27.2) — live plugged DP audio + modeset + unplug

Kernel: 7.3.0-aurora-j813-power2+ (carrying this exact drivers/gpu/drm/apple/audio.c commit). External monitor: EIZO EV2780 (2560x1440) on card1-DP-1 (card 0: USBC, audio-controller-1, HDMI/DP Jack = on).

  • Before playback (plugged, idle): dispext0_adma = off-0, dispext1_adma = off-0.
  • Pass 1 (aplay -D hw:0,0 -f S24_LE -c 2 -r 48000 -d 2 /dev/zero):
    • During playback: dispext0_adma = on, PCM state: RUNNING, hw_ptr = 28864, appl_ptr = 48512 (snd_hwparams_to_dma_slave_config: 0, dmaengine_slave_config: 0).
    • After close: EXIT=0, dispext0_adma = off-0.
  • Pass 2 (reopen hw:0,0, S24_LE 48 kHz 2ch, 2s — exercises managed-buffer reuse after DMA channel release/re-acquire):
    • During playback: dispext0_adma = on, PCM state: RUNNING, hw_ptr = 28864, appl_ptr = 48512.
    • After close: EXIT=0, dispext0_adma = off-0.
  • Pass 3 (reopen hw:0,0, S16_LE 44.1 kHz 2ch, 1s): EXIT=0, dispext0_adma = off-0 after close.
  • Modeset (swaymsg output DP-1 power off → power on, exercising dcpaud_before_modeset() + __av_service_disconnect + set_digital_out_mode) + reopen playback (hw:0,0 S24_LE 48 kHz):
    • dispext0_adma stayed off-0 across power off/on, post-modeset playback succeeded (EXIT=0), and returned to off-0 after close.
  • Unplug (card1-DP-1: disconnected, HDMI/DP Jack = off):
    • dispext0_adma = off-0, dispext1_adma = off-0.
    • Post-unplug open("/dev/snd/pcmC0D0p", O_WRONLY | O_NONBLOCK) + close() succeeded and returned dispext0_adma to off-0.
  • 0 failed systemd units, 0 audio/ADMAC warnings or errors in dmesg.

2. J873g (Mac mini M6, T8152, fw 27.2) — exact head a864160fdcc1

Kernel: 7.3.0-aurora-j873-pr3712+ built directly from a864160fdcc1 via one-shot aura-try.

  • Baseline (7.3.0-aurora-j873-main-1127+, without patch): dispext0_adma = on, dispext1_adma = on at idle.
  • With a864160fdcc1 (idle post-boot / post-PipeWire probe): disp_adma = off-0, dispext0_adma = off-0, dispext1_adma = off-0.
  • Two consecutive playback + reopen cycles (aplay -D hw:{0,2},0 -f S24_LE -c 2 -r 48000 -d 1 /dev/zero) on both external DisplayPort PCM cards (card 0 / audio-controller-1 and card 2 / audio-controller-2):
    • card 0: Pass 1 dispext0_adma: off-0 → on → off-0 (EXIT=0), Pass 2 reopen off-0 → on → off-0 (EXIT=0).
    • card 2: Pass 1 dispext1_adma: off-0 → on → off-0 (EXIT=0), Pass 2 reopen off-0 → on → off-0 (EXIT=0).
  • 0 failed systemd units, 0 new dmesg lines / audio warnings.

@aurora-silicon-review aurora-silicon-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Verdict: MERGE at a864160fdcc1

Converts this App's earlier review at the same head to an approval under the 12-01 merge bar (better than before and doesn't break; block only on a shown failure). No code blocker was found in it. The merge gate (a row on one Mac at this head + fast CI) is tracked by pr-readiness, not held here.

Checked: - Audited full diff (+96/-27 across drivers/gpu/drm/apple/audio.c and tools/asahi/dcpaud-open-fallback-tests.py):

  • Lock ordering is consistent (open_mutex -> link_lock -> data_lock) across dcp_pcm_open(), dcp_pcm_close(), dcp_pcm_native_close(), and dcpaud_before_modeset().
  • dcpaud_release_dma_locked() safely refuses release whenever silence_running || idle_set || link_prepared || link_started || READ_ONCE(stream_dma) is active, clears dcpaud->chan/dcpaud->silence under data_lock, and frees the silence buffer and DMA channel outside data_lock.
  • Guarding snd_pcm_set_managed_buffer() with if (!dcpaud->substream->dma_buffer.dev.dev) prevents re-allocating the managed buffer on subsequent opens while preserving the stable admac device reference.
  • dcpaud-open-fallback-tests.py verifies dma_releases across all error and success paths.

Follow-ups (not blocking): queued CI; J813 live plugged DP/HDMI audio playback/close/reopen/unplug row

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Dec 1, 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.

PCM close and failed opens release the idle DMA channel, while the native link keeps it when silence or a stream still owns it. The J813 and J873g rows cover release and reacquisition across repeated playback, with clean modeset and unplug on J813.

@DjDeveloperr
DjDeveloperr merged commit c23f669 into main Dec 1, 2026
16 of 64 checks passed
@DjDeveloperr
DjDeveloperr deleted the fix/dcpaud-release-idle-dma branch December 1, 2026 07:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:display Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (bot) needs-hw-row No hardware row at the PR head (bot) needs-review No approving review from Core or Omarchy Mac yet (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants