1 /* sis_ds.c -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
7 * Permission is hereby granted, free of charge, to any person obtaining a
8 * copy of this software and associated documentation files (the "Software"),
9 * to deal in the Software without restriction, including without limitation
10 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
11 * and/or sell copies of the Software, and to permit persons to whom the
12 * Software is furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice (including the next
15 * paragraph) shall be included in all copies or substantial portions of the
18 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
19 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
20 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
21 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
22 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
23 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
24 * DEALINGS IN THE SOFTWARE.
27 * Sung-Ching Lin <sclin@sis.com.tw>
34 /* Set Data Structure, not check repeated value
43 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
45 for (i = 0; i < SET_SIZE; i++) {
46 set->list[i].free_next = i + 1;
47 set->list[i].alloc_next = -1;
49 set->list[SET_SIZE - 1].free_next = -1;
57 int setAdd(set_t * set, ITEM_TYPE item)
62 set->list[free].val = item;
63 set->free = set->list[free].free_next;
68 set->list[free].alloc_next = set->alloc;
70 set->list[free].free_next = -1;
75 int setDel(set_t * set, ITEM_TYPE item)
77 int alloc = set->alloc;
81 if (set->list[alloc].val == item) {
83 set->list[prev].alloc_next =
84 set->list[alloc].alloc_next;
86 set->alloc = set->list[alloc].alloc_next;
90 alloc = set->list[alloc].alloc_next;
96 set->list[alloc].free_next = set->free;
98 set->list[alloc].alloc_next = -1;
103 /* setFirst -> setAdd -> setNext is wrong */
105 int setFirst(set_t * set, ITEM_TYPE * item)
107 if (set->alloc == -1)
110 *item = set->list[set->alloc].val;
111 set->trace = set->list[set->alloc].alloc_next;
116 int setNext(set_t * set, ITEM_TYPE * item)
118 if (set->trace == -1)
121 *item = set->list[set->trace].val;
122 set->trace = set->list[set->trace].alloc_next;
127 int setDestroy(set_t * set)
129 drm_free(set, DRM_MEM_DRIVER);
135 * GLX Hardware Device Driver common code
136 * Copyright (C) 1999 Wittawat Yamwong
138 * Permission is hereby granted, free of charge, to any person obtaining a
139 * copy of this software and associated documentation files (the "Software"),
140 * to deal in the Software without restriction, including without limitation
141 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
142 * and/or sell copies of the Software, and to permit persons to whom the
143 * Software is furnished to do so, subject to the following conditions:
145 * The above copyright notice and this permission notice shall be included
146 * in all copies or substantial portions of the Software.
148 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
149 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
150 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
151 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
152 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
153 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
154 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
158 #define ISFREE(bptr) ((bptr)->free)
160 memHeap_t *mmInit(int ofs, int size)
167 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
168 if (blocks != NULL) {
172 return (memHeap_t *) blocks;
177 /* Checks if a pointer 'b' is part of the heap 'heap' */
178 int mmBlockInHeap(memHeap_t * heap, PMemBlock b)
182 if (heap == NULL || b == NULL)
186 while (p != NULL && p != b) {
195 static TMemBlock *SliceBlock(TMemBlock * p,
196 int startofs, int size,
197 int reserved, int alignment)
202 if (startofs > p->ofs) {
203 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
205 newblock->ofs = startofs;
206 newblock->size = p->size - (startofs - p->ofs);
208 newblock->next = p->next;
209 p->size -= newblock->size;
215 if (size < p->size) {
216 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
218 newblock->ofs = startofs + size;
219 newblock->size = p->size - size;
221 newblock->next = p->next;
226 /* p = middle block */
227 p->align = alignment;
229 p->reserved = reserved;
233 PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch)
235 int mask, startofs, endofs;
238 if (heap == NULL || align2 < 0 || size <= 0)
241 mask = (1 << align2) - 1;
243 p = (TMemBlock *) heap;
246 startofs = (p->ofs + mask) & ~mask;
247 if (startofs < startSearch) {
248 startofs = startSearch;
250 endofs = startofs + size;
251 if (endofs <= (p->ofs + p->size))
258 p = SliceBlock(p, startofs, size, 0, mask + 1);
263 static __inline__ int Join2Blocks(TMemBlock * p)
265 if (p->free && p->next && p->next->free) {
266 TMemBlock *q = p->next;
269 drm_free(q, DRM_MEM_DRIVER);
275 int mmFreeMem(PMemBlock b)
286 while (p != NULL && p != b) {
290 if (p == NULL || p->free || p->reserved)