Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Switch USB to use non-coherent buffers for data transfer...
details: https://anonhg.NetBSD.org/src/rev/ca99e2bd9ad3
branches: trunk
changeset: 970886:ca99e2bd9ad3
user: skrll <skrll%NetBSD.org@localhost>
date: Sun Apr 05 20:59:38 2020 +0000
description:
Switch USB to use non-coherent buffers for data transfers in the
same way as OpenBSD.
The use of coherent (uncacheable on ARM and other arches) mappings
for transfer buffers impacts performance, espcially where memcpys
are involved.
Audit the necessary usb_syncmem operations - a few were missing.
diffstat:
sys/arch/mips/adm5120/dev/ahci.c | 14 ++++++-
sys/dev/usb/ehci.c | 18 +++++----
sys/dev/usb/ohci.c | 30 ++++++++++++----
sys/dev/usb/uhci.c | 18 +++++----
sys/dev/usb/usb_mem.c | 55 ++++++++++++++++--------------
sys/dev/usb/usb_mem.h | 13 +++---
sys/dev/usb/usbdi.c | 7 ++-
sys/dev/usb/xhci.c | 45 ++++++++++++++++---------
sys/external/bsd/dwc2/dist/dwc2_hcd.c | 10 ++--
sys/external/bsd/dwc2/dist/dwc2_hcdddma.c | 8 ++--
sys/external/bsd/dwc2/dwc2.c | 6 +-
11 files changed, 134 insertions(+), 90 deletions(-)
diffs (truncated from 776 to 300 lines):
diff -r 87d2dbdd055b -r ca99e2bd9ad3 sys/arch/mips/adm5120/dev/ahci.c
--- a/sys/arch/mips/adm5120/dev/ahci.c Sun Apr 05 20:53:46 2020 +0000
+++ b/sys/arch/mips/adm5120/dev/ahci.c Sun Apr 05 20:59:38 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ahci.c,v 1.21 2020/02/21 12:41:29 skrll Exp $ */
+/* $NetBSD: ahci.c,v 1.22 2020/04/05 20:59:38 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.21 2020/02/21 12:41:29 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ahci.c,v 1.22 2020/04/05 20:59:38 skrll Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -879,7 +879,7 @@
td3 = (struct admhcd_td *)KSEG1ADDR(&td_v[3]);
err = usb_allocmem(&sc->sc_bus,
sizeof(usb_device_request_t),
- 0, &reqdma);
+ 0, USBMALLOC_COHERENT, &reqdma);
if (err)
return USBD_NOMEM;
@@ -1259,6 +1259,10 @@
segs = i;
len = 0;
+ if (xfer->ux_length)
+ usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
+ isread ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
+
/* printf("segs: %d\n",segs);
printf("ep: %p\n",ep);
printf("ep->control: %x\n",ep->control);
@@ -1317,6 +1321,10 @@
level--;
/* printf("bulk_start<<<\n"); */
+ if (xfer->ux_length)
+ usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
+ isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
+
usb_transfer_complete(xfer);
mutex_exit(&sc->sc_lock);
diff -r 87d2dbdd055b -r ca99e2bd9ad3 sys/dev/usb/ehci.c
--- a/sys/dev/usb/ehci.c Sun Apr 05 20:53:46 2020 +0000
+++ b/sys/dev/usb/ehci.c Sun Apr 05 20:59:38 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ehci.c,v 1.277 2020/03/14 02:35:33 christos Exp $ */
+/* $NetBSD: ehci.c,v 1.278 2020/04/05 20:59:38 skrll Exp $ */
/*
* Copyright (c) 2004-2012 The NetBSD Foundation, Inc.
@@ -53,7 +53,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.277 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ehci.c,v 1.278 2020/04/05 20:59:38 skrll Exp $");
#include "ohci.h"
#include "uhci.h"
@@ -517,7 +517,7 @@
case 3: return EIO;
}
err = usb_allocmem(&sc->sc_bus, sc->sc_flsize * sizeof(ehci_link_t),
- EHCI_FLALIGN_ALIGN, &sc->sc_fldma);
+ EHCI_FLALIGN_ALIGN, USBMALLOC_COHERENT, &sc->sc_fldma);
if (err)
return err;
DPRINTF("flsize=%jd", sc->sc_flsize, 0, 0, 0);
@@ -2003,7 +2003,7 @@
switch (xfertype) {
case UE_CONTROL:
err = usb_allocmem(&sc->sc_bus, sizeof(usb_device_request_t),
- 0, &epipe->ctrl.reqdma);
+ 0, USBMALLOC_COHERENT, &epipe->ctrl.reqdma);
#ifdef EHCI_DEBUG
if (err)
printf("ehci_open: usb_allocmem()=%d\n", err);
@@ -2803,7 +2803,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, EHCI_SQH_SIZE * EHCI_SQH_CHUNK,
- EHCI_PAGE_SIZE, &dma);
+ EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma);
#ifdef EHCI_DEBUG
if (err)
printf("ehci_alloc_sqh: usb_allocmem()=%d\n", err);
@@ -2856,7 +2856,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, EHCI_SQTD_SIZE*EHCI_SQTD_CHUNK,
- EHCI_PAGE_SIZE, &dma);
+ EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma);
#ifdef EHCI_DEBUG
if (err)
printf("ehci_alloc_sqtd: usb_allocmem()=%d\n", err);
@@ -3113,8 +3113,9 @@
if (freeitd == NULL) {
DPRINTF("allocating chunk", 0, 0, 0, 0);
mutex_exit(&sc->sc_lock);
+
err = usb_allocmem(&sc->sc_bus, EHCI_ITD_SIZE * EHCI_ITD_CHUNK,
- EHCI_PAGE_SIZE, &dma);
+ EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma);
if (err) {
DPRINTF("alloc returned %jd", err, 0, 0, 0);
@@ -3161,8 +3162,9 @@
if (freesitd == NULL) {
DPRINTF("allocating chunk", 0, 0, 0, 0);
mutex_exit(&sc->sc_lock);
+
err = usb_allocmem(&sc->sc_bus, EHCI_SITD_SIZE * EHCI_SITD_CHUNK,
- EHCI_PAGE_SIZE, &dma);
+ EHCI_PAGE_SIZE, USBMALLOC_COHERENT, &dma);
if (err) {
DPRINTF("alloc returned %jd", err, 0, 0,
diff -r 87d2dbdd055b -r ca99e2bd9ad3 sys/dev/usb/ohci.c
--- a/sys/dev/usb/ohci.c Sun Apr 05 20:53:46 2020 +0000
+++ b/sys/dev/usb/ohci.c Sun Apr 05 20:59:38 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ohci.c,v 1.300 2020/03/14 02:35:33 christos Exp $ */
+/* $NetBSD: ohci.c,v 1.301 2020/04/05 20:59:38 skrll Exp $ */
/*
* Copyright (c) 1998, 2004, 2005, 2012 The NetBSD Foundation, Inc.
@@ -41,7 +41,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.300 2020/03/14 02:35:33 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ohci.c,v 1.301 2020/04/05 20:59:38 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -409,7 +409,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, OHCI_SED_SIZE * OHCI_SED_CHUNK,
- OHCI_ED_ALIGN, &dma);
+ OHCI_ED_ALIGN, USBMALLOC_COHERENT, &dma);
if (err)
return 0;
@@ -468,7 +468,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, OHCI_STD_SIZE * OHCI_STD_CHUNK,
- OHCI_TD_ALIGN, &dma);
+ OHCI_TD_ALIGN, USBMALLOC_COHERENT, &dma);
if (err)
return NULL;
@@ -712,7 +712,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, OHCI_SITD_SIZE * OHCI_SITD_CHUNK,
- OHCI_ITD_ALIGN, &dma);
+ OHCI_ITD_ALIGN, USBMALLOC_COHERENT, &dma);
if (err)
return NULL;
mutex_enter(&sc->sc_lock);
@@ -815,7 +815,7 @@
/* XXX determine alignment by R/W */
/* Allocate the HCCA area. */
err = usb_allocmem(&sc->sc_bus, OHCI_HCCA_SIZE,
- OHCI_HCCA_ALIGN, &sc->sc_hccadma);
+ OHCI_HCCA_ALIGN, USBMALLOC_COHERENT, &sc->sc_hccadma);
if (err) {
sc->sc_hcca = NULL;
return err;
@@ -2081,8 +2081,8 @@
case UE_CONTROL:
pipe->up_methods = &ohci_device_ctrl_methods;
err = usb_allocmem(&sc->sc_bus,
- sizeof(usb_device_request_t),
- 0, &opipe->ctrl.reqdma);
+ sizeof(usb_device_request_t), 0,
+ USBMALLOC_COHERENT, &opipe->ctrl.reqdma);
if (err)
goto bad;
mutex_enter(&sc->sc_lock);
@@ -3460,6 +3460,12 @@
DPRINTFN(1, "used=%jd next=%jd xfer=%#jx nframes=%jd",
isoc->inuse, isoc->next, (uintptr_t)xfer, xfer->ux_nframes);
+ int isread =
+ (UE_GET_DIR(xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress) == UE_DIR_IN);
+
+ usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
+ isread ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
+
if (isoc->next == -1) {
/* Not in use yet, schedule it a few frames ahead. */
isoc->next = O32TOH(sc->sc_hcca->hcca_frame_number) + 5;
@@ -3630,6 +3636,14 @@
{
OHCIHIST_FUNC(); OHCIHIST_CALLED();
DPRINTFN(1, "xfer=%#jx", (uintptr_t)xfer, 0, 0, 0);
+
+ int isread =
+ (UE_GET_DIR(xfer->ux_pipe->up_endpoint->ue_edesc->bEndpointAddress) == UE_DIR_IN);
+
+ DPRINTFN(10, "xfer=%#jx, actlen=%jd", (uintptr_t)xfer, xfer->ux_actlen,
+ 0, 0);
+ usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
+ isread ? BUS_DMASYNC_POSTREAD : BUS_DMASYNC_POSTWRITE);
}
usbd_status
diff -r 87d2dbdd055b -r ca99e2bd9ad3 sys/dev/usb/uhci.c
--- a/sys/dev/usb/uhci.c Sun Apr 05 20:53:46 2020 +0000
+++ b/sys/dev/usb/uhci.c Sun Apr 05 20:59:38 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: uhci.c,v 1.299 2020/03/15 15:00:14 skrll Exp $ */
+/* $NetBSD: uhci.c,v 1.300 2020/04/05 20:59:38 skrll Exp $ */
/*
* Copyright (c) 1998, 2004, 2011, 2012 The NetBSD Foundation, Inc.
@@ -42,7 +42,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.299 2020/03/15 15:00:14 skrll Exp $");
+__KERNEL_RCSID(0, "$NetBSD: uhci.c,v 1.300 2020/04/05 20:59:38 skrll Exp $");
#ifdef _KERNEL_OPT
#include "opt_usb.h"
@@ -456,7 +456,7 @@
/* Allocate and initialize real frame array. */
err = usb_allocmem(&sc->sc_bus,
UHCI_FRAMELIST_COUNT * sizeof(uhci_physaddr_t),
- UHCI_FRAMELIST_ALIGN, &sc->sc_dma);
+ UHCI_FRAMELIST_ALIGN, USBMALLOC_COHERENT, &sc->sc_dma);
if (err)
return err;
sc->sc_pframes = KERNADDR(&sc->sc_dma, 0);
@@ -1847,7 +1847,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, UHCI_STD_SIZE * UHCI_STD_CHUNK,
- UHCI_TD_ALIGN, &dma);
+ UHCI_TD_ALIGN, USBMALLOC_COHERENT, &dma);
if (err)
return NULL;
@@ -1914,7 +1914,7 @@
mutex_exit(&sc->sc_lock);
err = usb_allocmem(&sc->sc_bus, UHCI_SQH_SIZE * UHCI_SQH_CHUNK,
- UHCI_QH_ALIGN, &dma);
+ UHCI_QH_ALIGN, USBMALLOC_COHERENT, &dma);
if (err)
return NULL;
@@ -2201,7 +2201,6 @@
int len = xfer->ux_bufsize;
int err = 0;
-
UHCIHIST_FUNC(); UHCIHIST_CALLED();
DPRINTFN(3, "xfer=%#jx len=%jd flags=%jd", (uintptr_t)xfer, len,
xfer->ux_flags, 0);
@@ -2919,6 +2918,9 @@
KASSERT(xfer->ux_nframes != 0);
+ usb_syncmem(&xfer->ux_dmabuf, 0, xfer->ux_length,
+ rd ? BUS_DMASYNC_PREREAD : BUS_DMASYNC_PREWRITE);
+
mutex_enter(&sc->sc_lock);
next = isoc->next;
if (next == -1) {
@@ -3482,8 +3484,8 @@
goto bad;
}
err = usb_allocmem(&sc->sc_bus,
- sizeof(usb_device_request_t),
- 0, &upipe->ctrl.reqdma);
+ sizeof(usb_device_request_t), 0,
+ USBMALLOC_COHERENT, &upipe->ctrl.reqdma);
if (err) {
uhci_free_sqh(sc, upipe->ctrl.sqh);
uhci_free_std(sc, upipe->ctrl.setup);
diff -r 87d2dbdd055b -r ca99e2bd9ad3 sys/dev/usb/usb_mem.c
--- a/sys/dev/usb/usb_mem.c Sun Apr 05 20:53:46 2020 +0000
+++ b/sys/dev/usb/usb_mem.c Sun Apr 05 20:59:38 2020 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_mem.c,v 1.75 2020/03/15 14:19:04 skrll Exp $ */
+/* $NetBSD: usb_mem.c,v 1.76 2020/04/05 20:59:38 skrll Exp $ */
/*
Home |
Main Index |
Thread Index |
Old Index