Lines Matching +full:block +full:- +full:size
1 // SPDX-License-Identifier: MIT
19 struct drm_buddy_block *block; in drm_block_alloc() local
23 block = kmem_cache_zalloc(slab_blocks, GFP_KERNEL); in drm_block_alloc()
24 if (!block) in drm_block_alloc()
27 block->header = offset; in drm_block_alloc()
28 block->header |= order; in drm_block_alloc()
29 block->parent = parent; in drm_block_alloc()
31 BUG_ON(block->header & DRM_BUDDY_HEADER_UNUSED); in drm_block_alloc()
32 return block; in drm_block_alloc()
36 struct drm_buddy_block *block) in drm_block_free() argument
38 kmem_cache_free(slab_blocks, block); in drm_block_free()
42 struct drm_buddy_block *block) in list_insert_sorted() argument
47 head = &mm->free_list[drm_buddy_block_order(block)]; in list_insert_sorted()
49 list_add(&block->link, head); in list_insert_sorted()
54 if (drm_buddy_block_offset(block) < drm_buddy_block_offset(node)) in list_insert_sorted()
57 __list_add(&block->link, node->link.prev, &node->link); in list_insert_sorted()
60 static void clear_reset(struct drm_buddy_block *block) in clear_reset() argument
62 block->header &= ~DRM_BUDDY_HEADER_CLEAR; in clear_reset()
65 static void mark_cleared(struct drm_buddy_block *block) in mark_cleared() argument
67 block->header |= DRM_BUDDY_HEADER_CLEAR; in mark_cleared()
70 static void mark_allocated(struct drm_buddy_block *block) in mark_allocated() argument
72 block->header &= ~DRM_BUDDY_HEADER_STATE; in mark_allocated()
73 block->header |= DRM_BUDDY_ALLOCATED; in mark_allocated()
75 list_del(&block->link); in mark_allocated()
79 struct drm_buddy_block *block) in mark_free() argument
81 block->header &= ~DRM_BUDDY_HEADER_STATE; in mark_free()
82 block->header |= DRM_BUDDY_FREE; in mark_free()
84 list_insert_sorted(mm, block); in mark_free()
87 static void mark_split(struct drm_buddy_block *block) in mark_split() argument
89 block->header &= ~DRM_BUDDY_HEADER_STATE; in mark_split()
90 block->header |= DRM_BUDDY_SPLIT; in mark_split()
92 list_del(&block->link); in mark_split()
106 __get_buddy(struct drm_buddy_block *block) in __get_buddy() argument
110 parent = block->parent; in __get_buddy()
114 if (parent->left == block) in __get_buddy()
115 return parent->right; in __get_buddy()
117 return parent->left; in __get_buddy()
121 struct drm_buddy_block *block, in __drm_buddy_free() argument
127 while ((parent = block->parent)) { in __drm_buddy_free()
130 buddy = __get_buddy(block); in __drm_buddy_free()
137 * Check the block and its buddy clear state and exit in __drm_buddy_free()
140 if (drm_buddy_block_is_clear(block) != in __drm_buddy_free()
144 if (drm_buddy_block_is_clear(block)) in __drm_buddy_free()
148 list_del(&buddy->link); in __drm_buddy_free()
150 mm->clear_avail -= drm_buddy_block_size(mm, buddy); in __drm_buddy_free()
152 drm_block_free(mm, block); in __drm_buddy_free()
155 block = parent; in __drm_buddy_free()
158 order = drm_buddy_block_order(block); in __drm_buddy_free()
159 mark_free(mm, block); in __drm_buddy_free()
173 return -ENOMEM; in __force_merge()
175 if (min_order > mm->max_order) in __force_merge()
176 return -EINVAL; in __force_merge()
178 for (i = min_order - 1; i >= 0; i--) { in __force_merge()
179 struct drm_buddy_block *block, *prev; in __force_merge() local
181 list_for_each_entry_safe_reverse(block, prev, &mm->free_list[i], link) { in __force_merge()
185 if (!block->parent) in __force_merge()
188 block_start = drm_buddy_block_offset(block); in __force_merge()
189 block_end = block_start + drm_buddy_block_size(mm, block) - 1; in __force_merge()
194 buddy = __get_buddy(block); in __force_merge()
198 WARN_ON(drm_buddy_block_is_clear(block) == in __force_merge()
202 * If the prev block is same as buddy, don't access the in __force_merge()
203 * block in the next iteration as we would free the in __force_merge()
204 * buddy block as part of the free function. in __force_merge()
209 list_del(&block->link); in __force_merge()
210 if (drm_buddy_block_is_clear(block)) in __force_merge()
211 mm->clear_avail -= drm_buddy_block_size(mm, block); in __force_merge()
213 order = __drm_buddy_free(mm, block, true); in __force_merge()
219 return -ENOMEM; in __force_merge()
223 * drm_buddy_init - init memory manager
226 * @size: size in bytes to manage
227 * @chunk_size: minimum page size in bytes for our allocations
234 int drm_buddy_init(struct drm_buddy *mm, u64 size, u64 chunk_size) in drm_buddy_init() argument
239 if (size < chunk_size) in drm_buddy_init()
240 return -EINVAL; in drm_buddy_init()
243 return -EINVAL; in drm_buddy_init()
246 return -EINVAL; in drm_buddy_init()
248 size = round_down(size, chunk_size); in drm_buddy_init()
250 mm->size = size; in drm_buddy_init()
251 mm->avail = size; in drm_buddy_init()
252 mm->clear_avail = 0; in drm_buddy_init()
253 mm->chunk_size = chunk_size; in drm_buddy_init()
254 mm->max_order = ilog2(size) - ilog2(chunk_size); in drm_buddy_init()
256 BUG_ON(mm->max_order > DRM_BUDDY_MAX_ORDER); in drm_buddy_init()
258 mm->free_list = kmalloc_array(mm->max_order + 1, in drm_buddy_init()
261 if (!mm->free_list) in drm_buddy_init()
262 return -ENOMEM; in drm_buddy_init()
264 for (i = 0; i <= mm->max_order; ++i) in drm_buddy_init()
265 INIT_LIST_HEAD(&mm->free_list[i]); in drm_buddy_init()
267 mm->n_roots = hweight64(size); in drm_buddy_init()
269 mm->roots = kmalloc_array(mm->n_roots, in drm_buddy_init()
272 if (!mm->roots) in drm_buddy_init()
279 * Split into power-of-two blocks, in case we are given a size that is in drm_buddy_init()
280 * not itself a power-of-two. in drm_buddy_init()
287 order = ilog2(size) - ilog2(chunk_size); in drm_buddy_init()
296 BUG_ON(i > mm->max_order); in drm_buddy_init()
299 mm->roots[i] = root; in drm_buddy_init()
302 size -= root_size; in drm_buddy_init()
304 } while (size); in drm_buddy_init()
309 while (i--) in drm_buddy_init()
310 drm_block_free(mm, mm->roots[i]); in drm_buddy_init()
311 kfree(mm->roots); in drm_buddy_init()
313 kfree(mm->free_list); in drm_buddy_init()
314 return -ENOMEM; in drm_buddy_init()
319 * drm_buddy_fini - tear down the memory manager
327 u64 root_size, size; in drm_buddy_fini() local
331 size = mm->size; in drm_buddy_fini()
333 for (i = 0; i < mm->n_roots; ++i) { in drm_buddy_fini()
334 order = ilog2(size) - ilog2(mm->chunk_size); in drm_buddy_fini()
335 __force_merge(mm, 0, size, order); in drm_buddy_fini()
337 WARN_ON(!drm_buddy_block_is_free(mm->roots[i])); in drm_buddy_fini()
338 drm_block_free(mm, mm->roots[i]); in drm_buddy_fini()
340 root_size = mm->chunk_size << order; in drm_buddy_fini()
341 size -= root_size; in drm_buddy_fini()
344 WARN_ON(mm->avail != mm->size); in drm_buddy_fini()
346 kfree(mm->roots); in drm_buddy_fini()
347 kfree(mm->free_list); in drm_buddy_fini()
352 struct drm_buddy_block *block) in split_block() argument
354 unsigned int block_order = drm_buddy_block_order(block) - 1; in split_block()
355 u64 offset = drm_buddy_block_offset(block); in split_block()
357 BUG_ON(!drm_buddy_block_is_free(block)); in split_block()
358 BUG_ON(!drm_buddy_block_order(block)); in split_block()
360 block->left = drm_block_alloc(mm, block, block_order, offset); in split_block()
361 if (!block->left) in split_block()
362 return -ENOMEM; in split_block()
364 block->right = drm_block_alloc(mm, block, block_order, in split_block()
365 offset + (mm->chunk_size << block_order)); in split_block()
366 if (!block->right) { in split_block()
367 drm_block_free(mm, block->left); in split_block()
368 return -ENOMEM; in split_block()
371 mark_free(mm, block->left); in split_block()
372 mark_free(mm, block->right); in split_block()
374 if (drm_buddy_block_is_clear(block)) { in split_block()
375 mark_cleared(block->left); in split_block()
376 mark_cleared(block->right); in split_block()
377 clear_reset(block); in split_block()
380 mark_split(block); in split_block()
386 * drm_get_buddy - get buddy address
388 * @block: DRM buddy block
390 * Returns the corresponding buddy block for @block, or NULL
391 * if this is a root block and can't be merged further.
396 drm_get_buddy(struct drm_buddy_block *block) in drm_get_buddy() argument
398 return __get_buddy(block); in drm_get_buddy()
403 * drm_buddy_free_block - free a block
406 * @block: block to be freed
409 struct drm_buddy_block *block) in drm_buddy_free_block() argument
411 BUG_ON(!drm_buddy_block_is_allocated(block)); in drm_buddy_free_block()
412 mm->avail += drm_buddy_block_size(mm, block); in drm_buddy_free_block()
413 if (drm_buddy_block_is_clear(block)) in drm_buddy_free_block()
414 mm->clear_avail += drm_buddy_block_size(mm, block); in drm_buddy_free_block()
416 __drm_buddy_free(mm, block, false); in drm_buddy_free_block()
425 struct drm_buddy_block *block, *on; in __drm_buddy_free_list() local
429 list_for_each_entry_safe(block, on, objects, link) { in __drm_buddy_free_list()
431 mark_cleared(block); in __drm_buddy_free_list()
433 clear_reset(block); in __drm_buddy_free_list()
434 drm_buddy_free_block(mm, block); in __drm_buddy_free_list()
452 * drm_buddy_free_list - free blocks
468 static bool block_incompatible(struct drm_buddy_block *block, unsigned int flags) in block_incompatible() argument
472 return needs_clear != drm_buddy_block_is_clear(block); in block_incompatible()
482 u64 req_size = mm->chunk_size << order; in __alloc_range_bias()
483 struct drm_buddy_block *block; in __alloc_range_bias() local
489 end = end - 1; in __alloc_range_bias()
491 for (i = 0; i < mm->n_roots; ++i) in __alloc_range_bias()
492 list_add_tail(&mm->roots[i]->tmp_link, &dfs); in __alloc_range_bias()
498 block = list_first_entry_or_null(&dfs, in __alloc_range_bias()
501 if (!block) in __alloc_range_bias()
504 list_del(&block->tmp_link); in __alloc_range_bias()
506 if (drm_buddy_block_order(block) < order) in __alloc_range_bias()
509 block_start = drm_buddy_block_offset(block); in __alloc_range_bias()
510 block_end = block_start + drm_buddy_block_size(mm, block) - 1; in __alloc_range_bias()
515 if (drm_buddy_block_is_allocated(block)) in __alloc_range_bias()
527 if (!fallback && block_incompatible(block, flags)) in __alloc_range_bias()
531 order == drm_buddy_block_order(block)) { in __alloc_range_bias()
533 * Find the free block within the range. in __alloc_range_bias()
535 if (drm_buddy_block_is_free(block)) in __alloc_range_bias()
536 return block; in __alloc_range_bias()
541 if (!drm_buddy_block_is_split(block)) { in __alloc_range_bias()
542 err = split_block(mm, block); in __alloc_range_bias()
547 list_add(&block->right->tmp_link, &dfs); in __alloc_range_bias()
548 list_add(&block->left->tmp_link, &dfs); in __alloc_range_bias()
551 return ERR_PTR(-ENOSPC); in __alloc_range_bias()
559 buddy = __get_buddy(block); in __alloc_range_bias()
561 (drm_buddy_block_is_free(block) && in __alloc_range_bias()
563 __drm_buddy_free(mm, block, false); in __alloc_range_bias()
573 struct drm_buddy_block *block; in __drm_buddy_alloc_range_bias() local
576 block = __alloc_range_bias(mm, start, end, order, in __drm_buddy_alloc_range_bias()
578 if (IS_ERR(block)) in __drm_buddy_alloc_range_bias()
582 return block; in __drm_buddy_alloc_range_bias()
589 struct drm_buddy_block *max_block = NULL, *block = NULL; in get_maxblock() local
592 for (i = order; i <= mm->max_order; ++i) { in get_maxblock()
595 list_for_each_entry_reverse(tmp_block, &mm->free_list[i], link) { in get_maxblock()
599 block = tmp_block; in get_maxblock()
603 if (!block) in get_maxblock()
607 max_block = block; in get_maxblock()
611 if (drm_buddy_block_offset(block) > in get_maxblock()
613 max_block = block; in get_maxblock()
625 struct drm_buddy_block *block = NULL; in alloc_from_freelist() local
630 block = get_maxblock(mm, order, flags); in alloc_from_freelist()
631 if (block) in alloc_from_freelist()
632 /* Store the obtained block order */ in alloc_from_freelist()
633 tmp = drm_buddy_block_order(block); in alloc_from_freelist()
635 for (tmp = order; tmp <= mm->max_order; ++tmp) { in alloc_from_freelist()
638 list_for_each_entry_reverse(tmp_block, &mm->free_list[tmp], link) { in alloc_from_freelist()
642 block = tmp_block; in alloc_from_freelist()
646 if (block) in alloc_from_freelist()
651 if (!block) { in alloc_from_freelist()
653 for (tmp = order; tmp <= mm->max_order; ++tmp) { in alloc_from_freelist()
654 if (!list_empty(&mm->free_list[tmp])) { in alloc_from_freelist()
655 block = list_last_entry(&mm->free_list[tmp], in alloc_from_freelist()
658 if (block) in alloc_from_freelist()
663 if (!block) in alloc_from_freelist()
664 return ERR_PTR(-ENOSPC); in alloc_from_freelist()
667 BUG_ON(!drm_buddy_block_is_free(block)); in alloc_from_freelist()
670 err = split_block(mm, block); in alloc_from_freelist()
674 block = block->right; in alloc_from_freelist()
675 tmp--; in alloc_from_freelist()
677 return block; in alloc_from_freelist()
681 __drm_buddy_free(mm, block, false); in alloc_from_freelist()
687 u64 start, u64 size, in __alloc_range() argument
691 struct drm_buddy_block *block; in __alloc_range() local
698 end = start + size - 1; in __alloc_range()
704 block = list_first_entry_or_null(dfs, in __alloc_range()
707 if (!block) in __alloc_range()
710 list_del(&block->tmp_link); in __alloc_range()
712 block_start = drm_buddy_block_offset(block); in __alloc_range()
713 block_end = block_start + drm_buddy_block_size(mm, block) - 1; in __alloc_range()
718 if (drm_buddy_block_is_allocated(block)) { in __alloc_range()
719 err = -ENOSPC; in __alloc_range()
724 if (drm_buddy_block_is_free(block)) { in __alloc_range()
725 mark_allocated(block); in __alloc_range()
726 total_allocated += drm_buddy_block_size(mm, block); in __alloc_range()
727 mm->avail -= drm_buddy_block_size(mm, block); in __alloc_range()
728 if (drm_buddy_block_is_clear(block)) in __alloc_range()
729 mm->clear_avail -= drm_buddy_block_size(mm, block); in __alloc_range()
730 list_add_tail(&block->link, &allocated); in __alloc_range()
732 } else if (!mm->clear_avail) { in __alloc_range()
733 err = -ENOSPC; in __alloc_range()
738 if (!drm_buddy_block_is_split(block)) { in __alloc_range()
739 err = split_block(mm, block); in __alloc_range()
744 list_add(&block->right->tmp_link, dfs); in __alloc_range()
745 list_add(&block->left->tmp_link, dfs); in __alloc_range()
748 if (total_allocated < size) { in __alloc_range()
749 err = -ENOSPC; in __alloc_range()
763 buddy = __get_buddy(block); in __alloc_range()
765 (drm_buddy_block_is_free(block) && in __alloc_range()
767 __drm_buddy_free(mm, block, false); in __alloc_range()
770 if (err == -ENOSPC && total_allocated_on_err) { in __alloc_range()
782 u64 size, in __drm_buddy_alloc_range() argument
789 for (i = 0; i < mm->n_roots; ++i) in __drm_buddy_alloc_range()
790 list_add_tail(&mm->roots[i]->tmp_link, &dfs); in __drm_buddy_alloc_range()
792 return __alloc_range(mm, &dfs, start, size, in __drm_buddy_alloc_range()
797 u64 size, in __alloc_contig_try_harder() argument
802 struct drm_buddy_block *block; in __alloc_contig_try_harder() local
810 modify_size = rounddown_pow_of_two(size); in __alloc_contig_try_harder()
811 pages = modify_size >> ilog2(mm->chunk_size); in __alloc_contig_try_harder()
812 order = fls(pages) - 1; in __alloc_contig_try_harder()
814 return -ENOSPC; in __alloc_contig_try_harder()
816 list = &mm->free_list[order]; in __alloc_contig_try_harder()
818 return -ENOSPC; in __alloc_contig_try_harder()
820 list_for_each_entry_reverse(block, list, link) { in __alloc_contig_try_harder()
822 rhs_offset = drm_buddy_block_offset(block); in __alloc_contig_try_harder()
823 err = __drm_buddy_alloc_range(mm, rhs_offset, size, in __alloc_contig_try_harder()
825 if (!err || err != -ENOSPC) in __alloc_contig_try_harder()
828 lhs_size = max((size - filled), min_block_size); in __alloc_contig_try_harder()
833 lhs_offset = drm_buddy_block_offset(block) - lhs_size; in __alloc_contig_try_harder()
839 } else if (err != -ENOSPC) { in __alloc_contig_try_harder()
847 return -ENOSPC; in __alloc_contig_try_harder()
851 * drm_buddy_block_trim - free unused pages
855 * @new_size: original size requested
857 * MUST contain single block as input to be trimmed.
862 * For contiguous allocation, we round up the size to the nearest
863 * power of two value, drivers consume *actual* size, so remaining
875 struct drm_buddy_block *block; in drm_buddy_block_trim() local
882 return -EINVAL; in drm_buddy_block_trim()
884 block = list_first_entry(blocks, in drm_buddy_block_trim()
888 block_start = drm_buddy_block_offset(block); in drm_buddy_block_trim()
889 block_end = block_start + drm_buddy_block_size(mm, block); in drm_buddy_block_trim()
891 if (WARN_ON(!drm_buddy_block_is_allocated(block))) in drm_buddy_block_trim()
892 return -EINVAL; in drm_buddy_block_trim()
894 if (new_size > drm_buddy_block_size(mm, block)) in drm_buddy_block_trim()
895 return -EINVAL; in drm_buddy_block_trim()
897 if (!new_size || !IS_ALIGNED(new_size, mm->chunk_size)) in drm_buddy_block_trim()
898 return -EINVAL; in drm_buddy_block_trim()
900 if (new_size == drm_buddy_block_size(mm, block)) in drm_buddy_block_trim()
908 return -EINVAL; in drm_buddy_block_trim()
910 if (!IS_ALIGNED(new_start, mm->chunk_size)) in drm_buddy_block_trim()
911 return -EINVAL; in drm_buddy_block_trim()
914 return -EINVAL; in drm_buddy_block_trim()
917 list_del(&block->link); in drm_buddy_block_trim()
918 mark_free(mm, block); in drm_buddy_block_trim()
919 mm->avail += drm_buddy_block_size(mm, block); in drm_buddy_block_trim()
920 if (drm_buddy_block_is_clear(block)) in drm_buddy_block_trim()
921 mm->clear_avail += drm_buddy_block_size(mm, block); in drm_buddy_block_trim()
924 parent = block->parent; in drm_buddy_block_trim()
925 block->parent = NULL; in drm_buddy_block_trim()
927 list_add(&block->tmp_link, &dfs); in drm_buddy_block_trim()
930 mark_allocated(block); in drm_buddy_block_trim()
931 mm->avail -= drm_buddy_block_size(mm, block); in drm_buddy_block_trim()
932 if (drm_buddy_block_is_clear(block)) in drm_buddy_block_trim()
933 mm->clear_avail -= drm_buddy_block_size(mm, block); in drm_buddy_block_trim()
934 list_add(&block->link, blocks); in drm_buddy_block_trim()
937 block->parent = parent; in drm_buddy_block_trim()
958 * drm_buddy_alloc_blocks - allocate power-of-two blocks
961 * @start: start of the allowed range for this block
962 * @end: end of the allowed range for this block
963 * @size: size of the allocation in bytes
969 * the tree and returns the desired block.
972 * are enforced, which picks the block from the freelist.
978 u64 start, u64 end, u64 size, in drm_buddy_alloc_blocks() argument
983 struct drm_buddy_block *block = NULL; in drm_buddy_alloc_blocks() local
990 if (size < mm->chunk_size) in drm_buddy_alloc_blocks()
991 return -EINVAL; in drm_buddy_alloc_blocks()
993 if (min_block_size < mm->chunk_size) in drm_buddy_alloc_blocks()
994 return -EINVAL; in drm_buddy_alloc_blocks()
997 return -EINVAL; in drm_buddy_alloc_blocks()
999 if (!IS_ALIGNED(start | end | size, mm->chunk_size)) in drm_buddy_alloc_blocks()
1000 return -EINVAL; in drm_buddy_alloc_blocks()
1002 if (end > mm->size) in drm_buddy_alloc_blocks()
1003 return -EINVAL; in drm_buddy_alloc_blocks()
1005 if (range_overflows(start, size, mm->size)) in drm_buddy_alloc_blocks()
1006 return -EINVAL; in drm_buddy_alloc_blocks()
1009 if (start + size == end) { in drm_buddy_alloc_blocks()
1011 return -EINVAL; in drm_buddy_alloc_blocks()
1013 return __drm_buddy_alloc_range(mm, start, size, NULL, blocks); in drm_buddy_alloc_blocks()
1016 original_size = size; in drm_buddy_alloc_blocks()
1019 /* Roundup the size to power of 2 */ in drm_buddy_alloc_blocks()
1021 size = roundup_pow_of_two(size); in drm_buddy_alloc_blocks()
1022 min_block_size = size; in drm_buddy_alloc_blocks()
1023 /* Align size value to min_block_size */ in drm_buddy_alloc_blocks()
1024 } else if (!IS_ALIGNED(size, min_block_size)) { in drm_buddy_alloc_blocks()
1025 size = round_up(size, min_block_size); in drm_buddy_alloc_blocks()
1028 pages = size >> ilog2(mm->chunk_size); in drm_buddy_alloc_blocks()
1029 order = fls(pages) - 1; in drm_buddy_alloc_blocks()
1030 min_order = ilog2(min_block_size) - ilog2(mm->chunk_size); in drm_buddy_alloc_blocks()
1033 order = min(order, (unsigned int)fls(pages) - 1); in drm_buddy_alloc_blocks()
1034 BUG_ON(order > mm->max_order); in drm_buddy_alloc_blocks()
1038 block = __drm_buddy_alloc_blocks(mm, start, in drm_buddy_alloc_blocks()
1042 if (!IS_ERR(block)) in drm_buddy_alloc_blocks()
1045 if (order-- == min_order) { in drm_buddy_alloc_blocks()
1047 if (mm->clear_avail && in drm_buddy_alloc_blocks()
1049 block = __drm_buddy_alloc_blocks(mm, start, in drm_buddy_alloc_blocks()
1053 if (!IS_ERR(block)) { in drm_buddy_alloc_blocks()
1060 * Try contiguous block allocation through in drm_buddy_alloc_blocks()
1069 err = -ENOSPC; in drm_buddy_alloc_blocks()
1074 mark_allocated(block); in drm_buddy_alloc_blocks()
1075 mm->avail -= drm_buddy_block_size(mm, block); in drm_buddy_alloc_blocks()
1076 if (drm_buddy_block_is_clear(block)) in drm_buddy_alloc_blocks()
1077 mm->clear_avail -= drm_buddy_block_size(mm, block); in drm_buddy_alloc_blocks()
1078 kmemleak_update_trace(block); in drm_buddy_alloc_blocks()
1079 list_add_tail(&block->link, &allocated); in drm_buddy_alloc_blocks()
1081 pages -= BIT(order); in drm_buddy_alloc_blocks()
1087 /* Trim the allocated block to the required size */ in drm_buddy_alloc_blocks()
1089 original_size != size) { in drm_buddy_alloc_blocks()
1098 block = list_last_entry(&allocated, typeof(*block), link); in drm_buddy_alloc_blocks()
1099 list_move(&block->link, &temp); in drm_buddy_alloc_blocks()
1101 trim_size = drm_buddy_block_size(mm, block) - in drm_buddy_alloc_blocks()
1102 (size - original_size); in drm_buddy_alloc_blocks()
1124 * drm_buddy_block_print - print block information
1127 * @block: DRM buddy block
1131 struct drm_buddy_block *block, in drm_buddy_block_print() argument
1134 u64 start = drm_buddy_block_offset(block); in drm_buddy_block_print()
1135 u64 size = drm_buddy_block_size(mm, block); in drm_buddy_block_print() local
1137 drm_printf(p, "%#018llx-%#018llx: %llu\n", start, start + size, size); in drm_buddy_block_print()
1142 * drm_buddy_print - print allocator state
1152 mm->chunk_size >> 10, mm->size >> 20, mm->avail >> 20, mm->clear_avail >> 20); in drm_buddy_print()
1154 for (order = mm->max_order; order >= 0; order--) { in drm_buddy_print()
1155 struct drm_buddy_block *block; in drm_buddy_print() local
1158 list_for_each_entry(block, &mm->free_list[order], link) { in drm_buddy_print()
1159 BUG_ON(!drm_buddy_block_is_free(block)); in drm_buddy_print()
1163 drm_printf(p, "order-%2d ", order); in drm_buddy_print()
1165 free = count * (mm->chunk_size << order); in drm_buddy_print()
1185 return -ENOMEM; in drm_buddy_module_init()