FreeBSD/sys/dev/ofw/openfirm.c
/*
 * xref-phandle-device lookup helper routines.
 *
 * As soon as we are able to use malloc(), walk the node tree and build a list
 * of info that cross-references node handles, xref handles, and device_t
 * instances.  This list exists primarily to allow association of a device_t
 * with an xref handle, but it is also used to speed up translation between xref
 * and node handles.  Before malloc() is available we have to recursively search
 * the node tree each time we want to translate between a node and xref handle.
 * Afterwards we can do the translations by searching this much shorter list.
 */
xref-phandle-device lookup helper routines.
As soon as we are able to use malloc(), walk the node tree and build a list
of info that cross-references node handles, xref handles, and device_t
instances.  This list exists primarily to allow association of a device_t
with an xref handle, but it is also used to speed up translation between xref
and node handles.  Before malloc() is available we have to recursively search
the node tree each time we want to translate between a node and xref handle.
Afterwards we can do the translations by searching this much shorter list.
xref - phandle - device lookup helper routines . As soon as we are able to use malloc () walk the node tree and build a list of info that cross - references node handles xref handles and device_t instances . This list exists primarily to allow association of a device_t with an xref handle but it is also used to speed up translation between xref and node handles . Before malloc () is available we have to recursively search the node tree each time we want to translate between a node and xref handle . Afterwards we can do the translations by searching this much shorter list .
static void
xrefinfo_create(phandle_t node)
{
	struct xrefinfo * xi;
	phandle_t child, xref;
	for (child = OF_child(node); child != 0; child = OF_peer(child)) {
		xrefinfo_create(child);
		if (OF_getencprop(child, "phandle", &xref, sizeof(xref)) ==
		    -1 && OF_getencprop(child, "ibm,phandle", &xref,
		    sizeof(xref)) == -1 && OF_getencprop(child,
		    "linux,phandle", &xref, sizeof(xref)) == -1)
			continue;
		xi = malloc(sizeof(*xi), M_OFWPROP, M_WAITOK | M_ZERO);
		xi->node = child;
		xi->xref = xref;
		SLIST_INSERT_HEAD(&xreflist, xi, next_entry);
	}
}
static void xrefinfo_create ( phandle_t node ) { struct xrefinfo * xi ; phandle_t child , xref ; for ( child = OF_child ( node ) ; child != 0 ; child = OF_peer ( child ) ) { xrefinfo_create ( child ) ; if ( OF_getencprop ( child , " " , & xref , sizeof ( xref ) ) == -1 && OF_getencprop ( child , " " , & xref , sizeof ( xref ) ) == -1 && OF_getencprop ( child , " " , & xref , sizeof ( xref ) ) == -1 ) continue ; xi = malloc ( sizeof ( * xi ) , M_OFWPROP , M_WAITOK | M_ZERO ) ; xi -> node = child ; xi -> xref = xref ; SLIST_INSERT_HEAD ( & xreflist , xi , next_entry ) ; } }
xref-phandle-device lookup helper routines.
xref - phandle - device lookup helper routines .
/*
	 * Recursively descend from parent, looking for nodes with a property
	 * named either "phandle", "ibm,phandle", or "linux,phandle".  For each
	 * such node found create an entry in the xreflist.
	 */