mirror of
https://git.FreeBSD.org/src.git
synced 2024-12-17 10:26:15 +00:00
add defines and ifdefs so this code will compile on 4.x
add spls so this code will work on 4.x
This commit is contained in:
parent
8c8e8f8013
commit
f00f162a5f
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=78670
@ -105,7 +105,11 @@ chn_sleep(struct pcm_channel *c, char *str, int timeout)
|
||||
int ret;
|
||||
|
||||
CHN_LOCKASSERT(c);
|
||||
#ifdef USING_MUTEX
|
||||
ret = msleep(bs, c->lock, PRIBIO | PCATCH, str, timeout);
|
||||
#else
|
||||
ret = tsleep(bs, PRIBIO | PCATCH, str, timeout);
|
||||
#endif
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -97,9 +97,15 @@ void chn_rdupdate(struct pcm_channel *c);
|
||||
|
||||
int chn_notify(struct pcm_channel *c, u_int32_t flags);
|
||||
|
||||
#ifdef USING_MUTEX
|
||||
#define CHN_LOCK(c) mtx_lock((struct mtx *)((c)->lock))
|
||||
#define CHN_UNLOCK(c) mtx_unlock((struct mtx *)((c)->lock))
|
||||
#define CHN_LOCKASSERT(c)
|
||||
#else
|
||||
#define CHN_LOCK(c)
|
||||
#define CHN_UNLOCK(c)
|
||||
#define CHN_LOCKASSERT(c)
|
||||
#endif
|
||||
|
||||
int fmtvalid(u_int32_t fmt, u_int32_t *fmtlist);
|
||||
|
||||
|
@ -57,7 +57,9 @@ static struct cdevsw dsp_cdevsw = {
|
||||
/* flags */ 0,
|
||||
};
|
||||
|
||||
#ifdef USING_DEVFS
|
||||
static eventhandler_tag dsp_ehtag;
|
||||
#endif
|
||||
|
||||
static struct snddev_info *
|
||||
dsp_get_info(dev_t dev)
|
||||
@ -139,9 +141,11 @@ dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
{
|
||||
struct pcm_channel *rdch, *wrch;
|
||||
struct snddev_info *d;
|
||||
intrmask_t s;
|
||||
u_int32_t fmt;
|
||||
int devtype;
|
||||
|
||||
s = spltty();
|
||||
d = dsp_get_info(i_dev);
|
||||
devtype = PCMDEV(i_dev);
|
||||
|
||||
@ -172,6 +176,7 @@ dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
if ((d->flags & SD_F_SIMPLEX) && (i_dev->si_drv1 || i_dev->si_drv2)) {
|
||||
/* simplex device, already open, exit */
|
||||
snd_mtxunlock(d->lock);
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
@ -187,12 +192,14 @@ dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
if (!rdch) {
|
||||
/* no channel available, exit */
|
||||
snd_mtxunlock(d->lock);
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
/* got a channel, already locked for us */
|
||||
} else {
|
||||
/* already open for read, exit */
|
||||
snd_mtxunlock(d->lock);
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
}
|
||||
@ -210,6 +217,7 @@ dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
}
|
||||
/* exit */
|
||||
snd_mtxunlock(d->lock);
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
/* got a channel, already locked for us */
|
||||
@ -221,6 +229,7 @@ dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
}
|
||||
/* exit */
|
||||
snd_mtxunlock(d->lock);
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
}
|
||||
@ -253,6 +262,7 @@ dsp_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
}
|
||||
CHN_UNLOCK(wrch);
|
||||
}
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -261,8 +271,10 @@ dsp_close(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
{
|
||||
struct pcm_channel *rdch, *wrch;
|
||||
struct snddev_info *d;
|
||||
intrmask_t s;
|
||||
int exit;
|
||||
|
||||
s = spltty();
|
||||
d = dsp_get_info(i_dev);
|
||||
snd_mtxlock(d->lock);
|
||||
rdch = i_dev->si_drv1;
|
||||
@ -287,6 +299,7 @@ dsp_close(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
}
|
||||
if (exit) {
|
||||
snd_mtxunlock(d->lock);
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -314,6 +327,7 @@ dsp_close(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
pcm_chnrelease(wrch);
|
||||
}
|
||||
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -321,8 +335,10 @@ static int
|
||||
dsp_read(dev_t i_dev, struct uio *buf, int flag)
|
||||
{
|
||||
struct pcm_channel *rdch, *wrch;
|
||||
intrmask_t s;
|
||||
int ret;
|
||||
|
||||
s = spltty();
|
||||
getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD);
|
||||
|
||||
KASSERT(rdch, ("dsp_read: nonexistant channel"));
|
||||
@ -330,6 +346,7 @@ dsp_read(dev_t i_dev, struct uio *buf, int flag)
|
||||
|
||||
if (rdch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
|
||||
splx(s);
|
||||
return EINVAL;
|
||||
}
|
||||
if (!(rdch->flags & CHN_F_RUNNING))
|
||||
@ -337,6 +354,7 @@ dsp_read(dev_t i_dev, struct uio *buf, int flag)
|
||||
ret = chn_read(rdch, buf);
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_RD);
|
||||
|
||||
splx(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -344,8 +362,10 @@ static int
|
||||
dsp_write(dev_t i_dev, struct uio *buf, int flag)
|
||||
{
|
||||
struct pcm_channel *rdch, *wrch;
|
||||
intrmask_t s;
|
||||
int ret;
|
||||
|
||||
s = spltty();
|
||||
getchns(i_dev, &rdch, &wrch, SD_F_PRIO_WR);
|
||||
|
||||
KASSERT(wrch, ("dsp_write: nonexistant channel"));
|
||||
@ -353,6 +373,7 @@ dsp_write(dev_t i_dev, struct uio *buf, int flag)
|
||||
|
||||
if (wrch->flags & (CHN_F_MAPPED | CHN_F_DEAD)) {
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
|
||||
splx(s);
|
||||
return EINVAL;
|
||||
}
|
||||
if (!(wrch->flags & CHN_F_RUNNING))
|
||||
@ -360,6 +381,7 @@ dsp_write(dev_t i_dev, struct uio *buf, int flag)
|
||||
ret = chn_write(wrch, buf);
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_WR);
|
||||
|
||||
splx(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -368,9 +390,9 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
{
|
||||
struct pcm_channel *wrch, *rdch;
|
||||
struct snddev_info *d;
|
||||
intrmask_t s;
|
||||
int kill;
|
||||
int ret = 0, *arg_i = (int *)arg, tmp;
|
||||
u_long s;
|
||||
|
||||
/*
|
||||
* this is an evil hack to allow broken apps to perform mixer ioctls
|
||||
@ -384,6 +406,7 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
return mixer_ioctl(pdev, cmd, arg, mode, p);
|
||||
}
|
||||
|
||||
s = spltty();
|
||||
d = dsp_get_info(i_dev);
|
||||
getchns(i_dev, &rdch, &wrch, 0);
|
||||
|
||||
@ -394,6 +417,7 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
kill |= 2;
|
||||
if (kill == 3) {
|
||||
relchns(i_dev, rdch, wrch, 0);
|
||||
splx(s);
|
||||
return EINVAL;
|
||||
}
|
||||
if (kill & 1)
|
||||
@ -405,7 +429,6 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
* all routines are called with int. blocked. Make sure that
|
||||
* ints are re-enabled when calling slow or blocking functions!
|
||||
*/
|
||||
s = spltty();
|
||||
switch(cmd) {
|
||||
#ifdef OLDPCM_IOCTL
|
||||
/*
|
||||
@ -902,9 +925,11 @@ dsp_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
static int
|
||||
dsp_poll(dev_t i_dev, int events, struct proc *p)
|
||||
{
|
||||
int ret, e;
|
||||
struct pcm_channel *wrch = NULL, *rdch = NULL;
|
||||
intrmask_t s;
|
||||
int ret, e;
|
||||
|
||||
s = spltty();
|
||||
ret = 0;
|
||||
getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
|
||||
|
||||
@ -920,6 +945,7 @@ dsp_poll(dev_t i_dev, int events, struct proc *p)
|
||||
}
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
|
||||
|
||||
splx(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -927,11 +953,13 @@ static int
|
||||
dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot)
|
||||
{
|
||||
struct pcm_channel *wrch = NULL, *rdch = NULL, *c;
|
||||
intrmask_t s;
|
||||
int ret;
|
||||
|
||||
if (nprot & PROT_EXEC)
|
||||
return -1;
|
||||
|
||||
s = spltty();
|
||||
getchns(i_dev, &rdch, &wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
|
||||
#if 0
|
||||
/*
|
||||
@ -939,18 +967,21 @@ dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot)
|
||||
* our vm system doesn't allow this, so force write buffer
|
||||
*/
|
||||
|
||||
if (wrch && (nprot & PROT_WRITE))
|
||||
if (wrch && (nprot & PROT_WRITE)) {
|
||||
c = wrch;
|
||||
else if (rdch && (nprot & PROT_READ))
|
||||
} else if (rdch && (nprot & PROT_READ)) {
|
||||
c = rdch;
|
||||
else
|
||||
} else {
|
||||
splx(s);
|
||||
return -1;
|
||||
}
|
||||
#else
|
||||
c = wrch;
|
||||
#endif
|
||||
|
||||
if (c == NULL) {
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
|
||||
splx(s);
|
||||
return -1;
|
||||
}
|
||||
|
||||
@ -958,6 +989,7 @@ dsp_mmap(dev_t i_dev, vm_offset_t offset, int nprot)
|
||||
ret = atop(vtophys(((char *)sndbuf_getbuf(c->bufsoft)) + offset));
|
||||
relchns(i_dev, rdch, wrch, SD_F_PRIO_RD | SD_F_PRIO_WR);
|
||||
|
||||
splx(s);
|
||||
return ret;
|
||||
}
|
||||
|
||||
@ -989,6 +1021,7 @@ dsp_unregister(int unit, int channel)
|
||||
return 0;
|
||||
}
|
||||
|
||||
#ifdef USING_DEVFS
|
||||
static void
|
||||
dsp_clone(void *arg, char *name, int namelen, dev_t *dev)
|
||||
{
|
||||
@ -1056,5 +1089,6 @@ dsp_sysuninit(void *p)
|
||||
|
||||
SYSINIT(dsp_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysinit, NULL);
|
||||
SYSUNINIT(dsp_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, dsp_sysuninit, NULL);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -87,7 +87,9 @@ static struct cdevsw mixer_cdevsw = {
|
||||
/* flags */ 0,
|
||||
};
|
||||
|
||||
#ifdef USING_DEVFS
|
||||
static eventhandler_tag mixer_ehtag;
|
||||
#endif
|
||||
|
||||
static dev_t
|
||||
mixer_get_devt(device_t dev)
|
||||
@ -394,12 +396,17 @@ static int
|
||||
mixer_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
{
|
||||
struct snd_mixer *m;
|
||||
intrmask_t s;
|
||||
|
||||
s = spltty();
|
||||
m = i_dev->si_drv1;
|
||||
if (m->busy)
|
||||
if (m->busy) {
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
m->busy = 1;
|
||||
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -407,26 +414,33 @@ static int
|
||||
mixer_close(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
{
|
||||
struct snd_mixer *m;
|
||||
intrmask_t s;
|
||||
|
||||
s = spltty();
|
||||
m = i_dev->si_drv1;
|
||||
if (!m->busy)
|
||||
if (!m->busy) {
|
||||
splx(s);
|
||||
return EBADF;
|
||||
}
|
||||
m->busy = 0;
|
||||
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
int
|
||||
mixer_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
{
|
||||
struct snd_mixer *m;
|
||||
intrmask_t s;
|
||||
int ret, *arg_i = (int *)arg;
|
||||
int v = -1, j = cmd & 0xff;
|
||||
struct snd_mixer *m;
|
||||
|
||||
m = i_dev->si_drv1;
|
||||
if (!m->busy)
|
||||
return EBADF;
|
||||
|
||||
s = spltty();
|
||||
snd_mtxlock(m->lock);
|
||||
if ((cmd & MIXER_WRITE(0)) == MIXER_WRITE(0)) {
|
||||
if (j == SOUND_MIXER_RECSRC)
|
||||
@ -434,6 +448,7 @@ mixer_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
else
|
||||
ret = mixer_set(m, j, *arg_i);
|
||||
snd_mtxunlock(m->lock);
|
||||
splx(s);
|
||||
return (ret == 0)? 0 : ENXIO;
|
||||
}
|
||||
|
||||
@ -461,9 +476,11 @@ mixer_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
|
||||
return (v != -1)? 0 : ENXIO;
|
||||
}
|
||||
snd_mtxunlock(m->lock);
|
||||
splx(s);
|
||||
return ENXIO;
|
||||
}
|
||||
|
||||
#ifdef USING_DEVFS
|
||||
static void
|
||||
mixer_clone(void *arg, char *name, int namelen, dev_t *dev)
|
||||
{
|
||||
@ -493,5 +510,6 @@ mixer_sysuninit(void *p)
|
||||
|
||||
SYSINIT(mixer_sysinit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysinit, NULL);
|
||||
SYSUNINIT(mixer_sysuninit, SI_SUB_DRIVERS, SI_ORDER_MIDDLE, mixer_sysuninit, NULL);
|
||||
#endif
|
||||
|
||||
|
||||
|
@ -58,7 +58,11 @@ static int sndstat_isopen = 0;
|
||||
static int sndstat_bufptr;
|
||||
|
||||
static int sndstat_verbose = 0;
|
||||
#ifdef USING_MUTEX
|
||||
TUNABLE_INT("hw.snd.verbose", &sndstat_verbose);
|
||||
#else
|
||||
TUNABLE_INT_DECL("hw.snd.verbose", 0, sndstat_verbose);
|
||||
#endif
|
||||
|
||||
static int sndstat_prepare(struct sbuf *s);
|
||||
|
||||
@ -83,42 +87,60 @@ SYSCTL_PROC(_hw_snd, OID_AUTO, verbose, CTLTYPE_INT | CTLFLAG_RW,
|
||||
static int
|
||||
sndstat_open(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
{
|
||||
intrmask_t s;
|
||||
int err;
|
||||
|
||||
if (sndstat_isopen)
|
||||
s = spltty();
|
||||
if (sndstat_isopen) {
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
if (sbuf_new(&sndstat_sbuf, NULL, 4096, 0) == NULL)
|
||||
}
|
||||
if (sbuf_new(&sndstat_sbuf, NULL, 4096, 0) == NULL) {
|
||||
splx(s);
|
||||
return ENXIO;
|
||||
}
|
||||
sndstat_bufptr = 0;
|
||||
err = (sndstat_prepare(&sndstat_sbuf) > 0)? 0 : ENOMEM;
|
||||
if (!err)
|
||||
sndstat_isopen = 1;
|
||||
|
||||
splx(s);
|
||||
return err;
|
||||
}
|
||||
|
||||
static int
|
||||
sndstat_close(dev_t i_dev, int flags, int mode, struct proc *p)
|
||||
{
|
||||
if (!sndstat_isopen)
|
||||
intrmask_t s;
|
||||
|
||||
s = spltty();
|
||||
if (!sndstat_isopen) {
|
||||
splx(s);
|
||||
return EBADF;
|
||||
}
|
||||
sbuf_delete(&sndstat_sbuf);
|
||||
sndstat_isopen = 0;
|
||||
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
sndstat_read(dev_t i_dev, struct uio *buf, int flag)
|
||||
{
|
||||
intrmask_t s;
|
||||
int l, err;
|
||||
|
||||
if (!sndstat_isopen)
|
||||
s = spltty();
|
||||
if (!sndstat_isopen) {
|
||||
splx(s);
|
||||
return EBADF;
|
||||
}
|
||||
l = min(buf->uio_resid, sbuf_len(&sndstat_sbuf) - sndstat_bufptr);
|
||||
err = (l > 0)? uiomove(sbuf_data(&sndstat_sbuf) + sndstat_bufptr, l, buf) : 0;
|
||||
sndstat_bufptr += l;
|
||||
|
||||
splx(s);
|
||||
return err;
|
||||
}
|
||||
|
||||
@ -212,13 +234,19 @@ sndstat_init(void)
|
||||
static int
|
||||
sndstat_uninit(void)
|
||||
{
|
||||
if (sndstat_isopen)
|
||||
intrmask_t s;
|
||||
|
||||
s = spltty();
|
||||
if (sndstat_isopen) {
|
||||
splx(s);
|
||||
return EBUSY;
|
||||
}
|
||||
|
||||
if (sndstat_dev)
|
||||
destroy_dev(sndstat_dev);
|
||||
sndstat_dev = 0;
|
||||
|
||||
splx(s);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
@ -72,10 +72,12 @@ void
|
||||
snd_mtxassert(void *m)
|
||||
{
|
||||
#ifdef USING_MUTEX
|
||||
#ifdef INVARIANTS
|
||||
struct mtx *mtx = m;
|
||||
|
||||
mtx_assert(mtx, MA_OWNED);
|
||||
#endif
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
|
@ -69,12 +69,19 @@
|
||||
#include <vm/vm.h>
|
||||
#include <vm/pmap.h>
|
||||
|
||||
#undef USING_MUTEX
|
||||
#undef USING_DEVFS
|
||||
|
||||
#if __FreeBSD_version > 500000
|
||||
#define USING_MUTEX
|
||||
#define USING_DEVFS
|
||||
#endif
|
||||
#define SND_DYNSYSCTL
|
||||
|
||||
#ifndef INTR_MPSAFE
|
||||
#define INTR_MPSAFE 0
|
||||
#endif
|
||||
|
||||
#else
|
||||
struct isa_device { int dummy; };
|
||||
#define d_open_t void
|
||||
|
Loading…
Reference in New Issue
Block a user