2005-02-27 03:26:58 +03:00
|
|
|
/* $NetBSD: midi.c,v 1.39 2005/02/27 00:26:58 perry Exp $ */
|
1998-08-07 04:00:55 +04:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 The NetBSD Foundation, Inc.
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
1998-11-26 01:17:06 +03:00
|
|
|
* This code is derived from software contributed to The NetBSD Foundation
|
2003-12-04 16:57:30 +03:00
|
|
|
* by Lennart Augustsson (augustss@NetBSD.org).
|
1998-08-07 04:00:55 +04:00
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
* 3. All advertising materials mentioning features or use of this software
|
|
|
|
* must display the following acknowledgement:
|
|
|
|
* This product includes software developed by the NetBSD
|
|
|
|
* Foundation, Inc. and its contributors.
|
|
|
|
* 4. Neither the name of The NetBSD Foundation nor the names of its
|
|
|
|
* contributors may be used to endorse or promote products derived
|
|
|
|
* from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. 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 FOUNDATION 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.
|
|
|
|
*/
|
|
|
|
|
2001-11-13 08:32:49 +03:00
|
|
|
#include <sys/cdefs.h>
|
2005-02-27 03:26:58 +03:00
|
|
|
__KERNEL_RCSID(0, "$NetBSD: midi.c,v 1.39 2005/02/27 00:26:58 perry Exp $");
|
2001-11-13 08:32:49 +03:00
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
#include "midi.h"
|
|
|
|
#include "sequencer.h"
|
|
|
|
|
|
|
|
#include <sys/param.h>
|
|
|
|
#include <sys/ioctl.h>
|
|
|
|
#include <sys/fcntl.h>
|
|
|
|
#include <sys/vnode.h>
|
|
|
|
#include <sys/select.h>
|
|
|
|
#include <sys/poll.h>
|
|
|
|
#include <sys/malloc.h>
|
|
|
|
#include <sys/proc.h>
|
|
|
|
#include <sys/systm.h>
|
2000-03-23 10:01:25 +03:00
|
|
|
#include <sys/callout.h>
|
1998-08-07 04:00:55 +04:00
|
|
|
#include <sys/syslog.h>
|
|
|
|
#include <sys/kernel.h>
|
|
|
|
#include <sys/signalvar.h>
|
|
|
|
#include <sys/conf.h>
|
|
|
|
#include <sys/audioio.h>
|
|
|
|
#include <sys/midiio.h>
|
|
|
|
#include <sys/device.h>
|
|
|
|
|
|
|
|
#include <dev/audio_if.h>
|
1998-08-18 01:16:09 +04:00
|
|
|
#include <dev/midi_if.h>
|
1998-08-07 04:00:55 +04:00
|
|
|
#include <dev/midivar.h>
|
|
|
|
|
1998-12-20 17:26:44 +03:00
|
|
|
#if NMIDI > 0
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
#ifdef AUDIO_DEBUG
|
|
|
|
#define DPRINTF(x) if (mididebug) printf x
|
|
|
|
#define DPRINTFN(n,x) if (mididebug >= (n)) printf x
|
|
|
|
int mididebug = 0;
|
|
|
|
#else
|
|
|
|
#define DPRINTF(x)
|
|
|
|
#define DPRINTFN(n,x)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
int midi_wait;
|
|
|
|
|
2001-10-03 02:41:22 +04:00
|
|
|
void midi_in(void *, int);
|
|
|
|
void midi_out(void *);
|
|
|
|
int midi_start_output(struct midi_softc *, int);
|
|
|
|
int midi_sleep_timo(int *, char *, int);
|
|
|
|
int midi_sleep(int *, char *);
|
|
|
|
void midi_wakeup(int *);
|
|
|
|
void midi_initbuf(struct midi_buffer *);
|
|
|
|
void midi_timeout(void *);
|
1998-08-07 04:00:55 +04:00
|
|
|
|
2001-10-03 02:41:22 +04:00
|
|
|
int midiprobe(struct device *, struct cfdata *, void *);
|
|
|
|
void midiattach(struct device *, struct device *, void *);
|
|
|
|
int mididetach(struct device *, int);
|
|
|
|
int midiactivate(struct device *, enum devact);
|
1998-08-07 04:00:55 +04:00
|
|
|
|
2002-09-06 17:18:43 +04:00
|
|
|
dev_type_open(midiopen);
|
|
|
|
dev_type_close(midiclose);
|
|
|
|
dev_type_read(midiread);
|
|
|
|
dev_type_write(midiwrite);
|
|
|
|
dev_type_ioctl(midiioctl);
|
|
|
|
dev_type_poll(midipoll);
|
2002-10-23 13:10:23 +04:00
|
|
|
dev_type_kqfilter(midikqfilter);
|
2002-09-06 17:18:43 +04:00
|
|
|
|
|
|
|
const struct cdevsw midi_cdevsw = {
|
|
|
|
midiopen, midiclose, midiread, midiwrite, midiioctl,
|
2002-10-23 13:10:23 +04:00
|
|
|
nostop, notty, midipoll, nommap, midikqfilter,
|
2002-09-06 17:18:43 +04:00
|
|
|
};
|
|
|
|
|
2002-10-01 01:17:57 +04:00
|
|
|
CFATTACH_DECL(midi, sizeof(struct midi_softc),
|
2002-10-02 20:33:28 +04:00
|
|
|
midiprobe, midiattach, mididetach, midiactivate);
|
1998-08-07 04:00:55 +04:00
|
|
|
|
1998-08-18 01:16:09 +04:00
|
|
|
#ifdef MIDI_SAVE
|
|
|
|
#define MIDI_SAVE_SIZE 100000
|
|
|
|
int midicnt;
|
|
|
|
struct {
|
|
|
|
int cnt;
|
|
|
|
u_char buf[MIDI_SAVE_SIZE];
|
|
|
|
} midisave;
|
|
|
|
#define MIDI_GETSAVE _IOWR('m', 100, int)
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
extern struct cfdriver midi_cd;
|
|
|
|
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midiprobe(struct device *parent, struct cfdata *match, void *aux)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct audio_attach_args *sa = aux;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTFN(6,("midiprobe: type=%d sa=%p hw=%p\n",
|
1998-08-07 04:00:55 +04:00
|
|
|
sa->type, sa, sa->hwif));
|
2000-05-06 18:35:28 +04:00
|
|
|
return (sa->type == AUDIODEV_TYPE_MIDI);
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midiattach(struct device *parent, struct device *self, void *aux)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = (void *)self;
|
|
|
|
struct audio_attach_args *sa = aux;
|
2004-10-29 16:57:15 +04:00
|
|
|
const struct midi_hw_if *hwp = sa->hwif;
|
1998-08-07 04:00:55 +04:00
|
|
|
void *hdlp = sa->hdl;
|
|
|
|
|
|
|
|
DPRINTFN(6, ("MIDI attach\n"));
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (hwp == 0 ||
|
|
|
|
hwp->open == 0 ||
|
|
|
|
hwp->close == 0 ||
|
|
|
|
hwp->output == 0 ||
|
|
|
|
hwp->getinfo == 0) {
|
|
|
|
printf("midi: missing method\n");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2000-03-23 10:01:25 +03:00
|
|
|
|
|
|
|
callout_init(&sc->sc_callout);
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->hw_if = hwp;
|
|
|
|
sc->hw_hdl = hdlp;
|
2001-01-13 19:16:12 +03:00
|
|
|
sc->dying = 0;
|
1998-08-12 22:11:53 +04:00
|
|
|
midi_attach(sc, parent);
|
|
|
|
}
|
|
|
|
|
2001-01-13 19:09:04 +03:00
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midiactivate(struct device *self, enum devact act)
|
2001-01-13 19:09:04 +03:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = (struct midi_softc *)self;
|
|
|
|
|
|
|
|
switch (act) {
|
|
|
|
case DVACT_ACTIVATE:
|
|
|
|
return (EOPNOTSUPP);
|
|
|
|
|
|
|
|
case DVACT_DEACTIVATE:
|
|
|
|
sc->dying = 1;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
mididetach(struct device *self, int flags)
|
2001-01-13 19:09:04 +03:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = (struct midi_softc *)self;
|
|
|
|
int maj, mn;
|
|
|
|
|
|
|
|
DPRINTF(("midi_detach: sc=%p flags=%d\n", sc, flags));
|
|
|
|
|
|
|
|
sc->dying = 1;
|
|
|
|
|
|
|
|
wakeup(&sc->wchan);
|
|
|
|
wakeup(&sc->rchan);
|
|
|
|
|
|
|
|
/* locate the major number */
|
2002-09-06 17:18:43 +04:00
|
|
|
maj = cdevsw_lookup_major(&midi_cdevsw);
|
2001-01-13 19:09:04 +03:00
|
|
|
|
|
|
|
/* Nuke the vnodes for any open instances (calls close). */
|
|
|
|
mn = self->dv_unit;
|
|
|
|
vdevgone(maj, mn, mn, VCHR);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-08-12 22:11:53 +04:00
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_attach(struct midi_softc *sc, struct device *parent)
|
1998-08-12 22:11:53 +04:00
|
|
|
{
|
|
|
|
struct midi_info mi;
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->isopen = 0;
|
|
|
|
|
|
|
|
midi_wait = MIDI_WAIT * hz / 1000000;
|
|
|
|
if (midi_wait == 0)
|
|
|
|
midi_wait = 1;
|
|
|
|
|
1998-08-12 22:11:53 +04:00
|
|
|
sc->sc_dev = parent;
|
|
|
|
sc->hw_if->getinfo(sc->hw_hdl, &mi);
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->props = mi.props;
|
1999-10-19 20:04:52 +04:00
|
|
|
printf(": %s\n", mi.name);
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_unit_count(void)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
return midi_cd.cd_ndevs;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_initbuf(struct midi_buffer *mb)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
mb->used = 0;
|
|
|
|
mb->usedhigh = MIDI_BUFSIZE;
|
|
|
|
mb->end = mb->start + mb->usedhigh;
|
|
|
|
mb->inp = mb->outp = mb->start;
|
|
|
|
}
|
|
|
|
|
1998-08-12 22:11:53 +04:00
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_sleep_timo(int *chan, char *label, int timo)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
int st;
|
|
|
|
|
|
|
|
if (!label)
|
|
|
|
label = "midi";
|
|
|
|
|
|
|
|
DPRINTFN(5, ("midi_sleep_timo: %p %s %d\n", chan, label, timo));
|
|
|
|
*chan = 1;
|
|
|
|
st = tsleep(chan, PWAIT | PCATCH, label, timo);
|
|
|
|
*chan = 0;
|
|
|
|
#ifdef MIDI_DEBUG
|
|
|
|
if (st != 0)
|
|
|
|
printf("midi_sleep: %d\n", st);
|
|
|
|
#endif
|
|
|
|
return st;
|
|
|
|
}
|
|
|
|
|
1998-08-12 22:11:53 +04:00
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_sleep(int *chan, char *label)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
return midi_sleep_timo(chan, label, 0);
|
|
|
|
}
|
|
|
|
|
1998-08-12 22:11:53 +04:00
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_wakeup(int *chan)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
if (*chan) {
|
|
|
|
DPRINTFN(5, ("midi_wakeup: %p\n", chan));
|
|
|
|
wakeup(chan);
|
|
|
|
*chan = 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int midi_lengths[] = { 2,2,2,2,1,1,2,0 };
|
|
|
|
/* Number of bytes in a MIDI command */
|
|
|
|
#define MIDI_LENGTH(d) (midi_lengths[((d) >> 4) & 7])
|
|
|
|
|
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_in(void *addr, int data)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = addr;
|
|
|
|
struct midi_buffer *mb = &sc->inbuf;
|
|
|
|
int i;
|
|
|
|
|
1998-08-13 04:13:56 +04:00
|
|
|
if (!sc->isopen)
|
|
|
|
return;
|
1998-08-07 04:00:55 +04:00
|
|
|
if (data == MIDI_ACK)
|
|
|
|
return;
|
2000-01-18 21:49:35 +03:00
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTFN(3, ("midi_in: sc=%p data=0x%02x state=%d pos=%d\n",
|
2000-01-18 21:49:35 +03:00
|
|
|
sc, data, sc->in_state, sc->in_pos));
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
if (!(sc->flags & FREAD))
|
|
|
|
return; /* discard data if not reading */
|
|
|
|
|
|
|
|
switch(sc->in_state) {
|
|
|
|
case MIDI_IN_START:
|
|
|
|
if (MIDI_IS_STATUS(data)) {
|
|
|
|
switch(data) {
|
|
|
|
case 0xf0: /* Sysex */
|
|
|
|
sc->in_state = MIDI_IN_SYSEX;
|
2003-11-23 04:25:59 +03:00
|
|
|
sc->in_msg[0] = data;
|
|
|
|
sc->in_pos = 1;
|
|
|
|
sc->in_left = 0;
|
|
|
|
goto deliver_raw;
|
1998-08-07 04:00:55 +04:00
|
|
|
case 0xf1: /* MTC quarter frame */
|
|
|
|
case 0xf3: /* Song select */
|
|
|
|
sc->in_state = MIDI_IN_DATA;
|
|
|
|
sc->in_msg[0] = data;
|
|
|
|
sc->in_pos = 1;
|
|
|
|
sc->in_left = 1;
|
|
|
|
break;
|
|
|
|
case 0xf2: /* Song position pointer */
|
|
|
|
sc->in_state = MIDI_IN_DATA;
|
|
|
|
sc->in_msg[0] = data;
|
|
|
|
sc->in_pos = 1;
|
|
|
|
sc->in_left = 2;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (MIDI_IS_COMMON(data)) {
|
|
|
|
sc->in_msg[0] = data;
|
|
|
|
sc->in_pos = 1;
|
|
|
|
goto deliver;
|
|
|
|
} else {
|
|
|
|
sc->in_state = MIDI_IN_DATA;
|
|
|
|
sc->in_msg[0] = sc->in_status = data;
|
|
|
|
sc->in_pos = 1;
|
2000-01-18 21:49:35 +03:00
|
|
|
sc->in_left = MIDI_LENGTH(data);
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (MIDI_IS_STATUS(sc->in_status)) {
|
|
|
|
sc->in_state = MIDI_IN_DATA;
|
|
|
|
sc->in_msg[0] = sc->in_status;
|
|
|
|
sc->in_msg[1] = data;
|
|
|
|
sc->in_pos = 2;
|
|
|
|
sc->in_left = MIDI_LENGTH(sc->in_status) - 1;
|
2003-11-02 14:56:36 +03:00
|
|
|
if (sc->in_left == 0)
|
|
|
|
goto deliver;
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return;
|
|
|
|
case MIDI_IN_DATA:
|
2003-11-02 14:56:36 +03:00
|
|
|
KASSERT(sc->in_left >= 1);
|
|
|
|
KASSERT(sc->in_pos < 3);
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->in_msg[sc->in_pos++] = data;
|
2003-11-02 14:56:36 +03:00
|
|
|
if (--sc->in_left == 0)
|
1998-08-07 04:00:55 +04:00
|
|
|
break; /* deliver data */
|
|
|
|
return;
|
|
|
|
case MIDI_IN_SYSEX:
|
2003-11-23 04:25:59 +03:00
|
|
|
sc->in_msg[0] = data;
|
|
|
|
sc->in_pos = 1;
|
|
|
|
sc->in_left = 0;
|
1998-08-07 04:00:55 +04:00
|
|
|
if (data == MIDI_SYSEX_END)
|
|
|
|
sc->in_state = MIDI_IN_START;
|
2003-11-23 04:25:59 +03:00
|
|
|
goto deliver_raw;
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
deliver:
|
|
|
|
sc->in_state = MIDI_IN_START;
|
|
|
|
#if NSEQUENCER > 0
|
|
|
|
if (sc->seqopen) {
|
2001-10-03 02:41:22 +04:00
|
|
|
extern void midiseq_in(struct midi_dev *,u_char *,int);
|
1998-10-05 13:21:41 +04:00
|
|
|
midiseq_in(sc->seq_md, sc->in_msg, sc->in_pos);
|
1998-08-07 04:00:55 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
#endif
|
2003-11-23 04:25:59 +03:00
|
|
|
deliver_raw:
|
1998-08-07 04:00:55 +04:00
|
|
|
if (mb->used + sc->in_pos > mb->usedhigh) {
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTF(("midi_in: buffer full, discard data=0x%02x\n",
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->in_msg[0]));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
for (i = 0; i < sc->in_pos; i++) {
|
|
|
|
*mb->inp++ = sc->in_msg[i];
|
|
|
|
if (mb->inp >= mb->end)
|
|
|
|
mb->inp = mb->start;
|
|
|
|
mb->used++;
|
|
|
|
}
|
|
|
|
midi_wakeup(&sc->rchan);
|
2002-10-23 13:10:23 +04:00
|
|
|
selnotify(&sc->rsel, 0);
|
1998-08-07 04:00:55 +04:00
|
|
|
if (sc->async)
|
|
|
|
psignal(sc->async, SIGIO);
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_out(void *addr)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = addr;
|
1998-08-13 04:13:56 +04:00
|
|
|
|
|
|
|
if (!sc->isopen)
|
|
|
|
return;
|
1998-08-07 04:00:55 +04:00
|
|
|
DPRINTFN(3, ("midi_out: %p\n", sc));
|
|
|
|
midi_start_output(sc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
midiopen(dev_t dev, int flags, int ifmt, struct proc *p)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc;
|
2004-10-29 16:57:15 +04:00
|
|
|
const struct midi_hw_if *hw;
|
1998-08-07 04:00:55 +04:00
|
|
|
int error;
|
|
|
|
|
2000-07-06 04:43:04 +04:00
|
|
|
sc = device_lookup(&midi_cd, MIDIUNIT(dev));
|
|
|
|
if (sc == NULL)
|
|
|
|
return (ENXIO);
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return (EIO);
|
2000-07-06 04:43:04 +04:00
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
DPRINTF(("midiopen %p\n", sc));
|
|
|
|
|
|
|
|
hw = sc->hw_if;
|
|
|
|
if (!hw)
|
|
|
|
return ENXIO;
|
|
|
|
if (sc->isopen)
|
|
|
|
return EBUSY;
|
|
|
|
sc->in_state = MIDI_IN_START;
|
|
|
|
sc->in_status = 0;
|
|
|
|
error = hw->open(sc->hw_hdl, flags, midi_in, midi_out, sc);
|
|
|
|
if (error)
|
|
|
|
return error;
|
|
|
|
sc->isopen++;
|
1998-09-13 10:30:25 +04:00
|
|
|
midi_initbuf(&sc->outbuf);
|
|
|
|
midi_initbuf(&sc->inbuf);
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->flags = flags;
|
|
|
|
sc->rchan = 0;
|
|
|
|
sc->wchan = 0;
|
|
|
|
sc->pbus = 0;
|
|
|
|
sc->async = 0;
|
|
|
|
|
1998-08-18 01:16:09 +04:00
|
|
|
#ifdef MIDI_SAVE
|
|
|
|
if (midicnt != 0) {
|
|
|
|
midisave.cnt = midicnt;
|
|
|
|
midicnt = 0;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
midiclose(dev_t dev, int flags, int ifmt, struct proc *p)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
int unit = MIDIUNIT(dev);
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
2004-10-29 16:57:15 +04:00
|
|
|
const struct midi_hw_if *hw = sc->hw_if;
|
1998-08-07 04:00:55 +04:00
|
|
|
int s, error;
|
|
|
|
|
|
|
|
DPRINTF(("midiclose %p\n", sc));
|
|
|
|
|
|
|
|
midi_start_output(sc, 0);
|
|
|
|
error = 0;
|
|
|
|
s = splaudio();
|
|
|
|
while (sc->outbuf.used > 0 && !error) {
|
|
|
|
DPRINTFN(2,("midiclose sleep used=%d\n", sc->outbuf.used));
|
1998-08-13 04:13:56 +04:00
|
|
|
error = midi_sleep_timo(&sc->wchan, "mid_dr", 30*hz);
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
splx(s);
|
1998-09-13 10:30:25 +04:00
|
|
|
sc->isopen = 0;
|
1998-08-07 04:00:55 +04:00
|
|
|
hw->close(sc->hw_hdl);
|
|
|
|
#if NSEQUENCER > 0
|
|
|
|
sc->seqopen = 0;
|
1998-10-05 13:21:41 +04:00
|
|
|
sc->seq_md = 0;
|
1998-08-07 04:00:55 +04:00
|
|
|
#endif
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midiread(dev_t dev, struct uio *uio, int ioflag)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
int unit = MIDIUNIT(dev);
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
|
|
|
struct midi_buffer *mb = &sc->inbuf;
|
|
|
|
int error;
|
|
|
|
u_char *outp;
|
|
|
|
int used, cc, n, resid;
|
|
|
|
int s;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTF(("midiread: %p, count=%lu\n", sc,
|
1999-02-26 04:18:09 +03:00
|
|
|
(unsigned long)uio->uio_resid));
|
1998-08-07 04:00:55 +04:00
|
|
|
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
error = 0;
|
|
|
|
resid = uio->uio_resid;
|
|
|
|
while (uio->uio_resid == resid && !error) {
|
|
|
|
s = splaudio();
|
|
|
|
while (mb->used <= 0) {
|
|
|
|
if (ioflag & IO_NDELAY) {
|
|
|
|
splx(s);
|
|
|
|
return EWOULDBLOCK;
|
|
|
|
}
|
|
|
|
error = midi_sleep(&sc->rchan, "mid rd");
|
|
|
|
if (error) {
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
used = mb->used;
|
|
|
|
outp = mb->outp;
|
|
|
|
splx(s);
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
1998-08-07 04:00:55 +04:00
|
|
|
cc = used; /* maximum to read */
|
|
|
|
n = mb->end - outp;
|
|
|
|
if (n < cc)
|
|
|
|
cc = n; /* don't read beyond end of buffer */
|
|
|
|
if (uio->uio_resid < cc)
|
|
|
|
cc = uio->uio_resid; /* and no more than we want */
|
|
|
|
DPRINTFN(3, ("midiread: uiomove cc=%d\n", cc));
|
|
|
|
error = uiomove(outp, cc, uio);
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
used -= cc;
|
|
|
|
outp += cc;
|
|
|
|
if (outp >= mb->end)
|
|
|
|
outp = mb->start;
|
|
|
|
s = splaudio();
|
|
|
|
mb->outp = outp;
|
|
|
|
mb->used = used;
|
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_timeout(void *arg)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = arg;
|
|
|
|
|
|
|
|
DPRINTFN(3,("midi_timeout: %p\n", sc));
|
|
|
|
midi_start_output(sc, 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_start_output(struct midi_softc *sc, int intr)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_buffer *mb = &sc->outbuf;
|
2001-01-31 19:19:35 +03:00
|
|
|
u_char out;
|
1998-08-07 04:00:55 +04:00
|
|
|
int error;
|
|
|
|
int s;
|
2001-01-31 02:02:18 +03:00
|
|
|
int i;
|
1998-08-07 04:00:55 +04:00
|
|
|
|
|
|
|
error = 0;
|
2001-01-13 19:09:04 +03:00
|
|
|
|
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
if (sc->pbus && !intr) {
|
|
|
|
DPRINTFN(4, ("midi_start_output: busy\n"));
|
|
|
|
return 0;
|
|
|
|
}
|
2001-01-31 02:02:18 +03:00
|
|
|
sc->pbus = (mb->used > 0)?1:0;
|
|
|
|
for (i = 0; i < MIDI_MAX_WRITE && mb->used > 0 &&
|
|
|
|
(!error || error==EINPROGRESS); i++) {
|
|
|
|
s = splaudio();
|
2001-01-31 19:19:35 +03:00
|
|
|
out = *mb->outp;
|
|
|
|
mb->outp++;
|
|
|
|
if (mb->outp >= mb->end)
|
|
|
|
mb->outp = mb->start;
|
|
|
|
mb->used--;
|
|
|
|
splx(s);
|
1998-08-18 01:16:09 +04:00
|
|
|
#ifdef MIDI_SAVE
|
2001-01-31 19:19:35 +03:00
|
|
|
midisave.buf[midicnt] = out;
|
1998-08-18 01:16:09 +04:00
|
|
|
midicnt = (midicnt + 1) % MIDI_SAVE_SIZE;
|
|
|
|
#endif
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTFN(4, ("midi_start_output: %p i=%d, data=0x%02x\n",
|
2001-01-31 19:19:35 +03:00
|
|
|
sc, i, out));
|
|
|
|
error = sc->hw_if->output(sc->hw_hdl, out);
|
2001-01-31 02:02:18 +03:00
|
|
|
if ((sc->props & MIDI_PROP_OUT_INTR) && error!=EINPROGRESS)
|
|
|
|
/* If ointr is enabled, midi_start_output()
|
|
|
|
* normally writes only one byte,
|
|
|
|
* except hw_if->output() returns EINPROGRESS.
|
|
|
|
*/
|
|
|
|
break;
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
midi_wakeup(&sc->wchan);
|
2002-10-23 13:10:23 +04:00
|
|
|
selnotify(&sc->wsel, 0);
|
1998-08-07 04:00:55 +04:00
|
|
|
if (sc->async)
|
|
|
|
psignal(sc->async, SIGIO);
|
2001-01-31 02:02:18 +03:00
|
|
|
if (!(sc->props & MIDI_PROP_OUT_INTR) || error==EINPROGRESS) {
|
|
|
|
if (mb->used > 0)
|
2000-03-23 10:01:25 +03:00
|
|
|
callout_reset(&sc->sc_callout, midi_wait,
|
2001-01-31 02:02:18 +03:00
|
|
|
midi_timeout, sc);
|
|
|
|
else
|
|
|
|
sc->pbus = 0;
|
|
|
|
}
|
|
|
|
if ((sc->props & MIDI_PROP_OUT_INTR) && error==EINPROGRESS)
|
|
|
|
error = 0;
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midiwrite(dev_t dev, struct uio *uio, int ioflag)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
int unit = MIDIUNIT(dev);
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
|
|
|
struct midi_buffer *mb = &sc->outbuf;
|
|
|
|
int error;
|
|
|
|
u_char *inp;
|
|
|
|
int used, cc, n;
|
|
|
|
int s;
|
|
|
|
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTFN(2, ("midiwrite: %p, unit=%d, count=%lu\n", sc, unit,
|
1999-02-26 04:18:09 +03:00
|
|
|
(unsigned long)uio->uio_resid));
|
1998-08-07 04:00:55 +04:00
|
|
|
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
error = 0;
|
|
|
|
while (uio->uio_resid > 0 && !error) {
|
|
|
|
s = splaudio();
|
|
|
|
if (mb->used >= mb->usedhigh) {
|
2005-02-27 03:26:58 +03:00
|
|
|
DPRINTFN(3,("midi_write: sleep used=%d hiwat=%d\n",
|
1998-08-07 04:00:55 +04:00
|
|
|
mb->used, mb->usedhigh));
|
|
|
|
if (ioflag & IO_NDELAY) {
|
|
|
|
splx(s);
|
|
|
|
return EWOULDBLOCK;
|
|
|
|
}
|
|
|
|
error = midi_sleep(&sc->wchan, "mid wr");
|
|
|
|
if (error) {
|
|
|
|
splx(s);
|
|
|
|
return error;
|
|
|
|
}
|
2005-02-27 03:26:58 +03:00
|
|
|
}
|
1998-08-07 04:00:55 +04:00
|
|
|
used = mb->used;
|
|
|
|
inp = mb->inp;
|
|
|
|
splx(s);
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
1998-08-07 04:00:55 +04:00
|
|
|
cc = mb->usedhigh - used; /* maximum to write */
|
|
|
|
n = mb->end - inp;
|
|
|
|
if (n < cc)
|
1998-12-15 21:03:07 +03:00
|
|
|
cc = n; /* don't write beyond end of buffer */
|
1998-08-07 04:00:55 +04:00
|
|
|
if (uio->uio_resid < cc)
|
|
|
|
cc = uio->uio_resid; /* and no more than we have */
|
|
|
|
error = uiomove(inp, cc, uio);
|
|
|
|
#ifdef MIDI_DEBUG
|
|
|
|
if (error)
|
1998-12-15 21:03:07 +03:00
|
|
|
printf("midi_write:(1) uiomove failed %d; "
|
|
|
|
"cc=%d inp=%p\n",
|
1998-08-07 04:00:55 +04:00
|
|
|
error, cc, inp);
|
|
|
|
#endif
|
|
|
|
if (error)
|
|
|
|
break;
|
|
|
|
inp = mb->inp + cc;
|
|
|
|
if (inp >= mb->end)
|
|
|
|
inp = mb->start;
|
|
|
|
s = splaudio();
|
|
|
|
mb->inp = inp;
|
|
|
|
mb->used += cc;
|
|
|
|
splx(s);
|
|
|
|
error = midi_start_output(sc, 0);
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
1998-08-24 21:59:25 +04:00
|
|
|
/*
|
1998-12-15 21:03:07 +03:00
|
|
|
* This write routine is only called from sequencer code and expects
|
1998-08-24 21:59:25 +04:00
|
|
|
* a write that is smaller than the MIDI buffer.
|
|
|
|
*/
|
|
|
|
int
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_writebytes(int unit, u_char *buf, int cc)
|
1998-08-24 21:59:25 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
|
|
|
struct midi_buffer *mb = &sc->outbuf;
|
|
|
|
int n, s;
|
|
|
|
|
|
|
|
DPRINTFN(2, ("midi_writebytes: %p, unit=%d, cc=%d\n", sc, unit, cc));
|
1998-12-15 21:03:07 +03:00
|
|
|
DPRINTFN(3, ("midi_writebytes: %x %x %x\n",buf[0],buf[1],buf[2]));
|
1998-08-24 21:59:25 +04:00
|
|
|
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
|
|
|
|
1998-08-24 21:59:25 +04:00
|
|
|
s = splaudio();
|
|
|
|
if (mb->used + cc >= mb->usedhigh) {
|
|
|
|
splx(s);
|
|
|
|
return (EWOULDBLOCK);
|
|
|
|
}
|
|
|
|
n = mb->end - mb->inp;
|
|
|
|
if (cc < n)
|
|
|
|
n = cc;
|
1998-12-15 21:03:07 +03:00
|
|
|
mb->used += cc;
|
|
|
|
memcpy(mb->inp, buf, n);
|
1998-08-24 21:59:25 +04:00
|
|
|
mb->inp += n;
|
|
|
|
if (mb->inp >= mb->end) {
|
|
|
|
mb->inp = mb->start;
|
|
|
|
cc -= n;
|
|
|
|
if (cc > 0) {
|
|
|
|
memcpy(mb->inp, buf + n, cc);
|
|
|
|
mb->inp += cc;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
splx(s);
|
|
|
|
return (midi_start_output(sc, 0));
|
|
|
|
}
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
midiioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
int unit = MIDIUNIT(dev);
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
2004-10-29 16:57:15 +04:00
|
|
|
const struct midi_hw_if *hw = sc->hw_if;
|
1998-08-07 04:00:55 +04:00
|
|
|
int error;
|
|
|
|
|
|
|
|
DPRINTF(("midiioctl: %p cmd=0x%08lx\n", sc, cmd));
|
2001-01-13 19:09:04 +03:00
|
|
|
|
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
error = 0;
|
|
|
|
switch (cmd) {
|
|
|
|
case FIONBIO:
|
|
|
|
/* All handled in the upper FS layer. */
|
|
|
|
break;
|
|
|
|
|
|
|
|
case FIOASYNC:
|
|
|
|
if (*(int *)addr) {
|
|
|
|
if (sc->async)
|
|
|
|
return EBUSY;
|
2003-06-30 02:28:00 +04:00
|
|
|
sc->async = p;
|
|
|
|
DPRINTF(("midi_ioctl: FIOASYNC %p\n", p));
|
1998-08-07 04:00:55 +04:00
|
|
|
} else
|
|
|
|
sc->async = 0;
|
|
|
|
break;
|
|
|
|
|
|
|
|
#if 0
|
|
|
|
case MIDI_PRETIME:
|
|
|
|
/* XXX OSS
|
|
|
|
* This should set up a read timeout, but that's
|
|
|
|
* why we have poll(), so there's nothing yet. */
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1998-08-18 01:16:09 +04:00
|
|
|
#ifdef MIDI_SAVE
|
|
|
|
case MIDI_GETSAVE:
|
|
|
|
error = copyout(&midisave, *(void **)addr, sizeof midisave);
|
|
|
|
break;
|
|
|
|
#endif
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
default:
|
|
|
|
if (hw->ioctl)
|
2003-06-30 02:28:00 +04:00
|
|
|
error = hw->ioctl(sc->hw_hdl, cmd, addr, flag, p);
|
1998-08-07 04:00:55 +04:00
|
|
|
else
|
|
|
|
error = EINVAL;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return error;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2003-06-30 02:28:00 +04:00
|
|
|
midipoll(dev_t dev, int events, struct proc *p)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
int unit = MIDIUNIT(dev);
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
|
|
|
int revents = 0;
|
2002-06-01 21:54:21 +04:00
|
|
|
int s;
|
1998-08-07 04:00:55 +04:00
|
|
|
|
|
|
|
DPRINTF(("midipoll: %p events=0x%x\n", sc, events));
|
|
|
|
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return EIO;
|
|
|
|
|
2002-06-01 21:54:21 +04:00
|
|
|
s = splaudio();
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
if (events & (POLLIN | POLLRDNORM))
|
|
|
|
if (sc->inbuf.used > 0)
|
|
|
|
revents |= events & (POLLIN | POLLRDNORM);
|
|
|
|
|
|
|
|
if (events & (POLLOUT | POLLWRNORM))
|
|
|
|
if (sc->outbuf.used < sc->outbuf.usedhigh)
|
|
|
|
revents |= events & (POLLOUT | POLLWRNORM);
|
|
|
|
|
|
|
|
if (revents == 0) {
|
|
|
|
if (events & (POLLIN | POLLRDNORM))
|
2003-06-30 02:28:00 +04:00
|
|
|
selrecord(p, &sc->rsel);
|
1998-08-07 04:00:55 +04:00
|
|
|
|
|
|
|
if (events & (POLLOUT | POLLWRNORM))
|
2003-06-30 02:28:00 +04:00
|
|
|
selrecord(p, &sc->wsel);
|
1998-08-07 04:00:55 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
splx(s);
|
|
|
|
return revents;
|
|
|
|
}
|
|
|
|
|
2002-10-23 13:10:23 +04:00
|
|
|
static void
|
|
|
|
filt_midirdetach(struct knote *kn)
|
|
|
|
{
|
|
|
|
struct midi_softc *sc = kn->kn_hook;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splaudio();
|
2002-11-26 21:49:40 +03:00
|
|
|
SLIST_REMOVE(&sc->rsel.sel_klist, kn, knote, kn_selnext);
|
2002-10-23 13:10:23 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_midiread(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
struct midi_softc *sc = kn->kn_hook;
|
|
|
|
|
|
|
|
/* XXXLUKEM (thorpej): please make sure this is correct. */
|
|
|
|
|
|
|
|
kn->kn_data = sc->inbuf.used;
|
|
|
|
return (kn->kn_data > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct filterops midiread_filtops =
|
|
|
|
{ 1, NULL, filt_midirdetach, filt_midiread };
|
|
|
|
|
|
|
|
static void
|
|
|
|
filt_midiwdetach(struct knote *kn)
|
|
|
|
{
|
|
|
|
struct midi_softc *sc = kn->kn_hook;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
s = splaudio();
|
2002-11-26 21:49:40 +03:00
|
|
|
SLIST_REMOVE(&sc->wsel.sel_klist, kn, knote, kn_selnext);
|
2002-10-23 13:10:23 +04:00
|
|
|
splx(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
filt_midiwrite(struct knote *kn, long hint)
|
|
|
|
{
|
|
|
|
struct midi_softc *sc = kn->kn_hook;
|
|
|
|
|
|
|
|
/* XXXLUKEM (thorpej): please make sure this is correct. */
|
|
|
|
|
|
|
|
kn->kn_data = sc->outbuf.usedhigh - sc->outbuf.used;
|
|
|
|
return (kn->kn_data > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
static const struct filterops midiwrite_filtops =
|
|
|
|
{ 1, NULL, filt_midiwdetach, filt_midiwrite };
|
|
|
|
|
|
|
|
int
|
|
|
|
midikqfilter(dev_t dev, struct knote *kn)
|
|
|
|
{
|
|
|
|
int unit = MIDIUNIT(dev);
|
|
|
|
struct midi_softc *sc = midi_cd.cd_devs[unit];
|
|
|
|
struct klist *klist;
|
|
|
|
int s;
|
|
|
|
|
|
|
|
switch (kn->kn_filter) {
|
|
|
|
case EVFILT_READ:
|
2002-11-26 21:49:40 +03:00
|
|
|
klist = &sc->rsel.sel_klist;
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_fop = &midiread_filtops;
|
|
|
|
break;
|
|
|
|
|
|
|
|
case EVFILT_WRITE:
|
2002-11-26 21:49:40 +03:00
|
|
|
klist = &sc->wsel.sel_klist;
|
2002-10-23 13:10:23 +04:00
|
|
|
kn->kn_fop = &midiwrite_filtops;
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
kn->kn_hook = sc;
|
|
|
|
|
|
|
|
s = splaudio();
|
|
|
|
SLIST_INSERT_HEAD(klist, kn, kn_selnext);
|
|
|
|
splx(s);
|
|
|
|
|
|
|
|
return (0);
|
|
|
|
}
|
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
void
|
2001-10-03 02:41:22 +04:00
|
|
|
midi_getinfo(dev_t dev, struct midi_info *mi)
|
1998-08-07 04:00:55 +04:00
|
|
|
{
|
|
|
|
struct midi_softc *sc;
|
|
|
|
|
2000-07-06 04:43:04 +04:00
|
|
|
sc = device_lookup(&midi_cd, MIDIUNIT(dev));
|
|
|
|
if (sc == NULL)
|
1998-08-07 04:00:55 +04:00
|
|
|
return;
|
2001-01-13 19:09:04 +03:00
|
|
|
if (sc->dying)
|
|
|
|
return;
|
2000-07-06 04:43:04 +04:00
|
|
|
|
1998-08-07 04:00:55 +04:00
|
|
|
sc->hw_if->getinfo(sc->hw_hdl, mi);
|
|
|
|
}
|
|
|
|
|
1998-12-20 17:26:44 +03:00
|
|
|
#endif /* NMIDI > 0 */
|
|
|
|
|
|
|
|
#if NMIDI > 0 || NMIDIBUS > 0
|
|
|
|
|
2001-10-03 02:41:22 +04:00
|
|
|
int audioprint(void *, const char *);
|
1998-08-18 01:16:09 +04:00
|
|
|
|
1999-09-09 14:24:39 +04:00
|
|
|
struct device *
|
2004-10-29 16:57:15 +04:00
|
|
|
midi_attach_mi(const struct midi_hw_if *mhwp, void *hdlp, struct device *dev)
|
1998-08-18 01:16:09 +04:00
|
|
|
{
|
|
|
|
struct audio_attach_args arg;
|
|
|
|
|
|
|
|
#ifdef DIAGNOSTIC
|
|
|
|
if (mhwp == NULL) {
|
2003-01-31 05:15:57 +03:00
|
|
|
aprint_error("midi_attach_mi: NULL\n");
|
1999-09-09 14:24:39 +04:00
|
|
|
return (0);
|
1998-08-18 01:16:09 +04:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
arg.type = AUDIODEV_TYPE_MIDI;
|
|
|
|
arg.hwif = mhwp;
|
|
|
|
arg.hdl = hdlp;
|
1999-09-09 14:24:39 +04:00
|
|
|
return (config_found(dev, &arg, audioprint));
|
1998-08-18 01:16:09 +04:00
|
|
|
}
|
|
|
|
|
1998-12-20 17:26:44 +03:00
|
|
|
#endif /* NMIDI > 0 || NMIDIBUS > 0 */
|