blob: 9c145143ad0f7a451852a0238d46873398e61083 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/* mga_state.c -- State support for MGA G200/G400 -*- linux-c -*-
2 * Created: Thu Jan 27 02:53:43 2000 by jhartmann@precisioninsight.com
3 *
4 * Copyright 1999 Precision Insight, Inc., Cedar Park, Texas.
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
6 * All Rights Reserved.
7 *
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
14 *
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
17 * Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
23 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
24 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
25 * OTHER DEALINGS IN THE SOFTWARE.
26 *
27 * Authors:
28 * Jeff Hartmann <jhartmann@valinux.com>
29 * Keith Whitwell <keith@tungstengraphics.com>
30 *
31 * Rewritten by:
32 * Gareth Hughes <gareth@valinux.com>
33 */
34
David Howells760285e2012-10-02 18:01:07 +010035#include <drm/drmP.h>
36#include <drm/mga_drm.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070037#include "mga_drv.h"
38
39/* ================================================================
40 * DMA hardware state programming functions
41 */
42
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +020043static void mga_emit_clip_rect(drm_mga_private_t *dev_priv,
44 struct drm_clip_rect *box)
Linus Torvalds1da177e2005-04-16 15:20:36 -070045{
46 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
47 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
48 unsigned int pitch = dev_priv->front_pitch;
49 DMA_LOCALS;
50
Dave Airlieb5e89ed2005-09-25 14:28:13 +100051 BEGIN_DMA(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -070052
53 /* Force reset of DWGCTL on G400 (eliminates clip disable bit).
54 */
Dave Airliee29971f2005-10-20 23:49:00 +010055 if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
Dave Airlie6795c982005-07-10 18:20:09 +100056 DMA_BLOCK(MGA_DWGCTL, ctx->dwgctl,
57 MGA_LEN + MGA_EXEC, 0x80000000,
58 MGA_DWGCTL, ctx->dwgctl,
59 MGA_LEN + MGA_EXEC, 0x80000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -070060 }
Dave Airlie6795c982005-07-10 18:20:09 +100061 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
62 MGA_CXBNDRY, ((box->x2 - 1) << 16) | box->x1,
Dave Airlieb5e89ed2005-09-25 14:28:13 +100063 MGA_YTOP, box->y1 * pitch, MGA_YBOT, (box->y2 - 1) * pitch);
Linus Torvalds1da177e2005-04-16 15:20:36 -070064
65 ADVANCE_DMA();
66}
67
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +020068static __inline__ void mga_g200_emit_context(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070069{
70 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
71 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
72 DMA_LOCALS;
73
Dave Airlieb5e89ed2005-09-25 14:28:13 +100074 BEGIN_DMA(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -070075
Dave Airlieb5e89ed2005-09-25 14:28:13 +100076 DMA_BLOCK(MGA_DSTORG, ctx->dstorg,
77 MGA_MACCESS, ctx->maccess,
78 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -070079
Dave Airlieb5e89ed2005-09-25 14:28:13 +100080 DMA_BLOCK(MGA_ALPHACTRL, ctx->alphactrl,
81 MGA_FOGCOL, ctx->fogcolor,
82 MGA_WFLAG, ctx->wflag, MGA_ZORG, dev_priv->depth_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -070083
Dave Airlieb5e89ed2005-09-25 14:28:13 +100084 DMA_BLOCK(MGA_FCOL, ctx->fcol,
85 MGA_DMAPAD, 0x00000000,
86 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -070087
88 ADVANCE_DMA();
89}
90
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +020091static __inline__ void mga_g400_emit_context(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -070092{
93 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
94 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
95 DMA_LOCALS;
96
Dave Airlieb5e89ed2005-09-25 14:28:13 +100097 BEGIN_DMA(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -070098
Dave Airlieb5e89ed2005-09-25 14:28:13 +100099 DMA_BLOCK(MGA_DSTORG, ctx->dstorg,
100 MGA_MACCESS, ctx->maccess,
101 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700102
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000103 DMA_BLOCK(MGA_ALPHACTRL, ctx->alphactrl,
104 MGA_FOGCOL, ctx->fogcolor,
105 MGA_WFLAG, ctx->wflag, MGA_ZORG, dev_priv->depth_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000107 DMA_BLOCK(MGA_WFLAG1, ctx->wflag,
108 MGA_TDUALSTAGE0, ctx->tdualstage0,
109 MGA_TDUALSTAGE1, ctx->tdualstage1, MGA_FCOL, ctx->fcol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700110
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000111 DMA_BLOCK(MGA_STENCIL, ctx->stencil,
112 MGA_STENCILCTL, ctx->stencilctl,
113 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700114
115 ADVANCE_DMA();
116}
117
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200118static __inline__ void mga_g200_emit_tex0(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700119{
120 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
121 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
122 DMA_LOCALS;
123
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000124 BEGIN_DMA(4);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700125
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000126 DMA_BLOCK(MGA_TEXCTL2, tex->texctl2,
127 MGA_TEXCTL, tex->texctl,
128 MGA_TEXFILTER, tex->texfilter,
129 MGA_TEXBORDERCOL, tex->texbordercol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700130
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000131 DMA_BLOCK(MGA_TEXORG, tex->texorg,
132 MGA_TEXORG1, tex->texorg1,
133 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000135 DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
136 MGA_TEXWIDTH, tex->texwidth,
137 MGA_TEXHEIGHT, tex->texheight, MGA_WR24, tex->texwidth);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000139 DMA_BLOCK(MGA_WR34, tex->texheight,
140 MGA_TEXTRANS, 0x0000ffff,
141 MGA_TEXTRANSHIGH, 0x0000ffff, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700142
143 ADVANCE_DMA();
144}
145
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200146static __inline__ void mga_g400_emit_tex0(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700147{
148 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
149 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[0];
150 DMA_LOCALS;
151
Dave Airliebc5f4522007-11-05 12:50:58 +1000152/* printk("mga_g400_emit_tex0 %x %x %x\n", tex->texorg, */
153/* tex->texctl, tex->texctl2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700154
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000155 BEGIN_DMA(6);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700156
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000157 DMA_BLOCK(MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC,
158 MGA_TEXCTL, tex->texctl,
159 MGA_TEXFILTER, tex->texfilter,
160 MGA_TEXBORDERCOL, tex->texbordercol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700161
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000162 DMA_BLOCK(MGA_TEXORG, tex->texorg,
163 MGA_TEXORG1, tex->texorg1,
164 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700165
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000166 DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
167 MGA_TEXWIDTH, tex->texwidth,
168 MGA_TEXHEIGHT, tex->texheight, MGA_WR49, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700169
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000170 DMA_BLOCK(MGA_WR57, 0x00000000,
171 MGA_WR53, 0x00000000,
172 MGA_WR61, 0x00000000, MGA_WR52, MGA_G400_WR_MAGIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700173
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000174 DMA_BLOCK(MGA_WR60, MGA_G400_WR_MAGIC,
175 MGA_WR54, tex->texwidth | MGA_G400_WR_MAGIC,
176 MGA_WR62, tex->texheight | MGA_G400_WR_MAGIC,
177 MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700178
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000179 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
180 MGA_DMAPAD, 0x00000000,
181 MGA_TEXTRANS, 0x0000ffff, MGA_TEXTRANSHIGH, 0x0000ffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700182
183 ADVANCE_DMA();
184}
185
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200186static __inline__ void mga_g400_emit_tex1(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700187{
188 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
189 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[1];
190 DMA_LOCALS;
191
Dave Airliebc5f4522007-11-05 12:50:58 +1000192/* printk("mga_g400_emit_tex1 %x %x %x\n", tex->texorg, */
193/* tex->texctl, tex->texctl2); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700194
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000195 BEGIN_DMA(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700196
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000197 DMA_BLOCK(MGA_TEXCTL2, (tex->texctl2 |
198 MGA_MAP1_ENABLE |
199 MGA_G400_TC2_MAGIC),
200 MGA_TEXCTL, tex->texctl,
201 MGA_TEXFILTER, tex->texfilter,
202 MGA_TEXBORDERCOL, tex->texbordercol);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700203
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000204 DMA_BLOCK(MGA_TEXORG, tex->texorg,
205 MGA_TEXORG1, tex->texorg1,
206 MGA_TEXORG2, tex->texorg2, MGA_TEXORG3, tex->texorg3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700207
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000208 DMA_BLOCK(MGA_TEXORG4, tex->texorg4,
209 MGA_TEXWIDTH, tex->texwidth,
210 MGA_TEXHEIGHT, tex->texheight, MGA_WR49, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700211
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000212 DMA_BLOCK(MGA_WR57, 0x00000000,
213 MGA_WR53, 0x00000000,
214 MGA_WR61, 0x00000000,
215 MGA_WR52, tex->texwidth | MGA_G400_WR_MAGIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700216
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000217 DMA_BLOCK(MGA_WR60, tex->texheight | MGA_G400_WR_MAGIC,
218 MGA_TEXTRANS, 0x0000ffff,
219 MGA_TEXTRANSHIGH, 0x0000ffff,
220 MGA_TEXCTL2, tex->texctl2 | MGA_G400_TC2_MAGIC);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700221
222 ADVANCE_DMA();
223}
224
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200225static __inline__ void mga_g200_emit_pipe(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700226{
227 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
228 unsigned int pipe = sarea_priv->warp_pipe;
229 DMA_LOCALS;
230
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000231 BEGIN_DMA(3);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700232
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000233 DMA_BLOCK(MGA_WIADDR, MGA_WMODE_SUSPEND,
234 MGA_WVRTXSZ, 0x00000007,
235 MGA_WFLAG, 0x00000000, MGA_WR24, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700236
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000237 DMA_BLOCK(MGA_WR25, 0x00000100,
238 MGA_WR34, 0x00000000,
239 MGA_WR42, 0x0000ffff, MGA_WR60, 0x0000ffff);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700240
Anand Gadiyarfd589a82009-07-16 17:13:03 +0200241 /* Padding required due to hardware bug.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700242 */
Dave Airlie6795c982005-07-10 18:20:09 +1000243 DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
244 MGA_DMAPAD, 0xffffffff,
245 MGA_DMAPAD, 0xffffffff,
246 MGA_WIADDR, (dev_priv->warp_pipe_phys[pipe] |
247 MGA_WMODE_START | dev_priv->wagp_enable));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700248
249 ADVANCE_DMA();
250}
251
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200252static __inline__ void mga_g400_emit_pipe(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700253{
254 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
255 unsigned int pipe = sarea_priv->warp_pipe;
256 DMA_LOCALS;
257
Dave Airliebc5f4522007-11-05 12:50:58 +1000258/* printk("mga_g400_emit_pipe %x\n", pipe); */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700259
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000260 BEGIN_DMA(10);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700261
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000262 DMA_BLOCK(MGA_WIADDR2, MGA_WMODE_SUSPEND,
263 MGA_DMAPAD, 0x00000000,
264 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700265
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000266 if (pipe & MGA_T2) {
267 DMA_BLOCK(MGA_WVRTXSZ, 0x00001e09,
268 MGA_DMAPAD, 0x00000000,
269 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700270
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000271 DMA_BLOCK(MGA_WACCEPTSEQ, 0x00000000,
272 MGA_WACCEPTSEQ, 0x00000000,
273 MGA_WACCEPTSEQ, 0x00000000,
274 MGA_WACCEPTSEQ, 0x1e000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700275 } else {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000276 if (dev_priv->warp_pipe & MGA_T2) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700277 /* Flush the WARP pipe */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000278 DMA_BLOCK(MGA_YDST, 0x00000000,
279 MGA_FXLEFT, 0x00000000,
280 MGA_FXRIGHT, 0x00000001,
281 MGA_DWGCTL, MGA_DWGCTL_FLUSH);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700282
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000283 DMA_BLOCK(MGA_LEN + MGA_EXEC, 0x00000001,
284 MGA_DWGSYNC, 0x00007000,
285 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
286 MGA_LEN + MGA_EXEC, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700287
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000288 DMA_BLOCK(MGA_TEXCTL2, (MGA_DUALTEX |
289 MGA_G400_TC2_MAGIC),
290 MGA_LEN + MGA_EXEC, 0x00000000,
291 MGA_TEXCTL2, MGA_G400_TC2_MAGIC,
292 MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700293 }
294
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000295 DMA_BLOCK(MGA_WVRTXSZ, 0x00001807,
296 MGA_DMAPAD, 0x00000000,
297 MGA_DMAPAD, 0x00000000, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700298
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000299 DMA_BLOCK(MGA_WACCEPTSEQ, 0x00000000,
300 MGA_WACCEPTSEQ, 0x00000000,
301 MGA_WACCEPTSEQ, 0x00000000,
302 MGA_WACCEPTSEQ, 0x18000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700303 }
304
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000305 DMA_BLOCK(MGA_WFLAG, 0x00000000,
306 MGA_WFLAG1, 0x00000000,
307 MGA_WR56, MGA_G400_WR56_MAGIC, MGA_DMAPAD, 0x00000000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700308
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000309 DMA_BLOCK(MGA_WR49, 0x00000000, /* tex0 */
310 MGA_WR57, 0x00000000, /* tex0 */
311 MGA_WR53, 0x00000000, /* tex1 */
312 MGA_WR61, 0x00000000); /* tex1 */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700313
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000314 DMA_BLOCK(MGA_WR54, MGA_G400_WR_MAGIC, /* tex0 width */
315 MGA_WR62, MGA_G400_WR_MAGIC, /* tex0 height */
316 MGA_WR52, MGA_G400_WR_MAGIC, /* tex1 width */
317 MGA_WR60, MGA_G400_WR_MAGIC); /* tex1 height */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700318
Anand Gadiyarfd589a82009-07-16 17:13:03 +0200319 /* Padding required due to hardware bug */
Dave Airlie6795c982005-07-10 18:20:09 +1000320 DMA_BLOCK(MGA_DMAPAD, 0xffffffff,
321 MGA_DMAPAD, 0xffffffff,
322 MGA_DMAPAD, 0xffffffff,
323 MGA_WIADDR2, (dev_priv->warp_pipe_phys[pipe] |
324 MGA_WMODE_START | dev_priv->wagp_enable));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700325
326 ADVANCE_DMA();
327}
328
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200329static void mga_g200_emit_state(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700330{
331 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
332 unsigned int dirty = sarea_priv->dirty;
333
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000334 if (sarea_priv->warp_pipe != dev_priv->warp_pipe) {
335 mga_g200_emit_pipe(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700336 dev_priv->warp_pipe = sarea_priv->warp_pipe;
337 }
338
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000339 if (dirty & MGA_UPLOAD_CONTEXT) {
340 mga_g200_emit_context(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700341 sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
342 }
343
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000344 if (dirty & MGA_UPLOAD_TEX0) {
345 mga_g200_emit_tex0(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700346 sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
347 }
348}
349
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200350static void mga_g400_emit_state(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700351{
352 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
353 unsigned int dirty = sarea_priv->dirty;
354 int multitex = sarea_priv->warp_pipe & MGA_T2;
355
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000356 if (sarea_priv->warp_pipe != dev_priv->warp_pipe) {
357 mga_g400_emit_pipe(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700358 dev_priv->warp_pipe = sarea_priv->warp_pipe;
359 }
360
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000361 if (dirty & MGA_UPLOAD_CONTEXT) {
362 mga_g400_emit_context(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363 sarea_priv->dirty &= ~MGA_UPLOAD_CONTEXT;
364 }
365
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000366 if (dirty & MGA_UPLOAD_TEX0) {
367 mga_g400_emit_tex0(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368 sarea_priv->dirty &= ~MGA_UPLOAD_TEX0;
369 }
370
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000371 if ((dirty & MGA_UPLOAD_TEX1) && multitex) {
372 mga_g400_emit_tex1(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700373 sarea_priv->dirty &= ~MGA_UPLOAD_TEX1;
374 }
375}
376
Linus Torvalds1da177e2005-04-16 15:20:36 -0700377/* ================================================================
378 * SAREA state verification
379 */
380
381/* Disallow all write destinations except the front and backbuffer.
382 */
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200383static int mga_verify_context(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700384{
385 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
386 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
387
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000388 if (ctx->dstorg != dev_priv->front_offset &&
389 ctx->dstorg != dev_priv->back_offset) {
390 DRM_ERROR("*** bad DSTORG: %x (front %x, back %x)\n\n",
391 ctx->dstorg, dev_priv->front_offset,
392 dev_priv->back_offset);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700393 ctx->dstorg = 0;
Eric Anholt20caafa2007-08-25 19:22:43 +1000394 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700395 }
396
397 return 0;
398}
399
400/* Disallow texture reads from PCI space.
401 */
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200402static int mga_verify_tex(drm_mga_private_t *dev_priv, int unit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700403{
404 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
405 drm_mga_texture_regs_t *tex = &sarea_priv->tex_state[unit];
406 unsigned int org;
407
408 org = tex->texorg & (MGA_TEXORGMAP_MASK | MGA_TEXORGACC_MASK);
409
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000410 if (org == (MGA_TEXORGMAP_SYSMEM | MGA_TEXORGACC_PCI)) {
411 DRM_ERROR("*** bad TEXORG: 0x%x, unit %d\n", tex->texorg, unit);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 tex->texorg = 0;
Eric Anholt20caafa2007-08-25 19:22:43 +1000413 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700414 }
415
416 return 0;
417}
418
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200419static int mga_verify_state(drm_mga_private_t *dev_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700420{
421 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
422 unsigned int dirty = sarea_priv->dirty;
423 int ret = 0;
424
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000425 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700426 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
427
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000428 if (dirty & MGA_UPLOAD_CONTEXT)
429 ret |= mga_verify_context(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700430
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000431 if (dirty & MGA_UPLOAD_TEX0)
432 ret |= mga_verify_tex(dev_priv, 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700433
Dave Airlie6795c982005-07-10 18:20:09 +1000434 if (dev_priv->chipset >= MGA_CARD_TYPE_G400) {
435 if (dirty & MGA_UPLOAD_TEX1)
436 ret |= mga_verify_tex(dev_priv, 1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700437
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000438 if (dirty & MGA_UPLOAD_PIPE)
439 ret |= (sarea_priv->warp_pipe > MGA_MAX_G400_PIPES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700440 } else {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000441 if (dirty & MGA_UPLOAD_PIPE)
442 ret |= (sarea_priv->warp_pipe > MGA_MAX_G200_PIPES);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700443 }
444
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000445 return (ret == 0);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700446}
447
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200448static int mga_verify_iload(drm_mga_private_t *dev_priv,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000449 unsigned int dstorg, unsigned int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700450{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000451 if (dstorg < dev_priv->texture_offset ||
452 dstorg + length > (dev_priv->texture_offset +
453 dev_priv->texture_size)) {
454 DRM_ERROR("*** bad iload DSTORG: 0x%x\n", dstorg);
Eric Anholt20caafa2007-08-25 19:22:43 +1000455 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700456 }
457
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000458 if (length & MGA_ILOAD_MASK) {
459 DRM_ERROR("*** bad iload length: 0x%x\n",
460 length & MGA_ILOAD_MASK);
Eric Anholt20caafa2007-08-25 19:22:43 +1000461 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700462 }
463
464 return 0;
465}
466
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200467static int mga_verify_blit(drm_mga_private_t *dev_priv,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000468 unsigned int srcorg, unsigned int dstorg)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700469{
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000470 if ((srcorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM) ||
471 (dstorg & 0x3) == (MGA_SRCACC_PCI | MGA_SRCMAP_SYSMEM)) {
472 DRM_ERROR("*** bad blit: src=0x%x dst=0x%x\n", srcorg, dstorg);
Eric Anholt20caafa2007-08-25 19:22:43 +1000473 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700474 }
475 return 0;
476}
477
Linus Torvalds1da177e2005-04-16 15:20:36 -0700478/* ================================================================
479 *
480 */
481
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200482static void mga_dma_dispatch_clear(struct drm_device *dev, drm_mga_clear_t *clear)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700483{
484 drm_mga_private_t *dev_priv = dev->dev_private;
485 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
486 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
Dave Airlieeddca552007-07-11 16:09:54 +1000487 struct drm_clip_rect *pbox = sarea_priv->boxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700488 int nbox = sarea_priv->nbox;
489 int i;
490 DMA_LOCALS;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000491 DRM_DEBUG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000493 BEGIN_DMA(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700494
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000495 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
496 MGA_DMAPAD, 0x00000000,
497 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
499 ADVANCE_DMA();
500
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000501 for (i = 0; i < nbox; i++) {
Dave Airlieeddca552007-07-11 16:09:54 +1000502 struct drm_clip_rect *box = &pbox[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700503 u32 height = box->y2 - box->y1;
504
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000505 DRM_DEBUG(" from=%d,%d to=%d,%d\n",
506 box->x1, box->y1, box->x2, box->y2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700507
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000508 if (clear->flags & MGA_FRONT) {
509 BEGIN_DMA(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000511 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
512 MGA_PLNWT, clear->color_mask,
513 MGA_YDSTLEN, (box->y1 << 16) | height,
514 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000516 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
517 MGA_FCOL, clear->clear_color,
518 MGA_DSTORG, dev_priv->front_offset,
519 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700520
521 ADVANCE_DMA();
522 }
523
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000524 if (clear->flags & MGA_BACK) {
525 BEGIN_DMA(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700526
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000527 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
528 MGA_PLNWT, clear->color_mask,
529 MGA_YDSTLEN, (box->y1 << 16) | height,
530 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700531
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000532 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
533 MGA_FCOL, clear->clear_color,
534 MGA_DSTORG, dev_priv->back_offset,
535 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700536
537 ADVANCE_DMA();
538 }
539
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000540 if (clear->flags & MGA_DEPTH) {
541 BEGIN_DMA(2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700542
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000543 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
544 MGA_PLNWT, clear->depth_mask,
545 MGA_YDSTLEN, (box->y1 << 16) | height,
546 MGA_FXBNDRY, (box->x2 << 16) | box->x1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700547
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000548 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
549 MGA_FCOL, clear->clear_depth,
550 MGA_DSTORG, dev_priv->depth_offset,
551 MGA_DWGCTL + MGA_EXEC, dev_priv->clear_cmd);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700552
553 ADVANCE_DMA();
554 }
555
556 }
557
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000558 BEGIN_DMA(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700559
560 /* Force reset of DWGCTL */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000561 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
562 MGA_DMAPAD, 0x00000000,
563 MGA_PLNWT, ctx->plnwt, MGA_DWGCTL, ctx->dwgctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700564
565 ADVANCE_DMA();
566
567 FLUSH_DMA();
568}
569
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200570static void mga_dma_dispatch_swap(struct drm_device *dev)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700571{
572 drm_mga_private_t *dev_priv = dev->dev_private;
573 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
574 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
Dave Airlieeddca552007-07-11 16:09:54 +1000575 struct drm_clip_rect *pbox = sarea_priv->boxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700576 int nbox = sarea_priv->nbox;
577 int i;
578 DMA_LOCALS;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000579 DRM_DEBUG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700580
581 sarea_priv->last_frame.head = dev_priv->prim.tail;
582 sarea_priv->last_frame.wrap = dev_priv->prim.last_wrap;
583
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000584 BEGIN_DMA(4 + nbox);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700585
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000586 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
587 MGA_DMAPAD, 0x00000000,
588 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700589
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000590 DMA_BLOCK(MGA_DSTORG, dev_priv->front_offset,
591 MGA_MACCESS, dev_priv->maccess,
592 MGA_SRCORG, dev_priv->back_offset,
593 MGA_AR5, dev_priv->front_pitch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700594
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000595 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
596 MGA_DMAPAD, 0x00000000,
597 MGA_PLNWT, 0xffffffff, MGA_DWGCTL, MGA_DWGCTL_COPY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700598
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000599 for (i = 0; i < nbox; i++) {
Dave Airlieeddca552007-07-11 16:09:54 +1000600 struct drm_clip_rect *box = &pbox[i];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700601 u32 height = box->y2 - box->y1;
602 u32 start = box->y1 * dev_priv->front_pitch;
603
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000604 DRM_DEBUG(" from=%d,%d to=%d,%d\n",
605 box->x1, box->y1, box->x2, box->y2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700606
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000607 DMA_BLOCK(MGA_AR0, start + box->x2 - 1,
608 MGA_AR3, start + box->x1,
609 MGA_FXBNDRY, ((box->x2 - 1) << 16) | box->x1,
610 MGA_YDSTLEN + MGA_EXEC, (box->y1 << 16) | height);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700611 }
612
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000613 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
614 MGA_PLNWT, ctx->plnwt,
615 MGA_SRCORG, dev_priv->front_offset, MGA_DWGCTL, ctx->dwgctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700616
617 ADVANCE_DMA();
618
619 FLUSH_DMA();
620
Márton Németh3e684ea2008-01-24 15:58:57 +1000621 DRM_DEBUG("... done.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700622}
623
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200624static void mga_dma_dispatch_vertex(struct drm_device *dev, struct drm_buf *buf)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700625{
626 drm_mga_private_t *dev_priv = dev->dev_private;
627 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
628 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
629 u32 address = (u32) buf->bus_address;
630 u32 length = (u32) buf->used;
631 int i = 0;
632 DMA_LOCALS;
Márton Németh3e684ea2008-01-24 15:58:57 +1000633 DRM_DEBUG("buf=%d used=%d\n", buf->idx, buf->used);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700634
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000635 if (buf->used) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700636 buf_priv->dispatched = 1;
637
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000638 MGA_EMIT_STATE(dev_priv, sarea_priv->dirty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700639
640 do {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000641 if (i < sarea_priv->nbox) {
642 mga_emit_clip_rect(dev_priv,
643 &sarea_priv->boxes[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700644 }
645
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000646 BEGIN_DMA(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700647
Dave Airlie6795c982005-07-10 18:20:09 +1000648 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
649 MGA_DMAPAD, 0x00000000,
650 MGA_SECADDRESS, (address |
651 MGA_DMA_VERTEX),
652 MGA_SECEND, ((address + length) |
653 dev_priv->dma_access));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700654
655 ADVANCE_DMA();
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000656 } while (++i < sarea_priv->nbox);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700657 }
658
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000659 if (buf_priv->discard) {
660 AGE_BUFFER(buf_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700661 buf->pending = 0;
662 buf->used = 0;
663 buf_priv->dispatched = 0;
664
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000665 mga_freelist_put(dev, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700666 }
667
668 FLUSH_DMA();
669}
670
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200671static void mga_dma_dispatch_indices(struct drm_device *dev, struct drm_buf *buf,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000672 unsigned int start, unsigned int end)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700673{
674 drm_mga_private_t *dev_priv = dev->dev_private;
675 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
676 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
677 u32 address = (u32) buf->bus_address;
678 int i = 0;
679 DMA_LOCALS;
Márton Németh3e684ea2008-01-24 15:58:57 +1000680 DRM_DEBUG("buf=%d start=%d end=%d\n", buf->idx, start, end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700681
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000682 if (start != end) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700683 buf_priv->dispatched = 1;
684
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000685 MGA_EMIT_STATE(dev_priv, sarea_priv->dirty);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700686
687 do {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000688 if (i < sarea_priv->nbox) {
689 mga_emit_clip_rect(dev_priv,
690 &sarea_priv->boxes[i]);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700691 }
692
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000693 BEGIN_DMA(1);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700694
Dave Airlie6795c982005-07-10 18:20:09 +1000695 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
696 MGA_DMAPAD, 0x00000000,
697 MGA_SETUPADDRESS, address + start,
698 MGA_SETUPEND, ((address + end) |
699 dev_priv->dma_access));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700700
701 ADVANCE_DMA();
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000702 } while (++i < sarea_priv->nbox);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700703 }
704
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000705 if (buf_priv->discard) {
706 AGE_BUFFER(buf_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700707 buf->pending = 0;
708 buf->used = 0;
709 buf_priv->dispatched = 0;
710
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000711 mga_freelist_put(dev, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700712 }
713
714 FLUSH_DMA();
715}
716
717/* This copies a 64 byte aligned agp region to the frambuffer with a
718 * standard blit, the ioctl needs to do checking.
719 */
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200720static void mga_dma_dispatch_iload(struct drm_device *dev, struct drm_buf *buf,
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000721 unsigned int dstorg, unsigned int length)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722{
723 drm_mga_private_t *dev_priv = dev->dev_private;
724 drm_mga_buf_priv_t *buf_priv = buf->dev_private;
725 drm_mga_context_regs_t *ctx = &dev_priv->sarea_priv->context_state;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000726 u32 srcorg =
727 buf->bus_address | dev_priv->dma_access | MGA_SRCMAP_SYSMEM;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728 u32 y2;
729 DMA_LOCALS;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000730 DRM_DEBUG("buf=%d used=%d\n", buf->idx, buf->used);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700731
732 y2 = length / 64;
733
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000734 BEGIN_DMA(5);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700735
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000736 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
737 MGA_DMAPAD, 0x00000000,
738 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700739
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000740 DMA_BLOCK(MGA_DSTORG, dstorg,
741 MGA_MACCESS, 0x00000000, MGA_SRCORG, srcorg, MGA_AR5, 64);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700742
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000743 DMA_BLOCK(MGA_PITCH, 64,
744 MGA_PLNWT, 0xffffffff,
745 MGA_DMAPAD, 0x00000000, MGA_DWGCTL, MGA_DWGCTL_COPY);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700746
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000747 DMA_BLOCK(MGA_AR0, 63,
748 MGA_AR3, 0,
749 MGA_FXBNDRY, (63 << 16) | 0, MGA_YDSTLEN + MGA_EXEC, y2);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700750
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000751 DMA_BLOCK(MGA_PLNWT, ctx->plnwt,
752 MGA_SRCORG, dev_priv->front_offset,
753 MGA_PITCH, dev_priv->front_pitch, MGA_DWGSYNC, 0x00007000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754
755 ADVANCE_DMA();
756
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000757 AGE_BUFFER(buf_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700758
759 buf->pending = 0;
760 buf->used = 0;
761 buf_priv->dispatched = 0;
762
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000763 mga_freelist_put(dev, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700764
765 FLUSH_DMA();
766}
767
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200768static void mga_dma_dispatch_blit(struct drm_device *dev, drm_mga_blit_t *blit)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700769{
770 drm_mga_private_t *dev_priv = dev->dev_private;
771 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
772 drm_mga_context_regs_t *ctx = &sarea_priv->context_state;
Dave Airlieeddca552007-07-11 16:09:54 +1000773 struct drm_clip_rect *pbox = sarea_priv->boxes;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700774 int nbox = sarea_priv->nbox;
775 u32 scandir = 0, i;
776 DMA_LOCALS;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000777 DRM_DEBUG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700778
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000779 BEGIN_DMA(4 + nbox);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700780
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000781 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
782 MGA_DMAPAD, 0x00000000,
783 MGA_DWGSYNC, 0x00007100, MGA_DWGSYNC, 0x00007000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700784
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000785 DMA_BLOCK(MGA_DWGCTL, MGA_DWGCTL_COPY,
786 MGA_PLNWT, blit->planemask,
787 MGA_SRCORG, blit->srcorg, MGA_DSTORG, blit->dstorg);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700788
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000789 DMA_BLOCK(MGA_SGN, scandir,
790 MGA_MACCESS, dev_priv->maccess,
791 MGA_AR5, blit->ydir * blit->src_pitch,
792 MGA_PITCH, blit->dst_pitch);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000794 for (i = 0; i < nbox; i++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700795 int srcx = pbox[i].x1 + blit->delta_sx;
796 int srcy = pbox[i].y1 + blit->delta_sy;
797 int dstx = pbox[i].x1 + blit->delta_dx;
798 int dsty = pbox[i].y1 + blit->delta_dy;
799 int h = pbox[i].y2 - pbox[i].y1;
800 int w = pbox[i].x2 - pbox[i].x1 - 1;
801 int start;
802
Nicolas Kaiserf2b2cb72010-07-12 01:46:57 +0200803 if (blit->ydir == -1)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700804 srcy = blit->height - srcy - 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700805
806 start = srcy * blit->src_pitch + srcx;
807
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000808 DMA_BLOCK(MGA_AR0, start + w,
809 MGA_AR3, start,
810 MGA_FXBNDRY, ((dstx + w) << 16) | (dstx & 0xffff),
811 MGA_YDSTLEN + MGA_EXEC, (dsty << 16) | h);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812 }
813
814 /* Do something to flush AGP?
815 */
816
817 /* Force reset of DWGCTL */
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000818 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
819 MGA_PLNWT, ctx->plnwt,
820 MGA_PITCH, dev_priv->front_pitch, MGA_DWGCTL, ctx->dwgctl);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700821
822 ADVANCE_DMA();
823}
824
Linus Torvalds1da177e2005-04-16 15:20:36 -0700825/* ================================================================
826 *
827 */
828
Eric Anholtc153f452007-09-03 12:06:45 +1000829static int mga_dma_clear(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700830{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700831 drm_mga_private_t *dev_priv = dev->dev_private;
832 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000833 drm_mga_clear_t *clear = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700834
Eric Anholt6c340ea2007-08-25 20:23:09 +1000835 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700836
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000837 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700838 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
839
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000840 WRAP_TEST_WITH_RETURN(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700841
Eric Anholtc153f452007-09-03 12:06:45 +1000842 mga_dma_dispatch_clear(dev, clear);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700843
844 /* Make sure we restore the 3D state next time.
845 */
846 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
847
848 return 0;
849}
850
Eric Anholtc153f452007-09-03 12:06:45 +1000851static int mga_dma_swap(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700852{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700853 drm_mga_private_t *dev_priv = dev->dev_private;
854 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
855
Eric Anholt6c340ea2007-08-25 20:23:09 +1000856 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700857
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000858 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700859 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
860
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000861 WRAP_TEST_WITH_RETURN(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700862
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000863 mga_dma_dispatch_swap(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700864
865 /* Make sure we restore the 3D state next time.
866 */
867 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
868
869 return 0;
870}
871
Eric Anholtc153f452007-09-03 12:06:45 +1000872static int mga_dma_vertex(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700873{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700874 drm_mga_private_t *dev_priv = dev->dev_private;
Dave Airliecdd55a22007-07-11 16:32:08 +1000875 struct drm_device_dma *dma = dev->dma;
Dave Airlie056219e2007-07-11 16:17:42 +1000876 struct drm_buf *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700877 drm_mga_buf_priv_t *buf_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000878 drm_mga_vertex_t *vertex = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700879
Eric Anholt6c340ea2007-08-25 20:23:09 +1000880 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700881
Eric Anholtc153f452007-09-03 12:06:45 +1000882 if (vertex->idx < 0 || vertex->idx > dma->buf_count)
Eric Anholt20caafa2007-08-25 19:22:43 +1000883 return -EINVAL;
Eric Anholtc153f452007-09-03 12:06:45 +1000884 buf = dma->buflist[vertex->idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700885 buf_priv = buf->dev_private;
886
Eric Anholtc153f452007-09-03 12:06:45 +1000887 buf->used = vertex->used;
888 buf_priv->discard = vertex->discard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700889
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000890 if (!mga_verify_state(dev_priv)) {
Eric Anholtc153f452007-09-03 12:06:45 +1000891 if (vertex->discard) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000892 if (buf_priv->dispatched == 1)
893 AGE_BUFFER(buf_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700894 buf_priv->dispatched = 0;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000895 mga_freelist_put(dev, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700896 }
Eric Anholt20caafa2007-08-25 19:22:43 +1000897 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700898 }
899
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000900 WRAP_TEST_WITH_RETURN(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700901
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000902 mga_dma_dispatch_vertex(dev, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700903
904 return 0;
905}
906
Eric Anholtc153f452007-09-03 12:06:45 +1000907static int mga_dma_indices(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700908{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700909 drm_mga_private_t *dev_priv = dev->dev_private;
Dave Airliecdd55a22007-07-11 16:32:08 +1000910 struct drm_device_dma *dma = dev->dma;
Dave Airlie056219e2007-07-11 16:17:42 +1000911 struct drm_buf *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700912 drm_mga_buf_priv_t *buf_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000913 drm_mga_indices_t *indices = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700914
Eric Anholt6c340ea2007-08-25 20:23:09 +1000915 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700916
Eric Anholtc153f452007-09-03 12:06:45 +1000917 if (indices->idx < 0 || indices->idx > dma->buf_count)
Eric Anholt20caafa2007-08-25 19:22:43 +1000918 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700919
Eric Anholtc153f452007-09-03 12:06:45 +1000920 buf = dma->buflist[indices->idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700921 buf_priv = buf->dev_private;
922
Eric Anholtc153f452007-09-03 12:06:45 +1000923 buf_priv->discard = indices->discard;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700924
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000925 if (!mga_verify_state(dev_priv)) {
Eric Anholtc153f452007-09-03 12:06:45 +1000926 if (indices->discard) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000927 if (buf_priv->dispatched == 1)
928 AGE_BUFFER(buf_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700929 buf_priv->dispatched = 0;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000930 mga_freelist_put(dev, buf);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700931 }
Eric Anholt20caafa2007-08-25 19:22:43 +1000932 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700933 }
934
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000935 WRAP_TEST_WITH_RETURN(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700936
Eric Anholtc153f452007-09-03 12:06:45 +1000937 mga_dma_dispatch_indices(dev, buf, indices->start, indices->end);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700938
939 return 0;
940}
941
Eric Anholtc153f452007-09-03 12:06:45 +1000942static int mga_dma_iload(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700943{
Dave Airliecdd55a22007-07-11 16:32:08 +1000944 struct drm_device_dma *dma = dev->dma;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700945 drm_mga_private_t *dev_priv = dev->dev_private;
Dave Airlie056219e2007-07-11 16:17:42 +1000946 struct drm_buf *buf;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700947 drm_mga_buf_priv_t *buf_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000948 drm_mga_iload_t *iload = data;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000949 DRM_DEBUG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700950
Eric Anholt6c340ea2007-08-25 20:23:09 +1000951 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700952
Linus Torvalds1da177e2005-04-16 15:20:36 -0700953#if 0
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000954 if (mga_do_wait_for_idle(dev_priv) < 0) {
955 if (MGA_DMA_DEBUG)
Márton Németh3e684ea2008-01-24 15:58:57 +1000956 DRM_INFO("-EBUSY\n");
Eric Anholt20caafa2007-08-25 19:22:43 +1000957 return -EBUSY;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700958 }
959#endif
Eric Anholtc153f452007-09-03 12:06:45 +1000960 if (iload->idx < 0 || iload->idx > dma->buf_count)
Eric Anholt20caafa2007-08-25 19:22:43 +1000961 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700962
Eric Anholtc153f452007-09-03 12:06:45 +1000963 buf = dma->buflist[iload->idx];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700964 buf_priv = buf->dev_private;
965
Eric Anholtc153f452007-09-03 12:06:45 +1000966 if (mga_verify_iload(dev_priv, iload->dstorg, iload->length)) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000967 mga_freelist_put(dev, buf);
Eric Anholt20caafa2007-08-25 19:22:43 +1000968 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700969 }
970
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000971 WRAP_TEST_WITH_RETURN(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700972
Eric Anholtc153f452007-09-03 12:06:45 +1000973 mga_dma_dispatch_iload(dev, buf, iload->dstorg, iload->length);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700974
975 /* Make sure we restore the 3D state next time.
976 */
977 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
978
979 return 0;
980}
981
Eric Anholtc153f452007-09-03 12:06:45 +1000982static int mga_dma_blit(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700983{
Linus Torvalds1da177e2005-04-16 15:20:36 -0700984 drm_mga_private_t *dev_priv = dev->dev_private;
985 drm_mga_sarea_t *sarea_priv = dev_priv->sarea_priv;
Eric Anholtc153f452007-09-03 12:06:45 +1000986 drm_mga_blit_t *blit = data;
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000987 DRM_DEBUG("\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700988
Eric Anholt6c340ea2007-08-25 20:23:09 +1000989 LOCK_TEST_WITH_RETURN(dev, file_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700990
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000991 if (sarea_priv->nbox > MGA_NR_SAREA_CLIPRECTS)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700992 sarea_priv->nbox = MGA_NR_SAREA_CLIPRECTS;
993
Eric Anholtc153f452007-09-03 12:06:45 +1000994 if (mga_verify_blit(dev_priv, blit->srcorg, blit->dstorg))
Eric Anholt20caafa2007-08-25 19:22:43 +1000995 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700996
Dave Airlieb5e89ed2005-09-25 14:28:13 +1000997 WRAP_TEST_WITH_RETURN(dev_priv);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700998
Eric Anholtc153f452007-09-03 12:06:45 +1000999 mga_dma_dispatch_blit(dev, blit);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001000
1001 /* Make sure we restore the 3D state next time.
1002 */
1003 dev_priv->sarea_priv->dirty |= MGA_UPLOAD_CONTEXT;
1004
1005 return 0;
1006}
1007
Eric Anholtc153f452007-09-03 12:06:45 +10001008static int mga_getparam(struct drm_device *dev, void *data, struct drm_file *file_priv)
Linus Torvalds1da177e2005-04-16 15:20:36 -07001009{
Linus Torvalds1da177e2005-04-16 15:20:36 -07001010 drm_mga_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001011 drm_mga_getparam_t *param = data;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001012 int value;
1013
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001014 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001015 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001016 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001017 }
1018
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001019 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001020
Eric Anholtc153f452007-09-03 12:06:45 +10001021 switch (param->param) {
Linus Torvalds1da177e2005-04-16 15:20:36 -07001022 case MGA_PARAM_IRQ_NR:
Jesse Barnes9bfbd5c2008-09-15 15:00:33 -07001023 value = drm_dev_to_irq(dev);
Linus Torvalds1da177e2005-04-16 15:20:36 -07001024 break;
Dave Airlie6795c982005-07-10 18:20:09 +10001025 case MGA_PARAM_CARD_TYPE:
1026 value = dev_priv->chipset;
1027 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001028 default:
Eric Anholt20caafa2007-08-25 19:22:43 +10001029 return -EINVAL;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001030 }
1031
Eric Anholtc153f452007-09-03 12:06:45 +10001032 if (DRM_COPY_TO_USER(param->value, &value, sizeof(int))) {
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001033 DRM_ERROR("copy_to_user\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001034 return -EFAULT;
Linus Torvalds1da177e2005-04-16 15:20:36 -07001035 }
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001036
Linus Torvalds1da177e2005-04-16 15:20:36 -07001037 return 0;
1038}
1039
Eric Anholtc153f452007-09-03 12:06:45 +10001040static int mga_set_fence(struct drm_device *dev, void *data, struct drm_file *file_priv)
Dave Airlie6795c982005-07-10 18:20:09 +10001041{
Dave Airlie6795c982005-07-10 18:20:09 +10001042 drm_mga_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001043 u32 *fence = data;
Dave Airlie6795c982005-07-10 18:20:09 +10001044 DMA_LOCALS;
1045
1046 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001047 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001048 return -EINVAL;
Dave Airlie6795c982005-07-10 18:20:09 +10001049 }
1050
1051 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
1052
Eric Anholtc153f452007-09-03 12:06:45 +10001053 /* I would normal do this assignment in the declaration of fence,
Dave Airlie6795c982005-07-10 18:20:09 +10001054 * but dev_priv may be NULL.
1055 */
1056
Eric Anholtc153f452007-09-03 12:06:45 +10001057 *fence = dev_priv->next_fence_to_post;
Dave Airlie6795c982005-07-10 18:20:09 +10001058 dev_priv->next_fence_to_post++;
1059
1060 BEGIN_DMA(1);
1061 DMA_BLOCK(MGA_DMAPAD, 0x00000000,
1062 MGA_DMAPAD, 0x00000000,
Dave Airlieb5e89ed2005-09-25 14:28:13 +10001063 MGA_DMAPAD, 0x00000000, MGA_SOFTRAP, 0x00000000);
Dave Airlie6795c982005-07-10 18:20:09 +10001064 ADVANCE_DMA();
1065
Dave Airlie6795c982005-07-10 18:20:09 +10001066 return 0;
1067}
1068
Eric Anholtc153f452007-09-03 12:06:45 +10001069static int mga_wait_fence(struct drm_device *dev, void *data, struct drm_file *
1070file_priv)
Dave Airlie6795c982005-07-10 18:20:09 +10001071{
Dave Airlie6795c982005-07-10 18:20:09 +10001072 drm_mga_private_t *dev_priv = dev->dev_private;
Eric Anholtc153f452007-09-03 12:06:45 +10001073 u32 *fence = data;
Dave Airlie6795c982005-07-10 18:20:09 +10001074
1075 if (!dev_priv) {
Márton Németh3e684ea2008-01-24 15:58:57 +10001076 DRM_ERROR("called with no initialization\n");
Eric Anholt20caafa2007-08-25 19:22:43 +10001077 return -EINVAL;
Dave Airlie6795c982005-07-10 18:20:09 +10001078 }
1079
Dave Airlie6795c982005-07-10 18:20:09 +10001080 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
1081
Eric Anholtc153f452007-09-03 12:06:45 +10001082 mga_driver_fence_wait(dev, fence);
Dave Airlie6795c982005-07-10 18:20:09 +10001083 return 0;
1084}
1085
Eric Anholtc153f452007-09-03 12:06:45 +10001086struct drm_ioctl_desc mga_ioctls[] = {
Dave Airlie1b2f1482010-08-14 20:20:34 +10001087 DRM_IOCTL_DEF_DRV(MGA_INIT, mga_dma_init, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
1088 DRM_IOCTL_DEF_DRV(MGA_FLUSH, mga_dma_flush, DRM_AUTH),
1089 DRM_IOCTL_DEF_DRV(MGA_RESET, mga_dma_reset, DRM_AUTH),
1090 DRM_IOCTL_DEF_DRV(MGA_SWAP, mga_dma_swap, DRM_AUTH),
1091 DRM_IOCTL_DEF_DRV(MGA_CLEAR, mga_dma_clear, DRM_AUTH),
1092 DRM_IOCTL_DEF_DRV(MGA_VERTEX, mga_dma_vertex, DRM_AUTH),
1093 DRM_IOCTL_DEF_DRV(MGA_INDICES, mga_dma_indices, DRM_AUTH),
1094 DRM_IOCTL_DEF_DRV(MGA_ILOAD, mga_dma_iload, DRM_AUTH),
1095 DRM_IOCTL_DEF_DRV(MGA_BLIT, mga_dma_blit, DRM_AUTH),
1096 DRM_IOCTL_DEF_DRV(MGA_GETPARAM, mga_getparam, DRM_AUTH),
1097 DRM_IOCTL_DEF_DRV(MGA_SET_FENCE, mga_set_fence, DRM_AUTH),
1098 DRM_IOCTL_DEF_DRV(MGA_WAIT_FENCE, mga_wait_fence, DRM_AUTH),
1099 DRM_IOCTL_DEF_DRV(MGA_DMA_BOOTSTRAP, mga_dma_bootstrap, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY),
Linus Torvalds1da177e2005-04-16 15:20:36 -07001100};
1101
1102int mga_max_ioctl = DRM_ARRAY_SIZE(mga_ioctls);