Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2008-2010 Intel Corporation |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice (including the next |
| 12 | * paragraph) shall be included in all copies or substantial portions of the |
| 13 | * Software. |
| 14 | * |
| 15 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 18 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
| 20 | * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS |
| 21 | * IN THE SOFTWARE. |
| 22 | * |
| 23 | * Authors: |
| 24 | * Eric Anholt <eric@anholt.net> |
| 25 | * Zou Nan hai <nanhai.zou@intel.com> |
| 26 | * Xiang Hai hao<haihao.xiang@intel.com> |
| 27 | * |
| 28 | */ |
| 29 | |
| 30 | #include "drmP.h" |
| 31 | #include "drm.h" |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 32 | #include "i915_drv.h" |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 33 | #include "i915_drm.h" |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 34 | #include "i915_trace.h" |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 35 | #include "intel_drv.h" |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 36 | |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 37 | static inline int ring_space(struct intel_ring_buffer *ring) |
| 38 | { |
| 39 | int space = (ring->head & HEAD_ADDR) - (ring->tail + 8); |
| 40 | if (space < 0) |
| 41 | space += ring->size; |
| 42 | return space; |
| 43 | } |
| 44 | |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 45 | static u32 i915_gem_get_seqno(struct drm_device *dev) |
| 46 | { |
| 47 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 48 | u32 seqno; |
| 49 | |
| 50 | seqno = dev_priv->next_seqno; |
| 51 | |
| 52 | /* reserve 0 for non-seqno */ |
| 53 | if (++dev_priv->next_seqno == 0) |
| 54 | dev_priv->next_seqno = 1; |
| 55 | |
| 56 | return seqno; |
| 57 | } |
| 58 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 59 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 60 | render_ring_flush(struct intel_ring_buffer *ring, |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 61 | u32 invalidate_domains, |
| 62 | u32 flush_domains) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 63 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 64 | struct drm_device *dev = ring->dev; |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 65 | u32 cmd; |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 66 | int ret; |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 67 | |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 68 | /* |
| 69 | * read/write caches: |
| 70 | * |
| 71 | * I915_GEM_DOMAIN_RENDER is always invalidated, but is |
| 72 | * only flushed if MI_NO_WRITE_FLUSH is unset. On 965, it is |
| 73 | * also flushed at 2d versus 3d pipeline switches. |
| 74 | * |
| 75 | * read-only caches: |
| 76 | * |
| 77 | * I915_GEM_DOMAIN_SAMPLER is flushed on pre-965 if |
| 78 | * MI_READ_FLUSH is set, and is always flushed on 965. |
| 79 | * |
| 80 | * I915_GEM_DOMAIN_COMMAND may not exist? |
| 81 | * |
| 82 | * I915_GEM_DOMAIN_INSTRUCTION, which exists on 965, is |
| 83 | * invalidated when MI_EXE_FLUSH is set. |
| 84 | * |
| 85 | * I915_GEM_DOMAIN_VERTEX, which exists on 965, is |
| 86 | * invalidated with every MI_FLUSH. |
| 87 | * |
| 88 | * TLBs: |
| 89 | * |
| 90 | * On 965, TLBs associated with I915_GEM_DOMAIN_COMMAND |
| 91 | * and I915_GEM_DOMAIN_CPU in are invalidated at PTE write and |
| 92 | * I915_GEM_DOMAIN_RENDER and I915_GEM_DOMAIN_SAMPLER |
| 93 | * are flushed at any MI_FLUSH. |
| 94 | */ |
| 95 | |
| 96 | cmd = MI_FLUSH | MI_NO_WRITE_FLUSH; |
| 97 | if ((invalidate_domains|flush_domains) & |
| 98 | I915_GEM_DOMAIN_RENDER) |
| 99 | cmd &= ~MI_NO_WRITE_FLUSH; |
| 100 | if (INTEL_INFO(dev)->gen < 4) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 101 | /* |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 102 | * On the 965, the sampler cache always gets flushed |
| 103 | * and this bit is reserved. |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 104 | */ |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 105 | if (invalidate_domains & I915_GEM_DOMAIN_SAMPLER) |
| 106 | cmd |= MI_READ_FLUSH; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 107 | } |
Chris Wilson | 36d527d | 2011-03-19 22:26:49 +0000 | [diff] [blame] | 108 | if (invalidate_domains & I915_GEM_DOMAIN_INSTRUCTION) |
| 109 | cmd |= MI_EXE_FLUSH; |
| 110 | |
| 111 | if (invalidate_domains & I915_GEM_DOMAIN_COMMAND && |
| 112 | (IS_G4X(dev) || IS_GEN5(dev))) |
| 113 | cmd |= MI_INVALIDATE_ISP; |
| 114 | |
| 115 | ret = intel_ring_begin(ring, 2); |
| 116 | if (ret) |
| 117 | return ret; |
| 118 | |
| 119 | intel_ring_emit(ring, cmd); |
| 120 | intel_ring_emit(ring, MI_NOOP); |
| 121 | intel_ring_advance(ring); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 122 | |
| 123 | return 0; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 124 | } |
| 125 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 126 | static void ring_write_tail(struct intel_ring_buffer *ring, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 127 | u32 value) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 128 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 129 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 130 | I915_WRITE_TAIL(ring, value); |
Xiang, Haihao | d46eefa | 2010-09-16 10:43:12 +0800 | [diff] [blame] | 131 | } |
| 132 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 133 | u32 intel_ring_get_active_head(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 134 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 135 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
| 136 | u32 acthd_reg = INTEL_INFO(ring->dev)->gen >= 4 ? |
Daniel Vetter | 3d281d8 | 2010-09-24 21:14:22 +0200 | [diff] [blame] | 137 | RING_ACTHD(ring->mmio_base) : ACTHD; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 138 | |
| 139 | return I915_READ(acthd_reg); |
| 140 | } |
| 141 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 142 | static int init_ring_common(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 143 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 144 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 145 | struct drm_i915_gem_object *obj = ring->obj; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 146 | u32 head; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 147 | |
| 148 | /* Stop the ring if it's running. */ |
Daniel Vetter | 7f2ab69 | 2010-08-02 17:06:59 +0200 | [diff] [blame] | 149 | I915_WRITE_CTL(ring, 0); |
Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 150 | I915_WRITE_HEAD(ring, 0); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 151 | ring->write_tail(ring, 0); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 152 | |
| 153 | /* Initialize the ring. */ |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 154 | I915_WRITE_START(ring, obj->gtt_offset); |
Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 155 | head = I915_READ_HEAD(ring) & HEAD_ADDR; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 156 | |
| 157 | /* G45 ring initialization fails to reset head to zero */ |
| 158 | if (head != 0) { |
Chris Wilson | 6fd0d56 | 2010-12-05 20:42:33 +0000 | [diff] [blame] | 159 | DRM_DEBUG_KMS("%s head not reset to zero " |
| 160 | "ctl %08x head %08x tail %08x start %08x\n", |
| 161 | ring->name, |
| 162 | I915_READ_CTL(ring), |
| 163 | I915_READ_HEAD(ring), |
| 164 | I915_READ_TAIL(ring), |
| 165 | I915_READ_START(ring)); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 166 | |
Daniel Vetter | 570ef60 | 2010-08-02 17:06:23 +0200 | [diff] [blame] | 167 | I915_WRITE_HEAD(ring, 0); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 168 | |
Chris Wilson | 6fd0d56 | 2010-12-05 20:42:33 +0000 | [diff] [blame] | 169 | if (I915_READ_HEAD(ring) & HEAD_ADDR) { |
| 170 | DRM_ERROR("failed to set %s head to zero " |
| 171 | "ctl %08x head %08x tail %08x start %08x\n", |
| 172 | ring->name, |
| 173 | I915_READ_CTL(ring), |
| 174 | I915_READ_HEAD(ring), |
| 175 | I915_READ_TAIL(ring), |
| 176 | I915_READ_START(ring)); |
| 177 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 178 | } |
| 179 | |
Daniel Vetter | 7f2ab69 | 2010-08-02 17:06:59 +0200 | [diff] [blame] | 180 | I915_WRITE_CTL(ring, |
Chris Wilson | ae69b42 | 2010-11-07 11:45:52 +0000 | [diff] [blame] | 181 | ((ring->size - PAGE_SIZE) & RING_NR_PAGES) |
Chris Wilson | 6aa5606 | 2010-10-29 21:44:37 +0100 | [diff] [blame] | 182 | | RING_REPORT_64K | RING_VALID); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 183 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 184 | /* If the head is still not zero, the ring is dead */ |
Chris Wilson | 176f28e | 2010-10-28 11:18:07 +0100 | [diff] [blame] | 185 | if ((I915_READ_CTL(ring) & RING_VALID) == 0 || |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 186 | I915_READ_START(ring) != obj->gtt_offset || |
Chris Wilson | 176f28e | 2010-10-28 11:18:07 +0100 | [diff] [blame] | 187 | (I915_READ_HEAD(ring) & HEAD_ADDR) != 0) { |
Chris Wilson | e74cfed | 2010-11-09 10:16:56 +0000 | [diff] [blame] | 188 | DRM_ERROR("%s initialization failed " |
| 189 | "ctl %08x head %08x tail %08x start %08x\n", |
| 190 | ring->name, |
| 191 | I915_READ_CTL(ring), |
| 192 | I915_READ_HEAD(ring), |
| 193 | I915_READ_TAIL(ring), |
| 194 | I915_READ_START(ring)); |
| 195 | return -EIO; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 196 | } |
| 197 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 198 | if (!drm_core_check_feature(ring->dev, DRIVER_MODESET)) |
| 199 | i915_kernel_lost_context(ring->dev); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 200 | else { |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 201 | ring->head = I915_READ_HEAD(ring); |
Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 202 | ring->tail = I915_READ_TAIL(ring) & TAIL_ADDR; |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 203 | ring->space = ring_space(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 204 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 205 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 206 | return 0; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 207 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 208 | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 209 | /* |
| 210 | * 965+ support PIPE_CONTROL commands, which provide finer grained control |
| 211 | * over cache flushing. |
| 212 | */ |
| 213 | struct pipe_control { |
| 214 | struct drm_i915_gem_object *obj; |
| 215 | volatile u32 *cpu_page; |
| 216 | u32 gtt_offset; |
| 217 | }; |
| 218 | |
| 219 | static int |
| 220 | init_pipe_control(struct intel_ring_buffer *ring) |
| 221 | { |
| 222 | struct pipe_control *pc; |
| 223 | struct drm_i915_gem_object *obj; |
| 224 | int ret; |
| 225 | |
| 226 | if (ring->private) |
| 227 | return 0; |
| 228 | |
| 229 | pc = kmalloc(sizeof(*pc), GFP_KERNEL); |
| 230 | if (!pc) |
| 231 | return -ENOMEM; |
| 232 | |
| 233 | obj = i915_gem_alloc_object(ring->dev, 4096); |
| 234 | if (obj == NULL) { |
| 235 | DRM_ERROR("Failed to allocate seqno page\n"); |
| 236 | ret = -ENOMEM; |
| 237 | goto err; |
| 238 | } |
| 239 | obj->agp_type = AGP_USER_CACHED_MEMORY; |
| 240 | |
| 241 | ret = i915_gem_object_pin(obj, 4096, true); |
| 242 | if (ret) |
| 243 | goto err_unref; |
| 244 | |
| 245 | pc->gtt_offset = obj->gtt_offset; |
| 246 | pc->cpu_page = kmap(obj->pages[0]); |
| 247 | if (pc->cpu_page == NULL) |
| 248 | goto err_unpin; |
| 249 | |
| 250 | pc->obj = obj; |
| 251 | ring->private = pc; |
| 252 | return 0; |
| 253 | |
| 254 | err_unpin: |
| 255 | i915_gem_object_unpin(obj); |
| 256 | err_unref: |
| 257 | drm_gem_object_unreference(&obj->base); |
| 258 | err: |
| 259 | kfree(pc); |
| 260 | return ret; |
| 261 | } |
| 262 | |
| 263 | static void |
| 264 | cleanup_pipe_control(struct intel_ring_buffer *ring) |
| 265 | { |
| 266 | struct pipe_control *pc = ring->private; |
| 267 | struct drm_i915_gem_object *obj; |
| 268 | |
| 269 | if (!ring->private) |
| 270 | return; |
| 271 | |
| 272 | obj = pc->obj; |
| 273 | kunmap(obj->pages[0]); |
| 274 | i915_gem_object_unpin(obj); |
| 275 | drm_gem_object_unreference(&obj->base); |
| 276 | |
| 277 | kfree(pc); |
| 278 | ring->private = NULL; |
| 279 | } |
| 280 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 281 | static int init_render_ring(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 282 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 283 | struct drm_device *dev = ring->dev; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 284 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 285 | int ret = init_ring_common(ring); |
Zhenyu Wang | a69ffdb | 2010-08-30 16:12:42 +0800 | [diff] [blame] | 286 | |
Chris Wilson | a6c45cf | 2010-09-17 00:32:17 +0100 | [diff] [blame] | 287 | if (INTEL_INFO(dev)->gen > 3) { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 288 | int mode = VS_TIMER_DISPATCH << 16 | VS_TIMER_DISPATCH; |
Zhenyu Wang | a69ffdb | 2010-08-30 16:12:42 +0800 | [diff] [blame] | 289 | if (IS_GEN6(dev)) |
| 290 | mode |= MI_FLUSH_ENABLE << 16 | MI_FLUSH_ENABLE; |
| 291 | I915_WRITE(MI_MODE, mode); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 292 | } |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 293 | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 294 | if (INTEL_INFO(dev)->gen >= 6) { |
| 295 | } else if (IS_GEN5(dev)) { |
| 296 | ret = init_pipe_control(ring); |
| 297 | if (ret) |
| 298 | return ret; |
| 299 | } |
| 300 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 301 | return ret; |
| 302 | } |
| 303 | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 304 | static void render_ring_cleanup(struct intel_ring_buffer *ring) |
| 305 | { |
| 306 | if (!ring->private) |
| 307 | return; |
| 308 | |
| 309 | cleanup_pipe_control(ring); |
| 310 | } |
| 311 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 312 | static void |
| 313 | update_semaphore(struct intel_ring_buffer *ring, int i, u32 seqno) |
| 314 | { |
| 315 | struct drm_device *dev = ring->dev; |
| 316 | struct drm_i915_private *dev_priv = dev->dev_private; |
| 317 | int id; |
| 318 | |
| 319 | /* |
| 320 | * cs -> 1 = vcs, 0 = bcs |
| 321 | * vcs -> 1 = bcs, 0 = cs, |
| 322 | * bcs -> 1 = cs, 0 = vcs. |
| 323 | */ |
| 324 | id = ring - dev_priv->ring; |
| 325 | id += 2 - i; |
| 326 | id %= 3; |
| 327 | |
| 328 | intel_ring_emit(ring, |
| 329 | MI_SEMAPHORE_MBOX | |
| 330 | MI_SEMAPHORE_REGISTER | |
| 331 | MI_SEMAPHORE_UPDATE); |
| 332 | intel_ring_emit(ring, seqno); |
| 333 | intel_ring_emit(ring, |
| 334 | RING_SYNC_0(dev_priv->ring[id].mmio_base) + 4*i); |
| 335 | } |
| 336 | |
| 337 | static int |
| 338 | gen6_add_request(struct intel_ring_buffer *ring, |
| 339 | u32 *result) |
| 340 | { |
| 341 | u32 seqno; |
| 342 | int ret; |
| 343 | |
| 344 | ret = intel_ring_begin(ring, 10); |
| 345 | if (ret) |
| 346 | return ret; |
| 347 | |
| 348 | seqno = i915_gem_get_seqno(ring->dev); |
| 349 | update_semaphore(ring, 0, seqno); |
| 350 | update_semaphore(ring, 1, seqno); |
| 351 | |
| 352 | intel_ring_emit(ring, MI_STORE_DWORD_INDEX); |
| 353 | intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 354 | intel_ring_emit(ring, seqno); |
| 355 | intel_ring_emit(ring, MI_USER_INTERRUPT); |
| 356 | intel_ring_advance(ring); |
| 357 | |
| 358 | *result = seqno; |
| 359 | return 0; |
| 360 | } |
| 361 | |
| 362 | int |
| 363 | intel_ring_sync(struct intel_ring_buffer *ring, |
| 364 | struct intel_ring_buffer *to, |
| 365 | u32 seqno) |
| 366 | { |
| 367 | int ret; |
| 368 | |
| 369 | ret = intel_ring_begin(ring, 4); |
| 370 | if (ret) |
| 371 | return ret; |
| 372 | |
| 373 | intel_ring_emit(ring, |
| 374 | MI_SEMAPHORE_MBOX | |
| 375 | MI_SEMAPHORE_REGISTER | |
| 376 | intel_ring_sync_index(ring, to) << 17 | |
| 377 | MI_SEMAPHORE_COMPARE); |
| 378 | intel_ring_emit(ring, seqno); |
| 379 | intel_ring_emit(ring, 0); |
| 380 | intel_ring_emit(ring, MI_NOOP); |
| 381 | intel_ring_advance(ring); |
| 382 | |
| 383 | return 0; |
| 384 | } |
| 385 | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 386 | #define PIPE_CONTROL_FLUSH(ring__, addr__) \ |
| 387 | do { \ |
| 388 | intel_ring_emit(ring__, GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | \ |
| 389 | PIPE_CONTROL_DEPTH_STALL | 2); \ |
| 390 | intel_ring_emit(ring__, (addr__) | PIPE_CONTROL_GLOBAL_GTT); \ |
| 391 | intel_ring_emit(ring__, 0); \ |
| 392 | intel_ring_emit(ring__, 0); \ |
| 393 | } while (0) |
| 394 | |
| 395 | static int |
| 396 | pc_render_add_request(struct intel_ring_buffer *ring, |
| 397 | u32 *result) |
| 398 | { |
| 399 | struct drm_device *dev = ring->dev; |
| 400 | u32 seqno = i915_gem_get_seqno(dev); |
| 401 | struct pipe_control *pc = ring->private; |
| 402 | u32 scratch_addr = pc->gtt_offset + 128; |
| 403 | int ret; |
| 404 | |
| 405 | /* For Ironlake, MI_USER_INTERRUPT was deprecated and apparently |
| 406 | * incoherent with writes to memory, i.e. completely fubar, |
| 407 | * so we need to use PIPE_NOTIFY instead. |
| 408 | * |
| 409 | * However, we also need to workaround the qword write |
| 410 | * incoherence by flushing the 6 PIPE_NOTIFY buffers out to |
| 411 | * memory before requesting an interrupt. |
| 412 | */ |
| 413 | ret = intel_ring_begin(ring, 32); |
| 414 | if (ret) |
| 415 | return ret; |
| 416 | |
| 417 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | |
| 418 | PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH); |
| 419 | intel_ring_emit(ring, pc->gtt_offset | PIPE_CONTROL_GLOBAL_GTT); |
| 420 | intel_ring_emit(ring, seqno); |
| 421 | intel_ring_emit(ring, 0); |
| 422 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
| 423 | scratch_addr += 128; /* write to separate cachelines */ |
| 424 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
| 425 | scratch_addr += 128; |
| 426 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
| 427 | scratch_addr += 128; |
| 428 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
| 429 | scratch_addr += 128; |
| 430 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
| 431 | scratch_addr += 128; |
| 432 | PIPE_CONTROL_FLUSH(ring, scratch_addr); |
| 433 | intel_ring_emit(ring, GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | |
| 434 | PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH | |
| 435 | PIPE_CONTROL_NOTIFY); |
| 436 | intel_ring_emit(ring, pc->gtt_offset | PIPE_CONTROL_GLOBAL_GTT); |
| 437 | intel_ring_emit(ring, seqno); |
| 438 | intel_ring_emit(ring, 0); |
| 439 | intel_ring_advance(ring); |
| 440 | |
| 441 | *result = seqno; |
| 442 | return 0; |
| 443 | } |
| 444 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 445 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 446 | render_ring_add_request(struct intel_ring_buffer *ring, |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 447 | u32 *result) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 448 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 449 | struct drm_device *dev = ring->dev; |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 450 | u32 seqno = i915_gem_get_seqno(dev); |
| 451 | int ret; |
Zhenyu Wang | ca76482 | 2010-05-27 10:26:42 +0800 | [diff] [blame] | 452 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 453 | ret = intel_ring_begin(ring, 4); |
| 454 | if (ret) |
| 455 | return ret; |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 456 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 457 | intel_ring_emit(ring, MI_STORE_DWORD_INDEX); |
| 458 | intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 459 | intel_ring_emit(ring, seqno); |
| 460 | intel_ring_emit(ring, MI_USER_INTERRUPT); |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 461 | intel_ring_advance(ring); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 462 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 463 | *result = seqno; |
| 464 | return 0; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 465 | } |
| 466 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 467 | static u32 |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 468 | ring_get_seqno(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 469 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 470 | return intel_read_status_page(ring, I915_GEM_HWS_INDEX); |
| 471 | } |
| 472 | |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 473 | static u32 |
| 474 | pc_render_get_seqno(struct intel_ring_buffer *ring) |
| 475 | { |
| 476 | struct pipe_control *pc = ring->private; |
| 477 | return pc->cpu_page[0]; |
| 478 | } |
| 479 | |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 480 | static void |
| 481 | ironlake_enable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 482 | { |
| 483 | dev_priv->gt_irq_mask &= ~mask; |
| 484 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
| 485 | POSTING_READ(GTIMR); |
| 486 | } |
| 487 | |
| 488 | static void |
| 489 | ironlake_disable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 490 | { |
| 491 | dev_priv->gt_irq_mask |= mask; |
| 492 | I915_WRITE(GTIMR, dev_priv->gt_irq_mask); |
| 493 | POSTING_READ(GTIMR); |
| 494 | } |
| 495 | |
| 496 | static void |
| 497 | i915_enable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 498 | { |
| 499 | dev_priv->irq_mask &= ~mask; |
| 500 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 501 | POSTING_READ(IMR); |
| 502 | } |
| 503 | |
| 504 | static void |
| 505 | i915_disable_irq(drm_i915_private_t *dev_priv, u32 mask) |
| 506 | { |
| 507 | dev_priv->irq_mask |= mask; |
| 508 | I915_WRITE(IMR, dev_priv->irq_mask); |
| 509 | POSTING_READ(IMR); |
| 510 | } |
| 511 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 512 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 513 | render_ring_get_irq(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 514 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 515 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 516 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 517 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 518 | if (!dev->irq_enabled) |
| 519 | return false; |
| 520 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 521 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 522 | if (ring->irq_refcount++ == 0) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 523 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 524 | ironlake_enable_irq(dev_priv, |
| 525 | GT_PIPE_NOTIFY | GT_USER_INTERRUPT); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 526 | else |
| 527 | i915_enable_irq(dev_priv, I915_USER_INTERRUPT); |
| 528 | } |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 529 | spin_unlock(&ring->irq_lock); |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 530 | |
| 531 | return true; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 532 | } |
| 533 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 534 | static void |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 535 | render_ring_put_irq(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 536 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 537 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 538 | drm_i915_private_t *dev_priv = dev->dev_private; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 539 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 540 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 541 | if (--ring->irq_refcount == 0) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 542 | if (HAS_PCH_SPLIT(dev)) |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 543 | ironlake_disable_irq(dev_priv, |
| 544 | GT_USER_INTERRUPT | |
| 545 | GT_PIPE_NOTIFY); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 546 | else |
| 547 | i915_disable_irq(dev_priv, I915_USER_INTERRUPT); |
| 548 | } |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 549 | spin_unlock(&ring->irq_lock); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 550 | } |
| 551 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 552 | void intel_ring_setup_status_page(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 553 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 554 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
| 555 | u32 mmio = IS_GEN6(ring->dev) ? |
| 556 | RING_HWS_PGA_GEN6(ring->mmio_base) : |
| 557 | RING_HWS_PGA(ring->mmio_base); |
| 558 | I915_WRITE(mmio, (u32)ring->status_page.gfx_addr); |
| 559 | POSTING_READ(mmio); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 560 | } |
| 561 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 562 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 563 | bsd_ring_flush(struct intel_ring_buffer *ring, |
| 564 | u32 invalidate_domains, |
| 565 | u32 flush_domains) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 566 | { |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 567 | int ret; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 568 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 569 | ret = intel_ring_begin(ring, 2); |
| 570 | if (ret) |
| 571 | return ret; |
| 572 | |
| 573 | intel_ring_emit(ring, MI_FLUSH); |
| 574 | intel_ring_emit(ring, MI_NOOP); |
| 575 | intel_ring_advance(ring); |
| 576 | return 0; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 577 | } |
| 578 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 579 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 580 | ring_add_request(struct intel_ring_buffer *ring, |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 581 | u32 *result) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 582 | { |
| 583 | u32 seqno; |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 584 | int ret; |
| 585 | |
| 586 | ret = intel_ring_begin(ring, 4); |
| 587 | if (ret) |
| 588 | return ret; |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 589 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 590 | seqno = i915_gem_get_seqno(ring->dev); |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 591 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 592 | intel_ring_emit(ring, MI_STORE_DWORD_INDEX); |
| 593 | intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 594 | intel_ring_emit(ring, seqno); |
| 595 | intel_ring_emit(ring, MI_USER_INTERRUPT); |
| 596 | intel_ring_advance(ring); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 597 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 598 | *result = seqno; |
| 599 | return 0; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 600 | } |
| 601 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 602 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 603 | ring_get_irq(struct intel_ring_buffer *ring, u32 flag) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 604 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 605 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 606 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 607 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 608 | if (!dev->irq_enabled) |
| 609 | return false; |
| 610 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 611 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 612 | if (ring->irq_refcount++ == 0) |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 613 | ironlake_enable_irq(dev_priv, flag); |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 614 | spin_unlock(&ring->irq_lock); |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 615 | |
| 616 | return true; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 617 | } |
| 618 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 619 | static void |
| 620 | ring_put_irq(struct intel_ring_buffer *ring, u32 flag) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 621 | { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 622 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 623 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 624 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 625 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 626 | if (--ring->irq_refcount == 0) |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 627 | ironlake_disable_irq(dev_priv, flag); |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 628 | spin_unlock(&ring->irq_lock); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 629 | } |
| 630 | |
| 631 | static bool |
| 632 | gen6_ring_get_irq(struct intel_ring_buffer *ring, u32 gflag, u32 rflag) |
| 633 | { |
| 634 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 635 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 636 | |
| 637 | if (!dev->irq_enabled) |
| 638 | return false; |
| 639 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 640 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 641 | if (ring->irq_refcount++ == 0) { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 642 | ring->irq_mask &= ~rflag; |
| 643 | I915_WRITE_IMR(ring, ring->irq_mask); |
| 644 | ironlake_enable_irq(dev_priv, gflag); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 645 | } |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 646 | spin_unlock(&ring->irq_lock); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 647 | |
| 648 | return true; |
| 649 | } |
| 650 | |
| 651 | static void |
| 652 | gen6_ring_put_irq(struct intel_ring_buffer *ring, u32 gflag, u32 rflag) |
| 653 | { |
| 654 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 655 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 656 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 657 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 658 | if (--ring->irq_refcount == 0) { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 659 | ring->irq_mask |= rflag; |
| 660 | I915_WRITE_IMR(ring, ring->irq_mask); |
| 661 | ironlake_disable_irq(dev_priv, gflag); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 662 | } |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 663 | spin_unlock(&ring->irq_lock); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 664 | } |
| 665 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 666 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 667 | bsd_ring_get_irq(struct intel_ring_buffer *ring) |
| 668 | { |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 669 | return ring_get_irq(ring, GT_BSD_USER_INTERRUPT); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 670 | } |
| 671 | static void |
| 672 | bsd_ring_put_irq(struct intel_ring_buffer *ring) |
| 673 | { |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 674 | ring_put_irq(ring, GT_BSD_USER_INTERRUPT); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 675 | } |
| 676 | |
| 677 | static int |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 678 | ring_dispatch_execbuffer(struct intel_ring_buffer *ring, u32 offset, u32 length) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 679 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 680 | int ret; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 681 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 682 | ret = intel_ring_begin(ring, 2); |
| 683 | if (ret) |
| 684 | return ret; |
| 685 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 686 | intel_ring_emit(ring, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 687 | MI_BATCH_BUFFER_START | (2 << 6) | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 688 | MI_BATCH_NON_SECURE_I965); |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 689 | intel_ring_emit(ring, offset); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 690 | intel_ring_advance(ring); |
| 691 | |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 692 | return 0; |
| 693 | } |
| 694 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 695 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 696 | render_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 697 | u32 offset, u32 len) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 698 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 699 | struct drm_device *dev = ring->dev; |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 700 | int ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 701 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 702 | if (IS_I830(dev) || IS_845G(dev)) { |
| 703 | ret = intel_ring_begin(ring, 4); |
| 704 | if (ret) |
| 705 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 706 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 707 | intel_ring_emit(ring, MI_BATCH_BUFFER); |
| 708 | intel_ring_emit(ring, offset | MI_BATCH_NON_SECURE); |
| 709 | intel_ring_emit(ring, offset + len - 8); |
| 710 | intel_ring_emit(ring, 0); |
| 711 | } else { |
| 712 | ret = intel_ring_begin(ring, 2); |
| 713 | if (ret) |
| 714 | return ret; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 715 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 716 | if (INTEL_INFO(dev)->gen >= 4) { |
| 717 | intel_ring_emit(ring, |
| 718 | MI_BATCH_BUFFER_START | (2 << 6) | |
| 719 | MI_BATCH_NON_SECURE_I965); |
| 720 | intel_ring_emit(ring, offset); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 721 | } else { |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 722 | intel_ring_emit(ring, |
| 723 | MI_BATCH_BUFFER_START | (2 << 6)); |
| 724 | intel_ring_emit(ring, offset | MI_BATCH_NON_SECURE); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 725 | } |
| 726 | } |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 727 | intel_ring_advance(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 728 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 729 | return 0; |
| 730 | } |
| 731 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 732 | static void cleanup_status_page(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 733 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 734 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 735 | struct drm_i915_gem_object *obj; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 736 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 737 | obj = ring->status_page.obj; |
| 738 | if (obj == NULL) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 739 | return; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 740 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 741 | kunmap(obj->pages[0]); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 742 | i915_gem_object_unpin(obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 743 | drm_gem_object_unreference(&obj->base); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 744 | ring->status_page.obj = NULL; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 745 | |
| 746 | memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 747 | } |
| 748 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 749 | static int init_status_page(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 750 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 751 | struct drm_device *dev = ring->dev; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 752 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 753 | struct drm_i915_gem_object *obj; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 754 | int ret; |
| 755 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 756 | obj = i915_gem_alloc_object(dev, 4096); |
| 757 | if (obj == NULL) { |
| 758 | DRM_ERROR("Failed to allocate status page\n"); |
| 759 | ret = -ENOMEM; |
| 760 | goto err; |
| 761 | } |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 762 | obj->agp_type = AGP_USER_CACHED_MEMORY; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 763 | |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 764 | ret = i915_gem_object_pin(obj, 4096, true); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 765 | if (ret != 0) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 766 | goto err_unref; |
| 767 | } |
| 768 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 769 | ring->status_page.gfx_addr = obj->gtt_offset; |
| 770 | ring->status_page.page_addr = kmap(obj->pages[0]); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 771 | if (ring->status_page.page_addr == NULL) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 772 | memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 773 | goto err_unpin; |
| 774 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 775 | ring->status_page.obj = obj; |
| 776 | memset(ring->status_page.page_addr, 0, PAGE_SIZE); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 777 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 778 | intel_ring_setup_status_page(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 779 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
| 780 | ring->name, ring->status_page.gfx_addr); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 781 | |
| 782 | return 0; |
| 783 | |
| 784 | err_unpin: |
| 785 | i915_gem_object_unpin(obj); |
| 786 | err_unref: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 787 | drm_gem_object_unreference(&obj->base); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 788 | err: |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 789 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 790 | } |
| 791 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 792 | int intel_init_ring_buffer(struct drm_device *dev, |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 793 | struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 794 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 795 | struct drm_i915_gem_object *obj; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 796 | int ret; |
| 797 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 798 | ring->dev = dev; |
Chris Wilson | 23bc598 | 2010-09-29 16:10:57 +0100 | [diff] [blame] | 799 | INIT_LIST_HEAD(&ring->active_list); |
| 800 | INIT_LIST_HEAD(&ring->request_list); |
Chris Wilson | 6419340 | 2010-10-24 12:38:05 +0100 | [diff] [blame] | 801 | INIT_LIST_HEAD(&ring->gpu_write_list); |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 802 | |
Chris Wilson | b259f67 | 2011-03-29 13:19:09 +0100 | [diff] [blame] | 803 | init_waitqueue_head(&ring->irq_queue); |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 804 | spin_lock_init(&ring->irq_lock); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 805 | ring->irq_mask = ~0; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 806 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 807 | if (I915_NEED_GFX_HWS(dev)) { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 808 | ret = init_status_page(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 809 | if (ret) |
| 810 | return ret; |
| 811 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 812 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 813 | obj = i915_gem_alloc_object(dev, ring->size); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 814 | if (obj == NULL) { |
| 815 | DRM_ERROR("Failed to allocate ringbuffer\n"); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 816 | ret = -ENOMEM; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 817 | goto err_hws; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 818 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 819 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 820 | ring->obj = obj; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 821 | |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 822 | ret = i915_gem_object_pin(obj, PAGE_SIZE, true); |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 823 | if (ret) |
| 824 | goto err_unref; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 825 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 826 | ring->map.size = ring->size; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 827 | ring->map.offset = dev->agp->base + obj->gtt_offset; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 828 | ring->map.type = 0; |
| 829 | ring->map.flags = 0; |
| 830 | ring->map.mtrr = 0; |
| 831 | |
| 832 | drm_core_ioremap_wc(&ring->map, dev); |
| 833 | if (ring->map.handle == NULL) { |
| 834 | DRM_ERROR("Failed to map ringbuffer.\n"); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 835 | ret = -EINVAL; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 836 | goto err_unpin; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 837 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 838 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 839 | ring->virtual_start = ring->map.handle; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 840 | ret = ring->init(ring); |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 841 | if (ret) |
| 842 | goto err_unmap; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 843 | |
Chris Wilson | 55249ba | 2010-12-22 14:04:47 +0000 | [diff] [blame] | 844 | /* Workaround an erratum on the i830 which causes a hang if |
| 845 | * the TAIL pointer points to within the last 2 cachelines |
| 846 | * of the buffer. |
| 847 | */ |
| 848 | ring->effective_size = ring->size; |
| 849 | if (IS_I830(ring->dev)) |
| 850 | ring->effective_size -= 128; |
| 851 | |
Chris Wilson | c584fe4 | 2010-10-29 18:15:52 +0100 | [diff] [blame] | 852 | return 0; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 853 | |
| 854 | err_unmap: |
| 855 | drm_core_ioremapfree(&ring->map, dev); |
| 856 | err_unpin: |
| 857 | i915_gem_object_unpin(obj); |
| 858 | err_unref: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 859 | drm_gem_object_unreference(&obj->base); |
| 860 | ring->obj = NULL; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 861 | err_hws: |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 862 | cleanup_status_page(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 863 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 864 | } |
| 865 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 866 | void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 867 | { |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 868 | struct drm_i915_private *dev_priv; |
| 869 | int ret; |
| 870 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 871 | if (ring->obj == NULL) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 872 | return; |
| 873 | |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 874 | /* Disable the ring buffer. The ring must be idle at this point */ |
| 875 | dev_priv = ring->dev->dev_private; |
Ben Widawsky | 96f298a | 2011-03-19 18:14:27 -0700 | [diff] [blame^] | 876 | ret = intel_wait_ring_idle(ring); |
Chris Wilson | 29ee399 | 2011-01-24 16:35:42 +0000 | [diff] [blame] | 877 | if (ret) |
| 878 | DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n", |
| 879 | ring->name, ret); |
| 880 | |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 881 | I915_WRITE_CTL(ring, 0); |
| 882 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 883 | drm_core_ioremapfree(&ring->map, ring->dev); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 884 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 885 | i915_gem_object_unpin(ring->obj); |
| 886 | drm_gem_object_unreference(&ring->obj->base); |
| 887 | ring->obj = NULL; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 888 | |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 889 | if (ring->cleanup) |
| 890 | ring->cleanup(ring); |
| 891 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 892 | cleanup_status_page(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 893 | } |
| 894 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 895 | static int intel_wrap_ring_buffer(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 896 | { |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 897 | unsigned int *virt; |
Chris Wilson | 55249ba | 2010-12-22 14:04:47 +0000 | [diff] [blame] | 898 | int rem = ring->size - ring->tail; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 899 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 900 | if (ring->space < rem) { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 901 | int ret = intel_wait_ring_buffer(ring, rem); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 902 | if (ret) |
| 903 | return ret; |
| 904 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 905 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 906 | virt = (unsigned int *)(ring->virtual_start + ring->tail); |
Chris Wilson | 1741dd4 | 2010-08-04 15:18:12 +0100 | [diff] [blame] | 907 | rem /= 8; |
| 908 | while (rem--) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 909 | *virt++ = MI_NOOP; |
Chris Wilson | 1741dd4 | 2010-08-04 15:18:12 +0100 | [diff] [blame] | 910 | *virt++ = MI_NOOP; |
| 911 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 912 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 913 | ring->tail = 0; |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 914 | ring->space = ring_space(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 915 | |
| 916 | return 0; |
| 917 | } |
| 918 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 919 | int intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 920 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 921 | struct drm_device *dev = ring->dev; |
Zou Nan hai | cae5852 | 2010-11-09 17:17:32 +0800 | [diff] [blame] | 922 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 923 | unsigned long end; |
Chris Wilson | 6aa5606 | 2010-10-29 21:44:37 +0100 | [diff] [blame] | 924 | u32 head; |
| 925 | |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 926 | /* If the reported head position has wrapped or hasn't advanced, |
| 927 | * fallback to the slow and accurate path. |
| 928 | */ |
| 929 | head = intel_read_status_page(ring, 4); |
| 930 | if (head > ring->head) { |
| 931 | ring->head = head; |
| 932 | ring->space = ring_space(ring); |
| 933 | if (ring->space >= n) |
| 934 | return 0; |
| 935 | } |
| 936 | |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 937 | trace_i915_ring_wait_begin(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 938 | end = jiffies + 3 * HZ; |
| 939 | do { |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 940 | ring->head = I915_READ_HEAD(ring); |
| 941 | ring->space = ring_space(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 942 | if (ring->space >= n) { |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 943 | trace_i915_ring_wait_end(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 944 | return 0; |
| 945 | } |
| 946 | |
| 947 | if (dev->primary->master) { |
| 948 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 949 | if (master_priv->sarea_priv) |
| 950 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 951 | } |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 952 | |
Chris Wilson | e60a0b1 | 2010-10-13 10:09:14 +0100 | [diff] [blame] | 953 | msleep(1); |
Chris Wilson | f4e0b29 | 2010-10-29 21:06:16 +0100 | [diff] [blame] | 954 | if (atomic_read(&dev_priv->mm.wedged)) |
| 955 | return -EAGAIN; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 956 | } while (!time_after(jiffies, end)); |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 957 | trace_i915_ring_wait_end(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 958 | return -EBUSY; |
| 959 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 960 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 961 | int intel_ring_begin(struct intel_ring_buffer *ring, |
| 962 | int num_dwords) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 963 | { |
Chris Wilson | 21dd373 | 2011-01-26 15:55:56 +0000 | [diff] [blame] | 964 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
Zou Nan hai | be26a10 | 2010-06-12 17:40:24 +0800 | [diff] [blame] | 965 | int n = 4*num_dwords; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 966 | int ret; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 967 | |
Chris Wilson | 21dd373 | 2011-01-26 15:55:56 +0000 | [diff] [blame] | 968 | if (unlikely(atomic_read(&dev_priv->mm.wedged))) |
| 969 | return -EIO; |
| 970 | |
Chris Wilson | 55249ba | 2010-12-22 14:04:47 +0000 | [diff] [blame] | 971 | if (unlikely(ring->tail + n > ring->effective_size)) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 972 | ret = intel_wrap_ring_buffer(ring); |
| 973 | if (unlikely(ret)) |
| 974 | return ret; |
| 975 | } |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 976 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 977 | if (unlikely(ring->space < n)) { |
| 978 | ret = intel_wait_ring_buffer(ring, n); |
| 979 | if (unlikely(ret)) |
| 980 | return ret; |
| 981 | } |
Chris Wilson | d97ed33 | 2010-08-04 15:18:13 +0100 | [diff] [blame] | 982 | |
| 983 | ring->space -= n; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 984 | return 0; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 985 | } |
| 986 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 987 | void intel_ring_advance(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 988 | { |
Chris Wilson | d97ed33 | 2010-08-04 15:18:13 +0100 | [diff] [blame] | 989 | ring->tail &= ring->size - 1; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 990 | ring->write_tail(ring, ring->tail); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 991 | } |
| 992 | |
Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 993 | static const struct intel_ring_buffer render_ring = { |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 994 | .name = "render ring", |
Chris Wilson | 9220434 | 2010-09-18 11:02:01 +0100 | [diff] [blame] | 995 | .id = RING_RENDER, |
Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 996 | .mmio_base = RENDER_RING_BASE, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 997 | .size = 32 * PAGE_SIZE, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 998 | .init = init_render_ring, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 999 | .write_tail = ring_write_tail, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1000 | .flush = render_ring_flush, |
| 1001 | .add_request = render_ring_add_request, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1002 | .get_seqno = ring_get_seqno, |
| 1003 | .irq_get = render_ring_get_irq, |
| 1004 | .irq_put = render_ring_put_irq, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1005 | .dispatch_execbuffer = render_ring_dispatch_execbuffer, |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 1006 | .cleanup = render_ring_cleanup, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1007 | }; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1008 | |
| 1009 | /* ring buffer for bit-stream decoder */ |
| 1010 | |
Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 1011 | static const struct intel_ring_buffer bsd_ring = { |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1012 | .name = "bsd ring", |
Chris Wilson | 9220434 | 2010-09-18 11:02:01 +0100 | [diff] [blame] | 1013 | .id = RING_BSD, |
Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 1014 | .mmio_base = BSD_RING_BASE, |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1015 | .size = 32 * PAGE_SIZE, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1016 | .init = init_ring_common, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1017 | .write_tail = ring_write_tail, |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1018 | .flush = bsd_ring_flush, |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1019 | .add_request = ring_add_request, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1020 | .get_seqno = ring_get_seqno, |
| 1021 | .irq_get = bsd_ring_get_irq, |
| 1022 | .irq_put = bsd_ring_put_irq, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1023 | .dispatch_execbuffer = ring_dispatch_execbuffer, |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1024 | }; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1025 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1026 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1027 | static void gen6_bsd_ring_write_tail(struct intel_ring_buffer *ring, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1028 | u32 value) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1029 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1030 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1031 | |
| 1032 | /* Every tail move must follow the sequence below */ |
| 1033 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1034 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK | |
| 1035 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_DISABLE); |
| 1036 | I915_WRITE(GEN6_BSD_RNCID, 0x0); |
| 1037 | |
| 1038 | if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) & |
| 1039 | GEN6_BSD_SLEEP_PSMI_CONTROL_IDLE_INDICATOR) == 0, |
| 1040 | 50)) |
| 1041 | DRM_ERROR("timed out waiting for IDLE Indicator\n"); |
| 1042 | |
Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 1043 | I915_WRITE_TAIL(ring, value); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1044 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1045 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK | |
| 1046 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_ENABLE); |
| 1047 | } |
| 1048 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1049 | static int gen6_ring_flush(struct intel_ring_buffer *ring, |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1050 | u32 invalidate, u32 flush) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1051 | { |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1052 | uint32_t cmd; |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1053 | int ret; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1054 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1055 | ret = intel_ring_begin(ring, 4); |
| 1056 | if (ret) |
| 1057 | return ret; |
| 1058 | |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1059 | cmd = MI_FLUSH_DW; |
| 1060 | if (invalidate & I915_GEM_GPU_DOMAINS) |
| 1061 | cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD; |
| 1062 | intel_ring_emit(ring, cmd); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1063 | intel_ring_emit(ring, 0); |
| 1064 | intel_ring_emit(ring, 0); |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1065 | intel_ring_emit(ring, MI_NOOP); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1066 | intel_ring_advance(ring); |
| 1067 | return 0; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1068 | } |
| 1069 | |
| 1070 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1071 | gen6_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 1072 | u32 offset, u32 len) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1073 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1074 | int ret; |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1075 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1076 | ret = intel_ring_begin(ring, 2); |
| 1077 | if (ret) |
| 1078 | return ret; |
| 1079 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1080 | intel_ring_emit(ring, MI_BATCH_BUFFER_START | MI_BATCH_NON_SECURE_I965); |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1081 | /* bit0-7 is the length on GEN6+ */ |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 1082 | intel_ring_emit(ring, offset); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1083 | intel_ring_advance(ring); |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1084 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1085 | return 0; |
| 1086 | } |
| 1087 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1088 | static bool |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1089 | gen6_render_ring_get_irq(struct intel_ring_buffer *ring) |
| 1090 | { |
| 1091 | return gen6_ring_get_irq(ring, |
| 1092 | GT_USER_INTERRUPT, |
| 1093 | GEN6_RENDER_USER_INTERRUPT); |
| 1094 | } |
| 1095 | |
| 1096 | static void |
| 1097 | gen6_render_ring_put_irq(struct intel_ring_buffer *ring) |
| 1098 | { |
| 1099 | return gen6_ring_put_irq(ring, |
| 1100 | GT_USER_INTERRUPT, |
| 1101 | GEN6_RENDER_USER_INTERRUPT); |
| 1102 | } |
| 1103 | |
| 1104 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1105 | gen6_bsd_ring_get_irq(struct intel_ring_buffer *ring) |
| 1106 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1107 | return gen6_ring_get_irq(ring, |
| 1108 | GT_GEN6_BSD_USER_INTERRUPT, |
| 1109 | GEN6_BSD_USER_INTERRUPT); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1110 | } |
| 1111 | |
| 1112 | static void |
| 1113 | gen6_bsd_ring_put_irq(struct intel_ring_buffer *ring) |
| 1114 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1115 | return gen6_ring_put_irq(ring, |
| 1116 | GT_GEN6_BSD_USER_INTERRUPT, |
| 1117 | GEN6_BSD_USER_INTERRUPT); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1118 | } |
| 1119 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1120 | /* ring buffer for Video Codec for Gen6+ */ |
Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 1121 | static const struct intel_ring_buffer gen6_bsd_ring = { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1122 | .name = "gen6 bsd ring", |
| 1123 | .id = RING_BSD, |
| 1124 | .mmio_base = GEN6_BSD_RING_BASE, |
| 1125 | .size = 32 * PAGE_SIZE, |
| 1126 | .init = init_ring_common, |
| 1127 | .write_tail = gen6_bsd_ring_write_tail, |
| 1128 | .flush = gen6_ring_flush, |
| 1129 | .add_request = gen6_add_request, |
| 1130 | .get_seqno = ring_get_seqno, |
| 1131 | .irq_get = gen6_bsd_ring_get_irq, |
| 1132 | .irq_put = gen6_bsd_ring_put_irq, |
| 1133 | .dispatch_execbuffer = gen6_ring_dispatch_execbuffer, |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1134 | }; |
| 1135 | |
| 1136 | /* Blitter support (SandyBridge+) */ |
| 1137 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1138 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1139 | blt_ring_get_irq(struct intel_ring_buffer *ring) |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1140 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1141 | return gen6_ring_get_irq(ring, |
| 1142 | GT_BLT_USER_INTERRUPT, |
| 1143 | GEN6_BLITTER_USER_INTERRUPT); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1144 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1145 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1146 | static void |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1147 | blt_ring_put_irq(struct intel_ring_buffer *ring) |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1148 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1149 | gen6_ring_put_irq(ring, |
| 1150 | GT_BLT_USER_INTERRUPT, |
| 1151 | GEN6_BLITTER_USER_INTERRUPT); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1152 | } |
| 1153 | |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1154 | |
| 1155 | /* Workaround for some stepping of SNB, |
| 1156 | * each time when BLT engine ring tail moved, |
| 1157 | * the first command in the ring to be parsed |
| 1158 | * should be MI_BATCH_BUFFER_START |
| 1159 | */ |
| 1160 | #define NEED_BLT_WORKAROUND(dev) \ |
| 1161 | (IS_GEN6(dev) && (dev->pdev->revision < 8)) |
| 1162 | |
| 1163 | static inline struct drm_i915_gem_object * |
| 1164 | to_blt_workaround(struct intel_ring_buffer *ring) |
| 1165 | { |
| 1166 | return ring->private; |
| 1167 | } |
| 1168 | |
| 1169 | static int blt_ring_init(struct intel_ring_buffer *ring) |
| 1170 | { |
| 1171 | if (NEED_BLT_WORKAROUND(ring->dev)) { |
| 1172 | struct drm_i915_gem_object *obj; |
Chris Wilson | 27153f7 | 2010-11-02 11:17:23 +0000 | [diff] [blame] | 1173 | u32 *ptr; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1174 | int ret; |
| 1175 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1176 | obj = i915_gem_alloc_object(ring->dev, 4096); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1177 | if (obj == NULL) |
| 1178 | return -ENOMEM; |
| 1179 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1180 | ret = i915_gem_object_pin(obj, 4096, true); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1181 | if (ret) { |
| 1182 | drm_gem_object_unreference(&obj->base); |
| 1183 | return ret; |
| 1184 | } |
| 1185 | |
| 1186 | ptr = kmap(obj->pages[0]); |
Chris Wilson | 27153f7 | 2010-11-02 11:17:23 +0000 | [diff] [blame] | 1187 | *ptr++ = MI_BATCH_BUFFER_END; |
| 1188 | *ptr++ = MI_NOOP; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1189 | kunmap(obj->pages[0]); |
| 1190 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1191 | ret = i915_gem_object_set_to_gtt_domain(obj, false); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1192 | if (ret) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1193 | i915_gem_object_unpin(obj); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1194 | drm_gem_object_unreference(&obj->base); |
| 1195 | return ret; |
| 1196 | } |
| 1197 | |
| 1198 | ring->private = obj; |
| 1199 | } |
| 1200 | |
| 1201 | return init_ring_common(ring); |
| 1202 | } |
| 1203 | |
| 1204 | static int blt_ring_begin(struct intel_ring_buffer *ring, |
| 1205 | int num_dwords) |
| 1206 | { |
| 1207 | if (ring->private) { |
| 1208 | int ret = intel_ring_begin(ring, num_dwords+2); |
| 1209 | if (ret) |
| 1210 | return ret; |
| 1211 | |
| 1212 | intel_ring_emit(ring, MI_BATCH_BUFFER_START); |
| 1213 | intel_ring_emit(ring, to_blt_workaround(ring)->gtt_offset); |
| 1214 | |
| 1215 | return 0; |
| 1216 | } else |
| 1217 | return intel_ring_begin(ring, 4); |
| 1218 | } |
| 1219 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1220 | static int blt_ring_flush(struct intel_ring_buffer *ring, |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1221 | u32 invalidate, u32 flush) |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1222 | { |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1223 | uint32_t cmd; |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1224 | int ret; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1225 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1226 | ret = blt_ring_begin(ring, 4); |
| 1227 | if (ret) |
| 1228 | return ret; |
| 1229 | |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1230 | cmd = MI_FLUSH_DW; |
| 1231 | if (invalidate & I915_GEM_DOMAIN_RENDER) |
| 1232 | cmd |= MI_INVALIDATE_TLB; |
| 1233 | intel_ring_emit(ring, cmd); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1234 | intel_ring_emit(ring, 0); |
| 1235 | intel_ring_emit(ring, 0); |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1236 | intel_ring_emit(ring, MI_NOOP); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1237 | intel_ring_advance(ring); |
| 1238 | return 0; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1239 | } |
| 1240 | |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1241 | static void blt_ring_cleanup(struct intel_ring_buffer *ring) |
| 1242 | { |
| 1243 | if (!ring->private) |
| 1244 | return; |
| 1245 | |
| 1246 | i915_gem_object_unpin(ring->private); |
| 1247 | drm_gem_object_unreference(ring->private); |
| 1248 | ring->private = NULL; |
| 1249 | } |
| 1250 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1251 | static const struct intel_ring_buffer gen6_blt_ring = { |
| 1252 | .name = "blt ring", |
| 1253 | .id = RING_BLT, |
| 1254 | .mmio_base = BLT_RING_BASE, |
| 1255 | .size = 32 * PAGE_SIZE, |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1256 | .init = blt_ring_init, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1257 | .write_tail = ring_write_tail, |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1258 | .flush = blt_ring_flush, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1259 | .add_request = gen6_add_request, |
| 1260 | .get_seqno = ring_get_seqno, |
| 1261 | .irq_get = blt_ring_get_irq, |
| 1262 | .irq_put = blt_ring_put_irq, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1263 | .dispatch_execbuffer = gen6_ring_dispatch_execbuffer, |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1264 | .cleanup = blt_ring_cleanup, |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1265 | }; |
| 1266 | |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1267 | int intel_init_render_ring_buffer(struct drm_device *dev) |
| 1268 | { |
| 1269 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1270 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1271 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1272 | *ring = render_ring; |
| 1273 | if (INTEL_INFO(dev)->gen >= 6) { |
| 1274 | ring->add_request = gen6_add_request; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1275 | ring->irq_get = gen6_render_ring_get_irq; |
| 1276 | ring->irq_put = gen6_render_ring_put_irq; |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 1277 | } else if (IS_GEN5(dev)) { |
| 1278 | ring->add_request = pc_render_add_request; |
| 1279 | ring->get_seqno = pc_render_get_seqno; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1280 | } |
| 1281 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1282 | if (!I915_NEED_GFX_HWS(dev)) { |
| 1283 | ring->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
| 1284 | memset(ring->status_page.page_addr, 0, PAGE_SIZE); |
| 1285 | } |
| 1286 | |
| 1287 | return intel_init_ring_buffer(dev, ring); |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1288 | } |
| 1289 | |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 1290 | int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size) |
| 1291 | { |
| 1292 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1293 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
| 1294 | |
| 1295 | *ring = render_ring; |
| 1296 | if (INTEL_INFO(dev)->gen >= 6) { |
| 1297 | ring->add_request = gen6_add_request; |
| 1298 | ring->irq_get = gen6_render_ring_get_irq; |
| 1299 | ring->irq_put = gen6_render_ring_put_irq; |
| 1300 | } else if (IS_GEN5(dev)) { |
| 1301 | ring->add_request = pc_render_add_request; |
| 1302 | ring->get_seqno = pc_render_get_seqno; |
| 1303 | } |
| 1304 | |
| 1305 | ring->dev = dev; |
| 1306 | INIT_LIST_HEAD(&ring->active_list); |
| 1307 | INIT_LIST_HEAD(&ring->request_list); |
| 1308 | INIT_LIST_HEAD(&ring->gpu_write_list); |
| 1309 | |
| 1310 | ring->size = size; |
| 1311 | ring->effective_size = ring->size; |
| 1312 | if (IS_I830(ring->dev)) |
| 1313 | ring->effective_size -= 128; |
| 1314 | |
| 1315 | ring->map.offset = start; |
| 1316 | ring->map.size = size; |
| 1317 | ring->map.type = 0; |
| 1318 | ring->map.flags = 0; |
| 1319 | ring->map.mtrr = 0; |
| 1320 | |
| 1321 | drm_core_ioremap_wc(&ring->map, dev); |
| 1322 | if (ring->map.handle == NULL) { |
| 1323 | DRM_ERROR("can not ioremap virtual address for" |
| 1324 | " ring buffer\n"); |
| 1325 | return -ENOMEM; |
| 1326 | } |
| 1327 | |
| 1328 | ring->virtual_start = (void __force __iomem *)ring->map.handle; |
| 1329 | return 0; |
| 1330 | } |
| 1331 | |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1332 | int intel_init_bsd_ring_buffer(struct drm_device *dev) |
| 1333 | { |
| 1334 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1335 | struct intel_ring_buffer *ring = &dev_priv->ring[VCS]; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1336 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1337 | if (IS_GEN6(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1338 | *ring = gen6_bsd_ring; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1339 | else |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1340 | *ring = bsd_ring; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1341 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1342 | return intel_init_ring_buffer(dev, ring); |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1343 | } |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1344 | |
| 1345 | int intel_init_blt_ring_buffer(struct drm_device *dev) |
| 1346 | { |
| 1347 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1348 | struct intel_ring_buffer *ring = &dev_priv->ring[BCS]; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1349 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1350 | *ring = gen6_blt_ring; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1351 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1352 | return intel_init_ring_buffer(dev, ring); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1353 | } |