mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
vmm: Allow for device ID allocation on a segment
Allocating a device ID is crucial for assigning a specific ID to a device. We need this to implement configurable PCI device ID. Signed-off-by: Pascal Scholz <pascal.scholz@cyberus-technology.de> On-behalf-of: SAP pascal.scholz@sap.com Signed-off-by: Rob Bradford <rbradford@meta.com>
This commit is contained in:
committed by
Rob Bradford
parent
afd155d578
commit
34f08002e1
@@ -494,7 +494,7 @@ pub enum DeviceManagerError {
|
||||
|
||||
/// Failed to find an available PCI device ID.
|
||||
#[error("Failed to find an available PCI device ID")]
|
||||
NextPciDeviceId(#[source] pci::PciRootError),
|
||||
AllocatePciDeviceId(#[source] pci::PciRootError),
|
||||
|
||||
/// Could not reserve the PCI device ID.
|
||||
#[error("Could not reserve the PCI device ID")]
|
||||
@@ -4555,7 +4555,8 @@ impl DeviceManager {
|
||||
|
||||
(pci_segment_id, pci_device_bdf, resources)
|
||||
} else {
|
||||
let pci_device_bdf = self.pci_segments[pci_segment_id as usize].next_device_bdf()?;
|
||||
let pci_device_bdf =
|
||||
self.pci_segments[pci_segment_id as usize].allocate_device_id(None)?;
|
||||
|
||||
(pci_segment_id, pci_device_bdf, None)
|
||||
})
|
||||
|
||||
+10
-3
@@ -164,15 +164,22 @@ impl PciSegment {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn next_device_bdf(&self) -> DeviceManagerResult<PciBdf> {
|
||||
/// Allocates a device's ID on this PCI segment.
|
||||
///
|
||||
/// - `device_id`: Device ID to request for allocation
|
||||
///
|
||||
/// ## Errors
|
||||
/// * [`DeviceManagerError::AllocatePciDeviceId`] if device ID
|
||||
/// allocation on the bus fails.
|
||||
pub(crate) fn allocate_device_id(&self, device_id: Option<u8>) -> DeviceManagerResult<PciBdf> {
|
||||
Ok(PciBdf::new(
|
||||
self.id,
|
||||
0,
|
||||
self.pci_bus
|
||||
.lock()
|
||||
.unwrap()
|
||||
.next_device_id()
|
||||
.map_err(DeviceManagerError::NextPciDeviceId)? as u8,
|
||||
.allocate_device_id(device_id)
|
||||
.map_err(DeviceManagerError::AllocatePciDeviceId)?,
|
||||
0,
|
||||
))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user