From a4bf0b7cd18595d1ff37ccaa53112cb3b94dc512 Mon Sep 17 00:00:00 2001 From: Bill XIE Date: Thu, 22 Mar 2018 17:07:43 +0800 Subject: [PATCH] drivers/pc80/tpm: Add some optional delay to tis_readresponse() Certain TPMs (observed on Infineon SLB9635 installed on revolve 810 g1) seem to need some delay between tis_wait_valid() and tis_has_valid_data(), or tis_has_valid_data() may invalidly return 0, ending the loop immaturely with some bytes left unread, and fail to pass the check below, causing the current command not finalized by tis_command_ready(), and blocking any later tis_wait_ready(). This time the added delay is controlled by a Kconfig option TPM_RDRESP_NEED_DELAY. Change-Id: Ic2a2f252e72a0bbce51e2863f8e46647b1570ba5 Signed-off-by: Bill XIE Reviewed-on: https://review.coreboot.org/25322 Reviewed-by: Paul Menzel Reviewed-by: Philipp Deppenwiese Tested-by: build bot (Jenkins) --- src/drivers/pc80/tpm/Kconfig | 9 +++++++++ src/drivers/pc80/tpm/tis.c | 8 ++++++++ 2 files changed, 17 insertions(+) diff --git a/src/drivers/pc80/tpm/Kconfig b/src/drivers/pc80/tpm/Kconfig index 3bd9083802..879b4a2341 100644 --- a/src/drivers/pc80/tpm/Kconfig +++ b/src/drivers/pc80/tpm/Kconfig @@ -46,3 +46,12 @@ config TPM_DEACTIVATE depends on LPC_TPM help Deactivate TPM by issuing deactivate command. + +config TPM_RDRESP_NEED_DELAY + bool "Enable Delay Workaround for TPM" + default n + depends on LPC_TPM + help + Certain TPMs seem to need some delay when reading response + to work around a race-condition-related issue, possibly + caused by ill-programmed TPM firmware. diff --git a/src/drivers/pc80/tpm/tis.c b/src/drivers/pc80/tpm/tis.c index 9802654ee1..714b7e5ed0 100644 --- a/src/drivers/pc80/tpm/tis.c +++ b/src/drivers/pc80/tpm/tis.c @@ -595,6 +595,14 @@ static u32 tis_readresponse(u8 *buffer, size_t *len) if (offset == expected_count) break; /* We got all we need */ + /* + * Certain TPMs seem to need some delay between tis_wait_valid() + * and tis_has_valid_data(), or some race-condition-related + * issue will occur. + */ + if (IS_ENABLED(CONFIG_TPM_RDRESP_NEED_DELAY)) + udelay(10); + } while (tis_has_valid_data(locality)); /* * Make sure we indeed read all there was. */