MutDeviceMmio

Trait MutDeviceMmio 

Source
pub trait MutDeviceMmio {
    // Required methods
    fn mmio_read(
        &mut self,
        base: MmioAddress,
        offset: MmioAddressOffset,
        data: &mut [u8],
    );
    fn mmio_write(
        &mut self,
        base: MmioAddress,
        offset: MmioAddressOffset,
        data: &[u8],
    );
}
Expand description

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

§Example

struct DummyDevice {
    config: u32,
}

impl MutDeviceMmio for DummyDevice {
    fn mmio_read(&mut self, _base: MmioAddress, _offset: MmioAddressOffset, data: &mut [u8]) {
        if data.len() > 4 {
            return;
        }
        for (idx, iter) in data.iter_mut().enumerate() {
            *iter = (self.config >> (idx * 8) & 0xff) as u8;
        }
    }

    fn mmio_write(&mut self, _base: MmioAddress, _offset: MmioAddressOffset, data: &[u8]) {
        self.config = u32::from(data[0]) & 0xff;
    }
}

Required Methods§

Source

fn mmio_read( &mut self, base: MmioAddress, offset: MmioAddressOffset, data: &mut [u8], )

Handle a read operation on the device.

§Arguments
  • base: base address on a MMIO bus
  • offset: base address’ offset
  • data: a buffer provided by the caller to store the read data
Source

fn mmio_write( &mut self, base: MmioAddress, offset: MmioAddressOffset, data: &[u8], )

Handle a write operation to the device.

§Arguments
  • base: base address on a MMIO bus
  • offset: base address’ offset
  • data: a buffer provided by the caller holding the data to write

Implementors§