Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* r128_state.c -- State support for r128 -*- linux-c -*- |
| 2 | * Created: Thu Jan 27 02:53:43 2000 by gareth@valinux.com |
| 3 | * |
| 4 | * Copyright 2000 VA Linux Systems, Inc., Sunnyvale, California. |
| 5 | * All Rights Reserved. |
| 6 | * |
| 7 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 8 | * copy of this software and associated documentation files (the "Software"), |
| 9 | * to deal in the Software without restriction, including without limitation |
| 10 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 11 | * and/or sell copies of the Software, and to permit persons to whom the |
| 12 | * Software is furnished to do so, subject to the following conditions: |
| 13 | * |
| 14 | * The above copyright notice and this permission notice (including the next |
| 15 | * paragraph) shall be included in all copies or substantial portions of the |
| 16 | * Software. |
| 17 | * |
| 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 20 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 21 | * PRECISION INSIGHT AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 22 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 23 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
| 24 | * DEALINGS IN THE SOFTWARE. |
| 25 | * |
| 26 | * Authors: |
| 27 | * Gareth Hughes <gareth@valinux.com> |
| 28 | */ |
| 29 | |
| 30 | #include "drmP.h" |
| 31 | #include "drm.h" |
| 32 | #include "r128_drm.h" |
| 33 | #include "r128_drv.h" |
| 34 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 35 | /* ================================================================ |
| 36 | * CCE hardware state programming functions |
| 37 | */ |
| 38 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 39 | static void r128_emit_clip_rects(drm_r128_private_t * dev_priv, |
| 40 | drm_clip_rect_t * boxes, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | { |
| 42 | u32 aux_sc_cntl = 0x00000000; |
| 43 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 44 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 45 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 46 | BEGIN_RING((count < 3 ? count : 3) * 5 + 2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 48 | if (count >= 1) { |
| 49 | OUT_RING(CCE_PACKET0(R128_AUX1_SC_LEFT, 3)); |
| 50 | OUT_RING(boxes[0].x1); |
| 51 | OUT_RING(boxes[0].x2 - 1); |
| 52 | OUT_RING(boxes[0].y1); |
| 53 | OUT_RING(boxes[0].y2 - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | |
| 55 | aux_sc_cntl |= (R128_AUX1_SC_EN | R128_AUX1_SC_MODE_OR); |
| 56 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 57 | if (count >= 2) { |
| 58 | OUT_RING(CCE_PACKET0(R128_AUX2_SC_LEFT, 3)); |
| 59 | OUT_RING(boxes[1].x1); |
| 60 | OUT_RING(boxes[1].x2 - 1); |
| 61 | OUT_RING(boxes[1].y1); |
| 62 | OUT_RING(boxes[1].y2 - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 63 | |
| 64 | aux_sc_cntl |= (R128_AUX2_SC_EN | R128_AUX2_SC_MODE_OR); |
| 65 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 66 | if (count >= 3) { |
| 67 | OUT_RING(CCE_PACKET0(R128_AUX3_SC_LEFT, 3)); |
| 68 | OUT_RING(boxes[2].x1); |
| 69 | OUT_RING(boxes[2].x2 - 1); |
| 70 | OUT_RING(boxes[2].y1); |
| 71 | OUT_RING(boxes[2].y2 - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | |
| 73 | aux_sc_cntl |= (R128_AUX3_SC_EN | R128_AUX3_SC_MODE_OR); |
| 74 | } |
| 75 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 76 | OUT_RING(CCE_PACKET0(R128_AUX_SC_CNTL, 0)); |
| 77 | OUT_RING(aux_sc_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 78 | |
| 79 | ADVANCE_RING(); |
| 80 | } |
| 81 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 82 | static __inline__ void r128_emit_core(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | { |
| 84 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 85 | drm_r128_context_regs_t *ctx = &sarea_priv->context_state; |
| 86 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 87 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 89 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 90 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 91 | OUT_RING(CCE_PACKET0(R128_SCALE_3D_CNTL, 0)); |
| 92 | OUT_RING(ctx->scale_3d_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 93 | |
| 94 | ADVANCE_RING(); |
| 95 | } |
| 96 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 97 | static __inline__ void r128_emit_context(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 98 | { |
| 99 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 100 | drm_r128_context_regs_t *ctx = &sarea_priv->context_state; |
| 101 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 102 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 104 | BEGIN_RING(13); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 106 | OUT_RING(CCE_PACKET0(R128_DST_PITCH_OFFSET_C, 11)); |
| 107 | OUT_RING(ctx->dst_pitch_offset_c); |
| 108 | OUT_RING(ctx->dp_gui_master_cntl_c); |
| 109 | OUT_RING(ctx->sc_top_left_c); |
| 110 | OUT_RING(ctx->sc_bottom_right_c); |
| 111 | OUT_RING(ctx->z_offset_c); |
| 112 | OUT_RING(ctx->z_pitch_c); |
| 113 | OUT_RING(ctx->z_sten_cntl_c); |
| 114 | OUT_RING(ctx->tex_cntl_c); |
| 115 | OUT_RING(ctx->misc_3d_state_cntl_reg); |
| 116 | OUT_RING(ctx->texture_clr_cmp_clr_c); |
| 117 | OUT_RING(ctx->texture_clr_cmp_msk_c); |
| 118 | OUT_RING(ctx->fog_color_c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 119 | |
| 120 | ADVANCE_RING(); |
| 121 | } |
| 122 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 123 | static __inline__ void r128_emit_setup(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 124 | { |
| 125 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 126 | drm_r128_context_regs_t *ctx = &sarea_priv->context_state; |
| 127 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 128 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 130 | BEGIN_RING(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 132 | OUT_RING(CCE_PACKET1(R128_SETUP_CNTL, R128_PM4_VC_FPU_SETUP)); |
| 133 | OUT_RING(ctx->setup_cntl); |
| 134 | OUT_RING(ctx->pm4_vc_fpu_setup); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 135 | |
| 136 | ADVANCE_RING(); |
| 137 | } |
| 138 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 139 | static __inline__ void r128_emit_masks(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 140 | { |
| 141 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 142 | drm_r128_context_regs_t *ctx = &sarea_priv->context_state; |
| 143 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 144 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 145 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 146 | BEGIN_RING(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 147 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 148 | OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0)); |
| 149 | OUT_RING(ctx->dp_write_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 150 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 151 | OUT_RING(CCE_PACKET0(R128_STEN_REF_MASK_C, 1)); |
| 152 | OUT_RING(ctx->sten_ref_mask_c); |
| 153 | OUT_RING(ctx->plane_3d_mask_c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
| 155 | ADVANCE_RING(); |
| 156 | } |
| 157 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 158 | static __inline__ void r128_emit_window(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | { |
| 160 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 161 | drm_r128_context_regs_t *ctx = &sarea_priv->context_state; |
| 162 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 163 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 164 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 165 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 166 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 167 | OUT_RING(CCE_PACKET0(R128_WINDOW_XY_OFFSET, 0)); |
| 168 | OUT_RING(ctx->window_xy_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 169 | |
| 170 | ADVANCE_RING(); |
| 171 | } |
| 172 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 173 | static __inline__ void r128_emit_tex0(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 174 | { |
| 175 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 176 | drm_r128_context_regs_t *ctx = &sarea_priv->context_state; |
| 177 | drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[0]; |
| 178 | int i; |
| 179 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 180 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 181 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 182 | BEGIN_RING(7 + R128_MAX_TEXTURE_LEVELS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 184 | OUT_RING(CCE_PACKET0(R128_PRIM_TEX_CNTL_C, |
| 185 | 2 + R128_MAX_TEXTURE_LEVELS)); |
| 186 | OUT_RING(tex->tex_cntl); |
| 187 | OUT_RING(tex->tex_combine_cntl); |
| 188 | OUT_RING(ctx->tex_size_pitch_c); |
| 189 | for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) { |
| 190 | OUT_RING(tex->tex_offset[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | } |
| 192 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 193 | OUT_RING(CCE_PACKET0(R128_CONSTANT_COLOR_C, 1)); |
| 194 | OUT_RING(ctx->constant_color_c); |
| 195 | OUT_RING(tex->tex_border_color); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | ADVANCE_RING(); |
| 198 | } |
| 199 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 200 | static __inline__ void r128_emit_tex1(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 201 | { |
| 202 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 203 | drm_r128_texture_regs_t *tex = &sarea_priv->tex_state[1]; |
| 204 | int i; |
| 205 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 206 | DRM_DEBUG(" %s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 207 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 208 | BEGIN_RING(5 + R128_MAX_TEXTURE_LEVELS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 209 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 210 | OUT_RING(CCE_PACKET0(R128_SEC_TEX_CNTL_C, 1 + R128_MAX_TEXTURE_LEVELS)); |
| 211 | OUT_RING(tex->tex_cntl); |
| 212 | OUT_RING(tex->tex_combine_cntl); |
| 213 | for (i = 0; i < R128_MAX_TEXTURE_LEVELS; i++) { |
| 214 | OUT_RING(tex->tex_offset[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | } |
| 216 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 217 | OUT_RING(CCE_PACKET0(R128_SEC_TEXTURE_BORDER_COLOR_C, 0)); |
| 218 | OUT_RING(tex->tex_border_color); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 219 | |
| 220 | ADVANCE_RING(); |
| 221 | } |
| 222 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 223 | static __inline__ void r128_emit_state(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 224 | { |
| 225 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 226 | unsigned int dirty = sarea_priv->dirty; |
| 227 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 228 | DRM_DEBUG("%s: dirty=0x%08x\n", __FUNCTION__, dirty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 229 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 230 | if (dirty & R128_UPLOAD_CORE) { |
| 231 | r128_emit_core(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 232 | sarea_priv->dirty &= ~R128_UPLOAD_CORE; |
| 233 | } |
| 234 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 235 | if (dirty & R128_UPLOAD_CONTEXT) { |
| 236 | r128_emit_context(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 237 | sarea_priv->dirty &= ~R128_UPLOAD_CONTEXT; |
| 238 | } |
| 239 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 240 | if (dirty & R128_UPLOAD_SETUP) { |
| 241 | r128_emit_setup(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 242 | sarea_priv->dirty &= ~R128_UPLOAD_SETUP; |
| 243 | } |
| 244 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 245 | if (dirty & R128_UPLOAD_MASKS) { |
| 246 | r128_emit_masks(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | sarea_priv->dirty &= ~R128_UPLOAD_MASKS; |
| 248 | } |
| 249 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 250 | if (dirty & R128_UPLOAD_WINDOW) { |
| 251 | r128_emit_window(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 252 | sarea_priv->dirty &= ~R128_UPLOAD_WINDOW; |
| 253 | } |
| 254 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 255 | if (dirty & R128_UPLOAD_TEX0) { |
| 256 | r128_emit_tex0(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 257 | sarea_priv->dirty &= ~R128_UPLOAD_TEX0; |
| 258 | } |
| 259 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 260 | if (dirty & R128_UPLOAD_TEX1) { |
| 261 | r128_emit_tex1(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 262 | sarea_priv->dirty &= ~R128_UPLOAD_TEX1; |
| 263 | } |
| 264 | |
| 265 | /* Turn off the texture cache flushing */ |
| 266 | sarea_priv->context_state.tex_cntl_c &= ~R128_TEX_CACHE_FLUSH; |
| 267 | |
| 268 | sarea_priv->dirty &= ~R128_REQUIRE_QUIESCENCE; |
| 269 | } |
| 270 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 271 | #if R128_PERFORMANCE_BOXES |
| 272 | /* ================================================================ |
| 273 | * Performance monitoring functions |
| 274 | */ |
| 275 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 276 | static void r128_clear_box(drm_r128_private_t * dev_priv, |
| 277 | int x, int y, int w, int h, int r, int g, int b) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 278 | { |
| 279 | u32 pitch, offset; |
| 280 | u32 fb_bpp, color; |
| 281 | RING_LOCALS; |
| 282 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 283 | switch (dev_priv->fb_bpp) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 284 | case 16: |
| 285 | fb_bpp = R128_GMC_DST_16BPP; |
| 286 | color = (((r & 0xf8) << 8) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 287 | ((g & 0xfc) << 3) | ((b & 0xf8) >> 3)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 288 | break; |
| 289 | case 24: |
| 290 | fb_bpp = R128_GMC_DST_24BPP; |
| 291 | color = ((r << 16) | (g << 8) | b); |
| 292 | break; |
| 293 | case 32: |
| 294 | fb_bpp = R128_GMC_DST_32BPP; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 295 | color = (((0xff) << 24) | (r << 16) | (g << 8) | b); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 296 | break; |
| 297 | default: |
| 298 | return; |
| 299 | } |
| 300 | |
| 301 | offset = dev_priv->back_offset; |
| 302 | pitch = dev_priv->back_pitch >> 3; |
| 303 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 304 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 306 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 307 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 308 | R128_GMC_BRUSH_SOLID_COLOR | |
| 309 | fb_bpp | |
| 310 | R128_GMC_SRC_DATATYPE_COLOR | |
| 311 | R128_ROP3_P | |
| 312 | R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_AUX_CLIP_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 314 | OUT_RING((pitch << 21) | (offset >> 5)); |
| 315 | OUT_RING(color); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 316 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 317 | OUT_RING((x << 16) | y); |
| 318 | OUT_RING((w << 16) | h); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | |
| 320 | ADVANCE_RING(); |
| 321 | } |
| 322 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 323 | static void r128_cce_performance_boxes(drm_r128_private_t * dev_priv) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 325 | if (atomic_read(&dev_priv->idle_count) == 0) { |
| 326 | r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 328 | atomic_set(&dev_priv->idle_count, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 329 | } |
| 330 | } |
| 331 | |
| 332 | #endif |
| 333 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | /* ================================================================ |
| 335 | * CCE command dispatch functions |
| 336 | */ |
| 337 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | static void r128_print_dirty(const char *msg, unsigned int flags) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 339 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 340 | DRM_INFO("%s: (0x%x) %s%s%s%s%s%s%s%s%s\n", |
| 341 | msg, |
| 342 | flags, |
| 343 | (flags & R128_UPLOAD_CORE) ? "core, " : "", |
| 344 | (flags & R128_UPLOAD_CONTEXT) ? "context, " : "", |
| 345 | (flags & R128_UPLOAD_SETUP) ? "setup, " : "", |
| 346 | (flags & R128_UPLOAD_TEX0) ? "tex0, " : "", |
| 347 | (flags & R128_UPLOAD_TEX1) ? "tex1, " : "", |
| 348 | (flags & R128_UPLOAD_MASKS) ? "masks, " : "", |
| 349 | (flags & R128_UPLOAD_WINDOW) ? "window, " : "", |
| 350 | (flags & R128_UPLOAD_CLIPRECTS) ? "cliprects, " : "", |
| 351 | (flags & R128_REQUIRE_QUIESCENCE) ? "quiescence, " : ""); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 352 | } |
| 353 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 354 | static void r128_cce_dispatch_clear(drm_device_t * dev, |
| 355 | drm_r128_clear_t * clear) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 356 | { |
| 357 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 358 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 359 | int nbox = sarea_priv->nbox; |
| 360 | drm_clip_rect_t *pbox = sarea_priv->boxes; |
| 361 | unsigned int flags = clear->flags; |
| 362 | int i; |
| 363 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 364 | DRM_DEBUG("%s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 365 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 366 | if (dev_priv->page_flipping && dev_priv->current_page == 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 367 | unsigned int tmp = flags; |
| 368 | |
| 369 | flags &= ~(R128_FRONT | R128_BACK); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 370 | if (tmp & R128_FRONT) |
| 371 | flags |= R128_BACK; |
| 372 | if (tmp & R128_BACK) |
| 373 | flags |= R128_FRONT; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 374 | } |
| 375 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 376 | for (i = 0; i < nbox; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | int x = pbox[i].x1; |
| 378 | int y = pbox[i].y1; |
| 379 | int w = pbox[i].x2 - x; |
| 380 | int h = pbox[i].y2 - y; |
| 381 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 382 | DRM_DEBUG("dispatch clear %d,%d-%d,%d flags 0x%x\n", |
| 383 | pbox[i].x1, pbox[i].y1, pbox[i].x2, |
| 384 | pbox[i].y2, flags); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 385 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 386 | if (flags & (R128_FRONT | R128_BACK)) { |
| 387 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 388 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 389 | OUT_RING(CCE_PACKET0(R128_DP_WRITE_MASK, 0)); |
| 390 | OUT_RING(clear->color_mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 391 | |
| 392 | ADVANCE_RING(); |
| 393 | } |
| 394 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 395 | if (flags & R128_FRONT) { |
| 396 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 397 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 398 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 399 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 400 | R128_GMC_BRUSH_SOLID_COLOR | |
| 401 | (dev_priv->color_fmt << 8) | |
| 402 | R128_GMC_SRC_DATATYPE_COLOR | |
| 403 | R128_ROP3_P | |
| 404 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 405 | R128_GMC_AUX_CLIP_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 406 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 407 | OUT_RING(dev_priv->front_pitch_offset_c); |
| 408 | OUT_RING(clear->clear_color); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 410 | OUT_RING((x << 16) | y); |
| 411 | OUT_RING((w << 16) | h); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
| 413 | ADVANCE_RING(); |
| 414 | } |
| 415 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 416 | if (flags & R128_BACK) { |
| 417 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 418 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 419 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 420 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 421 | R128_GMC_BRUSH_SOLID_COLOR | |
| 422 | (dev_priv->color_fmt << 8) | |
| 423 | R128_GMC_SRC_DATATYPE_COLOR | |
| 424 | R128_ROP3_P | |
| 425 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 426 | R128_GMC_AUX_CLIP_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 427 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 428 | OUT_RING(dev_priv->back_pitch_offset_c); |
| 429 | OUT_RING(clear->clear_color); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 430 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 431 | OUT_RING((x << 16) | y); |
| 432 | OUT_RING((w << 16) | h); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | |
| 434 | ADVANCE_RING(); |
| 435 | } |
| 436 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 437 | if (flags & R128_DEPTH) { |
| 438 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 439 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 440 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 441 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 442 | R128_GMC_BRUSH_SOLID_COLOR | |
| 443 | (dev_priv->depth_fmt << 8) | |
| 444 | R128_GMC_SRC_DATATYPE_COLOR | |
| 445 | R128_ROP3_P | |
| 446 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 447 | R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 448 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 449 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 450 | OUT_RING(clear->clear_depth); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 451 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 452 | OUT_RING((x << 16) | y); |
| 453 | OUT_RING((w << 16) | h); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 454 | |
| 455 | ADVANCE_RING(); |
| 456 | } |
| 457 | } |
| 458 | } |
| 459 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 460 | static void r128_cce_dispatch_swap(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | { |
| 462 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 463 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 464 | int nbox = sarea_priv->nbox; |
| 465 | drm_clip_rect_t *pbox = sarea_priv->boxes; |
| 466 | int i; |
| 467 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 468 | DRM_DEBUG("%s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | |
| 470 | #if R128_PERFORMANCE_BOXES |
| 471 | /* Do some trivial performance monitoring... |
| 472 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 473 | r128_cce_performance_boxes(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 474 | #endif |
| 475 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 476 | for (i = 0; i < nbox; i++) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 477 | int x = pbox[i].x1; |
| 478 | int y = pbox[i].y1; |
| 479 | int w = pbox[i].x2 - x; |
| 480 | int h = pbox[i].y2 - y; |
| 481 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 482 | BEGIN_RING(7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 484 | OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5)); |
| 485 | OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL | |
| 486 | R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 487 | R128_GMC_BRUSH_NONE | |
| 488 | (dev_priv->color_fmt << 8) | |
| 489 | R128_GMC_SRC_DATATYPE_COLOR | |
| 490 | R128_ROP3_S | |
| 491 | R128_DP_SRC_SOURCE_MEMORY | |
| 492 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 493 | R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 494 | |
| 495 | /* Make this work even if front & back are flipped: |
| 496 | */ |
| 497 | if (dev_priv->current_page == 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 498 | OUT_RING(dev_priv->back_pitch_offset_c); |
| 499 | OUT_RING(dev_priv->front_pitch_offset_c); |
| 500 | } else { |
| 501 | OUT_RING(dev_priv->front_pitch_offset_c); |
| 502 | OUT_RING(dev_priv->back_pitch_offset_c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 503 | } |
| 504 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 505 | OUT_RING((x << 16) | y); |
| 506 | OUT_RING((x << 16) | y); |
| 507 | OUT_RING((w << 16) | h); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 508 | |
| 509 | ADVANCE_RING(); |
| 510 | } |
| 511 | |
| 512 | /* Increment the frame counter. The client-side 3D driver must |
| 513 | * throttle the framerate by waiting for this value before |
| 514 | * performing the swapbuffer ioctl. |
| 515 | */ |
| 516 | dev_priv->sarea_priv->last_frame++; |
| 517 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 518 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 519 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 520 | OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0)); |
| 521 | OUT_RING(dev_priv->sarea_priv->last_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 522 | |
| 523 | ADVANCE_RING(); |
| 524 | } |
| 525 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 526 | static void r128_cce_dispatch_flip(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | { |
| 528 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 529 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 530 | DRM_DEBUG("%s: page=%d pfCurrentPage=%d\n", |
| 531 | __FUNCTION__, |
| 532 | dev_priv->current_page, dev_priv->sarea_priv->pfCurrentPage); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 533 | |
| 534 | #if R128_PERFORMANCE_BOXES |
| 535 | /* Do some trivial performance monitoring... |
| 536 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 537 | r128_cce_performance_boxes(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | #endif |
| 539 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 540 | BEGIN_RING(4); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
| 542 | R128_WAIT_UNTIL_PAGE_FLIPPED(); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 543 | OUT_RING(CCE_PACKET0(R128_CRTC_OFFSET, 0)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 545 | if (dev_priv->current_page == 0) { |
| 546 | OUT_RING(dev_priv->back_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 547 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 548 | OUT_RING(dev_priv->front_offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 549 | } |
| 550 | |
| 551 | ADVANCE_RING(); |
| 552 | |
| 553 | /* Increment the frame counter. The client-side 3D driver must |
| 554 | * throttle the framerate by waiting for this value before |
| 555 | * performing the swapbuffer ioctl. |
| 556 | */ |
| 557 | dev_priv->sarea_priv->last_frame++; |
| 558 | dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page = |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 559 | 1 - dev_priv->current_page; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 560 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 561 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 563 | OUT_RING(CCE_PACKET0(R128_LAST_FRAME_REG, 0)); |
| 564 | OUT_RING(dev_priv->sarea_priv->last_frame); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | |
| 566 | ADVANCE_RING(); |
| 567 | } |
| 568 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 569 | static void r128_cce_dispatch_vertex(drm_device_t * dev, drm_buf_t * buf) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 570 | { |
| 571 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 572 | drm_r128_buf_priv_t *buf_priv = buf->dev_private; |
| 573 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 574 | int format = sarea_priv->vc_format; |
| 575 | int offset = buf->bus_address; |
| 576 | int size = buf->used; |
| 577 | int prim = buf_priv->prim; |
| 578 | int i = 0; |
| 579 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 580 | DRM_DEBUG("buf=%d nbox=%d\n", buf->idx, sarea_priv->nbox); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 581 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 582 | if (0) |
| 583 | r128_print_dirty("dispatch_vertex", sarea_priv->dirty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 584 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 585 | if (buf->used) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 586 | buf_priv->dispatched = 1; |
| 587 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 588 | if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) { |
| 589 | r128_emit_state(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 590 | } |
| 591 | |
| 592 | do { |
| 593 | /* Emit the next set of up to three cliprects */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 594 | if (i < sarea_priv->nbox) { |
| 595 | r128_emit_clip_rects(dev_priv, |
| 596 | &sarea_priv->boxes[i], |
| 597 | sarea_priv->nbox - i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 598 | } |
| 599 | |
| 600 | /* Emit the vertex buffer rendering commands */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 601 | BEGIN_RING(5); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 602 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 603 | OUT_RING(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM, 3)); |
| 604 | OUT_RING(offset); |
| 605 | OUT_RING(size); |
| 606 | OUT_RING(format); |
| 607 | OUT_RING(prim | R128_CCE_VC_CNTL_PRIM_WALK_LIST | |
| 608 | (size << R128_CCE_VC_CNTL_NUM_SHIFT)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 609 | |
| 610 | ADVANCE_RING(); |
| 611 | |
| 612 | i += 3; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 613 | } while (i < sarea_priv->nbox); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 614 | } |
| 615 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 616 | if (buf_priv->discard) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | buf_priv->age = dev_priv->sarea_priv->last_dispatch; |
| 618 | |
| 619 | /* Emit the vertex buffer age */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 620 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 621 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 622 | OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0)); |
| 623 | OUT_RING(buf_priv->age); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | |
| 625 | ADVANCE_RING(); |
| 626 | |
| 627 | buf->pending = 1; |
| 628 | buf->used = 0; |
| 629 | /* FIXME: Check dispatched field */ |
| 630 | buf_priv->dispatched = 0; |
| 631 | } |
| 632 | |
| 633 | dev_priv->sarea_priv->last_dispatch++; |
| 634 | |
| 635 | sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS; |
| 636 | sarea_priv->nbox = 0; |
| 637 | } |
| 638 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 639 | static void r128_cce_dispatch_indirect(drm_device_t * dev, |
| 640 | drm_buf_t * buf, int start, int end) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 641 | { |
| 642 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 643 | drm_r128_buf_priv_t *buf_priv = buf->dev_private; |
| 644 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 645 | DRM_DEBUG("indirect: buf=%d s=0x%x e=0x%x\n", buf->idx, start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 646 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 647 | if (start != end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 648 | int offset = buf->bus_address + start; |
| 649 | int dwords = (end - start + 3) / sizeof(u32); |
| 650 | |
| 651 | /* Indirect buffer data must be an even number of |
| 652 | * dwords, so if we've been given an odd number we must |
| 653 | * pad the data with a Type-2 CCE packet. |
| 654 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 655 | if (dwords & 1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 656 | u32 *data = (u32 *) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 657 | ((char *)dev->agp_buffer_map->handle |
| 658 | + buf->offset + start); |
| 659 | data[dwords++] = cpu_to_le32(R128_CCE_PACKET2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 660 | } |
| 661 | |
| 662 | buf_priv->dispatched = 1; |
| 663 | |
| 664 | /* Fire off the indirect buffer */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 665 | BEGIN_RING(3); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 666 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 667 | OUT_RING(CCE_PACKET0(R128_PM4_IW_INDOFF, 1)); |
| 668 | OUT_RING(offset); |
| 669 | OUT_RING(dwords); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 670 | |
| 671 | ADVANCE_RING(); |
| 672 | } |
| 673 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 674 | if (buf_priv->discard) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 675 | buf_priv->age = dev_priv->sarea_priv->last_dispatch; |
| 676 | |
| 677 | /* Emit the indirect buffer age */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 678 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 679 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 680 | OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0)); |
| 681 | OUT_RING(buf_priv->age); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 682 | |
| 683 | ADVANCE_RING(); |
| 684 | |
| 685 | buf->pending = 1; |
| 686 | buf->used = 0; |
| 687 | /* FIXME: Check dispatched field */ |
| 688 | buf_priv->dispatched = 0; |
| 689 | } |
| 690 | |
| 691 | dev_priv->sarea_priv->last_dispatch++; |
| 692 | } |
| 693 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 694 | static void r128_cce_dispatch_indices(drm_device_t * dev, |
| 695 | drm_buf_t * buf, |
| 696 | int start, int end, int count) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 697 | { |
| 698 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 699 | drm_r128_buf_priv_t *buf_priv = buf->dev_private; |
| 700 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 701 | int format = sarea_priv->vc_format; |
| 702 | int offset = dev->agp_buffer_map->offset - dev_priv->cce_buffers_offset; |
| 703 | int prim = buf_priv->prim; |
| 704 | u32 *data; |
| 705 | int dwords; |
| 706 | int i = 0; |
| 707 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 708 | DRM_DEBUG("indices: s=%d e=%d c=%d\n", start, end, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 709 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 710 | if (0) |
| 711 | r128_print_dirty("dispatch_indices", sarea_priv->dirty); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 712 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 713 | if (start != end) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 714 | buf_priv->dispatched = 1; |
| 715 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 716 | if (sarea_priv->dirty & ~R128_UPLOAD_CLIPRECTS) { |
| 717 | r128_emit_state(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 718 | } |
| 719 | |
| 720 | dwords = (end - start + 3) / sizeof(u32); |
| 721 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 722 | data = (u32 *) ((char *)dev->agp_buffer_map->handle |
| 723 | + buf->offset + start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 724 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 725 | data[0] = cpu_to_le32(CCE_PACKET3(R128_3D_RNDR_GEN_INDX_PRIM, |
| 726 | dwords - 2)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 727 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 728 | data[1] = cpu_to_le32(offset); |
| 729 | data[2] = cpu_to_le32(R128_MAX_VB_VERTS); |
| 730 | data[3] = cpu_to_le32(format); |
| 731 | data[4] = cpu_to_le32((prim | R128_CCE_VC_CNTL_PRIM_WALK_IND | |
| 732 | (count << 16))); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 733 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 734 | if (count & 0x1) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 735 | #ifdef __LITTLE_ENDIAN |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 736 | data[dwords - 1] &= 0x0000ffff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 737 | #else |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 738 | data[dwords - 1] &= 0xffff0000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 739 | #endif |
| 740 | } |
| 741 | |
| 742 | do { |
| 743 | /* Emit the next set of up to three cliprects */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 744 | if (i < sarea_priv->nbox) { |
| 745 | r128_emit_clip_rects(dev_priv, |
| 746 | &sarea_priv->boxes[i], |
| 747 | sarea_priv->nbox - i); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 748 | } |
| 749 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 750 | r128_cce_dispatch_indirect(dev, buf, start, end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 751 | |
| 752 | i += 3; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 753 | } while (i < sarea_priv->nbox); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 754 | } |
| 755 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 756 | if (buf_priv->discard) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 757 | buf_priv->age = dev_priv->sarea_priv->last_dispatch; |
| 758 | |
| 759 | /* Emit the vertex buffer age */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 760 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 762 | OUT_RING(CCE_PACKET0(R128_LAST_DISPATCH_REG, 0)); |
| 763 | OUT_RING(buf_priv->age); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | |
| 765 | ADVANCE_RING(); |
| 766 | |
| 767 | buf->pending = 1; |
| 768 | /* FIXME: Check dispatched field */ |
| 769 | buf_priv->dispatched = 0; |
| 770 | } |
| 771 | |
| 772 | dev_priv->sarea_priv->last_dispatch++; |
| 773 | |
| 774 | sarea_priv->dirty &= ~R128_UPLOAD_CLIPRECTS; |
| 775 | sarea_priv->nbox = 0; |
| 776 | } |
| 777 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 778 | static int r128_cce_dispatch_blit(DRMFILE filp, |
| 779 | drm_device_t * dev, drm_r128_blit_t * blit) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 780 | { |
| 781 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 782 | drm_device_dma_t *dma = dev->dma; |
| 783 | drm_buf_t *buf; |
| 784 | drm_r128_buf_priv_t *buf_priv; |
| 785 | u32 *data; |
| 786 | int dword_shift, dwords; |
| 787 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 788 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | |
| 790 | /* The compiler won't optimize away a division by a variable, |
| 791 | * even if the only legal values are powers of two. Thus, we'll |
| 792 | * use a shift instead. |
| 793 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 794 | switch (blit->format) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 795 | case R128_DATATYPE_ARGB8888: |
| 796 | dword_shift = 0; |
| 797 | break; |
| 798 | case R128_DATATYPE_ARGB1555: |
| 799 | case R128_DATATYPE_RGB565: |
| 800 | case R128_DATATYPE_ARGB4444: |
| 801 | case R128_DATATYPE_YVYU422: |
| 802 | case R128_DATATYPE_VYUY422: |
| 803 | dword_shift = 1; |
| 804 | break; |
| 805 | case R128_DATATYPE_CI8: |
| 806 | case R128_DATATYPE_RGB8: |
| 807 | dword_shift = 2; |
| 808 | break; |
| 809 | default: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 810 | DRM_ERROR("invalid blit format %d\n", blit->format); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 811 | return DRM_ERR(EINVAL); |
| 812 | } |
| 813 | |
| 814 | /* Flush the pixel cache, and mark the contents as Read Invalid. |
| 815 | * This ensures no pixel data gets mixed up with the texture |
| 816 | * data from the host data blit, otherwise part of the texture |
| 817 | * image may be corrupted. |
| 818 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 819 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 820 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 821 | OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0)); |
| 822 | OUT_RING(R128_PC_RI_GUI | R128_PC_FLUSH_GUI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 823 | |
| 824 | ADVANCE_RING(); |
| 825 | |
| 826 | /* Dispatch the indirect buffer. |
| 827 | */ |
| 828 | buf = dma->buflist[blit->idx]; |
| 829 | buf_priv = buf->dev_private; |
| 830 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 831 | if (buf->filp != filp) { |
| 832 | DRM_ERROR("process %d using buffer owned by %p\n", |
| 833 | DRM_CURRENTPID, buf->filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 834 | return DRM_ERR(EINVAL); |
| 835 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 836 | if (buf->pending) { |
| 837 | DRM_ERROR("sending pending buffer %d\n", blit->idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 838 | return DRM_ERR(EINVAL); |
| 839 | } |
| 840 | |
| 841 | buf_priv->discard = 1; |
| 842 | |
| 843 | dwords = (blit->width * blit->height) >> dword_shift; |
| 844 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 845 | data = (u32 *) ((char *)dev->agp_buffer_map->handle + buf->offset); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 847 | data[0] = cpu_to_le32(CCE_PACKET3(R128_CNTL_HOSTDATA_BLT, dwords + 6)); |
| 848 | data[1] = cpu_to_le32((R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 849 | R128_GMC_BRUSH_NONE | |
| 850 | (blit->format << 8) | |
| 851 | R128_GMC_SRC_DATATYPE_COLOR | |
| 852 | R128_ROP3_S | |
| 853 | R128_DP_SRC_SOURCE_HOST_DATA | |
| 854 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 855 | R128_GMC_AUX_CLIP_DIS | R128_GMC_WR_MSK_DIS)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 856 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 857 | data[2] = cpu_to_le32((blit->pitch << 21) | (blit->offset >> 5)); |
| 858 | data[3] = cpu_to_le32(0xffffffff); |
| 859 | data[4] = cpu_to_le32(0xffffffff); |
| 860 | data[5] = cpu_to_le32((blit->y << 16) | blit->x); |
| 861 | data[6] = cpu_to_le32((blit->height << 16) | blit->width); |
| 862 | data[7] = cpu_to_le32(dwords); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 863 | |
| 864 | buf->used = (dwords + 8) * sizeof(u32); |
| 865 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 866 | r128_cce_dispatch_indirect(dev, buf, 0, buf->used); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 867 | |
| 868 | /* Flush the pixel cache after the blit completes. This ensures |
| 869 | * the texture data is written out to memory before rendering |
| 870 | * continues. |
| 871 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 872 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 873 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 874 | OUT_RING(CCE_PACKET0(R128_PC_GUI_CTLSTAT, 0)); |
| 875 | OUT_RING(R128_PC_FLUSH_GUI); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 876 | |
| 877 | ADVANCE_RING(); |
| 878 | |
| 879 | return 0; |
| 880 | } |
| 881 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 882 | /* ================================================================ |
| 883 | * Tiled depth buffer management |
| 884 | * |
| 885 | * FIXME: These should all set the destination write mask for when we |
| 886 | * have hardware stencil support. |
| 887 | */ |
| 888 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 889 | static int r128_cce_dispatch_write_span(drm_device_t * dev, |
| 890 | drm_r128_depth_t * depth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 891 | { |
| 892 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 893 | int count, x, y; |
| 894 | u32 *buffer; |
| 895 | u8 *mask; |
| 896 | int i, buffer_size, mask_size; |
| 897 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 898 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 899 | |
| 900 | count = depth->n; |
| 901 | if (count > 4096 || count <= 0) |
| 902 | return DRM_ERR(EMSGSIZE); |
| 903 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 904 | if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | return DRM_ERR(EFAULT); |
| 906 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 907 | if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 908 | return DRM_ERR(EFAULT); |
| 909 | } |
| 910 | |
| 911 | buffer_size = depth->n * sizeof(u32); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 912 | buffer = drm_alloc(buffer_size, DRM_MEM_BUFS); |
| 913 | if (buffer == NULL) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 914 | return DRM_ERR(ENOMEM); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 915 | if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) { |
| 916 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | return DRM_ERR(EFAULT); |
| 918 | } |
| 919 | |
| 920 | mask_size = depth->n * sizeof(u8); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 921 | if (depth->mask) { |
| 922 | mask = drm_alloc(mask_size, DRM_MEM_BUFS); |
| 923 | if (mask == NULL) { |
| 924 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 925 | return DRM_ERR(ENOMEM); |
| 926 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 927 | if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) { |
| 928 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
| 929 | drm_free(mask, mask_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 930 | return DRM_ERR(EFAULT); |
| 931 | } |
| 932 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 933 | for (i = 0; i < count; i++, x++) { |
| 934 | if (mask[i]) { |
| 935 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 936 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 937 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 938 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 939 | R128_GMC_BRUSH_SOLID_COLOR | |
| 940 | (dev_priv->depth_fmt << 8) | |
| 941 | R128_GMC_SRC_DATATYPE_COLOR | |
| 942 | R128_ROP3_P | |
| 943 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 944 | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 946 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 947 | OUT_RING(buffer[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 948 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 949 | OUT_RING((x << 16) | y); |
| 950 | OUT_RING((1 << 16) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 951 | |
| 952 | ADVANCE_RING(); |
| 953 | } |
| 954 | } |
| 955 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 956 | drm_free(mask, mask_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 958 | for (i = 0; i < count; i++, x++) { |
| 959 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 960 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 961 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 962 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 963 | R128_GMC_BRUSH_SOLID_COLOR | |
| 964 | (dev_priv->depth_fmt << 8) | |
| 965 | R128_GMC_SRC_DATATYPE_COLOR | |
| 966 | R128_ROP3_P | |
| 967 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 968 | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 970 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 971 | OUT_RING(buffer[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 972 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 973 | OUT_RING((x << 16) | y); |
| 974 | OUT_RING((1 << 16) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 975 | |
| 976 | ADVANCE_RING(); |
| 977 | } |
| 978 | } |
| 979 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 980 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 981 | |
| 982 | return 0; |
| 983 | } |
| 984 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 985 | static int r128_cce_dispatch_write_pixels(drm_device_t * dev, |
| 986 | drm_r128_depth_t * depth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 987 | { |
| 988 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 989 | int count, *x, *y; |
| 990 | u32 *buffer; |
| 991 | u8 *mask; |
| 992 | int i, xbuf_size, ybuf_size, buffer_size, mask_size; |
| 993 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 994 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 995 | |
| 996 | count = depth->n; |
| 997 | if (count > 4096 || count <= 0) |
| 998 | return DRM_ERR(EMSGSIZE); |
| 999 | |
| 1000 | xbuf_size = count * sizeof(*x); |
| 1001 | ybuf_size = count * sizeof(*y); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1002 | x = drm_alloc(xbuf_size, DRM_MEM_BUFS); |
| 1003 | if (x == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1004 | return DRM_ERR(ENOMEM); |
| 1005 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1006 | y = drm_alloc(ybuf_size, DRM_MEM_BUFS); |
| 1007 | if (y == NULL) { |
| 1008 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1009 | return DRM_ERR(ENOMEM); |
| 1010 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1011 | if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) { |
| 1012 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1013 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | return DRM_ERR(EFAULT); |
| 1015 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1016 | if (DRM_COPY_FROM_USER(y, depth->y, xbuf_size)) { |
| 1017 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1018 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1019 | return DRM_ERR(EFAULT); |
| 1020 | } |
| 1021 | |
| 1022 | buffer_size = depth->n * sizeof(u32); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1023 | buffer = drm_alloc(buffer_size, DRM_MEM_BUFS); |
| 1024 | if (buffer == NULL) { |
| 1025 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1026 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1027 | return DRM_ERR(ENOMEM); |
| 1028 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1029 | if (DRM_COPY_FROM_USER(buffer, depth->buffer, buffer_size)) { |
| 1030 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1031 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
| 1032 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1033 | return DRM_ERR(EFAULT); |
| 1034 | } |
| 1035 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1036 | if (depth->mask) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1037 | mask_size = depth->n * sizeof(u8); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1038 | mask = drm_alloc(mask_size, DRM_MEM_BUFS); |
| 1039 | if (mask == NULL) { |
| 1040 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1041 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
| 1042 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1043 | return DRM_ERR(ENOMEM); |
| 1044 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1045 | if (DRM_COPY_FROM_USER(mask, depth->mask, mask_size)) { |
| 1046 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1047 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
| 1048 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
| 1049 | drm_free(mask, mask_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1050 | return DRM_ERR(EFAULT); |
| 1051 | } |
| 1052 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1053 | for (i = 0; i < count; i++) { |
| 1054 | if (mask[i]) { |
| 1055 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1056 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1057 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 1058 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 1059 | R128_GMC_BRUSH_SOLID_COLOR | |
| 1060 | (dev_priv->depth_fmt << 8) | |
| 1061 | R128_GMC_SRC_DATATYPE_COLOR | |
| 1062 | R128_ROP3_P | |
| 1063 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 1064 | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1065 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1066 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 1067 | OUT_RING(buffer[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1068 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1069 | OUT_RING((x[i] << 16) | y[i]); |
| 1070 | OUT_RING((1 << 16) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1071 | |
| 1072 | ADVANCE_RING(); |
| 1073 | } |
| 1074 | } |
| 1075 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1076 | drm_free(mask, mask_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1077 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1078 | for (i = 0; i < count; i++) { |
| 1079 | BEGIN_RING(6); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1080 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1081 | OUT_RING(CCE_PACKET3(R128_CNTL_PAINT_MULTI, 4)); |
| 1082 | OUT_RING(R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 1083 | R128_GMC_BRUSH_SOLID_COLOR | |
| 1084 | (dev_priv->depth_fmt << 8) | |
| 1085 | R128_GMC_SRC_DATATYPE_COLOR | |
| 1086 | R128_ROP3_P | |
| 1087 | R128_GMC_CLR_CMP_CNTL_DIS | |
| 1088 | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1089 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1090 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 1091 | OUT_RING(buffer[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1092 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1093 | OUT_RING((x[i] << 16) | y[i]); |
| 1094 | OUT_RING((1 << 16) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1095 | |
| 1096 | ADVANCE_RING(); |
| 1097 | } |
| 1098 | } |
| 1099 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1100 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1101 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
| 1102 | drm_free(buffer, buffer_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1103 | |
| 1104 | return 0; |
| 1105 | } |
| 1106 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1107 | static int r128_cce_dispatch_read_span(drm_device_t * dev, |
| 1108 | drm_r128_depth_t * depth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1109 | { |
| 1110 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1111 | int count, x, y; |
| 1112 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1113 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1114 | |
| 1115 | count = depth->n; |
| 1116 | if (count > 4096 || count <= 0) |
| 1117 | return DRM_ERR(EMSGSIZE); |
| 1118 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1119 | if (DRM_COPY_FROM_USER(&x, depth->x, sizeof(x))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1120 | return DRM_ERR(EFAULT); |
| 1121 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1122 | if (DRM_COPY_FROM_USER(&y, depth->y, sizeof(y))) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1123 | return DRM_ERR(EFAULT); |
| 1124 | } |
| 1125 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1126 | BEGIN_RING(7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1127 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1128 | OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5)); |
| 1129 | OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL | |
| 1130 | R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 1131 | R128_GMC_BRUSH_NONE | |
| 1132 | (dev_priv->depth_fmt << 8) | |
| 1133 | R128_GMC_SRC_DATATYPE_COLOR | |
| 1134 | R128_ROP3_S | |
| 1135 | R128_DP_SRC_SOURCE_MEMORY | |
| 1136 | R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1137 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1138 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 1139 | OUT_RING(dev_priv->span_pitch_offset_c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1140 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1141 | OUT_RING((x << 16) | y); |
| 1142 | OUT_RING((0 << 16) | 0); |
| 1143 | OUT_RING((count << 16) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1144 | |
| 1145 | ADVANCE_RING(); |
| 1146 | |
| 1147 | return 0; |
| 1148 | } |
| 1149 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1150 | static int r128_cce_dispatch_read_pixels(drm_device_t * dev, |
| 1151 | drm_r128_depth_t * depth) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1152 | { |
| 1153 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1154 | int count, *x, *y; |
| 1155 | int i, xbuf_size, ybuf_size; |
| 1156 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1157 | DRM_DEBUG("%s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1158 | |
| 1159 | count = depth->n; |
| 1160 | if (count > 4096 || count <= 0) |
| 1161 | return DRM_ERR(EMSGSIZE); |
| 1162 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1163 | if (count > dev_priv->depth_pitch) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1164 | count = dev_priv->depth_pitch; |
| 1165 | } |
| 1166 | |
| 1167 | xbuf_size = count * sizeof(*x); |
| 1168 | ybuf_size = count * sizeof(*y); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1169 | x = drm_alloc(xbuf_size, DRM_MEM_BUFS); |
| 1170 | if (x == NULL) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1171 | return DRM_ERR(ENOMEM); |
| 1172 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1173 | y = drm_alloc(ybuf_size, DRM_MEM_BUFS); |
| 1174 | if (y == NULL) { |
| 1175 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1176 | return DRM_ERR(ENOMEM); |
| 1177 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1178 | if (DRM_COPY_FROM_USER(x, depth->x, xbuf_size)) { |
| 1179 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1180 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1181 | return DRM_ERR(EFAULT); |
| 1182 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1183 | if (DRM_COPY_FROM_USER(y, depth->y, ybuf_size)) { |
| 1184 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1185 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1186 | return DRM_ERR(EFAULT); |
| 1187 | } |
| 1188 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1189 | for (i = 0; i < count; i++) { |
| 1190 | BEGIN_RING(7); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1191 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1192 | OUT_RING(CCE_PACKET3(R128_CNTL_BITBLT_MULTI, 5)); |
| 1193 | OUT_RING(R128_GMC_SRC_PITCH_OFFSET_CNTL | |
| 1194 | R128_GMC_DST_PITCH_OFFSET_CNTL | |
| 1195 | R128_GMC_BRUSH_NONE | |
| 1196 | (dev_priv->depth_fmt << 8) | |
| 1197 | R128_GMC_SRC_DATATYPE_COLOR | |
| 1198 | R128_ROP3_S | |
| 1199 | R128_DP_SRC_SOURCE_MEMORY | |
| 1200 | R128_GMC_CLR_CMP_CNTL_DIS | R128_GMC_WR_MSK_DIS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1201 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1202 | OUT_RING(dev_priv->depth_pitch_offset_c); |
| 1203 | OUT_RING(dev_priv->span_pitch_offset_c); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1204 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1205 | OUT_RING((x[i] << 16) | y[i]); |
| 1206 | OUT_RING((i << 16) | 0); |
| 1207 | OUT_RING((1 << 16) | 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1208 | |
| 1209 | ADVANCE_RING(); |
| 1210 | } |
| 1211 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1212 | drm_free(x, xbuf_size, DRM_MEM_BUFS); |
| 1213 | drm_free(y, ybuf_size, DRM_MEM_BUFS); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1214 | |
| 1215 | return 0; |
| 1216 | } |
| 1217 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1218 | /* ================================================================ |
| 1219 | * Polygon stipple |
| 1220 | */ |
| 1221 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1222 | static void r128_cce_dispatch_stipple(drm_device_t * dev, u32 * stipple) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1223 | { |
| 1224 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1225 | int i; |
| 1226 | RING_LOCALS; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1227 | DRM_DEBUG("%s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1228 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1229 | BEGIN_RING(33); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1230 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1231 | OUT_RING(CCE_PACKET0(R128_BRUSH_DATA0, 31)); |
| 1232 | for (i = 0; i < 32; i++) { |
| 1233 | OUT_RING(stipple[i]); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | ADVANCE_RING(); |
| 1237 | } |
| 1238 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1239 | /* ================================================================ |
| 1240 | * IOCTL functions |
| 1241 | */ |
| 1242 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1243 | static int r128_cce_clear(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1244 | { |
| 1245 | DRM_DEVICE; |
| 1246 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1247 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
| 1248 | drm_r128_clear_t clear; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1249 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1250 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1251 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1252 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1253 | DRM_COPY_FROM_USER_IOCTL(clear, (drm_r128_clear_t __user *) data, |
| 1254 | sizeof(clear)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1255 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1256 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1257 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1258 | if (sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1259 | sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS; |
| 1260 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1261 | r128_cce_dispatch_clear(dev, &clear); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1262 | COMMIT_RING(); |
| 1263 | |
| 1264 | /* Make sure we restore the 3D state next time. |
| 1265 | */ |
| 1266 | dev_priv->sarea_priv->dirty |= R128_UPLOAD_CONTEXT | R128_UPLOAD_MASKS; |
| 1267 | |
| 1268 | return 0; |
| 1269 | } |
| 1270 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1271 | static int r128_do_init_pageflip(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1272 | { |
| 1273 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1274 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1275 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1276 | dev_priv->crtc_offset = R128_READ(R128_CRTC_OFFSET); |
| 1277 | dev_priv->crtc_offset_cntl = R128_READ(R128_CRTC_OFFSET_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1278 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1279 | R128_WRITE(R128_CRTC_OFFSET, dev_priv->front_offset); |
| 1280 | R128_WRITE(R128_CRTC_OFFSET_CNTL, |
| 1281 | dev_priv->crtc_offset_cntl | R128_CRTC_OFFSET_FLIP_CNTL); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1282 | |
| 1283 | dev_priv->page_flipping = 1; |
| 1284 | dev_priv->current_page = 0; |
| 1285 | dev_priv->sarea_priv->pfCurrentPage = dev_priv->current_page; |
| 1286 | |
| 1287 | return 0; |
| 1288 | } |
| 1289 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1290 | static int r128_do_cleanup_pageflip(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1291 | { |
| 1292 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1293 | DRM_DEBUG("\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1294 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1295 | R128_WRITE(R128_CRTC_OFFSET, dev_priv->crtc_offset); |
| 1296 | R128_WRITE(R128_CRTC_OFFSET_CNTL, dev_priv->crtc_offset_cntl); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1297 | |
| 1298 | if (dev_priv->current_page != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1299 | r128_cce_dispatch_flip(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1300 | COMMIT_RING(); |
| 1301 | } |
| 1302 | |
| 1303 | dev_priv->page_flipping = 0; |
| 1304 | return 0; |
| 1305 | } |
| 1306 | |
| 1307 | /* Swapping and flipping are different operations, need different ioctls. |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1308 | * They can & should be intermixed to support multiple 3d windows. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1309 | */ |
| 1310 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1311 | static int r128_cce_flip(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1312 | { |
| 1313 | DRM_DEVICE; |
| 1314 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1315 | DRM_DEBUG("%s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1316 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1317 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1318 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1319 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1320 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1321 | if (!dev_priv->page_flipping) |
| 1322 | r128_do_init_pageflip(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1323 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1324 | r128_cce_dispatch_flip(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1325 | |
| 1326 | COMMIT_RING(); |
| 1327 | return 0; |
| 1328 | } |
| 1329 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1330 | static int r128_cce_swap(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1331 | { |
| 1332 | DRM_DEVICE; |
| 1333 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1334 | drm_r128_sarea_t *sarea_priv = dev_priv->sarea_priv; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1335 | DRM_DEBUG("%s\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1336 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1337 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1338 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1339 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1340 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1341 | if (sarea_priv->nbox > R128_NR_SAREA_CLIPRECTS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1342 | sarea_priv->nbox = R128_NR_SAREA_CLIPRECTS; |
| 1343 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1344 | r128_cce_dispatch_swap(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1345 | dev_priv->sarea_priv->dirty |= (R128_UPLOAD_CONTEXT | |
| 1346 | R128_UPLOAD_MASKS); |
| 1347 | |
| 1348 | COMMIT_RING(); |
| 1349 | return 0; |
| 1350 | } |
| 1351 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1352 | static int r128_cce_vertex(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1353 | { |
| 1354 | DRM_DEVICE; |
| 1355 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1356 | drm_device_dma_t *dma = dev->dma; |
| 1357 | drm_buf_t *buf; |
| 1358 | drm_r128_buf_priv_t *buf_priv; |
| 1359 | drm_r128_vertex_t vertex; |
| 1360 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1361 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1362 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1363 | if (!dev_priv) { |
| 1364 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1365 | return DRM_ERR(EINVAL); |
| 1366 | } |
| 1367 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1368 | DRM_COPY_FROM_USER_IOCTL(vertex, (drm_r128_vertex_t __user *) data, |
| 1369 | sizeof(vertex)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1370 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1371 | DRM_DEBUG("pid=%d index=%d count=%d discard=%d\n", |
| 1372 | DRM_CURRENTPID, vertex.idx, vertex.count, vertex.discard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1373 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1374 | if (vertex.idx < 0 || vertex.idx >= dma->buf_count) { |
| 1375 | DRM_ERROR("buffer index %d (of %d max)\n", |
| 1376 | vertex.idx, dma->buf_count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1377 | return DRM_ERR(EINVAL); |
| 1378 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1379 | if (vertex.prim < 0 || |
| 1380 | vertex.prim > R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2) { |
| 1381 | DRM_ERROR("buffer prim %d\n", vertex.prim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1382 | return DRM_ERR(EINVAL); |
| 1383 | } |
| 1384 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1385 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
| 1386 | VB_AGE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1387 | |
| 1388 | buf = dma->buflist[vertex.idx]; |
| 1389 | buf_priv = buf->dev_private; |
| 1390 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1391 | if (buf->filp != filp) { |
| 1392 | DRM_ERROR("process %d using buffer owned by %p\n", |
| 1393 | DRM_CURRENTPID, buf->filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1394 | return DRM_ERR(EINVAL); |
| 1395 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1396 | if (buf->pending) { |
| 1397 | DRM_ERROR("sending pending buffer %d\n", vertex.idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1398 | return DRM_ERR(EINVAL); |
| 1399 | } |
| 1400 | |
| 1401 | buf->used = vertex.count; |
| 1402 | buf_priv->prim = vertex.prim; |
| 1403 | buf_priv->discard = vertex.discard; |
| 1404 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1405 | r128_cce_dispatch_vertex(dev, buf); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1406 | |
| 1407 | COMMIT_RING(); |
| 1408 | return 0; |
| 1409 | } |
| 1410 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1411 | static int r128_cce_indices(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1412 | { |
| 1413 | DRM_DEVICE; |
| 1414 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1415 | drm_device_dma_t *dma = dev->dma; |
| 1416 | drm_buf_t *buf; |
| 1417 | drm_r128_buf_priv_t *buf_priv; |
| 1418 | drm_r128_indices_t elts; |
| 1419 | int count; |
| 1420 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1421 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1422 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1423 | if (!dev_priv) { |
| 1424 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1425 | return DRM_ERR(EINVAL); |
| 1426 | } |
| 1427 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1428 | DRM_COPY_FROM_USER_IOCTL(elts, (drm_r128_indices_t __user *) data, |
| 1429 | sizeof(elts)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1430 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1431 | DRM_DEBUG("pid=%d buf=%d s=%d e=%d d=%d\n", DRM_CURRENTPID, |
| 1432 | elts.idx, elts.start, elts.end, elts.discard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1433 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1434 | if (elts.idx < 0 || elts.idx >= dma->buf_count) { |
| 1435 | DRM_ERROR("buffer index %d (of %d max)\n", |
| 1436 | elts.idx, dma->buf_count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1437 | return DRM_ERR(EINVAL); |
| 1438 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1439 | if (elts.prim < 0 || elts.prim > R128_CCE_VC_CNTL_PRIM_TYPE_TRI_TYPE2) { |
| 1440 | DRM_ERROR("buffer prim %d\n", elts.prim); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1441 | return DRM_ERR(EINVAL); |
| 1442 | } |
| 1443 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1444 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
| 1445 | VB_AGE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1446 | |
| 1447 | buf = dma->buflist[elts.idx]; |
| 1448 | buf_priv = buf->dev_private; |
| 1449 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1450 | if (buf->filp != filp) { |
| 1451 | DRM_ERROR("process %d using buffer owned by %p\n", |
| 1452 | DRM_CURRENTPID, buf->filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1453 | return DRM_ERR(EINVAL); |
| 1454 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1455 | if (buf->pending) { |
| 1456 | DRM_ERROR("sending pending buffer %d\n", elts.idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1457 | return DRM_ERR(EINVAL); |
| 1458 | } |
| 1459 | |
| 1460 | count = (elts.end - elts.start) / sizeof(u16); |
| 1461 | elts.start -= R128_INDEX_PRIM_OFFSET; |
| 1462 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1463 | if (elts.start & 0x7) { |
| 1464 | DRM_ERROR("misaligned buffer 0x%x\n", elts.start); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1465 | return DRM_ERR(EINVAL); |
| 1466 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1467 | if (elts.start < buf->used) { |
| 1468 | DRM_ERROR("no header 0x%x - 0x%x\n", elts.start, buf->used); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1469 | return DRM_ERR(EINVAL); |
| 1470 | } |
| 1471 | |
| 1472 | buf->used = elts.end; |
| 1473 | buf_priv->prim = elts.prim; |
| 1474 | buf_priv->discard = elts.discard; |
| 1475 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1476 | r128_cce_dispatch_indices(dev, buf, elts.start, elts.end, count); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1477 | |
| 1478 | COMMIT_RING(); |
| 1479 | return 0; |
| 1480 | } |
| 1481 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1482 | static int r128_cce_blit(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1483 | { |
| 1484 | DRM_DEVICE; |
| 1485 | drm_device_dma_t *dma = dev->dma; |
| 1486 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1487 | drm_r128_blit_t blit; |
| 1488 | int ret; |
| 1489 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1490 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1491 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1492 | DRM_COPY_FROM_USER_IOCTL(blit, (drm_r128_blit_t __user *) data, |
| 1493 | sizeof(blit)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1494 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1495 | DRM_DEBUG("pid=%d index=%d\n", DRM_CURRENTPID, blit.idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1496 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1497 | if (blit.idx < 0 || blit.idx >= dma->buf_count) { |
| 1498 | DRM_ERROR("buffer index %d (of %d max)\n", |
| 1499 | blit.idx, dma->buf_count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1500 | return DRM_ERR(EINVAL); |
| 1501 | } |
| 1502 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1503 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
| 1504 | VB_AGE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1505 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1506 | ret = r128_cce_dispatch_blit(filp, dev, &blit); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1507 | |
| 1508 | COMMIT_RING(); |
| 1509 | return ret; |
| 1510 | } |
| 1511 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1512 | static int r128_cce_depth(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1513 | { |
| 1514 | DRM_DEVICE; |
| 1515 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1516 | drm_r128_depth_t depth; |
| 1517 | int ret; |
| 1518 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1519 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1520 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1521 | DRM_COPY_FROM_USER_IOCTL(depth, (drm_r128_depth_t __user *) data, |
| 1522 | sizeof(depth)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1523 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1524 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1525 | |
| 1526 | ret = DRM_ERR(EINVAL); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1527 | switch (depth.func) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1528 | case R128_WRITE_SPAN: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1529 | ret = r128_cce_dispatch_write_span(dev, &depth); |
Dave Airlie | 41aac24 | 2005-04-16 15:24:04 -0700 | [diff] [blame] | 1530 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1531 | case R128_WRITE_PIXELS: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1532 | ret = r128_cce_dispatch_write_pixels(dev, &depth); |
Dave Airlie | 41aac24 | 2005-04-16 15:24:04 -0700 | [diff] [blame] | 1533 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1534 | case R128_READ_SPAN: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1535 | ret = r128_cce_dispatch_read_span(dev, &depth); |
Dave Airlie | 41aac24 | 2005-04-16 15:24:04 -0700 | [diff] [blame] | 1536 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1537 | case R128_READ_PIXELS: |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1538 | ret = r128_cce_dispatch_read_pixels(dev, &depth); |
Dave Airlie | 41aac24 | 2005-04-16 15:24:04 -0700 | [diff] [blame] | 1539 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1540 | } |
| 1541 | |
| 1542 | COMMIT_RING(); |
| 1543 | return ret; |
| 1544 | } |
| 1545 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1546 | static int r128_cce_stipple(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1547 | { |
| 1548 | DRM_DEVICE; |
| 1549 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1550 | drm_r128_stipple_t stipple; |
| 1551 | u32 mask[32]; |
| 1552 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1553 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1554 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1555 | DRM_COPY_FROM_USER_IOCTL(stipple, (drm_r128_stipple_t __user *) data, |
| 1556 | sizeof(stipple)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1557 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1558 | if (DRM_COPY_FROM_USER(&mask, stipple.mask, 32 * sizeof(u32))) |
| 1559 | return DRM_ERR(EFAULT); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1560 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1561 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1562 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1563 | r128_cce_dispatch_stipple(dev, mask); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1564 | |
| 1565 | COMMIT_RING(); |
| 1566 | return 0; |
| 1567 | } |
| 1568 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1569 | static int r128_cce_indirect(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1570 | { |
| 1571 | DRM_DEVICE; |
| 1572 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1573 | drm_device_dma_t *dma = dev->dma; |
| 1574 | drm_buf_t *buf; |
| 1575 | drm_r128_buf_priv_t *buf_priv; |
| 1576 | drm_r128_indirect_t indirect; |
| 1577 | #if 0 |
| 1578 | RING_LOCALS; |
| 1579 | #endif |
| 1580 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1581 | LOCK_TEST_WITH_RETURN(dev, filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1582 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1583 | if (!dev_priv) { |
| 1584 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1585 | return DRM_ERR(EINVAL); |
| 1586 | } |
| 1587 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1588 | DRM_COPY_FROM_USER_IOCTL(indirect, (drm_r128_indirect_t __user *) data, |
| 1589 | sizeof(indirect)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1590 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1591 | DRM_DEBUG("indirect: idx=%d s=%d e=%d d=%d\n", |
| 1592 | indirect.idx, indirect.start, indirect.end, indirect.discard); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1593 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1594 | if (indirect.idx < 0 || indirect.idx >= dma->buf_count) { |
| 1595 | DRM_ERROR("buffer index %d (of %d max)\n", |
| 1596 | indirect.idx, dma->buf_count - 1); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1597 | return DRM_ERR(EINVAL); |
| 1598 | } |
| 1599 | |
| 1600 | buf = dma->buflist[indirect.idx]; |
| 1601 | buf_priv = buf->dev_private; |
| 1602 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1603 | if (buf->filp != filp) { |
| 1604 | DRM_ERROR("process %d using buffer owned by %p\n", |
| 1605 | DRM_CURRENTPID, buf->filp); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1606 | return DRM_ERR(EINVAL); |
| 1607 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1608 | if (buf->pending) { |
| 1609 | DRM_ERROR("sending pending buffer %d\n", indirect.idx); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1610 | return DRM_ERR(EINVAL); |
| 1611 | } |
| 1612 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1613 | if (indirect.start < buf->used) { |
| 1614 | DRM_ERROR("reusing indirect: start=0x%x actual=0x%x\n", |
| 1615 | indirect.start, buf->used); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1616 | return DRM_ERR(EINVAL); |
| 1617 | } |
| 1618 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1619 | RING_SPACE_TEST_WITH_RETURN(dev_priv); |
| 1620 | VB_AGE_TEST_WITH_RETURN(dev_priv); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1621 | |
| 1622 | buf->used = indirect.end; |
| 1623 | buf_priv->discard = indirect.discard; |
| 1624 | |
| 1625 | #if 0 |
| 1626 | /* Wait for the 3D stream to idle before the indirect buffer |
| 1627 | * containing 2D acceleration commands is processed. |
| 1628 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1629 | BEGIN_RING(2); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1630 | RADEON_WAIT_UNTIL_3D_IDLE(); |
| 1631 | ADVANCE_RING(); |
| 1632 | #endif |
| 1633 | |
| 1634 | /* Dispatch the indirect buffer full of commands from the |
| 1635 | * X server. This is insecure and is thus only available to |
| 1636 | * privileged clients. |
| 1637 | */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1638 | r128_cce_dispatch_indirect(dev, buf, indirect.start, indirect.end); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1639 | |
| 1640 | COMMIT_RING(); |
| 1641 | return 0; |
| 1642 | } |
| 1643 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1644 | static int r128_getparam(DRM_IOCTL_ARGS) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1645 | { |
| 1646 | DRM_DEVICE; |
| 1647 | drm_r128_private_t *dev_priv = dev->dev_private; |
| 1648 | drm_r128_getparam_t param; |
| 1649 | int value; |
| 1650 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1651 | if (!dev_priv) { |
| 1652 | DRM_ERROR("%s called with no initialization\n", __FUNCTION__); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1653 | return DRM_ERR(EINVAL); |
| 1654 | } |
| 1655 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1656 | DRM_COPY_FROM_USER_IOCTL(param, (drm_r128_getparam_t __user *) data, |
| 1657 | sizeof(param)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1658 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1659 | DRM_DEBUG("pid=%d\n", DRM_CURRENTPID); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1660 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1661 | switch (param.param) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1662 | case R128_PARAM_IRQ_NR: |
| 1663 | value = dev->irq; |
| 1664 | break; |
| 1665 | default: |
| 1666 | return DRM_ERR(EINVAL); |
| 1667 | } |
| 1668 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1669 | if (DRM_COPY_TO_USER(param.value, &value, sizeof(int))) { |
| 1670 | DRM_ERROR("copy_to_user\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1671 | return DRM_ERR(EFAULT); |
| 1672 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1673 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1674 | return 0; |
| 1675 | } |
| 1676 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1677 | void r128_driver_prerelease(drm_device_t * dev, DRMFILE filp) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1678 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1679 | if (dev->dev_private) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1680 | drm_r128_private_t *dev_priv = dev->dev_private; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1681 | if (dev_priv->page_flipping) { |
| 1682 | r128_do_cleanup_pageflip(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1683 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1684 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1685 | } |
| 1686 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1687 | void r128_driver_pretakedown(drm_device_t * dev) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1688 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1689 | r128_do_cleanup_cce(dev); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1690 | } |
| 1691 | |
| 1692 | drm_ioctl_desc_t r128_ioctls[] = { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1693 | [DRM_IOCTL_NR(DRM_R128_INIT)] = {r128_cce_init, 1, 1}, |
| 1694 | [DRM_IOCTL_NR(DRM_R128_CCE_START)] = {r128_cce_start, 1, 1}, |
| 1695 | [DRM_IOCTL_NR(DRM_R128_CCE_STOP)] = {r128_cce_stop, 1, 1}, |
| 1696 | [DRM_IOCTL_NR(DRM_R128_CCE_RESET)] = {r128_cce_reset, 1, 1}, |
| 1697 | [DRM_IOCTL_NR(DRM_R128_CCE_IDLE)] = {r128_cce_idle, 1, 0}, |
| 1698 | [DRM_IOCTL_NR(DRM_R128_RESET)] = {r128_engine_reset, 1, 0}, |
| 1699 | [DRM_IOCTL_NR(DRM_R128_FULLSCREEN)] = {r128_fullscreen, 1, 0}, |
| 1700 | [DRM_IOCTL_NR(DRM_R128_SWAP)] = {r128_cce_swap, 1, 0}, |
| 1701 | [DRM_IOCTL_NR(DRM_R128_FLIP)] = {r128_cce_flip, 1, 0}, |
| 1702 | [DRM_IOCTL_NR(DRM_R128_CLEAR)] = {r128_cce_clear, 1, 0}, |
| 1703 | [DRM_IOCTL_NR(DRM_R128_VERTEX)] = {r128_cce_vertex, 1, 0}, |
| 1704 | [DRM_IOCTL_NR(DRM_R128_INDICES)] = {r128_cce_indices, 1, 0}, |
| 1705 | [DRM_IOCTL_NR(DRM_R128_BLIT)] = {r128_cce_blit, 1, 0}, |
| 1706 | [DRM_IOCTL_NR(DRM_R128_DEPTH)] = {r128_cce_depth, 1, 0}, |
| 1707 | [DRM_IOCTL_NR(DRM_R128_STIPPLE)] = {r128_cce_stipple, 1, 0}, |
| 1708 | [DRM_IOCTL_NR(DRM_R128_INDIRECT)] = {r128_cce_indirect, 1, 1}, |
| 1709 | [DRM_IOCTL_NR(DRM_R128_GETPARAM)] = {r128_getparam, 1, 0}, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1710 | }; |
| 1711 | |
| 1712 | int r128_max_ioctl = DRM_ARRAY_SIZE(r128_ioctls); |