From patchwork Thu Feb 27 21:17:50 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 3736261 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.19.201]) by patchwork1.web.kernel.org (Postfix) with ESMTP id A63249F2F7 for ; Thu, 27 Feb 2014 21:48:00 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A3A6120237 for ; Thu, 27 Feb 2014 21:47:59 +0000 (UTC) Received: from casper.infradead.org (casper.infradead.org [85.118.1.10]) (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 884342016C for ; Thu, 27 Feb 2014 21:47:58 +0000 (UTC) Received: from merlin.infradead.org ([2001:4978:20e::2]) by casper.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WJ8Nm-0007W0-42; Thu, 27 Feb 2014 21:20:42 +0000 Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WJ8N4-0004CQ-Aa; Thu, 27 Feb 2014 21:19:58 +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 1WJ8Ls-00043i-02 for linux-arm-kernel@lists.infradead.org; Thu, 27 Feb 2014 21:18:52 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by devils.ext.ti.com (8.13.7/8.13.7) with ESMTP id s1RLIGBC000734; Thu, 27 Feb 2014 15:18:16 -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 s1RLIG6V029965; Thu, 27 Feb 2014 15:18:16 -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:18:15 -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 s1RLHrfi023451; Thu, 27 Feb 2014 15:18:15 -0600 From: Santosh Shilimkar To: Subject: [PATCH v2 5/7] ARM: of: introduce common routine for DMA configuration Date: Thu, 27 Feb 2014 16:17:50 -0500 Message-ID: <1393535872-20915-6-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 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20140227_161844_343378_0FD3CD00 X-CRM114-Status: GOOD ( 21.69 ) X-Spam-Score: -3.8 (---) Cc: devicetree@vger.kernel.org, Grygorii Strashko , Russell King , linus.walleij@linaro.org, magnus.damm@gmail.com, Olof Johansson , robh+dt@kernel.org, Santosh Shilimkar , grant.likely@linaro.org, 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=-1.1 required=5.0 tests=BAYES_00,KHOP_BIG_TO_CC, RCVD_IN_DNSWL_MED, RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=no 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 From: Grygorii Strashko This patch introduces ARM specific function arm_dt_dma_configure() which intended to retrieve DMA configuration from DT and setup Platform device's DMA parameters. The DMA configuration in DT has to be specified using "dma-ranges" and "dam-coherent" properties if supported. The DMA configuration applied by arm_dt_dma_configure() as following: - call of_get_dma_range() and get supported DMA range info (dma_addr, cpu_addr, dma_size); - if "not found" then fill dma_mask as DMA_BIT_MASK(32) (this is default behaviour); - if "failed" then clean up dma_mask (DMA not supported) - if ok then update devices DMA configuration: set dma_mask to (dma_addr + dma_size - 1) set dma_pfn_offset to PFN_DOWN(cpu_addr - dma_addr) Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Cc: Grant Likely Cc: Rob Herring Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar --- arch/arm/include/asm/prom.h | 3 +++ arch/arm/kernel/devtree.c | 61 +++++++++++++++++++++++++++++++++++++++++++ drivers/of/platform.c | 5 +++- include/linux/of.h | 2 +- 4 files changed, 69 insertions(+), 2 deletions(-) diff --git a/arch/arm/include/asm/prom.h b/arch/arm/include/asm/prom.h index b681575..1acb732 100644 --- a/arch/arm/include/asm/prom.h +++ b/arch/arm/include/asm/prom.h @@ -11,11 +11,13 @@ #ifndef __ASMARM_PROM_H #define __ASMARM_PROM_H +struct device; #ifdef CONFIG_OF extern const struct machine_desc *setup_machine_fdt(unsigned int dt_phys); extern void arm_dt_memblock_reserve(void); extern void __init arm_dt_init_cpu_maps(void); +extern void arm_dt_dma_configure(struct device *dev); #else /* CONFIG_OF */ @@ -26,6 +28,7 @@ static inline const struct machine_desc *setup_machine_fdt(unsigned int dt_phys) static inline void arm_dt_memblock_reserve(void) { } static inline void arm_dt_init_cpu_maps(void) { } +static inline void arm_dt_dma_configure(struct device *dev) { } #endif /* CONFIG_OF */ #endif /* ASMARM_PROM_H */ diff --git a/arch/arm/kernel/devtree.c b/arch/arm/kernel/devtree.c index f751714..926b5dd 100644 --- a/arch/arm/kernel/devtree.c +++ b/arch/arm/kernel/devtree.c @@ -18,6 +18,9 @@ #include #include #include +#include +#include +#include #include #include @@ -235,3 +238,61 @@ const struct machine_desc * __init setup_machine_fdt(unsigned int dt_phys) return mdesc; } + +void arm_dt_dma_configure(struct device *dev) +{ + dma_addr_t dma_addr; + phys_addr_t paddr, size; + dma_addr_t dma_mask; + int ret; + + /* + * if dma-ranges property doesn't exist - use 32 bits DMA mask + * by default and don't set skip archdata.dma_pfn_offset + */ + ret = of_dma_get_range(dev->of_node, &dma_addr, &paddr, &size); + if (ret == -ENODEV) { + dev->coherent_dma_mask = DMA_BIT_MASK(32); + if (!dev->dma_mask) + dev->dma_mask = &dev->coherent_dma_mask; + return; + } + + /* if failed - disable DMA for device */ + if (ret < 0) { + dev_err(dev, "failed to configure DMA\n"); + return; + } + + /* DMA ranges found. Calculate and set dma_pfn_offset */ + dev->archdata.dma_pfn_offset = PFN_DOWN(paddr - dma_addr); + + /* Configure DMA mask */ + dev->dma_mask = kmalloc(sizeof(*dev->dma_mask), GFP_KERNEL); + if (!dev->dma_mask) + return; + + dma_mask = dma_addr + size - 1; + + ret = arm_dma_set_mask(dev, dma_mask); + if (ret < 0) { + dev_err(dev, "failed to set DMA mask %#08x\n", dma_mask); + kfree(dev->dma_mask); + dev->dma_mask = NULL; + return; + } + + dev_dbg(dev, "dma_pfn_offset(%#08lx) dma_mask(%#016llx)\n", + dev->archdata.dma_pfn_offset, *dev->dma_mask); + + if (of_dma_is_coherent(dev->of_node)) { + set_dma_ops(dev, &arm_coherent_dma_ops); + dev_dbg(dev, "device is dma coherent\n"); + } + + ret = dma_set_coherent_mask(dev, dma_mask); + if (ret < 0) { + dev_err(dev, "failed to set coherent DMA mask %#08x\n", + dma_mask); + } +} diff --git a/drivers/of/platform.c b/drivers/of/platform.c index 404d1da..97d5533 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -213,10 +213,13 @@ static struct platform_device *of_platform_device_create_pdata( #if defined(CONFIG_MICROBLAZE) dev->archdata.dma_mask = 0xffffffffUL; -#endif +#elif defined(CONFIG_ARM_LPAE) + arm_dt_dma_configure(&dev->dev); +#else dev->dev.coherent_dma_mask = DMA_BIT_MASK(32); if (!dev->dev.dma_mask) dev->dev.dma_mask = &dev->dev.coherent_dma_mask; +#endif dev->dev.bus = &platform_bus_type; dev->dev.platform_data = platform_data; diff --git a/include/linux/of.h b/include/linux/of.h index 70c64ba..a321058 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -136,7 +136,7 @@ static inline unsigned long of_read_ulong(const __be32 *cell, int size) return of_read_number(cell, size); } -#if defined(CONFIG_SPARC) +#if defined(CONFIG_SPARC) || defined(CONFIG_ARM_LPAE) #include #endif