From owner-svn-src-all@FreeBSD.ORG Fri Dec 13 16:38:22 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 ESMTPS id 902A1A90; Fri, 13 Dec 2013 16:38:22 +0000 (UTC) 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 5D77F175D; Fri, 13 Dec 2013 16:38:22 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.7/8.14.7) with ESMTP id rBDGcMJR024077; Fri, 13 Dec 2013 16:38:22 GMT (envelope-from ian@svn.freebsd.org) Received: (from ian@localhost) by svn.freebsd.org (8.14.7/8.14.7/Submit) id rBDGcMC1024076; Fri, 13 Dec 2013 16:38:22 GMT (envelope-from ian@svn.freebsd.org) Message-Id: <201312131638.rBDGcMC1024076@svn.freebsd.org> From: Ian Lepore Date: Fri, 13 Dec 2013 16:38:22 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r259309 - stable/10/sys/arm/arm X-SVN-Group: stable-10 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.17 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: Fri, 13 Dec 2013 16:38:22 -0000 Author: ian Date: Fri Dec 13 16:38:21 2013 New Revision: 259309 URL: http://svnweb.freebsd.org/changeset/base/259309 Log: 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. Modified: stable/10/sys/arm/arm/busdma_machdep-v6.c Directory Properties: stable/10/ (props changed) Modified: stable/10/sys/arm/arm/busdma_machdep-v6.c ============================================================================== --- stable/10/sys/arm/arm/busdma_machdep-v6.c Fri Dec 13 16:14:08 2013 (r259308) +++ stable/10/sys/arm/arm/busdma_machdep-v6.c Fri Dec 13 16:38:21 2013 (r259309) @@ -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);