include sched.h to get sched_yield() prototype
[mesa.git] / src / mesa / drivers / dri / common / mm.h
1 /*
2 * GLX Hardware Device Driver common code
3 * Copyright (C) 1999 Keith Whitwell
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 #ifndef MM_INC
26 #define MM_INC
27
28 struct mem_block_t {
29 struct mem_block_t *next;
30 struct mem_block_t *heap;
31 int ofs,size;
32 int align;
33 int free:1;
34 int reserved:1;
35 };
36 typedef struct mem_block_t TMemBlock;
37 typedef struct mem_block_t *PMemBlock;
38
39 /* a heap is just the first block in a chain */
40 typedef struct mem_block_t memHeap_t;
41
42 static __inline__ int mmBlockSize(PMemBlock b)
43 { return b->size; }
44
45 static __inline__ int mmOffset(PMemBlock b)
46 { return b->ofs; }
47
48 /*
49 * input: total size in bytes
50 * return: a heap pointer if OK, NULL if error
51 */
52 memHeap_t *mmInit( int ofs, int size );
53
54 /*
55 * Allocate 'size' bytes with 2^align2 bytes alignment,
56 * restrict the search to free memory after 'startSearch'
57 * depth and back buffers should be in different 4mb banks
58 * to get better page hits if possible
59 * input: size = size of block
60 * align2 = 2^align2 bytes alignment
61 * startSearch = linear offset from start of heap to begin search
62 * return: pointer to the allocated block, 0 if error
63 */
64 PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2,
65 int startSearch );
66
67 /*
68 * Free block starts at offset
69 * input: pointer to a block
70 * return: 0 if OK, -1 if error
71 */
72 int mmFreeMem( PMemBlock b );
73
74 /*
75 * destroy MM
76 */
77 void mmDestroy( memHeap_t *mmInit );
78
79 /* For debuging purpose. */
80 void mmDumpMemInfo( memHeap_t *mmInit );
81
82 #endif