Commit 9f593f13 authored by Nicholas Piggin's avatar Nicholas Piggin Committed by Michael Ellerman

powerpc/setup: Add cpu_to_phys_id array

Build an array that finds hardware CPU number from logical CPU
number in firmware CPU discovery. Use that rather than setting
paca of other CPUs directly, to begin with. Subsequent patch will
not have pacas allocated at this point.
Signed-off-by: default avatarNicholas Piggin <npiggin@gmail.com>
[mpe: Fix SMP=n build by adding #ifdef in arch_match_cpu_phys_id()]
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
parent c0abd0c7
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
extern int boot_cpuid; extern int boot_cpuid;
extern int spinning_secondaries; extern int spinning_secondaries;
extern u32 *cpu_to_phys_id;
extern void cpu_die(void); extern void cpu_die(void);
extern int cpu_to_chip_id(int cpu); extern int cpu_to_chip_id(int cpu);
......
...@@ -874,5 +874,15 @@ EXPORT_SYMBOL(cpu_to_chip_id); ...@@ -874,5 +874,15 @@ EXPORT_SYMBOL(cpu_to_chip_id);
bool arch_match_cpu_phys_id(int cpu, u64 phys_id) bool arch_match_cpu_phys_id(int cpu, u64 phys_id)
{ {
#ifdef CONFIG_SMP
/*
* Early firmware scanning must use this rather than
* get_hard_smp_processor_id because we don't have pacas allocated
* until memory topology is discovered.
*/
if (cpu_to_phys_id != NULL)
return (int)phys_id == cpu_to_phys_id[cpu];
#endif
return (int)phys_id == get_hard_smp_processor_id(cpu); return (int)phys_id == get_hard_smp_processor_id(cpu);
} }
...@@ -437,6 +437,8 @@ static void __init cpu_init_thread_core_maps(int tpc) ...@@ -437,6 +437,8 @@ static void __init cpu_init_thread_core_maps(int tpc)
} }
u32 *cpu_to_phys_id = NULL;
/** /**
* setup_cpu_maps - initialize the following cpu maps: * setup_cpu_maps - initialize the following cpu maps:
* cpu_possible_mask * cpu_possible_mask
...@@ -463,6 +465,10 @@ void __init smp_setup_cpu_maps(void) ...@@ -463,6 +465,10 @@ void __init smp_setup_cpu_maps(void)
DBG("smp_setup_cpu_maps()\n"); DBG("smp_setup_cpu_maps()\n");
cpu_to_phys_id = __va(memblock_alloc(nr_cpu_ids * sizeof(u32),
__alignof__(u32)));
memset(cpu_to_phys_id, 0, nr_cpu_ids * sizeof(u32));
for_each_node_by_type(dn, "cpu") { for_each_node_by_type(dn, "cpu") {
const __be32 *intserv; const __be32 *intserv;
__be32 cpu_be; __be32 cpu_be;
...@@ -480,6 +486,7 @@ void __init smp_setup_cpu_maps(void) ...@@ -480,6 +486,7 @@ void __init smp_setup_cpu_maps(void)
intserv = of_get_property(dn, "reg", &len); intserv = of_get_property(dn, "reg", &len);
if (!intserv) { if (!intserv) {
cpu_be = cpu_to_be32(cpu); cpu_be = cpu_to_be32(cpu);
/* XXX: what is this? uninitialized?? */
intserv = &cpu_be; /* assume logical == phys */ intserv = &cpu_be; /* assume logical == phys */
len = 4; len = 4;
} }
...@@ -499,8 +506,8 @@ void __init smp_setup_cpu_maps(void) ...@@ -499,8 +506,8 @@ void __init smp_setup_cpu_maps(void)
"enable-method", "spin-table"); "enable-method", "spin-table");
set_cpu_present(cpu, avail); set_cpu_present(cpu, avail);
set_hard_smp_processor_id(cpu, be32_to_cpu(intserv[j]));
set_cpu_possible(cpu, true); set_cpu_possible(cpu, true);
cpu_to_phys_id[cpu] = be32_to_cpu(intserv[j]);
cpu++; cpu++;
} }
...@@ -570,6 +577,12 @@ void __init smp_setup_cpu_maps(void) ...@@ -570,6 +577,12 @@ void __init smp_setup_cpu_maps(void)
setup_nr_cpu_ids(); setup_nr_cpu_ids();
free_unused_pacas(); free_unused_pacas();
for_each_possible_cpu(cpu) {
if (cpu == smp_processor_id())
continue;
set_hard_smp_processor_id(cpu, cpu_to_phys_id[cpu]);
}
} }
#endif /* CONFIG_SMP */ #endif /* CONFIG_SMP */
......
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