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 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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:
14 *
15 * 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.
18 *
19 * 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 * VA LINUX SYSTEMS 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
25 * OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 *    Jeff Hartmann <jhartmann@valinux.com>
29 *    Keith Whitwell <keithw@valinux.com>
30 *
31 * Rewritten by:
32 *    Gareth Hughes <gareth@valinux.com>
33 */
34
35#ifndef __MGA_DRM_H__
36#define __MGA_DRM_H__
37
38/* WARNING: If you change any of these defines, make sure to change the
39 * defines in the Xserver file (mga_sarea.h)
40 */
41#ifndef __MGA_SAREA_DEFINES__
42#define __MGA_SAREA_DEFINES__
43
44/* WARP pipe flags
45 */
46#define MGA_F			0x1		/* fog */
47#define MGA_A			0x2		/* alpha */
48#define MGA_S			0x4		/* specular */
49#define MGA_T2			0x8		/* multitexture */
50
51#define MGA_WARP_TGZ		0
52#define MGA_WARP_TGZF		(MGA_F)
53#define MGA_WARP_TGZA		(MGA_A)
54#define MGA_WARP_TGZAF		(MGA_F|MGA_A)
55#define MGA_WARP_TGZS		(MGA_S)
56#define MGA_WARP_TGZSF		(MGA_S|MGA_F)
57#define MGA_WARP_TGZSA		(MGA_S|MGA_A)
58#define MGA_WARP_TGZSAF		(MGA_S|MGA_F|MGA_A)
59#define MGA_WARP_T2GZ		(MGA_T2)
60#define MGA_WARP_T2GZF		(MGA_T2|MGA_F)
61#define MGA_WARP_T2GZA		(MGA_T2|MGA_A)
62#define MGA_WARP_T2GZAF		(MGA_T2|MGA_A|MGA_F)
63#define MGA_WARP_T2GZS		(MGA_T2|MGA_S)
64#define MGA_WARP_T2GZSF		(MGA_T2|MGA_S|MGA_F)
65#define MGA_WARP_T2GZSA		(MGA_T2|MGA_S|MGA_A)
66#define MGA_WARP_T2GZSAF	(MGA_T2|MGA_S|MGA_F|MGA_A)
67
68#define MGA_MAX_G200_PIPES	8		/* no multitex */
69#define MGA_MAX_G400_PIPES	16
70#define MGA_MAX_WARP_PIPES	MGA_MAX_G400_PIPES
71#define MGA_WARP_UCODE_SIZE	32768		/* in bytes */
72
73#define MGA_CARD_TYPE_G200	1
74#define MGA_CARD_TYPE_G400	2
75
76
77#define MGA_FRONT		0x1
78#define MGA_BACK		0x2
79#define MGA_DEPTH		0x4
80
81/* What needs to be changed for the current vertex dma buffer?
82 */
83#define MGA_UPLOAD_CONTEXT	0x1
84#define MGA_UPLOAD_TEX0		0x2
85#define MGA_UPLOAD_TEX1		0x4
86#define MGA_UPLOAD_PIPE		0x8
87#define MGA_UPLOAD_TEX0IMAGE	0x10 /* handled client-side */
88#define MGA_UPLOAD_TEX1IMAGE	0x20 /* handled client-side */
89#define MGA_UPLOAD_2D		0x40
90#define MGA_WAIT_AGE		0x80 /* handled client-side */
91#define MGA_UPLOAD_CLIPRECTS	0x100 /* handled client-side */
92
93/* 32 buffers of 64k each, total 2 meg.
94 */
95#define MGA_BUFFER_SIZE		(1 << 16)
96#define MGA_NUM_BUFFERS		128
97
98/* Keep these small for testing.
99 */
100#define MGA_NR_SAREA_CLIPRECTS	8
101
102/* 2 heaps (1 for card, 1 for agp), each divided into upto 128
103 * regions, subject to a minimum region size of (1<<16) == 64k.
104 *
105 * Clients may subdivide regions internally, but when sharing between
106 * clients, the region size is the minimum granularity.
107 */
108
109#define MGA_CARD_HEAP			0
110#define MGA_AGP_HEAP			1
111#define MGA_NR_TEX_HEAPS		2
112#define MGA_NR_TEX_REGIONS		16
113#define MGA_LOG_MIN_TEX_REGION_SIZE	16
114
115#endif /* __MGA_SAREA_DEFINES__ */
116
117
118/* Setup registers for 3D context
119 */
120typedef struct {
121	unsigned int dstorg;
122	unsigned int maccess;
123	unsigned int plnwt;
124	unsigned int dwgctl;
125	unsigned int alphactrl;
126	unsigned int fogcolor;
127	unsigned int wflag;
128	unsigned int tdualstage0;
129	unsigned int tdualstage1;
130	unsigned int fcol;
131	unsigned int stencil;
132	unsigned int stencilctl;
133} drm_mga_context_regs_t;
134
135/* Setup registers for 2D, X server
136 */
137typedef struct {
138	unsigned int pitch;
139} drm_mga_server_regs_t;
140
141/* Setup registers for each texture unit
142 */
143typedef struct {
144	unsigned int texctl;
145	unsigned int texctl2;
146	unsigned int texfilter;
147	unsigned int texbordercol;
148	unsigned int texorg;
149	unsigned int texwidth;
150	unsigned int texheight;
151	unsigned int texorg1;
152	unsigned int texorg2;
153	unsigned int texorg3;
154	unsigned int texorg4;
155} drm_mga_texture_regs_t;
156
157/* General aging mechanism
158 */
159typedef struct {
160	unsigned int head;		/* Position of head pointer          */
161	unsigned int wrap;		/* Primary DMA wrap count            */
162} drm_mga_age_t;
163
164typedef struct _drm_mga_sarea {
165	/* The channel for communication of state information to the kernel
166	 * on firing a vertex dma buffer.
167	 */
168   	drm_mga_context_regs_t context_state;
169   	drm_mga_server_regs_t server_state;
170   	drm_mga_texture_regs_t tex_state[2];
171   	unsigned int warp_pipe;
172   	unsigned int dirty;
173   	unsigned int vertsize;
174
175	/* The current cliprects, or a subset thereof.
176	 */
177   	drm_clip_rect_t boxes[MGA_NR_SAREA_CLIPRECTS];
178   	unsigned int nbox;
179
180	/* Information about the most recently used 3d drawable.  The
181	 * client fills in the req_* fields, the server fills in the
182	 * exported_ fields and puts the cliprects into boxes, above.
183	 *
184	 * The client clears the exported_drawable field before
185	 * clobbering the boxes data.
186	 */
187        unsigned int req_drawable;	 /* the X drawable id */
188	unsigned int req_draw_buffer;	 /* MGA_FRONT or MGA_BACK */
189
190        unsigned int exported_drawable;
191	unsigned int exported_index;
192        unsigned int exported_stamp;
193        unsigned int exported_buffers;
194        unsigned int exported_nfront;
195        unsigned int exported_nback;
196	int exported_back_x, exported_front_x, exported_w;
197	int exported_back_y, exported_front_y, exported_h;
198   	drm_clip_rect_t exported_boxes[MGA_NR_SAREA_CLIPRECTS];
199
200	/* Counters for aging textures and for client-side throttling.
201	 */
202	unsigned int status[4];
203	unsigned int last_wrap;
204
205	drm_mga_age_t last_frame;
206        unsigned int last_enqueue;	/* last time a buffer was enqueued */
207	unsigned int last_dispatch;	/* age of the most recently dispatched buffer */
208	unsigned int last_quiescent;     /*  */
209
210	/* LRU lists for texture memory in agp space and on the card.
211	 */
212	drm_tex_region_t texList[MGA_NR_TEX_HEAPS][MGA_NR_TEX_REGIONS+1];
213	unsigned int texAge[MGA_NR_TEX_HEAPS];
214
215	/* Mechanism to validate card state.
216	 */
217   	int ctxOwner;
218} drm_mga_sarea_t;
219
220
221/* WARNING: If you change any of these defines, make sure to change the
222 * defines in the Xserver file (xf86drmMga.h)
223 */
224typedef struct _drm_mga_warp_index {
225   	int installed;
226   	unsigned long phys_addr;
227   	int size;
228} drm_mga_warp_index_t;
229
230typedef struct drm_mga_init {
231   	enum {
232	   	MGA_INIT_DMA    = 0x01,
233	       	MGA_CLEANUP_DMA = 0x02
234	} func;
235
236   	unsigned long sarea_priv_offset;
237
238	int chipset;
239   	int sgram;
240
241	unsigned int maccess;
242
243   	unsigned int fb_cpp;
244	unsigned int front_offset, front_pitch;
245   	unsigned int back_offset, back_pitch;
246
247   	unsigned int depth_cpp;
248   	unsigned int depth_offset, depth_pitch;
249
250   	unsigned int texture_offset[MGA_NR_TEX_HEAPS];
251   	unsigned int texture_size[MGA_NR_TEX_HEAPS];
252
253	unsigned long fb_offset;
254	unsigned long mmio_offset;
255	unsigned long status_offset;
256	unsigned long warp_offset;
257	unsigned long primary_offset;
258	unsigned long buffers_offset;
259} drm_mga_init_t;
260
261typedef struct drm_mga_fullscreen {
262	enum {
263		MGA_INIT_FULLSCREEN    = 0x01,
264		MGA_CLEANUP_FULLSCREEN = 0x02
265	} func;
266} drm_mga_fullscreen_t;
267
268typedef struct drm_mga_clear {
269	unsigned int flags;
270	unsigned int clear_color;
271	unsigned int clear_depth;
272	unsigned int color_mask;
273	unsigned int depth_mask;
274} drm_mga_clear_t;
275
276typedef struct drm_mga_vertex {
277   	int idx;			/* buffer to queue */
278	int used;			/* bytes in use */
279	int discard;			/* client finished with buffer?  */
280} drm_mga_vertex_t;
281
282typedef struct drm_mga_indices {
283   	int idx;			/* buffer to queue */
284	unsigned int start;
285	unsigned int end;
286	int discard;			/* client finished with buffer?  */
287} drm_mga_indices_t;
288
289typedef struct drm_mga_iload {
290	int idx;
291	unsigned int dstorg;
292	unsigned int length;
293} drm_mga_iload_t;
294
295typedef struct _drm_mga_blit {
296	unsigned int planemask;
297	unsigned int srcorg;
298	unsigned int dstorg;
299	int src_pitch, dst_pitch;
300	int delta_sx, delta_sy;
301	int delta_dx, delta_dy;
302	int height, ydir;		/* flip image vertically */
303	int source_pitch, dest_pitch;
304} drm_mga_blit_t;
305
306#endif
307