@@ -16,7 +16,6 @@ DECLARE_PER_CPU(struct ia64_cpu, cpu_devices);
DECLARE_PER_CPU(int, cpu_state);
#ifdef CONFIG_HOTPLUG_CPU
-extern int arch_register_cpu(int num);
extern void arch_unregister_cpu(int);
#endif
@@ -126,7 +126,6 @@ enum cpu_type_enum {
#if !defined(__ASSEMBLY__)
#ifdef CONFIG_HOTPLUG_CPU
-extern int arch_register_cpu(int num);
extern void arch_unregister_cpu(int);
#endif
#endif /* ! __ASSEMBLY__ */
@@ -28,7 +28,6 @@ struct x86_cpu {
};
#ifdef CONFIG_HOTPLUG_CPU
-extern int arch_register_cpu(int num);
extern void arch_unregister_cpu(int);
extern void start_cpu0(void);
#ifdef CONFIG_DEBUG_HOTPLUG_CPU0
@@ -492,19 +492,25 @@ bool cpu_is_hotpluggable(unsigned int cpu)
EXPORT_SYMBOL_GPL(cpu_is_hotpluggable);
#ifdef CONFIG_GENERIC_CPU_DEVICES
-static DEFINE_PER_CPU(struct cpu, cpu_devices);
+DEFINE_PER_CPU(struct cpu, cpu_devices);
+
+int __weak arch_register_cpu(int cpu)
+{
+ return register_cpu(&per_cpu(cpu_devices, cpu), cpu);
+}
#endif
static void __init cpu_dev_register_generic(void)
{
-#ifdef CONFIG_GENERIC_CPU_DEVICES
int i;
+ if (!IS_ENABLED(CONFIG_GENERIC_CPU_DEVICES))
+ return;
+
for_each_present_cpu(i) {
- if (register_cpu(&per_cpu(cpu_devices, i), i))
+ if (arch_register_cpu(i))
panic("Failed to register CPU device");
}
-#endif
}
#ifdef CONFIG_GENERIC_CPU_VULNERABILITIES
@@ -75,12 +75,17 @@ extern __printf(4, 5)
struct device *cpu_device_create(struct device *parent, void *drvdata,
const struct attribute_group **groups,
const char *fmt, ...);
+extern int arch_register_cpu(int cpu);
#ifdef CONFIG_HOTPLUG_CPU
extern void unregister_cpu(struct cpu *cpu);
extern ssize_t arch_cpu_probe(const char *, size_t);
extern ssize_t arch_cpu_release(const char *, size_t);
#endif
+#ifdef CONFIG_GENERIC_CPU_DEVICES
+DECLARE_PER_CPU(struct cpu, cpu_devices);
+#endif
+
/*
* These states are not related to the core CPU hotplug mechanism. They are
* used by various (sub)architectures to track internal state
architectures often have extra per-cpu work that needs doing before a CPU is registered, often to determine if a CPU is hotpluggable. To allow more architectures to use GENERIC_CPU_DEVICES, wrap the call as a __weak arch_register_cpu(). This aligns with the way x86, ia64 and loongarch register hotplug CPUs when they become present. ACPI's acpi_processor.c also has a __weak version of this symbol because arm64 doesn't define one. The duplicate __weak definitions are only a problem if arm64 selects GENERIC_CPU_DEVICES without defining one. This gets fixed up in later patches. Signed-off-by: James Morse <james.morse@arm.com> --- arch/ia64/include/asm/cpu.h | 1 - arch/loongarch/include/asm/cpu.h | 1 - arch/x86/include/asm/cpu.h | 1 - drivers/base/cpu.c | 14 ++++++++++---- include/linux/cpu.h | 5 +++++ 5 files changed, 15 insertions(+), 7 deletions(-)