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

Weongyo Jeong weongyo at FreeBSD.org
Mon Sep 20 23:17:28 UTC 2010


Author: weongyo
Date: Mon Sep 20 23:17:26 2010
New Revision: 212937
URL: http://svn.freebsd.org/changeset/base/212937

Log:
  Adds a variable `npage' to struct usb_page_cache which points the number
  of DMA pages for a usb_page_cache structure.  In the previous it just
  pointed a pointer of the array for page_start variable so USB stack
  explicitly didn't know how many array could be accessed by
  bus_dmamap_load(9) callback.  Only a developer of the host controller
  driver knows it in their mind not in code.

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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/controller/ehci.c	Mon Sep 20 23:17:26 2010	(r212937)
@@ -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,
+	(*func)(bus, &sc->sc_hw.pframes_pc, &sc->sc_hw.pframes_pg, 1,
 	    sizeof(uint32_t) * EHCI_FRAMELIST_COUNT, EHCI_FRAMELIST_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.async_start_pc, &sc->sc_hw.async_start_pg,
+	(*func)(bus, &sc->sc_hw.async_start_pc, &sc->sc_hw.async_start_pg, 1,
 	    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,
+		    sc->sc_hw.intr_start_pg + i, 1,
 		    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,
+		    sc->sc_hw.isoc_hs_start_pg + i, 1,
 		    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,
+		    sc->sc_hw.isoc_fs_start_pg + i, 1,
 		    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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/controller/ohci.c	Mon Sep 20 23:17:26 2010	(r212937)
@@ -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,
+	(*func)(bus, &sc->sc_hw.hcca_pc, &sc->sc_hw.hcca_pg, 1,
 	    sizeof(ohci_hcca_t), OHCI_HCCA_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.ctrl_start_pc, &sc->sc_hw.ctrl_start_pg,
+	(*func)(bus, &sc->sc_hw.ctrl_start_pc, &sc->sc_hw.ctrl_start_pg, 1,
 	    sizeof(ohci_ed_t), OHCI_ED_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg,
+	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg, 1,
 	    sizeof(ohci_ed_t), OHCI_ED_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.isoc_start_pc, &sc->sc_hw.isoc_start_pg,
+	(*func)(bus, &sc->sc_hw.isoc_start_pc, &sc->sc_hw.isoc_start_pg, 1,
 	    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,
+		    sc->sc_hw.intr_start_pg + i, 1,
 		    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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/controller/uhci.c	Mon Sep 20 23:17:26 2010	(r212937)
@@ -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,
+	(*func)(bus, &sc->sc_hw.pframes_pc, &sc->sc_hw.pframes_pg, 1,
 	    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,
+	(*func)(bus, &sc->sc_hw.ls_ctl_start_pc, &sc->sc_hw.ls_ctl_start_pg, 1,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.fs_ctl_start_pc, &sc->sc_hw.fs_ctl_start_pg,
+	(*func)(bus, &sc->sc_hw.fs_ctl_start_pc, &sc->sc_hw.fs_ctl_start_pg, 1,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg,
+	(*func)(bus, &sc->sc_hw.bulk_start_pc, &sc->sc_hw.bulk_start_pg, 1,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.last_qh_pc, &sc->sc_hw.last_qh_pg,
+	(*func)(bus, &sc->sc_hw.last_qh_pc, &sc->sc_hw.last_qh_pg, 1,
 	    sizeof(uhci_qh_t), UHCI_QH_ALIGN);
 
-	(*func)(bus, &sc->sc_hw.last_td_pc, &sc->sc_hw.last_td_pg,
+	(*func)(bus, &sc->sc_hw.last_td_pc, &sc->sc_hw.last_td_pg, 1,
 	    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,
+		    sc->sc_hw.isoc_start_pg + i, 1,
 		    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,
+		    sc->sc_hw.intr_start_pg + i, 1,
 		    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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/controller/usb_controller.c	Mon Sep 20 23:17:26 2010	(r212937)
@@ -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, usb_size_t size, usb_size_t align)
+    struct usb_page *pg, int npg, 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, usb_size_t size, usb_size_t align)
+    struct usb_page *pg, int npg, 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, size, align))
+	if (usb_pc_alloc_mem(pc, pg, npg, 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, usb_size_t size, usb_size_t align)
+    struct usb_page *pg, int npg, 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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/usb_busdma.c	Mon Sep 20 23:17:26 2010	(r212937)
@@ -428,7 +428,7 @@ usb_pc_common_mem_cb(void *arg, bus_dma_
 	if (error)
 		goto done;
 
-	USB_ASSERT(nseg == 1, ("too many segments (%d)", nseg));
+	USB_ASSERT(nseg <= pc->npage, ("too many segments (%d)", nseg));
 
 	pg = pc->page_start;
 	pg->physaddr = segs[0].ds_addr & ~(USB_PAGE_SIZE - 1);
@@ -463,7 +463,7 @@ done:
  * Else: Failure
  *------------------------------------------------------------------------*/
 uint8_t
-usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
+usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg, int npg,
     usb_size_t size, usb_size_t align)
 {
 	struct usb_dma_parent_tag *uptag;
@@ -519,6 +519,7 @@ usb_pc_alloc_mem(struct usb_page_cache *
 	/* setup page cache */
 	pc->buffer = ptr;
 	pc->page_start = pg;
+	pc->npage = npg;
 	pc->page_offset_buf = 0;
 	pc->page_offset_end = size;
 	pc->map = map;
@@ -552,6 +553,7 @@ error:
 	/* reset most of the page cache */
 	pc->buffer = NULL;
 	pc->page_start = NULL;
+	pc->npage = 0;
 	pc->page_offset_buf = 0;
 	pc->page_offset_end = 0;
 	pc->map = NULL;
@@ -910,6 +912,7 @@ usb_bdma_work_loop(struct usb_xfer_queue
 		 * the USB page caches.
 		 */
 		xfer->frbuffers[0].page_start = pg;
+		xfer->frbuffers[0].npage = (frlength_0 / USB_PAGE_SIZE) + 2;
 
 		info->dma_nframes = nframes;
 		info->dma_currframe = 0;
@@ -921,6 +924,8 @@ usb_bdma_work_loop(struct usb_xfer_queue
 		while (--nframes > 0) {
 			xfer->frbuffers[nframes].isread = isread;
 			xfer->frbuffers[nframes].page_start = pg;
+			xfer->frbuffers[nframes].npage =
+			    (xfer->frlengths[nframes] / USB_PAGE_SIZE);
 
 			pg += (xfer->frlengths[nframes] / USB_PAGE_SIZE);
 			pg += 2;

Modified: user/weongyo/usb/sys/dev/usb/usb_busdma.h
==============================================================================
--- user/weongyo/usb/sys/dev/usb/usb_busdma.h	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/usb_busdma.h	Mon Sep 20 23:17:26 2010	(r212937)
@@ -88,6 +88,7 @@ struct usb_page_cache {
 	bus_dma_tag_t tag;
 	bus_dmamap_t map;
 	struct usb_page *page_start;
+	int npage;
 #endif
 	struct usb_dma_parent_tag *tag_parent;	/* always set */
 	void   *buffer;			/* virtual buffer pointer */
@@ -141,7 +142,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,
-	    usb_size_t size, usb_size_t align);
+	    int npg, 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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/usb_controller.h	Mon Sep 20 23:17:26 2010	(r212937)
@@ -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 *, usb_size_t,
-		    usb_size_t);
+		    struct usb_page_cache *, struct usb_page *, int,
+		    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	Mon Sep 20 23:00:21 2010	(r212936)
+++ user/weongyo/usb/sys/dev/usb/usb_transfer.c	Mon Sep 20 23:17:26 2010	(r212937)
@@ -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, z, align)) {
+		    pg, 1, z, align)) {
 			return (1);	/* failure */
 		}
 		/* Set beginning of current buffer */
@@ -285,6 +285,7 @@ usbd_transfer_setup_sub_malloc(struct us
 			}
 			pc->buffer = USB_ADD_BYTES(buf, y * size);
 			pc->page_start = pg;
+			pc->npage = 1;
 
 			mtx_lock(pc->tag_parent->mtx);
 			if (usb_pc_load_mem(pc, size, 1 /* synchronous */ )) {


More information about the svn-src-user mailing list