1119895Sanholt/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2152909Sanholt * Created: Mon Jan  4 10:05:05 1999 by sclin@sis.com.tw
3152909Sanholt */
4139749Simp/*-
5119895Sanholt * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
6119895Sanholt * All rights reserved.
7119895Sanholt *
8119895Sanholt * Permission is hereby granted, free of charge, to any person obtaining a
9119895Sanholt * copy of this software and associated documentation files (the "Software"),
10119895Sanholt * to deal in the Software without restriction, including without limitation
11119895Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12119895Sanholt * and/or sell copies of the Software, and to permit persons to whom the
13119895Sanholt * Software is furnished to do so, subject to the following conditions:
14145132Sanholt *
15119895Sanholt * The above copyright notice and this permission notice (including the next
16119895Sanholt * paragraph) shall be included in all copies or substantial portions of the
17119895Sanholt * Software.
18145132Sanholt *
19119895Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20119895Sanholt * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21119895Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
22119895Sanholt * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23119895Sanholt * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24119895Sanholt * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25119895Sanholt * DEALINGS IN THE SOFTWARE.
26145132Sanholt *
27119895Sanholt * Authors:
28119895Sanholt *    Sung-Ching Lin <sclin@sis.com.tw>
29145132Sanholt *
30119895Sanholt */
31119895Sanholt
32152909Sanholt#include <sys/cdefs.h>
33152909Sanholt__FBSDID("$FreeBSD$");
34152909Sanholt
35119895Sanholt#ifndef __SIS_DS_H__
36119895Sanholt#define __SIS_DS_H__
37119895Sanholt
38119895Sanholt/* Set Data Structure */
39119895Sanholt
40119895Sanholt#define SET_SIZE 5000
41119895Sanholt
42126533Sobrientypedef unsigned long ITEM_TYPE;
43119895Sanholt
44119895Sanholttypedef struct {
45119895Sanholt	ITEM_TYPE val;
46119895Sanholt	int alloc_next, free_next;
47119895Sanholt} list_item_t;
48119895Sanholt
49119895Sanholttypedef struct {
50119895Sanholt	int alloc;
51119895Sanholt	int free;
52119895Sanholt	int trace;
53119895Sanholt	list_item_t list[SET_SIZE];
54119895Sanholt} set_t;
55119895Sanholt
56119895Sanholtset_t *setInit(void);
57145132Sanholtint setAdd(set_t * set, ITEM_TYPE item);
58145132Sanholtint setDel(set_t * set, ITEM_TYPE item);
59145132Sanholtint setFirst(set_t * set, ITEM_TYPE * item);
60145132Sanholtint setNext(set_t * set, ITEM_TYPE * item);
61145132Sanholtint setDestroy(set_t * set);
62119895Sanholt
63119895Sanholt/*
64119895Sanholt * GLX Hardware Device Driver common code
65145132Sanholt * Copyright (C) 1999 Wittawat Yamwong
66119895Sanholt *
67119895Sanholt * Permission is hereby granted, free of charge, to any person obtaining a
68119895Sanholt * copy of this software and associated documentation files (the "Software"),
69119895Sanholt * to deal in the Software without restriction, including without limitation
70119895Sanholt * the rights to use, copy, modify, merge, publish, distribute, sublicense,
71119895Sanholt * and/or sell copies of the Software, and to permit persons to whom the
72119895Sanholt * Software is furnished to do so, subject to the following conditions:
73119895Sanholt *
74119895Sanholt * The above copyright notice and this permission notice shall be included
75119895Sanholt * in all copies or substantial portions of the Software.
76119895Sanholt *
77119895Sanholt * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
78119895Sanholt * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79119895Sanholt * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
80157617Sanholt * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
81145132Sanholt * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
82145132Sanholt * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
83119895Sanholt * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84119895Sanholt *
85119895Sanholt */
86119895Sanholt
87119895Sanholtstruct mem_block_t {
88119895Sanholt	struct mem_block_t *next;
89119895Sanholt	struct mem_block_t *heap;
90145132Sanholt	int ofs, size;
91119895Sanholt	int align;
92145132Sanholt	unsigned int free:1;
93145132Sanholt	unsigned int reserved:1;
94119895Sanholt};
95119895Sanholttypedef struct mem_block_t TMemBlock;
96119895Sanholttypedef struct mem_block_t *PMemBlock;
97119895Sanholt
98119895Sanholt/* a heap is just the first block in a chain */
99119895Sanholttypedef struct mem_block_t memHeap_t;
100119895Sanholt
101119895Sanholtstatic __inline__ int mmBlockSize(PMemBlock b)
102119895Sanholt{
103119895Sanholt	return b->size;
104119895Sanholt}
105119895Sanholt
106119895Sanholtstatic __inline__ int mmOffset(PMemBlock b)
107119895Sanholt{
108119895Sanholt	return b->ofs;
109119895Sanholt}
110119895Sanholt
111119895Sanholtstatic __inline__ void mmMarkReserved(PMemBlock b)
112119895Sanholt{
113119895Sanholt	b->reserved = 1;
114119895Sanholt}
115119895Sanholt
116145132Sanholt/*
117119895Sanholt * input: total size in bytes
118119895Sanholt * return: a heap pointer if OK, NULL if error
119119895Sanholt */
120145132SanholtmemHeap_t *mmInit(int ofs, int size);
121119895Sanholt
122119895Sanholt/*
123119895Sanholt * Allocate 'size' bytes with 2^align2 bytes alignment,
124119895Sanholt * restrict the search to free memory after 'startSearch'
125119895Sanholt * depth and back buffers should be in different 4mb banks
126119895Sanholt * to get better page hits if possible
127119895Sanholt * input:	size = size of block
128119895Sanholt *       	align2 = 2^align2 bytes alignment
129119895Sanholt *		startSearch = linear offset from start of heap to begin search
130119895Sanholt * return: pointer to the allocated block, 0 if error
131119895Sanholt */
132145132SanholtPMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch);
133119895Sanholt
134119895Sanholt/*
135119895Sanholt * Returns 1 if the block 'b' is part of the heap 'heap'
136119895Sanholt */
137145132Sanholtint mmBlockInHeap(PMemBlock heap, PMemBlock b);
138119895Sanholt
139119895Sanholt/*
140119895Sanholt * Free block starts at offset
141119895Sanholt * input: pointer to a block
142119895Sanholt * return: 0 if OK, -1 if error
143119895Sanholt */
144145132Sanholtint mmFreeMem(PMemBlock b);
145119895Sanholt
146119895Sanholt/* For debuging purpose. */
147145132Sanholtvoid mmDumpMemInfo(memHeap_t * mmInit);
148119895Sanholt
149145132Sanholt#endif				/* __SIS_DS_H__ */
150