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