mirror of
https://chromium.googlesource.com/crosvm/crosvm
synced 2025-02-06 02:25:23 +00:00
devices: Introduce remove() for bus
When device's bar is reallocated, the old ranges will be deleted, this commit add remove() function to delete one old range from bus->devices. BUG=b:174705596 TEST=Boot a vm, monitor Bar Reallocation then check function Change-Id: Id0600ae1d7a3d04c7f05a90abcc8807b7f1020c3 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/crosvm/+/3184725 Tested-by: kokoro <noreply+kokoro@google.com> Commit-Queue: Daniel Verkamp <dverkamp@chromium.org> Reviewed-by: Daniel Verkamp <dverkamp@chromium.org>
This commit is contained in:
parent
ccb9014afb
commit
d982b8d9a3
1 changed files with 24 additions and 0 deletions
|
@ -150,6 +150,8 @@ pub trait BusDeviceObj {
|
|||
#[sorted]
|
||||
#[derive(Error, Debug)]
|
||||
pub enum Error {
|
||||
#[error("Bus Range not found")]
|
||||
Empty,
|
||||
/// The insertion failed because the new device overlapped with an old device.
|
||||
#[error("new device overlaps with an old device")]
|
||||
Overlap,
|
||||
|
@ -295,6 +297,28 @@ impl Bus {
|
|||
Ok(())
|
||||
}
|
||||
|
||||
/// Remove the given device at the given address space.
|
||||
pub fn remove(&self, base: u64, len: u64) -> Result<()> {
|
||||
if len == 0 {
|
||||
return Err(Error::Overlap);
|
||||
}
|
||||
|
||||
let mut devices = self.devices.lock();
|
||||
if devices
|
||||
.iter()
|
||||
.any(|(range, _dev)| range.base == base && range.len == len)
|
||||
{
|
||||
let ret = devices.remove(&BusRange { base, len });
|
||||
if ret.is_some() {
|
||||
Ok(())
|
||||
} else {
|
||||
Err(Error::Empty)
|
||||
}
|
||||
} else {
|
||||
Err(Error::Empty)
|
||||
}
|
||||
}
|
||||
|
||||
/// Reads data from the device that owns the range containing `addr` and puts it into `data`.
|
||||
///
|
||||
/// Returns true on success, otherwise `data` is untouched.
|
||||
|
|
Loading…
Reference in a new issue