diff mbox

drm/i915: Promote invalid buffer alignment.

Message ID 1259788057-10159-1-git-send-email-chris@chris-wilson.co.uk (mailing list archive)
State Rejected
Headers show

Commit Message

Chris Wilson Dec. 2, 2009, 9:07 p.m. UTC
None
diff mbox

Patch

diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c
index 214fb18..846f050 100644
--- a/drivers/gpu/drm/i915/i915_gem.c
+++ b/drivers/gpu/drm/i915/i915_gem.c
@@ -2577,6 +2577,7 @@  i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
 	drm_i915_private_t *dev_priv = dev->dev_private;
 	struct drm_i915_gem_object *obj_priv = obj->driver_private;
 	struct drm_mm_node *free_space;
+	unsigned required_alignment;
 	bool retry_alloc = false;
 	int ret;
 
@@ -2588,11 +2589,17 @@  i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment)
 		return -EINVAL;
 	}
 
-	if (alignment == 0)
-		alignment = i915_gem_get_gtt_alignment(obj);
-	if (alignment & (i915_gem_get_gtt_alignment(obj) - 1)) {
-		DRM_ERROR("Invalid object alignment requested %u\n", alignment);
-		return -EINVAL;
+	required_alignment = i915_gem_get_gtt_alignment(obj);
+	if (alignment & (required_alignment - 1)) {
+		WARN(1,"Invalid object alignment requested %x < %x\n",
+		     alignment, required_alignment);
+		/* Use the smallest possible alignment that honours the
+		 * fencing restrictions and the user request.
+		 */
+		if (alignment < required_alignment)
+			alignment = required_alignment;
+		else
+			alignment = (alignment + required_alignment) & -required_alignment;
 	}
 
  search_free: