mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
synced 2026-05-16 00:51:51 -04:00
RISC-V: 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 riscv. While at it, add input validation to make the code more robust. And also update acpi_numa.c and rhct.c to use the new interface instead of the legacy get_acpi_id_for_cpu(). Signed-off-by: Chengwen Feng <fengchengwen@huawei.com> Reviewed-by: Jonathan Cameron <jonathan.cameron@huawei.com> Link: https://patch.msgid.link/20260401081640.26875-4-fengchengwen@huawei.com Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
This commit is contained in:
committed by
Rafael J. Wysocki
parent
d78ef9d2e1
commit
0c8231994e
@@ -65,6 +65,7 @@ static inline u32 get_acpi_id_for_cpu(int cpu)
|
||||
{
|
||||
return acpi_cpu_get_madt_rintc(cpu)->uid;
|
||||
}
|
||||
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid);
|
||||
|
||||
int acpi_get_riscv_isa(struct acpi_table_header *table,
|
||||
unsigned int cpu, const char **isa);
|
||||
|
||||
@@ -337,3 +337,19 @@ int raw_pci_write(unsigned int domain, unsigned int bus,
|
||||
}
|
||||
|
||||
#endif /* CONFIG_PCI */
|
||||
|
||||
int acpi_get_cpu_uid(unsigned int cpu, u32 *uid)
|
||||
{
|
||||
struct acpi_madt_rintc *rintc;
|
||||
|
||||
if (cpu >= nr_cpu_ids)
|
||||
return -EINVAL;
|
||||
|
||||
rintc = acpi_cpu_get_madt_rintc(cpu);
|
||||
if (!rintc)
|
||||
return -ENODEV;
|
||||
|
||||
*uid = rintc->uid;
|
||||
return 0;
|
||||
}
|
||||
EXPORT_SYMBOL_GPL(acpi_get_cpu_uid);
|
||||
|
||||
@@ -37,11 +37,14 @@ static int __init acpi_numa_get_nid(unsigned int cpu)
|
||||
|
||||
static inline int get_cpu_for_acpi_id(u32 uid)
|
||||
{
|
||||
int cpu;
|
||||
u32 cpu_uid;
|
||||
int ret;
|
||||
|
||||
for (cpu = 0; cpu < nr_cpu_ids; cpu++)
|
||||
if (uid == get_acpi_id_for_cpu(cpu))
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -44,10 +44,15 @@ int acpi_get_riscv_isa(struct acpi_table_header *table, unsigned int cpu, const
|
||||
struct acpi_rhct_isa_string *isa_node;
|
||||
struct acpi_table_rhct *rhct;
|
||||
u32 *hart_info_node_offset;
|
||||
u32 acpi_cpu_id = get_acpi_id_for_cpu(cpu);
|
||||
u32 acpi_cpu_id;
|
||||
int ret;
|
||||
|
||||
BUG_ON(acpi_disabled);
|
||||
|
||||
ret = acpi_get_cpu_uid(cpu, &acpi_cpu_id);
|
||||
if (ret != 0)
|
||||
return ret;
|
||||
|
||||
if (!table) {
|
||||
rhct = acpi_get_rhct();
|
||||
if (!rhct)
|
||||
|
||||
Reference in New Issue
Block a user