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.2 2003/06/17 04:28:31 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.2 2003/06/17 04:28:31 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 /* close */ dsp_close,
51 /* write */ dsp_write,
52 /* ioctl */ dsp_ioctl,
55 /* strategy */ nostrategy,
57 /* maj */ SND_CDEV_MAJOR,
64 static eventhandler_tag dsp_ehtag;
67 static struct snddev_info *
68 dsp_get_info(dev_t dev)
70 struct snddev_info *d;
74 if (unit >= devclass_get_maxunit(pcm_devclass))
76 d = devclass_get_softc(pcm_devclass, unit);
82 dsp_get_flags(dev_t dev)
88 if (unit >= devclass_get_maxunit(pcm_devclass))
90 bdev = devclass_get_device(pcm_devclass, unit);
92 return pcm_getflags(bdev);
96 dsp_set_flags(dev_t dev, u_int32_t flags)
102 if (unit >= devclass_get_maxunit(pcm_devclass))
104 bdev = devclass_get_device(pcm_devclass, unit);
106 pcm_setflags(bdev, flags);
110 * return the channels channels associated with an open device instance.
111 * set the priority if the device is simplex and one direction (only) is
113 * lock channels specified.
116 getchns(dev_t dev, struct pcm_channel **rdch, struct pcm_channel **wrch, u_int32_t prio)
118 struct snddev_info *d;
121 flags = dsp_get_flags(dev);
122 d = dsp_get_info(dev);
125 KASSERT((flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
126 ("getchns: read and write both prioritised"));
128 if ((flags & SD_F_PRIO_SET) == 0 && (prio != (SD_F_PRIO_RD | SD_F_PRIO_WR))) {
129 flags |= prio & (SD_F_PRIO_RD | SD_F_PRIO_WR);
130 dsp_set_flags(dev, flags);
133 *rdch = dev->si_drv1;
134 *wrch = dev->si_drv2;
135 if ((flags & SD_F_SIMPLEX) && (flags & SD_F_PRIO_SET)) {
137 if (*rdch && flags & SD_F_PRIO_WR) {
139 *rdch = pcm_getfakechan(d);
140 } else if (*wrch && flags & SD_F_PRIO_RD) {
142 *wrch = pcm_getfakechan(d);
146 pcm_getfakechan(d)->flags |= CHN_F_BUSY;
150 if (*rdch && *rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
152 if (*wrch && *wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
158 /* unlock specified channels */
160 relchns(dev_t dev, struct pcm_channel *rdch, struct pcm_channel *wrch, u_int32_t prio)
162 struct snddev_info *d;
164 d = dsp_get_info(dev);
165 if (wrch && wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
167 if (rdch && rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
175 dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
177 struct pcm_channel *rdch, *wrch;
178 struct snddev_info *d;
184 d = dsp_get_info(i_dev);
185 devtype = PCMDEV(i_dev);
187 /* decide default format */
201 case SND_DEV_NORESET:
214 panic("impossible devtype %d", devtype);
217 /* lock snddev so nobody else can monkey with it */
220 rdch = i_dev->si_drv1;
221 wrch = i_dev->si_drv2;
223 if ((dsp_get_flags(i_dev) & SD_F_SIMPLEX) && (rdch || wrch)) {
224 /* simplex device, already open, exit */
230 if (((flags & FREAD) && rdch) || ((flags & FWRITE) && wrch)) {
231 /* device already open in one or both directions */
237 /* if we get here, the open request is valid */
240 if (devtype == SND_DEV_DSPREC)
241 rdch = pcm_chnalloc(d, PCMDIR_REC, p->p_pid, PCMCHAN(i_dev));
243 rdch = pcm_chnalloc(d, PCMDIR_REC, p->p_pid, -1);
245 /* no channel available, exit */
250 /* got a channel, already locked for us */
253 if (flags & FWRITE) {
255 wrch = pcm_chnalloc(d, PCMDIR_PLAY, p->p_pid, -1);
257 /* no channel available */
258 if (rdch && (flags & FREAD)) {
259 /* just opened a read channel, release it */
260 pcm_chnrelease(rdch);
267 /* got a channel, already locked for us */
270 i_dev->si_drv1 = rdch;
271 i_dev->si_drv2 = wrch;
273 /* finished with snddev, new channels still locked */
275 /* bump refcounts, reset and unlock any channels that we just opened */
277 if (chn_reset(rdch, fmt)) {
279 pcm_chnrelease(rdch);
280 if (wrch && (flags & FWRITE))
281 pcm_chnrelease(wrch);
286 if (flags & O_NONBLOCK)
287 rdch->flags |= CHN_F_NBIO;
291 if (flags & FWRITE) {
292 if (chn_reset(wrch, fmt)) {
294 pcm_chnrelease(wrch);
297 pcm_chnref(rdch, -1);
298 pcm_chnrelease(rdch);
305 if (flags & O_NONBLOCK)
306 wrch->flags |= CHN_F_NBIO;
315 dsp_close(dev_t i_dev, int flags, int mode, struct proc *p)
317 struct pcm_channel *rdch, *wrch;
318 struct snddev_info *d;
323 d = dsp_get_info(i_dev);
325 rdch = i_dev->si_drv1;
326 wrch = i_dev->si_drv2;
330 /* decrement refcount for each channel, exit if nonzero */
333 if (pcm_chnref(rdch, -1) > 0) {
340 if (pcm_chnref(wrch, -1) > 0) {
351 /* both refcounts are zero, abort and release */
353 if (pcm_getfakechan(d))
354 pcm_getfakechan(d)->flags = 0;
356 i_dev->si_drv1 = NULL;
357 i_dev->si_drv2 = NULL;
359 dsp_set_flags(i_dev, dsp_get_flags(i_dev) & ~SD_F_TRANSIENT);
363 chn_abort(rdch); /* won't sleep */
364 rdch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
366 pcm_chnrelease(rdch);
369 chn_flush(wrch); /* may sleep */
370 wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
372 pcm_chnrelease(wrch);
380 dsp_read(dev_t i_dev, struct uio *buf, int flag)
382 struct pcm_channel *rdch, *wrch;
387 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD);
389 KASSERT(rdch, ("dsp_read: nonexistant channel"));
390 KASSERT(rdch->flags & CHN_F_BUSY, ("dsp_read: nonbusy channel"));
392 if (rdch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
393 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
397 if (!(rdch->flags & CHN_F_RUNNING))
398 rdch->flags |= CHN_F_RUNNING;
399 ret = chn_read(rdch, buf);
400 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
407 dsp_write(dev_t i_dev, struct uio *buf, int flag)
409 struct pcm_channel *rdch, *wrch;
414 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_WR);
416 KASSERT(wrch, ("dsp_write: nonexistant channel"));
417 KASSERT(wrch->flags & CHN_F_BUSY, ("dsp_write: nonbusy channel"));
419 if (wrch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
420 relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
424 if (!(wrch->flags & CHN_F_RUNNING))
425 wrch->flags |= CHN_F_RUNNING;
426 ret = chn_write(wrch, buf);
427 relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
434 dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
436 struct pcm_channel *wrch, *rdch;
437 struct snddev_info *d;
440 int ret = 0, *arg_i = (int *)arg, tmp;
443 * this is an evil hack to allow broken apps to perform mixer ioctls
447 if (IOCGROUP(cmd) == 'M') {
450 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0));
451 return mixer_ioctl(pdev, cmd, arg, mode, p);
455 d = dsp_get_info(i_dev);
456 getchns(i_dev, &rdch, &wrch, 0);
459 if (wrch && (wrch->flags & CHN_F_DEAD))
461 if (rdch && (rdch->flags & CHN_F_DEAD))
464 relchns(i_dev, rdch, wrch, 0);
476 * we start with the new ioctl interface.
478 case AIONWRITE: /* how many bytes can write ? */
480 if (wrch && wrch->bufhard.dl)
481 while (chn_wrfeed(wrch) == 0);
483 *arg_i = wrch? sndbuf_getfree(wrch->bufsoft) : 0;
486 case AIOSSIZE: /* set the current blocksize */
488 struct snd_size *p = (struct snd_size *)arg;
494 chn_setblocksize(wrch, 2, p->play_size);
495 p->play_size = sndbuf_getblksz(wrch->bufsoft);
500 chn_setblocksize(rdch, 2, p->rec_size);
501 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
506 case AIOGSIZE: /* get the current blocksize */
508 struct snd_size *p = (struct snd_size *)arg;
511 p->play_size = sndbuf_getblksz(wrch->bufsoft);
513 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
519 snd_chan_param *p = (snd_chan_param *)arg;
523 chn_setformat(wrch, p->play_format);
524 chn_setspeed(wrch, p->play_rate);
529 chn_setformat(rdch, p->rec_format);
530 chn_setspeed(rdch, p->rec_rate);
538 snd_chan_param *p = (snd_chan_param *)arg;
540 p->play_rate = wrch? wrch->speed : 0;
541 p->rec_rate = rdch? rdch->speed : 0;
542 p->play_format = wrch? wrch->format : 0;
543 p->rec_format = rdch? rdch->format : 0;
547 case AIOGCAP: /* get capabilities */
549 snd_capabilities *p = (snd_capabilities *)arg;
550 struct pcmchan_caps *pcaps = NULL, *rcaps = NULL;
555 rcaps = chn_getcaps(rdch);
559 pcaps = chn_getcaps(wrch);
561 p->rate_min = max(rcaps? rcaps->minspeed : 0,
562 pcaps? pcaps->minspeed : 0);
563 p->rate_max = min(rcaps? rcaps->maxspeed : 1000000,
564 pcaps? pcaps->maxspeed : 1000000);
565 p->bufsize = min(rdch? sndbuf_getsize(rdch->bufsoft) : 1000000,
566 wrch? sndbuf_getsize(wrch->bufsoft) : 1000000);
567 /* XXX bad on sb16 */
568 p->formats = (rdch? chn_getformats(rdch) : 0xffffffff) &
569 (wrch? chn_getformats(wrch) : 0xffffffff);
571 p->formats |= (dsp_get_flags(i_dev) & SD_F_SIMPLEX)? 0 : AFMT_FULLDUPLEX;
572 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(PCMUNIT(i_dev), SND_DEV_CTL, 0));
573 p->mixers = 1; /* default: one mixer */
574 p->inputs = pdev->si_drv1? mix_getdevs(pdev->si_drv1) : 0;
575 p->left = p->right = 100;
584 if (*arg_i == AIOSYNC_PLAY && wrch)
585 *arg_i = chn_abort(wrch);
586 else if (*arg_i == AIOSYNC_CAPTURE && rdch)
587 *arg_i = chn_abort(rdch);
589 printf("AIOSTOP: bad channel 0x%x\n", *arg_i);
595 printf("AIOSYNC chan 0x%03lx pos %lu unimplemented\n",
596 ((snd_sync_parm *)arg)->chan, ((snd_sync_parm *)arg)->pos);
600 * here follow the standard ioctls (filio.h etc.)
602 case FIONREAD: /* get # bytes to read */
603 /* if (rdch && rdch->bufhard.dl)
604 while (chn_rdfeed(rdch) == 0);
605 */ *arg_i = rdch? sndbuf_getready(rdch->bufsoft) : 0;
608 case FIOASYNC: /*set/clear async i/o */
609 DEB( printf("FIOASYNC\n") ; )
612 case SNDCTL_DSP_NONBLOCK:
613 case FIONBIO: /* set/clear non-blocking i/o */
615 rdch->flags &= ~CHN_F_NBIO;
617 wrch->flags &= ~CHN_F_NBIO;
620 rdch->flags |= CHN_F_NBIO;
622 wrch->flags |= CHN_F_NBIO;
627 * Finally, here is the linux-compatible ioctl interface
629 #define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
630 case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
631 case SNDCTL_DSP_GETBLKSIZE:
633 *arg_i = sndbuf_getblksz(wrch->bufsoft);
635 *arg_i = sndbuf_getblksz(rdch->bufsoft);
640 case SNDCTL_DSP_SETBLKSIZE:
641 RANGE(*arg_i, 16, 65536);
644 chn_setblocksize(wrch, 2, *arg_i);
649 chn_setblocksize(rdch, 2, *arg_i);
654 case SNDCTL_DSP_RESET:
655 DEB(printf("dsp reset\n"));
662 case SNDCTL_DSP_SYNC:
663 DEB(printf("dsp sync\n"));
664 /* chn_sync may sleep */
667 chn_sync(wrch, sndbuf_getsize(wrch->bufsoft) - 4);
672 case SNDCTL_DSP_SPEED:
673 /* chn_setspeed may sleep */
677 ret = chn_setspeed(wrch, *arg_i);
681 if (rdch && ret == 0) {
683 ret = chn_setspeed(rdch, *arg_i);
691 case SOUND_PCM_READ_RATE:
692 *arg_i = wrch? wrch->speed : rdch->speed;
695 case SNDCTL_DSP_STEREO:
697 *arg_i = (*arg_i)? AFMT_STEREO : 0;
700 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
701 tmp = (wrch->format & AFMT_STEREO)? 1 : 0;
704 if (rdch && ret == 0) {
706 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
708 tmp = (rdch->format & AFMT_STEREO)? 1 : 0;
714 case SOUND_PCM_WRITE_CHANNELS:
715 /* case SNDCTL_DSP_CHANNELS: ( == SOUND_PCM_WRITE_CHANNELS) */
718 *arg_i = (*arg_i != 1)? AFMT_STEREO : 0;
721 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
722 tmp = (wrch->format & AFMT_STEREO)? 2 : 1;
725 if (rdch && ret == 0) {
727 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
729 tmp = (rdch->format & AFMT_STEREO)? 2 : 1;
734 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1;
738 case SOUND_PCM_READ_CHANNELS:
739 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1;
742 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */
743 *arg_i = wrch? chn_getformats(wrch) : chn_getformats(rdch);
746 case SNDCTL_DSP_SETFMT: /* sets _one_ format */
748 if ((*arg_i != AFMT_QUERY)) {
752 ret = chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO));
753 tmp = wrch->format & ~AFMT_STEREO;
756 if (rdch && ret == 0) {
758 ret = chn_setformat(rdch, (*arg_i) | (rdch->format & AFMT_STEREO));
760 tmp = rdch->format & ~AFMT_STEREO;
765 *arg_i = (wrch? wrch->format : rdch->format) & ~AFMT_STEREO;
768 case SNDCTL_DSP_SETFRAGMENT:
770 DEB(printf("SNDCTL_DSP_SETFRAGMENT 0x%08x\n", *(int *)arg));
772 u_int32_t fragln = (*arg_i) & 0x0000ffff;
773 u_int32_t maxfrags = ((*arg_i) & 0xffff0000) >> 16;
776 RANGE(fragln, 4, 16);
777 fragsz = 1 << fragln;
780 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
785 if (maxfrags * fragsz > CHN_2NDBUFMAXSIZE)
786 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
788 DEB(printf("SNDCTL_DSP_SETFRAGMENT %d frags, %d sz\n", maxfrags, fragsz));
791 ret = chn_setblocksize(rdch, maxfrags, fragsz);
792 maxfrags = sndbuf_getblkcnt(rdch->bufsoft);
793 fragsz = sndbuf_getblksz(rdch->bufsoft);
796 if (wrch && ret == 0) {
798 ret = chn_setblocksize(wrch, maxfrags, fragsz);
799 maxfrags = sndbuf_getblkcnt(wrch->bufsoft);
800 fragsz = sndbuf_getblksz(wrch->bufsoft);
809 *arg_i = (maxfrags << 16) | fragln;
813 case SNDCTL_DSP_GETISPACE:
814 /* return the size of data available in the input queue */
816 audio_buf_info *a = (audio_buf_info *)arg;
818 struct snd_dbuf *bs = rdch->bufsoft;
821 a->bytes = sndbuf_getready(bs);
822 a->fragments = a->bytes / sndbuf_getblksz(bs);
823 a->fragstotal = sndbuf_getblkcnt(bs);
824 a->fragsize = sndbuf_getblksz(bs);
830 case SNDCTL_DSP_GETOSPACE:
831 /* return space available in the output queue */
833 audio_buf_info *a = (audio_buf_info *)arg;
835 struct snd_dbuf *bs = wrch->bufsoft;
839 a->bytes = sndbuf_getfree(bs);
840 a->fragments = a->bytes / sndbuf_getblksz(bs);
841 a->fragstotal = sndbuf_getblkcnt(bs);
842 a->fragsize = sndbuf_getblksz(bs);
848 case SNDCTL_DSP_GETIPTR:
850 count_info *a = (count_info *)arg;
852 struct snd_dbuf *bs = rdch->bufsoft;
856 a->bytes = sndbuf_gettotal(bs);
857 a->blocks = sndbuf_getblocks(bs) - rdch->blocks;
858 a->ptr = sndbuf_getreadyptr(bs);
859 rdch->blocks = sndbuf_getblocks(bs);
866 case SNDCTL_DSP_GETOPTR:
868 count_info *a = (count_info *)arg;
870 struct snd_dbuf *bs = wrch->bufsoft;
874 a->bytes = sndbuf_gettotal(bs);
875 a->blocks = sndbuf_getblocks(bs) - wrch->blocks;
876 a->ptr = sndbuf_getreadyptr(bs);
877 wrch->blocks = sndbuf_getblocks(bs);
884 case SNDCTL_DSP_GETCAPS:
885 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
886 if (rdch && wrch && !(dsp_get_flags(i_dev) & SD_F_SIMPLEX))
887 *arg_i |= DSP_CAP_DUPLEX;
890 case SOUND_PCM_READ_BITS:
891 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_16BIT)? 16 : 8;
894 case SNDCTL_DSP_SETTRIGGER:
897 rdch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
898 if (*arg_i & PCM_ENABLE_INPUT)
901 rdch->flags |= CHN_F_NOTRIGGER;
906 wrch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
907 if (*arg_i & PCM_ENABLE_OUTPUT)
910 wrch->flags |= CHN_F_NOTRIGGER;
915 case SNDCTL_DSP_GETTRIGGER:
917 if (wrch && wrch->flags & CHN_F_TRIGGERED)
918 *arg_i |= PCM_ENABLE_OUTPUT;
919 if (rdch && rdch->flags & CHN_F_TRIGGERED)
920 *arg_i |= PCM_ENABLE_INPUT;
923 case SNDCTL_DSP_GETODELAY:
925 struct snd_dbuf *b = wrch->bufhard;
926 struct snd_dbuf *bs = wrch->bufsoft;
930 *arg_i = sndbuf_getready(b) + sndbuf_getready(bs);
936 case SNDCTL_DSP_POST:
939 wrch->flags &= ~CHN_F_NOTRIGGER;
945 case SNDCTL_DSP_MAPINBUF:
946 case SNDCTL_DSP_MAPOUTBUF:
947 case SNDCTL_DSP_SETSYNCRO:
950 case SNDCTL_DSP_SUBDIVIDE:
951 case SOUND_PCM_WRITE_FILTER:
952 case SOUND_PCM_READ_FILTER:
953 /* dunno what these do, don't sound important */
955 DEB(printf("default ioctl fn 0x%08lx fail\n", cmd));
959 relchns(i_dev, rdch, wrch, 0);
965 dsp_poll(dev_t i_dev, int events, struct proc *p)
967 struct pcm_channel *wrch = NULL, *rdch = NULL;
973 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
976 e = (events & (POLLOUT | POLLWRNORM));
978 ret |= chn_poll(wrch, e, p);
981 e = (events & (POLLIN | POLLRDNORM));
983 ret |= chn_poll(rdch, e, p);
985 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
992 dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot)
994 struct pcm_channel *wrch = NULL, *rdch = NULL, *c;
998 if (nprot & PROT_EXEC)
1002 getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1005 * XXX the linux api uses the nprot to select read/write buffer
1006 * our vm system doesn't allow this, so force write buffer
1009 if (wrch && (nprot & PROT_WRITE)) {
1011 } else if (rdch && (nprot & PROT_READ)) {
1022 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1027 if (offset >= sndbuf_getsize(c->bufsoft)) {
1028 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1033 if (!(c->flags & CHN_F_MAPPED))
1034 c->flags |= CHN_F_MAPPED;
1036 ret = atop(vtophys(sndbuf_getbufofs(c->bufsoft, offset)));
1037 relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1044 dsp_register(int unit, int channel)
1046 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP, channel),
1047 UID_ROOT, GID_WHEEL, 0666, "dsp%d.%d", unit, channel);
1048 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSP16, channel),
1049 UID_ROOT, GID_WHEEL, 0666, "dspW%d.%d", unit, channel);
1050 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_AUDIO, channel),
1051 UID_ROOT, GID_WHEEL, 0666, "audio%d.%d", unit, channel);
1057 dsp_registerrec(int unit, int channel)
1059 make_dev(&dsp_cdevsw, PCMMKMINOR(unit, SND_DEV_DSPREC, channel),
1060 UID_ROOT, GID_WHEEL, 0666, "dspr%d.%d", unit, channel);
1066 dsp_unregister(int unit, int channel)
1070 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP, channel));
1072 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSP16, channel));
1074 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_AUDIO, channel));
1081 dsp_unregisterrec(int unit, int channel)
1085 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, SND_DEV_DSPREC, channel));
1093 dsp_clone(void *arg, char *name, int namelen, dev_t *dev)
1096 int i, cont, unit, devtype;
1097 int devtypes[3] = {SND_DEV_DSP, SND_DEV_DSP16, SND_DEV_AUDIO};
1098 char *devnames[3] = {"dsp", "dspW", "audio"};
1102 if (pcm_devclass == NULL)
1107 for (i = 0; (i < 3) && (unit == -1); i++) {
1108 devtype = devtypes[i];
1109 if (strcmp(name, devnames[i]) == 0) {
1112 if (dev_stdclone(name, NULL, devnames[i], &unit) != 1)
1116 if (unit == -1 || unit >= devclass_get_maxunit(pcm_devclass))
1120 for (i = 0; cont; i++) {
1121 pdev = makedev(SND_CDEV_MAJOR, PCMMKMINOR(unit, devtype, i));
1122 if (pdev->si_flags & SI_NAMED) {
1123 if ((pdev->si_drv1 == NULL) && (pdev->si_drv2 == NULL)) {
1134 dsp_sysinit(void *p)
1136 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000);
1140 dsp_sysuninit(void *p)
1142 if (dsp_ehtag != NULL)
1143 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag);
1146 SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
1147 SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);