History log of /freebsd-current/sys/dev/sound/pcm/dsp.c
Revision Date Author Comments
# 5d980fad 22-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Handle unavailable devices in various OSS IOCTLs

mixer(8)'s -a option is used to print information about all mixer
devices in the system. To do this, it loops from 0 to
mixer_get_nmixers(), and tries to open "/dev/mixer%d". However, this
approach doesn't work when there are disabled/unregistered mixers in the
system, or when an audio device simply doesn't have a mixer.

mixer_get_nmixers() calls SNDCTL_SYSINFO and returns
oss_sysinfo->nummixers, whose value is the number of currently _enabled_
mixers only. Taking the bug report mentioned below (277615) as an
example, suppose a system with 8 mixer devices total, but 3 of them are
either disabled or non-existent, which means they will not show up under
/dev, meaning we have 5 enabled mixer devices, which is also what the
value of oss_sysinfo->nummixers will be. What mixer(8) will do is loop
from 0 to 5 (instead of 8), and start calling mixer_open() on
/dev/mixer0, up to /dev/mixer4, and as is expected, the first call will
fail right away, hence the error shown in the bug report.

To fix this, modify oss_sysinfo->nummixers to hold the value of the
maximum unit in the system, which, although not necessarily "correct",
is more intuitive for applications that will want to use this value to
loop through all mixer devices.

Additionally, notify applications that a device is
unavailable/unregistered instead of skipping it. The current
implementations of SNDCTL_AUDIOINFO, SNDCTL_MIXERINFO and
SNDCTL_CARDINFO break applications that expect to get information about
a device that is skipped. Related discussion can be found here:
https://reviews.freebsd.org/D45135#1029526

It has to be noted, that other applications, apart from mixer(8), suffer
from this.

PR: 277615
Sponsored by: The FreeBSD Foundation
MFC after: 1 day
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D45256


# e07f9178 22-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Separate implementations for SNDCTL_AUDIOINFO[_EX] and SNDCTL_ENGINEINFO

FreeBSD's implementation of SNDCTL_AUDIOINFO[_EX] and SNDCTL_ENGINEINFO
does not exactly work as intended. The problem is essentially that both
IOCTLs return the same information, while in fact the information
returned currently by dsp_oss_audioinfo() is what _only_
SNDCTL_ENGINEINFO is meant to return.

This behavior is also noted in the OSS manual [1] (see bold paragraph in
"Audio engines and device files" section), but since e8c0d15a64fa
("sound: Get rid of snd_clone and use DEVFS_CDEVPRIV(9)") we can
actually fix this, because we now expose only a single device for each
soundcard, and create the engines (channels) internally.
SNDCTL_ENGINEINFO will now report info about all channels in a given
device, and SNDCTL_AUDIOINFO[_EX] will only report information about
/dev/dspX.

To make this work, we also have to modify the SNDCTL_SYSINFO IOCTL to
report the number of audio devices and audio engines correctly.

While here, modernize the minimum and maximum channel counting in both
SNDCTL_AUDIOINFO[_EX] and SNDCTL_ENGINEINFO. Currently these IOCTLs will
report only up to 2 channels, which is no longer the case.

[1] http://manuals.opensound.com/developer/SNDCTL_AUDIOINFO.html

PR: 246231, 252761
Sponsored by: The FreeBSD Foundation
MFC after: 1 day
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D45164


# 24d5cc14 09-May-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Rename oss_audioinfo->real_device to oss_audioinfo->legacy_device

The OSS manual now documents this field as "legacy_device".

Sponsored by: The FreeBSD Foundation
MFC after: 3 days
Reviewed by: dev_submerge.ch
Differential Revision: https://reviews.freebsd.org/D45138


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

sound: Use nitems() where possible

No functional change intended.

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


# 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


# 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


# 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


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

sound: Wrap dsp_clone() and mixer_clone() with bus_topo_lock()

Make sure that the softc isn't freed in between the checks.

Sponsored by: The FreeBSD Foundation
MFC after; 1 day
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44991


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

sound: Fix NULL dereference in dsp_clone() and mixer_clone()

If we only have a single soundcard attached and we detach it right
before entering [dsp|mixer]_clone(), there is a chance pcm_unregister()
will have returned already, meaning it will have set snd_unit to -1, and
thus devclass_get_softc() will return NULL here.

While here, 1) move the calls to dsp_destroy_dev() and mixer_uninit()
below the point where we unset SD_F_REGISTERED, and 2) follow what
mixer_clone() does and make sure we don't use a NULL d->dsp_dev in
dsp_clone().

Reported by: KASAN
Sponsored by: The FreeBSD Foundation
MFC after: 1 day
Reviewed by: markj
Differential Revision: https://reviews.freebsd.org/D44924


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

sound: Simplify unit fetching in dsp_oss_audioinfo()

"i" keeps the value of the current unit, so we do not have to call
PCMUNIT() and device_get_unit() to fetch it.

In the mixer case, I think it is more correct to do it like this, since
mixer and DSP device units have a 1-1 relationship (i.e the mixer unit
is always the same as the corresponding DSP device one) and that way we
can make it more clear.

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


# 4f854658 12-Apr-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Update some LICENSE headers

The following commits introduced substantial changes to pcm/dsp.c,
pcm/sndstat.c and pcm/sound.c.

9da3b645dbaaad724d524727d003fed7be05ff7c ("sound: Move
sndstat_prepare_pcm() to pcm/sndstat.c and remove
sndstat_entry->handler")
e8c0d15a64fadb4a330f2da7244becaac161bb70 ("sound: Get rid of snd_clone
and use DEVFS_CDEVPRIV(9)")

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


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

sound: Implement asynchronous device detach

Hot-unplugging a sound device, such as a USB sound card, whilst being
consumed by an application, results in an infinite loop until either the
application closes the device's file descriptor, or the channel
automatically times out after hw.snd.timeout seconds. In the case of a
detach however, the timeout approach is still not ideal, since we want
all resources to be released immediatelly, without waiting for N seconds
until we can use the bus again.

The timeout mechanism works by calling chn_sleep() in chn_read() and
chn_write() (see pcm/channel.c) in order to send the thread to sleep,
using cv_timedwait_sig(). Since chn_sleep() sets the CHN_F_SLEEPING flag
while waiting for cv_timedwait_sig() to return, we can test this flag in
pcm_unregister() (called during detach) and wakeup the sleeping
thread(s) to immediately kill the channel(s) being consumed.

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


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


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

Revert "sound: Implement asynchronous device detach"

This reverts commit 9eff58c6d52b66eb8abe7f724dabcd804a566df4.

We are reverting dc831e93bad6 ("sound: Get rid of snd_clone and use
DEVFS_CDEVPRIV(9)"), so revert this commit as well since it depends
dc831e93bad6.


# 9eff58c6 31-Mar-2024 Christos Margiolis <christos@FreeBSD.org>

sound: Implement asynchronous device detach

Hot-unplugging a sound device, such as a USB sound card, whilst being
consumed by an application, results in an infinite loop until either the
application closes the device's file descriptor, or the channel
automatically times out after hw.snd.timeout seconds. In the case of a
detach however, the timeout approach is still not ideal, since we want
all resources to be released immediatelly, without waiting for N seconds
until we can use the bus again.

The timeout mechanism works by calling chn_sleep() in chn_read() and
chn_write() (see pcm/channel.c) in order to send the thread to sleep,
using cv_timedwait_sig(). Since chn_sleep() sets the CHN_F_SLEEPING flag
while waiting for cv_timedwait_sig() to return, we can test this flag in
pcm_unregister() (called during detach) and wakeup the sleeping
thread(s) to immediately kill the channel(s) being consumed.

Sponsored by: The FreeBSD Foundation
MFC after: 2 months
PR: 194727, 278055, 202275, 220949, 272286
Reviewed by: dev_submerge.ch, markj
Differential Revision: https://reviews.freebsd.org/D43545


# 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


# 61c83167 24-Nov-2023 Florian Walpen <dev@submerge.ch>

sound: Fix OSS API requests for more than 8 channels

Audio devices with more than 8 channels need bitperfect mode to operate,
the vchan processing chain is limited to 8 channels. For these devices,
let applications properly select a certain number of channels supported
by the driver, instead of mapping the request to a vchan format.

Reviewed by: emaste
Pull Request: https://github.com/freebsd/freebsd-src/pull/914


# 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


# 82a265ad 16-Aug-2023 Warner Losh <imp@FreeBSD.org>

sys: Remove $FreeBSD$: sound driver version

Remove /SND_DECLARE_FILE\("\$FreeBSD\$"\);/


# 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


# ad370f76 04-Nov-2022 Florian Walpen <dev@submerge.ch>

sound(4): Fix memory map of /dev/dsp devices when buffer size is not a multiple of PAGE_SIZE.

By using sndbuf_getallocsize() instead of sndbuf_getsize() in dsp_mmap_single().

PR: 267555
MFC after: 1 week
Sponsored by: NVIDIA Networking


# 4a83ca10 28-Sep-2021 Hans Petter Selasky <hselasky@FreeBSD.org>

sound(4): Implement mixer mute control for feeder channels.

PR: 258711
Differential Revision: https://reviews.freebsd.org/D31636
MFC after: 1 week
Sponsored by: NVIDIA Networking


# 3428b6c0 28-Mar-2021 Mark Johnston <markj@FreeBSD.org>

Fix several dev_clone callbacks to avoid out-of-bounds reads

Use strncmp() instead of bcmp(), so that we don't have to find the
minimum of the string lengths before comparing.

Reviewed by: kib
Reported by: KASAN
MFC after: 3 days
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D29463


# 77602e97 20-Nov-2020 Konstantin Belousov <kib@FreeBSD.org>

Unlock channels when any of them are locked, when returning for non-busy state.

Reported and tested by: "Wall, Stephen" <stephen.wall@redcom.com>
Sponsored by: The FreeBSD Foundation
MFC after: 1 week


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

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


# 40d59cd7 07-May-2020 Hans Petter Selasky <hselasky@FreeBSD.org>

Set PCM_CAP_VIRTUAL for virtual DSP devices.

Submitted by: Kevin Zheng <kevinz5000@gmail.com>
PR: 246206
MFC after: 1 week
Sponsored by: Mellanox Technologies


# 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


# d77e8982 02-Dec-2018 Konstantin Belousov <kib@FreeBSD.org>

Add a comment noting that the additional range checks are not needed.

The object size is set in the dsp_mmap_single() which provides the
range limit by vm_fault().

Reported by: C Turt <ecturt@gmail.com>
Reviewed by: alc, markj
admbug: 781
MFC after: 2 weeks
Sponsored by: The FreeBSD Foundation


# 33f4bcca 27-Jul-2018 Eitan Adler <eadler@FreeBSD.org>

Use https over http for FreeBSD pages


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


# d3f37016 26-Apr-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Allow DSP basename cloning to be disabled or enabled at boot and
runtime. This is useful when implementing OSS sound stacks in
userspace via libcuse for example.

MFC after: 2 weeks


# 32a0e5d5 24-Mar-2015 Hans Petter Selasky <hselasky@FreeBSD.org>

Make all PCM core sysctls tunable and remove redundant TUNABLE()
statements. This allows for setting all PCM core parameters in the
kernel environment through loader.conf(5) or kenv(1) which is useful
for pluggable PCM devices like USB audio devices which might be
plugged after that sysctl.conf(5) is executed.


# 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>


# 8fb3bbe7 17-Apr-2013 Gabor Kovesdan <gabor@FreeBSD.org>

- Corrrect mispellings of word useful

Submitted by: Christoph Mallon <christoph.mallon@gmx.de> (via private mail)


# 89f6b863 08-Mar-2013 Attilio Rao <attilio@FreeBSD.org>

Switch the vm_object mutex to be a rwlock. This will enable in the
future further optimizations where the vm_object lock will be held
in read mode most of the time the page cache resident pool of pages
are accessed for reading purposes.

The change is mostly mechanical but few notes are reported:
* The KPI changes as follow:
- VM_OBJECT_LOCK() -> VM_OBJECT_WLOCK()
- VM_OBJECT_TRYLOCK() -> VM_OBJECT_TRYWLOCK()
- VM_OBJECT_UNLOCK() -> VM_OBJECT_WUNLOCK()
- VM_OBJECT_LOCK_ASSERT(MA_OWNED) -> VM_OBJECT_ASSERT_WLOCKED()
(in order to avoid visibility of implementation details)
- The read-mode operations are added:
VM_OBJECT_RLOCK(), VM_OBJECT_TRYRLOCK(), VM_OBJECT_RUNLOCK(),
VM_OBJECT_ASSERT_RLOCKED(), VM_OBJECT_ASSERT_LOCKED()
* The vm/vm_pager.h namespace pollution avoidance (forcing requiring
sys/mutex.h in consumers directly to cater its inlining functions
using VM_OBJECT_LOCK()) imposes that all the vm/vm_pager.h
consumers now must include also sys/rwlock.h.
* zfs requires a quite convoluted fix to include FreeBSD rwlocks into
the compat layer because the name clash between FreeBSD and solaris
versions must be avoided.
At this purpose zfs redefines the vm_object locking functions
directly, isolating the FreeBSD components in specific compat stubs.

The KPI results heavilly broken by this commit. Thirdy part ports must
be updated accordingly (I can think off-hand of VirtualBox, for example).

Sponsored by: EMC / Isilon storage division
Reviewed by: jeff
Reviewed by: pjd (ZFS specific review)
Discussed with: alc
Tested by: pho


# 7a2aafc3 12-Sep-2011 Andriy Gapon <avg@FreeBSD.org>

dsp_ioctl: fix type of variable used to store ioctl request

PR: kern/156433
Submitted by: Grigori Goronzy <greg@chown.ath.cx>
Reviewed by: hselasky
Approved by: re (kib)
MFC after: 1 week


# 76dc2afd 11-May-2011 Andriy Gapon <avg@FreeBSD.org>

fix build on 32-bit platforms for r221803

Casting a pointer to a wide integer is probably not that bad, but I am
still guilty of not testing this.

Pointyhat to: avg
MFC after: 1 week
X-MFC with: r221803


# a5669965 12-May-2011 Andriy Gapon <avg@FreeBSD.org>

dsp/pcm: allow to mmap both read and write buffers using the same fd

This brings our implementation in line with OSS specification for
systems that support mmap. The change should also improve compatibility
with OSS software not specifically written for FreeBSD, e.g. PulseAudio
OSS plugin.

Reviewed by: kib, jhb
MFC after: 1 week


# e3888a98 03-May-2011 Andriy Gapon <avg@FreeBSD.org>

SNDCTL_DSP_GETIPTR: set pointer to sndbuf_getfreeptr()

Rationale:
- unlike current behavior this seems to be compliant with OSS
specification:
http://manuals.opensound.com/developer/SNDCTL_DSP_GETIPTR.html
- this seems to meet expectations of some OSS programs compiled for or
ported from Linux, e.g. ALSA OSS plugin
- this doesn't seem to break any programs as far as current testing
shows

Tested by: nox, hselasky
MFC after: 4 days


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


# 72208ab4 31-Mar-2010 Alexander Motin <mav@FreeBSD.org>

MFC r205734:
Fix lock leakage.

PR: kern/145081


# 42d008a1 27-Mar-2010 Alexander Motin <mav@FreeBSD.org>

Fix lock leakage.

PR: kern/145081


# 1ea94461 14-Feb-2010 Alexander Motin <mav@FreeBSD.org>

MFC r202150, r202170:
Make OSS_GETVERSION ioctl really work. It has 'M' group, not 'P',
as different nearby ones, and was grabbed by MIXER_xxx() handler.

While there, replace '(cmd & MIXER_xxx(0)) == MIXER_xxx(0)' expressions
with more correct '(cmd & ~0xff) == MIXER_xxx(0)'. Use of bit operations
to compare numeric fields doesn't looks sane.


# b7d561a3 12-Jan-2010 Alexander Motin <mav@FreeBSD.org>

Make OSS_GETVERSION ioctl supported also for DSP devices,
same as 4Front and Linux do.

MFC after: 1 month


# 2fdb5f0b 12-Jan-2010 Alexander Motin <mav@FreeBSD.org>

Make OSS_GETVERSION ioctl really work. It has 'M' group, not 'P',
as different nearby ones, and was grabbed by MIXER_xxx() handler.

While there, replace '(cmd & MIXER_xxx(0)) == MIXER_xxx(0)' expressions
with more correct '(cmd & ~0xff) == MIXER_READ(0)'. Use of bit operations
to compare numeric fields doesn't looks sane.

MFC after: 1 month


# cfd7bace 29-Dec-2009 Robert Noland <rnoland@FreeBSD.org>

Update d_mmap() to accept vm_ooffset_t and vm_memattr_t.

This replaces d_mmap() with the d_mmap2() implementation and also
changes the type of offset to vm_ooffset_t.

Purge d_mmap2().

All driver modules will need to be rebuilt since D_VERSION is also
bumped.

Reviewed by: jhb@
MFC after: Not in this lifetime...


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


# 609c69b7 10-Jan-2009 Alexander Motin <mav@FreeBSD.org>

Make devnode include full device path.
This makes OSSv4 osstest tool work.


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

Remove debug slipped with the previous commit.


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


# d3ce8327 26-Sep-2008 Ed Schouten <ed@FreeBSD.org>

Remove unit2minor() use from kernel code.

When I changed kern_conf.c three months ago I made device unit numbers
equal to (unneeded) device minor numbers. We used to require
bitshifting, because there were eight bits in the middle that were
reserved for a device major number. Not very long after I turned
dev2unit(), minor(), unit2minor() and minor2unit() into macro's.
The unit2minor() and minor2unit() macro's were no-ops.

We'd better not remove these four macro's from the kernel, because there
is a lot of (external) code that may still depend on them. For now it's
harmless to remove all invocations of unit2minor() and minor2unit().

Reviewed by: kib


# 2bc59982 26-May-2008 Ariff Abdullah <ariff@FreeBSD.org>

Release pcm mutex before calling snd_clone_unref(), which in turns might
calling destroy_dev() with sleepable malloc(9). The entire opetation
is being serialized through pcm cv from top down, so dropping mutex is
rather safe.

Reported by: delphij


# 429cc100 11-Apr-2008 Ariff Abdullah <ariff@FreeBSD.org>

Don't mess up with CHN_F_TRIGGERED, since it should exclusively
be handled by chn_abort() and chn_start() alone. This should fix
few issues with single duplex hardware (mostly) or pre virtual record
(RELENG 6) under WINE emulation and possibly others that using
SNDCTL_DSP_SETTRIGGER.

MFC after: 3 days


# a5b0e312 03-Jul-2007 Ariff Abdullah <ariff@FreeBSD.org>

Be much more forgiving towards applications that requesting ioctls
that should be a no-op (for example, requesting SYNC on record path).
The standards does not indicate that such requests are illegal, so
just return it as success instead of EINVAL.

Approved by: re (mux)


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


# adb0d36d 10-Jun-2007 Matt Jacob <mjacob@FreeBSD.org>

Cast len to be a uintmax_t and make format in KASSERT match so as
to avoid different sizes on different platforms types of complaints.

Reviewed by: Ariff


# 9c271f79 03-Jun-2007 Ariff Abdullah <ariff@FreeBSD.org>

Insert NULL pointer checking around devclass_get_maxunit(pcm_devclass, ..) .
Things can get ugly without it due to uninitialized class. RELENG_6 need
a simmilar, but different treatment as well.

err.. perhaps we should teach devclass_get_maxunit() to return -1 ?

MFC after: 1 day


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


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

[stage: 7/9]

EWOULDBLOCK -> EAGAIN.


# b45d0ec8 07-Dec-2006 Ariff Abdullah <ariff@FreeBSD.org>

Remove comment that is no longer relevant since previous
buffering fix.


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


# 394ebd35 28-Oct-2006 Alexander Leidinger <netchild@FreeBSD.org>

MFP4:
Rename MAX_SAMPLE_RATES macro to OSS_MAX_SAMPLE_RATES. The old
macro clashed with those used in other applications and libaries
(ex: RtAudio). 4Front responded by updating their spec, so we
will follow suit.

Submitted by: ryanb
Noticed by: pointyhat/kris


# 0f85b689 08-Oct-2006 Alexander Leidinger <netchild@FreeBSD.org>

Remove unnecessary test case. (As written, that branch will never
be followed.)

Submitted by: ryanb
Found with: Coverity Prevent
CID: 239860


# f77472e6 29-Sep-2006 Ruslan Ermilov <ru@FreeBSD.org>

The SNDCTL_DSP_NONBLOCK ioctl doesn't take an argument, from
what I can tell by browsing the Internet (Linux, OSS, etc.).


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


# 844f9220 29-Mar-2006 Ariff Abdullah <ariff@FreeBSD.org>

Remove paranoid thread hijacking check. It cause wierd behaviour
(dangling channel - process association) especially in threaded
or fork()ed apps.


# 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


# c8c4c87d 29-Jan-2006 Alexander Leidinger <netchild@FreeBSD.org>

Fix some potential NULL pointer dereferences.

This is supposed to fix some Coverity Prevent errors (Ariff didn't
looked at the CID's (ENOTIME), I just told him that there are some problems
in function dsp_ioctl()).

CID: 215-218
Found with: Coverity Prevent(tm)
Submitted by: ariff
MFC after: 5 days


# da8623ec 25-Jan-2006 Joel Dahl <joel@FreeBSD.org>

Fix typos and clean up some comments.

Approved by: ariff


# 2fd8d3d8 16-Jan-2006 Ariff Abdullah <ariff@FreeBSD.org>

Restore old compatibility of feeding directly into /dev/dsp at 8000 hz
while preserving the New World Order.

Discussed with: [1] Michael W. Oliver <michael at gargantuan.com>
MFC after: 1 week

[1] http://lists.freebsd.org/pipermail/freebsd-multimedia/2006-January/003562.html


# c3ebbcbd 30-Dec-2005 Ariff Abdullah <ariff@FreeBSD.org>

Fix LOR #174.

Tested with: WITNESS, INVARIANTS and DIAGNOSTICS


# f935ac60 30-Dec-2005 Ariff Abdullah <ariff@FreeBSD.org>

Disable frantic DMA update within few SNDCTL_DSP_* ioctl.
This should reduce huge playback / recording latency for
applications that try to act smarter and manage their own
buffering (XMMS, Skype, etc.).

Note to Skype + via8xxx users: Remove previous hackish
"hint.pcm.<unit>.via_dxs_disabled" from kernel hint and see
whether this changes cure all those annoying sound issues.


# ee43f8a6 14-Nov-2005 Ariff Abdullah <ariff@FreeBSD.org>

From luigi:
In SNDCTL_DSP_SETFRAGMENT, if you specify both read and
write channels, the existing code first acts on the
read channel, but as a side effect it updates the
arguments (maxfrags, fragsz) passed by the caller according
to acceptable values for the read channel, and then uses the
modified values to act on the write channel.
The problem with this approach is that, given a
(maxfrags, fragsz) user-specified value, the actual
values computed by the read and write channels may differ:
e.g. the read channel might want to allocate more fragments
than what the user specified because it has no side-effects
on the delay and it helps in case of slow readers,
whereas the write channel needs to use as few fragments
as possible to keep the audio latency low (very important
with telephony apps).

This patch stores the values computed by the read channel
into temproary variables so the write channel will use
the actual arguments of the ioctl.

This patch is very helpful with telephony apps such as asterisk.

Submitted by: luigi
Approved by: netchild (mentor)


# 8be20fbe 03-Nov-2005 Ariff Abdullah <ariff@FreeBSD.org>

Appropriate NULL pointer checking to avoid mysterious panic during
device cloning.

Approved by: netchild (mentor)


# 85cc3851 30-Oct-2005 Dag-Erling Smørgrav <des@FreeBSD.org>

Add some safeguards to AIOSFMT:

- Return EINVAL if play_format or rec_format is set but the corresponding
sample rate is 0.

- Don't try to set the playback or recording format to 0. Previously,
issuing an AIOSFMT ioctl with an all-zeroes snd_chan_param would
trigger a KASSERT in chn_fmtchain(); I'm unsure about the effects on
a kernel without INVARIANTS. After this commit, issuing AIOSFMT with
an all-zeroes snd_chan_param is equivalent to issuing AIOGFMT.

MFC after: 2 weeks


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

General spl* cleanup. It doesn't serve any purpose anymore.

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


# 831a62e7 12-Sep-2005 Alexander Leidinger <netchild@FreeBSD.org>

- Fix the locking in dsp.c to prevent a LOR (AFAIK not on the LOR page).

- Remove an assertion in sound.c, it's not needed (and causes a panic now).
From the conversation via mail between glebius and Ariff:
---snip---
> Well, but which mutex protects now? Do we own anything else
> in pcm_chnalloc()? I see some queue(4) macros in pcm_chnalloc(),
> they should be protected, shouldn't they?
Queue insertion/removal occur during
1) driver loading (which is pretty much single thread /
sequential) or unloading (mutex protected, bail out if there is
any channel with refcount > 0 or busy).
2) vchan_create()/destroy(), (which is *sigh* quite complicated), but
somehow protected by 'master'/parent channel mutex. Other
thread cannot add/remove vchan (or even continue traversing
that queue) unless it can acquire parent channel mutex.
---snip---

Fix the locking in dsp.c to prevent a LOR (AFAIK not on the LOR page).

Submitted by: Ariff Abdullah <skywizard@MyBSD.org.my>
Tested with: INVARIANTS[1] and DIAGNOSTICS[2]
Tested by: netchild [1,2], David Reid <david@jetnet.co.uk> [1]


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

Release lock for a while during chn_reset() / pcm_chnalloc() operation
while malloc()ing, this fixes LOR 129.

See
- http://lists.freebsd.org/pipermail/freebsd-current/2005-June/051157.html
- http://lists.freebsd.org/pipermail/freebsd-current/2005-August/054620.html
- http://sources.zabbadoz.net/freebsd/lor.html#129

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


# 6a113b3d 08-Aug-2005 Robert Watson <rwatson@FreeBSD.org>

Merge the dev_clone and dev_clone_cred event handlers into a single
event handler, dev_clone, which accepts a credential argument.
Implementors of the event can ignore it if they're not interested,
and most do. This avoids having multiple event handler types and
fall-back/precedence logic in devfs.

This changes the kernel API for /dev cloning, and may affect third
party packages containg cloning kernel modules.

Requested by: phk
MFC after: 3 days


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


# f4f6abcb 30-Mar-2005 Poul-Henning Kamp <phk@FreeBSD.org>

Explicitly hold a reference to the cdev we have just cloned. This
closes the race where the cdev was reclaimed before it ever made it
back to devfs lookup.


# 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


# a92c890f 02-Jul-2004 Alexander Leidinger <netchild@FreeBSD.org>

Implement SNDCTL_DSP_SETDUPLEX. This may fix sound apps which want to
use full duplex mode.

Approved by: matk


# f3732fd1 17-Jun-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Second half of the dev_t cleanup.

The big lines are:
NODEV -> NULL
NOUDEV -> NODEV
udev_t -> dev_t
udev2dev() -> findcdev()

Various minor adjustments including handling of userland access to kernel
space struct cdev etc.


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

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


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

Lock channels only as necessary in dsp_ioctl(), and only lock one
channel at a time unless it is actually necessary to lock both.
This avoids problems with lock order reversal and malloc() calls
with a mutex held when lower level code unlocks a channel, calls malloc(),
and relocks the channel. This also avoids the cost of some unnecessary
locking and unlocking.

Tested by: matk


# dc08ffec 21-Feb-2004 Poul-Henning Kamp <phk@FreeBSD.org>

Device megapatch 4/6:

Introduce d_version field in struct cdevsw, this must always be
initialized to D_VERSION.

Flip sense of D_NOGIANT flag to D_NEEDGIANT, this involves removing
four D_NOGIANT flags and adding 145 D_NEEDGIANT flags.


# 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>


# e7245381 25-Jan-2004 Mathew Kanner <matk@FreeBSD.org>

Fix a panic in dsp_clone when trying to access a sound
device that doesn't exists. I'm using my discretion and
committing without mentor approval since Seigo is away.

Noticed by: Maxime Henrion <mux@freebsd.org>


# 222d2384 19-Jan-2004 Mathew Kanner <matk@FreeBSD.org>

Reduce latency when using the SNDCTL_DSP_RESET ioctl by calling
chn_resetbuf().

Submited by: Pyun YongHyeon <yongari@kt-is.co.kr>
Approved by: tanimura (mentor)


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


# 42c3555c 10-Nov-2003 Scott Long <scottl@FreeBSD.org>

Fix sound LOR problems:

dsp_open: rearrange to only hold one lock at a time

dsp_close: ditto

mixer_hwvol_init: delete locking, the only consumer seems to
be the ess driver and it only call it a creation time, I
think the device will be stable across the sleepable malloc.

cmi interrupt routine: Release locks while caller chn_intr,
either this or do what emu10k1 does which is have no locks
at in the interrupt handler.

Submitted by: mat@cnd.mcgill.ca


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

update my email address.


# b9c6d8cd 14-Aug-2003 Cameron Grant <cg@FreeBSD.org>

modify comments


# f1e875be 26-Jun-2003 Matthew N. Dodd <mdodd@FreeBSD.org>

Set a lower bound on fragment size rather than returning a failure
when the user specifies a maximum fragment size < 2.

This is the behavior that Linux provides and fixes the problem I've
observed in Tribes2 where sounds effects are delayed by 1/2 a second.


# 4f3204ef 01-May-2003 Orion Hodson <orion@FreeBSD.org>

Fix lock order reversal when opening device and chn_reset fails.

Submitted by: Jan-Espen Pettersen <sigsegv@leakingmemory.org>
Tested by: Georg Funk <georgfunk@web.de>


# 227f9a1c 24-Mar-2003 Jake Burkholder <jake@FreeBSD.org>

- Add vm_paddr_t, a physical address type. This is required for systems
where physical addresses larger than virtual addresses, such as i386s
with PAE.
- Use this to represent physical addresses in the MI vm system and in the
i386 pmap code. This also changes the paddr parameter to d_mmap_t.
- Fix printf formats to handle physical addresses >4G in the i386 memory
detection code, and due to kvtop returning vm_paddr_t instead of u_long.

Note that this is a name change only; vm_paddr_t is still the same as
vm_offset_t on all currently supported platforms.

Sponsored by: DARPA, Network Associates Laboratories
Discussed with: re, phk (cdevsw change)


# 7ac40f5f 02-Mar-2003 Poul-Henning Kamp <phk@FreeBSD.org>

Gigacommit to improve device-driver source compatibility between
branches:

Initialize struct cdevsw using C99 sparse initializtion and remove
all initializations to default values.

This patch is automatically generated and has been tested by compiling
LINT with all the fields in struct cdevsw in reverse order on alpha,
sparc64 and i386.

Approved by: re(scottl)


# 07159f9c 24-Feb-2003 Maxime Henrion <mux@FreeBSD.org>

Cleanup of the d_mmap_t interface.

- Get rid of the useless atop() / pmap_phys_address() detour. The
device mmap handlers must now give back the physical address
without atop()'ing it.
- Don't borrow the physical address of the mapping in the returned
int. Now we properly pass a vm_offset_t * and expect it to be
filled by the mmap handler when the mapping was successful. The
mmap handler must now return 0 when successful, any other value
is considered as an error. Previously, returning -1 was the only
way to fail. This change thus accidentally fixes some devices
which were bogusly returning errno constants which would have been
considered as addresses by the device pager.
- Garbage collect the poorly named pmap_phys_address() now that it's
no longer used.
- Convert all the d_mmap_t consumers to the new API.

I'm still not sure wheter we need a __FreeBSD_version bump for this,
since and we didn't guarantee API/ABI stability until 5.1-RELEASE.

Discussed with: alc, phk, jake
Reviewed by: peter
Compile-tested on: LINT (i386), GENERIC (alpha and sparc64)
Runtime-tested on: i386


# d00d7d5c 11-Feb-2003 Brian Feldman <green@FreeBSD.org>

Sound devices were being leaked by dsp_open() not actually releasing the
channels it allocates if chn_reset() on them resulted in failure.
ARROW'D!


# a8be3e63 05-Jan-2003 Brian Feldman <green@FreeBSD.org>

Fix the duplicate unlock of the pcm read channel in certain cases.

Reviewed by: cg


# 47d5a0f3 28-Aug-2002 Orion Hodson <orion@FreeBSD.org>

Marginally simplify dsp_open error handling by adding an early test to
determine liklihood of opening device in requested directions. Makes for
simpler error handling and change should close kern/35004.

PR: kern/35004.


# 22967090 20-Aug-2002 Orion Hodson <orion@FreeBSD.org>

Back out last commit. Needs slightly more subtle handling.


# 42e67fd3 18-Aug-2002 Orion Hodson <orion@FreeBSD.org>

Apply reference counting patch. Fixes problem of two applications
opening the device, eg one read only and one write only, and the
reference count being non-zero when both exit rendering device
permanently busy.

PR: kern/35004
Submitted by: Bill Wells
MFC after: 3 days


# 436c9b65 24-Jan-2002 Scott Long <scottl@FreeBSD.org>

Fix code that had rotted behind debugging macros.

Approved by: cg (in principle)
MFC after: 2 weeks


# 095159ec 22-Jan-2002 Cameron Grant <cg@FreeBSD.org>

add more error checking to open of /dev/dsp* and /dev/audio* - if the
default format for the chosen subdevice cannot be obtained return an error
instead of returning success with an indeteterminate format selected.

note that this should never happen once the feederchain builder works for
recording.


# 1c72c53f 22-Jan-2002 Cameron Grant <cg@FreeBSD.org>

don't allow mmap beyond the end of the buffer

Submitted by: Philippe Anel <philippe.anel@noos.fr> (partially)


# 16a33022 23-Oct-2001 Cameron Grant <cg@FreeBSD.org>

fix SNDCTL_DSP_GETISPACE behaviour


# 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


# b40ce416 12-Sep-2001 Julian Elischer <julian@FreeBSD.org>

KSE Milestone 2
Note ALL MODULES MUST BE RECOMPILED
make the kernel aware that there are smaller units of scheduling than the
process. (but only allow one thread per process at this time).
This is functionally equivalent to teh previousl -current except
that there is a thread associated with each process.

Sorry john! (your next MFC will be a doosie!)

Reviewed by: peter@freebsd.org, dillon@freebsd.org

X-MFC after: ha ha ha ha


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


# 334326a1 22-Aug-2001 Cameron Grant <cg@FreeBSD.org>

handle bogus values passed to SOUND_PCM_WRITE_CHANNELS/SNDCTL_DSP_CHANNELS
ioctls better- if 0 is passed, return the current setting. if 1 or 2 are
passed, behave accordingly. treat values >2 as 2.

PR: kern/29964


# 92f39b2c 23-Aug-2001 Cameron Grant <cg@FreeBSD.org>

MFS: make SNDCTL_DSP_SETTRIGGER work


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


# c76f0116 01-Jul-2001 Cameron Grant <cg@FreeBSD.org>

don't set a flag that is already set


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

tidy up/simplify dsp_clone()


# 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


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

use devclass_get_maxunit() correctly


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


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

fix a potential panic in dsp_clone() if no pcm devices were detected


# 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


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


# 9a1ec7eb 13-Mar-2001 Cameron Grant <cg@FreeBSD.org>

fix a panic triggerable by anyone with read/write access to the audio
devices. opening /dev/{dsp,dspW,audio}0 and then opening a different device
from that list and closing it resulted in a panic when any operation is
performed on the first fd.

we prevent this happening by denying the second open unless it uses the same
minor device as the first.

PR: kern/25519


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


# 41b3c726 06-Nov-2000 Cameron Grant <cg@FreeBSD.org>

if a channel dies, rejuvenate it on close()


# d16b5673 27-Oct-2000 Cameron Grant <cg@FreeBSD.org>

implement SNDCTL_DSP_POST


# c0960a5e 25-Oct-2000 Cameron Grant <cg@FreeBSD.org>

handle AFMT_QUERY right


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


# fa06efc7 19-Aug-2000 Cameron Grant <cg@FreeBSD.org>

fix SNDCTL_DSP_GETODELAY

PR: kern/20340
Submitted by: Takashi SHIRAI <shirai@nintendo.co.jp>


# 05a1fdb4 02-Aug-2000 Nick Sayer <nsayer@FreeBSD.org>

Simplex devices will always report EBUSY on 2nd (and subsequent)
opens if the reference count is not decremented on close.

Note that this may result in the reference count being corrupted
on full duplex devices (due to mismatching opens/closes), but the
code doesn't use the reference count for anything on full duplex
devices.


# e04387c9 30-Jul-2000 Cameron Grant <cg@FreeBSD.org>

fix a bug where opening /dev/dsp twice resulted in it being busy until reboot


# e4d5b250 20-Jun-2000 Cameron Grant <cg@FreeBSD.org>

fix a bug where opening for write would not fail if channel allocation failed

when playing, if we stall for 1s with no data advancing, abort and mark the
channel dead - fail all future operations


# 1a50bd2e 07-Jun-2000 Cameron Grant <cg@FreeBSD.org>

handle duplex properly in the AIOGCAP ioctl - this may (partially?) fix rat


# 94e3845c 27-May-2000 Cameron Grant <cg@FreeBSD.org>

fix the return value of the SOUND_PCM_WRITE_CHANNELS ioctl

re-enable old pcm ioctls


# d28089a1 26-May-2000 Cameron Grant <cg@FreeBSD.org>

move various fields from pcm_channel to snd_dbuf

improve chn_read code- don't stop/restart on overrun, just dump data

more error checking on ioctls


# eb95c536 29-Apr-2000 Poul-Henning Kamp <phk@FreeBSD.org>

Remove unneeded #include <sys/kernel.h>


# a0e22dd8 23-Apr-2000 Cameron Grant <cg@FreeBSD.org>

implement settrigger according to spec

fixes for non-blocking mode


# 8ae4c159 17-Apr-2000 Cameron Grant <cg@FreeBSD.org>

more mmap fixes


# 603ddb6d 14-Apr-2000 Cameron Grant <cg@FreeBSD.org>

make mmap sort-of work. there seem to be interactions with certain hw
drivers, so still work in progress.

do various mmap-related ioctls right.

improve blocksize control.

bits of cleanup.


# bd18f334 04-Apr-2000 Cameron Grant <cg@FreeBSD.org>

allow /dev/dsp to be opened seperately for reading and writing.


# 45248baa 26-Jan-2000 Cameron Grant <cg@FreeBSD.org>

handle simplex devices right


# 898cb2af 10-Jan-2000 Cameron Grant <cg@FreeBSD.org>

make dsp_read() assert that it has a read channel, not a write channel

Submitted by: green


# 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


# 5f070b67 12-Dec-1999 Cameron Grant <cg@FreeBSD.org>

more dma underrun fixes, using a per-channel 2nd buffer

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


# 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


# 4d25c041 29-Nov-1999 Alfred Perlstein <alfred@FreeBSD.org>

tanimura implemented SNDCTL_DSP_GETODELAY for pcm.

Submitted by: tanimura


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

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


# 62c631ed 13-Nov-1999 Doug Rabson <dfr@FreeBSD.org>

* Ignore the wierd fakechan workarounds for simplex in dsp_ioctl().
Without this, ioctl commands for setting formats and speeds were
essentially ignored for simplex devices until the application actually
performed a read or write.
* Make sure that both channels are set in the SB mixer code and provide a
mixer table specifically for the ess18xx which supports the extended
accuracy available on this part.
* Fix a stupid bug in ess_format() which ignored the passed-in format and
changed the hardware based on the value which was set last time. This
meant that the hardware setting was often not set correctly at all.
* Add a custom identify driver for the ESS1888 which automagically detects
and adds the device in a pseudo-PnP way. This driver also emits the magic
sequence which enables the sound hardware after a hard reset, allowing
it to work correctly for the sound hardware of a PWS 433au (and probably
all other PWS class alpha machines).

With these changes, I was able to play back simple sounds on my 433au. I
have not tested recording or any other formats other than 8bit ulaw and
16bit stereo.


# 35e6a54a 06-Nov-1999 Seigo Tanimura <tanimura@FreeBSD.org>

Conserve stereo mode in ioctl SNDCTL_DSP_SETFMT.

PR: 14372
Submitted by: Mattias Pantzare <pantzer@ludd.luth.se>, Ville-Pertti Keinonen <will@iki.fi>


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


# fc809073 19-Sep-1999 Peter Wemm <peter@FreeBSD.org>

Fix the "dsp sync" debugging printf that was unconditional. Fix a few
formatting nits/glitches/whatever.


# 4a848083 04-Sep-1999 Cameron Grant <cg@FreeBSD.org>

bugfix: deallocate channels properly if no read/write ops between open/close


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