vmm: Add pci_segment option to UserDeviceConfig

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 d4f7f42800
commit f71f6da907
2 changed files with 16 additions and 7 deletions

View File

@ -1695,23 +1695,33 @@ pub struct UserDeviceConfig {
pub socket: PathBuf,
#[serde(default)]
pub id: Option<String>,
#[serde(default)]
pub pci_segment: u16,
}
impl UserDeviceConfig {
pub const SYNTAX: &'static str = "Userspace device socket=<socket_path>,id=<device_id>\"";
pub const SYNTAX: &'static str =
"Userspace device socket=<socket_path>,id=<device_id>,pci_segment=<segment_id>\"";
pub fn parse(user_device: &str) -> Result<Self> {
let mut parser = OptionParser::new();
parser.add("socket").add("id");
parser.add("socket").add("id").add("pci_segment");
parser.parse(user_device).map_err(Error::ParseUserDevice)?;
let socket = parser
.get("socket")
.map(PathBuf::from)
.ok_or(Error::ParseUserDeviceSocketMissing)?;
let id = parser.get("id");
let pci_segment = parser
.convert::<u16>("pci_segment")
.map_err(Error::ParseUserDevice)?
.unwrap_or_default();
Ok(UserDeviceConfig { socket, id })
Ok(UserDeviceConfig {
socket,
id,
pci_segment,
})
}
}
#[derive(Clone, Debug, PartialEq, Deserialize, Serialize, Default)]

View File

@ -3063,8 +3063,7 @@ impl DeviceManager {
&mut self,
device_cfg: &mut UserDeviceConfig,
) -> DeviceManagerResult<(u32, String)> {
// TODO: Fill with PCI segment ID from config when available
let pci_segment_id = 0;
let pci_segment_id = device_cfg.pci_segment;
let pci_device_bdf = self.pci_segments[pci_segment_id as usize].next_device_bdf()?;
let legacy_interrupt_group =
@ -3449,7 +3448,7 @@ impl DeviceManager {
let (device_id, device_name) = self.add_vfio_user_device(device_cfg)?;
// 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 {
id: device_name,