2 * Copyright (c) 1999 Cameron Grant <cg@freebsd.org>
3 * (C) 1997 Luigi Rizzo (luigi@iet.unipi.it)
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * $FreeBSD: src/sys/dev/sound/pcm/sound.c,v 1.93.2.5 2007/06/04 09:06:05 ariff Exp $
28 * $DragonFly: src/sys/dev/sound/pcm/sound.c,v 1.12 2008/01/06 16:55:51 swildner Exp $
31 #include <dev/sound/pcm/sound.h>
32 #include <dev/sound/pcm/vchan.h>
33 #include <dev/sound/pcm/dsp.h>
34 #include <sys/sysctl.h>
36 #include "feeder_if.h"
38 SND_DECLARE_FILE("$DragonFly: src/sys/dev/sound/pcm/sound.c,v 1.12 2008/01/06 16:55:51 swildner Exp $");
40 devclass_t pcm_devclass;
42 int pcm_veto_load = 1;
46 TUNABLE_INT("hw.snd.unit", &snd_unit);
49 int snd_maxautovchans = 4;
50 TUNABLE_INT("hw.snd.maxautovchans", &snd_maxautovchans);
52 SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD, 0, "Sound driver");
54 static int sndstat_prepare_pcm(struct sbuf *s, device_t dev, int verbose);
56 struct sysctl_ctx_list *
57 snd_sysctl_tree(device_t dev)
59 struct snddev_info *d = device_get_softc(dev);
61 return &d->sysctl_tree;
65 snd_sysctl_tree_top(device_t dev)
67 struct snddev_info *d = device_get_softc(dev);
69 return d->sysctl_tree_top;
73 snd_mtxcreate(const char *desc, const char *type)
78 m = kmalloc(sizeof(*m), M_DEVBUF, M_WAITOK | M_ZERO);
79 lockinit(m, __DECONST(char *, type), 0, LK_CANRECURSE);
82 return (void *)0xcafebabe;
97 snd_mtxassert(void *m)
112 lockmgr(lk, LK_EXCLUSIVE | LK_RETRY);
117 snd_mtxunlock(void *m)
122 lockmgr(lk, LK_RELEASE);
127 snd_mtxsleep(void *addr, sndlock_t lock, int flags, const char *wmesg, int timo)
131 tsleep_interlock(addr, flags);
133 r = tsleep(addr, flags | PINTERLOCKED, wmesg, timo);
141 snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
144 flags &= INTR_MPSAFE;
145 flags |= INTR_TYPE_AV;
147 flags = INTR_TYPE_AV;
149 return bus_setup_intr(dev, res, flags, hand, param, cookiep, NULL);
152 #ifndef PCM_DEBUG_MTX
154 pcm_lock(struct snddev_info *d)
156 snd_mtxlock(d->lock);
160 pcm_unlock(struct snddev_info *d)
162 snd_mtxunlock(d->lock);
167 pcm_getfakechan(struct snddev_info *d)
173 pcm_setvchans(struct snddev_info *d, int newcnt)
175 struct snddev_channel *sce = NULL;
176 struct pcm_channel *c = NULL;
177 int err = 0, vcnt, dcnt, i;
181 if (!(d->flags & SD_F_AUTOVCHAN)) {
186 vcnt = d->vchancount;
187 dcnt = d->playcount + d->reccount;
189 if (newcnt < 0 || (dcnt + newcnt) > (PCMMAXCHAN + 1)) {
197 /* add new vchans - find a parent channel first */
198 SLIST_FOREACH(sce, &d->channels, link) {
201 if (c->direction == PCMDIR_PLAY &&
202 ((c->flags & CHN_F_HAS_VCHAN) ||
204 !(c->flags & (CHN_F_BUSY | CHN_F_VIRTUAL)))))
211 c->flags |= CHN_F_BUSY;
212 while (err == 0 && newcnt > vcnt) {
213 if (dcnt > PCMMAXCHAN) {
214 device_printf(d->dev, "%s: Maximum channel reached.\n", __func__);
217 err = vchan_create(c);
221 } else if (err == E2BIG && newcnt > vcnt)
222 device_printf(d->dev, "%s: err=%d Maximum channel reached.\n", __func__, err);
225 c->flags &= ~CHN_F_BUSY;
227 } else if (newcnt < vcnt) {
228 #define ORPHAN_CDEVT(cdevt) \
229 ((cdevt) == NULL || ((cdevt)->si_drv1 == NULL && \
230 (cdevt)->si_drv2 == NULL))
231 while (err == 0 && newcnt < vcnt) {
233 SLIST_FOREACH(sce, &d->channels, link) {
236 if (c->direction == PCMDIR_PLAY &&
237 (c->flags & CHN_F_VIRTUAL) &&
239 if (!(c->flags & CHN_F_BUSY) &&
240 ORPHAN_CDEVT(sce->dsp_devt) &&
241 ORPHAN_CDEVT(sce->dspW_devt) &&
242 ORPHAN_CDEVT(sce->audio_devt) &&
243 ORPHAN_CDEVT(sce->dspr_devt))
246 * Either we're busy, or our cdev
247 * has been stolen by dsp_clone().
248 * Skip, and increase newcnt.
250 if (!(c->flags & CHN_F_BUSY))
251 device_printf(d->dev,
252 "%s: <%s> somebody steal my cdev!\n",
263 err = vchan_destroy(c);
267 device_printf(d->dev,
268 "%s: WARNING: vchan_destroy() failed!",
278 /* return error status and a locked channel */
280 pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction,
281 pid_t pid, int chnum)
283 struct pcm_channel *c;
284 struct snddev_channel *sce;
289 /* scan for a free channel */
290 SLIST_FOREACH(sce, &d->channels, link) {
293 if (c->direction == direction && !(c->flags & CHN_F_BUSY)) {
294 if (chnum < 0 || sce->chan_num == chnum) {
295 c->flags |= CHN_F_BUSY;
301 if (sce->chan_num == chnum) {
302 if (c->direction != direction)
304 else if (c->flags & CHN_F_BUSY)
310 } else if (c->direction == direction && (c->flags & CHN_F_BUSY))
315 /* no channel available */
316 if (chnum == -1 && direction == PCMDIR_PLAY && d->vchancount > 0 &&
317 d->vchancount < snd_maxautovchans &&
318 d->devcount <= PCMMAXCHAN) {
319 err = pcm_setvchans(d, d->vchancount + 1);
329 /* release a locked channel and unlock it */
331 pcm_chnrelease(struct pcm_channel *c)
334 c->flags &= ~CHN_F_BUSY;
341 pcm_chnref(struct pcm_channel *c, int ref)
352 pcm_inprog(struct snddev_info *d, int delta)
368 pcm_setmaxautovchans(struct snddev_info *d, int num)
370 if (num > 0 && d->vchancount == 0)
372 else if (num == 0 && d->vchancount > 0)
378 sysctl_hw_snd_unit(SYSCTL_HANDLER_ARGS)
380 struct snddev_info *d;
384 error = sysctl_handle_int(oidp, &unit, sizeof(unit), req);
385 if (error == 0 && req->newptr != NULL) {
386 if (unit < 0 || (pcm_devclass != NULL &&
387 unit >= devclass_get_maxunit(pcm_devclass)))
389 d = devclass_get_softc(pcm_devclass, unit);
390 if (d == NULL || SLIST_EMPTY(&d->channels))
396 SYSCTL_PROC(_hw_snd, OID_AUTO, unit, CTLTYPE_INT | CTLFLAG_RW,
397 0, sizeof(int), sysctl_hw_snd_unit, "I", "");
401 sysctl_hw_snd_maxautovchans(SYSCTL_HANDLER_ARGS)
403 struct snddev_info *d;
406 v = snd_maxautovchans;
407 error = sysctl_handle_int(oidp, &v, sizeof(v), req);
408 if (error == 0 && req->newptr != NULL) {
409 if (v < 0 || v > PCMMAXCHAN)
411 if (pcm_devclass != NULL && v != snd_maxautovchans) {
412 for (i = 0; i < devclass_get_maxunit(pcm_devclass); i++) {
413 d = devclass_get_softc(pcm_devclass, i);
416 pcm_setmaxautovchans(d, v);
419 snd_maxautovchans = v;
423 SYSCTL_PROC(_hw_snd, OID_AUTO, maxautovchans, CTLTYPE_INT | CTLFLAG_RW,
424 0, sizeof(int), sysctl_hw_snd_maxautovchans, "I", "");
427 pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo)
429 struct snddev_channel *sce;
430 struct pcm_channel *ch, *c;
432 uint32_t flsearch = 0;
433 int direction, err, rpnum, *pnum;
438 direction = PCMDIR_PLAY;
439 pnum = &d->playcount;
444 direction = PCMDIR_REC;
450 direction = PCMDIR_PLAY;
451 pnum = &d->vchancount;
452 flsearch = CHN_F_VIRTUAL;
459 ch = kmalloc(sizeof(*ch), M_DEVBUF, M_WAITOK | M_ZERO);
461 ch->methods = kobj_create(cls, M_DEVBUF, M_WAITOK);
468 snd_mtxlock(d->lock);
471 SLIST_FOREACH(sce, &d->channels, link) {
473 if (direction != c->direction ||
474 (c->flags & CHN_F_VIRTUAL) != flsearch)
476 if (ch->num == c->num)
480 device_printf(d->dev,
481 "%s: %s channel numbering screwed (Expect: %d, Got: %d)\n",
482 __func__, dirs, ch->num, c->num);
484 goto retry_num_search;
488 goto retry_num_search_out;
491 SLIST_FOREACH(sce, &d->channels, link) {
493 if (direction != c->direction ||
494 (c->flags & CHN_F_VIRTUAL) != flsearch)
496 if (ch->num == c->num) {
498 goto retry_num_search;
502 retry_num_search_out:
503 if (*pnum != rpnum) {
504 device_printf(d->dev,
505 "%s: WARNING: pnum screwed : dirs=%s, pnum=%d, rpnum=%d\n",
506 __func__, dirs, *pnum, rpnum);
510 snd_mtxunlock(d->lock);
513 ch->parentsnddev = d;
514 ch->parentchannel = parent;
516 ksnprintf(ch->name, CHN_NAMELEN, "%s:%s:%d", device_get_nameunit(ch->dev), dirs, ch->num);
518 err = chn_init(ch, devinfo, dir, direction);
520 device_printf(d->dev, "chn_init(%s) failed: err = %d\n", ch->name, err);
521 kobj_delete(ch->methods, M_DEVBUF);
523 snd_mtxlock(d->lock);
525 snd_mtxunlock(d->lock);
534 pcm_chn_iterate(struct snddev_info *d, void **cookie)
536 struct snddev_channel **last = (struct snddev_channel **)cookie;
539 *last = SLIST_FIRST(&d->channels);
541 *last = SLIST_NEXT(*last, link);
546 return (*last)->channel;
550 pcm_chn_destroy(struct pcm_channel *ch)
552 struct snddev_info *d;
555 d = ch->parentsnddev;
558 device_printf(d->dev, "chn_kill(%s) failed, err = %d\n", ch->name, err);
562 kobj_delete(ch->methods, M_DEVBUF);
569 pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
571 struct snddev_channel *sce, *tmp, *after;
573 int device = device_get_unit(d->dev);
577 * Note it's confusing nomenclature.
579 * device -> pcm_device
580 * unit -> pcm_channel
581 * channel -> snddev_channel
586 sce = kmalloc(sizeof(*sce), M_DEVBUF, M_WAITOK | M_ZERO);
588 snd_mtxlock(d->lock);
593 SLIST_FOREACH(tmp, &d->channels, link) {
594 if (sce->chan_num == tmp->chan_num)
598 device_printf(d->dev,
599 "%s: cdev numbering screwed (Expect: %d, Got: %d)\n",
600 __func__, sce->chan_num, tmp->chan_num);
602 goto retry_chan_num_search;
607 goto retry_chan_num_search_out;
608 retry_chan_num_search:
610 * Look for possible channel numbering collision. This may not
611 * be optimized, but it will ensure that no collision occured.
612 * Can be considered cheap since none of the locking/unlocking
613 * operations involved.
617 SLIST_FOREACH(tmp, &d->channels, link) {
618 if (sce->chan_num == tmp->chan_num) {
620 goto retry_chan_num_search;
622 if (sce->chan_num > tmp->chan_num)
626 retry_chan_num_search_out:
628 * Don't overflow PCMMKMINOR / PCMMAXCHAN.
630 if (sce->chan_num > PCMMAXCHAN) {
631 snd_mtxunlock(d->lock);
632 device_printf(d->dev,
633 "%s: WARNING: sce->chan_num overflow! (%d)\n",
634 __func__, sce->chan_num);
635 kfree(sce, M_DEVBUF);
638 if (d->devcount != rdevcount) {
639 device_printf(d->dev,
640 "%s: WARNING: devcount screwed! d->devcount=%u, rdevcount=%u\n",
641 __func__, d->devcount, rdevcount);
642 d->devcount = rdevcount;
646 SLIST_INSERT_HEAD(&d->channels, sce, link);
648 SLIST_INSERT_AFTER(after, sce, link);
653 SLIST_FOREACH(tmp, &d->channels, link) {
654 if (cnum != tmp->chan_num)
655 device_printf(d->dev,
656 "%s: WARNING: inconsistent cdev numbering! (Expect: %d, Got: %d)\n",
657 __func__, cnum, tmp->chan_num);
663 namelen = strlen(ch->name);
664 if ((CHN_NAMELEN - namelen) > 10) { /* ":dspXX.YYY" */
665 ksnprintf(ch->name + namelen,
666 CHN_NAMELEN - namelen, ":dsp%d.%d",
667 device, sce->chan_num);
669 snd_mtxunlock(d->lock);
672 * I will revisit these someday, and nuke it mercilessly..
674 sce->dsp_devt = make_dev(&dsp_cdevsw,
675 PCMMKMINOR(device, SND_DEV_DSP, sce->chan_num),
676 UID_ROOT, GID_WHEEL, 0666, "dsp%d.%d",
677 device, sce->chan_num);
678 reference_dev(sce->dsp_devt);
680 sce->dspW_devt = make_dev(&dsp_cdevsw,
681 PCMMKMINOR(device, SND_DEV_DSP16, sce->chan_num),
682 UID_ROOT, GID_WHEEL, 0666, "dspW%d.%d",
683 device, sce->chan_num);
684 reference_dev(sce->dspW_devt);
686 sce->audio_devt = sce->dsp_devt;
687 reference_dev(sce->audio_devt);
689 if (ch->direction == PCMDIR_REC) {
690 sce->dspr_devt = make_dev(&dsp_cdevsw,
691 PCMMKMINOR(device, SND_DEV_DSPREC,
692 sce->chan_num), UID_ROOT, GID_WHEEL,
693 0666, "dspr%d.%d", device, sce->chan_num);
694 reference_dev(sce->dspr_devt);
701 pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch)
703 struct snddev_channel *sce;
708 if (!mtx_owned(d->lock)) {
709 snd_mtxlock(d->lock);
714 SLIST_FOREACH(sce, &d->channels, link) {
715 if (sce->channel == ch)
720 snd_mtxunlock(d->lock);
724 SLIST_REMOVE(&d->channels, sce, snddev_channel, link);
726 if (ch->flags & CHN_F_VIRTUAL)
728 else if (ch->direction == PCMDIR_REC)
735 snd_mtxunlock(d->lock);
737 kfree(sce, M_DEVBUF);
743 pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
745 struct snddev_info *d = device_get_softc(dev);
746 struct pcm_channel *ch;
749 ch = pcm_chn_create(d, NULL, cls, dir, devinfo);
751 device_printf(d->dev, "pcm_chn_create(%s, %d, %p) failed\n", cls->name, dir, devinfo);
755 err = pcm_chn_add(d, ch);
757 device_printf(d->dev, "pcm_chn_add(%s) failed, err=%d\n", ch->name, err);
766 pcm_killchan(device_t dev)
768 struct snddev_info *d = device_get_softc(dev);
769 struct snddev_channel *sce;
770 struct pcm_channel *ch;
773 sce = SLIST_FIRST(&d->channels);
776 error = pcm_chn_remove(d, sce->channel);
779 return (pcm_chn_destroy(ch));
783 pcm_setstatus(device_t dev, char *str)
785 struct snddev_info *d = device_get_softc(dev);
787 snd_mtxlock(d->lock);
788 strncpy(d->status, str, SND_STATUSLEN);
789 snd_mtxunlock(d->lock);
790 if (snd_maxautovchans > 0)
796 pcm_getflags(device_t dev)
798 struct snddev_info *d = device_get_softc(dev);
804 pcm_setflags(device_t dev, uint32_t val)
806 struct snddev_info *d = device_get_softc(dev);
812 pcm_getdevinfo(device_t dev)
814 struct snddev_info *d = device_get_softc(dev);
820 pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max)
822 struct snddev_info *d = device_get_softc(dev);
826 if (resource_int_value(device_get_name(dev), device_get_unit(dev), "buffersize", &sz) == 0) {
830 device_printf(dev, "'buffersize=%d' hint is out of range (%d-%d), using %d\n", x, min, max, sz);
837 device_printf(dev, "'buffersize=%d' hint is not a power of 2, using %d\n", sz, x);
850 pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
852 struct snddev_info *d = device_get_softc(dev);
855 device_printf(dev, "disabled due to an error while initialising: %d\n", pcm_veto_load);
860 d->lock = snd_mtxcreate(device_get_nameunit(dev), "sound cdev");
864 * d->flags should be cleared by the allocator of the softc.
865 * We cannot clear this field here because several devices set
866 * this flag before calling pcm_register().
871 d->devinfo = devinfo;
878 SLIST_INIT(&d->channels);
880 if ((numplay == 0 || numrec == 0) && numplay != numrec)
881 d->flags |= SD_F_SIMPLEX;
883 d->fakechan = fkchan_setup(dev);
884 chn_init(d->fakechan, NULL, 0, 0);
887 sysctl_ctx_init(&d->sysctl_tree);
888 d->sysctl_tree_top = SYSCTL_ADD_NODE(&d->sysctl_tree,
889 SYSCTL_STATIC_CHILDREN(_hw_snd), OID_AUTO,
890 device_get_nameunit(dev), CTLFLAG_RD, 0, "");
891 if (d->sysctl_tree_top == NULL) {
892 sysctl_ctx_free(&d->sysctl_tree);
895 SYSCTL_ADD_INT(snd_sysctl_tree(dev), SYSCTL_CHILDREN(snd_sysctl_tree_top(dev)),
896 OID_AUTO, "buffersize", CTLFLAG_RD, &d->bufsz, 0, "");
899 d->flags |= SD_F_AUTOVCHAN;
903 sndstat_register(dev, d->status, sndstat_prepare_pcm);
906 snd_mtxfree(d->lock);
911 pcm_unregister(device_t dev)
913 struct snddev_info *d = device_get_softc(dev);
914 struct snddev_channel *sce;
915 struct pcmchan_children *pce;
916 struct pcm_channel *ch;
918 if (sndstat_acquire() != 0) {
919 device_printf(dev, "unregister: sndstat busy\n");
923 snd_mtxlock(d->lock);
925 device_printf(dev, "unregister: operation in progress\n");
926 snd_mtxunlock(d->lock);
931 SLIST_FOREACH(sce, &d->channels, link) {
933 if (ch->refcount > 0) {
934 device_printf(dev, "unregister: channel %s busy (pid %d)\n", ch->name, ch->pid);
935 snd_mtxunlock(d->lock);
941 if (mixer_uninit(dev) == EBUSY) {
942 device_printf(dev, "unregister: mixer busy\n");
943 snd_mtxunlock(d->lock);
948 SLIST_FOREACH(sce, &d->channels, link) {
949 int unit = device_get_unit(d->dev);
952 release_dev(sce->dsp_devt);
953 kprintf("devfs: Please check that only the correct dsp devices were removed!!!\n");
954 dev_ops_remove_minor(&dsp_cdevsw,
955 /*PCMMKMINOR(-1, -1, 0),*/
956 PCMMKMINOR(unit, SND_DEV_DSP, sce->chan_num));
957 sce->dsp_devt = NULL;
959 if (sce->dspW_devt) {
960 release_dev(sce->dspW_devt);
961 kprintf("devfs: Please check that only the correct dspW devices were removed!!!\n");
962 dev_ops_remove_minor(&dsp_cdevsw,
963 /*PCMMKMINOR(-1, -1, 0),*/
964 PCMMKMINOR(unit, SND_DEV_DSP16, sce->chan_num));
965 sce->dspW_devt = NULL;
967 if (sce->audio_devt) {
968 release_dev(sce->audio_devt);
970 dev_ops_remove(&dsp_cdevsw,
971 PCMMKMINOR(-1, -1, 0),
972 PCMMKMINOR(unit, SND_DEV_DSP16, sce->chan_num));
974 sce->audio_devt = NULL;
976 if (sce->dspr_devt) {
977 release_dev(sce->dspr_devt);
978 kprintf("devfs: Please check that only the correct dspr devices were removed!!!!\n");
979 dev_ops_remove_minor(&dsp_cdevsw,
980 /*PCMMKMINOR(-1, -1, 0),*/
981 PCMMKMINOR(unit, SND_DEV_DSPREC, sce->chan_num));
982 sce->dspr_devt = NULL;
988 pce = SLIST_FIRST(&ch->children);
989 while (pce != NULL) {
991 device_printf(d->dev, "<%s> removing <%s>\n",
992 ch->name, (pce->channel != NULL) ?
993 pce->channel->name : "unknown");
995 SLIST_REMOVE(&ch->children, pce, pcmchan_children, link);
996 kfree(pce, M_DEVBUF);
997 pce = SLIST_FIRST(&ch->children);
1001 #ifdef SND_DYNSYSCTL
1002 d->sysctl_tree_top = NULL;
1003 sysctl_ctx_free(&d->sysctl_tree);
1007 SLIST_FOREACH(sce, &d->channels, link) {
1011 if (!SLIST_EMPTY(&ch->children))
1012 device_printf(d->dev, "%s: WARNING: <%s> dangling child!\n",
1013 __func__, ch->name);
1016 while (!SLIST_EMPTY(&d->channels))
1019 chn_kill(d->fakechan);
1020 fkchan_kill(d->fakechan);
1023 device_printf(d->dev, "%s: devcount=%u, playcount=%u, "
1024 "reccount=%u, vchancount=%u\n",
1025 __func__, d->devcount, d->playcount, d->reccount,
1028 snd_mtxunlock(d->lock);
1029 snd_mtxfree(d->lock);
1030 sndstat_unregister(dev);
1035 /************************************************************************/
1038 sndstat_prepare_pcm(struct sbuf *s, device_t dev, int verbose)
1040 struct snddev_info *d;
1041 struct snddev_channel *sce;
1042 struct pcm_channel *c;
1043 struct pcm_feeder *f;
1049 d = device_get_softc(dev);
1053 snd_mtxlock(d->lock);
1054 if (!SLIST_EMPTY(&d->channels)) {
1056 SLIST_FOREACH(sce, &d->channels, link) {
1058 if (c->direction == PCMDIR_PLAY) {
1059 if (c->flags & CHN_F_VIRTUAL)
1066 sbuf_printf(s, " (%dp/%dr/%dv channels%s%s)", d->playcount, d->reccount, d->vchancount,
1067 (d->flags & SD_F_SIMPLEX)? "" : " duplex",
1069 (device_get_unit(dev) == snd_unit)? " default" : ""
1076 snd_mtxunlock(d->lock);
1080 SLIST_FOREACH(sce, &d->channels, link) {
1083 KASSERT(c->bufhard != NULL && c->bufsoft != NULL,
1084 ("hosed pcm channel setup"));
1086 sbuf_printf(s, "\n\t");
1088 /* it would be better to indent child channels */
1089 sbuf_printf(s, "%s[%s]: ", c->parentchannel? c->parentchannel->name : "", c->name);
1090 sbuf_printf(s, "spd %d", c->speed);
1091 if (c->speed != sndbuf_getspd(c->bufhard))
1092 sbuf_printf(s, "/%d", sndbuf_getspd(c->bufhard));
1093 sbuf_printf(s, ", fmt 0x%08x", c->format);
1094 if (c->format != sndbuf_getfmt(c->bufhard))
1095 sbuf_printf(s, "/0x%08x", sndbuf_getfmt(c->bufhard));
1096 sbuf_printf(s, ", flags 0x%08x, 0x%08x", c->flags, c->feederflags);
1098 sbuf_printf(s, ", pid %d", c->pid);
1099 sbuf_printf(s, "\n\t");
1101 sbuf_printf(s, "interrupts %d, ", c->interrupts);
1102 if (c->direction == PCMDIR_REC)
1103 sbuf_printf(s, "overruns %d, hfree %d, sfree %d [b:%d/%d/%d|bs:%d/%d/%d]",
1104 c->xruns, sndbuf_getfree(c->bufhard), sndbuf_getfree(c->bufsoft),
1105 sndbuf_getsize(c->bufhard), sndbuf_getblksz(c->bufhard),
1106 sndbuf_getblkcnt(c->bufhard),
1107 sndbuf_getsize(c->bufsoft), sndbuf_getblksz(c->bufsoft),
1108 sndbuf_getblkcnt(c->bufsoft));
1110 sbuf_printf(s, "underruns %d, ready %d [b:%d/%d/%d|bs:%d/%d/%d]",
1111 c->xruns, sndbuf_getready(c->bufsoft),
1112 sndbuf_getsize(c->bufhard), sndbuf_getblksz(c->bufhard),
1113 sndbuf_getblkcnt(c->bufhard),
1114 sndbuf_getsize(c->bufsoft), sndbuf_getblksz(c->bufsoft),
1115 sndbuf_getblkcnt(c->bufsoft));
1116 sbuf_printf(s, "\n\t");
1118 sbuf_printf(s, "{%s}", (c->direction == PCMDIR_REC)? "hardware" : "userland");
1119 sbuf_printf(s, " -> ");
1121 while (f->source != NULL)
1124 sbuf_printf(s, "%s", f->class->name);
1125 if (f->desc->type == FEEDER_FMT)
1126 sbuf_printf(s, "(0x%08x -> 0x%08x)", f->desc->in, f->desc->out);
1127 if (f->desc->type == FEEDER_RATE)
1128 sbuf_printf(s, "(%d -> %d)", FEEDER_GET(f, FEEDRATE_SRC), FEEDER_GET(f, FEEDRATE_DST));
1129 if (f->desc->type == FEEDER_ROOT || f->desc->type == FEEDER_MIXER ||
1130 f->desc->type == FEEDER_VOLUME)
1131 sbuf_printf(s, "(0x%08x)", f->desc->out);
1132 sbuf_printf(s, " -> ");
1135 sbuf_printf(s, "{%s}", (c->direction == PCMDIR_REC)? "userland" : "hardware");
1138 sbuf_printf(s, " (mixer only)");
1139 snd_mtxunlock(d->lock);
1144 /************************************************************************/
1146 #ifdef SND_DYNSYSCTL
1148 sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS)
1150 struct snddev_info *d;
1155 newcnt = d->vchancount;
1156 err = sysctl_handle_int(oidp, &newcnt, sizeof(newcnt), req);
1158 if (err == 0 && req->newptr != NULL && d->vchancount != newcnt)
1159 err = pcm_setvchans(d, newcnt);
1165 /************************************************************************/
1168 sound_modevent(module_t mod, int type, void *data)
1171 return (midi_modevent(mod, type, data));
1177 DEV_MODULE(sound, sound_modevent, NULL);
1178 MODULE_VERSION(sound, SOUND_MODVER);