hypervisor, vm-device: Relocate InterruptSourceConfig

Move this enum from vm-device to hypervisor crate so that hypervisor
crate does not gain an extra dependency.

Signed-off-by: Rob Bradford <robert.bradford@intel.com>
This commit is contained in:
Rob Bradford 2022-05-10 22:23:18 +01:00
parent b1bd87df19
commit 3ffc105f83
7 changed files with 38 additions and 40 deletions

2
Cargo.lock generated
View File

@ -356,7 +356,6 @@ dependencies = [
"serde_derive", "serde_derive",
"serde_json", "serde_json",
"thiserror", "thiserror",
"vm-device",
"vm-memory", "vm-memory",
"vmm-sys-util", "vmm-sys-util",
] ]
@ -1297,6 +1296,7 @@ name = "vm-device"
version = "0.1.0" version = "0.1.0"
dependencies = [ dependencies = [
"anyhow", "anyhow",
"hypervisor",
"serde", "serde",
"serde_derive", "serde_derive",
"serde_json", "serde_json",

View File

@ -23,7 +23,6 @@ mshv-ioctls = { git = "https://github.com/rust-vmm/mshv", branch = "main", optio
serde = { version = "1.0.137", features = ["rc"] } serde = { version = "1.0.137", features = ["rc"] }
serde_derive = "1.0.137" serde_derive = "1.0.137"
serde_json = "1.0.81" serde_json = "1.0.81"
vm-device = { path = "../vm-device" }
vm-memory = { version = "0.7.0", features = ["backend-mmap", "backend-atomic"] } vm-memory = { version = "0.7.0", features = ["backend-mmap", "backend-atomic"] }
vmm-sys-util = { version = "0.9.0", features = ["with-serde"] } vmm-sys-util = { version = "0.9.0", features = ["with-serde"] }

View File

@ -17,7 +17,7 @@ use crate::cpu;
use crate::device; use crate::device;
use crate::hypervisor; use crate::hypervisor;
use crate::vec_with_array_field; use crate::vec_with_array_field;
use crate::vm::{self, VmOps}; use crate::vm::{self, InterruptSourceConfig, VmOps};
#[cfg(target_arch = "aarch64")] #[cfg(target_arch = "aarch64")]
use crate::{arm64_core_reg_id, offset__of}; use crate::{arm64_core_reg_id, offset__of};
use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd}; use kvm_ioctls::{NoDatamatch, VcpuFd, VmFd};
@ -32,7 +32,6 @@ use std::result;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::{Arc, RwLock}; use std::sync::{Arc, RwLock};
use vm_device::interrupt::InterruptSourceConfig;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
// x86_64 dependencies // x86_64 dependencies
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]

View File

@ -11,7 +11,7 @@ use crate::cpu;
use crate::cpu::Vcpu; use crate::cpu::Vcpu;
use crate::hypervisor; use crate::hypervisor;
use crate::vec_with_array_field; use crate::vec_with_array_field;
use crate::vm::{self, VmOps}; use crate::vm::{self, InterruptSourceConfig, VmOps};
pub use mshv_bindings::*; pub use mshv_bindings::*;
pub use mshv_ioctls::IoEventAddress; pub use mshv_ioctls::IoEventAddress;
use mshv_ioctls::{set_registers_64, Mshv, NoDatamatch, VcpuFd, VmFd}; use mshv_ioctls::{set_registers_64, Mshv, NoDatamatch, VcpuFd, VmFd};
@ -23,7 +23,6 @@ use vm::DataMatch;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub mod x86_64; pub mod x86_64;
use crate::device; use crate::device;
use vm_device::interrupt::InterruptSourceConfig;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
#[cfg(target_arch = "x86_64")] #[cfg(target_arch = "x86_64")]
pub use x86_64::VcpuMshvState as CpuState; pub use x86_64::VcpuMshvState as CpuState;

View File

@ -28,7 +28,6 @@ use kvm_ioctls::Cap;
use std::fs::File; use std::fs::File;
use std::sync::Arc; use std::sync::Arc;
use thiserror::Error; use thiserror::Error;
use vm_device::interrupt::InterruptSourceConfig;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
/// ///
@ -217,6 +216,39 @@ pub enum HypervisorVmError {
/// ///
pub type Result<T> = std::result::Result<T, HypervisorVmError>; pub type Result<T> = std::result::Result<T, HypervisorVmError>;
/// Configuration data for legacy interrupts.
///
/// On x86 platforms, legacy interrupts means those interrupts routed through PICs or IOAPICs.
#[derive(Copy, Clone, Debug)]
pub struct LegacyIrqSourceConfig {
pub irqchip: u32,
pub pin: u32,
}
/// Configuration data for MSI/MSI-X interrupts.
///
/// On x86 platforms, these interrupts are vectors delivered directly to the LAPIC.
#[derive(Copy, Clone, Debug, Default)]
pub struct MsiIrqSourceConfig {
/// High address to delivery message signaled interrupt.
pub high_addr: u32,
/// Low address to delivery message signaled interrupt.
pub low_addr: u32,
/// Data to write to delivery message signaled interrupt.
pub data: u32,
/// Unique ID of the device to delivery message signaled interrupt.
pub devid: u32,
}
/// Configuration data for an interrupt source.
#[derive(Copy, Clone, Debug)]
pub enum InterruptSourceConfig {
/// Configuration data for Legacy interrupts.
LegacyIrq(LegacyIrqSourceConfig),
/// Configuration data for PciMsi, PciMsix and generic MSI interrupts.
MsiIrq(MsiIrqSourceConfig),
}
/// ///
/// Trait to represent a Vm /// Trait to represent a Vm
/// ///

View File

@ -11,6 +11,7 @@ mshv = ["vfio-ioctls/mshv"]
[dependencies] [dependencies]
anyhow = "1.0.57" anyhow = "1.0.57"
hypervisor = { path = "../hypervisor" }
thiserror = "1.0.31" thiserror = "1.0.31"
serde = { version = "1.0.137", features = ["rc"] } serde = { version = "1.0.137", features = ["rc"] }
serde_derive = "1.0.137" serde_derive = "1.0.137"

View File

@ -57,6 +57,7 @@
//! * The virtual device backend requests the interrupt manager to create an interrupt group //! * The virtual device backend requests the interrupt manager to create an interrupt group
//! according to guest configuration information //! according to guest configuration information
pub use hypervisor::vm::{InterruptSourceConfig, LegacyIrqSourceConfig, MsiIrqSourceConfig};
use std::sync::Arc; use std::sync::Arc;
use vmm_sys_util::eventfd::EventFd; use vmm_sys_util::eventfd::EventFd;
@ -66,39 +67,6 @@ pub type Result<T> = std::io::Result<T>;
/// Data type to store an interrupt source identifier. /// Data type to store an interrupt source identifier.
pub type InterruptIndex = u32; pub type InterruptIndex = u32;
/// Configuration data for legacy interrupts.
///
/// On x86 platforms, legacy interrupts means those interrupts routed through PICs or IOAPICs.
#[derive(Copy, Clone, Debug)]
pub struct LegacyIrqSourceConfig {
pub irqchip: u32,
pub pin: u32,
}
/// Configuration data for MSI/MSI-X interrupts.
///
/// On x86 platforms, these interrupts are vectors delivered directly to the LAPIC.
#[derive(Copy, Clone, Debug, Default)]
pub struct MsiIrqSourceConfig {
/// High address to delivery message signaled interrupt.
pub high_addr: u32,
/// Low address to delivery message signaled interrupt.
pub low_addr: u32,
/// Data to write to delivery message signaled interrupt.
pub data: u32,
/// Unique ID of the device to delivery message signaled interrupt.
pub devid: u32,
}
/// Configuration data for an interrupt source.
#[derive(Copy, Clone, Debug)]
pub enum InterruptSourceConfig {
/// Configuration data for Legacy interrupts.
LegacyIrq(LegacyIrqSourceConfig),
/// Configuration data for PciMsi, PciMsix and generic MSI interrupts.
MsiIrq(MsiIrqSourceConfig),
}
/// Configuration data for legacy, pin based interrupt groups. /// Configuration data for legacy, pin based interrupt groups.
/// ///
/// A legacy interrupt group only takes one irq number as its configuration. /// A legacy interrupt group only takes one irq number as its configuration.