linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dario Binacchi <dariobin@libero.it>
To: linux-kernel@vger.kernel.org
Cc: Dario Binacchi <dariobin@libero.it>,
	Bin Meng <bmeng.cn@gmail.com>,
	Frank Rowand <frowand.list@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	devicetree@vger.kernel.org
Subject: [PATCH 1/2] fdt: translate address if #size-cells = <0>
Date: Fri,  2 Apr 2021 21:20:53 +0200	[thread overview]
Message-ID: <20210402192054.7934-2-dariobin@libero.it> (raw)
In-Reply-To: <20210402192054.7934-1-dariobin@libero.it>

The __of_translate_address() translates an address from the device tree
into a CPU physical address. A note in the description of the routine
explains that the crossing of any level with #size-cells = <0> can not
be mapped to a CPU physical address not because it's really specified
that way, but because this is traditionally the way IBM at least do
things. This does not happen for Texas Instruments, or at least for the
beaglebone device tree. Without this patch, in fact, the translation into
physical addresses of the registers contained in the am33xx-clocks.dtsi
nodes would not be possible. They all have a parent with #size-cells = <0>.

The CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS symbol makes translation
possible even in the case of crossing levels with #size-cells = <0>.

The patch has been tested on a beaglebone black board. The addresses
generated for the clock registers are those specified by the AM335x
reference manual.

Signed-off-by: Dario Binacchi <dariobin@libero.it>
---

 drivers/of/Kconfig       | 13 +++++++++++++
 drivers/of/address.c     |  8 +++++++-
 drivers/of/fdt_address.c |  6 ++++--
 3 files changed, 24 insertions(+), 3 deletions(-)

diff --git a/drivers/of/Kconfig b/drivers/of/Kconfig
index 18450437d5d5..5a76c8c23de6 100644
--- a/drivers/of/Kconfig
+++ b/drivers/of/Kconfig
@@ -100,4 +100,17 @@ config OF_DMA_DEFAULT_COHERENT
 	# arches should select this if DMA is coherent by default for OF devices
 	bool
 
+
+config OF_TRANSLATE_ZERO_SIZE_CELLS
+	bool "Enable translation for zero size cells"
+	depends on OF_EARLY_FLATTREE || OF_ADDRESS
+	default y if SOC_AM33XX
+	help
+	  The routine used to translate an FDT address into a physical CPU
+	  address was developed by IBM. It considers that crossing any level
+	  with #size-cells = <0> makes translation impossible, even if it is
+	  not the way it was specified.
+	  Enabling this option makes translation possible even in the case
+	  of crossing levels with #size-cells = <0>.
+
 endif # OF
diff --git a/drivers/of/address.c b/drivers/of/address.c
index 73ddf2540f3f..7b7ef69fb126 100644
--- a/drivers/of/address.c
+++ b/drivers/of/address.c
@@ -20,7 +20,10 @@
 /* Max address size we deal with */
 #define OF_MAX_ADDR_CELLS	4
 #define OF_CHECK_ADDR_COUNT(na)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS)
-#define OF_CHECK_COUNTS(na, ns)	(OF_CHECK_ADDR_COUNT(na) && (ns) > 0)
+#define OF_CHECK_COUNTS(na, ns)						\
+	(OF_CHECK_ADDR_COUNT(na) &&					\
+	 ((ns) > 0 || (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) && \
+		      (ns) == 0)))
 
 static struct of_bus *of_match_bus(struct device_node *np);
 static int __of_address_to_resource(struct device_node *dev,
@@ -420,6 +423,9 @@ static struct of_bus *of_match_bus(struct device_node *np)
 
 static int of_empty_ranges_quirk(struct device_node *np)
 {
+	if (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS))
+		return true;
+
 	if (IS_ENABLED(CONFIG_PPC)) {
 		/* To save cycles, we cache the result for global "Mac" setting */
 		static int quirk_state = -1;
diff --git a/drivers/of/fdt_address.c b/drivers/of/fdt_address.c
index 1dc15ab78b10..09c78c94c1b5 100644
--- a/drivers/of/fdt_address.c
+++ b/drivers/of/fdt_address.c
@@ -19,8 +19,10 @@
 
 /* Max address size we deal with */
 #define OF_MAX_ADDR_CELLS	4
-#define OF_CHECK_COUNTS(na, ns)	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS && \
-			(ns) > 0)
+#define OF_CHECK_COUNTS(na, ns)						\
+	((na) > 0 && (na) <= OF_MAX_ADDR_CELLS &&			\
+	 ((ns) > 0 || (IS_ENABLED(CONFIG_OF_TRANSLATE_ZERO_SIZE_CELLS) && \
+		       (ns) == 0)))
 
 /* Debug utility */
 #ifdef DEBUG
-- 
2.17.1


  reply	other threads:[~2021-04-02 19:21 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-02 19:20 [PATCH 0/2] fdt: translate address if #size-cells = <0> Dario Binacchi
2021-04-02 19:20 ` Dario Binacchi [this message]
2021-04-02 19:20 ` [PATCH 2/2] clk: ti: get register address from device tree Dario Binacchi
2021-04-06  6:02   ` Tero Kristo
2021-04-06 14:06 ` [PATCH 0/2] fdt: translate address if #size-cells = <0> Rob Herring
2021-04-06 22:02   ` Dario Binacchi
2021-04-07  1:16     ` Rob Herring
2021-04-07  7:07       ` Dario Binacchi
2021-04-07 12:52         ` Rob Herring
2021-04-07 13:21           ` Tero Kristo
2021-04-08 20:24             ` Dario Binacchi
2021-04-09 10:32               ` Tero Kristo
2021-04-11 19:30                 ` Dario Binacchi
2021-04-12  7:41                   ` Tero Kristo
2021-04-14 20:39                     ` Dario Binacchi
2021-04-17  8:37                       ` Tony Lindgren

Reply instructions:

You may reply publicly 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=20210402192054.7934-2-dariobin@libero.it \
    --to=dariobin@libero.it \
    --cc=bmeng.cn@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=frowand.list@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.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
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).