Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb separate mididev and jack logically.



details:   https://anonhg.NetBSD.org/src/rev/9abe142a49fe
branches:  trunk
changeset: 503244:9abe142a49fe
user:      tshiozak <tshiozak%NetBSD.org@localhost>
date:      Sat Feb 03 18:50:31 2001 +0000

description:
separate mididev and jack logically.

diffstat:

 sys/dev/usb/umidi.c    |  363 ++++++++++++++++++++++++++----------------------
 sys/dev/usb/umidivar.h |   45 +++--
 2 files changed, 223 insertions(+), 185 deletions(-)

diffs (truncated from 670 to 300 lines):

diff -r 30d12b00ad4b -r 9abe142a49fe sys/dev/usb/umidi.c
--- a/sys/dev/usb/umidi.c       Sat Feb 03 18:43:45 2001 +0000
+++ b/sys/dev/usb/umidi.c       Sat Feb 03 18:50:31 2001 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: umidi.c,v 1.3 2001/02/03 16:49:06 tshiozak Exp $       */
+/*     $NetBSD: umidi.c,v 1.4 2001/02/03 18:50:31 tshiozak Exp $       */
 /*
  * Copyright (c) 2001 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -89,11 +89,15 @@
                                         struct umidi_jack *,
                                         struct umidi_jack *,
                                         struct umidi_mididev *);
-static usbd_status unbind_jacks_from_mididev(struct umidi_mididev *);
-static usbd_status unbind_all_jacks(struct umidi_softc *);
+static void unbind_jacks_from_mididev(struct umidi_mididev *);
+static void unbind_all_jacks(struct umidi_softc *);
 static usbd_status assign_all_jacks_automatically(struct umidi_softc *);
-static usbd_status open_jack(struct umidi_jack *);
-static void close_jack(struct umidi_jack *);
+static usbd_status open_out_jack(struct umidi_jack *, void *,
+                                void (*)(void *));
+static usbd_status open_in_jack(struct umidi_jack *, void *,
+                               void (*)(void *, int));
+static void close_out_jack(struct umidi_jack *);
+static void close_in_jack(struct umidi_jack *);
 
 static usbd_status attach_mididev(struct umidi_softc *,
                                  struct umidi_mididev *);
@@ -113,9 +117,9 @@
 
 static void init_packet(struct umidi_packet *);
 
-static void in_packet_to_mididev(struct umidi_endpoint *, uByte *);
 static usbd_status start_input_transfer(struct umidi_endpoint *);
 static usbd_status start_output_transfer(struct umidi_endpoint *);
+static int out_jack_output(struct umidi_jack *, int);
 static void in_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
 static void out_intr(usbd_xfer_handle, usbd_private_handle, usbd_status);
 static void out_build_packet(int, struct umidi_packet *, uByte);
@@ -251,7 +255,6 @@
 
        sc->sc_dying = 1;
        detach_all_mididevs(sc, flags);
-       unbind_all_jacks(sc);
        free_all_mididevs(sc);
        free_all_jacks(sc);
        free_all_endpoints(sc);
@@ -263,6 +266,9 @@
 }
 
 
+/*
+ * midi_if stuffs
+ */
 int
 umidi_open(void *addr,
           int flags,
@@ -279,18 +285,15 @@
                return ENXIO;
        if (mididev->opened)
                return EBUSY;
-       if (sc->sc_dying || mididev->dying)
+       if (sc->sc_dying)
                return EIO;
 
+       mididev->opened = 1;
        mididev->flags = flags;
-       mididev->opened = 1;
-       mididev->arg = arg;
-       mididev->iintr = iintr;
-       mididev->ointr = ointr;
        if ((mididev->flags & FWRITE) && mididev->out_jack)
-               open_jack(mididev->out_jack);
+               open_out_jack(mididev->out_jack, arg, ointr);
        if ((mididev->flags & FREAD) && mididev->in_jack) {
-               open_jack(mididev->in_jack);
+               open_in_jack(mididev->in_jack, arg, iintr);
        }
 
        return 0;
@@ -304,74 +307,22 @@
 
        s = splusb();
        if ((mididev->flags & FWRITE) && mididev->out_jack)
-               close_jack(mididev->out_jack);
+               close_out_jack(mididev->out_jack);
        if ((mididev->flags & FREAD) && mididev->in_jack)
-               close_jack(mididev->in_jack);
+               close_in_jack(mididev->in_jack);
        mididev->opened = 0;
-       mididev->arg = NULL;
-       mididev->iintr = NULL;
-       mididev->ointr = NULL;
        splx(s);
 }
 
-#ifdef UMIDI_DEBUG
-#define DPR_PACKET(dir, sc, p)                                         \
-if ((unsigned char)(p)->buffer[1]!=0xFE)                               \
-       DPRINTFN(500,                                                   \
-                ("%s: umidi packet(" #dir "): %02X %02X %02X %02X\n",  \
-                 USBDEVNAME(sc->sc_dev),                               \
-                 (unsigned char)(p)->buffer[0],                        \
-                 (unsigned char)(p)->buffer[1],                        \
-                 (unsigned char)(p)->buffer[2],                        \
-                 (unsigned char)(p)->buffer[3]));
-#else
-#define DPR_PACKET(dir, sc, p)
-#endif
-
 int
 umidi_output(void *addr, int d)
 {
        struct umidi_mididev *mididev = addr;
-       struct umidi_softc *sc = mididev->sc;
-       struct umidi_jack *out_jack = mididev->out_jack;
-       struct umidi_endpoint *ep;
-       int error;
-       int s;
 
-       if (sc->sc_dying || mididev->dying || !mididev->opened)
+       if (!mididev->out_jack || !mididev->opened)
                return EIO;
 
-       error = 0;
-       if (out_jack && (ep=out_jack->endpoint)!=NULL && ep->buffer) {
-               DPRINTFN(1000, ("umidi_output: ep=%p 0x%02x\n", ep, d));
-               out_build_packet(out_jack->cable_number, &out_jack->packet, d);
-               switch (out_jack->packet.state) {
-               case PS_EXCL_0:
-               case PS_END:
-                       DPR_PACKET(out, sc, &out_jack->packet);
-                       s = splusb();
-                       if (LIST_EMPTY(&ep->queue)) {
-                               memcpy(ep->buffer,
-                                      out_jack->packet.buffer,
-                                      UMIDI_PACKET_SIZE);
-                               start_output_transfer(ep);
-                       }
-                       if (LIST_EMPTY(&ep->queue))
-                               LIST_INSERT_HEAD(&ep->queue,
-                                                out_jack, queue);
-                       else
-                               LIST_INSERT_AFTER(ep->queue_tail,
-                                                 out_jack, queue);
-                       ep->queue_tail = out_jack;
-                       splx(s);
-                       break;
-               default:
-                       error = EINPROGRESS;
-               }
-       } else
-               error = ENODEV;
-
-       return error;
+       return out_jack_output(mididev->out_jack, d);
 }
 
 void
@@ -387,7 +338,9 @@
 }
 
 
-/* --- */
+/*
+ * each endpoint stuffs
+ */
 
 /* alloc/free pipe */
 static usbd_status
@@ -397,7 +350,7 @@
        usbd_status err;
 
        DPRINTF(("%s: alloc_pipe %p\n", USBDEVNAME(sc->sc_dev), ep));
-       LIST_INIT(&ep->queue);
+       LIST_INIT(&ep->queue_head);
        ep->xfer = usbd_alloc_xfer(sc->sc_udev);
        if (!ep->xfer) {
            err = USBD_NOMEM;
@@ -523,7 +476,7 @@
                sc->sc_out_num_jacks += fp->out_ep[i].num_jacks;
                ep->num_open = 0;
                memset(ep->jacks, 0, sizeof(ep->jacks));
-               LIST_INIT(&ep->queue);
+               LIST_INIT(&ep->queue_head);
                ep++;
        }
        ep = &sc->sc_in_ep[0];
@@ -741,7 +694,10 @@
 }
 
 
-/* */
+/*
+ * jack stuffs
+ */
+
 static usbd_status
 alloc_all_jacks(struct umidi_softc *sc)
 {
@@ -763,16 +719,20 @@
 
        jack = &sc->sc_out_jacks[0];
        for (i=0; i<sc->sc_out_num_jacks; i++) {
-               init_packet(&jack->packet);
+               jack->opened = 0;
+               jack->binded = 0;
+               jack->arg = NULL;
+               jack->u.out.intr = NULL;
                jack->cable_number = i;
-               jack->mididev = NULL;
                jack++;
        }
        jack = &sc->sc_in_jacks[0];
        for (i=0; i<sc->sc_in_num_jacks; i++) {
-               init_packet(&jack->packet);
+               jack->opened = 0;
+               jack->binded = 0;
+               jack->arg = NULL;
+               jack->u.in.intr = NULL;
                jack->cable_number = i;
-               jack->mididev = NULL;
                jack++;
        }
 
@@ -824,47 +784,45 @@
                      struct umidi_jack *in_jack,
                      struct umidi_mididev *mididev)
 {
-       if (mididev->opened || mididev->out_jack || mididev->in_jack)
+       if (out_jack->binded || in_jack->binded)
+               return USBD_IN_USE;
+       if (mididev->out_jack || mididev->in_jack)
                return USBD_IN_USE;
 
+       if (out_jack)
+               out_jack->binded = 1;
+       if (in_jack)
+               in_jack->binded = 1;
        mididev->in_jack = in_jack;
        mididev->out_jack = out_jack;
-       if (in_jack)
-               in_jack->mididev = mididev;
-       if (out_jack)
-               out_jack->mididev = mididev;
 
        return USBD_NORMAL_COMPLETION;
 }
 
-static usbd_status
+static void
 unbind_jacks_from_mididev(struct umidi_mididev *mididev)
 {
-       if (mididev->opened) {
-               if ((mididev->flags&FWRITE) && mididev->out_jack)
-                       close_jack(mididev->out_jack);
-               if ((mididev->flags&FWRITE) && mididev->in_jack)
-                       close_jack(mididev->in_jack);
-               mididev->out_jack = mididev->in_jack = NULL;
-       }
+       if ((mididev->flags&FWRITE) && mididev->out_jack)
+               close_out_jack(mididev->out_jack);
+       if ((mididev->flags&FWRITE) && mididev->in_jack)
+               close_in_jack(mididev->in_jack);
 
-       return USBD_NORMAL_COMPLETION;
+       if (mididev->out_jack)
+               mididev->out_jack->binded = 0;
+       if (mididev->in_jack)
+               mididev->in_jack->binded = 0;
+       mididev->out_jack = mididev->in_jack = NULL;
 }
 
-static usbd_status
+static void
 unbind_all_jacks(struct umidi_softc *sc)
 {
-       usbd_status err;
        int i;
 
        if (sc->sc_mididevs)
                for (i=0; i<sc->sc_num_mididevs; i++) {
-                       err = unbind_jacks_from_mididev(&sc->sc_mididevs[i]);
-                       if (err!=USBD_NORMAL_COMPLETION)
-                               return err;
+                       unbind_jacks_from_mididev(&sc->sc_mididevs[i]);
                }
-
-       return USBD_NORMAL_COMPLETION;
 }
 
 static usbd_status
@@ -894,14 +852,34 @@
 }
 
 static usbd_status
-open_jack(struct umidi_jack *jack)
+open_out_jack(struct umidi_jack *jack, void *arg, void (*intr)(void *))
+{



Home | Main Index | Thread Index | Old Index