Yu-Ping Wu has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/71724 )
Change subject: drivers/spi/tpm: Wait for STS_COMMAND_READY ......................................................................
drivers/spi/tpm: Wait for STS_COMMAND_READY
If we reset Ti50 in the middle of a command, it will not become ready for the 1st command after reboot until the TPM app returns the buffer from the previously ongoing command. Therefore, add a loop to retry writing TPM_STS_COMMAND_READY to STS register.
BUG=b:263531882 TEST=emerge-corsola coreboot BRANCH=none
Change-Id: I06fd8f400622f6b9afea520cec19ea962ebe8568 Signed-off-by: Yu-Ping Wu yupingso@chromium.org --- M src/drivers/spi/tpm/tpm.c 1 file changed, 42 insertions(+), 5 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/24/71724/1
diff --git a/src/drivers/spi/tpm/tpm.c b/src/drivers/spi/tpm/tpm.c index 976a8d8..050edd3 100644 --- a/src/drivers/spi/tpm/tpm.c +++ b/src/drivers/spi/tpm/tpm.c @@ -604,6 +604,7 @@ uint8_t *rsp_body = tpm2_response; union fifo_transfer_buffer fifo_buffer; const int HEADER_SIZE = 6; + struct stopwatch sw;
/* Do not try using an uninitialized TPM. */ if (!tpm_info.vendor_id) @@ -622,11 +623,28 @@ return 0; }
- /* Let the TPM know that the command is coming. */ - if (write_tpm_sts(TPM_STS_COMMAND_READY) != CB_SUCCESS) { - printk(BIOS_ERR, "TPM_STS_COMMAND_READY failed\n"); - return 0; - } + /* + * Let the TPM know that the command is coming. + * + * If we reset Ti50 in the middle of a command, it will not become ready for the 1st + * command after reboot until the TPM app returns the buffer from the previously ongoing + * command. + */ + expected_status_bits = TPM_STS_VALID | TPM_STS_COMMAND_READY; + stopwatch_init_usecs_expire(&sw, 1000); + status = 0; + do { + enum cb_err ret = write_tpm_sts(TPM_STS_COMMAND_READY); + udelay(10); + if (ret == CB_SUCCESS) + read_tpm_sts(&status); + else + printk(BIOS_WARNING, "failed to write TPM_STS_COMMAND_READY\n"); + if (stopwatch_expired(&sw)) { + printk(BIOS_ERR, "timeout waiting for TPM_STS_COMMAND_READY\n"); + return 0; + } + } while (!(status & expected_status_bits));
/* * TPM commands and responses written to and read from the FIFO