vm-allocator: Make port IO non optional

This is only for allocating the port IO address range.
If a platform does not have PIO devices at all, the address
range will simply be unused.
So, simplify the vm-allocator data structure by making both
MMIO and PIO mandatory.

Signed-off-by: Chao Peng <chao.p.peng@linux.intel.com>
This commit is contained in:
Chao Peng 2019-06-26 16:02:00 +00:00 committed by Sebastien Boeuf
parent 1268165040
commit af7cd74e04
2 changed files with 10 additions and 18 deletions

View File

@ -28,7 +28,7 @@ fn pagesize() -> usize {
/// # use vm_allocator::SystemAllocator;
/// # use vm_memory::{Address, GuestAddress, GuestUsize};
/// let mut allocator = SystemAllocator::new(
/// Some(GuestAddress(0x1000)), Some(0x10000),
/// GuestAddress(0x1000), 0x10000,
/// GuestAddress(0x10000000), 0x10000000,
/// 5).unwrap();
/// assert_eq!(allocator.allocate_irq(), Some(5));
@ -37,7 +37,7 @@ fn pagesize() -> usize {
///
/// ```
pub struct SystemAllocator {
io_address_space: Option<AddressAllocator>,
io_address_space: AddressAllocator,
mmio_address_space: AddressAllocator,
next_irq: u32,
}
@ -53,19 +53,15 @@ impl SystemAllocator {
/// * `mmio_size` - The size of MMIO memory.
/// * `first_irq` - The first irq number to give out.
pub fn new(
io_base: Option<GuestAddress>,
io_size: Option<GuestUsize>,
io_base: GuestAddress,
io_size: GuestUsize,
mmio_base: GuestAddress,
mmio_size: GuestUsize,
first_irq: u32,
) -> Option<Self> {
let page_size = pagesize() as u64;
Some(SystemAllocator {
io_address_space: if let (Some(b), Some(s)) = (io_base, io_size) {
Some(AddressAllocator::new(b, s, Some(0x1))?)
} else {
None
},
io_address_space: AddressAllocator::new(io_base, io_size, Some(0x1))?,
mmio_address_space: AddressAllocator::new(mmio_base, mmio_size, Some(page_size))?,
next_irq: first_irq,
})
@ -84,12 +80,10 @@ impl SystemAllocator {
/// Reserves a section of `size` bytes of IO address space.
pub fn allocate_io_addresses(
&mut self,
address: GuestAddress,
address: Option<GuestAddress>,
size: GuestUsize,
) -> Option<GuestAddress> {
self.io_address_space
.as_mut()?
.allocate(Some(address), size)
self.io_address_space.allocate(address, size)
}
/// Reserves a section of `size` bytes of MMIO address space.
@ -104,9 +98,7 @@ impl SystemAllocator {
/// Free an IO address 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) {
if let Some(io_address) = self.io_address_space.as_mut() {
io_address.free(address, size)
}
self.io_address_space.free(address, size)
}
/// Free an MMIO address range.

View File

@ -1068,8 +1068,8 @@ impl<'a> Vm<'a> {
// Let's allocate 64 GiB of addressable MMIO space, starting at 0.
let mut allocator = SystemAllocator::new(
None,
None,
GuestAddress(0),
1 << 16 as GuestUsize,
GuestAddress(0),
1 << 36 as GuestUsize,
X86_64_IRQ_BASE,