summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authortanimura <tanimura@FreeBSD.org>2001-02-18 15:58:56 +0000
committertanimura <tanimura@FreeBSD.org>2001-02-18 15:58:56 +0000
commit548e16646ad1b2c4238bf0ca29ed5c33e1efff74 (patch)
tree5bc45e68b007a71e18767b83c5849c71b745ecdb /sys/dev
parent18d474781ff1acbc67429e2db4fa0cf9a0d3c51e (diff)
downloadFreeBSD-src-548e16646ad1b2c4238bf0ca29ed5c33e1efff74.zip
FreeBSD-src-548e16646ad1b2c4238bf0ca29ed5c33e1efff74.tar.gz
Encapselate midi_info, nmidi and nsynth into midi.c.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/sound/isa/emu8000.c24
-rw-r--r--sys/dev/sound/isa/gusmidi.c19
-rw-r--r--sys/dev/sound/isa/mpu.c14
-rw-r--r--sys/dev/sound/isa/opl.c34
-rw-r--r--sys/dev/sound/isa/uartsio.c14
-rw-r--r--sys/dev/sound/midi/midi.c53
-rw-r--r--sys/dev/sound/midi/midi.h10
-rw-r--r--sys/dev/sound/midi/midisynth.c8
-rw-r--r--sys/dev/sound/midi/sequencer.c108
-rw-r--r--sys/dev/sound/pci/csamidi.c20
10 files changed, 128 insertions, 176 deletions
diff --git a/sys/dev/sound/isa/emu8000.c b/sys/dev/sound/isa/emu8000.c
index 25f1802..0efb05c 100644
--- a/sys/dev/sound/isa/emu8000.c
+++ b/sys/dev/sound/isa/emu8000.c
@@ -723,7 +723,7 @@ emu_attach(device_t dev)
emu_writehwcf3(scp, 0x0004);
/* Fill the softc for this unit. */
- scp->devinfo = devinfo = &midi_info[unit];
+ scp->devinfo = devinfo = create_mididev_info_unit(&unit, MDT_SYNTH);
bcopy(&emu_synthinfo, &scp->synthinfo, sizeof(emu_synthinfo));
/* Fill the midi info. */
@@ -741,9 +741,6 @@ emu_attach(device_t dev)
midibuf_init(&devinfo->midi_dbuf_in);
midibuf_init(&devinfo->midi_dbuf_out);
- /* Increase the number of the synthesizers. */
- nsynth++;
-
DEB(printf("emu%d: attached.\n", unit));
return (0);
@@ -776,11 +773,6 @@ emu_read(dev_t i_dev, struct uio *buf, int flag)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("emu_read: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("emu_read: unit %d is not configured.\n", unit));
@@ -807,11 +799,6 @@ emu_write(dev_t i_dev, struct uio *buf, int flag)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("emu_write: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("emu_write: unit %d is not configured.\n", unit));
@@ -843,11 +830,6 @@ emu_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
DEB(printf("emu%d: ioctlling, cmd 0x%x.\n", unit, (int)cmd));
- if (unit >= nmidi + nsynth) {
- DEB(printf("emu_ioctl: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("emu_ioctl: unit %d is not configured.\n", unit));
@@ -858,7 +840,7 @@ emu_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
switch (cmd) {
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
- if (synthinfo->device >= nmidi + nsynth || synthinfo->device != unit)
+ if (synthinfo->device != unit)
return (ENXIO);
bcopy(&scp->synthinfo, synthinfo, sizeof(scp->synthinfo));
synthinfo->device = unit;
@@ -866,7 +848,7 @@ emu_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
- if (midiinfo->device >= nmidi + nsynth || midiinfo->device != unit)
+ if (midiinfo->device != unit)
return (ENXIO);
bcopy(&emu_midiinfo, midiinfo, sizeof(emu_midiinfo));
strcpy(midiinfo->name, scp->synthinfo.name);
diff --git a/sys/dev/sound/isa/gusmidi.c b/sys/dev/sound/isa/gusmidi.c
index 11644f8..d95c75f 100644
--- a/sys/dev/sound/isa/gusmidi.c
+++ b/sys/dev/sound/isa/gusmidi.c
@@ -199,7 +199,7 @@ gusmidi_init(device_t dev)
/* Fill the softc. */
scp->dev = dev;
- scp->devinfo = devinfo = &midi_info[unit];
+ scp->devinfo = devinfo = create_mididev_info_unit(&unit, MDT_MIDI);
/* Fill the midi info. */
bcopy(&gusmidi_op_desc, devinfo, sizeof(gusmidi_op_desc));
@@ -222,9 +222,6 @@ gusmidi_init(device_t dev)
bus_setup_intr(dev, scp->irq, INTR_TYPE_TTY, gusmidi_intr, scp,
&scp->ih);
- /* Increase the number of midi devices. */
- nmidi++;
-
return (0);
}
@@ -237,11 +234,6 @@ gusmidi_open(dev_t i_dev, int flags, int mode, struct proc *p)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("gusmidi_open: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("gusmidi_open: unit %d is not configured.\n", unit));
@@ -268,11 +260,6 @@ gusmidi_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("gusmidi_ioctl: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("gusmidi_ioctl: unit %d is not configured.\n", unit));
@@ -283,7 +270,7 @@ gusmidi_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
switch (cmd) {
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
- if (synthinfo->device > nmidi + nsynth || synthinfo->device != unit)
+ if (synthinfo->device != unit)
return (ENXIO);
bcopy(&gusmidi_synthinfo, synthinfo, sizeof(gusmidi_synthinfo));
synthinfo->device = unit;
@@ -291,7 +278,7 @@ gusmidi_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
- if (midiinfo->device > nmidi + nsynth || midiinfo->device != unit)
+ if (midiinfo->device != unit)
return (ENXIO);
bcopy(&gusmidi_midiinfo, midiinfo, sizeof(gusmidi_midiinfo));
midiinfo->device = unit;
diff --git a/sys/dev/sound/isa/mpu.c b/sys/dev/sound/isa/mpu.c
index 2ed93c1..4adb80d 100644
--- a/sys/dev/sound/isa/mpu.c
+++ b/sys/dev/sound/isa/mpu.c
@@ -379,7 +379,7 @@ mpu_attach(device_t dev)
/* Fill the softc. */
scp->dev = dev;
- scp->devinfo = devinfo = &midi_info[unit];
+ scp->devinfo = devinfo = create_mididev_info_unit(&unit, MDT_MIDI);
callout_handle_init(&scp->dh);
/* Fill the midi info. */
@@ -399,9 +399,6 @@ mpu_attach(device_t dev)
midibuf_init(&devinfo->midi_dbuf_in);
midibuf_init(&devinfo->midi_dbuf_out);
- /* Increase the number of midi devices. */
- nmidi++;
-
/* Now we can handle the interrupts. */
if (scp->irq != NULL)
bus_setup_intr(dev, scp->irq, INTR_TYPE_TTY, mpu_intr, scp,
@@ -437,11 +434,6 @@ mpu_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("mpu_ioctl: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("mpu_ioctl: unit %d is not configured.\n", unit));
@@ -452,7 +444,7 @@ mpu_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
switch (cmd) {
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
- if (synthinfo->device > nmidi + nsynth || synthinfo->device != unit)
+ if (synthinfo->device != unit)
return (ENXIO);
bcopy(&mpu_synthinfo, synthinfo, sizeof(mpu_synthinfo));
synthinfo->device = unit;
@@ -460,7 +452,7 @@ mpu_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
- if (midiinfo->device > nmidi + nsynth || midiinfo->device != unit)
+ if (midiinfo->device != unit)
return (ENXIO);
bcopy(&mpu_midiinfo, midiinfo, sizeof(mpu_midiinfo));
midiinfo->device = unit;
diff --git a/sys/dev/sound/isa/opl.c b/sys/dev/sound/isa/opl.c
index ab433c5..2d41321 100644
--- a/sys/dev/sound/isa/opl.c
+++ b/sys/dev/sound/isa/opl.c
@@ -654,7 +654,7 @@ opl_attach(device_t dev)
/* Fill the softc for this unit. */
scp->dev = dev;
- scp->devinfo = devinfo = &midi_info[unit];
+ scp->devinfo = devinfo = create_mididev_info_unit(&unit, MDT_SYNTH);
/* Allocate other resources. */
if (opl_allocres(scp, dev)) {
@@ -761,9 +761,6 @@ opl_attach(device_t dev)
midibuf_init(&devinfo->midi_dbuf_in);
midibuf_init(&devinfo->midi_dbuf_out);
- /* Increase the number of the synthesizers. */
- nsynth++;
-
DEB(printf("opl%d: attached.\n", unit));
DEB(printf("opl%d: the chip is OPL%d.\n", unit, scp->model));
@@ -787,11 +784,6 @@ opl_open(dev_t i_dev, int flags, int mode, struct proc *p)
DEB(printf("opl%d: opening.\n", unit));
- if (unit >= nmidi + nsynth) {
- DEB(printf("opl_open: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("opl_open: unit %d is not configured.\n", unit));
@@ -828,11 +820,6 @@ opl_close(dev_t i_dev, int flags, int mode, struct proc *p)
DEB(printf("opl%d: closing.\n", unit));
- if (unit >= nmidi + nsynth) {
- DEB(printf("opl_close: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("opl_close: unit %d is not configured.\n", unit));
@@ -862,11 +849,6 @@ opl_read(dev_t i_dev, struct uio *buf, int flag)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("opl_read: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("opl_read: unit %d is not configured.\n", unit));
@@ -894,11 +876,6 @@ opl_write(dev_t i_dev, struct uio *buf, int flag)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("opl_write: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("opl_write: unit %d is not configured.\n", unit));
@@ -932,11 +909,6 @@ opl_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
DEB(printf("opl%d: ioctlling, cmd 0x%x.\n", unit, (int)cmd));
- if (unit >= nmidi + nsynth) {
- DEB(printf("opl_ioctl: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("opl_ioctl: unit %d is not configured.\n", unit));
@@ -947,7 +919,7 @@ opl_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
switch (cmd) {
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
- if (synthinfo->device >= nmidi + nsynth || synthinfo->device != unit)
+ if (synthinfo->device != unit)
return (ENXIO);
bcopy(&scp->synthinfo, synthinfo, sizeof(scp->synthinfo));
synthinfo->device = unit;
@@ -959,7 +931,7 @@ opl_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
- if (midiinfo->device >= nmidi + nsynth || midiinfo->device != unit)
+ if (midiinfo->device != unit)
return (ENXIO);
bcopy(&opl_midiinfo, midiinfo, sizeof(opl_midiinfo));
strcpy(midiinfo->name, scp->synthinfo.name);
diff --git a/sys/dev/sound/isa/uartsio.c b/sys/dev/sound/isa/uartsio.c
index 56b4e5d..5f56e36 100644
--- a/sys/dev/sound/isa/uartsio.c
+++ b/sys/dev/sound/isa/uartsio.c
@@ -228,7 +228,7 @@ uartsio_attach(device_t dev)
/* Fill the softc. */
scp->dev = dev;
- scp->devinfo = devinfo = &midi_info[unit];
+ scp->devinfo = devinfo = create_mididev_info_unit(&unit, MDT_MIDI);
/* Fill the midi info. */
bcopy(&uartsio_op_desc, devinfo, sizeof(uartsio_op_desc));
@@ -262,9 +262,6 @@ uartsio_attach(device_t dev)
uartsio_readport(scp, com_iir);
uartsio_readport(scp, com_data);
- /* Increase the number of midi devices. */
- nmidi++;
-
/* Now we can handle the interrupts. */
bus_setup_intr(dev, scp->irq, INTR_TYPE_TTY, uartsio_intr, scp, &scp->ih);
@@ -284,11 +281,6 @@ uartsio_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("uartsio_ioctl: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("uartsio_ioctl: unit %d is not configured.\n", unit));
@@ -299,7 +291,7 @@ uartsio_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
switch (cmd) {
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
- if (synthinfo->device > nmidi + nsynth || synthinfo->device != unit)
+ if (synthinfo->device != unit)
return (ENXIO);
bcopy(&uartsio_synthinfo, synthinfo, sizeof(uartsio_synthinfo));
synthinfo->device = unit;
@@ -307,7 +299,7 @@ uartsio_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
- if (midiinfo->device > nmidi + nsynth || midiinfo->device != unit)
+ if (midiinfo->device != unit)
return (ENXIO);
bcopy(&uartsio_midiinfo, midiinfo, sizeof(uartsio_midiinfo));
midiinfo->device = unit;
diff --git a/sys/dev/sound/midi/midi.c b/sys/dev/sound/midi/midi.c
index 429a564..1b504bc 100644
--- a/sys/dev/sound/midi/midi.c
+++ b/sys/dev/sound/midi/midi.c
@@ -90,10 +90,8 @@ static struct cdevsw midi_cdevsw = {
* descriptors for active devices. also used as the public softc
* of a device.
*/
-mididev_info midi_info[NMIDI_MAX];
-
-u_long nmidi; /* total number of midi devices, filled in by the driver */
-u_long nsynth; /* total number of synthesizers, filled in by the driver */
+static mididev_info midi_info[NMIDI_MAX];
+static int nmidi, nsynth;
/* These make the buffer for /dev/midistat */
static int midistatbusy;
@@ -141,7 +139,6 @@ mididev_info *
get_mididev_info(dev_t i_dev, int *unit)
{
int u;
- mididev_info *d = NULL;
if (MIDIDEV(i_dev) != MIDI_DEV_MIDIN)
return NULL;
@@ -149,15 +146,55 @@ get_mididev_info(dev_t i_dev, int *unit)
if (unit)
*unit = u;
- if (u >= nmidi + nsynth) {
- DEB(printf("get_mididev_info: unit %d is not configured.\n", u));
+ return get_mididev_info_unit(u);
+}
+
+/*
+ * a small utility function which, given a unit number, returns
+ * a pointer to the associated mididev_info struct.
+ */
+mididev_info *
+get_mididev_info_unit(int unit)
+{
+ mididev_info *d;
+
+ if (unit >= nmidi + nsynth) {
+ DEB(printf("get_mididev_info_unit: unit %d is not configured.\n", u));
return NULL;
}
- d = &midi_info[u];
+ d = &midi_info[unit];
return d;
}
+/* Create a new midi device info structure. */
+mididev_info *
+create_mididev_info_unit(int *unit, int type)
+{
+ /* XXX midi_info is still static. */
+ switch (type) {
+ case MDT_MIDI:
+ nmidi++;
+ break;
+ case MDT_SYNTH:
+ nsynth++;
+ break;
+ default:
+ panic("unsupported device type");
+ break;
+ }
+
+ *unit = nmidi + nsynth - 1;
+ return get_mididev_info_unit(*unit);
+}
+
+/* Return the number of configured devices. */
+int
+mididev_info_number(void)
+{
+ return nmidi + nsynth;
+}
+
/*
* here are the switches for the main functions. The switches do
* all necessary checks on the device number to make sure
diff --git a/sys/dev/sound/midi/midi.h b/sys/dev/sound/midi/midi.h
index a702222..b0982c8 100644
--- a/sys/dev/sound/midi/midi.h
+++ b/sys/dev/sound/midi/midi.h
@@ -257,16 +257,16 @@ struct _mididev_info {
#define DEB(x)
#endif
- extern mididev_info midi_info[NMIDI_MAX];
-
- extern u_long nmidi;
- extern u_long nsynth;
-
/* This is the generic midi drvier initializer. */
int midiinit(mididev_info *d, device_t dev);
/* This provides an access to the mididev_info. */
mididev_info *get_mididev_info(dev_t i_dev, int *unit);
+ mididev_info *get_mididev_info_unit(int unit);
+ mididev_info *create_mididev_info_unit(int *unit, int type);
+ int mididev_info_number(void);
+#define MDT_MIDI (0)
+#define MDT_SYNTH (1)
/* These are the generic methods for a midi driver. */
d_open_t midi_open;
diff --git a/sys/dev/sound/midi/midisynth.c b/sys/dev/sound/midi/midisynth.c
index 0c6dd8a..481f79c 100644
--- a/sys/dev/sound/midi/midisynth.c
+++ b/sys/dev/sound/midi/midisynth.c
@@ -529,10 +529,6 @@ synth_readraw(mididev_info *md, u_char *buf, int len, int nonblock)
return (ENXIO);
unit = md->unit;
- if (unit >= nmidi + nsynth) {
- DEB(printf("synth_readraw: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
if ((md->fflags & FREAD) == 0) {
DEB(printf("mpu_readraw: unit %d is not for reading.\n", unit));
return (EIO);
@@ -571,10 +567,6 @@ synth_writeraw(mididev_info *md, u_char *buf, int len, int nonblock)
unit = md->unit;
- if (unit >= nmidi + nsynth) {
- DEB(printf("synth_writeraw: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
if ((md->fflags & FWRITE) == 0) {
DEB(printf("synth_writeraw: unit %d is not for writing.\n", unit));
return (EIO);
diff --git a/sys/dev/sound/midi/sequencer.c b/sys/dev/sound/midi/sequencer.c
index bf29cac..7b010b4 100644
--- a/sys/dev/sound/midi/sequencer.c
+++ b/sys/dev/sound/midi/sequencer.c
@@ -174,7 +174,7 @@ static int seq_closemidi(sc_p scp, mididev_info *md, int flags, int mode, struct
static void seq_panic(sc_p scp);
static int seq_sync(sc_p scp);
-static seqdev_info * get_seqdev_info(dev_t i_dev, int *unit);
+static seqdev_info *get_seqdev_info(dev_t i_dev, int *unit);
/*
* Here are the main functions to interact to the user process.
@@ -287,8 +287,8 @@ seq_open(dev_t i_dev, int flags, int mode, struct proc *p)
splx(s);
/* Open midi devices. */
- for (midiunit = 0 ; midiunit < nmidi + nsynth ; midiunit++) {
- md = &midi_info[midiunit];
+ for (midiunit = 0 ; midiunit < mididev_info_number() ; midiunit++) {
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md))
seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, p);
}
@@ -335,8 +335,8 @@ seq_close(dev_t i_dev, int flags, int mode, struct proc *p)
seq_sync(scp);
/* Clean up the midi device. */
- for (i = 0 ; i < nmidi + nsynth ; i++) {
- md = &midi_info[i];
+ for (i = 0 ; i < mididev_info_number() ; i++) {
+ md = get_mididev_info_unit(i);
if (MIDICONFED(md))
seq_closemidi(scp, md, scp->fflags, MIDIDEV_MODE, p);
}
@@ -448,9 +448,9 @@ seq_write(dev_t i_dev, struct uio *buf, int flag)
/* A long event, these are the patches/samples for a synthesizer. */
midiunit = *(u_short *)&event[2];
- if (midiunit < 0 || midiunit >= nmidi + nsynth)
+ if (midiunit < 0 || midiunit >= mididev_info_number())
return (ENXIO);
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (!MIDICONFED(md))
return (ENXIO);
s = splmidi();
@@ -502,9 +502,9 @@ seq_write(dev_t i_dev, struct uio *buf, int flag)
if (ev_code == SEQ_MIDIPUTC) {
/* An event passed to the midi device itself. */
midiunit = event[2];
- if (midiunit < 0 || midiunit >= nmidi + nsynth)
+ if (midiunit < 0 || midiunit >= mididev_info_number())
return (ENXIO);
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (!MIDICONFED(md))
return (ENXIO);
if ((md->flags & MIDI_F_BUSY) == 0
@@ -618,8 +618,8 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
sd->callback(sd, SEQ_CB_ABORT | SEQ_CB_WR);
/* Pass the ioctl to the midi devices. */
- for (midiunit = 0 ; midiunit < nmidi + nsynth ; midiunit++) {
- md = &midi_info[midiunit];
+ for (midiunit = 0 ; midiunit < mididev_info_number() ; midiunit++) {
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md) && scp->midi_open[midiunit] && (md->flags & MIDI_F_WRITING) != 0) {
arg2 = *(int *)arg;
midi_ioctl(MIDIMKDEV(major(i_dev), midiunit, SND_DEV_MIDIN), cmd, (caddr_t)&arg2, mode, p);
@@ -636,8 +636,8 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
sd->callback(sd, SEQ_CB_ABORT | SEQ_CB_RD);
/* Pass the ioctl to the midi devices. */
- for (midiunit = 0 ; midiunit < nmidi + nsynth ; midiunit++) {
- md = &midi_info[midiunit];
+ for (midiunit = 0 ; midiunit < mididev_info_number() ; midiunit++) {
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md) && scp->midi_open[midiunit] && (md->flags & MIDI_F_WRITING) != 0) {
arg2 = *(int *)arg;
midi_ioctl(MIDIMKDEV(major(i_dev), midiunit, SND_DEV_MIDIN), cmd, (caddr_t)&arg2, mode, p);
@@ -708,11 +708,11 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_SEQ_TESTMIDI:
midiunit = *(int *)arg;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md) && !scp->midi_open[midiunit]) {
ret = seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
break;
@@ -749,12 +749,12 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_SEQ_RESETSAMPLES:
midiunit = *(int *)arg;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
if (!scp->midi_open[midiunit]) {
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md)) {
ret = seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
if (ret != 0)
@@ -767,21 +767,21 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
ret = midi_ioctl(MIDIMKDEV(major(i_dev), midiunit, SND_DEV_MIDIN), cmd, arg, mode, p);
break;
case SNDCTL_SEQ_NRSYNTHS:
- *(int *)arg = nmidi + nsynth;
+ *(int *)arg = mididev_info_number();
ret = 0;
break;
case SNDCTL_SEQ_NRMIDIS:
- *(int *)arg = nmidi + nsynth;
+ *(int *)arg = mididev_info_number();
ret = 0;
break;
case SNDCTL_SYNTH_MEMAVL:
midiunit = *(int *)arg;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
if (!scp->midi_open[midiunit]) {
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md)) {
ret = seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
if (ret != 0)
@@ -795,12 +795,12 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_FM_4OP_ENABLE:
midiunit = *(int *)arg;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
if (!scp->midi_open[midiunit]) {
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md)) {
ret = seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
if (ret != 0)
@@ -815,7 +815,7 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
midiunit = synthinfo->device;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
@@ -830,7 +830,7 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
midiunit = midiinfo->device;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
@@ -839,7 +839,7 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
case SNDCTL_PMGR_IFACE:
patinfo = (struct patmgr_info *)arg;
midiunit = patinfo->device;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
@@ -852,12 +852,12 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
case SNDCTL_PMGR_ACCESS:
patinfo = (struct patmgr_info *)arg;
midiunit = patinfo->device;
- if (midiunit >= nmidi + nsynth) {
+ if (midiunit >= mididev_info_number()) {
ret = ENXIO;
break;
}
if (!scp->midi_open[midiunit]) {
- md = &midi_info[midiunit];
+ md = get_mididev_info_unit(midiunit);
if (MIDICONFED(md)) {
ret = seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
if (ret != 0)
@@ -889,7 +889,7 @@ seq_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
}
if (!scp->midi_open[0]) {
- md = &midi_info[0];
+ md = get_mididev_info_unit(0);
if (MIDICONFED(md)) {
ret = seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
if (ret != 0)
@@ -1139,7 +1139,7 @@ seq_playevent(sc_p scp, u_char *event)
sd = scp->devinfo;
unit = sd->unit;
- md = &midi_info[0];
+ md = get_mididev_info_unit(0);
if (!MIDICONFED(md))
return (MORE);
@@ -1195,8 +1195,8 @@ seq_playevent(sc_p scp, u_char *event)
break;
case SEQ_MIDIPUTC:
/* Pass through to the midi device. */
- if (event[2] < nmidi + nsynth) {
- md = &midi_info[event[2]];
+ if (event[2] < mididev_info_number()) {
+ md = get_mididev_info_unit(event[2]);
if (MIDICONFED(md) && ((md->flags & MIDI_F_BUSY) != 0 || seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc) == 0)) {
if (md->synth.writeraw(md, &event[1], sizeof(event[1]), 1) == EAGAIN) {
/* The queue was full. Try again later. */
@@ -1216,8 +1216,8 @@ seq_playevent(sc_p scp, u_char *event)
ret = MORE;
break;
case SEQ_PRIVATE:
- if (event[1] < nmidi + nsynth) {
- md = &midi_info[event[1]];
+ if (event[1] < mididev_info_number()) {
+ md = get_mididev_info_unit(event[1]);
if (MIDICONFED(md) && md->synth.hwcontrol(md, event) == EAGAIN) {
ret = QUEUEFULL;
break;
@@ -1380,9 +1380,9 @@ seq_extended(sc_p scp, u_char *event)
sd = scp->devinfo;
unit = sd->unit;
- if (event[2] >= nmidi + nsynth)
+ if (event[2] >= mididev_info_number())
return (MORE);
- md = &midi_info[event[2]];
+ md = get_mididev_info_unit(event[2]);
if (!MIDICONFED(md) && (md->flags & MIDI_F_BUSY) == 0 && seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc) != 0)
return (MORE);
@@ -1439,9 +1439,9 @@ seq_chnvoice(sc_p scp, u_char *event)
sd = scp->devinfo;
- if (dev >= nmidi + nsynth)
+ if (dev >= mididev_info_number())
return (MORE);
- md = &midi_info[dev];
+ md = get_mididev_info_unit(dev);
if (!MIDICONFED(md) && (md->flags & MIDI_F_BUSY) == 0 && seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc) != 0)
return (MORE);
@@ -1464,7 +1464,7 @@ seq_chnvoice(sc_p scp, u_char *event)
voice = chn;
#if notyet
- if (scp->seq_mode == SEQ_2 && dev < nmidi + nsynth && chn == 9) {
+ if (scp->seq_mode == SEQ_2 && dev < mididev_info_number() && chn == 9) {
/* This channel is a percussion. The note number is the patch number. */
if (md->synth.setinstr(md, voice, 128 + note) == EAGAIN)
return (QUEUEFULL);
@@ -1544,9 +1544,9 @@ seq_chncommon(sc_p scp, u_char *event)
sd = scp->devinfo;
unit = sd->unit;
- if (dev >= nmidi + nsynth)
+ if (dev >= mididev_info_number())
return (MORE);
- md = &midi_info[dev];
+ md = get_mididev_info_unit(dev);
if (!MIDICONFED(md) && (md->flags & MIDI_F_BUSY) == 0 && seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc) != 0)
return (MORE);
@@ -1555,7 +1555,7 @@ seq_chncommon(sc_p scp, u_char *event)
#if notyet
if (scp->seq_mode == SEQ_2) {
md->synth.chn_info[chn].pgm_num = p1;
- if (dev < nmidi + nsynth)
+ if (dev < mididev_info_number())
if (md->synth.setinstr(md, chn, p1) == EAGAIN)
return (QUEUEFULL);
} else
@@ -1572,7 +1572,7 @@ seq_chncommon(sc_p scp, u_char *event)
if (p1 < 32)
/* We have set the MSB, clear the LSB. */
md->synth.chn_info[chn].controllers[p1 + 32] = 0;
- if (dev < nmidi + nsynth) {
+ if (dev < mididev_info_number()) {
val = w14 & 0x7f;
if (p1 < 64) {
/* Combine the MSB and the LSB. */
@@ -1600,7 +1600,7 @@ seq_chncommon(sc_p scp, u_char *event)
#if notyet
if (scp->seq_mode == SEQ_2) {
md->synth.chn_info[chn].bender_value = w14;
- if (dev < nmidi + nsynth) {
+ if (dev < mididev_info_number()) {
/* Handle all of the notes playing on this channel. */
key = ((int)chn << 8);
for (i = 0 ; i < md->synth.alloc.max_voice ; i++)
@@ -1708,9 +1708,9 @@ seq_sysex(sc_p scp, u_char *event)
sd = scp->devinfo;
unit = sd->unit;
- if (event[1] >= nmidi + nsynth)
+ if (event[1] >= mididev_info_number())
return (MORE);
- md = &midi_info[event[1]];
+ md = get_mididev_info_unit(event[1]);
if (!MIDICONFED(md) || md->synth.sendsysex == NULL
|| ((md->flags & MIDI_F_BUSY) == 0 && seq_openmidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc) != 0))
return (MORE);
@@ -1824,8 +1824,8 @@ seq_reset(sc_p scp)
#if notyet
/* Reset the synthesizers. */
- for (i = 0 ; i < nmidi + nsynth ; i++) {
- md = &midi_info[i];
+ for (i = 0 ; i < mididev_info_number() ; i++) {
+ md = get_mididev_info_unit(i);
if (MIDICONFED(md) && scp->midi_open[i])
md->synth.reset(md);
}
@@ -1834,9 +1834,9 @@ seq_reset(sc_p scp)
#if notyet
if (scp->seq_mode == SEQ_2) {
for (chn = 0 ; chn < 16 ; chn++)
- for (i = 0 ; i < nmidi + nsynth ; i++)
+ for (i = 0 ; i < mididev_info_number() ; i++)
if (midi_open[i]) {
- md = &midi_info[i];
+ md = get_mididev_info_unit(i);
if (!MIDICONFED(md))
continue;
if (md->synth.controller(md, chn, 123, 0) == EAGAIN /* All notes off. */
@@ -1850,8 +1850,8 @@ seq_reset(sc_p scp)
} else {
#endif /* notyet */
splx(s);
- for (i = 0 ; i < nmidi + nsynth ; i++) {
- md = &midi_info[i];
+ for (i = 0 ; i < mididev_info_number() ; i++) {
+ md = get_mididev_info_unit(i);
if (!MIDICONFED(md))
continue;
@@ -1878,8 +1878,8 @@ seq_reset(sc_p scp)
return (EAGAIN);
}
}
- for (i = 0 ; i < nmidi + nsynth ; i++){
- md = &midi_info[i];
+ for (i = 0 ; i < mididev_info_number() ; i++){
+ md = get_mididev_info_unit(i);
if (MIDICONFED(md))
seq_closemidi(scp, md, scp->fflags, MIDIDEV_MODE, curproc);
}
diff --git a/sys/dev/sound/pci/csamidi.c b/sys/dev/sound/pci/csamidi.c
index 74ebb6e..b29e9ba 100644
--- a/sys/dev/sound/pci/csamidi.c
+++ b/sys/dev/sound/pci/csamidi.c
@@ -112,8 +112,11 @@ static int csamidi_readdata(sc_p scp);
static int csamidi_writedata(sc_p scp, u_int32_t value);
static u_int32_t csamidi_readio(sc_p scp, u_long offset);
static void csamidi_writeio(sc_p scp, u_long offset, u_int32_t data);
+/* Not used in this file. */
+#if notdef
static u_int32_t csamidi_readmem(sc_p scp, u_long offset);
static void csamidi_writemem(sc_p scp, u_long offset, u_int32_t data);
+#endif /* notdef */
static int csamidi_allocres(sc_p scp, device_t dev);
static void csamidi_releaseres(sc_p scp, device_t dev);
@@ -189,7 +192,7 @@ csamidi_attach(device_t dev)
/* Fill the softc. */
scp->dev = dev;
- scp->devinfo = devinfo = &midi_info[unit];
+ scp->devinfo = devinfo = create_mididev_info_unit(&unit, MDT_MIDI);
/* Fill the midi info. */
bcopy(&csamidi_op_desc, devinfo, sizeof(csamidi_op_desc));
@@ -204,9 +207,6 @@ csamidi_attach(device_t dev)
midibuf_init(&devinfo->midi_dbuf_in);
midibuf_init(&devinfo->midi_dbuf_out);
- /* Increase the number of midi devices. */
- nmidi++;
-
/* Enable interrupt. */
if (bus_setup_intr(dev, scp->irq, INTR_TYPE_TTY, csamidi_intr, scp, &scp->ih)) {
csamidi_releaseres(scp, dev);
@@ -230,11 +230,6 @@ csamidi_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
unit = MIDIUNIT(i_dev);
- if (unit >= nmidi + nsynth) {
- DEB(printf("csamidi_ioctl: unit %d does not exist.\n", unit));
- return (ENXIO);
- }
-
devinfo = get_mididev_info(i_dev, &unit);
if (devinfo == NULL) {
DEB(printf("csamidi_ioctl: unit %d is not configured.\n", unit));
@@ -245,7 +240,7 @@ csamidi_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
switch (cmd) {
case SNDCTL_SYNTH_INFO:
synthinfo = (struct synth_info *)arg;
- if (synthinfo->device > nmidi + nsynth || synthinfo->device != unit)
+ if (synthinfo->device != unit)
return (ENXIO);
bcopy(&csamidi_synthinfo, synthinfo, sizeof(csamidi_synthinfo));
synthinfo->device = unit;
@@ -253,7 +248,7 @@ csamidi_ioctl(dev_t i_dev, u_long cmd, caddr_t arg, int mode, struct proc *p)
break;
case SNDCTL_MIDI_INFO:
midiinfo = (struct midi_info *)arg;
- if (midiinfo->device > nmidi + nsynth || midiinfo->device != unit)
+ if (midiinfo->device != unit)
return (ENXIO);
bcopy(&csamidi_midiinfo, midiinfo, sizeof(csamidi_midiinfo));
midiinfo->device = unit;
@@ -482,6 +477,8 @@ csamidi_writeio(sc_p scp, u_long offset, u_int32_t data)
bus_space_write_4(rman_get_bustag(scp->io), rman_get_bushandle(scp->io), offset, data);
}
+/* Not used in this file. */
+#if notdef
static u_int32_t
csamidi_readmem(sc_p scp, u_long offset)
{
@@ -493,6 +490,7 @@ csamidi_writemem(sc_p scp, u_long offset, u_int32_t data)
{
bus_space_write_4(rman_get_bustag(scp->mem), rman_get_bushandle(scp->mem), offset, data);
}
+#endif /* notdef */
/* Allocates resources. */
static int
OpenPOWER on IntegriCloud