From patchwork Mon Feb 24 20:53:52 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 25213 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-yk0-f197.google.com (mail-yk0-f197.google.com [209.85.160.197]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 3F8F02066C for ; Mon, 24 Feb 2014 20:55:50 +0000 (UTC) Received: by mail-yk0-f197.google.com with SMTP id 142sf25611591ykq.0 for ; Mon, 24 Feb 2014 12:55:50 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:delivered-to:from:to:subject:date:message-id :in-reply-to:references:mime-version:cc:precedence:list-id :list-unsubscribe:list-archive:list-post:list-help:list-subscribe :sender:errors-to:x-original-sender :x-original-authentication-results:mailing-list:content-type :content-transfer-encoding; bh=PUwJ6NnbsIxce6g7qLfDcrPNfpfVlbhO2rPtojd2+eU=; b=RsoMFOyOYdQDPTP7co3scVCiylywtYEAAkBQ/FH53Y8r46mR9+cOgfk0RaJRiqrY1x vu30FDGyk+aY6CaWmkkZ6ozHRSWTIOkeIsQcvP26ZLQ71gtrdRktdRUhjF1/OR7U/Rwi 69f/CQoWWI/FhnBrhDH+t5dOyyjSYEyopIMBIduOLWThM8d50p1qNt4wgVOXQCMuxuB7 cKOskkGxDRQdHNmTqJdK6LoeyYDDmEmealqP/znxSudumH2G1gL1IHAGDJ0ZAJBzip8J bNbVUQMiuvxVUuKFYSvVK+i70lGkO1p4+Sii/tBXJCCQ1jW5WmA1z22Hbb9Q+LRG8oMK XkhQ== X-Gm-Message-State: ALoCoQmGBF/68QBM+3woAngQIAiBBNwHW444Aa51pPmyJDggMZVC7L8pGr3Eizr6ZTXQEpLN9Xkp X-Received: by 10.236.128.243 with SMTP id f79mr362812yhi.27.1393275350014; Mon, 24 Feb 2014 12:55:50 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.165 with SMTP id x34ls2263059qgx.53.gmail; Mon, 24 Feb 2014 12:55:49 -0800 (PST) X-Received: by 10.52.245.136 with SMTP id xo8mr1178680vdc.72.1393275349909; Mon, 24 Feb 2014 12:55:49 -0800 (PST) Received: from mail-ve0-f172.google.com (mail-ve0-f172.google.com [209.85.128.172]) by mx.google.com with ESMTPS id xt2si6202688vcb.108.2014.02.24.12.55.49 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 12:55:49 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.128.172; Received: by mail-ve0-f172.google.com with SMTP id jz11so4452692veb.31 for ; Mon, 24 Feb 2014 12:55:49 -0800 (PST) X-Received: by 10.52.118.242 with SMTP id kp18mr1455504vdb.27.1393275349810; Mon, 24 Feb 2014 12:55:49 -0800 (PST) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.220.174.196 with SMTP id u4csp88362vcz; Mon, 24 Feb 2014 12:55:49 -0800 (PST) X-Received: by 10.194.58.180 with SMTP id s20mr21230676wjq.54.1393275348710; Mon, 24 Feb 2014 12:55:48 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id h9si16376090wjb.42.2014.02.24.12.55.48 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Feb 2014 12:55:48 -0800 (PST) Received-SPF: pass (google.com: domain of linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org designates 2001:770:15f::2 as permitted sender) client-ip=2001:770:15f::2; Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WI2YK-0004pO-O4; Mon, 24 Feb 2014 20:55:04 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WI2YC-0002wO-Ii; Mon, 24 Feb 2014 20:54:56 +0000 Received: from devils.ext.ti.com ([198.47.26.153]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WI2Y9-0002un-GT for linux-arm-kernel@lists.infradead.org; Mon, 24 Feb 2014 20:54:54 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1OKsPmX031737; Mon, 24 Feb 2014 14:54:25 -0600 Received: from DLEE71.ent.ti.com (dlee71.ent.ti.com [157.170.170.114]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1OKsOO1012206; Mon, 24 Feb 2014 14:54:24 -0600 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, 24 Feb 2014 14:54:24 -0600 Received: from ula0393909.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1OKrvD7007081; Mon, 24 Feb 2014 14:54:24 -0600 From: Santosh Shilimkar To: Subject: [PATCH 1/4] ARM: mm: Introduce archdata.dma_pfn_offset Date: Mon, 24 Feb 2014 15:53:52 -0500 Message-ID: <1393275235-1087-2-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393275235-1087-1-git-send-email-santosh.shilimkar@ti.com> References: <1393275235-1087-1-git-send-email-santosh.shilimkar@ti.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140224_155453_626375_43BEBFD0 X-CRM114-Status: GOOD ( 13.55 ) X-Spam-Score: -6.9 (------) X-Spam-Report: SpamAssassin version 3.3.2 on merlin.infradead.org summary: Content analysis details: (-6.9 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.153 listed in list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record -0.0 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] Cc: Olof Johansson , Santosh Shilimkar , Grygorii Strashko , Russell King , Arnd Bergmann 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+patch=linaro.org@lists.infradead.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: santosh.shilimkar@ti.com X-Original-Authentication-Results: mx.google.com; spf=neutral (google.com: 209.85.128.172 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 From: Grygorii Strashko 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 This patch introduces new field dma_pfn_offset in ARM dev_archdata structure which has to be filed per-device at arch init time (simplest way is to use Platform bus notifier to handle BUS_NOTIFY_ADD_DEVICE event) and updates DMA address translation routines in order to accommodate bus offset value by default. Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar --- arch/arm/include/asm/device.h | 1 + arch/arm/include/asm/dma-mapping.h | 17 +++++++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/arch/arm/include/asm/device.h b/arch/arm/include/asm/device.h index dc662fc..861961c 100644 --- a/arch/arm/include/asm/device.h +++ b/arch/arm/include/asm/device.h @@ -8,6 +8,7 @@ struct dev_archdata { struct dma_map_ops *dma_ops; + unsigned long dma_pfn_offset; #ifdef CONFIG_DMABOUNCE struct dmabounce_device_info *dmabounce; #endif diff --git a/arch/arm/include/asm/dma-mapping.h b/arch/arm/include/asm/dma-mapping.h index e701a4d..247ed72 100644 --- a/arch/arm/include/asm/dma-mapping.h +++ b/arch/arm/include/asm/dma-mapping.h @@ -58,22 +58,31 @@ 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) { - return (dma_addr_t)__pfn_to_bus(pfn); + if (!dev) + return DMA_ERROR_CODE; + return (dma_addr_t)__pfn_to_bus(pfn - dev->archdata.dma_pfn_offset); } static inline unsigned long dma_to_pfn(struct device *dev, dma_addr_t addr) { - return __bus_to_pfn(addr); + if (!dev) + return 0; + return __bus_to_pfn(addr) + dev->archdata.dma_pfn_offset; } static inline void *dma_to_virt(struct device *dev, dma_addr_t addr) { - return (void *)__bus_to_virt((unsigned long)addr); + if (!dev) + return NULL; + return (void *)__bus_to_virt(__pfn_to_bus(dma_to_pfn(dev, addr))); } static inline dma_addr_t virt_to_dma(struct device *dev, void *addr) { - return (dma_addr_t)__virt_to_bus((unsigned long)(addr)); + if (!dev) + return DMA_ERROR_CODE; + return pfn_to_dma(dev, + __bus_to_pfn(__virt_to_bus((unsigned long)(addr)))); } #else