pub struct Registration<T: Handler + 'static> { /* private fields */ }
Expand description
A registration of an IRQ handler for a given IRQ line.
§Examples
The following is an example of using Registration
. It uses a
Completion
to coordinate between the IRQ
handler and process context. Completion
uses interior mutability, so the
handler can signal with Completion::complete_all()
and the process
context can wait with Completion::wait_for_completion()
even though
there is no way to get a mutable reference to the any of the fields in
Data
.
use kernel::c_str;
use kernel::device::{Bound, Device};
use kernel::irq::{self, Flags, IrqRequest, IrqReturn, Registration};
use kernel::prelude::*;
use kernel::sync::{Arc, Completion};
// Data shared between process and IRQ context.
#[pin_data]
struct Data {
#[pin]
completion: Completion,
}
impl irq::Handler for Data {
// Executed in IRQ context.
fn handle(&self, _dev: &Device<Bound>) -> IrqReturn {
self.completion.complete_all();
IrqReturn::Handled
}
}
// Registers an IRQ handler for the given IrqRequest.
//
// This runs in process context and assumes `request` was previously acquired from a device.
fn register_irq(
handler: impl PinInit<Data, Error>,
request: IrqRequest<'_>,
) -> Result<Arc<Registration<Data>>> {
let registration = Registration::new(request, Flags::SHARED, c_str!("my_device"), handler);
let registration = Arc::pin_init(registration, GFP_KERNEL)?;
registration.handler().completion.wait_for_completion();
Ok(registration)
}
§Invariants
- We own an irq handler whose cookie is a pointer to
Self
.
Implementations§
Source§impl<T: Handler + 'static> Registration<T>
impl<T: Handler + 'static> Registration<T>
Sourcepub fn new<'a>(
request: IrqRequest<'a>,
flags: Flags,
name: &'static CStr,
handler: impl PinInit<T, Error> + 'a,
) -> impl PinInit<Self, Error> + 'a
pub fn new<'a>( request: IrqRequest<'a>, flags: Flags, name: &'static CStr, handler: impl PinInit<T, Error> + 'a, ) -> impl PinInit<Self, Error> + 'a
Registers the IRQ handler with the system for the given IRQ number.
Sourcepub fn handler(&self) -> &T
pub fn handler(&self) -> &T
Returns a reference to the handler that was registered with the system.
Sourcepub fn try_synchronize(&self) -> Result
pub fn try_synchronize(&self) -> Result
Wait for pending IRQ handlers on other CPUs.
This will attempt to access the inner Devres
container.
Sourcepub fn synchronize(&self, dev: &Device<Bound>) -> Result
pub fn synchronize(&self, dev: &Device<Bound>) -> Result
Wait for pending IRQ handlers on other CPUs.
Trait Implementations§
Source§impl<T: Handler + 'static> HasPinData for Registration<T>
impl<T: Handler + 'static> HasPinData for Registration<T>
Auto Trait Implementations§
impl<T> !Freeze for Registration<T>
impl<T> !RefUnwindSafe for Registration<T>
impl<T> Send for Registration<T>where
T: Send,
impl<T> Sync for Registration<T>
impl<T> !UnwindSafe for Registration<T>
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
Source§impl<T> PinInit<T> for T
impl<T> PinInit<T> for T
Source§unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
unsafe fn __pinned_init(self, slot: *mut T) -> Result<(), Infallible>
Initializes
slot
. Read more