Merge from vendor branch NETGRAPH:
[dragonfly.git] / sys / dev / drm / sis_ds.h
1 /* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2  * Created: Mon Jan  4 10:05:05 1999 by sclin@sis.com.tw
3  */
4 /*
5  * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
6  * All rights reserved.
7  *
8  * Permission is hereby granted, free of charge, to any person obtaining a
9  * copy of this software and associated documentation files (the "Software"),
10  * to deal in the Software without restriction, including without limitation
11  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12  * and/or sell copies of the Software, and to permit persons to whom the
13  * Software is furnished to do so, subject to the following conditions:
14  *
15  * The above copyright notice and this permission notice (including the next
16  * paragraph) shall be included in all copies or substantial portions of the
17  * Software.
18  *
19  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22  * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23  * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24  * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25  * DEALINGS IN THE SOFTWARE.
26  *
27  * Authors:
28  *    Sung-Ching Lin <sclin@sis.com.tw>
29  *
30  * $DragonFly: src/sys/dev/drm/sis_ds.h,v 1.1 2008/04/05 18:12:29 hasso Exp $
31  */
32
33 #ifndef __SIS_DS_H__
34 #define __SIS_DS_H__
35
36 /* Set Data Structure */
37
38 #define SET_SIZE 5000
39
40 typedef unsigned long ITEM_TYPE;
41
42 typedef struct {
43         ITEM_TYPE val;
44         int alloc_next, free_next;
45 } list_item_t;
46
47 typedef struct {
48         int alloc;
49         int free;
50         int trace;
51         list_item_t list[SET_SIZE];
52 } set_t;
53
54 set_t *setInit(void);
55 int setAdd(set_t * set, ITEM_TYPE item);
56 int setDel(set_t * set, ITEM_TYPE item);
57 int setFirst(set_t * set, ITEM_TYPE * item);
58 int setNext(set_t * set, ITEM_TYPE * item);
59 int setDestroy(set_t * set);
60
61 /*
62  * GLX Hardware Device Driver common code
63  * Copyright (C) 1999 Wittawat Yamwong
64  *
65  * Permission is hereby granted, free of charge, to any person obtaining a
66  * copy of this software and associated documentation files (the "Software"),
67  * to deal in the Software without restriction, including without limitation
68  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
69  * and/or sell copies of the Software, and to permit persons to whom the
70  * Software is furnished to do so, subject to the following conditions:
71  *
72  * The above copyright notice and this permission notice shall be included
73  * in all copies or substantial portions of the Software.
74  *
75  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
76  * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
77  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
78  * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
79  * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
80  * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
81  * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
82  *
83  */
84
85 struct mem_block_t {
86         struct mem_block_t *next;
87         struct mem_block_t *heap;
88         int ofs, size;
89         int align;
90         unsigned int free:1;
91         unsigned int reserved:1;
92 };
93 typedef struct mem_block_t TMemBlock;
94 typedef struct mem_block_t *PMemBlock;
95
96 /* a heap is just the first block in a chain */
97 typedef struct mem_block_t memHeap_t;
98
99 static __inline__ int mmBlockSize(PMemBlock b)
100 {
101         return b->size;
102 }
103
104 static __inline__ int mmOffset(PMemBlock b)
105 {
106         return b->ofs;
107 }
108
109 static __inline__ void mmMarkReserved(PMemBlock b)
110 {
111         b->reserved = 1;
112 }
113
114 /*
115  * input: total size in bytes
116  * return: a heap pointer if OK, NULL if error
117  */
118 memHeap_t *mmInit(int ofs, int size);
119
120 /*
121  * Allocate 'size' bytes with 2^align2 bytes alignment,
122  * restrict the search to free memory after 'startSearch'
123  * depth and back buffers should be in different 4mb banks
124  * to get better page hits if possible
125  * input:       size = size of block
126  *              align2 = 2^align2 bytes alignment
127  *              startSearch = linear offset from start of heap to begin search
128  * return: pointer to the allocated block, 0 if error
129  */
130 PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch);
131
132 /*
133  * Returns 1 if the block 'b' is part of the heap 'heap'
134  */
135 int mmBlockInHeap(PMemBlock heap, PMemBlock b);
136
137 /*
138  * Free block starts at offset
139  * input: pointer to a block
140  * return: 0 if OK, -1 if error
141  */
142 int mmFreeMem(PMemBlock b);
143
144 /* For debuging purpose. */
145 void mmDumpMemInfo(memHeap_t * mmInit);
146
147 #endif                          /* __SIS_DS_H__ */