mirror of
https://github.com/cloud-hypervisor/cloud-hypervisor.git
synced 2026-08-05 02:19:16 +00:00
interrupt: Make IRQ delivery generic
Because we cannot always assume the irq fd will be the way to send an IRQ to the guest, this means we cannot make the assumption that every virtio device implementation should expect an EventFd to trigger an IRQ. This commit organizes the code related to virtio devices so that it now expects a Rust closure instead of a known EventFd. This lets the caller decide what should be done whenever a device needs to trigger an interrupt to the guest. The closure will allow for other type of interrupt mechanism such as MSI to be implemented. From the device perspective, it could be a pin based interrupt or an MSI, it does not matter since the device will simply call into the provided callback, passing the appropriate Queue as a reference. This design keeps the device model generic. Signed-off-by: Sebastien Boeuf <sebastien.boeuf@intel.com>
This commit is contained in:
committed by
Rob Bradford
parent
1f53488003
commit
d3c7b45542
+4
-1
@@ -7,10 +7,13 @@ use crate::PciInterruptPin;
|
||||
use devices::BusDevice;
|
||||
use std;
|
||||
use std::fmt::{self, Display};
|
||||
use std::sync::Arc;
|
||||
use vm_allocator::SystemAllocator;
|
||||
use vm_memory::{GuestAddress, GuestUsize};
|
||||
use vmm_sys_util::EventFd;
|
||||
|
||||
pub type IrqClosure = Box<Fn() -> std::result::Result<(), std::io::Error> + Send + Sync>;
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum Error {
|
||||
/// Setup of the device capabilities failed.
|
||||
@@ -41,7 +44,7 @@ impl Display for Error {
|
||||
pub trait PciDevice: BusDevice {
|
||||
/// Assign a legacy PCI IRQ to this device.
|
||||
/// The device may write to `irq_evt` to trigger an interrupt.
|
||||
fn assign_irq(&mut self, _irq_evt: EventFd, _irq_num: u32, _irq_pin: PciInterruptPin) {}
|
||||
fn assign_irq(&mut self, _irq_cb: Arc<IrqClosure>, _irq_num: u32, _irq_pin: PciInterruptPin) {}
|
||||
|
||||
/// Allocates the needed PCI BARs space using the `allocate` function which takes a size and
|
||||
/// returns an address. Returns a Vec of (GuestAddress, GuestUsize) tuples.
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ pub use self::configuration::{
|
||||
PciSubclass,
|
||||
};
|
||||
pub use self::device::Error as PciDeviceError;
|
||||
pub use self::device::PciDevice;
|
||||
pub use self::device::{IrqClosure, PciDevice};
|
||||
pub use self::root::{PciConfigIo, PciConfigMmio, PciRoot, PciRootError};
|
||||
|
||||
/// PCI has four interrupt pins A->D.
|
||||
|
||||
Reference in New Issue
Block a user