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