Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/usb Use USBMALLOC_ZERO to ensure that all DMA memory...



details:   https://anonhg.NetBSD.org/src/rev/9e64cf4881a1
branches:  trunk
changeset: 949134:9e64cf4881a1
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Jan 02 12:39:33 2021 +0000

description:
Use USBMALLOC_ZERO to ensure that all DMA memory is zero initialized.

diffstat:

 sys/dev/usb/xhci.c |  31 +++++++++++++++----------------
 1 files changed, 15 insertions(+), 16 deletions(-)

diffs (120 lines):

diff -r 87101f03ba20 -r 9e64cf4881a1 sys/dev/usb/xhci.c
--- a/sys/dev/usb/xhci.c        Sat Jan 02 12:39:03 2021 +0000
+++ b/sys/dev/usb/xhci.c        Sat Jan 02 12:39:33 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: xhci.c,v 1.136 2020/12/22 01:07:23 riastradh Exp $     */
+/*     $NetBSD: xhci.c,v 1.137 2021/01/02 12:39:33 jmcneill Exp $      */
 
 /*
  * Copyright (c) 2013 Jonathan A. Kollasch
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.136 2020/12/22 01:07:23 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: xhci.c,v 1.137 2021/01/02 12:39:33 jmcneill Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_usb.h"
@@ -1087,7 +1087,8 @@
        if (sc->sc_maxspbuf != 0) {
                err = usb_allocmem(&sc->sc_bus,
                    sizeof(uint64_t) * sc->sc_maxspbuf, sizeof(uint64_t),
-                   USBMALLOC_COHERENT, &sc->sc_spbufarray_dma);
+                   USBMALLOC_COHERENT | USBMALLOC_ZERO,
+                   &sc->sc_spbufarray_dma);
                if (err) {
                        aprint_error_dev(sc->sc_dev,
                            "spbufarray init fail, err %d\n", err);
@@ -1101,7 +1102,8 @@
                        usb_dma_t * const dma = &sc->sc_spbuf_dma[i];
                        /* allocate contexts */
                        err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz,
-                           sc->sc_pgsz, USBMALLOC_COHERENT, dma);
+                           sc->sc_pgsz, USBMALLOC_COHERENT | USBMALLOC_ZERO,
+                           dma);
                        if (err) {
                                aprint_error_dev(sc->sc_dev,
                                    "spbufarray_dma init fail, err %d\n", err);
@@ -1149,7 +1151,8 @@
            XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN);
        KASSERTMSG(size <= (512 * 1024), "eventst size %zu too large", size);
        align = XHCI_EVENT_RING_SEGMENT_TABLE_ALIGN;
-       err = usb_allocmem(&sc->sc_bus, size, align, USBMALLOC_COHERENT, dma);
+       err = usb_allocmem(&sc->sc_bus, size, align,
+           USBMALLOC_COHERENT | USBMALLOC_ZERO, dma);
        if (err) {
                aprint_error_dev(sc->sc_dev, "eventst init fail, err %d\n",
                    err);
@@ -1157,8 +1160,6 @@
                goto bad3;
        }
 
-       memset(KERNADDR(dma, 0), 0, size);
-       usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE);
        aprint_debug_dev(sc->sc_dev, "eventst: 0x%016jx %p %zx\n",
            (uintmax_t)DMAADDR(&sc->sc_eventst_dma, 0),
            KERNADDR(&sc->sc_eventst_dma, 0),
@@ -1168,7 +1169,8 @@
        size = (1 + sc->sc_maxslots) * sizeof(uint64_t);
        KASSERTMSG(size <= 2048, "dcbaa size %zu too large", size);
        align = XHCI_DEVICE_CONTEXT_BASE_ADDRESS_ARRAY_ALIGN;
-       err = usb_allocmem(&sc->sc_bus, size, align, USBMALLOC_COHERENT, dma);
+       err = usb_allocmem(&sc->sc_bus, size, align,
+           USBMALLOC_COHERENT | USBMALLOC_ZERO, dma);
        if (err) {
                aprint_error_dev(sc->sc_dev, "dcbaa init fail, err %d\n", err);
                rv = ENOMEM;
@@ -1179,15 +1181,14 @@
            KERNADDR(&sc->sc_dcbaa_dma, 0),
            sc->sc_dcbaa_dma.udma_block->size);
 
-       memset(KERNADDR(dma, 0), 0, size);
        if (sc->sc_maxspbuf != 0) {
                /*
                 * DCBA entry 0 hold the scratchbuf array pointer.
                 */
                *(uint64_t *)KERNADDR(dma, 0) =
                    htole64(DMAADDR(&sc->sc_spbufarray_dma, 0));
+               usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE);
        }
-       usb_syncmem(dma, 0, size, BUS_DMASYNC_PREWRITE);
 
        sc->sc_slots = kmem_zalloc(sizeof(*sc->sc_slots) * sc->sc_maxslots,
            KM_SLEEP);
@@ -2580,8 +2581,8 @@
        xr = kmem_zalloc(sizeof(struct xhci_ring), KM_SLEEP);
        DPRINTFN(1, "ring %#jx", (uintptr_t)xr, 0, 0, 0);
 
-       err = usb_allocmem(&sc->sc_bus, size, align, USBMALLOC_COHERENT,
-           &xr->xr_dma);
+       err = usb_allocmem(&sc->sc_bus, size, align,
+           USBMALLOC_COHERENT | USBMALLOC_ZERO, &xr->xr_dma);
        if (err) {
                kmem_free(xr, sizeof(struct xhci_ring));
                DPRINTFN(1, "alloc xr_dma failed %jd", err, 0, 0, 0);
@@ -3020,22 +3021,20 @@
 
        /* allocate contexts */
        err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, sc->sc_pgsz,
-           USBMALLOC_COHERENT, &xs->xs_dc_dma);
+           USBMALLOC_COHERENT | USBMALLOC_ZERO, &xs->xs_dc_dma);
        if (err) {
                DPRINTFN(1, "failed to allocmem output device context %jd",
                    err, 0, 0, 0);
                return err;
        }
-       memset(KERNADDR(&xs->xs_dc_dma, 0), 0, sc->sc_pgsz);
 
        err = usb_allocmem(&sc->sc_bus, sc->sc_pgsz, sc->sc_pgsz,
-           USBMALLOC_COHERENT, &xs->xs_ic_dma);
+           USBMALLOC_COHERENT | USBMALLOC_ZERO, &xs->xs_ic_dma);
        if (err) {
                DPRINTFN(1, "failed to allocmem input device context %jd",
                    err, 0, 0, 0);
                goto bad1;
        }
-       memset(KERNADDR(&xs->xs_ic_dma, 0), 0, sc->sc_pgsz);
 
        memset(&xs->xs_xr[0], 0, sizeof(xs->xs_xr));
        xs->xs_idx = slot;



Home | Main Index | Thread Index | Old Index