Skip to contentSkip to conversation

tpm: Upgrade TPM TIS for support of a TPM 2

PATCH Superseded Stefan Berger 3 participants 9 messages May 8, 2015 – May 19, 2015

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover tpm: Upgrade TPM TIS for support of a TPM 2

After the previous upgrade of the TPM TIS to version 1.3, we now upgrade it to support a TPM 2 in the backend.

Stefan Berger (3):
Extend TPM TIS interface to support TPM 2
tpm: Probe for connected TPM 1.2 or TPM 2
TPM2 ACPI table support

 backends/tpm.c               |  14 +++++
 hw/i386/Makefile.objs        |   2 +-
 hw/i386/acpi-build.c         |  38 +++++++++++--
 hw/i386/acpi-defs.h          |  18 +++++++
 hw/i386/ssdt-tpm2.dsl        |  44 +++++++++++++++
 hw/tpm/Makefile.objs         |   2 +-
 hw/tpm/tpm_int.h             |   7 +++
 hw/tpm/tpm_passthrough.c     |  65 ++++++----------------
 hw/tpm/tpm_tis.c             | 119 ++++++++++++++++++++++++++++++++++++----
 hw/tpm/tpm_tis.h             |   1 +
 hw/tpm/tpm_util.c            | 126 +++++++++++++++++++++++++++++++++++++++++++
 hw/tpm/tpm_util.h            |  28 ++++++++++
 include/hw/acpi/tpm.h        |   5 ++
 include/sysemu/tpm.h         |  17 +++++-
 include/sysemu/tpm_backend.h |  23 ++++++++
 15 files changed, 443 insertions(+), 66 deletions(-)
 create mode 100644 hw/i386/ssdt-tpm2.dsl
 create mode 100644 hw/tpm/tpm_util.c
 create mode 100644 hw/tpm/tpm_util.h
Signature · 1 line
1.9.3
#2 lore raw

PATCH v3 2/3 tpm: Probe for connected TPM 1.2 or TPM 2

In the TPM passthrough backend driver, modify the probing code so that we can check whether a TPM 1.2 or TPM 2 is being used and adapt the behavior of the TPM TIS accordingly.

Move the code that tested for a TPM 1.2 into tpm_utils.c and extend it with test for probing for TPM 2. Have the function return the version of TPM found.

---

v1->v2:
- prefixed TPM 2 #define's with TPM2

---
 hw/tpm/Makefile.objs     |   2 +-
 hw/tpm/tpm_int.h         |   6 +++
 hw/tpm/tpm_passthrough.c |  59 +++-------------------
 hw/tpm/tpm_util.c        | 126 +++++++++++++++++++++++++++++++++++++++++++++++
 hw/tpm/tpm_util.h        |  28 +++++++++++
 5 files changed, 167 insertions(+), 54 deletions(-)
 create mode 100644 hw/tpm/tpm_util.c
 create mode 100644 hw/tpm/tpm_util.h
hw/tpm/Makefile.objs +1 -1
index 99f5983..64cecc3 100644
@@ -1,2 +1,2 @@
 common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o
-common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
+common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o tpm_util.o
hw/tpm/tpm_int.h +6 -0
index 9866c79..f2f285b 100644
@@ -66,4 +66,10 @@ struct tpm_resp_hdr {
 #define TPM_ORD_ContinueSelfTest  0x53
 #define TPM_ORD_GetTicks          0xf1
 
+
+/* TPM2 defines */
+#define TPM2_ST_NO_SESSIONS       0x8001
+
+#define TPM2_CC_ReadClock         0x00000181
+
 #endif /* TPM_TPM_INT_H */
hw/tpm/tpm_passthrough.c +6 -53

84 lines not on this page · raw message

hw/tpm/tpm_util.c new file +126 -0

126 lines not on this page · raw message

hw/tpm/tpm_util.h new file +28 -0
new file mode 100644
index 0000000..e7f354a
@@ -0,0 +1,28 @@
+/*
+ * TPM utility functions
+ *
+ *  Copyright (c) 2010 - 2015 IBM Corporation
+ *  Authors:
+ *    Stefan Berger <[email protected]>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, see <http://www.gnu.org/licenses/>
+ */
+#ifndef TPM_TPM_UTILS_H
+#define TPM_TPM_UTILS_H
+
+#include "sysemu/tpm_backend.h"
+
+int tpm_util_test_tpmdev(int tpm_fd, TPMVersion *tpm_version);
+
+#endif /* TPM_TPM_UTILS_H */
Signature · 1 line
1.9.3
#3 lore raw

PATCH v3 3/3 TPM2 ACPI table support

In reply to Stefan Berger

Add a TPM2 ACPI table if a TPM 2 is used in the backend. Also add an SSDT for the TPM 2.

Rename tpm_find() to tpm_get_version() and have this function return the version of the TPM found, TPMVersion_Unspec if no TPM is found. Use the version number to build version specific ACPI tables.

---

v2->v3:
- followed Igor's suggestion of a default case with an assert()
- added an SSDT for TPM2; it will be a bit different than TPM1.2's SSDT once we add PPI to it

---
 hw/i386/Makefile.objs |  2 +-
 hw/i386/acpi-build.c  | 38 ++++++++++++++++++++++++++++++++++----
 hw/i386/acpi-defs.h   | 18 ++++++++++++++++++
 hw/i386/ssdt-tpm2.dsl | 44 ++++++++++++++++++++++++++++++++++++++++++++
 hw/tpm/tpm_tis.c      | 11 +++++++++++
 include/hw/acpi/tpm.h |  5 +++++
 include/sysemu/tpm.h  | 11 +++++++++--
 7 files changed, 122 insertions(+), 7 deletions(-)
 create mode 100644 hw/i386/ssdt-tpm2.dsl
hw/i386/Makefile.objs +1 -1
index e058a39..0be5d97 100644
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c \
 	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +34 -4
index e761005..e648ab5 100644
@@ -42,6 +42,7 @@
 #include "hw/acpi/memory_hotplug.h"
 #include "sysemu/tpm.h"
 #include "hw/acpi/tpm.h"
+#include "sysemu/tpm_backend.h"
 
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
@@ -111,7 +112,7 @@ typedef struct AcpiPmInfo {
 
 typedef struct AcpiMiscInfo {
     bool has_hpet;
-    bool has_tpm;
+    TPMVersion tpm_version;
     const unsigned char *dsdt_code;
     unsigned dsdt_size;
     uint16_t pvpanic_port;
@@ -239,7 +240,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 static void acpi_get_misc_info(AcpiMiscInfo *info)
 {
     info->has_hpet = hpet_find();
-    info->has_tpm = tpm_find();
+    info->tpm_version = tpm_get_version();
     info->pvpanic_port = pvpanic_port();
     info->applesmc_io_base = applesmc_port();
 }
@@ -468,6 +469,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
 }
 
 #include "hw/i386/ssdt-tpm.hex"
+#include "hw/i386/ssdt-tpm2.hex"
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
@@ -1065,6 +1067,25 @@ build_tpm_ssdt(GArray *table_data, GArray *linker)
     memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));
 }
 
+static void
+build_tpm2(GArray *table_data, GArray *linker)
+{
+    Acpi20TPM2 *tpm2_ptr;
+    void *tpm_ptr;
+
+    tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
+    memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));
+
+    tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    tpm2_ptr->control_area_address = cpu_to_le64(0);
+    tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
+}
+
 typedef enum {
     MEM_AFFINITY_NOFLAGS      = 0,
     MEM_AFFINITY_ENABLED      = (1 << 0),
@@ -1428,12 +1449,21 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         acpi_add_table(table_offsets, tables_blob);
         build_hpet(tables_blob, tables->linker);
     }
-    if (misc.has_tpm) {
+    if (misc.tpm_version != TPM_VERSION_UNSPEC) {
         acpi_add_table(table_offsets, tables_blob);
         build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
         acpi_add_table(table_offsets, tables_blob);
-        build_tpm_ssdt(tables_blob, tables->linker);
+        switch (misc.tpm_version) {
+        case TPM_VERSION_1_2:
+            build_tpm_ssdt(tables_blob, tables->linker);
+            break;
+        case TPM_VERSION_2_0:
+            build_tpm2(tables_blob, tables->linker);
+            break;
+        default:
+            assert(false);
+        }
     }
     if (guest_info->numa_nodes) {
         acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-defs.h +18 -0
index c4468f8..79ee9b1 100644
@@ -316,6 +316,9 @@ typedef struct AcpiTableMcfg AcpiTableMcfg;
 
 /*
  * TCPA Description Table
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
  */
 struct Acpi20Tcpa {
     ACPI_TABLE_HEADER_DEF                    /* ACPI common table header */
@@ -325,6 +328,21 @@ struct Acpi20Tcpa {
 } QEMU_PACKED;
 typedef struct Acpi20Tcpa Acpi20Tcpa;
 
+/*
+ * TPM2
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
+ */
+struct Acpi20TPM2 {
+    ACPI_TABLE_HEADER_DEF
+    uint16_t platform_class;
+    uint16_t reserved;
+    uint64_t control_area_address;
+    uint32_t start_method;
+} QEMU_PACKED;
+typedef struct Acpi20TPM2 Acpi20TPM2;
+
 /* DMAR - DMA Remapping table r2.2 */
 struct AcpiTableDmar {
     ACPI_TABLE_HEADER_DEF
hw/i386/ssdt-tpm2.dsl new file +44 -0

44 lines not on this page · raw message

hw/tpm/tpm_tis.c +11 -0
index 69fbfae..daf2ac9 100644
@@ -32,6 +32,7 @@
 #include "tpm_tis.h"
 #include "qemu-common.h"
 #include "qemu/main-loop.h"
+#include "sysemu/tpm_backend.h"
 
 #define DEBUG_TIS 0
 
@@ -962,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s)
 }
 
 /*
+ * Get the TPMVersion of the backend device being used
+ */
+TPMVersion tpm_tis_get_tpm_version(Object *obj)
+{
+    TPMState *s = TPM(obj);
+
+    return tpm_backend_get_tpm_version(s->be_driver);
+}
+
+/*
  * This function is called when the machine starts, resets or due to
  * S3 resume.
  */
include/hw/acpi/tpm.h +5 -0
index 792fcbf..6d516c6 100644
@@ -26,4 +26,9 @@
 #define TPM_TCPA_ACPI_CLASS_CLIENT  0
 #define TPM_TCPA_ACPI_CLASS_SERVER  1
 
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_ACPI_CLASS_SERVER      1
+
+#define TPM2_START_METHOD_MMIO      6
+
 #endif /* HW_ACPI_TPM_H */
include/sysemu/tpm.h +9 -2
index 848df41..c143890 100644
@@ -26,11 +26,18 @@ typedef enum  TPMVersion {
     TPM_VERSION_2_0 = 2,
 } TPMVersion;
 
+TPMVersion tpm_tis_get_tpm_version(Object *obj);
+
 #define TYPE_TPM_TIS                "tpm-tis"
 
-static inline bool tpm_find(void)
+static inline TPMVersion tpm_get_version(void)
 {
-    return object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+
+    if (obj) {
+        return tpm_tis_get_tpm_version(obj);
+    }
+    return TPM_VERSION_UNSPEC;
 }
 
 #endif /* QEMU_TPM_H */
Signature · 1 line
1.9.3
#1 lore raw

PATCH v3 1/3 Extend TPM TIS interface to support TPM 2

In reply to Stefan Berger

Following the recent upgrade to version 1.3, extend the TPM TIS interface with capabilities introduced for support of a TPM 2.

TPM TIS for TPM 2 introduced the following extensions beyond the TPM TIS 1.3 (used for TPM 1.2):

- A new 32bit interface Id register was introduced.
- New flags for the status (STS) register were defined.
- New flags for the capability flags were defined.

Support the above if a TPM TIS 1.3 for TPM 2 is used with a TPM 2 on the backend side. Support the old TPM TIS 1.3 configuration if a TPM 1.2 is being used. A subsequent patch will then determine which TPM version is being used in the backend.

---

v1->v2:
- fixed enums to be all upper case
- enum TPMVersion converted to typedef

---
 backends/tpm.c               |  14 ++++++
 hw/tpm/tpm_int.h             |   1 +
 hw/tpm/tpm_passthrough.c     |  14 ++++++
 hw/tpm/tpm_tis.c             | 108 +++++++++++++++++++++++++++++++++++++++----
 hw/tpm/tpm_tis.h             |   1 +
 include/sysemu/tpm.h         |   6 +++
 include/sysemu/tpm_backend.h |  23 +++++++++
 7 files changed, 158 insertions(+), 9 deletions(-)
backends/tpm.c +14 -0
index 4efe367..9b0d0a5 100644
@@ -96,6 +96,20 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s)
     return k->ops->get_tpm_established_flag(s);
 }
 
+int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty)
+{
+    TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
+
+    return k->ops->reset_tpm_established_flag(s, locty);
+}
+
+TPMVersion tpm_backend_get_tpm_version(TPMBackend *s)
+{
+    TPMBackendClass *k = TPM_BACKEND_GET_CLASS(s);
+
+    return k->ops->get_tpm_version(s);
+}
+
 static bool tpm_backend_prop_get_opened(Object *obj, Error **errp)
 {
     TPMBackend *s = TPM_BACKEND(obj);
hw/tpm/tpm_int.h +1 -0
index 2b35fe2..9866c79 100644
@@ -29,6 +29,7 @@ struct TPMState {
 
     char *backend;
     TPMBackend *be_driver;
+    TPMVersion be_tpm_version;
 };
 
 #define TPM(obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)
hw/tpm/tpm_passthrough.c +14 -0
index 73ca906..f1361d2 100644
@@ -267,6 +267,13 @@ static bool tpm_passthrough_get_tpm_established_flag(TPMBackend *tb)
     return false;
 }
 
+static int tpm_passthrough_reset_tpm_established_flag(TPMBackend *tb,
+                                                      uint8_t locty)
+{
+    /* only a TPM 2.0 will support this */
+    return 0;
+}
+
 static bool tpm_passthrough_get_startup_error(TPMBackend *tb)
 {
     TPMPassthruState *tpm_pt = TPM_PASSTHROUGH(tb);
@@ -324,6 +331,11 @@ static const char *tpm_passthrough_create_desc(void)
     return "Passthrough TPM backend driver";
 }
 
+static TPMVersion tpm_passthrough_get_tpm_version(TPMBackend *tb)
+{
+    return TPM_VERSION_1_2;
+}
+
 /*
  * A basic test of a TPM device. We expect a well formatted response header
  * (error response is fine) within one second.
@@ -540,6 +552,8 @@ static const TPMDriverOps tpm_passthrough_driver = {
     .deliver_request          = tpm_passthrough_deliver_request,
     .cancel_cmd               = tpm_passthrough_cancel_cmd,
     .get_tpm_established_flag = tpm_passthrough_get_tpm_established_flag,
+    .reset_tpm_established_flag = tpm_passthrough_reset_tpm_established_flag,
+    .get_tpm_version          = tpm_passthrough_get_tpm_version,
 };
 
 static void tpm_passthrough_inst_init(Object *obj)
hw/tpm/tpm_tis.c +99 -9

184 lines not on this page · raw message

hw/tpm/tpm_tis.h +1 -0
index db78d51..a1df41f 100644
@@ -42,6 +42,7 @@ typedef struct TPMLocality {
     TPMTISState state;
     uint8_t access;
     uint32_t sts;
+    uint32_t iface_id;
     uint32_t inte;
     uint32_t ints;
 
include/sysemu/tpm.h +6 -0
index 9b81ce9..848df41 100644
@@ -20,6 +20,12 @@ int tpm_config_parse(QemuOptsList *opts_list, const char *optarg);
 int tpm_init(void);
 void tpm_cleanup(void);
 
+typedef enum  TPMVersion {
+    TPM_VERSION_UNSPEC = 0,
+    TPM_VERSION_1_2 = 1,
+    TPM_VERSION_2_0 = 2,
+} TPMVersion;
+
 #define TYPE_TPM_TIS                "tpm-tis"
 
 static inline bool tpm_find(void)
include/sysemu/tpm_backend.h +23 -0
index 540ee25..0a366be 100644
@@ -88,6 +88,10 @@ struct TPMDriverOps {
     void (*cancel_cmd)(TPMBackend *t);
 
     bool (*get_tpm_established_flag)(TPMBackend *t);
+
+    int (*reset_tpm_established_flag)(TPMBackend *t, uint8_t locty);
+
+    TPMVersion (*get_tpm_version)(TPMBackend *t);
 };
 
 
@@ -192,6 +196,15 @@ void tpm_backend_cancel_cmd(TPMBackend *s);
 bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
 
 /**
+ * tpm_backend_reset_tpm_established_flag:
+ * @s: the backend
+ * @locty: the locality number
+ *
+ * Reset the TPM establishment flag.
+ */
+int tpm_backend_reset_tpm_established_flag(TPMBackend *s, uint8_t locty);
+
+/**
  * tpm_backend_open:
  * @s: the backend to open
  * @errp: a pointer to return the #Error object if an error occurs.
@@ -201,6 +214,16 @@ bool tpm_backend_get_tpm_established_flag(TPMBackend *s);
  */
 void tpm_backend_open(TPMBackend *s, Error **errp);
 
+/**
+ * tpm_backend_get_tpm_version:
+ * @s: the backend to call into
+ *
+ * Get the TPM Version that is emulated at the backend.
+ *
+ * Returns TPMVersion.
+ */
+TPMVersion tpm_backend_get_tpm_version(TPMBackend *s);
+
 TPMBackend *qemu_find_tpm(const char *id);
 
 const TPMDriverOps *tpm_get_backend_driver(const char *type);
Signature · 1 line
1.9.3
#4 lore raw

Re: [Qemu-devel] [PATCH v3 3/3] TPM2 ACPI table support

In reply to Stefan Berger
Quoted 80 lines · On Fri, 8 May 2015 11:52:46 -0400 Stefan Berger <[email protected]>…

Add a TPM2 ACPI table if a TPM 2 is used in the backend. Also add an SSDT for the TPM 2.

Rename tpm_find() to tpm_get_version() and have this function return the version of the TPM found, TPMVersion_Unspec if no TPM is found. Use the version number to build version specific ACPI tables.

---

v2->v3:
- followed Igor's suggestion of a default case with an assert()
- added an SSDT for TPM2; it will be a bit different than TPM1.2's SSDT once we add PPI to it

---
 hw/i386/Makefile.objs |  2 +-
 hw/i386/acpi-build.c  | 38 ++++++++++++++++++++++++++++++++++----
 hw/i386/acpi-defs.h   | 18 ++++++++++++++++++
 hw/i386/ssdt-tpm2.dsl | 44 ++++++++++++++++++++++++++++++++++++++++++++
 hw/tpm/tpm_tis.c      | 11 +++++++++++
 include/hw/acpi/tpm.h |  5 +++++
 include/sysemu/tpm.h  | 11 +++++++++--
 7 files changed, 122 insertions(+), 7 deletions(-)
 create mode 100644 hw/i386/ssdt-tpm2.dsl
hw/i386/Makefile.objs +1 -1
index e058a39..0be5d97 100644
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
 obj-y += acpi-build.o
 hw/i386/acpi-build.o: hw/i386/acpi-build.c \
 	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex
 
 iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
     ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +4 -2
index e761005..e648ab5 100644
@@ -42,6 +42,7 @@
 #include "hw/acpi/memory_hotplug.h"
 #include "sysemu/tpm.h"
 #include "hw/acpi/tpm.h"
+#include "sysemu/tpm_backend.h"
 
 /* Supported chipsets: */
 #include "hw/acpi/piix4.h"
@@ -111,7 +112,7 @@ typedef struct AcpiPmInfo {
 
 typedef struct AcpiMiscInfo {
     bool has_hpet;
-    bool has_tpm;
+    TPMVersion tpm_version;
     const unsigned char *dsdt_code;
     unsigned dsdt_size;
     uint16_t pvpanic_port;
@@ -239,7 +240,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
 static void acpi_get_misc_info(AcpiMiscInfo *info)
 {
     info->has_hpet = hpet_find();
-    info->has_tpm = tpm_find();
+    info->tpm_version = tpm_get_version();
     info->pvpanic_port = pvpanic_port();
     info->applesmc_io_base = applesmc_port();
 }
@@ -468,6 +469,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
 }
 
 #include "hw/i386/ssdt-tpm.hex"
+#include "hw/i386/ssdt-tpm2.hex"
 
 /* Assign BSEL property to all buses.  In the future, this can be changed
  * to only assign to buses that support hotplug.
@@ -1065,6 +1067,25 @@ build_tpm_ssdt(GArray *table_data, GArray *linker)
     memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker) · line 1077

Quoted 10 lines
hw/i386/acpi-build.c +8 -0
 }
 
+static void
+build_tpm2(GArray *table_data, GArray *linker)
+{
+    Acpi20TPM2 *tpm2_ptr;
+    void *tpm_ptr;
+
+    tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
+    memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));

^^^ does almost the same as build_tpm_ssdt(), replacing AML template with dynamic AML generation would help to consolidate v1 and v2 versions of build_tpm_ssdt().

Quoted 114 lines
hw/i386/acpi-build.c +22 -2
+
+    tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    tpm2_ptr->control_area_address = cpu_to_le64(0);
+    tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
+}
+
 typedef enum {
     MEM_AFFINITY_NOFLAGS      = 0,
     MEM_AFFINITY_ENABLED      = (1 << 0),
@@ -1428,12 +1449,21 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
         acpi_add_table(table_offsets, tables_blob);
         build_hpet(tables_blob, tables->linker);
     }
-    if (misc.has_tpm) {
+    if (misc.tpm_version != TPM_VERSION_UNSPEC) {
         acpi_add_table(table_offsets, tables_blob);
         build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
         acpi_add_table(table_offsets, tables_blob);
-        build_tpm_ssdt(tables_blob, tables->linker);
+        switch (misc.tpm_version) {
+        case TPM_VERSION_1_2:
+            build_tpm_ssdt(tables_blob, tables->linker);
+            break;
+        case TPM_VERSION_2_0:
+            build_tpm2(tables_blob, tables->linker);
+            break;
+        default:
+            assert(false);
+        }
     }
     if (guest_info->numa_nodes) {
         acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-defs.h +18 -0
index c4468f8..79ee9b1 100644
@@ -316,6 +316,9 @@ typedef struct AcpiTableMcfg AcpiTableMcfg;
 
 /*
  * TCPA Description Table
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
  */
 struct Acpi20Tcpa {
     ACPI_TABLE_HEADER_DEF                    /* ACPI common table header */
@@ -325,6 +328,21 @@ struct Acpi20Tcpa {
 } QEMU_PACKED;
 typedef struct Acpi20Tcpa Acpi20Tcpa;
 
+/*
+ * TPM2
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
+ */
+struct Acpi20TPM2 {
+    ACPI_TABLE_HEADER_DEF
+    uint16_t platform_class;
+    uint16_t reserved;
+    uint64_t control_area_address;
+    uint32_t start_method;
+} QEMU_PACKED;
+typedef struct Acpi20TPM2 Acpi20TPM2;
+
 /* DMAR - DMA Remapping table r2.2 */
 struct AcpiTableDmar {
     ACPI_TABLE_HEADER_DEF
hw/i386/ssdt-tpm2.dsl new file +34 -0
new file mode 100644
index 0000000..96936ed
@@ -0,0 +1,44 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "hw/acpi/tpm.h"
+
+ACPI_EXTRACT_ALL_CODE ssdt_tpm2_aml
+
+DefinitionBlock (
+    "ssdt-tpm2.aml",    // Output Filename
+    "SSDT",             // Signature
+    0x01,               // SSDT Compliance Revision
+    "BXPC",             // OEMID
+    "BXSSDT",           // TABLE ID
+    0x1                 // OEM Revision
+    )
+{
+    Scope(\_SB) {
+        /* TPM with emulated TPM TIS interface */
+        Device (TPM) {
+            Name (_HID, EisaID ("PNP0C31"))
+            Name (_CRS, ResourceTemplate ()
+            {
+                Memory32Fixed (ReadWrite, TPM_TIS_ADDR_BASE, TPM_TIS_ADDR_SIZE)

hw/i386/ssdt-tpm2.dsl line 44

Quoted 10 lines
hw/i386/ssdt-tpm2.dsl new file +10 -0
+
+                /* TPM 2 is recent enough to support interrupts */
+                IRQNoFlags () {TPM_TIS_IRQ}
+            })
+            Method (_STA, 0, NotSerialized) {
+                Return (0x0F)
+            }
+        }
+    }
+}

Pls, don't add another ASL template.
It would be better to rewrite above using AML API in C and while at it convert hw/i386/ssdt-tpm.dsl to AML API as well. hw/i386/ssdt-tpm.dsl is pretty much the same as ssdt-tpm2.aml except of IRQNoFlags() so they could share common code and for v2 you'll add extra IRQ resource.

Also I'd suggest to put TPM device under \_SB.PCI0 scope so that its _CRS wouldn't conflict with PCI0._CRS but rather be a consumer of it.

Quoted 68 lines
hw/tpm/tpm_tis.c +11 -0
index 69fbfae..daf2ac9 100644
@@ -32,6 +32,7 @@
 #include "tpm_tis.h"
 #include "qemu-common.h"
 #include "qemu/main-loop.h"
+#include "sysemu/tpm_backend.h"
 
 #define DEBUG_TIS 0
 
@@ -962,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s)
 }
 
 /*
+ * Get the TPMVersion of the backend device being used
+ */
+TPMVersion tpm_tis_get_tpm_version(Object *obj)
+{
+    TPMState *s = TPM(obj);
+
+    return tpm_backend_get_tpm_version(s->be_driver);
+}
+
+/*
  * This function is called when the machine starts, resets or due to
  * S3 resume.
  */
include/hw/acpi/tpm.h +5 -0
index 792fcbf..6d516c6 100644
@@ -26,4 +26,9 @@
 #define TPM_TCPA_ACPI_CLASS_CLIENT  0
 #define TPM_TCPA_ACPI_CLASS_SERVER  1
 
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_ACPI_CLASS_SERVER      1
+
+#define TPM2_START_METHOD_MMIO      6
+
 #endif /* HW_ACPI_TPM_H */
include/sysemu/tpm.h +9 -2
index 848df41..c143890 100644
@@ -26,11 +26,18 @@ typedef enum  TPMVersion {
     TPM_VERSION_2_0 = 2,
 } TPMVersion;
 
+TPMVersion tpm_tis_get_tpm_version(Object *obj);
+
 #define TYPE_TPM_TIS                "tpm-tis"
 
-static inline bool tpm_find(void)
+static inline TPMVersion tpm_get_version(void)
 {
-    return object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+
+    if (obj) {
+        return tpm_tis_get_tpm_version(obj);
+    }
+    return TPM_VERSION_UNSPEC;
 }
 
 #endif /* QEMU_TPM_H */
#5 lore raw

Re: [Qemu-devel] [PATCH v3 3/3] TPM2 ACPI table support

Quoted 85 lines · Igor Mammedov
Quoted 82 lines · On Fri, 8 May 2015 11:52:46 -0400 Stefan Berger <[email protected]>…

Add a TPM2 ACPI table if a TPM 2 is used in the backend. Also add an SSDT for the TPM 2.

Rename tpm_find() to tpm_get_version() and have this function return the version of the TPM found, TPMVersion_Unspec if no TPM is found. Use the version number to build version specific ACPI tables.

---

v2->v3:
- followed Igor's suggestion of a default case with an assert()
- added an SSDT for TPM2; it will be a bit different than TPM1.2's SSDT once we add PPI to it

---
  hw/i386/Makefile.objs |  2 +-
  hw/i386/acpi-build.c  | 38 ++++++++++++++++++++++++++++++++++----
  hw/i386/acpi-defs.h   | 18 ++++++++++++++++++
  hw/i386/ssdt-tpm2.dsl | 44 ++++++++++++++++++++++++++++++++++++++++++++
  hw/tpm/tpm_tis.c      | 11 +++++++++++
  include/hw/acpi/tpm.h |  5 +++++
  include/sysemu/tpm.h  | 11 +++++++++--
  7 files changed, 122 insertions(+), 7 deletions(-)

create mode 100644 hw/i386/ssdt-tpm2.dsl

hw/i386/Makefile.objs +1 -1
index e058a39..0be5d97 100644
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
  obj-y += acpi-build.o
  hw/i386/acpi-build.o: hw/i386/acpi-build.c \
  	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex
 
  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
      ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +4 -2
index e761005..e648ab5 100644
@@ -42,6 +42,7 @@
  #include "hw/acpi/memory_hotplug.h"
  #include "sysemu/tpm.h"
  #include "hw/acpi/tpm.h"
+#include "sysemu/tpm_backend.h"
 
  /* Supported chipsets: */
  #include "hw/acpi/piix4.h"
@@ -111,7 +112,7 @@ typedef struct AcpiPmInfo {
 
  typedef struct AcpiMiscInfo {
      bool has_hpet;
-    bool has_tpm;
+    TPMVersion tpm_version;
      const unsigned char *dsdt_code;
      unsigned dsdt_size;
      uint16_t pvpanic_port;
@@ -239,7 +240,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
  static void acpi_get_misc_info(AcpiMiscInfo *info)
  {
      info->has_hpet = hpet_find();
-    info->has_tpm = tpm_find();
+    info->tpm_version = tpm_get_version();
      info->pvpanic_port = pvpanic_port();
      info->applesmc_io_base = applesmc_port();
  }
@@ -468,6 +469,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
  }
 
  #include "hw/i386/ssdt-tpm.hex"
+#include "hw/i386/ssdt-tpm2.hex"
 
  /* Assign BSEL property to all buses.  In the future, this can be changed
   * to only assign to buses that support hotplug.
@@ -1065,6 +1067,25 @@ build_tpm_ssdt(GArray *table_data, GArray *linker)
      memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));
  }
 
Quoted 11 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker) · line 1077

Quoted 8 lines
hw/i386/acpi-build.c +8 -0
+static void
+build_tpm2(GArray *table_data, GArray *linker)
+{
+    Acpi20TPM2 *tpm2_ptr;
+    void *tpm_ptr;
+
+    tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
+    memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));

^^^ does almost the same as build_tpm_ssdt(), replacing AML template with dynamic AML generation would help to consolidate v1 and v2 versions of build_tpm_ssdt().

So the SSDT's for the TPM v1.2 and TPM 2 differ, but only slightly so. What does building the AML template via Opcodes etc. help in this case? Doesn't this make the code more or less unreadable? I don't understand why we shoudln't use the AML compiler on it?

Quoted 118 lines
Quoted 118 lines
hw/i386/acpi-build.c +22 -2
+
+    tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    tpm2_ptr->control_area_address = cpu_to_le64(0);
+    tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
+}
+
  typedef enum {
      MEM_AFFINITY_NOFLAGS      = 0,
      MEM_AFFINITY_ENABLED      = (1 << 0),
@@ -1428,12 +1449,21 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
          acpi_add_table(table_offsets, tables_blob);
          build_hpet(tables_blob, tables->linker);
      }
-    if (misc.has_tpm) {
+    if (misc.tpm_version != TPM_VERSION_UNSPEC) {
          acpi_add_table(table_offsets, tables_blob);
          build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
          acpi_add_table(table_offsets, tables_blob);
-        build_tpm_ssdt(tables_blob, tables->linker);
+        switch (misc.tpm_version) {
+        case TPM_VERSION_1_2:
+            build_tpm_ssdt(tables_blob, tables->linker);
+            break;
+        case TPM_VERSION_2_0:
+            build_tpm2(tables_blob, tables->linker);
+            break;
+        default:
+            assert(false);
+        }
      }
      if (guest_info->numa_nodes) {
          acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-defs.h +18 -0
index c4468f8..79ee9b1 100644
@@ -316,6 +316,9 @@ typedef struct AcpiTableMcfg AcpiTableMcfg;
 
  /*
   * TCPA Description Table
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
   */
  struct Acpi20Tcpa {
      ACPI_TABLE_HEADER_DEF                    /* ACPI common table header */
@@ -325,6 +328,21 @@ struct Acpi20Tcpa {
  } QEMU_PACKED;
  typedef struct Acpi20Tcpa Acpi20Tcpa;
 
+/*
+ * TPM2
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
+ */
+struct Acpi20TPM2 {
+    ACPI_TABLE_HEADER_DEF
+    uint16_t platform_class;
+    uint16_t reserved;
+    uint64_t control_area_address;
+    uint32_t start_method;
+} QEMU_PACKED;
+typedef struct Acpi20TPM2 Acpi20TPM2;
+
  /* DMAR - DMA Remapping table r2.2 */
  struct AcpiTableDmar {
      ACPI_TABLE_HEADER_DEF
hw/i386/ssdt-tpm2.dsl new file +37 -0
new file mode 100644
index 0000000..96936ed
@@ -0,0 +1,44 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "hw/acpi/tpm.h"
+
+ACPI_EXTRACT_ALL_CODE ssdt_tpm2_aml
+
+DefinitionBlock (
+    "ssdt-tpm2.aml",    // Output Filename
+    "SSDT",             // Signature
+    0x01,               // SSDT Compliance Revision
+    "BXPC",             // OEMID
+    "BXSSDT",           // TABLE ID
+    0x1                 // OEM Revision
+    )
+{
+    Scope(\_SB) {
+        /* TPM with emulated TPM TIS interface */
+        Device (TPM) {
+            Name (_HID, EisaID ("PNP0C31"))
+            Name (_CRS, ResourceTemplate ()
+            {
+                Memory32Fixed (ReadWrite, TPM_TIS_ADDR_BASE, TPM_TIS_ADDR_SIZE)
+
+                /* TPM 2 is recent enough to support interrupts */
+                IRQNoFlags () {TPM_TIS_IRQ}
Quoted 8 lines

hw/i386/ssdt-tpm2.dsl line 44

Quoted 7 lines
hw/i386/ssdt-tpm2.dsl new file +7 -0
+            })
+            Method (_STA, 0, NotSerialized) {
+                Return (0x0F)
+            }
+        }
+    }
+}

Pls, don't add another ASL template.

Pls tell me why it is better to compile by hand rather than use a higher level language here?

Regards,
Stefan

Quoted 80 lines

It would be better to rewrite above using AML API in C and while at it convert hw/i386/ssdt-tpm.dsl to AML API as well. hw/i386/ssdt-tpm.dsl is pretty much the same as ssdt-tpm2.aml except of IRQNoFlags() so they could share common code and for v2 you'll add extra IRQ resource.

Also I'd suggest to put TPM device under \_SB.PCI0 scope so that its _CRS wouldn't conflict with PCI0._CRS but rather be a consumer of it.

Quoted 68 lines
hw/tpm/tpm_tis.c +11 -0
index 69fbfae..daf2ac9 100644
@@ -32,6 +32,7 @@
  #include "tpm_tis.h"
  #include "qemu-common.h"
  #include "qemu/main-loop.h"
+#include "sysemu/tpm_backend.h"
 
  #define DEBUG_TIS 0
 
@@ -962,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s)
  }
 
  /*
+ * Get the TPMVersion of the backend device being used
+ */
+TPMVersion tpm_tis_get_tpm_version(Object *obj)
+{
+    TPMState *s = TPM(obj);
+
+    return tpm_backend_get_tpm_version(s->be_driver);
+}
+
+/*
   * This function is called when the machine starts, resets or due to
   * S3 resume.
   */
include/hw/acpi/tpm.h +5 -0
index 792fcbf..6d516c6 100644
@@ -26,4 +26,9 @@
  #define TPM_TCPA_ACPI_CLASS_CLIENT  0
  #define TPM_TCPA_ACPI_CLASS_SERVER  1
 
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_ACPI_CLASS_SERVER      1
+
+#define TPM2_START_METHOD_MMIO      6
+
  #endif /* HW_ACPI_TPM_H */
include/sysemu/tpm.h +9 -2
index 848df41..c143890 100644
@@ -26,11 +26,18 @@ typedef enum  TPMVersion {
      TPM_VERSION_2_0 = 2,
  } TPMVersion;
 
+TPMVersion tpm_tis_get_tpm_version(Object *obj);
+
  #define TYPE_TPM_TIS                "tpm-tis"
 
-static inline bool tpm_find(void)
+static inline TPMVersion tpm_get_version(void)
  {
-    return object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+
+    if (obj) {
+        return tpm_tis_get_tpm_version(obj);
+    }
+    return TPM_VERSION_UNSPEC;
  }
 
  #endif /* QEMU_TPM_H */
#6 lore raw

Re: [Qemu-devel] [PATCH v3 3/3] TPM2 ACPI table support

Quoted 98 lines · On Fri, 15 May 2015 11:31:30 -0400 Stefan Berger <[email protected]>…
Quoted 85 lines · Igor Mammedov
Quoted 82 lines · On Fri, 8 May 2015 11:52:46 -0400 Stefan Berger <[email protected]>…

Add a TPM2 ACPI table if a TPM 2 is used in the backend. Also add an SSDT for the TPM 2.

Rename tpm_find() to tpm_get_version() and have this function return the version of the TPM found, TPMVersion_Unspec if no TPM is found. Use the version number to build version specific ACPI tables.

---

v2->v3:
- followed Igor's suggestion of a default case with an assert()
- added an SSDT for TPM2; it will be a bit different than TPM1.2's SSDT once we add PPI to it

---
  hw/i386/Makefile.objs |  2 +-
  hw/i386/acpi-build.c  | 38 ++++++++++++++++++++++++++++++++++----
  hw/i386/acpi-defs.h   | 18 ++++++++++++++++++
  hw/i386/ssdt-tpm2.dsl | 44 ++++++++++++++++++++++++++++++++++++++++++++
  hw/tpm/tpm_tis.c      | 11 +++++++++++
  include/hw/acpi/tpm.h |  5 +++++
  include/sysemu/tpm.h  | 11 +++++++++--
  7 files changed, 122 insertions(+), 7 deletions(-)

create mode 100644 hw/i386/ssdt-tpm2.dsl

hw/i386/Makefile.objs +1 -1
index e058a39..0be5d97 100644
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
  obj-y += acpi-build.o
  hw/i386/acpi-build.o: hw/i386/acpi-build.c \
  	hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-	hw/i386/ssdt-tpm.hex
+	hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex
 
  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
      ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +4 -2
index e761005..e648ab5 100644
@@ -42,6 +42,7 @@
  #include "hw/acpi/memory_hotplug.h"
  #include "sysemu/tpm.h"
  #include "hw/acpi/tpm.h"
+#include "sysemu/tpm_backend.h"
 
  /* Supported chipsets: */
  #include "hw/acpi/piix4.h"
@@ -111,7 +112,7 @@ typedef struct AcpiPmInfo {
 
  typedef struct AcpiMiscInfo {
      bool has_hpet;
-    bool has_tpm;
+    TPMVersion tpm_version;
      const unsigned char *dsdt_code;
      unsigned dsdt_size;
      uint16_t pvpanic_port;
@@ -239,7 +240,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
  static void acpi_get_misc_info(AcpiMiscInfo *info)
  {
      info->has_hpet = hpet_find();
-    info->has_tpm = tpm_find();
+    info->tpm_version = tpm_get_version();
      info->pvpanic_port = pvpanic_port();
      info->applesmc_io_base = applesmc_port();
  }
@@ -468,6 +469,7 @@ build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,
  }
 
  #include "hw/i386/ssdt-tpm.hex"
+#include "hw/i386/ssdt-tpm2.hex"
 
  /* Assign BSEL property to all buses.  In the future, this can be changed
   * to only assign to buses that support hotplug.
@@ -1065,6 +1067,25 @@ build_tpm_ssdt(GArray *table_data, GArray *linker)
      memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));
  }
 
Quoted 11 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker) · line 1077

Quoted 8 lines
hw/i386/acpi-build.c +8 -0
+static void
+build_tpm2(GArray *table_data, GArray *linker)
+{
+    Acpi20TPM2 *tpm2_ptr;
+    void *tpm_ptr;
+
+    tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
+    memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));

^^^ does almost the same as build_tpm_ssdt(), replacing AML template with dynamic AML generation would help to consolidate v1 and v2 versions of build_tpm_ssdt().

Quoted 6 lines

So the SSDT's for the TPM v1.2 and TPM 2 differ, but only slightly so. What does building the AML template via Opcodes etc. help in this case? Doesn't this
make the code more or less unreadable? I don't understand why we shoudln't use
the AML compiler on it?

Generating AML code directly from C allows us to drop maintaining binary blobs for AML templates in QEMU source tree simplifying code in most cases (but sometimes it's a bit verbose). So far we've got rid of SSDT templates creating it completely from C and when I'm get my hands in remaining DSDT eventually it would be possible to drop dependency on IASL.

AML API is not operating in terms of opcodes but mostly in terms that resemble ASL.
For example look at:

8ac6f7a pc: acpi-build: drop template patching and create Device(SMC) dynamically

which I think is the closest to what is needed to convert TPM device. Also since you are building a dedicated SSDT table for TPM you might need to look at

011bb749 pc: acpi-build: use aml_scope() for \_SB scope

to see how API is initialized, but instead of generating a separate SSDT I'd suggest to move Device(TPM) generation into common SSDT (build_ssdt()).

Ask me if you have any questions regarding usage of API, I should be able to point to relevant commits.

Quoted 129 lines
Quoted 120 lines
Quoted 120 lines
hw/i386/acpi-build.c +22 -2
+
+    tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+
+    tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);
+    tpm2_ptr->control_area_address = cpu_to_le64(0);
+    tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+
+    build_header(linker, table_data,
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
+}
+
  typedef enum {
      MEM_AFFINITY_NOFLAGS      = 0,
      MEM_AFFINITY_ENABLED      = (1 << 0),
@@ -1428,12 +1449,21 @@ void acpi_build(PcGuestInfo *guest_info, AcpiBuildTables *tables)
          acpi_add_table(table_offsets, tables_blob);
          build_hpet(tables_blob, tables->linker);
      }
-    if (misc.has_tpm) {
+    if (misc.tpm_version != TPM_VERSION_UNSPEC) {
          acpi_add_table(table_offsets, tables_blob);
          build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
 
          acpi_add_table(table_offsets, tables_blob);
-        build_tpm_ssdt(tables_blob, tables->linker);
+        switch (misc.tpm_version) {
+        case TPM_VERSION_1_2:
+            build_tpm_ssdt(tables_blob, tables->linker);
+            break;
+        case TPM_VERSION_2_0:
+            build_tpm2(tables_blob, tables->linker);
+            break;
+        default:
+            assert(false);
+        }
      }
      if (guest_info->numa_nodes) {
          acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-defs.h +18 -0
index c4468f8..79ee9b1 100644
@@ -316,6 +316,9 @@ typedef struct AcpiTableMcfg AcpiTableMcfg;
 
  /*
   * TCPA Description Table
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
   */
  struct Acpi20Tcpa {
      ACPI_TABLE_HEADER_DEF                    /* ACPI common table header */
@@ -325,6 +328,21 @@ struct Acpi20Tcpa {
  } QEMU_PACKED;
  typedef struct Acpi20Tcpa Acpi20Tcpa;
 
+/*
+ * TPM2
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification
+ */
+struct Acpi20TPM2 {
+    ACPI_TABLE_HEADER_DEF
+    uint16_t platform_class;
+    uint16_t reserved;
+    uint64_t control_area_address;
+    uint32_t start_method;
+} QEMU_PACKED;
+typedef struct Acpi20TPM2 Acpi20TPM2;
+
  /* DMAR - DMA Remapping table r2.2 */
  struct AcpiTableDmar {
      ACPI_TABLE_HEADER_DEF
hw/i386/ssdt-tpm2.dsl new file +37 -0
new file mode 100644
index 0000000..96936ed
@@ -0,0 +1,44 @@
+/*
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public License along
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "hw/acpi/tpm.h"
+
+ACPI_EXTRACT_ALL_CODE ssdt_tpm2_aml
+
+DefinitionBlock (
+    "ssdt-tpm2.aml",    // Output Filename
+    "SSDT",             // Signature
+    0x01,               // SSDT Compliance Revision
+    "BXPC",             // OEMID
+    "BXSSDT",           // TABLE ID
+    0x1                 // OEM Revision
+    )
+{
+    Scope(\_SB) {
+        /* TPM with emulated TPM TIS interface */
+        Device (TPM) {
+            Name (_HID, EisaID ("PNP0C31"))
+            Name (_CRS, ResourceTemplate ()
+            {
+                Memory32Fixed (ReadWrite, TPM_TIS_ADDR_BASE, TPM_TIS_ADDR_SIZE)
+
+                /* TPM 2 is recent enough to support interrupts */
+                IRQNoFlags () {TPM_TIS_IRQ}
Quoted 8 lines

hw/i386/ssdt-tpm2.dsl line 44

Quoted 7 lines
hw/i386/ssdt-tpm2.dsl new file +7 -0
+            })
+            Method (_STA, 0, NotSerialized) {
+                Return (0x0F)
+            }
+        }
+    }
+}

Pls, don't add another ASL template.

Quoted 2 lines

Pls tell me why it is better to compile by hand rather than use a higher level language here?

It addition to above reasons creating it dynamically it would be possible to make TPM_TIS_ADDR_BASE not hardcoded throughout QEMU and SeaBIOS but configurable as tpm device property.

Quoted 85 lines

Regards,
Stefan

Quoted 80 lines

It would be better to rewrite above using AML API in C and while at it convert hw/i386/ssdt-tpm.dsl to AML API as well. hw/i386/ssdt-tpm.dsl is pretty much the same as ssdt-tpm2.aml except of IRQNoFlags() so they could share common code and for v2 you'll add extra IRQ resource.

Also I'd suggest to put TPM device under \_SB.PCI0 scope so that its _CRS wouldn't conflict with PCI0._CRS but rather be a consumer of it.

Quoted 68 lines
hw/tpm/tpm_tis.c +11 -0
index 69fbfae..daf2ac9 100644
@@ -32,6 +32,7 @@
  #include "tpm_tis.h"
  #include "qemu-common.h"
  #include "qemu/main-loop.h"
+#include "sysemu/tpm_backend.h"
 
  #define DEBUG_TIS 0
 
@@ -962,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s)
  }
 
  /*
+ * Get the TPMVersion of the backend device being used
+ */
+TPMVersion tpm_tis_get_tpm_version(Object *obj)
+{
+    TPMState *s = TPM(obj);
+
+    return tpm_backend_get_tpm_version(s->be_driver);
+}
+
+/*
   * This function is called when the machine starts, resets or due to
   * S3 resume.
   */
include/hw/acpi/tpm.h +5 -0
index 792fcbf..6d516c6 100644
@@ -26,4 +26,9 @@
  #define TPM_TCPA_ACPI_CLASS_CLIENT  0
  #define TPM_TCPA_ACPI_CLASS_SERVER  1
 
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_ACPI_CLASS_SERVER      1
+
+#define TPM2_START_METHOD_MMIO      6
+
  #endif /* HW_ACPI_TPM_H */
include/sysemu/tpm.h +9 -2
index 848df41..c143890 100644
@@ -26,11 +26,18 @@ typedef enum  TPMVersion {
      TPM_VERSION_2_0 = 2,
  } TPMVersion;
 
+TPMVersion tpm_tis_get_tpm_version(Object *obj);
+
  #define TYPE_TPM_TIS                "tpm-tis"
 
-static inline bool tpm_find(void)
+static inline TPMVersion tpm_get_version(void)
  {
-    return object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+
+    if (obj) {
+        return tpm_tis_get_tpm_version(obj);
+    }
+    return TPM_VERSION_UNSPEC;
  }
 
  #endif /* QEMU_TPM_H */
#7 lore raw

Re: [Qemu-devel] [PATCH v3 3/3] TPM2 ACPI table support

Igor Mammedov <[email protected]> wrote on 05/15/2015 12:57:40 PM:

Quoted 8 lines

From: Igor Mammedov <[email protected]>
To: Stefan Berger <[email protected]>
Cc: [email protected], [email protected], [email protected], Stefan Berger/Watson/IBM@IBMUS, Dimitrios Pendarakis/Watson/IBM@IBMUS, George Wilson/Austin/IBM@IBMUS
Date: 05/15/2015 01:07 PM
Subject: Re: [PATCH v3 3/3] TPM2 ACPI table support

Quoted 22 lines
Quoted 19 lines · On Fri, 15 May 2015 11:31:30 -0400 Stefan Berger <[email protected]>…
Quoted 18 lines · Igor Mammedov
Quoted 15 lines · On Fri, 8 May 2015 11:52:46 -0400 Stefan Berger <[email protected]>…

Add a TPM2 ACPI table if a TPM 2 is used in the backend. Also add an SSDT for the TPM 2.

Rename tpm_find() to tpm_get_version() and have this function return the version of the TPM found, TPMVersion_Unspec if no TPM is found. Use the version number to build version specific ACPI tables.

---

v2->v3:
- followed Igor's suggestion of a default case with an assert()
- added an SSDT for TPM2; it will be a bit different than

TPM1.2's

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

SSDT once we add PPI to it

---
  hw/i386/Makefile.objs |  2 +-
  hw/i386/acpi-build.c  | 38 ++++++++++++++++++++++++++++++++++----
  hw/i386/acpi-defs.h   | 18 ++++++++++++++++++
  hw/i386/ssdt-tpm2.dsl | 44 

++++++++++++++++++++++++++++++++++++++++++++

Quoted 53 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
  hw/tpm/tpm_tis.c      | 11 +++++++++++
  include/hw/acpi/tpm.h |  5 +++++
  include/sysemu/tpm.h  | 11 +++++++++--
  7 files changed, 122 insertions(+), 7 deletions(-)

create mode 100644 hw/i386/ssdt-tpm2.dsl

hw/i386/Makefile.objs +1 -1
index e058a39..0be5d97 100644
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
  obj-y += acpi-build.o
  hw/i386/acpi-build.o: hw/i386/acpi-build.c \
     hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-   hw/i386/ssdt-tpm.hex
+   hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex
 
  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
      ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +2 -1
index e761005..e648ab5 100644
@@ -42,6 +42,7 @@
  #include "hw/acpi/memory_hotplug.h"
  #include "sysemu/tpm.h"
  #include "hw/acpi/tpm.h"
+#include "sysemu/tpm_backend.h"
 
  /* Supported chipsets: */
  #include "hw/acpi/piix4.h"
@@ -111,7 +112,7 @@ typedef struct AcpiPmInfo {
 
  typedef struct AcpiMiscInfo {
      bool has_hpet;
-    bool has_tpm;
+    TPMVersion tpm_version;
      const unsigned char *dsdt_code;
      unsigned dsdt_size;
      uint16_t pvpanic_port;
@@ -239,7 +240,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
  static void acpi_get_misc_info(AcpiMiscInfo *info)
Quoted 8 lines
Quoted 8 lines

hw/i386/acpi-build.c build_madt(GArray *table_data, GArray

Quoted 8 lines
hw/i386/acpi-build.c +1 -1
  {
      info->has_hpet = hpet_find();
-    info->has_tpm = tpm_find();
+    info->tpm_version = tpm_get_version();
      info->pvpanic_port = pvpanic_port();
      info->applesmc_io_base = applesmc_port();
  }
@@ -468,6 +469,7 @@ build_madt(GArray *table_data, GArray 

*linker, AcpiCpuInfo *cpu,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/i386/acpi-build.c +0 -0
  }
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

hw/i386/acpi-build.c build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
  #include "hw/i386/ssdt-tpm.hex"
+#include "hw/i386/ssdt-tpm2.hex"
 
  /* Assign BSEL property to all buses.  In the future, this 

can be changed

Quoted 2 lines
Quoted 2 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray

Quoted 2 lines
hw/i386/acpi-build.c +0 -0
   * to only assign to buses that support hotplug.
@@ -1065,6 +1067,25 @@ build_tpm_ssdt(GArray *table_data, GArray 

*linker)

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker) · line 1077

Quoted 11 lines
hw/i386/acpi-build.c +8 -0
      memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));
  }
 
+static void
+build_tpm2(GArray *table_data, GArray *linker)
+{
+    Acpi20TPM2 *tpm2_ptr;
+    void *tpm_ptr;
+
+    tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
+    memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));

^^^ does almost the same as build_tpm_ssdt(), replacing AML template with dynamic AML generation would help to consolidate v1 and v2 versions of build_tpm_ssdt().

Quoted 2 lines
Quoted 2 lines

So the SSDT's for the TPM v1.2 and TPM 2 differ, but only slightly so. What does building the AML template via Opcodes etc. help in this

case?

Quoted 7 lines
Quoted 4 lines

Doesn't this
make the code more or less unreadable? I don't understand why we shoudln't use
the AML compiler on it?

Generating AML code directly from C allows us to drop maintaining binary blobs for AML templates in QEMU source tree simplifying code in most cases (but sometimes it's a bit verbose).

Phew, I looked at the code. It becomes quite a hurdle to contribute something in this area.
Being able to write and learn ASL is one thing, building something similar to
the ASL in C is yet another thing.

In the TPM case we have 2 SSDTs, one for TPM 1.2 and one for TPM 2. They are very similar
and could be merged into one asl code with #if around the parts that are different,
which are related to the IRQ and the check for ranges of opcodes supported. Couldn't we
use these first and then, if absolutely necessary, convert it?

Quoted 3 lines

So far we've got rid of SSDT templates creating it completely from C and when I'm get my hands in remaining DSDT eventually it would be possible to drop dependency on IASL.

IASL is from an rpm, right ? Why not use it for the simpler cases?

Quoted 12 lines

AML API is not operating in terms of opcodes but mostly in terms that resemble ASL.
For example look at:

8ac6f7a pc: acpi-build: drop template patching and create Device
(SMC) dynamically

which I think is the closest to what is needed to convert TPM device. Also since you are building a dedicated SSDT table for TPM you might need to look at

Quoted 8 lines

011bb749 pc: acpi-build: use aml_scope() for \_SB scope

to see how API is initialized, but instead of generating a separate SSDT I'd suggest to move Device(TPM) generation into common SSDT (build_ssdt()).

Ask me if you have any questions regarding usage of API, I should be able to point to relevant commits.

Stefan

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker)

Quoted 8 lines
hw/i386/acpi-build.c +4 -0
+
+    tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+
+    tpm2_ptr->platform_class = 

cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-build.c +4 -0
+    tpm2_ptr->control_area_address = cpu_to_le64(0);
+    tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+
+    build_header(linker, table_data,
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

hw/i386/acpi-build.c void acpi_build(PcGuestInfo

Quoted 7 lines
hw/i386/acpi-build.c +3 -0
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
+}
+
  typedef enum {
      MEM_AFFINITY_NOFLAGS      = 0,
      MEM_AFFINITY_ENABLED      = (1 << 0),
@@ -1428,12 +1449,21 @@ void acpi_build(PcGuestInfo 

*guest_info, AcpiBuildTables *tables)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/i386/acpi-build.c +1 -1
          acpi_add_table(table_offsets, tables_blob);
          build_hpet(tables_blob, tables->linker);
      }
-    if (misc.has_tpm) {
+    if (misc.tpm_version != TPM_VERSION_UNSPEC) {
          acpi_add_table(table_offsets, tables_blob);
          build_tpm_tcpa(tables_blob, tables->linker, 

tables->tcpalog);

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
hw/i386/acpi-build.c +10 -1
          acpi_add_table(table_offsets, tables_blob);
-        build_tpm_ssdt(tables_blob, tables->linker);
+        switch (misc.tpm_version) {
+        case TPM_VERSION_1_2:
+            build_tpm_ssdt(tables_blob, tables->linker);
+            break;
+        case TPM_VERSION_2_0:
+            build_tpm2(tables_blob, tables->linker);
+            break;
+        default:
+            assert(false);
+        }
      }
      if (guest_info->numa_nodes) {
          acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-defs.h +0 -0
index c4468f8..79ee9b1 100644
@@ -316,6 +316,9 @@ typedef struct AcpiTableMcfg AcpiTableMcfg;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

hw/i386/acpi-defs.h typedef struct AcpiTableMcfg AcpiTableMcfg;

Quoted 5 lines
hw/i386/acpi-defs.h +3 -0
  /*
   * TCPA Description Table
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * 

http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

hw/i386/acpi-defs.h typedef struct AcpiTableMcfg AcpiTableMcfg;

Quoted 3 lines
hw/i386/acpi-defs.h +0 -0
   */
  struct Acpi20Tcpa {
      ACPI_TABLE_HEADER_DEF                    /* ACPI common 

table header */

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-defs.h +0 -0
@@ -325,6 +328,21 @@ struct Acpi20Tcpa {
  } QEMU_PACKED;
  typedef struct Acpi20Tcpa Acpi20Tcpa;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

hw/i386/acpi-defs.h struct Acpi20Tcpa {

Quoted 5 lines
hw/i386/acpi-defs.h +5 -0
+/*
+ * TPM2
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * 

http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
hw/i386/acpi-defs.h +10 -0
+ */
+struct Acpi20TPM2 {
+    ACPI_TABLE_HEADER_DEF
+    uint16_t platform_class;
+    uint16_t reserved;
+    uint64_t control_area_address;
+    uint32_t start_method;
+} QEMU_PACKED;
+typedef struct Acpi20TPM2 Acpi20TPM2;
+
  /* DMAR - DMA Remapping table r2.2 */
  struct AcpiTableDmar {
      ACPI_TABLE_HEADER_DEF
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/i386/ssdt-tpm2.dsl line 2

Quoted 8 lines
hw/i386/ssdt-tpm2.dsl new file +2 -0
new file mode 100644
index 0000000..96936ed
@@ -0,0 +1,44 @@
+/*
+ * This program is free software; you can redistribute it and/or 

modify

Quoted 1 line
Quoted 1 line
Quoted 1 line

hw/i386/ssdt-tpm2.dsl line 3

Quoted 1 line
hw/i386/ssdt-tpm2.dsl new file +1 -0
+ * it under the terms of the GNU General Public License as 

published by

Quoted 1 line
Quoted 1 line
Quoted 1 line

hw/i386/ssdt-tpm2.dsl line 4

Quoted 1 line
hw/i386/ssdt-tpm2.dsl new file +1 -0
+ * the Free Software Foundation; either version 2 of the License, 

or

Quoted 24 lines
Quoted 8 lines
Quoted 8 lines

hw/i386/ssdt-tpm2.dsl

Quoted 8 lines
hw/i386/ssdt-tpm2.dsl new file +8 -0
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 

License along

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
hw/i386/ssdt-tpm2.dsl new file +15 -0
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "hw/acpi/tpm.h"
+
+ACPI_EXTRACT_ALL_CODE ssdt_tpm2_aml
+
+DefinitionBlock (
+    "ssdt-tpm2.aml",    // Output Filename
+    "SSDT",             // Signature
+    0x01,               // SSDT Compliance Revision
+    "BXPC",             // OEMID
+    "BXSSDT",           // TABLE ID
+    0x1                 // OEM Revision
+    )
+{
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines

hw/i386/ssdt-tpm2.dsl

Quoted 7 lines
hw/i386/ssdt-tpm2.dsl new file +7 -0
+    Scope(\_SB) {
+        /* TPM with emulated TPM TIS interface */
+        Device (TPM) {
+            Name (_HID, EisaID ("PNP0C31"))
+            Name (_CRS, ResourceTemplate ()
+            {
+                Memory32Fixed (ReadWrite, TPM_TIS_ADDR_BASE, 

TPM_TIS_ADDR_SIZE)

Quoted 13 lines
Quoted 11 lines

hw/i386/ssdt-tpm2.dsl line 44

Quoted 10 lines
hw/i386/ssdt-tpm2.dsl new file +10 -0
+
+                /* TPM 2 is recent enough to support interrupts */
+                IRQNoFlags () {TPM_TIS_IRQ}
+            })
+            Method (_STA, 0, NotSerialized) {
+                Return (0x0F)
+            }
+        }
+    }
+}

Pls, don't add another ASL template.

Pls tell me why it is better to compile by hand rather than use a

higher

Quoted 37 lines
Quoted 1 line

level language here?

It addition to above reasons creating it dynamically it would be possible to make TPM_TIS_ADDR_BASE not hardcoded throughout QEMU and SeaBIOS but configurable as tpm device property.

Quoted 31 lines

Regards,
Stefan

Quoted 27 lines

It would be better to rewrite above using AML API in C and while at it convert hw/i386/ssdt-tpm.dsl to AML API as well. hw/i386/ssdt-tpm.dsl is pretty much the same as ssdt-tpm2.aml except of IRQNoFlags() so they could share common code and for v2 you'll add extra IRQ resource.

Also I'd suggest to put TPM device under \_SB.PCI0 scope so that its _CRS wouldn't conflict with PCI0._CRS but rather be a consumer of it.

Quoted 15 lines
hw/tpm/tpm_tis.c +1 -0
index 69fbfae..daf2ac9 100644
@@ -32,6 +32,7 @@
  #include "tpm_tis.h"
  #include "qemu-common.h"
  #include "qemu/main-loop.h"
+#include "sysemu/tpm_backend.h"
 
  #define DEBUG_TIS 0
 
@@ -962,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s)
  }
 
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/tpm/tpm_tis.c +3 -0
  /*
+ * Get the TPMVersion of the backend device being used
+ */
+TPMVersion tpm_tis_get_tpm_version(Object *obj)
Quoted 8 lines
Quoted 8 lines

hw/tpm/tpm_tis.c static int tpm_tis_do_startup_tpm(TPMState *s)

Quoted 8 lines
hw/tpm/tpm_tis.c +7 -0
+{
+    TPMState *s = TPM(obj);
+
+    return tpm_backend_get_tpm_version(s->be_driver);
+}
+
+/*
   * This function is called when the machine starts, resets or due 

to

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
hw/tpm/tpm_tis.c +0 -0
   * S3 resume.
   */
include/hw/acpi/tpm.h +5 -0
index 792fcbf..6d516c6 100644
@@ -26,4 +26,9 @@
  #define TPM_TCPA_ACPI_CLASS_CLIENT  0
  #define TPM_TCPA_ACPI_CLASS_SERVER  1
 
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_ACPI_CLASS_SERVER      1
+
+#define TPM2_START_METHOD_MMIO      6
+
  #endif /* HW_ACPI_TPM_H */
include/sysemu/tpm.h +2 -0
index 848df41..c143890 100644
@@ -26,11 +26,18 @@ typedef enum  TPMVersion {
      TPM_VERSION_2_0 = 2,
  } TPMVersion;
 
+TPMVersion tpm_tis_get_tpm_version(Object *obj);
+
  #define TYPE_TPM_TIS                "tpm-tis"
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/sysemu/tpm.h typedef enum TPMVersion {

Quoted 5 lines
include/sysemu/tpm.h +2 -2
-static inline bool tpm_find(void)
+static inline TPMVersion tpm_get_version(void)
  {
-    return object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, 

NULL);

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
include/sysemu/tpm.h +5 -0
+
+    if (obj) {
+        return tpm_tis_get_tpm_version(obj);
+    }
+    return TPM_VERSION_UNSPEC;
  }
 
  #endif /* QEMU_TPM_H */
#8 lore raw

Re: [Qemu-devel] [PATCH v3 3/3] TPM2 ACPI table support

Quoted 127 lines · On Fri, 15 May 2015 15:13:14 -0400 Stefan Berger <[email protected]> wrote:

Igor Mammedov <[email protected]> wrote on 05/15/2015 12:57:40 PM:

Quoted 8 lines

From: Igor Mammedov <[email protected]>
To: Stefan Berger <[email protected]>
Cc: [email protected], [email protected], [email protected], Stefan Berger/Watson/IBM@IBMUS, Dimitrios Pendarakis/Watson/IBM@IBMUS, George Wilson/Austin/IBM@IBMUS
Date: 05/15/2015 01:07 PM
Subject: Re: [PATCH v3 3/3] TPM2 ACPI table support

Quoted 22 lines
Quoted 19 lines · On Fri, 15 May 2015 11:31:30 -0400 Stefan Berger <[email protected]>…
Quoted 18 lines · Igor Mammedov
Quoted 15 lines · On Fri, 8 May 2015 11:52:46 -0400 Stefan Berger <[email protected]>…

Add a TPM2 ACPI table if a TPM 2 is used in the backend. Also add an SSDT for the TPM 2.

Rename tpm_find() to tpm_get_version() and have this function return the version of the TPM found, TPMVersion_Unspec if no TPM is found. Use the version number to build version specific ACPI tables.

---

v2->v3:
- followed Igor's suggestion of a default case with an assert()
- added an SSDT for TPM2; it will be a bit different than

TPM1.2's

Quoted 6 lines
Quoted 6 lines
Quoted 6 lines
Quoted 6 lines

SSDT once we add PPI to it

---
  hw/i386/Makefile.objs |  2 +-
  hw/i386/acpi-build.c  | 38 ++++++++++++++++++++++++++++++++++----
  hw/i386/acpi-defs.h   | 18 ++++++++++++++++++
  hw/i386/ssdt-tpm2.dsl | 44 

++++++++++++++++++++++++++++++++++++++++++++

Quoted 53 lines
Quoted 42 lines
Quoted 42 lines
Quoted 42 lines
  hw/tpm/tpm_tis.c      | 11 +++++++++++
  include/hw/acpi/tpm.h |  5 +++++
  include/sysemu/tpm.h  | 11 +++++++++--
  7 files changed, 122 insertions(+), 7 deletions(-)

create mode 100644 hw/i386/ssdt-tpm2.dsl

hw/i386/Makefile.objs +1 -1
index e058a39..0be5d97 100644
@@ -9,7 +9,7 @@ obj-y += kvmvapic.o
  obj-y += acpi-build.o
  hw/i386/acpi-build.o: hw/i386/acpi-build.c \
     hw/i386/acpi-dsdt.hex hw/i386/q35-acpi-dsdt.hex \
-   hw/i386/ssdt-tpm.hex
+   hw/i386/ssdt-tpm.hex hw/i386/ssdt-tpm2.hex
 
  iasl-option=$(shell if test -z "`$(1) $(2) 2>&1 > /dev/null`" \
      ; then echo "$(2)"; else echo "$(3)"; fi ;)
hw/i386/acpi-build.c +2 -1
index e761005..e648ab5 100644
@@ -42,6 +42,7 @@
  #include "hw/acpi/memory_hotplug.h"
  #include "sysemu/tpm.h"
  #include "hw/acpi/tpm.h"
+#include "sysemu/tpm_backend.h"
 
  /* Supported chipsets: */
  #include "hw/acpi/piix4.h"
@@ -111,7 +112,7 @@ typedef struct AcpiPmInfo {
 
  typedef struct AcpiMiscInfo {
      bool has_hpet;
-    bool has_tpm;
+    TPMVersion tpm_version;
      const unsigned char *dsdt_code;
      unsigned dsdt_size;
      uint16_t pvpanic_port;
@@ -239,7 +240,7 @@ static void acpi_get_pm_info(AcpiPmInfo *pm)
  static void acpi_get_misc_info(AcpiMiscInfo *info)
Quoted 8 lines
Quoted 8 lines

hw/i386/acpi-build.c build_madt(GArray *table_data, GArray

Quoted 8 lines
hw/i386/acpi-build.c +1 -1
  {
      info->has_hpet = hpet_find();
-    info->has_tpm = tpm_find();
+    info->tpm_version = tpm_get_version();
      info->pvpanic_port = pvpanic_port();
      info->applesmc_io_base = applesmc_port();
  }
@@ -468,6 +469,7 @@ build_madt(GArray *table_data, GArray 

*linker, AcpiCpuInfo *cpu,

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
hw/i386/acpi-build.c +0 -0
  }
 
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

hw/i386/acpi-build.c build_madt(GArray *table_data, GArray *linker, AcpiCpuInfo *cpu,

Quoted 4 lines
hw/i386/acpi-build.c +1 -0
  #include "hw/i386/ssdt-tpm.hex"
+#include "hw/i386/ssdt-tpm2.hex"
 
  /* Assign BSEL property to all buses.  In the future, this 

can be changed

Quoted 2 lines
Quoted 2 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray

Quoted 2 lines
hw/i386/acpi-build.c +0 -0
   * to only assign to buses that support hotplug.
@@ -1065,6 +1067,25 @@ build_tpm_ssdt(GArray *table_data, GArray 

*linker)

Quoted 15 lines
Quoted 15 lines
Quoted 14 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker) · line 1077

Quoted 11 lines
hw/i386/acpi-build.c +8 -0
      memcpy(tpm_ptr, ssdt_tpm_aml, sizeof(ssdt_tpm_aml));
  }
 
+static void
+build_tpm2(GArray *table_data, GArray *linker)
+{
+    Acpi20TPM2 *tpm2_ptr;
+    void *tpm_ptr;
+
+    tpm_ptr = acpi_data_push(table_data, sizeof(ssdt_tpm2_aml));
+    memcpy(tpm_ptr, ssdt_tpm2_aml, sizeof(ssdt_tpm2_aml));

^^^ does almost the same as build_tpm_ssdt(), replacing AML template with dynamic AML generation would help to consolidate v1 and v2 versions of build_tpm_ssdt().

Quoted 2 lines
Quoted 2 lines

So the SSDT's for the TPM v1.2 and TPM 2 differ, but only slightly so. What does building the AML template via Opcodes etc. help in this

case?

Quoted 7 lines
Quoted 4 lines

Doesn't this
make the code more or less unreadable? I don't understand why we shoudln't use
the AML compiler on it?

Generating AML code directly from C allows us to drop maintaining binary blobs for AML templates in QEMU source tree simplifying code in most cases (but sometimes it's a bit verbose).

Quoted 5 lines

Phew, I looked at the code. It becomes quite a hurdle to contribute something in this area.
Being able to write and learn ASL is one thing, building something similar to
the ASL in C is yet another thing.

for current TPM conversion it's trivial (including TPM2):

+ scope = aml_scope("\\_SB.PCI0");
+ dev = aml_device("TPM");
+

+        aml_append(dev, aml_name_decl("_HID", aml_eisaid("PNP0C31")));
+        /* device present, functioning, decoding, not shown in UI */
+        aml_append(dev, aml_name_decl("_STA", aml_int(0xB)));

+
+ crs = aml_resource_template();
+ aml_append(crs,
+ aml_memory32_fixed(TPM_TIS_ADDR_BASE, TPM_TIS_ADDR_SIZE, aml_ReadWrite)
+ );
+ if (tpm2) {
+ aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ));

+        }
+        aml_append(dev, aml_name_decl("_CRS", crs));
+        aml_append(scope, dev);

+
+ aml_append(ssdt, scope);

aml_memory32_fixed is not in mainline yet, but should be there soon:
"[PATCH v6 04/22] hw/acpi/aml-build: Add aml_memory32_fixed() term"

Quoted 7 lines

In the TPM case we have 2 SSDTs, one for TPM 1.2 and one for TPM 2. They are very similar
and could be merged into one asl code with #if around the parts that are different,
which are related to the IRQ and the check for ranges of opcodes supported. Couldn't we
use these first and then, if absolutely necessary, convert it?

you might have noticed, a new ARM ACPI patches don't use templates at all and use only C API to build tables.
x86 ASL parts in process of converting, it would be nice not to add more conversion material.

Quoted 5 lines
Quoted 3 lines

So far we've got rid of SSDT templates creating it completely from C and when I'm get my hands in remaining DSDT eventually it would be possible to drop dependency on IASL.

IASL is from an rpm, right ? Why not use it for the simpler cases?

Maintaining binary template blobs is hassle, there were numerous cases when master tree build failed or didn't work as expected after ACPI patches were pulled in, since developer and maintainers usually have IASL on their boxes and forget about need to update blobs as well. Dropping dependency on IASL and precompiled blobs helps us to make less mistakes here.

Quoted 261 lines
Quoted 11 lines

AML API is not operating in terms of opcodes but mostly in terms that resemble ASL.
For example look at:

8ac6f7a pc: acpi-build: drop template patching and create Device
(SMC) dynamically

which I think is the closest to what is needed to convert TPM device. Also since you are building a dedicated SSDT table for TPM you might need to look at

Quoted 8 lines

011bb749 pc: acpi-build: use aml_scope() for \_SB scope

to see how API is initialized, but instead of generating a separate SSDT I'd suggest to move Device(TPM) generation into common SSDT (build_ssdt()).

Ask me if you have any questions regarding usage of API, I should be able to point to relevant commits.

Stefan

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/i386/acpi-build.c build_tpm_ssdt(GArray *table_data, GArray *linker)

Quoted 8 lines
hw/i386/acpi-build.c +4 -0
+
+    tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr);
+
+    tpm2_ptr->platform_class = 

cpu_to_le16(TPM2_ACPI_CLASS_CLIENT);

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-build.c +4 -0
+    tpm2_ptr->control_area_address = cpu_to_le64(0);
+    tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO);
+
+    build_header(linker, table_data,
Quoted 15 lines
Quoted 7 lines
Quoted 7 lines

hw/i386/acpi-build.c void acpi_build(PcGuestInfo

Quoted 7 lines
hw/i386/acpi-build.c +3 -0
+                 (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4);
+}
+
  typedef enum {
      MEM_AFFINITY_NOFLAGS      = 0,
      MEM_AFFINITY_ENABLED      = (1 << 0),
@@ -1428,12 +1449,21 @@ void acpi_build(PcGuestInfo 

*guest_info, AcpiBuildTables *tables)

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
hw/i386/acpi-build.c +1 -1
          acpi_add_table(table_offsets, tables_blob);
          build_hpet(tables_blob, tables->linker);
      }
-    if (misc.has_tpm) {
+    if (misc.tpm_version != TPM_VERSION_UNSPEC) {
          acpi_add_table(table_offsets, tables_blob);
          build_tpm_tcpa(tables_blob, tables->linker, 

tables->tcpalog);

Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
hw/i386/acpi-build.c +10 -1
          acpi_add_table(table_offsets, tables_blob);
-        build_tpm_ssdt(tables_blob, tables->linker);
+        switch (misc.tpm_version) {
+        case TPM_VERSION_1_2:
+            build_tpm_ssdt(tables_blob, tables->linker);
+            break;
+        case TPM_VERSION_2_0:
+            build_tpm2(tables_blob, tables->linker);
+            break;
+        default:
+            assert(false);
+        }
      }
      if (guest_info->numa_nodes) {
          acpi_add_table(table_offsets, tables_blob);
hw/i386/acpi-defs.h +0 -0
index c4468f8..79ee9b1 100644
@@ -316,6 +316,9 @@ typedef struct AcpiTableMcfg AcpiTableMcfg;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

hw/i386/acpi-defs.h typedef struct AcpiTableMcfg AcpiTableMcfg;

Quoted 5 lines
hw/i386/acpi-defs.h +3 -0
  /*
   * TCPA Description Table
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * 

http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

hw/i386/acpi-defs.h typedef struct AcpiTableMcfg AcpiTableMcfg;

Quoted 3 lines
hw/i386/acpi-defs.h +0 -0
   */
  struct Acpi20Tcpa {
      ACPI_TABLE_HEADER_DEF                    /* ACPI common 

table header */

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/i386/acpi-defs.h +0 -0
@@ -325,6 +328,21 @@ struct Acpi20Tcpa {
  } QEMU_PACKED;
  typedef struct Acpi20Tcpa Acpi20Tcpa;
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

hw/i386/acpi-defs.h struct Acpi20Tcpa {

Quoted 5 lines
hw/i386/acpi-defs.h +5 -0
+/*
+ * TPM2
+ *
+ * Following Level 00, Rev 00.37 of specs:
+ * 

http://www.trustedcomputinggroup.org/resources/tcg_acpi_specification

Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
Quoted 13 lines
hw/i386/acpi-defs.h +10 -0
+ */
+struct Acpi20TPM2 {
+    ACPI_TABLE_HEADER_DEF
+    uint16_t platform_class;
+    uint16_t reserved;
+    uint64_t control_area_address;
+    uint32_t start_method;
+} QEMU_PACKED;
+typedef struct Acpi20TPM2 Acpi20TPM2;
+
  /* DMAR - DMA Remapping table r2.2 */
  struct AcpiTableDmar {
      ACPI_TABLE_HEADER_DEF
Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

hw/i386/ssdt-tpm2.dsl line 2

Quoted 8 lines
hw/i386/ssdt-tpm2.dsl new file +2 -0
new file mode 100644
index 0000000..96936ed
@@ -0,0 +1,44 @@
+/*
+ * This program is free software; you can redistribute it and/or 

modify

Quoted 1 line
Quoted 1 line
Quoted 1 line

hw/i386/ssdt-tpm2.dsl line 3

Quoted 1 line
hw/i386/ssdt-tpm2.dsl new file +1 -0
+ * it under the terms of the GNU General Public License as 

published by

Quoted 1 line
Quoted 1 line
Quoted 1 line

hw/i386/ssdt-tpm2.dsl line 4

Quoted 1 line
hw/i386/ssdt-tpm2.dsl new file +1 -0
+ * the Free Software Foundation; either version 2 of the License, 

or

Quoted 24 lines
Quoted 8 lines
Quoted 8 lines

hw/i386/ssdt-tpm2.dsl

Quoted 8 lines
hw/i386/ssdt-tpm2.dsl new file +8 -0
+ * (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+
+ * You should have received a copy of the GNU General Public 

License along

Quoted 15 lines
Quoted 15 lines
Quoted 15 lines
hw/i386/ssdt-tpm2.dsl new file +15 -0
+ * with this program; if not, see <http://www.gnu.org/licenses/>.
+ */
+#include "hw/acpi/tpm.h"
+
+ACPI_EXTRACT_ALL_CODE ssdt_tpm2_aml
+
+DefinitionBlock (
+    "ssdt-tpm2.aml",    // Output Filename
+    "SSDT",             // Signature
+    0x01,               // SSDT Compliance Revision
+    "BXPC",             // OEMID
+    "BXSSDT",           // TABLE ID
+    0x1                 // OEM Revision
+    )
+{
Quoted 21 lines
Quoted 7 lines
Quoted 7 lines

hw/i386/ssdt-tpm2.dsl

Quoted 7 lines
hw/i386/ssdt-tpm2.dsl new file +7 -0
+    Scope(\_SB) {
+        /* TPM with emulated TPM TIS interface */
+        Device (TPM) {
+            Name (_HID, EisaID ("PNP0C31"))
+            Name (_CRS, ResourceTemplate ()
+            {
+                Memory32Fixed (ReadWrite, TPM_TIS_ADDR_BASE, 

TPM_TIS_ADDR_SIZE)

Quoted 13 lines
Quoted 11 lines

hw/i386/ssdt-tpm2.dsl line 44

Quoted 10 lines
hw/i386/ssdt-tpm2.dsl new file +10 -0
+
+                /* TPM 2 is recent enough to support interrupts */
+                IRQNoFlags () {TPM_TIS_IRQ}
+            })
+            Method (_STA, 0, NotSerialized) {
+                Return (0x0F)
+            }
+        }
+    }
+}

Pls, don't add another ASL template.

Pls tell me why it is better to compile by hand rather than use a

higher

Quoted 37 lines
Quoted 1 line

level language here?

It addition to above reasons creating it dynamically it would be possible to make TPM_TIS_ADDR_BASE not hardcoded throughout QEMU and SeaBIOS but configurable as tpm device property.

Quoted 31 lines

Regards,
Stefan

Quoted 27 lines

It would be better to rewrite above using AML API in C and while at it convert hw/i386/ssdt-tpm.dsl to AML API as well. hw/i386/ssdt-tpm.dsl is pretty much the same as ssdt-tpm2.aml except of IRQNoFlags() so they could share common code and for v2 you'll add extra IRQ resource.

Also I'd suggest to put TPM device under \_SB.PCI0 scope so that its _CRS wouldn't conflict with PCI0._CRS but rather be a consumer of it.

Quoted 15 lines
hw/tpm/tpm_tis.c +1 -0
index 69fbfae..daf2ac9 100644
@@ -32,6 +32,7 @@
  #include "tpm_tis.h"
  #include "qemu-common.h"
  #include "qemu/main-loop.h"
+#include "sysemu/tpm_backend.h"
 
  #define DEBUG_TIS 0
 
@@ -962,6 +963,16 @@ static int tpm_tis_do_startup_tpm(TPMState *s)
  }
 
Quoted 12 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
hw/tpm/tpm_tis.c +3 -0
  /*
+ * Get the TPMVersion of the backend device being used
+ */
+TPMVersion tpm_tis_get_tpm_version(Object *obj)
Quoted 8 lines
Quoted 8 lines

hw/tpm/tpm_tis.c static int tpm_tis_do_startup_tpm(TPMState *s)

Quoted 8 lines
hw/tpm/tpm_tis.c +7 -0
+{
+    TPMState *s = TPM(obj);
+
+    return tpm_backend_get_tpm_version(s->be_driver);
+}
+
+/*
   * This function is called when the machine starts, resets or due 

to

Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
hw/tpm/tpm_tis.c +0 -0
   * S3 resume.
   */
include/hw/acpi/tpm.h +5 -0
index 792fcbf..6d516c6 100644
@@ -26,4 +26,9 @@
  #define TPM_TCPA_ACPI_CLASS_CLIENT  0
  #define TPM_TCPA_ACPI_CLASS_SERVER  1
 
+#define TPM2_ACPI_CLASS_CLIENT      0
+#define TPM2_ACPI_CLASS_SERVER      1
+
+#define TPM2_START_METHOD_MMIO      6
+
  #endif /* HW_ACPI_TPM_H */
include/sysemu/tpm.h +2 -0
index 848df41..c143890 100644
@@ -26,11 +26,18 @@ typedef enum  TPMVersion {
      TPM_VERSION_2_0 = 2,
  } TPMVersion;
 
+TPMVersion tpm_tis_get_tpm_version(Object *obj);
+
  #define TYPE_TPM_TIS                "tpm-tis"
 
Quoted 5 lines
Quoted 5 lines
Quoted 5 lines

include/sysemu/tpm.h typedef enum TPMVersion {

Quoted 5 lines
include/sysemu/tpm.h +2 -2
-static inline bool tpm_find(void)
+static inline TPMVersion tpm_get_version(void)
  {
-    return object_resolve_path_type("", TYPE_TPM_TIS, NULL);
+    Object *obj = object_resolve_path_type("", TYPE_TPM_TIS, 

NULL);

Quoted 10 lines
Quoted 9 lines
Quoted 8 lines
Quoted 8 lines
include/sysemu/tpm.h +5 -0
+
+    if (obj) {
+        return tpm_tis_get_tpm_version(obj);
+    }
+    return TPM_VERSION_UNSPEC;
  }
 
  #endif /* QEMU_TPM_H */