vm-allocator: Introduce RISC-V architecture

Provide implementation for GSI allocator to work on riscv64
architecture, and doc comment for riscv64 as well.

Signed-off-by: Ruoqing He <heruoqing@iscas.ac.cn>
This commit is contained in:
Ruoqing He 2024-12-04 16:23:15 +08:00 committed by Rob Bradford
parent 1e602bd9a6
commit 5b715f483d
2 changed files with 9 additions and 5 deletions

View File

@ -62,7 +62,7 @@ impl GsiAllocator {
allocator
}
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
/// New GSI allocator
pub fn new() -> Self {
GsiAllocator {
@ -97,7 +97,7 @@ impl GsiAllocator {
Ok(irq)
}
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
/// Allocate an IRQ
pub fn allocate_irq(&mut self) -> Result<u32> {
let irq = self.next_irq;
@ -106,7 +106,7 @@ impl GsiAllocator {
}
}
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
impl Default for GsiAllocator {
fn default() -> Self {
GsiAllocator::new()

View File

@ -22,7 +22,7 @@ use crate::page_size::get_page_size;
/// ```
/// # #[cfg(target_arch = "x86_64")]
/// # use vm_allocator::{GsiApic, SystemAllocator};
/// # #[cfg(target_arch = "aarch64")]
/// # #[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
/// # use vm_allocator::SystemAllocator;
/// # use vm_memory::{Address, GuestAddress, GuestUsize};
/// let mut allocator = SystemAllocator::new(
@ -34,10 +34,14 @@ use crate::page_size::get_page_size;
/// assert_eq!(allocator.allocate_irq(), Some(5));
/// #[cfg(target_arch = "aarch64")]
/// assert_eq!(allocator.allocate_irq(), Some(32));
/// #[cfg(target_arch = "riscv64")]
/// assert_eq!(allocator.allocate_irq(), Some(0));
/// #[cfg(target_arch = "x86_64")]
/// assert_eq!(allocator.allocate_irq(), Some(6));
/// #[cfg(target_arch = "aarch64")]
/// assert_eq!(allocator.allocate_irq(), Some(33));
/// #[cfg(target_arch = "riscv64")]
/// assert_eq!(allocator.allocate_irq(), Some(1));
/// assert_eq!(allocator.allocate_platform_mmio_addresses(None, 0x1000, Some(0x1000)), Some(GuestAddress(0x1fff_f000)));
///
/// ```
@ -74,7 +78,7 @@ impl SystemAllocator {
)?,
#[cfg(target_arch = "x86_64")]
gsi_allocator: GsiAllocator::new(apics),
#[cfg(target_arch = "aarch64")]
#[cfg(any(target_arch = "aarch64", target_arch = "riscv64"))]
gsi_allocator: GsiAllocator::new(),
})
}