vmm: Add pci_segment option to DeviceConfig

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2021-10-07 16:54:32 +01:00
parent ca955a47ff
commit d4f7f42800
2 changed files with 23 additions and 9 deletions

View File

@ -1654,14 +1654,16 @@ pub struct DeviceConfig {
pub iommu: bool, pub iommu: bool,
#[serde(default)] #[serde(default)]
pub id: Option<String>, pub id: Option<String>,
#[serde(default)]
pub pci_segment: u16,
} }
impl DeviceConfig { impl DeviceConfig {
pub const SYNTAX: &'static str = pub const SYNTAX: &'static str =
"Direct device assignment parameters \"path=<device_path>,iommu=on|off,id=<device_id>\""; "Direct device assignment parameters \"path=<device_path>,iommu=on|off,id=<device_id>,pci_segment=<segment_id>\"";
pub fn parse(device: &str) -> Result<Self> { pub fn parse(device: &str) -> Result<Self> {
let mut parser = OptionParser::new(); let mut parser = OptionParser::new();
parser.add("path").add("id").add("iommu"); parser.add("path").add("id").add("iommu").add("pci_segment");
parser.parse(device).map_err(Error::ParseDevice)?; parser.parse(device).map_err(Error::ParseDevice)?;
let path = parser let path = parser
@ -1674,7 +1676,17 @@ impl DeviceConfig {
.unwrap_or(Toggle(false)) .unwrap_or(Toggle(false))
.0; .0;
let id = parser.get("id"); let id = parser.get("id");
Ok(DeviceConfig { path, iommu, id }) let pci_segment = parser
.convert::<u16>("pci_segment")
.map_err(Error::ParseDevice)?
.unwrap_or_default();
Ok(DeviceConfig {
path,
iommu,
id,
pci_segment,
})
} }
} }
@ -2754,7 +2766,8 @@ mod tests {
DeviceConfig { DeviceConfig {
path: PathBuf::from("/path/to/device"), path: PathBuf::from("/path/to/device"),
id: None, id: None,
iommu: false iommu: false,
..Default::default()
} }
); );
@ -2763,7 +2776,8 @@ mod tests {
DeviceConfig { DeviceConfig {
path: PathBuf::from("/path/to/device"), path: PathBuf::from("/path/to/device"),
id: None, id: None,
iommu: true iommu: true,
..Default::default()
} }
); );
@ -2772,7 +2786,8 @@ mod tests {
DeviceConfig { DeviceConfig {
path: PathBuf::from("/path/to/device"), path: PathBuf::from("/path/to/device"),
id: Some("mydevice0".to_owned()), id: Some("mydevice0".to_owned()),
iommu: true iommu: true,
..Default::default()
} }
); );

View File

@ -2851,8 +2851,7 @@ impl DeviceManager {
&mut self, &mut self,
device_cfg: &mut DeviceConfig, device_cfg: &mut DeviceConfig,
) -> DeviceManagerResult<(u32, String)> { ) -> DeviceManagerResult<(u32, String)> {
// TODO: Fill with PCI segment ID from config when available let pci_segment_id = device_cfg.pci_segment;
let pci_segment_id = 0;
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].next_device_bdf()?;
let mut needs_dma_mapping = false; let mut needs_dma_mapping = false;
@ -3435,7 +3434,7 @@ impl DeviceManager {
let (device_id, device_name) = self.add_passthrough_device(device_cfg)?; let (device_id, device_name) = self.add_passthrough_device(device_cfg)?;
// Update the PCIU bitmap // Update the PCIU bitmap
self.pci_segments[0].pci_devices_up |= 1 << (device_id >> 3); self.pci_segments[device_cfg.pci_segment as usize].pci_devices_up |= 1 << (device_id >> 3);
Ok(PciDeviceInfo { Ok(PciDeviceInfo {
id: device_name, id: device_name,