- pre2
[davej-history.git] / drivers / char / drm / mga_drv.h
blobf49bd0f6c89600b82b3181cf4aab28ab891e90fa
1 /* mga_drv.h -- Private header for the Matrox g200/g400 driver -*- linux-c -*-
2 * Created: Mon Dec 13 01:50:01 1999 by jhartmann@precisioninsight.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All rights reserved.
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:
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.
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 * 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.
27 * Authors: Rickard E. (Rik) Faith <faith@valinux.com>
28 * Jeff Hartmann <jhartmann@valinux.com>
32 #ifndef _MGA_DRV_H_
33 #define _MGA_DRV_H_
35 #define MGA_BUF_IN_USE 0
36 #define MGA_BUF_SWAP_PENDING 1
37 #define MGA_BUF_FORCE_FIRE 2
38 #define MGA_BUF_NEEDS_OVERFLOW 3
40 typedef struct {
41 u32 buffer_status;
42 int num_dwords;
43 int max_dwords;
44 u32 *current_dma_ptr;
45 u32 *head;
46 u32 phys_head;
47 unsigned int prim_age;
48 int sec_used;
49 int idx;
50 } drm_mga_prim_buf_t;
52 typedef struct _drm_mga_freelist {
53 unsigned int age;
54 drm_buf_t *buf;
55 struct _drm_mga_freelist *next;
56 struct _drm_mga_freelist *prev;
57 } drm_mga_freelist_t;
59 #define MGA_IN_DISPATCH 0
60 #define MGA_IN_FLUSH 1
61 #define MGA_IN_WAIT 2
62 #define MGA_IN_GETBUF 3
64 typedef struct _drm_mga_private {
65 u32 dispatch_status;
66 unsigned int next_prim_age;
67 __volatile__ unsigned int last_prim_age;
68 int reserved_map_idx;
69 int buffer_map_idx;
70 drm_mga_sarea_t *sarea_priv;
71 int primary_size;
72 int warp_ucode_size;
73 int chipset;
74 unsigned int frontOffset;
75 unsigned int backOffset;
76 unsigned int depthOffset;
77 unsigned int textureOffset;
78 unsigned int textureSize;
79 int cpp;
80 unsigned int stride;
81 int sgram;
82 int use_agp;
83 drm_mga_warp_index_t WarpIndex[MGA_MAX_G400_PIPES];
84 unsigned int WarpPipe;
85 atomic_t pending_bufs;
86 void *status_page;
87 unsigned long real_status_page;
88 u8 *ioremap;
89 drm_mga_prim_buf_t **prim_bufs;
90 drm_mga_prim_buf_t *next_prim;
91 drm_mga_prim_buf_t *last_prim;
92 drm_mga_prim_buf_t *current_prim;
93 int current_prim_idx;
94 drm_mga_freelist_t *head;
95 drm_mga_freelist_t *tail;
96 wait_queue_head_t flush_queue; /* Processes waiting until flush */
97 wait_queue_head_t wait_queue; /* Processes waiting until interrupt */
98 wait_queue_head_t buf_queue; /* Processes waiting for a free buf */
99 /* Some validated register values:
101 u32 mAccess;
102 } drm_mga_private_t;
104 /* mga_drv.c */
105 extern int mga_version(struct inode *inode, struct file *filp,
106 unsigned int cmd, unsigned long arg);
107 extern int mga_open(struct inode *inode, struct file *filp);
108 extern int mga_release(struct inode *inode, struct file *filp);
109 extern int mga_ioctl(struct inode *inode, struct file *filp,
110 unsigned int cmd, unsigned long arg);
111 extern int mga_unlock(struct inode *inode, struct file *filp,
112 unsigned int cmd, unsigned long arg);
114 /* mga_dma.c */
115 extern int mga_dma_schedule(drm_device_t *dev, int locked);
116 extern int mga_dma(struct inode *inode, struct file *filp,
117 unsigned int cmd, unsigned long arg);
118 extern int mga_irq_install(drm_device_t *dev, int irq);
119 extern int mga_irq_uninstall(drm_device_t *dev);
120 extern int mga_control(struct inode *inode, struct file *filp,
121 unsigned int cmd, unsigned long arg);
122 extern int mga_lock(struct inode *inode, struct file *filp,
123 unsigned int cmd, unsigned long arg);
125 /* mga_dma_init does init and release */
126 extern int mga_dma_init(struct inode *inode, struct file *filp,
127 unsigned int cmd, unsigned long arg);
128 extern int mga_dma_cleanup(drm_device_t *dev);
129 extern int mga_flush_ioctl(struct inode *inode, struct file *filp,
130 unsigned int cmd, unsigned long arg);
131 extern void mga_flush_write_combine(void);
132 extern unsigned int mga_create_sync_tag(drm_device_t *dev);
133 extern drm_buf_t *mga_freelist_get(drm_device_t *dev);
134 extern int mga_freelist_put(drm_device_t *dev, drm_buf_t *buf);
135 extern int mga_advance_primary(drm_device_t *dev);
136 extern void mga_reclaim_buffers(drm_device_t *dev, pid_t pid);
139 /* mga_bufs.c */
140 extern int mga_addbufs(struct inode *inode, struct file *filp,
141 unsigned int cmd, unsigned long arg);
142 extern int mga_infobufs(struct inode *inode, struct file *filp,
143 unsigned int cmd, unsigned long arg);
144 extern int mga_markbufs(struct inode *inode, struct file *filp,
145 unsigned int cmd, unsigned long arg);
146 extern int mga_freebufs(struct inode *inode, struct file *filp,
147 unsigned int cmd, unsigned long arg);
148 extern int mga_mapbufs(struct inode *inode, struct file *filp,
149 unsigned int cmd, unsigned long arg);
150 extern int mga_addmap(struct inode *inode, struct file *filp,
151 unsigned int cmd, unsigned long arg);
152 /* mga_state.c */
153 extern int mga_clear_bufs(struct inode *inode, struct file *filp,
154 unsigned int cmd, unsigned long arg);
155 extern int mga_swap_bufs(struct inode *inode, struct file *filp,
156 unsigned int cmd, unsigned long arg);
157 extern int mga_iload(struct inode *inode, struct file *filp,
158 unsigned int cmd, unsigned long arg);
159 extern int mga_vertex(struct inode *inode, struct file *filp,
160 unsigned int cmd, unsigned long arg);
161 extern int mga_indices(struct inode *inode, struct file *filp,
162 unsigned int cmd, unsigned long arg);
163 /* mga_context.c */
164 extern int mga_resctx(struct inode *inode, struct file *filp,
165 unsigned int cmd, unsigned long arg);
166 extern int mga_addctx(struct inode *inode, struct file *filp,
167 unsigned int cmd, unsigned long arg);
168 extern int mga_modctx(struct inode *inode, struct file *filp,
169 unsigned int cmd, unsigned long arg);
170 extern int mga_getctx(struct inode *inode, struct file *filp,
171 unsigned int cmd, unsigned long arg);
172 extern int mga_switchctx(struct inode *inode, struct file *filp,
173 unsigned int cmd, unsigned long arg);
174 extern int mga_newctx(struct inode *inode, struct file *filp,
175 unsigned int cmd, unsigned long arg);
176 extern int mga_rmctx(struct inode *inode, struct file *filp,
177 unsigned int cmd, unsigned long arg);
179 extern int mga_context_switch(drm_device_t *dev, int old, int new);
180 extern int mga_context_switch_complete(drm_device_t *dev, int new);
183 typedef enum {
184 TT_GENERAL,
185 TT_BLIT,
186 TT_VECTOR,
187 TT_VERTEX
188 } transferType_t;
190 typedef struct {
191 drm_mga_freelist_t *my_freelist;
192 int discard;
193 int dispatched;
194 } drm_mga_buf_priv_t;
196 #define DWGREG0 0x1c00
197 #define DWGREG0_END 0x1dff
198 #define DWGREG1 0x2c00
199 #define DWGREG1_END 0x2dff
201 #define ISREG0(r) (r >= DWGREG0 && r <= DWGREG0_END)
202 #define ADRINDEX0(r) (u8)((r - DWGREG0) >> 2)
203 #define ADRINDEX1(r) (u8)(((r - DWGREG1) >> 2) | 0x80)
204 #define ADRINDEX(r) (ISREG0(r) ? ADRINDEX0(r) : ADRINDEX1(r))
206 #define MGA_VERBOSE 0
207 #define MGA_NUM_PRIM_BUFS 8
209 #define PRIMLOCALS u8 tempIndex[4]; u32 *dma_ptr; u32 phys_head; \
210 int outcount, num_dwords
212 #define PRIM_OVERFLOW(dev, dev_priv, length) do { \
213 drm_mga_prim_buf_t *tmp_buf = \
214 dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
215 if( test_bit(MGA_BUF_NEEDS_OVERFLOW, \
216 &tmp_buf->buffer_status)) { \
217 mga_advance_primary(dev); \
218 mga_dma_schedule(dev, 1); \
219 tmp_buf = dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
220 } else if( tmp_buf->max_dwords - tmp_buf->num_dwords < length || \
221 tmp_buf->sec_used > MGA_DMA_BUF_NR/2) { \
222 set_bit(MGA_BUF_FORCE_FIRE, &tmp_buf->buffer_status); \
223 mga_advance_primary(dev); \
224 mga_dma_schedule(dev, 1); \
225 tmp_buf = dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
227 if(MGA_VERBOSE) \
228 DRM_DEBUG("PRIMGETPTR in %s\n", __FUNCTION__); \
229 dma_ptr = tmp_buf->current_dma_ptr; \
230 num_dwords = tmp_buf->num_dwords; \
231 phys_head = tmp_buf->phys_head; \
232 outcount = 0; \
233 } while(0)
235 #define PRIMGETPTR(dev_priv) do { \
236 drm_mga_prim_buf_t *tmp_buf = \
237 dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
238 if(MGA_VERBOSE) \
239 DRM_DEBUG("PRIMGETPTR in %s\n", __FUNCTION__); \
240 dma_ptr = tmp_buf->current_dma_ptr; \
241 num_dwords = tmp_buf->num_dwords; \
242 phys_head = tmp_buf->phys_head; \
243 outcount = 0; \
244 } while(0)
246 #define PRIMPTR(prim_buf) do { \
247 if(MGA_VERBOSE) \
248 DRM_DEBUG("PRIMPTR in %s\n", __FUNCTION__); \
249 dma_ptr = prim_buf->current_dma_ptr; \
250 num_dwords = prim_buf->num_dwords; \
251 phys_head = prim_buf->phys_head; \
252 outcount = 0; \
253 } while(0)
255 #define PRIMFINISH(prim_buf) do { \
256 if (MGA_VERBOSE) { \
257 DRM_DEBUG( "PRIMFINISH in %s\n", __FUNCTION__); \
258 if (outcount & 3) \
259 DRM_DEBUG(" --- truncation\n"); \
261 prim_buf->num_dwords = num_dwords; \
262 prim_buf->current_dma_ptr = dma_ptr; \
263 } while(0)
265 #define PRIMADVANCE(dev_priv) do { \
266 drm_mga_prim_buf_t *tmp_buf = \
267 dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
268 if (MGA_VERBOSE) { \
269 DRM_DEBUG("PRIMADVANCE in %s\n", __FUNCTION__); \
270 if (outcount & 3) \
271 DRM_DEBUG(" --- truncation\n"); \
273 tmp_buf->num_dwords = num_dwords; \
274 tmp_buf->current_dma_ptr = dma_ptr; \
275 } while (0)
277 #define PRIMUPDATE(dev_priv) do { \
278 drm_mga_prim_buf_t *tmp_buf = \
279 dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
280 tmp_buf->sec_used++; \
281 } while (0)
283 #define AGEBUF(dev_priv, buf_priv) do { \
284 drm_mga_prim_buf_t *tmp_buf = \
285 dev_priv->prim_bufs[dev_priv->current_prim_idx]; \
286 buf_priv->my_freelist->age = tmp_buf->prim_age; \
287 } while (0)
290 #define PRIMOUTREG(reg, val) do { \
291 tempIndex[outcount]=ADRINDEX(reg); \
292 dma_ptr[1+outcount] = val; \
293 if (MGA_VERBOSE) \
294 DRM_DEBUG(" PRIMOUT %d: 0x%x -- 0x%x\n", \
295 num_dwords + 1 + outcount, ADRINDEX(reg), val); \
296 if( ++outcount == 4) { \
297 outcount = 0; \
298 dma_ptr[0] = *(u32 *)tempIndex; \
299 dma_ptr+=5; \
300 num_dwords += 5; \
302 }while (0)
304 /* A reduced set of the mga registers.
307 #define MGAREG_MGA_EXEC 0x0100
308 #define MGAREG_ALPHACTRL 0x2c7c
309 #define MGAREG_AR0 0x1c60
310 #define MGAREG_AR1 0x1c64
311 #define MGAREG_AR2 0x1c68
312 #define MGAREG_AR3 0x1c6c
313 #define MGAREG_AR4 0x1c70
314 #define MGAREG_AR5 0x1c74
315 #define MGAREG_AR6 0x1c78
316 #define MGAREG_CXBNDRY 0x1c80
317 #define MGAREG_CXLEFT 0x1ca0
318 #define MGAREG_CXRIGHT 0x1ca4
319 #define MGAREG_DMAPAD 0x1c54
320 #define MGAREG_DSTORG 0x2cb8
321 #define MGAREG_DWGCTL 0x1c00
322 #define MGAREG_DWGSYNC 0x2c4c
323 #define MGAREG_FCOL 0x1c24
324 #define MGAREG_FIFOSTATUS 0x1e10
325 #define MGAREG_FOGCOL 0x1cf4
326 #define MGAREG_FXBNDRY 0x1c84
327 #define MGAREG_FXLEFT 0x1ca8
328 #define MGAREG_FXRIGHT 0x1cac
329 #define MGAREG_ICLEAR 0x1e18
330 #define MGAREG_IEN 0x1e1c
331 #define MGAREG_LEN 0x1c5c
332 #define MGAREG_MACCESS 0x1c04
333 #define MGAREG_PITCH 0x1c8c
334 #define MGAREG_PLNWT 0x1c1c
335 #define MGAREG_PRIMADDRESS 0x1e58
336 #define MGAREG_PRIMEND 0x1e5c
337 #define MGAREG_PRIMPTR 0x1e50
338 #define MGAREG_SECADDRESS 0x2c40
339 #define MGAREG_SECEND 0x2c44
340 #define MGAREG_SETUPADDRESS 0x2cd0
341 #define MGAREG_SETUPEND 0x2cd4
342 #define MGAREG_SOFTRAP 0x2c48
343 #define MGAREG_SRCORG 0x2cb4
344 #define MGAREG_STATUS 0x1e14
345 #define MGAREG_STENCIL 0x2cc8
346 #define MGAREG_STENCILCTL 0x2ccc
347 #define MGAREG_TDUALSTAGE0 0x2cf8
348 #define MGAREG_TDUALSTAGE1 0x2cfc
349 #define MGAREG_TEXBORDERCOL 0x2c5c
350 #define MGAREG_TEXCTL 0x2c30
351 #define MGAREG_TEXCTL2 0x2c3c
352 #define MGAREG_TEXFILTER 0x2c58
353 #define MGAREG_TEXHEIGHT 0x2c2c
354 #define MGAREG_TEXORG 0x2c24
355 #define MGAREG_TEXORG1 0x2ca4
356 #define MGAREG_TEXORG2 0x2ca8
357 #define MGAREG_TEXORG3 0x2cac
358 #define MGAREG_TEXORG4 0x2cb0
359 #define MGAREG_TEXTRANS 0x2c34
360 #define MGAREG_TEXTRANSHIGH 0x2c38
361 #define MGAREG_TEXWIDTH 0x2c28
362 #define MGAREG_WACCEPTSEQ 0x1dd4
363 #define MGAREG_WCODEADDR 0x1e6c
364 #define MGAREG_WFLAG 0x1dc4
365 #define MGAREG_WFLAG1 0x1de0
366 #define MGAREG_WFLAGNB 0x1e64
367 #define MGAREG_WFLAGNB1 0x1e08
368 #define MGAREG_WGETMSB 0x1dc8
369 #define MGAREG_WIADDR 0x1dc0
370 #define MGAREG_WIADDR2 0x1dd8
371 #define MGAREG_WMISC 0x1e70
372 #define MGAREG_WVRTXSZ 0x1dcc
373 #define MGAREG_YBOT 0x1c9c
374 #define MGAREG_YDST 0x1c90
375 #define MGAREG_YDSTLEN 0x1c88
376 #define MGAREG_YDSTORG 0x1c94
377 #define MGAREG_YTOP 0x1c98
378 #define MGAREG_ZORG 0x1c0c
380 #define PDEA_pagpxfer_enable 0x2
382 #define WIA_wmode_suspend 0x0
383 #define WIA_wmode_start 0x3
384 #define WIA_wagp_agp 0x4
386 #define DC_opcod_line_open 0x0
387 #define DC_opcod_autoline_open 0x1
388 #define DC_opcod_line_close 0x2
389 #define DC_opcod_autoline_close 0x3
390 #define DC_opcod_trap 0x4
391 #define DC_opcod_texture_trap 0x6
392 #define DC_opcod_bitblt 0x8
393 #define DC_opcod_iload 0x9
394 #define DC_atype_rpl 0x0
395 #define DC_atype_rstr 0x10
396 #define DC_atype_zi 0x30
397 #define DC_atype_blk 0x40
398 #define DC_atype_i 0x70
399 #define DC_linear_xy 0x0
400 #define DC_linear_linear 0x80
401 #define DC_zmode_nozcmp 0x0
402 #define DC_zmode_ze 0x200
403 #define DC_zmode_zne 0x300
404 #define DC_zmode_zlt 0x400
405 #define DC_zmode_zlte 0x500
406 #define DC_zmode_zgt 0x600
407 #define DC_zmode_zgte 0x700
408 #define DC_solid_disable 0x0
409 #define DC_solid_enable 0x800
410 #define DC_arzero_disable 0x0
411 #define DC_arzero_enable 0x1000
412 #define DC_sgnzero_disable 0x0
413 #define DC_sgnzero_enable 0x2000
414 #define DC_shftzero_disable 0x0
415 #define DC_shftzero_enable 0x4000
416 #define DC_bop_SHIFT 16
417 #define DC_trans_SHIFT 20
418 #define DC_bltmod_bmonolef 0x0
419 #define DC_bltmod_bmonowf 0x8000000
420 #define DC_bltmod_bplan 0x2000000
421 #define DC_bltmod_bfcol 0x4000000
422 #define DC_bltmod_bu32bgr 0x6000000
423 #define DC_bltmod_bu32rgb 0xe000000
424 #define DC_bltmod_bu24bgr 0x16000000
425 #define DC_bltmod_bu24rgb 0x1e000000
426 #define DC_pattern_disable 0x0
427 #define DC_pattern_enable 0x20000000
428 #define DC_transc_disable 0x0
429 #define DC_transc_enable 0x40000000
430 #define DC_clipdis_disable 0x0
431 #define DC_clipdis_enable 0x80000000
433 #define SETADD_mode_vertlist 0x0
436 #define MGA_CLEAR_CMD (DC_opcod_trap | DC_arzero_enable | \
437 DC_sgnzero_enable | DC_shftzero_enable | \
438 (0xC << DC_bop_SHIFT) | DC_clipdis_enable | \
439 DC_solid_enable | DC_transc_enable)
442 #define MGA_COPY_CMD (DC_opcod_bitblt | DC_atype_rpl | DC_linear_xy | \
443 DC_solid_disable | DC_arzero_disable | \
444 DC_sgnzero_enable | DC_shftzero_enable | \
445 (0xC << DC_bop_SHIFT) | DC_bltmod_bfcol | \
446 DC_pattern_disable | DC_transc_disable | \
447 DC_clipdis_enable) \
449 #define MGA_FLUSH_CMD (DC_opcod_texture_trap | (0xF << DC_trans_SHIFT) |\
450 DC_arzero_enable | DC_sgnzero_enable | \
451 DC_atype_i)
453 #endif