1999-09-01 04:08:39 +00:00
|
|
|
/*
|
|
|
|
* Copyright (c) 1999 Cameron Grant <gandalf@vilnya.demon.co.uk>
|
|
|
|
* (C) 1997 Luigi Rizzo (luigi@iet.unipi.it)
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
|
|
|
|
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
|
|
|
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
|
|
|
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
|
|
|
|
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
|
|
|
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
|
|
|
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
|
|
|
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
|
|
|
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
|
|
|
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
|
|
|
* SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
1999-11-20 16:50:33 +00:00
|
|
|
#include <dev/sound/pcm/sound.h>
|
2001-05-27 17:22:00 +00:00
|
|
|
#include <dev/sound/pcm/vchan.h>
|
2000-08-29 16:21:33 +00:00
|
|
|
#include <sys/sysctl.h>
|
1999-09-01 04:08:39 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
#include "feeder_if.h"
|
|
|
|
|
|
|
|
SND_DECLARE_FILE("$FreeBSD$");
|
|
|
|
|
|
|
|
struct snddev_channel {
|
|
|
|
SLIST_ENTRY(snddev_channel) link;
|
|
|
|
struct pcm_channel *channel;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct snddev_info {
|
|
|
|
SLIST_HEAD(, snddev_channel) channels;
|
|
|
|
struct pcm_channel *fakechan;
|
2001-09-18 14:50:52 +00:00
|
|
|
unsigned devcount, playcount, reccount, vchancount;
|
2001-08-23 11:30:52 +00:00
|
|
|
unsigned flags;
|
|
|
|
int inprog;
|
2001-09-18 14:50:52 +00:00
|
|
|
unsigned int bufsz;
|
2001-08-23 11:30:52 +00:00
|
|
|
void *devinfo;
|
|
|
|
device_t dev;
|
|
|
|
char status[SND_STATUSLEN];
|
|
|
|
struct sysctl_ctx_list sysctl_tree;
|
|
|
|
struct sysctl_oid *sysctl_tree_top;
|
|
|
|
void *lock;
|
|
|
|
};
|
|
|
|
|
2001-06-16 21:25:10 +00:00
|
|
|
devclass_t pcm_devclass;
|
2001-02-27 07:01:49 +00:00
|
|
|
|
2002-01-26 22:13:24 +00:00
|
|
|
int pcm_veto_load = 1;
|
|
|
|
|
2001-02-27 07:01:49 +00:00
|
|
|
#ifdef USING_DEVFS
|
2001-06-16 21:25:10 +00:00
|
|
|
int snd_unit = 0;
|
2001-06-08 05:24:21 +00:00
|
|
|
TUNABLE_INT("hw.snd.unit", &snd_unit);
|
2001-02-27 07:01:49 +00:00
|
|
|
#endif
|
2001-07-03 12:53:09 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
int snd_maxautovchans = 0;
|
|
|
|
TUNABLE_INT("hw.snd.maxautovchans", &snd_maxautovchans);
|
2001-02-27 07:01:49 +00:00
|
|
|
|
|
|
|
SYSCTL_NODE(_hw, OID_AUTO, snd, CTLFLAG_RD, 0, "Sound driver");
|
1999-09-01 04:08:39 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
static int sndstat_prepare_pcm(struct sbuf *s, device_t dev, int verbose);
|
|
|
|
|
|
|
|
struct sysctl_ctx_list *
|
|
|
|
snd_sysctl_tree(device_t dev)
|
|
|
|
{
|
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
|
|
|
|
|
|
|
return &d->sysctl_tree;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sysctl_oid *
|
|
|
|
snd_sysctl_tree_top(device_t dev)
|
|
|
|
{
|
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
|
|
|
|
|
|
|
return d->sysctl_tree_top;
|
|
|
|
}
|
|
|
|
|
2001-02-27 07:45:09 +00:00
|
|
|
void *
|
2002-04-04 20:54:27 +00:00
|
|
|
snd_mtxcreate(const char *desc, const char *type)
|
2001-02-27 07:45:09 +00:00
|
|
|
{
|
|
|
|
#ifdef USING_MUTEX
|
|
|
|
struct mtx *m;
|
|
|
|
|
|
|
|
m = malloc(sizeof(*m), M_DEVBUF, M_WAITOK | M_ZERO);
|
|
|
|
if (m == NULL)
|
|
|
|
return NULL;
|
2002-04-04 20:54:27 +00:00
|
|
|
mtx_init(m, desc, type, MTX_RECURSE);
|
2001-02-27 07:45:09 +00:00
|
|
|
return m;
|
|
|
|
#else
|
2001-03-05 15:49:42 +00:00
|
|
|
return (void *)0xcafebabe;
|
2001-02-27 07:45:09 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
snd_mtxfree(void *m)
|
|
|
|
{
|
|
|
|
#ifdef USING_MUTEX
|
|
|
|
struct mtx *mtx = m;
|
|
|
|
|
|
|
|
mtx_assert(mtx, MA_OWNED);
|
|
|
|
mtx_destroy(mtx);
|
|
|
|
free(mtx, M_DEVBUF);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
snd_mtxassert(void *m)
|
|
|
|
{
|
|
|
|
#ifdef USING_MUTEX
|
2001-06-23 17:36:51 +00:00
|
|
|
#ifdef INVARIANTS
|
2001-02-27 07:45:09 +00:00
|
|
|
struct mtx *mtx = m;
|
|
|
|
|
|
|
|
mtx_assert(mtx, MA_OWNED);
|
|
|
|
#endif
|
2001-06-23 17:36:51 +00:00
|
|
|
#endif
|
2001-02-27 07:45:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
snd_mtxlock(void *m)
|
|
|
|
{
|
|
|
|
#ifdef USING_MUTEX
|
|
|
|
struct mtx *mtx = m;
|
|
|
|
|
|
|
|
mtx_lock(mtx);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
snd_mtxunlock(void *m)
|
|
|
|
{
|
|
|
|
#ifdef USING_MUTEX
|
|
|
|
struct mtx *mtx = m;
|
|
|
|
|
|
|
|
mtx_unlock(mtx);
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
snd_setup_intr(device_t dev, struct resource *res, int flags, driver_intr_t hand, void *param, void **cookiep)
|
|
|
|
{
|
|
|
|
#ifdef USING_MUTEX
|
|
|
|
flags &= INTR_MPSAFE;
|
2001-06-16 22:59:46 +00:00
|
|
|
flags |= INTR_TYPE_AV;
|
2001-02-27 07:45:09 +00:00
|
|
|
#else
|
2001-06-16 22:59:46 +00:00
|
|
|
flags = INTR_TYPE_AV;
|
2001-02-27 07:45:09 +00:00
|
|
|
#endif
|
|
|
|
return bus_setup_intr(dev, res, flags, hand, param, cookiep);
|
|
|
|
}
|
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
void
|
|
|
|
pcm_lock(struct snddev_info *d)
|
|
|
|
{
|
|
|
|
snd_mtxlock(d->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pcm_unlock(struct snddev_info *d)
|
|
|
|
{
|
|
|
|
snd_mtxunlock(d->lock);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct pcm_channel *
|
|
|
|
pcm_getfakechan(struct snddev_info *d)
|
|
|
|
{
|
|
|
|
return d->fakechan;
|
|
|
|
}
|
|
|
|
|
2001-06-14 13:31:30 +00:00
|
|
|
/* return a locked channel */
|
2001-05-27 17:22:00 +00:00
|
|
|
struct pcm_channel *
|
2001-09-05 16:28:41 +00:00
|
|
|
pcm_chnalloc(struct snddev_info *d, int direction, pid_t pid, int chnum)
|
2001-05-27 17:22:00 +00:00
|
|
|
{
|
|
|
|
struct pcm_channel *c;
|
|
|
|
struct snddev_channel *sce;
|
2001-06-27 19:59:45 +00:00
|
|
|
int err;
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2001-06-14 13:31:30 +00:00
|
|
|
snd_mtxassert(d->lock);
|
2001-06-27 19:59:45 +00:00
|
|
|
|
|
|
|
/* scan for a free channel */
|
2001-05-27 17:22:00 +00:00
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
2001-06-07 20:06:22 +00:00
|
|
|
CHN_LOCK(c);
|
2001-05-27 17:22:00 +00:00
|
|
|
if ((c->direction == direction) && !(c->flags & CHN_F_BUSY)) {
|
2001-09-05 16:28:41 +00:00
|
|
|
if (chnum == -1 || c->num == chnum) {
|
|
|
|
c->flags |= CHN_F_BUSY;
|
|
|
|
c->pid = pid;
|
|
|
|
return c;
|
|
|
|
}
|
2001-05-27 17:22:00 +00:00
|
|
|
}
|
2001-06-07 20:06:22 +00:00
|
|
|
CHN_UNLOCK(c);
|
2001-05-27 17:22:00 +00:00
|
|
|
}
|
2001-06-27 19:59:45 +00:00
|
|
|
|
|
|
|
/* no channel available */
|
|
|
|
if (direction == PCMDIR_PLAY) {
|
2001-08-23 11:30:52 +00:00
|
|
|
if ((d->vchancount > 0) && (d->vchancount < snd_maxautovchans)) {
|
2001-06-27 19:59:45 +00:00
|
|
|
/* try to create a vchan */
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
if (!SLIST_EMPTY(&c->children)) {
|
|
|
|
err = vchan_create(c);
|
|
|
|
if (!err)
|
2001-09-05 16:28:41 +00:00
|
|
|
return pcm_chnalloc(d, direction, pid, -1);
|
2001-06-27 19:59:45 +00:00
|
|
|
else
|
|
|
|
device_printf(d->dev, "vchan_create(%s) == %d\n", c->name, err);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-06-14 13:31:30 +00:00
|
|
|
/* release a locked channel and unlock it */
|
2001-05-27 17:22:00 +00:00
|
|
|
int
|
2001-06-14 13:31:30 +00:00
|
|
|
pcm_chnrelease(struct pcm_channel *c)
|
2001-05-27 17:22:00 +00:00
|
|
|
{
|
2001-06-14 13:31:30 +00:00
|
|
|
CHN_LOCKASSERT(c);
|
2001-05-27 17:22:00 +00:00
|
|
|
c->flags &= ~CHN_F_BUSY;
|
2001-06-14 13:31:30 +00:00
|
|
|
c->pid = -1;
|
2001-06-07 20:06:22 +00:00
|
|
|
CHN_UNLOCK(c);
|
2001-05-27 17:22:00 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pcm_chnref(struct pcm_channel *c, int ref)
|
|
|
|
{
|
2001-06-07 20:06:22 +00:00
|
|
|
int r;
|
|
|
|
|
2001-06-14 13:31:30 +00:00
|
|
|
CHN_LOCKASSERT(c);
|
2001-05-27 17:22:00 +00:00
|
|
|
c->refcount += ref;
|
2001-06-07 20:06:22 +00:00
|
|
|
r = c->refcount;
|
|
|
|
return r;
|
2001-05-27 17:22:00 +00:00
|
|
|
}
|
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
int
|
|
|
|
pcm_inprog(struct snddev_info *d, int delta)
|
|
|
|
{
|
|
|
|
d->inprog += delta;
|
|
|
|
return d->inprog;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void
|
|
|
|
pcm_setmaxautovchans(struct snddev_info *d, int num)
|
|
|
|
{
|
|
|
|
struct pcm_channel *c;
|
|
|
|
struct snddev_channel *sce;
|
|
|
|
int err, done;
|
|
|
|
|
|
|
|
if (num > 0 && d->vchancount == 0) {
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
if ((c->direction == PCMDIR_PLAY) && !(c->flags & CHN_F_BUSY)) {
|
|
|
|
c->flags |= CHN_F_BUSY;
|
|
|
|
err = vchan_create(c);
|
|
|
|
if (err) {
|
|
|
|
device_printf(d->dev, "vchan_create(%s) == %d\n", c->name, err);
|
|
|
|
c->flags &= ~CHN_F_BUSY;
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if (num == 0 && d->vchancount > 0) {
|
|
|
|
done = 0;
|
|
|
|
while (!done) {
|
|
|
|
done = 1;
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
if ((c->flags & CHN_F_VIRTUAL) && !(c->flags & CHN_F_BUSY)) {
|
|
|
|
done = 0;
|
|
|
|
err = vchan_destroy(c);
|
|
|
|
if (err)
|
|
|
|
device_printf(d->dev, "vchan_destroy(%s) == %d\n", c->name, err);
|
2002-05-19 06:31:56 +00:00
|
|
|
break; /* restart */
|
2001-08-23 11:30:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2001-06-14 13:31:30 +00:00
|
|
|
#ifdef USING_DEVFS
|
2000-09-01 20:09:24 +00:00
|
|
|
static int
|
2001-06-26 21:54:55 +00:00
|
|
|
sysctl_hw_snd_unit(SYSCTL_HANDLER_ARGS)
|
2000-09-01 20:09:24 +00:00
|
|
|
{
|
2001-06-14 13:31:30 +00:00
|
|
|
struct snddev_info *d;
|
2000-09-01 20:09:24 +00:00
|
|
|
int error, unit;
|
|
|
|
|
|
|
|
unit = snd_unit;
|
|
|
|
error = sysctl_handle_int(oidp, &unit, sizeof(unit), req);
|
|
|
|
if (error == 0 && req->newptr != NULL) {
|
2001-06-18 00:10:47 +00:00
|
|
|
if (unit < 0 || unit >= devclass_get_maxunit(pcm_devclass))
|
2001-06-14 13:31:30 +00:00
|
|
|
return EINVAL;
|
|
|
|
d = devclass_get_softc(pcm_devclass, unit);
|
2001-06-17 23:23:06 +00:00
|
|
|
if (d == NULL || SLIST_EMPTY(&d->channels))
|
2001-06-14 13:31:30 +00:00
|
|
|
return EINVAL;
|
2000-09-01 20:09:24 +00:00
|
|
|
snd_unit = unit;
|
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2001-01-03 01:25:26 +00:00
|
|
|
SYSCTL_PROC(_hw_snd, OID_AUTO, unit, CTLTYPE_INT | CTLFLAG_RW,
|
2001-06-26 21:54:55 +00:00
|
|
|
0, sizeof(int), sysctl_hw_snd_unit, "I", "");
|
2001-02-27 07:01:49 +00:00
|
|
|
#endif
|
2000-09-01 20:09:24 +00:00
|
|
|
|
2001-06-26 21:54:55 +00:00
|
|
|
static int
|
2001-08-23 11:30:52 +00:00
|
|
|
sysctl_hw_snd_maxautovchans(SYSCTL_HANDLER_ARGS)
|
2001-06-26 21:54:55 +00:00
|
|
|
{
|
2001-08-23 11:30:52 +00:00
|
|
|
struct snddev_info *d;
|
|
|
|
int i, v, error;
|
2001-06-27 19:59:45 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
v = snd_maxautovchans;
|
2001-06-27 19:59:45 +00:00
|
|
|
error = sysctl_handle_int(oidp, &v, sizeof(v), req);
|
|
|
|
if (error == 0 && req->newptr != NULL) {
|
|
|
|
if (v < 0 || v >= SND_MAXVCHANS)
|
|
|
|
return EINVAL;
|
2001-08-23 11:30:52 +00:00
|
|
|
if (v != snd_maxautovchans) {
|
|
|
|
for (i = 0; i < devclass_get_maxunit(pcm_devclass); i++) {
|
|
|
|
d = devclass_get_softc(pcm_devclass, i);
|
|
|
|
if (!d)
|
|
|
|
continue;
|
|
|
|
pcm_setmaxautovchans(d, v);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
snd_maxautovchans = v;
|
2001-06-27 19:59:45 +00:00
|
|
|
}
|
|
|
|
return (error);
|
|
|
|
}
|
2001-08-23 11:30:52 +00:00
|
|
|
SYSCTL_PROC(_hw_snd, OID_AUTO, maxautovchans, CTLTYPE_INT | CTLFLAG_RW,
|
|
|
|
0, sizeof(int), sysctl_hw_snd_maxautovchans, "I", "");
|
2001-06-27 19:59:45 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
struct pcm_channel *
|
|
|
|
pcm_chn_create(struct snddev_info *d, struct pcm_channel *parent, kobj_class_t cls, int dir, void *devinfo)
|
1999-09-01 04:08:39 +00:00
|
|
|
{
|
2001-05-27 17:22:00 +00:00
|
|
|
struct pcm_channel *ch;
|
2000-09-01 20:09:24 +00:00
|
|
|
char *dirs;
|
2001-09-18 14:50:52 +00:00
|
|
|
int err, *pnum;
|
1999-09-01 04:08:39 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
switch(dir) {
|
|
|
|
case PCMDIR_PLAY:
|
|
|
|
dirs = "play";
|
2001-09-18 14:50:52 +00:00
|
|
|
pnum = &d->playcount;
|
2001-05-27 17:22:00 +00:00
|
|
|
break;
|
2001-09-18 14:50:52 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
case PCMDIR_REC:
|
|
|
|
dirs = "record";
|
2001-09-18 14:50:52 +00:00
|
|
|
pnum = &d->reccount;
|
2001-05-27 17:22:00 +00:00
|
|
|
break;
|
2001-09-18 14:50:52 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
case PCMDIR_VIRTUAL:
|
|
|
|
dirs = "virtual";
|
|
|
|
dir = PCMDIR_PLAY;
|
2001-09-18 14:50:52 +00:00
|
|
|
pnum = &d->vchancount;
|
2001-05-27 17:22:00 +00:00
|
|
|
break;
|
2001-09-18 14:50:52 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
default:
|
|
|
|
return NULL;
|
2000-06-06 22:24:53 +00:00
|
|
|
}
|
2001-05-27 17:22:00 +00:00
|
|
|
|
|
|
|
ch = malloc(sizeof(*ch), M_DEVBUF, M_WAITOK | M_ZERO);
|
|
|
|
if (!ch)
|
|
|
|
return NULL;
|
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
ch->methods = kobj_create(cls, M_DEVBUF, M_WAITOK);
|
2001-05-27 17:22:00 +00:00
|
|
|
if (!ch->methods) {
|
|
|
|
free(ch, M_DEVBUF);
|
2001-09-18 14:50:52 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2001-09-18 14:50:52 +00:00
|
|
|
ch->num = (*pnum)++;
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
ch->pid = -1;
|
|
|
|
ch->parentsnddev = d;
|
|
|
|
ch->parentchannel = parent;
|
2002-01-25 04:14:12 +00:00
|
|
|
ch->dev = d->dev;
|
2001-09-18 14:50:52 +00:00
|
|
|
snprintf(ch->name, 32, "%s:%s:%d", device_get_nameunit(d->dev), dirs, ch->num);
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2000-12-18 01:36:41 +00:00
|
|
|
err = chn_init(ch, devinfo, dir);
|
|
|
|
if (err) {
|
2001-09-18 14:50:52 +00:00
|
|
|
device_printf(d->dev, "chn_init(%s) failed: err = %d\n", ch->name, err);
|
2001-05-27 17:22:00 +00:00
|
|
|
kobj_delete(ch->methods, M_DEVBUF);
|
|
|
|
free(ch, M_DEVBUF);
|
2001-09-18 14:50:52 +00:00
|
|
|
(*pnum)--;
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
return ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
|
|
|
pcm_chn_destroy(struct pcm_channel *ch)
|
|
|
|
{
|
2001-09-18 14:50:52 +00:00
|
|
|
struct snddev_info *d;
|
2001-05-27 17:22:00 +00:00
|
|
|
int err;
|
|
|
|
|
2001-09-18 14:50:52 +00:00
|
|
|
d = ch->parentsnddev;
|
2001-05-27 17:22:00 +00:00
|
|
|
err = chn_kill(ch);
|
|
|
|
if (err) {
|
2001-09-18 14:50:52 +00:00
|
|
|
device_printf(d->dev, "chn_kill(%s) failed, err = %d\n", ch->name, err);
|
2001-05-27 17:22:00 +00:00
|
|
|
return err;
|
2000-01-05 20:44:41 +00:00
|
|
|
}
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2001-09-18 14:50:52 +00:00
|
|
|
if (ch->direction == PCMDIR_REC)
|
|
|
|
d->reccount--;
|
|
|
|
else if (ch->flags & CHN_F_VIRTUAL)
|
|
|
|
d->vchancount--;
|
|
|
|
else
|
|
|
|
d->playcount--;
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
kobj_delete(ch->methods, M_DEVBUF);
|
|
|
|
free(ch, M_DEVBUF);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-06-27 19:59:45 +00:00
|
|
|
pcm_chn_add(struct snddev_info *d, struct pcm_channel *ch, int mkdev)
|
2001-05-27 17:22:00 +00:00
|
|
|
{
|
2001-08-23 11:30:52 +00:00
|
|
|
struct snddev_channel *sce, *tmp, *after;
|
2001-05-27 17:22:00 +00:00
|
|
|
int unit = device_get_unit(d->dev);
|
2001-06-14 13:31:30 +00:00
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
sce = malloc(sizeof(*sce), M_DEVBUF, M_WAITOK | M_ZERO);
|
|
|
|
if (!sce) {
|
|
|
|
return ENOMEM;
|
|
|
|
}
|
|
|
|
|
2002-07-22 02:38:20 +00:00
|
|
|
snd_mtxlock(d->lock);
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
sce->channel = ch;
|
2001-08-23 11:30:52 +00:00
|
|
|
if (SLIST_EMPTY(&d->channels)) {
|
|
|
|
SLIST_INSERT_HEAD(&d->channels, sce, link);
|
|
|
|
} else {
|
|
|
|
after = NULL;
|
|
|
|
SLIST_FOREACH(tmp, &d->channels, link) {
|
|
|
|
after = tmp;
|
|
|
|
}
|
|
|
|
SLIST_INSERT_AFTER(after, sce, link);
|
|
|
|
}
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2001-09-05 16:28:41 +00:00
|
|
|
if (mkdev) {
|
2001-06-27 19:59:45 +00:00
|
|
|
dsp_register(unit, d->devcount++);
|
2001-09-05 16:28:41 +00:00
|
|
|
if (ch->direction == PCMDIR_REC)
|
|
|
|
dsp_registerrec(unit, ch->num);
|
|
|
|
}
|
2001-06-14 13:31:30 +00:00
|
|
|
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2000-09-01 20:09:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
int
|
2001-06-27 19:59:45 +00:00
|
|
|
pcm_chn_remove(struct snddev_info *d, struct pcm_channel *ch, int rmdev)
|
2000-09-01 20:09:24 +00:00
|
|
|
{
|
2001-05-27 17:22:00 +00:00
|
|
|
struct snddev_channel *sce;
|
|
|
|
int unit = device_get_unit(d->dev);
|
2000-09-01 20:09:24 +00:00
|
|
|
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
if (sce->channel == ch)
|
|
|
|
goto gotit;
|
2000-09-01 20:09:24 +00:00
|
|
|
}
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
return EINVAL;
|
|
|
|
gotit:
|
|
|
|
SLIST_REMOVE(&d->channels, sce, snddev_channel, link);
|
|
|
|
free(sce, M_DEVBUF);
|
|
|
|
|
2001-09-05 16:28:41 +00:00
|
|
|
if (rmdev) {
|
2001-06-27 19:59:45 +00:00
|
|
|
dsp_unregister(unit, --d->devcount);
|
2001-09-05 16:28:41 +00:00
|
|
|
if (ch->direction == PCMDIR_REC)
|
2001-09-18 14:50:52 +00:00
|
|
|
dsp_unregisterrec(unit, ch->num);
|
2001-09-05 16:28:41 +00:00
|
|
|
}
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
|
1999-09-01 04:08:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2001-05-27 17:22:00 +00:00
|
|
|
int
|
|
|
|
pcm_addchan(device_t dev, int dir, kobj_class_t cls, void *devinfo)
|
|
|
|
{
|
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2001-08-23 11:30:52 +00:00
|
|
|
struct pcm_channel *ch;
|
|
|
|
int err;
|
2001-05-27 17:22:00 +00:00
|
|
|
|
|
|
|
ch = pcm_chn_create(d, NULL, cls, dir, devinfo);
|
|
|
|
if (!ch) {
|
|
|
|
device_printf(d->dev, "pcm_chn_create(%s, %d, %p) failed\n", cls->name, dir, devinfo);
|
|
|
|
return ENODEV;
|
|
|
|
}
|
2001-06-26 21:54:55 +00:00
|
|
|
|
2001-06-27 19:59:45 +00:00
|
|
|
err = pcm_chn_add(d, ch, 1);
|
2001-05-27 17:22:00 +00:00
|
|
|
if (err) {
|
|
|
|
device_printf(d->dev, "pcm_chn_add(%s) failed, err=%d\n", ch->name, err);
|
|
|
|
pcm_chn_destroy(ch);
|
2001-06-26 21:54:55 +00:00
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
2002-07-23 14:50:51 +00:00
|
|
|
if (snd_maxautovchans > 0 && (d->flags & SD_F_AUTOVCHAN) &&
|
|
|
|
ch->direction == PCMDIR_PLAY && d->vchancount == 0) {
|
2001-06-26 21:54:55 +00:00
|
|
|
ch->flags |= CHN_F_BUSY;
|
2001-08-23 11:30:52 +00:00
|
|
|
err = vchan_create(ch);
|
2001-06-26 21:54:55 +00:00
|
|
|
if (err) {
|
2001-08-23 11:30:52 +00:00
|
|
|
device_printf(d->dev, "vchan_create(%s) == %d\n", ch->name, err);
|
|
|
|
ch->flags &= ~CHN_F_BUSY;
|
2001-06-26 21:54:55 +00:00
|
|
|
}
|
2001-05-27 17:22:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
pcm_killchan(device_t dev)
|
|
|
|
{
|
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
|
|
|
struct snddev_channel *sce;
|
|
|
|
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
sce = SLIST_FIRST(&d->channels);
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2001-06-27 19:59:45 +00:00
|
|
|
return pcm_chn_remove(d, sce->channel, 1);
|
2001-05-27 17:22:00 +00:00
|
|
|
}
|
|
|
|
|
1999-09-01 04:08:39 +00:00
|
|
|
int
|
|
|
|
pcm_setstatus(device_t dev, char *str)
|
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2001-06-07 20:06:22 +00:00
|
|
|
|
|
|
|
snd_mtxlock(d->lock);
|
1999-09-01 04:08:39 +00:00
|
|
|
strncpy(d->status, str, SND_STATUSLEN);
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
1999-09-01 04:08:39 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
u_int32_t
|
|
|
|
pcm_getflags(device_t dev)
|
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2001-06-07 20:06:22 +00:00
|
|
|
|
1999-09-01 04:08:39 +00:00
|
|
|
return d->flags;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
|
|
|
pcm_setflags(device_t dev, u_int32_t val)
|
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2001-06-16 21:25:10 +00:00
|
|
|
|
1999-09-01 04:08:39 +00:00
|
|
|
d->flags = val;
|
|
|
|
}
|
|
|
|
|
2000-03-20 15:30:50 +00:00
|
|
|
void *
|
|
|
|
pcm_getdevinfo(device_t dev)
|
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2001-06-07 20:06:22 +00:00
|
|
|
|
2000-03-20 15:30:50 +00:00
|
|
|
return d->devinfo;
|
|
|
|
}
|
|
|
|
|
2001-09-18 14:50:52 +00:00
|
|
|
unsigned int
|
|
|
|
pcm_getbuffersize(device_t dev, unsigned int min, unsigned int deflt, unsigned int max)
|
|
|
|
{
|
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2002-01-23 05:49:41 +00:00
|
|
|
int sz, x;
|
2001-09-18 14:50:52 +00:00
|
|
|
|
|
|
|
sz = 0;
|
2002-01-23 05:49:41 +00:00
|
|
|
if (resource_int_value(device_get_name(dev), device_get_unit(dev), "buffersize", &sz) == 0) {
|
|
|
|
x = sz;
|
2001-09-18 14:50:52 +00:00
|
|
|
RANGE(sz, min, max);
|
2002-01-23 05:49:41 +00:00
|
|
|
if (x != sz)
|
|
|
|
device_printf(dev, "'buffersize=%d' hint is out of range (%d-%d), using %d\n", x, min, max, sz);
|
|
|
|
x = min;
|
|
|
|
while (x < sz)
|
|
|
|
x <<= 1;
|
|
|
|
if (x > sz)
|
|
|
|
x >>= 1;
|
|
|
|
if (x != sz) {
|
|
|
|
device_printf(dev, "'buffersize=%d' hint is not a power of 2, using %d\n", sz, x);
|
|
|
|
sz = x;
|
|
|
|
}
|
|
|
|
} else {
|
2001-09-18 14:50:52 +00:00
|
|
|
sz = deflt;
|
2002-01-23 05:49:41 +00:00
|
|
|
}
|
|
|
|
|
2001-09-18 14:50:52 +00:00
|
|
|
d->bufsz = sz;
|
|
|
|
|
|
|
|
return sz;
|
|
|
|
}
|
|
|
|
|
1999-09-01 04:08:39 +00:00
|
|
|
int
|
|
|
|
pcm_register(device_t dev, void *devinfo, int numplay, int numrec)
|
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
1999-09-01 04:08:39 +00:00
|
|
|
|
2002-01-26 22:13:24 +00:00
|
|
|
if (pcm_veto_load) {
|
|
|
|
device_printf(dev, "disabled due to an error while initialising: %d\n", pcm_veto_load);
|
|
|
|
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
2002-04-04 20:54:27 +00:00
|
|
|
d->lock = snd_mtxcreate(device_get_nameunit(dev), "sound cdev");
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
|
2001-06-26 21:54:55 +00:00
|
|
|
d->flags = 0;
|
2000-06-20 23:27:12 +00:00
|
|
|
d->dev = dev;
|
1999-09-01 04:08:39 +00:00
|
|
|
d->devinfo = devinfo;
|
2001-06-27 19:59:45 +00:00
|
|
|
d->devcount = 0;
|
2001-09-05 16:28:41 +00:00
|
|
|
d->reccount = 0;
|
2001-09-18 14:50:52 +00:00
|
|
|
d->playcount = 0;
|
2001-06-27 19:59:45 +00:00
|
|
|
d->vchancount = 0;
|
2001-06-16 21:25:10 +00:00
|
|
|
d->inprog = 0;
|
2000-01-06 04:11:36 +00:00
|
|
|
|
2001-06-16 21:25:10 +00:00
|
|
|
if (((numplay == 0) || (numrec == 0)) && (numplay != numrec))
|
2001-06-14 13:31:30 +00:00
|
|
|
d->flags |= SD_F_SIMPLEX;
|
2001-06-16 21:25:10 +00:00
|
|
|
|
2001-06-14 13:31:30 +00:00
|
|
|
d->fakechan = fkchan_setup(dev);
|
|
|
|
chn_init(d->fakechan, NULL, 0);
|
1999-09-01 04:08:39 +00:00
|
|
|
|
2001-02-27 07:01:49 +00:00
|
|
|
#ifdef SND_DYNSYSCTL
|
2001-01-05 07:07:03 +00:00
|
|
|
sysctl_ctx_init(&d->sysctl_tree);
|
|
|
|
d->sysctl_tree_top = SYSCTL_ADD_NODE(&d->sysctl_tree,
|
2001-01-11 23:22:33 +00:00
|
|
|
SYSCTL_STATIC_CHILDREN(_hw_snd), OID_AUTO,
|
2001-01-05 07:07:03 +00:00
|
|
|
device_get_nameunit(dev), CTLFLAG_RD, 0, "");
|
2001-01-11 23:22:33 +00:00
|
|
|
if (d->sysctl_tree_top == NULL) {
|
2001-01-05 07:07:03 +00:00
|
|
|
sysctl_ctx_free(&d->sysctl_tree);
|
|
|
|
goto no;
|
|
|
|
}
|
2001-09-18 14:50:52 +00:00
|
|
|
SYSCTL_ADD_INT(snd_sysctl_tree(dev), SYSCTL_CHILDREN(snd_sysctl_tree_top(dev)),
|
|
|
|
OID_AUTO, "buffersize", CTLFLAG_RD, &d->bufsz, 0, "");
|
2001-02-27 07:01:49 +00:00
|
|
|
#endif
|
2001-06-14 13:31:30 +00:00
|
|
|
if (numplay > 0)
|
2001-08-23 11:30:52 +00:00
|
|
|
vchan_initsys(dev);
|
2001-06-26 21:54:55 +00:00
|
|
|
if (numplay == 1)
|
|
|
|
d->flags |= SD_F_AUTOVCHAN;
|
|
|
|
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2001-08-23 11:30:52 +00:00
|
|
|
sndstat_register(dev, d->status, sndstat_prepare_pcm);
|
1999-09-01 04:08:39 +00:00
|
|
|
return 0;
|
|
|
|
no:
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxfree(d->lock);
|
1999-09-01 04:08:39 +00:00
|
|
|
return ENXIO;
|
|
|
|
}
|
|
|
|
|
2000-09-01 20:09:24 +00:00
|
|
|
int
|
|
|
|
pcm_unregister(device_t dev)
|
2000-08-29 16:21:33 +00:00
|
|
|
{
|
2001-03-24 23:10:29 +00:00
|
|
|
struct snddev_info *d = device_get_softc(dev);
|
2001-05-27 17:22:00 +00:00
|
|
|
struct snddev_channel *sce;
|
2001-09-18 14:50:52 +00:00
|
|
|
struct pcm_channel *ch;
|
2000-08-29 16:21:33 +00:00
|
|
|
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxlock(d->lock);
|
2001-06-16 21:25:10 +00:00
|
|
|
if (d->inprog) {
|
2001-09-14 20:26:03 +00:00
|
|
|
device_printf(dev, "unregister: operation in progress\n");
|
|
|
|
snd_mtxunlock(d->lock);
|
|
|
|
return EBUSY;
|
|
|
|
}
|
|
|
|
if (sndstat_busy() != 0) {
|
|
|
|
device_printf(dev, "unregister: sndstat busy\n");
|
2001-06-16 21:25:10 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
|
|
|
return EBUSY;
|
|
|
|
}
|
2001-05-27 17:22:00 +00:00
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
2001-09-18 14:50:52 +00:00
|
|
|
ch = sce->channel;
|
|
|
|
if (ch->refcount > 0) {
|
2002-04-28 22:59:45 +00:00
|
|
|
device_printf(dev, "unregister: channel %s busy (pid %d)\n", ch->name, ch->pid);
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2001-05-27 17:22:00 +00:00
|
|
|
return EBUSY;
|
|
|
|
}
|
2000-09-05 20:58:51 +00:00
|
|
|
}
|
2001-06-16 21:25:10 +00:00
|
|
|
if (mixer_uninit(dev)) {
|
2001-09-14 20:26:03 +00:00
|
|
|
device_printf(dev, "unregister: mixer busy\n");
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
2000-09-05 20:58:51 +00:00
|
|
|
return EBUSY;
|
|
|
|
}
|
2000-08-29 16:21:33 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
#ifdef SND_DYNSYSCTL
|
|
|
|
d->sysctl_tree_top = NULL;
|
|
|
|
sysctl_ctx_free(&d->sysctl_tree);
|
|
|
|
#endif
|
2001-06-17 23:23:06 +00:00
|
|
|
while (!SLIST_EMPTY(&d->channels))
|
2001-05-27 17:22:00 +00:00
|
|
|
pcm_killchan(dev);
|
2000-08-29 16:21:33 +00:00
|
|
|
|
2001-03-24 23:10:29 +00:00
|
|
|
chn_kill(d->fakechan);
|
|
|
|
fkchan_kill(d->fakechan);
|
2001-02-27 07:01:49 +00:00
|
|
|
|
2001-06-07 20:06:22 +00:00
|
|
|
snd_mtxfree(d->lock);
|
2000-09-01 20:09:24 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2000-08-29 16:21:33 +00:00
|
|
|
|
2001-08-23 11:30:52 +00:00
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
static int
|
|
|
|
sndstat_prepare_pcm(struct sbuf *s, device_t dev, int verbose)
|
|
|
|
{
|
|
|
|
struct snddev_info *d;
|
|
|
|
struct snddev_channel *sce;
|
|
|
|
struct pcm_channel *c;
|
|
|
|
struct pcm_feeder *f;
|
|
|
|
int pc, rc, vc;
|
|
|
|
|
|
|
|
if (verbose < 1)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
d = device_get_softc(dev);
|
|
|
|
if (!d)
|
|
|
|
return ENXIO;
|
|
|
|
|
|
|
|
snd_mtxlock(d->lock);
|
|
|
|
if (!SLIST_EMPTY(&d->channels)) {
|
|
|
|
pc = rc = vc = 0;
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
if (c->direction == PCMDIR_PLAY) {
|
|
|
|
if (c->flags & CHN_F_VIRTUAL)
|
|
|
|
vc++;
|
|
|
|
else
|
|
|
|
pc++;
|
|
|
|
} else
|
|
|
|
rc++;
|
|
|
|
}
|
2001-09-18 14:50:52 +00:00
|
|
|
sbuf_printf(s, " (%dp/%dr/%dv channels%s%s)", d->playcount, d->reccount, d->vchancount,
|
2001-08-23 11:30:52 +00:00
|
|
|
(d->flags & SD_F_SIMPLEX)? "" : " duplex",
|
|
|
|
#ifdef USING_DEVFS
|
|
|
|
(device_get_unit(dev) == snd_unit)? " default" : ""
|
|
|
|
#else
|
|
|
|
""
|
|
|
|
#endif
|
|
|
|
);
|
|
|
|
if (verbose <= 1)
|
|
|
|
goto skipverbose;
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
2001-08-29 02:49:54 +00:00
|
|
|
sbuf_printf(s, "\n\t");
|
|
|
|
|
|
|
|
sbuf_printf(s, "%s[%s]: ", c->parentchannel? c->parentchannel->name : "", c->name);
|
2002-01-23 06:02:15 +00:00
|
|
|
sbuf_printf(s, "spd %d", c->speed);
|
|
|
|
if (c->speed != sndbuf_getspd(c->bufhard))
|
|
|
|
sbuf_printf(s, "/%d", sndbuf_getspd(c->bufhard));
|
|
|
|
sbuf_printf(s, ", fmt 0x%08x", c->format);
|
|
|
|
if (c->format != sndbuf_getfmt(c->bufhard))
|
|
|
|
sbuf_printf(s, "/0x%08x", sndbuf_getfmt(c->bufhard));
|
|
|
|
sbuf_printf(s, ", flags %08x", c->flags);
|
2001-08-23 11:30:52 +00:00
|
|
|
if (c->pid != -1)
|
|
|
|
sbuf_printf(s, ", pid %d", c->pid);
|
|
|
|
sbuf_printf(s, "\n\t");
|
2002-01-23 06:02:15 +00:00
|
|
|
|
2001-08-29 09:17:43 +00:00
|
|
|
if (c->bufhard != NULL && c->bufsoft != NULL) {
|
2001-08-29 02:49:54 +00:00
|
|
|
sbuf_printf(s, "interrupts %d, ", c->interrupts);
|
|
|
|
if (c->direction == PCMDIR_REC)
|
|
|
|
sbuf_printf(s, "overruns %d, hfree %d, sfree %d",
|
|
|
|
c->xruns, sndbuf_getfree(c->bufhard), sndbuf_getfree(c->bufsoft));
|
|
|
|
else
|
2001-08-29 09:17:43 +00:00
|
|
|
sbuf_printf(s, "underruns %d, ready %d",
|
|
|
|
c->xruns, sndbuf_getready(c->bufsoft));
|
2001-08-29 02:49:54 +00:00
|
|
|
sbuf_printf(s, "\n\t");
|
|
|
|
}
|
2002-01-23 06:02:15 +00:00
|
|
|
|
|
|
|
sbuf_printf(s, "{%s}", (c->direction == PCMDIR_REC)? "hardware" : "userland");
|
|
|
|
sbuf_printf(s, " -> ");
|
2001-08-23 11:30:52 +00:00
|
|
|
f = c->feeder;
|
2002-01-23 06:02:15 +00:00
|
|
|
while (f->source != NULL)
|
|
|
|
f = f->source;
|
|
|
|
while (f != NULL) {
|
2001-08-23 11:30:52 +00:00
|
|
|
sbuf_printf(s, "%s", f->class->name);
|
|
|
|
if (f->desc->type == FEEDER_FMT)
|
2002-01-23 06:02:15 +00:00
|
|
|
sbuf_printf(s, "(0x%08x -> 0x%08x)", f->desc->in, f->desc->out);
|
2001-08-23 11:30:52 +00:00
|
|
|
if (f->desc->type == FEEDER_RATE)
|
2002-01-23 06:02:15 +00:00
|
|
|
sbuf_printf(s, "(%d -> %d)", FEEDER_GET(f, FEEDRATE_SRC), FEEDER_GET(f, FEEDRATE_DST));
|
2001-08-23 11:30:52 +00:00
|
|
|
if (f->desc->type == FEEDER_ROOT || f->desc->type == FEEDER_MIXER)
|
2002-01-23 06:02:15 +00:00
|
|
|
sbuf_printf(s, "(0x%08x)", f->desc->out);
|
|
|
|
sbuf_printf(s, " -> ");
|
|
|
|
f = f->parent;
|
2001-08-23 11:30:52 +00:00
|
|
|
}
|
2002-01-23 06:02:15 +00:00
|
|
|
sbuf_printf(s, "{%s}", (c->direction == PCMDIR_REC)? "userland" : "hardware");
|
2001-08-23 11:30:52 +00:00
|
|
|
}
|
|
|
|
} else
|
|
|
|
sbuf_printf(s, " (mixer only)");
|
2002-05-19 06:31:56 +00:00
|
|
|
skipverbose:
|
2001-08-23 11:30:52 +00:00
|
|
|
snd_mtxunlock(d->lock);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
|
|
|
#ifdef SND_DYNSYSCTL
|
|
|
|
int
|
|
|
|
sysctl_hw_snd_vchans(SYSCTL_HANDLER_ARGS)
|
|
|
|
{
|
|
|
|
struct snddev_info *d;
|
|
|
|
struct snddev_channel *sce;
|
|
|
|
struct pcm_channel *c;
|
|
|
|
int err, oldcnt, newcnt, cnt;
|
|
|
|
|
|
|
|
d = oidp->oid_arg1;
|
|
|
|
|
|
|
|
pcm_lock(d);
|
|
|
|
cnt = 0;
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
if ((c->direction == PCMDIR_PLAY) && (c->flags & CHN_F_VIRTUAL))
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
oldcnt = cnt;
|
|
|
|
newcnt = cnt;
|
|
|
|
|
|
|
|
err = sysctl_handle_int(oidp, &newcnt, sizeof(newcnt), req);
|
|
|
|
if (err == 0 && req->newptr != NULL) {
|
|
|
|
if (newcnt < 0 || newcnt > SND_MAXVCHANS) {
|
|
|
|
pcm_unlock(d);
|
|
|
|
return EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (newcnt > cnt) {
|
|
|
|
/* add new vchans - find a parent channel first */
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
/* not a candidate if not a play channel */
|
|
|
|
if (c->direction != PCMDIR_PLAY)
|
2002-05-19 06:31:56 +00:00
|
|
|
continue;
|
2001-08-23 11:30:52 +00:00
|
|
|
/* not a candidate if a virtual channel */
|
|
|
|
if (c->flags & CHN_F_VIRTUAL)
|
2002-05-19 06:31:56 +00:00
|
|
|
continue;
|
2001-08-23 11:30:52 +00:00
|
|
|
/* not a candidate if it's in use */
|
|
|
|
if ((c->flags & CHN_F_BUSY) && (SLIST_EMPTY(&c->children)))
|
2002-05-19 06:31:56 +00:00
|
|
|
continue;
|
2001-08-23 11:30:52 +00:00
|
|
|
/*
|
|
|
|
* if we get here we're a nonvirtual play channel, and either
|
|
|
|
* 1) not busy
|
|
|
|
* 2) busy with children, not directly open
|
|
|
|
*
|
|
|
|
* thus we can add children
|
|
|
|
*/
|
|
|
|
goto addok;
|
|
|
|
}
|
|
|
|
pcm_unlock(d);
|
|
|
|
return EBUSY;
|
|
|
|
addok:
|
|
|
|
c->flags |= CHN_F_BUSY;
|
|
|
|
while (err == 0 && newcnt > cnt) {
|
|
|
|
err = vchan_create(c);
|
|
|
|
if (err == 0)
|
|
|
|
cnt++;
|
|
|
|
}
|
|
|
|
if (SLIST_EMPTY(&c->children))
|
|
|
|
c->flags &= ~CHN_F_BUSY;
|
|
|
|
} else if (newcnt < cnt) {
|
|
|
|
while (err == 0 && newcnt < cnt) {
|
|
|
|
SLIST_FOREACH(sce, &d->channels, link) {
|
|
|
|
c = sce->channel;
|
|
|
|
if ((c->flags & (CHN_F_BUSY | CHN_F_VIRTUAL)) == CHN_F_VIRTUAL)
|
|
|
|
goto remok;
|
|
|
|
}
|
|
|
|
pcm_unlock(d);
|
|
|
|
return EINVAL;
|
|
|
|
remok:
|
|
|
|
err = vchan_destroy(c);
|
|
|
|
if (err == 0)
|
|
|
|
cnt--;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
pcm_unlock(d);
|
|
|
|
return err;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/************************************************************************/
|
|
|
|
|
2000-09-01 20:09:24 +00:00
|
|
|
static moduledata_t sndpcm_mod = {
|
|
|
|
"snd_pcm",
|
2001-06-16 21:25:10 +00:00
|
|
|
NULL,
|
2000-09-01 20:09:24 +00:00
|
|
|
NULL
|
|
|
|
};
|
|
|
|
DECLARE_MODULE(snd_pcm, sndpcm_mod, SI_SUB_DRIVERS, SI_ORDER_MIDDLE);
|
|
|
|
MODULE_VERSION(snd_pcm, PCM_MODVER);
|