pub struct Registration<'a, T: Handler> { /* 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 core::pin::Pin;
use kernel::{
irq::{
self,
Flags,
IrqRequest,
IrqReturn,
Registration,
},
prelude::*,
sync::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) -> 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(
request: IrqRequest<'_>,
) -> Result<Pin<KBox<Registration<'_, Data>>>> {
// SAFETY: The returned Registration is not leaked.
let registration = unsafe {
Registration::new(
request,
Flags::SHARED,
c"my_device",
try_pin_init!(Data {
completion <- Completion::new(),
}? Error),
)
};
let registration = KBox::pin_init(registration, GFP_KERNEL)?;
registration.handler().completion.wait_for_completion();
Ok(registration)
}§Invariants
- We own an irq handler registered via
request_irqwhose cookie is a pointer toSelf.
Implementations§
Source§impl<'a, T: Handler> Registration<'a, T>
impl<'a, T: Handler> Registration<'a, T>
Source§impl<'a, T: Handler> Registration<'a, T>
impl<'a, T: Handler> Registration<'a, T>
Sourcepub unsafe fn new(
request: IrqRequest<'a>,
flags: Flags,
name: &'static CStr,
handler: impl PinInit<T, Error> + 'a,
) -> impl PinInit<Self, Error> + 'awhere
T: 'a,
pub unsafe fn new(
request: IrqRequest<'a>,
flags: Flags,
name: &'static CStr,
handler: impl PinInit<T, Error> + 'a,
) -> impl PinInit<Self, Error> + 'awhere
T: 'a,
Registers the IRQ handler with the system for the given IRQ number.
§Safety
Callers must not mem::forget() the returned Registration or otherwise prevent its
Drop implementation from running.
Sourcepub fn handler(&self) -> &T
pub fn handler(&self) -> &T
Returns a reference to the handler that was registered with the system.
Sourcepub fn synchronize(&self)
pub fn synchronize(&self)
Wait for pending IRQ handlers on other CPUs.
Trait Implementations§
Source§impl<'a, T: Handler> Drop for Registration<'a, T>
impl<'a, T: Handler> Drop for Registration<'a, T>
Source§impl<'a, T: Handler> HasPinData for Registration<'a, T>
impl<'a, T: Handler> HasPinData for Registration<'a, T>
Source§impl<T: Handler> PinnedDrop for Registration<'_, T>
impl<T: Handler> PinnedDrop for Registration<'_, T>
Auto Trait Implementations§
impl<'a, T> !RefUnwindSafe for Registration<'a, T>
impl<'a, T> !UnsafeUnpin for Registration<'a, T>
impl<'a, T> !UnwindSafe for Registration<'a, T>
impl<'a, T> Freeze for Registration<'a, T>where
T: Freeze,
impl<'a, T> Send for Registration<'a, T>where
T: Send,
impl<'a, T> Sync for Registration<'a, 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