183827f40a2d97261528087331b0bee6ce2cf27c5root/************************************************************************** 283827f40a2d97261528087331b0bee6ce2cf27c5root * 383827f40a2d97261528087331b0bee6ce2cf27c5root * Copyright 2006-2008 Tungsten Graphics, Inc., Cedar Park, TX., USA. 483827f40a2d97261528087331b0bee6ce2cf27c5root * All Rights Reserved. 583827f40a2d97261528087331b0bee6ce2cf27c5root * Copyright 2009 VMware, Inc., Palo Alto, CA., USA. 683827f40a2d97261528087331b0bee6ce2cf27c5root * All Rights Reserved. 783827f40a2d97261528087331b0bee6ce2cf27c5root * 883827f40a2d97261528087331b0bee6ce2cf27c5root * Permission is hereby granted, free of charge, to any person obtaining a 983827f40a2d97261528087331b0bee6ce2cf27c5root * copy of this software and associated documentation files (the 1083827f40a2d97261528087331b0bee6ce2cf27c5root * "Software"), to deal in the Software without restriction, including 1183827f40a2d97261528087331b0bee6ce2cf27c5root * without limitation the rights to use, copy, modify, merge, publish, 1283827f40a2d97261528087331b0bee6ce2cf27c5root * distribute, sub license, and/or sell copies of the Software, and to 1383827f40a2d97261528087331b0bee6ce2cf27c5root * permit persons to whom the Software is furnished to do so, subject to 1483827f40a2d97261528087331b0bee6ce2cf27c5root * the following conditions: 1583827f40a2d97261528087331b0bee6ce2cf27c5root * 1683827f40a2d97261528087331b0bee6ce2cf27c5root * The above copyright notice and this permission notice (including the 1783827f40a2d97261528087331b0bee6ce2cf27c5root * next paragraph) shall be included in all copies or substantial portions 1883827f40a2d97261528087331b0bee6ce2cf27c5root * of the Software. 1983827f40a2d97261528087331b0bee6ce2cf27c5root * 2083827f40a2d97261528087331b0bee6ce2cf27c5root * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 2183827f40a2d97261528087331b0bee6ce2cf27c5root * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 2283827f40a2d97261528087331b0bee6ce2cf27c5root * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL 2383827f40a2d97261528087331b0bee6ce2cf27c5root * THE COPYRIGHT HOLDERS, AUTHORS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, 2483827f40a2d97261528087331b0bee6ce2cf27c5root * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2583827f40a2d97261528087331b0bee6ce2cf27c5root * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE 2683827f40a2d97261528087331b0bee6ce2cf27c5root * USE OR OTHER DEALINGS IN THE SOFTWARE. 2783827f40a2d97261528087331b0bee6ce2cf27c5root * 2883827f40a2d97261528087331b0bee6ce2cf27c5root **************************************************************************/ 2983827f40a2d97261528087331b0bee6ce2cf27c5root 3083827f40a2d97261528087331b0bee6ce2cf27c5root/* 3183827f40a2d97261528087331b0bee6ce2cf27c5root * Generic simple memory manager implementation. Intended to be used as a base 3283827f40a2d97261528087331b0bee6ce2cf27c5root * class implementation for more advanced memory managers. 3383827f40a2d97261528087331b0bee6ce2cf27c5root * 3483827f40a2d97261528087331b0bee6ce2cf27c5root * Note that the algorithm used is quite simple and there might be substantial 3583827f40a2d97261528087331b0bee6ce2cf27c5root * performance gains if a smarter free list is implemented. Currently it is just an 3683827f40a2d97261528087331b0bee6ce2cf27c5root * unordered stack of free regions. This could easily be improved if an RB-tree 3783827f40a2d97261528087331b0bee6ce2cf27c5root * is used instead. At least if we expect heavy fragmentation. 3883827f40a2d97261528087331b0bee6ce2cf27c5root * 3983827f40a2d97261528087331b0bee6ce2cf27c5root * Authors: 4083827f40a2d97261528087331b0bee6ce2cf27c5root * Thomas Hellstrom <thomas-at-tungstengraphics-dot-com> 4183827f40a2d97261528087331b0bee6ce2cf27c5root */ 4283827f40a2d97261528087331b0bee6ce2cf27c5root 4383827f40a2d97261528087331b0bee6ce2cf27c5root#ifndef _WSBM_MM_H_ 4483827f40a2d97261528087331b0bee6ce2cf27c5root#define _WSBM_MM_H_ 4583827f40a2d97261528087331b0bee6ce2cf27c5root 4683827f40a2d97261528087331b0bee6ce2cf27c5root#include "wsbm_util.h" 4783827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmMM 4883827f40a2d97261528087331b0bee6ce2cf27c5root{ 4983827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmListHead fl_entry; 5083827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmListHead ml_entry; 5183827f40a2d97261528087331b0bee6ce2cf27c5root}; 5283827f40a2d97261528087331b0bee6ce2cf27c5root 5383827f40a2d97261528087331b0bee6ce2cf27c5rootstruct _WsbmMMNode 5483827f40a2d97261528087331b0bee6ce2cf27c5root{ 5583827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmListHead fl_entry; 5683827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmListHead ml_entry; 5783827f40a2d97261528087331b0bee6ce2cf27c5root int free; 5883827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long start; 5983827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long size; 6083827f40a2d97261528087331b0bee6ce2cf27c5root struct _WsbmMM *mm; 6183827f40a2d97261528087331b0bee6ce2cf27c5root}; 6283827f40a2d97261528087331b0bee6ce2cf27c5root 6383827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmMMNode *wsbmMMSearchFree(const struct _WsbmMM *mm, 6483827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long size, 6583827f40a2d97261528087331b0bee6ce2cf27c5root unsigned alignment, 6683827f40a2d97261528087331b0bee6ce2cf27c5root int best_match); 6783827f40a2d97261528087331b0bee6ce2cf27c5rootextern struct _WsbmMMNode *wsbmMMGetBlock(struct _WsbmMMNode *parent, 6883827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long size, 6983827f40a2d97261528087331b0bee6ce2cf27c5root unsigned alignment); 7083827f40a2d97261528087331b0bee6ce2cf27c5rootextern void wsbmMMPutBlock(struct _WsbmMMNode *cur); 7183827f40a2d97261528087331b0bee6ce2cf27c5rootextern void wsbmMMtakedown(struct _WsbmMM *mm); 7283827f40a2d97261528087331b0bee6ce2cf27c5rootextern int wsbmMMinit(struct _WsbmMM *mm, unsigned long start, 7383827f40a2d97261528087331b0bee6ce2cf27c5root unsigned long size); 7483827f40a2d97261528087331b0bee6ce2cf27c5rootextern int wsbmMMclean(struct _WsbmMM *mm); 7583827f40a2d97261528087331b0bee6ce2cf27c5root#endif 76