Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ofw Change the meaning of of_compatible return value...



details:   https://anonhg.NetBSD.org/src/rev/25ab52ccbee5
branches:  trunk
changeset: 342207:25ab52ccbee5
user:      jmcneill <jmcneill%NetBSD.org@localhost>
date:      Sat Dec 12 22:22:51 2015 +0000

description:
Change the meaning of of_compatible return values >= 0. Previously, the
function would return the index of the matching compatibility string in
the "strings" parameter on success. None of the callers in tree use this,
so instead change the function to return a reverse index of the matching
compatibility string in the phandle's "compatible" property. The result is
that the function will return a higher number for earlier "compatible"
matches.

Add a new of_match_compatible() that simply returns of_compatible() + 1,
for use in driver match functions.

diffstat:

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

diffs (130 lines):

diff -r f9b376279568 -r 25ab52ccbee5 sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Sat Dec 12 21:57:40 2015 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Sat Dec 12 22:22:51 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_subr.c,v 1.23 2013/10/25 14:32:10 jdc Exp $        */
+/*     $NetBSD: ofw_subr.c,v 1.24 2015/12/12 22:22:51 jmcneill Exp $   */
 
 /*
  * Copyright 1998
@@ -34,7 +34,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.23 2013/10/25 14:32:10 jdc Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.24 2015/12/12 22:22:51 jmcneill Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -79,7 +79,7 @@
  * it matches any of the provided strings.
  *
  * It should be used when determining whether a driver can drive
- * a partcular device.
+ * a particular device.
  *
  * Arguments:
  *     phandle         OFW phandle of device to be checked for
@@ -90,8 +90,8 @@
  *
  * Return Value:
  *     -1 if none of the strings are found in phandle's "compatibility"
- *     property, or the index of the string in "strings" of the first
- *     string found in phandle's "compatibility" property.
+ *     property, or the reverse index of the matching string in the
+ *     phandle's "compatibility" property.
  *
  * Side Effects:
  *     None.
@@ -99,7 +99,8 @@
 int
 of_compatible(int phandle, const char * const *strings)
 {
-       int len, allocated, rv;
+
+       int len, olen, allocated, nstr, cstr, rv;
        char *buf;
        const char *sp, *nsp;
 
@@ -121,11 +122,25 @@
                goto out;
        }
 
+       /* count 'compatible' strings */
        sp = buf;
+       nstr = 0;
+       olen = len;
        while (len && (nsp = memchr(sp, 0, len)) != NULL) {
+               nsp++;                  /* skip over NUL char */
+               len -= (nsp - sp);
+               sp = nsp;
+               nstr++;
+       }
+       len = olen;
+
+       sp = buf;
+       rv = nstr;
+       while (len && (nsp = memchr(sp, 0, len)) != NULL) {
+               rv--;
                /* look for a match among the strings provided */
-               for (rv = 0; strings[rv] != NULL; rv++)
-                       if (strcmp(sp, strings[rv]) == 0)
+               for (cstr = 0; strings[cstr] != NULL; cstr++)
+                       if (strcmp(sp, strings[cstr]) == 0)
                                goto out;
 
                nsp++;                  /* skip over NUL char */
@@ -138,7 +153,36 @@
        if (allocated)
                free(buf, M_TEMP);
        return (rv);
+}
 
+/*
+ * int of_match_compatible(phandle, strings)
+ *
+ * This routine checks an OFW node's "compatible" entry to see if
+ * it matches any of the provided strings.
+ *
+ * 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.
+ *     strings         Array of containing expected "compatibility"
+ *                     property values, presence of any of which
+ *                     indicates compatibility.
+ *
+ * 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_compatible(int phandle, const char * const *strings)
+{
+       return of_compatible(phandle, strings) + 1;
 }
 
 /*
diff -r f9b376279568 -r 25ab52ccbee5 sys/dev/ofw/openfirm.h
--- a/sys/dev/ofw/openfirm.h    Sat Dec 12 21:57:40 2015 +0000
+++ b/sys/dev/ofw/openfirm.h    Sat Dec 12 22:22:51 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: openfirm.h,v 1.30 2013/05/16 18:43:09 christos Exp $   */
+/*     $NetBSD: openfirm.h,v 1.31 2015/12/12 22:22:51 jmcneill Exp $   */
 
 /*
  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
@@ -105,6 +105,7 @@
  * Functions and variables provided by machine-independent code.
  */
 int    of_compatible(int, const char * const *);
+int    of_match_compatible(int, const char * const *);
 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