FreeBSD kernel sound device code
sound.c
Go to the documentation of this file.
1/*-
2 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
3 *
4 * Copyright (c) 2005-2009 Ariff Abdullah <ariff@FreeBSD.org>
5 * Portions Copyright (c) Ryan Beasley <ryan.beasley@gmail.com> - GSoC 2006
6 * Copyright (c) 1999 Cameron Grant <cg@FreeBSD.org>
7 * Copyright (c) 1997 Luigi Rizzo
8 * All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 * SUCH DAMAGE.
30 */
31
32#ifdef HAVE_KERNEL_OPTION_HEADERS
33#include "opt_snd.h"
34#endif
35
36#include <dev/sound/pcm/sound.h>
37#include <dev/sound/pcm/ac97.h>
38#include <dev/sound/pcm/vchan.h>
39#include <dev/sound/pcm/dsp.h>
41#include <dev/sound/version.h>
42#include <sys/limits.h>
43#include <sys/sysctl.h>
44
45#include "feeder_if.h"
46
47SND_DECLARE_FILE("$FreeBSD$");
48
49devclass_t pcm_devclass;
50
52
53int snd_unit = -1;
54
55static int snd_unit_auto = -1;
56SYSCTL_INT(_hw_snd, OID_AUTO, default_auto, CTLFLAG_RWTUN,
57 &snd_unit_auto, 0, "assign default unit to a newly attached device");
58
60
61SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD | CTLFLAG_MPSAFE, 0,
62 "Sound driver");
63
64static void pcm_sysinit(device_t);
65
66/*
67 * XXX I've had enough with people not telling proper version/arch
68 * while reporting problems, not after 387397913213th questions/requests.
69 */
70static char snd_driver_version[] =
71 __XSTRING(SND_DRV_VERSION)"/"MACHINE_ARCH;
72SYSCTL_STRING(_hw_snd, OID_AUTO, version, CTLFLAG_RD, &snd_driver_version,
73 0, "driver version/arch");
74
78struct unrhdr *pcmsg_unrhdr = NULL;
79
80static int
82{
85}
86
87void *
88snd_mtxcreate(const char *desc, const char *type)
89{
90 struct mtx *m;
91
92 m = malloc(sizeof(*m), M_DEVBUF, M_WAITOK | M_ZERO);
93 mtx_init(m, desc, type, MTX_DEF);
94 return m;
95}
96
97void
99{
100 struct mtx *mtx = m;
101
102 mtx_destroy(mtx);
103 free(mtx, M_DEVBUF);
104}
105
106void
108{
109#ifdef INVARIANTS
110 struct mtx *mtx = m;
111
112 mtx_assert(mtx, MA_OWNED);
113#endif
114}
115
116int
117snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
118{
119 struct snddev_info *d;
120
121 flags &= INTR_MPSAFE;
122 flags |= INTR_TYPE_AV;
123 d = device_get_softc(dev);
124 if (d != NULL && (flags & INTR_MPSAFE))
125 d->flags |= SD_F_MPSAFE;
126
127 return bus_setup_intr(dev, res, flags, NULL, hand, param, cookiep);
128}
129
130static void
132{
133 int cmax;
134
136
137 cmax = d->playcount + d->reccount - 1;
138 if (d->pvchancount > 0)
139 cmax += max(d->pvchancount, snd_maxautovchans) - 1;
140 if (d->rvchancount > 0)
141 cmax += max(d->rvchancount, snd_maxautovchans) - 1;
142 if (cmax > PCMMAXCLONE)
143 cmax = PCMMAXCLONE;
144 (void)snd_clone_gc(d->clones);
145 (void)snd_clone_setmaxunit(d->clones, cmax);
146}
147
148int
149pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num)
150{
151 struct pcm_channel *c, *ch, *nch;
152 struct pcmchan_caps *caps;
153 int i, err, vcnt;
154
156
157 if ((direction == PCMDIR_PLAY && d->playcount < 1) ||
158 (direction == PCMDIR_REC && d->reccount < 1))
159 return (ENODEV);
160
161 if (!(d->flags & SD_F_AUTOVCHAN))
162 return (EINVAL);
163
164 if (newcnt < 0 || newcnt > SND_MAXVCHANS)
165 return (E2BIG);
166
167 if (direction == PCMDIR_PLAY)
168 vcnt = d->pvchancount;
169 else if (direction == PCMDIR_REC)
170 vcnt = d->rvchancount;
171 else
172 return (EINVAL);
173
174 if (newcnt > vcnt) {
175 KASSERT(num == -1 ||
176 (num >= 0 && num < SND_MAXVCHANS && (newcnt - 1) == vcnt),
177 ("bogus vchan_create() request num=%d newcnt=%d vcnt=%d",
178 num, newcnt, vcnt));
179 /* add new vchans - find a parent channel first */
180 ch = NULL;
181 CHN_FOREACH(c, d, channels.pcm) {
182 CHN_LOCK(c);
183 if (c->direction == direction &&
184 ((c->flags & CHN_F_HAS_VCHAN) || (vcnt == 0 &&
185 c->refcount < 1 &&
186 !(c->flags & (CHN_F_BUSY | CHN_F_VIRTUAL))))) {
187 /*
188 * Reuse hw channel with vchans already
189 * created.
190 */
191 if (c->flags & CHN_F_HAS_VCHAN) {
192 ch = c;
193 break;
194 }
195 /*
196 * No vchans ever created, look for
197 * channels with supported formats.
198 */
199 caps = chn_getcaps(c);
200 if (caps == NULL) {
201 CHN_UNLOCK(c);
202 continue;
203 }
204 for (i = 0; caps->fmtlist[i] != 0; i++) {
205 if (caps->fmtlist[i] & AFMT_CONVERTIBLE)
206 break;
207 }
208 if (caps->fmtlist[i] != 0) {
209 ch = c;
210 break;
211 }
212 }
213 CHN_UNLOCK(c);
214 }
215 if (ch == NULL)
216 return (EBUSY);
217 ch->flags |= CHN_F_BUSY;
218 err = 0;
219 while (err == 0 && newcnt > vcnt) {
220 err = vchan_create(ch, num);
221 if (err == 0)
222 vcnt++;
223 else if (err == E2BIG && newcnt > vcnt)
224 device_printf(d->dev,
225 "%s: err=%d Maximum channel reached.\n",
226 __func__, err);
227 }
228 if (vcnt == 0)
229 ch->flags &= ~CHN_F_BUSY;
230 CHN_UNLOCK(ch);
231 if (err != 0)
232 return (err);
233 else
235 } else if (newcnt < vcnt) {
236 KASSERT(num == -1,
237 ("bogus vchan_destroy() request num=%d", num));
238 CHN_FOREACH(c, d, channels.pcm) {
239 CHN_LOCK(c);
240 if (c->direction != direction ||
241 CHN_EMPTY(c, children) ||
242 !(c->flags & CHN_F_HAS_VCHAN)) {
243 CHN_UNLOCK(c);
244 continue;
245 }
246 CHN_FOREACH_SAFE(ch, c, nch, children) {
247 CHN_LOCK(ch);
248 if (vcnt == 1 && c->refcount > 0) {
249 CHN_UNLOCK(ch);
250 break;
251 }
252 if (!(ch->flags & CHN_F_BUSY) &&
253 ch->refcount < 1) {
254 err = vchan_destroy(ch);
255 if (err == 0)
256 vcnt--;
257 } else
258 CHN_UNLOCK(ch);
259 if (vcnt == newcnt)
260 break;
261 }
262 CHN_UNLOCK(c);
263 break;
264 }
266 }
267
268 return (0);
269}
270
271/* return error status and a locked channel */
272int
273pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction,
274 pid_t pid, char *comm, int devunit)
275{
276 struct pcm_channel *c;
277 int err, vchancount, vchan_num;
278
279 KASSERT(d != NULL && ch != NULL && (devunit == -1 ||
280 !(devunit & ~(SND_U_MASK | SND_D_MASK | SND_C_MASK))) &&
282 ("%s(): invalid d=%p ch=%p direction=%d pid=%d devunit=%d",
283 __func__, d, ch, direction, pid, devunit));
285
286 /* Double check again. */
287 if (devunit != -1) {
288 switch (snd_unit2d(devunit)) {
291 if (direction != PCMDIR_PLAY)
292 return (ENOTSUP);
293 break;
296 if (direction != PCMDIR_REC)
297 return (ENOTSUP);
298 break;
299 default:
300 if (!(direction == PCMDIR_PLAY ||
302 return (ENOTSUP);
303 break;
304 }
305 }
306
307 *ch = NULL;
308 vchan_num = 0;
309 vchancount = (direction == PCMDIR_PLAY) ? d->pvchancount :
310 d->rvchancount;
311
312retry_chnalloc:
313 err = ENOTSUP;
314 /* scan for a free channel */
315 CHN_FOREACH(c, d, channels.pcm) {
316 CHN_LOCK(c);
317 if (devunit == -1 && c->direction == direction &&
318 (c->flags & CHN_F_VIRTUAL)) {
319 if (vchancount < snd_maxautovchans &&
320 vchan_num < CHN_CHAN(c)) {
321 CHN_UNLOCK(c);
322 goto vchan_alloc;
323 }
324 vchan_num++;
325 }
326 if (c->direction == direction && !(c->flags & CHN_F_BUSY) &&
327 (devunit == -1 || devunit == -2 || c->unit == devunit)) {
328 c->flags |= CHN_F_BUSY;
329 c->pid = pid;
330 strlcpy(c->comm, (comm != NULL) ? comm :
331 CHN_COMM_UNKNOWN, sizeof(c->comm));
332 *ch = c;
333 return (0);
334 } else if (c->unit == devunit) {
335 if (c->direction != direction)
336 err = ENOTSUP;
337 else if (c->flags & CHN_F_BUSY)
338 err = EBUSY;
339 else
340 err = EINVAL;
341 CHN_UNLOCK(c);
342 return (err);
343 } else if ((devunit == -1 || devunit == -2) &&
345 err = EBUSY;
346 CHN_UNLOCK(c);
347 }
348
349 if (devunit == -2)
350 return (err);
351
352vchan_alloc:
353 /* no channel available */
354 if (devunit == -1 || snd_unit2d(devunit) == SND_DEV_DSPHW_VPLAY ||
355 snd_unit2d(devunit) == SND_DEV_DSPHW_VREC) {
356 if (!(vchancount > 0 && vchancount < snd_maxautovchans) &&
357 (devunit == -1 || snd_unit2c(devunit) < snd_maxautovchans))
358 return (err);
359 err = pcm_setvchans(d, direction, vchancount + 1,
360 (devunit == -1) ? -1 : snd_unit2c(devunit));
361 if (err == 0) {
362 if (devunit == -1)
363 devunit = -2;
364 goto retry_chnalloc;
365 }
366 }
367
368 return (err);
369}
370
371/* release a locked channel and unlock it */
372int
374{
377
378 c->flags &= ~CHN_F_BUSY;
379 c->pid = -1;
380 strlcpy(c->comm, CHN_COMM_UNUSED, sizeof(c->comm));
381 CHN_UNLOCK(c);
382
383 return (0);
384}
385
386int
387pcm_chnref(struct pcm_channel *c, int ref)
388{
391
392 c->refcount += ref;
393
394 return (c->refcount);
395}
396
397int
398pcm_inprog(struct snddev_info *d, int delta)
399{
401
402 d->inprog += delta;
403
404 return (d->inprog);
405}
406
407static void
409{
411
412 if (num < 0)
413 return;
414
415 if (num >= 0 && d->pvchancount > num)
416 (void)pcm_setvchans(d, PCMDIR_PLAY, num, -1);
417 else if (num > 0 && d->pvchancount == 0)
418 (void)pcm_setvchans(d, PCMDIR_PLAY, 1, -1);
419
420 if (num >= 0 && d->rvchancount > num)
421 (void)pcm_setvchans(d, PCMDIR_REC, num, -1);
422 else if (num > 0 && d->rvchancount == 0)
423 (void)pcm_setvchans(d, PCMDIR_REC, 1, -1);
424
426}
427
428static int
429sysctl_hw_snd_default_unit(SYSCTL_HANDLER_ARGS)
430{
431 struct snddev_info *d;
432 int error, unit;
433
434 unit = snd_unit;
435 error = sysctl_handle_int(oidp, &unit, 0, req);
436 if (error == 0 && req->newptr != NULL) {
437 d = devclass_get_softc(pcm_devclass, unit);
438 if (!PCM_REGISTERED(d) || CHN_EMPTY(d, channels.pcm))
439 return EINVAL;
440 snd_unit = unit;
441 snd_unit_auto = 0;
442 }
443 return (error);
444}
445/* XXX: do we need a way to let the user change the default unit? */
446SYSCTL_PROC(_hw_snd, OID_AUTO, default_unit,
447 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_ANYBODY | CTLFLAG_NEEDGIANT, 0,
448 sizeof(int), sysctl_hw_snd_default_unit, "I",
449 "default sound device");
450
451static int
452sysctl_hw_snd_maxautovchans(SYSCTL_HANDLER_ARGS)
453{
454 struct snddev_info *d;
455 int i, v, error;
456
458 error = sysctl_handle_int(oidp, &v, 0, req);
459 if (error == 0 && req->newptr != NULL) {
460 if (v < 0)
461 v = 0;
462 if (v > SND_MAXVCHANS)
463 v = SND_MAXVCHANS;
465 for (i = 0; pcm_devclass != NULL &&
466 i < devclass_get_maxunit(pcm_devclass); i++) {
467 d = devclass_get_softc(pcm_devclass, i);
468 if (!PCM_REGISTERED(d))
469 continue;
473 }
474 }
475 return (error);
476}
477SYSCTL_PROC(_hw_snd, OID_AUTO, maxautovchans,
478 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
480 "maximum virtual channel");
481
482struct pcm_channel *
483pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo)
484{
485 struct pcm_channel *ch;
486 int direction, err, rpnum, *pnum, max;
487 int udc, device, chan;
488 char *dirs, *devname, buf[CHN_NAMELEN];
489
492 KASSERT(num >= -1, ("invalid num=%d", num));
493
494 switch (dir) {
495 case PCMDIR_PLAY:
496 dirs = "play";
498 pnum = &d->playcount;
499 device = SND_DEV_DSPHW_PLAY;
501 break;
503 dirs = "virtual";
505 pnum = &d->pvchancount;
506 device = SND_DEV_DSPHW_VPLAY;
508 break;
509 case PCMDIR_REC:
510 dirs = "record";
512 pnum = &d->reccount;
513 device = SND_DEV_DSPHW_REC;
515 break;
517 dirs = "virtual";
519 pnum = &d->rvchancount;
520 device = SND_DEV_DSPHW_VREC;
522 break;
523 default:
524 return (NULL);
525 }
526
527 chan = (num == -1) ? 0 : num;
528
529 if (*pnum >= max || chan >= max)
530 return (NULL);
531
532 rpnum = 0;
533
534 CHN_FOREACH(ch, d, channels.pcm) {
535 if (CHN_DEV(ch) != device)
536 continue;
537 if (chan == CHN_CHAN(ch)) {
538 if (num != -1) {
539 device_printf(d->dev,
540 "channel num=%d allocated!\n", chan);
541 return (NULL);
542 }
543 chan++;
544 if (chan >= max) {
545 device_printf(d->dev,
546 "chan=%d > %d\n", chan, max);
547 return (NULL);
548 }
549 }
550 rpnum++;
551 }
552
553 if (*pnum != rpnum) {
554 device_printf(d->dev,
555 "%s(): WARNING: pnum screwed : dirs=%s pnum=%d rpnum=%d\n",
556 __func__, dirs, *pnum, rpnum);
557 return (NULL);
558 }
559
560 udc = snd_mkunit(device_get_unit(d->dev), device, chan);
561 devname = dsp_unit2name(buf, sizeof(buf), udc);
562
563 if (devname == NULL) {
564 device_printf(d->dev,
565 "Failed to query device name udc=0x%08x\n", udc);
566 return (NULL);
567 }
568
569 PCM_UNLOCK(d);
570 ch = malloc(sizeof(*ch), M_DEVBUF, M_WAITOK | M_ZERO);
571 ch->methods = kobj_create(cls, M_DEVBUF, M_WAITOK | M_ZERO);
572 ch->unit = udc;
573 ch->pid = -1;
574 strlcpy(ch->comm, CHN_COMM_UNUSED, sizeof(ch->comm));
575 ch->parentsnddev = d;
576 ch->parentchannel = parent;
577 ch->dev = d->dev;
578 ch->trigger = PCMTRIG_STOP;
579 snprintf(ch->name, sizeof(ch->name), "%s:%s:%s",
580 device_get_nameunit(ch->dev), dirs, devname);
581
582 err = chn_init(ch, devinfo, dir, direction);
583 PCM_LOCK(d);
584 if (err) {
585 device_printf(d->dev, "chn_init(%s) failed: err = %d\n",
586 ch->name, err);
587 kobj_delete(ch->methods, M_DEVBUF);
588 free(ch, M_DEVBUF);
589 return (NULL);
590 }
591
592 return (ch);
593}
594
595int
597{
598 struct snddev_info *d __diagused;
599 int err;
600
601 d = ch->parentsnddev;
603
604 err = chn_kill(ch);
605 if (err) {
606 device_printf(ch->dev, "chn_kill(%s) failed, err = %d\n",
607 ch->name, err);
608 return (err);
609 }
610
611 kobj_delete(ch->methods, M_DEVBUF);
612 free(ch, M_DEVBUF);
613
614 return (0);
615}
616
617int
618pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
619{
622 KASSERT(ch != NULL && (ch->direction == PCMDIR_PLAY ||
623 ch->direction == PCMDIR_REC), ("Invalid pcm channel"));
624
626
627 switch (CHN_DEV(ch)) {
629 d->playcount++;
630 break;
632 d->pvchancount++;
633 break;
635 d->reccount++;
636 break;
638 d->rvchancount++;
639 break;
640 default:
641 break;
642 }
643
644 d->devcount++;
645
646 return (0);
647}
648
649int
651{
652 struct pcm_channel *tmp;
653
656
657 tmp = NULL;
658
659 CHN_FOREACH(tmp, d, channels.pcm) {
660 if (tmp == ch)
661 break;
662 }
663
664 if (tmp != ch)
665 return (EINVAL);
666
667 CHN_REMOVE(d, ch, channels.pcm);
668
669 switch (CHN_DEV(ch)) {
671 d->playcount--;
672 break;
674 d->pvchancount--;
675 break;
677 d->reccount--;
678 break;
680 d->rvchancount--;
681 break;
682 default:
683 break;
684 }
685
686 d->devcount--;
687
688 return (0);
689}
690
691int
692pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
693{
694 struct snddev_info *d = device_get_softc(dev);
695 struct pcm_channel *ch;
696 int err;
697
699
700 PCM_LOCK(d);
701 ch = pcm_chn_create(d, NULL, cls, dir, -1, devinfo);
702 if (!ch) {
703 device_printf(d->dev, "pcm_chn_create(%s, %d, %p) failed\n",
704 cls->name, dir, devinfo);
705 PCM_UNLOCK(d);
706 return (ENODEV);
707 }
708
709 err = pcm_chn_add(d, ch);
710 PCM_UNLOCK(d);
711 if (err) {
712 device_printf(d->dev, "pcm_chn_add(%s) failed, err=%d\n",
713 ch->name, err);
714 pcm_chn_destroy(ch);
715 }
716
717 return (err);
718}
719
720static int
722{
723 struct snddev_info *d = device_get_softc(dev);
724 struct pcm_channel *ch;
725 int error;
726
728
729 ch = CHN_FIRST(d, channels.pcm);
730
731 PCM_LOCK(d);
732 error = pcm_chn_remove(d, ch);
733 PCM_UNLOCK(d);
734 if (error)
735 return (error);
736 return (pcm_chn_destroy(ch));
737}
738
739static int
741{
742 struct snddev_info *d;
743 int i, best, bestprio, prio;
744
745 best = -1;
746 bestprio = -100;
747 for (i = 0; pcm_devclass != NULL &&
748 i < devclass_get_maxunit(pcm_devclass); i++) {
749 d = devclass_get_softc(pcm_devclass, i);
750 if (!PCM_REGISTERED(d))
751 continue;
752 prio = 0;
753 if (d->playcount == 0)
754 prio -= 10;
755 if (d->reccount == 0)
756 prio -= 2;
757 if (prio > bestprio || (prio == bestprio && i == old)) {
758 best = i;
759 bestprio = prio;
760 }
761 }
762 return (best);
763}
764
765int
766pcm_setstatus(device_t dev, char *str)
767{
768 struct snddev_info *d = device_get_softc(dev);
769
770 /* should only be called once */
771 if (d->flags & SD_F_REGISTERED)
772 return (EINVAL);
773
775
776 if (d->playcount == 0 || d->reccount == 0)
777 d->flags |= SD_F_SIMPLEX;
778
779 if (d->playcount > 0 || d->reccount > 0)
780 d->flags |= SD_F_AUTOVCHAN;
781
783
784 strlcpy(d->status, str, SND_STATUSLEN);
785
786 PCM_LOCK(d);
787
788 /* Last stage, enable cloning. */
789 if (d->clones != NULL)
790 (void)snd_clone_enable(d->clones);
791
792 /* Done, we're ready.. */
794
795 PCM_RELEASE(d);
796
797 PCM_UNLOCK(d);
798
799 /*
800 * Create all sysctls once SD_F_REGISTERED is set else
801 * tunable sysctls won't work:
802 */
804
805 if (snd_unit_auto < 0)
806 snd_unit_auto = (snd_unit < 0) ? 1 : 0;
807 if (snd_unit < 0 || snd_unit_auto > 1)
808 snd_unit = device_get_unit(dev);
809 else if (snd_unit_auto == 1)
811
812 return (0);
813}
814
815uint32_t
817{
818 struct snddev_info *d = device_get_softc(dev);
819
820 return d->flags;
821}
822
823void
824pcm_setflags(device_t dev, uint32_t val)
825{
826 struct snddev_info *d = device_get_softc(dev);
827
828 d->flags = val;
829}
830
831void *
833{
834 struct snddev_info *d = device_get_softc(dev);
835
836 return d->devinfo;
837}
838
839unsigned int
840pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
841{
842 struct snddev_info *d = device_get_softc(dev);
843 int sz, x;
844
845 sz = 0;
846 if (resource_int_value(device_get_name(dev), device_get_unit(dev), "buffersize", &sz) == 0) {
847 x = sz;
848 RANGE(sz, minbufsz, maxbufsz);
849 if (x != sz)
850 device_printf(dev, "'buffersize=%d' hint is out of range (%d-%d), using %d\n", x, minbufsz, maxbufsz, sz);
851 x = minbufsz;
852 while (x < sz)
853 x <<= 1;
854 if (x > sz)
855 x >>= 1;
856 if (x != sz) {
857 device_printf(dev, "'buffersize=%d' hint is not a power of 2, using %d\n", sz, x);
858 sz = x;
859 }
860 } else {
861 sz = deflt;
862 }
863
864 d->bufsz = sz;
865
866 return sz;
867}
868
869static int
870sysctl_dev_pcm_bitperfect(SYSCTL_HANDLER_ARGS)
871{
872 struct snddev_info *d;
873 int err, val;
874
875 d = oidp->oid_arg1;
876 if (!PCM_REGISTERED(d))
877 return (ENODEV);
878
879 PCM_LOCK(d);
880 PCM_WAIT(d);
881 val = (d->flags & SD_F_BITPERFECT) ? 1 : 0;
882 PCM_ACQUIRE(d);
883 PCM_UNLOCK(d);
884
885 err = sysctl_handle_int(oidp, &val, 0, req);
886
887 if (err == 0 && req->newptr != NULL) {
888 if (!(val == 0 || val == 1)) {
890 return (EINVAL);
891 }
892
893 PCM_LOCK(d);
894
895 d->flags &= ~SD_F_BITPERFECT;
896 d->flags |= (val != 0) ? SD_F_BITPERFECT : 0;
897
898 PCM_RELEASE(d);
899 PCM_UNLOCK(d);
900 } else
902
903 return (err);
904}
905
906#ifdef SND_DEBUG
907static int
908sysctl_dev_pcm_clone_flags(SYSCTL_HANDLER_ARGS)
909{
910 struct snddev_info *d;
911 uint32_t flags;
912 int err;
913
914 d = oidp->oid_arg1;
915 if (!PCM_REGISTERED(d) || d->clones == NULL)
916 return (ENODEV);
917
919
921 err = sysctl_handle_int(oidp, &flags, 0, req);
922
923 if (err == 0 && req->newptr != NULL) {
924 if (flags & ~SND_CLONE_MASK)
925 err = EINVAL;
926 else
928 }
929
931
932 return (err);
933}
934
935static int
936sysctl_dev_pcm_clone_deadline(SYSCTL_HANDLER_ARGS)
937{
938 struct snddev_info *d;
939 int err, deadline;
940
941 d = oidp->oid_arg1;
942 if (!PCM_REGISTERED(d) || d->clones == NULL)
943 return (ENODEV);
944
946
947 deadline = snd_clone_getdeadline(d->clones);
948 err = sysctl_handle_int(oidp, &deadline, 0, req);
949
950 if (err == 0 && req->newptr != NULL) {
951 if (deadline < 0)
952 err = EINVAL;
953 else
954 (void)snd_clone_setdeadline(d->clones, deadline);
955 }
956
958
959 return (err);
960}
961
962static int
963sysctl_dev_pcm_clone_gc(SYSCTL_HANDLER_ARGS)
964{
965 struct snddev_info *d;
966 int err, val;
967
968 d = oidp->oid_arg1;
969 if (!PCM_REGISTERED(d) || d->clones == NULL)
970 return (ENODEV);
971
972 val = 0;
973 err = sysctl_handle_int(oidp, &val, 0, req);
974
975 if (err == 0 && req->newptr != NULL && val != 0) {
977 val = snd_clone_gc(d->clones);
979 if (bootverbose != 0 || snd_verbose > 3)
980 device_printf(d->dev, "clone gc: pruned=%d\n", val);
981 }
982
983 return (err);
984}
985
986static int
987sysctl_hw_snd_clone_gc(SYSCTL_HANDLER_ARGS)
988{
989 struct snddev_info *d;
990 int i, err, val;
991
992 val = 0;
993 err = sysctl_handle_int(oidp, &val, 0, req);
994
995 if (err == 0 && req->newptr != NULL && val != 0) {
996 for (i = 0; pcm_devclass != NULL &&
997 i < devclass_get_maxunit(pcm_devclass); i++) {
998 d = devclass_get_softc(pcm_devclass, i);
999 if (!PCM_REGISTERED(d) || d->clones == NULL)
1000 continue;
1002 val = snd_clone_gc(d->clones);
1004 if (bootverbose != 0 || snd_verbose > 3)
1005 device_printf(d->dev, "clone gc: pruned=%d\n",
1006 val);
1007 }
1008 }
1009
1010 return (err);
1011}
1012SYSCTL_PROC(_hw_snd, OID_AUTO, clone_gc,
1013 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_NEEDGIANT, 0, sizeof(int),
1014 sysctl_hw_snd_clone_gc, "I",
1015 "global clone garbage collector");
1016#endif
1017
1018static u_int8_t
1020{
1021 u_int8_t mode = 0;
1022
1023 if (d->playcount > 0)
1024 mode |= PCM_MODE_PLAY;
1025 if (d->reccount > 0)
1026 mode |= PCM_MODE_REC;
1027 if (d->mixer_dev != NULL)
1028 mode |= PCM_MODE_MIXER;
1029
1030 return (mode);
1031}
1032
1033static void
1035{
1036 struct snddev_info *d = device_get_softc(dev);
1037 u_int8_t mode;
1038
1039 mode = pcm_mode_init(d);
1040
1041 /* XXX: a user should be able to set this with a control tool, the
1042 sysadmin then needs min+max sysctls for this */
1043 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
1044 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1045 OID_AUTO, "buffersize", CTLFLAG_RD, &d->bufsz, 0, "allocated buffer size");
1046 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1047 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1048 "bitperfect", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, d,
1049 sizeof(d), sysctl_dev_pcm_bitperfect, "I",
1050 "bit-perfect playback/recording (0=disable, 1=enable)");
1051 SYSCTL_ADD_UINT(device_get_sysctl_ctx(dev),
1052 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)),
1053 OID_AUTO, "mode", CTLFLAG_RD, NULL, mode,
1054 "mode (1=mixer, 2=play, 4=rec. The values are OR'ed if more than one"
1055 "mode is supported)");
1056#ifdef SND_DEBUG
1057 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1058 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1059 "clone_flags", CTLTYPE_UINT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1060 d, sizeof(d), sysctl_dev_pcm_clone_flags, "IU",
1061 "clone flags");
1062 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1063 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1064 "clone_deadline", CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE,
1065 d, sizeof(d), sysctl_dev_pcm_clone_deadline, "I",
1066 "clone expiration deadline (ms)");
1067 SYSCTL_ADD_PROC(device_get_sysctl_ctx(dev),
1068 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO,
1069 "clone_gc",
1070 CTLTYPE_INT | CTLFLAG_RWTUN | CTLFLAG_MPSAFE, d, sizeof(d),
1071 sysctl_dev_pcm_clone_gc, "I", "clone garbage collector");
1072#endif
1073 if (d->flags & SD_F_AUTOVCHAN)
1075 if (d->flags & SD_F_EQ)
1077}
1078
1079int
1080pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
1081{
1082 struct snddev_info *d;
1083 int i;
1084
1085 if (pcm_veto_load) {
1086 device_printf(dev, "disabled due to an error while initialising: %d\n", pcm_veto_load);
1087
1088 return EINVAL;
1089 }
1090
1091 if (device_get_unit(dev) > PCMMAXUNIT) {
1092 device_printf(dev, "PCMMAXUNIT reached : unit=%d > %d\n",
1093 device_get_unit(dev), PCMMAXUNIT);
1094 device_printf(dev,
1095 "Use 'hw.snd.maxunit' tunable to raise the limit.\n");
1096 return ENODEV;
1097 }
1098
1099 d = device_get_softc(dev);
1100 d->dev = dev;
1101 d->lock = snd_mtxcreate(device_get_nameunit(dev), "sound cdev");
1102 cv_init(&d->cv, device_get_nameunit(dev));
1105#if 0
1106 /*
1107 * d->flags should be cleared by the allocator of the softc.
1108 * We cannot clear this field here because several devices set
1109 * this flag before calling pcm_register().
1110 */
1111 d->flags = 0;
1112#endif
1113 i = 0;
1114 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
1115 "vpc", &i) != 0 || i != 0)
1116 d->flags |= SD_F_VPC;
1117
1118 if (resource_int_value(device_get_name(dev), device_get_unit(dev),
1119 "bitperfect", &i) == 0 && i != 0)
1120 d->flags |= SD_F_BITPERFECT;
1121
1122 d->devinfo = devinfo;
1123 d->devcount = 0;
1124 d->reccount = 0;
1125 d->playcount = 0;
1126 d->pvchancount = 0;
1127 d->rvchancount = 0;
1128 d->pvchanrate = 0;
1129 d->pvchanformat = 0;
1130 d->rvchanrate = 0;
1131 d->rvchanformat = 0;
1132 d->inprog = 0;
1133
1134 /*
1135 * Create clone manager, disabled by default. Cloning will be
1136 * enabled during final stage of driver initialization through
1137 * pcm_setstatus().
1138 */
1143
1144 CHN_INIT(d, channels.pcm);
1145 CHN_INIT(d, channels.pcm.busy);
1146 CHN_INIT(d, channels.pcm.opened);
1147
1148 /* XXX This is incorrect, but lets play along for now. */
1149 if ((numplay == 0 || numrec == 0) && numplay != numrec)
1150 d->flags |= SD_F_SIMPLEX;
1151
1152 sysctl_ctx_init(&d->play_sysctl_ctx);
1153 d->play_sysctl_tree = SYSCTL_ADD_NODE(&d->play_sysctl_ctx,
1154 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "play",
1155 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "playback channels node");
1156 sysctl_ctx_init(&d->rec_sysctl_ctx);
1157 d->rec_sysctl_tree = SYSCTL_ADD_NODE(&d->rec_sysctl_ctx,
1158 SYSCTL_CHILDREN(device_get_sysctl_tree(dev)), OID_AUTO, "rec",
1159 CTLFLAG_RD | CTLFLAG_MPSAFE, 0, "recording channels node");
1160
1161 if (numplay > 0 || numrec > 0)
1162 d->flags |= SD_F_AUTOVCHAN;
1163
1165
1166 return 0;
1167}
1168
1169int
1171{
1172 struct snddev_info *d;
1173 struct pcm_channel *ch;
1174
1175 d = device_get_softc(dev);
1176
1177 if (!PCM_ALIVE(d)) {
1178 device_printf(dev, "unregister: device not configured\n");
1179 return (0);
1180 }
1181
1182 PCM_LOCK(d);
1183 PCM_WAIT(d);
1184
1185 d->flags |= SD_F_DETACHING;
1186
1187 if (d->inprog != 0) {
1188 device_printf(dev, "unregister: operation in progress\n");
1189 PCM_UNLOCK(d);
1190 return (EBUSY);
1191 }
1192
1193 PCM_ACQUIRE(d);
1194 PCM_UNLOCK(d);
1195
1196 CHN_FOREACH(ch, d, channels.pcm) {
1197 CHN_LOCK(ch);
1198 if (ch->refcount > 0) {
1199 device_printf(dev,
1200 "unregister: channel %s busy (pid %d)\n",
1201 ch->name, ch->pid);
1202 CHN_UNLOCK(ch);
1204 return (EBUSY);
1205 }
1206 CHN_UNLOCK(ch);
1207 }
1208
1209 if (d->clones != NULL) {
1210 if (snd_clone_busy(d->clones) != 0) {
1211 device_printf(dev, "unregister: clone busy\n");
1213 return (EBUSY);
1214 } else {
1215 PCM_LOCK(d);
1216 (void)snd_clone_disable(d->clones);
1217 PCM_UNLOCK(d);
1218 }
1219 }
1220
1221 if (mixer_uninit(dev) == EBUSY) {
1222 device_printf(dev, "unregister: mixer busy\n");
1223 PCM_LOCK(d);
1224 if (d->clones != NULL)
1225 (void)snd_clone_enable(d->clones);
1226 PCM_RELEASE(d);
1227 PCM_UNLOCK(d);
1228 return (EBUSY);
1229 }
1230
1231 /* remove /dev/sndstat entry first */
1233
1234 PCM_LOCK(d);
1235 d->flags |= SD_F_DYING;
1236 d->flags &= ~SD_F_REGISTERED;
1237 PCM_UNLOCK(d);
1238
1239 /*
1240 * No lock being held, so this thing can be flushed without
1241 * stucking into devdrn oblivion.
1242 */
1243 if (d->clones != NULL) {
1245 d->clones = NULL;
1246 }
1247
1248 if (d->play_sysctl_tree != NULL) {
1249 sysctl_ctx_free(&d->play_sysctl_ctx);
1250 d->play_sysctl_tree = NULL;
1251 }
1252 if (d->rec_sysctl_tree != NULL) {
1253 sysctl_ctx_free(&d->rec_sysctl_ctx);
1254 d->rec_sysctl_tree = NULL;
1255 }
1256
1257 while (!CHN_EMPTY(d, channels.pcm))
1259
1261
1262 PCM_LOCK(d);
1263 PCM_RELEASE(d);
1264 cv_destroy(&d->cv);
1265 PCM_UNLOCK(d);
1266 snd_mtxfree(d->lock);
1267
1268 if (snd_unit == device_get_unit(dev)) {
1269 snd_unit = pcm_best_unit(-1);
1270 if (snd_unit_auto == 0)
1271 snd_unit_auto = 1;
1272 }
1273
1274 return (0);
1275}
1276
1277/************************************************************************/
1278
1295void
1296sound_oss_sysinfo(oss_sysinfo *si)
1297{
1298 static char si_product[] = "FreeBSD native OSS ABI";
1299 static char si_version[] = __XSTRING(__FreeBSD_version);
1300 static char si_license[] = "BSD";
1301 static int intnbits = sizeof(int) * 8; /* Better suited as macro?
1302 Must pester a C guru. */
1303
1304 struct snddev_info *d;
1305 struct pcm_channel *c;
1306 int i, j, ncards;
1307
1308 ncards = 0;
1309
1310 strlcpy(si->product, si_product, sizeof(si->product));
1311 strlcpy(si->version, si_version, sizeof(si->version));
1312 si->versionnum = SOUND_VERSION;
1313 strlcpy(si->license, si_license, sizeof(si->license));
1314
1315 /*
1316 * Iterate over PCM devices and their channels, gathering up data
1317 * for the numaudios, ncards, and openedaudio fields.
1318 */
1319 si->numaudios = 0;
1320 bzero((void *)&si->openedaudio, sizeof(si->openedaudio));
1321
1322 j = 0;
1323
1324 for (i = 0; pcm_devclass != NULL &&
1325 i < devclass_get_maxunit(pcm_devclass); i++) {
1326 d = devclass_get_softc(pcm_devclass, i);
1327 if (!PCM_REGISTERED(d))
1328 continue;
1329
1330 /* XXX Need Giant magic entry ??? */
1331
1332 /* See note in function's docblock */
1334 PCM_LOCK(d);
1335
1336 si->numaudios += d->devcount;
1337 ++ncards;
1338
1339 CHN_FOREACH(c, d, channels.pcm) {
1341 CHN_LOCK(c);
1342 if (c->flags & CHN_F_BUSY)
1343 si->openedaudio[j / intnbits] |=
1344 (1 << (j % intnbits));
1345 CHN_UNLOCK(c);
1346 j++;
1347 }
1348
1349 PCM_UNLOCK(d);
1350 }
1351 si->numaudioengines = si->numaudios;
1352
1353 si->numsynths = 0; /* OSSv4 docs: this field is obsolete */
1365 si->nummidis = 0;
1366 si->numtimers = 0;
1367 si->nummixers = mixer_count;
1368 si->numcards = ncards;
1369 /* OSSv4 docs: Intended only for test apps; API doesn't
1370 really have much of a concept of cards. Shouldn't be
1371 used by applications. */
1372
1378 bzero((void *)&si->openedmidi, sizeof(si->openedmidi));
1379
1380 /*
1381 * Si->filler is a reserved array, but according to docs each
1382 * element should be set to -1.
1383 */
1384 for (i = 0; i < sizeof(si->filler)/sizeof(si->filler[0]); i++)
1385 si->filler[i] = -1;
1386}
1387
1388int
1389sound_oss_card_info(oss_card_info *si)
1390{
1391 struct snddev_info *d;
1392 int i, ncards;
1393
1394 ncards = 0;
1395
1396 for (i = 0; pcm_devclass != NULL &&
1397 i < devclass_get_maxunit(pcm_devclass); i++) {
1398 d = devclass_get_softc(pcm_devclass, i);
1399 if (!PCM_REGISTERED(d))
1400 continue;
1401
1402 if (ncards++ != si->card)
1403 continue;
1404
1406 PCM_LOCK(d);
1407
1408 strlcpy(si->shortname, device_get_nameunit(d->dev),
1409 sizeof(si->shortname));
1410 strlcpy(si->longname, device_get_desc(d->dev),
1411 sizeof(si->longname));
1412 strlcpy(si->hw_info, d->status, sizeof(si->hw_info));
1413 si->intr_count = si->ack_count = 0;
1414
1415 PCM_UNLOCK(d);
1416
1417 return (0);
1418 }
1419 return (ENXIO);
1420}
1421
1422/************************************************************************/
1423
1424static int
1425sound_modevent(module_t mod, int type, void *data)
1426{
1427 int ret;
1428#if 0
1429 return (midi_modevent(mod, type, data));
1430#else
1431 ret = 0;
1432
1433 switch(type) {
1434 case MOD_LOAD:
1435 pcmsg_unrhdr = new_unrhdr(1, INT_MAX, NULL);
1436 break;
1437 case MOD_UNLOAD:
1438 if (pcmsg_unrhdr != NULL) {
1439 delete_unrhdr(pcmsg_unrhdr);
1440 pcmsg_unrhdr = NULL;
1441 }
1442 break;
1443 case MOD_SHUTDOWN:
1444 break;
1445 default:
1446 ret = ENOTSUP;
1447 }
1448
1449 return ret;
1450#endif
1451}
1452
u_int32_t data
Definition: ac97_if.m:60
void * devinfo
Definition: ac97_if.m:47
char * desc
Definition: atiixp.c:174
int chn_kill(struct pcm_channel *c)
Definition: channel.c:1285
struct pcmchan_caps * chn_getcaps(struct pcm_channel *c)
Definition: channel.c:2277
int chn_init(struct pcm_channel *c, void *devinfo, int dir, int direction)
Definition: channel.c:1163
#define CHN_UNLOCK(c)
Definition: channel.h:322
#define CHN_UNLOCKASSERT(c)
Definition: channel.h:325
#define PCMDIR_PLAY_VIRTUAL
Definition: channel.h:340
#define CHN_LOCK(c)
Definition: channel.h:321
#define CHN_NAMELEN
Definition: channel.h:81
#define CHN_F_HAS_VCHAN
Definition: channel.h:370
#define CHN_COMM_UNKNOWN
Definition: channel.h:83
#define PCMDIR_PLAY
Definition: channel.h:339
#define CHN_COMM_UNUSED
Definition: channel.h:82
#define CHN_FOREACH_SAFE(w, x, y, z)
Definition: channel.h:184
#define CHN_DEV(x)
Definition: channel.h:244
#define CHN_INSERT_SORT_ASCEND(x, y, z)
Definition: channel.h:240
#define CHN_EMPTY(x, y)
Definition: channel.h:178
#define CHN_INIT(x, y)
Definition: channel.h:176
#define CHN_FOREACH(x, y, z)
Definition: channel.h:181
#define CHN_F_BUSY
Definition: channel.h:364
#define CHN_LOCKASSERT(c)
Definition: channel.h:324
#define CHN_FIRST(x, y)
Definition: channel.h:179
#define PCMDIR_REC_VIRTUAL
Definition: channel.h:342
#define CHN_CHAN(x)
Definition: channel.h:245
#define CHN_REMOVE(x, y, z)
Definition: channel.h:193
#define PCMTRIG_STOP
Definition: channel.h:347
#define PCMDIR_REC
Definition: channel.h:341
#define CHN_F_VIRTUAL
Definition: channel.h:376
struct pcm_channel * c
Definition: channel_if.m:106
METHOD int free
Definition: channel_if.m:110
struct pcmchan_matrix * m
Definition: channel_if.m:232
int snd_clone_busy(struct snd_clone *c)
Definition: clone.c:134
struct snd_clone * snd_clone_create(int typemask, int maxunit, int deadline, uint32_t flags)
Definition: clone.c:106
uint32_t snd_clone_setflags(struct snd_clone *c, uint32_t flags)
Definition: clone.c:243
int snd_clone_setmaxunit(struct snd_clone *c, int maxunit)
Definition: clone.c:202
int snd_clone_disable(struct snd_clone *c)
Definition: clone.c:170
uint32_t snd_clone_getflags(struct snd_clone *c)
Definition: clone.c:235
int snd_clone_setdeadline(struct snd_clone *c, int deadline)
Definition: clone.c:225
int snd_clone_enable(struct snd_clone *c)
Definition: clone.c:157
int snd_clone_getdeadline(struct snd_clone *c)
Definition: clone.c:217
int snd_clone_gc(struct snd_clone *c)
Definition: clone.c:308
void snd_clone_destroy(struct snd_clone *c)
Definition: clone.c:360
#define SND_CLONE_DEADLINE_DEFAULT
Definition: clone.h:41
#define SND_CLONE_GC_UNREF
Definition: clone.h:66
#define SND_CLONE_MASK
Definition: clone.h:78
#define SND_CLONE_WAITOK
Definition: clone.h:70
#define SND_CLONE_GC_ENABLE
Definition: clone.h:65
#define SND_CLONE_GC_LASTREF
Definition: clone.h:67
#define SND_CLONE_GC_EXPIRED
Definition: clone.h:68
void dsp_cdevinfo_init(struct snddev_info *d)
Definition: dsp.c:332
void dsp_cdevinfo_flush(struct snddev_info *d)
Definition: dsp.c:349
int type
Definition: dsp.c:386
char * dsp_unit2name(char *buf, size_t len, int unit)
Definition: dsp.c:2534
int max
Definition: dsp.c:392
void feeder_eq_initsys(device_t)
Definition: feeder_eq.c:664
int dir
Definition: hdac_if.m:45
bus_addr_t buf
Definition: hdac_if.m:63
struct @109 error
uint8_t chan
uint8_t param
static int midi_modevent(module_t mod, int type, void *data)
Definition: midi.c:1441
int mixer_uninit(device_t dev)
Definition: mixer.c:805
int mixer_count
Definition: mixer.c:113
unsigned dev
Definition: mixer_if.m:59
u_int32_t val
#define RANGE(var, low, high)
Definition: sequencer.h:45
int sndstat_unregister(device_t dev)
Definition: sndstat.c:1118
int sndstat_register(device_t dev, char *str, sndstat_handler handler)
Definition: sndstat.c:1059
#define SNDSTAT_PREPARE_PCM_BEGIN()
Definition: sndstat.h:37
#define SNDSTAT_PREPARE_PCM_ARGS
Definition: sndstat.h:34
#define SNDSTAT_PREPARE_PCM_END()
Definition: sndstat.h:65
void snd_mtxassert(void *m)
Definition: sound.c:107
void * snd_mtxcreate(const char *desc, const char *type)
Definition: sound.c:88
int snd_maxautovchans
Definition: sound.c:59
static int pcm_killchan(device_t dev)
Definition: sound.c:721
void pcm_setflags(device_t dev, uint32_t val)
Definition: sound.c:824
static int sysctl_dev_pcm_bitperfect(SYSCTL_HANDLER_ARGS)
Definition: sound.c:870
SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD|CTLFLAG_MPSAFE, 0, "Sound driver")
void * pcm_getdevinfo(device_t dev)
Definition: sound.c:832
int sound_oss_card_info(oss_card_info *si)
Definition: sound.c:1389
uint32_t pcm_getflags(device_t dev)
Definition: sound.c:816
SYSCTL_PROC(_hw_snd, OID_AUTO, default_unit, CTLTYPE_INT|CTLFLAG_RWTUN|CTLFLAG_ANYBODY|CTLFLAG_NEEDGIANT, 0, sizeof(int), sysctl_hw_snd_default_unit, "I", "default sound device")
struct unrhdr * pcmsg_unrhdr
Unit number allocator for syncgroup IDs.
Definition: sound.c:78
int pcm_setvchans(struct snddev_info *d, int direction, int newcnt, int num)
Definition: sound.c:149
struct pcm_channel * pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, int num, void *devinfo)
Definition: sound.c:483
static void pcm_setmaxautovchans(struct snddev_info *d, int num)
Definition: sound.c:408
static u_int8_t pcm_mode_init(struct snddev_info *d)
Definition: sound.c:1019
int pcm_setstatus(device_t dev, char *str)
Definition: sound.c:766
devclass_t pcm_devclass
Definition: sound.c:49
void snd_mtxfree(void *m)
Definition: sound.c:98
static char snd_driver_version[]
Definition: sound.c:70
void sound_oss_sysinfo(oss_sysinfo *si)
Handle OSSv4 SNDCTL_SYSINFO ioctl.
Definition: sound.c:1296
SND_DECLARE_FILE("$FreeBSD$")
int pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
Definition: sound.c:692
int pcm_chn_destroy(struct pcm_channel *ch)
Definition: sound.c:596
static void pcm_clonereset(struct snddev_info *d)
Definition: sound.c:131
static int sndstat_prepare_pcm(SNDSTAT_PREPARE_PCM_ARGS)
Definition: sound.c:81
int pcm_veto_load
Definition: sound.c:51
static int sysctl_hw_snd_maxautovchans(SYSCTL_HANDLER_ARGS)
Definition: sound.c:452
int pcm_unregister(device_t dev)
Definition: sound.c:1170
int pcm_inprog(struct snddev_info *d, int delta)
Definition: sound.c:398
static int pcm_best_unit(int old)
Definition: sound.c:740
int pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
Definition: sound.c:1080
int snd_unit
Definition: sound.c:53
int pcm_chnalloc(struct snddev_info *d, struct pcm_channel **ch, int direction, pid_t pid, char *comm, int devunit)
Definition: sound.c:273
int snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
Definition: sound.c:117
int pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch)
Definition: sound.c:618
unsigned int pcm_getbuffersize(device_t dev, unsigned int minbufsz, unsigned int deflt, unsigned int maxbufsz)
Definition: sound.c:840
SYSCTL_INT(_hw_snd, OID_AUTO, default_auto, CTLFLAG_RWTUN, &snd_unit_auto, 0, "assign default unit to a newly attached device")
SYSCTL_STRING(_hw_snd, OID_AUTO, version, CTLFLAG_RD, &snd_driver_version, 0, "driver version/arch")
DEV_MODULE(sound, sound_modevent, NULL)
static int sysctl_hw_snd_default_unit(SYSCTL_HANDLER_ARGS)
Definition: sound.c:429
MODULE_VERSION(sound, SOUND_MODVER)
int pcm_chnref(struct pcm_channel *c, int ref)
Definition: sound.c:387
static void pcm_sysinit(device_t)
Definition: sound.c:1034
int pcm_chnrelease(struct pcm_channel *c)
Definition: sound.c:373
static int snd_unit_auto
Definition: sound.c:55
int pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch)
Definition: sound.c:650
static int sound_modevent(module_t mod, int type, void *data)
Definition: sound.c:1425
#define SD_F_REGISTERED
Definition: sound.h:139
#define SD_F_AUTOVCHAN
Definition: sound.h:133
#define PCMMAXUNIT
Definition: sound.h:113
#define PCM_RELEASE_QUICK(x)
Definition: sound.h:573
#define SND_MAXHWCHAN
Definition: sound.h:129
#define PCM_MODE_MIXER
Definition: sound.h:415
#define SOUND_MODVER
Definition: sound.h:100
#define PCM_RELEASE(x)
Definition: sound.h:554
#define PCM_LOCKASSERT(d)
Definition: sound.h:423
#define SD_F_DYING
Definition: sound.h:135
#define PCMMAXCLONE
Definition: sound.h:117
#define PCM_MODE_REC
Definition: sound.h:417
#define SND_DEV_DSPHW_VREC
Definition: sound.h:277
#define SD_F_MPSAFE
Definition: sound.h:138
#define PCM_ACQUIRE(x)
Definition: sound.h:546
#define SD_F_DETACHING
Definition: sound.h:136
#define PCM_BUSYASSERT(x)
Definition: sound.h:580
#define PCM_WAIT(x)
Definition: sound.h:540
#define SND_MAXVCHANS
Definition: sound.h:130
#define SD_F_BITPERFECT
Definition: sound.h:140
#define PCM_UNLOCK(d)
Definition: sound.h:421
#define SND_DEV_DSPHW_REC
Definition: sound.h:276
#define SD_F_SIMPLEX
Definition: sound.h:132
#define PCM_ALIVE(x)
Definition: sound.h:176
#define PCM_LOCK(d)
Definition: sound.h:420
#define AFMT_CONVERTIBLE
Definition: sound.h:199
int snd_verbose
#define SND_DEV_DSPHW_VPLAY
Definition: sound.h:275
#define PCM_ACQUIRE_QUICK(x)
Definition: sound.h:565
#define SD_F_EQ
Definition: sound.h:142
#define SND_STATUSLEN
Definition: sound.h:98
#define SND_DEV_DSPHW_PLAY
Definition: sound.h:274
#define PCM_UNLOCKASSERT(d)
Definition: sound.h:424
#define PCM_REGISTERED(x)
Definition: sound.h:178
#define PCM_MODE_PLAY
Definition: sound.h:416
#define SD_F_VPC
Definition: sound.h:141
char name[CHN_NAMELEN]
Definition: channel.h:109
u_int32_t flags
Definition: channel.h:96
kobj_t methods
Definition: channel.h:86
int trigger
Definition: channel.h:112
struct pcm_channel::@28 channels
pid_t pid
Definition: channel.h:88
int direction
Definition: channel.h:100
int refcount
Definition: channel.h:89
struct pcm_channel * parentchannel
Definition: channel.h:105
int unit
Definition: channel.h:108
char comm[MAXCOMLEN+1]
Definition: channel.h:110
struct snddev_info * parentsnddev
Definition: channel.h:104
device_t dev
Definition: channel.h:107
u_int32_t caps
Definition: channel.h:36
unsigned playcount
Definition: sound.h:395
struct mtx * lock
Definition: sound.h:402
unsigned rvchancount
Definition: sound.h:395
struct cv cv
Definition: sound.h:409
struct cdev * mixer_dev
Definition: sound.h:403
unsigned devcount
Definition: sound.h:395
char status[SND_STATUSLEN]
Definition: sound.h:401
struct snd_clone * clones
Definition: sound.h:394
unsigned flags
Definition: sound.h:396
unsigned pvchancount
Definition: sound.h:395
struct snddev_info::@49::@50 pcm
uint32_t pvchanformat
Definition: sound.h:404
unsigned reccount
Definition: sound.h:395
uint32_t rvchanformat
Definition: sound.h:405
uint32_t rvchanrate
Definition: sound.h:405
struct sysctl_oid * play_sysctl_tree
Definition: sound.h:408
struct snddev_info::@49 channels
struct sysctl_ctx_list play_sysctl_ctx rec_sysctl_ctx
Definition: sound.h:407
unsigned int bufsz
Definition: sound.h:398
struct sysctl_oid * rec_sysctl_tree
Definition: sound.h:408
uint32_t pvchanrate
Definition: sound.h:404
void * devinfo
Definition: sound.h:399
device_t dev
Definition: sound.h:400
int inprog
Definition: sound.h:397
int snd_unit2d(int unit)
Definition: unit.c:116
int snd_mkunit(int u, int d, int c)
Definition: unit.c:156
int snd_unit2c(int unit)
Definition: unit.c:124
#define SND_U_MASK
Definition: unit.h:50
#define SND_C_MASK
Definition: unit.h:52
#define SND_D_MASK
Definition: unit.h:51
const void * req
int vchan_destroy(struct pcm_channel *c)
Definition: vchan.c:852
int vchan_create(struct pcm_channel *parent, int num)
Definition: vchan.c:667
void vchan_initsys(device_t dev)
Definition: vchan.c:940
#define SND_DRV_VERSION
Definition: version.h:42