Module Name: src
Committed By: matt
Date: Fri Jan 7 02:49:58 UTC 2011
Modified Files:
src/sys/dev/usb [matt-nb5-pq3]: files.usb usb_mem.c
Log Message:
Add USB_FRAG_DMA_WORKAROUND kludge
To generate a diff of this commit:
cvs rdiff -u -r1.90 -r1.90.16.1 src/sys/dev/usb/files.usb
cvs rdiff -u -r1.37 -r1.37.18.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.16.1
--- src/sys/dev/usb/files.usb:1.90 Fri Oct 10 16:37:16 2008
+++ src/sys/dev/usb/files.usb Fri Jan 7 02:49:58 2011
@@ -1,10 +1,11 @@
-# $NetBSD: files.usb,v 1.90 2008/10/10 16:37:16 joerg Exp $
+# $NetBSD: files.usb,v 1.90.16.1 2011/01/07 02:49:58 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.18.1
--- src/sys/dev/usb/usb_mem.c:1.37 Sat Jun 28 17:42:53 2008
+++ src/sys/dev/usb/usb_mem.c Fri Jan 7 02:49:58 2011
@@ -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.18.1 2011/01/07 02:49:58 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.18.1 2011/01/07 02:49:58 matt Exp $");
+
+#include "opt_usb.h"
#include <sys/param.h>
#include <sys/systm.h>
@@ -47,6 +49,7 @@
#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>
@@ -109,7 +112,7 @@
(u_long)size, (u_long)align));
#ifdef DIAGNOSTIC
- if (!curproc) {
+ if (!cpu_intr_p()) {
printf("usb_block_allocmem: in interrupt context, size=%lu\n",
(unsigned long) size);
}
@@ -117,7 +120,7 @@
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 @@
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 @@
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 @@
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 @@
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);