From: crwulff@gmail.com
To: qemu-devel@nongnu.org
Cc: Chris Wulff <crwulff@gmail.com>
Subject: [Qemu-devel] [PATCH 5/9] FDT: Add additional access methods for array types and walking children.
Date: Sun, 9 Sep 2012 20:20:03 -0400 [thread overview]
Message-ID: <1347236407-10465-6-git-send-email-crwulff@gmail.com> (raw)
In-Reply-To: <1347236407-10465-1-git-send-email-crwulff@gmail.com>
From: Chris Wulff <crwulff@gmail.com>
Signed-off-by: Chris Wulff <crwulff@gmail.com>
---
device_tree.c | 88 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++
device_tree.h | 18 ++++++++++++
2 files changed, 106 insertions(+)
diff --git a/device_tree.c b/device_tree.c
index d7a9b6b..7fa7646 100644
--- a/device_tree.c
+++ b/device_tree.c
@@ -27,6 +27,14 @@
#include <libfdt.h>
+#define CHECK_HEADER(fdt) \
+ { \
+ int err = fdt_check_header(fdt); \
+ if (err != 0) { \
+ return err; \
+ } \
+ }
+
#define FDT_MAX_SIZE 0x10000
void *create_device_tree(int *sizep)
@@ -304,3 +312,83 @@ int qemu_devtree_add_subnode(void *fdt, const char *name)
g_free(dupname);
return retval;
}
+
+int qemu_devtree_node_offset(void *fdt, const char *node_path)
+{
+ return fdt_path_offset(fdt, node_path);
+}
+
+int qemu_devtree_subnode_offset_namelen(void *fdt, int parentoffset,
+ const char *name, int namelen)
+{
+ return fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
+}
+
+int qemu_devtree_next_child_offset(void *fdt, int parentoffset, int childoffset)
+{
+ int level = 0;
+ uint32_t tag;
+ int offset, nextoffset;
+
+ CHECK_HEADER(fdt);
+ tag = fdt_next_tag(fdt, parentoffset, &nextoffset);
+ if (tag != FDT_BEGIN_NODE) {
+ return -FDT_ERR_BADOFFSET;
+ }
+
+ do {
+ offset = nextoffset;
+ tag = fdt_next_tag(fdt, offset, &nextoffset);
+
+ switch (tag) {
+ case FDT_END:
+ return -FDT_ERR_TRUNCATED;
+
+ case FDT_BEGIN_NODE:
+ level++;
+ if (level != 1) {
+ continue;
+ }
+ if (offset > childoffset) {
+ return offset;
+ }
+ break;
+
+ case FDT_END_NODE:
+ level--;
+ break;
+
+ case FDT_PROP:
+ case FDT_NOP:
+ break;
+
+ default:
+ return -FDT_ERR_BADSTRUCTURE;
+ }
+ } while (level >= 0);
+
+ return -FDT_ERR_NOTFOUND;
+}
+
+const char *qemu_devtree_get_name(const void *fdt, int nodeoffset, int *lenp)
+{
+ return fdt_get_name(fdt, nodeoffset, lenp);
+}
+
+const void *qemu_devtree_getprop_offset(const void *fdt, int nodeoffset,
+ const char *name, int *lenp)
+{
+ return fdt_getprop(fdt, nodeoffset, name, lenp);
+}
+
+uint32_t qemu_devtree_int_array_index(const void *propval, unsigned int index)
+{
+ return be32_to_cpu(((uint32_t *)propval)[index]);
+}
+
+int qemu_devtree_node_check_compatible(const void *fdt, int nodeoffset,
+ const char *compatible)
+{
+ return fdt_node_check_compatible(fdt, nodeoffset, compatible);
+}
+
diff --git a/device_tree.h b/device_tree.h
index f7a3e6c..e01b460 100644
--- a/device_tree.h
+++ b/device_tree.h
@@ -49,4 +49,22 @@ int qemu_devtree_add_subnode(void *fdt, const char *name);
sizeof(qdt_tmp)); \
} while (0)
+int qemu_devtree_node_offset(void *fdt, const char *node_path);
+
+int qemu_devtree_subnode_offset_namelen(void *fdt, int parentoffset,
+ const char *name, int namelen);
+
+int qemu_devtree_next_child_offset(void *fdt, int parentoffset,
+ int childoffset);
+
+const char *qemu_devtree_get_name(const void *fdt, int nodeoffset, int *lenp);
+
+const void *qemu_devtree_getprop_offset(const void *fdt, int nodeoffset,
+ const char *name, int *lenp);
+
+uint32_t qemu_devtree_int_array_index(const void *propval, unsigned int index);
+
+int qemu_devtree_node_check_compatible(const void *fdt, int nodeoffset,
+ const char *compatible);
+
#endif /* __DEVICE_TREE_H__ */
--
1.7.9.5
next prev parent reply other threads:[~2012-09-10 0:19 UTC|newest]
Thread overview: 31+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <Nios2-Resend2>
2012-09-10 0:19 ` [Qemu-devel] [PATCH 0/9] Altera NiosII support crwulff
2012-09-10 0:19 ` [Qemu-devel] [PATCH 1/9] NiosII: Add support for the Altera NiosII soft-core CPU crwulff
2012-09-11 20:19 ` Blue Swirl
2012-09-14 3:30 ` Chris Wulff
2012-09-11 21:34 ` Aurelien Jarno
2012-09-11 22:30 ` Richard Henderson
2012-09-11 23:18 ` Richard Henderson
2012-09-14 3:42 ` Chris Wulff
2012-09-15 15:33 ` Chris Wulff
2012-09-15 14:55 ` Andreas Färber
2012-09-10 0:20 ` [Qemu-devel] [PATCH 2/9] NiosII: Disassembly of NiosII instructions ported from GDB crwulff
2012-09-11 19:58 ` Blue Swirl
2012-09-10 0:20 ` [Qemu-devel] [PATCH 3/9] Altera: Add support for Altera devices required to boot linux on NiosII crwulff
2012-09-11 19:53 ` Blue Swirl
2012-09-15 15:06 ` Andreas Färber
2012-09-10 0:20 ` [Qemu-devel] [PATCH 4/9] LabX: Support for some Lab X FPGA devices crwulff
2012-09-11 20:22 ` Blue Swirl
2012-09-10 0:20 ` crwulff [this message]
2012-09-12 0:12 ` [Qemu-devel] [PATCH 5/9] FDT: Add additional access methods for array types and walking children Peter Crosthwaite
2012-09-10 0:20 ` [Qemu-devel] [PATCH 6/9] NiosII: Build system and documentation integration crwulff
2012-09-10 0:20 ` [Qemu-devel] [PATCH 7/9] NiosII: Add a config that is dynamically set up by a device tree file crwulff
2012-09-11 19:40 ` Blue Swirl
2012-09-10 0:20 ` [Qemu-devel] [PATCH 8/9] MicroBlaze: " crwulff
2012-09-11 19:27 ` Blue Swirl
2012-09-12 0:17 ` Peter Crosthwaite
2012-09-14 19:13 ` Blue Swirl
2012-09-11 23:59 ` Peter Crosthwaite
2012-09-14 4:01 ` Chris Wulff
2012-09-10 0:20 ` [Qemu-devel] [PATCH 9/9] xilinx_timer: Fix a compile error if debug messages are enabled crwulff
2012-09-12 0:25 ` Peter Crosthwaite
2012-09-11 23:40 ` [Qemu-devel] [PATCH 0/9] Altera NiosII support Peter Crosthwaite
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=1347236407-10465-6-git-send-email-crwulff@gmail.com \
--to=crwulff@gmail.com \
--cc=qemu-devel@nongnu.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).