diff mbox

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

Message ID 1282645653-7870-2-git-send-email-yuanhan.liu@intel.com (mailing list archive)
State Deferred, archived
Headers show

Commit Message

Yuanhan Liu Aug. 24, 2010, 10:27 a.m. UTC
None
diff mbox

Patch

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,