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>
31 #include <sys/cdefs.h>
32 __FBSDID("$FreeBSD$");
34 #include "dev/drm/drmP.h"
35 #include "dev/drm/drm.h"
36 #include "dev/drm/sis_ds.h"
38 /* Set Data Structure, not check repeated value
47 set = (set_t *) drm_alloc(sizeof(set_t), DRM_MEM_DRIVER);
49 for (i = 0; i < SET_SIZE; i++) {
50 set->list[i].free_next = i + 1;
51 set->list[i].alloc_next = -1;
53 set->list[SET_SIZE - 1].free_next = -1;
61 int setAdd(set_t * set, ITEM_TYPE item)
66 set->list[free].val = item;
67 set->free = set->list[free].free_next;
72 set->list[free].alloc_next = set->alloc;
74 set->list[free].free_next = -1;
79 int setDel(set_t * set, ITEM_TYPE item)
81 int alloc = set->alloc;
85 if (set->list[alloc].val == item) {
87 set->list[prev].alloc_next =
88 set->list[alloc].alloc_next;
90 set->alloc = set->list[alloc].alloc_next;
94 alloc = set->list[alloc].alloc_next;
100 set->list[alloc].free_next = set->free;
102 set->list[alloc].alloc_next = -1;
107 /* setFirst -> setAdd -> setNext is wrong */
109 int setFirst(set_t * set, ITEM_TYPE * item)
111 if (set->alloc == -1)
114 *item = set->list[set->alloc].val;
115 set->trace = set->list[set->alloc].alloc_next;
120 int setNext(set_t * set, ITEM_TYPE * item)
122 if (set->trace == -1)
125 *item = set->list[set->trace].val;
126 set->trace = set->list[set->trace].alloc_next;
131 int setDestroy(set_t * set)
133 drm_free(set, sizeof(set_t), DRM_MEM_DRIVER);
139 * GLX Hardware Device Driver common code
140 * Copyright (C) 1999 Wittawat Yamwong
142 * Permission is hereby granted, free of charge, to any person obtaining a
143 * copy of this software and associated documentation files (the "Software"),
144 * to deal in the Software without restriction, including without limitation
145 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
146 * and/or sell copies of the Software, and to permit persons to whom the
147 * Software is furnished to do so, subject to the following conditions:
149 * The above copyright notice and this permission notice shall be included
150 * in all copies or substantial portions of the Software.
152 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
153 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
154 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
155 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
156 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
157 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
158 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
162 #define ISFREE(bptr) ((bptr)->free)
164 memHeap_t *mmInit(int ofs, int size)
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 static TMemBlock *SliceBlock(TMemBlock * p,
200 int startofs, int size,
201 int reserved, int alignment)
206 if (startofs > p->ofs) {
207 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
209 newblock->ofs = startofs;
210 newblock->size = p->size - (startofs - p->ofs);
212 newblock->next = p->next;
213 p->size -= newblock->size;
219 if (size < p->size) {
220 newblock = (TMemBlock *) drm_calloc(1, sizeof(TMemBlock),
222 newblock->ofs = startofs + size;
223 newblock->size = p->size - size;
225 newblock->next = p->next;
230 /* p = middle block */
231 p->align = alignment;
233 p->reserved = reserved;
237 PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch)
239 int mask, startofs, endofs;
242 if (heap == NULL || align2 < 0 || size <= 0)
245 mask = (1 << align2) - 1;
247 p = (TMemBlock *) heap;
250 startofs = (p->ofs + mask) & ~mask;
251 if (startofs < startSearch) {
252 startofs = startSearch;
254 endofs = startofs + size;
255 if (endofs <= (p->ofs + p->size))
262 p = SliceBlock(p, startofs, size, 0, mask + 1);
267 static __inline__ int Join2Blocks(TMemBlock * p)
269 if (p->free && p->next && p->next->free) {
270 TMemBlock *q = p->next;
273 drm_free(q, sizeof(TMemBlock), DRM_MEM_DRIVER);
279 int mmFreeMem(PMemBlock b)
290 while (p != NULL && p != b) {
294 if (p == NULL || p->free || p->reserved)