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
impl Bus
sourcepub fn get_bus_type(&self) -> BusType
pub fn get_bus_type(&self) -> BusType
Gets the bus type
sourcepub fn set_access_id(&mut self, id: usize)
pub fn set_access_id(&mut self, id: usize)
Sets the id that will be used for BusAccessInfo.
fn first_before(&self, addr: u64) -> Option<(BusRange, BusEntry)>
fn get_device(&self, addr: u64) -> Option<(u64, u64, BusEntry)>
sourcefn unique_devices(&self) -> Vec<BusDeviceEntry>
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.
sourcefn unique_devices_with_snapshot_key(&self) -> Vec<(String, BusDeviceEntry)>
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.
pub fn sleep_devices(&self) -> Result<()>
pub fn wake_devices(&self) -> Result<()>
pub fn snapshot_devices(&self, snapshot_writer: &SnapshotWriter) -> Result<()>
pub fn restore_devices(&self, snapshot_reader: &SnapshotReader) -> Result<()>
sourcepub fn insert(
&self,
device: Arc<Mutex<dyn BusDevice>>,
base: u64,
len: u64
) -> Result<(), Error>
pub fn insert( &self, device: Arc<Mutex<dyn BusDevice>>, base: u64, len: u64 ) -> Result<(), Error>
Puts the given device at the given address space.
sourcepub fn insert_sync(
&self,
device: Arc<dyn BusDeviceSync>,
base: u64,
len: u64
) -> Result<(), Error>
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.
sourcepub fn remove(&self, base: u64, len: u64) -> Result<(), Error>
pub fn remove(&self, base: u64, len: u64) -> Result<(), Error>
Remove the given device at the given address space.
Trait Implementations§
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
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>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
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)
fn as_any(&self) -> &(dyn Any + 'static)
&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)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait
(where Trait: Downcast
) to &Any
. This is needed since Rust cannot
generate &mut Any
’s vtable from &mut Trait
’s.