Module Name:    src
Committed By:   jmcneill
Date:           Fri Jun 30 09:17:05 UTC 2017

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

Log Message:
Add of_search_compatible, which searches an array of compat_data structures
for a matching "compatible" entry matching the supplied OFW node. This
allows us to associate data with compatible strings.


To generate a diff of this commit:
cvs rdiff -u -r1.28 -r1.29 src/sys/dev/ofw/ofw_subr.c
cvs rdiff -u -r1.34 -r1.35 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.28 src/sys/dev/ofw/ofw_subr.c:1.29
--- src/sys/dev/ofw/ofw_subr.c:1.28	Sun Apr 30 16:46:09 2017
+++ src/sys/dev/ofw/ofw_subr.c	Fri Jun 30 09:17:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.c,v 1.28 2017/04/30 16:46:09 jmcneill Exp $	*/
+/*	$NetBSD: ofw_subr.c,v 1.29 2017/06/30 09:17:05 jmcneill Exp $	*/
 
 /*
  * Copyright 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.28 2017/04/30 16:46:09 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.29 2017/06/30 09:17:05 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -186,6 +186,38 @@ of_match_compatible(int phandle, const c
 }
 
 /*
+ * const struct of_compat_data *of_search_compatible(phandle, compat_data)
+ *
+ * This routine searches an array of compat_data structures for a
+ * matching "compatible" entry matching the supplied OFW node.
+ *
+ * Arguments:
+ *	phandle		OFW phandle of device to be checked for
+ *			compatibility.
+ *	compat_data	Array of possible compat entry strings and
+ *			associated metadata. The last entry in the
+ *			list should have a "compat" of NULL to terminate
+ *			the list.
+ *
+ * Return Value:
+ *	The first matching compat_data entry in the array. If no matches
+ *	are found, the terminating ("compat" of NULL) record is returned.
+ *
+ * Side Effects:
+ *	None.
+ */
+const struct of_compat_data *
+of_search_compatible(int phandle, const struct of_compat_data *compat_data)
+{
+	for (; compat_data->compat != NULL; compat_data++) {
+		const char *compat[] = { compat_data->compat, NULL };
+		if (of_match_compatible(phandle, compat))
+			break;
+	}
+	return compat_data;
+}
+
+/*
  * int of_packagename(phandle, buf, bufsize)
  *
  * This routine places the last component of an OFW node's name

Index: src/sys/dev/ofw/openfirm.h
diff -u src/sys/dev/ofw/openfirm.h:1.34 src/sys/dev/ofw/openfirm.h:1.35
--- src/sys/dev/ofw/openfirm.h:1.34	Sun Apr 30 16:46:09 2017
+++ src/sys/dev/ofw/openfirm.h	Fri Jun 30 09:17:05 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: openfirm.h,v 1.34 2017/04/30 16:46:09 jmcneill Exp $	*/
+/*	$NetBSD: openfirm.h,v 1.35 2017/06/30 09:17:05 jmcneill Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -65,6 +65,10 @@ struct ofbus_attach_args {
 	int		oba_unit;
 };
 
+struct of_compat_data {
+	const char *compat;
+	uintptr_t data;
+};
 
 /*
  * Functions and variables provided by machine-dependent code.
@@ -106,6 +110,8 @@ int	openfirmware(void *);
  */
 int	of_compatible(int, const char * const *);
 int	of_match_compatible(int, const char * const *);
+const struct of_compat_data *
+	of_search_compatible(int, 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 *);

Reply via email to