Source-Changes-HG archive

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

[src/trunk]: src/sys/dev/ofw Implement of_match_compat_data() using device_co...



details:   https://anonhg.NetBSD.org/src/rev/402fc17d401e
branches:  trunk
changeset: 980137:402fc17d401e
user:      thorpej <thorpej%NetBSD.org@localhost>
date:      Sun Jan 24 17:44:16 2021 +0000

description:
Implement of_match_compat_data() using device_compatible_match_strlist().
Implement of_search_compatible() using device_compatible_lookup_strlist().

diffstat:

 sys/dev/ofw/ofw_subr.c |  55 +++++++++++++++++++++++++++++++++++++------------
 1 files changed, 41 insertions(+), 14 deletions(-)

diffs (95 lines):

diff -r c1134e1f288a -r 402fc17d401e sys/dev/ofw/ofw_subr.c
--- a/sys/dev/ofw/ofw_subr.c    Sun Jan 24 17:42:36 2021 +0000
+++ b/sys/dev/ofw/ofw_subr.c    Sun Jan 24 17:44:16 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: ofw_subr.c,v 1.45 2021/01/24 16:45:41 thorpej Exp $    */
+/*     $NetBSD: ofw_subr.c,v 1.46 2021/01/24 17:44:16 thorpej Exp $    */
 
 /*
  * Copyright 1998
@@ -34,10 +34,11 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.45 2021/01/24 16:45:41 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ofw_subr.c,v 1.46 2021/01/24 17:44:16 thorpej Exp $");
 
 #include <sys/param.h>
 #include <sys/device.h>
+#include <sys/kmem.h>
 #include <sys/systm.h>
 #include <sys/malloc.h>
 #include <dev/ofw/openfirm.h>
@@ -215,13 +216,25 @@
 of_match_compat_data(int phandle,
     const struct device_compatible_entry *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;
+       char *prop, propbuf[OFW_MAX_STACK_BUF_SIZE];
+       int proplen, match = 0;
+
+       proplen = OF_getproplen(phandle, "compatible");
+       if (proplen <= 0) {
+               return 0;
        }
-       return 0;
+
+       prop = kmem_tmpbuf_alloc(proplen, propbuf, sizeof(propbuf), KM_SLEEP);
+
+       if (OF_getprop(phandle, "compatible", prop, proplen) != proplen) {
+               goto out;
+       }
+
+       match = device_compatible_match_strlist(prop, proplen, compat_data);
+
+ out:
+       kmem_tmpbuf_free(prop, proplen, propbuf);
+       return match;
 }
 
 /*
@@ -241,7 +254,7 @@
  *
  * Return Value:
  *     The first matching compat_data entry in the array. If no matches
- *     are found, the NULL is returned.
+ *     are found, NULL is returned.
  *
  * Side Effects:
  *     None.
@@ -250,12 +263,26 @@
 of_search_compatible(int phandle,
     const struct device_compatible_entry *compat_data)
 {
-       for (; compat_data->compat != NULL; compat_data++) {
-               const char *compat[] = { compat_data->compat, NULL };
-               if (of_match_compatible(phandle, compat))
-                       return compat_data;
+       char *prop, propbuf[OFW_MAX_STACK_BUF_SIZE];
+       const struct device_compatible_entry *match = NULL;
+       int proplen;
+
+       proplen = OF_getproplen(phandle, "compatible");
+       if (proplen <= 0) {
+               return 0;
        }
-       return NULL;
+
+       prop = kmem_tmpbuf_alloc(proplen, propbuf, sizeof(propbuf), KM_SLEEP);
+
+       if (OF_getprop(phandle, "compatible", prop, proplen) != proplen) {
+               goto out;
+       }
+
+       match = device_compatible_lookup_strlist(prop, proplen, compat_data);
+
+ out:
+       kmem_tmpbuf_free(prop, proplen, propbuf);
+       return match;
 }
 
 /*



Home | Main Index | Thread Index | Old Index