Deleted Added
full compact
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_busdma.c 184824 2008-11-10 20:54:31Z thompsa $ */
1/* $FreeBSD: head/sys/dev/usb2/core/usb2_busdma.c 185087 2008-11-19 08:56:35Z alfred $ */
2/*-
3 * Copyright (c) 2008 Hans Petter Selasky. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 587 unchanged lines hidden (view full) ---

597 if (size > 0) {
598 if (sync) {
599 struct usb2_dma_parent_tag *uptag;
600 int err;
601
602 uptag = pc->tag_parent;
603
604 /*
605 * We have to unload the previous loaded DMA
606 * pages before trying to load a new one!
607 */
608 bus_dmamap_unload(pc->tag, pc->map);
609
610 /*
611 * Try to load memory into DMA.
612 */
613 err = bus_dmamap_load(
614 pc->tag, pc->map, pc->buffer, size,
615 &usb2_pc_alloc_mem_cb, pc, BUS_DMA_WAITOK);
616 if (err == EINPROGRESS) {
617 usb2_cv_wait(uptag->cv, uptag->mtx);
618 err = 0;
619 }
620 if (err || uptag->dma_error) {
621 return (1);
622 }
623 } else {
624
625 /*
626 * We have to unload the previous loaded DMA
627 * pages before trying to load a new one!
628 */
629 bus_dmamap_unload(pc->tag, pc->map);
630
631 /*
632 * Try to load memory into DMA. The callback
633 * will be called in all cases:
634 */
635 if (bus_dmamap_load(
636 pc->tag, pc->map, pc->buffer, size,
637 &usb2_pc_load_mem_cb, pc, BUS_DMA_WAITOK)) {
638 }
639 }

--- 11 unchanged lines hidden (view full) ---

651}
652
653/*------------------------------------------------------------------------*
654 * usb2_pc_cpu_invalidate - invalidate CPU cache
655 *------------------------------------------------------------------------*/
656void
657usb2_pc_cpu_invalidate(struct usb2_page_cache *pc)
658{
659 if (pc->page_offset_end == pc->page_offset_buf) {
660 /* nothing has been loaded into this page cache! */
661 return;
662 }
663 bus_dmamap_sync(pc->tag, pc->map,
664 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
665 return;
666}
667
668/*------------------------------------------------------------------------*
669 * usb2_pc_cpu_flush - flush CPU cache
670 *------------------------------------------------------------------------*/
671void
672usb2_pc_cpu_flush(struct usb2_page_cache *pc)
673{
674 if (pc->page_offset_end == pc->page_offset_buf) {
675 /* nothing has been loaded into this page cache! */
676 return;
677 }
678 bus_dmamap_sync(pc->tag, pc->map,
679 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
680 return;
681}
682
683/*------------------------------------------------------------------------*
684 * usb2_pc_dmamap_create - create a DMA map
685 *

--- 287 unchanged lines hidden (view full) ---

973
974 /* setup page cache */
975 pc->page_offset_buf = 0;
976 pc->page_offset_end = size;
977 pc->ismultiseg = 1;
978
979 if (size > 0) {
980
981 /*
982 * We have to unload the previous loaded DMA
983 * pages before trying to load a new one!
984 */
985 bus_dmamap_unload(pc->tag, pc->map);
986
987 /* try to load memory into DMA using using no wait option */
988 if (bus_dmamap_load(pc->tag, pc->map, pc->buffer,
989 size, NULL, BUS_DMA_NOWAIT)) {
990 error = ENOMEM;
991 } else {
992 error = 0;
993 }
994

--- 21 unchanged lines hidden (view full) ---

1016 *------------------------------------------------------------------------*/
1017void
1018usb2_pc_cpu_invalidate(struct usb2_page_cache *pc)
1019{
1020 uint32_t len;
1021
1022 len = pc->page_offset_end - pc->page_offset_buf;
1023
1024 if (len == 0) {
1025 /* nothing has been loaded into this page cache */
1026 return;
1027 }
1028 bus_dmamap_sync(pc->tag, pc->map, 0, len,
1029 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD);
1030 return;
1031}
1032
1033/*------------------------------------------------------------------------*
1034 * usb2_pc_cpu_flush - flush CPU cache
1035 *------------------------------------------------------------------------*/
1036void
1037usb2_pc_cpu_flush(struct usb2_page_cache *pc)
1038{
1039 uint32_t len;
1040
1041 len = pc->page_offset_end - pc->page_offset_buf;
1042
1043 if (len == 0) {
1044 /* nothing has been loaded into this page cache */
1045 return;
1046 }
1047 bus_dmamap_sync(pc->tag, pc->map, 0, len,
1048 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD);
1049 return;
1050}
1051
1052/*------------------------------------------------------------------------*
1053 * usb2_pc_dmamap_create - create a DMA map
1054 *

--- 332 unchanged lines hidden (view full) ---

1387 /* can be multiple frame buffers */
1388 nframes = xfer->nframes;
1389 }
1390
1391 pc = xfer->frbuffers;
1392
1393 while (nframes--) {
1394
1361 if (pc->page_offset_buf != pc->page_offset_end) {
1362 if (pc->isread) {
1363 usb2_pc_cpu_invalidate(pc);
1364 } else {
1365 usb2_pc_cpu_flush(pc);
1366 }
1395 if (pc->isread) {
1396 usb2_pc_cpu_invalidate(pc);
1397 } else {
1398 usb2_pc_cpu_flush(pc);
1399 }
1400 pc++;
1401 }
1402
1403 return;
1404}
1405
1406/*------------------------------------------------------------------------*

--- 14 unchanged lines hidden (view full) ---

1421 } else {
1422 /* can be multiple frame buffers */
1423 nframes = xfer->nframes;
1424 }
1425
1426 pc = xfer->frbuffers;
1427
1428 while (nframes--) {
1397
1398 if (pc->page_offset_buf != pc->page_offset_end) {
1399 if (pc->isread) {
1400 usb2_pc_cpu_invalidate(pc);
1401 }
1429 if (pc->isread) {
1430 usb2_pc_cpu_invalidate(pc);
1431 }
1432 pc++;
1433 }
1434 return;
1435}