From: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
To: U-Boot Mailing List <u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org>
Cc: Tom Rini <trini-l0cyMroinI0@public.gmane.org>,
Jerry Van Baren
<vanbaren-He//nVnquyzQT0dZR+AlfA@public.gmane.org>,
Devicetree Discuss
<devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org>
Subject: [PATCH 03/14] fdt: Add fdtdec_decode_region() to decode memory region
Date: Thu, 25 Oct 2012 19:31:00 -0700 [thread overview]
Message-ID: <1351218671-15228-4-git-send-email-sjg@chromium.org> (raw)
In-Reply-To: <1351218671-15228-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
A memory region has a start and a size and is often specified in
a node by a 'reg' property. Add a function to decode this information
from the fdt.
Signed-off-by: Simon Glass <sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
---
include/fdtdec.h | 19 +++++++++++++++++++
lib/fdtdec.c | 17 +++++++++++++++++
2 files changed, 36 insertions(+), 0 deletions(-)
diff --git a/include/fdtdec.h b/include/fdtdec.h
index e828662..341e6a1 100644
--- a/include/fdtdec.h
+++ b/include/fdtdec.h
@@ -40,10 +40,12 @@
typedef u64 fdt_addr_t;
#define FDT_ADDR_T_NONE (-1ULL)
#define fdt_addr_to_cpu(reg) be64_to_cpu(reg)
+#define fdt_size_to_cpu(reg) be64_to_cpu(reg)
#else
typedef u32 fdt_addr_t;
#define FDT_ADDR_T_NONE (-1U)
#define fdt_addr_to_cpu(reg) be32_to_cpu(reg)
+#define fdt_size_to_cpu(reg) be32_to_cpu(reg)
#endif
/* Information obtained about memory from the FDT */
@@ -408,4 +410,21 @@ int fdtdec_get_byte_array(const void *blob, int node, const char *prop_name,
*/
const u8 *fdtdec_locate_byte_array(const void *blob, int node,
const char *prop_name, int count);
+
+/**
+ * Look up a property in a node which contains a memory region address and
+ * size. Then return a pointer to this address.
+ *
+ * The property must hold one address with a length. This is only tested on
+ * 32-bit machines.
+ *
+ * @param blob FDT blob
+ * @param node node to examine
+ * @param prop_name name of property to find
+ * @param ptrp returns pointer to region, or NULL if no address
+ * @param size returns size of region
+ * @return 0 if ok, -1 on error (propery not found)
+ */
+int fdtdec_decode_region(const void *blob, int node,
+ const char *prop_name, void **ptrp, size_t *size);
#endif
diff --git a/lib/fdtdec.c b/lib/fdtdec.c
index 2d60c8a..5570972 100644
--- a/lib/fdtdec.c
+++ b/lib/fdtdec.c
@@ -542,3 +542,20 @@ char *fdtdec_get_config_string(const void *blob, const char *prop_name)
return (char *)nodep;
}
+
+int fdtdec_decode_region(const void *blob, int node,
+ const char *prop_name, void **ptrp, size_t *size)
+{
+ const fdt_addr_t *cell;
+ int len;
+
+ debug("%s: %s\n", __func__, prop_name);
+ cell = fdt_getprop(blob, node, prop_name, &len);
+ if (!cell || (len != sizeof(fdt_addr_t) * 2))
+ return -1;
+
+ *ptrp = (void *)fdt_addr_to_cpu(*cell);
+ *size = fdt_size_to_cpu(cell[1]);
+ debug("%s: size=%zx\n", __func__, *size);
+ return 0;
+}
--
1.7.7.3
next prev parent reply other threads:[~2012-10-26 2:31 UTC|newest]
Thread overview: 26+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-10-26 2:30 [PATCH 0/14] fdt: Add various device tree utilities and features Simon Glass
[not found] ` <1351218671-15228-1-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-10-26 2:30 ` [PATCH 01/14] fdt: Add function to get config int from device tree Simon Glass
2012-10-26 2:30 ` [PATCH 02/14] fdt: Add function to get a config string " Simon Glass
2012-10-26 2:31 ` Simon Glass [this message]
2012-10-26 2:31 ` [PATCH 04/14] fdt: Add function for decoding multiple gpios globally available Simon Glass
2012-10-26 2:31 ` [PATCH 05/14] fdt: Export fdtdec_find_alias_node() function Simon Glass
[not found] ` <1351218671-15228-6-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-10-26 4:24 ` David Gibson
2012-10-31 23:50 ` Simon Glass
2012-10-26 2:31 ` [PATCH 06/14] fdt: Export fdtdec_lookup() and fix the name Simon Glass
2012-10-26 2:31 ` [PATCH 07/14] fdt: Add function to read boolean property Simon Glass
2012-10-26 2:31 ` [PATCH 08/14] fdt: Add fdtdec_get_uint64 to decode a 64-bit value from a property Simon Glass
2012-10-26 2:31 ` [PATCH 09/14] fdt: Add polarity-aware gpio functions to fdtdec Simon Glass
2012-10-26 7:17 ` Lucas Stach
2012-10-31 23:59 ` Simon Glass
2012-11-01 4:50 ` Stephen Warren
2012-11-15 23:31 ` Simon Glass
2012-11-15 23:46 ` Stephen Warren
2012-11-16 0:01 ` Simon Glass
2012-10-26 2:31 ` [PATCH 11/14] fdt: Tell the FDT library where the device tree is Simon Glass
2012-10-26 2:31 ` [PATCH 12/14] fdt: Allow device tree to specify secure booting Simon Glass
2012-10-26 2:31 ` [PATCH 10/14] fdt: Load boot command from device tree Simon Glass
2012-10-26 2:31 ` [PATCH 13/14] fdt: Add option to default to most compatible conf in a fit image Simon Glass
2012-10-26 2:31 ` [PATCH 14/14] fdt: Set kernaddr if fdt indicates a kernel is present Simon Glass
[not found] ` <1351218671-15228-15-git-send-email-sjg-F7+t8E8rja9g9hUCZPvPmw@public.gmane.org>
2012-11-28 14:30 ` [U-Boot] " Dennis Lan (dlan)
2012-11-18 1:35 ` [PATCH 0/14] fdt: Add various device tree utilities and features Jerry Van Baren
2012-11-19 17:08 ` 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=1351218671-15228-4-git-send-email-sjg@chromium.org \
--to=sjg-f7+t8e8rja9g9huczpvpmw@public.gmane.org \
--cc=devicetree-discuss-uLR06cmDAlY/bJ5BZ2RsiQ@public.gmane.org \
--cc=trini-l0cyMroinI0@public.gmane.org \
--cc=u-boot-0aAXYlwwYIKGBzrmiIFOJg@public.gmane.org \
--cc=vanbaren-He//nVnquyzQT0dZR+AlfA@public.gmane.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).