blob: 94f2b4728b638bfdfbed941584e0521e1f3925c6 [file] [log] [blame]
Dave Airlie952d7512006-01-02 14:44:12 +11001/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
Linus Torvalds1da177e2005-04-16 15:20:36 -07002 * Created: Mon Jan 4 10:05:05 1999 by sclin@sis.com.tw
Dave Airlie952d7512006-01-02 14:44:12 +11003 */
4/*
Linus Torvalds1da177e2005-04-16 15:20:36 -07005 * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
6 * All rights reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
Dave Airlieb5e89ed2005-09-25 14:28:13 +100014 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070015 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
Dave Airlieb5e89ed2005-09-25 14:28:13 +100018 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070019 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
Dave Airlieb5e89ed2005-09-25 14:28:13 +100026 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070027 * Authors:
28 * Sung-Ching Lin <sclin@sis.com.tw>
Dave Airlieb5e89ed2005-09-25 14:28:13 +100029 *
Linus Torvalds1da177e2005-04-16 15:20:36 -070030 */
31
32#ifndef __SIS_DS_H__
33#define __SIS_DS_H__
34
35/* Set Data Structure */
36
37#define SET_SIZE 5000
38
Dave Airlie952d7512006-01-02 14:44:12 +110039typedef unsigned long ITEM_TYPE;
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41typedef struct {
42 ITEM_TYPE val;
43 int alloc_next, free_next;
44} list_item_t;
45
46typedef struct {
47 int alloc;
48 int free;
49 int trace;
50 list_item_t list[SET_SIZE];
51} set_t;
52
53set_t *setInit(void);
Dave Airlieb5e89ed2005-09-25 14:28:13 +100054int setAdd(set_t * set, ITEM_TYPE item);
55int setDel(set_t * set, ITEM_TYPE item);
56int setFirst(set_t * set, ITEM_TYPE * item);
57int setNext(set_t * set, ITEM_TYPE * item);
58int setDestroy(set_t * set);
Linus Torvalds1da177e2005-04-16 15:20:36 -070059
60/*
61 * GLX Hardware Device Driver common code
62 * Copyright (C) 1999 Wittawat Yamwong
63 *
64 * Permission is hereby granted, free of charge, to any person obtaining a
65 * copy of this software and associated documentation files (the "Software"),
66 * to deal in the Software without restriction, including without limitation
67 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
68 * and/or sell copies of the Software, and to permit persons to whom the
69 * Software is furnished to do so, subject to the following conditions:
70 *
71 * The above copyright notice and this permission notice shall be included
72 * in all copies or substantial portions of the Software.
73 *
74 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
75 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
76 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
Dave Airlieb5e89ed2005-09-25 14:28:13 +100077 * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
78 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
79 * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
Linus Torvalds1da177e2005-04-16 15:20:36 -070080 * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
81 *
82 */
83
84struct mem_block_t {
85 struct mem_block_t *next;
86 struct mem_block_t *heap;
Dave Airlieb5e89ed2005-09-25 14:28:13 +100087 int ofs, size;
Linus Torvalds1da177e2005-04-16 15:20:36 -070088 int align;
89 unsigned int free:1;
90 unsigned int reserved:1;
91};
92typedef struct mem_block_t TMemBlock;
93typedef struct mem_block_t *PMemBlock;
94
95/* a heap is just the first block in a chain */
96typedef struct mem_block_t memHeap_t;
97
98static __inline__ int mmBlockSize(PMemBlock b)
99{
100 return b->size;
101}
102
103static __inline__ int mmOffset(PMemBlock b)
104{
105 return b->ofs;
106}
107
108static __inline__ void mmMarkReserved(PMemBlock b)
109{
110 b->reserved = 1;
111}
112
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000113/*
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114 * input: total size in bytes
115 * return: a heap pointer if OK, NULL if error
116 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000117memHeap_t *mmInit(int ofs, int size);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700118
119/*
120 * Allocate 'size' bytes with 2^align2 bytes alignment,
121 * restrict the search to free memory after 'startSearch'
122 * depth and back buffers should be in different 4mb banks
123 * to get better page hits if possible
124 * input: size = size of block
125 * align2 = 2^align2 bytes alignment
126 * startSearch = linear offset from start of heap to begin search
127 * return: pointer to the allocated block, 0 if error
128 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000129PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
131/*
132 * Returns 1 if the block 'b' is part of the heap 'heap'
133 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000134int mmBlockInHeap(PMemBlock heap, PMemBlock b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700135
136/*
137 * Free block starts at offset
138 * input: pointer to a block
139 * return: 0 if OK, -1 if error
140 */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000141int mmFreeMem(PMemBlock b);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143/* For debuging purpose. */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000144void mmDumpMemInfo(memHeap_t * mmInit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700145
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000146#endif /* __SIS_DS_H__ */