diff options
Diffstat (limited to 'sys/dev/ofw/ofw_bus_subr.c')
-rw-r--r-- | sys/dev/ofw/ofw_bus_subr.c | 41 |
1 files changed, 41 insertions, 0 deletions
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c index a9261ce..233675d 100644 --- a/sys/dev/ofw/ofw_bus_subr.c +++ b/sys/dev/ofw/ofw_bus_subr.c @@ -551,3 +551,44 @@ ofw_bus_find_compatible(phandle_t node, const char *onecompat) } return (0); } + +/** + * @brief Return child of bus whose phandle is node + * + * A direct child of @p will be returned if it its phandle in the + * OFW tree is @p node. Otherwise, NULL is returned. + * + * @param bus The bus to examine + * @param node The phandle_t to look for. + */ +device_t +ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node) +{ + device_t *children, retval, child; + int nkid, i; + + /* + * Nothing can match the flag value for no node. + */ + if (node == -1) + return (NULL); + + /* + * Search the children for a match. We microoptimize + * a bit by not using ofw_bus_get since we already know + * the parent. We do not recurse. + */ + if (device_get_children(bus, &children, &nkid) != 0) + return (NULL); + retval = NULL; + for (i = 0; i < nkid; i++) { + child = children[i]; + if (OFW_BUS_GET_NODE(bus, child) == node) { + retval = child; + break; + } + } + free(children, M_TEMP); + + return (retval); +} |