dmaengine Archive on lore.kernel.org
 help / color / Atom feed
From: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
To: robh+dt@kernel.org, devicetree@vger.kernel.org,
	frowand.list@gmail.com, linux-arm-kernel@lists.infradead.org,
	linux-wireless@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-arm-msm@vger.kernel.org, dmaengine@vger.kernel.org,
	etnaviv@lists.freedesktop.org, dri-devel@lists.freedesktop.org,
	xen-devel@lists.xenproject.org, linux-tegra@vger.kernel.org,
	linux-media@vger.kernel.org, linux-pci@vger.kernel.org
Cc: mbrugger@suse.com, robin.murphy@arm.com, f.fainelli@gmail.com,
	james.quinlan@broadcom.com, wahrenst@gmx.net,
	Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
Subject: [PATCH 04/11] of: address: introduce of_translate_dma_address_parent()
Date: Tue, 24 Sep 2019 20:12:35 +0200
Message-ID: <20190924181244.7159-5-nsaenzjulienne@suse.de> (raw)
In-Reply-To: <20190924181244.7159-1-nsaenzjulienne@suse.de>

Some devices might not have a DT node of their own, but might still need
to translate DMA addresses based on their bus DT node.

Update of_translate_dma_address() to only depend on the parent DT node.
Rename it to of_translate_dma_address_parent(). The later will be still
available as a wrapper around the new function.

Signed-off-by: Nicolas Saenz Julienne <nsaenzjulienne@suse.de>
---

 drivers/of/address.c | 60 ++++++++++++++++++++++++++------------------
 1 file changed, 36 insertions(+), 24 deletions(-)

diff --git a/drivers/of/address.c b/drivers/of/address.c
index 9c1e638fa8ea..c9eb4ebcc2e9 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -570,33 +570,32 @@ static int of_translate_one(struct device_node *parent, struct of_bus *bus,
  * device that had registered logical PIO mapping, and the return code is
  * relative to that node.
  */
-static u64 __of_translate_address(struct device_node *dev,
-				  struct device_node *(*get_parent)(const struct device_node *),
-				  const __be32 *in_addr, const char *rprop,
-				  struct device_node **host)
+static u64 __of_translate_address_parent(struct device_node *parent,
+					 struct device_node *(*get_parent)
+						(const struct device_node *),
+					 const __be32 *in_addr,
+					 const char *rprop,
+					 struct device_node **host)
 {
-	struct device_node *parent = NULL;
+	struct device_node *dev = NULL;
 	struct of_bus *bus, *pbus;
 	__be32 addr[OF_MAX_ADDR_CELLS];
 	int na, ns, pna, pns;
 	u64 result = OF_BAD_ADDR;
 
-	pr_debug("** translation for device %pOF **\n", dev);
-
-	/* Increase refcount at current level */
-	of_node_get(dev);
-
 	*host = NULL;
-	/* Get parent & match bus type */
-	parent = get_parent(dev);
-	if (parent == NULL)
+
+	if (!parent)
 		goto bail;
+
+	/* Increase refcount at current level and match bus type */
+	of_node_get(parent);
 	bus = of_match_bus(parent);
 
 	/* Count address cells & copy address locally */
 	bus->count_cells(parent, &na, &ns);
 	if (!OF_CHECK_COUNTS(na, ns)) {
-		pr_debug("Bad cell count for %pOF\n", dev);
+		pr_debug("Bad cell count for %pOF\n", parent);
 		goto bail;
 	}
 	memcpy(addr, in_addr, na * 4);
@@ -610,9 +609,8 @@ static u64 __of_translate_address(struct device_node *dev,
 		struct logic_pio_hwaddr *iorange;
 
 		/* Switch to parent bus */
-		of_node_put(dev);
 		dev = parent;
-		parent = get_parent(dev);
+		parent = get_parent(parent);
 
 		/* If root, we have finished */
 		if (parent == NULL) {
@@ -650,6 +648,8 @@ static u64 __of_translate_address(struct device_node *dev,
 			break;
 
 		/* Complete the move up one level */
+		of_node_put(dev);
+		dev = parent;
 		na = pna;
 		ns = pns;
 		bus = pbus;
@@ -668,8 +668,10 @@ u64 of_translate_address(struct device_node *dev, const __be32 *in_addr)
 	struct device_node *host;
 	u64 ret;
 
-	ret = __of_translate_address(dev, of_get_parent,
-				     in_addr, "ranges", &host);
+	pr_debug("** translation for device %pOF **\n", dev);
+
+	ret = __of_translate_address_parent(dev->parent, of_get_parent,
+					    in_addr, "ranges", &host);
 	if (host) {
 		of_node_put(host);
 		return OF_BAD_ADDR;
@@ -697,14 +699,14 @@ static struct device_node *__of_get_dma_parent(const struct device_node *np)
 	return of_node_get(args.np);
 }
 
-u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
+static u64 of_translate_dma_address_parent(struct device_node *parent,
+					   const __be32 *in_addr)
 {
 	struct device_node *host;
 	u64 ret;
 
-	ret = __of_translate_address(dev, __of_get_dma_parent,
-				     in_addr, "dma-ranges", &host);
-
+	ret = __of_translate_address_parent(parent, __of_get_dma_parent, in_addr,
+					    "dma-ranges", &host);
 	if (host) {
 		of_node_put(host);
 		return OF_BAD_ADDR;
@@ -712,6 +714,14 @@ u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
 
 	return ret;
 }
+
+u64 of_translate_dma_address(struct device_node *dev, const __be32 *in_addr)
+{
+	pr_debug("** translation for device %pOF **\n", dev);
+
+	return of_translate_dma_address_parent(__of_get_dma_parent(dev->parent),
+					       in_addr);
+}
 EXPORT_SYMBOL(of_translate_dma_address);
 
 const __be32 *of_get_address(struct device_node *dev, int index, u64 *size,
@@ -759,8 +769,10 @@ static u64 of_translate_ioport(struct device_node *dev, const __be32 *in_addr,
 	unsigned long port;
 	struct device_node *host;
 
-	taddr = __of_translate_address(dev, of_get_parent,
-				       in_addr, "ranges", &host);
+	pr_debug("** translation for device %pOF **\n", dev);
+
+	taddr = __of_translate_address_parent(dev->parent, of_get_parent,
+					      in_addr, "ranges", &host);
 	if (host) {
 		/* host-specific port access */
 		port = logic_pio_trans_hwaddr(&host->fwnode, taddr, size);
-- 
2.23.0


  parent reply index

Thread overview: 27+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-09-24 18:12 [PATCH 00/11] of: Fix DMA configuration for non-DT masters Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 01/11] of: address: clean-up unused variable in of_dma_get_range() Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 02/11] of: base: introduce __of_n_*_cells_parent() Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 03/11] of: address: use parent DT node in bus->count_cells() Nicolas Saenz Julienne
2019-09-24 18:12 ` Nicolas Saenz Julienne [this message]
2019-09-24 18:12 ` [PATCH 05/11] of: expose __of_get_dma_parent() to OF subsystem Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 06/11] of: address: use parent OF node in of_dma_get_range() Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 07/11] dts: arm64: layerscape: add dma-ranges property to qoric-mc node Nicolas Saenz Julienne
2019-10-14  8:28   ` Shawn Guo
2019-10-14 10:00     ` Nicolas Saenz Julienne
2019-10-14 11:09       ` Shawn Guo
2019-09-24 18:12 ` [PATCH 08/11] dts: arm64: layerscape: add dma-ranges property to pcie nodes Nicolas Saenz Julienne
2019-10-14  8:29   ` Shawn Guo
2019-09-24 18:12 ` [PATCH 09/11] of: device: remove comment in of_dma_configure() Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 10/11] of: device: introduce of_dma_configure_parent() Nicolas Saenz Julienne
2019-09-24 18:12 ` [PATCH 11/11] of: simplify of_dma_config()'s arguments Nicolas Saenz Julienne
2019-09-24 21:59 ` [PATCH 00/11] of: Fix DMA configuration for non-DT masters Rob Herring
2019-09-25 14:52   ` Nicolas Saenz Julienne
2019-09-25 15:09     ` Robin Murphy
2019-09-25 15:30       ` Nicolas Saenz Julienne
2019-09-25 16:16         ` Rob Herring
2019-09-25 16:52           ` Robin Murphy
2019-09-25 21:33             ` Rob Herring
2019-09-26 10:44               ` Nicolas Saenz Julienne
2019-09-26 11:20                 ` Robin Murphy
2019-10-02 18:28                   ` Florian Fainelli
2019-09-25 16:07     ` Rob Herring

Reply instructions:

You may reply publically to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190924181244.7159-5-nsaenzjulienne@suse.de \
    --to=nsaenzjulienne@suse.de \
    --cc=devicetree@vger.kernel.org \
    --cc=dmaengine@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=etnaviv@lists.freedesktop.org \
    --cc=f.fainelli@gmail.com \
    --cc=frowand.list@gmail.com \
    --cc=james.quinlan@broadcom.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-arm-msm@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-media@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-tegra@vger.kernel.org \
    --cc=linux-wireless@vger.kernel.org \
    --cc=mbrugger@suse.com \
    --cc=robh+dt@kernel.org \
    --cc=robin.murphy@arm.com \
    --cc=wahrenst@gmx.net \
    --cc=xen-devel@lists.xenproject.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link

dmaengine Archive on lore.kernel.org

Archives are clonable:
	git clone --mirror https://lore.kernel.org/dmaengine/0 dmaengine/git/0.git

	# If you have public-inbox 1.1+ installed, you may
	# initialize and index your mirror using the following commands:
	public-inbox-init -V2 dmaengine dmaengine/ https://lore.kernel.org/dmaengine \
		dmaengine@vger.kernel.org
	public-inbox-index dmaengine

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://nntp.lore.kernel.org/org.kernel.vger.dmaengine


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git