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>
35 /* Set Data Structure, not check repeated value
44 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
46 for (i = 0; i < SET_SIZE; i++) {
47 set->list[i].free_next = i + 1;
48 set->list[i].alloc_next = -1;
50 set->list[SET_SIZE - 1].free_next = -1;
58 int setAdd(set_t * set, ITEM_TYPE item)
63 set->list[free].val = item;
64 set->free = set->list[free].free_next;
69 set->list[free].alloc_next = set->alloc;
71 set->list[free].free_next = -1;
76 int setDel(set_t * set, ITEM_TYPE item)
78 int alloc = set->alloc;
82 if (set->list[alloc].val == item) {
84 set->list[prev].alloc_next =
85 set->list[alloc].alloc_next;
87 set->alloc = set->list[alloc].alloc_next;
91 alloc = set->list[alloc].alloc_next;
97 set->list[alloc].free_next = set->free;
99 set->list[alloc].alloc_next = -1;
104 /* setFirst -> setAdd -> setNext is wrong */
106 int setFirst(set_t * set, ITEM_TYPE * item)
108 if (set->alloc == -1)
111 *item = set->list[set->alloc].val;
112 set->trace = set->list[set->alloc].alloc_next;
117 int setNext(set_t * set, ITEM_TYPE * item)
119 if (set->trace == -1)
122 *item = set->list[set->trace].val;
123 set->trace = set->list[set->trace].alloc_next;
128 int setDestroy(set_t * set)
130 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
136 * GLX Hardware Device Driver common code
137 * Copyright (C) 1999 Wittawat Yamwong
139 * Permission is hereby granted, free of charge, to any person obtaining a
140 * copy of this software and associated documentation files (the "Software"),
141 * to deal in the Software without restriction, including without limitation
142 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
143 * and/or sell copies of the Software, and to permit persons to whom the
144 * Software is furnished to do so, subject to the following conditions:
146 * The above copyright notice and this permission notice shall be included
147 * in all copies or substantial portions of the Software.
149 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
150 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
151 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
152 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
153 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
154 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
155 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
159 #define ISFREE(bptr) ((bptr)->free)
161 memHeap_t *mmInit(int ofs, int size)
168 blocks = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
169 if (blocks != NULL) {
173 return (memHeap_t *) blocks;
178 /* Checks if a pointer 'b' is part of the heap 'heap' */
179 int mmBlockInHeap(memHeap_t * heap, PMemBlock b)
183 if (heap == NULL || b == NULL)
187 while (p != NULL && p != b) {
196 static TMemBlock *SliceBlock(TMemBlock * p,
197 int startofs, int size,
198 int reserved, int alignment)
203 if (startofs > p->ofs) {
204 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
206 newblock->ofs = startofs;
207 newblock->size = p->size - (startofs - p->ofs);
209 newblock->next = p->next;
210 p->size -= newblock->size;
216 if (size < p->size) {
217 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
219 newblock->ofs = startofs + size;
220 newblock->size = p->size - size;
222 newblock->next = p->next;
227 /* p = middle block */
228 p->align = alignment;
230 p->reserved = reserved;
234 PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch)
236 int mask, startofs, endofs;
239 if (heap == NULL || align2 < 0 || size <= 0)
242 mask = (1 << align2) - 1;
244 p = (TMemBlock *) heap;
247 startofs = (p->ofs + mask) & ~mask;
248 if (startofs < startSearch) {
249 startofs = startSearch;
251 endofs = startofs + size;
252 if (endofs <= (p->ofs + p->size))
259 p = SliceBlock(p, startofs, size, 0, mask + 1);
264 static __inline__ int Join2Blocks(TMemBlock * p)
266 if (p->free && p->next && p->next->free) {
267 TMemBlock *q = p->next;
270 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
276 int mmFreeMem(PMemBlock b)
287 while (p != NULL && p != b) {
291 if (p == NULL || p->free || p->reserved)