The mmu IRQ reports page faults and completed commands for each address
space. Tyr does not request it, so nothing can report an mmu page fault.

Add MmuIrq, a TyrIrqTrait implementation for the MMU_CONTROL IRQ
registers, and request the "mmu" interrupt in probe before the firmware
is loaded. Keep the registration in TyrDrmRegistrationData ahead of the
clocks and regulators, since dropping it writes the IRQ mask through
MMIO, which needs them enabled.

All interrupt sources stay masked for now. The next patch unmasks and
reports page faults.

Signed-off-by: Daniel Almeida <[email protected]>
---
 drivers/gpu/drm/tyr/driver.rs  | 18 +++++++++-
 drivers/gpu/drm/tyr/mmu.rs     |  1 +
 drivers/gpu/drm/tyr/mmu/irq.rs | 77 ++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 95 insertions(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/tyr/driver.rs b/drivers/gpu/drm/tyr/driver.rs
index 9aa536b16972..44ff1f522902 100644
--- a/drivers/gpu/drm/tyr/driver.rs
+++ b/drivers/gpu/drm/tyr/driver.rs
@@ -34,7 +34,14 @@
     fw::Firmware,
     gem::Bo,
     gpu::GpuInfo,
-    mmu::Mmu,
+    irq::TyrIrqRegistration,
+    mmu::{
+        irq::{
+            mmu_irq_init,
+            MmuIrq, //
+        },
+        Mmu, //
+    },
     regs::gpu_control::*,
     reset, //
 };
@@ -73,6 +80,10 @@ pub(crate) struct TyrDrmRegistrationData<'drm> {
     /// Firmware sections.
     pub(crate) fw: Firmware<'drm>,
 
+    // `TyrIrqRegistration::drop()` writes to the GPU registers, so keep this
+    // field before the clocks and regulators.
+    _mmu_irq: Pin<KBox<TyrIrqRegistration<'drm, MmuIrq>>>,
+
     #[pin]
     clks: Mutex<Clocks>,
 
@@ -142,6 +153,10 @@ fn probe<'bound>(
 
             let mmu = Mmu::new(pdev.as_ref(), hw.clone(), &gpu_info)?;
 
+            // SAFETY: The registration ends up in `TyrDrmRegistrationData`, 
which `_reg`
+            // drops at unbind, and every error path before that drops it.
+            let mmu_irq = unsafe { mmu_irq_init(pdev, hw.clone()) }?;
+
             let firmware = Firmware::new(
                 pdev.as_ref(),
                 hw.clone(),
@@ -164,6 +179,7 @@ fn probe<'bound>(
                         // so reset work is drained before borrowed data 
expires.
                         reset <- reset::ResetHandle::new(pdev, hw.clone()),
                         fw: firmware,
+                        _mmu_irq: mmu_irq,
                         clks <- new_mutex!(Clocks {
                             core: core_clk,
                             stacks: stacks_clk,
diff --git a/drivers/gpu/drm/tyr/mmu.rs b/drivers/gpu/drm/tyr/mmu.rs
index adac036744a3..f095c3374e3a 100644
--- a/drivers/gpu/drm/tyr/mmu.rs
+++ b/drivers/gpu/drm/tyr/mmu.rs
@@ -42,6 +42,7 @@
 };
 
 pub(crate) mod address_space;
+pub(crate) mod irq;
 
 pub(crate) type AsSlotManager<'drm> = SlotManager<AddressSpaceManager<'drm>, 
MAX_AS>;
 
diff --git a/drivers/gpu/drm/tyr/mmu/irq.rs b/drivers/gpu/drm/tyr/mmu/irq.rs
new file mode 100644
index 000000000000..7f8b02613e9e
--- /dev/null
+++ b/drivers/gpu/drm/tyr/mmu/irq.rs
@@ -0,0 +1,77 @@
+// SPDX-License-Identifier: GPL-2.0 or MIT
+
+//! IRQ handling for the MMU IRQ.
+//!
+//! The MMU IRQ reports page faults and completed commands for each address 
space.
+
+use kernel::{
+    device::Bound,
+    io::Io,
+    platform,
+    prelude::*,
+    sync::Arc, //
+};
+
+use crate::{
+    driver::IoMem,
+    irq::{
+        TyrIrqRegistration,
+        TyrIrqTrait, //
+    },
+    regs::mmu_control::{
+        IRQ_CLEAR,
+        IRQ_MASK,
+        IRQ_RAWSTAT,
+        IRQ_STATUS, //
+    },
+    reset::HwGate, //
+};
+
+/// The MMU IRQ, signalling events from the address spaces.
+pub(crate) struct MmuIrq;
+
+/// Requests a threaded IRQ registration for the MMU IRQ.
+///
+/// # Safety
+///
+/// Callers must not `mem::forget()` the resulting registration or otherwise 
prevent its
+/// [`Drop`] implementation from running.
+pub(crate) unsafe fn mmu_irq_init<'a>(
+    pdev: &'a platform::Device<Bound>,
+    hw: Arc<HwGate<'a>>,
+) -> Result<Pin<KBox<TyrIrqRegistration<'a, MmuIrq>>>> {
+    let mmu_irq = MmuIrq;
+    // Ensure interrupt sources are disabled until the handler is registered.
+    mmu_irq.clear_mask(hw.access().iomem());
+
+    // SAFETY: The caller guarantees the resulting registration will not be 
leaked.
+    unsafe { TyrIrqRegistration::request(pdev, c"mmu", c"tyr-mmu", mmu_irq, 
hw) }
+}
+
+impl TyrIrqTrait for MmuIrq {
+    fn read_status(&self, io: &IoMem<'_>) -> u32 {
+        io.read(IRQ_STATUS).into_raw()
+    }
+
+    fn clear_mask(&self, io: &IoMem<'_>) {
+        io.write_reg(IRQ_MASK::zeroed());
+    }
+
+    fn reenable_mask(&self, io: &IoMem<'_>) {
+        io.write_reg(IRQ_MASK::from_raw(self.mask()));
+    }
+
+    fn read_raw_status(&self, io: &IoMem<'_>) -> u32 {
+        io.read(IRQ_RAWSTAT).into_raw()
+    }
+
+    fn clear_status(&self, io: &IoMem<'_>, status: u32) {
+        io.write_reg(IRQ_CLEAR::from_raw(status));
+    }
+
+    fn mask(&self) -> u32 {
+        IRQ_MASK::zeroed().into_raw()
+    }
+
+    fn handle(&self, _status: u32) {}
+}

-- 
2.56.0

Reply via email to