From 244a34b3d0e5f5278194e0902870060448c347eb Mon Sep 17 00:00:00 2001 From: NyeonWoo Kim Date: Sat, 16 Aug 2025 13:34:35 +0900 Subject: [PATCH] cpu/x86/mp_init: Refactor ICR wait logic Extracted ICR wait logic into a new function 'icr_wait_timeout'. Change-Id: Ie48899f7afb125061fd7efd44c83f5775c05d254 Signed-off-by: NyeonWoo Kim Reviewed-on: https://review.coreboot.org/c/coreboot/+/88788 Tested-by: build bot (Jenkins) Reviewed-by: Nicholas Sudsgaard Reviewed-by: Shuo Liu --- src/cpu/x86/mp_init.c | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/cpu/x86/mp_init.c b/src/cpu/x86/mp_init.c index f223ccc6e5..23880c74c8 100644 --- a/src/cpu/x86/mp_init.c +++ b/src/cpu/x86/mp_init.c @@ -424,8 +424,7 @@ static enum cb_err apic_wait_timeout(int total_delay, int delay_step) return CB_SUCCESS; } -/* Send Startup IPI to APs */ -static enum cb_err send_sipi_to_aps(int ap_count, atomic_t *num_aps, int sipi_vector) +static enum cb_err icr_wait_timeout(void) { if (lapic_busy()) { printk(BIOS_DEBUG, "Waiting for ICR not to be busy...\n"); @@ -436,6 +435,15 @@ static enum cb_err send_sipi_to_aps(int ap_count, atomic_t *num_aps, int sipi_ve printk(BIOS_DEBUG, "done.\n"); } + return CB_SUCCESS; +} + +/* Send Startup IPI to APs */ +static enum cb_err send_sipi_to_aps(int ap_count, atomic_t *num_aps, int sipi_vector) +{ + if (icr_wait_timeout() != CB_SUCCESS) + return CB_ERR; + lapic_send_ipi_others(LAPIC_INT_ASSERT | LAPIC_MT_STARTUP | sipi_vector); printk(BIOS_DEBUG, "Waiting for SIPI to complete...\n"); if (apic_wait_timeout(10000 /* 10 ms */, 50 /* us */) != CB_SUCCESS) { @@ -466,14 +474,8 @@ static enum cb_err start_aps(struct bus *cpu_bus, int ap_count, atomic_t *num_ap printk(BIOS_DEBUG, "Attempting to start %d APs\n", ap_count); - if (lapic_busy()) { - printk(BIOS_DEBUG, "Waiting for ICR not to be busy...\n"); - if (apic_wait_timeout(1000 /* 1 ms */, 50) != CB_SUCCESS) { - printk(BIOS_ERR, "timed out. Aborting.\n"); - return CB_ERR; - } - printk(BIOS_DEBUG, "done.\n"); - } + if (icr_wait_timeout() != CB_SUCCESS) + return CB_ERR; /* Send INIT IPI to all but self. */ lapic_send_ipi_others(LAPIC_INT_ASSERT | LAPIC_MT_INIT); @@ -651,14 +653,8 @@ static enum cb_err mp_init(struct bus *cpu_bus, struct mp_params *p) void smm_initiate_relocation_parallel(void) { - if (lapic_busy()) { - printk(BIOS_DEBUG, "Waiting for ICR not to be busy..."); - if (apic_wait_timeout(1000 /* 1 ms */, 50) != CB_SUCCESS) { - printk(BIOS_DEBUG, "timed out. Aborting.\n"); - return; - } - printk(BIOS_DEBUG, "done.\n"); - } + if (icr_wait_timeout() != CB_SUCCESS) + return; lapic_send_ipi_self(LAPIC_INT_ASSERT | LAPIC_MT_SMI);