sis_ds.h revision 126533
119960Sjoerg/* sis_ds.h -- Private header for Direct Rendering Manager -*- linux-c -*-
219304Speter * Created: Mon Jan  4 10:05:05 1999 by sclin@sis.com.tw
319960Sjoerg *
419960Sjoerg * Copyright 2000 Silicon Integrated Systems Corp, Inc., HsinChu, Taiwan.
519304Speter * All rights reserved.
619960Sjoerg *
719960Sjoerg * Permission is hereby granted, free of charge, to any person obtaining a
819304Speter * copy of this software and associated documentation files (the "Software"),
919960Sjoerg * to deal in the Software without restriction, including without limitation
1019960Sjoerg * the rights to use, copy, modify, merge, publish, distribute, sublicense,
1119960Sjoerg * and/or sell copies of the Software, and to permit persons to whom the
1219960Sjoerg * Software is furnished to do so, subject to the following conditions:
1319960Sjoerg *
1419960Sjoerg * The above copyright notice and this permission notice (including the next
1519960Sjoerg * paragraph) shall be included in all copies or substantial portions of the
1619960Sjoerg * Software.
1719960Sjoerg *
1819304Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1919304Speter * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
2019304Speter * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
2119960Sjoerg * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
2219960Sjoerg * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
2319960Sjoerg * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
2419960Sjoerg * DEALINGS IN THE SOFTWARE.
2519304Speter *
2619304Speter * Authors:
2719304Speter *    Sung-Ching Lin <sclin@sis.com.tw>
2819304Speter *
2919304Speter * $FreeBSD: head/sys/dev/drm/sis_ds.h 126533 2004-03-03 08:24:31Z obrien $
3019960Sjoerg */
3119304Speter
3219960Sjoerg#ifndef __SIS_DS_H__
3319960Sjoerg#define __SIS_DS_H__
3419960Sjoerg
3519960Sjoerg/* Set Data Structure */
3619960Sjoerg
3719960Sjoerg#define SET_SIZE 5000
3819960Sjoerg
3919960Sjoergtypedef unsigned long ITEM_TYPE;
4019960Sjoerg
4119960Sjoergtypedef struct {
4219960Sjoerg	ITEM_TYPE val;
4319960Sjoerg	int alloc_next, free_next;
4419960Sjoerg} list_item_t;
4519960Sjoerg
46254225Spetertypedef struct {
4719960Sjoerg	int alloc;
4819304Speter	int free;
4919960Sjoerg	int trace;
5019960Sjoerg	list_item_t list[SET_SIZE];
5119960Sjoerg} set_t;
5219960Sjoerg
5319960Sjoergset_t *setInit(void);
5419960Sjoergint setAdd(set_t *set, ITEM_TYPE item);
5519960Sjoergint setDel(set_t *set, ITEM_TYPE item);
5619960Sjoergint setFirst(set_t *set, ITEM_TYPE *item);
5719960Sjoergint setNext(set_t *set, ITEM_TYPE *item);
5819960Sjoergint setDestroy(set_t *set);
5919960Sjoerg
6019960Sjoerg/*
6119960Sjoerg * GLX Hardware Device Driver common code
6219960Sjoerg * Copyright (C) 1999 Keith Whitwell
6319960Sjoerg *
6419960Sjoerg * Permission is hereby granted, free of charge, to any person obtaining a
6519304Speter * copy of this software and associated documentation files (the "Software"),
6619960Sjoerg * to deal in the Software without restriction, including without limitation
6719304Speter * the rights to use, copy, modify, merge, publish, distribute, sublicense,
6819960Sjoerg * and/or sell copies of the Software, and to permit persons to whom the
6919304Speter * Software is furnished to do so, subject to the following conditions:
7019960Sjoerg *
7119960Sjoerg * The above copyright notice and this permission notice shall be included
7219304Speter * in all copies or substantial portions of the Software.
7319960Sjoerg *
7419304Speter * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
7519304Speter * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
7619960Sjoerg * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
7719960Sjoerg * KEITH WHITWELL, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM,
7819304Speter * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
7919304Speter * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE
8019960Sjoerg * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
8119960Sjoerg *
8219960Sjoerg */
8319960Sjoerg
8419960Sjoergstruct mem_block_t {
8519960Sjoerg	struct mem_block_t *next;
8619960Sjoerg	struct mem_block_t *heap;
8719960Sjoerg	int ofs,size;
8819304Speter	int align;
8919960Sjoerg	int free:1;
9019960Sjoerg	int reserved:1;
9119304Speter};
9219960Sjoergtypedef struct mem_block_t TMemBlock;
9319960Sjoergtypedef struct mem_block_t *PMemBlock;
9419304Speter
9519960Sjoerg/* a heap is just the first block in a chain */
9619304Spetertypedef struct mem_block_t memHeap_t;
9719304Speter
9819960Sjoergstatic __inline__ int mmBlockSize(PMemBlock b)
99254225Speter{
10019960Sjoerg	return b->size;
10119960Sjoerg}
102254225Speter
10319960Sjoergstatic __inline__ int mmOffset(PMemBlock b)
10419960Sjoerg{
10519960Sjoerg	return b->ofs;
10619960Sjoerg}
10719960Sjoerg
108254225Speterstatic __inline__ void mmMarkReserved(PMemBlock b)
10919960Sjoerg{
11019960Sjoerg	b->reserved = 1;
11119304Speter}
11219304Speter
11319960Sjoerg/*
11419960Sjoerg * input: total size in bytes
11519960Sjoerg * return: a heap pointer if OK, NULL if error
11619960Sjoerg */
11719960SjoergmemHeap_t *mmInit( int ofs, int size );
11819960Sjoerg
11919960SjoergmemHeap_t *mmAddRange( memHeap_t *heap,
12019960Sjoerg		       int ofs,
12119960Sjoerg		       int size );
12219960Sjoerg
12319960Sjoerg/*
12419960Sjoerg * Allocate 'size' bytes with 2^align2 bytes alignment,
12519960Sjoerg * restrict the search to free memory after 'startSearch'
12619960Sjoerg * depth and back buffers should be in different 4mb banks
12719960Sjoerg * to get better page hits if possible
128254225Speter * input:	size = size of block
12919960Sjoerg *       	align2 = 2^align2 bytes alignment
13019960Sjoerg *		startSearch = linear offset from start of heap to begin search
13119304Speter * return: pointer to the allocated block, 0 if error
13219960Sjoerg */
13319960SjoergPMemBlock mmAllocMem( memHeap_t *heap, int size, int align2, int startSearch );
13419960Sjoerg
13519960Sjoerg/*
13619960Sjoerg * Returns 1 if the block 'b' is part of the heap 'heap'
13719960Sjoerg */
13819960Sjoergint mmBlockInHeap( PMemBlock heap, PMemBlock b );
13919304Speter
14019304Speter/*
14119960Sjoerg * Free block starts at offset
14219960Sjoerg * input: pointer to a block
14319304Speter * return: 0 if OK, -1 if error
14419960Sjoerg */
14519960Sjoergint mmFreeMem( PMemBlock b );
14619960Sjoerg
14719960Sjoerg/*
14819960Sjoerg * Reserve 'size' bytes block start at offset
14919304Speter * This is used to prevent allocation of memory already used
15019960Sjoerg * by the X server for the front buffer, pixmaps, and cursor
15119960Sjoerg * input: size, offset
15219960Sjoerg * output: 0 if OK, -1 if error
15319304Speter */
15419960Sjoergint mmReserveMem( memHeap_t *heap, int offset,int size );
15519304Speterint mmFreeReserved( memHeap_t *heap, int offset );
15619304Speter
15719960Sjoerg/*
15819304Speter * destroy MM
15919304Speter */
16019960Sjoergvoid mmDestroy( memHeap_t *mmInit );
16119304Speter
16219304Speter/* For debuging purpose. */
16319304Spetervoid mmDumpMemInfo( memHeap_t *mmInit );
16419960Sjoerg
16519960Sjoerg#endif /* __SIS_DS_H__ */
16619960Sjoerg