vmm: Enable memory manager for AArch64

Screened IO space as it is not available on AArch64.

Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
Michael Zhao 2020-06-09 14:54:15 +08:00 committed by Rob Bradford
parent eeeb45bbb9
commit b5f1c912d6
3 changed files with 15 additions and 6 deletions

View File

@ -41,6 +41,7 @@ fn pagesize() -> usize {
/// ///
/// ``` /// ```
pub struct SystemAllocator { pub struct SystemAllocator {
#[cfg(target_arch = "x86_64")]
io_address_space: AddressAllocator, io_address_space: AddressAllocator,
mmio_address_space: AddressAllocator, mmio_address_space: AddressAllocator,
mmio_hole_address_space: AddressAllocator, mmio_hole_address_space: AddressAllocator,
@ -51,8 +52,8 @@ impl SystemAllocator {
/// Creates a new `SystemAllocator` for managing addresses and irq numvers. /// Creates a new `SystemAllocator` for managing addresses and irq numvers.
/// Can return `None` if `base` + `size` overflows a u64 /// Can return `None` if `base` + `size` overflows a u64
/// ///
/// * `io_base` - The starting address of IO memory. /// * `io_base` - (X86) The starting address of IO memory.
/// * `io_size` - The size of IO memory. /// * `io_size` - (X86) The size of IO memory.
/// * `mmio_base` - The starting address of MMIO memory. /// * `mmio_base` - The starting address of MMIO memory.
/// * `mmio_size` - The size of MMIO memory. /// * `mmio_size` - The size of MMIO memory.
/// * `mmio_hole_base` - The starting address of MMIO memory in 32-bit address space. /// * `mmio_hole_base` - The starting address of MMIO memory in 32-bit address space.
@ -60,8 +61,8 @@ impl SystemAllocator {
/// * `apics` - (X86) Vector of APIC's. /// * `apics` - (X86) Vector of APIC's.
/// ///
pub fn new( pub fn new(
io_base: GuestAddress, #[cfg(target_arch = "x86_64")] io_base: GuestAddress,
io_size: GuestUsize, #[cfg(target_arch = "x86_64")] io_size: GuestUsize,
mmio_base: GuestAddress, mmio_base: GuestAddress,
mmio_size: GuestUsize, mmio_size: GuestUsize,
mmio_hole_base: GuestAddress, mmio_hole_base: GuestAddress,
@ -69,6 +70,7 @@ impl SystemAllocator {
#[cfg(target_arch = "x86_64")] apics: Vec<GsiApic>, #[cfg(target_arch = "x86_64")] apics: Vec<GsiApic>,
) -> Option<Self> { ) -> Option<Self> {
Some(SystemAllocator { Some(SystemAllocator {
#[cfg(target_arch = "x86_64")]
io_address_space: AddressAllocator::new(io_base, io_size)?, io_address_space: AddressAllocator::new(io_base, io_size)?,
mmio_address_space: AddressAllocator::new(mmio_base, mmio_size)?, mmio_address_space: AddressAllocator::new(mmio_base, mmio_size)?,
mmio_hole_address_space: AddressAllocator::new(mmio_hole_base, mmio_hole_size)?, mmio_hole_address_space: AddressAllocator::new(mmio_hole_base, mmio_hole_size)?,
@ -89,6 +91,7 @@ impl SystemAllocator {
self.gsi_allocator.allocate_gsi().ok() self.gsi_allocator.allocate_gsi().ok()
} }
#[cfg(target_arch = "x86_64")]
/// Reserves a section of `size` bytes of IO address space. /// Reserves a section of `size` bytes of IO address space.
pub fn allocate_io_addresses( pub fn allocate_io_addresses(
&mut self, &mut self,
@ -128,6 +131,7 @@ impl SystemAllocator {
) )
} }
#[cfg(target_arch = "x86_64")]
/// Free an IO address range. /// Free an IO address range.
/// We can only free a range if it matches exactly an already allocated range. /// We can only free a range if it matches exactly an already allocated range.
pub fn free_io_addresses(&mut self, address: GuestAddress, size: GuestUsize) { pub fn free_io_addresses(&mut self, address: GuestAddress, size: GuestUsize) {

View File

@ -37,7 +37,9 @@ use std::os::unix::thread::JoinHandleExt;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier, Mutex}; use std::sync::{Arc, Barrier, Mutex};
use std::{cmp, io, result, thread}; use std::{cmp, io, result, thread};
use vm_memory::{GuestAddress, GuestMemoryAtomic, GuestMemoryMmap}; #[cfg(target_arch = "x86_64")]
use vm_memory::GuestAddress;
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
use vm_migration::{ use vm_migration::{
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable, Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
Transportable, Transportable,
@ -675,6 +677,7 @@ impl CpuManager {
vcpus: Vec::with_capacity(usize::from(config.max_vcpus)), vcpus: Vec::with_capacity(usize::from(config.max_vcpus)),
})); }));
#[cfg(target_arch = "x86_64")]
device_manager device_manager
.allocator() .allocator()
.lock() .lock()

View File

@ -302,8 +302,10 @@ impl MemoryManager {
// Both MMIO and PIO address spaces start at address 0. // Both MMIO and PIO address spaces start at address 0.
let allocator = Arc::new(Mutex::new( let allocator = Arc::new(Mutex::new(
SystemAllocator::new( SystemAllocator::new(
#[cfg(target_arch = "x86_64")]
GuestAddress(0), GuestAddress(0),
1 << 16 as GuestUsize, #[cfg(target_arch = "x86_64")]
(1 << 16 as GuestUsize),
GuestAddress(0), GuestAddress(0),
mmio_address_space_size(), mmio_address_space_size(),
layout::MEM_32BIT_DEVICES_START, layout::MEM_32BIT_DEVICES_START,