Add ofw_bus_find_child_by_phandle, a helper routine to find a device_t
child matchig a given phandle_t. Differential Revision: https://reviews.freebsd.org/D2871
This commit is contained in:
parent
0a866e9f12
commit
9d4e4ebe6d
@ -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);
|
||||
}
|
||||
|
@ -107,4 +107,7 @@ phandle_t ofw_bus_find_compatible(phandle_t, const char *);
|
||||
/* Helper to search for a child with a given name */
|
||||
phandle_t ofw_bus_find_child(phandle_t, const char *);
|
||||
|
||||
/* Helper routine to find a device_t child matchig a given phandle_t */
|
||||
device_t ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node);
|
||||
|
||||
#endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */
|
||||
|
Loading…
Reference in New Issue
Block a user