PERFORCE change 126781 for review

Hans Petter Selasky hselasky at FreeBSD.org
Mon Sep 24 11:23:05 PDT 2007


http://perforce.freebsd.org/chv.cgi?CH=126781

Change 126781 by hselasky at hselasky_laptop001 on 2007/09/24 18:22:37

	
	- add missing include "sys/uio.h"
	
	- clean up the CPU cache flush and CPU cache invalidate stuff
	
	  - disabling interrupts to avoid CPU cache pollution is not
	    necessary hence the CPUs can usually do cache operations
	    on a per range basis.
	
	  - remove recursive counter from "struct usbd_page". The only
	    real reason for this is some fixup code in "uhci.c" which
	    I will modify so that it does not recurse the cache operations
	    on the same memory region.

Affected files ...

.. //depot/projects/usb/src/sys/dev/usb/usb_subr.c#43 edit
.. //depot/projects/usb/src/sys/dev/usb/usb_subr.h#45 edit

Differences ...

==== //depot/projects/usb/src/sys/dev/usb/usb_subr.c#43 (text+ko) ====

@@ -60,6 +60,7 @@
 #include <sys/mbuf.h>
 #include <sys/kthread.h>
 #include <sys/unistd.h>
+#include <sys/uio.h>
 
 #include <dev/usb/usb_port.h>
 #include <dev/usb/usb.h>
@@ -2356,13 +2357,10 @@
 	page->physaddr = physaddr;
 	page->buffer = ptr;
 	page->length = size;
-	page->exit_level = 0;
-	page->intr_temp = 0;
 
+	usbd_page_dma_exit(page);
 	bzero(ptr, size);
-
-	bus_dmamap_sync(page->tag, page->map, 
-			BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
+	usbd_page_dma_enter(page);
 
 #ifdef USB_DEBUG
 	if(usbdebug > 14)
@@ -2389,14 +2387,6 @@
 	bus_dmamap_t map = page->map;
 	void *ptr = page->buffer;
 
-	if (page->exit_level == 0) {
-	    bus_dmamap_sync(page->tag, page->map, 
-			    BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
-	} else {
-	    panic("%s:%d: exit_level is not zero!\n",
-		  __FUNCTION__, __LINE__);
-	}
-
 	bus_dmamap_unload(tag, map);
 
 	bus_dmamem_free(tag, ptr, map);
@@ -2411,31 +2401,28 @@
 	return;
 }
 
+/*------------------------------------------------------------------------*
+ *	usbd_page_dma_exit - invalidate CPU cache
+ *
+ * NOTE: Make sure that this function does not appear alone without a
+ * "usbd_page_dma_enter()" call unless you know what you are doing !
+ *------------------------------------------------------------------------*/
 void
 usbd_page_dma_exit(struct usbd_page *page)
 {
-	if ((page->exit_level)++ == 0) {
-		/*
-		 * Disable interrupts so that the
-		 * PCI controller can continue
-		 * using the memory as quick as
-		 * possible:
-		 */
-		page->intr_temp = intr_disable();
-		bus_dmamap_sync(page->tag, page->map, 
-				BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
-	}
+	bus_dmamap_sync(page->tag, page->map, 
+			BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
 	return;
 }
 
+/*------------------------------------------------------------------------*
+ *	usbd_page_dma_enter - flush CPU cache
+ *------------------------------------------------------------------------*/
 void
 usbd_page_dma_enter(struct usbd_page *page)
 {
-	if (--(page->exit_level) == 0) {
-		bus_dmamap_sync(page->tag, page->map, 
-				BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
-		intr_restore(page->intr_temp);
-	}
+	bus_dmamap_sync(page->tag, page->map, 
+			BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
 	return;
 }
 #endif
@@ -2493,13 +2480,12 @@
 	page->physaddr = page->map->dm_segs[0].ds_addr;
 	page->buffer = ptr;
 	page->length = size;
-	page->exit_level = 0;
-	page->intr_temp = 0;
+
+	usbd_page_dma_exit(page);
 
 	bzero(ptr, size);
 
-	bus_dmamap_sync(page->tag, page->map, 0, page->length, 
-			BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
+	usbd_page_dma_enter(page);
 
 #ifdef USB_DEBUG
 	if(usbdebug > 14)
@@ -2533,14 +2519,6 @@
 	 */
 	struct usbd_page temp = *page;
 
-	if (temp.exit_level == 0) {
-	    bus_dmamap_sync(temp.tag, temp.map, 0, temp.length, 
-			    BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
-	} else {
-	    panic("%s:%d: exit_level is not zero!\n",
-		  __FUNCTION__, __LINE__);
-	}
-
 	bus_dmamap_unload(temp.tag, temp.map);
 	bus_dmamap_destroy(temp.tag, temp.map);
 	bus_dmamem_unmap(temp.tag, temp.buffer, temp.length);
@@ -2556,31 +2534,28 @@
 	return;
 }
 
+/*------------------------------------------------------------------------*
+ *	usbd_page_dma_exit - invalidate CPU cache
+ *
+ * NOTE: Make sure that this function does not appear alone without a
+ * "usbd_page_dma_enter()" call unless you know what you are doing !
+ *------------------------------------------------------------------------*/
 void
 usbd_page_dma_exit(struct usbd_page *page)
 {
-	if ((page->exit_level)++ == 0) {
-		/*
-		 * Disable interrupts so that the
-		 * PCI controller can continue
-		 * using the memory as quick as
-		 * possible:
-		 */
-		page->intr_temp = intr_disable();
-		bus_dmamap_sync(page->tag, page->map, 0, page->length,
-				BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
-	}
+	bus_dmamap_sync(page->tag, page->map, 0, page->length,
+			BUS_DMASYNC_POSTWRITE|BUS_DMASYNC_POSTREAD);
 	return;
 }
 
+/*------------------------------------------------------------------------*
+ *	usbd_page_dma_enter - flush CPU cache
+ *------------------------------------------------------------------------*/
 void
 usbd_page_dma_enter(struct usbd_page *page)
 {
-	if (--(page->exit_level) == 0) {
-		bus_dmamap_sync(page->tag, page->map, 0, page->length,
-				BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
-		intr_restore(page->intr_temp);
-	}
+	bus_dmamap_sync(page->tag, page->map, 0, page->length,
+			BUS_DMASYNC_PREWRITE|BUS_DMASYNC_PREREAD);
 	return;
 }
 #endif

==== //depot/projects/usb/src/sys/dev/usb/usb_subr.h#45 (text+ko) ====

@@ -158,18 +158,15 @@
 #ifdef __FreeBSD__
 	bus_dma_tag_t		tag;
 	bus_dmamap_t		map;
-	register_t		intr_temp;
 #endif
 
 #ifdef __NetBSD__
 	bus_dma_tag_t		tag;
 	bus_dmamap_t		map;
 	bus_dma_segment_t	seg;
-	register_t		intr_temp;
 	int32_t			seg_count;
 #endif
 	uint32_t		length;
-	uint16_t		exit_level;
 };
 
 struct usbd_page_search {


More information about the p4-projects mailing list