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.
This commit is contained in:
thorpej 2018-06-26 04:32:35 +00:00
parent 53b1355eec
commit 408f5aa571
6 changed files with 39 additions and 42 deletions

View File

@ -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>
@ -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 @@ static void
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 @@ axppmic_attach(device_t parent, device_t self, void *aux)
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);

View File

@ -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 @@ dsrtc_model_by_compat(const struct i2c_attach_args *ia)
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;

View File

@ -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 @@ iic_fill_compat(struct i2c_attach_args *ia, const char *compat, size_t len,
* 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 @@ iic_use_direct_match(const struct i2c_attach_args *ia, const cfdata_t cf,
}
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;
}

View File

@ -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 @@ int iicbus_print(void *, const char *);
/*
* 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 *);

View File

@ -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 @@ device_compatible_entry_matches(const struct device_compatible_entry *dce,
*
* 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 @@ device_compatible_match(const char **device_compats, int ndevice_compats,
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;
}
/*

View File

@ -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 @@ bool device_is_a(device_t, const char *);
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);