2 * SPDX-License-Identifier: MIT
4 * Copyright © 2014-2018 Intel Corporation
8 #include "intel_workarounds.h"
11 * DOC: Hardware workarounds
13 * This file is intended as a central place to implement most [1]_ of the
14 * required workarounds for hardware to work as originally intended. They fall
15 * in five basic categories depending on how/when they are applied:
17 * - Workarounds that touch registers that are saved/restored to/from the HW
18 * context image. The list is emitted (via Load Register Immediate commands)
19 * everytime a new context is created.
20 * - GT workarounds. The list of these WAs is applied whenever these registers
21 * revert to default values (on GPU reset, suspend/resume [2]_, etc..).
22 * - Display workarounds. The list is applied during display clock-gating
24 * - Workarounds that whitelist a privileged register, so that UMDs can manage
25 * them directly. This is just a special case of a MMMIO workaround (as we
26 * write the list of these to/be-whitelisted registers to some special HW
28 * - Workaround batchbuffers, that get executed automatically by the hardware
29 * on every HW context restore.
31 * .. [1] Please notice that there are other WAs that, due to their nature,
32 * cannot be applied from a central place. Those are peppered around the rest
33 * of the code, as needed.
35 * .. [2] Technically, some registers are powercontext saved & restored, so they
36 * survive a suspend/resume. In practice, writing them again is not too
37 * costly and simplifies things. We can revisit this in the future.
42 * Keep things in this file ordered by WA type, as per the above (context, GT,
43 * display, register whitelist, batchbuffer). Then, inside each type, keep the
46 * - Infrastructure functions and macros
47 * - WAs per platform in standard gen/chrono order
48 * - Public functions to init or apply the given workaround type.
51 static void wa_init_start(struct i915_wa_list *wal, const char *name)
56 #define WA_LIST_CHUNK (1 << 4)
58 static void wa_init_finish(struct i915_wa_list *wal)
60 /* Trim unused entries. */
61 if (!IS_ALIGNED(wal->count, WA_LIST_CHUNK)) {
62 struct i915_wa *list = kmemdup(wal->list,
63 wal->count * sizeof(*list),
75 DRM_DEBUG_DRIVER("Initialized %u %s workarounds\n",
76 wal->wa_count, wal->name);
79 static void _wa_add(struct i915_wa_list *wal, const struct i915_wa *wa)
81 unsigned int addr = i915_mmio_reg_offset(wa->reg);
82 unsigned int start = 0, end = wal->count;
83 const unsigned int grow = WA_LIST_CHUNK;
86 GEM_BUG_ON(!is_power_of_2(grow));
88 if (IS_ALIGNED(wal->count, grow)) { /* Either uninitialized or full. */
91 list = kmalloc_array(ALIGN(wal->count + 1, grow), sizeof(*wa),
94 DRM_ERROR("No space for workaround init!\n");
99 memcpy(list, wal->list, sizeof(*wa) * wal->count);
104 while (start < end) {
105 unsigned int mid = start + (end - start) / 2;
107 if (i915_mmio_reg_offset(wal->list[mid].reg) < addr) {
109 } else if (i915_mmio_reg_offset(wal->list[mid].reg) > addr) {
112 wa_ = &wal->list[mid];
114 if ((wa->mask & ~wa_->mask) == 0) {
115 DRM_ERROR("Discarding overwritten w/a for reg %04x (mask: %08x, value: %08x)\n",
116 i915_mmio_reg_offset(wa_->reg),
117 wa_->mask, wa_->val);
119 wa_->val &= ~wa->mask;
124 wa_->mask |= wa->mask;
130 wa_ = &wal->list[wal->count++];
133 while (wa_-- > wal->list) {
134 GEM_BUG_ON(i915_mmio_reg_offset(wa_[0].reg) ==
135 i915_mmio_reg_offset(wa_[1].reg));
136 if (i915_mmio_reg_offset(wa_[1].reg) >
137 i915_mmio_reg_offset(wa_[0].reg))
140 swap(wa_[1], wa_[0]);
145 __wa_add(struct i915_wa_list *wal, i915_reg_t reg, u32 mask, u32 val)
147 struct i915_wa wa = {
156 #define WA_REG(addr, mask, val) __wa_add(wal, (addr), (mask), (val))
158 #define WA_SET_BIT_MASKED(addr, mask) \
159 WA_REG(addr, (mask), _MASKED_BIT_ENABLE(mask))
161 #define WA_CLR_BIT_MASKED(addr, mask) \
162 WA_REG(addr, (mask), _MASKED_BIT_DISABLE(mask))
164 #define WA_SET_FIELD_MASKED(addr, mask, value) \
165 WA_REG(addr, (mask), _MASKED_FIELD(mask, value))
167 static void gen8_ctx_workarounds_init(struct intel_engine_cs *engine)
169 struct i915_wa_list *wal = &engine->ctx_wa_list;
171 WA_SET_BIT_MASKED(INSTPM, INSTPM_FORCE_ORDERING);
173 /* WaDisableAsyncFlipPerfMode:bdw,chv */
174 WA_SET_BIT_MASKED(MI_MODE, ASYNC_FLIP_PERF_DISABLE);
176 /* WaDisablePartialInstShootdown:bdw,chv */
177 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
178 PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
180 /* Use Force Non-Coherent whenever executing a 3D context. This is a
181 * workaround for for a possible hang in the unlikely event a TLB
182 * invalidation occurs during a PSD flush.
184 /* WaForceEnableNonCoherent:bdw,chv */
185 /* WaHdcDisableFetchWhenMasked:bdw,chv */
186 WA_SET_BIT_MASKED(HDC_CHICKEN0,
187 HDC_DONOT_FETCH_MEM_WHEN_MASKED |
188 HDC_FORCE_NON_COHERENT);
190 /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0:
191 * "The Hierarchical Z RAW Stall Optimization allows non-overlapping
192 * polygons in the same 8x4 pixel/sample area to be processed without
193 * stalling waiting for the earlier ones to write to Hierarchical Z
196 * This optimization is off by default for BDW and CHV; turn it on.
198 WA_CLR_BIT_MASKED(CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE);
200 /* Wa4x4STCOptimizationDisable:bdw,chv */
201 WA_SET_BIT_MASKED(CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE);
204 * BSpec recommends 8x4 when MSAA is used,
205 * however in practice 16x4 seems fastest.
207 * Note that PS/WM thread counts depend on the WIZ hashing
208 * disable bit, which we don't touch here, but it's good
209 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM).
211 WA_SET_FIELD_MASKED(GEN7_GT_MODE,
212 GEN6_WIZ_HASHING_MASK,
213 GEN6_WIZ_HASHING_16x4);
216 static void bdw_ctx_workarounds_init(struct intel_engine_cs *engine)
218 struct drm_i915_private *i915 = engine->i915;
219 struct i915_wa_list *wal = &engine->ctx_wa_list;
221 gen8_ctx_workarounds_init(engine);
223 /* WaDisableThreadStallDopClockGating:bdw (pre-production) */
224 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
226 /* WaDisableDopClockGating:bdw
228 * Also see the related UCGTCL1 write in broadwell_init_clock_gating()
229 * to disable EUTC clock gating.
231 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
232 DOP_CLOCK_GATING_DISABLE);
234 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
235 GEN8_SAMPLER_POWER_BYPASS_DIS);
237 WA_SET_BIT_MASKED(HDC_CHICKEN0,
238 /* WaForceContextSaveRestoreNonCoherent:bdw */
239 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
240 /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */
241 (IS_BDW_GT3(i915) ? HDC_FENCE_DEST_SLM_DISABLE : 0));
244 static void chv_ctx_workarounds_init(struct intel_engine_cs *engine)
246 struct i915_wa_list *wal = &engine->ctx_wa_list;
248 gen8_ctx_workarounds_init(engine);
250 /* WaDisableThreadStallDopClockGating:chv */
251 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE);
253 /* Improve HiZ throughput on CHV. */
254 WA_SET_BIT_MASKED(HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X);
257 static void gen9_ctx_workarounds_init(struct intel_engine_cs *engine)
259 struct drm_i915_private *i915 = engine->i915;
260 struct i915_wa_list *wal = &engine->ctx_wa_list;
263 /* WaCompressedResourceSamplerPbeMediaNewHashMode:skl,kbl
265 * Must match Display Engine. See
266 * WaCompressedResourceDisplayNewHashMode.
268 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
269 GEN9_PBE_COMPRESSED_HASH_SELECTION);
270 WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7,
271 GEN9_SAMPLER_HASH_COMPRESSED_READ_ADDR);
274 /* WaClearFlowControlGpgpuContextSave:skl,bxt,kbl,glk,cfl */
275 /* WaDisablePartialInstShootdown:skl,bxt,kbl,glk,cfl */
276 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
277 FLOW_CONTROL_ENABLE |
278 PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE);
280 /* Syncing dependencies between camera and graphics:skl,bxt,kbl */
281 if (!IS_COFFEELAKE(i915))
282 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
283 GEN9_DISABLE_OCL_OOB_SUPPRESS_LOGIC);
285 /* WaEnableYV12BugFixInHalfSliceChicken7:skl,bxt,kbl,glk,cfl */
286 /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt,kbl,cfl */
287 WA_SET_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN7,
288 GEN9_ENABLE_YV12_BUGFIX |
289 GEN9_ENABLE_GPGPU_PREEMPTION);
291 /* Wa4x4STCOptimizationDisable:skl,bxt,kbl,glk,cfl */
292 /* WaDisablePartialResolveInVc:skl,bxt,kbl,cfl */
293 WA_SET_BIT_MASKED(CACHE_MODE_1,
294 GEN8_4x4_STC_OPTIMIZATION_DISABLE |
295 GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE);
297 /* WaCcsTlbPrefetchDisable:skl,bxt,kbl,glk,cfl */
298 WA_CLR_BIT_MASKED(GEN9_HALF_SLICE_CHICKEN5,
299 GEN9_CCS_TLB_PREFETCH_ENABLE);
301 /* WaForceContextSaveRestoreNonCoherent:skl,bxt,kbl,cfl */
302 WA_SET_BIT_MASKED(HDC_CHICKEN0,
303 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT |
304 HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE);
306 /* WaForceEnableNonCoherent and WaDisableHDCInvalidation are
307 * both tied to WaForceContextSaveRestoreNonCoherent
308 * in some hsds for skl. We keep the tie for all gen9. The
309 * documentation is a bit hazy and so we want to get common behaviour,
310 * even though there is no clear evidence we would need both on kbl/bxt.
311 * This area has been source of system hangs so we play it safe
312 * and mimic the skl regardless of what bspec says.
314 * Use Force Non-Coherent whenever executing a 3D context. This
315 * is a workaround for a possible hang in the unlikely event
316 * a TLB invalidation occurs during a PSD flush.
319 /* WaForceEnableNonCoherent:skl,bxt,kbl,cfl */
320 WA_SET_BIT_MASKED(HDC_CHICKEN0,
321 HDC_FORCE_NON_COHERENT);
323 /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt,kbl,cfl */
324 if (IS_SKYLAKE(i915) || IS_KABYLAKE(i915) || IS_COFFEELAKE(i915))
325 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3,
326 GEN8_SAMPLER_POWER_BYPASS_DIS);
328 /* WaDisableSTUnitPowerOptimization:skl,bxt,kbl,glk,cfl */
329 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE);
332 * Supporting preemption with fine-granularity requires changes in the
333 * batch buffer programming. Since we can't break old userspace, we
334 * need to set our default preemption level to safe value. Userspace is
335 * still able to use more fine-grained preemption levels, since in
336 * WaEnablePreemptionGranularityControlByUMD we're whitelisting the
337 * per-ctx register. As such, WaDisable{3D,GPGPU}MidCmdPreemption are
338 * not real HW workarounds, but merely a way to start using preemption
339 * while maintaining old contract with userspace.
342 /* WaDisable3DMidCmdPreemption:skl,bxt,glk,cfl,[cnl] */
343 WA_CLR_BIT_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL);
345 /* WaDisableGPGPUMidCmdPreemption:skl,bxt,blk,cfl,[cnl] */
346 WA_SET_FIELD_MASKED(GEN8_CS_CHICKEN1,
347 GEN9_PREEMPT_GPGPU_LEVEL_MASK,
348 GEN9_PREEMPT_GPGPU_COMMAND_LEVEL);
350 /* WaClearHIZ_WM_CHICKEN3:bxt,glk */
351 if (IS_GEN9_LP(i915))
352 WA_SET_BIT_MASKED(GEN9_WM_CHICKEN3, GEN9_FACTOR_IN_CLR_VAL_HIZ);
355 static void skl_tune_iz_hashing(struct intel_engine_cs *engine)
357 struct drm_i915_private *i915 = engine->i915;
358 struct i915_wa_list *wal = &engine->ctx_wa_list;
359 u8 vals[3] = { 0, 0, 0 };
362 for (i = 0; i < 3; i++) {
366 * Only consider slices where one, and only one, subslice has 7
369 if (!is_power_of_2(INTEL_INFO(i915)->sseu.subslice_7eu[i]))
373 * subslice_7eu[i] != 0 (because of the check above) and
374 * ss_max == 4 (maximum number of subslices possible per slice)
378 ss = ffs(INTEL_INFO(i915)->sseu.subslice_7eu[i]) - 1;
382 if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0)
385 /* Tune IZ hashing. See intel_device_info_runtime_init() */
386 WA_SET_FIELD_MASKED(GEN7_GT_MODE,
387 GEN9_IZ_HASHING_MASK(2) |
388 GEN9_IZ_HASHING_MASK(1) |
389 GEN9_IZ_HASHING_MASK(0),
390 GEN9_IZ_HASHING(2, vals[2]) |
391 GEN9_IZ_HASHING(1, vals[1]) |
392 GEN9_IZ_HASHING(0, vals[0]));
395 static void skl_ctx_workarounds_init(struct intel_engine_cs *engine)
397 gen9_ctx_workarounds_init(engine);
398 skl_tune_iz_hashing(engine);
401 static void bxt_ctx_workarounds_init(struct intel_engine_cs *engine)
403 struct i915_wa_list *wal = &engine->ctx_wa_list;
405 gen9_ctx_workarounds_init(engine);
407 /* WaDisableThreadStallDopClockGating:bxt */
408 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN,
409 STALL_DOP_GATING_DISABLE);
411 /* WaToEnableHwFixForPushConstHWBug:bxt */
412 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
413 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
416 static void kbl_ctx_workarounds_init(struct intel_engine_cs *engine)
418 struct drm_i915_private *i915 = engine->i915;
419 struct i915_wa_list *wal = &engine->ctx_wa_list;
421 gen9_ctx_workarounds_init(engine);
423 /* WaToEnableHwFixForPushConstHWBug:kbl */
424 if (IS_KBL_REVID(i915, KBL_REVID_C0, REVID_FOREVER))
425 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
426 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
428 /* WaDisableSbeCacheDispatchPortSharing:kbl */
429 WA_SET_BIT_MASKED(GEN7_HALF_SLICE_CHICKEN1,
430 GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
433 static void glk_ctx_workarounds_init(struct intel_engine_cs *engine)
435 struct i915_wa_list *wal = &engine->ctx_wa_list;
437 gen9_ctx_workarounds_init(engine);
439 /* WaToEnableHwFixForPushConstHWBug:glk */
440 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
441 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
444 static void cfl_ctx_workarounds_init(struct intel_engine_cs *engine)
446 struct i915_wa_list *wal = &engine->ctx_wa_list;
448 gen9_ctx_workarounds_init(engine);
450 /* WaToEnableHwFixForPushConstHWBug:cfl */
451 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
452 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
454 /* WaDisableSbeCacheDispatchPortSharing:cfl */
455 WA_SET_BIT_MASKED(GEN7_HALF_SLICE_CHICKEN1,
456 GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE);
459 static void cnl_ctx_workarounds_init(struct intel_engine_cs *engine)
461 struct drm_i915_private *i915 = engine->i915;
462 struct i915_wa_list *wal = &engine->ctx_wa_list;
464 /* WaForceContextSaveRestoreNonCoherent:cnl */
465 WA_SET_BIT_MASKED(CNL_HDC_CHICKEN0,
466 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT);
468 /* WaThrottleEUPerfToAvoidTDBackPressure:cnl(pre-prod) */
469 if (IS_CNL_REVID(i915, CNL_REVID_B0, CNL_REVID_B0))
470 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, THROTTLE_12_5);
472 /* WaDisableReplayBufferBankArbitrationOptimization:cnl */
473 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
474 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION);
476 /* WaDisableEnhancedSBEVertexCaching:cnl (pre-prod) */
477 if (IS_CNL_REVID(i915, 0, CNL_REVID_B0))
478 WA_SET_BIT_MASKED(COMMON_SLICE_CHICKEN2,
479 GEN8_CSC2_SBE_VUE_CACHE_CONSERVATIVE);
481 /* WaPushConstantDereferenceHoldDisable:cnl */
482 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2, PUSH_CONSTANT_DEREF_DISABLE);
484 /* FtrEnableFastAnisoL1BankingFix:cnl */
485 WA_SET_BIT_MASKED(HALF_SLICE_CHICKEN3, CNL_FAST_ANISO_L1_BANKING_FIX);
487 /* WaDisable3DMidCmdPreemption:cnl */
488 WA_CLR_BIT_MASKED(GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL);
490 /* WaDisableGPGPUMidCmdPreemption:cnl */
491 WA_SET_FIELD_MASKED(GEN8_CS_CHICKEN1,
492 GEN9_PREEMPT_GPGPU_LEVEL_MASK,
493 GEN9_PREEMPT_GPGPU_COMMAND_LEVEL);
495 /* WaDisableEarlyEOT:cnl */
496 WA_SET_BIT_MASKED(GEN8_ROW_CHICKEN, DISABLE_EARLY_EOT);
499 static void icl_ctx_workarounds_init(struct intel_engine_cs *engine)
501 struct drm_i915_private *i915 = engine->i915;
502 struct i915_wa_list *wal = &engine->ctx_wa_list;
504 /* Wa_1604370585:icl (pre-prod)
505 * Formerly known as WaPushConstantDereferenceHoldDisable
507 if (IS_ICL_REVID(i915, ICL_REVID_A0, ICL_REVID_B0))
508 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
509 PUSH_CONSTANT_DEREF_DISABLE);
511 /* WaForceEnableNonCoherent:icl
512 * This is not the same workaround as in early Gen9 platforms, where
513 * lacking this could cause system hangs, but coherency performance
514 * overhead is high and only a few compute workloads really need it
515 * (the register is whitelisted in hardware now, so UMDs can opt in
516 * for coherency if they have a good reason).
518 WA_SET_BIT_MASKED(ICL_HDC_MODE, HDC_FORCE_NON_COHERENT);
520 /* Wa_2006611047:icl (pre-prod)
521 * Formerly known as WaDisableImprovedTdlClkGating
523 if (IS_ICL_REVID(i915, ICL_REVID_A0, ICL_REVID_A0))
524 WA_SET_BIT_MASKED(GEN7_ROW_CHICKEN2,
525 GEN11_TDL_CLOCK_GATING_FIX_DISABLE);
527 /* WaEnableStateCacheRedirectToCS:icl */
528 WA_SET_BIT_MASKED(GEN9_SLICE_COMMON_ECO_CHICKEN1,
529 GEN11_STATE_CACHE_REDIRECT_TO_CS);
531 /* Wa_2006665173:icl (pre-prod) */
532 if (IS_ICL_REVID(i915, ICL_REVID_A0, ICL_REVID_A0))
533 WA_SET_BIT_MASKED(GEN11_COMMON_SLICE_CHICKEN3,
534 GEN11_BLEND_EMB_FIX_DISABLE_IN_RCC);
537 void intel_engine_init_ctx_wa(struct intel_engine_cs *engine)
539 struct drm_i915_private *i915 = engine->i915;
540 struct i915_wa_list *wal = &engine->ctx_wa_list;
542 wa_init_start(wal, "context");
544 if (INTEL_GEN(i915) < 8)
546 else if (IS_BROADWELL(i915))
547 bdw_ctx_workarounds_init(engine);
548 else if (IS_CHERRYVIEW(i915))
549 chv_ctx_workarounds_init(engine);
550 else if (IS_SKYLAKE(i915))
551 skl_ctx_workarounds_init(engine);
552 else if (IS_BROXTON(i915))
553 bxt_ctx_workarounds_init(engine);
554 else if (IS_KABYLAKE(i915))
555 kbl_ctx_workarounds_init(engine);
556 else if (IS_GEMINILAKE(i915))
557 glk_ctx_workarounds_init(engine);
558 else if (IS_COFFEELAKE(i915))
559 cfl_ctx_workarounds_init(engine);
560 else if (IS_CANNONLAKE(i915))
561 cnl_ctx_workarounds_init(engine);
562 else if (IS_ICELAKE(i915))
563 icl_ctx_workarounds_init(engine);
565 MISSING_CASE(INTEL_GEN(i915));
570 int intel_engine_emit_ctx_wa(struct i915_request *rq)
572 struct i915_wa_list *wal = &rq->engine->ctx_wa_list;
581 ret = rq->engine->emit_flush(rq, EMIT_BARRIER);
585 cs = intel_ring_begin(rq, (wal->count * 2 + 2));
589 *cs++ = MI_LOAD_REGISTER_IMM(wal->count);
590 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) {
591 *cs++ = i915_mmio_reg_offset(wa->reg);
596 intel_ring_advance(rq, cs);
598 ret = rq->engine->emit_flush(rq, EMIT_BARRIER);
606 wa_masked_en(struct i915_wa_list *wal, i915_reg_t reg, u32 val)
608 struct i915_wa wa = {
611 .val = _MASKED_BIT_ENABLE(val)
618 wa_write_masked_or(struct i915_wa_list *wal, i915_reg_t reg, u32 mask,
621 struct i915_wa wa = {
631 wa_write(struct i915_wa_list *wal, i915_reg_t reg, u32 val)
633 wa_write_masked_or(wal, reg, ~0, val);
637 wa_write_or(struct i915_wa_list *wal, i915_reg_t reg, u32 val)
639 wa_write_masked_or(wal, reg, val, val);
642 static void gen9_gt_workarounds_init(struct drm_i915_private *i915)
644 struct i915_wa_list *wal = &i915->gt_wa_list;
646 /* WaDisableKillLogic:bxt,skl,kbl */
647 if (!IS_COFFEELAKE(i915))
653 /* WaCompressedResourceSamplerPbeMediaNewHashMode:skl,kbl
655 * Must match Display Engine. See
656 * WaCompressedResourceDisplayNewHashMode.
660 MMCD_PCLA | MMCD_HOTSPOT_EN);
663 /* WaDisableHDCInvalidation:skl,bxt,kbl,cfl */
666 BDW_DISABLE_HDC_INVALIDATION);
669 static void skl_gt_workarounds_init(struct drm_i915_private *i915)
671 struct i915_wa_list *wal = &i915->gt_wa_list;
673 gen9_gt_workarounds_init(i915);
675 /* WaDisableGafsUnitClkGating:skl */
678 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
680 /* WaInPlaceDecompressionHang:skl */
681 if (IS_SKL_REVID(i915, SKL_REVID_H0, REVID_FOREVER))
683 GEN9_GAMT_ECO_REG_RW_IA,
684 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
687 static void bxt_gt_workarounds_init(struct drm_i915_private *i915)
689 struct i915_wa_list *wal = &i915->gt_wa_list;
691 gen9_gt_workarounds_init(i915);
693 /* WaInPlaceDecompressionHang:bxt */
695 GEN9_GAMT_ECO_REG_RW_IA,
696 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
699 static void kbl_gt_workarounds_init(struct drm_i915_private *i915)
701 struct i915_wa_list *wal = &i915->gt_wa_list;
703 gen9_gt_workarounds_init(i915);
705 /* WaDisableDynamicCreditSharing:kbl */
706 if (IS_KBL_REVID(i915, 0, KBL_REVID_B0))
709 GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING);
711 /* WaDisableGafsUnitClkGating:kbl */
714 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
716 /* WaInPlaceDecompressionHang:kbl */
718 GEN9_GAMT_ECO_REG_RW_IA,
719 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
722 static void glk_gt_workarounds_init(struct drm_i915_private *i915)
724 gen9_gt_workarounds_init(i915);
727 static void cfl_gt_workarounds_init(struct drm_i915_private *i915)
729 struct i915_wa_list *wal = &i915->gt_wa_list;
731 gen9_gt_workarounds_init(i915);
733 /* WaDisableGafsUnitClkGating:cfl */
736 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE);
738 /* WaInPlaceDecompressionHang:cfl */
740 GEN9_GAMT_ECO_REG_RW_IA,
741 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
744 static void wa_init_mcr(struct drm_i915_private *dev_priv)
746 const struct sseu_dev_info *sseu = &(INTEL_INFO(dev_priv)->sseu);
747 struct i915_wa_list *wal = &dev_priv->gt_wa_list;
748 u32 mcr_slice_subslice_mask;
751 * WaProgramMgsrForL3BankSpecificMmioReads: cnl,icl
752 * L3Banks could be fused off in single slice scenario. If that is
753 * the case, we might need to program MCR select to a valid L3Bank
754 * by default, to make sure we correctly read certain registers
755 * later on (in the range 0xB100 - 0xB3FF).
756 * This might be incompatible with
757 * WaProgramMgsrForCorrectSliceSpecificMmioReads.
758 * Fortunately, this should not happen in production hardware, so
759 * we only assert that this is the case (instead of implementing
760 * something more complex that requires checking the range of every
763 if (INTEL_GEN(dev_priv) >= 10 &&
764 is_power_of_2(sseu->slice_mask)) {
766 * read FUSE3 for enabled L3 Bank IDs, if L3 Bank matches
767 * enabled subslice, no need to redirect MCR packet
769 u32 slice = fls(sseu->slice_mask);
770 u32 fuse3 = I915_READ(GEN10_MIRROR_FUSE3);
771 u8 ss_mask = sseu->subslice_mask[slice];
773 u8 enabled_mask = (ss_mask | ss_mask >>
774 GEN10_L3BANK_PAIR_COUNT) & GEN10_L3BANK_MASK;
775 u8 disabled_mask = fuse3 & GEN10_L3BANK_MASK;
778 * Production silicon should have matched L3Bank and
781 WARN_ON((enabled_mask & disabled_mask) != enabled_mask);
784 if (INTEL_GEN(dev_priv) >= 11)
785 mcr_slice_subslice_mask = GEN11_MCR_SLICE_MASK |
786 GEN11_MCR_SUBSLICE_MASK;
788 mcr_slice_subslice_mask = GEN8_MCR_SLICE_MASK |
789 GEN8_MCR_SUBSLICE_MASK;
791 * WaProgramMgsrForCorrectSliceSpecificMmioReads:cnl,icl
792 * Before any MMIO read into slice/subslice specific registers, MCR
793 * packet control register needs to be programmed to point to any
794 * enabled s/ss pair. Otherwise, incorrect values will be returned.
795 * This means each subsequent MMIO read will be forwarded to an
796 * specific s/ss combination, but this is OK since these registers
797 * are consistent across s/ss in almost all cases. In the rare
798 * occasions, such as INSTDONE, where this value is dependent
799 * on s/ss combo, the read should be done with read_subslice_reg.
801 wa_write_masked_or(wal,
803 mcr_slice_subslice_mask,
804 intel_calculate_mcr_s_ss_select(dev_priv));
807 static void cnl_gt_workarounds_init(struct drm_i915_private *i915)
809 struct i915_wa_list *wal = &i915->gt_wa_list;
813 /* WaDisableI2mCycleOnWRPort:cnl (pre-prod) */
814 if (IS_CNL_REVID(i915, CNL_REVID_B0, CNL_REVID_B0))
817 GAMT_CHKN_DISABLE_I2M_CYCLE_ON_WR_PORT);
819 /* WaInPlaceDecompressionHang:cnl */
821 GEN9_GAMT_ECO_REG_RW_IA,
822 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
825 static void icl_gt_workarounds_init(struct drm_i915_private *i915)
827 struct i915_wa_list *wal = &i915->gt_wa_list;
831 /* WaInPlaceDecompressionHang:icl */
833 GEN9_GAMT_ECO_REG_RW_IA,
834 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS);
836 /* WaModifyGamTlbPartitioning:icl */
837 wa_write_masked_or(wal,
838 GEN11_GACB_PERF_CTRL,
839 GEN11_HASH_CTRL_MASK,
840 GEN11_HASH_CTRL_BIT0 | GEN11_HASH_CTRL_BIT4);
843 * Formerly known as WaCL2SFHalfMaxAlloc
847 GEN11_LSN_UNSLCVC_GAFS_HALF_SF_MAXALLOC |
848 GEN11_LSN_UNSLCVC_GAFS_HALF_CL2_MAXALLOC);
851 * Formerly known as WaDisCtxReload
854 GEN8_GAMW_ECO_DEV_RW_IA,
855 GAMW_ECO_DEV_CTX_RELOAD_DISABLE);
857 /* Wa_1405779004:icl (pre-prod) */
858 if (IS_ICL_REVID(i915, ICL_REVID_A0, ICL_REVID_A0))
860 SLICE_UNIT_LEVEL_CLKGATE,
861 MSCUNIT_CLKGATE_DIS);
863 /* Wa_1406680159:icl */
865 SUBSLICE_UNIT_LEVEL_CLKGATE,
868 /* Wa_1406838659:icl (pre-prod) */
869 if (IS_ICL_REVID(i915, ICL_REVID_A0, ICL_REVID_B0))
871 INF_UNIT_LEVEL_CLKGATE,
875 * Formerly known as WaGamTlbPendError
879 GAMT_CHKN_DISABLE_L3_COH_PIPE);
882 void intel_gt_init_workarounds(struct drm_i915_private *i915)
884 struct i915_wa_list *wal = &i915->gt_wa_list;
886 wa_init_start(wal, "GT");
888 if (INTEL_GEN(i915) < 8)
890 else if (IS_BROADWELL(i915))
892 else if (IS_CHERRYVIEW(i915))
894 else if (IS_SKYLAKE(i915))
895 skl_gt_workarounds_init(i915);
896 else if (IS_BROXTON(i915))
897 bxt_gt_workarounds_init(i915);
898 else if (IS_KABYLAKE(i915))
899 kbl_gt_workarounds_init(i915);
900 else if (IS_GEMINILAKE(i915))
901 glk_gt_workarounds_init(i915);
902 else if (IS_COFFEELAKE(i915))
903 cfl_gt_workarounds_init(i915);
904 else if (IS_CANNONLAKE(i915))
905 cnl_gt_workarounds_init(i915);
906 else if (IS_ICELAKE(i915))
907 icl_gt_workarounds_init(i915);
909 MISSING_CASE(INTEL_GEN(i915));
914 static enum forcewake_domains
915 wal_get_fw_for_rmw(struct drm_i915_private *dev_priv,
916 const struct i915_wa_list *wal)
918 enum forcewake_domains fw = 0;
922 for (i = 0, wa = wal->list; i < wal->count; i++, wa++)
923 fw |= intel_uncore_forcewake_for_reg(dev_priv,
932 wa_list_apply(struct drm_i915_private *dev_priv, const struct i915_wa_list *wal)
934 enum forcewake_domains fw;
942 fw = wal_get_fw_for_rmw(dev_priv, wal);
944 spin_lock_irqsave(&dev_priv->uncore.lock, flags);
945 intel_uncore_forcewake_get__locked(dev_priv, fw);
947 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) {
948 u32 val = I915_READ_FW(wa->reg);
953 I915_WRITE_FW(wa->reg, val);
956 intel_uncore_forcewake_put__locked(dev_priv, fw);
957 spin_unlock_irqrestore(&dev_priv->uncore.lock, flags);
959 DRM_DEBUG_DRIVER("Applied %u %s workarounds\n", wal->count, wal->name);
962 void intel_gt_apply_workarounds(struct drm_i915_private *dev_priv)
964 wa_list_apply(dev_priv, &dev_priv->gt_wa_list);
968 wa_verify(const struct i915_wa *wa, u32 cur, const char *name, const char *from)
970 if ((cur ^ wa->val) & wa->mask) {
971 DRM_ERROR("%s workaround lost on %s! (%x=%x/%x, expected %x, mask=%x)\n",
972 name, from, i915_mmio_reg_offset(wa->reg), cur,
973 cur & wa->mask, wa->val, wa->mask);
981 static bool wa_list_verify(struct drm_i915_private *dev_priv,
982 const struct i915_wa_list *wal,
989 for (i = 0, wa = wal->list; i < wal->count; i++, wa++)
990 ok &= wa_verify(wa, I915_READ(wa->reg), wal->name, from);
995 bool intel_gt_verify_workarounds(struct drm_i915_private *dev_priv,
998 return wa_list_verify(dev_priv, &dev_priv->gt_wa_list, from);
1002 whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg)
1004 struct i915_wa wa = {
1008 if (GEM_DEBUG_WARN_ON(wal->count >= RING_MAX_NONPRIV_SLOTS))
1014 static void gen9_whitelist_build(struct i915_wa_list *w)
1016 /* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */
1017 whitelist_reg(w, GEN9_CTX_PREEMPT_REG);
1019 /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl,cfl,[cnl] */
1020 whitelist_reg(w, GEN8_CS_CHICKEN1);
1022 /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */
1023 whitelist_reg(w, GEN8_HDC_CHICKEN1);
1026 static void skl_whitelist_build(struct i915_wa_list *w)
1028 gen9_whitelist_build(w);
1030 /* WaDisableLSQCROPERFforOCL:skl */
1031 whitelist_reg(w, GEN8_L3SQCREG4);
1034 static void bxt_whitelist_build(struct i915_wa_list *w)
1036 gen9_whitelist_build(w);
1039 static void kbl_whitelist_build(struct i915_wa_list *w)
1041 gen9_whitelist_build(w);
1043 /* WaDisableLSQCROPERFforOCL:kbl */
1044 whitelist_reg(w, GEN8_L3SQCREG4);
1047 static void glk_whitelist_build(struct i915_wa_list *w)
1049 gen9_whitelist_build(w);
1051 /* WA #0862: Userspace has to set "Barrier Mode" to avoid hangs. */
1052 whitelist_reg(w, GEN9_SLICE_COMMON_ECO_CHICKEN1);
1055 static void cfl_whitelist_build(struct i915_wa_list *w)
1057 gen9_whitelist_build(w);
1060 static void cnl_whitelist_build(struct i915_wa_list *w)
1062 /* WaEnablePreemptionGranularityControlByUMD:cnl */
1063 whitelist_reg(w, GEN8_CS_CHICKEN1);
1066 static void icl_whitelist_build(struct i915_wa_list *w)
1068 /* WaAllowUMDToModifyHalfSliceChicken7:icl */
1069 whitelist_reg(w, GEN9_HALF_SLICE_CHICKEN7);
1071 /* WaAllowUMDToModifySamplerMode:icl */
1072 whitelist_reg(w, GEN10_SAMPLER_MODE);
1075 void intel_engine_init_whitelist(struct intel_engine_cs *engine)
1077 struct drm_i915_private *i915 = engine->i915;
1078 struct i915_wa_list *w = &engine->whitelist;
1080 GEM_BUG_ON(engine->id != RCS);
1082 wa_init_start(w, "whitelist");
1084 if (INTEL_GEN(i915) < 8)
1086 else if (IS_BROADWELL(i915))
1088 else if (IS_CHERRYVIEW(i915))
1090 else if (IS_SKYLAKE(i915))
1091 skl_whitelist_build(w);
1092 else if (IS_BROXTON(i915))
1093 bxt_whitelist_build(w);
1094 else if (IS_KABYLAKE(i915))
1095 kbl_whitelist_build(w);
1096 else if (IS_GEMINILAKE(i915))
1097 glk_whitelist_build(w);
1098 else if (IS_COFFEELAKE(i915))
1099 cfl_whitelist_build(w);
1100 else if (IS_CANNONLAKE(i915))
1101 cnl_whitelist_build(w);
1102 else if (IS_ICELAKE(i915))
1103 icl_whitelist_build(w);
1105 MISSING_CASE(INTEL_GEN(i915));
1110 void intel_engine_apply_whitelist(struct intel_engine_cs *engine)
1112 struct drm_i915_private *dev_priv = engine->i915;
1113 const struct i915_wa_list *wal = &engine->whitelist;
1114 const u32 base = engine->mmio_base;
1121 for (i = 0, wa = wal->list; i < wal->count; i++, wa++)
1122 I915_WRITE(RING_FORCE_TO_NONPRIV(base, i),
1123 i915_mmio_reg_offset(wa->reg));
1125 /* And clear the rest just in case of garbage */
1126 for (; i < RING_MAX_NONPRIV_SLOTS; i++)
1127 I915_WRITE(RING_FORCE_TO_NONPRIV(base, i),
1128 i915_mmio_reg_offset(RING_NOPID(base)));
1130 DRM_DEBUG_DRIVER("Applied %u %s workarounds\n", wal->count, wal->name);
1133 static void rcs_engine_wa_init(struct intel_engine_cs *engine)
1135 struct drm_i915_private *i915 = engine->i915;
1136 struct i915_wa_list *wal = &engine->wa_list;
1138 if (IS_ICELAKE(i915)) {
1139 /* This is not an Wa. Enable for better image quality */
1142 _3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE);
1144 /* WaPipelineFlushCoherentLines:icl */
1147 GEN8_LQSC_FLUSH_COHERENT_LINES);
1151 * Formerly known as WaGAPZPriorityScheme
1155 GEN11_ARBITRATION_PRIO_ORDER_MASK);
1159 * Formerly known as WaL3BankAddressHashing
1161 wa_write_masked_or(wal,
1163 GEN11_HASH_CTRL_EXCL_MASK,
1164 GEN11_HASH_CTRL_EXCL_BIT0);
1165 wa_write_masked_or(wal,
1167 GEN11_BANK_HASH_ADDR_EXCL_MASK,
1168 GEN11_BANK_HASH_ADDR_EXCL_BIT0);
1172 * Formerly known as WaDisableCleanEvicts
1176 GEN11_LQSC_CLEAN_EVICT_DISABLE);
1178 /* WaForwardProgressSoftReset:icl */
1180 GEN10_SCRATCH_LNCF2,
1181 PMFLUSHDONE_LNICRSDROP |
1182 PMFLUSH_GAPL3UNBLOCK |
1183 PMFLUSHDONE_LNEBLK);
1185 /* Wa_1406609255:icl (pre-prod) */
1186 if (IS_ICL_REVID(i915, ICL_REVID_A0, ICL_REVID_B0))
1189 GEN7_DISABLE_DEMAND_PREFETCH |
1190 GEN7_DISABLE_SAMPLER_PREFETCH);
1193 if (IS_GEN9(i915) || IS_CANNONLAKE(i915)) {
1194 /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl,cfl,cnl */
1196 GEN7_FF_SLICE_CS_CHICKEN1,
1197 GEN9_FFSC_PERCTX_PREEMPT_CTRL);
1200 if (IS_SKYLAKE(i915) || IS_KABYLAKE(i915) || IS_COFFEELAKE(i915)) {
1201 /* WaEnableGapsTsvCreditFix:skl,kbl,cfl */
1204 GEN9_GAPS_TSV_CREDIT_DISABLE);
1207 if (IS_BROXTON(i915)) {
1208 /* WaDisablePooledEuLoadBalancingFix:bxt */
1210 FF_SLICE_CS_CHICKEN2,
1211 GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE);
1214 if (IS_GEN9(i915)) {
1215 /* WaContextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk,cfl */
1217 GEN9_CSFE_CHICKEN1_RCS,
1218 GEN9_PREEMPT_GPGPU_SYNC_SWITCH_DISABLE);
1220 /* WaEnableLbsSlaRetryTimerDecrement:skl,bxt,kbl,glk,cfl */
1223 GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE);
1225 /* WaProgramL3SqcReg1DefaultForPerf:bxt,glk */
1226 if (IS_GEN9_LP(i915))
1227 wa_write_masked_or(wal,
1229 L3_PRIO_CREDITS_MASK,
1230 L3_GENERAL_PRIO_CREDITS(62) |
1231 L3_HIGH_PRIO_CREDITS(2));
1233 /* WaOCLCoherentLineFlush:skl,bxt,kbl,cfl */
1236 GEN8_LQSC_FLUSH_COHERENT_LINES);
1240 static void xcs_engine_wa_init(struct intel_engine_cs *engine)
1242 struct drm_i915_private *i915 = engine->i915;
1243 struct i915_wa_list *wal = &engine->wa_list;
1245 /* WaKBLVECSSemaphoreWaitPoll:kbl */
1246 if (IS_KBL_REVID(i915, KBL_REVID_A0, KBL_REVID_E0)) {
1248 RING_SEMA_WAIT_POLL(engine->mmio_base),
1253 void intel_engine_init_workarounds(struct intel_engine_cs *engine)
1255 struct i915_wa_list *wal = &engine->wa_list;
1257 if (GEM_WARN_ON(INTEL_GEN(engine->i915) < 8))
1260 wa_init_start(wal, engine->name);
1262 if (engine->id == RCS)
1263 rcs_engine_wa_init(engine);
1265 xcs_engine_wa_init(engine);
1267 wa_init_finish(wal);
1270 void intel_engine_apply_workarounds(struct intel_engine_cs *engine)
1272 wa_list_apply(engine->i915, &engine->wa_list);
1275 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
1276 static bool intel_engine_verify_workarounds(struct intel_engine_cs *engine,
1279 return wa_list_verify(engine->i915, &engine->wa_list, from);
1282 #include "selftests/intel_workarounds.c"