summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorian <ian@FreeBSD.org>2014-09-02 03:45:01 +0000
committerian <ian@FreeBSD.org>2014-09-02 03:45:01 +0000
commit29ba19b429e334f6eb07025de2ff4a0018e6d583 (patch)
tree422059d043ba36b3216bd878789658a8ab1cdcea
parent944d759ab76deb18c2c4163e3d18d5fd2ff1b5ee (diff)
downloadFreeBSD-src-29ba19b429e334f6eb07025de2ff4a0018e6d583.zip
FreeBSD-src-29ba19b429e334f6eb07025de2ff4a0018e6d583.tar.gz
Add OF_xref_from_device() so that there's no need to have an intermediate
call to ofw_bus_get_node() to lookup info that's already in the xreflist.
-rw-r--r--sys/dev/ofw/openfirm.c16
-rw-r--r--sys/dev/ofw/openfirm.h1
2 files changed, 17 insertions, 0 deletions
diff --git a/sys/dev/ofw/openfirm.c b/sys/dev/ofw/openfirm.c
index ae66cae..0df49c5 100644
--- a/sys/dev/ofw/openfirm.c
+++ b/sys/dev/ofw/openfirm.c
@@ -96,6 +96,7 @@ static boolean_t xref_init_done;
#define FIND_BY_XREF 0
#define FIND_BY_NODE 1
+#define FIND_BY_DEV 1
/*
* xref-phandle-device lookup helper routines.
@@ -152,6 +153,8 @@ xrefinfo_find(phandle_t phandle, int find_by)
return (xi);
else if (find_by == FIND_BY_NODE && phandle == xi->node)
return (xi);
+ else if (find_by == FIND_BY_DEV && phandle == (uintptr_t)xi->dev)
+ return (xi);
}
return (NULL);
}
@@ -584,6 +587,19 @@ OF_device_from_xref(phandle_t xref)
panic("Attempt to find device before xreflist_init");
}
+phandle_t
+OF_xref_from_device(device_t dev)
+{
+ struct xrefinfo *xi;
+
+ if (xref_init_done) {
+ if ((xi = xrefinfo_find((uintptr_t)dev, FIND_BY_DEV)) == NULL)
+ return (0);
+ return (xi->xref);
+ }
+ panic("Attempt to find xref before xreflist_init");
+}
+
int
OF_device_register_xref(phandle_t xref, device_t dev)
{
diff --git a/sys/dev/ofw/openfirm.h b/sys/dev/ofw/openfirm.h
index 37b27f5..d3967a4 100644
--- a/sys/dev/ofw/openfirm.h
+++ b/sys/dev/ofw/openfirm.h
@@ -141,6 +141,7 @@ phandle_t OF_xref_from_node(phandle_t node);
* the device_t associated with an xref handle.
*/
device_t OF_device_from_xref(phandle_t xref);
+phandle_t OF_xref_from_device(device_t dev);
int OF_device_register_xref(phandle_t xref, device_t dev);
/* Device I/O functions */
OpenPOWER on IntegriCloud