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