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 <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-07-25 13:55:24 +01:00
parent 2e8eb96ef6
commit a749182777
2 changed files with 33 additions and 18 deletions

View File

@ -4,6 +4,7 @@
// //
#[repr(packed)] #[repr(packed)]
#[derive(Clone, Copy)]
pub struct GenericAddress { pub struct GenericAddress {
pub address_space_id: u8, pub address_space_id: u8,
pub register_bit_width: u8, pub register_bit_width: u8,

View File

@ -7,6 +7,7 @@ use crate::device_manager::DeviceManager;
use crate::memory_manager::MemoryManager; use crate::memory_manager::MemoryManager;
use crate::pci_segment::PciSegment; use crate::pci_segment::PciSegment;
use crate::{GuestMemoryMmap, GuestRegionMmap}; use crate::{GuestMemoryMmap, GuestRegionMmap};
#[cfg(target_arch = "aarch64")]
use acpi_tables::sdt::GenericAddress; use acpi_tables::sdt::GenericAddress;
use acpi_tables::{aml::Aml, rsdp::Rsdp, sdt::Sdt}; use acpi_tables::{aml::Aml, rsdp::Rsdp, sdt::Sdt};
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
@ -14,7 +15,6 @@ use arch::aarch64::DeviceInfoForFdt;
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
use arch::DeviceType; use arch::DeviceType;
use arch::NumaNodes; use arch::NumaNodes;
use bitflags::bitflags; use bitflags::bitflags;
use pci::PciBdf; use pci::PciBdf;
use std::sync::{Arc, Mutex}; use std::sync::{Arc, Mutex};
@ -185,25 +185,39 @@ pub fn create_dsdt_table(
dsdt dsdt
} }
fn create_facp_table(dsdt_offset: GuestAddress) -> Sdt { fn create_facp_table(dsdt_offset: GuestAddress, device_manager: &Arc<Mutex<DeviceManager>>) -> Sdt {
// Revision 6 of the ACPI FADT table is 276 bytes long // 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); 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 let device_manager = device_manager.lock().unwrap();
facp.write(76, 0xb008u32); if let Some(address) = device_manager.acpi_platform_addresses().reset_reg_address {
// RESET_REG // RESET_REG
facp.write(116, GenericAddress::io_port_address::<u8>(0x3c0)); facp.write(116, address);
// RESET_VALUE // RESET_VALUE
facp.write(128, 1u8); facp.write(128, 1u8);
// X_PM_TMR_BLK }
facp.write(208, GenericAddress::io_port_address::<u32>(0xb008));
if let Some(address) = device_manager
.acpi_platform_addresses()
.sleep_control_reg_address
{
// SLEEP_CONTROL_REG // SLEEP_CONTROL_REG
facp.write(244, GenericAddress::io_port_address::<u8>(0x3c0)); facp.write(244, address);
}
if let Some(address) = device_manager
.acpi_platform_addresses()
.sleep_status_reg_address
{
// SLEEP_STATUS_REG // SLEEP_STATUS_REG
facp.write(256, GenericAddress::io_port_address::<u8>(0x3c0)); 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 // aarch64 specific fields
@ -604,7 +618,7 @@ pub fn create_acpi_tables(
.expect("Error writing DSDT table"); .expect("Error writing DSDT table");
// FACP aka FADT // 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(); let facp_offset = dsdt_offset.checked_add(dsdt.len() as u64).unwrap();
guest_mem guest_mem
.write_slice(facp.as_slice(), facp_offset) .write_slice(facp.as_slice(), facp_offset)
@ -792,7 +806,7 @@ pub fn create_acpi_tables_tdx(
)]; )];
// FACP aka FADT // FACP aka FADT
tables.push(create_facp_table(GuestAddress(0))); tables.push(create_facp_table(GuestAddress(0), device_manager));
// MADT // MADT
tables.push(cpu_manager.lock().unwrap().create_madt()); tables.push(cpu_manager.lock().unwrap().create_madt());