Commit 7a6b2896 authored by Daniel Vetter's avatar Daniel Vetter Committed by Dave Airlie

drm_mm: extract check_free_mm_node

There are already two copies of this logic. And the new scanning
stuff will add some more. So extract it into a small helper
function.
Signed-off-by: default avatarDaniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: default avatarThomas Hellstrom <thellstrom@vmwgfx.com>
Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
Signed-off-by: default avatarDave Airlie <airlied@redhat.com>
parent d1024ce9
...@@ -283,6 +283,27 @@ void drm_mm_put_block(struct drm_mm_node *cur) ...@@ -283,6 +283,27 @@ void drm_mm_put_block(struct drm_mm_node *cur)
EXPORT_SYMBOL(drm_mm_put_block); EXPORT_SYMBOL(drm_mm_put_block);
static int check_free_mm_node(struct drm_mm_node *entry, unsigned long size,
unsigned alignment)
{
unsigned wasted = 0;
if (entry->size < size)
return 0;
if (alignment) {
register unsigned tmp = entry->start % alignment;
if (tmp)
wasted = alignment - tmp;
}
if (entry->size >= size + wasted) {
return 1;
}
return 0;
}
struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
unsigned long size, unsigned long size,
unsigned alignment, int best_match) unsigned alignment, int best_match)
...@@ -290,32 +311,22 @@ struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm, ...@@ -290,32 +311,22 @@ struct drm_mm_node *drm_mm_search_free(const struct drm_mm *mm,
struct drm_mm_node *entry; struct drm_mm_node *entry;
struct drm_mm_node *best; struct drm_mm_node *best;
unsigned long best_size; unsigned long best_size;
unsigned wasted;
best = NULL; best = NULL;
best_size = ~0UL; best_size = ~0UL;
list_for_each_entry(entry, &mm->free_stack, free_stack) { list_for_each_entry(entry, &mm->free_stack, free_stack) {
wasted = 0; if (!check_free_mm_node(entry, size, alignment))
if (entry->size < size)
continue; continue;
if (alignment) {
register unsigned tmp = entry->start % alignment;
if (tmp)
wasted += alignment - tmp;
}
if (entry->size >= size + wasted) {
if (!best_match) if (!best_match)
return entry; return entry;
if (entry->size < best_size) { if (entry->size < best_size) {
best = entry; best = entry;
best_size = entry->size; best_size = entry->size;
} }
} }
}
return best; return best;
} }
...@@ -331,39 +342,25 @@ struct drm_mm_node *drm_mm_search_free_in_range(const struct drm_mm *mm, ...@@ -331,39 +342,25 @@ struct drm_mm_node *drm_mm_search_free_in_range(const struct drm_mm *mm,
struct drm_mm_node *entry; struct drm_mm_node *entry;
struct drm_mm_node *best; struct drm_mm_node *best;
unsigned long best_size; unsigned long best_size;
unsigned wasted;
best = NULL; best = NULL;
best_size = ~0UL; best_size = ~0UL;
list_for_each_entry(entry, &mm->free_stack, free_stack) { list_for_each_entry(entry, &mm->free_stack, free_stack) {
wasted = 0;
if (entry->size < size)
continue;
if (entry->start > end || (entry->start+entry->size) < start) if (entry->start > end || (entry->start+entry->size) < start)
continue; continue;
if (entry->start < start) if (!check_free_mm_node(entry, size, alignment))
wasted += start - entry->start; continue;
if (alignment) {
register unsigned tmp = (entry->start + wasted) % alignment;
if (tmp)
wasted += alignment - tmp;
}
if (entry->size >= size + wasted &&
(entry->start + wasted + size) <= end) {
if (!best_match) if (!best_match)
return entry; return entry;
if (entry->size < best_size) { if (entry->size < best_size) {
best = entry; best = entry;
best_size = entry->size; best_size = entry->size;
} }
} }
}
return best; return best;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment