Add OF_xref_from_node_strict() which returns -1 if there is no xref handle

for the node.  The default routine returns the untranslated handle, which
is sometimes useful, but sometimes you really need to know there's no
entry in the xref<->node<->device translation table.
This commit is contained in:
ian 2014-09-06 15:11:35 +00:00
parent e54555ca52
commit cd70b067cc
2 changed files with 21 additions and 5 deletions

View File

@ -554,15 +554,15 @@ OF_node_from_xref(phandle_t xref)
return (node);
}
phandle_t
OF_xref_from_node(phandle_t node)
static phandle_t
xref_from_node(phandle_t node, phandle_t notfoundvalue)
{
struct xrefinfo *xi;
phandle_t xref;
if (xref_init_done) {
if ((xi = xrefinfo_find(node, FIND_BY_NODE)) == NULL)
return (node);
return (notfoundvalue);
return (xi->xref);
}
@ -570,10 +570,24 @@ OF_xref_from_node(phandle_t node)
-1 && OF_getencprop(node, "ibm,phandle", &xref,
sizeof(xref)) == -1 && OF_getencprop(node,
"linux,phandle", &xref, sizeof(xref)) == -1)
return (node);
return (notfoundvalue);
return (xref);
}
phandle_t
OF_xref_from_node(phandle_t node)
{
return (xref_from_node(node, node));
}
phandle_t
OF_xref_from_node_strict(phandle_t node)
{
return (xref_from_node(node, -1));
}
device_t
OF_device_from_xref(phandle_t xref)
{

View File

@ -128,10 +128,12 @@ ssize_t OF_package_to_path(phandle_t node, char *buf, size_t len);
* Some OF implementations (IBM, FDT) have a concept of effective phandles
* used for device-tree cross-references. Given one of these, returns the
* real phandle. If one can't be found (or running on OF implementations
* without this property), returns its input.
* without this property), OF_xref_from_node() returns its input, while the
* strict version returns -1.
*/
phandle_t OF_node_from_xref(phandle_t xref);
phandle_t OF_xref_from_node(phandle_t node);
phandle_t OF_xref_from_node_strict(phandle_t node);
/*
* When properties contain references to other nodes using xref handles it is