FreeBSD kernel sound device code
sound.c File Reference
#include <dev/sound/pcm/sound.h>
#include <dev/sound/pcm/ac97.h>
#include <dev/sound/pcm/vchan.h>
#include <dev/sound/pcm/dsp.h>
#include <dev/sound/pcm/sndstat.h>
#include <dev/sound/version.h>
#include <sys/limits.h>
#include <sys/sysctl.h>
#include "feeder_if.h"
Include dependency graph for sound.c:

Go to the source code of this file.

Functions

 SND_DECLARE_FILE ("$FreeBSD$")
 
 SYSCTL_INT (_hw_snd, OID_AUTO, default_auto, CTLFLAG_RWTUN, &snd_unit_auto, 0, "assign default unit to a newly attached device")
 
 SYSCTL_NODE (_hw, OID_AUTO, snd, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "Sound driver")
 
static void pcm_sysinit (device_t)
 
 SYSCTL_STRING (_hw_snd, OID_AUTO, version, CTLFLAG_RD, &snd_driver_version, 0, "driver version/arch")
 
static int sndstat_prepare_pcm (SNDSTAT_PREPARE_PCM_ARGS)
 
void * snd_mtxcreate (const char *desc, const char *type)
 
void snd_mtxfree (void *m)
 
void snd_mtxassert (void *m)
 
int snd_setup_intr (device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
 
static void pcm_clonereset (struct snddev_info *d)
 
int pcm_setvchans (struct snddev_info *d, int direction, int newcnt, int num)
 
int pcm_chnalloc (struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, char *comm, int devunit)
 
int pcm_chnrelease (struct pcm_channel *c)
 
int pcm_chnref (struct pcm_channel *c, int ref)
 
int pcm_inprog (struct snddev_info *d, int delta)
 
static void pcm_setmaxautovchans (struct snddev_info *d, int num)
 
static int sysctl_hw_snd_default_unit (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_hw_snd, OID_AUTO, default_unit, CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_ANYBODY|CTLFLAG_NEEDGIANT, 0, sizeof(int), sysctl_hw_snd_default_unit, "I", "default sound device")
 
static int sysctl_hw_snd_maxautovchans (SYSCTL_HANDLER_ARGS)
 
 SYSCTL_PROC (_hw_snd, OID_AUTO, maxautovchans, CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_NEEDGIANT, 0, sizeof(int), sysctl_hw_snd_maxautovchans, "I", "maximum virtual channel")
 
struct pcm_channelpcm_chn_create (struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo)
 
int pcm_chn_destroy (struct pcm_channel *ch)
 
int pcm_chn_add (struct snddev_info *d, struct pcm_channel *ch)
 
int pcm_chn_remove (struct snddev_info *d, struct pcm_channel *ch)
 
int pcm_addchan (device_t dev, int dir, kobj_class_t cls, void *devinfo)
 
static int pcm_killchan (device_t dev)
 
static int pcm_best_unit (int old)
 
int pcm_setstatus (device_t dev, char *str)
 
uint32_t pcm_getflags (device_t dev)
 
void pcm_setflags (device_t dev, uint32_t val)
 
void * pcm_getdevinfo (device_t dev)
 
unsigned int pcm_getbuffersize (device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
 
static int sysctl_dev_pcm_bitperfect (SYSCTL_HANDLER_ARGS)
 
static u_int8_t pcm_mode_init (struct snddev_info *d)
 
int pcm_register (device_t dev, void *devinfo, int numplay, int numrec)
 
int pcm_unregister (device_t dev)
 
void sound_oss_sysinfo (oss_sysinfo *si)
 Handle OSSv4 SNDCTL_SYSINFO ioctl. More...
 
int sound_oss_card_info (oss_card_info *si)
 
static int sound_modevent (module_t mod, int type, void *data)
 
 DEV_MODULE (sound, sound_modevent, NULL)
 
 MODULE_VERSION (sound, SOUND_MODVER)
 

Variables

devclass_t pcm_devclass
 
int pcm_veto_load = 1
 
int snd_unit = -1
 
static int snd_unit_auto = -1
 
int snd_maxautovchans = 16
 
static char snd_driver_version []
 
struct unrhdr * pcmsg_unrhdr = NULL
 Unit number allocator for syncgroup IDs. More...
 

Function Documentation

◆ DEV_MODULE()

DEV_MODULE ( sound  ,
sound_modevent  ,
NULL   
)

◆ MODULE_VERSION()

MODULE_VERSION ( sound  ,
SOUND_MODVER   
)

◆ pcm_addchan()

◆ pcm_best_unit()

static int pcm_best_unit ( int  old)
static

Definition at line 740 of file sound.c.

References pcm_devclass, PCM_REGISTERED, snddev_info::playcount, and snddev_info::reccount.

Referenced by pcm_setstatus(), and pcm_unregister().

Here is the caller graph for this function:

◆ pcm_chn_add()

◆ pcm_chn_create()

◆ pcm_chn_destroy()

int pcm_chn_destroy ( struct pcm_channel ch)

Definition at line 596 of file sound.c.

References chn_kill(), pcm_channel::dev, free, pcm_channel::methods, pcm_channel::name, pcm_channel::parentsnddev, and PCM_BUSYASSERT.

Referenced by pcm_addchan(), pcm_killchan(), vchan_create(), and vchan_destroy().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcm_chn_remove()

◆ pcm_chnalloc()

int pcm_chnalloc ( struct snddev_info d,
struct pcm_channel **  ch,
int  direction,
pid_t  pid,
char *  comm,
int  devunit 
)

◆ pcm_chnref()

int pcm_chnref ( struct pcm_channel c,
int  ref 
)

Definition at line 387 of file sound.c.

References c, CHN_LOCKASSERT, pcm_channel::parentsnddev, PCM_BUSYASSERT, and pcm_channel::refcount.

Referenced by dsp_close(), dsp_get_volume_channel(), dsp_open(), and getchns().

Here is the caller graph for this function:

◆ pcm_chnrelease()

int pcm_chnrelease ( struct pcm_channel c)

Definition at line 373 of file sound.c.

References c, CHN_COMM_UNUSED, CHN_LOCKASSERT, CHN_UNLOCK, pcm_channel::comm, pcm_channel::flags, pcm_channel::parentsnddev, PCM_BUSYASSERT, and pcm_channel::pid.

Referenced by dsp_close(), dsp_open(), and getchns().

Here is the caller graph for this function:

◆ pcm_clonereset()

static void pcm_clonereset ( struct snddev_info d)
static

Definition at line 131 of file sound.c.

References snddev_info::clones, max, PCM_BUSYASSERT, PCMMAXCLONE, snddev_info::playcount, snddev_info::pvchancount, snddev_info::reccount, snddev_info::rvchancount, snd_clone_gc(), snd_clone_setmaxunit(), and snd_maxautovchans.

Referenced by pcm_setmaxautovchans(), and pcm_setvchans().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcm_getbuffersize()

unsigned int pcm_getbuffersize ( device_t  dev,
unsigned int  minbufsz,
unsigned int  deflt,
unsigned int  maxbufsz 
)

◆ pcm_getdevinfo()

◆ pcm_getflags()

◆ pcm_inprog()

int pcm_inprog ( struct snddev_info d,
int  delta 
)

Definition at line 398 of file sound.c.

References snddev_info::inprog, and PCM_LOCKASSERT.

◆ pcm_killchan()

static int pcm_killchan ( device_t  dev)
static

Definition at line 721 of file sound.c.

References pcm_channel::channels, CHN_FIRST, dev, error, PCM_BUSYASSERT, pcm_chn_destroy(), pcm_chn_remove(), PCM_LOCK, and PCM_UNLOCK.

Referenced by pcm_unregister().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcm_mode_init()

static u_int8_t pcm_mode_init ( struct snddev_info d)
static

Definition at line 1019 of file sound.c.

References snddev_info::mixer_dev, PCM_MODE_MIXER, PCM_MODE_PLAY, PCM_MODE_REC, snddev_info::playcount, and snddev_info::reccount.

Referenced by pcm_sysinit().

Here is the caller graph for this function:

◆ pcm_register()

int pcm_register ( device_t  dev,
void *  devinfo,
int  numplay,
int  numrec 
)

Definition at line 1080 of file sound.c.

References snddev_info::channels, CHN_INIT, snddev_info::clones, snddev_info::cv, dev, snddev_info::dev, snddev_info::devcount, devinfo, snddev_info::devinfo, dsp_cdevinfo_init(), snddev_info::flags, snddev_info::inprog, snddev_info::lock, PCM_ACQUIRE_QUICK, pcm_veto_load, PCMMAXCLONE, PCMMAXUNIT, snddev_info::play_sysctl_tree, snddev_info::playcount, snddev_info::pvchancount, snddev_info::pvchanformat, snddev_info::pvchanrate, snddev_info::rec_sysctl_ctx, snddev_info::rec_sysctl_tree, snddev_info::reccount, snddev_info::rvchancount, snddev_info::rvchanformat, snddev_info::rvchanrate, SD_F_AUTOVCHAN, SD_F_BITPERFECT, SD_F_SIMPLEX, SD_F_VPC, snd_clone_create(), SND_CLONE_DEADLINE_DEFAULT, SND_CLONE_GC_ENABLE, SND_CLONE_GC_EXPIRED, SND_CLONE_GC_LASTREF, SND_CLONE_GC_UNREF, SND_CLONE_WAITOK, SND_D_MASK, snd_mtxcreate(), SND_U_MASK, sndstat_prepare_pcm(), sndstat_register(), and snddev_info::status.

Referenced by ad1816_attach(), als_pci_attach(), aoa_attach(), atiixp_chip_post_init(), audio_soc_init(), cmi_attach(), cs4281_pci_attach(), emu_pci_attach(), emu_pcm_attach(), envy24_pci_attach(), envy24ht_pci_attach(), es_pci_attach(), ess_attach(), fm801_pci_attach(), hdaa_pcm_attach(), hdspe_pcm_attach(), ich_pci_attach(), m3_pci_attach(), mss_doattach(), nm_pci_attach(), pcmcsa_attach(), sb16_attach(), sb_attach(), sv_attach(), tr_pci_attach(), uaudio_attach_sub(), and via_attach().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcm_setflags()

◆ pcm_setmaxautovchans()

static void pcm_setmaxautovchans ( struct snddev_info d,
int  num 
)
static

Definition at line 408 of file sound.c.

References PCM_BUSYASSERT, pcm_clonereset(), pcm_setvchans(), PCMDIR_PLAY, PCMDIR_REC, snddev_info::pvchancount, and snddev_info::rvchancount.

Referenced by pcm_setstatus(), and sysctl_hw_snd_maxautovchans().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcm_setstatus()

◆ pcm_setvchans()

◆ pcm_sysinit()

static void pcm_sysinit ( device_t  dev)
static

Definition at line 1034 of file sound.c.

References snddev_info::bufsz, dev, feeder_eq_initsys(), snddev_info::flags, pcm_mode_init(), SD_F_AUTOVCHAN, SD_F_EQ, sysctl_dev_pcm_bitperfect(), and vchan_initsys().

Referenced by pcm_setstatus().

Here is the call graph for this function:
Here is the caller graph for this function:

◆ pcm_unregister()

◆ SND_DECLARE_FILE()

SND_DECLARE_FILE ( "$FreeBSD$"  )

◆ snd_mtxassert()

void snd_mtxassert ( void *  m)

Definition at line 107 of file sound.c.

References m.

Referenced by sbc_lockassert().

Here is the caller graph for this function:

◆ snd_mtxcreate()

◆ snd_mtxfree()

◆ snd_setup_intr()

int snd_setup_intr ( device_t  dev,
struct resource *  res,
int  flags,
driver_intr_t  hand,
void *  param,
void **  cookiep 
)

◆ sndstat_prepare_pcm()

static int sndstat_prepare_pcm ( SNDSTAT_PREPARE_PCM_ARGS  )
static

Definition at line 81 of file sound.c.

References SNDSTAT_PREPARE_PCM_BEGIN, and SNDSTAT_PREPARE_PCM_END.

Referenced by pcm_register().

Here is the caller graph for this function:

◆ sound_modevent()

static int sound_modevent ( module_t  mod,
int  type,
void *  data 
)
static

Definition at line 1425 of file sound.c.

References data, midi_modevent(), pcmsg_unrhdr, and type.

Here is the call graph for this function:

◆ sound_oss_card_info()

int sound_oss_card_info ( oss_card_info *  si)

Definition at line 1389 of file sound.c.

References snddev_info::dev, pcm_devclass, PCM_LOCK, PCM_REGISTERED, PCM_UNLOCK, PCM_UNLOCKASSERT, and snddev_info::status.

Referenced by dsp_ioctl(), and mixer_ioctl_cmd().

Here is the caller graph for this function:

◆ sound_oss_sysinfo()

void sound_oss_sysinfo ( oss_sysinfo *  si)

Handle OSSv4 SNDCTL_SYSINFO ioctl.

Parameters
siPointer to oss_sysinfo struct where information about the sound subsystem will be written/copied.

This routine returns information about the sound system, such as the current OSS version, number of audio, MIDI, and mixer drivers, etc. Also includes a bitmask showing which of the above types of devices are open (busy).

Note
Calling threads must not hold any snddev_info or pcm_channel locks.
Author
Ryan Beasley ryanb.nosp@m.@Fre.nosp@m.eBSD..nosp@m.org
Todo:
Collect num{midis,timers}.

Need access to sound/midi/midi.c::midistat_lock in order to safely touch midi_devices and get a head count of, well, MIDI devices. midistat_lock is a global static (i.e., local to midi.c), but midi_devices is a regular global; should the mutex be publicized, or is there another way to get this information?

NB: MIDI/sequencer stuff is currently on hold.

Todo:
Fill in "busy devices" fields.

si->openedmidi = " MIDI devices

Definition at line 1296 of file sound.c.

References c, pcm_channel::channels, CHN_F_BUSY, CHN_FOREACH, CHN_LOCK, CHN_UNLOCK, CHN_UNLOCKASSERT, snddev_info::devcount, pcm_channel::flags, mixer_count, pcm_devclass, PCM_LOCK, PCM_REGISTERED, PCM_UNLOCK, and PCM_UNLOCKASSERT.

Referenced by dsp_ioctl(), and mixer_ioctl_cmd().

Here is the caller graph for this function:

◆ sysctl_dev_pcm_bitperfect()

static int sysctl_dev_pcm_bitperfect ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 870 of file sound.c.

References snddev_info::flags, PCM_ACQUIRE, PCM_LOCK, PCM_REGISTERED, PCM_RELEASE, PCM_RELEASE_QUICK, PCM_UNLOCK, PCM_WAIT, req, SD_F_BITPERFECT, and val.

Referenced by pcm_sysinit().

Here is the caller graph for this function:

◆ sysctl_hw_snd_default_unit()

static int sysctl_hw_snd_default_unit ( SYSCTL_HANDLER_ARGS  )
static

◆ sysctl_hw_snd_maxautovchans()

static int sysctl_hw_snd_maxautovchans ( SYSCTL_HANDLER_ARGS  )
static

Definition at line 452 of file sound.c.

References error, PCM_ACQUIRE_QUICK, pcm_devclass, PCM_REGISTERED, PCM_RELEASE_QUICK, pcm_setmaxautovchans(), req, snd_maxautovchans, and SND_MAXVCHANS.

Here is the call graph for this function:

◆ SYSCTL_INT()

SYSCTL_INT ( _hw_snd  ,
OID_AUTO  ,
default_auto  ,
CTLFLAG_RWTUN  ,
snd_unit_auto,
,
"assign default unit to a newly attached device"   
)

◆ SYSCTL_NODE()

SYSCTL_NODE ( _hw  ,
OID_AUTO  ,
snd  ,
CTLFLAG_RD|  CTLFLAG_MPSAFE,
,
"Sound driver"   
)

◆ SYSCTL_PROC() [1/2]

SYSCTL_PROC ( _hw_snd  ,
OID_AUTO  ,
default_unit  ,
CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_ANYBODY|  CTLFLAG_NEEDGIANT,
,
sizeof(int)  ,
sysctl_hw_snd_default_unit  ,
"I"  ,
"default sound device"   
)

◆ SYSCTL_PROC() [2/2]

SYSCTL_PROC ( _hw_snd  ,
OID_AUTO  ,
maxautovchans  ,
CTLTYPE_INT|CTLFLAG_RWTUN|  CTLFLAG_NEEDGIANT,
,
sizeof(int)  ,
sysctl_hw_snd_maxautovchans  ,
"I"  ,
"maximum virtual channel  
)

◆ SYSCTL_STRING()

SYSCTL_STRING ( _hw_snd  ,
OID_AUTO  ,
version  ,
CTLFLAG_RD  ,
snd_driver_version,
,
"driver version/arch"   
)

Variable Documentation

◆ pcm_devclass

◆ pcm_veto_load

int pcm_veto_load = 1

Definition at line 51 of file sound.c.

Referenced by pcm_register(), and SLIST_HEAD().

◆ pcmsg_unrhdr

struct unrhdr* pcmsg_unrhdr = NULL

Unit number allocator for syncgroup IDs.

Definition at line 78 of file sound.c.

Referenced by dsp_close(), dsp_oss_syncgroup(), dsp_oss_syncstart(), and sound_modevent().

◆ snd_driver_version

char snd_driver_version[]
static
Initial value:
=
__XSTRING(SND_DRV_VERSION)"/"MACHINE_ARCH
#define SND_DRV_VERSION
Definition: version.h:42

Definition at line 70 of file sound.c.

◆ snd_maxautovchans

int snd_maxautovchans = 16

◆ snd_unit

int snd_unit = -1

◆ snd_unit_auto

int snd_unit_auto = -1
static

Definition at line 55 of file sound.c.

Referenced by pcm_setstatus(), pcm_unregister(), and sysctl_hw_snd_default_unit().