Commit d22632c8 authored by Matthew Auld's avatar Matthew Auld
Browse files

drm/i915: support forcing the page size with lmem



For some specialised objects we might need something larger than the
regions min_page_size due to some hw restriction, and slightly more
hairy is needing something smaller with the guarantee that such objects
will never be inserted into any GTT, which is the case for the paging
structures.

This also fixes how we setup the BO page_alignment, if we later migrate
the object somewhere else. For example if the placements are {SMEM,
LMEM}, then we might get this wrong. Pushing the min_page_size behaviour
into the manager should fix this.

v2(Thomas): push the default page size behaviour into buddy_man, and let
the user override it with the page-alignment, which looks cleaner

v3: rebase on ttm sys changes

Signed-off-by: default avatarMatthew Auld <matthew.auld@intel.com>
Cc: Thomas Hellström <thomas.hellstrom@linux.intel.com>
Reviewed-by: default avatarThomas Hellström <thomas.hellstrom@linux.intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20210625103824.558481-1-matthew.auld@intel.com
parent e11b7b6e
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -90,7 +90,7 @@ i915_gem_setup(struct drm_i915_gem_object *obj, u64 size)
	 */
	flags = I915_BO_ALLOC_USER;

	ret = mr->ops->init_object(mr, obj, size, flags);
	ret = mr->ops->init_object(mr, obj, size, 0, flags);
	if (ret)
		return ret;

+32 −1
Original line number Diff line number Diff line
@@ -72,11 +72,42 @@ bool __i915_gem_object_is_lmem(struct drm_i915_gem_object *obj)
		      mr->type == INTEL_MEMORY_STOLEN_LOCAL);
}

/**
 * __i915_gem_object_create_lmem_with_ps - Create lmem object and force the
 * minimum page size for the backing pages.
 * @i915: The i915 instance.
 * @size: The size in bytes for the object. Note that we need to round the size
 * up depending on the @page_size. The final object size can be fished out from
 * the drm GEM object.
 * @page_size: The requested minimum page size in bytes for this object. This is
 * useful if we need something bigger than the regions min_page_size due to some
 * hw restriction, or in some very specialised cases where it needs to be
 * smaller, where the internal fragmentation cost is too great when rounding up
 * the object size.
 * @flags: The optional BO allocation flags.
 *
 * Note that this interface assumes you know what you are doing when forcing the
 * @page_size. If this is smaller than the regions min_page_size then it can
 * never be inserted into any GTT, otherwise it might lead to undefined
 * behaviour.
 *
 * Return: The object pointer, which might be an ERR_PTR in the case of failure.
 */
struct drm_i915_gem_object *
__i915_gem_object_create_lmem_with_ps(struct drm_i915_private *i915,
				      resource_size_t size,
				      resource_size_t page_size,
				      unsigned int flags)
{
	return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
					     size, page_size, flags);
}

struct drm_i915_gem_object *
i915_gem_object_create_lmem(struct drm_i915_private *i915,
			    resource_size_t size,
			    unsigned int flags)
{
	return i915_gem_object_create_region(i915->mm.regions[INTEL_REGION_LMEM],
					     size, flags);
					     size, 0, flags);
}
+5 −0
Original line number Diff line number Diff line
@@ -23,6 +23,11 @@ bool i915_gem_object_is_lmem(struct drm_i915_gem_object *obj);

bool __i915_gem_object_is_lmem(struct drm_i915_gem_object *obj);

struct drm_i915_gem_object *
__i915_gem_object_create_lmem_with_ps(struct drm_i915_private *i915,
				      resource_size_t size,
				      resource_size_t page_size,
				      unsigned int flags);
struct drm_i915_gem_object *
i915_gem_object_create_lmem(struct drm_i915_private *i915,
			    resource_size_t size,
+11 −2
Original line number Diff line number Diff line
@@ -32,9 +32,11 @@ void i915_gem_object_release_memory_region(struct drm_i915_gem_object *obj)
struct drm_i915_gem_object *
i915_gem_object_create_region(struct intel_memory_region *mem,
			      resource_size_t size,
			      resource_size_t page_size,
			      unsigned int flags)
{
	struct drm_i915_gem_object *obj;
	resource_size_t default_page_size;
	int err;

	/*
@@ -48,7 +50,14 @@ i915_gem_object_create_region(struct intel_memory_region *mem,
	if (!mem)
		return ERR_PTR(-ENODEV);

	size = round_up(size, mem->min_page_size);
	default_page_size = mem->min_page_size;
	if (page_size)
		default_page_size = page_size;

	GEM_BUG_ON(!is_power_of_2_u64(default_page_size));
	GEM_BUG_ON(default_page_size < PAGE_SIZE);

	size = round_up(size, default_page_size);

	GEM_BUG_ON(!size);
	GEM_BUG_ON(!IS_ALIGNED(size, I915_GTT_MIN_ALIGNMENT));
@@ -60,7 +69,7 @@ i915_gem_object_create_region(struct intel_memory_region *mem,
	if (!obj)
		return ERR_PTR(-ENOMEM);

	err = mem->ops->init_object(mem, obj, size, flags);
	err = mem->ops->init_object(mem, obj, size, page_size, flags);
	if (err)
		goto err_object_free;

+1 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ void i915_gem_object_release_memory_region(struct drm_i915_gem_object *obj);
struct drm_i915_gem_object *
i915_gem_object_create_region(struct intel_memory_region *mem,
			      resource_size_t size,
			      resource_size_t page_size,
			      unsigned int flags);

#endif
Loading