axvirtio_blk/lib.rs
1//! # AxVirtIO Block Device Library
2//!
3//! This crate provides a VirtIO block device implementation for the AxVirtIO framework.
4//! It includes MMIO transport, block device backend traits, and request handling
5//! for VirtIO block devices according to the VirtIO specification.
6//!
7//! ## Features
8//!
9//! - VirtIO block device MMIO implementation
10//! - Pluggable block backend support
11//! - Guest memory access abstraction
12//! - VirtIO queue management for block operations
13//!
14//! ## Usage
15//!
16//! ```rust,no_run
17//! use axvirtio_blk::{VirtioMmioBlockDevice, BlockBackend, VirtioBlockConfig, VirtioResult};
18//! use axaddrspace::GuestMemoryAccessor;
19//! use axaddrspace::GuestPhysAddr;
20//! use memory_addr::PhysAddr;
21//!
22//! // Implement your block backend
23//! struct MyBlockBackend;
24//! impl BlockBackend for MyBlockBackend {
25//! fn read(&self, _sector: u64, _buffer: &mut [u8]) -> VirtioResult<usize> {
26//! Ok(0)
27//! }
28//! fn write(&self, _sector: u64, _buffer: &[u8]) -> VirtioResult<usize> {
29//! Ok(0)
30//! }
31//! fn flush(&self) -> VirtioResult<()> {
32//! Ok(())
33//! }
34//! }
35//!
36//! #[derive(Clone)]
37//! struct MyTranslator;
38//! impl GuestMemoryAccessor for MyTranslator {
39//! fn translate_and_get_limit(&self, guest_addr: GuestPhysAddr) -> Option<(PhysAddr, usize)> {
40//! None
41//! }
42//! }
43//!
44//! // Create and use the VirtIO block device
45//! let backend = MyBlockBackend;
46//! let translator = MyTranslator;
47//! let block_config = VirtioBlockConfig::default();
48//! let device = VirtioMmioBlockDevice::new(GuestPhysAddr::from(0x0a000000), 0x200, backend, block_config, translator);
49//! ```
50
51#![no_std]
52
53#[macro_use]
54extern crate alloc;
55
56#[macro_use]
57extern crate log;
58
59mod backend;
60mod block;
61mod constants;
62mod mmio;
63
64// Re-export from axvirtio-common
65pub use axvirtio_common::{VirtioConfig, VirtioError, VirtioQueue, VirtioResult};
66
67// Re-export device-specific types
68pub use backend::BlockBackend;
69pub use block::config::VirtioBlockConfig;
70pub use mmio::VirtioMmioBlockDevice;