extern crate alloc;
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
use alloc::boxed::Box;
use core::time::Duration;
use ax_errno::AxResult;
use axvm_types::{HostPhysAddr, HostVirtAddr};
pub trait HostMemory {
fn alloc_frame(&self) -> Option<HostPhysAddr>;
fn dealloc_frame(&self, paddr: HostPhysAddr);
fn alloc_contiguous_frames(
&self,
num_frames: usize,
frame_align: usize,
) -> Option<HostPhysAddr>;
fn dealloc_contiguous_frames(&self, paddr: HostPhysAddr, num_frames: usize);
fn phys_to_virt(&self, paddr: HostPhysAddr) -> HostVirtAddr;
fn virt_to_phys(&self, vaddr: HostVirtAddr) -> HostPhysAddr;
}
pub trait HostTime {
type CancelToken: Copy + Send + Sync + 'static;
#[cfg(target_arch = "x86_64")]
fn nanos_to_ticks(&self, nanos: u64) -> u64;
fn monotonic_time(&self) -> Duration;
fn set_oneshot_timer(&self, deadline_ns: u64);
#[cfg(any(target_arch = "x86_64", target_arch = "aarch64"))]
fn register_timer(
&self,
deadline_ns: u64,
callback: Box<dyn FnOnce(Duration) + Send + 'static>,
) -> Self::CancelToken;
#[cfg(target_arch = "x86_64")]
fn cancel_timer(&self, token: Self::CancelToken);
}
pub trait HostCpu {
type CpuMask: Send + Sync + 'static;
fn cpu_count(&self) -> usize;
fn this_cpu_id(&self) -> usize;
fn bind_current_to_cpu(&self, cpu_id: usize) -> AxResult;
}
#[cfg(target_arch = "x86_64")]
pub trait HostConsole {
fn write_bytes(&self, bytes: &[u8]);
fn read_bytes(&self, bytes: &mut [u8]) -> usize;
}
pub trait HostPlatform {
fn has_hardware_support(&self) -> bool;
fn enable_virtualization_on_current_cpu(&self) -> AxResult;
fn enable_virtualization_on_all_cpus(&self) -> AxResult;
}