ACPI: Add helper for MADT LAPICs
This avoids some code duplication related to X2APIC mode.
Change-Id: I592c69e0f52687924fe41189b082c86913999136
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/74312
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Tim Wawrzynczak <inforichland@gmail.com>
diff --git a/src/acpi/acpi.c b/src/acpi/acpi.c
index 2439d7b..f4b6d20 100644
--- a/src/acpi/acpi.c
+++ b/src/acpi/acpi.c
@@ -122,7 +122,7 @@
return sizeof(acpi_mcfg_mmconfig_t);
}
-int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
+static int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic)
{
lapic->type = LOCAL_APIC; /* Local APIC structure */
lapic->length = sizeof(acpi_madt_lapic_t);
@@ -133,7 +133,7 @@
return lapic->length;
}
-int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic)
+static int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic)
{
lapic->type = LOCAL_X2APIC; /* Local APIC structure */
lapic->reserved = 0;
@@ -145,6 +145,18 @@
return lapic->length;
}
+unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 index, u32 lapic_id)
+{
+ if (lapic_id <= ACPI_MADT_MAX_LAPIC_ID)
+ current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, index,
+ lapic_id);
+ else
+ current += acpi_create_madt_lx2apic((acpi_madt_lx2apic_t *)current, index,
+ lapic_id);
+
+ return current;
+}
+
static unsigned long acpi_create_madt_lapics(unsigned long current)
{
struct device *cpu;
@@ -159,14 +171,8 @@
}
if (num_cpus > 1)
bubblesort(apic_ids, num_cpus, NUM_ASCENDING);
- for (index = 0; index < num_cpus; index++) {
- if (apic_ids[index] < 0xff)
- current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current,
- index, apic_ids[index]);
- else
- current += acpi_create_madt_lx2apic((acpi_madt_lx2apic_t *)current,
- index, apic_ids[index]);
- }
+ for (index = 0; index < num_cpus; index++)
+ current = acpi_create_madt_one_lapic(current, index, apic_ids[index]);
return current;
}