]> bbs.cooldavid.org Git - net-next-2.6.git/commitdiff
of/promtree: add package-to-path support to pdt
authorAndres Salomon <dilinger@queued.net>
Mon, 11 Oct 2010 03:52:57 +0000 (21:52 -0600)
committerGrant Likely <grant.likely@secretlab.ca>
Wed, 13 Oct 2010 03:58:08 +0000 (21:58 -0600)
package-to-path is a PROM function which tells us the real (full) name of the
node.  This provides a hook for that in the prom ops struct, and makes use
of it in the pdt code when attempting to determine a node's name.  If the
hook is available, try using it (falling back to looking at the "name"
property if it fails).

Signed-off-by: Andres Salomon <dilinger@queued.net>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
drivers/of/pdt.c
include/linux/of_pdt.h

index 31a4fb8694db08e1675a273a4db8bef2528fca2c..28295d0a50f64b919e4d43e1e8e73307f04a4683 100644 (file)
@@ -132,6 +132,47 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
        return buf;
 }
 
+static char * __init of_pdt_try_pkg2path(phandle node)
+{
+       char *res, *buf = NULL;
+       int len;
+
+       if (!of_pdt_prom_ops->pkg2path)
+               return NULL;
+
+       if (of_pdt_prom_ops->pkg2path(node, buf, 0, &len))
+               return NULL;
+       buf = prom_early_alloc(len + 1);
+       if (of_pdt_prom_ops->pkg2path(node, buf, len, &len)) {
+               pr_err("%s: package-to-path failed\n", __func__);
+               return NULL;
+       }
+
+       res = strrchr(buf, '/');
+       if (!res) {
+               pr_err("%s: couldn't find / in %s\n", __func__, buf);
+               return NULL;
+       }
+       return res+1;
+}
+
+/*
+ * When fetching the node's name, first try using package-to-path; if
+ * that fails (either because the arch hasn't supplied a PROM callback,
+ * or some other random failure), fall back to just looking at the node's
+ * 'name' property.
+ */
+static char * __init of_pdt_build_name(phandle node)
+{
+       char *buf;
+
+       buf = of_pdt_try_pkg2path(node);
+       if (!buf)
+               buf = of_pdt_get_one_property(node, "name");
+
+       return buf;
+}
+
 static struct device_node * __init of_pdt_create_node(phandle node,
                                                    struct device_node *parent)
 {
@@ -146,7 +187,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
 
        kref_init(&dp->kref);
 
-       dp->name = of_pdt_get_one_property(node, "name");
+       dp->name = of_pdt_build_name(node);
        dp->type = of_pdt_get_one_property(node, "device_type");
        dp->phandle = node;
 
index 0f7d0c56348ab779eb12ff8de7201aae55d3f13c..c65a18a0cfdf3f45a3925c652410395eb842da84 100644 (file)
@@ -29,6 +29,9 @@ struct of_pdt_ops {
        /* phandles are 0 if no child or sibling exists */
        phandle (*getchild)(phandle parent);
        phandle (*getsibling)(phandle node);
+
+       /* return 0 on success; fill in 'len' with number of bytes in path */
+       int (*pkg2path)(phandle node, char *buf, const int buflen, int *len);
 };
 
 extern void *prom_early_alloc(unsigned long size);