Expand description
Basic traits and structures for emulated devices in ArceOS hypervisor.
This crate provides the foundational abstractions for implementing virtual devices
in the AxVisor hypervisor. It is
designed for no_std environments and supports multiple architectures.
§Overview
The crate contains the following key components:
Device: The unified V3 device trait used by the runtime hot path.DeviceAccess: The access-scoped capability context passed to devices.Resource: Static device resource declarations used for registration validation and bus dispatch.IrqSinkandIrqLine: Architecture-neutral interrupt delivery contracts used by device factories.
§Usage
New emulated devices should implement Device directly and receive all
sensitive runtime abilities through DeviceAccess.
ⓘ
use axdevice_base::{
AccessWidth, BusAccess, BusKind, BusResponse, Device, DeviceAccess,
DeviceError, Resource,
};
struct MyDevice {
base_addr: usize,
size: usize,
resources: [Resource; 1],
}
impl Device for MyDevice {
fn name(&self) -> &str {
"my-device"
}
fn resources(&self) -> &[Resource] {
&self.resources
}
fn access(
&self,
access: &BusAccess,
context: &mut dyn DeviceAccess,
) -> Result<BusResponse, DeviceError> {
match (access.kind, access.is_read) {
(BusKind::Mmio, true) => Ok(BusResponse::Read { value: 0 }),
(BusKind::Mmio, false) => Ok(BusResponse::Write),
_ => Err(DeviceError::OutOfRange { addr: access.addr }),
}
}
}§Feature Flags
This crate currently has no optional feature flags. All functionality is available by default.
Structs§
- BusAccess
- An access issued by a vCPU to a device on a bus.
- Device
Id - Opaque identifier assigned to a device when it is registered into a
[
DeviceRuntime]. - DmaGrant
- Permission token for access-scoped guest-memory DMA.
- Guest
Phys Addr - Guest physical address.
- IrqLine
- A shareable interrupt line connected to an
IrqSink. - IrqLine
Id - Identifier of an interrupt line within a virtual machine.
- Noop
Device Access - A no-permission access context for tests and adapter-only callers.
- Port
- The port number of an x86 I/O operation.
- Port
Range - A inclusive range of port numbers.
- Stop
Grant - Permission token for requesting VM stop/suspend style actions.
- SysReg
Addr - A system register address.
- SysReg
Addr Range - A inclusive range of system register addresses.
- Timer
Grant - Permission token for virtual timer scheduling.
- Wake
Grant - Permission token for waking a vCPU from a device.
Enums§
- Access
Width - The width of a guest bus access.
- Arch
- Target instruction-set architecture.
- BusKind
- The kind of bus a device is connected to.
- BusResponse
- The result of a bus access dispatched to a device.
- Device
Error - Errors that can occur during device access handling.
- Interrupt
Trigger Mode - Interrupt trigger mode.
- Invalid
Resource Reason - The reason a resource was rejected as structurally invalid during validation.
- IrqError
- Errors reported while routing or signaling a virtual interrupt line.
- Registry
Error - Errors that can be returned when registering a device.
- Resource
- A resource that a device declares it needs during registration.
Traits§
- BusRouter
- Bus dispatch interface — the runtime hot-path half of a
[
DeviceRuntime]. - Device
- The unified device trait.
- Device
Access - Context scoped to one device bus access.
- Device
Addr - An address-like type that can be used to access devices.
- Device
Addr Range - A range of device addresses. It may be contiguous or not.
- Device
Registry - Device registration interface — the build-time / management-path half of a
[
DeviceRuntime]. - IrqSink
- Receives state changes and pulses from interrupt lines.
Type Aliases§
- Device
Result - Result type returned by device access operations.
- Guest
Phys Addr Range - Guest physical address range.
- IrqResult
- Result type returned by virtual interrupt routing operations.