pub struct ThreadedRegistration<'a, T: ThreadedHandler> { /* private fields */ }Expand description
A registration of a threaded IRQ handler for a given IRQ line.
Two callbacks are required: one to handle the IRQ, and one to handle any other work in a separate thread.
The thread handler is only called if the IRQ handler returns
ThreadedIrqReturn::WakeThread.
§Examples
The following is an example of using ThreadedRegistration. It uses a
Mutex to provide interior mutability.
use core::pin::Pin;
use kernel::{
irq::{
self,
Flags,
IrqRequest,
IrqReturn,
ThreadedHandler,
ThreadedIrqReturn,
ThreadedRegistration,
},
prelude::*,
sync::Mutex,
};
// Declare a struct that will be passed in when the interrupt fires. The u32
// merely serves as an example of some internal data.
//
// [`irq::ThreadedHandler::handle`] takes `&self`. This example
// illustrates how interior mutability can be used when sharing the data
// between process context and IRQ context.
#[pin_data]
struct Data {
#[pin]
value: Mutex<u32>,
}
impl ThreadedHandler for Data {
// This will run (in a separate kthread) if and only if
// [`ThreadedHandler::handle`] returns [`WakeThread`], which it does by
// default.
fn handle_threaded(&self) -> IrqReturn {
let mut data = self.value.lock();
*data += 1;
IrqReturn::Handled
}
}
// Registers a threaded IRQ handler for the given [`IrqRequest`].
//
// This is executing in process context and assumes that `request` was
// previously acquired from a device.
fn register_threaded_irq(
request: IrqRequest<'_>,
) -> Result<Pin<KBox<ThreadedRegistration<'_, Data>>>> {
// SAFETY: The returned Registration is not leaked.
let registration = unsafe {
ThreadedRegistration::new(
request,
Flags::SHARED,
c"my_device",
try_pin_init!(Data {
value <- kernel::new_mutex!(0),
}? Error),
)
};
let registration = KBox::pin_init(registration, GFP_KERNEL)?;
{
// The data can be accessed from process context too.
let mut data = registration.handler().value.lock();
*data += 1;
}
Ok(registration)
}§Invariants
- We own an irq handler registered via
request_threaded_irqwhose cookie is a pointer toSelf.
Implementations§
Source§impl<'a, T: ThreadedHandler> ThreadedRegistration<'a, T>
impl<'a, T: ThreadedHandler> ThreadedRegistration<'a, T>
Source§impl<'a, T: ThreadedHandler> ThreadedRegistration<'a, T>
impl<'a, T: ThreadedHandler> ThreadedRegistration<'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 ThreadedRegistration 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: ThreadedHandler> Drop for ThreadedRegistration<'a, T>
impl<'a, T: ThreadedHandler> Drop for ThreadedRegistration<'a, T>
Source§impl<'a, T: ThreadedHandler> HasPinData for ThreadedRegistration<'a, T>
impl<'a, T: ThreadedHandler> HasPinData for ThreadedRegistration<'a, T>
Source§impl<T: ThreadedHandler> PinnedDrop for ThreadedRegistration<'_, T>
impl<T: ThreadedHandler> PinnedDrop for ThreadedRegistration<'_, T>
Auto Trait Implementations§
impl<'a, T> !RefUnwindSafe for ThreadedRegistration<'a, T>
impl<'a, T> !UnsafeUnpin for ThreadedRegistration<'a, T>
impl<'a, T> !UnwindSafe for ThreadedRegistration<'a, T>
impl<'a, T> Freeze for ThreadedRegistration<'a, T>where
T: Freeze,
impl<'a, T> Send for ThreadedRegistration<'a, T>where
T: Send,
impl<'a, T> Sync for ThreadedRegistration<'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