From f48dd169954716562bc88f9ecb25d38d63c18f8d Mon Sep 17 00:00:00 2001 From: Felix Held Date: Tue, 29 Oct 2024 20:45:44 +0100 Subject: soc/amd/common/psp_smi_flash: refactor SPI controller busy check Since the functions that call 'spi_controller_available' end up checking if the SPI controller is busy, refactor the function into 'spi_controller_busy' to simplify the logic on the caller's side. Also move printing of the notice that the SPI controller is busy to 'spi_controller_busy' to not have that duplicated in caller. Signed-off-by: Felix Held Change-Id: Ibc21ab6eacf07c4adffdb4658142c2f9dfcbf2a1 Reviewed-on: https://review.coreboot.org/c/coreboot/+/84920 Reviewed-by: Matt DeVillier Tested-by: build bot (Jenkins) --- src/soc/amd/common/block/psp/psp_smi_flash.c | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/soc') diff --git a/src/soc/amd/common/block/psp/psp_smi_flash.c b/src/soc/amd/common/block/psp/psp_smi_flash.c index ca595536c1..abddcdf19a 100644 --- a/src/soc/amd/common/block/psp/psp_smi_flash.c +++ b/src/soc/amd/common/block/psp/psp_smi_flash.c @@ -92,9 +92,14 @@ static enum mbox_p2c_status find_psp_spi_flash_device_region(uint64_t target_nv_ return MBOX_PSP_SUCCESS; } -static bool spi_controller_available(void) +static bool spi_controller_busy(void) { - return !(spi_read8(SPI_MISC_CNTRL) & SPI_SEMAPHORE_DRIVER_LOCKED); + const bool busy = (spi_read8(SPI_MISC_CNTRL) & SPI_SEMAPHORE_DRIVER_LOCKED); + + if (busy) + printk(BIOS_NOTICE, "PSP: SPI controller busy\n"); + + return busy; } enum mbox_p2c_status psp_smi_spi_get_info(struct mbox_default_buffer *buffer) @@ -113,8 +118,7 @@ enum mbox_p2c_status psp_smi_spi_get_info(struct mbox_default_buffer *buffer) if (!is_valid_psp_spi_info(cmd_buf)) return MBOX_PSP_COMMAND_PROCESS_ERROR; - if (!spi_controller_available()) { - printk(BIOS_NOTICE, "PSP: SPI controller busy\n"); + if (spi_controller_busy()) { return MBOX_PSP_SPI_BUSY; } @@ -156,8 +160,7 @@ enum mbox_p2c_status psp_smi_spi_read(struct mbox_default_buffer *buffer) if (!is_valid_psp_spi_read_write(cmd_buf)) return MBOX_PSP_COMMAND_PROCESS_ERROR; - if (!spi_controller_available()) { - printk(BIOS_NOTICE, "PSP: SPI controller busy\n"); + if (spi_controller_busy()) { return MBOX_PSP_SPI_BUSY; } @@ -205,8 +208,7 @@ enum mbox_p2c_status psp_smi_spi_write(struct mbox_default_buffer *buffer) if (!is_valid_psp_spi_read_write(cmd_buf)) return MBOX_PSP_COMMAND_PROCESS_ERROR; - if (!spi_controller_available()) { - printk(BIOS_NOTICE, "PSP: SPI controller busy\n"); + if (spi_controller_busy()) { return MBOX_PSP_SPI_BUSY; } @@ -253,8 +255,7 @@ enum mbox_p2c_status psp_smi_spi_erase(struct mbox_default_buffer *buffer) if (!is_valid_psp_spi_erase(cmd_buf)) return MBOX_PSP_COMMAND_PROCESS_ERROR; - if (!spi_controller_available()) { - printk(BIOS_NOTICE, "PSP: SPI controller busy\n"); + if (spi_controller_busy()) { return MBOX_PSP_SPI_BUSY; } -- cgit v1.2.3