From: Peter Crosthwaite <peter.crosthwaite@petalogix.com>
To: crwulff@gmail.com
Cc: peter.maydell@linaro.org, peter.crosthwaite@xilinx.com,
qemu-devel@nongnu.org
Subject: Re: [Qemu-devel] [PATCH 5/9] FDT: Add additional access methods for array types and walking children.
Date: Wed, 12 Sep 2012 10:12:03 +1000 [thread overview]
Message-ID: <1347408723.30441.33.camel@PetaLogix-ws2> (raw)
In-Reply-To: <1347236407-10465-6-git-send-email-crwulff@gmail.com>
On Sun, 2012-09-09 at 20:20 -0400, crwulff@gmail.com wrote:
> 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; \
> + } \
> + }
> +
Im thinking the best way (and I have recently done some patches along
this line) is to use the qemu error reporting mechanism. Rather than
return 1, populate an Error ** with an error code. Not a blocker as this
is out of scope of this series, but would make this macro foo go away
with a nice inline function.
> #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);
> +}
device_tree so far has been able to insulate clients from dealing with
offsets. Good to keep it that way and use node_paths instead. Offsets
have the problem where they are globally invalidated as soon as the
device tree is manipulated.
I have an alternate API extension that does a lot of what you are trying
to do but nodepaths are used as handles to nodes rather than offsets.
Will send patch.
> +
> +int qemu_devtree_subnode_offset_namelen(void *fdt, int parentoffset,
> + const char *name, int namelen)
> +{
> + return fdt_subnode_offset_namelen(fdt, parentoffset, name, namelen);
> +}
No need for no-operation wrappers, just call into lib-fdt directly. Most
device-tree api calls exit(1) on failure which is why we have these thin
wrappers.
> +
> +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);
This is get_prop_cell but with an index. We debated this on the list
recently (cc PMM) that get_prop_cell should(nt) have an index field into
it that lets you get the non-zeroth property. I have a patch in my tree
that changes this that ill send you along with the rest.
> +
> +int qemu_devtree_node_check_compatible(const void *fdt, int nodeoffset,
> + const char *compatible);
> +
> #endif /* __DEVICE_TREE_H__ */
Regards,
Peter
next prev parent reply other threads:[~2012-09-12 0:12 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 ` [Qemu-devel] [PATCH 5/9] FDT: Add additional access methods for array types and walking children crwulff
2012-09-12 0:12 ` Peter Crosthwaite [this message]
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=1347408723.30441.33.camel@PetaLogix-ws2 \
--to=peter.crosthwaite@petalogix.com \
--cc=crwulff@gmail.com \
--cc=peter.crosthwaite@xilinx.com \
--cc=peter.maydell@linaro.org \
--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).