Module Name: src
Committed By: thorpej
Date: Wed Jan 27 04:54:08 UTC 2021
Modified Files:
src/sys/kern: subr_autoconf.c
src/sys/sys: device.h
Log Message:
Add device_compatible_match_id() and device_compatible_lookup_id(), which
are like device_compatible_match() and device_compatible_lookup(), but
take a single scalar value as an ID.
Add a "uintptr_t id" field to device_compatible_entry, in an anonymous
union with the existing "const char *compat" field.
To generate a diff of this commit:
cvs rdiff -u -r1.276 -r1.277 src/sys/kern/subr_autoconf.c
cvs rdiff -u -r1.163 -r1.164 src/sys/sys/device.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/kern/subr_autoconf.c
diff -u src/sys/kern/subr_autoconf.c:1.276 src/sys/kern/subr_autoconf.c:1.277
--- src/sys/kern/subr_autoconf.c:1.276 Sun Jan 24 17:42:36 2021
+++ src/sys/kern/subr_autoconf.c Wed Jan 27 04:54:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.276 2021/01/24 17:42:36 thorpej Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.277 2021/01/27 04:54:08 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -77,7 +77,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.276 2021/01/24 17:42:36 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.277 2021/01/27 04:54:08 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -2345,7 +2345,7 @@ strarray_match_internal(const char ** co
unsigned int i;
if (strings == NULL || nstrings == 0) {
- return 0;
+ return false;
}
for (i = 0; i < nstrings; i++) {
@@ -2499,6 +2499,43 @@ device_compatible_pmatch_strlist(
device_compatsize, driver_compats, NULL, strlist_pmatch);
}
+static int
+device_compatible_match_id_internal(
+ uintptr_t const id, uintptr_t const mask, uintptr_t const sentinel_id,
+ const struct device_compatible_entry *driver_compats,
+ const struct device_compatible_entry **matching_entryp)
+{
+ const struct device_compatible_entry *dce = NULL;
+
+ if (mask == 0)
+ return 0;
+
+ for (dce = driver_compats; dce->id != sentinel_id; dce++) {
+ if ((id & mask) == dce->id) {
+ if (matching_entryp != NULL) {
+ *matching_entryp = dce;
+ }
+ return 1;
+ }
+ }
+ return 0;
+}
+
+/*
+ * device_compatible_match_id:
+ *
+ * Like device_compatible_match(), but takes a single
+ * unsigned integer device ID.
+ */
+int
+device_compatible_match_id(
+ uintptr_t const id, uintptr_t const sentinel_id,
+ const struct device_compatible_entry *driver_compats)
+{
+ return device_compatible_match_id_internal(id, (uintptr_t)-1,
+ sentinel_id, driver_compats, NULL);
+}
+
/*
* device_compatible_lookup:
*
@@ -2580,6 +2617,26 @@ device_compatible_plookup_strlist(
}
/*
+ * device_compatible_lookup_id:
+ *
+ * Like device_compatible_lookup(), but takes a single
+ * unsigned integer device ID.
+ */
+const struct device_compatible_entry *
+device_compatible_lookup_id(
+ uintptr_t const id, uintptr_t const sentinel_id,
+ const struct device_compatible_entry *driver_compats)
+{
+ const struct device_compatible_entry *dce;
+
+ if (device_compatible_match_id_internal(id, (uintptr_t)-1,
+ sentinel_id, driver_compats, &dce)) {
+ return dce;
+ }
+ return NULL;
+}
+
+/*
* Power management related functions.
*/
Index: src/sys/sys/device.h
diff -u src/sys/sys/device.h:1.163 src/sys/sys/device.h:1.164
--- src/sys/sys/device.h:1.163 Wed Jan 27 01:00:05 2021
+++ src/sys/sys/device.h Wed Jan 27 04:54:08 2021
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.163 2021/01/27 01:00:05 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.164 2021/01/27 04:54:08 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -124,7 +124,10 @@ typedef struct cfattach *cfattach_t;
#if defined(_KERNEL) || defined(_KMEMUSER)
struct device_compatible_entry {
- const char *compat;
+ union {
+ const char *compat;
+ uintptr_t id;
+ };
union {
const void *data;
uintptr_t value;
@@ -567,6 +570,12 @@ const struct device_compatible_entry *
device_compatible_plookup_strlist(const char *, size_t,
const struct device_compatible_entry *);
+int device_compatible_match_id(uintptr_t const, uintptr_t const,
+ const struct device_compatible_entry *);
+const struct device_compatible_entry *
+ device_compatible_lookup_id(uintptr_t const, uintptr_t const,
+ const struct device_compatible_entry *);
+
bool device_pmf_is_registered(device_t);
bool device_pmf_is_registered(device_t);