Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 2 Sep 2014 03:45:01 +0000 (UTC)
From:      Ian Lepore <ian@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r270958 - head/sys/dev/ofw
Message-ID:  <201409020345.s823j1HW059013@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ian
Date: Tue Sep  2 03:45:01 2014
New Revision: 270958
URL: http://svnweb.freebsd.org/changeset/base/270958

Log:
  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.

Modified:
  head/sys/dev/ofw/openfirm.c
  head/sys/dev/ofw/openfirm.h

Modified: head/sys/dev/ofw/openfirm.c
==============================================================================
--- head/sys/dev/ofw/openfirm.c	Tue Sep  2 03:23:05 2014	(r270957)
+++ head/sys/dev/ofw/openfirm.c	Tue Sep  2 03:45:01 2014	(r270958)
@@ -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 fin
 			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)
 {

Modified: head/sys/dev/ofw/openfirm.h
==============================================================================
--- head/sys/dev/ofw/openfirm.h	Tue Sep  2 03:23:05 2014	(r270957)
+++ head/sys/dev/ofw/openfirm.h	Tue Sep  2 03:45:01 2014	(r270958)
@@ -141,6 +141,7 @@ phandle_t	OF_xref_from_node(phandle_t no
  * 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 */



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201409020345.s823j1HW059013>