aboutsummaryrefslogtreecommitdiff
path: root/sys/dev/sound/pcm/mixer.c
diff options
context:
space:
mode:
Diffstat (limited to 'sys/dev/sound/pcm/mixer.c')
-rw-r--r--sys/dev/sound/pcm/mixer.c178
1 files changed, 52 insertions, 126 deletions
diff --git a/sys/dev/sound/pcm/mixer.c b/sys/dev/sound/pcm/mixer.c
index f281dff36248..f6eb669010b5 100644
--- a/sys/dev/sound/pcm/mixer.c
+++ b/sys/dev/sound/pcm/mixer.c
@@ -48,7 +48,6 @@ SYSCTL_INT(_hw_snd, OID_AUTO, vpc_mixer_bypass, CTLFLAG_RWTUN,
struct snd_mixer {
KOBJ_FIELDS;
void *devinfo;
- int busy;
int hwvol_mixer;
int hwvol_step;
int type;
@@ -63,13 +62,8 @@ struct snd_mixer {
u_int32_t child[32];
u_int8_t realdev[32];
char name[MIXER_NAMELEN];
- struct mtx *lock;
+ struct mtx lock;
oss_mixer_enuminfo enuminfo;
- /**
- * Counter is incremented when applications change any of this
- * mixer's controls. A change in value indicates that persistent
- * mixer applications should update their displays.
- */
int modify_counter;
};
@@ -131,12 +125,12 @@ mixer_lookup(char *devname)
#define MIXER_SET_UNLOCK(x, y) do { \
if ((y) != 0) \
- snd_mtxunlock((x)->lock); \
+ mtx_unlock(&(x)->lock); \
} while (0)
#define MIXER_SET_LOCK(x, y) do { \
if ((y) != 0) \
- snd_mtxlock((x)->lock); \
+ mtx_lock(&(x)->lock); \
} while (0)
static int
@@ -149,12 +143,12 @@ mixer_set_softpcmvol(struct snd_mixer *m, struct snddev_info *d,
if (!PCM_REGISTERED(d))
return (EINVAL);
- if (mtx_owned(m->lock))
+ if (mtx_owned(&m->lock))
dropmtx = 1;
else
dropmtx = 0;
- if (!(d->flags & SD_F_MPSAFE) || mtx_owned(d->lock) != 0)
+ if (!(d->flags & SD_F_MPSAFE) || mtx_owned(&d->lock) != 0)
acquiremtx = 0;
else
acquiremtx = 1;
@@ -202,12 +196,12 @@ mixer_set_eq(struct snd_mixer *m, struct snddev_info *d,
if (!PCM_REGISTERED(d))
return (EINVAL);
- if (mtx_owned(m->lock))
+ if (mtx_owned(&m->lock))
dropmtx = 1;
else
dropmtx = 0;
- if (!(d->flags & SD_F_MPSAFE) || mtx_owned(d->lock) != 0)
+ if (!(d->flags & SD_F_MPSAFE) || mtx_owned(&d->lock) != 0)
acquiremtx = 0;
else
acquiremtx = 1;
@@ -258,7 +252,7 @@ mixer_set(struct snd_mixer *m, u_int dev, u_int32_t muted, u_int lev)
return (-1);
/* It is safe to drop this mutex due to Giant. */
- if (!(d->flags & SD_F_MPSAFE) && mtx_owned(m->lock) != 0)
+ if (!(d->flags & SD_F_MPSAFE) && mtx_owned(&m->lock) != 0)
dropmtx = 1;
else
dropmtx = 0;
@@ -372,7 +366,7 @@ mixer_setrecsrc(struct snd_mixer *mixer, u_int32_t src)
d = device_get_softc(mixer->dev);
if (d == NULL)
return -1;
- if (!(d->flags & SD_F_MPSAFE) && mtx_owned(mixer->lock) != 0)
+ if (!(d->flags & SD_F_MPSAFE) && mtx_owned(&mixer->lock) != 0)
dropmtx = 1;
else
dropmtx = 0;
@@ -609,14 +603,6 @@ mix_getparent(struct snd_mixer *m, u_int32_t dev)
}
u_int32_t
-mix_getchild(struct snd_mixer *m, u_int32_t dev)
-{
- if (m == NULL || dev >= SOUND_MIXER_NRDEVICES)
- return 0;
- return m->child[dev];
-}
-
-u_int32_t
mix_getdevs(struct snd_mixer *m)
{
return m->devs;
@@ -660,11 +646,10 @@ mixer_obj_create(device_t dev, kobj_class_t cls, void *devinfo,
strlcat(m->name, ":", sizeof(m->name));
strlcat(m->name, desc, sizeof(m->name));
}
- m->lock = snd_mtxcreate(m->name, (type == MIXER_TYPE_PRIMARY) ?
- "primary pcm mixer" : "secondary pcm mixer");
+ mtx_init(&m->lock, m->name, (type == MIXER_TYPE_PRIMARY) ?
+ "primary pcm mixer" : "secondary pcm mixer", MTX_DEF);
m->type = type;
m->devinfo = devinfo;
- m->busy = 0;
m->dev = dev;
for (i = 0; i < nitems(m->parent); i++) {
m->parent[i] = SOUND_MIXER_NONE;
@@ -673,8 +658,8 @@ mixer_obj_create(device_t dev, kobj_class_t cls, void *devinfo,
}
if (MIXER_INIT(m)) {
- snd_mtxlock(m->lock);
- snd_mtxfree(m->lock);
+ mtx_lock(&m->lock);
+ mtx_destroy(&m->lock);
kobj_delete((kobj_t)m, M_MIXER);
return (NULL);
}
@@ -693,7 +678,7 @@ mixer_delete(struct snd_mixer *m)
MIXER_UNINIT(m);
- snd_mtxfree(m->lock);
+ mtx_destroy(&m->lock);
kobj_delete((kobj_t)m, M_MIXER);
return (0);
@@ -805,20 +790,20 @@ mixer_uninit(device_t dev)
pdev->si_drv1 = NULL;
destroy_dev(pdev);
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
for (i = 0; i < SOUND_MIXER_NRDEVICES; i++)
mixer_set(m, i, 0, 0);
mixer_setrecsrc(m, SOUND_MASK_MIC);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
/* mixer uninit can sleep --hps */
MIXER_UNINIT(m);
- snd_mtxfree(m->lock);
+ mtx_destroy(&m->lock);
kobj_delete((kobj_t)m, M_MIXER);
d->mixer_dev = NULL;
@@ -835,11 +820,11 @@ mixer_reinit(device_t dev)
pdev = mixer_get_devt(dev);
m = pdev->si_drv1;
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
i = MIXER_REINIT(m);
if (i) {
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return i;
}
@@ -851,7 +836,7 @@ mixer_reinit(device_t dev)
}
mixer_setrecsrc(m, m->recsrc);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return 0;
}
@@ -864,21 +849,21 @@ sysctl_hw_snd_hwvol_mixer(SYSCTL_HANDLER_ARGS)
struct snd_mixer *m;
m = oidp->oid_arg1;
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
strlcpy(devname, snd_mixernames[m->hwvol_mixer], sizeof(devname));
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
error = sysctl_handle_string(oidp, &devname[0], sizeof(devname), req);
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
if (error == 0 && req->newptr != NULL) {
dev = mixer_lookup(devname);
if (dev == -1) {
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return EINVAL;
} else {
m->hwvol_mixer = dev;
}
}
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return error;
}
@@ -917,9 +902,9 @@ mixer_hwvol_mute(device_t dev)
pdev = mixer_get_devt(dev);
m = pdev->si_drv1;
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
mixer_hwvol_mute_locked(m);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
}
void
@@ -955,17 +940,9 @@ mixer_hwvol_step(device_t dev, int left_step, int right_step)
pdev = mixer_get_devt(dev);
m = pdev->si_drv1;
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
mixer_hwvol_step_locked(m, left_step, right_step);
- snd_mtxunlock(m->lock);
-}
-
-int
-mixer_busy(struct snd_mixer *m)
-{
- KASSERT(m != NULL, ("NULL snd_mixer"));
-
- return (m->busy);
+ mtx_unlock(&m->lock);
}
int
@@ -975,9 +952,9 @@ mix_set(struct snd_mixer *m, u_int dev, u_int left, u_int right)
KASSERT(m != NULL, ("NULL snd_mixer"));
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
ret = mixer_set(m, dev, m->mutedevs, left | (right << 8));
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return ((ret != 0) ? ENXIO : 0);
}
@@ -989,9 +966,9 @@ mix_get(struct snd_mixer *m, u_int dev)
KASSERT(m != NULL, ("NULL snd_mixer"));
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
ret = mixer_get(m, dev);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return (ret);
}
@@ -1003,9 +980,9 @@ mix_setrecsrc(struct snd_mixer *m, u_int32_t src)
KASSERT(m != NULL, ("NULL snd_mixer"));
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
ret = mixer_setrecsrc(m, src);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return ((ret != 0) ? ENXIO : 0);
}
@@ -1017,21 +994,13 @@ mix_getrecsrc(struct snd_mixer *m)
KASSERT(m != NULL, ("NULL snd_mixer"));
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
ret = mixer_getrecsrc(m);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return (ret);
}
-int
-mix_get_type(struct snd_mixer *m)
-{
- KASSERT(m != NULL, ("NULL snd_mixer"));
-
- return (m->type);
-}
-
device_t
mix_get_dev(struct snd_mixer *m)
{
@@ -1056,12 +1025,6 @@ mixer_open(struct cdev *i_dev, int flags, int mode, struct thread *td)
if (!PCM_REGISTERED(d))
return (EBADF);
- /* XXX Need Giant magic entry ??? */
-
- snd_mtxlock(m->lock);
- m->busy = 1;
- snd_mtxunlock(m->lock);
-
return (0);
}
@@ -1070,7 +1033,6 @@ mixer_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
{
struct snddev_info *d;
struct snd_mixer *m;
- int ret;
if (i_dev == NULL || i_dev->si_drv1 == NULL)
return (EBADF);
@@ -1080,14 +1042,7 @@ mixer_close(struct cdev *i_dev, int flags, int mode, struct thread *td)
if (!PCM_REGISTERED(d))
return (EBADF);
- /* XXX Need Giant magic entry ??? */
-
- snd_mtxlock(m->lock);
- ret = (m->busy == 0) ? EBADF : 0;
- m->busy = 0;
- snd_mtxunlock(m->lock);
-
- return (ret);
+ return (0);
}
static int
@@ -1163,9 +1118,9 @@ mixer_ioctl_channel(struct cdev *dev, u_long cmd, caddr_t arg, int mode,
if ((j == SOUND_MIXER_DEVMASK || j == SOUND_MIXER_CAPS ||
j == SOUND_MIXER_STEREODEVS) &&
(cmd & ~0xff) == MIXER_READ(0)) {
- snd_mtxlock(m->lock);
+ mtx_lock(&m->lock);
*(int *)arg = mix_getdevs(m);
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
if (rdch != NULL)
*(int *)arg |= SOUND_MASK_RECLEV;
if (wrch != NULL)
@@ -1282,11 +1237,7 @@ mixer_ioctl_cmd(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
if (m == NULL)
return (EBADF);
- snd_mtxlock(m->lock);
- if (from == MIXER_CMD_CDEV && !m->busy) {
- snd_mtxunlock(m->lock);
- return (EBADF);
- }
+ mtx_lock(&m->lock);
switch (cmd) {
case SNDCTL_DSP_GET_RECSRC_NAMES:
bcopy((void *)&m->enuminfo, arg, sizeof(oss_mixer_enuminfo));
@@ -1320,7 +1271,7 @@ mixer_ioctl_cmd(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
ret = mixer_set(m, j, m->mutedevs, *arg_i);
break;
}
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return ((ret == 0) ? 0 : ENXIO);
}
if ((cmd & ~0xff) == MIXER_READ(0)) {
@@ -1344,11 +1295,11 @@ mixer_ioctl_cmd(struct cdev *i_dev, u_long cmd, caddr_t arg, int mode,
break;
}
*arg_i = v;
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return ((v != -1) ? 0 : ENXIO);
}
done:
- snd_mtxunlock(m->lock);
+ mtx_unlock(&m->lock);
return (ret);
}
@@ -1477,7 +1428,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
}
m = d->mixer_dev->si_drv1;
- mtx_lock(m->lock);
+ mtx_lock(&m->lock);
/*
* At this point, the following synchronization stuff
@@ -1490,6 +1441,11 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
mi->dev = i;
snprintf(mi->id, sizeof(mi->id), "mixer%d", i);
strlcpy(mi->name, m->name, sizeof(mi->name));
+ /**
+ * Counter is incremented when applications change any of this
+ * mixer's controls. A change in value indicates that
+ * persistent mixer applications should update their displays.
+ */
mi->modify_counter = m->modify_counter;
mi->card_number = i;
/*
@@ -1549,7 +1505,7 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
snprintf(mi->devnode, sizeof(mi->devnode), "/dev/mixer%d", i);
mi->legacy_device = i;
- mtx_unlock(m->lock);
+ mtx_unlock(&m->lock);
PCM_UNLOCK(d);
@@ -1568,35 +1524,5 @@ mixer_oss_mixerinfo(struct cdev *i_dev, oss_mixerinfo *mi)
struct mtx *
mixer_get_lock(struct snd_mixer *m)
{
- if (m->lock == NULL) {
- return (&Giant);
- }
- return (m->lock);
-}
-
-int
-mix_get_locked(struct snd_mixer *m, u_int dev, int *pleft, int *pright)
-{
- int level;
-
- level = mixer_get(m, dev);
- if (level < 0) {
- *pright = *pleft = -1;
- return (-1);
- }
-
- *pleft = level & 0xFF;
- *pright = (level >> 8) & 0xFF;
-
- return (0);
-}
-
-int
-mix_set_locked(struct snd_mixer *m, u_int dev, int left, int right)
-{
- int level;
-
- level = (left & 0xFF) | ((right & 0xFF) << 8);
-
- return (mixer_set(m, dev, m->mutedevs, level));
+ return (&m->lock);
}