Rev 3618 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3618 | Rev 3742 | ||
---|---|---|---|
Line 52... | Line 52... | ||
52 | ofw_root = root; |
52 | ofw_root = root; |
53 | } |
53 | } |
54 | 54 | ||
55 | /** Get OpenFirmware node property. |
55 | /** Get OpenFirmware node property. |
56 | * |
56 | * |
57 | * @param node Node in which to lookup the property. |
57 | * @param node Node in which to lookup the property. |
58 | * @param name Name of the property. |
58 | * @param name Name of the property. |
59 | * |
59 | * |
60 | * @return Pointer to the property structure or NULL if no such property. |
60 | * @return Pointer to the property structure or NULL if no such |
- | 61 | * property. |
|
61 | */ |
62 | */ |
- | 63 | ofw_tree_property_t * |
|
62 | ofw_tree_property_t *ofw_tree_getprop(const ofw_tree_node_t *node, const char *name) |
64 | ofw_tree_getprop(const ofw_tree_node_t *node, const char *name) |
63 | { |
65 | { |
64 | unsigned int i; |
66 | unsigned int i; |
65 | 67 | ||
66 | for (i = 0; i < node->properties; i++) { |
68 | for (i = 0; i < node->properties; i++) { |
67 | if (strcmp(node->property[i].name, name) == 0) |
69 | if (strcmp(node->property[i].name, name) == 0) |
Line 71... | Line 73... | ||
71 | return NULL; |
73 | return NULL; |
72 | } |
74 | } |
73 | 75 | ||
74 | /** Return value of the 'name' property. |
76 | /** Return value of the 'name' property. |
75 | * |
77 | * |
76 | * @param node Node of interest. |
78 | * @param node Node of interest. |
77 | * |
79 | * |
78 | * @return Value of the 'name' property belonging to the node. |
80 | * @return Value of the 'name' property belonging to the node. |
79 | */ |
81 | */ |
80 | const char *ofw_tree_node_name(const ofw_tree_node_t *node) |
82 | const char *ofw_tree_node_name(const ofw_tree_node_t *node) |
81 | { |
83 | { |
82 | ofw_tree_property_t *prop; |
84 | ofw_tree_property_t *prop; |
83 | 85 | ||
Line 91... | Line 93... | ||
91 | return prop->value; |
93 | return prop->value; |
92 | } |
94 | } |
93 | 95 | ||
94 | /** Lookup child of given name. |
96 | /** Lookup child of given name. |
95 | * |
97 | * |
96 | * @param node Node whose child is being looked up. |
98 | * @param node Node whose child is being looked up. |
97 | * @param name Name of the child being looked up. |
99 | * @param name Name of the child being looked up. |
98 | * |
100 | * |
99 | * @return NULL if there is no such child or pointer to the matching child node. |
101 | * @return NULL if there is no such child or pointer to the |
- | 102 | * matching child node. |
|
100 | */ |
103 | */ |
101 | ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *name) |
104 | ofw_tree_node_t *ofw_tree_find_child(ofw_tree_node_t *node, const char *name) |
102 | { |
105 | { |
103 | ofw_tree_node_t *cur; |
106 | ofw_tree_node_t *cur; |
104 | 107 | ||
Line 125... | Line 128... | ||
125 | return NULL; |
128 | return NULL; |
126 | } |
129 | } |
127 | 130 | ||
128 | /** Lookup first child of given device type. |
131 | /** Lookup first child of given device type. |
129 | * |
132 | * |
130 | * @param node Node whose child is being looked up. |
133 | * @param node Node whose child is being looked up. |
131 | * @param name Device type of the child being looked up. |
134 | * @param name Device type of the child being looked up. |
132 | * |
135 | * |
133 | * @return NULL if there is no such child or pointer to the matching child node. |
136 | * @return NULL if there is no such child or pointer to the |
- | 137 | * matching child node. |
|
134 | */ |
138 | */ |
- | 139 | ofw_tree_node_t * |
|
135 | ofw_tree_node_t *ofw_tree_find_child_by_device_type(ofw_tree_node_t *node, const char *name) |
140 | ofw_tree_find_child_by_device_type(ofw_tree_node_t *node, const char *name) |
136 | { |
141 | { |
137 | ofw_tree_node_t *cur; |
142 | ofw_tree_node_t *cur; |
138 | ofw_tree_property_t *prop; |
143 | ofw_tree_property_t *prop; |
139 | 144 | ||
140 | for (cur = node->child; cur; cur = cur->peer) { |
145 | for (cur = node->child; cur; cur = cur->peer) { |
Line 151... | Line 156... | ||
151 | /** Lookup node with matching node_handle. |
156 | /** Lookup node with matching node_handle. |
152 | * |
157 | * |
153 | * Child nodes are looked up recursively contrary to peer nodes that |
158 | * Child nodes are looked up recursively contrary to peer nodes that |
154 | * are looked up iteratively to avoid stack overflow. |
159 | * are looked up iteratively to avoid stack overflow. |
155 | * |
160 | * |
156 | * @param root Root of the searched subtree. |
161 | * @param root Root of the searched subtree. |
157 | * @param handle OpenFirmware handle. |
162 | * @param handle OpenFirmware handle. |
158 | * |
163 | * |
159 | * @return NULL if there is no such node or pointer to the matching node. |
164 | * @return NULL if there is no such node or pointer to the matching |
- | 165 | * node. |
|
160 | */ |
166 | */ |
- | 167 | ofw_tree_node_t * |
|
161 | ofw_tree_node_t *ofw_tree_find_node_by_handle(ofw_tree_node_t *root, uint32_t handle) |
168 | ofw_tree_find_node_by_handle(ofw_tree_node_t *root, uint32_t handle) |
162 | { |
169 | { |
163 | ofw_tree_node_t *cur; |
170 | ofw_tree_node_t *cur; |
164 | 171 | ||
165 | for (cur = root; cur; cur = cur->peer) { |
172 | for (cur = root; cur; cur = cur->peer) { |
166 | if (cur->node_handle == handle) |
173 | if (cur->node_handle == handle) |
Line 178... | Line 185... | ||
178 | return NULL; |
185 | return NULL; |
179 | } |
186 | } |
180 | 187 | ||
181 | /** Lookup first peer of given device type. |
188 | /** Lookup first peer of given device type. |
182 | * |
189 | * |
183 | * @param node Node whose peer is being looked up. |
190 | * @param node Node whose peer is being looked up. |
184 | * @param name Device type of the child being looked up. |
191 | * @param name Device type of the child being looked up. |
185 | * |
192 | * |
186 | * @return NULL if there is no such child or pointer to the matching child node. |
193 | * @return NULL if there is no such child or pointer to the |
- | 194 | * matching child node. |
|
187 | */ |
195 | */ |
- | 196 | ofw_tree_node_t * |
|
188 | ofw_tree_node_t *ofw_tree_find_peer_by_device_type(ofw_tree_node_t *node, const char *name) |
197 | ofw_tree_find_peer_by_device_type(ofw_tree_node_t *node, const char *name) |
189 | { |
198 | { |
190 | ofw_tree_node_t *cur; |
199 | ofw_tree_node_t *cur; |
191 | ofw_tree_property_t *prop; |
200 | ofw_tree_property_t *prop; |
192 | 201 | ||
193 | for (cur = node->peer; cur; cur = cur->peer) { |
202 | for (cur = node->peer; cur; cur = cur->peer) { |
Line 202... | Line 211... | ||
202 | } |
211 | } |
203 | 212 | ||
204 | 213 | ||
205 | /** Lookup first peer of given name. |
214 | /** Lookup first peer of given name. |
206 | * |
215 | * |
207 | * @param node Node whose peer is being looked up. |
216 | * @param node Node whose peer is being looked up. |
208 | * @param name Name of the child being looked up. |
217 | * @param name Name of the child being looked up. |
209 | * |
218 | * |
210 | * @return NULL if there is no such peer or pointer to the matching peer node. |
219 | * @return NULL if there is no such peer or pointer to the matching |
- | 220 | * peer node. |
|
211 | */ |
221 | */ |
- | 222 | ofw_tree_node_t * |
|
212 | ofw_tree_node_t *ofw_tree_find_peer_by_name(ofw_tree_node_t *node, |
223 | ofw_tree_find_peer_by_name(ofw_tree_node_t *node, const char *name) |
213 | const char *name) |
- | |
214 | { |
224 | { |
215 | ofw_tree_node_t *cur; |
225 | ofw_tree_node_t *cur; |
216 | ofw_tree_property_t *prop; |
226 | ofw_tree_property_t *prop; |
217 | 227 | ||
218 | for (cur = node->peer; cur; cur = cur->peer) { |
228 | for (cur = node->peer; cur; cur = cur->peer) { |
Line 226... | Line 236... | ||
226 | return NULL; |
236 | return NULL; |
227 | } |
237 | } |
228 | 238 | ||
229 | /** Lookup OpenFirmware node by its path. |
239 | /** Lookup OpenFirmware node by its path. |
230 | * |
240 | * |
231 | * @param path Path to the node. |
241 | * @param path Path to the node. |
232 | * |
242 | * |
233 | * @return NULL if there is no such node or pointer to the leaf node. |
243 | * @return NULL if there is no such node or pointer to the leaf |
- | 244 | * node. |
|
234 | */ |
245 | */ |
235 | ofw_tree_node_t *ofw_tree_lookup(const char *path) |
246 | ofw_tree_node_t *ofw_tree_lookup(const char *path) |
236 | { |
247 | { |
237 | char buf[NAME_BUF_LEN+1]; |
248 | char buf[NAME_BUF_LEN + 1]; |
238 | ofw_tree_node_t *node = ofw_root; |
249 | ofw_tree_node_t *node = ofw_root; |
239 | index_t i, j; |
250 | index_t i, j; |
240 | 251 | ||
241 | if (path[0] != '/') |
252 | if (path[0] != '/') |
242 | return NULL; |
253 | return NULL; |
Line 258... | Line 269... | ||
258 | /** Print OpenFirmware device subtree rooted in a node. |
269 | /** Print OpenFirmware device subtree rooted in a node. |
259 | * |
270 | * |
260 | * Child nodes are processed recursively and peer nodes are processed |
271 | * Child nodes are processed recursively and peer nodes are processed |
261 | * iteratively in order to avoid stack overflow. |
272 | * iteratively in order to avoid stack overflow. |
262 | * |
273 | * |
263 | * @param node Root of the subtree. |
274 | * @param node Root of the subtree. |
264 | * @param path Current path, NULL for the very root of the entire tree. |
275 | * @param path Current path, NULL for the very root of the entire tree. |
265 | */ |
276 | */ |
266 | static void ofw_tree_node_print(const ofw_tree_node_t *node, const char *path) |
277 | static void ofw_tree_node_print(const ofw_tree_node_t *node, const char *path) |
267 | { |
278 | { |
268 | char *p; |
279 | char *p; |
269 | const ofw_tree_node_t *cur; |
280 | const ofw_tree_node_t *cur; |