mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-18 18:45:19 +00:00
pci: Allow specific PCI b/d/f to be reserved
In order to let the PciBus user choose where a device should be placed on the bus, a new function get_device_id() is introduced. This will be helpful in the context of snapshot/restore as the caller will be able to place the PCI devices on the same slot they were placed before the snapshot was taken. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
e577b64a58
commit
1e0ebb760f
@ -34,6 +34,8 @@ pub enum PciRootError {
|
|||||||
NoPciDeviceSlotAvailable,
|
NoPciDeviceSlotAvailable,
|
||||||
/// Invalid PCI device identifier provided.
|
/// Invalid PCI device identifier provided.
|
||||||
InvalidPciDeviceSlot(usize),
|
InvalidPciDeviceSlot(usize),
|
||||||
|
/// Valid PCI device identifier but already used.
|
||||||
|
AlreadyInUsePciDeviceSlot(usize),
|
||||||
}
|
}
|
||||||
pub type Result<T> = std::result::Result<T, PciRootError>;
|
pub type Result<T> = std::result::Result<T, PciRootError>;
|
||||||
|
|
||||||
@ -155,6 +157,19 @@ impl PciBus {
|
|||||||
Err(PciRootError::NoPciDeviceSlotAvailable)
|
Err(PciRootError::NoPciDeviceSlotAvailable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn get_device_id(&mut self, id: usize) -> Result<()> {
|
||||||
|
if id < NUM_DEVICE_IDS {
|
||||||
|
if !self.device_ids[id] {
|
||||||
|
self.device_ids[id] = true;
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
Err(PciRootError::AlreadyInUsePciDeviceSlot(id))
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
Err(PciRootError::InvalidPciDeviceSlot(id))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub fn put_device_id(&mut self, id: usize) -> Result<()> {
|
pub fn put_device_id(&mut self, id: usize) -> Result<()> {
|
||||||
if id < NUM_DEVICE_IDS {
|
if id < NUM_DEVICE_IDS {
|
||||||
self.device_ids[id] = false;
|
self.device_ids[id] = false;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user