cpu/x86/mp_init: factor out send_sipi_to_aps function

Apart from the SIPI number in the debug message the two instances of the
SIPI sending code in start_aps are identical, so factor it out into a
new send_sipi_to_aps function.

Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I6a921b81fce77fbf58c7ae3b50efd8c3e6e5aef3
Reviewed-on: https://review.coreboot.org/c/coreboot/+/58453
Reviewed-by: Raul Rangel <rrangel@chromium.org>
Reviewed-by: Paul Menzel <paulepanter@mailbox.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
This commit is contained in:
Felix Held 2021-10-19 01:03:24 +02:00 committed by Felix Held
parent edc5af552a
commit b04e2bae77
1 changed files with 25 additions and 32 deletions

View File

@ -425,6 +425,29 @@ static int apic_wait_timeout(int total_delay, int delay_step)
return timeout;
}
/* Send Startup IPI to APs */
static enum cb_err send_sipi_to_aps(int ap_count, atomic_t *num_aps, int sipi_vector)
{
if (lapic_busy()) {
printk(BIOS_DEBUG, "Waiting for ICR not to be busy...");
if (apic_wait_timeout(1000 /* 1 ms */, 50)) {
printk(BIOS_ERR, "timed out. Aborting.\n");
return CB_ERR;
}
printk(BIOS_DEBUG, "done.\n");
}
lapic_send_ipi(LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT | LAPIC_DM_STARTUP | sipi_vector,
0);
printk(BIOS_DEBUG, "Waiting for SIPI to complete...");
if (apic_wait_timeout(10000 /* 10 ms */, 50 /* us */)) {
printk(BIOS_ERR, "timed out.\n");
return CB_ERR;
}
printk(BIOS_DEBUG, "done.\n");
return CB_SUCCESS;
}
static int start_aps(struct bus *cpu_bus, int ap_count, atomic_t *num_aps)
{
int sipi_vector;
@ -466,23 +489,8 @@ static int start_aps(struct bus *cpu_bus, int ap_count, atomic_t *num_aps)
}
/* Send 1st Startup IPI (SIPI) */
if (lapic_busy()) {
printk(BIOS_DEBUG, "Waiting for ICR not to be busy...");
if (apic_wait_timeout(1000 /* 1 ms */, 50)) {
printk(BIOS_ERR, "timed out. Aborting.\n");
if (send_sipi_to_aps(ap_count, num_aps, sipi_vector) != CB_SUCCESS)
return -1;
}
printk(BIOS_DEBUG, "done.\n");
}
lapic_send_ipi(LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT | LAPIC_DM_STARTUP | sipi_vector,
0);
printk(BIOS_DEBUG, "Waiting for 1st SIPI to complete...");
if (apic_wait_timeout(10000 /* 10 ms */, 50 /* us */)) {
printk(BIOS_ERR, "timed out.\n");
return -1;
}
printk(BIOS_DEBUG, "done.\n");
/* Wait for CPUs to check in up to 200 us. */
wait_for_aps(num_aps, ap_count, 200 /* us */, 15 /* us */);
@ -491,23 +499,8 @@ static int start_aps(struct bus *cpu_bus, int ap_count, atomic_t *num_aps)
return 0;
/* Send 2nd SIPI */
if (lapic_busy()) {
printk(BIOS_DEBUG, "Waiting for ICR not to be busy...");
if (apic_wait_timeout(1000 /* 1 ms */, 50)) {
printk(BIOS_ERR, "timed out. Aborting.\n");
if (send_sipi_to_aps(ap_count, num_aps, sipi_vector) != CB_SUCCESS)
return -1;
}
printk(BIOS_DEBUG, "done.\n");
}
lapic_send_ipi(LAPIC_DEST_ALLBUT | LAPIC_INT_ASSERT | LAPIC_DM_STARTUP | sipi_vector,
0);
printk(BIOS_DEBUG, "Waiting for 2nd SIPI to complete...");
if (apic_wait_timeout(10000 /* 10 ms */, 50 /* us */)) {
printk(BIOS_ERR, "timed out.\n");
return -1;
}
printk(BIOS_DEBUG, "done.\n");
/* Wait for CPUs to check in. */
if (wait_for_aps(num_aps, ap_count, 100000 /* 100 ms */, 50 /* us */)) {