[RFC PATCH v2 10/35] riscv: Switch over to GENERIC_CPU_DEVICES

From: James Morse
Date: Wed Sep 13 2023 - 12:39:49 EST


Now that GENERIC_CPU_DEVICES calls arch_register_cpu(), which can be
overridden by the arch code, switch over to this to allow common code
to choose when the register_cpu() call is made.

This allows topology_init() to be removed.

This is an intermediate step to the logic being moved to drivers/acpi,
where GENERIC_CPU_DEVICES will do the work when booting with acpi=off.

Signed-off-by: James Morse <james.morse@xxxxxxx>
---
arch/riscv/Kconfig | 1 +
arch/riscv/kernel/setup.c | 19 ++++---------------
2 files changed, 5 insertions(+), 15 deletions(-)

diff --git a/arch/riscv/Kconfig b/arch/riscv/Kconfig
index d607ab0f7c6d..eeb80fb55acc 100644
--- a/arch/riscv/Kconfig
+++ b/arch/riscv/Kconfig
@@ -69,6 +69,7 @@ config RISCV
select GENERIC_ARCH_TOPOLOGY
select GENERIC_ATOMIC64 if !64BIT
select GENERIC_CLOCKEVENTS_BROADCAST if SMP
+ select GENERIC_CPU_DEVICES
select GENERIC_EARLY_IOREMAP
select GENERIC_ENTRY
select GENERIC_GETTIMEOFDAY if HAVE_GENERIC_VDSO
diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c
index e600aab116a4..f5bd6b8d0c52 100644
--- a/arch/riscv/kernel/setup.c
+++ b/arch/riscv/kernel/setup.c
@@ -62,7 +62,6 @@ atomic_t hart_lottery __section(".sdata")
#endif
;
unsigned long boot_cpu_hartid;
-static DEFINE_PER_CPU(struct cpu, cpu_devices);

/*
* Place kernel memory regions on the resource tree so that
@@ -320,23 +319,13 @@ void __init setup_arch(char **cmdline_p)
riscv_set_dma_cache_alignment();
}

-static int __init topology_init(void)
+int arch_register_cpu(int cpu)
{
- int i, ret;
+ struct cpu *c = &per_cpu(cpu_devices, cpu);

- for_each_possible_cpu(i) {
- struct cpu *cpu = &per_cpu(cpu_devices, i);
-
- cpu->hotpluggable = cpu_has_hotplug(i);
- ret = register_cpu(cpu, i);
- if (unlikely(ret))
- pr_warn("Warning: %s: register_cpu %d failed (%d)\n",
- __func__, i, ret);
- }
-
- return 0;
+ c->hotpluggable = cpu_has_hotplug(cpu);
+ return register_cpu(c, cpu);
}
-subsys_initcall(topology_init);

void free_initmem(void)
{
--
2.39.2