Kernel KVM virtualization development
 help / color / mirror / Atom feed
From: Andrew Jones <drjones@redhat.com>
To: kvm@vger.kernel.org
Cc: lvivier@redhat.com, thuth@redhat.com, pbonzini@redhat.com
Subject: [kvm-unit-tests PATCH 1/2] devicetree: search up tree in dt_get_nr_cells
Date: Tue, 10 May 2016 19:32:05 +0200	[thread overview]
Message-ID: <1462901526-11013-2-git-send-email-drjones@redhat.com> (raw)
In-Reply-To: <1462901526-11013-1-git-send-email-drjones@redhat.com>

Search up the tree until we find #address-cells/#size-cells.
Also only assign outputs if both address and size are found.

Signed-off-by: Andrew Jones <drjones@redhat.com>
---
 lib/devicetree.c | 17 +++++++++++++----
 lib/devicetree.h |  3 ++-
 2 files changed, 15 insertions(+), 5 deletions(-)

diff --git a/lib/devicetree.c b/lib/devicetree.c
index a5c7f7c69ddfd..d3751e2b7e7f9 100644
--- a/lib/devicetree.c
+++ b/lib/devicetree.c
@@ -24,21 +24,30 @@ int dt_get_nr_cells(int fdtnode, u32 *nr_address_cells, u32 *nr_size_cells)
 {
 	const struct fdt_property *prop;
 	u32 *nr_cells;
-	int len;
+	int len, nac, nsc;
+
+	while (1) {
+		prop = fdt_get_property(fdt, fdtnode, "#address-cells", &len);
+		if (prop != NULL || len != -FDT_ERR_NOTFOUND)
+			break;
+		fdtnode = fdt_parent_offset(fdt, fdtnode);
+	}
 
-	prop = fdt_get_property(fdt, fdtnode, "#address-cells", &len);
 	if (prop == NULL)
 		return len;
 
 	nr_cells = (u32 *)prop->data;
-	*nr_address_cells = fdt32_to_cpu(*nr_cells);
+	nac = fdt32_to_cpu(*nr_cells);
 
 	prop = fdt_get_property(fdt, fdtnode, "#size-cells", &len);
 	if (prop == NULL)
 		return len;
 
 	nr_cells = (u32 *)prop->data;
-	*nr_size_cells = fdt32_to_cpu(*nr_cells);
+	nsc = fdt32_to_cpu(*nr_cells);
+
+	*nr_address_cells = nac;
+	*nr_size_cells = nsc;
 
 	return 0;
 }
diff --git a/lib/devicetree.h b/lib/devicetree.h
index c8c86eeae28b6..09f2509409615 100644
--- a/lib/devicetree.h
+++ b/lib/devicetree.h
@@ -168,7 +168,8 @@ extern int dt_pbus_get_base_compatible(const char *compatible,
 
 /*
  * dt_get_nr_cells sets @nr_address_cells and @nr_size_cells to the
- * #address-cells and #size-cells properties of @fdtnode
+ * #address-cells and #size-cells properties of @fdtnode, potentially
+ * searching up the tree to find them in a parent node.
  * returns
  *  - zero on success
  *  - a negative FDT_ERR_* value on failure
-- 
2.4.11


  reply	other threads:[~2016-05-10 17:32 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-05-10 17:32 [kvm-unit-tests PATCH 0/2] devicetree: use correct #address/#size cells Andrew Jones
2016-05-10 17:32 ` Andrew Jones [this message]
2016-05-11  7:02   ` [kvm-unit-tests PATCH 1/2] devicetree: search up tree in dt_get_nr_cells Thomas Huth
2016-05-11  9:04     ` Andrew Jones
2016-05-11  9:28       ` Thomas Huth
2016-05-11 11:23         ` Andrew Jones
2016-05-10 17:32 ` [kvm-unit-tests PATCH 2/2] devicetree: use node #address/size-cells Andrew Jones
2016-05-11  7:12   ` Thomas Huth
2016-05-11  9:09     ` Andrew Jones

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=1462901526-11013-2-git-send-email-drjones@redhat.com \
    --to=drjones@redhat.com \
    --cc=kvm@vger.kernel.org \
    --cc=lvivier@redhat.com \
    --cc=pbonzini@redhat.com \
    --cc=thuth@redhat.com \
    /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