When calculating the number of bounce pages needed, round the maxsize
up to a multiple of PAGE_SIZE, and add one page because there can always be one more boundary crossing than the number of pages in the transfer.
This commit is contained in:
parent
5ac96cd6b7
commit
170337ca9d
@ -425,14 +425,21 @@ bus_dma_tag_create(bus_dma_tag_t parent, bus_size_t alignment,
|
||||
if (_bus_dma_can_bounce(newtag->lowaddr, newtag->highaddr)
|
||||
|| newtag->alignment > 1)
|
||||
newtag->flags |= BUS_DMA_COULD_BOUNCE;
|
||||
else
|
||||
maxsize = 2; /* Need at most 2 bounce pages for unaligned access on cache line boundaries */
|
||||
|
||||
/*
|
||||
* Any request can auto-bounce due to cacheline alignment, in addition
|
||||
* to any alignment or boundary specifications in the tag, so if the
|
||||
* ALLOCNOW flag is set, there's always work to do.
|
||||
*/
|
||||
if ((flags & BUS_DMA_ALLOCNOW) != 0) {
|
||||
struct bounce_zone *bz;
|
||||
|
||||
/* Must bounce */
|
||||
|
||||
/*
|
||||
* Round size up to a full page, and add one more page because
|
||||
* there can always be one more boundary crossing than the
|
||||
* number of pages in a transfer.
|
||||
*/
|
||||
maxsize = roundup2(maxsize, PAGE_SIZE) + PAGE_SIZE;
|
||||
|
||||
if ((error = alloc_bounce_zone(newtag)) != 0) {
|
||||
free(newtag, M_DEVBUF);
|
||||
return (error);
|
||||
@ -518,20 +525,22 @@ static int allocate_bz_and_pages(bus_dma_tag_t dmat, bus_dmamap_t mapp)
|
||||
STAILQ_INIT(&(mapp->bpages));
|
||||
|
||||
/*
|
||||
* Attempt to add pages to our pool on a per-instance
|
||||
* basis up to a sane limit.
|
||||
* Attempt to add pages to our pool on a per-instance basis up to a sane
|
||||
* limit. Even if the tag isn't flagged as COULD_BOUNCE due to
|
||||
* alignment and boundary constraints, it could still auto-bounce due to
|
||||
* cacheline alignment, which requires at most two bounce pages.
|
||||
*/
|
||||
if (dmat->flags & BUS_DMA_COULD_BOUNCE)
|
||||
maxpages = MAX_BPAGES;
|
||||
else
|
||||
maxpages = 2 * bz->map_count; /* Only need at most 2 pages for buffers unaligned on cache line boundaries */
|
||||
maxpages = 2 * bz->map_count;
|
||||
if ((dmat->flags & BUS_DMA_MIN_ALLOC_COMP) == 0
|
||||
|| (bz->map_count > 0 && bz->total_bpages < maxpages)) {
|
||||
int pages;
|
||||
|
||||
pages = MAX(atop(dmat->maxsize), 1);
|
||||
pages = atop(roundup2(dmat->maxsize, PAGE_SIZE)) + 1;
|
||||
pages = MIN(maxpages - bz->total_bpages, pages);
|
||||
pages = MAX(pages, 1);
|
||||
pages = MAX(pages, 2);
|
||||
if (alloc_bounce_pages(dmat, pages) < pages)
|
||||
return (ENOMEM);
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user