Skip to content

Commit

Permalink
lib/acpi: Fix the behavior to fit with how it used to be
Browse files Browse the repository at this point in the history
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 <[email protected]>
(cherry picked from commit c294b7d)
  • Loading branch information
Tomasz Bursztyka authored and jhedberg committed Nov 1, 2023
1 parent 3b52bc7 commit 79a538d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
6 changes: 3 additions & 3 deletions include/zephyr/acpi/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
18 changes: 13 additions & 5 deletions lib/acpi/acpi.c
Original file line number Diff line number Diff line change
Expand Up @@ -791,21 +791,29 @@ 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)) {
/* Error on MAD table. */
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;
}

0 comments on commit 79a538d

Please sign in to comment.