summaryrefslogtreecommitdiff
path: root/sys/dev
diff options
context:
space:
mode:
authorjmcneill <jmcneill@NetBSD.org>2015-12-12 22:22:51 +0000
committerjmcneill <jmcneill@NetBSD.org>2015-12-12 22:22:51 +0000
commit3496a576e18ac5d4546c9c8f689aedf59e64af5d (patch)
treedd0824ebe234a1210aaa25086cac0322bff647ec /sys/dev
parent64f2b443245e0afad1ac1d32b63de6aa2b5f8566 (diff)
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 (limited to 'sys/dev')
-rw-r--r--sys/dev/ofw/ofw_subr.c60
-rw-r--r--sys/dev/ofw/openfirm.h3
2 files changed, 54 insertions, 9 deletions
diff --git a/sys/dev/ofw/ofw_subr.c b/sys/dev/ofw/ofw_subr.c
index 54174a7ba3a..db9b03da3af 100644
--- a/sys/dev/ofw/ofw_subr.c
+++ b/sys/dev/ofw/ofw_subr.c
@@ -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 @@ of_decode_int(const unsigned char *p)
* 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 @@ of_decode_int(const unsigned char *p)
*
* 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 @@ of_decode_int(const unsigned char *p)
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 @@ of_compatible(int phandle, const char * const *strings)
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 @@ out:
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 --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h
index d5b085727e1..b134b861170 100644
--- a/sys/dev/ofw/openfirm.h
+++ b/sys/dev/ofw/openfirm.h
@@ -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 @@ int openfirmware(void *);
* 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 *);