Add support for TPM Physical Presence interface
v13 cover Add support for TPM Physical Presence interface
Hi,
The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware looks for and acts upon by sending sequences of commands to the TPM.
A dedicated memory region is added to the TPM CRB & TIS devices, at address/size 0xFED45000/0x400. A new "etc/tpm/config" fw_cfg entry holds the location for that PPI region and some version details, to allow for future flexibility.
With the associated edk2/ovmf firmware, the Windows HLK "PPI 1.3" test now runs successfully.
It is based on previous work from Stefan Berger ("[PATCH v2 0/4] Implement Physical Presence interface for TPM 1.2 and 2")
The edk2 support is merged upstream.
v13:
- removed needless error handling in tpm_ppi_init()
- splitted "add ACPI memory clear interface"
- moved acpi build function in dedicated hw/acpi/tpm.c
- added some function documentation in headers
- various code cleanups suggested by Philippe
- rebased
Marc-André Lureau (3):
tpm: add a "ppi" boolean property
acpi: add ACPI memory clear interface
tpm: clear RAM when "memory overwrite" requested
Stefan Berger (3):
tpm: allocate/map buffer for TPM Physical Presence interface
acpi: expose TPM/PPI configuration parameters to firmware via fw_cfg
acpi: build TPM Physical Presence interface
hw/tpm/tpm_ppi.h | 47 +++++ include/hw/acpi/tpm.h | 23 +++ include/hw/compat.h | 11 +- hw/acpi/tpm.c | 447 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 29 ++- hw/tpm/tpm_crb.c | 11 ++ hw/tpm/tpm_ppi.c | 53 +++++ hw/tpm/tpm_tis.c | 11 ++ docs/specs/tpm.txt | 104 ++++++++++ hw/acpi/Makefile.objs | 1 + hw/tpm/Makefile.objs | 1 + hw/tpm/trace-events | 3 + 12 files changed, 738 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/acpi/tpm.c create mode 100644 hw/tpm/tpm_ppi.c
Signature · 1 line
2.20.0
PATCH v13 1/6 tpm: add a "ppi" boolean property
The following patches implement the TPM Physical Presence Interface, make use of a new memory region and a fw_cfg entry. Enable PPI by default with >=4.0 machine type, to avoid migration issues.
--- include/hw/compat.h | 11 ++++++++++- hw/tpm/tpm_crb.c | 3 +++ hw/tpm/tpm_tis.c | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-)
include/hw/compat.h +10 -1
@@ -2,7 +2,16 @@#define HW_COMPAT_H #define HW_COMPAT_3_1 \ -/* empty */ + { \ + .driver = "tpm-crb", \ + .property = "ppi", \ + .value = "false", \ + }, \ + { \ + .driver = "tpm-tis", \ + .property = "ppi", \ + .value = "false", \ + },#define HW_COMPAT_3_0 \/* empty */
hw/tpm/tpm_crb.c +3 -0
@@ -41,6 +41,8 @@ typedef struct CRBState {MemoryRegion cmdmem;size_t be_buffer_size; + +bool ppi_enabled; } CRBState;#define CRB (obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB)
@@ -221,6 +223,7 @@ static const VMStateDescription vmstate_tpm_crb = {static Property tpm_crb_properties[] = {DEFINE_PROP_TPMBE ("tpmdev" , CRBState, tpmbe), +DEFINE_PROP_BOOL ("ppi" , CRBState, ppi_enabled, true),DEFINE_PROP_END_OF_LIST (), };
hw/tpm/tpm_tis.c +3 -0
@@ -81,6 +81,8 @@ typedef struct TPMState {TPMVersion be_tpm_version;size_t be_buffer_size; + +bool ppi_enabled; } TPMState;#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)
@@ -950,6 +952,7 @@ static const VMStateDescription vmstate_tpm_tis = {static Property tpm_tis_properties[] = {DEFINE_PROP_UINT32 ("irq" , TPMState, irq_num,TPM_TIS_IRQ ),DEFINE_PROP_TPMBE ("tpmdev" , TPMState, be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMState, ppi_enabled, true),DEFINE_PROP_END_OF_LIST (), };
Signature · 1 line
2.20.0
Re: [Qemu-devel] [PATCH v13 1/6] tpm: add a "ppi" boolean property
Quoted 6 lines · Marc-André Lureau
The following patches implement the TPM Physical Presence Interface, make use of a new memory region and a
fw_cfgentry. Enable PPI by default with >=4.0 machine type, to avoid migration issues.Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Igor Mammedov <[email protected]>
Quoted 71 lines
--- include/hw/compat.h | 11 ++++++++++- hw/tpm/tpm_crb.c | 3 +++ hw/tpm/tpm_tis.c | 3 +++ 3 files changed, 16 insertions(+), 1 deletion(-)include/hw/compat.h +10
-1@@ -2,7 +2,16 @@#define HW_COMPAT_H #define HW_COMPAT_3_1 \ -/* empty */ + { \ + .driver = "tpm-crb", \ + .property = "ppi", \ + .value = "false", \ + }, \ + { \ + .driver = "tpm-tis", \ + .property = "ppi", \ + .value = "false", \ + },#define HW_COMPAT_3_0 \/* empty */ hw/tpm/tpm_crb.c +3
-0@@ -41,6 +41,8 @@ typedef struct CRBState {MemoryRegion cmdmem;size_t be_buffer_size; + +bool ppi_enabled; } CRBState;#define CRB (obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB)@@ -221,6 +223,7 @@ static const VMStateDescription vmstate_tpm_crb = {static Property tpm_crb_properties[] = {DEFINE_PROP_TPMBE ("tpmdev" , CRBState, tpmbe), +DEFINE_PROP_BOOL ("ppi" , CRBState, ppi_enabled, true),DEFINE_PROP_END_OF_LIST (), };hw/tpm/tpm_tis.c +3
-0@@ -81,6 +81,8 @@ typedef struct TPMState {TPMVersion be_tpm_version;size_t be_buffer_size; + +bool ppi_enabled; } TPMState;#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)@@ -950,6 +952,7 @@ static const VMStateDescription vmstate_tpm_tis = {static Property tpm_tis_properties[] = {DEFINE_PROP_UINT32 ("irq" , TPMState, irq_num,TPM_TIS_IRQ ),DEFINE_PROP_TPMBE ("tpmdev" , TPMState, be_driver), +DEFINE_PROP_BOOL ("ppi" , TPMState, ppi_enabled, true),DEFINE_PROP_END_OF_LIST (), };
PATCH v13 2/6 tpm: allocate/map buffer for TPM Physical Presence interface
In reply to Marc-André LureauFrom: Stefan Berger <[email protected]>
Implement a virtual memory device for the TPM Physical Presence interface. The memory is located at 0xFED45000 and used by ACPI to send messages to the firmware (BIOS) and by the firmware to provide parameters for each one of the supported codes.
This interface should be used by all TPM devices on x86 and can be added by calling tpm_ppi_init_io().
Note: bios_linker cannot be used to allocate the PPI memory region, since the reserved memory should stay stable across reboots, and might be needed before the ACPI tables are installed.
--- hw/tpm/tpm_ppi.h | 37 +++++++++++++++++++++++++++++++++++++ include/hw/acpi/tpm.h | 6 ++++++ hw/tpm/tpm_crb.c | 7 +++++++ hw/tpm/tpm_ppi.c | 31 +++++++++++++++++++++++++++++++ hw/tpm/tpm_tis.c | 7 +++++++ hw/tpm/Makefile.objs | 1 + 6 files changed, 89 insertions(+) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/tpm/tpm_ppi.c
hw/tpm/tpm_ppi.h new file +37 -0
@@ -0,0 +1,37 @@ +/* +* TPM Physical Presence Interface +* +* Copyright (C) 2018 IBM Corporation +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef TPM_TPM_PPI_H +#define TPM_TPM_PPI_H + +#include "hw/acpi/tpm.h" +#include "exec/address-spaces.h" + +typedef struct TPMPPI { +MemoryRegion ram; +uint8_t *buf; +}TPMPPI ; + +/** +* tpm_ppi_init: +* @tpmppi: a TPMPPI +* @m: the address-space / MemoryRegion to use +* @addr: the address of the PPI region +* @obj: the owner object +* @errp: an Error** +* +* Register the TPM PPI memory region at @addr on the given address +* space for the object @obj. +**/ +void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m, +hwaddr addr,Object *obj); + +#endif /* TPM_TPM_PPI_H */
include/hw/acpi/tpm.h +6 -0
@@ -188,4 +188,10 @@ REG32(CRB_DATA_BUFFER, 0x80)#define TPM2_START_METHOD_MMIO 6#define TPM2_START_METHOD_CRB 7 +/* +* Physical Presence Interface +*/ +#define TPM_PPI_ADDR_SIZE 0x400 +#define TPM_PPI_ADDR_BASE 0xFED45000 +#endif /* HW_ACPI_TPM_H */
hw/tpm/tpm_crb.c +7 -0
@@ -29,6 +29,7 @@#include "sysemu/reset.h" #include "tpm_int.h" #include "tpm_util.h" +#include "tpm_ppi.h" #include "trace.h" typedef struct CRBState {
@@ -43,6 +44,7 @@ typedef struct CRBState {size_t be_buffer_size;bool ppi_enabled; +TPMPPI ppi; } CRBState;#define CRB (obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB)
@@ -294,6 +296,11 @@ static void tpm_crb_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (get_system_memory (),TPM_CRB_ADDR_BASE +sizeof (s->regs), &s->cmdmem); +if (s->ppi_enabled) { +tpm_ppi_init (&s->ppi,get_system_memory (), +TPM_PPI_ADDR_BASE ,OBJECT (s)); + } +qemu_register_reset (tpm_crb_reset, dev); }
hw/tpm/tpm_ppi.c new file +31 -0
@@ -0,0 +1,31 @@ +/* +* tpm_ppi.c - TPM Physical Presence Interface +* +* Copyright (C) 2018 IBM Corporation +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" + +#include "qapi/error.h" +#include "cpu.h" +#include "sysemu/memory_mapping.h" +#include "migration/vmstate.h" +#include "tpm_ppi.h" + +void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m, +hwaddr addr,Object *obj) +{ + tpmppi->buf =g_malloc0 (HOST_PAGE_ALIGN (TPM_PPI_ADDR_SIZE )); +memory_region_init_ram_device_ptr (&tpmppi->ram, obj,"tpm-ppi" , +TPM_PPI_ADDR_SIZE , tpmppi->buf); +vmstate_register_ram (&tpmppi->ram,DEVICE (obj)); + +memory_region_add_subregion (m, addr, &tpmppi->ram); +}
hw/tpm/tpm_tis.c +7 -0
@@ -31,6 +31,7 @@#include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "tpm_util.h" +#include "tpm_ppi.h" #include "trace.h" #define TPM_TIS_NUM_LOCALITIES 5/* per spec */
@@ -83,6 +84,7 @@ typedef struct TPMState {size_t be_buffer_size;bool ppi_enabled; +TPMPPI ppi; } TPMState;#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)
@@ -979,6 +981,11 @@ static void tpm_tis_realizefn(DeviceState *dev, Error **errp)memory_region_add_subregion (isa_address_space (ISA_DEVICE (dev)),TPM_TIS_ADDR_BASE , &s->mmio); + +if (s->ppi_enabled) { +tpm_ppi_init (&s->ppi,isa_address_space (ISA_DEVICE (dev)), +TPM_PPI_ADDR_BASE ,OBJECT (s)); + } }static void tpm_tis_initfn (Object *obj)
hw/tpm/Makefile.objs +1 -0
@@ -1,4 +1,5 @@ common-obj-y += tpm_util.o +obj-y += tpm_ppi.o common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
Signature · 1 line
2.20.0
Re: [Qemu-devel] [PATCH v13 2/6] tpm: allocate/map buffer for TPM Physical Presence interface
Quoted 53 lines · Marc-André Lureau
From: Stefan Berger <[email protected]>
Implement a virtual memory device for the TPM Physical Presence interface. The memory is located at
0xFED45000and used by ACPI to send messages to the firmware (BIOS) and by the firmware to provide parameters for each one of the supported codes.This interface should be used by all TPM devices on x86 and can be added by calling
tpm_ppi_init_io().Note:
bios_linkercannot be used to allocate the PPI memory region, since the reserved memory should stay stable across reboots, and might be needed before the ACPI tables are installed.Signed-off-by Stefan Berger <[email protected]>Signed-off-by Marc-André Lureau <[email protected]>Reviewed-by Igor Mammedov <[email protected]>--- hw/tpm/tpm_ppi.h | 37 +++++++++++++++++++++++++++++++++++++ include/hw/acpi/tpm.h | 6 ++++++ hw/tpm/tpm_crb.c | 7 +++++++ hw/tpm/tpm_ppi.c | 31 +++++++++++++++++++++++++++++++ hw/tpm/tpm_tis.c | 7 +++++++ hw/tpm/Makefile.objs | 1 + 6 files changed, 89 insertions(+) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/tpm/tpm_ppi.chw/tpm/tpm_ppi.h new file +19
-0@@ -0,0 +1,37 @@ +/* +* TPM Physical Presence Interface +* +* Copyright (C) 2018 IBM Corporation +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +*/ +#ifndef TPM_TPM_PPI_H +#define TPM_TPM_PPI_H + +#include "hw/acpi/tpm.h" +#include "exec/address-spaces.h" + +typedef struct TPMPPI { + MemoryRegion ram;
hw/tpm/tpm_ppi.h line 29
Quoted 10 lines
hw/tpm/tpm_ppi.h new file +10
-0+uint8_t *buf; +}TPMPPI ; + +/** +* tpm_ppi_init: +* @tpmppi: a TPMPPI +* @m: the address-space / MemoryRegion to use +* @addr: the address of the PPI region +* @obj: the owner object +* @errp: an Error**
You removed errp.
Without the'errp' line:
Quoted 135 lines
hw/tpm/tpm_ppi.h new file +8
-0+* +* Register the TPM PPI memory region at @addr on the given address +* space for the object @obj. +**/ +void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m, +hwaddr addr,Object *obj); + +#endif /* TPM_TPM_PPI_H */ include/hw/acpi/tpm.h +6
-0@@ -188,4 +188,10 @@ REG32(CRB_DATA_BUFFER, 0x80)#define TPM2_START_METHOD_MMIO 6#define TPM2_START_METHOD_CRB 7 +/* +* Physical Presence Interface +*/ +#define TPM_PPI_ADDR_SIZE 0x400 +#define TPM_PPI_ADDR_BASE 0xFED45000 +#endif /* HW_ACPI_TPM_H */ hw/tpm/tpm_crb.c +7
-0@@ -29,6 +29,7 @@#include "sysemu/reset.h" #include "tpm_int.h" #include "tpm_util.h" +#include "tpm_ppi.h" #include "trace.h" typedef struct CRBState {@@ -43,6 +44,7 @@ typedef struct CRBState {size_t be_buffer_size;bool ppi_enabled; +TPMPPI ppi; } CRBState;#define CRB (obj) OBJECT_CHECK(CRBState, (obj), TYPE_TPM_CRB)@@ -294,6 +296,11 @@ static void tpm_crb_realize(DeviceState *dev, Error **errp)memory_region_add_subregion (get_system_memory (),TPM_CRB_ADDR_BASE +sizeof (s->regs), &s->cmdmem); +if (s->ppi_enabled) { +tpm_ppi_init (&s->ppi,get_system_memory (), +TPM_PPI_ADDR_BASE ,OBJECT (s)); + } +qemu_register_reset (tpm_crb_reset, dev); }hw/tpm/tpm_ppi.c new file +31
-0@@ -0,0 +1,31 @@ +/* +* tpm_ppi.c - TPM Physical Presence Interface +* +* Copyright (C) 2018 IBM Corporation +* +* Authors: +* Stefan Berger <[email protected]> +* +* This work is licensed under the terms of the GNU GPL, version 2 or later. +* See the COPYING file in the top-level directory. +* +*/ + +#include "qemu/osdep.h" + +#include "qapi/error.h" +#include "cpu.h" +#include "sysemu/memory_mapping.h" +#include "migration/vmstate.h" +#include "tpm_ppi.h" + +void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m, +hwaddr addr,Object *obj) +{ + tpmppi->buf =g_malloc0 (HOST_PAGE_ALIGN (TPM_PPI_ADDR_SIZE )); +memory_region_init_ram_device_ptr (&tpmppi->ram, obj,"tpm-ppi" , +TPM_PPI_ADDR_SIZE , tpmppi->buf); +vmstate_register_ram (&tpmppi->ram,DEVICE (obj)); + +memory_region_add_subregion (m, addr, &tpmppi->ram); +}hw/tpm/tpm_tis.c +7
-0@@ -31,6 +31,7 @@#include "sysemu/tpm_backend.h" #include "tpm_int.h" #include "tpm_util.h" +#include "tpm_ppi.h" #include "trace.h" #define TPM_TIS_NUM_LOCALITIES 5/* per spec */ @@ -83,6 +84,7 @@ typedef struct TPMState {size_t be_buffer_size;bool ppi_enabled; +TPMPPI ppi; } TPMState;#define TPM (obj) OBJECT_CHECK(TPMState, (obj), TYPE_TPM_TIS)@@ -979,6 +981,11 @@ static void tpm_tis_realizefn(DeviceState *dev, Error **errp)memory_region_add_subregion (isa_address_space (ISA_DEVICE (dev)),TPM_TIS_ADDR_BASE , &s->mmio); + +if (s->ppi_enabled) { +tpm_ppi_init (&s->ppi,isa_address_space (ISA_DEVICE (dev)), +TPM_PPI_ADDR_BASE ,OBJECT (s)); + } }static void tpm_tis_initfn (Object *obj)hw/tpm/Makefile.objs +1
-0@@ -1,4 +1,5 @@ common-obj-y += tpm_util.o +obj-y += tpm_ppi.o common-obj-$(CONFIG_TPM_TIS) += tpm_tis.o common-obj-$(CONFIG_TPM_CRB) += tpm_crb.o common-obj-$(CONFIG_TPM_PASSTHROUGH) += tpm_passthrough.o
PATCH v13 3/6 acpi: expose TPM/PPI configuration parameters to firmware via fw_cfg
In reply to Marc-André LureauFrom: Stefan Berger <[email protected]>
To avoid having to hard code the base address of the PPI virtual memory device we introduce a fw_cfg file etc/tpm/config that holds the base address of the PPI device, the version of the PPI interface and the version of the attached TPM.
--- include/hw/acpi/tpm.h | 3 +++ hw/i386/acpi-build.c | 19 +++++++++++++++++++ docs/specs/tpm.txt | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+)
include/hw/acpi/tpm.h +3 -0
@@ -194,4 +194,7 @@ REG32(CRB_DATA_BUFFER, 0x80)#define TPM_PPI_ADDR_SIZE 0x400#define TPM_PPI_ADDR_BASE 0xFED45000 +#define TPM_PPI_VERSION_NONE 0 +#define TPM_PPI_VERSION_1_30 1 +#endif /* HW_ACPI_TPM_H */
hw/i386/acpi-build.c +19 -0
@@ -119,6 +119,12 @@ typedef struct AcpiBuildPciBusHotplugState {bool pcihp_bridge_en; } AcpiBuildPciBusHotplugState; +typedef struct FwCfgTPMConfig { +uint32_t tpmppi_address; +uint8_t tpm_version; +uint8_t tpmppi_version; +} QEMU_PACKED FwCfgTPMConfig; +static void init_common_fadt_data (Object *o,AcpiFadtData *data) {uint32_t io =object_property_get_uint (o,ACPI_PM_PROP_PM_IO_BASE ,NULL );
@@ -2855,6 +2861,8 @@ void acpi_setup(void)AcpiBuildTables tables;AcpiBuildState *build_state;Object *vmgenid_dev; +TPMIf *tpm; +static FwCfgTPMConfig tpm_config;if (!pcms->fw_cfg) {ACPI_BUILD_DPRINTF ("No fw cfg. Bailing out.\n" );
@@ -2889,6 +2897,17 @@ void acpi_setup(void)fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); + tpm =tpm_find (); +if (tpm &&object_property_get_bool (OBJECT (tpm),"ppi" , &error_abort)) { + tpm_config = (FwCfgTPMConfig ) { + .tpmppi_address =cpu_to_le32 (TPM_PPI_ADDR_BASE ), + .tpm_version =tpm_get_version (tpm), + .tpmppi_version =TPM_PPI_VERSION_NONE + }; +fw_cfg_add_file (pcms->fw_cfg,"etc/tpm/config" , + &tpm_config,sizeof tpm_config); + } + vmgenid_dev =find_vmgenid_dev ();if (vmgenid_dev) { vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,
docs/specs/tpm.txt +19 -0
@@ -34,6 +34,25 @@ The CRB interface makes a memory mapped IO region in the area 0xfed40000 - QEMU files related to TPM CRB interface: - hw/tpm/tpm_crb.c += fw_cfg interface = + +The bios/firmware may read the "etc/tpm/config" fw_cfg entry for +configuring the guest appropriately. + +The entry of 6 bytes has the following content, in little-endian: + + #define TPM_VERSION_UNSPEC 0 + #define TPM_VERSION_1_2 1 + #define TPM_VERSION_2_0 2 + + #define TPM_PPI_VERSION_NONE 0 + #define TPM_PPI_VERSION_1_30 1 + + struct FwCfgTPMConfig { + uint32_t tpmppi_address; /* PPI memory location */ + uint8_t tpm_version; /* TPM version */ + uint8_t tpmppi_version; /* PPI version */ + }; = ACPI Interface =
Signature · 1 line
2.20.0
Re: [Qemu-devel] [PATCH v13 3/6] acpi: expose TPM/PPI configuration parameters to firmware via fw_cfg
Quoted 11 lines · Marc-André Lureau
From: Stefan Berger <[email protected]>
To avoid having to hard code the base address of the PPI virtual memory device we introduce a
fw_cfgfile etc/tpm/config that holds the base address of the PPI device, the version of the PPI interface and the version of the attached TPM.Signed-off-by Stefan Berger <[email protected]>[ Marc-André: renamed to etc/tpm/config, made it static, document it ]Signed-off-by Marc-André Lureau <[email protected]>
Quoted 93 lines
--- include/hw/acpi/tpm.h | 3 +++ hw/i386/acpi-build.c | 19 +++++++++++++++++++ docs/specs/tpm.txt | 19 +++++++++++++++++++ 3 files changed, 41 insertions(+)include/hw/acpi/tpm.h +3
-0@@ -194,4 +194,7 @@ REG32(CRB_DATA_BUFFER, 0x80)#define TPM_PPI_ADDR_SIZE 0x400#define TPM_PPI_ADDR_BASE 0xFED45000 +#define TPM_PPI_VERSION_NONE 0 +#define TPM_PPI_VERSION_1_30 1 +#endif /* HW_ACPI_TPM_H */ hw/i386/acpi-build.c +19
-0@@ -119,6 +119,12 @@ typedef struct AcpiBuildPciBusHotplugState {bool pcihp_bridge_en; } AcpiBuildPciBusHotplugState; +typedef struct FwCfgTPMConfig { +uint32_t tpmppi_address; +uint8_t tpm_version; +uint8_t tpmppi_version; +} QEMU_PACKED FwCfgTPMConfig; +static void init_common_fadt_data (Object *o,AcpiFadtData *data) {uint32_t io =object_property_get_uint (o,ACPI_PM_PROP_PM_IO_BASE ,NULL );@@ -2855,6 +2861,8 @@ void acpi_setup(void)AcpiBuildTables tables;AcpiBuildState *build_state;Object *vmgenid_dev; +TPMIf *tpm; +static FwCfgTPMConfig tpm_config;if (!pcms->fw_cfg) {ACPI_BUILD_DPRINTF ("No fw cfg. Bailing out.\n" );@@ -2889,6 +2897,17 @@ void acpi_setup(void)fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); + tpm =tpm_find (); +if (tpm &&object_property_get_bool (OBJECT (tpm),"ppi" , &error_abort)) { + tpm_config = (FwCfgTPMConfig ) { + .tpmppi_address =cpu_to_le32 (TPM_PPI_ADDR_BASE ), + .tpm_version =tpm_get_version (tpm), + .tpmppi_version =TPM_PPI_VERSION_NONE + }; +fw_cfg_add_file (pcms->fw_cfg,"etc/tpm/config" , + &tpm_config,sizeof tpm_config); + } + vmgenid_dev =find_vmgenid_dev ();if (vmgenid_dev) { vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,docs/specs/tpm.txt +19
-0@@ -34,6 +34,25 @@ The CRB interface makes a memory mapped IO region in the area 0xfed40000 - QEMU files related to TPM CRB interface: - hw/tpm/tpm_crb.c += fw_cfg interface = + +The bios/firmware may read the "etc/tpm/config" fw_cfg entry for +configuring the guest appropriately. + +The entry of 6 bytes has the following content, in little-endian: + + #define TPM_VERSION_UNSPEC 0 + #define TPM_VERSION_1_2 1 + #define TPM_VERSION_2_0 2 + + #define TPM_PPI_VERSION_NONE 0 + #define TPM_PPI_VERSION_1_30 1 + + struct FwCfgTPMConfig { + uint32_t tpmppi_address; /* PPI memory location */ + uint8_t tpm_version; /* TPM version */ + uint8_t tpmppi_version; /* PPI version */ + }; = ACPI Interface =
PATCH v13 4/6 acpi: build TPM Physical Presence interface
In reply to Marc-André LureauFrom: Stefan Berger <[email protected]>
The TPM Physical Presence interface consists of an ACPI part, a shared memory part, and code in the firmware. Users can send messages to the firmware by writing a code into the shared memory through invoking the ACPI code. When a reboot happens, the firmware looks for the code and acts on it by sending sequences of commands to the TPM.
This patch adds the ACPI code. It is similar to the one in EDK2 but doesn't assume that SMIs are necessary to use. It uses a similar datastructure for the shared memory as EDK2 does so that EDK2 and SeaBIOS could both make use of it. I extended the shared memory data structure with an array of 256 bytes, one for each code that could be implemented. The array contains flags describing the individual codes. This decouples the ACPI implementation from the firmware implementation.
The underlying TCG specification is accessible from the following page.
https://trustedcomputinggroup.org/tcg-physical-presence-interface-specification/
This patch implements version 1.30.
--- include/hw/acpi/tpm.h | 12 ++ hw/acpi/tpm.c | 400 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 12 +- docs/specs/tpm.txt | 83 +++++++++ hw/acpi/Makefile.objs | 1 + 5 files changed, 505 insertions(+), 3 deletions(-) create mode 100644 hw/acpi/tpm.c
include/hw/acpi/tpm.h +12 -0
@@ -18,6 +18,8 @@#include "qemu/units.h" #include "hw/registerfields.h" +#include "hw/acpi/aml-build.h" +#include "sysemu/tpm.h" #define TPM_TIS_ADDR_BASE 0xFED40000#define TPM_TIS_ADDR_SIZE 0x5000
@@ -197,4 +199,14 @@ REG32(CRB_DATA_BUFFER, 0x80)#define TPM_PPI_VERSION_NONE 0#define TPM_PPI_VERSION_1_30 1 +/* whether function is blocked by BIOS settings; bits 0, 1, 2 */ +#define TPM_PPI_FUNC_NOT_IMPLEMENTED (0 << 0) +#define TPM_PPI_FUNC_BIOS_ONLY (1 << 0) +#define TPM_PPI_FUNC_BLOCKED (2 << 0) +#define TPM_PPI_FUNC_ALLOWED_USR_REQ (3 << 0) +#define TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ (4 << 0) +#define TPM_PPI_FUNC_MASK (7 << 0) + +void tpm_build_ppi_acpi (TPMIf *tpm,Aml *dev); +#endif /* HW_ACPI_TPM_H */
hw/acpi/tpm.c new file +400 -0
400 lines not on this page · raw message
hw/i386/acpi-build.c +9 -3
@@ -1802,6 +1802,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,uint32_t nr_mem = machine->ram_slots;int root_bus_limit =0xFF ;PCIBus *bus =NULL ; +TPMIf *tpm =tpm_find ();int i; dsdt =init_aml_allocator ();
@@ -2139,7 +2140,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); -if (TPM_IS_TIS (tpm_find ())) { +if (TPM_IS_TIS (tpm)) { dev =aml_device ("ISA.TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0C31" )));aml_append (dev,aml_name_decl ("_STA" ,aml_int (0xF )));
@@ -2153,6 +2154,9 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,*/ /* aml_append(crs, aml_irq_no_flags(TPM_TIS_IRQ)); */ aml_append (dev,aml_name_decl ("_CRS" , crs)); + +tpm_build_ppi_acpi (tpm, dev); +aml_append (scope, dev); }
@@ -2160,7 +2164,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } -if (TPM_IS_CRB (tpm_find ())) { +if (TPM_IS_CRB (tpm)) { dev =aml_device ("TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" ))); crs =aml_resource_template ();
@@ -2172,6 +2176,8 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (method,aml_return (aml_int (0x0f )));aml_append (dev, method); +tpm_build_ppi_acpi (tpm, dev); +aml_append (sb_scope, dev); }
@@ -2902,7 +2908,7 @@ void acpi_setup(void) tpm_config = (FwCfgTPMConfig ) { .tpmppi_address =cpu_to_le32 (TPM_PPI_ADDR_BASE ), .tpm_version =tpm_get_version (tpm), - .tpmppi_version =TPM_PPI_VERSION_NONE + .tpmppi_version =TPM_PPI_VERSION_1_30 };fw_cfg_add_file (pcms->fw_cfg,"etc/tpm/config" , &tpm_config,sizeof tpm_config);
docs/specs/tpm.txt +83 -0
89 lines not on this page · raw message
hw/acpi/Makefile.objs +1 -0
@@ -11,6 +11,7 @@ common-obj-$(call lnot,$(CONFIG_ACPI_X86)) += acpi-stub.o common-obj-y += acpi_interface.o common-obj-y += bios-linker-loader.o common-obj-y += aml-build.o +common-obj-$(CONFIG_TPM) += tpm.o common-obj-$(CONFIG_IPMI) += ipmi.o common-obj-$(call lnot,$(CONFIG_IPMI)) += ipmi-stub.o
Signature · 1 line
2.20.0
PATCH v13 5/6 acpi: add ACPI memory clear interface
In reply to Marc-André LureauThe interface is described in the "TCG Platform Reset Attack Mitigation Specification", chapter 6 "ACPI _DSM Function". According to Laszlo, it's not so easy to implement in OVMF, he suggested to do it in qemu instead.
See specification documentation for more details, and next commit for memory clear on reset handling.
--- include/hw/acpi/tpm.h | 2 ++ hw/acpi/tpm.c | 47 +++++++++++++++++++++++++++++++++++++++++++ docs/specs/tpm.txt | 2 ++ 3 files changed, 51 insertions(+)
include/hw/acpi/tpm.h +2 -0
@@ -207,6 +207,8 @@ REG32(CRB_DATA_BUFFER, 0x80)#define TPM_PPI_FUNC_ALLOWED_USR_NOT_REQ (4 << 0)#define TPM_PPI_FUNC_MASK (7 << 0) +#define TPM_PPI_MOVV_OFFSET 0x15a +void tpm_build_ppi_acpi (TPMIf *tpm,Aml *dev);#endif /* HW_ACPI_TPM_H */
hw/acpi/tpm.c +47 -0
59 lines not on this page · raw message
docs/specs/tpm.txt +2 -0
@@ -135,6 +135,8 @@ layout: +----------+--------+--------+-------------------------------------------+ | next_step| 0x1 | 0x159 | Operation to execute after reboot by | | | | | firmware. Used by firmware. | + +----------+--------+--------+-------------------------------------------+ + | movv | 0x1 | 0x15a | Memory overwrite variable | +----------+--------+--------+-------------------------------------------+ The following values are supported for the 'func' field. They correspond
Signature · 1 line
2.20.0
PATCH v13 6/6 tpm: clear RAM when "memory overwrite" requested
In reply to Marc-André LureauNote: the "Platform Reset Attack Mitigation" specification isn't explicit about NVDIMM, since they could have different usages. It uses the term "system memory" generally (and also "volatile memory RAM" in its introduction). For initial support, I propose to consider non-volatile memory as not being subject to the memory clear. There is an on-going discussion in the TCG "pcclientwg" working group for future revisions.
CPU cache clearing is done unconditionally in edk2 since commit d20ae95a13e851 (edk2-stable201811).
--- hw/tpm/tpm_ppi.h | 10 ++++++++++ hw/tpm/tpm_crb.c | 1 + hw/tpm/tpm_ppi.c | 22 ++++++++++++++++++++++ hw/tpm/tpm_tis.c | 1 + hw/tpm/trace-events | 3 +++ 5 files changed, 37 insertions(+)
hw/tpm/tpm_ppi.h +10 -0
@@ -34,4 +34,14 @@ typedef struct TPMPPI {void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m,hwaddr addr,Object *obj); +/** +* tpm_ppi_reset: +* @tpmppi: a TPMPPI +* +* Function to call on machine reset. It will check if the "Memory +* overwrite" variable is set, and perform a memory clear on volatile +* memory if requested. +**/ +void tpm_ppi_reset (TPMPPI *tpmppi); +#endif /* TPM_TPM_PPI_H */
hw/tpm/tpm_crb.c +1 -0
@@ -233,6 +233,7 @@ static void tpm_crb_reset(void *dev) {CRBState *s =CRB (dev); +tpm_ppi_reset (&s->ppi);tpm_backend_reset (s->tpmbe);memset (s->regs,0 ,sizeof (s->regs));
hw/tpm/tpm_ppi.c +22 -0
@@ -16,8 +16,30 @@#include "qapi/error.h" #include "cpu.h" #include "sysemu/memory_mapping.h" +#include "sysemu/reset.h" #include "migration/vmstate.h" #include "tpm_ppi.h" +#include "trace.h" + +void tpm_ppi_reset (TPMPPI *tpmppi) +{ +if (tpmppi->buf[TPM_PPI_MOVV_OFFSET ] &0x1 ) { +GuestPhysBlockList guest_phys_blocks; +GuestPhysBlock *block; + +guest_phys_blocks_init (&guest_phys_blocks); +guest_phys_blocks_append (&guest_phys_blocks); + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { +trace_tpm_ppi_memset (block->host_addr, + block->target_end - block->target_start); +memset (block->host_addr,0 , + block->target_end - block->target_start); +memory_region_set_dirty (block->mr,0 , + block->target_end - block->target_start); + } +guest_phys_blocks_free (&guest_phys_blocks); + } +}void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m,hwaddr addr,Object *obj)
hw/tpm/tpm_tis.c +1 -0
@@ -868,6 +868,7 @@ static void tpm_tis_reset(DeviceState *dev) s->be_buffer_size =MIN (tpm_backend_get_buffer_size (s->be_driver),TPM_TIS_BUFFER_MAX ); +tpm_ppi_reset (&s->ppi);tpm_backend_reset (s->be_driver); s->active_locty =TPM_TIS_NO_LOCALITY ;
hw/tpm/trace-events +3 -0
@@ -51,3 +51,6 @@ tpm_tis_mmio_write_init_abort(void) "Initiating abort" tpm_tis_mmio_write_lowering_irq(void) "Lowering IRQ" tpm_tis_mmio_write_data2send(uint32_t value, unsigned size) "Data to send to TPM: 0x%08x (size=%d)" tpm_tis_pre_save(uint8_t locty, uint32_t rw_offset) "locty: %d, rw_offset = %u" + +# hw/tpm/tpm_ppi.c +tpm_ppi_memset(uint8_t *ptr, size_t size) "memset: %p %zu"
Signature · 1 line
2.20.0
Re: [Qemu-devel] [PATCH v13 6/6] tpm: clear RAM when "memory overwrite" requested
Quoted 65 lines · Marc-André Lureau
Note: the "Platform Reset Attack Mitigation" specification isn't explicit about NVDIMM, since they could have different usages. It uses the term "system memory" generally (and also "volatile memory RAM" in its introduction). For initial support, I propose to consider non-volatile memory as not being subject to the memory clear. There is an on-going discussion in the TCG "pcclientwg" working group for future revisions.
CPU cache clearing is done unconditionally in edk2 since commit
d20ae95a13e851(edk2-stable201811).Signed-off-by Marc-André Lureau <[email protected]>--- hw/tpm/tpm_ppi.h | 10 ++++++++++ hw/tpm/tpm_crb.c | 1 + hw/tpm/tpm_ppi.c | 22 ++++++++++++++++++++++ hw/tpm/tpm_tis.c | 1 + hw/tpm/trace-events | 3 +++ 5 files changed, 37 insertions(+)hw/tpm/tpm_ppi.h +10
-0@@ -34,4 +34,14 @@ typedef struct TPMPPI {void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m,hwaddr addr,Object *obj); +/** +* tpm_ppi_reset: +* @tpmppi: a TPMPPI +* +* Function to call on machine reset. It will check if the "Memory +* overwrite" variable is set, and perform a memory clear on volatile +* memory if requested. +**/ +void tpm_ppi_reset (TPMPPI *tpmppi); +#endif /* TPM_TPM_PPI_H */ hw/tpm/tpm_crb.c +1
-0@@ -233,6 +233,7 @@ static void tpm_crb_reset(void *dev) {CRBState *s =CRB (dev); +tpm_ppi_reset (&s->ppi);tpm_backend_reset (s->tpmbe);memset (s->regs,0 ,sizeof (s->regs));hw/tpm/tpm_ppi.c +4
-0@@ -16,8 +16,30 @@#include "qapi/error.h" #include "cpu.h" #include "sysemu/memory_mapping.h" +#include "sysemu/reset.h" #include "migration/vmstate.h" #include "tpm_ppi.h" +#include "trace.h" + +void tpm_ppi_reset (TPMPPI *tpmppi)
hw/tpm/tpm_ppi.c line 34
Quoted 10 lines
hw/tpm/tpm_ppi.c +10
-0+{ +if (tpmppi->buf[TPM_PPI_MOVV_OFFSET ] &0x1 ) { +GuestPhysBlockList guest_phys_blocks; +GuestPhysBlock *block; + +guest_phys_blocks_init (&guest_phys_blocks); +guest_phys_blocks_append (&guest_phys_blocks); + QTAILQ_FOREACH(block, &guest_phys_blocks.head, next) { +trace_tpm_ppi_memset (block->host_addr, + block->target_end - block->target_start);
Add 3 spaces to align :)
Quoted 35 lines
hw/tpm/tpm_ppi.c +8
-0+memset (block->host_addr,0 , + block->target_end - block->target_start); +memory_region_set_dirty (block->mr,0 , + block->target_end - block->target_start); + } +guest_phys_blocks_free (&guest_phys_blocks); + } +}void tpm_ppi_init (TPMPPI *tpmppi,struct MemoryRegion *m,hwaddr addr,Object *obj)hw/tpm/tpm_tis.c +1
-0@@ -868,6 +868,7 @@ static void tpm_tis_reset(DeviceState *dev) s->be_buffer_size =MIN (tpm_backend_get_buffer_size (s->be_driver),TPM_TIS_BUFFER_MAX ); +tpm_ppi_reset (&s->ppi);tpm_backend_reset (s->be_driver); s->active_locty =TPM_TIS_NO_LOCALITY ;hw/tpm/trace-events +3
-0@@ -51,3 +51,6 @@ tpm_tis_mmio_write_init_abort(void) "Initiating abort" tpm_tis_mmio_write_lowering_irq(void) "Lowering IRQ" tpm_tis_mmio_write_data2send(uint32_t value, unsigned size) "Data to send to TPM: 0x%08x (size=%d)" tpm_tis_pre_save(uint8_t locty, uint32_t rw_offset) "locty: %d, rw_offset = %u" + +# hw/tpm/tpm_ppi.c +tpm_ppi_memset(uint8_t *ptr, size_t size) "memset: %p %zu"
Quoted 12 lines · Marc-André Lureau
Hi,
The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware looks for and acts upon by sending sequences of commands to the TPM.
A dedicated memory region is added to the TPM CRB & TIS devices, at address/size 0xFED45000/0x400. A new "etc/tpm/config"
fw_cfgentry holds the location for that PPI region and some version details, to allow for future flexibility.
Quoted 7 lines
With the associated edk2/ovmf firmware, the Windows HLK "PPI 1.3" test now runs successfully.
It is based on previous work from Stefan Berger ("[PATCH v2 0/4] Implement Physical Presence interface for TPM 1.2 and 2")
The edk2 support is merged upstream.
Breaks build with tpm disabled:
/usr/bin/ld: hw/i386/acpi-build.o: in function `build_dsdt':
/scm/qemu/hw/i386/acpi-build.c:2158: undefined reference to tpm_build_ppi_acpi' /usr/bin/ld: /scm/qemu/hw/i386/acpi-build.c:2179: undefined reference to tpm_build_ppi_acpi'
collect2: error: ld returned 1 exit status
Quoted 37 lines
v13:
- removed needless error handling intpm_ppi_init()
- splitted "add ACPI memory clear interface"
- moved acpi build function in dedicatedhw/acpi/tpm.c
- added some function documentation in headers
- various code cleanups suggested by Philippe
- rebasedMarc-André Lureau (3):
tpm: add a "ppi" boolean property
acpi: add ACPI memory clear interface
tpm: clear RAM when "memory overwrite" requestedStefan Berger (3):
tpm: allocate/map buffer for TPM Physical Presence interface
acpi: expose TPM/PPI configuration parameters to firmware viafw_cfg
acpi: build TPM Physical Presence interfacehw/tpm/tpm_ppi.h | 47 +++++ include/hw/acpi/tpm.h | 23 +++ include/hw/compat.h | 11 +- hw/acpi/tpm.c | 447 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 29 ++- hw/tpm/tpm_crb.c | 11 ++ hw/tpm/tpm_ppi.c | 53 +++++ hw/tpm/tpm_tis.c | 11 ++ docs/specs/tpm.txt | 104 ++++++++++ hw/acpi/Makefile.objs | 1 + hw/tpm/Makefile.objs | 1 + hw/tpm/trace-events | 3 + 12 files changed, 738 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/acpi/tpm.c create mode 100644 hw/tpm/tpm_ppi.cSignature · 1 line
2.20.0
Hi Michael,
Quoted 23 lines · Michael S. Tsirkin
Quoted 12 lines · Marc-André Lureau
Hi,
The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware looks for and acts upon by sending sequences of commands to the TPM.
A dedicated memory region is added to the TPM CRB & TIS devices, at address/size 0xFED45000/0x400. A new "etc/tpm/config"
fw_cfgentry holds the location for that PPI region and some version details, to allow for future flexibility.Quoted 7 lines
With the associated edk2/ovmf firmware, the Windows HLK "PPI 1.3" test now runs successfully.
It is based on previous work from Stefan Berger ("[PATCH v2 0/4] Implement Physical Presence interface for TPM 1.2 and 2")
The edk2 support is merged upstream.
Quoted 6 lines
Breaks build with tpm disabled:
/usr/bin/ld:hw/i386/acpi-build.o: in function `build_dsdt':
/scm/qemu/hw/i386/acpi-build.c:2158: undefined reference totpm_build_ppi_acpi' /usr/bin/ld: /scm/qemu/hw/i386/acpi-build.c:2179: undefined reference totpm_build_ppi_acpi'
collect2: error: ld returned 1 exit status
Thanks for noticing, this is probably a regression from v13, since the tpm_build_ppi_acpi was moved to a separate unit that is not always built.
There is a lot of TPM code that we always build in acpi-build. Either the code should have #ifdef TPM, or we use stubs.
Fwiw, the preliminary #ifdef patch would look like that, is that desirable, or should we just add some stub:
hw/i386/acpi-build.c +15 -4
@@ -41,14 +41,16 @@#include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/acpi/memory_hotplug.h" +#ifdef CONFIG_TPM #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" -#include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" +#endif +#include "hw/acpi/vmgenid.h" #include "hw/timer/mc146818rtc_regs.h" #include "hw/mem/memory-device.h" #include "sysemu/numa.h" - +#include "qemu/units.h" /* Supported chipsets: */ #include "hw/acpi/piix4.h" #include "hw/acpi/pcihp.h"
@@ -105,7 +107,9 @@ typedef struct AcpiPmInfo { typedef struct AcpiMiscInfo { bool is_piix4; bool has_hpet; +#ifdef CONFIG_TPM TPMVersion tpm_version; +#endif const unsigned char *dsdt_code; unsigned dsdt_size; uint16_t pvpanic_port;
@@ -234,7 +238,9 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) } info->has_hpet =hpet_find (); +#ifdef CONFIG_TPM info->tpm_version =tpm_get_version (tpm_find ()); +#endif info->pvpanic_port =pvpanic_port (); info->applesmc_io_base =applesmc_port (); }
@@ -1962,10 +1968,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) {aml_append (crs,aml_memory32_fixed (TPM_TIS_ADDR_BASE ,TPM_TIS_ADDR_SIZE ,AML_READ_WRITE )); } +#endif aml_append (scope,aml_name_decl ("_CRS" , crs));/* reserve GPE0 block resources */
@@ -2133,6 +2141,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) { dev =aml_device ("ISA.TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0C31" )));
@@ -2149,11 +2158,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev); } - +#endif aml_append (sb_scope, scope); } } +#ifdef CONFIG_TPM if (TPM_IS_CRB (tpm_find ())) { dev =aml_device ("TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" )));
@@ -2168,7 +2178,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, aml_append(sb_scope, dev); } - +#endif aml_append (dsdt, sb_scope);/* copy AML table into ACPI tables blob and patch header there */
@@ -2194,6 +2204,7 @@ build_hpet(GArray *table_data, BIOSLinker *linker) (void *)hpet, "HPET", sizeof(*hpet), 1, NULL, NULL); } +#ifdef CONFIG_TPM static void build_tpm_tcpa (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) {
@@ -2247,6 +2258,7 @@ build_tpm2(GArray *table_data, BIOSLinker
*linker, GArray *tcpalog)
build_header(linker, table_data,
(void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); }
+#endif
#define HOLE_640K_START (640 * KiB)
#define HOLE_640K_END (1 * MiB)
@@ -2679,6 +2691,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)
acpi_add_table(table_offsets, tables_blob);
build_hpet(tables_blob, tables->linker);
}
+#ifdef CONFIG_TPM
if (misc.tpm_version != TPM_VERSION_UNSPEC) {
acpi_add_table(table_offsets, tables_blob);
build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);
@@ -2688,6 +2701,7 @@ void acpi_build(AcpiBuildTables *tables,
MachineState *machine)
build_tpm2(tables_blob, tables->linker, tables->tcpalog);
}
}
+#endif
if (pcms->numa_nodes) {
acpi_add_table(table_offsets, tables_blob);
build_srat(tables_blob, tables->linker, machine);
@@ -2886,9 +2900,10 @@ void acpi_setup(void)
acpi_add_rom_blob(build_state, tables.linker->cmd_blob,
"etc/table-loader", 0);+#ifdef CONFIG_TPM
fw_cfg_add_file(pcms->fw_cfg, ACPI_BUILD_TPMLOG_FILE,
tables.tcpalog->data, acpi_data_len(tables.tcpalog));
-
+#endif
vmgenid_dev = find_vmgenid_dev();
if (vmgenid_dev) {
vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,Quoted 39 lines
Quoted 38 lines
v13:
- removed needless error handling intpm_ppi_init()
- splitted "add ACPI memory clear interface"
- moved acpi build function in dedicatedhw/acpi/tpm.c
- added some function documentation in headers
- various code cleanups suggested by Philippe
- rebasedMarc-André Lureau (3):
tpm: add a "ppi" boolean property
acpi: add ACPI memory clear interface
tpm: clear RAM when "memory overwrite" requestedStefan Berger (3):
tpm: allocate/map buffer for TPM Physical Presence interface
acpi: expose TPM/PPI configuration parameters to firmware viafw_cfg
acpi: build TPM Physical Presence interfacehw/tpm/tpm_ppi.h | 47 +++++ include/hw/acpi/tpm.h | 23 +++ include/hw/compat.h | 11 +- hw/acpi/tpm.c | 447 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 29 ++- hw/tpm/tpm_crb.c | 11 ++ hw/tpm/tpm_ppi.c | 53 +++++ hw/tpm/tpm_tis.c | 11 ++ docs/specs/tpm.txt | 104 ++++++++++ hw/acpi/Makefile.objs | 1 + hw/tpm/Makefile.objs | 1 + hw/tpm/trace-events | 3 + 12 files changed, 738 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/acpi/tpm.c create mode 100644 hw/tpm/tpm_ppi.c--
2.20.0
Signature · 1 line
Marc-André Lureau
Quoted 37 lines · Marc-André Lureau
Hi Michael,
Quoted 23 lines · Michael S. Tsirkin
Quoted 12 lines · Marc-André Lureau
Hi,
The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware looks for and acts upon by sending sequences of commands to the TPM.
A dedicated memory region is added to the TPM CRB & TIS devices, at address/size 0xFED45000/0x400. A new "etc/tpm/config"
fw_cfgentry holds the location for that PPI region and some version details, to allow for future flexibility.Quoted 7 lines
With the associated edk2/ovmf firmware, the Windows HLK "PPI 1.3" test now runs successfully.
It is based on previous work from Stefan Berger ("[PATCH v2 0/4] Implement Physical Presence interface for TPM 1.2 and 2")
The edk2 support is merged upstream.
Quoted 6 lines
Breaks build with tpm disabled:
/usr/bin/ld:hw/i386/acpi-build.o: in function `build_dsdt':
/scm/qemu/hw/i386/acpi-build.c:2158: undefined reference totpm_build_ppi_acpi' /usr/bin/ld: /scm/qemu/hw/i386/acpi-build.c:2179: undefined reference totpm_build_ppi_acpi'
collect2: error: ld returned 1 exit statusThanks for noticing, this is probably a regression from v13, since the
tpm_build_ppi_acpiwas moved to a separate unit that is not always built.
Quoted 5 lines
There is a lot of TPM code that we always build in acpi-build. Either the code should have #ifdef TPM, or we use stubs.
Fwiw, the preliminary #ifdef patch would look like that, is that desirable, or should we just add some stub:
Seems way too messy. I'd prefer stubs.
Quoted 179 lines
hw/i386/acpi-build.c +16
-4@@ -41,14 +41,16 @@#include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/acpi/memory_hotplug.h" +#ifdef CONFIG_TPM #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" -#include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" +#endif +#include "hw/acpi/vmgenid.h" #include "hw/timer/mc146818rtc_regs.h" #include "hw/mem/memory-device.h" #include "sysemu/numa.h" - +#include "qemu/units.h" /* Supported chipsets: */ #include "hw/acpi/piix4.h" #include "hw/acpi/pcihp.h" @@ -105,7 +107,9 @@ typedef struct AcpiPmInfo { typedef struct AcpiMiscInfo { bool is_piix4; bool has_hpet; +#ifdef CONFIG_TPM TPMVersion tpm_version; +#endif const unsigned char *dsdt_code; unsigned dsdt_size; uint16_t pvpanic_port;@@ -234,7 +238,9 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) } info->has_hpet =hpet_find (); +#ifdef CONFIG_TPM info->tpm_version =tpm_get_version (tpm_find ()); +#endif info->pvpanic_port =pvpanic_port (); info->applesmc_io_base =applesmc_port (); }@@ -1962,10 +1968,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) {aml_append (crs,aml_memory32_fixed (TPM_TIS_ADDR_BASE ,TPM_TIS_ADDR_SIZE ,AML_READ_WRITE )); } +#endif aml_append (scope,aml_name_decl ("_CRS" , crs));/* reserve GPE0 block resources */ @@ -2133,6 +2141,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) { dev =aml_device ("ISA.TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0C31" )));@@ -2149,11 +2158,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev); } - +#endif aml_append (sb_scope, scope); } } +#ifdef CONFIG_TPM if (TPM_IS_CRB (tpm_find ())) { dev =aml_device ("TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" )));@@ -2168,7 +2178,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, aml_append(sb_scope, dev); } - +#endif aml_append (dsdt, sb_scope);/* copy AML table into ACPI tables blob and patch header there */ @@ -2194,6 +2204,7 @@ build_hpet(GArray *table_data, BIOSLinker *linker) (void *)hpet, "HPET", sizeof(*hpet), 1, NULL, NULL); } +#ifdef CONFIG_TPM static void build_tpm_tcpa (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) {@@ -2247,6 +2258,7 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)build_header (linker, table_data, (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#endif #define HOLE_640K_START (640 * KiB)#define
HOLE_640K_END(1 * MiB)hw/i386/acpi-build.c +1
-0@@ -2679,6 +2691,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets ,tables_blob );build_hpet (tables_blob, tables->linker); } +#ifdef CONFIG_TPM if (misc.tpm_version !=TPM_VERSION_UNSPEC ) {acpi_add_table (table_offsets, tables_blob);build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);hw/i386/acpi-build.c +1
-0@@ -2688,6 +2701,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) build_tpm2(tables_blob, tables->linker, tables->tcpalog); } } +#endif if (pcms->numa_nodes) {acpi_add_table (table_offsets, tables_blob);build_srat(tables_blob, tables->linker, machine);hw/i386/acpi-build.c +2
-1@@ -2886,9 +2900,10 @@ void acpi_setup(void)acpi_add_rom_blob (build_state, tables.linker->cmd_blob,"etc/table-loader" ,0 ); +#ifdef CONFIG_TPM fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); - +#endif vmgenid_dev =find_vmgenid_dev ();if (vmgenid_dev) { vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,Quoted 41 lines
Quoted 40 lines
v13:
- removed needless error handling intpm_ppi_init()
- splitted "add ACPI memory clear interface"
- moved acpi build function in dedicatedhw/acpi/tpm.c
- added some function documentation in headers
- various code cleanups suggested by Philippe
- rebasedMarc-André Lureau (3):
tpm: add a "ppi" boolean property
acpi: add ACPI memory clear interface
tpm: clear RAM when "memory overwrite" requestedStefan Berger (3):
tpm: allocate/map buffer for TPM Physical Presence interface
acpi: expose TPM/PPI configuration parameters to firmware viafw_cfg
acpi: build TPM Physical Presence interfacehw/tpm/tpm_ppi.h | 47 +++++ include/hw/acpi/tpm.h | 23 +++ include/hw/compat.h | 11 +- hw/acpi/tpm.c | 447 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 29 ++- hw/tpm/tpm_crb.c | 11 ++ hw/tpm/tpm_ppi.c | 53 +++++ hw/tpm/tpm_tis.c | 11 ++ docs/specs/tpm.txt | 104 ++++++++++ hw/acpi/Makefile.objs | 1 + hw/tpm/Makefile.objs | 1 + hw/tpm/trace-events | 3 + 12 files changed, 738 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/acpi/tpm.c create mode 100644 hw/tpm/tpm_ppi.c--
2.20.0Signature · 1 line
Marc-André Lureau
Hi
Quoted 39 lines · Michael S. Tsirkin
Quoted 37 lines · Marc-André Lureau
Hi Michael,
Quoted 23 lines · Michael S. Tsirkin
Quoted 12 lines · Marc-André Lureau
Hi,
The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware looks for and acts upon by sending sequences of commands to the TPM.
A dedicated memory region is added to the TPM CRB & TIS devices, at address/size 0xFED45000/0x400. A new "etc/tpm/config"
fw_cfgentry holds the location for that PPI region and some version details, to allow for future flexibility.Quoted 7 lines
With the associated edk2/ovmf firmware, the Windows HLK "PPI 1.3" test now runs successfully.
It is based on previous work from Stefan Berger ("[PATCH v2 0/4] Implement Physical Presence interface for TPM 1.2 and 2")
The edk2 support is merged upstream.
Quoted 6 lines
Breaks build with tpm disabled:
/usr/bin/ld:hw/i386/acpi-build.o: in function `build_dsdt':
/scm/qemu/hw/i386/acpi-build.c:2158: undefined reference totpm_build_ppi_acpi' /usr/bin/ld: /scm/qemu/hw/i386/acpi-build.c:2179: undefined reference totpm_build_ppi_acpi'
collect2: error: ld returned 1 exit statusThanks for noticing, this is probably a regression from v13, since the
tpm_build_ppi_acpiwas moved to a separate unit that is not always built.
Quoted 7 lines
Quoted 5 lines
There is a lot of TPM code that we always build in acpi-build. Either the code should have #ifdef TPM, or we use stubs.
Fwiw, the preliminary #ifdef patch would look like that, is that desirable, or should we just add some stub:
Seems way too messy. I'd prefer stubs.
Beside the missing stub, and an indentation fix, could someone review the last 2 patches?
Quoted 180 lines
Quoted 180 lines
hw/i386/acpi-build.c +16
-4@@ -41,14 +41,16 @@#include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/acpi/memory_hotplug.h" +#ifdef CONFIG_TPM #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" -#include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" +#endif +#include "hw/acpi/vmgenid.h" #include "hw/timer/mc146818rtc_regs.h" #include "hw/mem/memory-device.h" #include "sysemu/numa.h" - +#include "qemu/units.h" /* Supported chipsets: */ #include "hw/acpi/piix4.h" #include "hw/acpi/pcihp.h" @@ -105,7 +107,9 @@ typedef struct AcpiPmInfo { typedef struct AcpiMiscInfo { bool is_piix4; bool has_hpet; +#ifdef CONFIG_TPM TPMVersion tpm_version; +#endif const unsigned char *dsdt_code; unsigned dsdt_size; uint16_t pvpanic_port;@@ -234,7 +238,9 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) } info->has_hpet =hpet_find (); +#ifdef CONFIG_TPM info->tpm_version =tpm_get_version (tpm_find ()); +#endif info->pvpanic_port =pvpanic_port (); info->applesmc_io_base =applesmc_port (); }@@ -1962,10 +1968,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) {aml_append (crs,aml_memory32_fixed (TPM_TIS_ADDR_BASE ,TPM_TIS_ADDR_SIZE ,AML_READ_WRITE )); } +#endif aml_append (scope,aml_name_decl ("_CRS" , crs));/* reserve GPE0 block resources */ @@ -2133,6 +2141,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) { dev =aml_device ("ISA.TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0C31" )));@@ -2149,11 +2158,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev); } - +#endif aml_append (sb_scope, scope); } } +#ifdef CONFIG_TPM if (TPM_IS_CRB (tpm_find ())) { dev =aml_device ("TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" )));@@ -2168,7 +2178,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, aml_append(sb_scope, dev); } - +#endif aml_append (dsdt, sb_scope);/* copy AML table into ACPI tables blob and patch header there */ @@ -2194,6 +2204,7 @@ build_hpet(GArray *table_data, BIOSLinker *linker) (void *)hpet, "HPET", sizeof(*hpet), 1, NULL, NULL); } +#ifdef CONFIG_TPM static void build_tpm_tcpa (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) {@@ -2247,6 +2258,7 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)build_header (linker, table_data, (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#endif #define HOLE_640K_START (640 * KiB)#define
HOLE_640K_END(1 * MiB)hw/i386/acpi-build.c +1
-0@@ -2679,6 +2691,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets ,tables_blob );build_hpet (tables_blob, tables->linker); } +#ifdef CONFIG_TPM if (misc.tpm_version !=TPM_VERSION_UNSPEC ) {acpi_add_table (table_offsets, tables_blob);build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);hw/i386/acpi-build.c +1
-0@@ -2688,6 +2701,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) build_tpm2(tables_blob, tables->linker, tables->tcpalog); } } +#endif if (pcms->numa_nodes) {acpi_add_table (table_offsets, tables_blob);build_srat(tables_blob, tables->linker, machine);hw/i386/acpi-build.c +2
-1@@ -2886,9 +2900,10 @@ void acpi_setup(void)acpi_add_rom_blob (build_state, tables.linker->cmd_blob,"etc/table-loader" ,0 ); +#ifdef CONFIG_TPM fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); - +#endif vmgenid_dev =find_vmgenid_dev ();if (vmgenid_dev) { vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,Quoted 38 lines
Quoted 38 lines
v13:
- removed needless error handling intpm_ppi_init()
- splitted "add ACPI memory clear interface"
- moved acpi build function in dedicatedhw/acpi/tpm.c
- added some function documentation in headers
- various code cleanups suggested by Philippe
- rebasedMarc-André Lureau (3):
tpm: add a "ppi" boolean property
acpi: add ACPI memory clear interface
tpm: clear RAM when "memory overwrite" requestedStefan Berger (3):
tpm: allocate/map buffer for TPM Physical Presence interface
acpi: expose TPM/PPI configuration parameters to firmware viafw_cfg
acpi: build TPM Physical Presence interfacehw/tpm/tpm_ppi.h | 47 +++++ include/hw/acpi/tpm.h | 23 +++ include/hw/compat.h | 11 +- hw/acpi/tpm.c | 447 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 29 ++- hw/tpm/tpm_crb.c | 11 ++ hw/tpm/tpm_ppi.c | 53 +++++ hw/tpm/tpm_tis.c | 11 ++ docs/specs/tpm.txt | 104 ++++++++++ hw/acpi/Makefile.objs | 1 + hw/tpm/Makefile.objs | 1 + hw/tpm/trace-events | 3 + 12 files changed, 738 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/acpi/tpm.c create mode 100644 hw/tpm/tpm_ppi.cQuoted 3 lines
Quoted 2 lines
--
2.20.0--
Marc-André Lureau
Signature · 1 line
Marc-André Lureau
Quoted 45 lines · Marc-André Lureau
Hi
Quoted 42 lines · Michael S. Tsirkin
Quoted 40 lines · Marc-André Lureau
Hi Michael,
Quoted 23 lines · Michael S. Tsirkin
Quoted 12 lines · Marc-André Lureau
Hi,
The following patches implement the TPM Physical Presence Interface that allows a user to set a command via ACPI (sysfs entry in Linux) that, upon the next reboot, the firmware looks for and acts upon by sending sequences of commands to the TPM.
A dedicated memory region is added to the TPM CRB & TIS devices, at address/size 0xFED45000/0x400. A new "etc/tpm/config"
fw_cfgentry holds the location for that PPI region and some version details, to allow for future flexibility.Quoted 7 lines
With the associated edk2/ovmf firmware, the Windows HLK "PPI 1.3" test now runs successfully.
It is based on previous work from Stefan Berger ("[PATCH v2 0/4] Implement Physical Presence interface for TPM 1.2 and 2")
The edk2 support is merged upstream.
Quoted 6 lines
Breaks build with tpm disabled:
/usr/bin/ld:hw/i386/acpi-build.o: in function `build_dsdt':
/scm/qemu/hw/i386/acpi-build.c:2158: undefined reference totpm_build_ppi_acpi' /usr/bin/ld: /scm/qemu/hw/i386/acpi-build.c:2179: undefined reference totpm_build_ppi_acpi'
collect2: error: ld returned 1 exit statusThanks for noticing, this is probably a regression from v13, since the
tpm_build_ppi_acpiwas moved to a separate unit that is not always built.There is a lot of TPM code that we always build in acpi-build. Either the code should have #ifdef TPM, or we use stubs.
Quoted 7 lines
Quoted 4 lines
Quoted 2 lines
Fwiw, the preliminary #ifdef patch would look like that, is that desirable, or should we just add some stub:
Seems way too messy. I'd prefer stubs.
Beside the missing stub, and an indentation fix, could someone review the last 2 patches?
I think they are fine was going to merge.
Quoted 185 lines
Quoted 180 lines
Quoted 180 lines
hw/i386/acpi-build.c +16
-4@@ -41,14 +41,16 @@#include "hw/isa/isa.h" #include "hw/block/fdc.h" #include "hw/acpi/memory_hotplug.h" +#ifdef CONFIG_TPM #include "sysemu/tpm.h" #include "hw/acpi/tpm.h" -#include "hw/acpi/vmgenid.h" #include "sysemu/tpm_backend.h" +#endif +#include "hw/acpi/vmgenid.h" #include "hw/timer/mc146818rtc_regs.h" #include "hw/mem/memory-device.h" #include "sysemu/numa.h" - +#include "qemu/units.h" /* Supported chipsets: */ #include "hw/acpi/piix4.h" #include "hw/acpi/pcihp.h" @@ -105,7 +107,9 @@ typedef struct AcpiPmInfo { typedef struct AcpiMiscInfo { bool is_piix4; bool has_hpet; +#ifdef CONFIG_TPM TPMVersion tpm_version; +#endif const unsigned char *dsdt_code; unsigned dsdt_size; uint16_t pvpanic_port;@@ -234,7 +238,9 @@ static void acpi_get_misc_info(AcpiMiscInfo *info) } info->has_hpet =hpet_find (); +#ifdef CONFIG_TPM info->tpm_version =tpm_get_version (tpm_find ()); +#endif info->pvpanic_port =pvpanic_port (); info->applesmc_io_base =applesmc_port (); }@@ -1962,10 +1968,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, } } +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) {aml_append (crs,aml_memory32_fixed (TPM_TIS_ADDR_BASE ,TPM_TIS_ADDR_SIZE ,AML_READ_WRITE )); } +#endif aml_append (scope,aml_name_decl ("_CRS" , crs));/* reserve GPE0 block resources */ @@ -2133,6 +2141,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,/* Scan all PCI buses. Generate tables to support hotplug. */ build_append_pci_bus_devices (scope, bus, pm->pcihp_bridge_en); +#ifdef CONFIG_TPM if (TPM_IS_TIS (tpm_find ())) { dev =aml_device ("ISA.TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_eisaid ("PNP0C31" )));@@ -2149,11 +2158,12 @@ build_dsdt(GArray *table_data, BIOSLinker *linker,aml_append (dev,aml_name_decl ("_CRS" , crs));aml_append (scope, dev); } - +#endif aml_append (sb_scope, scope); } } +#ifdef CONFIG_TPM if (TPM_IS_CRB (tpm_find ())) { dev =aml_device ("TPM" );aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" )));@@ -2168,7 +2178,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, aml_append(sb_scope, dev); } - +#endif aml_append (dsdt, sb_scope);/* copy AML table into ACPI tables blob and patch header there */ @@ -2194,6 +2204,7 @@ build_hpet(GArray *table_data, BIOSLinker *linker) (void *)hpet, "HPET", sizeof(*hpet), 1, NULL, NULL); } +#ifdef CONFIG_TPM static void build_tpm_tcpa (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) {@@ -2247,6 +2258,7 @@ build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)build_header (linker, table_data, (void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL); } +#endif #define HOLE_640K_START (640 * KiB)#define
HOLE_640K_END(1 * MiB)hw/i386/acpi-build.c +1
-0@@ -2679,6 +2691,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine)acpi_add_table (table_offsets ,tables_blob );build_hpet (tables_blob, tables->linker); } +#ifdef CONFIG_TPM if (misc.tpm_version !=TPM_VERSION_UNSPEC ) {acpi_add_table (table_offsets, tables_blob);build_tpm_tcpa(tables_blob, tables->linker, tables->tcpalog);hw/i386/acpi-build.c +1
-0@@ -2688,6 +2701,7 @@ void acpi_build(AcpiBuildTables *tables, MachineState *machine) build_tpm2(tables_blob, tables->linker, tables->tcpalog); } } +#endif if (pcms->numa_nodes) {acpi_add_table (table_offsets, tables_blob);build_srat(tables_blob, tables->linker, machine);hw/i386/acpi-build.c +2
-1@@ -2886,9 +2900,10 @@ void acpi_setup(void)acpi_add_rom_blob (build_state, tables.linker->cmd_blob,"etc/table-loader" ,0 ); +#ifdef CONFIG_TPM fw_cfg_add_file (pcms->fw_cfg,ACPI_BUILD_TPMLOG_FILE , tables.tcpalog->data,acpi_data_len (tables.tcpalog)); - +#endif vmgenid_dev =find_vmgenid_dev ();if (vmgenid_dev) { vmgenid_add_fw_cfg(VMGENID(vmgenid_dev), pcms->fw_cfg,Quoted 38 lines
Quoted 38 lines
v13:
- removed needless error handling intpm_ppi_init()
- splitted "add ACPI memory clear interface"
- moved acpi build function in dedicatedhw/acpi/tpm.c
- added some function documentation in headers
- various code cleanups suggested by Philippe
- rebasedMarc-André Lureau (3):
tpm: add a "ppi" boolean property
acpi: add ACPI memory clear interface
tpm: clear RAM when "memory overwrite" requestedStefan Berger (3):
tpm: allocate/map buffer for TPM Physical Presence interface
acpi: expose TPM/PPI configuration parameters to firmware viafw_cfg
acpi: build TPM Physical Presence interfacehw/tpm/tpm_ppi.h | 47 +++++ include/hw/acpi/tpm.h | 23 +++ include/hw/compat.h | 11 +- hw/acpi/tpm.c | 447 ++++++++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 29 ++- hw/tpm/tpm_crb.c | 11 ++ hw/tpm/tpm_ppi.c | 53 +++++ hw/tpm/tpm_tis.c | 11 ++ docs/specs/tpm.txt | 104 ++++++++++ hw/acpi/Makefile.objs | 1 + hw/tpm/Makefile.objs | 1 + hw/tpm/trace-events | 3 + 12 files changed, 738 insertions(+), 3 deletions(-) create mode 100644 hw/tpm/tpm_ppi.h create mode 100644 hw/acpi/tpm.c create mode 100644 hw/tpm/tpm_ppi.cQuoted 3 lines
Quoted 2 lines
--
2.20.0--
Marc-André LureauSignature · 1 line
Marc-André Lureau