mm.h revision 22944501
122944501Smrg/* 222944501Smrg * GLX Hardware Device Driver common code 322944501Smrg * Copyright (C) 1999 Wittawat Yamwong 422944501Smrg * 522944501Smrg * Permission is hereby granted, free of charge, to any person obtaining a 622944501Smrg * copy of this software and associated documentation files (the "Software"), 722944501Smrg * to deal in the Software without restriction, including without limitation 822944501Smrg * the rights to use, copy, modify, merge, publish, distribute, sublicense, 922944501Smrg * and/or sell copies of the Software, and to permit persons to whom the 1022944501Smrg * Software is furnished to do so, subject to the following conditions: 1122944501Smrg * 1222944501Smrg * The above copyright notice and this permission notice shall be included 1322944501Smrg * in all copies or substantial portions of the Software. 1422944501Smrg * 1522944501Smrg * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 1622944501Smrg * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 1722944501Smrg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 1822944501Smrg * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, 1922944501Smrg * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR 2022944501Smrg * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE 2122944501Smrg * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 2222944501Smrg */ 2322944501Smrg 2422944501Smrg/** 2522944501Smrg * Memory manager code. Primarily used by device drivers to manage texture 2622944501Smrg * heaps, etc. 2722944501Smrg */ 2822944501Smrg 2922944501Smrg#ifndef MM_H 3022944501Smrg#define MM_H 3122944501Smrg 3222944501Smrgstruct mem_block { 3322944501Smrg struct mem_block *next, *prev; 3422944501Smrg struct mem_block *next_free, *prev_free; 3522944501Smrg struct mem_block *heap; 3622944501Smrg int ofs, size; 3722944501Smrg unsigned int free:1; 3822944501Smrg unsigned int reserved:1; 3922944501Smrg}; 4022944501Smrg 4122944501Smrg/* Rename the variables in the drm copy of this code so that it doesn't 4222944501Smrg * conflict with mesa or whoever else has copied it around. 4322944501Smrg */ 4422944501Smrg#define mmInit drm_mmInit 4522944501Smrg#define mmAllocMem drm_mmAllocMem 4622944501Smrg#define mmFreeMem drm_mmFreeMem 4722944501Smrg#define mmFindBlock drm_mmFindBlock 4822944501Smrg#define mmDestroy drm_mmDestroy 4922944501Smrg#define mmDumpMemInfo drm_mmDumpMemInfo 5022944501Smrg 5122944501Smrg/** 5222944501Smrg * input: total size in bytes 5322944501Smrg * return: a heap pointer if OK, NULL if error 5422944501Smrg */ 5522944501Smrgextern struct mem_block *mmInit(int ofs, int size); 5622944501Smrg 5722944501Smrg/** 5822944501Smrg * Allocate 'size' bytes with 2^align2 bytes alignment, 5922944501Smrg * restrict the search to free memory after 'startSearch' 6022944501Smrg * depth and back buffers should be in different 4mb banks 6122944501Smrg * to get better page hits if possible 6222944501Smrg * input: size = size of block 6322944501Smrg * align2 = 2^align2 bytes alignment 6422944501Smrg * startSearch = linear offset from start of heap to begin search 6522944501Smrg * return: pointer to the allocated block, 0 if error 6622944501Smrg */ 6722944501Smrgextern struct mem_block *mmAllocMem(struct mem_block *heap, int size, 6822944501Smrg int align2, int startSearch); 6922944501Smrg 7022944501Smrg/** 7122944501Smrg * Free block starts at offset 7222944501Smrg * input: pointer to a block 7322944501Smrg * return: 0 if OK, -1 if error 7422944501Smrg */ 7522944501Smrgextern int mmFreeMem(struct mem_block *b); 7622944501Smrg 7722944501Smrg/** 7822944501Smrg * Free block starts at offset 7922944501Smrg * input: pointer to a heap, start offset 8022944501Smrg * return: pointer to a block 8122944501Smrg */ 8222944501Smrgextern struct mem_block *mmFindBlock(struct mem_block *heap, int start); 8322944501Smrg 8422944501Smrg/** 8522944501Smrg * destroy MM 8622944501Smrg */ 8722944501Smrgextern void mmDestroy(struct mem_block *mmInit); 8822944501Smrg 8922944501Smrg/** 9022944501Smrg * For debuging purpose. 9122944501Smrg */ 9222944501Smrgextern void mmDumpMemInfo(const struct mem_block *mmInit); 9322944501Smrg 9422944501Smrg#endif 95