diff options
author | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2023-04-07 23:05:46 +0300 |
---|---|---|
committer | Kyösti Mälkki <kyosti.malkki@gmail.com> | 2023-04-11 19:58:17 +0000 |
commit | 2e9f0d3b6aa754dc71cd36086d1eb2a839bdb7bd (patch) | |
tree | 31a80c52cf753a8f6adeed13b2e01adff5e0af0f | |
parent | 9ac1fb729fa316564992403580254b1c4afbf9c2 (diff) |
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>
-rw-r--r-- | src/acpi/acpi.c | 26 | ||||
-rw-r--r-- | src/include/acpi/acpi.h | 6 | ||||
-rw-r--r-- | src/soc/intel/common/block/acpi/cpu_hybrid.c | 11 | ||||
-rw-r--r-- | src/soc/intel/xeon_sp/spr/soc_acpi.c | 3 |
4 files changed, 23 insertions, 23 deletions
diff --git a/src/acpi/acpi.c b/src/acpi/acpi.c index 2439d7b44a..f4b6d20e50 100644 --- a/src/acpi/acpi.c +++ b/src/acpi/acpi.c @@ -122,7 +122,7 @@ int acpi_create_mcfg_mmconfig(acpi_mcfg_mmconfig_t *mmconfig, u32 base, 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 @@ int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic) 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 @@ int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic) 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 @@ static unsigned long acpi_create_madt_lapics(unsigned long current) } 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; } diff --git a/src/include/acpi/acpi.h b/src/include/acpi/acpi.h index 36201ae140..77f73ae358 100644 --- a/src/include/acpi/acpi.h +++ b/src/include/acpi/acpi.h @@ -682,6 +682,8 @@ typedef struct acpi_madt_lapic { u32 flags; /* Local APIC flags */ } __packed acpi_madt_lapic_t; +#define ACPI_MADT_MAX_LAPIC_ID 0xfe + /* MADT: Local APIC NMI Structure */ typedef struct acpi_madt_lapic_nmi { u8 type; /* Type (4) */ @@ -1334,7 +1336,6 @@ int acpi_create_cedt_chbs(acpi_cedt_chbs_t *chbs, u32 uid, u32 cxl_ver, u64 base int acpi_create_cedt_cfmws(acpi_cedt_cfmws_t *cfmws, u64 base_hpa, u64 window_size, u8 eniw, u32 hbig, u16 restriction, u16 qtg_id, const u32 *interleave_target); -int acpi_create_madt_lapic(acpi_madt_lapic_t *lapic, u8 cpu, u8 apic); int acpi_create_madt_ioapic(acpi_madt_ioapic_t *ioapic, u8 id, u32 addr, u32 gsi_base); int acpi_create_madt_ioapic_from_hw(acpi_madt_ioapic_t *ioapic, u32 addr); @@ -1343,12 +1344,11 @@ int acpi_create_madt_irqoverride(acpi_madt_irqoverride_t *irqoverride, void acpi_create_madt(acpi_madt_t *madt); +unsigned long acpi_create_madt_one_lapic(unsigned long current, u32 cpu, u32 apic); unsigned long acpi_create_madt_lapics_with_nmis(unsigned long current); unsigned long acpi_create_madt_lapic_nmis(unsigned long current); -int acpi_create_madt_lx2apic(acpi_madt_lx2apic_t *lapic, u32 cpu, u32 apic); - int acpi_create_srat_lapic(acpi_srat_lapic_t *lapic, u8 node, u8 apic); int acpi_create_srat_x2apic(acpi_srat_x2apic_t *x2apic, u32 node, u32 apic); int acpi_create_srat_mem(acpi_srat_mem_t *mem, u8 node, u32 basek, u32 sizek, diff --git a/src/soc/intel/common/block/acpi/cpu_hybrid.c b/src/soc/intel/common/block/acpi/cpu_hybrid.c index 2e39f720ab..e18c28868f 100644 --- a/src/soc/intel/common/block/acpi/cpu_hybrid.c +++ b/src/soc/intel/common/block/acpi/cpu_hybrid.c @@ -81,14 +81,9 @@ static unsigned long acpi_create_madt_lapics_hybrid(unsigned long current) { size_t index; - for (index = 0; index < cpu_apic_info.total_cpu_cnt; index++) { - if (cpu_apic_info.apic_ids[index] < 0xff) - current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, - index, cpu_apic_info.apic_ids[index]); - else - current += acpi_create_madt_lx2apic((acpi_madt_lx2apic_t *)current, - index, cpu_apic_info.apic_ids[index]); - } + for (index = 0; index < cpu_apic_info.total_cpu_cnt; index++) + current = acpi_create_madt_one_lapic(current, index, + cpu_apic_info.apic_ids[index]); return current; } diff --git a/src/soc/intel/xeon_sp/spr/soc_acpi.c b/src/soc/intel/xeon_sp/spr/soc_acpi.c index 619e5bb423..c609f4fa65 100644 --- a/src/soc/intel/xeon_sp/spr/soc_acpi.c +++ b/src/soc/intel/xeon_sp/spr/soc_acpi.c @@ -540,8 +540,7 @@ unsigned long xeonsp_acpi_create_madt_lapics(unsigned long current) } if (!cpu->enabled) continue; - current += acpi_create_madt_lapic((acpi_madt_lapic_t *)current, num_cpus, - cpu->path.apic.apic_id); + current = acpi_create_madt_one_lapic(current, num_cpus, cpu->path.apic.apic_id); num_cpus++; } |