]> git.kernelconcepts.de Git - karo-tx-linux.git/commitdiff
Consolidate of_find_node_by routines
authorStephen Rothwell <sfr@canb.auug.org.au>
Tue, 24 Apr 2007 07:57:33 +0000 (17:57 +1000)
committerStephen Rothwell <sfr@canb.auug.org.au>
Fri, 20 Jul 2007 03:39:06 +0000 (13:39 +1000)
This consolidates the routines of_find_node_by_path, of_find_node_by_name,
of_find_node_by_type and of_find_compatible_device.  Again, the comparison
of strings are done differently by Sparc and PowerPC and also these add
read_locks around the iterations.

Signed-off-by: Stephen Rothwell <sfr@canb.auug.org.au>
Acked-by: Paul Mackerras <paulus@samba.org>
Acked-by: David S. Miller <davem@davemloft.net>
arch/powerpc/kernel/prom.c
arch/sparc/kernel/prom.c
arch/sparc64/kernel/prom.c
drivers/of/base.c
include/asm-powerpc/prom.h
include/asm-sparc/prom.h
include/asm-sparc64/prom.h

index 5fa221ce87148ae385b3787b0fc076d998eafe6d..bdcd23d8d8b99f8648b61a63aa4ece60f66c375a 100644 (file)
@@ -78,7 +78,7 @@ static struct boot_param_header *initial_boot_params __initdata;
 struct boot_param_header *initial_boot_params;
 #endif
 
 struct boot_param_header *initial_boot_params;
 #endif
 
-static struct device_node *allnodes = NULL;
+extern struct device_node *allnodes;   /* temporary while merging */
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
@@ -1083,119 +1083,6 @@ EXPORT_SYMBOL(machine_is_compatible);
  *
  *******/
 
  *
  *******/
 
-/**
- *     of_find_node_by_name - Find a node by its "name" property
- *     @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
- *     @name:  The name string to match against
- *
- *     Returns a node pointer with refcount incremented, use
- *     of_node_put() on it when done.
- */
-struct device_node *of_find_node_by_name(struct device_node *from,
-       const char *name)
-{
-       struct device_node *np;
-
-       read_lock(&devtree_lock);
-       np = from ? from->allnext : allnodes;
-       for (; np != NULL; np = np->allnext)
-               if (np->name != NULL && strcasecmp(np->name, name) == 0
-                   && of_node_get(np))
-                       break;
-       of_node_put(from);
-       read_unlock(&devtree_lock);
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_name);
-
-/**
- *     of_find_node_by_type - Find a node by its "device_type" property
- *     @from:  The node to start searching from, or NULL to start searching
- *             the entire device tree. 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 from for you.
- *     @type:  The type string to match against
- *
- *     Returns a node pointer with refcount incremented, use
- *     of_node_put() on it when done.
- */
-struct device_node *of_find_node_by_type(struct device_node *from,
-       const char *type)
-{
-       struct device_node *np;
-
-       read_lock(&devtree_lock);
-       np = from ? from->allnext : allnodes;
-       for (; np != 0; np = np->allnext)
-               if (np->type != 0 && strcasecmp(np->type, type) == 0
-                   && of_node_get(np))
-                       break;
-       of_node_put(from);
-       read_unlock(&devtree_lock);
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_type);
-
-/**
- *     of_find_compatible_node - Find a node based on type and one of the
- *                                tokens in its "compatible" property
- *     @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
- *     @type:          The type string to match "device_type" or NULL to ignore
- *     @compatible:    The string to match to one of the tokens in the device
- *                     "compatible" list.
- *
- *     Returns a node pointer with refcount incremented, use
- *     of_node_put() on it when done.
- */
-struct device_node *of_find_compatible_node(struct device_node *from,
-       const char *type, const char *compatible)
-{
-       struct device_node *np;
-
-       read_lock(&devtree_lock);
-       np = from ? from->allnext : allnodes;
-       for (; np != 0; np = np->allnext) {
-               if (type != NULL
-                   && !(np->type != 0 && strcasecmp(np->type, type) == 0))
-                       continue;
-               if (of_device_is_compatible(np, compatible) && of_node_get(np))
-                       break;
-       }
-       of_node_put(from);
-       read_unlock(&devtree_lock);
-       return np;
-}
-EXPORT_SYMBOL(of_find_compatible_node);
-
-/**
- *     of_find_node_by_path - Find a node matching a full OF path
- *     @path:  The full path to match
- *
- *     Returns a node pointer with refcount incremented, use
- *     of_node_put() on it when done.
- */
-struct device_node *of_find_node_by_path(const char *path)
-{
-       struct device_node *np = allnodes;
-
-       read_lock(&devtree_lock);
-       for (; np != 0; np = np->allnext) {
-               if (np->full_name != 0 && strcasecmp(np->full_name, path) == 0
-                   && of_node_get(np))
-                       break;
-       }
-       read_unlock(&devtree_lock);
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_path);
-
 /**
  *     of_find_node_by_phandle - Find a node given a phandle
  *     @handle:        phandle of the node to find
 /**
  *     of_find_node_by_phandle - Find a node given a phandle
  *     @handle:        phandle of the node to find
index 3f8ccfad2e013252dc1dc1cdf4abe07bb0184185..012f98346bcd54405daef3e8a01f95a733665bde 100644 (file)
 #include <asm/prom.h>
 #include <asm/oplib.h>
 
 #include <asm/prom.h>
 #include <asm/oplib.h>
 
-static struct device_node *allnodes;
+extern struct device_node *allnodes;   /* temporary while merging */
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
-struct device_node *of_find_node_by_path(const char *path)
-{
-       struct device_node *np = allnodes;
-
-       for (; np != 0; np = np->allnext) {
-               if (np->full_name != 0 && strcmp(np->full_name, path) == 0)
-                       break;
-       }
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_path);
-
 struct device_node *of_find_node_by_phandle(phandle handle)
 {
        struct device_node *np;
 struct device_node *of_find_node_by_phandle(phandle handle)
 {
        struct device_node *np;
@@ -54,52 +41,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
 }
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
 }
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
-struct device_node *of_find_node_by_name(struct device_node *from,
-       const char *name)
-{
-       struct device_node *np;
-
-       np = from ? from->allnext : allnodes;
-       for (; np != NULL; np = np->allnext)
-               if (np->name != NULL && strcmp(np->name, name) == 0)
-                       break;
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_name);
-
-struct device_node *of_find_node_by_type(struct device_node *from,
-       const char *type)
-{
-       struct device_node *np;
-
-       np = from ? from->allnext : allnodes;
-       for (; np != 0; np = np->allnext)
-               if (np->type != 0 && strcmp(np->type, type) == 0)
-                       break;
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_type);
-
-struct device_node *of_find_compatible_node(struct device_node *from,
-       const char *type, const char *compatible)
-{
-       struct device_node *np;
-
-       np = from ? from->allnext : allnodes;
-       for (; np != 0; np = np->allnext) {
-               if (type != NULL
-                   && !(np->type != 0 && strcmp(np->type, type) == 0))
-                       continue;
-               if (of_device_is_compatible(np, compatible))
-                       break;
-       }
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_compatible_node);
-
 int of_getintprop_default(struct device_node *np, const char *name, int def)
 {
        struct property *prop;
 int of_getintprop_default(struct device_node *np, const char *name, int def)
 {
        struct property *prop;
index ee96ef61bc997cac31dc6dd4bae860599550774d..2b2017ce2267b8e973f160e2b5c16bcf6002ecd2 100644 (file)
 #include <asm/upa.h>
 #include <asm/smp.h>
 
 #include <asm/upa.h>
 #include <asm/smp.h>
 
-static struct device_node *allnodes;
+extern struct device_node *allnodes;   /* temporary while merging */
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
 
 extern rwlock_t devtree_lock;  /* temporary while merging */
 
-struct device_node *of_find_node_by_path(const char *path)
-{
-       struct device_node *np = allnodes;
-
-       for (; np != 0; np = np->allnext) {
-               if (np->full_name != 0 && strcmp(np->full_name, path) == 0)
-                       break;
-       }
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_path);
-
 struct device_node *of_find_node_by_phandle(phandle handle)
 {
        struct device_node *np;
 struct device_node *of_find_node_by_phandle(phandle handle)
 {
        struct device_node *np;
@@ -59,52 +46,6 @@ struct device_node *of_find_node_by_phandle(phandle handle)
 }
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
 }
 EXPORT_SYMBOL(of_find_node_by_phandle);
 
-struct device_node *of_find_node_by_name(struct device_node *from,
-       const char *name)
-{
-       struct device_node *np;
-
-       np = from ? from->allnext : allnodes;
-       for (; np != NULL; np = np->allnext)
-               if (np->name != NULL && strcmp(np->name, name) == 0)
-                       break;
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_name);
-
-struct device_node *of_find_node_by_type(struct device_node *from,
-       const char *type)
-{
-       struct device_node *np;
-
-       np = from ? from->allnext : allnodes;
-       for (; np != 0; np = np->allnext)
-               if (np->type != 0 && strcmp(np->type, type) == 0)
-                       break;
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_node_by_type);
-
-struct device_node *of_find_compatible_node(struct device_node *from,
-       const char *type, const char *compatible)
-{
-       struct device_node *np;
-
-       np = from ? from->allnext : allnodes;
-       for (; np != 0; np = np->allnext) {
-               if (type != NULL
-                   && !(np->type != 0 && strcmp(np->type, type) == 0))
-                       continue;
-               if (of_device_is_compatible(np, compatible))
-                       break;
-       }
-
-       return np;
-}
-EXPORT_SYMBOL(of_find_compatible_node);
-
 int of_getintprop_default(struct device_node *np, const char *name, int def)
 {
        struct property *prop;
 int of_getintprop_default(struct device_node *np, const char *name, int def)
 {
        struct property *prop;
index 6b6dfcc56522122ff4e5f99af3d227318cef8b40..9377f3bc410ac0083e96f3fefb48400ae4342a43 100644 (file)
@@ -20,6 +20,8 @@
 #include <linux/of.h>
 #include <linux/spinlock.h>
 
 #include <linux/of.h>
 #include <linux/spinlock.h>
 
+struct device_node *allnodes;
+
 /* use when traversing tree through the allnext, child, sibling,
  * or parent members of struct device_node.
  */
 /* use when traversing tree through the allnext, child, sibling,
  * or parent members of struct device_node.
  */
@@ -158,3 +160,116 @@ struct device_node *of_get_next_child(const struct device_node *node,
        return next;
 }
 EXPORT_SYMBOL(of_get_next_child);
        return next;
 }
 EXPORT_SYMBOL(of_get_next_child);
+
+/**
+ *     of_find_node_by_path - Find a node matching a full OF path
+ *     @path:  The full path to match
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.
+ */
+struct device_node *of_find_node_by_path(const char *path)
+{
+       struct device_node *np = allnodes;
+
+       read_lock(&devtree_lock);
+       for (; np; np = np->allnext) {
+               if (np->full_name && (of_node_cmp(np->full_name, path) == 0)
+                   && of_node_get(np))
+                       break;
+       }
+       read_unlock(&devtree_lock);
+       return np;
+}
+EXPORT_SYMBOL(of_find_node_by_path);
+
+/**
+ *     of_find_node_by_name - Find a node by its "name" property
+ *     @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
+ *     @name:  The name string to match against
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.
+ */
+struct device_node *of_find_node_by_name(struct device_node *from,
+       const char *name)
+{
+       struct device_node *np;
+
+       read_lock(&devtree_lock);
+       np = from ? from->allnext : allnodes;
+       for (; np; np = np->allnext)
+               if (np->name && (of_node_cmp(np->name, name) == 0)
+                   && of_node_get(np))
+                       break;
+       of_node_put(from);
+       read_unlock(&devtree_lock);
+       return np;
+}
+EXPORT_SYMBOL(of_find_node_by_name);
+
+/**
+ *     of_find_node_by_type - Find a node by its "device_type" property
+ *     @from:  The node to start searching from, or NULL to start searching
+ *             the entire device tree. 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 from for you.
+ *     @type:  The type string to match against
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.
+ */
+struct device_node *of_find_node_by_type(struct device_node *from,
+       const char *type)
+{
+       struct device_node *np;
+
+       read_lock(&devtree_lock);
+       np = from ? from->allnext : allnodes;
+       for (; np; np = np->allnext)
+               if (np->type && (of_node_cmp(np->type, type) == 0)
+                   && of_node_get(np))
+                       break;
+       of_node_put(from);
+       read_unlock(&devtree_lock);
+       return np;
+}
+EXPORT_SYMBOL(of_find_node_by_type);
+
+/**
+ *     of_find_compatible_node - Find a node based on type and one of the
+ *                                tokens in its "compatible" property
+ *     @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
+ *     @type:          The type string to match "device_type" or NULL to ignore
+ *     @compatible:    The string to match to one of the tokens in the device
+ *                     "compatible" list.
+ *
+ *     Returns a node pointer with refcount incremented, use
+ *     of_node_put() on it when done.
+ */
+struct device_node *of_find_compatible_node(struct device_node *from,
+       const char *type, const char *compatible)
+{
+       struct device_node *np;
+
+       read_lock(&devtree_lock);
+       np = from ? from->allnext : allnodes;
+       for (; np; np = np->allnext) {
+               if (type
+                   && !(np->type && (of_node_cmp(np->type, type) == 0)))
+                       continue;
+               if (of_device_is_compatible(np, compatible) && of_node_get(np))
+                       break;
+       }
+       of_node_put(from);
+       read_unlock(&devtree_lock);
+       return np;
+}
+EXPORT_SYMBOL(of_find_compatible_node);
index 75b1144ca580abade65b0887efac6f8ce41420cb..6e391c9894ce7e513f7e75e1a62c263d5f7a6eb1 100644 (file)
@@ -26,6 +26,7 @@
 
 #define of_compat_cmp(s1, s2, l)       strncasecmp((s1), (s2), (l))
 #define of_prop_cmp(s1, s2)            strcmp((s1), (s2))
 
 #define of_compat_cmp(s1, s2, l)       strncasecmp((s1), (s2), (l))
 #define of_prop_cmp(s1, s2)            strcmp((s1), (s2))
+#define of_node_cmp(s1, s2)            strcasecmp((s1), (s2))
 
 /* Definitions used by the flattened device tree */
 #define OF_DT_HEADER           0xd00dfeed      /* marker */
 
 /* Definitions used by the flattened device tree */
 #define OF_DT_HEADER           0xd00dfeed      /* marker */
index c7d54958a90eddde61cb65edf1396f189942b06f..db9feb75bd86f0713b26fe09edd366abefc8c80e 100644 (file)
@@ -25,6 +25,7 @@
 
 #define of_compat_cmp(s1, s2, l)       strncmp((s1), (s2), (l))
 #define of_prop_cmp(s1, s2)            strcasecmp((s1), (s2))
 
 #define of_compat_cmp(s1, s2, l)       strncmp((s1), (s2), (l))
 #define of_prop_cmp(s1, s2)            strcasecmp((s1), (s2))
+#define of_node_cmp(s1, s2)            strcmp((s1), (s2))
 
 typedef u32 phandle;
 typedef u32 ihandle;
 
 typedef u32 phandle;
 typedef u32 ihandle;
index e83896f3c141a3178c791be8dcf8c0b180b5aa98..2b9e0d795faf7d1ddfbe360589947f4c6e4b8c55 100644 (file)
@@ -25,6 +25,7 @@
 
 #define of_compat_cmp(s1, s2, l)       strncmp((s1), (s2), (l))
 #define of_prop_cmp(s1, s2)            strcasecmp((s1), (s2))
 
 #define of_compat_cmp(s1, s2, l)       strncmp((s1), (s2), (l))
 #define of_prop_cmp(s1, s2)            strcasecmp((s1), (s2))
+#define of_node_cmp(s1, s2)            strcmp((s1), (s2))
 
 typedef u32 phandle;
 typedef u32 ihandle;
 
 typedef u32 phandle;
 typedef u32 ihandle;