From owner-svn-src-all@FreeBSD.ORG Wed Oct 16 16:32:36 2013 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTP id 20A94C8A; Wed, 16 Oct 2013 16:32:36 +0000 (UTC) (envelope-from ian@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mx1.freebsd.org (Postfix) with ESMTPS id E71422A7E; Wed, 16 Oct 2013 16:32:35 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id r9GGWZ7a031117; Wed, 16 Oct 2013 16:32:35 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.7/8.14.5/Submit) id r9GGWZmC031116; Wed, 16 Oct 2013 16:32:35 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201310161632.r9GGWZmC031116@svn.freebsd.org> From: Ian Lepore Date: Wed, 16 Oct 2013 16:32:35 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r256637 - head/sys/arm/arm X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 16 Oct 2013 16:32:36 -0000 Author: ian Date: Wed Oct 16 16:32:35 2013 New Revision: 256637 URL: http://svnweb.freebsd.org/changeset/base/256637 Log: 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. Modified: head/sys/arm/arm/busdma_machdep-v6.c Modified: head/sys/arm/arm/busdma_machdep-v6.c ============================================================================== --- head/sys/arm/arm/busdma_machdep-v6.c Wed Oct 16 16:05:49 2013 (r256636) +++ head/sys/arm/arm/busdma_machdep-v6.c Wed Oct 16 16:32:35 2013 (r256637) @@ -425,14 +425,21 @@ bus_dma_tag_create(bus_dma_tag_t parent, 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 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);