mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vm-allocator: Enable vm-allocator for AArch64
Implemented GSI allocator and system allocator for AArch64. Renamed some layout definitions to align more code between architectures. Signed-off-by: Michael Zhao <michael.zhao@arm.com>
This commit is contained in:
committed by
Rob Bradford
parent
5343b0ac18
commit
e9488846f1
@@ -2,6 +2,9 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
use arch;
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
use std::collections::btree_map::BTreeMap;
|
||||
use std::result;
|
||||
|
||||
@@ -13,12 +16,14 @@ pub enum Error {
|
||||
pub type Result<T> = result::Result<T, Error>;
|
||||
|
||||
/// GsiApic
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
#[derive(Copy, Clone)]
|
||||
pub struct GsiApic {
|
||||
base: u32,
|
||||
irqs: u32,
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
impl GsiApic {
|
||||
/// New GSI APIC
|
||||
pub fn new(base: u32, irqs: u32) -> Self {
|
||||
@@ -28,12 +33,14 @@ impl GsiApic {
|
||||
|
||||
/// GsiAllocator
|
||||
pub struct GsiAllocator {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
apics: BTreeMap<u32, u32>,
|
||||
next_irq: u32,
|
||||
next_gsi: u32,
|
||||
}
|
||||
|
||||
impl GsiAllocator {
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
/// New GSI allocator
|
||||
pub fn new(apics: Vec<GsiApic>) -> Self {
|
||||
let mut allocator = GsiAllocator {
|
||||
@@ -57,13 +64,23 @@ impl GsiAllocator {
|
||||
allocator
|
||||
}
|
||||
|
||||
/// Allocate a GSI
|
||||
pub fn allocate_gsi(&mut self) -> Result<u32> {
|
||||
self.next_gsi = self.next_gsi.checked_add(1).ok_or(Error::Overflow)?;
|
||||
|
||||
Ok(self.next_gsi - 1)
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
/// New GSI allocator
|
||||
pub fn new() -> Self {
|
||||
GsiAllocator {
|
||||
next_irq: arch::IRQ_BASE,
|
||||
next_gsi: arch::IRQ_BASE,
|
||||
}
|
||||
}
|
||||
|
||||
/// Allocate a GSI
|
||||
pub fn allocate_gsi(&mut self) -> Result<u32> {
|
||||
let gsi = self.next_gsi;
|
||||
self.next_gsi = self.next_gsi.checked_add(1).ok_or(Error::Overflow)?;
|
||||
Ok(gsi)
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "x86_64")]
|
||||
/// Allocate an IRQ
|
||||
pub fn allocate_irq(&mut self) -> Result<u32> {
|
||||
let mut irq: u32 = 0;
|
||||
@@ -81,4 +98,12 @@ impl GsiAllocator {
|
||||
|
||||
Ok(irq)
|
||||
}
|
||||
|
||||
#[cfg(target_arch = "aarch64")]
|
||||
/// Allocate an IRQ
|
||||
pub fn allocate_irq(&mut self) -> Result<u32> {
|
||||
let irq = self.next_irq;
|
||||
self.next_irq = self.next_irq.checked_add(1).ok_or(Error::Overflow)?;
|
||||
Ok(irq)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user