summaryrefslogtreecommitdiffstats
path: root/sys/arm
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2013-12-13 16:38:21 +0000
committerian <ian@FreeBSD.org>2013-12-13 16:38:21 +0000
commit39a72e06bfca1f79c9a07d23d75fda9755f372e9 (patch)
treee9d363a3cee2c11d5d37b613ad25f00d9e563994 /sys/arm
parentf6a96c9d56d8e49f7ed1ccf733620a6d8fb0d451 (diff)
downloadFreeBSD-src-39a72e06bfca1f79c9a07d23d75fda9755f372e9.zip
FreeBSD-src-39a72e06bfca1f79c9a07d23d75fda9755f372e9.tar.gz
MFC r256637:
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.
Diffstat (limited to 'sys/arm')
-rw-r--r--sys/arm/arm/busdma_machdep-v6.c29
1 files changed, 19 insertions, 10 deletions
diff --git a/sys/arm/arm/busdma_machdep-v6.c b/sys/arm/arm/busdma_machdep-v6.c
index b4f4110..15329ac 100644
--- a/sys/arm/arm/busdma_machdep-v6.c
+++ b/sys/arm/arm/busdma_machdep-v6.c
@@ -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);
OpenPOWER on IntegriCloud