Skip to content

Commit 7cd5f56

Browse files
fengchengwenrafaeljw
authored andcommitted
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>
1 parent 591cd65 commit 7cd5f56

2 files changed

Lines changed: 32 additions & 12 deletions

File tree

arch/arm64/include/asm/acpi.h

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -118,18 +118,8 @@ static inline u32 get_acpi_id_for_cpu(unsigned int cpu)
118118
{
119119
return acpi_cpu_get_madt_gicc(cpu)->uid;
120120
}
121-
122-
static inline int get_cpu_for_acpi_id(u32 uid)
123-
{
124-
int cpu;
125-
126-
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
127-
if (acpi_cpu_get_madt_gicc(cpu) &&
128-
uid == get_acpi_id_for_cpu(cpu))
129-
return cpu;
130-
131-
return -EINVAL;
132-
}
121+
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid);
122+
int get_cpu_for_acpi_id(u32 uid);
133123

134124
static inline void arch_fix_phys_package_id(int num, u32 slot) { }
135125
void __init acpi_init_cpus(void);

arch/arm64/kernel/acpi.c

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -458,3 +458,33 @@ int acpi_unmap_cpu(int cpu)
458458
}
459459
EXPORT_SYMBOL(acpi_unmap_cpu);
460460
#endif /* CONFIG_ACPI_HOTPLUG_CPU */
461+
462+
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
463+
{
464+
struct acpi_madt_generic_interrupt *gicc;
465+
466+
if (cpu >= nr_cpu_ids)
467+
return -EINVAL;
468+
469+
gicc = acpi_cpu_get_madt_gicc(cpu);
470+
if (!gicc)
471+
return -ENODEV;
472+
473+
*uid = gicc->uid;
474+
return 0;
475+
}
476+
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
477+
478+
int get_cpu_for_acpi_id(u32 uid)
479+
{
480+
u32 cpu_uid;
481+
int ret;
482+
483+
for (int cpu = 0; cpu < nr_cpu_ids; cpu++) {
484+
ret = acpi_get_cpu_uid(cpu, &cpu_uid);
485+
if (ret == 0 && uid == cpu_uid)
486+
return cpu;
487+
}
488+
489+
return -EINVAL;
490+
}

0 commit comments

Comments
 (0)