Skip to content

dmaengine/ASoC: apple: enable runtime PM for SIO and MCA audio domains - #3359

Open
erikwb wants to merge 9 commits into
mainfrom
feat/apple-sio-mca-runtime-pm
Open

erikwb wants to merge 9 commits into
mainfrom
feat/apple-sio-mca-runtime-pm

Conversation

@erikwb

@erikwb erikwb commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor

What: Implement SIO firmware stop/restart across runtime PM (apple-sio + apple_sleep_engine_reset() fallback), defer sio_issue_pending() descriptor publication via a resume worker when firmware is suspended or suspending, close SIO admission on runtime/sleep stop-return double failure until a confirmed RTKit restart (0e6b27f5a2a8), carry SIO runtime PM onto #3195's held-transfer lifecycle (df82585852cb) without letting timed-out stale tags pin SIO active (daf99763dd95), enable MCA audio_p runtime PM with lazy ADMAC channel allocation on open (mca), and parent T8103 ps_fpwm0..2 under ps_sio (t8103-pmgr.dtsi), allowing idle SIO/audio/SPI/UART power domains to power off cleanly when no audio stream is open.
Tested: Composite live hardware rows plus host checks and kernel builds at 0e6b27f5a2a8:

  • J313 (M1 MacBook Air, T8103) at 0e6b27f5a2a8 in composite trial kernel (origin/main 429e7e15f122 + #3335, #3506, #3508, #3269, #3359, #3289; 3/3 .o/.text hashes byte-identical in apple-sio.o, sleep.o, and mca.o vs single-PR merge on 429e7e15f122, default cmdline, docked CalDigit TS5 + DP-2): arecord hw:0,0 (3ch FLOAT_LE 48 kHz, 3 s = 1,728,044 bytes), 10/10 capture cycles with >500 ms gaps, sio/admac/pwm runtime status back to suspended, kbd_backlight 0 -> 255 -> 0 pwm active/suspended, 0 dmesg SIO/ADMAC/MCA errors, 0 failed units, 0 AVC denials, 5 err+ lines identical to default boot, and 1x deep S2R (rtcwake -d rtc1 -m mem -s 30, ext display DPMS off first: success=1, wake NUB.SPMI0Sw3IRQ; a subsequent post-resume ISP v4l2-ctl capture hung in that composite session with cause unassigned).
  • J713 (M4 MacBook Air, T8132, 27.2 firmware) at 0e6b27f5a2a8 in composite trial kernel (origin/main 429e7e15f122 + #3359, #3560, #3491, #3717, #3297, #3300; Linux 7.3.0, default cmdline, GRUB one-shot + one-shot Stage 2 carrying composite t8132-j713.dtb, battery): apple-sio 3ade00000.dma-controller stays runtime_status active (runtime_suspended_time 0, stop_at_commit); both apple-admac controllers (393300000, 393800000) are suspended at idle; arecord -D hw:0,0 -f FLOAT_LE -r 48000 -c 3 -d 3 (3 runs before sleeps, 1 after) cycles 393300000 suspended -> active -> suspended within 1 s (144,000 frames, 410,396–410,397 non-zero samples, peak 0.0002, 0 NaN); rtcwake -m freeze -s 20 (s2idle) and rtcwake -m mem -s 25 (deep sleep) both resume cleanly (suspend_stats success 1 and 2, fail 0) with SIO active, ADMACs suspended, and capture unchanged; 0 SIO/MCA/ADMAC error lines, 0 failed units, 0 AppArmor denials, 0 Oops/WARN.
  • J716c (16-inch M5 Max, T6050) boot sanity at 0e6b27f5a2a8 in composite trial kernel (origin/main 429e7e15f122 + #3409, #3560, #3651, #3717, #3359, #3289; default cmdline, default Stage 2 b0a2f222b5a9): boots to desktop, apple-sio registered with no sio device in the T6050 DT (apple-sio/apple-mca unbound; apple-admac 293800000/2d3200000 probed), 2x pm_test=devices + 1x pm_test=platform clean, 0 apple-sio/apple-admac/mca errors (1 baseline failed system unit aurora-peripherals.service, 0 failed user units, 0 LSM denials, 0 Oops/BUG/WARN/SError/GPU faults).
  • Host checks and builds at 0e6b27f5a2a8: arm64 LLVM=1 W=1 object build and full J313/J713 kernel builds (0 errors, 0 warnings in touched drivers), KUnit (apple-sio: 45 passed, 1 skipped apple_g17_rx_util_min_test needing CONFIG_UCLAMP_TASK; pwm-apple: 40 passed), host tests (sio 68/68 including sio-rpm-issue-tests 9 scenarios + 11 mutations + a8d2f37caf89 control, dcpaud 15/15, apple-pwm-pm 2/2), and checkpatch.pl --strict (0 errors). CHECK_DTBS=y on T8103 DTBs passed at daf99763dd95 (0 new warnings; DT files unchanged since). Prior J313, J713, and J616C (by @AxxzyWasTaken) rows at pre-merge e9cfcbd1b8fb are under Evidence.
    Risk: two-way door · all Apple Silicon Macs with Apple SIO / MCA audio / T8103 FPWM (M1–M5; commit_stop and stop_at_commit SIO controllers remain active at runtime).
    Not yet: Exact-head 0e6b27f5a2a8 live hardware verification for the remaining unrun paths:
  • J313 (M1 MacBook Air, T8103): configured-channel post-autosuspend SIO descriptor issue, reboot-time led_pwm_shutdown() under idle ps_sio, undocked s2idle (hard-resets J313 on baseline main), and live speaker playback aplay (only with the machine owner's go-ahead and active speakerguardd v2 gating).
  • Hosted CI at 0e6b27f5a2a8: re-run CI checks (the prior 2026-12-01T00:10Z runs at daf99763dd95 were cancelled in queue at 03:18Z).
  • External M2/M3 Macs: runtime testing on external hardware.
Details
  1. dmaengine: apple-sio: stop and restart SIO firmware across runtime PM (ddf95fc58b08):

    • Previously sio_probe() dropped its runtime PM reference while sio_suspend() was a no-op stub, leaving sio_mbox active and risking ps_sio_cpu powering off under live SIO firmware if no sibling pinned sio_dart.
    • For controllers not deferred to the sleep commit boundary (!hw->commit_stop && !hw->stop_at_commit), sio_suspend() stops idle SIO firmware via apple_rtkit_sleep_stop() after a 500 ms autosuspend delay once all channels are quiet and no live mailbox tags are in flight.
    • sio_resume() pulses apple_sleep_engine_reset(dev) upfront before apple_rtkit_power_cycled_return(), avoiding the 1-second -ETIME (-62) wait when a sibling domain (audio/SPI) kept ps_sio powered on across runtime suspend.
    • Holds runtime PM across sio_device_config(), sio_terminate_work(), sio_stop_quiet(), and active idle transfers (sio_set_idle()..sio_clear_idle()), and avoids double-stopping or waking an already runtime-suspended SIO across system sleep.
    • Extends apple_sleep_engine_reset() (drivers/soc/apple/sleep.c) to fall back to reg index 0 when reg-names is absent and to map apple,pmgr directly when apple_sleep is not bound.
  2. ASoC: apple: mca: enable runtime PM on audio_p and allocate ADMAC channels on open (a8d2f37caf89):

    • Previously apple_mca_probe() pinned audio_p via mca->pd_link (DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE) without enabling runtime PM on mca->dev, and mca_pcm_new() held ADMAC channels for the lifetime of the sound card, permanently pinning ps_sio_adma, sio_dart, and the SIO domain hierarchy.
    • Caches DAI BCLK polarity and TX/RX bitstart in mca_fe_set_fmt() and writes them in mca_fe_hw_params() / mca_configure_serdes() so ps_audio_p can safely power off between streams.
    • Enables runtime PM (200 ms autosuspend) on mca->dev, holding references across mca_pcm_open()/mca_close() and mca_be_startup()/mca_be_shutdown(), and skips MMIO in apple_mca_suspend_late()/apple_mca_resume_early() when already runtime-suspended.
    • Formats DMA channel names in a stack char name[16] buffer in mca_request_dma_channel() instead of devm_kasprintf(), validates channel presence in mca_pcm_new(), and allocates/releases ADMAC channels per stream in mca_pcm_open() / mca_close() via snd_dmaengine_pcm_close_release_chan().
  3. arm64: dts: apple: t8103: parent ps_fpwm0..2 under ps_sio (e5a7623da91c):

    • Parents ps_fpwm0, ps_fpwm1, and ps_fpwm2 under ps_sio in arch/arm64/boot/dts/apple/t8103-pmgr.dtsi, matching t600x, t8112, t602x, t6030, t6040, and t8140 so pwm_apple (including led_pwm_shutdown() on reboot) keeps ps_sio up while active and lets ps_fpwm* and ps_sio suspend together when idle.
  4. dmaengine: apple-sio: hold runtime PM across issued transfers (457a940bfff4):

    • sio_device_config() drops its runtime PM reference after configuring a channel, so sio_issue_pending() can run after the 500 ms autosuspend window or while sio_suspend() is in flight.
    • Tracks a per-channel transfer runtime PM reference (tx_rpm_held) acquired via pm_runtime_get_if_active() when SIO is active or deferred to siochan->issue_wq (pm_runtime_resume_and_get()), guards sio_fill_in_{old,ring}_locked() against stopped firmware, includes tx_rpm_held and !list_empty(&siochan->vc.desc_issued) in sio_chan_busy(), flushes issue_wq before terminate_wq in sio_synchronize(), and adds KUnit coverage (sio_issue_pending_after_autosuspend_test and sio_sleep_busy_test in drivers/dma/apple-sio-boot-test.c).
  5. dmaengine: apple-sio: harden runtime PM transfer lifecycle, teardown, and error reporting (4295db09de60):

    • Gates descriptor publication via sio_firmware_active() (!READ_ONCE(sio->rpm_stopped) && !READ_ONCE(sio->asleep)), and releases tx_rpm_held via sio_take_tx_pm_put_locked() / sio_put_tx_pm() across sio_handle_issue_ack(), sio_process_report(), sio_stop_quiet(), sio_clear_idle(), sio_terminate_all(), and sio_terminate_work() once current_tx, retired, non-idle ring state, and pending ACKs are clear.
    • Checks READ_ONCE(siochan->host->removing) under vc.lock before vchan_issue_pending() in sio_issue_pending() (and in sio_prep_dma_cyclic()), so late issue calls after teardown admission closes neither move submitted descriptors to desc_issued nor invoke vchan_cookie_complete() to rearm vc.task.
    • In sio_remove(), closes admission (WRITE_ONCE(sio->removing, true) synchronized under each channel's vc.lock), cancels issue_wq, flushes terminate_wq before and after unregistering the DMA provider, quiesces runtime PM (pm_runtime_dont_use_autosuspend() + pm_runtime_barrier(), while sio_suspend() refuses new suspends once removing is set), and shuts down / disables RTKit mailbox RX (apple_rtkit_shutdown() when sio->arrays is present, plus apple_rtkit_mailbox_off()) before the final drain and tasklet_kill(&siochan->vc.task).
    • Aborts deferred vc.desc_issued descriptors with DMA_TRANS_ABORTED on runtime resume / pm_runtime_get_if_active() failure, asleep, or teardown, and records each aborted cookie alongside its exact u32 residue in a bounded 16-entry FIFO ring (error_cookies) preserved across subsequent healthy transfers until cookie reuse or channel release.
  6. tools/asahi: add apple-sio runtime PM issue lifecycle host test (e9cfcbd1b8fb):

    • Extracts the production apple-sio.c functions into a host runtime PM, virt-dma, and RTKit model registered in tools/asahi/run-host-tests.py, covering post-autosuspend issue, mid-suspend issue (both desc_issued refusal and concurrent apple_rtkit_sleep_stop() race), cancel before issue_wq, ring/idle handover with clear_idle(), commit_stop, asleep, multi-residue DMA_ERROR retention across healthy transfers, late issue_pending() after removing closes, and active sio_remove() quiescing apple_rtkit_shutdown() -> apple_rtkit_mailbox_off() before final tasklet_kill(), plus 10 mutations and the pre-fix a8d2f37caf89 baseline.
  7. Merge branch 'main' into feat/apple-sio-mca-runtime-pm (df82585852cb):

    • Carries SIO runtime PM onto #3195's held-transfer lifecycle (sio_end_tx(), sio_release_tx(), sio_sync()): sio_terminate_work() resumes SIO around sio_end_tx() and hands its reference to a next transfer started without one; sio_release_tx() drops tx_rpm_held with the last transfer and aborts issued descriptors when firmware is stopped or removing; sio_stop_quiet() holds runtime PM and releases tx_rpm_held; sio_sync() flushes issue_wq first and kills vc.task before returning so callbacks from aborted descriptors complete before dmaengine_synchronize() returns; updates KUnit and sio-rpm-issue-tests fixtures for sync_lock/sync_wait and held-transfer fields.
  8. dmaengine: apple-sio: let a stale tag not hold the SIO up at runtime (daf99763dd95):

    • Adds sio_tags_live() (!bitmap_subset(tags->allocated, tags->stale, SIO_NTAGS) under tags->lock) so timed-out stale tags no longer permanently block sio_suspend(), while live in-flight tags still return -EBUSY.
    • Calls sio_release_stale(sio) in sio_resume() immediately after restarting SIO firmware from reset before clearing sio->rpm_stopped.
  9. dmaengine: apple-sio: close admission on suspend stop/return double failure (0e6b27f5a2a8):

    • Marks sio->rtk_unavailable = true when both apple_rtkit_sleep_stop() and immediate apple_rtkit_sleep_return() fail in sio_suspend() or sio_suspend_late(), preventing descriptor issue on the RPM_ACTIVE return path while RTKit is unavailable.
    • Rejects sio_prep_dma_cyclic(), sio_device_config(), sio_set_idle(), and sio_issue_pending() / sio_issue_work() (aborting queued descriptors with DMA_TRANS_ABORTED) while rtk_unavailable is set, and reopens admission only if a confirmed RTKit restart runs in sio_resume() or sio_resume_early() (clearing rtk_unavailable alongside rpm_stopped / asleep; note that after a non--EBUSY/-EAGAIN runtime-suspend error, Linux runtime PM records power.runtime_error, so recovery via sio_resume() is not triggered automatically without clearing the runtime PM error or running system-sleep sio_resume_early()).
    • Adds KUnit (sio_rtk_unavailable_rejects_issue_test in drivers/dma/apple-sio-boot-test.c) and host model coverage (double-failure rejection while RPM_ACTIVE and mid-suspend, failed restart staying closed, confirmed restart reopening, and admit-after-suspend-double-fail mutation).
Evidence
  • PR commits (merge parent 27284bfe9110, cleanly mergeable with origin/main a171afd2123f):
    • ddf95fc58b08f70a70513f30c73f7fcc8d17c46f — dmaengine: apple-sio: stop and restart SIO firmware across runtime PM
    • a8d2f37caf8953f54470eb4d54bfb21e903846d3 — ASoC: apple: mca: enable runtime PM on audio_p and allocate ADMAC channels on open
    • e5a7623da91c9d112cb890674b2b62cde6e17158 — arm64: dts: apple: t8103: parent ps_fpwm0..2 under ps_sio
    • 457a940bfff4574219bc6954009243286010e9ae — dmaengine: apple-sio: hold runtime PM across issued transfers
    • 4295db09de607ec485b815b20ce963690f209c54 — dmaengine: apple-sio: harden runtime PM transfer lifecycle, teardown, and error reporting
    • e9cfcbd1b8fbd2219d23cca242e90db8a290bf37 — tools/asahi: add apple-sio runtime PM issue lifecycle host test
    • df82585852cbe7560dc22f356f90762d19048877 — Merge branch 'main' into feat/apple-sio-mca-runtime-pm
    • daf99763dd959d8647803d50722150aba381cf42 — dmaengine: apple-sio: let a stale tag not hold the SIO up at runtime
    • 0e6b27f5a2a8e6acddf027c53574e84d3a794548 — dmaengine: apple-sio: close admission on suspend stop/return double failure
  • Build (arm64 LLVM=1 W=1) at 0e6b27f5a2a8:
    • W=1 object build (defconfig + asahi.config): 0 errors, 0 object warnings across drivers/soc/apple/sleep.o, drivers/dma/apple-sio.o, sound/soc/apple/mca.o, drivers/dma/apple-admac.o, drivers/gpu/drm/apple/audio.o, and drivers/pwm/pwm-apple.o.
    • Full linux-j313 and linux-j713 kernel builds (7.3.0+): 0 errors, 0 warnings in apple-sio.c, mca.c, sleep.c.
    • CHECK_DTBS=y across T8103 DTBs (t8103-{j274,j293,j313,j456,j457}.dtb) at daf99763dd95 (DT unchanged in 0e6b27f5a2a8): exit 0, 0 warnings referencing ps_fpwm* or ps_sio.
  • KUnit (tools/testing/kunit/kunit.py run --arch=arm64 --make_options LLVM=1) at 0e6b27f5a2a8:
    • drivers/dma/apple-sio.kunitconfig: 45 passed, 1 skipped (apple_g17_rx_util_min_test, needs CONFIG_UCLAMP_TASK), covering apple-sio-t6030 (10/10), apple-sio-t6041 (7/7), apple-sio-probe (2/2), apple-sio-boot (8/8 including sio_sleep_busy_test, sio_issue_pending_after_autosuspend_test, and sio_rtk_unavailable_rejects_issue_test), apple-sio-msg (7/7), apple-sio-terminate (8/8), and apple_mbox_g17_stall (3/4 + 1 skipped).
    • drivers/pwm/pwm-apple.kunitconfig: 40 passed (pwm-apple, including apple_pwm_test_runtime_pm_keeps_registers and apple_pwm_test_zero_duty_runtime_pm_readback).
  • Host tests (tools/asahi/run-host-tests.py) at 0e6b27f5a2a8:
    • --only sio: 68/68 passed (including sio-rpm-issue-tests 9 scenarios, all 11 mutations including skip-remove-shutdown, skip-remove-mailbox-off, and admit-after-suspend-double-fail, and --ref a8d2f37caf8953f54470eb4d54bfb21e903846d3 killed).
    • --only dcpaud: 15/15 passed.
    • --only apple-pwm-pm: 2/2 passed.
  • Checkpatch (scripts/checkpatch.pl --strict --git origin/main..HEAD): 0 errors across all PR commits (0e6b27f5a2a8, daf99763dd95, 4295db09de60, a8d2f37caf89, ddf95fc58b08: 0 errors, 0 warnings, 0 checks; 1 file-addition MAINTAINERS notice on e9cfcbd1b8fb; 1 commit-description 75-col wrap warning each on e5a7623da91c and 457a940bfff4).
  • Live hardware at 0e6b27f5a2a8 (composite trial kernels over origin/main 429e7e15f122):
    • J313 (M1 MacBook Air, T8103) composite (origin/main 429e7e15f122 + #3335, #3506, #3508, #3269, #3359 0e6b27f5a2a8, #3289; 3/3 .o/.text hashes byte-identical in apple-sio.o, sleep.o, and mca.o vs single-PR merge on 429e7e15f122; GRUB one-shot, default cmdline, docked CalDigit TS5 + DP-2 3840x2160@120, AC 100%): 0 failed units, 0 AVC denials, 5 err+ lines identical to default boot; arecord hw:0,0 (3ch FLOAT_LE 48 kHz, 3 s = 1,728,044 bytes) and 10/10 capture cycles with >500 ms gaps passed with sio/admac/pwm runtime status returning to suspended; kbd_backlight 0 -> 255 -> 0 pwm active/suspended; 0 dmesg SIO/ADMAC/MCA errors; 1x deep S2R (rtcwake -d rtc1 -m mem -s 30, ext display DPMS off first) passed (success=1, wake NUB.SPMI0Sw3IRQ; right after deep S2R, post-resume ISP v4l2-ctl capture hung with cause unassigned). s2idle and reboot-time led_pwm_shutdown() did not run.
    • J713 (M4 MacBook Air, T8132, 27.2 firmware) composite (origin/main 429e7e15f122 + #3359 0e6b27f5a2a8, #3560 6c38b2268568, #3491 44d22bf36fb3, #3717 27ffbe1aa92a, #3297 0378182e01b8, #3300 241b8646ccdf; Linux 7.3.0, GRUB one-shot + one-shot Stage 2 carrying composite t8132-j713.dtb, default cmdline, battery 50% to 43%, no speaker playback, no external display attached): apple-sio 3ade00000.dma-controller stays runtime_status active (runtime_suspended_time 0, stop_at_commit); both apple-admac controllers (393300000, 393800000) are suspended at idle; arecord -D hw:0,0 -f FLOAT_LE -r 48000 -c 3 -d 3 (built-in high-quality microphone, 3 runs before sleeps and 1 after both) cycles 393300000 suspended -> active for the stream and -> suspended within 1 s of stop, capturing 144000 frames per run with 410396–410397 non-zero samples, peak 0.0002, 0 NaN; rtcwake -m freeze -s 20 (s2idle) and rtcwake -m mem -s 25 (deep sleep) both resumed cleanly (suspend_stats success 1 and 2, fail 0) with SIO active, ADMACs suspended, and capture repeating unchanged; 0 SIO/MCA/ADMAC error lines, 0 failed units, 0 AppArmor denials, 0 Oops/WARN.
    • J716c (16-inch M5 Max, T6050) composite boot sanity (origin/main 429e7e15f122 + #3409, #3560, #3651, #3717, #3359 0e6b27f5a2a8, #3289; Linux 7.3.0, default cmdline, default Stage 2 b0a2f222b5a9): boots to desktop; apple-sio registered (/sys/bus/platform/drivers/apple-sio) with no sio node in T6050 DT (apple-sio/apple-mca unbound; apple-admac 293800000.dma-controller and 2d3200000.dma-controller probe); sleep.c apple,seq-commit-sio present and 2x pm_test=devices + 1x pm_test=platform resumed cleanly; 0 apple-sio/apple-admac/mca errors or warnings; 1 baseline failed unit (aurora-peripherals.service), 0 failed user units, 0 LSM denials, 0 Oops/BUG/WARN/SError/GPU faults (4 kernel err+ lines from main base).
  • Pre-merge hardware runs at e9cfcbd1b8fb (retained for baseline context):
    • J616C (M4 Max, T6041) by @AxxzyWasTaken (combined battery batch atop main fe9af4b604784 with e9cfcbd1b8fbd, alongside iio: aop_temp, aop_las: run board temperature and lid angle reports on demand with idle stop #3409 and serial: apple-dockchannel: stop idle console drain timer, back off RX, and add sleep PM #3335): clean boot, 0 failed units, 0 dmesg errors, speakerguardd-v2 active (Speaker Playback Mux=Secondary), both audio ADMACs (513300000.dma-controller, 513800000.dma-controller) enter suspended (usage=0) at idle, apple-sio (429e00000.dma-controller) stays active (stop_at_commit), settled battery idle 3.52–3.59 W (disp_bl=100, kbd_bl=64).
    • J713 (M4 MacBook Air, T8132) at e9cfcbd1b8fb: apple-sio (3ade00000, stop_at_commit=true) stayed active; apple-admac (393300000 / 393800000) cycled suspended -> active -> suspended across a 2 s 3-ch FLOAT_LE arecord mic capture (hw:0,0, 96,000 frames, 266,397 non-zero samples, peak 0.00169, 0 NaNs) and remained clean across 3× s2idle; 0 SIO/MCA/ADMAC errors.
    • J313 (M1 MacBook Air, T8103) at e9cfcbd1b8fb: internal HPAI mic (hw:AppleJ313HPAI,0, 3-ch float, 2 s = 96,000 frames, ~288k/288k non-zero, peak 7e-4, rms 1.35e-4, 0 NaN/Inf, both before and after deep sleep) and jack mic (hw:AppleJ313,0, 2-ch S16, 96,000 frames) exercised cleanly; apple-admac, apple-mca, and AOP DMA cycled suspended -> active -> suspended within 5 s; apple-sio stayed suspended across capture and sleeps; 0 SIO/ADMAC/MCA errors or leaks. In batched candidate ac44bee46ee4 (main 9e38a276dcb4): live DT shows ps_fpwm0..2 parented under ps_sio, 236400000.sio and 236408000.mbox stayed suspended with speakersafetyd holding pcmC1D2c (0 -62/-ETIME), stopping speakersafetyd dropped all 5 devices to suspended and 14 power domains (sio_cpu, dpa0, mca0..5, sio_adma, audio_p, uart_p, spi_p, fpwm0, fpwm2) to off-0, and kbd_backlight 0 -> 128 -> 0 ran before and after deep S2R with 0 SErrors.
    • Earlier J313 M1 MacBook Air run at a8d2f37caf89: boot + docked dpaudio1 wake (~2 ms wake, 0 -62/-ETIME); all 5 devices reached suspended and all 9 PMGR domains (sio_cpu, dpa0, mca2, sio_adma, audio_p, uart_p, spi_p, sio, sio_busif) dropped to off-0 with all PCMs closed (macsmc_hwmon Heatpipe Power 3,248.1 -> 3,171.2 mW); real mic capture and speaker playback passed with 0 errors.

sio_probe() released its runtime PM reference while sio_suspend() was a
no-op stub, leaving sio_mbox active and risking ps_sio_cpu powering off
under live SIO firmware whenever no other consumer pinned sio_dart.

Implement sio_suspend() and sio_resume() for controllers that are not
deferred to the sleep commit boundary (!commit_stop && !stop_at_commit):
- Stop idle SIO firmware in sio_suspend() with apple_rtkit_sleep_stop()
  once all channels are quiet and no mailbox tags are outstanding, using
  a 500 ms autosuspend delay so back-to-back calls do not thrash it.
- Restart SIO in sio_resume() via apple_rtkit_power_cycled_return(),
  falling back to apple_sleep_engine_reset() when a sibling domain kept
  the shared SIO power switch on across runtime suspend.
- Hold runtime PM across sio_device_config(), sio_terminate_work(),
  sio_stop_quiet(), and active idle transfers (sio_set_idle() through
  sio_clear_idle()).
- Keep commit_stop and stop_at_commit controllers active at runtime and
  through system suspend so commit-time stops run untouched; avoid
  double-stopping or waking an already runtime-suspended SIO across
  system sleep.
- Allow apple_sleep_engine_reset() to fall back to reg index 0 when
  reg-names is absent and to map apple,pmgr directly when apple_sleep is
  not bound, so the engine-reset recovery works on every board with
  standard apple,pmgr-pwrstate domains.

Signed-off-by: Erik Bourget <[email protected]>
…nnels on open

apple_mca_probe() pinned the audio_p power domain via mca->pd_link
(DL_FLAG_PM_RUNTIME | DL_FLAG_RPM_ACTIVE) without enabling runtime PM on
mca->dev, and mca_pcm_new() held ADMAC channels for the lifetime of the
card, pinning ps_sio_adma, sio_dart, and the SIO power-domain hierarchy
permanently on even when no audio stream is open.

Enable runtime PM on MCA and allocate ADMAC channels lazily on open:
- Cache DAI BCLK polarity and TX/RX bitstart in mca_fe_set_fmt() and
  program them in mca_fe_hw_params() / mca_configure_serdes() so
  ps_audio_p can safely power off between streams.
- Enable runtime PM on mca->dev with a 200 ms autosuspend delay in
  apple_mca_probe(), holding a reference across mca_pcm_open()/mca_close()
  and mca_be_startup()/mca_be_shutdown(), and skip MMIO in
  apple_mca_suspend_late()/apple_mca_resume_early() when already
  runtime-suspended.
- Format DMA channel names in a stack buffer in mca_request_dma_channel()
  instead of devm_kasprintf() to avoid leaking memory across open/close
  cycles.
- Request ADMAC channels briefly in mca_pcm_new() to validate presence
  and configure managed PCM buffers, then allocate them in mca_pcm_open()
  and release them in mca_close() via
  snd_dmaengine_pcm_close_release_chan().

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested review from a team as code owners November 27, 2026 06:07
@erikwb
erikwb requested review from LiamRay11 and maralcbr November 27, 2026 06:07
@github-actions github-actions Bot added area:audio Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) door:two-way Revertible or not, from Merge risk (bot) needs-review No approving review from Core or Omarchy Mac yet (bot) labels Nov 27, 2026
@github-actions

github-actions Bot commented Nov 27, 2026 •

Copy link
Copy Markdown

Merge readiness at 0e6b27f5: not ready yet

Check Detail
CI at head no failing: host-tests
Review no needs one approving review from Core or Omarchy Mac (not the author)
Requested changes no requested by DjDeveloperr
Hardware row at head ok in the PR body at 0e6b27f5
Conflicts ok none
PR text ok Risk: two-way · all Apple Silicon Macs with Apple SIO / MCA audio / T8103 FPWM (M1–M5; commitstop and stopatcommit SIO controllers remain active at runtime).

Areas: area:audio, area:gpu, area:platform

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: Changes requested at a8d2f37caf89.

The configuration path holds a temporary runtime PM reference, then drops it. A DMA client can configure a channel and issue a descriptor after that autosuspend window. sio_issue_pending() still calls sio_update_current_tx_locked() and fills the ring under the channel spinlock without obtaining a live firmware reference or deferring to a resume worker. Prevent descriptor publication while firmware is suspended or suspending. Cover a configured channel issuing after autosuspend, with the PM reference held until it is safe to stop. The current undocked sleep and cross-generation rows remain open.

FPWM0..2 sit behind the SIO fabric on T8103, matching t600x, t8112, t602x, t6030, t6040, and t8140. Without power-domains = <&ps_sio>, letting ps_sio power down at runtime idle allows pwm_apple (for example during led_pwm_shutdown() on reboot) to write FPWM MMIO registers with the SIO fabric powered off, triggering an asynchronous SError in apple_pwm_apply().

Parent ps_fpwm0, ps_fpwm1, and ps_fpwm2 under ps_sio so active PWM users hold ps_sio up while idle PWM (duty cycle 0) lets ps_fpwm* and ps_sio suspend together.

Signed-off-by: Erik Bourget <[email protected]>
sio_device_config() drops its temporary runtime PM reference on return, so a client calling sio_issue_pending() after the 500 ms autosuspend delay could publish descriptors while SIO firmware is stopped or mid-suspend.

Track a per-channel transfer runtime PM reference (tx_rpm_held) held while current_tx is active:
- Acquire it in atomic context via pm_runtime_get_if_active() when SIO is active; otherwise keep the descriptor on vc.desc_issued and defer activation to sio_issue_work(), which calls pm_runtime_resume_and_get() before publishing.
- Guard sio_fill_in_old_locked() and sio_fill_in_ring_locked() against rpm_stopped, mark channels with tx_rpm_held or queued vc.desc_issued entries busy in sio_chan_busy(), and flush issue_wq before terminate_wq in sio_synchronize().
- Release tx_rpm_held when current_tx clears without a queued successor (in ring-to-idle handover and sio_terminate_work()).
- Add KUnit coverage for issuing after autosuspend, draining deferred descriptors, busy accounting, and ring handover PM release.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb

erikwb commented Nov 27, 2026 •

Copy link
Copy Markdown
Contributor Author

Addressed in e5a7623da91c and 457a940bfff4:

  • 457a940bfff4 (apple-sio.c, apple-sio-boot-test.c): sio_issue_pending() no longer publishes descriptors while SIO is runtime-suspended or transitioning. It acquires a per-channel tx_rpm_held runtime PM reference via pm_runtime_get_if_active() when SIO is active and !rpm_stopped; otherwise it leaves the descriptor queued on vc.desc_issued and schedules sio_issue_work() to call pm_runtime_resume_and_get() before publishing. tx_rpm_held stays held across active transfers until cleared in ring-to-idle handover or sio_terminate_work(); sio_fill_in_*() checks rpm_stopped; sio_chan_busy() checks tx_rpm_held and !list_empty(&vc.desc_issued); sio_synchronize() flushes issue_wq before terminate_wq. Added KUnit coverage (sio_issue_pending_after_autosuspend_test + sio_sleep_busy_test): 27/27 apple-sio* tests pass on arm64 QEMU.
  • e5a7623da91c (t8103-pmgr.dtsi): Letting ps_sio power off on T8103 exposed a missing power-domains = <&ps_sio>; on ps_fpwm0..2 (the only SIO-bus domains missing it on T8103, causing an asynchronous SError in apple_pwm_apply() during reboot). Added the parent links and verified active-kbd_backlight reboot + fpwm1 idle-off on J313.

@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: FINISH, then merge.

Blocker: In sio_issue_work(), a failed pm_runtime_resume_and_get() logs and returns while the accepted descriptor remains on desc_issued. issue_pending() has already returned and no retry is scheduled. A client waiting for completion can hang until it explicitly terminates the channel. Please define a bounded retry or report a terminal DMA error to the client, and cover runtime resume failure and recovery in KUnit.

Checked: The issue paths now acquire a runtime PM reference before publishing, and both refill paths check the stopped state. The new KUnit test demonstrates that a stopped engine stays unpublished and terminate/synchronize drains the descriptor. It does not cover progress or client-visible failure after the worker's resume fails. The J313 row covers a successful autosuspend/wake. Broader hardware and hosted checks still apply.

@github-actions github-actions Bot added the ci-failing A check failed at the PR head (bot) label Nov 27, 2026
… and error reporting

Harden the apple-sio transfer runtime PM lifecycle, teardown ordering,
and aborted-descriptor reporting on top of the active-transfer
reference tracking:
- Gate descriptor publication on firmware being active
  (!rpm_stopped && !asleep) via sio_firmware_active(), and release
  tx_rpm_held across all quiet paths (issue ACK, report processing,
  stop_quiet, clear_idle, terminate_all, and terminate_work) once
  current_tx, non-idle ring state, retired list, and pending ACKs are
  clear.
- Check READ_ONCE(sio->removing) under vc.lock before
  vchan_issue_pending() in sio_issue_pending() and in
  sio_prep_dma_cyclic() so late issue calls after teardown admission
  closes neither move submitted descriptors to desc_issued nor invoke
  vchan_cookie_complete() to rearm vc.task.
- In sio_remove(), close admission under vc.lock, cancel issue_wq, flush
  terminate_wq before and after unregistering the DMA provider, refuse
  new runtime suspends and quiesce runtime PM via
  pm_runtime_dont_use_autosuspend() + pm_runtime_barrier(), and shut
  down/disable RTKit mailbox RX (apple_rtkit_shutdown() when sio->arrays
  is present, plus apple_rtkit_mailbox_off()) before the final drain and
  tasklet_kill().
- Abort deferred vc.desc_issued descriptors with DMA_TRANS_ABORTED on
  resume/RPM failure or teardown instead of stranding them, and record
  each aborted cookie with its exact u32 residue in a bounded 16-entry
  FIFO ring (siochan->error_cookies) preserved across subsequent healthy
  transfers until cookie reuse or channel resource release.

Signed-off-by: Erik Bourget <[email protected]>
Extract the apple-sio.c runtime PM, descriptor issue, terminate, ring
handover, error ring, and remove paths into a host model registered in
tools/asahi/run-host-tests.py.

Covers issuing after autosuspend and mid-suspend (both desc_issued
refusal and concurrent sleep_stop race), cancel before issue_wq runs,
ring/idle handover with clear_idle(), commit_stop and asleep guards,
per-cookie DMA_ERROR residues across subsequent healthy transfers, late
issue_pending() after remove admission closes, and active sio_remove()
quiescing apple_rtkit_shutdown() -> apple_rtkit_mailbox_off() before
final tasklet_kill(), plus 10 targeted mutations and pre-fix regression
baseline a8d2f37.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb
erikwb requested a review from DjDeveloperr as a code owner November 27, 2026 22:32
@erikwb

erikwb commented Nov 27, 2026

Copy link
Copy Markdown
Contributor Author

Reconciled on top of the live PR head 457a940bfff4 (preserving e5a7623da91c and 457a940bfff4 intact as ancestors) in 4295db09de60 and e9cfcbd1b8fb.

In drivers/dma/apple-sio.c:

  • Preserved e5a7623da91c (t8103-pmgr.dtsi ps_fpwm0..2 parenting under ps_sio) and 457a940bfff4's tx_rpm_held, !list_empty(&siochan->vc.desc_issued) busy accounting in sio_chan_busy(), and KUnit coverage in drivers/dma/apple-sio-boot-test.c, and layered the lifecycle, teardown, and error-ring fixes strictly on top.
  • sio_issue_pending() checks READ_ONCE(siochan->host->removing) under vc.lock before calling vchan_issue_pending(), so late issue calls after teardown admission closes neither move submitted descriptors to desc_issued nor invoke vchan_cookie_complete() to schedule/rearm vc.task. sio_prep_dma_cyclic() likewise returns NULL once sio->removing is set.
  • When admission is open, sio_issue_pending() checks sio_try_get_tx_pm_locked() (pm_runtime_get_if_active() plus sio_firmware_active(sio) via !READ_ONCE(sio->rpm_stopped) && !READ_ONCE(sio->asleep)) before publishing a descriptor, deferring to siochan->issue_wq (pm_runtime_resume_and_get()) when the device is suspending, suspended, or resuming.
  • sio_update_current_tx_locked() refuses to start a transfer when READ_ONCE(siochan->host->removing) is set or !sio_firmware_active(sio), while sio_fill_in_old_locked() and sio_fill_in_ring_locked() check only !sio_firmware_active(sio). The removing admission checks live in sio_issue_pending(), sio_prep_dma_cyclic(), sio_issue_work() and the resume path of sio_terminate_work(), so no new descriptor reaches the fill helpers once teardown has closed admission.
  • siochan->tx_rpm_held stays held until current_tx, retired, non-idle ring state, and pending ACKs are all clear (released via sio_take_tx_pm_put_locked() / sio_put_tx_pm() across sio_terminate_all(), sio_terminate_work(), sio_handle_issue_ack(), sio_process_report(), sio_stop_quiet(), and sio_clear_idle()), while sio_synchronize() flushes issue_wq and terminate_wq and unconditionally kills vc.task.
  • sio_remove() closes admission (WRITE_ONCE(sio->removing, true) synchronized under each channel's vc.lock), cancels issue_wq with cancel_work_sync(), drains terminate_wq and vc.task before unregistering the DMA provider (of_dma_controller_free() + dma_async_device_unregister()), flushes terminate_wq, quiesces runtime PM (pm_runtime_dont_use_autosuspend() + pm_runtime_barrier(), while sio_suspend() refuses new suspends once sio->removing is set), and shuts down / disables RTKit mailbox RX (apple_rtkit_shutdown() when sio->arrays is present, plus apple_rtkit_mailbox_off()) before the final drain (sio_abort_issued_locked() + sio_take_tx_pm_put_locked()) and tasklet_kill(&siochan->vc.task).
  • When pm_runtime_resume_and_get() or sio_try_get_tx_pm_locked() fails (or deferred descriptors cannot start due to teardown or asleep), sio_abort_issued_locked() drains vc.desc_issued with DMA_TRANS_ABORTED via vchan_cookie_complete(), records each aborted cookie and its exact u32 residue in a bounded 16-entry FIFO ring (siochan->error_cookies) preserved across subsequent healthy submissions (retiring only a matching wrapped-around cookie on new transfer start in sio_update_current_tx_locked() and clearing the ring in sio_free_chan_resources()), and releases tx_rpm_held.
  • In tools/asahi/sio-rpm-issue-tests.c, set sio->arrays (non-NULL) in the active-remove fixture and assert the exact call order apple_rtkit_shutdown() -> apple_rtkit_mailbox_off() -> final tasklet_kill(), backed by the skip-remove-shutdown and skip-remove-mailbox-off mutations in tools/asahi/sio-rpm-issue-tests.py.

Verified locally after e9cfcbd1b8fb:

  • arm64 LLVM=1 W=1 build of drivers/soc/apple/sleep.o, drivers/dma/apple-sio.o, sound/soc/apple/mca.o, drivers/dma/apple-admac.o, drivers/gpu/drm/apple/audio.o, and drivers/pwm/pwm-apple.o, plus T8103 DTBs (t8103-{j293,j274,j313,j456,j457}.dtb): 0 errors, 0 object warnings.
  • tools/testing/kunit/kunit.py --arch=arm64 --make_options LLVM=1: apple-sio-boot 7/7 passed (including sio_sleep_busy_test and sio_issue_pending_after_autosuspend_test) and pwm-apple 39/39 passed.
  • tools/asahi/run-host-tests.py --only sio-rpm-issue: 12/12 passed (control + 10 mutations + --ref a8d2f37caf8953f54470eb4d54bfb21e903846d3 killed); --only dcpaud: 15/15 passed; --only apple-pwm-pm: 2/2 passed.
  • ./scripts/checkpatch.pl --strict --git 457a940bfff4..HEAD: 0 errors, 0 warnings, 0 checks on 4295db09de60 (drivers/dma/apple-sio.c); 0 errors, 1 file-addition MAINTAINERS notice on e9cfcbd1b8fb.

Hardware at e9cfcbd1b8fb (batched candidates on main 9e38a276dcb4, zero playback):

  • J313 (M1 MacBook Air, T8103; candidate ac44bee46ee4): live DT shows ps_fpwm0..2 parented under ps_sio; 236400000.sio and 236408000.mbox stayed suspended even with speakersafetyd holding pcmC1D2c (0 -62/-ETIME); stopping speakersafetyd dropped all 5 devices to suspended and 14 power domains (sio_cpu, dpa0, mca0..5, sio_adma, audio_p, uart_p, spi_p, fpwm0, fpwm2) to off-0 (fpwm1 keeps sio up through the new parent link until the separate zero-duty PWM runtime PM change); kbd_backlight 0 -> 128 -> 0 before and after deep S2R with 0 SErrors.
  • J713 (M4 MacBook Air, T8132; candidate b3dbf237542b): 3ade00000.dma-controller (sio_hw_t8140, stop_at_commit=true) stayed rpm=active while apple-admac stayed rpm=suspended before and after 3× s2idle; 0 SIO/MCA/ADMAC errors.

Still under **Not yet:**: real-stream playback and capture at this head (playback needs the machine owner's go-ahead and speakersafetyd gating), the configured-channel post-autosuspend issue path under a real stream, reboot-time led_pwm_shutdown(), undocked s2idle, and J713 stop_at_commit transfers under a real stream.

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

The deferred-resume failure now completes queued descriptors with DMA_TRANS_ABORTED and retains per-cookie residue in the error history. That addresses my previous stranded-descriptor finding. A real configured stream issued after autosuspend, capture, and J713 commit-stop transfer evidence are still missing. Please post those rows and exercise provider teardown with an active stream at this head before landing.

@github-actions github-actions Bot added the area:gpu Area from CODEOWNERS (bot) label Nov 27, 2026
@erikwb

erikwb commented Nov 28, 2026

Copy link
Copy Markdown
Contributor Author

Added exact-head (e9cfcbd1b8fb) live mic capture hardware rows on J713 and J313 and updated the PR body:

  • J713 (M4 MacBook Air, T8132): apple-sio (3ade00000, stop_at_commit=true) stayed active; apple-admac (393300000 / 393800000) cycled suspended -> active -> suspended across a 2 s 3-ch FLOAT_LE arecord mic capture (hw:0,0, 96,000 frames, 266,397 non-zero samples, peak 0.00169, 0 NaNs) and remained clean across 3× s2idle; 0 SIO/MCA/ADMAC errors.
  • J313 (M1 MacBook Air, T8103): internal HPAI mic (hw:AppleJ313HPAI,0, 3-ch float, 2 s = 96,000 frames, ~288k/288k non-zero, peak 7e-4, rms 1.35e-4, 0 NaN/Inf, both before and after deep sleep) and jack mic (hw:AppleJ313,0, 2-ch S16, 96,000 frames) exercised cleanly; apple-admac, apple-mca, and AOP DMA cycled suspended -> active -> suspended within 5 s; apple-sio stayed suspended across capture and sleeps; 0 SIO/ADMAC/MCA errors or leaks.

Still under **Not yet:**:

  • Live speaker playback (aplay) was intentionally skipped in unattended testing (only capture paths were exercised on J713 and J313; speaker playback requires the machine owner's go-ahead and active speaker protection gating).
  • Live-hardware configured-channel post-autosuspend SIO descriptor issue and active-stream sio_remove() provider teardown (covered in host tests sio-rpm-issue-tests.py 12/12 and apple-sio-boot KUnit 7/7; apple-sio stayed suspended during the J313 ADMAC/MCA capture paths).
  • Reboot-time led_pwm_shutdown() under idle ps_sio at e9cfcbd1b8fb, undocked s2idle on J313, and runtime testing on external M2/M3 Macs.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Nov 30, 2026
@AxxzyWasTaken

Copy link
Copy Markdown
Contributor

Tested on M4 Max (J616C / T6041) in a combined battery batch atop main (fe9af4b604784, with PR head e9cfcbd1b8fbd, alongside #3409 and #3335):

  • Clean boot, 0 failed units, 0 dmesg errors, speakerguardd-v2 active (Speaker Playback Mux=Secondary).
  • MCA audio_p runtime PM verified: both audio ADMACs (513300000.dma-controller, 513800000.dma-controller) enter suspended (usage=0) at idle.
  • apple-sio (429e00000.dma-controller) correctly stays active on T6041 (stop_at_commit) with no regressions.
  • Settled battery idle: 3.52–3.59 W (disp_bl=100, kbd_bl=64).

main ended SIO transfers differently (#3195): an ended transfer is freed
only once the firmware no longer reads its descriptors (sio_end_tx(),
sio_release_tx()), and is held with its channel otherwise; synchronize
waits for that (sio_sync()), bounded only from the SIO's prepare to its
complete, under a per-channel lock.

Carry the runtime PM of this branch onto that lifecycle:
- sio_terminate_work() resumes the SIO around sio_end_tx() and hands its
  reference to a next transfer started without one. If the resume fails,
  sio_end_tx() still frees the transfer only once it is known stopped.
- sio_release_tx(), where an ended or held transfer is finally freed,
  drops the channel's transfer reference with its last transfer, and
  aborts issued descriptors when there is no firmware to start them on
  (removal, or stopped), as the old terminate path did.
- sio_stop_quiet() keeps main's result and gains the runtime PM hold and
  the transfer reference release.
- sio_sync() flushes the deferred issue worker before ending anything,
  and kills the tasklet before returning: descriptors aborted with no
  transfer to end complete through it, and dmaengine_synchronize() must
  not return before their callbacks have run.
- A held transfer stays the channel's current one, so it keeps the
  channel busy and its runtime PM reference, and the firmware up.

Tests: initialise the per-channel sync lock in the runtime PM KUnit
fixture; give main's tag fixture an issue worker and a runtime-active,
held device as probe leaves it; extend the sio-rpm-issue host model with
main's held-transfer code and the fields it uses.

Signed-off-by: Erik Bourget <[email protected]>
A call that times out keeps its tag until its late reply comes or the
firmware is reset, and runtime suspend refused while any tag was
allocated. One firmware call that never got its reply then kept the
SIO firmware running for good.

A kept tag answers nothing any more: runtime suspend now refuses only
for a tag whose request still waits for its reply. The runtime resume
restarts the firmware from reset, after which no late reply comes, so
it releases the kept tags, as the refused-sleep restart already does.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb

erikwb commented Dec 1, 2026 •

Copy link
Copy Markdown
Contributor Author

Merged main (with #3195's SIO transfer lifecycle) at daf99763.

#3195 changed how a transfer ends: it is freed only once the firmware no longer reads its descriptors (sio_end_tx() / sio_release_tx()), and is otherwise held with its channel, while sio_sync() waits for that. The runtime PM of this PR now follows that lifecycle:

  • sio_terminate_work() resumes the SIO around sio_end_tx(). If the resume fails, the transfer is still freed only once it is known to be stopped.
  • sio_release_tx() drops the channel's transfer reference with its last transfer, and aborts issued descriptors when no firmware can start them.
  • A held transfer stays the channel's current one, so it keeps the channel busy and keeps the firmware up.
  • sio_sync() flushes the deferred issue worker first, and kills the tasklet before returning. Descriptors aborted with no transfer to end complete through that tasklet, so without the kill their callbacks could run after dmaengine_synchronize() returns. The host model caught this.
  • daf99763: a tag kept for a call that timed out no longer blocks runtime suspend, and the runtime resume (a restart from reset) releases such tags. Without this, one unanswered call kept the SIO firmware up indefinitely.

Tested: not on a Mac yet at daf99763. Host checks at daf99763:

  • ARM64 KUnit apple-sio*: 44 passed, 1 skipped (apple_g17_rx_util_min_test, which needs CONFIG_UCLAMP_TASK).
  • run-host-tests.py --only sio: 67/67, including sio-rpm-issue-tests, all 10 of its mutations caught, and the a8d2f37c control.
  • J313 config kernel build: clean, no new warnings in apple-sio.c, mca.c or sleep.c.

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

Blockers:

  • Hosted CI at daf99763dd95 is still queued (28 jobs queued: apple-build, dt-checks, host-tests, pr-text, readiness, and KUnit suites) — wait for all checks to complete green.
  • Post exact-head daf99763dd95 hardware verification after the #3195 SIO transfer-lifecycle merge and daf99763 stale-tag runtime PM fix (configured audio stream issued after autosuspend, capture, and J713 commit-stop transfer check).

Checked:

  • Audited commit daf99763dd (dmaengine: apple-sio: let a stale tag not hold the SIO up at runtime):
    • sio_tags_live() checks !bitmap_subset(tags->allocated, tags->stale, SIO_NTAGS) under tags->lock, preventing timed-out stale tags from permanently blocking sio_suspend() while still returning -EBUSY for any live in-flight tag.
    • sio_resume() calls sio_release_stale(sio) immediately after restarting SIO firmware from reset (where no late reply for a timed-out call can arrive) before clearing sio->rpm_stopped.
  • Noted J616C (T6041) MCA audio_p runtime PM pass on pre-merge e9cfcbd1.
Evidence
  • Head: daf99763dd959d8647803d50722150aba381cf42 (base main, MERGEABLE, 9 files +2451/-168).
  • Status checks at review time: 28 queued, 9 skipped, 1 cancelled, 0 failed.

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) needs-hw-row No hardware row at the PR head (bot) labels Dec 1, 2026

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

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 commit daf99763dd (dmaengine: apple-sio: let a stale tag not hold the SIO up at runtime):

  • sio_tags_live() checks !bitmap_subset(tags->allocated, tags->stale, SIO_NTAGS) under tags->lock, preventing timed-out stale tags from permanently blocking sio_suspend() while still returning -EBUSY for any live in-flight tag.
  • sio_resume() calls sio_release_stale(sio) immediately after restarting SIO firmware from reset (where no late reply for a timed-out call can arrive) before clearing sio->rpm_stopped.
  • Noted J616C (T6041) MCA audio_p runtime PM pass on pre-merge e9cfcbd1.

Follow-ups (not blocking): queued CI; post-merge audio runtime PM row incl. J713 commit-stop

…ailure

When apple_rtkit_sleep_stop() fails in sio_suspend() and the immediate
apple_rtkit_sleep_return() fallback also fails, runtime PM returns the
device to RPM_ACTIVE while RTKit remains unavailable. Because
pm_runtime_get_if_active() succeeds on an RPM_ACTIVE device,
sio_issue_pending() could otherwise accept and publish a descriptor to
unavailable firmware.

Mark the controller unavailable (rtk_unavailable) when both runtime/sleep
stop and immediate return fail, rejecting cyclic prep, config, idle
setup, and descriptor issue (aborting queued descriptors with
DMA_TRANS_ABORTED) until sio_resume() or sio_resume_early() confirms an
RTKit restart.

Add KUnit and host unit test coverage for the double-failure admission
closure, rejection while RPM_ACTIVE or mid-suspend, and reopening after a
confirmed RTKit restart.

Signed-off-by: Erik Bourget <[email protected]>
@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

Fixed in 0e6b27f5a2a8 and updated the PR description (including identifying 27284bfe9110 as the merge parent):

  • Double-failure admission closure (0e6b27f5a2a8, drivers/dma/apple-sio.c):
    • When both apple_rtkit_sleep_stop() and the immediate apple_rtkit_sleep_return() fallback fail in sio_suspend() (or sio_suspend_late()), sio->rtk_unavailable is set before returning the suspend error so descriptor admission stays closed even though runtime PM returns the device to RPM_ACTIVE.
    • While rtk_unavailable is set, sio_firmware_active() returns false, sio_prep_dma_cyclic() returns NULL, sio_device_config() and sio_set_idle() reject with -EIO, and sio_issue_pending() / sio_issue_work() reject and abort queued descriptors with DMA_TRANS_ABORTED (DMA_ERROR).
    • Admission reopens only after a confirmed RTKit restart in sio_resume() (which also runs recovery when rtk_unavailable is set) or sio_resume_early().
  • Unit tests (drivers/dma/apple-sio-boot-test.c, tools/asahi/sio-rpm-issue-tests.{c,py}, tools/asahi/run-host-tests.py):
    • Added KUnit test sio_rtk_unavailable_rejects_issue_test and host-model scenarios covering the apple_rtkit_sleep_stop() + apple_rtkit_sleep_return() double-failure path (RPM_ACTIVE and mid-suspend), failed restart keeping admission closed, confirmed restart reopening admission, and the admit-after-suspend-double-fail mutation.
  • Verification at 0e6b27f5a2a8:
    • git merge-tree --write-tree origin/main HEAD: clean (7e6786793192, 0 conflicts).
    • arm64 LLVM=1 W=1 (defconfig + asahi.config): 0 errors and 0 warnings across drivers/soc/apple/sleep.o, drivers/dma/apple-sio.o, sound/soc/apple/mca.o, drivers/dma/apple-admac.o, drivers/gpu/drm/apple/audio.o, and drivers/pwm/pwm-apple.o; full linux-j313 and linux-j713 builds pass (7.3.0+).
    • KUnit (arm64 LLVM=1): drivers/dma/apple-sio.kunitconfig 45 passed, 1 skipped (apple_g17_rx_util_min_test, needs CONFIG_UCLAMP_TASK); drivers/pwm/pwm-apple.kunitconfig 40 passed.
    • Host tests (tools/asahi/run-host-tests.py): --only sio 68/68 passed (9 scenarios + 11 mutations + a8d2f37caf89 control), --only dcpaud 15/15 passed, --only apple-pwm-pm 2/2 passed.
    • scripts/checkpatch.pl --strict --git origin/main..HEAD: 0 errors (0e6b27f5a2a8: 0 errors, 0 warnings, 0 checks).
  • Live hardware at 0e6b27f5a2a8 (composite trial kernels on origin/main 429e7e15f122):
    • J313 (T8103, apple-sio.o/sleep.o/mca.o 3/3 .o/.text byte-identical vs single-PR merge on 429e7e15f122): arecord hw:0,0 (3ch FLOAT_LE 48 kHz, 3 s = 1,728,044 bytes) and 10/10 capture cycles (>500 ms gaps) passed with sio/admac/pwm runtime status returning to suspended; kbd_backlight 0 -> 255 -> 0 pwm active/suspended; 0 SIO/ADMAC/MCA dmesg errors; 0 failed units; 0 AVC denials; 1x deep S2R (rtcwake -d rtc1 -m mem -s 30, ext DPMS off first) resumed cleanly (subsequent post-resume ISP v4l2-ctl capture hung with cause unassigned). s2idle and reboot-time led_pwm_shutdown() remain in Not yet.
    • J713 (M4 MacBook Air, T8132, 27.2 firmware, composite): apple-sio 3ade00000.dma-controller stayed active (runtime_suspended_time 0, stop_at_commit); both apple-admac controllers (393300000, 393800000) idled suspended; arecord -D hw:0,0 -f FLOAT_LE -r 48000 -c 3 -d 3 (3 runs before sleeps, 1 after) cycled 393300000 suspended -> active -> suspended within 1 s (144,000 frames, 410,396–410,397 non-zero samples, peak 0.0002, 0 NaN); rtcwake -m freeze -s 20 (s2idle) and rtcwake -m mem -s 25 (deep sleep) both resumed cleanly (suspend_stats success 1 and 2, fail 0) with SIO active, ADMACs suspended, and capture unchanged; 0 SIO/MCA/ADMAC error lines, 0 failed units, 0 AppArmor denials, 0 Oops/WARN.
    • J716c (T6050) boot sanity: boots to desktop (1 baseline failed unit aurora-peripherals.service, 0 failed user units, 0 LSM denials, 0 Oops/BUG/WARN/SError); apple-sio registered with no sio device in T6050 DT (apple-sio/apple-mca unbound; apple-admac probed cleanly; 2x pm_test=devices + 1x pm_test=platform clean; 0 SIO/ADMAC/MCA errors).
  • Remaining before merge: re-run hosted CI at 0e6b27f5a2a8 and cover remaining unrun rows (J313 s2idle/led_pwm_shutdown()/configured-channel post-autosuspend SIO issue/permitted aplay, external M2/M3 Macs).

@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed needs-hw-row No hardware row at the PR head (bot) ci-failing A check failed at the PR head (bot) labels 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.

drivers/dma/apple-sio.c:3207 now calls apple_sleep_engine_reset() during ordinary runtime resume, but drivers/soc/apple/sleep.c:3255–3272 can leave the PMGR register in a forced reset or off state on timeout. For example, after writing PS_ENGINE_RESET_0, a failed poll skips both the power-on and saved-value writes. The helper then restores the DART state and returns while genpd still considers the domain on. Please make the failure path restore the touched power-state registers before restoring DART state, or explicitly coordinate a failed-domain state with the PMGR provider. Please cover a timeout after the reset write in the regression test.

@github-actions github-actions Bot added the changes-requested A reviewer requested changes (bot) label Dec 1, 2026

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

area:audio Area from CODEOWNERS (bot) area:gpu Area from CODEOWNERS (bot) area:platform Area from CODEOWNERS (bot) blast:all Macs affected, from Merge risk (bot) changes-requested A reviewer requested changes (bot) ci-failing A check failed at the PR head (bot) door:two-way Revertible or not, from Merge risk (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.

3 participants