mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-01-03 03:15:20 +00:00
pci: Move VfioCommon creation to a dedicated function
This is some preliminatory work for moving both VfioUser and Vfio to the new restore design. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
parent
559faa272a
commit
d6bf1f5eb0
@ -406,6 +406,53 @@ pub(crate) struct VfioCommon {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl VfioCommon {
|
impl VfioCommon {
|
||||||
|
pub(crate) fn new(
|
||||||
|
msi_interrupt_manager: Arc<dyn InterruptManager<GroupConfig = MsiIrqGroupConfig>>,
|
||||||
|
legacy_interrupt_group: Option<Arc<dyn InterruptSourceGroup>>,
|
||||||
|
vfio_wrapper: Arc<dyn Vfio>,
|
||||||
|
subclass: &dyn PciSubclass,
|
||||||
|
bdf: PciBdf,
|
||||||
|
restoring: bool,
|
||||||
|
) -> Result<Self, VfioPciError> {
|
||||||
|
let configuration = PciConfiguration::new(
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
PciClassCode::Other,
|
||||||
|
subclass,
|
||||||
|
None,
|
||||||
|
PciHeaderType::Device,
|
||||||
|
0,
|
||||||
|
0,
|
||||||
|
None,
|
||||||
|
None,
|
||||||
|
);
|
||||||
|
|
||||||
|
let mut vfio_common = VfioCommon {
|
||||||
|
mmio_regions: Vec::new(),
|
||||||
|
configuration,
|
||||||
|
interrupt: Interrupt {
|
||||||
|
intx: None,
|
||||||
|
msi: None,
|
||||||
|
msix: None,
|
||||||
|
},
|
||||||
|
msi_interrupt_manager,
|
||||||
|
legacy_interrupt_group,
|
||||||
|
vfio_wrapper,
|
||||||
|
patches: HashMap::new(),
|
||||||
|
};
|
||||||
|
|
||||||
|
// No need to parse capabilities from the device if on the restore path.
|
||||||
|
// The initialization will be performed later when restore() will be
|
||||||
|
// called.
|
||||||
|
if !restoring {
|
||||||
|
vfio_common.parse_capabilities(bdf);
|
||||||
|
vfio_common.initialize_legacy_interrupt()?;
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(vfio_common)
|
||||||
|
}
|
||||||
|
|
||||||
pub(crate) fn allocate_bars(
|
pub(crate) fn allocate_bars(
|
||||||
&mut self,
|
&mut self,
|
||||||
allocator: &Arc<Mutex<SystemAllocator>>,
|
allocator: &Arc<Mutex<SystemAllocator>>,
|
||||||
@ -1226,43 +1273,16 @@ impl VfioPciDevice {
|
|||||||
let device = Arc::new(device);
|
let device = Arc::new(device);
|
||||||
device.reset();
|
device.reset();
|
||||||
|
|
||||||
let configuration = PciConfiguration::new(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
PciClassCode::Other,
|
|
||||||
&PciVfioSubclass::VfioSubclass,
|
|
||||||
None,
|
|
||||||
PciHeaderType::Device,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
|
|
||||||
let vfio_wrapper = VfioDeviceWrapper::new(Arc::clone(&device));
|
let vfio_wrapper = VfioDeviceWrapper::new(Arc::clone(&device));
|
||||||
|
|
||||||
let mut common = VfioCommon {
|
let common = VfioCommon::new(
|
||||||
mmio_regions: Vec::new(),
|
|
||||||
configuration,
|
|
||||||
interrupt: Interrupt {
|
|
||||||
intx: None,
|
|
||||||
msi: None,
|
|
||||||
msix: None,
|
|
||||||
},
|
|
||||||
msi_interrupt_manager,
|
msi_interrupt_manager,
|
||||||
legacy_interrupt_group,
|
legacy_interrupt_group,
|
||||||
vfio_wrapper: Arc::new(vfio_wrapper) as Arc<dyn Vfio>,
|
Arc::new(vfio_wrapper) as Arc<dyn Vfio>,
|
||||||
patches: HashMap::new(),
|
&PciVfioSubclass::VfioSubclass,
|
||||||
};
|
bdf,
|
||||||
|
restoring,
|
||||||
// No need to parse capabilities from the device if on the restore path.
|
)?;
|
||||||
// The initialization will be performed later when restore() will be
|
|
||||||
// called.
|
|
||||||
if !restoring {
|
|
||||||
common.parse_capabilities(bdf);
|
|
||||||
common.initialize_legacy_interrupt()?;
|
|
||||||
}
|
|
||||||
|
|
||||||
let vfio_pci_device = VfioPciDevice {
|
let vfio_pci_device = VfioPciDevice {
|
||||||
id,
|
id,
|
||||||
|
@ -3,15 +3,12 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
//
|
//
|
||||||
|
|
||||||
use crate::vfio::{Interrupt, UserMemoryRegion, Vfio, VfioCommon, VfioError};
|
use crate::vfio::{UserMemoryRegion, Vfio, VfioCommon, VfioError};
|
||||||
use crate::{BarReprogrammingParams, PciBarConfiguration, VfioPciError};
|
use crate::{BarReprogrammingParams, PciBarConfiguration, VfioPciError};
|
||||||
use crate::{
|
use crate::{PciBdf, PciDevice, PciDeviceError, PciSubclass};
|
||||||
PciBdf, PciClassCode, PciConfiguration, PciDevice, PciDeviceError, PciHeaderType, PciSubclass,
|
|
||||||
};
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use hypervisor::HypervisorVmError;
|
use hypervisor::HypervisorVmError;
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
|
||||||
use std::os::unix::prelude::AsRawFd;
|
use std::os::unix::prelude::AsRawFd;
|
||||||
use std::ptr::null_mut;
|
use std::ptr::null_mut;
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
@ -51,6 +48,8 @@ pub enum VfioUserPciDeviceError {
|
|||||||
DmaUnmap(#[source] VfioUserError),
|
DmaUnmap(#[source] VfioUserError),
|
||||||
#[error("Failed to initialize legacy interrupts: {0}")]
|
#[error("Failed to initialize legacy interrupts: {0}")]
|
||||||
InitializeLegacyInterrupts(#[source] VfioPciError),
|
InitializeLegacyInterrupts(#[source] VfioPciError),
|
||||||
|
#[error("Failed to create VfioCommon: {0}")]
|
||||||
|
CreateVfioCommon(#[source] VfioPciError),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone)]
|
#[derive(Copy, Clone)]
|
||||||
@ -76,20 +75,6 @@ impl VfioUserPciDevice {
|
|||||||
restoring: bool,
|
restoring: bool,
|
||||||
memory_slot: Arc<dyn Fn() -> u32 + Send + Sync>,
|
memory_slot: Arc<dyn Fn() -> u32 + Send + Sync>,
|
||||||
) -> Result<Self, VfioUserPciDeviceError> {
|
) -> Result<Self, VfioUserPciDeviceError> {
|
||||||
// This is used for the BAR and capabilities only
|
|
||||||
let configuration = PciConfiguration::new(
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
PciClassCode::Other,
|
|
||||||
&PciVfioUserSubclass::VfioUserSubclass,
|
|
||||||
None,
|
|
||||||
PciHeaderType::Device,
|
|
||||||
0,
|
|
||||||
0,
|
|
||||||
None,
|
|
||||||
None,
|
|
||||||
);
|
|
||||||
let resettable = client.lock().unwrap().resettable();
|
let resettable = client.lock().unwrap().resettable();
|
||||||
if resettable {
|
if resettable {
|
||||||
client
|
client
|
||||||
@ -103,29 +88,15 @@ impl VfioUserPciDevice {
|
|||||||
client: client.clone(),
|
client: client.clone(),
|
||||||
};
|
};
|
||||||
|
|
||||||
let mut common = VfioCommon {
|
let common = VfioCommon::new(
|
||||||
mmio_regions: Vec::new(),
|
|
||||||
configuration,
|
|
||||||
interrupt: Interrupt {
|
|
||||||
intx: None,
|
|
||||||
msi: None,
|
|
||||||
msix: None,
|
|
||||||
},
|
|
||||||
msi_interrupt_manager,
|
msi_interrupt_manager,
|
||||||
legacy_interrupt_group,
|
legacy_interrupt_group,
|
||||||
vfio_wrapper: Arc::new(vfio_wrapper) as Arc<dyn Vfio>,
|
Arc::new(vfio_wrapper) as Arc<dyn Vfio>,
|
||||||
patches: HashMap::new(),
|
&PciVfioUserSubclass::VfioUserSubclass,
|
||||||
};
|
bdf,
|
||||||
|
restoring,
|
||||||
// No need to parse capabilities from the device if on the restore path.
|
)
|
||||||
// The initialization will be performed later when restore() will be
|
.map_err(VfioUserPciDeviceError::CreateVfioCommon)?;
|
||||||
// called.
|
|
||||||
if !restoring {
|
|
||||||
common.parse_capabilities(bdf);
|
|
||||||
common
|
|
||||||
.initialize_legacy_interrupt()
|
|
||||||
.map_err(VfioUserPciDeviceError::InitializeLegacyInterrupts)?;
|
|
||||||
}
|
|
||||||
|
|
||||||
Ok(Self {
|
Ok(Self {
|
||||||
id,
|
id,
|
||||||
|
Loading…
Reference in New Issue
Block a user