GGTT VMA sizes might be smaller than the whole object size due to different GGTT views. Signed-off-by: Joonas Lahtinen <joonas.lahtinen@xxxxxxxxxxxxxxx> --- drivers/gpu/drm/i915/i915_gem.c | 32 +++++++++++++++++++------------- drivers/gpu/drm/i915/i915_gem_gtt.c | 23 +++++++++++++++++++++++ drivers/gpu/drm/i915/i915_gem_gtt.h | 4 ++++ 3 files changed, 46 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c index f7b8766..77116bd 100644 --- a/drivers/gpu/drm/i915/i915_gem.c +++ b/drivers/gpu/drm/i915/i915_gem.c @@ -3507,7 +3507,7 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj, { struct drm_device *dev = obj->base.dev; struct drm_i915_private *dev_priv = dev->dev_private; - u32 size, fence_size, fence_alignment, unfenced_alignment; + u32 size, vma_size, fence_size, fence_alignment, unfenced_alignment; unsigned long start = flags & PIN_OFFSET_BIAS ? flags & PIN_OFFSET_MASK : 0; unsigned long end = @@ -3518,15 +3518,18 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj, if(WARN_ON(i915_is_ggtt(vm) != !!ggtt_view)) return ERR_PTR(-EINVAL); + size = ggtt_view ? i915_ggtt_view_size(obj, ggtt_view) : + obj->base.size; + fence_size = i915_gem_get_gtt_size(dev, - obj->base.size, + size, obj->tiling_mode); fence_alignment = i915_gem_get_gtt_alignment(dev, - obj->base.size, + size, obj->tiling_mode, true); unfenced_alignment = i915_gem_get_gtt_alignment(dev, - obj->base.size, + size, obj->tiling_mode, false); if (alignment == 0) @@ -3537,14 +3540,15 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj, return ERR_PTR(-EINVAL); } - size = flags & PIN_MAPPABLE ? fence_size : obj->base.size; + vma_size = flags & PIN_MAPPABLE ? fence_size : size; /* If the object is bigger than the entire aperture, reject it early * before evicting everything in a vain attempt to find space. */ - if (obj->base.size > end) { - DRM_DEBUG("Attempting to bind an object larger than the aperture: object=%zd > %s aperture=%lu\n", - obj->base.size, + if (vma_size > end) { + DRM_DEBUG("Attempting to bind %s larger than the aperture: object=%u > %s aperture=%lu\n", + ggtt_view ? "a GGTT view " : "an object", + vma_size, flags & PIN_MAPPABLE ? "mappable" : "total", end); return ERR_PTR(-E2BIG); @@ -3564,13 +3568,13 @@ i915_gem_object_bind_to_vm(struct drm_i915_gem_object *obj, search_free: ret = drm_mm_insert_node_in_range_generic(&vm->mm, &vma->node, - size, alignment, + vma_size, alignment, obj->cache_level, start, end, DRM_MM_SEARCH_DEFAULT, DRM_MM_CREATE_DEFAULT); if (ret) { - ret = i915_gem_evict_something(dev, vm, size, alignment, + ret = i915_gem_evict_something(dev, vm, vma_size, alignment, obj->cache_level, start, end, flags); @@ -4233,13 +4237,15 @@ i915_gem_object_do_pin(struct drm_i915_gem_object *obj, if ((bound ^ vma->bound) & GLOBAL_BIND) { bool mappable, fenceable; - u32 fence_size, fence_alignment; + u32 size, fence_size, fence_alignment; + + size = i915_ggtt_view_size(obj, ggtt_view); fence_size = i915_gem_get_gtt_size(obj->base.dev, - obj->base.size, + size, obj->tiling_mode); fence_alignment = i915_gem_get_gtt_alignment(obj->base.dev, - obj->base.size, + size, obj->tiling_mode, true); diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.c b/drivers/gpu/drm/i915/i915_gem_gtt.c index 18c695b..fd99fb5 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.c +++ b/drivers/gpu/drm/i915/i915_gem_gtt.c @@ -2976,3 +2976,26 @@ int i915_vma_bind(struct i915_vma *vma, enum i915_cache_level cache_level, return 0; } + +/** + * i915_ggtt_view_size - Get the size of a GGTT view. + * @obj: Object the view is of. + * @view: The view in question. + * + * @return The size of the GGTT view in bytes. + */ +size_t +i915_ggtt_view_size(struct drm_i915_gem_object *obj, + const struct i915_ggtt_view *view) +{ + BUG_ON(!view); + + if (view->type == I915_GGTT_VIEW_NORMAL || + view->type == I915_GGTT_VIEW_ROTATED) { + return obj->base.size; + } else { + WARN_ONCE(1, "GGTT view %u not implemented!\n", view->type); + return obj->base.size; + } +} + diff --git a/drivers/gpu/drm/i915/i915_gem_gtt.h b/drivers/gpu/drm/i915/i915_gem_gtt.h index 29de64d..d6d6d5b 100644 --- a/drivers/gpu/drm/i915/i915_gem_gtt.h +++ b/drivers/gpu/drm/i915/i915_gem_gtt.h @@ -498,4 +498,8 @@ i915_ggtt_view_equal(const struct i915_ggtt_view *a, return a->type == b->type; } +size_t +i915_ggtt_view_size(struct drm_i915_gem_object *obj, + const struct i915_ggtt_view *view); + #endif -- 1.9.3 _______________________________________________ Intel-gfx mailing list Intel-gfx@xxxxxxxxxxxxxxxxxxxxx http://lists.freedesktop.org/mailman/listinfo/intel-gfx