#hypervisor #devices #abstraction-layer

axdevice

A reusable, OS-agnostic device abstraction layer designed for virtual machines

4 releases

Uses new Rust 2024

0.2.2 Mar 6, 2026
0.2.1 Feb 9, 2026
0.2.1-preview.1 Feb 8, 2026
0.2.0 Feb 3, 2026

#793 in Configuration

Download history 81/week @ 2026-01-29 68/week @ 2026-02-05 30/week @ 2026-02-19 14/week @ 2026-02-26 107/week @ 2026-03-05

159 downloads per month
Used in 2 crates

Apache-2.0

27KB
401 lines

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 std required: Uses alloc and core only, 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: Defines AxVmDeviceConfig, a wrapper for device configuration input.
  • device.rs: Defines AxVmDevices, 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 axdevice::{AxVmDeviceConfig, AxVmDevices};

// Step 1: Load configuration (e.g. from .toml or hypervisor setup)
let config = AxVmDeviceConfig::new(vec![/* EmulatedDeviceConfig */]);

// Step 2: Initialize devices
let devices = AxVmDevices::new(config);

// Step 3: Emulate MMIO access
let _ = devices.handle_mmio_read(0x1000_0000, 4);
devices.handle_mmio_write(0x1000_0000, 4, 0xdead_beef);

๐Ÿ“ฆ Dependencies

License

Axdevice is licensed under the Apache License, Version 2.0. See the LICENSE file for details.

Dependencies

~8MB
~130K SLoC