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_search_compatible, which searches an arra...



details:   https://anonhg.NetBSD.org/src/rev/cca9f2207cea
branches:  trunk
changeset: 825117:cca9f2207cea
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Fri Jun 30 09:17:05 2017 +0000

description:
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.

diffstat:

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

diffs (86 lines):

diff -r 1b2cede90d78 -r cca9f2207cea sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Fri Jun 30 09:11:22 2017 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Fri Jun 30 09:17:05 2017 +0000
@@ -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 @@
 }
 
 /*
+ * 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
diff -r 1b2cede90d78 -r cca9f2207cea sys/dev/ofw/openfirm.h
--- a/sys/dev/ofw/openfirm.h    Fri Jun 30 09:11:22 2017 +0000
+++ b/sys/dev/ofw/openfirm.h    Fri Jun 30 09:17:05 2017 +0000
@@ -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 @@
        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    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 *);



Home | Main Index | Thread Index | Old Index