1/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
2 * Created: Mon Jan  4 10:05:05 1999 by sclin@sis.com.tw
3 *
4 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
5 * All rights reserved.
6 *
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:
13 *
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
16 * Software.
17 *
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.
25 *
26 * Authors:
27 *    Sung-Ching Lin <sclin@sis.com.tw>
28 *
29 */
30
31#ifndef _sis_ds_h_
32#define _sis_ds_h_
33
34/* Set Data Structure */
35
36#define SET_SIZE 5000
37#define MALLOC(s) kmalloc(s, GFP_KERNEL)
38#define FREE(s) kfree(s)
39
40typedef unsigned int ITEM_TYPE;
41
42typedef struct {
43  ITEM_TYPE val;
44  int alloc_next, free_next;
45} list_item_t;
46
47typedef struct {
48  int alloc;
49  int free;
50  int trace;
51  list_item_t list[SET_SIZE];
52} set_t;
53
54set_t *setInit(void);
55int setAdd(set_t *set, ITEM_TYPE item);
56int setDel(set_t *set, ITEM_TYPE item);
57int setFirst(set_t *set, ITEM_TYPE *item);
58int setNext(set_t *set, ITEM_TYPE *item);
59int setDestroy(set_t *set);
60
61#endif
62
63/*
64 * GLX Hardware Device Driver common code
65 * Copyright (C) 1999 Keith Whitwell
66 *
67 * Permission is hereby granted, free of charge, to any person obtaining a
68 * copy of this software and associated documentation files (the "Software"),
69 * to deal in the Software without restriction, including without limitation
70 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
71 * and/or sell copies of the Software, and to permit persons to whom the
72 * Software is furnished to do so, subject to the following conditions:
73 *
74 * The above copyright notice and this permission notice shall be included
75 * in all copies or substantial portions of the Software.
76 *
77 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
78 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
79 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
80 * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
81 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
82 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
83 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
84 *
85 */
86
87#ifndef MM_INC
88#define MM_INC
89
90struct mem_block_t {
91  struct mem_block_t *next;
92  struct mem_block_t *heap;
93  int ofs,size;
94  int align;
95  int free:1;
96  int reserved:1;
97};
98typedef struct mem_block_t TMemBlock;
99typedef struct mem_block_t *PMemBlock;
100
101/* a heap is just the first block in a chain */
102typedef struct mem_block_t memHeap_t;
103
104static __inline__ int mmBlockSize(PMemBlock b)
105{ return b->size; }
106
107static __inline__ int mmOffset(PMemBlock b)
108{ return b->ofs; }
109
110static __inline__ void mmMarkReserved(PMemBlock b)
111{ b->reserved = 1; }
112
113/*
114 * input: total size in bytes
115 * return: a heap pointer if OK, NULL if error
116 */
117memHeap_t *mmInit( int ofs, int size );
118
119
120
121memHeap_t *mmAddRange( memHeap_t *heap,
122		       int ofs,
123		       int size );
124
125
126/*
127 * Allocate 'size' bytes with 2^align2 bytes alignment,
128 * restrict the search to free memory after 'startSearch'
129 * depth and back buffers should be in different 4mb banks
130 * to get better page hits if possible
131 * input:	size = size of block
132 *       	align2 = 2^align2 bytes alignment
133 *		startSearch = linear offset from start of heap to begin search
134 * return: pointer to the allocated block, 0 if error
135 */
136PMemBlock  mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch );
137
138/*
139 * Free block starts at offset
140 * input: pointer to a block
141 * return: 0 if OK, -1 if error
142 */
143int  mmFreeMem( PMemBlock b );
144
145/*
146 * Reserve 'size' bytes block start at offset
147 * This is used to prevent allocation of memory already used
148 * by the X server for the front buffer, pixmaps, and cursor
149 * input: size, offset
150 * output: 0 if OK, -1 if error
151 */
152int mmReserveMem( memHeap_t *heap, int offset,int size );
153int mmFreeReserved( memHeap_t *heap, int offset );
154
155/*
156 * destroy MM
157 */
158void mmDestroy( memHeap_t *mmInit );
159
160/* For debuging purpose. */
161void mmDumpMemInfo( memHeap_t *mmInit );
162
163#endif
164