Skip to contentSkip to conversation

vTPM/aarch64 ACPI support

PATCH Superseded Eric Auger 7 participants 21 messages May 5, 2020 – May 14, 2020

v2 of 7 Superseded Latest is v7 →

lore
Share & tools
lore

Eric Auger

author
#0 lore raw

v2 cover vTPM/aarch64 ACPI support

Those patches bring MMIO TPM TIS ACPI support in machvirt. The first patch moves the TPM2 ACPI table generation code in the generic code. Then the table is added if the TPM2 sysbus device is dynamically instantiated in machvirt. Also the TPM2 device object is described in the DSDT.

Many thanks to Ard for his support.

Tested with LUKS partition automatic decryption.

Best Regards

Eric

This series can be found at:
https://github.com/eauger/qemu/tree/v5.0-tpm-acpi-v2

History:
v1 -> v2:
- move build_tpm2() in the generic code (Michael)
- collect Stefan's R-b on 3/3

Eric Auger (3):
acpi: Move build_tpm2() in the generic part arm/acpi: TPM2 ACPI table support
arm/acpi: Add the TPM2.0 device under the DSDT

 include/hw/acpi/aml-build.h |  2 ++
 include/sysemu/tpm.h        |  2 ++
 hw/acpi/aml-build.c         | 31 ++++++++++++++++++++++++
 hw/arm/virt-acpi-build.c    | 47 +++++++++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 30 -----------------------
 5 files changed, 82 insertions(+), 30 deletions(-)
Signature · 1 line
2.20.1
author
#1 lore raw

PATCH v2 1/3 acpi: Move build_tpm2() in the generic part

We plan to build the tpm2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.

No change in the implementation.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 30 ++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 30 ------------------------------
 3 files changed, 32 insertions(+), 30 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0f4ed53d7f..a67ab4618a 100644
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 
 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
                 const char *oem_id, const char *oem_table_id);
+
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog);
 #endif
hw/acpi/aml-build.c +30 -0
index 2c3702b882..1f7fd09112 100644
@@ -26,6 +26,7 @@
 #include "qemu/bitops.h"
 #include "sysemu/numa.h"
 #include "hw/boards.h"
+#include "hw/acpi/tpm.h"
 
 static GArray *build_alloc_array(void)
 {
@@ -1875,6 +1876,35 @@ build_hdr:
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
 
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
+{
+    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
+    unsigned log_addr_offset =
+        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    if (TPM_IS_TIS_ISA(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(0);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+    } else if (TPM_IS_CRB(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
+    } else {
+        g_warn_if_reached();
+    }
+
+    tpm2_ptr->log_area_minimum_length =
+        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+
+    /* log area start address to be filled by Guest linker */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                   log_addr_offset, log_addr_size,
+                                   ACPI_BUILD_TPMLOG_FILE, 0);
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+}
+
 /* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */
 static Aml *aml_serial_bus_device(uint8_t serial_bus_type, uint8_t flags,
                                   uint16_t type_flags,
hw/i386/acpi-build.c +0 -30
index 23c77eeb95..c7c560e269 100644
@@ -2296,36 +2296,6 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
                  (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL, NULL);
 }
 
-static void
-build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
-{
-    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
-    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
-    unsigned log_addr_offset =
-        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
-
-    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
-    if (TPM_IS_TIS_ISA(tpm_find())) {
-        tpm2_ptr->control_area_address = cpu_to_le64(0);
-        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
-    } else if (TPM_IS_CRB(tpm_find())) {
-        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
-        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
-    } else {
-        g_warn_if_reached();
-    }
-
-    tpm2_ptr->log_area_minimum_length =
-        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
-
-    /* log area start address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
-                                   log_addr_offset, log_addr_size,
-                                   ACPI_BUILD_TPMLOG_FILE, 0);
-    build_header(linker, table_data,
-                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
-}
-
 #define HOLE_640K_START  (640 * KiB)
 #define HOLE_640K_END   (1 * MiB)
 
Signature · 1 line
2.20.1
Reviewed-by on v2 1/3
#2 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Quoted 6 lines · Eric Auger

We plan to build the tpm2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.

No change in the implementation.

Quoted 106 lines
---
  include/hw/acpi/aml-build.h |  2 ++
  hw/acpi/aml-build.c         | 30 ++++++++++++++++++++++++++++++
  hw/i386/acpi-build.c        | 30 ------------------------------
  3 files changed, 32 insertions(+), 30 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0f4ed53d7f..a67ab4618a 100644
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 
  void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
                  const char *oem_id, const char *oem_table_id);
+
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog);
  #endif
hw/acpi/aml-build.c +30 -0
index 2c3702b882..1f7fd09112 100644
@@ -26,6 +26,7 @@
  #include "qemu/bitops.h"
  #include "sysemu/numa.h"
  #include "hw/boards.h"
+#include "hw/acpi/tpm.h"
 
  static GArray *build_alloc_array(void)
  {
@@ -1875,6 +1876,35 @@ build_hdr:
                   "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
  }
 
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
+{
+    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
+    unsigned log_addr_offset =
+        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    if (TPM_IS_TIS_ISA(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(0);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+    } else if (TPM_IS_CRB(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
+    } else {
+        g_warn_if_reached();
+    }
+
+    tpm2_ptr->log_area_minimum_length =
+        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+
+    /* log area start address to be filled by Guest linker */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                   log_addr_offset, log_addr_size,
+                                   ACPI_BUILD_TPMLOG_FILE, 0);
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+}
+
  /* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */
  static Aml *aml_serial_bus_device(uint8_t serial_bus_type, uint8_t flags,
                                    uint16_t type_flags,
hw/i386/acpi-build.c +0 -30
index 23c77eeb95..c7c560e269 100644
@@ -2296,36 +2296,6 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
                   (void *)tcpa, "TCPA", sizeof(*tcpa), 2, NULL, NULL);
  }
 
-static void
-build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
-{
-    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
-    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
-    unsigned log_addr_offset =
-        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
-
-    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
-    if (TPM_IS_TIS_ISA(tpm_find())) {
-        tpm2_ptr->control_area_address = cpu_to_le64(0);
-        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
-    } else if (TPM_IS_CRB(tpm_find())) {
-        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
-        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
-    } else {
-        g_warn_if_reached();
-    }
-
-    tpm2_ptr->log_area_minimum_length =
-        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
-
-    /* log area start address to be filled by Guest linker */
-    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
-                                   log_addr_offset, log_addr_size,
-                                   ACPI_BUILD_TPMLOG_FILE, 0);
-    build_header(linker, table_data,
-                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
-}
-
  #define HOLE_640K_START  (640 * KiB)
  #define HOLE_640K_END   (1 * MiB)
 
#3 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

In reply to Eric Auger
Quoted 58 lines · Eric Auger

We plan to build the tpm2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.

No change in the implementation.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 30 ++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 30 ------------------------------
 3 files changed, 32 insertions(+), 30 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0f4ed53d7f..a67ab4618a 100644
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 
 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
                 const char *oem_id, const char *oem_table_id);
+
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog);
 #endif
hw/acpi/aml-build.c +20 -0
index 2c3702b882..1f7fd09112 100644
@@ -26,6 +26,7 @@
 #include "qemu/bitops.h"
 #include "sysemu/numa.h"
 #include "hw/boards.h"
+#include "hw/acpi/tpm.h"
 
 static GArray *build_alloc_array(void)
 {
@@ -1875,6 +1876,35 @@ build_hdr:
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
 
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
+{
+    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
+    unsigned log_addr_offset =
+        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    if (TPM_IS_TIS_ISA(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(0);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+    } else if (TPM_IS_CRB(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
+    } else {
+        g_warn_if_reached();
+    }
+
+    tpm2_ptr->log_area_minimum_length =

hw/acpi/aml-build.c build_hdr: · line 1907

Quoted 10 lines
hw/acpi/aml-build.c +10 -0
+        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+
+    /* log area start address to be filled by Guest linker */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                   log_addr_offset, log_addr_size,
+                                   ACPI_BUILD_TPMLOG_FILE, 0);
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+}
+

I'll let Igor and mst confirm/deny this, but my understanding was that the build_append* API was the preferred way to create the table. Indeed, I don't see too many table.field = cpu_to_le(...) lines in aml-build.c

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

Thanks,
drew

author
#4 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Hi,

Quoted 74 lines · Andrew Jones
Quoted 58 lines · Eric Auger

We plan to build the tpm2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.

No change in the implementation.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 30 ++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 30 ------------------------------
 3 files changed, 32 insertions(+), 30 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0f4ed53d7f..a67ab4618a 100644
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 
 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
                 const char *oem_id, const char *oem_table_id);
+
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog);
 #endif
hw/acpi/aml-build.c +20 -0
index 2c3702b882..1f7fd09112 100644
@@ -26,6 +26,7 @@
 #include "qemu/bitops.h"
 #include "sysemu/numa.h"
 #include "hw/boards.h"
+#include "hw/acpi/tpm.h"
 
 static GArray *build_alloc_array(void)
 {
@@ -1875,6 +1876,35 @@ build_hdr:
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
 
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
+{
+    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
+    unsigned log_addr_offset =
+        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    if (TPM_IS_TIS_ISA(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(0);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+    } else if (TPM_IS_CRB(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
+    } else {
+        g_warn_if_reached();
+    }
+
+    tpm2_ptr->log_area_minimum_length =

hw/acpi/aml-build.c build_hdr: · line 1907

Quoted 10 lines
hw/acpi/aml-build.c +10 -0
+        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+
+    /* log area start address to be filled by Guest linker */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                   log_addr_offset, log_addr_size,
+                                   ACPI_BUILD_TPMLOG_FILE, 0);
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+}
+

I'll let Igor and mst confirm/deny this, but my understanding was that the build_append* API was the preferred way to create the table. Indeed, I don't see too many table.field = cpu_to_le(...) lines in aml-build.c

Quoted 2 lines

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

The reason I did not convert is that the struct is as follows

struct Acpi20TPM2 {
    ACPI_TABLE_HEADER_DEF
    uint16_t platform_class;
    uint16_t reserved;
    uint64_t control_area_address;
    uint32_t start_method;
    uint8_t start_method_params[12];
    uint32_t log_area_minimum_length;
    uint64_t log_area_start_address;
} QEMU_PACKED;

If I understand correctly the build_append* adds the fields contiguously. It was not straightforward to me how to skip the start_method_params array.

While we are at it the tcpalog arg is not used. Shall I remove it?

Thanks

Eric

Quoted 5 lines

Thanks,
drew

#5 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Quoted 94 lines · On Wed, 6 May 2020 11:50:09 +0200 Auger Eric <[email protected]> wrote:

Hi,

Quoted 74 lines · Andrew Jones
Quoted 58 lines · Eric Auger

We plan to build the tpm2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.

No change in the implementation.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 30 ++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 30 ------------------------------
 3 files changed, 32 insertions(+), 30 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0f4ed53d7f..a67ab4618a 100644
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 
 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
                 const char *oem_id, const char *oem_table_id);
+
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog);
 #endif
hw/acpi/aml-build.c +20 -0
index 2c3702b882..1f7fd09112 100644
@@ -26,6 +26,7 @@
 #include "qemu/bitops.h"
 #include "sysemu/numa.h"
 #include "hw/boards.h"
+#include "hw/acpi/tpm.h"
 
 static GArray *build_alloc_array(void)
 {
@@ -1875,6 +1876,35 @@ build_hdr:
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
 
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
+{
+    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
+    unsigned log_addr_offset =
+        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    if (TPM_IS_TIS_ISA(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(0);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+    } else if (TPM_IS_CRB(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
+    } else {
+        g_warn_if_reached();
+    }
+
+    tpm2_ptr->log_area_minimum_length =

hw/acpi/aml-build.c build_hdr: · line 1907

Quoted 10 lines
hw/acpi/aml-build.c +10 -0
+        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+
+    /* log area start address to be filled by Guest linker */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                   log_addr_offset, log_addr_size,
+                                   ACPI_BUILD_TPMLOG_FILE, 0);
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+}
+  

I'll let Igor and mst confirm/deny this, but my understanding was that the build_append* API was the preferred way to create the table. Indeed, I don't see too many table.field = cpu_to_le(...) lines in aml-build.c

Quoted 2 lines

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

The reason I did not convert is that the struct is as follows

struct Acpi20TPM2 {
    ACPI_TABLE_HEADER_DEF
    uint16_t platform_class;
    uint16_t reserved;
    uint64_t control_area_address;
    uint32_t start_method;
    uint8_t start_method_params[12];
    uint32_t log_area_minimum_length;
    uint64_t log_area_start_address;
} QEMU_PACKED;
Quoted 3 lines

If I understand correctly the build_append* adds the fields contiguously. It was not straightforward to me how to skip the start_method_params array.

you can use g_array_append_vals() for adding byte array (even is it's all zeros)

Quoted 11 lines

While we are at it the tcpalog arg is not used. Shall I remove it?

Thanks

Eric

Quoted 5 lines

Thanks,
drew

author
#6 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Hi Igor,

Quoted 97 lines · Igor Mammedov
Quoted 94 lines · On Wed, 6 May 2020 11:50:09 +0200 Auger Eric <[email protected]> wrote:

Hi,

Quoted 74 lines · Andrew Jones
Quoted 58 lines · Eric Auger

We plan to build the tpm2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.

No change in the implementation.

---
 include/hw/acpi/aml-build.h |  2 ++
 hw/acpi/aml-build.c         | 30 ++++++++++++++++++++++++++++++
 hw/i386/acpi-build.c        | 30 ------------------------------
 3 files changed, 32 insertions(+), 30 deletions(-)
include/hw/acpi/aml-build.h +2 -0
index 0f4ed53d7f..a67ab4618a 100644
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);
 
 void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
                 const char *oem_id, const char *oem_table_id);
+
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog);
 #endif
hw/acpi/aml-build.c +20 -0
index 2c3702b882..1f7fd09112 100644
@@ -26,6 +26,7 @@
 #include "qemu/bitops.h"
 #include "sysemu/numa.h"
 #include "hw/boards.h"
+#include "hw/acpi/tpm.h"
 
 static GArray *build_alloc_array(void)
 {
@@ -1875,6 +1876,35 @@ build_hdr:
                  "FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
 }
 
+void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
+{
+    Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+    unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
+    unsigned log_addr_offset =
+        (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    if (TPM_IS_TIS_ISA(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(0);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+    } else if (TPM_IS_CRB(tpm_find())) {
+        tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
+        tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
+    } else {
+        g_warn_if_reached();
+    }
+
+    tpm2_ptr->log_area_minimum_length =

hw/acpi/aml-build.c build_hdr: · line 1907

Quoted 10 lines
hw/acpi/aml-build.c +10 -0
+        cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+
+    /* log area start address to be filled by Guest linker */
+    bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
+                                   log_addr_offset, log_addr_size,
+                                   ACPI_BUILD_TPMLOG_FILE, 0);
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
+}
+  

I'll let Igor and mst confirm/deny this, but my understanding was that the build_append* API was the preferred way to create the table. Indeed, I don't see too many table.field = cpu_to_le(...) lines in aml-build.c

Quoted 2 lines

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

The reason I did not convert is that the struct is as follows

struct Acpi20TPM2 {
    ACPI_TABLE_HEADER_DEF
    uint16_t platform_class;
    uint16_t reserved;
    uint64_t control_area_address;
    uint32_t start_method;
    uint8_t start_method_params[12];
    uint32_t log_area_minimum_length;
    uint64_t log_area_start_address;
} QEMU_PACKED;
Quoted 5 lines
Quoted 3 lines

If I understand correctly the build_append* adds the fields contiguously. It was not straightforward to me how to skip the start_method_params array.

you can use g_array_append_vals() for adding byte array (even is it's all zeros)

OK I will do.

Thank you for your input.

Eric

Quoted 14 lines
Quoted 12 lines

While we are at it the tcpalog arg is not used. Shall I remove it?

Thanks

Eric

Quoted 5 lines

Thanks,
drew

#7 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

In reply to Andrew Jones
Quoted 2 lines · Andrew Jones

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

I'd rather refactoring was done in a separate patch - easier to review.

Signature · 1 line
MST
#8 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Quoted 6 lines · On Wed, 6 May 2020 05:58:25 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Andrew Jones

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

I'd rather refactoring was done in a separate patch - easier to review.

maybe first convert and then move

PS:
me wonders if we have test with TPM enabled, if not maybe it's time to add them i.e. first goes testcase in bios-tables and then refactoring/moving in that case review is simpler.

author
#9 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Hi Igor,

Quoted 7 lines · Igor Mammedov
Quoted 4 lines · On Wed, 6 May 2020 05:58:25 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Andrew Jones

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

Quoted 8 lines
Quoted 2 lines

I'd rather refactoring was done in a separate patch - easier to review.

maybe first convert and then move

PS:
me wonders if we have test with TPM enabled, if not maybe it's time to add them i.e. first goes testcase in bios-tables and then refactoring/moving in that case review is simpler.

Do you mean tests checking the ACPI table content when TPM is instantiated? I don't think so otherwise it would have failed I guess. Otherwise we have functional tests with TPM (MMIO access), ie qtest tests tpm-tis-device-test and tpm-tis-device-swtpm-test.

Thanks

Eric

Quoted 2 lines
#10 lore raw

Re: [PATCH v2 1/3] acpi: Move build_tpm2() in the generic part

Quoted 12 lines · On Tue, 12 May 2020 17:59:25 +0200 Auger Eric <[email protected]> wrote:

Hi Igor,

Quoted 9 lines · Igor Mammedov
Quoted 6 lines · On Wed, 6 May 2020 05:58:25 -0400 "Michael S. Tsirkin" <[email protected]> wrote:
Quoted 2 lines · Andrew Jones

I realize this function is just getting moved, but maybe it should get converted to the build_append* API while being moved?

I'd rather refactoring was done in a separate patch - easier to review.

Quoted 8 lines
Quoted 6 lines

maybe first convert and then move

PS:
me wonders if we have test with TPM enabled, if not maybe it's time to add them i.e. first goes testcase in bios-tables and then refactoring/moving in that case review is simpler.

Do you mean tests checking the ACPI table content when TPM is instantiated? I don't think so otherwise it would have failed I guess.

yes, I've meant that.

Quoted 8 lines

Otherwise we have functional tests with TPM (MMIO access), ie qtest tests tpm-tis-device-test and tpm-tis-device-swtpm-test.

Thanks

Eric

Quoted 2 lines
author
#11 lore raw

PATCH v2 2/3 arm/acpi: TPM2 ACPI table support

In reply to Eric Auger

Add a TPM2 ACPI table if a TPM2.0 sysbus device has been dynamically instantiated.

---

v1 -> v2:
- reuse generic build_tpm2() and alloc log area externally
- call tpm_find() once in build_tpm2()

---
 include/sysemu/tpm.h     |  2 ++
 hw/acpi/aml-build.c      |  5 +++--
 hw/arm/virt-acpi-build.c | 11 +++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
include/sysemu/tpm.h +2 -0
index f37851b1aa..03fb25941c 100644
@@ -50,6 +50,8 @@ typedef struct TPMIfClass {
 
 #define TPM_IS_TIS_ISA(chr)                         \
     object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
+#define TPM_IS_TIS_SYSBUS(chr)                      \
+    object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
 #define TPM_IS_CRB(chr)                             \
     object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
 #define TPM_IS_SPAPR(chr)                           \
hw/acpi/aml-build.c +3 -2
index 1f7fd09112..4224675cb2 100644
@@ -1882,12 +1882,13 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
     unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
     unsigned log_addr_offset =
         (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+    TPMIf *tpmif = tpm_find();
 
     tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
-    if (TPM_IS_TIS_ISA(tpm_find())) {
+    if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
         tpm2_ptr->control_area_address = cpu_to_le64(0);
         tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
-    } else if (TPM_IS_CRB(tpm_find())) {
+    } else if (TPM_IS_CRB(tpmif)) {
         tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
         tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
     } else {
hw/arm/virt-acpi-build.c +11 -0
index 81d41a3990..1a2ec10c8f 100644
@@ -41,11 +41,13 @@
 #include "hw/acpi/pci.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/generic_event_device.h"
+#include "hw/acpi/tpm.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
+#include "sysemu/tpm.h"
 #include "kvm_arm.h"
 #include "migration/vmstate.h"
 
@@ -831,6 +833,15 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
         build_iort(tables_blob, tables->linker, vms);
     }
 
+    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
+        acpi_data_push(tables->tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
+        bios_linker_loader_alloc(tables->linker, ACPI_BUILD_TPMLOG_FILE,
+                                 tables->tcpalog, 1, false);
+
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm2(tables_blob, tables->linker, tables->tcpalog);
+    }
+
     /* XSDT is pointed to by RSDP */
     xsdt = tables_blob->len;
     build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
Signature · 1 line
2.20.1
Reviewed-by on v2 2/3
#12 lore raw

Re: [PATCH v2 2/3] arm/acpi: TPM2 ACPI table support

Quoted 4 lines · Eric Auger

Add a TPM2 ACPI table if a TPM2.0 sysbus device has been dynamically instantiated.

Quoted 79 lines

---

v1 -> v2:
- reuse generic build_tpm2() and alloc log area externally
- call tpm_find() once in build_tpm2()

---
  include/sysemu/tpm.h     |  2 ++
  hw/acpi/aml-build.c      |  5 +++--
  hw/arm/virt-acpi-build.c | 11 +++++++++++
  3 files changed, 16 insertions(+), 2 deletions(-)
include/sysemu/tpm.h +2 -0
index f37851b1aa..03fb25941c 100644
@@ -50,6 +50,8 @@ typedef struct TPMIfClass {
 
  #define TPM_IS_TIS_ISA(chr)                         \
      object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
+#define TPM_IS_TIS_SYSBUS(chr)                      \
+    object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
  #define TPM_IS_CRB(chr)                             \
      object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
  #define TPM_IS_SPAPR(chr)                           \
hw/acpi/aml-build.c +3 -2
index 1f7fd09112..4224675cb2 100644
@@ -1882,12 +1882,13 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
      unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
      unsigned log_addr_offset =
          (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+    TPMIf *tpmif = tpm_find();
 
      tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
-    if (TPM_IS_TIS_ISA(tpm_find())) {
+    if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
          tpm2_ptr->control_area_address = cpu_to_le64(0);
          tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
-    } else if (TPM_IS_CRB(tpm_find())) {
+    } else if (TPM_IS_CRB(tpmif)) {
          tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
          tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
      } else {
hw/arm/virt-acpi-build.c +11 -0
index 81d41a3990..1a2ec10c8f 100644
@@ -41,11 +41,13 @@
  #include "hw/acpi/pci.h"
  #include "hw/acpi/memory_hotplug.h"
  #include "hw/acpi/generic_event_device.h"
+#include "hw/acpi/tpm.h"
  #include "hw/pci/pcie_host.h"
  #include "hw/pci/pci.h"
  #include "hw/arm/virt.h"
  #include "sysemu/numa.h"
  #include "sysemu/reset.h"
+#include "sysemu/tpm.h"
  #include "kvm_arm.h"
  #include "migration/vmstate.h"
 
@@ -831,6 +833,15 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
          build_iort(tables_blob, tables->linker, vms);
      }
 
+    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
+        acpi_data_push(tables->tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
+        bios_linker_loader_alloc(tables->linker, ACPI_BUILD_TPMLOG_FILE,
+                                 tables->tcpalog, 1, false);
+
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm2(tables_blob, tables->linker, tables->tcpalog);
+    }
+
      /* XSDT is pointed to by RSDP */
      xsdt = tables_blob->len;
      build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
#13 lore raw

Re: [PATCH v2 2/3] arm/acpi: TPM2 ACPI table support

In reply to Eric Auger
Quoted 4 lines · On Tue, 5 May 2020 16:44:18 +0200 Eric Auger <[email protected]> wrote:

Add a TPM2 ACPI table if a TPM2.0 sysbus device has been dynamically instantiated.

on x86 we also do:

  fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,                       
                  tables.tcpalog->data, acpi_data_len(tables.tcpalog)); 

question is why it's not necessary in case of ARM?

Quoted 79 lines

---

v1 -> v2:
- reuse generic build_tpm2() and alloc log area externally
- call tpm_find() once in build_tpm2()

---
 include/sysemu/tpm.h     |  2 ++
 hw/acpi/aml-build.c      |  5 +++--
 hw/arm/virt-acpi-build.c | 11 +++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
include/sysemu/tpm.h +2 -0
index f37851b1aa..03fb25941c 100644
@@ -50,6 +50,8 @@ typedef struct TPMIfClass {
 
 #define TPM_IS_TIS_ISA(chr)                         \
     object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
+#define TPM_IS_TIS_SYSBUS(chr)                      \
+    object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
 #define TPM_IS_CRB(chr)                             \
     object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
 #define TPM_IS_SPAPR(chr)                           \
hw/acpi/aml-build.c +3 -2
index 1f7fd09112..4224675cb2 100644
@@ -1882,12 +1882,13 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
     unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
     unsigned log_addr_offset =
         (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+    TPMIf *tpmif = tpm_find();
 
     tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
-    if (TPM_IS_TIS_ISA(tpm_find())) {
+    if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
         tpm2_ptr->control_area_address = cpu_to_le64(0);
         tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
-    } else if (TPM_IS_CRB(tpm_find())) {
+    } else if (TPM_IS_CRB(tpmif)) {
         tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
         tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
     } else {
hw/arm/virt-acpi-build.c +11 -0
index 81d41a3990..1a2ec10c8f 100644
@@ -41,11 +41,13 @@
 #include "hw/acpi/pci.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/generic_event_device.h"
+#include "hw/acpi/tpm.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
+#include "sysemu/tpm.h"
 #include "kvm_arm.h"
 #include "migration/vmstate.h"
 
@@ -831,6 +833,15 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
         build_iort(tables_blob, tables->linker, vms);
     }
 
+    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
+        acpi_data_push(tables->tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
+        bios_linker_loader_alloc(tables->linker, ACPI_BUILD_TPMLOG_FILE,
+                                 tables->tcpalog, 1, false);
+
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm2(tables_blob, tables->linker, tables->tcpalog);
+    }
+
     /* XSDT is pointed to by RSDP */
     xsdt = tables_blob->len;
     build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
author
#14 lore raw

Re: [PATCH v2 2/3] arm/acpi: TPM2 ACPI table support

Hi Igor,

Quoted 6 lines · Igor Mammedov
Quoted 3 lines · On Tue, 5 May 2020 16:44:18 +0200 Eric Auger <[email protected]> wrote:

Add a TPM2 ACPI table if a TPM2.0 sysbus device has been dynamically instantiated.

Quoted 8 lines
Quoted 1 line

on x86 we also do:

  fw_cfg_add_file(x86ms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,                       
                  tables.tcpalog->data, acpi_data_len(tables.tcpalog)); 

question is why it's not necessary in case of ARM?

you have it in virt_acpi_setup():
fw_cfg_add_file(vms->fw_cfg, ACPI_BUILD_TPMLOG_FILE, tables.tcpalog->data, acpi_data_len(tables.tcpalog));

Thanks

Eric

Quoted 81 lines
Quoted 80 lines

---

v1 -> v2:
- reuse generic build_tpm2() and alloc log area externally
- call tpm_find() once in build_tpm2()

---
 include/sysemu/tpm.h     |  2 ++
 hw/acpi/aml-build.c      |  5 +++--
 hw/arm/virt-acpi-build.c | 11 +++++++++++
 3 files changed, 16 insertions(+), 2 deletions(-)
include/sysemu/tpm.h +2 -0
index f37851b1aa..03fb25941c 100644
@@ -50,6 +50,8 @@ typedef struct TPMIfClass {
 
 #define TPM_IS_TIS_ISA(chr)                         \
     object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA)
+#define TPM_IS_TIS_SYSBUS(chr)                      \
+    object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)
 #define TPM_IS_CRB(chr)                             \
     object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)
 #define TPM_IS_SPAPR(chr)                           \
hw/acpi/aml-build.c +3 -2
index 1f7fd09112..4224675cb2 100644
@@ -1882,12 +1882,13 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
     unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
     unsigned log_addr_offset =
         (char *)&tpm2_ptr->log_area_start_address - table_data->data;
+    TPMIf *tpmif = tpm_find();
 
     tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
-    if (TPM_IS_TIS_ISA(tpm_find())) {
+    if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
         tpm2_ptr->control_area_address = cpu_to_le64(0);
         tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
-    } else if (TPM_IS_CRB(tpm_find())) {
+    } else if (TPM_IS_CRB(tpmif)) {
         tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL);
         tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB);
     } else {
hw/arm/virt-acpi-build.c +11 -0
index 81d41a3990..1a2ec10c8f 100644
@@ -41,11 +41,13 @@
 #include "hw/acpi/pci.h"
 #include "hw/acpi/memory_hotplug.h"
 #include "hw/acpi/generic_event_device.h"
+#include "hw/acpi/tpm.h"
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
+#include "sysemu/tpm.h"
 #include "kvm_arm.h"
 #include "migration/vmstate.h"
 
@@ -831,6 +833,15 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)
         build_iort(tables_blob, tables->linker, vms);
     }
 
+    if (tpm_get_version(tpm_find()) == TPM_VERSION_2_0) {
+        acpi_data_push(tables->tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
+        bios_linker_loader_alloc(tables->linker, ACPI_BUILD_TPMLOG_FILE,
+                                 tables->tcpalog, 1, false);
+
+        acpi_add_table(table_offsets, tables_blob);
+        build_tpm2(tables_blob, tables->linker, tables->tcpalog);
+    }
+
     /* XSDT is pointed to by RSDP */
     xsdt = tables_blob->len;
     build_xsdt(tables_blob, tables->linker, table_offsets, NULL, NULL);
author
#15 lore raw

PATCH v2 3/3 arm/acpi: Add the TPM2.0 device under the DSDT

In reply to Eric Auger

In case it is dynamically instantiated, add the TPM 2.0 device object under the DSDT table in the ACPI namespace. Its HID is MSFT0101 while its current resource settings (CRS) property is initialized with the guest physical address and MMIO size of the device.

---

v1 -> v2:
- use memory_region_size
- fix mingw compilation issue by casting to uint32_t
- added Stefan's R-b

---
 hw/arm/virt-acpi-build.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
hw/arm/virt-acpi-build.c +36 -0
index 1a2ec10c8f..8534d14e20 100644
@@ -45,6 +45,7 @@
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
+#include "hw/platform-bus.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
 #include "sysemu/tpm.h"
@@ -362,6 +363,40 @@ static void acpi_dsdt_add_power_button(Aml *scope)
     aml_append(scope, dev);
 }
 
+static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
+{
+    hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+    MemoryRegion *sbdev_mr;
+    SysBusDevice *sbdev;
+    hwaddr tpm_base;
+
+    sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()),
+                                                TYPE_SYS_BUS_DEVICE);
+    if (!sbdev) {
+        return;
+    }
+
+    tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
+    assert(tpm_base != -1);
+
+    tpm_base += pbus_base;
+
+    sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
+
+    Aml *dev = aml_device("TPM0");
+    aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
+    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+
+    Aml *crs = aml_resource_template();
+    aml_append(crs,
+               aml_memory32_fixed(tpm_base,
+                                  (uint32_t)memory_region_size(sbdev_mr),
+                                  AML_READ_WRITE));
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
@@ -756,6 +791,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     }
 
     acpi_dsdt_add_power_button(scope);
+    acpi_dsdt_add_tpm(scope, vms);
 
     aml_append(dsdt, scope);
 
Signature · 1 line
2.20.1
#16 lore raw

Re: [PATCH v2 3/3] arm/acpi: Add the TPM2.0 device under the DSDT

Hi,

hw/arm/virt-acpi-build.c static void acpi_dsdt_add_power_button(Aml *scope) · line 375

Quoted 10 lines · Eric Auger
hw/arm/virt-acpi-build.c +10 -0
+static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
+{
+    hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+    MemoryRegion *sbdev_mr;
+    SysBusDevice *sbdev;
+    hwaddr tpm_base;
+
+    sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()),
+                                                TYPE_SYS_BUS_DEVICE);

Does it need to check the tpm version like you do in previous patch?

tpm_get_version(tpm_find()) == TPM_VERSION_2_0

Thanks,
Shannon

#17 lore raw

Re: [PATCH v2 3/3] arm/acpi: Add the TPM2.0 device under the DSDT

Quoted 17 lines · Shannon Zhao

Hi,

hw/arm/virt-acpi-build.c static void acpi_dsdt_add_power_button(Aml *scope) · line 375

Quoted 10 lines · Eric Auger
hw/arm/virt-acpi-build.c +10 -0
+static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
+{
+    hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+    MemoryRegion *sbdev_mr;
+    SysBusDevice *sbdev;
+    hwaddr tpm_base;
+
+    sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()),
+                                                TYPE_SYS_BUS_DEVICE);

Does it need to check the tpm version like you do in previous patch?

Quoted 2 lines

tpm_get_version(tpm_find()) == TPM_VERSION_2_0

I don't think so. The device node could in theory be used to describe a TPM 1.2/1.3 as well, even though we never actually do that.

#18 lore raw

Re: [PATCH v2 3/3] arm/acpi: Add the TPM2.0 device under the DSDT

Quoted 16 lines · Ard Biesheuvel
Quoted 15 lines · Shannon Zhao

Hi,

hw/arm/virt-acpi-build.c static void acpi_dsdt_add_power_button(Aml *scope) · line 375

Quoted 10 lines · Eric Auger
hw/arm/virt-acpi-build.c +10 -0
+static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
+{
+    hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+    MemoryRegion *sbdev_mr;
+    SysBusDevice *sbdev;
+    hwaddr tpm_base;
+
+    sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()),
+                                                TYPE_SYS_BUS_DEVICE);

Does it need to check the tpm version like you do in previous patch?

Quoted 4 lines
Quoted 2 lines

tpm_get_version(tpm_find()) == TPM_VERSION_2_0

I don't think so. The device node could in theory be used to describe a TPM 1.2/1.3 as well, even though we never actually do that.

There is no TPM 1.3. There may be a TIS v1.3.

#19 lore raw

Re: [PATCH v2 3/3] arm/acpi: Add the TPM2.0 device under the DSDT

In reply to Eric Auger
Quoted 34 lines · On Tue, 5 May 2020 16:44:19 +0200 Eric Auger <[email protected]> wrote:

In case it is dynamically instantiated, add the TPM 2.0 device object under the DSDT table in the ACPI namespace. Its HID is MSFT0101 while its current resource settings (CRS) property is initialized with the guest physical address and MMIO size of the device.

---

v1 -> v2:
- use memory_region_size
- fix mingw compilation issue by casting to uint32_t
- added Stefan's R-b

---
 hw/arm/virt-acpi-build.c | 36 ++++++++++++++++++++++++++++++++++++
 1 file changed, 36 insertions(+)
hw/arm/virt-acpi-build.c +1 -0
index 1a2ec10c8f..8534d14e20 100644
@@ -45,6 +45,7 @@
 #include "hw/pci/pcie_host.h"
 #include "hw/pci/pci.h"
 #include "hw/arm/virt.h"
+#include "hw/platform-bus.h"
 #include "sysemu/numa.h"
 #include "sysemu/reset.h"
 #include "sysemu/tpm.h"
@@ -362,6 +363,40 @@ static void acpi_dsdt_add_power_button(Aml *scope)
     aml_append(scope, dev);
 }
 

hw/arm/virt-acpi-build.c static void acpi_dsdt_add_power_button(Aml *scope) · line 375

Quoted 10 lines
hw/arm/virt-acpi-build.c +10 -0
+static void acpi_dsdt_add_tpm(Aml *scope, VirtMachineState *vms)
+{
+    hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS].base;
+    PlatformBusDevice *pbus = PLATFORM_BUS_DEVICE(vms->platform_bus_dev);
+    MemoryRegion *sbdev_mr;
+    SysBusDevice *sbdev;
+    hwaddr tpm_base;
+
+    sbdev = (SysBusDevice *)object_dynamic_cast(OBJECT(tpm_find()),
+                                                TYPE_SYS_BUS_DEVICE);

SYS_BUS_DEVICE(object_dynamic_cast())

Quoted 35 lines
hw/arm/virt-acpi-build.c +25 -0
+    if (!sbdev) {
+        return;
+    }
+
+    tpm_base = platform_bus_get_mmio_addr(pbus, sbdev, 0);
+    assert(tpm_base != -1);
+
+    tpm_base += pbus_base;
+
+    sbdev_mr = sysbus_mmio_get_region(sbdev, 0);
+
+    Aml *dev = aml_device("TPM0");
+    aml_append(dev, aml_name_decl("_HID", aml_string("MSFT0101")));
+    aml_append(dev, aml_name_decl("_UID", aml_int(0)));
+
+    Aml *crs = aml_resource_template();
+    aml_append(crs,
+               aml_memory32_fixed(tpm_base,
+                                  (uint32_t)memory_region_size(sbdev_mr),
+                                  AML_READ_WRITE));
+    aml_append(dev, aml_name_decl("_CRS", crs));
+    aml_append(scope, dev);
+}
+
 static void
 build_iort(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
 {
@@ -756,6 +791,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms)
     }
 
     acpi_dsdt_add_power_button(scope);
+    acpi_dsdt_add_tpm(scope, vms);
 
     aml_append(dsdt, scope);
 
Tested-by on the v2 series
#20 lore raw
In reply to Eric Auger
Quoted 11 lines · Eric Auger

Those patches bring MMIO TPM TIS ACPI support in machvirt. The first patch moves the TPM2 ACPI table generation code in the generic code. Then the table is added if the TPM2 sysbus device is dynamically instantiated in machvirt. Also the TPM2 device object is described in the DSDT.

Many thanks to Ard for his support.

Tested with LUKS partition automatic decryption.

Thanks Eric