aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/sound
Commit message (Collapse)AuthorAgeFilesLines
* sound: enforce MASTER volume mute during playbackSean Farley3 days1-1/+10
| | | | | | | | | | | | | | | | | | | MASTER mute (vol.mute) works while audio is playing. However, if a stream is stopped and restarted (PCMTRIG_STOP -> PCMTRIG_START), the audio will resume even though the mixer shows the MASTER volume as muted. Other streams that are already playing remain silent. New streams may also start playing audio regardless of the MASTER mute state. The volume feeder now considers the MASTER mute when determining whether a channel should be muted. This ensures MASTER mute is consistently enforced for all streams and removes the dependency on trigger-driven state propagation. Tested with Creative Labs CA0132 card. MFC after: 1 week Reviewed by: christos Differential Revision: https://reviews.freebsd.org/D55605
* sound: Notify devd when no devices are connectedChristos Margiolis13 days1-0/+2
| | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D55531
* sound: Notify devd on hw.snd.default_unit changeChristos Margiolis13 days1-0/+7
| | | | | | | | | | | | | | | If we have virtual_oss running, this devd notification will make sure to automatically transfer sound to the new default unit, while also making sure that we switch to it only for the supported directions (recording and/or playback). For more information, please refer to 2ffaca551eaf ("snd_hda: Implement automatic redirection between associations"). Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D55530
* chore: replace {0, 0} with {DEV,KOBJ}METHOD_ENDEnji Cooper2026-02-2523-29/+29
| | | | | | | | | | | | | | Both of the aforementioned macros have been present in FreeBSD for well over a decade: 2009 for `KOBJMETHOD_END`; 2011 for `DEVMETHOD_END`. Adapt all hardcoded references of `{0, 0}` with `DEVMETHOD_END` and `KOBJMETHOD_END` as appropriate. This helps ensure that future adaptations to drivers following patterns documented in driver(9) can be made more easily/without issue. MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D55414
* sound: Detect unsupported formatsChristos Margiolis2026-02-211-1/+15
| | | | | | | | | | | This way we can avoid edge-cases like 8af6aee96ed609456900c6dd92dafabac5e89c0a ("virtual_oss(8): Remove floating point formats from preference list"). Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D55403
* bus: Document special ranges of IVARsJohn Baldwin2026-02-171-1/+1
| | | | | | | | | | | | | Some IVAR indices are special in that they have global meaning across multiple buses where as other IVARs are always private to the local bus. Try to document this a bit and add constants for the various ranges to avoid future conflicts. This is a no-op, but IVAR indices are now generally defined as enums as that makes it easier to define them in terms of ranges. Reviewed by: imp, royger, andrew Differential Revision: https://reviews.freebsd.org/D54159
* sound: Replace MIN() with min()Christos Margiolis2026-01-125-12/+12
| | | | | | | | | We use min() in most places. No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Unlock around uiomove() in midi_{read,write}()Christos Margiolis2026-01-121-2/+6
| | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54130
* sound: Merge chn_intr() with chn_intr_locked()Christos Margiolis2026-01-022-19/+2
| | | | | | | | | | | | There is no scenario where chn_intr() is called with the channel lock already held. No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D53854
* snd_uaudio: Do not use pcm_channel->lock to protect uaudio_chanChristos Margiolis2026-01-021-15/+12
| | | | | | | | | | | This is a layering violation, but it also makes the control flow confusing; snd_uaudio(4) should have its own lock to protect its structures. Fixes: 5cc34a83e1 ("Revert "sound: Merge chn_intr() with chn_intr_locked()"") Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54102
* sound: Retire unused snd_midi->nameChristos Margiolis2026-01-021-1/+0
| | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Allocate mpu401 with M_WAITOKChristos Margiolis2026-01-021-4/+1
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Get rid of unused MIDIQ macrosChristos Margiolis2026-01-021-2/+0
| | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Make mpu_if definitions staticChristos Margiolis2026-01-021-3/+3
| | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire mpu_callbackp()Christos Margiolis2026-01-023-15/+1
| | | | | | | | | It is the exact same as mpu_callback(). No functional changed intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Get rid of unused midi/midi.c definesChristos Margiolis2026-01-021-13/+0
| | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Do not check for NULL before free()Christos Margiolis2026-01-0220-95/+47
| | | | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54174
* sound: Take device type into account in sndstatChristos Margiolis2026-01-023-46/+47
| | | | | | | | | | sndstat will be extended to work with MIDI devices as well, so separate functionality based on the device type. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54141
* sound: Move sndstat out of pcm/Christos Margiolis2026-01-024-5/+41
| | | | | | | | | Needed by follow-up patches that will add sndstat support for midi/ Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54140
* sound: Improve snd_midi->{in,out}q allocationChristos Margiolis2026-01-021-16/+8
| | | | | | | | | | | | | Currently we lock and allocate the buffers with M_NOWAIT, without checking if the return value of malloc(). This is not necessary as subsequent check below will eventually check that. However, for correctness, allocate the buffers with M_WAITOK (there is no reason not to) and lock afterwards. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54131
* sound: Retire MIDIQ_DEBUGChristos Margiolis2026-01-021-17/+0
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire MIDI_DEBUGChristos Margiolis2026-01-021-39/+1
| | | | | | | Better logging will be implemented. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Rename midi_cdevsw name to "midi"Christos Margiolis2026-01-021-2/+2
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Remove dead if-statementChristos Margiolis2026-01-021-1/+0
| | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire snd_midi->busyChristos Margiolis2026-01-021-24/+7
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Merge midi_destroy() with midi_uninit()Christos Margiolis2026-01-021-43/+14
| | | | | | | | | | Also always call MPU_UNINIT(). It does not make sense not to if we are deallocating everything. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54192
* sound: Update midi/midi.* LICENSEChristos Margiolis2026-01-022-0/+8
| | | | | Spsonsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire snd_midi->qlockChristos Margiolis2026-01-021-38/+22
| | | | | | | | | | | | snd_midi->qlock is used to protect snd_midi->{in,out}q. However, apart from the numerous LORs present already in the code, there is no reason not to use snd_midi->lock, as we do for the rest of the structure Started by: https://github.com/freebsd/freebsd-src/pull/1902 Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: dev_nicolas-provost.fr Differential Revision: https://reviews.freebsd.org/D54129
* snd_dummy: Initial MIDI supportChristos Margiolis2026-01-021-0/+47
| | | | | | | | | | Because testing the midi/ code of sound(4) requires a physical MIDI device, add some basic MIDI support to snd_dummy(4) so that we can test patches to midi/ easier. Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54127
* sound: Retire midi_devs and mstat_lockChristos Margiolis2026-01-023-113/+26
| | | | | | | | | | | | | | | | | | | Nowadays midi_devs only has two uses: 1. To verify in midi_init() if a given device unit exists, as well as to calculate the next device unit. Instead, make sure we always get a unique unit and channel number using unr(9). 2. To keep track of all midi devices, so that it can destroy them all at once in midi_sysuninit(). However, since we stopped building midi as a kernel module, there is no reason to do that, simply let the drivers tear down the devices themselves. Also retire mstat_lock since it's only used to protect midi_devs. PR: 261071 Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D54126
* sound: Stop building midi as a moduleChristos Margiolis2026-01-021-37/+7
| | | | | | | | | | | There is no reason for this. The midi functions are used by drivers on-demand anyway. Use SYSINIT(9) instead to do the appropriate (de-)initilizations. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54125
* sound: Get rid of unnecessary breaksChristos Margiolis2026-01-026-13/+0
| | | | | | | No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire unused pcm_feeder->alignChristos Margiolis2026-01-021-2/+0
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Update pcm/feeder.h LICENSEChristos Margiolis2026-01-021-0/+4
| | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire pcm_feeder->desc_staticChristos Margiolis2026-01-0210-56/+54
| | | | | | | | | Not sure what the value of this was. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D54103
* snd_hda: Default to 256 when corb/rirb is invalidChristos Margiolis2026-01-021-4/+10
| | | | | | | | PR: 289284 Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: emaste Differential Revision: https://reviews.freebsd.org/D54339
* bus_alloc_resource: Pass rid by value to BUS_ALLOC_RESOURCE DEVMETHODJohn Baldwin2025-12-092-6/+6
| | | | | | | | | The wrapper functions such as bus_alloc_resource_any() still support passing the rid by value or pointer, but the underlying implementation now passes by value. Reviewed by: imp Differential Revision: https://reviews.freebsd.org/D53402
* sound: Retire snd_mixer->busyChristos Margiolis2025-11-283-35/+1
| | | | | | | | | | | | | | | | | Does not really serve any real purpose. It gets set on mixer_open() and unset on mixer_close(), so it essentially tells us whether the mixer is open or not. mixer_close() uses it to return EBADF in case the mixer is not busied, as in, the mixer has not been open()'d yet. This is redundant. The other place where this is used is to decide whether to serve an ioctl issued by userland, in which case it won't if, again, the mixer has not been busied (i.e., opened). Again, seems redundant. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53859
* sound: Fix revents in midi_poll()Nicolas Provost2025-11-241-11/+9
| | | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: christos Pull Request: https://github.com/freebsd/freebsd-src/pull/1887
* Revert "sound: Merge chn_intr() with chn_intr_locked()"Christos Margiolis2025-11-232-2/+19
| | | | | | | | | It turns out that snd_uaudio(4) uses sound(4)'s channel lock for its USB transfer callbacks. I will try to address this at some point, because this is layering violation, but for now we need to revert the commit, as it causes a lock recursion panic with USB audio devices. This reverts commit e254ef87a30bfcaabc6e4d8e0ecf05f6949a4f06.
* sound: Retire snd_mtx* wrappersChristos Margiolis2025-11-2134-556/+512
| | | | | | | | | | | | Do not create mutexes with snd_mtxcreate(). It doesn't provide any value, plus it first allocates the mutex with malloc(9). Allocate mutexes in the stack and use mtx_* functions directly instead of the snd_mtx* wrappers. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D53855
* sound: Merge chn_intr() with chn_intr_locked()Christos Margiolis2025-11-212-19/+2
| | | | | | | | | | | | There is no scenario where chn_intr() is called with the channel lock already held. No functional change intended. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: kib, markj Differential Revision: https://reviews.freebsd.org/D53854
* sound: Merge PCM_ALIVE() with PCM_REGISTERED()Christos Margiolis2025-11-212-3/+3
| | | | | | | | | PCM_ALIVE() is used only in pcm_unregister(), but it does not hurt to use PCM_REGISTERED(), which uses PCM_ALIVE() internally. In fact, it's more robust this way. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Clean up midi/ includesChristos Margiolis2025-11-212-23/+11
| | | | | | Sponsored by: The FreeBSD Foundation MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D53841
* sound: Simplify logic in dsp_io_ops()Christos Margiolis2025-11-211-22/+10
| | | | | | | | | | | | | | | | | | | | | | Use CHN_LOCK()/CHN_UNLOCK() directly, instead of dsp_lock_chans()/dsp_unlock_chans(). These functions are useful when we want to potentially lock both channels. Here we know which channel we are locking, so we can just lock it directly. This way we get rid of the prio variable as well. Related to runpid again, there is no reason to assign it when CHN_F_RUNNING is not set. channel->pid (as well as channel->comm) is always assigned in dsp_chn_alloc(). Get rid of runpid. I do not see how we can end up with channel->pid (td->td_proc->p_pid) not matching buf->uio_td->td_proc->p_pid. Also improve errno values. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: markj Differential Revision: https://reviews.freebsd.org/D53736
* sound: Remove vchan_passthrough() and hw.snd.passthrough_verboseChristos Margiolis2025-11-202-23/+0
| | | | | | | Unused and confusing. Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Fix KASSERT panics in chn_read() and chn_write()Christos Margiolis2025-11-201-48/+22
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | INVARIANTS kernels may trigger a KASSERT panic from sndbuf_acquire(), when fuzzing write(2) using stress2, because of a race in chn_write(). In the case of chn_write(), what sndbuf_acquire() does is extend the ready-to-read area of the buffer by a specified amount of bytes. The KASSERT in question makes sure the number of bytes we want to extend the ready area by, is less than or equal to the number of free bytes in the buffer. This makes sense, because we cannot extend the ready area to something larger than what is available (i.e., free) in the first place. What chn_write() currently does for every write is; calculate the appropriate write size, let's say X, unlock the channel, uiomove() X bytes to the channel's buffer, lock the channel, and call sndbuf_acquire() to extend the ready area by X bytes. The problem with this approach, however, is the following. Suppose an empty channel buffer with a length of 1024 bytes, and 2 threads, (A) and (B), where (B) is a higher-priority one. Suppose thread (A) wants to write 1024 bytes. It unlocks the channel and uiomove()s 1024 bytes to the channel buffer. At the same time, thread (B) picks up the lock, and because it is higher priority, it keeps dominating the lock for a few iterations. By the time thread (A) picks up the lock again, it tries to call sndbuf_acquire() with a size of 1024 bytes, which was calculated before it performed the uiomove(). In this case, there is a very high chance that the buffer will not be empty, that is, have a free area of 1024 bytes, as was the case when thread (A) started executing, and so the KASSERT will trigger a panic because the condition (bytes <= free) is not met. Another scenario that can trigger a panic is the following: suppose a buffer with a size of 4 bytes, and two threads: (A) and (B). In the first iteration, thread (A) wants to write 2 bytes, while the buffer is empty, BUT the pointer (sndbuf_getfreeptr()) is at the end (i.e., buf[3]). In the first iteration of the loop, because of the way we calculate t, we'll end up writing only 1 byte, so after sz -= t, sz will be 1, and so we'll need one more iteration in the inner loop, to write the remaining 1 byte. Now we're at the end of the first loop, thread (A) unlocks the channel, it has written 1 byte, it needs to write 1 more, and the buffer is left with 3 empty slots. Now thread (B) picks up the lock, and it wants to write 3 (or more) bytes. Eventually it writes the 3 bytes, and it leaves the buffer with 0 free slots. By the time thread (A) picks up the lock again, and continues with the second iteration of the inner loop, it will try to write the last byte, but sndbuf_acquire() will panic because there is no free space anymore. To fix this, get rid of the inner loop and calculate the write size on each iteration. Also, call sndbuf_acquire() before unlocking the channel. In the scenarios explained above, we'll end up entering the chn_sleep() case. Modify it as well, so that we do not kill the channel if we need to sleep more. Do the same for chn_read() to avoid possible similar panics from sndbuf_dispose(). Reported by: pho Tested by: christos, pho Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: pho, kib Differential Revision: https://reviews.freebsd.org/D53666
* snd_hda: Patch Lenovo V15Christos Margiolis2025-11-172-1/+3
| | | | | | | PR: 290496 Tested by: adrian Sponsored by: The FreeBSD Foundation MFC after: 1 week
* sound: Retire SND_DIAGNOSTIC PCM locking macrosChristos Margiolis2025-11-131-103/+0
| | | | | | | | | | Disabled by default, but also redundant, since most of the errors they catch will be caught anyway by WITNESS and the locking subsystem. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D53735
* sound: Do not use double pointer in dsp_io_ops()Christos Margiolis2025-11-131-13/+13
| | | | | | | | | No reason to do so. Sponsored by: The FreeBSD Foundation MFC after: 1 week Reviewed by: kib Differential Revision: https://reviews.freebsd.org/D53734