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>
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include "dev/drm/mga.h"
40 #include "dev/drm/drmP.h"
41 #include "dev/drm/drm.h"
42 #include "dev/drm/mga_drm.h"
43 #include "dev/drm/mga_drv.h"
46 /* ================================================================
47 * DMA hardware state programming functions
50 static void mga_emit_clip_rect( drm_mga_private_t *dev_priv,
51 drm_clip_rect_t *box )
53 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
54 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
55 unsigned int pitch = dev_priv->front_pitch;
60 /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
62 if ( dev_priv->chipset == MGA_CARD_TYPE_G400 ) {
63 DMA_BLOCK( MGA_DWGCTL, ctx->dwgctl,
64 MGA_LEN + MGA_EXEC, 0x80000000,
65 MGA_DWGCTL, ctx->dwgctl,
66 MGA_LEN + MGA_EXEC, 0x80000000 );
68 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
69 MGA_CXBNDRY, (box->x2 << 16) | box->x1,
70 MGA_YTOP, box->y1 * pitch,
71 MGA_YBOT, box->y2 * pitch );
76 static __inline__ void mga_g200_emit_context( drm_mga_private_t *dev_priv )
78 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
79 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
84 DMA_BLOCK( MGA_DSTORG, ctx->dstorg,
85 MGA_MACCESS, ctx->maccess,
86 MGA_PLNWT, ctx->plnwt,
87 MGA_DWGCTL, ctx->dwgctl );
89 DMA_BLOCK( MGA_ALPHACTRL, ctx->alphactrl,
90 MGA_FOGCOL, ctx->fogcolor,
91 MGA_WFLAG, ctx->wflag,
92 MGA_ZORG, dev_priv->depth_offset );
94 DMA_BLOCK( MGA_FCOL, ctx->fcol,
95 MGA_DMAPAD, 0x00000000,
96 MGA_DMAPAD, 0x00000000,
97 MGA_DMAPAD, 0x00000000 );
102 static __inline__ void mga_g400_emit_context( drm_mga_private_t *dev_priv )
104 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
105 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
110 DMA_BLOCK( MGA_DSTORG, ctx->dstorg,
111 MGA_MACCESS, ctx->maccess,
112 MGA_PLNWT, ctx->plnwt,
113 MGA_DWGCTL, ctx->dwgctl );
115 DMA_BLOCK( MGA_ALPHACTRL, ctx->alphactrl,
116 MGA_FOGCOL, ctx->fogcolor,
117 MGA_WFLAG, ctx->wflag,
118 MGA_ZORG, dev_priv->depth_offset );
120 DMA_BLOCK( MGA_WFLAG1, ctx->wflag,
121 MGA_TDUALSTAGE0, ctx->tdualstage0,
122 MGA_TDUALSTAGE1, ctx->tdualstage1,
123 MGA_FCOL, ctx->fcol );
125 DMA_BLOCK( MGA_STENCIL, ctx->stencil,
126 MGA_STENCILCTL, ctx->stencilctl,
127 MGA_DMAPAD, 0x00000000,
128 MGA_DMAPAD, 0x00000000 );
133 static __inline__ void mga_g200_emit_tex0( drm_mga_private_t *dev_priv )
135 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
136 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
141 DMA_BLOCK( MGA_TEXCTL2, tex->texctl2,
142 MGA_TEXCTL, tex->texctl,
143 MGA_TEXFILTER, tex->texfilter,
144 MGA_TEXBORDERCOL, tex->texbordercol );
146 DMA_BLOCK( MGA_TEXORG, tex->texorg,
147 MGA_TEXORG1, tex->texorg1,
148 MGA_TEXORG2, tex->texorg2,
149 MGA_TEXORG3, tex->texorg3 );
151 DMA_BLOCK( MGA_TEXORG4, tex->texorg4,
152 MGA_TEXWIDTH, tex->texwidth,
153 MGA_TEXHEIGHT, tex->texheight,
154 MGA_WR24, tex->texwidth );
156 DMA_BLOCK( MGA_WR34, tex->texheight,
157 MGA_TEXTRANS, 0x0000ffff,
158 MGA_TEXTRANSHIGH, 0x0000ffff,
159 MGA_DMAPAD, 0x00000000 );
164 static /*__inline__*/ void mga_g400_emit_tex0( drm_mga_private_t *dev_priv )
166 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
167 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
170 /* printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
171 /* tex->texctl, tex->texctl2); */
175 DMA_BLOCK( MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC,
176 MGA_TEXCTL, tex->texctl,
177 MGA_TEXFILTER, tex->texfilter,
178 MGA_TEXBORDERCOL, tex->texbordercol );
180 DMA_BLOCK( MGA_TEXORG, tex->texorg,
181 MGA_TEXORG1, tex->texorg1,
182 MGA_TEXORG2, tex->texorg2,
183 MGA_TEXORG3, tex->texorg3 );
185 DMA_BLOCK( MGA_TEXORG4, tex->texorg4,
186 MGA_TEXWIDTH, tex->texwidth,
187 MGA_TEXHEIGHT, tex->texheight,
188 MGA_WR49, 0x00000000 );
190 DMA_BLOCK( MGA_WR57, 0x00000000,
191 MGA_WR53, 0x00000000,
192 MGA_WR61, 0x00000000,
193 MGA_WR52, MGA_G400_WR_MAGIC );
195 DMA_BLOCK( MGA_WR60, MGA_G400_WR_MAGIC,
196 MGA_WR54, tex->texwidth | MGA_G400_WR_MAGIC,
197 MGA_WR62, tex->texheight | MGA_G400_WR_MAGIC,
198 MGA_DMAPAD, 0x00000000 );
200 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
201 MGA_DMAPAD, 0x00000000,
202 MGA_TEXTRANS, 0x0000ffff,
203 MGA_TEXTRANSHIGH, 0x0000ffff );
208 static __inline__ void mga_g400_emit_tex1( drm_mga_private_t *dev_priv )
210 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
211 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[1];
214 /* printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg, */
215 /* tex->texctl, tex->texctl2); */
219 DMA_BLOCK( MGA_TEXCTL2, (tex->texctl2 |
222 MGA_TEXCTL, tex->texctl,
223 MGA_TEXFILTER, tex->texfilter,
224 MGA_TEXBORDERCOL, tex->texbordercol );
226 DMA_BLOCK( MGA_TEXORG, tex->texorg,
227 MGA_TEXORG1, tex->texorg1,
228 MGA_TEXORG2, tex->texorg2,
229 MGA_TEXORG3, tex->texorg3 );
231 DMA_BLOCK( MGA_TEXORG4, tex->texorg4,
232 MGA_TEXWIDTH, tex->texwidth,
233 MGA_TEXHEIGHT, tex->texheight,
234 MGA_WR49, 0x00000000 );
236 DMA_BLOCK( MGA_WR57, 0x00000000,
237 MGA_WR53, 0x00000000,
238 MGA_WR61, 0x00000000,
239 MGA_WR52, tex->texwidth | MGA_G400_WR_MAGIC );
241 DMA_BLOCK( MGA_WR60, tex->texheight | MGA_G400_WR_MAGIC,
242 MGA_TEXTRANS, 0x0000ffff,
243 MGA_TEXTRANSHIGH, 0x0000ffff,
244 MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC );
249 static __inline__ void mga_g200_emit_pipe( drm_mga_private_t *dev_priv )
251 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
252 unsigned int pipe = sarea_priv->warp_pipe;
257 DMA_BLOCK( MGA_WIADDR, MGA_WMODE_SUSPEND,
258 MGA_WVRTXSZ, 0x00000007,
259 MGA_WFLAG, 0x00000000,
260 MGA_WR24, 0x00000000 );
262 DMA_BLOCK( MGA_WR25, 0x00000100,
263 MGA_WR34, 0x00000000,
264 MGA_WR42, 0x0000ffff,
265 MGA_WR60, 0x0000ffff );
267 /* Padding required to to hardware bug.
269 DMA_BLOCK( MGA_DMAPAD, 0xffffffff,
270 MGA_DMAPAD, 0xffffffff,
271 MGA_DMAPAD, 0xffffffff,
272 MGA_WIADDR, (dev_priv->warp_pipe_phys[pipe] |
279 static /*__inline__*/ void mga_g400_emit_pipe( drm_mga_private_t *dev_priv )
281 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
282 unsigned int pipe = sarea_priv->warp_pipe;
285 /* printk("mga_g400_emit_pipe %x\n", pipe); */
289 DMA_BLOCK( MGA_WIADDR2, MGA_WMODE_SUSPEND,
290 MGA_DMAPAD, 0x00000000,
291 MGA_DMAPAD, 0x00000000,
292 MGA_DMAPAD, 0x00000000 );
294 if ( pipe & MGA_T2 ) {
295 DMA_BLOCK( MGA_WVRTXSZ, 0x00001e09,
296 MGA_DMAPAD, 0x00000000,
297 MGA_DMAPAD, 0x00000000,
298 MGA_DMAPAD, 0x00000000 );
300 DMA_BLOCK( MGA_WACCEPTSEQ, 0x00000000,
301 MGA_WACCEPTSEQ, 0x00000000,
302 MGA_WACCEPTSEQ, 0x00000000,
303 MGA_WACCEPTSEQ, 0x1e000000 );
305 if ( dev_priv->warp_pipe & MGA_T2 ) {
306 /* Flush the WARP pipe */
307 DMA_BLOCK( MGA_YDST, 0x00000000,
308 MGA_FXLEFT, 0x00000000,
309 MGA_FXRIGHT, 0x00000001,
310 MGA_DWGCTL, MGA_DWGCTL_FLUSH );
312 DMA_BLOCK( MGA_LEN + MGA_EXEC, 0x00000001,
313 MGA_DWGSYNC, 0x00007000,
314 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
315 MGA_LEN + MGA_EXEC, 0x00000000 );
317 DMA_BLOCK( MGA_TEXCTL2, (MGA_DUALTEX |
319 MGA_LEN + MGA_EXEC, 0x00000000,
320 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
321 MGA_DMAPAD, 0x00000000 );
324 DMA_BLOCK( MGA_WVRTXSZ, 0x00001807,
325 MGA_DMAPAD, 0x00000000,
326 MGA_DMAPAD, 0x00000000,
327 MGA_DMAPAD, 0x00000000 );
329 DMA_BLOCK( MGA_WACCEPTSEQ, 0x00000000,
330 MGA_WACCEPTSEQ, 0x00000000,
331 MGA_WACCEPTSEQ, 0x00000000,
332 MGA_WACCEPTSEQ, 0x18000000 );
335 DMA_BLOCK( MGA_WFLAG, 0x00000000,
336 MGA_WFLAG1, 0x00000000,
337 MGA_WR56, MGA_G400_WR56_MAGIC,
338 MGA_DMAPAD, 0x00000000 );
340 DMA_BLOCK( MGA_WR49, 0x00000000, /* tex0 */
341 MGA_WR57, 0x00000000, /* tex0 */
342 MGA_WR53, 0x00000000, /* tex1 */
343 MGA_WR61, 0x00000000 ); /* tex1 */
345 DMA_BLOCK( MGA_WR54, MGA_G400_WR_MAGIC, /* tex0 width */
346 MGA_WR62, MGA_G400_WR_MAGIC, /* tex0 height */
347 MGA_WR52, MGA_G400_WR_MAGIC, /* tex1 width */
348 MGA_WR60, MGA_G400_WR_MAGIC ); /* tex1 height */
350 /* Padding required to to hardware bug */
351 DMA_BLOCK( MGA_DMAPAD, 0xffffffff,
352 MGA_DMAPAD, 0xffffffff,
353 MGA_DMAPAD, 0xffffffff,
354 MGA_WIADDR2, (dev_priv->warp_pipe_phys[pipe] |
361 static void mga_g200_emit_state( drm_mga_private_t *dev_priv )
363 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
364 unsigned int dirty = sarea_priv->dirty;
366 if ( sarea_priv->warp_pipe != dev_priv->warp_pipe ) {
367 mga_g200_emit_pipe( dev_priv );
368 dev_priv->warp_pipe = sarea_priv->warp_pipe;
371 if ( dirty & MGA_UPLOAD_CONTEXT ) {
372 mga_g200_emit_context( dev_priv );
373 sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
376 if ( dirty & MGA_UPLOAD_TEX0 ) {
377 mga_g200_emit_tex0( dev_priv );
378 sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
382 static void mga_g400_emit_state( drm_mga_private_t *dev_priv )
384 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
385 unsigned int dirty = sarea_priv->dirty;
386 int multitex = sarea_priv->warp_pipe & MGA_T2;
388 if ( sarea_priv->warp_pipe != dev_priv->warp_pipe ) {
389 mga_g400_emit_pipe( dev_priv );
390 dev_priv->warp_pipe = sarea_priv->warp_pipe;
393 if ( dirty & MGA_UPLOAD_CONTEXT ) {
394 mga_g400_emit_context( dev_priv );
395 sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
398 if ( dirty & MGA_UPLOAD_TEX0 ) {
399 mga_g400_emit_tex0( dev_priv );
400 sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
403 if ( (dirty & MGA_UPLOAD_TEX1) && multitex ) {
404 mga_g400_emit_tex1( dev_priv );
405 sarea_priv->dirty &= ~MGA_UPLOAD_TEX1;
410 /* ================================================================
411 * SAREA state verification
414 /* Disallow all write destinations except the front and backbuffer.
416 static int mga_verify_context( drm_mga_private_t *dev_priv )
418 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
419 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
421 if ( ctx->dstorg != dev_priv->front_offset &&
422 ctx->dstorg != dev_priv->back_offset ) {
423 DRM_ERROR( "*** bad DSTORG: %x (front %x, back %x)\n\n",
424 ctx->dstorg, dev_priv->front_offset,
425 dev_priv->back_offset );
427 return DRM_ERR(EINVAL);
433 /* Disallow texture reads from PCI space.
435 static int mga_verify_tex( drm_mga_private_t *dev_priv, int unit )
437 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
438 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[unit];
441 org = tex->texorg & (MGA_TEXORGMAP_MASK | MGA_TEXORGACC_MASK);
443 if ( org == (MGA_TEXORGMAP_SYSMEM | MGA_TEXORGACC_PCI) ) {
444 DRM_ERROR( "*** bad TEXORG: 0x%x, unit %d\n",
447 return DRM_ERR(EINVAL);
453 static int mga_verify_state( drm_mga_private_t *dev_priv )
455 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
456 unsigned int dirty = sarea_priv->dirty;
459 if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
460 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
462 if ( dirty & MGA_UPLOAD_CONTEXT )
463 ret |= mga_verify_context( dev_priv );
465 if ( dirty & MGA_UPLOAD_TEX0 )
466 ret |= mga_verify_tex( dev_priv, 0 );
468 if ( dev_priv->chipset == MGA_CARD_TYPE_G400 ) {
469 if ( dirty & MGA_UPLOAD_TEX1 )
470 ret |= mga_verify_tex( dev_priv, 1 );
472 if ( dirty & MGA_UPLOAD_PIPE )
473 ret |= ( sarea_priv->warp_pipe > MGA_MAX_G400_PIPES );
475 if ( dirty & MGA_UPLOAD_PIPE )
476 ret |= ( sarea_priv->warp_pipe > MGA_MAX_G200_PIPES );
482 static int mga_verify_iload( drm_mga_private_t *dev_priv,
483 unsigned int dstorg, unsigned int length )
485 if ( dstorg < dev_priv->texture_offset ||
486 dstorg + length > (dev_priv->texture_offset +
487 dev_priv->texture_size) ) {
488 DRM_ERROR( "*** bad iload DSTORG: 0x%x\n", dstorg );
489 return DRM_ERR(EINVAL);
492 if ( length & MGA_ILOAD_MASK ) {
493 DRM_ERROR( "*** bad iload length: 0x%x\n",
494 length & MGA_ILOAD_MASK );
495 return DRM_ERR(EINVAL);
501 static int mga_verify_blit( drm_mga_private_t *dev_priv,
502 unsigned int srcorg, unsigned int dstorg )
504 if ( (srcorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ||
505 (dstorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ) {
506 DRM_ERROR( "*** bad blit: src=0x%x dst=0x%x\n",
508 return DRM_ERR(EINVAL);
514 /* ================================================================
518 static void mga_dma_dispatch_clear( drm_device_t *dev,
519 drm_mga_clear_t *clear )
521 drm_mga_private_t *dev_priv = dev->dev_private;
522 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
523 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
524 drm_clip_rect_t *pbox = sarea_priv->boxes;
525 int nbox = sarea_priv->nbox;
532 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
533 MGA_DMAPAD, 0x00000000,
534 MGA_DWGSYNC, 0x00007100,
535 MGA_DWGSYNC, 0x00007000 );
539 for ( i = 0 ; i < nbox ; i++ ) {
540 drm_clip_rect_t *box = &pbox[i];
541 u32 height = box->y2 - box->y1;
543 DRM_DEBUG( " from=%d,%d to=%d,%d\n",
544 box->x1, box->y1, box->x2, box->y2 );
546 if ( clear->flags & MGA_FRONT ) {
549 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
550 MGA_PLNWT, clear->color_mask,
551 MGA_YDSTLEN, (box->y1 << 16) | height,
552 MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
554 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
555 MGA_FCOL, clear->clear_color,
556 MGA_DSTORG, dev_priv->front_offset,
557 MGA_DWGCTL + MGA_EXEC,
558 dev_priv->clear_cmd );
564 if ( clear->flags & MGA_BACK ) {
567 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
568 MGA_PLNWT, clear->color_mask,
569 MGA_YDSTLEN, (box->y1 << 16) | height,
570 MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
572 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
573 MGA_FCOL, clear->clear_color,
574 MGA_DSTORG, dev_priv->back_offset,
575 MGA_DWGCTL + MGA_EXEC,
576 dev_priv->clear_cmd );
581 if ( clear->flags & MGA_DEPTH ) {
584 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
585 MGA_PLNWT, clear->depth_mask,
586 MGA_YDSTLEN, (box->y1 << 16) | height,
587 MGA_FXBNDRY, (box->x2 << 16) | box->x1 );
589 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
590 MGA_FCOL, clear->clear_depth,
591 MGA_DSTORG, dev_priv->depth_offset,
592 MGA_DWGCTL + MGA_EXEC,
593 dev_priv->clear_cmd );
602 /* Force reset of DWGCTL */
603 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
604 MGA_DMAPAD, 0x00000000,
605 MGA_PLNWT, ctx->plnwt,
606 MGA_DWGCTL, ctx->dwgctl );
613 static void mga_dma_dispatch_swap( drm_device_t *dev )
615 drm_mga_private_t *dev_priv = dev->dev_private;
616 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
617 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
618 drm_clip_rect_t *pbox = sarea_priv->boxes;
619 int nbox = sarea_priv->nbox;
624 sarea_priv->last_frame.head = dev_priv->prim.tail;
625 sarea_priv->last_frame.wrap = dev_priv->prim.last_wrap;
627 BEGIN_DMA( 4 + nbox );
629 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
630 MGA_DMAPAD, 0x00000000,
631 MGA_DWGSYNC, 0x00007100,
632 MGA_DWGSYNC, 0x00007000 );
634 DMA_BLOCK( MGA_DSTORG, dev_priv->front_offset,
635 MGA_MACCESS, dev_priv->maccess,
636 MGA_SRCORG, dev_priv->back_offset,
637 MGA_AR5, dev_priv->front_pitch );
639 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
640 MGA_DMAPAD, 0x00000000,
641 MGA_PLNWT, 0xffffffff,
642 MGA_DWGCTL, MGA_DWGCTL_COPY );
644 for ( i = 0 ; i < nbox ; i++ ) {
645 drm_clip_rect_t *box = &pbox[i];
646 u32 height = box->y2 - box->y1;
647 u32 start = box->y1 * dev_priv->front_pitch;
649 DRM_DEBUG( " from=%d,%d to=%d,%d\n",
650 box->x1, box->y1, box->x2, box->y2 );
652 DMA_BLOCK( MGA_AR0, start + box->x2 - 1,
653 MGA_AR3, start + box->x1,
654 MGA_FXBNDRY, ((box->x2 - 1) << 16) | box->x1,
655 MGA_YDSTLEN + MGA_EXEC,
656 (box->y1 << 16) | height );
659 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
660 MGA_PLNWT, ctx->plnwt,
661 MGA_SRCORG, dev_priv->front_offset,
662 MGA_DWGCTL, ctx->dwgctl );
668 DRM_DEBUG( "%s... done.\n", __FUNCTION__ );
671 static void mga_dma_dispatch_vertex( drm_device_t *dev, drm_buf_t *buf )
673 drm_mga_private_t *dev_priv = dev->dev_private;
674 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
675 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
676 u32 address = (u32) buf->bus_address;
677 u32 length = (u32) buf->used;
680 DRM_DEBUG( "vertex: buf=%d used=%d\n", buf->idx, buf->used );
683 buf_priv->dispatched = 1;
685 MGA_EMIT_STATE( dev_priv, sarea_priv->dirty );
688 if ( i < sarea_priv->nbox ) {
689 mga_emit_clip_rect( dev_priv,
690 &sarea_priv->boxes[i] );
695 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
696 MGA_DMAPAD, 0x00000000,
697 MGA_SECADDRESS, (address |
699 MGA_SECEND, ((address + length) |
703 } while ( ++i < sarea_priv->nbox );
706 if ( buf_priv->discard ) {
707 AGE_BUFFER( buf_priv );
710 buf_priv->dispatched = 0;
712 mga_freelist_put( dev, buf );
718 static void mga_dma_dispatch_indices( drm_device_t *dev, drm_buf_t *buf,
719 unsigned int start, unsigned int end )
721 drm_mga_private_t *dev_priv = dev->dev_private;
722 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
723 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
724 u32 address = (u32) buf->bus_address;
727 DRM_DEBUG( "indices: buf=%d start=%d end=%d\n", buf->idx, start, end );
729 if ( start != end ) {
730 buf_priv->dispatched = 1;
732 MGA_EMIT_STATE( dev_priv, sarea_priv->dirty );
735 if ( i < sarea_priv->nbox ) {
736 mga_emit_clip_rect( dev_priv,
737 &sarea_priv->boxes[i] );
742 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
743 MGA_DMAPAD, 0x00000000,
744 MGA_SETUPADDRESS, address + start,
745 MGA_SETUPEND, ((address + end) |
749 } while ( ++i < sarea_priv->nbox );
752 if ( buf_priv->discard ) {
753 AGE_BUFFER( buf_priv );
756 buf_priv->dispatched = 0;
758 mga_freelist_put( dev, buf );
764 /* This copies a 64 byte aligned agp region to the frambuffer with a
765 * standard blit, the ioctl needs to do checking.
767 static void mga_dma_dispatch_iload( drm_device_t *dev, drm_buf_t *buf,
768 unsigned int dstorg, unsigned int length )
770 drm_mga_private_t *dev_priv = dev->dev_private;
771 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
772 drm_mga_context_regs_t *ctx = &dev_priv->sarea_priv->context_state;
773 u32 srcorg = buf->bus_address | MGA_SRCACC_AGP | MGA_SRCMAP_SYSMEM;
776 DRM_DEBUG( "buf=%d used=%d\n", buf->idx, buf->used );
782 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
783 MGA_DMAPAD, 0x00000000,
784 MGA_DWGSYNC, 0x00007100,
785 MGA_DWGSYNC, 0x00007000 );
787 DMA_BLOCK( MGA_DSTORG, dstorg,
788 MGA_MACCESS, 0x00000000,
792 DMA_BLOCK( MGA_PITCH, 64,
793 MGA_PLNWT, 0xffffffff,
794 MGA_DMAPAD, 0x00000000,
795 MGA_DWGCTL, MGA_DWGCTL_COPY );
797 DMA_BLOCK( MGA_AR0, 63,
799 MGA_FXBNDRY, (63 << 16) | 0,
800 MGA_YDSTLEN + MGA_EXEC, y2 );
802 DMA_BLOCK( MGA_PLNWT, ctx->plnwt,
803 MGA_SRCORG, dev_priv->front_offset,
804 MGA_PITCH, dev_priv->front_pitch,
805 MGA_DWGSYNC, 0x00007000 );
809 AGE_BUFFER( buf_priv );
813 buf_priv->dispatched = 0;
815 mga_freelist_put( dev, buf );
820 static void mga_dma_dispatch_blit( drm_device_t *dev,
821 drm_mga_blit_t *blit )
823 drm_mga_private_t *dev_priv = dev->dev_private;
824 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
825 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
826 drm_clip_rect_t *pbox = sarea_priv->boxes;
827 int nbox = sarea_priv->nbox;
832 BEGIN_DMA( 4 + nbox );
834 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
835 MGA_DMAPAD, 0x00000000,
836 MGA_DWGSYNC, 0x00007100,
837 MGA_DWGSYNC, 0x00007000 );
839 DMA_BLOCK( MGA_DWGCTL, MGA_DWGCTL_COPY,
840 MGA_PLNWT, blit->planemask,
841 MGA_SRCORG, blit->srcorg,
842 MGA_DSTORG, blit->dstorg );
844 DMA_BLOCK( MGA_SGN, scandir,
845 MGA_MACCESS, dev_priv->maccess,
846 MGA_AR5, blit->ydir * blit->src_pitch,
847 MGA_PITCH, blit->dst_pitch );
849 for ( i = 0 ; i < nbox ; i++ ) {
850 int srcx = pbox[i].x1 + blit->delta_sx;
851 int srcy = pbox[i].y1 + blit->delta_sy;
852 int dstx = pbox[i].x1 + blit->delta_dx;
853 int dsty = pbox[i].y1 + blit->delta_dy;
854 int h = pbox[i].y2 - pbox[i].y1;
855 int w = pbox[i].x2 - pbox[i].x1 - 1;
858 if ( blit->ydir == -1 ) {
859 srcy = blit->height - srcy - 1;
862 start = srcy * blit->src_pitch + srcx;
864 DMA_BLOCK( MGA_AR0, start + w,
866 MGA_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff),
867 MGA_YDSTLEN + MGA_EXEC, (dsty << 16) | h );
870 /* Do something to flush AGP?
873 /* Force reset of DWGCTL */
874 DMA_BLOCK( MGA_DMAPAD, 0x00000000,
875 MGA_PLNWT, ctx->plnwt,
876 MGA_PITCH, dev_priv->front_pitch,
877 MGA_DWGCTL, ctx->dwgctl );
883 /* ================================================================
887 int mga_dma_clear( DRM_IOCTL_ARGS )
890 drm_mga_private_t *dev_priv = dev->dev_private;
891 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
892 drm_mga_clear_t clear;
894 LOCK_TEST_WITH_RETURN( dev, filp );
896 DRM_COPY_FROM_USER_IOCTL( clear, (drm_mga_clear_t *)data, sizeof(clear) );
898 if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
899 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
901 WRAP_TEST_WITH_RETURN( dev_priv );
903 mga_dma_dispatch_clear( dev, &clear );
905 /* Make sure we restore the 3D state next time.
907 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
912 int mga_dma_swap( DRM_IOCTL_ARGS )
915 drm_mga_private_t *dev_priv = dev->dev_private;
916 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
918 LOCK_TEST_WITH_RETURN( dev, filp );
920 if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
921 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
923 WRAP_TEST_WITH_RETURN( dev_priv );
925 mga_dma_dispatch_swap( dev );
927 /* Make sure we restore the 3D state next time.
929 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
934 int mga_dma_vertex( DRM_IOCTL_ARGS )
937 drm_mga_private_t *dev_priv = dev->dev_private;
938 drm_device_dma_t *dma = dev->dma;
940 drm_mga_buf_priv_t *buf_priv;
941 drm_mga_vertex_t vertex;
943 LOCK_TEST_WITH_RETURN( dev, filp );
945 DRM_COPY_FROM_USER_IOCTL( vertex,
946 (drm_mga_vertex_t *)data,
949 if(vertex.idx < 0 || vertex.idx > dma->buf_count) return DRM_ERR(EINVAL);
950 buf = dma->buflist[vertex.idx];
951 buf_priv = buf->dev_private;
953 buf->used = vertex.used;
954 buf_priv->discard = vertex.discard;
956 if ( !mga_verify_state( dev_priv ) ) {
957 if ( vertex.discard ) {
958 if ( buf_priv->dispatched == 1 )
959 AGE_BUFFER( buf_priv );
960 buf_priv->dispatched = 0;
961 mga_freelist_put( dev, buf );
963 return DRM_ERR(EINVAL);
966 WRAP_TEST_WITH_RETURN( dev_priv );
968 mga_dma_dispatch_vertex( dev, buf );
973 int mga_dma_indices( DRM_IOCTL_ARGS )
976 drm_mga_private_t *dev_priv = dev->dev_private;
977 drm_device_dma_t *dma = dev->dma;
979 drm_mga_buf_priv_t *buf_priv;
980 drm_mga_indices_t indices;
982 LOCK_TEST_WITH_RETURN( dev, filp );
984 DRM_COPY_FROM_USER_IOCTL( indices,
985 (drm_mga_indices_t *)data,
988 if(indices.idx < 0 || indices.idx > dma->buf_count) return DRM_ERR(EINVAL);
990 buf = dma->buflist[indices.idx];
991 buf_priv = buf->dev_private;
993 buf_priv->discard = indices.discard;
995 if ( !mga_verify_state( dev_priv ) ) {
996 if ( indices.discard ) {
997 if ( buf_priv->dispatched == 1 )
998 AGE_BUFFER( buf_priv );
999 buf_priv->dispatched = 0;
1000 mga_freelist_put( dev, buf );
1002 return DRM_ERR(EINVAL);
1005 WRAP_TEST_WITH_RETURN( dev_priv );
1007 mga_dma_dispatch_indices( dev, buf, indices.start, indices.end );
1012 int mga_dma_iload( DRM_IOCTL_ARGS )
1015 drm_device_dma_t *dma = dev->dma;
1016 drm_mga_private_t *dev_priv = dev->dev_private;
1018 drm_mga_buf_priv_t *buf_priv;
1019 drm_mga_iload_t iload;
1022 LOCK_TEST_WITH_RETURN( dev, filp );
1024 DRM_COPY_FROM_USER_IOCTL( iload, (drm_mga_iload_t *)data, sizeof(iload) );
1027 if ( mga_do_wait_for_idle( dev_priv ) < 0 ) {
1028 if ( MGA_DMA_DEBUG )
1029 DRM_INFO( "%s: -EBUSY\n", __FUNCTION__ );
1030 return DRM_ERR(EBUSY);
1033 if(iload.idx < 0 || iload.idx > dma->buf_count) return DRM_ERR(EINVAL);
1035 buf = dma->buflist[iload.idx];
1036 buf_priv = buf->dev_private;
1038 if ( mga_verify_iload( dev_priv, iload.dstorg, iload.length ) ) {
1039 mga_freelist_put( dev, buf );
1040 return DRM_ERR(EINVAL);
1043 WRAP_TEST_WITH_RETURN( dev_priv );
1045 mga_dma_dispatch_iload( dev, buf, iload.dstorg, iload.length );
1047 /* Make sure we restore the 3D state next time.
1049 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
1054 int mga_dma_blit( DRM_IOCTL_ARGS )
1057 drm_mga_private_t *dev_priv = dev->dev_private;
1058 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
1059 drm_mga_blit_t blit;
1062 LOCK_TEST_WITH_RETURN( dev, filp );
1064 DRM_COPY_FROM_USER_IOCTL( blit, (drm_mga_blit_t *)data, sizeof(blit) );
1066 if ( sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS )
1067 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
1069 if ( mga_verify_blit( dev_priv, blit.srcorg, blit.dstorg ) )
1070 return DRM_ERR(EINVAL);
1072 WRAP_TEST_WITH_RETURN( dev_priv );
1074 mga_dma_dispatch_blit( dev, &blit );
1076 /* Make sure we restore the 3D state next time.
1078 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
1083 int mga_getparam( DRM_IOCTL_ARGS )
1086 drm_mga_private_t *dev_priv = dev->dev_private;
1087 drm_mga_getparam_t param;
1091 DRM_ERROR( "%s called with no initialization\n", __FUNCTION__ );
1092 return DRM_ERR(EINVAL);
1095 DRM_COPY_FROM_USER_IOCTL( param, (drm_mga_getparam_t *)data,
1098 DRM_DEBUG( "pid=%d\n", DRM_CURRENTPID );
1100 switch( param.param ) {
1101 case MGA_PARAM_IRQ_NR:
1105 return DRM_ERR(EINVAL);
1108 if ( DRM_COPY_TO_USER( param.value, &value, sizeof(int) ) ) {
1109 DRM_ERROR( "copy_to_user\n" );
1110 return DRM_ERR(EFAULT);