mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2025-03-20 07:58:55 +00:00
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:
parent
f24a12913a
commit
15025d71b1
2
Cargo.lock
generated
2
Cargo.lock
generated
@ -742,7 +742,6 @@ version = "0.1.0"
|
|||||||
dependencies = [
|
dependencies = [
|
||||||
"anyhow",
|
"anyhow",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"devices",
|
|
||||||
"hypervisor",
|
"hypervisor",
|
||||||
"libc",
|
"libc",
|
||||||
"log 0.4.11",
|
"log 0.4.11",
|
||||||
@ -1525,7 +1524,6 @@ dependencies = [
|
|||||||
"arc-swap",
|
"arc-swap",
|
||||||
"block_util",
|
"block_util",
|
||||||
"byteorder",
|
"byteorder",
|
||||||
"devices",
|
|
||||||
"epoll",
|
"epoll",
|
||||||
"io-uring",
|
"io-uring",
|
||||||
"libc",
|
"libc",
|
||||||
|
@ -7,8 +7,8 @@ use acpi_tables::{aml, aml::Aml};
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
use BusDevice;
|
|
||||||
use HotPlugNotificationFlags;
|
use HotPlugNotificationFlags;
|
||||||
|
|
||||||
/// A device for handling ACPI shutdown and reboot
|
/// A device for handling ACPI shutdown and reboot
|
||||||
|
@ -10,7 +10,6 @@
|
|||||||
// See https://pdos.csail.mit.edu/6.828/2016/readings/ia32/ioapic.pdf for a specification.
|
// See https://pdos.csail.mit.edu/6.828/2016/readings/ia32/ioapic.pdf for a specification.
|
||||||
|
|
||||||
use super::interrupt_controller::{Error, InterruptController};
|
use super::interrupt_controller::{Error, InterruptController};
|
||||||
use crate::BusDevice;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use std::result;
|
use std::result;
|
||||||
@ -19,6 +18,7 @@ use vm_device::interrupt::{
|
|||||||
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
|
InterruptIndex, InterruptManager, InterruptSourceConfig, InterruptSourceGroup,
|
||||||
MsiIrqGroupConfig, MsiIrqSourceConfig,
|
MsiIrqGroupConfig, MsiIrqSourceConfig,
|
||||||
};
|
};
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_memory::GuestAddress;
|
use vm_memory::GuestAddress;
|
||||||
use vm_migration::{
|
use vm_migration::{
|
||||||
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
||||||
|
@ -5,8 +5,7 @@
|
|||||||
use libc::{clock_gettime, gmtime_r, time_t, timespec, tm, CLOCK_REALTIME};
|
use libc::{clock_gettime, gmtime_r, time_t, timespec, tm, CLOCK_REALTIME};
|
||||||
use std::cmp::min;
|
use std::cmp::min;
|
||||||
use std::mem;
|
use std::mem;
|
||||||
|
use vm_device::BusDevice;
|
||||||
use crate::BusDevice;
|
|
||||||
|
|
||||||
const INDEX_MASK: u8 = 0x7f;
|
const INDEX_MASK: u8 = 0x7f;
|
||||||
const INDEX_OFFSET: u64 = 0x0;
|
const INDEX_OFFSET: u64 = 0x0;
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
//
|
//
|
||||||
|
|
||||||
use BusDevice;
|
use vm_device::BusDevice;
|
||||||
|
|
||||||
/// Provides firmware debug output via I/O port controls
|
/// Provides firmware debug output via I/O port controls
|
||||||
#[derive(Default)]
|
#[derive(Default)]
|
||||||
|
@ -4,7 +4,7 @@
|
|||||||
|
|
||||||
use vmm_sys_util::eventfd::EventFd;
|
use vmm_sys_util::eventfd::EventFd;
|
||||||
|
|
||||||
use BusDevice;
|
use vm_device::BusDevice;
|
||||||
|
|
||||||
/// A i8042 PS/2 controller that emulates just enough to shutdown the machine.
|
/// A i8042 PS/2 controller that emulates just enough to shutdown the machine.
|
||||||
pub struct I8042Device {
|
pub struct I8042Device {
|
||||||
|
@ -12,9 +12,8 @@ use std::fmt;
|
|||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::time::Instant;
|
use std::time::Instant;
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
|
|
||||||
use crate::BusDevice;
|
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
|
use vm_device::BusDevice;
|
||||||
|
|
||||||
// As you can see in https://static.docs.arm.com/ddi0224/c/real_time_clock_pl031_r1p3_technical_reference_manual_DDI0224C.pdf
|
// As you can see in https://static.docs.arm.com/ddi0224/c/real_time_clock_pl031_r1p3_technical_reference_manual_DDI0224C.pdf
|
||||||
// at section 3.2 Summary of RTC registers, the total size occupied by this device is 0x000 -> 0xFFC + 4 = 0x1000.
|
// at section 3.2 Summary of RTC registers, the total size occupied by this device is 0x000 -> 0xFFC + 4 = 0x1000.
|
||||||
|
@ -5,12 +5,12 @@
|
|||||||
// Use of this source code is governed by a BSD-style license that can be
|
// Use of this source code is governed by a BSD-style license that can be
|
||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
|
|
||||||
use crate::BusDevice;
|
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
use std::{io, result};
|
use std::{io, result};
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_migration::{
|
use vm_migration::{
|
||||||
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
||||||
Transportable,
|
Transportable,
|
||||||
|
@ -25,12 +25,8 @@ extern crate vmm_sys_util;
|
|||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate serde_json;
|
extern crate serde_json;
|
||||||
|
|
||||||
use std::fs::File;
|
|
||||||
use std::io;
|
|
||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
mod acpi;
|
mod acpi;
|
||||||
mod bus;
|
|
||||||
#[cfg(target_arch = "aarch64")]
|
#[cfg(target_arch = "aarch64")]
|
||||||
pub mod gic;
|
pub mod gic;
|
||||||
pub mod interrupt_controller;
|
pub mod interrupt_controller;
|
||||||
@ -40,45 +36,6 @@ pub mod legacy;
|
|||||||
|
|
||||||
#[cfg(feature = "acpi")]
|
#[cfg(feature = "acpi")]
|
||||||
pub use self::acpi::{AcpiGEDDevice, AcpiPMTimerDevice, AcpiShutdownDevice};
|
pub use self::acpi::{AcpiGEDDevice, AcpiPMTimerDevice, AcpiShutdownDevice};
|
||||||
pub use self::bus::{Bus, BusDevice, Error as BusError};
|
|
||||||
|
|
||||||
pub type DeviceEventT = u16;
|
|
||||||
|
|
||||||
/// The payload is used to handle events where the internal state of the VirtIO device
|
|
||||||
/// needs to be changed.
|
|
||||||
pub enum EpollHandlerPayload {
|
|
||||||
/// DrivePayload(disk_image)
|
|
||||||
DrivePayload(File),
|
|
||||||
/// Events that do not need a payload.
|
|
||||||
Empty,
|
|
||||||
}
|
|
||||||
|
|
||||||
type Result<T> = std::result::Result<T, Error>;
|
|
||||||
|
|
||||||
pub trait EpollHandler: Send {
|
|
||||||
fn handle_event(
|
|
||||||
&mut self,
|
|
||||||
device_event: DeviceEventT,
|
|
||||||
event_flags: u32,
|
|
||||||
payload: EpollHandlerPayload,
|
|
||||||
) -> Result<()>;
|
|
||||||
}
|
|
||||||
|
|
||||||
#[derive(Debug)]
|
|
||||||
pub enum Error {
|
|
||||||
FailedReadingQueue {
|
|
||||||
event_type: &'static str,
|
|
||||||
underlying: io::Error,
|
|
||||||
},
|
|
||||||
FailedReadTap,
|
|
||||||
FailedSignalingUsedQueue(io::Error),
|
|
||||||
PayloadExpected,
|
|
||||||
UnknownEvent {
|
|
||||||
device: &'static str,
|
|
||||||
event: DeviceEventT,
|
|
||||||
},
|
|
||||||
IoError(io::Error),
|
|
||||||
}
|
|
||||||
|
|
||||||
bitflags! {
|
bitflags! {
|
||||||
pub struct HotPlugNotificationFlags: u8 {
|
pub struct HotPlugNotificationFlags: u8 {
|
||||||
|
@ -7,7 +7,6 @@ edition = "2018"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
anyhow = "1.0"
|
anyhow = "1.0"
|
||||||
byteorder = "1.3.4"
|
byteorder = "1.3.4"
|
||||||
devices = { path = "../devices" }
|
|
||||||
hypervisor = { path = "../hypervisor" }
|
hypervisor = { path = "../hypervisor" }
|
||||||
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
|
vfio-ioctls = { git = "https://github.com/cloud-hypervisor/vfio-ioctls", branch = "ch" }
|
||||||
vmm-sys-util = ">=0.3.1"
|
vmm-sys-util = ">=0.3.1"
|
||||||
|
@ -7,11 +7,11 @@ use crate::configuration::{
|
|||||||
};
|
};
|
||||||
use crate::device::{DeviceRelocation, Error as PciDeviceError, PciDevice};
|
use crate::device::{DeviceRelocation, Error as PciDeviceError, PciDevice};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use devices::BusDevice;
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::ops::DerefMut;
|
use std::ops::DerefMut;
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
|
use vm_device::{Bus, BusDevice};
|
||||||
use vm_memory::{Address, GuestAddress, GuestUsize};
|
use vm_memory::{Address, GuestAddress, GuestUsize};
|
||||||
|
|
||||||
const VENDOR_ID_INTEL: u16 = 0x8086;
|
const VENDOR_ID_INTEL: u16 = 0x8086;
|
||||||
@ -26,9 +26,9 @@ pub enum PciRootError {
|
|||||||
/// Could not allocate an IRQ number.
|
/// Could not allocate an IRQ number.
|
||||||
AllocateIrq,
|
AllocateIrq,
|
||||||
/// Could not add a device to the port io bus.
|
/// Could not add a device to the port io bus.
|
||||||
PioInsert(devices::BusError),
|
PioInsert(vm_device::BusError),
|
||||||
/// Could not add a device to the mmio bus.
|
/// Could not add a device to the mmio bus.
|
||||||
MmioInsert(devices::BusError),
|
MmioInsert(vm_device::BusError),
|
||||||
/// Could not find an available device slot on the PCI bus.
|
/// Could not find an available device slot on the PCI bus.
|
||||||
NoPciDeviceSlotAvailable,
|
NoPciDeviceSlotAvailable,
|
||||||
/// Invalid PCI device identifier provided.
|
/// Invalid PCI device identifier provided.
|
||||||
@ -110,8 +110,8 @@ impl PciBus {
|
|||||||
pub fn register_mapping(
|
pub fn register_mapping(
|
||||||
&self,
|
&self,
|
||||||
dev: Arc<Mutex<dyn BusDevice>>,
|
dev: Arc<Mutex<dyn BusDevice>>,
|
||||||
#[cfg(target_arch = "x86_64")] io_bus: &devices::Bus,
|
#[cfg(target_arch = "x86_64")] io_bus: &Bus,
|
||||||
mmio_bus: &devices::Bus,
|
mmio_bus: &Bus,
|
||||||
bars: Vec<(GuestAddress, GuestUsize, PciBarRegionType)>,
|
bars: Vec<(GuestAddress, GuestUsize, PciBarRegionType)>,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
for (address, size, type_) in bars {
|
for (address, size, type_) in bars {
|
||||||
|
@ -3,11 +3,11 @@
|
|||||||
// found in the LICENSE-BSD-3-Clause file.
|
// found in the LICENSE-BSD-3-Clause file.
|
||||||
|
|
||||||
use crate::configuration::{self, PciBarRegionType};
|
use crate::configuration::{self, PciBarRegionType};
|
||||||
use devices::BusDevice;
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::fmt::{self, Display};
|
use std::fmt::{self, Display};
|
||||||
use std::{self, io, result};
|
use std::{self, io, result};
|
||||||
use vm_allocator::SystemAllocator;
|
use vm_allocator::SystemAllocator;
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_memory::{GuestAddress, GuestUsize};
|
use vm_memory::{GuestAddress, GuestUsize};
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
|
@ -5,7 +5,6 @@
|
|||||||
//! Implements pci devices and busses.
|
//! Implements pci devices and busses.
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate log;
|
extern crate log;
|
||||||
extern crate devices;
|
|
||||||
extern crate hypervisor;
|
extern crate hypervisor;
|
||||||
extern crate serde;
|
extern crate serde;
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 OR BSD-3-Clause
|
||||||
//
|
//
|
||||||
|
|
||||||
extern crate devices;
|
|
||||||
extern crate vm_allocator;
|
extern crate vm_allocator;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
@ -12,7 +11,6 @@ use crate::{
|
|||||||
PciDevice, PciDeviceError, PciHeaderType, PciSubclass, MSIX_TABLE_ENTRY_SIZE,
|
PciDevice, PciDeviceError, PciHeaderType, PciSubclass, MSIX_TABLE_ENTRY_SIZE,
|
||||||
};
|
};
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use devices::BusDevice;
|
|
||||||
use std::any::Any;
|
use std::any::Any;
|
||||||
use std::ops::Deref;
|
use std::ops::Deref;
|
||||||
use std::os::unix::io::AsRawFd;
|
use std::os::unix::io::AsRawFd;
|
||||||
@ -25,6 +23,7 @@ use vm_allocator::SystemAllocator;
|
|||||||
use vm_device::interrupt::{
|
use vm_device::interrupt::{
|
||||||
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
|
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
|
||||||
};
|
};
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
Address, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap, GuestRegionMmap,
|
Address, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap, GuestRegionMmap,
|
||||||
GuestUsize,
|
GuestUsize,
|
||||||
|
@ -15,7 +15,6 @@ anyhow = "1.0"
|
|||||||
arc-swap = ">=0.4.4"
|
arc-swap = ">=0.4.4"
|
||||||
block_util = { path = "../block_util" }
|
block_util = { path = "../block_util" }
|
||||||
byteorder = "1.3.4"
|
byteorder = "1.3.4"
|
||||||
devices = { path = "../devices" }
|
|
||||||
epoll = ">=4.0.1"
|
epoll = ">=4.0.1"
|
||||||
io-uring = ">=0.4.0"
|
io-uring = ">=0.4.0"
|
||||||
libc = "0.2.77"
|
libc = "0.2.77"
|
||||||
|
@ -10,13 +10,13 @@ use crate::{
|
|||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use byteorder::{ByteOrder, LittleEndian};
|
use byteorder::{ByteOrder, LittleEndian};
|
||||||
use devices::BusDevice;
|
|
||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use std::num::Wrapping;
|
use std::num::Wrapping;
|
||||||
use std::result;
|
use std::result;
|
||||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||||
use std::sync::{Arc, Mutex};
|
use std::sync::{Arc, Mutex};
|
||||||
use vm_device::interrupt::InterruptSourceGroup;
|
use vm_device::interrupt::InterruptSourceGroup;
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap};
|
use vm_memory::{GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap};
|
||||||
use vm_migration::{
|
use vm_migration::{
|
||||||
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
Migratable, MigratableError, Pausable, Snapshot, SnapshotDataSection, Snapshottable,
|
||||||
|
@ -6,7 +6,6 @@
|
|||||||
//
|
//
|
||||||
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
// SPDX-License-Identifier: Apache-2.0 AND BSD-3-Clause
|
||||||
|
|
||||||
extern crate devices;
|
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
extern crate pci;
|
extern crate pci;
|
||||||
extern crate vm_allocator;
|
extern crate vm_allocator;
|
||||||
@ -21,7 +20,6 @@ use crate::{
|
|||||||
DEVICE_INIT, VIRTIO_MSI_NO_VECTOR,
|
DEVICE_INIT, VIRTIO_MSI_NO_VECTOR,
|
||||||
};
|
};
|
||||||
use anyhow::anyhow;
|
use anyhow::anyhow;
|
||||||
use devices::BusDevice;
|
|
||||||
use libc::EFD_NONBLOCK;
|
use libc::EFD_NONBLOCK;
|
||||||
use pci::{
|
use pci::{
|
||||||
BarReprogrammingParams, MsixCap, MsixConfig, PciBarConfiguration, PciBarRegionType,
|
BarReprogrammingParams, MsixCap, MsixConfig, PciBarConfiguration, PciBarRegionType,
|
||||||
@ -39,6 +37,7 @@ use vm_allocator::SystemAllocator;
|
|||||||
use vm_device::interrupt::{
|
use vm_device::interrupt::{
|
||||||
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
|
InterruptIndex, InterruptManager, InterruptSourceGroup, MsiIrqGroupConfig,
|
||||||
};
|
};
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap,
|
Address, ByteValued, GuestAddress, GuestAddressSpace, GuestMemoryAtomic, GuestMemoryMmap,
|
||||||
GuestUsize, Le32,
|
GuestUsize, Le32,
|
||||||
|
@ -1,9 +1,24 @@
|
|||||||
|
// Copyright © 2020 Intel Corporation
|
||||||
|
//
|
||||||
|
// SPDX-License-Identifier: Apache-2.0
|
||||||
|
//
|
||||||
|
|
||||||
#[macro_use]
|
#[macro_use]
|
||||||
extern crate serde_derive;
|
extern crate serde_derive;
|
||||||
extern crate vm_memory;
|
extern crate vm_memory;
|
||||||
|
|
||||||
|
use std::io;
|
||||||
|
|
||||||
|
mod bus;
|
||||||
pub mod interrupt;
|
pub mod interrupt;
|
||||||
|
|
||||||
|
pub use self::bus::{Bus, BusDevice, Error as BusError};
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum Error {
|
||||||
|
IoError(io::Error),
|
||||||
|
}
|
||||||
|
|
||||||
/// Type of Message Singaled Interrupt
|
/// Type of Message Singaled Interrupt
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
||||||
pub enum MsiIrqType {
|
pub enum MsiIrqType {
|
||||||
|
@ -27,19 +27,18 @@ use arch::x86_64::SgxEpcSection;
|
|||||||
use arch::EntryPoint;
|
use arch::EntryPoint;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use arch::{CpuidPatch, CpuidReg};
|
use arch::{CpuidPatch, CpuidReg};
|
||||||
use devices::{interrupt_controller::InterruptController, BusDevice};
|
use devices::interrupt_controller::InterruptController;
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use hypervisor::CpuId;
|
use hypervisor::CpuId;
|
||||||
use hypervisor::{CpuState, VmExit};
|
use hypervisor::{CpuState, VmExit};
|
||||||
|
|
||||||
use libc::{c_void, siginfo_t};
|
use libc::{c_void, siginfo_t};
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
use std::os::unix::thread::JoinHandleExt;
|
use std::os::unix::thread::JoinHandleExt;
|
||||||
use std::sync::atomic::{AtomicBool, Ordering};
|
use std::sync::atomic::{AtomicBool, Ordering};
|
||||||
use std::sync::{Arc, Barrier, Mutex};
|
use std::sync::{Arc, Barrier, Mutex};
|
||||||
use std::{cmp, io, result, thread};
|
use std::{cmp, io, result, thread};
|
||||||
|
use vm_device::{Bus, BusDevice};
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use vm_memory::GuestAddress;
|
use vm_memory::GuestAddress;
|
||||||
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
|
use vm_memory::{GuestMemoryAtomic, GuestMemoryMmap};
|
||||||
@ -129,7 +128,7 @@ pub enum Error {
|
|||||||
ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
|
ThreadCleanup(std::boxed::Box<dyn std::any::Any + std::marker::Send>),
|
||||||
|
|
||||||
/// Cannot add legacy device to Bus.
|
/// Cannot add legacy device to Bus.
|
||||||
BusError(devices::BusError),
|
BusError(vm_device::BusError),
|
||||||
|
|
||||||
/// Failed to allocate IO port
|
/// Failed to allocate IO port
|
||||||
AllocateIOPort,
|
AllocateIOPort,
|
||||||
@ -234,8 +233,8 @@ pub struct Vcpu {
|
|||||||
vcpu: Arc<dyn hypervisor::Vcpu>,
|
vcpu: Arc<dyn hypervisor::Vcpu>,
|
||||||
id: u8,
|
id: u8,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
io_bus: Arc<devices::Bus>,
|
io_bus: Arc<Bus>,
|
||||||
mmio_bus: Arc<devices::Bus>,
|
mmio_bus: Arc<Bus>,
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
||||||
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
|
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
||||||
@ -255,8 +254,8 @@ impl Vcpu {
|
|||||||
pub fn new(
|
pub fn new(
|
||||||
id: u8,
|
id: u8,
|
||||||
vm: &Arc<dyn hypervisor::Vm>,
|
vm: &Arc<dyn hypervisor::Vm>,
|
||||||
#[cfg(target_arch = "x86_64")] io_bus: Arc<devices::Bus>,
|
#[cfg(target_arch = "x86_64")] io_bus: Arc<Bus>,
|
||||||
mmio_bus: Arc<devices::Bus>,
|
mmio_bus: Arc<Bus>,
|
||||||
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
|
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
|
||||||
creation_ts: std::time::Instant,
|
creation_ts: std::time::Instant,
|
||||||
) -> Result<Arc<Mutex<Self>>> {
|
) -> Result<Arc<Mutex<Self>>> {
|
||||||
@ -322,7 +321,7 @@ impl Vcpu {
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
VmExit::IoIn(addr, data) => {
|
VmExit::IoIn(addr, data) => {
|
||||||
if let Err(e) = self.io_bus.read(u64::from(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);
|
warn!("Guest PIO read to unregistered address 0x{:x}", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -334,7 +333,7 @@ impl Vcpu {
|
|||||||
self.log_debug_ioport(data[0]);
|
self.log_debug_ioport(data[0]);
|
||||||
}
|
}
|
||||||
if let Err(e) = self.io_bus.write(u64::from(addr), data) {
|
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);
|
warn!("Guest PIO write to unregistered address 0x{:x}", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -342,7 +341,7 @@ impl Vcpu {
|
|||||||
}
|
}
|
||||||
VmExit::MmioRead(addr, data) => {
|
VmExit::MmioRead(addr, data) => {
|
||||||
if let Err(e) = self.mmio_bus.read(addr as u64, 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);
|
warn!("Guest MMIO read to unregistered address 0x{:x}", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -350,7 +349,7 @@ impl Vcpu {
|
|||||||
}
|
}
|
||||||
VmExit::MmioWrite(addr, data) => {
|
VmExit::MmioWrite(addr, data) => {
|
||||||
if let Err(e) = self.mmio_bus.write(addr as u64, 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);
|
warn!("Guest MMIO write to unregistered address 0x{:x}", addr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -458,9 +457,9 @@ impl Snapshottable for Vcpu {
|
|||||||
pub struct CpuManager {
|
pub struct CpuManager {
|
||||||
config: CpusConfig,
|
config: CpusConfig,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
io_bus: Arc<devices::Bus>,
|
io_bus: Arc<Bus>,
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
#[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))]
|
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
||||||
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
|
interrupt_controller: Option<Arc<Mutex<dyn InterruptController>>>,
|
||||||
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
#[cfg_attr(target_arch = "aarch64", allow(dead_code))]
|
||||||
|
@ -39,7 +39,7 @@ use devices::gic;
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use devices::ioapic;
|
use devices::ioapic;
|
||||||
use devices::{
|
use devices::{
|
||||||
interrupt_controller, interrupt_controller::InterruptController, legacy::Serial, BusDevice,
|
interrupt_controller, interrupt_controller::InterruptController, legacy::Serial,
|
||||||
HotPlugNotificationFlags,
|
HotPlugNotificationFlags,
|
||||||
};
|
};
|
||||||
use hypervisor::kvm_ioctls;
|
use hypervisor::kvm_ioctls;
|
||||||
@ -81,7 +81,7 @@ use vm_allocator::SystemAllocator;
|
|||||||
use vm_device::interrupt::{
|
use vm_device::interrupt::{
|
||||||
InterruptIndex, InterruptManager, LegacyIrqGroupConfig, MsiIrqGroupConfig,
|
InterruptIndex, InterruptManager, LegacyIrqGroupConfig, MsiIrqGroupConfig,
|
||||||
};
|
};
|
||||||
use vm_device::Resource;
|
use vm_device::{Bus, BusDevice, Resource};
|
||||||
use vm_memory::guest_memory::FileOffset;
|
use vm_memory::guest_memory::FileOffset;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
Address, GuestAddress, GuestAddressSpace, GuestRegionMmap, GuestUsize, MmapRegion,
|
Address, GuestAddress, GuestAddressSpace, GuestRegionMmap, GuestUsize, MmapRegion,
|
||||||
@ -249,7 +249,7 @@ pub enum DeviceManagerError {
|
|||||||
Mmap(io::Error),
|
Mmap(io::Error),
|
||||||
|
|
||||||
/// Cannot add legacy device to Bus.
|
/// Cannot add legacy device to Bus.
|
||||||
BusError(devices::BusError),
|
BusError(vm_device::BusError),
|
||||||
|
|
||||||
/// Failed to allocate IO port
|
/// Failed to allocate IO port
|
||||||
AllocateIOPort,
|
AllocateIOPort,
|
||||||
@ -298,10 +298,10 @@ pub enum DeviceManagerError {
|
|||||||
RemoveDeviceFromPciBus(pci::PciRootError),
|
RemoveDeviceFromPciBus(pci::PciRootError),
|
||||||
|
|
||||||
/// Failed removing a bus device from the IO bus.
|
/// 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.
|
/// 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.
|
/// Failed to find the device corresponding to a specific PCI b/d/f.
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
@ -459,8 +459,8 @@ impl Console {
|
|||||||
struct AddressManager {
|
struct AddressManager {
|
||||||
allocator: Arc<Mutex<SystemAllocator>>,
|
allocator: Arc<Mutex<SystemAllocator>>,
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
io_bus: Arc<devices::Bus>,
|
io_bus: Arc<Bus>,
|
||||||
mmio_bus: Arc<devices::Bus>,
|
mmio_bus: Arc<Bus>,
|
||||||
vm: Arc<dyn hypervisor::Vm>,
|
vm: Arc<dyn hypervisor::Vm>,
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
device_tree: Arc<Mutex<DeviceTree>>,
|
device_tree: Arc<Mutex<DeviceTree>>,
|
||||||
@ -822,8 +822,8 @@ impl DeviceManager {
|
|||||||
let address_manager = Arc::new(AddressManager {
|
let address_manager = Arc::new(AddressManager {
|
||||||
allocator: memory_manager.lock().unwrap().allocator(),
|
allocator: memory_manager.lock().unwrap().allocator(),
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
io_bus: Arc::new(devices::Bus::new()),
|
io_bus: Arc::new(Bus::new()),
|
||||||
mmio_bus: Arc::new(devices::Bus::new()),
|
mmio_bus: Arc::new(Bus::new()),
|
||||||
vm: vm.clone(),
|
vm: vm.clone(),
|
||||||
#[cfg(feature = "pci_support")]
|
#[cfg(feature = "pci_support")]
|
||||||
device_tree: Arc::clone(&device_tree),
|
device_tree: Arc::clone(&device_tree),
|
||||||
@ -2998,11 +2998,11 @@ impl DeviceManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[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
|
&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
|
&self.address_manager.mmio_bus
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,8 +15,6 @@ use arch::x86_64::{SgxEpcRegion, SgxEpcSection};
|
|||||||
use arch::{get_host_cpu_phys_bits, layout, RegionType};
|
use arch::{get_host_cpu_phys_bits, layout, RegionType};
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use devices::ioapic;
|
use devices::ioapic;
|
||||||
use devices::BusDevice;
|
|
||||||
|
|
||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use libc::{MAP_NORESERVE, MAP_POPULATE, MAP_SHARED, PROT_READ, PROT_WRITE};
|
use libc::{MAP_NORESERVE, MAP_POPULATE, MAP_SHARED, PROT_READ, PROT_WRITE};
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
@ -33,6 +31,7 @@ use url::Url;
|
|||||||
#[cfg(target_arch = "x86_64")]
|
#[cfg(target_arch = "x86_64")]
|
||||||
use vm_allocator::GsiApic;
|
use vm_allocator::GsiApic;
|
||||||
use vm_allocator::SystemAllocator;
|
use vm_allocator::SystemAllocator;
|
||||||
|
use vm_device::BusDevice;
|
||||||
use vm_memory::guest_memory::FileOffset;
|
use vm_memory::guest_memory::FileOffset;
|
||||||
use vm_memory::{
|
use vm_memory::{
|
||||||
mmap::MmapRegionError, Address, Bytes, Error as MmapError, GuestAddress, GuestAddressSpace,
|
mmap::MmapRegionError, Address, Bytes, Error as MmapError, GuestAddress, GuestAddressSpace,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user