Skip to content

Commit e27e1e6

Browse files
eaugermstsirkin
authored andcommitted
acpi: Some build_tpm2() code reshape
Remove any reference to Acpi20TPM2 and adopt an implementation similar to build_ghes_v2(). Signed-off-by: Eric Auger <[email protected]> Suggested-by: Igor Mammedov <[email protected]> Reviewed-by: Stefan Berger <[email protected]> Tested-by: Stefan Berger <[email protected]> Reviewed-by: Igor Mammedov <[email protected]> Message-Id: <[email protected]> Tested-by: Ard Biesheuvel <[email protected]> Reviewed-by: Michael S. Tsirkin <[email protected]> Signed-off-by: Michael S. Tsirkin <[email protected]>
1 parent 93dd625 commit e27e1e6

File tree

2 files changed

+32
-37
lines changed

2 files changed

+32
-37
lines changed

hw/acpi/aml-build.c

Lines changed: 32 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1878,48 +1878,61 @@ void build_fadt(GArray *tbl, BIOSLinker *linker, const AcpiFadtData *f,
18781878
"FACP", tbl->len - fadt_start, f->rev, oem_id, oem_table_id);
18791879
}
18801880

1881+
/*
1882+
* build_tpm2 - Build the TPM2 table as specified in
1883+
* table 7: TCG Hardware Interface Description Table Format for TPM 2.0
1884+
* of TCG ACPI Specification, Family “1.2” and “2.0”, Version 1.2, Rev 8
1885+
*/
18811886
void build_tpm2(GArray *table_data, BIOSLinker *linker, GArray *tcpalog)
18821887
{
1883-
Acpi20TPM2 *tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
1884-
unsigned log_addr_size = sizeof(tpm2_ptr->log_area_start_address);
1885-
unsigned log_addr_offset =
1886-
(char *)&tpm2_ptr->log_area_start_address - table_data->data;
18871888
uint8_t start_method_params[12] = {};
1889+
unsigned log_addr_offset, tpm2_start;
1890+
uint64_t control_area_start_address;
18881891
TPMIf *tpmif = tpm_find();
1892+
uint32_t start_method;
1893+
void *tpm2_ptr;
1894+
1895+
tpm2_start = table_data->len;
1896+
tpm2_ptr = acpi_data_push(table_data, sizeof(AcpiTableHeader));
18891897

1890-
/* platform class */
1898+
/* Platform Class */
18911899
build_append_int_noprefix(table_data, TPM2_ACPI_CLASS_CLIENT, 2);
1892-
/* reserved */
1900+
/* Reserved */
18931901
build_append_int_noprefix(table_data, 0, 2);
18941902
if (TPM_IS_TIS_ISA(tpmif) || TPM_IS_TIS_SYSBUS(tpmif)) {
1895-
/* address of control area */
1896-
build_append_int_noprefix(table_data, 0, 8);
1897-
/* start method */
1898-
build_append_int_noprefix(table_data, TPM2_START_METHOD_MMIO, 4);
1903+
control_area_start_address = 0;
1904+
start_method = TPM2_START_METHOD_MMIO;
18991905
} else if (TPM_IS_CRB(tpmif)) {
1900-
build_append_int_noprefix(table_data, TPM_CRB_ADDR_CTRL, 8);
1901-
build_append_int_noprefix(table_data, TPM2_START_METHOD_CRB, 4);
1906+
control_area_start_address = TPM_CRB_ADDR_CTRL;
1907+
start_method = TPM2_START_METHOD_CRB;
19021908
} else {
1903-
g_warn_if_reached();
1909+
g_assert_not_reached();
19041910
}
1911+
/* Address of Control Area */
1912+
build_append_int_noprefix(table_data, control_area_start_address, 8);
1913+
/* Start Method */
1914+
build_append_int_noprefix(table_data, start_method, 4);
19051915

1906-
/* platform specific parameters */
1907-
g_array_append_vals(table_data, &start_method_params, 12);
1916+
/* Platform Specific Parameters */
1917+
g_array_append_vals(table_data, &start_method_params,
1918+
ARRAY_SIZE(start_method_params));
19081919

1909-
/* log area minimum length */
1920+
/* Log Area Minimum Length */
19101921
build_append_int_noprefix(table_data, TPM_LOG_AREA_MINIMUM_SIZE, 4);
19111922

19121923
acpi_data_push(tcpalog, TPM_LOG_AREA_MINIMUM_SIZE);
19131924
bios_linker_loader_alloc(linker, ACPI_BUILD_TPMLOG_FILE, tcpalog, 1,
19141925
false);
19151926

1916-
/* log area start address to be filled by Guest linker */
1927+
log_addr_offset = table_data->len;
1928+
1929+
/* Log Area Start Address to be filled by Guest linker */
19171930
build_append_int_noprefix(table_data, 0, 8);
19181931
bios_linker_loader_add_pointer(linker, ACPI_BUILD_TABLE_FILE,
1919-
log_addr_offset, log_addr_size,
1932+
log_addr_offset, 8,
19201933
ACPI_BUILD_TPMLOG_FILE, 0);
19211934
build_header(linker, table_data,
1922-
(void *)tpm2_ptr, "TPM2", sizeof(*tpm2_ptr), 4, NULL, NULL);
1935+
tpm2_ptr, "TPM2", table_data->len - tpm2_start, 4, NULL, NULL);
19231936
}
19241937

19251938
/* ACPI 5.0: 6.4.3.8.2 Serial Bus Connection Descriptors */

include/hw/acpi/acpi-defs.h

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -465,24 +465,6 @@ struct Acpi20Tcpa {
465465
} QEMU_PACKED;
466466
typedef struct Acpi20Tcpa Acpi20Tcpa;
467467

468-
/*
469-
* TPM2
470-
*
471-
* Following Version 1.2, Revision 8 of specs:
472-
* https://trustedcomputinggroup.org/tcg-acpi-specification/
473-
*/
474-
struct Acpi20TPM2 {
475-
ACPI_TABLE_HEADER_DEF
476-
uint16_t platform_class;
477-
uint16_t reserved;
478-
uint64_t control_area_address;
479-
uint32_t start_method;
480-
uint8_t start_method_params[12];
481-
uint32_t log_area_minimum_length;
482-
uint64_t log_area_start_address;
483-
} QEMU_PACKED;
484-
typedef struct Acpi20TPM2 Acpi20TPM2;
485-
486468
/* DMAR - DMA Remapping table r2.2 */
487469
struct AcpiTableDmar {
488470
ACPI_TABLE_HEADER_DEF

0 commit comments

Comments
 (0)