2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <dev/sound/pcm/sound.h>
28 #include <sys/ctype.h>
30 SND_DECLARE_FILE("$FreeBSD$");
32 static int dsp_mmap_allow_prot_exec = 0;
33 SYSCTL_INT(_hw_snd, OID_AUTO, compat_linux_mmap, CTLFLAG_RW,
34 &dsp_mmap_allow_prot_exec, 0, "linux mmap compatibility");
37 struct pcm_channel *rdch, *wrch;
39 TAILQ_ENTRY(dsp_cdevinfo) link;
42 #define PCM_RDCH(x) (((struct dsp_cdevinfo *)(x)->si_drv1)->rdch)
43 #define PCM_WRCH(x) (((struct dsp_cdevinfo *)(x)->si_drv1)->wrch)
44 #define PCM_SIMPLEX(x) (((struct dsp_cdevinfo *)(x)->si_drv1)->simplex)
46 #define DSP_CDEVINFO_CACHESIZE 8
48 #define DSP_REGISTERED(x, y) (PCM_REGISTERED(x) && \
49 (y) != NULL && (y)->si_drv1 != NULL)
53 static d_open_t dsp_open;
54 static d_close_t dsp_close;
55 static d_read_t dsp_read;
56 static d_write_t dsp_write;
57 static d_ioctl_t dsp_ioctl;
58 static d_poll_t dsp_poll;
59 static d_mmap_t dsp_mmap;
61 struct cdevsw dsp_cdevsw = {
62 .d_version = D_VERSION,
74 static eventhandler_tag dsp_ehtag = NULL;
75 static int dsp_umax = -1;
76 static int dsp_cmax = -1;
79 static int dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgroup *group);
80 static int dsp_oss_syncstart(int sg_id);
81 static int dsp_oss_policy(struct pcm_channel *wrch, struct pcm_channel *rdch, int policy);
82 #ifdef OSSV4_EXPERIMENT
83 static int dsp_oss_cookedmode(struct pcm_channel *wrch, struct pcm_channel *rdch, int enabled);
84 static int dsp_oss_getchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map);
85 static int dsp_oss_setchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map);
86 static int dsp_oss_getlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label);
87 static int dsp_oss_setlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label);
88 static int dsp_oss_getsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song);
89 static int dsp_oss_setsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song);
90 static int dsp_oss_setname(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *name);
93 static struct snddev_info *
94 dsp_get_info(struct cdev *dev)
96 return (devclass_get_softc(pcm_devclass, PCMUNIT(dev)));
100 dsp_get_flags(struct cdev *dev)
104 bdev = devclass_get_device(pcm_devclass, PCMUNIT(dev));
106 return ((bdev != NULL) ? pcm_getflags(bdev) : 0xffffffff);
110 dsp_set_flags(struct cdev *dev, uint32_t flags)
114 bdev = devclass_get_device(pcm_devclass, PCMUNIT(dev));
117 pcm_setflags(bdev, flags);
121 * return the channels associated with an open device instance.
122 * lock channels specified.
125 getchns(struct cdev *dev, struct pcm_channel **rdch, struct pcm_channel **wrch,
128 struct snddev_info *d;
129 struct pcm_channel *ch;
132 if (PCM_SIMPLEX(dev) != 0) {
133 d = dsp_get_info(dev);
134 if (!PCM_REGISTERED(d))
140 * Note: order is important -
141 * pcm flags -> prio query flags -> wild guess
144 flags = dsp_get_flags(dev);
145 if (flags & SD_F_PRIO_WR) {
147 PCM_RDCH(dev) = NULL;
148 } else if (flags & SD_F_PRIO_RD) {
150 PCM_WRCH(dev) = NULL;
151 } else if (prio & SD_F_PRIO_WR) {
153 PCM_RDCH(dev) = NULL;
154 flags |= SD_F_PRIO_WR;
155 } else if (prio & SD_F_PRIO_RD) {
157 PCM_WRCH(dev) = NULL;
158 flags |= SD_F_PRIO_RD;
159 } else if (PCM_WRCH(dev) != NULL) {
161 PCM_RDCH(dev) = NULL;
162 flags |= SD_F_PRIO_WR;
163 } else if (PCM_RDCH(dev) != NULL) {
165 PCM_WRCH(dev) = NULL;
166 flags |= SD_F_PRIO_RD;
168 PCM_SIMPLEX(dev) = 0;
169 dsp_set_flags(dev, flags);
179 *rdch = PCM_RDCH(dev);
180 *wrch = PCM_WRCH(dev);
182 if (*rdch != NULL && (prio & SD_F_PRIO_RD))
184 if (*wrch != NULL && (prio & SD_F_PRIO_WR))
190 /* unlock specified channels */
192 relchns(struct cdev *dev, struct pcm_channel *rdch, struct pcm_channel *wrch,
195 if (wrch != NULL && (prio & SD_F_PRIO_WR))
197 if (rdch != NULL && (prio & SD_F_PRIO_RD))
202 dsp_cdevinfo_alloc(struct cdev *dev,
203 struct pcm_channel *rdch, struct pcm_channel *wrch)
205 struct snddev_info *d;
206 struct dsp_cdevinfo *cdi;
209 d = dsp_get_info(dev);
211 KASSERT(PCM_REGISTERED(d) && dev != NULL && dev->si_drv1 == NULL &&
213 ("bogus %s(), what are you trying to accomplish here?", __func__));
215 mtx_assert(d->lock, MA_OWNED);
217 simplex = (dsp_get_flags(dev) & SD_F_SIMPLEX) ? 1 : 0;
220 * Scan for free instance entry and put it into the end of list.
221 * Create new one if necessary.
223 TAILQ_FOREACH(cdi, &d->dsp_cdevinfo_pool, link) {
228 cdi->simplex = simplex;
230 TAILQ_REMOVE(&d->dsp_cdevinfo_pool, cdi, link);
231 TAILQ_INSERT_TAIL(&d->dsp_cdevinfo_pool, cdi, link);
236 cdi = malloc(sizeof(*cdi), M_DEVBUF, M_WAITOK | M_ZERO);
240 cdi->simplex = simplex;
242 TAILQ_INSERT_TAIL(&d->dsp_cdevinfo_pool, cdi, link);
247 dsp_cdevinfo_free(struct cdev *dev)
249 struct snddev_info *d;
250 struct dsp_cdevinfo *cdi, *tmp;
254 d = dsp_get_info(dev);
256 KASSERT(PCM_REGISTERED(d) && dev != NULL && dev->si_drv1 != NULL &&
257 PCM_RDCH(dev) == NULL && PCM_WRCH(dev) == NULL,
258 ("bogus %s(), what are you trying to accomplish here?", __func__));
260 mtx_assert(d->lock, MA_OWNED);
270 * Once it is free, move it back to the beginning of list for
271 * faster new entry allocation.
273 TAILQ_REMOVE(&d->dsp_cdevinfo_pool, cdi, link);
274 TAILQ_INSERT_HEAD(&d->dsp_cdevinfo_pool, cdi, link);
277 * Scan the list, cache free entries up to DSP_CDEVINFO_CACHESIZE.
278 * Reset simplex flags.
280 flags = dsp_get_flags(dev) & ~SD_F_PRIO_SET;
281 i = DSP_CDEVINFO_CACHESIZE;
282 TAILQ_FOREACH_SAFE(cdi, &d->dsp_cdevinfo_pool, link, tmp) {
283 if (cdi->busy != 0) {
284 if (cdi->simplex == 0) {
285 if (cdi->rdch != NULL)
286 flags |= SD_F_PRIO_RD;
287 if (cdi->wrch != NULL)
288 flags |= SD_F_PRIO_WR;
292 TAILQ_REMOVE(&d->dsp_cdevinfo_pool, cdi, link);
298 dsp_set_flags(dev, flags);
302 dsp_cdevinfo_init(struct snddev_info *d)
304 struct dsp_cdevinfo *cdi;
307 KASSERT(d != NULL, ("NULL snddev_info"));
309 mtx_assert(d->lock, MA_NOTOWNED);
311 TAILQ_INIT(&d->dsp_cdevinfo_pool);
312 for (i = 0; i < DSP_CDEVINFO_CACHESIZE; i++) {
313 cdi = malloc(sizeof(*cdi), M_DEVBUF, M_WAITOK | M_ZERO);
314 TAILQ_INSERT_HEAD(&d->dsp_cdevinfo_pool, cdi, link);
319 dsp_cdevinfo_flush(struct snddev_info *d)
321 struct dsp_cdevinfo *cdi, *tmp;
323 KASSERT(d != NULL, ("NULL snddev_info"));
325 mtx_assert(d->lock, MA_NOTOWNED);
327 cdi = TAILQ_FIRST(&d->dsp_cdevinfo_pool);
328 while (cdi != NULL) {
329 tmp = TAILQ_NEXT(cdi, link);
333 TAILQ_INIT(&d->dsp_cdevinfo_pool);
336 /* duplex / simplex cdev type */
338 DSP_CDEV_TYPE_RDONLY, /* simplex read-only (record) */
339 DSP_CDEV_TYPE_WRONLY, /* simplex write-only (play) */
340 DSP_CDEV_TYPE_RDWR, /* duplex read, write, or both */
343 #define DSP_F_VALID(x) ((x) & (FREAD | FWRITE))
344 #define DSP_F_DUPLEX(x) (((x) & (FREAD | FWRITE)) == (FREAD | FWRITE))
345 #define DSP_F_SIMPLEX(x) (!DSP_F_DUPLEX(x))
346 #define DSP_F_READ(x) ((x) & FREAD)
347 #define DSP_F_WRITE(x) ((x) & FWRITE)
349 static const struct {
359 { SND_DEV_DSP, "dsp", ".", 0, 0, 0,
360 AFMT_U8, DSP_DEFAULT_SPEED, DSP_CDEV_TYPE_RDWR },
361 { SND_DEV_AUDIO, "audio", ".", 0, 0, 0,
362 AFMT_MU_LAW, DSP_DEFAULT_SPEED, DSP_CDEV_TYPE_RDWR },
363 { SND_DEV_DSP16, "dspW", ".", 0, 0, 0,
364 AFMT_S16_LE, DSP_DEFAULT_SPEED, DSP_CDEV_TYPE_RDWR },
365 { SND_DEV_DSPHW_PLAY, "dsp", ".p", 1, 1, SND_MAXHWCHAN,
366 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_WRONLY },
367 { SND_DEV_DSPHW_VPLAY, "dsp", ".vp", 1, 1, SND_MAXVCHANS,
368 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_WRONLY },
369 { SND_DEV_DSPHW_REC, "dsp", ".r", 1, 1, SND_MAXHWCHAN,
370 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_RDONLY },
371 { SND_DEV_DSPHW_VREC, "dsp", ".vr", 1, 1, SND_MAXVCHANS,
372 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_RDONLY },
373 { SND_DEV_DSPHW_CD, "dspcd", ".", 0, 0, 0,
374 AFMT_S16_LE | AFMT_STEREO, 44100, DSP_CDEV_TYPE_RDWR },
375 { SND_DEV_DSP_MMAP, "dsp_mmap", ".", 0, 0, 0,
376 AFMT_S16_LE | AFMT_STEREO, 48000, DSP_CDEV_TYPE_RDWR },
379 #define DSP_FIXUP_ERROR() do { \
380 prio = dsp_get_flags(i_dev); \
381 if (!DSP_F_VALID(flags)) \
383 if (!DSP_F_DUPLEX(flags) && \
384 ((DSP_F_READ(flags) && d->reccount == 0) || \
385 (DSP_F_WRITE(flags) && d->playcount == 0))) \
387 else if (!DSP_F_DUPLEX(flags) && (prio & SD_F_SIMPLEX) && \
388 ((DSP_F_READ(flags) && (prio & SD_F_PRIO_WR)) || \
389 (DSP_F_WRITE(flags) && (prio & SD_F_PRIO_RD)))) \
391 else if (DSP_REGISTERED(d, i_dev)) \
396 dsp_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
398 struct pcm_channel *rdch, *wrch;
399 struct snddev_info *d;
400 uint32_t fmt, spd, prio;
401 int i, error, rderror, wrerror, devtype, wdevunit, rdevunit;
403 /* Kind of impossible.. */
404 if (i_dev == NULL || td == NULL)
407 d = dsp_get_info(i_dev);
408 if (!PCM_REGISTERED(d))
413 /* Lock snddev so nobody else can monkey with it. */
418 * Try to acquire cloned device before someone else pick it.
419 * ENODEV means this is not a cloned droids.
421 error = snd_clone_acquire(i_dev);
422 if (!(error == 0 || error == ENODEV)) {
433 (void)snd_clone_release(i_dev);
440 * That is just enough. Acquire and unlock pcm lock so
441 * the other will just have to wait until we finish doing
447 devtype = PCMDEV(i_dev);
453 for (i = 0; i < (sizeof(dsp_cdevs) / sizeof(dsp_cdevs[0])); i++) {
454 if (devtype != dsp_cdevs[i].type)
456 if (DSP_F_SIMPLEX(flags) &&
457 ((dsp_cdevs[i].query == DSP_CDEV_TYPE_WRONLY &&
458 DSP_F_READ(flags)) ||
459 (dsp_cdevs[i].query == DSP_CDEV_TYPE_RDONLY &&
460 DSP_F_WRITE(flags)))) {
462 * simplex, opposite direction? Please be gone..
464 (void)snd_clone_release(i_dev);
465 PCM_RELEASE_QUICK(d);
469 if (dsp_cdevs[i].query == DSP_CDEV_TYPE_WRONLY)
470 wdevunit = dev2unit(i_dev);
471 else if (dsp_cdevs[i].query == DSP_CDEV_TYPE_RDONLY)
472 rdevunit = dev2unit(i_dev);
473 fmt = dsp_cdevs[i].fmt;
474 spd = dsp_cdevs[i].spd;
478 /* No matching devtype? */
479 if (fmt == 0 || spd == 0)
480 panic("impossible devtype %d", devtype);
488 * if we get here, the open request is valid- either:
489 * * we were previously not open
490 * * we were open for play xor record and the opener wants
491 * the non-open direction
493 if (DSP_F_READ(flags)) {
495 rderror = pcm_chnalloc(d, &rdch, PCMDIR_REC,
496 td->td_proc->p_pid, rdevunit);
498 if (rderror == 0 && (chn_reset(rdch, fmt) != 0 ||
499 (chn_setspeed(rdch, spd) != 0)))
504 pcm_chnrelease(rdch);
505 if (!DSP_F_DUPLEX(flags)) {
506 (void)snd_clone_release(i_dev);
507 PCM_RELEASE_QUICK(d);
513 if (flags & O_NONBLOCK)
514 rdch->flags |= CHN_F_NBIO;
520 if (DSP_F_WRITE(flags)) {
522 wrerror = pcm_chnalloc(d, &wrch, PCMDIR_PLAY,
523 td->td_proc->p_pid, wdevunit);
525 if (wrerror == 0 && (chn_reset(wrch, fmt) != 0 ||
526 (chn_setspeed(wrch, spd) != 0)))
531 pcm_chnrelease(wrch);
532 if (!DSP_F_DUPLEX(flags)) {
535 * Lock, deref and release previously
536 * created record channel
539 pcm_chnref(rdch, -1);
540 pcm_chnrelease(rdch);
542 (void)snd_clone_release(i_dev);
543 PCM_RELEASE_QUICK(d);
549 if (flags & O_NONBLOCK)
550 wrch->flags |= CHN_F_NBIO;
556 if (rdch == NULL && wrch == NULL) {
557 (void)snd_clone_release(i_dev);
558 PCM_RELEASE_QUICK(d);
560 return ((wrerror != 0) ? wrerror : rderror);
566 * We're done. Allocate channels information for this cdev.
568 dsp_cdevinfo_alloc(i_dev, rdch, wrch);
571 * Increase clone refcount for its automatic garbage collector.
573 (void)snd_clone_ref(i_dev);
584 dsp_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
586 struct pcm_channel *rdch, *wrch;
587 struct snddev_info *d;
590 d = dsp_get_info(i_dev);
591 if (!DSP_REGISTERED(d, i_dev))
599 rdch = PCM_RDCH(i_dev);
600 wrch = PCM_WRCH(i_dev);
609 * The channel itself need not be locked because:
610 * a) Adding a channel to a syncgroup happens only in dsp_ioctl(),
611 * which cannot run concurrently to dsp_close().
612 * b) The syncmember pointer (sm) is protected by the global
613 * syncgroup list lock.
614 * c) A channel can't just disappear, invalidating pointers,
615 * unless it's closed/dereferenced first.
618 sg_ids = chn_syncdestroy(rdch);
621 free_unr(pcmsg_unrhdr, sg_ids);
624 refs += pcm_chnref(rdch, -1);
625 chn_abort(rdch); /* won't sleep */
626 rdch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
628 pcm_chnrelease(rdch);
629 PCM_RDCH(i_dev) = NULL;
633 * Please see block above.
636 sg_ids = chn_syncdestroy(wrch);
639 free_unr(pcmsg_unrhdr, sg_ids);
642 refs += pcm_chnref(wrch, -1);
643 chn_flush(wrch); /* may sleep */
644 wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
646 pcm_chnrelease(wrch);
647 PCM_WRCH(i_dev) = NULL;
652 * If there are no more references, release the channels.
654 if (refs == 0 && PCM_RDCH(i_dev) == NULL &&
655 PCM_WRCH(i_dev) == NULL) {
656 dsp_cdevinfo_free(i_dev);
658 * Release clone busy state and unref it
659 * so the automatic garbage collector will
660 * get the hint and do the remaining cleanup
663 (void)snd_clone_release(i_dev);
666 * destroy_dev() might sleep, so release pcm lock
667 * here and rely on pcm cv serialization.
670 (void)snd_clone_unref(i_dev);
684 dsp_io_ops(struct cdev *i_dev, struct uio *buf)
686 struct snddev_info *d;
687 struct pcm_channel **ch, *rdch, *wrch;
688 int (*chn_io)(struct pcm_channel *, struct uio *);
692 KASSERT(i_dev != NULL && buf != NULL &&
693 (buf->uio_rw == UIO_READ || buf->uio_rw == UIO_WRITE),
694 ("%s(): io train wreck!", __func__));
696 d = dsp_get_info(i_dev);
697 if (!DSP_REGISTERED(d, i_dev))
702 switch (buf->uio_rw) {
714 panic("invalid/corrupted uio direction: %d", buf->uio_rw);
720 runpid = buf->uio_td->td_proc->p_pid;
722 getchns(i_dev, &rdch, &wrch, prio);
724 if (*ch == NULL || !((*ch)->flags & CHN_F_BUSY)) {
729 if (((*ch)->flags & (CHN_F_MAPPED | CHN_F_DEAD)) ||
730 (((*ch)->flags & CHN_F_RUNNING) && (*ch)->pid != runpid)) {
731 relchns(i_dev, rdch, wrch, prio);
734 } else if (!((*ch)->flags & CHN_F_RUNNING)) {
735 (*ch)->flags |= CHN_F_RUNNING;
740 * chn_read/write must give up channel lock in order to copy bytes
741 * from/to userland, so up the "in progress" counter to make sure
742 * someone else doesn't come along and muss up the buffer.
745 ret = chn_io(*ch, buf);
748 CHN_BROADCAST(&(*ch)->cv);
750 relchns(i_dev, rdch, wrch, prio);
758 dsp_read(struct cdev *i_dev, struct uio *buf, int flag)
760 return (dsp_io_ops(i_dev, buf));
764 dsp_write(struct cdev *i_dev, struct uio *buf, int flag)
766 return (dsp_io_ops(i_dev, buf));
770 dsp_ioctl(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
772 struct pcm_channel *chn, *rdch, *wrch;
773 struct snddev_info *d;
774 int *arg_i, ret, kill, tmp, xcmd;
776 d = dsp_get_info(i_dev);
777 if (!DSP_REGISTERED(d, i_dev))
787 * this is an evil hack to allow broken apps to perform mixer ioctls
790 if (IOCGROUP(cmd) == 'M') {
792 * This is at least, a bug to bug compatible with OSS.
794 if (d->mixer_dev != NULL) {
795 PCM_ACQUIRE_QUICK(d);
796 ret = mixer_ioctl_cmd(d->mixer_dev, cmd, arg, -1, td,
798 PCM_RELEASE_QUICK(d);
808 * Certain ioctls may be made on any type of device (audio, mixer,
809 * and MIDI). Handle those special cases here.
811 if (IOCGROUP(cmd) == 'X') {
812 PCM_ACQUIRE_QUICK(d);
815 sound_oss_sysinfo((oss_sysinfo *)arg);
817 case SNDCTL_AUDIOINFO:
818 ret = dsp_oss_audioinfo(i_dev, (oss_audioinfo *)arg);
820 case SNDCTL_MIXERINFO:
821 ret = mixer_oss_mixerinfo(i_dev, (oss_mixerinfo *)arg);
826 PCM_RELEASE_QUICK(d);
831 getchns(i_dev, &rdch, &wrch, 0);
834 if (wrch && (wrch->flags & CHN_F_DEAD))
836 if (rdch && (rdch->flags & CHN_F_DEAD))
839 relchns(i_dev, rdch, wrch, 0);
848 if (wrch == NULL && rdch == NULL) {
849 relchns(i_dev, rdch, wrch, 0);
857 * we start with the new ioctl interface.
859 case AIONWRITE: /* how many bytes can write ? */
863 if (wrch && wrch->bufhard.dl)
864 while (chn_wrfeed(wrch) == 0);
866 *arg_i = sndbuf_getfree(wrch->bufsoft);
874 case AIOSSIZE: /* set the current blocksize */
876 struct snd_size *p = (struct snd_size *)arg;
880 PCM_ACQUIRE_QUICK(d);
883 chn_setblocksize(wrch, 2, p->play_size);
884 p->play_size = sndbuf_getblksz(wrch->bufsoft);
889 chn_setblocksize(rdch, 2, p->rec_size);
890 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
893 PCM_RELEASE_QUICK(d);
896 case AIOGSIZE: /* get the current blocksize */
898 struct snd_size *p = (struct snd_size *)arg;
902 p->play_size = sndbuf_getblksz(wrch->bufsoft);
907 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
916 snd_chan_param *p = (snd_chan_param *)arg;
918 if (cmd == AIOSFMT &&
919 ((p->play_format != 0 && p->play_rate == 0) ||
920 (p->rec_format != 0 && p->rec_rate == 0))) {
924 PCM_ACQUIRE_QUICK(d);
927 if (cmd == AIOSFMT && p->play_format != 0) {
928 chn_setformat(wrch, p->play_format);
929 chn_setspeed(wrch, p->play_rate);
931 p->play_rate = wrch->speed;
932 p->play_format = wrch->format;
940 if (cmd == AIOSFMT && p->rec_format != 0) {
941 chn_setformat(rdch, p->rec_format);
942 chn_setspeed(rdch, p->rec_rate);
944 p->rec_rate = rdch->speed;
945 p->rec_format = rdch->format;
951 PCM_RELEASE_QUICK(d);
955 case AIOGCAP: /* get capabilities */
957 snd_capabilities *p = (snd_capabilities *)arg;
958 struct pcmchan_caps *pcaps = NULL, *rcaps = NULL;
964 rcaps = chn_getcaps(rdch);
968 pcaps = chn_getcaps(wrch);
970 p->rate_min = max(rcaps? rcaps->minspeed : 0,
971 pcaps? pcaps->minspeed : 0);
972 p->rate_max = min(rcaps? rcaps->maxspeed : 1000000,
973 pcaps? pcaps->maxspeed : 1000000);
974 p->bufsize = min(rdch? sndbuf_getsize(rdch->bufsoft) : 1000000,
975 wrch? sndbuf_getsize(wrch->bufsoft) : 1000000);
976 /* XXX bad on sb16 */
977 p->formats = (rdch? chn_getformats(rdch) : 0xffffffff) &
978 (wrch? chn_getformats(wrch) : 0xffffffff);
980 p->formats |= (dsp_get_flags(i_dev) & SD_F_SIMPLEX)? 0 : AFMT_FULLDUPLEX;
982 p->mixers = 1; /* default: one mixer */
983 p->inputs = pdev->si_drv1? mix_getdevs(pdev->si_drv1) : 0;
984 p->left = p->right = 100;
994 if (*arg_i == AIOSYNC_PLAY && wrch) {
996 *arg_i = chn_abort(wrch);
998 } else if (*arg_i == AIOSYNC_CAPTURE && rdch) {
1000 *arg_i = chn_abort(rdch);
1003 printf("AIOSTOP: bad channel 0x%x\n", *arg_i);
1009 printf("AIOSYNC chan 0x%03lx pos %lu unimplemented\n",
1010 ((snd_sync_parm *)arg)->chan, ((snd_sync_parm *)arg)->pos);
1014 * here follow the standard ioctls (filio.h etc.)
1016 case FIONREAD: /* get # bytes to read */
1019 /* if (rdch && rdch->bufhard.dl)
1020 while (chn_rdfeed(rdch) == 0);
1022 *arg_i = sndbuf_getready(rdch->bufsoft);
1030 case FIOASYNC: /*set/clear async i/o */
1031 DEB( printf("FIOASYNC\n") ; )
1034 case SNDCTL_DSP_NONBLOCK: /* set non-blocking i/o */
1035 case FIONBIO: /* set/clear non-blocking i/o */
1038 if (cmd == SNDCTL_DSP_NONBLOCK || *arg_i)
1039 rdch->flags |= CHN_F_NBIO;
1041 rdch->flags &= ~CHN_F_NBIO;
1046 if (cmd == SNDCTL_DSP_NONBLOCK || *arg_i)
1047 wrch->flags |= CHN_F_NBIO;
1049 wrch->flags &= ~CHN_F_NBIO;
1055 * Finally, here is the linux-compatible ioctl interface
1057 #define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
1058 case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
1059 case SNDCTL_DSP_GETBLKSIZE:
1060 chn = wrch ? wrch : rdch;
1063 *arg_i = sndbuf_getblksz(chn->bufsoft);
1071 case SNDCTL_DSP_SETBLKSIZE:
1072 RANGE(*arg_i, 16, 65536);
1073 PCM_ACQUIRE_QUICK(d);
1076 chn_setblocksize(wrch, 2, *arg_i);
1081 chn_setblocksize(rdch, 2, *arg_i);
1084 PCM_RELEASE_QUICK(d);
1087 case SNDCTL_DSP_RESET:
1088 DEB(printf("dsp reset\n"));
1103 case SNDCTL_DSP_SYNC:
1104 DEB(printf("dsp sync\n"));
1105 /* chn_sync may sleep */
1113 case SNDCTL_DSP_SPEED:
1114 /* chn_setspeed may sleep */
1116 PCM_ACQUIRE_QUICK(d);
1119 ret = chn_setspeed(wrch, *arg_i);
1123 if (rdch && ret == 0) {
1125 ret = chn_setspeed(rdch, *arg_i);
1130 PCM_RELEASE_QUICK(d);
1134 case SOUND_PCM_READ_RATE:
1135 chn = wrch ? wrch : rdch;
1138 *arg_i = chn->speed;
1146 case SNDCTL_DSP_STEREO:
1148 *arg_i = (*arg_i)? AFMT_STEREO : 0;
1149 PCM_ACQUIRE_QUICK(d);
1152 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
1153 tmp = (wrch->format & AFMT_STEREO)? 1 : 0;
1156 if (rdch && ret == 0) {
1158 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
1160 tmp = (rdch->format & AFMT_STEREO)? 1 : 0;
1163 PCM_RELEASE_QUICK(d);
1167 case SOUND_PCM_WRITE_CHANNELS:
1168 /* case SNDCTL_DSP_CHANNELS: ( == SOUND_PCM_WRITE_CHANNELS) */
1171 *arg_i = (*arg_i != 1)? AFMT_STEREO : 0;
1172 PCM_ACQUIRE_QUICK(d);
1175 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
1176 tmp = (wrch->format & AFMT_STEREO)? 2 : 1;
1179 if (rdch && ret == 0) {
1181 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
1183 tmp = (rdch->format & AFMT_STEREO)? 2 : 1;
1186 PCM_RELEASE_QUICK(d);
1189 chn = wrch ? wrch : rdch;
1191 *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1;
1196 case SOUND_PCM_READ_CHANNELS:
1197 chn = wrch ? wrch : rdch;
1200 *arg_i = (chn->format & AFMT_STEREO) ? 2 : 1;
1208 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */
1209 chn = wrch ? wrch : rdch;
1212 *arg_i = chn_getformats(chn);
1220 case SNDCTL_DSP_SETFMT: /* sets _one_ format */
1221 if ((*arg_i != AFMT_QUERY)) {
1223 PCM_ACQUIRE_QUICK(d);
1226 ret = chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO));
1227 tmp = wrch->format & ~AFMT_STEREO;
1230 if (rdch && ret == 0) {
1232 ret = chn_setformat(rdch, (*arg_i) | (rdch->format & AFMT_STEREO));
1234 tmp = rdch->format & ~AFMT_STEREO;
1237 PCM_RELEASE_QUICK(d);
1240 chn = wrch ? wrch : rdch;
1242 *arg_i = chn->format & ~AFMT_STEREO;
1247 case SNDCTL_DSP_SETFRAGMENT:
1248 DEB(printf("SNDCTL_DSP_SETFRAGMENT 0x%08x\n", *(int *)arg));
1250 uint32_t fragln = (*arg_i) & 0x0000ffff;
1251 uint32_t maxfrags = ((*arg_i) & 0xffff0000) >> 16;
1253 uint32_t r_maxfrags, r_fragsz;
1255 RANGE(fragln, 4, 16);
1256 fragsz = 1 << fragln;
1259 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
1262 if (maxfrags * fragsz > CHN_2NDBUFMAXSIZE)
1263 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
1265 DEB(printf("SNDCTL_DSP_SETFRAGMENT %d frags, %d sz\n", maxfrags, fragsz));
1266 PCM_ACQUIRE_QUICK(d);
1269 ret = chn_setblocksize(rdch, maxfrags, fragsz);
1270 r_maxfrags = sndbuf_getblkcnt(rdch->bufsoft);
1271 r_fragsz = sndbuf_getblksz(rdch->bufsoft);
1274 r_maxfrags = maxfrags;
1277 if (wrch && ret == 0) {
1279 ret = chn_setblocksize(wrch, maxfrags, fragsz);
1280 maxfrags = sndbuf_getblkcnt(wrch->bufsoft);
1281 fragsz = sndbuf_getblksz(wrch->bufsoft);
1283 } else { /* use whatever came from the read channel */
1284 maxfrags = r_maxfrags;
1287 PCM_RELEASE_QUICK(d);
1290 while (fragsz > 1) {
1294 *arg_i = (maxfrags << 16) | fragln;
1298 case SNDCTL_DSP_GETISPACE:
1299 /* return the size of data available in the input queue */
1301 audio_buf_info *a = (audio_buf_info *)arg;
1303 struct snd_dbuf *bs = rdch->bufsoft;
1306 a->bytes = sndbuf_getready(bs);
1307 a->fragments = a->bytes / sndbuf_getblksz(bs);
1308 a->fragstotal = sndbuf_getblkcnt(bs);
1309 a->fragsize = sndbuf_getblksz(bs);
1316 case SNDCTL_DSP_GETOSPACE:
1317 /* return space available in the output queue */
1319 audio_buf_info *a = (audio_buf_info *)arg;
1321 struct snd_dbuf *bs = wrch->bufsoft;
1324 /* XXX abusive DMA update: chn_wrupdate(wrch); */
1325 a->bytes = sndbuf_getfree(bs);
1326 a->fragments = a->bytes / sndbuf_getblksz(bs);
1327 a->fragstotal = sndbuf_getblkcnt(bs);
1328 a->fragsize = sndbuf_getblksz(bs);
1335 case SNDCTL_DSP_GETIPTR:
1337 count_info *a = (count_info *)arg;
1339 struct snd_dbuf *bs = rdch->bufsoft;
1342 /* XXX abusive DMA update: chn_rdupdate(rdch); */
1343 a->bytes = sndbuf_gettotal(bs);
1344 a->blocks = sndbuf_getblocks(bs) - rdch->blocks;
1345 a->ptr = sndbuf_getreadyptr(bs);
1346 rdch->blocks = sndbuf_getblocks(bs);
1353 case SNDCTL_DSP_GETOPTR:
1355 count_info *a = (count_info *)arg;
1357 struct snd_dbuf *bs = wrch->bufsoft;
1360 /* XXX abusive DMA update: chn_wrupdate(wrch); */
1361 a->bytes = sndbuf_gettotal(bs);
1362 a->blocks = sndbuf_getblocks(bs) - wrch->blocks;
1363 a->ptr = sndbuf_getreadyptr(bs);
1364 wrch->blocks = sndbuf_getblocks(bs);
1371 case SNDCTL_DSP_GETCAPS:
1373 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
1374 if (rdch && wrch && !(dsp_get_flags(i_dev) & SD_F_SIMPLEX))
1375 *arg_i |= DSP_CAP_DUPLEX;
1379 case SOUND_PCM_READ_BITS:
1380 chn = wrch ? wrch : rdch;
1383 if (chn->format & AFMT_8BIT)
1385 else if (chn->format & AFMT_16BIT)
1387 else if (chn->format & AFMT_24BIT)
1389 else if (chn->format & AFMT_32BIT)
1400 case SNDCTL_DSP_SETTRIGGER:
1403 rdch->flags &= ~CHN_F_NOTRIGGER;
1404 if (*arg_i & PCM_ENABLE_INPUT)
1409 rdch->flags |= CHN_F_NOTRIGGER;
1415 wrch->flags &= ~CHN_F_NOTRIGGER;
1416 if (*arg_i & PCM_ENABLE_OUTPUT)
1421 wrch->flags |= CHN_F_NOTRIGGER;
1427 case SNDCTL_DSP_GETTRIGGER:
1431 if (wrch->flags & CHN_F_TRIGGERED)
1432 *arg_i |= PCM_ENABLE_OUTPUT;
1437 if (rdch->flags & CHN_F_TRIGGERED)
1438 *arg_i |= PCM_ENABLE_INPUT;
1443 case SNDCTL_DSP_GETODELAY:
1445 struct snd_dbuf *bs = wrch->bufsoft;
1448 /* XXX abusive DMA update: chn_wrupdate(wrch); */
1449 *arg_i = sndbuf_getready(bs);
1455 case SNDCTL_DSP_POST:
1458 wrch->flags &= ~CHN_F_NOTRIGGER;
1464 case SNDCTL_DSP_SETDUPLEX:
1466 * switch to full-duplex mode if card is in half-duplex
1467 * mode and is able to work in full-duplex mode
1470 if (rdch && wrch && (dsp_get_flags(i_dev) & SD_F_SIMPLEX))
1471 dsp_set_flags(i_dev, dsp_get_flags(i_dev)^SD_F_SIMPLEX);
1476 * The following four ioctls are simple wrappers around mixer_ioctl
1477 * with no further processing. xcmd is short for "translated
1480 case SNDCTL_DSP_GETRECVOL:
1482 xcmd = SOUND_MIXER_READ_RECLEV;
1484 case SNDCTL_DSP_SETRECVOL:
1486 xcmd = SOUND_MIXER_WRITE_RECLEV;
1488 case SNDCTL_DSP_GETPLAYVOL:
1490 xcmd = SOUND_MIXER_READ_PCM;
1492 case SNDCTL_DSP_SETPLAYVOL:
1494 xcmd = SOUND_MIXER_WRITE_PCM;
1496 if (d->mixer_dev != NULL) {
1497 PCM_ACQUIRE_QUICK(d);
1498 ret = mixer_ioctl_cmd(d->mixer_dev, xcmd, arg, -1, td,
1500 PCM_RELEASE_QUICK(d);
1505 case SNDCTL_DSP_GET_RECSRC_NAMES:
1506 case SNDCTL_DSP_GET_RECSRC:
1507 case SNDCTL_DSP_SET_RECSRC:
1508 if (d->mixer_dev != NULL) {
1509 PCM_ACQUIRE_QUICK(d);
1510 ret = mixer_ioctl_cmd(d->mixer_dev, cmd, arg, -1, td,
1512 PCM_RELEASE_QUICK(d);
1518 * The following 3 ioctls aren't very useful at the moment. For
1519 * now, only a single channel is associated with a cdev (/dev/dspN
1520 * instance), so there's only a single output routing to use (i.e.,
1521 * the wrch bound to this cdev).
1523 case SNDCTL_DSP_GET_PLAYTGT_NAMES:
1525 oss_mixer_enuminfo *ei;
1526 ei = (oss_mixer_enuminfo *)arg;
1529 ei->version = 0; /* static for now */
1530 ei->strindex[0] = 0;
1534 strlcpy(ei->strings, wrch->name,
1535 sizeof(ei->strings));
1538 ei->strings[0] = '\0';
1542 case SNDCTL_DSP_GET_PLAYTGT:
1543 case SNDCTL_DSP_SET_PLAYTGT: /* yes, they are the same for now */
1546 * OSSv4: "The value that was accepted by the device will
1547 * be returned back in the variable pointed by the
1556 case SNDCTL_DSP_SILENCE:
1558 * Flush the software (pre-feed) buffer, but try to minimize playback
1559 * interruption. (I.e., record unplayed samples with intent to
1560 * restore by SNDCTL_DSP_SKIP.) Intended for application "pause"
1566 struct snd_dbuf *bs;
1568 while (wrch->inprog != 0)
1569 cv_wait(&wrch->cv, wrch->lock);
1571 if ((bs->shadbuf != NULL) && (sndbuf_getready(bs) > 0)) {
1572 bs->sl = sndbuf_getready(bs);
1573 sndbuf_dispose(bs, bs->shadbuf, sndbuf_getready(bs));
1574 sndbuf_fillsilence(bs);
1581 case SNDCTL_DSP_SKIP:
1583 * OSSv4 docs: "This ioctl call discards all unplayed samples in the
1584 * playback buffer by moving the current write position immediately
1585 * before the point where the device is currently reading the samples."
1590 struct snd_dbuf *bs;
1592 while (wrch->inprog != 0)
1593 cv_wait(&wrch->cv, wrch->lock);
1595 if ((bs->shadbuf != NULL) && (bs->sl > 0)) {
1596 sndbuf_softreset(bs);
1597 sndbuf_acquire(bs, bs->shadbuf, bs->sl);
1605 case SNDCTL_DSP_CURRENT_OPTR:
1606 case SNDCTL_DSP_CURRENT_IPTR:
1608 * @note Changing formats resets the buffer counters, which differs
1609 * from the 4Front drivers. However, I don't expect this to be
1610 * much of a problem.
1612 * @note In a test where @c CURRENT_OPTR is called immediately after write
1613 * returns, this driver is about 32K samples behind whereas
1614 * 4Front's is about 8K samples behind. Should determine source
1615 * of discrepancy, even if only out of curiosity.
1617 * @todo Actually test SNDCTL_DSP_CURRENT_IPTR.
1619 chn = (cmd == SNDCTL_DSP_CURRENT_OPTR) ? wrch : rdch;
1623 struct snd_dbuf *bs;
1626 oss_count_t *oc = (oss_count_t *)arg;
1631 tmp = (sndbuf_getsize(b) + chn_getptr(chn) - sndbuf_gethwptr(b)) % sndbuf_getsize(b);
1632 oc->samples = (sndbuf_gettotal(b) + tmp) / sndbuf_getbps(b);
1633 oc->fifo_samples = (sndbuf_getready(b) - tmp) / sndbuf_getbps(b);
1635 oc->samples = sndbuf_gettotal(bs) / sndbuf_getbps(bs);
1636 oc->fifo_samples = sndbuf_getready(bs) / sndbuf_getbps(bs);
1642 case SNDCTL_DSP_HALT_OUTPUT:
1643 case SNDCTL_DSP_HALT_INPUT:
1644 chn = (cmd == SNDCTL_DSP_HALT_OUTPUT) ? wrch : rdch;
1654 case SNDCTL_DSP_LOW_WATER:
1656 * Set the number of bytes required to attract attention by
1661 wrch->lw = (*arg_i > 1) ? *arg_i : 1;
1666 rdch->lw = (*arg_i > 1) ? *arg_i : 1;
1671 case SNDCTL_DSP_GETERROR:
1673 * OSSv4 docs: "All errors and counters will automatically be
1674 * cleared to zeroes after the call so each call will return only
1675 * the errors that occurred after the previous invocation. ... The
1676 * play_underruns and rec_overrun fields are the only usefull fields
1677 * returned by OSS 4.0."
1680 audio_errinfo *ei = (audio_errinfo *)arg;
1682 bzero((void *)ei, sizeof(*ei));
1686 ei->play_underruns = wrch->xruns;
1692 ei->rec_overruns = rdch->xruns;
1699 case SNDCTL_DSP_SYNCGROUP:
1700 PCM_ACQUIRE_QUICK(d);
1701 ret = dsp_oss_syncgroup(wrch, rdch, (oss_syncgroup *)arg);
1702 PCM_RELEASE_QUICK(d);
1705 case SNDCTL_DSP_SYNCSTART:
1706 PCM_ACQUIRE_QUICK(d);
1707 ret = dsp_oss_syncstart(*arg_i);
1708 PCM_RELEASE_QUICK(d);
1711 case SNDCTL_DSP_POLICY:
1712 PCM_ACQUIRE_QUICK(d);
1713 ret = dsp_oss_policy(wrch, rdch, *arg_i);
1714 PCM_RELEASE_QUICK(d);
1717 #ifdef OSSV4_EXPERIMENT
1719 * XXX The following ioctls are not yet supported and just return
1722 case SNDCTL_DSP_GETOPEAKS:
1723 case SNDCTL_DSP_GETIPEAKS:
1724 chn = (cmd == SNDCTL_DSP_GETOPEAKS) ? wrch : rdch;
1728 oss_peaks_t *op = (oss_peaks_t *)arg;
1732 ret = chn_getpeaks(chn, &lpeak, &rpeak);
1744 * XXX Once implemented, revisit this for proper cv protection
1747 case SNDCTL_DSP_COOKEDMODE:
1748 ret = dsp_oss_cookedmode(wrch, rdch, *arg_i);
1750 case SNDCTL_DSP_GET_CHNORDER:
1751 ret = dsp_oss_getchnorder(wrch, rdch, (unsigned long long *)arg);
1753 case SNDCTL_DSP_SET_CHNORDER:
1754 ret = dsp_oss_setchnorder(wrch, rdch, (unsigned long long *)arg);
1756 case SNDCTL_GETLABEL:
1757 ret = dsp_oss_getlabel(wrch, rdch, (oss_label_t *)arg);
1759 case SNDCTL_SETLABEL:
1760 ret = dsp_oss_setlabel(wrch, rdch, (oss_label_t *)arg);
1762 case SNDCTL_GETSONG:
1763 ret = dsp_oss_getsong(wrch, rdch, (oss_longname_t *)arg);
1765 case SNDCTL_SETSONG:
1766 ret = dsp_oss_setsong(wrch, rdch, (oss_longname_t *)arg);
1768 case SNDCTL_SETNAME:
1769 ret = dsp_oss_setname(wrch, rdch, (oss_longname_t *)arg);
1773 * @note The SNDCTL_CARDINFO ioctl was omitted per 4Front developer
1774 * documentation. "The usability of this call is very limited. It's
1775 * provided only for completeness of the API. OSS API doesn't have
1776 * any concept of card. Any information returned by this ioctl calld
1777 * is reserved exclusively for the utility programs included in the
1778 * OSS package. Applications should not try to use for this
1779 * information in any ways."
1781 case SNDCTL_CARDINFO:
1785 * @note The S/PDIF interface ioctls, @c SNDCTL_DSP_READCTL and
1786 * @c SNDCTL_DSP_WRITECTL have been omitted at the suggestion of
1787 * 4Front Technologies.
1789 case SNDCTL_DSP_READCTL:
1790 case SNDCTL_DSP_WRITECTL:
1793 #endif /* !0 (explicitly omitted ioctls) */
1795 #endif /* !OSSV4_EXPERIMENT */
1796 case SNDCTL_DSP_MAPINBUF:
1797 case SNDCTL_DSP_MAPOUTBUF:
1798 case SNDCTL_DSP_SETSYNCRO:
1801 case SNDCTL_DSP_SUBDIVIDE:
1802 case SOUND_PCM_WRITE_FILTER:
1803 case SOUND_PCM_READ_FILTER:
1804 /* dunno what these do, don't sound important */
1807 DEB(printf("default ioctl fn 0x%08lx fail\n", cmd));
1812 relchns(i_dev, rdch, wrch, 0);
1820 dsp_poll(struct cdev *i_dev, int events, struct thread *td)
1822 struct snddev_info *d;
1823 struct pcm_channel *wrch, *rdch;
1826 d = dsp_get_info(i_dev);
1827 if (!DSP_REGISTERED(d, i_dev))
1836 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1838 if (wrch != NULL && !(wrch->flags & CHN_F_DEAD)) {
1839 e = (events & (POLLOUT | POLLWRNORM));
1841 ret |= chn_poll(wrch, e, td);
1844 if (rdch != NULL && !(rdch->flags & CHN_F_DEAD)) {
1845 e = (events & (POLLIN | POLLRDNORM));
1847 ret |= chn_poll(rdch, e, td);
1850 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1858 dsp_mmap(struct cdev *i_dev, vm_offset_t offset, vm_paddr_t *paddr, int nprot)
1860 struct snddev_info *d;
1861 struct pcm_channel *wrch, *rdch, *c;
1864 * Reject PROT_EXEC by default. It just doesn't makes sense.
1865 * Unfortunately, we have to give up this one due to linux_mmap
1868 * http://lists.freebsd.org/pipermail/freebsd-emulation/2007-June/003698.html
1871 if ((nprot & PROT_EXEC) && dsp_mmap_allow_prot_exec == 0)
1874 d = dsp_get_info(i_dev);
1875 if (!DSP_REGISTERED(d, i_dev))
1880 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1883 * XXX The linux api uses the nprot to select read/write buffer
1884 * our vm system doesn't allow this, so force write buffer.
1886 * This is just a quack to fool full-duplex mmap, so that at
1887 * least playback _or_ recording works. If you really got the
1888 * urge to make _both_ work at the same time, avoid O_RDWR.
1889 * Just open each direction separately and mmap() it.
1891 * Failure is not an option due to INVARIANTS check within
1892 * device_pager.c, which means, we have to give up one over
1895 c = (wrch != NULL) ? wrch : rdch;
1897 if (c == NULL || (c->flags & CHN_F_MMAP_INVALID) ||
1898 offset >= sndbuf_getsize(c->bufsoft) ||
1899 (wrch != NULL && (wrch->flags & CHN_F_MMAP_INVALID)) ||
1900 (rdch != NULL && (rdch->flags & CHN_F_MMAP_INVALID))) {
1901 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1906 /* XXX full-duplex quack. */
1908 wrch->flags |= CHN_F_MAPPED;
1910 rdch->flags |= CHN_F_MAPPED;
1912 *paddr = vtophys(sndbuf_getbufofs(c->bufsoft, offset));
1913 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1922 /* So much for dev_stdclone() */
1924 dsp_stdclone(char *name, char *namep, char *sep, int use_sep, int *u, int *c)
1928 len = strlen(namep);
1930 if (bcmp(name, namep, len) != 0)
1935 if (isdigit(*name) == 0)
1940 if (*name == '0' && !(name[1] == '\0' || bcmp(name + 1, sep, len) == 0))
1943 for (*u = 0; isdigit(*name) != 0; name++) {
1951 return ((use_sep == 0) ? 0 : ENODEV);
1953 if (bcmp(name, sep, len) != 0 || isdigit(name[len]) == 0)
1958 if (*name == '0' && name[1] != '\0')
1961 for (*c = 0; isdigit(*name) != 0; name++) {
1975 dsp_clone(void *arg,
1976 #if __FreeBSD_version >= 600034
1979 char *name, int namelen, struct cdev **dev)
1981 struct snddev_info *d;
1982 struct snd_clone_entry *ce;
1983 struct pcm_channel *c;
1984 int i, unit, udcmask, cunit, devtype, devhw, devcmax, tumax;
1985 char *devname, *devsep;
1987 KASSERT(dsp_umax >= 0 && dsp_cmax >= 0, ("Uninitialized unit!"));
2001 for (i = 0; unit == -1 &&
2002 i < (sizeof(dsp_cdevs) / sizeof(dsp_cdevs[0])); i++) {
2003 devtype = dsp_cdevs[i].type;
2004 devname = dsp_cdevs[i].name;
2005 devsep = dsp_cdevs[i].sep;
2006 devhw = dsp_cdevs[i].hw;
2007 devcmax = dsp_cdevs[i].max - 1;
2008 if (strcmp(name, devname) == 0)
2010 else if (dsp_stdclone(name, devname, devsep,
2011 dsp_cdevs[i].use_sep, &unit, &cunit) != 0) {
2017 d = devclass_get_softc(pcm_devclass, unit);
2018 if (!PCM_REGISTERED(d) || d->clones == NULL)
2021 /* XXX Need Giant magic entry ??? */
2024 if (snd_clone_disabled(d->clones)) {
2033 udcmask = snd_u2unit(unit) | snd_d2unit(devtype);
2036 KASSERT(devcmax <= dsp_cmax,
2037 ("overflow: devcmax=%d, dsp_cmax=%d", devcmax, dsp_cmax));
2038 if (cunit > devcmax) {
2039 PCM_RELEASE_QUICK(d);
2042 udcmask |= snd_c2unit(cunit);
2043 CHN_FOREACH(c, d, channels.pcm) {
2045 if (c->unit != udcmask) {
2050 udcmask &= ~snd_c2unit(cunit);
2052 * Temporarily increase clone maxunit to overcome
2053 * vchan flexibility.
2055 * # sysctl dev.pcm.0.play.vchans=256
2056 * dev.pcm.0.play.vchans: 1 -> 256
2057 * # cat /dev/zero > /dev/dsp0.vp255 &
2059 * # sysctl dev.pcm.0.play.vchans=0
2060 * dev.pcm.0.play.vchans: 256 -> 1
2062 * [1] + running cat /dev/zero > /dev/dsp0.vp255
2064 * # cat /dev/zero > /dev/dsp0.vp255
2065 * zsh: operation not supported: /dev/dsp0.vp255
2067 tumax = snd_clone_getmaxunit(d->clones);
2069 snd_clone_setmaxunit(d->clones, cunit);
2072 goto dsp_clone_alloc;
2075 * Ok, so we're requesting unallocated vchan, but still
2076 * within maximum vchan limit.
2078 if (((devtype == SND_DEV_DSPHW_VPLAY && d->pvchancount > 0) ||
2079 (devtype == SND_DEV_DSPHW_VREC && d->rvchancount > 0)) &&
2080 cunit < snd_maxautovchans) {
2081 udcmask &= ~snd_c2unit(cunit);
2082 tumax = snd_clone_getmaxunit(d->clones);
2084 snd_clone_setmaxunit(d->clones, cunit);
2087 goto dsp_clone_alloc;
2089 PCM_RELEASE_QUICK(d);
2094 ce = snd_clone_alloc(d->clones, dev, &cunit, udcmask);
2096 snd_clone_setmaxunit(d->clones, tumax);
2098 udcmask |= snd_c2unit(cunit);
2099 *dev = make_dev(&dsp_cdevsw, udcmask,
2100 UID_ROOT, GID_WHEEL, 0666, "%s%d%s%d",
2101 devname, unit, devsep, cunit);
2102 snd_clone_register(ce, *dev);
2105 PCM_RELEASE_QUICK(d);
2112 dsp_sysinit(void *p)
2114 if (dsp_ehtag != NULL)
2116 /* initialize unit numbering */
2118 dsp_umax = PCMMAXUNIT;
2119 dsp_cmax = PCMMAXCHAN;
2120 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000);
2124 dsp_sysuninit(void *p)
2126 if (dsp_ehtag == NULL)
2128 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag);
2132 SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
2133 SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);
2137 dsp_unit2name(char *buf, size_t len, int unit)
2141 KASSERT(buf != NULL && len != 0,
2142 ("bogus buf=%p len=%ju", buf, (uintmax_t)len));
2144 dtype = snd_unit2d(unit);
2146 for (i = 0; i < (sizeof(dsp_cdevs) / sizeof(dsp_cdevs[0])); i++) {
2147 if (dtype != dsp_cdevs[i].type)
2149 snprintf(buf, len, "%s%d%s%d", dsp_cdevs[i].name,
2150 snd_unit2u(unit), dsp_cdevs[i].sep, snd_unit2c(unit));
2158 * @brief Handler for SNDCTL_AUDIOINFO.
2160 * Gathers information about the audio device specified in ai->dev. If
2161 * ai->dev == -1, then this function gathers information about the current
2162 * device. If the call comes in on a non-audio device and ai->dev == -1,
2165 * This routine is supposed to go practically straight to the hardware,
2166 * getting capabilities directly from the sound card driver, side-stepping
2167 * the intermediate channel interface.
2169 * Note, however, that the usefulness of this command is significantly
2170 * decreased when requesting info about any device other than the one serving
2171 * the request. While each snddev_channel refers to a specific device node,
2172 * the converse is *not* true. Currently, when a sound device node is opened,
2173 * the sound subsystem scans for an available audio channel (or channels, if
2174 * opened in read+write) and then assigns them to the si_drv[12] private
2175 * data fields. As a result, any information returned linking a channel to
2176 * a specific character device isn't necessarily accurate.
2179 * Calling threads must not hold any snddev_info or pcm_channel locks.
2181 * @param dev device on which the ioctl was issued
2182 * @param ai ioctl request data container
2185 * @retval EINVAL ai->dev specifies an invalid device
2187 * @todo Verify correctness of Doxygen tags. ;)
2190 dsp_oss_audioinfo(struct cdev *i_dev, oss_audioinfo *ai)
2192 struct pcmchan_caps *caps;
2193 struct pcm_channel *ch;
2194 struct snddev_info *d;
2196 int i, nchan, *rates, minch, maxch;
2197 char *devname, buf[CHN_NAMELEN];
2200 * If probing the device that received the ioctl, make sure it's a
2201 * DSP device. (Users may use this ioctl with /dev/mixer and
2204 if (ai->dev == -1 && i_dev->si_devsw != &dsp_cdevsw)
2210 bzero(buf, sizeof(buf));
2213 * Search for the requested audio device (channel). Start by
2214 * iterating over pcm devices.
2216 for (i = 0; pcm_devclass != NULL &&
2217 i < devclass_get_maxunit(pcm_devclass); i++) {
2218 d = devclass_get_softc(pcm_devclass, i);
2219 if (!PCM_REGISTERED(d))
2222 /* XXX Need Giant magic entry ??? */
2224 /* See the note in function docblock */
2225 mtx_assert(d->lock, MA_NOTOWNED);
2228 CHN_FOREACH(ch, d, channels.pcm) {
2229 mtx_assert(ch->lock, MA_NOTOWNED);
2231 if (ai->dev == -1) {
2232 if (DSP_REGISTERED(d, i_dev) &&
2233 (ch == PCM_RDCH(i_dev) || /* record ch */
2234 ch == PCM_WRCH(i_dev))) { /* playback ch */
2235 devname = dsp_unit2name(buf,
2236 sizeof(buf), ch->unit);
2238 } else if (ai->dev == nchan) {
2239 devname = dsp_unit2name(buf, sizeof(buf),
2242 if (devname != NULL)
2248 if (devname != NULL) {
2250 * At this point, the following synchronization stuff
2252 * - a specific PCM device is locked.
2253 * - a specific audio channel has been locked, so be
2254 * sure to unlock when exiting;
2257 caps = chn_getcaps(ch);
2260 * With all handles collected, zero out the user's
2261 * container and begin filling in its fields.
2263 bzero((void *)ai, sizeof(oss_audioinfo));
2266 strlcpy(ai->name, ch->name, sizeof(ai->name));
2268 if ((ch->flags & CHN_F_BUSY) == 0)
2271 ai->busy = (ch->direction == PCMDIR_PLAY) ? OPEN_WRITE : OPEN_READ;
2275 * @c cmd - OSSv4 docs: "Only supported under Linux at
2276 * this moment." Cop-out, I know, but I'll save
2277 * running around in the process table for later.
2278 * Is there a risk of leaking information?
2283 * These flags stolen from SNDCTL_DSP_GETCAPS handler.
2284 * Note, however, that a single channel operates in
2285 * only one direction, so DSP_CAP_DUPLEX is out.
2288 * @todo @c SNDCTL_AUDIOINFO::caps - Make drivers keep
2289 * these in pcmchan::caps?
2291 ai->caps = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
2294 * Collect formats supported @b natively by the
2295 * device. Also determine min/max channels. (I.e.,
2296 * mono, stereo, or both?)
2298 * If any channel is stereo, maxch = 2;
2299 * if all channels are stereo, minch = 2, too;
2300 * if any channel is mono, minch = 1;
2301 * and if all channels are mono, maxch = 1.
2306 for (i = 0; caps->fmtlist[i]; i++) {
2307 fmts |= caps->fmtlist[i];
2308 if (caps->fmtlist[i] & AFMT_STEREO) {
2309 minch = (minch == 0) ? 2 : minch;
2313 maxch = (maxch == 0) ? 1 : maxch;
2317 if (ch->direction == PCMDIR_PLAY)
2318 ai->oformats = fmts;
2320 ai->iformats = fmts;
2324 * @c magic - OSSv4 docs: "Reserved for internal use
2328 * @c card_number - OSSv4 docs: "Number of the sound
2329 * card where this device belongs or -1 if this
2330 * information is not available. Applications
2331 * should normally not use this field for any
2334 ai->card_number = -1;
2336 * @todo @c song_name - depends first on
2337 * SNDCTL_[GS]ETSONG @todo @c label - depends
2338 * on SNDCTL_[GS]ETLABEL
2339 * @todo @c port_number - routing information?
2341 ai->port_number = -1;
2342 ai->mixer_dev = (d->mixer_dev != NULL) ? PCMUNIT(d->mixer_dev) : -1;
2345 * @c real_device - OSSv4 docs: "Obsolete."
2347 ai->real_device = -1;
2348 strlcpy(ai->devnode, devname, sizeof(ai->devnode));
2349 ai->enabled = device_is_attached(d->dev) ? 1 : 0;
2352 * @c flags - OSSv4 docs: "Reserved for future use."
2355 * @c binding - OSSv4 docs: "Reserved for future use."
2357 * @todo @c handle - haven't decided how to generate
2358 * this yet; bus, vendor, device IDs?
2360 ai->min_rate = caps->minspeed;
2361 ai->max_rate = caps->maxspeed;
2363 ai->min_channels = minch;
2364 ai->max_channels = maxch;
2366 ai->nrates = chn_getrates(ch, &rates);
2367 if (ai->nrates > OSS_MAX_SAMPLE_RATES)
2368 ai->nrates = OSS_MAX_SAMPLE_RATES;
2370 for (i = 0; i < ai->nrates; i++)
2371 ai->rates[i] = rates[i];
2378 if (devname != NULL)
2382 /* Exhausted the search -- nothing is locked, so return. */
2387 * @brief Assigns a PCM channel to a sync group.
2389 * Sync groups are used to enable audio operations on multiple devices
2390 * simultaneously. They may be used with any number of devices and may
2391 * span across applications. Devices are added to groups with
2392 * the SNDCTL_DSP_SYNCGROUP ioctl, and operations are triggered with the
2393 * SNDCTL_DSP_SYNCSTART ioctl.
2395 * If the @c id field of the @c group parameter is set to zero, then a new
2396 * sync group is created. Otherwise, wrch and rdch (if set) are added to
2397 * the group specified.
2399 * @todo As far as memory allocation, should we assume that things are
2400 * okay and allocate with M_WAITOK before acquiring channel locks,
2401 * freeing later if not?
2403 * @param wrch output channel associated w/ device (if any)
2404 * @param rdch input channel associated w/ device (if any)
2405 * @param group Sync group parameters
2408 * @retval non-zero error to be propagated upstream
2411 dsp_oss_syncgroup(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_syncgroup *group)
2413 struct pcmchan_syncmember *smrd, *smwr;
2414 struct pcmchan_syncgroup *sg;
2423 * Free_unr() may sleep, so store released syncgroup IDs until after
2424 * all locks are released.
2426 sg_ids[0] = sg_ids[1] = sg_ids[2] = 0;
2431 * - Insert channel(s) into group's member list.
2432 * - Set CHN_F_NOTRIGGER on channel(s).
2433 * - Stop channel(s).
2437 * If device's channels are already mapped to a group, unmap them.
2441 sg_ids[0] = chn_syncdestroy(wrch);
2446 sg_ids[1] = chn_syncdestroy(rdch);
2450 * Verify that mode matches character device properites.
2451 * - Bail if PCM_ENABLE_OUTPUT && wrch == NULL.
2452 * - Bail if PCM_ENABLE_INPUT && rdch == NULL.
2454 if (((wrch == NULL) && (group->mode & PCM_ENABLE_OUTPUT)) ||
2455 ((rdch == NULL) && (group->mode & PCM_ENABLE_INPUT))) {
2461 * An id of zero indicates the user wants to create a new
2464 if (group->id == 0) {
2465 sg = (struct pcmchan_syncgroup *)malloc(sizeof(*sg), M_DEVBUF, M_NOWAIT);
2467 SLIST_INIT(&sg->members);
2468 sg->id = alloc_unr(pcmsg_unrhdr);
2471 SLIST_INSERT_HEAD(&snd_pcm_syncgroups, sg, link);
2475 SLIST_FOREACH(sg, &snd_pcm_syncgroups, link) {
2476 if (sg->id == group->id)
2483 /* Couldn't create or find a syncgroup. Fail. */
2488 * Allocate a syncmember, assign it and a channel together, and
2489 * insert into syncgroup.
2491 if (group->mode & PCM_ENABLE_INPUT) {
2492 smrd = (struct pcmchan_syncmember *)malloc(sizeof(*smrd), M_DEVBUF, M_NOWAIT);
2498 SLIST_INSERT_HEAD(&sg->members, smrd, link);
2503 rdch->flags |= CHN_F_NOTRIGGER;
2507 if (group->mode & PCM_ENABLE_OUTPUT) {
2508 smwr = (struct pcmchan_syncmember *)malloc(sizeof(*smwr), M_DEVBUF, M_NOWAIT);
2514 SLIST_INSERT_HEAD(&sg->members, smwr, link);
2519 wrch->flags |= CHN_F_NOTRIGGER;
2527 free(smrd, M_DEVBUF);
2528 if ((sg != NULL) && SLIST_EMPTY(&sg->members)) {
2530 SLIST_REMOVE(&snd_pcm_syncgroups, sg, pcmchan_syncgroup, link);
2548 free_unr(pcmsg_unrhdr, sg_ids[0]);
2550 free_unr(pcmsg_unrhdr, sg_ids[1]);
2552 free_unr(pcmsg_unrhdr, sg_ids[2]);
2558 * @brief Launch a sync group into action
2560 * Sync groups are established via SNDCTL_DSP_SYNCGROUP. This function
2561 * iterates over all members, triggering them along the way.
2563 * @note Caller must not hold any channel locks.
2565 * @param sg_id sync group identifier
2568 * @retval non-zero error worthy of propagating upstream to user
2571 dsp_oss_syncstart(int sg_id)
2573 struct pcmchan_syncmember *sm, *sm_tmp;
2574 struct pcmchan_syncgroup *sg;
2575 struct pcm_channel *c;
2578 /* Get the synclists lock */
2585 /* Search for syncgroup by ID */
2586 SLIST_FOREACH(sg, &snd_pcm_syncgroups, link) {
2587 if (sg->id == sg_id)
2591 /* Return EINVAL if not found */
2597 /* Any removals resulting in an empty group should've handled this */
2598 KASSERT(!SLIST_EMPTY(&sg->members), ("found empty syncgroup"));
2601 * Attempt to lock all member channels - if any are already
2602 * locked, unlock those acquired, sleep for a bit, and try
2605 SLIST_FOREACH(sm, &sg->members, link) {
2606 if (CHN_TRYLOCK(sm->ch) == 0) {
2607 int timo = hz * 5/1000;
2611 /* Release all locked channels so far, retry */
2612 SLIST_FOREACH(sm_tmp, &sg->members, link) {
2613 /* sm is the member already locked */
2616 CHN_UNLOCK(sm_tmp->ch);
2619 /** @todo Is PRIBIO correct/ */
2620 ret = msleep(sm, &snd_pcm_syncgroups_mtx,
2621 PRIBIO | PCATCH, "pcmsg", timo);
2622 if (ret == EINTR || ret == ERESTART)
2626 ret = 0; /* Assumes ret == EAGAIN... */
2629 } while (needlocks && ret == 0);
2631 /* Proceed only if no errors encountered. */
2633 /* Launch channels */
2634 while((sm = SLIST_FIRST(&sg->members)) != NULL) {
2635 SLIST_REMOVE_HEAD(&sg->members, link);
2640 c->flags &= ~CHN_F_NOTRIGGER;
2646 SLIST_REMOVE(&snd_pcm_syncgroups, sg, pcmchan_syncgroup, link);
2653 * Free_unr() may sleep, so be sure to give up the syncgroup lock
2657 free_unr(pcmsg_unrhdr, sg_id);
2663 * @brief Handler for SNDCTL_DSP_POLICY
2665 * The SNDCTL_DSP_POLICY ioctl is a simpler interface to control fragment
2666 * size and count like with SNDCTL_DSP_SETFRAGMENT. Instead of the user
2667 * specifying those two parameters, s/he simply selects a number from 0..10
2668 * which corresponds to a buffer size. Smaller numbers request smaller
2669 * buffers with lower latencies (at greater overhead from more frequent
2670 * interrupts), while greater numbers behave in the opposite manner.
2672 * The 4Front spec states that a value of 5 should be the default. However,
2673 * this implementation deviates slightly by using a linear scale without
2674 * consulting drivers. I.e., even though drivers may have different default
2675 * buffer sizes, a policy argument of 5 will have the same result across
2678 * See http://manuals.opensound.com/developer/SNDCTL_DSP_POLICY.html for
2681 * @todo When SNDCTL_DSP_COOKEDMODE is supported, it'll be necessary to
2682 * work with hardware drivers directly.
2684 * @note PCM channel arguments must not be locked by caller.
2686 * @param wrch Pointer to opened playback channel (optional; may be NULL)
2687 * @param rdch " recording channel (optional; may be NULL)
2688 * @param policy Integer from [0:10]
2690 * @retval 0 constant (for now)
2693 dsp_oss_policy(struct pcm_channel *wrch, struct pcm_channel *rdch, int policy)
2697 if (policy < CHN_POLICY_MIN || policy > CHN_POLICY_MAX)
2700 /* Default: success */
2705 ret = chn_setlatency(rdch, policy);
2709 if (wrch && ret == 0) {
2711 ret = chn_setlatency(wrch, policy);
2721 #ifdef OSSV4_EXPERIMENT
2723 * @brief Enable or disable "cooked" mode
2725 * This is a handler for @c SNDCTL_DSP_COOKEDMODE. When in cooked mode, which
2726 * is the default, the sound system handles rate and format conversions
2727 * automatically (ex: user writing 11025Hz/8 bit/unsigned but card only
2728 * operates with 44100Hz/16bit/signed samples).
2730 * Disabling cooked mode is intended for applications wanting to mmap()
2731 * a sound card's buffer space directly, bypassing the FreeBSD 2-stage
2732 * feeder architecture, presumably to gain as much control over audio
2733 * hardware as possible.
2735 * See @c http://manuals.opensound.com/developer/SNDCTL_DSP_COOKEDMODE.html
2738 * @note Currently, this function is just a stub that always returns EINVAL.
2740 * @todo Figure out how to and actually implement this.
2742 * @param wrch playback channel (optional; may be NULL)
2743 * @param rdch recording channel (optional; may be NULL)
2744 * @param enabled 0 = raw mode, 1 = cooked mode
2746 * @retval EINVAL Operation not yet supported.
2749 dsp_oss_cookedmode(struct pcm_channel *wrch, struct pcm_channel *rdch, int enabled)
2755 * @brief Retrieve channel interleaving order
2757 * This is the handler for @c SNDCTL_DSP_GET_CHNORDER.
2759 * See @c http://manuals.opensound.com/developer/SNDCTL_DSP_GET_CHNORDER.html
2762 * @note As the ioctl definition is still under construction, FreeBSD
2763 * does not currently support SNDCTL_DSP_GET_CHNORDER.
2765 * @param wrch playback channel (optional; may be NULL)
2766 * @param rdch recording channel (optional; may be NULL)
2767 * @param map channel map (result will be stored there)
2769 * @retval EINVAL Operation not yet supported.
2772 dsp_oss_getchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map)
2778 * @brief Specify channel interleaving order
2780 * This is the handler for @c SNDCTL_DSP_SET_CHNORDER.
2782 * @note As the ioctl definition is still under construction, FreeBSD
2783 * does not currently support @c SNDCTL_DSP_SET_CHNORDER.
2785 * @param wrch playback channel (optional; may be NULL)
2786 * @param rdch recording channel (optional; may be NULL)
2787 * @param map channel map
2789 * @retval EINVAL Operation not yet supported.
2792 dsp_oss_setchnorder(struct pcm_channel *wrch, struct pcm_channel *rdch, unsigned long long *map)
2798 * @brief Retrieve an audio device's label
2800 * This is a handler for the @c SNDCTL_GETLABEL ioctl.
2802 * See @c http://manuals.opensound.com/developer/SNDCTL_GETLABEL.html
2805 * From Hannu@4Front: "For example ossxmix (just like some HW mixer
2806 * consoles) can show variable "labels" for certain controls. By default
2807 * the application name (say quake) is shown as the label but
2808 * applications may change the labels themselves."
2810 * @note As the ioctl definition is still under construction, FreeBSD
2811 * does not currently support @c SNDCTL_GETLABEL.
2813 * @param wrch playback channel (optional; may be NULL)
2814 * @param rdch recording channel (optional; may be NULL)
2815 * @param label label gets copied here
2817 * @retval EINVAL Operation not yet supported.
2820 dsp_oss_getlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label)
2826 * @brief Specify an audio device's label
2828 * This is a handler for the @c SNDCTL_SETLABEL ioctl. Please see the
2829 * comments for @c dsp_oss_getlabel immediately above.
2831 * See @c http://manuals.opensound.com/developer/SNDCTL_GETLABEL.html
2834 * @note As the ioctl definition is still under construction, FreeBSD
2835 * does not currently support SNDCTL_SETLABEL.
2837 * @param wrch playback channel (optional; may be NULL)
2838 * @param rdch recording channel (optional; may be NULL)
2839 * @param label label gets copied from here
2841 * @retval EINVAL Operation not yet supported.
2844 dsp_oss_setlabel(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_label_t *label)
2850 * @brief Retrieve name of currently played song
2852 * This is a handler for the @c SNDCTL_GETSONG ioctl. Audio players could
2853 * tell the system the name of the currently playing song, which would be
2854 * visible in @c /dev/sndstat.
2856 * See @c http://manuals.opensound.com/developer/SNDCTL_GETSONG.html
2859 * @note As the ioctl definition is still under construction, FreeBSD
2860 * does not currently support SNDCTL_GETSONG.
2862 * @param wrch playback channel (optional; may be NULL)
2863 * @param rdch recording channel (optional; may be NULL)
2864 * @param song song name gets copied here
2866 * @retval EINVAL Operation not yet supported.
2869 dsp_oss_getsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song)
2875 * @brief Retrieve name of currently played song
2877 * This is a handler for the @c SNDCTL_SETSONG ioctl. Audio players could
2878 * tell the system the name of the currently playing song, which would be
2879 * visible in @c /dev/sndstat.
2881 * See @c http://manuals.opensound.com/developer/SNDCTL_SETSONG.html
2884 * @note As the ioctl definition is still under construction, FreeBSD
2885 * does not currently support SNDCTL_SETSONG.
2887 * @param wrch playback channel (optional; may be NULL)
2888 * @param rdch recording channel (optional; may be NULL)
2889 * @param song song name gets copied from here
2891 * @retval EINVAL Operation not yet supported.
2894 dsp_oss_setsong(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *song)
2900 * @brief Rename a device
2902 * This is a handler for the @c SNDCTL_SETNAME ioctl.
2904 * See @c http://manuals.opensound.com/developer/SNDCTL_SETNAME.html for
2907 * From Hannu@4Front: "This call is used to change the device name
2908 * reported in /dev/sndstat and ossinfo. So instead of using some generic
2909 * 'OSS loopback audio (MIDI) driver' the device may be given a meaningfull
2910 * name depending on the current context (for example 'OSS virtual wave table
2911 * synth' or 'VoIP link to London')."
2913 * @note As the ioctl definition is still under construction, FreeBSD
2914 * does not currently support SNDCTL_SETNAME.
2916 * @param wrch playback channel (optional; may be NULL)
2917 * @param rdch recording channel (optional; may be NULL)
2918 * @param name new device name gets copied from here
2920 * @retval EINVAL Operation not yet supported.
2923 dsp_oss_setname(struct pcm_channel *wrch, struct pcm_channel *rdch, oss_longname_t *name)
2927 #endif /* !OSSV4_EXPERIMENT */