ofw_fdt: Simplify parts with new libfdt methods
libfdt now provides methods to iterate through subnodes and properties in a convenient fashion. Replace our ofw_fdt_{peer,child} searches with calls to their corresponding libfdt methods. Rework ofw_fdt_nextprop to use the fdt_for_each_property_offset macro, making it even more obvious what it's doing. No functional change intended. Reviewed by: nwhitehorn MFC after: 1 week Differential Revision: https://reviews.freebsd.org/D14225
This commit is contained in:
parent
ed8bce2cd5
commit
cd78f5ff20
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=330019
@ -174,7 +174,7 @@ fdt_phandle_offset(phandle_t p)
|
|||||||
static phandle_t
|
static phandle_t
|
||||||
ofw_fdt_peer(ofw_t ofw, phandle_t node)
|
ofw_fdt_peer(ofw_t ofw, phandle_t node)
|
||||||
{
|
{
|
||||||
int depth, offset;
|
int offset;
|
||||||
|
|
||||||
if (node == 0) {
|
if (node == 0) {
|
||||||
/* Find root node */
|
/* Find root node */
|
||||||
@ -186,39 +186,21 @@ ofw_fdt_peer(ofw_t ofw, phandle_t node)
|
|||||||
offset = fdt_phandle_offset(node);
|
offset = fdt_phandle_offset(node);
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
offset = fdt_next_subnode(fdtp, offset);
|
||||||
for (depth = 1, offset = fdt_next_node(fdtp, offset, &depth);
|
return (fdt_offset_phandle(offset));
|
||||||
offset >= 0;
|
|
||||||
offset = fdt_next_node(fdtp, offset, &depth)) {
|
|
||||||
if (depth < 0)
|
|
||||||
return (0);
|
|
||||||
if (depth == 1)
|
|
||||||
return (fdt_offset_phandle(offset));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the first child of this node or 0. */
|
/* Return the first child of this node or 0. */
|
||||||
static phandle_t
|
static phandle_t
|
||||||
ofw_fdt_child(ofw_t ofw, phandle_t node)
|
ofw_fdt_child(ofw_t ofw, phandle_t node)
|
||||||
{
|
{
|
||||||
int depth, offset;
|
int offset;
|
||||||
|
|
||||||
offset = fdt_phandle_offset(node);
|
offset = fdt_phandle_offset(node);
|
||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return (0);
|
return (0);
|
||||||
|
offset = fdt_first_subnode(fdtp, offset);
|
||||||
for (depth = 0, offset = fdt_next_node(fdtp, offset, &depth);
|
return (fdt_offset_phandle(offset));
|
||||||
(offset >= 0) && (depth > 0);
|
|
||||||
offset = fdt_next_node(fdtp, offset, &depth)) {
|
|
||||||
if (depth < 0)
|
|
||||||
return (0);
|
|
||||||
if (depth == 1)
|
|
||||||
return (fdt_offset_phandle(offset));
|
|
||||||
}
|
|
||||||
|
|
||||||
return (0);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Return the parent of this node or 0. */
|
/* Return the parent of this node or 0. */
|
||||||
@ -341,27 +323,25 @@ ofw_fdt_nextprop(ofw_t ofw, phandle_t package, const char *previous, char *buf,
|
|||||||
if (offset < 0)
|
if (offset < 0)
|
||||||
return (-1);
|
return (-1);
|
||||||
|
|
||||||
/* Find the first prop in the node */
|
if (previous == NULL)
|
||||||
offset = fdt_first_property_offset(fdtp, offset);
|
/* Find the first prop in the node */
|
||||||
if (offset < 0)
|
offset = fdt_first_property_offset(fdtp, offset);
|
||||||
return (0); /* No properties */
|
else {
|
||||||
|
fdt_for_each_property_offset(offset, fdtp, offset) {
|
||||||
if (previous != NULL) {
|
|
||||||
while (offset >= 0) {
|
|
||||||
prop = fdt_getprop_by_offset(fdtp, offset, &name, NULL);
|
prop = fdt_getprop_by_offset(fdtp, offset, &name, NULL);
|
||||||
if (prop == NULL)
|
if (prop == NULL)
|
||||||
return (-1); /* Internal error */
|
return (-1); /* Internal error */
|
||||||
|
/* Skip until we find 'previous', then bail out */
|
||||||
|
if (strcmp(name, previous) != 0)
|
||||||
|
continue;
|
||||||
offset = fdt_next_property_offset(fdtp, offset);
|
offset = fdt_next_property_offset(fdtp, offset);
|
||||||
if (offset < 0)
|
break;
|
||||||
return (0); /* No more properties */
|
|
||||||
|
|
||||||
/* Check if the last one was the one we wanted */
|
|
||||||
if (strcmp(name, previous) == 0)
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (offset < 0)
|
||||||
|
return (0); /* No properties */
|
||||||
|
|
||||||
prop = fdt_getprop_by_offset(fdtp, offset, &name, &offset);
|
prop = fdt_getprop_by_offset(fdtp, offset, &name, &offset);
|
||||||
if (prop == NULL)
|
if (prop == NULL)
|
||||||
return (-1); /* Internal error */
|
return (-1); /* Internal error */
|
||||||
|
Loading…
Reference in New Issue
Block a user