summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Held <felix-coreboot@felixheld.de>2024-08-02 19:56:53 +0200
committerFelix Held <felix-coreboot@felixheld.de>2024-08-07 16:32:39 +0000
commitc12392b316cfc3213a61b900bc7d4064e5ee09d7 (patch)
tree4771b235c759e57f0d0f0ee156eef28caad6e35c
parent159430aa290dddce499c2f8dcbc863b11b6a56f4 (diff)
soc/amd/common/psp_smi_flash: validate target SPI region ID
Add and use functions to validate the target non-volatile storage ID in the different command buffer structs. This patch is a slightly reworked version of parts of CB:65523. Document #55758 Rev. 2.04 was used as a reference. Test=When selecting SOC_AMD_COMMON_BLOCK_PSP_SMI, Mandolin still builds Signed-off-by: Felix Held <felix-coreboot@felixheld.de> Signed-off-by: Ritul Guru <ritul.bits@gmail.com> Change-Id: Idda0166c862d41d380b2ed21345eead5e0a1c135 Reviewed-on: https://review.coreboot.org/c/coreboot/+/83758 Reviewed-by: Martin Roth <martin.roth@amd.corp-partner.google.com> Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
-rw-r--r--src/soc/amd/common/block/psp/psp_smi_flash.c46
1 files changed, 46 insertions, 0 deletions
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 b987cec170..f1b9d85fbb 100644
--- a/src/soc/amd/common/block/psp/psp_smi_flash.c
+++ b/src/soc/amd/common/block/psp/psp_smi_flash.c
@@ -1,6 +1,7 @@
/* SPDX-License-Identifier: GPL-2.0-only */
#include <console/console.h>
+#include <device/mmio.h>
#include <types.h>
#include "psp_def.h"
@@ -45,30 +46,75 @@ struct mbox_pspv2_cmd_spi_erase {
struct pspv2_spi_erase_request req;
} __packed;
+static bool is_valid_psp_spi_id(u64 target_nv_id)
+{
+ return target_nv_id == SMI_TARGET_NVRAM ||
+ target_nv_id == SMI_TARGET_RPMC_NVRAM;
+}
+
+static bool is_valid_psp_spi_info(struct mbox_pspv2_cmd_spi_info *cmd_buf)
+{
+ return is_valid_psp_spi_id(read64(&cmd_buf->req.target_nv_id));
+}
+
+static bool is_valid_psp_spi_read_write(struct mbox_pspv2_cmd_spi_read_write *cmd_buf)
+{
+ return is_valid_psp_spi_id(read64(&cmd_buf->req.target_nv_id));
+}
+
+static bool is_valid_psp_spi_erase(struct mbox_pspv2_cmd_spi_erase *cmd_buf)
+{
+ return is_valid_psp_spi_id(read64(&cmd_buf->req.target_nv_id));
+}
+
enum mbox_p2c_status psp_smi_spi_get_info(struct mbox_default_buffer *buffer)
{
+ struct mbox_pspv2_cmd_spi_info *const cmd_buf =
+ (struct mbox_pspv2_cmd_spi_info *)buffer;
+
printk(BIOS_SPEW, "PSP: SPI info request\n");
+ if (!is_valid_psp_spi_info(cmd_buf))
+ return MBOX_PSP_COMMAND_PROCESS_ERROR;
+
return MBOX_PSP_UNSUPPORTED;
}
enum mbox_p2c_status psp_smi_spi_read(struct mbox_default_buffer *buffer)
{
+ struct mbox_pspv2_cmd_spi_read_write *const cmd_buf =
+ (struct mbox_pspv2_cmd_spi_read_write *)buffer;
+
printk(BIOS_SPEW, "PSP: SPI read request\n");
+ if (!is_valid_psp_spi_read_write(cmd_buf))
+ return MBOX_PSP_COMMAND_PROCESS_ERROR;
+
return MBOX_PSP_UNSUPPORTED;
}
enum mbox_p2c_status psp_smi_spi_write(struct mbox_default_buffer *buffer)
{
+ struct mbox_pspv2_cmd_spi_read_write *const cmd_buf =
+ (struct mbox_pspv2_cmd_spi_read_write *)buffer;
+
printk(BIOS_SPEW, "PSP: SPI write request\n");
+ if (!is_valid_psp_spi_read_write(cmd_buf))
+ return MBOX_PSP_COMMAND_PROCESS_ERROR;
+
return MBOX_PSP_UNSUPPORTED;
}
enum mbox_p2c_status psp_smi_spi_erase(struct mbox_default_buffer *buffer)
{
+ struct mbox_pspv2_cmd_spi_erase *const cmd_buf =
+ (struct mbox_pspv2_cmd_spi_erase *)buffer;
+
printk(BIOS_SPEW, "PSP: SPI erase request\n");
+ if (!is_valid_psp_spi_erase(cmd_buf))
+ return MBOX_PSP_COMMAND_PROCESS_ERROR;
+
return MBOX_PSP_UNSUPPORTED;
}