diff mbox

[9/9] drm/i915: use drm_mm_for_each_scanned_node_reverse helper

Message ID 1289583401-16605-10-git-send-email-daniel.vetter@ffwll.ch (mailing list archive)
State New, archived
Headers show

Commit Message

Daniel Vetter Nov. 12, 2010, 5:36 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem_evict.c b/drivers/gpu/drm/i915/i915_gem_evict.c
index ea252a4..845b6ad 100644
--- a/drivers/gpu/drm/i915/i915_gem_evict.c
+++ b/drivers/gpu/drm/i915/i915_gem_evict.c
@@ -32,9 +32,8 @@ 
 #include "i915_drm.h"
 
 static bool
-mark_free(struct drm_i915_gem_object *obj, struct list_head *unwind)
+mark_free(struct drm_i915_gem_object *obj)
 {
-	list_add(&obj->evict_list, unwind);
 	drm_gem_object_reference(&obj->base);
 	return drm_mm_scan_add_block(&obj->gtt_space);
 }
@@ -44,8 +43,9 @@  i915_gem_evict_something(struct drm_device *dev, int min_size,
 			 unsigned alignment, bool mappable)
 {
 	drm_i915_private_t *dev_priv = dev->dev_private;
-	struct list_head eviction_list, unwind_list;
+	struct list_head eviction_list;
 	struct drm_i915_gem_object *obj;
+	struct drm_mm_node *node, *next;
 	int ret = 0;
 
 	i915_gem_retire_requests(dev);
@@ -86,7 +86,6 @@  i915_gem_evict_something(struct drm_device *dev, int min_size,
 	 * object on the TAIL.
 	 */
 
-	INIT_LIST_HEAD(&unwind_list);
 	if (mappable)
 		drm_mm_init_scan_with_range(&dev_priv->mm.gtt_space, min_size,
 					    alignment, 0,
@@ -96,7 +95,7 @@  i915_gem_evict_something(struct drm_device *dev, int min_size,
 
 	/* First see if there is a large enough contiguous idle region... */
 	list_for_each_entry(obj, &dev_priv->mm.inactive_list, mm_list) {
-		if (mark_free(obj, &unwind_list))
+		if (mark_free(obj))
 			goto found;
 	}
 
@@ -106,7 +105,7 @@  i915_gem_evict_something(struct drm_device *dev, int min_size,
 		if (obj->base.write_domain || obj->pin_count)
 			continue;
 
-		if (mark_free(obj, &unwind_list))
+		if (mark_free(obj))
 			goto found;
 	}
 
@@ -115,19 +114,22 @@  i915_gem_evict_something(struct drm_device *dev, int min_size,
 		if (obj->pin_count)
 			continue;
 
-		if (mark_free(obj, &unwind_list))
+		if (mark_free(obj))
 			goto found;
 	}
 	list_for_each_entry(obj, &dev_priv->mm.active_list, mm_list) {
 		if (! obj->base.write_domain || obj->pin_count)
 			continue;
 
-		if (mark_free(obj, &unwind_list))
+		if (mark_free(obj))
 			goto found;
 	}
 
 	/* Nothing found, clean up and bail out! */
-	list_for_each_entry(obj, &unwind_list, evict_list) {
+	drm_mm_for_each_scanned_node_reverse(node, next,
+					     &dev_priv->mm.gtt_space) {
+		obj = container_of(node, struct drm_i915_gem_object, gtt_space);
+
 		ret = drm_mm_scan_remove_block(&obj->gtt_space);
 		BUG_ON(ret);
 		drm_gem_object_unreference(&obj->base);
@@ -143,15 +145,14 @@  found:
 	 * scanning, therefore store to be evicted objects on a
 	 * temporary list. */
 	INIT_LIST_HEAD(&eviction_list);
-	while (!list_empty(&unwind_list)) {
-		obj = list_first_entry(&unwind_list,
-				       struct drm_i915_gem_object,
-				       evict_list);
+	drm_mm_for_each_scanned_node_reverse(node, next,
+					     &dev_priv->mm.gtt_space) {
+		obj = container_of(node, struct drm_i915_gem_object, gtt_space);
+
 		if (drm_mm_scan_remove_block(&obj->gtt_space)) {
-			list_move(&obj->evict_list, &eviction_list);
+			list_add(&obj->evict_list, &eviction_list);
 			continue;
 		}
-		list_del(&obj->evict_list);
 		drm_gem_object_unreference(&obj->base);
 	}