]> xenbits.xensource.com Git - seabios.git/commitdiff
tpm: Refactor duplicated wait code in tis_wait_sts() & crb_wait_reg()
authorStephen Douthit <stephend@silicom-usa.com>
Tue, 27 Feb 2018 19:17:09 +0000 (14:17 -0500)
committerKevin O'Connor <kevin@koconnor.net>
Fri, 2 Mar 2018 15:59:09 +0000 (10:59 -0500)
Signed-off-by: Stephen Douthit <stephend@silicom-usa.com>
Tested-by: Stephen Douthit <stephend@silicom-usa.com>
Reviewed-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
src/hw/tpm_drivers.c

index 1fd05e1a0c44e838a31775c88d3dc35ff1f157f6..13ad821d4890ce6cbdab64604114180679a161d2 100644 (file)
@@ -63,6 +63,39 @@ static void *crb_cmd;
 static u32 crb_resp_size;
 static void *crb_resp;
 
+static u32 wait_reg8(u8* reg, u32 time, u8 mask, u8 expect)
+{
+    if (!CONFIG_TCGBIOS)
+        return 0;
+
+    u32 rc = 1;
+    u32 end = timer_calc_usec(time);
+
+    for (;;) {
+        u8 value = readl(reg);
+        if ((value & mask) == expect) {
+            rc = 0;
+            break;
+        }
+        if (timer_check(end)) {
+            warn_timeout();
+            break;
+        }
+        yield();
+    }
+    return rc;
+}
+
+static u32 tis_wait_sts(u8 locty, u32 time, u8 mask, u8 expect)
+{
+    return wait_reg8(TIS_REG(locty, TIS_REG_STS), time, mask, expect);
+}
+
+static u32 crb_wait_reg(u8 locty, u16 reg, u32 time, u8 mask, u8 expect)
+{
+    return wait_reg8(CRB_REG(locty, reg), time, mask, expect);
+}
+
 /* if device is not there, return '0', '1' otherwise */
 static u32 tis_probe(void)
 {
@@ -152,30 +185,6 @@ static void set_timeouts(u32 timeouts[4], u32 durations[3])
         memcpy(dus, durations, 3 * sizeof(u32));
 }
 
-
-static u32 tis_wait_sts(u8 locty, u32 time, u8 mask, u8 expect)
-{
-    if (!CONFIG_TCGBIOS)
-        return 0;
-
-    u32 rc = 1;
-    u32 end = timer_calc_usec(time);
-
-    for (;;) {
-        u8 sts = readb(TIS_REG(locty, TIS_REG_STS));
-        if ((sts & mask) == expect) {
-            rc = 0;
-            break;
-        }
-        if (timer_check(end)) {
-            warn_timeout();
-            break;
-        }
-        yield();
-    }
-    return rc;
-}
-
 static u32 tis_activate(u8 locty)
 {
     if (!CONFIG_TCGBIOS)
@@ -399,29 +408,6 @@ static u32 crb_init(void)
     return 0;
 }
 
-static u32 crb_wait_reg(u8 locty, u8 reg, u32 time, u8 mask, u8 expect)
-{
-    if (!CONFIG_TCGBIOS)
-        return 0;
-
-    u32 rc = 1;
-    u32 end = timer_calc_usec(time);
-
-    for (;;) {
-        u8 sts = readl(CRB_REG(locty, reg));
-        if ((sts & mask) == expect) {
-            rc = 0;
-            break;
-        }
-        if (timer_check(end)) {
-            warn_timeout();
-            break;
-        }
-        yield();
-    }
-    return rc;
-}
-
 static u32 crb_activate(u8 locty)
 {
     if (!CONFIG_TCGBIOS)