History log of /freebsd-current/sys/dev/sound/pcm/sound.h
Revision Date Author Comments
# 7ad5f383 06-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Move vchan-related code to pcm/vchan.*

pcm/sound.* contains code that should be part of pcm/vchan.*.

Changes:
- pcm_setvchans() -> vchan_setnew()
- pcm_setmaxautovchans() -> vchan_setmaxauto()
- hw.snd.maxautovchans moved to pcm/vchan.c
- snd_maxautovchans declaration moved to pcm/vchan.h and definition to
pcm/vchan.c

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D45015


# 72cbd381 06-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Remove unused dsp_cdevs[] fields and devices

These fields and devices are unused as of e8c0d15a64fa ("sound: Get rid
of snd_clone and use DEVFS_CDEVPRIV(9)").

While here, remove unused SND_DEV_* defines from pcm/sound.h and convert
the list to an enum.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D45013


# 923e0040 06-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Move chip.h contents to pcm/sound.h

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44997


# 139bcec8 06-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Convert pcm_chn_add() to void

It always returns 0.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D44998


# 2e9962ef 06-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Merge pcm_chn_create() and chn_init()

Follow-up of b3ea087c05d8c75978a302cbb3fa92ce1afa3e49 ("sound: Merge
pcm_chn_destroy() and chn_kill()")

While here, add device_printf()'s to all failure points. Also fix an
existing bug where we'd unlock an already unlocked channel, in case we
went to "out" (now "out2") before locking the channel.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D44993


# a24050e2 28-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Move pcm_chnref() and pcm_chnrelease() to pcm/channel.c

Improve code layering. These are channel functions, and so they do not
belong in pcm/sound.c.

While here, assert in chn_ref() that new refcount won't be negative.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44985


# b3ea087c 28-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Merge pcm_chn_destroy() and chn_kill()

pcm_chn_destroy() acts like a wrapper around chn_kill(), and
additionally calls a few more functions that should in fact be part of
chn_kill()'s logic. Merge pcm_chn_destroy()'s functionality in
chn_kill() to improve readability, as well as code layering.

While here, convert chn_kill() to void as it currently always returns 0.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44984


# 25723d66 28-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Retire unit.*

The unit.* code is largely obsolete and imposes limits that are no
longer needed nowadays.

- Capping the maximum allowed soundcards in a given machine. By default,
the limit is 512 (snd_max_u() in unit.c), and the maximum possible is
2048 (SND_UNIT_UMAX in unit.h). It can also be tuned through the
hw.snd.maxunit loader(8) tunable. Even though these limits are large
enough that they should never cause problems, there is no need for
this limit to exist in the first place.
- Capping the available device/channel types. By default, this is 32
(snd_max_d() in unit.c). However, these types are pre-defined in
pcm/sound.h (see SND_DEV_*), so the cap is unnecessary when we know
that their number is constant.
- Capping the number of channels per-device. By default, the limit 1024
(snd_max_c() in unit.c). This is probably the most problematic of the
limits mentioned, because this limit can never be reached, as the
maximum is hard-capped at either hw.snd.maxautovchans (16 by default),
or SND_MAXHWCHAN and SND_MAXVCHANS.

These limtits are encoded in masks (see SND_U_MASK, SND_D_MASK,
SND_C_MASK in unit.h) and are used to construct a bitfield of the form
[dsp_unit, type, channel_unit] in snd_mkunit() which is assigned to
pcm_channel->unit.

This patch gets rid of everything unit.*-related and makes a slightly
different use of the "unit" field to only contain the channel unit
number. The channel type is stored in a new pcm_channel->type field, and
the DSP unit number need not be stored at all, since we can fetch it
from device_get_unit(pcm_channel->dev). This change has the effect that
we no longer need to impose caps on the number of soundcards,
device/channel types and per-device channels. As a result the code is
noticeably simplified and more readable.

Apart from the fact that the hw.snd.maxunit loader(8) tunable is also
retired as a side-effect of this patch, sound(4)'s behavior remains the
same.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D44912


# 1b82d425 18-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Remove obsolete DV_F_* flags

The ISA sound drivers that used them are retired.

Last reference of DV_F_DRQ_MASK and DV_F_DUAL_DMA:
716924cb4832ea0a440daf09913a06f3166f243e ("Retire snd_sbc ISA sound card
driver")

Last reference of DV_F_DEV_MASK and DV_F_DEV_SHIFT:
5126e5eeeb5e07ceef3c809452a8c9f508b2d4d1 ("Retire snd_mss ISA sound card
driver")

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D44858


# 8b97dce6 18-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Remove PCMMINOR()

It's a NO-OP.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj, emaste
Differential Revision: https://reviews.freebsd.org/D44854


# 4d2be7be 18-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Get rid of snddev_info->devcount

snddev_info->devcount keeps track of the total number of channels for a
given device. However, it is redundant to have it, since it is only used
in sound_oss_sysinfo() to populate the "numaudios" field, and we also
keep track of the channel counts in the playcount, pvchancount, reccount
and rvchancount fields anyway. We can simply sum those fields together
instead of updating a separate variable upon every channel
addition/deletion.

Sponsored by: The FreeBSD Foundation
MFC after: 1 week
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44852


# e8c0d15a 11-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Get rid of snd_clone and use DEVFS_CDEVPRIV(9)

Currently the snd_clone framework creates device nodes on-demand for
every channel, through the dsp_clone() callback, and is responsible for
routing audio to the appropriate channel(s). This patch gets rid of the
whole snd_clone framework (including any related sysctls) and instead
uses DEVFS_CDEVPRIV(9) to handle device opening, channel allocation and
audio routing. This results in a significant reduction in code size as
well as complexity.

Behavior that is preserved:

- hw.snd.basename_clone.
- Exclusive access of an audio device (i.e VCHANs disabled).
- Multiple processes can read from/write to the device.
- A device can only be opened as many times as the maximum allowed
channel number (see SND_MAXHWCHAN in pcm/sound.h).
- OSSv4 compatibility aliases are preserved.

Behavior changes:

Only one /dev/dspX device node is created (on attach) for each audio
device, as opposed to the current /dev/dspX.Y devices created by
snd_clone. According to the sound(4) man page, devices are not meant to
be opened through /dev/dspX.Y anyway, so it is best if we do not create
device nodes for them in the first place. As a result of this, modify
dsp_oss_audioinfo() to print /dev/dspX in the "ai->devnode", instead of
/dev/dspX.Y.

Sponsored by: The FreeBSD Foundation
MFC after: 2 months
Reviewed by: dev_submerge.ch, bapt, markj
Differential Revision: https://reviews.freebsd.org/D44411


# c0d8f586 04-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

Revert "sound: Get rid of snd_clone and use DEVFS_CDEVPRIV(9)"

This reverts commit dc831e93bad63f9faea09f1806a7733a40bff316.

After several reports in the mailing lists, this commit breaks
pulseaudio. Revert until the issue is resolved.


# 9da3b645 02-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Move sndstat_prepare_pcm() to pcm/sndstat.c and remove sndstat_entry->handler

Since all sndstat_entry->handler fields point to sndstat_prepare_pcm(),
we can just call the function directly, without assigning it to a
function pointer and calling it indirectly.

While here, move sndstat_prepare_pcm() to pcm/sndstat.c, as it is more
suitable there.

No functional change intended.

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D44571


# dc831e93 30-Mar-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Get rid of snd_clone and use DEVFS_CDEVPRIV(9)

Currently the snd_clone framework creates device nodes on-demand for
every channel, through the dsp_clone() callback, and is responsible for
routing audio to the appropriate channel(s). This patch gets rid of the
whole snd_clone framework (including any related sysctls) and instead
uses DEVFS_CDEVPRIV(9) to handle device opening, channel allocation and
audio routing. This results in a significant reduction in code size as
well as complexity.

Behavior that is preserved:

- hw.snd.basename_clone.
- Exclusive access of an audio device (i.e VCHANs disabled).
- Multiple processes can read from/write to the device.
- A device can only be opened as many times as the maximum allowed
channel number (see SND_MAXHWCHAN in pcm/sound.h).
- OSSv4 compatibility aliases are preserved.

Behavior changes:

Only one /dev/dspX device node is created (on attach) for each audio
device, as opposed to the current /dev/dspX.Y devices created by
snd_clone. According to the sound(4) man page, devices are not meant to
be opened through /dev/dspX.Y anyway, so it is best if we do not create
device nodes for them in the first place. As a result of this, modify
dsp_oss_audioinfo() to print /dev/dspX in the "ai->devnode", instead of
/dev/dspX.Y.

Sponsored by: The FreeBSD Foundation
MFC after: 2 months
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D44411


# b5e55dbf 29-Mar-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Remove unused SND_DEV_LAST and SND_DEV_MAX constants

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44554


# c136e618 29-Mar-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Fix SND_DIAGNOSTIC ifdef comment

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44555


# 883b8ed5 12-Feb-2024 Christos Margiolis <christos@FreeBSD.org>

sound: remove snddev_info->inprog and pcm_inprog()

No longer used.

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D43737


# 837cd192 16-Jan-2024 Christos Margiolis <christos@FreeBSD.org>

sound: remove PCM_KLDSTRING() and fix status strings

PCM_KLDSTRING() prints the kernel module associated with a given audio
device only when that module is not compiled in. Get rid of
PCM_KLDSTRING() altogether and print the driver name (even for modules
that are compiled in) instead, as it implies the module as well.

While here, convert all status strings to the following dmesg-like
format:

[<port|mem> <irq>] on <driver>

Sponsored by: The FreeBSD Foundation
MFC after: 2 weeks
Reviewed by: markj, imp
Differential Revision: https://reviews.freebsd.org/D43349


# 5aacf339 18-Aug-2023 John Baldwin <jhb@FreeBSD.org>

sys: Remove SND_DECLARE_FILE

Reviewed by: kbowling, imp, emaste
Differential Revision: https://reviews.freebsd.org/D41499


# cbe53bd9 18-Aug-2023 John Baldwin <jhb@FreeBSD.org>

pcm: Turn SND_DECLARE_FILE into a no-op.

SND_DECLARE_FILE originally added lines to the output of /dev/sndstat
listing the $FreeBSD$ strings for individual files, but only if the
value of hw.snd.verbose was raised to 3. With the switch to Git these
strings became meaningless as they were now all identical and no longer
contained the path (which was implicitly included previously via the
keyword expansion).

This commit removes all of the infrastructure to support file version
strings from /dev/sndstat, but preserves the KPI/KBI by turning the
SND_DECLARE_FILE macro into a nop and changing the backing sysinit
functions into null functions and is suitable for merging to
stable/13.

A future commit will remove SND_DECLARE_FILE entirely.

Reviewed by: kbowling, emaste
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D41498


# 95ee2897 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: two-line .h pattern

Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/


# 4d846d26 10-May-2023 Warner Losh <imp@FreeBSD.org>

spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD

The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with: pfg
MFC After: 3 days
Sponsored by: Netflix


# ed2196e5 28-Jul-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

sound(4): Implement playback and recording mode sysctl(8).

The dev.pcm.<N>.mode sysctl(8) gives information if a sound device
supports hardware mixing, playback or recording.

Submitted by: Christos Margiolis <christos@freebsd.org>
Differential Revision: https://reviews.freebsd.org/D31320
MFC after: 1 week
Sponsored by: NVIDIA Networking


# c96151d3 17-Mar-2021 Ka Ho Ng <khng@FreeBSD.org>

Implement sndstat nvlist-based enumeration ioctls.

These ioctl commands aim to provide easier ways for user space
applications to enumerate existing audio devices and the node they can
potentially use.

The exchange of device lists between user space and kernel is done on
nv(9). Some ioctl commands are added to /dev/sndstat node:
- SNDSTAT_REFRESH_DEVS
- SNDSTAT_GET_DEVS
- SNDSTAT_ADD_USER_DEVS
- SNDSTAT_FLUSH_USER_DEVS

Bump __FreeBSD_version to reflect the addition of the ioctls.

Sponsored by: The FreeBSD Foundation
Reviewed by: hselasky
Approved by: philip (mentor)
Differential Revision: https://reviews.freebsd.org/D26884


# 378503af 01-Sep-2020 Mateusz Guzik <mjg@FreeBSD.org>

sound: clean up empty lines in .c and .h files


# cc1efc23 04-Mar-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Implement a detaching flag for the sound(4) subsystem to take
appropriate actions when we are trying to detach an audio device,
but cannot because someone is using it.

This avoids applications having to wait for the DSP read data
timeout before they receive any error indication.
Tested with virtual_oss(8).

Remove some unused definitions while at it.

PR: 194727
MFC after: 1 week
Sponsored by: Mellanox Technologies


# e2e050c8 19-May-2019 Conrad Meyer <cem@FreeBSD.org>

Extract eventfilter declarations to sys/_eventfilter.h

This allows replacing "sys/eventfilter.h" includes with "sys/_eventfilter.h"
in other header files (e.g., sys/{bus,conf,cpu}.h) and reduces header
pollution substantially.

EVENTHANDLER_DECLARE and EVENTHANDLER_LIST_DECLAREs were moved out of .c
files into appropriate headers (e.g., sys/proc.h, powernv/opal.h).

As a side effect of reduced header pollution, many .c files and headers no
longer contain needed definitions. The remainder of the patch addresses
adding appropriate includes to fix those files.

LOCK_DEBUG and LOCK_FILE_LINE_ARG are moved to sys/_lock.h, as required by
sys/mutex.h since r326106 (but silently protected by header pollution prior
to this change).

No functional change (intended). Of course, any out of tree modules that
relied on header pollution for sys/eventhandler.h, sys/lock.h, or
sys/mutex.h inclusion need to be fixed. __FreeBSD_version has been bumped.


# 718cf2cc 27-Nov-2017 Pedro F. Giffuni <pfg@FreeBSD.org>

sys/dev: further adoption of SPDX licensing ID tags.

Mainly focus on files that use BSD 2-Clause license, however the tool I
was using misidentified many licenses so this was mostly a manual - error
prone - task.

The Software Package Data Exchange (SPDX) group provides a specification
to make it easier for automated tools to detect and summarize well known
opensource licenses. We are gradually adopting the specification, noting
that the tags are considered only advisory and do not, in any way,
superceed or replace the license texts.


# 8461d581 09-Feb-2016 Hans Petter Selasky <hselasky@FreeBSD.org>

To support userspace audio daemons like Virtual OSS, /dev/sndstat is
made writeable by the root user. Userspace audio daemons can add or
update an entry in /dev/sndstat by doing a single system write call to
any /dev/sndstat file descriptor handle. When the audio daemon closes the
file handle or is killed the entry disappears.

While at it, cleanup the sound status code a bit:
- keep the device list sorted to avoid sorting the list every time a
/dev/sndstat read request is made.
- factor out locking into a pair of locking macros.
- use the sound status lock to protect all per file handle states,
when generating the output for /dev/sndstat and when removing or
adding sound status devices. This way sndstat_acquire() and
sndstat_release() become superfluous and can be removed.

Reviewed by: mav @
Differential Revision: https://reviews.freebsd.org/D5191


# 4ece1a88 08-May-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Extend the maximum number of allowed PCM channels in a PCM stream to
127 and decrease the maximum number of sub-channels to 1. These
definitions are only used inside the kernel and can be changed later
if more than one sub-channel is desired. This has been done to allow
so-called USB audio rack modules to work with FreeBSD.

Bump the FreeBSD version to force recompiling all external modules.

MFC after: 2 weeks
Reviewed by: mav


# 775fcb6e 03-Nov-2014 Baptiste Daroussin <bapt@FreeBSD.org>

Remove check for obsolete FreeBSD versions

PR: 194517
Submitted by: François Tigeot <ftigeot@wolfpond.org>


# a7d5f7eb 19-Oct-2010 Jamie Gritton <jamie@FreeBSD.org>

A new jail(8) with a configuration file, to replace the work currently done
by /etc/rc.d/jail.


# 5870e3c9 11-Jun-2009 Ariff Abdullah <ariff@FreeBSD.org>

Remove custom KOBJMETHOD(), CHANNEL_DECLARE() and MIXER_DECLARE()
(enabled with SND_DEBUG) that was intended to provoke build failure
due to inconsistencies.


# 5cda20cf 09-Jun-2009 Ariff Abdullah <ariff@FreeBSD.org>

Move machine dependant AFMT_* definition from sound.h
to global soundcard.h .


# 90da2b28 07-Jun-2009 Ariff Abdullah <ariff@FreeBSD.org>

Sound Mega-commit. Expect further cleanup until code freeze.

For a slightly thorough explaination, please refer to
[1] http://people.freebsd.org/~ariff/SOUND_4.TXT.html .

Summary of changes includes:

1 Volume Per-Channel (vpc). Provides private / standalone volume control
unique per-stream pcm channel without touching master volume / pcm.
Applications can directly use SNDCTL_DSP_[GET|SET][PLAY|REC]VOL, or for
backwards compatibility, SOUND_MIXER_PCM through the opened dsp device
instead of /dev/mixer. Special "bypass" mode is enabled through
/dev/mixer which will automatically detect if the adjustment is made
through /dev/mixer and forward its request to this private volume
controller. Changes to this volume object will not interfere with
other channels.

Requirements:
- SNDCTL_DSP_[GET|SET][PLAY|REC]_VOL are newer ioctls (OSSv4) which
require specific application modifications (preferred).
- No modifications required for using bypass mode, so applications
like mplayer or xmms should work out of the box.

Kernel hints:
- hint.pcm.%d.vpc (0 = disable vpc).

Kernel sysctls:
- hw.snd.vpc_mixer_bypass (default: 1). Enable or disable /dev/mixer
bypass mode.
- hw.snd.vpc_autoreset (default: 1). By default, closing/opening
/dev/dsp will reset the volume back to 0 db gain/attenuation.
Setting this to 0 will preserve its settings across device
closing/opening.
- hw.snd.vpc_reset (default: 0). Panic/reset button to reset all
volume settings back to 0 db.
- hw.snd.vpc_0db (default: 45). 0 db relative to linear mixer value.

2 High quality fixed-point Bandlimited SINC sampling rate converter,
based on Julius O'Smith's Digital Audio Resampling -
http://ccrma.stanford.edu/~jos/resample/. It includes a filter design
script written in awk (the clumsiest joke I've ever written)
- 100% 32bit fixed-point, 64bit accumulator.
- Possibly among the fastest (if not fastest) of its kind.
- Resampling quality is tunable, either runtime or during kernel
compilation (FEEDER_RATE_PRESETS).
- Quality can be further customized during kernel compilation by
defining FEEDER_RATE_PRESETS in /etc/make.conf.

Kernel sysctls:
- hw.snd.feeder_rate_quality.
0 - Zero-order Hold (ZOH). Fastest, bad quality.
1 - Linear Interpolation (LINEAR). Slightly slower than ZOH,
better quality but still does not eliminate aliasing.
2 - (and above) - Sinc Interpolation(SINC). Best quality. SINC
quality always start from 2 and above.

Rough quality comparisons:
- http://people.freebsd.org/~ariff/z_comparison/

3 Bit-perfect mode. Bypasses all feeder/dsp effects. Pure sound will be
directly fed into the hardware.

4 Parametric (compile time) Software Equalizer (Bass/Treble mixer). Can
be customized by defining FEEDER_EQ_PRESETS in /etc/make.conf.

5 Transparent/Adaptive Virtual Channel. Now you don't have to disable
vchans in order to make digital format pass through. It also makes
vchans more dynamic by choosing a better format/rate among all the
concurrent streams, which means that dev.pcm.X.play.vchanformat/rate
becomes sort of optional.

6 Exclusive Stream, with special open() mode O_EXCL. This will "mute"
other concurrent vchan streams and only allow a single channel with
O_EXCL set to keep producing sound.

Other Changes:
* most feeder_* stuffs are compilable in userland. Let's not
speculate whether we should go all out for it (save that for
FreeBSD 16.0-RELEASE).
* kobj signature fixups, thanks to Andriy Gapon <avg@freebsd.org>
* pull out channel mixing logic out of vchan.c and create its own
feeder_mixer for world justice.
* various refactoring here and there, for good or bad.
* activation of few more OSSv4 ioctls() (see [1] above).
* opt_snd.h for possible compile time configuration:
(mostly for debugging purposes, don't try these at home)
SND_DEBUG
SND_DIAGNOSTIC
SND_FEEDER_MULTIFORMAT
SND_FEEDER_FULL_MULTIFORMAT
SND_FEEDER_RATE_HP
SND_PCM_64
SND_OLDSTEREO

Manual page updates are on the way.

Tested by: joel, Olivier SMEDTS <olivier at gid0 d org>, too many
unsung / unnamed heroes.


# 999da778 27-May-2009 Joel Dahl <joel@FreeBSD.org>

Slightly adjust copyright text.

Approved by: Hannu Savolainen <hannu@opensound.com>


# 52f6e09e 10-Jan-2009 Alexander Motin <mav@FreeBSD.org>

Import some new constants and structures fields from OSSv4.
Implement some OSSv4 ioctls to make ossinfo tool work and print
something reasonable.


# d7f03759 19-Oct-2008 Ulf Lilleengen <lulf@FreeBSD.org>

- Import the HEAD csup code which is the basis for the cvsmode work.


# e5bfdc76 19-Aug-2008 Ed Schouten <ed@FreeBSD.org>

Don't include <sys/tty.h> in our sound layer. It is not needed.

The PCM's sound.h file only seems to include <sys/tty.h>, because
channel_if seems to require selinfo. Just replace it with
<sys/selinfo.h>.

There's no real problem with including <sys/tty.h> here, even with
MPSAFE TTY, but <sys/tty.h> is something that should be used by the TTY
layer, its driver and code that integrated it with the process tree.


# e4e61333 15-Jun-2007 Ariff Abdullah <ariff@FreeBSD.org>

Last (again ?!?) major commit for RELENG_7, featuring total Giant
eradication in/from userland path, countless locking fixes, etc.

- General sleep call through msleep(9) has been converted to condvar(9)
with better consistencies.
- Heavily guard every possible "slow path" entries (open(), close(),
few ioctl()s, sysctls), but once it entering "fast path" (io, interrupt
started), they are free to fly on their own.
- Rearrange locking sequences, resulting better concurrency and
serialization. Large part doesn't even need locking at all, and will be
removed in future. Less clutter, except in few places due to lock
ordering.
- Anonymous mixer object creation/deletion to simplify mixer handling
beyond typical mixer ioctls.
Submitted by: chibis (with modifications)
- Add few mix_[get|set|..] functions to avoid calling mixer_ioctl()
directly using cryptic arguments.
- Locking fixes to avoid possible deadlock with (still under Giant) USB.
- Better simplex/duplex device handling.
- Recover mmap() functionality for recording, which has been lost
since 2.2.x - 3.x (the introduction of newpcm). Full-duplex mmap still
doesn't work (due to VM/page design), but people still can mmap
both by opening each direction separately. mmaped playback is guarantee
to work either way.
- New sysctl: "hw.snd.compat_linux_mmap" to allow PROT_EXEC page
mapping, due to recent changes in linux compatibility layer which
require it. All linux applications that using sound + mmap() (mostly games)
require this to be enabled. Disabled by default.
- Other goodies.. too many, that will increase releng7 shareholder value
and make users of releng6 (and below) cry ;)

* This commit should be atomic. If anything goes wrong (not counting problem
originated from elsewhere), I will not hesitate to revert everything back
within 12 hours. This substantial changes itself not a rocket science
and the process has begun for almost 2 years, and lots of incremental
changes are already in place during that period of time.
* Some issues does occur in snd_emu10kx (note the 'x') due to various
internal locking issues and it is currently being worked on by chibis.

Tested by: chibis (Yuriy Tsibizov), joel, Alexandre Vieira,
many innocent souls...


# bba4862c 31-May-2007 Ariff Abdullah <ariff@FreeBSD.org>

Last major commit and updates for RELENG_7:

- Rework the entire pcm_channel structure:
* Remove rarely used link placeholder, instead, make each pcm_channel
as head/link of each own/each other. Unlock - Lock sequence due to
sleep malloc has been reduced.
* Implement "busy" queue which will contain list of busy/active
channels. This greatly reduce locking contention for example while
servicing interrupt for hardware with many channels or when virtual
channels reach its 256 peak channels.

- So I heard you like v chan ... O RLY?
Welcome to Virtual **Record** Channels (vrec, rec vchans, vchans for
recording, Rec-Chan, you decide), the ultimate solutions for your
nagging O_RDWR full-duplex wannabe (note: flash plugins) monopolizing
single record channel causing EBUSY. Vrec works exactly like Vchans
(or, should I rename it to "Vplay" :) , except that it operates on the
opposite direction (recording). Up to 256 vrecs (like vchans) are
possible.

Notes:
* Relocate dev.pcm.%d.{vchans,vchanformat,vchanrate} to each of its
respective node/direction:
dev.pcm.%d.play.* for "play" (cdev = dsp%d.vp%d)
dev.pcm.%d.rec.* for "record" (cdev = dsp%d.vr%d)
* Don't expect that it will magically give you ability to split
"recording source" (eg: 1 channel for cdrom, 1 channel for mic,
etc). Just admit that you only have a *single* recording source /
channel. Please bug your hardware vendor instead :)

- Bump maxautovchans from 4 to 16. For a full-fledged multimedia
desktop/workstation with too many soundservers installed (esound,
artsd, jackd, pulse/polypaudio, ding-dong pling plong mudkip fuh fuh,
etc), 4 seems inadequate. There will be no memory penalty here, since
virtual channels are allocate only by demand.

- Nuke/Rework the entire statically created cdev entries. Everything is
clonable through snd own clone manager which designed to withstand many
kind of abusive devfs droids such as:
* while : ; do /bin/test -e /dev/dsp ; done
* jot 16777216 0 | while read x ; do ls /dev/dsp0.$x ; done
* hundreds (could be thousands) concurrent threads/process opening
"/dev/dsp" (previously, this might result EBUSY even with just
3 contesting threads/procs).
o Reusable clone objects (instead of creating new one like there's no
tomorrow) after certain expiration deadline. The clone allocator will
decide whether to reuse, share, or creating new clone.
o Automatic garbage collector.

- Dynamic unit magic allocator. Maximum attached soundcards can be tuned
using tunable "hw.snd.maxunit" (Default to 512). Minimum is 16, and
maximum is 2048.

- ..other fixes, mostly related to concurrency issues.

joel@ will do the manpage updates on sound(4).

Have fun.


# 0e86bad6 06-May-2007 Ariff Abdullah <ariff@FreeBSD.org>

PCMMKMINOR() bit twiddling, so we can have:
- 2048 unique sound cards (dsp0 -> dsp2047)
(used to be 15)
- 32 unique device types (dspW, audio, mixer, sndstat, .. 32th)
(used to be 15)
- 256 unique cloneable devices (dsp%d.0 -> dsp%d.255)
(unchanged)


# e492b759 18-Apr-2007 Ariff Abdullah <ariff@FreeBSD.org>

Break ABI / module compatibility for the upcoming sndbuf_alloc() changes.


# c30ec742 16-Mar-2007 Ariff Abdullah <ariff@FreeBSD.org>

[stage: 4/9]

- Rearrange FEEDER_* constants starting from 0 to 31, so the future
additions will be much easier and consistent.
- Introduce FEEDER_SWAPLR. Few super broken hardwares (found on several
extremely cheap uaudio stick, possibly others) mistakenly wired left
and right channels wrongly, screwing output or input.


# a580b31a 25-Nov-2006 Ariff Abdullah <ariff@FreeBSD.org>

Welcome to Once-a-year Sound Mega-Commit. Enjoy numerous updates and fixes
in every sense.

General
-------

- Multichannel safe, endian safe, format safe
* Large part of critical pcm filters such as vchan.c, feeder_rate.c,
feeder_volume.c, feeder_fmt.c and feeder.c has been rewritten so that
using them does not cause the pcm data to be converted to 16bit little
endian.
* Macrosses for accessing pcm data safely are defined within sound.h in
the form of PCM_READ_* / PCM_WRITE_*
* Currently, most of them are probably limited for mono/stereo handling,
but the future addition of true multichannel will be much easier.

- Low latency operation
* Well, this require lot more works to do not just within sound driver,
but we're heading towards right direction. Buffer/block sizing within
channel.c is rewritten to calculate precise allocation for various
combination of sample/data/rate size. As a result, applying correct
SNDCTL_DSP_POLICY value will achive expected latency behaviour simmilar
to what commercial 4front driver do.
* Signal handling fix. ctrl+c of "cat /dev/zero > /dev/dsp" does not
result long delay.
* Eliminate sound truncation if the sound data is too small.
DIY:
1) Download / extract
http://people.freebsd.org/~ariff/lowlatency/shortfiles.tar.gz
2) Do a comparison between "cat state*.au > /dev/dsp" and
"for x in state*.au ; do cat $x > /dev/dsp ; done"
- there should be no "perceivable" differences.
Double close for PR kern/31445.

CAVEAT: Low latency come with (unbearable) price especially for poorly
written applications. Applications that trying to act smarter
by requesting (wrong) blocksize/blockcount will suffer the most.
Fixup samples/patches can be found at:
http://people.freebsd.org/~ariff/ports/

- Switch minimum/maximum sampling rate limit to "1" and "2016000" (48k * 42)
due to closer compatibility with 4front driver.
Discussed with: marcus@ (long time ago?)

- All driver specific sysctls in the form of "hw.snd.pcm%d.*" have been
moved to their own dev sysctl nodes, notably:
hw.snd.pcm%d.vchans -> dev.pcm.%d.vchans
Bump __FreeBSD_version.

Driver specific
---------------

- Ditto for sysctls.

- snd_atiixp, snd_es137x, snd_via8233, snd_hda
* Numerous cleanups and fixes.
* _EXPERIMENTAL_ polling mode support using simple callout_* mechanisme.
This was intended for pure debugging and latency measurement, but proven
good enough in few unexpected and rare cases (such as problematic shared
IRQ with GIANT devices - USB). Polling can be enabled/disabled through
dev.pcm.0.polling. Disabled by default.

- snd_ich
* Fix possible overflow during speed calibration. Delay final
initialization (pcm_setstatus) after calibration finished.
PR: kern/100169
Tested by: Kevin Overman <oberman@es.net>
* Inverted EAPD for few Nec VersaPro.
PR: kern/104715
Submitted by: KAWATA Masahiko <kawata@mta.biglobe.ne.jp>

Thanks to various people, notably Joel Dahl, Yuriy Tsibizov, Kevin Oberman,
those at #freebsd-azalia @ freenode and others for testing.

Joel Dahl will do the manpage update.


# 7699548f 28-Sep-2006 Ariff Abdullah <ariff@FreeBSD.org>

Various fixups, especially for the upcomming High Definition Audio
commit.

1) sys/dev/sound/pcm/sound.h
sys/dev/sound/pcm/channel.c
* Be more specific: SD_F_SOFTVOL -> SD_F_SOFTPCMVOL
2) sys/dev/sound/pcm/mixer.[ch]
* Implement
mix_setparentchild()
mix_setrealdev()
mix_getparent()
mix_getchild()
The purpose of these functions is implement relative volume
adjustment, such as to tie two or more mixer device into a
single logical device. Usefull for the upcoming HDA driver
and few AC97 codec (such as AD1981B) where the master volume
"vol" need to be implemented using this logical manner.
3) sys/dev/sound/pcm/ac97_patch.[ch]
* Patch for AD1981B codec to enable (automuting) headphone jack sense.
4) sys/dev/sound/pcm/ac97.c
* Implement proper logical master volume for AD9181B codec
through various mix_set{parentchild,realdev}(). Tie both
"ogain" (headphone volume) and "phone" (speaker/lineout) to
a logical "vol".
5) sys/dev/sound/pcm/usb/uaudio_pcm.c
* ditto, for "vol" -> { "pcm" }.

MFC after: 1 month


# b611c801 23-Sep-2006 Alexander Leidinger <netchild@FreeBSD.org>

MFp4 the sound Google Summer of Code project:

The goal was to sync with the OSSv4 API 4Front Technologies uses in their
proprietary OSS driver. This was successful as far as possible. The part
of the API which is stable is implemented, for the rest there are some
stubs already.

New system ioctls:
- SNDCTL_SYSINFO - obtain audio system info (version, # of audio/midi/
mixer devices, etc.)
- SNDCTL_AUDIOINFO - fetch details about a specific audio device
- SNDCTL_MIXERINFO - fetch details about a specific mixer device

New audio ioctls:
- Sync groups (SNDCTL_DSP_SYNCGROUP/SNDCTL_DSP_SYNCSTART) which allow
triggered playback/recording on multiple devices (even across processes
simultaneously).
- Peak meters (SNDCTL_DSP_GETIPEAKS/SNDCTL_DSP_GETOPEAKS) - can query
audio drivers for peak levels (needs driver support, disabled for now).
- Per channel playback/recording levels -
SNDCTL_DSP_{GET,SET}{PLAY,REC}VOL. Note that these are still in name
only, just wrapping around the AC97-style mixer at the moment. The next
step is to push them down to the drivers.

Audio ioctls still under development by 4Front (for which stubs may exist
in this commit):
- SNDCTL_GETNAME, SNDCTL_{GET,SET}{SONG,LABEL}
- SNDCTL_DSP_{GET,SET}_CHNORDER
- SNDCTL_MIX_ENUMINFO, SNDCTL_MIX_EXTINFO - (might be documented enough in
the OSS releases to work on this. These ioctls cover the cool "twiddle
any knob on your card" features.)

Missing:
- SNDCTL_DSP_COOKEDMODE -- this ioctl is used to give applications direct
access to a card's buffers, bypassing the feeder architecture. It's
a toughy -- "someone" needs to decide :
(a) if this is desireable, and (b) if it's reasonably feasible.

Updates for driver writers:
So far, only two routines to the channel class (in channel_if.m) are added.
One is for fetching a list of discrete supported playback/recording rates
of a channel, and the other is for fetching peak level info (useful for
drawing peak meters). Interested parties may want to help pushing down
SNDCTL_DSP_{GET,SET}{PLAY,REC}VOL into the drivers.

To use the new stuff you need to rebuild the sound drivers or your kernel
(depending on if you use modules or not) and to install soundcard.h (a
buildworld/installworld handles this).

Sponsored by: Google SoC 2006
Submitted by: ryanb
Many thanks to: 4Front Technologies for their cooperation, explanations
and the nice license of their soundcard.h.


# d55d96f6 17-Jul-2006 Alexander Leidinger <netchild@FreeBSD.org>

Rename some variables. This fixes some (but not all) problems on the way
for WARNS > 2 cleanlyness.

Submitted by: Yuriy Tsibizov <Yuriy.Tsibizov@gfk.ru>


# c40da00c 16-May-2006 Poul-Henning Kamp <phk@FreeBSD.org>

Since DELAY() was moved, most <machine/clock.h> #includes have been
unnecessary.


# 3fdb3676 20-Mar-2006 Ariff Abdullah <ariff@FreeBSD.org>

Apply more thorough fixes while dealing with device opening and closing:

- Determine open direction using 'flags', not 'mode'. This bug exist since
past 4 years.
- Don't allow opening the same device twice, be it in a same or different
direction.
- O_RDWR is allowed, provided that it is done by a single open (for example
by mixer(8)) and the underlying hardware support true full-duplex operation.
- Do various paranoid checking in case other process/thread trying to hijack
the same device twice (or more).

MFC after: 5 days


# 7982e7a4 15-Mar-2006 Ariff Abdullah <ariff@FreeBSD.org>

Fix severe 8bit integer overflow during channel creation and destruction,
especially for vchans. It turns out that channel numbering always depend
on d->devcount counter (which keep increasing), while PCMMKMINOR() truncate
everything to 8bit length. At some point the truncation cause the newly
created character device overlapped with the existence one, causing erratic
overall system behaviour and panic. Easily reproduce with something like:

(Luckily, only root can reproduce this)

while : ; do
sysctl hw.snd.pcm0.vchans=200
sysctl hw.snd.pcm0.vchans=100
done

- Enforce channel/chardev numbering within 8bit boundary. Return E2BIG
if necessary.
- Traverse d->channels SLIST and try to reclaim "free" counter during channel
creation. Don't rely on d->devcount at all.
- Destroy vchans in reverse order.

Anyway, this is not the fault of vchans. It is just that vchans are so cute
and begging to be abused ;) . Don't blame her.

Old, hidden bugs.. sigh..

MFC after: 3 days


# 28ef3fb0 02-Oct-2005 Alexander Leidinger <netchild@FreeBSD.org>

sys/dev/sound/pcm/sndstat.c:
* General spl* cleanup. It doesn't serve any purpose anymore.
* Nuke sndstat_busy(). Addition of sndstat_acquire() /
sndstat_release() for sndstat exclusive access. [1]

sys/dev/sound/pcm/sound.c:
* Remove duplicate SLIST_INIT()
* Use sndstat_acquire() / release() to lock / release the entire
sndstat during pcm_unregister(). This should fix LOR #159 [1]

sys/dev/sound/pcm/sound.h:
* Definition of SD_F_SOFTVOL (part of feeder volume)
* Nuke sndstat_busy(). Addition of sndstat_acquire() /
sndstat_release() for exclusive sndstat access. [1]

Submitted by: Ariff Abdullah <skywizard@MyBSD.org.my>
LOR: 159 [1]
Discussed with: yongari [1]


# 5cfcc28b 10-Sep-2005 Alexander Leidinger <netchild@FreeBSD.org>

- fake.c
* Add missing A_LAW / MU_LAW format.
- feeder.c
* Fix format chain building. Traverse backward instead of forward
during format chainning.
- feeder_fmt.c
* Add missing alaw/mulaw converter.
* Add 16 -> 24/32bit converter.
* whitespace cleanup.
- sound.h
* alaw / mulaw are member of AFMT_8BIT.

Submitted by: Ariff Abdullah <skywizard@MyBSD.org.my>


# 87506547 31-Jul-2005 Alexander Leidinger <netchild@FreeBSD.org>

Whats New:
1. Support wide range sampling rate, as low as 1hz up to int32 max
(which is, insane) through new feeder_rate, multiple precisions
choice (32/64 bit converter). This is indeed, quite insane, but it
does give us more room and flexibility. Plenty sysctl options to
adjust resampling characteristics.
2. Support 24/32 bit pcm format conversion through new, much improved,
simplified and optimized feeder_fmt.

Changes:
1. buffer.c / dsp.c / sound.h
* Support for 24/32 AFMT.
2. feeder_rate.c
* New implementation of sampling rate conversion with 32/64 bit
precision, 1 - int32max hz (which is, ridiculous, yet very
addictive). Much improved / smarter buffer management to not
cause any missing samples at the end of conversion process
* Tunable sysctls for various aspect:
hw.snd.feeder_rate_ratemin - minimum allowable sampling rate
(default to 4000)
hw.snd.feeder_rate_ratemax - maximum allowable sampling rate
(default to 1102500)
hw.snd.feeder_rate_buffersize - conversion buffer size
(default to 8192)
hw.snd.feeder_rate_scaling - scaling / conversion method
(please refer to the source for explaination). Default to
previous implementation type.
3. feeder_fmt.c / sound.h
* New implementation, support for 24/32bit conversion, optimized,
and simplified. Few routines has been removed (8 to xlaw, 16 to
8). It just doesn't make sense.
4. channel.c
* Support for 24/32 AFMT
* Fix wrong xruns increment, causing incorrect underruns statistic
while using vchans.
5. vchan.c
* Support for 24/32 AFMT
* Proper speed / rate detection especially for fixed rate ac97.
User can override it using kernel hint:
hint.pcm.<unit>.vchanrate="xxxx".

Notes / Issues:
* Virtual Channels (vchans)
Enabling vchans can really, really help to solve overrun
issues. This is quite understandable, because it operates
entirely within its own buffering system without relying on
hardware interrupt / state. Even if you don't need vchan,
just enable single channel can help much. Few soundcards
(notably via8233x, sblive, possibly others) have their own
hardware multi channel, and this is unfortunately beyond
vchan reachability.
* The arrival of 24/32 also come with a price. Applications
that can do 24/32bit playback need to be recompiled (notably
mplayer). Use (recompiled) mplayer to experiment / test /
debug this various format using -af format=fmt. Note that
24bit seeking in mplayer is a little bit broken, sometimes
can cause silence or loud static noise. Pausing / seeking
few times can solve this problem.
You don't have to rebuild world entirely for this. Simply
copy /usr/src/sys/sys/soundcard.h to
/usr/include/sys/soundcard.h would suffice. Few drivers also
need recompilation, and this can be done via
/usr/src/sys/modules/sound/.
Support for 24bit hardware playback is beyond the scope of
this changes. That would require spessific hardware driver
changes.
* Don't expect playing 9999999999hz is a wise decision. Be
reasonable. The new feeder_rate implemention provide
flexibility, not insanity. You can easily chew up your CPU
with this kind of mind instability. Please use proper
mosquito repellent device for this obvious cracked brain
attempt. As for testing purposes, you can use (again)
mplayer to generate / play with different sampling rate. Use
something like "mplayer -af resample=192000:0:0 <files>".

Submitted by: Ariff Abdullah <skywizard@MyBSD.org.my>
Tested by: multimedia@


# e70377df 27-Feb-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Use dynamic major number allocation.


# 098ca2bd 05-Jan-2005 Warner Losh <imp@FreeBSD.org>

Start each of the license/copyright comments with /*-, minor shuffle of lines


# 0739ea1d 15-Jul-2004 Seigo Tanimura <tanimura@FreeBSD.org>

Rename the sound device drivers:

- `sound'
The generic sound driver, always required.

- `snd_*'
Device-dependent drivers, named after the sound module names.
Configure accordingly to your hardware.

In addition, rename the `snd_pcm' module to `sound' in order to sync
with the driver names.

Suggested by: cg


# b8c48216 10-Jul-2004 Marcel Moolenaar <marcel@FreeBSD.org>

Remove DDB. The one user of this macro has been changed to use BVDDB.
Yes, DDB is unrelated to the debugger with the same acronym. Hence,
the change.


# 89c9c53d 16-Jun-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.


# 8fb9a995 14-Apr-2004 Brian Feldman <green@FreeBSD.org>

The newpcm headers currently #define away INTR_MPSAFE and INTR_TYPE_AV
because they bogusly check for defined(INTR_MPSAFE) -- something which
never was a #define. Correct the definitions.

This make INTR_TYPE_AV finally get used instead of the lower-priority
INTR_TYPE_TTY, so it's quite possible some improvement will be had
on sound driver performance. It would also make all the drivers
marked INTR_MPSAFE actually run without Giant (which does seem to
work for me), but:
INTR_MPSAFE HAS BEEN REMOVED FROM EVERY SOUND DRIVER!
It needs to be re-added on a case-by-case basis since there is no one
who will vouch for which sound drivers, if any, willy actually operate
correctly without Giant, since there hasn't been testing because of
this bug disabling INTR_MPSAFE.

Found by: "Yuriy Tsibizov" <Yuriy.Tsibizov@gfk.ru>


# 0d8ed52e 06-Mar-2004 Mathew Kanner <matk@FreeBSD.org>

Augment /dev/sndstat with the module names, if applicable.

Approved by: tanimura (mentor)


# a3193a9c 28-Feb-2004 Don Lewis <truckman@FreeBSD.org>

Create a new mutex type for virtual channels. This allows us to get
rid of the MTX_DUPOK flag on channel mutexes, which allows witness to
do a better job of lock order checking. Nuke snd_chnmtxcreate() since
it is no longer needed.

Tested by: matk


# 12e524a2 28-Jan-2004 Don Lewis <truckman@FreeBSD.org>

Change KASSERT() in feed_vchan16() into an explicit test and call to
panic() so that the buffer overflow just beyond this point is always
caught, even when the code is not compiled with INVARIANTS.

Change chn_setblocksize() buffer reallocation code to attempt to avoid
the feed_vchan16() buffer overflow by attempting to always keep the
bufsoft buffer at least as large as the bufhard buffer.

Print a diagnositic message
Danger! %s bufsoft size increasing from %d to %d after CHANNEL_SETBLOCKSIZE()
if our best attempts fail. If feed_vchan16() were to be called by
the interrupt handler while locks are dropped in chn_setblocksize()
to increase the size bufsoft to match the size of bufhard, the panic()
code in feed_vchan16() will be triggered. If the diagnostic message
is printed, it is a warning that a panic is possible if the system
were to see events in an "unlucky" order.

Change the locking code to avoid the need for MTX_RECURSIVE mutexes.

Add the MTX_DUPOK option to the channel mutexes and change the locking
sequence to always lock the parent channel before its children to avoid
the possibility of deadlock.

Actually implement locking assertions for the channel mutexes and fix
the problems found by the resulting assertion violations.

Clean up the locking code in dsp_ioctl().

Allocate the channel buffers using the malloc() M_WAITOK option instead
of M_NOWAIT so that buffer allocation won't fail. Drop locks across
the malloc() calls.

Add/modify KASSERTS() in attempt to detect problems early.

Abuse layering by adding a pointer to the snd_dbuf structure that points
back to the pcm_channel that owns it. This allows sndbuf_resize() to do
proper locking without having to change the its API, which is used by
the hardware drivers.

Don't dereference a NULL pointer when setting hw.snd.maxautovchans
if a hardware driver is not loaded. Noticed by Ryan Sommers
<ryans at gamersimpact.com>.

Tested by: Stefan Ehmann <shoesoft AT gmx.net>
Tested by: matk (Mathew Kanner)
Tested by: Gordon Bergling <gbergling AT 0xfce3.net>


# 5ee30e27 19-Jan-2004 Mathew Kanner <matk@FreeBSD.org>

Fix a panic when kldloading a sound driver. Do this by replacing the
link-list of dev_t's with named variables. Remove used code.

Approved by: tanimura (mentor)


# 45550658 17-Jan-2004 Poul-Henning Kamp <phk@FreeBSD.org>

As previously announced: discontinue use of makedev() call in soundcode.

This takes us a lot closer to refcounting dev_t.

This patch originally by cg@ with a few minor changes by me.

It is largely untested, but has been HEADSUP'ed twice, so presumably
people have not found any issues with it.

Submitted by: cg@


# 3f225978 07-Sep-2003 Cameron Grant <cg@FreeBSD.org>

update my email address.


# a527dbc7 18-Aug-2003 Cameron Grant <cg@FreeBSD.org>

handle locking when creating or destroying vchans better


# 3febcc57 07-Feb-2003 Yoshihiro Takahashi <nyan@FreeBSD.org>

- Clean up ISA DMA supports.
- Rename all sndbuf_isadma* functions to sndbuf_dma* and move them into
sys/dev/sound/isa/sndbuf_dma.c.

No response from: sound


# 67beb5a5 25-Nov-2002 Cameron Grant <cg@FreeBSD.org>

various fixes to eliminate locking warnings

Approved by: re
Reviewed by: orion


# ab85003b 15-Sep-2002 Bruce Evans <bde@FreeBSD.org>

Fixed breakage from removing the used include of <sys/buf.h> in the
previous commit:
Include <sys/mutex.h> and its prerequisite <sys/lock.h> instead of
depending on namespace pollution in <sys/buf.h>. Only do this in the
__FreeBSD_version > 500000 case although the __FreeBSD_version < 500000
case has already rotted.


# 296bbb4c 14-Sep-2002 Poul-Henning Kamp <phk@FreeBSD.org>

FreeBSD -current doesn't need <sys/buf.h> or <sys/bio.h>.


# 2c69ba87 04-Apr-2002 John Baldwin <jhb@FreeBSD.org>

Change snd_mtxcreate() to accept a lock type as an extra argument that is
passed to mtx_init().


# b8a36395 26-Jan-2002 Cameron Grant <cg@FreeBSD.org>

* improve error handling
* be more specific in verbose boot messages
* allow the feeder subsystem to veto pcm* attaching if there is an error
initialising the root feeder
* don't free/malloc a new tmpbuf when resizing a snd_dbuf to the same size as
it currently is
* store the feeder description in the feeder structure instead of mallocing
space for it


# a67fe5c1 18-Sep-2001 Cameron Grant <cg@FreeBSD.org>

change tracking of channel counts.

add method for retrieving "buffersize" hints for pcm devices, adjusted for
specified minimum, maximum and default values.


# 5c25132a 14-Sep-2001 George C A Reid <greid@FreeBSD.org>

- Correctly increment the channel refcount in dsp_open() such that it is
no longer possible to unload the driver module while sound is playing
(which resulted in a panic).
- Fix a similar problem with the sndstat device that I found while looking
at the above.
- Append a newline character to error messages in pcm_unregister()

Reviewed by: cg
MFC after: 10 days


# 506a5308 05-Sep-2001 Cameron Grant <cg@FreeBSD.org>

add a method for recording of specific channels for devices with more than
one hardware record channel. new devices, /dev/dsprX.Y where X is unit
number and Y is channel index.


# 67b1dce3 23-Aug-2001 Cameron Grant <cg@FreeBSD.org>

many changes:

* add new channels to the end of the list so channels used in order of
addition

* de-globalise definition of struct snddev_info and provide accessor
functions where necessary.

* move the $FreeBSD$ tag in each .c file into a macro and allow the
/dev/sndstat handler to display these when set to maximum verbosity to aid
debugging.

* allow each device to register its own sndstat handler to reduce the amount
of groping sndstat must do in foreign structs.


# cbe7d6a3 02-Jul-2001 Cameron Grant <cg@FreeBSD.org>

remove obsolete typedefs.

only define INTR_TYPE_AV if it is not already defined.


# bc0e6469 02-Jul-2001 Brian Feldman <green@FreeBSD.org>

Correct obviously wrong mistakes.


# 0cfa4761 02-Jul-2001 Brian Feldman <green@FreeBSD.org>

Make all this compile on 4.3, modulus sbuf.


# f637a36c 27-Jun-2001 Cameron Grant <cg@FreeBSD.org>

don't flag the playback hardchan as busy on devices with only one of them.

if a device has vchans already but they are all busy, allocate another one
at open() time, up to a maximum of hw.snd.maxvchans.

when creating/destroying vchans, don't make/remove a devnode for the
first/last one as it replaces a hardchan.


# cd9766c5 26-Jun-2001 Cameron Grant <cg@FreeBSD.org>

add a tunable/sysctl, hw.snd.autovchans. if this is set to a value n where
n > 0, n vchans will be assigned to any devices that subsequently register
with a single playback channel.


# f00f162a 23-Jun-2001 Cameron Grant <cg@FreeBSD.org>

add defines and ifdefs so this code will compile on 4.x

add spls so this code will work on 4.x


# faeebea2 17-Jun-2001 Cameron Grant <cg@FreeBSD.org>

revise dsp_clone() to return the first nonbusy channel instead of simply
cycling channel numbers.

remove unused fields from struct snddev_info.


# d95502a8 16-Jun-2001 Cameron Grant <cg@FreeBSD.org>

use a global devclass for all drivers - i'm not entirely sure why this
worked before.

mixer, dsp and sndstat are seperate devices - give them their own cdevsws
instead of demuxing requests sent to a single cdevsw.

use the si_drv1/si_drv2 fields in dev_t structures for holding information
specific to an open instance of mixer/dsp.

nuke /dev/{dsp,dspW,audio}[0-9]* links - this functionality is now provided
using cloning.

various locking fixes.


# b8f0d9e0 14-Jun-2001 Cameron Grant <cg@FreeBSD.org>

various locking fixes, rework open logic and channel registration

PR: kern/28084


# 49c5e6e2 07-Jun-2001 Cameron Grant <cg@FreeBSD.org>

lock sound device when adding/removing channels
implement setblocksize for vchans
don't panic when doing certain ioctls or aborting on a vchan
xmms now works with vchans


# 285648f9 27-May-2001 Cameron Grant <cg@FreeBSD.org>

beginnings of virtual playback channel support

instead of using two malloced arrays for storing channel lists, use an
slist. convert the sndstat device to use sbufs and optionally provide more
detail about channel state.

vchans are software mixed playback channels. they are not enabled by this
commit. they use the feeder infrastructure to emulate normal playback
channels in a manner transparent to applications, whilst providing as many
channels are desired, especially suitable for devices with only one hardware
playback channel. in the future they will provide additional features.

those wishing to test this functionality will need to add vchan.c to
sys/conf/files and use 'sysctl -w hw.snd.pcm0.vchans' to enable it.

blocksize and auto-rate selection are not yet supported.


# 66ef8af5 24-Mar-2001 Cameron Grant <cg@FreeBSD.org>

mega-commit.

this introduces a new buffering mechanism which results in dramatic
simplification of the channel manager.

as several structures have changed, we take the opportunity to move their
definitions into the source files where they are used, make them private and
de-typedef them.

the sound drivers are updated to use snd_setup_intr instead of
bus_setup_intr, and to comply with the de-typedefed structures.

the ac97, mixer and channel layers have been updated with finegrained
locking, as have some drivers- not all though. the rest will follow soon.


# a0585a78 05-Mar-2001 Cameron Grant <cg@FreeBSD.org>

MFS: add kobj.h to reduce diffs from -stable


# dec507e8 05-Mar-2001 Cameron Grant <cg@FreeBSD.org>

enable per-device sysctls unconditionally


# 37209180 27-Feb-2001 Cameron Grant <cg@FreeBSD.org>

add functions for sound drivers to use for locking and setting up interrupt
handlers. these are not yet used, but will allow compatibility for driver
modules from 5.x to 4.x.


# 041e207d 26-Feb-2001 Cameron Grant <cg@FreeBSD.org>

MFS: 4.x/5.x compatibility #defines


# b3b7ccfe 02-Jan-2001 John Baldwin <jhb@FreeBSD.org>

Create a new sysctl node 'hw.snd' and move 'hw.sndunit' to
'hw.snd.unit'.

Reviewed by: cg


# 350a5faf 22-Dec-2000 Cameron Grant <cg@FreeBSD.org>

update code dealing with snd_dbuf objects to do so using a functional interface

modify chn_setblocksize() to pick a default soft-blocksize appropriate to the
sample rate and format in use. it will aim for a power of two size small
enough to generate block sizes of at most 20ms. it will also set the
hard-blocksize taking into account rate/format conversions in use.

update drivers to implement setblocksize correctly:
updated, tested: sb16, emu10k1, maestro, solo
updated, untested: ad1816, ess, mss, sb8, csa
not updated: ds1, es137x, fm801, neomagic, t4dwave, via82c686

i lack hardware to test: ad1816, csa, fm801, neomagic
others will be updated/tested in the next few days.


# 0f55ac6c 17-Dec-2000 Cameron Grant <cg@FreeBSD.org>

kobjify.

this gives us several benefits, including:

* easier extensibility- new optional methods can be added to
ac97/mixer/channel classes without having to fixup every driver.

* forward compatibility for drivers, provided no new mandatory methods are
added.


# 4e2e565c 06-Nov-2000 Cameron Grant <cg@FreeBSD.org>

add AFMT_8BIT for easier determination of formats


# 37ab02c0 05-Sep-2000 Cameron Grant <cg@FreeBSD.org>

tidy up a little, add a mask for 32bit formats


# 33dbf14a 01-Sep-2000 Cameron Grant <cg@FreeBSD.org>

change mixer api slightly
change channel interface - kobj implementation coming soonish
make pcm_makelinks not panic if modular
add pcm_unregister()

these changes support newpcm kld unloading, but this is only implemented
by ds1.c


# 513693be 20-Aug-2000 Cameron Grant <cg@FreeBSD.org>

rework feeder sytem to allow feeders in klds

modify driver capability reporting format to list every audio format
seperately- required for above and because we could not previously indicate
that mono was unsupported.

there should be no functional impact.


# 071280d4 09-Aug-2000 Cameron Grant <cg@FreeBSD.org>

MFS: module macro changes


# 1874ec25 08-Aug-2000 Cameron Grant <cg@FreeBSD.org>

MFS: sync with peter's isadma fixup


# d98c7b9a 18-Jul-2000 Cameron Grant <cg@FreeBSD.org>

make this file suitable for 4-stable as well as 5-current


# f314f3da 03-Jul-2000 Cameron Grant <cg@FreeBSD.org>

add module metadata. this is a hack, sound drivers will eventually present a
bus to which pcm, mixer, etc will attach.


# 7c14268d 19-May-2000 Yoshihiro Takahashi <nyan@FreeBSD.org>

Supported the mss on PC-98 and Sound Blaster 98.

Submitted by: "T.Yamaoka" <taka@windows.squares.net>


# 9626b608 05-May-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Separate the struct bio related stuff out of <sys/buf.h> into
<sys/bio.h>.

<sys/bio.h> is now a prerequisite for <sys/buf.h> but it shall
not be made a nested include according to bdes teachings on the
subject of nested includes.

Diskdrivers and similar stuff below specfs::strategy() should no
longer need to include <sys/buf.> unless they need caching of data.

Still a few bogus uses of struct buf to track down.

Repocopy by: peter


# 39004e69 20-Mar-2000 Cameron Grant <cg@FreeBSD.org>

update the ac97 layer:
* add a callback for initialising the mixer interface
* support ac97 2.1 variable rate audio feature

fix ac97-using drivers for the above

add suspend/resume support for neomagic


# 96e00123 29-Jan-2000 Peter Wemm <peter@FreeBSD.org>

Remove a rather bizzare set of #ifdefs and #defines that all worked out
to be a NO-OP.


# 664a31e4 28-Dec-1999 Peter Wemm <peter@FreeBSD.org>

Change #ifdef KERNEL to #ifdef _KERNEL in the public headers. "KERNEL"
is an application space macro and the applications are supposed to be free
to use it as they please (but cannot). This is consistant with the other
BSD's who made this change quite some time ago. More commits to come.


# a0b57fb7 28-Dec-1999 Cameron Grant <cg@FreeBSD.org>

- latest 2ndbuffer patch
- make chn_setdir work for rec on isa cards
- note: es1371 does not irq in smp

Submitted by: tanimura


# 0927bf43 11-Dec-1999 Cameron Grant <cg@FreeBSD.org>

move channel-swapping support to the hardware driver since it knows the card
state best


# c2af6f65 06-Dec-1999 Peter Wemm <peter@FreeBSD.org>

Update for pnp adjustments regarding NPNP.

Also, optimize out a mess of #if's that were duplicating work already
done by config(8). For example, if a file is marked as
"dev/sound/pci/foo.c optional pcm pci" then it's only added if pcm *and*
pci are present, so #if NPCM > 0 and #if NPCI > 0 are totally redundant.
A bit more work is still needed.

Discussed with: cg (a few weeks ago)


# 0e25481f 05-Dec-1999 Cameron Grant <cg@FreeBSD.org>

fix dma underrun issues
mutate some panics to kasserts
add more spl protection

PR: kern/14990
Partially Submitted by: Vladimir N.Silyaev <vns@delta.odessa.ua>
Reviewed by: dfr


# ef9308b1 20-Nov-1999 Cameron Grant <cg@FreeBSD.org>

repo-copied to make way for newmidi, this commit updates include paths


# 5b78a734 28-Sep-1999 Cameron Grant <cg@FreeBSD.org>

* add a non-reset device- will not reset the channel on open. you
will have to mknod yourself for now.
* don't eat the first write()
* partial rvplayer fix- don't panic on unaligned writes unless our
feeder chain requires them for downconversion. a fuller fix is
on the way.


# 53c5a968 01-Sep-1999 Peter Wemm <peter@FreeBSD.org>

$Id$ -> $FreeBSD$


# 987e5972 31-Aug-1999 Cameron Grant <cg@FreeBSD.org>

say hello to newpcm. it is not yet enabled, requiring new pnp code from dfr
to compile successfully. further details will be provided in the commit
enabling newpcm.