use std::io;
use std::os::unix::io::RawFd;
use crate::device::PciDeviceInternal;
pub struct PciInterrupts<'a> {
pub(crate) device: &'a dyn PciDeviceInternal,
}
impl PciInterrupts<'_> {
pub fn intx(&self) -> PciInterruptMechanism {
PciInterruptMechanism {
device_internal: self.device,
kind: PciInterruptKind::Intx,
}
}
pub fn msi(&self) -> PciInterruptMechanism {
PciInterruptMechanism {
device_internal: self.device,
kind: PciInterruptKind::Msi,
}
}
pub fn msi_x(&self) -> PciInterruptMechanism {
PciInterruptMechanism {
device_internal: self.device,
kind: PciInterruptKind::MsiX,
}
}
}
pub struct PciInterruptMechanism<'a> {
pub(crate) device_internal: &'a dyn PciDeviceInternal,
pub(crate) kind: PciInterruptKind,
}
impl PciInterruptMechanism<'_> {
pub fn max(&self) -> usize {
self.device_internal.interrupts_max(self.kind)
}
pub fn enable(&self, eventfds: &[RawFd]) -> io::Result<()> {
self.device_internal.interrupts_enable(self.kind, eventfds)
}
pub fn disable(&self) -> io::Result<()> {
self.device_internal.interrupts_disable(self.kind)
}
}
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
pub(crate) enum PciInterruptKind {
Intx = 0,
Msi = 1,
MsiX = 2,
}