Werner Zeh has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/58240 )
Change subject: drivers/pc80/tpm: Use stopwatch for timeout-loops ......................................................................
drivers/pc80/tpm: Use stopwatch for timeout-loops
There are manual timeout-loops which use a fixed value and udelay(). In all cases there is a debug printk() inside this loop which, when enabled, takes way longer than the counted microsecond delay. This leads to the result that e.g. a 1 second delay takes nearly an eternity if the debug messages are enabled due to the longer function execution time.
This patch uses the stopwatch scheme for the timeout-loops which still makes sure that the timeout period is maintained while it takes longer function calls like printk() into account.
TEST=Enable TPM debug messages on a board where the TPM hits a timeout by failure and make sure that the debug messages occur in the log just in the timeout period.
Change-Id: I8fd261c9d60a9a60509c847dbc4983bc05f41d48 Signed-off-by: Werner Zeh werner.zeh@siemens.com --- M src/drivers/pc80/tpm/tis.c 1 file changed, 13 insertions(+), 13 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/40/58240/1
diff --git a/src/drivers/pc80/tpm/tis.c b/src/drivers/pc80/tpm/tis.c index 2b29acf..d3ba221 100644 --- a/src/drivers/pc80/tpm/tis.c +++ b/src/drivers/pc80/tpm/tis.c @@ -22,6 +22,7 @@ #include <security/tpm/tis.h> #include <device/pnp.h> #include <drivers/tpm/tpm_ppi.h> +#include <timer.h> #include "chip.h"
#define PREFIX "lpc_tpm: " @@ -249,13 +250,13 @@ */ static int tis_wait_sts(int locality, u8 mask, u8 expected) { - u32 time_us = MAX_DELAY_US; - while (time_us > 0) { + struct stopwatch sw; + + stopwatch_init_usecs_expire(&sw, MAX_DELAY_US); + while (!stopwatch_expired(&sw)) { u8 value = tpm_read_status(locality); if ((value & mask) == expected) return 0; - udelay(1); /* 1 us */ - time_us--; } return TPM_TIMEOUT_ERR; } @@ -302,13 +303,13 @@ */ static int tis_wait_access(int locality, u8 mask, u8 expected) { - u32 time_us = MAX_DELAY_US; - while (time_us > 0) { + struct stopwatch sw; + + stopwatch_init_usecs_expire(&sw, MAX_DELAY_US); + while (!stopwatch_expired(&sw)) { u8 value = tpm_read_access(locality); if ((value & mask) == expected) return 0; - udelay(1); /* 1 us */ - time_us--; } return TPM_TIMEOUT_ERR; } @@ -440,7 +441,6 @@ { u32 offset = 0; u16 burst = 0; - u32 max_cycles = 0; u8 locality = 0;
if (tis_wait_ready(locality)) { @@ -452,20 +452,20 @@
while (1) { unsigned int count; + struct stopwatch sw; + + stopwatch_init_usecs_expire(&sw, MAX_DELAY_US);
/* Wait till the device is ready to accept more data. */ while (!burst) { - if (max_cycles++ == MAX_DELAY_US) { + if (stopwatch_expired(&sw)) { printf("%s:%d failed to feed %d bytes of %d\n", __FILE__, __LINE__, len - offset, len); return TPM_DRIVER_ERR; } - udelay(1); burst = tpm_read_burst_count(locality); }
- max_cycles = 0; - /* * Calculate number of bytes the TPM is ready to accept in one * shot.