aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStephen Douthit <stephend@silicom-usa.com>2018-02-27 14:17:09 -0500
committerKevin O'Connor <kevin@koconnor.net>2018-03-02 10:59:09 -0500
commit559b3e2ba43c80ac02a67903d57ae1acad5dfff1 (patch)
tree9e0be67392bd446001a3df0c78ee3b8742b8b0a5
parent9c6e73b5ebf1f184f96e9ed498a8d1a51512e807 (diff)
downloadseabios-559b3e2ba43c80ac02a67903d57ae1acad5dfff1.tar.gz
tpm: Refactor duplicated wait code in tis_wait_sts() & crb_wait_reg()
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>
-rw-r--r--src/hw/tpm_drivers.c80
1 files changed, 33 insertions, 47 deletions
diff --git a/src/hw/tpm_drivers.c b/src/hw/tpm_drivers.c
index 1fd05e1a..13ad821d 100644
--- a/src/hw/tpm_drivers.c
+++ b/src/hw/tpm_drivers.c
@@ -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)