[SeaBIOS] [PATCH v2 2/5] tpm: Set timeouts and durations to microsecond values

Stefan Berger stefanb at us.ibm.com
Sat Nov 21 14:32:37 CET 2015


From: Stefan Berger <stefanb at linux.vnet.ibm.com>

Fix the timeouts and durations -- they are provided in microseconds.
Adapt the TPM driver for it.

Get TPM specific timeout and duration values earlier from the device.

Signed-off-by: Stefan Berger <stefanb at linux.vnet.ibm.com>
---
 src/hw/tpm_drivers.c | 11 ++++++-----
 src/hw/tpm_drivers.h | 23 ++++++++++++++---------
 src/tcgbios.c        |  8 ++++----
 3 files changed, 24 insertions(+), 18 deletions(-)

diff --git a/src/hw/tpm_drivers.c b/src/hw/tpm_drivers.c
index 0bf5997..fcf176e 100644
--- a/src/hw/tpm_drivers.c
+++ b/src/hw/tpm_drivers.c
@@ -93,15 +93,16 @@ static u32 tis_wait_sts(u8 locty, u32 time, u8 mask, u8 expect)
         return 0;
 
     u32 rc = 1;
+    u32 ctr = 0;
 
-    while (time > 0) {
+    while (time > ctr) {
         u8 sts = readb(TIS_REG(locty, TIS_REG_STS));
         if ((sts & mask) == expect) {
             rc = 0;
             break;
         }
-        msleep(1);
-        time--;
+        usleep(1000);
+        ctr += 1000;
     }
     return rc;
 }
@@ -188,8 +189,8 @@ static u32 tis_senddata(const u8 *const data, u32 len)
         while (burst == 0 && ctr < timeout_d) {
                burst = readl(TIS_REG(locty, TIS_REG_STS)) >> 8;
             if (burst == 0) {
-                msleep(1);
-                ctr++;
+                usleep(1000);
+                ctr += 1000;
             }
         }
 
diff --git a/src/hw/tpm_drivers.h b/src/hw/tpm_drivers.h
index 6357d02..a8dfebf 100644
--- a/src/hw/tpm_drivers.h
+++ b/src/hw/tpm_drivers.h
@@ -66,12 +66,13 @@ extern struct tpm_driver tpm_drivers[];
 #define TIS_ACCESS_REQUEST_USE         (1 << 1) /* 0x02 */
 #define TIS_ACCESS_TPM_ESTABLISHMENT   (1 << 0) /* 0x01 */
 
-#define SCALER 10
-
-#define TIS_DEFAULT_TIMEOUT_A          (750  * SCALER)
-#define TIS_DEFAULT_TIMEOUT_B          (2000 * SCALER)
-#define TIS_DEFAULT_TIMEOUT_C          (750  * SCALER)
-#define TIS_DEFAULT_TIMEOUT_D          (750  * SCALER)
+/*
+ * Default TIS timeouts used before getting them from the TPM itself
+ */
+#define TIS_DEFAULT_TIMEOUT_A           750 * 1000 /* ms */
+#define TIS_DEFAULT_TIMEOUT_B          2000 * 1000 /* us */
+#define TIS_DEFAULT_TIMEOUT_C           750 * 1000 /* us */
+#define TIS_DEFAULT_TIMEOUT_D           750 * 1000 /* us */
 
 enum tisTimeoutType {
     TIS_TIMEOUT_TYPE_A = 0,
@@ -80,8 +81,12 @@ enum tisTimeoutType {
     TIS_TIMEOUT_TYPE_D,
 };
 
-#define TPM_DEFAULT_DURATION_SHORT     (2000  * SCALER)
-#define TPM_DEFAULT_DURATION_MEDIUM    (20000 * SCALER)
-#define TPM_DEFAULT_DURATION_LONG      (60000 * SCALER)
+/*
+ * Default command durations used before getting them from the
+ * TPM itself
+ */
+#define TPM_DEFAULT_DURATION_SHORT      2000 * 1000 /* us */
+#define TPM_DEFAULT_DURATION_MEDIUM    20000 * 1000 /* us */
+#define TPM_DEFAULT_DURATION_LONG      60000 * 1000 /* us */
 
 #endif /* TPM_DRIVERS_H */
diff --git a/src/tcgbios.c b/src/tcgbios.c
index decf0fd..38bc737 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -459,6 +459,10 @@ tpm_startup(void)
     if (rc || returnCode)
         goto err_exit;
 
+    rc = determine_timeouts();
+    if (rc)
+        goto err_exit;
+
     rc = build_and_send_cmd(0, TPM_ORD_SelfTestFull, NULL, 0,
                             NULL, 0, &returnCode, TPM_DURATION_TYPE_LONG);
 
@@ -477,10 +481,6 @@ tpm_startup(void)
     if (rc || (returnCode != 0 && returnCode != TPM_BAD_LOCALITY))
         goto err_exit;
 
-    rc = determine_timeouts();
-    if (rc)
-        goto err_exit;
-
     rc = tpm_smbios_measure();
     if (rc)
         goto err_exit;
-- 
2.4.3




More information about the SeaBIOS mailing list