drm/i915: Move the size computations to drm buddy
authorArunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Sat, 9 Sep 2023 16:09:02 +0000 (09:09 -0700)
committerChristian König <christian.koenig@amd.com>
Mon, 11 Sep 2023 18:18:13 +0000 (20:18 +0200)
- Move roundup_power_of_two() to drm buddy file to support
  the new try harder mechanism for contiguous allocation.

- Move trim function call to drm_buddy_alloc_blocks() function.

Signed-off-by: Arunpravin Paneer Selvam <Arunpravin.PaneerSelvam@amd.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20230909160902.15644-2-Arunpravin.PaneerSelvam@amd.com
Reviewed-by: Matthew Auld <matthew.auld@intel.com>
Signed-off-by: Christian König <christian.koenig@amd.com>
drivers/gpu/drm/i915/i915_ttm_buddy_manager.c

index a1bc804cfa1520fd05640c7d1acd5a7ac402efbd..0d735d5c2b355dfd9233da2cdbf6865acbdd41a9 100644 (file)
@@ -59,6 +59,9 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man,
        if (place->flags & TTM_PL_FLAG_TOPDOWN)
                bman_res->flags |= DRM_BUDDY_TOPDOWN_ALLOCATION;
 
+       if (place->flags & TTM_PL_FLAG_CONTIGUOUS)
+               bman_res->flags |= DRM_BUDDY_CONTIGUOUS_ALLOCATION;
+
        if (place->fpfn || lpfn != man->size)
                bman_res->flags |= DRM_BUDDY_RANGE_ALLOCATION;
 
@@ -72,18 +75,6 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man,
        GEM_BUG_ON(min_page_size < mm->chunk_size);
        GEM_BUG_ON(!IS_ALIGNED(size, min_page_size));
 
-       if (place->fpfn + PFN_UP(bman_res->base.size) != place->lpfn &&
-           place->flags & TTM_PL_FLAG_CONTIGUOUS) {
-               unsigned long pages;
-
-               size = roundup_pow_of_two(size);
-               min_page_size = size;
-
-               pages = size >> ilog2(mm->chunk_size);
-               if (pages > lpfn)
-                       lpfn = pages;
-       }
-
        if (size > lpfn << PAGE_SHIFT) {
                err = -E2BIG;
                goto err_free_res;
@@ -107,14 +98,6 @@ static int i915_ttm_buddy_man_alloc(struct ttm_resource_manager *man,
        if (unlikely(err))
                goto err_free_blocks;
 
-       if (place->flags & TTM_PL_FLAG_CONTIGUOUS) {
-               u64 original_size = (u64)bman_res->base.size;
-
-               drm_buddy_block_trim(mm,
-                                    original_size,
-                                    &bman_res->blocks);
-       }
-
        if (lpfn <= bman->visible_size) {
                bman_res->used_visible_size = PFN_UP(bman_res->base.size);
        } else {