[PATCH 5/9] drm/tyr: use FLUSH_CACHES instead of FLUSH_PT
From: Daniel Almeida
Date: Fri Nov 27 2026 - 21:16:55 EST
Tyr cleans and invalidates the L2 cache with FLUSH_PT, an address space
command that is deprecated from Mali-Gx20 onwards.
Use GPU_COMMAND FLUSH_CACHES followed by UNLOCK instead, like panthor
did in commit dd11c7dec74b ("drm/panthor: Make MMU cache maintenance use
FLUSH_CACHES command"). Also clean and invalidate the load/store caches,
which FLUSH_PT left alone, since after an unmap they can still hold gpu
writes to the unmapped pages, which must not be written back once the
pages are freed. Panthor does the same since commit 6e2d3b3e8589
("drm/panthor: Add support for atomic page table updates").
Signed-off-by: Daniel Almeida <daniel.almeida@xxxxxxxxxxxxx>
---
drivers/gpu/drm/tyr/gpu/irq.rs | 2 ++
drivers/gpu/drm/tyr/mmu/address_space.rs | 36 ++++++++++++++++++++++++++++++--
2 files changed, 36 insertions(+), 2 deletions(-)
diff --git a/drivers/gpu/drm/tyr/gpu/irq.rs b/drivers/gpu/drm/tyr/gpu/irq.rs
index 3dd1f634c847..91166d77cd9b 100644
--- a/drivers/gpu/drm/tyr/gpu/irq.rs
+++ b/drivers/gpu/drm/tyr/gpu/irq.rs
@@ -90,6 +90,8 @@ fn clear_status(&self, io: &IoMem<'_>, status: u32) {
fn mask(&self) -> u32 {
// Only GPU faults are handled. DOORBELL_MIRROR must stay masked because
// GPU_IRQ_CLEAR cannot clear it.
+ // CLEAN_CACHES_COMPLETED must stay masked because the MMU's cache flush
+ // polls it.
GPU_IRQ_MASK::zeroed().with_gpu_fault(true).into_raw()
}
diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs b/drivers/gpu/drm/tyr/mmu/address_space.rs
index 34f5481a6957..d266beec7b40 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -45,6 +45,12 @@
Mmu, //
},
regs::{
+ gpu_control::{
+ FlushMode,
+ GPU_COMMAND,
+ GPU_IRQ_CLEAR,
+ GPU_IRQ_RAWSTAT, //
+ },
mmu_control::mmu_as_control,
mmu_control::mmu_as_control::*,
MAX_AS, //
@@ -425,7 +431,8 @@ fn as_start_update(&mut self, io: &IoMem<'_>, as_nr: usize, region: &Range<u64>)
/// Returns an error if the slot is invalid or if the flush command fails.
fn as_end_update(&mut self, io: &IoMem<'_>, as_nr: usize) -> Result {
self.validate_as_slot(as_nr)?;
- self.as_send_cmd_and_wait(io, as_nr, MmuCommand::FlushPt)?;
+ self.flush_caches(io)?;
+ self.as_send_cmd_and_wait(io, as_nr, MmuCommand::Unlock)?;
Ok(())
}
@@ -434,7 +441,32 @@ fn as_end_update(&mut self, io: &IoMem<'_>, as_nr: usize) -> Result {
/// Returns an error if the slot is invalid or if the flush command fails.
fn as_flush(&mut self, io: &IoMem<'_>, as_nr: usize) -> Result {
self.validate_as_slot(as_nr)?;
- self.as_send_cmd_and_wait(io, as_nr, MmuCommand::FlushPt)
+ self.flush_caches(io)?;
+ self.as_send_cmd_and_wait(io, as_nr, MmuCommand::Unlock)
+ }
+
+ /// Cleans and invalidates the L2 and load/store caches, and waits until that completes.
+ ///
+ /// Taking `&mut self` keeps calls from overlapping.
+ fn flush_caches(&mut self, io: &IoMem<'_>) -> Result {
+ io.write_reg(GPU_IRQ_CLEAR::zeroed().with_clean_caches_completed(true));
+ io.write_reg(GPU_COMMAND::flush_caches(
+ FlushMode::CleanInvalidate,
+ FlushMode::CleanInvalidate,
+ FlushMode::None,
+ ));
+
+ // The GPU IRQ leaves CLEAN_CACHES_COMPLETED masked, so its handler does
+ // not clear the bit under this poll.
+ poll::read_poll_timeout(
+ || Ok(io.read(GPU_IRQ_RAWSTAT)),
+ |status| status.clean_caches_completed(),
+ Delta::from_micros(50),
+ Delta::from_millis(100),
+ )
+ .inspect_err(|_| dev_err!(self.dev, "GPU cache flush timed out\n"))?;
+
+ Ok(())
}
}
--
2.56.0