1 /************************************************************************** 2 * 3 * Copyright (C) 1999 Wittawat Yamwong 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice shall be included 13 * in all copies or substantial portions of the Software. 14 * 15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 16 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 18 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 19 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 20 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 21 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 22 * 23 **************************************************************************/ 24 25 26 /** 27 * @file 28 * Memory manager code. Primarily used by device drivers to manage texture 29 * heaps, etc. 30 */ 31 32 #ifndef _U_MM_H_ 33 #define _U_MM_H_ 34 35 #ifdef __cplusplus 36 extern "C" { 37 #endif 38 39 struct mem_block { 40 struct mem_block *next, *prev; 41 struct mem_block *next_free, *prev_free; 42 struct mem_block *heap; 43 int ofs,size; 44 unsigned int free:1; 45 unsigned int reserved:1; 46 }; 47 48 49 50 /** 51 * input: total size in bytes 52 * return: a heap pointer if OK, NULL if error 53 */ 54 extern struct mem_block *u_mmInit(int ofs, int size); 55 56 /** 57 * Allocate 'size' bytes with 2^align2 bytes alignment, 58 * restrict the search to free memory after 'startSearch' 59 * depth and back buffers should be in different 4mb banks 60 * to get better page hits if possible 61 * input: size = size of block 62 * align2 = 2^align2 bytes alignment 63 * startSearch = linear offset from start of heap to begin search 64 * return: pointer to the allocated block, 0 if error 65 */ 66 extern struct mem_block *u_mmAllocMem(struct mem_block *heap, int size, int align2, 67 int startSearch); 68 69 /** 70 * Free block starts at offset 71 * input: pointer to a block 72 * return: 0 if OK, -1 if error 73 */ 74 extern int u_mmFreeMem(struct mem_block *b); 75 76 /** 77 * Free block starts at offset 78 * input: pointer to a heap, start offset 79 * return: pointer to a block 80 */ 81 extern struct mem_block *u_mmFindBlock(struct mem_block *heap, int start); 82 83 /** 84 * destroy MM 85 */ 86 extern void u_mmDestroy(struct mem_block *mmInit); 87 88 /** 89 * For debugging purposes. 90 */ 91 extern void u_mmDumpMemInfo(const struct mem_block *mmInit); 92 93 #ifdef __cplusplus 94 } 95 #endif 96 97 #endif 98