busdma_machdep-v6.c (254229) | busdma_machdep-v6.c (256637) |
---|---|
1/*- 2 * Copyright (c) 2012 Ian Lepore 3 * Copyright (c) 2010 Mark Tinguely 4 * Copyright (c) 2004 Olivier Houchard 5 * Copyright (c) 2002 Peter Grehan 6 * Copyright (c) 1997, 1998 Justin T. Gibbs. 7 * All rights reserved. 8 * --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * From i386/busdma_machdep.c 191438 2009-04-23 20:24:19Z jhb 31 */ 32 33#include <sys/cdefs.h> | 1/*- 2 * Copyright (c) 2012 Ian Lepore 3 * Copyright (c) 2010 Mark Tinguely 4 * Copyright (c) 2004 Olivier Houchard 5 * Copyright (c) 2002 Peter Grehan 6 * Copyright (c) 1997, 1998 Justin T. Gibbs. 7 * All rights reserved. 8 * --- 17 unchanged lines hidden (view full) --- 26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 28 * SUCH DAMAGE. 29 * 30 * From i386/busdma_machdep.c 191438 2009-04-23 20:24:19Z jhb 31 */ 32 33#include <sys/cdefs.h> |
34__FBSDID("$FreeBSD: head/sys/arm/arm/busdma_machdep-v6.c 254229 2013-08-11 21:21:02Z cognet $"); | 34__FBSDID("$FreeBSD: head/sys/arm/arm/busdma_machdep-v6.c 256637 2013-10-16 16:32:35Z ian $"); |
35 36#define _ARM32_BUS_DMA_PRIVATE 37#include <sys/param.h> 38#include <sys/kdb.h> 39#include <ddb/ddb.h> 40#include <ddb/db_output.h> 41#include <sys/systm.h> 42#include <sys/malloc.h> --- 377 unchanged lines hidden (view full) --- 420 } 421 if (newtag->parent != NULL) 422 atomic_add_int(&parent->ref_count, 1); 423 } 424 425 if (_bus_dma_can_bounce(newtag->lowaddr, newtag->highaddr) 426 || newtag->alignment > 1) 427 newtag->flags |= BUS_DMA_COULD_BOUNCE; | 35 36#define _ARM32_BUS_DMA_PRIVATE 37#include <sys/param.h> 38#include <sys/kdb.h> 39#include <ddb/ddb.h> 40#include <ddb/db_output.h> 41#include <sys/systm.h> 42#include <sys/malloc.h> --- 377 unchanged lines hidden (view full) --- 420 } 421 if (newtag->parent != NULL) 422 atomic_add_int(&parent->ref_count, 1); 423 } 424 425 if (_bus_dma_can_bounce(newtag->lowaddr, newtag->highaddr) 426 || newtag->alignment > 1) 427 newtag->flags |= BUS_DMA_COULD_BOUNCE; |
428 else 429 maxsize = 2; /* Need at most 2 bounce pages for unaligned access on cache line boundaries */ | |
430 | 428 |
429 /* 430 * Any request can auto-bounce due to cacheline alignment, in addition 431 * to any alignment or boundary specifications in the tag, so if the 432 * ALLOCNOW flag is set, there's always work to do. 433 */ |
|
431 if ((flags & BUS_DMA_ALLOCNOW) != 0) { 432 struct bounce_zone *bz; | 434 if ((flags & BUS_DMA_ALLOCNOW) != 0) { 435 struct bounce_zone *bz; |
433 434 /* Must bounce */ 435 | 436 /* 437 * Round size up to a full page, and add one more page because 438 * there can always be one more boundary crossing than the 439 * number of pages in a transfer. 440 */ 441 maxsize = roundup2(maxsize, PAGE_SIZE) + PAGE_SIZE; 442 |
436 if ((error = alloc_bounce_zone(newtag)) != 0) { 437 free(newtag, M_DEVBUF); 438 return (error); 439 } 440 bz = newtag->bounce_zone; 441 442 if (ptoa(bz->total_bpages) < maxsize) { 443 int pages; --- 69 unchanged lines hidden (view full) --- 513 if (dmat->bounce_zone == NULL) 514 if ((error = alloc_bounce_zone(dmat)) != 0) 515 return (error); 516 bz = dmat->bounce_zone; 517 /* Initialize the new map */ 518 STAILQ_INIT(&(mapp->bpages)); 519 520 /* | 443 if ((error = alloc_bounce_zone(newtag)) != 0) { 444 free(newtag, M_DEVBUF); 445 return (error); 446 } 447 bz = newtag->bounce_zone; 448 449 if (ptoa(bz->total_bpages) < maxsize) { 450 int pages; --- 69 unchanged lines hidden (view full) --- 520 if (dmat->bounce_zone == NULL) 521 if ((error = alloc_bounce_zone(dmat)) != 0) 522 return (error); 523 bz = dmat->bounce_zone; 524 /* Initialize the new map */ 525 STAILQ_INIT(&(mapp->bpages)); 526 527 /* |
521 * Attempt to add pages to our pool on a per-instance 522 * basis up to a sane limit. | 528 * Attempt to add pages to our pool on a per-instance basis up to a sane 529 * limit. Even if the tag isn't flagged as COULD_BOUNCE due to 530 * alignment and boundary constraints, it could still auto-bounce due to 531 * cacheline alignment, which requires at most two bounce pages. |
523 */ 524 if (dmat->flags & BUS_DMA_COULD_BOUNCE) 525 maxpages = MAX_BPAGES; 526 else | 532 */ 533 if (dmat->flags & BUS_DMA_COULD_BOUNCE) 534 maxpages = MAX_BPAGES; 535 else |
527 maxpages = 2 * bz->map_count; /* Only need at most 2 pages for buffers unaligned on cache line boundaries */ | 536 maxpages = 2 * bz->map_count; |
528 if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 529 || (bz->map_count > 0 && bz->total_bpages < maxpages)) { 530 int pages; 531 | 537 if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0 538 || (bz->map_count > 0 && bz->total_bpages < maxpages)) { 539 int pages; 540 |
532 pages = MAX(atop(dmat->maxsize), 1); | 541 pages = atop(roundup2(dmat->maxsize, PAGE_SIZE)) + 1; |
533 pages = MIN(maxpages - bz->total_bpages, pages); | 542 pages = MIN(maxpages - bz->total_bpages, pages); |
534 pages = MAX(pages, 1); | 543 pages = MAX(pages, 2); |
535 if (alloc_bounce_pages(dmat, pages) < pages) 536 return (ENOMEM); 537 538 if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0) 539 dmat->flags |= BUS_DMA_MIN_ALLOC_COMP; 540 } 541 bz->map_count++; 542 return (0); --- 991 unchanged lines hidden --- | 544 if (alloc_bounce_pages(dmat, pages) < pages) 545 return (ENOMEM); 546 547 if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0) 548 dmat->flags |= BUS_DMA_MIN_ALLOC_COMP; 549 } 550 bz->map_count++; 551 return (0); --- 991 unchanged lines hidden --- |