Crate vm_device[][src]

Expand description

This crate provides:

  • device traits defining read and write operations on specialized buses
  • device manager (bus-specific traits and a concrete implementation) for operating devices and dispatching I/O
  • abstractions for defining resources and their constraints (e.g. a specific bus address range, IRQ number, etc)

MutDevicePio and MutDeviceMmio traits help with composite inner mutability (i.e. if we have a Mutex that holds a T which implements MutDevicePio, then the Mutex can implement DevicePio based on its inner mutability properties).

Example

Implement a simple log PIO device, register it with IoManager and dispatch a write operation to the device.

 use std::sync::{Arc, Mutex};
 use vm_device::bus::{PioAddress, PioAddressOffset, PioRange};
 use vm_device::device_manager::{IoManager, PioManager};
 use vm_device::MutDevicePio;

 struct LogDevice {}

 impl MutDevicePio for LogDevice {
     fn pio_read(&mut self, base: PioAddress, offset: PioAddressOffset, _data: &mut [u8]) {
         println!("mut pio_read: base {:?}, offset {}", base, offset);
     }
     fn pio_write(&mut self, base: PioAddress, offset: PioAddressOffset, data: &[u8]) {
         println!(
             "mut pio_write: base {:?}, offset {}, data {:?}",
             base, offset, data
         );
     }
 }

 // IoManager implements PioManager trait.
 let mut manager = IoManager::new();
 let device = LogDevice {};
 let bus_range = PioRange::new(PioAddress(0), 10).unwrap();
 manager
     .register_pio(bus_range, Arc::new(Mutex::new(device)))
     .unwrap();
 manager.pio_write(PioAddress(0), &vec![b'o', b'k']).unwrap();

Modules

Provides abstractions for modelling an I/O bus.

System level device management.

Structs to manage device resources.

Traits

Allows a device to be attached to a MMIO bus.

Allows a device to be attached to a PIO bus.

Same as DeviceMmio but the methods are invoked with a mutable self borrow.

Same as DevicePio but the methods are invoked with a mutable self borrow.