From a74918277790e9aef32eac64896c36ea68658ad8 Mon Sep 17 00:00:00 2001 From: Rob Bradford Date: Mon, 25 Jul 2022 13:55:24 +0100 Subject: [PATCH] vmm: acpi: Use ACPI platform device addresses from DeviceManager Remove the hardcoded addresses. Also remove PM_TMR_BLK as spec compliant implementation will use X_PM_TMR_BLK over this field. Signed-off-by: Rob Bradford --- acpi_tables/src/sdt.rs | 1 + vmm/src/acpi.rs | 50 +++++++++++++++++++++++++++--------------- 2 files changed, 33 insertions(+), 18 deletions(-) diff --git a/acpi_tables/src/sdt.rs b/acpi_tables/src/sdt.rs index a9e60a1da..1e80a4aee 100644 --- a/acpi_tables/src/sdt.rs +++ b/acpi_tables/src/sdt.rs @@ -4,6 +4,7 @@ // #[repr(packed)] +#[derive(Clone, Copy)] pub struct GenericAddress { pub address_space_id: u8, pub register_bit_width: u8, diff --git a/vmm/src/acpi.rs b/vmm/src/acpi.rs index 644e44f7f..a439ccb77 100644 --- a/vmm/src/acpi.rs +++ b/vmm/src/acpi.rs @@ -7,6 +7,7 @@ use crate::device_manager::DeviceManager; use crate::memory_manager::MemoryManager; use crate::pci_segment::PciSegment; use crate::{GuestMemoryMmap, GuestRegionMmap}; +#[cfg(target_arch = "aarch64")] use acpi_tables::sdt::GenericAddress; use acpi_tables::{aml::Aml, rsdp::Rsdp, sdt::Sdt}; #[cfg(target_arch = "aarch64")] @@ -14,7 +15,6 @@ use arch::aarch64::DeviceInfoForFdt; #[cfg(target_arch = "aarch64")] use arch::DeviceType; use arch::NumaNodes; - use bitflags::bitflags; use pci::PciBdf; use std::sync::{Arc, Mutex}; @@ -185,25 +185,39 @@ pub fn create_dsdt_table( dsdt } -fn create_facp_table(dsdt_offset: GuestAddress) -> Sdt { +fn create_facp_table(dsdt_offset: GuestAddress, device_manager: &Arc>) -> Sdt { // Revision 6 of the ACPI FADT table is 276 bytes long let mut facp = Sdt::new(*b"FACP", 276, 6, *b"CLOUDH", *b"CHFACP ", 1); - // x86_64 specific fields - #[cfg(target_arch = "x86_64")] { - // PM_TMR_BLK I/O port - facp.write(76, 0xb008u32); - // RESET_REG - facp.write(116, GenericAddress::io_port_address::(0x3c0)); - // RESET_VALUE - facp.write(128, 1u8); - // X_PM_TMR_BLK - facp.write(208, GenericAddress::io_port_address::(0xb008)); - // SLEEP_CONTROL_REG - facp.write(244, GenericAddress::io_port_address::(0x3c0)); - // SLEEP_STATUS_REG - facp.write(256, GenericAddress::io_port_address::(0x3c0)); + let device_manager = device_manager.lock().unwrap(); + if let Some(address) = device_manager.acpi_platform_addresses().reset_reg_address { + // RESET_REG + facp.write(116, address); + // RESET_VALUE + facp.write(128, 1u8); + } + + if let Some(address) = device_manager + .acpi_platform_addresses() + .sleep_control_reg_address + { + // SLEEP_CONTROL_REG + facp.write(244, address); + } + + if let Some(address) = device_manager + .acpi_platform_addresses() + .sleep_status_reg_address + { + // SLEEP_STATUS_REG + facp.write(256, address); + } + + if let Some(address) = device_manager.acpi_platform_addresses().pm_timer_address { + // X_PM_TMR_BLK + facp.write(208, address); + } } // aarch64 specific fields @@ -604,7 +618,7 @@ pub fn create_acpi_tables( .expect("Error writing DSDT table"); // FACP aka FADT - let facp = create_facp_table(dsdt_offset); + let facp = create_facp_table(dsdt_offset, device_manager); let facp_offset = dsdt_offset.checked_add(dsdt.len() as u64).unwrap(); guest_mem .write_slice(facp.as_slice(), facp_offset) @@ -792,7 +806,7 @@ pub fn create_acpi_tables_tdx( )]; // FACP aka FADT - tables.push(create_facp_table(GuestAddress(0))); + tables.push(create_facp_table(GuestAddress(0), device_manager)); // MADT tables.push(cpu_manager.lock().unwrap().create_madt());