History log of /openbsd-current/sys/dev/pci/neo.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.42 24-May-2024 jsg

remove unneeded includes; ok miod@


# 1.41 13-May-2024 jsg

remove prototypes with no matching function
ok mpi@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.40 26-Oct-2022 kn

Make audio(9) get_props() optional, remove it from duplex drivers

The property bits of audio(9) are obsolete and ought to be removed
completely.

sys/dev/audio.c:audio_open() currently uses get_props() to bail out if
read *and* write was requested on a non-duplex driver.

Drivers that currently support playing but not recording need adjustment
before the API can be cleaned up.

Drivers that advertise themselves as full duplex, i.e. those that always
return AUDIO_PROP_FULLDUPLEX unconditionally in their get_props() currently
always succeed this check.

As this is the only property, losen audio_open()'s DIAGNOSTIC check and only
do the duplex check if the driver provides get_props().

This allows for simple removal of get_props() from full-duplex drivers
without adding any other code or without changing functionality.

This includes all audio drivers under sys/dev/pci/ (maestro(4) being the
only unfinished exception here).

Other drivers as well as the API change can then follow in smaller diffs.

This builds on amd64, arm64, i386, macppc and sparc64.
amd64 with azalia(4) still plays, records as well as plays and records
at the same time on my X230 as tested with

$ aucat -i play.wav [-o rec.wav]

alpha and hppa tests by miod
OK ratchov miod


# 1.39 19-Oct-2022 kn

Use C99 struct init for struct audio_hw_if

This audio(9) struct will lose a member, but drivers init their struct quite
inconsistently, most pre-C99 style.

Use C99 style everywhere, to get rid of all annoying differences and allow
for easy member removals/additions:
- don't change current order of members
- no explicit NULL members
- no comments or blank lines
- trailing comma in last member line

GENERIC.MP builds fine with this on arm64, amd64, i386 and sparc64.

macppc and alpha build-tested by miod
OK ratchov miod


# 1.38 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 21-Mar-2022 miod

Constify struct {audio,midi,radio,video}_hw_if. No functional change.

ok mpi@ ratchov@ "More const is good" deraadt@


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.41 13-May-2024 jsg

remove prototypes with no matching function
ok mpi@


Revision tags: OPENBSD_7_3_BASE OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.40 26-Oct-2022 kn

Make audio(9) get_props() optional, remove it from duplex drivers

The property bits of audio(9) are obsolete and ought to be removed
completely.

sys/dev/audio.c:audio_open() currently uses get_props() to bail out if
read *and* write was requested on a non-duplex driver.

Drivers that currently support playing but not recording need adjustment
before the API can be cleaned up.

Drivers that advertise themselves as full duplex, i.e. those that always
return AUDIO_PROP_FULLDUPLEX unconditionally in their get_props() currently
always succeed this check.

As this is the only property, losen audio_open()'s DIAGNOSTIC check and only
do the duplex check if the driver provides get_props().

This allows for simple removal of get_props() from full-duplex drivers
without adding any other code or without changing functionality.

This includes all audio drivers under sys/dev/pci/ (maestro(4) being the
only unfinished exception here).

Other drivers as well as the API change can then follow in smaller diffs.

This builds on amd64, arm64, i386, macppc and sparc64.
amd64 with azalia(4) still plays, records as well as plays and records
at the same time on my X230 as tested with

$ aucat -i play.wav [-o rec.wav]

alpha and hppa tests by miod
OK ratchov miod


# 1.39 19-Oct-2022 kn

Use C99 struct init for struct audio_hw_if

This audio(9) struct will lose a member, but drivers init their struct quite
inconsistently, most pre-C99 style.

Use C99 style everywhere, to get rid of all annoying differences and allow
for easy member removals/additions:
- don't change current order of members
- no explicit NULL members
- no comments or blank lines
- trailing comma in last member line

GENERIC.MP builds fine with this on arm64, amd64, i386 and sparc64.

macppc and alpha build-tested by miod
OK ratchov miod


# 1.38 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 21-Mar-2022 miod

Constify struct {audio,midi,radio,video}_hw_if. No functional change.

ok mpi@ ratchov@ "More const is good" deraadt@


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.40 26-Oct-2022 kn

Make audio(9) get_props() optional, remove it from duplex drivers

The property bits of audio(9) are obsolete and ought to be removed
completely.

sys/dev/audio.c:audio_open() currently uses get_props() to bail out if
read *and* write was requested on a non-duplex driver.

Drivers that currently support playing but not recording need adjustment
before the API can be cleaned up.

Drivers that advertise themselves as full duplex, i.e. those that always
return AUDIO_PROP_FULLDUPLEX unconditionally in their get_props() currently
always succeed this check.

As this is the only property, losen audio_open()'s DIAGNOSTIC check and only
do the duplex check if the driver provides get_props().

This allows for simple removal of get_props() from full-duplex drivers
without adding any other code or without changing functionality.

This includes all audio drivers under sys/dev/pci/ (maestro(4) being the
only unfinished exception here).

Other drivers as well as the API change can then follow in smaller diffs.

This builds on amd64, arm64, i386, macppc and sparc64.
amd64 with azalia(4) still plays, records as well as plays and records
at the same time on my X230 as tested with

$ aucat -i play.wav [-o rec.wav]

alpha and hppa tests by miod
OK ratchov miod


# 1.39 19-Oct-2022 kn

Use C99 struct init for struct audio_hw_if

This audio(9) struct will lose a member, but drivers init their struct quite
inconsistently, most pre-C99 style.

Use C99 style everywhere, to get rid of all annoying differences and allow
for easy member removals/additions:
- don't change current order of members
- no explicit NULL members
- no comments or blank lines
- trailing comma in last member line

GENERIC.MP builds fine with this on arm64, amd64, i386 and sparc64.

macppc and alpha build-tested by miod
OK ratchov miod


# 1.38 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 21-Mar-2022 miod

Constify struct {audio,midi,radio,video}_hw_if. No functional change.

ok mpi@ ratchov@ "More const is good" deraadt@


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.39 19-Oct-2022 kn

Use C99 struct init for struct audio_hw_if

This audio(9) struct will lose a member, but drivers init their struct quite
inconsistently, most pre-C99 style.

Use C99 style everywhere, to get rid of all annoying differences and allow
for easy member removals/additions:
- don't change current order of members
- no explicit NULL members
- no comments or blank lines
- trailing comma in last member line

GENERIC.MP builds fine with this on arm64, amd64, i386 and sparc64.

macppc and alpha build-tested by miod
OK ratchov miod


# 1.38 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 21-Mar-2022 miod

Constify struct {audio,midi,radio,video}_hw_if. No functional change.

ok mpi@ ratchov@ "More const is good" deraadt@


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.39 19-Oct-2022 kn

Use C99 struct init for struct audio_hw_if

This audio(9) struct will lose a member, but drivers init their struct quite
inconsistently, most pre-C99 style.

Use C99 style everywhere, to get rid of all annoying differences and allow
for easy member removals/additions:
- don't change current order of members
- no explicit NULL members
- no comments or blank lines
- trailing comma in last member line

GENERIC.MP builds fine with this on arm64, amd64, i386 and sparc64.

macppc and alpha build-tested by miod
OK ratchov miod


# 1.38 18-Oct-2022 kn

Remove unused AUDIO_PROP_{MMAP,INDEPENDENT}

AUDIO_PROP_FULLDUPLEX is the only audio(9) in use, the other two died with
commit 1cf2860827c8ca659d8097d8da94a5ae5b888c53
Author: ratchov <ratchov@openbsd.org>
Date: Thu Jun 25 06:43:45 2015 +0000

Reimplement the audio driver in a simpler way, removing unused/unusable
functionality. Same API and ABI except for the removed bits and no
behaviour change for programs using libsndio. With help from armani@
and mpi@, thanks.

but remained defined and set in drivers.

and the following merely moved them when they were dead code already:

commit 9215aa3dfad387bca877a805534df6dcfe8722eb
Author: ratchov <ratchov@openbsd.org>
Date: Wed Aug 31 07:22:43 2016 +0000

Delete unused ioctls and associated macros. Move macros that are still
used internally by low-level drivers from sys/audioio.h to
dev/audio_if.h instead of deleting them.

None of this is used in base or ports; codesearch.debian.net only shows
AUDIO_PROP_{CAPTURE,PLAYBACK} in firefox-esr, mozjs and cubeb.

ratchov points out that audio_if.h and audioio.h are private interfaces
and the codesearch shows SunOS and NetBSD bits (#ifdef'd out on OpenBSD).

OK ratchov


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE
# 1.37 21-Mar-2022 miod

Constify struct {audio,midi,radio,video}_hw_if. No functional change.

ok mpi@ ratchov@ "More const is good" deraadt@


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.37 21-Mar-2022 miod

Constify struct {audio,midi,radio,video}_hw_if. No functional change.

ok mpi@ ratchov@ "More const is good" deraadt@


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.36 11-Mar-2022 mpi

Constify struct cfattach.


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.35 16-Feb-2022 anton

Make room for a cookie argument passed to audio_attach_mi(). Currently
unused but intended to be used to correlate audio and wskbd devices.

ok ratchov@


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.34 09-Jan-2022 jsg

spelling
feedback and ok tb@ jmc@ ok ratchov@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE OPENBSD_6_6_BASE OPENBSD_6_7_BASE OPENBSD_6_8_BASE OPENBSD_6_9_BASE OPENBSD_7_0_BASE
# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


# 1.33 11-Apr-2018 ratchov

Add mixer save/restore capability to the audio(4) driver and
use it during suspend/resume. Remove driver-specific mixer
save/restore bits that don't need to be duplicated in every
low-lever driver.

ok mpi


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE OPENBSD_6_3_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer


Revision tags: OPENBSD_6_1_BASE OPENBSD_6_2_BASE
# 1.32 19-Sep-2016 ratchov

Remove unused getdev() audio driver functions.


# 1.31 14-Sep-2016 ratchov

Remove drain(), query_encoding(), mappage() and get_default_params()
methods from all audio drivers and from the audio_if structure as they
are never called.


Revision tags: OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.30 11-May-2015 ratchov

Remove all audio format conversion code from the kernel (btw holding
the kernel_lock), as we already do better conversions in
user-mode. Yet, no need for every single driver to fiddle with the
conversion code as they are done transparently by common MI code. With
help from armani and miod, support from mpi

ok armani@


Revision tags: OPENBSD_5_5_BASE OPENBSD_5_6_BASE OPENBSD_5_7_BASE
# 1.29 15-Nov-2013 brad

ansify some function definitions.
no functional change.

ok sthen@


Revision tags: OPENBSD_5_4_BASE
# 1.28 24-May-2013 ratchov

Since audio code is mp safe, establish isa and pci audio interrupts
with the IPL_MPSAFE flag. In certain circumstances, this prevents
interrupt handlers from waiting the global kernel_lock possibly (hold
by slower code) to be released.

ok kettenis


# 1.27 15-May-2013 ratchov

Introduce a global interrupt-aware mutex protecting data
structures (including sound-card registers) from concurent
access by syscall and interrupt code-paths. Since critical
sections remain the same, calls to splraise/spllower can be
safely replaced by calls to mtx_enter/mtx_leave with two
exceptions: (1) mutexes are not reentrant (the inner splraise
is thus removed), and (2) we're not allowed to sleep with a
mutex (either msleep is used or the mutex is released before
sleeping).

ok and help from kettenis, a lot of work from armani


Revision tags: OPENBSD_4_9_BASE OPENBSD_5_0_BASE OPENBSD_5_1_BASE OPENBSD_5_2_BASE OPENBSD_5_3_BASE
# 1.26 07-Sep-2010 deraadt

remove the powerhook code. All architectures now use the ca_activate tree
traversal code to suspend/resume
ok oga kettenis blambert


# 1.25 27-Aug-2010 deraadt

Mangle neo_power's contents into a neo_activate function, then make
neo_power into a stub which calls it. Tested on an ancient z505r; my
first laptop....


Revision tags: OPENBSD_4_8_BASE
# 1.24 15-Jul-2010 jakemsr

add two new members to structs audio_encoding and audio_prinfo.
for both structs, the new members are 'bps' and 'msb', which
describe the number of bytes per sample and data alignment in the
sample, respectively. drivers must properly set these fields in
the 'query_encoding', 'set_parameters' and 'get_default_params'
hardware interface methods.

discussed with ratchov, deraadt


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE OPENBSD_4_7_BASE
# 1.23 25-Oct-2008 jakemsr

audio(9) says low level drivers are allowed to change the requested
values of the audio_params structure during AUDIO_SETINFO if the
hardware cannot be set to exactly the requested mode.

some drivers do this sometimes. others always return EINVAL if there
isn't an exact match.

be more consistent. only return EINVAL if an absurd parameter was
requested, otherwise return a supported set of parameters, as close
as possible to what was requested.

with/ok ratchov@


Revision tags: OPENBSD_4_4_BASE
# 1.22 29-May-2008 jakemsr

use ac97 default parameters for these ac97 based drivers.

this makes the emulation expansion factor 1 by default since there's no
emulation. previously the factor was 2 because these drivers emulate
8-bit ulaw playback with 16-bit linear encodings. having a factor
other than 1 by default creates block size and hiwat/lowat issues
with applications that set the block size and hiwat before other
parameters.

ok ratchov@


# 1.21 21-Apr-2008 jakemsr

allow low level audio drivers to specify a default sample format,
instead of 8-bit mono mulaw @ 8kHz.

this is just the infrastructure; no drivers are specifying a default
yet.

ok ratchov@, deanna@


Revision tags: OPENBSD_4_3_BASE
# 1.20 05-Nov-2007 jakemsr

audio encoding conversion cleanup

- the endianness of the conversions don't depend on the endianness
of machine the conversions are built on, but the endianness of the
audio data itself. choose encoding conversions explicitly, instead
of relying on #defines based on the endianness of the machine.
- replace home-grown conversions with comparable conversions in
auconv.c and mulaw.c
- use the proper conversion for ulinear_be:16 -> slinear_le:16 in
auixp(4)

thanks ajacoutot@ and sthen@ for !x86 testing


Revision tags: OPENBSD_3_8_BASE OPENBSD_3_9_BASE OPENBSD_4_0_BASE OPENBSD_4_1_BASE OPENBSD_4_2_BASE
# 1.19 09-Aug-2005 mickey

do not set PCI_COMMAND_MASTER_ENABLE explicitly as it's already set in pcisubmatch(); kettenis@ testing; brad@ ok


Revision tags: OPENBSD_3_7_BASE
# 1.18 12-Dec-2004 deraadt

remove old microcode include


# 1.17 22-Nov-2004 deraadt

filesystem firmware loading


Revision tags: OPENBSD_3_4_BASE OPENBSD_3_5_BASE OPENBSD_3_6_BASE SMP_SYNC_A SMP_SYNC_B UBC_SYNC_A
# 1.16 27-Apr-2003 ho

strcpy/sprintf cleanup of sys/dev. miod@, deraadt@ says to commit.


Revision tags: OPENBSD_3_3_BASE
# 1.15 21-Mar-2003 jason

install a powerhook to restore the AC97 state after suspend;
aditya at dsl dot cis dot upenn dot edu via pr 3165; ok millert


# 1.14 21-Feb-2003 tedu

remove unused variable

ok mickey@


Revision tags: UBC_SYNC_B
# 1.13 04-Oct-2002 mickey

formatting, grammar, spaces; from grendel@zeitbombe.org


Revision tags: OPENBSD_3_1_BASE OPENBSD_3_2_BASE
# 1.12 14-Mar-2002 millert

Final __P removal plus some cosmetic fixups


# 1.11 14-Mar-2002 millert

First round of __P removal in sys


# 1.10 20-Jan-2002 ericj

make all audio drivers use the new allocm and round_buffersize decl's.
will ease porting, and generally cleans up a bit


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.9 16-Sep-2001 art

branches: 1.9.4;
Typos in comments.
From Alexander Yurchenko <grange@rt.mipt.ru>


# 1.8 25-Aug-2001 art

Change pci_intr_map to take pci_attach_args as an argument.
All callers actually took all arguments to pci_intr_map from pci_attach_args
structs, so this simplifies code.
This also allows more complicated interrupt assignment schemes like the one
on sparc64.

This makes sparc64 pci interrupts work.

Inspired by the same change in NetBSD.


# 1.7 18-Jun-2001 deraadt

more more microcode (so it does not end up installed in includes, for one)


# 1.6 12-Jun-2001 niklas

Make pci_mapreg_map take an extra argument where we can
put a size limitation of the PCI region to map. That makes the PERC 3/Di
raid controller usable, as it publishes too much PCI memory for us to map
in the kernel virtual memory. As we only access the first 256 byte it is
of no use to map 128MB of kvm.


Revision tags: OPENBSD_2_9_BASE
# 1.5 03-Mar-2001 deraadt

branches: 1.5.4;
use AC97_HOST_DONT_READANY since some machines are unreliable


Revision tags: OPENBSD_2_8_BASE
# 1.4 19-Jul-2000 csapuntz

As in NetBSD, added direction to allocm/round_buffer_size APIs.
Accomplished by adding functions to audio_hw_if instead of redoing
current ones so as to minimize need to change drivers.

For Neomagic, tell the AC97 subsystem that we don't support reads.


Revision tags: OPENBSD_2_7_BASE
# 1.3 14-Apr-2000 csapuntz

Some documentation for future generations of maintainers


# 1.2 13-Apr-2000 csapuntz

Remove printf from interrupt handler...

Use blksize more aggressively instead of hard-wiring it everywhere

Fix to nm_waitcd and neo_malloc. neo_malloc still ain't pretty.


# 1.1 13-Apr-2000 csapuntz

NeoMagic 256AV/ZX audio driver

Still in beta.

May lock up your machine when accessing mixer