From 35f02752673e573ae00d1c4628edf839aee1e4be Mon Sep 17 00:00:00 2001 From: James Morse Date: Thu, 16 Apr 2020 11:05:04 +0800 Subject: [PATCH 2869/2944] openEuler: ACPI / processor: Add helper to convert acpi_id to a phys_cpuid commit f9a6fbe92c9088f4c6b7e45e115aa749beebc7ca openEuler-1.0 hulk inclusion category: feature bugzilla: 28055 CVE: NA ------------------------------ The PPTT parsing code only has access to an acpi_id, we need a hardware property, preferably the corresponding phys_cpuid_t. acpi_get_cpuid() requires us to have the acpi_handle, which would imply we already have the acpi_device or acpi_processor structure. This call is useful when the CPU may not have been mapped, e.g. when walking the namespace. The PPTT is parsed after CPUs have been discovered and mapped, add a helper to walk the possible CPUs and test whether the acpi_processor matches our acpi_id. Signed-off-by: James Morse Signed-off-by: Wang ShaoBo Reviewed-By: Xie XiuQi Signed-off-by: Yang Yingliang Signed-off-by: Xin Hao Reviewed-by: Baolin Wang --- drivers/acpi/processor_core.c | 16 ++++++++++++++++ include/acpi/processor.h | 1 + 2 files changed, 17 insertions(+) diff --git a/drivers/acpi/processor_core.c b/drivers/acpi/processor_core.c index 8c0a54d..333547b 100644 --- a/drivers/acpi/processor_core.c +++ b/drivers/acpi/processor_core.c @@ -9,7 +9,9 @@ * Yinghai Lu * Jiang Liu */ +#include #include +#include #include #include @@ -263,6 +265,20 @@ int acpi_get_cpuid(acpi_handle handle, int type, u32 acpi_id) } EXPORT_SYMBOL_GPL(acpi_get_cpuid); +phys_cpuid_t acpi_id_to_phys_cpuid(u32 acpi_id) +{ + int cpu; + struct acpi_processor *pr; + + for_each_possible_cpu(cpu) { + pr = per_cpu(processors, cpu); + if (pr && pr->acpi_id == acpi_id) + return pr->phys_id; + } + + return PHYS_CPUID_INVALID; +} + #ifdef CONFIG_ACPI_HOTPLUG_IOAPIC static int get_ioapic_id(struct acpi_subtable_header *entry, u32 gsi_base, u64 *phys_addr, int *ioapic_id) diff --git a/include/acpi/processor.h b/include/acpi/processor.h index 1194a4c..9235b41 100644 --- a/include/acpi/processor.h +++ b/include/acpi/processor.h @@ -333,6 +333,7 @@ static inline int acpi_processor_get_bios_limit(int cpu, unsigned int *limit) phys_cpuid_t acpi_map_madt_entry(u32 acpi_id); int acpi_map_cpuid(phys_cpuid_t phys_id, u32 acpi_id); int acpi_get_cpuid(acpi_handle, int type, u32 acpi_id); +phys_cpuid_t acpi_id_to_phys_cpuid(u32 acpi_id); #ifdef CONFIG_ACPI_CPPC_LIB extern int acpi_cppc_processor_probe(struct acpi_processor *pr); -- 1.8.3.1