A new helper function which clears the contents of
a ring and the relevant pointers such as rptr/wptr.

Suggested-by: Lijo Lazar <[email protected]>
Signed-off-by: Timur Kristóf <[email protected]>
---
 drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h 
b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
index 61e30de1977b..49df2c4745a1 100644
--- a/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
+++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h
@@ -488,6 +488,25 @@ static inline void amdgpu_ring_clear_ring(struct 
amdgpu_ring *ring)
        memset32(ring->ring, ring->funcs->nop, ring->buf_mask + 1);
 }
 
+static inline void amdgpu_ring_clear_ring_and_ptrs(struct amdgpu_ring *ring)
+{
+       /* Clear the contents of the ring. */
+       amdgpu_ring_clear_ring(ring);
+
+       /* Clear the ring pointers on the CPU. */
+       ring->wptr = 0;
+
+       /*
+        * Clear the ring pointers allocated in writeback.
+        *
+        * Note: we always allocate 64 bits for these pointers,
+        * but older HW generations only use the lower 32 bits.
+        * Use 64-bit atomics for simplicity.
+        */
+       atomic64_set((atomic64_t *)ring->wptr_cpu_addr, 0);
+       atomic64_set((atomic64_t *)ring->rptr_cpu_addr, 0);
+}
+
 static inline void amdgpu_ring_write(struct amdgpu_ring *ring, uint32_t v)
 {
        ring->ring[ring->wptr++ & ring->buf_mask] = v;
-- 
2.55.0

Reply via email to