1450N/A * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. 1450N/A/************************************************************************** 1450N/A * Copyright 2006 Tungsten Graphics, Inc., Bismarck, ND., USA. 1450N/A * Copyright (c) 2009, 2013, Intel Corporation. 1450N/A * Permission is hereby granted, free of charge, to any person obtaining a 1450N/A * copy of this software and associated documentation files (the 1450N/A * "Software"), to deal in the Software without restriction, including 1450N/A * without limitation the rights to use, copy, modify, merge, publish, 1450N/A * distribute, sub license, and/or sell copies of the Software, and to 1450N/A * permit persons to whom the Software is furnished to do so, subject to 1450N/A * the following conditions: 1450N/A * The above copyright notice and this permission notice (including the 1450N/A * next paragraph) shall be included in all copies or substantial portions 1450N/A * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 1450N/A * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1450N/A * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 1450N/A * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 1450N/A * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 1450N/A * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 1450N/A * USE OR OTHER DEALINGS IN THE SOFTWARE. 1450N/A **************************************************************************/ 1450N/A * Generic simple memory manager implementation. Intended to be used as a base 1450N/A * class implementation for more advanced memory managers. 1450N/A * Note that the algorithm used is quite simple and there might be substantial 1450N/A * performance gains if a smarter free list is implemented. Currently it is just an 1450N/A * unordered stack of free regions. This could easily be improved if an RB-tree 1450N/A * is used instead. At least if we expect heavy fragmentation. 1450N/A * Aligned allocations can also see improvement. 1450N/A * Thomas Hellström <thomas-at-tungstengraphics-dot-com> 1450N/A/* drm_mm_pre_get() - pre allocate drm_mm_node structure 1450N/A * drm_mm: memory manager struct we are pre-allocating for 1450N/A * Returns 0 on success or -ENOMEM if allocation fails. 1450N/A * Search for free space and insert a preallocated memory node. Returns 1450N/A * -ENOSPC if no suitable free area is available. The preallocated memory node 1450N/A * Search for free space and insert a preallocated memory node. Returns 1450N/A * -ENOSPC if no suitable free area is available. This is for range 1450N/A * restricted allocations. The preallocated memory node must be cleared. 1450N/A * Remove a memory node from the allocator. 1450N/A * Remove a memory node from the allocator and free the allocated struct 1450N/A * drm_mm_node. Only to be used on a struct drm_mm_node obtained by one of the 1450N/A * drm_mm_get_block functions. 1450N/A * Moves an allocation. To be used with embedded struct drm_mm_node. 1450N/A * This simply sets up the scanning routines with the parameters for the desired 1450N/A * Warning: As long as the scan list is non-empty, no other operations than 1450N/A * This simply sets up the scanning routines with the parameters for the desired 1450N/A * hole. This version is for range-restricted scans. 1450N/A * Warning: As long as the scan list is non-empty, no other operations than 1450N/A * Add a node to the scan list that might be freed to make space for the desired 1450N/A * Returns non-zero, if a hole has been found, zero otherwise. 1450N/A * Remove a node from the scan list. 1450N/A * Nodes _must_ be removed in the exact same order from the scan list as they 1450N/A * have been added, otherwise the internal state of the memory manager will be 1450N/A * When the scan list is empty, the selected memory nodes can be freed. An 1450N/A * immediatly following drm_mm_search_free with best_match = 0 will then return 1450N/A * the just freed block (because its at the top of the free_stack list). 1450N/A * Returns one if this block should be evicted, zero otherwise. Will always 1450N/A * return zero when no hole has been found. 1450N/A /* Clever trick to avoid a special case in the free hole tracking. */