2 * Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
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
26 * $FreeBSD: src/sys/dev/sound/pcm/dsp.c,v 1.15.2.13 2002/08/30 13:53:03 orion Exp $
27 * $DragonFly: src/sys/dev/sound/pcm/dsp.c,v 1.7 2004/05/21 01:14:27 dillon Exp $
30 #include <sys/param.h>
31 #include <sys/queue.h>
33 #include <dev/sound/pcm/sound.h>
35 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/dsp.c,v 1.7 2004/05/21 01:14:27 dillon Exp $");
39 static d_open_t dsp_open;
40 static d_close_t dsp_close;
41 static d_read_t dsp_read;
42 static d_write_t dsp_write;
43 static d_ioctl_t dsp_ioctl;
44 static d_poll_t dsp_poll;
45 static d_mmap_t dsp_mmap;
47 static struct cdevsw dsp_cdevsw = {
49 /* maj */ SND_CDEV_MAJOR,
55 /* close */ dsp_close,
57 /* write */ dsp_write,
58 /* ioctl */ dsp_ioctl,
61 /* strategy */ nostrategy,
67 static eventhandler_tag dsp_ehtag;
70 static struct snddev_info *
71 dsp_get_info(dev_t dev)
73 struct snddev_info *d;
77 if (unit >= devclass_get_maxunit(pcm_devclass))
79 d = devclass_get_softc(pcm_devclass, unit);
85 dsp_get_flags(dev_t dev)
91 if (unit >= devclass_get_maxunit(pcm_devclass))
93 bdev = devclass_get_device(pcm_devclass, unit);
95 return pcm_getflags(bdev);
99 dsp_set_flags(dev_t dev, u_int32_t flags)
105 if (unit >= devclass_get_maxunit(pcm_devclass))
107 bdev = devclass_get_device(pcm_devclass, unit);
109 pcm_setflags(bdev, flags);
113 * return the channels channels associated with an open device instance.
114 * set the priority if the device is simplex and one direction (only) is
116 * lock channels specified.
119 getchns(dev_t dev, struct pcm_channel **rdch, struct pcm_channel **wrch, u_int32_t prio)
121 struct snddev_info *d;
124 flags = dsp_get_flags(dev);
125 d = dsp_get_info(dev);
128 KASSERT((flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
129 ("getchns: read and write both prioritised"));
131 if ((flags & SD_F_PRIO_SET) == 0 && (prio != (SD_F_PRIO_RD | SD_F_PRIO_WR))) {
132 flags |= prio & (SD_F_PRIO_RD | SD_F_PRIO_WR);
133 dsp_set_flags(dev, flags);
136 *rdch = dev->si_drv1;
137 *wrch = dev->si_drv2;
138 if ((flags & SD_F_SIMPLEX) && (flags & SD_F_PRIO_SET)) {
140 if (*rdch && flags & SD_F_PRIO_WR) {
142 *rdch = pcm_getfakechan(d);
143 } else if (*wrch && flags & SD_F_PRIO_RD) {
145 *wrch = pcm_getfakechan(d);
149 pcm_getfakechan(d)->flags |= CHN_F_BUSY;
153 if (*rdch && *rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
155 if (*wrch && *wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
161 /* unlock specified channels */
163 relchns(dev_t dev, struct pcm_channel *rdch, struct pcm_channel *wrch, u_int32_t prio)
165 struct snddev_info *d;
167 d = dsp_get_info(dev);
168 if (wrch && wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
170 if (rdch && rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
178 dsp_open(dev_t i_dev, int flags, int mode, struct thread *td)
180 struct pcm_channel *rdch, *wrch;
181 struct snddev_info *d;
185 struct proc *p = td->td_proc;
190 d = dsp_get_info(i_dev);
191 devtype = PCMDEV(i_dev);
193 /* decide default format */
207 case SND_DEV_NORESET:
220 panic("impossible devtype %d", devtype);
223 /* lock snddev so nobody else can monkey with it */
226 rdch = i_dev->si_drv1;
227 wrch = i_dev->si_drv2;
229 if ((dsp_get_flags(i_dev) & SD_F_SIMPLEX) && (rdch || wrch)) {
230 /* simplex device, already open, exit */
236 if (((flags & FREAD) && rdch) || ((flags & FWRITE) && wrch)) {
237 /* device already open in one or both directions */
243 /* if we get here, the open request is valid */
246 if (devtype == SND_DEV_DSPREC)
247 rdch = pcm_chnalloc(d, PCMDIR_REC, p->p_pid, PCMCHAN(i_dev));
249 rdch = pcm_chnalloc(d, PCMDIR_REC, p->p_pid, -1);
251 /* no channel available, exit */
256 /* got a channel, already locked for us */
259 if (flags & FWRITE) {
261 wrch = pcm_chnalloc(d, PCMDIR_PLAY, p->p_pid, -1);
263 /* no channel available */
264 if (rdch && (flags & FREAD)) {
265 /* just opened a read channel, release it */
266 pcm_chnrelease(rdch);
273 /* got a channel, already locked for us */
276 i_dev->si_drv1 = rdch;
277 i_dev->si_drv2 = wrch;
279 /* finished with snddev, new channels still locked */
281 /* bump refcounts, reset and unlock any channels that we just opened */
283 if (chn_reset(rdch, fmt)) {
285 pcm_chnrelease(rdch);
286 if (wrch && (flags & FWRITE))
287 pcm_chnrelease(wrch);
292 if (flags & O_NONBLOCK)
293 rdch->flags |= CHN_F_NBIO;
297 if (flags & FWRITE) {
298 if (chn_reset(wrch, fmt)) {
300 pcm_chnrelease(wrch);
303 pcm_chnref(rdch, -1);
304 pcm_chnrelease(rdch);
311 if (flags & O_NONBLOCK)
312 wrch->flags |= CHN_F_NBIO;
321 dsp_close(dev_t i_dev, int flags, int mode, struct thread *td)
323 struct pcm_channel *rdch, *wrch;
324 struct snddev_info *d;
329 d = dsp_get_info(i_dev);
331 rdch = i_dev->si_drv1;
332 wrch = i_dev->si_drv2;
336 /* decrement refcount for each channel, exit if nonzero */
339 if (pcm_chnref(rdch, -1) > 0) {
346 if (pcm_chnref(wrch, -1) > 0) {
357 /* both refcounts are zero, abort and release */
359 if (pcm_getfakechan(d))
360 pcm_getfakechan(d)->flags = 0;
362 i_dev->si_drv1 = NULL;
363 i_dev->si_drv2 = NULL;
365 dsp_set_flags(i_dev, dsp_get_flags(i_dev) & ~SD_F_TRANSIENT);
369 chn_abort(rdch); /* won't sleep */
370 rdch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
372 pcm_chnrelease(rdch);
375 chn_flush(wrch); /* may sleep */
376 wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
378 pcm_chnrelease(wrch);
386 dsp_read(dev_t i_dev, struct uio *buf, int flag)
388 struct pcm_channel *rdch, *wrch;
393 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD);
395 KASSERT(rdch, ("dsp_read: nonexistant channel"));
396 KASSERT(rdch->flags & CHN_F_BUSY, ("dsp_read: nonbusy channel"));
398 if (rdch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
399 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
403 if (!(rdch->flags & CHN_F_RUNNING))
404 rdch->flags |= CHN_F_RUNNING;
405 ret = chn_read(rdch, buf);
406 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
413 dsp_write(dev_t i_dev, struct uio *buf, int flag)
415 struct pcm_channel *rdch, *wrch;
420 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_WR);
422 KASSERT(wrch, ("dsp_write: nonexistant channel"));
423 KASSERT(wrch->flags & CHN_F_BUSY, ("dsp_write: nonbusy channel"));
425 if (wrch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
426 relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
430 if (!(wrch->flags & CHN_F_RUNNING))
431 wrch->flags |= CHN_F_RUNNING;
432 ret = chn_write(wrch, buf);
433 relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
440 dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct thread *td)
442 struct pcm_channel *wrch, *rdch;
443 struct snddev_info *d;
446 int ret = 0, *arg_i = (int *)arg, tmp;
449 * this is an evil hack to allow broken apps to perform mixer ioctls
453 if (IOCGROUP(cmd) == 'M') {
456 pdev = make_adhoc_dev(&dsp_cdevsw,
457 PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0));
458 return mixer_ioctl(pdev, cmd, arg, mode, td);
462 d = dsp_get_info(i_dev);
463 getchns(i_dev, &rdch, &wrch, 0);
466 if (wrch && (wrch->flags & CHN_F_DEAD))
468 if (rdch && (rdch->flags & CHN_F_DEAD))
471 relchns(i_dev, rdch, wrch, 0);
483 * we start with the new ioctl interface.
485 case AIONWRITE: /* how many bytes can write ? */
487 if (wrch && wrch->bufhard.dl)
488 while (chn_wrfeed(wrch) == 0);
490 *arg_i = wrch? sndbuf_getfree(wrch->bufsoft) : 0;
493 case AIOSSIZE: /* set the current blocksize */
495 struct snd_size *p = (struct snd_size *)arg;
501 chn_setblocksize(wrch, 2, p->play_size);
502 p->play_size = sndbuf_getblksz(wrch->bufsoft);
507 chn_setblocksize(rdch, 2, p->rec_size);
508 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
513 case AIOGSIZE: /* get the current blocksize */
515 struct snd_size *p = (struct snd_size *)arg;
518 p->play_size = sndbuf_getblksz(wrch->bufsoft);
520 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
526 snd_chan_param *p = (snd_chan_param *)arg;
530 chn_setformat(wrch, p->play_format);
531 chn_setspeed(wrch, p->play_rate);
536 chn_setformat(rdch, p->rec_format);
537 chn_setspeed(rdch, p->rec_rate);
545 snd_chan_param *p = (snd_chan_param *)arg;
547 p->play_rate = wrch? wrch->speed : 0;
548 p->rec_rate = rdch? rdch->speed : 0;
549 p->play_format = wrch? wrch->format : 0;
550 p->rec_format = rdch? rdch->format : 0;
554 case AIOGCAP: /* get capabilities */
556 snd_capabilities *p = (snd_capabilities *)arg;
557 struct pcmchan_caps *pcaps = NULL, *rcaps = NULL;
562 rcaps = chn_getcaps(rdch);
566 pcaps = chn_getcaps(wrch);
568 p->rate_min = max(rcaps? rcaps->minspeed : 0,
569 pcaps? pcaps->minspeed : 0);
570 p->rate_max = min(rcaps? rcaps->maxspeed : 1000000,
571 pcaps? pcaps->maxspeed : 1000000);
572 p->bufsize = min(rdch? sndbuf_getsize(rdch->bufsoft) : 1000000,
573 wrch? sndbuf_getsize(wrch->bufsoft) : 1000000);
574 /* XXX bad on sb16 */
575 p->formats = (rdch? chn_getformats(rdch) : 0xffffffff) &
576 (wrch? chn_getformats(wrch) : 0xffffffff);
578 p->formats |= (dsp_get_flags(i_dev) & SD_F_SIMPLEX)? 0 : AFMT_FULLDUPLEX;
579 pdev = make_adhoc_dev(&dsp_cdevsw, PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0));
580 p->mixers = 1; /* default: one mixer */
581 p->inputs = pdev->si_drv1? mix_getdevs(pdev->si_drv1) : 0;
582 p->left = p->right = 100;
591 if (*arg_i == AIOSYNC_PLAY && wrch)
592 *arg_i = chn_abort(wrch);
593 else if (*arg_i == AIOSYNC_CAPTURE && rdch)
594 *arg_i = chn_abort(rdch);
596 printf("AIOSTOP: bad channel 0x%x\n", *arg_i);
602 printf("AIOSYNC chan 0x%03lx pos %lu unimplemented\n",
603 ((snd_sync_parm *)arg)->chan, ((snd_sync_parm *)arg)->pos);
607 * here follow the standard ioctls (filio.h etc.)
609 case FIONREAD: /* get # bytes to read */
610 /* if (rdch && rdch->bufhard.dl)
611 while (chn_rdfeed(rdch) == 0);
612 */ *arg_i = rdch? sndbuf_getready(rdch->bufsoft) : 0;
615 case FIOASYNC: /*set/clear async i/o */
616 DEB( printf("FIOASYNC\n") ; )
619 case SNDCTL_DSP_NONBLOCK:
620 case FIONBIO: /* set/clear non-blocking i/o */
622 rdch->flags &= ~CHN_F_NBIO;
624 wrch->flags &= ~CHN_F_NBIO;
627 rdch->flags |= CHN_F_NBIO;
629 wrch->flags |= CHN_F_NBIO;
634 * Finally, here is the linux-compatible ioctl interface
636 #define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
637 case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
638 case SNDCTL_DSP_GETBLKSIZE:
640 *arg_i = sndbuf_getblksz(wrch->bufsoft);
642 *arg_i = sndbuf_getblksz(rdch->bufsoft);
647 case SNDCTL_DSP_SETBLKSIZE:
648 RANGE(*arg_i, 16, 65536);
651 chn_setblocksize(wrch, 2, *arg_i);
656 chn_setblocksize(rdch, 2, *arg_i);
661 case SNDCTL_DSP_RESET:
662 DEB(printf("dsp reset\n"));
669 case SNDCTL_DSP_SYNC:
670 DEB(printf("dsp sync\n"));
671 /* chn_sync may sleep */
674 chn_sync(wrch, sndbuf_getsize(wrch->bufsoft) - 4);
679 case SNDCTL_DSP_SPEED:
680 /* chn_setspeed may sleep */
684 ret = chn_setspeed(wrch, *arg_i);
688 if (rdch && ret == 0) {
690 ret = chn_setspeed(rdch, *arg_i);
698 case SOUND_PCM_READ_RATE:
699 *arg_i = wrch? wrch->speed : rdch->speed;
702 case SNDCTL_DSP_STEREO:
704 *arg_i = (*arg_i)? AFMT_STEREO : 0;
707 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
708 tmp = (wrch->format & AFMT_STEREO)? 1 : 0;
711 if (rdch && ret == 0) {
713 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
715 tmp = (rdch->format & AFMT_STEREO)? 1 : 0;
721 case SOUND_PCM_WRITE_CHANNELS:
722 /* case SNDCTL_DSP_CHANNELS: ( == SOUND_PCM_WRITE_CHANNELS) */
725 *arg_i = (*arg_i != 1)? AFMT_STEREO : 0;
728 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
729 tmp = (wrch->format & AFMT_STEREO)? 2 : 1;
732 if (rdch && ret == 0) {
734 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
736 tmp = (rdch->format & AFMT_STEREO)? 2 : 1;
741 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1;
745 case SOUND_PCM_READ_CHANNELS:
746 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1;
749 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */
750 *arg_i = wrch? chn_getformats(wrch) : chn_getformats(rdch);
753 case SNDCTL_DSP_SETFMT: /* sets _one_ format */
755 if ((*arg_i != AFMT_QUERY)) {
759 ret = chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO));
760 tmp = wrch->format & ~AFMT_STEREO;
763 if (rdch && ret == 0) {
765 ret = chn_setformat(rdch, (*arg_i) | (rdch->format & AFMT_STEREO));
767 tmp = rdch->format & ~AFMT_STEREO;
772 *arg_i = (wrch? wrch->format : rdch->format) & ~AFMT_STEREO;
775 case SNDCTL_DSP_SETFRAGMENT:
777 DEB(printf("SNDCTL_DSP_SETFRAGMENT 0x%08x\n", *(int *)arg));
779 u_int32_t fragln = (*arg_i) & 0x0000ffff;
780 u_int32_t maxfrags = ((*arg_i) & 0xffff0000) >> 16;
783 RANGE(fragln, 4, 16);
784 fragsz = 1 << fragln;
787 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
792 if (maxfrags * fragsz > CHN_2NDBUFMAXSIZE)
793 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
795 DEB(printf("SNDCTL_DSP_SETFRAGMENT %d frags, %d sz\n", maxfrags, fragsz));
798 ret = chn_setblocksize(rdch, maxfrags, fragsz);
799 maxfrags = sndbuf_getblkcnt(rdch->bufsoft);
800 fragsz = sndbuf_getblksz(rdch->bufsoft);
803 if (wrch && ret == 0) {
805 ret = chn_setblocksize(wrch, maxfrags, fragsz);
806 maxfrags = sndbuf_getblkcnt(wrch->bufsoft);
807 fragsz = sndbuf_getblksz(wrch->bufsoft);
816 *arg_i = (maxfrags << 16) | fragln;
820 case SNDCTL_DSP_GETISPACE:
821 /* return the size of data available in the input queue */
823 audio_buf_info *a = (audio_buf_info *)arg;
825 struct snd_dbuf *bs = rdch->bufsoft;
828 a->bytes = sndbuf_getready(bs);
829 a->fragments = a->bytes / sndbuf_getblksz(bs);
830 a->fragstotal = sndbuf_getblkcnt(bs);
831 a->fragsize = sndbuf_getblksz(bs);
837 case SNDCTL_DSP_GETOSPACE:
838 /* return space available in the output queue */
840 audio_buf_info *a = (audio_buf_info *)arg;
842 struct snd_dbuf *bs = wrch->bufsoft;
846 a->bytes = sndbuf_getfree(bs);
847 a->fragments = a->bytes / sndbuf_getblksz(bs);
848 a->fragstotal = sndbuf_getblkcnt(bs);
849 a->fragsize = sndbuf_getblksz(bs);
855 case SNDCTL_DSP_GETIPTR:
857 count_info *a = (count_info *)arg;
859 struct snd_dbuf *bs = rdch->bufsoft;
863 a->bytes = sndbuf_gettotal(bs);
864 a->blocks = sndbuf_getblocks(bs) - rdch->blocks;
865 a->ptr = sndbuf_getreadyptr(bs);
866 rdch->blocks = sndbuf_getblocks(bs);
873 case SNDCTL_DSP_GETOPTR:
875 count_info *a = (count_info *)arg;
877 struct snd_dbuf *bs = wrch->bufsoft;
881 a->bytes = sndbuf_gettotal(bs);
882 a->blocks = sndbuf_getblocks(bs) - wrch->blocks;
883 a->ptr = sndbuf_getreadyptr(bs);
884 wrch->blocks = sndbuf_getblocks(bs);
891 case SNDCTL_DSP_GETCAPS:
892 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
893 if (rdch && wrch && !(dsp_get_flags(i_dev) & SD_F_SIMPLEX))
894 *arg_i |= DSP_CAP_DUPLEX;
897 case SOUND_PCM_READ_BITS:
898 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_16BIT)? 16 : 8;
901 case SNDCTL_DSP_SETTRIGGER:
904 rdch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
905 if (*arg_i & PCM_ENABLE_INPUT)
908 rdch->flags |= CHN_F_NOTRIGGER;
913 wrch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
914 if (*arg_i & PCM_ENABLE_OUTPUT)
917 wrch->flags |= CHN_F_NOTRIGGER;
922 case SNDCTL_DSP_GETTRIGGER:
924 if (wrch && wrch->flags & CHN_F_TRIGGERED)
925 *arg_i |= PCM_ENABLE_OUTPUT;
926 if (rdch && rdch->flags & CHN_F_TRIGGERED)
927 *arg_i |= PCM_ENABLE_INPUT;
930 case SNDCTL_DSP_GETODELAY:
932 struct snd_dbuf *b = wrch->bufhard;
933 struct snd_dbuf *bs = wrch->bufsoft;
937 *arg_i = sndbuf_getready(b) + sndbuf_getready(bs);
943 case SNDCTL_DSP_POST:
946 wrch->flags &= ~CHN_F_NOTRIGGER;
952 case SNDCTL_DSP_MAPINBUF:
953 case SNDCTL_DSP_MAPOUTBUF:
954 case SNDCTL_DSP_SETSYNCRO:
957 case SNDCTL_DSP_SUBDIVIDE:
958 case SOUND_PCM_WRITE_FILTER:
959 case SOUND_PCM_READ_FILTER:
960 /* dunno what these do, don't sound important */
962 DEB(printf("default ioctl fn 0x%08lx fail\n", cmd));
966 relchns(i_dev, rdch, wrch, 0);
972 dsp_poll(dev_t i_dev, int events, struct thread *td)
974 struct pcm_channel *wrch = NULL, *rdch = NULL;
980 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
983 e = (events & (POLLOUT | POLLWRNORM));
985 ret |= chn_poll(wrch, e, td->td_proc);
988 e = (events & (POLLIN | POLLRDNORM));
990 ret |= chn_poll(rdch, e, td->td_proc);
992 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
999 dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot)
1001 struct pcm_channel *wrch = NULL, *rdch = NULL, *c;
1005 if (nprot & PROT_EXEC)
1009 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1012 * XXX the linux api uses the nprot to select read/write buffer
1013 * our vm system doesn't allow this, so force write buffer
1016 if (wrch && (nprot & PROT_WRITE)) {
1018 } else if (rdch && (nprot & PROT_READ)) {
1029 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1034 if (offset >= sndbuf_getsize(c->bufsoft)) {
1035 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1040 if (!(c->flags & CHN_F_MAPPED))
1041 c->flags |= CHN_F_MAPPED;
1043 ret = atop(vtophys(sndbuf_getbufofs(c->bufsoft, offset)));
1044 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1051 dsp_register(int unit, int channel)
1053 cdevsw_add(&dsp_cdevsw,
1054 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP, 0));
1055 cdevsw_add(&dsp_cdevsw,
1056 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP16, 0));
1057 cdevsw_add(&dsp_cdevsw,
1058 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_AUDIO, 0));
1059 cdevsw_add(&dsp_cdevsw,
1060 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_NORESET, 0));
1061 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP, channel),
1062 UID_ROOT, GID_WHEEL, 0666, "dsp%d.%d", unit, channel);
1063 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP16, channel),
1064 UID_ROOT, GID_WHEEL, 0666, "dspW%d.%d", unit, channel);
1065 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_AUDIO, channel),
1066 UID_ROOT, GID_WHEEL, 0666, "audio%d.%d", unit, channel);
1072 dsp_registerrec(int unit, int channel)
1074 cdevsw_add(&dsp_cdevsw,
1075 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSPREC, 0));
1076 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSPREC, channel),
1077 UID_ROOT, GID_WHEEL, 0666, "dspr%d.%d", unit, channel);
1083 dsp_unregister(int unit, int channel)
1085 cdevsw_remove(&dsp_cdevsw,
1086 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP, 0));
1087 cdevsw_remove(&dsp_cdevsw,
1088 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP16, 0));
1089 cdevsw_remove(&dsp_cdevsw,
1090 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_AUDIO, 0));
1091 cdevsw_remove(&dsp_cdevsw,
1092 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_NORESET, 0));
1097 dsp_unregisterrec(int unit, int channel)
1099 cdevsw_remove(&dsp_cdevsw,
1100 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSPREC, 0));
1106 dsp_clone(void *arg, char *name, int namelen, dev_t *dev)
1109 int i, cont, unit, devtype;
1110 int devtypes[3] = {SND_DEV_DSP, SND_DEV_DSP16, SND_DEV_AUDIO};
1111 char *devnames[3] = {"dsp", "dspW", "audio"};
1115 if (pcm_devclass == NULL)
1120 for (i = 0; (i < 3) && (unit == -1); i++) {
1121 devtype = devtypes[i];
1122 if (strcmp(name, devnames[i]) == 0) {
1125 if (dev_stdclone(name, NULL, devnames[i], &unit) != 1)
1129 if (unit == -1 || unit >= devclass_get_maxunit(pcm_devclass))
1133 for (i = 0; cont; i++) {
1134 pdev = make_adhoc_dev(&dsp_cdevsw, PCMMKMINOR(unit, devtype, i));
1135 if (pdev->si_flags & SI_NAMED) {
1136 if ((pdev->si_drv1 == NULL) && (pdev->si_drv2 == NULL)) {
1147 dsp_sysinit(void *p)
1149 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000);
1153 dsp_sysuninit(void *p)
1155 if (dsp_ehtag != NULL)
1156 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag);
1159 SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
1160 SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);