Date: Sat, 20 Jun 2015 04:48:49 +0000 (UTC) From: Warner Losh <imp@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284624 - head/sys/dev/ofw Message-ID: <201506200448.t5K4mnAB088545@svn.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: imp Date: Sat Jun 20 04:48:48 2015 New Revision: 284624 URL: https://svnweb.freebsd.org/changeset/base/284624 Log: 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 Modified: head/sys/dev/ofw/ofw_bus_subr.c head/sys/dev/ofw/ofw_bus_subr.h Modified: head/sys/dev/ofw/ofw_bus_subr.c ============================================================================== --- head/sys/dev/ofw/ofw_bus_subr.c Sat Jun 20 04:02:33 2015 (r284623) +++ head/sys/dev/ofw/ofw_bus_subr.c Sat Jun 20 04:48:48 2015 (r284624) @@ -551,3 +551,44 @@ ofw_bus_find_compatible(phandle_t node, } 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); +} Modified: head/sys/dev/ofw/ofw_bus_subr.h ============================================================================== --- head/sys/dev/ofw/ofw_bus_subr.h Sat Jun 20 04:02:33 2015 (r284623) +++ head/sys/dev/ofw/ofw_bus_subr.h Sat Jun 20 04:48:48 2015 (r284624) @@ -107,4 +107,7 @@ phandle_t ofw_bus_find_compatible(phandl /* 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_ */
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201506200448.t5K4mnAB088545>