1 /* r128_state.c -- State support for r128 -*- linux-c -*-
2 * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com
5 * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California.
8 * Permission is hereby granted, free of charge, to any person obtaining a
9 * copy of this software and associated documentation files (the "Software"),
10 * to deal in the Software without restriction, including without limitation
11 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
12 * and/or sell copies of the Software, and to permit persons to whom the
13 * Software is furnished to do so, subject to the following conditions:
15 * The above copyright notice and this permission notice (including the next
16 * paragraph) shall be included in all copies or substantial portions of the
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
20 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * PRECISION INSIGHT 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 OTHER
25 * DEALINGS IN THE SOFTWARE.
28 * Gareth Hughes <gareth@valinux.com>
32 #include <drm/r128_drm.h>
35 /* ================================================================
36 * CCE hardware state programming functions
39 static void r128_emit_clip_rects(drm_r128_private_t
*dev_priv
,
40 struct drm_clip_rect
*boxes
, int count
)
42 u32 aux_sc_cntl
= 0x00000000;
46 BEGIN_RING((count
< 3 ? count
: 3) * 5 + 2);
49 OUT_RING(CCE_PACKET0(R128_AUX1_SC_LEFT
, 3));
50 OUT_RING(boxes
[0].x1
);
51 OUT_RING(boxes
[0].x2
- 1);
52 OUT_RING(boxes
[0].y1
);
53 OUT_RING(boxes
[0].y2
- 1);
55 aux_sc_cntl
|= (R128_AUX1_SC_EN
| R128_AUX1_SC_MODE_OR
);
58 OUT_RING(CCE_PACKET0(R128_AUX2_SC_LEFT
, 3));
59 OUT_RING(boxes
[1].x1
);
60 OUT_RING(boxes
[1].x2
- 1);
61 OUT_RING(boxes
[1].y1
);
62 OUT_RING(boxes
[1].y2
- 1);
64 aux_sc_cntl
|= (R128_AUX2_SC_EN
| R128_AUX2_SC_MODE_OR
);
67 OUT_RING(CCE_PACKET0(R128_AUX3_SC_LEFT
, 3));
68 OUT_RING(boxes
[2].x1
);
69 OUT_RING(boxes
[2].x2
- 1);
70 OUT_RING(boxes
[2].y1
);
71 OUT_RING(boxes
[2].y2
- 1);
73 aux_sc_cntl
|= (R128_AUX3_SC_EN
| R128_AUX3_SC_MODE_OR
);
76 OUT_RING(CCE_PACKET0(R128_AUX_SC_CNTL
, 0));
77 OUT_RING(aux_sc_cntl
);
82 static __inline__
void r128_emit_core(drm_r128_private_t
*dev_priv
)
84 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
85 drm_r128_context_regs_t
*ctx
= &sarea_priv
->context_state
;
91 OUT_RING(CCE_PACKET0(R128_SCALE_3D_CNTL
, 0));
92 OUT_RING(ctx
->scale_3d_cntl
);
97 static __inline__
void r128_emit_context(drm_r128_private_t
*dev_priv
)
99 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
100 drm_r128_context_regs_t
*ctx
= &sarea_priv
->context_state
;
106 OUT_RING(CCE_PACKET0(R128_DST_PITCH_OFFSET_C
, 11));
107 OUT_RING(ctx
->dst_pitch_offset_c
);
108 OUT_RING(ctx
->dp_gui_master_cntl_c
);
109 OUT_RING(ctx
->sc_top_left_c
);
110 OUT_RING(ctx
->sc_bottom_right_c
);
111 OUT_RING(ctx
->z_offset_c
);
112 OUT_RING(ctx
->z_pitch_c
);
113 OUT_RING(ctx
->z_sten_cntl_c
);
114 OUT_RING(ctx
->tex_cntl_c
);
115 OUT_RING(ctx
->misc_3d_state_cntl_reg
);
116 OUT_RING(ctx
->texture_clr_cmp_clr_c
);
117 OUT_RING(ctx
->texture_clr_cmp_msk_c
);
118 OUT_RING(ctx
->fog_color_c
);
123 static __inline__
void r128_emit_setup(drm_r128_private_t
*dev_priv
)
125 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
126 drm_r128_context_regs_t
*ctx
= &sarea_priv
->context_state
;
132 OUT_RING(CCE_PACKET1(R128_SETUP_CNTL
, R128_PM4_VC_FPU_SETUP
));
133 OUT_RING(ctx
->setup_cntl
);
134 OUT_RING(ctx
->pm4_vc_fpu_setup
);
139 static __inline__
void r128_emit_masks(drm_r128_private_t
*dev_priv
)
141 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
142 drm_r128_context_regs_t
*ctx
= &sarea_priv
->context_state
;
148 OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK
, 0));
149 OUT_RING(ctx
->dp_write_mask
);
151 OUT_RING(CCE_PACKET0(R128_STEN_REF_MASK_C
, 1));
152 OUT_RING(ctx
->sten_ref_mask_c
);
153 OUT_RING(ctx
->plane_3d_mask_c
);
158 static __inline__
void r128_emit_window(drm_r128_private_t
*dev_priv
)
160 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
161 drm_r128_context_regs_t
*ctx
= &sarea_priv
->context_state
;
167 OUT_RING(CCE_PACKET0(R128_WINDOW_XY_OFFSET
, 0));
168 OUT_RING(ctx
->window_xy_offset
);
173 static __inline__
void r128_emit_tex0(drm_r128_private_t
*dev_priv
)
175 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
176 drm_r128_context_regs_t
*ctx
= &sarea_priv
->context_state
;
177 drm_r128_texture_regs_t
*tex
= &sarea_priv
->tex_state
[0];
182 BEGIN_RING(7 + R128_MAX_TEXTURE_LEVELS
);
184 OUT_RING(CCE_PACKET0(R128_PRIM_TEX_CNTL_C
,
185 2 + R128_MAX_TEXTURE_LEVELS
));
186 OUT_RING(tex
->tex_cntl
);
187 OUT_RING(tex
->tex_combine_cntl
);
188 OUT_RING(ctx
->tex_size_pitch_c
);
189 for (i
= 0; i
< R128_MAX_TEXTURE_LEVELS
; i
++)
190 OUT_RING(tex
->tex_offset
[i
]);
192 OUT_RING(CCE_PACKET0(R128_CONSTANT_COLOR_C
, 1));
193 OUT_RING(ctx
->constant_color_c
);
194 OUT_RING(tex
->tex_border_color
);
199 static __inline__
void r128_emit_tex1(drm_r128_private_t
*dev_priv
)
201 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
202 drm_r128_texture_regs_t
*tex
= &sarea_priv
->tex_state
[1];
207 BEGIN_RING(5 + R128_MAX_TEXTURE_LEVELS
);
209 OUT_RING(CCE_PACKET0(R128_SEC_TEX_CNTL_C
, 1 + R128_MAX_TEXTURE_LEVELS
));
210 OUT_RING(tex
->tex_cntl
);
211 OUT_RING(tex
->tex_combine_cntl
);
212 for (i
= 0; i
< R128_MAX_TEXTURE_LEVELS
; i
++)
213 OUT_RING(tex
->tex_offset
[i
]);
215 OUT_RING(CCE_PACKET0(R128_SEC_TEXTURE_BORDER_COLOR_C
, 0));
216 OUT_RING(tex
->tex_border_color
);
221 static void r128_emit_state(drm_r128_private_t
*dev_priv
)
223 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
224 unsigned int dirty
= sarea_priv
->dirty
;
226 DRM_DEBUG("dirty=0x%08x\n", dirty
);
228 if (dirty
& R128_UPLOAD_CORE
) {
229 r128_emit_core(dev_priv
);
230 sarea_priv
->dirty
&= ~R128_UPLOAD_CORE
;
233 if (dirty
& R128_UPLOAD_CONTEXT
) {
234 r128_emit_context(dev_priv
);
235 sarea_priv
->dirty
&= ~R128_UPLOAD_CONTEXT
;
238 if (dirty
& R128_UPLOAD_SETUP
) {
239 r128_emit_setup(dev_priv
);
240 sarea_priv
->dirty
&= ~R128_UPLOAD_SETUP
;
243 if (dirty
& R128_UPLOAD_MASKS
) {
244 r128_emit_masks(dev_priv
);
245 sarea_priv
->dirty
&= ~R128_UPLOAD_MASKS
;
248 if (dirty
& R128_UPLOAD_WINDOW
) {
249 r128_emit_window(dev_priv
);
250 sarea_priv
->dirty
&= ~R128_UPLOAD_WINDOW
;
253 if (dirty
& R128_UPLOAD_TEX0
) {
254 r128_emit_tex0(dev_priv
);
255 sarea_priv
->dirty
&= ~R128_UPLOAD_TEX0
;
258 if (dirty
& R128_UPLOAD_TEX1
) {
259 r128_emit_tex1(dev_priv
);
260 sarea_priv
->dirty
&= ~R128_UPLOAD_TEX1
;
263 /* Turn off the texture cache flushing */
264 sarea_priv
->context_state
.tex_cntl_c
&= ~R128_TEX_CACHE_FLUSH
;
266 sarea_priv
->dirty
&= ~R128_REQUIRE_QUIESCENCE
;
269 #if R128_PERFORMANCE_BOXES
270 /* ================================================================
271 * Performance monitoring functions
274 static void r128_clear_box(drm_r128_private_t
*dev_priv
,
275 int x
, int y
, int w
, int h
, int r
, int g
, int b
)
281 switch (dev_priv
->fb_bpp
) {
283 fb_bpp
= R128_GMC_DST_16BPP
;
284 color
= (((r
& 0xf8) << 8) |
285 ((g
& 0xfc) << 3) | ((b
& 0xf8) >> 3));
288 fb_bpp
= R128_GMC_DST_24BPP
;
289 color
= ((r
<< 16) | (g
<< 8) | b
);
292 fb_bpp
= R128_GMC_DST_32BPP
;
293 color
= (((0xff) << 24) | (r
<< 16) | (g
<< 8) | b
);
299 offset
= dev_priv
->back_offset
;
300 pitch
= dev_priv
->back_pitch
>> 3;
304 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
305 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
306 R128_GMC_BRUSH_SOLID_COLOR
|
308 R128_GMC_SRC_DATATYPE_COLOR
|
310 R128_GMC_CLR_CMP_CNTL_DIS
| R128_GMC_AUX_CLIP_DIS
);
312 OUT_RING((pitch
<< 21) | (offset
>> 5));
315 OUT_RING((x
<< 16) | y
);
316 OUT_RING((w
<< 16) | h
);
321 static void r128_cce_performance_boxes(drm_r128_private_t
*dev_priv
)
323 if (atomic_read(&dev_priv
->idle_count
) == 0)
324 r128_clear_box(dev_priv
, 64, 4, 8, 8, 0, 255, 0);
326 atomic_set(&dev_priv
->idle_count
, 0);
331 /* ================================================================
332 * CCE command dispatch functions
335 static void r128_print_dirty(const char *msg
, unsigned int flags
)
337 DRM_INFO("%s: (0x%x) %s%s%s%s%s%s%s%s%s\n",
340 (flags
& R128_UPLOAD_CORE
) ? "core, " : "",
341 (flags
& R128_UPLOAD_CONTEXT
) ? "context, " : "",
342 (flags
& R128_UPLOAD_SETUP
) ? "setup, " : "",
343 (flags
& R128_UPLOAD_TEX0
) ? "tex0, " : "",
344 (flags
& R128_UPLOAD_TEX1
) ? "tex1, " : "",
345 (flags
& R128_UPLOAD_MASKS
) ? "masks, " : "",
346 (flags
& R128_UPLOAD_WINDOW
) ? "window, " : "",
347 (flags
& R128_UPLOAD_CLIPRECTS
) ? "cliprects, " : "",
348 (flags
& R128_REQUIRE_QUIESCENCE
) ? "quiescence, " : "");
351 static void r128_cce_dispatch_clear(struct drm_device
*dev
,
352 drm_r128_clear_t
*clear
)
354 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
355 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
356 int nbox
= sarea_priv
->nbox
;
357 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
358 unsigned int flags
= clear
->flags
;
363 if (dev_priv
->page_flipping
&& dev_priv
->current_page
== 1) {
364 unsigned int tmp
= flags
;
366 flags
&= ~(R128_FRONT
| R128_BACK
);
367 if (tmp
& R128_FRONT
)
373 for (i
= 0; i
< nbox
; i
++) {
376 int w
= pbox
[i
].x2
- x
;
377 int h
= pbox
[i
].y2
- y
;
379 DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n",
380 pbox
[i
].x1
, pbox
[i
].y1
, pbox
[i
].x2
,
383 if (flags
& (R128_FRONT
| R128_BACK
)) {
386 OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK
, 0));
387 OUT_RING(clear
->color_mask
);
392 if (flags
& R128_FRONT
) {
395 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
396 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
397 R128_GMC_BRUSH_SOLID_COLOR
|
398 (dev_priv
->color_fmt
<< 8) |
399 R128_GMC_SRC_DATATYPE_COLOR
|
401 R128_GMC_CLR_CMP_CNTL_DIS
|
402 R128_GMC_AUX_CLIP_DIS
);
404 OUT_RING(dev_priv
->front_pitch_offset_c
);
405 OUT_RING(clear
->clear_color
);
407 OUT_RING((x
<< 16) | y
);
408 OUT_RING((w
<< 16) | h
);
413 if (flags
& R128_BACK
) {
416 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
417 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
418 R128_GMC_BRUSH_SOLID_COLOR
|
419 (dev_priv
->color_fmt
<< 8) |
420 R128_GMC_SRC_DATATYPE_COLOR
|
422 R128_GMC_CLR_CMP_CNTL_DIS
|
423 R128_GMC_AUX_CLIP_DIS
);
425 OUT_RING(dev_priv
->back_pitch_offset_c
);
426 OUT_RING(clear
->clear_color
);
428 OUT_RING((x
<< 16) | y
);
429 OUT_RING((w
<< 16) | h
);
434 if (flags
& R128_DEPTH
) {
437 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
438 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
439 R128_GMC_BRUSH_SOLID_COLOR
|
440 (dev_priv
->depth_fmt
<< 8) |
441 R128_GMC_SRC_DATATYPE_COLOR
|
443 R128_GMC_CLR_CMP_CNTL_DIS
|
444 R128_GMC_AUX_CLIP_DIS
| R128_GMC_WR_MSK_DIS
);
446 OUT_RING(dev_priv
->depth_pitch_offset_c
);
447 OUT_RING(clear
->clear_depth
);
449 OUT_RING((x
<< 16) | y
);
450 OUT_RING((w
<< 16) | h
);
457 static void r128_cce_dispatch_swap(struct drm_device
*dev
)
459 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
460 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
461 int nbox
= sarea_priv
->nbox
;
462 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
467 #if R128_PERFORMANCE_BOXES
468 /* Do some trivial performance monitoring...
470 r128_cce_performance_boxes(dev_priv
);
473 for (i
= 0; i
< nbox
; i
++) {
476 int w
= pbox
[i
].x2
- x
;
477 int h
= pbox
[i
].y2
- y
;
481 OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI
, 5));
482 OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL
|
483 R128_GMC_DST_PITCH_OFFSET_CNTL
|
484 R128_GMC_BRUSH_NONE
|
485 (dev_priv
->color_fmt
<< 8) |
486 R128_GMC_SRC_DATATYPE_COLOR
|
488 R128_DP_SRC_SOURCE_MEMORY
|
489 R128_GMC_CLR_CMP_CNTL_DIS
|
490 R128_GMC_AUX_CLIP_DIS
| R128_GMC_WR_MSK_DIS
);
492 /* Make this work even if front & back are flipped:
494 if (dev_priv
->current_page
== 0) {
495 OUT_RING(dev_priv
->back_pitch_offset_c
);
496 OUT_RING(dev_priv
->front_pitch_offset_c
);
498 OUT_RING(dev_priv
->front_pitch_offset_c
);
499 OUT_RING(dev_priv
->back_pitch_offset_c
);
502 OUT_RING((x
<< 16) | y
);
503 OUT_RING((x
<< 16) | y
);
504 OUT_RING((w
<< 16) | h
);
509 /* Increment the frame counter. The client-side 3D driver must
510 * throttle the framerate by waiting for this value before
511 * performing the swapbuffer ioctl.
513 dev_priv
->sarea_priv
->last_frame
++;
517 OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG
, 0));
518 OUT_RING(dev_priv
->sarea_priv
->last_frame
);
523 static void r128_cce_dispatch_flip(struct drm_device
*dev
)
525 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
527 DRM_DEBUG("page=%d pfCurrentPage=%d\n",
528 dev_priv
->current_page
, dev_priv
->sarea_priv
->pfCurrentPage
);
530 #if R128_PERFORMANCE_BOXES
531 /* Do some trivial performance monitoring...
533 r128_cce_performance_boxes(dev_priv
);
538 R128_WAIT_UNTIL_PAGE_FLIPPED();
539 OUT_RING(CCE_PACKET0(R128_CRTC_OFFSET
, 0));
541 if (dev_priv
->current_page
== 0)
542 OUT_RING(dev_priv
->back_offset
);
544 OUT_RING(dev_priv
->front_offset
);
548 /* Increment the frame counter. The client-side 3D driver must
549 * throttle the framerate by waiting for this value before
550 * performing the swapbuffer ioctl.
552 dev_priv
->sarea_priv
->last_frame
++;
553 dev_priv
->sarea_priv
->pfCurrentPage
= dev_priv
->current_page
=
554 1 - dev_priv
->current_page
;
558 OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG
, 0));
559 OUT_RING(dev_priv
->sarea_priv
->last_frame
);
564 static void r128_cce_dispatch_vertex(struct drm_device
*dev
, struct drm_buf
*buf
)
566 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
567 drm_r128_buf_priv_t
*buf_priv
= buf
->dev_private
;
568 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
569 int format
= sarea_priv
->vc_format
;
570 int offset
= buf
->bus_address
;
571 int size
= buf
->used
;
572 int prim
= buf_priv
->prim
;
575 DRM_DEBUG("buf=%d nbox=%d\n", buf
->idx
, sarea_priv
->nbox
);
578 r128_print_dirty("dispatch_vertex", sarea_priv
->dirty
);
581 buf_priv
->dispatched
= 1;
583 if (sarea_priv
->dirty
& ~R128_UPLOAD_CLIPRECTS
)
584 r128_emit_state(dev_priv
);
587 /* Emit the next set of up to three cliprects */
588 if (i
< sarea_priv
->nbox
) {
589 r128_emit_clip_rects(dev_priv
,
590 &sarea_priv
->boxes
[i
],
591 sarea_priv
->nbox
- i
);
594 /* Emit the vertex buffer rendering commands */
597 OUT_RING(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM
, 3));
601 OUT_RING(prim
| R128_CCE_VC_CNTL_PRIM_WALK_LIST
|
602 (size
<< R128_CCE_VC_CNTL_NUM_SHIFT
));
607 } while (i
< sarea_priv
->nbox
);
610 if (buf_priv
->discard
) {
611 buf_priv
->age
= dev_priv
->sarea_priv
->last_dispatch
;
613 /* Emit the vertex buffer age */
616 OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG
, 0));
617 OUT_RING(buf_priv
->age
);
623 /* FIXME: Check dispatched field */
624 buf_priv
->dispatched
= 0;
627 dev_priv
->sarea_priv
->last_dispatch
++;
629 sarea_priv
->dirty
&= ~R128_UPLOAD_CLIPRECTS
;
630 sarea_priv
->nbox
= 0;
633 static void r128_cce_dispatch_indirect(struct drm_device
*dev
,
634 struct drm_buf
*buf
, int start
, int end
)
636 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
637 drm_r128_buf_priv_t
*buf_priv
= buf
->dev_private
;
639 DRM_DEBUG("indirect: buf=%d s=0x%x e=0x%x\n", buf
->idx
, start
, end
);
642 int offset
= buf
->bus_address
+ start
;
643 int dwords
= (end
- start
+ 3) / sizeof(u32
);
645 /* Indirect buffer data must be an even number of
646 * dwords, so if we've been given an odd number we must
647 * pad the data with a Type-2 CCE packet.
651 ((char *)dev
->agp_buffer_map
->handle
652 + buf
->offset
+ start
);
653 data
[dwords
++] = cpu_to_le32(R128_CCE_PACKET2
);
656 buf_priv
->dispatched
= 1;
658 /* Fire off the indirect buffer */
661 OUT_RING(CCE_PACKET0(R128_PM4_IW_INDOFF
, 1));
668 if (buf_priv
->discard
) {
669 buf_priv
->age
= dev_priv
->sarea_priv
->last_dispatch
;
671 /* Emit the indirect buffer age */
674 OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG
, 0));
675 OUT_RING(buf_priv
->age
);
681 /* FIXME: Check dispatched field */
682 buf_priv
->dispatched
= 0;
685 dev_priv
->sarea_priv
->last_dispatch
++;
688 static void r128_cce_dispatch_indices(struct drm_device
*dev
,
690 int start
, int end
, int count
)
692 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
693 drm_r128_buf_priv_t
*buf_priv
= buf
->dev_private
;
694 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
695 int format
= sarea_priv
->vc_format
;
696 int offset
= dev
->agp_buffer_map
->offset
- dev_priv
->cce_buffers_offset
;
697 int prim
= buf_priv
->prim
;
702 DRM_DEBUG("indices: s=%d e=%d c=%d\n", start
, end
, count
);
705 r128_print_dirty("dispatch_indices", sarea_priv
->dirty
);
708 buf_priv
->dispatched
= 1;
710 if (sarea_priv
->dirty
& ~R128_UPLOAD_CLIPRECTS
)
711 r128_emit_state(dev_priv
);
713 dwords
= (end
- start
+ 3) / sizeof(u32
);
715 data
= (u32
*) ((char *)dev
->agp_buffer_map
->handle
716 + buf
->offset
+ start
);
718 data
[0] = cpu_to_le32(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM
,
721 data
[1] = cpu_to_le32(offset
);
722 data
[2] = cpu_to_le32(R128_MAX_VB_VERTS
);
723 data
[3] = cpu_to_le32(format
);
724 data
[4] = cpu_to_le32((prim
| R128_CCE_VC_CNTL_PRIM_WALK_IND
|
728 #ifdef __LITTLE_ENDIAN
729 data
[dwords
- 1] &= 0x0000ffff;
731 data
[dwords
- 1] &= 0xffff0000;
736 /* Emit the next set of up to three cliprects */
737 if (i
< sarea_priv
->nbox
) {
738 r128_emit_clip_rects(dev_priv
,
739 &sarea_priv
->boxes
[i
],
740 sarea_priv
->nbox
- i
);
743 r128_cce_dispatch_indirect(dev
, buf
, start
, end
);
746 } while (i
< sarea_priv
->nbox
);
749 if (buf_priv
->discard
) {
750 buf_priv
->age
= dev_priv
->sarea_priv
->last_dispatch
;
752 /* Emit the vertex buffer age */
755 OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG
, 0));
756 OUT_RING(buf_priv
->age
);
761 /* FIXME: Check dispatched field */
762 buf_priv
->dispatched
= 0;
765 dev_priv
->sarea_priv
->last_dispatch
++;
767 sarea_priv
->dirty
&= ~R128_UPLOAD_CLIPRECTS
;
768 sarea_priv
->nbox
= 0;
771 static int r128_cce_dispatch_blit(struct drm_device
*dev
,
772 struct drm_file
*file_priv
,
773 drm_r128_blit_t
*blit
)
775 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
776 struct drm_device_dma
*dma
= dev
->dma
;
778 drm_r128_buf_priv_t
*buf_priv
;
780 int dword_shift
, dwords
;
784 /* The compiler won't optimize away a division by a variable,
785 * even if the only legal values are powers of two. Thus, we'll
786 * use a shift instead.
788 switch (blit
->format
) {
789 case R128_DATATYPE_ARGB8888
:
792 case R128_DATATYPE_ARGB1555
:
793 case R128_DATATYPE_RGB565
:
794 case R128_DATATYPE_ARGB4444
:
795 case R128_DATATYPE_YVYU422
:
796 case R128_DATATYPE_VYUY422
:
799 case R128_DATATYPE_CI8
:
800 case R128_DATATYPE_RGB8
:
804 DRM_ERROR("invalid blit format %d\n", blit
->format
);
808 /* Flush the pixel cache, and mark the contents as Read Invalid.
809 * This ensures no pixel data gets mixed up with the texture
810 * data from the host data blit, otherwise part of the texture
811 * image may be corrupted.
815 OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT
, 0));
816 OUT_RING(R128_PC_RI_GUI
| R128_PC_FLUSH_GUI
);
820 /* Dispatch the indirect buffer.
822 buf
= dma
->buflist
[blit
->idx
];
823 buf_priv
= buf
->dev_private
;
825 if (buf
->file_priv
!= file_priv
) {
826 DRM_ERROR("process %d using buffer owned by %p\n",
827 DRM_CURRENTPID
, buf
->file_priv
);
831 DRM_ERROR("sending pending buffer %d\n", blit
->idx
);
835 buf_priv
->discard
= 1;
837 dwords
= (blit
->width
* blit
->height
) >> dword_shift
;
839 data
= (u32
*) ((char *)dev
->agp_buffer_map
->handle
+ buf
->offset
);
841 data
[0] = cpu_to_le32(CCE_PACKET3(R128_CNTL_HOSTDATA_BLT
, dwords
+ 6));
842 data
[1] = cpu_to_le32((R128_GMC_DST_PITCH_OFFSET_CNTL
|
843 R128_GMC_BRUSH_NONE
|
844 (blit
->format
<< 8) |
845 R128_GMC_SRC_DATATYPE_COLOR
|
847 R128_DP_SRC_SOURCE_HOST_DATA
|
848 R128_GMC_CLR_CMP_CNTL_DIS
|
849 R128_GMC_AUX_CLIP_DIS
| R128_GMC_WR_MSK_DIS
));
851 data
[2] = cpu_to_le32((blit
->pitch
<< 21) | (blit
->offset
>> 5));
852 data
[3] = cpu_to_le32(0xffffffff);
853 data
[4] = cpu_to_le32(0xffffffff);
854 data
[5] = cpu_to_le32((blit
->y
<< 16) | blit
->x
);
855 data
[6] = cpu_to_le32((blit
->height
<< 16) | blit
->width
);
856 data
[7] = cpu_to_le32(dwords
);
858 buf
->used
= (dwords
+ 8) * sizeof(u32
);
860 r128_cce_dispatch_indirect(dev
, buf
, 0, buf
->used
);
862 /* Flush the pixel cache after the blit completes. This ensures
863 * the texture data is written out to memory before rendering
868 OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT
, 0));
869 OUT_RING(R128_PC_FLUSH_GUI
);
876 /* ================================================================
877 * Tiled depth buffer management
879 * FIXME: These should all set the destination write mask for when we
880 * have hardware stencil support.
883 static int r128_cce_dispatch_write_span(struct drm_device
*dev
,
884 drm_r128_depth_t
*depth
)
886 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
890 int i
, buffer_size
, mask_size
;
895 if (count
> 4096 || count
<= 0)
898 if (copy_from_user(&x
, depth
->x
, sizeof(x
)))
900 if (copy_from_user(&y
, depth
->y
, sizeof(y
)))
903 buffer_size
= depth
->n
* sizeof(u32
);
904 buffer
= memdup_user(depth
->buffer
, buffer_size
);
906 return PTR_ERR(buffer
);
908 mask_size
= depth
->n
;
910 mask
= memdup_user(depth
->mask
, mask_size
);
913 return PTR_ERR(mask
);
916 for (i
= 0; i
< count
; i
++, x
++) {
920 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
921 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
922 R128_GMC_BRUSH_SOLID_COLOR
|
923 (dev_priv
->depth_fmt
<< 8) |
924 R128_GMC_SRC_DATATYPE_COLOR
|
926 R128_GMC_CLR_CMP_CNTL_DIS
|
927 R128_GMC_WR_MSK_DIS
);
929 OUT_RING(dev_priv
->depth_pitch_offset_c
);
932 OUT_RING((x
<< 16) | y
);
933 OUT_RING((1 << 16) | 1);
941 for (i
= 0; i
< count
; i
++, x
++) {
944 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
945 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
946 R128_GMC_BRUSH_SOLID_COLOR
|
947 (dev_priv
->depth_fmt
<< 8) |
948 R128_GMC_SRC_DATATYPE_COLOR
|
950 R128_GMC_CLR_CMP_CNTL_DIS
|
951 R128_GMC_WR_MSK_DIS
);
953 OUT_RING(dev_priv
->depth_pitch_offset_c
);
956 OUT_RING((x
<< 16) | y
);
957 OUT_RING((1 << 16) | 1);
968 static int r128_cce_dispatch_write_pixels(struct drm_device
*dev
,
969 drm_r128_depth_t
*depth
)
971 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
975 int i
, xbuf_size
, ybuf_size
, buffer_size
, mask_size
;
980 if (count
> 4096 || count
<= 0)
983 xbuf_size
= count
* sizeof(*x
);
984 ybuf_size
= count
* sizeof(*y
);
985 x
= memdup_user(depth
->x
, xbuf_size
);
988 y
= memdup_user(depth
->y
, ybuf_size
);
993 buffer_size
= depth
->n
* sizeof(u32
);
994 buffer
= memdup_user(depth
->buffer
, buffer_size
);
995 if (IS_ERR(buffer
)) {
998 return PTR_ERR(buffer
);
1002 mask_size
= depth
->n
;
1003 mask
= memdup_user(depth
->mask
, mask_size
);
1008 return PTR_ERR(mask
);
1011 for (i
= 0; i
< count
; i
++) {
1015 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
1016 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
1017 R128_GMC_BRUSH_SOLID_COLOR
|
1018 (dev_priv
->depth_fmt
<< 8) |
1019 R128_GMC_SRC_DATATYPE_COLOR
|
1021 R128_GMC_CLR_CMP_CNTL_DIS
|
1022 R128_GMC_WR_MSK_DIS
);
1024 OUT_RING(dev_priv
->depth_pitch_offset_c
);
1025 OUT_RING(buffer
[i
]);
1027 OUT_RING((x
[i
] << 16) | y
[i
]);
1028 OUT_RING((1 << 16) | 1);
1036 for (i
= 0; i
< count
; i
++) {
1039 OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI
, 4));
1040 OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL
|
1041 R128_GMC_BRUSH_SOLID_COLOR
|
1042 (dev_priv
->depth_fmt
<< 8) |
1043 R128_GMC_SRC_DATATYPE_COLOR
|
1045 R128_GMC_CLR_CMP_CNTL_DIS
|
1046 R128_GMC_WR_MSK_DIS
);
1048 OUT_RING(dev_priv
->depth_pitch_offset_c
);
1049 OUT_RING(buffer
[i
]);
1051 OUT_RING((x
[i
] << 16) | y
[i
]);
1052 OUT_RING((1 << 16) | 1);
1065 static int r128_cce_dispatch_read_span(struct drm_device
*dev
,
1066 drm_r128_depth_t
*depth
)
1068 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1074 if (count
> 4096 || count
<= 0)
1077 if (copy_from_user(&x
, depth
->x
, sizeof(x
)))
1079 if (copy_from_user(&y
, depth
->y
, sizeof(y
)))
1084 OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI
, 5));
1085 OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL
|
1086 R128_GMC_DST_PITCH_OFFSET_CNTL
|
1087 R128_GMC_BRUSH_NONE
|
1088 (dev_priv
->depth_fmt
<< 8) |
1089 R128_GMC_SRC_DATATYPE_COLOR
|
1091 R128_DP_SRC_SOURCE_MEMORY
|
1092 R128_GMC_CLR_CMP_CNTL_DIS
| R128_GMC_WR_MSK_DIS
);
1094 OUT_RING(dev_priv
->depth_pitch_offset_c
);
1095 OUT_RING(dev_priv
->span_pitch_offset_c
);
1097 OUT_RING((x
<< 16) | y
);
1098 OUT_RING((0 << 16) | 0);
1099 OUT_RING((count
<< 16) | 1);
1106 static int r128_cce_dispatch_read_pixels(struct drm_device
*dev
,
1107 drm_r128_depth_t
*depth
)
1109 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1111 int i
, xbuf_size
, ybuf_size
;
1116 if (count
> 4096 || count
<= 0)
1119 if (count
> dev_priv
->depth_pitch
)
1120 count
= dev_priv
->depth_pitch
;
1122 xbuf_size
= count
* sizeof(*x
);
1123 ybuf_size
= count
* sizeof(*y
);
1124 x
= kmalloc(xbuf_size
, GFP_KERNEL
);
1127 y
= kmalloc(ybuf_size
, GFP_KERNEL
);
1132 if (copy_from_user(x
, depth
->x
, xbuf_size
)) {
1137 if (copy_from_user(y
, depth
->y
, ybuf_size
)) {
1143 for (i
= 0; i
< count
; i
++) {
1146 OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI
, 5));
1147 OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL
|
1148 R128_GMC_DST_PITCH_OFFSET_CNTL
|
1149 R128_GMC_BRUSH_NONE
|
1150 (dev_priv
->depth_fmt
<< 8) |
1151 R128_GMC_SRC_DATATYPE_COLOR
|
1153 R128_DP_SRC_SOURCE_MEMORY
|
1154 R128_GMC_CLR_CMP_CNTL_DIS
| R128_GMC_WR_MSK_DIS
);
1156 OUT_RING(dev_priv
->depth_pitch_offset_c
);
1157 OUT_RING(dev_priv
->span_pitch_offset_c
);
1159 OUT_RING((x
[i
] << 16) | y
[i
]);
1160 OUT_RING((i
<< 16) | 0);
1161 OUT_RING((1 << 16) | 1);
1172 /* ================================================================
1176 static void r128_cce_dispatch_stipple(struct drm_device
*dev
, u32
*stipple
)
1178 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1185 OUT_RING(CCE_PACKET0(R128_BRUSH_DATA0
, 31));
1186 for (i
= 0; i
< 32; i
++)
1187 OUT_RING(stipple
[i
]);
1192 /* ================================================================
1196 static int r128_cce_clear(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1198 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1199 drm_r128_sarea_t
*sarea_priv
;
1200 drm_r128_clear_t
*clear
= data
;
1203 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1205 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1207 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1209 sarea_priv
= dev_priv
->sarea_priv
;
1211 if (sarea_priv
->nbox
> R128_NR_SAREA_CLIPRECTS
)
1212 sarea_priv
->nbox
= R128_NR_SAREA_CLIPRECTS
;
1214 r128_cce_dispatch_clear(dev
, clear
);
1217 /* Make sure we restore the 3D state next time.
1219 dev_priv
->sarea_priv
->dirty
|= R128_UPLOAD_CONTEXT
| R128_UPLOAD_MASKS
;
1224 static int r128_do_init_pageflip(struct drm_device
*dev
)
1226 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1229 dev_priv
->crtc_offset
= R128_READ(R128_CRTC_OFFSET
);
1230 dev_priv
->crtc_offset_cntl
= R128_READ(R128_CRTC_OFFSET_CNTL
);
1232 R128_WRITE(R128_CRTC_OFFSET
, dev_priv
->front_offset
);
1233 R128_WRITE(R128_CRTC_OFFSET_CNTL
,
1234 dev_priv
->crtc_offset_cntl
| R128_CRTC_OFFSET_FLIP_CNTL
);
1236 dev_priv
->page_flipping
= 1;
1237 dev_priv
->current_page
= 0;
1238 dev_priv
->sarea_priv
->pfCurrentPage
= dev_priv
->current_page
;
1243 static int r128_do_cleanup_pageflip(struct drm_device
*dev
)
1245 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1248 R128_WRITE(R128_CRTC_OFFSET
, dev_priv
->crtc_offset
);
1249 R128_WRITE(R128_CRTC_OFFSET_CNTL
, dev_priv
->crtc_offset_cntl
);
1251 if (dev_priv
->current_page
!= 0) {
1252 r128_cce_dispatch_flip(dev
);
1256 dev_priv
->page_flipping
= 0;
1260 /* Swapping and flipping are different operations, need different ioctls.
1261 * They can & should be intermixed to support multiple 3d windows.
1264 static int r128_cce_flip(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1266 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1269 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1271 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1273 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1275 if (!dev_priv
->page_flipping
)
1276 r128_do_init_pageflip(dev
);
1278 r128_cce_dispatch_flip(dev
);
1284 static int r128_cce_swap(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1286 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1287 drm_r128_sarea_t
*sarea_priv
= dev_priv
->sarea_priv
;
1290 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1292 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1294 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1296 if (sarea_priv
->nbox
> R128_NR_SAREA_CLIPRECTS
)
1297 sarea_priv
->nbox
= R128_NR_SAREA_CLIPRECTS
;
1299 r128_cce_dispatch_swap(dev
);
1300 dev_priv
->sarea_priv
->dirty
|= (R128_UPLOAD_CONTEXT
|
1307 static int r128_cce_vertex(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1309 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1310 struct drm_device_dma
*dma
= dev
->dma
;
1311 struct drm_buf
*buf
;
1312 drm_r128_buf_priv_t
*buf_priv
;
1313 drm_r128_vertex_t
*vertex
= data
;
1315 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1317 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1319 DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
1320 DRM_CURRENTPID
, vertex
->idx
, vertex
->count
, vertex
->discard
);
1322 if (vertex
->idx
< 0 || vertex
->idx
>= dma
->buf_count
) {
1323 DRM_ERROR("buffer index %d (of %d max)\n",
1324 vertex
->idx
, dma
->buf_count
- 1);
1327 if (vertex
->prim
< 0 ||
1328 vertex
->prim
> R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2
) {
1329 DRM_ERROR("buffer prim %d\n", vertex
->prim
);
1333 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1334 VB_AGE_TEST_WITH_RETURN(dev_priv
);
1336 buf
= dma
->buflist
[vertex
->idx
];
1337 buf_priv
= buf
->dev_private
;
1339 if (buf
->file_priv
!= file_priv
) {
1340 DRM_ERROR("process %d using buffer owned by %p\n",
1341 DRM_CURRENTPID
, buf
->file_priv
);
1345 DRM_ERROR("sending pending buffer %d\n", vertex
->idx
);
1349 buf
->used
= vertex
->count
;
1350 buf_priv
->prim
= vertex
->prim
;
1351 buf_priv
->discard
= vertex
->discard
;
1353 r128_cce_dispatch_vertex(dev
, buf
);
1359 static int r128_cce_indices(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1361 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1362 struct drm_device_dma
*dma
= dev
->dma
;
1363 struct drm_buf
*buf
;
1364 drm_r128_buf_priv_t
*buf_priv
;
1365 drm_r128_indices_t
*elts
= data
;
1368 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1370 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1372 DRM_DEBUG("pid=%d buf=%d s=%d e=%d d=%d\n", DRM_CURRENTPID
,
1373 elts
->idx
, elts
->start
, elts
->end
, elts
->discard
);
1375 if (elts
->idx
< 0 || elts
->idx
>= dma
->buf_count
) {
1376 DRM_ERROR("buffer index %d (of %d max)\n",
1377 elts
->idx
, dma
->buf_count
- 1);
1380 if (elts
->prim
< 0 ||
1381 elts
->prim
> R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2
) {
1382 DRM_ERROR("buffer prim %d\n", elts
->prim
);
1386 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1387 VB_AGE_TEST_WITH_RETURN(dev_priv
);
1389 buf
= dma
->buflist
[elts
->idx
];
1390 buf_priv
= buf
->dev_private
;
1392 if (buf
->file_priv
!= file_priv
) {
1393 DRM_ERROR("process %d using buffer owned by %p\n",
1394 DRM_CURRENTPID
, buf
->file_priv
);
1398 DRM_ERROR("sending pending buffer %d\n", elts
->idx
);
1402 count
= (elts
->end
- elts
->start
) / sizeof(u16
);
1403 elts
->start
-= R128_INDEX_PRIM_OFFSET
;
1405 if (elts
->start
& 0x7) {
1406 DRM_ERROR("misaligned buffer 0x%x\n", elts
->start
);
1409 if (elts
->start
< buf
->used
) {
1410 DRM_ERROR("no header 0x%x - 0x%x\n", elts
->start
, buf
->used
);
1414 buf
->used
= elts
->end
;
1415 buf_priv
->prim
= elts
->prim
;
1416 buf_priv
->discard
= elts
->discard
;
1418 r128_cce_dispatch_indices(dev
, buf
, elts
->start
, elts
->end
, count
);
1424 static int r128_cce_blit(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1426 struct drm_device_dma
*dma
= dev
->dma
;
1427 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1428 drm_r128_blit_t
*blit
= data
;
1431 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1433 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1435 DRM_DEBUG("pid=%d index=%d\n", DRM_CURRENTPID
, blit
->idx
);
1437 if (blit
->idx
< 0 || blit
->idx
>= dma
->buf_count
) {
1438 DRM_ERROR("buffer index %d (of %d max)\n",
1439 blit
->idx
, dma
->buf_count
- 1);
1443 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1444 VB_AGE_TEST_WITH_RETURN(dev_priv
);
1446 ret
= r128_cce_dispatch_blit(dev
, file_priv
, blit
);
1452 int r128_cce_depth(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1454 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1455 drm_r128_depth_t
*depth
= data
;
1458 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1460 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1462 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1465 switch (depth
->func
) {
1466 case R128_WRITE_SPAN
:
1467 ret
= r128_cce_dispatch_write_span(dev
, depth
);
1469 case R128_WRITE_PIXELS
:
1470 ret
= r128_cce_dispatch_write_pixels(dev
, depth
);
1472 case R128_READ_SPAN
:
1473 ret
= r128_cce_dispatch_read_span(dev
, depth
);
1475 case R128_READ_PIXELS
:
1476 ret
= r128_cce_dispatch_read_pixels(dev
, depth
);
1484 int r128_cce_stipple(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1486 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1487 drm_r128_stipple_t
*stipple
= data
;
1490 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1492 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1494 if (copy_from_user(&mask
, stipple
->mask
, 32 * sizeof(u32
)))
1497 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1499 r128_cce_dispatch_stipple(dev
, mask
);
1505 static int r128_cce_indirect(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1507 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1508 struct drm_device_dma
*dma
= dev
->dma
;
1509 struct drm_buf
*buf
;
1510 drm_r128_buf_priv_t
*buf_priv
;
1511 drm_r128_indirect_t
*indirect
= data
;
1516 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
1518 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1520 DRM_DEBUG("idx=%d s=%d e=%d d=%d\n",
1521 indirect
->idx
, indirect
->start
, indirect
->end
,
1524 if (indirect
->idx
< 0 || indirect
->idx
>= dma
->buf_count
) {
1525 DRM_ERROR("buffer index %d (of %d max)\n",
1526 indirect
->idx
, dma
->buf_count
- 1);
1530 buf
= dma
->buflist
[indirect
->idx
];
1531 buf_priv
= buf
->dev_private
;
1533 if (buf
->file_priv
!= file_priv
) {
1534 DRM_ERROR("process %d using buffer owned by %p\n",
1535 DRM_CURRENTPID
, buf
->file_priv
);
1539 DRM_ERROR("sending pending buffer %d\n", indirect
->idx
);
1543 if (indirect
->start
< buf
->used
) {
1544 DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
1545 indirect
->start
, buf
->used
);
1549 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
1550 VB_AGE_TEST_WITH_RETURN(dev_priv
);
1552 buf
->used
= indirect
->end
;
1553 buf_priv
->discard
= indirect
->discard
;
1556 /* Wait for the 3D stream to idle before the indirect buffer
1557 * containing 2D acceleration commands is processed.
1560 RADEON_WAIT_UNTIL_3D_IDLE();
1564 /* Dispatch the indirect buffer full of commands from the
1565 * X server. This is insecure and is thus only available to
1566 * privileged clients.
1568 r128_cce_dispatch_indirect(dev
, buf
, indirect
->start
, indirect
->end
);
1574 int r128_getparam(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
1576 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1577 drm_r128_getparam_t
*param
= data
;
1580 DEV_INIT_TEST_WITH_RETURN(dev_priv
);
1582 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID
);
1584 switch (param
->param
) {
1585 case R128_PARAM_IRQ_NR
:
1586 value
= dev
->pdev
->irq
;
1592 if (copy_to_user(param
->value
, &value
, sizeof(int))) {
1593 DRM_ERROR("copy_to_user\n");
1600 void r128_driver_preclose(struct drm_device
*dev
, struct drm_file
*file_priv
)
1602 if (dev
->dev_private
) {
1603 drm_r128_private_t
*dev_priv
= dev
->dev_private
;
1604 if (dev_priv
->page_flipping
)
1605 r128_do_cleanup_pageflip(dev
);
1608 void r128_driver_lastclose(struct drm_device
*dev
)
1610 r128_do_cleanup_cce(dev
);
1613 const struct drm_ioctl_desc r128_ioctls
[] = {
1614 DRM_IOCTL_DEF_DRV(R128_INIT
, r128_cce_init
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1615 DRM_IOCTL_DEF_DRV(R128_CCE_START
, r128_cce_start
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1616 DRM_IOCTL_DEF_DRV(R128_CCE_STOP
, r128_cce_stop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1617 DRM_IOCTL_DEF_DRV(R128_CCE_RESET
, r128_cce_reset
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1618 DRM_IOCTL_DEF_DRV(R128_CCE_IDLE
, r128_cce_idle
, DRM_AUTH
),
1619 DRM_IOCTL_DEF_DRV(R128_RESET
, r128_engine_reset
, DRM_AUTH
),
1620 DRM_IOCTL_DEF_DRV(R128_FULLSCREEN
, r128_fullscreen
, DRM_AUTH
),
1621 DRM_IOCTL_DEF_DRV(R128_SWAP
, r128_cce_swap
, DRM_AUTH
),
1622 DRM_IOCTL_DEF_DRV(R128_FLIP
, r128_cce_flip
, DRM_AUTH
),
1623 DRM_IOCTL_DEF_DRV(R128_CLEAR
, r128_cce_clear
, DRM_AUTH
),
1624 DRM_IOCTL_DEF_DRV(R128_VERTEX
, r128_cce_vertex
, DRM_AUTH
),
1625 DRM_IOCTL_DEF_DRV(R128_INDICES
, r128_cce_indices
, DRM_AUTH
),
1626 DRM_IOCTL_DEF_DRV(R128_BLIT
, r128_cce_blit
, DRM_AUTH
),
1627 DRM_IOCTL_DEF_DRV(R128_DEPTH
, r128_cce_depth
, DRM_AUTH
),
1628 DRM_IOCTL_DEF_DRV(R128_STIPPLE
, r128_cce_stipple
, DRM_AUTH
),
1629 DRM_IOCTL_DEF_DRV(R128_INDIRECT
, r128_cce_indirect
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
1630 DRM_IOCTL_DEF_DRV(R128_GETPARAM
, r128_getparam
, DRM_AUTH
),
1633 int r128_max_ioctl
= ARRAY_SIZE(r128_ioctls
);