* [PATCH v7 0/3] drm/tyr: add Job IRQ handling
@ 2026-11-23 14:58 Laura Nao
2026-11-23 14:58 ` [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic() Laura Nao
` (2 more replies)
0 siblings, 3 replies; 5+ messages in thread
From: Laura Nao @ 2026-11-23 14:58 UTC (permalink / raw)
To: Daniel Almeida, Alice Ryhl, Danilo Krummrich, David Airlie,
Simona Vetter, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Tamir Duberstein, Alexandre Courbot,
Onur Özkan
Cc: linux-kernel, dri-devel, rust-for-linux, kernel, Laura Nao,
Deborah Brouwer
Changes in v7:
- Rebased on top of drm-rust-next
- Added spinlock to serialize mask register writes with state
transitions, matching panthor's behavior.
- Added IrqState to track an interrupt state and coordinate
primary/threaded handlers and teardown.
- Replaced JobIrqMaskGuard with new TyrIrqRegistration struct, which
wraps a ThreadedRegistration. Its drop implementation ensures
interrupts are masked and status is updated before free_irq() is
called, preventing racing with threaded handlers running concurrently
on another CPU and a possible IRQ storm.
- Updated job_irq_init to resolve the IRQ registration into a
Pin<KBox<TyrIrqRegistration<...>>>, so it's fully initialized before
returning.
- Rebased on top of "drm/tyr: GPU reset infrastructure"[3]. Updated
code to leverage HwGate for IO operations.
- Added "drm/tyr: add HwGate::try_access_atomic()"
- Link to v6: https://lore.kernel.org/r/20260728-tyr-irq-v2-v6-0-15c90baed949@collabora.com
Changes in v6:
- Split changes into two separate commits: the first one creates a new
file with TyrIrq/TyrIrqTrait and their related impls, the second
commit imports and uses TyrIrq/TyrIrqTrait from crate::irq instead of
crate::driver
- Removed irq() accessor, unmasking the interrupts in TyrIrq::request()
by accessing the private irq field directly instead
- Add JobIrqMaskGuard to mask the Job IRQ before free_irq() runs, fixing
incorrect drop order in the IRQ teardown path
- Combined fw_ready/job_irq_wait into a separate JobIrqEvents type
- Store firmware-ready state only once and always wake waiters
unconditionally
- Clear the status once the handler has been successfully registered
- Use mask() in reenable_mask() to reduce code duplication
- Reworded commit messages to reflect the changes
- Link to v5: https://lore.kernel.org/r/20260728-tyr-irq-v2-v5-1-59fd9dea952a@collabora.com
Changes in v5:
- Implement PinnedDrop on TyrIrq to clear the interrupt mask on teardown
- Link to v4: https://lore.kernel.org/r/20260805-tyr-irq-v2-v4-1-81a4701611c0@collabora.com
Changes in v4:
- Replaced c_str! with C-String in irq.rs
- Moved clear_status() before handle() in handle_threaded(), to avoid
losing events if hw re-asserts the bit while handle() is running.
- Only unmask interrupt sources in job_irq_init() when the handler is
correctly registered.
- Link to v3: https://lore.kernel.org/r/20260728-tyr-irq-v2-v3-1-9c9bc5c029c5@collabora.com
Changes in v3:
- Propagated request_threaded_irq_by_name safety requirement up the
call chain, made TyrIrq::request() and job_irq_init() unsafe
- Dropped CSG bits masking, added TODO comment to note this will be
handled at a later stage. Reworded commit message to reflect the
change.
- Added documentation for TyrIrqTrait, TyrIrq, JobIrq and job_irq_init()
- Link to v2: https://lore.kernel.org/r/20260729-tyr-irq-v2-v2-1-c2750fc11d59@collabora.com
Changes in v2:
- Dropped Wait custom type in favor of WaitQueue
- Renamed JobIrq lifetime to generic 'a
This series follows up to [1], which adds support for firmware loading
and MCU booting to the Tyr driver. The changes included here were
originally introduced in its v4[2], then dropped to reduce the scope of
the series, and have been adjusted to work with the HRT (Higher-Ranked
Lifetime Types) driver architecture recently introduced.
The series adds a threaded IRQ wrapper for the firmware Job interrupts,
used to signal events from the global CSF (GLB) and Command Stream Group
(CSG) interfaces.
These changes will be later used to wait for global CSF interface
readiness after firmware boot, as part of the CSF firmware interfaces
support that will be submitted as a separate series.
This series is based on drm-rust-next and depends on:
- [PATCH v9 0/2] drm/tyr: GPU reset infrastructure[3] and its
dependencies
Note: A branch with all the changes is available here:
https://gitlab.freedesktop.org/laura.nao/linux/-/commits/b4/tyr-irq-v7
[1] https://lore.kernel.org/all/20260728-fw-boot-b4-v10-0-9187aefa3f2f@collabora.com/
[2] https://lore.kernel.org/rust-for-linux/20260424-b4-fw-boot-v4-v4-15-a5d91050789d@collabora.com/
[3] https://lore.kernel.org/all/20261122-tyr-reset-impl-v9-0-ed42d8f513ec@onurozkan.dev/
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
Daniel Almeida (1):
drm/tyr: add HwGate::try_access_atomic()
Laura Nao (2):
drm/tyr: add TyrIrq threaded IRQ wrapper
drm/tyr: add Job IRQ handling
drivers/gpu/drm/tyr/fw.rs | 1 +
drivers/gpu/drm/tyr/fw/irq.rs | 148 +++++++++++++++++++
drivers/gpu/drm/tyr/irq.rs | 269 +++++++++++++++++++++++++++++++++++
drivers/gpu/drm/tyr/reset/hw_gate.rs | 54 ++++++-
drivers/gpu/drm/tyr/tyr.rs | 1 +
5 files changed, 471 insertions(+), 2 deletions(-)
---
base-commit: 746918a0c6c0c1738e74d5e198ee06c848e2ddd2
change-id: 20260728-tyr-irq-v2-0b3c5022be33
Best regards,
--
Laura Nao <laura.nao@collabora.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic()
2026-11-23 14:58 [PATCH v7 0/3] drm/tyr: add Job IRQ handling Laura Nao
@ 2026-11-23 14:58 ` Laura Nao
2026-11-23 18:13 ` Onur Özkan
2026-11-23 14:58 ` [PATCH v7 2/3] drm/tyr: add TyrIrq threaded IRQ wrapper Laura Nao
2026-11-23 14:58 ` [PATCH v7 3/3] drm/tyr: add Job IRQ handling Laura Nao
2 siblings, 1 reply; 5+ messages in thread
From: Laura Nao @ 2026-11-23 14:58 UTC (permalink / raw)
To: Daniel Almeida, Alice Ryhl, Danilo Krummrich, David Airlie,
Simona Vetter, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Tamir Duberstein, Alexandre Courbot,
Onur Özkan
Cc: linux-kernel, dri-devel, rust-for-linux, kernel, Laura Nao
From: Daniel Almeida <daniel.almeida@collabora.com>
HwGate::access() takes gate_lock, which is a mutex, so it cannot be
called from atomic context. IRQ handlers need to access the GPU
registers, and those are only reachable through the gate.
Add HwGate::try_access_atomic(). It enters SRCU without taking gate_lock
and returns None if the reset worker has closed the gate. close() now
sets a closed flag before waiting for SRCU readers, and HwClosedGuard
clears it when dropped. SRCU guarantees that a reader either sees the
flag set or is waited for.
An IRQ handler that gets None cannot acknowledge its interrupt, so its
interrupt has to stay masked while the gate is closed. Document this on
close(). No caller needs to do this yet: the only reset runs at probe,
before any IRQ handler is registered.
There are no users yet. The Job IRQ handler will be the first one.
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
---
drivers/gpu/drm/tyr/reset/hw_gate.rs | 55 ++++++++++++++++++++++++++++++++++--
1 file changed, 53 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/tyr/reset/hw_gate.rs b/drivers/gpu/drm/tyr/reset/hw_gate.rs
index 201f8c953078..40b38f07c472 100644
--- a/drivers/gpu/drm/tyr/reset/hw_gate.rs
+++ b/drivers/gpu/drm/tyr/reset/hw_gate.rs
@@ -6,10 +6,18 @@
//! access with reset. Readers hold the mutex while entering SRCU, then release
//! it before accessing hardware. The reset worker holds the mutex while waiting
//! for admitted readers and resetting hardware.
+//!
+//! Readers that cannot sleep use [`HwGate::try_access_atomic`] instead. It
+//! enters SRCU without taking the mutex and fails if the reset worker has set
+//! `closed`, which it does before waiting for readers.
use kernel::{
prelude::*,
sync::{
+ atomic::{
+ Atomic,
+ Relaxed, //
+ },
new_mutex,
srcu,
Mutex,
@@ -32,6 +40,9 @@ pub(crate) struct HwGate<'hw> {
/// Drains readers that entered before the reset worker acquired `gate_lock`.
#[pin]
srcu: Srcu,
+ /// Set while the reset worker owns the hardware. Checked by readers that
+ /// cannot take `gate_lock`.
+ closed: Atomic<bool>,
}
impl<'hw> HwGate<'hw> {
@@ -41,6 +52,7 @@ pub(crate) fn new(iomem: IoMem<'hw>) -> impl PinInit<Self, Error> {
iomem,
gate_lock <- new_mutex!(()),
srcu <- kernel::new_srcu!(),
+ closed: Atomic::new(false),
})
}
@@ -60,15 +72,45 @@ pub(crate) fn access(&self) -> HwAccessGuard<'_, 'hw> {
}
}
+ /// Enters a reset-sensitive hardware-access section without sleeping.
+ ///
+ /// Returns `None` while the reset worker owns the hardware, in which case
+ /// the caller must skip its hardware access.
+ #[expect(dead_code)]
+ pub(crate) fn try_access_atomic(&self) -> Option<HwAccessGuard<'_, 'hw>> {
+ let srcu = self.srcu.read_lock();
+
+ // `close()` sets `closed` before waiting for readers, so SRCU guarantees
+ // that this reader either sees it set or is waited for.
+ if self.closed.load(Relaxed) {
+ return None;
+ }
+
+ Some(HwAccessGuard {
+ gate: self,
+ _srcu: srcu,
+ })
+ }
+
/// Stops new readers and drains admitted readers for the reset worker.
///
/// Callers must serialize write-side access. The reset controller's state
/// machine provides that serialization.
+ ///
+ /// An IRQ handler that uses [`HwGate::try_access_atomic`] cannot acknowledge
+ /// its interrupt while the gate is closed. Callers must mask such an
+ /// interrupt before closing the gate and keep it masked until the gate
+ /// reopens.
pub(super) fn close(&self) -> HwClosedGuard<'_, 'hw> {
let gate_lock = self.gate_lock.lock();
- // Holding `gate_lock` prevents new readers from entering SRCU. Readers
- // admitted before us are enrolled, so wait for their read-side work.
+ // Stop `try_access_atomic()` readers. This must happen before waiting
+ // for readers below.
+ self.closed.store(true, Relaxed);
+
+ // Holding `gate_lock` prevents new readers from entering SRCU through
+ // `access()`. Readers admitted before us are enrolled, so wait for their
+ // read-side work.
self.srcu.synchronize();
HwClosedGuard {
@@ -104,3 +146,12 @@ pub(super) fn iomem(&self) -> &IoMem<'hw> {
&self.gate.iomem
}
}
+
+impl Drop for HwClosedGuard<'_, '_> {
+ fn drop(&mut self) {
+ // Reopen for `try_access_atomic()`. A reader that races with this and
+ // still sees `closed` set returns `None`, as it would have before the
+ // store.
+ self.gate.closed.store(false, Relaxed);
+ }
+}
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v7 2/3] drm/tyr: add TyrIrq threaded IRQ wrapper
2026-11-23 14:58 [PATCH v7 0/3] drm/tyr: add Job IRQ handling Laura Nao
2026-11-23 14:58 ` [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic() Laura Nao
@ 2026-11-23 14:58 ` Laura Nao
2026-11-23 14:58 ` [PATCH v7 3/3] drm/tyr: add Job IRQ handling Laura Nao
2 siblings, 0 replies; 5+ messages in thread
From: Laura Nao @ 2026-11-23 14:58 UTC (permalink / raw)
To: Daniel Almeida, Alice Ryhl, Danilo Krummrich, David Airlie,
Simona Vetter, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Tamir Duberstein, Alexandre Courbot,
Onur Özkan
Cc: linux-kernel, dri-devel, rust-for-linux, kernel, Laura Nao,
Deborah Brouwer
Introduce a generic TyrIrq threaded IRQ wrapper along with the
TyrIrqTrait trait describing the operations required to handle a
Tyr interrupt source.
Co-developed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Co-developed-by: Deborah Brouwer <deborah.brouwer@collabora.com>
Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/gpu/drm/tyr/irq.rs | 270 +++++++++++++++++++++++++++++++++++
drivers/gpu/drm/tyr/reset/hw_gate.rs | 1 -
drivers/gpu/drm/tyr/tyr.rs | 1 +
3 files changed, 271 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tyr/irq.rs b/drivers/gpu/drm/tyr/irq.rs
new file mode 100644
index 000000000000..4a065c6272c5
--- /dev/null
+++ b/drivers/gpu/drm/tyr/irq.rs
@@ -0,0 +1,270 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
+
+//! Threaded IRQ wrapper shared by all Tyr interrupt sources.
+#![allow(dead_code)]
+use core::marker::PhantomPinned;
+
+use kernel::{
+ device::Bound,
+ interrupt::LocalInterruptDisabled,
+ irq::{
+ Flags,
+ IrqReturn,
+ ThreadedHandler,
+ ThreadedIrqReturn,
+ ThreadedRegistration, //
+ },
+ platform,
+ prelude::*,
+ sync::{
+ atomic::{
+ ordering:: {
+ Full,
+ Release, //
+ },
+ Atomic,
+ AtomicType, //
+ },
+ Arc,
+ SpinLockIrq, //
+ }, //
+};
+
+use crate::{
+ driver::IoMem,
+ reset::HwGate, //
+};
+
+/// Trait describing the operations required to service a Tyr interrupt source.
+pub(crate) trait TyrIrqTrait: Sync {
+ /// Returns the masked interrupt status.
+ fn read_status(&self, io: &IoMem<'_>) -> u32;
+
+ /// Clears all bits in the mask register, disabling the interrupt sources.
+ fn clear_mask(&self, io: &IoMem<'_>);
+
+ /// Sets the mask register to re-enable the interrupt sources.
+ fn reenable_mask(&self, io: &IoMem<'_>);
+
+ /// Returns the raw interrupt status, regardless of the current mask.
+ fn read_raw_status(&self, io: &IoMem<'_>) -> u32;
+
+ /// Clears the given bits in the interrupt status register.
+ fn clear_status(&self, io: &IoMem<'_>, status: u32);
+
+ /// Returns the bitmask of interrupt sources handled by this instance.
+ fn mask(&self) -> u32;
+
+ /// Handles the given pending, unmasked interrupt bits.
+ fn handle(&self, status: u32);
+}
+
+/// State shared between a [`TyrIrq`] and its [`TyrIrqRegistration`], used to
+/// coordinate the primary handler, the threaded handler, and teardown.
+#[derive(Clone, Copy, PartialEq, Eq)]
+#[repr(i32)]
+enum IrqState {
+ /// Active and ready to process new events.
+ Active = 0,
+ /// A primary handler has claimed a pending event and the threaded handler is running, or
+ /// about to run, to service it.
+ Processing,
+ // Being deregistered: the mask has been, or is being, cleared, and no
+ // handler may re-enable it.
+ Unregistering,
+}
+
+// SAFETY: `IrqState` and `i32` has the same size and alignment, and it's round-trip
+// transmutable to `i32`.
+unsafe impl AtomicType for IrqState {
+ type Repr = i32;
+}
+
+/// A threaded IRQ wrapper shared by all Tyr interrupt sources.
+#[pin_data]
+pub(crate) struct TyrIrq<'a, T: TyrIrqTrait> {
+ /// The interrupt source.
+ irq: T,
+ /// Shared gate that coordinates hardware access with GPU reset.
+ hw: Arc<HwGate<'a>>,
+ /// Current state.
+ state: Atomic<IrqState>,
+ #[pin]
+ lock: SpinLockIrq<()>,
+ #[pin]
+ _pin: PhantomPinned,
+}
+
+impl<'a, T: TyrIrqTrait> TyrIrq<'a, T> {
+ /// Requests a threaded IRQ registration for `irq`, using `name` to look up the interrupt.
+ /// Returns the shared [`IrqState`] alongside the registration.
+ ///
+ /// # Safety
+ ///
+ /// Callers must not `mem::forget()` the resulting registration or otherwise prevent its
+ /// [`Drop`] implementation from running.
+ unsafe fn request(
+ pdev: &'a platform::Device<Bound>,
+ name: &'static CStr,
+ irq: T,
+ hw: Arc<HwGate<'a>>,
+ ) -> Result<impl PinInit<ThreadedRegistration<'a, Self>, Error> + 'a>
+ where
+ T: 'a,
+ {
+ let state = Atomic::new(IrqState::Active);
+
+ let handler = try_pin_init!(Self {
+ irq,
+ hw,
+ state,
+ lock <- kernel::new_spinlock_irq!(()),
+ _pin: PhantomPinned,
+ });
+
+ // SAFETY: The caller guarantees the resulting registration will not be leaked.
+ let registration =
+ unsafe { pdev.request_threaded_irq_by_name(Flags::SHARED, name, name, handler) };
+
+ // Clear the status and unmask once the handler has been
+ // successfully registered.
+ Ok(registration.pin_chain(|reg| {
+ let handler = reg.handler();
+ let hw_guard = handler.hw.access();
+ let io = hw_guard.iomem();
+ let irq = &handler.irq;
+ irq.clear_status(io, irq.mask());
+ irq.reenable_mask(io);
+ Ok(())
+ }))
+ }
+}
+
+impl<T: TyrIrqTrait> ThreadedHandler for TyrIrq<'_, T> {
+ fn handle(&self) -> ThreadedIrqReturn {
+ // SAFETY: `handle()` is the hard IRQ handler, so interrupts are already
+ // disabled.
+ let token = unsafe { LocalInterruptDisabled::assume_disabled() };
+ let _guard = self.lock.lock_with(token);
+
+ // Only proceed if still `Active`. If `Unregistering`, the IRQ is being
+ // torn down and must not be handled.
+ if self
+ .state
+ .cmpxchg(IrqState::Active, IrqState::Processing, Full)
+ .is_err()
+ {
+ return ThreadedIrqReturn::None;
+ }
+
+ let Some(hw_guard) = self.hw.try_access_atomic() else {
+ let _ = self
+ .state
+ .cmpxchg(IrqState::Processing, IrqState::Active, Full);
+ return ThreadedIrqReturn::None;
+ };
+ let io = hw_guard.iomem();
+
+ let masked_status = self.irq.read_status(io);
+
+ if masked_status == 0 {
+ // Go back to `Active`, unless the IRQ is being torn down.
+ let _ = self
+ .state
+ .cmpxchg(IrqState::Processing, IrqState::Active, Full);
+ return ThreadedIrqReturn::None;
+ }
+
+ self.irq.clear_mask(io);
+ ThreadedIrqReturn::WakeThread
+ }
+
+ fn handle_threaded(&self) -> IrqReturn {
+ let mut ret = IrqReturn::None;
+
+ loop {
+ let hw_guard = self.hw.access();
+ let io = hw_guard.iomem();
+ let raw_status = self.irq.read_raw_status(io) & self.irq.mask();
+ if raw_status == 0 {
+ break;
+ }
+ self.irq.clear_status(io, raw_status);
+ drop(hw_guard);
+ self.irq.handle(raw_status);
+ ret = IrqReturn::Handled;
+ }
+
+ // Only re-enable the mask if still `Processing`. If `Unregistering`, the
+ // IRQ is being torn down and must stay masked.
+ let hw_guard = self.hw.access();
+ let _guard = self.lock.lock();
+ if self
+ .state
+ .cmpxchg(IrqState::Processing, IrqState::Active, Full)
+ .is_ok()
+ {
+ self.irq.reenable_mask(hw_guard.iomem());
+ }
+
+ ret
+ }
+}
+
+// A [`ThreadedRegistration`] for a Tyr interrupt source and its state.
+
+// Unlike a bare [`ThreadedRegistration`], dropping this type is always
+// safe to do while the device remains on a shared IRQ line: its `Drop`
+// implementation masks the interrupt source, and notifies teardown via the
+// shared [`IrqState`], before the inner [`ThreadedRegistration`] is
+// dropped and deregisters the handler.
+#[pin_data(PinnedDrop)]
+pub(crate) struct TyrIrqRegistration<'a, T: TyrIrqTrait> {
+ #[pin]
+ registration: ThreadedRegistration<'a, TyrIrq<'a, T>>,
+}
+
+#[pinned_drop]
+impl<T: TyrIrqTrait> PinnedDrop for TyrIrqRegistration<'_, T> {
+ fn drop(self: Pin<&mut Self>) {
+ // Flag teardown and mask the interrupt source, before
+ // `self.registration`'s own `PinnedDrop` runs next and calls `free_irq()`.
+ // This prevents the hardware from asserting the interrupt again once it is
+ // deregistered. `free_irq()` itself waits for any handler already in
+ // flight to complete, and having already flagged `Unregistering`, such a
+ // handler will not re-enable the mask (see `TyrIrq::handle_threaded`).
+ let handler = self.registration.handler();
+ let hw_guard = handler.hw.access();
+ let _guard = handler.lock.lock();
+ handler.state.store(IrqState::Unregistering, Release);
+ handler.irq.clear_mask(hw_guard.iomem());
+ }
+}
+
+impl<'a, T: TyrIrqTrait> TyrIrqRegistration<'a, T> {
+ /// Requests a threaded IRQ registration for `irq`, using `name` to look up the interrupt.
+ ///
+ /// # Safety
+ ///
+ /// Callers must not `mem::forget()` the resulting registration or otherwise prevent its
+ /// [`Drop`] implementation from running.
+ pub(crate) unsafe fn request(
+ pdev: &'a platform::Device<Bound>,
+ name: &'static CStr,
+ irq: T,
+ hw: Arc<HwGate<'a>>,
+ ) -> Result<Pin<KBox<Self>>>
+ where
+ T: 'a,
+ {
+ // SAFETY: The caller guarantees the resulting registration will not be leaked.
+ let registration = unsafe { TyrIrq::request(pdev, name, irq, hw) }?;
+
+ KBox::try_pin_init(
+ try_pin_init!(Self {
+ registration <- registration,
+ }),
+ GFP_KERNEL,
+ )
+ }
+}
diff --git a/drivers/gpu/drm/tyr/reset/hw_gate.rs b/drivers/gpu/drm/tyr/reset/hw_gate.rs
index 40b38f07c472..2157b4b8ba78 100644
--- a/drivers/gpu/drm/tyr/reset/hw_gate.rs
+++ b/drivers/gpu/drm/tyr/reset/hw_gate.rs
@@ -76,7 +76,6 @@ pub(crate) fn access(&self) -> HwAccessGuard<'_, 'hw> {
///
/// Returns `None` while the reset worker owns the hardware, in which case
/// the caller must skip its hardware access.
- #[expect(dead_code)]
pub(crate) fn try_access_atomic(&self) -> Option<HwAccessGuard<'_, 'hw>> {
let srcu = self.srcu.read_lock();
diff --git a/drivers/gpu/drm/tyr/tyr.rs b/drivers/gpu/drm/tyr/tyr.rs
index 9d995650be81..b112cc8a5573 100644
--- a/drivers/gpu/drm/tyr/tyr.rs
+++ b/drivers/gpu/drm/tyr/tyr.rs
@@ -12,6 +12,7 @@
mod fw;
mod gem;
mod gpu;
+mod irq;
mod mmu;
mod regs;
mod reset;
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v7 3/3] drm/tyr: add Job IRQ handling
2026-11-23 14:58 [PATCH v7 0/3] drm/tyr: add Job IRQ handling Laura Nao
2026-11-23 14:58 ` [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic() Laura Nao
2026-11-23 14:58 ` [PATCH v7 2/3] drm/tyr: add TyrIrq threaded IRQ wrapper Laura Nao
@ 2026-11-23 14:58 ` Laura Nao
2 siblings, 0 replies; 5+ messages in thread
From: Laura Nao @ 2026-11-23 14:58 UTC (permalink / raw)
To: Daniel Almeida, Alice Ryhl, Danilo Krummrich, David Airlie,
Simona Vetter, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Tamir Duberstein, Alexandre Courbot,
Onur Özkan
Cc: linux-kernel, dri-devel, rust-for-linux, kernel, Laura Nao,
Deborah Brouwer
The Job IRQ reports requests from the CSF firmware, including global
interface requests and CSG attention bits. Only the GLB bit is currently
handled, as it will be used to check firmware readiness. CSG bits
handling will be added at a later stage. The Job IRQ handler masks the
interrupt in the primary IRQ handler, processes pending raw status in
the threaded handler, clears the handled bits, and reenables the mask
before returning.
Add JobIrqEvents to hold the wait queue and the ready flag used to
signal firmware readiness when the GLB bit is set.
Co-developed-by: Daniel Almeida <daniel.almeida@collabora.com>
Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
Co-developed-by: Deborah Brouwer <deborah.brouwer@collabora.com>
Signed-off-by: Deborah Brouwer <deborah.brouwer@collabora.com>
Signed-off-by: Laura Nao <laura.nao@collabora.com>
---
drivers/gpu/drm/tyr/fw.rs | 1 +
drivers/gpu/drm/tyr/fw/irq.rs | 148 ++++++++++++++++++++++++++++++++++++++++++
drivers/gpu/drm/tyr/irq.rs | 1 -
3 files changed, 149 insertions(+), 1 deletion(-)
diff --git a/drivers/gpu/drm/tyr/fw.rs b/drivers/gpu/drm/tyr/fw.rs
index f2e0404addf2..ecf2ea171bc9 100644
--- a/drivers/gpu/drm/tyr/fw.rs
+++ b/drivers/gpu/drm/tyr/fw.rs
@@ -69,6 +69,7 @@
vm::Vm, //
};
+pub(crate) mod irq;
mod parser;
pub(super) const CSF_MCU_SHARED_REGION_START: u32 = 0x04000000;
diff --git a/drivers/gpu/drm/tyr/fw/irq.rs b/drivers/gpu/drm/tyr/fw/irq.rs
new file mode 100644
index 000000000000..a736d8cd4374
--- /dev/null
+++ b/drivers/gpu/drm/tyr/fw/irq.rs
@@ -0,0 +1,148 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
+
+//! IRQ handling for the Job IRQ.
+//!
+//! The Job IRQ signals events from the MCU, including global interface acknowledgements.
+#![allow(dead_code)]
+
+use kernel::{
+ device::Bound, //
+ io::Io,
+ new_waitqueue,
+ platform,
+ prelude::*,
+ sync::{
+ atomic::{
+ ordering,
+ Atomic, //
+ },
+ Arc,
+ WaitQueue, //
+ },
+ time::{
+ Delta,
+ Msecs, //
+ },
+};
+
+use crate::{
+ irq::{
+ TyrIrqRegistration,
+ TyrIrqTrait, //
+ },
+ regs::job_control::{
+ JOB_IRQ_CLEAR,
+ JOB_IRQ_MASK,
+ JOB_IRQ_RAWSTAT,
+ JOB_IRQ_STATUS, //
+ },
+ driver::IoMem,
+ reset::HwGate, //
+};
+
+/// The firmware events published by the Job IRQ handler, and the queue used to announce them.
+#[pin_data]
+pub(crate) struct JobIrqEvents {
+ #[pin]
+ wait: WaitQueue,
+ /// Set once the firmware has signalled that the global interface is ready.
+ ready: Atomic<bool>,
+}
+
+impl JobIrqEvents {
+ /// Creates a new, empty set of Job IRQ events.
+ pub(crate) fn new() -> Result<Arc<Self>> {
+ Arc::pin_init(
+ pin_init!(JobIrqEvents {
+ wait <- new_waitqueue!(),
+ ready: Atomic::new(false),
+ }),
+ GFP_KERNEL,
+ )
+ }
+
+ /// Clears the firmware-ready state.
+ #[expect(dead_code)]
+ pub(crate) fn clear_ready(&self) {
+ self.ready.store(false, ordering::Relaxed);
+ }
+
+ /// Waits until the firmware signals readiness via the GLB IRQ bit, or the timeout expires.
+ pub(crate) fn wait_ready(&self, timeout_ms: Msecs) -> Result {
+ self.wait.wait_event_timeout(
+ || self.ready.load(ordering::Acquire),
+ Delta::from_millis(timeout_ms.into()).to_jiffies_timeout(),
+ )?;
+
+ Ok(())
+ }
+
+ /// Updates state and wakes up waiters
+ fn signal(&self, status: u32) {
+ // TODO: handle other Job IRQ events (e.g. CSG attention bits) here once
+ // support for them is added.
+
+ // The GLB bit only signals firmware readiness once, at power up
+ if JOB_IRQ_RAWSTAT::from_raw(status).glb() && !self.ready.load(ordering::Relaxed) {
+ self.ready.store(true, ordering::Release);
+ }
+
+ self.wait.wake_up_all();
+ }
+}
+
+// The Job IRQ, signalling requests or notification from the MCU.
+pub(crate) struct JobIrq {
+ /// Firmware events signalled by this IRQ.
+ events: Arc<JobIrqEvents>,
+}
+
+
+/// Requests a threaded IRQ registration for the Job IRQ.
+///
+/// # Safety
+///
+/// Callers must not `mem::forget()` the resulting registration or otherwise prevent its
+/// [`Drop`] implementation from running.
+pub(crate) unsafe fn job_irq_init<'a>(
+ pdev: &'a platform::Device<Bound>,
+ hw: Arc<HwGate<'a>>,
+ events: Arc<JobIrqEvents>,
+) -> Result<Pin<KBox<TyrIrqRegistration<'a, JobIrq>>>> {
+ let job_irq = JobIrq { events };
+ // Ensure interrupt sources are disabled until the handler is registered.
+ job_irq.clear_mask(hw.access().iomem());
+
+ // SAFETY: The caller guarantees the resulting registration will not be leaked.
+ unsafe { TyrIrqRegistration::request(pdev, c"job", job_irq, hw) }
+}
+
+impl TyrIrqTrait for JobIrq {
+ fn read_status(&self, io: &IoMem<'_>) -> u32 {
+ io.read(JOB_IRQ_STATUS).into_raw()
+ }
+
+ fn clear_mask(&self, io: &IoMem<'_>) {
+ io.write_reg(JOB_IRQ_MASK::zeroed());
+ }
+
+ fn reenable_mask(&self, io: &IoMem<'_>) {
+ io.write_reg(JOB_IRQ_MASK::from_raw(self.mask()));
+ }
+
+ fn read_raw_status(&self, io: &IoMem<'_>) -> u32 {
+ io.read(JOB_IRQ_RAWSTAT).into_raw()
+ }
+
+ fn clear_status(&self, io: &IoMem<'_>, status: u32) {
+ io.write_reg(JOB_IRQ_CLEAR::from_raw(status));
+ }
+
+ fn mask(&self) -> u32 {
+ JOB_IRQ_MASK::zeroed().with_glb(true).into_raw()
+ }
+
+ fn handle(&self, status: u32) {
+ self.events.signal(status);
+ }
+}
diff --git a/drivers/gpu/drm/tyr/irq.rs b/drivers/gpu/drm/tyr/irq.rs
index 4a065c6272c5..5632f50b0a13 100644
--- a/drivers/gpu/drm/tyr/irq.rs
+++ b/drivers/gpu/drm/tyr/irq.rs
@@ -1,7 +1,6 @@
// SPDX-License-Identifier: GPL-2.0 or MIT
//! Threaded IRQ wrapper shared by all Tyr interrupt sources.
-#![allow(dead_code)]
use core::marker::PhantomPinned;
use kernel::{
--
2.39.5
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic()
2026-11-23 14:58 ` [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic() Laura Nao
@ 2026-11-23 18:13 ` Onur Özkan
0 siblings, 0 replies; 5+ messages in thread
From: Onur Özkan @ 2026-11-23 18:13 UTC (permalink / raw)
To: Laura Nao
Cc: Daniel Almeida, Alice Ryhl, Danilo Krummrich, David Airlie,
Simona Vetter, Miguel Ojeda, Boqun Feng, Gary Guo,
Björn Roy Baron, Benno Lossin, Andreas Hindborg,
Trevor Gross, Tamir Duberstein, Alexandre Courbot, linux-kernel,
dri-devel, rust-for-linux, kernel, Onur Ozkan
On Mon, 23 Nov 2026 15:58:45 +0100
Laura Nao <laura.nao@collabora.com> wrote:
> From: Daniel Almeida <daniel.almeida@collabora.com>
>
> HwGate::access() takes gate_lock, which is a mutex, so it cannot be
> called from atomic context. IRQ handlers need to access the GPU
> registers, and those are only reachable through the gate.
>
> Add HwGate::try_access_atomic(). It enters SRCU without taking gate_lock
> and returns None if the reset worker has closed the gate. close() now
> sets a closed flag before waiting for SRCU readers, and HwClosedGuard
> clears it when dropped. SRCU guarantees that a reader either sees the
> flag set or is waited for.
>
> An IRQ handler that gets None cannot acknowledge its interrupt, so its
> interrupt has to stay masked while the gate is closed. Document this on
> close(). No caller needs to do this yet: the only reset runs at probe,
> before any IRQ handler is registered.
>
> There are no users yet. The Job IRQ handler will be the first one.
>
> Signed-off-by: Daniel Almeida <daniel.almeida@collabora.com>
LGTM
Reviewed-by: Onur Ozkan <work@onurozkan.dev>
> ---
> drivers/gpu/drm/tyr/reset/hw_gate.rs | 55 ++++++++++++++++++++++++++++++++++--
> 1 file changed, 53 insertions(+), 2 deletions(-)
>
> diff --git a/drivers/gpu/drm/tyr/reset/hw_gate.rs b/drivers/gpu/drm/tyr/reset/hw_gate.rs
> index 201f8c953078..40b38f07c472 100644
> --- a/drivers/gpu/drm/tyr/reset/hw_gate.rs
> +++ b/drivers/gpu/drm/tyr/reset/hw_gate.rs
> @@ -6,10 +6,18 @@
> //! access with reset. Readers hold the mutex while entering SRCU, then release
> //! it before accessing hardware. The reset worker holds the mutex while waiting
> //! for admitted readers and resetting hardware.
> +//!
> +//! Readers that cannot sleep use [`HwGate::try_access_atomic`] instead. It
> +//! enters SRCU without taking the mutex and fails if the reset worker has set
> +//! `closed`, which it does before waiting for readers.
>
> use kernel::{
> prelude::*,
> sync::{
> + atomic::{
> + Atomic,
> + Relaxed, //
> + },
> new_mutex,
> srcu,
> Mutex,
> @@ -32,6 +40,9 @@ pub(crate) struct HwGate<'hw> {
> /// Drains readers that entered before the reset worker acquired `gate_lock`.
> #[pin]
> srcu: Srcu,
> + /// Set while the reset worker owns the hardware. Checked by readers that
> + /// cannot take `gate_lock`.
> + closed: Atomic<bool>,
> }
>
> impl<'hw> HwGate<'hw> {
> @@ -41,6 +52,7 @@ pub(crate) fn new(iomem: IoMem<'hw>) -> impl PinInit<Self, Error> {
> iomem,
> gate_lock <- new_mutex!(()),
> srcu <- kernel::new_srcu!(),
> + closed: Atomic::new(false),
> })
> }
>
> @@ -60,15 +72,45 @@ pub(crate) fn access(&self) -> HwAccessGuard<'_, 'hw> {
> }
> }
>
> + /// Enters a reset-sensitive hardware-access section without sleeping.
> + ///
> + /// Returns `None` while the reset worker owns the hardware, in which case
> + /// the caller must skip its hardware access.
> + #[expect(dead_code)]
> + pub(crate) fn try_access_atomic(&self) -> Option<HwAccessGuard<'_, 'hw>> {
> + let srcu = self.srcu.read_lock();
> +
> + // `close()` sets `closed` before waiting for readers, so SRCU guarantees
> + // that this reader either sees it set or is waited for.
> + if self.closed.load(Relaxed) {
> + return None;
> + }
> +
> + Some(HwAccessGuard {
> + gate: self,
> + _srcu: srcu,
> + })
> + }
> +
> /// Stops new readers and drains admitted readers for the reset worker.
> ///
> /// Callers must serialize write-side access. The reset controller's state
> /// machine provides that serialization.
> + ///
> + /// An IRQ handler that uses [`HwGate::try_access_atomic`] cannot acknowledge
> + /// its interrupt while the gate is closed. Callers must mask such an
> + /// interrupt before closing the gate and keep it masked until the gate
> + /// reopens.
> pub(super) fn close(&self) -> HwClosedGuard<'_, 'hw> {
> let gate_lock = self.gate_lock.lock();
>
> - // Holding `gate_lock` prevents new readers from entering SRCU. Readers
> - // admitted before us are enrolled, so wait for their read-side work.
> + // Stop `try_access_atomic()` readers. This must happen before waiting
> + // for readers below.
> + self.closed.store(true, Relaxed);
> +
> + // Holding `gate_lock` prevents new readers from entering SRCU through
> + // `access()`. Readers admitted before us are enrolled, so wait for their
> + // read-side work.
> self.srcu.synchronize();
>
> HwClosedGuard {
> @@ -104,3 +146,12 @@ pub(super) fn iomem(&self) -> &IoMem<'hw> {
> &self.gate.iomem
> }
> }
> +
> +impl Drop for HwClosedGuard<'_, '_> {
> + fn drop(&mut self) {
> + // Reopen for `try_access_atomic()`. A reader that races with this and
> + // still sees `closed` set returns `None`, as it would have before the
> + // store.
> + self.gate.closed.store(false, Relaxed);
> + }
> +}
>
> --
> 2.39.5
>
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2026-11-23 18:13 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-23 14:58 [PATCH v7 0/3] drm/tyr: add Job IRQ handling Laura Nao
2026-11-23 14:58 ` [PATCH v7 1/3] drm/tyr: add HwGate::try_access_atomic() Laura Nao
2026-11-23 18:13 ` Onur Özkan
2026-11-23 14:58 ` [PATCH v7 2/3] drm/tyr: add TyrIrq threaded IRQ wrapper Laura Nao
2026-11-23 14:58 ` [PATCH v7 3/3] drm/tyr: add Job IRQ handling Laura Nao
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®