From patchwork Mon May 5 21:43:24 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 4117341 Return-Path: X-Original-To: patchwork-linux-arm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id D270FBFF02 for ; Mon, 5 May 2014 21:47:44 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id EB8AA2024C for ; Mon, 5 May 2014 21:47:43 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id F302320220 for ; Mon, 5 May 2014 21:47:42 +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 1WhQgB-0005WX-8o; Mon, 05 May 2014 21:44:07 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WhQg8-0005UY-2r for linux-arm-kernel@lists.infradead.org; Mon, 05 May 2014 21:44:04 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s45LhQ25022895; Mon, 5 May 2014 16:43:26 -0500 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id s45LhPnE004578; Mon, 5 May 2014 16:43:25 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Mon, 5 May 2014 16:43:25 -0500 Received: from [158.218.103.31] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s45LhOrk000869; Mon, 5 May 2014 16:43:24 -0500 Message-ID: <536805FC.8090406@ti.com> Date: Mon, 5 May 2014 17:43:24 -0400 From: Santosh Shilimkar User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.3.0 MIME-Version: 1.0 To: Russell King - ARM Linux Subject: Re: [PATCH v3 5/7] ARM: dma: Use dma_pfn_offset for dma address translation References: <1398353407-2345-1-git-send-email-santosh.shilimkar@ti.com> <1398353407-2345-6-git-send-email-santosh.shilimkar@ti.com> <20140502145852.GC3693@n2100.arm.linux.org.uk> <5363B42C.4010404@ti.com> <20140505195040.GE3693@n2100.arm.linux.org.uk> In-Reply-To: <20140505195040.GE3693@n2100.arm.linux.org.uk> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140505_144404_288919_5AE29D9F X-CRM114-Status: GOOD ( 17.50 ) X-Spam-Score: -5.7 (-----) Cc: devicetree@vger.kernel.org, Grygorii Strashko , Arnd Bergmann , Greg Kroah-Hartman , Linus Walleij , linux-kernel@vger.kernel.org, Grant Likely , Rob Herring , Catalin Marinas , Olof Johansson , linux-arm-kernel@lists.infradead.org X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Spam-Status: No, score=-2.5 required=5.0 tests=BAYES_00,RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP On Monday 05 May 2014 03:50 PM, Russell King - ARM Linux wrote: > On Fri, May 02, 2014 at 11:05:16AM -0400, Santosh Shilimkar wrote: >> On Friday 02 May 2014 10:58 AM, Russell King - ARM Linux wrote: >>> On Thu, Apr 24, 2014 at 11:30:05AM -0400, Santosh Shilimkar wrote: >>>> static inline void *dma_to_virt(struct device *dev, dma_addr_t addr) >>>> { >>>> - return (void *)__bus_to_virt((unsigned long)addr); >>>> + if (!dev) >>>> + return (void *)__bus_to_virt((unsigned long)addr); >>>> + else >>>> + return (void *)__bus_to_virt(__pfn_to_bus(dma_to_pfn(dev, addr))); >>> >>> This is quite horrendous. There's easier ways to do this... I assume >>> you haven't looked at the assembler resulting from this at all with >>> stuff like the p2v patching enabled? >>> >> I haven't. Will check. > > if (dev) { > unsigned long pfn = dma_to_pfn(dev, addr); > > return phys_to_virt(__pfn_to_phys(pfn)); > } > > return (void *)__bus_to_virt((unsigned long)addr); > Thanks a lot Russell. Updated patch below for archive records. From 97a6f063270265d03ffcb010b9dc156b274631e7 Mon Sep 17 00:00:00 2001 From: Grygorii Strashko Date: Thu, 24 Apr 2014 11:30:05 -0400 Subject: [PATCH v3 5/7] ARM: dma: Use dma_pfn_offset for dma address translation In most of cases DMA addresses can be performed using offset value of Bus address space relatively to physical address space as following: PFN->DMA: __pfn_to_phys(pfn + [-]dma_pfn_offset) DMA->PFN: __phys_to_pfn(dma_addr) + [-]dma_pfn_offset Thanks to Russell King for suggesting the optimised macro's for conversion. Cc: Greg Kroah-Hartman Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Cc: Grant Likely Cc: Catalin Marinas Cc: Linus Walleij Reviewed-by: Rob Herring Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar --- arch/arm/include/asm/dma-mapping.h | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index e701a4d..b0c79fd 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -58,21 +58,37 @@ static inline int dma_set_mask(struct device *dev, u64 mask) #ifndef __arch_pfn_to_dma static inline dma_addr_t pfn_to_dma(struct device *dev, unsigned long pfn) { + if (dev) + pfn -= dev->dma_pfn_offset; return (dma_addr_t)__pfn_to_bus(pfn); } static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr) { - return __bus_to_pfn(addr); + unsigned long pfn = __bus_to_pfn(addr); + + if (dev) + pfn += dev->dma_pfn_offset; + + return pfn; } static inline void *dma_to_virt(struct device *dev, dma_addr_t addr) { + if (dev) { + unsigned long pfn = dma_to_pfn(dev, addr); + + return phys_to_virt(__pfn_to_phys(pfn)); + } + return (void *)__bus_to_virt((unsigned long)addr); } static inline dma_addr_t virt_to_dma(struct device *dev, void *addr) { + if (dev) + return pfn_to_dma(dev, virt_to_pfn(addr)); + return (dma_addr_t)__virt_to_bus((unsigned long)(addr)); }