mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-22 21:55:20 +00:00
build: make PCI (virtio and vfio) disableable at build time
Although included by default it is now possible to build without PCI support. Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
parent
6d27ac9dfc
commit
c042483953
@ -18,8 +18,9 @@ tempdir= "0.3.7"
|
||||
lazy_static= "1.4.0"
|
||||
|
||||
[features]
|
||||
default = ["acpi"]
|
||||
default = ["acpi", "pci"]
|
||||
acpi = ["vmm/acpi"]
|
||||
pci = ["vmm/pci_support"]
|
||||
|
||||
# Integration tests require a special environment to run in
|
||||
integration_tests = []
|
||||
|
@ -4,6 +4,10 @@ version = "0.1.0"
|
||||
authors = ["Samuel Ortiz <sameo@linux.intel.com>"]
|
||||
edition = "2018"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
pci_support = ["pci"]
|
||||
|
||||
[dependencies]
|
||||
byteorder = "1.3.2"
|
||||
devices = { path = "../devices" }
|
||||
@ -12,7 +16,7 @@ libc = "0.2.60"
|
||||
log = "0.4.8"
|
||||
net_gen = { path = "../net_gen" }
|
||||
net_util = { path = "../net_util" }
|
||||
pci = { path = "../pci" }
|
||||
pci = { path = "../pci", optional = true }
|
||||
tempfile = "3.1.0"
|
||||
virtio-bindings = { path = "../virtio-bindings" }
|
||||
vm-allocator = { path = "../vm-allocator" }
|
||||
|
@ -12,6 +12,7 @@
|
||||
extern crate epoll;
|
||||
#[macro_use]
|
||||
extern crate log;
|
||||
#[cfg(feature = "pci_support")]
|
||||
extern crate pci;
|
||||
extern crate vhost_rs;
|
||||
extern crate virtio_bindings;
|
||||
|
@ -2,8 +2,11 @@
|
||||
//
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#[cfg(feature = "pci_support")]
|
||||
mod pci_common_config;
|
||||
#[cfg(feature = "pci_support")]
|
||||
mod pci_device;
|
||||
|
||||
#[cfg(feature = "pci_support")]
|
||||
pub use pci_common_config::VirtioPciCommonConfig;
|
||||
#[cfg(feature = "pci_support")]
|
||||
pub use pci_device::VirtioPciDevice;
|
||||
|
@ -7,6 +7,7 @@
|
||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||
|
||||
extern crate devices;
|
||||
#[cfg(feature = "pci_support")]
|
||||
extern crate pci;
|
||||
extern crate vm_allocator;
|
||||
extern crate vm_memory;
|
||||
|
@ -7,6 +7,7 @@ edition = "2018"
|
||||
[features]
|
||||
default = []
|
||||
acpi = ["acpi_tables","devices/acpi", "arch/acpi"]
|
||||
pci_support = ["pci", "vfio", "vm-virtio/pci_support"]
|
||||
|
||||
[dependencies]
|
||||
acpi_tables = { path = "../acpi_tables", optional = true }
|
||||
@ -18,9 +19,9 @@ kvm-ioctls = { git = "https://github.com/rust-vmm/kvm-ioctls", branch = "master"
|
||||
libc = "0.2.62"
|
||||
log = "0.4.8"
|
||||
net_util = { path = "../net_util" }
|
||||
pci = {path = "../pci"}
|
||||
pci = {path = "../pci", optional = true}
|
||||
qcow = { path = "../qcow" }
|
||||
vfio = { path = "../vfio" }
|
||||
vfio = { path = "../vfio", optional = true }
|
||||
vm-virtio = { path = "../vm-virtio" }
|
||||
vm-allocator = { path = "../vm-allocator" }
|
||||
vmm-sys-util = { git = "https://github.com/rust-vmm/vmm-sys-util" }
|
||||
|
@ -19,6 +19,7 @@ use libc::O_TMPFILE;
|
||||
use libc::{EFD_NONBLOCK, TIOCGWINSZ};
|
||||
|
||||
use net_util::Tap;
|
||||
#[cfg(feature = "pci_support")]
|
||||
use pci::{
|
||||
InterruptDelivery, InterruptParameters, PciConfigIo, PciDevice, PciInterruptPin, PciRoot,
|
||||
};
|
||||
@ -32,9 +33,11 @@ use std::os::unix::io::AsRawFd;
|
||||
use std::ptr::null_mut;
|
||||
use std::result;
|
||||
use std::sync::{Arc, Mutex, RwLock};
|
||||
#[cfg(feature = "pci_support")]
|
||||
use vfio::{VfioDevice, VfioPciDevice, VfioPciError};
|
||||
use vm_allocator::SystemAllocator;
|
||||
use vm_memory::{Address, GuestMemoryMmap, GuestUsize};
|
||||
#[cfg(feature = "pci_support")]
|
||||
use vm_virtio::transport::VirtioPciDevice;
|
||||
use vm_virtio::{VirtioSharedMemory, VirtioSharedMemoryList};
|
||||
use vmm_sys_util::eventfd::EventFd;
|
||||
@ -98,6 +101,7 @@ pub enum DeviceManagerError {
|
||||
Irq(io::Error),
|
||||
|
||||
/// Cannot allocate PCI BARs
|
||||
#[cfg(feature = "pci_support")]
|
||||
AllocateBars(pci::PciDeviceError),
|
||||
|
||||
/// Cannot register ioevent.
|
||||
@ -107,6 +111,7 @@ pub enum DeviceManagerError {
|
||||
VirtioDevice(vmm_sys_util::errno::Error),
|
||||
|
||||
/// Cannot add PCI device
|
||||
#[cfg(feature = "pci_support")]
|
||||
AddPciDevice(pci::PciRootError),
|
||||
|
||||
/// Cannot open persistent memory file
|
||||
@ -128,12 +133,15 @@ pub enum DeviceManagerError {
|
||||
ConsoleOutputFileOpen(io::Error),
|
||||
|
||||
/// Cannot create a VFIO device
|
||||
#[cfg(feature = "pci_support")]
|
||||
VfioCreate(vfio::VfioError),
|
||||
|
||||
/// Cannot create a VFIO PCI device
|
||||
#[cfg(feature = "pci_support")]
|
||||
VfioPciCreate(vfio::VfioPciError),
|
||||
|
||||
/// Failed to map VFIO MMIO region.
|
||||
#[cfg(feature = "pci_support")]
|
||||
VfioMapRegion(VfioPciError),
|
||||
|
||||
/// Failed to create the KVM device.
|
||||
@ -272,9 +280,6 @@ pub struct DeviceManager {
|
||||
// IOAPIC
|
||||
ioapic: Option<Arc<Mutex<ioapic::Ioapic>>>,
|
||||
|
||||
// PCI root
|
||||
pci: Arc<Mutex<PciConfigIo>>,
|
||||
|
||||
// mmap()ed region to unmap on drop
|
||||
mmap_regions: Vec<(*mut libc::c_void, usize)>,
|
||||
|
||||
@ -395,8 +400,11 @@ impl DeviceManager {
|
||||
&mut mmap_regions,
|
||||
)?);
|
||||
|
||||
#[allow(unused_mut)]
|
||||
let mut cmdline_additions = Vec::new();
|
||||
|
||||
#[cfg(feature = "pci_support")]
|
||||
{
|
||||
let pci_root = PciRoot::new(None);
|
||||
let mut pci = PciConfigIo::new(pci_root);
|
||||
|
||||
@ -413,8 +421,12 @@ impl DeviceManager {
|
||||
}
|
||||
|
||||
DeviceManager::add_vfio_devices(vm_info, allocator, &mut pci, &mut buses, mem_slots)?;
|
||||
|
||||
let pci = Arc::new(Mutex::new(pci));
|
||||
io_bus
|
||||
.insert(pci, 0xcf8, 0x8)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
}
|
||||
|
||||
|
||||
let mut dm = DeviceManager {
|
||||
io_bus,
|
||||
@ -424,7 +436,6 @@ impl DeviceManager {
|
||||
#[cfg(feature = "acpi")]
|
||||
acpi_device,
|
||||
ioapic,
|
||||
pci,
|
||||
mmap_regions,
|
||||
cmdline_additions,
|
||||
};
|
||||
@ -767,6 +778,7 @@ impl DeviceManager {
|
||||
.map_err(DeviceManagerError::CreateKvmDevice)
|
||||
}
|
||||
|
||||
#[cfg(feature = "pci_support")]
|
||||
fn add_vfio_devices(
|
||||
vm_info: &VmInfo,
|
||||
allocator: &mut SystemAllocator,
|
||||
@ -808,6 +820,7 @@ impl DeviceManager {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[cfg(feature = "pci_support")]
|
||||
fn add_virtio_pci_device(
|
||||
virtio_device: Box<dyn vm_virtio::VirtioDevice>,
|
||||
memory: &Arc<RwLock<GuestMemoryMmap>>,
|
||||
@ -939,11 +952,6 @@ impl DeviceManager {
|
||||
.insert(self.acpi_device.clone(), 0x3c0, 0x4)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
|
||||
// Insert the PCI root configuration space.
|
||||
self.io_bus
|
||||
.insert(self.pci.clone(), 0xcf8, 0x8)
|
||||
.map_err(DeviceManagerError::BusError)?;
|
||||
|
||||
if let Some(ioapic) = &self.ioapic {
|
||||
// Insert IOAPIC
|
||||
self.mmio_bus
|
||||
|
@ -17,6 +17,7 @@ extern crate libc;
|
||||
extern crate linux_loader;
|
||||
extern crate net_util;
|
||||
extern crate signal_hook;
|
||||
#[cfg(feature = "pci_support")]
|
||||
extern crate vfio;
|
||||
extern crate vm_allocator;
|
||||
extern crate vm_memory;
|
||||
|
Loading…
Reference in New Issue
Block a user