]> git.ipfire.org Git - thirdparty/kernel/linux.git/commitdiff
drm/amdgpu: add a helper to calculate ring distance
authorAlex Deucher <alexander.deucher@amd.com>
Thu, 29 Jan 2026 19:49:13 +0000 (14:49 -0500)
committerAlex Deucher <alexander.deucher@amd.com>
Mon, 23 Feb 2026 19:16:31 +0000 (14:16 -0500)
Add a helper to calculate the distance in DWs between
two wptrs.

Reviewed-by: Pierre-Eric Pelloux-Prayer <pierre-eric.pelloux-prayer@amd.com>
Signed-off-by: Alex Deucher <alexander.deucher@amd.com>
drivers/gpu/drm/amd/amdgpu/amdgpu_ring.h

index cb0fb1a989d2f5791f07df1e7a8dbc405b255e29..1abd8fdb5cef629fe2b33183ba156479a1f2242d 100644 (file)
@@ -522,6 +522,17 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring,
        ring->count_dw -= count_dw;
 }
 
+static inline unsigned int amdgpu_ring_get_dw_distance(struct amdgpu_ring *ring,
+                                                      u64 start_wptr, u64 end_wptr)
+{
+       unsigned int start = start_wptr & ring->buf_mask;
+       unsigned int end = end_wptr & ring->buf_mask;
+
+       if (end < start)
+               end += ring->ring_size >> 2;
+       return end - start;
+}
+
 /**
  * amdgpu_ring_patch_cond_exec - patch dw count of conditional execute
  * @ring: amdgpu_ring structure
@@ -532,18 +543,13 @@ static inline void amdgpu_ring_write_multiple(struct amdgpu_ring *ring,
 static inline void amdgpu_ring_patch_cond_exec(struct amdgpu_ring *ring,
                                               unsigned int offset)
 {
-       unsigned cur;
-
        if (!ring->funcs->init_cond_exec)
                return;
 
        WARN_ON(offset > ring->buf_mask);
        WARN_ON(ring->ring[offset] != 0);
 
-       cur = (ring->wptr - 1) & ring->buf_mask;
-       if (cur < offset)
-               cur += ring->ring_size >> 2;
-       ring->ring[offset] = cur - offset;
+       ring->ring[offset] = amdgpu_ring_get_dw_distance(ring, offset, ring->wptr - 1);
 }
 
 int amdgpu_ring_test_helper(struct amdgpu_ring *ring);