Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys Change device_compatible_match() and iic_compatible_matc...
details: https://anonhg.NetBSD.org/src/rev/581bd9e275a0
branches: trunk
changeset: 320197:581bd9e275a0
user: thorpej <thorpej%NetBSD.org@localhost>
date: Tue Jun 26 04:32:35 2018 +0000
description:
Change device_compatible_match() and iic_compatible_match() to return
the weighted match value and take an optional compatible-entry pointer,
rather than the other way around.
diffstat:
sys/dev/i2c/axppmic.c | 8 ++++----
sys/dev/i2c/ds1307.c | 7 +++----
sys/dev/i2c/i2c.c | 27 +++++++++++++--------------
sys/dev/i2c/i2cvar.h | 8 ++++----
sys/kern/subr_autoconf.c | 22 +++++++++++-----------
sys/sys/device.h | 9 ++++-----
6 files changed, 39 insertions(+), 42 deletions(-)
diffs (232 lines):
diff -r aa6698a211fa -r 581bd9e275a0 sys/dev/i2c/axppmic.c
--- a/sys/dev/i2c/axppmic.c Tue Jun 26 00:06:08 2018 +0000
+++ b/sys/dev/i2c/axppmic.c Tue Jun 26 04:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $ */
+/* $NetBSD: axppmic.c,v 1.13 2018/06/26 04:32:35 thorpej Exp $ */
/*-
* Copyright (c) 2014-2018 Jared McNeill <jmcneill%invisible.ca@localhost>
@@ -27,7 +27,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.12 2018/06/19 02:08:12 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: axppmic.c,v 1.13 2018/06/26 04:32:35 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -694,7 +694,7 @@
axppmic_attach(device_t parent, device_t self, void *aux)
{
struct axppmic_softc *sc = device_private(self);
- const struct device_compatible_entry *dce;
+ const struct device_compatible_entry *dce = NULL;
const struct axppmic_config *c;
struct axpreg_attach_args aaa;
struct i2c_attach_args *ia = aux;
@@ -702,7 +702,7 @@
uint32_t irq_mask;
void *ih;
- dce = iic_compatible_match(ia, axppmic_compat_data, NULL);
+ (void) iic_compatible_match(ia, axppmic_compat_data, &dce);
KASSERT(dce != NULL);
c = DEVICE_COMPAT_ENTRY_GET_PTR(dce);
diff -r aa6698a211fa -r 581bd9e275a0 sys/dev/i2c/ds1307.c
--- a/sys/dev/i2c/ds1307.c Tue Jun 26 00:06:08 2018 +0000
+++ b/sys/dev/i2c/ds1307.c Tue Jun 26 04:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: ds1307.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $ */
+/* $NetBSD: ds1307.c,v 1.28 2018/06/26 04:32:35 thorpej Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -36,7 +36,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.27 2018/06/18 17:07:07 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: ds1307.c,v 1.28 2018/06/26 04:32:35 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -249,8 +249,7 @@
const struct dsrtc_model *dm = NULL;
const struct device_compatible_entry *dce;
- dce = iic_compatible_match(ia, dsrtc_compat_data, NULL);
- if (dce != NULL)
+ if (iic_compatible_match(ia, dsrtc_compat_data, &dce))
dm = DEVICE_COMPAT_ENTRY_GET_PTR(dce);
return dm;
diff -r aa6698a211fa -r 581bd9e275a0 sys/dev/i2c/i2c.c
--- a/sys/dev/i2c/i2c.c Tue Jun 26 00:06:08 2018 +0000
+++ b/sys/dev/i2c/i2c.c Tue Jun 26 04:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: i2c.c,v 1.64 2018/06/22 15:52:00 martin Exp $ */
+/* $NetBSD: i2c.c,v 1.65 2018/06/26 04:32:35 thorpej Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -40,7 +40,7 @@
#endif
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.64 2018/06/22 15:52:00 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: i2c.c,v 1.65 2018/06/26 04:32:35 thorpej Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -695,22 +695,22 @@
* Match a device's "compatible" property against the list
* of compatible strings provided by the driver.
*/
-const struct device_compatible_entry *
+int
iic_compatible_match(const struct i2c_attach_args *ia,
const struct device_compatible_entry *compats,
- int *match_resultp)
+ const struct device_compatible_entry **matching_entryp)
{
- const struct device_compatible_entry *dce;
- int match_weight;
+ int match_result;
- dce = device_compatible_match(ia->ia_compat, ia->ia_ncompat,
- compats, &match_weight);
- if (dce != NULL && match_resultp != NULL) {
- *match_resultp = MIN(I2C_MATCH_DIRECT_COMPATIBLE + match_weight,
- I2C_MATCH_DIRECT_COMPATIBLE_MAX);
+ match_result = device_compatible_match(ia->ia_compat, ia->ia_ncompat,
+ compats, matching_entryp);
+ if (match_result) {
+ match_result =
+ MIN(I2C_MATCH_DIRECT_COMPATIBLE + match_result - 1,
+ I2C_MATCH_DIRECT_COMPATIBLE_MAX);
}
- return dce;
+ return match_result;
}
/*
@@ -735,8 +735,7 @@
}
if (ia->ia_ncompat > 0 && ia->ia_compat != NULL) {
- if (iic_compatible_match(ia, compats, match_resultp) == NULL)
- *match_resultp = 0;
+ *match_resultp = iic_compatible_match(ia, compats, NULL);
return true;
}
diff -r aa6698a211fa -r 581bd9e275a0 sys/dev/i2c/i2cvar.h
--- a/sys/dev/i2c/i2cvar.h Tue Jun 26 00:06:08 2018 +0000
+++ b/sys/dev/i2c/i2cvar.h Tue Jun 26 04:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: i2cvar.h,v 1.15 2018/06/18 17:07:07 thorpej Exp $ */
+/* $NetBSD: i2cvar.h,v 1.16 2018/06/26 04:32:35 thorpej Exp $ */
/*
* Copyright (c) 2003 Wasabi Systems, Inc.
@@ -164,9 +164,9 @@
/*
* API presented to i2c devices.
*/
-const struct device_compatible_entry *
- iic_compatible_match(const struct i2c_attach_args *,
- const struct device_compatible_entry *, int *);
+int iic_compatible_match(const struct i2c_attach_args *,
+ const struct device_compatible_entry *,
+ const struct device_compatible_entry **);
bool iic_use_direct_match(const struct i2c_attach_args *, const cfdata_t,
const struct device_compatible_entry *, int *);
diff -r aa6698a211fa -r 581bd9e275a0 sys/kern/subr_autoconf.c
--- a/sys/kern/subr_autoconf.c Tue Jun 26 00:06:08 2018 +0000
+++ b/sys/kern/subr_autoconf.c Tue Jun 26 04:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: subr_autoconf.c,v 1.260 2018/06/19 04:10:51 thorpej Exp $ */
+/* $NetBSD: subr_autoconf.c,v 1.261 2018/06/26 04:32:35 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.260 2018/06/19 04:10:51 thorpej Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_autoconf.c,v 1.261 2018/06/26 04:32:35 thorpej Exp $");
#ifdef _KERNEL_OPT
#include "opt_ddb.h"
@@ -2302,20 +2302,20 @@
*
* Match a driver's "compatible" data against a device's
* "compatible" strings. If a match is found, we return
- * the matching device_compatible_entry, along with a
- * matching weight.
+ * a weighted match result, and optionally the matching
+ * entry.
*/
-const struct device_compatible_entry *
+int
device_compatible_match(const char **device_compats, int ndevice_compats,
const struct device_compatible_entry *driver_compats,
- int *match_weightp)
+ const struct device_compatible_entry **matching_entryp)
{
const struct device_compatible_entry *dce = NULL;
int i, match_weight;
if (ndevice_compats == 0 || device_compats == NULL ||
driver_compats == NULL)
- return NULL;
+ return 0;
/*
* We take the first match because we start with the most-specific
@@ -2329,13 +2329,13 @@
if (device_compatible_entry_matches(dce,
device_compats[i])) {
KASSERT(match_weight >= 0);
- if (match_weightp)
- *match_weightp = match_weight;
- return dce;
+ if (matching_entryp)
+ *matching_entryp = dce;
+ return 1 + match_weight;
}
}
}
- return NULL;
+ return 0;
}
/*
diff -r aa6698a211fa -r 581bd9e275a0 sys/sys/device.h
--- a/sys/sys/device.h Tue Jun 26 00:06:08 2018 +0000
+++ b/sys/sys/device.h Tue Jun 26 04:32:35 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: device.h,v 1.153 2018/06/18 15:36:54 thorpej Exp $ */
+/* $NetBSD: device.h,v 1.154 2018/06/26 04:32:35 thorpej Exp $ */
/*
* Copyright (c) 1996, 2000 Christopher G. Demetriou
@@ -552,10 +552,9 @@
device_t device_find_by_xname(const char *);
device_t device_find_by_driver_unit(const char *, int);
-const struct device_compatible_entry *
- device_compatible_match(const char **, int,
- const struct device_compatible_entry *,
- int *);
+int device_compatible_match(const char **, int,
+ const struct device_compatible_entry *,
+ const struct device_compatible_entry **);
bool device_pmf_is_registered(device_t);
Home |
Main Index |
Thread Index |
Old Index