cpu/x86/lapic: Fix regression with X2APIC_LATE_WORKAROUND
This patch fixes the boot hang due to commit 053a45bcdb3ccf8 ("cpu/x86/lapic: Fix X2APIC_ONLY regression") on platform which selects X2APIC_LATE_WORKAROUND config.
[EMERG] Switching from X2APIC to XAPIC mode is not implemented.
Without this patch: Boot gets stuck inside at BS_WRITE_TABLES when enable_lapic() gets called after X2APIC mode has been enabled. The fix is to change enable_lapic() to track when late enablement for X2APIC mode happens with X2APIC_LATE_WORKAROUND.
TEST=Able to build and boot google/rex to chromeos.
Change-Id: I41e72380e9cfb59721d0df607ad875d7b6546974
Signed-off-by: Kyösti Mälkki <kyosti.malkki@gmail.com>
Reviewed-on: https://review.coreboot.org/c/coreboot/+/76384
Reviewed-by: Subrata Banik <subratabanik@google.com>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
diff --git a/src/cpu/x86/lapic/lapic.c b/src/cpu/x86/lapic/lapic.c
index 24d2e37..8e0449a 100644
--- a/src/cpu/x86/lapic/lapic.c
+++ b/src/cpu/x86/lapic/lapic.c
@@ -9,6 +9,8 @@
#include <smp/node.h>
#include <types.h>
+static bool quirk_x2apic_allowed;
+
void enable_lapic_mode(bool try_set_x2apic)
{
uintptr_t apic_base;
@@ -46,14 +48,18 @@
die("Switching from X2APIC to XAPIC mode is not implemented.");
}
+ if (CONFIG(X2APIC_LATE_WORKAROUND) && use_x2apic)
+ quirk_x2apic_allowed = true;
}
void enable_lapic(void)
{
bool try_set_x2apic = true;
- if (CONFIG(XAPIC_ONLY) || CONFIG(X2APIC_LATE_WORKAROUND))
+ if (CONFIG(XAPIC_ONLY))
try_set_x2apic = false;
+ else if (CONFIG(X2APIC_LATE_WORKAROUND))
+ try_set_x2apic = quirk_x2apic_allowed;
enable_lapic_mode(try_set_x2apic);
}