mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-04 04:25:45 +00:00
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:
parent
1268165040
commit
af7cd74e04
@ -28,7 +28,7 @@ fn pagesize() -> usize {
|
|||||||
/// # use vm_allocator::SystemAllocator;
|
/// # use vm_allocator::SystemAllocator;
|
||||||
/// # use vm_memory::{Address, GuestAddress, GuestUsize};
|
/// # use vm_memory::{Address, GuestAddress, GuestUsize};
|
||||||
/// let mut allocator = SystemAllocator::new(
|
/// let mut allocator = SystemAllocator::new(
|
||||||
/// Some(GuestAddress(0x1000)), Some(0x10000),
|
/// GuestAddress(0x1000), 0x10000,
|
||||||
/// GuestAddress(0x10000000), 0x10000000,
|
/// GuestAddress(0x10000000), 0x10000000,
|
||||||
/// 5).unwrap();
|
/// 5).unwrap();
|
||||||
/// assert_eq!(allocator.allocate_irq(), Some(5));
|
/// assert_eq!(allocator.allocate_irq(), Some(5));
|
||||||
@ -37,7 +37,7 @@ fn pagesize() -> usize {
|
|||||||
///
|
///
|
||||||
/// ```
|
/// ```
|
||||||
pub struct SystemAllocator {
|
pub struct SystemAllocator {
|
||||||
io_address_space: Option<AddressAllocator>,
|
io_address_space: AddressAllocator,
|
||||||
mmio_address_space: AddressAllocator,
|
mmio_address_space: AddressAllocator,
|
||||||
next_irq: u32,
|
next_irq: u32,
|
||||||
}
|
}
|
||||||
@ -53,19 +53,15 @@ impl SystemAllocator {
|
|||||||
/// * `mmio_size` - The size of MMIO memory.
|
/// * `mmio_size` - The size of MMIO memory.
|
||||||
/// * `first_irq` - The first irq number to give out.
|
/// * `first_irq` - The first irq number to give out.
|
||||||
pub fn new(
|
pub fn new(
|
||||||
io_base: Option<GuestAddress>,
|
io_base: GuestAddress,
|
||||||
io_size: Option<GuestUsize>,
|
io_size: GuestUsize,
|
||||||
mmio_base: GuestAddress,
|
mmio_base: GuestAddress,
|
||||||
mmio_size: GuestUsize,
|
mmio_size: GuestUsize,
|
||||||
first_irq: u32,
|
first_irq: u32,
|
||||||
) -> Option<Self> {
|
) -> Option<Self> {
|
||||||
let page_size = pagesize() as u64;
|
let page_size = pagesize() as u64;
|
||||||
Some(SystemAllocator {
|
Some(SystemAllocator {
|
||||||
io_address_space: if let (Some(b), Some(s)) = (io_base, io_size) {
|
io_address_space: AddressAllocator::new(io_base, io_size, Some(0x1))?,
|
||||||
Some(AddressAllocator::new(b, s, Some(0x1))?)
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
},
|
|
||||||
mmio_address_space: AddressAllocator::new(mmio_base, mmio_size, Some(page_size))?,
|
mmio_address_space: AddressAllocator::new(mmio_base, mmio_size, Some(page_size))?,
|
||||||
next_irq: first_irq,
|
next_irq: first_irq,
|
||||||
})
|
})
|
||||||
@ -84,12 +80,10 @@ impl SystemAllocator {
|
|||||||
/// 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,
|
||||||
address: GuestAddress,
|
address: Option<GuestAddress>,
|
||||||
size: GuestUsize,
|
size: GuestUsize,
|
||||||
) -> Option<GuestAddress> {
|
) -> Option<GuestAddress> {
|
||||||
self.io_address_space
|
self.io_address_space.allocate(address, size)
|
||||||
.as_mut()?
|
|
||||||
.allocate(Some(address), size)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Reserves a section of `size` bytes of MMIO address space.
|
/// Reserves a section of `size` bytes of MMIO address space.
|
||||||
@ -104,9 +98,7 @@ impl SystemAllocator {
|
|||||||
/// 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) {
|
||||||
if let Some(io_address) = self.io_address_space.as_mut() {
|
self.io_address_space.free(address, size)
|
||||||
io_address.free(address, size)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Free an MMIO address range.
|
/// Free an MMIO address range.
|
||||||
|
@ -1068,8 +1068,8 @@ impl<'a> Vm<'a> {
|
|||||||
|
|
||||||
// Let's allocate 64 GiB of addressable MMIO space, starting at 0.
|
// Let's allocate 64 GiB of addressable MMIO space, starting at 0.
|
||||||
let mut allocator = SystemAllocator::new(
|
let mut allocator = SystemAllocator::new(
|
||||||
None,
|
GuestAddress(0),
|
||||||
None,
|
1 << 16 as GuestUsize,
|
||||||
GuestAddress(0),
|
GuestAddress(0),
|
||||||
1 << 36 as GuestUsize,
|
1 << 36 as GuestUsize,
|
||||||
X86_64_IRQ_BASE,
|
X86_64_IRQ_BASE,
|
||||||
|
Loading…
Reference in New Issue
Block a user