Module Name: src
Committed By: jmcneill
Date: Sat Dec 12 22:22:51 UTC 2015
Modified Files:
src/sys/dev/ofw: ofw_subr.c openfirm.h
Log Message:
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.
To generate a diff of this commit:
cvs rdiff -u -r1.23 -r1.24 src/sys/dev/ofw/ofw_subr.c
cvs rdiff -u -r1.30 -r1.31 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.23 src/sys/dev/ofw/ofw_subr.c:1.24
--- src/sys/dev/ofw/ofw_subr.c:1.23 Fri Oct 25 14:32:10 2013
+++ src/sys/dev/ofw/ofw_subr.c Sat Dec 12 22:22:51 2015
@@ -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 *
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;
}
/*
Index: src/sys/dev/ofw/openfirm.h
diff -u src/sys/dev/ofw/openfirm.h:1.30 src/sys/dev/ofw/openfirm.h:1.31
--- src/sys/dev/ofw/openfirm.h:1.30 Thu May 16 18:43:09 2013
+++ src/sys/dev/ofw/openfirm.h Sat Dec 12 22:22:51 2015
@@ -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 *);