[PATCH v3 2/4] LoongArch: Refactor get_acpi_id_for_cpu() related code

From: Tiezhu Yang
Date: Wed Apr 10 2024 - 21:05:28 EST


Currently, cpu_logical_map(cpu) is defined as __cpu_logical_map[cpu]
in arch/loongarch/include/asm/smp.h and __cpu_logical_map[] is defined
in arch/loongarch/kernel/smp.c, that is to say, cpu_logical_map(cpu) is
vaild only under CONFIG_SMP, the implementation of get_acpi_id_for_cpu()
which calls cpu_logical_map(cpu) is not suitable for the case of non-SMP,
so refactor get_acpi_id_for_cpu() related code to make it work well for
both SMP and non-SMP.

Signed-off-by: Tiezhu Yang <yangtiezhu@xxxxxxxxxxx>
---
arch/loongarch/include/asm/acpi.h | 7 ++++++-
arch/loongarch/kernel/acpi.c | 9 ++++++++-
2 files changed, 14 insertions(+), 2 deletions(-)

diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm/acpi.h
index 49e29b29996f..a4ad3f75bd60 100644
--- a/arch/loongarch/include/asm/acpi.h
+++ b/arch/loongarch/include/asm/acpi.h
@@ -39,9 +39,14 @@ extern struct acpi_madt_core_pic acpi_core_pic[MAX_CORE_PIC];

extern int __init parse_acpi_topology(void);

+static inline struct acpi_madt_core_pic *acpi_cpu_get_core_pic(int cpu)
+{
+ return &acpi_core_pic[cpu];
+}
+
static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
{
- return acpi_core_pic[cpu_logical_map(cpu)].processor_id;
+ return acpi_cpu_get_core_pic(cpu)->processor_id;
}

#endif /* !CONFIG_ACPI */
diff --git a/arch/loongarch/kernel/acpi.c b/arch/loongarch/kernel/acpi.c
index 5cf59c617126..ccfa90faf0ea 100644
--- a/arch/loongarch/kernel/acpi.c
+++ b/arch/loongarch/kernel/acpi.c
@@ -98,8 +98,15 @@ acpi_parse_processor(union acpi_subtable_headers *header, const unsigned long en
return -EINVAL;

acpi_table_print_madt_entry(&header->common);
+
+ /*
+ * When CONFIG_SMP is disabled, mapping won't be created for all cpus.
+ * CPUs more than num_possible_cpus will be ignored.
+ */
+ if (processor->core_id >= 0 && processor->core_id < num_possible_cpus())
+ acpi_core_pic[processor->core_id] = *processor;
+
#ifdef CONFIG_SMP
- acpi_core_pic[processor->core_id] = *processor;
set_processor_mask(processor->core_id, processor->flags);
#endif

--
2.42.0