Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Rearrange the code a little so we can decide if ...



details:   https://anonhg.NetBSD.org/src/rev/cc10b1287ed6
branches:  trunk
changeset: 476332:cc10b1287ed6
user:      augustss <augustss%NetBSD.org@localhost>
date:      Mon Sep 13 19:18:17 1999 +0000

description:
Rearrange the code a little so we can decide if we are in process
or interrupt context in a reliable way.  Mainly used for DIAGNOSTIC.

diffstat:

 sys/dev/usb/TODO       |   8 ++++++++
 sys/dev/usb/ohci.c     |  28 ++++++++++++++++------------
 sys/dev/usb/ohcivar.h  |   5 +----
 sys/dev/usb/uhci.c     |  39 +++++++++++++++++++++------------------
 sys/dev/usb/uhcivar.h  |   4 +---
 sys/dev/usb/uhub.c     |   4 +++-
 sys/dev/usb/usb.c      |   4 +++-
 sys/dev/usb/usb_mem.c  |  14 +++++++-------
 sys/dev/usb/usb_mem.h  |   6 +++---
 sys/dev/usb/usb_subr.c |   4 +++-
 sys/dev/usb/usbdi.c    |   4 ++--
 sys/dev/usb/usbdivar.h |   7 ++++++-
 12 files changed, 74 insertions(+), 53 deletions(-)

diffs (truncated from 476 to 300 lines):

diff -r 914534b4a5a4 -r cc10b1287ed6 sys/dev/usb/TODO
--- a/sys/dev/usb/TODO  Mon Sep 13 19:13:09 1999 +0000
+++ b/sys/dev/usb/TODO  Mon Sep 13 19:18:17 1999 +0000
@@ -38,6 +38,14 @@
        implement input
        test with more devices
 
+Stylistic changes:
+       use NULL not 0
+       declare all local definitions static
+       rename s/request/xfer/
+       use usb_ and usbd_ consistently
+       indent continuation lines according to KNF
+       rearrange the contents and names of some files (Nick)
+
 Document device driver API.
 
 Document HC driver API.
diff -r 914534b4a5a4 -r cc10b1287ed6 sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c        Mon Sep 13 19:13:09 1999 +0000
+++ b/sys/dev/usb/ohci.c        Mon Sep 13 19:18:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohci.c,v 1.43 1999/09/11 08:19:26 augustss Exp $       */
+/*     $NetBSD: ohci.c,v 1.44 1999/09/13 19:18:17 augustss Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -294,7 +294,7 @@
 
        if (!sc->sc_freeeds) {
                DPRINTFN(2, ("ohci_alloc_sed: allocating chunk\n"));
-               r = usb_allocmem(sc->sc_dmatag, OHCI_SED_SIZE * OHCI_SED_CHUNK,
+               r = usb_allocmem(&sc->sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK,
                                 OHCI_ED_ALIGN, &dma);
                if (r != USBD_NORMAL_COMPLETION)
                        return (0);
@@ -333,7 +333,7 @@
 
        if (!sc->sc_freetds) {
                DPRINTFN(2, ("ohci_alloc_std: allocating chunk\n"));
-               r = usb_allocmem(sc->sc_dmatag, OHCI_STD_SIZE * OHCI_STD_CHUNK,
+               r = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
                                 OHCI_TD_ALIGN, &dma);
                if (r != USBD_NORMAL_COMPLETION)
                        return (0);
@@ -390,7 +390,7 @@
                LIST_INIT(&sc->sc_hash_tds[i]);
 
        /* Allocate the HCCA area. */
-       r = usb_allocmem(sc->sc_dmatag, OHCI_HCCA_SIZE, 
+       r = usb_allocmem(&sc->sc_bus, OHCI_HCCA_SIZE, 
                         OHCI_HCCA_ALIGN, &sc->sc_hccadma);
        if (r != USBD_NORMAL_COMPLETION)
                return (r);
@@ -548,7 +548,7 @@
  bad2:
        ohci_free_sed(sc, sc->sc_bulk_head);
  bad1:
-       usb_freemem(sc->sc_dmatag, &sc->sc_hccadma);
+       usb_freemem(&sc->sc_bus, &sc->sc_hccadma);
        return (r);
 }
 
@@ -560,7 +560,7 @@
 {
        struct ohci_softc *sc = (struct ohci_softc *)bus;
 
-       return (usb_allocmem(sc->sc_dmatag, size, 0, dma));
+       return (usb_allocmem(&sc->sc_bus, size, 0, dma));
 }
 
 void
@@ -570,7 +570,7 @@
 {
        struct ohci_softc *sc = (struct ohci_softc *)bus;
 
-       usb_freemem(sc->sc_dmatag, dma);
+       usb_freemem(&sc->sc_bus, dma);
 }
 
 #if !defined(__OpenBSD__)
@@ -668,7 +668,8 @@
        if (!eintrs)
                return (0);
 
-       sc->sc_intrs++;
+       sc->sc_bus.intr_context = 1;
+       sc->sc_bus.no_intrs++;
        DPRINTFN(7, ("ohci_intr: sc=%p intrs=%x(%x) eintr=%x\n", 
                     sc, (u_int)intrs, OREAD4(sc, OHCI_INTERRUPT_STATUS),
                     (u_int)eintrs));
@@ -703,6 +704,8 @@
                ohci_rhsc_able(sc, 0);
        }
 
+       sc->sc_bus.intr_context = 0;
+
        /* Block unprocessed interrupts. XXX */
        OWRITE4(sc, OHCI_INTERRUPT_DISABLE, intrs);
        sc->sc_eintrs &= ~intrs;
@@ -1304,7 +1307,7 @@
                switch (ed->bmAttributes & UE_XFERTYPE) {
                case UE_CONTROL:
                        pipe->methods = &ohci_device_ctrl_methods;
-                       r = usb_allocmem(sc->sc_dmatag, 
+                       r = usb_allocmem(&sc->sc_bus, 
                                         sizeof(usb_device_request_t), 
                                         0, &opipe->u.ctl.reqdma);
                        if (r != USBD_NORMAL_COMPLETION)
@@ -1408,11 +1411,12 @@
        DPRINTFN(1,("ohci_abort_req: stop ed=%p\n", sed));
        sed->ed.ed_flags |= LE(OHCI_ED_SKIP); /* force hardware skip */
 
-       if (curproc) {
+       if (reqh->device->bus->intr_context) {
+               /* We have no process context, so we can't use tsleep(). */
+               timeout(ohci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
+       } else {
                usb_delay_ms(opipe->pipe.device->bus, 1);
                ohci_abort_req_end(reqh);
-       } else {
-               timeout(ohci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
        }
 }
 
diff -r 914534b4a5a4 -r cc10b1287ed6 sys/dev/usb/ohcivar.h
--- a/sys/dev/usb/ohcivar.h     Mon Sep 13 19:13:09 1999 +0000
+++ b/sys/dev/usb/ohcivar.h     Mon Sep 13 19:18:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ohcivar.h,v 1.8 1999/08/22 23:41:00 augustss Exp $     */
+/*     $NetBSD: ohcivar.h,v 1.9 1999/09/13 19:18:17 augustss Exp $     */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -71,7 +71,6 @@
 #if defined(__NetBSD__) || defined(__OpenBSD__)
        void *sc_ih;                    /* interrupt vectoring */
 
-       bus_dma_tag_t sc_dmatag;        /* DMA tag */
        /* XXX should keep track of all DMA memory */
 #endif /* __NetBSD__ || defined(__OpenBSD__) */
 
@@ -95,8 +94,6 @@
 
        usbd_request_handle sc_intrreqh;
 
-       int sc_intrs;
-
        char sc_vendor[16];
        int sc_id_vendor;
 } ohci_softc_t;
diff -r 914534b4a5a4 -r cc10b1287ed6 sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c        Mon Sep 13 19:13:09 1999 +0000
+++ b/sys/dev/usb/uhci.c        Mon Sep 13 19:18:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhci.c,v 1.49 1999/09/11 08:19:26 augustss Exp $       */
+/*     $NetBSD: uhci.c,v 1.50 1999/09/13 19:18:17 augustss Exp $       */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -345,7 +345,7 @@
        uhci_busreset(sc);
 
        /* Allocate and initialize real frame array. */
-       r = usb_allocmem(sc->sc_dmatag, 
+       r = usb_allocmem(&sc->sc_bus, 
                         UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t),
                         UHCI_FRAMELIST_ALIGN, &sc->sc_dma);
        if (r != USBD_NORMAL_COMPLETION)
@@ -424,7 +424,7 @@
 {
        struct uhci_softc *sc = (struct uhci_softc *)bus;
 
-       return (usb_allocmem(sc->sc_dmatag, size, 0, dma));
+       return (usb_allocmem(&sc->sc_bus, size, 0, dma));
 }
 
 void
@@ -434,7 +434,7 @@
 {
        struct uhci_softc *sc = (struct uhci_softc *)bus;
 
-       usb_freemem(sc->sc_dmatag, dma);
+       usb_freemem(&sc->sc_bus, dma);
 }
 
 #if !defined(__OpenBSD__)
@@ -564,7 +564,7 @@
        uhci_softc_t *sc = uhci;
 
        uhci_dumpregs(sc);
-       printf("intrs=%d\n", sc->sc_intrs);
+       printf("intrs=%d\n", sc->sc_bus.no_intrs);
        printf("framelist[i].link = %08x\n", sc->sc_framelist[0].link);
        uhci_dump_qh(sc->sc_ctl_start->qh.hlink);
 }
@@ -766,8 +766,6 @@
        int ack;
        uhci_intr_info_t *ii;
 
-       sc->sc_intrs++;
-
 #if defined(USB_DEBUG)
        if (uhcidebug > 15) {
                DPRINTF(("%s: uhci_intr\n", USBDEVNAME(sc->sc_bus.bdev)));
@@ -810,6 +808,9 @@
        else    /* nothing to acknowledge */
                return (0);
 
+       sc->sc_bus.intr_context = 1;
+       sc->sc_bus.no_intrs++;
+
        /*
         * Interrupts on UHCI really suck.  When the host controller
         * interrupts because a transfer is completed there is no
@@ -826,6 +827,8 @@
 
        DPRINTFN(10, ("uhci_intr: exit\n"));
 
+       sc->sc_bus.intr_context = 0;
+
        return (1);
 }
 
@@ -1113,7 +1116,7 @@
 
        if (!sc->sc_freetds) {
                DPRINTFN(2,("uhci_alloc_std: allocating chunk\n"));
-               r = usb_allocmem(sc->sc_dmatag, UHCI_STD_SIZE * UHCI_STD_CHUNK,
+               r = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK,
                                 UHCI_TD_ALIGN, &dma);
                if (r != USBD_NORMAL_COMPLETION)
                        return (0);
@@ -1159,7 +1162,7 @@
 
        if (!sc->sc_freeqhs) {
                DPRINTFN(2, ("uhci_alloc_sqh: allocating chunk\n"));
-               r = usb_allocmem(sc->sc_dmatag, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
+               r = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
                                 UHCI_QH_ALIGN, &dma);
                if (r != USBD_NORMAL_COMPLETION)
                        return 0;
@@ -1425,13 +1428,13 @@
        reqh->hcpriv = ii;
 
        /* make sure hardware has completed, */
-       if (curproc) {
+       if (reqh->device->bus->intr_context) {
+               /* We have no process context, so we can't use tsleep(). */
+               timeout(uhci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
+       } else {
                usb_delay_ms(reqh->pipe->device->bus, 1);
                /* and call final part of interrupt handler. */
                uhci_abort_req_end(reqh);
-       } else {
-               /* We have no process context, so we can't use tsleep(). */
-               timeout(uhci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
        }
 }
 
@@ -1922,13 +1925,13 @@
        reqh->hcpriv = ii;
 
        /* make sure hardware has completed, */
-       if (curproc) {
+       if (reqh->device->bus->intr_context) {
+               /* We have no process context, so we can't use tsleep(). */
+               timeout(uhci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
+       } else {
                usb_delay_ms(reqh->pipe->device->bus, 1);
                /* and call final part of interrupt handler. */
                uhci_abort_req_end(reqh);
-       } else {
-               /* We have no process context, so we can't use tsleep(). */
-               timeout(uhci_abort_req_end, reqh, hz / USB_FRAMES_PER_SECOND);
        }
 }
 
@@ -2300,7 +2303,7 @@
                                uhci_free_std(sc, upipe->u.ctl.setup);
                                goto bad;
                        }
-                       r = usb_allocmem(sc->sc_dmatag, 
+                       r = usb_allocmem(&sc->sc_bus, 
                                         sizeof(usb_device_request_t), 
                                         0, &upipe->u.ctl.reqdma);
                        if (r != USBD_NORMAL_COMPLETION) {
diff -r 914534b4a5a4 -r cc10b1287ed6 sys/dev/usb/uhcivar.h
--- a/sys/dev/usb/uhcivar.h     Mon Sep 13 19:13:09 1999 +0000
+++ b/sys/dev/usb/uhcivar.h     Mon Sep 13 19:18:17 1999 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: uhcivar.h,v 1.12 1999/08/22 23:41:00 augustss Exp $    */
+/*     $NetBSD: uhcivar.h,v 1.13 1999/09/13 19:18:17 augustss Exp $    */
 
 /*
  * Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -132,7 +132,6 @@
 #if defined(__NetBSD__) || defined(__OpenBSD__)
        void *sc_ih;                    /* interrupt vectoring */
 



Home | Main Index | Thread Index | Old Index