Expand description
Write virtio devices in Rust.
This crate provides utilities for virtio devices to manipulate descriptor rings. Only the device side is targeted, and this crate is completely unsuitable, and not intended, for writing drivers.
The provided wrappers are built up in a series of layers, each providing a higher level and more convenient interface, at the cost of injecting some policy opinions for managing the rings. The layers/modules are:
chainHigh level iteration and walking of descriptor chains as series of byte ranges including manipulation through [std::io::read] and [std::io::write] interfaces.queueProvides functional virt queue management allowing for descriptor chains to be retrieved, iterated and returned.ringProvides the barest minimum Rust type safety over accessing the rings. This is not expected to generally be needed, withqueuecompletely hiding allringdetails. There are some additional modules providing:memDefinitions for memory translation between drivers and devices.utilSmall wrappers and trait implementations that are commonly useful, but very opinionated.fake_queueHelpers for writing unittests against virtio devices.
What this crate does not provide is any transport or device type specific management. The user then is responsible for performing all setup and feature negotiation prior to using this crate to manage the negotiated queues. The user therefore needs to provide:
- Location of negotiated desc, used and avail rings as
mem::DeviceRangedefinitions. - Implementation of
mem::DriverMemfor driver to device memory address translation. - Implementation of
queue::DriverNotifyfor signaling the driver. - A way to receive signals from the driver to know when to check for descriptors.
With these pieces existing a typical usage of this crate is expected to be:
- Construct a
queue::Queueby passing the ring definitions toqueue::Queue::new - Build a
util::DescChainStreamfrom thequeue::Queueand connect theutil::DescChainStream::waker - Construct
chain::ReadableChainorchain::WritableChainfrom thequeue::DescChainitems generated by theutil::DescChainStream - Process the
chain::ReadableChainorchain::WritableChainusing their provided methods or the [std::io::read] and [std::io::write] trait implementations. - Explicitly return the chain or let it
dropto have thequeue::Queuereturn it to the driver.
Commonly if expecting to process descriptors chains in batches you will also want to wrap your
queue::DriverNotify in a util::BufferedNotify, but you must ensure to call
util::BufferedNotify::flush.
Modulesยง
- chain
- Descriptor chain walking.
- fake_
queue - Fake queue for simulating driver interactions in unittests
- mem
- Structures for talking about memory shared between virtio devices and drivers
- queue
- Virtqueue management wrappers.
- ring
- Minimal type-safe definitions of the virtio data structures.
- util
- Small utility wrappers and trait implementations.