Struct devices::bus::Bus

source ·
pub struct Bus {
    devices: Arc<Mutex<BTreeMap<BusRange, BusEntry>>>,
    access_id: usize,
    bus_type: BusType,
}
Expand description

A device container for routing reads and writes over some address space.

This doesn’t have any restrictions on what kind of device or address space this applies to. The only restriction is that no two devices can overlap in this address space.

Fields§

§devices: Arc<Mutex<BTreeMap<BusRange, BusEntry>>>§access_id: usize§bus_type: BusType

Implementations§

source§

impl Bus

source

pub fn new(bus_type: BusType) -> Bus

Constructs an a bus with an empty address space.

source

pub fn get_bus_type(&self) -> BusType

Gets the bus type

source

pub fn set_access_id(&mut self, id: usize)

Sets the id that will be used for BusAccessInfo.

source

fn first_before(&self, addr: u64) -> Option<(BusRange, BusEntry)>

source

fn get_device(&self, addr: u64) -> Option<(u64, u64, BusEntry)>

source

fn unique_devices(&self) -> Vec<BusDeviceEntry>

There is no unique ID for device instances. For now we use the Arc pointers to dedup them.

See virtio-gpu for an example of a single device instance with multiple bus entries.

TODO: Add a unique ID to BusDevice and use that instead of pointers.

source

fn unique_devices_with_snapshot_key(&self) -> Vec<(String, BusDeviceEntry)>

Same as unique_devices, but also calculates the “snapshot key” for each device.

The keys are used to associate a particular device with data in a serialized snapshot. The keys need to be stable across multiple runs of the same crosvm binary.

It is most convienent to calculate all the snapshot keys at once, because the keys are dependant on the order of devices on the bus.

source

pub fn sleep_devices(&self) -> Result<()>

source

pub fn wake_devices(&self) -> Result<()>

source

pub fn snapshot_devices(&self, snapshot_writer: &SnapshotWriter) -> Result<()>

source

pub fn restore_devices(&self, snapshot_reader: &SnapshotReader) -> Result<()>

source

pub fn insert( &self, device: Arc<Mutex<dyn BusDevice>>, base: u64, len: u64 ) -> Result<(), Error>

Puts the given device at the given address space.

source

pub fn insert_sync( &self, device: Arc<dyn BusDeviceSync>, base: u64, len: u64 ) -> Result<(), Error>

Puts the given device that implements BusDeviceSync at the given address space. Devices that implement BusDeviceSync manage thread safety internally, and thus can be written to by multiple threads simultaneously.

source

pub fn remove(&self, base: u64, len: u64) -> Result<(), Error>

Remove the given device at the given address space.

source

pub fn read(&self, addr: u64, data: &mut [u8]) -> bool

Reads data from the device that owns the range containing addr and puts it into data.

Returns true on success, otherwise data is filled with zeroes.

source

pub fn write(&self, addr: u64, data: &[u8]) -> bool

Writes data to the device that owns the range containing addr.

Returns true on success, otherwise data is untouched.

Trait Implementations§

source§

impl Clone for Bus

source§

fn clone(&self) -> Bus

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl Default for Bus

source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl RefUnwindSafe for Bus

§

impl Send for Bus

§

impl Sync for Bus

§

impl Unpin for Bus

§

impl UnwindSafe for Bus

Blanket Implementations§

source§

impl<T> Any for T
where T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for T
where T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> Downcast for T
where T: Any,

§

fn into_any(self: Box<T>) -> Box<dyn Any>

Convert Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.
§

fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>

Convert Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be further downcast into Rc<ConcreteType> where ConcreteType implements Trait.
§

fn as_any(&self) -> &(dyn Any + 'static)

Convert &Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &Any’s vtable from &Trait’s.
§

fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)

Convert &mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot generate &mut Any’s vtable from &mut Trait’s.
§

impl<T> DowncastSync for T
where T: Any + Send + Sync,

§

fn into_any_arc(self: Arc<T>) -> Arc<dyn Any + Send + Sync>

Convert Arc<Trait> (where Trait: Downcast) to Arc<Any>. Arc<Any> can then be further downcast into Arc<ConcreteType> where ConcreteType implements Trait.
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for T
where U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

§

fn vzip(self) -> V