[SeaBIOS] [PATCH] tpm: Add support for TPM2 ACPI table

Stefan Berger posted 1 patch 6 years, 5 months ago
Patches applied successfully (tree, apply log)
git fetch https://github.com/patchew-project/seabios tags/patchew/1510689827-3441-1-git-send-email-stefanb@linux.vnet.ibm.com
src/std/acpi.h | 13 +++++++++++++
src/tcgbios.c  | 52 +++++++++++++++++++++++++++++++++++++++++-----------
2 files changed, 54 insertions(+), 11 deletions(-)
[SeaBIOS] [PATCH] tpm: Add support for TPM2 ACPI table
Posted by Stefan Berger 6 years, 5 months ago
Add support for the TPM2 ACPI table. If we find it and its
of the appropriate size, we can get the log_area_start_address
and log_area_minimum_size from it.

The latest version of the spec can be found here:

https://trustedcomputinggroup.org/tcg-acpi-specification/

Signed-off-by: Stefan Berger <stefanb@linux.vnet.ibm.com>
---
 src/std/acpi.h | 13 +++++++++++++
 src/tcgbios.c  | 52 +++++++++++++++++++++++++++++++++++++++++-----------
 2 files changed, 54 insertions(+), 11 deletions(-)

diff --git a/src/std/acpi.h b/src/std/acpi.h
index c2ea707..c01fa7b 100644
--- a/src/std/acpi.h
+++ b/src/std/acpi.h
@@ -307,4 +307,17 @@ struct tcpa_descriptor_rev2
 #define TCPA_ACPI_CLASS_CLIENT          0
 #define TCPA_ACPI_CLASS_SERVER          1
 
+#define TPM2_SIGNATURE 0x324D5054
+struct tpm2_descriptor_rev2
+{
+    ACPI_TABLE_HEADER_DEF
+    u16  platform_class;
+    u16  reserved;
+    u64  address_of_control_area;
+    u32  start_method;
+    u8   start_method_params[12];
+    u32  log_area_minimum_length;
+    u64  log_area_start_address;
+} PACKED;
+
 #endif // acpi.h
diff --git a/src/tcgbios.c b/src/tcgbios.c
index 151707b..9348a23 100644
--- a/src/tcgbios.c
+++ b/src/tcgbios.c
@@ -48,15 +48,9 @@ struct {
     u8 *          log_area_last_entry;
 } tpm_state VARLOW;
 
-static int
-tpm_tcpa_probe(void)
+static int tpm_set_log_area(u8 *log_area_start_address,
+                            u32 log_area_minimum_length)
 {
-    struct tcpa_descriptor_rev2 *tcpa = find_acpi_table(TCPA_SIGNATURE);
-    if (!tcpa)
-        return -1;
-
-    u8 *log_area_start_address = (u8*)(long)tcpa->log_area_start_address;
-    u32 log_area_minimum_length = tcpa->log_area_minimum_length;
     if (!log_area_start_address || !log_area_minimum_length)
         return -1;
 
@@ -69,6 +63,39 @@ tpm_tcpa_probe(void)
     return 0;
 }
 
+static int
+tpm_tcpa_probe(void)
+{
+    struct tcpa_descriptor_rev2 *tcpa = find_acpi_table(TCPA_SIGNATURE);
+    if (!tcpa)
+        return -1;
+
+    dprintf(DEBUG_tcg, "TCGBIOS: TCPA: LASA = %p, LAML = %u\n",
+            (u8 *)(long)tcpa->log_area_start_address,
+            tcpa->log_area_minimum_length);
+
+    return tpm_set_log_area((u8*)(long)tcpa->log_area_start_address,
+                            tcpa->log_area_minimum_length);
+}
+
+static int
+tpm_tpm2_probe(void)
+{
+    struct tpm2_descriptor_rev2 *tpm2 = find_acpi_table(TPM2_SIGNATURE);
+    if (!tpm2)
+        return -1;
+
+    if (tpm2->length < 76)
+        return -1;
+
+    dprintf(DEBUG_tcg, "TCGBIOS: TPM2: LASA = %p, LAML = %u\n",
+            (u8 *)(long)tpm2->log_area_start_address,
+            tpm2->log_area_minimum_length);
+
+    return tpm_set_log_area((u8*)(long)tpm2->log_area_start_address,
+                            tpm2->log_area_minimum_length);
+}
+
 /*
  * Extend the ACPI log with the given entry by copying the
  * entry data into the log.
@@ -949,9 +976,12 @@ tpm_setup(void)
             "TCGBIOS: Detected a TPM %s.\n",
              (TPM_version == TPM_VERSION_1_2) ? "1.2" : "2");
 
-    int ret = tpm_tcpa_probe();
-    if (ret)
-        return;
+    int ret = tpm_tpm2_probe();
+    if (ret) {
+        ret = tpm_tcpa_probe();
+        if (ret)
+            return;
+    }
 
     TPM_working = 1;
 
-- 
2.5.5


_______________________________________________
SeaBIOS mailing list
SeaBIOS@seabios.org
https://mail.coreboot.org/mailman/listinfo/seabios
Re: [SeaBIOS] [PATCH] tpm: Add support for TPM2 ACPI table
Posted by Kevin O'Connor 6 years, 5 months ago
On Tue, Nov 14, 2017 at 03:03:47PM -0500, Stefan Berger wrote:
> Add support for the TPM2 ACPI table. If we find it and its
> of the appropriate size, we can get the log_area_start_address
> and log_area_minimum_size from it.
> 
> The latest version of the spec can be found here:
> 
> https://trustedcomputinggroup.org/tcg-acpi-specification/

Thanks.  I committed this patch.

-Kevin

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