Module Name:    src
Committed By:   jmcneill
Date:           Mon Jul  3 00:47:34 UTC 2017

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

Log Message:
Add of_match_compat_data.

This routine searches an array of compat_data structures for a
matching "compatible" entry matching the supplied OFW node.


To generate a diff of this commit:
cvs rdiff -u -r1.29 -r1.30 src/sys/dev/ofw/ofw_subr.c
cvs rdiff -u -r1.35 -r1.36 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.29 src/sys/dev/ofw/ofw_subr.c:1.30
--- src/sys/dev/ofw/ofw_subr.c:1.29	Fri Jun 30 09:17:05 2017
+++ src/sys/dev/ofw/ofw_subr.c	Mon Jul  3 00:47:34 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: ofw_subr.c,v 1.29 2017/06/30 09:17:05 jmcneill Exp $	*/
+/*	$NetBSD: ofw_subr.c,v 1.30 2017/07/03 00:47:34 jmcneill Exp $	*/
 
 /*
  * Copyright 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.29 2017/06/30 09:17:05 jmcneill Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.30 2017/07/03 00:47:34 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -186,6 +186,43 @@ of_match_compatible(int phandle, const c
 }
 
 /*
+ * int of_match_compat_data(phandle, compat_data)
+ *
+ * This routine searches an array of compat_data structures for a
+ * matching "compatible" entry matching the supplied OFW node.
+ *
+ * It should be used when determining whether a driver can drive
+ * a particular device.
+ *
+ * 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:
+ *	0 if none of the strings are found in phandle's "compatibility"
+ *	property, or a positive number based on the reverse index of the
+ *	matching string in the phandle's "compatibility" property, plus 1.
+ *
+ * Side Effects:
+ *	None.
+ */
+int
+of_match_compat_data(int phandle, const struct of_compat_data *compat_data)
+{
+	for (; compat_data->compat != NULL; compat_data++) {
+		const char *compat[] = { compat_data->compat, NULL };
+		const int match = of_match_compatible(phandle, compat);
+		if (match)
+			return match;
+	}
+	return 0;
+}
+
+/*
  * const struct of_compat_data *of_search_compatible(phandle, compat_data)
  *
  * This routine searches an array of compat_data structures for a

Index: src/sys/dev/ofw/openfirm.h
diff -u src/sys/dev/ofw/openfirm.h:1.35 src/sys/dev/ofw/openfirm.h:1.36
--- src/sys/dev/ofw/openfirm.h:1.35	Fri Jun 30 09:17:05 2017
+++ src/sys/dev/ofw/openfirm.h	Mon Jul  3 00:47:34 2017
@@ -1,4 +1,4 @@
-/*	$NetBSD: openfirm.h,v 1.35 2017/06/30 09:17:05 jmcneill Exp $	*/
+/*	$NetBSD: openfirm.h,v 1.36 2017/07/03 00:47:34 jmcneill Exp $	*/
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -110,6 +110,7 @@ int	openfirmware(void *);
  */
 int	of_compatible(int, const char * const *);
 int	of_match_compatible(int, const char * const *);
+int	of_match_compat_data(int, const struct of_compat_data *);
 const struct of_compat_data *
 	of_search_compatible(int, const struct of_compat_data *);
 int	of_decode_int(const unsigned char *);

Reply via email to