Skip to content

Commit e2f2a93

Browse files
dilingerglikely
authored andcommitted
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>
1 parent ed41850 commit e2f2a93

2 files changed

Lines changed: 45 additions & 1 deletion

File tree

‎drivers/of/pdt.c‎

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,47 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name)
132132
return buf;
133133
}
134134

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+
135176
static struct device_node * __init of_pdt_create_node(phandle node,
136177
struct device_node *parent)
137178
{
@@ -146,7 +187,7 @@ static struct device_node * __init of_pdt_create_node(phandle node,
146187

147188
kref_init(&dp->kref);
148189

149-
dp->name = of_pdt_get_one_property(node, "name");
190+
dp->name = of_pdt_build_name(node);
150191
dp->type = of_pdt_get_one_property(node, "device_type");
151192
dp->phandle = node;
152193

‎include/linux/of_pdt.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ struct of_pdt_ops {
2929
/* phandles are 0 if no child or sibling exists */
3030
phandle (*getchild)(phandle parent);
3131
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);
3235
};
3336

3437
extern void *prom_early_alloc(unsigned long size);

0 commit comments

Comments
 (0)