devices, vm-device: Move BusDevice and Bus into vm-device

This removes the dependency of the pci crate on the devices crate which
now only contains the device implementations themselves.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford
2020-09-09 15:30:31 +01:00
parent f24a12913a
commit 15025d71b1
22 changed files with 56 additions and 95 deletions

View File

@@ -27,19 +27,18 @@ use arch::x86_64::SgxEpcSection;
use arch::EntryPoint;
#[cfg(target_arch = "x86_64")]
use arch::{CpuidPatch, CpuidReg};
use devices::{interrupt_controller::InterruptController, BusDevice};
use devices::interrupt_controller::InterruptController;
#[cfg(target_arch = "x86_64")]
use hypervisor::CpuId;
use hypervisor::{CpuState, VmExit};
use libc::{c_void, siginfo_t};
#[cfg(target_arch = "x86_64")]
use std::fmt;
use std::os::unix::thread::JoinHandleExt;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, Barrier, Mutex};
use std::{cmp, io, result, thread};
use vm_device::{Bus, BusDevice};
#[cfg(target_arch = "x86_64")]
use vm_memory::GuestAddress;
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
@@ -129,7 +128,7 @@ pub enum Error {
ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
/// Cannot add legacy device to Bus.
BusError(devices::BusError),
BusError(vm_device::BusError),
/// Failed to allocate IO port
AllocateIOPort,
@@ -234,8 +233,8 @@ pub struct Vcpu {
vcpu: Arc<dyn hypervisor::Vcpu>,
id: u8,
#[cfg(target_arch = "x86_64")]
io_bus: Arc<devices::Bus>,
mmio_bus: Arc<devices::Bus>,
io_bus: Arc<Bus>,
mmio_bus: Arc<Bus>,
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
@@ -255,8 +254,8 @@ impl Vcpu {
pub fn new(
id: u8,
vm: &Arc<dyn hypervisor::Vm>,
#[cfg(target_arch = "x86_64")] io_bus: Arc<devices::Bus>,
mmio_bus: Arc<devices::Bus>,
#[cfg(target_arch = "x86_64")] io_bus: Arc<Bus>,
mmio_bus: Arc<Bus>,
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
creation_ts: std::time::Instant,
) -> Result<Arc<Mutex<Self>>> {
@@ -322,7 +321,7 @@ impl Vcpu {
#[cfg(target_arch = "x86_64")]
VmExit::IoIn(addr, data) => {
if let Err(e) = self.io_bus.read(u64::from(addr), data) {
if let devices::BusError::MissingAddressRange = e {
if let vm_device::BusError::MissingAddressRange = e {
warn!("Guest PIO read to unregistered address 0x{:x}", addr);
}
}
@@ -334,7 +333,7 @@ impl Vcpu {
self.log_debug_ioport(data[0]);
}
if let Err(e) = self.io_bus.write(u64::from(addr), data) {
if let devices::BusError::MissingAddressRange = e {
if let vm_device::BusError::MissingAddressRange = e {
warn!("Guest PIO write to unregistered address 0x{:x}", addr);
}
}
@@ -342,7 +341,7 @@ impl Vcpu {
}
VmExit::MmioRead(addr, data) => {
if let Err(e) = self.mmio_bus.read(addr as u64, data) {
if let devices::BusError::MissingAddressRange = e {
if let vm_device::BusError::MissingAddressRange = e {
warn!("Guest MMIO read to unregistered address 0x{:x}", addr);
}
}
@@ -350,7 +349,7 @@ impl Vcpu {
}
VmExit::MmioWrite(addr, data) => {
if let Err(e) = self.mmio_bus.write(addr as u64, data) {
if let devices::BusError::MissingAddressRange = e {
if let vm_device::BusError::MissingAddressRange = e {
warn!("Guest MMIO write to unregistered address 0x{:x}", addr);
}
}
@@ -458,9 +457,9 @@ impl Snapshottable for Vcpu {
pub struct CpuManager {
config: CpusConfig,
#[cfg(target_arch = "x86_64")]
io_bus: Arc<devices::Bus>,
io_bus: Arc<Bus>,
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
mmio_bus: Arc<devices::Bus>,
mmio_bus: Arc<Bus>,
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]

View File

@@ -39,7 +39,7 @@ use devices::gic;
#[cfg(target_arch = "x86_64")]
use devices::ioapic;
use devices::{
interrupt_controller, interrupt_controller::InterruptController, legacy::Serial, BusDevice,
interrupt_controller, interrupt_controller::InterruptController, legacy::Serial,
HotPlugNotificationFlags,
};
use hypervisor::kvm_ioctls;
@@ -81,7 +81,7 @@ use vm_allocator::SystemAllocator;
use vm_device::interrupt::{
InterruptIndex, InterruptManager, LegacyIrqGroupConfig, MsiIrqGroupConfig,
};
use vm_device::Resource;
use vm_device::{Bus, BusDevice, Resource};
use vm_memory::guest_memory::FileOffset;
use vm_memory::{
Address, GuestAddress, GuestAddressSpace, GuestRegionMmap, GuestUsize, MmapRegion,
@@ -249,7 +249,7 @@ pub enum DeviceManagerError {
Mmap(io::Error),
/// Cannot add legacy device to Bus.
BusError(devices::BusError),
BusError(vm_device::BusError),
/// Failed to allocate IO port
AllocateIOPort,
@@ -298,10 +298,10 @@ pub enum DeviceManagerError {
RemoveDeviceFromPciBus(pci::PciRootError),
/// Failed removing a bus device from the IO bus.
RemoveDeviceFromIoBus(devices::BusError),
RemoveDeviceFromIoBus(vm_device::BusError),
/// Failed removing a bus device from the MMIO bus.
RemoveDeviceFromMmioBus(devices::BusError),
RemoveDeviceFromMmioBus(vm_device::BusError),
/// Failed to find the device corresponding to a specific PCI b/d/f.
#[cfg(feature = "pci_support")]
@@ -459,8 +459,8 @@ impl Console {
struct AddressManager {
allocator: Arc<Mutex<SystemAllocator>>,
#[cfg(target_arch = "x86_64")]
io_bus: Arc<devices::Bus>,
mmio_bus: Arc<devices::Bus>,
io_bus: Arc<Bus>,
mmio_bus: Arc<Bus>,
vm: Arc<dyn hypervisor::Vm>,
#[cfg(feature = "pci_support")]
device_tree: Arc<Mutex<DeviceTree>>,
@@ -822,8 +822,8 @@ impl DeviceManager {
let address_manager = Arc::new(AddressManager {
allocator: memory_manager.lock().unwrap().allocator(),
#[cfg(target_arch = "x86_64")]
io_bus: Arc::new(devices::Bus::new()),
mmio_bus: Arc::new(devices::Bus::new()),
io_bus: Arc::new(Bus::new()),
mmio_bus: Arc::new(Bus::new()),
vm: vm.clone(),
#[cfg(feature = "pci_support")]
device_tree: Arc::clone(&device_tree),
@@ -2998,11 +2998,11 @@ impl DeviceManager {
}
#[cfg(target_arch = "x86_64")]
pub fn io_bus(&self) -> &Arc<devices::Bus> {
pub fn io_bus(&self) -> &Arc<Bus> {
&self.address_manager.io_bus
}
pub fn mmio_bus(&self) -> &Arc<devices::Bus> {
pub fn mmio_bus(&self) -> &Arc<Bus> {
&self.address_manager.mmio_bus
}

View File

@@ -15,8 +15,6 @@ use arch::x86_64::{SgxEpcRegion, SgxEpcSection};
use arch::{get_host_cpu_phys_bits, layout, RegionType};
#[cfg(target_arch = "x86_64")]
use devices::ioapic;
use devices::BusDevice;
#[cfg(target_arch = "x86_64")]
use libc::{MAP_NORESERVE, MAP_POPULATE, MAP_SHARED, PROT_READ, PROT_WRITE};
use std::collections::HashMap;
@@ -33,6 +31,7 @@ use url::Url;
#[cfg(target_arch = "x86_64")]
use vm_allocator::GsiApic;
use vm_allocator::SystemAllocator;
use vm_device::BusDevice;
use vm_memory::guest_memory::FileOffset;
use vm_memory::{
mmap::MmapRegionError, Address, Bytes, Error as MmapError, GuestAddress, GuestAddressSpace,