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:
Pascal Scholz
2026-03-26 14:16:06 +01:00
committed by Rob Bradford
parent afd155d578
commit 34f08002e1
3 changed files with 160 additions and 14 deletions
+3 -2
View File
@@ -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
View File
@@ -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,
))
}