arm64: acpi: Add acpi_get_cpu_uid() for unified ACPI CPU UID retrieval

As a step towards unifying the interface for retrieving ACPI CPU UID
across architectures, introduce a new function acpi_get_cpu_uid() for
arm64. While at it, add input validation to make the code more robust.

Reimplement get_cpu_for_acpi_id() based on acpi_get_cpu_uid() for
consistency, and move its implementation next to the new function for
code coherence.

Signed-off-by: Chengwen Feng <fengchengwen@huawei.com>
Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com>
Acked-by: Catalin Marinas <catalin.marinas@arm.com>
Link: https://patch.msgid.link/20260401081640.26875-2-fengchengwen@huawei.com
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
Chengwen Feng 2026-04-01 16:16:33 +08:00 committed by Rafael J. Wysocki
parent 591cd656a1
commit 7cd5f5659a
2 changed files with 32 additions and 12 deletions

View File

@ -118,18 +118,8 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
{
return acpi_cpu_get_madt_gicc(cpu)->uid;
}
static inline int get_cpu_for_acpi_id(u32 uid)
{
int cpu;
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
if (acpi_cpu_get_madt_gicc(cpu) &&
uid == get_acpi_id_for_cpu(cpu))
return cpu;
return -EINVAL;
}
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid);
int get_cpu_for_acpi_id(u32 uid);
static inline void arch_fix_phys_package_id(int num, u32 slot) { }
void __init acpi_init_cpus(void);

View File

@ -458,3 +458,33 @@ int acpi_unmap_cpu(int cpu)
}
EXPORT_SYMBOL(acpi_unmap_cpu);
#endif /* CONFIG_ACPI_HOTPLUG_CPU */
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
{
struct acpi_madt_generic_interrupt *gicc;
if (cpu >= nr_cpu_ids)
return -EINVAL;
gicc = acpi_cpu_get_madt_gicc(cpu);
if (!gicc)
return -ENODEV;
*uid = gicc->uid;
return 0;
}
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
int get_cpu_for_acpi_id(u32 uid)
{
u32 cpu_uid;
int ret;
for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
if (ret == 0 && uid == cpu_uid)
return cpu;
}
return -EINVAL;
}