Skip to content

Commit 95835a8

Browse files
mripardrobherring
authored andcommitted
of: address: Retrieve a parent through a callback in __of_translate_address
The __of_translate_address function is used to translate the device tree addresses to physical addresses using the various ranges property to create the offset. However, it's shared between the CPU addresses (based on the ranges property) and the DMA addresses (based on dma-ranges). Since we're going to add support for a DMA parent node that is not the DT parent node, we need to change the logic a bit to have a callback function that will retrieve the parent node we should use. Reviewed-by: Robin Murphy <robin.murphy@arm.com> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com> Signed-off-by: Rob Herring <robh@kernel.org>
1 parent e5ffa40 commit 95835a8

1 file changed

Lines changed: 9 additions & 5 deletions

File tree

‎drivers/of/address.c‎

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -569,6 +569,7 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
569569
* relative to that node.
570570
*/
571571
static u64 __of_translate_address(struct device_node *dev,
572+
struct device_node *(*get_parent)(const struct device_node *),
572573
const __be32 *in_addr, const char *rprop,
573574
struct device_node **host)
574575
{
@@ -585,7 +586,7 @@ static u64 __of_translate_address(struct device_node *dev,
585586

586587
*host = NULL;
587588
/* Get parent & match bus type */
588-
parent = of_get_parent(dev);
589+
parent = get_parent(dev);
589590
if (parent == NULL)
590591
goto bail;
591592
bus = of_match_bus(parent);
@@ -609,7 +610,7 @@ static u64 __of_translate_address(struct device_node *dev,
609610
/* Switch to parent bus */
610611
of_node_put(dev);
611612
dev = parent;
612-
parent = of_get_parent(dev);
613+
parent = get_parent(dev);
613614

614615
/* If root, we have finished */
615616
if (parent == NULL) {
@@ -665,7 +666,8 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
665666
struct device_node *host;
666667
u64 ret;
667668

668-
ret = __of_translate_address(dev, in_addr, "ranges", &host);
669+
ret = __of_translate_address(dev, of_get_parent,
670+
in_addr, "ranges", &host);
669671
if (host) {
670672
of_node_put(host);
671673
return OF_BAD_ADDR;
@@ -680,7 +682,8 @@ u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
680682
struct device_node *host;
681683
u64 ret;
682684

683-
ret = __of_translate_address(dev, in_addr, "dma-ranges", &host);
685+
ret = __of_translate_address(dev, of_get_parent,
686+
in_addr, "dma-ranges", &host);
684687

685688
if (host) {
686689
of_node_put(host);
@@ -736,7 +739,8 @@ static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr,
736739
unsigned long port;
737740
struct device_node *host;
738741

739-
taddr = __of_translate_address(dev, in_addr, "ranges", &host);
742+
taddr = __of_translate_address(dev, of_get_parent,
743+
in_addr, "ranges", &host);
740744
if (host) {
741745
/* host-specific port access */
742746
port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size);

0 commit comments

Comments
 (0)