From 79a538dad03ab55b78f880be7394492016199146 Mon Sep 17 00:00:00 2001 From: Tomasz Bursztyka Date: Fri, 27 Oct 2023 10:25:10 +0200 Subject: [PATCH] lib/acpi: Fix the behavior to fit with how it used to be z_acpi_get_cpu() used to retrieve the local apic on enabled CPU, where n was about the n'th enabled CPU, not just the n'th local apic. The system indeed keeps local apic info also about non-enabled CPU, and we don't care about these as there is nothing to do about it. This issue exists on up_squared board for instance, but it's a common one anyway. Signed-off-by: Tomasz Bursztyka (cherry picked from commit c294b7d2701230d7e66aaeeb541d7997f880023e) --- include/zephyr/acpi/acpi.h | 6 +++--- lib/acpi/acpi.c | 18 +++++++++++++----- 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/include/zephyr/acpi/acpi.h b/include/zephyr/acpi/acpi.h index 77a1f2e95278..c66f55acbb86 100644 --- a/include/zephyr/acpi/acpi.h +++ b/include/zephyr/acpi/acpi.h @@ -175,10 +175,10 @@ int acpi_drhd_get(enum AcpiDmarScopeType scope, struct acpi_dmar_device_scope *d union acpi_dmar_id *dmar_id, int *num_inst, int max_inst); /** - * @brief Retrieve lapic info for a specific cpu. + * @brief Retrieve the 'n'th enabled local apic info. * * @param cpu_num the cpu number - * @return lapic info on success or NULL + * @return local apic info on success or NULL otherwise */ -struct acpi_madt_local_apic *acpi_local_apic_get(uint32_t cpu_num); +struct acpi_madt_local_apic *acpi_local_apic_get(int cpu_num); #endif diff --git a/lib/acpi/acpi.c b/lib/acpi/acpi.c index d8f91d01ce80..dca6e81cc3e2 100644 --- a/lib/acpi/acpi.c +++ b/lib/acpi/acpi.c @@ -791,10 +791,13 @@ int acpi_drhd_get(enum AcpiDmarScopeType scope, struct acpi_dmar_device_scope *d return 0; } -struct acpi_madt_local_apic *acpi_local_apic_get(uint32_t cpu_num) +#define ACPI_CPU_FLAGS_ENABLED 0x01u + +struct acpi_madt_local_apic *acpi_local_apic_get(int cpu_num) { struct acpi_madt_local_apic *lapic; int cpu_cnt; + int idx; if (acpi_madt_entry_get(ACPI_MADT_TYPE_LOCAL_APIC, (ACPI_SUBTABLE_HEADER **)&lapic, &cpu_cnt)) { @@ -802,10 +805,15 @@ struct acpi_madt_local_apic *acpi_local_apic_get(uint32_t cpu_num) return NULL; } - if ((cpu_num >= cpu_cnt) || !(lapic[cpu_num].LapicFlags & 1u)) { - /* Proccessor not enabled. */ - return NULL; + for (idx = 0; cpu_num >= 0 && idx < cpu_cnt; idx++) { + if (lapic[idx].LapicFlags & ACPI_CPU_FLAGS_ENABLED) { + if (cpu_num == 0) { + return &lapic[idx]; + } + + cpu_num--; + } } - return &lapic[cpu_num]; + return NULL; }