Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Maxime Ripard and committed by
Rob Herring
95835a8d e5ffa40c

+9 -5
+9 -5
drivers/of/address.c
··· 569 569 * relative to that node. 570 570 */ 571 571 static u64 __of_translate_address(struct device_node *dev, 572 + struct device_node *(*get_parent)(const struct device_node *), 572 573 const __be32 *in_addr, const char *rprop, 573 574 struct device_node **host) 574 575 { ··· 586 585 587 586 *host = NULL; 588 587 /* Get parent & match bus type */ 589 - parent = of_get_parent(dev); 588 + parent = get_parent(dev); 590 589 if (parent == NULL) 591 590 goto bail; 592 591 bus = of_match_bus(parent); ··· 610 609 /* Switch to parent bus */ 611 610 of_node_put(dev); 612 611 dev = parent; 613 - parent = of_get_parent(dev); 612 + parent = get_parent(dev); 614 613 615 614 /* If root, we have finished */ 616 615 if (parent == NULL) { ··· 666 665 struct device_node *host; 667 666 u64 ret; 668 667 669 - ret = __of_translate_address(dev, in_addr, "ranges", &host); 668 + ret = __of_translate_address(dev, of_get_parent, 669 + in_addr, "ranges", &host); 670 670 if (host) { 671 671 of_node_put(host); 672 672 return OF_BAD_ADDR; ··· 682 680 struct device_node *host; 683 681 u64 ret; 684 682 685 - ret = __of_translate_address(dev, in_addr, "dma-ranges", &host); 683 + ret = __of_translate_address(dev, of_get_parent, 684 + in_addr, "dma-ranges", &host); 686 685 687 686 if (host) { 688 687 of_node_put(host); ··· 739 736 unsigned long port; 740 737 struct device_node *host; 741 738 742 - taddr = __of_translate_address(dev, in_addr, "ranges", &host); 739 + taddr = __of_translate_address(dev, of_get_parent, 740 + in_addr, "ranges", &host); 743 741 if (host) { 744 742 /* host-specific port access */ 745 743 port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size);