Skip to content

Commit ce92546

Browse files
vlsunilpalmer-dabbelt
authored andcommitted
RISC-V: smpboot: Add ACPI support in setup_smp()
Enable SMP boot on ACPI based platforms by using the RINTC structures in the MADT table. Signed-off-by: Sunil V L <[email protected]> Acked-by: Rafael J. Wysocki <[email protected]> Reviewed-by: Conor Dooley <[email protected]> Reviewed-by: Andrew Jones <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Palmer Dabbelt <[email protected]>
1 parent 6194612 commit ce92546

File tree

2 files changed

+73
-1
lines changed

2 files changed

+73
-1
lines changed

arch/riscv/include/asm/acpi.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,8 @@ struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
6464
u32 get_acpi_id_for_cpu(int cpu);
6565
int acpi_get_riscv_isa(struct acpi_table_header *table,
6666
unsigned int cpu, const char **isa);
67+
68+
static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
6769
#else
6870
static inline void acpi_init_rintc_map(void) { }
6971
static inline struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)

arch/riscv/kernel/smpboot.c

Lines changed: 71 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
* Copyright (C) 2017 SiFive
99
*/
1010

11+
#include <linux/acpi.h>
1112
#include <linux/arch_topology.h>
1213
#include <linux/module.h>
1314
#include <linux/init.h>
@@ -70,6 +71,72 @@ void __init smp_prepare_cpus(unsigned int max_cpus)
7071
}
7172
}
7273

74+
#ifdef CONFIG_ACPI
75+
static unsigned int cpu_count = 1;
76+
77+
static int __init acpi_parse_rintc(union acpi_subtable_headers *header, const unsigned long end)
78+
{
79+
unsigned long hart;
80+
static bool found_boot_cpu;
81+
struct acpi_madt_rintc *processor = (struct acpi_madt_rintc *)header;
82+
83+
/*
84+
* Each RINTC structure in MADT will have a flag. If ACPI_MADT_ENABLED
85+
* bit in the flag is not enabled, it means OS should not try to enable
86+
* the cpu to which RINTC belongs.
87+
*/
88+
if (!(processor->flags & ACPI_MADT_ENABLED))
89+
return 0;
90+
91+
if (BAD_MADT_ENTRY(processor, end))
92+
return -EINVAL;
93+
94+
acpi_table_print_madt_entry(&header->common);
95+
96+
hart = processor->hart_id;
97+
if (hart == INVALID_HARTID) {
98+
pr_warn("Invalid hartid\n");
99+
return 0;
100+
}
101+
102+
if (hart == cpuid_to_hartid_map(0)) {
103+
BUG_ON(found_boot_cpu);
104+
found_boot_cpu = true;
105+
early_map_cpu_to_node(0, acpi_numa_get_nid(cpu_count));
106+
return 0;
107+
}
108+
109+
if (cpu_count >= NR_CPUS) {
110+
pr_warn("NR_CPUS is too small for the number of ACPI tables.\n");
111+
return 0;
112+
}
113+
114+
cpuid_to_hartid_map(cpu_count) = hart;
115+
early_map_cpu_to_node(cpu_count, acpi_numa_get_nid(cpu_count));
116+
cpu_count++;
117+
118+
return 0;
119+
}
120+
121+
static void __init acpi_parse_and_init_cpus(void)
122+
{
123+
int cpuid;
124+
125+
cpu_set_ops(0);
126+
127+
acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_rintc, 0);
128+
129+
for (cpuid = 1; cpuid < nr_cpu_ids; cpuid++) {
130+
if (cpuid_to_hartid_map(cpuid) != INVALID_HARTID) {
131+
cpu_set_ops(cpuid);
132+
set_cpu_possible(cpuid, true);
133+
}
134+
}
135+
}
136+
#else
137+
#define acpi_parse_and_init_cpus(...) do { } while (0)
138+
#endif
139+
73140
static void __init of_parse_and_init_cpus(void)
74141
{
75142
struct device_node *dn;
@@ -118,7 +185,10 @@ static void __init of_parse_and_init_cpus(void)
118185

119186
void __init setup_smp(void)
120187
{
121-
of_parse_and_init_cpus();
188+
if (acpi_disabled)
189+
of_parse_and_init_cpus();
190+
else
191+
acpi_parse_and_init_cpus();
122192
}
123193

124194
static int start_secondary_cpu(int cpu, struct task_struct *tidle)

0 commit comments

Comments
 (0)