Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Add device_compatible_match_id() and device_compatible_l...
details: https://anonhg.NetBSD.org/src/rev/39a5f2c18ef9
branches: trunk
changeset: 958984:39a5f2c18ef9
user: thorpej <thorpej%NetBSD.org@localhost>
date: Wed Jan 27 04:54:08 2021 +0000
description:
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.
diffstat:
sys/kern/subr_autoconf.c | 63 +++++++++++++++++++++++++++++++++++++++++++++--
sys/sys/device.h | 13 ++++++++-
2 files changed, 71 insertions(+), 5 deletions(-)
diffs (132 lines):
diff -r 232baca798b7 -r 39a5f2c18ef9 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c Wed Jan 27 04:35:15 2021 +0000
+++ b/sys/kern/subr_autoconf.c Wed Jan 27 04:54:08 2021 +0000
@@ -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 @@
unsigned int i;
if (strings == NULL || nstrings == 0) {
- return 0;
+ return false;
}
for (i = 0; i < nstrings; i++) {
@@ -2499,6 +2499,43 @@
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_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.
*/
diff -r 232baca798b7 -r 39a5f2c18ef9 sys/sys/device.h
--- a/sys/sys/device.h Wed Jan 27 04:35:15 2021 +0000
+++ b/sys/sys/device.h Wed Jan 27 04:54:08 2021 +0000
@@ -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 @@
#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 @@
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);
Home |
Main Index |
Thread Index |
Old Index