Rev 3675 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 3675 | Rev 4377 | ||
---|---|---|---|
Line 36... | Line 36... | ||
36 | */ |
36 | */ |
37 | 37 | ||
38 | #include <genarch/ofw/ofw_tree.h> |
38 | #include <genarch/ofw/ofw_tree.h> |
39 | #include <arch/memstr.h> |
39 | #include <arch/memstr.h> |
40 | #include <mm/slab.h> |
40 | #include <mm/slab.h> |
41 | #include <func.h> |
41 | #include <string.h> |
42 | #include <print.h> |
42 | #include <print.h> |
43 | #include <panic.h> |
43 | #include <panic.h> |
44 | 44 | ||
45 | #define PATH_MAX_LEN 80 |
45 | #define PATH_MAX_LEN 80 |
46 | #define NAME_BUF_LEN 50 |
46 | #define NAME_BUF_LEN 50 |
Line 64... | Line 64... | ||
64 | 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) |
65 | { |
65 | { |
66 | unsigned int i; |
66 | unsigned int i; |
67 | 67 | ||
68 | for (i = 0; i < node->properties; i++) { |
68 | for (i = 0; i < node->properties; i++) { |
69 | if (strcmp(node->property[i].name, name) == 0) |
69 | if (str_cmp(node->property[i].name, name) == 0) |
70 | return &node->property[i]; |
70 | return &node->property[i]; |
71 | } |
71 | } |
72 | 72 | ||
73 | return NULL; |
73 | return NULL; |
74 | } |
74 | } |
Line 83... | Line 83... | ||
83 | { |
83 | { |
84 | ofw_tree_property_t *prop; |
84 | ofw_tree_property_t *prop; |
85 | 85 | ||
86 | prop = ofw_tree_getprop(node, "name"); |
86 | prop = ofw_tree_getprop(node, "name"); |
87 | if (!prop) |
87 | if (!prop) |
88 | panic("Node without name property.\n"); |
88 | panic("Node without name property."); |
89 | 89 | ||
90 | if (prop->size < 2) |
90 | if (prop->size < 2) |
91 | panic("Invalid name property.\n"); |
91 | panic("Invalid name property."); |
92 | 92 | ||
93 | return prop->value; |
93 | return prop->value; |
94 | } |
94 | } |
95 | 95 | ||
96 | /** Lookup child of given name. |
96 | /** Lookup child of given name. |
Line 107... | Line 107... | ||
107 | 107 | ||
108 | /* |
108 | /* |
109 | * Try to find the disambigued name. |
109 | * Try to find the disambigued name. |
110 | */ |
110 | */ |
111 | for (cur = node->child; cur; cur = cur->peer) { |
111 | for (cur = node->child; cur; cur = cur->peer) { |
112 | if (strcmp(cur->da_name, name) == 0) |
112 | if (str_cmp(cur->da_name, name) == 0) |
113 | return cur; |
113 | return cur; |
114 | } |
114 | } |
115 | 115 | ||
116 | /* |
116 | /* |
117 | * Disambigued name not found. |
117 | * Disambigued name not found. |
Line 119... | Line 119... | ||
119 | * |
119 | * |
120 | * We need to do this because paths stored in "/aliases" |
120 | * We need to do this because paths stored in "/aliases" |
121 | * are not always fully-qualified. |
121 | * are not always fully-qualified. |
122 | */ |
122 | */ |
123 | for (cur = node->child; cur; cur = cur->peer) { |
123 | for (cur = node->child; cur; cur = cur->peer) { |
124 | if (strcmp(ofw_tree_node_name(cur), name) == 0) |
124 | if (str_cmp(ofw_tree_node_name(cur), name) == 0) |
125 | return cur; |
125 | return cur; |
126 | } |
126 | } |
127 | 127 | ||
128 | return NULL; |
128 | return NULL; |
129 | } |
129 | } |
Line 144... | Line 144... | ||
144 | 144 | ||
145 | for (cur = node->child; cur; cur = cur->peer) { |
145 | for (cur = node->child; cur; cur = cur->peer) { |
146 | prop = ofw_tree_getprop(cur, "device_type"); |
146 | prop = ofw_tree_getprop(cur, "device_type"); |
147 | if (!prop || !prop->value) |
147 | if (!prop || !prop->value) |
148 | continue; |
148 | continue; |
149 | if (strcmp(prop->value, name) == 0) |
149 | if (str_cmp(prop->value, name) == 0) |
150 | return cur; |
150 | return cur; |
151 | } |
151 | } |
152 | 152 | ||
153 | return NULL; |
153 | return NULL; |
154 | } |
154 | } |
Line 201... | Line 201... | ||
201 | 201 | ||
202 | for (cur = node->peer; cur; cur = cur->peer) { |
202 | for (cur = node->peer; cur; cur = cur->peer) { |
203 | prop = ofw_tree_getprop(cur, "device_type"); |
203 | prop = ofw_tree_getprop(cur, "device_type"); |
204 | if (!prop || !prop->value) |
204 | if (!prop || !prop->value) |
205 | continue; |
205 | continue; |
206 | if (strcmp(prop->value, name) == 0) |
206 | if (str_cmp(prop->value, name) == 0) |
207 | return cur; |
207 | return cur; |
208 | } |
208 | } |
209 | 209 | ||
210 | return NULL; |
210 | return NULL; |
211 | } |
211 | } |
Line 227... | Line 227... | ||
227 | 227 | ||
228 | for (cur = node->peer; cur; cur = cur->peer) { |
228 | for (cur = node->peer; cur; cur = cur->peer) { |
229 | prop = ofw_tree_getprop(cur, "name"); |
229 | prop = ofw_tree_getprop(cur, "name"); |
230 | if (!prop || !prop->value) |
230 | if (!prop || !prop->value) |
231 | continue; |
231 | continue; |
232 | if (strcmp(prop->value, name) == 0) |
232 | if (str_cmp(prop->value, name) == 0) |
233 | return cur; |
233 | return cur; |
234 | } |
234 | } |
235 | 235 | ||
236 | return NULL; |
236 | return NULL; |
237 | } |
237 | } |
Line 250... | Line 250... | ||
250 | index_t i, j; |
250 | index_t i, j; |
251 | 251 | ||
252 | if (path[0] != '/') |
252 | if (path[0] != '/') |
253 | return NULL; |
253 | return NULL; |
254 | 254 | ||
255 | for (i = 1; i < strlen(path) && node; i = j + 1) { |
255 | for (i = 1; (i < str_size(path)) && (node); i = j + 1) { |
256 | for (j = i; j < strlen(path) && path[j] != '/'; j++) |
256 | for (j = i; (j < str_size(path)) && (path[j] != '/'); j++); |
257 | ; |
257 | |
258 | if (i == j) /* skip extra slashes */ |
258 | /* Skip extra slashes */ |
- | 259 | if (i == j) |
|
259 | continue; |
260 | continue; |
260 | 261 | ||
261 | memcpy(buf, &path[i], j - i); |
262 | memcpy(buf, &path[i], j - i); |
262 | buf[j - i] = '\0'; |
263 | buf[j - i] = 0; |
263 | node = ofw_tree_find_child(node, buf); |
264 | node = ofw_tree_find_child(node, buf); |
264 | } |
265 | } |
265 | 266 | ||
266 | return node; |
267 | return node; |
267 | } |
268 | } |