Commit 7a8b64d1 authored by Rob Herring's avatar Rob Herring

of/address: use range parser for of_dma_get_range

of_dma_get_range() does the same ranges parsing as
of_pci_range_parser_one(), so let's refactor of_dma_get_range() to use
it instead.

This commit is no functional change. Subsequent commits will parse more
than the 1st dma-ranges entry.
Signed-off-by: default avatarRob Herring <robh@kernel.org>
parent bc5e522e
...@@ -939,10 +939,11 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz ...@@ -939,10 +939,11 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz
{ {
struct device_node *node = of_node_get(np); struct device_node *node = of_node_get(np);
const __be32 *ranges = NULL; const __be32 *ranges = NULL;
int len, naddr, nsize, pna; int len;
int ret = 0; int ret = 0;
bool found_dma_ranges = false; bool found_dma_ranges = false;
u64 dmaaddr; struct of_range_parser parser;
struct of_range range;
while (node) { while (node) {
ranges = of_get_property(node, "dma-ranges", &len); ranges = of_get_property(node, "dma-ranges", &len);
...@@ -967,33 +968,20 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz ...@@ -967,33 +968,20 @@ int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz
goto out; goto out;
} }
naddr = of_bus_n_addr_cells(node); of_dma_range_parser_init(&parser, node);
nsize = of_bus_n_size_cells(node);
pna = of_n_addr_cells(node); for_each_of_range(&parser, &range) {
if ((len / sizeof(__be32)) % (pna + naddr + nsize)) { pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n",
ret = -EINVAL; range.bus_addr, range.cpu_addr, range.size);
goto out;
} *dma_addr = range.bus_addr;
*paddr = range.cpu_addr;
*size = range.size;
/* 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(node, ranges + naddr);
if (*paddr == OF_BAD_ADDR) {
pr_err("translation of DMA address(%llx) to CPU address failed node(%pOF)\n",
dmaaddr, np);
ret = -EINVAL;
goto out; goto out;
} }
*dma_addr = dmaaddr;
*size = of_read_number(ranges + naddr + pna, nsize);
pr_debug("dma_addr(%llx) cpu_addr(%llx) size(%llx)\n", pr_err("translation of DMA ranges failed on node(%pOF)\n", np);
*dma_addr, *paddr, *size);
out: out:
of_node_put(node); of_node_put(node);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment