Source-Changes-HG archive

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

[src/nick-nhusb]: src/sys Step #1 of memory allocation re-organisation.



details:   https://anonhg.NetBSD.org/src/rev/36150053f628
branches:  nick-nhusb
changeset: 334060:36150053f628
user:      skrll <skrll%NetBSD.org@localhost>
date:      Tue Dec 02 09:00:33 2014 +0000

description:
Step #1 of memory allocation re-organisation.

Centralised the buffer allocation routine which now supports DMA
and non-DMA capable host controllers.  Remove the
ubm_{alloc,free}m methods from usbd_bus_methods.

The buffer allocation is only allowed in thread context and,
therefore, negates the usefulness of the reserve dma code which
is removed in this change.

USBD_NO_COPY is also no longer required as usbd_transfer and
usbd_transfer_complete now track buffer usage and handle any
copying.

diffstat:

 sys/arch/mips/adm5120/dev/ahci.c        |   27 +----
 sys/conf/files                          |    6 +-
 sys/dev/ic/sl811hs.c                    |   72 +------------
 sys/dev/usb/aubtfwl.c                   |    6 +-
 sys/dev/usb/auvitek_dtv.c               |    8 +-
 sys/dev/usb/auvitek_video.c             |    6 +-
 sys/dev/usb/ehci.c                      |   53 +---------
 sys/dev/usb/ehcivar.h                   |    3 +-
 sys/dev/usb/emdtv_dtv.c                 |    6 +-
 sys/dev/usb/files.usb                   |    4 +-
 sys/dev/usb/if_athn_usb.c               |   16 +-
 sys/dev/usb/if_atu.c                    |   10 +-
 sys/dev/usb/if_aue.c                    |   10 +-
 sys/dev/usb/if_axe.c                    |   10 +-
 sys/dev/usb/if_axen.c                   |   10 +-
 sys/dev/usb/if_cdce.c                   |   10 +-
 sys/dev/usb/if_cue.c                    |   10 +-
 sys/dev/usb/if_kue.c                    |   10 +-
 sys/dev/usb/if_otus.c                   |   12 +-
 sys/dev/usb/if_rum.c                    |    8 +-
 sys/dev/usb/if_run.c                    |   10 +-
 sys/dev/usb/if_smsc.c                   |    8 +-
 sys/dev/usb/if_udav.c                   |   10 +-
 sys/dev/usb/if_upgt.c                   |    8 +-
 sys/dev/usb/if_upl.c                    |   10 +-
 sys/dev/usb/if_ural.c                   |   10 +-
 sys/dev/usb/if_url.c                    |   10 +-
 sys/dev/usb/if_urndis.c                 |   10 +-
 sys/dev/usb/if_urtw.c                   |    6 +-
 sys/dev/usb/if_urtwn.c                  |   10 +-
 sys/dev/usb/if_zyd.c                    |   12 +-
 sys/dev/usb/irmce.c                     |    8 +-
 sys/dev/usb/motg.c                      |   39 +------
 sys/dev/usb/motgvar.h                   |    4 +-
 sys/dev/usb/ohci.c                      |   40 +------
 sys/dev/usb/ohcivar.h                   |    3 +-
 sys/dev/usb/pseye.c                     |    6 +-
 sys/dev/usb/stuirda.c                   |    6 +-
 sys/dev/usb/uaudio.c                    |    8 +-
 sys/dev/usb/ubt.c                       |   14 +-
 sys/dev/usb/ucom.c                      |    8 +-
 sys/dev/usb/udl.c                       |    8 +-
 sys/dev/usb/udsir.c                     |   10 +-
 sys/dev/usb/ugen.c                      |   18 +-
 sys/dev/usb/uhci.c                      |   65 +-----------
 sys/dev/usb/uhcivar.h                   |    3 +-
 sys/dev/usb/uhso.c                      |   12 +-
 sys/dev/usb/uirda.c                     |   12 +-
 sys/dev/usb/ulpt.c                      |   11 +-
 sys/dev/usb/umass.c                     |   12 +-
 sys/dev/usb/umidi.c                     |    8 +-
 sys/dev/usb/urio.c                      |    8 +-
 sys/dev/usb/usb_mem.c                   |  150 +----------------------------
 sys/dev/usb/usb_mem.h                   |   28 +-----
 sys/dev/usb/usbdi.c                     |  163 ++++++++++++++++++++-----------
 sys/dev/usb/usbdi.h                     |    3 +-
 sys/dev/usb/usbdivar.h                  |   15 +-
 sys/dev/usb/usscanner.c                 |   14 +-
 sys/dev/usb/ustir.c                     |    8 +-
 sys/dev/usb/utoppy.c                    |    8 +-
 sys/dev/usb/uvideo.c                    |    8 +-
 sys/dev/usb/xhci.c                      |   50 +--------
 sys/external/bsd/dwc2/dwc2.c            |   38 +------
 sys/external/bsd/dwc2/dwc2var.h         |    3 +-
 sys/rump/dev/lib/libugenhc/Makefile     |    4 +-
 sys/rump/dev/lib/libugenhc/ugenhc.c     |   23 +---
 sys/rump/dev/lib/libugenhc/ugenhc_dma.c |  110 ---------------------
 67 files changed, 387 insertions(+), 942 deletions(-)

diffs (truncated from 3632 to 300 lines):

diff -r 86d48444a730 -r 36150053f628 sys/arch/mips/adm5120/dev/ahci.c
--- a/sys/arch/mips/adm5120/dev/ahci.c  Mon Dec 01 21:52:00 2014 +0000
+++ b/sys/arch/mips/adm5120/dev/ahci.c  Tue Dec 02 09:00:33 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ahci.c,v 1.12.6.3 2014/12/01 12:38:39 skrll Exp $      */
+/*     $NetBSD: ahci.c,v 1.12.6.4 2014/12/02 09:00:33 skrll Exp $      */
 
 /*-
  * Copyright (c) 2007 Ruslan Ermilov and Vsevolod Lobko.
@@ -64,7 +64,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.12.6.3 2014/12/01 12:38:39 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.12.6.4 2014/12/02 09:00:33 skrll Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -94,8 +94,6 @@
 static void            ahci_poll(struct usbd_bus *);
 static void            ahci_poll_hub(void *);
 static void            ahci_poll_device(void *arg);
-static usbd_status     ahci_allocm(struct usbd_bus *, usb_dma_t *, uint32_t);
-static void            ahci_freem(struct usbd_bus *, usb_dma_t *);
 static usbd_xfer_handle ahci_allocx(struct usbd_bus *);
 static void            ahci_freex(struct usbd_bus *, usbd_xfer_handle);
 
@@ -176,8 +174,6 @@
        .ubm_open = ahci_open,
        .ubm_softint = ahci_softintr,
        .ubm_dopoll = ahci_poll,
-       .ubm_allocm = ahci_allocm,
-       .ubm_freem = ahci_freem,
        .ubm_allocx = ahci_allocx,
        .ubm_freex = ahci_freex,
        .ubm_getlock = ahci_get_lock,
@@ -280,6 +276,7 @@
        sc->sc_bus.methods = &ahci_bus_methods;
        sc->sc_bus.pipe_size = sizeof(struct ahci_pipe);
        sc->sc_bus.dmatag = sc->sc_dmat;
+       sc->sc_bus.usedma = true;
 
        /* Map the device. */
        if (bus_space_map(sc->sc_st, aa->oba_addr,
@@ -468,24 +465,6 @@
        mutex_exit(&sc->sc_lock);
 }
 
-usbd_status
-ahci_allocm(struct usbd_bus *bus, usb_dma_t *dma, uint32_t size)
-{
-       struct ahci_softc *sc = (struct ahci_softc *)bus;
-
-       DPRINTF(D_MEM, ("SLallocm"));
-       return usb_allocmem(&sc->sc_bus, size, 0, dma);
-}
-
-void
-ahci_freem(struct usbd_bus *bus, usb_dma_t *dma)
-{
-       struct ahci_softc *sc = (struct ahci_softc *)bus;
-
-       DPRINTF(D_MEM, ("SLfreem"));
-       usb_freemem(&sc->sc_bus, dma);
-}
-
 usbd_xfer_handle
 ahci_allocx(struct usbd_bus *bus)
 {
diff -r 86d48444a730 -r 36150053f628 sys/conf/files
--- a/sys/conf/files    Mon Dec 01 21:52:00 2014 +0000
+++ b/sys/conf/files    Tue Dec 02 09:00:33 2014 +0000
@@ -1,4 +1,4 @@
-#      $NetBSD: files,v 1.1121 2014/10/31 07:38:36 uebayasi Exp $
+#      $NetBSD: files,v 1.1121.2.1 2014/12/02 09:00:33 skrll Exp $
 #      @(#)files.newconf       7.5 (Berkeley) 5/10/93
 
 version        20141030
@@ -1206,8 +1206,6 @@
 # use them in an 'attach-with'.
 #
 
-defparam USB_MEM_RESERVE
-
 define usbroothub
 file   dev/usb/usbroothub_subr.c       usbroothub
 
@@ -1235,7 +1233,7 @@
 
 # Mentor graphics OTG IP
 defflag        opt_motg.h      MOTG_ALLWINNER
-device motg: usbus, usbroothub, usb_dma
+device motg: usbus, usbroothub
 file   dev/usb/motg.c                  motg                    needs-flag
 
 # SL811HS/T USB controller
diff -r 86d48444a730 -r 36150053f628 sys/dev/ic/sl811hs.c
--- a/sys/dev/ic/sl811hs.c      Mon Dec 01 21:52:00 2014 +0000
+++ b/sys/dev/ic/sl811hs.c      Tue Dec 02 09:00:33 2014 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: sl811hs.c,v 1.47.6.2 2014/12/01 12:38:39 skrll Exp $   */
+/*     $NetBSD: sl811hs.c,v 1.47.6.3 2014/12/02 09:00:33 skrll Exp $   */
 
 /*
  * Not (c) 2007 Matthew Orgass
@@ -68,7 +68,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: sl811hs.c,v 1.47.6.2 2014/12/01 12:38:39 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: sl811hs.c,v 1.47.6.3 2014/12/02 09:00:33 skrll Exp $");
 
 #include "opt_slhci.h"
 
@@ -423,8 +423,6 @@
 typedef usbd_status (*LockCallFunc)(struct slhci_softc *, struct slhci_pipe
     *, struct usbd_xfer *);
 
-usbd_status slhci_allocm(struct usbd_bus *, usb_dma_t *, uint32_t);
-void slhci_freem(struct usbd_bus *, usb_dma_t *);
 struct usbd_xfer * slhci_allocx(struct usbd_bus *);
 void slhci_freex(struct usbd_bus *, struct usbd_xfer *);
 static void slhci_get_lock(struct usbd_bus *, kmutex_t **);
@@ -683,8 +681,6 @@
        .ubm_open = slhci_open,
        .ubm_softint= slhci_void,
        .ubm_dopoll = slhci_poll,
-       .ubm_allocm = slhci_allocm,
-       .ubm_freem = slhci_freem,
        .ubm_allocx = slhci_allocx,
        .ubm_freex = slhci_freex,
        .ubm_getlock = slhci_get_lock,
@@ -760,55 +756,6 @@
 
 /* Start out of lock functions. */
 
-struct slhci_mem {
-       usb_dma_block_t block;
-       uint8_t data[];
-};
-
-/*
- * The SL811HS does not do DMA as a host controller, but NetBSD's USB interface
- * assumes DMA is used.  So we fake the DMA block.
- */
-usbd_status
-slhci_allocm(struct usbd_bus *bus, usb_dma_t *dma, uint32_t size)
-{
-       struct slhci_mem *mem;
-
-       mem = malloc(sizeof(struct slhci_mem) + size, M_USB, M_NOWAIT|M_ZERO);
-
-       DLOG(D_MEM, "allocm %p", mem, 0,0,0);
-
-       if (mem == NULL)
-               return USBD_NOMEM;
-
-       dma->block = &mem->block;
-       dma->block->kaddr = mem->data;
-
-       /* dma->offs = 0; */
-       dma->block->nsegs = 1;
-       dma->block->size = size;
-       dma->block->align = size;
-       dma->block->flags |= USB_DMA_FULLBLOCK;
-
-#ifdef SLHCI_MEM_ACCOUNTING
-       slhci_mem_use(bus, 1);
-#endif
-
-       return USBD_NORMAL_COMPLETION;
-}
-
-void
-slhci_freem(struct usbd_bus *bus, usb_dma_t *dma)
-{
-       DLOG(D_MEM, "freem %p", dma->block, 0,0,0);
-
-#ifdef SLHCI_MEM_ACCOUNTING
-       slhci_mem_use(bus, -1);
-#endif
-
-       free(dma->block, M_USB);
-}
-
 struct usbd_xfer *
 slhci_allocx(struct usbd_bus *bus)
 {
@@ -935,7 +882,7 @@
                        spipe->control |= SL11_EPCTRL_DATATOGGLE;
                spipe->tregs[LEN] = spipe->newlen[1];
                if (spipe->tregs[LEN])
-                       spipe->buffer = KERNADDR(&xfer->dmabuf, 0);
+                       spipe->buffer = xfer->buf;
                else
                        spipe->buffer = NULL;
                spipe->lastframe = t->frame;
@@ -1262,6 +1209,7 @@
        sc->sc_bus.usbrev = USBREV_1_1;
        sc->sc_bus.methods = __UNCONST(&slhci_bus_methods);
        sc->sc_bus.pipe_size = sizeof(struct slhci_pipe);
+       sc->sc_bus.usedma = false;
 
        if (!sc->sc_enable_power)
                t->flags |= F_REALPOWER;
@@ -2126,7 +2074,7 @@
                            return);
                        spipe->tregs[LEN] = spipe->newlen[1];
                        spipe->bustime = spipe->newbustime[1];
-                       spipe->buffer = KERNADDR(&xfer->dmabuf, 0);
+                       spipe->buffer = xfer->buf;
                        spipe->ptype = PT_CTRL_DATA;
                } else {
 status_setup:
@@ -2391,7 +2339,7 @@
                        if (t->rootintr != NULL) {
                                u_char *p;
 
-                               p = KERNADDR(&t->rootintr->dmabuf, 0);
+                               p = t->rootintr->buf;
                                p[0] = 2;
                                t->rootintr->actlen = 1;
                                t->rootintr->status = USBD_NORMAL_COMPLETION;
@@ -2502,7 +2450,7 @@
        xfer->actlen = 0;
        spipe->xfer = xfer;
        if (spipe->tregs[LEN])
-               KASSERT(spipe->buffer == KERNADDR(&xfer->dmabuf, 0));
+               KASSERT(spipe->buffer == xfer->buf);
        slhci_queue_timed(sc, spipe);
        slhci_dotransfer(sc);
 }
@@ -3230,7 +3178,7 @@
        type = req->bmRequestType;
 
        if (len)
-               buf = KERNADDR(&xfer->dmabuf, 0);
+               buf = xfer->buf;
 
        SLHCI_DEXEC(D_TRACE, slhci_log_req_hub(req));
 
@@ -3434,7 +3382,7 @@
        if(xfer->length > 0 &&
            UE_GET_DIR(xfer->pipe->endpoint->edesc->bEndpointAddress) ==
            UE_DIR_IN) {
-               buf = KERNADDR(&xfer->dmabuf, 0);
+               buf = xfer->buf;
                DDOLOGBUF(buf, xfer->actlen);
                DDOLOG("len %d actlen %d short %d", xfer->length,
                    xfer->actlen, xfer->length - xfer->actlen, 0);
@@ -3588,7 +3536,7 @@
        DDOLOG("xfer: length=%u, actlen=%u, flags=%#x, timeout=%u,",
                xfer->length, xfer->actlen, xfer->flags, xfer->timeout);
        if (xfer->dmabuf.block)
-               DDOLOG("buffer=%p", KERNADDR(&xfer->dmabuf, 0), 0,0,0);
+               DDOLOG("buffer=%p", xfer->buf, 0,0,0);
        slhci_log_req_hub(&xfer->request);
 }
 
diff -r 86d48444a730 -r 36150053f628 sys/dev/usb/aubtfwl.c
--- a/sys/dev/usb/aubtfwl.c     Mon Dec 01 21:52:00 2014 +0000
+++ b/sys/dev/usb/aubtfwl.c     Tue Dec 02 09:00:33 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: aubtfwl.c,v 1.5.10.1 2014/12/01 13:03:05 skrll Exp $ */
+/* $NetBSD: aubtfwl.c,v 1.5.10.2 2014/12/02 09:00:33 skrll Exp $ */
 
 /*
  * Copyright (c) 2011 Jonathan A. Kollasch
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: aubtfwl.c,v 1.5.10.1 2014/12/01 13:03:05 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: aubtfwl.c,v 1.5.10.2 2014/12/02 09:00:33 skrll Exp $");
 
 #include <sys/param.h>
 #include <dev/usb/usb.h>
@@ -191,7 +191,7 @@
                        break;
                }
                error = usbd_bulk_transfer(xfer, pipe,
-                   USBD_NO_COPY, USBD_DEFAULT_TIMEOUT,
+                   0, USBD_DEFAULT_TIMEOUT,
                    buf, &n);
                if (error != USBD_NORMAL_COMPLETION) {
                        aprint_error_dev(self, "xfer failed, %s\n",
diff -r 86d48444a730 -r 36150053f628 sys/dev/usb/auvitek_dtv.c
--- a/sys/dev/usb/auvitek_dtv.c Mon Dec 01 21:52:00 2014 +0000
+++ b/sys/dev/usb/auvitek_dtv.c Tue Dec 02 09:00:33 2014 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: auvitek_dtv.c,v 1.6 2013/01/22 12:40:42 jmcneill Exp $ */
+/* $NetBSD: auvitek_dtv.c,v 1.6.14.1 2014/12/02 09:00:33 skrll Exp $ */
 
 /*-
  * Copyright (c) 2011 Jared D. McNeill <jmcneill%invisible.ca@localhost>
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: auvitek_dtv.c,v 1.6 2013/01/22 12:40:42 jmcneill Exp $");



Home | Main Index | Thread Index | Old Index