Merged mga branch with trunk
[platform/upstream/libdrm.git] / linux / mga_drm.h
1 /* mga_drm.h -- Public header for the Matrox g200/g400 driver -*- linux-c -*-
2  * Created: Tue Jan 25 01:50:01 1999 by jhartmann@precisioninsight.com
3  *
4  * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
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: Jeff Hartmann <jhartmann@precisioninsight.com>
27  *          Keith Whitwell <keithw@precisioninsight.com>
28  *
29  * $XFree86$
30  */
31
32 #ifndef _MGA_DRM_H_
33 #define _MGA_DRM_H_
34
35 /* WARNING: If you change any of these defines, make sure to change the
36  * defines in the Xserver file (xf86drmMga.h)
37  */
38 #ifndef _MGA_DEFINES_
39 #define _MGA_DEFINES_
40 #define MGA_F  0x1              /* fog */
41 #define MGA_A  0x2              /* alpha */
42 #define MGA_S  0x4              /* specular */
43 #define MGA_T2 0x8              /* multitexture */
44
45 #define MGA_WARP_TGZ            0
46 #define MGA_WARP_TGZF           (MGA_F)
47 #define MGA_WARP_TGZA           (MGA_A)
48 #define MGA_WARP_TGZAF          (MGA_F|MGA_A)
49 #define MGA_WARP_TGZS           (MGA_S)
50 #define MGA_WARP_TGZSF          (MGA_S|MGA_F)
51 #define MGA_WARP_TGZSA          (MGA_S|MGA_A)
52 #define MGA_WARP_TGZSAF         (MGA_S|MGA_F|MGA_A)
53 #define MGA_WARP_T2GZ           (MGA_T2)
54 #define MGA_WARP_T2GZF          (MGA_T2|MGA_F)
55 #define MGA_WARP_T2GZA          (MGA_T2|MGA_A)
56 #define MGA_WARP_T2GZAF         (MGA_T2|MGA_A|MGA_F)
57 #define MGA_WARP_T2GZS          (MGA_T2|MGA_S)
58 #define MGA_WARP_T2GZSF         (MGA_T2|MGA_S|MGA_F)
59 #define MGA_WARP_T2GZSA         (MGA_T2|MGA_S|MGA_A)
60 #define MGA_WARP_T2GZSAF        (MGA_T2|MGA_S|MGA_F|MGA_A)
61
62 #define MGA_MAX_G400_PIPES 16
63 #define MGA_MAX_G200_PIPES  8   /* no multitex */
64
65 #define MGA_MAX_WARP_PIPES MGA_MAX_G400_PIPES
66
67 #define MGA_CARD_TYPE_G200 1
68 #define MGA_CARD_TYPE_G400 2
69 #define MGA_FRONT   0x1
70 #define MGA_BACK    0x2
71 #define MGA_DEPTH   0x4
72
73 /* 3d state excluding texture units:
74  */
75 #define MGA_CTXREG_DSTORG   0   /* validated */
76 #define MGA_CTXREG_MACCESS  1   
77 #define MGA_CTXREG_PLNWT    2   
78 #define MGA_CTXREG_DWGCTL    3  
79 #define MGA_CTXREG_ALPHACTRL 4
80 #define MGA_CTXREG_FOGCOLOR  5
81 #define MGA_CTXREG_WFLAG     6
82 #define MGA_CTXREG_TDUAL0    7
83 #define MGA_CTXREG_TDUAL1    8
84 #define MGA_CTXREG_FCOL      9
85 #define MGA_CTX_SETUP_SIZE   10
86
87 /* 2d state
88  */
89 #define MGA_2DREG_PITCH         0
90 #define MGA_2D_SETUP_SIZE       1
91
92 /* Each texture unit has a state:
93  */
94 #define MGA_TEXREG_CTL        0
95 #define MGA_TEXREG_CTL2       1
96 #define MGA_TEXREG_FILTER     2
97 #define MGA_TEXREG_BORDERCOL  3
98 #define MGA_TEXREG_ORG        4 /* validated */
99 #define MGA_TEXREG_ORG1       5
100 #define MGA_TEXREG_ORG2       6
101 #define MGA_TEXREG_ORG3       7
102 #define MGA_TEXREG_ORG4       8
103 #define MGA_TEXREG_WIDTH      9
104 #define MGA_TEXREG_HEIGHT     10
105 #define MGA_TEX_SETUP_SIZE    11
106
107 /* What needs to be changed for the current vertex dma buffer?
108  */
109 #define MGA_UPLOAD_CTX        0x1
110 #define MGA_UPLOAD_TEX0       0x2
111 #define MGA_UPLOAD_TEX1       0x4
112 #define MGA_UPLOAD_PIPE       0x8
113 #define MGA_UPLOAD_TEX0IMAGE  0x10
114 #define MGA_UPLOAD_TEX1IMAGE  0x20
115 #define MGA_UPLOAD_2D         0x40
116 #define MGA_WAIT_AGE          0x80 /* handled client-side */
117 #define MGA_UPLOAD_CLIPRECTS  0x100 /* handled client-side */
118 #define MGA_DMA_FLUSH         0x200 /* set when someone gets the lock
119                                        quiescent */
120
121 /* 64 buffers of 16k each, total 1 meg.
122  */
123 #define MGA_DMA_BUF_ORDER     14
124 #define MGA_DMA_BUF_SZ        (1<<MGA_DMA_BUF_ORDER)
125 #define MGA_DMA_BUF_NR        63
126
127 /* Keep these small for testing.
128  */
129 #define MGA_NR_SAREA_CLIPRECTS 8
130
131 /* 2 heaps (1 for card, 1 for agp), each divided into upto 128
132  * regions, subject to a minimum region size of (1<<16) == 64k. 
133  *
134  * Clients may subdivide regions internally, but when sharing between
135  * clients, the region size is the minimum granularity. 
136  */
137
138 #define MGA_CARD_HEAP 0
139 #define MGA_AGP_HEAP  1
140 #define MGA_NR_TEX_HEAPS 2
141 #define MGA_NR_TEX_REGIONS 16
142 #define MGA_LOG_MIN_TEX_REGION_SIZE 16
143 #endif
144
145 typedef struct _drm_mga_warp_index {
146         int installed;
147         unsigned long phys_addr;
148         int size;
149 } drm_mga_warp_index_t;
150
151 typedef struct drm_mga_init {
152         enum { 
153                 MGA_INIT_DMA = 0x01,
154                 MGA_CLEANUP_DMA = 0x02
155         } func;
156         int reserved_map_agpstart;
157         int reserved_map_idx;
158         int buffer_map_idx;
159         int sarea_priv_offset;
160         int primary_size;
161         int warp_ucode_size;
162         int frontOffset;
163         int backOffset;
164         int depthOffset;
165         int textureOffset;
166         int textureSize;
167         int agpTextureOffset;
168         int agpTextureSize;
169         int cpp;
170         int stride;
171         int sgram;
172         int chipset;
173         drm_mga_warp_index_t WarpIndex[MGA_MAX_WARP_PIPES];
174         int mAccess;
175 } drm_mga_init_t;
176
177 /* Warning: if you change the sarea structure, you must change the Xserver
178  * structures as well */
179
180 typedef struct _drm_mga_tex_region {
181         unsigned char next, prev;       
182         unsigned char in_use;   
183         int age;                        
184 } drm_mga_tex_region_t;
185
186 typedef struct _drm_mga_sarea {
187         /* The channel for communication of state information to the kernel
188          * on firing a vertex dma buffer.
189          */
190         unsigned int ContextState[MGA_CTX_SETUP_SIZE];
191         unsigned int ServerState[MGA_2D_SETUP_SIZE];
192         unsigned int TexState[2][MGA_TEX_SETUP_SIZE];
193         unsigned int WarpPipe;
194         unsigned int dirty;
195
196         unsigned int nbox;
197         drm_clip_rect_t boxes[MGA_NR_SAREA_CLIPRECTS];
198
199
200         /* Information about the most recently used 3d drawable.  The
201          * client fills in the req_* fields, the server fills in the 
202          * exported_ fields and puts the cliprects into boxes, above.
203          *
204          * The client clears the exported_drawable field before
205          * clobbering the boxes data.
206          */
207         unsigned int req_drawable;       /* the X drawable id */
208         unsigned int req_draw_buffer;    /* MGA_FRONT or MGA_BACK */
209
210         unsigned int exported_drawable;  
211         unsigned int exported_index; 
212         unsigned int exported_stamp;    
213         unsigned int exported_buffers;   
214         unsigned int exported_nfront;
215         unsigned int exported_nback;
216         int exported_back_x, exported_front_x, exported_w;      
217         int exported_back_y, exported_front_y, exported_h;
218         drm_clip_rect_t exported_boxes[MGA_NR_SAREA_CLIPRECTS];
219    
220         /* Counters for aging textures and for client-side throttling.
221          */
222         int last_enqueue;       /* last time a buffer was enqueued */
223         int last_dispatch;      /* age of the most recently dispatched buffer */
224         int last_quiescent;     /*  */
225
226
227         /* LRU lists for texture memory in agp space and on the card
228          */
229         drm_mga_tex_region_t texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS+1];
230         unsigned int texAge[MGA_NR_TEX_HEAPS];
231         
232         /* Mechanism to validate card state.
233          */
234         int ctxOwner;
235 } drm_mga_sarea_t;      
236
237 /* Device specific ioctls:
238  */
239 typedef struct _drm_mga_clear {
240         int clear_color;
241         int clear_depth;
242         int flags;
243 } drm_mga_clear_t;
244
245 typedef struct _drm_mga_swap {
246         int dummy;
247 } drm_mga_swap_t;
248
249 typedef struct _drm_mga_iload {
250         int idx;
251         int length;
252         unsigned int destOrg;
253 } drm_mga_iload_t;
254
255 typedef struct _drm_mga_vertex {
256         int idx;                /* buffer to queue */
257         int used;               /* bytes in use */
258         int discard;            /* client finished with buffer?  */
259 } drm_mga_vertex_t;
260
261 #endif