vTPM/aarch64 ACPI support
v3 cover vTPM/aarch64 ACPI support
Those patches bring MMIO TPM TIS ACPI support in machvirt. The TPM2 build function is converted to build_append style. Then the code is moved to the generic part.
On ARM, the TPM2 table is added when the TPM TIS sysbus device is dynamically instantiated in machvirt.
Also the TPM2 device object is described in the DSDT.
Many thanks to Ard for his support.
Tested with LUKS partition automatic decryption. Also tested with new bios-tables-test dedicated tests, sent separately.
Depends on "acpi: tpm: Do not build TCPA table for TPM 2"
Best Regards
Eric
This series can be found at:
https://github.com/eauger/qemu/tree/v5.0-tpm-acpi-v3
History:
v2 -> v3:
- Rebase on top of Stefan's
"acpi: tpm: Do not build TCPA table for TPM 2"
- brings conversion to build_append
v1 -> v2:
- move build_tpm2() in the generic code (Michael)
- collect Stefan's R-b on 3/3
Eric Auger (4):
acpi: Convert build_tpm2() to build_append* API
acpi: Move build_tpm2() in the generic part arm/acpi: TPM2 ACPI table support
arm/acpi: Add the TPM2.0 device under the DSDT
include/hw/acpi/aml-build.h | 2 ++ include/sysemu/tpm.h | 2 ++ hw/acpi/aml-build.c | 45 +++++++++++++++++++++++++++++++++++++ hw/arm/virt-acpi-build.c | 39 ++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 34 ---------------------------- 5 files changed, 88 insertions(+), 34 deletions(-)
Signature · 1 line
2.20.1
PATCH v3 1/4 acpi: Convert build_tpm2() to build_append* API
In preparation of its move to the generic acpi code, let's convert build_tpm2() to use build_append API. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.
--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)
hw/i386/acpi-build.c +19 -9
@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)static void build_tpm2 (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) { -Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof *tpm2_ptr); +Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof (AcpiTableHeader));unsigned log_addr_size =sizeof (tpm2_ptr->log_area_start_address);unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data; +uint8_t start_method_params[12 ] = {}; - tpm2_ptr->platform_class =cpu_to_le16 (TPM2_ACPI_CLASS_CLIENT ); +/* platform class */ +build_append_int_noprefix (table_data,TPM2_ACPI_CLASS_CLIENT ,2 ); +/* reserved */ +build_append_int_noprefix (table_data,0 ,2 );if (TPM_IS_TIS_ISA (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (0 ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_MMIO ); +/* address of control area */ +build_append_int_noprefix (table_data,0 ,8 ); +/* start method */ +build_append_int_noprefix (table_data,TPM2_START_METHOD_MMIO ,4 ); }else if (TPM_IS_CRB (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (TPM_CRB_ADDR_CTRL ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_CRB ); +build_append_int_noprefix (table_data,TPM_CRB_ADDR_CTRL ,8 ); +build_append_int_noprefix (table_data,TPM2_START_METHOD_CRB ,4 ); }else {g_warn_if_reached (); } - tpm2_ptr->log_area_minimum_length = -cpu_to_le32 (TPM_LOG_AREA_MINIMUM_SIZE ); +/* platform specific parameters */ +g_array_append_vals (table_data, &start_method_params,12 ); -acpi_data_push (tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); +/* log area minimum length */ +build_append_int_noprefix (table_data,TPM_LOG_AREA_MINIMUM_SIZE ,4 ); + +acpi_data_push (tcpalog,TPM_LOG_AREA_MINIMUM_SIZE );bios_linker_loader_alloc (linker,ACPI_BUILD_TPMLOG_FILE , tcpalog,1 , false);/* log area start address to be filled by Guest linker */ +build_append_int_noprefix (table_data,0 ,8 );bios_linker_loader_add_pointer (linker,ACPI_BUILD_TABLE_FILE , log_addr_offset, log_addr_size,ACPI_BUILD_TPMLOG_FILE ,0 );
Signature · 1 line
2.20.1
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
Quoted 15 lines · Eric Auger
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)hw/i386/acpi-build.c +0
-0
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2301
Quoted 5 lines
hw/i386/acpi-build.c +1
-1@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)static void build_tpm2 (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) { -Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof *tpm2_ptr); +Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof (AcpiTableHeader));
And now you want to build the data structure by pushing fields? I would definitely NOT do this.
Quoted 44 lines
hw/i386/acpi-build.c +18
-8unsigned log_addr_size =sizeof (tpm2_ptr->log_area_start_address);unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data; +uint8_t start_method_params[12 ] = {}; - tpm2_ptr->platform_class =cpu_to_le16 (TPM2_ACPI_CLASS_CLIENT ); +/* platform class */ +build_append_int_noprefix (table_data,TPM2_ACPI_CLASS_CLIENT ,2 ); +/* reserved */ +build_append_int_noprefix (table_data,0 ,2 );if (TPM_IS_TIS_ISA (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (0 ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_MMIO ); +/* address of control area */ +build_append_int_noprefix (table_data,0 ,8 ); +/* start method */ +build_append_int_noprefix (table_data,TPM2_START_METHOD_MMIO ,4 ); }else if (TPM_IS_CRB (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (TPM_CRB_ADDR_CTRL ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_CRB ); +build_append_int_noprefix (table_data,TPM_CRB_ADDR_CTRL ,8 ); +build_append_int_noprefix (table_data,TPM2_START_METHOD_CRB ,4 ); }else {g_warn_if_reached (); } - tpm2_ptr->log_area_minimum_length = -cpu_to_le32 (TPM_LOG_AREA_MINIMUM_SIZE ); +/* platform specific parameters */ +g_array_append_vals (table_data, &start_method_params,12 ); -acpi_data_push (tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); +/* log area minimum length */ +build_append_int_noprefix (table_data,TPM_LOG_AREA_MINIMUM_SIZE ,4 ); + +acpi_data_push (tcpalog,TPM_LOG_AREA_MINIMUM_SIZE );bios_linker_loader_alloc (linker,ACPI_BUILD_TPMLOG_FILE , tcpalog,1 , false);/* log area start address to be filled by Guest linker */ +build_append_int_noprefix (table_data,0 ,8 );bios_linker_loader_add_pointer (linker,ACPI_BUILD_TABLE_FILE , log_addr_offset, log_addr_size,ACPI_BUILD_TPMLOG_FILE ,0 );
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
Hi Stefan,
Quoted 11 lines · Stefan Berger
Quoted 10 lines · Eric Auger
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>---
hw/i386/acpi-build.c| 28 +++++++++++++++++++---------1 file changed, 19 insertions(+), 9 deletions(-)
Quoted 15 lines
Quoted 6 lines
hw/i386/acpi-build.c +0
-0@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)Quoted 6 lines
static void
build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog){
- Acpi20TPM2*tpm2_ptr=acpi_data_push(table_data, sizeof *tpm2_ptr); + Acpi20TPM2*tpm2_ptr=acpi_data_push(table_data, sizeof(AcpiTableHeader));And now you want to build the data structure by pushing fields? I would definitely NOT do this.
If I didn't misinterpret things, this was recommended by Drew and Igor as buid_append* API avoids to take care of endianness and this is the API now used in the generic ACPI code. Besides I also think that in that case it does not simplify things but maybe I did that the wrong way? Or maybe I didn't understand your remark?
Thanks
Eric
Quoted 47 lines
Quoted 45 lines
unsigned
log_addr_size=sizeof(tpm2_ptr->log_area_start_address); unsignedlog_addr_offset=
(char *)&tpm2_ptr->log_area_start_address -table_data->data; +uint8_tstart_method_params[12] = {};
-tpm2_ptr->platform_class=cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); + /* platform class */
+build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2); + /* reserved */
+build_append_int_noprefix(table_data, 0, 2);
if (TPM_IS_TIS_ISA(tpm_find())) {
-tpm2_ptr->control_area_address=cpu_to_le64(0);
-tpm2_ptr->start_method=cpu_to_le32(TPM2_START_METHOD_MMIO); + /* address of control area */
+build_append_int_noprefix(table_data, 0, 8);
+ /* start method */
+build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO, 4);
} else if (TPM_IS_CRB(tpm_find())) {
-tpm2_ptr->control_area_address=cpu_to_le64(TPM_CRB_ADDR_CTRL); -tpm2_ptr->start_method=cpu_to_le32(TPM2_START_METHOD_CRB); +build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8); +build_append_int_noprefix(table_data, TPM2_START_METHOD_CRB, 4); } else {
g_warn_if_reached();
}
-tpm2_ptr->log_area_minimum_length=
-cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+ /* platform specific parameters */
+g_array_append_vals(table_data, &start_method_params, 12); -acpi_data_push(tcpalog, le32_to_cpu(tpm2_ptr->log_area_minimum_length));
+ /* log area minimum length */
+build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4); +
+acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE); bios_linker_loader_alloc(linker,ACPI_BUILD_TPMLOG_FILE, tcpalog, 1,
false);
/* log area start address to be filled by Guest linker */ +build_append_int_noprefix(table_data, 0, 8);bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, log_addr_offset, log_addr_size, ACPI_BUILD_TPMLOG_FILE, 0);
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
Quoted 27 lines · Auger Eric
Hi Stefan,
Quoted 11 lines · Stefan Berger
Quoted 10 lines · Eric Auger
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)Quoted 14 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker · line 2303
Quoted 12 lines
hw/i386/acpi-build.c +1
-1@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) static void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) { - Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr); + Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data,sizeof (AcpiTableHeader));And now you want to build the data structure by pushing fields? I would definitely NOT do this.
Quoted 5 lines
If I didn't misinterpret things, this was recommended by Drew and Igor as buid_append* API avoids to take care of endianness and this is the API now used in the generic ACPI code. Besides I also think that in that case it does not simplify things but maybe I did that the wrong way? Or maybe I didn't understand your remark?
If that's what they are saying... I would prefer filling out data structures with functions like cpu_to_acpi16() because that seems to be less error prone.
Quoted 22 lines
Quoted 22 lines
Quoted 22 lines
hw/i386/acpi-build.c +10
-4unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address); unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data; + uint8_t start_method_params[12] = {}; - tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); + /* platform class */ + build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2); + /* reserved */ + build_append_int_noprefix(table_data, 0, 2); if (TPM_IS_TIS_ISA(tpm_find())) { - tpm2_ptr->control_area_address = cpu_to_le64(0); - tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO); + /* address of control area */ + build_append_int_noprefix(table_data, 0, 8); + /* start method */ + build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO,4 ); } else if (TPM_IS_CRB(tpm_find())) { - tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL); - tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB); + build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8);
Quoted 8 lines
Quoted 8 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2324
Quoted 8 lines
hw/i386/acpi-build.c +3
-1+ build_append_int_noprefix(table_data, TPM2_START_METHOD_CRB, 4); } else { g_warn_if_reached(); } - tpm2_ptr->log_area_minimum_length = - cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE); + /* platform specific parameters */ + g_array_append_vals(table_data, &start_method_params, 12);
Maybe this should be wrapped in an inline function like build_append_array() or so.
Quoted 6 lines
Quoted 6 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2329
Quoted 6 lines
hw/i386/acpi-build.c +4
-0- acpi_data_push(tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); + /* log area minimum length */ + build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4); + + acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
At this point we have a double-allocation of log memory on x86_64. You'd need the patch I posted to create the TCPA table only for TPM 1.2.
Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
hw/i386/acpi-build.c +1
-0bios_linker_loader_alloc(linker, ACPI_BUILD_TPMLOG_FILE, tcpalog,1 , false); /* log area start address to be filled by Guest linker */ + build_append_int_noprefix(table_data, 0, 8); bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, log_addr_offset, log_addr_size, ACPI_BUILD_TPMLOG_FILE, 0);
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
Hi Stefan,
Quoted 36 lines · Stefan Berger
Quoted 28 lines · Auger Eric
Hi Stefan,
Quoted 11 lines · Stefan Berger
Quoted 10 lines · Eric Auger
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>---
hw/i386/acpi-build.c| 28 +++++++++++++++++++---------1 file changed, 19 insertions(+), 9 deletions(-)Quoted 15 lines
Quoted 6 lines
hw/i386/acpi-build.c +0
-0@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)Quoted 7 lines
static void
build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog){
- Acpi20TPM2*tpm2_ptr=acpi_data_push(table_data, sizeof *tpm2_ptr);
+ Acpi20TPM2*tpm2_ptr=acpi_data_push(table_data, sizeof(AcpiTableHeader));And now you want to build the data structure by pushing fields? I would definitely NOT do this.
Quoted 5 lines
If I didn't misinterpret things, this was recommended by Drew and Igor as buid_append* API avoids to take care of endianness and this is the API now used in the generic ACPI code. Besides I also think that in that case it does not simplify things but maybe I did that the wrong way? Or maybe I didn't understand your remark?
Quoted 3 lines
If that's what they are saying... I would prefer filling out data structures with functions like
cpu_to_acpi16()because that seems to be less error prone.
understood. Let's wait for other comments and we will make a decision wrt direction.
Quoted 37 lines
Quoted 28 lines
Quoted 28 lines
Quoted 28 lines
unsigned
log_addr_size=sizeof(tpm2_ptr->log_area_start_address);
unsignedlog_addr_offset=
(char *)&tpm2_ptr->log_area_start_address -table_data->data;
+uint8_tstart_method_params[12] = {};
-tpm2_ptr->platform_class=cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); + /* platform class */
+build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2); + /* reserved */
+build_append_int_noprefix(table_data, 0, 2);
if (TPM_IS_TIS_ISA(tpm_find())) {
-tpm2_ptr->control_area_address=cpu_to_le64(0);
-tpm2_ptr->start_method=cpu_to_le32(TPM2_START_METHOD_MMIO); + /* address of control area */
+build_append_int_noprefix(table_data, 0, 8);
+ /* start method */
+build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO, 4);
} else if (TPM_IS_CRB(tpm_find())) {
-tpm2_ptr->control_area_address=cpu_to_le64(TPM_CRB_ADDR_CTRL);
-tpm2_ptr->start_method=cpu_to_le32(TPM2_START_METHOD_CRB); +build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8); + build_append_int_noprefix(table_data,Quoted 8 lines
Quoted 8 lines
Quoted 8 lines
TPM2_START_METHOD_CRB, 4);
} else {
g_warn_if_reached();
}
-tpm2_ptr->log_area_minimum_length=
-cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE);
+ /* platform specific parameters */
+g_array_append_vals(table_data, &start_method_params, 12);
Quoted 2 lines
Maybe this should be wrapped in an inline function like
build_append_array()or so.
Hum OK
Quoted 11 lines
Quoted 9 lines
Quoted 9 lines
Quoted 9 lines
-
acpi_data_push(tcpalog, le32_to_cpu(tpm2_ptr->log_area_minimum_length)); + /* log area minimum length */
+build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4);
+
+acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
Quoted 2 lines
At this point we have a double-allocation of log memory on
x86_64. You'd need the patch I posted to create the TCPA table only for TPM 1.2.
This series applies on top of this patch (mentionned in the cover letter).
Quoted 15 lines
Quoted 12 lines
Quoted 12 lines
Quoted 11 lines
bios_linker_loader_alloc(linker,
ACPI_BUILD_TPMLOG_FILE, tcpalog, 1,
false);
/* log area start address to be filled by Guest linker */ +build_append_int_noprefix(table_data, 0, 8);bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, log_addr_offset, log_addr_size, ACPI_BUILD_TPMLOG_FILE, 0);
Thanks
Eric
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
In reply to Stefan BergerQuoted 35 lines · On Tue, 2 Jun 2020 10:24:03 -0400 Stefan Berger <[email protected]> wrote:
Quoted 27 lines · Auger Eric
Hi Stefan,
Quoted 11 lines · Stefan Berger
Quoted 10 lines · Eric Auger
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)Quoted 14 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker · line 2303
Quoted 12 lines
hw/i386/acpi-build.c +1
-1@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) static void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) { - Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof *tpm2_ptr); + Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data,sizeof (AcpiTableHeader));And now you want to build the data structure by pushing fields? I would definitely NOT do this.
Quoted 5 lines
If I didn't misinterpret things, this was recommended by Drew and Igor as buid_append* API avoids to take care of endianness and this is the API now used in the generic ACPI code. Besides I also think that in that case it does not simplify things but maybe I did that the wrong way? Or maybe I didn't understand your remark?
Quoted 3 lines
If that's what they are saying... I would prefer filling out data structures with functions like
cpu_to_acpi16()because that seems to be less error prone.
practice showed it was opposite, it was easy to forget about cpu_to_le build_append_int_noprefix() API we don't have to care about endiannes issues anymore at places where API is used.
Another reasons for using build_append_int_noprefix() is that one doesn't have to define packed structures, work around unaligned access and bit plus is when I review patch it boiles down to comparing it with table in a spec row by row as API enforces the same order as in spec, which makes reviews much easier.
Quoted 32 lines
Quoted 23 lines
Quoted 23 lines
Quoted 23 lines
hw/i386/acpi-build.c +10
-4unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address); unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data; + uint8_t start_method_params[12] = {}; - tpm2_ptr->platform_class = cpu_to_le16(TPM2_ACPI_CLASS_CLIENT); + /* platform class */ + build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2); + /* reserved */ + build_append_int_noprefix(table_data, 0, 2); if (TPM_IS_TIS_ISA(tpm_find())) { - tpm2_ptr->control_area_address = cpu_to_le64(0); - tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_MMIO); + /* address of control area */ + build_append_int_noprefix(table_data, 0, 8); + /* start method */ + build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO,4 ); } else if (TPM_IS_CRB(tpm_find())) { - tpm2_ptr->control_area_address = cpu_to_le64(TPM_CRB_ADDR_CTRL); - tpm2_ptr->start_method = cpu_to_le32(TPM2_START_METHOD_CRB); + build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8);Quoted 8 lines
Quoted 8 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2324
Quoted 8 lines
hw/i386/acpi-build.c +3
-1+ build_append_int_noprefix(table_data, TPM2_START_METHOD_CRB, 4); } else { g_warn_if_reached(); } - tpm2_ptr->log_area_minimum_length = - cpu_to_le32(TPM_LOG_AREA_MINIMUM_SIZE); + /* platform specific parameters */ + g_array_append_vals(table_data, &start_method_params, 12);
Quoted 2 lines
Maybe this should be wrapped in an inline function like
build_append_array()or so.
I guss I'm just used to g_array_append_vals() but build_append_array() looks nicer and consistent with build_append_foo API
Quoted 27 lines
Quoted 8 lines
Quoted 8 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2329
Quoted 8 lines
hw/i386/acpi-build.c +4
-0- acpi_data_push(tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); + /* log area minimum length */ + build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4); + + acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);At this point we have a double-allocation of log memory on
x86_64. You'd need the patch I posted to create the TCPA table only for TPM 1.2.Quoted 9 lines
Quoted 9 lines
Quoted 8 lines
hw/i386/acpi-build.c +1
-0bios_linker_loader_alloc(linker, ACPI_BUILD_TPMLOG_FILE, tcpalog,1 , false); /* log area start address to be filled by Guest linker */ + build_append_int_noprefix(table_data, 0, 8); bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE, log_addr_offset, log_addr_size, ACPI_BUILD_TPMLOG_FILE, 0);
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
In reply to Eric AugerQuoted 15 lines · On Mon, 1 Jun 2020 11:57:34 +0200 Eric Auger <[email protected]> wrote:
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)hw/i386/acpi-build.c +0
-0
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2305
Quoted 9 lines
hw/i386/acpi-build.c +1
-1@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)static void build_tpm2 (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) { -Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof *tpm2_ptr); +Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof (AcpiTableHeader));unsigned log_addr_size =sizeof (tpm2_ptr->log_area_start_address);unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data;
Is this the reason why you've kept Acpi20TPM2 around?
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2307
Quoted 4 lines
hw/i386/acpi-build.c +2
-1+uint8_t start_method_params[12 ] = {}; - tpm2_ptr->platform_class =cpu_to_le16 (TPM2_ACPI_CLASS_CLIENT ); +/* platform class */
pls verbatim filed names from spec in comments
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2312
Quoted 13 lines
hw/i386/acpi-build.c +7
-4+build_append_int_noprefix (table_data,TPM2_ACPI_CLASS_CLIENT ,2 ); +/* reserved */ +build_append_int_noprefix (table_data,0 ,2 );if (TPM_IS_TIS_ISA (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (0 ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_MMIO ); +/* address of control area */ +build_append_int_noprefix (table_data,0 ,8 ); +/* start method */ +build_append_int_noprefix (table_data,TPM2_START_METHOD_MMIO ,4 ); }else if (TPM_IS_CRB (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (TPM_CRB_ADDR_CTRL ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_CRB );
missing field name comments
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2321
Quoted 5 lines
hw/i386/acpi-build.c +2
-0+build_append_int_noprefix (table_data,TPM_CRB_ADDR_CTRL ,8 ); +build_append_int_noprefix (table_data,TPM2_START_METHOD_CRB ,4 ); }else {g_warn_if_reached (); }
considering fields are the same I'd also restructure above as
if () {
control_area_address =
start_method =
...
}
/* address of control area */
build_append_int_noprefix(table_data, control_area_address, 8);
/* start method */
build_append_int_noprefix(table_data, start_method, 4); which is bit easier to read
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2331
Quoted 13 lines
hw/i386/acpi-build.c +6
-3- tpm2_ptr->log_area_minimum_length = -cpu_to_le32 (TPM_LOG_AREA_MINIMUM_SIZE ); +/* platform specific parameters */ +g_array_append_vals (table_data, &start_method_params,12 ); -acpi_data_push (tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); +/* log area minimum length */ +build_append_int_noprefix (table_data,TPM_LOG_AREA_MINIMUM_SIZE ,4 ); + +acpi_data_push (tcpalog,TPM_LOG_AREA_MINIMUM_SIZE );bios_linker_loader_alloc (linker,ACPI_BUILD_TPMLOG_FILE , tcpalog,1 , false);
I suggest to drop Acpi20TPM2 with pointer math above and use approach similar to build_ghes_v2/address_offset, i.e. get actual offest here:
log_addr_offset = table_data->len
and s/log_addr_size/8/
Quoted 5 lines
hw/i386/acpi-build.c +1
-0/* log area start address to be filled by Guest linker */ +build_append_int_noprefix (table_data,0 ,8 );bios_linker_loader_add_pointer (linker,ACPI_BUILD_TABLE_FILE , log_addr_offset, log_addr_size,ACPI_BUILD_TPMLOG_FILE ,0 );
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
Hi Igor,
Quoted 24 lines · Igor Mammedov
Quoted 20 lines · On Mon, 1 Jun 2020 11:57:34 +0200 Eric Auger <[email protected]> wrote:
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)hw/i386/acpi-build.c +1
-1@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)static void build_tpm2 (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) { -Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof *tpm2_ptr); +Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof (AcpiTableHeader));
Quoted 5 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2304
Quoted 3 lines
hw/i386/acpi-build.c +0
-0unsigned log_addr_size =sizeof (tpm2_ptr->log_area_start_address);unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data;Is this the reason why you've kept Acpi20TPM2 around?
Yes it is
Quoted 7 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2307
Quoted 6 lines
hw/i386/acpi-build.c +2
-1+uint8_t start_method_params[12 ] = {}; - tpm2_ptr->platform_class =cpu_to_le16 (TPM2_ACPI_CLASS_CLIENT ); +/* platform class */ pls verbatim filed names from spec in comments
Do you want "Platform Class" instead?
Quoted 15 lines
Quoted 4 lines
hw/i386/acpi-build.c +3
-0+build_append_int_noprefix (table_data,TPM2_ACPI_CLASS_CLIENT ,2 ); +/* reserved */ +build_append_int_noprefix (table_data,0 ,2 );hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2312
Quoted 10 lines
hw/i386/acpi-build.c +4
-4if (TPM_IS_TIS_ISA (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (0 ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_MMIO ); +/* address of control area */ +build_append_int_noprefix (table_data,0 ,8 ); +/* start method */ +build_append_int_noprefix (table_data,TPM2_START_METHOD_MMIO ,4 ); }else if (TPM_IS_CRB (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (TPM_CRB_ADDR_CTRL ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_CRB );
Quoted 1 line
missing field name comments
OK
Quoted 18 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2321
Quoted 6 lines
hw/i386/acpi-build.c +2
-0+build_append_int_noprefix (table_data,TPM_CRB_ADDR_CTRL ,8 ); +build_append_int_noprefix (table_data,TPM2_START_METHOD_CRB ,4 ); }else {g_warn_if_reached (); }considering fields are the same I'd also restructure above as
if () { control_area_address = start_method = ... } /* address of control area */ build_append_int_noprefix(table_data, control_area_address, 8); /* start method */ build_append_int_noprefix(table_data, start_method, 4);
Quoted 1 line
which is bit easier to read
OK
Quoted 15 lines
Quoted 4 lines
hw/i386/acpi-build.c +0
-2- tpm2_ptr->log_area_minimum_length = -cpu_to_le32 (TPM_LOG_AREA_MINIMUM_SIZE );hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2331
Quoted 10 lines
hw/i386/acpi-build.c +6
-1+/* platform specific parameters */ +g_array_append_vals (table_data, &start_method_params,12 ); -acpi_data_push (tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); +/* log area minimum length */ +build_append_int_noprefix (table_data,TPM_LOG_AREA_MINIMUM_SIZE ,4 ); + +acpi_data_push (tcpalog,TPM_LOG_AREA_MINIMUM_SIZE );bios_linker_loader_alloc (linker,ACPI_BUILD_TPMLOG_FILE , tcpalog,1 , false);
Quoted 4 lines
I suggest to drop Acpi20TPM2 with pointer math above and use approach similar to build_ghes_v2/address_offset, i.e. get actual offest here:
log_addr_offset = table_data->len
yes, that's simpler. Thank you for the suggestion.
Quoted 2 lines
and s/log_addr_size/8/
OK
Thanks
Eric
Quoted 7 lines
Quoted 6 lines
hw/i386/acpi-build.c +1
-0/* log area start address to be filled by Guest linker */ +build_append_int_noprefix (table_data,0 ,8 );bios_linker_loader_add_pointer (linker,ACPI_BUILD_TABLE_FILE , log_addr_offset, log_addr_size,ACPI_BUILD_TPMLOG_FILE ,0 );
Re: [PATCH v3 1/4] acpi: Convert build_tpm2() to build_append* API
Quoted 35 lines · On Wed, 10 Jun 2020 18:15:07 +0200 Auger Eric <[email protected]> wrote:
Hi Igor,
Quoted 24 lines · Igor Mammedov
Quoted 20 lines · On Mon, 1 Jun 2020 11:57:34 +0200 Eric Auger <[email protected]> wrote:
In preparation of its move to the generic acpi code, let's convert
build_tpm2()to usebuild_appendAPI. This latter now is prefered in place of direct ACPI struct field settings with manual endianness conversion.Signed-off-by Eric Auger <[email protected]>--- hw/i386/acpi-build.c | 28 +++++++++++++++++++--------- 1 file changed, 19 insertions(+), 9 deletions(-)hw/i386/acpi-build.c +1
-1@@ -2298,30 +2298,40 @@ build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)static void build_tpm2 (GArray *table_data,BIOSLinker *linker,GArray *tcpalog) { -Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof *tpm2_ptr); +Acpi20TPM2 *tpm2_ptr =acpi_data_push (table_data,sizeof (AcpiTableHeader));Quoted 5 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2304
Quoted 3 lines
hw/i386/acpi-build.c +0
-0unsigned log_addr_size =sizeof (tpm2_ptr->log_area_start_address);unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data;Is this the reason why you've kept Acpi20TPM2 around?
Yes it is
Quoted 2 lines
Quoted 6 lines
Quoted 5 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2307
Quoted 4 lines
hw/i386/acpi-build.c +2
-1+uint8_t start_method_params[12 ] = {}; - tpm2_ptr->platform_class =cpu_to_le16 (TPM2_ACPI_CLASS_CLIENT ); +/* platform class */ pls verbatim filed names from spec in comments
Do you want "Platform Class" instead?
yep, just copy past field names from spec as is.
Quoted 71 lines
Quoted 15 lines
Quoted 4 lines
hw/i386/acpi-build.c +3
-0+build_append_int_noprefix (table_data,TPM2_ACPI_CLASS_CLIENT ,2 ); +/* reserved */ +build_append_int_noprefix (table_data,0 ,2 );hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2312
Quoted 10 lines
hw/i386/acpi-build.c +4
-4if (TPM_IS_TIS_ISA (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (0 ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_MMIO ); +/* address of control area */ +build_append_int_noprefix (table_data,0 ,8 ); +/* start method */ +build_append_int_noprefix (table_data,TPM2_START_METHOD_MMIO ,4 ); }else if (TPM_IS_CRB (tpm_find ())) { - tpm2_ptr->control_area_address =cpu_to_le64 (TPM_CRB_ADDR_CTRL ); - tpm2_ptr->start_method =cpu_to_le32 (TPM2_START_METHOD_CRB );Quoted 1 line
missing field name comments
OK
Quoted 18 lines
hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2321
Quoted 6 lines
hw/i386/acpi-build.c +2
-0+build_append_int_noprefix (table_data,TPM_CRB_ADDR_CTRL ,8 ); +build_append_int_noprefix (table_data,TPM2_START_METHOD_CRB ,4 ); }else {g_warn_if_reached (); }considering fields are the same I'd also restructure above as
if () { control_area_address = start_method = ... } /* address of control area */ build_append_int_noprefix(table_data, control_area_address, 8); /* start method */ build_append_int_noprefix(table_data, start_method, 4);Quoted 1 line
which is bit easier to read
OK
Quoted 15 lines
Quoted 4 lines
hw/i386/acpi-build.c +0
-2- tpm2_ptr->log_area_minimum_length = -cpu_to_le32 (TPM_LOG_AREA_MINIMUM_SIZE );hw/i386/acpi-build.c build_tpm_tcpa(GArray *table_data, BIOSLinker *linker, GArray *tcpalog) · line 2331
Quoted 10 lines
hw/i386/acpi-build.c +6
-1+/* platform specific parameters */ +g_array_append_vals (table_data, &start_method_params,12 ); -acpi_data_push (tcpalog,le32_to_cpu (tpm2_ptr->log_area_minimum_length)); +/* log area minimum length */ +build_append_int_noprefix (table_data,TPM_LOG_AREA_MINIMUM_SIZE ,4 ); + +acpi_data_push (tcpalog,TPM_LOG_AREA_MINIMUM_SIZE );bios_linker_loader_alloc (linker,ACPI_BUILD_TPMLOG_FILE , tcpalog,1 , false);Quoted 4 lines
I suggest to drop Acpi20TPM2 with pointer math above and use approach similar to build_ghes_v2/address_offset, i.e. get actual offest here:
log_addr_offset = table_data->lenyes, that's simpler. Thank you for the suggestion.
Quoted 2 lines
and s/log_addr_size/8/
OK
Thanks
Eric
Quoted 7 lines
Quoted 6 lines
hw/i386/acpi-build.c +1
-0/* log area start address to be filled by Guest linker */ +build_append_int_noprefix (table_data,0 ,8 );bios_linker_loader_add_pointer (linker,ACPI_BUILD_TABLE_FILE , log_addr_offset, log_addr_size,ACPI_BUILD_TPMLOG_FILE ,0 );
PATCH v3 2/4 acpi: Move build_tpm2() in the generic part
In reply to Eric AugerWe plan to build the TPM2 table on ARM too. In order to reuse the generation code, let's move build_tpm2() to aml-build.c.
No change in the implementation.
--- include/hw/acpi/aml-build.h | 2 ++ hw/acpi/aml-build.c | 44 +++++++++++++++++++++++++++++++++++++ hw/i386/acpi-build.c | 44 ------------------------------------- 3 files changed, 46 insertions(+), 44 deletions(-)
include/hw/acpi/aml-build.h +2 -0
@@ -437,4 +437,6 @@ void build_slit(GArray *table_data, BIOSLinker *linker, MachineState *ms);void build_fadt (GArray *tbl,BIOSLinker *linker,const AcpiFadtData *f,const char *oem_id,const char *oem_table_id); + +void build_tpm2 (GArray *table_data,BIOSLinker *linker,GArray *tcpalog);#endif
hw/acpi/aml-build.c +44 -0
56 lines not on this page · raw message
hw/i386/acpi-build.c +0 -44
50 lines not on this page · raw message
Signature · 1 line
2.20.1
PATCH v3 3/4 arm/acpi: TPM2 ACPI table support
In reply to Eric AugerAdd a TPM2 ACPI table if a TPM2.0 sysbus device has been dynamically instantiated.
---
v2 -> v3:
- do not to need to create the log area anymore
v1 -> v2:
- reuse generic build_tpm2() and alloc log area externally
- call tpm_find() once in build_tpm2()
--- include/sysemu/tpm.h | 2 ++ hw/acpi/aml-build.c | 5 +++-- hw/arm/virt-acpi-build.c | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-)
include/sysemu/tpm.h +2 -0
@@ -50,6 +50,8 @@ typedef struct TPMIfClass {#define TPM_IS_TIS_ISA (chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_ISA) +#define TPM_IS_TIS_SYSBUS (chr) \ + object_dynamic_cast(OBJECT(chr), TYPE_TPM_TIS_SYSBUS)#define TPM_IS_CRB (chr) \ object_dynamic_cast(OBJECT(chr), TYPE_TPM_CRB)#define TPM_IS_SPAPR (chr) \
hw/acpi/aml-build.c +3 -2
@@ -1885,17 +1885,18 @@ void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)unsigned log_addr_offset = (char *)&tpm2_ptr->log_area_start_address - table_data->data;uint8_t start_method_params[12 ] = {}; +TPMIf *tpmif =tpm_find ();/* platform class */ build_append_int_noprefix (table_data,TPM2_ACPI_CLASS_CLIENT ,2 );/* reserved */ build_append_int_noprefix (table_data,0 ,2 ); -if (TPM_IS_TIS_ISA (tpm_find ())) { +if (TPM_IS_TIS_ISA (tpmif) ||TPM_IS_TIS_SYSBUS (tpmif)) {/* address of control area */ build_append_int_noprefix (table_data,0 ,8 );/* start method */ build_append_int_noprefix (table_data,TPM2_START_METHOD_MMIO ,4 ); - }else if (TPM_IS_CRB (tpm_find ())) { + }else if (TPM_IS_CRB (tpmif)) {build_append_int_noprefix (table_data,TPM_CRB_ADDR_CTRL ,8 );build_append_int_noprefix (table_data,TPM2_START_METHOD_CRB ,4 ); }else {
hw/arm/virt-acpi-build.c +7 -0
@@ -41,12 +41,14 @@#include "hw/acpi/pci.h" #include "hw/acpi/memory_hotplug.h" #include "hw/acpi/generic_event_device.h" +#include "hw/acpi/tpm.h" #include "hw/pci/pcie_host.h" #include "hw/pci/pci.h" #include "hw/arm/virt.h" #include "hw/mem/nvdimm.h" #include "sysemu/numa.h" #include "sysemu/reset.h" +#include "sysemu/tpm.h" #include "kvm_arm.h" #include "migration/vmstate.h" #include "hw/acpi/ghes.h"
@@ -844,6 +846,11 @@ void virt_acpi_build(VirtMachineState *vms, AcpiBuildTables *tables)build_iort (tables_blob, tables->linker, vms); } +if (tpm_get_version (tpm_find ()) ==TPM_VERSION_2_0 ) { +acpi_add_table (table_offsets, tables_blob); +build_tpm2 (tables_blob, tables->linker, tables->tcpalog); + } +/* XSDT is pointed to by RSDP */ xsdt = tables_blob->len;build_xsdt (tables_blob, tables->linker, table_offsets,NULL ,NULL );
Signature · 1 line
2.20.1
PATCH v3 4/4 arm/acpi: Add the TPM2.0 device under the DSDT
In reply to Eric AugerIn case it is dynamically instantiated, add the TPM 2.0 device object under the DSDT table in the ACPI namespace. Its HID is MSFT0101 while its current resource settings (CRS) property is initialized with the guest physical address and MMIO size of the device.
---
v2 -> v3:
- use SYS_BUS_DEVICE() instead of
(SysBusDevice *)object_dynamic_cast(OBJECT())
v1 -> v2:
- use memory_region_size
- fix mingw compilation issue by casting to uint32_t
- added Stefan's R-b
--- hw/arm/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)
hw/arm/virt-acpi-build.c +32 -0
@@ -46,6 +46,7 @@#include "hw/pci/pci.h" #include "hw/arm/virt.h" #include "hw/mem/nvdimm.h" +#include "hw/platform-bus.h" #include "sysemu/numa.h" #include "sysemu/reset.h" #include "sysemu/tpm.h"
@@ -364,6 +365,36 @@ static void acpi_dsdt_add_power_button(Aml *scope)aml_append (scope, dev); } +static void acpi_dsdt_add_tpm (Aml *scope,VirtMachineState *vms) +{ +hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS ].base; +PlatformBusDevice *pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); +MemoryRegion *sbdev_mr; +SysBusDevice *sbdev; +hwaddr tpm_base; + + sbdev =SYS_BUS_DEVICE (tpm_find ()); + + tpm_base =platform_bus_get_mmio_addr (pbus, sbdev,0 ); +assert (tpm_base !=-1 ); + + tpm_base += pbus_base; + + sbdev_mr =sysbus_mmio_get_region (sbdev,0 ); + +Aml *dev =aml_device ("TPM0" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +Aml *crs =aml_resource_template (); +aml_append (crs, +aml_memory32_fixed (tpm_base, + (uint32_t )memory_region_size (sbdev_mr), +AML_READ_WRITE )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (scope, dev); +} +static void build_iort (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms) {
@@ -758,6 +789,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) }acpi_dsdt_add_power_button (scope); +acpi_dsdt_add_tpm (scope, vms);aml_append (dsdt, scope);
Signature · 1 line
2.20.1
Re: [PATCH v3 4/4] arm/acpi: Add the TPM2.0 device under the DSDT
Quoted 72 lines · On Mon, 1 Jun 2020 11:57:37 +0200 Eric Auger <[email protected]> wrote:
In case it is dynamically instantiated, add the TPM 2.0 device object under the DSDT table in the ACPI namespace. Its HID is MSFT0101 while its current resource settings (CRS) property is initialized with the guest physical address and MMIO size of the device.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Stefan Berger <[email protected]>---
v2 -> v3:
- useSYS_BUS_DEVICE()instead of
(SysBusDevice *)object_dynamic_cast(OBJECT())v1 -> v2:
- usememory_region_size
- fix mingw compilation issue by casting touint32_t
- added Stefan's R-b--- hw/arm/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)hw/arm/virt-acpi-build.c +31
-0@@ -46,6 +46,7 @@#include "hw/pci/pci.h" #include "hw/arm/virt.h" #include "hw/mem/nvdimm.h" +#include "hw/platform-bus.h" #include "sysemu/numa.h" #include "sysemu/reset.h" #include "sysemu/tpm.h" @@ -364,6 +365,36 @@ static void acpi_dsdt_add_power_button(Aml *scope)aml_append (scope, dev); } +static void acpi_dsdt_add_tpm (Aml *scope,VirtMachineState *vms) +{ +hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS ].base; +PlatformBusDevice *pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); +MemoryRegion *sbdev_mr; +SysBusDevice *sbdev; +hwaddr tpm_base; + + sbdev =SYS_BUS_DEVICE (tpm_find ()); + + tpm_base =platform_bus_get_mmio_addr (pbus, sbdev,0 ); +assert (tpm_base !=-1 ); + + tpm_base += pbus_base; + + sbdev_mr =sysbus_mmio_get_region (sbdev,0 ); + +Aml *dev =aml_device ("TPM0" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +Aml *crs =aml_resource_template (); +aml_append (crs, +aml_memory32_fixed (tpm_base, + (uint32_t )memory_region_size (sbdev_mr), +AML_READ_WRITE )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (scope, dev); +} +static void build_iort (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms) {
hw/arm/virt-acpi-build.c build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 792
Quoted 4 lines
hw/arm/virt-acpi-build.c +1
-0@@ -758,6 +789,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) }acpi_dsdt_add_power_button (scope); +acpi_dsdt_add_tpm (scope, vms);
shouldn't be this guarded by check if TPM device is present?
perhaps pass found here tpm to acpi_dsdt_add_tpm() as an argument
Quoted 3 lines
hw/arm/virt-acpi-build.c +0
-0aml_append (dsdt, scope);
Re: [PATCH v3 4/4] arm/acpi: Add the TPM2.0 device under the DSDT
Hi Igor,
Quoted 77 lines · Igor Mammedov
Quoted 74 lines · On Mon, 1 Jun 2020 11:57:37 +0200 Eric Auger <[email protected]> wrote:
In case it is dynamically instantiated, add the TPM 2.0 device object under the DSDT table in the ACPI namespace. Its HID is MSFT0101 while its current resource settings (CRS) property is initialized with the guest physical address and MMIO size of the device.
Signed-off-by Eric Auger <[email protected]>Reviewed-by Stefan Berger <[email protected]>---
v2 -> v3:
- useSYS_BUS_DEVICE()instead of
(SysBusDevice *)object_dynamic_cast(OBJECT())v1 -> v2:
- usememory_region_size
- fix mingw compilation issue by casting touint32_t
- added Stefan's R-b--- hw/arm/virt-acpi-build.c | 32 ++++++++++++++++++++++++++++++++ 1 file changed, 32 insertions(+)hw/arm/virt-acpi-build.c +31
-0@@ -46,6 +46,7 @@#include "hw/pci/pci.h" #include "hw/arm/virt.h" #include "hw/mem/nvdimm.h" +#include "hw/platform-bus.h" #include "sysemu/numa.h" #include "sysemu/reset.h" #include "sysemu/tpm.h" @@ -364,6 +365,36 @@ static void acpi_dsdt_add_power_button(Aml *scope)aml_append (scope, dev); } +static void acpi_dsdt_add_tpm (Aml *scope,VirtMachineState *vms) +{ +hwaddr pbus_base = vms->memmap[VIRT_PLATFORM_BUS ].base; +PlatformBusDevice *pbus =PLATFORM_BUS_DEVICE (vms->platform_bus_dev); +MemoryRegion *sbdev_mr; +SysBusDevice *sbdev; +hwaddr tpm_base; + + sbdev =SYS_BUS_DEVICE (tpm_find ()); + + tpm_base =platform_bus_get_mmio_addr (pbus, sbdev,0 ); +assert (tpm_base !=-1 ); + + tpm_base += pbus_base; + + sbdev_mr =sysbus_mmio_get_region (sbdev,0 ); + +Aml *dev =aml_device ("TPM0" ); +aml_append (dev,aml_name_decl ("_HID" ,aml_string ("MSFT0101" ))); +aml_append (dev,aml_name_decl ("_UID" ,aml_int (0 ))); + +Aml *crs =aml_resource_template (); +aml_append (crs, +aml_memory32_fixed (tpm_base, + (uint32_t )memory_region_size (sbdev_mr), +AML_READ_WRITE )); +aml_append (dev,aml_name_decl ("_CRS" , crs)); +aml_append (scope, dev); +} +static void build_iort (GArray *table_data,BIOSLinker *linker,VirtMachineState *vms) {@@ -758,6 +789,7 @@ build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) }
Quoted 3 lines
hw/arm/virt-acpi-build.c build_dsdt(GArray *table_data, BIOSLinker *linker, VirtMachineState *vms) · line 792
Quoted 2 lines
hw/arm/virt-acpi-build.c +1
-0acpi_dsdt_add_power_button (scope); +acpi_dsdt_add_tpm (scope, vms);shouldn't be this guarded by check if TPM device is present?
Yes I should. the check was in v2 and was dropped in v3.
thanks
Eric
Quoted 7 lines
perhaps pass found here tpm to
acpi_dsdt_add_tpm()as an argumentQuoted 3 lines
hw/arm/virt-acpi-build.c +0
-0aml_append (dsdt, scope);