Module Name: src
Committed By: matt
Date: Wed Jan 4 00:11:13 UTC 2012
Modified Files:
src/sys/dev/usb [matt-nb5-mips64]: files.usb usb_mem.c
Log Message:
Merge USB_FRAG_DMA_WORKAROUND from matt-nb5-pq3 branch.
To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.90.12.1 src/sys/dev/usb/files.usb
cvs rdiff -u -r1.37 -r1.37.14.1 src/sys/dev/usb/usb_mem.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/files.usb
diff -u src/sys/dev/usb/files.usb:1.90 src/sys/dev/usb/files.usb:1.90.12.1
--- src/sys/dev/usb/files.usb:1.90 Fri Oct 10 16:37:16 2008
+++ src/sys/dev/usb/files.usb Wed Jan 4 00:11:13 2012
@@ -1,10 +1,11 @@
-# $NetBSD: files.usb,v 1.90 2008/10/10 16:37:16 joerg Exp $
+# $NetBSD: files.usb,v 1.90.12.1 2012/01/04 00:11:13 matt Exp $
#
# Config file and device description for machine-independent USB code.
# Included by ports that need it. Ports that use it must provide
# their own "major" declarations for the appropriate devices.
defflag USBVERBOSE
+defflag opt_usb.h USB_FRAG_DMA_WORKAROUND
defflag opt_uvideo.h UVIDEO_DEBUG
Index: src/sys/dev/usb/usb_mem.c
diff -u src/sys/dev/usb/usb_mem.c:1.37 src/sys/dev/usb/usb_mem.c:1.37.14.1
--- src/sys/dev/usb/usb_mem.c:1.37 Sat Jun 28 17:42:53 2008
+++ src/sys/dev/usb/usb_mem.c Wed Jan 4 00:11:13 2012
@@ -1,4 +1,4 @@
-/* $NetBSD: usb_mem.c,v 1.37 2008/06/28 17:42:53 bouyer Exp $ */
+/* $NetBSD: usb_mem.c,v 1.37.14.1 2012/01/04 00:11:13 matt Exp $ */
/*
* Copyright (c) 1998 The NetBSD Foundation, Inc.
@@ -38,7 +38,9 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.37 2008/06/28 17:42:53 bouyer Exp $");
+__KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v 1.37.14.1 2012/01/04 00:11:13 matt Exp $");
+
+#include "opt_usb.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -47,6 +49,7 @@ __KERNEL_RCSID(0, "$NetBSD: usb_mem.c,v
#include <sys/queue.h>
#include <sys/device.h> /* for usbdivar.h */
#include <sys/bus.h>
+#include <sys/cpu.h>
#ifdef __NetBSD__
#include <sys/extent.h>
@@ -108,8 +111,8 @@ usb_block_allocmem(bus_dma_tag_t tag, si
DPRINTFN(5, ("usb_block_allocmem: size=%lu align=%lu\n",
(u_long)size, (u_long)align));
-#ifdef DIAGNOSTIC
- if (!curproc) {
+#if defined(DIAGNOSTIC) && 0
+ if (!cpu_intr_p()) {
printf("usb_block_allocmem: in interrupt context, size=%lu\n",
(unsigned long) size);
}
@@ -117,7 +120,7 @@ usb_block_allocmem(bus_dma_tag_t tag, si
s = splusb();
/* First check the free list. */
- for (p = LIST_FIRST(&usb_blk_freelist); p; p = LIST_NEXT(p, next)) {
+ LIST_FOREACH(p, &usb_blk_freelist, next) {
if (p->tag == tag && p->size >= size && p->align >= align) {
LIST_REMOVE(p, next);
usb_blk_nfree--;
@@ -131,7 +134,7 @@ usb_block_allocmem(bus_dma_tag_t tag, si
splx(s);
#ifdef DIAGNOSTIC
- if (!curproc) {
+ if (cpu_intr_p()) {
printf("usb_block_allocmem: in interrupt context, failed\n");
return (USBD_NOMEM);
}
@@ -239,9 +242,10 @@ usb_allocmem(usbd_bus_handle bus, size_t
s = splusb();
/* Check for free fragments. */
- for (f = LIST_FIRST(&usb_frag_freelist); f; f = LIST_NEXT(f, next))
+ LIST_FOREACH(f, &usb_frag_freelist, next) {
if (f->block->tag == tag)
break;
+ }
if (f == NULL) {
DPRINTFN(1, ("usb_allocmem: adding fragments\n"));
err = usb_block_allocmem(tag, USB_MEM_BLOCK, USB_MEM_SMALL,&b);
@@ -255,11 +259,17 @@ usb_allocmem(usbd_bus_handle bus, size_t
f->block = b;
f->offs = i;
LIST_INSERT_HEAD(&usb_frag_freelist, f, next);
+#ifdef USB_FRAG_DMA_WORKAROUND
+ i += 1 * USB_MEM_SMALL;
+#endif
}
f = LIST_FIRST(&usb_frag_freelist);
}
p->block = f->block;
p->offs = f->offs;
+#ifdef USB_FRAG_DMA_WORKAROUND
+ p->offs += USB_MEM_SMALL;
+#endif
p->block->flags &= ~USB_DMA_RESERVE;
LIST_REMOVE(f, next);
splx(s);
@@ -279,8 +289,14 @@ usb_freemem(usbd_bus_handle bus, usb_dma
return;
}
f = KERNADDR(p, 0);
+#ifdef USB_FRAG_DMA_WORKAROUND
+ f = (void *)((uintptr_t)f - USB_MEM_SMALL);
+#endif
f->block = p->block;
f->offs = p->offs;
+#ifdef USB_FRAG_DMA_WORKAROUND
+ f->offs -= USB_MEM_SMALL;
+#endif
s = splusb();
LIST_INSERT_HEAD(&usb_frag_freelist, f, next);
splx(s);