diff mbox

[U-Boot,05/23] fdt: Add a subnodes iterator macro

Message ID 1408346196-30419-6-git-send-email-thierry.reding@gmail.com
State Superseded
Delegated to: Simon Glass
Headers show

Commit Message

Thierry Reding Aug. 18, 2014, 7:16 a.m. UTC
From: Thierry Reding <treding@nvidia.com>

The fdt_for_each_subnode() iterator macro provided by this patch can be
used to iterate over a device tree node's subnodes. At each iteration a
loop variable will be set to the next subnode.

Signed-off-by: Thierry Reding <treding@nvidia.com>
---
 include/libfdt.h | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)

Comments

Simon Glass Aug. 18, 2014, 6:11 p.m. UTC | #1
On 18 August 2014 01:16, Thierry Reding <thierry.reding@gmail.com> wrote:
> From: Thierry Reding <treding@nvidia.com>
>
> The fdt_for_each_subnode() iterator macro provided by this patch can be
> used to iterate over a device tree node's subnodes. At each iteration a
> loop variable will be set to the next subnode.
>
> Signed-off-by: Thierry Reding <treding@nvidia.com>

Acked-by: Simon Glass <sjg@chromium.org>

Will this go upstream to dtc at some point?

> ---
>  include/libfdt.h | 20 ++++++++++++++++++++
>  1 file changed, 20 insertions(+)
>
> diff --git a/include/libfdt.h b/include/libfdt.h
> index 4d7fb2681669..0330d7a29a58 100644
> --- a/include/libfdt.h
> +++ b/include/libfdt.h
> @@ -163,6 +163,26 @@ int fdt_first_subnode(const void *fdt, int offset);
>   */
>  int fdt_next_subnode(const void *fdt, int offset);
>
> +/**
> + * fdt_for_each_subnode - iterate over all subnodes of a parent
> + *
> + * This is actually a wrapper around a for loop and would be used like so:
> + *
> + *     fdt_for_each_subnode(fdt, node, parent) {
> + *             ...
> + *             use node
> + *             ...
> + *     }
> + *
> + * @fdt:       FDT blob
> + * @node:      child node
> + * @parent:    parent node

It might be worth mentioning the type of each of these since it is not
in the macro.

> + */
> +#define fdt_for_each_subnode(fdt, node, parent)                \
> +       for (node = fdt_first_subnode(fdt, parent);     \
> +            node >= 0;                                 \
> +            node = fdt_next_subnode(fdt, node))
> +
>  /**********************************************************************/
>  /* General functions                                                  */
>  /**********************************************************************/
> --
> 2.0.4
>

Regards,
Simon
Thierry Reding Aug. 19, 2014, 12:22 p.m. UTC | #2
On Mon, Aug 18, 2014 at 12:11:03PM -0600, Simon Glass wrote:
> On 18 August 2014 01:16, Thierry Reding <thierry.reding@gmail.com> wrote:
> > From: Thierry Reding <treding@nvidia.com>
> >
> > The fdt_for_each_subnode() iterator macro provided by this patch can be
> > used to iterate over a device tree node's subnodes. At each iteration a
> > loop variable will be set to the next subnode.
> >
> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> 
> Acked-by: Simon Glass <sjg@chromium.org>
> 
> Will this go upstream to dtc at some point?

I suppose it could. I don't know anything about how code flows back and
forth between dtc and U-Boot.

> > ---
> >  include/libfdt.h | 20 ++++++++++++++++++++
> >  1 file changed, 20 insertions(+)
> >
> > diff --git a/include/libfdt.h b/include/libfdt.h
> > index 4d7fb2681669..0330d7a29a58 100644
> > --- a/include/libfdt.h
> > +++ b/include/libfdt.h
> > @@ -163,6 +163,26 @@ int fdt_first_subnode(const void *fdt, int offset);
> >   */
> >  int fdt_next_subnode(const void *fdt, int offset);
> >
> > +/**
> > + * fdt_for_each_subnode - iterate over all subnodes of a parent
> > + *
> > + * This is actually a wrapper around a for loop and would be used like so:
> > + *
> > + *     fdt_for_each_subnode(fdt, node, parent) {
> > + *             ...
> > + *             use node
> > + *             ...
> > + *     }
> > + *
> > + * @fdt:       FDT blob
> > + * @node:      child node
> > + * @parent:    parent node
> 
> It might be worth mentioning the type of each of these since it is not
> in the macro.

Will do.

Thierry
Simon Glass Aug. 19, 2014, 12:57 p.m. UTC | #3
Hi Thierry,

On 19 August 2014 06:22, Thierry Reding <thierry.reding@gmail.com> wrote:
> On Mon, Aug 18, 2014 at 12:11:03PM -0600, Simon Glass wrote:
>> On 18 August 2014 01:16, Thierry Reding <thierry.reding@gmail.com> wrote:
>> > From: Thierry Reding <treding@nvidia.com>
>> >
>> > The fdt_for_each_subnode() iterator macro provided by this patch can be
>> > used to iterate over a device tree node's subnodes. At each iteration a
>> > loop variable will be set to the next subnode.
>> >
>> > Signed-off-by: Thierry Reding <treding@nvidia.com>
>>
>> Acked-by: Simon Glass <sjg@chromium.org>
>>
>> Will this go upstream to dtc at some point?
>
> I suppose it could. I don't know anything about how code flows back and
> forth between dtc and U-Boot.

Well normally we try to send changes upstream to minimise the diff
between libfdt and U-Boot. You can join
devicetree-compiler@vger.kernel.org and send patches. If they get
modified upstream then I can apply a diff to U-Boot when they are
applied.

Regards,
Simon
Thierry Reding Aug. 19, 2014, 1:12 p.m. UTC | #4
On Tue, Aug 19, 2014 at 06:57:54AM -0600, Simon Glass wrote:
> Hi Thierry,
> 
> On 19 August 2014 06:22, Thierry Reding <thierry.reding@gmail.com> wrote:
> > On Mon, Aug 18, 2014 at 12:11:03PM -0600, Simon Glass wrote:
> >> On 18 August 2014 01:16, Thierry Reding <thierry.reding@gmail.com> wrote:
> >> > From: Thierry Reding <treding@nvidia.com>
> >> >
> >> > The fdt_for_each_subnode() iterator macro provided by this patch can be
> >> > used to iterate over a device tree node's subnodes. At each iteration a
> >> > loop variable will be set to the next subnode.
> >> >
> >> > Signed-off-by: Thierry Reding <treding@nvidia.com>
> >>
> >> Acked-by: Simon Glass <sjg@chromium.org>
> >>
> >> Will this go upstream to dtc at some point?
> >
> > I suppose it could. I don't know anything about how code flows back and
> > forth between dtc and U-Boot.
> 
> Well normally we try to send changes upstream to minimise the diff
> between libfdt and U-Boot. You can join
> devicetree-compiler@vger.kernel.org and send patches. If they get
> modified upstream then I can apply a diff to U-Boot when they are
> applied.

Okay, I'll prepare a patch against upstream dtc then.

Thierry
diff mbox

Patch

diff --git a/include/libfdt.h b/include/libfdt.h
index 4d7fb2681669..0330d7a29a58 100644
--- a/include/libfdt.h
+++ b/include/libfdt.h
@@ -163,6 +163,26 @@  int fdt_first_subnode(const void *fdt, int offset);
  */
 int fdt_next_subnode(const void *fdt, int offset);
 
+/**
+ * fdt_for_each_subnode - iterate over all subnodes of a parent
+ *
+ * This is actually a wrapper around a for loop and would be used like so:
+ *
+ *	fdt_for_each_subnode(fdt, node, parent) {
+ *		...
+ *		use node
+ *		...
+ *	}
+ *
+ * @fdt:	FDT blob
+ * @node:	child node
+ * @parent:	parent node
+ */
+#define fdt_for_each_subnode(fdt, node, parent)		\
+	for (node = fdt_first_subnode(fdt, parent);	\
+	     node >= 0;					\
+	     node = fdt_next_subnode(fdt, node))
+
 /**********************************************************************/
 /* General functions                                                  */
 /**********************************************************************/