From owner-svn-src-head@FreeBSD.ORG Mon May 11 14:10:55 2015 Return-Path: Delivered-To: svn-src-head@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id B8732210; Mon, 11 May 2015 14:10:55 +0000 (UTC) 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 8CDE3177D; Mon, 11 May 2015 14:10:55 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.9/8.14.9) with ESMTP id t4BEAtL6076932; Mon, 11 May 2015 14:10:55 GMT (envelope-from andrew@FreeBSD.org) Received: (from andrew@localhost) by svn.freebsd.org (8.14.9/8.14.9/Submit) id t4BEAth3076931; Mon, 11 May 2015 14:10:55 GMT (envelope-from andrew@FreeBSD.org) Message-Id: <201505111410.t4BEAth3076931@svn.freebsd.org> X-Authentication-Warning: svn.freebsd.org: andrew set sender to andrew@FreeBSD.org using -f From: Andrew Turner Date: Mon, 11 May 2015 14:10:55 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r282770 - 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: Mon, 11 May 2015 14:10:55 -0000 Author: andrew Date: Mon May 11 14:10:54 2015 New Revision: 282770 URL: https://svnweb.freebsd.org/changeset/base/282770 Log: Add ofw_bus_find_compatible to find a compatible ofw node. This will be used on ARM to help find the correct node to use to start secondary CPUs as this happens before device enumeration. Modified: head/sys/dev/ofw/ofw_bus_subr.c Modified: head/sys/dev/ofw/ofw_bus_subr.c ============================================================================== --- head/sys/dev/ofw/ofw_bus_subr.c Mon May 11 14:07:48 2015 (r282769) +++ head/sys/dev/ofw/ofw_bus_subr.c Mon May 11 14:10:54 2015 (r282770) @@ -176,12 +176,37 @@ ofw_bus_status_okay(device_t dev) return (0); } +static int +ofw_bus_node_is_compatible(const char *compat, int len, const char *onecompat) +{ + int onelen, l, ret; + + onelen = strlen(onecompat); + + ret = 0; + while (len > 0) { + if (strlen(compat) == onelen && + strncasecmp(compat, onecompat, onelen) == 0) { + /* Found it. */ + ret = 1; + break; + } + + /* Slide to the next sub-string. */ + l = strlen(compat) + 1; + compat += l; + len -= l; + } + + return (ret); +} + int ofw_bus_is_compatible(device_t dev, const char *onecompat) { phandle_t node; const char *compat; - int len, onelen, l; + int len; if ((compat = ofw_bus_get_compat(dev)) == NULL) return (0); @@ -193,20 +218,7 @@ ofw_bus_is_compatible(device_t dev, cons if ((len = OF_getproplen(node, "compatible")) <= 0) return (0); - onelen = strlen(onecompat); - - while (len > 0) { - if (strlen(compat) == onelen && - strncasecmp(compat, onecompat, onelen) == 0) - /* Found it. */ - return (1); - - /* Slide to the next sub-string. */ - l = strlen(compat) + 1; - compat += l; - len -= l; - } - return (0); + return (ofw_bus_node_is_compatible(compat, len, onecompat)); } int @@ -487,3 +499,30 @@ ofw_bus_intr_to_rl(device_t dev, phandle return (err); } +phandle_t +ofw_bus_find_compatible(phandle_t node, const char *onecompat) +{ + phandle_t child, ret; + void *compat; + int len; + + /* + * Traverse all children of 'start' node, and find first with + * matching 'compatible' property. + */ + for (child = OF_child(node); child != 0; child = OF_peer(child)) { + len = OF_getprop_alloc(node, "compatible", 1, &compat); + if (len >= 0) { + ret = ofw_bus_node_is_compatible(compat, len, + onecompat); + free(compat, M_OFWPROP); + if (ret != 0) + return (child); + } + + ret = ofw_bus_find_compatible(child, onecompat); + if (ret != 0) + return (ret); + } + return (0); +}