[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <CAL_Jsq+j_mVp2F=Cb4F+i2Q-B4A7YLvLCP+YnAxkUJT2S+rcQQ@mail.gmail.com>
Date: Thu, 1 May 2014 20:06:25 -0500
From: Rob Herring <robherring2@...il.com>
To: Santosh Shilimkar <santosh.shilimkar@...com>
Cc: "linux-kernel@...r.kernel.org" <linux-kernel@...r.kernel.org>,
"linux-arm-kernel@...ts.infradead.org"
<linux-arm-kernel@...ts.infradead.org>,
"devicetree@...r.kernel.org" <devicetree@...r.kernel.org>,
Grygorii Strashko <grygorii.strashko@...com>,
Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Russell King <linux@....linux.org.uk>,
Arnd Bergmann <arnd@...db.de>, Olof Johansson <olof@...om.net>,
Grant Likely <grant.likely@...aro.org>,
Rob Herring <robh+dt@...nel.org>,
Catalin Marinas <catalin.marinas@....com>,
Linus Walleij <linus.walleij@...aro.org>
Subject: Re: [PATCH v3 2/7] of: introduce of_dma_get_range() helper
On Thu, Apr 24, 2014 at 10:30 AM, Santosh Shilimkar
<santosh.shilimkar@...com> wrote:
> From: Grygorii Strashko <grygorii.strashko@...com>
>
> 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 <gregkh@...uxfoundation.org>
> Cc: Russell King <linux@....linux.org.uk>
> Cc: Arnd Bergmann <arnd@...db.de>
> Cc: Olof Johansson <olof@...om.net>
> Cc: Grant Likely <grant.likely@...aro.org>
> Cc: Rob Herring <robh+dt@...nel.org>
> Cc: Catalin Marinas <catalin.marinas@....com>
> Cc: Linus Walleij <linus.walleij@...aro.org>
> Signed-off-by: Grygorii Strashko <grygorii.strashko@...com>
> Signed-off-by: Santosh Shilimkar <santosh.shilimkar@...com>
Reviewed-by: Rob Herring <robh@...nel.org>
> ---
> 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
> --
> 1.7.9.5
>
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists