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 | } |
Chris Wilson | 93dfb40 | 2011-03-29 16:59:50 -0700 | [diff] [blame] | 239 | obj->cache_level = I915_CACHE_LLC; |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 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; |
Jesse Barnes | 65d3eb1 | 2011-04-06 14:54:44 -0700 | [diff] [blame] | 289 | if (IS_GEN6(dev) || IS_GEN7(dev)) |
Zhenyu Wang | a69ffdb | 2010-08-30 16:12:42 +0800 | [diff] [blame] | 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 | { |
Eric Anholt | 4593010 | 2011-05-06 17:12:35 -0700 | [diff] [blame] | 554 | struct drm_device *dev = ring->dev; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 555 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Eric Anholt | 4593010 | 2011-05-06 17:12:35 -0700 | [diff] [blame] | 556 | u32 mmio = 0; |
| 557 | |
| 558 | /* The ring status page addresses are no longer next to the rest of |
| 559 | * the ring registers as of gen7. |
| 560 | */ |
| 561 | if (IS_GEN7(dev)) { |
| 562 | switch (ring->id) { |
| 563 | case RING_RENDER: |
| 564 | mmio = RENDER_HWS_PGA_GEN7; |
| 565 | break; |
| 566 | case RING_BLT: |
| 567 | mmio = BLT_HWS_PGA_GEN7; |
| 568 | break; |
| 569 | case RING_BSD: |
| 570 | mmio = BSD_HWS_PGA_GEN7; |
| 571 | break; |
| 572 | } |
| 573 | } else if (IS_GEN6(ring->dev)) { |
| 574 | mmio = RING_HWS_PGA_GEN6(ring->mmio_base); |
| 575 | } else { |
| 576 | mmio = RING_HWS_PGA(ring->mmio_base); |
| 577 | } |
| 578 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 579 | I915_WRITE(mmio, (u32)ring->status_page.gfx_addr); |
| 580 | POSTING_READ(mmio); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 581 | } |
| 582 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 583 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 584 | bsd_ring_flush(struct intel_ring_buffer *ring, |
| 585 | u32 invalidate_domains, |
| 586 | u32 flush_domains) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 587 | { |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 588 | int ret; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 589 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 590 | ret = intel_ring_begin(ring, 2); |
| 591 | if (ret) |
| 592 | return ret; |
| 593 | |
| 594 | intel_ring_emit(ring, MI_FLUSH); |
| 595 | intel_ring_emit(ring, MI_NOOP); |
| 596 | intel_ring_advance(ring); |
| 597 | return 0; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 598 | } |
| 599 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 600 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 601 | ring_add_request(struct intel_ring_buffer *ring, |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 602 | u32 *result) |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 603 | { |
| 604 | u32 seqno; |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 605 | int ret; |
| 606 | |
| 607 | ret = intel_ring_begin(ring, 4); |
| 608 | if (ret) |
| 609 | return ret; |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 610 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 611 | seqno = i915_gem_get_seqno(ring->dev); |
Chris Wilson | 6f392d5 | 2010-08-07 11:01:22 +0100 | [diff] [blame] | 612 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 613 | intel_ring_emit(ring, MI_STORE_DWORD_INDEX); |
| 614 | intel_ring_emit(ring, I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); |
| 615 | intel_ring_emit(ring, seqno); |
| 616 | intel_ring_emit(ring, MI_USER_INTERRUPT); |
| 617 | intel_ring_advance(ring); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 618 | |
Chris Wilson | 3cce469 | 2010-10-27 16:11:02 +0100 | [diff] [blame] | 619 | *result = seqno; |
| 620 | return 0; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 621 | } |
| 622 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 623 | static bool |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 624 | gen6_ring_get_irq(struct intel_ring_buffer *ring, u32 gflag, u32 rflag) |
| 625 | { |
| 626 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 627 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 628 | |
| 629 | if (!dev->irq_enabled) |
| 630 | return false; |
| 631 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 632 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 633 | if (ring->irq_refcount++ == 0) { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 634 | ring->irq_mask &= ~rflag; |
| 635 | I915_WRITE_IMR(ring, ring->irq_mask); |
| 636 | ironlake_enable_irq(dev_priv, gflag); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 637 | } |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 638 | spin_unlock(&ring->irq_lock); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 639 | |
| 640 | return true; |
| 641 | } |
| 642 | |
| 643 | static void |
| 644 | gen6_ring_put_irq(struct intel_ring_buffer *ring, u32 gflag, u32 rflag) |
| 645 | { |
| 646 | struct drm_device *dev = ring->dev; |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 647 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 648 | |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 649 | spin_lock(&ring->irq_lock); |
Chris Wilson | 01a0333 | 2011-01-04 22:22:56 +0000 | [diff] [blame] | 650 | if (--ring->irq_refcount == 0) { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 651 | ring->irq_mask |= rflag; |
| 652 | I915_WRITE_IMR(ring, ring->irq_mask); |
| 653 | ironlake_disable_irq(dev_priv, gflag); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 654 | } |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 655 | spin_unlock(&ring->irq_lock); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 656 | } |
| 657 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 658 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 659 | bsd_ring_get_irq(struct intel_ring_buffer *ring) |
| 660 | { |
Feng, Boqun | 5bfa106 | 2011-05-16 16:02:39 +0800 | [diff] [blame] | 661 | struct drm_device *dev = ring->dev; |
| 662 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 663 | |
| 664 | if (!dev->irq_enabled) |
| 665 | return false; |
| 666 | |
| 667 | spin_lock(&ring->irq_lock); |
| 668 | if (ring->irq_refcount++ == 0) { |
| 669 | if (IS_G4X(dev)) |
| 670 | i915_enable_irq(dev_priv, I915_BSD_USER_INTERRUPT); |
| 671 | else |
| 672 | ironlake_enable_irq(dev_priv, GT_BSD_USER_INTERRUPT); |
| 673 | } |
| 674 | spin_unlock(&ring->irq_lock); |
| 675 | |
| 676 | return true; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 677 | } |
| 678 | static void |
| 679 | bsd_ring_put_irq(struct intel_ring_buffer *ring) |
| 680 | { |
Feng, Boqun | 5bfa106 | 2011-05-16 16:02:39 +0800 | [diff] [blame] | 681 | struct drm_device *dev = ring->dev; |
| 682 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 683 | |
| 684 | spin_lock(&ring->irq_lock); |
| 685 | if (--ring->irq_refcount == 0) { |
| 686 | if (IS_G4X(dev)) |
| 687 | i915_disable_irq(dev_priv, I915_BSD_USER_INTERRUPT); |
| 688 | else |
| 689 | ironlake_disable_irq(dev_priv, GT_BSD_USER_INTERRUPT); |
| 690 | } |
| 691 | spin_unlock(&ring->irq_lock); |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 692 | } |
| 693 | |
| 694 | static int |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 695 | 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] | 696 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 697 | int ret; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 698 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 699 | ret = intel_ring_begin(ring, 2); |
| 700 | if (ret) |
| 701 | return ret; |
| 702 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 703 | intel_ring_emit(ring, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 704 | MI_BATCH_BUFFER_START | (2 << 6) | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 705 | MI_BATCH_NON_SECURE_I965); |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 706 | intel_ring_emit(ring, offset); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 707 | intel_ring_advance(ring); |
| 708 | |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 709 | return 0; |
| 710 | } |
| 711 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 712 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 713 | render_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 714 | u32 offset, u32 len) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 715 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 716 | struct drm_device *dev = ring->dev; |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 717 | int ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 718 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 719 | if (IS_I830(dev) || IS_845G(dev)) { |
| 720 | ret = intel_ring_begin(ring, 4); |
| 721 | if (ret) |
| 722 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 723 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 724 | intel_ring_emit(ring, MI_BATCH_BUFFER); |
| 725 | intel_ring_emit(ring, offset | MI_BATCH_NON_SECURE); |
| 726 | intel_ring_emit(ring, offset + len - 8); |
| 727 | intel_ring_emit(ring, 0); |
| 728 | } else { |
| 729 | ret = intel_ring_begin(ring, 2); |
| 730 | if (ret) |
| 731 | return ret; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 732 | |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 733 | if (INTEL_INFO(dev)->gen >= 4) { |
| 734 | intel_ring_emit(ring, |
| 735 | MI_BATCH_BUFFER_START | (2 << 6) | |
| 736 | MI_BATCH_NON_SECURE_I965); |
| 737 | intel_ring_emit(ring, offset); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 738 | } else { |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 739 | intel_ring_emit(ring, |
| 740 | MI_BATCH_BUFFER_START | (2 << 6)); |
| 741 | intel_ring_emit(ring, offset | MI_BATCH_NON_SECURE); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 742 | } |
| 743 | } |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 744 | intel_ring_advance(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 745 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 746 | return 0; |
| 747 | } |
| 748 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 749 | static void cleanup_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 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 752 | struct drm_i915_gem_object *obj; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 753 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 754 | obj = ring->status_page.obj; |
| 755 | if (obj == NULL) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 756 | return; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 757 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 758 | kunmap(obj->pages[0]); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 759 | i915_gem_object_unpin(obj); |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 760 | drm_gem_object_unreference(&obj->base); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 761 | ring->status_page.obj = NULL; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 762 | |
| 763 | memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 764 | } |
| 765 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 766 | static int init_status_page(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 767 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 768 | struct drm_device *dev = ring->dev; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 769 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 770 | struct drm_i915_gem_object *obj; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 771 | int ret; |
| 772 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 773 | obj = i915_gem_alloc_object(dev, 4096); |
| 774 | if (obj == NULL) { |
| 775 | DRM_ERROR("Failed to allocate status page\n"); |
| 776 | ret = -ENOMEM; |
| 777 | goto err; |
| 778 | } |
Chris Wilson | 93dfb40 | 2011-03-29 16:59:50 -0700 | [diff] [blame] | 779 | obj->cache_level = I915_CACHE_LLC; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 780 | |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 781 | ret = i915_gem_object_pin(obj, 4096, true); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 782 | if (ret != 0) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 783 | goto err_unref; |
| 784 | } |
| 785 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 786 | ring->status_page.gfx_addr = obj->gtt_offset; |
| 787 | ring->status_page.page_addr = kmap(obj->pages[0]); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 788 | if (ring->status_page.page_addr == NULL) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 789 | memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 790 | goto err_unpin; |
| 791 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 792 | ring->status_page.obj = obj; |
| 793 | memset(ring->status_page.page_addr, 0, PAGE_SIZE); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 794 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 795 | intel_ring_setup_status_page(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 796 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
| 797 | ring->name, ring->status_page.gfx_addr); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 798 | |
| 799 | return 0; |
| 800 | |
| 801 | err_unpin: |
| 802 | i915_gem_object_unpin(obj); |
| 803 | err_unref: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 804 | drm_gem_object_unreference(&obj->base); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 805 | err: |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 806 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 807 | } |
| 808 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 809 | int intel_init_ring_buffer(struct drm_device *dev, |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 810 | struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 811 | { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 812 | struct drm_i915_gem_object *obj; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 813 | int ret; |
| 814 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 815 | ring->dev = dev; |
Chris Wilson | 23bc598 | 2010-09-29 16:10:57 +0100 | [diff] [blame] | 816 | INIT_LIST_HEAD(&ring->active_list); |
| 817 | INIT_LIST_HEAD(&ring->request_list); |
Chris Wilson | 6419340 | 2010-10-24 12:38:05 +0100 | [diff] [blame] | 818 | INIT_LIST_HEAD(&ring->gpu_write_list); |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 819 | |
Chris Wilson | b259f67 | 2011-03-29 13:19:09 +0100 | [diff] [blame] | 820 | init_waitqueue_head(&ring->irq_queue); |
Chris Wilson | 0dc79fb | 2011-01-05 10:32:24 +0000 | [diff] [blame] | 821 | spin_lock_init(&ring->irq_lock); |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 822 | ring->irq_mask = ~0; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 823 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 824 | if (I915_NEED_GFX_HWS(dev)) { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 825 | ret = init_status_page(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 826 | if (ret) |
| 827 | return ret; |
| 828 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 829 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 830 | obj = i915_gem_alloc_object(dev, ring->size); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 831 | if (obj == NULL) { |
| 832 | DRM_ERROR("Failed to allocate ringbuffer\n"); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 833 | ret = -ENOMEM; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 834 | goto err_hws; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 835 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 836 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 837 | ring->obj = obj; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 838 | |
Daniel Vetter | 75e9e91 | 2010-11-04 17:11:09 +0100 | [diff] [blame] | 839 | ret = i915_gem_object_pin(obj, PAGE_SIZE, true); |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 840 | if (ret) |
| 841 | goto err_unref; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 842 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 843 | ring->map.size = ring->size; |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 844 | ring->map.offset = dev->agp->base + obj->gtt_offset; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 845 | ring->map.type = 0; |
| 846 | ring->map.flags = 0; |
| 847 | ring->map.mtrr = 0; |
| 848 | |
| 849 | drm_core_ioremap_wc(&ring->map, dev); |
| 850 | if (ring->map.handle == NULL) { |
| 851 | DRM_ERROR("Failed to map ringbuffer.\n"); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 852 | ret = -EINVAL; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 853 | goto err_unpin; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 854 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 855 | |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 856 | ring->virtual_start = ring->map.handle; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 857 | ret = ring->init(ring); |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 858 | if (ret) |
| 859 | goto err_unmap; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 860 | |
Chris Wilson | 55249ba | 2010-12-22 14:04:47 +0000 | [diff] [blame] | 861 | /* Workaround an erratum on the i830 which causes a hang if |
| 862 | * the TAIL pointer points to within the last 2 cachelines |
| 863 | * of the buffer. |
| 864 | */ |
| 865 | ring->effective_size = ring->size; |
| 866 | if (IS_I830(ring->dev)) |
| 867 | ring->effective_size -= 128; |
| 868 | |
Chris Wilson | c584fe4 | 2010-10-29 18:15:52 +0100 | [diff] [blame] | 869 | return 0; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 870 | |
| 871 | err_unmap: |
| 872 | drm_core_ioremapfree(&ring->map, dev); |
| 873 | err_unpin: |
| 874 | i915_gem_object_unpin(obj); |
| 875 | err_unref: |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 876 | drm_gem_object_unreference(&obj->base); |
| 877 | ring->obj = NULL; |
Chris Wilson | dd785e3 | 2010-08-07 11:01:34 +0100 | [diff] [blame] | 878 | err_hws: |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 879 | cleanup_status_page(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 880 | return ret; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 881 | } |
| 882 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 883 | void intel_cleanup_ring_buffer(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 884 | { |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 885 | struct drm_i915_private *dev_priv; |
| 886 | int ret; |
| 887 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 888 | if (ring->obj == NULL) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 889 | return; |
| 890 | |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 891 | /* Disable the ring buffer. The ring must be idle at this point */ |
| 892 | dev_priv = ring->dev->dev_private; |
Ben Widawsky | 96f298a | 2011-03-19 18:14:27 -0700 | [diff] [blame] | 893 | ret = intel_wait_ring_idle(ring); |
Chris Wilson | 29ee399 | 2011-01-24 16:35:42 +0000 | [diff] [blame] | 894 | if (ret) |
| 895 | DRM_ERROR("failed to quiesce %s whilst cleaning up: %d\n", |
| 896 | ring->name, ret); |
| 897 | |
Chris Wilson | 33626e6 | 2010-10-29 16:18:36 +0100 | [diff] [blame] | 898 | I915_WRITE_CTL(ring, 0); |
| 899 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 900 | drm_core_ioremapfree(&ring->map, ring->dev); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 901 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 902 | i915_gem_object_unpin(ring->obj); |
| 903 | drm_gem_object_unreference(&ring->obj->base); |
| 904 | ring->obj = NULL; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 905 | |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 906 | if (ring->cleanup) |
| 907 | ring->cleanup(ring); |
| 908 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 909 | cleanup_status_page(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 910 | } |
| 911 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 912 | static int intel_wrap_ring_buffer(struct intel_ring_buffer *ring) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 913 | { |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 914 | unsigned int *virt; |
Chris Wilson | 55249ba | 2010-12-22 14:04:47 +0000 | [diff] [blame] | 915 | int rem = ring->size - ring->tail; |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 916 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 917 | if (ring->space < rem) { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 918 | int ret = intel_wait_ring_buffer(ring, rem); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 919 | if (ret) |
| 920 | return ret; |
| 921 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 922 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 923 | virt = (unsigned int *)(ring->virtual_start + ring->tail); |
Chris Wilson | 1741dd4 | 2010-08-04 15:18:12 +0100 | [diff] [blame] | 924 | rem /= 8; |
| 925 | while (rem--) { |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 926 | *virt++ = MI_NOOP; |
Chris Wilson | 1741dd4 | 2010-08-04 15:18:12 +0100 | [diff] [blame] | 927 | *virt++ = MI_NOOP; |
| 928 | } |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 929 | |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 930 | ring->tail = 0; |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 931 | ring->space = ring_space(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 932 | |
| 933 | return 0; |
| 934 | } |
| 935 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 936 | int intel_wait_ring_buffer(struct intel_ring_buffer *ring, int n) |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 937 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 938 | struct drm_device *dev = ring->dev; |
Zou Nan hai | cae5852 | 2010-11-09 17:17:32 +0800 | [diff] [blame] | 939 | struct drm_i915_private *dev_priv = dev->dev_private; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 940 | unsigned long end; |
Chris Wilson | 6aa5606 | 2010-10-29 21:44:37 +0100 | [diff] [blame] | 941 | u32 head; |
| 942 | |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 943 | /* If the reported head position has wrapped or hasn't advanced, |
| 944 | * fallback to the slow and accurate path. |
| 945 | */ |
| 946 | head = intel_read_status_page(ring, 4); |
| 947 | if (head > ring->head) { |
| 948 | ring->head = head; |
| 949 | ring->space = ring_space(ring); |
| 950 | if (ring->space >= n) |
| 951 | return 0; |
| 952 | } |
| 953 | |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 954 | trace_i915_ring_wait_begin(ring); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 955 | end = jiffies + 3 * HZ; |
| 956 | do { |
Chris Wilson | c7dca47 | 2011-01-20 17:00:10 +0000 | [diff] [blame] | 957 | ring->head = I915_READ_HEAD(ring); |
| 958 | ring->space = ring_space(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 959 | if (ring->space >= n) { |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 960 | trace_i915_ring_wait_end(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 961 | return 0; |
| 962 | } |
| 963 | |
| 964 | if (dev->primary->master) { |
| 965 | struct drm_i915_master_private *master_priv = dev->primary->master->driver_priv; |
| 966 | if (master_priv->sarea_priv) |
| 967 | master_priv->sarea_priv->perf_boxes |= I915_BOX_WAIT; |
| 968 | } |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 969 | |
Chris Wilson | e60a0b1 | 2010-10-13 10:09:14 +0100 | [diff] [blame] | 970 | msleep(1); |
Chris Wilson | f4e0b29 | 2010-10-29 21:06:16 +0100 | [diff] [blame] | 971 | if (atomic_read(&dev_priv->mm.wedged)) |
| 972 | return -EAGAIN; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 973 | } while (!time_after(jiffies, end)); |
Chris Wilson | db53a30 | 2011-02-03 11:57:46 +0000 | [diff] [blame] | 974 | trace_i915_ring_wait_end(ring); |
Eric Anholt | 62fdfea | 2010-05-21 13:26:39 -0700 | [diff] [blame] | 975 | return -EBUSY; |
| 976 | } |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 977 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 978 | int intel_ring_begin(struct intel_ring_buffer *ring, |
| 979 | int num_dwords) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 980 | { |
Chris Wilson | 21dd373 | 2011-01-26 15:55:56 +0000 | [diff] [blame] | 981 | struct drm_i915_private *dev_priv = ring->dev->dev_private; |
Zou Nan hai | be26a10 | 2010-06-12 17:40:24 +0800 | [diff] [blame] | 982 | int n = 4*num_dwords; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 983 | int ret; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 984 | |
Chris Wilson | 21dd373 | 2011-01-26 15:55:56 +0000 | [diff] [blame] | 985 | if (unlikely(atomic_read(&dev_priv->mm.wedged))) |
| 986 | return -EIO; |
| 987 | |
Chris Wilson | 55249ba | 2010-12-22 14:04:47 +0000 | [diff] [blame] | 988 | if (unlikely(ring->tail + n > ring->effective_size)) { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 989 | ret = intel_wrap_ring_buffer(ring); |
| 990 | if (unlikely(ret)) |
| 991 | return ret; |
| 992 | } |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 993 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 994 | if (unlikely(ring->space < n)) { |
| 995 | ret = intel_wait_ring_buffer(ring, n); |
| 996 | if (unlikely(ret)) |
| 997 | return ret; |
| 998 | } |
Chris Wilson | d97ed33 | 2010-08-04 15:18:13 +0100 | [diff] [blame] | 999 | |
| 1000 | ring->space -= n; |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1001 | return 0; |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1002 | } |
| 1003 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1004 | void intel_ring_advance(struct intel_ring_buffer *ring) |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1005 | { |
Chris Wilson | d97ed33 | 2010-08-04 15:18:13 +0100 | [diff] [blame] | 1006 | ring->tail &= ring->size - 1; |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1007 | ring->write_tail(ring, ring->tail); |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1008 | } |
| 1009 | |
Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 1010 | static const struct intel_ring_buffer render_ring = { |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1011 | .name = "render ring", |
Chris Wilson | 9220434 | 2010-09-18 11:02:01 +0100 | [diff] [blame] | 1012 | .id = RING_RENDER, |
Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 1013 | .mmio_base = RENDER_RING_BASE, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1014 | .size = 32 * PAGE_SIZE, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1015 | .init = init_render_ring, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1016 | .write_tail = ring_write_tail, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1017 | .flush = render_ring_flush, |
| 1018 | .add_request = render_ring_add_request, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1019 | .get_seqno = ring_get_seqno, |
| 1020 | .irq_get = render_ring_get_irq, |
| 1021 | .irq_put = render_ring_put_irq, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1022 | .dispatch_execbuffer = render_ring_dispatch_execbuffer, |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 1023 | .cleanup = render_ring_cleanup, |
Zou Nan hai | 8187a2b | 2010-05-21 09:08:55 +0800 | [diff] [blame] | 1024 | }; |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1025 | |
| 1026 | /* ring buffer for bit-stream decoder */ |
| 1027 | |
Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 1028 | static const struct intel_ring_buffer bsd_ring = { |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1029 | .name = "bsd ring", |
Chris Wilson | 9220434 | 2010-09-18 11:02:01 +0100 | [diff] [blame] | 1030 | .id = RING_BSD, |
Daniel Vetter | 333e9fe | 2010-08-02 16:24:01 +0200 | [diff] [blame] | 1031 | .mmio_base = BSD_RING_BASE, |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1032 | .size = 32 * PAGE_SIZE, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1033 | .init = init_ring_common, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1034 | .write_tail = ring_write_tail, |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1035 | .flush = bsd_ring_flush, |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1036 | .add_request = ring_add_request, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1037 | .get_seqno = ring_get_seqno, |
| 1038 | .irq_get = bsd_ring_get_irq, |
| 1039 | .irq_put = bsd_ring_put_irq, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1040 | .dispatch_execbuffer = ring_dispatch_execbuffer, |
Zou Nan hai | d1b851f | 2010-05-21 09:08:57 +0800 | [diff] [blame] | 1041 | }; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1042 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1043 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1044 | static void gen6_bsd_ring_write_tail(struct intel_ring_buffer *ring, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1045 | u32 value) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1046 | { |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1047 | drm_i915_private_t *dev_priv = ring->dev->dev_private; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1048 | |
| 1049 | /* Every tail move must follow the sequence below */ |
| 1050 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1051 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK | |
| 1052 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_DISABLE); |
| 1053 | I915_WRITE(GEN6_BSD_RNCID, 0x0); |
| 1054 | |
| 1055 | if (wait_for((I915_READ(GEN6_BSD_SLEEP_PSMI_CONTROL) & |
| 1056 | GEN6_BSD_SLEEP_PSMI_CONTROL_IDLE_INDICATOR) == 0, |
| 1057 | 50)) |
| 1058 | DRM_ERROR("timed out waiting for IDLE Indicator\n"); |
| 1059 | |
Daniel Vetter | 870e86d | 2010-08-02 16:29:44 +0200 | [diff] [blame] | 1060 | I915_WRITE_TAIL(ring, value); |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1061 | I915_WRITE(GEN6_BSD_SLEEP_PSMI_CONTROL, |
| 1062 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_MODIFY_MASK | |
| 1063 | GEN6_BSD_SLEEP_PSMI_CONTROL_RC_ILDL_MESSAGE_ENABLE); |
| 1064 | } |
| 1065 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1066 | static int gen6_ring_flush(struct intel_ring_buffer *ring, |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1067 | u32 invalidate, u32 flush) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1068 | { |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1069 | uint32_t cmd; |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1070 | int ret; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1071 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1072 | ret = intel_ring_begin(ring, 4); |
| 1073 | if (ret) |
| 1074 | return ret; |
| 1075 | |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1076 | cmd = MI_FLUSH_DW; |
| 1077 | if (invalidate & I915_GEM_GPU_DOMAINS) |
| 1078 | cmd |= MI_INVALIDATE_TLB | MI_INVALIDATE_BSD; |
| 1079 | intel_ring_emit(ring, cmd); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1080 | intel_ring_emit(ring, 0); |
| 1081 | intel_ring_emit(ring, 0); |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1082 | intel_ring_emit(ring, MI_NOOP); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1083 | intel_ring_advance(ring); |
| 1084 | return 0; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1085 | } |
| 1086 | |
| 1087 | static int |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1088 | gen6_ring_dispatch_execbuffer(struct intel_ring_buffer *ring, |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 1089 | u32 offset, u32 len) |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1090 | { |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1091 | int ret; |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1092 | |
Chris Wilson | e1f99ce | 2010-10-27 12:45:26 +0100 | [diff] [blame] | 1093 | ret = intel_ring_begin(ring, 2); |
| 1094 | if (ret) |
| 1095 | return ret; |
| 1096 | |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1097 | 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] | 1098 | /* bit0-7 is the length on GEN6+ */ |
Chris Wilson | c4e7a41 | 2010-11-30 14:10:25 +0000 | [diff] [blame] | 1099 | intel_ring_emit(ring, offset); |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1100 | intel_ring_advance(ring); |
Chris Wilson | ab6f8e3 | 2010-09-19 17:53:44 +0100 | [diff] [blame] | 1101 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1102 | return 0; |
| 1103 | } |
| 1104 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1105 | static bool |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1106 | gen6_render_ring_get_irq(struct intel_ring_buffer *ring) |
| 1107 | { |
| 1108 | return gen6_ring_get_irq(ring, |
| 1109 | GT_USER_INTERRUPT, |
| 1110 | GEN6_RENDER_USER_INTERRUPT); |
| 1111 | } |
| 1112 | |
| 1113 | static void |
| 1114 | gen6_render_ring_put_irq(struct intel_ring_buffer *ring) |
| 1115 | { |
| 1116 | return gen6_ring_put_irq(ring, |
| 1117 | GT_USER_INTERRUPT, |
| 1118 | GEN6_RENDER_USER_INTERRUPT); |
| 1119 | } |
| 1120 | |
| 1121 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1122 | gen6_bsd_ring_get_irq(struct intel_ring_buffer *ring) |
| 1123 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1124 | return gen6_ring_get_irq(ring, |
| 1125 | GT_GEN6_BSD_USER_INTERRUPT, |
| 1126 | GEN6_BSD_USER_INTERRUPT); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1127 | } |
| 1128 | |
| 1129 | static void |
| 1130 | gen6_bsd_ring_put_irq(struct intel_ring_buffer *ring) |
| 1131 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1132 | return gen6_ring_put_irq(ring, |
| 1133 | GT_GEN6_BSD_USER_INTERRUPT, |
| 1134 | GEN6_BSD_USER_INTERRUPT); |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1135 | } |
| 1136 | |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1137 | /* ring buffer for Video Codec for Gen6+ */ |
Chris Wilson | e070868 | 2010-09-19 14:46:27 +0100 | [diff] [blame] | 1138 | static const struct intel_ring_buffer gen6_bsd_ring = { |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1139 | .name = "gen6 bsd ring", |
| 1140 | .id = RING_BSD, |
| 1141 | .mmio_base = GEN6_BSD_RING_BASE, |
| 1142 | .size = 32 * PAGE_SIZE, |
| 1143 | .init = init_ring_common, |
| 1144 | .write_tail = gen6_bsd_ring_write_tail, |
| 1145 | .flush = gen6_ring_flush, |
| 1146 | .add_request = gen6_add_request, |
| 1147 | .get_seqno = ring_get_seqno, |
| 1148 | .irq_get = gen6_bsd_ring_get_irq, |
| 1149 | .irq_put = gen6_bsd_ring_put_irq, |
| 1150 | .dispatch_execbuffer = gen6_ring_dispatch_execbuffer, |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1151 | }; |
| 1152 | |
| 1153 | /* Blitter support (SandyBridge+) */ |
| 1154 | |
Chris Wilson | b13c2b9 | 2010-12-13 16:54:50 +0000 | [diff] [blame] | 1155 | static bool |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1156 | blt_ring_get_irq(struct intel_ring_buffer *ring) |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1157 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1158 | return gen6_ring_get_irq(ring, |
| 1159 | GT_BLT_USER_INTERRUPT, |
| 1160 | GEN6_BLITTER_USER_INTERRUPT); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1161 | } |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1162 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1163 | static void |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1164 | blt_ring_put_irq(struct intel_ring_buffer *ring) |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1165 | { |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1166 | gen6_ring_put_irq(ring, |
| 1167 | GT_BLT_USER_INTERRUPT, |
| 1168 | GEN6_BLITTER_USER_INTERRUPT); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1169 | } |
| 1170 | |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1171 | |
| 1172 | /* Workaround for some stepping of SNB, |
| 1173 | * each time when BLT engine ring tail moved, |
| 1174 | * the first command in the ring to be parsed |
| 1175 | * should be MI_BATCH_BUFFER_START |
| 1176 | */ |
| 1177 | #define NEED_BLT_WORKAROUND(dev) \ |
| 1178 | (IS_GEN6(dev) && (dev->pdev->revision < 8)) |
| 1179 | |
| 1180 | static inline struct drm_i915_gem_object * |
| 1181 | to_blt_workaround(struct intel_ring_buffer *ring) |
| 1182 | { |
| 1183 | return ring->private; |
| 1184 | } |
| 1185 | |
| 1186 | static int blt_ring_init(struct intel_ring_buffer *ring) |
| 1187 | { |
| 1188 | if (NEED_BLT_WORKAROUND(ring->dev)) { |
| 1189 | struct drm_i915_gem_object *obj; |
Chris Wilson | 27153f7 | 2010-11-02 11:17:23 +0000 | [diff] [blame] | 1190 | u32 *ptr; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1191 | int ret; |
| 1192 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1193 | obj = i915_gem_alloc_object(ring->dev, 4096); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1194 | if (obj == NULL) |
| 1195 | return -ENOMEM; |
| 1196 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1197 | ret = i915_gem_object_pin(obj, 4096, true); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1198 | if (ret) { |
| 1199 | drm_gem_object_unreference(&obj->base); |
| 1200 | return ret; |
| 1201 | } |
| 1202 | |
| 1203 | ptr = kmap(obj->pages[0]); |
Chris Wilson | 27153f7 | 2010-11-02 11:17:23 +0000 | [diff] [blame] | 1204 | *ptr++ = MI_BATCH_BUFFER_END; |
| 1205 | *ptr++ = MI_NOOP; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1206 | kunmap(obj->pages[0]); |
| 1207 | |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1208 | ret = i915_gem_object_set_to_gtt_domain(obj, false); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1209 | if (ret) { |
Chris Wilson | 05394f3 | 2010-11-08 19:18:58 +0000 | [diff] [blame] | 1210 | i915_gem_object_unpin(obj); |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1211 | drm_gem_object_unreference(&obj->base); |
| 1212 | return ret; |
| 1213 | } |
| 1214 | |
| 1215 | ring->private = obj; |
| 1216 | } |
| 1217 | |
| 1218 | return init_ring_common(ring); |
| 1219 | } |
| 1220 | |
| 1221 | static int blt_ring_begin(struct intel_ring_buffer *ring, |
| 1222 | int num_dwords) |
| 1223 | { |
| 1224 | if (ring->private) { |
| 1225 | int ret = intel_ring_begin(ring, num_dwords+2); |
| 1226 | if (ret) |
| 1227 | return ret; |
| 1228 | |
| 1229 | intel_ring_emit(ring, MI_BATCH_BUFFER_START); |
| 1230 | intel_ring_emit(ring, to_blt_workaround(ring)->gtt_offset); |
| 1231 | |
| 1232 | return 0; |
| 1233 | } else |
| 1234 | return intel_ring_begin(ring, 4); |
| 1235 | } |
| 1236 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1237 | static int blt_ring_flush(struct intel_ring_buffer *ring, |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1238 | u32 invalidate, u32 flush) |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1239 | { |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1240 | uint32_t cmd; |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1241 | int ret; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1242 | |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1243 | ret = blt_ring_begin(ring, 4); |
| 1244 | if (ret) |
| 1245 | return ret; |
| 1246 | |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1247 | cmd = MI_FLUSH_DW; |
| 1248 | if (invalidate & I915_GEM_DOMAIN_RENDER) |
| 1249 | cmd |= MI_INVALIDATE_TLB; |
| 1250 | intel_ring_emit(ring, cmd); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1251 | intel_ring_emit(ring, 0); |
| 1252 | intel_ring_emit(ring, 0); |
Chris Wilson | 71a77e0 | 2011-02-02 12:13:49 +0000 | [diff] [blame] | 1253 | intel_ring_emit(ring, MI_NOOP); |
Chris Wilson | b72f3ac | 2011-01-04 17:34:02 +0000 | [diff] [blame] | 1254 | intel_ring_advance(ring); |
| 1255 | return 0; |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1256 | } |
| 1257 | |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1258 | static void blt_ring_cleanup(struct intel_ring_buffer *ring) |
| 1259 | { |
| 1260 | if (!ring->private) |
| 1261 | return; |
| 1262 | |
| 1263 | i915_gem_object_unpin(ring->private); |
| 1264 | drm_gem_object_unreference(ring->private); |
| 1265 | ring->private = NULL; |
| 1266 | } |
| 1267 | |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1268 | static const struct intel_ring_buffer gen6_blt_ring = { |
| 1269 | .name = "blt ring", |
| 1270 | .id = RING_BLT, |
| 1271 | .mmio_base = BLT_RING_BASE, |
| 1272 | .size = 32 * PAGE_SIZE, |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1273 | .init = blt_ring_init, |
Chris Wilson | 297b0c5 | 2010-10-22 17:02:41 +0100 | [diff] [blame] | 1274 | .write_tail = ring_write_tail, |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1275 | .flush = blt_ring_flush, |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1276 | .add_request = gen6_add_request, |
| 1277 | .get_seqno = ring_get_seqno, |
| 1278 | .irq_get = blt_ring_get_irq, |
| 1279 | .irq_put = blt_ring_put_irq, |
Chris Wilson | 78501ea | 2010-10-27 12:18:21 +0100 | [diff] [blame] | 1280 | .dispatch_execbuffer = gen6_ring_dispatch_execbuffer, |
Zou Nan hai | 8d19215 | 2010-11-02 16:31:01 +0800 | [diff] [blame] | 1281 | .cleanup = blt_ring_cleanup, |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1282 | }; |
| 1283 | |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1284 | int intel_init_render_ring_buffer(struct drm_device *dev) |
| 1285 | { |
| 1286 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1287 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1288 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1289 | *ring = render_ring; |
| 1290 | if (INTEL_INFO(dev)->gen >= 6) { |
| 1291 | ring->add_request = gen6_add_request; |
Chris Wilson | 0f46832 | 2011-01-04 17:35:21 +0000 | [diff] [blame] | 1292 | ring->irq_get = gen6_render_ring_get_irq; |
| 1293 | ring->irq_put = gen6_render_ring_put_irq; |
Chris Wilson | c6df541 | 2010-12-15 09:56:50 +0000 | [diff] [blame] | 1294 | } else if (IS_GEN5(dev)) { |
| 1295 | ring->add_request = pc_render_add_request; |
| 1296 | ring->get_seqno = pc_render_get_seqno; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1297 | } |
| 1298 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1299 | if (!I915_NEED_GFX_HWS(dev)) { |
| 1300 | ring->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
| 1301 | memset(ring->status_page.page_addr, 0, PAGE_SIZE); |
| 1302 | } |
| 1303 | |
| 1304 | return intel_init_ring_buffer(dev, ring); |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1305 | } |
| 1306 | |
Chris Wilson | e8616b6 | 2011-01-20 09:57:11 +0000 | [diff] [blame] | 1307 | int intel_render_ring_init_dri(struct drm_device *dev, u64 start, u32 size) |
| 1308 | { |
| 1309 | drm_i915_private_t *dev_priv = dev->dev_private; |
| 1310 | struct intel_ring_buffer *ring = &dev_priv->ring[RCS]; |
| 1311 | |
| 1312 | *ring = render_ring; |
| 1313 | if (INTEL_INFO(dev)->gen >= 6) { |
| 1314 | ring->add_request = gen6_add_request; |
| 1315 | ring->irq_get = gen6_render_ring_get_irq; |
| 1316 | ring->irq_put = gen6_render_ring_put_irq; |
| 1317 | } else if (IS_GEN5(dev)) { |
| 1318 | ring->add_request = pc_render_add_request; |
| 1319 | ring->get_seqno = pc_render_get_seqno; |
| 1320 | } |
| 1321 | |
| 1322 | ring->dev = dev; |
| 1323 | INIT_LIST_HEAD(&ring->active_list); |
| 1324 | INIT_LIST_HEAD(&ring->request_list); |
| 1325 | INIT_LIST_HEAD(&ring->gpu_write_list); |
| 1326 | |
| 1327 | ring->size = size; |
| 1328 | ring->effective_size = ring->size; |
| 1329 | if (IS_I830(ring->dev)) |
| 1330 | ring->effective_size -= 128; |
| 1331 | |
| 1332 | ring->map.offset = start; |
| 1333 | ring->map.size = size; |
| 1334 | ring->map.type = 0; |
| 1335 | ring->map.flags = 0; |
| 1336 | ring->map.mtrr = 0; |
| 1337 | |
| 1338 | drm_core_ioremap_wc(&ring->map, dev); |
| 1339 | if (ring->map.handle == NULL) { |
| 1340 | DRM_ERROR("can not ioremap virtual address for" |
| 1341 | " ring buffer\n"); |
| 1342 | return -ENOMEM; |
| 1343 | } |
| 1344 | |
| 1345 | ring->virtual_start = (void __force __iomem *)ring->map.handle; |
| 1346 | return 0; |
| 1347 | } |
| 1348 | |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1349 | int intel_init_bsd_ring_buffer(struct drm_device *dev) |
| 1350 | { |
| 1351 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1352 | struct intel_ring_buffer *ring = &dev_priv->ring[VCS]; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1353 | |
Jesse Barnes | 65d3eb1 | 2011-04-06 14:54:44 -0700 | [diff] [blame] | 1354 | if (IS_GEN6(dev) || IS_GEN7(dev)) |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1355 | *ring = gen6_bsd_ring; |
Xiang, Haihao | 881f47b | 2010-09-19 14:40:43 +0100 | [diff] [blame] | 1356 | else |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1357 | *ring = bsd_ring; |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1358 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1359 | return intel_init_ring_buffer(dev, ring); |
Xiang, Haihao | 5c1143b | 2010-09-16 10:43:11 +0800 | [diff] [blame] | 1360 | } |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1361 | |
| 1362 | int intel_init_blt_ring_buffer(struct drm_device *dev) |
| 1363 | { |
| 1364 | drm_i915_private_t *dev_priv = dev->dev_private; |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1365 | struct intel_ring_buffer *ring = &dev_priv->ring[BCS]; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1366 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1367 | *ring = gen6_blt_ring; |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1368 | |
Chris Wilson | 1ec14ad | 2010-12-04 11:30:53 +0000 | [diff] [blame] | 1369 | return intel_init_ring_buffer(dev, ring); |
Chris Wilson | 549f736 | 2010-10-19 11:19:32 +0100 | [diff] [blame] | 1370 | } |