[PATCH V2 11/21] RISC-V: ACPI: Add a function to retrieve the hartid
Sunil V L
sunilvl at ventanamicro.com
Thu Feb 16 10:20:33 PST 2023
The hartid is in the RINTC structure of the MADT table. Instead of
parsing the ACPI table every time, cache it and provide a function
to read it.
Signed-off-by: Sunil V L <sunilvl at ventanamicro.com>
Acked-by: Rafael J. Wysocki <rafael.j.wysocki at intel.com>
---
arch/riscv/include/asm/acpi.h | 8 +++++
arch/riscv/kernel/acpi.c | 55 +++++++++++++++++++++++++++++++++++
2 files changed, 63 insertions(+)
diff --git a/arch/riscv/include/asm/acpi.h b/arch/riscv/include/asm/acpi.h
index 3c3a8ac3b37a..b9d7b713fb43 100644
--- a/arch/riscv/include/asm/acpi.h
+++ b/arch/riscv/include/asm/acpi.h
@@ -67,6 +67,9 @@ int acpi_numa_get_nid(unsigned int cpu);
static inline int acpi_numa_get_nid(unsigned int cpu) { return NUMA_NO_NODE; }
#endif /* CONFIG_ACPI_NUMA */
+struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu);
+
+u32 get_acpi_id_for_cpu(int cpu);
#else
static inline int acpi_get_riscv_isa(struct acpi_table_header *table,
unsigned int cpu, const char **isa)
@@ -74,6 +77,11 @@ static inline int acpi_get_riscv_isa(struct acpi_table_header *table,
return -EINVAL;
}
+static inline u32 get_acpi_id_for_cpu(int cpu)
+{
+ return -1;
+}
+
#endif /* CONFIG_ACPI */
#endif /*_ASM_ACPI_H*/
diff --git a/arch/riscv/kernel/acpi.c b/arch/riscv/kernel/acpi.c
index 81d448c41714..13b26c87c136 100644
--- a/arch/riscv/kernel/acpi.c
+++ b/arch/riscv/kernel/acpi.c
@@ -24,6 +24,61 @@ EXPORT_SYMBOL(acpi_disabled);
int acpi_pci_disabled = 1; /* skip ACPI PCI scan and IRQ initialization */
EXPORT_SYMBOL(acpi_pci_disabled);
+static unsigned int intc_count;
+static struct acpi_madt_rintc cpu_madt_rintc[NR_CPUS];
+
+static int acpi_parse_madt_rintc(union acpi_subtable_headers *header, const unsigned long end)
+{
+ struct acpi_madt_rintc *rintc = (struct acpi_madt_rintc *)header;
+
+ if (!(rintc->flags & ACPI_MADT_ENABLED))
+ return 0;
+
+ cpu_madt_rintc[intc_count++] = *rintc;
+
+ return 0;
+}
+
+static int acpi_init_rintc_array(void)
+{
+ if (acpi_table_parse_madt(ACPI_MADT_TYPE_RINTC, acpi_parse_madt_rintc, 0) > 0)
+ return 0;
+
+ pr_info("No valid RINTC entries exist\n");
+ return -ENODEV;
+}
+
+struct acpi_madt_rintc *acpi_cpu_get_madt_rintc(int cpu)
+{
+ static bool rintc_init_done;
+ unsigned int i;
+
+ if (!rintc_init_done) {
+ if (acpi_init_rintc_array()) {
+ pr_err("Failed to initialize RINTC array\n");
+ return NULL;
+ }
+ rintc_init_done = true;
+ }
+
+ for (i = 0; i < intc_count; i++) {
+ if (cpu_madt_rintc[i].hart_id == cpuid_to_hartid_map(cpu))
+ return &cpu_madt_rintc[i];
+ }
+
+ return NULL;
+}
+
+u32 get_acpi_id_for_cpu(int cpu)
+{
+ struct acpi_madt_rintc *rintc = acpi_cpu_get_madt_rintc(cpu);
+
+ if (!rintc)
+ return -1;
+
+ return rintc->uid;
+}
+
/*
* __acpi_map_table() will be called before paging_init(), so early_ioremap()
* or early_memremap() should be called here to for ACPI table mapping.
--
2.34.1
More information about the linux-riscv
mailing list