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))]