diff options
author | Felix Held <felix-coreboot@felixheld.de> | 2024-08-23 23:39:30 +0200 |
---|---|---|
committer | Felix Held <felix-coreboot@felixheld.de> | 2024-08-27 11:34:31 +0000 |
commit | 84db1745e6ee9554927e3e90fad87a16f3e37d91 (patch) | |
tree | b4ac3c0ade0d125c9d528c7e2972d5268e921660 | |
parent | acb304439482d660d4ed22268a6e75887028f7f7 (diff) |
soc/amd/common/psp/psp_smi_flash: factor out generation-specific code
Factor out the code to access the request buffer into PSP generation
specific file. This is a preparation for adding PSP SMI flash access
support for the PSP generation 1 which has a slightly different request
buffer layout.
Signed-off-by: Felix Held <felix-coreboot@felixheld.de>
Change-Id: I8e18f7ea53592d9fd413ad56e8d137cfc13ad5d4
Reviewed-on: https://review.coreboot.org/c/coreboot/+/84062
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Matt DeVillier <matt.devillier@amd.corp-partner.google.com>
Reviewed-by: Marshall Dawson <marshalldawson3rd@gmail.com>
-rw-r--r-- | src/soc/amd/common/block/psp/Makefile.mk | 1 | ||||
-rw-r--r-- | src/soc/amd/common/block/psp/psp_smi_flash.c | 95 | ||||
-rw-r--r-- | src/soc/amd/common/block/psp/psp_smi_flash.h | 56 | ||||
-rw-r--r-- | src/soc/amd/common/block/psp/psp_smi_flash_gen2.c | 58 |
4 files changed, 116 insertions, 94 deletions
diff --git a/src/soc/amd/common/block/psp/Makefile.mk b/src/soc/amd/common/block/psp/Makefile.mk index b72343c365..20e55e80cb 100644 --- a/src/soc/amd/common/block/psp/Makefile.mk +++ b/src/soc/amd/common/block/psp/Makefile.mk @@ -29,6 +29,7 @@ ramstage-$(CONFIG_PSP_PLATFORM_SECURE_BOOT) += psb.c ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_I2C3_TPM_SHARED_WITH_PSP) += tpm.c smm-y += psp_gen2.c +smm-$(CONFIG_SOC_AMD_COMMON_BLOCK_PSP_SMI) += psp_smi_flash_gen2.c smm-y += psp_smm_gen2.c ramstage-$(CONFIG_SOC_AMD_COMMON_BLOCK_PSP_SPL) += spl_fuse.c 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 405fc29ef7..8a622961c5 100644 --- a/src/soc/amd/common/block/psp/psp_smi_flash.c +++ b/src/soc/amd/common/block/psp/psp_smi_flash.c @@ -9,100 +9,7 @@ #include <spi_flash.h> #include <types.h> #include "psp_def.h" - -enum psp_spi_id_type { - SMI_TARGET_NVRAM = 0, - SMI_TARGET_RPMC_NVRAM = 5, -}; - -struct pspv2_spi_info_request { - u64 target_nv_id; - u64 lba; - u64 block_size; - u64 num_blocks; -} __packed; - -struct mbox_pspv2_cmd_spi_info { - struct mbox_buffer_header header; - struct pspv2_spi_info_request req; -} __packed; - -struct pspv2_spi_read_write_request { - u64 target_nv_id; - u64 lba; - u64 offset; - u64 num_bytes; - u8 buffer[]; -} __packed; - -struct mbox_pspv2_cmd_spi_read_write { - struct mbox_buffer_header header; - struct pspv2_spi_read_write_request req; -} __packed; - -struct pspv2_spi_erase_request { - u64 target_nv_id; - u64 lba; - u64 num_blocks; -} __packed; - -struct mbox_pspv2_cmd_spi_erase { - struct mbox_buffer_header header; - 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)); -} - -static u64 get_psp_spi_info_id(struct mbox_pspv2_cmd_spi_info *cmd_buf) -{ - return read64(&cmd_buf->req.target_nv_id); -} - -static void set_psp_spi_info(struct mbox_pspv2_cmd_spi_info *cmd_buf, - u64 lba, u64 block_size, u64 num_blocks) -{ - write64(&cmd_buf->req.lba, lba); - write64(&cmd_buf->req.block_size, block_size); - write64(&cmd_buf->req.num_blocks, num_blocks); -} - -static void get_psp_spi_read_write(struct mbox_pspv2_cmd_spi_read_write *cmd_buf, - u64 *target_nv_id, u64 *lba, u64 *offset, - u64 *num_bytes, u8 **data) -{ - *target_nv_id = read64(&cmd_buf->req.target_nv_id); - *lba = read64(&cmd_buf->req.lba); - *offset = read64(&cmd_buf->req.offset); - *num_bytes = read64(&cmd_buf->req.num_bytes); - *data = cmd_buf->req.buffer; -} - -static void get_psp_spi_erase(struct mbox_pspv2_cmd_spi_erase *cmd_buf, - u64 *target_nv_id, u64 *lba, u64 *num_blocks) -{ - *target_nv_id = read64(&cmd_buf->req.target_nv_id); - *lba = read64(&cmd_buf->req.lba); - *num_blocks = read64(&cmd_buf->req.num_blocks); -} +#include "psp_smi_flash.h" static bool is_valid_rw_byte_count(struct mbox_pspv2_cmd_spi_read_write *cmd_buf, u64 num_bytes) diff --git a/src/soc/amd/common/block/psp/psp_smi_flash.h b/src/soc/amd/common/block/psp/psp_smi_flash.h new file mode 100644 index 0000000000..077cc3b72c --- /dev/null +++ b/src/soc/amd/common/block/psp/psp_smi_flash.h @@ -0,0 +1,56 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <types.h> +#include "psp_def.h" + +enum psp_spi_id_type { + SMI_TARGET_NVRAM = 0, + SMI_TARGET_RPMC_NVRAM = 5, +}; + +struct pspv2_spi_info_request { + u64 target_nv_id; + u64 lba; + u64 block_size; + u64 num_blocks; +} __packed; + +struct mbox_pspv2_cmd_spi_info { + struct mbox_buffer_header header; + struct pspv2_spi_info_request req; +} __packed; + +struct pspv2_spi_read_write_request { + u64 target_nv_id; + u64 lba; + u64 offset; + u64 num_bytes; + u8 buffer[]; +} __packed; + +struct mbox_pspv2_cmd_spi_read_write { + struct mbox_buffer_header header; + struct pspv2_spi_read_write_request req; +} __packed; + +struct pspv2_spi_erase_request { + u64 target_nv_id; + u64 lba; + u64 num_blocks; +} __packed; + +struct mbox_pspv2_cmd_spi_erase { + struct mbox_buffer_header header; + struct pspv2_spi_erase_request req; +} __packed; + +bool is_valid_psp_spi_info(struct mbox_pspv2_cmd_spi_info *cmd_buf); +bool is_valid_psp_spi_read_write(struct mbox_pspv2_cmd_spi_read_write *cmd_buf); +bool is_valid_psp_spi_erase(struct mbox_pspv2_cmd_spi_erase *cmd_buf); +u64 get_psp_spi_info_id(struct mbox_pspv2_cmd_spi_info *cmd_buf); +void set_psp_spi_info(struct mbox_pspv2_cmd_spi_info *cmd_buf, u64 lba, u64 block_size, + u64 num_blocks); +void get_psp_spi_read_write(struct mbox_pspv2_cmd_spi_read_write *cmd_buf, u64 *target_nv_id, + u64 *lba, u64 *offset, u64 *num_bytes, u8 **data); +void get_psp_spi_erase(struct mbox_pspv2_cmd_spi_erase *cmd_buf, u64 *target_nv_id, u64 *lba, + u64 *num_blocks); diff --git a/src/soc/amd/common/block/psp/psp_smi_flash_gen2.c b/src/soc/amd/common/block/psp/psp_smi_flash_gen2.c new file mode 100644 index 0000000000..99ea0303d5 --- /dev/null +++ b/src/soc/amd/common/block/psp/psp_smi_flash_gen2.c @@ -0,0 +1,58 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ + +#include <device/mmio.h> +#include <types.h> +#include "psp_def.h" +#include "psp_smi_flash.h" + +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; +} + +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)); +} + +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)); +} + +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)); +} + +u64 get_psp_spi_info_id(struct mbox_pspv2_cmd_spi_info *cmd_buf) +{ + return read64(&cmd_buf->req.target_nv_id); +} + +void set_psp_spi_info(struct mbox_pspv2_cmd_spi_info *cmd_buf, u64 lba, u64 block_size, + u64 num_blocks) +{ + write64(&cmd_buf->req.lba, lba); + write64(&cmd_buf->req.block_size, block_size); + write64(&cmd_buf->req.num_blocks, num_blocks); +} + +void get_psp_spi_read_write(struct mbox_pspv2_cmd_spi_read_write *cmd_buf, u64 *target_nv_id, + u64 *lba, u64 *offset, u64 *num_bytes, u8 **data) +{ + *target_nv_id = read64(&cmd_buf->req.target_nv_id); + *lba = read64(&cmd_buf->req.lba); + *offset = read64(&cmd_buf->req.offset); + *num_bytes = read64(&cmd_buf->req.num_bytes); + *data = cmd_buf->req.buffer; +} + +void get_psp_spi_erase(struct mbox_pspv2_cmd_spi_erase *cmd_buf, u64 *target_nv_id, u64 *lba, + u64 *num_blocks) +{ + *target_nv_id = read64(&cmd_buf->req.target_nv_id); + *lba = read64(&cmd_buf->req.lba); + *num_blocks = read64(&cmd_buf->req.num_blocks); +} |