[Intel-gfx] [PATCH 2/2] drm/i915: ringbuffer: Add a helper function to update ring buffer space

Yuanhan Liu yuanhan.liu at intel.com
Tue Aug 24 12:27:33 CEST 2010


There are several places will calc the space of ring buffer. To make it clear
and simple, define a helper function called intel_ring_update_space to do this.

Signed-off-by: Yuanhan Liu <yuanhan.liu at intel.com>
---
 drivers/gpu/drm/i915/i915_dma.c         |    4 +---
 drivers/gpu/drm/i915/intel_ringbuffer.c |   14 ++++----------
 drivers/gpu/drm/i915/intel_ringbuffer.h |    8 ++++++++
 3 files changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
index c5d6021..aa1f311 100644
--- a/drivers/gpu/drm/i915/i915_dma.c
+++ b/drivers/gpu/drm/i915/i915_dma.c
@@ -109,9 +109,7 @@ void i915_kernel_lost_context(struct drm_device * dev)
 
 	ring->head = ring->get_head(dev, ring);
 	ring->tail = ring->get_tail(dev, ring);
-	ring->space = ring->head - (ring->tail + 8);
-	if (ring->space < 0)
-		ring->space += ring->size;
+	intel_ring_update_space(ring);
 
 	if (!dev->primary->master)
 		return;
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.c b/drivers/gpu/drm/i915/intel_ringbuffer.c
index 0140f80..4a17851 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.c
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.c
@@ -208,9 +208,7 @@ static int init_ring_common(struct drm_device *dev,
 	else {
 		ring->head = ring->get_head(dev, ring);
 		ring->tail = ring->get_tail(dev, ring);
-		ring->space = ring->head - (ring->tail + 8);
-		if (ring->space < 0)
-			ring->space += ring->size;
+		intel_ring_update_space(ring);
 	}
 	return 0;
 }
@@ -666,9 +664,7 @@ int intel_init_ring_buffer(struct drm_device *dev,
 	else {
 		ring->head = ring->get_head(dev, ring);
 		ring->tail = ring->get_tail(dev, ring);
-		ring->space = ring->head - (ring->tail + 8);
-		if (ring->space < 0)
-			ring->space += ring->size;
+		intel_ring_update_space(ring);
 	}
 	INIT_LIST_HEAD(&ring->active_list);
 	INIT_LIST_HEAD(&ring->request_list);
@@ -721,7 +717,7 @@ int intel_wrap_ring_buffer(struct drm_device *dev,
 	}
 
 	ring->tail = 0;
-	ring->space = ring->head - 8;
+	intel_ring_update_space(ring);
 
 	return 0;
 }
@@ -735,9 +731,7 @@ int intel_wait_ring_buffer(struct drm_device *dev,
 	end = jiffies + 3 * HZ;
 	do {
 		ring->head = ring->get_head(dev, ring);
-		ring->space = ring->head - (ring->tail + 8);
-		if (ring->space < 0)
-			ring->space += ring->size;
+		intel_ring_update_space(ring);
 		if (ring->space >= n) {
 			trace_i915_ring_wait_end (dev);
 			return 0;
diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 525e7d3..86d9f2e 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -115,6 +115,14 @@ static inline void intel_ring_emit(struct drm_device *dev,
 	ring->tail += 4;
 }
 
+static inline void intel_ring_update_space(struct intel_ring_buffer *ring)
+{
+	ring->space = ring->head - (ring->tail + 8);
+	if (ring->space < 0)
+		ring->space += ring->size;
+}
+
+
 void intel_fill_struct(struct drm_device *dev,
 		struct intel_ring_buffer *ring,
 		void *data,
-- 
1.7.2.1




More information about the Intel-gfx mailing list