mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2024-10-03 20:15:45 +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>,
|
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> {
|
impl<E> MsiInterruptGroup<E> {
|
||||||
fn new(
|
fn new(
|
||||||
vm_fd: Arc<dyn hypervisor::Vm>,
|
vm_fd: Arc<dyn hypervisor::Vm>,
|
||||||
@ -202,32 +234,11 @@ impl InterruptSourceGroup for KvmMsiInterruptGroup {
|
|||||||
|
|
||||||
fn update(&self, index: InterruptIndex, config: InterruptSourceConfig) -> Result<()> {
|
fn update(&self, index: InterruptIndex, config: InterruptSourceConfig) -> Result<()> {
|
||||||
if let Some(route) = self.irq_routes.get(&index) {
|
if let Some(route) = self.irq_routes.get(&index) {
|
||||||
if let InterruptSourceConfig::MsiIrq(cfg) = &config {
|
let entry = KvmRoutingEntry::make_entry(route.gsi, &config)?;
|
||||||
let mut kvm_route = kvm_irq_routing_entry {
|
self.gsi_msi_routes
|
||||||
gsi: route.gsi,
|
.lock()
|
||||||
type_: KVM_IRQ_ROUTING_MSI,
|
.unwrap()
|
||||||
..Default::default()
|
.insert(route.gsi, *entry);
|
||||||
};
|
|
||||||
|
|
||||||
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",
|
|
||||||
));
|
|
||||||
}
|
|
||||||
|
|
||||||
return self.set_gsi_routes();
|
return self.set_gsi_routes();
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user