[Intel-gfx] [PATCH 1/4] drm/i915: Introduce for_each_fence_reg()

Zhi Wang zhi.a.wang at intel.com
Tue Jun 28 13:51:42 UTC 2016


Introduce a macro for iterating all fence registers.

Cc: Joonas Lahtinen <joonas.lahtinen at linux.intel.com>
Cc: Tvrtko Ursulin <tvrtko.ursulin at linux.intel.com>
Cc: Chris Wilson <chris at chris-wilson.co.uk>
Signed-off-by: Zhi Wang <zhi.a.wang at intel.com>
---
 drivers/gpu/drm/i915/i915_drv.h       | 4 ++++
 drivers/gpu/drm/i915/i915_gem_fence.c | 8 +++-----
 2 files changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
index 9ef4919..2d88e7e 100644
--- a/drivers/gpu/drm/i915/i915_drv.h
+++ b/drivers/gpu/drm/i915/i915_drv.h
@@ -459,6 +459,10 @@ struct drm_i915_fence_reg {
 	int pin_count;
 };
 
+#define for_each_fence_reg(dev_priv, reg, index) \
+	for ((index) = 0, (reg) = &dev_priv->fence_regs[index]; \
+	     (index) < dev_priv->num_fence_regs; (index)++, (reg)++)
+
 struct sdvo_device_mapping {
 	u8 initialized;
 	u8 dvo_port;
diff --git a/drivers/gpu/drm/i915/i915_gem_fence.c b/drivers/gpu/drm/i915/i915_gem_fence.c
index 2b6bdc2..1dfb09b 100644
--- a/drivers/gpu/drm/i915/i915_gem_fence.c
+++ b/drivers/gpu/drm/i915/i915_gem_fence.c
@@ -317,8 +317,7 @@ i915_find_fence_reg(struct drm_device *dev)
 
 	/* First try to find a free reg */
 	avail = NULL;
-	for (i = 0; i < dev_priv->num_fence_regs; i++) {
-		reg = &dev_priv->fence_regs[i];
+	for_each_fence_reg(dev_priv, reg, i) {
 		if (!reg->obj)
 			return reg;
 
@@ -473,11 +472,10 @@ i915_gem_object_unpin_fence(struct drm_i915_gem_object *obj)
 void i915_gem_restore_fences(struct drm_device *dev)
 {
 	struct drm_i915_private *dev_priv = dev->dev_private;
+	struct drm_i915_fence_reg *reg;
 	int i;
 
-	for (i = 0; i < dev_priv->num_fence_regs; i++) {
-		struct drm_i915_fence_reg *reg = &dev_priv->fence_regs[i];
-
+	for_each_fence_reg(dev_priv, reg, i) {
 		/*
 		 * Commit delayed tiling changes if we have an object still
 		 * attached to the fence, otherwise just clear the fence.
-- 
1.9.1



More information about the Intel-gfx mailing list