From 5f608c97341195e49ae30d557cec4f7980737463 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Micha=C5=82=20Kope=C4=87?= Date: Thu, 16 Mar 2023 14:30:06 +0100 Subject: [PATCH] drivers/smmstore/ramstage.c: retry smmstore init up 5 times MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Retry calling the SMI 5 times in case the initial write to APM did not cause SMM entry immediately. Fixes occasional SMMSTORE initialization failure on Clevo NV4xPZ with Intel i5-1240P processor. The issue was especially evident when all logging in coreboot was disabled. Based on SMMSTORE implementation in MrChromebox's fork of EDK2: https://github.com/MrChromebox/edk2/commit/27854bc8c5e7147f01e50404f6e5b16ffedf08b8 Change-Id: I8929af25c4f69873bbdd835fde5cb60fc324b6ab Signed-off-by: Michał Kopeć --- src/drivers/smmstore/ramstage.c | 28 ++++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/src/drivers/smmstore/ramstage.c b/src/drivers/smmstore/ramstage.c index ef80e221bc..d0eeeb6900 100644 --- a/src/drivers/smmstore/ramstage.c +++ b/src/drivers/smmstore/ramstage.c @@ -8,6 +8,7 @@ #include #include #include +#include static struct smmstore_params_info info; @@ -39,6 +40,7 @@ static void init_store(void *unused) struct smmstore_params_init args; uint32_t eax = ~0; uint32_t ebx; + uint8_t retry = 5; if (smmstore_get_info(&info) < 0) { printk(BIOS_INFO, "SMMSTORE: Failed to get meta data\n"); @@ -57,14 +59,24 @@ static void init_store(void *unused) printk(BIOS_INFO, "SMMSTORE: Setting up SMI handler\n"); - /* Issue SMI using APM to update the com buffer and to lock the SMMSTORE */ - __asm__ __volatile__ ( - "outb %%al, %%dx" - : "=a" (eax) - : "a" ((SMMSTORE_CMD_INIT << 8) | APM_CNT_SMMSTORE), - "b" (ebx), - "d" (APM_CNT) - : "memory"); + /* + * Issue SMI using APM to update the com buffer and to lock the SMMSTORE. + * Retry 5 times in case the SMI isn't triggered immediately. + */ + do { + __asm__ __volatile__ ( + "outb %%al, %%dx" + : "=a" (eax) + : "a" ((SMMSTORE_CMD_INIT << 8) | APM_CNT_SMMSTORE), + "b" (ebx), + "d" (APM_CNT) + : "memory"); + + if (eax == SMMSTORE_RET_SUCCESS) + break; + + mdelay(1); + } while (retry--); if (eax != SMMSTORE_RET_SUCCESS) { printk(BIOS_ERR, "SMMSTORE: Failed to install com buffer\n");