All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thierry Reding <thierry.reding@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 2/6] fdtdec: Implement fdtdec_get_max_phandle()
Date: Fri,  8 Mar 2019 21:11:36 +0100	[thread overview]
Message-ID: <20190308201140.2383-2-thierry.reding@gmail.com> (raw)
In-Reply-To: <20190308201140.2383-1-thierry.reding@gmail.com>

From: Thierry Reding <treding@nvidia.com>

This function allows looking up the highest phandle value stored in a
device tree, which is useful to determine the next best phandle value
for new nodes.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 include/fdtdec.h | 12 ++++++++++++
 lib/fdtdec.c     | 28 ++++++++++++++++++++++++++++
 2 files changed, 40 insertions(+)

diff --git a/include/fdtdec.h b/include/fdtdec.h
index a965c33157c9..5eb3c0c237a9 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -956,6 +956,18 @@ int fdtdec_setup_mem_size_base(void);
  */
 int fdtdec_setup_memory_banksize(void);
 
+/**
+ * fdtdec_get_max_phandle() - return the highest phandle in an FDT blob
+ *
+ * Returns the highest phandle in the given FDT blob. The result of this can
+ * be used to generate a new phandle by incrementing by one.
+ *
+ * @param blob	FDT blob
+ * @param maxp	return location for the highest phandle in the FDT blob
+ * @return 0 on success or a negative error code on failure
+ */
+int fdtdec_get_max_phandle(const void *blob, uint32_t *maxp);
+
 /**
  * Set up the device tree ready for use
  */
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 09a7e133a539..f2af947c106e 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -1243,6 +1243,34 @@ __weak void *board_fdt_blob_setup(void)
 }
 #endif
 
+int fdtdec_get_max_phandle(const void *blob, uint32_t *maxp)
+{
+	uint32_t max = 0;
+	int offset = -1;
+
+	while (true) {
+		uint32_t phandle;
+
+		offset = fdt_next_node(blob, offset, NULL);
+		if (offset < 0) {
+			if (offset == -FDT_ERR_NOTFOUND)
+				break;
+
+			return offset;
+		}
+
+		phandle = fdt_get_phandle(blob, offset);
+
+		if (phandle > max)
+			max = phandle;
+	}
+
+	if (maxp)
+		*maxp = max;
+
+	return 0;
+}
+
 int fdtdec_setup(void)
 {
 #if CONFIG_IS_ENABLED(OF_CONTROL)
-- 
2.20.1

  reply	other threads:[~2019-03-08 20:11 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-08 20:11 [U-Boot] [PATCH 1/6] fdtdec: Add cpu_to_fdt_{addr,size}() macros Thierry Reding
2019-03-08 20:11 ` Thierry Reding [this message]
2019-03-10 21:51   ` [U-Boot] [PATCH 2/6] fdtdec: Implement fdtdec_get_max_phandle() Simon Glass
2019-03-11  9:27     ` Thierry Reding
2019-03-19  1:24       ` Simon Glass
2019-03-08 20:11 ` [U-Boot] [PATCH 3/6] fdtdec: Implement fdtdec_set_phandle() Thierry Reding
2019-03-10 21:51   ` Simon Glass
2019-03-11 10:04     ` Thierry Reding
2019-03-19  1:24       ` Simon Glass
2019-03-08 20:11 ` [U-Boot] [PATCH 4/6] fdtdec: Implement fdtdec_add_reserved_memory() Thierry Reding
2019-03-10 21:51   ` Simon Glass
2019-03-11 10:06     ` Thierry Reding
2019-03-19  1:24       ` Simon Glass
2019-03-08 20:11 ` [U-Boot] [PATCH 5/6] fdtdec: Implement carveout support functions Thierry Reding
2019-03-10 21:51   ` Simon Glass
2019-03-08 20:11 ` [U-Boot] [PATCH 6/6] p2371-2180: Add support for framebuffer carveouts Thierry Reding
2019-03-19  1:24   ` Simon Glass
2019-03-10 21:51 ` [U-Boot] [PATCH 1/6] fdtdec: Add cpu_to_fdt_{addr, size}() macros Simon Glass

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=20190308201140.2383-2-thierry.reding@gmail.com \
    --to=thierry.reding@gmail.com \
    --cc=u-boot@lists.denx.de \
    /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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.