diff options
author | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-04-24 03:57:33 -0400 |
---|---|---|
committer | Stephen Rothwell <sfr@canb.auug.org.au> | 2007-07-19 23:39:06 -0400 |
commit | 1ef4d4242d9c494c49ae1ae66dc938fce0272816 (patch) | |
tree | 74c64ec940b306b5d1e7bb93a980041ad670468d /arch/powerpc/kernel/prom.c | |
parent | d1cd355a5e44dfe993efc0c0458ca9f99a28a9a3 (diff) |
Consolidate of_find_node_by routines
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>
Diffstat (limited to 'arch/powerpc/kernel/prom.c')
-rw-r--r-- | arch/powerpc/kernel/prom.c | 115 |
1 files changed, 1 insertions, 114 deletions
diff --git a/arch/powerpc/kernel/prom.c b/arch/powerpc/kernel/prom.c index 5fa221ce8714..bdcd23d8d8b9 100644 --- a/arch/powerpc/kernel/prom.c +++ b/arch/powerpc/kernel/prom.c | |||
@@ -78,7 +78,7 @@ static struct boot_param_header *initial_boot_params __initdata; | |||
78 | struct boot_param_header *initial_boot_params; | 78 | struct boot_param_header *initial_boot_params; |
79 | #endif | 79 | #endif |
80 | 80 | ||
81 | static struct device_node *allnodes = NULL; | 81 | extern struct device_node *allnodes; /* temporary while merging */ |
82 | 82 | ||
83 | extern rwlock_t devtree_lock; /* temporary while merging */ | 83 | extern rwlock_t devtree_lock; /* temporary while merging */ |
84 | 84 | ||
@@ -1084,119 +1084,6 @@ EXPORT_SYMBOL(machine_is_compatible); | |||
1084 | *******/ | 1084 | *******/ |
1085 | 1085 | ||
1086 | /** | 1086 | /** |
1087 | * of_find_node_by_name - Find a node by its "name" property | ||
1088 | * @from: The node to start searching from or NULL, the node | ||
1089 | * you pass will not be searched, only the next one | ||
1090 | * will; typically, you pass what the previous call | ||
1091 | * returned. of_node_put() will be called on it | ||
1092 | * @name: The name string to match against | ||
1093 | * | ||
1094 | * Returns a node pointer with refcount incremented, use | ||
1095 | * of_node_put() on it when done. | ||
1096 | */ | ||
1097 | struct device_node *of_find_node_by_name(struct device_node *from, | ||
1098 | const char *name) | ||
1099 | { | ||
1100 | struct device_node *np; | ||
1101 | |||
1102 | read_lock(&devtree_lock); | ||
1103 | np = from ? from->allnext : allnodes; | ||
1104 | for (; np != NULL; np = np->allnext) | ||
1105 | if (np->name != NULL && strcasecmp(np->name, name) == 0 | ||
1106 | && of_node_get(np)) | ||
1107 | break; | ||
1108 | of_node_put(from); | ||
1109 | read_unlock(&devtree_lock); | ||
1110 | return np; | ||
1111 | } | ||
1112 | EXPORT_SYMBOL(of_find_node_by_name); | ||
1113 | |||
1114 | /** | ||
1115 | * of_find_node_by_type - Find a node by its "device_type" property | ||
1116 | * @from: The node to start searching from, or NULL to start searching | ||
1117 | * the entire device tree. The node you pass will not be | ||
1118 | * searched, only the next one will; typically, you pass | ||
1119 | * what the previous call returned. of_node_put() will be | ||
1120 | * called on from for you. | ||
1121 | * @type: The type string to match against | ||
1122 | * | ||
1123 | * Returns a node pointer with refcount incremented, use | ||
1124 | * of_node_put() on it when done. | ||
1125 | */ | ||
1126 | struct device_node *of_find_node_by_type(struct device_node *from, | ||
1127 | const char *type) | ||
1128 | { | ||
1129 | struct device_node *np; | ||
1130 | |||
1131 | read_lock(&devtree_lock); | ||
1132 | np = from ? from->allnext : allnodes; | ||
1133 | for (; np != 0; np = np->allnext) | ||
1134 | if (np->type != 0 && strcasecmp(np->type, type) == 0 | ||
1135 | && of_node_get(np)) | ||
1136 | break; | ||
1137 | of_node_put(from); | ||
1138 | read_unlock(&devtree_lock); | ||
1139 | return np; | ||
1140 | } | ||
1141 | EXPORT_SYMBOL(of_find_node_by_type); | ||
1142 | |||
1143 | /** | ||
1144 | * of_find_compatible_node - Find a node based on type and one of the | ||
1145 | * tokens in its "compatible" property | ||
1146 | * @from: The node to start searching from or NULL, the node | ||
1147 | * you pass will not be searched, only the next one | ||
1148 | * will; typically, you pass what the previous call | ||
1149 | * returned. of_node_put() will be called on it | ||
1150 | * @type: The type string to match "device_type" or NULL to ignore | ||
1151 | * @compatible: The string to match to one of the tokens in the device | ||
1152 | * "compatible" list. | ||
1153 | * | ||
1154 | * Returns a node pointer with refcount incremented, use | ||
1155 | * of_node_put() on it when done. | ||
1156 | */ | ||
1157 | struct device_node *of_find_compatible_node(struct device_node *from, | ||
1158 | const char *type, const char *compatible) | ||
1159 | { | ||
1160 | struct device_node *np; | ||
1161 | |||
1162 | read_lock(&devtree_lock); | ||
1163 | np = from ? from->allnext : allnodes; | ||
1164 | for (; np != 0; np = np->allnext) { | ||
1165 | if (type != NULL | ||
1166 | && !(np->type != 0 && strcasecmp(np->type, type) == 0)) | ||
1167 | continue; | ||
1168 | if (of_device_is_compatible(np, compatible) && of_node_get(np)) | ||
1169 | break; | ||
1170 | } | ||
1171 | of_node_put(from); | ||
1172 | read_unlock(&devtree_lock); | ||
1173 | return np; | ||
1174 | } | ||
1175 | EXPORT_SYMBOL(of_find_compatible_node); | ||
1176 | |||
1177 | /** | ||
1178 | * of_find_node_by_path - Find a node matching a full OF path | ||
1179 | * @path: The full path to match | ||
1180 | * | ||
1181 | * Returns a node pointer with refcount incremented, use | ||
1182 | * of_node_put() on it when done. | ||
1183 | */ | ||
1184 | struct device_node *of_find_node_by_path(const char *path) | ||
1185 | { | ||
1186 | struct device_node *np = allnodes; | ||
1187 | |||
1188 | read_lock(&devtree_lock); | ||
1189 | for (; np != 0; np = np->allnext) { | ||
1190 | if (np->full_name != 0 && strcasecmp(np->full_name, path) == 0 | ||
1191 | && of_node_get(np)) | ||
1192 | break; | ||
1193 | } | ||
1194 | read_unlock(&devtree_lock); | ||
1195 | return np; | ||
1196 | } | ||
1197 | EXPORT_SYMBOL(of_find_node_by_path); | ||
1198 | |||
1199 | /** | ||
1200 | * of_find_node_by_phandle - Find a node given a phandle | 1087 | * of_find_node_by_phandle - Find a node given a phandle |
1201 | * @handle: phandle of the node to find | 1088 | * @handle: phandle of the node to find |
1202 | * | 1089 | * |