From 3e37f599339bd05bc7097855747d4e80c6513863 Mon Sep 17 00:00:00 2001 From: Sebastien Boeuf Date: Fri, 18 Oct 2019 15:04:44 -0700 Subject: [PATCH] pci: Add new DeviceRelocation trait This new trait will allow the VMM to implement the mechanism following a BAR modification regarding its location in the guest address space. Signed-off-by: Sebastien Boeuf --- pci/src/device.rs | 15 +++++++++++++++ pci/src/lib.rs | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/pci/src/device.rs b/pci/src/device.rs index 1baeb0edd..47041fe42 100755 --- a/pci/src/device.rs +++ b/pci/src/device.rs @@ -91,3 +91,18 @@ pub trait PciDevice: BusDevice { /// * `data` - The data to write. fn write_bar(&mut self, _base: u64, _offset: u64, _data: &[u8]) {} } + +/// This trait defines a set of functions which can be triggered whenever a +/// PCI device is modified in any way. +pub trait DeviceRelocation: Send + Sync { + /// The BAR needs to be moved to a different location in the guest address + /// space. This follows a decision from the software running in the guest. + fn move_bar( + &self, + old_base: u64, + new_base: u64, + len: u64, + pci_dev: &mut dyn PciDevice, + region_type: PciBarRegionType, + ); +} diff --git a/pci/src/lib.rs b/pci/src/lib.rs index 400e4692e..4432bb3f1 100644 --- a/pci/src/lib.rs +++ b/pci/src/lib.rs @@ -23,7 +23,7 @@ pub use self::configuration::{ PciNetworkControllerSubclass, PciProgrammingInterface, PciSerialBusSubClass, PciSubclass, }; pub use self::device::{ - Error as PciDeviceError, InterruptDelivery, InterruptParameters, PciDevice, + DeviceRelocation, Error as PciDeviceError, InterruptDelivery, InterruptParameters, PciDevice, }; pub use self::msi::MsiCap; pub use self::msix::{MsixCap, MsixConfig, MsixTableEntry, MSIX_TABLE_ENTRY_SIZE};