diff --git a/Cargo.toml b/Cargo.toml index a7ae5fb..6d09f46 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -10,7 +10,7 @@ repository = "https://github.com/arceos-hypervisor/axvisor_api" [package] name = "axvisor_api" -version = "0.2.0" +version = "0.3.0" description = "Basic API for components of the Hypervisor on ArceOS" documentation = "https://docs.rs/axvisor_api" readme = "README.md" @@ -24,15 +24,18 @@ repository.workspace = true [dependencies] # === Core Components === # Procedural macro definitions -axvisor_api_proc = { path = "axvisor_api_proc", version = "0.2.0" } +axvisor_api_proc = { path = "axvisor_api_proc", version = "0.3.0"} # === Third-party Libraries === # Address space abstraction -axaddrspace = "0.1.0" +axaddrspace = "0.3" # Interface definition tools -crate_interface = "0.2" +crate_interface = "0.3" # Physical/virtual address types memory_addr = "0.4" +# CPU mask +cpumask = "0.1.0" + [package.metadata.docs.rs] all-features = true diff --git a/axvisor_api_proc/Cargo.toml b/axvisor_api_proc/Cargo.toml index 2d05c2b..f6e233f 100644 --- a/axvisor_api_proc/Cargo.toml +++ b/axvisor_api_proc/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "axvisor_api_proc" -version = "0.2.0" +version = "0.3.0" description = "Procedural macros for the `axvisor_api` crate" documentation = "https://docs.rs/axvisor_api_proc" readme = "README.md" diff --git a/src/arch.rs b/src/arch.rs index 4671b4e..977f639 100644 --- a/src/arch.rs +++ b/src/arch.rs @@ -133,4 +133,16 @@ pub trait ArchIf { /// later. #[cfg(target_arch = "aarch64")] fn get_host_gicr_base() -> PhysAddr; + + /// Retrieve the current pending interrupt for the CPU from the physical hardware. + #[cfg(target_arch = "aarch64")] + fn fetch_irq() -> u64; + /// Calls the IRQ handler of the underlying OS to handle a pending interrupt. + /// + /// TODO: Determine if this function should be exposed in other architectures (and moved to + /// `host` module) or remain architecture-specific. + /// + /// TODO: Consider whether this function should replace `AxVCpuExitReason::ExternalInterrupt`. + #[cfg(target_arch = "aarch64")] + fn handle_irq(); } diff --git a/src/memory.rs b/src/memory.rs index 49f6033..941807c 100644 --- a/src/memory.rs +++ b/src/memory.rs @@ -170,6 +170,7 @@ pub trait MemoryIf { /// This struct provides an implementation of the `AxMmHal` trait from the /// `axaddrspace` crate, delegating to the axvisor_api memory functions. #[doc(hidden)] +#[derive(Debug)] pub struct AxMmHalApiImpl; impl axaddrspace::AxMmHal for AxMmHalApiImpl { diff --git a/src/vmm.rs b/src/vmm.rs index 722f1d5..8de149c 100644 --- a/src/vmm.rs +++ b/src/vmm.rs @@ -71,6 +71,12 @@ pub type VCpuId = usize; /// Represents the interrupt vector number to be injected into a guest. pub type InterruptVector = u8; +/// The maximum number of virtual CPUs supported in a virtual machine. +pub const MAX_VCPU_NUM: usize = 64; + +/// A set of virtual CPUs. +pub type VCpuSet = cpumask::CpuMask; + /// The API trait for virtual machine management functionalities. /// /// This trait defines the core VM management interface required by the @@ -78,6 +84,7 @@ pub type InterruptVector = u8; /// layer. #[crate::api_def] pub trait VmmIf { + /// Notify that a virtual CPU timer has expired. /// Get the identifier of the current virtual machine. /// /// This function returns the VM ID of the VM that the calling context @@ -145,6 +152,9 @@ pub trait VmmIf { /// ``` fn inject_interrupt(vm_id: VMId, vcpu_id: VCpuId, vector: InterruptVector); + /// Inject an interrupt to a set of virtual CPUs. + fn inject_interrupt_to_cpus(vm_id: VMId, vcpu_set: VCpuSet, vector: InterruptVector); + /// Notify that a virtual CPU's timer has expired. /// /// This function is called when a vCPU's virtual timer expires and needs @@ -162,7 +172,8 @@ pub trait VmmIf { fn notify_vcpu_timer_expired(vm_id: VMId, vcpu_id: VCpuId); } -/// Get the number of virtual CPUs in the current virtual machine. +/// Get the number of virtual CPUs in the current virtual machine executing on +/// the current physical CPU. /// /// This is a convenience function that combines [`current_vm_id`] and /// [`vcpu_num`]. @@ -179,7 +190,8 @@ pub fn current_vm_vcpu_num() -> usize { vcpu_num(current_vm_id()).unwrap() } -/// Get the bitmask of active virtual CPUs in the current virtual machine. +/// Get the bitmask of active virtual CPUs in the current virtual machine +/// executing on the current physical CPU. /// /// This is a convenience function that combines [`current_vm_id`] and /// [`active_vcpus`].