We are incorrectly limiting the max allocation size as per the mm max_order, which is effectively the largest power-of-two that we can fit in the region size. However, it's normal to setup the region or allocator with a non-power-of-two size(for example 3G), which we should already handle correctly, except it seems for the early too-big-check. v2: make sure we also exercise the I915_BO_ALLOC_CONTIGUOUS path, which is quite different, since for that we are actually limited by the largest power-of-two that we can fit within the region size. (Chris) Fixes: b908be543e44 ("drm/i915: support creating LMEM objects") Signed-off-by: Matthew Auld <matthew.auld@intel.com> Cc: Chris Wilson <chris@chris-wilson.co.uk> Cc: CQ Tang <cq.tang@intel.com> Reviewed-by: Chris Wilson <chris@chris-wilson.co.uk> Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk> Link: https://patchwork.freedesktop.org/patch/msgid/20201021103606.241395-1-matthew.auld@intel.com (cherry picked from commit 83ebef47f8ebe320d5c5673db82f9903a4f40a69) Signed-off-by: Rodrigo Vivi <rodrigo.vivi@intel.com>
62 lines
1.6 KiB
C
62 lines
1.6 KiB
C
// SPDX-License-Identifier: MIT
|
|
/*
|
|
* Copyright © 2019 Intel Corporation
|
|
*/
|
|
|
|
#include "gem/i915_gem_region.h"
|
|
#include "intel_memory_region.h"
|
|
|
|
#include "mock_region.h"
|
|
|
|
static const struct drm_i915_gem_object_ops mock_region_obj_ops = {
|
|
.name = "mock-region",
|
|
.get_pages = i915_gem_object_get_pages_buddy,
|
|
.put_pages = i915_gem_object_put_pages_buddy,
|
|
.release = i915_gem_object_release_memory_region,
|
|
};
|
|
|
|
static struct drm_i915_gem_object *
|
|
mock_object_create(struct intel_memory_region *mem,
|
|
resource_size_t size,
|
|
unsigned int flags)
|
|
{
|
|
static struct lock_class_key lock_class;
|
|
struct drm_i915_private *i915 = mem->i915;
|
|
struct drm_i915_gem_object *obj;
|
|
|
|
if (size > mem->mm.size)
|
|
return ERR_PTR(-E2BIG);
|
|
|
|
obj = i915_gem_object_alloc();
|
|
if (!obj)
|
|
return ERR_PTR(-ENOMEM);
|
|
|
|
drm_gem_private_object_init(&i915->drm, &obj->base, size);
|
|
i915_gem_object_init(obj, &mock_region_obj_ops, &lock_class);
|
|
|
|
obj->read_domains = I915_GEM_DOMAIN_CPU | I915_GEM_DOMAIN_GTT;
|
|
|
|
i915_gem_object_set_cache_coherency(obj, I915_CACHE_NONE);
|
|
|
|
i915_gem_object_init_memory_region(obj, mem, flags);
|
|
|
|
return obj;
|
|
}
|
|
|
|
static const struct intel_memory_region_ops mock_region_ops = {
|
|
.init = intel_memory_region_init_buddy,
|
|
.release = intel_memory_region_release_buddy,
|
|
.create_object = mock_object_create,
|
|
};
|
|
|
|
struct intel_memory_region *
|
|
mock_region_create(struct drm_i915_private *i915,
|
|
resource_size_t start,
|
|
resource_size_t size,
|
|
resource_size_t min_page_size,
|
|
resource_size_t io_start)
|
|
{
|
|
return intel_memory_region_create(i915, start, size, min_page_size,
|
|
io_start, &mock_region_ops);
|
|
}
|