mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-11-04 19:11:11 +00:00
vmm: Add pci_segment option to UserDeviceConfig
Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
d4f7f42800
commit
f71f6da907
@ -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)]
|
||||
|
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user