Repository navigation
ASoC: apple: macaudio: Serve both speaker protection interfaces - #1279
Merged
Merged
Conversation
The tree carries only the "Speaker Protection" lease, which a
protection engine in the signal path (speakerguardd v2) owns. The
distribution kernels revert it to get "Speaker Volume Unlock" back,
the volume lock that speakersafetyd and speakerguardd 0.1 use, so the
fleet and distribution kernels differ, and the lease cannot return on
the boards it is qualified for without locking every other Mac out.
Carry both. "Speaker Protection Interface" says which one owns the
speakers:
- "Speaker Volume Unlock", at every card bind: the volume lock exactly
as on a lock-only kernel ("Speaker Sample Rate", the ELEM_LOCK and
ping lease, its ceiling, the system-sleep handling, the J700
software-gain epoch, "Amp Gain Volume" limited but the amp's to set).
An owner may hold "Speaker Protection", but nothing is granted, and
its locks and releases touch no amp.
- "Speaker Protection", after a CAP_SYS_ADMIN write only. The handover
passes through both floors: the lock's ceiling first, then no
speaker start and the running streams stopped, the lease's safe
level, every amp gain fixed at its limit, and only then the ceiling
lifted with every volume still at the safe level. While leased the
lock's ping fails with -EBUSY and userspace writes to the speaker
volumes and amp gains with -EPERM.
Back to "Speaker Volume Unlock" by a write, or after 30 s without an
owner of "Speaker Protection" (the engine died, or never came): the
lease's floor, then the lock's ceiling over the safe level. The
speakers go up only once a daemon holds the lock and pings it, as
after a cold bind, and a daemon still holding it learns once, with
-ETIMEDOUT, that it lost it. An engine that restarts within the grace
keeps the lease.
The switch is state for the boot: INACTIVE keeps alsactl off it, and
whatever makes it persist writes it again at every boot.
On the J700 the software gain's table top follows the interface
through a new register of the AOP component, which no control exposes:
half the amplifier's full scale under the lock, the scale its daemon
was calibrated against, and the full scale only while leased.
Assisted-by: LLM
Signed-off-by: Ryan Murray <[email protected]>
Contributor
Author
|
Merge-train: KUnit 61/61 + Rust 6/6, the selftest, host-tests CI SUCCESS, and user-path rows PASS on the M1 Pro (J316) and the M2 (J413) with the published speakersafetyd stack. The v2 switch/kill/revert proof passes on the M2. The default (Speaker Volume Unlock) is the interface users already run, so this changes no user default. Merging per the 11-09 rule. |
2 tasks done
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
One kernel for both speaker protection stacks. The default is the interface users run today.
Why
integration/aurora carries only the "Speaker Protection" lease/grant interface (speakerguardd v2). Every distro kernel (kernel-aurora / linux-aurora / nixos, -27 and -28) reverts it with
0001-restore-legacy-speaker-protection.patchto get "Speaker Volume Unlock" back for speakersafetyd and speakerguardd 0.1. That leaves fleet and distro kernels with different code, and v2 cannot come back on the boards it qualifies on without locking out everyone else.What
macaudio carries both interfaces. A new control,
Speaker Protection Interface, says which one owns the speakers:Speaker Volume Unlock(default at every card bind). The legacy volume lock, behaving exactly as the distro kernels do with 0001:Speaker Sample Rate, the ELEM_LOCK + magic-ping lease (250 ms), the ceiling (TAS/SN012776 at 1, MAX98360A at the safe level), the system-sleep handling, the J700 software-gain epoch,Amp Gain Volumelimited but writable, and the deprecatedplease_blow_up_my_speakersno-op. Here the lease does nothing: a v2 owner may holdSpeaker Protection, but a grant fails with -EBUSY and its lock/unlock touch no amp.Speaker Protection(lease). Only after a CAP_SYS_ADMIN write. The handover goes through both floors in order:While leased, the legacy ping fails with -EBUSY and userspace writes to the speaker volumes and amp gains fail with -EPERM.
Back to
Speaker Volume Unlock. By an admin write, or automatically after 30 s with no owner ofSpeaker Protection(the engine died, or never came). The path: the lease's floor (ramped), the J700 back to the legacy table, then the legacy ceiling over the safe level. The speakers unlock only on a fresh ping, as after a cold bind. A daemon that still holds the lock gets -ETIMEDOUT once ("lock lost").The control is INACTIVE + VOLATILE, so alsactl never saves or restores it, and nothing reads it from the cmdline. Making the choice persist is the job of the userspace upgrade tool (lane SGUP): it writes the control at boot or in v2's ExecStartPre. A v2 restart within 30 s keeps the lease.
aop_t8140 (J700): a new register
REG_SPKR_FULL_SCALEwith no control. It defaults to the legacy table (ceiling 1<<30, the exact literal from 0001), and macaudio selects the 1<<31 table only while leased.Tests:
apple-speaker-pm-volumessuite from 0001 is back.apple-speaker-interfacesuite covers bind = lock, the switch through the floor, the revert starting at the floor (unlock only on a ping), the unowned revert and its grace, CAP_SYS_ADMIN, and INACTIVE.the_volume_lock_keeps_the_legacy_ceiling.selftests/alsa/macaudio-fixed-controls.pyupdated.For userspace (v2's gate): a card with
Speaker Protection Interfaceis a dual kernel. Read that control instead of treating the presence ofSpeaker Protectionas v2-only.Proof
Build:
7.3.0-aurora-sgupki1= integration/aurora 7d03e42 (fleet43's source) + this commit (same tree), fleet config.apple-speaker-protection,-hpf,-pm-volumes,-interface,-admission,-amp-level,apple-mca-capture-sync.snd_soc_t8140_aop_audio_speaker: 6/6.macaudio-fixed-controls.py: 678 attempts, 0 failures in both validation modes.kill -9of v2: lease 0 and volumes 0 at once. The systemd restart is re-granted within 1 s and the interface is kept.systemctl stopof v2: the floor at once, and the interface reverts after 30 s with the volumes still at 0 and still locked.Heads-up for fleet kernels
From this merge on, a fleet kernel starts every boot on "Speaker Volume Unlock". On the lab Macs that run v2, the speakers then stay at the lock's ceiling until the v2 packaging writes "Speaker Protection Interface" before taking the lease. That change is in speakerguardd v2 (lane SGUP2), and it has to land before the next fleet promotion on the v2 boards. Users are unaffected: this default is what the distro kernels already run.
Not covered on hardware: the J700 (Neo) side. In the default mode it uses DJ's 1<<30 table, as -27/-28 do, and the Rust kunit covers it.
Logs: lane SGUP-KI notes (internal).
Assisted-by: LLM
🤖 Generated with Claude Code