mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-07-04 17:02:36 +00:00
vmm: acpi: Move MemoryManager ACPI device to an MMIO address
Migrate the MemoryManager from a fixed I/O port address to an allocated MMIO address. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
28ab6cea0e
commit
6006068951
|
@ -18,6 +18,8 @@ use crate::interrupt::kvm::KvmMsiInterruptManager as MsiInterruptManager;
|
||||||
#[cfg(feature = "mshv")]
|
#[cfg(feature = "mshv")]
|
||||||
use crate::interrupt::mshv::MshvMsiInterruptManager as MsiInterruptManager;
|
use crate::interrupt::mshv::MshvMsiInterruptManager as MsiInterruptManager;
|
||||||
use crate::interrupt::LegacyUserspaceInterruptManager;
|
use crate::interrupt::LegacyUserspaceInterruptManager;
|
||||||
|
#[cfg(feature = "acpi")]
|
||||||
|
use crate::memory_manager::MEMORY_MANAGER_ACPI_SIZE;
|
||||||
use crate::memory_manager::{Error as MemoryManagerError, MemoryManager};
|
use crate::memory_manager::{Error as MemoryManagerError, MemoryManager};
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
use crate::vm::NumaNodes;
|
use crate::vm::NumaNodes;
|
||||||
|
@ -897,22 +899,17 @@ impl DeviceManager {
|
||||||
)));
|
)));
|
||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
self.address_manager
|
{
|
||||||
.allocator
|
let memory_manager_acpi_address = self.memory_manager.lock().unwrap().acpi_address;
|
||||||
.lock()
|
self.address_manager
|
||||||
.unwrap()
|
.mmio_bus
|
||||||
.allocate_io_addresses(Some(GuestAddress(0x0a00)), 0x18, None)
|
.insert(
|
||||||
.ok_or(DeviceManagerError::AllocateIOPort)?;
|
Arc::clone(&self.memory_manager) as Arc<Mutex<dyn BusDevice>>,
|
||||||
|
memory_manager_acpi_address.0,
|
||||||
#[cfg(feature = "acpi")]
|
MEMORY_MANAGER_ACPI_SIZE as u64,
|
||||||
self.address_manager
|
)
|
||||||
.io_bus
|
.map_err(DeviceManagerError::BusError)?;
|
||||||
.insert(
|
}
|
||||||
Arc::clone(&self.memory_manager) as Arc<Mutex<dyn BusDevice>>,
|
|
||||||
0xa00,
|
|
||||||
0x18,
|
|
||||||
)
|
|
||||||
.map_err(DeviceManagerError::BusError)?;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
self.add_legacy_devices(
|
self.add_legacy_devices(
|
||||||
|
|
|
@ -44,6 +44,9 @@ use vm_migration::{
|
||||||
Transportable,
|
Transportable,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#[cfg(feature = "acpi")]
|
||||||
|
pub const MEMORY_MANAGER_ACPI_SIZE: usize = 0x18;
|
||||||
|
|
||||||
const DEFAULT_MEMORY_ZONE: &str = "mem0";
|
const DEFAULT_MEMORY_ZONE: &str = "mem0";
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
|
@ -134,6 +137,9 @@ pub struct MemoryManager {
|
||||||
// This is useful for getting the dirty pages as we need to know the
|
// This is useful for getting the dirty pages as we need to know the
|
||||||
// slots that the mapping is created in.
|
// slots that the mapping is created in.
|
||||||
guest_ram_mappings: Vec<GuestRamMapping>,
|
guest_ram_mappings: Vec<GuestRamMapping>,
|
||||||
|
|
||||||
|
#[cfg(feature = "acpi")]
|
||||||
|
pub acpi_address: GuestAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -253,6 +259,9 @@ pub enum Error {
|
||||||
|
|
||||||
// Error copying snapshot into region
|
// Error copying snapshot into region
|
||||||
SnapshotCopy(GuestMemoryError),
|
SnapshotCopy(GuestMemoryError),
|
||||||
|
|
||||||
|
/// Failed to allocate MMIO address
|
||||||
|
AllocateMMIOAddress,
|
||||||
}
|
}
|
||||||
|
|
||||||
const ENABLE_FLAG: usize = 0;
|
const ENABLE_FLAG: usize = 0;
|
||||||
|
@ -294,6 +303,8 @@ impl BusDevice for MemoryManager {
|
||||||
data.copy_from_slice(&state.length.to_le_bytes()[4..]);
|
data.copy_from_slice(&state.length.to_le_bytes()[4..]);
|
||||||
}
|
}
|
||||||
STATUS_OFFSET => {
|
STATUS_OFFSET => {
|
||||||
|
// The Linux kernel, quite reasonably, doesn't zero the memory it gives us.
|
||||||
|
data.copy_from_slice(&[0; 8][0..data.len()]);
|
||||||
if state.active {
|
if state.active {
|
||||||
data[0] |= 1 << ENABLE_FLAG;
|
data[0] |= 1 << ENABLE_FLAG;
|
||||||
}
|
}
|
||||||
|
@ -714,6 +725,13 @@ impl MemoryManager {
|
||||||
.ok_or(Error::CreateSystemAllocator)?,
|
.ok_or(Error::CreateSystemAllocator)?,
|
||||||
));
|
));
|
||||||
|
|
||||||
|
#[cfg(feature = "acpi")]
|
||||||
|
let acpi_address = allocator
|
||||||
|
.lock()
|
||||||
|
.unwrap()
|
||||||
|
.allocate_mmio_addresses(None, MEMORY_MANAGER_ACPI_SIZE as u64, None)
|
||||||
|
.ok_or(Error::AllocateMMIOAddress)?;
|
||||||
|
|
||||||
let memory_manager = Arc::new(Mutex::new(MemoryManager {
|
let memory_manager = Arc::new(Mutex::new(MemoryManager {
|
||||||
boot_guest_memory,
|
boot_guest_memory,
|
||||||
guest_memory: guest_memory.clone(),
|
guest_memory: guest_memory.clone(),
|
||||||
|
@ -738,6 +756,8 @@ impl MemoryManager {
|
||||||
snapshot_memory_regions: Vec::new(),
|
snapshot_memory_regions: Vec::new(),
|
||||||
memory_zones,
|
memory_zones,
|
||||||
guest_ram_mappings: Vec::new(),
|
guest_ram_mappings: Vec::new(),
|
||||||
|
#[cfg(feature = "acpi")]
|
||||||
|
acpi_address,
|
||||||
}));
|
}));
|
||||||
|
|
||||||
guest_memory.memory().with_regions(|_, region| {
|
guest_memory.memory().with_regions(|_, region| {
|
||||||
|
@ -1763,15 +1783,22 @@ impl Aml for MemoryManager {
|
||||||
&aml::Name::new("_UID".into(), &"Memory Hotplug Controller"),
|
&aml::Name::new("_UID".into(), &"Memory Hotplug Controller"),
|
||||||
// Mutex to protect concurrent access as we write to choose slot and then read back status
|
// Mutex to protect concurrent access as we write to choose slot and then read back status
|
||||||
&aml::Mutex::new("MLCK".into(), 0),
|
&aml::Mutex::new("MLCK".into(), 0),
|
||||||
// I/O port for memory controller
|
|
||||||
&aml::Name::new(
|
&aml::Name::new(
|
||||||
"_CRS".into(),
|
"_CRS".into(),
|
||||||
&aml::ResourceTemplate::new(vec![&aml::IO::new(
|
&aml::ResourceTemplate::new(vec![&aml::AddressSpace::new_memory(
|
||||||
0x0a00, 0x0a00, 0x01, 0x18,
|
aml::AddressSpaceCachable::NotCacheable,
|
||||||
|
true,
|
||||||
|
self.acpi_address.0 as u64,
|
||||||
|
self.acpi_address.0 + MEMORY_MANAGER_ACPI_SIZE as u64 - 1,
|
||||||
)]),
|
)]),
|
||||||
),
|
),
|
||||||
// OpRegion and Fields map I/O port into individual field values
|
// OpRegion and Fields map MMIO range into individual field values
|
||||||
&aml::OpRegion::new("MHPR".into(), aml::OpRegionSpace::SystemIO, 0xa00, 0x18),
|
&aml::OpRegion::new(
|
||||||
|
"MHPR".into(),
|
||||||
|
aml::OpRegionSpace::SystemMemory,
|
||||||
|
self.acpi_address.0 as usize,
|
||||||
|
MEMORY_MANAGER_ACPI_SIZE,
|
||||||
|
),
|
||||||
&aml::Field::new(
|
&aml::Field::new(
|
||||||
"MHPR".into(),
|
"MHPR".into(),
|
||||||
aml::FieldAccessType::DWord,
|
aml::FieldAccessType::DWord,
|
||||||
|
|
Loading…
Reference in New Issue
Block a user