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: 25479 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pb0-f72.google.com (mail-pb0-f72.google.com [209.85.160.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id 5FAF120447 for ; Thu, 27 Feb 2014 21:18:57 +0000 (UTC) Received: by mail-pb0-f72.google.com with SMTP id jt11sf7223719pbb.3 for ; Thu, 27 Feb 2014 13:18:56 -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=OJtO0CsvSmPIudrgyPqZTeWnARzqkfZaNjhQjZFc770=; b=MuBrVjLmhuwDJjnkde6oV2UzOoTGEPmcIf7kNum0jan0ZYIFq49lh58KP9PfruOoUu 6za1kuEhnsUw2vjufKn0bSrGz+j1nhnFPi+dZzFE9uP6psqfaNIxAuhWGyrQLyfRCX/L FyAJ7BIcK7NXGSRVhMvYTTnSOebVUTkpL9rpBKdVa9Cw1r+uoutJiyCsFlEvTGlZ0ZFV SjhLaurFHWLldSawKhY8O7j9SOvZTkcl42Xd6a0AUFnH4e/iIROYjVcFy9hW2tXMmZlG c3wN1iSGG8koyHJ65f3J6Wc2qjePQBnHAQc/8PtaMeHsKkkK7/wpCauDkR6E3pfEO/nY mXsQ== X-Gm-Message-State: ALoCoQm1EnGi1Lu/GHWWHBuAjV3HDVFbJQ7lX0DyzOX/IWnCzAaB+CB/gWzp5vNPymt/7J0rJR6S X-Received: by 10.66.231.132 with SMTP id tg4mr6810412pac.31.1393535936652; Thu, 27 Feb 2014 13:18:56 -0800 (PST) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.40.165 with SMTP id x34ls854852qgx.53.gmail; Thu, 27 Feb 2014 13:18:56 -0800 (PST) X-Received: by 10.58.190.99 with SMTP id gp3mr2755839vec.32.1393535936517; Thu, 27 Feb 2014 13:18:56 -0800 (PST) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id ec3si1647818vcb.122.2014.02.27.13.18.56 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 27 Feb 2014 13:18:56 -0800 (PST) Received-SPF: neutral (google.com: 209.85.220.180 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.180; Received: by mail-vc0-f180.google.com with SMTP id ks9so3141337vcb.11 for ; Thu, 27 Feb 2014 13:18:56 -0800 (PST) X-Received: by 10.220.164.80 with SMTP id d16mr12348638vcy.15.1393535936395; Thu, 27 Feb 2014 13:18:56 -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 u1csp6159vcs; Thu, 27 Feb 2014 13:18:55 -0800 (PST) X-Received: by 10.68.237.99 with SMTP id vb3mr15466353pbc.76.1393535935176; Thu, 27 Feb 2014 13:18:55 -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.54; Thu, 27 Feb 2014 13:18:54 -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 S1751729AbaB0VSx (ORCPT + 9 others); Thu, 27 Feb 2014 16:18:53 -0500 Received: from devils.ext.ti.com ([198.47.26.153]:58443 "EHLO devils.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751550AbaB0VSx (ORCPT ); Thu, 27 Feb 2014 16:18:53 -0500 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: CC: , , , , , , Grygorii Strashko , Russell King , Olof Johansson , Santosh Shilimkar 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 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.180 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 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