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