2
0
mirror of https://github.com/edk2-porting/linux-next.git synced 2024-12-23 12:43:55 +08:00

drm/ttm: replace drm_mm_pre_get() by direct alloc

Instead of calling drm_mm_pre_get() in a row, we now preallocate the node
and then use the atomic insertion functions. This has the exact same
semantics and there is no reason to use the racy pre-allocations.

Note that ttm_bo_man_get_node() does not run in atomic context. Nouveau
already uses GFP_KERNEL alloc in nouveau/nouveau_ttm.c in
nouveau_gart_manager_new(). So we can do the same in
ttm_bo_man_get_node().

Signed-off-by: David Herrmann <dh.herrmann@gmail.com>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Signed-off-by: Dave Airlie <airlied@redhat.com>
This commit is contained in:
David Herrmann 2013-07-27 13:37:59 +02:00 committed by Dave Airlie
parent 28ec711cd4
commit 78af329a85

View File

@ -61,29 +61,25 @@ static int ttm_bo_man_get_node(struct ttm_mem_type_manager *man,
lpfn = placement->lpfn; lpfn = placement->lpfn;
if (!lpfn) if (!lpfn)
lpfn = man->size; lpfn = man->size;
do {
ret = drm_mm_pre_get(mm);
if (unlikely(ret))
return ret;
spin_lock(&rman->lock); node = kzalloc(sizeof(*node), GFP_KERNEL);
node = drm_mm_search_free_in_range(mm, if (!node)
mem->num_pages, mem->page_alignment, return -ENOMEM;
placement->fpfn, lpfn,
DRM_MM_SEARCH_BEST); spin_lock(&rman->lock);
if (unlikely(node == NULL)) { ret = drm_mm_insert_node_in_range(mm, node, mem->num_pages,
spin_unlock(&rman->lock); mem->page_alignment,
return 0; placement->fpfn, lpfn,
} DRM_MM_SEARCH_BEST);
node = drm_mm_get_block_atomic_range(node, mem->num_pages, spin_unlock(&rman->lock);
mem->page_alignment,
placement->fpfn, if (unlikely(ret)) {
lpfn); kfree(node);
spin_unlock(&rman->lock); } else {
} while (node == NULL); mem->mm_node = node;
mem->start = node->start;
}
mem->mm_node = node;
mem->start = node->start;
return 0; return 0;
} }
@ -94,8 +90,10 @@ static void ttm_bo_man_put_node(struct ttm_mem_type_manager *man,
if (mem->mm_node) { if (mem->mm_node) {
spin_lock(&rman->lock); spin_lock(&rman->lock);
drm_mm_put_block(mem->mm_node); drm_mm_remove_node(mem->mm_node);
spin_unlock(&rman->lock); spin_unlock(&rman->lock);
kfree(mem->mm_node);
mem->mm_node = NULL; mem->mm_node = NULL;
} }
} }