tpm: Upgrade TPM TIS for support of a TPM 2
v4 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-tpm-common.dsl | 36 ++++++++++++ hw/i386/ssdt-tpm.dsl | 16 +---- hw/i386/ssdt-tpm.hex.generated | 26 +++++++-- hw/i386/ssdt-tpm2.dsl | 29 +++++++++ hw/i386/ssdt-tpm2.hex.generated | 109 ++++++++++++++++++++++++++++++++++ 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 ++++++++ 19 files changed, 594 insertions(+), 87 deletions(-) create mode 100644 hw/i386/ssdt-tpm-common.dsl create mode 100644 hw/i386/ssdt-tpm2.dsl create mode 100644 hw/i386/ssdt-tpm2.hex.generated create mode 100644 hw/tpm/tpm_util.c create mode 100644 hw/tpm/tpm_util.h
Signature · 1 line
1.9.3
PATCH v4 1/3 Extend TPM TIS interface to support TPM 2
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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
PATCH v4 3/3 TPM2 ACPI table support
In reply to Stefan BergerAdd 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.
---
v3->v4:
- added .hex.generated files
- SSDT's for TPM v1.2 and TPM 2 now use common code via #include (enabling IRQ for TPM v1.2)
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-tpm-common.dsl | 36 +++++++++++++ hw/i386/ssdt-tpm.dsl | 16 +----- hw/i386/ssdt-tpm.hex.generated | 26 +++++++--- hw/i386/ssdt-tpm2.dsl | 29 +++++++++++ hw/i386/ssdt-tpm2.hex.generated | 109 ++++++++++++++++++++++++++++++++++++++++ hw/tpm/tpm_tis.c | 11 ++++ include/hw/acpi/tpm.h | 5 ++ include/sysemu/tpm.h | 11 +++- 11 files changed, 273 insertions(+), 28 deletions(-) create mode 100644 hw/i386/ssdt-tpm-common.dsl create mode 100644 hw/i386/ssdt-tpm2.dsl create mode 100644 hw/i386/ssdt-tpm2.hex.generated
hw/i386/Makefile.objs +1 -1
@@ -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
@@ -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
@@ -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-tpm-common.dsl new file +36 -0
@@ -0,0 +1,36 @@ +/* + * 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/>. + */ + +/* + * Common parts for TPM 1.2 and TPM 2 (with slight differences for PPI) + * to be #included + */ + + + External(\_SB.PCI0.ISA, DeviceObj) + Scope(\_SB.PCI0.ISA) { + /* 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) + IRQNoFlags () {TPM_TIS_IRQ} + }) + Method (_STA, 0, NotSerialized) { + Return (0x0F) + } + } + }
hw/i386/ssdt-tpm.dsl +1 -15
@@ -25,19 +25,5 @@ DefinitionBlock ( 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) - // older Linux tpm_tis drivers do not work with IRQ - //IRQNoFlags () {TPM_TIS_IRQ} - }) - Method (_STA, 0, NotSerialized) { - Return (0x0F) - } - } - } +#include "ssdt-tpm-common.dsl" }
hw/i386/ssdt-tpm.hex.generated +20 -6
@@ -3,12 +3,12 @@ static unsigned char ssdt_tpm_aml[] = { 0x53, 0x44, 0x54, -0x5d, +0x6b, 0x0, 0x0, 0x0, 0x1, -0x1c, +0x37, 0x42, 0x58, 0x50,
@@ -36,15 +36,26 @@ static unsigned char ssdt_tpm_aml[] = { 0x14, 0x20, 0x10, -0x38, +0x46, +0x4, 0x5c, +0x2f, +0x3, 0x5f, 0x53, 0x42, 0x5f, +0x50, +0x43, +0x49, +0x30, +0x49, +0x53, +0x41, +0x5f, 0x5b, 0x82, -0x30, +0x33, 0x54, 0x50, 0x4d,
@@ -65,9 +76,9 @@ static unsigned char ssdt_tpm_aml[] = { 0x52, 0x53, 0x11, -0x11, +0x14, 0xa, -0xe, +0x11, 0x86, 0x9, 0x0,
@@ -80,6 +91,9 @@ static unsigned char ssdt_tpm_aml[] = { 0x50, 0x0, 0x0, +0x22, +0x20, +0x0, 0x79, 0x0, 0x14,
hw/i386/ssdt-tpm2.dsl new file +29 -0
@@ -0,0 +1,29 @@ +/* + * 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 + ) +{ +#include "ssdt-tpm-common.dsl" +}
hw/i386/ssdt-tpm2.hex.generated new file +109 -0
109 lines not on this page · raw message
hw/tpm/tpm_tis.c +11 -0
@@ -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
@@ -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
@@ -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
PATCH v4 2/3 tpm: Probe for connected TPM 1.2 or TPM 2
In reply to Stefan BergerIn 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
@@ -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
@@ -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
@@ -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