Struct dbs_interrupt::DeviceInterruptManager
source · pub struct DeviceInterruptManager<T: InterruptManager> { /* private fields */ }
Expand description
A struct to manage interrupts and interrupt modes for a device.
The interrupt manager may support multiple working mode. For example, an interrupt manager for a PCI device may work in legacy mode, PCI MSI mode or PCI MSIx mode. Under certain conditions, the interrupt manager may switch between interrupt working modes. To simplify implementation, switching working mode is only supported at configuration stage and will be disabled at runtime stage. The DeviceInterruptManager::enable() switches the interrupt manager from configuration stage into runtime stage. And DeviceInterruptManager::reset() switches from runtime stage back to initial configuration stage.
Implementations§
source§impl<T: InterruptManager> DeviceInterruptManager<T>
impl<T: InterruptManager> DeviceInterruptManager<T>
sourcepub fn new(intr_mgr: T, resources: &DeviceResources) -> Result<Self>
pub fn new(intr_mgr: T, resources: &DeviceResources) -> Result<Self>
Create an interrupt manager for a device.
Arguments
intr_mgr
: underline interrupt manager to allocate/free interrupt groups.resources
: resources assigned to the device, including assigned interrupt resources.
sourcepub fn set_device_id(&mut self, device_id: Option<u32>)
pub fn set_device_id(&mut self, device_id: Option<u32>)
Set device_id for MSI routing
sourcepub fn is_enabled(&self) -> bool
pub fn is_enabled(&self) -> bool
Check whether the interrupt manager has been activated.
sourcepub fn enable(&mut self) -> Result<()>
pub fn enable(&mut self) -> Result<()>
Switch the interrupt manager from configuration stage into runtime stage.
The working mode could only be changed at configuration stage, and all requests to change working mode at runtime stage will be rejected.
If the interrupt manager is still in DISABLED mode when DeviceInterruptManager::enable() is called, it will be put into LEGACY mode if LEGACY mode is supported.
sourcepub fn reset(&mut self) -> Result<()>
pub fn reset(&mut self) -> Result<()>
Switch the interrupt manager from runtime stage back into initial configuration stage.
Currently we doesn’t track the usage of interrupt group object given out by get_group()
,
so the the caller needs to take the responsibility to release all interrupt group object
reference before calling DeviceInterruptManager::reset().
sourcepub fn get_working_mode(&mut self) -> DeviceInterruptMode
pub fn get_working_mode(&mut self) -> DeviceInterruptMode
Get the current interrupt working mode.
sourcepub fn set_working_mode(&mut self, mode: DeviceInterruptMode) -> Result<()>
pub fn set_working_mode(&mut self, mode: DeviceInterruptMode) -> Result<()>
Switch interrupt working mode.
Currently switching working mode is only supported during device configuration stage and
will always return failure if called during device runtime stage. The device switches from
configuration stage to runtime stage by invoking DeviceInterruptManager::enable()
. With
this constraint, the device drivers may call DeviceInterruptManager::get_group()
to get
the underline active interrupt group object, and directly calls the interrupt group object’s
methods to trigger/acknowledge interrupts.
This is a key design decision for optimizing performance. Though the DeviceInterruptManager object itself is not multi-thread safe and must be protected from concurrent access by the caller, the interrupt source group object is multi-thread safe and could be called concurrently to trigger/acknowledge interrupts. This design may help to improve performance for MSI interrupts.
Arguments
mode
: target working mode.
sourcepub fn get_group(&self) -> Option<Arc<Box<dyn InterruptSourceGroup>>>
pub fn get_group(&self) -> Option<Arc<Box<dyn InterruptSourceGroup>>>
Get the underline interrupt source group object, so the device driver could concurrently trigger/acknowledge interrupts by using the returned group object.
sourcepub fn get_group_unchecked(&self) -> Arc<Box<dyn InterruptSourceGroup>>
pub fn get_group_unchecked(&self) -> Arc<Box<dyn InterruptSourceGroup>>
Get the underline interrupt source group object, ignore the mode
source§impl<T: InterruptManager> DeviceInterruptManager<T>
impl<T: InterruptManager> DeviceInterruptManager<T>
sourcepub fn set_msi_high_address(&mut self, index: u32, data: u32) -> Result<()>
pub fn set_msi_high_address(&mut self, index: u32, data: u32) -> Result<()>
Set the high address for a MSI message.
sourcepub fn set_msi_low_address(&mut self, index: u32, data: u32) -> Result<()>
pub fn set_msi_low_address(&mut self, index: u32, data: u32) -> Result<()>
Set the low address for a MSI message.
sourcepub fn set_msi_data(&mut self, index: u32, data: u32) -> Result<()>
pub fn set_msi_data(&mut self, index: u32, data: u32) -> Result<()>
Set the data for a MSI message.
sourcepub fn get_msi_mask(&self, index: u32) -> Result<bool>
pub fn get_msi_mask(&self, index: u32) -> Result<bool>
Get msi irq MASK state