svn commit: r213043 - in user/weongyo/usb/sys/dev/usb: . controller

Weongyo Jeong weongyo at FreeBSD.org
Thu Sep 23 01:19:31 UTC 2010


Author: weongyo
Date: Thu Sep 23 01:19:31 2010
New Revision: 213043
URL: http://svn.freebsd.org/changeset/base/213043

Log:
  Reverts partial commits from r212937 - r213022; looks wrong approach to
  verify the boundaries of DMA segments.

Modified:
  user/weongyo/usb/sys/dev/usb/controller/ehci.c
  user/weongyo/usb/sys/dev/usb/controller/ohci.c
  user/weongyo/usb/sys/dev/usb/controller/uhci.c
  user/weongyo/usb/sys/dev/usb/controller/usb_controller.c
  user/weongyo/usb/sys/dev/usb/usb_busdma.c
  user/weongyo/usb/sys/dev/usb/usb_busdma.h
  user/weongyo/usb/sys/dev/usb/usb_controller.h
  user/weongyo/usb/sys/dev/usb/usb_transfer.c

Modified: user/weongyo/usb/sys/dev/usb/controller/ehci.c
==============================================================================
--- user/weongyo/usb/sys/dev/usb/controller/ehci.c	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/controller/ehci.c	Thu Sep 23 01:19:31 2010	(r213043)
@@ -153,27 +153,27 @@ ehci_iterate_hw_softc(struct usb_bus *bu
 	ehci_softc_t *sc = EHCI_BUS2SC(bus);
 	uint32_t i;
 
-	(*func)(bus, &sc->sc_hw.pframes_pc, &sc->sc_hw.pframes_pg, 1,
+	(*func)(bus, &sc->sc_hw.pframes_pc, &sc->sc_hw.pframes_pg,
 	    sizeof(uint32_t) * EHCI_FRAMELIST_COUNT, EHCI_FRAMELIST_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.async_start_pc, &sc->sc_hw.async_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.async_start_pc, &sc->sc_hw.async_start_pg,
 	    sizeof(ehci_qh_t), EHCI_QH_ALIGN);
 
 	for (i = 0; i != EHCI_VIRTUAL_FRAMELIST_COUNT; i++) {
 		(*func)(bus, sc->sc_hw.intr_start_pc + i,
-		    sc->sc_hw.intr_start_pg + i, 1,
+		    sc->sc_hw.intr_start_pg + i,
 		    sizeof(ehci_qh_t), EHCI_QH_ALIGN);
 	}
 
 	for (i = 0; i != EHCI_VIRTUAL_FRAMELIST_COUNT; i++) {
 		(*func)(bus, sc->sc_hw.isoc_hs_start_pc + i,
-		    sc->sc_hw.isoc_hs_start_pg + i, 1,
+		    sc->sc_hw.isoc_hs_start_pg + i,
 		    sizeof(ehci_itd_t), EHCI_ITD_ALIGN);
 	}
 
 	for (i = 0; i != EHCI_VIRTUAL_FRAMELIST_COUNT; i++) {
 		(*func)(bus, sc->sc_hw.isoc_fs_start_pc + i,
-		    sc->sc_hw.isoc_fs_start_pg + i, 1,
+		    sc->sc_hw.isoc_fs_start_pg + i,
 		    sizeof(ehci_sitd_t), EHCI_SITD_ALIGN);
 	}
 }

Modified: user/weongyo/usb/sys/dev/usb/controller/ohci.c
==============================================================================
--- user/weongyo/usb/sys/dev/usb/controller/ohci.c	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/controller/ohci.c	Thu Sep 23 01:19:31 2010	(r213043)
@@ -147,21 +147,21 @@ ohci_iterate_hw_softc(struct usb_bus *bu
 	struct ohci_softc *sc = OHCI_BUS2SC(bus);
 	uint32_t i;
 
-	(*func)(bus, &sc->sc_hw.hcca_pc, &sc->sc_hw.hcca_pg, 1,
+	(*func)(bus, &sc->sc_hw.hcca_pc, &sc->sc_hw.hcca_pg,
 	    sizeof(ohci_hcca_t), OHCI_HCCA_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.ctrl_start_pc, &sc->sc_hw.ctrl_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.ctrl_start_pc, &sc->sc_hw.ctrl_start_pg,
 	    sizeof(ohci_ed_t), OHCI_ED_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg,
 	    sizeof(ohci_ed_t), OHCI_ED_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.isoc_start_pc, &sc->sc_hw.isoc_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.isoc_start_pc, &sc->sc_hw.isoc_start_pg,
 	    sizeof(ohci_ed_t), OHCI_ED_ALIGN);
 
 	for (i = 0; i != OHCI_NO_EDS; i++) {
 		(*func)(bus, sc->sc_hw.intr_start_pc + i,
-		    sc->sc_hw.intr_start_pg + i, 1,
+		    sc->sc_hw.intr_start_pg + i,
 		    sizeof(ohci_ed_t), OHCI_ED_ALIGN);
 	}
 }

Modified: user/weongyo/usb/sys/dev/usb/controller/uhci.c
==============================================================================
--- user/weongyo/usb/sys/dev/usb/controller/uhci.c	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/controller/uhci.c	Thu Sep 23 01:19:31 2010	(r213043)
@@ -169,33 +169,33 @@ uhci_iterate_hw_softc(struct usb_bus *bu
 	struct uhci_softc *sc = UHCI_BUS2SC(bus);
 	uint32_t i;
 
-	(*func)(bus, &sc->sc_hw.pframes_pc, &sc->sc_hw.pframes_pg, 1,
+	(*func)(bus, &sc->sc_hw.pframes_pc, &sc->sc_hw.pframes_pg,
 	    sizeof(uint32_t) * UHCI_FRAMELIST_COUNT, UHCI_FRAMELIST_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.ls_ctl_start_pc, &sc->sc_hw.ls_ctl_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.ls_ctl_start_pc, &sc->sc_hw.ls_ctl_start_pg,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.fs_ctl_start_pc, &sc->sc_hw.fs_ctl_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.fs_ctl_start_pc, &sc->sc_hw.fs_ctl_start_pg,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg, 1,
+	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.last_qh_pc, &sc->sc_hw.last_qh_pg, 1,
+	(*func)(bus, &sc->sc_hw.last_qh_pc, &sc->sc_hw.last_qh_pg,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.last_td_pc, &sc->sc_hw.last_td_pg, 1,
+	(*func)(bus, &sc->sc_hw.last_td_pc, &sc->sc_hw.last_td_pg,
 	    sizeof(uhci_td_t), UHCI_TD_ALIGN);
 
 	for (i = 0; i != UHCI_VFRAMELIST_COUNT; i++) {
 		(*func)(bus, sc->sc_hw.isoc_start_pc + i,
-		    sc->sc_hw.isoc_start_pg + i, 1,
+		    sc->sc_hw.isoc_start_pg + i,
 		    sizeof(uhci_td_t), UHCI_TD_ALIGN);
 	}
 
 	for (i = 0; i != UHCI_IFRAMELIST_COUNT; i++) {
 		(*func)(bus, sc->sc_hw.intr_start_pc + i,
-		    sc->sc_hw.intr_start_pg + i, 1,
+		    sc->sc_hw.intr_start_pg + i,
 		    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 	}
 }

Modified: user/weongyo/usb/sys/dev/usb/controller/usb_controller.c
==============================================================================
--- user/weongyo/usb/sys/dev/usb/controller/usb_controller.c	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/controller/usb_controller.c	Thu Sep 23 01:19:31 2010	(r213043)
@@ -431,7 +431,7 @@ SYSUNINIT(usb_bus_unload, SI_SUB_KLD, SI
 #if USB_HAVE_BUSDMA
 static void
 usb_bus_mem_flush_all_cb(struct usb_bus *bus, struct usb_page_cache *pc,
-    struct usb_page *pg, int npg, usb_size_t size, usb_size_t align)
+    struct usb_page *pg, usb_size_t size, usb_size_t align)
 {
 
 	usb_pc_cpu_flush(pc);
@@ -457,13 +457,13 @@ usb_bus_mem_flush_all(struct usb_bus *bu
 #if USB_HAVE_BUSDMA
 static void
 usb_bus_mem_alloc_all_cb(struct usb_bus *bus, struct usb_page_cache *pc,
-    struct usb_page *pg, int npg, usb_size_t size, usb_size_t align)
+    struct usb_page *pg, usb_size_t size, usb_size_t align)
 {
 
 	/* need to initialize the page cache */
 	pc->tag_parent = bus->dma_parent_tag;
 
-	if (usb_pc_alloc_mem(pc, pg, npg, size, align))
+	if (usb_pc_alloc_mem(pc, pg, size, align))
 		bus->alloc_failed = 1;
 }
 #endif
@@ -496,7 +496,7 @@ usb_bus_mem_alloc_all(struct usb_bus *bu
 #if USB_HAVE_BUSDMA
 static void
 usb_bus_mem_free_all_cb(struct usb_bus *bus, struct usb_page_cache *pc,
-    struct usb_page *pg, int npg, usb_size_t size, usb_size_t align)
+    struct usb_page *pg, usb_size_t size, usb_size_t align)
 {
 
 	usb_pc_free_mem(pc);

Modified: user/weongyo/usb/sys/dev/usb/usb_busdma.c
==============================================================================
--- user/weongyo/usb/sys/dev/usb/usb_busdma.c	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/usb_busdma.c	Thu Sep 23 01:19:31 2010	(r213043)
@@ -78,61 +78,51 @@ static void	usb_pc_common_mem_cb(void *,
  * been properly initialized !
  *------------------------------------------------------------------------*/
 void
-usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset0,
+usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
     struct usb_page_search *res)
 {
 	struct usb_page *page;
-	usb_frlength_t end, offset = offset0;
-	int index;
 
 #if USB_HAVE_BUSDMA
-	if (pc->pages != NULL) {
-		USB_ASSERT(pc->npages > 0,
-		    ("wrong numbers of pages (%d)", pc->npages));
+	if (pc->page_start) {
+
 		/* Case 1 - something has been loaded into DMA */
+
 		if (pc->buffer) {
+
 			/* Case 1a - Kernel Virtual Address */
+
 			res->buffer = USB_ADD_BYTES(pc->buffer, offset);
 		}
 		offset += pc->page_offset_buf;
+
 		/* compute destination page */
-		page = pc->pages;
-		index = 0;
+
+		page = pc->page_start;
+
 		if (pc->ismultiseg) {
-			index += (offset / USB_PAGE_SIZE);
-			USB_ASSERT(index < pc->npages,
-			    ("invalid index number (%d / %d)", index,
-			    pc->npages));
+
+			page += (offset / USB_PAGE_SIZE);
+
 			offset %= USB_PAGE_SIZE;
-			/* If it's the last segment handle differently */
-			if ((index + 1) != pc->npages)
-				res->length = USB_PAGE_SIZE - offset;
-			else {
-				end = page[index].physlen;
-				if (index == 0)
-					end += pc->page_offset_buf;
-				USB_ASSERT(end >= offset,
-				    ("wrong offset (%d / %d)", end, offset));
-				res->length = end - offset;
-			}
-			res->physaddr = page[index].physaddr + offset;
+
+			res->length = USB_PAGE_SIZE - offset;
+			res->physaddr = page->physaddr + offset;
 		} else {
-			USB_ASSERT(pc->npages == 1,
-			    ("multiple DMA segments without pc->ismultiseg"));
-			USB_ASSERT(page[index].physlen > offset0,
-			    ("wrong offset (%zd/ %d)", page[index].physlen,
-			    offset0));
-			res->length = page[index].physlen - offset0;
-			res->physaddr = page[index].physaddr + offset;
+			res->length = 0 - 1;
+			res->physaddr = page->physaddr + offset;
 		}
 		if (!pc->buffer) {
+
 			/* Case 1b - Non Kernel Virtual Address */
-			res->buffer = USB_ADD_BYTES(page[index].buffer, offset);
+
+			res->buffer = USB_ADD_BYTES(page->buffer, offset);
 		}
 		return;
 	}
 #endif
 	/* Case 2 - Plain PIO */
+
 	res->buffer = USB_ADD_BYTES(pc->buffer, offset);
 	res->length = 0 - 1;
 #if USB_HAVE_BUSDMA
@@ -439,12 +429,8 @@ usb_pc_common_mem_cb(void *arg, bus_dma_
 	if (error)
 		goto done;
 
-	USB_ASSERT(nseg <= pc->npages,
-	    ("too many segments (%d <= %d)", nseg, pc->npages));
-
-	pg = pc->pages;
+	pg = pc->page_start;
 	pg->physaddr = segs[0].ds_addr & ~(USB_PAGE_SIZE - 1);
-	pg->physlen = segs[0].ds_len;
 	rem = segs[0].ds_addr & (USB_PAGE_SIZE - 1);
 	pc->page_offset_buf = rem;
 	pc->page_offset_end += rem;
@@ -458,18 +444,8 @@ usb_pc_common_mem_cb(void *arg, bus_dma_
 		goto done;
 	}
 #endif
-	for (i = 1; i < nseg; i++) {
-		/*
-		 * XXX Currently USB stack has a assumption that after second
-		 * segments always the address would be aligned by
-		 * USB_PAGE_SIZE.  If it's failed, all DMA operations would
-		 * be wrong.
-		 */
-		USB_ASSERT((segs[i].ds_addr & (USB_PAGE_SIZE - 1)) == 0,
-		    ("wrong DMA alignment (%#jx)", segs[i].ds_addr));
-		pg[i].physaddr = segs[i].ds_addr;
-		pg[i].physlen = segs[i].ds_len;
-	}
+	for (i = 1; i < nseg; i++)
+		pg[i].physaddr = segs[i].ds_addr & ~(USB_PAGE_SIZE - 1);
 done:
 	uptag->dma_error = (error ? 1 : 0);
 	if (isload)
@@ -486,7 +462,7 @@ done:
  * Else: Failure
  *------------------------------------------------------------------------*/
 uint8_t
-usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg, int npg,
+usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
     usb_size_t size, usb_size_t align)
 {
 	struct usb_dma_parent_tag *uptag;
@@ -547,8 +523,7 @@ usb_pc_alloc_mem(struct usb_page_cache *
 	}
 	/* setup page cache */
 	pc->buffer = ptr;
-	pc->pages = pg;
-	pc->npages = npg;
+	pc->page_start = pg;
 	pc->page_offset_buf = 0;
 	pc->page_offset_end = size;
 	pc->map = map;
@@ -581,8 +556,7 @@ usb_pc_alloc_mem(struct usb_page_cache *
 error:
 	/* reset most of the page cache */
 	pc->buffer = NULL;
-	pc->pages = NULL;
-	pc->npages = 0;
+	pc->page_start = NULL;
 	pc->page_offset_buf = 0;
 	pc->page_offset_end = 0;
 	pc->map = NULL;
@@ -935,32 +909,25 @@ usb_bdma_work_loop(struct usb_xfer_queue
 		}
 
 		/*
-		 * Setup the "pages" pointer which points to an array of
+		 * Setup the "page_start" pointer which points to an array of
 		 * USB pages where information about the physical address of a
 		 * page will be stored. Also initialise the "isread" field of
 		 * the USB page caches.
 		 */
-		xfer->frbuffers[0].pages = pg;
-		/* XXX why +2 here?  It looks it's a quirk */
-		xfer->frbuffers[0].npages = (frlength_0 / USB_PAGE_SIZE) + 2;
+		xfer->frbuffers[0].page_start = pg;
 
 		info->dma_nframes = nframes;
 		info->dma_currframe = 0;
 		info->dma_frlength_0 = frlength_0;
 
 		pg += (frlength_0 / USB_PAGE_SIZE);
-		/* XXX why +2 here?  It looks it's a quirk */
 		pg += 2;
 
 		while (--nframes > 0) {
 			xfer->frbuffers[nframes].isread = isread;
-			xfer->frbuffers[nframes].pages = pg;
-			/* XXX why +2 here?  It looks it's a quirk */
-			xfer->frbuffers[nframes].npages =
-			    (xfer->frlengths[nframes] / USB_PAGE_SIZE) + 2;
+			xfer->frbuffers[nframes].page_start = pg;
 
 			pg += (xfer->frlengths[nframes] / USB_PAGE_SIZE);
-			/* XXX why +2 here?  It looks it's a quirk */
 			pg += 2;
 		}
 

Modified: user/weongyo/usb/sys/dev/usb/usb_busdma.h
==============================================================================
--- user/weongyo/usb/sys/dev/usb/usb_busdma.h	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/usb_busdma.h	Thu Sep 23 01:19:31 2010	(r213043)
@@ -61,7 +61,6 @@ typedef void (usb_dma_callback_t)(struct
 struct usb_page {
 #if USB_HAVE_BUSDMA
 	bus_addr_t physaddr;
-	bus_size_t physlen;
 	void   *buffer;			/* non Kernel Virtual Address */
 #endif
 };
@@ -88,8 +87,7 @@ struct usb_page_cache {
 #if USB_HAVE_BUSDMA
 	bus_dma_tag_t tag;
 	bus_dmamap_t map;
-	struct usb_page *pages;		/* the array pointer of DMA segments */
-	int npages;			/* numbers of DMA segments */
+	struct usb_page *page_start;
 #endif
 	struct usb_dma_parent_tag *tag_parent;	/* always set */
 	void   *buffer;			/* virtual buffer pointer */
@@ -143,7 +141,7 @@ int	usb_uiomove(struct usb_page_cache *p
 struct usb_dma_tag *usb_dma_tag_find(struct usb_dma_parent_tag *udpt,
 	    usb_size_t size, usb_size_t align);
 uint8_t	usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
-	    int npg, usb_size_t size, usb_size_t align);
+	    usb_size_t size, usb_size_t align);
 uint8_t	usb_pc_dmamap_create(struct usb_page_cache *pc, usb_size_t size);
 uint8_t	usb_pc_load_mem(struct usb_page_cache *pc, usb_size_t size,
 	    uint8_t sync);

Modified: user/weongyo/usb/sys/dev/usb/usb_controller.h
==============================================================================
--- user/weongyo/usb/sys/dev/usb/usb_controller.h	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/usb_controller.h	Thu Sep 23 01:19:31 2010	(r213043)
@@ -46,8 +46,8 @@ struct usb_endpoint_descriptor;
 /* typedefs */
 
 typedef void	(usb_bus_mem_callback_t)(struct usb_bus *,
-		    struct usb_page_cache *, struct usb_page *, int,
-		    usb_size_t, usb_size_t);
+		    struct usb_page_cache *, struct usb_page *, usb_size_t,
+		    usb_size_t);
 
 /*
  * The following structure is used to define all the USB BUS

Modified: user/weongyo/usb/sys/dev/usb/usb_transfer.c
==============================================================================
--- user/weongyo/usb/sys/dev/usb/usb_transfer.c	Wed Sep 22 23:41:02 2010	(r213042)
+++ user/weongyo/usb/sys/dev/usb/usb_transfer.c	Thu Sep 23 01:19:31 2010	(r213043)
@@ -268,7 +268,7 @@ usbd_transfer_setup_sub_malloc(struct us
 			n_obj = r;
 		}
 		if (usb_pc_alloc_mem(parm->dma_page_cache_ptr,
-		    pg, 1, z, align)) {
+		    pg, z, align)) {
 			return (1);	/* failure */
 		}
 		/* Set beginning of current buffer */
@@ -284,8 +284,7 @@ usbd_transfer_setup_sub_malloc(struct us
 				return (1);	/* failure */
 			}
 			pc->buffer = USB_ADD_BYTES(buf, y * size);
-			pc->pages = pg;
-			pc->npages = 1;
+			pc->page_start = pg;
 
 			mtx_lock(pc->tag_parent->mtx);
 			if (usb_pc_load_mem(pc, size, 1 /* synchronous */ )) {


More information about the svn-src-user mailing list