diff --git a/src/soc/amd/common/block/psp/psp_def.h b/src/soc/amd/common/block/psp/psp_def.h index 6120c92174..9d60c264bf 100644 --- a/src/soc/amd/common/block/psp/psp_def.h +++ b/src/soc/amd/common/block/psp/psp_def.h @@ -175,4 +175,7 @@ enum cb_err soc_read_c2p38(uint32_t *msg_38_value); void enable_psp_smi(void); +void psp_set_smm_flag(void); +void psp_clear_smm_flag(void); + #endif /* __AMD_PSP_DEF_H__ */ diff --git a/src/soc/amd/common/block/psp/psp_gen1.c b/src/soc/amd/common/block/psp/psp_gen1.c index b3815f9283..d57759fa2b 100644 --- a/src/soc/amd/common/block/psp/psp_gen1.c +++ b/src/soc/amd/common/block/psp/psp_gen1.c @@ -115,6 +115,7 @@ static int wait_command(struct pspv1_mbox *mbox) int send_psp_command(uint32_t command, void *buffer) { struct pspv1_mbox *mbox = soc_get_mbox_address(); + int ret = 0; if (!mbox) return -PSPSTS_NOBASE; @@ -132,19 +133,30 @@ int send_psp_command(uint32_t command, void *buffer) if (wait_command(mbox)) return -PSPSTS_CMD_TIMEOUT; + if (ENV_SMM) + psp_set_smm_flag(); + /* set address of command-response buffer and write command register */ wr_mbox_cmd_resp(mbox, buffer); wr_mbox_cmd(mbox, command); /* PSP clears command register when complete */ - if (wait_command(mbox)) - return -PSPSTS_CMD_TIMEOUT; + if (wait_command(mbox)) { + ret = -PSPSTS_CMD_TIMEOUT; + goto out; + } /* check delivery status */ - if (rd_mbox_sts(mbox) & (PSPV1_STATUS_ERROR | PSPV1_STATUS_TERMINATED)) - return -PSPSTS_SEND_ERROR; + if (rd_mbox_sts(mbox) & (PSPV1_STATUS_ERROR | PSPV1_STATUS_TERMINATED)) { + ret = -PSPSTS_SEND_ERROR; + goto out; + } - return 0; +out: + if (ENV_SMM) + psp_clear_smm_flag(); + + return ret; } /* diff --git a/src/soc/amd/common/block/psp/psp_gen2.c b/src/soc/amd/common/block/psp/psp_gen2.c index 026d32f086..b3cb6ef8ed 100644 --- a/src/soc/amd/common/block/psp/psp_gen2.c +++ b/src/soc/amd/common/block/psp/psp_gen2.c @@ -152,6 +152,8 @@ static int wait_command(uintptr_t psp_mmio, bool wait_for_ready) int send_psp_command(uint32_t command, void *buffer) { const uintptr_t psp_mmio = get_psp_mmio_base(); + int ret = 0; + if (!psp_mmio) return -PSPSTS_NOBASE; @@ -161,20 +163,30 @@ int send_psp_command(uint32_t command, void *buffer) if (wait_command(psp_mmio, true)) return -PSPSTS_CMD_TIMEOUT; + if (ENV_SMM) + psp_set_smm_flag(); + /* set address of command-response buffer and write command register */ wr_mbox_buffer_ptr(psp_mmio, buffer); wr_mbox_cmd(psp_mmio, command); /* PSP clears command register when complete. All commands except * SxInfo set the Ready bit. */ - if (wait_command(psp_mmio, command != MBOX_BIOS_CMD_SX_INFO)) - return -PSPSTS_CMD_TIMEOUT; + if (wait_command(psp_mmio, command != MBOX_BIOS_CMD_SX_INFO)) { + ret = -PSPSTS_CMD_TIMEOUT; + goto out; + } /* check delivery status */ - if (rd_mbox_sts(psp_mmio)) - return -PSPSTS_SEND_ERROR; + if (rd_mbox_sts(psp_mmio)) { + ret = -PSPSTS_SEND_ERROR; + goto out; + } - return 0; +out: + if (ENV_SMM) + psp_clear_smm_flag(); + return ret; } enum cb_err psp_get_psp_capabilities(uint32_t *capabilities) diff --git a/src/soc/amd/common/block/psp/psp_smm.c b/src/soc/amd/common/block/psp/psp_smm.c index 7fade174d7..ef7a018827 100644 --- a/src/soc/amd/common/block/psp/psp_smm.c +++ b/src/soc/amd/common/block/psp/psp_smm.c @@ -36,27 +36,16 @@ struct { */ static uint32_t smm_flag; -static void set_smm_flag(void) +void psp_set_smm_flag(void) { smm_flag = 1; } -static void clear_smm_flag(void) +void psp_clear_smm_flag(void) { smm_flag = 0; } -static int send_psp_command_smm(uint32_t command, void *buffer) -{ - int cmd_status; - - set_smm_flag(); - cmd_status = send_psp_command(command, buffer); - clear_smm_flag(); - - return cmd_status; -} - /* * The MBOX_BIOS_CMD_SMM_INFO PSP mailbox command doesn't necessarily need be sent from SMM, * but doing so allows the linker to sort out the addresses of c2p_buffer, p2c_buffer and @@ -101,7 +90,7 @@ int psp_notify_smm(void) printk(BIOS_DEBUG, "PSP: Notify SMM info... "); - cmd_status = send_psp_command_smm(MBOX_BIOS_CMD_SMM_INFO, &buffer); + cmd_status = send_psp_command(MBOX_BIOS_CMD_SMM_INFO, &buffer); /* buffer's status shouldn't change but report it if it does */ psp_print_cmd_status(cmd_status, &buffer.header); @@ -129,7 +118,7 @@ void psp_notify_sx_info(uint8_t sleep_type) buffer->sleep_type = sleep_type; - cmd_status = send_psp_command_smm(MBOX_BIOS_CMD_SX_INFO, buffer); + cmd_status = send_psp_command(MBOX_BIOS_CMD_SX_INFO, buffer); /* buffer's status shouldn't change but report it if it does */ psp_print_cmd_status(cmd_status, &buffer->header);