]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Set timeouts and durations to microsecond values
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Sat, 21 Nov 2015 19:54:41 +0000 (14:54 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Sun, 22 Nov 2015 15:12:34 +0000 (10:12 -0500)
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@linux.vnet.ibm.com>
src/hw/tpm_drivers.c
src/hw/tpm_drivers.h
src/tcgbios.c

index 0bf5997721622e43ef480e1d908967a4cffb6067..093279763815914f5254be3cd0ff44479fe37d73 100644 (file)
 #include "config.h" // CONFIG_TPM_TIS_SHA1THRESHOLD
 #include "hw/tpm_drivers.h" // struct tpm_driver
 #include "std/tcg.h" // TCG_NO_RESPONSE
+#include "output.h" // warn_timeout
+#include "stacks.h" // yield
 #include "string.h" // memcpy
-#include "util.h" // msleep
+#include "util.h" // timer_calc_usec
 #include "x86.h" // readl
 
 static const u32 tis_default_timeouts[4] = {
@@ -93,15 +95,19 @@ static u32 tis_wait_sts(u8 locty, u32 time, u8 mask, u8 expect)
         return 0;
 
     u32 rc = 1;
+    u32 end = timer_calc_usec(time);
 
-    while (time > 0) {
+    for (;;) {
         u8 sts = readb(TIS_REG(locty, TIS_REG_STS));
         if ((sts & mask) == expect) {
             rc = 0;
             break;
         }
-        msleep(1);
-        time--;
+        if (timer_check(end)) {
+            warn_timeout();
+            break;
+        }
+        yield();
     }
     return rc;
 }
@@ -178,18 +184,21 @@ static u32 tis_senddata(const u8 *const data, u32 len)
 
     u32 rc = 0;
     u32 offset = 0;
-    u32 end = 0;
+    u32 end_loop = 0;
     u16 burst = 0;
-    u32 ctr = 0;
     u8 locty = tis_find_active_locality();
     u32 timeout_d = tpm_drivers[TIS_DRIVER_IDX].timeouts[TIS_TIMEOUT_TYPE_D];
+    u32 end = timer_calc_usec(timeout_d);
 
     do {
-        while (burst == 0 && ctr < timeout_d) {
+        while (burst == 0) {
                burst = readl(TIS_REG(locty, TIS_REG_STS)) >> 8;
             if (burst == 0) {
-                msleep(1);
-                ctr++;
+                if (timer_check(end)) {
+                    warn_timeout();
+                    break;
+                }
+                yield();
             }
         }
 
@@ -207,8 +216,8 @@ static u32 tis_senddata(const u8 *const data, u32 len)
         }
 
         if (offset == len)
-            end = 1;
-    } while (end == 0);
+            end_loop = 1;
+    } while (end_loop == 0);
 
     return rc;
 }
index 6357d02a5c2d904437fb29dcd92a4076288a441f..ec50cca0d3af7420fd0740af1daae4fb855fb21e 100644 (file)
@@ -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           750000 /* us */
+#define TIS_DEFAULT_TIMEOUT_B          2000000 /* us */
+#define TIS_DEFAULT_TIMEOUT_C           750000 /* us */
+#define TIS_DEFAULT_TIMEOUT_D           750000 /* 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      2000000 /* us */
+#define TPM_DEFAULT_DURATION_MEDIUM    20000000 /* us */
+#define TPM_DEFAULT_DURATION_LONG      60000000 /* us */
 
 #endif /* TPM_DRIVERS_H */
index decf0fd4e2b62f443708d0c3f038735987776dec..38bc73768252d0502d03b193186705e922fbec7a 100644 (file)
@@ -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;