vmm: interrupt: simplify interrupt handling traits

Drop the generic type E and use IrqRoutngEntry directly. This allows
dropping a bunch of trait bounds from code.

Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
Wei Liu
2021-03-24 16:29:06 +00:00
committed by Sebastien Boeuf
parent 1d9f27c9fb
commit f5c550affb

View File

@@ -4,6 +4,7 @@
// //
use devices::interrupt_controller::InterruptController; use devices::interrupt_controller::InterruptController;
use hypervisor::IrqRoutingEntry;
use std::collections::HashMap; use std::collections::HashMap;
use std::io; use std::io;
use std::sync::atomic::{AtomicBool, Ordering}; use std::sync::atomic::{AtomicBool, Ordering};
@@ -83,23 +84,18 @@ impl InterruptRoute {
} }
} }
pub struct RoutingEntry<E> { pub struct RoutingEntry<IrqRoutingEntry> {
route: E, route: IrqRoutingEntry,
masked: bool, masked: bool,
} }
pub struct MsiInterruptGroup<E> { pub struct MsiInterruptGroup<IrqRoutingEntry> {
vm: Arc<dyn hypervisor::Vm>, vm: Arc<dyn hypervisor::Vm>,
gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<E>>>>, gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<IrqRoutingEntry>>>>,
irq_routes: HashMap<InterruptIndex, InterruptRoute>, irq_routes: HashMap<InterruptIndex, InterruptRoute>,
} }
pub trait MsiInterruptGroupOps<E> { impl MsiInterruptGroup<IrqRoutingEntry> {
fn set_gsi_routes(&self, routes: &HashMap<u32, RoutingEntry<E>>) -> Result<()>;
}
use hypervisor::IrqRoutingEntry;
impl MsiInterruptGroupOps<IrqRoutingEntry> for MsiInterruptGroup<IrqRoutingEntry> {
fn set_gsi_routes(&self, routes: &HashMap<u32, RoutingEntry<IrqRoutingEntry>>) -> Result<()> { fn set_gsi_routes(&self, routes: &HashMap<u32, RoutingEntry<IrqRoutingEntry>>) -> Result<()> {
let mut entry_vec: Vec<IrqRoutingEntry> = Vec::new(); let mut entry_vec: Vec<IrqRoutingEntry> = Vec::new();
for (_, entry) in routes.iter() { for (_, entry) in routes.iter() {
@@ -127,10 +123,10 @@ pub trait RoutingEntryExt {
) -> Result<Box<Self>>; ) -> Result<Box<Self>>;
} }
impl<E> MsiInterruptGroup<E> { impl<IrqRoutingEntry> MsiInterruptGroup<IrqRoutingEntry> {
fn new( fn new(
vm: Arc<dyn hypervisor::Vm>, vm: Arc<dyn hypervisor::Vm>,
gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<E>>>>, gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<IrqRoutingEntry>>>>,
irq_routes: HashMap<InterruptIndex, InterruptRoute>, irq_routes: HashMap<InterruptIndex, InterruptRoute>,
) -> Self { ) -> Self {
MsiInterruptGroup { MsiInterruptGroup {
@@ -141,12 +137,7 @@ impl<E> MsiInterruptGroup<E> {
} }
} }
impl<E> InterruptSourceGroup for MsiInterruptGroup<E> impl InterruptSourceGroup for MsiInterruptGroup<IrqRoutingEntry> {
where
E: Send + Sync,
RoutingEntry<E>: RoutingEntryExt,
MsiInterruptGroup<E>: MsiInterruptGroupOps<E>,
{
fn enable(&self) -> Result<()> { fn enable(&self) -> Result<()> {
for (_, route) in self.irq_routes.iter() { for (_, route) in self.irq_routes.iter() {
route.enable(&self.vm)?; route.enable(&self.vm)?;
@@ -277,10 +268,10 @@ pub struct LegacyUserspaceInterruptManager {
ioapic: Arc<Mutex<dyn InterruptController>>, ioapic: Arc<Mutex<dyn InterruptController>>,
} }
pub struct MsiInterruptManager<E> { pub struct MsiInterruptManager<IrqRoutingEntry> {
allocator: Arc<Mutex<SystemAllocator>>, allocator: Arc<Mutex<SystemAllocator>>,
vm: Arc<dyn hypervisor::Vm>, vm: Arc<dyn hypervisor::Vm>,
gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<E>>>>, gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<IrqRoutingEntry>>>>,
} }
impl LegacyUserspaceInterruptManager { impl LegacyUserspaceInterruptManager {
@@ -289,7 +280,7 @@ impl LegacyUserspaceInterruptManager {
} }
} }
impl<E> MsiInterruptManager<E> { impl MsiInterruptManager<IrqRoutingEntry> {
pub fn new(allocator: Arc<Mutex<SystemAllocator>>, vm: Arc<dyn hypervisor::Vm>) -> Self { pub fn new(allocator: Arc<Mutex<SystemAllocator>>, vm: Arc<dyn hypervisor::Vm>) -> Self {
// Create a shared list of GSI that can be shared through all PCI // Create a shared list of GSI that can be shared through all PCI
// devices. This way, we can maintain the full list of used GSI, // devices. This way, we can maintain the full list of used GSI,
@@ -323,12 +314,7 @@ impl InterruptManager for LegacyUserspaceInterruptManager {
} }
} }
impl<E> InterruptManager for MsiInterruptManager<E> impl InterruptManager for MsiInterruptManager<IrqRoutingEntry> {
where
E: Send + Sync + 'static,
RoutingEntry<E>: RoutingEntryExt,
MsiInterruptGroup<E>: MsiInterruptGroupOps<E>,
{
type GroupConfig = MsiIrqGroupConfig; type GroupConfig = MsiIrqGroupConfig;
fn create_group( fn create_group(