1 /* radeon_state.c -- State support for Radeon -*- linux-c -*- */
3 * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
21 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
22 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
23 * DEALINGS IN THE SOFTWARE.
26 * Gareth Hughes <gareth@valinux.com>
27 * Kevin E. Martin <martin@valinux.com>
32 #include "drm_buffer.h"
33 #include "drm_sarea.h"
34 #include "radeon_drm.h"
35 #include "radeon_drv.h"
37 /* ================================================================
38 * Helper functions for client state checking and fixup
41 static __inline__
int radeon_check_and_fixup_offset(drm_radeon_private_t
*
43 struct drm_file
* file_priv
,
47 u32 fb_end
= dev_priv
->fb_location
+ dev_priv
->fb_size
- 1;
48 struct drm_radeon_driver_file_fields
*radeon_priv
;
50 /* Hrm ... the story of the offset ... So this function converts
51 * the various ideas of what userland clients might have for an
52 * offset in the card address space into an offset into the card
53 * address space :) So with a sane client, it should just keep
54 * the value intact and just do some boundary checking. However,
55 * not all clients are sane. Some older clients pass us 0 based
56 * offsets relative to the start of the framebuffer and some may
57 * assume the AGP aperture it appended to the framebuffer, so we
58 * try to detect those cases and fix them up.
60 * Note: It might be a good idea here to make sure the offset lands
61 * in some "allowed" area to protect things like the PCIE GART...
64 /* First, the best case, the offset already lands in either the
65 * framebuffer or the GART mapped space
67 if (radeon_check_offset(dev_priv
, off
))
70 /* Ok, that didn't happen... now check if we have a zero based
71 * offset that fits in the framebuffer + gart space, apply the
72 * magic offset we get from SETPARAM or calculated from fb_location
74 if (off
< (dev_priv
->fb_size
+ dev_priv
->gart_size
)) {
75 radeon_priv
= file_priv
->driver_priv
;
76 off
+= radeon_priv
->radeon_fb_delta
;
79 /* Finally, assume we aimed at a GART offset if beyond the fb */
81 off
= off
- fb_end
- 1 + dev_priv
->gart_vm_start
;
83 /* Now recheck and fail if out of bounds */
84 if (radeon_check_offset(dev_priv
, off
)) {
85 DRM_DEBUG("offset fixed up to 0x%x\n", (unsigned int)off
);
92 static __inline__
int radeon_check_and_fixup_packets(drm_radeon_private_t
*
94 struct drm_file
*file_priv
,
95 int id
, struct drm_buffer
*buf
)
100 case RADEON_EMIT_PP_MISC
:
101 data
= drm_buffer_pointer_to_dword(buf
,
102 (RADEON_RB3D_DEPTHOFFSET
- RADEON_PP_MISC
) / 4);
104 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, data
)) {
105 DRM_ERROR("Invalid depth buffer offset\n");
108 dev_priv
->have_z_offset
= 1;
111 case RADEON_EMIT_PP_CNTL
:
112 data
= drm_buffer_pointer_to_dword(buf
,
113 (RADEON_RB3D_COLOROFFSET
- RADEON_PP_CNTL
) / 4);
115 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, data
)) {
116 DRM_ERROR("Invalid colour buffer offset\n");
121 case R200_EMIT_PP_TXOFFSET_0
:
122 case R200_EMIT_PP_TXOFFSET_1
:
123 case R200_EMIT_PP_TXOFFSET_2
:
124 case R200_EMIT_PP_TXOFFSET_3
:
125 case R200_EMIT_PP_TXOFFSET_4
:
126 case R200_EMIT_PP_TXOFFSET_5
:
127 data
= drm_buffer_pointer_to_dword(buf
, 0);
128 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, data
)) {
129 DRM_ERROR("Invalid R200 texture offset\n");
134 case RADEON_EMIT_PP_TXFILTER_0
:
135 case RADEON_EMIT_PP_TXFILTER_1
:
136 case RADEON_EMIT_PP_TXFILTER_2
:
137 data
= drm_buffer_pointer_to_dword(buf
,
138 (RADEON_PP_TXOFFSET_0
- RADEON_PP_TXFILTER_0
) / 4);
139 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, data
)) {
140 DRM_ERROR("Invalid R100 texture offset\n");
145 case R200_EMIT_PP_CUBIC_OFFSETS_0
:
146 case R200_EMIT_PP_CUBIC_OFFSETS_1
:
147 case R200_EMIT_PP_CUBIC_OFFSETS_2
:
148 case R200_EMIT_PP_CUBIC_OFFSETS_3
:
149 case R200_EMIT_PP_CUBIC_OFFSETS_4
:
150 case R200_EMIT_PP_CUBIC_OFFSETS_5
:{
152 for (i
= 0; i
< 5; i
++) {
153 data
= drm_buffer_pointer_to_dword(buf
, i
);
154 if (radeon_check_and_fixup_offset(dev_priv
,
158 ("Invalid R200 cubic texture offset\n");
165 case RADEON_EMIT_PP_CUBIC_OFFSETS_T0
:
166 case RADEON_EMIT_PP_CUBIC_OFFSETS_T1
:
167 case RADEON_EMIT_PP_CUBIC_OFFSETS_T2
:{
169 for (i
= 0; i
< 5; i
++) {
170 data
= drm_buffer_pointer_to_dword(buf
, i
);
171 if (radeon_check_and_fixup_offset(dev_priv
,
175 ("Invalid R100 cubic texture offset\n");
182 case R200_EMIT_VAP_CTL
:{
185 OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH
, 0);
190 case RADEON_EMIT_RB3D_COLORPITCH
:
191 case RADEON_EMIT_RE_LINE_PATTERN
:
192 case RADEON_EMIT_SE_LINE_WIDTH
:
193 case RADEON_EMIT_PP_LUM_MATRIX
:
194 case RADEON_EMIT_PP_ROT_MATRIX_0
:
195 case RADEON_EMIT_RB3D_STENCILREFMASK
:
196 case RADEON_EMIT_SE_VPORT_XSCALE
:
197 case RADEON_EMIT_SE_CNTL
:
198 case RADEON_EMIT_SE_CNTL_STATUS
:
199 case RADEON_EMIT_RE_MISC
:
200 case RADEON_EMIT_PP_BORDER_COLOR_0
:
201 case RADEON_EMIT_PP_BORDER_COLOR_1
:
202 case RADEON_EMIT_PP_BORDER_COLOR_2
:
203 case RADEON_EMIT_SE_ZBIAS_FACTOR
:
204 case RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT
:
205 case RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED
:
206 case R200_EMIT_PP_TXCBLEND_0
:
207 case R200_EMIT_PP_TXCBLEND_1
:
208 case R200_EMIT_PP_TXCBLEND_2
:
209 case R200_EMIT_PP_TXCBLEND_3
:
210 case R200_EMIT_PP_TXCBLEND_4
:
211 case R200_EMIT_PP_TXCBLEND_5
:
212 case R200_EMIT_PP_TXCBLEND_6
:
213 case R200_EMIT_PP_TXCBLEND_7
:
214 case R200_EMIT_TCL_LIGHT_MODEL_CTL_0
:
215 case R200_EMIT_TFACTOR_0
:
216 case R200_EMIT_VTX_FMT_0
:
217 case R200_EMIT_MATRIX_SELECT_0
:
218 case R200_EMIT_TEX_PROC_CTL_2
:
219 case R200_EMIT_TCL_UCP_VERT_BLEND_CTL
:
220 case R200_EMIT_PP_TXFILTER_0
:
221 case R200_EMIT_PP_TXFILTER_1
:
222 case R200_EMIT_PP_TXFILTER_2
:
223 case R200_EMIT_PP_TXFILTER_3
:
224 case R200_EMIT_PP_TXFILTER_4
:
225 case R200_EMIT_PP_TXFILTER_5
:
226 case R200_EMIT_VTE_CNTL
:
227 case R200_EMIT_OUTPUT_VTX_COMP_SEL
:
228 case R200_EMIT_PP_TAM_DEBUG3
:
229 case R200_EMIT_PP_CNTL_X
:
230 case R200_EMIT_RB3D_DEPTHXY_OFFSET
:
231 case R200_EMIT_RE_AUX_SCISSOR_CNTL
:
232 case R200_EMIT_RE_SCISSOR_TL_0
:
233 case R200_EMIT_RE_SCISSOR_TL_1
:
234 case R200_EMIT_RE_SCISSOR_TL_2
:
235 case R200_EMIT_SE_VAP_CNTL_STATUS
:
236 case R200_EMIT_SE_VTX_STATE_CNTL
:
237 case R200_EMIT_RE_POINTSIZE
:
238 case R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0
:
239 case R200_EMIT_PP_CUBIC_FACES_0
:
240 case R200_EMIT_PP_CUBIC_FACES_1
:
241 case R200_EMIT_PP_CUBIC_FACES_2
:
242 case R200_EMIT_PP_CUBIC_FACES_3
:
243 case R200_EMIT_PP_CUBIC_FACES_4
:
244 case R200_EMIT_PP_CUBIC_FACES_5
:
245 case RADEON_EMIT_PP_TEX_SIZE_0
:
246 case RADEON_EMIT_PP_TEX_SIZE_1
:
247 case RADEON_EMIT_PP_TEX_SIZE_2
:
248 case R200_EMIT_RB3D_BLENDCOLOR
:
249 case R200_EMIT_TCL_POINT_SPRITE_CNTL
:
250 case RADEON_EMIT_PP_CUBIC_FACES_0
:
251 case RADEON_EMIT_PP_CUBIC_FACES_1
:
252 case RADEON_EMIT_PP_CUBIC_FACES_2
:
253 case R200_EMIT_PP_TRI_PERF_CNTL
:
254 case R200_EMIT_PP_AFS_0
:
255 case R200_EMIT_PP_AFS_1
:
256 case R200_EMIT_ATF_TFACTOR
:
257 case R200_EMIT_PP_TXCTLALL_0
:
258 case R200_EMIT_PP_TXCTLALL_1
:
259 case R200_EMIT_PP_TXCTLALL_2
:
260 case R200_EMIT_PP_TXCTLALL_3
:
261 case R200_EMIT_PP_TXCTLALL_4
:
262 case R200_EMIT_PP_TXCTLALL_5
:
263 case R200_EMIT_VAP_PVS_CNTL
:
264 /* These packets don't contain memory offsets */
268 DRM_ERROR("Unknown state packet ID %d\n", id
);
275 static __inline__
int radeon_check_and_fixup_packet3(drm_radeon_private_t
*
277 struct drm_file
*file_priv
,
278 drm_radeon_kcmd_buffer_t
*
282 u32
*cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 0);
286 count
= ((*cmd
& RADEON_CP_PACKET_COUNT_MASK
) >> 16);
289 if ((*cmd
& 0xc0000000) != RADEON_CP_PACKET3
) {
290 DRM_ERROR("Not a type 3 packet\n");
294 if (4 * *cmdsz
> drm_buffer_unprocessed(cmdbuf
->buffer
)) {
295 DRM_ERROR("Packet size larger than size of data provided\n");
299 switch (*cmd
& 0xff00) {
300 /* XXX Are there old drivers needing other packets? */
302 case RADEON_3D_DRAW_IMMD
:
303 case RADEON_3D_DRAW_VBUF
:
304 case RADEON_3D_DRAW_INDX
:
305 case RADEON_WAIT_FOR_IDLE
:
307 case RADEON_3D_CLEAR_ZMASK
:
308 /* case RADEON_CP_NEXT_CHAR:
309 case RADEON_CP_PLY_NEXTSCAN:
310 case RADEON_CP_SET_SCISSORS: */ /* probably safe but will never need them? */
311 /* these packets are safe */
314 case RADEON_CP_3D_DRAW_IMMD_2
:
315 case RADEON_CP_3D_DRAW_VBUF_2
:
316 case RADEON_CP_3D_DRAW_INDX_2
:
317 case RADEON_3D_CLEAR_HIZ
:
318 /* safe but r200 only */
319 if (dev_priv
->microcode_version
!= UCODE_R200
) {
320 DRM_ERROR("Invalid 3d packet for r100-class chip\n");
325 case RADEON_3D_LOAD_VBPNTR
:
327 if (count
> 18) { /* 12 arrays max */
328 DRM_ERROR("Too large payload in 3D_LOAD_VBPNTR (count=%d)\n",
333 /* carefully check packet contents */
334 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 1);
336 narrays
= *cmd
& ~0xc000;
339 while ((k
< narrays
) && (i
< (count
+ 2))) {
340 i
++; /* skip attribute field */
341 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, i
);
342 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
,
345 ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
353 /* have one more to process, they come in pairs */
354 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, i
);
356 if (radeon_check_and_fixup_offset(dev_priv
,
360 ("Invalid offset (k=%d i=%d) in 3D_LOAD_VBPNTR packet.\n",
367 /* do the counts match what we expect ? */
368 if ((k
!= narrays
) || (i
!= (count
+ 2))) {
370 ("Malformed 3D_LOAD_VBPNTR packet (k=%d i=%d narrays=%d count+1=%d).\n",
371 k
, i
, narrays
, count
+ 1);
376 case RADEON_3D_RNDR_GEN_INDX_PRIM
:
377 if (dev_priv
->microcode_version
!= UCODE_R100
) {
378 DRM_ERROR("Invalid 3d packet for r200-class chip\n");
382 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 1);
383 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, cmd
)) {
384 DRM_ERROR("Invalid rndr_gen_indx offset\n");
389 case RADEON_CP_INDX_BUFFER
:
390 if (dev_priv
->microcode_version
!= UCODE_R200
) {
391 DRM_ERROR("Invalid 3d packet for r100-class chip\n");
395 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 1);
396 if ((*cmd
& 0x8000ffff) != 0x80000810) {
397 DRM_ERROR("Invalid indx_buffer reg address %08X\n", *cmd
);
400 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 2);
401 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, cmd
)) {
402 DRM_ERROR("Invalid indx_buffer offset is %08X\n", *cmd
);
407 case RADEON_CNTL_HOSTDATA_BLT
:
408 case RADEON_CNTL_PAINT_MULTI
:
409 case RADEON_CNTL_BITBLT_MULTI
:
410 /* MSB of opcode: next DWORD GUI_CNTL */
411 cmd
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 1);
412 if (*cmd
& (RADEON_GMC_SRC_PITCH_OFFSET_CNTL
413 | RADEON_GMC_DST_PITCH_OFFSET_CNTL
)) {
414 u32
*cmd2
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 2);
415 offset
= *cmd2
<< 10;
416 if (radeon_check_and_fixup_offset
417 (dev_priv
, file_priv
, &offset
)) {
418 DRM_ERROR("Invalid first packet offset\n");
421 *cmd2
= (*cmd2
& 0xffc00000) | offset
>> 10;
424 if ((*cmd
& RADEON_GMC_SRC_PITCH_OFFSET_CNTL
) &&
425 (*cmd
& RADEON_GMC_DST_PITCH_OFFSET_CNTL
)) {
426 u32
*cmd3
= drm_buffer_pointer_to_dword(cmdbuf
->buffer
, 3);
428 if (radeon_check_and_fixup_offset
429 (dev_priv
, file_priv
, &offset
)) {
430 DRM_ERROR("Invalid second packet offset\n");
433 *cmd3
= (*cmd3
& 0xffc00000) | offset
>> 10;
438 DRM_ERROR("Invalid packet type %x\n", *cmd
& 0xff00);
445 /* ================================================================
446 * CP hardware state programming functions
449 static __inline__
void radeon_emit_clip_rect(drm_radeon_private_t
* dev_priv
,
450 struct drm_clip_rect
* box
)
454 DRM_DEBUG(" box: x1=%d y1=%d x2=%d y2=%d\n",
455 box
->x1
, box
->y1
, box
->x2
, box
->y2
);
458 OUT_RING(CP_PACKET0(RADEON_RE_TOP_LEFT
, 0));
459 OUT_RING((box
->y1
<< 16) | box
->x1
);
460 OUT_RING(CP_PACKET0(RADEON_RE_WIDTH_HEIGHT
, 0));
461 OUT_RING(((box
->y2
- 1) << 16) | (box
->x2
- 1));
467 static int radeon_emit_state(drm_radeon_private_t
* dev_priv
,
468 struct drm_file
*file_priv
,
469 drm_radeon_context_regs_t
* ctx
,
470 drm_radeon_texture_regs_t
* tex
,
474 DRM_DEBUG("dirty=0x%08x\n", dirty
);
476 if (dirty
& RADEON_UPLOAD_CONTEXT
) {
477 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
,
478 &ctx
->rb3d_depthoffset
)) {
479 DRM_ERROR("Invalid depth buffer offset\n");
483 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
,
484 &ctx
->rb3d_coloroffset
)) {
485 DRM_ERROR("Invalid depth buffer offset\n");
490 OUT_RING(CP_PACKET0(RADEON_PP_MISC
, 6));
491 OUT_RING(ctx
->pp_misc
);
492 OUT_RING(ctx
->pp_fog_color
);
493 OUT_RING(ctx
->re_solid_color
);
494 OUT_RING(ctx
->rb3d_blendcntl
);
495 OUT_RING(ctx
->rb3d_depthoffset
);
496 OUT_RING(ctx
->rb3d_depthpitch
);
497 OUT_RING(ctx
->rb3d_zstencilcntl
);
498 OUT_RING(CP_PACKET0(RADEON_PP_CNTL
, 2));
499 OUT_RING(ctx
->pp_cntl
);
500 OUT_RING(ctx
->rb3d_cntl
);
501 OUT_RING(ctx
->rb3d_coloroffset
);
502 OUT_RING(CP_PACKET0(RADEON_RB3D_COLORPITCH
, 0));
503 OUT_RING(ctx
->rb3d_colorpitch
);
507 if (dirty
& RADEON_UPLOAD_VERTFMT
) {
509 OUT_RING(CP_PACKET0(RADEON_SE_COORD_FMT
, 0));
510 OUT_RING(ctx
->se_coord_fmt
);
514 if (dirty
& RADEON_UPLOAD_LINE
) {
516 OUT_RING(CP_PACKET0(RADEON_RE_LINE_PATTERN
, 1));
517 OUT_RING(ctx
->re_line_pattern
);
518 OUT_RING(ctx
->re_line_state
);
519 OUT_RING(CP_PACKET0(RADEON_SE_LINE_WIDTH
, 0));
520 OUT_RING(ctx
->se_line_width
);
524 if (dirty
& RADEON_UPLOAD_BUMPMAP
) {
526 OUT_RING(CP_PACKET0(RADEON_PP_LUM_MATRIX
, 0));
527 OUT_RING(ctx
->pp_lum_matrix
);
528 OUT_RING(CP_PACKET0(RADEON_PP_ROT_MATRIX_0
, 1));
529 OUT_RING(ctx
->pp_rot_matrix_0
);
530 OUT_RING(ctx
->pp_rot_matrix_1
);
534 if (dirty
& RADEON_UPLOAD_MASKS
) {
536 OUT_RING(CP_PACKET0(RADEON_RB3D_STENCILREFMASK
, 2));
537 OUT_RING(ctx
->rb3d_stencilrefmask
);
538 OUT_RING(ctx
->rb3d_ropcntl
);
539 OUT_RING(ctx
->rb3d_planemask
);
543 if (dirty
& RADEON_UPLOAD_VIEWPORT
) {
545 OUT_RING(CP_PACKET0(RADEON_SE_VPORT_XSCALE
, 5));
546 OUT_RING(ctx
->se_vport_xscale
);
547 OUT_RING(ctx
->se_vport_xoffset
);
548 OUT_RING(ctx
->se_vport_yscale
);
549 OUT_RING(ctx
->se_vport_yoffset
);
550 OUT_RING(ctx
->se_vport_zscale
);
551 OUT_RING(ctx
->se_vport_zoffset
);
555 if (dirty
& RADEON_UPLOAD_SETUP
) {
557 OUT_RING(CP_PACKET0(RADEON_SE_CNTL
, 0));
558 OUT_RING(ctx
->se_cntl
);
559 OUT_RING(CP_PACKET0(RADEON_SE_CNTL_STATUS
, 0));
560 OUT_RING(ctx
->se_cntl_status
);
564 if (dirty
& RADEON_UPLOAD_MISC
) {
566 OUT_RING(CP_PACKET0(RADEON_RE_MISC
, 0));
567 OUT_RING(ctx
->re_misc
);
571 if (dirty
& RADEON_UPLOAD_TEX0
) {
572 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
,
573 &tex
[0].pp_txoffset
)) {
574 DRM_ERROR("Invalid texture offset for unit 0\n");
579 OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_0
, 5));
580 OUT_RING(tex
[0].pp_txfilter
);
581 OUT_RING(tex
[0].pp_txformat
);
582 OUT_RING(tex
[0].pp_txoffset
);
583 OUT_RING(tex
[0].pp_txcblend
);
584 OUT_RING(tex
[0].pp_txablend
);
585 OUT_RING(tex
[0].pp_tfactor
);
586 OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_0
, 0));
587 OUT_RING(tex
[0].pp_border_color
);
591 if (dirty
& RADEON_UPLOAD_TEX1
) {
592 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
,
593 &tex
[1].pp_txoffset
)) {
594 DRM_ERROR("Invalid texture offset for unit 1\n");
599 OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_1
, 5));
600 OUT_RING(tex
[1].pp_txfilter
);
601 OUT_RING(tex
[1].pp_txformat
);
602 OUT_RING(tex
[1].pp_txoffset
);
603 OUT_RING(tex
[1].pp_txcblend
);
604 OUT_RING(tex
[1].pp_txablend
);
605 OUT_RING(tex
[1].pp_tfactor
);
606 OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_1
, 0));
607 OUT_RING(tex
[1].pp_border_color
);
611 if (dirty
& RADEON_UPLOAD_TEX2
) {
612 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
,
613 &tex
[2].pp_txoffset
)) {
614 DRM_ERROR("Invalid texture offset for unit 2\n");
619 OUT_RING(CP_PACKET0(RADEON_PP_TXFILTER_2
, 5));
620 OUT_RING(tex
[2].pp_txfilter
);
621 OUT_RING(tex
[2].pp_txformat
);
622 OUT_RING(tex
[2].pp_txoffset
);
623 OUT_RING(tex
[2].pp_txcblend
);
624 OUT_RING(tex
[2].pp_txablend
);
625 OUT_RING(tex
[2].pp_tfactor
);
626 OUT_RING(CP_PACKET0(RADEON_PP_BORDER_COLOR_2
, 0));
627 OUT_RING(tex
[2].pp_border_color
);
636 static int radeon_emit_state2(drm_radeon_private_t
* dev_priv
,
637 struct drm_file
*file_priv
,
638 drm_radeon_state_t
* state
)
642 if (state
->dirty
& RADEON_UPLOAD_ZBIAS
) {
644 OUT_RING(CP_PACKET0(RADEON_SE_ZBIAS_FACTOR
, 1));
645 OUT_RING(state
->context2
.se_zbias_factor
);
646 OUT_RING(state
->context2
.se_zbias_constant
);
650 return radeon_emit_state(dev_priv
, file_priv
, &state
->context
,
651 state
->tex
, state
->dirty
);
654 /* New (1.3) state mechanism. 3 commands (packet, scalar, vector) in
655 * 1.3 cmdbuffers allow all previous state to be updated as well as
656 * the tcl scalar and vector areas.
662 } packet
[RADEON_MAX_STATE_PACKETS
] = {
663 {RADEON_PP_MISC
, 7, "RADEON_PP_MISC"},
664 {RADEON_PP_CNTL
, 3, "RADEON_PP_CNTL"},
665 {RADEON_RB3D_COLORPITCH
, 1, "RADEON_RB3D_COLORPITCH"},
666 {RADEON_RE_LINE_PATTERN
, 2, "RADEON_RE_LINE_PATTERN"},
667 {RADEON_SE_LINE_WIDTH
, 1, "RADEON_SE_LINE_WIDTH"},
668 {RADEON_PP_LUM_MATRIX
, 1, "RADEON_PP_LUM_MATRIX"},
669 {RADEON_PP_ROT_MATRIX_0
, 2, "RADEON_PP_ROT_MATRIX_0"},
670 {RADEON_RB3D_STENCILREFMASK
, 3, "RADEON_RB3D_STENCILREFMASK"},
671 {RADEON_SE_VPORT_XSCALE
, 6, "RADEON_SE_VPORT_XSCALE"},
672 {RADEON_SE_CNTL
, 2, "RADEON_SE_CNTL"},
673 {RADEON_SE_CNTL_STATUS
, 1, "RADEON_SE_CNTL_STATUS"},
674 {RADEON_RE_MISC
, 1, "RADEON_RE_MISC"},
675 {RADEON_PP_TXFILTER_0
, 6, "RADEON_PP_TXFILTER_0"},
676 {RADEON_PP_BORDER_COLOR_0
, 1, "RADEON_PP_BORDER_COLOR_0"},
677 {RADEON_PP_TXFILTER_1
, 6, "RADEON_PP_TXFILTER_1"},
678 {RADEON_PP_BORDER_COLOR_1
, 1, "RADEON_PP_BORDER_COLOR_1"},
679 {RADEON_PP_TXFILTER_2
, 6, "RADEON_PP_TXFILTER_2"},
680 {RADEON_PP_BORDER_COLOR_2
, 1, "RADEON_PP_BORDER_COLOR_2"},
681 {RADEON_SE_ZBIAS_FACTOR
, 2, "RADEON_SE_ZBIAS_FACTOR"},
682 {RADEON_SE_TCL_OUTPUT_VTX_FMT
, 11, "RADEON_SE_TCL_OUTPUT_VTX_FMT"},
683 {RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED
, 17,
684 "RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED"},
685 {R200_PP_TXCBLEND_0
, 4, "R200_PP_TXCBLEND_0"},
686 {R200_PP_TXCBLEND_1
, 4, "R200_PP_TXCBLEND_1"},
687 {R200_PP_TXCBLEND_2
, 4, "R200_PP_TXCBLEND_2"},
688 {R200_PP_TXCBLEND_3
, 4, "R200_PP_TXCBLEND_3"},
689 {R200_PP_TXCBLEND_4
, 4, "R200_PP_TXCBLEND_4"},
690 {R200_PP_TXCBLEND_5
, 4, "R200_PP_TXCBLEND_5"},
691 {R200_PP_TXCBLEND_6
, 4, "R200_PP_TXCBLEND_6"},
692 {R200_PP_TXCBLEND_7
, 4, "R200_PP_TXCBLEND_7"},
693 {R200_SE_TCL_LIGHT_MODEL_CTL_0
, 6, "R200_SE_TCL_LIGHT_MODEL_CTL_0"},
694 {R200_PP_TFACTOR_0
, 6, "R200_PP_TFACTOR_0"},
695 {R200_SE_VTX_FMT_0
, 4, "R200_SE_VTX_FMT_0"},
696 {R200_SE_VAP_CNTL
, 1, "R200_SE_VAP_CNTL"},
697 {R200_SE_TCL_MATRIX_SEL_0
, 5, "R200_SE_TCL_MATRIX_SEL_0"},
698 {R200_SE_TCL_TEX_PROC_CTL_2
, 5, "R200_SE_TCL_TEX_PROC_CTL_2"},
699 {R200_SE_TCL_UCP_VERT_BLEND_CTL
, 1, "R200_SE_TCL_UCP_VERT_BLEND_CTL"},
700 {R200_PP_TXFILTER_0
, 6, "R200_PP_TXFILTER_0"},
701 {R200_PP_TXFILTER_1
, 6, "R200_PP_TXFILTER_1"},
702 {R200_PP_TXFILTER_2
, 6, "R200_PP_TXFILTER_2"},
703 {R200_PP_TXFILTER_3
, 6, "R200_PP_TXFILTER_3"},
704 {R200_PP_TXFILTER_4
, 6, "R200_PP_TXFILTER_4"},
705 {R200_PP_TXFILTER_5
, 6, "R200_PP_TXFILTER_5"},
706 {R200_PP_TXOFFSET_0
, 1, "R200_PP_TXOFFSET_0"},
707 {R200_PP_TXOFFSET_1
, 1, "R200_PP_TXOFFSET_1"},
708 {R200_PP_TXOFFSET_2
, 1, "R200_PP_TXOFFSET_2"},
709 {R200_PP_TXOFFSET_3
, 1, "R200_PP_TXOFFSET_3"},
710 {R200_PP_TXOFFSET_4
, 1, "R200_PP_TXOFFSET_4"},
711 {R200_PP_TXOFFSET_5
, 1, "R200_PP_TXOFFSET_5"},
712 {R200_SE_VTE_CNTL
, 1, "R200_SE_VTE_CNTL"},
713 {R200_SE_TCL_OUTPUT_VTX_COMP_SEL
, 1,
714 "R200_SE_TCL_OUTPUT_VTX_COMP_SEL"},
715 {R200_PP_TAM_DEBUG3
, 1, "R200_PP_TAM_DEBUG3"},
716 {R200_PP_CNTL_X
, 1, "R200_PP_CNTL_X"},
717 {R200_RB3D_DEPTHXY_OFFSET
, 1, "R200_RB3D_DEPTHXY_OFFSET"},
718 {R200_RE_AUX_SCISSOR_CNTL
, 1, "R200_RE_AUX_SCISSOR_CNTL"},
719 {R200_RE_SCISSOR_TL_0
, 2, "R200_RE_SCISSOR_TL_0"},
720 {R200_RE_SCISSOR_TL_1
, 2, "R200_RE_SCISSOR_TL_1"},
721 {R200_RE_SCISSOR_TL_2
, 2, "R200_RE_SCISSOR_TL_2"},
722 {R200_SE_VAP_CNTL_STATUS
, 1, "R200_SE_VAP_CNTL_STATUS"},
723 {R200_SE_VTX_STATE_CNTL
, 1, "R200_SE_VTX_STATE_CNTL"},
724 {R200_RE_POINTSIZE
, 1, "R200_RE_POINTSIZE"},
725 {R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0
, 4,
726 "R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0"},
727 {R200_PP_CUBIC_FACES_0
, 1, "R200_PP_CUBIC_FACES_0"}, /* 61 */
728 {R200_PP_CUBIC_OFFSET_F1_0
, 5, "R200_PP_CUBIC_OFFSET_F1_0"}, /* 62 */
729 {R200_PP_CUBIC_FACES_1
, 1, "R200_PP_CUBIC_FACES_1"},
730 {R200_PP_CUBIC_OFFSET_F1_1
, 5, "R200_PP_CUBIC_OFFSET_F1_1"},
731 {R200_PP_CUBIC_FACES_2
, 1, "R200_PP_CUBIC_FACES_2"},
732 {R200_PP_CUBIC_OFFSET_F1_2
, 5, "R200_PP_CUBIC_OFFSET_F1_2"},
733 {R200_PP_CUBIC_FACES_3
, 1, "R200_PP_CUBIC_FACES_3"},
734 {R200_PP_CUBIC_OFFSET_F1_3
, 5, "R200_PP_CUBIC_OFFSET_F1_3"},
735 {R200_PP_CUBIC_FACES_4
, 1, "R200_PP_CUBIC_FACES_4"},
736 {R200_PP_CUBIC_OFFSET_F1_4
, 5, "R200_PP_CUBIC_OFFSET_F1_4"},
737 {R200_PP_CUBIC_FACES_5
, 1, "R200_PP_CUBIC_FACES_5"},
738 {R200_PP_CUBIC_OFFSET_F1_5
, 5, "R200_PP_CUBIC_OFFSET_F1_5"},
739 {RADEON_PP_TEX_SIZE_0
, 2, "RADEON_PP_TEX_SIZE_0"},
740 {RADEON_PP_TEX_SIZE_1
, 2, "RADEON_PP_TEX_SIZE_1"},
741 {RADEON_PP_TEX_SIZE_2
, 2, "RADEON_PP_TEX_SIZE_2"},
742 {R200_RB3D_BLENDCOLOR
, 3, "R200_RB3D_BLENDCOLOR"},
743 {R200_SE_TCL_POINT_SPRITE_CNTL
, 1, "R200_SE_TCL_POINT_SPRITE_CNTL"},
744 {RADEON_PP_CUBIC_FACES_0
, 1, "RADEON_PP_CUBIC_FACES_0"},
745 {RADEON_PP_CUBIC_OFFSET_T0_0
, 5, "RADEON_PP_CUBIC_OFFSET_T0_0"},
746 {RADEON_PP_CUBIC_FACES_1
, 1, "RADEON_PP_CUBIC_FACES_1"},
747 {RADEON_PP_CUBIC_OFFSET_T1_0
, 5, "RADEON_PP_CUBIC_OFFSET_T1_0"},
748 {RADEON_PP_CUBIC_FACES_2
, 1, "RADEON_PP_CUBIC_FACES_2"},
749 {RADEON_PP_CUBIC_OFFSET_T2_0
, 5, "RADEON_PP_CUBIC_OFFSET_T2_0"},
750 {R200_PP_TRI_PERF
, 2, "R200_PP_TRI_PERF"},
751 {R200_PP_AFS_0
, 32, "R200_PP_AFS_0"}, /* 85 */
752 {R200_PP_AFS_1
, 32, "R200_PP_AFS_1"},
753 {R200_PP_TFACTOR_0
, 8, "R200_ATF_TFACTOR"},
754 {R200_PP_TXFILTER_0
, 8, "R200_PP_TXCTLALL_0"},
755 {R200_PP_TXFILTER_1
, 8, "R200_PP_TXCTLALL_1"},
756 {R200_PP_TXFILTER_2
, 8, "R200_PP_TXCTLALL_2"},
757 {R200_PP_TXFILTER_3
, 8, "R200_PP_TXCTLALL_3"},
758 {R200_PP_TXFILTER_4
, 8, "R200_PP_TXCTLALL_4"},
759 {R200_PP_TXFILTER_5
, 8, "R200_PP_TXCTLALL_5"},
760 {R200_VAP_PVS_CNTL_1
, 2, "R200_VAP_PVS_CNTL"},
763 /* ================================================================
764 * Performance monitoring functions
767 static void radeon_clear_box(drm_radeon_private_t
* dev_priv
,
768 struct drm_radeon_master_private
*master_priv
,
769 int x
, int y
, int w
, int h
, int r
, int g
, int b
)
774 x
+= master_priv
->sarea_priv
->boxes
[0].x1
;
775 y
+= master_priv
->sarea_priv
->boxes
[0].y1
;
777 switch (dev_priv
->color_fmt
) {
778 case RADEON_COLOR_FORMAT_RGB565
:
779 color
= (((r
& 0xf8) << 8) |
780 ((g
& 0xfc) << 3) | ((b
& 0xf8) >> 3));
782 case RADEON_COLOR_FORMAT_ARGB8888
:
784 color
= (((0xff) << 24) | (r
<< 16) | (g
<< 8) | b
);
789 RADEON_WAIT_UNTIL_3D_IDLE();
790 OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK
, 0));
791 OUT_RING(0xffffffff);
796 OUT_RING(CP_PACKET3(RADEON_CNTL_PAINT_MULTI
, 4));
797 OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL
|
798 RADEON_GMC_BRUSH_SOLID_COLOR
|
799 (dev_priv
->color_fmt
<< 8) |
800 RADEON_GMC_SRC_DATATYPE_COLOR
|
801 RADEON_ROP3_P
| RADEON_GMC_CLR_CMP_CNTL_DIS
);
803 if (master_priv
->sarea_priv
->pfCurrentPage
== 1) {
804 OUT_RING(dev_priv
->front_pitch_offset
);
806 OUT_RING(dev_priv
->back_pitch_offset
);
811 OUT_RING((x
<< 16) | y
);
812 OUT_RING((w
<< 16) | h
);
817 static void radeon_cp_performance_boxes(drm_radeon_private_t
*dev_priv
, struct drm_radeon_master_private
*master_priv
)
819 /* Collapse various things into a wait flag -- trying to
820 * guess if userspase slept -- better just to have them tell us.
822 if (dev_priv
->stats
.last_frame_reads
> 1 ||
823 dev_priv
->stats
.last_clear_reads
> dev_priv
->stats
.clears
) {
824 dev_priv
->stats
.boxes
|= RADEON_BOX_WAIT_IDLE
;
827 if (dev_priv
->stats
.freelist_loops
) {
828 dev_priv
->stats
.boxes
|= RADEON_BOX_WAIT_IDLE
;
831 /* Purple box for page flipping
833 if (dev_priv
->stats
.boxes
& RADEON_BOX_FLIP
)
834 radeon_clear_box(dev_priv
, master_priv
, 4, 4, 8, 8, 255, 0, 255);
836 /* Red box if we have to wait for idle at any point
838 if (dev_priv
->stats
.boxes
& RADEON_BOX_WAIT_IDLE
)
839 radeon_clear_box(dev_priv
, master_priv
, 16, 4, 8, 8, 255, 0, 0);
841 /* Blue box: lost context?
844 /* Yellow box for texture swaps
846 if (dev_priv
->stats
.boxes
& RADEON_BOX_TEXTURE_LOAD
)
847 radeon_clear_box(dev_priv
, master_priv
, 40, 4, 8, 8, 255, 255, 0);
849 /* Green box if hardware never idles (as far as we can tell)
851 if (!(dev_priv
->stats
.boxes
& RADEON_BOX_DMA_IDLE
))
852 radeon_clear_box(dev_priv
, master_priv
, 64, 4, 8, 8, 0, 255, 0);
854 /* Draw bars indicating number of buffers allocated
855 * (not a great measure, easily confused)
857 if (dev_priv
->stats
.requested_bufs
) {
858 if (dev_priv
->stats
.requested_bufs
> 100)
859 dev_priv
->stats
.requested_bufs
= 100;
861 radeon_clear_box(dev_priv
, master_priv
, 4, 16,
862 dev_priv
->stats
.requested_bufs
, 4,
866 memset(&dev_priv
->stats
, 0, sizeof(dev_priv
->stats
));
870 /* ================================================================
871 * CP command dispatch functions
874 static void radeon_cp_dispatch_clear(struct drm_device
* dev
,
875 struct drm_master
*master
,
876 drm_radeon_clear_t
* clear
,
877 drm_radeon_clear_rect_t
* depth_boxes
)
879 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
880 struct drm_radeon_master_private
*master_priv
= master
->driver_priv
;
881 drm_radeon_sarea_t
*sarea_priv
= master_priv
->sarea_priv
;
882 drm_radeon_depth_clear_t
*depth_clear
= &dev_priv
->depth_clear
;
883 int nbox
= sarea_priv
->nbox
;
884 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
885 unsigned int flags
= clear
->flags
;
886 u32 rb3d_cntl
= 0, rb3d_stencilrefmask
= 0;
889 DRM_DEBUG("flags = 0x%x\n", flags
);
891 dev_priv
->stats
.clears
++;
893 if (sarea_priv
->pfCurrentPage
== 1) {
894 unsigned int tmp
= flags
;
896 flags
&= ~(RADEON_FRONT
| RADEON_BACK
);
897 if (tmp
& RADEON_FRONT
)
898 flags
|= RADEON_BACK
;
899 if (tmp
& RADEON_BACK
)
900 flags
|= RADEON_FRONT
;
902 if (flags
& (RADEON_DEPTH
|RADEON_STENCIL
)) {
903 if (!dev_priv
->have_z_offset
)
904 printk_once(KERN_ERR
"radeon: illegal depth clear request. Buggy mesa detected - please update.\n");
905 flags
&= ~(RADEON_DEPTH
| RADEON_STENCIL
);
908 if (flags
& (RADEON_FRONT
| RADEON_BACK
)) {
912 /* Ensure the 3D stream is idle before doing a
913 * 2D fill to clear the front or back buffer.
915 RADEON_WAIT_UNTIL_3D_IDLE();
917 OUT_RING(CP_PACKET0(RADEON_DP_WRITE_MASK
, 0));
918 OUT_RING(clear
->color_mask
);
922 /* Make sure we restore the 3D state next time.
924 sarea_priv
->ctx_owner
= 0;
926 for (i
= 0; i
< nbox
; i
++) {
929 int w
= pbox
[i
].x2
- x
;
930 int h
= pbox
[i
].y2
- y
;
932 DRM_DEBUG("%d,%d-%d,%d flags 0x%x\n",
935 if (flags
& RADEON_FRONT
) {
939 (RADEON_CNTL_PAINT_MULTI
, 4));
940 OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL
|
941 RADEON_GMC_BRUSH_SOLID_COLOR
|
944 RADEON_GMC_SRC_DATATYPE_COLOR
|
946 RADEON_GMC_CLR_CMP_CNTL_DIS
);
948 OUT_RING(dev_priv
->front_pitch_offset
);
949 OUT_RING(clear
->clear_color
);
951 OUT_RING((x
<< 16) | y
);
952 OUT_RING((w
<< 16) | h
);
957 if (flags
& RADEON_BACK
) {
961 (RADEON_CNTL_PAINT_MULTI
, 4));
962 OUT_RING(RADEON_GMC_DST_PITCH_OFFSET_CNTL
|
963 RADEON_GMC_BRUSH_SOLID_COLOR
|
966 RADEON_GMC_SRC_DATATYPE_COLOR
|
968 RADEON_GMC_CLR_CMP_CNTL_DIS
);
970 OUT_RING(dev_priv
->back_pitch_offset
);
971 OUT_RING(clear
->clear_color
);
973 OUT_RING((x
<< 16) | y
);
974 OUT_RING((w
<< 16) | h
);
982 /* no docs available, based on reverse engeneering by Stephane Marchesin */
983 if ((flags
& (RADEON_DEPTH
| RADEON_STENCIL
))
984 && (flags
& RADEON_CLEAR_FASTZ
)) {
987 int depthpixperline
=
988 dev_priv
->depth_fmt
==
989 RADEON_DEPTH_FORMAT_16BIT_INT_Z
? (dev_priv
->depth_pitch
/
995 u32 tempRB3D_DEPTHCLEARVALUE
= clear
->clear_depth
|
996 ((clear
->depth_mask
& 0xff) << 24);
998 /* Make sure we restore the 3D state next time.
999 * we haven't touched any "normal" state - still need this?
1001 sarea_priv
->ctx_owner
= 0;
1003 if ((dev_priv
->flags
& RADEON_HAS_HIERZ
)
1004 && (flags
& RADEON_USE_HIERZ
)) {
1005 /* FIXME : reverse engineer that for Rx00 cards */
1006 /* FIXME : the mask supposedly contains low-res z values. So can't set
1007 just to the max (0xff? or actually 0x3fff?), need to take z clear
1008 value into account? */
1009 /* pattern seems to work for r100, though get slight
1010 rendering errors with glxgears. If hierz is not enabled for r100,
1011 only 4 bits which indicate clear (15,16,31,32, all zero) matter, the
1012 other ones are ignored, and the same clear mask can be used. That's
1013 very different behaviour than R200 which needs different clear mask
1014 and different number of tiles to clear if hierz is enabled or not !?!
1016 clearmask
= (0xff << 22) | (0xff << 6) | 0x003f003f;
1018 /* clear mask : chooses the clearing pattern.
1019 rv250: could be used to clear only parts of macrotiles
1020 (but that would get really complicated...)?
1021 bit 0 and 1 (either or both of them ?!?!) are used to
1022 not clear tile (or maybe one of the bits indicates if the tile is
1023 compressed or not), bit 2 and 3 to not clear tile 1,...,.
1024 Pattern is as follows:
1025 | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29|
1026 bits -------------------------------------------------
1027 | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31|
1028 rv100: clearmask covers 2x8 4x1 tiles, but one clear still
1029 covers 256 pixels ?!?
1035 RADEON_WAIT_UNTIL_2D_IDLE();
1036 OUT_RING_REG(RADEON_RB3D_DEPTHCLEARVALUE
,
1037 tempRB3D_DEPTHCLEARVALUE
);
1038 /* what offset is this exactly ? */
1039 OUT_RING_REG(RADEON_RB3D_ZMASKOFFSET
, 0);
1040 /* need ctlstat, otherwise get some strange black flickering */
1041 OUT_RING_REG(RADEON_RB3D_ZCACHE_CTLSTAT
,
1042 RADEON_RB3D_ZC_FLUSH_ALL
);
1045 for (i
= 0; i
< nbox
; i
++) {
1046 int tileoffset
, nrtilesx
, nrtilesy
, j
;
1047 /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */
1048 if ((dev_priv
->flags
& RADEON_HAS_HIERZ
)
1049 && !(dev_priv
->microcode_version
== UCODE_R200
)) {
1050 /* FIXME : figure this out for r200 (when hierz is enabled). Or
1051 maybe r200 actually doesn't need to put the low-res z value into
1052 the tile cache like r100, but just needs to clear the hi-level z-buffer?
1053 Works for R100, both with hierz and without.
1054 R100 seems to operate on 2x1 8x8 tiles, but...
1055 odd: offset/nrtiles need to be 64 pix (4 block) aligned? Potentially
1056 problematic with resolutions which are not 64 pix aligned? */
1058 ((pbox
[i
].y1
>> 3) * depthpixperline
+
1061 ((pbox
[i
].x2
& ~63) -
1062 (pbox
[i
].x1
& ~63)) >> 4;
1064 (pbox
[i
].y2
>> 3) - (pbox
[i
].y1
>> 3);
1065 for (j
= 0; j
<= nrtilesy
; j
++) {
1068 (RADEON_3D_CLEAR_ZMASK
, 2));
1070 OUT_RING(tileoffset
* 8);
1071 /* the number of tiles to clear */
1072 OUT_RING(nrtilesx
+ 4);
1073 /* clear mask : chooses the clearing pattern. */
1074 OUT_RING(clearmask
);
1076 tileoffset
+= depthpixperline
>> 6;
1078 } else if (dev_priv
->microcode_version
== UCODE_R200
) {
1079 /* works for rv250. */
1080 /* find first macro tile (8x2 4x4 z-pixels on rv250) */
1082 ((pbox
[i
].y1
>> 3) * depthpixperline
+
1085 (pbox
[i
].x2
>> 5) - (pbox
[i
].x1
>> 5);
1087 (pbox
[i
].y2
>> 3) - (pbox
[i
].y1
>> 3);
1088 for (j
= 0; j
<= nrtilesy
; j
++) {
1091 (RADEON_3D_CLEAR_ZMASK
, 2));
1093 /* judging by the first tile offset needed, could possibly
1094 directly address/clear 4x4 tiles instead of 8x2 * 4x4
1095 macro tiles, though would still need clear mask for
1096 right/bottom if truly 4x4 granularity is desired ? */
1097 OUT_RING(tileoffset
* 16);
1098 /* the number of tiles to clear */
1099 OUT_RING(nrtilesx
+ 1);
1100 /* clear mask : chooses the clearing pattern. */
1101 OUT_RING(clearmask
);
1103 tileoffset
+= depthpixperline
>> 5;
1105 } else { /* rv 100 */
1106 /* rv100 might not need 64 pix alignment, who knows */
1107 /* offsets are, hmm, weird */
1109 ((pbox
[i
].y1
>> 4) * depthpixperline
+
1112 ((pbox
[i
].x2
& ~63) -
1113 (pbox
[i
].x1
& ~63)) >> 4;
1115 (pbox
[i
].y2
>> 4) - (pbox
[i
].y1
>> 4);
1116 for (j
= 0; j
<= nrtilesy
; j
++) {
1119 (RADEON_3D_CLEAR_ZMASK
, 2));
1120 OUT_RING(tileoffset
* 128);
1121 /* the number of tiles to clear */
1122 OUT_RING(nrtilesx
+ 4);
1123 /* clear mask : chooses the clearing pattern. */
1124 OUT_RING(clearmask
);
1126 tileoffset
+= depthpixperline
>> 6;
1131 /* TODO don't always clear all hi-level z tiles */
1132 if ((dev_priv
->flags
& RADEON_HAS_HIERZ
)
1133 && (dev_priv
->microcode_version
== UCODE_R200
)
1134 && (flags
& RADEON_USE_HIERZ
))
1135 /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */
1136 /* FIXME : the mask supposedly contains low-res z values. So can't set
1137 just to the max (0xff? or actually 0x3fff?), need to take z clear
1138 value into account? */
1141 OUT_RING(CP_PACKET3(RADEON_3D_CLEAR_HIZ
, 2));
1142 OUT_RING(0x0); /* First tile */
1144 OUT_RING((0xff << 22) | (0xff << 6) | 0x003f003f);
1149 /* We have to clear the depth and/or stencil buffers by
1150 * rendering a quad into just those buffers. Thus, we have to
1151 * make sure the 3D engine is configured correctly.
1153 else if ((dev_priv
->microcode_version
== UCODE_R200
) &&
1154 (flags
& (RADEON_DEPTH
| RADEON_STENCIL
))) {
1159 int tempRB3D_ZSTENCILCNTL
;
1160 int tempRB3D_STENCILREFMASK
;
1161 int tempRB3D_PLANEMASK
;
1163 int tempSE_VTE_CNTL
;
1164 int tempSE_VTX_FMT_0
;
1165 int tempSE_VTX_FMT_1
;
1166 int tempSE_VAP_CNTL
;
1167 int tempRE_AUX_SCISSOR_CNTL
;
1172 tempRB3D_CNTL
= depth_clear
->rb3d_cntl
;
1174 tempRB3D_ZSTENCILCNTL
= depth_clear
->rb3d_zstencilcntl
;
1175 tempRB3D_STENCILREFMASK
= 0x0;
1177 tempSE_CNTL
= depth_clear
->se_cntl
;
1181 tempSE_VAP_CNTL
= ( /* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK | */
1183 SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT
));
1185 tempRB3D_PLANEMASK
= 0x0;
1187 tempRE_AUX_SCISSOR_CNTL
= 0x0;
1190 SE_VTE_CNTL__VTX_XY_FMT_MASK
| SE_VTE_CNTL__VTX_Z_FMT_MASK
;
1192 /* Vertex format (X, Y, Z, W) */
1194 SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK
|
1195 SE_VTX_FMT_0__VTX_W0_PRESENT_MASK
;
1196 tempSE_VTX_FMT_1
= 0x0;
1199 * Depth buffer specific enables
1201 if (flags
& RADEON_DEPTH
) {
1202 /* Enable depth buffer */
1203 tempRB3D_CNTL
|= RADEON_Z_ENABLE
;
1205 /* Disable depth buffer */
1206 tempRB3D_CNTL
&= ~RADEON_Z_ENABLE
;
1210 * Stencil buffer specific enables
1212 if (flags
& RADEON_STENCIL
) {
1213 tempRB3D_CNTL
|= RADEON_STENCIL_ENABLE
;
1214 tempRB3D_STENCILREFMASK
= clear
->depth_mask
;
1216 tempRB3D_CNTL
&= ~RADEON_STENCIL_ENABLE
;
1217 tempRB3D_STENCILREFMASK
= 0x00000000;
1220 if (flags
& RADEON_USE_COMP_ZBUF
) {
1221 tempRB3D_ZSTENCILCNTL
|= RADEON_Z_COMPRESSION_ENABLE
|
1222 RADEON_Z_DECOMPRESSION_ENABLE
;
1224 if (flags
& RADEON_USE_HIERZ
) {
1225 tempRB3D_ZSTENCILCNTL
|= RADEON_Z_HIERARCHY_ENABLE
;
1229 RADEON_WAIT_UNTIL_2D_IDLE();
1231 OUT_RING_REG(RADEON_PP_CNTL
, tempPP_CNTL
);
1232 OUT_RING_REG(R200_RE_CNTL
, tempRE_CNTL
);
1233 OUT_RING_REG(RADEON_RB3D_CNTL
, tempRB3D_CNTL
);
1234 OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL
, tempRB3D_ZSTENCILCNTL
);
1235 OUT_RING_REG(RADEON_RB3D_STENCILREFMASK
,
1236 tempRB3D_STENCILREFMASK
);
1237 OUT_RING_REG(RADEON_RB3D_PLANEMASK
, tempRB3D_PLANEMASK
);
1238 OUT_RING_REG(RADEON_SE_CNTL
, tempSE_CNTL
);
1239 OUT_RING_REG(R200_SE_VTE_CNTL
, tempSE_VTE_CNTL
);
1240 OUT_RING_REG(R200_SE_VTX_FMT_0
, tempSE_VTX_FMT_0
);
1241 OUT_RING_REG(R200_SE_VTX_FMT_1
, tempSE_VTX_FMT_1
);
1242 OUT_RING_REG(R200_SE_VAP_CNTL
, tempSE_VAP_CNTL
);
1243 OUT_RING_REG(R200_RE_AUX_SCISSOR_CNTL
, tempRE_AUX_SCISSOR_CNTL
);
1246 /* Make sure we restore the 3D state next time.
1248 sarea_priv
->ctx_owner
= 0;
1250 for (i
= 0; i
< nbox
; i
++) {
1252 /* Funny that this should be required --
1255 radeon_emit_clip_rect(dev_priv
, &sarea_priv
->boxes
[i
]);
1258 OUT_RING(CP_PACKET3(R200_3D_DRAW_IMMD_2
, 12));
1259 OUT_RING((RADEON_PRIM_TYPE_RECT_LIST
|
1260 RADEON_PRIM_WALK_RING
|
1261 (3 << RADEON_NUM_VERTICES_SHIFT
)));
1262 OUT_RING(depth_boxes
[i
].ui
[CLEAR_X1
]);
1263 OUT_RING(depth_boxes
[i
].ui
[CLEAR_Y1
]);
1264 OUT_RING(depth_boxes
[i
].ui
[CLEAR_DEPTH
]);
1265 OUT_RING(0x3f800000);
1266 OUT_RING(depth_boxes
[i
].ui
[CLEAR_X1
]);
1267 OUT_RING(depth_boxes
[i
].ui
[CLEAR_Y2
]);
1268 OUT_RING(depth_boxes
[i
].ui
[CLEAR_DEPTH
]);
1269 OUT_RING(0x3f800000);
1270 OUT_RING(depth_boxes
[i
].ui
[CLEAR_X2
]);
1271 OUT_RING(depth_boxes
[i
].ui
[CLEAR_Y2
]);
1272 OUT_RING(depth_boxes
[i
].ui
[CLEAR_DEPTH
]);
1273 OUT_RING(0x3f800000);
1276 } else if ((flags
& (RADEON_DEPTH
| RADEON_STENCIL
))) {
1278 int tempRB3D_ZSTENCILCNTL
= depth_clear
->rb3d_zstencilcntl
;
1280 rb3d_cntl
= depth_clear
->rb3d_cntl
;
1282 if (flags
& RADEON_DEPTH
) {
1283 rb3d_cntl
|= RADEON_Z_ENABLE
;
1285 rb3d_cntl
&= ~RADEON_Z_ENABLE
;
1288 if (flags
& RADEON_STENCIL
) {
1289 rb3d_cntl
|= RADEON_STENCIL_ENABLE
;
1290 rb3d_stencilrefmask
= clear
->depth_mask
; /* misnamed field */
1292 rb3d_cntl
&= ~RADEON_STENCIL_ENABLE
;
1293 rb3d_stencilrefmask
= 0x00000000;
1296 if (flags
& RADEON_USE_COMP_ZBUF
) {
1297 tempRB3D_ZSTENCILCNTL
|= RADEON_Z_COMPRESSION_ENABLE
|
1298 RADEON_Z_DECOMPRESSION_ENABLE
;
1300 if (flags
& RADEON_USE_HIERZ
) {
1301 tempRB3D_ZSTENCILCNTL
|= RADEON_Z_HIERARCHY_ENABLE
;
1305 RADEON_WAIT_UNTIL_2D_IDLE();
1307 OUT_RING(CP_PACKET0(RADEON_PP_CNTL
, 1));
1308 OUT_RING(0x00000000);
1309 OUT_RING(rb3d_cntl
);
1311 OUT_RING_REG(RADEON_RB3D_ZSTENCILCNTL
, tempRB3D_ZSTENCILCNTL
);
1312 OUT_RING_REG(RADEON_RB3D_STENCILREFMASK
, rb3d_stencilrefmask
);
1313 OUT_RING_REG(RADEON_RB3D_PLANEMASK
, 0x00000000);
1314 OUT_RING_REG(RADEON_SE_CNTL
, depth_clear
->se_cntl
);
1317 /* Make sure we restore the 3D state next time.
1319 sarea_priv
->ctx_owner
= 0;
1321 for (i
= 0; i
< nbox
; i
++) {
1323 /* Funny that this should be required --
1326 radeon_emit_clip_rect(dev_priv
, &sarea_priv
->boxes
[i
]);
1330 OUT_RING(CP_PACKET3(RADEON_3D_DRAW_IMMD
, 13));
1331 OUT_RING(RADEON_VTX_Z_PRESENT
|
1332 RADEON_VTX_PKCOLOR_PRESENT
);
1333 OUT_RING((RADEON_PRIM_TYPE_RECT_LIST
|
1334 RADEON_PRIM_WALK_RING
|
1335 RADEON_MAOS_ENABLE
|
1336 RADEON_VTX_FMT_RADEON_MODE
|
1337 (3 << RADEON_NUM_VERTICES_SHIFT
)));
1339 OUT_RING(depth_boxes
[i
].ui
[CLEAR_X1
]);
1340 OUT_RING(depth_boxes
[i
].ui
[CLEAR_Y1
]);
1341 OUT_RING(depth_boxes
[i
].ui
[CLEAR_DEPTH
]);
1344 OUT_RING(depth_boxes
[i
].ui
[CLEAR_X1
]);
1345 OUT_RING(depth_boxes
[i
].ui
[CLEAR_Y2
]);
1346 OUT_RING(depth_boxes
[i
].ui
[CLEAR_DEPTH
]);
1349 OUT_RING(depth_boxes
[i
].ui
[CLEAR_X2
]);
1350 OUT_RING(depth_boxes
[i
].ui
[CLEAR_Y2
]);
1351 OUT_RING(depth_boxes
[i
].ui
[CLEAR_DEPTH
]);
1358 /* Increment the clear counter. The client-side 3D driver must
1359 * wait on this value before performing the clear ioctl. We
1360 * need this because the card's so damned fast...
1362 sarea_priv
->last_clear
++;
1366 RADEON_CLEAR_AGE(sarea_priv
->last_clear
);
1367 RADEON_WAIT_UNTIL_IDLE();
1372 static void radeon_cp_dispatch_swap(struct drm_device
*dev
, struct drm_master
*master
)
1374 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1375 struct drm_radeon_master_private
*master_priv
= master
->driver_priv
;
1376 drm_radeon_sarea_t
*sarea_priv
= master_priv
->sarea_priv
;
1377 int nbox
= sarea_priv
->nbox
;
1378 struct drm_clip_rect
*pbox
= sarea_priv
->boxes
;
1383 /* Do some trivial performance monitoring...
1385 if (dev_priv
->do_boxes
)
1386 radeon_cp_performance_boxes(dev_priv
, master_priv
);
1388 /* Wait for the 3D stream to idle before dispatching the bitblt.
1389 * This will prevent data corruption between the two streams.
1393 RADEON_WAIT_UNTIL_3D_IDLE();
1397 for (i
= 0; i
< nbox
; i
++) {
1400 int w
= pbox
[i
].x2
- x
;
1401 int h
= pbox
[i
].y2
- y
;
1403 DRM_DEBUG("%d,%d-%d,%d\n", x
, y
, w
, h
);
1407 OUT_RING(CP_PACKET0(RADEON_DP_GUI_MASTER_CNTL
, 0));
1408 OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL
|
1409 RADEON_GMC_DST_PITCH_OFFSET_CNTL
|
1410 RADEON_GMC_BRUSH_NONE
|
1411 (dev_priv
->color_fmt
<< 8) |
1412 RADEON_GMC_SRC_DATATYPE_COLOR
|
1414 RADEON_DP_SRC_SOURCE_MEMORY
|
1415 RADEON_GMC_CLR_CMP_CNTL_DIS
| RADEON_GMC_WR_MSK_DIS
);
1417 /* Make this work even if front & back are flipped:
1419 OUT_RING(CP_PACKET0(RADEON_SRC_PITCH_OFFSET
, 1));
1420 if (sarea_priv
->pfCurrentPage
== 0) {
1421 OUT_RING(dev_priv
->back_pitch_offset
);
1422 OUT_RING(dev_priv
->front_pitch_offset
);
1424 OUT_RING(dev_priv
->front_pitch_offset
);
1425 OUT_RING(dev_priv
->back_pitch_offset
);
1428 OUT_RING(CP_PACKET0(RADEON_SRC_X_Y
, 2));
1429 OUT_RING((x
<< 16) | y
);
1430 OUT_RING((x
<< 16) | y
);
1431 OUT_RING((w
<< 16) | h
);
1436 /* Increment the frame counter. The client-side 3D driver must
1437 * throttle the framerate by waiting for this value before
1438 * performing the swapbuffer ioctl.
1440 sarea_priv
->last_frame
++;
1444 RADEON_FRAME_AGE(sarea_priv
->last_frame
);
1445 RADEON_WAIT_UNTIL_2D_IDLE();
1450 void radeon_cp_dispatch_flip(struct drm_device
*dev
, struct drm_master
*master
)
1452 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1453 struct drm_radeon_master_private
*master_priv
= master
->driver_priv
;
1454 struct drm_sarea
*sarea
= (struct drm_sarea
*)master_priv
->sarea
->handle
;
1455 int offset
= (master_priv
->sarea_priv
->pfCurrentPage
== 1)
1456 ? dev_priv
->front_offset
: dev_priv
->back_offset
;
1458 DRM_DEBUG("pfCurrentPage=%d\n",
1459 master_priv
->sarea_priv
->pfCurrentPage
);
1461 /* Do some trivial performance monitoring...
1463 if (dev_priv
->do_boxes
) {
1464 dev_priv
->stats
.boxes
|= RADEON_BOX_FLIP
;
1465 radeon_cp_performance_boxes(dev_priv
, master_priv
);
1468 /* Update the frame offsets for both CRTCs
1472 RADEON_WAIT_UNTIL_3D_IDLE();
1473 OUT_RING_REG(RADEON_CRTC_OFFSET
,
1474 ((sarea
->frame
.y
* dev_priv
->front_pitch
+
1475 sarea
->frame
.x
* (dev_priv
->color_fmt
- 2)) & ~7)
1477 OUT_RING_REG(RADEON_CRTC2_OFFSET
, master_priv
->sarea_priv
->crtc2_base
1482 /* Increment the frame counter. The client-side 3D driver must
1483 * throttle the framerate by waiting for this value before
1484 * performing the swapbuffer ioctl.
1486 master_priv
->sarea_priv
->last_frame
++;
1487 master_priv
->sarea_priv
->pfCurrentPage
=
1488 1 - master_priv
->sarea_priv
->pfCurrentPage
;
1492 RADEON_FRAME_AGE(master_priv
->sarea_priv
->last_frame
);
1497 static int bad_prim_vertex_nr(int primitive
, int nr
)
1499 switch (primitive
& RADEON_PRIM_TYPE_MASK
) {
1500 case RADEON_PRIM_TYPE_NONE
:
1501 case RADEON_PRIM_TYPE_POINT
:
1503 case RADEON_PRIM_TYPE_LINE
:
1504 return (nr
& 1) || nr
== 0;
1505 case RADEON_PRIM_TYPE_LINE_STRIP
:
1507 case RADEON_PRIM_TYPE_TRI_LIST
:
1508 case RADEON_PRIM_TYPE_3VRT_POINT_LIST
:
1509 case RADEON_PRIM_TYPE_3VRT_LINE_LIST
:
1510 case RADEON_PRIM_TYPE_RECT_LIST
:
1511 return nr
% 3 || nr
== 0;
1512 case RADEON_PRIM_TYPE_TRI_FAN
:
1513 case RADEON_PRIM_TYPE_TRI_STRIP
:
1522 unsigned int finish
;
1524 unsigned int numverts
;
1525 unsigned int offset
;
1526 unsigned int vc_format
;
1527 } drm_radeon_tcl_prim_t
;
1529 static void radeon_cp_dispatch_vertex(struct drm_device
* dev
,
1530 struct drm_file
*file_priv
,
1531 struct drm_buf
* buf
,
1532 drm_radeon_tcl_prim_t
* prim
)
1534 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1535 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
1536 drm_radeon_sarea_t
*sarea_priv
= master_priv
->sarea_priv
;
1537 int offset
= dev_priv
->gart_buffers_offset
+ buf
->offset
+ prim
->start
;
1538 int numverts
= (int)prim
->numverts
;
1539 int nbox
= sarea_priv
->nbox
;
1543 DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d %d verts\n",
1545 prim
->vc_format
, prim
->start
, prim
->finish
, prim
->numverts
);
1547 if (bad_prim_vertex_nr(prim
->prim
, prim
->numverts
)) {
1548 DRM_ERROR("bad prim %x numverts %d\n",
1549 prim
->prim
, prim
->numverts
);
1554 /* Emit the next cliprect */
1556 radeon_emit_clip_rect(dev_priv
, &sarea_priv
->boxes
[i
]);
1559 /* Emit the vertex buffer rendering commands */
1562 OUT_RING(CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM
, 3));
1565 OUT_RING(prim
->vc_format
);
1566 OUT_RING(prim
->prim
| RADEON_PRIM_WALK_LIST
|
1567 RADEON_COLOR_ORDER_RGBA
|
1568 RADEON_VTX_FMT_RADEON_MODE
|
1569 (numverts
<< RADEON_NUM_VERTICES_SHIFT
));
1577 void radeon_cp_discard_buffer(struct drm_device
*dev
, struct drm_master
*master
, struct drm_buf
*buf
)
1579 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1580 struct drm_radeon_master_private
*master_priv
= master
->driver_priv
;
1581 drm_radeon_buf_priv_t
*buf_priv
= buf
->dev_private
;
1584 buf_priv
->age
= ++master_priv
->sarea_priv
->last_dispatch
;
1586 /* Emit the vertex buffer age */
1587 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_R600
) {
1589 R600_DISPATCH_AGE(buf_priv
->age
);
1593 RADEON_DISPATCH_AGE(buf_priv
->age
);
1601 static void radeon_cp_dispatch_indirect(struct drm_device
* dev
,
1602 struct drm_buf
* buf
, int start
, int end
)
1604 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1606 DRM_DEBUG("buf=%d s=0x%x e=0x%x\n", buf
->idx
, start
, end
);
1609 int offset
= (dev_priv
->gart_buffers_offset
1610 + buf
->offset
+ start
);
1611 int dwords
= (end
- start
+ 3) / sizeof(u32
);
1613 /* Indirect buffer data must be an even number of
1614 * dwords, so if we've been given an odd number we must
1615 * pad the data with a Type-2 CP packet.
1619 ((char *)dev
->agp_buffer_map
->handle
1620 + buf
->offset
+ start
);
1621 data
[dwords
++] = RADEON_CP_PACKET2
;
1624 /* Fire off the indirect buffer */
1627 OUT_RING(CP_PACKET0(RADEON_CP_IB_BASE
, 1));
1635 static void radeon_cp_dispatch_indices(struct drm_device
*dev
,
1636 struct drm_master
*master
,
1637 struct drm_buf
* elt_buf
,
1638 drm_radeon_tcl_prim_t
* prim
)
1640 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1641 struct drm_radeon_master_private
*master_priv
= master
->driver_priv
;
1642 drm_radeon_sarea_t
*sarea_priv
= master_priv
->sarea_priv
;
1643 int offset
= dev_priv
->gart_buffers_offset
+ prim
->offset
;
1647 int start
= prim
->start
+ RADEON_INDEX_PRIM_OFFSET
;
1648 int count
= (prim
->finish
- start
) / sizeof(u16
);
1649 int nbox
= sarea_priv
->nbox
;
1651 DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d offset: %x nr %d\n",
1654 prim
->start
, prim
->finish
, prim
->offset
, prim
->numverts
);
1656 if (bad_prim_vertex_nr(prim
->prim
, count
)) {
1657 DRM_ERROR("bad prim %x count %d\n", prim
->prim
, count
);
1661 if (start
>= prim
->finish
|| (prim
->start
& 0x7)) {
1662 DRM_ERROR("buffer prim %d\n", prim
->prim
);
1666 dwords
= (prim
->finish
- prim
->start
+ 3) / sizeof(u32
);
1668 data
= (u32
*) ((char *)dev
->agp_buffer_map
->handle
+
1669 elt_buf
->offset
+ prim
->start
);
1671 data
[0] = CP_PACKET3(RADEON_3D_RNDR_GEN_INDX_PRIM
, dwords
- 2);
1673 data
[2] = prim
->numverts
;
1674 data
[3] = prim
->vc_format
;
1675 data
[4] = (prim
->prim
|
1676 RADEON_PRIM_WALK_IND
|
1677 RADEON_COLOR_ORDER_RGBA
|
1678 RADEON_VTX_FMT_RADEON_MODE
|
1679 (count
<< RADEON_NUM_VERTICES_SHIFT
));
1683 radeon_emit_clip_rect(dev_priv
, &sarea_priv
->boxes
[i
]);
1685 radeon_cp_dispatch_indirect(dev
, elt_buf
,
1686 prim
->start
, prim
->finish
);
1693 #define RADEON_MAX_TEXTURE_SIZE RADEON_BUFFER_SIZE
1695 static int radeon_cp_dispatch_texture(struct drm_device
* dev
,
1696 struct drm_file
*file_priv
,
1697 drm_radeon_texture_t
* tex
,
1698 drm_radeon_tex_image_t
* image
)
1700 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1701 struct drm_buf
*buf
;
1704 const u8 __user
*data
;
1705 int size
, dwords
, tex_width
, blit_width
, spitch
;
1708 u32 texpitch
, microtile
;
1709 u32 offset
, byte_offset
;
1712 if (radeon_check_and_fixup_offset(dev_priv
, file_priv
, &tex
->offset
)) {
1713 DRM_ERROR("Invalid destination offset\n");
1717 dev_priv
->stats
.boxes
|= RADEON_BOX_TEXTURE_LOAD
;
1719 /* Flush the pixel cache. This ensures no pixel data gets mixed
1720 * up with the texture data from the host data blit, otherwise
1721 * part of the texture image may be corrupted.
1724 RADEON_FLUSH_CACHE();
1725 RADEON_WAIT_UNTIL_IDLE();
1728 /* The compiler won't optimize away a division by a variable,
1729 * even if the only legal values are powers of two. Thus, we'll
1730 * use a shift instead.
1732 switch (tex
->format
) {
1733 case RADEON_TXFORMAT_ARGB8888
:
1734 case RADEON_TXFORMAT_RGBA8888
:
1735 format
= RADEON_COLOR_FORMAT_ARGB8888
;
1736 tex_width
= tex
->width
* 4;
1737 blit_width
= image
->width
* 4;
1739 case RADEON_TXFORMAT_AI88
:
1740 case RADEON_TXFORMAT_ARGB1555
:
1741 case RADEON_TXFORMAT_RGB565
:
1742 case RADEON_TXFORMAT_ARGB4444
:
1743 case RADEON_TXFORMAT_VYUY422
:
1744 case RADEON_TXFORMAT_YVYU422
:
1745 format
= RADEON_COLOR_FORMAT_RGB565
;
1746 tex_width
= tex
->width
* 2;
1747 blit_width
= image
->width
* 2;
1749 case RADEON_TXFORMAT_I8
:
1750 case RADEON_TXFORMAT_RGB332
:
1751 format
= RADEON_COLOR_FORMAT_CI8
;
1752 tex_width
= tex
->width
* 1;
1753 blit_width
= image
->width
* 1;
1756 DRM_ERROR("invalid texture format %d\n", tex
->format
);
1759 spitch
= blit_width
>> 6;
1760 if (spitch
== 0 && image
->height
> 1)
1763 texpitch
= tex
->pitch
;
1764 if ((texpitch
<< 22) & RADEON_DST_TILE_MICRO
) {
1766 if (tex_width
< 64) {
1767 texpitch
&= ~(RADEON_DST_TILE_MICRO
>> 22);
1768 /* we got tiled coordinates, untile them */
1774 /* this might fail for zero-sized uploads - are those illegal? */
1775 if (!radeon_check_offset(dev_priv
, tex
->offset
+ image
->height
*
1777 DRM_ERROR("Invalid final destination offset\n");
1781 DRM_DEBUG("tex=%dx%d blit=%d\n", tex_width
, tex
->height
, blit_width
);
1784 DRM_DEBUG("tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
1785 tex
->offset
>> 10, tex
->pitch
, tex
->format
,
1786 image
->x
, image
->y
, image
->width
, image
->height
);
1788 /* Make a copy of some parameters in case we have to
1789 * update them for a multi-pass texture blit.
1791 height
= image
->height
;
1792 data
= (const u8 __user
*)image
->data
;
1794 size
= height
* blit_width
;
1796 if (size
> RADEON_MAX_TEXTURE_SIZE
) {
1797 height
= RADEON_MAX_TEXTURE_SIZE
/ blit_width
;
1798 size
= height
* blit_width
;
1799 } else if (size
< 4 && size
> 0) {
1801 } else if (size
== 0) {
1805 buf
= radeon_freelist_get(dev
);
1807 radeon_do_cp_idle(dev_priv
);
1808 buf
= radeon_freelist_get(dev
);
1811 DRM_DEBUG("EAGAIN\n");
1812 if (DRM_COPY_TO_USER(tex
->image
, image
, sizeof(*image
)))
1817 /* Dispatch the indirect buffer.
1820 (u32
*) ((char *)dev
->agp_buffer_map
->handle
+ buf
->offset
);
1823 #define RADEON_COPY_MT(_buf, _data, _width) \
1825 if (DRM_COPY_FROM_USER(_buf, _data, (_width))) {\
1826 DRM_ERROR("EFAULT on pad, %d bytes\n", (_width)); \
1832 /* texture micro tiling in use, minimum texture width is thus 16 bytes.
1833 however, we cannot use blitter directly for texture width < 64 bytes,
1834 since minimum tex pitch is 64 bytes and we need this to match
1835 the texture width, otherwise the blitter will tile it wrong.
1836 Thus, tiling manually in this case. Additionally, need to special
1837 case tex height = 1, since our actual image will have height 2
1838 and we need to ensure we don't read beyond the texture size
1840 if (tex
->height
== 1) {
1841 if (tex_width
>= 64 || tex_width
<= 16) {
1842 RADEON_COPY_MT(buffer
, data
,
1843 (int)(tex_width
* sizeof(u32
)));
1844 } else if (tex_width
== 32) {
1845 RADEON_COPY_MT(buffer
, data
, 16);
1846 RADEON_COPY_MT(buffer
+ 8,
1849 } else if (tex_width
>= 64 || tex_width
== 16) {
1850 RADEON_COPY_MT(buffer
, data
,
1851 (int)(dwords
* sizeof(u32
)));
1852 } else if (tex_width
< 16) {
1853 for (i
= 0; i
< tex
->height
; i
++) {
1854 RADEON_COPY_MT(buffer
, data
, tex_width
);
1858 } else if (tex_width
== 32) {
1859 /* TODO: make sure this works when not fitting in one buffer
1860 (i.e. 32bytes x 2048...) */
1861 for (i
= 0; i
< tex
->height
; i
+= 2) {
1862 RADEON_COPY_MT(buffer
, data
, 16);
1864 RADEON_COPY_MT(buffer
+ 8, data
, 16);
1866 RADEON_COPY_MT(buffer
+ 4, data
, 16);
1868 RADEON_COPY_MT(buffer
+ 12, data
, 16);
1874 if (tex_width
>= 32) {
1875 /* Texture image width is larger than the minimum, so we
1876 * can upload it directly.
1878 RADEON_COPY_MT(buffer
, data
,
1879 (int)(dwords
* sizeof(u32
)));
1881 /* Texture image width is less than the minimum, so we
1882 * need to pad out each image scanline to the minimum
1885 for (i
= 0; i
< tex
->height
; i
++) {
1886 RADEON_COPY_MT(buffer
, data
, tex_width
);
1893 #undef RADEON_COPY_MT
1894 byte_offset
= (image
->y
& ~2047) * blit_width
;
1895 buf
->file_priv
= file_priv
;
1897 offset
= dev_priv
->gart_buffers_offset
+ buf
->offset
;
1899 OUT_RING(CP_PACKET3(RADEON_CNTL_BITBLT_MULTI
, 5));
1900 OUT_RING(RADEON_GMC_SRC_PITCH_OFFSET_CNTL
|
1901 RADEON_GMC_DST_PITCH_OFFSET_CNTL
|
1902 RADEON_GMC_BRUSH_NONE
|
1904 RADEON_GMC_SRC_DATATYPE_COLOR
|
1906 RADEON_DP_SRC_SOURCE_MEMORY
|
1907 RADEON_GMC_CLR_CMP_CNTL_DIS
| RADEON_GMC_WR_MSK_DIS
);
1908 OUT_RING((spitch
<< 22) | (offset
>> 10));
1909 OUT_RING((texpitch
<< 22) | ((tex
->offset
>> 10) + (byte_offset
>> 10)));
1911 OUT_RING((image
->x
<< 16) | (image
->y
% 2048));
1912 OUT_RING((image
->width
<< 16) | height
);
1913 RADEON_WAIT_UNTIL_2D_IDLE();
1917 radeon_cp_discard_buffer(dev
, file_priv
->master
, buf
);
1919 /* Update the input parameters for next time */
1921 image
->height
-= height
;
1922 image
->data
= (const u8 __user
*)image
->data
+ size
;
1923 } while (image
->height
> 0);
1925 /* Flush the pixel cache after the blit completes. This ensures
1926 * the texture data is written out to memory before rendering
1930 RADEON_FLUSH_CACHE();
1931 RADEON_WAIT_UNTIL_2D_IDLE();
1938 static void radeon_cp_dispatch_stipple(struct drm_device
* dev
, u32
* stipple
)
1940 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
1947 OUT_RING(CP_PACKET0(RADEON_RE_STIPPLE_ADDR
, 0));
1948 OUT_RING(0x00000000);
1950 OUT_RING(CP_PACKET0_TABLE(RADEON_RE_STIPPLE_DATA
, 31));
1951 for (i
= 0; i
< 32; i
++) {
1952 OUT_RING(stipple
[i
]);
1958 static void radeon_apply_surface_regs(int surf_index
,
1959 drm_radeon_private_t
*dev_priv
)
1961 if (!dev_priv
->mmio
)
1964 radeon_do_cp_idle(dev_priv
);
1966 RADEON_WRITE(RADEON_SURFACE0_INFO
+ 16 * surf_index
,
1967 dev_priv
->surfaces
[surf_index
].flags
);
1968 RADEON_WRITE(RADEON_SURFACE0_LOWER_BOUND
+ 16 * surf_index
,
1969 dev_priv
->surfaces
[surf_index
].lower
);
1970 RADEON_WRITE(RADEON_SURFACE0_UPPER_BOUND
+ 16 * surf_index
,
1971 dev_priv
->surfaces
[surf_index
].upper
);
1974 /* Allocates a virtual surface
1975 * doesn't always allocate a real surface, will stretch an existing
1976 * surface when possible.
1978 * Note that refcount can be at most 2, since during a free refcount=3
1979 * might mean we have to allocate a new surface which might not always
1981 * For example : we allocate three contiguous surfaces ABC. If B is
1982 * freed, we suddenly need two surfaces to store A and C, which might
1983 * not always be available.
1985 static int alloc_surface(drm_radeon_surface_alloc_t
*new,
1986 drm_radeon_private_t
*dev_priv
,
1987 struct drm_file
*file_priv
)
1989 struct radeon_virt_surface
*s
;
1991 int virt_surface_index
;
1992 uint32_t new_upper
, new_lower
;
1994 new_lower
= new->address
;
1995 new_upper
= new_lower
+ new->size
- 1;
1998 if ((new_lower
>= new_upper
) || (new->flags
== 0) || (new->size
== 0) ||
1999 ((new_upper
& RADEON_SURF_ADDRESS_FIXED_MASK
) !=
2000 RADEON_SURF_ADDRESS_FIXED_MASK
)
2001 || ((new_lower
& RADEON_SURF_ADDRESS_FIXED_MASK
) != 0))
2004 /* make sure there is no overlap with existing surfaces */
2005 for (i
= 0; i
< RADEON_MAX_SURFACES
; i
++) {
2006 if ((dev_priv
->surfaces
[i
].refcount
!= 0) &&
2007 (((new_lower
>= dev_priv
->surfaces
[i
].lower
) &&
2008 (new_lower
< dev_priv
->surfaces
[i
].upper
)) ||
2009 ((new_lower
< dev_priv
->surfaces
[i
].lower
) &&
2010 (new_upper
> dev_priv
->surfaces
[i
].lower
)))) {
2015 /* find a virtual surface */
2016 for (i
= 0; i
< 2 * RADEON_MAX_SURFACES
; i
++)
2017 if (dev_priv
->virt_surfaces
[i
].file_priv
== NULL
)
2019 if (i
== 2 * RADEON_MAX_SURFACES
) {
2022 virt_surface_index
= i
;
2024 /* try to reuse an existing surface */
2025 for (i
= 0; i
< RADEON_MAX_SURFACES
; i
++) {
2027 if ((dev_priv
->surfaces
[i
].refcount
== 1) &&
2028 (new->flags
== dev_priv
->surfaces
[i
].flags
) &&
2029 (new_upper
+ 1 == dev_priv
->surfaces
[i
].lower
)) {
2030 s
= &(dev_priv
->virt_surfaces
[virt_surface_index
]);
2031 s
->surface_index
= i
;
2032 s
->lower
= new_lower
;
2033 s
->upper
= new_upper
;
2034 s
->flags
= new->flags
;
2035 s
->file_priv
= file_priv
;
2036 dev_priv
->surfaces
[i
].refcount
++;
2037 dev_priv
->surfaces
[i
].lower
= s
->lower
;
2038 radeon_apply_surface_regs(s
->surface_index
, dev_priv
);
2039 return virt_surface_index
;
2043 if ((dev_priv
->surfaces
[i
].refcount
== 1) &&
2044 (new->flags
== dev_priv
->surfaces
[i
].flags
) &&
2045 (new_lower
== dev_priv
->surfaces
[i
].upper
+ 1)) {
2046 s
= &(dev_priv
->virt_surfaces
[virt_surface_index
]);
2047 s
->surface_index
= i
;
2048 s
->lower
= new_lower
;
2049 s
->upper
= new_upper
;
2050 s
->flags
= new->flags
;
2051 s
->file_priv
= file_priv
;
2052 dev_priv
->surfaces
[i
].refcount
++;
2053 dev_priv
->surfaces
[i
].upper
= s
->upper
;
2054 radeon_apply_surface_regs(s
->surface_index
, dev_priv
);
2055 return virt_surface_index
;
2059 /* okay, we need a new one */
2060 for (i
= 0; i
< RADEON_MAX_SURFACES
; i
++) {
2061 if (dev_priv
->surfaces
[i
].refcount
== 0) {
2062 s
= &(dev_priv
->virt_surfaces
[virt_surface_index
]);
2063 s
->surface_index
= i
;
2064 s
->lower
= new_lower
;
2065 s
->upper
= new_upper
;
2066 s
->flags
= new->flags
;
2067 s
->file_priv
= file_priv
;
2068 dev_priv
->surfaces
[i
].refcount
= 1;
2069 dev_priv
->surfaces
[i
].lower
= s
->lower
;
2070 dev_priv
->surfaces
[i
].upper
= s
->upper
;
2071 dev_priv
->surfaces
[i
].flags
= s
->flags
;
2072 radeon_apply_surface_regs(s
->surface_index
, dev_priv
);
2073 return virt_surface_index
;
2077 /* we didn't find anything */
2081 static int free_surface(struct drm_file
*file_priv
,
2082 drm_radeon_private_t
* dev_priv
,
2085 struct radeon_virt_surface
*s
;
2087 /* find the virtual surface */
2088 for (i
= 0; i
< 2 * RADEON_MAX_SURFACES
; i
++) {
2089 s
= &(dev_priv
->virt_surfaces
[i
]);
2091 if ((lower
== s
->lower
) && (file_priv
== s
->file_priv
))
2093 if (dev_priv
->surfaces
[s
->surface_index
].
2095 dev_priv
->surfaces
[s
->surface_index
].
2098 if (dev_priv
->surfaces
[s
->surface_index
].
2100 dev_priv
->surfaces
[s
->surface_index
].
2103 dev_priv
->surfaces
[s
->surface_index
].refcount
--;
2104 if (dev_priv
->surfaces
[s
->surface_index
].
2106 dev_priv
->surfaces
[s
->surface_index
].
2108 s
->file_priv
= NULL
;
2109 radeon_apply_surface_regs(s
->surface_index
,
2118 static void radeon_surfaces_release(struct drm_file
*file_priv
,
2119 drm_radeon_private_t
* dev_priv
)
2122 for (i
= 0; i
< 2 * RADEON_MAX_SURFACES
; i
++) {
2123 if (dev_priv
->virt_surfaces
[i
].file_priv
== file_priv
)
2124 free_surface(file_priv
, dev_priv
,
2125 dev_priv
->virt_surfaces
[i
].lower
);
2129 /* ================================================================
2132 static int radeon_surface_alloc(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2134 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2135 drm_radeon_surface_alloc_t
*alloc
= data
;
2137 if (alloc_surface(alloc
, dev_priv
, file_priv
) == -1)
2143 static int radeon_surface_free(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2145 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2146 drm_radeon_surface_free_t
*memfree
= data
;
2148 if (free_surface(file_priv
, dev_priv
, memfree
->address
))
2154 static int radeon_cp_clear(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2156 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2157 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
2158 drm_radeon_sarea_t
*sarea_priv
= master_priv
->sarea_priv
;
2159 drm_radeon_clear_t
*clear
= data
;
2160 drm_radeon_clear_rect_t depth_boxes
[RADEON_NR_SAREA_CLIPRECTS
];
2163 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2165 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2167 if (sarea_priv
->nbox
> RADEON_NR_SAREA_CLIPRECTS
)
2168 sarea_priv
->nbox
= RADEON_NR_SAREA_CLIPRECTS
;
2170 if (DRM_COPY_FROM_USER(&depth_boxes
, clear
->depth_boxes
,
2171 sarea_priv
->nbox
* sizeof(depth_boxes
[0])))
2174 radeon_cp_dispatch_clear(dev
, file_priv
->master
, clear
, depth_boxes
);
2180 /* Not sure why this isn't set all the time:
2182 static int radeon_do_init_pageflip(struct drm_device
*dev
, struct drm_master
*master
)
2184 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2185 struct drm_radeon_master_private
*master_priv
= master
->driver_priv
;
2191 RADEON_WAIT_UNTIL_3D_IDLE();
2192 OUT_RING(CP_PACKET0(RADEON_CRTC_OFFSET_CNTL
, 0));
2193 OUT_RING(RADEON_READ(RADEON_CRTC_OFFSET_CNTL
) |
2194 RADEON_CRTC_OFFSET_FLIP_CNTL
);
2195 OUT_RING(CP_PACKET0(RADEON_CRTC2_OFFSET_CNTL
, 0));
2196 OUT_RING(RADEON_READ(RADEON_CRTC2_OFFSET_CNTL
) |
2197 RADEON_CRTC_OFFSET_FLIP_CNTL
);
2200 dev_priv
->page_flipping
= 1;
2202 if (master_priv
->sarea_priv
->pfCurrentPage
!= 1)
2203 master_priv
->sarea_priv
->pfCurrentPage
= 0;
2208 /* Swapping and flipping are different operations, need different ioctls.
2209 * They can & should be intermixed to support multiple 3d windows.
2211 static int radeon_cp_flip(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2213 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2216 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2218 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2220 if (!dev_priv
->page_flipping
)
2221 radeon_do_init_pageflip(dev
, file_priv
->master
);
2223 radeon_cp_dispatch_flip(dev
, file_priv
->master
);
2229 static int radeon_cp_swap(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2231 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2232 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
2233 drm_radeon_sarea_t
*sarea_priv
= master_priv
->sarea_priv
;
2237 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2239 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2241 if (sarea_priv
->nbox
> RADEON_NR_SAREA_CLIPRECTS
)
2242 sarea_priv
->nbox
= RADEON_NR_SAREA_CLIPRECTS
;
2244 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_R600
)
2245 r600_cp_dispatch_swap(dev
, file_priv
);
2247 radeon_cp_dispatch_swap(dev
, file_priv
->master
);
2248 sarea_priv
->ctx_owner
= 0;
2254 static int radeon_cp_vertex(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2256 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2257 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
2258 drm_radeon_sarea_t
*sarea_priv
;
2259 struct drm_device_dma
*dma
= dev
->dma
;
2260 struct drm_buf
*buf
;
2261 drm_radeon_vertex_t
*vertex
= data
;
2262 drm_radeon_tcl_prim_t prim
;
2264 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2266 sarea_priv
= master_priv
->sarea_priv
;
2268 DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n",
2269 DRM_CURRENTPID
, vertex
->idx
, vertex
->count
, vertex
->discard
);
2271 if (vertex
->idx
< 0 || vertex
->idx
>= dma
->buf_count
) {
2272 DRM_ERROR("buffer index %d (of %d max)\n",
2273 vertex
->idx
, dma
->buf_count
- 1);
2276 if (vertex
->prim
< 0 || vertex
->prim
> RADEON_PRIM_TYPE_3VRT_LINE_LIST
) {
2277 DRM_ERROR("buffer prim %d\n", vertex
->prim
);
2281 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2282 VB_AGE_TEST_WITH_RETURN(dev_priv
);
2284 buf
= dma
->buflist
[vertex
->idx
];
2286 if (buf
->file_priv
!= file_priv
) {
2287 DRM_ERROR("process %d using buffer owned by %p\n",
2288 DRM_CURRENTPID
, buf
->file_priv
);
2292 DRM_ERROR("sending pending buffer %d\n", vertex
->idx
);
2296 /* Build up a prim_t record:
2298 if (vertex
->count
) {
2299 buf
->used
= vertex
->count
; /* not used? */
2301 if (sarea_priv
->dirty
& ~RADEON_UPLOAD_CLIPRECTS
) {
2302 if (radeon_emit_state(dev_priv
, file_priv
,
2303 &sarea_priv
->context_state
,
2304 sarea_priv
->tex_state
,
2305 sarea_priv
->dirty
)) {
2306 DRM_ERROR("radeon_emit_state failed\n");
2310 sarea_priv
->dirty
&= ~(RADEON_UPLOAD_TEX0IMAGES
|
2311 RADEON_UPLOAD_TEX1IMAGES
|
2312 RADEON_UPLOAD_TEX2IMAGES
|
2313 RADEON_REQUIRE_QUIESCENCE
);
2317 prim
.finish
= vertex
->count
; /* unused */
2318 prim
.prim
= vertex
->prim
;
2319 prim
.numverts
= vertex
->count
;
2320 prim
.vc_format
= sarea_priv
->vc_format
;
2322 radeon_cp_dispatch_vertex(dev
, file_priv
, buf
, &prim
);
2325 if (vertex
->discard
) {
2326 radeon_cp_discard_buffer(dev
, file_priv
->master
, buf
);
2333 static int radeon_cp_indices(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2335 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2336 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
2337 drm_radeon_sarea_t
*sarea_priv
;
2338 struct drm_device_dma
*dma
= dev
->dma
;
2339 struct drm_buf
*buf
;
2340 drm_radeon_indices_t
*elts
= data
;
2341 drm_radeon_tcl_prim_t prim
;
2344 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2346 sarea_priv
= master_priv
->sarea_priv
;
2348 DRM_DEBUG("pid=%d index=%d start=%d end=%d discard=%d\n",
2349 DRM_CURRENTPID
, elts
->idx
, elts
->start
, elts
->end
,
2352 if (elts
->idx
< 0 || elts
->idx
>= dma
->buf_count
) {
2353 DRM_ERROR("buffer index %d (of %d max)\n",
2354 elts
->idx
, dma
->buf_count
- 1);
2357 if (elts
->prim
< 0 || elts
->prim
> RADEON_PRIM_TYPE_3VRT_LINE_LIST
) {
2358 DRM_ERROR("buffer prim %d\n", elts
->prim
);
2362 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2363 VB_AGE_TEST_WITH_RETURN(dev_priv
);
2365 buf
= dma
->buflist
[elts
->idx
];
2367 if (buf
->file_priv
!= file_priv
) {
2368 DRM_ERROR("process %d using buffer owned by %p\n",
2369 DRM_CURRENTPID
, buf
->file_priv
);
2373 DRM_ERROR("sending pending buffer %d\n", elts
->idx
);
2377 count
= (elts
->end
- elts
->start
) / sizeof(u16
);
2378 elts
->start
-= RADEON_INDEX_PRIM_OFFSET
;
2380 if (elts
->start
& 0x7) {
2381 DRM_ERROR("misaligned buffer 0x%x\n", elts
->start
);
2384 if (elts
->start
< buf
->used
) {
2385 DRM_ERROR("no header 0x%x - 0x%x\n", elts
->start
, buf
->used
);
2389 buf
->used
= elts
->end
;
2391 if (sarea_priv
->dirty
& ~RADEON_UPLOAD_CLIPRECTS
) {
2392 if (radeon_emit_state(dev_priv
, file_priv
,
2393 &sarea_priv
->context_state
,
2394 sarea_priv
->tex_state
,
2395 sarea_priv
->dirty
)) {
2396 DRM_ERROR("radeon_emit_state failed\n");
2400 sarea_priv
->dirty
&= ~(RADEON_UPLOAD_TEX0IMAGES
|
2401 RADEON_UPLOAD_TEX1IMAGES
|
2402 RADEON_UPLOAD_TEX2IMAGES
|
2403 RADEON_REQUIRE_QUIESCENCE
);
2406 /* Build up a prim_t record:
2408 prim
.start
= elts
->start
;
2409 prim
.finish
= elts
->end
;
2410 prim
.prim
= elts
->prim
;
2411 prim
.offset
= 0; /* offset from start of dma buffers */
2412 prim
.numverts
= RADEON_MAX_VB_VERTS
; /* duh */
2413 prim
.vc_format
= sarea_priv
->vc_format
;
2415 radeon_cp_dispatch_indices(dev
, file_priv
->master
, buf
, &prim
);
2416 if (elts
->discard
) {
2417 radeon_cp_discard_buffer(dev
, file_priv
->master
, buf
);
2424 static int radeon_cp_texture(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2426 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2427 drm_radeon_texture_t
*tex
= data
;
2428 drm_radeon_tex_image_t image
;
2431 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2433 if (tex
->image
== NULL
) {
2434 DRM_ERROR("null texture image!\n");
2438 if (DRM_COPY_FROM_USER(&image
,
2439 (drm_radeon_tex_image_t __user
*) tex
->image
,
2443 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2444 VB_AGE_TEST_WITH_RETURN(dev_priv
);
2446 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_R600
)
2447 ret
= r600_cp_dispatch_texture(dev
, file_priv
, tex
, &image
);
2449 ret
= radeon_cp_dispatch_texture(dev
, file_priv
, tex
, &image
);
2454 static int radeon_cp_stipple(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2456 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2457 drm_radeon_stipple_t
*stipple
= data
;
2460 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2462 if (DRM_COPY_FROM_USER(&mask
, stipple
->mask
, 32 * sizeof(u32
)))
2465 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2467 radeon_cp_dispatch_stipple(dev
, mask
);
2473 static int radeon_cp_indirect(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2475 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2476 struct drm_device_dma
*dma
= dev
->dma
;
2477 struct drm_buf
*buf
;
2478 drm_radeon_indirect_t
*indirect
= data
;
2481 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2483 DRM_DEBUG("idx=%d s=%d e=%d d=%d\n",
2484 indirect
->idx
, indirect
->start
, indirect
->end
,
2487 if (indirect
->idx
< 0 || indirect
->idx
>= dma
->buf_count
) {
2488 DRM_ERROR("buffer index %d (of %d max)\n",
2489 indirect
->idx
, dma
->buf_count
- 1);
2493 buf
= dma
->buflist
[indirect
->idx
];
2495 if (buf
->file_priv
!= file_priv
) {
2496 DRM_ERROR("process %d using buffer owned by %p\n",
2497 DRM_CURRENTPID
, buf
->file_priv
);
2501 DRM_ERROR("sending pending buffer %d\n", indirect
->idx
);
2505 if (indirect
->start
< buf
->used
) {
2506 DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n",
2507 indirect
->start
, buf
->used
);
2511 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2512 VB_AGE_TEST_WITH_RETURN(dev_priv
);
2514 buf
->used
= indirect
->end
;
2516 /* Dispatch the indirect buffer full of commands from the
2517 * X server. This is insecure and is thus only available to
2518 * privileged clients.
2520 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_R600
)
2521 r600_cp_dispatch_indirect(dev
, buf
, indirect
->start
, indirect
->end
);
2523 /* Wait for the 3D stream to idle before the indirect buffer
2524 * containing 2D acceleration commands is processed.
2527 RADEON_WAIT_UNTIL_3D_IDLE();
2529 radeon_cp_dispatch_indirect(dev
, buf
, indirect
->start
, indirect
->end
);
2532 if (indirect
->discard
) {
2533 radeon_cp_discard_buffer(dev
, file_priv
->master
, buf
);
2540 static int radeon_cp_vertex2(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
2542 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2543 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
2544 drm_radeon_sarea_t
*sarea_priv
;
2545 struct drm_device_dma
*dma
= dev
->dma
;
2546 struct drm_buf
*buf
;
2547 drm_radeon_vertex2_t
*vertex
= data
;
2549 unsigned char laststate
;
2551 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2553 sarea_priv
= master_priv
->sarea_priv
;
2555 DRM_DEBUG("pid=%d index=%d discard=%d\n",
2556 DRM_CURRENTPID
, vertex
->idx
, vertex
->discard
);
2558 if (vertex
->idx
< 0 || vertex
->idx
>= dma
->buf_count
) {
2559 DRM_ERROR("buffer index %d (of %d max)\n",
2560 vertex
->idx
, dma
->buf_count
- 1);
2564 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2565 VB_AGE_TEST_WITH_RETURN(dev_priv
);
2567 buf
= dma
->buflist
[vertex
->idx
];
2569 if (buf
->file_priv
!= file_priv
) {
2570 DRM_ERROR("process %d using buffer owned by %p\n",
2571 DRM_CURRENTPID
, buf
->file_priv
);
2576 DRM_ERROR("sending pending buffer %d\n", vertex
->idx
);
2580 if (sarea_priv
->nbox
> RADEON_NR_SAREA_CLIPRECTS
)
2583 for (laststate
= 0xff, i
= 0; i
< vertex
->nr_prims
; i
++) {
2584 drm_radeon_prim_t prim
;
2585 drm_radeon_tcl_prim_t tclprim
;
2587 if (DRM_COPY_FROM_USER(&prim
, &vertex
->prim
[i
], sizeof(prim
)))
2590 if (prim
.stateidx
!= laststate
) {
2591 drm_radeon_state_t state
;
2593 if (DRM_COPY_FROM_USER(&state
,
2594 &vertex
->state
[prim
.stateidx
],
2598 if (radeon_emit_state2(dev_priv
, file_priv
, &state
)) {
2599 DRM_ERROR("radeon_emit_state2 failed\n");
2603 laststate
= prim
.stateidx
;
2606 tclprim
.start
= prim
.start
;
2607 tclprim
.finish
= prim
.finish
;
2608 tclprim
.prim
= prim
.prim
;
2609 tclprim
.vc_format
= prim
.vc_format
;
2611 if (prim
.prim
& RADEON_PRIM_WALK_IND
) {
2612 tclprim
.offset
= prim
.numverts
* 64;
2613 tclprim
.numverts
= RADEON_MAX_VB_VERTS
; /* duh */
2615 radeon_cp_dispatch_indices(dev
, file_priv
->master
, buf
, &tclprim
);
2617 tclprim
.numverts
= prim
.numverts
;
2618 tclprim
.offset
= 0; /* not used */
2620 radeon_cp_dispatch_vertex(dev
, file_priv
, buf
, &tclprim
);
2623 if (sarea_priv
->nbox
== 1)
2624 sarea_priv
->nbox
= 0;
2627 if (vertex
->discard
) {
2628 radeon_cp_discard_buffer(dev
, file_priv
->master
, buf
);
2635 static int radeon_emit_packets(drm_radeon_private_t
* dev_priv
,
2636 struct drm_file
*file_priv
,
2637 drm_radeon_cmd_header_t header
,
2638 drm_radeon_kcmd_buffer_t
*cmdbuf
)
2640 int id
= (int)header
.packet
.packet_id
;
2644 if (id
>= RADEON_MAX_STATE_PACKETS
)
2647 sz
= packet
[id
].len
;
2648 reg
= packet
[id
].start
;
2650 if (sz
* sizeof(u32
) > drm_buffer_unprocessed(cmdbuf
->buffer
)) {
2651 DRM_ERROR("Packet size provided larger than data provided\n");
2655 if (radeon_check_and_fixup_packets(dev_priv
, file_priv
, id
,
2657 DRM_ERROR("Packet verification failed\n");
2662 OUT_RING(CP_PACKET0(reg
, (sz
- 1)));
2663 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, sz
);
2669 static __inline__
int radeon_emit_scalars(drm_radeon_private_t
*dev_priv
,
2670 drm_radeon_cmd_header_t header
,
2671 drm_radeon_kcmd_buffer_t
*cmdbuf
)
2673 int sz
= header
.scalars
.count
;
2674 int start
= header
.scalars
.offset
;
2675 int stride
= header
.scalars
.stride
;
2679 OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG
, 0));
2680 OUT_RING(start
| (stride
<< RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT
));
2681 OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG
, sz
- 1));
2682 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, sz
);
2689 static __inline__
int radeon_emit_scalars2(drm_radeon_private_t
*dev_priv
,
2690 drm_radeon_cmd_header_t header
,
2691 drm_radeon_kcmd_buffer_t
*cmdbuf
)
2693 int sz
= header
.scalars
.count
;
2694 int start
= ((unsigned int)header
.scalars
.offset
) + 0x100;
2695 int stride
= header
.scalars
.stride
;
2699 OUT_RING(CP_PACKET0(RADEON_SE_TCL_SCALAR_INDX_REG
, 0));
2700 OUT_RING(start
| (stride
<< RADEON_SCAL_INDX_DWORD_STRIDE_SHIFT
));
2701 OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_SCALAR_DATA_REG
, sz
- 1));
2702 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, sz
);
2707 static __inline__
int radeon_emit_vectors(drm_radeon_private_t
*dev_priv
,
2708 drm_radeon_cmd_header_t header
,
2709 drm_radeon_kcmd_buffer_t
*cmdbuf
)
2711 int sz
= header
.vectors
.count
;
2712 int start
= header
.vectors
.offset
;
2713 int stride
= header
.vectors
.stride
;
2717 OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH
, 0);
2718 OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG
, 0));
2719 OUT_RING(start
| (stride
<< RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT
));
2720 OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG
, (sz
- 1)));
2721 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, sz
);
2727 static __inline__
int radeon_emit_veclinear(drm_radeon_private_t
*dev_priv
,
2728 drm_radeon_cmd_header_t header
,
2729 drm_radeon_kcmd_buffer_t
*cmdbuf
)
2731 int sz
= header
.veclinear
.count
* 4;
2732 int start
= header
.veclinear
.addr_lo
| (header
.veclinear
.addr_hi
<< 8);
2737 if (sz
* 4 > drm_buffer_unprocessed(cmdbuf
->buffer
))
2741 OUT_RING_REG(RADEON_SE_TCL_STATE_FLUSH
, 0);
2742 OUT_RING(CP_PACKET0(RADEON_SE_TCL_VECTOR_INDX_REG
, 0));
2743 OUT_RING(start
| (1 << RADEON_VEC_INDX_OCTWORD_STRIDE_SHIFT
));
2744 OUT_RING(CP_PACKET0_TABLE(RADEON_SE_TCL_VECTOR_DATA_REG
, (sz
- 1)));
2745 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, sz
);
2751 static int radeon_emit_packet3(struct drm_device
* dev
,
2752 struct drm_file
*file_priv
,
2753 drm_radeon_kcmd_buffer_t
*cmdbuf
)
2755 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2762 if ((ret
= radeon_check_and_fixup_packet3(dev_priv
, file_priv
,
2764 DRM_ERROR("Packet verification failed\n");
2769 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, cmdsz
);
2775 static int radeon_emit_packet3_cliprect(struct drm_device
*dev
,
2776 struct drm_file
*file_priv
,
2777 drm_radeon_kcmd_buffer_t
*cmdbuf
,
2780 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2781 struct drm_clip_rect box
;
2784 struct drm_clip_rect __user
*boxes
= cmdbuf
->boxes
;
2790 if ((ret
= radeon_check_and_fixup_packet3(dev_priv
, file_priv
,
2792 DRM_ERROR("Packet verification failed\n");
2800 if (i
< cmdbuf
->nbox
) {
2801 if (DRM_COPY_FROM_USER(&box
, &boxes
[i
], sizeof(box
)))
2803 /* FIXME The second and subsequent times round
2804 * this loop, send a WAIT_UNTIL_3D_IDLE before
2805 * calling emit_clip_rect(). This fixes a
2806 * lockup on fast machines when sending
2807 * several cliprects with a cmdbuf, as when
2808 * waving a 2D window over a 3D
2809 * window. Something in the commands from user
2810 * space seems to hang the card when they're
2811 * sent several times in a row. That would be
2812 * the correct place to fix it but this works
2813 * around it until I can figure that out - Tim
2817 RADEON_WAIT_UNTIL_3D_IDLE();
2820 radeon_emit_clip_rect(dev_priv
, &box
);
2824 OUT_RING_DRM_BUFFER(cmdbuf
->buffer
, cmdsz
);
2827 } while (++i
< cmdbuf
->nbox
);
2828 if (cmdbuf
->nbox
== 1)
2833 drm_buffer_advance(cmdbuf
->buffer
, cmdsz
* 4);
2837 static int radeon_emit_wait(struct drm_device
* dev
, int flags
)
2839 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2842 DRM_DEBUG("%x\n", flags
);
2844 case RADEON_WAIT_2D
:
2846 RADEON_WAIT_UNTIL_2D_IDLE();
2849 case RADEON_WAIT_3D
:
2851 RADEON_WAIT_UNTIL_3D_IDLE();
2854 case RADEON_WAIT_2D
| RADEON_WAIT_3D
:
2856 RADEON_WAIT_UNTIL_IDLE();
2866 static int radeon_cp_cmdbuf(struct drm_device
*dev
, void *data
,
2867 struct drm_file
*file_priv
)
2869 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
2870 struct drm_device_dma
*dma
= dev
->dma
;
2871 struct drm_buf
*buf
= NULL
;
2872 drm_radeon_cmd_header_t stack_header
;
2874 drm_radeon_kcmd_buffer_t
*cmdbuf
= data
;
2877 LOCK_TEST_WITH_RETURN(dev
, file_priv
);
2879 RING_SPACE_TEST_WITH_RETURN(dev_priv
);
2880 VB_AGE_TEST_WITH_RETURN(dev_priv
);
2882 if (cmdbuf
->bufsz
> 64 * 1024 || cmdbuf
->bufsz
< 0) {
2886 /* Allocate an in-kernel area and copy in the cmdbuf. Do this to avoid
2887 * races between checking values and using those values in other code,
2888 * and simply to avoid a lot of function calls to copy in data.
2890 if (cmdbuf
->bufsz
!= 0) {
2892 void __user
*buffer
= cmdbuf
->buffer
;
2893 rv
= drm_buffer_alloc(&cmdbuf
->buffer
, cmdbuf
->bufsz
);
2896 rv
= drm_buffer_copy_from_user(cmdbuf
->buffer
, buffer
,
2902 orig_nbox
= cmdbuf
->nbox
;
2904 if (dev_priv
->microcode_version
== UCODE_R300
) {
2906 temp
= r300_do_cp_cmdbuf(dev
, file_priv
, cmdbuf
);
2908 if (cmdbuf
->bufsz
!= 0)
2909 drm_buffer_free(cmdbuf
->buffer
);
2914 /* microcode_version != r300 */
2915 while (drm_buffer_unprocessed(cmdbuf
->buffer
) >= sizeof(stack_header
)) {
2917 drm_radeon_cmd_header_t
*header
;
2918 header
= drm_buffer_read_object(cmdbuf
->buffer
,
2919 sizeof(stack_header
), &stack_header
);
2921 switch (header
->header
.cmd_type
) {
2922 case RADEON_CMD_PACKET
:
2923 DRM_DEBUG("RADEON_CMD_PACKET\n");
2924 if (radeon_emit_packets
2925 (dev_priv
, file_priv
, *header
, cmdbuf
)) {
2926 DRM_ERROR("radeon_emit_packets failed\n");
2931 case RADEON_CMD_SCALARS
:
2932 DRM_DEBUG("RADEON_CMD_SCALARS\n");
2933 if (radeon_emit_scalars(dev_priv
, *header
, cmdbuf
)) {
2934 DRM_ERROR("radeon_emit_scalars failed\n");
2939 case RADEON_CMD_VECTORS
:
2940 DRM_DEBUG("RADEON_CMD_VECTORS\n");
2941 if (radeon_emit_vectors(dev_priv
, *header
, cmdbuf
)) {
2942 DRM_ERROR("radeon_emit_vectors failed\n");
2947 case RADEON_CMD_DMA_DISCARD
:
2948 DRM_DEBUG("RADEON_CMD_DMA_DISCARD\n");
2949 idx
= header
->dma
.buf_idx
;
2950 if (idx
< 0 || idx
>= dma
->buf_count
) {
2951 DRM_ERROR("buffer index %d (of %d max)\n",
2952 idx
, dma
->buf_count
- 1);
2956 buf
= dma
->buflist
[idx
];
2957 if (buf
->file_priv
!= file_priv
|| buf
->pending
) {
2958 DRM_ERROR("bad buffer %p %p %d\n",
2959 buf
->file_priv
, file_priv
,
2964 radeon_cp_discard_buffer(dev
, file_priv
->master
, buf
);
2967 case RADEON_CMD_PACKET3
:
2968 DRM_DEBUG("RADEON_CMD_PACKET3\n");
2969 if (radeon_emit_packet3(dev
, file_priv
, cmdbuf
)) {
2970 DRM_ERROR("radeon_emit_packet3 failed\n");
2975 case RADEON_CMD_PACKET3_CLIP
:
2976 DRM_DEBUG("RADEON_CMD_PACKET3_CLIP\n");
2977 if (radeon_emit_packet3_cliprect
2978 (dev
, file_priv
, cmdbuf
, orig_nbox
)) {
2979 DRM_ERROR("radeon_emit_packet3_clip failed\n");
2984 case RADEON_CMD_SCALARS2
:
2985 DRM_DEBUG("RADEON_CMD_SCALARS2\n");
2986 if (radeon_emit_scalars2(dev_priv
, *header
, cmdbuf
)) {
2987 DRM_ERROR("radeon_emit_scalars2 failed\n");
2992 case RADEON_CMD_WAIT
:
2993 DRM_DEBUG("RADEON_CMD_WAIT\n");
2994 if (radeon_emit_wait(dev
, header
->wait
.flags
)) {
2995 DRM_ERROR("radeon_emit_wait failed\n");
2999 case RADEON_CMD_VECLINEAR
:
3000 DRM_DEBUG("RADEON_CMD_VECLINEAR\n");
3001 if (radeon_emit_veclinear(dev_priv
, *header
, cmdbuf
)) {
3002 DRM_ERROR("radeon_emit_veclinear failed\n");
3008 DRM_ERROR("bad cmd_type %d at byte %d\n",
3009 header
->header
.cmd_type
,
3010 cmdbuf
->buffer
->iterator
);
3015 if (cmdbuf
->bufsz
!= 0)
3016 drm_buffer_free(cmdbuf
->buffer
);
3018 DRM_DEBUG("DONE\n");
3023 if (cmdbuf
->bufsz
!= 0)
3024 drm_buffer_free(cmdbuf
->buffer
);
3028 static int radeon_cp_getparam(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
3030 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
3031 drm_radeon_getparam_t
*param
= data
;
3034 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID
);
3036 switch (param
->param
) {
3037 case RADEON_PARAM_GART_BUFFER_OFFSET
:
3038 value
= dev_priv
->gart_buffers_offset
;
3040 case RADEON_PARAM_LAST_FRAME
:
3041 dev_priv
->stats
.last_frame_reads
++;
3042 value
= GET_SCRATCH(dev_priv
, 0);
3044 case RADEON_PARAM_LAST_DISPATCH
:
3045 value
= GET_SCRATCH(dev_priv
, 1);
3047 case RADEON_PARAM_LAST_CLEAR
:
3048 dev_priv
->stats
.last_clear_reads
++;
3049 value
= GET_SCRATCH(dev_priv
, 2);
3051 case RADEON_PARAM_IRQ_NR
:
3052 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_R600
)
3055 value
= drm_dev_to_irq(dev
);
3057 case RADEON_PARAM_GART_BASE
:
3058 value
= dev_priv
->gart_vm_start
;
3060 case RADEON_PARAM_REGISTER_HANDLE
:
3061 value
= dev_priv
->mmio
->offset
;
3063 case RADEON_PARAM_STATUS_HANDLE
:
3064 value
= dev_priv
->ring_rptr_offset
;
3066 #if BITS_PER_LONG == 32
3068 * This ioctl() doesn't work on 64-bit platforms because hw_lock is a
3069 * pointer which can't fit into an int-sized variable. According to
3070 * Michel Dänzer, the ioctl() is only used on embedded platforms, so
3071 * not supporting it shouldn't be a problem. If the same functionality
3072 * is needed on 64-bit platforms, a new ioctl() would have to be added,
3073 * so backwards-compatibility for the embedded platforms can be
3074 * maintained. --davidm 4-Feb-2004.
3076 case RADEON_PARAM_SAREA_HANDLE
:
3077 /* The lock is the first dword in the sarea. */
3078 /* no users of this parameter */
3081 case RADEON_PARAM_GART_TEX_HANDLE
:
3082 value
= dev_priv
->gart_textures_offset
;
3084 case RADEON_PARAM_SCRATCH_OFFSET
:
3085 if (!dev_priv
->writeback_works
)
3087 if ((dev_priv
->flags
& RADEON_FAMILY_MASK
) >= CHIP_R600
)
3088 value
= R600_SCRATCH_REG_OFFSET
;
3090 value
= RADEON_SCRATCH_REG_OFFSET
;
3092 case RADEON_PARAM_CARD_TYPE
:
3093 if (dev_priv
->flags
& RADEON_IS_PCIE
)
3094 value
= RADEON_CARD_PCIE
;
3095 else if (dev_priv
->flags
& RADEON_IS_AGP
)
3096 value
= RADEON_CARD_AGP
;
3098 value
= RADEON_CARD_PCI
;
3100 case RADEON_PARAM_VBLANK_CRTC
:
3101 value
= radeon_vblank_crtc_get(dev
);
3103 case RADEON_PARAM_FB_LOCATION
:
3104 value
= radeon_read_fb_location(dev_priv
);
3106 case RADEON_PARAM_NUM_GB_PIPES
:
3107 value
= dev_priv
->num_gb_pipes
;
3109 case RADEON_PARAM_NUM_Z_PIPES
:
3110 value
= dev_priv
->num_z_pipes
;
3113 DRM_DEBUG("Invalid parameter %d\n", param
->param
);
3117 if (DRM_COPY_TO_USER(param
->value
, &value
, sizeof(int))) {
3118 DRM_ERROR("copy_to_user\n");
3125 static int radeon_cp_setparam(struct drm_device
*dev
, void *data
, struct drm_file
*file_priv
)
3127 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
3128 struct drm_radeon_master_private
*master_priv
= file_priv
->master
->driver_priv
;
3129 drm_radeon_setparam_t
*sp
= data
;
3130 struct drm_radeon_driver_file_fields
*radeon_priv
;
3132 switch (sp
->param
) {
3133 case RADEON_SETPARAM_FB_LOCATION
:
3134 radeon_priv
= file_priv
->driver_priv
;
3135 radeon_priv
->radeon_fb_delta
= dev_priv
->fb_location
-
3138 case RADEON_SETPARAM_SWITCH_TILING
:
3139 if (sp
->value
== 0) {
3140 DRM_DEBUG("color tiling disabled\n");
3141 dev_priv
->front_pitch_offset
&= ~RADEON_DST_TILE_MACRO
;
3142 dev_priv
->back_pitch_offset
&= ~RADEON_DST_TILE_MACRO
;
3143 if (master_priv
->sarea_priv
)
3144 master_priv
->sarea_priv
->tiling_enabled
= 0;
3145 } else if (sp
->value
== 1) {
3146 DRM_DEBUG("color tiling enabled\n");
3147 dev_priv
->front_pitch_offset
|= RADEON_DST_TILE_MACRO
;
3148 dev_priv
->back_pitch_offset
|= RADEON_DST_TILE_MACRO
;
3149 if (master_priv
->sarea_priv
)
3150 master_priv
->sarea_priv
->tiling_enabled
= 1;
3153 case RADEON_SETPARAM_PCIGART_LOCATION
:
3154 dev_priv
->pcigart_offset
= sp
->value
;
3155 dev_priv
->pcigart_offset_set
= 1;
3157 case RADEON_SETPARAM_NEW_MEMMAP
:
3158 dev_priv
->new_memmap
= sp
->value
;
3160 case RADEON_SETPARAM_PCIGART_TABLE_SIZE
:
3161 dev_priv
->gart_info
.table_size
= sp
->value
;
3162 if (dev_priv
->gart_info
.table_size
< RADEON_PCIGART_TABLE_SIZE
)
3163 dev_priv
->gart_info
.table_size
= RADEON_PCIGART_TABLE_SIZE
;
3165 case RADEON_SETPARAM_VBLANK_CRTC
:
3166 return radeon_vblank_crtc_set(dev
, sp
->value
);
3169 DRM_DEBUG("Invalid parameter %d\n", sp
->param
);
3176 /* When a client dies:
3177 * - Check for and clean up flipped page state
3178 * - Free any alloced GART memory.
3179 * - Free any alloced radeon surfaces.
3181 * DRM infrastructure takes care of reclaiming dma buffers.
3183 void radeon_driver_preclose(struct drm_device
*dev
, struct drm_file
*file_priv
)
3185 if (dev
->dev_private
) {
3186 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
3187 dev_priv
->page_flipping
= 0;
3188 radeon_mem_release(file_priv
, dev_priv
->gart_heap
);
3189 radeon_mem_release(file_priv
, dev_priv
->fb_heap
);
3190 radeon_surfaces_release(file_priv
, dev_priv
);
3194 void radeon_driver_lastclose(struct drm_device
*dev
)
3196 radeon_surfaces_release(PCIGART_FILE_PRIV
, dev
->dev_private
);
3197 radeon_do_release(dev
);
3200 int radeon_driver_open(struct drm_device
*dev
, struct drm_file
*file_priv
)
3202 drm_radeon_private_t
*dev_priv
= dev
->dev_private
;
3203 struct drm_radeon_driver_file_fields
*radeon_priv
;
3206 radeon_priv
= kmalloc(sizeof(*radeon_priv
), GFP_KERNEL
);
3211 file_priv
->driver_priv
= radeon_priv
;
3214 radeon_priv
->radeon_fb_delta
= dev_priv
->fb_location
;
3216 radeon_priv
->radeon_fb_delta
= 0;
3220 void radeon_driver_postclose(struct drm_device
*dev
, struct drm_file
*file_priv
)
3222 struct drm_radeon_driver_file_fields
*radeon_priv
=
3223 file_priv
->driver_priv
;
3228 struct drm_ioctl_desc radeon_ioctls
[] = {
3229 DRM_IOCTL_DEF(DRM_RADEON_CP_INIT
, radeon_cp_init
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
3230 DRM_IOCTL_DEF(DRM_RADEON_CP_START
, radeon_cp_start
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
3231 DRM_IOCTL_DEF(DRM_RADEON_CP_STOP
, radeon_cp_stop
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
3232 DRM_IOCTL_DEF(DRM_RADEON_CP_RESET
, radeon_cp_reset
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
3233 DRM_IOCTL_DEF(DRM_RADEON_CP_IDLE
, radeon_cp_idle
, DRM_AUTH
),
3234 DRM_IOCTL_DEF(DRM_RADEON_CP_RESUME
, radeon_cp_resume
, DRM_AUTH
),
3235 DRM_IOCTL_DEF(DRM_RADEON_RESET
, radeon_engine_reset
, DRM_AUTH
),
3236 DRM_IOCTL_DEF(DRM_RADEON_FULLSCREEN
, radeon_fullscreen
, DRM_AUTH
),
3237 DRM_IOCTL_DEF(DRM_RADEON_SWAP
, radeon_cp_swap
, DRM_AUTH
),
3238 DRM_IOCTL_DEF(DRM_RADEON_CLEAR
, radeon_cp_clear
, DRM_AUTH
),
3239 DRM_IOCTL_DEF(DRM_RADEON_VERTEX
, radeon_cp_vertex
, DRM_AUTH
),
3240 DRM_IOCTL_DEF(DRM_RADEON_INDICES
, radeon_cp_indices
, DRM_AUTH
),
3241 DRM_IOCTL_DEF(DRM_RADEON_TEXTURE
, radeon_cp_texture
, DRM_AUTH
),
3242 DRM_IOCTL_DEF(DRM_RADEON_STIPPLE
, radeon_cp_stipple
, DRM_AUTH
),
3243 DRM_IOCTL_DEF(DRM_RADEON_INDIRECT
, radeon_cp_indirect
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
3244 DRM_IOCTL_DEF(DRM_RADEON_VERTEX2
, radeon_cp_vertex2
, DRM_AUTH
),
3245 DRM_IOCTL_DEF(DRM_RADEON_CMDBUF
, radeon_cp_cmdbuf
, DRM_AUTH
),
3246 DRM_IOCTL_DEF(DRM_RADEON_GETPARAM
, radeon_cp_getparam
, DRM_AUTH
),
3247 DRM_IOCTL_DEF(DRM_RADEON_FLIP
, radeon_cp_flip
, DRM_AUTH
),
3248 DRM_IOCTL_DEF(DRM_RADEON_ALLOC
, radeon_mem_alloc
, DRM_AUTH
),
3249 DRM_IOCTL_DEF(DRM_RADEON_FREE
, radeon_mem_free
, DRM_AUTH
),
3250 DRM_IOCTL_DEF(DRM_RADEON_INIT_HEAP
, radeon_mem_init_heap
, DRM_AUTH
|DRM_MASTER
|DRM_ROOT_ONLY
),
3251 DRM_IOCTL_DEF(DRM_RADEON_IRQ_EMIT
, radeon_irq_emit
, DRM_AUTH
),
3252 DRM_IOCTL_DEF(DRM_RADEON_IRQ_WAIT
, radeon_irq_wait
, DRM_AUTH
),
3253 DRM_IOCTL_DEF(DRM_RADEON_SETPARAM
, radeon_cp_setparam
, DRM_AUTH
),
3254 DRM_IOCTL_DEF(DRM_RADEON_SURF_ALLOC
, radeon_surface_alloc
, DRM_AUTH
),
3255 DRM_IOCTL_DEF(DRM_RADEON_SURF_FREE
, radeon_surface_free
, DRM_AUTH
),
3256 DRM_IOCTL_DEF(DRM_RADEON_CS
, r600_cs_legacy_ioctl
, DRM_AUTH
)
3259 int radeon_max_ioctl
= DRM_ARRAY_SIZE(radeon_ioctls
);