From patchwork Fri Aug 8 23:40:43 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Scott Wood X-Patchwork-Id: 378702 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [103.22.144.68]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id AA17514011B for ; Sat, 9 Aug 2014 09:42:37 +1000 (EST) Received: from ozlabs.org (ozlabs.org [103.22.144.67]) by lists.ozlabs.org (Postfix) with ESMTP id 86F5F1A0C0E for ; Sat, 9 Aug 2014 09:42:37 +1000 (EST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from na01-by2-obe.outbound.protection.outlook.com (mail-by2lp0239.outbound.protection.outlook.com [207.46.163.239]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id E73E11A0A6A for ; Sat, 9 Aug 2014 09:41:11 +1000 (EST) Received: from snotra.am.freescale.net (192.88.168.49) by BN1PR0301MB0723.namprd03.prod.outlook.com (25.160.78.142) with Microsoft SMTP Server (TLS) id 15.0.1005.10; Fri, 8 Aug 2014 23:40:56 +0000 From: Scott Wood To: Benjamin Herrenschmidt Subject: [PATCH 2/4] powerpc/64: Honor swiotlb limit in coherent allocations Date: Fri, 8 Aug 2014 18:40:43 -0500 Message-ID: <1407541245-27617-2-git-send-email-scottwood@freescale.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1407541245-27617-1-git-send-email-scottwood@freescale.com> References: <1407541245-27617-1-git-send-email-scottwood@freescale.com> MIME-Version: 1.0 X-Originating-IP: [192.88.168.49] X-ClientProxiedBy: BLUPR05CA0049.namprd05.prod.outlook.com (10.141.20.19) To BN1PR0301MB0723.namprd03.prod.outlook.com (25.160.78.142) X-Microsoft-Antispam: BCL:0;PCL:0;RULEID:;UriScan:; X-Forefront-PRVS: 02973C87BC X-Forefront-Antispam-Report: SFV:NSPM; SFS:(6009001)(199002)(189002)(50986999)(19580395003)(19580405001)(87286001)(83322001)(110136001)(66066001)(62966002)(74662001)(33646002)(76176999)(31966008)(74502001)(99396002)(85306004)(88136002)(89996001)(102836001)(46102001)(101416001)(104166001)(87976001)(76482001)(36756003)(79102001)(77982001)(77156001)(42186005)(86362001)(83072002)(92566001)(92726001)(85852003)(50466002)(48376002)(106356001)(81342001)(20776003)(81542001)(21056001)(4396001)(95666004)(64706001)(229853001)(47776003)(107046002)(80022001)(50226001)(105586002)(77096002)(93916002); DIR:OUT; SFP:; SCL:1; SRVR:BN1PR0301MB0723; H:snotra.am.freescale.net; FPR:; MLV:sfv; PTR:InfoNoRecords; MX:1; LANG:en; X-OriginatorOrg: freescale.com Cc: Scott Wood , linuxppc-dev@lists.ozlabs.org, Shaohui Xie X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" FSL PCI cannot directly address the whole lower 4 GiB due to conflicts with PCICSRBAR and outbound windows, and thus max_direct_dma_addr is less than 4GiB. Honor that limit in dma_direct_alloc_coherent(). Note that setting the DMA mask to 31 bits is not an option, since many PCI drivers would fail if we reject 32-bit DMA in dma_supported(), and we have no control over the setting of coherent_dma_mask if dma_supported() returns true. Signed-off-by: Scott Wood Cc: Shaohui Xie --- arch/powerpc/kernel/dma.c | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/arch/powerpc/kernel/dma.c b/arch/powerpc/kernel/dma.c index dfd99ef..a7b0156 100644 --- a/arch/powerpc/kernel/dma.c +++ b/arch/powerpc/kernel/dma.c @@ -15,6 +15,7 @@ #include #include #include +#include /* * Generic direct DMA implementation @@ -25,6 +26,18 @@ * default the offset is PCI_DRAM_OFFSET. */ +static u64 __maybe_unused get_pfn_limit(struct device *dev) +{ + u64 pfn = (dev->coherent_dma_mask >> PAGE_SHIFT) + 1; + struct dev_archdata __maybe_unused *sd = &dev->archdata; + +#ifdef CONFIG_SWIOTLB + if (sd->max_direct_dma_addr && sd->dma_ops == &swiotlb_dma_ops) + pfn = min_t(u64, pfn, sd->max_direct_dma_addr >> PAGE_SHIFT); +#endif + + return pfn; +} void *dma_direct_alloc_coherent(struct device *dev, size_t size, dma_addr_t *dma_handle, gfp_t flag, @@ -40,7 +53,7 @@ void *dma_direct_alloc_coherent(struct device *dev, size_t size, #else struct page *page; int node = dev_to_node(dev); - u64 pfn = (dev->coherent_dma_mask >> PAGE_SHIFT) + 1; + u64 pfn = get_pfn_limit(dev); int zone; zone = dma_pfn_limit_to_zone(pfn);