43#include <sys/eventhandler.h>
44#include <sys/ioccom.h>
46#include <sys/sockio.h>
48#include <sys/selinfo.h>
50#include <sys/kernel.h>
51#include <sys/module.h>
55#include <sys/syslog.h>
57#include <sys/malloc.h>
59#include <machine/resource.h>
60#include <machine/bus.h>
62#include <sys/limits.h>
66#include <sys/soundcard.h>
67#include <sys/sndstat.h>
68#include <sys/sysctl.h>
75#include <sys/condvar.h>
78#define KOBJMETHOD_END { NULL, NULL }
96#define PCM_SOFTC_SIZE (sizeof(struct snddev_info))
98#define SND_STATUSLEN 64
100#define SOUND_MODVER 5
102#define SOUND_MINVER SOUND_MODVER
103#define SOUND_PREFVER SOUND_MODVER
104#define SOUND_MAXVER SOUND_MODVER
113#define PCMMAXUNIT (snd_max_u())
114#define PCMMAXDEV (snd_max_d())
115#define PCMMAXCHAN (snd_max_c())
117#define PCMMAXCLONE PCMMAXCHAN
119#define PCMUNIT(x) (snd_unit2u(dev2unit(x)))
120#define PCMDEV(x) (snd_unit2d(dev2unit(x)))
121#define PCMCHAN(x) (snd_unit2c(dev2unit(x)))
124#define PCMMINOR(x) (x)
129#define SND_MAXHWCHAN 256
130#define SND_MAXVCHANS SND_MAXHWCHAN
132#define SD_F_SIMPLEX 0x00000001
133#define SD_F_AUTOVCHAN 0x00000002
134#define SD_F_SOFTPCMVOL 0x00000004
135#define SD_F_DYING 0x00000008
136#define SD_F_DETACHING 0x00000010
137#define SD_F_BUSY 0x00000020
138#define SD_F_MPSAFE 0x00000040
139#define SD_F_REGISTERED 0x00000080
140#define SD_F_BITPERFECT 0x00000100
141#define SD_F_VPC 0x00000200
142#define SD_F_EQ 0x00000400
143#define SD_F_EQ_ENABLED 0x00000800
144#define SD_F_EQ_BYPASSED 0x00001000
145#define SD_F_EQ_PC 0x00002000
147#define SD_F_EQ_DEFAULT (SD_F_EQ | SD_F_EQ_ENABLED)
148#define SD_F_EQ_MASK (SD_F_EQ | SD_F_EQ_ENABLED | \
149 SD_F_EQ_BYPASSED | SD_F_EQ_PC)
151#define SD_F_PRIO_RD 0x10000000
152#define SD_F_PRIO_WR 0x20000000
153#define SD_F_PRIO_SET (SD_F_PRIO_RD | SD_F_PRIO_WR)
154#define SD_F_DIR_SET 0x40000000
155#define SD_F_TRANSIENT 0xf0000000
157#define SD_F_BITS "\020" \
176#define PCM_ALIVE(x) ((x) != NULL && (x)->lock != NULL && \
177 !((x)->flags & SD_F_DYING))
178#define PCM_REGISTERED(x) (PCM_ALIVE(x) && \
179 ((x)->flags & SD_F_REGISTERED))
181#define PCM_DETACHING(x) ((x)->flags & SD_F_DETACHING)
184#define RANGE(var, low, high) (var) = \
185 (((var)<(low))? (low) : ((var)>(high))? (high) : (var))
186#define DSP_BUFFSIZE (8192)
189#define AFMT_32BIT (AFMT_S32_LE | AFMT_S32_BE | AFMT_U32_LE | AFMT_U32_BE)
190#define AFMT_24BIT (AFMT_S24_LE | AFMT_S24_BE | AFMT_U24_LE | AFMT_U24_BE)
191#define AFMT_16BIT (AFMT_S16_LE | AFMT_S16_BE | AFMT_U16_LE | AFMT_U16_BE)
192#define AFMT_G711 (AFMT_MU_LAW | AFMT_A_LAW)
193#define AFMT_8BIT (AFMT_G711 | AFMT_U8 | AFMT_S8)
194#define AFMT_SIGNED (AFMT_S32_LE | AFMT_S32_BE | AFMT_S24_LE | AFMT_S24_BE | \
195 AFMT_S16_LE | AFMT_S16_BE | AFMT_S8)
196#define AFMT_BIGENDIAN (AFMT_S32_BE | AFMT_U32_BE | AFMT_S24_BE | AFMT_U24_BE | \
197 AFMT_S16_BE | AFMT_U16_BE)
199#define AFMT_CONVERTIBLE (AFMT_8BIT | AFMT_16BIT | AFMT_24BIT | \
203#define AFMT_VCHAN (AFMT_CONVERTIBLE & ~AFMT_G711)
205#define AFMT_PASSTHROUGH AFMT_AC3
206#define AFMT_PASSTHROUGH_RATE 48000
207#define AFMT_PASSTHROUGH_CHANNEL 2
208#define AFMT_PASSTHROUGH_EXTCHANNEL 0
214#define AFMT_ENCODING_MASK 0xf00fffff
215#define AFMT_CHANNEL_MASK 0x07f00000
216#define AFMT_CHANNEL_SHIFT 20
217#define AFMT_CHANNEL_MAX 0x7f
218#define AFMT_EXTCHANNEL_MASK 0x08000000
219#define AFMT_EXTCHANNEL_SHIFT 27
220#define AFMT_EXTCHANNEL_MAX 1
222#define AFMT_ENCODING(v) ((v) & AFMT_ENCODING_MASK)
224#define AFMT_EXTCHANNEL(v) (((v) & AFMT_EXTCHANNEL_MASK) >> \
225 AFMT_EXTCHANNEL_SHIFT)
227#define AFMT_CHANNEL(v) (((v) & AFMT_CHANNEL_MASK) >> \
230#define AFMT_BIT(v) (((v) & AFMT_32BIT) ? 32 : \
231 (((v) & AFMT_24BIT) ? 24 : \
232 ((((v) & AFMT_16BIT) || \
233 ((v) & AFMT_PASSTHROUGH)) ? 16 : 8)))
235#define AFMT_BPS(v) (AFMT_BIT(v) >> 3)
236#define AFMT_ALIGN(v) (AFMT_BPS(v) * AFMT_CHANNEL(v))
238#define SND_FORMAT(f, c, e) (AFMT_ENCODING(f) | \
239 (((c) << AFMT_CHANNEL_SHIFT) & \
240 AFMT_CHANNEL_MASK) | \
241 (((e) << AFMT_EXTCHANNEL_SHIFT) & \
242 AFMT_EXTCHANNEL_MASK))
244#define AFMT_U8_NE AFMT_U8
245#define AFMT_S8_NE AFMT_S8
247#define AFMT_SIGNED_NE (AFMT_S8_NE | AFMT_S16_NE | AFMT_S24_NE | AFMT_S32_NE)
249#define AFMT_NE (AFMT_SIGNED_NE | AFMT_U8_NE | AFMT_U16_NE | \
250 AFMT_U24_NE | AFMT_U32_NE)
263#define SND_DEV_MIDIN 2
265#define SND_DEV_AUDIO 4
266#define SND_DEV_DSP16 5
267#define SND_DEV_STATUS 6
269#define SND_DEV_SEQ2 8
270#define SND_DEV_SNDPROC 9
271#define SND_DEV_PSS SND_DEV_SNDPROC
272#define SND_DEV_NORESET 10
274#define SND_DEV_DSPHW_PLAY 11
275#define SND_DEV_DSPHW_VPLAY 12
276#define SND_DEV_DSPHW_REC 13
277#define SND_DEV_DSPHW_VREC 14
279#define SND_DEV_DSPHW_CD 15
286#define SND_DEV_DSP_MMAP 16
287#define SND_DEV_DSP_AC3 17
288#define SND_DEV_DSP_MULTICH 18
289#define SND_DEV_DSP_SPDIFOUT 19
290#define SND_DEV_DSP_SPDIFIN 20
292#define SND_DEV_LAST SND_DEV_DSP_SPDIFIN
293#define SND_DEV_MAX PCMMAXDEV
295#define DSP_DEFAULT_SPEED 8000
312#define BVDDB(x) if (bootverbose) x
322 pid_t pid,
char *comm,
int devunit);
333unsigned int pcm_getbuffersize(device_t
dev,
unsigned int minbufsz,
unsigned int deflt,
unsigned int maxbufsz);
342 driver_intr_t hand,
void *param,
void **cookiep);
347#define snd_mtxlock(m) mtx_lock(m)
348#define snd_mtxunlock(m) mtx_unlock(m)
356#define SND_DECLARE_FILE(version) \
357 _SND_DECLARE_FILE(__LINE__, version)
359#define _SND_DECLARE_FILE(uniq, version) \
360 __SND_DECLARE_FILE(uniq, version)
362#define __SND_DECLARE_FILE(uniq, version) \
363 static char sndstat_vinfo[] = version; \
364 SYSINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_registerfile, sndstat_vinfo); \
365 SYSUNINIT(sdf_ ## uniq, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, sndstat_unregisterfile, sndstat_vinfo);
368#define DV_F_DRQ_MASK 0x00000007
369#define DV_F_DUAL_DMA 0x00000010
372#define DV_F_DEV_MASK 0x0000ff00
373#define DV_F_DEV_SHIFT 8
415#define PCM_MODE_MIXER 0x01
416#define PCM_MODE_PLAY 0x02
417#define PCM_MODE_REC 0x04
419#define PCM_LOCKOWNED(d) mtx_owned((d)->lock)
420#define PCM_LOCK(d) mtx_lock((d)->lock)
421#define PCM_UNLOCK(d) mtx_unlock((d)->lock)
422#define PCM_TRYLOCK(d) mtx_trylock((d)->lock)
423#define PCM_LOCKASSERT(d) mtx_assert((d)->lock, MA_OWNED)
424#define PCM_UNLOCKASSERT(d) mtx_assert((d)->lock, MA_NOTOWNED)
431#define PCM_WAIT(x) do { \
432 if (!PCM_LOCKOWNED(x)) \
433 panic("%s(%d): [PCM WAIT] Mutex not owned!", \
434 __func__, __LINE__); \
435 while ((x)->flags & SD_F_BUSY) { \
436 if (snd_verbose > 3) \
437 device_printf((x)->dev, \
438 "%s(%d): [PCM WAIT] calling cv_wait().\n", \
439 __func__, __LINE__); \
440 cv_wait(&(x)->cv, (x)->lock); \
444#define PCM_ACQUIRE(x) do { \
445 if (!PCM_LOCKOWNED(x)) \
446 panic("%s(%d): [PCM ACQUIRE] Mutex not owned!", \
447 __func__, __LINE__); \
448 if ((x)->flags & SD_F_BUSY) \
449 panic("%s(%d): [PCM ACQUIRE] " \
450 "Trying to acquire BUSY cv!", __func__, __LINE__); \
451 (x)->flags |= SD_F_BUSY; \
454#define PCM_RELEASE(x) do { \
455 if (!PCM_LOCKOWNED(x)) \
456 panic("%s(%d): [PCM RELEASE] Mutex not owned!", \
457 __func__, __LINE__); \
458 if ((x)->flags & SD_F_BUSY) { \
459 (x)->flags &= ~SD_F_BUSY; \
460 if ((x)->cv.cv_waiters != 0) { \
461 if ((x)->cv.cv_waiters > 1 && snd_verbose > 3) \
462 device_printf((x)->dev, \
463 "%s(%d): [PCM RELEASE] " \
464 "cv_waiters=%d > 1!\n", \
465 __func__, __LINE__, \
466 (x)->cv.cv_waiters); \
467 cv_broadcast(&(x)->cv); \
470 panic("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \
471 __func__, __LINE__); \
475#define PCM_ACQUIRE_QUICK(x) do { \
476 if (PCM_LOCKOWNED(x)) \
477 panic("%s(%d): [PCM ACQUIRE QUICK] Mutex owned!", \
478 __func__, __LINE__); \
485#define PCM_RELEASE_QUICK(x) do { \
486 if (PCM_LOCKOWNED(x)) \
487 panic("%s(%d): [PCM RELEASE QUICK] Mutex owned!", \
488 __func__, __LINE__); \
494#define PCM_BUSYASSERT(x) do { \
495 if (!((x) != NULL && ((x)->flags & SD_F_BUSY))) \
496 panic("%s(%d): [PCM BUSYASSERT] " \
497 "Failed, snddev_info=%p", __func__, __LINE__, x); \
500#define PCM_GIANT_ENTER(x) do { \
501 int _pcm_giant = 0; \
502 if (PCM_LOCKOWNED(x)) \
503 panic("%s(%d): [GIANT ENTER] PCM lock owned!", \
504 __func__, __LINE__); \
505 if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \
506 device_printf((x)->dev, \
507 "%s(%d): [GIANT ENTER] Giant owned!\n", \
508 __func__, __LINE__); \
509 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \
515#define PCM_GIANT_EXIT(x) do { \
516 if (PCM_LOCKOWNED(x)) \
517 panic("%s(%d): [GIANT EXIT] PCM lock owned!", \
518 __func__, __LINE__); \
519 if (!(_pcm_giant == 0 || _pcm_giant == 1)) \
520 panic("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \
521 __func__, __LINE__); \
522 if ((x)->flags & SD_F_MPSAFE) { \
523 if (_pcm_giant == 1) \
524 panic("%s(%d): [GIANT EXIT] MPSAFE Giant?", \
525 __func__, __LINE__); \
526 if (mtx_owned(&Giant) != 0 && snd_verbose > 3) \
527 device_printf((x)->dev, \
528 "%s(%d): [GIANT EXIT] Giant owned!\n", \
529 __func__, __LINE__); \
531 if (_pcm_giant != 0) { \
532 if (mtx_owned(&Giant) == 0) \
533 panic("%s(%d): [GIANT EXIT] Giant not owned!", \
534 __func__, __LINE__); \
536 mtx_unlock(&Giant); \
540#define PCM_WAIT(x) do { \
542 while ((x)->flags & SD_F_BUSY) \
543 cv_wait(&(x)->cv, (x)->lock); \
546#define PCM_ACQUIRE(x) do { \
548 KASSERT(!((x)->flags & SD_F_BUSY), \
549 ("%s(%d): [PCM ACQUIRE] Trying to acquire BUSY cv!", \
550 __func__, __LINE__)); \
551 (x)->flags |= SD_F_BUSY; \
554#define PCM_RELEASE(x) do { \
556 KASSERT((x)->flags & SD_F_BUSY, \
557 ("%s(%d): [PCM RELEASE] Releasing non-BUSY cv!", \
558 __func__, __LINE__)); \
559 (x)->flags &= ~SD_F_BUSY; \
560 if ((x)->cv.cv_waiters != 0) \
561 cv_broadcast(&(x)->cv); \
565#define PCM_ACQUIRE_QUICK(x) do { \
566 PCM_UNLOCKASSERT(x); \
573#define PCM_RELEASE_QUICK(x) do { \
574 PCM_UNLOCKASSERT(x); \
580#define PCM_BUSYASSERT(x) KASSERT(x != NULL && \
581 ((x)->flags & SD_F_BUSY), \
582 ("%s(%d): [PCM BUSYASSERT] " \
583 "Failed, snddev_info=%p", \
584 __func__, __LINE__, x))
586#define PCM_GIANT_ENTER(x) do { \
587 int _pcm_giant = 0; \
588 PCM_UNLOCKASSERT(x); \
589 if (!((x)->flags & SD_F_MPSAFE) && mtx_owned(&Giant) == 0) \
595#define PCM_GIANT_EXIT(x) do { \
596 PCM_UNLOCKASSERT(x); \
597 KASSERT(_pcm_giant == 0 || _pcm_giant == 1, \
598 ("%s(%d): [GIANT EXIT] _pcm_giant screwed!", \
599 __func__, __LINE__)); \
600 KASSERT(!((x)->flags & SD_F_MPSAFE) || \
601 (((x)->flags & SD_F_MPSAFE) && _pcm_giant == 0), \
602 ("%s(%d): [GIANT EXIT] MPSAFE Giant?", \
603 __func__, __LINE__)); \
604 if (_pcm_giant != 0) { \
605 mtx_assert(&Giant, MA_OWNED); \
607 mtx_unlock(&Giant); \
612#define PCM_GIANT_LEAVE(x) \
617#define PCM_KLDSTRING(a) ("kld " # a)
619#define PCM_KLDSTRING(a) ""
SLIST_HEAD(pcm_synclist, pcmchan_syncgroup) snd_pcm_syncgroups
struct pcmchan_matrix * m
void snd_mtxassert(void *m)
void * snd_mtxcreate(const char *desc, const char *type)
void * pcm_getdevinfo(device_t dev)
struct unrhdr * pcmsg_unrhdr
Unit number allocator for syncgroup IDs.
u_int32_t pcm_getflags(device_t dev)
int pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num)
struct pcm_channel * pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo)
int pcm_setstatus(device_t dev, char *str)
void snd_mtxfree(void *m)
int sndstat_unregisterfile(char *str)
int sndstat_registerfile(char *str)
int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
int pcm_chn_destroy(struct pcm_channel *ch)
int sndstat_unregister(device_t dev)
void pcm_setflags(device_t dev, u_int32_t val)
int sound_oss_card_info(oss_card_info *)
int pcm_unregister(device_t dev)
void sound_oss_sysinfo(oss_sysinfo *)
Handle OSSv4 SNDCTL_SYSINFO ioctl.
int pcm_inprog(struct snddev_info *d, int delta)
int pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, char *comm, int devunit)
int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
int(* sndstat_handler)(struct sbuf *s, device_t dev, int verbose)
int sndstat_register(device_t dev, char *str, sndstat_handler handler)
int pcm_chnref(struct pcm_channel *c, int ref)
int pcm_chnrelease(struct pcm_channel *c)
int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch)
struct snddev_info::@49::@50::@51 busy
TAILQ_HEAD(dsp_cdevinfo_linkhead, dsp_cdevinfo) dsp_cdevinfo_pool
char status[SND_STATUSLEN]
struct snd_clone * clones
struct snddev_info::@49::@50 pcm
struct snddev_info::@49::@50::@52 opened
struct sysctl_oid * play_sysctl_tree
struct snddev_info::@49 channels
struct sysctl_ctx_list play_sysctl_ctx rec_sysctl_ctx
struct sysctl_oid * rec_sysctl_tree