diff options
author | Andres Salomon <dilinger@queued.net> | 2010-10-10 23:52:57 -0400 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2010-10-12 23:58:08 -0400 |
commit | e2f2a93b6384cfe0face0be595bfbda1475d864b (patch) | |
tree | f379fda9976cba42f3fccb0bcbac71312db869d3 | |
parent | ed41850298f7a55519de0b8573e217ed8a45c199 (diff) |
of/promtree: add package-to-path support to pdt
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>
-rw-r--r-- | drivers/of/pdt.c | 43 | ||||
-rw-r--r-- | include/linux/of_pdt.h | 3 |
2 files changed, 45 insertions, 1 deletions
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c index 31a4fb8694db..28295d0a50f6 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c | |||
@@ -132,6 +132,47 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name) | |||
132 | return buf; | 132 | return buf; |
133 | } | 133 | } |
134 | 134 | ||
135 | static char * __init of_pdt_try_pkg2path(phandle node) | ||
136 | { | ||
137 | char *res, *buf = NULL; | ||
138 | int len; | ||
139 | |||
140 | if (!of_pdt_prom_ops->pkg2path) | ||
141 | return NULL; | ||
142 | |||
143 | if (of_pdt_prom_ops->pkg2path(node, buf, 0, &len)) | ||
144 | return NULL; | ||
145 | buf = prom_early_alloc(len + 1); | ||
146 | if (of_pdt_prom_ops->pkg2path(node, buf, len, &len)) { | ||
147 | pr_err("%s: package-to-path failed\n", __func__); | ||
148 | return NULL; | ||
149 | } | ||
150 | |||
151 | res = strrchr(buf, '/'); | ||
152 | if (!res) { | ||
153 | pr_err("%s: couldn't find / in %s\n", __func__, buf); | ||
154 | return NULL; | ||
155 | } | ||
156 | return res+1; | ||
157 | } | ||
158 | |||
159 | /* | ||
160 | * When fetching the node's name, first try using package-to-path; if | ||
161 | * that fails (either because the arch hasn't supplied a PROM callback, | ||
162 | * or some other random failure), fall back to just looking at the node's | ||
163 | * 'name' property. | ||
164 | */ | ||
165 | static char * __init of_pdt_build_name(phandle node) | ||
166 | { | ||
167 | char *buf; | ||
168 | |||
169 | buf = of_pdt_try_pkg2path(node); | ||
170 | if (!buf) | ||
171 | buf = of_pdt_get_one_property(node, "name"); | ||
172 | |||
173 | return buf; | ||
174 | } | ||
175 | |||
135 | static struct device_node * __init of_pdt_create_node(phandle node, | 176 | static struct device_node * __init of_pdt_create_node(phandle node, |
136 | struct device_node *parent) | 177 | struct device_node *parent) |
137 | { | 178 | { |
@@ -146,7 +187,7 @@ static struct device_node * __init of_pdt_create_node(phandle node, | |||
146 | 187 | ||
147 | kref_init(&dp->kref); | 188 | kref_init(&dp->kref); |
148 | 189 | ||
149 | dp->name = of_pdt_get_one_property(node, "name"); | 190 | dp->name = of_pdt_build_name(node); |
150 | dp->type = of_pdt_get_one_property(node, "device_type"); | 191 | dp->type = of_pdt_get_one_property(node, "device_type"); |
151 | dp->phandle = node; | 192 | dp->phandle = node; |
152 | 193 | ||
diff --git a/include/linux/of_pdt.h b/include/linux/of_pdt.h index 0f7d0c56348a..c65a18a0cfdf 100644 --- a/include/linux/of_pdt.h +++ b/include/linux/of_pdt.h | |||
@@ -29,6 +29,9 @@ struct of_pdt_ops { | |||
29 | /* phandles are 0 if no child or sibling exists */ | 29 | /* phandles are 0 if no child or sibling exists */ |
30 | phandle (*getchild)(phandle parent); | 30 | phandle (*getchild)(phandle parent); |
31 | phandle (*getsibling)(phandle node); | 31 | phandle (*getsibling)(phandle node); |
32 | |||
33 | /* return 0 on success; fill in 'len' with number of bytes in path */ | ||
34 | int (*pkg2path)(phandle node, char *buf, const int buflen, int *len); | ||
32 | }; | 35 | }; |
33 | 36 | ||
34 | extern void *prom_early_alloc(unsigned long size); | 37 | extern void *prom_early_alloc(unsigned long size); |