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>
36 /* Set Data Structure, not check repeated value
45 set = (set_t *)DRM(alloc)(sizeof(set_t), DRM_MEM_DRIVER);
47 for (i = 0; i < SET_SIZE; i++) {
48 set->list[i].free_next = i + 1;
49 set->list[i].alloc_next = -1;
51 set->list[SET_SIZE-1].free_next = -1;
59 int setAdd(set_t *set, ITEM_TYPE item)
64 set->list[free].val = item;
65 set->free = set->list[free].free_next;
70 set->list[free].alloc_next = set->alloc;
72 set->list[free].free_next = -1;
77 int setDel(set_t *set, ITEM_TYPE item)
79 int alloc = set->alloc;
83 if (set->list[alloc].val == item) {
85 set->list[prev].alloc_next =
86 set->list[alloc].alloc_next;
88 set->alloc = set->list[alloc].alloc_next;
92 alloc = set->list[alloc].alloc_next;
98 set->list[alloc].free_next = set->free;
100 set->list[alloc].alloc_next = -1;
105 /* setFirst -> setAdd -> setNext is wrong */
107 int setFirst(set_t *set, ITEM_TYPE *item)
109 if (set->alloc == -1)
112 *item = set->list[set->alloc].val;
113 set->trace = set->list[set->alloc].alloc_next;
118 int setNext(set_t *set, ITEM_TYPE *item)
120 if (set->trace == -1)
123 *item = set->list[set->trace].val;
124 set->trace = set->list[set->trace].alloc_next;
129 int setDestroy(set_t *set)
131 DRM(free)(set, sizeof(set_t), DRM_MEM_DRIVER);
137 * GLX Hardware Device Driver common code
138 * Copyright (C) 1999 Keith Whitwell
140 * Permission is hereby granted, free of charge, to any person obtaining a
141 * copy of this software and associated documentation files (the "Software"),
142 * to deal in the Software without restriction, including without limitation
143 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
144 * and/or sell copies of the Software, and to permit persons to whom the
145 * Software is furnished to do so, subject to the following conditions:
147 * The above copyright notice and this permission notice shall be included
148 * in all copies or substantial portions of the Software.
150 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
151 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
152 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
153 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
154 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
155 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
156 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
160 #define ISFREE(bptr) ((bptr)->free)
162 memHeap_t *mmInit(int ofs,
170 blocks = (TMemBlock *)DRM(calloc)(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
171 if (blocks != NULL) {
175 return (memHeap_t *)blocks;
180 /* Checks if a pointer 'b' is part of the heap 'heap' */
181 int mmBlockInHeap(memHeap_t *heap, PMemBlock b)
185 if (heap == NULL || b == NULL)
189 while (p != NULL && p != b) {
198 /* Kludgey workaround for existing i810 server. Remove soon.
200 memHeap_t *mmAddRange( memHeap_t *heap,
205 blocks = (TMemBlock *)DRM(calloc)(2, sizeof(TMemBlock), DRM_MEM_DRIVER);
206 if (blocks != NULL) {
207 blocks[0].size = size;
210 blocks[0].next = &blocks[1];
212 /* Discontinuity - stops JoinBlock from trying to join
213 * non-adjacent ranges.
217 blocks[1].ofs = ofs+size;
218 blocks[1].next = (PMemBlock)heap;
219 return (memHeap_t *)blocks;
224 static TMemBlock* SliceBlock(TMemBlock *p,
225 int startofs, int size,
226 int reserved, int alignment)
231 if (startofs > p->ofs) {
232 newblock = (TMemBlock*) DRM(calloc)(1, sizeof(TMemBlock),
234 newblock->ofs = startofs;
235 newblock->size = p->size - (startofs - p->ofs);
237 newblock->next = p->next;
238 p->size -= newblock->size;
244 if (size < p->size) {
245 newblock = (TMemBlock*) DRM(calloc)(1, sizeof(TMemBlock),
247 newblock->ofs = startofs + size;
248 newblock->size = p->size - size;
250 newblock->next = p->next;
255 /* p = middle block */
256 p->align = alignment;
258 p->reserved = reserved;
262 PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch)
264 int mask,startofs, endofs;
267 if (heap == NULL || align2 < 0 || size <= 0)
270 mask = (1 << align2)-1;
272 p = (TMemBlock *)heap;
275 startofs = (p->ofs + mask) & ~mask;
276 if ( startofs < startSearch ) {
277 startofs = startSearch;
279 endofs = startofs+size;
280 if (endofs <= (p->ofs+p->size))
287 p = SliceBlock(p,startofs,size,0,mask+1);
292 static __inline__ int Join2Blocks(TMemBlock *p)
294 if (p->free && p->next && p->next->free) {
295 TMemBlock *q = p->next;
298 DRM(free)(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
304 int mmFreeMem(PMemBlock b)
315 while (p != NULL && p != b) {
319 if (p == NULL || p->free || p->reserved)
329 int mmReserveMem(memHeap_t *heap, int offset,int size)
334 if (heap == NULL || size <= 0)
337 endofs = offset + size;
338 p = (TMemBlock *)heap;
339 while (p && p->ofs <= offset) {
340 if (ISFREE(p) && endofs <= (p->ofs+p->size)) {
341 SliceBlock(p,offset,size,1,1);
349 int mmFreeReserved(memHeap_t *heap, int offset)
356 p = (TMemBlock *)heap;
358 while (p != NULL && p->ofs != offset) {
362 if (p == NULL || !p->reserved)
373 void mmDestroy(memHeap_t *heap)
380 p = (TMemBlock *)heap;
383 DRM(free)(p, sizeof(TMemBlock), DRM_MEM_DRIVER);