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