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>
This commit is contained in:
		@@ -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;
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user