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