Module Name:    src
Committed By:   jmcneill
Date:           Sat Jan 19 20:50:48 UTC 2019

Modified Files:
        src/sys/dev/fdt: fdtbus.c fdtvar.h

Log Message:
Add a helper to search the tree for a node with the specified property


To generate a diff of this commit:
cvs rdiff -u -r1.25 -r1.26 src/sys/dev/fdt/fdtbus.c
cvs rdiff -u -r1.44 -r1.45 src/sys/dev/fdt/fdtvar.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/fdt/fdtbus.c
diff -u src/sys/dev/fdt/fdtbus.c:1.25 src/sys/dev/fdt/fdtbus.c:1.26
--- src/sys/dev/fdt/fdtbus.c:1.25	Wed Jan  2 14:54:54 2019
+++ src/sys/dev/fdt/fdtbus.c	Sat Jan 19 20:50:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtbus.c,v 1.25 2019/01/02 14:54:54 jmcneill Exp $ */
+/* $NetBSD: fdtbus.c,v 1.26 2019/01/19 20:50:48 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.25 2019/01/02 14:54:54 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fdtbus.c,v 1.26 2019/01/19 20:50:48 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -345,6 +345,24 @@ fdt_remove_bycompat(const char *compatib
 	}
 }
 
+int
+fdt_find_with_property(const char *prop, int *pindex)
+{
+	struct fdt_node *node;
+	int index = 0;
+
+	TAILQ_FOREACH(node, &fdt_nodes, n_nodes) {
+		if (index < *pindex)
+			continue;
+		if (of_hasprop(node->n_phandle, prop)) {
+			*pindex = index;
+			return node->n_phandle;
+		}
+	}
+
+	return -1;
+}
+
 static u_int
 fdt_get_order(int phandle)
 {

Index: src/sys/dev/fdt/fdtvar.h
diff -u src/sys/dev/fdt/fdtvar.h:1.44 src/sys/dev/fdt/fdtvar.h:1.45
--- src/sys/dev/fdt/fdtvar.h:1.44	Wed Jan  2 18:38:43 2019
+++ src/sys/dev/fdt/fdtvar.h	Sat Jan 19 20:50:48 2019
@@ -1,4 +1,4 @@
-/* $NetBSD: fdtvar.h,v 1.44 2019/01/02 18:38:43 jmcneill Exp $ */
+/* $NetBSD: fdtvar.h,v 1.45 2019/01/19 20:50:48 jmcneill Exp $ */
 
 /*-
  * Copyright (c) 2015 Jared D. McNeill <[email protected]>
@@ -368,6 +368,7 @@ void		fdt_add_child(device_t, int, struc
 
 void		fdt_remove_byhandle(int);
 void		fdt_remove_bycompat(const char *[]);
+int		fdt_find_with_property(const char *, int *);
 int		fdtbus_print(void *, const char *);
 
 #endif /* _DEV_FDT_FDTVAR_H */

Reply via email to