From patchwork Mon Feb 24 20:53:55 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 25215 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-qa0-f72.google.com (mail-qa0-f72.google.com [209.85.216.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 823612066C for ; Mon, 24 Feb 2014 20:57:36 +0000 (UTC) Received: by mail-qa0-f72.google.com with SMTP id f11sf10033468qae.7 for ; Mon, 24 Feb 2014 12:57:36 -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=Z7X5BZRdDd5q2RlexPL+eMQqp6BGJf2tB+/DODxUbBk=; b=P8OTJ64NJpzTZoNbddcPrfMa+nS0nXbD7niPCfm9cK0RLqWiIG5APpQ+70LLESlxec B2LQYR9MdaoI8BNKJdqlWcNXft1voADTwv1eUJo1Fsqt/6DQTTMmQBbl3RdaybgWZwPB UqSOtUDVh6yLo3QXbFhMuDmXMp0QWoBLXZ1YZD15BS9fvmbhEhzUIC4u54kK5ghOWurb RXYs2JU3uk9UP3uRjdVpSMSh4gRnQEMwj9zK2WL/LGFZ8VP+/pBZeAH5/bRsQIMvgbtL AK4vIvrgRq7ReSLNs0vlCh3svs3iDJNYkfTf703HyWmhX8AZYcC7Fi/awyduTjHg9VrD KWnA== X-Gm-Message-State: ALoCoQnIQlE/vFu2f3DH+p23gNiTB5Qj2a78C3I6QR3/fZCGEkYWPKhlK9Tf5hm08AgFgVdEiEVY X-Received: by 10.236.184.165 with SMTP id s25mr481233yhm.0.1393275456333; Mon, 24 Feb 2014 12:57:36 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.90.80 with SMTP id w74ls2056051qgd.95.gmail; Mon, 24 Feb 2014 12:57:36 -0800 (PST) X-Received: by 10.52.135.65 with SMTP id pq1mr11786341vdb.13.1393275456163; Mon, 24 Feb 2014 12:57:36 -0800 (PST) Received: from mail-ve0-f171.google.com (mail-ve0-f171.google.com [209.85.128.171]) by mx.google.com with ESMTPS id e9si6202716vct.109.2014.02.24.12.57.36 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Mon, 24 Feb 2014 12:57:36 -0800 (PST) Received-SPF: neutral (google.com: 209.85.128.171 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.171; Received: by mail-ve0-f171.google.com with SMTP id oz11so1687399veb.2 for ; Mon, 24 Feb 2014 12:57:36 -0800 (PST) X-Received: by 10.52.189.98 with SMTP id gh2mr93125vdc.86.1393275456058; Mon, 24 Feb 2014 12:57:36 -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 u4csp88449vcz; Mon, 24 Feb 2014 12:57:35 -0800 (PST) X-Received: by 10.180.25.46 with SMTP id z14mr16207066wif.49.1393275455130; Mon, 24 Feb 2014 12:57:35 -0800 (PST) Received: from casper.infradead.org (casper.infradead.org. [2001:770:15f::2]) by mx.google.com with ESMTPS id c4si16398534wjb.13.2014.02.24.12.57.34 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 24 Feb 2014 12:57:35 -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 1WI2ZG-0005YA-AC; Mon, 24 Feb 2014 20:56:02 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WI2Z3-00030A-9y; Mon, 24 Feb 2014 20:55:49 +0000 Received: from bear.ext.ti.com ([192.94.94.41]) by merlin.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WI2Yq-0002xf-Ba for linux-arm-kernel@lists.infradead.org; Mon, 24 Feb 2014 20:55:38 +0000 Received: from dlelxv90.itg.ti.com ([172.17.2.17]) by bear.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1OKt7D8025530; Mon, 24 Feb 2014 14:55:07 -0600 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dlelxv90.itg.ti.com (8.14.3/8.13.8) with ESMTP id s1OKt62r012738; Mon, 24 Feb 2014 14:55:07 -0600 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.174.1; Mon, 24 Feb 2014 14:54:27 -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 s1OKrvDA007081; Mon, 24 Feb 2014 14:54:27 -0600 From: Santosh Shilimkar To: Subject: [PATCH 4/4] ARM: keystone: Use dma-ranges for dma_pfn_offset configuration Date: Mon, 24 Feb 2014 15:53:55 -0500 Message-ID: <1393275235-1087-5-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_155536_570626_090DE01A X-CRM114-Status: GOOD ( 17.15 ) 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 [192.94.94.41 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.171 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 Keystone platforms have their physical memory mapped at an address outside the 32-bit physical range. A Keystone machine with 16G of RAM would find its memory at 0x0800000000 - 0x0bffffffff. The system interconnect allows to perform DMA transfers from first 2G of physical memory (0x08 0000 0000 to 08 7FFF FFFF) which aliased in hardware to the 32-bit addressable space (0x80000000 - 0xffffffff), because DMA HW supports only 32-bits addressing. Get DMA range configuration from DT and use it to configure per device dma_pfn_offset. DMA addresses translation will be performed as following: _dev->archdata.dma_pfn_offset = PFN_DOWN( - ); DMA->PFN: __bus_to_pfn(addr) + dev->archdata.dma_pfn_offset PFN->DMA: __pfn_to_bus(pfn - dev->archdata.dma_pfn_offset) Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar --- arch/arm/mach-keystone/keystone.c | 76 +++++++++++++++++++++++++++++++++++-- 1 file changed, 73 insertions(+), 3 deletions(-) diff --git a/arch/arm/mach-keystone/keystone.c b/arch/arm/mach-keystone/keystone.c index e735555..ebe0a66 100644 --- a/arch/arm/mach-keystone/keystone.c +++ b/arch/arm/mach-keystone/keystone.c @@ -33,6 +33,7 @@ static void __iomem *keystone_rstctrl; static struct notifier_block platform_nb; +static unsigned long keystone_dma_pfn_offset __read_mostly; static bool is_coherent(struct device *dev) { @@ -48,15 +49,82 @@ static bool is_coherent(struct device *dev) return false; } +static unsigned long get_dma_pfn_offset(struct device *dev) +{ + struct device_node *node = of_node_get(dev->of_node); + const u32 *ranges = NULL; + int len, naddr, nsize, pna; + dma_addr_t dma_addr; + phys_addr_t cpu_addr, size; + unsigned long dma_pfn_offset = 0; + + if (!node) + return 0; + + while (1) { + naddr = of_n_addr_cells(node); + nsize = of_n_size_cells(node); + node = of_get_next_parent(node); + if (!node) + break; + + ranges = of_get_property(node, "dma-ranges", &len); + + /* Ignore empty ranges, they imply no translation required */ + if (ranges && len > 0) + break; + } + + if (!ranges) { + dev_dbg(dev, "no dma-ranges found\n"); + goto out; + } + + /* + * dma-ranges format: + * DMA addr : naddr cells + * CPU addr : pna cells + * size : nsize cells + */ + len /= sizeof(u32); + pna = of_n_addr_cells(node); + dma_addr = of_read_number(ranges, nsize); + cpu_addr = of_translate_dma_address(dev->of_node, ranges); + size = of_read_number(ranges + naddr + pna, nsize); + dma_pfn_offset = PFN_DOWN(cpu_addr - dma_addr); + + dev_dbg(dev, "%s: naddr-%u nsize-%u pna-%u len-%u\n", + node->name, naddr, nsize, pna, len); + dev_dbg(dev, "dma_addr-%08x cpu_addr-%pa size-%pa dma_pfn_offset-%08lx\n", + dma_addr, &cpu_addr, &size, dma_pfn_offset); + +out: + of_node_put(node); + return dma_pfn_offset; +} + static int keystone_platform_notifier(struct notifier_block *nb, unsigned long event, void *dev) { + struct device *_dev = dev; + if (event != BUS_NOTIFY_ADD_DEVICE) return NOTIFY_DONE; - if (is_coherent(dev)) { - set_dma_ops(dev, &arm_coherent_dma_ops); - pr_info("\t\t%s: keystone device is coherent\n", dev_name(dev)); + if (!_dev) + return NOTIFY_BAD; + + if (!_dev->of_node) + _dev->archdata.dma_pfn_offset = keystone_dma_pfn_offset; + else + _dev->archdata.dma_pfn_offset = get_dma_pfn_offset(_dev); + + dev_dbg(_dev, "set dma_pfn_offset %08lx\n", + _dev->archdata.dma_pfn_offset); + + if (is_coherent(_dev)) { + set_dma_ops(_dev, &arm_coherent_dma_ops); + dev_info(_dev, "keystone device is coherent\n"); } return NOTIFY_OK; @@ -120,6 +188,8 @@ static void __init keystone_init_meminfo(void) /* Populate the arch idmap hook */ arch_virt_to_idmap = keystone_virt_to_idmap; + keystone_dma_pfn_offset = PFN_DOWN(KEYSTONE_HIGH_PHYS_START - + KEYSTONE_LOW_PHYS_START); platform_nb.notifier_call = keystone_platform_notifier;