Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/dev/ofw Add of_match_compat_data.



details:   https://anonhg.NetBSD.org/src/rev/9112d333109c
branches:  trunk
changeset: 825190:9112d333109c
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Mon Jul 03 00:47:34 2017 +0000

description:
Add of_match_compat_data.

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

diffstat:

 sys/dev/ofw/ofw_subr.c |  41 +++++++++++++++++++++++++++++++++++++++--
 sys/dev/ofw/openfirm.h |   3 ++-
 2 files changed, 41 insertions(+), 3 deletions(-)

diffs (79 lines):

diff -r 439458a89508 -r 9112d333109c sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Sun Jul 02 22:41:30 2017 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Mon Jul 03 00:47:34 2017 +0000
@@ -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 @@
 }
 
 /*
+ * 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
diff -r 439458a89508 -r 9112d333109c sys/dev/ofw/openfirm.h
--- a/sys/dev/ofw/openfirm.h    Sun Jul 02 22:41:30 2017 +0000
+++ b/sys/dev/ofw/openfirm.h    Mon Jul 03 00:47:34 2017 +0000
@@ -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    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 *);



Home | Main Index | Thread Index | Old Index