When a cache flush times out, the next call to flush_caches() issues a
new FLUSH_CACHES while the first one may still be pending, which has an
undefined result in the hardware.

Track the pending flush and return -EIO until the gpu reports it
complete, like panthor does since commit 3c0a60195b37 ("drm/panthor:
Recover from panthor_gpu_flush_caches() failures").

Signed-off-by: Daniel Almeida <[email protected]>
---
 drivers/gpu/drm/tyr/mmu/address_space.rs | 13 +++++++++++++
 1 file changed, 13 insertions(+)

diff --git a/drivers/gpu/drm/tyr/mmu/address_space.rs 
b/drivers/gpu/drm/tyr/mmu/address_space.rs
index d266beec7b40..fc617f282cbe 100644
--- a/drivers/gpu/drm/tyr/mmu/address_space.rs
+++ b/drivers/gpu/drm/tyr/mmu/address_space.rs
@@ -167,6 +167,9 @@ pub(crate) struct AddressSpaceManager<'drm> {
 
     /// Bitmask of present address space slots from GPU_AS_PRESENT register.
     as_present: u32,
+
+    /// Whether a cache flush was issued and its completion has not been seen 
yet.
+    flush_pending: bool,
 }
 
 impl<'drm> AddressSpaceManager<'drm> {
@@ -191,6 +194,7 @@ pub(super) fn new(
             dev,
             hw,
             as_present,
+            flush_pending: false,
         })
     }
 
@@ -448,13 +452,21 @@ fn as_flush(&mut self, io: &IoMem<'_>, as_nr: usize) -> 
Result {
     /// Cleans and invalidates the L2 and load/store caches, and waits until 
that completes.
     ///
     /// Taking `&mut self` keeps calls from overlapping.
+    /// A flush that timed out may still be pending, and issuing another one 
then has an undefined
+    /// result, so after such a flush the next ones fail with EIO until the 
GPU reports its
+    /// completion.
     fn flush_caches(&mut self, io: &IoMem<'_>) -> Result {
+        if self.flush_pending && 
!io.read(GPU_IRQ_RAWSTAT).clean_caches_completed() {
+            return Err(EIO);
+        }
+
         
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,
         ));
+        self.flush_pending = true;
 
         // The GPU IRQ leaves CLEAN_CACHES_COMPLETED masked, so its handler 
does
         // not clear the bit under this poll.
@@ -466,6 +478,7 @@ fn flush_caches(&mut self, io: &IoMem<'_>) -> Result {
         )
         .inspect_err(|_| dev_err!(self.dev, "GPU cache flush timed out\n"))?;
 
+        self.flush_pending = false;
         Ok(())
     }
 }

-- 
2.56.0

Reply via email to