From patchwork Wed Apr 18 10:36:29 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hiroshi Doyu X-Patchwork-Id: 7918 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 33D0123E4C for ; Wed, 18 Apr 2012 10:37:02 +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 D5917A18870 for ; Wed, 18 Apr 2012 10:37:01 +0000 (UTC) Received: by iage36 with SMTP id e36so14035099iag.11 for ; Wed, 18 Apr 2012 03:37:01 -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=Nv/ESD7Oorx7P0bsQRwezfMEKzAMYzscANwFc/Tvmrs=; b=XNCKiOZ5v28IFN877palEmZWOvRarTlQHeifB+eltSaFTpHWDmH5XSBcISe/y1pkt2 H6bUPsIrAS5qE36jEc1qBgEg1P1ZxZTqYr5vZLuLIHbr/yS60U4+LJBJ+vjm2IBFPRom ha/i6U34Ui+7WYmDBcOnX+Bb5vvCM7A0+fQJWwC2J6SGP3GH0j6oE/pqx+f3/4PiWtYe H6ertus5/X3Z90ZNuYwZqRJTJ1s4ZfjMuxtg6l7Iy3kLmri1mBobW5HNt298yxeOe9q/ 5LFu9QNgMGSOiiXmzHc3gczSdwCfm6/TfC27I7EfQMy1CQJ4ET7s/fOCucBZn+Cc2MOK cDWw== Received: by 10.50.154.167 with SMTP id vp7mr1174677igb.55.1334745421267; Wed, 18 Apr 2012 03:37:01 -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 x6csp207947ibt; Wed, 18 Apr 2012 03:37:00 -0700 (PDT) Received: by 10.180.104.65 with SMTP id gc1mr4974864wib.13.1334745414467; Wed, 18 Apr 2012 03:36:54 -0700 (PDT) Received: from mombin.canonical.com (mombin.canonical.com. [91.189.95.16]) by mx.google.com with ESMTP id cm8si15617079wib.6.2012.04.18.03.36.53; Wed, 18 Apr 2012 03:36:54 -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 1SKSFn-0002tw-K8; Wed, 18 Apr 2012 10:36:51 +0000 Received: from hqemgate04.nvidia.com ([216.228.121.35]) by mombin.canonical.com with esmtp (Exim 4.71) (envelope-from ) id 1SKSFm-0002tl-9e for linaro-mm-sig@lists.linaro.org; Wed, 18 Apr 2012 10:36:50 +0000 Received: from hqnvupgp05.nvidia.com (Not Verified[216.228.121.13]) by hqemgate04.nvidia.com id ; Wed, 18 Apr 2012 03:35:40 -0700 Received: from hqemhub03.nvidia.com ([172.17.108.22]) by hqnvupgp05.nvidia.com (PGP Universal service); Wed, 18 Apr 2012 03:36:34 -0700 X-PGP-Universal: processed; by hqnvupgp05.nvidia.com on Wed, 18 Apr 2012 03:36:34 -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; Wed, 18 Apr 2012 03:36:33 -0700 Received: from DEMAIL01.nvidia.com ([10.21.69.140]) by deemhub01.nvidia.com ([10.21.69.137]) with mapi; Wed, 18 Apr 2012 12:36:31 +0200 From: Hiroshi Doyu To: "thierry.reding@avionic-design.de" Date: Wed, 18 Apr 2012 12:36:29 +0200 Thread-Topic: [PATCH 1/1] dt: Add general DMA window parser Thread-Index: Ac0dTx4BRCRIhxsDSFiMGhMIHuBptw== Message-ID: <20120418.133629.1664781135413277375.hdoyu@nvidia.com> References: <20120418092613.GA8632@avionic-0098.mockup.avionic-design.de><20120418.131907.2172387798112620167.hdoyu@nvidia.com><20120418102629.GA14533@avionic-0098.mockup.avionic-design.de> In-Reply-To: <20120418102629.GA14533@avionic-0098.mockup.avionic-design.de> 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" , "swarren@wwwdotorg.org" , "joerg.roedel@amd.com" , "devicetree-discuss@lists.ozlabs.org" , "linaro-mm-sig@lists.linaro.org" , "iommu@lists.linux-foundation.org" , "linux-tegra@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" Subject: Re: [Linaro-mm-sig] [PATCH 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: ALoCoQkedKyfsZ8yYD7nJSMQ5KEkv/6wCJPwPjuZlTrBbOOtGmsMCxVpQW+MLc2KxO6gXGD4SNtE From: Thierry Reding Subject: Re: [PATCH 1/1] dt: Add general DMA window parser Date: Wed, 18 Apr 2012 12:26:29 +0200 Message-ID: <20120418102629.GA14533@avionic-0098.mockup.avionic-design.de> > * PGP Signed by an unknown key > > * Hiroshi Doyu wrote: > > + cells = prop ? *(__be32 *)prop : of_n_addr_cells(dn); > > I think this needs to be: > > cells = prop ? be32_to_cpup(prop) : of_n_addr_cells(dn); > > Only casting isn't enough, you need the bytes to be swapped. Right. Try again. Sorry for spamming. >From 1ee8a9b3a839456b170af74b11a4304bfda965c4 Mon Sep 17 00:00:00 2001 From: Hiroshi DOYU Date: Wed, 18 Apr 2012 12:09:03 +0300 Subject: [PATCH 1/1] dt: Add general DMA window parser This code was stolen from: "arch/microblaze/kernel/prom_parse.c" "arch/powerpc/kernel/prom_parse.c" Once "ibm," prefix is removed from dts file. This generic one could replace the originals. Signed-off-by: Hiroshi DOYU --- drivers/of/Kconfig | 4 ++++ drivers/of/Makefile | 1 + drivers/of/of_dma.c | 35 +++++++++++++++++++++++++++++++++++ include/linux/of_address.h | 10 ++++++++++ 4 files changed, 50 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..45c9e88 --- /dev/null +++ b/drivers/of/of_dma.c @@ -0,0 +1,35 @@ +/* + * Stolen from: + * "arch/microblaze/kernel/prom_parse.c" + * "arch/powerpc/kernel/prom_parse.c" + */ + +#include + +void of_parse_dma_window(struct device_node *dn, const void *dma_window_prop, + unsigned long *busno, unsigned long *phys, unsigned long *size) +{ + const __be32 *dma_window; + u32 cells; + const unsigned char *prop; + + dma_window = dma_window_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); + *phys = 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); + *size = of_read_number(dma_window, cells); +} + diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 01b925a..2a0f7c6 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -21,6 +21,10 @@ 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 void of_parse_dma_window(struct device_node *dn, + const void *dma_window_prop, unsigned long *busno, + unsigned long *phys, unsigned long *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 +52,12 @@ static inline const u32 *of_get_address(struct device_node *dev, int index, { return NULL; } + +static inline void of_parse_dma_window(struct device_node *dn, + const void *dma_window_prop, unsigned long *busno, + unsigned long *phys, unsigned long *size) +{ +} #endif /* CONFIG_OF_ADDRESS */