Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev add detaching/deactivation code to midi driver.



details:   https://anonhg.NetBSD.org/src/rev/e47579e0094b
branches:  trunk
changeset: 502193:e47579e0094b
user:      tshiozak <tshiozak%NetBSD.org@localhost>
date:      Sat Jan 13 16:09:04 2001 +0000

description:
add detaching/deactivation code to midi driver.

diffstat:

 sys/dev/midi.c    |  81 +++++++++++++++++++++++++++++++++++++++++++++++++++++-
 sys/dev/midivar.h |   3 +-
 2 files changed, 81 insertions(+), 3 deletions(-)

diffs (191 lines):

diff -r c008eae16ea7 -r e47579e0094b sys/dev/midi.c
--- a/sys/dev/midi.c    Sat Jan 13 14:11:38 2001 +0000
+++ b/sys/dev/midi.c    Sat Jan 13 16:09:04 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: midi.c,v 1.17 2000/07/06 00:43:04 thorpej Exp $        */
+/*     $NetBSD: midi.c,v 1.18 2001/01/13 16:09:04 tshiozak Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -85,9 +85,12 @@
 
 int    midiprobe __P((struct device *, struct cfdata *, void *));
 void   midiattach __P((struct device *, struct device *, void *));
+int    mididetach __P((struct device *, int));
+int    midiactivate __P((struct device *, enum devact));
 
 struct cfattach midi_ca = {
-       sizeof(struct midi_softc), midiprobe, midiattach
+       sizeof(struct midi_softc), midiprobe, midiattach,
+       mididetach, midiactivate
 };
 
 #ifdef MIDI_SAVE
@@ -146,6 +149,52 @@
        midi_attach(sc, parent);
 }
 
+int
+midiactivate(self, act)
+       struct device *self;
+       enum devact act;
+{
+       struct midi_softc *sc = (struct midi_softc *)self;
+
+       switch (act) {
+       case DVACT_ACTIVATE:
+               return (EOPNOTSUPP);
+               break;
+
+       case DVACT_DEACTIVATE:
+               sc->dying = 1;
+               break;
+       }
+       return (0);
+}
+
+int
+mididetach(self, flags)
+       struct device *self;
+       int flags;
+{
+       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 */
+       for (maj = 0; maj < nchrdev; maj++)
+               if (cdevsw[maj].d_open == midiopen)
+                       break;
+
+       /* Nuke the vnodes for any open instances (calls close). */
+       mn = self->dv_unit;
+       vdevgone(maj, mn, mn, VCHR);
+
+       return (0);
+}
+
 void
 midi_attach(sc, parent)
        struct midi_softc *sc;
@@ -351,6 +400,8 @@
        sc = device_lookup(&midi_cd, MIDIUNIT(dev));
        if (sc == NULL)
                return (ENXIO);
+       if (sc->dying)
+               return (EIO);
 
        DPRINTF(("midiopen %p\n", sc));
 
@@ -430,6 +481,9 @@
        DPRINTF(("midiread: %p, count=%lu\n", sc, 
                 (unsigned long)uio->uio_resid));
 
+       if (sc->dying)
+               return EIO;
+
        error = 0;
        resid = uio->uio_resid;
        while (uio->uio_resid == resid && !error) {
@@ -448,6 +502,8 @@
                used = mb->used;
                outp = mb->outp;
                splx(s);
+               if (sc->dying)
+                       return EIO;
                cc = used;      /* maximum to read */
                n = mb->end - outp;
                if (n < cc)
@@ -493,6 +549,10 @@
 
        error = 0;
        mmax = sc->props & MIDI_PROP_OUT_INTR ? 1 : MIDI_MAX_WRITE;
+
+       if (sc->dying)
+               return EIO;
+
        s = splaudio();
        if (sc->pbus && !intr) {
                DPRINTFN(4, ("midi_start_output: busy\n"));
@@ -547,6 +607,9 @@
        DPRINTFN(2, ("midiwrite: %p, unit=%d, count=%lu\n", sc, unit, 
                     (unsigned long)uio->uio_resid));
 
+       if (sc->dying)
+               return EIO;
+
        error = 0;
        while (uio->uio_resid > 0 && !error) {
                s = splaudio();
@@ -566,6 +629,8 @@
                used = mb->used;
                inp = mb->inp;
                splx(s);
+               if (sc->dying)
+                       return EIO;
                cc = mb->usedhigh - used;       /* maximum to write */
                n = mb->end - inp;
                if (n < cc)
@@ -610,6 +675,9 @@
        DPRINTFN(2, ("midi_writebytes: %p, unit=%d, cc=%d\n", sc, unit, cc));
        DPRINTFN(3, ("midi_writebytes: %x %x %x\n",buf[0],buf[1],buf[2]));
 
+       if (sc->dying)
+               return EIO;
+
        s = splaudio();
        if (mb->used + cc >= mb->usedhigh) {
                splx(s);
@@ -647,6 +715,10 @@
        int error;
 
        DPRINTF(("midiioctl: %p cmd=0x%08lx\n", sc, cmd));
+
+       if (sc->dying)
+               return EIO;
+
        error = 0;
        switch (cmd) {
        case FIONBIO:
@@ -701,6 +773,9 @@
 
        DPRINTF(("midipoll: %p events=0x%x\n", sc, events));
 
+       if (sc->dying)
+               return EIO;
+
        if (events & (POLLIN | POLLRDNORM))
                if (sc->inbuf.used > 0)
                        revents |= events & (POLLIN | POLLRDNORM);
@@ -731,6 +806,8 @@
        sc = device_lookup(&midi_cd, MIDIUNIT(dev));
        if (sc == NULL)
                return;
+       if (sc->dying)
+               return;
 
        sc->hw_if->getinfo(sc->hw_hdl, mi);
 }
diff -r c008eae16ea7 -r e47579e0094b sys/dev/midivar.h
--- a/sys/dev/midivar.h Sat Jan 13 14:11:38 2001 +0000
+++ b/sys/dev/midivar.h Sat Jan 13 16:09:04 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: midivar.h,v 1.7 2000/03/23 07:01:26 thorpej Exp $      */
+/*     $NetBSD: midivar.h,v 1.8 2001/01/13 16:09:04 tshiozak Exp $     */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -64,6 +64,7 @@
        struct  device *sc_dev; /* Hardware device struct */
        int     isopen;         /* Open indicator */
        int     flags;          /* Open flags */
+       int     dying;
        struct  midi_buffer outbuf;
        struct  midi_buffer inbuf;
        int     props;



Home | Main Index | Thread Index | Old Index