LoongArch: Add multi-processor (SMP) support
[platform/kernel/linux-starfive.git] / arch / loongarch / kernel / setup.c
index 29f3b82..34a3011 100644 (file)
@@ -38,6 +38,7 @@
 #include <asm/pgalloc.h>
 #include <asm/sections.h>
 #include <asm/setup.h>
+#include <asm/smp.h>
 #include <asm/time.h>
 
 #define SMBIOS_BIOSSIZE_OFFSET         0x09
@@ -322,6 +323,29 @@ static int __init reserve_memblock_reserved_regions(void)
 }
 arch_initcall(reserve_memblock_reserved_regions);
 
+#ifdef CONFIG_SMP
+static void __init prefill_possible_map(void)
+{
+       int i, possible;
+
+       possible = num_processors + disabled_cpus;
+       if (possible > nr_cpu_ids)
+               possible = nr_cpu_ids;
+
+       pr_info("SMP: Allowing %d CPUs, %d hotplug CPUs\n",
+                       possible, max((possible - num_processors), 0));
+
+       for (i = 0; i < possible; i++)
+               set_cpu_possible(i, true);
+       for (; i < NR_CPUS; i++)
+               set_cpu_possible(i, false);
+
+       nr_cpu_ids = possible;
+}
+#else
+static inline void prefill_possible_map(void) {}
+#endif
+
 void __init setup_arch(char **cmdline_p)
 {
        cpu_probe();
@@ -336,6 +360,8 @@ void __init setup_arch(char **cmdline_p)
        arch_mem_init(cmdline_p);
 
        resource_init();
+       plat_smp_setup();
+       prefill_possible_map();
 
        paging_init();
 }