public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Jerry Van Baren <gvb.uboot@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot-Users] [PATCH 1/2] libfdt: Add some utilities to manipulate the reserved memory map.
Date: Sat, 14 Apr 2007 23:42:14 -0400	[thread overview]
Message-ID: <20070415034214.GC8130@dellserver.lan> (raw)

Signed-off-by: Gerald Van Baren <vanbaren@cideas.com>
---
 include/libfdt.h |    5 +++
 libfdt/fdt_ro.c  |   72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 libfdt/fdt_wip.c |   26 +++++++++++++++++++
 3 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/include/libfdt.h b/include/libfdt.h
index 61f56ec..f8bac73 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -86,6 +86,8 @@ void *fdt_getprop(const void *fdt, int nodeoffset,
 
 uint32_t fdt_next_tag(const void *fdt, int offset,
 		      int *nextoffset, char **namep);
+int fdt_num_reservemap(void *fdt, int *used, int *total);
+int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re);
 
 /* Write-in-place functions */
 int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
@@ -99,6 +101,8 @@ int fdt_setprop_inplace(void *fdt, int nodeoffset, const char *name,
 
 int fdt_nop_property(void *fdt, int nodeoffset, const char *name);
 int fdt_nop_node(void *fdt, int nodeoffset);
+int fdt_insert_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size);
+
 
 /* Sequential-write functions */
 int fdt_create(void *buf, int bufsize);
@@ -115,6 +119,7 @@ int fdt_property(void *fdt, const char *name, const void *val, int len);
 	fdt_property(fdt, name, str, strlen(str)+1)
 int fdt_end_node(void *fdt);
 int fdt_finish(void *fdt);
+int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size);
 
 /* Read-write functions */
 int fdt_open_into(void *fdt, void *buf, int bufsize);
diff --git a/libfdt/fdt_ro.c b/libfdt/fdt_ro.c
index 2711324..af33336 100644
--- a/libfdt/fdt_ro.c
+++ b/libfdt/fdt_ro.c
@@ -329,3 +329,75 @@ uint32_t fdt_next_tag(const void *fdt, int offset, int *nextoffset, char **namep
 
 	return tag;
 }
+
+/*
+ * Return the number of used reserve map entries and total slots available.
+ */
+int fdt_num_reservemap(void *fdt, int *used, int *total)
+{
+	struct fdt_reserve_entry *re;
+	int  start;
+	int  end;
+	int  err = fdt_check_header(fdt);
+
+	if (err != 0)
+		return err;
+
+	start = fdt_off_mem_rsvmap(fdt);
+
+	/*
+	 * Convention is that the reserve map is before the dt_struct,
+	 * but it does not have to be.
+	 */
+	end = fdt_totalsize(fdt);
+	if (end > fdt_off_dt_struct(fdt))
+		end = fdt_off_dt_struct(fdt);
+	if (end > fdt_off_dt_strings(fdt))
+		end = fdt_off_dt_strings(fdt);
+
+	/*
+	 * Since the reserved area list is zero terminated, you get one fewer.
+	 */
+	if (total)
+		*total = ((end - start) / sizeof(struct fdt_reserve_entry)) - 1;
+
+	if (used) {
+		*used = 0;
+		while (start < end) {
+			re = (struct fdt_reserve_entry *)(fdt + start);
+			if (re->size == 0)
+				return 0;	/* zero size terminates the list */
+
+			*used += 1;
+			start += sizeof(struct fdt_reserve_entry);
+		}
+		/*
+		 * If we get here, there was no zero size termination.
+		 */
+		return -FDT_ERR_BADLAYOUT;
+	}
+	return 0;
+}
+
+/*
+ * Return the nth reserve map entry.
+ */
+int fdt_get_reservemap(void *fdt, int n, struct fdt_reserve_entry *re)
+{
+	int  used;
+	int  total;
+	int  err;
+
+	err = fdt_num_reservemap(fdt, &used, &total);
+	if (err != 0)
+		return err;
+
+	if (n >= total)
+		return -FDT_ERR_NOSPACE;
+	if (re) {
+		*re = *(struct fdt_reserve_entry *)
+			_fdt_offset_ptr(fdt, n * sizeof(struct fdt_reserve_entry));
+	}
+	return 0;
+}
+
diff --git a/libfdt/fdt_wip.c b/libfdt/fdt_wip.c
index 261b9b0..cf81183 100644
--- a/libfdt/fdt_wip.c
+++ b/libfdt/fdt_wip.c
@@ -110,3 +110,29 @@ int fdt_nop_node(void *fdt, int nodeoffset)
 	nop_region(fdt_offset_ptr(fdt, nodeoffset, 0), endoffset - nodeoffset);
 	return 0;
 }
+
+/*
+ * Replace a reserve map entry in the nth slot.
+ */
+int fdt_replace_reservemap_entry(void *fdt, int n, uint64_t addr, uint64_t size)
+{
+	struct fdt_reserve_entry *re;
+	int  used;
+	int  total;
+	int  err;
+
+	err = fdt_num_reservemap(fdt, &used, &total);
+	if (err != 0)
+		return err;
+
+	if (n >= total)
+		return -FDT_ERR_NOSPACE;
+	re = (struct fdt_reserve_entry *)
+		(fdt + fdt_off_mem_rsvmap(fdt) +
+		 (n * sizeof(struct fdt_reserve_entry)));
+	re->address = cpu_to_fdt64(addr);
+	re->size    = cpu_to_fdt64(size);
+
+	return 0;
+}
+
-- 
1.4.4.4

             reply	other threads:[~2007-04-15  3:42 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-04-15  3:42 Jerry Van Baren [this message]
2007-04-15 12:23 ` [U-Boot-Users] [PATCH 1/2] libfdt: Add some utilities to manipulate the reserved memory map Jerry Van Baren

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=20070415034214.GC8130@dellserver.lan \
    --to=gvb.uboot@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox