axdevice
axdevice is a reusable, OS-agnostic device abstraction layer designed for virtual machines. It allows dynamic device configuration and MMIO emulation in no_std environments, making it suitable for hypervisors or operating systems targeting RISC-V or AArch64.
โจ Highlights
- ๐ฆ Componentized: Designed as a modular crate to be integrated into any OS or hypervisor.
- ๐งฉ Flexible device abstraction: Supports dynamic device registration and MMIO handling.
- ๐ ๏ธ No
stdrequired: Usesallocandcoreonly, suitable for bare-metal development. - ๐งต Thread-safe: Devices are stored using
Arc, ready for multicore use. - ๐งฑ Easily extensible: Just plug in device types via
axdevice_base::BaseDeviceOps.
๐ฆ Structure
config.rs: DefinesAxVmDeviceConfig, a wrapper for device configuration input.device.rs: DefinesAxVmDevices, manages and dispatches MMIO to registered devices.
๐ Dependency Graph
+-------------------+
| axvmconfig | <- defines EmulatedDeviceConfig
+-------------------+
|
v
+------------------+ uses +-----------------------+
| axdevice +-------------->+ axdevice_base::trait |
| (this crate) | +-----------------------+
+------------------+ ^
| |
v |
+------------------+ |
| axaddrspace | -- GuestPhysAddr ----+
+------------------+
๐ Usage Flow
[1] Load VM device config (Vec<EmulatedDeviceConfig>)
โ
[2] Create AxVmDeviceConfig
โ
[3] Pass into AxVmDevices::new()
โ
[4] MMIO access triggers handle_mmio_{read,write}
โ
[5] Device selected by GuestPhysAddr
โ
[6] Forwarded to BaseDeviceOps::handle_{read,write}()
๐ Example
use ;
// Step 1: Load configuration (e.g. from .toml or hypervisor setup)
let config = new;
// Step 2: Initialize devices
let devices = new;
// Step 3: Emulate MMIO access
let _ = devices.handle_mmio_read;
devices.handle_mmio_write;
๐ฆ Dependencies
axvmconfigaxaddrspaceaxdevice_baselog,alloc,cfg-if,axerrno
License
Axdevice is licensed under the Apache License, Version 2.0. See the LICENSE file for details.