Commit 819d5965 authored by Sudeep KarkadaNagesha's avatar Sudeep KarkadaNagesha

powerpc: refactor of_get_cpu_node to support other architectures

Currently different drivers requiring to access cpu device node are
parsing the device tree themselves. Since the ordering in the DT need
not match the logical cpu ordering, the parsing logic needs to consider
that. However, this has resulted in lots of code duplication and in some
cases even incorrect logic.

It's better to consolidate them by adding support for getting cpu
device node for a given logical cpu index in DT core library. However
logical to physical index mapping can be architecture specific.

PowerPC has it's own implementation to get the cpu node for a given
logical index.

This patch refactors the current implementation of of_get_cpu_node.
This in preparation to move the implementation to DT core library.
It separates out the logical to physical mapping so that a default
matching of the physical id to the logical cpu index can be added
when moved to common code. Architecture specific code can override it.

Cc: Rob Herring <rob.herring@calxeda.com>
Cc: Grant Likely <grant.likely@linaro.org>
Acked-by: default avatarBenjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: default avatarSudeep KarkadaNagesha <sudeep.karkadanagesha@arm.com>
parent 007fb9ae
...@@ -865,45 +865,63 @@ static int __init prom_reconfig_setup(void) ...@@ -865,45 +865,63 @@ static int __init prom_reconfig_setup(void)
__initcall(prom_reconfig_setup); __initcall(prom_reconfig_setup);
#endif #endif
bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
{
return (int)phys_id == get_hard_smp_processor_id(cpu);
}
static bool __of_find_n_match_cpu_property(struct device_node *cpun,
const char *prop_name, int cpu, unsigned int *thread)
{
const __be32 *cell;
int ac, prop_len, tid;
u64 hwid;
ac = of_n_addr_cells(cpun);
cell = of_get_property(cpun, prop_name, &prop_len);
if (!cell)
return false;
prop_len /= sizeof(*cell);
for (tid = 0; tid < prop_len; tid++) {
hwid = of_read_number(cell, ac);
if (arch_match_cpu_phys_id(cpu, hwid)) {
if (thread)
*thread = tid;
return true;
}
cell += ac;
}
return false;
}
/* Find the device node for a given logical cpu number, also returns the cpu /* Find the device node for a given logical cpu number, also returns the cpu
* local thread number (index in ibm,interrupt-server#s) if relevant and * local thread number (index in ibm,interrupt-server#s) if relevant and
* asked for (non NULL) * asked for (non NULL)
*/ */
struct device_node *of_get_cpu_node(int cpu, unsigned int *thread) struct device_node *of_get_cpu_node(int cpu, unsigned int *thread)
{ {
int hardid; struct device_node *cpun, *cpus;
struct device_node *np;
hardid = get_hard_smp_processor_id(cpu); cpus = of_find_node_by_path("/cpus");
if (!cpus) {
pr_warn("Missing cpus node, bailing out\n");
return NULL;
}
for_each_node_by_type(np, "cpu") { for_each_child_of_node(cpus, cpun) {
const u32 *intserv; if (of_node_cmp(cpun->type, "cpu"))
unsigned int plen, t; continue;
/* Check for ibm,ppc-interrupt-server#s. If it doesn't exist /* Check for non-standard "ibm,ppc-interrupt-server#s" property
* fallback to "reg" property and assume no threads * for thread ids on PowerPC. If it doesn't exist fallback to
* standard "reg" property.
*/ */
intserv = of_get_property(np, "ibm,ppc-interrupt-server#s", if (__of_find_n_match_cpu_property(cpun,
&plen); "ibm,ppc-interrupt-server#s", cpu, thread))
if (intserv == NULL) { return cpun;
const u32 *reg = of_get_property(np, "reg", NULL);
if (reg == NULL) if (__of_find_n_match_cpu_property(cpun, "reg", cpu, thread))
continue; return cpun;
if (*reg == hardid) {
if (thread)
*thread = 0;
return np;
}
} else {
plen /= sizeof(u32);
for (t = 0; t < plen; t++) {
if (hardid == intserv[t]) {
if (thread)
*thread = t;
return np;
}
}
}
} }
return NULL; return NULL;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment