summaryrefslogtreecommitdiffstats
path: root/sys/dev
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2013-12-13 17:23:47 +0000
committerian <ian@FreeBSD.org>2013-12-13 17:23:47 +0000
commit366fb50b48cf6f8c18ba9d1c8eb56dd89c5c917e (patch)
treeb88b6cad1a720ae8c986b1dabd225b52cc9ee6bc /sys/dev
parent8f39a8efa7e77b93e2c57c61369be20c2b401181 (diff)
downloadFreeBSD-src-366fb50b48cf6f8c18ba9d1c8eb56dd89c5c917e.zip
FreeBSD-src-366fb50b48cf6f8c18ba9d1c8eb56dd89c5c917e.tar.gz
MFC r257130:
Add a helper routine to search for a compat string in a table that associates compat strings with arbitrary values that mean something to the driver. This is handy for drivers that support several variations of similar hardware and need to know which one matched.
Diffstat (limited to 'sys/dev')
-rw-r--r--sys/dev/ofw/ofw_bus_subr.c15
-rw-r--r--sys/dev/ofw/ofw_bus_subr.h15
2 files changed, 30 insertions, 0 deletions
diff --git a/sys/dev/ofw/ofw_bus_subr.c b/sys/dev/ofw/ofw_bus_subr.c
index 9b9dee4..86426ca 100644
--- a/sys/dev/ofw/ofw_bus_subr.c
+++ b/sys/dev/ofw/ofw_bus_subr.c
@@ -197,6 +197,21 @@ ofw_bus_is_compatible_strict(device_t dev, const char *compatible)
return (0);
}
+const struct ofw_compat_data *
+ofw_bus_search_compatible(device_t dev, const struct ofw_compat_data *compat)
+{
+
+ if (compat == NULL)
+ return NULL;
+
+ for (; compat->ocd_str != NULL; ++compat) {
+ if (ofw_bus_is_compatible(dev, compat->ocd_str))
+ break;
+ }
+
+ return (compat);
+}
+
int
ofw_bus_has_prop(device_t dev, const char *propname)
{
diff --git a/sys/dev/ofw/ofw_bus_subr.h b/sys/dev/ofw/ofw_bus_subr.h
index b777f77..184ab07 100644
--- a/sys/dev/ofw/ofw_bus_subr.h
+++ b/sys/dev/ofw/ofw_bus_subr.h
@@ -47,6 +47,11 @@ struct ofw_bus_iinfo {
pcell_t opi_addrc;
};
+struct ofw_compat_data {
+ const char *ocd_str;
+ uintptr_t ocd_data;
+};
+
/* Generic implementation of ofw_bus_if.m methods and helper routines */
int ofw_bus_gen_setup_devinfo(struct ofw_bus_devinfo *, phandle_t);
void ofw_bus_gen_destroy_devinfo(struct ofw_bus_devinfo *);
@@ -74,6 +79,16 @@ void ofw_bus_find_iparent(phandle_t);
int ofw_bus_is_compatible(device_t, const char *);
int ofw_bus_is_compatible_strict(device_t, const char *);
+/*
+ * Helper routine to search a list of compat properties. The table is
+ * terminated by an entry with a NULL compat-string pointer; a pointer to that
+ * table entry is returned if none of the compat strings match for the device,
+ * giving you control over the not-found value. Will not return NULL unless the
+ * provided table pointer is NULL.
+ */
+const struct ofw_compat_data *
+ ofw_bus_search_compatible(device_t, const struct ofw_compat_data *);
+
/* Helper routine for checking existence of a prop */
int ofw_bus_has_prop(device_t, const char *);
OpenPOWER on IntegriCloud