/drivers/char/drm/radeon_state.c

https://bitbucket.org/evzijst/gittest · C · 3102 lines · 2319 code · 481 blank · 302 comment · 327 complexity · ffee6bcbcc422e06c42ca5a737156a5c MD5 · raw file

Large files are truncated click here to view the full file

  1. /* radeon_state.c -- State support for Radeon -*- linux-c -*-
  2. *
  3. * Copyright 2000 VA Linux Systems, Inc., Fremont, California.
  4. * All Rights Reserved.
  5. *
  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:
  12. *
  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
  15. * Software.
  16. *
  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.
  24. *
  25. * Authors:
  26. * Gareth Hughes <gareth@valinux.com>
  27. * Kevin E. Martin <martin@valinux.com>
  28. */
  29. #include "drmP.h"
  30. #include "drm.h"
  31. #include "drm_sarea.h"
  32. #include "radeon_drm.h"
  33. #include "radeon_drv.h"
  34. /* ================================================================
  35. * Helper functions for client state checking and fixup
  36. */
  37. static __inline__ int radeon_check_and_fixup_offset( drm_radeon_private_t *dev_priv,
  38. drm_file_t *filp_priv,
  39. u32 *offset ) {
  40. u32 off = *offset;
  41. struct drm_radeon_driver_file_fields *radeon_priv;
  42. if ( off >= dev_priv->fb_location &&
  43. off < ( dev_priv->gart_vm_start + dev_priv->gart_size ) )
  44. return 0;
  45. radeon_priv = filp_priv->driver_priv;
  46. off += radeon_priv->radeon_fb_delta;
  47. DRM_DEBUG( "offset fixed up to 0x%x\n", off );
  48. if ( off < dev_priv->fb_location ||
  49. off >= ( dev_priv->gart_vm_start + dev_priv->gart_size ) )
  50. return DRM_ERR( EINVAL );
  51. *offset = off;
  52. return 0;
  53. }
  54. static __inline__ int radeon_check_and_fixup_packets( drm_radeon_private_t *dev_priv,
  55. drm_file_t *filp_priv,
  56. int id,
  57. u32 __user *data ) {
  58. switch ( id ) {
  59. case RADEON_EMIT_PP_MISC:
  60. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  61. &data[( RADEON_RB3D_DEPTHOFFSET
  62. - RADEON_PP_MISC ) / 4] ) ) {
  63. DRM_ERROR( "Invalid depth buffer offset\n" );
  64. return DRM_ERR( EINVAL );
  65. }
  66. break;
  67. case RADEON_EMIT_PP_CNTL:
  68. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  69. &data[( RADEON_RB3D_COLOROFFSET
  70. - RADEON_PP_CNTL ) / 4] ) ) {
  71. DRM_ERROR( "Invalid colour buffer offset\n" );
  72. return DRM_ERR( EINVAL );
  73. }
  74. break;
  75. case R200_EMIT_PP_TXOFFSET_0:
  76. case R200_EMIT_PP_TXOFFSET_1:
  77. case R200_EMIT_PP_TXOFFSET_2:
  78. case R200_EMIT_PP_TXOFFSET_3:
  79. case R200_EMIT_PP_TXOFFSET_4:
  80. case R200_EMIT_PP_TXOFFSET_5:
  81. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  82. &data[0] ) ) {
  83. DRM_ERROR( "Invalid R200 texture offset\n" );
  84. return DRM_ERR( EINVAL );
  85. }
  86. break;
  87. case RADEON_EMIT_PP_TXFILTER_0:
  88. case RADEON_EMIT_PP_TXFILTER_1:
  89. case RADEON_EMIT_PP_TXFILTER_2:
  90. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  91. &data[( RADEON_PP_TXOFFSET_0
  92. - RADEON_PP_TXFILTER_0 ) / 4] ) ) {
  93. DRM_ERROR( "Invalid R100 texture offset\n" );
  94. return DRM_ERR( EINVAL );
  95. }
  96. break;
  97. case R200_EMIT_PP_CUBIC_OFFSETS_0:
  98. case R200_EMIT_PP_CUBIC_OFFSETS_1:
  99. case R200_EMIT_PP_CUBIC_OFFSETS_2:
  100. case R200_EMIT_PP_CUBIC_OFFSETS_3:
  101. case R200_EMIT_PP_CUBIC_OFFSETS_4:
  102. case R200_EMIT_PP_CUBIC_OFFSETS_5: {
  103. int i;
  104. for ( i = 0; i < 5; i++ ) {
  105. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  106. &data[i] ) ) {
  107. DRM_ERROR( "Invalid R200 cubic texture offset\n" );
  108. return DRM_ERR( EINVAL );
  109. }
  110. }
  111. break;
  112. }
  113. case RADEON_EMIT_PP_CUBIC_OFFSETS_T0:
  114. case RADEON_EMIT_PP_CUBIC_OFFSETS_T1:
  115. case RADEON_EMIT_PP_CUBIC_OFFSETS_T2:{
  116. int i;
  117. for (i = 0; i < 5; i++) {
  118. if (radeon_check_and_fixup_offset(dev_priv,
  119. filp_priv,
  120. &data[i])) {
  121. DRM_ERROR
  122. ("Invalid R100 cubic texture offset\n");
  123. return DRM_ERR(EINVAL);
  124. }
  125. }
  126. }
  127. break;
  128. case RADEON_EMIT_RB3D_COLORPITCH:
  129. case RADEON_EMIT_RE_LINE_PATTERN:
  130. case RADEON_EMIT_SE_LINE_WIDTH:
  131. case RADEON_EMIT_PP_LUM_MATRIX:
  132. case RADEON_EMIT_PP_ROT_MATRIX_0:
  133. case RADEON_EMIT_RB3D_STENCILREFMASK:
  134. case RADEON_EMIT_SE_VPORT_XSCALE:
  135. case RADEON_EMIT_SE_CNTL:
  136. case RADEON_EMIT_SE_CNTL_STATUS:
  137. case RADEON_EMIT_RE_MISC:
  138. case RADEON_EMIT_PP_BORDER_COLOR_0:
  139. case RADEON_EMIT_PP_BORDER_COLOR_1:
  140. case RADEON_EMIT_PP_BORDER_COLOR_2:
  141. case RADEON_EMIT_SE_ZBIAS_FACTOR:
  142. case RADEON_EMIT_SE_TCL_OUTPUT_VTX_FMT:
  143. case RADEON_EMIT_SE_TCL_MATERIAL_EMMISSIVE_RED:
  144. case R200_EMIT_PP_TXCBLEND_0:
  145. case R200_EMIT_PP_TXCBLEND_1:
  146. case R200_EMIT_PP_TXCBLEND_2:
  147. case R200_EMIT_PP_TXCBLEND_3:
  148. case R200_EMIT_PP_TXCBLEND_4:
  149. case R200_EMIT_PP_TXCBLEND_5:
  150. case R200_EMIT_PP_TXCBLEND_6:
  151. case R200_EMIT_PP_TXCBLEND_7:
  152. case R200_EMIT_TCL_LIGHT_MODEL_CTL_0:
  153. case R200_EMIT_TFACTOR_0:
  154. case R200_EMIT_VTX_FMT_0:
  155. case R200_EMIT_VAP_CTL:
  156. case R200_EMIT_MATRIX_SELECT_0:
  157. case R200_EMIT_TEX_PROC_CTL_2:
  158. case R200_EMIT_TCL_UCP_VERT_BLEND_CTL:
  159. case R200_EMIT_PP_TXFILTER_0:
  160. case R200_EMIT_PP_TXFILTER_1:
  161. case R200_EMIT_PP_TXFILTER_2:
  162. case R200_EMIT_PP_TXFILTER_3:
  163. case R200_EMIT_PP_TXFILTER_4:
  164. case R200_EMIT_PP_TXFILTER_5:
  165. case R200_EMIT_VTE_CNTL:
  166. case R200_EMIT_OUTPUT_VTX_COMP_SEL:
  167. case R200_EMIT_PP_TAM_DEBUG3:
  168. case R200_EMIT_PP_CNTL_X:
  169. case R200_EMIT_RB3D_DEPTHXY_OFFSET:
  170. case R200_EMIT_RE_AUX_SCISSOR_CNTL:
  171. case R200_EMIT_RE_SCISSOR_TL_0:
  172. case R200_EMIT_RE_SCISSOR_TL_1:
  173. case R200_EMIT_RE_SCISSOR_TL_2:
  174. case R200_EMIT_SE_VAP_CNTL_STATUS:
  175. case R200_EMIT_SE_VTX_STATE_CNTL:
  176. case R200_EMIT_RE_POINTSIZE:
  177. case R200_EMIT_TCL_INPUT_VTX_VECTOR_ADDR_0:
  178. case R200_EMIT_PP_CUBIC_FACES_0:
  179. case R200_EMIT_PP_CUBIC_FACES_1:
  180. case R200_EMIT_PP_CUBIC_FACES_2:
  181. case R200_EMIT_PP_CUBIC_FACES_3:
  182. case R200_EMIT_PP_CUBIC_FACES_4:
  183. case R200_EMIT_PP_CUBIC_FACES_5:
  184. case RADEON_EMIT_PP_TEX_SIZE_0:
  185. case RADEON_EMIT_PP_TEX_SIZE_1:
  186. case RADEON_EMIT_PP_TEX_SIZE_2:
  187. case R200_EMIT_RB3D_BLENDCOLOR:
  188. case R200_EMIT_TCL_POINT_SPRITE_CNTL:
  189. case RADEON_EMIT_PP_CUBIC_FACES_0:
  190. case RADEON_EMIT_PP_CUBIC_FACES_1:
  191. case RADEON_EMIT_PP_CUBIC_FACES_2:
  192. case R200_EMIT_PP_TRI_PERF_CNTL:
  193. /* These packets don't contain memory offsets */
  194. break;
  195. default:
  196. DRM_ERROR( "Unknown state packet ID %d\n", id );
  197. return DRM_ERR( EINVAL );
  198. }
  199. return 0;
  200. }
  201. static __inline__ int radeon_check_and_fixup_packet3( drm_radeon_private_t *dev_priv,
  202. drm_file_t *filp_priv,
  203. drm_radeon_cmd_buffer_t *cmdbuf,
  204. unsigned int *cmdsz ) {
  205. u32 *cmd = (u32 *) cmdbuf->buf;
  206. *cmdsz = 2 + ( ( cmd[0] & RADEON_CP_PACKET_COUNT_MASK ) >> 16 );
  207. if ( ( cmd[0] & 0xc0000000 ) != RADEON_CP_PACKET3 ) {
  208. DRM_ERROR( "Not a type 3 packet\n" );
  209. return DRM_ERR( EINVAL );
  210. }
  211. if ( 4 * *cmdsz > cmdbuf->bufsz ) {
  212. DRM_ERROR( "Packet size larger than size of data provided\n" );
  213. return DRM_ERR( EINVAL );
  214. }
  215. /* Check client state and fix it up if necessary */
  216. if ( cmd[0] & 0x8000 ) { /* MSB of opcode: next DWORD GUI_CNTL */
  217. u32 offset;
  218. if ( cmd[1] & ( RADEON_GMC_SRC_PITCH_OFFSET_CNTL
  219. | RADEON_GMC_DST_PITCH_OFFSET_CNTL ) ) {
  220. offset = cmd[2] << 10;
  221. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv, &offset ) ) {
  222. DRM_ERROR( "Invalid first packet offset\n" );
  223. return DRM_ERR( EINVAL );
  224. }
  225. cmd[2] = ( cmd[2] & 0xffc00000 ) | offset >> 10;
  226. }
  227. if ( ( cmd[1] & RADEON_GMC_SRC_PITCH_OFFSET_CNTL ) &&
  228. ( cmd[1] & RADEON_GMC_DST_PITCH_OFFSET_CNTL ) ) {
  229. offset = cmd[3] << 10;
  230. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv, &offset ) ) {
  231. DRM_ERROR( "Invalid second packet offset\n" );
  232. return DRM_ERR( EINVAL );
  233. }
  234. cmd[3] = ( cmd[3] & 0xffc00000 ) | offset >> 10;
  235. }
  236. }
  237. return 0;
  238. }
  239. /* ================================================================
  240. * CP hardware state programming functions
  241. */
  242. static __inline__ void radeon_emit_clip_rect( drm_radeon_private_t *dev_priv,
  243. drm_clip_rect_t *box )
  244. {
  245. RING_LOCALS;
  246. DRM_DEBUG( " box: x1=%d y1=%d x2=%d y2=%d\n",
  247. box->x1, box->y1, box->x2, box->y2 );
  248. BEGIN_RING( 4 );
  249. OUT_RING( CP_PACKET0( RADEON_RE_TOP_LEFT, 0 ) );
  250. OUT_RING( (box->y1 << 16) | box->x1 );
  251. OUT_RING( CP_PACKET0( RADEON_RE_WIDTH_HEIGHT, 0 ) );
  252. OUT_RING( ((box->y2 - 1) << 16) | (box->x2 - 1) );
  253. ADVANCE_RING();
  254. }
  255. /* Emit 1.1 state
  256. */
  257. static int radeon_emit_state( drm_radeon_private_t *dev_priv,
  258. drm_file_t *filp_priv,
  259. drm_radeon_context_regs_t *ctx,
  260. drm_radeon_texture_regs_t *tex,
  261. unsigned int dirty )
  262. {
  263. RING_LOCALS;
  264. DRM_DEBUG( "dirty=0x%08x\n", dirty );
  265. if ( dirty & RADEON_UPLOAD_CONTEXT ) {
  266. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  267. &ctx->rb3d_depthoffset ) ) {
  268. DRM_ERROR( "Invalid depth buffer offset\n" );
  269. return DRM_ERR( EINVAL );
  270. }
  271. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  272. &ctx->rb3d_coloroffset ) ) {
  273. DRM_ERROR( "Invalid depth buffer offset\n" );
  274. return DRM_ERR( EINVAL );
  275. }
  276. BEGIN_RING( 14 );
  277. OUT_RING( CP_PACKET0( RADEON_PP_MISC, 6 ) );
  278. OUT_RING( ctx->pp_misc );
  279. OUT_RING( ctx->pp_fog_color );
  280. OUT_RING( ctx->re_solid_color );
  281. OUT_RING( ctx->rb3d_blendcntl );
  282. OUT_RING( ctx->rb3d_depthoffset );
  283. OUT_RING( ctx->rb3d_depthpitch );
  284. OUT_RING( ctx->rb3d_zstencilcntl );
  285. OUT_RING( CP_PACKET0( RADEON_PP_CNTL, 2 ) );
  286. OUT_RING( ctx->pp_cntl );
  287. OUT_RING( ctx->rb3d_cntl );
  288. OUT_RING( ctx->rb3d_coloroffset );
  289. OUT_RING( CP_PACKET0( RADEON_RB3D_COLORPITCH, 0 ) );
  290. OUT_RING( ctx->rb3d_colorpitch );
  291. ADVANCE_RING();
  292. }
  293. if ( dirty & RADEON_UPLOAD_VERTFMT ) {
  294. BEGIN_RING( 2 );
  295. OUT_RING( CP_PACKET0( RADEON_SE_COORD_FMT, 0 ) );
  296. OUT_RING( ctx->se_coord_fmt );
  297. ADVANCE_RING();
  298. }
  299. if ( dirty & RADEON_UPLOAD_LINE ) {
  300. BEGIN_RING( 5 );
  301. OUT_RING( CP_PACKET0( RADEON_RE_LINE_PATTERN, 1 ) );
  302. OUT_RING( ctx->re_line_pattern );
  303. OUT_RING( ctx->re_line_state );
  304. OUT_RING( CP_PACKET0( RADEON_SE_LINE_WIDTH, 0 ) );
  305. OUT_RING( ctx->se_line_width );
  306. ADVANCE_RING();
  307. }
  308. if ( dirty & RADEON_UPLOAD_BUMPMAP ) {
  309. BEGIN_RING( 5 );
  310. OUT_RING( CP_PACKET0( RADEON_PP_LUM_MATRIX, 0 ) );
  311. OUT_RING( ctx->pp_lum_matrix );
  312. OUT_RING( CP_PACKET0( RADEON_PP_ROT_MATRIX_0, 1 ) );
  313. OUT_RING( ctx->pp_rot_matrix_0 );
  314. OUT_RING( ctx->pp_rot_matrix_1 );
  315. ADVANCE_RING();
  316. }
  317. if ( dirty & RADEON_UPLOAD_MASKS ) {
  318. BEGIN_RING( 4 );
  319. OUT_RING( CP_PACKET0( RADEON_RB3D_STENCILREFMASK, 2 ) );
  320. OUT_RING( ctx->rb3d_stencilrefmask );
  321. OUT_RING( ctx->rb3d_ropcntl );
  322. OUT_RING( ctx->rb3d_planemask );
  323. ADVANCE_RING();
  324. }
  325. if ( dirty & RADEON_UPLOAD_VIEWPORT ) {
  326. BEGIN_RING( 7 );
  327. OUT_RING( CP_PACKET0( RADEON_SE_VPORT_XSCALE, 5 ) );
  328. OUT_RING( ctx->se_vport_xscale );
  329. OUT_RING( ctx->se_vport_xoffset );
  330. OUT_RING( ctx->se_vport_yscale );
  331. OUT_RING( ctx->se_vport_yoffset );
  332. OUT_RING( ctx->se_vport_zscale );
  333. OUT_RING( ctx->se_vport_zoffset );
  334. ADVANCE_RING();
  335. }
  336. if ( dirty & RADEON_UPLOAD_SETUP ) {
  337. BEGIN_RING( 4 );
  338. OUT_RING( CP_PACKET0( RADEON_SE_CNTL, 0 ) );
  339. OUT_RING( ctx->se_cntl );
  340. OUT_RING( CP_PACKET0( RADEON_SE_CNTL_STATUS, 0 ) );
  341. OUT_RING( ctx->se_cntl_status );
  342. ADVANCE_RING();
  343. }
  344. if ( dirty & RADEON_UPLOAD_MISC ) {
  345. BEGIN_RING( 2 );
  346. OUT_RING( CP_PACKET0( RADEON_RE_MISC, 0 ) );
  347. OUT_RING( ctx->re_misc );
  348. ADVANCE_RING();
  349. }
  350. if ( dirty & RADEON_UPLOAD_TEX0 ) {
  351. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  352. &tex[0].pp_txoffset ) ) {
  353. DRM_ERROR( "Invalid texture offset for unit 0\n" );
  354. return DRM_ERR( EINVAL );
  355. }
  356. BEGIN_RING( 9 );
  357. OUT_RING( CP_PACKET0( RADEON_PP_TXFILTER_0, 5 ) );
  358. OUT_RING( tex[0].pp_txfilter );
  359. OUT_RING( tex[0].pp_txformat );
  360. OUT_RING( tex[0].pp_txoffset );
  361. OUT_RING( tex[0].pp_txcblend );
  362. OUT_RING( tex[0].pp_txablend );
  363. OUT_RING( tex[0].pp_tfactor );
  364. OUT_RING( CP_PACKET0( RADEON_PP_BORDER_COLOR_0, 0 ) );
  365. OUT_RING( tex[0].pp_border_color );
  366. ADVANCE_RING();
  367. }
  368. if ( dirty & RADEON_UPLOAD_TEX1 ) {
  369. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  370. &tex[1].pp_txoffset ) ) {
  371. DRM_ERROR( "Invalid texture offset for unit 1\n" );
  372. return DRM_ERR( EINVAL );
  373. }
  374. BEGIN_RING( 9 );
  375. OUT_RING( CP_PACKET0( RADEON_PP_TXFILTER_1, 5 ) );
  376. OUT_RING( tex[1].pp_txfilter );
  377. OUT_RING( tex[1].pp_txformat );
  378. OUT_RING( tex[1].pp_txoffset );
  379. OUT_RING( tex[1].pp_txcblend );
  380. OUT_RING( tex[1].pp_txablend );
  381. OUT_RING( tex[1].pp_tfactor );
  382. OUT_RING( CP_PACKET0( RADEON_PP_BORDER_COLOR_1, 0 ) );
  383. OUT_RING( tex[1].pp_border_color );
  384. ADVANCE_RING();
  385. }
  386. if ( dirty & RADEON_UPLOAD_TEX2 ) {
  387. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv,
  388. &tex[2].pp_txoffset ) ) {
  389. DRM_ERROR( "Invalid texture offset for unit 2\n" );
  390. return DRM_ERR( EINVAL );
  391. }
  392. BEGIN_RING( 9 );
  393. OUT_RING( CP_PACKET0( RADEON_PP_TXFILTER_2, 5 ) );
  394. OUT_RING( tex[2].pp_txfilter );
  395. OUT_RING( tex[2].pp_txformat );
  396. OUT_RING( tex[2].pp_txoffset );
  397. OUT_RING( tex[2].pp_txcblend );
  398. OUT_RING( tex[2].pp_txablend );
  399. OUT_RING( tex[2].pp_tfactor );
  400. OUT_RING( CP_PACKET0( RADEON_PP_BORDER_COLOR_2, 0 ) );
  401. OUT_RING( tex[2].pp_border_color );
  402. ADVANCE_RING();
  403. }
  404. return 0;
  405. }
  406. /* Emit 1.2 state
  407. */
  408. static int radeon_emit_state2( drm_radeon_private_t *dev_priv,
  409. drm_file_t *filp_priv,
  410. drm_radeon_state_t *state )
  411. {
  412. RING_LOCALS;
  413. if (state->dirty & RADEON_UPLOAD_ZBIAS) {
  414. BEGIN_RING( 3 );
  415. OUT_RING( CP_PACKET0( RADEON_SE_ZBIAS_FACTOR, 1 ) );
  416. OUT_RING( state->context2.se_zbias_factor );
  417. OUT_RING( state->context2.se_zbias_constant );
  418. ADVANCE_RING();
  419. }
  420. return radeon_emit_state( dev_priv, filp_priv, &state->context,
  421. state->tex, state->dirty );
  422. }
  423. /* New (1.3) state mechanism. 3 commands (packet, scalar, vector) in
  424. * 1.3 cmdbuffers allow all previous state to be updated as well as
  425. * the tcl scalar and vector areas.
  426. */
  427. static struct {
  428. int start;
  429. int len;
  430. const char *name;
  431. } packet[RADEON_MAX_STATE_PACKETS] = {
  432. { RADEON_PP_MISC,7,"RADEON_PP_MISC" },
  433. { RADEON_PP_CNTL,3,"RADEON_PP_CNTL" },
  434. { RADEON_RB3D_COLORPITCH,1,"RADEON_RB3D_COLORPITCH" },
  435. { RADEON_RE_LINE_PATTERN,2,"RADEON_RE_LINE_PATTERN" },
  436. { RADEON_SE_LINE_WIDTH,1,"RADEON_SE_LINE_WIDTH" },
  437. { RADEON_PP_LUM_MATRIX,1,"RADEON_PP_LUM_MATRIX" },
  438. { RADEON_PP_ROT_MATRIX_0,2,"RADEON_PP_ROT_MATRIX_0" },
  439. { RADEON_RB3D_STENCILREFMASK,3,"RADEON_RB3D_STENCILREFMASK" },
  440. { RADEON_SE_VPORT_XSCALE,6,"RADEON_SE_VPORT_XSCALE" },
  441. { RADEON_SE_CNTL,2,"RADEON_SE_CNTL" },
  442. { RADEON_SE_CNTL_STATUS,1,"RADEON_SE_CNTL_STATUS" },
  443. { RADEON_RE_MISC,1,"RADEON_RE_MISC" },
  444. { RADEON_PP_TXFILTER_0,6,"RADEON_PP_TXFILTER_0" },
  445. { RADEON_PP_BORDER_COLOR_0,1,"RADEON_PP_BORDER_COLOR_0" },
  446. { RADEON_PP_TXFILTER_1,6,"RADEON_PP_TXFILTER_1" },
  447. { RADEON_PP_BORDER_COLOR_1,1,"RADEON_PP_BORDER_COLOR_1" },
  448. { RADEON_PP_TXFILTER_2,6,"RADEON_PP_TXFILTER_2" },
  449. { RADEON_PP_BORDER_COLOR_2,1,"RADEON_PP_BORDER_COLOR_2" },
  450. { RADEON_SE_ZBIAS_FACTOR,2,"RADEON_SE_ZBIAS_FACTOR" },
  451. { RADEON_SE_TCL_OUTPUT_VTX_FMT,11,"RADEON_SE_TCL_OUTPUT_VTX_FMT" },
  452. { RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED,17,"RADEON_SE_TCL_MATERIAL_EMMISSIVE_RED" },
  453. { R200_PP_TXCBLEND_0, 4, "R200_PP_TXCBLEND_0" },
  454. { R200_PP_TXCBLEND_1, 4, "R200_PP_TXCBLEND_1" },
  455. { R200_PP_TXCBLEND_2, 4, "R200_PP_TXCBLEND_2" },
  456. { R200_PP_TXCBLEND_3, 4, "R200_PP_TXCBLEND_3" },
  457. { R200_PP_TXCBLEND_4, 4, "R200_PP_TXCBLEND_4" },
  458. { R200_PP_TXCBLEND_5, 4, "R200_PP_TXCBLEND_5" },
  459. { R200_PP_TXCBLEND_6, 4, "R200_PP_TXCBLEND_6" },
  460. { R200_PP_TXCBLEND_7, 4, "R200_PP_TXCBLEND_7" },
  461. { R200_SE_TCL_LIGHT_MODEL_CTL_0, 6, "R200_SE_TCL_LIGHT_MODEL_CTL_0" },
  462. { R200_PP_TFACTOR_0, 6, "R200_PP_TFACTOR_0" },
  463. { R200_SE_VTX_FMT_0, 4, "R200_SE_VTX_FMT_0" },
  464. { R200_SE_VAP_CNTL, 1, "R200_SE_VAP_CNTL" },
  465. { R200_SE_TCL_MATRIX_SEL_0, 5, "R200_SE_TCL_MATRIX_SEL_0" },
  466. { R200_SE_TCL_TEX_PROC_CTL_2, 5, "R200_SE_TCL_TEX_PROC_CTL_2" },
  467. { R200_SE_TCL_UCP_VERT_BLEND_CTL, 1, "R200_SE_TCL_UCP_VERT_BLEND_CTL" },
  468. { R200_PP_TXFILTER_0, 6, "R200_PP_TXFILTER_0" },
  469. { R200_PP_TXFILTER_1, 6, "R200_PP_TXFILTER_1" },
  470. { R200_PP_TXFILTER_2, 6, "R200_PP_TXFILTER_2" },
  471. { R200_PP_TXFILTER_3, 6, "R200_PP_TXFILTER_3" },
  472. { R200_PP_TXFILTER_4, 6, "R200_PP_TXFILTER_4" },
  473. { R200_PP_TXFILTER_5, 6, "R200_PP_TXFILTER_5" },
  474. { R200_PP_TXOFFSET_0, 1, "R200_PP_TXOFFSET_0" },
  475. { R200_PP_TXOFFSET_1, 1, "R200_PP_TXOFFSET_1" },
  476. { R200_PP_TXOFFSET_2, 1, "R200_PP_TXOFFSET_2" },
  477. { R200_PP_TXOFFSET_3, 1, "R200_PP_TXOFFSET_3" },
  478. { R200_PP_TXOFFSET_4, 1, "R200_PP_TXOFFSET_4" },
  479. { R200_PP_TXOFFSET_5, 1, "R200_PP_TXOFFSET_5" },
  480. { R200_SE_VTE_CNTL, 1, "R200_SE_VTE_CNTL" },
  481. { R200_SE_TCL_OUTPUT_VTX_COMP_SEL, 1, "R200_SE_TCL_OUTPUT_VTX_COMP_SEL" },
  482. { R200_PP_TAM_DEBUG3, 1, "R200_PP_TAM_DEBUG3" },
  483. { R200_PP_CNTL_X, 1, "R200_PP_CNTL_X" },
  484. { R200_RB3D_DEPTHXY_OFFSET, 1, "R200_RB3D_DEPTHXY_OFFSET" },
  485. { R200_RE_AUX_SCISSOR_CNTL, 1, "R200_RE_AUX_SCISSOR_CNTL" },
  486. { R200_RE_SCISSOR_TL_0, 2, "R200_RE_SCISSOR_TL_0" },
  487. { R200_RE_SCISSOR_TL_1, 2, "R200_RE_SCISSOR_TL_1" },
  488. { R200_RE_SCISSOR_TL_2, 2, "R200_RE_SCISSOR_TL_2" },
  489. { R200_SE_VAP_CNTL_STATUS, 1, "R200_SE_VAP_CNTL_STATUS" },
  490. { R200_SE_VTX_STATE_CNTL, 1, "R200_SE_VTX_STATE_CNTL" },
  491. { R200_RE_POINTSIZE, 1, "R200_RE_POINTSIZE" },
  492. { R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0, 4, "R200_SE_TCL_INPUT_VTX_VECTOR_ADDR_0" },
  493. { R200_PP_CUBIC_FACES_0, 1, "R200_PP_CUBIC_FACES_0" }, /* 61 */
  494. { R200_PP_CUBIC_OFFSET_F1_0, 5, "R200_PP_CUBIC_OFFSET_F1_0" }, /* 62 */
  495. { R200_PP_CUBIC_FACES_1, 1, "R200_PP_CUBIC_FACES_1" },
  496. { R200_PP_CUBIC_OFFSET_F1_1, 5, "R200_PP_CUBIC_OFFSET_F1_1" },
  497. { R200_PP_CUBIC_FACES_2, 1, "R200_PP_CUBIC_FACES_2" },
  498. { R200_PP_CUBIC_OFFSET_F1_2, 5, "R200_PP_CUBIC_OFFSET_F1_2" },
  499. { R200_PP_CUBIC_FACES_3, 1, "R200_PP_CUBIC_FACES_3" },
  500. { R200_PP_CUBIC_OFFSET_F1_3, 5, "R200_PP_CUBIC_OFFSET_F1_3" },
  501. { R200_PP_CUBIC_FACES_4, 1, "R200_PP_CUBIC_FACES_4" },
  502. { R200_PP_CUBIC_OFFSET_F1_4, 5, "R200_PP_CUBIC_OFFSET_F1_4" },
  503. { R200_PP_CUBIC_FACES_5, 1, "R200_PP_CUBIC_FACES_5" },
  504. { R200_PP_CUBIC_OFFSET_F1_5, 5, "R200_PP_CUBIC_OFFSET_F1_5" },
  505. { RADEON_PP_TEX_SIZE_0, 2, "RADEON_PP_TEX_SIZE_0" },
  506. { RADEON_PP_TEX_SIZE_1, 2, "RADEON_PP_TEX_SIZE_1" },
  507. { RADEON_PP_TEX_SIZE_2, 2, "RADEON_PP_TEX_SIZE_2" },
  508. { R200_RB3D_BLENDCOLOR, 3, "R200_RB3D_BLENDCOLOR" },
  509. { R200_SE_TCL_POINT_SPRITE_CNTL, 1, "R200_SE_TCL_POINT_SPRITE_CNTL" },
  510. { RADEON_PP_CUBIC_FACES_0, 1, "RADEON_PP_CUBIC_FACES_0"},
  511. { RADEON_PP_CUBIC_OFFSET_T0_0, 5, "RADEON_PP_CUBIC_OFFSET_T0_0"},
  512. { RADEON_PP_CUBIC_FACES_1, 1, "RADEON_PP_CUBIC_FACES_1"},
  513. { RADEON_PP_CUBIC_OFFSET_T1_0, 5, "RADEON_PP_CUBIC_OFFSET_T1_0"},
  514. { RADEON_PP_CUBIC_FACES_2, 1, "RADEON_PP_CUBIC_FACES_2"},
  515. { RADEON_PP_CUBIC_OFFSET_T2_0, 5, "RADEON_PP_CUBIC_OFFSET_T2_0"},
  516. { R200_PP_TRI_PERF, 2, "R200_PP_TRI_PERF"},
  517. };
  518. /* ================================================================
  519. * Performance monitoring functions
  520. */
  521. static void radeon_clear_box( drm_radeon_private_t *dev_priv,
  522. int x, int y, int w, int h,
  523. int r, int g, int b )
  524. {
  525. u32 color;
  526. RING_LOCALS;
  527. x += dev_priv->sarea_priv->boxes[0].x1;
  528. y += dev_priv->sarea_priv->boxes[0].y1;
  529. switch ( dev_priv->color_fmt ) {
  530. case RADEON_COLOR_FORMAT_RGB565:
  531. color = (((r & 0xf8) << 8) |
  532. ((g & 0xfc) << 3) |
  533. ((b & 0xf8) >> 3));
  534. break;
  535. case RADEON_COLOR_FORMAT_ARGB8888:
  536. default:
  537. color = (((0xff) << 24) | (r << 16) | (g << 8) | b);
  538. break;
  539. }
  540. BEGIN_RING( 4 );
  541. RADEON_WAIT_UNTIL_3D_IDLE();
  542. OUT_RING( CP_PACKET0( RADEON_DP_WRITE_MASK, 0 ) );
  543. OUT_RING( 0xffffffff );
  544. ADVANCE_RING();
  545. BEGIN_RING( 6 );
  546. OUT_RING( CP_PACKET3( RADEON_CNTL_PAINT_MULTI, 4 ) );
  547. OUT_RING( RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  548. RADEON_GMC_BRUSH_SOLID_COLOR |
  549. (dev_priv->color_fmt << 8) |
  550. RADEON_GMC_SRC_DATATYPE_COLOR |
  551. RADEON_ROP3_P |
  552. RADEON_GMC_CLR_CMP_CNTL_DIS );
  553. if ( dev_priv->page_flipping && dev_priv->current_page == 1 ) {
  554. OUT_RING( dev_priv->front_pitch_offset );
  555. } else {
  556. OUT_RING( dev_priv->back_pitch_offset );
  557. }
  558. OUT_RING( color );
  559. OUT_RING( (x << 16) | y );
  560. OUT_RING( (w << 16) | h );
  561. ADVANCE_RING();
  562. }
  563. static void radeon_cp_performance_boxes( drm_radeon_private_t *dev_priv )
  564. {
  565. /* Collapse various things into a wait flag -- trying to
  566. * guess if userspase slept -- better just to have them tell us.
  567. */
  568. if (dev_priv->stats.last_frame_reads > 1 ||
  569. dev_priv->stats.last_clear_reads > dev_priv->stats.clears) {
  570. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  571. }
  572. if (dev_priv->stats.freelist_loops) {
  573. dev_priv->stats.boxes |= RADEON_BOX_WAIT_IDLE;
  574. }
  575. /* Purple box for page flipping
  576. */
  577. if ( dev_priv->stats.boxes & RADEON_BOX_FLIP )
  578. radeon_clear_box( dev_priv, 4, 4, 8, 8, 255, 0, 255 );
  579. /* Red box if we have to wait for idle at any point
  580. */
  581. if ( dev_priv->stats.boxes & RADEON_BOX_WAIT_IDLE )
  582. radeon_clear_box( dev_priv, 16, 4, 8, 8, 255, 0, 0 );
  583. /* Blue box: lost context?
  584. */
  585. /* Yellow box for texture swaps
  586. */
  587. if ( dev_priv->stats.boxes & RADEON_BOX_TEXTURE_LOAD )
  588. radeon_clear_box( dev_priv, 40, 4, 8, 8, 255, 255, 0 );
  589. /* Green box if hardware never idles (as far as we can tell)
  590. */
  591. if ( !(dev_priv->stats.boxes & RADEON_BOX_DMA_IDLE) )
  592. radeon_clear_box( dev_priv, 64, 4, 8, 8, 0, 255, 0 );
  593. /* Draw bars indicating number of buffers allocated
  594. * (not a great measure, easily confused)
  595. */
  596. if (dev_priv->stats.requested_bufs) {
  597. if (dev_priv->stats.requested_bufs > 100)
  598. dev_priv->stats.requested_bufs = 100;
  599. radeon_clear_box( dev_priv, 4, 16,
  600. dev_priv->stats.requested_bufs, 4,
  601. 196, 128, 128 );
  602. }
  603. memset( &dev_priv->stats, 0, sizeof(dev_priv->stats) );
  604. }
  605. /* ================================================================
  606. * CP command dispatch functions
  607. */
  608. static void radeon_cp_dispatch_clear( drm_device_t *dev,
  609. drm_radeon_clear_t *clear,
  610. drm_radeon_clear_rect_t *depth_boxes )
  611. {
  612. drm_radeon_private_t *dev_priv = dev->dev_private;
  613. drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
  614. drm_radeon_depth_clear_t *depth_clear = &dev_priv->depth_clear;
  615. int nbox = sarea_priv->nbox;
  616. drm_clip_rect_t *pbox = sarea_priv->boxes;
  617. unsigned int flags = clear->flags;
  618. u32 rb3d_cntl = 0, rb3d_stencilrefmask= 0;
  619. int i;
  620. RING_LOCALS;
  621. DRM_DEBUG( "flags = 0x%x\n", flags );
  622. dev_priv->stats.clears++;
  623. if ( dev_priv->page_flipping && dev_priv->current_page == 1 ) {
  624. unsigned int tmp = flags;
  625. flags &= ~(RADEON_FRONT | RADEON_BACK);
  626. if ( tmp & RADEON_FRONT ) flags |= RADEON_BACK;
  627. if ( tmp & RADEON_BACK ) flags |= RADEON_FRONT;
  628. }
  629. if ( flags & (RADEON_FRONT | RADEON_BACK) ) {
  630. BEGIN_RING( 4 );
  631. /* Ensure the 3D stream is idle before doing a
  632. * 2D fill to clear the front or back buffer.
  633. */
  634. RADEON_WAIT_UNTIL_3D_IDLE();
  635. OUT_RING( CP_PACKET0( RADEON_DP_WRITE_MASK, 0 ) );
  636. OUT_RING( clear->color_mask );
  637. ADVANCE_RING();
  638. /* Make sure we restore the 3D state next time.
  639. */
  640. dev_priv->sarea_priv->ctx_owner = 0;
  641. for ( i = 0 ; i < nbox ; i++ ) {
  642. int x = pbox[i].x1;
  643. int y = pbox[i].y1;
  644. int w = pbox[i].x2 - x;
  645. int h = pbox[i].y2 - y;
  646. DRM_DEBUG( "dispatch clear %d,%d-%d,%d flags 0x%x\n",
  647. x, y, w, h, flags );
  648. if ( flags & RADEON_FRONT ) {
  649. BEGIN_RING( 6 );
  650. OUT_RING( CP_PACKET3( RADEON_CNTL_PAINT_MULTI, 4 ) );
  651. OUT_RING( RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  652. RADEON_GMC_BRUSH_SOLID_COLOR |
  653. (dev_priv->color_fmt << 8) |
  654. RADEON_GMC_SRC_DATATYPE_COLOR |
  655. RADEON_ROP3_P |
  656. RADEON_GMC_CLR_CMP_CNTL_DIS );
  657. OUT_RING( dev_priv->front_pitch_offset );
  658. OUT_RING( clear->clear_color );
  659. OUT_RING( (x << 16) | y );
  660. OUT_RING( (w << 16) | h );
  661. ADVANCE_RING();
  662. }
  663. if ( flags & RADEON_BACK ) {
  664. BEGIN_RING( 6 );
  665. OUT_RING( CP_PACKET3( RADEON_CNTL_PAINT_MULTI, 4 ) );
  666. OUT_RING( RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  667. RADEON_GMC_BRUSH_SOLID_COLOR |
  668. (dev_priv->color_fmt << 8) |
  669. RADEON_GMC_SRC_DATATYPE_COLOR |
  670. RADEON_ROP3_P |
  671. RADEON_GMC_CLR_CMP_CNTL_DIS );
  672. OUT_RING( dev_priv->back_pitch_offset );
  673. OUT_RING( clear->clear_color );
  674. OUT_RING( (x << 16) | y );
  675. OUT_RING( (w << 16) | h );
  676. ADVANCE_RING();
  677. }
  678. }
  679. }
  680. /* hyper z clear */
  681. /* no docs available, based on reverse engeneering by Stephane Marchesin */
  682. if ((flags & (RADEON_DEPTH | RADEON_STENCIL)) && (flags & RADEON_CLEAR_FASTZ)) {
  683. int i;
  684. int depthpixperline = dev_priv->depth_fmt==RADEON_DEPTH_FORMAT_16BIT_INT_Z?
  685. (dev_priv->depth_pitch / 2): (dev_priv->depth_pitch / 4);
  686. u32 clearmask;
  687. u32 tempRB3D_DEPTHCLEARVALUE = clear->clear_depth |
  688. ((clear->depth_mask & 0xff) << 24);
  689. /* Make sure we restore the 3D state next time.
  690. * we haven't touched any "normal" state - still need this?
  691. */
  692. dev_priv->sarea_priv->ctx_owner = 0;
  693. if ((dev_priv->flags & CHIP_HAS_HIERZ) && (flags & RADEON_USE_HIERZ)) {
  694. /* FIXME : reverse engineer that for Rx00 cards */
  695. /* FIXME : the mask supposedly contains low-res z values. So can't set
  696. just to the max (0xff? or actually 0x3fff?), need to take z clear
  697. value into account? */
  698. /* pattern seems to work for r100, though get slight
  699. rendering errors with glxgears. If hierz is not enabled for r100,
  700. only 4 bits which indicate clear (15,16,31,32, all zero) matter, the
  701. other ones are ignored, and the same clear mask can be used. That's
  702. very different behaviour than R200 which needs different clear mask
  703. and different number of tiles to clear if hierz is enabled or not !?!
  704. */
  705. clearmask = (0xff<<22)|(0xff<<6)| 0x003f003f;
  706. }
  707. else {
  708. /* clear mask : chooses the clearing pattern.
  709. rv250: could be used to clear only parts of macrotiles
  710. (but that would get really complicated...)?
  711. bit 0 and 1 (either or both of them ?!?!) are used to
  712. not clear tile (or maybe one of the bits indicates if the tile is
  713. compressed or not), bit 2 and 3 to not clear tile 1,...,.
  714. Pattern is as follows:
  715. | 0,1 | 4,5 | 8,9 |12,13|16,17|20,21|24,25|28,29|
  716. bits -------------------------------------------------
  717. | 2,3 | 6,7 |10,11|14,15|18,19|22,23|26,27|30,31|
  718. rv100: clearmask covers 2x8 4x1 tiles, but one clear still
  719. covers 256 pixels ?!?
  720. */
  721. clearmask = 0x0;
  722. }
  723. BEGIN_RING( 8 );
  724. RADEON_WAIT_UNTIL_2D_IDLE();
  725. OUT_RING_REG( RADEON_RB3D_DEPTHCLEARVALUE,
  726. tempRB3D_DEPTHCLEARVALUE);
  727. /* what offset is this exactly ? */
  728. OUT_RING_REG( RADEON_RB3D_ZMASKOFFSET, 0 );
  729. /* need ctlstat, otherwise get some strange black flickering */
  730. OUT_RING_REG( RADEON_RB3D_ZCACHE_CTLSTAT, RADEON_RB3D_ZC_FLUSH_ALL );
  731. ADVANCE_RING();
  732. for (i = 0; i < nbox; i++) {
  733. int tileoffset, nrtilesx, nrtilesy, j;
  734. /* it looks like r200 needs rv-style clears, at least if hierz is not enabled? */
  735. if ((dev_priv->flags&CHIP_HAS_HIERZ) && !(dev_priv->microcode_version==UCODE_R200)) {
  736. /* FIXME : figure this out for r200 (when hierz is enabled). Or
  737. maybe r200 actually doesn't need to put the low-res z value into
  738. the tile cache like r100, but just needs to clear the hi-level z-buffer?
  739. Works for R100, both with hierz and without.
  740. R100 seems to operate on 2x1 8x8 tiles, but...
  741. odd: offset/nrtiles need to be 64 pix (4 block) aligned? Potentially
  742. problematic with resolutions which are not 64 pix aligned? */
  743. tileoffset = ((pbox[i].y1 >> 3) * depthpixperline + pbox[i].x1) >> 6;
  744. nrtilesx = ((pbox[i].x2 & ~63) - (pbox[i].x1 & ~63)) >> 4;
  745. nrtilesy = (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
  746. for (j = 0; j <= nrtilesy; j++) {
  747. BEGIN_RING( 4 );
  748. OUT_RING( CP_PACKET3( RADEON_3D_CLEAR_ZMASK, 2 ) );
  749. /* first tile */
  750. OUT_RING( tileoffset * 8 );
  751. /* the number of tiles to clear */
  752. OUT_RING( nrtilesx + 4 );
  753. /* clear mask : chooses the clearing pattern. */
  754. OUT_RING( clearmask );
  755. ADVANCE_RING();
  756. tileoffset += depthpixperline >> 6;
  757. }
  758. }
  759. else if (dev_priv->microcode_version==UCODE_R200) {
  760. /* works for rv250. */
  761. /* find first macro tile (8x2 4x4 z-pixels on rv250) */
  762. tileoffset = ((pbox[i].y1 >> 3) * depthpixperline + pbox[i].x1) >> 5;
  763. nrtilesx = (pbox[i].x2 >> 5) - (pbox[i].x1 >> 5);
  764. nrtilesy = (pbox[i].y2 >> 3) - (pbox[i].y1 >> 3);
  765. for (j = 0; j <= nrtilesy; j++) {
  766. BEGIN_RING( 4 );
  767. OUT_RING( CP_PACKET3( RADEON_3D_CLEAR_ZMASK, 2 ) );
  768. /* first tile */
  769. /* judging by the first tile offset needed, could possibly
  770. directly address/clear 4x4 tiles instead of 8x2 * 4x4
  771. macro tiles, though would still need clear mask for
  772. right/bottom if truely 4x4 granularity is desired ? */
  773. OUT_RING( tileoffset * 16 );
  774. /* the number of tiles to clear */
  775. OUT_RING( nrtilesx + 1 );
  776. /* clear mask : chooses the clearing pattern. */
  777. OUT_RING( clearmask );
  778. ADVANCE_RING();
  779. tileoffset += depthpixperline >> 5;
  780. }
  781. }
  782. else { /* rv 100 */
  783. /* rv100 might not need 64 pix alignment, who knows */
  784. /* offsets are, hmm, weird */
  785. tileoffset = ((pbox[i].y1 >> 4) * depthpixperline + pbox[i].x1) >> 6;
  786. nrtilesx = ((pbox[i].x2 & ~63) - (pbox[i].x1 & ~63)) >> 4;
  787. nrtilesy = (pbox[i].y2 >> 4) - (pbox[i].y1 >> 4);
  788. for (j = 0; j <= nrtilesy; j++) {
  789. BEGIN_RING( 4 );
  790. OUT_RING( CP_PACKET3( RADEON_3D_CLEAR_ZMASK, 2 ) );
  791. OUT_RING( tileoffset * 128 );
  792. /* the number of tiles to clear */
  793. OUT_RING( nrtilesx + 4 );
  794. /* clear mask : chooses the clearing pattern. */
  795. OUT_RING( clearmask );
  796. ADVANCE_RING();
  797. tileoffset += depthpixperline >> 6;
  798. }
  799. }
  800. }
  801. /* TODO don't always clear all hi-level z tiles */
  802. if ((dev_priv->flags & CHIP_HAS_HIERZ) && (dev_priv->microcode_version==UCODE_R200)
  803. && (flags & RADEON_USE_HIERZ))
  804. /* r100 and cards without hierarchical z-buffer have no high-level z-buffer */
  805. /* FIXME : the mask supposedly contains low-res z values. So can't set
  806. just to the max (0xff? or actually 0x3fff?), need to take z clear
  807. value into account? */
  808. {
  809. BEGIN_RING( 4 );
  810. OUT_RING( CP_PACKET3( RADEON_3D_CLEAR_HIZ, 2 ) );
  811. OUT_RING( 0x0 ); /* First tile */
  812. OUT_RING( 0x3cc0 );
  813. OUT_RING( (0xff<<22)|(0xff<<6)| 0x003f003f);
  814. ADVANCE_RING();
  815. }
  816. }
  817. /* We have to clear the depth and/or stencil buffers by
  818. * rendering a quad into just those buffers. Thus, we have to
  819. * make sure the 3D engine is configured correctly.
  820. */
  821. if ((dev_priv->microcode_version == UCODE_R200) &&
  822. (flags & (RADEON_DEPTH | RADEON_STENCIL))) {
  823. int tempPP_CNTL;
  824. int tempRE_CNTL;
  825. int tempRB3D_CNTL;
  826. int tempRB3D_ZSTENCILCNTL;
  827. int tempRB3D_STENCILREFMASK;
  828. int tempRB3D_PLANEMASK;
  829. int tempSE_CNTL;
  830. int tempSE_VTE_CNTL;
  831. int tempSE_VTX_FMT_0;
  832. int tempSE_VTX_FMT_1;
  833. int tempSE_VAP_CNTL;
  834. int tempRE_AUX_SCISSOR_CNTL;
  835. tempPP_CNTL = 0;
  836. tempRE_CNTL = 0;
  837. tempRB3D_CNTL = depth_clear->rb3d_cntl;
  838. tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
  839. tempRB3D_STENCILREFMASK = 0x0;
  840. tempSE_CNTL = depth_clear->se_cntl;
  841. /* Disable TCL */
  842. tempSE_VAP_CNTL = (/* SE_VAP_CNTL__FORCE_W_TO_ONE_MASK | */
  843. (0x9 << SE_VAP_CNTL__VF_MAX_VTX_NUM__SHIFT));
  844. tempRB3D_PLANEMASK = 0x0;
  845. tempRE_AUX_SCISSOR_CNTL = 0x0;
  846. tempSE_VTE_CNTL =
  847. SE_VTE_CNTL__VTX_XY_FMT_MASK |
  848. SE_VTE_CNTL__VTX_Z_FMT_MASK;
  849. /* Vertex format (X, Y, Z, W)*/
  850. tempSE_VTX_FMT_0 =
  851. SE_VTX_FMT_0__VTX_Z0_PRESENT_MASK |
  852. SE_VTX_FMT_0__VTX_W0_PRESENT_MASK;
  853. tempSE_VTX_FMT_1 = 0x0;
  854. /*
  855. * Depth buffer specific enables
  856. */
  857. if (flags & RADEON_DEPTH) {
  858. /* Enable depth buffer */
  859. tempRB3D_CNTL |= RADEON_Z_ENABLE;
  860. } else {
  861. /* Disable depth buffer */
  862. tempRB3D_CNTL &= ~RADEON_Z_ENABLE;
  863. }
  864. /*
  865. * Stencil buffer specific enables
  866. */
  867. if ( flags & RADEON_STENCIL ) {
  868. tempRB3D_CNTL |= RADEON_STENCIL_ENABLE;
  869. tempRB3D_STENCILREFMASK = clear->depth_mask;
  870. } else {
  871. tempRB3D_CNTL &= ~RADEON_STENCIL_ENABLE;
  872. tempRB3D_STENCILREFMASK = 0x00000000;
  873. }
  874. if (flags & RADEON_USE_COMP_ZBUF) {
  875. tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
  876. RADEON_Z_DECOMPRESSION_ENABLE;
  877. }
  878. if (flags & RADEON_USE_HIERZ) {
  879. tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
  880. }
  881. BEGIN_RING( 26 );
  882. RADEON_WAIT_UNTIL_2D_IDLE();
  883. OUT_RING_REG( RADEON_PP_CNTL, tempPP_CNTL );
  884. OUT_RING_REG( R200_RE_CNTL, tempRE_CNTL );
  885. OUT_RING_REG( RADEON_RB3D_CNTL, tempRB3D_CNTL );
  886. OUT_RING_REG( RADEON_RB3D_ZSTENCILCNTL,
  887. tempRB3D_ZSTENCILCNTL );
  888. OUT_RING_REG( RADEON_RB3D_STENCILREFMASK,
  889. tempRB3D_STENCILREFMASK );
  890. OUT_RING_REG( RADEON_RB3D_PLANEMASK, tempRB3D_PLANEMASK );
  891. OUT_RING_REG( RADEON_SE_CNTL, tempSE_CNTL );
  892. OUT_RING_REG( R200_SE_VTE_CNTL, tempSE_VTE_CNTL );
  893. OUT_RING_REG( R200_SE_VTX_FMT_0, tempSE_VTX_FMT_0 );
  894. OUT_RING_REG( R200_SE_VTX_FMT_1, tempSE_VTX_FMT_1 );
  895. OUT_RING_REG( R200_SE_VAP_CNTL, tempSE_VAP_CNTL );
  896. OUT_RING_REG( R200_RE_AUX_SCISSOR_CNTL,
  897. tempRE_AUX_SCISSOR_CNTL );
  898. ADVANCE_RING();
  899. /* Make sure we restore the 3D state next time.
  900. */
  901. dev_priv->sarea_priv->ctx_owner = 0;
  902. for ( i = 0 ; i < nbox ; i++ ) {
  903. /* Funny that this should be required --
  904. * sets top-left?
  905. */
  906. radeon_emit_clip_rect( dev_priv,
  907. &sarea_priv->boxes[i] );
  908. BEGIN_RING( 14 );
  909. OUT_RING( CP_PACKET3( R200_3D_DRAW_IMMD_2, 12 ) );
  910. OUT_RING( (RADEON_PRIM_TYPE_RECT_LIST |
  911. RADEON_PRIM_WALK_RING |
  912. (3 << RADEON_NUM_VERTICES_SHIFT)) );
  913. OUT_RING( depth_boxes[i].ui[CLEAR_X1] );
  914. OUT_RING( depth_boxes[i].ui[CLEAR_Y1] );
  915. OUT_RING( depth_boxes[i].ui[CLEAR_DEPTH] );
  916. OUT_RING( 0x3f800000 );
  917. OUT_RING( depth_boxes[i].ui[CLEAR_X1] );
  918. OUT_RING( depth_boxes[i].ui[CLEAR_Y2] );
  919. OUT_RING( depth_boxes[i].ui[CLEAR_DEPTH] );
  920. OUT_RING( 0x3f800000 );
  921. OUT_RING( depth_boxes[i].ui[CLEAR_X2] );
  922. OUT_RING( depth_boxes[i].ui[CLEAR_Y2] );
  923. OUT_RING( depth_boxes[i].ui[CLEAR_DEPTH] );
  924. OUT_RING( 0x3f800000 );
  925. ADVANCE_RING();
  926. }
  927. }
  928. else if ( (flags & (RADEON_DEPTH | RADEON_STENCIL)) ) {
  929. int tempRB3D_ZSTENCILCNTL = depth_clear->rb3d_zstencilcntl;
  930. rb3d_cntl = depth_clear->rb3d_cntl;
  931. if ( flags & RADEON_DEPTH ) {
  932. rb3d_cntl |= RADEON_Z_ENABLE;
  933. } else {
  934. rb3d_cntl &= ~RADEON_Z_ENABLE;
  935. }
  936. if ( flags & RADEON_STENCIL ) {
  937. rb3d_cntl |= RADEON_STENCIL_ENABLE;
  938. rb3d_stencilrefmask = clear->depth_mask; /* misnamed field */
  939. } else {
  940. rb3d_cntl &= ~RADEON_STENCIL_ENABLE;
  941. rb3d_stencilrefmask = 0x00000000;
  942. }
  943. if (flags & RADEON_USE_COMP_ZBUF) {
  944. tempRB3D_ZSTENCILCNTL |= RADEON_Z_COMPRESSION_ENABLE |
  945. RADEON_Z_DECOMPRESSION_ENABLE;
  946. }
  947. if (flags & RADEON_USE_HIERZ) {
  948. tempRB3D_ZSTENCILCNTL |= RADEON_Z_HIERARCHY_ENABLE;
  949. }
  950. BEGIN_RING( 13 );
  951. RADEON_WAIT_UNTIL_2D_IDLE();
  952. OUT_RING( CP_PACKET0( RADEON_PP_CNTL, 1 ) );
  953. OUT_RING( 0x00000000 );
  954. OUT_RING( rb3d_cntl );
  955. OUT_RING_REG( RADEON_RB3D_ZSTENCILCNTL, tempRB3D_ZSTENCILCNTL );
  956. OUT_RING_REG( RADEON_RB3D_STENCILREFMASK,
  957. rb3d_stencilrefmask );
  958. OUT_RING_REG( RADEON_RB3D_PLANEMASK,
  959. 0x00000000 );
  960. OUT_RING_REG( RADEON_SE_CNTL,
  961. depth_clear->se_cntl );
  962. ADVANCE_RING();
  963. /* Make sure we restore the 3D state next time.
  964. */
  965. dev_priv->sarea_priv->ctx_owner = 0;
  966. for ( i = 0 ; i < nbox ; i++ ) {
  967. /* Funny that this should be required --
  968. * sets top-left?
  969. */
  970. radeon_emit_clip_rect( dev_priv,
  971. &sarea_priv->boxes[i] );
  972. BEGIN_RING( 15 );
  973. OUT_RING( CP_PACKET3( RADEON_3D_DRAW_IMMD, 13 ) );
  974. OUT_RING( RADEON_VTX_Z_PRESENT |
  975. RADEON_VTX_PKCOLOR_PRESENT);
  976. OUT_RING( (RADEON_PRIM_TYPE_RECT_LIST |
  977. RADEON_PRIM_WALK_RING |
  978. RADEON_MAOS_ENABLE |
  979. RADEON_VTX_FMT_RADEON_MODE |
  980. (3 << RADEON_NUM_VERTICES_SHIFT)) );
  981. OUT_RING( depth_boxes[i].ui[CLEAR_X1] );
  982. OUT_RING( depth_boxes[i].ui[CLEAR_Y1] );
  983. OUT_RING( depth_boxes[i].ui[CLEAR_DEPTH] );
  984. OUT_RING( 0x0 );
  985. OUT_RING( depth_boxes[i].ui[CLEAR_X1] );
  986. OUT_RING( depth_boxes[i].ui[CLEAR_Y2] );
  987. OUT_RING( depth_boxes[i].ui[CLEAR_DEPTH] );
  988. OUT_RING( 0x0 );
  989. OUT_RING( depth_boxes[i].ui[CLEAR_X2] );
  990. OUT_RING( depth_boxes[i].ui[CLEAR_Y2] );
  991. OUT_RING( depth_boxes[i].ui[CLEAR_DEPTH] );
  992. OUT_RING( 0x0 );
  993. ADVANCE_RING();
  994. }
  995. }
  996. /* Increment the clear counter. The client-side 3D driver must
  997. * wait on this value before performing the clear ioctl. We
  998. * need this because the card's so damned fast...
  999. */
  1000. dev_priv->sarea_priv->last_clear++;
  1001. BEGIN_RING( 4 );
  1002. RADEON_CLEAR_AGE( dev_priv->sarea_priv->last_clear );
  1003. RADEON_WAIT_UNTIL_IDLE();
  1004. ADVANCE_RING();
  1005. }
  1006. static void radeon_cp_dispatch_swap( drm_device_t *dev )
  1007. {
  1008. drm_radeon_private_t *dev_priv = dev->dev_private;
  1009. drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
  1010. int nbox = sarea_priv->nbox;
  1011. drm_clip_rect_t *pbox = sarea_priv->boxes;
  1012. int i;
  1013. RING_LOCALS;
  1014. DRM_DEBUG( "\n" );
  1015. /* Do some trivial performance monitoring...
  1016. */
  1017. if (dev_priv->do_boxes)
  1018. radeon_cp_performance_boxes( dev_priv );
  1019. /* Wait for the 3D stream to idle before dispatching the bitblt.
  1020. * This will prevent data corruption between the two streams.
  1021. */
  1022. BEGIN_RING( 2 );
  1023. RADEON_WAIT_UNTIL_3D_IDLE();
  1024. ADVANCE_RING();
  1025. for ( i = 0 ; i < nbox ; i++ ) {
  1026. int x = pbox[i].x1;
  1027. int y = pbox[i].y1;
  1028. int w = pbox[i].x2 - x;
  1029. int h = pbox[i].y2 - y;
  1030. DRM_DEBUG( "dispatch swap %d,%d-%d,%d\n",
  1031. x, y, w, h );
  1032. BEGIN_RING( 7 );
  1033. OUT_RING( CP_PACKET3( RADEON_CNTL_BITBLT_MULTI, 5 ) );
  1034. OUT_RING( RADEON_GMC_SRC_PITCH_OFFSET_CNTL |
  1035. RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  1036. RADEON_GMC_BRUSH_NONE |
  1037. (dev_priv->color_fmt << 8) |
  1038. RADEON_GMC_SRC_DATATYPE_COLOR |
  1039. RADEON_ROP3_S |
  1040. RADEON_DP_SRC_SOURCE_MEMORY |
  1041. RADEON_GMC_CLR_CMP_CNTL_DIS |
  1042. RADEON_GMC_WR_MSK_DIS );
  1043. /* Make this work even if front & back are flipped:
  1044. */
  1045. if (dev_priv->current_page == 0) {
  1046. OUT_RING( dev_priv->back_pitch_offset );
  1047. OUT_RING( dev_priv->front_pitch_offset );
  1048. }
  1049. else {
  1050. OUT_RING( dev_priv->front_pitch_offset );
  1051. OUT_RING( dev_priv->back_pitch_offset );
  1052. }
  1053. OUT_RING( (x << 16) | y );
  1054. OUT_RING( (x << 16) | y );
  1055. OUT_RING( (w << 16) | h );
  1056. ADVANCE_RING();
  1057. }
  1058. /* Increment the frame counter. The client-side 3D driver must
  1059. * throttle the framerate by waiting for this value before
  1060. * performing the swapbuffer ioctl.
  1061. */
  1062. dev_priv->sarea_priv->last_frame++;
  1063. BEGIN_RING( 4 );
  1064. RADEON_FRAME_AGE( dev_priv->sarea_priv->last_frame );
  1065. RADEON_WAIT_UNTIL_2D_IDLE();
  1066. ADVANCE_RING();
  1067. }
  1068. static void radeon_cp_dispatch_flip( drm_device_t *dev )
  1069. {
  1070. drm_radeon_private_t *dev_priv = dev->dev_private;
  1071. drm_sarea_t *sarea = (drm_sarea_t *)dev_priv->sarea->handle;
  1072. int offset = (dev_priv->current_page == 1)
  1073. ? dev_priv->front_offset : dev_priv->back_offset;
  1074. RING_LOCALS;
  1075. DRM_DEBUG( "%s: page=%d pfCurrentPage=%d\n",
  1076. __FUNCTION__,
  1077. dev_priv->current_page,
  1078. dev_priv->sarea_priv->pfCurrentPage);
  1079. /* Do some trivial performance monitoring...
  1080. */
  1081. if (dev_priv->do_boxes) {
  1082. dev_priv->stats.boxes |= RADEON_BOX_FLIP;
  1083. radeon_cp_performance_boxes( dev_priv );
  1084. }
  1085. /* Update the frame offsets for both CRTCs
  1086. */
  1087. BEGIN_RING( 6 );
  1088. RADEON_WAIT_UNTIL_3D_IDLE();
  1089. OUT_RING_REG( RADEON_CRTC_OFFSET, ( ( sarea->frame.y * dev_priv->front_pitch
  1090. + sarea->frame.x
  1091. * ( dev_priv->color_fmt - 2 ) ) & ~7 )
  1092. + offset );
  1093. OUT_RING_REG( RADEON_CRTC2_OFFSET, dev_priv->sarea_priv->crtc2_base
  1094. + offset );
  1095. ADVANCE_RING();
  1096. /* Increment the frame counter. The client-side 3D driver must
  1097. * throttle the framerate by waiting for this value before
  1098. * performing the swapbuffer ioctl.
  1099. */
  1100. dev_priv->sarea_priv->last_frame++;
  1101. dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page =
  1102. 1 - dev_priv->current_page;
  1103. BEGIN_RING( 2 );
  1104. RADEON_FRAME_AGE( dev_priv->sarea_priv->last_frame );
  1105. ADVANCE_RING();
  1106. }
  1107. static int bad_prim_vertex_nr( int primitive, int nr )
  1108. {
  1109. switch (primitive & RADEON_PRIM_TYPE_MASK) {
  1110. case RADEON_PRIM_TYPE_NONE:
  1111. case RADEON_PRIM_TYPE_POINT:
  1112. return nr < 1;
  1113. case RADEON_PRIM_TYPE_LINE:
  1114. return (nr & 1) || nr == 0;
  1115. case RADEON_PRIM_TYPE_LINE_STRIP:
  1116. return nr < 2;
  1117. case RADEON_PRIM_TYPE_TRI_LIST:
  1118. case RADEON_PRIM_TYPE_3VRT_POINT_LIST:
  1119. case RADEON_PRIM_TYPE_3VRT_LINE_LIST:
  1120. case RADEON_PRIM_TYPE_RECT_LIST:
  1121. return nr % 3 || nr == 0;
  1122. case RADEON_PRIM_TYPE_TRI_FAN:
  1123. case RADEON_PRIM_TYPE_TRI_STRIP:
  1124. return nr < 3;
  1125. default:
  1126. return 1;
  1127. }
  1128. }
  1129. typedef struct {
  1130. unsigned int start;
  1131. unsigned int finish;
  1132. unsigned int prim;
  1133. unsigned int numverts;
  1134. unsigned int offset;
  1135. unsigned int vc_format;
  1136. } drm_radeon_tcl_prim_t;
  1137. static void radeon_cp_dispatch_vertex( drm_device_t *dev,
  1138. drm_buf_t *buf,
  1139. drm_radeon_tcl_prim_t *prim )
  1140. {
  1141. drm_radeon_private_t *dev_priv = dev->dev_private;
  1142. drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
  1143. int offset = dev_priv->gart_buffers_offset + buf->offset + prim->start;
  1144. int numverts = (int)prim->numverts;
  1145. int nbox = sarea_priv->nbox;
  1146. int i = 0;
  1147. RING_LOCALS;
  1148. DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d %d verts\n",
  1149. prim->prim,
  1150. prim->vc_format,
  1151. prim->start,
  1152. prim->finish,
  1153. prim->numverts);
  1154. if (bad_prim_vertex_nr( prim->prim, prim->numverts )) {
  1155. DRM_ERROR( "bad prim %x numverts %d\n",
  1156. prim->prim, prim->numverts );
  1157. return;
  1158. }
  1159. do {
  1160. /* Emit the next cliprect */
  1161. if ( i < nbox ) {
  1162. radeon_emit_clip_rect( dev_priv,
  1163. &sarea_priv->boxes[i] );
  1164. }
  1165. /* Emit the vertex buffer rendering commands */
  1166. BEGIN_RING( 5 );
  1167. OUT_RING( CP_PACKET3( RADEON_3D_RNDR_GEN_INDX_PRIM, 3 ) );
  1168. OUT_RING( offset );
  1169. OUT_RING( numverts );
  1170. OUT_RING( prim->vc_format );
  1171. OUT_RING( prim->prim | RADEON_PRIM_WALK_LIST |
  1172. RADEON_COLOR_ORDER_RGBA |
  1173. RADEON_VTX_FMT_RADEON_MODE |
  1174. (numverts << RADEON_NUM_VERTICES_SHIFT) );
  1175. ADVANCE_RING();
  1176. i++;
  1177. } while ( i < nbox );
  1178. }
  1179. static void radeon_cp_discard_buffer( drm_device_t *dev, drm_buf_t *buf )
  1180. {
  1181. drm_radeon_private_t *dev_priv = dev->dev_private;
  1182. drm_radeon_buf_priv_t *buf_priv = buf->dev_private;
  1183. RING_LOCALS;
  1184. buf_priv->age = ++dev_priv->sarea_priv->last_dispatch;
  1185. /* Emit the vertex buffer age */
  1186. BEGIN_RING( 2 );
  1187. RADEON_DISPATCH_AGE( buf_priv->age );
  1188. ADVANCE_RING();
  1189. buf->pending = 1;
  1190. buf->used = 0;
  1191. }
  1192. static void radeon_cp_dispatch_indirect( drm_device_t *dev,
  1193. drm_buf_t *buf,
  1194. int start, int end )
  1195. {
  1196. drm_radeon_private_t *dev_priv = dev->dev_private;
  1197. RING_LOCALS;
  1198. DRM_DEBUG( "indirect: buf=%d s=0x%x e=0x%x\n",
  1199. buf->idx, start, end );
  1200. if ( start != end ) {
  1201. int offset = (dev_priv->gart_buffers_offset
  1202. + buf->offset + start);
  1203. int dwords = (end - start + 3) / sizeof(u32);
  1204. /* Indirect buffer data must be an even number of
  1205. * dwords, so if we've been given an odd number we must
  1206. * pad the data with a Type-2 CP packet.
  1207. */
  1208. if ( dwords & 1 ) {
  1209. u32 *data = (u32 *)
  1210. ((char *)dev->agp_buffer_map->handle
  1211. + buf->offset + start);
  1212. data[dwords++] = RADEON_CP_PACKET2;
  1213. }
  1214. /* Fire off the indirect buffer */
  1215. BEGIN_RING( 3 );
  1216. OUT_RING( CP_PACKET0( RADEON_CP_IB_BASE, 1 ) );
  1217. OUT_RING( offset );
  1218. OUT_RING( dwords );
  1219. ADVANCE_RING();
  1220. }
  1221. }
  1222. static void radeon_cp_dispatch_indices( drm_device_t *dev,
  1223. drm_buf_t *elt_buf,
  1224. drm_radeon_tcl_prim_t *prim )
  1225. {
  1226. drm_radeon_private_t *dev_priv = dev->dev_private;
  1227. drm_radeon_sarea_t *sarea_priv = dev_priv->sarea_priv;
  1228. int offset = dev_priv->gart_buffers_offset + prim->offset;
  1229. u32 *data;
  1230. int dwords;
  1231. int i = 0;
  1232. int start = prim->start + RADEON_INDEX_PRIM_OFFSET;
  1233. int count = (prim->finish - start) / sizeof(u16);
  1234. int nbox = sarea_priv->nbox;
  1235. DRM_DEBUG("hwprim 0x%x vfmt 0x%x %d..%d offset: %x nr %d\n",
  1236. prim->prim,
  1237. prim->vc_format,
  1238. prim->start,
  1239. prim->finish,
  1240. prim->offset,
  1241. prim->numverts);
  1242. if (bad_prim_vertex_nr( prim->prim, count )) {
  1243. DRM_ERROR( "bad prim %x count %d\n",
  1244. prim->prim, count );
  1245. return;
  1246. }
  1247. if ( start >= prim->finish ||
  1248. (prim->start & 0x7) ) {
  1249. DRM_ERROR( "buffer prim %d\n", prim->prim );
  1250. return;
  1251. }
  1252. dwords = (prim->finish - prim->start + 3) / sizeof(u32);
  1253. data = (u32 *)((char *)dev->agp_buffer_map->handle +
  1254. elt_buf->offset + prim->start);
  1255. data[0] = CP_PACKET3( RADEON_3D_RNDR_GEN_INDX_PRIM, dwords-2 );
  1256. data[1] = offset;
  1257. data[2] = prim->numverts;
  1258. data[3] = prim->vc_format;
  1259. data[4] = (prim->prim |
  1260. RADEON_PRIM_WALK_IND |
  1261. RADEON_COLOR_ORDER_RGBA |
  1262. RADEON_VTX_FMT_RADEON_MODE |
  1263. (count << RADEON_NUM_VERTICES_SHIFT) );
  1264. do {
  1265. if ( i < nbox )
  1266. radeon_emit_clip_rect( dev_priv,
  1267. &sarea_priv->boxes[i] );
  1268. radeon_cp_dispatch_indirect( dev, elt_buf,
  1269. prim->start,
  1270. prim->finish );
  1271. i++;
  1272. } while ( i < nbox );
  1273. }
  1274. #define RADEON_MAX_TEXTURE_SIZE (RADEON_BUFFER_SIZE - 8 * sizeof(u32))
  1275. static int radeon_cp_dispatch_texture( DRMFILE filp,
  1276. drm_device_t *dev,
  1277. drm_radeon_texture_t *tex,
  1278. drm_radeon_tex_image_t *image )
  1279. {
  1280. drm_radeon_private_t *dev_priv = dev->dev_private;
  1281. drm_file_t *filp_priv;
  1282. drm_buf_t *buf;
  1283. u32 format;
  1284. u32 *buffer;
  1285. const u8 __user *data;
  1286. int size, dwords, tex_width, blit_width;
  1287. u32 height;
  1288. int i;
  1289. u32 texpitch, microtile;
  1290. RING_LOCALS;
  1291. DRM_GET_PRIV_WITH_RETURN( filp_priv, filp );
  1292. if ( radeon_check_and_fixup_offset( dev_priv, filp_priv, &tex->offset ) ) {
  1293. DRM_ERROR( "Invalid destination offset\n" );
  1294. return DRM_ERR( EINVAL );
  1295. }
  1296. dev_priv->stats.boxes |= RADEON_BOX_TEXTURE_LOAD;
  1297. /* Flush the pixel cache. This ensures no pixel data gets mixed
  1298. * up with the texture data from the host data blit, otherwise
  1299. * part of the texture image may be corrupted.
  1300. */
  1301. BEGIN_RING( 4 );
  1302. RADEON_FLUSH_CACHE();
  1303. RADEON_WAIT_UNTIL_IDLE();
  1304. ADVANCE_RING();
  1305. #ifdef __BIG_ENDIAN
  1306. /* The Mesa texture functions provide the data in little endian as the
  1307. * chip wants it, but we need to compensate for the fact that the CP
  1308. * ring gets byte-swapped
  1309. */
  1310. BEGIN_RING( 2 );
  1311. OUT_RING_REG( RADEON_RBBM_GUICNTL, RADEON_HOST_DATA_SWAP_32BIT );
  1312. ADVANCE_RING();
  1313. #endif
  1314. /* The compiler won't optimize away a division by a variable,
  1315. * even if the only legal values are powers of two. Thus, we'll
  1316. * use a shift instead.
  1317. */
  1318. switch ( tex->format ) {
  1319. case RADEON_TXFORMAT_ARGB8888:
  1320. case RADEON_TXFORMAT_RGBA8888:
  1321. format = RADEON_COLOR_FORMAT_ARGB8888;
  1322. tex_width = tex->width * 4;
  1323. blit_width = image->width * 4;
  1324. break;
  1325. case RADEON_TXFORMAT_AI88:
  1326. case RADEON_TXFORMAT_ARGB1555:
  1327. case RADEON_TXFORMAT_RGB565:
  1328. case RADEON_TXFORMAT_ARGB4444:
  1329. case RADEON_TXFORMAT_VYUY422:
  1330. case RADEON_TXFORMAT_YVYU422:
  1331. format = RADEON_COLOR_FORMAT_RGB565;
  1332. tex_width = tex->width * 2;
  1333. blit_width = image->width * 2;
  1334. break;
  1335. case RADEON_TXFORMAT_I8:
  1336. case RADEON_TXFORMAT_RGB332:
  1337. format = RADEON_COLOR_FORMAT_CI8;
  1338. tex_width = tex->width * 1;
  1339. blit_width = image->width * 1;
  1340. break;
  1341. default:
  1342. DRM_ERROR( "invalid texture format %d\n", tex->format );
  1343. return DRM_ERR(EINVAL);
  1344. }
  1345. texpitch = tex->pitch;
  1346. if ((texpitch << 22) & RADEON_DST_TILE_MICRO) {
  1347. microtile = 1;
  1348. if (tex_width < 64) {
  1349. texpitch &= ~(RADEON_DST_TILE_MICRO >> 22);
  1350. /* we got tiled coordinates, untile them */
  1351. image->x *= 2;
  1352. }
  1353. }
  1354. else microtile = 0;
  1355. DRM_DEBUG("tex=%dx%d blit=%d\n", tex_width, tex->height, blit_width );
  1356. do {
  1357. DRM_DEBUG( "tex: ofs=0x%x p=%d f=%d x=%hd y=%hd w=%hd h=%hd\n",
  1358. tex->offset >> 10, tex->pitch, tex->format,
  1359. image->x, image->y, image->width, image->height );
  1360. /* Make a copy of some parameters in case we have to
  1361. * update them for a multi-pass texture blit.
  1362. */
  1363. height = image->height;
  1364. data = (const u8 __user *)image->data;
  1365. size = height * blit_width;
  1366. if ( size > RADEON_MAX_TEXTURE_SIZE ) {
  1367. height = RADEON_MAX_TEXTURE_SIZE / blit_width;
  1368. size = height * blit_width;
  1369. } else if ( size < 4 && size > 0 ) {
  1370. size = 4;
  1371. } else if ( size == 0 ) {
  1372. return 0;
  1373. }
  1374. buf = radeon_freelist_get( dev );
  1375. if ( 0 && !buf ) {
  1376. radeon_do_cp_idle( dev_priv );
  1377. buf = radeon_freelist_get( dev );
  1378. }
  1379. if ( !buf ) {
  1380. DRM_DEBUG("radeon_cp_dispatch_texture: EAGAIN\n");
  1381. if (DRM_COPY_TO_USER( tex->image, image, sizeof(*image) ))
  1382. return DRM_ERR(EFAULT);
  1383. return DRM_ERR(EAGAIN);
  1384. }
  1385. /* Dispatch the indirect buffer.
  1386. */
  1387. buffer = (u32*)((char*)dev->agp_buffer_map->handle + buf->offset);
  1388. dwords = size / 4;
  1389. buffer[0] = CP_PACKET3( RADEON_CNTL_HOSTDATA_BLT, dwords + 6 );
  1390. buffer[1] = (RADEON_GMC_DST_PITCH_OFFSET_CNTL |
  1391. RADEON_GMC_BRUSH_NONE |
  1392. (format << 8) |
  1393. RADEON_GMC_SRC_DATATYPE_COLOR |
  1394. RADEON_ROP3_S |
  1395. RADEON_DP_SRC_SOURCE_HOST_DATA |
  1396. RADEON_GMC_CLR_CMP_CNTL_DIS |
  1397. RADEON_GMC_WR_MSK_DIS);
  1398. buffer[2] = (texpitch << 22) | (tex->offset >> 10);
  1399. buffer[3] = 0xffffffff;
  1400. buffer[4] = 0xffffffff;
  1401. buffer[5] = (image->y << 16) | image->x;
  1402. buffer[6] = (height << 16) | image->width;
  1403. buffer[7] = dwords;
  1404. buffer += 8;
  1405. if (microtile) {
  1406. /* texture micro tiling in use, minimum texture width is thus 16 bytes.
  1407. however, we cannot use blitter directly for texture width < 64 bytes,
  1408. since minimum tex pitch is 64 bytes and we need this to match
  1409. the texture width, otherwise the blitter will tile it wrong.
  1410. Thus, tiling manually in this case. Additionally, need to special
  1411. case tex height = 1, since our actual image will have height 2
  1412. and we need to ensure we don't read beyond the texture siz…