diff options
author | Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com> | 2013-08-15 09:01:40 -0400 |
---|---|---|
committer | Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com> | 2013-08-21 05:24:44 -0400 |
commit | 183912d352a242a276a7877852f107459a13aff9 (patch) | |
tree | c9f10475a57b92ed1dc7f6c778e8953839955f36 /drivers/of | |
parent | 819d596568d82ffb85b0b5989a1567810fe66098 (diff) |
of: move of_get_cpu_node implementation to DT core library
This patch moves the generalized implementation of of_get_cpu_node from
PowerPC to DT core library, thereby adding support for retrieving cpu
node for a given logical cpu index on any architecture.
The CPU subsystem can now use this function to assign of_node in the
cpu device while registering CPUs.
It is recommended to use these helper function only in pre-SMP/early
initialisation stages to retrieve CPU device node pointers in logical
ordering. Once the cpu devices are registered, it can be retrieved easily
from cpu device of_node which avoids unnecessary parsing and matching.
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Grant Likely <grant.likely@linaro.org>
Acked-by: Rob Herring <rob.herring@calxeda.com>
Signed-off-by: Sudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com>
Diffstat (limited to 'drivers/of')
-rw-r--r-- | drivers/of/base.c | 95 |
1 files changed, 95 insertions, 0 deletions
diff --git a/drivers/of/base.c b/drivers/of/base.c index 5c5427918eb2..605afa9fbe5e 100644 --- a/drivers/of/base.c +++ b/drivers/of/base.c | |||
@@ -18,6 +18,7 @@ | |||
18 | * 2 of the License, or (at your option) any later version. | 18 | * 2 of the License, or (at your option) any later version. |
19 | */ | 19 | */ |
20 | #include <linux/ctype.h> | 20 | #include <linux/ctype.h> |
21 | #include <linux/cpu.h> | ||
21 | #include <linux/module.h> | 22 | #include <linux/module.h> |
22 | #include <linux/of.h> | 23 | #include <linux/of.h> |
23 | #include <linux/spinlock.h> | 24 | #include <linux/spinlock.h> |
@@ -230,6 +231,100 @@ const void *of_get_property(const struct device_node *np, const char *name, | |||
230 | } | 231 | } |
231 | EXPORT_SYMBOL(of_get_property); | 232 | EXPORT_SYMBOL(of_get_property); |
232 | 233 | ||
234 | /* | ||
235 | * arch_match_cpu_phys_id - Match the given logical CPU and physical id | ||
236 | * | ||
237 | * @cpu: logical cpu index of a core/thread | ||
238 | * @phys_id: physical identifier of a core/thread | ||
239 | * | ||
240 | * CPU logical to physical index mapping is architecture specific. | ||
241 | * However this __weak function provides a default match of physical | ||
242 | * id to logical cpu index. phys_id provided here is usually values read | ||
243 | * from the device tree which must match the hardware internal registers. | ||
244 | * | ||
245 | * Returns true if the physical identifier and the logical cpu index | ||
246 | * correspond to the same core/thread, false otherwise. | ||
247 | */ | ||
248 | bool __weak arch_match_cpu_phys_id(int cpu, u64 phys_id) | ||
249 | { | ||
250 | return (u32)phys_id == cpu; | ||
251 | } | ||
252 | |||
253 | /** | ||
254 | * Checks if the given "prop_name" property holds the physical id of the | ||
255 | * core/thread corresponding to the logical cpu 'cpu'. If 'thread' is not | ||
256 | * NULL, local thread number within the core is returned in it. | ||
257 | */ | ||
258 | static bool __of_find_n_match_cpu_property(struct device_node *cpun, | ||
259 | const char *prop_name, int cpu, unsigned int *thread) | ||
260 | { | ||
261 | const __be32 *cell; | ||
262 | int ac, prop_len, tid; | ||
263 | u64 hwid; | ||
264 | |||
265 | ac = of_n_addr_cells(cpun); | ||
266 | cell = of_get_property(cpun, prop_name, &prop_len); | ||
267 | if (!cell) | ||
268 | return false; | ||
269 | prop_len /= sizeof(*cell); | ||
270 | for (tid = 0; tid < prop_len; tid++) { | ||
271 | hwid = of_read_number(cell, ac); | ||
272 | if (arch_match_cpu_phys_id(cpu, hwid)) { | ||
273 | if (thread) | ||
274 | *thread = tid; | ||
275 | return true; | ||
276 | } | ||
277 | cell += ac; | ||
278 | } | ||
279 | return false; | ||
280 | } | ||
281 | |||
282 | /** | ||
283 | * of_get_cpu_node - Get device node associated with the given logical CPU | ||
284 | * | ||
285 | * @cpu: CPU number(logical index) for which device node is required | ||
286 | * @thread: if not NULL, local thread number within the physical core is | ||
287 | * returned | ||
288 | * | ||
289 | * The main purpose of this function is to retrieve the device node for the | ||
290 | * given logical CPU index. It should be used to initialize the of_node in | ||
291 | * cpu device. Once of_node in cpu device is populated, all the further | ||
292 | * references can use that instead. | ||
293 | * | ||
294 | * CPU logical to physical index mapping is architecture specific and is built | ||
295 | * before booting secondary cores. This function uses arch_match_cpu_phys_id | ||
296 | * which can be overridden by architecture specific implementation. | ||
297 | * | ||
298 | * Returns a node pointer for the logical cpu if found, else NULL. | ||
299 | */ | ||
300 | struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) | ||
301 | { | ||
302 | struct device_node *cpun, *cpus; | ||
303 | |||
304 | cpus = of_find_node_by_path("/cpus"); | ||
305 | if (!cpus) { | ||
306 | pr_warn("Missing cpus node, bailing out\n"); | ||
307 | return NULL; | ||
308 | } | ||
309 | |||
310 | for_each_child_of_node(cpus, cpun) { | ||
311 | if (of_node_cmp(cpun->type, "cpu")) | ||
312 | continue; | ||
313 | /* Check for non-standard "ibm,ppc-interrupt-server#s" property | ||
314 | * for thread ids on PowerPC. If it doesn't exist fallback to | ||
315 | * standard "reg" property. | ||
316 | */ | ||
317 | if (IS_ENABLED(CONFIG_PPC) && | ||
318 | __of_find_n_match_cpu_property(cpun, | ||
319 | "ibm,ppc-interrupt-server#s", cpu, thread)) | ||
320 | return cpun; | ||
321 | if (__of_find_n_match_cpu_property(cpun, "reg", cpu, thread)) | ||
322 | return cpun; | ||
323 | } | ||
324 | return NULL; | ||
325 | } | ||
326 | EXPORT_SYMBOL(of_get_cpu_node); | ||
327 | |||
233 | /** Checks if the given "compat" string matches one of the strings in | 328 | /** Checks if the given "compat" string matches one of the strings in |
234 | * the device's "compatible" property | 329 | * the device's "compatible" property |
235 | */ | 330 | */ |