Module Name:    src
Committed By:   jmcneill
Date:           Thu Jul 16 21:32:44 UTC 2020

Modified Files:
        src/sys/dev/ofw: ofw_subr.c openfirm.h

Log Message:
Add of_find_bycompat helper to search a tree for a node by compat string.


To generate a diff of this commit:
cvs rdiff -u -r1.39 -r1.40 src/sys/dev/ofw/ofw_subr.c
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/ofw/openfirm.h

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/dev/ofw/ofw_subr.c
diff -u src/sys/dev/ofw/ofw_subr.c:1.39 src/sys/dev/ofw/ofw_subr.c:1.40
--- src/sys/dev/ofw/ofw_subr.c:1.39	Fri Jun 26 10:14:32 2020
+++ src/sys/dev/ofw/ofw_subr.c	Thu Jul 16 21:32:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.c,v 1.39 2020/06/26 10:14:32 martin Exp $	*/
+/*	$NetBSD: ofw_subr.c,v 1.40 2020/07/16 21:32:44 jmcneill Exp $	*/
 
 /*
  * Copyright 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.39 2020/06/26 10:14:32 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.40 2020/07/16 21:32:44 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -337,6 +337,26 @@ of_find_firstchild_byname(int node, cons
 }
 
 /*
+ * Find a child node that is compatible with str. Recurses, starting at node.
+ */
+int
+of_find_bycompat(int node, const char *str)
+{
+	const char * compatible[] = { str, NULL };
+	int child, ret;
+
+	for (child = OF_child(node); child; child = OF_peer(child)) {
+		if (of_match_compatible(child, compatible) != 0)
+			return child;
+		ret = of_find_bycompat(child, str);
+		if (ret != -1)
+			return ret;
+	}
+
+	return -1;
+}
+
+/*
  * Find a give node by name.  Recurses, and seems to walk upwards too.
  */
 

Index: src/sys/dev/ofw/openfirm.h
diff -u src/sys/dev/ofw/openfirm.h:1.38 src/sys/dev/ofw/openfirm.h:1.39
--- src/sys/dev/ofw/openfirm.h:1.38	Tue Aug  6 18:17:52 2019
+++ src/sys/dev/ofw/openfirm.h	Thu Jul 16 21:32:44 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: openfirm.h,v 1.38 2019/08/06 18:17:52 tnn Exp $	*/
+/*	$NetBSD: openfirm.h,v 1.39 2020/07/16 21:32:44 jmcneill Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -116,6 +116,7 @@ const struct of_compat_data *
 int	of_decode_int(const unsigned char *);
 int	of_packagename(int, char *, int);
 int	of_find_firstchild_byname(int, const char *);
+int	of_find_bycompat(int, const char *);
 int	of_getnode_byname(int, const char *);
 boolean_t	of_to_uint32_prop(prop_dictionary_t, int, const char *,
     const char *);

Reply via email to