1 /* mga_state.c -- State support for MGA G200/G400 -*- linux-c -*-
2 * Created: Thu Jan 27 02:53:43 2000 by jhartmann@precisioninsight.com
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
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
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.
28 * Jeff Hartmann <jhartmann@valinux.com>
29 * Keith Whitwell <keith@tungstengraphics.com>
32 * Gareth Hughes <gareth@valinux.com>
40 /* ================================================================
41 * DMA hardware state programming functions
44 static void mga_emit_clip_rect( drm_mga_private_t
*dev_priv
,
45 drm_clip_rect_t
*box
)
47 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
48 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
49 unsigned int pitch
= dev_priv
->front_pitch
;
54 /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
56 if ( dev_priv
->chipset
== MGA_CARD_TYPE_G400
) {
57 DMA_BLOCK( MGA_DWGCTL
, ctx
->dwgctl
,
58 MGA_LEN
+ MGA_EXEC
, 0x80000000,
59 MGA_DWGCTL
, ctx
->dwgctl
,
60 MGA_LEN
+ MGA_EXEC
, 0x80000000 );
62 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
63 MGA_CXBNDRY
, (box
->x2
<< 16) | box
->x1
,
64 MGA_YTOP
, box
->y1
* pitch
,
65 MGA_YBOT
, box
->y2
* pitch
);
70 static __inline__
void mga_g200_emit_context( drm_mga_private_t
*dev_priv
)
72 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
73 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
78 DMA_BLOCK( MGA_DSTORG
, ctx
->dstorg
,
79 MGA_MACCESS
, ctx
->maccess
,
80 MGA_PLNWT
, ctx
->plnwt
,
81 MGA_DWGCTL
, ctx
->dwgctl
);
83 DMA_BLOCK( MGA_ALPHACTRL
, ctx
->alphactrl
,
84 MGA_FOGCOL
, ctx
->fogcolor
,
85 MGA_WFLAG
, ctx
->wflag
,
86 MGA_ZORG
, dev_priv
->depth_offset
);
88 DMA_BLOCK( MGA_FCOL
, ctx
->fcol
,
89 MGA_DMAPAD
, 0x00000000,
90 MGA_DMAPAD
, 0x00000000,
91 MGA_DMAPAD
, 0x00000000 );
96 static __inline__
void mga_g400_emit_context( drm_mga_private_t
*dev_priv
)
98 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
99 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
104 DMA_BLOCK( MGA_DSTORG
, ctx
->dstorg
,
105 MGA_MACCESS
, ctx
->maccess
,
106 MGA_PLNWT
, ctx
->plnwt
,
107 MGA_DWGCTL
, ctx
->dwgctl
);
109 DMA_BLOCK( MGA_ALPHACTRL
, ctx
->alphactrl
,
110 MGA_FOGCOL
, ctx
->fogcolor
,
111 MGA_WFLAG
, ctx
->wflag
,
112 MGA_ZORG
, dev_priv
->depth_offset
);
114 DMA_BLOCK( MGA_WFLAG1
, ctx
->wflag
,
115 MGA_TDUALSTAGE0
, ctx
->tdualstage0
,
116 MGA_TDUALSTAGE1
, ctx
->tdualstage1
,
117 MGA_FCOL
, ctx
->fcol
);
119 DMA_BLOCK( MGA_STENCIL
, ctx
->stencil
,
120 MGA_STENCILCTL
, ctx
->stencilctl
,
121 MGA_DMAPAD
, 0x00000000,
122 MGA_DMAPAD
, 0x00000000 );
127 static __inline__
void mga_g200_emit_tex0( drm_mga_private_t
*dev_priv
)
129 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
130 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[0];
135 DMA_BLOCK( MGA_TEXCTL2
, tex
->texctl2
,
136 MGA_TEXCTL
, tex
->texctl
,
137 MGA_TEXFILTER
, tex
->texfilter
,
138 MGA_TEXBORDERCOL
, tex
->texbordercol
);
140 DMA_BLOCK( MGA_TEXORG
, tex
->texorg
,
141 MGA_TEXORG1
, tex
->texorg1
,
142 MGA_TEXORG2
, tex
->texorg2
,
143 MGA_TEXORG3
, tex
->texorg3
);
145 DMA_BLOCK( MGA_TEXORG4
, tex
->texorg4
,
146 MGA_TEXWIDTH
, tex
->texwidth
,
147 MGA_TEXHEIGHT
, tex
->texheight
,
148 MGA_WR24
, tex
->texwidth
);
150 DMA_BLOCK( MGA_WR34
, tex
->texheight
,
151 MGA_TEXTRANS
, 0x0000ffff,
152 MGA_TEXTRANSHIGH
, 0x0000ffff,
153 MGA_DMAPAD
, 0x00000000 );
158 static __inline__
void mga_g400_emit_tex0( drm_mga_private_t
*dev_priv
)
160 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
161 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[0];
164 /* printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
165 /* tex->texctl, tex->texctl2); */
169 DMA_BLOCK( MGA_TEXCTL2
, tex
->texctl2
| MGA_G400_TC2_MAGIC
,
170 MGA_TEXCTL
, tex
->texctl
,
171 MGA_TEXFILTER
, tex
->texfilter
,
172 MGA_TEXBORDERCOL
, tex
->texbordercol
);
174 DMA_BLOCK( MGA_TEXORG
, tex
->texorg
,
175 MGA_TEXORG1
, tex
->texorg1
,
176 MGA_TEXORG2
, tex
->texorg2
,
177 MGA_TEXORG3
, tex
->texorg3
);
179 DMA_BLOCK( MGA_TEXORG4
, tex
->texorg4
,
180 MGA_TEXWIDTH
, tex
->texwidth
,
181 MGA_TEXHEIGHT
, tex
->texheight
,
182 MGA_WR49
, 0x00000000 );
184 DMA_BLOCK( MGA_WR57
, 0x00000000,
185 MGA_WR53
, 0x00000000,
186 MGA_WR61
, 0x00000000,
187 MGA_WR52
, MGA_G400_WR_MAGIC
);
189 DMA_BLOCK( MGA_WR60
, MGA_G400_WR_MAGIC
,
190 MGA_WR54
, tex
->texwidth
| MGA_G400_WR_MAGIC
,
191 MGA_WR62
, tex
->texheight
| MGA_G400_WR_MAGIC
,
192 MGA_DMAPAD
, 0x00000000 );
194 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
195 MGA_DMAPAD
, 0x00000000,
196 MGA_TEXTRANS
, 0x0000ffff,
197 MGA_TEXTRANSHIGH
, 0x0000ffff );
202 static __inline__
void mga_g400_emit_tex1( drm_mga_private_t
*dev_priv
)
204 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
205 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[1];
208 /* printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg, */
209 /* tex->texctl, tex->texctl2); */
213 DMA_BLOCK( MGA_TEXCTL2
, (tex
->texctl2
|
216 MGA_TEXCTL
, tex
->texctl
,
217 MGA_TEXFILTER
, tex
->texfilter
,
218 MGA_TEXBORDERCOL
, tex
->texbordercol
);
220 DMA_BLOCK( MGA_TEXORG
, tex
->texorg
,
221 MGA_TEXORG1
, tex
->texorg1
,
222 MGA_TEXORG2
, tex
->texorg2
,
223 MGA_TEXORG3
, tex
->texorg3
);
225 DMA_BLOCK( MGA_TEXORG4
, tex
->texorg4
,
226 MGA_TEXWIDTH
, tex
->texwidth
,
227 MGA_TEXHEIGHT
, tex
->texheight
,
228 MGA_WR49
, 0x00000000 );
230 DMA_BLOCK( MGA_WR57
, 0x00000000,
231 MGA_WR53
, 0x00000000,
232 MGA_WR61
, 0x00000000,
233 MGA_WR52
, tex
->texwidth
| MGA_G400_WR_MAGIC
);
235 DMA_BLOCK( MGA_WR60
, tex
->texheight
| MGA_G400_WR_MAGIC
,
236 MGA_TEXTRANS
, 0x0000ffff,
237 MGA_TEXTRANSHIGH
, 0x0000ffff,
238 MGA_TEXCTL2
, tex
->texctl2
| MGA_G400_TC2_MAGIC
);
243 static __inline__
void mga_g200_emit_pipe( drm_mga_private_t
*dev_priv
)
245 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
246 unsigned int pipe
= sarea_priv
->warp_pipe
;
251 DMA_BLOCK( MGA_WIADDR
, MGA_WMODE_SUSPEND
,
252 MGA_WVRTXSZ
, 0x00000007,
253 MGA_WFLAG
, 0x00000000,
254 MGA_WR24
, 0x00000000 );
256 DMA_BLOCK( MGA_WR25
, 0x00000100,
257 MGA_WR34
, 0x00000000,
258 MGA_WR42
, 0x0000ffff,
259 MGA_WR60
, 0x0000ffff );
261 /* Padding required to to hardware bug.
263 DMA_BLOCK( MGA_DMAPAD
, 0xffffffff,
264 MGA_DMAPAD
, 0xffffffff,
265 MGA_DMAPAD
, 0xffffffff,
266 MGA_WIADDR
, (dev_priv
->warp_pipe_phys
[pipe
] |
273 static __inline__
void mga_g400_emit_pipe( drm_mga_private_t
*dev_priv
)
275 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
276 unsigned int pipe
= sarea_priv
->warp_pipe
;
279 /* printk("mga_g400_emit_pipe %x\n", pipe); */
283 DMA_BLOCK( MGA_WIADDR2
, MGA_WMODE_SUSPEND
,
284 MGA_DMAPAD
, 0x00000000,
285 MGA_DMAPAD
, 0x00000000,
286 MGA_DMAPAD
, 0x00000000 );
288 if ( pipe
& MGA_T2
) {
289 DMA_BLOCK( MGA_WVRTXSZ
, 0x00001e09,
290 MGA_DMAPAD
, 0x00000000,
291 MGA_DMAPAD
, 0x00000000,
292 MGA_DMAPAD
, 0x00000000 );
294 DMA_BLOCK( MGA_WACCEPTSEQ
, 0x00000000,
295 MGA_WACCEPTSEQ
, 0x00000000,
296 MGA_WACCEPTSEQ
, 0x00000000,
297 MGA_WACCEPTSEQ
, 0x1e000000 );
299 if ( dev_priv
->warp_pipe
& MGA_T2
) {
300 /* Flush the WARP pipe */
301 DMA_BLOCK( MGA_YDST
, 0x00000000,
302 MGA_FXLEFT
, 0x00000000,
303 MGA_FXRIGHT
, 0x00000001,
304 MGA_DWGCTL
, MGA_DWGCTL_FLUSH
);
306 DMA_BLOCK( MGA_LEN
+ MGA_EXEC
, 0x00000001,
307 MGA_DWGSYNC
, 0x00007000,
308 MGA_TEXCTL2
, MGA_G400_TC2_MAGIC
,
309 MGA_LEN
+ MGA_EXEC
, 0x00000000 );
311 DMA_BLOCK( MGA_TEXCTL2
, (MGA_DUALTEX
|
313 MGA_LEN
+ MGA_EXEC
, 0x00000000,
314 MGA_TEXCTL2
, MGA_G400_TC2_MAGIC
,
315 MGA_DMAPAD
, 0x00000000 );
318 DMA_BLOCK( MGA_WVRTXSZ
, 0x00001807,
319 MGA_DMAPAD
, 0x00000000,
320 MGA_DMAPAD
, 0x00000000,
321 MGA_DMAPAD
, 0x00000000 );
323 DMA_BLOCK( MGA_WACCEPTSEQ
, 0x00000000,
324 MGA_WACCEPTSEQ
, 0x00000000,
325 MGA_WACCEPTSEQ
, 0x00000000,
326 MGA_WACCEPTSEQ
, 0x18000000 );
329 DMA_BLOCK( MGA_WFLAG
, 0x00000000,
330 MGA_WFLAG1
, 0x00000000,
331 MGA_WR56
, MGA_G400_WR56_MAGIC
,
332 MGA_DMAPAD
, 0x00000000 );
334 DMA_BLOCK( MGA_WR49
, 0x00000000, /* tex0 */
335 MGA_WR57
, 0x00000000, /* tex0 */
336 MGA_WR53
, 0x00000000, /* tex1 */
337 MGA_WR61
, 0x00000000 ); /* tex1 */
339 DMA_BLOCK( MGA_WR54
, MGA_G400_WR_MAGIC
, /* tex0 width */
340 MGA_WR62
, MGA_G400_WR_MAGIC
, /* tex0 height */
341 MGA_WR52
, MGA_G400_WR_MAGIC
, /* tex1 width */
342 MGA_WR60
, MGA_G400_WR_MAGIC
); /* tex1 height */
344 /* Padding required to to hardware bug */
345 DMA_BLOCK( MGA_DMAPAD
, 0xffffffff,
346 MGA_DMAPAD
, 0xffffffff,
347 MGA_DMAPAD
, 0xffffffff,
348 MGA_WIADDR2
, (dev_priv
->warp_pipe_phys
[pipe
] |
355 static void mga_g200_emit_state( drm_mga_private_t
*dev_priv
)
357 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
358 unsigned int dirty
= sarea_priv
->dirty
;
360 if ( sarea_priv
->warp_pipe
!= dev_priv
->warp_pipe
) {
361 mga_g200_emit_pipe( dev_priv
);
362 dev_priv
->warp_pipe
= sarea_priv
->warp_pipe
;
365 if ( dirty
& MGA_UPLOAD_CONTEXT
) {
366 mga_g200_emit_context( dev_priv
);
367 sarea_priv
->dirty
&= ~MGA_UPLOAD_CONTEXT
;
370 if ( dirty
& MGA_UPLOAD_TEX0
) {
371 mga_g200_emit_tex0( dev_priv
);
372 sarea_priv
->dirty
&= ~MGA_UPLOAD_TEX0
;
376 static void mga_g400_emit_state( drm_mga_private_t
*dev_priv
)
378 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
379 unsigned int dirty
= sarea_priv
->dirty
;
380 int multitex
= sarea_priv
->warp_pipe
& MGA_T2
;
382 if ( sarea_priv
->warp_pipe
!= dev_priv
->warp_pipe
) {
383 mga_g400_emit_pipe( dev_priv
);
384 dev_priv
->warp_pipe
= sarea_priv
->warp_pipe
;
387 if ( dirty
& MGA_UPLOAD_CONTEXT
) {
388 mga_g400_emit_context( dev_priv
);
389 sarea_priv
->dirty
&= ~MGA_UPLOAD_CONTEXT
;
392 if ( dirty
& MGA_UPLOAD_TEX0
) {
393 mga_g400_emit_tex0( dev_priv
);
394 sarea_priv
->dirty
&= ~MGA_UPLOAD_TEX0
;
397 if ( (dirty
& MGA_UPLOAD_TEX1
) && multitex
) {
398 mga_g400_emit_tex1( dev_priv
);
399 sarea_priv
->dirty
&= ~MGA_UPLOAD_TEX1
;
404 /* ================================================================
405 * SAREA state verification
408 /* Disallow all write destinations except the front and backbuffer.
410 static int mga_verify_context( drm_mga_private_t
*dev_priv
)
412 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
413 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
415 if ( ctx
->dstorg
!= dev_priv
->front_offset
&&
416 ctx
->dstorg
!= dev_priv
->back_offset
) {
417 DRM_ERROR( "*** bad DSTORG: %x (front %x, back %x)\n\n",
418 ctx
->dstorg
, dev_priv
->front_offset
,
419 dev_priv
->back_offset
);
421 return DRM_ERR(EINVAL
);
427 /* Disallow texture reads from PCI space.
429 static int mga_verify_tex( drm_mga_private_t
*dev_priv
, int unit
)
431 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
432 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[unit
];
435 org
= tex
->texorg
& (MGA_TEXORGMAP_MASK
| MGA_TEXORGACC_MASK
);
437 if ( org
== (MGA_TEXORGMAP_SYSMEM
| MGA_TEXORGACC_PCI
) ) {
438 DRM_ERROR( "*** bad TEXORG: 0x%x, unit %d\n",
441 return DRM_ERR(EINVAL
);
447 static int mga_verify_state( drm_mga_private_t
*dev_priv
)
449 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
450 unsigned int dirty
= sarea_priv
->dirty
;
453 if ( sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
454 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
456 if ( dirty
& MGA_UPLOAD_CONTEXT
)
457 ret
|= mga_verify_context( dev_priv
);
459 if ( dirty
& MGA_UPLOAD_TEX0
)
460 ret
|= mga_verify_tex( dev_priv
, 0 );
462 if ( dev_priv
->chipset
== MGA_CARD_TYPE_G400
) {
463 if ( dirty
& MGA_UPLOAD_TEX1
)
464 ret
|= mga_verify_tex( dev_priv
, 1 );
466 if ( dirty
& MGA_UPLOAD_PIPE
)
467 ret
|= ( sarea_priv
->warp_pipe
> MGA_MAX_G400_PIPES
);
469 if ( dirty
& MGA_UPLOAD_PIPE
)
470 ret
|= ( sarea_priv
->warp_pipe
> MGA_MAX_G200_PIPES
);
476 static int mga_verify_iload( drm_mga_private_t
*dev_priv
,
477 unsigned int dstorg
, unsigned int length
)
479 if ( dstorg
< dev_priv
->texture_offset
||
480 dstorg
+ length
> (dev_priv
->texture_offset
+
481 dev_priv
->texture_size
) ) {
482 DRM_ERROR( "*** bad iload DSTORG: 0x%x\n", dstorg
);
483 return DRM_ERR(EINVAL
);
486 if ( length
& MGA_ILOAD_MASK
) {
487 DRM_ERROR( "*** bad iload length: 0x%x\n",
488 length
& MGA_ILOAD_MASK
);
489 return DRM_ERR(EINVAL
);
495 static int mga_verify_blit( drm_mga_private_t
*dev_priv
,
496 unsigned int srcorg
, unsigned int dstorg
)
498 if ( (srcorg
& 0x3) == (MGA_SRCACC_PCI
| MGA_SRCMAP_SYSMEM
) ||
499 (dstorg
& 0x3) == (MGA_SRCACC_PCI
| MGA_SRCMAP_SYSMEM
) ) {
500 DRM_ERROR( "*** bad blit: src=0x%x dst=0x%x\n",
502 return DRM_ERR(EINVAL
);
508 /* ================================================================
512 static void mga_dma_dispatch_clear( drm_device_t
*dev
,
513 drm_mga_clear_t
*clear
)
515 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
516 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
517 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
518 drm_clip_rect_t
*pbox
= sarea_priv
->boxes
;
519 int nbox
= sarea_priv
->nbox
;
526 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
527 MGA_DMAPAD
, 0x00000000,
528 MGA_DWGSYNC
, 0x00007100,
529 MGA_DWGSYNC
, 0x00007000 );
533 for ( i
= 0 ; i
< nbox
; i
++ ) {
534 drm_clip_rect_t
*box
= &pbox
[i
];
535 u32 height
= box
->y2
- box
->y1
;
537 DRM_DEBUG( " from=%d,%d to=%d,%d\n",
538 box
->x1
, box
->y1
, box
->x2
, box
->y2
);
540 if ( clear
->flags
& MGA_FRONT
) {
543 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
544 MGA_PLNWT
, clear
->color_mask
,
545 MGA_YDSTLEN
, (box
->y1
<< 16) | height
,
546 MGA_FXBNDRY
, (box
->x2
<< 16) | box
->x1
);
548 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
549 MGA_FCOL
, clear
->clear_color
,
550 MGA_DSTORG
, dev_priv
->front_offset
,
551 MGA_DWGCTL
+ MGA_EXEC
,
552 dev_priv
->clear_cmd
);
558 if ( clear
->flags
& MGA_BACK
) {
561 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
562 MGA_PLNWT
, clear
->color_mask
,
563 MGA_YDSTLEN
, (box
->y1
<< 16) | height
,
564 MGA_FXBNDRY
, (box
->x2
<< 16) | box
->x1
);
566 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
567 MGA_FCOL
, clear
->clear_color
,
568 MGA_DSTORG
, dev_priv
->back_offset
,
569 MGA_DWGCTL
+ MGA_EXEC
,
570 dev_priv
->clear_cmd
);
575 if ( clear
->flags
& MGA_DEPTH
) {
578 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
579 MGA_PLNWT
, clear
->depth_mask
,
580 MGA_YDSTLEN
, (box
->y1
<< 16) | height
,
581 MGA_FXBNDRY
, (box
->x2
<< 16) | box
->x1
);
583 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
584 MGA_FCOL
, clear
->clear_depth
,
585 MGA_DSTORG
, dev_priv
->depth_offset
,
586 MGA_DWGCTL
+ MGA_EXEC
,
587 dev_priv
->clear_cmd
);
596 /* Force reset of DWGCTL */
597 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
598 MGA_DMAPAD
, 0x00000000,
599 MGA_PLNWT
, ctx
->plnwt
,
600 MGA_DWGCTL
, ctx
->dwgctl
);
607 static void mga_dma_dispatch_swap( drm_device_t
*dev
)
609 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
610 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
611 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
612 drm_clip_rect_t
*pbox
= sarea_priv
->boxes
;
613 int nbox
= sarea_priv
->nbox
;
618 sarea_priv
->last_frame
.head
= dev_priv
->prim
.tail
;
619 sarea_priv
->last_frame
.wrap
= dev_priv
->prim
.last_wrap
;
621 BEGIN_DMA( 4 + nbox
);
623 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
624 MGA_DMAPAD
, 0x00000000,
625 MGA_DWGSYNC
, 0x00007100,
626 MGA_DWGSYNC
, 0x00007000 );
628 DMA_BLOCK( MGA_DSTORG
, dev_priv
->front_offset
,
629 MGA_MACCESS
, dev_priv
->maccess
,
630 MGA_SRCORG
, dev_priv
->back_offset
,
631 MGA_AR5
, dev_priv
->front_pitch
);
633 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
634 MGA_DMAPAD
, 0x00000000,
635 MGA_PLNWT
, 0xffffffff,
636 MGA_DWGCTL
, MGA_DWGCTL_COPY
);
638 for ( i
= 0 ; i
< nbox
; i
++ ) {
639 drm_clip_rect_t
*box
= &pbox
[i
];
640 u32 height
= box
->y2
- box
->y1
;
641 u32 start
= box
->y1
* dev_priv
->front_pitch
;
643 DRM_DEBUG( " from=%d,%d to=%d,%d\n",
644 box
->x1
, box
->y1
, box
->x2
, box
->y2
);
646 DMA_BLOCK( MGA_AR0
, start
+ box
->x2
- 1,
647 MGA_AR3
, start
+ box
->x1
,
648 MGA_FXBNDRY
, ((box
->x2
- 1) << 16) | box
->x1
,
649 MGA_YDSTLEN
+ MGA_EXEC
,
650 (box
->y1
<< 16) | height
);
653 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
654 MGA_PLNWT
, ctx
->plnwt
,
655 MGA_SRCORG
, dev_priv
->front_offset
,
656 MGA_DWGCTL
, ctx
->dwgctl
);
662 DRM_DEBUG( "%s... done.\n", __FUNCTION__
);
665 static void mga_dma_dispatch_vertex( drm_device_t
*dev
, drm_buf_t
*buf
)
667 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
668 drm_mga_buf_priv_t
*buf_priv
= buf
->dev_private
;
669 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
670 u32 address
= (u32
) buf
->bus_address
;
671 u32 length
= (u32
) buf
->used
;
674 DRM_DEBUG( "vertex: buf=%d used=%d\n", buf
->idx
, buf
->used
);
677 buf_priv
->dispatched
= 1;
679 MGA_EMIT_STATE( dev_priv
, sarea_priv
->dirty
);
682 if ( i
< sarea_priv
->nbox
) {
683 mga_emit_clip_rect( dev_priv
,
684 &sarea_priv
->boxes
[i
] );
689 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
690 MGA_DMAPAD
, 0x00000000,
691 MGA_SECADDRESS
, (address
|
693 MGA_SECEND
, ((address
+ length
) |
697 } while ( ++i
< sarea_priv
->nbox
);
700 if ( buf_priv
->discard
) {
701 AGE_BUFFER( buf_priv
);
704 buf_priv
->dispatched
= 0;
706 mga_freelist_put( dev
, buf
);
712 static void mga_dma_dispatch_indices( drm_device_t
*dev
, drm_buf_t
*buf
,
713 unsigned int start
, unsigned int end
)
715 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
716 drm_mga_buf_priv_t
*buf_priv
= buf
->dev_private
;
717 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
718 u32 address
= (u32
) buf
->bus_address
;
721 DRM_DEBUG( "indices: buf=%d start=%d end=%d\n", buf
->idx
, start
, end
);
723 if ( start
!= end
) {
724 buf_priv
->dispatched
= 1;
726 MGA_EMIT_STATE( dev_priv
, sarea_priv
->dirty
);
729 if ( i
< sarea_priv
->nbox
) {
730 mga_emit_clip_rect( dev_priv
,
731 &sarea_priv
->boxes
[i
] );
736 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
737 MGA_DMAPAD
, 0x00000000,
738 MGA_SETUPADDRESS
, address
+ start
,
739 MGA_SETUPEND
, ((address
+ end
) |
743 } while ( ++i
< sarea_priv
->nbox
);
746 if ( buf_priv
->discard
) {
747 AGE_BUFFER( buf_priv
);
750 buf_priv
->dispatched
= 0;
752 mga_freelist_put( dev
, buf
);
758 /* This copies a 64 byte aligned agp region to the frambuffer with a
759 * standard blit, the ioctl needs to do checking.
761 static void mga_dma_dispatch_iload( drm_device_t
*dev
, drm_buf_t
*buf
,
762 unsigned int dstorg
, unsigned int length
)
764 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
765 drm_mga_buf_priv_t
*buf_priv
= buf
->dev_private
;
766 drm_mga_context_regs_t
*ctx
= &dev_priv
->sarea_priv
->context_state
;
767 u32 srcorg
= buf
->bus_address
| MGA_SRCACC_AGP
| MGA_SRCMAP_SYSMEM
;
770 DRM_DEBUG( "buf=%d used=%d\n", buf
->idx
, buf
->used
);
776 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
777 MGA_DMAPAD
, 0x00000000,
778 MGA_DWGSYNC
, 0x00007100,
779 MGA_DWGSYNC
, 0x00007000 );
781 DMA_BLOCK( MGA_DSTORG
, dstorg
,
782 MGA_MACCESS
, 0x00000000,
786 DMA_BLOCK( MGA_PITCH
, 64,
787 MGA_PLNWT
, 0xffffffff,
788 MGA_DMAPAD
, 0x00000000,
789 MGA_DWGCTL
, MGA_DWGCTL_COPY
);
791 DMA_BLOCK( MGA_AR0
, 63,
793 MGA_FXBNDRY
, (63 << 16) | 0,
794 MGA_YDSTLEN
+ MGA_EXEC
, y2
);
796 DMA_BLOCK( MGA_PLNWT
, ctx
->plnwt
,
797 MGA_SRCORG
, dev_priv
->front_offset
,
798 MGA_PITCH
, dev_priv
->front_pitch
,
799 MGA_DWGSYNC
, 0x00007000 );
803 AGE_BUFFER( buf_priv
);
807 buf_priv
->dispatched
= 0;
809 mga_freelist_put( dev
, buf
);
814 static void mga_dma_dispatch_blit( drm_device_t
*dev
,
815 drm_mga_blit_t
*blit
)
817 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
818 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
819 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
820 drm_clip_rect_t
*pbox
= sarea_priv
->boxes
;
821 int nbox
= sarea_priv
->nbox
;
826 BEGIN_DMA( 4 + nbox
);
828 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
829 MGA_DMAPAD
, 0x00000000,
830 MGA_DWGSYNC
, 0x00007100,
831 MGA_DWGSYNC
, 0x00007000 );
833 DMA_BLOCK( MGA_DWGCTL
, MGA_DWGCTL_COPY
,
834 MGA_PLNWT
, blit
->planemask
,
835 MGA_SRCORG
, blit
->srcorg
,
836 MGA_DSTORG
, blit
->dstorg
);
838 DMA_BLOCK( MGA_SGN
, scandir
,
839 MGA_MACCESS
, dev_priv
->maccess
,
840 MGA_AR5
, blit
->ydir
* blit
->src_pitch
,
841 MGA_PITCH
, blit
->dst_pitch
);
843 for ( i
= 0 ; i
< nbox
; i
++ ) {
844 int srcx
= pbox
[i
].x1
+ blit
->delta_sx
;
845 int srcy
= pbox
[i
].y1
+ blit
->delta_sy
;
846 int dstx
= pbox
[i
].x1
+ blit
->delta_dx
;
847 int dsty
= pbox
[i
].y1
+ blit
->delta_dy
;
848 int h
= pbox
[i
].y2
- pbox
[i
].y1
;
849 int w
= pbox
[i
].x2
- pbox
[i
].x1
- 1;
852 if ( blit
->ydir
== -1 ) {
853 srcy
= blit
->height
- srcy
- 1;
856 start
= srcy
* blit
->src_pitch
+ srcx
;
858 DMA_BLOCK( MGA_AR0
, start
+ w
,
860 MGA_FXBNDRY
, ((dstx
+ w
) << 16) | (dstx
& 0xffff),
861 MGA_YDSTLEN
+ MGA_EXEC
, (dsty
<< 16) | h
);
864 /* Do something to flush AGP?
867 /* Force reset of DWGCTL */
868 DMA_BLOCK( MGA_DMAPAD
, 0x00000000,
869 MGA_PLNWT
, ctx
->plnwt
,
870 MGA_PITCH
, dev_priv
->front_pitch
,
871 MGA_DWGCTL
, ctx
->dwgctl
);
877 /* ================================================================
881 static int mga_dma_clear( DRM_IOCTL_ARGS
)
884 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
885 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
886 drm_mga_clear_t clear
;
888 LOCK_TEST_WITH_RETURN( dev
, filp
);
890 DRM_COPY_FROM_USER_IOCTL( clear
, (drm_mga_clear_t __user
*)data
, sizeof(clear
) );
892 if ( sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
893 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
895 WRAP_TEST_WITH_RETURN( dev_priv
);
897 mga_dma_dispatch_clear( dev
, &clear
);
899 /* Make sure we restore the 3D state next time.
901 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
906 static int mga_dma_swap( DRM_IOCTL_ARGS
)
909 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
910 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
912 LOCK_TEST_WITH_RETURN( dev
, filp
);
914 if ( sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
915 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
917 WRAP_TEST_WITH_RETURN( dev_priv
);
919 mga_dma_dispatch_swap( dev
);
921 /* Make sure we restore the 3D state next time.
923 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
928 static int mga_dma_vertex( DRM_IOCTL_ARGS
)
931 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
932 drm_device_dma_t
*dma
= dev
->dma
;
934 drm_mga_buf_priv_t
*buf_priv
;
935 drm_mga_vertex_t vertex
;
937 LOCK_TEST_WITH_RETURN( dev
, filp
);
939 DRM_COPY_FROM_USER_IOCTL( vertex
,
940 (drm_mga_vertex_t __user
*)data
,
943 if(vertex
.idx
< 0 || vertex
.idx
> dma
->buf_count
) return DRM_ERR(EINVAL
);
944 buf
= dma
->buflist
[vertex
.idx
];
945 buf_priv
= buf
->dev_private
;
947 buf
->used
= vertex
.used
;
948 buf_priv
->discard
= vertex
.discard
;
950 if ( !mga_verify_state( dev_priv
) ) {
951 if ( vertex
.discard
) {
952 if ( buf_priv
->dispatched
== 1 )
953 AGE_BUFFER( buf_priv
);
954 buf_priv
->dispatched
= 0;
955 mga_freelist_put( dev
, buf
);
957 return DRM_ERR(EINVAL
);
960 WRAP_TEST_WITH_RETURN( dev_priv
);
962 mga_dma_dispatch_vertex( dev
, buf
);
967 static int mga_dma_indices( DRM_IOCTL_ARGS
)
970 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
971 drm_device_dma_t
*dma
= dev
->dma
;
973 drm_mga_buf_priv_t
*buf_priv
;
974 drm_mga_indices_t indices
;
976 LOCK_TEST_WITH_RETURN( dev
, filp
);
978 DRM_COPY_FROM_USER_IOCTL( indices
,
979 (drm_mga_indices_t __user
*)data
,
982 if(indices
.idx
< 0 || indices
.idx
> dma
->buf_count
) return DRM_ERR(EINVAL
);
984 buf
= dma
->buflist
[indices
.idx
];
985 buf_priv
= buf
->dev_private
;
987 buf_priv
->discard
= indices
.discard
;
989 if ( !mga_verify_state( dev_priv
) ) {
990 if ( indices
.discard
) {
991 if ( buf_priv
->dispatched
== 1 )
992 AGE_BUFFER( buf_priv
);
993 buf_priv
->dispatched
= 0;
994 mga_freelist_put( dev
, buf
);
996 return DRM_ERR(EINVAL
);
999 WRAP_TEST_WITH_RETURN( dev_priv
);
1001 mga_dma_dispatch_indices( dev
, buf
, indices
.start
, indices
.end
);
1006 static int mga_dma_iload( DRM_IOCTL_ARGS
)
1009 drm_device_dma_t
*dma
= dev
->dma
;
1010 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
1012 drm_mga_buf_priv_t
*buf_priv
;
1013 drm_mga_iload_t iload
;
1016 LOCK_TEST_WITH_RETURN( dev
, filp
);
1018 DRM_COPY_FROM_USER_IOCTL( iload
, (drm_mga_iload_t __user
*)data
, sizeof(iload
) );
1021 if ( mga_do_wait_for_idle( dev_priv
) < 0 ) {
1022 if ( MGA_DMA_DEBUG
)
1023 DRM_INFO( "%s: -EBUSY\n", __FUNCTION__
);
1024 return DRM_ERR(EBUSY
);
1027 if(iload
.idx
< 0 || iload
.idx
> dma
->buf_count
) return DRM_ERR(EINVAL
);
1029 buf
= dma
->buflist
[iload
.idx
];
1030 buf_priv
= buf
->dev_private
;
1032 if ( mga_verify_iload( dev_priv
, iload
.dstorg
, iload
.length
) ) {
1033 mga_freelist_put( dev
, buf
);
1034 return DRM_ERR(EINVAL
);
1037 WRAP_TEST_WITH_RETURN( dev_priv
);
1039 mga_dma_dispatch_iload( dev
, buf
, iload
.dstorg
, iload
.length
);
1041 /* Make sure we restore the 3D state next time.
1043 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
1048 static int mga_dma_blit( DRM_IOCTL_ARGS
)
1051 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
1052 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
1053 drm_mga_blit_t blit
;
1056 LOCK_TEST_WITH_RETURN( dev
, filp
);
1058 DRM_COPY_FROM_USER_IOCTL( blit
, (drm_mga_blit_t __user
*)data
, sizeof(blit
) );
1060 if ( sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
1061 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
1063 if ( mga_verify_blit( dev_priv
, blit
.srcorg
, blit
.dstorg
) )
1064 return DRM_ERR(EINVAL
);
1066 WRAP_TEST_WITH_RETURN( dev_priv
);
1068 mga_dma_dispatch_blit( dev
, &blit
);
1070 /* Make sure we restore the 3D state next time.
1072 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
1077 static int mga_getparam( DRM_IOCTL_ARGS
)
1080 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
1081 drm_mga_getparam_t param
;
1085 DRM_ERROR( "%s called with no initialization\n", __FUNCTION__
);
1086 return DRM_ERR(EINVAL
);
1089 DRM_COPY_FROM_USER_IOCTL( param
, (drm_mga_getparam_t __user
*)data
,
1092 DRM_DEBUG( "pid=%d\n", DRM_CURRENTPID
);
1094 switch( param
.param
) {
1095 case MGA_PARAM_IRQ_NR
:
1099 return DRM_ERR(EINVAL
);
1102 if ( DRM_COPY_TO_USER( param
.value
, &value
, sizeof(int) ) ) {
1103 DRM_ERROR( "copy_to_user\n" );
1104 return DRM_ERR(EFAULT
);
1110 drm_ioctl_desc_t mga_ioctls
[] = {
1111 [DRM_IOCTL_NR(DRM_MGA_INIT
)] = { mga_dma_init
, 1, 1 },
1112 [DRM_IOCTL_NR(DRM_MGA_FLUSH
)] = { mga_dma_flush
, 1, 0 },
1113 [DRM_IOCTL_NR(DRM_MGA_RESET
)] = { mga_dma_reset
, 1, 0 },
1114 [DRM_IOCTL_NR(DRM_MGA_SWAP
)] = { mga_dma_swap
, 1, 0 },
1115 [DRM_IOCTL_NR(DRM_MGA_CLEAR
)] = { mga_dma_clear
, 1, 0 },
1116 [DRM_IOCTL_NR(DRM_MGA_VERTEX
)] = { mga_dma_vertex
, 1, 0 },
1117 [DRM_IOCTL_NR(DRM_MGA_INDICES
)] = { mga_dma_indices
, 1, 0 },
1118 [DRM_IOCTL_NR(DRM_MGA_ILOAD
)] = { mga_dma_iload
, 1, 0 },
1119 [DRM_IOCTL_NR(DRM_MGA_BLIT
)] = { mga_dma_blit
, 1, 0 },
1120 [DRM_IOCTL_NR(DRM_MGA_GETPARAM
)]= { mga_getparam
, 1, 0 },
1123 int mga_max_ioctl
= DRM_ARRAY_SIZE(mga_ioctls
);