17ec681f3Smrg/************************************************************************** 27ec681f3Smrg * 37ec681f3Smrg * Copyright (C) 1999 Wittawat Yamwong 47ec681f3Smrg * 57ec681f3Smrg * Permission is hereby granted, free of charge, to any person obtaining a 67ec681f3Smrg * copy of this software and associated documentation files (the "Software"), 77ec681f3Smrg * to deal in the Software without restriction, including without limitation 87ec681f3Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 97ec681f3Smrg * and/or sell copies of the Software, and to permit persons to whom the 107ec681f3Smrg * Software is furnished to do so, subject to the following conditions: 117ec681f3Smrg * 127ec681f3Smrg * The above copyright notice and this permission notice shall be included 137ec681f3Smrg * in all copies or substantial portions of the Software. 147ec681f3Smrg * 157ec681f3Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 167ec681f3Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 177ec681f3Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 187ec681f3Smrg * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 197ec681f3Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 207ec681f3Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 217ec681f3Smrg * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 227ec681f3Smrg * 237ec681f3Smrg **************************************************************************/ 247ec681f3Smrg 257ec681f3Smrg 267ec681f3Smrg/** 277ec681f3Smrg * @file 287ec681f3Smrg * Memory manager code. Primarily used by device drivers to manage texture 297ec681f3Smrg * heaps, etc. 307ec681f3Smrg */ 317ec681f3Smrg 327ec681f3Smrg 337ec681f3Smrg#ifndef _U_MM_H_ 347ec681f3Smrg#define _U_MM_H_ 357ec681f3Smrg 367ec681f3Smrg 377ec681f3Smrgstruct mem_block { 387ec681f3Smrg struct mem_block *next, *prev; 397ec681f3Smrg struct mem_block *next_free, *prev_free; 407ec681f3Smrg struct mem_block *heap; 417ec681f3Smrg int ofs,size; 427ec681f3Smrg unsigned int free:1; 437ec681f3Smrg unsigned int reserved:1; 447ec681f3Smrg}; 457ec681f3Smrg 467ec681f3Smrg 477ec681f3Smrg 487ec681f3Smrg/** 497ec681f3Smrg * input: total size in bytes 507ec681f3Smrg * return: a heap pointer if OK, NULL if error 517ec681f3Smrg */ 527ec681f3Smrgextern struct mem_block *u_mmInit(int ofs, int size); 537ec681f3Smrg 547ec681f3Smrg/** 557ec681f3Smrg * Allocate 'size' bytes with 2^align2 bytes alignment, 567ec681f3Smrg * restrict the search to free memory after 'startSearch' 577ec681f3Smrg * depth and back buffers should be in different 4mb banks 587ec681f3Smrg * to get better page hits if possible 597ec681f3Smrg * input: size = size of block 607ec681f3Smrg * align2 = 2^align2 bytes alignment 617ec681f3Smrg * startSearch = linear offset from start of heap to begin search 627ec681f3Smrg * return: pointer to the allocated block, 0 if error 637ec681f3Smrg */ 647ec681f3Smrgextern struct mem_block *u_mmAllocMem(struct mem_block *heap, int size, int align2, 657ec681f3Smrg int startSearch); 667ec681f3Smrg 677ec681f3Smrg/** 687ec681f3Smrg * Free block starts at offset 697ec681f3Smrg * input: pointer to a block 707ec681f3Smrg * return: 0 if OK, -1 if error 717ec681f3Smrg */ 727ec681f3Smrgextern int u_mmFreeMem(struct mem_block *b); 737ec681f3Smrg 747ec681f3Smrg/** 757ec681f3Smrg * Free block starts at offset 767ec681f3Smrg * input: pointer to a heap, start offset 777ec681f3Smrg * return: pointer to a block 787ec681f3Smrg */ 797ec681f3Smrgextern struct mem_block *u_mmFindBlock(struct mem_block *heap, int start); 807ec681f3Smrg 817ec681f3Smrg/** 827ec681f3Smrg * destroy MM 837ec681f3Smrg */ 847ec681f3Smrgextern void u_mmDestroy(struct mem_block *mmInit); 857ec681f3Smrg 867ec681f3Smrg/** 877ec681f3Smrg * For debugging purposes. 887ec681f3Smrg */ 897ec681f3Smrgextern void u_mmDumpMemInfo(const struct mem_block *mmInit); 907ec681f3Smrg 917ec681f3Smrg#endif 92