[SeaBIOS] [PATCH 1/3] tpm: Refactor duplicated wait code in tis_wait_sts() & crb_wait_reg()

Stephen Douthit posted 3 patches 7 years, 2 months ago
[SeaBIOS] [PATCH 1/3] tpm: Refactor duplicated wait code in tis_wait_sts() & crb_wait_reg()
Posted by Stephen Douthit 7 years, 2 months ago
Signed-off-by: Stephen Douthit <stephend@silicom-usa.com>
Tested-by: Stephen Douthit <stephend@silicom-usa.com>
---
 src/hw/tpm_drivers.c | 80 ++++++++++++++++++++++------------------------------
 1 file changed, 33 insertions(+), 47 deletions(-)

diff --git a/src/hw/tpm_drivers.c b/src/hw/tpm_drivers.c
index 1fd05e1..8d6fc33 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 sts = readl(reg);
+        if ((sts & 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)
-- 
2.14.3


_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH 1/3] tpm: Refactor duplicated wait code in tis_wait_sts() & crb_wait_reg()
Posted by Stefan Berger 7 years, 2 months ago
On 02/26/2018 03:37 PM, Stephen Douthit wrote:
> Signed-off-by: Stephen Douthit <stephend@silicom-usa.com>
> Tested-by: Stephen Douthit <stephend@silicom-usa.com>
> ---
>   src/hw/tpm_drivers.c | 80 ++++++++++++++++++++++------------------------------
>   1 file changed, 33 insertions(+), 47 deletions(-)
>
> diff --git a/src/hw/tpm_drivers.c b/src/hw/tpm_drivers.c
> index 1fd05e1..8d6fc33 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 sts = readl(reg);

Nit: call this 'value' instead since it has nothing to do anymore with 
the REG_STS below.

> +        if ((sts & 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)



_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH 1/3] tpm: Refactor duplicated wait code in tis_wait_sts() & crb_wait_reg()
Posted by Stephen Douthit 7 years, 2 months ago
On 02/26/2018 05:35 PM, Stefan Berger wrote:
> On 02/26/2018 03:37 PM, Stephen Douthit wrote:
>> Signed-off-by: Stephen Douthit <stephend@silicom-usa.com>
>> Tested-by: Stephen Douthit <stephend@silicom-usa.com>
>> ---
>>   src/hw/tpm_drivers.c | 80 ++++++++++++++++++++++------------------------------
>>   1 file changed, 33 insertions(+), 47 deletions(-)
>>
>> diff --git a/src/hw/tpm_drivers.c b/src/hw/tpm_drivers.c
>> index 1fd05e1..8d6fc33 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 sts = readl(reg);
> 
> Nit: call this 'value' instead since it has nothing to do anymore with the REG_STS below.

Will do.

>> +        if ((sts & 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)
> 
> 


_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios