usb_busdma.c (184824) | usb_busdma.c (185087) |
---|---|
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 /* | 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 /* |
|
605 * Try to load memory into DMA. 606 */ 607 err = bus_dmamap_load( 608 pc->tag, pc->map, pc->buffer, size, 609 &usb2_pc_alloc_mem_cb, pc, BUS_DMA_WAITOK); 610 if (err == EINPROGRESS) { 611 usb2_cv_wait(uptag->cv, uptag->mtx); 612 err = 0; 613 } 614 if (err || uptag->dma_error) { 615 return (1); 616 } 617 } else { 618 619 /* | 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 /* |
|
620 * Try to load memory into DMA. The callback 621 * will be called in all cases: 622 */ 623 if (bus_dmamap_load( 624 pc->tag, pc->map, pc->buffer, size, 625 &usb2_pc_load_mem_cb, pc, BUS_DMA_WAITOK)) { 626 } 627 } --- 11 unchanged lines hidden (view full) --- 639} 640 641/*------------------------------------------------------------------------* 642 * usb2_pc_cpu_invalidate - invalidate CPU cache 643 *------------------------------------------------------------------------*/ 644void 645usb2_pc_cpu_invalidate(struct usb2_page_cache *pc) 646{ | 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 } |
|
647 bus_dmamap_sync(pc->tag, pc->map, 648 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 649 return; 650} 651 652/*------------------------------------------------------------------------* 653 * usb2_pc_cpu_flush - flush CPU cache 654 *------------------------------------------------------------------------*/ 655void 656usb2_pc_cpu_flush(struct usb2_page_cache *pc) 657{ | 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 } |
|
658 bus_dmamap_sync(pc->tag, pc->map, 659 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 660 return; 661} 662 663/*------------------------------------------------------------------------* 664 * usb2_pc_dmamap_create - create a DMA map 665 * --- 287 unchanged lines hidden (view full) --- 953 954 /* setup page cache */ 955 pc->page_offset_buf = 0; 956 pc->page_offset_end = size; 957 pc->ismultiseg = 1; 958 959 if (size > 0) { 960 | 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 |
|
961 /* try to load memory into DMA using using no wait option */ 962 if (bus_dmamap_load(pc->tag, pc->map, pc->buffer, 963 size, NULL, BUS_DMA_NOWAIT)) { 964 error = ENOMEM; 965 } else { 966 error = 0; 967 } 968 --- 21 unchanged lines hidden (view full) --- 990 *------------------------------------------------------------------------*/ 991void 992usb2_pc_cpu_invalidate(struct usb2_page_cache *pc) 993{ 994 uint32_t len; 995 996 len = pc->page_offset_end - pc->page_offset_buf; 997 | 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 } |
|
998 bus_dmamap_sync(pc->tag, pc->map, 0, len, 999 BUS_DMASYNC_POSTWRITE | BUS_DMASYNC_POSTREAD); 1000 return; 1001} 1002 1003/*------------------------------------------------------------------------* 1004 * usb2_pc_cpu_flush - flush CPU cache 1005 *------------------------------------------------------------------------*/ 1006void 1007usb2_pc_cpu_flush(struct usb2_page_cache *pc) 1008{ 1009 uint32_t len; 1010 1011 len = pc->page_offset_end - pc->page_offset_buf; 1012 | 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 } |
|
1013 bus_dmamap_sync(pc->tag, pc->map, 0, len, 1014 BUS_DMASYNC_PREWRITE | BUS_DMASYNC_PREREAD); 1015 return; 1016} 1017 1018/*------------------------------------------------------------------------* 1019 * usb2_pc_dmamap_create - create a DMA map 1020 * --- 332 unchanged lines hidden (view full) --- 1353 /* can be multiple frame buffers */ 1354 nframes = xfer->nframes; 1355 } 1356 1357 pc = xfer->frbuffers; 1358 1359 while (nframes--) { 1360 | 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); |
1367 } 1368 pc++; 1369 } 1370 1371 return; 1372} 1373 1374/*------------------------------------------------------------------------* --- 14 unchanged lines hidden (view full) --- 1389 } else { 1390 /* can be multiple frame buffers */ 1391 nframes = xfer->nframes; 1392 } 1393 1394 pc = xfer->frbuffers; 1395 1396 while (nframes--) { | 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); |
1402 } 1403 pc++; 1404 } 1405 return; 1406} | 1431 } 1432 pc++; 1433 } 1434 return; 1435} |