Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Copyright © 2016 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 | */ |
| 24 | |
| 25 | #include "i915_drv.h" |
| 26 | #include "intel_ringbuffer.h" |
| 27 | #include "intel_lrc.h" |
| 28 | |
| 29 | static const struct engine_info { |
| 30 | const char *name; |
| 31 | unsigned exec_id; |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 32 | enum intel_engine_hw_id hw_id; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 33 | u32 mmio_base; |
| 34 | unsigned irq_shift; |
| 35 | int (*init_legacy)(struct intel_engine_cs *engine); |
| 36 | int (*init_execlists)(struct intel_engine_cs *engine); |
| 37 | } intel_engines[] = { |
| 38 | [RCS] = { |
| 39 | .name = "render ring", |
| 40 | .exec_id = I915_EXEC_RENDER, |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 41 | .hw_id = RCS_HW, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 42 | .mmio_base = RENDER_RING_BASE, |
| 43 | .irq_shift = GEN8_RCS_IRQ_SHIFT, |
| 44 | .init_execlists = logical_render_ring_init, |
| 45 | .init_legacy = intel_init_render_ring_buffer, |
| 46 | }, |
| 47 | [BCS] = { |
| 48 | .name = "blitter ring", |
| 49 | .exec_id = I915_EXEC_BLT, |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 50 | .hw_id = BCS_HW, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 51 | .mmio_base = BLT_RING_BASE, |
| 52 | .irq_shift = GEN8_BCS_IRQ_SHIFT, |
| 53 | .init_execlists = logical_xcs_ring_init, |
| 54 | .init_legacy = intel_init_blt_ring_buffer, |
| 55 | }, |
| 56 | [VCS] = { |
| 57 | .name = "bsd ring", |
| 58 | .exec_id = I915_EXEC_BSD, |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 59 | .hw_id = VCS_HW, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 60 | .mmio_base = GEN6_BSD_RING_BASE, |
| 61 | .irq_shift = GEN8_VCS1_IRQ_SHIFT, |
| 62 | .init_execlists = logical_xcs_ring_init, |
| 63 | .init_legacy = intel_init_bsd_ring_buffer, |
| 64 | }, |
| 65 | [VCS2] = { |
| 66 | .name = "bsd2 ring", |
| 67 | .exec_id = I915_EXEC_BSD, |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 68 | .hw_id = VCS2_HW, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 69 | .mmio_base = GEN8_BSD2_RING_BASE, |
| 70 | .irq_shift = GEN8_VCS2_IRQ_SHIFT, |
| 71 | .init_execlists = logical_xcs_ring_init, |
| 72 | .init_legacy = intel_init_bsd2_ring_buffer, |
| 73 | }, |
| 74 | [VECS] = { |
| 75 | .name = "video enhancement ring", |
| 76 | .exec_id = I915_EXEC_VEBOX, |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 77 | .hw_id = VECS_HW, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 78 | .mmio_base = VEBOX_RING_BASE, |
| 79 | .irq_shift = GEN8_VECS_IRQ_SHIFT, |
| 80 | .init_execlists = logical_xcs_ring_init, |
| 81 | .init_legacy = intel_init_vebox_ring_buffer, |
| 82 | }, |
| 83 | }; |
| 84 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 85 | static int |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 86 | intel_engine_setup(struct drm_i915_private *dev_priv, |
| 87 | enum intel_engine_id id) |
| 88 | { |
| 89 | const struct engine_info *info = &intel_engines[id]; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 90 | struct intel_engine_cs *engine; |
| 91 | |
| 92 | GEM_BUG_ON(dev_priv->engine[id]); |
| 93 | engine = kzalloc(sizeof(*engine), GFP_KERNEL); |
| 94 | if (!engine) |
| 95 | return -ENOMEM; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 96 | |
| 97 | engine->id = id; |
| 98 | engine->i915 = dev_priv; |
| 99 | engine->name = info->name; |
| 100 | engine->exec_id = info->exec_id; |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 101 | engine->hw_id = engine->guc_id = info->hw_id; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 102 | engine->mmio_base = info->mmio_base; |
| 103 | engine->irq_shift = info->irq_shift; |
| 104 | |
Chris Wilson | 0de9136 | 2016-11-14 20:41:01 +0000 | [diff] [blame] | 105 | /* Nothing to do here, execute in order of dependencies */ |
| 106 | engine->schedule = NULL; |
| 107 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 108 | dev_priv->engine[id] = engine; |
| 109 | return 0; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 110 | } |
| 111 | |
| 112 | /** |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 113 | * intel_engines_init_early() - allocate the Engine Command Streamers |
Tvrtko Ursulin | bf9e842 | 2016-12-01 14:16:38 +0000 | [diff] [blame] | 114 | * @dev_priv: i915 device private |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 115 | * |
| 116 | * Return: non-zero if the initialization failed. |
| 117 | */ |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 118 | int intel_engines_init_early(struct drm_i915_private *dev_priv) |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 119 | { |
Tvrtko Ursulin | c1bb114 | 2016-08-10 16:22:10 +0100 | [diff] [blame] | 120 | struct intel_device_info *device_info = mkwrite_device_info(dev_priv); |
Tvrtko Ursulin | 70006ad | 2016-10-13 11:02:56 +0100 | [diff] [blame] | 121 | unsigned int ring_mask = INTEL_INFO(dev_priv)->ring_mask; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 122 | unsigned int mask = 0; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 123 | struct intel_engine_cs *engine; |
| 124 | enum intel_engine_id id; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 125 | unsigned int i; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 126 | int err; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 127 | |
Tvrtko Ursulin | 70006ad | 2016-10-13 11:02:56 +0100 | [diff] [blame] | 128 | WARN_ON(ring_mask == 0); |
| 129 | WARN_ON(ring_mask & |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 130 | GENMASK(sizeof(mask) * BITS_PER_BYTE - 1, I915_NUM_ENGINES)); |
| 131 | |
| 132 | for (i = 0; i < ARRAY_SIZE(intel_engines); i++) { |
| 133 | if (!HAS_ENGINE(dev_priv, i)) |
| 134 | continue; |
| 135 | |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 136 | err = intel_engine_setup(dev_priv, i); |
| 137 | if (err) |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 138 | goto cleanup; |
| 139 | |
| 140 | mask |= ENGINE_MASK(i); |
| 141 | } |
| 142 | |
| 143 | /* |
| 144 | * Catch failures to update intel_engines table when the new engines |
| 145 | * are added to the driver by a warning and disabling the forgotten |
| 146 | * engines. |
| 147 | */ |
Tvrtko Ursulin | 70006ad | 2016-10-13 11:02:56 +0100 | [diff] [blame] | 148 | if (WARN_ON(mask != ring_mask)) |
Tvrtko Ursulin | c1bb114 | 2016-08-10 16:22:10 +0100 | [diff] [blame] | 149 | device_info->ring_mask = mask; |
| 150 | |
| 151 | device_info->num_rings = hweight32(mask); |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 152 | |
| 153 | return 0; |
| 154 | |
| 155 | cleanup: |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 156 | for_each_engine(engine, dev_priv, id) |
| 157 | kfree(engine); |
| 158 | return err; |
| 159 | } |
| 160 | |
| 161 | /** |
| 162 | * intel_engines_init() - allocate, populate and init the Engine Command Streamers |
| 163 | * @dev_priv: i915 device private |
| 164 | * |
| 165 | * Return: non-zero if the initialization failed. |
| 166 | */ |
| 167 | int intel_engines_init(struct drm_i915_private *dev_priv) |
| 168 | { |
| 169 | struct intel_device_info *device_info = mkwrite_device_info(dev_priv); |
| 170 | struct intel_engine_cs *engine; |
| 171 | enum intel_engine_id id, err_id; |
| 172 | unsigned int mask = 0; |
| 173 | int err = 0; |
| 174 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 175 | for_each_engine(engine, dev_priv, id) { |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 176 | int (*init)(struct intel_engine_cs *engine); |
| 177 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 178 | if (i915.enable_execlists) |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 179 | init = intel_engines[id].init_execlists; |
| 180 | else |
| 181 | init = intel_engines[id].init_legacy; |
| 182 | if (!init) { |
| 183 | kfree(engine); |
| 184 | dev_priv->engine[id] = NULL; |
| 185 | continue; |
| 186 | } |
| 187 | |
| 188 | err = init(engine); |
| 189 | if (err) { |
| 190 | err_id = id; |
| 191 | goto cleanup; |
| 192 | } |
| 193 | |
| 194 | mask |= ENGINE_MASK(id); |
| 195 | } |
| 196 | |
| 197 | /* |
| 198 | * Catch failures to update intel_engines table when the new engines |
| 199 | * are added to the driver by a warning and disabling the forgotten |
| 200 | * engines. |
| 201 | */ |
| 202 | if (WARN_ON(mask != INTEL_INFO(dev_priv)->ring_mask)) |
| 203 | device_info->ring_mask = mask; |
| 204 | |
| 205 | device_info->num_rings = hweight32(mask); |
| 206 | |
| 207 | return 0; |
| 208 | |
| 209 | cleanup: |
| 210 | for_each_engine(engine, dev_priv, id) { |
| 211 | if (id >= err_id) |
| 212 | kfree(engine); |
| 213 | else if (i915.enable_execlists) |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 214 | intel_logical_ring_cleanup(engine); |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 215 | else |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 216 | intel_engine_cleanup(engine); |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 217 | } |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame^] | 218 | return err; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 219 | } |
| 220 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 221 | void intel_engine_init_global_seqno(struct intel_engine_cs *engine, u32 seqno) |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 222 | { |
| 223 | struct drm_i915_private *dev_priv = engine->i915; |
| 224 | |
| 225 | /* Our semaphore implementation is strictly monotonic (i.e. we proceed |
| 226 | * so long as the semaphore value in the register/page is greater |
| 227 | * than the sync value), so whenever we reset the seqno, |
| 228 | * so long as we reset the tracking semaphore value to 0, it will |
| 229 | * always be before the next request's seqno. If we don't reset |
| 230 | * the semaphore value, then when the seqno moves backwards all |
| 231 | * future waits will complete instantly (causing rendering corruption). |
| 232 | */ |
| 233 | if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) { |
| 234 | I915_WRITE(RING_SYNC_0(engine->mmio_base), 0); |
| 235 | I915_WRITE(RING_SYNC_1(engine->mmio_base), 0); |
| 236 | if (HAS_VEBOX(dev_priv)) |
| 237 | I915_WRITE(RING_SYNC_2(engine->mmio_base), 0); |
| 238 | } |
Chris Wilson | 51d545d | 2016-08-15 10:49:02 +0100 | [diff] [blame] | 239 | if (dev_priv->semaphore) { |
| 240 | struct page *page = i915_vma_first_page(dev_priv->semaphore); |
| 241 | void *semaphores; |
| 242 | |
| 243 | /* Semaphores are in noncoherent memory, flush to be safe */ |
| 244 | semaphores = kmap(page); |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 245 | memset(semaphores + GEN8_SEMAPHORE_OFFSET(engine->id, 0), |
| 246 | 0, I915_NUM_ENGINES * gen8_semaphore_seqno_size); |
Chris Wilson | 51d545d | 2016-08-15 10:49:02 +0100 | [diff] [blame] | 247 | drm_clflush_virt_range(semaphores + GEN8_SEMAPHORE_OFFSET(engine->id, 0), |
| 248 | I915_NUM_ENGINES * gen8_semaphore_seqno_size); |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 249 | kunmap(page); |
| 250 | } |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 251 | |
| 252 | intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno); |
| 253 | if (engine->irq_seqno_barrier) |
| 254 | engine->irq_seqno_barrier(engine); |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 255 | |
| 256 | GEM_BUG_ON(i915_gem_active_isset(&engine->timeline->last_request)); |
| 257 | engine->timeline->last_submitted_seqno = seqno; |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 258 | |
| 259 | engine->hangcheck.seqno = seqno; |
| 260 | |
| 261 | /* After manually advancing the seqno, fake the interrupt in case |
| 262 | * there are any waiters for that seqno. |
| 263 | */ |
| 264 | intel_engine_wakeup(engine); |
| 265 | } |
| 266 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 267 | static void intel_engine_init_timeline(struct intel_engine_cs *engine) |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 268 | { |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 269 | engine->timeline = &engine->i915->gt.global_timeline.engine[engine->id]; |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 270 | } |
| 271 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 272 | /** |
| 273 | * intel_engines_setup_common - setup engine state not requiring hw access |
| 274 | * @engine: Engine to setup. |
| 275 | * |
| 276 | * Initializes @engine@ structure members shared between legacy and execlists |
| 277 | * submission modes which do not require hardware access. |
| 278 | * |
| 279 | * Typically done early in the submission mode specific engine setup stage. |
| 280 | */ |
| 281 | void intel_engine_setup_common(struct intel_engine_cs *engine) |
| 282 | { |
Chris Wilson | 20311bd | 2016-11-14 20:41:03 +0000 | [diff] [blame] | 283 | engine->execlist_queue = RB_ROOT; |
| 284 | engine->execlist_first = NULL; |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 285 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 286 | intel_engine_init_timeline(engine); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 287 | intel_engine_init_hangcheck(engine); |
Chris Wilson | 115003e9 | 2016-08-04 16:32:19 +0100 | [diff] [blame] | 288 | i915_gem_batch_pool_init(engine, &engine->batch_pool); |
Chris Wilson | 7756e45 | 2016-08-18 17:17:10 +0100 | [diff] [blame] | 289 | |
| 290 | intel_engine_init_cmd_parser(engine); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 291 | } |
| 292 | |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 293 | int intel_engine_create_scratch(struct intel_engine_cs *engine, int size) |
| 294 | { |
| 295 | struct drm_i915_gem_object *obj; |
| 296 | struct i915_vma *vma; |
| 297 | int ret; |
| 298 | |
| 299 | WARN_ON(engine->scratch); |
| 300 | |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 301 | obj = i915_gem_object_create_stolen(engine->i915, size); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 302 | if (!obj) |
Chris Wilson | 920cf41 | 2016-10-28 13:58:30 +0100 | [diff] [blame] | 303 | obj = i915_gem_object_create_internal(engine->i915, size); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 304 | if (IS_ERR(obj)) { |
| 305 | DRM_ERROR("Failed to allocate scratch page\n"); |
| 306 | return PTR_ERR(obj); |
| 307 | } |
| 308 | |
Chris Wilson | a01cb37 | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 309 | vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 310 | if (IS_ERR(vma)) { |
| 311 | ret = PTR_ERR(vma); |
| 312 | goto err_unref; |
| 313 | } |
| 314 | |
| 315 | ret = i915_vma_pin(vma, 0, 4096, PIN_GLOBAL | PIN_HIGH); |
| 316 | if (ret) |
| 317 | goto err_unref; |
| 318 | |
| 319 | engine->scratch = vma; |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 320 | DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n", |
| 321 | engine->name, i915_ggtt_offset(vma)); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 322 | return 0; |
| 323 | |
| 324 | err_unref: |
| 325 | i915_gem_object_put(obj); |
| 326 | return ret; |
| 327 | } |
| 328 | |
| 329 | static void intel_engine_cleanup_scratch(struct intel_engine_cs *engine) |
| 330 | { |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 331 | i915_vma_unpin_and_release(&engine->scratch); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 332 | } |
| 333 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 334 | /** |
| 335 | * intel_engines_init_common - initialize cengine state which might require hw access |
| 336 | * @engine: Engine to initialize. |
| 337 | * |
| 338 | * Initializes @engine@ structure members shared between legacy and execlists |
| 339 | * submission modes which do require hardware access. |
| 340 | * |
| 341 | * Typcally done at later stages of submission mode specific engine setup. |
| 342 | * |
| 343 | * Returns zero on success or an error code on failure. |
| 344 | */ |
| 345 | int intel_engine_init_common(struct intel_engine_cs *engine) |
| 346 | { |
| 347 | int ret; |
| 348 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 349 | /* We may need to do things with the shrinker which |
| 350 | * require us to immediately switch back to the default |
| 351 | * context. This can cause a problem as pinning the |
| 352 | * default context also requires GTT space which may not |
| 353 | * be available. To avoid this we always pin the default |
| 354 | * context. |
| 355 | */ |
| 356 | ret = engine->context_pin(engine, engine->i915->kernel_context); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 357 | if (ret) |
| 358 | return ret; |
| 359 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 360 | ret = intel_engine_init_breadcrumbs(engine); |
| 361 | if (ret) |
| 362 | goto err_unpin; |
| 363 | |
Chris Wilson | 4e50f08 | 2016-10-28 13:58:31 +0100 | [diff] [blame] | 364 | ret = i915_gem_render_state_init(engine); |
| 365 | if (ret) |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 366 | goto err_unpin; |
Chris Wilson | 4e50f08 | 2016-10-28 13:58:31 +0100 | [diff] [blame] | 367 | |
Chris Wilson | 7756e45 | 2016-08-18 17:17:10 +0100 | [diff] [blame] | 368 | return 0; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 369 | |
| 370 | err_unpin: |
| 371 | engine->context_unpin(engine, engine->i915->kernel_context); |
| 372 | return ret; |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 373 | } |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 374 | |
| 375 | /** |
| 376 | * intel_engines_cleanup_common - cleans up the engine state created by |
| 377 | * the common initiailizers. |
| 378 | * @engine: Engine to cleanup. |
| 379 | * |
| 380 | * This cleans up everything created by the common helpers. |
| 381 | */ |
| 382 | void intel_engine_cleanup_common(struct intel_engine_cs *engine) |
| 383 | { |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 384 | intel_engine_cleanup_scratch(engine); |
| 385 | |
Chris Wilson | 4e50f08 | 2016-10-28 13:58:31 +0100 | [diff] [blame] | 386 | i915_gem_render_state_fini(engine); |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 387 | intel_engine_fini_breadcrumbs(engine); |
Chris Wilson | 7756e45 | 2016-08-18 17:17:10 +0100 | [diff] [blame] | 388 | intel_engine_cleanup_cmd_parser(engine); |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 389 | i915_gem_batch_pool_fini(&engine->batch_pool); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 390 | |
| 391 | engine->context_unpin(engine, engine->i915->kernel_context); |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 392 | } |
Chris Wilson | 1b36595 | 2016-10-04 21:11:31 +0100 | [diff] [blame] | 393 | |
| 394 | u64 intel_engine_get_active_head(struct intel_engine_cs *engine) |
| 395 | { |
| 396 | struct drm_i915_private *dev_priv = engine->i915; |
| 397 | u64 acthd; |
| 398 | |
| 399 | if (INTEL_GEN(dev_priv) >= 8) |
| 400 | acthd = I915_READ64_2x32(RING_ACTHD(engine->mmio_base), |
| 401 | RING_ACTHD_UDW(engine->mmio_base)); |
| 402 | else if (INTEL_GEN(dev_priv) >= 4) |
| 403 | acthd = I915_READ(RING_ACTHD(engine->mmio_base)); |
| 404 | else |
| 405 | acthd = I915_READ(ACTHD); |
| 406 | |
| 407 | return acthd; |
| 408 | } |
| 409 | |
| 410 | u64 intel_engine_get_last_batch_head(struct intel_engine_cs *engine) |
| 411 | { |
| 412 | struct drm_i915_private *dev_priv = engine->i915; |
| 413 | u64 bbaddr; |
| 414 | |
| 415 | if (INTEL_GEN(dev_priv) >= 8) |
| 416 | bbaddr = I915_READ64_2x32(RING_BBADDR(engine->mmio_base), |
| 417 | RING_BBADDR_UDW(engine->mmio_base)); |
| 418 | else |
| 419 | bbaddr = I915_READ(RING_BBADDR(engine->mmio_base)); |
| 420 | |
| 421 | return bbaddr; |
| 422 | } |
Chris Wilson | 0e70447 | 2016-10-12 10:05:17 +0100 | [diff] [blame] | 423 | |
| 424 | const char *i915_cache_level_str(struct drm_i915_private *i915, int type) |
| 425 | { |
| 426 | switch (type) { |
| 427 | case I915_CACHE_NONE: return " uncached"; |
| 428 | case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped"; |
| 429 | case I915_CACHE_L3_LLC: return " L3+LLC"; |
| 430 | case I915_CACHE_WT: return " WT"; |
| 431 | default: return ""; |
| 432 | } |
| 433 | } |
| 434 | |
| 435 | static inline uint32_t |
| 436 | read_subslice_reg(struct drm_i915_private *dev_priv, int slice, |
| 437 | int subslice, i915_reg_t reg) |
| 438 | { |
| 439 | uint32_t mcr; |
| 440 | uint32_t ret; |
| 441 | enum forcewake_domains fw_domains; |
| 442 | |
| 443 | fw_domains = intel_uncore_forcewake_for_reg(dev_priv, reg, |
| 444 | FW_REG_READ); |
| 445 | fw_domains |= intel_uncore_forcewake_for_reg(dev_priv, |
| 446 | GEN8_MCR_SELECTOR, |
| 447 | FW_REG_READ | FW_REG_WRITE); |
| 448 | |
| 449 | spin_lock_irq(&dev_priv->uncore.lock); |
| 450 | intel_uncore_forcewake_get__locked(dev_priv, fw_domains); |
| 451 | |
| 452 | mcr = I915_READ_FW(GEN8_MCR_SELECTOR); |
| 453 | /* |
| 454 | * The HW expects the slice and sublice selectors to be reset to 0 |
| 455 | * after reading out the registers. |
| 456 | */ |
| 457 | WARN_ON_ONCE(mcr & (GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK)); |
| 458 | mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK); |
| 459 | mcr |= GEN8_MCR_SLICE(slice) | GEN8_MCR_SUBSLICE(subslice); |
| 460 | I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr); |
| 461 | |
| 462 | ret = I915_READ_FW(reg); |
| 463 | |
| 464 | mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK); |
| 465 | I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr); |
| 466 | |
| 467 | intel_uncore_forcewake_put__locked(dev_priv, fw_domains); |
| 468 | spin_unlock_irq(&dev_priv->uncore.lock); |
| 469 | |
| 470 | return ret; |
| 471 | } |
| 472 | |
| 473 | /* NB: please notice the memset */ |
| 474 | void intel_engine_get_instdone(struct intel_engine_cs *engine, |
| 475 | struct intel_instdone *instdone) |
| 476 | { |
| 477 | struct drm_i915_private *dev_priv = engine->i915; |
| 478 | u32 mmio_base = engine->mmio_base; |
| 479 | int slice; |
| 480 | int subslice; |
| 481 | |
| 482 | memset(instdone, 0, sizeof(*instdone)); |
| 483 | |
| 484 | switch (INTEL_GEN(dev_priv)) { |
| 485 | default: |
| 486 | instdone->instdone = I915_READ(RING_INSTDONE(mmio_base)); |
| 487 | |
| 488 | if (engine->id != RCS) |
| 489 | break; |
| 490 | |
| 491 | instdone->slice_common = I915_READ(GEN7_SC_INSTDONE); |
| 492 | for_each_instdone_slice_subslice(dev_priv, slice, subslice) { |
| 493 | instdone->sampler[slice][subslice] = |
| 494 | read_subslice_reg(dev_priv, slice, subslice, |
| 495 | GEN7_SAMPLER_INSTDONE); |
| 496 | instdone->row[slice][subslice] = |
| 497 | read_subslice_reg(dev_priv, slice, subslice, |
| 498 | GEN7_ROW_INSTDONE); |
| 499 | } |
| 500 | break; |
| 501 | case 7: |
| 502 | instdone->instdone = I915_READ(RING_INSTDONE(mmio_base)); |
| 503 | |
| 504 | if (engine->id != RCS) |
| 505 | break; |
| 506 | |
| 507 | instdone->slice_common = I915_READ(GEN7_SC_INSTDONE); |
| 508 | instdone->sampler[0][0] = I915_READ(GEN7_SAMPLER_INSTDONE); |
| 509 | instdone->row[0][0] = I915_READ(GEN7_ROW_INSTDONE); |
| 510 | |
| 511 | break; |
| 512 | case 6: |
| 513 | case 5: |
| 514 | case 4: |
| 515 | instdone->instdone = I915_READ(RING_INSTDONE(mmio_base)); |
| 516 | |
| 517 | if (engine->id == RCS) |
| 518 | /* HACK: Using the wrong struct member */ |
| 519 | instdone->slice_common = I915_READ(GEN4_INSTDONE1); |
| 520 | break; |
| 521 | case 3: |
| 522 | case 2: |
| 523 | instdone->instdone = I915_READ(GEN2_INSTDONE); |
| 524 | break; |
| 525 | } |
| 526 | } |