From patchwork Fri Mar 18 15:00:21 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 8621241 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A38F09F44D for ; Fri, 18 Mar 2016 15:10:37 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 8997F202E9 for ; Fri, 18 Mar 2016 15:10:36 +0000 (UTC) Received: from bombadil.infradead.org (unknown [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 847EE20220 for ; Fri, 18 Mar 2016 15:10:35 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1agvtW-0004V6-8Q; Fri, 18 Mar 2016 15:00:54 +0000 Received: from smtp.codeaurora.org ([198.145.29.96]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1agvtR-0004FY-2n for linux-arm-kernel@lists.infradead.org; Fri, 18 Mar 2016 15:00:50 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 3C58861243; Fri, 18 Mar 2016 15:00:28 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 2641F605F8; Fri, 18 Mar 2016 15:00:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Spam-Level: X-Spam-Status: No, score=-3.4 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, RDNS_NONE,UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 Received: from [10.228.68.107] (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id 2384760269; Fri, 18 Mar 2016 15:00:22 +0000 (UTC) Subject: Re: [PATCH 2/3] swiotlb: prefix dma_to_phys and phys_to_dma functions To: Robin Murphy , linux-arm-kernel@lists.infradead.org, timur@codeaurora.org, cov@codeaurora.org, nwatters@codeaurora.org References: <1458252137-24497-1-git-send-email-okaya@codeaurora.org> <1458252137-24497-2-git-send-email-okaya@codeaurora.org> <56EBF09A.1060503@arm.com> From: Sinan Kaya Message-ID: <56EC1805.5060207@codeaurora.org> Date: Fri, 18 Mar 2016 11:00:21 -0400 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.0 MIME-Version: 1.0 In-Reply-To: <56EBF09A.1060503@arm.com> X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160318_080049_314386_4F488827 X-CRM114-Status: GOOD ( 19.08 ) X-Spam-Score: -1.9 (-) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-mips@linux-mips.org, linux-ia64@vger.kernel.org, Fenghua Yu , Catalin Marinas , Will Deacon , Max Filippov , Chris Metcalf , Paul Mackerras , "H. Peter Anvin" , Huacai Chen , Guan Xuetao , Marek Szyprowski , Jisheng Zhang , Florian Fainelli , Russell King , Aaro Koskinen , Michael Ellerman , x86@kernel.org, Ingo Molnar , Benjamin Herrenschmidt , Guenter Roeck , linux-xtensa@linux-xtensa.org, Denys Vlasenko , Arnd Bergmann , Konrad Rzeszutek Wilk , Akinobu Mita , Bjorn Helgaas , Thomas Gleixner , Valentin Rothberg , Chris Zankel , Tony Luck , linux-pci@vger.kernel.org, Dean Nelson , linux-kernel@vger.kernel.org, Ralf Baechle , "Suthikulpanit, Suravee" , Joe Perches , Andrew Morton , linuxppc-dev@lists.ozlabs.org Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP On 3/18/2016 8:12 AM, Robin Murphy wrote: > Since we know for sure that swiotlb_to_phys is a no-op on arm64, it might be cleaner to simply not reference it at all. I suppose we could have some private local wrappers, e.g.: > > #define swiotlb_to_virt(addr) phys_to_virt((phys_addr_t)(addr)) > > to keep the intent of the code clear (and just in case anyone ever builds a system mad enough to warrant switching out that definition, but I'd hope that never happens). > > Otherwise, looks good - thanks for doing this! OK. I added this. Reviewed-by? I'm not happy to submit such a big patch for all different ARCHs. I couldn't find a cleaner solution. I'm willing to split this patch into multiple if there is a better way. diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index ada00c3..8c0f66b 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -29,6 +29,14 @@ #include +/* + * If you are building a system without IOMMU, then you are using SWIOTLB + * library. The ARM64 adaptation of this library does not support address + * translation and it assumes that physical address = dma address for such + * a use case. Please don't build a platform that violates this. + */ +#define swiotlb_to_virt(addr) phys_to_virt((phys_addr_t)(addr)) + static pgprot_t __get_dma_pgprot(struct dma_attrs *attrs, pgprot_t prot, bool coherent) { @@ -188,7 +196,7 @@ static void __dma_free(struct device *dev, size_t size, void *vaddr, dma_addr_t dma_handle, struct dma_attrs *attrs) { - void *swiotlb_addr = phys_to_virt(swiotlb_dma_to_phys(dev, dma_handle)); + void *swiotlb_addr = swiotlb_to_virt(dma_handle); size = PAGE_ALIGN(size); @@ -209,8 +217,7 @@ static dma_addr_t __swiotlb_map_page(struct device *dev, struct page *page, dev_addr = swiotlb_map_page(dev, page, offset, size, dir, attrs); if (!is_device_dma_coherent(dev)) - __dma_map_area(phys_to_virt(swiotlb_dma_to_phys(dev, dev_addr)), - size, dir); + __dma_map_area(swiotlb_to_virt(dev_addr), size, dir); return dev_addr; } @@ -283,8 +290,7 @@ static void __swiotlb_sync_single_for_device(struct device *dev, { swiotlb_sync_single_for_device(dev, dev_addr, size, dir); if (!is_device_dma_coherent(dev)) - __dma_map_area(phys_to_virt(swiotlb_dma_to_phys(dev, dev_addr)), - size, dir); + __dma_map_area(swiotlb_to_virt(dev_addr), size, dir); }