Skip to contentSkip to conversation

tpm: Fix initialization of a few flags of CRB interface

PATCH In review Stefan Berger 2 participants 7 messages Mar 20, 2018 – Mar 21, 2018

lore
Share & tools
lore
#0 lore raw

v2 cover tpm: Fix initialization of a few flags of CRB interface

Fix the initialization of a few flags of the CRB interface. I tested the changes with UEFI and it works fine. SeaBIOS needs to have the latest patches applied.

Stefan

Stefan Berger (4):
tpm: CRB: Set tpmRegValidSts flag to '1' in device reset
tpm: CRB: set registers to 0 by default
tpm: CRB: reset locAssigned upon relinquishing locality
tpm: CRB: query backend for TPM established flag

 hw/tpm/tpm_crb.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)
Signature · 1 line
2.5.5
#1 lore raw

PATCH v2 1/4 tpm: CRB: Set tpmRegValidSts flag to '1' in device reset

Fix the initialization of the tpmRegValidSts flag and set it to '1' during device reset without expecting a write to another register. This seems to also be the default behavior of real hardware.

---
 hw/tpm/tpm_crb.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
hw/tpm/tpm_crb.c +2 -2
index d8917cb..114b66e 100644
@@ -145,8 +145,6 @@ static void tpm_crb_mmio_write(void *opaque, hwaddr addr,
                              beenSeized, 0);
             ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
                              locAssigned, 1);
-            ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
-                             tpmRegValidSts, 1);
             break;
         }
         break;
@@ -210,6 +208,8 @@ static void tpm_crb_reset(void *dev)
 
     tpm_backend_reset(s->tpmbe);
 
+    ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
+                     tpmRegValidSts, 1);
     ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
                      InterfaceType, CRB_INTF_TYPE_CRB_ACTIVE);
     ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
Signature · 1 line
2.5.5
#2 lore raw

PATCH v2 2/4 tpm: CRB: set registers to 0 by default

In reply to Stefan Berger

Initialize all registers of the CRB device to 0. This clears a few flags upon a reset.

---
 hw/tpm/tpm_crb.c | 2 ++
 1 file changed, 2 insertions(+)
hw/tpm/tpm_crb.c +2 -0
index 114b66e..4bd76b5 100644
@@ -208,6 +208,8 @@ static void tpm_crb_reset(void *dev)
 
     tpm_backend_reset(s->tpmbe);
 
+    memset(s->regs, 0, sizeof(s->regs));
+
     ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
                      tpmRegValidSts, 1);
     ARRAY_FIELD_DP32(s->regs, CRB_INTF_ID,
Signature · 1 line
2.5.5
#3 lore raw

PATCH v2 3/4 tpm: CRB: reset locAssigned upon relinquishing locality

In reply to Stefan Berger
---
 hw/tpm/tpm_crb.c | 2 ++
 1 file changed, 2 insertions(+)
hw/tpm/tpm_crb.c +2 -0
index 4bd76b5..e8c42f6 100644
@@ -137,6 +137,8 @@ static void tpm_crb_mmio_write(void *opaque, hwaddr addr,
             /* not loc 3 or 4 */
             break;
         case CRB_LOC_CTRL_RELINQUISH:
+            ARRAY_FIELD_DP32(s->regs, CRB_LOC_STATE,
+                             locAssigned, 0);
             break;
         case CRB_LOC_CTRL_REQUEST_ACCESS:
             ARRAY_FIELD_DP32(s->regs, CRB_LOC_STS,
Signature · 1 line
2.5.5
#4 lore raw

PATCH v2 4/4 tpm: CRB: query backend for TPM established flag

In reply to Stefan Berger
---
 hw/tpm/tpm_crb.c | 6 ++++++
 1 file changed, 6 insertions(+)
hw/tpm/tpm_crb.c +6 -0
index e8c42f6..ef8b80e 100644
@@ -84,6 +84,12 @@ static uint64_t tpm_crb_mmio_read(void *opaque, hwaddr addr,
     unsigned offset = addr & 3;
     uint32_t val = *(uint32_t *)regs >> (8 * offset);
 
+    switch (addr) {
+    case A_CRB_LOC_STATE:
+        val |= !tpm_backend_get_tpm_established_flag(s->tpmbe);
+        break;
+    }
+
     trace_tpm_crb_mmio_read(addr, size, val);
 
     return val;
Signature · 1 line
2.5.5
Reviewed-by on the v2 series
#5 lore raw
In reply to Stefan Berger

Hi

Quoted 5 lines · Stefan Berger

Fix the initialization of a few flags of the CRB interface. I tested the changes with UEFI and it works fine. SeaBIOS needs to have the latest patches applied.

Stefan

Quoted 8 lines

Stefan Berger (4):
tpm: CRB: Set tpmRegValidSts flag to '1' in device reset
tpm: CRB: set registers to 0 by default
tpm: CRB: reset locAssigned upon relinquishing locality
tpm: CRB: query backend for TPM established flag

 hw/tpm/tpm_crb.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

Series:

For 2.12?
thanks

Signature · 1 line
Marc-André Lureau
#6 lore raw
Quoted 15 lines · Marc-André Lureau

Hi

Quoted 11 lines · Stefan Berger

Fix the initialization of a few flags of the CRB interface. I tested the changes with UEFI and it works fine. SeaBIOS needs to have the latest patches applied.

Stefan

Stefan Berger (4):
tpm: CRB: Set tpmRegValidSts flag to '1' in device reset
tpm: CRB: set registers to 0 by default
tpm: CRB: reset locAssigned upon relinquishing locality
tpm: CRB: query backend for TPM established flag

Quoted 6 lines
Quoted 2 lines
  hw/tpm/tpm_crb.c | 14 ++++++++++++--
  1 file changed, 12 insertions(+), 2 deletions(-)

Series:

For 2.12?

Ideally, yes.

Quoted 3 lines

thanks