From de612e4641b455a649704eca8dee9f797316d107 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= Date: Thu, 29 Oct 2009 01:39:07 +0100 Subject: [PATCH] drm/radeon/kms: fix calculation of free dwords in ring MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When CP_RB_RPTR is lower than CP_RB_WPTR we need other calculation Signed-off-by: Rafał Miłecki --- drivers/gpu/drm/radeon/radeon_ring.c | 12 ++++++++++-- 1 files changed, 10 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/radeon/radeon_ring.c b/drivers/gpu/drm/radeon/radeon_ring.c index 747b4bf..1dd377f 100644 --- a/drivers/gpu/drm/radeon/radeon_ring.c +++ b/drivers/gpu/drm/radeon/radeon_ring.c @@ -226,9 +226,17 @@ void radeon_ring_free_size(struct radeon_device *rdev) rdev->cp.rptr = RREG32(R600_CP_RB_RPTR); else rdev->cp.rptr = RREG32(RADEON_CP_RB_RPTR); + /* This works because ring_size is a power of 2 */ - rdev->cp.ring_free_dw = (rdev->cp.rptr + (rdev->cp.ring_size / 4)); - rdev->cp.ring_free_dw -= rdev->cp.wptr; + if (rdev->cp.wptr >= rdev->cp.rptr) { + /* ring_free_dw = (ring_size / 4) - (wptr - rptr) */ + rdev->cp.ring_free_dw = (rdev->cp.rptr + (rdev->cp.ring_size / 4)); + rdev->cp.ring_free_dw -= rdev->cp.wptr; + } + else { + /* ring_free_dw = rptr - wptr */ + rdev->cp.ring_free_dw = rdev->cp.rptr - rdev->cp.wptr; + } rdev->cp.ring_free_dw &= rdev->cp.ptr_mask; if (!rdev->cp.ring_free_dw) { rdev->cp.ring_free_dw = rdev->cp.ring_size / 4; -- 1.6.4.2