From patchwork Thu Mar 17 15:50:29 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sinan Kaya X-Patchwork-Id: 8612621 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 9DB109F6E1 for ; Thu, 17 Mar 2016 16:01:43 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id D11B720364 for ; Thu, 17 Mar 2016 16:01:41 +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 ADB4F20361 for ; Thu, 17 Mar 2016 16:01:40 +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 1agaCl-0004ge-Pb; Thu, 17 Mar 2016 15:51:19 +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 1agaCi-0004Zb-5l for linux-arm-kernel@lists.infradead.org; Thu, 17 Mar 2016 15:51:16 +0000 Received: from smtp.codeaurora.org (localhost [127.0.0.1]) by smtp.codeaurora.org (Postfix) with ESMTP id 25C2E605B3; Thu, 17 Mar 2016 15:50:55 +0000 (UTC) Received: by smtp.codeaurora.org (Postfix, from userid 1000) id 18EBB6089A; Thu, 17 Mar 2016 15:50:55 +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 drakthul.qualcomm.com (global_nat1_iad_fw.qualcomm.com [129.46.232.65]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) (Authenticated sender: okaya@smtp.codeaurora.org) by smtp.codeaurora.org (Postfix) with ESMTPSA id E25996034F; Thu, 17 Mar 2016 15:50:51 +0000 (UTC) From: Sinan Kaya To: linux-arm-kernel@lists.infradead.org, timur@codeaurora.org, cov@codeaurora.org, nwatters@codeaurora.org Subject: [PATCH] arm64: dma-mapping: fix dma_to_phys API for IOMMU attached devices Date: Thu, 17 Mar 2016 11:50:29 -0400 Message-Id: <1458229833-4886-1-git-send-email-okaya@codeaurora.org> X-Mailer: git-send-email 1.8.2.1 X-Virus-Scanned: ClamAV using ClamSMTP X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160317_085116_268749_09FBED4B X-CRM114-Status: GOOD ( 12.10 ) 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: Jisheng Zhang , Arnd Bergmann , "Suzuki K. Poulose" , Catalin Marinas , Dean Nelson , Will Deacon , linux-kernel@vger.kernel.org, Sinan Kaya , Max Filippov , "Suthikulpanit, Suravee" , Joe Perches , Andrew Morton , Robin Murphy , Marek Szyprowski MIME-Version: 1.0 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 This patch modifies dma_to_phys to call iommu_iova_to_phys to perform dma to phys conversions for IOMMU attached devices where dma and physical addresses often have distinct values. Signed-off-by: Nate Watterson Signed-off-by: Sinan Kaya --- arch/arm64/include/asm/dma-mapping.h | 5 +---- arch/arm64/mm/dma-mapping.c | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/arch/arm64/include/asm/dma-mapping.h b/arch/arm64/include/asm/dma-mapping.h index ba437f0..a0a486c 100644 --- a/arch/arm64/include/asm/dma-mapping.h +++ b/arch/arm64/include/asm/dma-mapping.h @@ -69,10 +69,7 @@ static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr) return (dma_addr_t)paddr; } -static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr) -{ - return (phys_addr_t)dev_addr; -} +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr); static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size) { diff --git a/arch/arm64/mm/dma-mapping.c b/arch/arm64/mm/dma-mapping.c index 331c4ca..8252a92 100644 --- a/arch/arm64/mm/dma-mapping.c +++ b/arch/arm64/mm/dma-mapping.c @@ -989,3 +989,19 @@ void arch_setup_dma_ops(struct device *dev, u64 dma_base, u64 size, dev->archdata.dma_coherent = coherent; __iommu_setup_dma_ops(dev, dma_base, size, iommu); } + +phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr) +{ + phys_addr_t phys = (phys_addr_t)dev_addr; + +#ifdef CONFIG_IOMMU_DMA + struct iommu_domain *domain; + + domain = iommu_get_domain_for_dev(dev); + if (domain) + phys = iommu_iova_to_phys(domain, dev_addr); +#endif + + return phys; +} +EXPORT_SYMBOL(dma_to_phys);