Page MenuHomeFreeBSD

D2871.diff
No OneTemporary

D2871.diff

Index: head/sys/dev/ofw/ofw_bus_subr.h
===================================================================
--- head/sys/dev/ofw/ofw_bus_subr.h
+++ head/sys/dev/ofw/ofw_bus_subr.h
@@ -107,4 +107,7 @@
/* Helper to search for a child with a given name */
phandle_t ofw_bus_find_child(phandle_t, const char *);
+/* Helper routine to find a device_t child matchig a given phandle_t */
+device_t ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node);
+
#endif /* !_DEV_OFW_OFW_BUS_SUBR_H_ */
Index: head/sys/dev/ofw/ofw_bus_subr.c
===================================================================
--- head/sys/dev/ofw/ofw_bus_subr.c
+++ head/sys/dev/ofw/ofw_bus_subr.c
@@ -551,3 +551,44 @@
}
return (0);
}
+
+/**
+ * @brief Return child of bus whose phandle is node
+ *
+ * A direct child of @p will be returned if it its phandle in the
+ * OFW tree is @p node. Otherwise, NULL is returned.
+ *
+ * @param bus The bus to examine
+ * @param node The phandle_t to look for.
+ */
+device_t
+ofw_bus_find_child_device_by_phandle(device_t bus, phandle_t node)
+{
+ device_t *children, retval, child;
+ int nkid, i;
+
+ /*
+ * Nothing can match the flag value for no node.
+ */
+ if (node == -1)
+ return (NULL);
+
+ /*
+ * Search the children for a match. We microoptimize
+ * a bit by not using ofw_bus_get since we already know
+ * the parent. We do not recurse.
+ */
+ if (device_get_children(bus, &children, &nkid) != 0)
+ return (NULL);
+ retval = NULL;
+ for (i = 0; i < nkid; i++) {
+ child = children[i];
+ if (OFW_BUS_GET_NODE(bus, child) == node) {
+ retval = child;
+ break;
+ }
+ }
+ free(children, M_TEMP);
+
+ return (retval);
+}

File Metadata

Mime Type
text/plain
Expires
Mon, Feb 3, 6:10 PM (21 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16440392
Default Alt Text
D2871.diff (1 KB)

Event Timeline