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 <tomasz.bursztyka@linux.intel.com>
This commit is contained in:
Tomasz Bursztyka 2023-10-27 10:25:10 +02:00 committed by Fabio Baltieri
parent 72f416f382
commit c294b7d270
2 changed files with 16 additions and 8 deletions

View file

@ -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

View file

@ -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;
}