[Intel-gfx] [PATCH 4/5] drm/i915: more semaphore cleanup

Ben Widawsky ben at bwidawsk.net
Fri Sep 16 04:09:00 CEST 2011


This turns the black magic into brown magic.

It's arguable whether or not this is more readable than the existing
code. It does add a nice assertion, fewer lines of actual code, and some
nice comments - as well as sticking to semantics now used in the
ringbuffer code.

Cc: Daniel Vetter <daniel.vetter at ffwll.ch>
Signed-off-by: Ben Widawsky <ben at bwidawsk.net>
---
 drivers/gpu/drm/i915/intel_ringbuffer.h |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/i915/intel_ringbuffer.h b/drivers/gpu/drm/i915/intel_ringbuffer.h
index 61790c8..e4516e4 100644
--- a/drivers/gpu/drm/i915/intel_ringbuffer.h
+++ b/drivers/gpu/drm/i915/intel_ringbuffer.h
@@ -119,23 +119,21 @@ intel_ring_flag(struct intel_ring_buffer *ring)
 	return (1 << ring->id);
 }
 
+/* intel_ring_sync_index - return the index (0-n, where n is total rings - 1)
+ * of the ring we're synchronizing to.
+ *
+ * @signaller - ring which last updated the mailbox
+ * @waiter - ring waiting on seqno in mailbox
+ */
 static inline u32
-intel_ring_sync_index(struct intel_ring_buffer *ring,
-		      struct intel_ring_buffer *other)
+intel_ring_sync_index(struct intel_ring_buffer *signaller,
+		      struct intel_ring_buffer *waiter)
 {
-	int idx;
-
-	/*
-	 * cs -> 0 = vcs, 1 = bcs
-	 * vcs -> 0 = bcs, 1 = cs,
-	 * bcs -> 0 = cs, 1 = vcs.
+	/* This bit of magic is based on the fact that there are 3 rings, and
+	 * the value of bit 17 is a unique way to identify the mailbox
 	 */
-
-	idx = (other->id - ring->id) - 1;
-	if (idx < 0)
-		idx += I915_NUM_RINGS;
-
-	return idx;
+	BUG_ON(signaller->semaphore_register[waiter->id] >> 17 > 1);
+	return (signaller->semaphore_register[waiter->id] >> 17);
 }
 
 static inline u32
-- 
1.7.6.1




More information about the Intel-gfx mailing list