r128_state.c 42.1 KB
Newer Older
Linus Torvalds's avatar
Linus Torvalds committed
1 2
/* r128_state.c -- State support for r128 -*- linux-c -*-
 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com
3 4
 */
/* Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
Linus Torvalds's avatar
Linus Torvalds committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
 * All Rights Reserved.
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice (including the next
 * paragraph) shall be included in all copies or substantial portions of the
 * Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
 * DEALINGS IN THE SOFTWARE.
 *
 * Authors:
 *    Gareth Hughes <gareth@valinux.com>
 */

#include "drmP.h"
#include "drm.h"
#include "r128_drm.h"
#include "r128_drv.h"

/* ================================================================
 * CCE hardware state programming functions
 */

Dave Airlie's avatar
Dave Airlie committed
39 40
static void r128_emit_clip_rects(drm_r128_private_t * dev_priv,
				 drm_clip_rect_t * boxes, int count)
Linus Torvalds's avatar
Linus Torvalds committed
41 42 43
{
	u32 aux_sc_cntl = 0x00000000;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
44
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
45

Dave Airlie's avatar
Dave Airlie committed
46
	BEGIN_RING((count < 3 ? count : 3) * 5 + 2);
Linus Torvalds's avatar
Linus Torvalds committed
47

Dave Airlie's avatar
Dave Airlie committed
48 49 50 51 52 53
	if (count >= 1) {
		OUT_RING(CCE_PACKET0(R128_AUX1_SC_LEFT, 3));
		OUT_RING(boxes[0].x1);
		OUT_RING(boxes[0].x2 - 1);
		OUT_RING(boxes[0].y1);
		OUT_RING(boxes[0].y2 - 1);
Linus Torvalds's avatar
Linus Torvalds committed
54 55 56

		aux_sc_cntl |= (R128_AUX1_SC_EN | R128_AUX1_SC_MODE_OR);
	}
Dave Airlie's avatar
Dave Airlie committed
57 58 59 60 61 62
	if (count >= 2) {
		OUT_RING(CCE_PACKET0(R128_AUX2_SC_LEFT, 3));
		OUT_RING(boxes[1].x1);
		OUT_RING(boxes[1].x2 - 1);
		OUT_RING(boxes[1].y1);
		OUT_RING(boxes[1].y2 - 1);
Linus Torvalds's avatar
Linus Torvalds committed
63 64 65

		aux_sc_cntl |= (R128_AUX2_SC_EN | R128_AUX2_SC_MODE_OR);
	}
Dave Airlie's avatar
Dave Airlie committed
66 67 68 69 70 71
	if (count >= 3) {
		OUT_RING(CCE_PACKET0(R128_AUX3_SC_LEFT, 3));
		OUT_RING(boxes[2].x1);
		OUT_RING(boxes[2].x2 - 1);
		OUT_RING(boxes[2].y1);
		OUT_RING(boxes[2].y2 - 1);
Linus Torvalds's avatar
Linus Torvalds committed
72 73 74 75

		aux_sc_cntl |= (R128_AUX3_SC_EN | R128_AUX3_SC_MODE_OR);
	}

Dave Airlie's avatar
Dave Airlie committed
76 77
	OUT_RING(CCE_PACKET0(R128_AUX_SC_CNTL, 0));
	OUT_RING(aux_sc_cntl);
Linus Torvalds's avatar
Linus Torvalds committed
78 79 80 81

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
82
static __inline__ void r128_emit_core(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
83 84 85 86
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
87
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
88

Dave Airlie's avatar
Dave Airlie committed
89
	BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
90

Dave Airlie's avatar
Dave Airlie committed
91 92
	OUT_RING(CCE_PACKET0(R128_SCALE_3D_CNTL, 0));
	OUT_RING(ctx->scale_3d_cntl);
Linus Torvalds's avatar
Linus Torvalds committed
93 94 95 96

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
97
static __inline__ void r128_emit_context(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
98 99 100 101
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118
	DRM_DEBUG("    %s\n", __FUNCTION__);

	BEGIN_RING(13);

	OUT_RING(CCE_PACKET0(R128_DST_PITCH_OFFSET_C, 11));
	OUT_RING(ctx->dst_pitch_offset_c);
	OUT_RING(ctx->dp_gui_master_cntl_c);
	OUT_RING(ctx->sc_top_left_c);
	OUT_RING(ctx->sc_bottom_right_c);
	OUT_RING(ctx->z_offset_c);
	OUT_RING(ctx->z_pitch_c);
	OUT_RING(ctx->z_sten_cntl_c);
	OUT_RING(ctx->tex_cntl_c);
	OUT_RING(ctx->misc_3d_state_cntl_reg);
	OUT_RING(ctx->texture_clr_cmp_clr_c);
	OUT_RING(ctx->texture_clr_cmp_msk_c);
	OUT_RING(ctx->fog_color_c);
Linus Torvalds's avatar
Linus Torvalds committed
119 120 121 122

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
123
static __inline__ void r128_emit_setup(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
124 125 126 127
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
128
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
129

Dave Airlie's avatar
Dave Airlie committed
130
	BEGIN_RING(3);
Linus Torvalds's avatar
Linus Torvalds committed
131

Dave Airlie's avatar
Dave Airlie committed
132 133 134
	OUT_RING(CCE_PACKET1(R128_SETUP_CNTL, R128_PM4_VC_FPU_SETUP));
	OUT_RING(ctx->setup_cntl);
	OUT_RING(ctx->pm4_vc_fpu_setup);
Linus Torvalds's avatar
Linus Torvalds committed
135 136 137 138

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
139
static __inline__ void r128_emit_masks(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
140 141 142 143
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
144
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
145

Dave Airlie's avatar
Dave Airlie committed
146
	BEGIN_RING(5);
Linus Torvalds's avatar
Linus Torvalds committed
147

Dave Airlie's avatar
Dave Airlie committed
148 149
	OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0));
	OUT_RING(ctx->dp_write_mask);
Linus Torvalds's avatar
Linus Torvalds committed
150

Dave Airlie's avatar
Dave Airlie committed
151 152 153
	OUT_RING(CCE_PACKET0(R128_STEN_REF_MASK_C, 1));
	OUT_RING(ctx->sten_ref_mask_c);
	OUT_RING(ctx->plane_3d_mask_c);
Linus Torvalds's avatar
Linus Torvalds committed
154 155 156 157

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
158
static __inline__ void r128_emit_window(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
159 160 161 162
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
163
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
164

Dave Airlie's avatar
Dave Airlie committed
165
	BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
166

Dave Airlie's avatar
Dave Airlie committed
167 168
	OUT_RING(CCE_PACKET0(R128_WINDOW_XY_OFFSET, 0));
	OUT_RING(ctx->window_xy_offset);
Linus Torvalds's avatar
Linus Torvalds committed
169 170 171 172

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
173
static __inline__ void r128_emit_tex0(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
174 175 176 177 178 179
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_context_regs_t *ctx = &sarea_priv->context_state;
	drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[0];
	int i;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
180
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
181

Dave Airlie's avatar
Dave Airlie committed
182
	BEGIN_RING(7 + R128_MAX_TEXTURE_LEVELS);
Linus Torvalds's avatar
Linus Torvalds committed
183

Dave Airlie's avatar
Dave Airlie committed
184 185 186 187 188 189 190
	OUT_RING(CCE_PACKET0(R128_PRIM_TEX_CNTL_C,
			     2 + R128_MAX_TEXTURE_LEVELS));
	OUT_RING(tex->tex_cntl);
	OUT_RING(tex->tex_combine_cntl);
	OUT_RING(ctx->tex_size_pitch_c);
	for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) {
		OUT_RING(tex->tex_offset[i]);
Linus Torvalds's avatar
Linus Torvalds committed
191 192
	}

Dave Airlie's avatar
Dave Airlie committed
193 194 195
	OUT_RING(CCE_PACKET0(R128_CONSTANT_COLOR_C, 1));
	OUT_RING(ctx->constant_color_c);
	OUT_RING(tex->tex_border_color);
Linus Torvalds's avatar
Linus Torvalds committed
196 197 198 199

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
200
static __inline__ void r128_emit_tex1(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
201 202 203 204 205
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[1];
	int i;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
206
	DRM_DEBUG("    %s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
207

Dave Airlie's avatar
Dave Airlie committed
208
	BEGIN_RING(5 + R128_MAX_TEXTURE_LEVELS);
Linus Torvalds's avatar
Linus Torvalds committed
209

Dave Airlie's avatar
Dave Airlie committed
210 211 212 213 214
	OUT_RING(CCE_PACKET0(R128_SEC_TEX_CNTL_C, 1 + R128_MAX_TEXTURE_LEVELS));
	OUT_RING(tex->tex_cntl);
	OUT_RING(tex->tex_combine_cntl);
	for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) {
		OUT_RING(tex->tex_offset[i]);
Linus Torvalds's avatar
Linus Torvalds committed
215 216
	}

Dave Airlie's avatar
Dave Airlie committed
217 218
	OUT_RING(CCE_PACKET0(R128_SEC_TEXTURE_BORDER_COLOR_C, 0));
	OUT_RING(tex->tex_border_color);
Linus Torvalds's avatar
Linus Torvalds committed
219 220 221 222

	ADVANCE_RING();
}

223
static void r128_emit_state(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
224 225 226 227
{
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	unsigned int dirty = sarea_priv->dirty;

Dave Airlie's avatar
Dave Airlie committed
228
	DRM_DEBUG("%s: dirty=0x%08x\n", __FUNCTION__, dirty);
Linus Torvalds's avatar
Linus Torvalds committed
229

Dave Airlie's avatar
Dave Airlie committed
230 231
	if (dirty & R128_UPLOAD_CORE) {
		r128_emit_core(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
232 233 234
		sarea_priv->dirty &= ~R128_UPLOAD_CORE;
	}

Dave Airlie's avatar
Dave Airlie committed
235 236
	if (dirty & R128_UPLOAD_CONTEXT) {
		r128_emit_context(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
237 238 239
		sarea_priv->dirty &= ~R128_UPLOAD_CONTEXT;
	}

Dave Airlie's avatar
Dave Airlie committed
240 241
	if (dirty & R128_UPLOAD_SETUP) {
		r128_emit_setup(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
242 243 244
		sarea_priv->dirty &= ~R128_UPLOAD_SETUP;
	}

Dave Airlie's avatar
Dave Airlie committed
245 246
	if (dirty & R128_UPLOAD_MASKS) {
		r128_emit_masks(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
247 248 249
		sarea_priv->dirty &= ~R128_UPLOAD_MASKS;
	}

Dave Airlie's avatar
Dave Airlie committed
250 251
	if (dirty & R128_UPLOAD_WINDOW) {
		r128_emit_window(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
252 253 254
		sarea_priv->dirty &= ~R128_UPLOAD_WINDOW;
	}

Dave Airlie's avatar
Dave Airlie committed
255 256
	if (dirty & R128_UPLOAD_TEX0) {
		r128_emit_tex0(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
257 258 259
		sarea_priv->dirty &= ~R128_UPLOAD_TEX0;
	}

Dave Airlie's avatar
Dave Airlie committed
260 261
	if (dirty & R128_UPLOAD_TEX1) {
		r128_emit_tex1(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275
		sarea_priv->dirty &= ~R128_UPLOAD_TEX1;
	}

	/* Turn off the texture cache flushing */
	sarea_priv->context_state.tex_cntl_c &= ~R128_TEX_CACHE_FLUSH;

	sarea_priv->dirty &= ~R128_REQUIRE_QUIESCENCE;
}

#if R128_PERFORMANCE_BOXES
/* ================================================================
 * Performance monitoring functions
 */

Dave Airlie's avatar
Dave Airlie committed
276 277
static void r128_clear_box(drm_r128_private_t * dev_priv,
			   int x, int y, int w, int h, int r, int g, int b)
Linus Torvalds's avatar
Linus Torvalds committed
278 279 280 281 282
{
	u32 pitch, offset;
	u32 fb_bpp, color;
	RING_LOCALS;

Dave Airlie's avatar
Dave Airlie committed
283
	switch (dev_priv->fb_bpp) {
Linus Torvalds's avatar
Linus Torvalds committed
284 285 286
	case 16:
		fb_bpp = R128_GMC_DST_16BPP;
		color = (((r & 0xf8) << 8) |
Dave Airlie's avatar
Dave Airlie committed
287
			 ((g & 0xfc) << 3) | ((b & 0xf8) >> 3));
Linus Torvalds's avatar
Linus Torvalds committed
288 289 290 291 292 293 294
		break;
	case 24:
		fb_bpp = R128_GMC_DST_24BPP;
		color = ((r << 16) | (g << 8) | b);
		break;
	case 32:
		fb_bpp = R128_GMC_DST_32BPP;
Dave Airlie's avatar
Dave Airlie committed
295
		color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
Linus Torvalds's avatar
Linus Torvalds committed
296 297 298 299 300 301 302 303
		break;
	default:
		return;
	}

	offset = dev_priv->back_offset;
	pitch = dev_priv->back_pitch >> 3;

Dave Airlie's avatar
Dave Airlie committed
304
	BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
305

Dave Airlie's avatar
Dave Airlie committed
306 307 308 309 310 311 312
	OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
	OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
		 R128_GMC_BRUSH_SOLID_COLOR |
		 fb_bpp |
		 R128_GMC_SRC_DATATYPE_COLOR |
		 R128_ROP3_P |
		 R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_AUX_CLIP_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
313

Dave Airlie's avatar
Dave Airlie committed
314 315
	OUT_RING((pitch << 21) | (offset >> 5));
	OUT_RING(color);
Linus Torvalds's avatar
Linus Torvalds committed
316

Dave Airlie's avatar
Dave Airlie committed
317 318
	OUT_RING((x << 16) | y);
	OUT_RING((w << 16) | h);
Linus Torvalds's avatar
Linus Torvalds committed
319 320 321 322

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
323
static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv)
Linus Torvalds's avatar
Linus Torvalds committed
324
{
Dave Airlie's avatar
Dave Airlie committed
325 326
	if (atomic_read(&dev_priv->idle_count) == 0) {
		r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
Linus Torvalds's avatar
Linus Torvalds committed
327
	} else {
Dave Airlie's avatar
Dave Airlie committed
328
		atomic_set(&dev_priv->idle_count, 0);
Linus Torvalds's avatar
Linus Torvalds committed
329 330 331 332 333 334 335 336 337
	}
}

#endif

/* ================================================================
 * CCE command dispatch functions
 */

Dave Airlie's avatar
Dave Airlie committed
338
static void r128_print_dirty(const char *msg, unsigned int flags)
Linus Torvalds's avatar
Linus Torvalds committed
339
{
Dave Airlie's avatar
Dave Airlie committed
340 341 342 343 344 345 346 347 348 349 350 351
	DRM_INFO("%s: (0x%x) %s%s%s%s%s%s%s%s%s\n",
		 msg,
		 flags,
		 (flags & R128_UPLOAD_CORE) ? "core, " : "",
		 (flags & R128_UPLOAD_CONTEXT) ? "context, " : "",
		 (flags & R128_UPLOAD_SETUP) ? "setup, " : "",
		 (flags & R128_UPLOAD_TEX0) ? "tex0, " : "",
		 (flags & R128_UPLOAD_TEX1) ? "tex1, " : "",
		 (flags & R128_UPLOAD_MASKS) ? "masks, " : "",
		 (flags & R128_UPLOAD_WINDOW) ? "window, " : "",
		 (flags & R128_UPLOAD_CLIPRECTS) ? "cliprects, " : "",
		 (flags & R128_REQUIRE_QUIESCENCE) ? "quiescence, " : "");
Linus Torvalds's avatar
Linus Torvalds committed
352 353
}

Dave Airlie's avatar
Dave Airlie committed
354 355
static void r128_cce_dispatch_clear(drm_device_t * dev,
				    drm_r128_clear_t * clear)
Linus Torvalds's avatar
Linus Torvalds committed
356 357 358 359 360 361 362 363
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	int nbox = sarea_priv->nbox;
	drm_clip_rect_t *pbox = sarea_priv->boxes;
	unsigned int flags = clear->flags;
	int i;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
364
	DRM_DEBUG("%s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
365

Dave Airlie's avatar
Dave Airlie committed
366
	if (dev_priv->page_flipping && dev_priv->current_page == 1) {
Linus Torvalds's avatar
Linus Torvalds committed
367 368 369
		unsigned int tmp = flags;

		flags &= ~(R128_FRONT | R128_BACK);
Dave Airlie's avatar
Dave Airlie committed
370 371 372 373
		if (tmp & R128_FRONT)
			flags |= R128_BACK;
		if (tmp & R128_BACK)
			flags |= R128_FRONT;
Linus Torvalds's avatar
Linus Torvalds committed
374 375
	}

Dave Airlie's avatar
Dave Airlie committed
376
	for (i = 0; i < nbox; i++) {
Linus Torvalds's avatar
Linus Torvalds committed
377 378 379 380 381
		int x = pbox[i].x1;
		int y = pbox[i].y1;
		int w = pbox[i].x2 - x;
		int h = pbox[i].y2 - y;

Dave Airlie's avatar
Dave Airlie committed
382 383 384
		DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n",
			  pbox[i].x1, pbox[i].y1, pbox[i].x2,
			  pbox[i].y2, flags);
Linus Torvalds's avatar
Linus Torvalds committed
385

Dave Airlie's avatar
Dave Airlie committed
386 387
		if (flags & (R128_FRONT | R128_BACK)) {
			BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
388

Dave Airlie's avatar
Dave Airlie committed
389 390
			OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0));
			OUT_RING(clear->color_mask);
Linus Torvalds's avatar
Linus Torvalds committed
391 392 393 394

			ADVANCE_RING();
		}

Dave Airlie's avatar
Dave Airlie committed
395 396
		if (flags & R128_FRONT) {
			BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
397

Dave Airlie's avatar
Dave Airlie committed
398 399 400 401 402 403 404 405
			OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
			OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
				 R128_GMC_BRUSH_SOLID_COLOR |
				 (dev_priv->color_fmt << 8) |
				 R128_GMC_SRC_DATATYPE_COLOR |
				 R128_ROP3_P |
				 R128_GMC_CLR_CMP_CNTL_DIS |
				 R128_GMC_AUX_CLIP_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
406

Dave Airlie's avatar
Dave Airlie committed
407 408
			OUT_RING(dev_priv->front_pitch_offset_c);
			OUT_RING(clear->clear_color);
Linus Torvalds's avatar
Linus Torvalds committed
409

Dave Airlie's avatar
Dave Airlie committed
410 411
			OUT_RING((x << 16) | y);
			OUT_RING((w << 16) | h);
Linus Torvalds's avatar
Linus Torvalds committed
412 413 414 415

			ADVANCE_RING();
		}

Dave Airlie's avatar
Dave Airlie committed
416 417
		if (flags & R128_BACK) {
			BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
418

Dave Airlie's avatar
Dave Airlie committed
419 420 421 422 423 424 425 426
			OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
			OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
				 R128_GMC_BRUSH_SOLID_COLOR |
				 (dev_priv->color_fmt << 8) |
				 R128_GMC_SRC_DATATYPE_COLOR |
				 R128_ROP3_P |
				 R128_GMC_CLR_CMP_CNTL_DIS |
				 R128_GMC_AUX_CLIP_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
427

Dave Airlie's avatar
Dave Airlie committed
428 429
			OUT_RING(dev_priv->back_pitch_offset_c);
			OUT_RING(clear->clear_color);
Linus Torvalds's avatar
Linus Torvalds committed
430

Dave Airlie's avatar
Dave Airlie committed
431 432
			OUT_RING((x << 16) | y);
			OUT_RING((w << 16) | h);
Linus Torvalds's avatar
Linus Torvalds committed
433 434 435 436

			ADVANCE_RING();
		}

Dave Airlie's avatar
Dave Airlie committed
437 438
		if (flags & R128_DEPTH) {
			BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
439

Dave Airlie's avatar
Dave Airlie committed
440 441 442 443 444 445 446 447
			OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
			OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
				 R128_GMC_BRUSH_SOLID_COLOR |
				 (dev_priv->depth_fmt << 8) |
				 R128_GMC_SRC_DATATYPE_COLOR |
				 R128_ROP3_P |
				 R128_GMC_CLR_CMP_CNTL_DIS |
				 R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
448

Dave Airlie's avatar
Dave Airlie committed
449 450
			OUT_RING(dev_priv->depth_pitch_offset_c);
			OUT_RING(clear->clear_depth);
Linus Torvalds's avatar
Linus Torvalds committed
451

Dave Airlie's avatar
Dave Airlie committed
452 453
			OUT_RING((x << 16) | y);
			OUT_RING((w << 16) | h);
Linus Torvalds's avatar
Linus Torvalds committed
454 455 456 457 458 459

			ADVANCE_RING();
		}
	}
}

Dave Airlie's avatar
Dave Airlie committed
460
static void r128_cce_dispatch_swap(drm_device_t * dev)
Linus Torvalds's avatar
Linus Torvalds committed
461 462 463 464 465 466 467
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	int nbox = sarea_priv->nbox;
	drm_clip_rect_t *pbox = sarea_priv->boxes;
	int i;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
468
	DRM_DEBUG("%s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
469 470 471 472

#if R128_PERFORMANCE_BOXES
	/* Do some trivial performance monitoring...
	 */
Dave Airlie's avatar
Dave Airlie committed
473
	r128_cce_performance_boxes(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
474 475
#endif

Dave Airlie's avatar
Dave Airlie committed
476
	for (i = 0; i < nbox; i++) {
Linus Torvalds's avatar
Linus Torvalds committed
477 478 479 480 481
		int x = pbox[i].x1;
		int y = pbox[i].y1;
		int w = pbox[i].x2 - x;
		int h = pbox[i].y2 - y;

Dave Airlie's avatar
Dave Airlie committed
482
		BEGIN_RING(7);
Linus Torvalds's avatar
Linus Torvalds committed
483

Dave Airlie's avatar
Dave Airlie committed
484 485 486 487 488 489 490 491 492 493
		OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
		OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
			 R128_GMC_DST_PITCH_OFFSET_CNTL |
			 R128_GMC_BRUSH_NONE |
			 (dev_priv->color_fmt << 8) |
			 R128_GMC_SRC_DATATYPE_COLOR |
			 R128_ROP3_S |
			 R128_DP_SRC_SOURCE_MEMORY |
			 R128_GMC_CLR_CMP_CNTL_DIS |
			 R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
494 495 496 497

		/* Make this work even if front & back are flipped:
		 */
		if (dev_priv->current_page == 0) {
Dave Airlie's avatar
Dave Airlie committed
498 499 500 501 502
			OUT_RING(dev_priv->back_pitch_offset_c);
			OUT_RING(dev_priv->front_pitch_offset_c);
		} else {
			OUT_RING(dev_priv->front_pitch_offset_c);
			OUT_RING(dev_priv->back_pitch_offset_c);
Linus Torvalds's avatar
Linus Torvalds committed
503 504
		}

Dave Airlie's avatar
Dave Airlie committed
505 506 507
		OUT_RING((x << 16) | y);
		OUT_RING((x << 16) | y);
		OUT_RING((w << 16) | h);
Linus Torvalds's avatar
Linus Torvalds committed
508 509 510 511 512 513 514 515 516 517

		ADVANCE_RING();
	}

	/* Increment the frame counter.  The client-side 3D driver must
	 * throttle the framerate by waiting for this value before
	 * performing the swapbuffer ioctl.
	 */
	dev_priv->sarea_priv->last_frame++;

Dave Airlie's avatar
Dave Airlie committed
518
	BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
519

Dave Airlie's avatar
Dave Airlie committed
520 521
	OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0));
	OUT_RING(dev_priv->sarea_priv->last_frame);
Linus Torvalds's avatar
Linus Torvalds committed
522 523 524 525

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
526
static void r128_cce_dispatch_flip(drm_device_t * dev)
Linus Torvalds's avatar
Linus Torvalds committed
527 528 529
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
530 531 532
	DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n",
		  __FUNCTION__,
		  dev_priv->current_page, dev_priv->sarea_priv->pfCurrentPage);
Linus Torvalds's avatar
Linus Torvalds committed
533 534 535 536

#if R128_PERFORMANCE_BOXES
	/* Do some trivial performance monitoring...
	 */
Dave Airlie's avatar
Dave Airlie committed
537
	r128_cce_performance_boxes(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
538 539
#endif

Dave Airlie's avatar
Dave Airlie committed
540
	BEGIN_RING(4);
Linus Torvalds's avatar
Linus Torvalds committed
541 542

	R128_WAIT_UNTIL_PAGE_FLIPPED();
Dave Airlie's avatar
Dave Airlie committed
543
	OUT_RING(CCE_PACKET0(R128_CRTC_OFFSET, 0));
Linus Torvalds's avatar
Linus Torvalds committed
544

Dave Airlie's avatar
Dave Airlie committed
545 546
	if (dev_priv->current_page == 0) {
		OUT_RING(dev_priv->back_offset);
Linus Torvalds's avatar
Linus Torvalds committed
547
	} else {
Dave Airlie's avatar
Dave Airlie committed
548
		OUT_RING(dev_priv->front_offset);
Linus Torvalds's avatar
Linus Torvalds committed
549 550 551 552 553 554 555 556 557 558
	}

	ADVANCE_RING();

	/* Increment the frame counter.  The client-side 3D driver must
	 * throttle the framerate by waiting for this value before
	 * performing the swapbuffer ioctl.
	 */
	dev_priv->sarea_priv->last_frame++;
	dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page =
Dave Airlie's avatar
Dave Airlie committed
559
	    1 - dev_priv->current_page;
Linus Torvalds's avatar
Linus Torvalds committed
560

Dave Airlie's avatar
Dave Airlie committed
561
	BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
562

Dave Airlie's avatar
Dave Airlie committed
563 564
	OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0));
	OUT_RING(dev_priv->sarea_priv->last_frame);
Linus Torvalds's avatar
Linus Torvalds committed
565 566 567 568

	ADVANCE_RING();
}

Dave Airlie's avatar
Dave Airlie committed
569
static void r128_cce_dispatch_vertex(drm_device_t * dev, drm_buf_t * buf)
Linus Torvalds's avatar
Linus Torvalds committed
570 571 572 573 574 575 576 577 578 579
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	drm_r128_buf_priv_t *buf_priv = buf->dev_private;
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	int format = sarea_priv->vc_format;
	int offset = buf->bus_address;
	int size = buf->used;
	int prim = buf_priv->prim;
	int i = 0;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
580
	DRM_DEBUG("buf=%d nbox=%d\n", buf->idx, sarea_priv->nbox);
Linus Torvalds's avatar
Linus Torvalds committed
581

Dave Airlie's avatar
Dave Airlie committed
582 583
	if (0)
		r128_print_dirty("dispatch_vertex", sarea_priv->dirty);
Linus Torvalds's avatar
Linus Torvalds committed
584

Dave Airlie's avatar
Dave Airlie committed
585
	if (buf->used) {
Linus Torvalds's avatar
Linus Torvalds committed
586 587
		buf_priv->dispatched = 1;

Dave Airlie's avatar
Dave Airlie committed
588 589
		if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) {
			r128_emit_state(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
590 591 592 593
		}

		do {
			/* Emit the next set of up to three cliprects */
Dave Airlie's avatar
Dave Airlie committed
594 595 596 597
			if (i < sarea_priv->nbox) {
				r128_emit_clip_rects(dev_priv,
						     &sarea_priv->boxes[i],
						     sarea_priv->nbox - i);
Linus Torvalds's avatar
Linus Torvalds committed
598 599 600
			}

			/* Emit the vertex buffer rendering commands */
Dave Airlie's avatar
Dave Airlie committed
601
			BEGIN_RING(5);
Linus Torvalds's avatar
Linus Torvalds committed
602

Dave Airlie's avatar
Dave Airlie committed
603 604 605 606 607 608
			OUT_RING(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM, 3));
			OUT_RING(offset);
			OUT_RING(size);
			OUT_RING(format);
			OUT_RING(prim | R128_CCE_VC_CNTL_PRIM_WALK_LIST |
				 (size << R128_CCE_VC_CNTL_NUM_SHIFT));
Linus Torvalds's avatar
Linus Torvalds committed
609 610 611 612

			ADVANCE_RING();

			i += 3;
Dave Airlie's avatar
Dave Airlie committed
613
		} while (i < sarea_priv->nbox);
Linus Torvalds's avatar
Linus Torvalds committed
614 615
	}

Dave Airlie's avatar
Dave Airlie committed
616
	if (buf_priv->discard) {
Linus Torvalds's avatar
Linus Torvalds committed
617 618 619
		buf_priv->age = dev_priv->sarea_priv->last_dispatch;

		/* Emit the vertex buffer age */
Dave Airlie's avatar
Dave Airlie committed
620
		BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
621

Dave Airlie's avatar
Dave Airlie committed
622 623
		OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
		OUT_RING(buf_priv->age);
Linus Torvalds's avatar
Linus Torvalds committed
624 625 626 627 628 629 630 631 632 633 634 635 636 637 638

		ADVANCE_RING();

		buf->pending = 1;
		buf->used = 0;
		/* FIXME: Check dispatched field */
		buf_priv->dispatched = 0;
	}

	dev_priv->sarea_priv->last_dispatch++;

	sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
	sarea_priv->nbox = 0;
}

Dave Airlie's avatar
Dave Airlie committed
639 640
static void r128_cce_dispatch_indirect(drm_device_t * dev,
				       drm_buf_t * buf, int start, int end)
Linus Torvalds's avatar
Linus Torvalds committed
641 642 643 644
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	drm_r128_buf_priv_t *buf_priv = buf->dev_private;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
645
	DRM_DEBUG("indirect: buf=%d s=0x%x e=0x%x\n", buf->idx, start, end);
Linus Torvalds's avatar
Linus Torvalds committed
646

Dave Airlie's avatar
Dave Airlie committed
647
	if (start != end) {
Linus Torvalds's avatar
Linus Torvalds committed
648 649 650 651 652 653 654
		int offset = buf->bus_address + start;
		int dwords = (end - start + 3) / sizeof(u32);

		/* Indirect buffer data must be an even number of
		 * dwords, so if we've been given an odd number we must
		 * pad the data with a Type-2 CCE packet.
		 */
Dave Airlie's avatar
Dave Airlie committed
655
		if (dwords & 1) {
Linus Torvalds's avatar
Linus Torvalds committed
656
			u32 *data = (u32 *)
Dave Airlie's avatar
Dave Airlie committed
657 658 659
			    ((char *)dev->agp_buffer_map->handle
			     + buf->offset + start);
			data[dwords++] = cpu_to_le32(R128_CCE_PACKET2);
Linus Torvalds's avatar
Linus Torvalds committed
660 661 662 663 664
		}

		buf_priv->dispatched = 1;

		/* Fire off the indirect buffer */
Dave Airlie's avatar
Dave Airlie committed
665
		BEGIN_RING(3);
Linus Torvalds's avatar
Linus Torvalds committed
666

Dave Airlie's avatar
Dave Airlie committed
667 668 669
		OUT_RING(CCE_PACKET0(R128_PM4_IW_INDOFF, 1));
		OUT_RING(offset);
		OUT_RING(dwords);
Linus Torvalds's avatar
Linus Torvalds committed
670 671 672 673

		ADVANCE_RING();
	}

Dave Airlie's avatar
Dave Airlie committed
674
	if (buf_priv->discard) {
Linus Torvalds's avatar
Linus Torvalds committed
675 676 677
		buf_priv->age = dev_priv->sarea_priv->last_dispatch;

		/* Emit the indirect buffer age */
Dave Airlie's avatar
Dave Airlie committed
678
		BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
679

Dave Airlie's avatar
Dave Airlie committed
680 681
		OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
		OUT_RING(buf_priv->age);
Linus Torvalds's avatar
Linus Torvalds committed
682 683 684 685 686 687 688 689 690 691 692 693

		ADVANCE_RING();

		buf->pending = 1;
		buf->used = 0;
		/* FIXME: Check dispatched field */
		buf_priv->dispatched = 0;
	}

	dev_priv->sarea_priv->last_dispatch++;
}

Dave Airlie's avatar
Dave Airlie committed
694 695 696
static void r128_cce_dispatch_indices(drm_device_t * dev,
				      drm_buf_t * buf,
				      int start, int end, int count)
Linus Torvalds's avatar
Linus Torvalds committed
697 698 699 700 701 702 703 704 705 706 707
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	drm_r128_buf_priv_t *buf_priv = buf->dev_private;
	drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv;
	int format = sarea_priv->vc_format;
	int offset = dev->agp_buffer_map->offset - dev_priv->cce_buffers_offset;
	int prim = buf_priv->prim;
	u32 *data;
	int dwords;
	int i = 0;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
708
	DRM_DEBUG("indices: s=%d e=%d c=%d\n", start, end, count);
Linus Torvalds's avatar
Linus Torvalds committed
709

Dave Airlie's avatar
Dave Airlie committed
710 711
	if (0)
		r128_print_dirty("dispatch_indices", sarea_priv->dirty);
Linus Torvalds's avatar
Linus Torvalds committed
712

Dave Airlie's avatar
Dave Airlie committed
713
	if (start != end) {
Linus Torvalds's avatar
Linus Torvalds committed
714 715
		buf_priv->dispatched = 1;

Dave Airlie's avatar
Dave Airlie committed
716 717
		if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) {
			r128_emit_state(dev_priv);
Linus Torvalds's avatar
Linus Torvalds committed
718 719 720 721
		}

		dwords = (end - start + 3) / sizeof(u32);

Dave Airlie's avatar
Dave Airlie committed
722 723
		data = (u32 *) ((char *)dev->agp_buffer_map->handle
				+ buf->offset + start);
Linus Torvalds's avatar
Linus Torvalds committed
724

Dave Airlie's avatar
Dave Airlie committed
725 726
		data[0] = cpu_to_le32(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM,
						  dwords - 2));
Linus Torvalds's avatar
Linus Torvalds committed
727

Dave Airlie's avatar
Dave Airlie committed
728 729 730 731 732
		data[1] = cpu_to_le32(offset);
		data[2] = cpu_to_le32(R128_MAX_VB_VERTS);
		data[3] = cpu_to_le32(format);
		data[4] = cpu_to_le32((prim | R128_CCE_VC_CNTL_PRIM_WALK_IND |
				       (count << 16)));
Linus Torvalds's avatar
Linus Torvalds committed
733

Dave Airlie's avatar
Dave Airlie committed
734
		if (count & 0x1) {
Linus Torvalds's avatar
Linus Torvalds committed
735
#ifdef __LITTLE_ENDIAN
Dave Airlie's avatar
Dave Airlie committed
736
			data[dwords - 1] &= 0x0000ffff;
Linus Torvalds's avatar
Linus Torvalds committed
737
#else
Dave Airlie's avatar
Dave Airlie committed
738
			data[dwords - 1] &= 0xffff0000;
Linus Torvalds's avatar
Linus Torvalds committed
739 740 741 742 743
#endif
		}

		do {
			/* Emit the next set of up to three cliprects */
Dave Airlie's avatar
Dave Airlie committed
744 745 746 747
			if (i < sarea_priv->nbox) {
				r128_emit_clip_rects(dev_priv,
						     &sarea_priv->boxes[i],
						     sarea_priv->nbox - i);
Linus Torvalds's avatar
Linus Torvalds committed
748 749
			}

Dave Airlie's avatar
Dave Airlie committed
750
			r128_cce_dispatch_indirect(dev, buf, start, end);
Linus Torvalds's avatar
Linus Torvalds committed
751 752

			i += 3;
Dave Airlie's avatar
Dave Airlie committed
753
		} while (i < sarea_priv->nbox);
Linus Torvalds's avatar
Linus Torvalds committed
754 755
	}

Dave Airlie's avatar
Dave Airlie committed
756
	if (buf_priv->discard) {
Linus Torvalds's avatar
Linus Torvalds committed
757 758 759
		buf_priv->age = dev_priv->sarea_priv->last_dispatch;

		/* Emit the vertex buffer age */
Dave Airlie's avatar
Dave Airlie committed
760
		BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
761

Dave Airlie's avatar
Dave Airlie committed
762 763
		OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0));
		OUT_RING(buf_priv->age);
Linus Torvalds's avatar
Linus Torvalds committed
764 765 766 767 768 769 770 771 772 773 774 775 776 777

		ADVANCE_RING();

		buf->pending = 1;
		/* FIXME: Check dispatched field */
		buf_priv->dispatched = 0;
	}

	dev_priv->sarea_priv->last_dispatch++;

	sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS;
	sarea_priv->nbox = 0;
}

Dave Airlie's avatar
Dave Airlie committed
778 779
static int r128_cce_dispatch_blit(DRMFILE filp,
				  drm_device_t * dev, drm_r128_blit_t * blit)
Linus Torvalds's avatar
Linus Torvalds committed
780 781 782 783 784 785 786 787
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	drm_device_dma_t *dma = dev->dma;
	drm_buf_t *buf;
	drm_r128_buf_priv_t *buf_priv;
	u32 *data;
	int dword_shift, dwords;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
788
	DRM_DEBUG("\n");
Linus Torvalds's avatar
Linus Torvalds committed
789 790 791 792 793

	/* The compiler won't optimize away a division by a variable,
	 * even if the only legal values are powers of two.  Thus, we'll
	 * use a shift instead.
	 */
Dave Airlie's avatar
Dave Airlie committed
794
	switch (blit->format) {
Linus Torvalds's avatar
Linus Torvalds committed
795 796 797 798 799 800 801 802 803 804 805 806 807 808 809
	case R128_DATATYPE_ARGB8888:
		dword_shift = 0;
		break;
	case R128_DATATYPE_ARGB1555:
	case R128_DATATYPE_RGB565:
	case R128_DATATYPE_ARGB4444:
	case R128_DATATYPE_YVYU422:
	case R128_DATATYPE_VYUY422:
		dword_shift = 1;
		break;
	case R128_DATATYPE_CI8:
	case R128_DATATYPE_RGB8:
		dword_shift = 2;
		break;
	default:
Dave Airlie's avatar
Dave Airlie committed
810
		DRM_ERROR("invalid blit format %d\n", blit->format);
Linus Torvalds's avatar
Linus Torvalds committed
811 812 813 814 815 816 817 818
		return DRM_ERR(EINVAL);
	}

	/* Flush the pixel cache, and mark the contents as Read Invalid.
	 * This ensures no pixel data gets mixed up with the texture
	 * data from the host data blit, otherwise part of the texture
	 * image may be corrupted.
	 */
Dave Airlie's avatar
Dave Airlie committed
819
	BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
820

Dave Airlie's avatar
Dave Airlie committed
821 822
	OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0));
	OUT_RING(R128_PC_RI_GUI | R128_PC_FLUSH_GUI);
Linus Torvalds's avatar
Linus Torvalds committed
823 824 825 826 827 828 829 830

	ADVANCE_RING();

	/* Dispatch the indirect buffer.
	 */
	buf = dma->buflist[blit->idx];
	buf_priv = buf->dev_private;

Dave Airlie's avatar
Dave Airlie committed
831 832 833
	if (buf->filp != filp) {
		DRM_ERROR("process %d using buffer owned by %p\n",
			  DRM_CURRENTPID, buf->filp);
Linus Torvalds's avatar
Linus Torvalds committed
834 835
		return DRM_ERR(EINVAL);
	}
Dave Airlie's avatar
Dave Airlie committed
836 837
	if (buf->pending) {
		DRM_ERROR("sending pending buffer %d\n", blit->idx);
Linus Torvalds's avatar
Linus Torvalds committed
838 839 840 841 842 843 844
		return DRM_ERR(EINVAL);
	}

	buf_priv->discard = 1;

	dwords = (blit->width * blit->height) >> dword_shift;

Dave Airlie's avatar
Dave Airlie committed
845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862
	data = (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset);

	data[0] = cpu_to_le32(CCE_PACKET3(R128_CNTL_HOSTDATA_BLT, dwords + 6));
	data[1] = cpu_to_le32((R128_GMC_DST_PITCH_OFFSET_CNTL |
			       R128_GMC_BRUSH_NONE |
			       (blit->format << 8) |
			       R128_GMC_SRC_DATATYPE_COLOR |
			       R128_ROP3_S |
			       R128_DP_SRC_SOURCE_HOST_DATA |
			       R128_GMC_CLR_CMP_CNTL_DIS |
			       R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS));

	data[2] = cpu_to_le32((blit->pitch << 21) | (blit->offset >> 5));
	data[3] = cpu_to_le32(0xffffffff);
	data[4] = cpu_to_le32(0xffffffff);
	data[5] = cpu_to_le32((blit->y << 16) | blit->x);
	data[6] = cpu_to_le32((blit->height << 16) | blit->width);
	data[7] = cpu_to_le32(dwords);
Linus Torvalds's avatar
Linus Torvalds committed
863 864 865

	buf->used = (dwords + 8) * sizeof(u32);

Dave Airlie's avatar
Dave Airlie committed
866
	r128_cce_dispatch_indirect(dev, buf, 0, buf->used);
Linus Torvalds's avatar
Linus Torvalds committed
867 868 869 870 871

	/* Flush the pixel cache after the blit completes.  This ensures
	 * the texture data is written out to memory before rendering
	 * continues.
	 */
Dave Airlie's avatar
Dave Airlie committed
872
	BEGIN_RING(2);
Linus Torvalds's avatar
Linus Torvalds committed
873

Dave Airlie's avatar
Dave Airlie committed
874 875
	OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0));
	OUT_RING(R128_PC_FLUSH_GUI);
Linus Torvalds's avatar
Linus Torvalds committed
876 877 878 879 880 881 882 883 884 885 886 887 888

	ADVANCE_RING();

	return 0;
}

/* ================================================================
 * Tiled depth buffer management
 *
 * FIXME: These should all set the destination write mask for when we
 * have hardware stencil support.
 */

Dave Airlie's avatar
Dave Airlie committed
889 890
static int r128_cce_dispatch_write_span(drm_device_t * dev,
					drm_r128_depth_t * depth)
Linus Torvalds's avatar
Linus Torvalds committed
891 892 893 894 895 896 897
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	int count, x, y;
	u32 *buffer;
	u8 *mask;
	int i, buffer_size, mask_size;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
898
	DRM_DEBUG("\n");
Linus Torvalds's avatar
Linus Torvalds committed
899 900 901 902 903

	count = depth->n;
	if (count > 4096 || count <= 0)
		return DRM_ERR(EMSGSIZE);

Dave Airlie's avatar
Dave Airlie committed
904
	if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) {
Linus Torvalds's avatar
Linus Torvalds committed
905 906
		return DRM_ERR(EFAULT);
	}
Dave Airlie's avatar
Dave Airlie committed
907
	if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) {
Linus Torvalds's avatar
Linus Torvalds committed
908 909 910 911
		return DRM_ERR(EFAULT);
	}

	buffer_size = depth->n * sizeof(u32);
Dave Airlie's avatar
Dave Airlie committed
912 913
	buffer = drm_alloc(buffer_size, DRM_MEM_BUFS);
	if (buffer == NULL)
Linus Torvalds's avatar
Linus Torvalds committed
914
		return DRM_ERR(ENOMEM);
Dave Airlie's avatar
Dave Airlie committed
915 916
	if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) {
		drm_free(buffer, buffer_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
917 918 919 920
		return DRM_ERR(EFAULT);
	}

	mask_size = depth->n * sizeof(u8);
Dave Airlie's avatar
Dave Airlie committed
921 922 923 924
	if (depth->mask) {
		mask = drm_alloc(mask_size, DRM_MEM_BUFS);
		if (mask == NULL) {
			drm_free(buffer, buffer_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
925 926
			return DRM_ERR(ENOMEM);
		}
Dave Airlie's avatar
Dave Airlie committed
927 928 929
		if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) {
			drm_free(buffer, buffer_size, DRM_MEM_BUFS);
			drm_free(mask, mask_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
930 931 932
			return DRM_ERR(EFAULT);
		}

Dave Airlie's avatar
Dave Airlie committed
933 934 935
		for (i = 0; i < count; i++, x++) {
			if (mask[i]) {
				BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
936

Dave Airlie's avatar
Dave Airlie committed
937 938 939 940 941 942 943 944
				OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
				OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
					 R128_GMC_BRUSH_SOLID_COLOR |
					 (dev_priv->depth_fmt << 8) |
					 R128_GMC_SRC_DATATYPE_COLOR |
					 R128_ROP3_P |
					 R128_GMC_CLR_CMP_CNTL_DIS |
					 R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
945

Dave Airlie's avatar
Dave Airlie committed
946 947
				OUT_RING(dev_priv->depth_pitch_offset_c);
				OUT_RING(buffer[i]);
Linus Torvalds's avatar
Linus Torvalds committed
948

Dave Airlie's avatar
Dave Airlie committed
949 950
				OUT_RING((x << 16) | y);
				OUT_RING((1 << 16) | 1);
Linus Torvalds's avatar
Linus Torvalds committed
951 952 953 954 955

				ADVANCE_RING();
			}
		}

Dave Airlie's avatar
Dave Airlie committed
956
		drm_free(mask, mask_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
957
	} else {
Dave Airlie's avatar
Dave Airlie committed
958 959
		for (i = 0; i < count; i++, x++) {
			BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
960

Dave Airlie's avatar
Dave Airlie committed
961 962 963 964 965 966 967 968
			OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
			OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
				 R128_GMC_BRUSH_SOLID_COLOR |
				 (dev_priv->depth_fmt << 8) |
				 R128_GMC_SRC_DATATYPE_COLOR |
				 R128_ROP3_P |
				 R128_GMC_CLR_CMP_CNTL_DIS |
				 R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
969

Dave Airlie's avatar
Dave Airlie committed
970 971
			OUT_RING(dev_priv->depth_pitch_offset_c);
			OUT_RING(buffer[i]);
Linus Torvalds's avatar
Linus Torvalds committed
972

Dave Airlie's avatar
Dave Airlie committed
973 974
			OUT_RING((x << 16) | y);
			OUT_RING((1 << 16) | 1);
Linus Torvalds's avatar
Linus Torvalds committed
975 976 977 978 979

			ADVANCE_RING();
		}
	}

Dave Airlie's avatar
Dave Airlie committed
980
	drm_free(buffer, buffer_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
981 982 983 984

	return 0;
}

Dave Airlie's avatar
Dave Airlie committed
985 986
static int r128_cce_dispatch_write_pixels(drm_device_t * dev,
					  drm_r128_depth_t * depth)
Linus Torvalds's avatar
Linus Torvalds committed
987 988 989 990 991 992 993
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	int count, *x, *y;
	u32 *buffer;
	u8 *mask;
	int i, xbuf_size, ybuf_size, buffer_size, mask_size;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
994
	DRM_DEBUG("\n");
Linus Torvalds's avatar
Linus Torvalds committed
995 996 997 998 999 1000 1001

	count = depth->n;
	if (count > 4096 || count <= 0)
		return DRM_ERR(EMSGSIZE);

	xbuf_size = count * sizeof(*x);
	ybuf_size = count * sizeof(*y);
Dave Airlie's avatar
Dave Airlie committed
1002 1003
	x = drm_alloc(xbuf_size, DRM_MEM_BUFS);
	if (x == NULL) {
Linus Torvalds's avatar
Linus Torvalds committed
1004 1005
		return DRM_ERR(ENOMEM);
	}
Dave Airlie's avatar
Dave Airlie committed
1006 1007 1008
	y = drm_alloc(ybuf_size, DRM_MEM_BUFS);
	if (y == NULL) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1009 1010
		return DRM_ERR(ENOMEM);
	}
Dave Airlie's avatar
Dave Airlie committed
1011 1012 1013
	if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
		drm_free(y, ybuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1014 1015
		return DRM_ERR(EFAULT);
	}
Dave Airlie's avatar
Dave Airlie committed
1016 1017 1018
	if (DRM_COPY_FROM_USER(y, depth->y, xbuf_size)) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
		drm_free(y, ybuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1019 1020 1021 1022
		return DRM_ERR(EFAULT);
	}

	buffer_size = depth->n * sizeof(u32);
Dave Airlie's avatar
Dave Airlie committed
1023 1024 1025 1026
	buffer = drm_alloc(buffer_size, DRM_MEM_BUFS);
	if (buffer == NULL) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
		drm_free(y, ybuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1027 1028
		return DRM_ERR(ENOMEM);
	}
Dave Airlie's avatar
Dave Airlie committed
1029 1030 1031 1032
	if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
		drm_free(y, ybuf_size, DRM_MEM_BUFS);
		drm_free(buffer, buffer_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1033 1034 1035
		return DRM_ERR(EFAULT);
	}

Dave Airlie's avatar
Dave Airlie committed
1036
	if (depth->mask) {
Linus Torvalds's avatar
Linus Torvalds committed
1037
		mask_size = depth->n * sizeof(u8);
Dave Airlie's avatar
Dave Airlie committed
1038 1039 1040 1041 1042
		mask = drm_alloc(mask_size, DRM_MEM_BUFS);
		if (mask == NULL) {
			drm_free(x, xbuf_size, DRM_MEM_BUFS);
			drm_free(y, ybuf_size, DRM_MEM_BUFS);
			drm_free(buffer, buffer_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1043 1044
			return DRM_ERR(ENOMEM);
		}
Dave Airlie's avatar
Dave Airlie committed
1045 1046 1047 1048 1049
		if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) {
			drm_free(x, xbuf_size, DRM_MEM_BUFS);
			drm_free(y, ybuf_size, DRM_MEM_BUFS);
			drm_free(buffer, buffer_size, DRM_MEM_BUFS);
			drm_free(mask, mask_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1050 1051 1052
			return DRM_ERR(EFAULT);
		}

Dave Airlie's avatar
Dave Airlie committed
1053 1054 1055
		for (i = 0; i < count; i++) {
			if (mask[i]) {
				BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
1056

Dave Airlie's avatar
Dave Airlie committed
1057 1058 1059 1060 1061 1062 1063 1064
				OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
				OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
					 R128_GMC_BRUSH_SOLID_COLOR |
					 (dev_priv->depth_fmt << 8) |
					 R128_GMC_SRC_DATATYPE_COLOR |
					 R128_ROP3_P |
					 R128_GMC_CLR_CMP_CNTL_DIS |
					 R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
1065

Dave Airlie's avatar
Dave Airlie committed
1066 1067
				OUT_RING(dev_priv->depth_pitch_offset_c);
				OUT_RING(buffer[i]);
Linus Torvalds's avatar
Linus Torvalds committed
1068

Dave Airlie's avatar
Dave Airlie committed
1069 1070
				OUT_RING((x[i] << 16) | y[i]);
				OUT_RING((1 << 16) | 1);
Linus Torvalds's avatar
Linus Torvalds committed
1071 1072 1073 1074 1075

				ADVANCE_RING();
			}
		}

Dave Airlie's avatar
Dave Airlie committed
1076
		drm_free(mask, mask_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1077
	} else {
Dave Airlie's avatar
Dave Airlie committed
1078 1079
		for (i = 0; i < count; i++) {
			BEGIN_RING(6);
Linus Torvalds's avatar
Linus Torvalds committed
1080

Dave Airlie's avatar
Dave Airlie committed
1081 1082 1083 1084 1085 1086 1087 1088
			OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4));
			OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL |
				 R128_GMC_BRUSH_SOLID_COLOR |
				 (dev_priv->depth_fmt << 8) |
				 R128_GMC_SRC_DATATYPE_COLOR |
				 R128_ROP3_P |
				 R128_GMC_CLR_CMP_CNTL_DIS |
				 R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
1089

Dave Airlie's avatar
Dave Airlie committed
1090 1091
			OUT_RING(dev_priv->depth_pitch_offset_c);
			OUT_RING(buffer[i]);
Linus Torvalds's avatar
Linus Torvalds committed
1092

Dave Airlie's avatar
Dave Airlie committed
1093 1094
			OUT_RING((x[i] << 16) | y[i]);
			OUT_RING((1 << 16) | 1);
Linus Torvalds's avatar
Linus Torvalds committed
1095 1096 1097 1098 1099

			ADVANCE_RING();
		}
	}

Dave Airlie's avatar
Dave Airlie committed
1100 1101 1102
	drm_free(x, xbuf_size, DRM_MEM_BUFS);
	drm_free(y, ybuf_size, DRM_MEM_BUFS);
	drm_free(buffer, buffer_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1103 1104 1105 1106

	return 0;
}

Dave Airlie's avatar
Dave Airlie committed
1107 1108
static int r128_cce_dispatch_read_span(drm_device_t * dev,
				       drm_r128_depth_t * depth)
Linus Torvalds's avatar
Linus Torvalds committed
1109 1110 1111 1112
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	int count, x, y;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
1113
	DRM_DEBUG("\n");
Linus Torvalds's avatar
Linus Torvalds committed
1114 1115 1116 1117 1118

	count = depth->n;
	if (count > 4096 || count <= 0)
		return DRM_ERR(EMSGSIZE);

Dave Airlie's avatar
Dave Airlie committed
1119
	if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) {
Linus Torvalds's avatar
Linus Torvalds committed
1120 1121
		return DRM_ERR(EFAULT);
	}
Dave Airlie's avatar
Dave Airlie committed
1122
	if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) {
Linus Torvalds's avatar
Linus Torvalds committed
1123 1124 1125
		return DRM_ERR(EFAULT);
	}

Dave Airlie's avatar
Dave Airlie committed
1126
	BEGIN_RING(7);
Linus Torvalds's avatar
Linus Torvalds committed
1127

Dave Airlie's avatar
Dave Airlie committed
1128 1129 1130 1131 1132 1133 1134 1135 1136
	OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
	OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
		 R128_GMC_DST_PITCH_OFFSET_CNTL |
		 R128_GMC_BRUSH_NONE |
		 (dev_priv->depth_fmt << 8) |
		 R128_GMC_SRC_DATATYPE_COLOR |
		 R128_ROP3_S |
		 R128_DP_SRC_SOURCE_MEMORY |
		 R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
1137

Dave Airlie's avatar
Dave Airlie committed
1138 1139
	OUT_RING(dev_priv->depth_pitch_offset_c);
	OUT_RING(dev_priv->span_pitch_offset_c);
Linus Torvalds's avatar
Linus Torvalds committed
1140

Dave Airlie's avatar
Dave Airlie committed
1141 1142 1143
	OUT_RING((x << 16) | y);
	OUT_RING((0 << 16) | 0);
	OUT_RING((count << 16) | 1);
Linus Torvalds's avatar
Linus Torvalds committed
1144 1145 1146 1147 1148 1149

	ADVANCE_RING();

	return 0;
}

Dave Airlie's avatar
Dave Airlie committed
1150 1151
static int r128_cce_dispatch_read_pixels(drm_device_t * dev,
					 drm_r128_depth_t * depth)
Linus Torvalds's avatar
Linus Torvalds committed
1152 1153 1154 1155 1156
{
	drm_r128_private_t *dev_priv = dev->dev_private;
	int count, *x, *y;
	int i, xbuf_size, ybuf_size;
	RING_LOCALS;
Dave Airlie's avatar
Dave Airlie committed
1157
	DRM_DEBUG("%s\n", __FUNCTION__);
Linus Torvalds's avatar
Linus Torvalds committed
1158 1159 1160 1161 1162

	count = depth->n;
	if (count > 4096 || count <= 0)
		return DRM_ERR(EMSGSIZE);

Dave Airlie's avatar
Dave Airlie committed
1163
	if (count > dev_priv->depth_pitch) {
Linus Torvalds's avatar
Linus Torvalds committed
1164 1165 1166 1167 1168
		count = dev_priv->depth_pitch;
	}

	xbuf_size = count * sizeof(*x);
	ybuf_size = count * sizeof(*y);
Dave Airlie's avatar
Dave Airlie committed
1169 1170
	x = drm_alloc(xbuf_size, DRM_MEM_BUFS);
	if (x == NULL) {
Linus Torvalds's avatar
Linus Torvalds committed
1171 1172
		return DRM_ERR(ENOMEM);
	}
Dave Airlie's avatar
Dave Airlie committed
1173 1174 1175
	y = drm_alloc(ybuf_size, DRM_MEM_BUFS);
	if (y == NULL) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1176 1177
		return DRM_ERR(ENOMEM);
	}
Dave Airlie's avatar
Dave Airlie committed
1178 1179 1180
	if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
		drm_free(y, ybuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1181 1182
		return DRM_ERR(EFAULT);
	}
Dave Airlie's avatar
Dave Airlie committed
1183 1184 1185
	if (DRM_COPY_FROM_USER(y, depth->y, ybuf_size)) {
		drm_free(x, xbuf_size, DRM_MEM_BUFS);
		drm_free(y, ybuf_size, DRM_MEM_BUFS);
Linus Torvalds's avatar
Linus Torvalds committed
1186 1187 1188
		return DRM_ERR(EFAULT);
	}

Dave Airlie's avatar
Dave Airlie committed
1189 1190
	for (i = 0; i < count; i++) {
		BEGIN_RING(7);
Linus Torvalds's avatar
Linus Torvalds committed
1191

Dave Airlie's avatar
Dave Airlie committed
1192 1193 1194 1195 1196 1197 1198 1199 1200
		OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5));
		OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL |
			 R128_GMC_DST_PITCH_OFFSET_CNTL |
			 R128_GMC_BRUSH_NONE |
			 (dev_priv->depth_fmt << 8) |
			 R128_GMC_SRC_DATATYPE_COLOR |
			 R128_ROP3_S |
			 R128_DP_SRC_SOURCE_MEMORY |
			 R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS);
Linus Torvalds's avatar
Linus Torvalds committed
1201

Dave Airlie's avatar
Dave Airlie committed
1202 1203
		OUT_RING(dev_priv->depth_pitch_offset_c);
		OUT_RING(dev_priv->span_pitch_offset_c);