midi.c revision 1.18 1 /* $NetBSD: midi.c,v 1.18 2001/01/13 16:09:04 tshiozak Exp $ */
2
3 /*
4 * Copyright (c) 1998 The NetBSD Foundation, Inc.
5 * All rights reserved.
6 *
7 * This code is derived from software contributed to The NetBSD Foundation
8 * by Lennart Augustsson (augustss (at) netbsd.org).
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the NetBSD
21 * Foundation, Inc. and its contributors.
22 * 4. Neither the name of The NetBSD Foundation nor the names of its
23 * contributors may be used to endorse or promote products derived
24 * from this software without specific prior written permission.
25 *
26 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
27 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
28 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
30 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
31 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
32 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
33 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
34 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
35 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
36 * POSSIBILITY OF SUCH DAMAGE.
37 */
38
39 #include "midi.h"
40 #include "sequencer.h"
41
42 #include <sys/param.h>
43 #include <sys/ioctl.h>
44 #include <sys/fcntl.h>
45 #include <sys/vnode.h>
46 #include <sys/select.h>
47 #include <sys/poll.h>
48 #include <sys/malloc.h>
49 #include <sys/proc.h>
50 #include <sys/systm.h>
51 #include <sys/callout.h>
52 #include <sys/syslog.h>
53 #include <sys/kernel.h>
54 #include <sys/signalvar.h>
55 #include <sys/conf.h>
56 #include <sys/audioio.h>
57 #include <sys/midiio.h>
58 #include <sys/device.h>
59
60 #include <dev/audio_if.h>
61 #include <dev/midi_if.h>
62 #include <dev/midivar.h>
63
64 #if NMIDI > 0
65
66 #ifdef AUDIO_DEBUG
67 #define DPRINTF(x) if (mididebug) printf x
68 #define DPRINTFN(n,x) if (mididebug >= (n)) printf x
69 int mididebug = 0;
70 #else
71 #define DPRINTF(x)
72 #define DPRINTFN(n,x)
73 #endif
74
75 int midi_wait;
76
77 void midi_in __P((void *, int));
78 void midi_out __P((void *));
79 int midi_start_output __P((struct midi_softc *, int));
80 int midi_sleep_timo __P((int *, char *, int));
81 int midi_sleep __P((int *, char *));
82 void midi_wakeup __P((int *));
83 void midi_initbuf __P((struct midi_buffer *));
84 void midi_timeout __P((void *));
85
86 int midiprobe __P((struct device *, struct cfdata *, void *));
87 void midiattach __P((struct device *, struct device *, void *));
88 int mididetach __P((struct device *, int));
89 int midiactivate __P((struct device *, enum devact));
90
91 struct cfattach midi_ca = {
92 sizeof(struct midi_softc), midiprobe, midiattach,
93 mididetach, midiactivate
94 };
95
96 #ifdef MIDI_SAVE
97 #define MIDI_SAVE_SIZE 100000
98 int midicnt;
99 struct {
100 int cnt;
101 u_char buf[MIDI_SAVE_SIZE];
102 } midisave;
103 #define MIDI_GETSAVE _IOWR('m', 100, int)
104
105 #endif
106
107 extern struct cfdriver midi_cd;
108
109 int
110 midiprobe(parent, match, aux)
111 struct device *parent;
112 struct cfdata *match;
113 void *aux;
114 {
115 struct audio_attach_args *sa = aux;
116
117 DPRINTFN(6,("midiprobe: type=%d sa=%p hw=%p\n",
118 sa->type, sa, sa->hwif));
119 return (sa->type == AUDIODEV_TYPE_MIDI);
120 }
121
122 void
123 midiattach(parent, self, aux)
124 struct device *parent, *self;
125 void *aux;
126 {
127 struct midi_softc *sc = (void *)self;
128 struct audio_attach_args *sa = aux;
129 struct midi_hw_if *hwp = sa->hwif;
130 void *hdlp = sa->hdl;
131
132 DPRINTFN(6, ("MIDI attach\n"));
133
134 #ifdef DIAGNOSTIC
135 if (hwp == 0 ||
136 hwp->open == 0 ||
137 hwp->close == 0 ||
138 hwp->output == 0 ||
139 hwp->getinfo == 0) {
140 printf("midi: missing method\n");
141 return;
142 }
143 #endif
144
145 callout_init(&sc->sc_callout);
146
147 sc->hw_if = hwp;
148 sc->hw_hdl = hdlp;
149 midi_attach(sc, parent);
150 }
151
152 int
153 midiactivate(self, act)
154 struct device *self;
155 enum devact act;
156 {
157 struct midi_softc *sc = (struct midi_softc *)self;
158
159 switch (act) {
160 case DVACT_ACTIVATE:
161 return (EOPNOTSUPP);
162 break;
163
164 case DVACT_DEACTIVATE:
165 sc->dying = 1;
166 break;
167 }
168 return (0);
169 }
170
171 int
172 mididetach(self, flags)
173 struct device *self;
174 int flags;
175 {
176 struct midi_softc *sc = (struct midi_softc *)self;
177 int maj, mn;
178
179 DPRINTF(("midi_detach: sc=%p flags=%d\n", sc, flags));
180
181 sc->dying = 1;
182
183 wakeup(&sc->wchan);
184 wakeup(&sc->rchan);
185
186 /* locate the major number */
187 for (maj = 0; maj < nchrdev; maj++)
188 if (cdevsw[maj].d_open == midiopen)
189 break;
190
191 /* Nuke the vnodes for any open instances (calls close). */
192 mn = self->dv_unit;
193 vdevgone(maj, mn, mn, VCHR);
194
195 return (0);
196 }
197
198 void
199 midi_attach(sc, parent)
200 struct midi_softc *sc;
201 struct device *parent;
202 {
203 struct midi_info mi;
204
205 sc->isopen = 0;
206
207 midi_wait = MIDI_WAIT * hz / 1000000;
208 if (midi_wait == 0)
209 midi_wait = 1;
210
211 sc->sc_dev = parent;
212 sc->hw_if->getinfo(sc->hw_hdl, &mi);
213 sc->props = mi.props;
214 printf(": %s\n", mi.name);
215 }
216
217 int
218 midi_unit_count()
219 {
220 return midi_cd.cd_ndevs;
221 }
222
223 void
224 midi_initbuf(mb)
225 struct midi_buffer *mb;
226 {
227 mb->used = 0;
228 mb->usedhigh = MIDI_BUFSIZE;
229 mb->end = mb->start + mb->usedhigh;
230 mb->inp = mb->outp = mb->start;
231 }
232
233 int
234 midi_sleep_timo(chan, label, timo)
235 int *chan;
236 char *label;
237 int timo;
238 {
239 int st;
240
241 if (!label)
242 label = "midi";
243
244 DPRINTFN(5, ("midi_sleep_timo: %p %s %d\n", chan, label, timo));
245 *chan = 1;
246 st = tsleep(chan, PWAIT | PCATCH, label, timo);
247 *chan = 0;
248 #ifdef MIDI_DEBUG
249 if (st != 0)
250 printf("midi_sleep: %d\n", st);
251 #endif
252 return st;
253 }
254
255 int
256 midi_sleep(chan, label)
257 int *chan;
258 char *label;
259 {
260 return midi_sleep_timo(chan, label, 0);
261 }
262
263 void
264 midi_wakeup(chan)
265 int *chan;
266 {
267 if (*chan) {
268 DPRINTFN(5, ("midi_wakeup: %p\n", chan));
269 wakeup(chan);
270 *chan = 0;
271 }
272 }
273
274 static int midi_lengths[] = { 2,2,2,2,1,1,2,0 };
275 /* Number of bytes in a MIDI command */
276 #define MIDI_LENGTH(d) (midi_lengths[((d) >> 4) & 7])
277
278 void
279 midi_in(addr, data)
280 void *addr;
281 int data;
282 {
283 struct midi_softc *sc = addr;
284 struct midi_buffer *mb = &sc->inbuf;
285 int i;
286
287 if (!sc->isopen)
288 return;
289 if (data == MIDI_ACK)
290 return;
291
292 DPRINTFN(3, ("midi_in: sc=%p data=0x%02x state=%d pos=%d\n",
293 sc, data, sc->in_state, sc->in_pos));
294
295 if (!(sc->flags & FREAD))
296 return; /* discard data if not reading */
297
298 switch(sc->in_state) {
299 case MIDI_IN_START:
300 if (MIDI_IS_STATUS(data)) {
301 switch(data) {
302 case 0xf0: /* Sysex */
303 sc->in_state = MIDI_IN_SYSEX;
304 break;
305 case 0xf1: /* MTC quarter frame */
306 case 0xf3: /* Song select */
307 sc->in_state = MIDI_IN_DATA;
308 sc->in_msg[0] = data;
309 sc->in_pos = 1;
310 sc->in_left = 1;
311 break;
312 case 0xf2: /* Song position pointer */
313 sc->in_state = MIDI_IN_DATA;
314 sc->in_msg[0] = data;
315 sc->in_pos = 1;
316 sc->in_left = 2;
317 break;
318 default:
319 if (MIDI_IS_COMMON(data)) {
320 sc->in_msg[0] = data;
321 sc->in_pos = 1;
322 goto deliver;
323 } else {
324 sc->in_state = MIDI_IN_DATA;
325 sc->in_msg[0] = sc->in_status = data;
326 sc->in_pos = 1;
327 sc->in_left = MIDI_LENGTH(data);
328 }
329 break;
330 }
331 } else {
332 if (MIDI_IS_STATUS(sc->in_status)) {
333 sc->in_state = MIDI_IN_DATA;
334 sc->in_msg[0] = sc->in_status;
335 sc->in_msg[1] = data;
336 sc->in_pos = 2;
337 sc->in_left = MIDI_LENGTH(sc->in_status) - 1;
338 }
339 }
340 return;
341 case MIDI_IN_DATA:
342 sc->in_msg[sc->in_pos++] = data;
343 if (--sc->in_left <= 0)
344 break; /* deliver data */
345 return;
346 case MIDI_IN_SYSEX:
347 if (data == MIDI_SYSEX_END)
348 sc->in_state = MIDI_IN_START;
349 return;
350 }
351 deliver:
352 sc->in_state = MIDI_IN_START;
353 #if NSEQUENCER > 0
354 if (sc->seqopen) {
355 extern void midiseq_in __P((struct midi_dev *,u_char *,int));
356 midiseq_in(sc->seq_md, sc->in_msg, sc->in_pos);
357 return;
358 }
359 #endif
360
361 if (mb->used + sc->in_pos > mb->usedhigh) {
362 DPRINTF(("midi_in: buffer full, discard data=0x%02x\n",
363 sc->in_msg[0]));
364 return;
365 }
366 for (i = 0; i < sc->in_pos; i++) {
367 *mb->inp++ = sc->in_msg[i];
368 if (mb->inp >= mb->end)
369 mb->inp = mb->start;
370 mb->used++;
371 }
372 midi_wakeup(&sc->rchan);
373 selwakeup(&sc->rsel);
374 if (sc->async)
375 psignal(sc->async, SIGIO);
376 }
377
378 void
379 midi_out(addr)
380 void *addr;
381 {
382 struct midi_softc *sc = addr;
383
384 if (!sc->isopen)
385 return;
386 DPRINTFN(3, ("midi_out: %p\n", sc));
387 midi_start_output(sc, 1);
388 }
389
390 int
391 midiopen(dev, flags, ifmt, p)
392 dev_t dev;
393 int flags, ifmt;
394 struct proc *p;
395 {
396 struct midi_softc *sc;
397 struct midi_hw_if *hw;
398 int error;
399
400 sc = device_lookup(&midi_cd, MIDIUNIT(dev));
401 if (sc == NULL)
402 return (ENXIO);
403 if (sc->dying)
404 return (EIO);
405
406 DPRINTF(("midiopen %p\n", sc));
407
408 hw = sc->hw_if;
409 if (!hw)
410 return ENXIO;
411 if (sc->isopen)
412 return EBUSY;
413 sc->in_state = MIDI_IN_START;
414 sc->in_status = 0;
415 error = hw->open(sc->hw_hdl, flags, midi_in, midi_out, sc);
416 if (error)
417 return error;
418 sc->isopen++;
419 midi_initbuf(&sc->outbuf);
420 midi_initbuf(&sc->inbuf);
421 sc->flags = flags;
422 sc->rchan = 0;
423 sc->wchan = 0;
424 sc->pbus = 0;
425 sc->async = 0;
426
427 #ifdef MIDI_SAVE
428 if (midicnt != 0) {
429 midisave.cnt = midicnt;
430 midicnt = 0;
431 }
432 #endif
433
434 return 0;
435 }
436
437 int
438 midiclose(dev, flags, ifmt, p)
439 dev_t dev;
440 int flags, ifmt;
441 struct proc *p;
442 {
443 int unit = MIDIUNIT(dev);
444 struct midi_softc *sc = midi_cd.cd_devs[unit];
445 struct midi_hw_if *hw = sc->hw_if;
446 int s, error;
447
448 DPRINTF(("midiclose %p\n", sc));
449
450 midi_start_output(sc, 0);
451 error = 0;
452 s = splaudio();
453 while (sc->outbuf.used > 0 && !error) {
454 DPRINTFN(2,("midiclose sleep used=%d\n", sc->outbuf.used));
455 error = midi_sleep_timo(&sc->wchan, "mid_dr", 30*hz);
456 }
457 splx(s);
458 sc->isopen = 0;
459 hw->close(sc->hw_hdl);
460 #if NSEQUENCER > 0
461 sc->seqopen = 0;
462 sc->seq_md = 0;
463 #endif
464 return 0;
465 }
466
467 int
468 midiread(dev, uio, ioflag)
469 dev_t dev;
470 struct uio *uio;
471 int ioflag;
472 {
473 int unit = MIDIUNIT(dev);
474 struct midi_softc *sc = midi_cd.cd_devs[unit];
475 struct midi_buffer *mb = &sc->inbuf;
476 int error;
477 u_char *outp;
478 int used, cc, n, resid;
479 int s;
480
481 DPRINTF(("midiread: %p, count=%lu\n", sc,
482 (unsigned long)uio->uio_resid));
483
484 if (sc->dying)
485 return EIO;
486
487 error = 0;
488 resid = uio->uio_resid;
489 while (uio->uio_resid == resid && !error) {
490 s = splaudio();
491 while (mb->used <= 0) {
492 if (ioflag & IO_NDELAY) {
493 splx(s);
494 return EWOULDBLOCK;
495 }
496 error = midi_sleep(&sc->rchan, "mid rd");
497 if (error) {
498 splx(s);
499 return error;
500 }
501 }
502 used = mb->used;
503 outp = mb->outp;
504 splx(s);
505 if (sc->dying)
506 return EIO;
507 cc = used; /* maximum to read */
508 n = mb->end - outp;
509 if (n < cc)
510 cc = n; /* don't read beyond end of buffer */
511 if (uio->uio_resid < cc)
512 cc = uio->uio_resid; /* and no more than we want */
513 DPRINTFN(3, ("midiread: uiomove cc=%d\n", cc));
514 error = uiomove(outp, cc, uio);
515 if (error)
516 break;
517 used -= cc;
518 outp += cc;
519 if (outp >= mb->end)
520 outp = mb->start;
521 s = splaudio();
522 mb->outp = outp;
523 mb->used = used;
524 splx(s);
525 }
526 return error;
527 }
528
529 void
530 midi_timeout(arg)
531 void *arg;
532 {
533 struct midi_softc *sc = arg;
534
535 DPRINTFN(3,("midi_timeout: %p\n", sc));
536 midi_start_output(sc, 1);
537 }
538
539 int
540 midi_start_output(sc, intr)
541 struct midi_softc *sc;
542 int intr;
543 {
544 struct midi_buffer *mb = &sc->outbuf;
545 u_char *outp;
546 int error;
547 int s;
548 int i, mmax;
549
550 error = 0;
551 mmax = sc->props & MIDI_PROP_OUT_INTR ? 1 : MIDI_MAX_WRITE;
552
553 if (sc->dying)
554 return EIO;
555
556 s = splaudio();
557 if (sc->pbus && !intr) {
558 DPRINTFN(4, ("midi_start_output: busy\n"));
559 splx(s);
560 return 0;
561 }
562 sc->pbus = 1;
563 for (i = 0; i < mmax && mb->used > 0 && !error; i++) {
564 outp = mb->outp;
565 splx(s);
566 DPRINTFN(4, ("midi_start_output: %p i=%d, data=0x%02x\n",
567 sc, i, *outp));
568 #ifdef MIDI_SAVE
569 midisave.buf[midicnt] = *outp;
570 midicnt = (midicnt + 1) % MIDI_SAVE_SIZE;
571 #endif
572 error = sc->hw_if->output(sc->hw_hdl, *outp++);
573 if (outp >= mb->end)
574 outp = mb->start;
575 s = splaudio();
576 mb->outp = outp;
577 mb->used--;
578 }
579 midi_wakeup(&sc->wchan);
580 selwakeup(&sc->wsel);
581 if (sc->async)
582 psignal(sc->async, SIGIO);
583 if (mb->used > 0) {
584 if (!(sc->props & MIDI_PROP_OUT_INTR))
585 callout_reset(&sc->sc_callout, midi_wait,
586 midi_timeout, sc);
587 } else
588 sc->pbus = 0;
589 splx(s);
590 return error;
591 }
592
593 int
594 midiwrite(dev, uio, ioflag)
595 dev_t dev;
596 struct uio *uio;
597 int ioflag;
598 {
599 int unit = MIDIUNIT(dev);
600 struct midi_softc *sc = midi_cd.cd_devs[unit];
601 struct midi_buffer *mb = &sc->outbuf;
602 int error;
603 u_char *inp;
604 int used, cc, n;
605 int s;
606
607 DPRINTFN(2, ("midiwrite: %p, unit=%d, count=%lu\n", sc, unit,
608 (unsigned long)uio->uio_resid));
609
610 if (sc->dying)
611 return EIO;
612
613 error = 0;
614 while (uio->uio_resid > 0 && !error) {
615 s = splaudio();
616 if (mb->used >= mb->usedhigh) {
617 DPRINTFN(3,("midi_write: sleep used=%d hiwat=%d\n",
618 mb->used, mb->usedhigh));
619 if (ioflag & IO_NDELAY) {
620 splx(s);
621 return EWOULDBLOCK;
622 }
623 error = midi_sleep(&sc->wchan, "mid wr");
624 if (error) {
625 splx(s);
626 return error;
627 }
628 }
629 used = mb->used;
630 inp = mb->inp;
631 splx(s);
632 if (sc->dying)
633 return EIO;
634 cc = mb->usedhigh - used; /* maximum to write */
635 n = mb->end - inp;
636 if (n < cc)
637 cc = n; /* don't write beyond end of buffer */
638 if (uio->uio_resid < cc)
639 cc = uio->uio_resid; /* and no more than we have */
640 error = uiomove(inp, cc, uio);
641 #ifdef MIDI_DEBUG
642 if (error)
643 printf("midi_write:(1) uiomove failed %d; "
644 "cc=%d inp=%p\n",
645 error, cc, inp);
646 #endif
647 if (error)
648 break;
649 inp = mb->inp + cc;
650 if (inp >= mb->end)
651 inp = mb->start;
652 s = splaudio();
653 mb->inp = inp;
654 mb->used += cc;
655 splx(s);
656 error = midi_start_output(sc, 0);
657 }
658 return error;
659 }
660
661 /*
662 * This write routine is only called from sequencer code and expects
663 * a write that is smaller than the MIDI buffer.
664 */
665 int
666 midi_writebytes(unit, buf, cc)
667 int unit;
668 u_char *buf;
669 int cc;
670 {
671 struct midi_softc *sc = midi_cd.cd_devs[unit];
672 struct midi_buffer *mb = &sc->outbuf;
673 int n, s;
674
675 DPRINTFN(2, ("midi_writebytes: %p, unit=%d, cc=%d\n", sc, unit, cc));
676 DPRINTFN(3, ("midi_writebytes: %x %x %x\n",buf[0],buf[1],buf[2]));
677
678 if (sc->dying)
679 return EIO;
680
681 s = splaudio();
682 if (mb->used + cc >= mb->usedhigh) {
683 splx(s);
684 return (EWOULDBLOCK);
685 }
686 n = mb->end - mb->inp;
687 if (cc < n)
688 n = cc;
689 mb->used += cc;
690 memcpy(mb->inp, buf, n);
691 mb->inp += n;
692 if (mb->inp >= mb->end) {
693 mb->inp = mb->start;
694 cc -= n;
695 if (cc > 0) {
696 memcpy(mb->inp, buf + n, cc);
697 mb->inp += cc;
698 }
699 }
700 splx(s);
701 return (midi_start_output(sc, 0));
702 }
703
704 int
705 midiioctl(dev, cmd, addr, flag, p)
706 dev_t dev;
707 u_long cmd;
708 caddr_t addr;
709 int flag;
710 struct proc *p;
711 {
712 int unit = MIDIUNIT(dev);
713 struct midi_softc *sc = midi_cd.cd_devs[unit];
714 struct midi_hw_if *hw = sc->hw_if;
715 int error;
716
717 DPRINTF(("midiioctl: %p cmd=0x%08lx\n", sc, cmd));
718
719 if (sc->dying)
720 return EIO;
721
722 error = 0;
723 switch (cmd) {
724 case FIONBIO:
725 /* All handled in the upper FS layer. */
726 break;
727
728 case FIOASYNC:
729 if (*(int *)addr) {
730 if (sc->async)
731 return EBUSY;
732 sc->async = p;
733 DPRINTF(("midi_ioctl: FIOASYNC %p\n", p));
734 } else
735 sc->async = 0;
736 break;
737
738 #if 0
739 case MIDI_PRETIME:
740 /* XXX OSS
741 * This should set up a read timeout, but that's
742 * why we have poll(), so there's nothing yet. */
743 error = EINVAL;
744 break;
745 #endif
746
747 #ifdef MIDI_SAVE
748 case MIDI_GETSAVE:
749 error = copyout(&midisave, *(void **)addr, sizeof midisave);
750 break;
751 #endif
752
753 default:
754 if (hw->ioctl)
755 error = hw->ioctl(sc->hw_hdl, cmd, addr, flag, p);
756 else
757 error = EINVAL;
758 break;
759 }
760 return error;
761 }
762
763 int
764 midipoll(dev, events, p)
765 dev_t dev;
766 int events;
767 struct proc *p;
768 {
769 int unit = MIDIUNIT(dev);
770 struct midi_softc *sc = midi_cd.cd_devs[unit];
771 int revents = 0;
772 int s = splaudio();
773
774 DPRINTF(("midipoll: %p events=0x%x\n", sc, events));
775
776 if (sc->dying)
777 return EIO;
778
779 if (events & (POLLIN | POLLRDNORM))
780 if (sc->inbuf.used > 0)
781 revents |= events & (POLLIN | POLLRDNORM);
782
783 if (events & (POLLOUT | POLLWRNORM))
784 if (sc->outbuf.used < sc->outbuf.usedhigh)
785 revents |= events & (POLLOUT | POLLWRNORM);
786
787 if (revents == 0) {
788 if (events & (POLLIN | POLLRDNORM))
789 selrecord(p, &sc->rsel);
790
791 if (events & (POLLOUT | POLLWRNORM))
792 selrecord(p, &sc->wsel);
793 }
794
795 splx(s);
796 return revents;
797 }
798
799 void
800 midi_getinfo(dev, mi)
801 dev_t dev;
802 struct midi_info *mi;
803 {
804 struct midi_softc *sc;
805
806 sc = device_lookup(&midi_cd, MIDIUNIT(dev));
807 if (sc == NULL)
808 return;
809 if (sc->dying)
810 return;
811
812 sc->hw_if->getinfo(sc->hw_hdl, mi);
813 }
814
815 #endif /* NMIDI > 0 */
816
817 #if NMIDI > 0 || NMIDIBUS > 0
818
819 int audioprint __P((void *, const char *));
820
821 struct device *
822 midi_attach_mi(mhwp, hdlp, dev)
823 struct midi_hw_if *mhwp;
824 void *hdlp;
825 struct device *dev;
826 {
827 struct audio_attach_args arg;
828
829 #ifdef DIAGNOSTIC
830 if (mhwp == NULL) {
831 printf("midi_attach_mi: NULL\n");
832 return (0);
833 }
834 #endif
835 arg.type = AUDIODEV_TYPE_MIDI;
836 arg.hwif = mhwp;
837 arg.hdl = hdlp;
838 return (config_found(dev, &arg, audioprint));
839 }
840
841 #endif /* NMIDI > 0 || NMIDIBUS > 0 */
842