Changes in kernel/genarch/src/ofw/ofw_tree.c [3113d47:63b5493] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/genarch/src/ofw/ofw_tree.c
r3113d47 r63b5493 38 38 #include <genarch/ofw/ofw_tree.h> 39 39 #include <mm/slab.h> 40 #include <sysinfo/sysinfo.h>41 40 #include <memstr.h> 42 41 #include <str.h> … … 66 65 const char *name) 67 66 { 68 for (size_t i = 0; i < node->properties; i++) { 67 size_t i; 68 69 for (i = 0; i < node->properties; i++) { 69 70 if (str_cmp(node->property[i].name, name) == 0) 70 71 return &node->property[i]; … … 103 104 const char *name) 104 105 { 106 ofw_tree_node_t *cur; 107 105 108 /* 106 109 * Try to find the disambigued name. 107 110 */ 108 for ( ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) {111 for (cur = node->child; cur; cur = cur->peer) { 109 112 if (str_cmp(cur->da_name, name) == 0) 110 113 return cur; … … 118 121 * are not always fully-qualified. 119 122 */ 120 for ( ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) {123 for (cur = node->child; cur; cur = cur->peer) { 121 124 if (str_cmp(ofw_tree_node_name(cur), name) == 0) 122 125 return cur; … … 138 141 const char *dtype) 139 142 { 140 for (ofw_tree_node_t *cur = node->child; cur; cur = cur->peer) { 143 ofw_tree_node_t *cur; 144 145 for (cur = node->child; cur; cur = cur->peer) { 141 146 ofw_tree_property_t *prop = 142 147 ofw_tree_getprop(cur, "device_type"); … … 167 172 phandle handle) 168 173 { 169 for (ofw_tree_node_t *cur = root; cur; cur = cur->peer) { 174 ofw_tree_node_t *cur; 175 176 for (cur = root; cur; cur = cur->peer) { 170 177 if (cur->node_handle == handle) 171 178 return cur; 172 179 173 180 if (cur->child) { 174 ofw_tree_node_t *node =175 ofw_tree_find_node_by_handle(cur->child, handle);181 ofw_tree_node_t *node 182 = ofw_tree_find_node_by_handle(cur->child, handle); 176 183 if (node) 177 184 return node; … … 194 201 const char *dtype) 195 202 { 196 for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) { 203 ofw_tree_node_t *cur; 204 205 for (cur = node->peer; cur; cur = cur->peer) { 197 206 ofw_tree_property_t *prop = 198 207 ofw_tree_getprop(cur, "device_type"); … … 220 229 const char *name) 221 230 { 222 for (ofw_tree_node_t *cur = node->peer; cur; cur = cur->peer) { 223 ofw_tree_property_t *prop = 224 ofw_tree_getprop(cur, "name"); 231 ofw_tree_node_t *cur; 232 233 for (cur = node->peer; cur; cur = cur->peer) { 234 ofw_tree_property_t *prop 235 = ofw_tree_getprop(cur, "name"); 225 236 226 237 if ((!prop) || (!prop->value)) … … 248 259 249 260 ofw_tree_node_t *node = ofw_root; 261 size_t i; 250 262 size_t j; 251 263 252 for ( size_ti = 1; (i < str_size(path)) && (node); i = j + 1) {264 for (i = 1; (i < str_size(path)) && (node); i = j + 1) { 253 265 for (j = i; (j < str_size(path)) && (path[j] != '/'); j++); 254 266 … … 282 294 const char *dtype, ofw_tree_walker_t walker, void *arg) 283 295 { 284 for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) { 296 ofw_tree_node_t *cur; 297 298 for (cur = node; cur; cur = cur->peer) { 285 299 ofw_tree_property_t *prop = 286 300 ofw_tree_getprop(cur, "device_type"); … … 320 334 } 321 335 322 /** Get OpenFirmware node properties. 323 * 324 * @param item Sysinfo item (unused). 325 * @param size Size of the returned data. 326 * @param dry_run Do not get the data, just calculate the size. 327 * @param data OpenFirmware node. 328 * 329 * @return Data containing a serialized dump of all node 330 * properties. If the return value is not NULL, it 331 * should be freed in the context of the sysinfo request. 332 * 333 */ 334 static void *ofw_sysinfo_properties(struct sysinfo_item *item, size_t *size, 335 bool dry_run, void *data) 336 { 337 ofw_tree_node_t *node = (ofw_tree_node_t *) data; 338 339 /* Compute serialized data size */ 340 *size = 0; 341 for (size_t i = 0; i < node->properties; i++) 342 *size += str_size(node->property[i].name) + 1 + 343 sizeof(node->property[i].size) + node->property[i].size; 344 345 if (dry_run) 346 return NULL; 347 348 void *dump = malloc(*size, FRAME_ATOMIC); 349 if (dump == NULL) { 350 *size = 0; 351 return NULL; 352 } 353 354 /* Serialize the data */ 355 size_t pos = 0; 356 for (size_t i = 0; i < node->properties; i++) { 357 /* Property name */ 358 str_cpy(dump + pos, *size - pos, node->property[i].name); 359 pos += str_size(node->property[i].name) + 1; 360 361 /* Value size */ 362 memcpy(dump + pos, &node->property[i].size, 363 sizeof(node->property[i].size)); 364 pos += sizeof(node->property[i].size); 365 366 /* Value */ 367 memcpy(dump + pos, node->property[i].value, 368 node->property[i].size); 369 pos += node->property[i].size; 370 } 371 372 return ((void *) dump); 373 } 374 375 /** Map OpenFirmware device subtree rooted in a node into sysinfo. 336 /** Print OpenFirmware device subtree rooted in a node. 376 337 * 377 338 * Child nodes are processed recursively and peer nodes are processed … … 382 343 * 383 344 */ 384 static void ofw_tree_node_ sysinfo(ofw_tree_node_t *node, const char *path)345 static void ofw_tree_node_print(ofw_tree_node_t *node, const char *path) 385 346 { 386 347 char *cur_path = (char *) malloc(PATH_MAX_LEN, 0); 387 388 for (ofw_tree_node_t *cur = node; cur; cur = cur->peer) { 389 if ((cur->parent) && (path)) 390 snprintf(cur_path, PATH_MAX_LEN, "%s.%s", path, cur->da_name); 391 else 392 snprintf(cur_path, PATH_MAX_LEN, "firmware.%s", cur->da_name); 393 394 sysinfo_set_item_gen_data(cur_path, NULL, ofw_sysinfo_properties, 395 (void *) cur); 348 ofw_tree_node_t *cur; 349 350 for (cur = node; cur; cur = cur->peer) { 351 if ((cur->parent) && (path)) { 352 snprintf(cur_path, PATH_MAX_LEN, "%s/%s", path, cur->da_name); 353 printf("%s\n", cur_path); 354 } else { 355 snprintf(cur_path, PATH_MAX_LEN, "%s", cur->da_name); 356 printf("/\n"); 357 } 396 358 397 359 if (cur->child) 398 ofw_tree_node_ sysinfo(cur->child, cur_path);360 ofw_tree_node_print(cur->child, cur_path); 399 361 } 400 362 … … 402 364 } 403 365 404 /** Map the OpenFirmware device tree into sysinfo. */405 void ofw_ sysinfo_map(void)406 { 407 ofw_tree_node_ sysinfo(ofw_root, NULL);366 /** Print the structure of the OpenFirmware device tree. */ 367 void ofw_tree_print(void) 368 { 369 ofw_tree_node_print(ofw_root, NULL); 408 370 } 409 371
Note:
See TracChangeset
for help on using the changeset viewer.