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.10 2006/07/28 02:17:38 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.10 2006/07/28 02:17:38 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 dev_ops dsp_ops = {
48 { "dsp", SND_CDEV_MAJOR, 0 },
59 static eventhandler_tag dsp_ehtag;
62 static struct snddev_info *
63 dsp_get_info(dev_t dev)
65 struct snddev_info *d;
69 if (unit >= devclass_get_maxunit(pcm_devclass))
71 d = devclass_get_softc(pcm_devclass, unit);
77 dsp_get_flags(dev_t dev)
83 if (unit >= devclass_get_maxunit(pcm_devclass))
85 bdev = devclass_get_device(pcm_devclass, unit);
87 return pcm_getflags(bdev);
91 dsp_set_flags(dev_t dev, u_int32_t flags)
97 if (unit >= devclass_get_maxunit(pcm_devclass))
99 bdev = devclass_get_device(pcm_devclass, unit);
101 pcm_setflags(bdev, flags);
105 * return the channels channels associated with an open device instance.
106 * set the priority if the device is simplex and one direction (only) is
108 * lock channels specified.
111 getchns(dev_t dev, struct pcm_channel **rdch, struct pcm_channel **wrch, u_int32_t prio)
113 struct snddev_info *d;
116 flags = dsp_get_flags(dev);
117 d = dsp_get_info(dev);
120 KASSERT((flags & SD_F_PRIO_SET) != SD_F_PRIO_SET, \
121 ("getchns: read and write both prioritised"));
123 if ((flags & SD_F_PRIO_SET) == 0 && (prio != (SD_F_PRIO_RD | SD_F_PRIO_WR))) {
124 flags |= prio & (SD_F_PRIO_RD | SD_F_PRIO_WR);
125 dsp_set_flags(dev, flags);
128 *rdch = dev->si_drv1;
129 *wrch = dev->si_drv2;
130 if ((flags & SD_F_SIMPLEX) && (flags & SD_F_PRIO_SET)) {
132 if (*rdch && flags & SD_F_PRIO_WR) {
134 *rdch = pcm_getfakechan(d);
135 } else if (*wrch && flags & SD_F_PRIO_RD) {
137 *wrch = pcm_getfakechan(d);
141 pcm_getfakechan(d)->flags |= CHN_F_BUSY;
145 if (*rdch && *rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
147 if (*wrch && *wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
153 /* unlock specified channels */
155 relchns(dev_t dev, struct pcm_channel *rdch, struct pcm_channel *wrch, u_int32_t prio)
157 struct snddev_info *d;
159 d = dsp_get_info(dev);
160 if (wrch && wrch != pcm_getfakechan(d) && (prio & SD_F_PRIO_WR))
162 if (rdch && rdch != pcm_getfakechan(d) && (prio & SD_F_PRIO_RD))
170 dsp_open(struct dev_open_args *ap)
172 dev_t dev = ap->a_head.a_dev;
173 struct pcm_channel *rdch, *wrch;
174 struct snddev_info *d;
179 d = dsp_get_info(dev);
180 devtype = PCMDEV(dev);
182 /* decide default format */
196 case SND_DEV_NORESET:
202 if (ap->a_oflags & FWRITE) {
209 panic("impossible devtype %d", devtype);
212 /* lock snddev so nobody else can monkey with it */
218 if ((dsp_get_flags(dev) & SD_F_SIMPLEX) && (rdch || wrch)) {
219 /* simplex device, already open, exit */
225 if (((ap->a_oflags & FREAD) && rdch) ||
226 ((ap->a_oflags & FWRITE) && wrch)) {
227 /* device already open in one or both directions */
233 /* if we get here, the open request is valid */
234 if (ap->a_oflags & FREAD) {
236 if (devtype == SND_DEV_DSPREC)
237 rdch = pcm_chnalloc(d, PCMDIR_REC, curproc->p_pid, PCMCHAN(dev));
239 rdch = pcm_chnalloc(d, PCMDIR_REC, curproc->p_pid, -1);
241 /* no channel available, exit */
246 /* got a channel, already locked for us */
249 if (ap->a_oflags & FWRITE) {
251 wrch = pcm_chnalloc(d, PCMDIR_PLAY, curproc->p_pid, -1);
253 /* no channel available */
254 if (rdch && (ap->a_oflags & FREAD)) {
255 /* just opened a read channel, release it */
256 pcm_chnrelease(rdch);
263 /* got a channel, already locked for us */
269 /* finished with snddev, new channels still locked */
271 /* bump refcounts, reset and unlock any channels that we just opened */
272 if (ap->a_oflags & FREAD) {
273 if (chn_reset(rdch, fmt)) {
275 pcm_chnrelease(rdch);
276 if (wrch && (ap->a_oflags & FWRITE))
277 pcm_chnrelease(wrch);
283 /* removed, will be passed as an IO_ flag */
284 if (ap->a_oflags & O_NONBLOCK)
285 rdch->flags |= CHN_F_NBIO;
290 if (ap->a_oflags & FWRITE) {
291 if (chn_reset(wrch, fmt)) {
293 pcm_chnrelease(wrch);
294 if (ap->a_oflags & FREAD) {
296 pcm_chnref(rdch, -1);
297 pcm_chnrelease(rdch);
305 /* removed, will be passed as an IO_ flag */
306 if (ap->a_oflags & O_NONBLOCK)
307 wrch->flags |= CHN_F_NBIO;
317 dsp_close(struct dev_close_args *ap)
319 dev_t dev = ap->a_head.a_dev;
320 struct pcm_channel *rdch, *wrch;
321 struct snddev_info *d;
325 d = dsp_get_info(dev);
332 /* decrement refcount for each channel, exit if nonzero */
335 if (pcm_chnref(rdch, -1) > 0) {
342 if (pcm_chnref(wrch, -1) > 0) {
353 /* both refcounts are zero, abort and release */
355 if (pcm_getfakechan(d))
356 pcm_getfakechan(d)->flags = 0;
361 dsp_set_flags(dev, dsp_get_flags(dev) & ~SD_F_TRANSIENT);
365 chn_abort(rdch); /* won't sleep */
366 rdch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
368 pcm_chnrelease(rdch);
371 chn_flush(wrch); /* may sleep */
372 wrch->flags &= ~(CHN_F_RUNNING | CHN_F_MAPPED | CHN_F_DEAD);
374 pcm_chnrelease(wrch);
382 dsp_read(struct dev_read_args *ap)
384 dev_t dev = ap->a_head.a_dev;
385 struct pcm_channel *rdch, *wrch;
389 getchns(dev, &rdch, &wrch, SD_F_PRIO_RD);
391 KASSERT(rdch, ("dsp_read: nonexistant channel"));
392 KASSERT(rdch->flags & CHN_F_BUSY, ("dsp_read: nonbusy channel"));
394 if (rdch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
395 relchns(dev, rdch, wrch, SD_F_PRIO_RD);
399 if (!(rdch->flags & CHN_F_RUNNING))
400 rdch->flags |= CHN_F_RUNNING;
401 ret = chn_read(rdch, ap->a_uio, ap->a_ioflag);
402 relchns(dev, rdch, wrch, SD_F_PRIO_RD);
409 dsp_write(struct dev_write_args *ap)
411 dev_t dev = ap->a_head.a_dev;
412 struct pcm_channel *rdch, *wrch;
416 getchns(dev, &rdch, &wrch, SD_F_PRIO_WR);
418 KASSERT(wrch, ("dsp_write: nonexistant channel"));
419 KASSERT(wrch->flags & CHN_F_BUSY, ("dsp_write: nonbusy channel"));
421 if (wrch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
422 relchns(dev, rdch, wrch, SD_F_PRIO_WR);
426 if (!(wrch->flags & CHN_F_RUNNING))
427 wrch->flags |= CHN_F_RUNNING;
428 ret = chn_write(wrch, ap->a_uio, ap->a_ioflag);
429 relchns(dev, rdch, wrch, SD_F_PRIO_WR);
436 dsp_ioctl(struct dev_ioctl_args *ap)
438 dev_t dev = ap->a_head.a_dev;
439 u_long cmd = ap->a_cmd;
440 caddr_t arg = ap->a_data;
441 struct pcm_channel *wrch, *rdch;
442 struct snddev_info *d;
444 int ret = 0, *arg_i = (int *)arg, tmp;
447 * this is an evil hack to allow broken apps to perform mixer ioctls
451 if (IOCGROUP(cmd) == 'M') {
454 pdev = make_adhoc_dev(&dsp_ops,
455 PCMMKMINOR(PCMUNIT(dev), SND_DEV_CTL, 0));
456 ap->a_head.a_dev = pdev;
457 return mixer_ioctl(ap);
461 d = dsp_get_info(dev);
462 getchns(dev, &rdch, &wrch, 0);
465 if (wrch && (wrch->flags & CHN_F_DEAD))
467 if (rdch && (rdch->flags & CHN_F_DEAD))
470 relchns(dev, rdch, wrch, 0);
482 * we start with the new ioctl interface.
484 case AIONWRITE: /* how many bytes can write ? */
486 if (wrch && wrch->bufhard.dl)
487 while (chn_wrfeed(wrch) == 0);
489 *arg_i = wrch? sndbuf_getfree(wrch->bufsoft) : 0;
492 case AIOSSIZE: /* set the current blocksize */
494 struct snd_size *p = (struct snd_size *)arg;
500 chn_setblocksize(wrch, 2, p->play_size);
501 p->play_size = sndbuf_getblksz(wrch->bufsoft);
506 chn_setblocksize(rdch, 2, p->rec_size);
507 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
512 case AIOGSIZE: /* get the current blocksize */
514 struct snd_size *p = (struct snd_size *)arg;
517 p->play_size = sndbuf_getblksz(wrch->bufsoft);
519 p->rec_size = sndbuf_getblksz(rdch->bufsoft);
525 snd_chan_param *p = (snd_chan_param *)arg;
529 chn_setformat(wrch, p->play_format);
530 chn_setspeed(wrch, p->play_rate);
535 chn_setformat(rdch, p->rec_format);
536 chn_setspeed(rdch, p->rec_rate);
544 snd_chan_param *p = (snd_chan_param *)arg;
546 p->play_rate = wrch? wrch->speed : 0;
547 p->rec_rate = rdch? rdch->speed : 0;
548 p->play_format = wrch? wrch->format : 0;
549 p->rec_format = rdch? rdch->format : 0;
553 case AIOGCAP: /* get capabilities */
555 snd_capabilities *p = (snd_capabilities *)arg;
556 struct pcmchan_caps *pcaps = NULL, *rcaps = NULL;
561 rcaps = chn_getcaps(rdch);
565 pcaps = chn_getcaps(wrch);
567 p->rate_min = max(rcaps? rcaps->minspeed : 0,
568 pcaps? pcaps->minspeed : 0);
569 p->rate_max = min(rcaps? rcaps->maxspeed : 1000000,
570 pcaps? pcaps->maxspeed : 1000000);
571 p->bufsize = min(rdch? sndbuf_getsize(rdch->bufsoft) : 1000000,
572 wrch? sndbuf_getsize(wrch->bufsoft) : 1000000);
573 /* XXX bad on sb16 */
574 p->formats = (rdch? chn_getformats(rdch) : 0xffffffff) &
575 (wrch? chn_getformats(wrch) : 0xffffffff);
577 p->formats |= (dsp_get_flags(dev) & SD_F_SIMPLEX)? 0 : AFMT_FULLDUPLEX;
578 pdev = make_adhoc_dev(&dsp_ops, PCMMKMINOR(PCMUNIT(dev), SND_DEV_CTL, 0));
579 p->mixers = 1; /* default: one mixer */
580 p->inputs = pdev->si_drv1? mix_getdevs(pdev->si_drv1) : 0;
581 p->left = p->right = 100;
590 if (*arg_i == AIOSYNC_PLAY && wrch)
591 *arg_i = chn_abort(wrch);
592 else if (*arg_i == AIOSYNC_CAPTURE && rdch)
593 *arg_i = chn_abort(rdch);
595 printf("AIOSTOP: bad channel 0x%x\n", *arg_i);
601 printf("AIOSYNC chan 0x%03lx pos %lu unimplemented\n",
602 ((snd_sync_parm *)arg)->chan, ((snd_sync_parm *)arg)->pos);
606 * here follow the standard ioctls (filio.h etc.)
608 case FIONREAD: /* get # bytes to read */
609 /* if (rdch && rdch->bufhard.dl)
610 while (chn_rdfeed(rdch) == 0);
611 */ *arg_i = rdch? sndbuf_getready(rdch->bufsoft) : 0;
614 case FIOASYNC: /*set/clear async i/o */
615 DEB( printf("FIOASYNC\n") ; )
618 case SNDCTL_DSP_NONBLOCK:
620 * set/clear non-blocking I/O. WARNING: non-blocking I/O
621 * can also be set with FIONBIO
624 rdch->flags &= ~CHN_F_NBIO;
626 wrch->flags &= ~CHN_F_NBIO;
629 rdch->flags |= CHN_F_NBIO;
631 wrch->flags |= CHN_F_NBIO;
636 * Finally, here is the linux-compatible ioctl interface
638 #define THE_REAL_SNDCTL_DSP_GETBLKSIZE _IOWR('P', 4, int)
639 case THE_REAL_SNDCTL_DSP_GETBLKSIZE:
640 case SNDCTL_DSP_GETBLKSIZE:
642 *arg_i = sndbuf_getblksz(wrch->bufsoft);
644 *arg_i = sndbuf_getblksz(rdch->bufsoft);
649 case SNDCTL_DSP_SETBLKSIZE:
650 RANGE(*arg_i, 16, 65536);
653 chn_setblocksize(wrch, 2, *arg_i);
658 chn_setblocksize(rdch, 2, *arg_i);
663 case SNDCTL_DSP_RESET:
664 DEB(printf("dsp reset\n"));
671 case SNDCTL_DSP_SYNC:
672 DEB(printf("dsp sync\n"));
673 /* chn_sync may sleep */
676 chn_sync(wrch, sndbuf_getsize(wrch->bufsoft) - 4);
681 case SNDCTL_DSP_SPEED:
682 /* chn_setspeed may sleep */
686 ret = chn_setspeed(wrch, *arg_i);
690 if (rdch && ret == 0) {
692 ret = chn_setspeed(rdch, *arg_i);
700 case SOUND_PCM_READ_RATE:
701 *arg_i = wrch? wrch->speed : rdch->speed;
704 case SNDCTL_DSP_STEREO:
706 *arg_i = (*arg_i)? AFMT_STEREO : 0;
709 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
710 tmp = (wrch->format & AFMT_STEREO)? 1 : 0;
713 if (rdch && ret == 0) {
715 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
717 tmp = (rdch->format & AFMT_STEREO)? 1 : 0;
723 case SOUND_PCM_WRITE_CHANNELS:
724 /* case SNDCTL_DSP_CHANNELS: ( == SOUND_PCM_WRITE_CHANNELS) */
727 *arg_i = (*arg_i != 1)? AFMT_STEREO : 0;
730 ret = chn_setformat(wrch, (wrch->format & ~AFMT_STEREO) | *arg_i);
731 tmp = (wrch->format & AFMT_STEREO)? 2 : 1;
734 if (rdch && ret == 0) {
736 ret = chn_setformat(rdch, (rdch->format & ~AFMT_STEREO) | *arg_i);
738 tmp = (rdch->format & AFMT_STEREO)? 2 : 1;
743 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1;
747 case SOUND_PCM_READ_CHANNELS:
748 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_STEREO)? 2 : 1;
751 case SNDCTL_DSP_GETFMTS: /* returns a mask of supported fmts */
752 *arg_i = wrch? chn_getformats(wrch) : chn_getformats(rdch);
755 case SNDCTL_DSP_SETFMT: /* sets _one_ format */
757 if ((*arg_i != AFMT_QUERY)) {
761 ret = chn_setformat(wrch, (*arg_i) | (wrch->format & AFMT_STEREO));
762 tmp = wrch->format & ~AFMT_STEREO;
765 if (rdch && ret == 0) {
767 ret = chn_setformat(rdch, (*arg_i) | (rdch->format & AFMT_STEREO));
769 tmp = rdch->format & ~AFMT_STEREO;
774 *arg_i = (wrch? wrch->format : rdch->format) & ~AFMT_STEREO;
777 case SNDCTL_DSP_SETFRAGMENT:
779 DEB(printf("SNDCTL_DSP_SETFRAGMENT 0x%08x\n", *(int *)arg));
781 u_int32_t fragln = (*arg_i) & 0x0000ffff;
782 u_int32_t maxfrags = ((*arg_i) & 0xffff0000) >> 16;
785 RANGE(fragln, 4, 16);
786 fragsz = 1 << fragln;
789 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
794 if (maxfrags * fragsz > CHN_2NDBUFMAXSIZE)
795 maxfrags = CHN_2NDBUFMAXSIZE / fragsz;
797 DEB(printf("SNDCTL_DSP_SETFRAGMENT %d frags, %d sz\n", maxfrags, fragsz));
800 ret = chn_setblocksize(rdch, maxfrags, fragsz);
801 maxfrags = sndbuf_getblkcnt(rdch->bufsoft);
802 fragsz = sndbuf_getblksz(rdch->bufsoft);
805 if (wrch && ret == 0) {
807 ret = chn_setblocksize(wrch, maxfrags, fragsz);
808 maxfrags = sndbuf_getblkcnt(wrch->bufsoft);
809 fragsz = sndbuf_getblksz(wrch->bufsoft);
818 *arg_i = (maxfrags << 16) | fragln;
822 case SNDCTL_DSP_GETISPACE:
823 /* return the size of data available in the input queue */
825 audio_buf_info *a = (audio_buf_info *)arg;
827 struct snd_dbuf *bs = rdch->bufsoft;
830 a->bytes = sndbuf_getready(bs);
831 a->fragments = a->bytes / sndbuf_getblksz(bs);
832 a->fragstotal = sndbuf_getblkcnt(bs);
833 a->fragsize = sndbuf_getblksz(bs);
839 case SNDCTL_DSP_GETOSPACE:
840 /* return space available in the output queue */
842 audio_buf_info *a = (audio_buf_info *)arg;
844 struct snd_dbuf *bs = wrch->bufsoft;
848 a->bytes = sndbuf_getfree(bs);
849 a->fragments = a->bytes / sndbuf_getblksz(bs);
850 a->fragstotal = sndbuf_getblkcnt(bs);
851 a->fragsize = sndbuf_getblksz(bs);
857 case SNDCTL_DSP_GETIPTR:
859 count_info *a = (count_info *)arg;
861 struct snd_dbuf *bs = rdch->bufsoft;
865 a->bytes = sndbuf_gettotal(bs);
866 a->blocks = sndbuf_getblocks(bs) - rdch->blocks;
867 a->ptr = sndbuf_getreadyptr(bs);
868 rdch->blocks = sndbuf_getblocks(bs);
875 case SNDCTL_DSP_GETOPTR:
877 count_info *a = (count_info *)arg;
879 struct snd_dbuf *bs = wrch->bufsoft;
883 a->bytes = sndbuf_gettotal(bs);
884 a->blocks = sndbuf_getblocks(bs) - wrch->blocks;
885 a->ptr = sndbuf_getreadyptr(bs);
886 wrch->blocks = sndbuf_getblocks(bs);
893 case SNDCTL_DSP_GETCAPS:
894 *arg_i = DSP_CAP_REALTIME | DSP_CAP_MMAP | DSP_CAP_TRIGGER;
895 if (rdch && wrch && !(dsp_get_flags(dev) & SD_F_SIMPLEX))
896 *arg_i |= DSP_CAP_DUPLEX;
899 case SOUND_PCM_READ_BITS:
900 *arg_i = ((wrch? wrch->format : rdch->format) & AFMT_16BIT)? 16 : 8;
903 case SNDCTL_DSP_SETTRIGGER:
906 rdch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
907 if (*arg_i & PCM_ENABLE_INPUT)
910 rdch->flags |= CHN_F_NOTRIGGER;
915 wrch->flags &= ~(CHN_F_TRIGGERED | CHN_F_NOTRIGGER);
916 if (*arg_i & PCM_ENABLE_OUTPUT)
919 wrch->flags |= CHN_F_NOTRIGGER;
924 case SNDCTL_DSP_GETTRIGGER:
926 if (wrch && wrch->flags & CHN_F_TRIGGERED)
927 *arg_i |= PCM_ENABLE_OUTPUT;
928 if (rdch && rdch->flags & CHN_F_TRIGGERED)
929 *arg_i |= PCM_ENABLE_INPUT;
932 case SNDCTL_DSP_GETODELAY:
934 struct snd_dbuf *b = wrch->bufhard;
935 struct snd_dbuf *bs = wrch->bufsoft;
939 *arg_i = sndbuf_getready(b) + sndbuf_getready(bs);
945 case SNDCTL_DSP_POST:
948 wrch->flags &= ~CHN_F_NOTRIGGER;
954 case SNDCTL_DSP_MAPINBUF:
955 case SNDCTL_DSP_MAPOUTBUF:
956 case SNDCTL_DSP_SETSYNCRO:
959 case SNDCTL_DSP_SUBDIVIDE:
960 case SOUND_PCM_WRITE_FILTER:
961 case SOUND_PCM_READ_FILTER:
962 /* dunno what these do, don't sound important */
964 DEB(printf("default ioctl fn 0x%08lx fail\n", cmd));
968 relchns(dev, rdch, wrch, 0);
974 dsp_poll(struct dev_poll_args *ap)
976 dev_t dev = ap->a_head.a_dev;
977 struct pcm_channel *wrch = NULL, *rdch = NULL;
982 getchns(dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
985 e = (ap->a_events & (POLLOUT | POLLWRNORM));
987 ret |= chn_poll(wrch, e);
990 e = (ap->a_events & (POLLIN | POLLRDNORM));
992 ret |= chn_poll(rdch, e);
994 relchns(dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1002 dsp_mmap(struct dev_mmap_args *ap)
1004 dev_t dev = ap->a_head.a_dev;
1005 struct pcm_channel *wrch = NULL, *rdch = NULL, *c;
1008 if (ap->a_nprot & PROT_EXEC)
1012 getchns(dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1015 * XXX the linux api uses the nprot to select read/write buffer
1016 * our vm system doesn't allow this, so force write buffer
1019 if (wrch && (ap->a_nprot & PROT_WRITE)) {
1021 } else if (rdch && (ap->a_nprot & PROT_READ)) {
1032 relchns(dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1037 if (ap->a_offset >= sndbuf_getsize(c->bufsoft)) {
1038 relchns(dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1043 if (!(c->flags & CHN_F_MAPPED))
1044 c->flags |= CHN_F_MAPPED;
1046 ret = atop(vtophys(sndbuf_getbufofs(c->bufsoft, ap->a_offset)));
1047 relchns(dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
1054 dsp_register(int unit, int channel)
1056 dev_ops_add(&dsp_ops,
1057 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP, 0));
1058 dev_ops_add(&dsp_ops,
1059 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP16, 0));
1060 dev_ops_add(&dsp_ops,
1061 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_AUDIO, 0));
1062 dev_ops_add(&dsp_ops,
1063 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_NORESET, 0));
1064 make_dev(&dsp_ops, PCMMKMINOR(unit, SND_DEV_DSP, channel),
1065 UID_ROOT, GID_WHEEL, 0666, "dsp%d.%d", unit, channel);
1066 make_dev(&dsp_ops, PCMMKMINOR(unit, SND_DEV_DSP16, channel),
1067 UID_ROOT, GID_WHEEL, 0666, "dspW%d.%d", unit, channel);
1068 make_dev(&dsp_ops, PCMMKMINOR(unit, SND_DEV_AUDIO, channel),
1069 UID_ROOT, GID_WHEEL, 0666, "audio%d.%d", unit, channel);
1075 dsp_registerrec(int unit, int channel)
1077 dev_ops_add(&dsp_ops,
1078 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSPREC, 0));
1079 make_dev(&dsp_ops, PCMMKMINOR(unit, SND_DEV_DSPREC, channel),
1080 UID_ROOT, GID_WHEEL, 0666, "dspr%d.%d", unit, channel);
1086 dsp_unregister(int unit, int channel)
1088 dev_ops_remove(&dsp_ops,
1089 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP, 0));
1090 dev_ops_remove(&dsp_ops,
1091 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSP16, 0));
1092 dev_ops_remove(&dsp_ops,
1093 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_AUDIO, 0));
1094 dev_ops_remove(&dsp_ops,
1095 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_NORESET, 0));
1100 dsp_unregisterrec(int unit, int channel)
1102 dev_ops_remove(&dsp_ops,
1103 PCMMKMINOR(-1, -1, 0), PCMMKMINOR(unit, SND_DEV_DSPREC, 0));
1109 dsp_clone(void *arg, char *name, int namelen, dev_t *dev)
1112 int i, cont, unit, devtype;
1113 int devtypes[3] = {SND_DEV_DSP, SND_DEV_DSP16, SND_DEV_AUDIO};
1114 char *devnames[3] = {"dsp", "dspW", "audio"};
1118 if (pcm_devclass == NULL)
1123 for (i = 0; (i < 3) && (unit == -1); i++) {
1124 devtype = devtypes[i];
1125 if (strcmp(name, devnames[i]) == 0) {
1128 if (dev_stdclone(name, NULL, devnames[i], &unit) != 1)
1132 if (unit == -1 || unit >= devclass_get_maxunit(pcm_devclass))
1136 for (i = 0; cont; i++) {
1137 pdev = make_adhoc_dev(&dsp_ops, PCMMKMINOR(unit, devtype, i));
1138 if (pdev->si_flags & SI_NAMED) {
1139 if ((pdev->si_drv1 == NULL) && (pdev->si_drv2 == NULL)) {
1150 dsp_sysinit(void *p)
1152 dsp_ehtag = EVENTHANDLER_REGISTER(dev_clone, dsp_clone, 0, 1000);
1156 dsp_sysuninit(void *p)
1158 if (dsp_ehtag != NULL)
1159 EVENTHANDLER_DEREGISTER(dev_clone, dsp_ehtag);
1162 SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
1163 SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);