Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Andres Salomon and committed by
Grant Likely
e2f2a93b ed418502

+45 -1
+42 -1
drivers/of/pdt.c
··· 132 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 176 static struct device_node * __init of_pdt_create_node(phandle node, 136 177 struct device_node *parent) 137 178 { ··· 187 146 188 147 kref_init(&dp->kref); 189 148 190 - dp->name = of_pdt_get_one_property(node, "name"); 149 + dp->name = of_pdt_build_name(node); 191 150 dp->type = of_pdt_get_one_property(node, "device_type"); 192 151 dp->phandle = node; 193 152
+3
include/linux/of_pdt.h
··· 29 29 /* phandles are 0 if no child or sibling exists */ 30 30 phandle (*getchild)(phandle parent); 31 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 37 extern void *prom_early_alloc(unsigned long size);