3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 #include <sys/stdint.h>
28 #include <sys/stddef.h>
29 #include <sys/param.h>
30 #include <sys/queue.h>
31 #include <sys/types.h>
32 #include <sys/systm.h>
33 #include <sys/kernel.h>
35 #include <sys/module.h>
37 #include <sys/mutex.h>
38 #include <sys/condvar.h>
39 #include <sys/sysctl.h>
41 #include <sys/unistd.h>
42 #include <sys/callout.h>
43 #include <sys/malloc.h>
46 #include <dev/usb/usb.h>
47 #include <dev/usb/usbdi.h>
48 #include <dev/usb/usbdi_util.h>
50 #define USB_DEBUG_VAR usb_debug
52 #include <dev/usb/usb_core.h>
53 #include <dev/usb/usb_busdma.h>
54 #include <dev/usb/usb_process.h>
55 #include <dev/usb/usb_transfer.h>
56 #include <dev/usb/usb_device.h>
57 #include <dev/usb/usb_util.h>
58 #include <dev/usb/usb_debug.h>
60 #include <dev/usb/usb_controller.h>
61 #include <dev/usb/usb_bus.h>
64 static void usb_dma_tag_create(struct usb_dma_tag *, usb_size_t, usb_size_t);
65 static void usb_dma_tag_destroy(struct usb_dma_tag *);
66 static void usb_dma_lock_cb(void *, bus_dma_lock_op_t);
67 static void usb_pc_alloc_mem_cb(void *, bus_dma_segment_t *, int, int);
68 static void usb_pc_load_mem_cb(void *, bus_dma_segment_t *, int, int);
69 static void usb_pc_common_mem_cb(void *, bus_dma_segment_t *, int, int,
73 /*------------------------------------------------------------------------*
74 * usbd_get_page - lookup DMA-able memory for the given offset
76 * NOTE: Only call this function when the "page_cache" structure has
77 * been properly initialized !
78 *------------------------------------------------------------------------*/
80 usbd_get_page(struct usb_page_cache *pc, usb_frlength_t offset,
81 struct usb_page_search *res)
84 struct usb_page *page;
88 /* Case 1 - something has been loaded into DMA */
92 /* Case 1a - Kernel Virtual Address */
94 res->buffer = USB_ADD_BYTES(pc->buffer, offset);
96 offset += pc->page_offset_buf;
98 /* compute destination page */
100 page = pc->page_start;
102 if (pc->ismultiseg) {
104 page += (offset / USB_PAGE_SIZE);
106 offset %= USB_PAGE_SIZE;
108 res->length = USB_PAGE_SIZE - offset;
109 res->physaddr = page->physaddr + offset;
111 res->length = (usb_size_t)-1;
112 res->physaddr = page->physaddr + offset;
116 /* Case 1b - Non Kernel Virtual Address */
118 res->buffer = USB_ADD_BYTES(page->buffer, offset);
123 /* Case 2 - Plain PIO */
125 res->buffer = USB_ADD_BYTES(pc->buffer, offset);
126 res->length = (usb_size_t)-1;
132 /*------------------------------------------------------------------------*
133 * usbd_copy_in - copy directly to DMA-able memory
134 *------------------------------------------------------------------------*/
136 usbd_copy_in(struct usb_page_cache *cache, usb_frlength_t offset,
137 const void *ptr, usb_frlength_t len)
139 struct usb_page_search buf_res;
143 usbd_get_page(cache, offset, &buf_res);
145 if (buf_res.length > len) {
146 buf_res.length = len;
148 memcpy(buf_res.buffer, ptr, buf_res.length);
150 offset += buf_res.length;
151 len -= buf_res.length;
152 ptr = USB_ADD_BYTES(ptr, buf_res.length);
156 /*------------------------------------------------------------------------*
157 * usbd_copy_in_user - copy directly to DMA-able memory from userland
162 *------------------------------------------------------------------------*/
165 usbd_copy_in_user(struct usb_page_cache *cache, usb_frlength_t offset,
166 const void *ptr, usb_frlength_t len)
168 struct usb_page_search buf_res;
173 usbd_get_page(cache, offset, &buf_res);
175 if (buf_res.length > len) {
176 buf_res.length = len;
178 error = copyin(ptr, buf_res.buffer, buf_res.length);
182 offset += buf_res.length;
183 len -= buf_res.length;
184 ptr = USB_ADD_BYTES(ptr, buf_res.length);
186 return (0); /* success */
190 /*------------------------------------------------------------------------*
191 * usbd_m_copy_in - copy a mbuf chain directly into DMA-able memory
192 *------------------------------------------------------------------------*/
194 struct usb_m_copy_in_arg {
195 struct usb_page_cache *cache;
196 usb_frlength_t dst_offset;
200 usbd_m_copy_in_cb(void *arg, void *src, uint32_t count)
202 register struct usb_m_copy_in_arg *ua = arg;
204 usbd_copy_in(ua->cache, ua->dst_offset, src, count);
205 ua->dst_offset += count;
210 usbd_m_copy_in(struct usb_page_cache *cache, usb_frlength_t dst_offset,
211 struct mbuf *m, usb_size_t src_offset, usb_frlength_t src_len)
213 struct usb_m_copy_in_arg arg = {cache, dst_offset};
216 error = m_apply(m, src_offset, src_len, &usbd_m_copy_in_cb, &arg);
220 /*------------------------------------------------------------------------*
221 * usb_uiomove - factored out code
222 *------------------------------------------------------------------------*/
225 usb_uiomove(struct usb_page_cache *pc, struct uio *uio,
226 usb_frlength_t pc_offset, usb_frlength_t len)
228 struct usb_page_search res;
233 usbd_get_page(pc, pc_offset, &res);
235 if (res.length > len) {
239 * "uiomove()" can sleep so one needs to make a wrapper,
240 * exiting the mutex and checking things
242 error = uiomove(res.buffer, res.length, uio);
247 pc_offset += res.length;
254 /*------------------------------------------------------------------------*
255 * usbd_copy_out - copy directly from DMA-able memory
256 *------------------------------------------------------------------------*/
258 usbd_copy_out(struct usb_page_cache *cache, usb_frlength_t offset,
259 void *ptr, usb_frlength_t len)
261 struct usb_page_search res;
265 usbd_get_page(cache, offset, &res);
267 if (res.length > len) {
270 memcpy(ptr, res.buffer, res.length);
272 offset += res.length;
274 ptr = USB_ADD_BYTES(ptr, res.length);
278 /*------------------------------------------------------------------------*
279 * usbd_copy_out_user - copy directly from DMA-able memory to userland
284 *------------------------------------------------------------------------*/
287 usbd_copy_out_user(struct usb_page_cache *cache, usb_frlength_t offset,
288 void *ptr, usb_frlength_t len)
290 struct usb_page_search res;
295 usbd_get_page(cache, offset, &res);
297 if (res.length > len) {
300 error = copyout(res.buffer, ptr, res.length);
304 offset += res.length;
306 ptr = USB_ADD_BYTES(ptr, res.length);
308 return (0); /* success */
312 /*------------------------------------------------------------------------*
313 * usbd_frame_zero - zero DMA-able memory
314 *------------------------------------------------------------------------*/
316 usbd_frame_zero(struct usb_page_cache *cache, usb_frlength_t offset,
319 struct usb_page_search res;
323 usbd_get_page(cache, offset, &res);
325 if (res.length > len) {
328 memset(res.buffer, 0, res.length);
330 offset += res.length;
337 /*------------------------------------------------------------------------*
338 * usb_dma_lock_cb - dummy callback
339 *------------------------------------------------------------------------*/
341 usb_dma_lock_cb(void *arg, bus_dma_lock_op_t op)
343 /* we use "mtx_owned()" instead of this function */
346 /*------------------------------------------------------------------------*
347 * usb_dma_tag_create - allocate a DMA tag
349 * NOTE: If the "align" parameter has a value of 1 the DMA-tag will
350 * allow multi-segment mappings. Else all mappings are single-segment.
351 *------------------------------------------------------------------------*/
353 usb_dma_tag_create(struct usb_dma_tag *udt,
354 usb_size_t size, usb_size_t align)
358 if (bus_dma_tag_create
359 ( /* parent */ udt->tag_parent->tag,
360 /* alignment */ align,
362 /* lowaddr */ (2ULL << (udt->tag_parent->dma_bits - 1)) - 1,
363 /* highaddr */ BUS_SPACE_MAXADDR,
365 /* filterarg */ NULL,
367 /* nsegments */ (align == 1 && size > 1) ?
368 (2 + (size / USB_PAGE_SIZE)) : 1,
369 /* maxsegsz */ (align == 1 && size > USB_PAGE_SIZE) ?
370 USB_PAGE_SIZE : size,
371 /* flags */ BUS_DMA_KEEP_PG_OFFSET,
372 /* lockfn */ &usb_dma_lock_cb,
380 /*------------------------------------------------------------------------*
381 * usb_dma_tag_free - free a DMA tag
382 *------------------------------------------------------------------------*/
384 usb_dma_tag_destroy(struct usb_dma_tag *udt)
386 bus_dma_tag_destroy(udt->tag);
389 /*------------------------------------------------------------------------*
390 * usb_pc_alloc_mem_cb - BUS-DMA callback function
391 *------------------------------------------------------------------------*/
393 usb_pc_alloc_mem_cb(void *arg, bus_dma_segment_t *segs,
396 usb_pc_common_mem_cb(arg, segs, nseg, error, 0);
399 /*------------------------------------------------------------------------*
400 * usb_pc_load_mem_cb - BUS-DMA callback function
401 *------------------------------------------------------------------------*/
403 usb_pc_load_mem_cb(void *arg, bus_dma_segment_t *segs,
406 usb_pc_common_mem_cb(arg, segs, nseg, error, 1);
409 /*------------------------------------------------------------------------*
410 * usb_pc_common_mem_cb - BUS-DMA callback function
411 *------------------------------------------------------------------------*/
413 usb_pc_common_mem_cb(void *arg, bus_dma_segment_t *segs,
414 int nseg, int error, uint8_t isload)
416 struct usb_dma_parent_tag *uptag;
417 struct usb_page_cache *pc;
424 uptag = pc->tag_parent;
427 * XXX There is sometimes recursive locking here.
428 * XXX We should try to find a better solution.
429 * XXX Until further the "owned" variable does
439 pg->physaddr = segs->ds_addr & ~(USB_PAGE_SIZE - 1);
440 rem = segs->ds_addr & (USB_PAGE_SIZE - 1);
441 pc->page_offset_buf = rem;
442 pc->page_offset_end += rem;
445 if (rem != (USB_P2U(pc->buffer) & (USB_PAGE_SIZE - 1))) {
447 * This check verifies that the physical address is correct:
449 DPRINTFN(0, "Page offset was not preserved\n");
455 off += USB_PAGE_SIZE;
456 if (off >= (segs->ds_len + rem)) {
464 pg->physaddr = (segs->ds_addr + off) & ~(USB_PAGE_SIZE - 1);
468 owned = mtx_owned(uptag->mtx);
470 mtx_lock(uptag->mtx);
472 uptag->dma_error = (error ? 1 : 0);
474 (uptag->func) (uptag);
476 cv_broadcast(uptag->cv);
479 mtx_unlock(uptag->mtx);
482 /*------------------------------------------------------------------------*
483 * usb_pc_alloc_mem - allocate DMA'able memory
488 *------------------------------------------------------------------------*/
490 usb_pc_alloc_mem(struct usb_page_cache *pc, struct usb_page *pg,
491 usb_size_t size, usb_size_t align)
493 struct usb_dma_parent_tag *uptag;
494 struct usb_dma_tag *utag;
499 uptag = pc->tag_parent;
503 * The alignment must be greater or equal to the
504 * "size" else the object can be split between two
505 * memory pages and we get a problem!
507 while (align < size) {
515 * XXX BUS-DMA workaround - FIXME later:
517 * We assume that that the aligment at this point of
518 * the code is greater than or equal to the size and
519 * less than two times the size, so that if we double
520 * the size, the size will be greater than the
523 * The bus-dma system has a check for "alignment"
524 * being less than "size". If that check fails we end
525 * up using contigmalloc which is page based even for
526 * small allocations. Try to avoid that to save
527 * memory, hence we sometimes to a large number of
530 if (size <= (USB_PAGE_SIZE / 2)) {
535 /* get the correct DMA tag */
536 utag = usb_dma_tag_find(uptag, size, align);
540 /* allocate memory */
541 if (bus_dmamem_alloc(
542 utag->tag, &ptr, (BUS_DMA_WAITOK | BUS_DMA_COHERENT), &map)) {
545 /* setup page cache */
548 pc->page_offset_buf = 0;
549 pc->page_offset_end = size;
552 pc->ismultiseg = (align == 1);
554 mtx_lock(uptag->mtx);
556 /* load memory into DMA */
557 err = bus_dmamap_load(
558 utag->tag, map, ptr, size, &usb_pc_alloc_mem_cb,
559 pc, (BUS_DMA_WAITOK | BUS_DMA_COHERENT));
561 if (err == EINPROGRESS) {
562 cv_wait(uptag->cv, uptag->mtx);
565 mtx_unlock(uptag->mtx);
567 if (err || uptag->dma_error) {
568 bus_dmamem_free(utag->tag, ptr, map);
571 memset(ptr, 0, size);
573 usb_pc_cpu_flush(pc);
578 /* reset most of the page cache */
580 pc->page_start = NULL;
581 pc->page_offset_buf = 0;
582 pc->page_offset_end = 0;
588 /*------------------------------------------------------------------------*
589 * usb_pc_free_mem - free DMA memory
591 * This function is NULL safe.
592 *------------------------------------------------------------------------*/
594 usb_pc_free_mem(struct usb_page_cache *pc)
596 if (pc && pc->buffer) {
598 bus_dmamap_unload(pc->tag, pc->map);
600 bus_dmamem_free(pc->tag, pc->buffer, pc->map);
606 /*------------------------------------------------------------------------*
607 * usb_pc_load_mem - load virtual memory into DMA
612 *------------------------------------------------------------------------*/
614 usb_pc_load_mem(struct usb_page_cache *pc, usb_size_t size, uint8_t sync)
616 /* setup page cache */
617 pc->page_offset_buf = 0;
618 pc->page_offset_end = size;
621 mtx_assert(pc->tag_parent->mtx, MA_OWNED);
625 struct usb_dma_parent_tag *uptag;
628 uptag = pc->tag_parent;
631 * We have to unload the previous loaded DMA
632 * pages before trying to load a new one!
634 bus_dmamap_unload(pc->tag, pc->map);
637 * Try to load memory into DMA.
639 err = bus_dmamap_load(
640 pc->tag, pc->map, pc->buffer, size,
641 &usb_pc_alloc_mem_cb, pc, BUS_DMA_WAITOK);
642 if (err == EINPROGRESS) {
643 cv_wait(uptag->cv, uptag->mtx);
646 if (err || uptag->dma_error) {
652 * We have to unload the previous loaded DMA
653 * pages before trying to load a new one!
655 bus_dmamap_unload(pc->tag, pc->map);
658 * Try to load memory into DMA. The callback
659 * will be called in all cases:
662 pc->tag, pc->map, pc->buffer, size,
663 &usb_pc_load_mem_cb, pc, BUS_DMA_WAITOK)) {
669 * Call callback so that refcount is decremented
672 pc->tag_parent->dma_error = 0;
673 (pc->tag_parent->func) (pc->tag_parent);
679 /*------------------------------------------------------------------------*
680 * usb_pc_cpu_invalidate - invalidate CPU cache
681 *------------------------------------------------------------------------*/
683 usb_pc_cpu_invalidate(struct usb_page_cache *pc)
685 if (pc->page_offset_end == pc->page_offset_buf) {
686 /* nothing has been loaded into this page cache! */
691 * TODO: We currently do XXX_POSTREAD and XXX_PREREAD at the
692 * same time, but in the future we should try to isolate the
693 * different cases to optimise the code. --HPS
695 bus_dmamap_sync(pc->tag, pc->map, BUS_DMASYNC_POSTREAD);
696 bus_dmamap_sync(pc->tag, pc->map, BUS_DMASYNC_PREREAD);
699 /*------------------------------------------------------------------------*
700 * usb_pc_cpu_flush - flush CPU cache
701 *------------------------------------------------------------------------*/
703 usb_pc_cpu_flush(struct usb_page_cache *pc)
705 if (pc->page_offset_end == pc->page_offset_buf) {
706 /* nothing has been loaded into this page cache! */
709 bus_dmamap_sync(pc->tag, pc->map, BUS_DMASYNC_PREWRITE);
712 /*------------------------------------------------------------------------*
713 * usb_pc_dmamap_create - create a DMA map
718 *------------------------------------------------------------------------*/
720 usb_pc_dmamap_create(struct usb_page_cache *pc, usb_size_t size)
722 struct usb_xfer_root *info;
723 struct usb_dma_tag *utag;
726 info = USB_DMATAG_TO_XROOT(pc->tag_parent);
732 utag = usb_dma_tag_find(pc->tag_parent, size, 1);
737 if (bus_dmamap_create(utag->tag, 0, &pc->map)) {
741 return 0; /* success */
746 return 1; /* failure */
749 /*------------------------------------------------------------------------*
750 * usb_pc_dmamap_destroy
752 * This function is NULL safe.
753 *------------------------------------------------------------------------*/
755 usb_pc_dmamap_destroy(struct usb_page_cache *pc)
758 bus_dmamap_destroy(pc->tag, pc->map);
764 /*------------------------------------------------------------------------*
765 * usb_dma_tag_find - factored out code
766 *------------------------------------------------------------------------*/
768 usb_dma_tag_find(struct usb_dma_parent_tag *udpt,
769 usb_size_t size, usb_size_t align)
771 struct usb_dma_tag *udt;
774 USB_ASSERT(align > 0, ("Invalid parameter align = 0\n"));
775 USB_ASSERT(size > 0, ("Invalid parameter size = 0\n"));
777 udt = udpt->utag_first;
778 nudt = udpt->utag_max;
782 if (udt->align == 0) {
783 usb_dma_tag_create(udt, size, align);
784 if (udt->tag == NULL) {
791 if ((udt->align == align) && (udt->size == size)) {
799 /*------------------------------------------------------------------------*
800 * usb_dma_tag_setup - initialise USB DMA tags
801 *------------------------------------------------------------------------*/
803 usb_dma_tag_setup(struct usb_dma_parent_tag *udpt,
804 struct usb_dma_tag *udt, bus_dma_tag_t dmat,
805 struct mtx *mtx, usb_dma_callback_t *func,
806 uint8_t ndmabits, uint8_t nudt)
808 memset(udpt, 0, sizeof(*udpt));
810 /* sanity checking */
814 /* something is corrupt */
817 /* initialise condition variable */
818 cv_init(udpt->cv, "USB DMA CV");
820 /* store some information */
824 udpt->utag_first = udt;
825 udpt->utag_max = nudt;
826 udpt->dma_bits = ndmabits;
829 memset(udt, 0, sizeof(*udt));
830 udt->tag_parent = udpt;
835 /*------------------------------------------------------------------------*
836 * usb_bus_tag_unsetup - factored out code
837 *------------------------------------------------------------------------*/
839 usb_dma_tag_unsetup(struct usb_dma_parent_tag *udpt)
841 struct usb_dma_tag *udt;
844 udt = udpt->utag_first;
845 nudt = udpt->utag_max;
850 /* destroy the USB DMA tag */
851 usb_dma_tag_destroy(udt);
857 if (udpt->utag_max) {
858 /* destroy the condition variable */
859 cv_destroy(udpt->cv);
863 /*------------------------------------------------------------------------*
866 * This function handles loading of virtual buffers into DMA and is
867 * only called when "dma_refcount" is zero.
868 *------------------------------------------------------------------------*/
870 usb_bdma_work_loop(struct usb_xfer_queue *pq)
872 struct usb_xfer_root *info;
873 struct usb_xfer *xfer;
874 usb_frcount_t nframes;
879 mtx_assert(info->xfer_mtx, MA_OWNED);
882 /* some error happened */
883 USB_BUS_LOCK(info->bus);
884 usbd_transfer_done(xfer, 0);
885 USB_BUS_UNLOCK(info->bus);
888 if (!xfer->flags_int.bdma_setup) {
890 usb_frlength_t frlength_0;
893 xfer->flags_int.bdma_setup = 1;
895 /* reset BUS-DMA load state */
899 if (xfer->flags_int.isochronous_xfr) {
900 /* only one frame buffer */
902 frlength_0 = xfer->sumlen;
904 /* can be multiple frame buffers */
905 nframes = xfer->nframes;
906 frlength_0 = xfer->frlengths[0];
910 * Set DMA direction first. This is needed to
911 * select the correct cache invalidate and cache
914 isread = USB_GET_DATA_ISREAD(xfer);
915 pg = xfer->dma_page_ptr;
917 if (xfer->flags_int.control_xfr &&
918 xfer->flags_int.control_hdr) {
920 if (xfer->flags_int.usb_mode == USB_MODE_DEVICE) {
921 /* The device controller writes to memory */
922 xfer->frbuffers[0].isread = 1;
924 /* The host controller reads from memory */
925 xfer->frbuffers[0].isread = 0;
929 xfer->frbuffers[0].isread = isread;
933 * Setup the "page_start" pointer which points to an array of
934 * USB pages where information about the physical address of a
935 * page will be stored. Also initialise the "isread" field of
936 * the USB page caches.
938 xfer->frbuffers[0].page_start = pg;
940 info->dma_nframes = nframes;
941 info->dma_currframe = 0;
942 info->dma_frlength_0 = frlength_0;
944 pg += (frlength_0 / USB_PAGE_SIZE);
947 while (--nframes > 0) {
948 xfer->frbuffers[nframes].isread = isread;
949 xfer->frbuffers[nframes].page_start = pg;
951 pg += (xfer->frlengths[nframes] / USB_PAGE_SIZE);
956 if (info->dma_error) {
957 USB_BUS_LOCK(info->bus);
958 usbd_transfer_done(xfer, USB_ERR_DMA_LOAD_FAILED);
959 USB_BUS_UNLOCK(info->bus);
962 if (info->dma_currframe != info->dma_nframes) {
964 if (info->dma_currframe == 0) {
966 usb_pc_load_mem(xfer->frbuffers,
967 info->dma_frlength_0, 0);
970 nframes = info->dma_currframe;
971 usb_pc_load_mem(xfer->frbuffers + nframes,
972 xfer->frlengths[nframes], 0);
975 /* advance frame index */
976 info->dma_currframe++;
981 usb_bdma_pre_sync(xfer);
983 /* start loading next USB transfer, if any */
984 usb_command_wrapper(pq, NULL);
986 /* finally start the hardware */
987 usbd_pipe_enter(xfer);
990 /*------------------------------------------------------------------------*
991 * usb_bdma_done_event
993 * This function is called when the BUS-DMA has loaded virtual memory
995 *------------------------------------------------------------------------*/
997 usb_bdma_done_event(struct usb_dma_parent_tag *udpt)
999 struct usb_xfer_root *info;
1001 info = USB_DMATAG_TO_XROOT(udpt);
1003 mtx_assert(info->xfer_mtx, MA_OWNED);
1006 info->dma_error = udpt->dma_error;
1008 /* enter workloop again */
1009 usb_command_wrapper(&info->dma_q,
1013 /*------------------------------------------------------------------------*
1016 * This function handles DMA synchronisation that must be done before
1017 * an USB transfer is started.
1018 *------------------------------------------------------------------------*/
1020 usb_bdma_pre_sync(struct usb_xfer *xfer)
1022 struct usb_page_cache *pc;
1023 usb_frcount_t nframes;
1025 if (xfer->flags_int.isochronous_xfr) {
1026 /* only one frame buffer */
1029 /* can be multiple frame buffers */
1030 nframes = xfer->nframes;
1033 pc = xfer->frbuffers;
1038 usb_pc_cpu_invalidate(pc);
1040 usb_pc_cpu_flush(pc);
1046 /*------------------------------------------------------------------------*
1047 * usb_bdma_post_sync
1049 * This function handles DMA synchronisation that must be done after
1050 * an USB transfer is complete.
1051 *------------------------------------------------------------------------*/
1053 usb_bdma_post_sync(struct usb_xfer *xfer)
1055 struct usb_page_cache *pc;
1056 usb_frcount_t nframes;
1058 if (xfer->flags_int.isochronous_xfr) {
1059 /* only one frame buffer */
1062 /* can be multiple frame buffers */
1063 nframes = xfer->nframes;
1066 pc = xfer->frbuffers;
1070 usb_pc_cpu_invalidate(pc);