Date: Fri, 30 Nov 2007 23:07:11 GMT From: Hans Petter Selasky <hselasky@FreeBSD.org> To: Perforce Change Reviews <perforce@FreeBSD.org> Subject: PERFORCE change 129848 for review Message-ID: <200711302307.lAUN7BtA024323@repoman.freebsd.org>
next in thread | raw e-mail | index | archive | help
http://perforce.freebsd.org/chv.cgi?CH=129848 Change 129848 by hselasky@hselasky_laptop001 on 2007/11/30 23:06:23 Factor out the following functions into common code in "usb_subr.c": {ehci,ohci,uhci}_flush_all {ehci,ohci,uhci}_alloc_all {ehci,ohci,uhci}_free_all {ehci,ohci,uhci}_dma_alloc_mem Affected files ... .. //depot/projects/usb/src/sys/arm/at91/ohci_atmelarm.c#9 edit .. //depot/projects/usb/src/sys/dev/usb/ehci.c#53 edit .. //depot/projects/usb/src/sys/dev/usb/ehci.h#23 edit .. //depot/projects/usb/src/sys/dev/usb/ehci_pci.c#27 edit .. //depot/projects/usb/src/sys/dev/usb/ohci.c#43 edit .. //depot/projects/usb/src/sys/dev/usb/ohci.h#19 edit .. //depot/projects/usb/src/sys/dev/usb/ohci_pci.c#27 edit .. //depot/projects/usb/src/sys/dev/usb/uhci.c#45 edit .. //depot/projects/usb/src/sys/dev/usb/uhci.h#19 edit .. //depot/projects/usb/src/sys/dev/usb/uhci_pci.c#26 edit Differences ... ==== //depot/projects/usb/src/sys/arm/at91/ohci_atmelarm.c#9 (text) ==== @@ -73,15 +73,12 @@ } /* store parent DMA tag */ - sc->sc_bus.dma_tag_parent = device_get_dma_tag(self); + sc->sc_ohci.sc_bus.dma_tag_parent = device_get_dma_tag(self); /* get all DMA memory */ - ohci_iterate_hw_softc(sc, &ohci_alloc_all); - - if (sc->sc_alloc_failed) { - ohci_iterate_hw_softc(sc, &ohci_free_all); - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + if (usbd_bus_mem_alloc_all(&(sc->sc_ohci.sc_bus), + &ohci_iterate_hw_softc)) { return ENOMEM; } sc->iclk = at91_pmc_clock_ref("ohci_clk"); @@ -205,9 +202,7 @@ } usbd_config_td_unsetup(&(sc->sc_config_td)); - ohci_iterate_hw_softc(sc, &ohci_free_all); - - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + usbd_bus_mem_free_all(&(sc->sc_bus), &ohci_iterate_hw_softc); mtx_destroy(&(sc->sc_ohci.sc_bus.mtx)); ==== //depot/projects/usb/src/sys/dev/usb/ehci.c#53 (text+ko) ==== @@ -85,10 +85,8 @@ SYSCTL_INT(_hw_usb_ehci, OID_AUTO, debug, CTLFLAG_RW, &ehcidebug, 0, "ehci debug level"); -static void - ehci_dump_regs(ehci_softc_t *sc); -static void - ehci_dump_sqh(ehci_qh_t *sqh); +static void ehci_dump_regs(ehci_softc_t *sc); +static void ehci_dump_sqh(ehci_qh_t *sqh); #else #define DPRINTF(x) do { } while (0) @@ -127,63 +125,37 @@ }; void -ehci_iterate_hw_softc(ehci_softc_t *sc, ehci_iterate_cb_t *cb) +ehci_iterate_hw_softc(struct usbd_bus *bus, usbd_bus_mem_sub_cb_t *cb) { + struct ehci_softc *sc = EHCI_BUS2SC(bus); uint32_t i; - cb(sc, &(sc->sc_hw.pframes_pc), &(sc->sc_hw.pframes_pg), + cb(bus, &(sc->sc_hw.pframes_pc), &(sc->sc_hw.pframes_pg), sizeof(uint32_t) * EHCI_FRAMELIST_COUNT, EHCI_FRAMELIST_ALIGN); - cb(sc, &(sc->sc_hw.async_start_pc), &(sc->sc_hw.async_start_pg), + cb(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++) { - cb(sc, sc->sc_hw.intr_start_pc + i, + cb(bus, sc->sc_hw.intr_start_pc + i, sc->sc_hw.intr_start_pg + i, sizeof(ehci_qh_t), EHCI_QH_ALIGN); } for (i = 0; i != EHCI_VIRTUAL_FRAMELIST_COUNT; i++) { - cb(sc, sc->sc_hw.isoc_hs_start_pc + i, + cb(bus, sc->sc_hw.isoc_hs_start_pc + i, sc->sc_hw.isoc_hs_start_pg + i, sizeof(ehci_itd_t), EHCI_ITD_ALIGN); } for (i = 0; i != EHCI_VIRTUAL_FRAMELIST_COUNT; i++) { - cb(sc, sc->sc_hw.isoc_fs_start_pc + i, + cb(bus, sc->sc_hw.isoc_fs_start_pc + i, sc->sc_hw.isoc_fs_start_pg + i, sizeof(ehci_sitd_t), EHCI_SITD_ALIGN); } return; } -void -ehci_flush_all(ehci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - usbd_pc_cpu_flush(pc); - return; -} - -void -ehci_alloc_all(ehci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - if (usbd_dma_alloc_mem(sc->sc_bus.dma_tag_parent, - sc->sc_bus.dma_tag, pc, pg, size, align)) { - sc->sc_alloc_failed = 1; - } - return; -} - -void -ehci_free_all(ehci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - usbd_dma_free_mem(pc); - return; -} - usbd_status ehci_init(ehci_softc_t *sc) { @@ -440,7 +412,7 @@ } /* flush all cache into memory */ - ehci_iterate_hw_softc(sc, &ehci_flush_all); + usbd_bus_mem_flush_all(&(sc->sc_bus), &ehci_iterate_hw_softc); #ifdef USB_DEBUG if (ehcidebug) { @@ -3661,30 +3633,11 @@ .start = ehci_root_intr_start, }; -static uint8_t -ehci_dma_alloc_mem(struct usbd_setup_params *parm, uint32_t size, - uint32_t align, struct usbd_page_search *info) -{ - ehci_softc_t *sc; - - sc = EHCI_BUS2SC(parm->udev->bus); - - /* FIXME sc->sc_bus.dma_tag to xfer->dma_tags */ - - if (usbd_dma_alloc_mem(sc->sc_bus.dma_tag_parent, - sc->sc_bus.dma_tag, parm->dma_page_cache_ptr, - parm->dma_page_ptr, size, align)) { - return (1); /* failure */ - } - usbd_get_page(parm->dma_page_cache_ptr, 0, info); - - return (0); -} - static void ehci_xfer_setup(struct usbd_setup_params *parm) { struct usbd_page_search page_info; + struct usbd_page_cache *pc; ehci_softc_t *sc; struct usbd_xfer *xfer; void *last_obj; @@ -3833,80 +3786,77 @@ for (n = 0; n != nitd; n++) { + register ehci_itd_t *td; + + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*td), + EHCI_ITD_ALIGN)) { + parm->err = USBD_NOMEM; + break; + } if (parm->buf) { - register ehci_itd_t *td; - - if (ehci_dma_alloc_mem(parm, sizeof(*td), - EHCI_ITD_ALIGN, &page_info)) { - parm->err = USBD_NOMEM; - break; - } td = page_info.buffer; /* init TD */ td->itd_self = htole32(page_info.physaddr | EHCI_LINK_ITD); td->obj_next = last_obj; - td->page_cache = parm->dma_page_cache_ptr; + td->page_cache = pc; last_obj = td; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } for (n = 0; n != nsitd; n++) { + register ehci_sitd_t *td; + + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*td), + EHCI_SITD_ALIGN)) { + parm->err = USBD_NOMEM; + break; + } if (parm->buf) { - register ehci_sitd_t *td; - - if (ehci_dma_alloc_mem(parm, sizeof(*td), - EHCI_SITD_ALIGN, &page_info)) { - parm->err = USBD_NOMEM; - break; - } td = page_info.buffer; /* init TD */ td->sitd_self = htole32(page_info.physaddr | EHCI_LINK_SITD); td->obj_next = last_obj; - td->page_cache = parm->dma_page_cache_ptr; + td->page_cache = pc; last_obj = td; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } for (n = 0; n != nqtd; n++) { + register ehci_qtd_t *qtd; + + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*qtd), + EHCI_QTD_ALIGN)) { + parm->err = USBD_NOMEM; + break; + } if (parm->buf) { - register ehci_qtd_t *qtd; - - if (ehci_dma_alloc_mem(parm, sizeof(*qtd), - EHCI_QTD_ALIGN, &page_info)) { - parm->err = USBD_NOMEM; - break; - } qtd = page_info.buffer; /* init TD */ qtd->qtd_self = htole32(page_info.physaddr); qtd->obj_next = last_obj; - qtd->page_cache = parm->dma_page_cache_ptr; + qtd->page_cache = pc; last_obj = qtd; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } xfer->td_start = last_obj; @@ -3915,28 +3865,27 @@ for (n = 0; n != nqh; n++) { + register ehci_qh_t *qh; + + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*qh), + EHCI_QH_ALIGN)) { + parm->err = USBD_NOMEM; + break; + } if (parm->buf) { - register ehci_qh_t *qh; - - if (ehci_dma_alloc_mem(parm, sizeof(*qh), - EHCI_QH_ALIGN, &page_info)) { - parm->err = USBD_NOMEM; - break; - } qh = page_info.buffer; /* init QH */ qh->qh_self = htole32(page_info.physaddr | EHCI_LINK_QH); qh->obj_next = last_obj; - qh->page_cache = parm->dma_page_cache_ptr; + qh->page_cache = pc; last_obj = qh; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } xfer->qh_start = last_obj; ==== //depot/projects/usb/src/sys/dev/usb/ehci.h#23 (text+ko) ==== @@ -473,7 +473,6 @@ uint8_t sc_addr; /* device address */ uint8_t sc_conf; /* device configuration */ uint8_t sc_isreset; - uint8_t sc_alloc_failed; uint8_t sc_hub_idata[8]; char sc_vendor[16]; /* vendor string for root hub */ @@ -502,13 +501,9 @@ #define EOWRITE4(sc, a, x) \ bus_space_write_4((sc)->sc_io_tag, (sc)->sc_io_hdl, (sc)->sc_offs+(a), (x)) -typedef void (ehci_iterate_cb_t)(ehci_softc_t *sc, struct usbd_page_cache *pc, struct usbd_page *pg, uint32_t size, uint32_t align); -ehci_iterate_cb_t ehci_flush_all; -ehci_iterate_cb_t ehci_alloc_all; -ehci_iterate_cb_t ehci_free_all; +usbd_bus_mem_cb_t ehci_iterate_hw_softc; usbd_status ehci_init(ehci_softc_t *sc); -void ehci_iterate_hw_softc(ehci_softc_t *sc, ehci_iterate_cb_t *cb); void ehci_detach(struct ehci_softc *sc); void ehci_suspend(struct ehci_softc *sc); void ehci_resume(struct ehci_softc *sc); ==== //depot/projects/usb/src/sys/dev/usb/ehci_pci.c#27 (text+ko) ==== @@ -221,11 +221,7 @@ /* get all DMA memory */ - ehci_iterate_hw_softc(sc, &ehci_alloc_all); - - if (sc->sc_alloc_failed) { - ehci_iterate_hw_softc(sc, &ehci_free_all); - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + if (usbd_bus_mem_alloc_all(&(sc->sc_bus), &ehci_iterate_hw_softc)) { return ENOMEM; } mtx_init(&sc->sc_bus.mtx, "usb lock", @@ -409,9 +405,7 @@ } usbd_config_td_unsetup(&(sc->sc_config_td)); - ehci_iterate_hw_softc(sc, &ehci_free_all); - - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + usbd_bus_mem_free_all(&(sc->sc_bus), &ehci_iterate_hw_softc); mtx_destroy(&sc->sc_bus.mtx); ==== //depot/projects/usb/src/sys/dev/usb/ohci.c#43 (text+ko) ==== @@ -148,56 +148,30 @@ } void -ohci_iterate_hw_softc(ohci_softc_t *sc, ohci_iterate_cb_t *cb) +ohci_iterate_hw_softc(struct usbd_bus *bus, usbd_bus_mem_sub_cb_t *cb) { + struct ohci_softc *sc = OHCI_BUS2SC(bus); uint32_t i; - cb(sc, &(sc->sc_hw.hcca_pc), &(sc->sc_hw.hcca_pg), + cb(bus, &(sc->sc_hw.hcca_pc), &(sc->sc_hw.hcca_pg), sizeof(ohci_hcca_t), OHCI_HCCA_ALIGN); - cb(sc, &(sc->sc_hw.ctrl_start_pc), &(sc->sc_hw.ctrl_start_pg), + cb(bus, &(sc->sc_hw.ctrl_start_pc), &(sc->sc_hw.ctrl_start_pg), sizeof(ohci_ed_t), OHCI_ED_ALIGN); - cb(sc, &(sc->sc_hw.bulk_start_pc), &(sc->sc_hw.bulk_start_pg), + cb(bus, &(sc->sc_hw.bulk_start_pc), &(sc->sc_hw.bulk_start_pg), sizeof(ohci_ed_t), OHCI_ED_ALIGN); - cb(sc, &(sc->sc_hw.isoc_start_pc), &(sc->sc_hw.isoc_start_pg), + cb(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++) { - cb(sc, sc->sc_hw.intr_start_pc + i, sc->sc_hw.intr_start_pg + i, + cb(bus, sc->sc_hw.intr_start_pc + i, sc->sc_hw.intr_start_pg + i, sizeof(ohci_ed_t), OHCI_ED_ALIGN); } return; } -void -ohci_flush_all(ohci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - usbd_pc_cpu_flush(pc); - return; -} - -void -ohci_alloc_all(ohci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - if (usbd_dma_alloc_mem(sc->sc_bus.dma_tag_parent, - sc->sc_bus.dma_tag, pc, pg, size, align)) { - sc->sc_alloc_failed = 1; - } - return; -} - -void -ohci_free_all(ohci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - usbd_dma_free_mem(pc); - return; -} - static usbd_status ohci_controller_init(ohci_softc_t *sc) { @@ -434,8 +408,9 @@ sc->sc_hcca_p->hcca_interrupt_table[i] = sc->sc_intr_p_last[i | (OHCI_NO_EDS / 2)]->ed_self; } + /* flush all cache into memory */ - ohci_iterate_hw_softc(sc, &ohci_flush_all); + usbd_bus_mem_flush_all(&(sc->sc_bus), &ohci_iterate_hw_softc); LIST_INIT(&sc->sc_interrupt_list_head); @@ -2696,19 +2671,11 @@ .start = ohci_root_intr_start, }; -static uint8_t -ohci_dma_alloc_mem(struct usbd_setup_params *parm, uint32_t size, - uint32_t align, struct usbd_page_search *info) -{ - XXX this function will be factored out shortly; - - return (0); -} - static void ohci_xfer_setup(struct usbd_setup_params *parm) { struct usbd_page_search page_info; + struct usbd_page_cache *pc; ohci_softc_t *sc; struct usbd_xfer *xfer; void *last_obj; @@ -2782,8 +2749,9 @@ ohci_td_t *td; - if (ohci_dma_alloc_mem(parm, sizeof(*td), - OHCI_TD_ALIGN, &page_info)) { + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*td), + OHCI_TD_ALIGN)) { parm->err = USBD_NOMEM; break; } @@ -2794,22 +2762,21 @@ /* init TD */ td->td_self = htole32(page_info.physaddr); td->obj_next = last_obj; - td->page_cache = parm->dma_page_cache_ptr; + td->page_cache = pc; last_obj = td; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } for (n = 0; n != nitd; n++) { ohci_itd_t *itd; - if (ohci_dma_alloc_mem(parm, sizeof(*itd), - OHCI_ITD_ALIGN, &page_info)) { + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*itd), + OHCI_ITD_ALIGN)) { parm->err = USBD_NOMEM; break; } @@ -2820,14 +2787,12 @@ /* init TD */ itd->itd_self = htole32(page_info.physaddr); itd->obj_next = last_obj; - itd->page_cache = parm->dma_page_cache_ptr; + itd->page_cache = pc; last_obj = itd; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } xfer->td_start = last_obj; @@ -2838,8 +2803,9 @@ ohci_ed_t *ed; - if (ohci_dma_alloc_mem(parm, sizeof(*ed), - OHCI_ED_ALIGN, &page_info)) { + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*ed), + OHCI_ED_ALIGN)) { parm->err = USBD_NOMEM; break; } @@ -2850,14 +2816,12 @@ /* init QH */ ed->ed_self = htole32(page_info.physaddr); ed->obj_next = last_obj; - ed->page_cache = parm->dma_page_cache_ptr; + ed->page_cache = pc; last_obj = ed; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } xfer->qh_start = last_obj; ==== //depot/projects/usb/src/sys/dev/usb/ohci.h#19 (text+ko) ==== @@ -348,20 +348,15 @@ uint8_t sc_noport; uint8_t sc_addr; /* device address */ uint8_t sc_conf; /* device configuration */ - uint8_t sc_alloc_failed; uint8_t sc_hub_idata[32]; char sc_vendor[16]; } ohci_softc_t; -typedef void (ohci_iterate_cb_t)(ohci_softc_t *sc, struct usbd_page_cache *pc, struct usbd_page *pg, uint32_t size, uint32_t align); -ohci_iterate_cb_t ohci_flush_all; -ohci_iterate_cb_t ohci_alloc_all; -ohci_iterate_cb_t ohci_free_all; +usbd_bus_mem_cb_t ohci_iterate_hw_softc; usbd_status ohci_init(ohci_softc_t *sc); -void ohci_iterate_hw_softc(ohci_softc_t *sc, ohci_iterate_cb_t *cb); void ohci_detach(struct ohci_softc *sc); void ohci_suspend(ohci_softc_t *sc); void ohci_resume(ohci_softc_t *sc); ==== //depot/projects/usb/src/sys/dev/usb/ohci_pci.c#27 (text+ko) ==== @@ -202,11 +202,7 @@ /* get all DMA memory */ - ohci_iterate_hw_softc(sc, &ohci_alloc_all); - - if (sc->sc_alloc_failed) { - ohci_iterate_hw_softc(sc, &ohci_free_all); - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + if (usbd_bus_mem_alloc_all(&(sc->sc_bus), &ohci_iterate_hw_softc)) { return ENOMEM; } mtx_init(&sc->sc_bus.mtx, "usb lock", @@ -366,9 +362,7 @@ } usbd_config_td_unsetup(&(sc->sc_config_td)); - ohci_iterate_hw_softc(sc, &ohci_free_all); - - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + usbd_bus_mem_free_all(&(sc->sc_bus), &ohci_iterate_hw_softc); mtx_destroy(&sc->sc_bus.mtx); ==== //depot/projects/usb/src/sys/dev/usb/uhci.c#45 (text+ko) ==== @@ -163,69 +163,43 @@ static void uhci_device_done(struct usbd_xfer *xfer, usbd_status error); void -uhci_iterate_hw_softc(uhci_softc_t *sc, uhci_iterate_cb_t *cb) +uhci_iterate_hw_softc(struct usbd_bus *bus, usbd_bus_mem_sub_cb_t *cb) { + struct uhci_softc *sc = UHCI_BUS2SC(bus); uint32_t i; - cb(sc, &(sc->sc_hw.pframes_pc), &(sc->sc_hw.pframes_pg), + cb(bus, &(sc->sc_hw.pframes_pc), &(sc->sc_hw.pframes_pg), sizeof(uint32_t) * UHCI_FRAMELIST_COUNT, UHCI_FRAMELIST_ALIGN); - cb(sc, &(sc->sc_hw.ls_ctl_start_pc), &(sc->sc_hw.ls_ctl_start_pg), + cb(bus, &(sc->sc_hw.ls_ctl_start_pc), &(sc->sc_hw.ls_ctl_start_pg), sizeof(uhci_qh_t), UHCI_QH_ALIGN); - cb(sc, &(sc->sc_hw.fs_ctl_start_pc), &(sc->sc_hw.fs_ctl_start_pg), + cb(bus, &(sc->sc_hw.fs_ctl_start_pc), &(sc->sc_hw.fs_ctl_start_pg), sizeof(uhci_qh_t), UHCI_QH_ALIGN); - cb(sc, &(sc->sc_hw.bulk_start_pc), &(sc->sc_hw.bulk_start_pg), + cb(bus, &(sc->sc_hw.bulk_start_pc), &(sc->sc_hw.bulk_start_pg), sizeof(uhci_qh_t), UHCI_QH_ALIGN); - cb(sc, &(sc->sc_hw.last_qh_pc), &(sc->sc_hw.last_qh_pg), + cb(bus, &(sc->sc_hw.last_qh_pc), &(sc->sc_hw.last_qh_pg), sizeof(uhci_qh_t), UHCI_QH_ALIGN); - cb(sc, &(sc->sc_hw.last_td_pc), &(sc->sc_hw.last_td_pg), + cb(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++) { - cb(sc, sc->sc_hw.isoc_start_pc + i, + cb(bus, sc->sc_hw.isoc_start_pc + i, sc->sc_hw.isoc_start_pg + i, sizeof(uhci_td_t), UHCI_TD_ALIGN); } for (i = 0; i != UHCI_IFRAMELIST_COUNT; i++) { - cb(sc, sc->sc_hw.intr_start_pc + i, + cb(bus, sc->sc_hw.intr_start_pc + i, sc->sc_hw.intr_start_pg + i, sizeof(uhci_qh_t), UHCI_QH_ALIGN); } return; } -void -uhci_flush_all(uhci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - usbd_pc_cpu_flush(pc); - return; -} - -void -uhci_alloc_all(uhci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - if (usbd_dma_alloc_mem(sc->sc_bus.dma_tag_parent, - sc->sc_bus.dma_tag, pc, pg, size, align)) { - sc->sc_alloc_failed = 1; - } - return; -} - -void -uhci_free_all(uhci_softc_t *sc, struct usbd_page_cache *pc, - struct usbd_page *pg, uint32_t size, uint32_t align) -{ - usbd_dma_free_mem(pc); - return; -} - static void uhci_mem_layout_init(struct uhci_mem_layout *ml, struct usbd_xfer *xfer) { @@ -427,7 +401,7 @@ qh->page_cache = pc; - return qh; + return (qh); } static struct uhci_td * @@ -446,7 +420,7 @@ td->page_cache = pc; - return td; + return (td); } usbd_status @@ -642,7 +616,7 @@ } /* flush all cache into memory */ - uhci_iterate_hw_softc(sc, &uhci_flush_all); + usbd_bus_mem_flush_all(&(sc->sc_bus), &uhci_iterate_hw_softc); LIST_INIT(&sc->sc_interrupt_list_head); @@ -1391,7 +1365,7 @@ td = xfer->td_transfer_last; - usbd_pc_invalidate(td->page_cache); + usbd_pc_cpu_invalidate(td->page_cache); status = le32toh(td->td_status); if (!(status & UHCI_TD_ACTIVE)) { @@ -3156,34 +3130,11 @@ .start = uhci_root_intr_start, }; -static uint8_t -uhci_dma_alloc_mem(struct usbd_setup_params *parm, uint32_t size, - uint32_t align, struct usbd_page_search *info) -{ - uhci_softc_t *sc; - - if (parm->buf == NULL) { - /* for the future */ - return (0); - } - sc = UHCI_BUS2SC(parm->udev->bus); - - /* FIXME sc->sc_bus.dma_tag to xfer->dma_tags */ - - if (usbd_dma_alloc_mem(sc->sc_bus.dma_tag_parent, - sc->sc_bus.dma_tag, parm->dma_page_cache_ptr, - parm->dma_page_ptr, size, align)) { - return (1); /* failure */ - } - usbd_get_page(parm->dma_page_cache_ptr, 0, info); - - return (0); -} - static void uhci_xfer_setup(struct usbd_setup_params *parm) { struct usbd_page_search page_info; + struct usbd_page_cache *pc; uhci_softc_t *sc; struct usbd_xfer *xfer; void *last_obj; @@ -3291,17 +3242,22 @@ } align = (1 << n); - xfer->buf_fixup = parm->dma_page_cache_ptr; - for (n = 0; n != nfixup; n++) { - if (uhci_dma_alloc_mem(parm, xfer->max_frame_size, - align, &page_info)) { + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, xfer->max_frame_size, + align)) { parm->err = USBD_NOMEM; break; } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; + if (n == 0) { + /* + * We depend on some assumptions here, like how + * "sub_malloc" lays out the "usbd_page_cache" + * structures + */ + xfer->buf_fixup = pc; + } } last_obj = NULL; @@ -3310,8 +3266,9 @@ uhci_td_t *td; - if (uhci_dma_alloc_mem(parm, sizeof(*td), - UHCI_TD_ALIGN, &page_info)) { + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*td), + UHCI_TD_ALIGN)) { parm->err = USBD_NOMEM; break; } @@ -3330,14 +3287,12 @@ } td->obj_next = last_obj; - td->page_cache = parm->dma_page_cache_ptr; + td->page_cache = pc; last_obj = td; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } xfer->td_start = last_obj; @@ -3348,8 +3303,9 @@ uhci_qh_t *qh; - if (uhci_dma_alloc_mem(parm, sizeof(*qh), - UHCI_QH_ALIGN, &page_info)) { + if (usbd_transfer_setup_sub_malloc( + parm, &page_info, &pc, sizeof(*qh), + UHCI_QH_ALIGN)) { parm->err = USBD_NOMEM; break; } @@ -3360,14 +3316,12 @@ /* init QH */ qh->qh_self = htole32(page_info.physaddr | UHCI_PTR_QH); qh->obj_next = last_obj; - qh->page_cache = parm->dma_page_cache_ptr; + qh->page_cache = pc; last_obj = qh; - usbd_pc_cpu_flush(parm->dma_page_cache_ptr); + usbd_pc_cpu_flush(pc); } - parm->dma_page_ptr++; - parm->dma_page_cache_ptr++; } xfer->qh_start = last_obj; ==== //depot/projects/usb/src/sys/dev/usb/uhci.h#19 (text+ko) ==== @@ -303,20 +303,15 @@ uint8_t sc_addr; /* device address */ uint8_t sc_conf; /* device configuration */ uint8_t sc_isreset; - uint8_t sc_alloc_failed; uint8_t sc_saved_sof; uint8_t sc_hub_idata[1]; char sc_vendor[16]; /* vendor string for root hub */ } uhci_softc_t; -typedef void (uhci_iterate_cb_t)(uhci_softc_t *sc, struct usbd_page_cache *pc, struct usbd_page *pg, uint32_t size, uint32_t align); -uhci_iterate_cb_t uhci_flush_all; -uhci_iterate_cb_t uhci_alloc_all; -uhci_iterate_cb_t uhci_free_all; +usbd_bus_mem_cb_t uhci_iterate_hw_softc; usbd_status uhci_init(uhci_softc_t *sc); -void uhci_iterate_hw_softc(uhci_softc_t *sc, uhci_iterate_cb_t *cb); void uhci_suspend(uhci_softc_t *sc); void uhci_resume(uhci_softc_t *sc); void uhci_reset(uhci_softc_t *sc); ==== //depot/projects/usb/src/sys/dev/usb/uhci_pci.c#26 (text+ko) ==== @@ -212,13 +212,13 @@ device_printf(self, "Could not allocate sc\n"); return (ENXIO); } + /* store parent DMA tag */ + + sc->sc_bus.dma_tag_parent = device_get_dma_tag(self); + /* get all DMA memory */ - uhci_iterate_hw_softc(sc, &uhci_alloc_all); - - if (sc->sc_alloc_failed) { - uhci_iterate_hw_softc(sc, &uhci_free_all); - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + if (usbd_bus_mem_alloc_all(&(sc->sc_bus), &uhci_iterate_hw_softc)) { return ENOMEM; } mtx_init(&sc->sc_bus.mtx, "usb lock", @@ -388,9 +388,7 @@ } usbd_config_td_unsetup(&(sc->sc_config_td)); - uhci_iterate_hw_softc(sc, &uhci_free_all); - - usbd_dma_tag_unsetup(sc->sc_bus.dma_tag); + usbd_bus_mem_free_all(&(sc->sc_bus), &uhci_iterate_hw_softc); mtx_destroy(&sc->sc_bus.mtx);
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200711302307.lAUN7BtA024323>