|
@@ -1,4 +1,43 @@
|
|
|
//! VirtIO guest drivers.
|
|
|
+//!
|
|
|
+//! These drivers can be used by bare-metal code (such as a bootloader or OS kernel) running in a VM
|
|
|
+//! to interact with VirtIO devices provided by the VMM (such as QEMU or crosvm).
|
|
|
+//!
|
|
|
+//! # Usage
|
|
|
+//!
|
|
|
+//! You must first implement the [`Hal`] trait, to allocate DMA regions and translate between
|
|
|
+//! physical addresses (as seen by devices) and virtual addresses (as seen by your program). You can
|
|
|
+//! then construct the appropriate transport for the VirtIO device, e.g. for an MMIO device (perhaps
|
|
|
+//! discovered from the device tree):
|
|
|
+//!
|
|
|
+//! ```
|
|
|
+//! use core::ptr::NonNull;
|
|
|
+//! use virtio_drivers::transport::mmio::{MmioTransport, VirtIOHeader};
|
|
|
+//!
|
|
|
+//! # fn example(mmio_device_address: usize) {
|
|
|
+//! let header = NonNull::new(mmio_device_address as *mut VirtIOHeader).unwrap();
|
|
|
+//! let transport = unsafe { MmioTransport::new(header) }.unwrap();
|
|
|
+//! # }
|
|
|
+//! ```
|
|
|
+//!
|
|
|
+//! You can then check what kind of VirtIO device it is and construct the appropriate driver:
|
|
|
+//!
|
|
|
+//! ```
|
|
|
+//! # use virtio_drivers::Hal;
|
|
|
+//! use virtio_drivers::{
|
|
|
+//! device::console::VirtIOConsole,
|
|
|
+//! transport::{mmio::MmioTransport, DeviceType, Transport},
|
|
|
+//! };
|
|
|
+
|
|
|
+//!
|
|
|
+//! # fn example<HalImpl: Hal>(transport: MmioTransport) {
|
|
|
+//! if transport.device_type() == DeviceType::Console {
|
|
|
+//! let mut console = VirtIOConsole::<HalImpl, _>::new(transport).unwrap();
|
|
|
+//! // Send a byte to the console.
|
|
|
+//! console.send(b'H').unwrap();
|
|
|
+//! }
|
|
|
+//! # }
|
|
|
+//! ```
|
|
|
|
|
|
#![cfg_attr(not(test), no_std)]
|
|
|
#![deny(unused_must_use, missing_docs)]
|
|
@@ -8,29 +47,13 @@
|
|
|
#[cfg(any(feature = "alloc", test))]
|
|
|
extern crate alloc;
|
|
|
|
|
|
-mod blk;
|
|
|
-mod console;
|
|
|
-mod gpu;
|
|
|
+pub mod device;
|
|
|
mod hal;
|
|
|
-#[cfg(feature = "alloc")]
|
|
|
-mod input;
|
|
|
-mod net;
|
|
|
mod queue;
|
|
|
-mod transport;
|
|
|
+pub mod transport;
|
|
|
mod volatile;
|
|
|
|
|
|
-pub use self::blk::{BlkReq, BlkResp, RespStatus, VirtIOBlk, SECTOR_SIZE};
|
|
|
-pub use self::console::VirtIOConsole;
|
|
|
-pub use self::gpu::VirtIOGpu;
|
|
|
pub use self::hal::{Hal, PhysAddr, VirtAddr};
|
|
|
-#[cfg(feature = "alloc")]
|
|
|
-pub use self::input::{InputConfigSelect, InputEvent, VirtIOInput};
|
|
|
-pub use self::net::VirtIONet;
|
|
|
-use self::queue::VirtQueue;
|
|
|
-pub use self::transport::mmio::{MmioError, MmioTransport, MmioVersion, VirtIOHeader};
|
|
|
-pub use self::transport::pci;
|
|
|
-pub use self::transport::{DeviceStatus, DeviceType, Transport};
|
|
|
-use hal::*;
|
|
|
|
|
|
/// The page size in bytes supported by the library (4 KiB).
|
|
|
pub const PAGE_SIZE: usize = 0x1000;
|