diff options
author | Andres Salomon <dilinger@queued.net> | 2011-02-24 01:38:22 -0500 |
---|---|---|
committer | Grant Likely <grant.likely@secretlab.ca> | 2011-03-02 15:45:19 -0500 |
commit | a74ea43df1afc68f265c0ac2cb64031d855ae97b (patch) | |
tree | 7e3b00d2493bd19c408df10a55daf111375c9104 /drivers | |
parent | 60cba5a57b8affe98ea9f2bac147be0fb253d5f4 (diff) |
of/promtree: allow DT device matching by fixing 'name' brokenness (v5)
Commit e2f2a93b, "of/promtree: add package-to-path support to pdt"
changed dp->name from using the 'name' property to using
package-to-path. This fixed /proc/device-tree creation by eliminating
conflicts between names (the 'name' property provides names like
'battery', whereas package-to-path provides names like
'/foo/bar/battery@0', which we stripped to 'battery@0'). However, it
also breaks of_device_id table matching.
The fix that we _really_ wanted was to keep dp->name based upon
the name property ('battery'), but based dp->full_name upon
package-to-path ('battery@0'). This patch does just that.
This changes all users (except SPARC) of promtree to use the full
result from package-to-path for full_name, rather than stripping the
directory out. In practice, the strings end up being exactly the
same; this change saves time, code, and memory.
SPARC continues to use the existing build_path_component() code.
v2: combine two patches and revert of_pdt_node_name to original version
v3: use dp->phandle instead of passing around node
v4: warn/bail out for non-sparc archs if pkg2path is not set
v5: split of_pdt_build_full_name into sparc & non-sparc versions
v6: Pass NULL to pkg2path before buf gets assigned.
Drop check for pkg2path hook on each and every node.
v7: Don't BUG() when unable to get the full_path; create a
known-unique name instead.
Signed-off-by: Andres Salomon <dilinger@queued.net>
Signed-off-by: Grant Likely <grant.likely@secretlab.ca>
Diffstat (limited to 'drivers')
-rw-r--r-- | drivers/of/pdt.c | 112 |
1 files changed, 42 insertions, 70 deletions
diff --git a/drivers/of/pdt.c b/drivers/of/pdt.c index 28295d0a50f..4d87b5dc928 100644 --- a/drivers/of/pdt.c +++ b/drivers/of/pdt.c | |||
@@ -36,19 +36,55 @@ unsigned int of_pdt_unique_id __initdata; | |||
36 | (p)->unique_id = of_pdt_unique_id++; \ | 36 | (p)->unique_id = of_pdt_unique_id++; \ |
37 | } while (0) | 37 | } while (0) |
38 | 38 | ||
39 | static inline const char *of_pdt_node_name(struct device_node *dp) | 39 | static char * __init of_pdt_build_full_name(struct device_node *dp) |
40 | { | 40 | { |
41 | return dp->path_component_name; | 41 | int len, ourlen, plen; |
42 | char *n; | ||
43 | |||
44 | dp->path_component_name = build_path_component(dp); | ||
45 | |||
46 | plen = strlen(dp->parent->full_name); | ||
47 | ourlen = strlen(dp->path_component_name); | ||
48 | len = ourlen + plen + 2; | ||
49 | |||
50 | n = prom_early_alloc(len); | ||
51 | strcpy(n, dp->parent->full_name); | ||
52 | if (!of_node_is_root(dp->parent)) { | ||
53 | strcpy(n + plen, "/"); | ||
54 | plen++; | ||
55 | } | ||
56 | strcpy(n + plen, dp->path_component_name); | ||
57 | |||
58 | return n; | ||
42 | } | 59 | } |
43 | 60 | ||
44 | #else | 61 | #else /* CONFIG_SPARC */ |
45 | 62 | ||
46 | static inline void of_pdt_incr_unique_id(void *p) { } | 63 | static inline void of_pdt_incr_unique_id(void *p) { } |
47 | static inline void irq_trans_init(struct device_node *dp) { } | 64 | static inline void irq_trans_init(struct device_node *dp) { } |
48 | 65 | ||
49 | static inline const char *of_pdt_node_name(struct device_node *dp) | 66 | static char * __init of_pdt_build_full_name(struct device_node *dp) |
50 | { | 67 | { |
51 | return dp->name; | 68 | static int failsafe_id = 0; /* for generating unique names on failure */ |
69 | char *buf; | ||
70 | int len; | ||
71 | |||
72 | if (of_pdt_prom_ops->pkg2path(dp->phandle, NULL, 0, &len)) | ||
73 | goto failsafe; | ||
74 | |||
75 | buf = prom_early_alloc(len + 1); | ||
76 | if (of_pdt_prom_ops->pkg2path(dp->phandle, buf, len, &len)) | ||
77 | goto failsafe; | ||
78 | return buf; | ||
79 | |||
80 | failsafe: | ||
81 | buf = prom_early_alloc(strlen(dp->parent->full_name) + | ||
82 | strlen(dp->name) + 16); | ||
83 | sprintf(buf, "%s/%s@unknown%i", | ||
84 | of_node_is_root(dp->parent) ? "" : dp->parent->full_name, | ||
85 | dp->name, failsafe_id++); | ||
86 | pr_err("%s: pkg2path failed; assigning %s\n", __func__, buf); | ||
87 | return buf; | ||
52 | } | 88 | } |
53 | 89 | ||
54 | #endif /* !CONFIG_SPARC */ | 90 | #endif /* !CONFIG_SPARC */ |
@@ -132,47 +168,6 @@ static char * __init of_pdt_get_one_property(phandle node, const char *name) | |||
132 | return buf; | 168 | return buf; |
133 | } | 169 | } |
134 | 170 | ||
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 | |||
176 | static struct device_node * __init of_pdt_create_node(phandle node, | 171 | static struct device_node * __init of_pdt_create_node(phandle node, |
177 | struct device_node *parent) | 172 | struct device_node *parent) |
178 | { | 173 | { |
@@ -187,7 +182,7 @@ static struct device_node * __init of_pdt_create_node(phandle node, | |||
187 | 182 | ||
188 | kref_init(&dp->kref); | 183 | kref_init(&dp->kref); |
189 | 184 | ||
190 | dp->name = of_pdt_build_name(node); | 185 | dp->name = of_pdt_get_one_property(node, "name"); |
191 | dp->type = of_pdt_get_one_property(node, "device_type"); | 186 | dp->type = of_pdt_get_one_property(node, "device_type"); |
192 | dp->phandle = node; | 187 | dp->phandle = node; |
193 | 188 | ||
@@ -198,26 +193,6 @@ static struct device_node * __init of_pdt_create_node(phandle node, | |||
198 | return dp; | 193 | return dp; |
199 | } | 194 | } |
200 | 195 | ||
201 | static char * __init of_pdt_build_full_name(struct device_node *dp) | ||
202 | { | ||
203 | int len, ourlen, plen; | ||
204 | char *n; | ||
205 | |||
206 | plen = strlen(dp->parent->full_name); | ||
207 | ourlen = strlen(of_pdt_node_name(dp)); | ||
208 | len = ourlen + plen + 2; | ||
209 | |||
210 | n = prom_early_alloc(len); | ||
211 | strcpy(n, dp->parent->full_name); | ||
212 | if (!of_node_is_root(dp->parent)) { | ||
213 | strcpy(n + plen, "/"); | ||
214 | plen++; | ||
215 | } | ||
216 | strcpy(n + plen, of_pdt_node_name(dp)); | ||
217 | |||
218 | return n; | ||
219 | } | ||
220 | |||
221 | static struct device_node * __init of_pdt_build_tree(struct device_node *parent, | 196 | static struct device_node * __init of_pdt_build_tree(struct device_node *parent, |
222 | phandle node, | 197 | phandle node, |
223 | struct device_node ***nextp) | 198 | struct device_node ***nextp) |
@@ -240,9 +215,6 @@ static struct device_node * __init of_pdt_build_tree(struct device_node *parent, | |||
240 | *(*nextp) = dp; | 215 | *(*nextp) = dp; |
241 | *nextp = &dp->allnext; | 216 | *nextp = &dp->allnext; |
242 | 217 | ||
243 | #if defined(CONFIG_SPARC) | ||
244 | dp->path_component_name = build_path_component(dp); | ||
245 | #endif | ||
246 | dp->full_name = of_pdt_build_full_name(dp); | 218 | dp->full_name = of_pdt_build_full_name(dp); |
247 | 219 | ||
248 | dp->child = of_pdt_build_tree(dp, | 220 | dp->child = of_pdt_build_tree(dp, |