1139749Simp/*- 2193640Sariff * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org> 3193640Sariff * Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org> 4192921Sjoel * Copyright (c) 1995 Hannu Savolainen 550724Scg * All rights reserved. 650724Scg * 750724Scg * Redistribution and use in source and binary forms, with or without 850724Scg * modification, are permitted provided that the following conditions 950724Scg * are met: 1050724Scg * 1. Redistributions of source code must retain the above copyright 1150724Scg * notice, this list of conditions and the following disclaimer. 1250724Scg * 2. Redistributions in binary form must reproduce the above copyright 1350724Scg * notice, this list of conditions and the following disclaimer in the 1450724Scg * documentation and/or other materials provided with the distribution. 1550724Scg * 1650724Scg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 1750724Scg * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1850724Scg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 1950724Scg * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 2050724Scg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2150724Scg * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2250724Scg * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2350724Scg * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2450724Scg * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2550724Scg * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2650724Scg * SUCH DAMAGE. 2750724Scg * 2850733Speter * $FreeBSD: stable/11/sys/dev/sound/pcm/sound.h 358878 2020-03-11 08:25:33Z hselasky $ 2950724Scg */ 3050724Scg 3150724Scg/* 3250724Scg * first, include kernel header files. 3350724Scg */ 3450724Scg 3550724Scg#ifndef _OS_H_ 3650724Scg#define _OS_H_ 3750724Scg 3855205Speter#ifdef _KERNEL 3950724Scg#include <sys/param.h> 4050724Scg#include <sys/systm.h> 4150724Scg#include <sys/ioccom.h> 4250724Scg#include <sys/filio.h> 4350724Scg#include <sys/sockio.h> 4450724Scg#include <sys/fcntl.h> 45181874Sed#include <sys/selinfo.h> 4650724Scg#include <sys/proc.h> 4750724Scg#include <sys/kernel.h> /* for DATA_SET */ 4850724Scg#include <sys/module.h> 4950724Scg#include <sys/conf.h> 5050724Scg#include <sys/file.h> 5150724Scg#include <sys/uio.h> 5250724Scg#include <sys/syslog.h> 5350724Scg#include <sys/errno.h> 5450724Scg#include <sys/malloc.h> 5550724Scg#include <sys/bus.h> 5650724Scg#include <machine/resource.h> 5750724Scg#include <machine/bus.h> 5850724Scg#include <sys/rman.h> 59164614Sariff#include <sys/limits.h> 6050724Scg#include <sys/mman.h> 6150724Scg#include <sys/poll.h> 6282180Scg#include <sys/sbuf.h> 6350724Scg#include <sys/soundcard.h> 6470617Sjhb#include <sys/sysctl.h> 6573769Scg#include <sys/kobj.h> 6650724Scg#include <vm/vm.h> 6750724Scg#include <vm/pmap.h> 6850724Scg 69103338Sbde#include <sys/lock.h> 70103338Sbde#include <sys/mutex.h> 71162588Snetchild#include <sys/condvar.h> 72103338Sbde 73193979Sariff#ifndef KOBJMETHOD_END 74193979Sariff#define KOBJMETHOD_END { NULL, NULL } 75193979Sariff#endif 76193979Sariff 7774763Scgstruct pcm_channel; 7874763Scgstruct pcm_feeder; 7974763Scgstruct snd_dbuf; 8074763Scgstruct snd_mixer; 8174763Scg 8274763Scg#include <dev/sound/pcm/buffer.h> 83193640Sariff#include <dev/sound/pcm/matrix.h> 84193640Sariff#include <dev/sound/pcm/matrix_map.h> 8553465Scg#include <dev/sound/pcm/channel.h> 8664881Scg#include <dev/sound/pcm/feeder.h> 8753465Scg#include <dev/sound/pcm/mixer.h> 88162588Snetchild#include <dev/sound/pcm/dsp.h> 89170161Sariff#include <dev/sound/clone.h> 90170161Sariff#include <dev/sound/unit.h> 9150724Scg 92193640Sariff#define PCM_SOFTC_SIZE (sizeof(struct snddev_info)) 9377269Scg 9474763Scg#define SND_STATUSLEN 64 9564442Scg 96193640Sariff#define SOUND_MODVER 5 9762483Scg 98168846Sariff#define SOUND_MINVER SOUND_MODVER 99132236Stanimura#define SOUND_PREFVER SOUND_MODVER 100168846Sariff#define SOUND_MAXVER SOUND_MODVER 10162483Scg 10278362Scg/* 103169319Sariff * We're abusing the fact that MAXMINOR still have enough room 104170161Sariff * for our bit twiddling and nobody ever need 512 unique soundcards, 105170161Sariff * 32 unique device types and 1024 unique cloneable devices for the 106170161Sariff * next 100 years... 107169319Sariff */ 10850724Scg 109170161Sariff#define PCMMAXUNIT (snd_max_u()) 110170161Sariff#define PCMMAXDEV (snd_max_d()) 111170161Sariff#define PCMMAXCHAN (snd_max_c()) 11278362Scg 113170161Sariff#define PCMMAXCLONE PCMMAXCHAN 114170161Sariff 115170161Sariff#define PCMUNIT(x) (snd_unit2u(dev2unit(x))) 116170161Sariff#define PCMDEV(x) (snd_unit2d(dev2unit(x))) 117170161Sariff#define PCMCHAN(x) (snd_unit2c(dev2unit(x))) 118170161Sariff 119193640Sariff/* XXX unit2minor compat */ 120193640Sariff#define PCMMINOR(x) (x) 121193640Sariff 122170161Sariff/* 123170161Sariff * By design, limit possible channels for each direction. 124170161Sariff */ 125170161Sariff#define SND_MAXHWCHAN 256 126170161Sariff#define SND_MAXVCHANS SND_MAXHWCHAN 127170161Sariff 12850724Scg#define SD_F_SIMPLEX 0x00000001 129150827Snetchild#define SD_F_AUTOVCHAN 0x00000002 130162738Sariff#define SD_F_SOFTPCMVOL 0x00000004 131193640Sariff#define SD_F_DYING 0x00000008 132358878Shselasky#define SD_F_DETACHING 0x00000010 133193640Sariff#define SD_F_BUSY 0x00000020 134193640Sariff#define SD_F_MPSAFE 0x00000040 135193640Sariff#define SD_F_REGISTERED 0x00000080 136193640Sariff#define SD_F_BITPERFECT 0x00000100 137193640Sariff#define SD_F_VPC 0x00000200 /* volume-per-channel */ 138193640Sariff#define SD_F_EQ 0x00000400 /* EQ */ 139193640Sariff#define SD_F_EQ_ENABLED 0x00000800 /* EQ enabled */ 140193640Sariff#define SD_F_EQ_BYPASSED 0x00001000 /* EQ bypassed */ 141193640Sariff#define SD_F_EQ_PC 0x00002000 /* EQ per-channel */ 142170815Sariff 143193640Sariff#define SD_F_EQ_DEFAULT (SD_F_EQ | SD_F_EQ_ENABLED) 144193640Sariff#define SD_F_EQ_MASK (SD_F_EQ | SD_F_EQ_ENABLED | \ 145193640Sariff SD_F_EQ_BYPASSED | SD_F_EQ_PC) 146193640Sariff 14750724Scg#define SD_F_PRIO_RD 0x10000000 14850724Scg#define SD_F_PRIO_WR 0x20000000 14950724Scg#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR) 15050724Scg#define SD_F_DIR_SET 0x40000000 15150724Scg#define SD_F_TRANSIENT 0xf0000000 15250724Scg 153193640Sariff#define SD_F_BITS "\020" \ 154193640Sariff "\001SIMPLEX" \ 155193640Sariff "\002AUTOVCHAN" \ 156193640Sariff "\003SOFTPCMVOL" \ 157193640Sariff "\004DYING" \ 158358878Shselasky "\005DETACHING" \ 159193640Sariff "\006BUSY" \ 160193640Sariff "\007MPSAFE" \ 161193640Sariff "\010REGISTERED" \ 162193640Sariff "\011BITPERFECT" \ 163193640Sariff "\012VPC" \ 164193640Sariff "\013EQ" \ 165193640Sariff "\014EQ_ENABLED" \ 166193640Sariff "\015EQ_BYPASSED" \ 167193640Sariff "\016EQ_PC" \ 168193640Sariff "\035PRIO_RD" \ 169193640Sariff "\036PRIO_WR" \ 170193640Sariff "\037DIR_SET" 171193640Sariff 172170815Sariff#define PCM_ALIVE(x) ((x) != NULL && (x)->lock != NULL && \ 173170815Sariff !((x)->flags & SD_F_DYING)) 174170815Sariff#define PCM_REGISTERED(x) (PCM_ALIVE(x) && \ 175170815Sariff ((x)->flags & SD_F_REGISTERED)) 176170815Sariff 177358878Shselasky#define PCM_DETACHING(x) ((x)->flags & SD_F_DETACHING) 178358878Shselasky 17950724Scg/* many variables should be reduced to a range. Here define a macro */ 18050724Scg#define RANGE(var, low, high) (var) = \ 18150724Scg (((var)<(low))? (low) : ((var)>(high))? (high) : (var)) 18255204Scg#define DSP_BUFFSIZE (8192) 18350724Scg 184193640Sariff/* make figuring out what a format is easier. got AFMT_STEREO already */ 185193640Sariff#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE) 186193640Sariff#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE) 187193640Sariff#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE) 188193640Sariff#define AFMT_G711 (AFMT_MU_LAW | AFMT_A_LAW) 189193640Sariff#define AFMT_8BIT (AFMT_G711 | AFMT_U8 | AFMT_S8) 190193640Sariff#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \ 191193640Sariff AFMT_S16_LE | AFMT_S16_BE | AFMT_S8) 192193640Sariff#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \ 193193640Sariff AFMT_S16_BE | AFMT_U16_BE) 194164614Sariff 195193640Sariff#define AFMT_CONVERTIBLE (AFMT_8BIT | AFMT_16BIT | AFMT_24BIT | \ 196193640Sariff AFMT_32BIT) 197164614Sariff 198193640Sariff/* Supported vchan mixing formats */ 199193640Sariff#define AFMT_VCHAN (AFMT_CONVERTIBLE & ~AFMT_G711) 200164614Sariff 201193640Sariff#define AFMT_PASSTHROUGH AFMT_AC3 202193640Sariff#define AFMT_PASSTHROUGH_RATE 48000 203193640Sariff#define AFMT_PASSTHROUGH_CHANNEL 2 204193640Sariff#define AFMT_PASSTHROUGH_EXTCHANNEL 0 205164614Sariff 206193640Sariff/* 207193640Sariff * We're simply using unused, contiguous bits from various AFMT_ definitions. 208193640Sariff * ~(0xb00ff7ff) 209193640Sariff */ 210193640Sariff#define AFMT_ENCODING_MASK 0xf00fffff 211282650Shselasky#define AFMT_CHANNEL_MASK 0x07f00000 212193640Sariff#define AFMT_CHANNEL_SHIFT 20 213282650Shselasky#define AFMT_CHANNEL_MAX 0x7f 214282650Shselasky#define AFMT_EXTCHANNEL_MASK 0x08000000 215282650Shselasky#define AFMT_EXTCHANNEL_SHIFT 27 216282650Shselasky#define AFMT_EXTCHANNEL_MAX 1 217164614Sariff 218193640Sariff#define AFMT_ENCODING(v) ((v) & AFMT_ENCODING_MASK) 219164614Sariff 220193640Sariff#define AFMT_EXTCHANNEL(v) (((v) & AFMT_EXTCHANNEL_MASK) >> \ 221193640Sariff AFMT_EXTCHANNEL_SHIFT) 222164614Sariff 223193640Sariff#define AFMT_CHANNEL(v) (((v) & AFMT_CHANNEL_MASK) >> \ 224193640Sariff AFMT_CHANNEL_SHIFT) 225164614Sariff 226193640Sariff#define AFMT_BIT(v) (((v) & AFMT_32BIT) ? 32 : \ 227193640Sariff (((v) & AFMT_24BIT) ? 24 : \ 228193640Sariff ((((v) & AFMT_16BIT) || \ 229193640Sariff ((v) & AFMT_PASSTHROUGH)) ? 16 : 8))) 230164614Sariff 231193640Sariff#define AFMT_BPS(v) (AFMT_BIT(v) >> 3) 232193640Sariff#define AFMT_ALIGN(v) (AFMT_BPS(v) * AFMT_CHANNEL(v)) 233164614Sariff 234193640Sariff#define SND_FORMAT(f, c, e) (AFMT_ENCODING(f) | \ 235193640Sariff (((c) << AFMT_CHANNEL_SHIFT) & \ 236193640Sariff AFMT_CHANNEL_MASK) | \ 237193640Sariff (((e) << AFMT_EXTCHANNEL_SHIFT) & \ 238193640Sariff AFMT_EXTCHANNEL_MASK)) 239164614Sariff 240193640Sariff#define AFMT_U8_NE AFMT_U8 241193640Sariff#define AFMT_S8_NE AFMT_S8 242164614Sariff 243193640Sariff#define AFMT_SIGNED_NE (AFMT_S8_NE | AFMT_S16_NE | AFMT_S24_NE | AFMT_S32_NE) 244164614Sariff 245193640Sariff#define AFMT_NE (AFMT_SIGNED_NE | AFMT_U8_NE | AFMT_U16_NE | \ 246193640Sariff AFMT_U24_NE | AFMT_U32_NE) 24750724Scg 24878362Scg/* 24950724Scg * Minor numbers for the sound driver. 25050724Scg * 25150724Scg * Unfortunately Creative called the codec chip of SB as a DSP. For this 25250724Scg * reason the /dev/dsp is reserved for digitized audio use. There is a 25350724Scg * device for true DSP processors but it will be called something else. 25450724Scg * In v3.0 it's /dev/sndproc but this could be a temporary solution. 25550724Scg */ 25650724Scg 25750724Scg#define SND_DEV_CTL 0 /* Control port /dev/mixer */ 25850724Scg#define SND_DEV_SEQ 1 /* Sequencer /dev/sequencer */ 25950724Scg#define SND_DEV_MIDIN 2 /* Raw midi access */ 26050724Scg#define SND_DEV_DSP 3 /* Digitized voice /dev/dsp */ 26150724Scg#define SND_DEV_AUDIO 4 /* Sparc compatible /dev/audio */ 26250724Scg#define SND_DEV_DSP16 5 /* Like /dev/dsp but 16 bits/sample */ 26350724Scg#define SND_DEV_STATUS 6 /* /dev/sndstat */ 26450724Scg /* #7 not in use now. */ 26550724Scg#define SND_DEV_SEQ2 8 /* /dev/sequencer, level 2 interface */ 26650724Scg#define SND_DEV_SNDPROC 9 /* /dev/sndproc for programmable devices */ 26750724Scg#define SND_DEV_PSS SND_DEV_SNDPROC /* ? */ 26851769Scg#define SND_DEV_NORESET 10 26950724Scg 270170161Sariff#define SND_DEV_DSPHW_PLAY 11 /* specific playback channel */ 271170161Sariff#define SND_DEV_DSPHW_VPLAY 12 /* specific virtual playback channel */ 272170161Sariff#define SND_DEV_DSPHW_REC 13 /* specific record channel */ 273170161Sariff#define SND_DEV_DSPHW_VREC 14 /* specific virtual record channel */ 274170161Sariff 275170815Sariff#define SND_DEV_DSPHW_CD 15 /* s16le/stereo 44100Hz CD */ 276170815Sariff 277193640Sariff/* 278193640Sariff * OSSv4 compatible device. For now, it serve no purpose and 279193640Sariff * the cloning itself will forward the request to ordinary /dev/dsp 280193640Sariff * instead. 281193640Sariff */ 282193640Sariff#define SND_DEV_DSP_MMAP 16 /* /dev/dsp_mmap */ 283193640Sariff#define SND_DEV_DSP_AC3 17 /* /dev/dsp_ac3 */ 284193640Sariff#define SND_DEV_DSP_MULTICH 18 /* /dev/dsp_multich */ 285193640Sariff#define SND_DEV_DSP_SPDIFOUT 19 /* /dev/dsp_spdifout */ 286193640Sariff#define SND_DEV_DSP_SPDIFIN 20 /* /dev/dsp_spdifin */ 287170815Sariff 288193640Sariff#define SND_DEV_LAST SND_DEV_DSP_SPDIFIN 289170815Sariff#define SND_DEV_MAX PCMMAXDEV 290170815Sariff 29150724Scg#define DSP_DEFAULT_SPEED 8000 29250724Scg 29350724Scg#define ON 1 29450724Scg#define OFF 0 29550724Scg 29689834Scgextern int pcm_veto_load; 29778362Scgextern int snd_unit; 298164614Sariffextern int snd_maxautovchans; 299164614Sariffextern int snd_verbose; 30078362Scgextern devclass_t pcm_devclass; 301162588Snetchildextern struct unrhdr *pcmsg_unrhdr; 30278362Scg 30350724Scg/* 30450724Scg * some macros for debugging purposes 30550724Scg * DDB/DEB to enable/disable debugging stuff 30650724Scg * BVDDB to enable debugging when bootverbose 30750724Scg */ 30850724Scg#define BVDDB(x) if (bootverbose) x 30950724Scg 31050724Scg#ifndef DEB 31150724Scg#define DEB(x) 31250724Scg#endif 31350724Scg 31470617SjhbSYSCTL_DECL(_hw_snd); 31570617Sjhb 316193640Sariffint pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num); 317193640Sariffint pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, 318193640Sariff pid_t pid, char *comm, int devunit); 31978214Scgint pcm_chnrelease(struct pcm_channel *c); 32077269Scgint pcm_chnref(struct pcm_channel *c, int ref); 32182180Scgint pcm_inprog(struct snddev_info *d, int delta); 32277269Scg 323170161Sariffstruct pcm_channel *pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo); 32477269Scgint pcm_chn_destroy(struct pcm_channel *ch); 325124740Smatkint pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch); 326124740Smatkint pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch); 32777269Scg 32870134Scgint pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo); 329160439Snetchildunsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz); 33050724Scgint pcm_register(device_t dev, void *devinfo, int numplay, int numrec); 33165340Scgint pcm_unregister(device_t dev); 33250724Scgint pcm_setstatus(device_t dev, char *str); 33350724Scgu_int32_t pcm_getflags(device_t dev); 33450724Scgvoid pcm_setflags(device_t dev, u_int32_t val); 33558384Scgvoid *pcm_getdevinfo(device_t dev); 33650724Scg 337124617Sphk 33873131Scgint snd_setup_intr(device_t dev, struct resource *res, int flags, 33973131Scg driver_intr_t hand, void *param, void **cookiep); 34073131Scg 34193814Sjhbvoid *snd_mtxcreate(const char *desc, const char *type); 34273131Scgvoid snd_mtxfree(void *m); 34373131Scgvoid snd_mtxassert(void *m); 344119096Scg#define snd_mtxlock(m) mtx_lock(m) 345119096Scg#define snd_mtxunlock(m) mtx_unlock(m) 346119096Scg 34782180Scgtypedef int (*sndstat_handler)(struct sbuf *s, device_t dev, int verbose); 34882180Scgint sndstat_register(device_t dev, char *str, sndstat_handler handler); 34982180Scgint sndstat_registerfile(char *str); 35082180Scgint sndstat_unregister(device_t dev); 35182180Scgint sndstat_unregisterfile(char *str); 35282180Scg 35382180Scg#define SND_DECLARE_FILE(version) \ 35482180Scg _SND_DECLARE_FILE(__LINE__, version) 35582180Scg 35682180Scg#define _SND_DECLARE_FILE(uniq, version) \ 35782180Scg __SND_DECLARE_FILE(uniq, version) 35882180Scg 35982180Scg#define __SND_DECLARE_FILE(uniq, version) \ 36082180Scg static char sndstat_vinfo[] = version; \ 36182180Scg SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \ 36282180Scg SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo); 36382180Scg 36450724Scg/* usage of flags in device config entry (config file) */ 36550724Scg#define DV_F_DRQ_MASK 0x00000007 /* mask for secondary drq */ 36650724Scg#define DV_F_DUAL_DMA 0x00000010 /* set to use secondary dma channel */ 36750724Scg 368119096Scg/* ought to be made obsolete but still used by mss */ 36950724Scg#define DV_F_DEV_MASK 0x0000ff00 /* force device type/class */ 37050724Scg#define DV_F_DEV_SHIFT 8 /* force device type/class */ 37182180Scg 372119096Scg/* 373119096Scg * this is rather kludgey- we need to duplicate these struct def'ns from sound.c 374119096Scg * so that the macro versions of pcm_{,un}lock can dereference them. 375124617Sphk * we also have to do this now makedev() has gone away. 376119096Scg */ 377119096Scg 378119096Scgstruct snddev_info { 379170161Sariff struct { 380170161Sariff struct { 381170161Sariff SLIST_HEAD(, pcm_channel) head; 382170161Sariff struct { 383170161Sariff SLIST_HEAD(, pcm_channel) head; 384170161Sariff } busy; 385193640Sariff struct { 386193640Sariff SLIST_HEAD(, pcm_channel) head; 387193640Sariff } opened; 388170161Sariff } pcm; 389170161Sariff } channels; 390170815Sariff TAILQ_HEAD(dsp_cdevinfo_linkhead, dsp_cdevinfo) dsp_cdevinfo_pool; 391170161Sariff struct snd_clone *clones; 392170161Sariff unsigned devcount, playcount, reccount, pvchancount, rvchancount ; 393119096Scg unsigned flags; 394119096Scg int inprog; 395119096Scg unsigned int bufsz; 396119096Scg void *devinfo; 397119096Scg device_t dev; 398119096Scg char status[SND_STATUSLEN]; 399119096Scg struct mtx *lock; 400130585Sphk struct cdev *mixer_dev; 401170161Sariff uint32_t pvchanrate, pvchanformat; 402170161Sariff uint32_t rvchanrate, rvchanformat; 403193640Sariff int32_t eqpreamp; 404170161Sariff struct sysctl_ctx_list play_sysctl_ctx, rec_sysctl_ctx; 405170161Sariff struct sysctl_oid *play_sysctl_tree, *rec_sysctl_tree; 406170815Sariff struct cv cv; 407119096Scg}; 408119096Scg 409162588Snetchildvoid sound_oss_sysinfo(oss_sysinfo *); 410187030Smavint sound_oss_card_info(oss_card_info *); 411162588Snetchild 412193640Sariff#define PCM_LOCKOWNED(d) mtx_owned((d)->lock) 413193640Sariff#define PCM_LOCK(d) mtx_lock((d)->lock) 414193640Sariff#define PCM_UNLOCK(d) mtx_unlock((d)->lock) 415193640Sariff#define PCM_TRYLOCK(d) mtx_trylock((d)->lock) 416193640Sariff#define PCM_LOCKASSERT(d) mtx_assert((d)->lock, MA_OWNED) 417193640Sariff#define PCM_UNLOCKASSERT(d) mtx_assert((d)->lock, MA_NOTOWNED) 418119096Scg 419170815Sariff/* 420193640Sariff * For PCM_[WAIT | ACQUIRE | RELEASE], be sure to surround these 421193640Sariff * with PCM_LOCK/UNLOCK() sequence, or I'll come to gnaw upon you! 422170815Sariff */ 423170815Sariff#ifdef SND_DIAGNOSTIC 424170815Sariff#define PCM_WAIT(x) do { \ 425193640Sariff if (!PCM_LOCKOWNED(x)) \ 426170815Sariff panic("%s(%d): [PCM WAIT] Mutex not owned!", \ 427170815Sariff __func__, __LINE__); \ 428170815Sariff while ((x)->flags & SD_F_BUSY) { \ 429170815Sariff if (snd_verbose > 3) \ 430170815Sariff device_printf((x)->dev, \ 431170815Sariff "%s(%d): [PCM WAIT] calling cv_wait().\n", \ 432170815Sariff __func__, __LINE__); \ 433170815Sariff cv_wait(&(x)->cv, (x)->lock); \ 434170815Sariff } \ 435193640Sariff} while (0) 436170815Sariff 437170815Sariff#define PCM_ACQUIRE(x) do { \ 438193640Sariff if (!PCM_LOCKOWNED(x)) \ 439170815Sariff panic("%s(%d): [PCM ACQUIRE] Mutex not owned!", \ 440170815Sariff __func__, __LINE__); \ 441170815Sariff if ((x)->flags & SD_F_BUSY) \ 442170815Sariff panic("%s(%d): [PCM ACQUIRE] " \ 443170815Sariff "Trying to acquire BUSY cv!", __func__, __LINE__); \ 444170815Sariff (x)->flags |= SD_F_BUSY; \ 445193640Sariff} while (0) 446170815Sariff 447170815Sariff#define PCM_RELEASE(x) do { \ 448193640Sariff if (!PCM_LOCKOWNED(x)) \ 449170815Sariff panic("%s(%d): [PCM RELEASE] Mutex not owned!", \ 450170815Sariff __func__, __LINE__); \ 451170815Sariff if ((x)->flags & SD_F_BUSY) { \ 452170815Sariff (x)->flags &= ~SD_F_BUSY; \ 453170815Sariff if ((x)->cv.cv_waiters != 0) { \ 454170815Sariff if ((x)->cv.cv_waiters > 1 && snd_verbose > 3) \ 455170815Sariff device_printf((x)->dev, \ 456170815Sariff "%s(%d): [PCM RELEASE] " \ 457170815Sariff "cv_waiters=%d > 1!\n", \ 458170815Sariff __func__, __LINE__, \ 459170815Sariff (x)->cv.cv_waiters); \ 460170815Sariff cv_broadcast(&(x)->cv); \ 461170815Sariff } \ 462170815Sariff } else \ 463170815Sariff panic("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ 464170815Sariff __func__, __LINE__); \ 465193640Sariff} while (0) 466170815Sariff 467170815Sariff/* Quick version, for shorter path. */ 468170815Sariff#define PCM_ACQUIRE_QUICK(x) do { \ 469193640Sariff if (PCM_LOCKOWNED(x)) \ 470170815Sariff panic("%s(%d): [PCM ACQUIRE QUICK] Mutex owned!", \ 471170815Sariff __func__, __LINE__); \ 472193640Sariff PCM_LOCK(x); \ 473170815Sariff PCM_WAIT(x); \ 474170815Sariff PCM_ACQUIRE(x); \ 475193640Sariff PCM_UNLOCK(x); \ 476193640Sariff} while (0) 477170815Sariff 478170815Sariff#define PCM_RELEASE_QUICK(x) do { \ 479193640Sariff if (PCM_LOCKOWNED(x)) \ 480170815Sariff panic("%s(%d): [PCM RELEASE QUICK] Mutex owned!", \ 481170815Sariff __func__, __LINE__); \ 482193640Sariff PCM_LOCK(x); \ 483170815Sariff PCM_RELEASE(x); \ 484193640Sariff PCM_UNLOCK(x); \ 485193640Sariff} while (0) 486170815Sariff 487170815Sariff#define PCM_BUSYASSERT(x) do { \ 488170815Sariff if (!((x) != NULL && ((x)->flags & SD_F_BUSY))) \ 489170815Sariff panic("%s(%d): [PCM BUSYASSERT] " \ 490170815Sariff "Failed, snddev_info=%p", __func__, __LINE__, x); \ 491193640Sariff} while (0) 492170815Sariff 493170815Sariff#define PCM_GIANT_ENTER(x) do { \ 494170815Sariff int _pcm_giant = 0; \ 495193640Sariff if (PCM_LOCKOWNED(x)) \ 496170815Sariff panic("%s(%d): [GIANT ENTER] PCM lock owned!", \ 497170815Sariff __func__, __LINE__); \ 498170815Sariff if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \ 499170815Sariff device_printf((x)->dev, \ 500170815Sariff "%s(%d): [GIANT ENTER] Giant owned!\n", \ 501170815Sariff __func__, __LINE__); \ 502170815Sariff if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \ 503170815Sariff do { \ 504170815Sariff mtx_lock(&Giant); \ 505170815Sariff _pcm_giant = 1; \ 506193640Sariff } while (0) 507170815Sariff 508170815Sariff#define PCM_GIANT_EXIT(x) do { \ 509193640Sariff if (PCM_LOCKOWNED(x)) \ 510170815Sariff panic("%s(%d): [GIANT EXIT] PCM lock owned!", \ 511170815Sariff __func__, __LINE__); \ 512170815Sariff if (!(_pcm_giant == 0 || _pcm_giant == 1)) \ 513170815Sariff panic("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \ 514170815Sariff __func__, __LINE__); \ 515170815Sariff if ((x)->flags & SD_F_MPSAFE) { \ 516170815Sariff if (_pcm_giant == 1) \ 517170815Sariff panic("%s(%d): [GIANT EXIT] MPSAFE Giant?", \ 518170815Sariff __func__, __LINE__); \ 519170815Sariff if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \ 520170815Sariff device_printf((x)->dev, \ 521170815Sariff "%s(%d): [GIANT EXIT] Giant owned!\n", \ 522170815Sariff __func__, __LINE__); \ 523170815Sariff } \ 524170815Sariff if (_pcm_giant != 0) { \ 525170815Sariff if (mtx_owned(&Giant) == 0) \ 526170815Sariff panic("%s(%d): [GIANT EXIT] Giant not owned!", \ 527170815Sariff __func__, __LINE__); \ 528170815Sariff _pcm_giant = 0; \ 529170815Sariff mtx_unlock(&Giant); \ 530170815Sariff } \ 531193640Sariff} while (0) 532170815Sariff#else /* SND_DIAGNOSTIC */ 533170815Sariff#define PCM_WAIT(x) do { \ 534193640Sariff PCM_LOCKASSERT(x); \ 535170815Sariff while ((x)->flags & SD_F_BUSY) \ 536170815Sariff cv_wait(&(x)->cv, (x)->lock); \ 537193640Sariff} while (0) 538170815Sariff 539170815Sariff#define PCM_ACQUIRE(x) do { \ 540193640Sariff PCM_LOCKASSERT(x); \ 541170815Sariff KASSERT(!((x)->flags & SD_F_BUSY), \ 542170815Sariff ("%s(%d): [PCM ACQUIRE] Trying to acquire BUSY cv!", \ 543170815Sariff __func__, __LINE__)); \ 544170815Sariff (x)->flags |= SD_F_BUSY; \ 545193640Sariff} while (0) 546170815Sariff 547170815Sariff#define PCM_RELEASE(x) do { \ 548193640Sariff PCM_LOCKASSERT(x); \ 549170815Sariff KASSERT((x)->flags & SD_F_BUSY, \ 550170815Sariff ("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \ 551170815Sariff __func__, __LINE__)); \ 552170815Sariff (x)->flags &= ~SD_F_BUSY; \ 553170815Sariff if ((x)->cv.cv_waiters != 0) \ 554170815Sariff cv_broadcast(&(x)->cv); \ 555193640Sariff} while (0) 556170815Sariff 557170815Sariff/* Quick version, for shorter path. */ 558170815Sariff#define PCM_ACQUIRE_QUICK(x) do { \ 559193640Sariff PCM_UNLOCKASSERT(x); \ 560193640Sariff PCM_LOCK(x); \ 561170815Sariff PCM_WAIT(x); \ 562170815Sariff PCM_ACQUIRE(x); \ 563193640Sariff PCM_UNLOCK(x); \ 564193640Sariff} while (0) 565170815Sariff 566170815Sariff#define PCM_RELEASE_QUICK(x) do { \ 567193640Sariff PCM_UNLOCKASSERT(x); \ 568193640Sariff PCM_LOCK(x); \ 569170815Sariff PCM_RELEASE(x); \ 570193640Sariff PCM_UNLOCK(x); \ 571193640Sariff} while (0) 572170815Sariff 573170815Sariff#define PCM_BUSYASSERT(x) KASSERT(x != NULL && \ 574170815Sariff ((x)->flags & SD_F_BUSY), \ 575170815Sariff ("%s(%d): [PCM BUSYASSERT] " \ 576170815Sariff "Failed, snddev_info=%p", \ 577170815Sariff __func__, __LINE__, x)) 578170815Sariff 579170815Sariff#define PCM_GIANT_ENTER(x) do { \ 580170815Sariff int _pcm_giant = 0; \ 581193640Sariff PCM_UNLOCKASSERT(x); \ 582170815Sariff if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \ 583170815Sariff do { \ 584170815Sariff mtx_lock(&Giant); \ 585170815Sariff _pcm_giant = 1; \ 586193640Sariff } while (0) 587170815Sariff 588170815Sariff#define PCM_GIANT_EXIT(x) do { \ 589193640Sariff PCM_UNLOCKASSERT(x); \ 590170815Sariff KASSERT(_pcm_giant == 0 || _pcm_giant == 1, \ 591170815Sariff ("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \ 592170815Sariff __func__, __LINE__)); \ 593170815Sariff KASSERT(!((x)->flags & SD_F_MPSAFE) || \ 594170815Sariff (((x)->flags & SD_F_MPSAFE) && _pcm_giant == 0), \ 595170815Sariff ("%s(%d): [GIANT EXIT] MPSAFE Giant?", \ 596170815Sariff __func__, __LINE__)); \ 597170815Sariff if (_pcm_giant != 0) { \ 598170815Sariff mtx_assert(&Giant, MA_OWNED); \ 599170815Sariff _pcm_giant = 0; \ 600170815Sariff mtx_unlock(&Giant); \ 601170815Sariff } \ 602193640Sariff} while (0) 603170815Sariff#endif /* !SND_DIAGNOSTIC */ 604170815Sariff 605170815Sariff#define PCM_GIANT_LEAVE(x) \ 606170815Sariff PCM_GIANT_EXIT(x); \ 607193640Sariff} while (0) 608170815Sariff 609126695Smatk#ifdef KLD_MODULE 610126695Smatk#define PCM_KLDSTRING(a) ("kld " # a) 611126695Smatk#else 612126695Smatk#define PCM_KLDSTRING(a) "" 613126695Smatk#endif 614126695Smatk 61582180Scg#endif /* _KERNEL */ 61682180Scg 61782180Scg#endif /* _OS_H_ */ 618