vmm: Add required acpi entries for vtpm device

Add an TPM2 entry to DSDT ACPI table. Add a TPM2 table to guest's ACPI.

Signed-off-by: Praveen K Paladugu <prapal@linux.microsoft.com>
Co-authored-by: Sean Yoo <t-seanyoo@microsoft.com>
This commit is contained in:
Praveen K Paladugu
2022-08-12 20:28:04 +00:00
committed by Rob Bradford
parent 7122e2989c
commit af261f231c
3 changed files with 57 additions and 2 deletions
+25
View File
@@ -264,6 +264,18 @@ fn create_mcfg_table(pci_segments: &[PciSegment]) -> Sdt {
mcfg
}
fn create_tpm2_table() -> Sdt {
let mut tpm = Sdt::new(*b"TPM2", 52, 3, *b"CLOUDH", *b"CHTPM2 ", 1);
tpm.write(36, 0_u16); //Platform Class
tpm.write(38, 0_u16); // Reserved Space
tpm.write(40, 0xfed4_0040_u64); // Address of Control Area
tpm.write(48, 7_u32); //Start Method
tpm.update_checksum();
tpm
}
fn create_srat_table(numa_nodes: &NumaNodes) -> Sdt {
let mut srat = Sdt::new(*b"SRAT", 36, 3, *b"CLOUDH", *b"CHSRAT ", 1);
// SRAT reserved 12 bytes
@@ -609,6 +621,7 @@ pub fn create_acpi_tables(
cpu_manager: &Arc<Mutex<CpuManager>>,
memory_manager: &Arc<Mutex<MemoryManager>>,
numa_nodes: &NumaNodes,
tpm_enabled: bool,
) -> GuestAddress {
trace_scoped!("create_acpi_tables");
@@ -723,6 +736,18 @@ pub fn create_acpi_tables(
prev_tbl_off = dbg2_offset;
}
if tpm_enabled {
// TPM2 Table
let tpm2 = create_tpm2_table();
let tpm2_offset = prev_tbl_off.checked_add(prev_tbl_len).unwrap();
guest_mem
.write_slice(tpm2.as_slice(), tpm2_offset)
.expect("Error writing TPM2 table");
tables.push(tpm2_offset.0);
prev_tbl_len = tpm2.len() as u64;
prev_tbl_off = tpm2_offset;
}
// SRAT and SLIT
// Only created if the NUMA nodes list is not empty.
if !numa_nodes.is_empty() {