mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-12-23 06:05:21 +00:00
vmm: interrupt: provide and use extension trait RoutingEntryExt
This trait contains a function which produces a interrupt routing entry. Implement that trait for KvmRoutingEntry and rewrite the update function. Signed-off-by: Wei Liu <liuwe@microsoft.com>
This commit is contained in:
parent
4dbca81b86
commit
b2abead65b
@ -116,6 +116,38 @@ struct MsiInterruptGroup<E> {
|
||||
irq_routes: HashMap<InterruptIndex, InterruptRoute>,
|
||||
}
|
||||
|
||||
trait RoutingEntryExt {
|
||||
fn make_entry(gsi: u32, config: &InterruptSourceConfig) -> Result<Box<Self>>;
|
||||
}
|
||||
|
||||
impl RoutingEntryExt for KvmRoutingEntry {
|
||||
fn make_entry(gsi: u32, config: &InterruptSourceConfig) -> Result<Box<Self>> {
|
||||
if let InterruptSourceConfig::MsiIrq(cfg) = &config {
|
||||
let mut kvm_route = kvm_irq_routing_entry {
|
||||
gsi,
|
||||
type_: KVM_IRQ_ROUTING_MSI,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
kvm_route.u.msi.address_lo = cfg.low_addr;
|
||||
kvm_route.u.msi.address_hi = cfg.high_addr;
|
||||
kvm_route.u.msi.data = cfg.data;
|
||||
|
||||
let kvm_entry = KvmRoutingEntry {
|
||||
route: kvm_route,
|
||||
masked: false,
|
||||
};
|
||||
|
||||
return Ok(Box::new(kvm_entry));
|
||||
}
|
||||
|
||||
Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Interrupt config type not supported",
|
||||
))
|
||||
}
|
||||
}
|
||||
|
||||
impl<E> MsiInterruptGroup<E> {
|
||||
fn new(
|
||||
vm_fd: Arc<dyn hypervisor::Vm>,
|
||||
@ -202,32 +234,11 @@ impl InterruptSourceGroup for KvmMsiInterruptGroup {
|
||||
|
||||
fn update(&self, index: InterruptIndex, config: InterruptSourceConfig) -> Result<()> {
|
||||
if let Some(route) = self.irq_routes.get(&index) {
|
||||
if let InterruptSourceConfig::MsiIrq(cfg) = &config {
|
||||
let mut kvm_route = kvm_irq_routing_entry {
|
||||
gsi: route.gsi,
|
||||
type_: KVM_IRQ_ROUTING_MSI,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
kvm_route.u.msi.address_lo = cfg.low_addr;
|
||||
kvm_route.u.msi.address_hi = cfg.high_addr;
|
||||
kvm_route.u.msi.data = cfg.data;
|
||||
|
||||
let kvm_entry = KvmRoutingEntry {
|
||||
route: kvm_route,
|
||||
masked: false,
|
||||
};
|
||||
|
||||
self.gsi_msi_routes
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(route.gsi, kvm_entry);
|
||||
} else {
|
||||
return Err(io::Error::new(
|
||||
io::ErrorKind::Other,
|
||||
"Interrupt config type not supported",
|
||||
));
|
||||
}
|
||||
let entry = KvmRoutingEntry::make_entry(route.gsi, &config)?;
|
||||
self.gsi_msi_routes
|
||||
.lock()
|
||||
.unwrap()
|
||||
.insert(route.gsi, *entry);
|
||||
|
||||
return self.set_gsi_routes();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user