From patchwork Mon Apr 23 11:53:52 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 8036 Return-Path: X-Original-To: patchwork@peony.canonical.com Delivered-To: patchwork@peony.canonical.com Received: from fiordland.canonical.com (fiordland.canonical.com [91.189.94.145]) by peony.canonical.com (Postfix) with ESMTP id DBCB723E13 for ; Mon, 23 Apr 2012 11:54:16 +0000 (UTC) Received: from mail-iy0-f180.google.com (mail-iy0-f180.google.com [209.85.210.180]) by fiordland.canonical.com (Postfix) with ESMTP id 7EC1CA1844D for ; Mon, 23 Apr 2012 11:54:16 +0000 (UTC) Received: by iage36 with SMTP id e36so22660573iag.11 for ; Mon, 23 Apr 2012 04:54:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-forwarded-to:x-forwarded-for:delivered-to:received-spf :x-pgp-universal:from:to:date:thread-topic:thread-index:message-id :references:in-reply-to:accept-language:x-ms-has-attach :x-ms-tnef-correlator:x-nvconfidentiality:acceptlanguage :mime-version:cc:subject:x-beenthere:x-mailman-version:precedence :list-id:list-unsubscribe:list-archive:list-post:list-help :list-subscribe:content-type:content-transfer-encoding:sender :errors-to:x-gm-message-state; bh=3aI/nUcdWSoukptJ3HFtq8nzSgl4aylac9d2x9upry4=; b=JrvO+0PvOpRz4KYNZBG1+f9O4G0WOA2MvmglVwdZ9YlLp1E87ZePgyhR/E4a33Yt6Y xlvPLd82PnCfOyMS9E1XII1WAzMK3OfrEud1HBKkqrz5APn/U/FbN2PCD2LpVKWxp3zy lwSits5QnGWMnDA8ux+k2S/s0elS1WVLhtQTkFtrg2Z/kcpcom9XV58/vyxpmPMhwj/x SOT42EJHN6xbQ1RoR/HAJt99+4Sz+dEJeOPSm+FbFvUTR+u80BkeJozIH0DTi0zgpU8G 3DgUPjfHE953nrPJ9by3IDlpnhVrjg3esVu2MgywkFEFVs6skVMCQ1AijkGagMQLYUKB kZCA== Received: by 10.42.19.72 with SMTP id a8mr10840815icb.39.1335182055881; Mon, 23 Apr 2012 04:54:15 -0700 (PDT) X-Forwarded-To: linaro-patchwork@canonical.com X-Forwarded-For: patch@linaro.org linaro-patchwork@canonical.com Delivered-To: patches@linaro.org Received: by 10.231.137.198 with SMTP id x6csp107095ibt; Mon, 23 Apr 2012 04:54:14 -0700 (PDT) Received: by 10.216.135.141 with SMTP id u13mr46761wei.79.1335182053374; Mon, 23 Apr 2012 04:54:13 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id e9si8459555wiw.42.2012.04.23.04.54.12; Mon, 23 Apr 2012 04:54:13 -0700 (PDT) Received-SPF: neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) client-ip=91.189.95.16; Authentication-Results: mx.google.com; spf=neutral (google.com: 91.189.95.16 is neither permitted nor denied by best guess record for domain of linaro-mm-sig-bounces@lists.linaro.org) smtp.mail=linaro-mm-sig-bounces@lists.linaro.org Received: from localhost ([127.0.0.1] helo=mombin.canonical.com) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SMHqL-0001le-O3; Mon, 23 Apr 2012 11:54:09 +0000 Received: from hqemgate03.nvidia.com ([216.228.121.140]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SMHqJ-0001lY-QV for linaro-mm-sig@lists.linaro.org; Mon, 23 Apr 2012 11:54:08 +0000 Received: from hqnvupgp05.nvidia.com (Not Verified[216.228.121.13]) by hqemgate03.nvidia.com id ; Mon, 23 Apr 2012 05:09:55 -0700 Received: from hqemhub03.nvidia.com ([172.17.108.22]) by hqnvupgp05.nvidia.com (PGP Universal service); Mon, 23 Apr 2012 04:53:57 -0700 X-PGP-Universal: processed; by hqnvupgp05.nvidia.com on Mon, 23 Apr 2012 04:53:57 -0700 Received: from deemhub01.nvidia.com (10.21.69.137) by hqemhub03.nvidia.com (172.20.150.15) with Microsoft SMTP Server (TLS) id 8.3.245.1; Mon, 23 Apr 2012 04:53:57 -0700 Received: from DEMAIL01.nvidia.com ([10.21.69.140]) by deemhub01.nvidia.com ([10.21.69.137]) with mapi; Mon, 23 Apr 2012 13:53:55 +0200 From: Hiroshi Doyu To: "swarren@wwwdotorg.org" , "devicetree-discuss@lists.ozlabs.org" Date: Mon, 23 Apr 2012 13:53:52 +0200 Thread-Topic: [PATCH v2 1/1] dt: Add general DMA window parser Thread-Index: Ac0hR8IFnQUnaXQKSWOo6kdDyrMJDQ== Message-ID: <20120423.145352.1868450546332033138.hdoyu@nvidia.com> References: <20120418.131907.2172387798112620167.hdoyu@nvidia.com><4F8EF99E.3050709@wwwdotorg.org><20120419151920.68ab735a5b9eb8fb938b4d11@nvidia.com> In-Reply-To: <20120419151920.68ab735a5b9eb8fb938b4d11@nvidia.com> Accept-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-nvconfidentiality: public acceptlanguage: en-US MIME-Version: 1.0 Cc: "arnd@arndb.de" , "joerg.roedel@amd.com" , "thierry.reding@avionic-design.de" , "linaro-mm-sig@lists.linaro.org" , "iommu@lists.linux-foundation.org" , "linux-tegra@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: [Linaro-mm-sig] [PATCH v2 1/1] dt: Add general DMA window parser X-BeenThere: linaro-mm-sig@lists.linaro.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: "Unified memory management interest group." List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: linaro-mm-sig-bounces@lists.linaro.org Errors-To: linaro-mm-sig-bounces@lists.linaro.org X-Gm-Message-State: ALoCoQngCcL7xq4/I3E5LlBE+FKjvNt9Nvr3f7T6HxR0BQ20194C+AOLCT1V6/VlrwECugorGVW+ From: Hiroshi DOYU This code was based on: "arch/microblaze/kernel/prom_parse.c" "arch/powerpc/kernel/prom_parse.c" "ibm," prefix could be supported with some modification. Signed-off-by: Hiroshi DOYU --- v2: - Add several error checks. (Thierry Reding) - Use property name given to func. (Stephen Warren) - Support multiple entries. (Stephen Warren) --- drivers/of/Kconfig | 4 ++ drivers/of/Makefile | 1 + drivers/of/of_dma.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_address.h | 13 ++++++++ 4 files changed, 85 insertions(+), 0 deletions(-) diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig index dfba3e6..3b0298b 100644 --- a/drivers/of/Kconfig +++ b/drivers/of/Kconfig @@ -83,4 +83,8 @@ config OF_MTD depends on MTD def_bool y +config OF_DMA + depends on HAS_DMA + def_bool y + endmenu # OF diff --git a/drivers/of/Makefile b/drivers/of/Makefile index e027f44..711ff5b 100644 --- a/drivers/of/Makefile +++ b/drivers/of/Makefile @@ -11,3 +11,4 @@ obj-$(CONFIG_OF_MDIO) += of_mdio.o obj-$(CONFIG_OF_PCI) += of_pci.o obj-$(CONFIG_OF_PCI_IRQ) += of_pci_irq.o obj-$(CONFIG_OF_MTD) += of_mtd.o +obj-$(CONFIG_OF_DMA) += of_dma.o diff --git a/drivers/of/of_dma.c b/drivers/of/of_dma.c new file mode 100644 index 0000000..80bd7aa --- /dev/null +++ b/drivers/of/of_dma.c @@ -0,0 +1,67 @@ +/* + * Copyright (c) 2012, NVIDIA CORPORATION. All rights reserved. + * + * Based on: + * "arch/microblaze/kernel/prom_parse.c" + * "arch/powerpc/kernel/prom_parse.c" + * + * This program is free software; you can redistribute it and/or modify it + * under the terms and conditions of the GNU General Public License, + * version 2, as published by the Free Software Foundation. + * + * This program is distributed in the hope it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + */ + +#include +#include + +int of_parse_dma_window(struct device_node *dn, + const char *propname, int index, + unsigned long *busno, + dma_addr_t *addr, size_t *size) +{ + const __be32 *dma_window, *end; + int bytes, cur_index = 0; + + if (!dn || !propname || !addr || !size) + return -EINVAL; + + dma_window = of_get_property(dn, propname, &bytes); + if (!dma_window) + return -ENODEV; + end = dma_window + bytes / sizeof(*dma_window); + + while (dma_window < end) { + u32 cells; + const void *prop; + + /* busno is always one cell */ + if (busno) + *busno = be32_to_cpup(dma_window++); + + prop = of_get_property(dn, "#dma-address-cells", NULL); + if (!prop) + prop = of_get_property(dn, "#address-cells", NULL); + + cells = prop ? be32_to_cpup(prop) : of_n_addr_cells(dn); + if (!cells) + return -EINVAL; + *addr = of_read_number(dma_window, cells); + dma_window += cells; + + prop = of_get_property(dn, "#dma-size-cells", NULL); + cells = prop ? be32_to_cpup(prop) : of_n_size_cells(dn); + if (!cells) + return -EINVAL; + *size = of_read_number(dma_window, cells); + dma_window += cells; + + if (cur_index++ == index) + break; + } + return 0; +} +EXPORT_SYMBOL(of_parse_dma_window); diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 01b925a..1138cd3 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -21,6 +21,11 @@ extern void __iomem *of_iomap(struct device_node *device, int index); extern const u32 *of_get_address(struct device_node *dev, int index, u64 *size, unsigned int *flags); +extern int of_parse_dma_window(struct device_node *dev, + const char *propname, int index, + unsigned long *busno, + dma_addr_t *phys, size_t *size); + #ifndef pci_address_to_pio static inline unsigned long pci_address_to_pio(phys_addr_t addr) { return -1; } #define pci_address_to_pio pci_address_to_pio @@ -48,6 +53,14 @@ static inline const u32 *of_get_address(struct device_node *dev, int index, { return NULL; } + +extern int of_parse_dma_window(struct device_node *dev, + const char *propname, int index, + unsigned long *busno, + dma_addr_t *phys, size_t *size) +{ + return 0; +} #endif /* CONFIG_OF_ADDRESS */