From patchwork Thu Feb 27 21:17:46 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 25476 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 D40E520447 for ; Thu, 27 Feb 2014 21:18:35 +0000 (UTC) Received: by mail-yk0-f197.google.com with SMTP id 142sf15533855ykq.0 for ; Thu, 27 Feb 2014 13:18:35 -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:cc:subject:date:message-id :in-reply-to:references:mime-version:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe:content-type; bh=Xpssn9Geelg+ffPgHKzKpQyWaRxYJXT5EMMhieAwhxY=; b=Kb3jmpHeNQonK3TaWzspjxBmAHCdZ5MljDaHlMI+yQnC1+EjkR9M0bSpLiPvJ5HKuK RYZxh4J/7WtnHQS3gOGKsRSLy/G4YTncbu+QlCmwSX/MCkBT0bzDsa+s28/zZT+zZGE1 3UMSatcuZ8RTcjnE+vDjSL1mMhpqePmO0dJgCLSaSnoYxPtEBiB8HshaJWj/WNpKYbdA 72HJOpe+B5fO8o6TUyvPrlvqCvIsKHFn8iELxN6UEw+BSG5X1V6tJzSX6A3r1qxwGWHv R0GHHoHmhPcRX5BUMnrCfKuZ/9PbTtQo0BiAyHFUfWiKs/kNkRCAZMpSTEVM7EvUYwae 1sIw== X-Gm-Message-State: ALoCoQkzUSmpXll6NttW9Jl0XLJxikxPMFw9iNR7+TUz38jL/B7dkqvnVvUgTROhOty5+1MYuRWl X-Received: by 10.58.179.101 with SMTP id df5mr7248166vec.38.1393535915609; Thu, 27 Feb 2014 13:18:35 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.26.35 with SMTP id 32ls837625qgu.80.gmail; Thu, 27 Feb 2014 13:18:35 -0800 (PST) X-Received: by 10.220.67.18 with SMTP id p18mr12514088vci.14.1393535915497; Thu, 27 Feb 2014 13:18:35 -0800 (PST) Received: from mail-vc0-f175.google.com (mail-vc0-f175.google.com [209.85.220.175]) by mx.google.com with ESMTPS id lz6si1647665vcb.106.2014.02.27.13.18.35 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 13:18:35 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.175 is neither permitted nor denied by best guess record for domain of patch+caf_=patchwork-forward=linaro.org@linaro.org) client-ip=209.85.220.175; Received: by mail-vc0-f175.google.com with SMTP id ij19so3134667vcb.34 for ; Thu, 27 Feb 2014 13:18:35 -0800 (PST) X-Received: by 10.58.243.3 with SMTP id wu3mr12387167vec.12.1393535915389; Thu, 27 Feb 2014 13:18:35 -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.130.193 with SMTP id u1csp6139vcs; Thu, 27 Feb 2014 13:18:34 -0800 (PST) X-Received: by 10.68.202.37 with SMTP id kf5mr15865329pbc.38.1393535914114; Thu, 27 Feb 2014 13:18:34 -0800 (PST) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id bi5si5843182pbb.319.2014.02.27.13.18.33; Thu, 27 Feb 2014 13:18:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of devicetree-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751375AbaB0VSc (ORCPT + 9 others); Thu, 27 Feb 2014 16:18:32 -0500 Received: from comal.ext.ti.com ([198.47.26.152]:41940 "EHLO comal.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751007AbaB0VSc (ORCPT ); Thu, 27 Feb 2014 16:18:32 -0500 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1RLHvRe018335; Thu, 27 Feb 2014 15:17:57 -0600 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 s1RLHvr0029633; Thu, 27 Feb 2014 15:17:57 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 27 Feb 2014 15:17:57 -0600 Received: from ula0393909.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1RLHrfe023451; Thu, 27 Feb 2014 15:17:56 -0600 From: Santosh Shilimkar To: CC: , , , , , , Grygorii Strashko , Russell King , Olof Johansson , Santosh Shilimkar Subject: [PATCH v2 1/7] ARM: mm: Introduce archdata.dma_pfn_offset Date: Thu, 27 Feb 2014 16:17:46 -0500 Message-ID: <1393535872-20915-2-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1393535872-20915-1-git-send-email-santosh.shilimkar@ti.com> References: <1393535872-20915-1-git-send-email-santosh.shilimkar@ti.com> MIME-Version: 1.0 Sender: devicetree-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: devicetree@vger.kernel.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.220.175 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 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , 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 Acked-by: Linus Walleij --- 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