Home | History | Annotate | Download | only in main
      1 /*
      2  * GLX Hardware Device Driver common code
      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  * Memory manager code.  Primarily used by device drivers to manage texture
     27  * heaps, etc.
     28  */
     29 
     30 
     31 #ifndef MM_H
     32 #define MM_H
     33 
     34 
     35 struct mem_block {
     36    struct mem_block *next, *prev;
     37    struct mem_block *next_free, *prev_free;
     38    struct mem_block *heap;
     39    unsigned ofs;
     40    unsigned size;
     41    unsigned free:1;
     42    unsigned reserved:1;
     43 };
     44 
     45 
     46 
     47 /**
     48  * input: total size in bytes
     49  * return: a heap pointer if OK, NULL if error
     50  */
     51 extern struct mem_block *mmInit(unsigned ofs, unsigned size);
     52 
     53 /**
     54  * Allocate 'size' bytes with 2^align2 bytes alignment,
     55  * restrict the search to free memory after 'startSearch'
     56  * depth and back buffers should be in different 4mb banks
     57  * to get better page hits if possible
     58  * input:	size = size of block
     59  *       	align2 = 2^align2 bytes alignment
     60  *		startSearch = linear offset from start of heap to begin search
     61  * return: pointer to the allocated block, 0 if error
     62  */
     63 extern struct mem_block *mmAllocMem(struct mem_block *heap, unsigned size,
     64                                     unsigned align2, unsigned startSearch);
     65 
     66 /**
     67  * Free block starts at offset
     68  * input: pointer to a block
     69  * return: 0 if OK, -1 if error
     70  */
     71 extern int mmFreeMem(struct mem_block *b);
     72 
     73 /**
     74  * Free block starts at offset
     75  * input: pointer to a heap, start offset
     76  * return: pointer to a block
     77  */
     78 extern struct mem_block *mmFindBlock(struct mem_block *heap, unsigned start);
     79 
     80 /**
     81  * destroy MM
     82  */
     83 extern void mmDestroy(struct mem_block *mmInit);
     84 
     85 /**
     86  * For debuging purpose.
     87  */
     88 extern void mmDumpMemInfo(const struct mem_block *mmInit);
     89 
     90 #endif
     91