diff options
author | Grygorii Strashko <grygorii.strashko@ti.com> | 2014-04-24 11:30:02 -0400 |
---|---|---|
committer | Santosh Shilimkar <santosh.shilimkar@ti.com> | 2014-05-05 18:11:13 -0400 |
commit | 18308c94723e162ed121942335bc186e66820a7a (patch) | |
tree | 48ac9d3721d820bdace974332f3925cc5dc2c02b /drivers/of | |
parent | 8febcaa2aac184d7e729acb75e9c4b80b04ad1b9 (diff) |
of: introduce of_dma_get_range() helper
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@linuxfoundation.org>
Cc: Russell King <linux@arm.linux.org.uk>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Olof Johansson <olof@lixom.net>
Cc: Grant Likely <grant.likely@linaro.org>
Cc: Catalin Marinas <catalin.marinas@arm.com>
Cc: Linus Walleij <linus.walleij@linaro.org>
Reviewed-by: Rob Herring <robh@kernel.org>
Signed-off-by: Grygorii Strashko <grygorii.strashko@ti.com>
Signed-off-by: Santosh Shilimkar <santosh.shilimkar@ti.com>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/address.c | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/drivers/of/address.c b/drivers/of/address.c index cb4242a69cd5..c54baee87d93 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) | |||
721 | return ioremap(res.start, resource_size(&res)); | 721 | return ioremap(res.start, resource_size(&res)); |
722 | } | 722 | } |
723 | EXPORT_SYMBOL(of_iomap); | 723 | EXPORT_SYMBOL(of_iomap); |
724 | |||
725 | /** | ||
726 | * of_dma_get_range - Get DMA range info | ||
727 | * @np: device node to get DMA range info | ||
728 | * @dma_addr: pointer to store initial DMA address of DMA range | ||
729 | * @paddr: pointer to store initial CPU address of DMA range | ||
730 | * @size: pointer to store size of DMA range | ||
731 | * | ||
732 | * Look in bottom up direction for the first "dma-ranges" property | ||
733 | * and parse it. | ||
734 | * dma-ranges format: | ||
735 | * DMA addr (dma_addr) : naddr cells | ||
736 | * CPU addr (phys_addr_t) : pna cells | ||
737 | * size : nsize cells | ||
738 | * | ||
739 | * It returns -ENODEV if "dma-ranges" property was not found | ||
740 | * for this device in DT. | ||
741 | */ | ||
742 | int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *size) | ||
743 | { | ||
744 | struct device_node *node = of_node_get(np); | ||
745 | const __be32 *ranges = NULL; | ||
746 | int len, naddr, nsize, pna; | ||
747 | int ret = 0; | ||
748 | u64 dmaaddr; | ||
749 | |||
750 | if (!node) | ||
751 | return -EINVAL; | ||
752 | |||
753 | while (1) { | ||
754 | naddr = of_n_addr_cells(node); | ||
755 | nsize = of_n_size_cells(node); | ||
756 | node = of_get_next_parent(node); | ||
757 | if (!node) | ||
758 | break; | ||
759 | |||
760 | ranges = of_get_property(node, "dma-ranges", &len); | ||
761 | |||
762 | /* Ignore empty ranges, they imply no translation required */ | ||
763 | if (ranges && len > 0) | ||
764 | break; | ||
765 | |||
766 | /* | ||
767 | * At least empty ranges has to be defined for parent node if | ||
768 | * DMA is supported | ||
769 | */ | ||
770 | if (!ranges) | ||
771 | break; | ||
772 | } | ||
773 | |||
774 | if (!ranges) { | ||
775 | pr_debug("%s: no dma-ranges found for node(%s)\n", | ||
776 | __func__, np->full_name); | ||
777 | ret = -ENODEV; | ||
778 | goto out; | ||
779 | } | ||
780 | |||
781 | len /= sizeof(u32); | ||
782 | |||
783 | pna = of_n_addr_cells(node); | ||
784 | |||
785 | /* dma-ranges format: | ||
786 | * DMA addr : naddr cells | ||
787 | * CPU addr : pna cells | ||
788 | * size : nsize cells | ||
789 | */ | ||
790 | dmaaddr = of_read_number(ranges, naddr); | ||
791 | *paddr = of_translate_dma_address(np, ranges); | ||
792 | if (*paddr == OF_BAD_ADDR) { | ||
793 | pr_err("%s: translation of DMA address(%pad) to CPU address failed node(%s)\n", | ||
794 | __func__, dma_addr, np->full_name); | ||
795 | ret = -EINVAL; | ||
796 | goto out; | ||
797 | } | ||
798 | *dma_addr = dmaaddr; | ||
799 | |||
800 | *size = of_read_number(ranges + naddr + pna, nsize); | ||
801 | |||
802 | pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", | ||
803 | *dma_addr, *paddr, *size); | ||
804 | |||
805 | out: | ||
806 | of_node_put(node); | ||
807 | |||
808 | return ret; | ||
809 | } | ||
810 | EXPORT_SYMBOL_GPL(of_dma_get_range); | ||