Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 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 | |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 24 | /** |
| 25 | * Memory manager code. Primarily used by device drivers to manage texture |
| 26 | * heaps, etc. |
| 27 | */ |
| 28 | |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 29 | #ifndef MM_H |
| 30 | #define MM_H |
| 31 | |
| 32 | struct mem_block { |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 33 | struct mem_block *next, *prev; |
| 34 | struct mem_block *next_free, *prev_free; |
| 35 | struct mem_block *heap; |
| 36 | int ofs, size; |
| 37 | unsigned int free:1; |
| 38 | unsigned int reserved:1; |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 39 | }; |
| 40 | |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 41 | /* Rename the variables in the drm copy of this code so that it doesn't |
| 42 | * conflict with mesa or whoever else has copied it around. |
| 43 | */ |
| 44 | #define mmInit drm_mmInit |
| 45 | #define mmAllocMem drm_mmAllocMem |
| 46 | #define mmFreeMem drm_mmFreeMem |
| 47 | #define mmFindBlock drm_mmFindBlock |
| 48 | #define mmDestroy drm_mmDestroy |
| 49 | #define mmDumpMemInfo drm_mmDumpMemInfo |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 50 | |
| 51 | /** |
| 52 | * input: total size in bytes |
| 53 | * return: a heap pointer if OK, NULL if error |
| 54 | */ |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 55 | extern struct mem_block *mmInit(int ofs, int size); |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 56 | |
| 57 | /** |
| 58 | * Allocate 'size' bytes with 2^align2 bytes alignment, |
| 59 | * restrict the search to free memory after 'startSearch' |
| 60 | * depth and back buffers should be in different 4mb banks |
| 61 | * to get better page hits if possible |
| 62 | * input: size = size of block |
| 63 | * align2 = 2^align2 bytes alignment |
| 64 | * startSearch = linear offset from start of heap to begin search |
| 65 | * return: pointer to the allocated block, 0 if error |
| 66 | */ |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 67 | extern struct mem_block *mmAllocMem(struct mem_block *heap, int size, |
Eric Anholt | d70d605 | 2009-10-06 12:40:42 -0700 | [diff] [blame] | 68 | int align2, int startSearch); |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 69 | |
| 70 | /** |
| 71 | * Free block starts at offset |
| 72 | * input: pointer to a block |
| 73 | * return: 0 if OK, -1 if error |
| 74 | */ |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 75 | extern int mmFreeMem(struct mem_block *b); |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 76 | |
| 77 | /** |
| 78 | * Free block starts at offset |
| 79 | * input: pointer to a heap, start offset |
| 80 | * return: pointer to a block |
| 81 | */ |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 82 | extern struct mem_block *mmFindBlock(struct mem_block *heap, int start); |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 83 | |
| 84 | /** |
| 85 | * destroy MM |
| 86 | */ |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 87 | extern void mmDestroy(struct mem_block *mmInit); |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 88 | |
| 89 | /** |
| 90 | * For debuging purpose. |
| 91 | */ |
Eric Anholt | 57b4c4c | 2008-06-11 15:58:33 -0700 | [diff] [blame] | 92 | extern void mmDumpMemInfo(const struct mem_block *mmInit); |
Eric Anholt | c485742 | 2008-06-03 10:20:49 -0700 | [diff] [blame] | 93 | |
| 94 | #endif |