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.VirtualInterruptController,WiredIrqInput, andIrqLine: architecture-neutral interrupt connections 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.
- Controller
Input Id - Identifies one hardware input on an interrupt controller.
- 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.
- Host
IrqId - Identifies one physical interrupt in the host interrupt namespace.
- Interrupt
Controller Id - Identifies an interrupt controller within one virtual machine.
- Interrupt
Source Id - Identifies one device connection to a controller input.
- IrqLine
- A shareable device connection to one wired controller input.
- IrqLine
Id - Identifier of an interrupt line within a virtual machine.
- ItsId
- Identifies one ITS instance within a virtual machine.
- LpiId
- Identifies one LPI in a virtual interrupt controller.
- MsiDevice
Id - Identifies an MSI-producing device in a message interrupt domain.
- MsiEndpoint
- A device-owned connection to a message interrupt controller.
- MsiEvent
Id - Identifies an event generated by an MSI-producing device.
- MsiMessage
- One message delivered to an MSI-capable interrupt controller.
- 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.
- Wired
IrqInput - A controller-owned wired interrupt input.
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
Endpoint - Pinpoints the interrupt endpoint involved in an operation.
- Interrupt
Sharing - Declares whether multiple independently owned sources may use one wired controller input.
- Interrupt
Trigger Mode - Interrupt trigger mode.
- Invalid
Resource Reason - The reason a resource was rejected as structurally invalid during validation.
- IrqError
- Errors reported while connecting or signaling interrupt endpoints.
- 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]. - Message
Interrupt Controller - Supplies planner-authorized MSI endpoints to virtual devices.
- Message
Interrupt Sink - Receives message-signaled interrupts for one controller.
- Virtual
Interrupt Controller - Supplies controller-owned wired inputs to virtual devices.
- Wired
IrqSink - Receives the aggregate electrical state of one controller input.
Type Aliases§
- Device
Result - Result type returned by device access operations.
- Guest
Phys Addr Range - Guest physical address range.
- Interrupt
Trigger - Trigger semantics of one wired interrupt input.
- IrqResult
- Result type returned by virtual interrupt connection operations.