Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1 | /* savage_state.c -- State and drawing support for Savage |
| 2 | * |
| 3 | * Copyright 2004 Felix Kuehling |
| 4 | * All Rights Reserved. |
| 5 | * |
| 6 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 7 | * copy of this software and associated documentation files (the "Software"), |
| 8 | * to deal in the Software without restriction, including without limitation |
| 9 | * the rights to use, copy, modify, merge, publish, distribute, sub license, |
| 10 | * and/or sell copies of the Software, and to permit persons to whom the |
| 11 | * Software is furnished to do so, subject to the following conditions: |
| 12 | * |
| 13 | * The above copyright notice and this permission notice (including the |
| 14 | * next paragraph) shall be included in all copies or substantial portions |
| 15 | * of the Software. |
| 16 | * |
| 17 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, |
| 18 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF |
| 19 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND |
| 20 | * NON-INFRINGEMENT. IN NO EVENT SHALL FELIX KUEHLING BE LIABLE FOR |
| 21 | * ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF |
| 22 | * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
| 23 | * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
| 24 | */ |
Sam Ravnborg | ac0ac21 | 2019-06-05 16:03:14 +0200 | [diff] [blame] | 25 | |
| 26 | #include <linux/slab.h> |
| 27 | #include <linux/uaccess.h> |
| 28 | |
| 29 | #include <drm/drm_device.h> |
| 30 | #include <drm/drm_file.h> |
| 31 | #include <drm/drm_print.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 32 | #include <drm/savage_drm.h> |
Sam Ravnborg | ac0ac21 | 2019-06-05 16:03:14 +0200 | [diff] [blame] | 33 | |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 34 | #include "savage_drv.h" |
| 35 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 36 | void savage_emit_clip_rect_s3d(drm_savage_private_t * dev_priv, |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 37 | const struct drm_clip_rect * pbox) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 38 | { |
| 39 | uint32_t scstart = dev_priv->state.s3d.new_scstart; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 40 | uint32_t scend = dev_priv->state.s3d.new_scend; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 41 | scstart = (scstart & ~SAVAGE_SCISSOR_MASK_S3D) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 42 | ((uint32_t) pbox->x1 & 0x000007ff) | |
| 43 | (((uint32_t) pbox->y1 << 16) & 0x07ff0000); |
| 44 | scend = (scend & ~SAVAGE_SCISSOR_MASK_S3D) | |
| 45 | (((uint32_t) pbox->x2 - 1) & 0x000007ff) | |
| 46 | ((((uint32_t) pbox->y2 - 1) << 16) & 0x07ff0000); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 47 | if (scstart != dev_priv->state.s3d.scstart || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 48 | scend != dev_priv->state.s3d.scend) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 49 | DMA_LOCALS; |
| 50 | BEGIN_DMA(4); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 51 | DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 52 | DMA_SET_REGISTERS(SAVAGE_SCSTART_S3D, 2); |
| 53 | DMA_WRITE(scstart); |
| 54 | DMA_WRITE(scend); |
| 55 | dev_priv->state.s3d.scstart = scstart; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 56 | dev_priv->state.s3d.scend = scend; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 57 | dev_priv->waiting = 1; |
| 58 | DMA_COMMIT(); |
| 59 | } |
| 60 | } |
| 61 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 62 | void savage_emit_clip_rect_s4(drm_savage_private_t * dev_priv, |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 63 | const struct drm_clip_rect * pbox) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 64 | { |
| 65 | uint32_t drawctrl0 = dev_priv->state.s4.new_drawctrl0; |
| 66 | uint32_t drawctrl1 = dev_priv->state.s4.new_drawctrl1; |
| 67 | drawctrl0 = (drawctrl0 & ~SAVAGE_SCISSOR_MASK_S4) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 68 | ((uint32_t) pbox->x1 & 0x000007ff) | |
| 69 | (((uint32_t) pbox->y1 << 12) & 0x00fff000); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 70 | drawctrl1 = (drawctrl1 & ~SAVAGE_SCISSOR_MASK_S4) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 71 | (((uint32_t) pbox->x2 - 1) & 0x000007ff) | |
| 72 | ((((uint32_t) pbox->y2 - 1) << 12) & 0x00fff000); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 73 | if (drawctrl0 != dev_priv->state.s4.drawctrl0 || |
| 74 | drawctrl1 != dev_priv->state.s4.drawctrl1) { |
| 75 | DMA_LOCALS; |
| 76 | BEGIN_DMA(4); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 77 | DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 78 | DMA_SET_REGISTERS(SAVAGE_DRAWCTRL0_S4, 2); |
| 79 | DMA_WRITE(drawctrl0); |
| 80 | DMA_WRITE(drawctrl1); |
| 81 | dev_priv->state.s4.drawctrl0 = drawctrl0; |
| 82 | dev_priv->state.s4.drawctrl1 = drawctrl1; |
| 83 | dev_priv->waiting = 1; |
| 84 | DMA_COMMIT(); |
| 85 | } |
| 86 | } |
| 87 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 88 | static int savage_verify_texaddr(drm_savage_private_t * dev_priv, int unit, |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 89 | uint32_t addr) |
| 90 | { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 91 | if ((addr & 6) != 2) { /* reserved bits */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 92 | DRM_ERROR("bad texAddr%d %08x (reserved bits)\n", unit, addr); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 93 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 94 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 95 | if (!(addr & 1)) { /* local */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 96 | addr &= ~7; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 97 | if (addr < dev_priv->texture_offset || |
| 98 | addr >= dev_priv->texture_offset + dev_priv->texture_size) { |
| 99 | DRM_ERROR |
| 100 | ("bad texAddr%d %08x (local addr out of range)\n", |
| 101 | unit, addr); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 102 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 103 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 104 | } else { /* AGP */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 105 | if (!dev_priv->agp_textures) { |
| 106 | DRM_ERROR("bad texAddr%d %08x (AGP not available)\n", |
| 107 | unit, addr); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 108 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 109 | } |
| 110 | addr &= ~7; |
| 111 | if (addr < dev_priv->agp_textures->offset || |
| 112 | addr >= (dev_priv->agp_textures->offset + |
| 113 | dev_priv->agp_textures->size)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 114 | DRM_ERROR |
| 115 | ("bad texAddr%d %08x (AGP addr out of range)\n", |
| 116 | unit, addr); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 117 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 118 | } |
| 119 | } |
| 120 | return 0; |
| 121 | } |
| 122 | |
| 123 | #define SAVE_STATE(reg,where) \ |
| 124 | if(start <= reg && start+count > reg) \ |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 125 | dev_priv->state.where = regs[reg - start] |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 126 | #define SAVE_STATE_MASK(reg,where,mask) do { \ |
| 127 | if(start <= reg && start+count > reg) { \ |
| 128 | uint32_t tmp; \ |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 129 | tmp = regs[reg - start]; \ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 130 | dev_priv->state.where = (tmp & (mask)) | \ |
| 131 | (dev_priv->state.where & ~(mask)); \ |
| 132 | } \ |
| 133 | } while (0) |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 134 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 135 | static int savage_verify_state_s3d(drm_savage_private_t * dev_priv, |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 136 | unsigned int start, unsigned int count, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 137 | const uint32_t *regs) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 138 | { |
| 139 | if (start < SAVAGE_TEXPALADDR_S3D || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 140 | start + count - 1 > SAVAGE_DESTTEXRWWATERMARK_S3D) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 141 | DRM_ERROR("invalid register range (0x%04x-0x%04x)\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 142 | start, start + count - 1); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 143 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 144 | } |
| 145 | |
| 146 | SAVE_STATE_MASK(SAVAGE_SCSTART_S3D, s3d.new_scstart, |
| 147 | ~SAVAGE_SCISSOR_MASK_S3D); |
| 148 | SAVE_STATE_MASK(SAVAGE_SCEND_S3D, s3d.new_scend, |
| 149 | ~SAVAGE_SCISSOR_MASK_S3D); |
| 150 | |
| 151 | /* if any texture regs were changed ... */ |
| 152 | if (start <= SAVAGE_TEXCTRL_S3D && |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 153 | start + count > SAVAGE_TEXPALADDR_S3D) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 154 | /* ... check texture state */ |
| 155 | SAVE_STATE(SAVAGE_TEXCTRL_S3D, s3d.texctrl); |
| 156 | SAVE_STATE(SAVAGE_TEXADDR_S3D, s3d.texaddr); |
| 157 | if (dev_priv->state.s3d.texctrl & SAVAGE_TEXCTRL_TEXEN_MASK) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 158 | return savage_verify_texaddr(dev_priv, 0, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 159 | dev_priv->state.s3d.texaddr); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | return 0; |
| 163 | } |
| 164 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 165 | static int savage_verify_state_s4(drm_savage_private_t * dev_priv, |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 166 | unsigned int start, unsigned int count, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 167 | const uint32_t *regs) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 168 | { |
| 169 | int ret = 0; |
| 170 | |
| 171 | if (start < SAVAGE_DRAWLOCALCTRL_S4 || |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 172 | start + count - 1 > SAVAGE_TEXBLENDCOLOR_S4) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 173 | DRM_ERROR("invalid register range (0x%04x-0x%04x)\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 174 | start, start + count - 1); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 175 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 176 | } |
| 177 | |
| 178 | SAVE_STATE_MASK(SAVAGE_DRAWCTRL0_S4, s4.new_drawctrl0, |
| 179 | ~SAVAGE_SCISSOR_MASK_S4); |
| 180 | SAVE_STATE_MASK(SAVAGE_DRAWCTRL1_S4, s4.new_drawctrl1, |
| 181 | ~SAVAGE_SCISSOR_MASK_S4); |
| 182 | |
| 183 | /* if any texture regs were changed ... */ |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 184 | if (start <= SAVAGE_TEXDESCR_S4 && |
| 185 | start + count > SAVAGE_TEXPALADDR_S4) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 186 | /* ... check texture state */ |
| 187 | SAVE_STATE(SAVAGE_TEXDESCR_S4, s4.texdescr); |
| 188 | SAVE_STATE(SAVAGE_TEXADDR0_S4, s4.texaddr0); |
| 189 | SAVE_STATE(SAVAGE_TEXADDR1_S4, s4.texaddr1); |
| 190 | if (dev_priv->state.s4.texdescr & SAVAGE_TEXDESCR_TEX0EN_MASK) |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 191 | ret |= savage_verify_texaddr(dev_priv, 0, |
| 192 | dev_priv->state.s4.texaddr0); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 193 | if (dev_priv->state.s4.texdescr & SAVAGE_TEXDESCR_TEX1EN_MASK) |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 194 | ret |= savage_verify_texaddr(dev_priv, 1, |
| 195 | dev_priv->state.s4.texaddr1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | return ret; |
| 199 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 200 | |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 201 | #undef SAVE_STATE |
| 202 | #undef SAVE_STATE_MASK |
| 203 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 204 | static int savage_dispatch_state(drm_savage_private_t * dev_priv, |
| 205 | const drm_savage_cmd_header_t * cmd_header, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 206 | const uint32_t *regs) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 207 | { |
| 208 | unsigned int count = cmd_header->state.count; |
| 209 | unsigned int start = cmd_header->state.start; |
| 210 | unsigned int count2 = 0; |
| 211 | unsigned int bci_size; |
| 212 | int ret; |
| 213 | DMA_LOCALS; |
| 214 | |
| 215 | if (!count) |
| 216 | return 0; |
| 217 | |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 218 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
| 219 | ret = savage_verify_state_s3d(dev_priv, start, count, regs); |
| 220 | if (ret != 0) |
| 221 | return ret; |
| 222 | /* scissor regs are emitted in savage_dispatch_draw */ |
| 223 | if (start < SAVAGE_SCSTART_S3D) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 224 | if (start + count > SAVAGE_SCEND_S3D + 1) |
| 225 | count2 = count - (SAVAGE_SCEND_S3D + 1 - start); |
| 226 | if (start + count > SAVAGE_SCSTART_S3D) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 227 | count = SAVAGE_SCSTART_S3D - start; |
| 228 | } else if (start <= SAVAGE_SCEND_S3D) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 229 | if (start + count > SAVAGE_SCEND_S3D + 1) { |
| 230 | count -= SAVAGE_SCEND_S3D + 1 - start; |
| 231 | start = SAVAGE_SCEND_S3D + 1; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 232 | } else |
| 233 | return 0; |
| 234 | } |
| 235 | } else { |
| 236 | ret = savage_verify_state_s4(dev_priv, start, count, regs); |
| 237 | if (ret != 0) |
| 238 | return ret; |
| 239 | /* scissor regs are emitted in savage_dispatch_draw */ |
| 240 | if (start < SAVAGE_DRAWCTRL0_S4) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 241 | if (start + count > SAVAGE_DRAWCTRL1_S4 + 1) |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 242 | count2 = count - |
| 243 | (SAVAGE_DRAWCTRL1_S4 + 1 - start); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 244 | if (start + count > SAVAGE_DRAWCTRL0_S4) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 245 | count = SAVAGE_DRAWCTRL0_S4 - start; |
| 246 | } else if (start <= SAVAGE_DRAWCTRL1_S4) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 247 | if (start + count > SAVAGE_DRAWCTRL1_S4 + 1) { |
| 248 | count -= SAVAGE_DRAWCTRL1_S4 + 1 - start; |
| 249 | start = SAVAGE_DRAWCTRL1_S4 + 1; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 250 | } else |
| 251 | return 0; |
| 252 | } |
| 253 | } |
| 254 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 255 | bci_size = count + (count + 254) / 255 + count2 + (count2 + 254) / 255; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 256 | |
| 257 | if (cmd_header->state.global) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 258 | BEGIN_DMA(bci_size + 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 259 | DMA_WRITE(BCI_CMD_WAIT | BCI_CMD_WAIT_3D); |
| 260 | dev_priv->waiting = 1; |
| 261 | } else { |
| 262 | BEGIN_DMA(bci_size); |
| 263 | } |
| 264 | |
| 265 | do { |
| 266 | while (count > 0) { |
| 267 | unsigned int n = count < 255 ? count : 255; |
| 268 | DMA_SET_REGISTERS(start, n); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 269 | DMA_COPY(regs, n); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 270 | count -= n; |
| 271 | start += n; |
| 272 | regs += n; |
| 273 | } |
| 274 | start += 2; |
| 275 | regs += 2; |
| 276 | count = count2; |
| 277 | count2 = 0; |
| 278 | } while (count); |
| 279 | |
| 280 | DMA_COMMIT(); |
| 281 | |
| 282 | return 0; |
| 283 | } |
| 284 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 285 | static int savage_dispatch_dma_prim(drm_savage_private_t * dev_priv, |
| 286 | const drm_savage_cmd_header_t * cmd_header, |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 287 | const struct drm_buf * dmabuf) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 288 | { |
| 289 | unsigned char reorder = 0; |
| 290 | unsigned int prim = cmd_header->prim.prim; |
| 291 | unsigned int skip = cmd_header->prim.skip; |
| 292 | unsigned int n = cmd_header->prim.count; |
| 293 | unsigned int start = cmd_header->prim.start; |
| 294 | unsigned int i; |
| 295 | BCI_LOCALS; |
| 296 | |
| 297 | if (!dmabuf) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 298 | DRM_ERROR("called without dma buffers!\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 299 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 300 | } |
| 301 | |
| 302 | if (!n) |
| 303 | return 0; |
| 304 | |
| 305 | switch (prim) { |
| 306 | case SAVAGE_PRIM_TRILIST_201: |
| 307 | reorder = 1; |
| 308 | prim = SAVAGE_PRIM_TRILIST; |
Gustavo A. R. Silva | bd4d73a | 2019-01-29 14:20:06 -0600 | [diff] [blame] | 309 | /* fall through */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 310 | case SAVAGE_PRIM_TRILIST: |
| 311 | if (n % 3 != 0) { |
| 312 | DRM_ERROR("wrong number of vertices %u in TRILIST\n", |
| 313 | n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 314 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 315 | } |
| 316 | break; |
| 317 | case SAVAGE_PRIM_TRISTRIP: |
| 318 | case SAVAGE_PRIM_TRIFAN: |
| 319 | if (n < 3) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 320 | DRM_ERROR |
| 321 | ("wrong number of vertices %u in TRIFAN/STRIP\n", |
| 322 | n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 323 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 324 | } |
| 325 | break; |
| 326 | default: |
| 327 | DRM_ERROR("invalid primitive type %u\n", prim); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 328 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 329 | } |
| 330 | |
| 331 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
| 332 | if (skip != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 333 | DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 334 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 335 | } |
| 336 | } else { |
| 337 | unsigned int size = 10 - (skip & 1) - (skip >> 1 & 1) - |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 338 | (skip >> 2 & 1) - (skip >> 3 & 1) - (skip >> 4 & 1) - |
| 339 | (skip >> 5 & 1) - (skip >> 6 & 1) - (skip >> 7 & 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 340 | if (skip > SAVAGE_SKIP_ALL_S4 || size != 8) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 341 | DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 342 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 343 | } |
| 344 | if (reorder) { |
| 345 | DRM_ERROR("TRILIST_201 used on Savage4 hardware\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 346 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 347 | } |
| 348 | } |
| 349 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 350 | if (start + n > dmabuf->total / 32) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 351 | DRM_ERROR("vertex indices (%u-%u) out of range (0-%u)\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 352 | start, start + n - 1, dmabuf->total / 32); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 353 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 354 | } |
| 355 | |
| 356 | /* Vertex DMA doesn't work with command DMA at the same time, |
| 357 | * so we use BCI_... to submit commands here. Flush buffered |
| 358 | * faked DMA first. */ |
| 359 | DMA_FLUSH(); |
| 360 | |
| 361 | if (dmabuf->bus_address != dev_priv->state.common.vbaddr) { |
| 362 | BEGIN_BCI(2); |
| 363 | BCI_SET_REGISTERS(SAVAGE_VERTBUFADDR, 1); |
| 364 | BCI_WRITE(dmabuf->bus_address | dev_priv->dma_type); |
| 365 | dev_priv->state.common.vbaddr = dmabuf->bus_address; |
| 366 | } |
| 367 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset) && dev_priv->waiting) { |
| 368 | /* Workaround for what looks like a hardware bug. If a |
| 369 | * WAIT_3D_IDLE was emitted some time before the |
| 370 | * indexed drawing command then the engine will lock |
| 371 | * up. There are two known workarounds: |
| 372 | * WAIT_IDLE_EMPTY or emit at least 63 NOPs. */ |
| 373 | BEGIN_BCI(63); |
| 374 | for (i = 0; i < 63; ++i) |
| 375 | BCI_WRITE(BCI_CMD_WAIT); |
| 376 | dev_priv->waiting = 0; |
| 377 | } |
| 378 | |
| 379 | prim <<= 25; |
| 380 | while (n != 0) { |
| 381 | /* Can emit up to 255 indices (85 triangles) at once. */ |
| 382 | unsigned int count = n > 255 ? 255 : n; |
| 383 | if (reorder) { |
| 384 | /* Need to reorder indices for correct flat |
| 385 | * shading while preserving the clock sense |
| 386 | * for correct culling. Only on Savage3D. */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 387 | int reorder[3] = { -1, -1, -1 }; |
| 388 | reorder[start % 3] = 2; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 389 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 390 | BEGIN_BCI((count + 1 + 1) / 2); |
| 391 | BCI_DRAW_INDICES_S3D(count, prim, start + 2); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 392 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 393 | for (i = start + 1; i + 1 < start + count; i += 2) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 394 | BCI_WRITE((i + reorder[i % 3]) | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 395 | ((i + 1 + |
| 396 | reorder[(i + 1) % 3]) << 16)); |
| 397 | if (i < start + count) |
| 398 | BCI_WRITE(i + reorder[i % 3]); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 399 | } else if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 400 | BEGIN_BCI((count + 1 + 1) / 2); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 401 | BCI_DRAW_INDICES_S3D(count, prim, start); |
| 402 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 403 | for (i = start + 1; i + 1 < start + count; i += 2) |
| 404 | BCI_WRITE(i | ((i + 1) << 16)); |
| 405 | if (i < start + count) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 406 | BCI_WRITE(i); |
| 407 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 408 | BEGIN_BCI((count + 2 + 1) / 2); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 409 | BCI_DRAW_INDICES_S4(count, prim, skip); |
| 410 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 411 | for (i = start; i + 1 < start + count; i += 2) |
| 412 | BCI_WRITE(i | ((i + 1) << 16)); |
| 413 | if (i < start + count) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 414 | BCI_WRITE(i); |
| 415 | } |
| 416 | |
| 417 | start += count; |
| 418 | n -= count; |
| 419 | |
| 420 | prim |= BCI_CMD_DRAW_CONT; |
| 421 | } |
| 422 | |
| 423 | return 0; |
| 424 | } |
| 425 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 426 | static int savage_dispatch_vb_prim(drm_savage_private_t * dev_priv, |
| 427 | const drm_savage_cmd_header_t * cmd_header, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 428 | const uint32_t *vtxbuf, unsigned int vb_size, |
| 429 | unsigned int vb_stride) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 430 | { |
| 431 | unsigned char reorder = 0; |
| 432 | unsigned int prim = cmd_header->prim.prim; |
| 433 | unsigned int skip = cmd_header->prim.skip; |
| 434 | unsigned int n = cmd_header->prim.count; |
| 435 | unsigned int start = cmd_header->prim.start; |
| 436 | unsigned int vtx_size; |
| 437 | unsigned int i; |
| 438 | DMA_LOCALS; |
| 439 | |
| 440 | if (!n) |
| 441 | return 0; |
| 442 | |
| 443 | switch (prim) { |
| 444 | case SAVAGE_PRIM_TRILIST_201: |
| 445 | reorder = 1; |
| 446 | prim = SAVAGE_PRIM_TRILIST; |
Gustavo A. R. Silva | bd4d73a | 2019-01-29 14:20:06 -0600 | [diff] [blame] | 447 | /* fall through */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 448 | case SAVAGE_PRIM_TRILIST: |
| 449 | if (n % 3 != 0) { |
| 450 | DRM_ERROR("wrong number of vertices %u in TRILIST\n", |
| 451 | n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 452 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 453 | } |
| 454 | break; |
| 455 | case SAVAGE_PRIM_TRISTRIP: |
| 456 | case SAVAGE_PRIM_TRIFAN: |
| 457 | if (n < 3) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 458 | DRM_ERROR |
| 459 | ("wrong number of vertices %u in TRIFAN/STRIP\n", |
| 460 | n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 461 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 462 | } |
| 463 | break; |
| 464 | default: |
| 465 | DRM_ERROR("invalid primitive type %u\n", prim); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 466 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 467 | } |
| 468 | |
| 469 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
| 470 | if (skip > SAVAGE_SKIP_ALL_S3D) { |
| 471 | DRM_ERROR("invalid skip flags 0x%04x\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 472 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 473 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 474 | vtx_size = 8; /* full vertex */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 475 | } else { |
| 476 | if (skip > SAVAGE_SKIP_ALL_S4) { |
| 477 | DRM_ERROR("invalid skip flags 0x%04x\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 478 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 479 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 480 | vtx_size = 10; /* full vertex */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 481 | } |
| 482 | |
| 483 | vtx_size -= (skip & 1) + (skip >> 1 & 1) + |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 484 | (skip >> 2 & 1) + (skip >> 3 & 1) + (skip >> 4 & 1) + |
| 485 | (skip >> 5 & 1) + (skip >> 6 & 1) + (skip >> 7 & 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 486 | |
| 487 | if (vtx_size > vb_stride) { |
| 488 | DRM_ERROR("vertex size greater than vb stride (%u > %u)\n", |
| 489 | vtx_size, vb_stride); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 490 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 491 | } |
| 492 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 493 | if (start + n > vb_size / (vb_stride * 4)) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 494 | DRM_ERROR("vertex indices (%u-%u) out of range (0-%u)\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 495 | start, start + n - 1, vb_size / (vb_stride * 4)); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 496 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 497 | } |
| 498 | |
| 499 | prim <<= 25; |
| 500 | while (n != 0) { |
| 501 | /* Can emit up to 255 vertices (85 triangles) at once. */ |
| 502 | unsigned int count = n > 255 ? 255 : n; |
| 503 | if (reorder) { |
| 504 | /* Need to reorder vertices for correct flat |
| 505 | * shading while preserving the clock sense |
| 506 | * for correct culling. Only on Savage3D. */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 507 | int reorder[3] = { -1, -1, -1 }; |
| 508 | reorder[start % 3] = 2; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 509 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 510 | BEGIN_DMA(count * vtx_size + 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 511 | DMA_DRAW_PRIMITIVE(count, prim, skip); |
| 512 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 513 | for (i = start; i < start + count; ++i) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 514 | unsigned int j = i + reorder[i % 3]; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 515 | DMA_COPY(&vtxbuf[vb_stride * j], vtx_size); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 516 | } |
| 517 | |
| 518 | DMA_COMMIT(); |
| 519 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 520 | BEGIN_DMA(count * vtx_size + 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 521 | DMA_DRAW_PRIMITIVE(count, prim, skip); |
| 522 | |
| 523 | if (vb_stride == vtx_size) { |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 524 | DMA_COPY(&vtxbuf[vb_stride * start], |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 525 | vtx_size * count); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 526 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 527 | for (i = start; i < start + count; ++i) { |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 528 | DMA_COPY(&vtxbuf [vb_stride * i], |
| 529 | vtx_size); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 530 | } |
| 531 | } |
| 532 | |
| 533 | DMA_COMMIT(); |
| 534 | } |
| 535 | |
| 536 | start += count; |
| 537 | n -= count; |
| 538 | |
| 539 | prim |= BCI_CMD_DRAW_CONT; |
| 540 | } |
| 541 | |
| 542 | return 0; |
| 543 | } |
| 544 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 545 | static int savage_dispatch_dma_idx(drm_savage_private_t * dev_priv, |
| 546 | const drm_savage_cmd_header_t * cmd_header, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 547 | const uint16_t *idx, |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 548 | const struct drm_buf * dmabuf) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 549 | { |
| 550 | unsigned char reorder = 0; |
| 551 | unsigned int prim = cmd_header->idx.prim; |
| 552 | unsigned int skip = cmd_header->idx.skip; |
| 553 | unsigned int n = cmd_header->idx.count; |
| 554 | unsigned int i; |
| 555 | BCI_LOCALS; |
| 556 | |
| 557 | if (!dmabuf) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 558 | DRM_ERROR("called without dma buffers!\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 559 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 560 | } |
| 561 | |
| 562 | if (!n) |
| 563 | return 0; |
| 564 | |
| 565 | switch (prim) { |
| 566 | case SAVAGE_PRIM_TRILIST_201: |
| 567 | reorder = 1; |
| 568 | prim = SAVAGE_PRIM_TRILIST; |
Gustavo A. R. Silva | bd4d73a | 2019-01-29 14:20:06 -0600 | [diff] [blame] | 569 | /* fall through */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 570 | case SAVAGE_PRIM_TRILIST: |
| 571 | if (n % 3 != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 572 | DRM_ERROR("wrong number of indices %u in TRILIST\n", n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 573 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 574 | } |
| 575 | break; |
| 576 | case SAVAGE_PRIM_TRISTRIP: |
| 577 | case SAVAGE_PRIM_TRIFAN: |
| 578 | if (n < 3) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 579 | DRM_ERROR |
| 580 | ("wrong number of indices %u in TRIFAN/STRIP\n", n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 581 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 582 | } |
| 583 | break; |
| 584 | default: |
| 585 | DRM_ERROR("invalid primitive type %u\n", prim); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 586 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 587 | } |
| 588 | |
| 589 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
| 590 | if (skip != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 591 | DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 592 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 593 | } |
| 594 | } else { |
| 595 | unsigned int size = 10 - (skip & 1) - (skip >> 1 & 1) - |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 596 | (skip >> 2 & 1) - (skip >> 3 & 1) - (skip >> 4 & 1) - |
| 597 | (skip >> 5 & 1) - (skip >> 6 & 1) - (skip >> 7 & 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 598 | if (skip > SAVAGE_SKIP_ALL_S4 || size != 8) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 599 | DRM_ERROR("invalid skip flags 0x%04x for DMA\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 600 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 601 | } |
| 602 | if (reorder) { |
| 603 | DRM_ERROR("TRILIST_201 used on Savage4 hardware\n"); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 604 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 605 | } |
| 606 | } |
| 607 | |
| 608 | /* Vertex DMA doesn't work with command DMA at the same time, |
| 609 | * so we use BCI_... to submit commands here. Flush buffered |
| 610 | * faked DMA first. */ |
| 611 | DMA_FLUSH(); |
| 612 | |
| 613 | if (dmabuf->bus_address != dev_priv->state.common.vbaddr) { |
| 614 | BEGIN_BCI(2); |
| 615 | BCI_SET_REGISTERS(SAVAGE_VERTBUFADDR, 1); |
| 616 | BCI_WRITE(dmabuf->bus_address | dev_priv->dma_type); |
| 617 | dev_priv->state.common.vbaddr = dmabuf->bus_address; |
| 618 | } |
| 619 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset) && dev_priv->waiting) { |
| 620 | /* Workaround for what looks like a hardware bug. If a |
| 621 | * WAIT_3D_IDLE was emitted some time before the |
| 622 | * indexed drawing command then the engine will lock |
| 623 | * up. There are two known workarounds: |
| 624 | * WAIT_IDLE_EMPTY or emit at least 63 NOPs. */ |
| 625 | BEGIN_BCI(63); |
| 626 | for (i = 0; i < 63; ++i) |
| 627 | BCI_WRITE(BCI_CMD_WAIT); |
| 628 | dev_priv->waiting = 0; |
| 629 | } |
| 630 | |
| 631 | prim <<= 25; |
| 632 | while (n != 0) { |
| 633 | /* Can emit up to 255 indices (85 triangles) at once. */ |
| 634 | unsigned int count = n > 255 ? 255 : n; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 635 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 636 | /* check indices */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 637 | for (i = 0; i < count; ++i) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 638 | if (idx[i] > dmabuf->total / 32) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 639 | DRM_ERROR("idx[%u]=%u out of range (0-%u)\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 640 | i, idx[i], dmabuf->total / 32); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 641 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 642 | } |
| 643 | } |
| 644 | |
| 645 | if (reorder) { |
| 646 | /* Need to reorder indices for correct flat |
| 647 | * shading while preserving the clock sense |
| 648 | * for correct culling. Only on Savage3D. */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 649 | int reorder[3] = { 2, -1, -1 }; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 650 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 651 | BEGIN_BCI((count + 1 + 1) / 2); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 652 | BCI_DRAW_INDICES_S3D(count, prim, idx[2]); |
| 653 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 654 | for (i = 1; i + 1 < count; i += 2) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 655 | BCI_WRITE(idx[i + reorder[i % 3]] | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 656 | (idx[i + 1 + |
| 657 | reorder[(i + 1) % 3]] << 16)); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 658 | if (i < count) |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 659 | BCI_WRITE(idx[i + reorder[i % 3]]); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 660 | } else if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 661 | BEGIN_BCI((count + 1 + 1) / 2); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 662 | BCI_DRAW_INDICES_S3D(count, prim, idx[0]); |
| 663 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 664 | for (i = 1; i + 1 < count; i += 2) |
| 665 | BCI_WRITE(idx[i] | (idx[i + 1] << 16)); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 666 | if (i < count) |
| 667 | BCI_WRITE(idx[i]); |
| 668 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 669 | BEGIN_BCI((count + 2 + 1) / 2); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 670 | BCI_DRAW_INDICES_S4(count, prim, skip); |
| 671 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 672 | for (i = 0; i + 1 < count; i += 2) |
| 673 | BCI_WRITE(idx[i] | (idx[i + 1] << 16)); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 674 | if (i < count) |
| 675 | BCI_WRITE(idx[i]); |
| 676 | } |
| 677 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 678 | idx += count; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 679 | n -= count; |
| 680 | |
| 681 | prim |= BCI_CMD_DRAW_CONT; |
| 682 | } |
| 683 | |
| 684 | return 0; |
| 685 | } |
| 686 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 687 | static int savage_dispatch_vb_idx(drm_savage_private_t * dev_priv, |
| 688 | const drm_savage_cmd_header_t * cmd_header, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 689 | const uint16_t *idx, |
| 690 | const uint32_t *vtxbuf, |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 691 | unsigned int vb_size, unsigned int vb_stride) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 692 | { |
| 693 | unsigned char reorder = 0; |
| 694 | unsigned int prim = cmd_header->idx.prim; |
| 695 | unsigned int skip = cmd_header->idx.skip; |
| 696 | unsigned int n = cmd_header->idx.count; |
| 697 | unsigned int vtx_size; |
| 698 | unsigned int i; |
| 699 | DMA_LOCALS; |
| 700 | |
| 701 | if (!n) |
| 702 | return 0; |
| 703 | |
| 704 | switch (prim) { |
| 705 | case SAVAGE_PRIM_TRILIST_201: |
| 706 | reorder = 1; |
| 707 | prim = SAVAGE_PRIM_TRILIST; |
Gustavo A. R. Silva | bd4d73a | 2019-01-29 14:20:06 -0600 | [diff] [blame] | 708 | /* fall through */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 709 | case SAVAGE_PRIM_TRILIST: |
| 710 | if (n % 3 != 0) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 711 | DRM_ERROR("wrong number of indices %u in TRILIST\n", n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 712 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 713 | } |
| 714 | break; |
| 715 | case SAVAGE_PRIM_TRISTRIP: |
| 716 | case SAVAGE_PRIM_TRIFAN: |
| 717 | if (n < 3) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 718 | DRM_ERROR |
| 719 | ("wrong number of indices %u in TRIFAN/STRIP\n", n); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 720 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 721 | } |
| 722 | break; |
| 723 | default: |
| 724 | DRM_ERROR("invalid primitive type %u\n", prim); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 725 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 726 | } |
| 727 | |
| 728 | if (S3_SAVAGE3D_SERIES(dev_priv->chipset)) { |
| 729 | if (skip > SAVAGE_SKIP_ALL_S3D) { |
| 730 | DRM_ERROR("invalid skip flags 0x%04x\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 731 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 732 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 733 | vtx_size = 8; /* full vertex */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 734 | } else { |
| 735 | if (skip > SAVAGE_SKIP_ALL_S4) { |
| 736 | DRM_ERROR("invalid skip flags 0x%04x\n", skip); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 737 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 738 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 739 | vtx_size = 10; /* full vertex */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 740 | } |
| 741 | |
| 742 | vtx_size -= (skip & 1) + (skip >> 1 & 1) + |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 743 | (skip >> 2 & 1) + (skip >> 3 & 1) + (skip >> 4 & 1) + |
| 744 | (skip >> 5 & 1) + (skip >> 6 & 1) + (skip >> 7 & 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 745 | |
| 746 | if (vtx_size > vb_stride) { |
| 747 | DRM_ERROR("vertex size greater than vb stride (%u > %u)\n", |
| 748 | vtx_size, vb_stride); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 749 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 750 | } |
| 751 | |
| 752 | prim <<= 25; |
| 753 | while (n != 0) { |
| 754 | /* Can emit up to 255 vertices (85 triangles) at once. */ |
| 755 | unsigned int count = n > 255 ? 255 : n; |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 756 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 757 | /* Check indices */ |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 758 | for (i = 0; i < count; ++i) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 759 | if (idx[i] > vb_size / (vb_stride * 4)) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 760 | DRM_ERROR("idx[%u]=%u out of range (0-%u)\n", |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 761 | i, idx[i], vb_size / (vb_stride * 4)); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 762 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 763 | } |
| 764 | } |
| 765 | |
| 766 | if (reorder) { |
| 767 | /* Need to reorder vertices for correct flat |
| 768 | * shading while preserving the clock sense |
| 769 | * for correct culling. Only on Savage3D. */ |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 770 | int reorder[3] = { 2, -1, -1 }; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 771 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 772 | BEGIN_DMA(count * vtx_size + 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 773 | DMA_DRAW_PRIMITIVE(count, prim, skip); |
| 774 | |
| 775 | for (i = 0; i < count; ++i) { |
| 776 | unsigned int j = idx[i + reorder[i % 3]]; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 777 | DMA_COPY(&vtxbuf[vb_stride * j], vtx_size); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 778 | } |
| 779 | |
| 780 | DMA_COMMIT(); |
| 781 | } else { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 782 | BEGIN_DMA(count * vtx_size + 1); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 783 | DMA_DRAW_PRIMITIVE(count, prim, skip); |
| 784 | |
| 785 | for (i = 0; i < count; ++i) { |
| 786 | unsigned int j = idx[i]; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 787 | DMA_COPY(&vtxbuf[vb_stride * j], vtx_size); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 788 | } |
| 789 | |
| 790 | DMA_COMMIT(); |
| 791 | } |
| 792 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 793 | idx += count; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 794 | n -= count; |
| 795 | |
| 796 | prim |= BCI_CMD_DRAW_CONT; |
| 797 | } |
| 798 | |
| 799 | return 0; |
| 800 | } |
| 801 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 802 | static int savage_dispatch_clear(drm_savage_private_t * dev_priv, |
| 803 | const drm_savage_cmd_header_t * cmd_header, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 804 | const drm_savage_cmd_header_t *data, |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 805 | unsigned int nbox, |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 806 | const struct drm_clip_rect *boxes) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 807 | { |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 808 | unsigned int flags = cmd_header->clear0.flags; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 809 | unsigned int clear_cmd; |
| 810 | unsigned int i, nbufs; |
| 811 | DMA_LOCALS; |
| 812 | |
| 813 | if (nbox == 0) |
| 814 | return 0; |
| 815 | |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 816 | clear_cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 817 | BCI_CMD_SEND_COLOR | BCI_CMD_DEST_PBD_NEW; |
| 818 | BCI_CMD_SET_ROP(clear_cmd, 0xCC); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 819 | |
| 820 | nbufs = ((flags & SAVAGE_FRONT) ? 1 : 0) + |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 821 | ((flags & SAVAGE_BACK) ? 1 : 0) + ((flags & SAVAGE_DEPTH) ? 1 : 0); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 822 | if (nbufs == 0) |
| 823 | return 0; |
| 824 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 825 | if (data->clear1.mask != 0xffffffff) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 826 | /* set mask */ |
| 827 | BEGIN_DMA(2); |
| 828 | DMA_SET_REGISTERS(SAVAGE_BITPLANEWTMASK, 1); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 829 | DMA_WRITE(data->clear1.mask); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 830 | DMA_COMMIT(); |
| 831 | } |
| 832 | for (i = 0; i < nbox; ++i) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 833 | unsigned int x, y, w, h; |
| 834 | unsigned int buf; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 835 | x = boxes[i].x1, y = boxes[i].y1; |
| 836 | w = boxes[i].x2 - boxes[i].x1; |
| 837 | h = boxes[i].y2 - boxes[i].y1; |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 838 | BEGIN_DMA(nbufs * 6); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 839 | for (buf = SAVAGE_FRONT; buf <= SAVAGE_DEPTH; buf <<= 1) { |
| 840 | if (!(flags & buf)) |
| 841 | continue; |
| 842 | DMA_WRITE(clear_cmd); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 843 | switch (buf) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 844 | case SAVAGE_FRONT: |
| 845 | DMA_WRITE(dev_priv->front_offset); |
| 846 | DMA_WRITE(dev_priv->front_bd); |
| 847 | break; |
| 848 | case SAVAGE_BACK: |
| 849 | DMA_WRITE(dev_priv->back_offset); |
| 850 | DMA_WRITE(dev_priv->back_bd); |
| 851 | break; |
| 852 | case SAVAGE_DEPTH: |
| 853 | DMA_WRITE(dev_priv->depth_offset); |
| 854 | DMA_WRITE(dev_priv->depth_bd); |
| 855 | break; |
| 856 | } |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 857 | DMA_WRITE(data->clear1.value); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 858 | DMA_WRITE(BCI_X_Y(x, y)); |
| 859 | DMA_WRITE(BCI_W_H(w, h)); |
| 860 | } |
| 861 | DMA_COMMIT(); |
| 862 | } |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 863 | if (data->clear1.mask != 0xffffffff) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 864 | /* reset mask */ |
| 865 | BEGIN_DMA(2); |
| 866 | DMA_SET_REGISTERS(SAVAGE_BITPLANEWTMASK, 1); |
| 867 | DMA_WRITE(0xffffffff); |
| 868 | DMA_COMMIT(); |
| 869 | } |
| 870 | |
| 871 | return 0; |
| 872 | } |
| 873 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 874 | static int savage_dispatch_swap(drm_savage_private_t * dev_priv, |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 875 | unsigned int nbox, const struct drm_clip_rect *boxes) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 876 | { |
| 877 | unsigned int swap_cmd; |
| 878 | unsigned int i; |
| 879 | DMA_LOCALS; |
| 880 | |
| 881 | if (nbox == 0) |
| 882 | return 0; |
| 883 | |
| 884 | swap_cmd = BCI_CMD_RECT | BCI_CMD_RECT_XP | BCI_CMD_RECT_YP | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 885 | BCI_CMD_SRC_PBD_COLOR_NEW | BCI_CMD_DEST_GBD; |
| 886 | BCI_CMD_SET_ROP(swap_cmd, 0xCC); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 887 | |
| 888 | for (i = 0; i < nbox; ++i) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 889 | BEGIN_DMA(6); |
| 890 | DMA_WRITE(swap_cmd); |
| 891 | DMA_WRITE(dev_priv->back_offset); |
| 892 | DMA_WRITE(dev_priv->back_bd); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 893 | DMA_WRITE(BCI_X_Y(boxes[i].x1, boxes[i].y1)); |
| 894 | DMA_WRITE(BCI_X_Y(boxes[i].x1, boxes[i].y1)); |
| 895 | DMA_WRITE(BCI_W_H(boxes[i].x2 - boxes[i].x1, |
| 896 | boxes[i].y2 - boxes[i].y1)); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 897 | DMA_COMMIT(); |
| 898 | } |
| 899 | |
| 900 | return 0; |
| 901 | } |
| 902 | |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 903 | static int savage_dispatch_draw(drm_savage_private_t * dev_priv, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 904 | const drm_savage_cmd_header_t *start, |
| 905 | const drm_savage_cmd_header_t *end, |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 906 | const struct drm_buf * dmabuf, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 907 | const unsigned int *vtxbuf, |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 908 | unsigned int vb_size, unsigned int vb_stride, |
| 909 | unsigned int nbox, |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 910 | const struct drm_clip_rect *boxes) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 911 | { |
| 912 | unsigned int i, j; |
| 913 | int ret; |
| 914 | |
| 915 | for (i = 0; i < nbox; ++i) { |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 916 | const drm_savage_cmd_header_t *cmdbuf; |
| 917 | dev_priv->emit_clip_rect(dev_priv, &boxes[i]); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 918 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 919 | cmdbuf = start; |
| 920 | while (cmdbuf < end) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 921 | drm_savage_cmd_header_t cmd_header; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 922 | cmd_header = *cmdbuf; |
| 923 | cmdbuf++; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 924 | switch (cmd_header.cmd.cmd) { |
| 925 | case SAVAGE_CMD_DMA_PRIM: |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 926 | ret = savage_dispatch_dma_prim( |
| 927 | dev_priv, &cmd_header, dmabuf); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 928 | break; |
| 929 | case SAVAGE_CMD_VB_PRIM: |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 930 | ret = savage_dispatch_vb_prim( |
| 931 | dev_priv, &cmd_header, |
| 932 | vtxbuf, vb_size, vb_stride); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 933 | break; |
| 934 | case SAVAGE_CMD_DMA_IDX: |
| 935 | j = (cmd_header.idx.count + 3) / 4; |
| 936 | /* j was check in savage_bci_cmdbuf */ |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 937 | ret = savage_dispatch_dma_idx(dev_priv, |
| 938 | &cmd_header, (const uint16_t *)cmdbuf, |
| 939 | dmabuf); |
| 940 | cmdbuf += j; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 941 | break; |
| 942 | case SAVAGE_CMD_VB_IDX: |
| 943 | j = (cmd_header.idx.count + 3) / 4; |
| 944 | /* j was check in savage_bci_cmdbuf */ |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 945 | ret = savage_dispatch_vb_idx(dev_priv, |
| 946 | &cmd_header, (const uint16_t *)cmdbuf, |
Dave Airlie | bc5f452 | 2007-11-05 12:50:58 +1000 | [diff] [blame] | 947 | (const uint32_t *)vtxbuf, vb_size, |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 948 | vb_stride); |
| 949 | cmdbuf += j; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 950 | break; |
| 951 | default: |
| 952 | /* What's the best return code? EFAULT? */ |
| 953 | DRM_ERROR("IMPLEMENTATION ERROR: " |
| 954 | "non-drawing-command %d\n", |
| 955 | cmd_header.cmd.cmd); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 956 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 957 | } |
| 958 | |
| 959 | if (ret != 0) |
| 960 | return ret; |
| 961 | } |
| 962 | } |
| 963 | |
| 964 | return 0; |
| 965 | } |
| 966 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 967 | int savage_bci_cmdbuf(struct drm_device *dev, void *data, struct drm_file *file_priv) |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 968 | { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 969 | drm_savage_private_t *dev_priv = dev->dev_private; |
Dave Airlie | cdd55a2 | 2007-07-11 16:32:08 +1000 | [diff] [blame] | 970 | struct drm_device_dma *dma = dev->dma; |
Dave Airlie | 056219e | 2007-07-11 16:17:42 +1000 | [diff] [blame] | 971 | struct drm_buf *dmabuf; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 972 | drm_savage_cmdbuf_t *cmdbuf = data; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 973 | drm_savage_cmd_header_t *kcmd_addr = NULL; |
| 974 | drm_savage_cmd_header_t *first_draw_cmd; |
| 975 | unsigned int *kvb_addr = NULL; |
Dave Airlie | eddca55 | 2007-07-11 16:09:54 +1000 | [diff] [blame] | 976 | struct drm_clip_rect *kbox_addr = NULL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 977 | unsigned int i, j; |
| 978 | int ret = 0; |
| 979 | |
| 980 | DRM_DEBUG("\n"); |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 981 | |
Eric Anholt | 6c340ea | 2007-08-25 20:23:09 +1000 | [diff] [blame] | 982 | LOCK_TEST_WITH_RETURN(dev, file_priv); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 983 | |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 984 | if (dma && dma->buflist) { |
Dan Carpenter | 968d72e | 2018-07-04 12:48:10 +0300 | [diff] [blame] | 985 | if (cmdbuf->dma_idx >= dma->buf_count) { |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 986 | DRM_ERROR |
| 987 | ("vertex buffer index %u out of range (0-%u)\n", |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 988 | cmdbuf->dma_idx, dma->buf_count - 1); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 989 | return -EINVAL; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 990 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 991 | dmabuf = dma->buflist[cmdbuf->dma_idx]; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 992 | } else { |
| 993 | dmabuf = NULL; |
| 994 | } |
| 995 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 996 | /* Copy the user buffers into kernel temporary areas. This hasn't been |
| 997 | * a performance loss compared to VERIFYAREA_READ/ |
| 998 | * COPY_FROM_USER_UNCHECKED when done in other drivers, and is correct |
| 999 | * for locking on FreeBSD. |
| 1000 | */ |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1001 | if (cmdbuf->size) { |
Xi Wang | 6587eb8 | 2012-04-06 17:38:24 -0400 | [diff] [blame] | 1002 | kcmd_addr = kmalloc_array(cmdbuf->size, 8, GFP_KERNEL); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1003 | if (kcmd_addr == NULL) |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1004 | return -ENOMEM; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1005 | |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 1006 | if (copy_from_user(kcmd_addr, cmdbuf->cmd_addr, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1007 | cmdbuf->size * 8)) |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1008 | { |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1009 | kfree(kcmd_addr); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1010 | return -EFAULT; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1011 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1012 | cmdbuf->cmd_addr = kcmd_addr; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1013 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1014 | if (cmdbuf->vb_size) { |
Markus Elfring | a6e3918 | 2016-08-18 18:12:03 +0200 | [diff] [blame] | 1015 | kvb_addr = memdup_user(cmdbuf->vb_addr, cmdbuf->vb_size); |
| 1016 | if (IS_ERR(kvb_addr)) { |
| 1017 | ret = PTR_ERR(kvb_addr); |
Dan Carpenter | f7741aa | 2016-10-12 09:22:27 +0300 | [diff] [blame] | 1018 | kvb_addr = NULL; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1019 | goto done; |
| 1020 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1021 | cmdbuf->vb_addr = kvb_addr; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1022 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1023 | if (cmdbuf->nbox) { |
Xi Wang | 6587eb8 | 2012-04-06 17:38:24 -0400 | [diff] [blame] | 1024 | kbox_addr = kmalloc_array(cmdbuf->nbox, sizeof(struct drm_clip_rect), |
| 1025 | GFP_KERNEL); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1026 | if (kbox_addr == NULL) { |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1027 | ret = -ENOMEM; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1028 | goto done; |
| 1029 | } |
| 1030 | |
Daniel Vetter | 1d6ac18 | 2013-12-11 11:34:44 +0100 | [diff] [blame] | 1031 | if (copy_from_user(kbox_addr, cmdbuf->box_addr, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1032 | cmdbuf->nbox * sizeof(struct drm_clip_rect))) { |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1033 | ret = -EFAULT; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1034 | goto done; |
| 1035 | } |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1036 | cmdbuf->box_addr = kbox_addr; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1037 | } |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1038 | |
| 1039 | /* Make sure writes to DMA buffers are finished before sending |
| 1040 | * DMA commands to the graphics hardware. */ |
Daniel Vetter | 85b2331 | 2013-12-11 11:34:45 +0100 | [diff] [blame] | 1041 | mb(); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1042 | |
| 1043 | /* Coming from user space. Don't know if the Xserver has |
| 1044 | * emitted wait commands. Assuming the worst. */ |
| 1045 | dev_priv->waiting = 1; |
| 1046 | |
| 1047 | i = 0; |
| 1048 | first_draw_cmd = NULL; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1049 | while (i < cmdbuf->size) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1050 | drm_savage_cmd_header_t cmd_header; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1051 | cmd_header = *(drm_savage_cmd_header_t *)cmdbuf->cmd_addr; |
| 1052 | cmdbuf->cmd_addr++; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1053 | i++; |
| 1054 | |
| 1055 | /* Group drawing commands with same state to minimize |
| 1056 | * iterations over clip rects. */ |
| 1057 | j = 0; |
| 1058 | switch (cmd_header.cmd.cmd) { |
| 1059 | case SAVAGE_CMD_DMA_IDX: |
| 1060 | case SAVAGE_CMD_VB_IDX: |
| 1061 | j = (cmd_header.idx.count + 3) / 4; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1062 | if (i + j > cmdbuf->size) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1063 | DRM_ERROR("indexed drawing command extends " |
| 1064 | "beyond end of command buffer\n"); |
| 1065 | DMA_FLUSH(); |
Julia Lawall | f104876 | 2012-03-17 18:57:02 +0100 | [diff] [blame] | 1066 | ret = -EINVAL; |
| 1067 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1068 | } |
| 1069 | /* fall through */ |
| 1070 | case SAVAGE_CMD_DMA_PRIM: |
| 1071 | case SAVAGE_CMD_VB_PRIM: |
| 1072 | if (!first_draw_cmd) |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1073 | first_draw_cmd = cmdbuf->cmd_addr - 1; |
| 1074 | cmdbuf->cmd_addr += j; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1075 | i += j; |
| 1076 | break; |
| 1077 | default: |
| 1078 | if (first_draw_cmd) { |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1079 | ret = savage_dispatch_draw( |
| 1080 | dev_priv, first_draw_cmd, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1081 | cmdbuf->cmd_addr - 1, |
| 1082 | dmabuf, cmdbuf->vb_addr, cmdbuf->vb_size, |
| 1083 | cmdbuf->vb_stride, |
| 1084 | cmdbuf->nbox, cmdbuf->box_addr); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1085 | if (ret != 0) |
Julia Lawall | f104876 | 2012-03-17 18:57:02 +0100 | [diff] [blame] | 1086 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1087 | first_draw_cmd = NULL; |
| 1088 | } |
| 1089 | } |
| 1090 | if (first_draw_cmd) |
| 1091 | continue; |
| 1092 | |
| 1093 | switch (cmd_header.cmd.cmd) { |
| 1094 | case SAVAGE_CMD_STATE: |
| 1095 | j = (cmd_header.state.count + 1) / 2; |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1096 | if (i + j > cmdbuf->size) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1097 | DRM_ERROR("command SAVAGE_CMD_STATE extends " |
| 1098 | "beyond end of command buffer\n"); |
| 1099 | DMA_FLUSH(); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1100 | ret = -EINVAL; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1101 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1102 | } |
Dave Airlie | b5e89ed | 2005-09-25 14:28:13 +1000 | [diff] [blame] | 1103 | ret = savage_dispatch_state(dev_priv, &cmd_header, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1104 | (const uint32_t *)cmdbuf->cmd_addr); |
| 1105 | cmdbuf->cmd_addr += j; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1106 | i += j; |
| 1107 | break; |
| 1108 | case SAVAGE_CMD_CLEAR: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1109 | if (i + 1 > cmdbuf->size) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1110 | DRM_ERROR("command SAVAGE_CMD_CLEAR extends " |
| 1111 | "beyond end of command buffer\n"); |
| 1112 | DMA_FLUSH(); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1113 | ret = -EINVAL; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1114 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1115 | } |
| 1116 | ret = savage_dispatch_clear(dev_priv, &cmd_header, |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1117 | cmdbuf->cmd_addr, |
| 1118 | cmdbuf->nbox, |
| 1119 | cmdbuf->box_addr); |
| 1120 | cmdbuf->cmd_addr++; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1121 | i++; |
| 1122 | break; |
| 1123 | case SAVAGE_CMD_SWAP: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1124 | ret = savage_dispatch_swap(dev_priv, cmdbuf->nbox, |
| 1125 | cmdbuf->box_addr); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1126 | break; |
| 1127 | default: |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1128 | DRM_ERROR("invalid command 0x%x\n", |
| 1129 | cmd_header.cmd.cmd); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1130 | DMA_FLUSH(); |
Eric Anholt | 20caafa | 2007-08-25 19:22:43 +1000 | [diff] [blame] | 1131 | ret = -EINVAL; |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1132 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1133 | } |
| 1134 | |
| 1135 | if (ret != 0) { |
| 1136 | DMA_FLUSH(); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1137 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1138 | } |
| 1139 | } |
| 1140 | |
| 1141 | if (first_draw_cmd) { |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1142 | ret = savage_dispatch_draw ( |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1143 | dev_priv, first_draw_cmd, cmdbuf->cmd_addr, dmabuf, |
| 1144 | cmdbuf->vb_addr, cmdbuf->vb_size, cmdbuf->vb_stride, |
| 1145 | cmdbuf->nbox, cmdbuf->box_addr); |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1146 | if (ret != 0) { |
| 1147 | DMA_FLUSH(); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1148 | goto done; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1149 | } |
| 1150 | } |
| 1151 | |
| 1152 | DMA_FLUSH(); |
| 1153 | |
Eric Anholt | c153f45 | 2007-09-03 12:06:45 +1000 | [diff] [blame] | 1154 | if (dmabuf && cmdbuf->discard) { |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1155 | drm_savage_buf_priv_t *buf_priv = dmabuf->dev_private; |
| 1156 | uint16_t event; |
| 1157 | event = savage_bci_emit_event(dev_priv, SAVAGE_WAIT_3D); |
| 1158 | SET_AGE(&buf_priv->age, event, dev_priv->event_wrap); |
| 1159 | savage_freelist_put(dev, dmabuf); |
| 1160 | } |
| 1161 | |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1162 | done: |
| 1163 | /* If we didn't need to allocate them, these'll be NULL */ |
Eric Anholt | 9a298b2 | 2009-03-24 12:23:04 -0700 | [diff] [blame] | 1164 | kfree(kcmd_addr); |
| 1165 | kfree(kvb_addr); |
| 1166 | kfree(kbox_addr); |
Dave Airlie | 3528af1 | 2006-01-02 16:11:44 +1100 | [diff] [blame] | 1167 | |
| 1168 | return ret; |
Dave Airlie | 282a167 | 2005-08-07 15:43:54 +1000 | [diff] [blame] | 1169 | } |