From owner-svn-src-head@FreeBSD.ORG Sat Jun 20 04:48:50 2015 Return-Path: Delivered-To: svn-src-head@hub.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 0BD90E01; Sat, 20 Jun 2015 04:48:50 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id D4456782; Sat, 20 Jun 2015 04:48:49 +0000 (UTC) (envelope-from imp@FreeBSD.org) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t5K4mnrs088550; Sat, 20 Jun 2015 04:48:49 GMT (envelope-from imp@FreeBSD.org) Received: (from imp@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t5K4mnAB088545; Sat, 20 Jun 2015 04:48:49 GMT (envelope-from imp@FreeBSD.org) Message-Id: <201506200448.t5K4mnAB088545@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: imp set sender to imp@FreeBSD.org using -f From: Warner Losh Date: Sat, 20 Jun 2015 04:48:49 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r284624 - head/sys/dev/ofw X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 20 Jun 2015 04:48:50 -0000 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_ */