mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-08-19 22:41:15 +00:00
vmm: interrupt: generify impl InterruptManager for MsiInterruptManager
The logic can be shared among hypervisor implementations. The 'static bound is used such that we don't need to deal with extra lifetime parameter everywhere. It should be okay because we know the entry type E doesn't contain any reference. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
ade904e356
commit
c31e747005
@ -103,24 +103,24 @@ impl InterruptRoute {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
struct RoutingEntry<E> {
|
pub struct RoutingEntry<E> {
|
||||||
route: E,
|
route: E,
|
||||||
masked: bool,
|
masked: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
type KvmRoutingEntry = RoutingEntry<kvm_irq_routing_entry>;
|
type KvmRoutingEntry = RoutingEntry<kvm_irq_routing_entry>;
|
||||||
|
|
||||||
struct MsiInterruptGroup<E> {
|
pub struct MsiInterruptGroup<E> {
|
||||||
vm_fd: Arc<dyn hypervisor::Vm>,
|
vm_fd: Arc<dyn hypervisor::Vm>,
|
||||||
gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<E>>>>,
|
gsi_msi_routes: Arc<Mutex<HashMap<u32, RoutingEntry<E>>>>,
|
||||||
irq_routes: HashMap<InterruptIndex, InterruptRoute>,
|
irq_routes: HashMap<InterruptIndex, InterruptRoute>,
|
||||||
}
|
}
|
||||||
|
|
||||||
trait MsiInterruptGroupOps {
|
pub trait MsiInterruptGroupOps {
|
||||||
fn set_gsi_routes(&self) -> Result<()>;
|
fn set_gsi_routes(&self) -> Result<()>;
|
||||||
}
|
}
|
||||||
|
|
||||||
trait RoutingEntryExt {
|
pub trait RoutingEntryExt {
|
||||||
fn make_entry(gsi: u32, config: &InterruptSourceConfig) -> Result<Box<Self>>;
|
fn make_entry(gsi: u32, config: &InterruptSourceConfig) -> Result<Box<Self>>;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -387,7 +387,12 @@ impl InterruptManager for LegacyUserspaceInterruptManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl InterruptManager for KvmMsiInterruptManager {
|
impl<E> InterruptManager for MsiInterruptManager<E>
|
||||||
|
where
|
||||||
|
E: Send + Sync + 'static,
|
||||||
|
RoutingEntry<E>: RoutingEntryExt,
|
||||||
|
MsiInterruptGroup<E>: MsiInterruptGroupOps,
|
||||||
|
{
|
||||||
type GroupConfig = MsiIrqGroupConfig;
|
type GroupConfig = MsiIrqGroupConfig;
|
||||||
|
|
||||||
fn create_group(
|
fn create_group(
|
||||||
@ -401,7 +406,7 @@ impl InterruptManager for KvmMsiInterruptManager {
|
|||||||
irq_routes.insert(i, InterruptRoute::new(&mut allocator)?);
|
irq_routes.insert(i, InterruptRoute::new(&mut allocator)?);
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(Arc::new(Box::new(KvmMsiInterruptGroup::new(
|
Ok(Arc::new(Box::new(MsiInterruptGroup::new(
|
||||||
self.vm_fd.clone(),
|
self.vm_fd.clone(),
|
||||||
self.gsi_msi_routes.clone(),
|
self.gsi_msi_routes.clone(),
|
||||||
irq_routes,
|
irq_routes,
|
||||||
|
Loading…
Reference in New Issue
Block a user