Module Name: src
Committed By: jmcneill
Date: Sat Jan 2 12:39:33 UTC 2021
Modified Files:
src/sys/dev/usb: xhci.c
Log Message:
Use USBMALLOC_ZERO to ensure that all DMA memory is zero initialized.
To generate a diff of this commit:
cvs rdiff -u -r1.136 -r1.137 src/sys/dev/usb/xhci.c
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: src/sys/dev/usb/xhci.c
diff -u src/sys/dev/usb/xhci.c:1.136 src/sys/dev/usb/xhci.c:1.137
--- src/sys/dev/usb/xhci.c:1.136 Tue Dec 22 01:07:23 2020
+++ src/sys/dev/usb/xhci.c Sat Jan 2 12:39:33 2021
@@ -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 @@ xhci_init(struct xhci_softc *sc)
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 @@ xhci_init(struct xhci_softc *sc)
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_init(struct xhci_softc *sc)
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 @@ xhci_init(struct xhci_softc *sc)
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 @@ xhci_init(struct xhci_softc *sc)
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 @@ xhci_init(struct xhci_softc *sc)
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 @@ xhci_ring_init(struct xhci_softc * const
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 @@ xhci_init_slot(struct usbd_device *dev,
/* 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;