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>
32 #include "dev/drm/sis.h"
33 #include "dev/drm/drmP.h"
34 #include "dev/drm/drm.h"
35 #include "dev/drm/sis_ds.h"
37 /* Set Data Structure, not check repeated value
46 set = (set_t *)DRM(alloc)(sizeof(set_t), DRM_MEM_DRIVER);
48 for (i = 0; i < SET_SIZE; i++) {
49 set->list[i].free_next = i + 1;
50 set->list[i].alloc_next = -1;
52 set->list[SET_SIZE-1].free_next = -1;
60 int setAdd(set_t *set, ITEM_TYPE item)
65 set->list[free].val = item;
66 set->free = set->list[free].free_next;
71 set->list[free].alloc_next = set->alloc;
73 set->list[free].free_next = -1;
78 int setDel(set_t *set, ITEM_TYPE item)
80 int alloc = set->alloc;
84 if (set->list[alloc].val == item) {
86 set->list[prev].alloc_next =
87 set->list[alloc].alloc_next;
89 set->alloc = set->list[alloc].alloc_next;
93 alloc = set->list[alloc].alloc_next;
99 set->list[alloc].free_next = set->free;
101 set->list[alloc].alloc_next = -1;
106 /* setFirst -> setAdd -> setNext is wrong */
108 int setFirst(set_t *set, ITEM_TYPE *item)
110 if (set->alloc == -1)
113 *item = set->list[set->alloc].val;
114 set->trace = set->list[set->alloc].alloc_next;
119 int setNext(set_t *set, ITEM_TYPE *item)
121 if (set->trace == -1)
124 *item = set->list[set->trace].val;
125 set->trace = set->list[set->trace].alloc_next;
130 int setDestroy(set_t *set)
132 DRM(free)(set, sizeof(set_t), DRM_MEM_DRIVER);
138 * GLX Hardware Device Driver common code
139 * Copyright (C) 1999 Keith Whitwell
141 * Permission is hereby granted, free of charge, to any person obtaining a
142 * copy of this software and associated documentation files (the "Software"),
143 * to deal in the Software without restriction, including without limitation
144 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
145 * and/or sell copies of the Software, and to permit persons to whom the
146 * Software is furnished to do so, subject to the following conditions:
148 * The above copyright notice and this permission notice shall be included
149 * in all copies or substantial portions of the Software.
151 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
152 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
153 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
154 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
155 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
156 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
157 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
161 #define ISFREE(bptr) ((bptr)->free)
163 memHeap_t *mmInit(int ofs,
171 blocks = (TMemBlock *)DRM(calloc)(1, sizeof(TMemBlock), DRM_MEM_DRIVER);
172 if (blocks != NULL) {
176 return (memHeap_t *)blocks;
181 /* Checks if a pointer 'b' is part of the heap 'heap' */
182 int mmBlockInHeap(memHeap_t *heap, PMemBlock b)
186 if (heap == NULL || b == NULL)
190 while (p != NULL && p != b) {
199 /* Kludgey workaround for existing i810 server. Remove soon.
201 memHeap_t *mmAddRange( memHeap_t *heap,
206 blocks = (TMemBlock *)DRM(calloc)(2, sizeof(TMemBlock), DRM_MEM_DRIVER);
207 if (blocks != NULL) {
208 blocks[0].size = size;
211 blocks[0].next = &blocks[1];
213 /* Discontinuity - stops JoinBlock from trying to join
214 * non-adjacent ranges.
218 blocks[1].ofs = ofs+size;
219 blocks[1].next = (PMemBlock)heap;
220 return (memHeap_t *)blocks;
225 static TMemBlock* SliceBlock(TMemBlock *p,
226 int startofs, int size,
227 int reserved, int alignment)
232 if (startofs > p->ofs) {
233 newblock = (TMemBlock*) DRM(calloc)(1, sizeof(TMemBlock),
235 newblock->ofs = startofs;
236 newblock->size = p->size - (startofs - p->ofs);
238 newblock->next = p->next;
239 p->size -= newblock->size;
245 if (size < p->size) {
246 newblock = (TMemBlock*) DRM(calloc)(1, sizeof(TMemBlock),
248 newblock->ofs = startofs + size;
249 newblock->size = p->size - size;
251 newblock->next = p->next;
256 /* p = middle block */
257 p->align = alignment;
259 p->reserved = reserved;
263 PMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch)
265 int mask,startofs, endofs;
268 if (heap == NULL || align2 < 0 || size <= 0)
271 mask = (1 << align2)-1;
273 p = (TMemBlock *)heap;
276 startofs = (p->ofs + mask) & ~mask;
277 if ( startofs < startSearch ) {
278 startofs = startSearch;
280 endofs = startofs+size;
281 if (endofs <= (p->ofs+p->size))
288 p = SliceBlock(p,startofs,size,0,mask+1);
293 static __inline__ int Join2Blocks(TMemBlock *p)
295 if (p->free && p->next && p->next->free) {
296 TMemBlock *q = p->next;
299 DRM(free)(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
305 int mmFreeMem(PMemBlock b)
316 while (p != NULL && p != b) {
320 if (p == NULL || p->free || p->reserved)
330 int mmReserveMem(memHeap_t *heap, int offset,int size)
335 if (heap == NULL || size <= 0)
338 endofs = offset + size;
339 p = (TMemBlock *)heap;
340 while (p && p->ofs <= offset) {
341 if (ISFREE(p) && endofs <= (p->ofs+p->size)) {
342 SliceBlock(p,offset,size,1,1);
350 int mmFreeReserved(memHeap_t *heap, int offset)
357 p = (TMemBlock *)heap;
359 while (p != NULL && p->ofs != offset) {
363 if (p == NULL || !p->reserved)
374 void mmDestroy(memHeap_t *heap)
381 p = (TMemBlock *)heap;
384 DRM(free)(p, sizeof(TMemBlock), DRM_MEM_DRIVER);