[v2,4/7] of: address: Add support for the dma-parent property

Message ID 824396752ee40c8e4222fddb4a80408646989c17.1549482066.git-series.maxime.ripard@bootlin.com
State Superseded
Headers show
Series
  • sunxi: Add DT representation for the MBUS controller
Related show

Checks

Context Check Description
robh/checkpatch success

Commit Message

Maxime Ripard Feb. 6, 2019, 7:41 p.m.
Some SoCs have devices that are using a separate bus from the main bus to
perform DMA.

These buses might have some restrictions and/or different mapping than from
the CPU side, so we'd need to express those using the usual dma-ranges, but
using a different DT node than the node's parent.

Add support for a dma-parent property that links to the DMA bus used by the
device in such a case.

Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
---
 drivers/of/address.c | 34 +++++++++++++++++++++++++++++++---
 1 file changed, 31 insertions(+), 3 deletions(-)

Comments

Rob Herring Feb. 6, 2019, 8:57 p.m. | #1
On Wed, Feb 6, 2019 at 1:42 PM Maxime Ripard <maxime.ripard@bootlin.com> wrote:
>
> Some SoCs have devices that are using a separate bus from the main bus to
> perform DMA.
>
> These buses might have some restrictions and/or different mapping than from
> the CPU side, so we'd need to express those using the usual dma-ranges, but
> using a different DT node than the node's parent.
>
> Add support for a dma-parent property that links to the DMA bus used by the
> device in such a case.

?? dma-parent is gone now, right? And I see #dma-parent-cells?

Rob
Maxime Ripard Feb. 11, 2019, 1:09 p.m. | #2
On Wed, Feb 06, 2019 at 02:57:51PM -0600, Rob Herring wrote:
> On Wed, Feb 6, 2019 at 1:42 PM Maxime Ripard <maxime.ripard@bootlin.com> wrote:
> >
> > Some SoCs have devices that are using a separate bus from the main bus to
> > perform DMA.
> >
> > These buses might have some restrictions and/or different mapping than from
> > the CPU side, so we'd need to express those using the usual dma-ranges, but
> > using a different DT node than the node's parent.
> >
> > Add support for a dma-parent property that links to the DMA bus used by the
> > device in such a case.
> 
> ?? dma-parent is gone now, right? And I see #dma-parent-cells?

Urgh, right... I forgot to update the commit log, I'll resend it.

Maxime

Patch

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 4c5dc21c71ca..0e9d87a664f5 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -583,8 +583,8 @@  static u64 __of_translate_address(struct device_node *dev,
 	/* Increase refcount at current level */
 	of_node_get(dev);
 
+	*host = NULL;
 	if (!parent) {
-		*host = NULL;
 		/* Get parent & match bus type */
 		parent = of_get_parent(dev);
 		if (parent == NULL)
@@ -678,12 +678,34 @@  u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
 }
 EXPORT_SYMBOL(of_translate_address);
 
+static struct device_node *__of_get_dma_parent(struct device_node *np)
+{
+	struct of_phandle_args args;
+	unsigned int index;
+	int ret;
+
+	ret = of_property_match_string(np, "interconnect-names", "dma");
+	if (ret < 0)
+		return of_get_parent(np);
+
+	ret = of_parse_phandle_with_args(np, "interconnects",
+					 "#interconnect-cells",
+					 index, &args);
+	if (ret < 0)
+		return of_get_parent(np);
+
+	return of_node_get(args.np);
+}
+
 u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
 {
+	struct device_node *parent;
 	struct device_node *host;
 	u64 ret;
 
-	ret = __of_translate_address(dev, NULL, in_addr, "dma-ranges", &host);
+	parent = __of_get_dma_parent(dev);
+	ret = __of_translate_address(dev, parent, in_addr, "dma-ranges", &host);
+	of_node_put(parent);
 
 	if (host) {
 		of_node_put(host);
@@ -911,9 +933,15 @@  int of_dma_get_range(struct device_node *np, u64 *dma_addr, u64 *paddr, u64 *siz
 		return -EINVAL;
 
 	while (1) {
+		struct device_node *parent;
+
 		naddr = of_n_addr_cells(node);
 		nsize = of_n_size_cells(node);
-		node = of_get_next_parent(node);
+
+		parent = __of_get_dma_parent(node);
+		of_node_put(node);
+
+		node = parent;
 		if (!node)
 			break;