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 | |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 25 | #include <drm/drm_print.h> |
| 26 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 27 | #include "i915_drv.h" |
Weinan Li | 1fd51d9 | 2017-10-15 11:55:25 +0800 | [diff] [blame] | 28 | #include "i915_vgpu.h" |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 29 | #include "intel_ringbuffer.h" |
| 30 | #include "intel_lrc.h" |
| 31 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 32 | /* Haswell does have the CXT_SIZE register however it does not appear to be |
| 33 | * valid. Now, docs explain in dwords what is in the context object. The full |
| 34 | * size is 70720 bytes, however, the power context and execlist context will |
| 35 | * never be saved (power context is stored elsewhere, and execlists don't work |
| 36 | * on HSW) - so the final size, including the extra state required for the |
| 37 | * Resource Streamer, is 66944 bytes, which rounds to 17 pages. |
| 38 | */ |
| 39 | #define HSW_CXT_TOTAL_SIZE (17 * PAGE_SIZE) |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 40 | |
| 41 | #define GEN8_LR_CONTEXT_RENDER_SIZE (20 * PAGE_SIZE) |
| 42 | #define GEN9_LR_CONTEXT_RENDER_SIZE (22 * PAGE_SIZE) |
Oscar Mateo | 3cf1934 | 2017-10-04 08:39:52 -0700 | [diff] [blame] | 43 | #define GEN10_LR_CONTEXT_RENDER_SIZE (18 * PAGE_SIZE) |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 44 | |
| 45 | #define GEN8_LR_CONTEXT_OTHER_SIZE ( 2 * PAGE_SIZE) |
| 46 | |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 47 | struct engine_class_info { |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 48 | const char *name; |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 49 | int (*init_legacy)(struct intel_engine_cs *engine); |
| 50 | int (*init_execlists)(struct intel_engine_cs *engine); |
Tvrtko Ursulin | 1803fcbc | 2017-11-10 14:26:27 +0000 | [diff] [blame] | 51 | |
| 52 | u8 uabi_class; |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 53 | }; |
| 54 | |
| 55 | static const struct engine_class_info intel_engine_classes[] = { |
| 56 | [RENDER_CLASS] = { |
| 57 | .name = "rcs", |
| 58 | .init_execlists = logical_render_ring_init, |
| 59 | .init_legacy = intel_init_render_ring_buffer, |
Tvrtko Ursulin | 1803fcbc | 2017-11-10 14:26:27 +0000 | [diff] [blame] | 60 | .uabi_class = I915_ENGINE_CLASS_RENDER, |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 61 | }, |
| 62 | [COPY_ENGINE_CLASS] = { |
| 63 | .name = "bcs", |
| 64 | .init_execlists = logical_xcs_ring_init, |
| 65 | .init_legacy = intel_init_blt_ring_buffer, |
Tvrtko Ursulin | 1803fcbc | 2017-11-10 14:26:27 +0000 | [diff] [blame] | 66 | .uabi_class = I915_ENGINE_CLASS_COPY, |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 67 | }, |
| 68 | [VIDEO_DECODE_CLASS] = { |
| 69 | .name = "vcs", |
| 70 | .init_execlists = logical_xcs_ring_init, |
| 71 | .init_legacy = intel_init_bsd_ring_buffer, |
Tvrtko Ursulin | 1803fcbc | 2017-11-10 14:26:27 +0000 | [diff] [blame] | 72 | .uabi_class = I915_ENGINE_CLASS_VIDEO, |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 73 | }, |
| 74 | [VIDEO_ENHANCEMENT_CLASS] = { |
| 75 | .name = "vecs", |
| 76 | .init_execlists = logical_xcs_ring_init, |
| 77 | .init_legacy = intel_init_vebox_ring_buffer, |
Tvrtko Ursulin | 1803fcbc | 2017-11-10 14:26:27 +0000 | [diff] [blame] | 78 | .uabi_class = I915_ENGINE_CLASS_VIDEO_ENHANCE, |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 79 | }, |
| 80 | }; |
| 81 | |
| 82 | struct engine_info { |
Michal Wajdeczko | 237ae7c | 2017-03-01 20:26:15 +0000 | [diff] [blame] | 83 | unsigned int hw_id; |
Chris Wilson | 1d39f28 | 2017-04-11 13:43:06 +0100 | [diff] [blame] | 84 | unsigned int uabi_id; |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 85 | u8 class; |
| 86 | u8 instance; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 87 | u32 mmio_base; |
| 88 | unsigned irq_shift; |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 89 | }; |
| 90 | |
| 91 | static const struct engine_info intel_engines[] = { |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 92 | [RCS] = { |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 93 | .hw_id = RCS_HW, |
Chris Wilson | 1d39f28 | 2017-04-11 13:43:06 +0100 | [diff] [blame] | 94 | .uabi_id = I915_EXEC_RENDER, |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 95 | .class = RENDER_CLASS, |
| 96 | .instance = 0, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 97 | .mmio_base = RENDER_RING_BASE, |
| 98 | .irq_shift = GEN8_RCS_IRQ_SHIFT, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 99 | }, |
| 100 | [BCS] = { |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 101 | .hw_id = BCS_HW, |
Chris Wilson | 1d39f28 | 2017-04-11 13:43:06 +0100 | [diff] [blame] | 102 | .uabi_id = I915_EXEC_BLT, |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 103 | .class = COPY_ENGINE_CLASS, |
| 104 | .instance = 0, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 105 | .mmio_base = BLT_RING_BASE, |
| 106 | .irq_shift = GEN8_BCS_IRQ_SHIFT, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 107 | }, |
| 108 | [VCS] = { |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 109 | .hw_id = VCS_HW, |
Chris Wilson | 1d39f28 | 2017-04-11 13:43:06 +0100 | [diff] [blame] | 110 | .uabi_id = I915_EXEC_BSD, |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 111 | .class = VIDEO_DECODE_CLASS, |
| 112 | .instance = 0, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 113 | .mmio_base = GEN6_BSD_RING_BASE, |
| 114 | .irq_shift = GEN8_VCS1_IRQ_SHIFT, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 115 | }, |
| 116 | [VCS2] = { |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 117 | .hw_id = VCS2_HW, |
Chris Wilson | 1d39f28 | 2017-04-11 13:43:06 +0100 | [diff] [blame] | 118 | .uabi_id = I915_EXEC_BSD, |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 119 | .class = VIDEO_DECODE_CLASS, |
| 120 | .instance = 1, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 121 | .mmio_base = GEN8_BSD2_RING_BASE, |
| 122 | .irq_shift = GEN8_VCS2_IRQ_SHIFT, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 123 | }, |
| 124 | [VECS] = { |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 125 | .hw_id = VECS_HW, |
Chris Wilson | 1d39f28 | 2017-04-11 13:43:06 +0100 | [diff] [blame] | 126 | .uabi_id = I915_EXEC_VEBOX, |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 127 | .class = VIDEO_ENHANCEMENT_CLASS, |
| 128 | .instance = 0, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 129 | .mmio_base = VEBOX_RING_BASE, |
| 130 | .irq_shift = GEN8_VECS_IRQ_SHIFT, |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 131 | }, |
| 132 | }; |
| 133 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 134 | /** |
| 135 | * ___intel_engine_context_size() - return the size of the context for an engine |
| 136 | * @dev_priv: i915 device private |
| 137 | * @class: engine class |
| 138 | * |
| 139 | * Each engine class may require a different amount of space for a context |
| 140 | * image. |
| 141 | * |
| 142 | * Return: size (in bytes) of an engine class specific context image |
| 143 | * |
| 144 | * Note: this size includes the HWSP, which is part of the context image |
| 145 | * in LRC mode, but does not include the "shared data page" used with |
| 146 | * GuC submission. The caller should account for this if using the GuC. |
| 147 | */ |
| 148 | static u32 |
| 149 | __intel_engine_context_size(struct drm_i915_private *dev_priv, u8 class) |
| 150 | { |
| 151 | u32 cxt_size; |
| 152 | |
| 153 | BUILD_BUG_ON(I915_GTT_PAGE_SIZE != PAGE_SIZE); |
| 154 | |
| 155 | switch (class) { |
| 156 | case RENDER_CLASS: |
| 157 | switch (INTEL_GEN(dev_priv)) { |
| 158 | default: |
| 159 | MISSING_CASE(INTEL_GEN(dev_priv)); |
Rodrigo Vivi | f65f841 | 2017-07-06 14:06:24 -0700 | [diff] [blame] | 160 | case 10: |
Oscar Mateo | 7fd0b1a | 2017-09-21 16:19:49 -0700 | [diff] [blame] | 161 | return GEN10_LR_CONTEXT_RENDER_SIZE; |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 162 | case 9: |
| 163 | return GEN9_LR_CONTEXT_RENDER_SIZE; |
| 164 | case 8: |
Chris Wilson | fb5c551 | 2017-11-20 20:55:00 +0000 | [diff] [blame] | 165 | return GEN8_LR_CONTEXT_RENDER_SIZE; |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 166 | case 7: |
| 167 | if (IS_HASWELL(dev_priv)) |
| 168 | return HSW_CXT_TOTAL_SIZE; |
| 169 | |
| 170 | cxt_size = I915_READ(GEN7_CXT_SIZE); |
| 171 | return round_up(GEN7_CXT_TOTAL_SIZE(cxt_size) * 64, |
| 172 | PAGE_SIZE); |
| 173 | case 6: |
| 174 | cxt_size = I915_READ(CXT_SIZE); |
| 175 | return round_up(GEN6_CXT_TOTAL_SIZE(cxt_size) * 64, |
| 176 | PAGE_SIZE); |
| 177 | case 5: |
| 178 | case 4: |
| 179 | case 3: |
| 180 | case 2: |
| 181 | /* For the special day when i810 gets merged. */ |
| 182 | case 1: |
| 183 | return 0; |
| 184 | } |
| 185 | break; |
| 186 | default: |
| 187 | MISSING_CASE(class); |
| 188 | case VIDEO_DECODE_CLASS: |
| 189 | case VIDEO_ENHANCEMENT_CLASS: |
| 190 | case COPY_ENGINE_CLASS: |
| 191 | if (INTEL_GEN(dev_priv) < 8) |
| 192 | return 0; |
| 193 | return GEN8_LR_CONTEXT_OTHER_SIZE; |
| 194 | } |
| 195 | } |
| 196 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 197 | static int |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 198 | intel_engine_setup(struct drm_i915_private *dev_priv, |
| 199 | enum intel_engine_id id) |
| 200 | { |
| 201 | const struct engine_info *info = &intel_engines[id]; |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 202 | const struct engine_class_info *class_info; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 203 | struct intel_engine_cs *engine; |
| 204 | |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 205 | GEM_BUG_ON(info->class >= ARRAY_SIZE(intel_engine_classes)); |
| 206 | class_info = &intel_engine_classes[info->class]; |
| 207 | |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 208 | if (GEM_WARN_ON(info->class > MAX_ENGINE_CLASS)) |
| 209 | return -EINVAL; |
| 210 | |
| 211 | if (GEM_WARN_ON(info->instance > MAX_ENGINE_INSTANCE)) |
| 212 | return -EINVAL; |
| 213 | |
| 214 | if (GEM_WARN_ON(dev_priv->engine_class[info->class][info->instance])) |
| 215 | return -EINVAL; |
| 216 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 217 | GEM_BUG_ON(dev_priv->engine[id]); |
| 218 | engine = kzalloc(sizeof(*engine), GFP_KERNEL); |
| 219 | if (!engine) |
| 220 | return -ENOMEM; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 221 | |
| 222 | engine->id = id; |
| 223 | engine->i915 = dev_priv; |
Oscar Mateo | 6e51614 | 2017-04-10 07:34:31 -0700 | [diff] [blame] | 224 | WARN_ON(snprintf(engine->name, sizeof(engine->name), "%s%u", |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 225 | class_info->name, info->instance) >= |
| 226 | sizeof(engine->name)); |
Tvrtko Ursulin | 5ec2cf7 | 2016-08-16 17:04:20 +0100 | [diff] [blame] | 227 | engine->hw_id = engine->guc_id = info->hw_id; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 228 | engine->mmio_base = info->mmio_base; |
| 229 | engine->irq_shift = info->irq_shift; |
Daniele Ceraolo Spurio | 0908180 | 2017-04-10 07:34:29 -0700 | [diff] [blame] | 230 | engine->class = info->class; |
| 231 | engine->instance = info->instance; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 232 | |
Tvrtko Ursulin | 1803fcbc | 2017-11-10 14:26:27 +0000 | [diff] [blame] | 233 | engine->uabi_id = info->uabi_id; |
| 234 | engine->uabi_class = class_info->uabi_class; |
| 235 | |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 236 | engine->context_size = __intel_engine_context_size(dev_priv, |
| 237 | engine->class); |
| 238 | if (WARN_ON(engine->context_size > BIT(20))) |
| 239 | engine->context_size = 0; |
| 240 | |
Chris Wilson | 0de9136 | 2016-11-14 20:41:01 +0000 | [diff] [blame] | 241 | /* Nothing to do here, execute in order of dependencies */ |
| 242 | engine->schedule = NULL; |
| 243 | |
Tvrtko Ursulin | 30e17b7 | 2017-11-21 18:18:48 +0000 | [diff] [blame] | 244 | spin_lock_init(&engine->stats.lock); |
| 245 | |
Changbin Du | 3fc0306 | 2017-03-13 10:47:11 +0800 | [diff] [blame] | 246 | ATOMIC_INIT_NOTIFIER_HEAD(&engine->context_status_notifier); |
| 247 | |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 248 | dev_priv->engine_class[info->class][info->instance] = engine; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 249 | dev_priv->engine[id] = engine; |
| 250 | return 0; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 251 | } |
| 252 | |
| 253 | /** |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 254 | * intel_engines_init_mmio() - allocate and prepare the Engine Command Streamers |
Tvrtko Ursulin | bf9e842 | 2016-12-01 14:16:38 +0000 | [diff] [blame] | 255 | * @dev_priv: i915 device private |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 256 | * |
| 257 | * Return: non-zero if the initialization failed. |
| 258 | */ |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 259 | int intel_engines_init_mmio(struct drm_i915_private *dev_priv) |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 260 | { |
Tvrtko Ursulin | c1bb114 | 2016-08-10 16:22:10 +0100 | [diff] [blame] | 261 | struct intel_device_info *device_info = mkwrite_device_info(dev_priv); |
Chris Wilson | 5f9be05 | 2017-04-11 17:56:58 +0100 | [diff] [blame] | 262 | const unsigned int ring_mask = INTEL_INFO(dev_priv)->ring_mask; |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 263 | struct intel_engine_cs *engine; |
| 264 | enum intel_engine_id id; |
Chris Wilson | 5f9be05 | 2017-04-11 17:56:58 +0100 | [diff] [blame] | 265 | unsigned int mask = 0; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 266 | unsigned int i; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 267 | int err; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 268 | |
Tvrtko Ursulin | 70006ad | 2016-10-13 11:02:56 +0100 | [diff] [blame] | 269 | WARN_ON(ring_mask == 0); |
| 270 | WARN_ON(ring_mask & |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 271 | GENMASK(sizeof(mask) * BITS_PER_BYTE - 1, I915_NUM_ENGINES)); |
| 272 | |
| 273 | for (i = 0; i < ARRAY_SIZE(intel_engines); i++) { |
| 274 | if (!HAS_ENGINE(dev_priv, i)) |
| 275 | continue; |
| 276 | |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 277 | err = intel_engine_setup(dev_priv, i); |
| 278 | if (err) |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 279 | goto cleanup; |
| 280 | |
| 281 | mask |= ENGINE_MASK(i); |
| 282 | } |
| 283 | |
| 284 | /* |
| 285 | * Catch failures to update intel_engines table when the new engines |
| 286 | * are added to the driver by a warning and disabling the forgotten |
| 287 | * engines. |
| 288 | */ |
Tvrtko Ursulin | 70006ad | 2016-10-13 11:02:56 +0100 | [diff] [blame] | 289 | if (WARN_ON(mask != ring_mask)) |
Tvrtko Ursulin | c1bb114 | 2016-08-10 16:22:10 +0100 | [diff] [blame] | 290 | device_info->ring_mask = mask; |
| 291 | |
Chris Wilson | 5f9be05 | 2017-04-11 17:56:58 +0100 | [diff] [blame] | 292 | /* We always presume we have at least RCS available for later probing */ |
| 293 | if (WARN_ON(!HAS_ENGINE(dev_priv, RCS))) { |
| 294 | err = -ENODEV; |
| 295 | goto cleanup; |
| 296 | } |
| 297 | |
Tvrtko Ursulin | c1bb114 | 2016-08-10 16:22:10 +0100 | [diff] [blame] | 298 | device_info->num_rings = hweight32(mask); |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 299 | |
Michel Thierry | ce453b3 | 2017-11-10 16:44:47 -0800 | [diff] [blame] | 300 | i915_check_and_clear_faults(dev_priv); |
| 301 | |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 302 | return 0; |
| 303 | |
| 304 | cleanup: |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 305 | for_each_engine(engine, dev_priv, id) |
| 306 | kfree(engine); |
| 307 | return err; |
| 308 | } |
| 309 | |
| 310 | /** |
Joonas Lahtinen | 63ffbcd | 2017-04-28 10:53:36 +0300 | [diff] [blame] | 311 | * intel_engines_init() - init the Engine Command Streamers |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 312 | * @dev_priv: i915 device private |
| 313 | * |
| 314 | * Return: non-zero if the initialization failed. |
| 315 | */ |
| 316 | int intel_engines_init(struct drm_i915_private *dev_priv) |
| 317 | { |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 318 | struct intel_engine_cs *engine; |
| 319 | enum intel_engine_id id, err_id; |
Tvrtko Ursulin | 33def1f | 2017-06-16 14:03:38 +0100 | [diff] [blame] | 320 | int err; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 321 | |
Akash Goel | 3b3f165 | 2016-10-13 22:44:48 +0530 | [diff] [blame] | 322 | for_each_engine(engine, dev_priv, id) { |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 323 | const struct engine_class_info *class_info = |
| 324 | &intel_engine_classes[engine->class]; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 325 | int (*init)(struct intel_engine_cs *engine); |
| 326 | |
Chris Wilson | fb5c551 | 2017-11-20 20:55:00 +0000 | [diff] [blame] | 327 | if (HAS_EXECLISTS(dev_priv)) |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 328 | init = class_info->init_execlists; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 329 | else |
Oscar Mateo | b8400f0 | 2017-04-10 07:34:32 -0700 | [diff] [blame] | 330 | init = class_info->init_legacy; |
Tvrtko Ursulin | 33def1f | 2017-06-16 14:03:38 +0100 | [diff] [blame] | 331 | |
| 332 | err = -EINVAL; |
| 333 | err_id = id; |
| 334 | |
| 335 | if (GEM_WARN_ON(!init)) |
| 336 | goto cleanup; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 337 | |
| 338 | err = init(engine); |
Tvrtko Ursulin | 33def1f | 2017-06-16 14:03:38 +0100 | [diff] [blame] | 339 | if (err) |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 340 | goto cleanup; |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 341 | |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 342 | GEM_BUG_ON(!engine->submit_request); |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 343 | } |
| 344 | |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 345 | return 0; |
| 346 | |
| 347 | cleanup: |
| 348 | for_each_engine(engine, dev_priv, id) { |
Tvrtko Ursulin | 33def1f | 2017-06-16 14:03:38 +0100 | [diff] [blame] | 349 | if (id >= err_id) { |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 350 | kfree(engine); |
Tvrtko Ursulin | 33def1f | 2017-06-16 14:03:38 +0100 | [diff] [blame] | 351 | dev_priv->engine[id] = NULL; |
| 352 | } else { |
Tvrtko Ursulin | 8ee7c6e | 2017-02-16 12:23:22 +0000 | [diff] [blame] | 353 | dev_priv->gt.cleanup_engine(engine); |
Tvrtko Ursulin | 33def1f | 2017-06-16 14:03:38 +0100 | [diff] [blame] | 354 | } |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 355 | } |
Chris Wilson | bb8f0f5 | 2017-01-24 11:01:34 +0000 | [diff] [blame] | 356 | return err; |
Tvrtko Ursulin | 88d2ba2 | 2016-07-13 16:03:40 +0100 | [diff] [blame] | 357 | } |
| 358 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 359 | 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] | 360 | { |
| 361 | struct drm_i915_private *dev_priv = engine->i915; |
| 362 | |
| 363 | /* Our semaphore implementation is strictly monotonic (i.e. we proceed |
| 364 | * so long as the semaphore value in the register/page is greater |
| 365 | * than the sync value), so whenever we reset the seqno, |
| 366 | * so long as we reset the tracking semaphore value to 0, it will |
| 367 | * always be before the next request's seqno. If we don't reset |
| 368 | * the semaphore value, then when the seqno moves backwards all |
| 369 | * future waits will complete instantly (causing rendering corruption). |
| 370 | */ |
| 371 | if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) { |
| 372 | I915_WRITE(RING_SYNC_0(engine->mmio_base), 0); |
| 373 | I915_WRITE(RING_SYNC_1(engine->mmio_base), 0); |
| 374 | if (HAS_VEBOX(dev_priv)) |
| 375 | I915_WRITE(RING_SYNC_2(engine->mmio_base), 0); |
| 376 | } |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 377 | |
| 378 | intel_write_status_page(engine, I915_GEM_HWS_INDEX, seqno); |
Chris Wilson | 14a6bbf | 2017-03-14 11:14:52 +0000 | [diff] [blame] | 379 | clear_bit(ENGINE_IRQ_BREADCRUMB, &engine->irq_posted); |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 380 | |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 381 | /* After manually advancing the seqno, fake the interrupt in case |
| 382 | * there are any waiters for that seqno. |
| 383 | */ |
| 384 | intel_engine_wakeup(engine); |
Chris Wilson | 2ca9faa | 2017-04-05 16:30:54 +0100 | [diff] [blame] | 385 | |
| 386 | GEM_BUG_ON(intel_engine_get_seqno(engine) != seqno); |
Chris Wilson | 57f275a | 2016-08-15 10:49:00 +0100 | [diff] [blame] | 387 | } |
| 388 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 389 | static void intel_engine_init_timeline(struct intel_engine_cs *engine) |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 390 | { |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 391 | engine->timeline = &engine->i915->gt.global_timeline.engine[engine->id]; |
Chris Wilson | dcff85c | 2016-08-05 10:14:11 +0100 | [diff] [blame] | 392 | } |
| 393 | |
Mika Kuoppala | 19df9a5 | 2017-09-22 15:43:04 +0300 | [diff] [blame] | 394 | static bool csb_force_mmio(struct drm_i915_private *i915) |
| 395 | { |
Mika Kuoppala | 19df9a5 | 2017-09-22 15:43:04 +0300 | [diff] [blame] | 396 | /* |
| 397 | * IOMMU adds unpredictable latency causing the CSB write (from the |
| 398 | * GPU into the HWSP) to only be visible some time after the interrupt |
| 399 | * (missed breadcrumb syndrome). |
| 400 | */ |
| 401 | if (intel_vtd_active()) |
| 402 | return true; |
| 403 | |
Weinan Li | 1fd51d9 | 2017-10-15 11:55:25 +0800 | [diff] [blame] | 404 | /* Older GVT emulation depends upon intercepting CSB mmio */ |
| 405 | if (intel_vgpu_active(i915) && !intel_vgpu_has_hwsp_emulation(i915)) |
| 406 | return true; |
| 407 | |
Mika Kuoppala | 19df9a5 | 2017-09-22 15:43:04 +0300 | [diff] [blame] | 408 | return false; |
| 409 | } |
| 410 | |
| 411 | static void intel_engine_init_execlist(struct intel_engine_cs *engine) |
| 412 | { |
| 413 | struct intel_engine_execlists * const execlists = &engine->execlists; |
| 414 | |
| 415 | execlists->csb_use_mmio = csb_force_mmio(engine->i915); |
| 416 | |
Mika Kuoppala | 76e7008 | 2017-09-22 15:43:07 +0300 | [diff] [blame] | 417 | execlists->port_mask = 1; |
| 418 | BUILD_BUG_ON_NOT_POWER_OF_2(execlists_num_ports(execlists)); |
| 419 | GEM_BUG_ON(execlists_num_ports(execlists) > EXECLIST_MAX_PORTS); |
| 420 | |
Mika Kuoppala | 19df9a5 | 2017-09-22 15:43:04 +0300 | [diff] [blame] | 421 | execlists->queue = RB_ROOT; |
| 422 | execlists->first = NULL; |
| 423 | } |
| 424 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 425 | /** |
| 426 | * intel_engines_setup_common - setup engine state not requiring hw access |
| 427 | * @engine: Engine to setup. |
| 428 | * |
| 429 | * Initializes @engine@ structure members shared between legacy and execlists |
| 430 | * submission modes which do not require hardware access. |
| 431 | * |
| 432 | * Typically done early in the submission mode specific engine setup stage. |
| 433 | */ |
| 434 | void intel_engine_setup_common(struct intel_engine_cs *engine) |
| 435 | { |
Mika Kuoppala | 19df9a5 | 2017-09-22 15:43:04 +0300 | [diff] [blame] | 436 | intel_engine_init_execlist(engine); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 437 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 438 | intel_engine_init_timeline(engine); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 439 | intel_engine_init_hangcheck(engine); |
Chris Wilson | 115003e9 | 2016-08-04 16:32:19 +0100 | [diff] [blame] | 440 | i915_gem_batch_pool_init(engine, &engine->batch_pool); |
Chris Wilson | 7756e45 | 2016-08-18 17:17:10 +0100 | [diff] [blame] | 441 | |
| 442 | intel_engine_init_cmd_parser(engine); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 443 | } |
| 444 | |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 445 | int intel_engine_create_scratch(struct intel_engine_cs *engine, int size) |
| 446 | { |
| 447 | struct drm_i915_gem_object *obj; |
| 448 | struct i915_vma *vma; |
| 449 | int ret; |
| 450 | |
| 451 | WARN_ON(engine->scratch); |
| 452 | |
Tvrtko Ursulin | 187685c | 2016-12-01 14:16:36 +0000 | [diff] [blame] | 453 | obj = i915_gem_object_create_stolen(engine->i915, size); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 454 | if (!obj) |
Chris Wilson | 920cf41 | 2016-10-28 13:58:30 +0100 | [diff] [blame] | 455 | obj = i915_gem_object_create_internal(engine->i915, size); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 456 | if (IS_ERR(obj)) { |
| 457 | DRM_ERROR("Failed to allocate scratch page\n"); |
| 458 | return PTR_ERR(obj); |
| 459 | } |
| 460 | |
Chris Wilson | a01cb37 | 2017-01-16 15:21:30 +0000 | [diff] [blame] | 461 | vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 462 | if (IS_ERR(vma)) { |
| 463 | ret = PTR_ERR(vma); |
| 464 | goto err_unref; |
| 465 | } |
| 466 | |
| 467 | ret = i915_vma_pin(vma, 0, 4096, PIN_GLOBAL | PIN_HIGH); |
| 468 | if (ret) |
| 469 | goto err_unref; |
| 470 | |
| 471 | engine->scratch = vma; |
Chris Wilson | bde13eb | 2016-08-15 10:49:07 +0100 | [diff] [blame] | 472 | DRM_DEBUG_DRIVER("%s pipe control offset: 0x%08x\n", |
| 473 | engine->name, i915_ggtt_offset(vma)); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 474 | return 0; |
| 475 | |
| 476 | err_unref: |
| 477 | i915_gem_object_put(obj); |
| 478 | return ret; |
| 479 | } |
| 480 | |
| 481 | static void intel_engine_cleanup_scratch(struct intel_engine_cs *engine) |
| 482 | { |
Chris Wilson | 19880c4 | 2016-08-15 10:49:05 +0100 | [diff] [blame] | 483 | i915_vma_unpin_and_release(&engine->scratch); |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 484 | } |
| 485 | |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame] | 486 | static void cleanup_phys_status_page(struct intel_engine_cs *engine) |
| 487 | { |
| 488 | struct drm_i915_private *dev_priv = engine->i915; |
| 489 | |
| 490 | if (!dev_priv->status_page_dmah) |
| 491 | return; |
| 492 | |
| 493 | drm_pci_free(&dev_priv->drm, dev_priv->status_page_dmah); |
| 494 | engine->status_page.page_addr = NULL; |
| 495 | } |
| 496 | |
| 497 | static void cleanup_status_page(struct intel_engine_cs *engine) |
| 498 | { |
| 499 | struct i915_vma *vma; |
| 500 | struct drm_i915_gem_object *obj; |
| 501 | |
| 502 | vma = fetch_and_zero(&engine->status_page.vma); |
| 503 | if (!vma) |
| 504 | return; |
| 505 | |
| 506 | obj = vma->obj; |
| 507 | |
| 508 | i915_vma_unpin(vma); |
| 509 | i915_vma_close(vma); |
| 510 | |
| 511 | i915_gem_object_unpin_map(obj); |
| 512 | __i915_gem_object_release_unless_active(obj); |
| 513 | } |
| 514 | |
| 515 | static int init_status_page(struct intel_engine_cs *engine) |
| 516 | { |
| 517 | struct drm_i915_gem_object *obj; |
| 518 | struct i915_vma *vma; |
| 519 | unsigned int flags; |
| 520 | void *vaddr; |
| 521 | int ret; |
| 522 | |
| 523 | obj = i915_gem_object_create_internal(engine->i915, PAGE_SIZE); |
| 524 | if (IS_ERR(obj)) { |
| 525 | DRM_ERROR("Failed to allocate status page\n"); |
| 526 | return PTR_ERR(obj); |
| 527 | } |
| 528 | |
| 529 | ret = i915_gem_object_set_cache_level(obj, I915_CACHE_LLC); |
| 530 | if (ret) |
| 531 | goto err; |
| 532 | |
| 533 | vma = i915_vma_instance(obj, &engine->i915->ggtt.base, NULL); |
| 534 | if (IS_ERR(vma)) { |
| 535 | ret = PTR_ERR(vma); |
| 536 | goto err; |
| 537 | } |
| 538 | |
| 539 | flags = PIN_GLOBAL; |
| 540 | if (!HAS_LLC(engine->i915)) |
| 541 | /* On g33, we cannot place HWS above 256MiB, so |
| 542 | * restrict its pinning to the low mappable arena. |
| 543 | * Though this restriction is not documented for |
| 544 | * gen4, gen5, or byt, they also behave similarly |
| 545 | * and hang if the HWS is placed at the top of the |
| 546 | * GTT. To generalise, it appears that all !llc |
| 547 | * platforms have issues with us placing the HWS |
| 548 | * above the mappable region (even though we never |
| 549 | * actually map it). |
| 550 | */ |
| 551 | flags |= PIN_MAPPABLE; |
Chris Wilson | 34a04e5 | 2017-09-13 09:56:03 +0100 | [diff] [blame] | 552 | else |
| 553 | flags |= PIN_HIGH; |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame] | 554 | ret = i915_vma_pin(vma, 0, 4096, flags); |
| 555 | if (ret) |
| 556 | goto err; |
| 557 | |
| 558 | vaddr = i915_gem_object_pin_map(obj, I915_MAP_WB); |
| 559 | if (IS_ERR(vaddr)) { |
| 560 | ret = PTR_ERR(vaddr); |
| 561 | goto err_unpin; |
| 562 | } |
| 563 | |
| 564 | engine->status_page.vma = vma; |
| 565 | engine->status_page.ggtt_offset = i915_ggtt_offset(vma); |
| 566 | engine->status_page.page_addr = memset(vaddr, 0, PAGE_SIZE); |
| 567 | |
| 568 | DRM_DEBUG_DRIVER("%s hws offset: 0x%08x\n", |
| 569 | engine->name, i915_ggtt_offset(vma)); |
| 570 | return 0; |
| 571 | |
| 572 | err_unpin: |
| 573 | i915_vma_unpin(vma); |
| 574 | err: |
| 575 | i915_gem_object_put(obj); |
| 576 | return ret; |
| 577 | } |
| 578 | |
| 579 | static int init_phys_status_page(struct intel_engine_cs *engine) |
| 580 | { |
| 581 | struct drm_i915_private *dev_priv = engine->i915; |
| 582 | |
| 583 | GEM_BUG_ON(engine->id != RCS); |
| 584 | |
| 585 | dev_priv->status_page_dmah = |
| 586 | drm_pci_alloc(&dev_priv->drm, PAGE_SIZE, PAGE_SIZE); |
| 587 | if (!dev_priv->status_page_dmah) |
| 588 | return -ENOMEM; |
| 589 | |
| 590 | engine->status_page.page_addr = dev_priv->status_page_dmah->vaddr; |
| 591 | memset(engine->status_page.page_addr, 0, PAGE_SIZE); |
| 592 | |
| 593 | return 0; |
| 594 | } |
| 595 | |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 596 | /** |
| 597 | * intel_engines_init_common - initialize cengine state which might require hw access |
| 598 | * @engine: Engine to initialize. |
| 599 | * |
| 600 | * Initializes @engine@ structure members shared between legacy and execlists |
| 601 | * submission modes which do require hardware access. |
| 602 | * |
| 603 | * Typcally done at later stages of submission mode specific engine setup. |
| 604 | * |
| 605 | * Returns zero on success or an error code on failure. |
| 606 | */ |
| 607 | int intel_engine_init_common(struct intel_engine_cs *engine) |
| 608 | { |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 609 | struct intel_ring *ring; |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 610 | int ret; |
| 611 | |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 612 | engine->set_default_submission(engine); |
| 613 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 614 | /* We may need to do things with the shrinker which |
| 615 | * require us to immediately switch back to the default |
| 616 | * context. This can cause a problem as pinning the |
| 617 | * default context also requires GTT space which may not |
| 618 | * be available. To avoid this we always pin the default |
| 619 | * context. |
| 620 | */ |
Chris Wilson | 266a240 | 2017-05-04 10:33:08 +0100 | [diff] [blame] | 621 | ring = engine->context_pin(engine, engine->i915->kernel_context); |
| 622 | if (IS_ERR(ring)) |
| 623 | return PTR_ERR(ring); |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 624 | |
Chris Wilson | e7af311 | 2017-10-03 21:34:48 +0100 | [diff] [blame] | 625 | /* |
| 626 | * Similarly the preempt context must always be available so that |
| 627 | * we can interrupt the engine at any time. |
| 628 | */ |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 629 | if (HAS_LOGICAL_RING_PREEMPTION(engine->i915)) { |
Chris Wilson | e7af311 | 2017-10-03 21:34:48 +0100 | [diff] [blame] | 630 | ring = engine->context_pin(engine, |
| 631 | engine->i915->preempt_context); |
| 632 | if (IS_ERR(ring)) { |
| 633 | ret = PTR_ERR(ring); |
| 634 | goto err_unpin_kernel; |
| 635 | } |
| 636 | } |
| 637 | |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 638 | ret = intel_engine_init_breadcrumbs(engine); |
| 639 | if (ret) |
Chris Wilson | e7af311 | 2017-10-03 21:34:48 +0100 | [diff] [blame] | 640 | goto err_unpin_preempt; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 641 | |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame] | 642 | if (HWS_NEEDS_PHYSICAL(engine->i915)) |
| 643 | ret = init_phys_status_page(engine); |
| 644 | else |
| 645 | ret = init_status_page(engine); |
| 646 | if (ret) |
Chris Wilson | 7c2fa7f | 2017-11-10 14:26:34 +0000 | [diff] [blame] | 647 | goto err_breadcrumbs; |
Chris Wilson | 4e50f08 | 2016-10-28 13:58:31 +0100 | [diff] [blame] | 648 | |
Chris Wilson | 7756e45 | 2016-08-18 17:17:10 +0100 | [diff] [blame] | 649 | return 0; |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 650 | |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame] | 651 | err_breadcrumbs: |
| 652 | intel_engine_fini_breadcrumbs(engine); |
Chris Wilson | e7af311 | 2017-10-03 21:34:48 +0100 | [diff] [blame] | 653 | err_unpin_preempt: |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 654 | if (HAS_LOGICAL_RING_PREEMPTION(engine->i915)) |
Chris Wilson | e7af311 | 2017-10-03 21:34:48 +0100 | [diff] [blame] | 655 | engine->context_unpin(engine, engine->i915->preempt_context); |
| 656 | err_unpin_kernel: |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 657 | engine->context_unpin(engine, engine->i915->kernel_context); |
| 658 | return ret; |
Tvrtko Ursulin | 019bf27 | 2016-07-13 16:03:41 +0100 | [diff] [blame] | 659 | } |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 660 | |
| 661 | /** |
| 662 | * intel_engines_cleanup_common - cleans up the engine state created by |
| 663 | * the common initiailizers. |
| 664 | * @engine: Engine to cleanup. |
| 665 | * |
| 666 | * This cleans up everything created by the common helpers. |
| 667 | */ |
| 668 | void intel_engine_cleanup_common(struct intel_engine_cs *engine) |
| 669 | { |
Chris Wilson | adc320c | 2016-08-15 10:48:59 +0100 | [diff] [blame] | 670 | intel_engine_cleanup_scratch(engine); |
| 671 | |
Daniele Ceraolo Spurio | 486e93f | 2017-09-13 09:56:02 +0100 | [diff] [blame] | 672 | if (HWS_NEEDS_PHYSICAL(engine->i915)) |
| 673 | cleanup_phys_status_page(engine); |
| 674 | else |
| 675 | cleanup_status_page(engine); |
| 676 | |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 677 | intel_engine_fini_breadcrumbs(engine); |
Chris Wilson | 7756e45 | 2016-08-18 17:17:10 +0100 | [diff] [blame] | 678 | intel_engine_cleanup_cmd_parser(engine); |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 679 | i915_gem_batch_pool_fini(&engine->batch_pool); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 680 | |
Chris Wilson | d2b4b97 | 2017-11-10 14:26:33 +0000 | [diff] [blame] | 681 | if (engine->default_state) |
| 682 | i915_gem_object_put(engine->default_state); |
| 683 | |
Michał Winiarski | a4598d1 | 2017-10-25 22:00:18 +0200 | [diff] [blame] | 684 | if (HAS_LOGICAL_RING_PREEMPTION(engine->i915)) |
Chris Wilson | e7af311 | 2017-10-03 21:34:48 +0100 | [diff] [blame] | 685 | engine->context_unpin(engine, engine->i915->preempt_context); |
Chris Wilson | e8a9c58 | 2016-12-18 15:37:20 +0000 | [diff] [blame] | 686 | engine->context_unpin(engine, engine->i915->kernel_context); |
Chris Wilson | 96a945a | 2016-08-03 13:19:16 +0100 | [diff] [blame] | 687 | } |
Chris Wilson | 1b36595 | 2016-10-04 21:11:31 +0100 | [diff] [blame] | 688 | |
| 689 | u64 intel_engine_get_active_head(struct intel_engine_cs *engine) |
| 690 | { |
| 691 | struct drm_i915_private *dev_priv = engine->i915; |
| 692 | u64 acthd; |
| 693 | |
| 694 | if (INTEL_GEN(dev_priv) >= 8) |
| 695 | acthd = I915_READ64_2x32(RING_ACTHD(engine->mmio_base), |
| 696 | RING_ACTHD_UDW(engine->mmio_base)); |
| 697 | else if (INTEL_GEN(dev_priv) >= 4) |
| 698 | acthd = I915_READ(RING_ACTHD(engine->mmio_base)); |
| 699 | else |
| 700 | acthd = I915_READ(ACTHD); |
| 701 | |
| 702 | return acthd; |
| 703 | } |
| 704 | |
| 705 | u64 intel_engine_get_last_batch_head(struct intel_engine_cs *engine) |
| 706 | { |
| 707 | struct drm_i915_private *dev_priv = engine->i915; |
| 708 | u64 bbaddr; |
| 709 | |
| 710 | if (INTEL_GEN(dev_priv) >= 8) |
| 711 | bbaddr = I915_READ64_2x32(RING_BBADDR(engine->mmio_base), |
| 712 | RING_BBADDR_UDW(engine->mmio_base)); |
| 713 | else |
| 714 | bbaddr = I915_READ(RING_BBADDR(engine->mmio_base)); |
| 715 | |
| 716 | return bbaddr; |
| 717 | } |
Chris Wilson | 0e70447 | 2016-10-12 10:05:17 +0100 | [diff] [blame] | 718 | |
| 719 | const char *i915_cache_level_str(struct drm_i915_private *i915, int type) |
| 720 | { |
| 721 | switch (type) { |
| 722 | case I915_CACHE_NONE: return " uncached"; |
| 723 | case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped"; |
| 724 | case I915_CACHE_L3_LLC: return " L3+LLC"; |
| 725 | case I915_CACHE_WT: return " WT"; |
| 726 | default: return ""; |
| 727 | } |
| 728 | } |
| 729 | |
| 730 | static inline uint32_t |
| 731 | read_subslice_reg(struct drm_i915_private *dev_priv, int slice, |
| 732 | int subslice, i915_reg_t reg) |
| 733 | { |
| 734 | uint32_t mcr; |
| 735 | uint32_t ret; |
| 736 | enum forcewake_domains fw_domains; |
| 737 | |
| 738 | fw_domains = intel_uncore_forcewake_for_reg(dev_priv, reg, |
| 739 | FW_REG_READ); |
| 740 | fw_domains |= intel_uncore_forcewake_for_reg(dev_priv, |
| 741 | GEN8_MCR_SELECTOR, |
| 742 | FW_REG_READ | FW_REG_WRITE); |
| 743 | |
| 744 | spin_lock_irq(&dev_priv->uncore.lock); |
| 745 | intel_uncore_forcewake_get__locked(dev_priv, fw_domains); |
| 746 | |
| 747 | mcr = I915_READ_FW(GEN8_MCR_SELECTOR); |
| 748 | /* |
| 749 | * The HW expects the slice and sublice selectors to be reset to 0 |
| 750 | * after reading out the registers. |
| 751 | */ |
| 752 | WARN_ON_ONCE(mcr & (GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK)); |
| 753 | mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK); |
| 754 | mcr |= GEN8_MCR_SLICE(slice) | GEN8_MCR_SUBSLICE(subslice); |
| 755 | I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr); |
| 756 | |
| 757 | ret = I915_READ_FW(reg); |
| 758 | |
| 759 | mcr &= ~(GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK); |
| 760 | I915_WRITE_FW(GEN8_MCR_SELECTOR, mcr); |
| 761 | |
| 762 | intel_uncore_forcewake_put__locked(dev_priv, fw_domains); |
| 763 | spin_unlock_irq(&dev_priv->uncore.lock); |
| 764 | |
| 765 | return ret; |
| 766 | } |
| 767 | |
| 768 | /* NB: please notice the memset */ |
| 769 | void intel_engine_get_instdone(struct intel_engine_cs *engine, |
| 770 | struct intel_instdone *instdone) |
| 771 | { |
| 772 | struct drm_i915_private *dev_priv = engine->i915; |
| 773 | u32 mmio_base = engine->mmio_base; |
| 774 | int slice; |
| 775 | int subslice; |
| 776 | |
| 777 | memset(instdone, 0, sizeof(*instdone)); |
| 778 | |
| 779 | switch (INTEL_GEN(dev_priv)) { |
| 780 | default: |
| 781 | instdone->instdone = I915_READ(RING_INSTDONE(mmio_base)); |
| 782 | |
| 783 | if (engine->id != RCS) |
| 784 | break; |
| 785 | |
| 786 | instdone->slice_common = I915_READ(GEN7_SC_INSTDONE); |
| 787 | for_each_instdone_slice_subslice(dev_priv, slice, subslice) { |
| 788 | instdone->sampler[slice][subslice] = |
| 789 | read_subslice_reg(dev_priv, slice, subslice, |
| 790 | GEN7_SAMPLER_INSTDONE); |
| 791 | instdone->row[slice][subslice] = |
| 792 | read_subslice_reg(dev_priv, slice, subslice, |
| 793 | GEN7_ROW_INSTDONE); |
| 794 | } |
| 795 | break; |
| 796 | case 7: |
| 797 | instdone->instdone = I915_READ(RING_INSTDONE(mmio_base)); |
| 798 | |
| 799 | if (engine->id != RCS) |
| 800 | break; |
| 801 | |
| 802 | instdone->slice_common = I915_READ(GEN7_SC_INSTDONE); |
| 803 | instdone->sampler[0][0] = I915_READ(GEN7_SAMPLER_INSTDONE); |
| 804 | instdone->row[0][0] = I915_READ(GEN7_ROW_INSTDONE); |
| 805 | |
| 806 | break; |
| 807 | case 6: |
| 808 | case 5: |
| 809 | case 4: |
| 810 | instdone->instdone = I915_READ(RING_INSTDONE(mmio_base)); |
| 811 | |
| 812 | if (engine->id == RCS) |
| 813 | /* HACK: Using the wrong struct member */ |
| 814 | instdone->slice_common = I915_READ(GEN4_INSTDONE1); |
| 815 | break; |
| 816 | case 3: |
| 817 | case 2: |
| 818 | instdone->instdone = I915_READ(GEN2_INSTDONE); |
| 819 | break; |
| 820 | } |
| 821 | } |
Chris Wilson | f97fbf9 | 2017-02-13 17:15:14 +0000 | [diff] [blame] | 822 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 823 | static int wa_add(struct drm_i915_private *dev_priv, |
| 824 | i915_reg_t addr, |
| 825 | const u32 mask, const u32 val) |
| 826 | { |
| 827 | const u32 idx = dev_priv->workarounds.count; |
| 828 | |
| 829 | if (WARN_ON(idx >= I915_MAX_WA_REGS)) |
| 830 | return -ENOSPC; |
| 831 | |
| 832 | dev_priv->workarounds.reg[idx].addr = addr; |
| 833 | dev_priv->workarounds.reg[idx].value = val; |
| 834 | dev_priv->workarounds.reg[idx].mask = mask; |
| 835 | |
| 836 | dev_priv->workarounds.count++; |
| 837 | |
| 838 | return 0; |
| 839 | } |
| 840 | |
| 841 | #define WA_REG(addr, mask, val) do { \ |
| 842 | const int r = wa_add(dev_priv, (addr), (mask), (val)); \ |
| 843 | if (r) \ |
| 844 | return r; \ |
| 845 | } while (0) |
| 846 | |
| 847 | #define WA_SET_BIT_MASKED(addr, mask) \ |
| 848 | WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask)) |
| 849 | |
| 850 | #define WA_CLR_BIT_MASKED(addr, mask) \ |
| 851 | WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask)) |
| 852 | |
| 853 | #define WA_SET_FIELD_MASKED(addr, mask, value) \ |
| 854 | WA_REG(addr, mask, _MASKED_FIELD(mask, value)) |
| 855 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 856 | static int wa_ring_whitelist_reg(struct intel_engine_cs *engine, |
| 857 | i915_reg_t reg) |
| 858 | { |
| 859 | struct drm_i915_private *dev_priv = engine->i915; |
| 860 | struct i915_workarounds *wa = &dev_priv->workarounds; |
| 861 | const uint32_t index = wa->hw_whitelist_count[engine->id]; |
| 862 | |
| 863 | if (WARN_ON(index >= RING_MAX_NONPRIV_SLOTS)) |
| 864 | return -EINVAL; |
| 865 | |
Oscar Mateo | 32ced39 | 2017-09-28 15:40:39 -0700 | [diff] [blame] | 866 | I915_WRITE(RING_FORCE_TO_NONPRIV(engine->mmio_base, index), |
| 867 | i915_mmio_reg_offset(reg)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 868 | wa->hw_whitelist_count[engine->id]++; |
| 869 | |
| 870 | return 0; |
| 871 | } |
| 872 | |
| 873 | static int gen8_init_workarounds(struct intel_engine_cs *engine) |
| 874 | { |
| 875 | struct drm_i915_private *dev_priv = engine->i915; |
| 876 | |
| 877 | WA_SET_BIT_MASKED(INSTPM, INSTPM_FORCE_ORDERING); |
| 878 | |
| 879 | /* WaDisableAsyncFlipPerfMode:bdw,chv */ |
| 880 | WA_SET_BIT_MASKED(MI_MODE, ASYNC_FLIP_PERF_DISABLE); |
| 881 | |
| 882 | /* WaDisablePartialInstShootdown:bdw,chv */ |
| 883 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, |
| 884 | PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE); |
| 885 | |
| 886 | /* Use Force Non-Coherent whenever executing a 3D context. This is a |
| 887 | * workaround for for a possible hang in the unlikely event a TLB |
| 888 | * invalidation occurs during a PSD flush. |
| 889 | */ |
| 890 | /* WaForceEnableNonCoherent:bdw,chv */ |
| 891 | /* WaHdcDisableFetchWhenMasked:bdw,chv */ |
| 892 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
| 893 | HDC_DONOT_FETCH_MEM_WHEN_MASKED | |
| 894 | HDC_FORCE_NON_COHERENT); |
| 895 | |
| 896 | /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0: |
| 897 | * "The Hierarchical Z RAW Stall Optimization allows non-overlapping |
| 898 | * polygons in the same 8x4 pixel/sample area to be processed without |
| 899 | * stalling waiting for the earlier ones to write to Hierarchical Z |
| 900 | * buffer." |
| 901 | * |
| 902 | * This optimization is off by default for BDW and CHV; turn it on. |
| 903 | */ |
| 904 | WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE); |
| 905 | |
| 906 | /* Wa4x4STCOptimizationDisable:bdw,chv */ |
| 907 | WA_SET_BIT_MASKED(CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE); |
| 908 | |
| 909 | /* |
| 910 | * BSpec recommends 8x4 when MSAA is used, |
| 911 | * however in practice 16x4 seems fastest. |
| 912 | * |
| 913 | * Note that PS/WM thread counts depend on the WIZ hashing |
| 914 | * disable bit, which we don't touch here, but it's good |
| 915 | * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). |
| 916 | */ |
| 917 | WA_SET_FIELD_MASKED(GEN7_GT_MODE, |
| 918 | GEN6_WIZ_HASHING_MASK, |
| 919 | GEN6_WIZ_HASHING_16x4); |
| 920 | |
| 921 | return 0; |
| 922 | } |
| 923 | |
| 924 | static int bdw_init_workarounds(struct intel_engine_cs *engine) |
| 925 | { |
| 926 | struct drm_i915_private *dev_priv = engine->i915; |
| 927 | int ret; |
| 928 | |
| 929 | ret = gen8_init_workarounds(engine); |
| 930 | if (ret) |
| 931 | return ret; |
| 932 | |
| 933 | /* WaDisableThreadStallDopClockGating:bdw (pre-production) */ |
| 934 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE); |
| 935 | |
| 936 | /* WaDisableDopClockGating:bdw |
| 937 | * |
| 938 | * Also see the related UCGTCL1 write in broadwell_init_clock_gating() |
| 939 | * to disable EUTC clock gating. |
| 940 | */ |
| 941 | WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2, |
| 942 | DOP_CLOCK_GATING_DISABLE); |
| 943 | |
| 944 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
| 945 | GEN8_SAMPLER_POWER_BYPASS_DIS); |
| 946 | |
| 947 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
| 948 | /* WaForceContextSaveRestoreNonCoherent:bdw */ |
| 949 | HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT | |
| 950 | /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */ |
| 951 | (IS_BDW_GT3(dev_priv) ? HDC_FENCE_DEST_SLM_DISABLE : 0)); |
| 952 | |
| 953 | return 0; |
| 954 | } |
| 955 | |
| 956 | static int chv_init_workarounds(struct intel_engine_cs *engine) |
| 957 | { |
| 958 | struct drm_i915_private *dev_priv = engine->i915; |
| 959 | int ret; |
| 960 | |
| 961 | ret = gen8_init_workarounds(engine); |
| 962 | if (ret) |
| 963 | return ret; |
| 964 | |
| 965 | /* WaDisableThreadStallDopClockGating:chv */ |
| 966 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE); |
| 967 | |
| 968 | /* Improve HiZ throughput on CHV. */ |
| 969 | WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X); |
| 970 | |
| 971 | return 0; |
| 972 | } |
| 973 | |
| 974 | static int gen9_init_workarounds(struct intel_engine_cs *engine) |
| 975 | { |
| 976 | struct drm_i915_private *dev_priv = engine->i915; |
| 977 | int ret; |
| 978 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 979 | /* WaConextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 980 | I915_WRITE(GEN9_CSFE_CHICKEN1_RCS, _MASKED_BIT_ENABLE(GEN9_PREEMPT_GPGPU_SYNC_SWITCH_DISABLE)); |
| 981 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 982 | /* WaEnableLbsSlaRetryTimerDecrement:skl,bxt,kbl,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 983 | I915_WRITE(BDW_SCRATCH1, I915_READ(BDW_SCRATCH1) | |
| 984 | GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); |
| 985 | |
Rodrigo Vivi | 98eed3d | 2017-06-19 14:21:47 -0700 | [diff] [blame] | 986 | /* WaDisableKillLogic:bxt,skl,kbl */ |
| 987 | if (!IS_COFFEELAKE(dev_priv)) |
| 988 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | |
| 989 | ECOCHK_DIS_TLB); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 990 | |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 991 | if (HAS_LLC(dev_priv)) { |
| 992 | /* WaCompressedResourceSamplerPbeMediaNewHashMode:skl,kbl |
| 993 | * |
| 994 | * Must match Display Engine. See |
| 995 | * WaCompressedResourceDisplayNewHashMode. |
| 996 | */ |
| 997 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 998 | GEN9_PBE_COMPRESSED_HASH_SELECTION); |
| 999 | WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7, |
| 1000 | GEN9_SAMPLER_HASH_COMPRESSED_READ_ADDR); |
Chris Wilson | 53221e1 | 2017-10-04 13:41:52 +0100 | [diff] [blame] | 1001 | |
| 1002 | I915_WRITE(MMCD_MISC_CTRL, |
| 1003 | I915_READ(MMCD_MISC_CTRL) | |
| 1004 | MMCD_PCLA | |
| 1005 | MMCD_HOTSPOT_EN); |
Ville Syrjälä | 9356404 | 2017-08-24 22:10:51 +0300 | [diff] [blame] | 1006 | } |
| 1007 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1008 | /* WaClearFlowControlGpgpuContextSave:skl,bxt,kbl,glk,cfl */ |
| 1009 | /* WaDisablePartialInstShootdown:skl,bxt,kbl,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1010 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, |
| 1011 | FLOW_CONTROL_ENABLE | |
| 1012 | PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE); |
| 1013 | |
| 1014 | /* Syncing dependencies between camera and graphics:skl,bxt,kbl */ |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1015 | if (!IS_COFFEELAKE(dev_priv)) |
| 1016 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
| 1017 | GEN9_DISABLE_OCL_OOB_SUPPRESS_LOGIC); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1018 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1019 | /* WaEnableYV12BugFixInHalfSliceChicken7:skl,bxt,kbl,glk,cfl */ |
| 1020 | /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt,kbl,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1021 | WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7, |
Arkadiusz Hiler | 0b71cea | 2017-05-12 13:20:15 +0200 | [diff] [blame] | 1022 | GEN9_ENABLE_YV12_BUGFIX | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1023 | GEN9_ENABLE_GPGPU_PREEMPTION); |
| 1024 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1025 | /* Wa4x4STCOptimizationDisable:skl,bxt,kbl,glk,cfl */ |
| 1026 | /* WaDisablePartialResolveInVc:skl,bxt,kbl,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1027 | WA_SET_BIT_MASKED(CACHE_MODE_1, (GEN8_4x4_STC_OPTIMIZATION_DISABLE | |
| 1028 | GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE)); |
| 1029 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1030 | /* WaCcsTlbPrefetchDisable:skl,bxt,kbl,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1031 | WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5, |
| 1032 | GEN9_CCS_TLB_PREFETCH_ENABLE); |
| 1033 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1034 | /* WaForceContextSaveRestoreNonCoherent:skl,bxt,kbl,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1035 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
| 1036 | HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT | |
| 1037 | HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE); |
| 1038 | |
| 1039 | /* WaForceEnableNonCoherent and WaDisableHDCInvalidation are |
| 1040 | * both tied to WaForceContextSaveRestoreNonCoherent |
| 1041 | * in some hsds for skl. We keep the tie for all gen9. The |
| 1042 | * documentation is a bit hazy and so we want to get common behaviour, |
| 1043 | * even though there is no clear evidence we would need both on kbl/bxt. |
| 1044 | * This area has been source of system hangs so we play it safe |
| 1045 | * and mimic the skl regardless of what bspec says. |
| 1046 | * |
| 1047 | * Use Force Non-Coherent whenever executing a 3D context. This |
| 1048 | * is a workaround for a possible hang in the unlikely event |
| 1049 | * a TLB invalidation occurs during a PSD flush. |
| 1050 | */ |
| 1051 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1052 | /* WaForceEnableNonCoherent:skl,bxt,kbl,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1053 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
| 1054 | HDC_FORCE_NON_COHERENT); |
| 1055 | |
Rodrigo Vivi | 98eed3d | 2017-06-19 14:21:47 -0700 | [diff] [blame] | 1056 | /* WaDisableHDCInvalidation:skl,bxt,kbl,cfl */ |
| 1057 | I915_WRITE(GAM_ECOCHK, I915_READ(GAM_ECOCHK) | |
| 1058 | BDW_DISABLE_HDC_INVALIDATION); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1059 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1060 | /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt,kbl,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1061 | if (IS_SKYLAKE(dev_priv) || |
| 1062 | IS_KABYLAKE(dev_priv) || |
Chris Wilson | f3e2b2c | 2017-11-14 13:43:39 +0000 | [diff] [blame] | 1063 | IS_COFFEELAKE(dev_priv)) |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1064 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, |
| 1065 | GEN8_SAMPLER_POWER_BYPASS_DIS); |
| 1066 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1067 | /* WaDisableSTUnitPowerOptimization:skl,bxt,kbl,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1068 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE); |
| 1069 | |
Valtteri Rantala | 7436830 | 2017-11-28 16:45:05 +0200 | [diff] [blame] | 1070 | /* WaProgramL3SqcReg1DefaultForPerf:bxt,glk */ |
| 1071 | if (IS_GEN9_LP(dev_priv)) { |
| 1072 | u32 val = I915_READ(GEN8_L3SQCREG1); |
| 1073 | |
| 1074 | val &= ~L3_PRIO_CREDITS_MASK; |
| 1075 | val |= L3_GENERAL_PRIO_CREDITS(62) | L3_HIGH_PRIO_CREDITS(2); |
| 1076 | I915_WRITE(GEN8_L3SQCREG1, val); |
| 1077 | } |
| 1078 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1079 | /* WaOCLCoherentLineFlush:skl,bxt,kbl,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1080 | I915_WRITE(GEN8_L3SQCREG4, (I915_READ(GEN8_L3SQCREG4) | |
| 1081 | GEN8_LQSC_FLUSH_COHERENT_LINES)); |
| 1082 | |
Michał Winiarski | 5152def | 2017-10-03 21:34:46 +0100 | [diff] [blame] | 1083 | /* |
| 1084 | * Supporting preemption with fine-granularity requires changes in the |
| 1085 | * batch buffer programming. Since we can't break old userspace, we |
| 1086 | * need to set our default preemption level to safe value. Userspace is |
| 1087 | * still able to use more fine-grained preemption levels, since in |
| 1088 | * WaEnablePreemptionGranularityControlByUMD we're whitelisting the |
| 1089 | * per-ctx register. As such, WaDisable{3D,GPGPU}MidCmdPreemption are |
| 1090 | * not real HW workarounds, but merely a way to start using preemption |
| 1091 | * while maintaining old contract with userspace. |
| 1092 | */ |
| 1093 | |
| 1094 | /* WaDisable3DMidCmdPreemption:skl,bxt,glk,cfl,[cnl] */ |
| 1095 | WA_CLR_BIT_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL); |
| 1096 | |
| 1097 | /* WaDisableGPGPUMidCmdPreemption:skl,bxt,blk,cfl,[cnl] */ |
| 1098 | WA_SET_FIELD_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_GPGPU_LEVEL_MASK, |
| 1099 | GEN9_PREEMPT_GPGPU_COMMAND_LEVEL); |
| 1100 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1101 | /* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1102 | ret = wa_ring_whitelist_reg(engine, GEN9_CTX_PREEMPT_REG); |
| 1103 | if (ret) |
| 1104 | return ret; |
| 1105 | |
Jeff McGee | 1e99834 | 2017-10-03 21:34:45 +0100 | [diff] [blame] | 1106 | /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl,cfl,[cnl] */ |
| 1107 | I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1, |
| 1108 | _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL)); |
| 1109 | ret = wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1110 | if (ret) |
| 1111 | return ret; |
| 1112 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1113 | /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */ |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1114 | ret = wa_ring_whitelist_reg(engine, GEN8_HDC_CHICKEN1); |
| 1115 | if (ret) |
| 1116 | return ret; |
| 1117 | |
| 1118 | return 0; |
| 1119 | } |
| 1120 | |
| 1121 | static int skl_tune_iz_hashing(struct intel_engine_cs *engine) |
| 1122 | { |
| 1123 | struct drm_i915_private *dev_priv = engine->i915; |
| 1124 | u8 vals[3] = { 0, 0, 0 }; |
| 1125 | unsigned int i; |
| 1126 | |
| 1127 | for (i = 0; i < 3; i++) { |
| 1128 | u8 ss; |
| 1129 | |
| 1130 | /* |
| 1131 | * Only consider slices where one, and only one, subslice has 7 |
| 1132 | * EUs |
| 1133 | */ |
| 1134 | if (!is_power_of_2(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i])) |
| 1135 | continue; |
| 1136 | |
| 1137 | /* |
| 1138 | * subslice_7eu[i] != 0 (because of the check above) and |
| 1139 | * ss_max == 4 (maximum number of subslices possible per slice) |
| 1140 | * |
| 1141 | * -> 0 <= ss <= 3; |
| 1142 | */ |
| 1143 | ss = ffs(INTEL_INFO(dev_priv)->sseu.subslice_7eu[i]) - 1; |
| 1144 | vals[i] = 3 - ss; |
| 1145 | } |
| 1146 | |
| 1147 | if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0) |
| 1148 | return 0; |
| 1149 | |
| 1150 | /* Tune IZ hashing. See intel_device_info_runtime_init() */ |
| 1151 | WA_SET_FIELD_MASKED(GEN7_GT_MODE, |
| 1152 | GEN9_IZ_HASHING_MASK(2) | |
| 1153 | GEN9_IZ_HASHING_MASK(1) | |
| 1154 | GEN9_IZ_HASHING_MASK(0), |
| 1155 | GEN9_IZ_HASHING(2, vals[2]) | |
| 1156 | GEN9_IZ_HASHING(1, vals[1]) | |
| 1157 | GEN9_IZ_HASHING(0, vals[0])); |
| 1158 | |
| 1159 | return 0; |
| 1160 | } |
| 1161 | |
| 1162 | static int skl_init_workarounds(struct intel_engine_cs *engine) |
| 1163 | { |
| 1164 | struct drm_i915_private *dev_priv = engine->i915; |
| 1165 | int ret; |
| 1166 | |
| 1167 | ret = gen9_init_workarounds(engine); |
| 1168 | if (ret) |
| 1169 | return ret; |
| 1170 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1171 | /* WaEnableGapsTsvCreditFix:skl */ |
| 1172 | I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) | |
| 1173 | GEN9_GAPS_TSV_CREDIT_DISABLE)); |
| 1174 | |
| 1175 | /* WaDisableGafsUnitClkGating:skl */ |
Oscar Mateo | 4827c54 | 2017-09-07 08:40:07 -0700 | [diff] [blame] | 1176 | I915_WRITE(GEN7_UCGCTL4, (I915_READ(GEN7_UCGCTL4) | |
| 1177 | GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1178 | |
| 1179 | /* WaInPlaceDecompressionHang:skl */ |
| 1180 | if (IS_SKL_REVID(dev_priv, SKL_REVID_H0, REVID_FOREVER)) |
Oscar Mateo | efc886c | 2017-09-07 08:40:04 -0700 | [diff] [blame] | 1181 | I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA, |
| 1182 | (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) | |
| 1183 | GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1184 | |
| 1185 | /* WaDisableLSQCROPERFforOCL:skl */ |
| 1186 | ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4); |
| 1187 | if (ret) |
| 1188 | return ret; |
| 1189 | |
| 1190 | return skl_tune_iz_hashing(engine); |
| 1191 | } |
| 1192 | |
| 1193 | static int bxt_init_workarounds(struct intel_engine_cs *engine) |
| 1194 | { |
| 1195 | struct drm_i915_private *dev_priv = engine->i915; |
| 1196 | int ret; |
| 1197 | |
| 1198 | ret = gen9_init_workarounds(engine); |
| 1199 | if (ret) |
| 1200 | return ret; |
| 1201 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1202 | /* WaDisableThreadStallDopClockGating:bxt */ |
| 1203 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, |
| 1204 | STALL_DOP_GATING_DISABLE); |
| 1205 | |
| 1206 | /* WaDisablePooledEuLoadBalancingFix:bxt */ |
Chris Wilson | 70a84f3 | 2017-11-14 13:43:40 +0000 | [diff] [blame] | 1207 | I915_WRITE(FF_SLICE_CS_CHICKEN2, |
| 1208 | _MASKED_BIT_ENABLE(GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1209 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1210 | /* WaToEnableHwFixForPushConstHWBug:bxt */ |
Chris Wilson | 70a84f3 | 2017-11-14 13:43:40 +0000 | [diff] [blame] | 1211 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 1212 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1213 | |
| 1214 | /* WaInPlaceDecompressionHang:bxt */ |
Chris Wilson | 70a84f3 | 2017-11-14 13:43:40 +0000 | [diff] [blame] | 1215 | I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA, |
| 1216 | (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) | |
| 1217 | GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1218 | |
| 1219 | return 0; |
| 1220 | } |
| 1221 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1222 | static int cnl_init_workarounds(struct intel_engine_cs *engine) |
| 1223 | { |
| 1224 | struct drm_i915_private *dev_priv = engine->i915; |
| 1225 | int ret; |
| 1226 | |
Oscar Mateo | 6cf20a0 | 2017-09-07 08:40:05 -0700 | [diff] [blame] | 1227 | /* WaDisableI2mCycleOnWRPort:cnl (pre-prod) */ |
Rodrigo Vivi | 86ebb01 | 2017-08-29 16:07:51 -0700 | [diff] [blame] | 1228 | if (IS_CNL_REVID(dev_priv, CNL_REVID_B0, CNL_REVID_B0)) |
Oscar Mateo | 6cf20a0 | 2017-09-07 08:40:05 -0700 | [diff] [blame] | 1229 | I915_WRITE(GAMT_CHKN_BIT_REG, |
| 1230 | (I915_READ(GAMT_CHKN_BIT_REG) | |
| 1231 | GAMT_CHKN_DISABLE_I2M_CYCLE_ON_WR_PORT)); |
Rodrigo Vivi | 86ebb01 | 2017-08-29 16:07:51 -0700 | [diff] [blame] | 1232 | |
Rodrigo Vivi | acfb555 | 2017-08-23 13:35:04 -0700 | [diff] [blame] | 1233 | /* WaForceContextSaveRestoreNonCoherent:cnl */ |
| 1234 | WA_SET_BIT_MASKED(CNL_HDC_CHICKEN0, |
| 1235 | HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT); |
| 1236 | |
Rodrigo Vivi | aa9f4c4 | 2017-09-06 15:03:25 -0700 | [diff] [blame] | 1237 | /* WaThrottleEUPerfToAvoidTDBackPressure:cnl(pre-prod) */ |
| 1238 | if (IS_CNL_REVID(dev_priv, CNL_REVID_B0, CNL_REVID_B0)) |
| 1239 | WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, THROTTLE_12_5); |
| 1240 | |
Rodrigo Vivi | e6d1a4f | 2017-08-15 16:16:49 -0700 | [diff] [blame] | 1241 | /* WaDisableReplayBufferBankArbitrationOptimization:cnl */ |
| 1242 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 1243 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); |
| 1244 | |
Rodrigo Vivi | d1d2475 | 2017-08-15 16:16:50 -0700 | [diff] [blame] | 1245 | /* WaDisableEnhancedSBEVertexCaching:cnl (pre-prod) */ |
| 1246 | if (IS_CNL_REVID(dev_priv, 0, CNL_REVID_B0)) |
| 1247 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 1248 | GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE); |
| 1249 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1250 | /* WaInPlaceDecompressionHang:cnl */ |
Oscar Mateo | efc886c | 2017-09-07 08:40:04 -0700 | [diff] [blame] | 1251 | I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA, |
| 1252 | (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) | |
| 1253 | GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS)); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1254 | |
Oscar Mateo | 2cbecff | 2017-08-23 12:56:31 -0700 | [diff] [blame] | 1255 | /* WaPushConstantDereferenceHoldDisable:cnl */ |
Oscar Mateo | b27f590 | 2017-09-07 08:40:06 -0700 | [diff] [blame] | 1256 | WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2, PUSH_CONSTANT_DEREF_DISABLE); |
Oscar Mateo | 2cbecff | 2017-08-23 12:56:31 -0700 | [diff] [blame] | 1257 | |
Rodrigo Vivi | 392572f | 2017-08-29 16:07:23 -0700 | [diff] [blame] | 1258 | /* FtrEnableFastAnisoL1BankingFix: cnl */ |
| 1259 | WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, CNL_FAST_ANISO_L1_BANKING_FIX); |
| 1260 | |
Michał Winiarski | 5152def | 2017-10-03 21:34:46 +0100 | [diff] [blame] | 1261 | /* WaDisable3DMidCmdPreemption:cnl */ |
| 1262 | WA_CLR_BIT_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL); |
| 1263 | |
| 1264 | /* WaDisableGPGPUMidCmdPreemption:cnl */ |
| 1265 | WA_SET_FIELD_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_GPGPU_LEVEL_MASK, |
| 1266 | GEN9_PREEMPT_GPGPU_COMMAND_LEVEL); |
| 1267 | |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1268 | /* WaEnablePreemptionGranularityControlByUMD:cnl */ |
Jeff McGee | 1e99834 | 2017-10-03 21:34:45 +0100 | [diff] [blame] | 1269 | I915_WRITE(GEN7_FF_SLICE_CS_CHICKEN1, |
| 1270 | _MASKED_BIT_ENABLE(GEN9_FFSC_PERCTX_PREEMPT_CTRL)); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1271 | ret= wa_ring_whitelist_reg(engine, GEN8_CS_CHICKEN1); |
| 1272 | if (ret) |
| 1273 | return ret; |
| 1274 | |
| 1275 | return 0; |
| 1276 | } |
| 1277 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1278 | static int kbl_init_workarounds(struct intel_engine_cs *engine) |
| 1279 | { |
| 1280 | struct drm_i915_private *dev_priv = engine->i915; |
| 1281 | int ret; |
| 1282 | |
| 1283 | ret = gen9_init_workarounds(engine); |
| 1284 | if (ret) |
| 1285 | return ret; |
| 1286 | |
| 1287 | /* WaEnableGapsTsvCreditFix:kbl */ |
| 1288 | I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) | |
| 1289 | GEN9_GAPS_TSV_CREDIT_DISABLE)); |
| 1290 | |
| 1291 | /* WaDisableDynamicCreditSharing:kbl */ |
| 1292 | if (IS_KBL_REVID(dev_priv, 0, KBL_REVID_B0)) |
Oscar Mateo | c6ea497c | 2017-09-07 08:40:08 -0700 | [diff] [blame] | 1293 | I915_WRITE(GAMT_CHKN_BIT_REG, |
| 1294 | (I915_READ(GAMT_CHKN_BIT_REG) | |
| 1295 | GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1296 | |
| 1297 | /* WaDisableFenceDestinationToSLM:kbl (pre-prod) */ |
| 1298 | if (IS_KBL_REVID(dev_priv, KBL_REVID_A0, KBL_REVID_A0)) |
| 1299 | WA_SET_BIT_MASKED(HDC_CHICKEN0, |
| 1300 | HDC_FENCE_DEST_SLM_DISABLE); |
| 1301 | |
| 1302 | /* WaToEnableHwFixForPushConstHWBug:kbl */ |
| 1303 | if (IS_KBL_REVID(dev_priv, KBL_REVID_C0, REVID_FOREVER)) |
| 1304 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 1305 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); |
| 1306 | |
| 1307 | /* WaDisableGafsUnitClkGating:kbl */ |
Oscar Mateo | 4827c54 | 2017-09-07 08:40:07 -0700 | [diff] [blame] | 1308 | I915_WRITE(GEN7_UCGCTL4, (I915_READ(GEN7_UCGCTL4) | |
| 1309 | GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1310 | |
| 1311 | /* WaDisableSbeCacheDispatchPortSharing:kbl */ |
| 1312 | WA_SET_BIT_MASKED( |
| 1313 | GEN7_HALF_SLICE_CHICKEN1, |
| 1314 | GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); |
| 1315 | |
| 1316 | /* WaInPlaceDecompressionHang:kbl */ |
Oscar Mateo | efc886c | 2017-09-07 08:40:04 -0700 | [diff] [blame] | 1317 | I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA, |
| 1318 | (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) | |
| 1319 | GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS)); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1320 | |
| 1321 | /* WaDisableLSQCROPERFforOCL:kbl */ |
| 1322 | ret = wa_ring_whitelist_reg(engine, GEN8_L3SQCREG4); |
| 1323 | if (ret) |
| 1324 | return ret; |
| 1325 | |
| 1326 | return 0; |
| 1327 | } |
| 1328 | |
| 1329 | static int glk_init_workarounds(struct intel_engine_cs *engine) |
| 1330 | { |
| 1331 | struct drm_i915_private *dev_priv = engine->i915; |
| 1332 | int ret; |
| 1333 | |
| 1334 | ret = gen9_init_workarounds(engine); |
| 1335 | if (ret) |
| 1336 | return ret; |
| 1337 | |
| 1338 | /* WaToEnableHwFixForPushConstHWBug:glk */ |
| 1339 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 1340 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); |
| 1341 | |
| 1342 | return 0; |
| 1343 | } |
| 1344 | |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1345 | static int cfl_init_workarounds(struct intel_engine_cs *engine) |
| 1346 | { |
| 1347 | struct drm_i915_private *dev_priv = engine->i915; |
| 1348 | int ret; |
| 1349 | |
| 1350 | ret = gen9_init_workarounds(engine); |
| 1351 | if (ret) |
| 1352 | return ret; |
| 1353 | |
| 1354 | /* WaEnableGapsTsvCreditFix:cfl */ |
| 1355 | I915_WRITE(GEN8_GARBCNTL, (I915_READ(GEN8_GARBCNTL) | |
| 1356 | GEN9_GAPS_TSV_CREDIT_DISABLE)); |
| 1357 | |
| 1358 | /* WaToEnableHwFixForPushConstHWBug:cfl */ |
| 1359 | WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2, |
| 1360 | GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); |
| 1361 | |
| 1362 | /* WaDisableGafsUnitClkGating:cfl */ |
Oscar Mateo | 4827c54 | 2017-09-07 08:40:07 -0700 | [diff] [blame] | 1363 | I915_WRITE(GEN7_UCGCTL4, (I915_READ(GEN7_UCGCTL4) | |
| 1364 | GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE)); |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1365 | |
| 1366 | /* WaDisableSbeCacheDispatchPortSharing:cfl */ |
| 1367 | WA_SET_BIT_MASKED( |
| 1368 | GEN7_HALF_SLICE_CHICKEN1, |
| 1369 | GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); |
| 1370 | |
| 1371 | /* WaInPlaceDecompressionHang:cfl */ |
Oscar Mateo | efc886c | 2017-09-07 08:40:04 -0700 | [diff] [blame] | 1372 | I915_WRITE(GEN9_GAMT_ECO_REG_RW_IA, |
| 1373 | (I915_READ(GEN9_GAMT_ECO_REG_RW_IA) | |
| 1374 | GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS)); |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1375 | |
| 1376 | return 0; |
| 1377 | } |
| 1378 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1379 | int init_workarounds_ring(struct intel_engine_cs *engine) |
| 1380 | { |
| 1381 | struct drm_i915_private *dev_priv = engine->i915; |
Chris Wilson | 02e012f | 2017-03-01 12:11:31 +0000 | [diff] [blame] | 1382 | int err; |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1383 | |
| 1384 | WARN_ON(engine->id != RCS); |
| 1385 | |
| 1386 | dev_priv->workarounds.count = 0; |
Chris Wilson | 02e012f | 2017-03-01 12:11:31 +0000 | [diff] [blame] | 1387 | dev_priv->workarounds.hw_whitelist_count[engine->id] = 0; |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1388 | |
| 1389 | if (IS_BROADWELL(dev_priv)) |
Chris Wilson | 02e012f | 2017-03-01 12:11:31 +0000 | [diff] [blame] | 1390 | err = bdw_init_workarounds(engine); |
| 1391 | else if (IS_CHERRYVIEW(dev_priv)) |
| 1392 | err = chv_init_workarounds(engine); |
| 1393 | else if (IS_SKYLAKE(dev_priv)) |
| 1394 | err = skl_init_workarounds(engine); |
| 1395 | else if (IS_BROXTON(dev_priv)) |
| 1396 | err = bxt_init_workarounds(engine); |
| 1397 | else if (IS_KABYLAKE(dev_priv)) |
| 1398 | err = kbl_init_workarounds(engine); |
| 1399 | else if (IS_GEMINILAKE(dev_priv)) |
| 1400 | err = glk_init_workarounds(engine); |
Rodrigo Vivi | 46c2666 | 2017-06-16 15:49:58 -0700 | [diff] [blame] | 1401 | else if (IS_COFFEELAKE(dev_priv)) |
| 1402 | err = cfl_init_workarounds(engine); |
Rodrigo Vivi | 90007bc | 2017-08-15 16:16:48 -0700 | [diff] [blame] | 1403 | else if (IS_CANNONLAKE(dev_priv)) |
| 1404 | err = cnl_init_workarounds(engine); |
Chris Wilson | 02e012f | 2017-03-01 12:11:31 +0000 | [diff] [blame] | 1405 | else |
| 1406 | err = 0; |
| 1407 | if (err) |
| 1408 | return err; |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1409 | |
Chris Wilson | 02e012f | 2017-03-01 12:11:31 +0000 | [diff] [blame] | 1410 | DRM_DEBUG_DRIVER("%s: Number of context specific w/a: %d\n", |
| 1411 | engine->name, dev_priv->workarounds.count); |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1412 | return 0; |
| 1413 | } |
| 1414 | |
| 1415 | int intel_ring_workarounds_emit(struct drm_i915_gem_request *req) |
| 1416 | { |
| 1417 | struct i915_workarounds *w = &req->i915->workarounds; |
| 1418 | u32 *cs; |
| 1419 | int ret, i; |
| 1420 | |
| 1421 | if (w->count == 0) |
| 1422 | return 0; |
| 1423 | |
| 1424 | ret = req->engine->emit_flush(req, EMIT_BARRIER); |
| 1425 | if (ret) |
| 1426 | return ret; |
| 1427 | |
| 1428 | cs = intel_ring_begin(req, (w->count * 2 + 2)); |
| 1429 | if (IS_ERR(cs)) |
| 1430 | return PTR_ERR(cs); |
| 1431 | |
| 1432 | *cs++ = MI_LOAD_REGISTER_IMM(w->count); |
| 1433 | for (i = 0; i < w->count; i++) { |
| 1434 | *cs++ = i915_mmio_reg_offset(w->reg[i].addr); |
| 1435 | *cs++ = w->reg[i].value; |
| 1436 | } |
| 1437 | *cs++ = MI_NOOP; |
| 1438 | |
| 1439 | intel_ring_advance(req, cs); |
| 1440 | |
| 1441 | ret = req->engine->emit_flush(req, EMIT_BARRIER); |
| 1442 | if (ret) |
| 1443 | return ret; |
| 1444 | |
Tvrtko Ursulin | 133b4bd | 2017-02-16 12:23:23 +0000 | [diff] [blame] | 1445 | return 0; |
| 1446 | } |
| 1447 | |
Chris Wilson | a091d4e | 2017-05-30 13:13:33 +0100 | [diff] [blame] | 1448 | static bool ring_is_idle(struct intel_engine_cs *engine) |
| 1449 | { |
| 1450 | struct drm_i915_private *dev_priv = engine->i915; |
| 1451 | bool idle = true; |
| 1452 | |
| 1453 | intel_runtime_pm_get(dev_priv); |
| 1454 | |
Chris Wilson | aed2fc1 | 2017-05-30 13:13:34 +0100 | [diff] [blame] | 1455 | /* First check that no commands are left in the ring */ |
| 1456 | if ((I915_READ_HEAD(engine) & HEAD_ADDR) != |
| 1457 | (I915_READ_TAIL(engine) & TAIL_ADDR)) |
| 1458 | idle = false; |
| 1459 | |
Chris Wilson | a091d4e | 2017-05-30 13:13:33 +0100 | [diff] [blame] | 1460 | /* No bit for gen2, so assume the CS parser is idle */ |
| 1461 | if (INTEL_GEN(dev_priv) > 2 && !(I915_READ_MODE(engine) & MODE_IDLE)) |
| 1462 | idle = false; |
| 1463 | |
| 1464 | intel_runtime_pm_put(dev_priv); |
| 1465 | |
| 1466 | return idle; |
| 1467 | } |
| 1468 | |
Chris Wilson | 5400367 | 2017-03-03 12:19:46 +0000 | [diff] [blame] | 1469 | /** |
| 1470 | * intel_engine_is_idle() - Report if the engine has finished process all work |
| 1471 | * @engine: the intel_engine_cs |
| 1472 | * |
| 1473 | * Return true if there are no requests pending, nothing left to be submitted |
| 1474 | * to hardware, and that the engine is idle. |
| 1475 | */ |
| 1476 | bool intel_engine_is_idle(struct intel_engine_cs *engine) |
| 1477 | { |
| 1478 | struct drm_i915_private *dev_priv = engine->i915; |
| 1479 | |
Chris Wilson | a8e9a41 | 2017-04-11 20:00:42 +0100 | [diff] [blame] | 1480 | /* More white lies, if wedged, hw state is inconsistent */ |
| 1481 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 1482 | return true; |
| 1483 | |
Chris Wilson | 5400367 | 2017-03-03 12:19:46 +0000 | [diff] [blame] | 1484 | /* Any inflight/incomplete requests? */ |
| 1485 | if (!i915_seqno_passed(intel_engine_get_seqno(engine), |
| 1486 | intel_engine_last_submit(engine))) |
| 1487 | return false; |
| 1488 | |
Chris Wilson | 8968a36 | 2017-04-12 00:44:26 +0100 | [diff] [blame] | 1489 | if (I915_SELFTEST_ONLY(engine->breadcrumbs.mock)) |
| 1490 | return true; |
| 1491 | |
Chris Wilson | 5400367 | 2017-03-03 12:19:46 +0000 | [diff] [blame] | 1492 | /* Interrupt/tasklet pending? */ |
| 1493 | if (test_bit(ENGINE_IRQ_EXECLIST, &engine->irq_posted)) |
| 1494 | return false; |
| 1495 | |
Chris Wilson | 4a118ec | 2017-10-23 22:32:36 +0100 | [diff] [blame] | 1496 | /* Waiting to drain ELSP? */ |
| 1497 | if (READ_ONCE(engine->execlists.active)) |
Chris Wilson | 5400367 | 2017-03-03 12:19:46 +0000 | [diff] [blame] | 1498 | return false; |
| 1499 | |
Chris Wilson | d6edb6e | 2017-07-21 13:32:24 +0100 | [diff] [blame] | 1500 | /* ELSP is empty, but there are ready requests? */ |
Mika Kuoppala | b620e87 | 2017-09-22 15:43:03 +0300 | [diff] [blame] | 1501 | if (READ_ONCE(engine->execlists.first)) |
Chris Wilson | d6edb6e | 2017-07-21 13:32:24 +0100 | [diff] [blame] | 1502 | return false; |
| 1503 | |
Chris Wilson | 5400367 | 2017-03-03 12:19:46 +0000 | [diff] [blame] | 1504 | /* Ring stopped? */ |
Chris Wilson | a091d4e | 2017-05-30 13:13:33 +0100 | [diff] [blame] | 1505 | if (!ring_is_idle(engine)) |
Chris Wilson | 5400367 | 2017-03-03 12:19:46 +0000 | [diff] [blame] | 1506 | return false; |
| 1507 | |
| 1508 | return true; |
| 1509 | } |
| 1510 | |
Chris Wilson | 0542524 | 2017-03-03 12:19:47 +0000 | [diff] [blame] | 1511 | bool intel_engines_are_idle(struct drm_i915_private *dev_priv) |
| 1512 | { |
| 1513 | struct intel_engine_cs *engine; |
| 1514 | enum intel_engine_id id; |
| 1515 | |
Chris Wilson | d7dc413 | 2017-12-12 13:21:48 +0000 | [diff] [blame] | 1516 | /* |
| 1517 | * If the driver is wedged, HW state may be very inconsistent and |
Chris Wilson | 8490ae20 | 2017-03-30 15:50:37 +0100 | [diff] [blame] | 1518 | * report that it is still busy, even though we have stopped using it. |
| 1519 | */ |
| 1520 | if (i915_terminally_wedged(&dev_priv->gpu_error)) |
| 1521 | return true; |
| 1522 | |
Chris Wilson | 0542524 | 2017-03-03 12:19:47 +0000 | [diff] [blame] | 1523 | for_each_engine(engine, dev_priv, id) { |
| 1524 | if (!intel_engine_is_idle(engine)) |
| 1525 | return false; |
| 1526 | } |
| 1527 | |
| 1528 | return true; |
| 1529 | } |
| 1530 | |
Chris Wilson | ae6c457 | 2017-11-10 14:26:28 +0000 | [diff] [blame] | 1531 | /** |
| 1532 | * intel_engine_has_kernel_context: |
| 1533 | * @engine: the engine |
| 1534 | * |
| 1535 | * Returns true if the last context to be executed on this engine, or has been |
| 1536 | * executed if the engine is already idle, is the kernel context |
| 1537 | * (#i915.kernel_context). |
| 1538 | */ |
Chris Wilson | 20ccd4d | 2017-10-24 23:08:55 +0100 | [diff] [blame] | 1539 | bool intel_engine_has_kernel_context(const struct intel_engine_cs *engine) |
| 1540 | { |
Chris Wilson | ae6c457 | 2017-11-10 14:26:28 +0000 | [diff] [blame] | 1541 | const struct i915_gem_context * const kernel_context = |
| 1542 | engine->i915->kernel_context; |
| 1543 | struct drm_i915_gem_request *rq; |
| 1544 | |
| 1545 | lockdep_assert_held(&engine->i915->drm.struct_mutex); |
| 1546 | |
| 1547 | /* |
| 1548 | * Check the last context seen by the engine. If active, it will be |
| 1549 | * the last request that remains in the timeline. When idle, it is |
| 1550 | * the last executed context as tracked by retirement. |
| 1551 | */ |
| 1552 | rq = __i915_gem_active_peek(&engine->timeline->last_request); |
| 1553 | if (rq) |
| 1554 | return rq->ctx == kernel_context; |
| 1555 | else |
| 1556 | return engine->last_retired_context == kernel_context; |
Chris Wilson | 20ccd4d | 2017-10-24 23:08:55 +0100 | [diff] [blame] | 1557 | } |
| 1558 | |
Chris Wilson | ff44ad5 | 2017-03-16 17:13:03 +0000 | [diff] [blame] | 1559 | void intel_engines_reset_default_submission(struct drm_i915_private *i915) |
| 1560 | { |
| 1561 | struct intel_engine_cs *engine; |
| 1562 | enum intel_engine_id id; |
| 1563 | |
| 1564 | for_each_engine(engine, i915, id) |
| 1565 | engine->set_default_submission(engine); |
| 1566 | } |
| 1567 | |
Chris Wilson | aba5e27 | 2017-10-25 15:39:41 +0100 | [diff] [blame] | 1568 | /** |
| 1569 | * intel_engines_park: called when the GT is transitioning from busy->idle |
| 1570 | * @i915: the i915 device |
| 1571 | * |
| 1572 | * The GT is now idle and about to go to sleep (maybe never to wake again?). |
| 1573 | * Time for us to tidy and put away our toys (release resources back to the |
| 1574 | * system). |
| 1575 | */ |
| 1576 | void intel_engines_park(struct drm_i915_private *i915) |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 1577 | { |
| 1578 | struct intel_engine_cs *engine; |
| 1579 | enum intel_engine_id id; |
| 1580 | |
| 1581 | for_each_engine(engine, i915, id) { |
Chris Wilson | 820c5bb | 2017-11-01 20:21:49 +0000 | [diff] [blame] | 1582 | /* Flush the residual irq tasklets first. */ |
| 1583 | intel_engine_disarm_breadcrumbs(engine); |
Sagar Arun Kamble | c6dce8f | 2017-11-16 19:02:37 +0530 | [diff] [blame] | 1584 | tasklet_kill(&engine->execlists.tasklet); |
Chris Wilson | 820c5bb | 2017-11-01 20:21:49 +0000 | [diff] [blame] | 1585 | |
Chris Wilson | 3265124 | 2017-10-27 12:06:17 +0100 | [diff] [blame] | 1586 | /* |
| 1587 | * We are committed now to parking the engines, make sure there |
| 1588 | * will be no more interrupts arriving later and the engines |
| 1589 | * are truly idle. |
| 1590 | */ |
Chris Wilson | 30b2940 | 2017-11-10 11:25:50 +0000 | [diff] [blame] | 1591 | if (wait_for(intel_engine_is_idle(engine), 10)) { |
Chris Wilson | 3265124 | 2017-10-27 12:06:17 +0100 | [diff] [blame] | 1592 | struct drm_printer p = drm_debug_printer(__func__); |
| 1593 | |
Chris Wilson | 30b2940 | 2017-11-10 11:25:50 +0000 | [diff] [blame] | 1594 | dev_err(i915->drm.dev, |
| 1595 | "%s is not idle before parking\n", |
| 1596 | engine->name); |
Chris Wilson | 0db18b1 | 2017-12-08 01:23:00 +0000 | [diff] [blame] | 1597 | intel_engine_dump(engine, &p, NULL); |
Chris Wilson | 3265124 | 2017-10-27 12:06:17 +0100 | [diff] [blame] | 1598 | } |
| 1599 | |
Chris Wilson | aba5e27 | 2017-10-25 15:39:41 +0100 | [diff] [blame] | 1600 | if (engine->park) |
| 1601 | engine->park(engine); |
| 1602 | |
Chris Wilson | aba5e27 | 2017-10-25 15:39:41 +0100 | [diff] [blame] | 1603 | i915_gem_batch_pool_fini(&engine->batch_pool); |
Mika Kuoppala | b620e87 | 2017-09-22 15:43:03 +0300 | [diff] [blame] | 1604 | engine->execlists.no_priolist = false; |
Chris Wilson | 6c06757 | 2017-05-17 13:10:03 +0100 | [diff] [blame] | 1605 | } |
| 1606 | } |
| 1607 | |
Chris Wilson | aba5e27 | 2017-10-25 15:39:41 +0100 | [diff] [blame] | 1608 | /** |
| 1609 | * intel_engines_unpark: called when the GT is transitioning from idle->busy |
| 1610 | * @i915: the i915 device |
| 1611 | * |
| 1612 | * The GT was idle and now about to fire up with some new user requests. |
| 1613 | */ |
| 1614 | void intel_engines_unpark(struct drm_i915_private *i915) |
| 1615 | { |
| 1616 | struct intel_engine_cs *engine; |
| 1617 | enum intel_engine_id id; |
| 1618 | |
| 1619 | for_each_engine(engine, i915, id) { |
| 1620 | if (engine->unpark) |
| 1621 | engine->unpark(engine); |
| 1622 | } |
| 1623 | } |
| 1624 | |
Chris Wilson | 90cad09 | 2017-09-06 16:28:59 +0100 | [diff] [blame] | 1625 | bool intel_engine_can_store_dword(struct intel_engine_cs *engine) |
| 1626 | { |
| 1627 | switch (INTEL_GEN(engine->i915)) { |
| 1628 | case 2: |
| 1629 | return false; /* uses physical not virtual addresses */ |
| 1630 | case 3: |
| 1631 | /* maybe only uses physical not virtual addresses */ |
| 1632 | return !(IS_I915G(engine->i915) || IS_I915GM(engine->i915)); |
| 1633 | case 6: |
| 1634 | return engine->class != VIDEO_DECODE_CLASS; /* b0rked */ |
| 1635 | default: |
| 1636 | return true; |
| 1637 | } |
| 1638 | } |
| 1639 | |
Chris Wilson | d2b4b97 | 2017-11-10 14:26:33 +0000 | [diff] [blame] | 1640 | unsigned int intel_engines_has_context_isolation(struct drm_i915_private *i915) |
| 1641 | { |
| 1642 | struct intel_engine_cs *engine; |
| 1643 | enum intel_engine_id id; |
| 1644 | unsigned int which; |
| 1645 | |
| 1646 | which = 0; |
| 1647 | for_each_engine(engine, i915, id) |
| 1648 | if (engine->default_state) |
| 1649 | which |= BIT(engine->uabi_class); |
| 1650 | |
| 1651 | return which; |
| 1652 | } |
| 1653 | |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1654 | static void print_request(struct drm_printer *m, |
| 1655 | struct drm_i915_gem_request *rq, |
| 1656 | const char *prefix) |
| 1657 | { |
Chris Wilson | a27d5a4 | 2017-10-15 21:43:10 +0100 | [diff] [blame] | 1658 | drm_printf(m, "%s%x%s [%x:%x] prio=%d @ %dms: %s\n", prefix, |
| 1659 | rq->global_seqno, |
| 1660 | i915_gem_request_completed(rq) ? "!" : "", |
| 1661 | rq->ctx->hw_id, rq->fence.seqno, |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1662 | rq->priotree.priority, |
| 1663 | jiffies_to_msecs(jiffies - rq->emitted_jiffies), |
| 1664 | rq->timeline->common->name); |
| 1665 | } |
| 1666 | |
Chris Wilson | 0db18b1 | 2017-12-08 01:23:00 +0000 | [diff] [blame] | 1667 | void intel_engine_dump(struct intel_engine_cs *engine, |
| 1668 | struct drm_printer *m, |
| 1669 | const char *header, ...) |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1670 | { |
Chris Wilson | a27d5a4 | 2017-10-15 21:43:10 +0100 | [diff] [blame] | 1671 | struct intel_breadcrumbs * const b = &engine->breadcrumbs; |
| 1672 | const struct intel_engine_execlists * const execlists = &engine->execlists; |
| 1673 | struct i915_gpu_error * const error = &engine->i915->gpu_error; |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1674 | struct drm_i915_private *dev_priv = engine->i915; |
| 1675 | struct drm_i915_gem_request *rq; |
| 1676 | struct rb_node *rb; |
Chris Wilson | e8a70ca | 2017-12-08 01:22:59 +0000 | [diff] [blame] | 1677 | char hdr[80]; |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1678 | u64 addr; |
| 1679 | |
Chris Wilson | 0db18b1 | 2017-12-08 01:23:00 +0000 | [diff] [blame] | 1680 | if (header) { |
| 1681 | va_list ap; |
| 1682 | |
| 1683 | va_start(ap, header); |
| 1684 | drm_vprintf(m, header, &ap); |
| 1685 | va_end(ap); |
| 1686 | } |
| 1687 | |
Chris Wilson | 2d8d1af | 2017-12-08 01:23:03 +0000 | [diff] [blame] | 1688 | if (i915_terminally_wedged(&engine->i915->gpu_error)) |
| 1689 | drm_printf(m, "*** WEDGED ***\n"); |
| 1690 | |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1691 | drm_printf(m, "\tcurrent seqno %x, last %x, hangcheck %x [%d ms], inflight %d\n", |
| 1692 | intel_engine_get_seqno(engine), |
| 1693 | intel_engine_last_submit(engine), |
| 1694 | engine->hangcheck.seqno, |
| 1695 | jiffies_to_msecs(jiffies - engine->hangcheck.action_timestamp), |
| 1696 | engine->timeline->inflight_seqnos); |
Chris Wilson | 528dd16 | 2017-12-08 01:23:02 +0000 | [diff] [blame] | 1697 | drm_printf(m, "\tReset count: %d (global %d)\n", |
| 1698 | i915_reset_engine_count(error, engine), |
| 1699 | i915_reset_count(error)); |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1700 | |
| 1701 | rcu_read_lock(); |
| 1702 | |
| 1703 | drm_printf(m, "\tRequests:\n"); |
| 1704 | |
| 1705 | rq = list_first_entry(&engine->timeline->requests, |
| 1706 | struct drm_i915_gem_request, link); |
| 1707 | if (&rq->link != &engine->timeline->requests) |
| 1708 | print_request(m, rq, "\t\tfirst "); |
| 1709 | |
| 1710 | rq = list_last_entry(&engine->timeline->requests, |
| 1711 | struct drm_i915_gem_request, link); |
| 1712 | if (&rq->link != &engine->timeline->requests) |
| 1713 | print_request(m, rq, "\t\tlast "); |
| 1714 | |
| 1715 | rq = i915_gem_find_active_request(engine); |
| 1716 | if (rq) { |
| 1717 | print_request(m, rq, "\t\tactive "); |
| 1718 | drm_printf(m, |
| 1719 | "\t\t[head %04x, postfix %04x, tail %04x, batch 0x%08x_%08x]\n", |
| 1720 | rq->head, rq->postfix, rq->tail, |
| 1721 | rq->batch ? upper_32_bits(rq->batch->node.start) : ~0u, |
| 1722 | rq->batch ? lower_32_bits(rq->batch->node.start) : ~0u); |
| 1723 | } |
| 1724 | |
| 1725 | drm_printf(m, "\tRING_START: 0x%08x [0x%08x]\n", |
| 1726 | I915_READ(RING_START(engine->mmio_base)), |
| 1727 | rq ? i915_ggtt_offset(rq->ring->vma) : 0); |
| 1728 | drm_printf(m, "\tRING_HEAD: 0x%08x [0x%08x]\n", |
| 1729 | I915_READ(RING_HEAD(engine->mmio_base)) & HEAD_ADDR, |
| 1730 | rq ? rq->ring->head : 0); |
| 1731 | drm_printf(m, "\tRING_TAIL: 0x%08x [0x%08x]\n", |
| 1732 | I915_READ(RING_TAIL(engine->mmio_base)) & TAIL_ADDR, |
| 1733 | rq ? rq->ring->tail : 0); |
Chris Wilson | 3c75de5 | 2017-10-26 12:50:48 +0100 | [diff] [blame] | 1734 | drm_printf(m, "\tRING_CTL: 0x%08x%s\n", |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1735 | I915_READ(RING_CTL(engine->mmio_base)), |
Chris Wilson | 3c75de5 | 2017-10-26 12:50:48 +0100 | [diff] [blame] | 1736 | I915_READ(RING_CTL(engine->mmio_base)) & (RING_WAIT | RING_WAIT_SEMAPHORE) ? " [waiting]" : ""); |
| 1737 | if (INTEL_GEN(engine->i915) > 2) { |
| 1738 | drm_printf(m, "\tRING_MODE: 0x%08x%s\n", |
| 1739 | I915_READ(RING_MI_MODE(engine->mmio_base)), |
| 1740 | I915_READ(RING_MI_MODE(engine->mmio_base)) & (MODE_IDLE) ? " [idle]" : ""); |
| 1741 | } |
Chris Wilson | 93c6e96 | 2017-11-20 20:55:04 +0000 | [diff] [blame] | 1742 | if (HAS_LEGACY_SEMAPHORES(dev_priv)) { |
Chris Wilson | af9ff6c | 2017-11-20 20:55:03 +0000 | [diff] [blame] | 1743 | drm_printf(m, "\tSYNC_0: 0x%08x\n", |
| 1744 | I915_READ(RING_SYNC_0(engine->mmio_base))); |
| 1745 | drm_printf(m, "\tSYNC_1: 0x%08x\n", |
| 1746 | I915_READ(RING_SYNC_1(engine->mmio_base))); |
| 1747 | if (HAS_VEBOX(dev_priv)) |
| 1748 | drm_printf(m, "\tSYNC_2: 0x%08x\n", |
| 1749 | I915_READ(RING_SYNC_2(engine->mmio_base))); |
| 1750 | } |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1751 | |
| 1752 | rcu_read_unlock(); |
| 1753 | |
| 1754 | addr = intel_engine_get_active_head(engine); |
| 1755 | drm_printf(m, "\tACTHD: 0x%08x_%08x\n", |
| 1756 | upper_32_bits(addr), lower_32_bits(addr)); |
| 1757 | addr = intel_engine_get_last_batch_head(engine); |
| 1758 | drm_printf(m, "\tBBADDR: 0x%08x_%08x\n", |
| 1759 | upper_32_bits(addr), lower_32_bits(addr)); |
Chris Wilson | a0cf579 | 2017-12-18 12:39:14 +0000 | [diff] [blame^] | 1760 | if (INTEL_GEN(dev_priv) >= 8) |
| 1761 | addr = I915_READ64_2x32(RING_DMA_FADD(engine->mmio_base), |
| 1762 | RING_DMA_FADD_UDW(engine->mmio_base)); |
| 1763 | else if (INTEL_GEN(dev_priv) >= 4) |
| 1764 | addr = I915_READ(RING_DMA_FADD(engine->mmio_base)); |
| 1765 | else |
| 1766 | addr = I915_READ(DMA_FADD_I8XX); |
| 1767 | drm_printf(m, "\tDMA_FADDR: 0x%08x_%08x\n", |
| 1768 | upper_32_bits(addr), lower_32_bits(addr)); |
| 1769 | if (INTEL_GEN(dev_priv) >= 4) { |
| 1770 | drm_printf(m, "\tIPEIR: 0x%08x\n", |
| 1771 | I915_READ(RING_IPEIR(engine->mmio_base))); |
| 1772 | drm_printf(m, "\tIPEHR: 0x%08x\n", |
| 1773 | I915_READ(RING_IPEHR(engine->mmio_base))); |
| 1774 | } else { |
| 1775 | drm_printf(m, "\tIPEIR: 0x%08x\n", I915_READ(IPEIR)); |
| 1776 | drm_printf(m, "\tIPEHR: 0x%08x\n", I915_READ(IPEHR)); |
| 1777 | } |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1778 | |
Chris Wilson | fb5c551 | 2017-11-20 20:55:00 +0000 | [diff] [blame] | 1779 | if (HAS_EXECLISTS(dev_priv)) { |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1780 | const u32 *hws = &engine->status_page.page_addr[I915_HWS_CSB_BUF0_INDEX]; |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1781 | u32 ptr, read, write; |
| 1782 | unsigned int idx; |
| 1783 | |
| 1784 | drm_printf(m, "\tExeclist status: 0x%08x %08x\n", |
| 1785 | I915_READ(RING_EXECLIST_STATUS_LO(engine)), |
| 1786 | I915_READ(RING_EXECLIST_STATUS_HI(engine))); |
| 1787 | |
| 1788 | ptr = I915_READ(RING_CONTEXT_STATUS_PTR(engine)); |
| 1789 | read = GEN8_CSB_READ_PTR(ptr); |
| 1790 | write = GEN8_CSB_WRITE_PTR(ptr); |
| 1791 | drm_printf(m, "\tExeclist CSB read %d [%d cached], write %d [%d from hws], interrupt posted? %s\n", |
| 1792 | read, execlists->csb_head, |
| 1793 | write, |
| 1794 | intel_read_status_page(engine, intel_hws_csb_write_index(engine->i915)), |
| 1795 | yesno(test_bit(ENGINE_IRQ_EXECLIST, |
| 1796 | &engine->irq_posted))); |
| 1797 | if (read >= GEN8_CSB_ENTRIES) |
| 1798 | read = 0; |
| 1799 | if (write >= GEN8_CSB_ENTRIES) |
| 1800 | write = 0; |
| 1801 | if (read > write) |
| 1802 | write += GEN8_CSB_ENTRIES; |
| 1803 | while (read < write) { |
| 1804 | idx = ++read % GEN8_CSB_ENTRIES; |
| 1805 | drm_printf(m, "\tExeclist CSB[%d]: 0x%08x [0x%08x in hwsp], context: %d [%d in hwsp]\n", |
| 1806 | idx, |
| 1807 | I915_READ(RING_CONTEXT_STATUS_BUF_LO(engine, idx)), |
| 1808 | hws[idx * 2], |
| 1809 | I915_READ(RING_CONTEXT_STATUS_BUF_HI(engine, idx)), |
| 1810 | hws[idx * 2 + 1]); |
| 1811 | } |
| 1812 | |
| 1813 | rcu_read_lock(); |
| 1814 | for (idx = 0; idx < execlists_num_ports(execlists); idx++) { |
| 1815 | unsigned int count; |
| 1816 | |
| 1817 | rq = port_unpack(&execlists->port[idx], &count); |
| 1818 | if (rq) { |
Chris Wilson | e8a70ca | 2017-12-08 01:22:59 +0000 | [diff] [blame] | 1819 | snprintf(hdr, sizeof(hdr), |
| 1820 | "\t\tELSP[%d] count=%d, rq: ", |
| 1821 | idx, count); |
| 1822 | print_request(m, rq, hdr); |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1823 | } else { |
Chris Wilson | e8a70ca | 2017-12-08 01:22:59 +0000 | [diff] [blame] | 1824 | drm_printf(m, "\t\tELSP[%d] idle\n", idx); |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1825 | } |
| 1826 | } |
Chris Wilson | 4a118ec | 2017-10-23 22:32:36 +0100 | [diff] [blame] | 1827 | drm_printf(m, "\t\tHW active? 0x%x\n", execlists->active); |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1828 | rcu_read_unlock(); |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1829 | } else if (INTEL_GEN(dev_priv) > 6) { |
| 1830 | drm_printf(m, "\tPP_DIR_BASE: 0x%08x\n", |
| 1831 | I915_READ(RING_PP_DIR_BASE(engine))); |
| 1832 | drm_printf(m, "\tPP_DIR_BASE_READ: 0x%08x\n", |
| 1833 | I915_READ(RING_PP_DIR_BASE_READ(engine))); |
| 1834 | drm_printf(m, "\tPP_DIR_DCLV: 0x%08x\n", |
| 1835 | I915_READ(RING_PP_DIR_DCLV(engine))); |
| 1836 | } |
| 1837 | |
Chris Wilson | a27d5a4 | 2017-10-15 21:43:10 +0100 | [diff] [blame] | 1838 | spin_lock_irq(&engine->timeline->lock); |
| 1839 | list_for_each_entry(rq, &engine->timeline->requests, link) |
| 1840 | print_request(m, rq, "\t\tE "); |
| 1841 | for (rb = execlists->first; rb; rb = rb_next(rb)) { |
| 1842 | struct i915_priolist *p = |
| 1843 | rb_entry(rb, typeof(*p), node); |
| 1844 | |
| 1845 | list_for_each_entry(rq, &p->requests, priotree.link) |
| 1846 | print_request(m, rq, "\t\tQ "); |
| 1847 | } |
| 1848 | spin_unlock_irq(&engine->timeline->lock); |
| 1849 | |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1850 | spin_lock_irq(&b->rb_lock); |
| 1851 | for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) { |
| 1852 | struct intel_wait *w = rb_entry(rb, typeof(*w), node); |
| 1853 | |
| 1854 | drm_printf(m, "\t%s [%d] waiting for %x\n", |
| 1855 | w->tsk->comm, w->tsk->pid, w->seqno); |
| 1856 | } |
| 1857 | spin_unlock_irq(&b->rb_lock); |
| 1858 | |
Chris Wilson | d5acadf | 2017-12-09 10:44:18 +0000 | [diff] [blame] | 1859 | if (INTEL_GEN(dev_priv) >= 6) { |
| 1860 | drm_printf(m, "\tRING_IMR: %08x\n", I915_READ_IMR(engine)); |
| 1861 | } |
| 1862 | |
Chris Wilson | 832265d | 2017-12-08 01:23:01 +0000 | [diff] [blame] | 1863 | drm_printf(m, "IRQ? 0x%lx (breadcrumbs? %s) (execlists? %s)\n", |
| 1864 | engine->irq_posted, |
| 1865 | yesno(test_bit(ENGINE_IRQ_BREADCRUMB, |
| 1866 | &engine->irq_posted)), |
| 1867 | yesno(test_bit(ENGINE_IRQ_EXECLIST, |
| 1868 | &engine->irq_posted))); |
Chris Wilson | c400cc2 | 2017-11-07 15:22:11 +0000 | [diff] [blame] | 1869 | drm_printf(m, "Idle? %s\n", yesno(intel_engine_is_idle(engine))); |
Chris Wilson | f636edb | 2017-10-09 12:02:57 +0100 | [diff] [blame] | 1870 | drm_printf(m, "\n"); |
| 1871 | } |
| 1872 | |
Tvrtko Ursulin | b46a33e | 2017-11-21 18:18:45 +0000 | [diff] [blame] | 1873 | static u8 user_class_map[] = { |
| 1874 | [I915_ENGINE_CLASS_RENDER] = RENDER_CLASS, |
| 1875 | [I915_ENGINE_CLASS_COPY] = COPY_ENGINE_CLASS, |
| 1876 | [I915_ENGINE_CLASS_VIDEO] = VIDEO_DECODE_CLASS, |
| 1877 | [I915_ENGINE_CLASS_VIDEO_ENHANCE] = VIDEO_ENHANCEMENT_CLASS, |
| 1878 | }; |
| 1879 | |
| 1880 | struct intel_engine_cs * |
| 1881 | intel_engine_lookup_user(struct drm_i915_private *i915, u8 class, u8 instance) |
| 1882 | { |
| 1883 | if (class >= ARRAY_SIZE(user_class_map)) |
| 1884 | return NULL; |
| 1885 | |
| 1886 | class = user_class_map[class]; |
| 1887 | |
| 1888 | GEM_BUG_ON(class > MAX_ENGINE_CLASS); |
| 1889 | |
| 1890 | if (instance > MAX_ENGINE_INSTANCE) |
| 1891 | return NULL; |
| 1892 | |
| 1893 | return i915->engine_class[class][instance]; |
| 1894 | } |
| 1895 | |
Tvrtko Ursulin | 30e17b7 | 2017-11-21 18:18:48 +0000 | [diff] [blame] | 1896 | /** |
| 1897 | * intel_enable_engine_stats() - Enable engine busy tracking on engine |
| 1898 | * @engine: engine to enable stats collection |
| 1899 | * |
| 1900 | * Start collecting the engine busyness data for @engine. |
| 1901 | * |
| 1902 | * Returns 0 on success or a negative error code. |
| 1903 | */ |
| 1904 | int intel_enable_engine_stats(struct intel_engine_cs *engine) |
| 1905 | { |
| 1906 | unsigned long flags; |
| 1907 | |
Tvrtko Ursulin | cf669b4 | 2017-11-29 10:28:05 +0000 | [diff] [blame] | 1908 | if (!intel_engine_supports_stats(engine)) |
Tvrtko Ursulin | 30e17b7 | 2017-11-21 18:18:48 +0000 | [diff] [blame] | 1909 | return -ENODEV; |
| 1910 | |
| 1911 | spin_lock_irqsave(&engine->stats.lock, flags); |
| 1912 | if (engine->stats.enabled == ~0) |
| 1913 | goto busy; |
| 1914 | if (engine->stats.enabled++ == 0) |
| 1915 | engine->stats.enabled_at = ktime_get(); |
| 1916 | spin_unlock_irqrestore(&engine->stats.lock, flags); |
| 1917 | |
| 1918 | return 0; |
| 1919 | |
| 1920 | busy: |
| 1921 | spin_unlock_irqrestore(&engine->stats.lock, flags); |
| 1922 | |
| 1923 | return -EBUSY; |
| 1924 | } |
| 1925 | |
| 1926 | static ktime_t __intel_engine_get_busy_time(struct intel_engine_cs *engine) |
| 1927 | { |
| 1928 | ktime_t total = engine->stats.total; |
| 1929 | |
| 1930 | /* |
| 1931 | * If the engine is executing something at the moment |
| 1932 | * add it to the total. |
| 1933 | */ |
| 1934 | if (engine->stats.active) |
| 1935 | total = ktime_add(total, |
| 1936 | ktime_sub(ktime_get(), engine->stats.start)); |
| 1937 | |
| 1938 | return total; |
| 1939 | } |
| 1940 | |
| 1941 | /** |
| 1942 | * intel_engine_get_busy_time() - Return current accumulated engine busyness |
| 1943 | * @engine: engine to report on |
| 1944 | * |
| 1945 | * Returns accumulated time @engine was busy since engine stats were enabled. |
| 1946 | */ |
| 1947 | ktime_t intel_engine_get_busy_time(struct intel_engine_cs *engine) |
| 1948 | { |
| 1949 | ktime_t total; |
| 1950 | unsigned long flags; |
| 1951 | |
| 1952 | spin_lock_irqsave(&engine->stats.lock, flags); |
| 1953 | total = __intel_engine_get_busy_time(engine); |
| 1954 | spin_unlock_irqrestore(&engine->stats.lock, flags); |
| 1955 | |
| 1956 | return total; |
| 1957 | } |
| 1958 | |
| 1959 | /** |
| 1960 | * intel_disable_engine_stats() - Disable engine busy tracking on engine |
| 1961 | * @engine: engine to disable stats collection |
| 1962 | * |
| 1963 | * Stops collecting the engine busyness data for @engine. |
| 1964 | */ |
| 1965 | void intel_disable_engine_stats(struct intel_engine_cs *engine) |
| 1966 | { |
| 1967 | unsigned long flags; |
| 1968 | |
Tvrtko Ursulin | cf669b4 | 2017-11-29 10:28:05 +0000 | [diff] [blame] | 1969 | if (!intel_engine_supports_stats(engine)) |
Tvrtko Ursulin | 30e17b7 | 2017-11-21 18:18:48 +0000 | [diff] [blame] | 1970 | return; |
| 1971 | |
| 1972 | spin_lock_irqsave(&engine->stats.lock, flags); |
| 1973 | WARN_ON_ONCE(engine->stats.enabled == 0); |
| 1974 | if (--engine->stats.enabled == 0) { |
| 1975 | engine->stats.total = __intel_engine_get_busy_time(engine); |
| 1976 | engine->stats.active = 0; |
| 1977 | } |
| 1978 | spin_unlock_irqrestore(&engine->stats.lock, flags); |
| 1979 | } |
| 1980 | |
Chris Wilson | f97fbf9 | 2017-02-13 17:15:14 +0000 | [diff] [blame] | 1981 | #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) |
| 1982 | #include "selftests/mock_engine.c" |
| 1983 | #endif |