mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-01 02:55:45 +00:00
vmm: Use a vector to store multiple segments
For now this still contains just one segment but is expanding in preparation for more segments. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
b4fc02857f
commit
fbb385834a
@ -826,7 +826,7 @@ pub struct DeviceManager {
|
|||||||
// Counter to keep track of the consumed device IDs.
|
// Counter to keep track of the consumed device IDs.
|
||||||
device_id_cnt: Wrapping<usize>,
|
device_id_cnt: Wrapping<usize>,
|
||||||
|
|
||||||
pci_segment: PciSegment,
|
pci_segments: Vec<PciSegment>,
|
||||||
|
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
||||||
// MSI Interrupt Manager
|
// MSI Interrupt Manager
|
||||||
@ -961,11 +961,11 @@ impl DeviceManager {
|
|||||||
vfio_container: None,
|
vfio_container: None,
|
||||||
iommu_device: None,
|
iommu_device: None,
|
||||||
iommu_attached_devices: None,
|
iommu_attached_devices: None,
|
||||||
pci_segment: PciSegment::new_default_segment(
|
pci_segments: vec![PciSegment::new_default_segment(
|
||||||
&address_manager,
|
&address_manager,
|
||||||
start_of_device_area,
|
start_of_device_area,
|
||||||
end_of_device_area,
|
end_of_device_area,
|
||||||
)?,
|
)?],
|
||||||
device_tree,
|
device_tree,
|
||||||
exit_evt: exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
exit_evt: exit_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
reset_evt: reset_evt.try_clone().map_err(DeviceManagerError::EventFd)?,
|
||||||
@ -1189,12 +1189,13 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
self.bus_devices
|
self.bus_devices.push(
|
||||||
.push(Arc::clone(self.pci_segment.pci_config_io.as_ref().unwrap())
|
Arc::clone(self.pci_segments[0].pci_config_io.as_ref().unwrap())
|
||||||
as Arc<Mutex<dyn BusDevice>>);
|
as Arc<Mutex<dyn BusDevice>>,
|
||||||
|
);
|
||||||
|
|
||||||
self.bus_devices
|
self.bus_devices
|
||||||
.push(Arc::clone(&self.pci_segment.pci_config_mmio) as Arc<Mutex<dyn BusDevice>>);
|
.push(Arc::clone(&self.pci_segments[0].pci_config_mmio) as Arc<Mutex<dyn BusDevice>>);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -2803,7 +2804,7 @@ impl DeviceManager {
|
|||||||
&mut self,
|
&mut self,
|
||||||
device_cfg: &mut DeviceConfig,
|
device_cfg: &mut DeviceConfig,
|
||||||
) -> DeviceManagerResult<(u32, String)> {
|
) -> DeviceManagerResult<(u32, String)> {
|
||||||
let pci_device_bdf = self.pci_segment.next_device_bdf()?;
|
let pci_device_bdf = self.pci_segments[0].next_device_bdf()?;
|
||||||
|
|
||||||
let mut needs_dma_mapping = false;
|
let mut needs_dma_mapping = false;
|
||||||
|
|
||||||
@ -2884,7 +2885,7 @@ impl DeviceManager {
|
|||||||
Some(
|
Some(
|
||||||
legacy_interrupt_manager
|
legacy_interrupt_manager
|
||||||
.create_group(LegacyIrqGroupConfig {
|
.create_group(LegacyIrqGroupConfig {
|
||||||
irq: self.pci_segment.pci_irq_slots[(pci_device_bdf >> 3) as usize]
|
irq: self.pci_segments[0].pci_irq_slots[(pci_device_bdf >> 3) as usize]
|
||||||
as InterruptIndex,
|
as InterruptIndex,
|
||||||
})
|
})
|
||||||
.map_err(DeviceManagerError::CreateInterruptGroup)?,
|
.map_err(DeviceManagerError::CreateInterruptGroup)?,
|
||||||
@ -2963,7 +2964,7 @@ impl DeviceManager {
|
|||||||
.allocate_bars(&mut self.address_manager.allocator.lock().unwrap())
|
.allocate_bars(&mut self.address_manager.allocator.lock().unwrap())
|
||||||
.map_err(DeviceManagerError::AllocateBars)?;
|
.map_err(DeviceManagerError::AllocateBars)?;
|
||||||
|
|
||||||
let mut pci_bus = self.pci_segment.pci_bus.lock().unwrap();
|
let mut pci_bus = self.pci_segments[0].pci_bus.lock().unwrap();
|
||||||
|
|
||||||
pci_bus
|
pci_bus
|
||||||
.add_device(bdf, pci_device)
|
.add_device(bdf, pci_device)
|
||||||
@ -3007,14 +3008,14 @@ impl DeviceManager {
|
|||||||
&mut self,
|
&mut self,
|
||||||
device_cfg: &mut UserDeviceConfig,
|
device_cfg: &mut UserDeviceConfig,
|
||||||
) -> DeviceManagerResult<(u32, String)> {
|
) -> DeviceManagerResult<(u32, String)> {
|
||||||
let pci_device_bdf = self.pci_segment.next_device_bdf()?;
|
let pci_device_bdf = self.pci_segments[0].next_device_bdf()?;
|
||||||
|
|
||||||
let legacy_interrupt_group =
|
let legacy_interrupt_group =
|
||||||
if let Some(legacy_interrupt_manager) = &self.legacy_interrupt_manager {
|
if let Some(legacy_interrupt_manager) = &self.legacy_interrupt_manager {
|
||||||
Some(
|
Some(
|
||||||
legacy_interrupt_manager
|
legacy_interrupt_manager
|
||||||
.create_group(LegacyIrqGroupConfig {
|
.create_group(LegacyIrqGroupConfig {
|
||||||
irq: self.pci_segment.pci_irq_slots[(pci_device_bdf >> 3) as usize]
|
irq: self.pci_segments[0].pci_irq_slots[(pci_device_bdf >> 3) as usize]
|
||||||
as InterruptIndex,
|
as InterruptIndex,
|
||||||
})
|
})
|
||||||
.map_err(DeviceManagerError::CreateInterruptGroup)?,
|
.map_err(DeviceManagerError::CreateInterruptGroup)?,
|
||||||
@ -3132,7 +3133,7 @@ impl DeviceManager {
|
|||||||
.pci_bdf
|
.pci_bdf
|
||||||
.ok_or(DeviceManagerError::MissingDeviceNodePciBdf)?;
|
.ok_or(DeviceManagerError::MissingDeviceNodePciBdf)?;
|
||||||
|
|
||||||
self.pci_segment
|
self.pci_segments[0]
|
||||||
.pci_bus
|
.pci_bus
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -3155,7 +3156,7 @@ impl DeviceManager {
|
|||||||
|
|
||||||
(pci_device_bdf, config_bar_addr)
|
(pci_device_bdf, config_bar_addr)
|
||||||
} else {
|
} else {
|
||||||
let pci_device_bdf = self.pci_segment.next_device_bdf()?;
|
let pci_device_bdf = self.pci_segments[0].next_device_bdf()?;
|
||||||
|
|
||||||
(pci_device_bdf, None)
|
(pci_device_bdf, None)
|
||||||
};
|
};
|
||||||
@ -3259,7 +3260,7 @@ impl DeviceManager {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
// Used to provide a fast path for handling PIO exits
|
// Used to provide a fast path for handling PIO exits
|
||||||
pub fn pci_config_io(&self) -> Arc<Mutex<PciConfigIo>> {
|
pub fn pci_config_io(&self) -> Arc<Mutex<PciConfigIo>> {
|
||||||
Arc::clone(self.pci_segment.pci_config_io.as_ref().unwrap())
|
Arc::clone(self.pci_segments[0].pci_config_io.as_ref().unwrap())
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn console(&self) -> &Arc<Console> {
|
pub fn console(&self) -> &Arc<Console> {
|
||||||
@ -3355,7 +3356,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_segment.pci_devices_up |= 1 << (device_id >> 3);
|
self.pci_segments[0].pci_devices_up |= 1 << (device_id >> 3);
|
||||||
|
|
||||||
Ok(PciDeviceInfo {
|
Ok(PciDeviceInfo {
|
||||||
id: device_name,
|
id: device_name,
|
||||||
@ -3370,7 +3371,7 @@ impl DeviceManager {
|
|||||||
let (device_id, device_name) = self.add_vfio_user_device(device_cfg)?;
|
let (device_id, device_name) = self.add_vfio_user_device(device_cfg)?;
|
||||||
|
|
||||||
// Update the PCIU bitmap
|
// Update the PCIU bitmap
|
||||||
self.pci_segment.pci_devices_up |= 1 << (device_id >> 3);
|
self.pci_segments[0].pci_devices_up |= 1 << (device_id >> 3);
|
||||||
|
|
||||||
Ok(PciDeviceInfo {
|
Ok(PciDeviceInfo {
|
||||||
id: device_name,
|
id: device_name,
|
||||||
@ -3429,7 +3430,7 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Update the PCID bitmap
|
// Update the PCID bitmap
|
||||||
self.pci_segment.pci_devices_down |= 1 << (pci_device_bdf >> 3);
|
self.pci_segments[0].pci_devices_down |= 1 << (pci_device_bdf >> 3);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
@ -3439,7 +3440,7 @@ impl DeviceManager {
|
|||||||
let pci_device_bdf = (device_id as u32) << 3;
|
let pci_device_bdf = (device_id as u32) << 3;
|
||||||
|
|
||||||
// Give the PCI device ID back to the PCI bus.
|
// Give the PCI device ID back to the PCI bus.
|
||||||
self.pci_segment
|
self.pci_segments[0]
|
||||||
.pci_bus
|
.pci_bus
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -3514,7 +3515,7 @@ impl DeviceManager {
|
|||||||
.map_err(DeviceManagerError::FreePciBars)?;
|
.map_err(DeviceManagerError::FreePciBars)?;
|
||||||
|
|
||||||
// Remove the device from the PCI bus
|
// Remove the device from the PCI bus
|
||||||
self.pci_segment
|
self.pci_segments[0]
|
||||||
.pci_bus
|
.pci_bus
|
||||||
.lock()
|
.lock()
|
||||||
.unwrap()
|
.unwrap()
|
||||||
@ -3585,7 +3586,7 @@ impl DeviceManager {
|
|||||||
let device_id = self.add_virtio_pci_device(device, &None, id.clone())?;
|
let device_id = self.add_virtio_pci_device(device, &None, id.clone())?;
|
||||||
|
|
||||||
// Update the PCIU bitmap
|
// Update the PCIU bitmap
|
||||||
self.pci_segment.pci_devices_up |= 1 << (device_id >> 3);
|
self.pci_segments[0].pci_devices_up |= 1 << (device_id >> 3);
|
||||||
|
|
||||||
Ok(PciDeviceInfo { id, bdf: device_id })
|
Ok(PciDeviceInfo { id, bdf: device_id })
|
||||||
}
|
}
|
||||||
@ -3902,7 +3903,7 @@ impl Aml for DeviceManager {
|
|||||||
.unwrap()
|
.unwrap()
|
||||||
.to_aml_bytes();
|
.to_aml_bytes();
|
||||||
|
|
||||||
let pci_dsdt_data = self.pci_segment.to_aml_bytes();
|
let pci_dsdt_data = self.pci_segments[0].to_aml_bytes();
|
||||||
bytes.extend_from_slice(pci_dsdt_data.as_slice());
|
bytes.extend_from_slice(pci_dsdt_data.as_slice());
|
||||||
bytes.extend_from_slice(mbrd_dsdt_data.as_slice());
|
bytes.extend_from_slice(mbrd_dsdt_data.as_slice());
|
||||||
if self.config.lock().unwrap().serial.mode != ConsoleOutputMode::Off {
|
if self.config.lock().unwrap().serial.mode != ConsoleOutputMode::Off {
|
||||||
@ -4056,15 +4057,15 @@ impl BusDevice for DeviceManager {
|
|||||||
match offset {
|
match offset {
|
||||||
PCIU_FIELD_OFFSET => {
|
PCIU_FIELD_OFFSET => {
|
||||||
assert!(data.len() == PCIU_FIELD_SIZE);
|
assert!(data.len() == PCIU_FIELD_SIZE);
|
||||||
data.copy_from_slice(&self.pci_segment.pci_devices_up.to_le_bytes());
|
data.copy_from_slice(&self.pci_segments[0].pci_devices_up.to_le_bytes());
|
||||||
// Clear the PCIU bitmap
|
// Clear the PCIU bitmap
|
||||||
self.pci_segment.pci_devices_up = 0;
|
self.pci_segments[0].pci_devices_up = 0;
|
||||||
}
|
}
|
||||||
PCID_FIELD_OFFSET => {
|
PCID_FIELD_OFFSET => {
|
||||||
assert!(data.len() == PCID_FIELD_SIZE);
|
assert!(data.len() == PCID_FIELD_SIZE);
|
||||||
data.copy_from_slice(&self.pci_segment.pci_devices_down.to_le_bytes());
|
data.copy_from_slice(&self.pci_segments[0].pci_devices_down.to_le_bytes());
|
||||||
// Clear the PCID bitmap
|
// Clear the PCID bitmap
|
||||||
self.pci_segment.pci_devices_down = 0;
|
self.pci_segments[0].pci_devices_down = 0;
|
||||||
}
|
}
|
||||||
B0EJ_FIELD_OFFSET => {
|
B0EJ_FIELD_OFFSET => {
|
||||||
assert!(data.len() == B0EJ_FIELD_SIZE);
|
assert!(data.len() == B0EJ_FIELD_SIZE);
|
||||||
|
Loading…
Reference in New Issue
Block a user