Skip to content

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

Merged
DjDeveloperr merged 11 commits into
mainfrom
feat/apple-sio-mca-runtime-pm
Dec 2, 2026
Merged

DjDeveloperr merged 11 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 with PMGR rollback on timeout), 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), parent T8103 ps_fpwm0..2 under ps_sio (t8103-pmgr.dtsi), and merge main (0bc45c54fbe6) at 06a014735072.
Tested: Host checks, KUnit suites, DT schema checks, kernel builds, and J313 (T8103) hardware verification at 06a014735072 (merged with origin/main 0bc45c54fbe6; prior composite J313, J713, and J716c hardware rows at 0e6b27f5a2a8 under Evidence):

  • Live J313 (M1 MacBook Air, T8103, 27.2 firmware) at 06a014735072 (in composite 807c3bbf2263 over origin/main d3de772ac0c1, one-shot trial Stage 2 with t8103-j313.dtb, default cmdline): booted DT carries ps_fpwm0..2 under ps_sio, apple-sio autosuspend 500 ms (control=auto); playing zeros (aplay, 3 s twice, rc 0) to hw:USBC,0 (dock monitor) woke apple-sio from suspended (apple-sio: RTKit: Initializing), advanced runtime_active_time 1257 -> 8500 ms, read active on close, and returned to suspended within 2 s in both rounds (repeating 8500 -> 15706 ms after deep S2R); arecord -D hw:AppleJ313HPAI,0 3-ch float 48 kHz (3 s) passed before and after 3x docked deep S2R (rtcwake -d /dev/rtc1 -m mem -s 20, suspend_stats success 0 -> 1 per cycle, fail 0, 16 MB RAM integrity PASS, 0 Oops/WARN/SError; speakerguardd-v2-switchtest.service failed identically on a separate newer-main build lacking #3359's DT/MCA changes while passing on the stock daily baseline).
  • Builds at 06a014735072: full linux-j313, linux-j713, and linux-j716c kernel builds pass (7.3.0+); arm64 LLVM=1 W=1 (defconfig + asahi.config, -d RUST) object builds pass with 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.
  • KUnit (arm64 LLVM=1) at 06a014735072: macaudio (apple-speaker-*) 84/84 passed; apple-sio 45 passed, 1 skipped (apple_g17_rx_util_min_test, needs CONFIG_UCLAMP_TASK); pwm-apple 40/40 passed.
  • Host tests (tools/asahi/run-host-tests.py) at 06a014735072: --only sio 70/70 passed (including sio-engine-reset-tests and sio-rpm-issue-tests 13 runs); --only dcpaud 15/15 passed; --only apple-pwm-pm 2/2 passed.
  • DT and style checks at 06a014735072: scripts/dtc/apple-dt-check.sh origin/main HEAD checked 5 changed DTBs with 0 new warnings; scripts/checkpatch.pl --strict --git origin/main..HEAD reported 0 errors across all commits.
    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: Remaining exact-head 06a014735072 checks and other hardware paths:
  • J313 (M1 MacBook Air, T8103): remaining items not run in the 807c3bbf2263 pass: physical-unplug s2idle (docked s2idle was refused cleanly by nhi, and software-undocked s2idle without a physical dock unplug hung/cold-reset), reboot-time led_pwm_shutdown() under idle ps_sio, and permitted speaker playback (with machine owner permission and active speakerguardd v2 gating; a kbd-backlight write read back 0 under aurora-kbd-light ownership).
  • J713 (M4 MacBook Air, T8132): exact-head 06a014735072 stop_at_commit sleep/wake with SIO active, mic capture, and ADMAC idle return (board off-network during this sweep, staged for retry).
  • J716c (16-inch M5 Max, T6050): exact-head 06a014735072 boot sanity (recording the booted DT's sio node status alongside apple-sio/apple-mca binding; not run before the J716c pass stopped on s2idle).
  • Hosted CI at 06a014735072: pending push and CI run on the unpublished 06a014735072 merge head.
  • External T6030 / M2 / M3 Macs: runtime testing on external hardware, specifically a T6030 (commit_no_cpu_down + commit_early alongside stop_at_commit, vs J713's stop_at_commit-only control) late-refusal sleep/wake (sio_resume_early() rx_held unwind via apple_rtkit_resume_rx()) and post-resume DP-audio recovery run.
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).
  10. soc: apple: sleep: restore PMGR domains when an engine reset fails (4a086af941a9):

    • Factors sleep_engine_reset_power() in drivers/soc/apple/sleep.c to save PMGR domain controls upfront and roll back every touched domain (including the domain whose poll timed out) in reverse order before restoring DART state, verifying settled state while preserving the original error.
    • Adds tools/asahi/sio-engine-reset-tests.py (registered in tools/asahi/run-host-tests.py) covering the full sequence and injected failures across all nine reset and power-on poll points.
  11. Merge branch 'main' into feat/apple-sio-mca-runtime-pm (06a014735072):

    • Merges origin/main (0bc45c54fbe6), resolving the two conflicts in drivers/dma/apple-sio.c with the T6030 commit_no_cpu_down / commit_early / rx_held updates in sio_probe() and sio_resume_early().
Evidence
  • PR commits (merge parent 0bc45c54fbe6, 10 files +2835/-181 vs origin/main):
    • 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
    • 4a086af941a9269d04e4cef19e207092aa5e75b8 — soc: apple: sleep: restore PMGR domains when an engine reset fails
    • 06a0147350726f28bd672915d8c6ae21fad5c74a — Merge branch 'main' into feat/apple-sio-mca-runtime-pm
  • Build (arm64 LLVM=1) at 06a014735072:
    • W=1 object build (defconfig + asahi.config, -d RUST): 0 errors, 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, linux-j713, and linux-j716c kernel builds (7.3.0+): exit 0 (Image.gz, dtbs, modules.tar.zst).
    • scripts/dtc/apple-dt-check.sh origin/main HEAD: 5 changed DTBs checked with their families; base: make rc=0, 294 warning lines, 5 of 141 DTBs checked; head: make rc=0, 294 warning lines, 5 of 141 DTBs checked; new warnings: 0, removed: 0.
  • KUnit (arm64 LLVM=1) at 06a014735072:
    • scripts/ci/apple-kunit.py run macaudio apple-sio:
      • macaudio (sound/soc/apple/macaudio.kunitconfig, apple-speaker-*): 84/84 passed.
      • apple-sio (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/40 passed (pwm-apple).
  • Host tests (tools/asahi/run-host-tests.py) at 06a014735072:
    • --only sio: 70/70 passed (including sio-engine-reset-tests, sio-rpm-issue-tests 13 runs covering all 11 mutations and a8d2f37caf89 control).
    • --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.
  • Live J313 (M1 MacBook Air, T8103, 27.2 firmware) at 06a014735072 in composite 807c3bbf2263 (origin/main d3de772ac0c1 + 06a014735072, one-shot trial Stage 2 with t8103-j313.dtb, default cmdline):
    • Booted DT shows ps_fpwm0..2 and ps_sio with power-domains; apple-sio autosuspend 500 ms, control=auto.
    • SIO wake after autosuspend, completed transfer, and return to suspended: playing zeros (aplay, 3 s, twice, rc 0) to hw:USBC,0 (dcp-dp-audio, dock monitor only) woke apple-sio from suspended with apple-sio: RTKit: Initializing on each open, advanced runtime_active_time 1257 -> 8500 ms, read active immediately after close, and returned to suspended within 2 s in both rounds; repeated after deep S2R (8500 -> 15706 ms, same pattern).
    • Mic capture (arecord -D hw:AppleJ313HPAI,0 3-channel float 48 kHz, 3 s to /dev/null): rc 0 before and after sleep.
    • Deep S2R: 3/3 docked (rtcwake -d /dev/rtc1 -m mem -s 20, suspend_stats success 0 -> 1 per cycle, fail 0, 16 MB RAM integrity PASS, 0 Oops/WARN/SError); speakerguardd-v2-switchtest.service failed identically on a separate newer-main build without #3359's DT/MCA changes while passing on the stock daily baseline.
  • Prior 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).
    • 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 apple-sio/apple-mca unbound (source t6050-j716c.dtb defines sio: dma-controller@505e00000 with status = "disabled"; the booted 0e6b27f5a2a8 DT was not archived to distinguish a disabled node from an omitted one; 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 <erik@ebourget.net>
…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 <erik@ebourget.net>
@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 06a01473: ready to merge

Check Detail
CI at head ok 12 checks passed
Review ok approved by DjDeveloperr
Requested changes ok none
Hardware row at head ok in the PR body at 06a01473
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
Merge: gh pr merge 3359 --merge (Owners and Core through the bypass: add --admin).

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 <erik@ebourget.net>
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 <erik@ebourget.net>
@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 <erik@ebourget.net>
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 <erik@ebourget.net>
@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 <erik@ebourget.net>
@github-actions github-actions Bot added ci-failing A check failed at the PR head (bot) and removed 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
@erikwb

erikwb commented Dec 1, 2026

Copy link
Copy Markdown
Contributor Author

We carry this PR in our J313 (M1 Air, T8103), J713 (M4 Air, T8132), and J716c (M5 Max, T6050) daily kernels.

Without runtime PM for apple-sio and apple-mca (and on-open ADMAC channel allocation), the SIO coprocessor and audio_p / MCA audio domains stayed powered continuously even when no audio or SIO transfer was active, wasting idle power on battery.

Running smoothly across all three daily kernels (J313, J713, and J716c) with audio playback/capture and idle runtime PM working cleanly.

@github-actions github-actions Bot removed the ci-failing A check failed at the PR head (bot) label Dec 2, 2026
SIO runtime resume resets the engine even when a sibling has kept its
power switch on. If either reset poll or the subsequent power-on poll
times out, the engine reset can leave a domain forced into reset or
targeting off while genpd still has it on.

Save the control state and restore every touched word in reverse order
before restoring DART state. Check the restored request and report any
domain that fails to settle while preserving the original reset error.

Inject failures at each reset and power-on poll in the host test.

Signed-off-by: DjDeveloperr <hey@djdev.me>
@DjDeveloperr

DjDeveloperr commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

4a086af941a9 restores the touched PMGR domains before DART restore if reset or power-on times out. The Arm64 W=1 build of sleep.o passed. The host test passed the successful sequence and all nine injected timeout points with GCC and Clang.

@erikwb, use this head for the next J313 SIO autosuspend/resume and capture receipt and the J713 commit-stop control. The existing rows cover 0e6b27f5a2a8. This head is ready for independent review while CI runs.

@DjDeveloperr
DjDeveloperr dismissed their stale review December 2, 2026 02:57

The PMGR reset rollback and timeout regression are in 4a086af.

@github-actions github-actions Bot added needs-hw-row No hardware row at the PR head (bot) and removed changes-requested A reviewer requested changes (bot) labels Dec 2, 2026
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.

The PMGR timeout fix at 4a086af941a9 resolves the earlier reset-state finding. Every failed power-state poll now reaches rollback, including the domain whose poll failed. The helper restores the saved controls in reverse order before DART restore, preserves the original error, and SIO keeps descriptor admission closed on that error. I reran the successful sequence and all nine timeout points with GCC and Clang. All nine host issue-lifecycle scenarios and the hosted Apple build, DT, host and SIO KUnit checks also passed.

@erikwb, the last physical results here cover 0e6b27f5a2a8. On your next docked J313 build, please record one actual SIO wake after autosuspend, a completed transfer and a return to suspended. The external DP audio channel can carry silence. A mic capture also checks MCA/ADMAC, but on the earlier J313 run SIO stayed suspended throughout capture. On your J713 commit-stop control, one known-good sleep/wake with SIO active, successful capture and ADMAC back at idle is sufficient. Please include the build SHA and any new driver errors. The J313 candidate can include #3850 unchanged.

Resolve conflicts in drivers/dma/apple-sio.c with T6030 commit-stop and commit_early updates from main: keep commit_no_cpu_down NULL base selection and hw->commit_early gating in sio_probe(), and keep sio->rx_held resume alongside WRITE_ONCE(sio->asleep, false) in sio_resume_early().

Signed-off-by: Erik Bourget <erik@ebourget.net>
@github-actions github-actions Bot removed the merge-conflict Conflicts with the base branch (bot) label Dec 2, 2026
@erikwb

erikwb commented Dec 2, 2026

Copy link
Copy Markdown
Contributor Author

Merged origin/main (0bc45c54fbe6) into feat/apple-sio-mca-runtime-pm at 06a014735072, resolving the two merge conflicts in drivers/dma/apple-sio.c:

  • sio_probe(): kept commit_no_cpu_down NULL base selection and hw->commit_early gating from main with !err under the rpm_put: exit path.
  • sio_resume_early(): kept sio->rx_held resume (apple_rtkit_resume_rx()) alongside WRITE_ONCE(sio->asleep, false).

Verified at 06a014735072:

  • Host tests (tools/asahi/run-host-tests.py): --only sio 70/70 passed (including sio-engine-reset-tests and sio-rpm-issue-tests), --only dcpaud 15/15 passed, --only apple-pwm-pm 2/2 passed.
  • KUnit (arm64 LLVM=1): macaudio (apple-speaker-*) 84/84 passed, apple-sio 45 passed / 1 skipped (apple_g17_rx_util_min_test, needs CONFIG_UCLAMP_TASK), pwm-apple 40/40 passed.
  • Builds and DT checks: full linux-j313, linux-j713, and linux-j716c kernel builds pass; arm64 LLVM=1 W=1 object builds pass with 0 errors and 0 warnings across touched drivers; scripts/dtc/apple-dt-check.sh origin/main HEAD passed with 0 new warnings across 5 changed DTBs; checkpatch.pl --strict --git origin/main..HEAD reported 0 errors.

@DjDeveloperr, updated the PR description for 06a014735072 with the completed J313 (T8103, 27.2 firmware) hardware pass (composite 807c3bbf2263 carrying 06a014735072 over origin/main d3de772ac0c1, one-shot trial Stage 2 with t8103-j313.dtb, default cmdline):

  • Booted DT has ps_fpwm0..2 under ps_sio and apple-sio autosuspend 500 ms (control=auto).
  • SIO wake/transfer/autosuspend via hw:USBC,0 (dcp-dp-audio zero playback, 3 s twice, rc 0): woke from suspended (apple-sio: RTKit: Initializing), runtime_active_time 1257 -> 8500 ms, returned to suspended within 2 s on both rounds, and repeated after deep S2R (8500 -> 15706 ms).
  • Mic capture (arecord -D hw:AppleJ313HPAI,0 3-ch float 48 kHz, 3 s) returned rc 0 before and after 3x docked deep S2R (rtcwake -d /dev/rtc1 -m mem -s 20, suspend_stats success 0 -> 1 per cycle, fail 0, 16 MB RAM integrity PASS, 0 Oops/WARN/SError; speakerguardd-v2-switchtest.service failed identically on a separate newer-main build lacking #3359's DT/MCA changes while passing on the stock daily baseline).

Remaining in **Not yet:**: J313 physical-unplug s2idle / led_pwm_shutdown() / permitted speaker playback, J713 stop_at_commit control run (board off-network during this sweep, staged for retry), J716c boot sanity (sio node status), hosted CI once 06a014735072 is pushed, and external T6030 late-refusal (rx_held unwind via apple_rtkit_resume_rx()) and DP-audio recovery.

@github-actions github-actions Bot removed the needs-hw-row No hardware row at the PR head (bot) label 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.

Approving at 06a014735072.

The PMGR reset rollback asked for in the earlier round is in. Every failed poll in sleep_engine_reset_power() rolls the touched domains back in reverse order, including the one that timed out, before the DART restore, and the original error is kept. The merge with main keeps main's commit_no_cpu_down, commit_early and rx_held handling in sio_probe() and sio_resume_early(). Apart from line offsets, this PR's own changes to apple-sio.c, mca.c and the T8103 DT are the same as at 0e6b27f5a2a8.

I checked these and found no blocking defect:

  • runtime PM get/put balance on every probe, remove and error path in both drivers;
  • system-sleep ordering: sio_system_suspend() stops the firmware through sio_suspend(), so sio_suspend_late() and sio_resume_early() skip it, and pm_runtime_force_resume() restarts it;
  • channel teardown while runtime-suspended: sio_terminate_work(), sio_stop_quiet() and sio_set_idle() resume first.

Checked locally on the merge with current main (bf7d80caf992, merges cleanly), arm64 LLVM=1:

  • W=1 build, defconfig + asahi.config, of sleep.o, apple-sio.o, mca.o, apple-admac.o, pwm-apple.o and the five T8103 DTBs: 0 warnings, 0 errors.
  • SIO KUnit (drivers/dma/apple-sio.kunitconfig), compile only: 0 warnings, 0 errors.
  • tools/asahi/run-host-tests.py --only sio: 70/70, including the a8d2f37caf89 control.
  • checkpatch.pl --strict on the 9 non-merge commits: 0 errors. It reports 2 long commit-log lines, 1 MAINTAINERS note, and 29 style checks in the host-test C file.

Non-blocking:

  1. drivers/dma/apple-sio.c:3211, sio_suspend(): if apple_rtkit_sleep_stop() fails but apple_rtkit_sleep_return() brings the firmware back, the stop error is still returned. Runtime PM keeps any error other than -EBUSY/-EAGAIN in power.runtime_error. Every later pm_runtime_resume_and_get() then fails with -EINVAL, so sio_device_config() and sio_set_idle() refuse until the next system sleep, even though the firmware is running. The fix is to return -EAGAIN in that branch and keep the real error only for the double failure.
  2. tools/asahi/run-host-tests.py loses its executable bit (100755 to 100644, from 4a086af941a9). CI and the docs run it through python3, so nothing breaks, but it should keep its mode.

Before merge: SIO/MCA is shared audio code, so it needs hardware rows from two generations. The J313 row covers this head. The second generation is still owed at this head: the J713 stop_at_commit control listed under Not yet. The J713 row at 0e6b27f5a2a8 doesn't carry over, because sleep.c has changed since then. Hosted KUnit for this head is still queued.

@github-actions github-actions Bot added ready-to-merge Meets the merge policy: merge it (bot) and removed needs-review No approving review from Core or Omarchy Mac yet (bot) labels Dec 2, 2026
@DjDeveloperr

Copy link
Copy Markdown
Contributor

J773g (T8132, 27.2) 06a0147 PASS: apple-sio (3ade00000, SIO v10) and apple-admac (393300000/393800000) bound cleanly on 7.3.0-j773g-comp3-3359-3972 (main 1262f9e + #3359 + #3972, boot_id=3506c984); playback and capture skipped (t8132-j773g.dtb has no /sound card or internal mic); 1x s2idle (rtcwake -m freeze) PASS with SIO/ADMAC forced active, then both ADMACs returned to runtime-suspended after idle while T8132 commit_stop SIO stayed active per sio_can_runtime_suspend(); mem sleep refused identically to base at 48ae00000.dcp (-16) without error; 0 SIO/ADMAC/MCA errors, 0 DART faults, 0 WARN/Oops, 0 failed units.

@DjDeveloperr
DjDeveloperr merged commit d5597c3 into main Dec 2, 2026
16 checks passed
@DjDeveloperr
DjDeveloperr deleted the feat/apple-sio-mca-runtime-pm branch December 2, 2026 20:54
@DjDeveloperr
DjDeveloperr restored the feat/apple-sio-mca-runtime-pm branch December 2, 2026 21:11
@DjDeveloperr
DjDeveloperr deleted the feat/apple-sio-mca-runtime-pm branch December 2, 2026 21:11
DjDeveloperr added a commit to AxxzyWasTaken/linux that referenced this pull request Dec 2, 2026
aurora-silicon#3359 landed and its branch was deleted, so this PR now targets main.
apple-sio.c: main made sio_commit_stop() skip the CPU-control word on
SIOs whose commit keeps the CPU up (commit_no_cpu_down). Keep that, and
keep this branch's early return for a SIO runtime PM already stopped.

Signed-off-by: DjDeveloperr <hey@djdev.me>
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) door:two-way Revertible or not, from Merge risk (bot) ready-to-merge Meets the merge policy: merge it (bot)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants