diff options
author | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-08-26 19:44:40 -0400 |
---|---|---|
committer | Rafael J. Wysocki <rafael.j.wysocki@intel.com> | 2013-08-26 19:44:40 -0400 |
commit | 7a330a5416de9240c93a6987e11cb32b581d3263 (patch) | |
tree | dba692d0b2cf263f85637edf012b1918d7ea08da /drivers/of | |
parent | c7878810f2d3a637bafc4fd55126eb9a5548ec77 (diff) | |
parent | 09198f8feff1fcdf03994f35955292f85b299bd6 (diff) |
Merge branch 'pm-cpufreq'
* pm-cpufreq: (60 commits)
cpufreq: pmac32-cpufreq: remove device tree parsing for cpu nodes
cpufreq: pmac64-cpufreq: remove device tree parsing for cpu nodes
cpufreq: maple-cpufreq: remove device tree parsing for cpu nodes
cpufreq: arm_big_little: remove device tree parsing for cpu nodes
cpufreq: kirkwood-cpufreq: remove device tree parsing for cpu nodes
cpufreq: spear-cpufreq: remove device tree parsing for cpu nodes
cpufreq: highbank-cpufreq: remove device tree parsing for cpu nodes
cpufreq: cpufreq-cpu0: remove device tree parsing for cpu nodes
cpufreq: imx6q-cpufreq: remove device tree parsing for cpu nodes
drivers/bus: arm-cci: avoid parsing DT for cpu device nodes
ARM: mvebu: remove device tree parsing for cpu nodes
ARM: topology: remove hwid/MPIDR dependency from cpu_capacity
of/device: add helper to get cpu device node from logical cpu index
driver/core: cpu: initialize of_node in cpu's device struture
ARM: DT/kernel: define ARM specific arch_match_cpu_phys_id
of: move of_get_cpu_node implementation to DT core library
powerpc: refactor of_get_cpu_node to support other architectures
openrisc: remove undefined of_get_cpu_node declaration
microblaze: remove undefined of_get_cpu_node declaration
cpufreq: fix bad unlock balance on !CONFIG_SMP
...
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 | */ |