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