Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 13 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 17 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 25 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | * Authors: |
| 27 | * Sung-Ching Lin <sclin@sis.com.tw> |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 28 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 29 | */ |
| 30 | |
| 31 | #ifndef __SIS_DS_H__ |
| 32 | #define __SIS_DS_H__ |
| 33 | |
| 34 | /* Set Data Structure */ |
| 35 | |
| 36 | #define SET_SIZE 5000 |
| 37 | |
| 38 | typedef unsigned int ITEM_TYPE; |
| 39 | |
| 40 | typedef struct { |
| 41 | ITEM_TYPE val; |
| 42 | int alloc_next, free_next; |
| 43 | } list_item_t; |
| 44 | |
| 45 | typedef struct { |
| 46 | int alloc; |
| 47 | int free; |
| 48 | int trace; |
| 49 | list_item_t list[SET_SIZE]; |
| 50 | } set_t; |
| 51 | |
| 52 | set_t *setInit(void); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 53 | int setAdd(set_t * set, ITEM_TYPE item); |
| 54 | int setDel(set_t * set, ITEM_TYPE item); |
| 55 | int setFirst(set_t * set, ITEM_TYPE * item); |
| 56 | int setNext(set_t * set, ITEM_TYPE * item); |
| 57 | int setDestroy(set_t * set); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 58 | |
| 59 | /* |
| 60 | * GLX Hardware Device Driver common code |
| 61 | * Copyright (C) 1999 Wittawat Yamwong |
| 62 | * |
| 63 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 64 | * copy of this software and associated documentation files (the "Software"), |
| 65 | * to deal in the Software without restriction, including without limitation |
| 66 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 67 | * and/or sell copies of the Software, and to permit persons to whom the |
| 68 | * Software is furnished to do so, subject to the following conditions: |
| 69 | * |
| 70 | * The above copyright notice and this permission notice shall be included |
| 71 | * in all copies or substantial portions of the Software. |
| 72 | * |
| 73 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS |
| 74 | * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 75 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 76 | * WITTAWAT YAMWONG, OR ANY OTHER CONTRIBUTORS BE LIABLE FOR ANY CLAIM, |
| 77 | * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR |
| 78 | * OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 79 | * OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 80 | * |
| 81 | */ |
| 82 | |
| 83 | struct mem_block_t { |
| 84 | struct mem_block_t *next; |
| 85 | struct mem_block_t *heap; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 86 | int ofs, size; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | int align; |
| 88 | unsigned int free:1; |
| 89 | unsigned int reserved:1; |
| 90 | }; |
| 91 | typedef struct mem_block_t TMemBlock; |
| 92 | typedef struct mem_block_t *PMemBlock; |
| 93 | |
| 94 | /* a heap is just the first block in a chain */ |
| 95 | typedef struct mem_block_t memHeap_t; |
| 96 | |
| 97 | static __inline__ int mmBlockSize(PMemBlock b) |
| 98 | { |
| 99 | return b->size; |
| 100 | } |
| 101 | |
| 102 | static __inline__ int mmOffset(PMemBlock b) |
| 103 | { |
| 104 | return b->ofs; |
| 105 | } |
| 106 | |
| 107 | static __inline__ void mmMarkReserved(PMemBlock b) |
| 108 | { |
| 109 | b->reserved = 1; |
| 110 | } |
| 111 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 112 | /* |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 113 | * input: total size in bytes |
| 114 | * return: a heap pointer if OK, NULL if error |
| 115 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 116 | memHeap_t *mmInit(int ofs, int size); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
| 118 | /* |
| 119 | * Allocate 'size' bytes with 2^align2 bytes alignment, |
| 120 | * restrict the search to free memory after 'startSearch' |
| 121 | * depth and back buffers should be in different 4mb banks |
| 122 | * to get better page hits if possible |
| 123 | * input: size = size of block |
| 124 | * align2 = 2^align2 bytes alignment |
| 125 | * startSearch = linear offset from start of heap to begin search |
| 126 | * return: pointer to the allocated block, 0 if error |
| 127 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 128 | PMemBlock mmAllocMem(memHeap_t * heap, int size, int align2, int startSearch); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
| 130 | /* |
| 131 | * Returns 1 if the block 'b' is part of the heap 'heap' |
| 132 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 133 | int mmBlockInHeap(PMemBlock heap, PMemBlock b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* |
| 136 | * Free block starts at offset |
| 137 | * input: pointer to a block |
| 138 | * return: 0 if OK, -1 if error |
| 139 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 140 | int mmFreeMem(PMemBlock b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
| 142 | /* For debuging purpose. */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 143 | void mmDumpMemInfo(memHeap_t * mmInit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 144 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 145 | #endif /* __SIS_DS_H__ */ |