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>
37 /* ================================================================
38 * DMA hardware state programming functions
41 static void mga_emit_clip_rect(drm_mga_private_t
*dev_priv
,
42 struct drm_clip_rect
*box
)
44 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
45 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
46 unsigned int pitch
= dev_priv
->front_pitch
;
51 /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
53 if (dev_priv
->chipset
>= MGA_CARD_TYPE_G400
) {
54 DMA_BLOCK(MGA_DWGCTL
, ctx
->dwgctl
,
55 MGA_LEN
+ MGA_EXEC
, 0x80000000,
56 MGA_DWGCTL
, ctx
->dwgctl
,
57 MGA_LEN
+ MGA_EXEC
, 0x80000000);
59 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
60 MGA_CXBNDRY
, ((box
->x2
- 1) << 16) | box
->x1
,
61 MGA_YTOP
, box
->y1
* pitch
, MGA_YBOT
, (box
->y2
- 1) * pitch
);
66 static __inline__
void mga_g200_emit_context(drm_mga_private_t
*dev_priv
)
68 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
69 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
74 DMA_BLOCK(MGA_DSTORG
, ctx
->dstorg
,
75 MGA_MACCESS
, ctx
->maccess
,
76 MGA_PLNWT
, ctx
->plnwt
, MGA_DWGCTL
, ctx
->dwgctl
);
78 DMA_BLOCK(MGA_ALPHACTRL
, ctx
->alphactrl
,
79 MGA_FOGCOL
, ctx
->fogcolor
,
80 MGA_WFLAG
, ctx
->wflag
, MGA_ZORG
, dev_priv
->depth_offset
);
82 DMA_BLOCK(MGA_FCOL
, ctx
->fcol
,
83 MGA_DMAPAD
, 0x00000000,
84 MGA_DMAPAD
, 0x00000000, MGA_DMAPAD
, 0x00000000);
89 static __inline__
void mga_g400_emit_context(drm_mga_private_t
*dev_priv
)
91 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
92 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
97 DMA_BLOCK(MGA_DSTORG
, ctx
->dstorg
,
98 MGA_MACCESS
, ctx
->maccess
,
99 MGA_PLNWT
, ctx
->plnwt
, MGA_DWGCTL
, ctx
->dwgctl
);
101 DMA_BLOCK(MGA_ALPHACTRL
, ctx
->alphactrl
,
102 MGA_FOGCOL
, ctx
->fogcolor
,
103 MGA_WFLAG
, ctx
->wflag
, MGA_ZORG
, dev_priv
->depth_offset
);
105 DMA_BLOCK(MGA_WFLAG1
, ctx
->wflag
,
106 MGA_TDUALSTAGE0
, ctx
->tdualstage0
,
107 MGA_TDUALSTAGE1
, ctx
->tdualstage1
, MGA_FCOL
, ctx
->fcol
);
109 DMA_BLOCK(MGA_STENCIL
, ctx
->stencil
,
110 MGA_STENCILCTL
, ctx
->stencilctl
,
111 MGA_DMAPAD
, 0x00000000, MGA_DMAPAD
, 0x00000000);
116 static __inline__
void mga_g200_emit_tex0(drm_mga_private_t
*dev_priv
)
118 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
119 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[0];
124 DMA_BLOCK(MGA_TEXCTL2
, tex
->texctl2
,
125 MGA_TEXCTL
, tex
->texctl
,
126 MGA_TEXFILTER
, tex
->texfilter
,
127 MGA_TEXBORDERCOL
, tex
->texbordercol
);
129 DMA_BLOCK(MGA_TEXORG
, tex
->texorg
,
130 MGA_TEXORG1
, tex
->texorg1
,
131 MGA_TEXORG2
, tex
->texorg2
, MGA_TEXORG3
, tex
->texorg3
);
133 DMA_BLOCK(MGA_TEXORG4
, tex
->texorg4
,
134 MGA_TEXWIDTH
, tex
->texwidth
,
135 MGA_TEXHEIGHT
, tex
->texheight
, MGA_WR24
, tex
->texwidth
);
137 DMA_BLOCK(MGA_WR34
, tex
->texheight
,
138 MGA_TEXTRANS
, 0x0000ffff,
139 MGA_TEXTRANSHIGH
, 0x0000ffff, MGA_DMAPAD
, 0x00000000);
144 static __inline__
void mga_g400_emit_tex0(drm_mga_private_t
*dev_priv
)
146 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
147 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[0];
150 /* printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
151 /* tex->texctl, tex->texctl2); */
155 DMA_BLOCK(MGA_TEXCTL2
, tex
->texctl2
| MGA_G400_TC2_MAGIC
,
156 MGA_TEXCTL
, tex
->texctl
,
157 MGA_TEXFILTER
, tex
->texfilter
,
158 MGA_TEXBORDERCOL
, tex
->texbordercol
);
160 DMA_BLOCK(MGA_TEXORG
, tex
->texorg
,
161 MGA_TEXORG1
, tex
->texorg1
,
162 MGA_TEXORG2
, tex
->texorg2
, MGA_TEXORG3
, tex
->texorg3
);
164 DMA_BLOCK(MGA_TEXORG4
, tex
->texorg4
,
165 MGA_TEXWIDTH
, tex
->texwidth
,
166 MGA_TEXHEIGHT
, tex
->texheight
, MGA_WR49
, 0x00000000);
168 DMA_BLOCK(MGA_WR57
, 0x00000000,
169 MGA_WR53
, 0x00000000,
170 MGA_WR61
, 0x00000000, MGA_WR52
, MGA_G400_WR_MAGIC
);
172 DMA_BLOCK(MGA_WR60
, MGA_G400_WR_MAGIC
,
173 MGA_WR54
, tex
->texwidth
| MGA_G400_WR_MAGIC
,
174 MGA_WR62
, tex
->texheight
| MGA_G400_WR_MAGIC
,
175 MGA_DMAPAD
, 0x00000000);
177 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
178 MGA_DMAPAD
, 0x00000000,
179 MGA_TEXTRANS
, 0x0000ffff, MGA_TEXTRANSHIGH
, 0x0000ffff);
184 static __inline__
void mga_g400_emit_tex1(drm_mga_private_t
*dev_priv
)
186 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
187 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[1];
190 /* printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg, */
191 /* tex->texctl, tex->texctl2); */
195 DMA_BLOCK(MGA_TEXCTL2
, (tex
->texctl2
|
198 MGA_TEXCTL
, tex
->texctl
,
199 MGA_TEXFILTER
, tex
->texfilter
,
200 MGA_TEXBORDERCOL
, tex
->texbordercol
);
202 DMA_BLOCK(MGA_TEXORG
, tex
->texorg
,
203 MGA_TEXORG1
, tex
->texorg1
,
204 MGA_TEXORG2
, tex
->texorg2
, MGA_TEXORG3
, tex
->texorg3
);
206 DMA_BLOCK(MGA_TEXORG4
, tex
->texorg4
,
207 MGA_TEXWIDTH
, tex
->texwidth
,
208 MGA_TEXHEIGHT
, tex
->texheight
, MGA_WR49
, 0x00000000);
210 DMA_BLOCK(MGA_WR57
, 0x00000000,
211 MGA_WR53
, 0x00000000,
212 MGA_WR61
, 0x00000000,
213 MGA_WR52
, tex
->texwidth
| MGA_G400_WR_MAGIC
);
215 DMA_BLOCK(MGA_WR60
, tex
->texheight
| MGA_G400_WR_MAGIC
,
216 MGA_TEXTRANS
, 0x0000ffff,
217 MGA_TEXTRANSHIGH
, 0x0000ffff,
218 MGA_TEXCTL2
, tex
->texctl2
| MGA_G400_TC2_MAGIC
);
223 static __inline__
void mga_g200_emit_pipe(drm_mga_private_t
*dev_priv
)
225 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
226 unsigned int pipe
= sarea_priv
->warp_pipe
;
231 DMA_BLOCK(MGA_WIADDR
, MGA_WMODE_SUSPEND
,
232 MGA_WVRTXSZ
, 0x00000007,
233 MGA_WFLAG
, 0x00000000, MGA_WR24
, 0x00000000);
235 DMA_BLOCK(MGA_WR25
, 0x00000100,
236 MGA_WR34
, 0x00000000,
237 MGA_WR42
, 0x0000ffff, MGA_WR60
, 0x0000ffff);
239 /* Padding required due to hardware bug.
241 DMA_BLOCK(MGA_DMAPAD
, 0xffffffff,
242 MGA_DMAPAD
, 0xffffffff,
243 MGA_DMAPAD
, 0xffffffff,
244 MGA_WIADDR
, (dev_priv
->warp_pipe_phys
[pipe
] |
245 MGA_WMODE_START
| dev_priv
->wagp_enable
));
250 static __inline__
void mga_g400_emit_pipe(drm_mga_private_t
*dev_priv
)
252 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
253 unsigned int pipe
= sarea_priv
->warp_pipe
;
256 /* printk("mga_g400_emit_pipe %x\n", pipe); */
260 DMA_BLOCK(MGA_WIADDR2
, MGA_WMODE_SUSPEND
,
261 MGA_DMAPAD
, 0x00000000,
262 MGA_DMAPAD
, 0x00000000, MGA_DMAPAD
, 0x00000000);
265 DMA_BLOCK(MGA_WVRTXSZ
, 0x00001e09,
266 MGA_DMAPAD
, 0x00000000,
267 MGA_DMAPAD
, 0x00000000, MGA_DMAPAD
, 0x00000000);
269 DMA_BLOCK(MGA_WACCEPTSEQ
, 0x00000000,
270 MGA_WACCEPTSEQ
, 0x00000000,
271 MGA_WACCEPTSEQ
, 0x00000000,
272 MGA_WACCEPTSEQ
, 0x1e000000);
274 if (dev_priv
->warp_pipe
& MGA_T2
) {
275 /* Flush the WARP pipe */
276 DMA_BLOCK(MGA_YDST
, 0x00000000,
277 MGA_FXLEFT
, 0x00000000,
278 MGA_FXRIGHT
, 0x00000001,
279 MGA_DWGCTL
, MGA_DWGCTL_FLUSH
);
281 DMA_BLOCK(MGA_LEN
+ MGA_EXEC
, 0x00000001,
282 MGA_DWGSYNC
, 0x00007000,
283 MGA_TEXCTL2
, MGA_G400_TC2_MAGIC
,
284 MGA_LEN
+ MGA_EXEC
, 0x00000000);
286 DMA_BLOCK(MGA_TEXCTL2
, (MGA_DUALTEX
|
288 MGA_LEN
+ MGA_EXEC
, 0x00000000,
289 MGA_TEXCTL2
, MGA_G400_TC2_MAGIC
,
290 MGA_DMAPAD
, 0x00000000);
293 DMA_BLOCK(MGA_WVRTXSZ
, 0x00001807,
294 MGA_DMAPAD
, 0x00000000,
295 MGA_DMAPAD
, 0x00000000, MGA_DMAPAD
, 0x00000000);
297 DMA_BLOCK(MGA_WACCEPTSEQ
, 0x00000000,
298 MGA_WACCEPTSEQ
, 0x00000000,
299 MGA_WACCEPTSEQ
, 0x00000000,
300 MGA_WACCEPTSEQ
, 0x18000000);
303 DMA_BLOCK(MGA_WFLAG
, 0x00000000,
304 MGA_WFLAG1
, 0x00000000,
305 MGA_WR56
, MGA_G400_WR56_MAGIC
, MGA_DMAPAD
, 0x00000000);
307 DMA_BLOCK(MGA_WR49
, 0x00000000, /* tex0 */
308 MGA_WR57
, 0x00000000, /* tex0 */
309 MGA_WR53
, 0x00000000, /* tex1 */
310 MGA_WR61
, 0x00000000); /* tex1 */
312 DMA_BLOCK(MGA_WR54
, MGA_G400_WR_MAGIC
, /* tex0 width */
313 MGA_WR62
, MGA_G400_WR_MAGIC
, /* tex0 height */
314 MGA_WR52
, MGA_G400_WR_MAGIC
, /* tex1 width */
315 MGA_WR60
, MGA_G400_WR_MAGIC
); /* tex1 height */
317 /* Padding required due to hardware bug */
318 DMA_BLOCK(MGA_DMAPAD
, 0xffffffff,
319 MGA_DMAPAD
, 0xffffffff,
320 MGA_DMAPAD
, 0xffffffff,
321 MGA_WIADDR2
, (dev_priv
->warp_pipe_phys
[pipe
] |
322 MGA_WMODE_START
| dev_priv
->wagp_enable
));
327 static void mga_g200_emit_state(drm_mga_private_t
*dev_priv
)
329 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
330 unsigned int dirty
= sarea_priv
->dirty
;
332 if (sarea_priv
->warp_pipe
!= dev_priv
->warp_pipe
) {
333 mga_g200_emit_pipe(dev_priv
);
334 dev_priv
->warp_pipe
= sarea_priv
->warp_pipe
;
337 if (dirty
& MGA_UPLOAD_CONTEXT
) {
338 mga_g200_emit_context(dev_priv
);
339 sarea_priv
->dirty
&= ~MGA_UPLOAD_CONTEXT
;
342 if (dirty
& MGA_UPLOAD_TEX0
) {
343 mga_g200_emit_tex0(dev_priv
);
344 sarea_priv
->dirty
&= ~MGA_UPLOAD_TEX0
;
348 static void mga_g400_emit_state(drm_mga_private_t
*dev_priv
)
350 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
351 unsigned int dirty
= sarea_priv
->dirty
;
352 int multitex
= sarea_priv
->warp_pipe
& MGA_T2
;
354 if (sarea_priv
->warp_pipe
!= dev_priv
->warp_pipe
) {
355 mga_g400_emit_pipe(dev_priv
);
356 dev_priv
->warp_pipe
= sarea_priv
->warp_pipe
;
359 if (dirty
& MGA_UPLOAD_CONTEXT
) {
360 mga_g400_emit_context(dev_priv
);
361 sarea_priv
->dirty
&= ~MGA_UPLOAD_CONTEXT
;
364 if (dirty
& MGA_UPLOAD_TEX0
) {
365 mga_g400_emit_tex0(dev_priv
);
366 sarea_priv
->dirty
&= ~MGA_UPLOAD_TEX0
;
369 if ((dirty
& MGA_UPLOAD_TEX1
) && multitex
) {
370 mga_g400_emit_tex1(dev_priv
);
371 sarea_priv
->dirty
&= ~MGA_UPLOAD_TEX1
;
375 /* ================================================================
376 * SAREA state verification
379 /* Disallow all write destinations except the front and backbuffer.
381 static int mga_verify_context(drm_mga_private_t
*dev_priv
)
383 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
384 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
386 if (ctx
->dstorg
!= dev_priv
->front_offset
&&
387 ctx
->dstorg
!= dev_priv
->back_offset
) {
388 DRM_ERROR("*** bad DSTORG: %x (front %x, back %x)\n\n",
389 ctx
->dstorg
, dev_priv
->front_offset
,
390 dev_priv
->back_offset
);
398 /* Disallow texture reads from PCI space.
400 static int mga_verify_tex(drm_mga_private_t
*dev_priv
, int unit
)
402 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
403 drm_mga_texture_regs_t
*tex
= &sarea_priv
->tex_state
[unit
];
406 org
= tex
->texorg
& (MGA_TEXORGMAP_MASK
| MGA_TEXORGACC_MASK
);
408 if (org
== (MGA_TEXORGMAP_SYSMEM
| MGA_TEXORGACC_PCI
)) {
409 DRM_ERROR("*** bad TEXORG: 0x%x, unit %d\n", tex
->texorg
, unit
);
417 static int mga_verify_state(drm_mga_private_t
*dev_priv
)
419 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
420 unsigned int dirty
= sarea_priv
->dirty
;
423 if (sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
424 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
426 if (dirty
& MGA_UPLOAD_CONTEXT
)
427 ret
|= mga_verify_context(dev_priv
);
429 if (dirty
& MGA_UPLOAD_TEX0
)
430 ret
|= mga_verify_tex(dev_priv
, 0);
432 if (dev_priv
->chipset
>= MGA_CARD_TYPE_G400
) {
433 if (dirty
& MGA_UPLOAD_TEX1
)
434 ret
|= mga_verify_tex(dev_priv
, 1);
436 if (dirty
& MGA_UPLOAD_PIPE
)
437 ret
|= (sarea_priv
->warp_pipe
> MGA_MAX_G400_PIPES
);
439 if (dirty
& MGA_UPLOAD_PIPE
)
440 ret
|= (sarea_priv
->warp_pipe
> MGA_MAX_G200_PIPES
);
446 static int mga_verify_iload(drm_mga_private_t
*dev_priv
,
447 unsigned int dstorg
, unsigned int length
)
449 if (dstorg
< dev_priv
->texture_offset
||
450 dstorg
+ length
> (dev_priv
->texture_offset
+
451 dev_priv
->texture_size
)) {
452 DRM_ERROR("*** bad iload DSTORG: 0x%x\n", dstorg
);
456 if (length
& MGA_ILOAD_MASK
) {
457 DRM_ERROR("*** bad iload length: 0x%x\n",
458 length
& MGA_ILOAD_MASK
);
465 static int mga_verify_blit(drm_mga_private_t
*dev_priv
,
466 unsigned int srcorg
, unsigned int dstorg
)
468 if ((srcorg
& 0x3) == (MGA_SRCACC_PCI
| MGA_SRCMAP_SYSMEM
) ||
469 (dstorg
& 0x3) == (MGA_SRCACC_PCI
| MGA_SRCMAP_SYSMEM
)) {
470 DRM_ERROR("*** bad blit: src=0x%x dst=0x%x\n", srcorg
, dstorg
);
476 /* ================================================================
480 static void mga_dma_dispatch_clear(struct drm_device
*dev
, drm_mga_clear_t
*clear
)
482 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
483 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
484 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
485 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
486 int nbox
= sarea_priv
->nbox
;
493 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
494 MGA_DMAPAD
, 0x00000000,
495 MGA_DWGSYNC
, 0x00007100, MGA_DWGSYNC
, 0x00007000);
499 for (i
= 0; i
< nbox
; i
++) {
500 struct drm_clip_rect
*box
= &pbox
[i
];
501 u32 height
= box
->y2
- box
->y1
;
503 DRM_DEBUG(" from=%d,%d to=%d,%d\n",
504 box
->x1
, box
->y1
, box
->x2
, box
->y2
);
506 if (clear
->flags
& MGA_FRONT
) {
509 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
510 MGA_PLNWT
, clear
->color_mask
,
511 MGA_YDSTLEN
, (box
->y1
<< 16) | height
,
512 MGA_FXBNDRY
, (box
->x2
<< 16) | box
->x1
);
514 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
515 MGA_FCOL
, clear
->clear_color
,
516 MGA_DSTORG
, dev_priv
->front_offset
,
517 MGA_DWGCTL
+ MGA_EXEC
, dev_priv
->clear_cmd
);
522 if (clear
->flags
& MGA_BACK
) {
525 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
526 MGA_PLNWT
, clear
->color_mask
,
527 MGA_YDSTLEN
, (box
->y1
<< 16) | height
,
528 MGA_FXBNDRY
, (box
->x2
<< 16) | box
->x1
);
530 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
531 MGA_FCOL
, clear
->clear_color
,
532 MGA_DSTORG
, dev_priv
->back_offset
,
533 MGA_DWGCTL
+ MGA_EXEC
, dev_priv
->clear_cmd
);
538 if (clear
->flags
& MGA_DEPTH
) {
541 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
542 MGA_PLNWT
, clear
->depth_mask
,
543 MGA_YDSTLEN
, (box
->y1
<< 16) | height
,
544 MGA_FXBNDRY
, (box
->x2
<< 16) | box
->x1
);
546 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
547 MGA_FCOL
, clear
->clear_depth
,
548 MGA_DSTORG
, dev_priv
->depth_offset
,
549 MGA_DWGCTL
+ MGA_EXEC
, dev_priv
->clear_cmd
);
558 /* Force reset of DWGCTL */
559 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
560 MGA_DMAPAD
, 0x00000000,
561 MGA_PLNWT
, ctx
->plnwt
, MGA_DWGCTL
, ctx
->dwgctl
);
568 static void mga_dma_dispatch_swap(struct drm_device
*dev
)
570 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
571 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
572 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
573 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
574 int nbox
= sarea_priv
->nbox
;
579 sarea_priv
->last_frame
.head
= dev_priv
->prim
.tail
;
580 sarea_priv
->last_frame
.wrap
= dev_priv
->prim
.last_wrap
;
584 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
585 MGA_DMAPAD
, 0x00000000,
586 MGA_DWGSYNC
, 0x00007100, MGA_DWGSYNC
, 0x00007000);
588 DMA_BLOCK(MGA_DSTORG
, dev_priv
->front_offset
,
589 MGA_MACCESS
, dev_priv
->maccess
,
590 MGA_SRCORG
, dev_priv
->back_offset
,
591 MGA_AR5
, dev_priv
->front_pitch
);
593 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
594 MGA_DMAPAD
, 0x00000000,
595 MGA_PLNWT
, 0xffffffff, MGA_DWGCTL
, MGA_DWGCTL_COPY
);
597 for (i
= 0; i
< nbox
; i
++) {
598 struct drm_clip_rect
*box
= &pbox
[i
];
599 u32 height
= box
->y2
- box
->y1
;
600 u32 start
= box
->y1
* dev_priv
->front_pitch
;
602 DRM_DEBUG(" from=%d,%d to=%d,%d\n",
603 box
->x1
, box
->y1
, box
->x2
, box
->y2
);
605 DMA_BLOCK(MGA_AR0
, start
+ box
->x2
- 1,
606 MGA_AR3
, start
+ box
->x1
,
607 MGA_FXBNDRY
, ((box
->x2
- 1) << 16) | box
->x1
,
608 MGA_YDSTLEN
+ MGA_EXEC
, (box
->y1
<< 16) | height
);
611 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
612 MGA_PLNWT
, ctx
->plnwt
,
613 MGA_SRCORG
, dev_priv
->front_offset
, MGA_DWGCTL
, ctx
->dwgctl
);
619 DRM_DEBUG("... done.\n");
622 static void mga_dma_dispatch_vertex(struct drm_device
*dev
, struct drm_buf
*buf
)
624 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
625 drm_mga_buf_priv_t
*buf_priv
= buf
->dev_private
;
626 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
627 u32 address
= (u32
) buf
->bus_address
;
628 u32 length
= (u32
) buf
->used
;
631 DRM_DEBUG("buf=%d used=%d\n", buf
->idx
, buf
->used
);
634 buf_priv
->dispatched
= 1;
636 MGA_EMIT_STATE(dev_priv
, sarea_priv
->dirty
);
639 if (i
< sarea_priv
->nbox
) {
640 mga_emit_clip_rect(dev_priv
,
641 &sarea_priv
->boxes
[i
]);
646 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
647 MGA_DMAPAD
, 0x00000000,
648 MGA_SECADDRESS
, (address
|
650 MGA_SECEND
, ((address
+ length
) |
651 dev_priv
->dma_access
));
654 } while (++i
< sarea_priv
->nbox
);
657 if (buf_priv
->discard
) {
658 AGE_BUFFER(buf_priv
);
661 buf_priv
->dispatched
= 0;
663 mga_freelist_put(dev
, buf
);
669 static void mga_dma_dispatch_indices(struct drm_device
*dev
, struct drm_buf
*buf
,
670 unsigned int start
, unsigned int end
)
672 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
673 drm_mga_buf_priv_t
*buf_priv
= buf
->dev_private
;
674 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
675 u32 address
= (u32
) buf
->bus_address
;
678 DRM_DEBUG("buf=%d start=%d end=%d\n", buf
->idx
, start
, end
);
681 buf_priv
->dispatched
= 1;
683 MGA_EMIT_STATE(dev_priv
, sarea_priv
->dirty
);
686 if (i
< sarea_priv
->nbox
) {
687 mga_emit_clip_rect(dev_priv
,
688 &sarea_priv
->boxes
[i
]);
693 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
694 MGA_DMAPAD
, 0x00000000,
695 MGA_SETUPADDRESS
, address
+ start
,
696 MGA_SETUPEND
, ((address
+ end
) |
697 dev_priv
->dma_access
));
700 } while (++i
< sarea_priv
->nbox
);
703 if (buf_priv
->discard
) {
704 AGE_BUFFER(buf_priv
);
707 buf_priv
->dispatched
= 0;
709 mga_freelist_put(dev
, buf
);
715 /* This copies a 64 byte aligned agp region to the frambuffer with a
716 * standard blit, the ioctl needs to do checking.
718 static void mga_dma_dispatch_iload(struct drm_device
*dev
, struct drm_buf
*buf
,
719 unsigned int dstorg
, unsigned int length
)
721 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
722 drm_mga_buf_priv_t
*buf_priv
= buf
->dev_private
;
723 drm_mga_context_regs_t
*ctx
= &dev_priv
->sarea_priv
->context_state
;
725 buf
->bus_address
| dev_priv
->dma_access
| MGA_SRCMAP_SYSMEM
;
728 DRM_DEBUG("buf=%d used=%d\n", buf
->idx
, buf
->used
);
734 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
735 MGA_DMAPAD
, 0x00000000,
736 MGA_DWGSYNC
, 0x00007100, MGA_DWGSYNC
, 0x00007000);
738 DMA_BLOCK(MGA_DSTORG
, dstorg
,
739 MGA_MACCESS
, 0x00000000, MGA_SRCORG
, srcorg
, MGA_AR5
, 64);
741 DMA_BLOCK(MGA_PITCH
, 64,
742 MGA_PLNWT
, 0xffffffff,
743 MGA_DMAPAD
, 0x00000000, MGA_DWGCTL
, MGA_DWGCTL_COPY
);
745 DMA_BLOCK(MGA_AR0
, 63,
747 MGA_FXBNDRY
, (63 << 16) | 0, MGA_YDSTLEN
+ MGA_EXEC
, y2
);
749 DMA_BLOCK(MGA_PLNWT
, ctx
->plnwt
,
750 MGA_SRCORG
, dev_priv
->front_offset
,
751 MGA_PITCH
, dev_priv
->front_pitch
, MGA_DWGSYNC
, 0x00007000);
755 AGE_BUFFER(buf_priv
);
759 buf_priv
->dispatched
= 0;
761 mga_freelist_put(dev
, buf
);
766 static void mga_dma_dispatch_blit(struct drm_device
*dev
, drm_mga_blit_t
*blit
)
768 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
769 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
770 drm_mga_context_regs_t
*ctx
= &sarea_priv
->context_state
;
771 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
772 int nbox
= sarea_priv
->nbox
;
779 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
780 MGA_DMAPAD
, 0x00000000,
781 MGA_DWGSYNC
, 0x00007100, MGA_DWGSYNC
, 0x00007000);
783 DMA_BLOCK(MGA_DWGCTL
, MGA_DWGCTL_COPY
,
784 MGA_PLNWT
, blit
->planemask
,
785 MGA_SRCORG
, blit
->srcorg
, MGA_DSTORG
, blit
->dstorg
);
787 DMA_BLOCK(MGA_SGN
, scandir
,
788 MGA_MACCESS
, dev_priv
->maccess
,
789 MGA_AR5
, blit
->ydir
* blit
->src_pitch
,
790 MGA_PITCH
, blit
->dst_pitch
);
792 for (i
= 0; i
< nbox
; i
++) {
793 int srcx
= pbox
[i
].x1
+ blit
->delta_sx
;
794 int srcy
= pbox
[i
].y1
+ blit
->delta_sy
;
795 int dstx
= pbox
[i
].x1
+ blit
->delta_dx
;
796 int dsty
= pbox
[i
].y1
+ blit
->delta_dy
;
797 int h
= pbox
[i
].y2
- pbox
[i
].y1
;
798 int w
= pbox
[i
].x2
- pbox
[i
].x1
- 1;
801 if (blit
->ydir
== -1)
802 srcy
= blit
->height
- srcy
- 1;
804 start
= srcy
* blit
->src_pitch
+ srcx
;
806 DMA_BLOCK(MGA_AR0
, start
+ w
,
808 MGA_FXBNDRY
, ((dstx
+ w
) << 16) | (dstx
& 0xffff),
809 MGA_YDSTLEN
+ MGA_EXEC
, (dsty
<< 16) | h
);
812 /* Do something to flush AGP?
815 /* Force reset of DWGCTL */
816 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
817 MGA_PLNWT
, ctx
->plnwt
,
818 MGA_PITCH
, dev_priv
->front_pitch
, MGA_DWGCTL
, ctx
->dwgctl
);
823 /* ================================================================
827 static int mga_dma_clear(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
829 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
830 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
831 drm_mga_clear_t
*clear
= data
;
833 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
835 if (sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
836 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
838 WRAP_TEST_WITH_RETURN(dev_priv
);
840 mga_dma_dispatch_clear(dev
, clear
);
842 /* Make sure we restore the 3D state next time.
844 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
849 static int mga_dma_swap(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
851 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
852 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
854 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
856 if (sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
857 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
859 WRAP_TEST_WITH_RETURN(dev_priv
);
861 mga_dma_dispatch_swap(dev
);
863 /* Make sure we restore the 3D state next time.
865 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
870 static int mga_dma_vertex(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
872 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
873 struct drm_device_dma
*dma
= dev
->dma
;
875 drm_mga_buf_priv_t
*buf_priv
;
876 drm_mga_vertex_t
*vertex
= data
;
878 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
880 if (vertex
->idx
< 0 || vertex
->idx
> dma
->buf_count
)
882 buf
= dma
->buflist
[vertex
->idx
];
883 buf_priv
= buf
->dev_private
;
885 buf
->used
= vertex
->used
;
886 buf_priv
->discard
= vertex
->discard
;
888 if (!mga_verify_state(dev_priv
)) {
889 if (vertex
->discard
) {
890 if (buf_priv
->dispatched
== 1)
891 AGE_BUFFER(buf_priv
);
892 buf_priv
->dispatched
= 0;
893 mga_freelist_put(dev
, buf
);
898 WRAP_TEST_WITH_RETURN(dev_priv
);
900 mga_dma_dispatch_vertex(dev
, buf
);
905 static int mga_dma_indices(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
907 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
908 struct drm_device_dma
*dma
= dev
->dma
;
910 drm_mga_buf_priv_t
*buf_priv
;
911 drm_mga_indices_t
*indices
= data
;
913 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
915 if (indices
->idx
< 0 || indices
->idx
> dma
->buf_count
)
918 buf
= dma
->buflist
[indices
->idx
];
919 buf_priv
= buf
->dev_private
;
921 buf_priv
->discard
= indices
->discard
;
923 if (!mga_verify_state(dev_priv
)) {
924 if (indices
->discard
) {
925 if (buf_priv
->dispatched
== 1)
926 AGE_BUFFER(buf_priv
);
927 buf_priv
->dispatched
= 0;
928 mga_freelist_put(dev
, buf
);
933 WRAP_TEST_WITH_RETURN(dev_priv
);
935 mga_dma_dispatch_indices(dev
, buf
, indices
->start
, indices
->end
);
940 static int mga_dma_iload(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
942 struct drm_device_dma
*dma
= dev
->dma
;
943 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
945 drm_mga_iload_t
*iload
= data
;
948 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
951 if (mga_do_wait_for_idle(dev_priv
) < 0) {
953 DRM_INFO("-EBUSY\n");
957 if (iload
->idx
< 0 || iload
->idx
> dma
->buf_count
)
960 buf
= dma
->buflist
[iload
->idx
];
962 if (mga_verify_iload(dev_priv
, iload
->dstorg
, iload
->length
)) {
963 mga_freelist_put(dev
, buf
);
967 WRAP_TEST_WITH_RETURN(dev_priv
);
969 mga_dma_dispatch_iload(dev
, buf
, iload
->dstorg
, iload
->length
);
971 /* Make sure we restore the 3D state next time.
973 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
978 static int mga_dma_blit(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
980 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
981 drm_mga_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
982 drm_mga_blit_t
*blit
= data
;
985 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
987 if (sarea_priv
->nbox
> MGA_NR_SAREA_CLIPRECTS
)
988 sarea_priv
->nbox
= MGA_NR_SAREA_CLIPRECTS
;
990 if (mga_verify_blit(dev_priv
, blit
->srcorg
, blit
->dstorg
))
993 WRAP_TEST_WITH_RETURN(dev_priv
);
995 mga_dma_dispatch_blit(dev
, blit
);
997 /* Make sure we restore the 3D state next time.
999 dev_priv
->sarea_priv
->dirty
|= MGA_UPLOAD_CONTEXT
;
1004 int mga_getparam(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1006 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
1007 drm_mga_getparam_t
*param
= data
;
1011 DRM_ERROR("called with no initialization\n");
1015 DRM_DEBUG("pid=%d\n", task_pid_nr(current
));
1017 switch (param
->param
) {
1018 case MGA_PARAM_IRQ_NR
:
1019 value
= dev
->pdev
->irq
;
1021 case MGA_PARAM_CARD_TYPE
:
1022 value
= dev_priv
->chipset
;
1028 if (copy_to_user(param
->value
, &value
, sizeof(int))) {
1029 DRM_ERROR("copy_to_user\n");
1036 static int mga_set_fence(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1038 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
1043 DRM_ERROR("called with no initialization\n");
1047 DRM_DEBUG("pid=%d\n", task_pid_nr(current
));
1049 /* I would normal do this assignment in the declaration of fence,
1050 * but dev_priv may be NULL.
1053 *fence
= dev_priv
->next_fence_to_post
;
1054 dev_priv
->next_fence_to_post
++;
1057 DMA_BLOCK(MGA_DMAPAD
, 0x00000000,
1058 MGA_DMAPAD
, 0x00000000,
1059 MGA_DMAPAD
, 0x00000000, MGA_SOFTRAP
, 0x00000000);
1065 static int mga_wait_fence(struct drm_device
*dev
, void *data
, struct drm_file
*
1068 drm_mga_private_t
*dev_priv
= dev
->dev_private
;
1072 DRM_ERROR("called with no initialization\n");
1076 DRM_DEBUG("pid=%d\n", task_pid_nr(current
));
1078 mga_driver_fence_wait(dev
, fence
);
1082 const struct drm_ioctl_desc mga_ioctls
[] = {
1083 DRM_IOCTL_DEF_DRV(MGA_INIT
, mga_dma_init
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1084 DRM_IOCTL_DEF_DRV(MGA_FLUSH
, mga_dma_flush
, DRM_AUTH
),
1085 DRM_IOCTL_DEF_DRV(MGA_RESET
, mga_dma_reset
, DRM_AUTH
),
1086 DRM_IOCTL_DEF_DRV(MGA_SWAP
, mga_dma_swap
, DRM_AUTH
),
1087 DRM_IOCTL_DEF_DRV(MGA_CLEAR
, mga_dma_clear
, DRM_AUTH
),
1088 DRM_IOCTL_DEF_DRV(MGA_VERTEX
, mga_dma_vertex
, DRM_AUTH
),
1089 DRM_IOCTL_DEF_DRV(MGA_INDICES
, mga_dma_indices
, DRM_AUTH
),
1090 DRM_IOCTL_DEF_DRV(MGA_ILOAD
, mga_dma_iload
, DRM_AUTH
),
1091 DRM_IOCTL_DEF_DRV(MGA_BLIT
, mga_dma_blit
, DRM_AUTH
),
1092 DRM_IOCTL_DEF_DRV(MGA_GETPARAM
, mga_getparam
, DRM_AUTH
),
1093 DRM_IOCTL_DEF_DRV(MGA_SET_FENCE
, mga_set_fence
, DRM_AUTH
),
1094 DRM_IOCTL_DEF_DRV(MGA_WAIT_FENCE
, mga_wait_fence
, DRM_AUTH
),
1095 DRM_IOCTL_DEF_DRV(MGA_DMA_BOOTSTRAP
, mga_dma_bootstrap
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1098 int mga_max_ioctl
= ARRAY_SIZE(mga_ioctls
);