From patchwork Thu Apr 24 15:30:02 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Santosh Shilimkar X-Patchwork-Id: 28983 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f71.google.com (mail-pa0-f71.google.com [209.85.220.71]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id AB0F72036A for ; Thu, 24 Apr 2014 15:33:08 +0000 (UTC) Received: by mail-pa0-f71.google.com with SMTP id kp14sf3003483pab.2 for ; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) 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=0CaydzHpkD9QilzXwJZj5jbqBL2TGivOxIBYp48ByIA=; b=mml59t27f2ch+V1Ucd/GWsTv73y0tfjRa1fzzuVFiOQK0p0Yd6MsWoD5PAjZRYtljt rHONRdKNQbrM++fsdhve5vUeEGEpwxrT3txVZbXaGGFhSsM8/656kn/vUc4ANd0Vw/4t TVpjpzwGmf/XV+t4s/A5XK8YdMIC6qswM6SC2NFdJ6dsPdW6x+1XxTaqDwIcrst+r938 OqjG5Joj19rvHTIk1f2cG7OSQRSioyTt3YN244lQ+0gNlzpBgTI3iTqVxV0MzD4C/6Lt qSelXIbAvER4m94BAZF1fDP8KVBDiZtaQHdIgRh68lG9hpxDYCxnVO2dTuKJMwC2/R/A UvlQ== X-Gm-Message-State: ALoCoQlbqMrYUMI0BvrktUPBLJTbfDTEXdn5NWN0YWoa1+FwpovM09oZDd+asSSaM7kQtp/s4y4R X-Received: by 10.66.102.3 with SMTP id fk3mr304496pab.17.1398353587829; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.91.36 with SMTP id y33ls1185231qgd.82.gmail; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) X-Received: by 10.52.128.84 with SMTP id nm20mr541285vdb.63.1398353587669; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) Received: from mail-vc0-f178.google.com (mail-vc0-f178.google.com [209.85.220.178]) by mx.google.com with ESMTPS id m3si1004728vcr.131.2014.04.24.08.33.07 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Thu, 24 Apr 2014 08:33:07 -0700 (PDT) Received-SPF: none (google.com: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) client-ip=209.85.220.178; Received: by mail-vc0-f178.google.com with SMTP id hu19so3101358vcb.23 for ; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) X-Received: by 10.220.249.6 with SMTP id mi6mr1053603vcb.33.1398353587559; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) 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.221.72 with SMTP id ib8csp25481vcb; Thu, 24 Apr 2014 08:33:07 -0700 (PDT) X-Received: by 10.224.136.74 with SMTP id q10mr3732535qat.78.1398353581638; Thu, 24 Apr 2014 08:33:01 -0700 (PDT) Received: from bombadil.infradead.org (bombadil.infradead.org. [2001:1868:205::9]) by mx.google.com with ESMTPS id v39si2363143qge.179.2014.04.24.08.33.01 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 24 Apr 2014 08:33:01 -0700 (PDT) Received-SPF: none (google.com: linux-arm-kernel-bounces+patch=linaro.org@lists.infradead.org does not designate permitted sender hosts) client-ip=2001:1868:205::9; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.80.1 #2 (Red Hat Linux)) id 1WdLco-0003l3-9a; Thu, 24 Apr 2014 15:31:46 +0000 Received: from comal.ext.ti.com ([198.47.26.152]) by bombadil.infradead.org with esmtps (Exim 4.80.1 #2 (Red Hat Linux)) id 1WdLcb-0003Z5-Gg for linux-arm-kernel@lists.infradead.org; Thu, 24 Apr 2014 15:31:34 +0000 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by comal.ext.ti.com (8.13.7/8.13.7) with ESMTP id s3OFUwRJ022520; Thu, 24 Apr 2014 10:30:58 -0500 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 s3OFUwfG003012; Thu, 24 Apr 2014 10:30:58 -0500 Received: from dlep32.itg.ti.com (157.170.170.100) by DLEE71.ent.ti.com (157.170.170.114) with Microsoft SMTP Server id 14.3.174.1; Thu, 24 Apr 2014 10:30:58 -0500 Received: from ula0393909.am.dhcp.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dlep32.itg.ti.com (8.14.3/8.13.8) with ESMTP id s3OFU9M8019851; Thu, 24 Apr 2014 10:30:57 -0500 From: Santosh Shilimkar To: Subject: [PATCH v3 2/7] of: introduce of_dma_get_range() helper Date: Thu, 24 Apr 2014 11:30:02 -0400 Message-ID: <1398353407-2345-3-git-send-email-santosh.shilimkar@ti.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1398353407-2345-1-git-send-email-santosh.shilimkar@ti.com> References: <1398353407-2345-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-20140424_083133_666681_AD1BC03A X-CRM114-Status: GOOD ( 14.38 ) X-Spam-Score: -5.7 (-----) X-Spam-Report: SpamAssassin version 3.3.2 on bombadil.infradead.org summary: Content analysis details: (-5.7 points) pts rule name description ---- ---------------------- -------------------------------------------------- -5.0 RCVD_IN_DNSWL_HI RBL: Sender listed at http://www.dnswl.org/, high trust [198.47.26.152 listed in list.dnswl.org] -0.7 RP_MATCHES_RCVD Envelope sender domain matches handover relay domain -0.0 SPF_PASS SPF: sender matches SPF record Cc: devicetree@vger.kernel.org, Grygorii Strashko , Russell King , Arnd Bergmann , Greg Kroah-Hartman , Linus Walleij , Grant Likely , Rob Herring , Santosh Shilimkar , Catalin Marinas , Olof Johansson , 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+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: patch+caf_=patchwork-forward=linaro.org@linaro.org does not designate permitted sender hosts) 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 The of_dma_get_range() allows to find "dma-range" property for the specified device and parse it. dma-ranges format: DMA addr (dma_addr) : naddr cells CPU addr (phys_addr_t) : pna cells size : nsize cells Cc: Greg Kroah-Hartman Cc: Russell King Cc: Arnd Bergmann Cc: Olof Johansson Cc: Grant Likely Cc: Rob Herring Cc: Catalin Marinas Cc: Linus Walleij Signed-off-by: Grygorii Strashko Signed-off-by: Santosh Shilimkar Reviewed-by: Rob Herring --- drivers/of/address.c | 87 ++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_address.h | 8 ++++ 2 files changed, 95 insertions(+) diff --git a/drivers/of/address.c b/drivers/of/address.c index cb4242a..c54baee 100644 --- a/drivers/of/address.c +++ b/drivers/of/address.c @@ -721,3 +721,90 @@ void __iomem *of_iomap(struct device_node *np, int index) return ioremap(res.start, resource_size(&res)); } EXPORT_SYMBOL(of_iomap); + +/** + * of_dma_get_range - Get DMA range info + * @np: device node to get DMA range info + * @dma_addr: pointer to store initial DMA address of DMA range + * @paddr: pointer to store initial CPU address of DMA range + * @size: pointer to store size of DMA range + * + * Look in bottom up direction for the first "dma-ranges" property + * and parse it. + * dma-ranges format: + * DMA addr (dma_addr) : naddr cells + * CPU addr (phys_addr_t) : pna cells + * size : nsize cells + * + * It returns -ENODEV if "dma-ranges" property was not found + * for this device in DT. + */ +int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size) +{ + struct device_node *node = of_node_get(np); + const __be32 *ranges = NULL; + int len, naddr, nsize, pna; + int ret = 0; + u64 dmaaddr; + + if (!node) + return -EINVAL; + + 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; + + /* + * At least empty ranges has to be defined for parent node if + * DMA is supported + */ + if (!ranges) + break; + } + + if (!ranges) { + pr_debug("%s: no dma-ranges found for node(%s)\n", + __func__, np->full_name); + ret = -ENODEV; + goto out; + } + + len /= sizeof(u32); + + pna = of_n_addr_cells(node); + + /* dma-ranges format: + * DMA addr : naddr cells + * CPU addr : pna cells + * size : nsize cells + */ + dmaaddr = of_read_number(ranges, naddr); + *paddr = of_translate_dma_address(np, ranges); + if (*paddr == OF_BAD_ADDR) { + pr_err("%s: translation of DMA address(%pad) to CPU address failed node(%s)\n", + __func__, dma_addr, np->full_name); + ret = -EINVAL; + goto out; + } + *dma_addr = dmaaddr; + + *size = of_read_number(ranges + naddr + pna, nsize); + + pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", + *dma_addr, *paddr, *size); + +out: + of_node_put(node); + + return ret; +} +EXPORT_SYMBOL_GPL(of_dma_get_range); diff --git a/include/linux/of_address.h b/include/linux/of_address.h index 5f6ed6b..4d7b325 100644 --- a/include/linux/of_address.h +++ b/include/linux/of_address.h @@ -63,6 +63,8 @@ extern int of_pci_range_parser_init(struct of_pci_range_parser *parser, extern struct of_pci_range *of_pci_range_parser_one( struct of_pci_range_parser *parser, struct of_pci_range *range); +extern int of_dma_get_range(struct device_node *np, u64 *dma_addr, + u64 *paddr, u64 *size); #else /* CONFIG_OF_ADDRESS */ static inline struct device_node *of_find_matching_node_by_address( struct device_node *from, @@ -90,6 +92,12 @@ static inline struct of_pci_range *of_pci_range_parser_one( { return NULL; } + +static inline int of_dma_get_range(struct device_node *np, u64 *dma_addr, + u64 *paddr, u64 *size) +{ + return -ENODEV; +} #endif /* CONFIG_OF_ADDRESS */ #ifdef CONFIG_OF