Felix Held has submitted this change. ( https://review.coreboot.org/c/coreboot/+/84066?usp=email )
Change subject: soc/amd/common/psp: add helper functions to retrieve capability bits ......................................................................
soc/amd/common/psp: add helper functions to retrieve capability bits
Add helper functions to send the PSP commands to query the fTPM and PSP capability bits as well as the HSTI state. All SoCs using any PSP generation support the MBOX_BIOS_CMD_PSP_FTPM_QUERY command and some generation 1 and all generation 2 PSP SoCs support the MBOX_BIOS_CMD_HSTI_QUERY command, so implement those two in the common psp.c. Only PSP generation 2 supports the MBOX_BIOS_CMD_PSP_CAPS_QUERY command, so implement that one in psp_gen2.c.
This code is ported and modified from github.com/teslamotors/coreboot/tree/tesla-4.12-amd
Document #54267 revision 1.06 was used as reference for the 1st PSP generation and document #55758 revision 2.04 was used for the 2nd PSP generation.
Signed-off-by: Felix Held felix-coreboot@felixheld.de Change-Id: I4e17f994fb332690828c55742262da793e297d99 Reviewed-on: https://review.coreboot.org/c/coreboot/+/84066 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 --- M src/soc/amd/common/block/psp/psp.c M src/soc/amd/common/block/psp/psp_def.h M src/soc/amd/common/block/psp/psp_gen2.c 3 files changed, 86 insertions(+), 0 deletions(-)
Approvals: build bot (Jenkins): Verified Matt DeVillier: Looks good to me, approved Marshall Dawson: Looks good to me, approved
diff --git a/src/soc/amd/common/block/psp/psp.c b/src/soc/amd/common/block/psp/psp.c index f989a3b..a8bb205 100644 --- a/src/soc/amd/common/block/psp/psp.c +++ b/src/soc/amd/common/block/psp/psp.c @@ -55,6 +55,52 @@ printk(BIOS_DEBUG, "OK\n"); }
+enum cb_err psp_get_ftpm_capabilties(uint32_t *capabilities) +{ + int cmd_status; + struct mbox_cmd_capability_query_buffer buffer = { + .header = { + .size = sizeof(buffer) + }, + }; + + printk(BIOS_DEBUG, "PSP: Querying fTPM capabilities..."); + + cmd_status = send_psp_command(MBOX_BIOS_CMD_PSP_FTPM_QUERY, &buffer); + + /* buffer's status shouldn't change but report it if it does */ + psp_print_cmd_status(cmd_status, &buffer.header); + + if (!cmd_status) + return CB_ERR; + + *capabilities = read32(&buffer.capabilities); + return CB_SUCCESS; +} + +enum cb_err psp_get_hsti_state(uint32_t *state) +{ + int cmd_status; + struct mbox_cmd_hsti_query_buffer buffer = { + .header = { + .size = sizeof(buffer) + }, + }; + + printk(BIOS_DEBUG, "PSP: Querying HSTI state..."); + + cmd_status = send_psp_command(MBOX_BIOS_CMD_HSTI_QUERY, &buffer); + + /* buffer's status shouldn't change but report it if it does */ + psp_print_cmd_status(cmd_status, &buffer.header); + + if (!cmd_status) + return CB_ERR; + + *state = read32(&buffer.state); + return CB_SUCCESS; +} + /* * Notify the PSP that the system is completing the boot process. Upon * receiving this command, the PSP will only honor commands where the buffer diff --git a/src/soc/amd/common/block/psp/psp_def.h b/src/soc/amd/common/block/psp/psp_def.h index fa3ce36..3cf2fc9 100644 --- a/src/soc/amd/common/block/psp/psp_def.h +++ b/src/soc/amd/common/block/psp/psp_def.h @@ -23,7 +23,9 @@ #define MBOX_BIOS_CMD_CLEAR_S3_STS 0x07 #define MBOX_BIOS_CMD_S3_DATA_INFO 0x08 #define MBOX_BIOS_CMD_NOP 0x09 +#define MBOX_BIOS_CMD_HSTI_QUERY 0x14 #define MBOX_BIOS_CMD_PSB_AUTO_FUSING 0x21 +#define MBOX_BIOS_CMD_PSP_CAPS_QUERY 0x27 #define MBOX_BIOS_CMD_SET_SPL_FUSE 0x2d #define MBOX_BIOS_CMD_QUERY_SPL_FUSE 0x47 #define MBOX_BIOS_CMD_I2C_TPM_ARBITRATION 0x64 @@ -84,6 +86,18 @@ u8 sleep_type; } __packed __aligned(32);
+/* MBOX_BIOS_CMD_PSP_FTPM_QUERY, MBOX_BIOS_CMD_PSP_CAPS_QUERY */ +struct mbox_cmd_capability_query_buffer { + struct mbox_buffer_header header; + uint32_t capabilities; +} __packed __aligned(32); + +/* MBOX_BIOS_CMD_HSTI_QUERY */ +struct mbox_cmd_hsti_query_buffer { + struct mbox_buffer_header header; + uint32_t state; +} __packed __aligned(32); + /* MBOX_BIOS_CMD_SET_SPL_FUSE */ struct mbox_cmd_late_spl_buffer { struct mbox_buffer_header header; @@ -132,6 +146,9 @@ /* This command needs to be implemented by the generation specific code. */ int send_psp_command(u32 command, void *buffer);
+enum cb_err psp_get_ftpm_capabilties(uint32_t *capabilities); +enum cb_err psp_get_psp_capabilities(uint32_t *capabilities); +enum cb_err psp_get_hsti_state(uint32_t *state); enum cb_err soc_read_c2p38(uint32_t *msg_38_value);
void enable_psp_smi(void); diff --git a/src/soc/amd/common/block/psp/psp_gen2.c b/src/soc/amd/common/block/psp/psp_gen2.c index bed31c1..a587cda 100644 --- a/src/soc/amd/common/block/psp/psp_gen2.c +++ b/src/soc/amd/common/block/psp/psp_gen2.c @@ -177,6 +177,29 @@ return 0; }
+enum cb_err psp_get_psp_capabilities(uint32_t *capabilities) +{ + int cmd_status; + struct mbox_cmd_capability_query_buffer buffer = { + .header = { + .size = sizeof(buffer) + }, + }; + + printk(BIOS_DEBUG, "PSP: Querying PSP capabilities..."); + + cmd_status = send_psp_command(MBOX_BIOS_CMD_PSP_CAPS_QUERY, &buffer); + + /* buffer's status shouldn't change but report it if it does */ + psp_print_cmd_status(cmd_status, &buffer.header); + + if (!cmd_status) + return CB_ERR; + + *capabilities = read32(&buffer.capabilities); + return CB_SUCCESS; +} + enum cb_err soc_read_c2p38(uint32_t *msg_38_value) { const uintptr_t psp_mmio = get_psp_mmio_base();