42,7 → 42,8 |
|
static ofw_tree_property_t *ofw_tree_properties_alloc(unsigned count) |
{ |
return balloc(count * sizeof(ofw_tree_property_t), sizeof(ofw_tree_property_t)); |
return balloc(count * sizeof(ofw_tree_property_t), |
sizeof(ofw_tree_property_t)); |
} |
|
static void * ofw_tree_space_alloc(size_t size) |
65,16 → 66,18 |
return addr; |
} |
|
/** Transfer information from one OpenFirmware node into its memory representation. |
/** Transfer information from one OpenFirmware node into its memory |
* representation. |
* |
* Transfer entire information from the OpenFirmware device tree 'current' node to |
* its memory representation in 'current_node'. This function recursively processes |
* all node's children. Node's peers are processed iteratively in order to prevent |
* stack from overflowing. |
* Transfer entire information from the OpenFirmware device tree 'current' node |
* to its memory representation in 'current_node'. This function recursively |
* processes all node's children. Node's peers are processed iteratively in |
* order to prevent stack from overflowing. |
* |
* @param current_node Pointer to uninitialized ofw_tree_node structure that will |
* become the memory represenation of 'current'. |
* @param parent_node Parent ofw_tree_node structure or NULL in case of root node. |
* @param current_node Pointer to uninitialized ofw_tree_node structure that |
* will become the memory represenation of 'current'. |
* @param parent_node Parent ofw_tree_node structure or NULL in case of root |
* node. |
* @param current OpenFirmware phandle to the current device tree node. |
*/ |
static void ofw_tree_node_process(ofw_tree_node_t *current_node, |
82,6 → 85,7 |
{ |
static char path[MAX_PATH_LEN+1]; |
static char name[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
static char name2[OFW_TREE_PROPERTY_MAX_NAMELEN]; |
phandle peer; |
phandle child; |
size_t len; |
130,7 → 134,8 |
|
child_node = ofw_tree_node_alloc(); |
if (child_node) { |
ofw_tree_node_process(child_node, current_node, child); |
ofw_tree_node_process(child_node, current_node, |
child); |
current_node->child = child_node; |
} |
} |
139,8 → 144,10 |
* Count properties. |
*/ |
name[0] = '\0'; |
while (ofw_next_property(current, name, name) == 1) |
while (ofw_next_property(current, name, name2) == 1) { |
current_node->properties++; |
memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN); |
} |
|
if (!current_node->properties) |
return; |
148,20 → 155,23 |
/* |
* Copy properties. |
*/ |
current_node->property = ofw_tree_properties_alloc(current_node->properties); |
current_node->property = |
ofw_tree_properties_alloc(current_node->properties); |
if (!current_node->property) |
return; |
|
name[0] = '\0'; |
for (i = 0; ofw_next_property(current, name, name) == 1; i++) { |
for (i = 0; ofw_next_property(current, name, name2) == 1; i++) { |
size_t size; |
|
if (i == current_node->properties) |
break; |
|
memcpy(name, name2, OFW_TREE_PROPERTY_MAX_NAMELEN); |
memcpy(current_node->property[i].name, name, |
OFW_TREE_PROPERTY_MAX_NAMELEN); |
current_node->property[i].name[OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0'; |
current_node->property[i].name[ |
OFW_TREE_PROPERTY_MAX_NAMELEN] = '\0'; |
|
size = ofw_get_proplen(current, name); |
current_node->property[i].size = size; |
173,7 → 183,8 |
/* |
* Copy property value to memory node. |
*/ |
(void) ofw_get_property(current, name, buf, size); |
(void) ofw_get_property(current, name, |
buf, size); |
} |
} else { |
current_node->property[i].value = NULL; |
180,7 → 191,8 |
} |
} |
|
current_node->properties = i; /* Just in case we ran out of memory. */ |
/* Just in case we ran out of memory. */ |
current_node->properties = i; |
|
/* |
* Iteratively process the next peer node. |
234,8 → 246,8 |
if (ssm_node != -1) { |
ssm = ofw_tree_node_alloc(); |
if (ssm) { |
ofw_tree_node_process( |
ssm, root, ofw_find_device("/ssm@0,0")); |
ofw_tree_node_process(ssm, root, |
ofw_find_device("/ssm@0,0")); |
ssm->peer = root->child; |
root->child = ssm; |
} |