[PATCH 2/3] LoongArch: ACPI: Introduce get_cpu_for_acpi_id

Jiaxun Yang posted 3 patches 1 year, 5 months ago
[PATCH 2/3] LoongArch: ACPI: Introduce get_cpu_for_acpi_id
Posted by Jiaxun Yang 1 year, 5 months ago
This would allow us to reverse lookup cpu_id from apic_id.
Since it won't be a hot function, just use simple iteration match.

Signed-off-by: Jiaxun Yang <jiaxun.yang@flygoat.com>
---
 arch/loongarch/include/asm/acpi.h | 12 ++++++++++++
 1 file changed, 12 insertions(+)

diff --git a/arch/loongarch/include/asm/acpi.h b/arch/loongarch/include/asm/acpi.h
index 313f66f7913a..5d4f8f5efdb6 100644
--- a/arch/loongarch/include/asm/acpi.h
+++ b/arch/loongarch/include/asm/acpi.h
@@ -45,6 +45,18 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
 	return acpi_core_pic[cpu_logical_map(cpu)].processor_id;
 }
 
+static inline int get_cpu_for_acpi_id(u32 acpi_id)
+{
+	int cpu;
+
+	for_each_possible_cpu(cpu) {
+		if (acpi_core_pic[cpu_logical_map(cpu)].processor_id == acpi_id)
+			return cpu;
+	}
+
+	return -1;
+}
+
 #endif /* !CONFIG_ACPI */
 
 #define ACPI_TABLE_UPGRADE_MAX_PHYS ARCH_LOW_ADDRESS_LIMIT

-- 
2.46.0