linuxppc-dev.lists.ozlabs.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] Add helpers for finding a device node which as a certain property
@ 2008-11-13  4:20 Michael Ellerman
  2008-11-13  4:20 ` [PATCH 2/4] Use for_each_node_with_property() in of_irq_map_init() Michael Ellerman
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: Michael Ellerman @ 2008-11-13  4:20 UTC (permalink / raw)
  To: linuxppc-dev

This commit adds a routine for finding a device node which has a certain
property, the contents of the property are not taken into account,
merely the presence or absence of the property.

Based on that routine, we add a for_each_ macro for iterating over all
nodes that have a certain property.

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 drivers/of/base.c  |   34 ++++++++++++++++++++++++++++++++++
 include/linux/of.h |    6 ++++++
 2 files changed, 40 insertions(+), 0 deletions(-)

diff --git a/drivers/of/base.c b/drivers/of/base.c
index 7c79e94..0c3dcd0 100644
--- a/drivers/of/base.c
+++ b/drivers/of/base.c
@@ -329,6 +329,40 @@ struct device_node *of_find_compatible_node(struct device_node *from,
 EXPORT_SYMBOL(of_find_compatible_node);
 
 /**
+ *	of_find_node_with_property - Find a node which has a property with
+ *                                   the given name.
+ *	@from:		The node to start searching from or NULL, the node
+ *			you pass will not be searched, only the next one
+ *			will; typically, you pass what the previous call
+ *			returned. of_node_put() will be called on it
+ *	@prop_name:	The name of the property to look for.
+ *
+ *	Returns a node pointer with refcount incremented, use
+ *	of_node_put() on it when done.
+ */
+struct device_node *of_find_node_with_property(struct device_node *from,
+	const char *prop_name)
+{
+	struct device_node *np;
+	struct property *pp;
+
+	read_lock(&devtree_lock);
+	np = from ? from->allnext : allnodes;
+	for (; np; np = np->allnext) {
+		for (pp = np->properties; pp != 0; pp = pp->next) {
+			if (of_prop_cmp(pp->name, prop_name) == 0) {
+				goto out;
+			}
+		}
+	}
+out:
+	of_node_put(from);
+	read_unlock(&devtree_lock);
+	return np;
+}
+EXPORT_SYMBOL(of_find_node_with_property);
+
+/**
  * of_match_node - Tell if an device_node has a matching of_match structure
  *	@matches:	array of of device match structures to search in
  *	@node:		the of device structure to match against
diff --git a/include/linux/of.h b/include/linux/of.h
index e2488f5..6a7efa2 100644
--- a/include/linux/of.h
+++ b/include/linux/of.h
@@ -57,6 +57,12 @@ extern struct device_node *of_get_next_child(const struct device_node *node,
 	for (child = of_get_next_child(parent, NULL); child != NULL; \
 	     child = of_get_next_child(parent, child))
 
+extern struct device_node *of_find_node_with_property(
+	struct device_node *from, const char *prop_name);
+#define for_each_node_with_property(dn, prop_name) \
+	for (dn = of_find_node_with_property(NULL, prop_name); dn; \
+	     dn = of_find_node_with_property(dn, prop_name))
+
 extern struct property *of_find_property(const struct device_node *np,
 					 const char *name,
 					 int *lenp);
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/4] Use for_each_node_with_property() in of_irq_map_init()
  2008-11-13  4:20 [PATCH 1/4] Add helpers for finding a device node which as a certain property Michael Ellerman
@ 2008-11-13  4:20 ` Michael Ellerman
  2008-11-13  4:20 ` [PATCH 3/4] Use of_find_node_with_property() in cell_iommu_fixed_mapping_init() Michael Ellerman
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2008-11-13  4:20 UTC (permalink / raw)
  To: linuxppc-dev

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/kernel/prom_parse.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/kernel/prom_parse.c b/arch/powerpc/kernel/prom_parse.c
index bc1fb27..2a1c02c 100644
--- a/arch/powerpc/kernel/prom_parse.c
+++ b/arch/powerpc/kernel/prom_parse.c
@@ -731,10 +731,7 @@ void of_irq_map_init(unsigned int flags)
 	if (flags & OF_IMAP_NO_PHANDLE) {
 		struct device_node *np;
 
-		for(np = NULL; (np = of_find_all_nodes(np)) != NULL;) {
-			if (of_get_property(np, "interrupt-controller", NULL)
-			    == NULL)
-				continue;
+		for_each_node_with_property(np, "interrupt-controller") {
 			/* Skip /chosen/interrupt-controller */
 			if (strcmp(np->name, "chosen") == 0)
 				continue;
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/4] Use of_find_node_with_property() in cell_iommu_fixed_mapping_init()
  2008-11-13  4:20 [PATCH 1/4] Add helpers for finding a device node which as a certain property Michael Ellerman
  2008-11-13  4:20 ` [PATCH 2/4] Use for_each_node_with_property() in of_irq_map_init() Michael Ellerman
@ 2008-11-13  4:20 ` Michael Ellerman
  2008-11-13  4:20 ` [PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch() Michael Ellerman
  2008-11-13  6:46 ` [PATCH 1/4] Add helpers for finding a device node which as a certain property David Miller
  3 siblings, 0 replies; 9+ messages in thread
From: Michael Ellerman @ 2008-11-13  4:20 UTC (permalink / raw)
  To: linuxppc-dev

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/platforms/cell/iommu.c |    5 +----
 1 files changed, 1 insertions(+), 4 deletions(-)

diff --git a/arch/powerpc/platforms/cell/iommu.c b/arch/powerpc/platforms/cell/iommu.c
index 3168272..86db4dd 100644
--- a/arch/powerpc/platforms/cell/iommu.c
+++ b/arch/powerpc/platforms/cell/iommu.c
@@ -1053,10 +1053,7 @@ static int __init cell_iommu_fixed_mapping_init(void)
 	}
 
 	/* We must have dma-ranges properties for fixed mapping to work */
-	for (np = NULL; (np = of_find_all_nodes(np));) {
-		if (of_find_property(np, "dma-ranges", NULL))
-			break;
-	}
+	np = of_find_node_with_property(NULL, "dma-ranges");
 	of_node_put(np);
 
 	if (!np) {
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch()
  2008-11-13  4:20 [PATCH 1/4] Add helpers for finding a device node which as a certain property Michael Ellerman
  2008-11-13  4:20 ` [PATCH 2/4] Use for_each_node_with_property() in of_irq_map_init() Michael Ellerman
  2008-11-13  4:20 ` [PATCH 3/4] Use of_find_node_with_property() in cell_iommu_fixed_mapping_init() Michael Ellerman
@ 2008-11-13  4:20 ` Michael Ellerman
  2008-11-13  9:27   ` Benjamin Herrenschmidt
  2008-11-13  6:46 ` [PATCH 1/4] Add helpers for finding a device node which as a certain property David Miller
  3 siblings, 1 reply; 9+ messages in thread
From: Michael Ellerman @ 2008-11-13  4:20 UTC (permalink / raw)
  To: linuxppc-dev

Signed-off-by: Michael Ellerman <michael@ellerman.id.au>
---
 arch/powerpc/platforms/powermac/setup.c |    4 +---
 1 files changed, 1 insertions(+), 3 deletions(-)

diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
index 82c14d2..1293772 100644
--- a/arch/powerpc/platforms/powermac/setup.c
+++ b/arch/powerpc/platforms/powermac/setup.c
@@ -310,9 +310,7 @@ static void __init pmac_setup_arch(void)
 	}
 
 	/* See if newworld or oldworld */
-	for (ic = NULL; (ic = of_find_all_nodes(ic)) != NULL; )
-		if (of_get_property(ic, "interrupt-controller", NULL))
-			break;
+	ic = of_find_node_with_property(NULL, "interrupt-controller");
 	if (ic) {
 		pmac_newworld = 1;
 		of_node_put(ic);
-- 
1.5.5

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property
  2008-11-13  4:20 [PATCH 1/4] Add helpers for finding a device node which as a certain property Michael Ellerman
                   ` (2 preceding siblings ...)
  2008-11-13  4:20 ` [PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch() Michael Ellerman
@ 2008-11-13  6:46 ` David Miller
  2008-11-13  6:49   ` Michael Ellerman
  3 siblings, 1 reply; 9+ messages in thread
From: David Miller @ 2008-11-13  6:46 UTC (permalink / raw)
  To: michael; +Cc: linuxppc-dev

From: Michael Ellerman <michael@ellerman.id.au>
Date: Thu, 13 Nov 2008 15:20:35 +1100 (EST)

> +	np = from ? from->allnext : allnodes;
> +	for (; np; np = np->allnext) {
> +		for (pp = np->properties; pp != 0; pp = pp->next) {
> +			if (of_prop_cmp(pp->name, prop_name) == 0) {
> +				goto out;
> +			}
> +		}
> +	}

We're starting to duplicate a lot of code in this file.

Perhaps split out the locked section of of_find_proeprty() into
a __of_find_property() and use that here and in of_find_property()
as well?

staitc struct property *__of_find_property(const struct device_node *np,
					   const char *name,
					   int *lenp)
{
	struct property *pp;

	for (pp = np->properties; pp != 0; pp = pp->next) {
		if (of_prop_cmp(pp->name, name) == 0) {
			if (lenp != 0)
				*lenp = pp->length;
			break;
		}
	}

	return pp;
}

struct property *of_find_property(const struct device_node *np,
				  const char *name,
				  int *lenp)
{
	struct property *pp;

	if (!np)
		return NULL;

	read_lock(&devtree_lock);
	pp = __of_find_property(np, name, lenp);
	read_unlock(&devtree_lock);

	return pp;
}
EXPORT_SYMBOL(of_find_property);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property
  2008-11-13  6:46 ` [PATCH 1/4] Add helpers for finding a device node which as a certain property David Miller
@ 2008-11-13  6:49   ` Michael Ellerman
  2008-11-13  7:11     ` Michael Ellerman
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Ellerman @ 2008-11-13  6:49 UTC (permalink / raw)
  To: David Miller; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 998 bytes --]

On Wed, 2008-11-12 at 22:46 -0800, David Miller wrote:
> From: Michael Ellerman <michael@ellerman.id.au>
> Date: Thu, 13 Nov 2008 15:20:35 +1100 (EST)
> 
> > +	np = from ? from->allnext : allnodes;
> > +	for (; np; np = np->allnext) {
> > +		for (pp = np->properties; pp != 0; pp = pp->next) {
> > +			if (of_prop_cmp(pp->name, prop_name) == 0) {
> > +				goto out;
> > +			}
> > +		}
> > +	}
> 
> We're starting to duplicate a lot of code in this file.

Agreed.

> Perhaps split out the locked section of of_find_proeprty() into
> a __of_find_property() and use that here and in of_find_property()
> as well?

Yeah I thought about it, but decided it wasn't worth it. But I'll try it
and see how the sizes end up.

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property
  2008-11-13  6:49   ` Michael Ellerman
@ 2008-11-13  7:11     ` Michael Ellerman
  2008-11-13  7:31       ` David Miller
  0 siblings, 1 reply; 9+ messages in thread
From: Michael Ellerman @ 2008-11-13  7:11 UTC (permalink / raw)
  To: David Miller; +Cc: linuxppc-dev

[-- Attachment #1: Type: text/plain, Size: 1441 bytes --]

On Thu, 2008-11-13 at 17:49 +1100, Michael Ellerman wrote:
> On Wed, 2008-11-12 at 22:46 -0800, David Miller wrote:
> > From: Michael Ellerman <michael@ellerman.id.au>
> > Date: Thu, 13 Nov 2008 15:20:35 +1100 (EST)
> > 
> > > +	np = from ? from->allnext : allnodes;
> > > +	for (; np; np = np->allnext) {
> > > +		for (pp = np->properties; pp != 0; pp = pp->next) {
> > > +			if (of_prop_cmp(pp->name, prop_name) == 0) {
> > > +				goto out;
> > > +			}
> > > +		}
> > > +	}
> > 
> > We're starting to duplicate a lot of code in this file.
> 
> Agreed.
> 
> > Perhaps split out the locked section of of_find_proeprty() into
> > a __of_find_property() and use that here and in of_find_property()
> > as well?
> 
> Yeah I thought about it, but decided it wasn't worth it. But I'll try it
> and see how the sizes end up.

With my compiler (4.3.1) it just gets inlined and actually makes the
text 8 bytes larger. We might be using different CFLAGs to sparc though.

I didn't think it made the source significantly clearer to split out the
of_find_property() logic, especially seeing as we don't need the lenp
behaviour in of_find_node_with_property().

cheers

-- 
Michael Ellerman
OzLabs, IBM Australia Development Lab

wwweb: http://michael.ellerman.id.au
phone: +61 2 6212 1183 (tie line 70 21183)

We do not inherit the earth from our ancestors,
we borrow it from our children. - S.M.A.R.T Person

[-- Attachment #2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 197 bytes --]

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/4] Add helpers for finding a device node which as a certain property
  2008-11-13  7:11     ` Michael Ellerman
@ 2008-11-13  7:31       ` David Miller
  0 siblings, 0 replies; 9+ messages in thread
From: David Miller @ 2008-11-13  7:31 UTC (permalink / raw)
  To: michael; +Cc: linuxppc-dev

From: Michael Ellerman <michael@ellerman.id.au>
Date: Thu, 13 Nov 2008 18:11:43 +1100

> With my compiler (4.3.1) it just gets inlined and actually makes the
> text 8 bytes larger. We might be using different CFLAGs to sparc though.
> 
> I didn't think it made the source significantly clearer to split out the
> of_find_property() logic, especially seeing as we don't need the lenp
> behaviour in of_find_node_with_property().

Fair enough.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch()
  2008-11-13  4:20 ` [PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch() Michael Ellerman
@ 2008-11-13  9:27   ` Benjamin Herrenschmidt
  0 siblings, 0 replies; 9+ messages in thread
From: Benjamin Herrenschmidt @ 2008-11-13  9:27 UTC (permalink / raw)
  To: Michael Ellerman; +Cc: linuxppc-dev

On Thu, 2008-11-13 at 15:20 +1100, Michael Ellerman wrote:
> Signed-off-by: Michael Ellerman <michael@ellerman.id.au>

Acked-by: Benjamin Herrenschmidt <benh@kernel.crashing.org>
---

> ---
>  arch/powerpc/platforms/powermac/setup.c |    4 +---
>  1 files changed, 1 insertions(+), 3 deletions(-)
> 
> diff --git a/arch/powerpc/platforms/powermac/setup.c b/arch/powerpc/platforms/powermac/setup.c
> index 82c14d2..1293772 100644
> --- a/arch/powerpc/platforms/powermac/setup.c
> +++ b/arch/powerpc/platforms/powermac/setup.c
> @@ -310,9 +310,7 @@ static void __init pmac_setup_arch(void)
>  	}
>  
>  	/* See if newworld or oldworld */
> -	for (ic = NULL; (ic = of_find_all_nodes(ic)) != NULL; )
> -		if (of_get_property(ic, "interrupt-controller", NULL))
> -			break;
> +	ic = of_find_node_with_property(NULL, "interrupt-controller");
>  	if (ic) {
>  		pmac_newworld = 1;
>  		of_node_put(ic);

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2008-11-13  9:27 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-11-13  4:20 [PATCH 1/4] Add helpers for finding a device node which as a certain property Michael Ellerman
2008-11-13  4:20 ` [PATCH 2/4] Use for_each_node_with_property() in of_irq_map_init() Michael Ellerman
2008-11-13  4:20 ` [PATCH 3/4] Use of_find_node_with_property() in cell_iommu_fixed_mapping_init() Michael Ellerman
2008-11-13  4:20 ` [PATCH 4/4] Use of_find_node_with_property() in pmac_setup_arch() Michael Ellerman
2008-11-13  9:27   ` Benjamin Herrenschmidt
2008-11-13  6:46 ` [PATCH 1/4] Add helpers for finding a device node which as a certain property David Miller
2008-11-13  6:49   ` Michael Ellerman
2008-11-13  7:11     ` Michael Ellerman
2008-11-13  7:31       ` David Miller

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).