1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2014-2018 Intel Corporation 4 */ 5 6 #include "i915_drv.h" 7 #include "i915_reg.h" 8 #include "intel_context.h" 9 #include "intel_engine_pm.h" 10 #include "intel_engine_regs.h" 11 #include "intel_gpu_commands.h" 12 #include "intel_gt.h" 13 #include "intel_gt_ccs_mode.h" 14 #include "intel_gt_mcr.h" 15 #include "intel_gt_print.h" 16 #include "intel_gt_regs.h" 17 #include "intel_ring.h" 18 #include "intel_workarounds.h" 19 20 #include "display/intel_fbc_regs.h" 21 22 /** 23 * DOC: Hardware workarounds 24 * 25 * Hardware workarounds are register programming documented to be executed in 26 * the driver that fall outside of the normal programming sequences for a 27 * platform. There are some basic categories of workarounds, depending on 28 * how/when they are applied: 29 * 30 * - Context workarounds: workarounds that touch registers that are 31 * saved/restored to/from the HW context image. The list is emitted (via Load 32 * Register Immediate commands) once when initializing the device and saved in 33 * the default context. That default context is then used on every context 34 * creation to have a "primed golden context", i.e. a context image that 35 * already contains the changes needed to all the registers. 36 * 37 * Context workarounds should be implemented in the \*_ctx_workarounds_init() 38 * variants respective to the targeted platforms. 39 * 40 * - Engine workarounds: the list of these WAs is applied whenever the specific 41 * engine is reset. It's also possible that a set of engine classes share a 42 * common power domain and they are reset together. This happens on some 43 * platforms with render and compute engines. In this case (at least) one of 44 * them need to keeep the workaround programming: the approach taken in the 45 * driver is to tie those workarounds to the first compute/render engine that 46 * is registered. When executing with GuC submission, engine resets are 47 * outside of kernel driver control, hence the list of registers involved in 48 * written once, on engine initialization, and then passed to GuC, that 49 * saves/restores their values before/after the reset takes place. See 50 * ``drivers/gpu/drm/i915/gt/uc/intel_guc_ads.c`` for reference. 51 * 52 * Workarounds for registers specific to RCS and CCS should be implemented in 53 * rcs_engine_wa_init() and ccs_engine_wa_init(), respectively; those for 54 * registers belonging to BCS, VCS or VECS should be implemented in 55 * xcs_engine_wa_init(). Workarounds for registers not belonging to a specific 56 * engine's MMIO range but that are part of of the common RCS/CCS reset domain 57 * should be implemented in general_render_compute_wa_init(). The settings 58 * about the CCS load balancing should be added in ccs_engine_wa_mode(). 59 * 60 * - GT workarounds: the list of these WAs is applied whenever these registers 61 * revert to their default values: on GPU reset, suspend/resume [1]_, etc. 62 * 63 * GT workarounds should be implemented in the \*_gt_workarounds_init() 64 * variants respective to the targeted platforms. 65 * 66 * - Register whitelist: some workarounds need to be implemented in userspace, 67 * but need to touch privileged registers. The whitelist in the kernel 68 * instructs the hardware to allow the access to happen. From the kernel side, 69 * this is just a special case of a MMIO workaround (as we write the list of 70 * these to/be-whitelisted registers to some special HW registers). 71 * 72 * Register whitelisting should be done in the \*_whitelist_build() variants 73 * respective to the targeted platforms. 74 * 75 * - Workaround batchbuffers: buffers that get executed automatically by the 76 * hardware on every HW context restore. These buffers are created and 77 * programmed in the default context so the hardware always go through those 78 * programming sequences when switching contexts. The support for workaround 79 * batchbuffers is enabled these hardware mechanisms: 80 * 81 * #. INDIRECT_CTX: A batchbuffer and an offset are provided in the default 82 * context, pointing the hardware to jump to that location when that offset 83 * is reached in the context restore. Workaround batchbuffer in the driver 84 * currently uses this mechanism for all platforms. 85 * 86 * #. BB_PER_CTX_PTR: A batchbuffer is provided in the default context, 87 * pointing the hardware to a buffer to continue executing after the 88 * engine registers are restored in a context restore sequence. This is 89 * currently not used in the driver. 90 * 91 * - Other: There are WAs that, due to their nature, cannot be applied from a 92 * central place. Those are peppered around the rest of the code, as needed. 93 * Workarounds related to the display IP are the main example. 94 * 95 * .. [1] Technically, some registers are powercontext saved & restored, so they 96 * survive a suspend/resume. In practice, writing them again is not too 97 * costly and simplifies things, so it's the approach taken in the driver. 98 */ 99 100 static void wa_init_start(struct i915_wa_list *wal, struct intel_gt *gt, 101 const char *name, const char *engine_name) 102 { 103 wal->gt = gt; 104 wal->name = name; 105 wal->engine_name = engine_name; 106 } 107 108 #define WA_LIST_CHUNK (1 << 4) 109 110 static void wa_init_finish(struct i915_wa_list *wal) 111 { 112 /* Trim unused entries. */ 113 if (!IS_ALIGNED(wal->count, WA_LIST_CHUNK)) { 114 struct i915_wa *list = kmemdup(wal->list, 115 wal->count * sizeof(*list), 116 GFP_KERNEL); 117 118 if (list) { 119 kfree(wal->list); 120 wal->list = list; 121 } 122 } 123 124 if (!wal->count) 125 return; 126 127 gt_dbg(wal->gt, "Initialized %u %s workarounds on %s\n", 128 wal->wa_count, wal->name, wal->engine_name); 129 } 130 131 static enum forcewake_domains 132 wal_get_fw_for_rmw(struct intel_uncore *uncore, const struct i915_wa_list *wal) 133 { 134 enum forcewake_domains fw = 0; 135 struct i915_wa *wa; 136 unsigned int i; 137 138 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) 139 fw |= intel_uncore_forcewake_for_reg(uncore, 140 wa->reg, 141 FW_REG_READ | 142 FW_REG_WRITE); 143 144 return fw; 145 } 146 147 static void _wa_add(struct i915_wa_list *wal, const struct i915_wa *wa) 148 { 149 unsigned int addr = i915_mmio_reg_offset(wa->reg); 150 struct drm_i915_private *i915 = wal->gt->i915; 151 unsigned int start = 0, end = wal->count; 152 const unsigned int grow = WA_LIST_CHUNK; 153 struct i915_wa *wa_; 154 155 GEM_BUG_ON(!is_power_of_2(grow)); 156 157 if (IS_ALIGNED(wal->count, grow)) { /* Either uninitialized or full. */ 158 struct i915_wa *list; 159 160 list = kmalloc_array(ALIGN(wal->count + 1, grow), sizeof(*wa), 161 GFP_KERNEL); 162 if (!list) { 163 drm_err(&i915->drm, "No space for workaround init!\n"); 164 return; 165 } 166 167 if (wal->list) { 168 memcpy(list, wal->list, sizeof(*wa) * wal->count); 169 kfree(wal->list); 170 } 171 172 wal->list = list; 173 } 174 175 while (start < end) { 176 unsigned int mid = start + (end - start) / 2; 177 178 if (i915_mmio_reg_offset(wal->list[mid].reg) < addr) { 179 start = mid + 1; 180 } else if (i915_mmio_reg_offset(wal->list[mid].reg) > addr) { 181 end = mid; 182 } else { 183 wa_ = &wal->list[mid]; 184 185 if ((wa->clr | wa_->clr) && !(wa->clr & ~wa_->clr)) { 186 drm_err(&i915->drm, 187 "Discarding overwritten w/a for reg %04x (clear: %08x, set: %08x)\n", 188 i915_mmio_reg_offset(wa_->reg), 189 wa_->clr, wa_->set); 190 191 wa_->set &= ~wa->clr; 192 } 193 194 wal->wa_count++; 195 wa_->set |= wa->set; 196 wa_->clr |= wa->clr; 197 wa_->read |= wa->read; 198 return; 199 } 200 } 201 202 wal->wa_count++; 203 wa_ = &wal->list[wal->count++]; 204 *wa_ = *wa; 205 206 while (wa_-- > wal->list) { 207 GEM_BUG_ON(i915_mmio_reg_offset(wa_[0].reg) == 208 i915_mmio_reg_offset(wa_[1].reg)); 209 if (i915_mmio_reg_offset(wa_[1].reg) > 210 i915_mmio_reg_offset(wa_[0].reg)) 211 break; 212 213 swap(wa_[1], wa_[0]); 214 } 215 } 216 217 static void wa_add(struct i915_wa_list *wal, i915_reg_t reg, 218 u32 clear, u32 set, u32 read_mask, bool masked_reg) 219 { 220 struct i915_wa wa = { 221 .reg = reg, 222 .clr = clear, 223 .set = set, 224 .read = read_mask, 225 .masked_reg = masked_reg, 226 }; 227 228 _wa_add(wal, &wa); 229 } 230 231 static void wa_mcr_add(struct i915_wa_list *wal, i915_mcr_reg_t reg, 232 u32 clear, u32 set, u32 read_mask, bool masked_reg) 233 { 234 struct i915_wa wa = { 235 .mcr_reg = reg, 236 .clr = clear, 237 .set = set, 238 .read = read_mask, 239 .masked_reg = masked_reg, 240 .is_mcr = 1, 241 }; 242 243 _wa_add(wal, &wa); 244 } 245 246 static void 247 wa_write_clr_set(struct i915_wa_list *wal, i915_reg_t reg, u32 clear, u32 set) 248 { 249 wa_add(wal, reg, clear, set, clear | set, false); 250 } 251 252 static void 253 wa_mcr_write_clr_set(struct i915_wa_list *wal, i915_mcr_reg_t reg, u32 clear, u32 set) 254 { 255 wa_mcr_add(wal, reg, clear, set, clear | set, false); 256 } 257 258 static void 259 wa_write(struct i915_wa_list *wal, i915_reg_t reg, u32 set) 260 { 261 wa_write_clr_set(wal, reg, ~0, set); 262 } 263 264 static void 265 wa_write_or(struct i915_wa_list *wal, i915_reg_t reg, u32 set) 266 { 267 wa_write_clr_set(wal, reg, set, set); 268 } 269 270 static void 271 wa_mcr_write_or(struct i915_wa_list *wal, i915_mcr_reg_t reg, u32 set) 272 { 273 wa_mcr_write_clr_set(wal, reg, set, set); 274 } 275 276 static void 277 wa_write_clr(struct i915_wa_list *wal, i915_reg_t reg, u32 clr) 278 { 279 wa_write_clr_set(wal, reg, clr, 0); 280 } 281 282 static void 283 wa_mcr_write_clr(struct i915_wa_list *wal, i915_mcr_reg_t reg, u32 clr) 284 { 285 wa_mcr_write_clr_set(wal, reg, clr, 0); 286 } 287 288 /* 289 * WA operations on "masked register". A masked register has the upper 16 bits 290 * documented as "masked" in b-spec. Its purpose is to allow writing to just a 291 * portion of the register without a rmw: you simply write in the upper 16 bits 292 * the mask of bits you are going to modify. 293 * 294 * The wa_masked_* family of functions already does the necessary operations to 295 * calculate the mask based on the parameters passed, so user only has to 296 * provide the lower 16 bits of that register. 297 */ 298 299 static void 300 wa_masked_en(struct i915_wa_list *wal, i915_reg_t reg, u32 val) 301 { 302 wa_add(wal, reg, 0, _MASKED_BIT_ENABLE(val), val, true); 303 } 304 305 static void 306 wa_mcr_masked_en(struct i915_wa_list *wal, i915_mcr_reg_t reg, u32 val) 307 { 308 wa_mcr_add(wal, reg, 0, _MASKED_BIT_ENABLE(val), val, true); 309 } 310 311 static void 312 wa_masked_dis(struct i915_wa_list *wal, i915_reg_t reg, u32 val) 313 { 314 wa_add(wal, reg, 0, _MASKED_BIT_DISABLE(val), val, true); 315 } 316 317 static void 318 wa_mcr_masked_dis(struct i915_wa_list *wal, i915_mcr_reg_t reg, u32 val) 319 { 320 wa_mcr_add(wal, reg, 0, _MASKED_BIT_DISABLE(val), val, true); 321 } 322 323 static void 324 wa_masked_field_set(struct i915_wa_list *wal, i915_reg_t reg, 325 u32 mask, u32 val) 326 { 327 wa_add(wal, reg, 0, _MASKED_FIELD(mask, val), mask, true); 328 } 329 330 static void 331 wa_mcr_masked_field_set(struct i915_wa_list *wal, i915_mcr_reg_t reg, 332 u32 mask, u32 val) 333 { 334 wa_mcr_add(wal, reg, 0, _MASKED_FIELD(mask, val), mask, true); 335 } 336 337 static void gen6_ctx_workarounds_init(struct intel_engine_cs *engine, 338 struct i915_wa_list *wal) 339 { 340 wa_masked_en(wal, INSTPM, INSTPM_FORCE_ORDERING); 341 } 342 343 static void gen7_ctx_workarounds_init(struct intel_engine_cs *engine, 344 struct i915_wa_list *wal) 345 { 346 wa_masked_en(wal, INSTPM, INSTPM_FORCE_ORDERING); 347 } 348 349 static void gen8_ctx_workarounds_init(struct intel_engine_cs *engine, 350 struct i915_wa_list *wal) 351 { 352 wa_masked_en(wal, INSTPM, INSTPM_FORCE_ORDERING); 353 354 /* WaDisableAsyncFlipPerfMode:bdw,chv */ 355 wa_masked_en(wal, RING_MI_MODE(RENDER_RING_BASE), ASYNC_FLIP_PERF_DISABLE); 356 357 /* WaDisablePartialInstShootdown:bdw,chv */ 358 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN, 359 PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE); 360 361 /* Use Force Non-Coherent whenever executing a 3D context. This is a 362 * workaround for a possible hang in the unlikely event a TLB 363 * invalidation occurs during a PSD flush. 364 */ 365 /* WaForceEnableNonCoherent:bdw,chv */ 366 /* WaHdcDisableFetchWhenMasked:bdw,chv */ 367 wa_masked_en(wal, HDC_CHICKEN0, 368 HDC_DONOT_FETCH_MEM_WHEN_MASKED | 369 HDC_FORCE_NON_COHERENT); 370 371 /* From the Haswell PRM, Command Reference: Registers, CACHE_MODE_0: 372 * "The Hierarchical Z RAW Stall Optimization allows non-overlapping 373 * polygons in the same 8x4 pixel/sample area to be processed without 374 * stalling waiting for the earlier ones to write to Hierarchical Z 375 * buffer." 376 * 377 * This optimization is off by default for BDW and CHV; turn it on. 378 */ 379 wa_masked_dis(wal, CACHE_MODE_0_GEN7, HIZ_RAW_STALL_OPT_DISABLE); 380 381 /* Wa4x4STCOptimizationDisable:bdw,chv */ 382 wa_masked_en(wal, CACHE_MODE_1, GEN8_4x4_STC_OPTIMIZATION_DISABLE); 383 384 /* 385 * BSpec recommends 8x4 when MSAA is used, 386 * however in practice 16x4 seems fastest. 387 * 388 * Note that PS/WM thread counts depend on the WIZ hashing 389 * disable bit, which we don't touch here, but it's good 390 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). 391 */ 392 wa_masked_field_set(wal, GEN7_GT_MODE, 393 GEN6_WIZ_HASHING_MASK, 394 GEN6_WIZ_HASHING_16x4); 395 } 396 397 static void bdw_ctx_workarounds_init(struct intel_engine_cs *engine, 398 struct i915_wa_list *wal) 399 { 400 struct drm_i915_private *i915 = engine->i915; 401 402 gen8_ctx_workarounds_init(engine, wal); 403 404 /* WaDisableThreadStallDopClockGating:bdw (pre-production) */ 405 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE); 406 407 /* WaDisableDopClockGating:bdw 408 * 409 * Also see the related UCGTCL1 write in bdw_init_clock_gating() 410 * to disable EUTC clock gating. 411 */ 412 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN2, 413 DOP_CLOCK_GATING_DISABLE); 414 415 wa_mcr_masked_en(wal, GEN8_HALF_SLICE_CHICKEN3, 416 GEN8_SAMPLER_POWER_BYPASS_DIS); 417 418 wa_masked_en(wal, HDC_CHICKEN0, 419 /* WaForceContextSaveRestoreNonCoherent:bdw */ 420 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT | 421 /* WaDisableFenceDestinationToSLM:bdw (pre-prod) */ 422 (IS_BROADWELL_GT3(i915) ? HDC_FENCE_DEST_SLM_DISABLE : 0)); 423 } 424 425 static void chv_ctx_workarounds_init(struct intel_engine_cs *engine, 426 struct i915_wa_list *wal) 427 { 428 gen8_ctx_workarounds_init(engine, wal); 429 430 /* WaDisableThreadStallDopClockGating:chv */ 431 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN, STALL_DOP_GATING_DISABLE); 432 433 /* Improve HiZ throughput on CHV. */ 434 wa_masked_en(wal, HIZ_CHICKEN, CHV_HZ_8X8_MODE_IN_1X); 435 } 436 437 static void gen9_ctx_workarounds_init(struct intel_engine_cs *engine, 438 struct i915_wa_list *wal) 439 { 440 struct drm_i915_private *i915 = engine->i915; 441 442 if (HAS_LLC(i915)) { 443 /* WaCompressedResourceSamplerPbeMediaNewHashMode:skl,kbl 444 * 445 * Must match Display Engine. See 446 * WaCompressedResourceDisplayNewHashMode. 447 */ 448 wa_masked_en(wal, COMMON_SLICE_CHICKEN2, 449 GEN9_PBE_COMPRESSED_HASH_SELECTION); 450 wa_mcr_masked_en(wal, GEN9_HALF_SLICE_CHICKEN7, 451 GEN9_SAMPLER_HASH_COMPRESSED_READ_ADDR); 452 } 453 454 /* WaClearFlowControlGpgpuContextSave:skl,bxt,kbl,glk,cfl */ 455 /* WaDisablePartialInstShootdown:skl,bxt,kbl,glk,cfl */ 456 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN, 457 FLOW_CONTROL_ENABLE | 458 PARTIAL_INSTRUCTION_SHOOTDOWN_DISABLE); 459 460 /* WaEnableYV12BugFixInHalfSliceChicken7:skl,bxt,kbl,glk,cfl */ 461 /* WaEnableSamplerGPGPUPreemptionSupport:skl,bxt,kbl,cfl */ 462 wa_mcr_masked_en(wal, GEN9_HALF_SLICE_CHICKEN7, 463 GEN9_ENABLE_YV12_BUGFIX | 464 GEN9_ENABLE_GPGPU_PREEMPTION); 465 466 /* Wa4x4STCOptimizationDisable:skl,bxt,kbl,glk,cfl */ 467 /* WaDisablePartialResolveInVc:skl,bxt,kbl,cfl */ 468 wa_masked_en(wal, CACHE_MODE_1, 469 GEN8_4x4_STC_OPTIMIZATION_DISABLE | 470 GEN9_PARTIAL_RESOLVE_IN_VC_DISABLE); 471 472 /* WaCcsTlbPrefetchDisable:skl,bxt,kbl,glk,cfl */ 473 wa_mcr_masked_dis(wal, GEN9_HALF_SLICE_CHICKEN5, 474 GEN9_CCS_TLB_PREFETCH_ENABLE); 475 476 /* WaForceContextSaveRestoreNonCoherent:skl,bxt,kbl,cfl */ 477 wa_masked_en(wal, HDC_CHICKEN0, 478 HDC_FORCE_CONTEXT_SAVE_RESTORE_NON_COHERENT | 479 HDC_FORCE_CSR_NON_COHERENT_OVR_DISABLE); 480 481 /* WaForceEnableNonCoherent and WaDisableHDCInvalidation are 482 * both tied to WaForceContextSaveRestoreNonCoherent 483 * in some hsds for skl. We keep the tie for all gen9. The 484 * documentation is a bit hazy and so we want to get common behaviour, 485 * even though there is no clear evidence we would need both on kbl/bxt. 486 * This area has been source of system hangs so we play it safe 487 * and mimic the skl regardless of what bspec says. 488 * 489 * Use Force Non-Coherent whenever executing a 3D context. This 490 * is a workaround for a possible hang in the unlikely event 491 * a TLB invalidation occurs during a PSD flush. 492 */ 493 494 /* WaForceEnableNonCoherent:skl,bxt,kbl,cfl */ 495 wa_masked_en(wal, HDC_CHICKEN0, 496 HDC_FORCE_NON_COHERENT); 497 498 /* WaDisableSamplerPowerBypassForSOPingPong:skl,bxt,kbl,cfl */ 499 if (IS_SKYLAKE(i915) || 500 IS_KABYLAKE(i915) || 501 IS_COFFEELAKE(i915) || 502 IS_COMETLAKE(i915)) 503 wa_mcr_masked_en(wal, GEN8_HALF_SLICE_CHICKEN3, 504 GEN8_SAMPLER_POWER_BYPASS_DIS); 505 506 /* WaDisableSTUnitPowerOptimization:skl,bxt,kbl,glk,cfl */ 507 wa_mcr_masked_en(wal, HALF_SLICE_CHICKEN2, GEN8_ST_PO_DISABLE); 508 509 /* 510 * Supporting preemption with fine-granularity requires changes in the 511 * batch buffer programming. Since we can't break old userspace, we 512 * need to set our default preemption level to safe value. Userspace is 513 * still able to use more fine-grained preemption levels, since in 514 * WaEnablePreemptionGranularityControlByUMD we're whitelisting the 515 * per-ctx register. As such, WaDisable{3D,GPGPU}MidCmdPreemption are 516 * not real HW workarounds, but merely a way to start using preemption 517 * while maintaining old contract with userspace. 518 */ 519 520 /* WaDisable3DMidCmdPreemption:skl,bxt,glk,cfl,[cnl] */ 521 wa_masked_dis(wal, GEN8_CS_CHICKEN1, GEN9_PREEMPT_3D_OBJECT_LEVEL); 522 523 /* WaDisableGPGPUMidCmdPreemption:skl,bxt,blk,cfl,[cnl] */ 524 wa_masked_field_set(wal, GEN8_CS_CHICKEN1, 525 GEN9_PREEMPT_GPGPU_LEVEL_MASK, 526 GEN9_PREEMPT_GPGPU_COMMAND_LEVEL); 527 528 /* WaClearHIZ_WM_CHICKEN3:bxt,glk */ 529 if (IS_GEN9_LP(i915)) 530 wa_masked_en(wal, GEN9_WM_CHICKEN3, GEN9_FACTOR_IN_CLR_VAL_HIZ); 531 } 532 533 static void skl_tune_iz_hashing(struct intel_engine_cs *engine, 534 struct i915_wa_list *wal) 535 { 536 struct intel_gt *gt = engine->gt; 537 u8 vals[3] = { 0, 0, 0 }; 538 unsigned int i; 539 540 for (i = 0; i < 3; i++) { 541 u8 ss; 542 543 /* 544 * Only consider slices where one, and only one, subslice has 7 545 * EUs 546 */ 547 if (!is_power_of_2(gt->info.sseu.subslice_7eu[i])) 548 continue; 549 550 /* 551 * subslice_7eu[i] != 0 (because of the check above) and 552 * ss_max == 4 (maximum number of subslices possible per slice) 553 * 554 * -> 0 <= ss <= 3; 555 */ 556 ss = ffs(gt->info.sseu.subslice_7eu[i]) - 1; 557 vals[i] = 3 - ss; 558 } 559 560 if (vals[0] == 0 && vals[1] == 0 && vals[2] == 0) 561 return; 562 563 /* Tune IZ hashing. See intel_device_info_runtime_init() */ 564 wa_masked_field_set(wal, GEN7_GT_MODE, 565 GEN9_IZ_HASHING_MASK(2) | 566 GEN9_IZ_HASHING_MASK(1) | 567 GEN9_IZ_HASHING_MASK(0), 568 GEN9_IZ_HASHING(2, vals[2]) | 569 GEN9_IZ_HASHING(1, vals[1]) | 570 GEN9_IZ_HASHING(0, vals[0])); 571 } 572 573 static void skl_ctx_workarounds_init(struct intel_engine_cs *engine, 574 struct i915_wa_list *wal) 575 { 576 gen9_ctx_workarounds_init(engine, wal); 577 skl_tune_iz_hashing(engine, wal); 578 } 579 580 static void bxt_ctx_workarounds_init(struct intel_engine_cs *engine, 581 struct i915_wa_list *wal) 582 { 583 gen9_ctx_workarounds_init(engine, wal); 584 585 /* WaDisableThreadStallDopClockGating:bxt */ 586 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN, 587 STALL_DOP_GATING_DISABLE); 588 589 /* WaToEnableHwFixForPushConstHWBug:bxt */ 590 wa_masked_en(wal, COMMON_SLICE_CHICKEN2, 591 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); 592 } 593 594 static void kbl_ctx_workarounds_init(struct intel_engine_cs *engine, 595 struct i915_wa_list *wal) 596 { 597 struct drm_i915_private *i915 = engine->i915; 598 599 gen9_ctx_workarounds_init(engine, wal); 600 601 /* WaToEnableHwFixForPushConstHWBug:kbl */ 602 if (IS_KABYLAKE(i915) && IS_GRAPHICS_STEP(i915, STEP_C0, STEP_FOREVER)) 603 wa_masked_en(wal, COMMON_SLICE_CHICKEN2, 604 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); 605 606 /* WaDisableSbeCacheDispatchPortSharing:kbl */ 607 wa_mcr_masked_en(wal, GEN8_HALF_SLICE_CHICKEN1, 608 GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); 609 } 610 611 static void glk_ctx_workarounds_init(struct intel_engine_cs *engine, 612 struct i915_wa_list *wal) 613 { 614 gen9_ctx_workarounds_init(engine, wal); 615 616 /* WaToEnableHwFixForPushConstHWBug:glk */ 617 wa_masked_en(wal, COMMON_SLICE_CHICKEN2, 618 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); 619 } 620 621 static void cfl_ctx_workarounds_init(struct intel_engine_cs *engine, 622 struct i915_wa_list *wal) 623 { 624 gen9_ctx_workarounds_init(engine, wal); 625 626 /* WaToEnableHwFixForPushConstHWBug:cfl */ 627 wa_masked_en(wal, COMMON_SLICE_CHICKEN2, 628 GEN8_SBE_DISABLE_REPLAY_BUF_OPTIMIZATION); 629 630 /* WaDisableSbeCacheDispatchPortSharing:cfl */ 631 wa_mcr_masked_en(wal, GEN8_HALF_SLICE_CHICKEN1, 632 GEN7_SBE_SS_CACHE_DISPATCH_PORT_SHARING_DISABLE); 633 } 634 635 static void icl_ctx_workarounds_init(struct intel_engine_cs *engine, 636 struct i915_wa_list *wal) 637 { 638 /* Wa_1406697149 (WaDisableBankHangMode:icl) */ 639 wa_write(wal, GEN8_L3CNTLREG, GEN8_ERRDETBCTRL); 640 641 /* WaForceEnableNonCoherent:icl 642 * This is not the same workaround as in early Gen9 platforms, where 643 * lacking this could cause system hangs, but coherency performance 644 * overhead is high and only a few compute workloads really need it 645 * (the register is whitelisted in hardware now, so UMDs can opt in 646 * for coherency if they have a good reason). 647 */ 648 wa_mcr_masked_en(wal, ICL_HDC_MODE, HDC_FORCE_NON_COHERENT); 649 650 /* WaEnableFloatBlendOptimization:icl */ 651 wa_mcr_add(wal, GEN10_CACHE_MODE_SS, 0, 652 _MASKED_BIT_ENABLE(FLOAT_BLEND_OPTIMIZATION_ENABLE), 653 0 /* write-only, so skip validation */, 654 true); 655 656 /* WaDisableGPGPUMidThreadPreemption:icl */ 657 wa_masked_field_set(wal, GEN8_CS_CHICKEN1, 658 GEN9_PREEMPT_GPGPU_LEVEL_MASK, 659 GEN9_PREEMPT_GPGPU_THREAD_GROUP_LEVEL); 660 661 /* allow headerless messages for preemptible GPGPU context */ 662 wa_mcr_masked_en(wal, GEN10_SAMPLER_MODE, 663 GEN11_SAMPLER_ENABLE_HEADLESS_MSG); 664 665 /* Wa_1604278689:icl,ehl */ 666 wa_write(wal, IVB_FBC_RT_BASE, 0xFFFFFFFF & ~ILK_FBC_RT_VALID); 667 wa_write_clr_set(wal, IVB_FBC_RT_BASE_UPPER, 668 0, 669 0xFFFFFFFF); 670 671 /* Wa_1406306137:icl,ehl */ 672 wa_mcr_masked_en(wal, GEN9_ROW_CHICKEN4, GEN11_DIS_PICK_2ND_EU); 673 } 674 675 /* 676 * These settings aren't actually workarounds, but general tuning settings that 677 * need to be programmed on dg2 platform. 678 */ 679 static void dg2_ctx_gt_tuning_init(struct intel_engine_cs *engine, 680 struct i915_wa_list *wal) 681 { 682 wa_mcr_masked_en(wal, CHICKEN_RASTER_2, TBIMR_FAST_CLIP); 683 wa_mcr_write_clr_set(wal, XEHP_L3SQCREG5, L3_PWM_TIMER_INIT_VAL_MASK, 684 REG_FIELD_PREP(L3_PWM_TIMER_INIT_VAL_MASK, 0x7f)); 685 wa_mcr_write_clr_set(wal, XEHP_FF_MODE2, FF_MODE2_TDS_TIMER_MASK, 686 FF_MODE2_TDS_TIMER_128); 687 } 688 689 static void gen12_ctx_workarounds_init(struct intel_engine_cs *engine, 690 struct i915_wa_list *wal) 691 { 692 struct drm_i915_private *i915 = engine->i915; 693 694 /* 695 * Wa_1409142259:tgl,dg1,adl-p 696 * Wa_1409347922:tgl,dg1,adl-p 697 * Wa_1409252684:tgl,dg1,adl-p 698 * Wa_1409217633:tgl,dg1,adl-p 699 * Wa_1409207793:tgl,dg1,adl-p 700 * Wa_1409178076:tgl,dg1,adl-p 701 * Wa_1408979724:tgl,dg1,adl-p 702 * Wa_14010443199:tgl,rkl,dg1,adl-p 703 * Wa_14010698770:tgl,rkl,dg1,adl-s,adl-p 704 * Wa_1409342910:tgl,rkl,dg1,adl-s,adl-p 705 */ 706 wa_masked_en(wal, GEN11_COMMON_SLICE_CHICKEN3, 707 GEN12_DISABLE_CPS_AWARE_COLOR_PIPE); 708 709 /* WaDisableGPGPUMidThreadPreemption:gen12 */ 710 wa_masked_field_set(wal, GEN8_CS_CHICKEN1, 711 GEN9_PREEMPT_GPGPU_LEVEL_MASK, 712 GEN9_PREEMPT_GPGPU_THREAD_GROUP_LEVEL); 713 714 /* 715 * Wa_16011163337 - GS_TIMER 716 * 717 * TDS_TIMER: Although some platforms refer to it as Wa_1604555607, we 718 * need to program it even on those that don't explicitly list that 719 * workaround. 720 * 721 * Note that the programming of GEN12_FF_MODE2 is further modified 722 * according to the FF_MODE2 guidance given by Wa_1608008084. 723 * Wa_1608008084 tells us the FF_MODE2 register will return the wrong 724 * value when read from the CPU. 725 * 726 * The default value for this register is zero for all fields. 727 * So instead of doing a RMW we should just write the desired values 728 * for TDS and GS timers. Note that since the readback can't be trusted, 729 * the clear mask is just set to ~0 to make sure other bits are not 730 * inadvertently set. For the same reason read verification is ignored. 731 */ 732 wa_add(wal, 733 GEN12_FF_MODE2, 734 ~0, 735 FF_MODE2_TDS_TIMER_128 | FF_MODE2_GS_TIMER_224, 736 0, false); 737 738 if (!IS_DG1(i915)) { 739 /* Wa_1806527549 */ 740 wa_masked_en(wal, HIZ_CHICKEN, HZ_DEPTH_TEST_LE_GE_OPT_DISABLE); 741 742 /* Wa_1606376872 */ 743 wa_masked_en(wal, COMMON_SLICE_CHICKEN4, DISABLE_TDC_LOAD_BALANCING_CALC); 744 } 745 } 746 747 static void dg1_ctx_workarounds_init(struct intel_engine_cs *engine, 748 struct i915_wa_list *wal) 749 { 750 gen12_ctx_workarounds_init(engine, wal); 751 752 /* Wa_1409044764 */ 753 wa_masked_dis(wal, GEN11_COMMON_SLICE_CHICKEN3, 754 DG1_FLOAT_POINT_BLEND_OPT_STRICT_MODE_EN); 755 756 /* Wa_22010493298 */ 757 wa_masked_en(wal, HIZ_CHICKEN, 758 DG1_HZ_READ_SUPPRESSION_OPTIMIZATION_DISABLE); 759 } 760 761 static void dg2_ctx_workarounds_init(struct intel_engine_cs *engine, 762 struct i915_wa_list *wal) 763 { 764 dg2_ctx_gt_tuning_init(engine, wal); 765 766 /* Wa_16013271637:dg2 */ 767 wa_mcr_masked_en(wal, XEHP_SLICE_COMMON_ECO_CHICKEN1, 768 MSC_MSAA_REODER_BUF_BYPASS_DISABLE); 769 770 /* Wa_14014947963:dg2 */ 771 wa_masked_field_set(wal, VF_PREEMPTION, PREEMPTION_VERTEX_COUNT, 0x4000); 772 773 /* Wa_18018764978:dg2 */ 774 wa_mcr_masked_en(wal, XEHP_PSS_MODE2, SCOREBOARD_STALL_FLUSH_CONTROL); 775 776 /* Wa_18019271663:dg2 */ 777 wa_masked_en(wal, CACHE_MODE_1, MSAA_OPTIMIZATION_REDUC_DISABLE); 778 779 /* Wa_14019877138:dg2 */ 780 wa_mcr_masked_en(wal, XEHP_PSS_CHICKEN, FD_END_COLLECT); 781 } 782 783 static void xelpg_ctx_gt_tuning_init(struct intel_engine_cs *engine, 784 struct i915_wa_list *wal) 785 { 786 struct intel_gt *gt = engine->gt; 787 788 dg2_ctx_gt_tuning_init(engine, wal); 789 790 /* 791 * Due to Wa_16014892111, the DRAW_WATERMARK tuning must be done in 792 * gen12_emit_indirect_ctx_rcs() rather than here on some early 793 * steppings. 794 */ 795 if (!(IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 796 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0))) 797 wa_add(wal, DRAW_WATERMARK, VERT_WM_VAL, 0x3FF, 0, false); 798 } 799 800 static void xelpg_ctx_workarounds_init(struct intel_engine_cs *engine, 801 struct i915_wa_list *wal) 802 { 803 struct intel_gt *gt = engine->gt; 804 805 xelpg_ctx_gt_tuning_init(engine, wal); 806 807 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 808 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0)) { 809 /* Wa_14014947963 */ 810 wa_masked_field_set(wal, VF_PREEMPTION, 811 PREEMPTION_VERTEX_COUNT, 0x4000); 812 813 /* Wa_16013271637 */ 814 wa_mcr_masked_en(wal, XEHP_SLICE_COMMON_ECO_CHICKEN1, 815 MSC_MSAA_REODER_BUF_BYPASS_DISABLE); 816 817 /* Wa_18019627453 */ 818 wa_mcr_masked_en(wal, VFLSKPD, VF_PREFETCH_TLB_DIS); 819 820 /* Wa_18018764978 */ 821 wa_mcr_masked_en(wal, XEHP_PSS_MODE2, SCOREBOARD_STALL_FLUSH_CONTROL); 822 } 823 824 /* Wa_18019271663 */ 825 wa_masked_en(wal, CACHE_MODE_1, MSAA_OPTIMIZATION_REDUC_DISABLE); 826 827 /* Wa_14019877138 */ 828 wa_mcr_masked_en(wal, XEHP_PSS_CHICKEN, FD_END_COLLECT); 829 } 830 831 static void fakewa_disable_nestedbb_mode(struct intel_engine_cs *engine, 832 struct i915_wa_list *wal) 833 { 834 /* 835 * This is a "fake" workaround defined by software to ensure we 836 * maintain reliable, backward-compatible behavior for userspace with 837 * regards to how nested MI_BATCH_BUFFER_START commands are handled. 838 * 839 * The per-context setting of MI_MODE[12] determines whether the bits 840 * of a nested MI_BATCH_BUFFER_START instruction should be interpreted 841 * in the traditional manner or whether they should instead use a new 842 * tgl+ meaning that breaks backward compatibility, but allows nesting 843 * into 3rd-level batchbuffers. When this new capability was first 844 * added in TGL, it remained off by default unless a context 845 * intentionally opted in to the new behavior. However Xe_HPG now 846 * flips this on by default and requires that we explicitly opt out if 847 * we don't want the new behavior. 848 * 849 * From a SW perspective, we want to maintain the backward-compatible 850 * behavior for userspace, so we'll apply a fake workaround to set it 851 * back to the legacy behavior on platforms where the hardware default 852 * is to break compatibility. At the moment there is no Linux 853 * userspace that utilizes third-level batchbuffers, so this will avoid 854 * userspace from needing to make any changes. using the legacy 855 * meaning is the correct thing to do. If/when we have userspace 856 * consumers that want to utilize third-level batch nesting, we can 857 * provide a context parameter to allow them to opt-in. 858 */ 859 wa_masked_dis(wal, RING_MI_MODE(engine->mmio_base), TGL_NESTED_BB_EN); 860 } 861 862 static void gen12_ctx_gt_mocs_init(struct intel_engine_cs *engine, 863 struct i915_wa_list *wal) 864 { 865 u8 mocs; 866 867 /* 868 * Some blitter commands do not have a field for MOCS, those 869 * commands will use MOCS index pointed by BLIT_CCTL. 870 * BLIT_CCTL registers are needed to be programmed to un-cached. 871 */ 872 if (engine->class == COPY_ENGINE_CLASS) { 873 mocs = engine->gt->mocs.uc_index; 874 wa_write_clr_set(wal, 875 BLIT_CCTL(engine->mmio_base), 876 BLIT_CCTL_MASK, 877 BLIT_CCTL_MOCS(mocs, mocs)); 878 } 879 } 880 881 /* 882 * gen12_ctx_gt_fake_wa_init() aren't programmingan official workaround 883 * defined by the hardware team, but it programming general context registers. 884 * Adding those context register programming in context workaround 885 * allow us to use the wa framework for proper application and validation. 886 */ 887 static void 888 gen12_ctx_gt_fake_wa_init(struct intel_engine_cs *engine, 889 struct i915_wa_list *wal) 890 { 891 if (GRAPHICS_VER_FULL(engine->i915) >= IP_VER(12, 55)) 892 fakewa_disable_nestedbb_mode(engine, wal); 893 894 gen12_ctx_gt_mocs_init(engine, wal); 895 } 896 897 static void 898 __intel_engine_init_ctx_wa(struct intel_engine_cs *engine, 899 struct i915_wa_list *wal, 900 const char *name) 901 { 902 struct drm_i915_private *i915 = engine->i915; 903 904 wa_init_start(wal, engine->gt, name, engine->name); 905 906 /* Applies to all engines */ 907 /* 908 * Fake workarounds are not the actual workaround but 909 * programming of context registers using workaround framework. 910 */ 911 if (GRAPHICS_VER(i915) >= 12) 912 gen12_ctx_gt_fake_wa_init(engine, wal); 913 914 if (engine->class != RENDER_CLASS) 915 goto done; 916 917 if (IS_GFX_GT_IP_RANGE(engine->gt, IP_VER(12, 70), IP_VER(12, 74))) 918 xelpg_ctx_workarounds_init(engine, wal); 919 else if (IS_DG2(i915)) 920 dg2_ctx_workarounds_init(engine, wal); 921 else if (IS_DG1(i915)) 922 dg1_ctx_workarounds_init(engine, wal); 923 else if (GRAPHICS_VER(i915) == 12) 924 gen12_ctx_workarounds_init(engine, wal); 925 else if (GRAPHICS_VER(i915) == 11) 926 icl_ctx_workarounds_init(engine, wal); 927 else if (IS_COFFEELAKE(i915) || IS_COMETLAKE(i915)) 928 cfl_ctx_workarounds_init(engine, wal); 929 else if (IS_GEMINILAKE(i915)) 930 glk_ctx_workarounds_init(engine, wal); 931 else if (IS_KABYLAKE(i915)) 932 kbl_ctx_workarounds_init(engine, wal); 933 else if (IS_BROXTON(i915)) 934 bxt_ctx_workarounds_init(engine, wal); 935 else if (IS_SKYLAKE(i915)) 936 skl_ctx_workarounds_init(engine, wal); 937 else if (IS_CHERRYVIEW(i915)) 938 chv_ctx_workarounds_init(engine, wal); 939 else if (IS_BROADWELL(i915)) 940 bdw_ctx_workarounds_init(engine, wal); 941 else if (GRAPHICS_VER(i915) == 7) 942 gen7_ctx_workarounds_init(engine, wal); 943 else if (GRAPHICS_VER(i915) == 6) 944 gen6_ctx_workarounds_init(engine, wal); 945 else if (GRAPHICS_VER(i915) < 8) 946 ; 947 else 948 MISSING_CASE(GRAPHICS_VER(i915)); 949 950 done: 951 wa_init_finish(wal); 952 } 953 954 void intel_engine_init_ctx_wa(struct intel_engine_cs *engine) 955 { 956 __intel_engine_init_ctx_wa(engine, &engine->ctx_wa_list, "context"); 957 } 958 959 int intel_engine_emit_ctx_wa(struct i915_request *rq) 960 { 961 struct i915_wa_list *wal = &rq->engine->ctx_wa_list; 962 struct intel_uncore *uncore = rq->engine->uncore; 963 enum forcewake_domains fw; 964 unsigned long flags; 965 struct i915_wa *wa; 966 unsigned int i; 967 u32 *cs; 968 int ret; 969 970 if (wal->count == 0) 971 return 0; 972 973 ret = rq->engine->emit_flush(rq, EMIT_BARRIER); 974 if (ret) 975 return ret; 976 977 if ((IS_GFX_GT_IP_RANGE(rq->engine->gt, IP_VER(12, 70), IP_VER(12, 74)) || 978 IS_DG2(rq->i915)) && rq->engine->class == RENDER_CLASS) 979 cs = intel_ring_begin(rq, (wal->count * 2 + 6)); 980 else 981 cs = intel_ring_begin(rq, (wal->count * 2 + 2)); 982 983 if (IS_ERR(cs)) 984 return PTR_ERR(cs); 985 986 fw = wal_get_fw_for_rmw(uncore, wal); 987 988 intel_gt_mcr_lock(wal->gt, &flags); 989 spin_lock(&uncore->lock); 990 intel_uncore_forcewake_get__locked(uncore, fw); 991 992 *cs++ = MI_LOAD_REGISTER_IMM(wal->count); 993 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) { 994 u32 val; 995 996 /* Skip reading the register if it's not really needed */ 997 if (wa->masked_reg || (wa->clr | wa->set) == U32_MAX) { 998 val = wa->set; 999 } else { 1000 val = wa->is_mcr ? 1001 intel_gt_mcr_read_any_fw(wal->gt, wa->mcr_reg) : 1002 intel_uncore_read_fw(uncore, wa->reg); 1003 val &= ~wa->clr; 1004 val |= wa->set; 1005 } 1006 1007 *cs++ = i915_mmio_reg_offset(wa->reg); 1008 *cs++ = val; 1009 } 1010 *cs++ = MI_NOOP; 1011 1012 /* Wa_14019789679 */ 1013 if ((IS_GFX_GT_IP_RANGE(rq->engine->gt, IP_VER(12, 70), IP_VER(12, 74)) || 1014 IS_DG2(rq->i915)) && rq->engine->class == RENDER_CLASS) { 1015 *cs++ = CMD_3DSTATE_MESH_CONTROL; 1016 *cs++ = 0; 1017 *cs++ = 0; 1018 *cs++ = MI_NOOP; 1019 } 1020 1021 intel_uncore_forcewake_put__locked(uncore, fw); 1022 spin_unlock(&uncore->lock); 1023 intel_gt_mcr_unlock(wal->gt, flags); 1024 1025 intel_ring_advance(rq, cs); 1026 1027 ret = rq->engine->emit_flush(rq, EMIT_BARRIER); 1028 if (ret) 1029 return ret; 1030 1031 return 0; 1032 } 1033 1034 static void 1035 gen4_gt_workarounds_init(struct intel_gt *gt, 1036 struct i915_wa_list *wal) 1037 { 1038 /* WaDisable_RenderCache_OperationalFlush:gen4,ilk */ 1039 wa_masked_dis(wal, CACHE_MODE_0, RC_OP_FLUSH_ENABLE); 1040 } 1041 1042 static void 1043 g4x_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1044 { 1045 gen4_gt_workarounds_init(gt, wal); 1046 1047 /* WaDisableRenderCachePipelinedFlush:g4x,ilk */ 1048 wa_masked_en(wal, CACHE_MODE_0, CM0_PIPELINED_RENDER_FLUSH_DISABLE); 1049 } 1050 1051 static void 1052 ilk_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1053 { 1054 g4x_gt_workarounds_init(gt, wal); 1055 1056 wa_masked_en(wal, _3D_CHICKEN2, _3D_CHICKEN2_WM_READ_PIPELINED); 1057 } 1058 1059 static void 1060 snb_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1061 { 1062 } 1063 1064 static void 1065 ivb_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1066 { 1067 /* Apply the WaDisableRHWOOptimizationForRenderHang:ivb workaround. */ 1068 wa_masked_dis(wal, 1069 GEN7_COMMON_SLICE_CHICKEN1, 1070 GEN7_CSC1_RHWO_OPT_DISABLE_IN_RCC); 1071 1072 /* WaApplyL3ControlAndL3ChickenMode:ivb */ 1073 wa_write(wal, GEN7_L3CNTLREG1, GEN7_WA_FOR_GEN7_L3_CONTROL); 1074 wa_write(wal, GEN7_L3_CHICKEN_MODE_REGISTER, GEN7_WA_L3_CHICKEN_MODE); 1075 1076 /* WaForceL3Serialization:ivb */ 1077 wa_write_clr(wal, GEN7_L3SQCREG4, L3SQ_URB_READ_CAM_MATCH_DISABLE); 1078 } 1079 1080 static void 1081 vlv_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1082 { 1083 /* WaForceL3Serialization:vlv */ 1084 wa_write_clr(wal, GEN7_L3SQCREG4, L3SQ_URB_READ_CAM_MATCH_DISABLE); 1085 1086 /* 1087 * WaIncreaseL3CreditsForVLVB0:vlv 1088 * This is the hardware default actually. 1089 */ 1090 wa_write(wal, GEN7_L3SQCREG1, VLV_B0_WA_L3SQCREG1_VALUE); 1091 } 1092 1093 static void 1094 hsw_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1095 { 1096 /* L3 caching of data atomics doesn't work -- disable it. */ 1097 wa_write(wal, HSW_SCRATCH1, HSW_SCRATCH1_L3_DATA_ATOMICS_DISABLE); 1098 1099 wa_add(wal, 1100 HSW_ROW_CHICKEN3, 0, 1101 _MASKED_BIT_ENABLE(HSW_ROW_CHICKEN3_L3_GLOBAL_ATOMICS_DISABLE), 1102 0 /* XXX does this reg exist? */, true); 1103 1104 /* WaVSRefCountFullforceMissDisable:hsw */ 1105 wa_write_clr(wal, GEN7_FF_THREAD_MODE, GEN7_FF_VS_REF_CNT_FFME); 1106 } 1107 1108 static void 1109 gen9_wa_init_mcr(struct drm_i915_private *i915, struct i915_wa_list *wal) 1110 { 1111 const struct sseu_dev_info *sseu = &to_gt(i915)->info.sseu; 1112 unsigned int slice, subslice; 1113 u32 mcr, mcr_mask; 1114 1115 GEM_BUG_ON(GRAPHICS_VER(i915) != 9); 1116 1117 /* 1118 * WaProgramMgsrForCorrectSliceSpecificMmioReads:gen9,glk,kbl,cml 1119 * Before any MMIO read into slice/subslice specific registers, MCR 1120 * packet control register needs to be programmed to point to any 1121 * enabled s/ss pair. Otherwise, incorrect values will be returned. 1122 * This means each subsequent MMIO read will be forwarded to an 1123 * specific s/ss combination, but this is OK since these registers 1124 * are consistent across s/ss in almost all cases. In the rare 1125 * occasions, such as INSTDONE, where this value is dependent 1126 * on s/ss combo, the read should be done with read_subslice_reg. 1127 */ 1128 slice = ffs(sseu->slice_mask) - 1; 1129 GEM_BUG_ON(slice >= ARRAY_SIZE(sseu->subslice_mask.hsw)); 1130 subslice = ffs(intel_sseu_get_hsw_subslices(sseu, slice)); 1131 GEM_BUG_ON(!subslice); 1132 subslice--; 1133 1134 /* 1135 * We use GEN8_MCR..() macros to calculate the |mcr| value for 1136 * Gen9 to address WaProgramMgsrForCorrectSliceSpecificMmioReads 1137 */ 1138 mcr = GEN8_MCR_SLICE(slice) | GEN8_MCR_SUBSLICE(subslice); 1139 mcr_mask = GEN8_MCR_SLICE_MASK | GEN8_MCR_SUBSLICE_MASK; 1140 1141 drm_dbg(&i915->drm, "MCR slice:%d/subslice:%d = %x\n", slice, subslice, mcr); 1142 1143 wa_write_clr_set(wal, GEN8_MCR_SELECTOR, mcr_mask, mcr); 1144 } 1145 1146 static void 1147 gen9_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1148 { 1149 struct drm_i915_private *i915 = gt->i915; 1150 1151 /* WaProgramMgsrForCorrectSliceSpecificMmioReads:glk,kbl,cml,gen9 */ 1152 gen9_wa_init_mcr(i915, wal); 1153 1154 /* WaDisableKillLogic:bxt,skl,kbl */ 1155 if (!IS_COFFEELAKE(i915) && !IS_COMETLAKE(i915)) 1156 wa_write_or(wal, 1157 GAM_ECOCHK, 1158 ECOCHK_DIS_TLB); 1159 1160 if (HAS_LLC(i915)) { 1161 /* WaCompressedResourceSamplerPbeMediaNewHashMode:skl,kbl 1162 * 1163 * Must match Display Engine. See 1164 * WaCompressedResourceDisplayNewHashMode. 1165 */ 1166 wa_write_or(wal, 1167 MMCD_MISC_CTRL, 1168 MMCD_PCLA | MMCD_HOTSPOT_EN); 1169 } 1170 1171 /* WaDisableHDCInvalidation:skl,bxt,kbl,cfl */ 1172 wa_write_or(wal, 1173 GAM_ECOCHK, 1174 BDW_DISABLE_HDC_INVALIDATION); 1175 } 1176 1177 static void 1178 skl_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1179 { 1180 gen9_gt_workarounds_init(gt, wal); 1181 1182 /* WaDisableGafsUnitClkGating:skl */ 1183 wa_write_or(wal, 1184 GEN7_UCGCTL4, 1185 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE); 1186 1187 /* WaInPlaceDecompressionHang:skl */ 1188 if (IS_SKYLAKE(gt->i915) && IS_GRAPHICS_STEP(gt->i915, STEP_A0, STEP_H0)) 1189 wa_write_or(wal, 1190 GEN9_GAMT_ECO_REG_RW_IA, 1191 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS); 1192 } 1193 1194 static void 1195 kbl_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1196 { 1197 gen9_gt_workarounds_init(gt, wal); 1198 1199 /* WaDisableDynamicCreditSharing:kbl */ 1200 if (IS_KABYLAKE(gt->i915) && IS_GRAPHICS_STEP(gt->i915, 0, STEP_C0)) 1201 wa_write_or(wal, 1202 GAMT_CHKN_BIT_REG, 1203 GAMT_CHKN_DISABLE_DYNAMIC_CREDIT_SHARING); 1204 1205 /* WaDisableGafsUnitClkGating:kbl */ 1206 wa_write_or(wal, 1207 GEN7_UCGCTL4, 1208 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE); 1209 1210 /* WaInPlaceDecompressionHang:kbl */ 1211 wa_write_or(wal, 1212 GEN9_GAMT_ECO_REG_RW_IA, 1213 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS); 1214 } 1215 1216 static void 1217 glk_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1218 { 1219 gen9_gt_workarounds_init(gt, wal); 1220 } 1221 1222 static void 1223 cfl_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1224 { 1225 gen9_gt_workarounds_init(gt, wal); 1226 1227 /* WaDisableGafsUnitClkGating:cfl */ 1228 wa_write_or(wal, 1229 GEN7_UCGCTL4, 1230 GEN8_EU_GAUNIT_CLOCK_GATE_DISABLE); 1231 1232 /* WaInPlaceDecompressionHang:cfl */ 1233 wa_write_or(wal, 1234 GEN9_GAMT_ECO_REG_RW_IA, 1235 GAMT_ECO_ENABLE_IN_PLACE_DECOMPRESS); 1236 } 1237 1238 static void __set_mcr_steering(struct i915_wa_list *wal, 1239 i915_reg_t steering_reg, 1240 unsigned int slice, unsigned int subslice) 1241 { 1242 u32 mcr, mcr_mask; 1243 1244 mcr = GEN11_MCR_SLICE(slice) | GEN11_MCR_SUBSLICE(subslice); 1245 mcr_mask = GEN11_MCR_SLICE_MASK | GEN11_MCR_SUBSLICE_MASK; 1246 1247 wa_write_clr_set(wal, steering_reg, mcr_mask, mcr); 1248 } 1249 1250 static void debug_dump_steering(struct intel_gt *gt) 1251 { 1252 struct drm_printer p = drm_dbg_printer(>->i915->drm, DRM_UT_DRIVER, 1253 "MCR Steering:"); 1254 1255 if (drm_debug_enabled(DRM_UT_DRIVER)) 1256 intel_gt_mcr_report_steering(&p, gt, false); 1257 } 1258 1259 static void __add_mcr_wa(struct intel_gt *gt, struct i915_wa_list *wal, 1260 unsigned int slice, unsigned int subslice) 1261 { 1262 __set_mcr_steering(wal, GEN8_MCR_SELECTOR, slice, subslice); 1263 1264 gt->default_steering.groupid = slice; 1265 gt->default_steering.instanceid = subslice; 1266 1267 debug_dump_steering(gt); 1268 } 1269 1270 static void 1271 icl_wa_init_mcr(struct intel_gt *gt, struct i915_wa_list *wal) 1272 { 1273 const struct sseu_dev_info *sseu = >->info.sseu; 1274 unsigned int subslice; 1275 1276 GEM_BUG_ON(GRAPHICS_VER(gt->i915) < 11); 1277 GEM_BUG_ON(hweight8(sseu->slice_mask) > 1); 1278 1279 /* 1280 * Although a platform may have subslices, we need to always steer 1281 * reads to the lowest instance that isn't fused off. When Render 1282 * Power Gating is enabled, grabbing forcewake will only power up a 1283 * single subslice (the "minconfig") if there isn't a real workload 1284 * that needs to be run; this means that if we steer register reads to 1285 * one of the higher subslices, we run the risk of reading back 0's or 1286 * random garbage. 1287 */ 1288 subslice = __ffs(intel_sseu_get_hsw_subslices(sseu, 0)); 1289 1290 /* 1291 * If the subslice we picked above also steers us to a valid L3 bank, 1292 * then we can just rely on the default steering and won't need to 1293 * worry about explicitly re-steering L3BANK reads later. 1294 */ 1295 if (gt->info.l3bank_mask & BIT(subslice)) 1296 gt->steering_table[L3BANK] = NULL; 1297 1298 __add_mcr_wa(gt, wal, 0, subslice); 1299 } 1300 1301 static void 1302 xehp_init_mcr(struct intel_gt *gt, struct i915_wa_list *wal) 1303 { 1304 const struct sseu_dev_info *sseu = >->info.sseu; 1305 unsigned long slice, subslice = 0, slice_mask = 0; 1306 u32 lncf_mask = 0; 1307 int i; 1308 1309 /* 1310 * On Xe_HP the steering increases in complexity. There are now several 1311 * more units that require steering and we're not guaranteed to be able 1312 * to find a common setting for all of them. These are: 1313 * - GSLICE (fusable) 1314 * - DSS (sub-unit within gslice; fusable) 1315 * - L3 Bank (fusable) 1316 * - MSLICE (fusable) 1317 * - LNCF (sub-unit within mslice; always present if mslice is present) 1318 * 1319 * We'll do our default/implicit steering based on GSLICE (in the 1320 * sliceid field) and DSS (in the subsliceid field). If we can 1321 * find overlap between the valid MSLICE and/or LNCF values with 1322 * a suitable GSLICE, then we can just re-use the default value and 1323 * skip and explicit steering at runtime. 1324 * 1325 * We only need to look for overlap between GSLICE/MSLICE/LNCF to find 1326 * a valid sliceid value. DSS steering is the only type of steering 1327 * that utilizes the 'subsliceid' bits. 1328 * 1329 * Also note that, even though the steering domain is called "GSlice" 1330 * and it is encoded in the register using the gslice format, the spec 1331 * says that the combined (geometry | compute) fuse should be used to 1332 * select the steering. 1333 */ 1334 1335 /* Find the potential gslice candidates */ 1336 slice_mask = intel_slicemask_from_xehp_dssmask(sseu->subslice_mask, 1337 GEN_DSS_PER_GSLICE); 1338 1339 /* 1340 * Find the potential LNCF candidates. Either LNCF within a valid 1341 * mslice is fine. 1342 */ 1343 for_each_set_bit(i, >->info.mslice_mask, GEN12_MAX_MSLICES) 1344 lncf_mask |= (0x3 << (i * 2)); 1345 1346 /* 1347 * Are there any sliceid values that work for both GSLICE and LNCF 1348 * steering? 1349 */ 1350 if (slice_mask & lncf_mask) { 1351 slice_mask &= lncf_mask; 1352 gt->steering_table[LNCF] = NULL; 1353 } 1354 1355 /* How about sliceid values that also work for MSLICE steering? */ 1356 if (slice_mask & gt->info.mslice_mask) { 1357 slice_mask &= gt->info.mslice_mask; 1358 gt->steering_table[MSLICE] = NULL; 1359 } 1360 1361 slice = __ffs(slice_mask); 1362 subslice = intel_sseu_find_first_xehp_dss(sseu, GEN_DSS_PER_GSLICE, slice) % 1363 GEN_DSS_PER_GSLICE; 1364 1365 __add_mcr_wa(gt, wal, slice, subslice); 1366 1367 /* 1368 * SQIDI ranges are special because they use different steering 1369 * registers than everything else we work with. On XeHP SDV and 1370 * DG2-G10, any value in the steering registers will work fine since 1371 * all instances are present, but DG2-G11 only has SQIDI instances at 1372 * ID's 2 and 3, so we need to steer to one of those. For simplicity 1373 * we'll just steer to a hardcoded "2" since that value will work 1374 * everywhere. 1375 */ 1376 __set_mcr_steering(wal, MCFG_MCR_SELECTOR, 0, 2); 1377 __set_mcr_steering(wal, SF_MCR_SELECTOR, 0, 2); 1378 1379 /* 1380 * On DG2, GAM registers have a dedicated steering control register 1381 * and must always be programmed to a hardcoded groupid of "1." 1382 */ 1383 if (IS_DG2(gt->i915)) 1384 __set_mcr_steering(wal, GAM_MCR_SELECTOR, 1, 0); 1385 } 1386 1387 static void 1388 icl_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1389 { 1390 struct drm_i915_private *i915 = gt->i915; 1391 1392 icl_wa_init_mcr(gt, wal); 1393 1394 /* WaModifyGamTlbPartitioning:icl */ 1395 wa_write_clr_set(wal, 1396 GEN11_GACB_PERF_CTRL, 1397 GEN11_HASH_CTRL_MASK, 1398 GEN11_HASH_CTRL_BIT0 | GEN11_HASH_CTRL_BIT4); 1399 1400 /* Wa_1405766107:icl 1401 * Formerly known as WaCL2SFHalfMaxAlloc 1402 */ 1403 wa_write_or(wal, 1404 GEN11_LSN_UNSLCVC, 1405 GEN11_LSN_UNSLCVC_GAFS_HALF_SF_MAXALLOC | 1406 GEN11_LSN_UNSLCVC_GAFS_HALF_CL2_MAXALLOC); 1407 1408 /* Wa_220166154:icl 1409 * Formerly known as WaDisCtxReload 1410 */ 1411 wa_write_or(wal, 1412 GEN8_GAMW_ECO_DEV_RW_IA, 1413 GAMW_ECO_DEV_CTX_RELOAD_DISABLE); 1414 1415 /* Wa_1406463099:icl 1416 * Formerly known as WaGamTlbPendError 1417 */ 1418 wa_write_or(wal, 1419 GAMT_CHKN_BIT_REG, 1420 GAMT_CHKN_DISABLE_L3_COH_PIPE); 1421 1422 /* 1423 * Wa_1408615072:icl,ehl (vsunit) 1424 * Wa_1407596294:icl,ehl (hsunit) 1425 */ 1426 wa_write_or(wal, UNSLICE_UNIT_LEVEL_CLKGATE, 1427 VSUNIT_CLKGATE_DIS | HSUNIT_CLKGATE_DIS); 1428 1429 /* Wa_1407352427:icl,ehl */ 1430 wa_write_or(wal, UNSLICE_UNIT_LEVEL_CLKGATE2, 1431 PSDUNIT_CLKGATE_DIS); 1432 1433 /* Wa_1406680159:icl,ehl */ 1434 wa_mcr_write_or(wal, 1435 GEN11_SUBSLICE_UNIT_LEVEL_CLKGATE, 1436 GWUNIT_CLKGATE_DIS); 1437 1438 /* Wa_1607087056:icl,ehl,jsl */ 1439 if (IS_ICELAKE(i915) || 1440 ((IS_JASPERLAKE(i915) || IS_ELKHARTLAKE(i915)) && 1441 IS_GRAPHICS_STEP(i915, STEP_A0, STEP_B0))) 1442 wa_write_or(wal, 1443 GEN11_SLICE_UNIT_LEVEL_CLKGATE, 1444 L3_CLKGATE_DIS | L3_CR2X_CLKGATE_DIS); 1445 1446 /* 1447 * This is not a documented workaround, but rather an optimization 1448 * to reduce sampler power. 1449 */ 1450 wa_mcr_write_clr(wal, GEN10_DFR_RATIO_EN_AND_CHICKEN, DFR_DISABLE); 1451 } 1452 1453 /* 1454 * Though there are per-engine instances of these registers, 1455 * they retain their value through engine resets and should 1456 * only be provided on the GT workaround list rather than 1457 * the engine-specific workaround list. 1458 */ 1459 static void 1460 wa_14011060649(struct intel_gt *gt, struct i915_wa_list *wal) 1461 { 1462 struct intel_engine_cs *engine; 1463 int id; 1464 1465 for_each_engine(engine, gt, id) { 1466 if (engine->class != VIDEO_DECODE_CLASS || 1467 (engine->instance % 2)) 1468 continue; 1469 1470 wa_write_or(wal, VDBOX_CGCTL3F10(engine->mmio_base), 1471 IECPUNIT_CLKGATE_DIS); 1472 } 1473 } 1474 1475 static void 1476 gen12_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1477 { 1478 icl_wa_init_mcr(gt, wal); 1479 1480 /* Wa_14011060649:tgl,rkl,dg1,adl-s,adl-p */ 1481 wa_14011060649(gt, wal); 1482 1483 /* Wa_14011059788:tgl,rkl,adl-s,dg1,adl-p */ 1484 wa_mcr_write_or(wal, GEN10_DFR_RATIO_EN_AND_CHICKEN, DFR_DISABLE); 1485 1486 /* 1487 * Wa_14015795083 1488 * 1489 * Firmware on some gen12 platforms locks the MISCCPCTL register, 1490 * preventing i915 from modifying it for this workaround. Skip the 1491 * readback verification for this workaround on debug builds; if the 1492 * workaround doesn't stick due to firmware behavior, it's not an error 1493 * that we want CI to flag. 1494 */ 1495 wa_add(wal, GEN7_MISCCPCTL, GEN12_DOP_CLOCK_GATE_RENDER_ENABLE, 1496 0, 0, false); 1497 } 1498 1499 static void 1500 dg1_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1501 { 1502 gen12_gt_workarounds_init(gt, wal); 1503 1504 /* Wa_1409420604:dg1 */ 1505 wa_mcr_write_or(wal, SUBSLICE_UNIT_LEVEL_CLKGATE2, 1506 CPSSUNIT_CLKGATE_DIS); 1507 1508 /* Wa_1408615072:dg1 */ 1509 /* Empirical testing shows this register is unaffected by engine reset. */ 1510 wa_write_or(wal, UNSLICE_UNIT_LEVEL_CLKGATE2, VSUNIT_CLKGATE_DIS_TGL); 1511 } 1512 1513 static void 1514 dg2_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1515 { 1516 xehp_init_mcr(gt, wal); 1517 1518 /* Wa_14011060649:dg2 */ 1519 wa_14011060649(gt, wal); 1520 1521 if (IS_DG2_G10(gt->i915)) { 1522 /* Wa_22010523718:dg2 */ 1523 wa_write_or(wal, UNSLICE_UNIT_LEVEL_CLKGATE, 1524 CG3DDISCFEG_CLKGATE_DIS); 1525 1526 /* Wa_14011006942:dg2 */ 1527 wa_mcr_write_or(wal, GEN11_SUBSLICE_UNIT_LEVEL_CLKGATE, 1528 DSS_ROUTER_CLKGATE_DIS); 1529 } 1530 1531 /* Wa_14014830051:dg2 */ 1532 wa_mcr_write_clr(wal, SARB_CHICKEN1, COMP_CKN_IN); 1533 1534 /* 1535 * Wa_14015795083 1536 * Skip verification for possibly locked register. 1537 */ 1538 wa_add(wal, GEN7_MISCCPCTL, GEN12_DOP_CLOCK_GATE_RENDER_ENABLE, 1539 0, 0, false); 1540 1541 /* Wa_18018781329 */ 1542 wa_mcr_write_or(wal, RENDER_MOD_CTRL, FORCE_MISS_FTLB); 1543 wa_mcr_write_or(wal, COMP_MOD_CTRL, FORCE_MISS_FTLB); 1544 wa_mcr_write_or(wal, XEHP_VDBX_MOD_CTRL, FORCE_MISS_FTLB); 1545 wa_mcr_write_or(wal, XEHP_VEBX_MOD_CTRL, FORCE_MISS_FTLB); 1546 1547 /* Wa_1509235366:dg2 */ 1548 wa_mcr_write_or(wal, XEHP_GAMCNTRL_CTRL, 1549 INVALIDATION_BROADCAST_MODE_DIS | GLOBAL_INVALIDATION_MODE); 1550 1551 /* Wa_14010648519:dg2 */ 1552 wa_mcr_write_or(wal, XEHP_L3NODEARBCFG, XEHP_LNESPARE); 1553 } 1554 1555 static void 1556 xelpg_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1557 { 1558 /* Wa_14018575942 / Wa_18018781329 */ 1559 wa_mcr_write_or(wal, RENDER_MOD_CTRL, FORCE_MISS_FTLB); 1560 wa_mcr_write_or(wal, COMP_MOD_CTRL, FORCE_MISS_FTLB); 1561 1562 /* Wa_22016670082 */ 1563 wa_write_or(wal, GEN12_SQCNT1, GEN12_STRICT_RAR_ENABLE); 1564 1565 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 1566 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0)) { 1567 /* Wa_14014830051 */ 1568 wa_mcr_write_clr(wal, SARB_CHICKEN1, COMP_CKN_IN); 1569 1570 /* Wa_14015795083 */ 1571 wa_write_clr(wal, GEN7_MISCCPCTL, GEN12_DOP_CLOCK_GATE_RENDER_ENABLE); 1572 } 1573 1574 /* 1575 * Unlike older platforms, we no longer setup implicit steering here; 1576 * all MCR accesses are explicitly steered. 1577 */ 1578 debug_dump_steering(gt); 1579 } 1580 1581 static void 1582 wa_16021867713(struct intel_gt *gt, struct i915_wa_list *wal) 1583 { 1584 struct intel_engine_cs *engine; 1585 int id; 1586 1587 for_each_engine(engine, gt, id) 1588 if (engine->class == VIDEO_DECODE_CLASS) 1589 wa_write_or(wal, VDBOX_CGCTL3F1C(engine->mmio_base), 1590 MFXPIPE_CLKGATE_DIS); 1591 } 1592 1593 static void 1594 xelpmp_gt_workarounds_init(struct intel_gt *gt, struct i915_wa_list *wal) 1595 { 1596 wa_16021867713(gt, wal); 1597 1598 /* 1599 * Wa_14018778641 1600 * Wa_18018781329 1601 * 1602 * Note that although these registers are MCR on the primary 1603 * GT, the media GT's versions are regular singleton registers. 1604 */ 1605 wa_write_or(wal, XELPMP_GSC_MOD_CTRL, FORCE_MISS_FTLB); 1606 1607 /* 1608 * Wa_14018575942 1609 * 1610 * Issue is seen on media KPI test running on VDBOX engine 1611 * especially VP9 encoding WLs 1612 */ 1613 wa_write_or(wal, XELPMP_VDBX_MOD_CTRL, FORCE_MISS_FTLB); 1614 1615 /* Wa_22016670082 */ 1616 wa_write_or(wal, GEN12_SQCNT1, GEN12_STRICT_RAR_ENABLE); 1617 1618 debug_dump_steering(gt); 1619 } 1620 1621 /* 1622 * The bspec performance guide has recommended MMIO tuning settings. These 1623 * aren't truly "workarounds" but we want to program them through the 1624 * workaround infrastructure to make sure they're (re)applied at the proper 1625 * times. 1626 * 1627 * The programming in this function is for settings that persist through 1628 * engine resets and also are not part of any engine's register state context. 1629 * I.e., settings that only need to be re-applied in the event of a full GT 1630 * reset. 1631 */ 1632 static void gt_tuning_settings(struct intel_gt *gt, struct i915_wa_list *wal) 1633 { 1634 if (IS_GFX_GT_IP_RANGE(gt, IP_VER(12, 70), IP_VER(12, 74))) { 1635 wa_mcr_write_or(wal, XEHP_L3SCQREG7, BLEND_FILL_CACHING_OPT_DIS); 1636 wa_mcr_write_or(wal, XEHP_SQCM, EN_32B_ACCESS); 1637 } 1638 1639 if (IS_DG2(gt->i915)) { 1640 wa_mcr_write_or(wal, XEHP_L3SCQREG7, BLEND_FILL_CACHING_OPT_DIS); 1641 wa_mcr_write_or(wal, XEHP_SQCM, EN_32B_ACCESS); 1642 } 1643 } 1644 1645 static void 1646 gt_init_workarounds(struct intel_gt *gt, struct i915_wa_list *wal) 1647 { 1648 struct drm_i915_private *i915 = gt->i915; 1649 1650 gt_tuning_settings(gt, wal); 1651 1652 if (gt->type == GT_MEDIA) { 1653 if (MEDIA_VER_FULL(i915) == IP_VER(13, 0)) 1654 xelpmp_gt_workarounds_init(gt, wal); 1655 else 1656 MISSING_CASE(MEDIA_VER_FULL(i915)); 1657 1658 return; 1659 } 1660 1661 if (IS_GFX_GT_IP_RANGE(gt, IP_VER(12, 70), IP_VER(12, 74))) 1662 xelpg_gt_workarounds_init(gt, wal); 1663 else if (IS_DG2(i915)) 1664 dg2_gt_workarounds_init(gt, wal); 1665 else if (IS_DG1(i915)) 1666 dg1_gt_workarounds_init(gt, wal); 1667 else if (GRAPHICS_VER(i915) == 12) 1668 gen12_gt_workarounds_init(gt, wal); 1669 else if (GRAPHICS_VER(i915) == 11) 1670 icl_gt_workarounds_init(gt, wal); 1671 else if (IS_COFFEELAKE(i915) || IS_COMETLAKE(i915)) 1672 cfl_gt_workarounds_init(gt, wal); 1673 else if (IS_GEMINILAKE(i915)) 1674 glk_gt_workarounds_init(gt, wal); 1675 else if (IS_KABYLAKE(i915)) 1676 kbl_gt_workarounds_init(gt, wal); 1677 else if (IS_BROXTON(i915)) 1678 gen9_gt_workarounds_init(gt, wal); 1679 else if (IS_SKYLAKE(i915)) 1680 skl_gt_workarounds_init(gt, wal); 1681 else if (IS_HASWELL(i915)) 1682 hsw_gt_workarounds_init(gt, wal); 1683 else if (IS_VALLEYVIEW(i915)) 1684 vlv_gt_workarounds_init(gt, wal); 1685 else if (IS_IVYBRIDGE(i915)) 1686 ivb_gt_workarounds_init(gt, wal); 1687 else if (GRAPHICS_VER(i915) == 6) 1688 snb_gt_workarounds_init(gt, wal); 1689 else if (GRAPHICS_VER(i915) == 5) 1690 ilk_gt_workarounds_init(gt, wal); 1691 else if (IS_G4X(i915)) 1692 g4x_gt_workarounds_init(gt, wal); 1693 else if (GRAPHICS_VER(i915) == 4) 1694 gen4_gt_workarounds_init(gt, wal); 1695 else if (GRAPHICS_VER(i915) <= 8) 1696 ; 1697 else 1698 MISSING_CASE(GRAPHICS_VER(i915)); 1699 } 1700 1701 void intel_gt_init_workarounds(struct intel_gt *gt) 1702 { 1703 struct i915_wa_list *wal = >->wa_list; 1704 1705 wa_init_start(wal, gt, "GT", "global"); 1706 gt_init_workarounds(gt, wal); 1707 wa_init_finish(wal); 1708 } 1709 1710 static bool 1711 wa_verify(struct intel_gt *gt, const struct i915_wa *wa, u32 cur, 1712 const char *name, const char *from) 1713 { 1714 if ((cur ^ wa->set) & wa->read) { 1715 gt_err(gt, 1716 "%s workaround lost on %s! (reg[%x]=0x%x, relevant bits were 0x%x vs expected 0x%x)\n", 1717 name, from, i915_mmio_reg_offset(wa->reg), 1718 cur, cur & wa->read, wa->set & wa->read); 1719 1720 return false; 1721 } 1722 1723 return true; 1724 } 1725 1726 static void wa_list_apply(const struct i915_wa_list *wal) 1727 { 1728 struct intel_gt *gt = wal->gt; 1729 struct intel_uncore *uncore = gt->uncore; 1730 enum forcewake_domains fw; 1731 unsigned long flags; 1732 struct i915_wa *wa; 1733 unsigned int i; 1734 1735 if (!wal->count) 1736 return; 1737 1738 fw = wal_get_fw_for_rmw(uncore, wal); 1739 1740 intel_gt_mcr_lock(gt, &flags); 1741 spin_lock(&uncore->lock); 1742 intel_uncore_forcewake_get__locked(uncore, fw); 1743 1744 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) { 1745 u32 val, old = 0; 1746 1747 /* open-coded rmw due to steering */ 1748 if (wa->clr) 1749 old = wa->is_mcr ? 1750 intel_gt_mcr_read_any_fw(gt, wa->mcr_reg) : 1751 intel_uncore_read_fw(uncore, wa->reg); 1752 val = (old & ~wa->clr) | wa->set; 1753 if (val != old || !wa->clr) { 1754 if (wa->is_mcr) 1755 intel_gt_mcr_multicast_write_fw(gt, wa->mcr_reg, val); 1756 else 1757 intel_uncore_write_fw(uncore, wa->reg, val); 1758 } 1759 1760 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) { 1761 u32 val = wa->is_mcr ? 1762 intel_gt_mcr_read_any_fw(gt, wa->mcr_reg) : 1763 intel_uncore_read_fw(uncore, wa->reg); 1764 1765 wa_verify(gt, wa, val, wal->name, "application"); 1766 } 1767 } 1768 1769 intel_uncore_forcewake_put__locked(uncore, fw); 1770 spin_unlock(&uncore->lock); 1771 intel_gt_mcr_unlock(gt, flags); 1772 } 1773 1774 void intel_gt_apply_workarounds(struct intel_gt *gt) 1775 { 1776 wa_list_apply(>->wa_list); 1777 } 1778 1779 static bool wa_list_verify(struct intel_gt *gt, 1780 const struct i915_wa_list *wal, 1781 const char *from) 1782 { 1783 struct intel_uncore *uncore = gt->uncore; 1784 struct i915_wa *wa; 1785 enum forcewake_domains fw; 1786 unsigned long flags; 1787 unsigned int i; 1788 bool ok = true; 1789 1790 fw = wal_get_fw_for_rmw(uncore, wal); 1791 1792 intel_gt_mcr_lock(gt, &flags); 1793 spin_lock(&uncore->lock); 1794 intel_uncore_forcewake_get__locked(uncore, fw); 1795 1796 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) 1797 ok &= wa_verify(wal->gt, wa, wa->is_mcr ? 1798 intel_gt_mcr_read_any_fw(gt, wa->mcr_reg) : 1799 intel_uncore_read_fw(uncore, wa->reg), 1800 wal->name, from); 1801 1802 intel_uncore_forcewake_put__locked(uncore, fw); 1803 spin_unlock(&uncore->lock); 1804 intel_gt_mcr_unlock(gt, flags); 1805 1806 return ok; 1807 } 1808 1809 bool intel_gt_verify_workarounds(struct intel_gt *gt, const char *from) 1810 { 1811 return wa_list_verify(gt, >->wa_list, from); 1812 } 1813 1814 __maybe_unused 1815 static bool is_nonpriv_flags_valid(u32 flags) 1816 { 1817 /* Check only valid flag bits are set */ 1818 if (flags & ~RING_FORCE_TO_NONPRIV_MASK_VALID) 1819 return false; 1820 1821 /* NB: Only 3 out of 4 enum values are valid for access field */ 1822 if ((flags & RING_FORCE_TO_NONPRIV_ACCESS_MASK) == 1823 RING_FORCE_TO_NONPRIV_ACCESS_INVALID) 1824 return false; 1825 1826 return true; 1827 } 1828 1829 static void 1830 whitelist_reg_ext(struct i915_wa_list *wal, i915_reg_t reg, u32 flags) 1831 { 1832 struct i915_wa wa = { 1833 .reg = reg 1834 }; 1835 1836 if (GEM_DEBUG_WARN_ON(wal->count >= RING_MAX_NONPRIV_SLOTS)) 1837 return; 1838 1839 if (GEM_DEBUG_WARN_ON(!is_nonpriv_flags_valid(flags))) 1840 return; 1841 1842 wa.reg.reg |= flags; 1843 _wa_add(wal, &wa); 1844 } 1845 1846 static void 1847 whitelist_mcr_reg_ext(struct i915_wa_list *wal, i915_mcr_reg_t reg, u32 flags) 1848 { 1849 struct i915_wa wa = { 1850 .mcr_reg = reg, 1851 .is_mcr = 1, 1852 }; 1853 1854 if (GEM_DEBUG_WARN_ON(wal->count >= RING_MAX_NONPRIV_SLOTS)) 1855 return; 1856 1857 if (GEM_DEBUG_WARN_ON(!is_nonpriv_flags_valid(flags))) 1858 return; 1859 1860 wa.mcr_reg.reg |= flags; 1861 _wa_add(wal, &wa); 1862 } 1863 1864 static void 1865 whitelist_reg(struct i915_wa_list *wal, i915_reg_t reg) 1866 { 1867 whitelist_reg_ext(wal, reg, RING_FORCE_TO_NONPRIV_ACCESS_RW); 1868 } 1869 1870 static void 1871 whitelist_mcr_reg(struct i915_wa_list *wal, i915_mcr_reg_t reg) 1872 { 1873 whitelist_mcr_reg_ext(wal, reg, RING_FORCE_TO_NONPRIV_ACCESS_RW); 1874 } 1875 1876 static void gen9_whitelist_build(struct i915_wa_list *w) 1877 { 1878 /* WaVFEStateAfterPipeControlwithMediaStateClear:skl,bxt,glk,cfl */ 1879 whitelist_reg(w, GEN9_CTX_PREEMPT_REG); 1880 1881 /* WaEnablePreemptionGranularityControlByUMD:skl,bxt,kbl,cfl,[cnl] */ 1882 whitelist_reg(w, GEN8_CS_CHICKEN1); 1883 1884 /* WaAllowUMDToModifyHDCChicken1:skl,bxt,kbl,glk,cfl */ 1885 whitelist_reg(w, GEN8_HDC_CHICKEN1); 1886 1887 /* WaSendPushConstantsFromMMIO:skl,bxt */ 1888 whitelist_reg(w, COMMON_SLICE_CHICKEN2); 1889 } 1890 1891 static void skl_whitelist_build(struct intel_engine_cs *engine) 1892 { 1893 struct i915_wa_list *w = &engine->whitelist; 1894 1895 if (engine->class != RENDER_CLASS) 1896 return; 1897 1898 gen9_whitelist_build(w); 1899 1900 /* WaDisableLSQCROPERFforOCL:skl */ 1901 whitelist_mcr_reg(w, GEN8_L3SQCREG4); 1902 } 1903 1904 static void bxt_whitelist_build(struct intel_engine_cs *engine) 1905 { 1906 if (engine->class != RENDER_CLASS) 1907 return; 1908 1909 gen9_whitelist_build(&engine->whitelist); 1910 } 1911 1912 static void kbl_whitelist_build(struct intel_engine_cs *engine) 1913 { 1914 struct i915_wa_list *w = &engine->whitelist; 1915 1916 if (engine->class != RENDER_CLASS) 1917 return; 1918 1919 gen9_whitelist_build(w); 1920 1921 /* WaDisableLSQCROPERFforOCL:kbl */ 1922 whitelist_mcr_reg(w, GEN8_L3SQCREG4); 1923 } 1924 1925 static void glk_whitelist_build(struct intel_engine_cs *engine) 1926 { 1927 struct i915_wa_list *w = &engine->whitelist; 1928 1929 if (engine->class != RENDER_CLASS) 1930 return; 1931 1932 gen9_whitelist_build(w); 1933 1934 /* WA #0862: Userspace has to set "Barrier Mode" to avoid hangs. */ 1935 whitelist_reg(w, GEN9_SLICE_COMMON_ECO_CHICKEN1); 1936 } 1937 1938 static void cfl_whitelist_build(struct intel_engine_cs *engine) 1939 { 1940 struct i915_wa_list *w = &engine->whitelist; 1941 1942 if (engine->class != RENDER_CLASS) 1943 return; 1944 1945 gen9_whitelist_build(w); 1946 1947 /* 1948 * WaAllowPMDepthAndInvocationCountAccessFromUMD:cfl,whl,cml,aml 1949 * 1950 * This covers 4 register which are next to one another : 1951 * - PS_INVOCATION_COUNT 1952 * - PS_INVOCATION_COUNT_UDW 1953 * - PS_DEPTH_COUNT 1954 * - PS_DEPTH_COUNT_UDW 1955 */ 1956 whitelist_reg_ext(w, PS_INVOCATION_COUNT, 1957 RING_FORCE_TO_NONPRIV_ACCESS_RD | 1958 RING_FORCE_TO_NONPRIV_RANGE_4); 1959 } 1960 1961 static void allow_read_ctx_timestamp(struct intel_engine_cs *engine) 1962 { 1963 struct i915_wa_list *w = &engine->whitelist; 1964 1965 if (engine->class != RENDER_CLASS) 1966 whitelist_reg_ext(w, 1967 RING_CTX_TIMESTAMP(engine->mmio_base), 1968 RING_FORCE_TO_NONPRIV_ACCESS_RD); 1969 } 1970 1971 static void cml_whitelist_build(struct intel_engine_cs *engine) 1972 { 1973 allow_read_ctx_timestamp(engine); 1974 1975 cfl_whitelist_build(engine); 1976 } 1977 1978 static void icl_whitelist_build(struct intel_engine_cs *engine) 1979 { 1980 struct i915_wa_list *w = &engine->whitelist; 1981 1982 allow_read_ctx_timestamp(engine); 1983 1984 switch (engine->class) { 1985 case RENDER_CLASS: 1986 /* WaAllowUMDToModifyHalfSliceChicken7:icl */ 1987 whitelist_mcr_reg(w, GEN9_HALF_SLICE_CHICKEN7); 1988 1989 /* WaAllowUMDToModifySamplerMode:icl */ 1990 whitelist_mcr_reg(w, GEN10_SAMPLER_MODE); 1991 1992 /* WaEnableStateCacheRedirectToCS:icl */ 1993 whitelist_reg(w, GEN9_SLICE_COMMON_ECO_CHICKEN1); 1994 1995 /* 1996 * WaAllowPMDepthAndInvocationCountAccessFromUMD:icl 1997 * 1998 * This covers 4 register which are next to one another : 1999 * - PS_INVOCATION_COUNT 2000 * - PS_INVOCATION_COUNT_UDW 2001 * - PS_DEPTH_COUNT 2002 * - PS_DEPTH_COUNT_UDW 2003 */ 2004 whitelist_reg_ext(w, PS_INVOCATION_COUNT, 2005 RING_FORCE_TO_NONPRIV_ACCESS_RD | 2006 RING_FORCE_TO_NONPRIV_RANGE_4); 2007 break; 2008 2009 case VIDEO_DECODE_CLASS: 2010 /* hucStatusRegOffset */ 2011 whitelist_reg_ext(w, _MMIO(0x2000 + engine->mmio_base), 2012 RING_FORCE_TO_NONPRIV_ACCESS_RD); 2013 /* hucUKernelHdrInfoRegOffset */ 2014 whitelist_reg_ext(w, _MMIO(0x2014 + engine->mmio_base), 2015 RING_FORCE_TO_NONPRIV_ACCESS_RD); 2016 /* hucStatus2RegOffset */ 2017 whitelist_reg_ext(w, _MMIO(0x23B0 + engine->mmio_base), 2018 RING_FORCE_TO_NONPRIV_ACCESS_RD); 2019 break; 2020 2021 default: 2022 break; 2023 } 2024 } 2025 2026 static void tgl_whitelist_build(struct intel_engine_cs *engine) 2027 { 2028 struct i915_wa_list *w = &engine->whitelist; 2029 2030 allow_read_ctx_timestamp(engine); 2031 2032 switch (engine->class) { 2033 case RENDER_CLASS: 2034 /* 2035 * WaAllowPMDepthAndInvocationCountAccessFromUMD:tgl 2036 * Wa_1408556865:tgl 2037 * 2038 * This covers 4 registers which are next to one another : 2039 * - PS_INVOCATION_COUNT 2040 * - PS_INVOCATION_COUNT_UDW 2041 * - PS_DEPTH_COUNT 2042 * - PS_DEPTH_COUNT_UDW 2043 */ 2044 whitelist_reg_ext(w, PS_INVOCATION_COUNT, 2045 RING_FORCE_TO_NONPRIV_ACCESS_RD | 2046 RING_FORCE_TO_NONPRIV_RANGE_4); 2047 2048 /* 2049 * Wa_1808121037:tgl 2050 * Wa_14012131227:dg1 2051 * Wa_1508744258:tgl,rkl,dg1,adl-s,adl-p 2052 */ 2053 whitelist_reg(w, GEN7_COMMON_SLICE_CHICKEN1); 2054 2055 /* Wa_1806527549:tgl */ 2056 whitelist_reg(w, HIZ_CHICKEN); 2057 2058 /* Required by recommended tuning setting (not a workaround) */ 2059 whitelist_reg(w, GEN11_COMMON_SLICE_CHICKEN3); 2060 2061 break; 2062 default: 2063 break; 2064 } 2065 } 2066 2067 static void dg2_whitelist_build(struct intel_engine_cs *engine) 2068 { 2069 struct i915_wa_list *w = &engine->whitelist; 2070 2071 switch (engine->class) { 2072 case RENDER_CLASS: 2073 /* Required by recommended tuning setting (not a workaround) */ 2074 whitelist_mcr_reg(w, XEHP_COMMON_SLICE_CHICKEN3); 2075 2076 break; 2077 default: 2078 break; 2079 } 2080 } 2081 2082 static void xelpg_whitelist_build(struct intel_engine_cs *engine) 2083 { 2084 struct i915_wa_list *w = &engine->whitelist; 2085 2086 switch (engine->class) { 2087 case RENDER_CLASS: 2088 /* Required by recommended tuning setting (not a workaround) */ 2089 whitelist_mcr_reg(w, XEHP_COMMON_SLICE_CHICKEN3); 2090 2091 break; 2092 default: 2093 break; 2094 } 2095 } 2096 2097 void intel_engine_init_whitelist(struct intel_engine_cs *engine) 2098 { 2099 struct drm_i915_private *i915 = engine->i915; 2100 struct i915_wa_list *w = &engine->whitelist; 2101 2102 wa_init_start(w, engine->gt, "whitelist", engine->name); 2103 2104 if (engine->gt->type == GT_MEDIA) 2105 ; /* none yet */ 2106 else if (IS_GFX_GT_IP_RANGE(engine->gt, IP_VER(12, 70), IP_VER(12, 74))) 2107 xelpg_whitelist_build(engine); 2108 else if (IS_DG2(i915)) 2109 dg2_whitelist_build(engine); 2110 else if (GRAPHICS_VER(i915) == 12) 2111 tgl_whitelist_build(engine); 2112 else if (GRAPHICS_VER(i915) == 11) 2113 icl_whitelist_build(engine); 2114 else if (IS_COMETLAKE(i915)) 2115 cml_whitelist_build(engine); 2116 else if (IS_COFFEELAKE(i915)) 2117 cfl_whitelist_build(engine); 2118 else if (IS_GEMINILAKE(i915)) 2119 glk_whitelist_build(engine); 2120 else if (IS_KABYLAKE(i915)) 2121 kbl_whitelist_build(engine); 2122 else if (IS_BROXTON(i915)) 2123 bxt_whitelist_build(engine); 2124 else if (IS_SKYLAKE(i915)) 2125 skl_whitelist_build(engine); 2126 else if (GRAPHICS_VER(i915) <= 8) 2127 ; 2128 else 2129 MISSING_CASE(GRAPHICS_VER(i915)); 2130 2131 wa_init_finish(w); 2132 } 2133 2134 void intel_engine_apply_whitelist(struct intel_engine_cs *engine) 2135 { 2136 const struct i915_wa_list *wal = &engine->whitelist; 2137 struct intel_uncore *uncore = engine->uncore; 2138 const u32 base = engine->mmio_base; 2139 struct i915_wa *wa; 2140 unsigned int i; 2141 2142 if (!wal->count) 2143 return; 2144 2145 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) 2146 intel_uncore_write(uncore, 2147 RING_FORCE_TO_NONPRIV(base, i), 2148 i915_mmio_reg_offset(wa->reg)); 2149 2150 /* And clear the rest just in case of garbage */ 2151 for (; i < RING_MAX_NONPRIV_SLOTS; i++) 2152 intel_uncore_write(uncore, 2153 RING_FORCE_TO_NONPRIV(base, i), 2154 i915_mmio_reg_offset(RING_NOPID(base))); 2155 } 2156 2157 /* 2158 * engine_fake_wa_init(), a place holder to program the registers 2159 * which are not part of an official workaround defined by the 2160 * hardware team. 2161 * Adding programming of those register inside workaround will 2162 * allow utilizing wa framework to proper application and verification. 2163 */ 2164 static void 2165 engine_fake_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2166 { 2167 u8 mocs_w, mocs_r; 2168 2169 /* 2170 * RING_CMD_CCTL specifies the default MOCS entry that will be used 2171 * by the command streamer when executing commands that don't have 2172 * a way to explicitly specify a MOCS setting. The default should 2173 * usually reference whichever MOCS entry corresponds to uncached 2174 * behavior, although use of a WB cached entry is recommended by the 2175 * spec in certain circumstances on specific platforms. 2176 */ 2177 if (GRAPHICS_VER(engine->i915) >= 12) { 2178 mocs_r = engine->gt->mocs.uc_index; 2179 mocs_w = engine->gt->mocs.uc_index; 2180 2181 if (HAS_L3_CCS_READ(engine->i915) && 2182 engine->class == COMPUTE_CLASS) { 2183 mocs_r = engine->gt->mocs.wb_index; 2184 2185 /* 2186 * Even on the few platforms where MOCS 0 is a 2187 * legitimate table entry, it's never the correct 2188 * setting to use here; we can assume the MOCS init 2189 * just forgot to initialize wb_index. 2190 */ 2191 drm_WARN_ON(&engine->i915->drm, mocs_r == 0); 2192 } 2193 2194 wa_masked_field_set(wal, 2195 RING_CMD_CCTL(engine->mmio_base), 2196 CMD_CCTL_MOCS_MASK, 2197 CMD_CCTL_MOCS_OVERRIDE(mocs_w, mocs_r)); 2198 } 2199 } 2200 2201 static void 2202 rcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2203 { 2204 struct drm_i915_private *i915 = engine->i915; 2205 struct intel_gt *gt = engine->gt; 2206 2207 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 2208 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0)) { 2209 /* Wa_22014600077 */ 2210 wa_mcr_masked_en(wal, GEN10_CACHE_MODE_SS, 2211 ENABLE_EU_COUNT_FOR_TDL_FLUSH); 2212 } 2213 2214 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 2215 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0) || 2216 IS_DG2(i915)) { 2217 /* Wa_1509727124 */ 2218 wa_mcr_masked_en(wal, GEN10_SAMPLER_MODE, 2219 SC_DISABLE_POWER_OPTIMIZATION_EBB); 2220 } 2221 2222 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 2223 IS_DG2(i915)) { 2224 /* Wa_22012856258 */ 2225 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN2, 2226 GEN12_DISABLE_READ_SUPPRESSION); 2227 } 2228 2229 if (IS_DG2(i915)) { 2230 /* 2231 * Wa_22010960976:dg2 2232 * Wa_14013347512:dg2 2233 */ 2234 wa_mcr_masked_dis(wal, XEHP_HDC_CHICKEN0, 2235 LSC_L1_FLUSH_CTL_3D_DATAPORT_FLUSH_EVENTS_MASK); 2236 } 2237 2238 if (IS_GFX_GT_IP_RANGE(gt, IP_VER(12, 70), IP_VER(12, 71)) || 2239 IS_DG2(i915)) { 2240 /* Wa_14015150844 */ 2241 wa_mcr_add(wal, XEHP_HDC_CHICKEN0, 0, 2242 _MASKED_BIT_ENABLE(DIS_ATOMIC_CHAINING_TYPED_WRITES), 2243 0, true); 2244 } 2245 2246 if (IS_DG2(i915) || IS_ALDERLAKE_P(i915) || IS_ALDERLAKE_S(i915) || 2247 IS_DG1(i915) || IS_ROCKETLAKE(i915) || IS_TIGERLAKE(i915)) { 2248 /* 2249 * Wa_1606700617:tgl,dg1,adl-p 2250 * Wa_22010271021:tgl,rkl,dg1,adl-s,adl-p 2251 * Wa_14010826681:tgl,dg1,rkl,adl-p 2252 * Wa_18019627453:dg2 2253 */ 2254 wa_masked_en(wal, 2255 GEN9_CS_DEBUG_MODE1, 2256 FF_DOP_CLOCK_GATE_DISABLE); 2257 } 2258 2259 if (IS_ALDERLAKE_P(i915) || IS_ALDERLAKE_S(i915) || IS_DG1(i915) || 2260 IS_ROCKETLAKE(i915) || IS_TIGERLAKE(i915)) { 2261 /* Wa_1606931601:tgl,rkl,dg1,adl-s,adl-p */ 2262 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN2, GEN12_DISABLE_EARLY_READ); 2263 2264 /* 2265 * Wa_1407928979:tgl A* 2266 * Wa_18011464164:tgl[B0+],dg1[B0+] 2267 * Wa_22010931296:tgl[B0+],dg1[B0+] 2268 * Wa_14010919138:rkl,dg1,adl-s,adl-p 2269 */ 2270 wa_write_or(wal, GEN7_FF_THREAD_MODE, 2271 GEN12_FF_TESSELATION_DOP_GATE_DISABLE); 2272 2273 /* Wa_1406941453:tgl,rkl,dg1,adl-s,adl-p */ 2274 wa_mcr_masked_en(wal, 2275 GEN10_SAMPLER_MODE, 2276 ENABLE_SMALLPL); 2277 } 2278 2279 if (IS_ALDERLAKE_P(i915) || IS_ALDERLAKE_S(i915) || 2280 IS_ROCKETLAKE(i915) || IS_TIGERLAKE(i915)) { 2281 /* Wa_1409804808 */ 2282 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN2, 2283 GEN12_PUSH_CONST_DEREF_HOLD_DIS); 2284 2285 /* Wa_14010229206 */ 2286 wa_mcr_masked_en(wal, GEN9_ROW_CHICKEN4, GEN12_DISABLE_TDL_PUSH); 2287 } 2288 2289 if (IS_ROCKETLAKE(i915) || IS_TIGERLAKE(i915) || IS_ALDERLAKE_P(i915)) { 2290 /* 2291 * Wa_1607297627 2292 * 2293 * On TGL and RKL there are multiple entries for this WA in the 2294 * BSpec; some indicate this is an A0-only WA, others indicate 2295 * it applies to all steppings so we trust the "all steppings." 2296 */ 2297 wa_masked_en(wal, 2298 RING_PSMI_CTL(RENDER_RING_BASE), 2299 GEN12_WAIT_FOR_EVENT_POWER_DOWN_DISABLE | 2300 GEN8_RC_SEMA_IDLE_MSG_DISABLE); 2301 } 2302 2303 if (GRAPHICS_VER(i915) == 11) { 2304 /* This is not an Wa. Enable for better image quality */ 2305 wa_masked_en(wal, 2306 _3D_CHICKEN3, 2307 _3D_CHICKEN3_AA_LINE_QUALITY_FIX_ENABLE); 2308 2309 /* 2310 * Wa_1405543622:icl 2311 * Formerly known as WaGAPZPriorityScheme 2312 */ 2313 wa_write_or(wal, 2314 GEN8_GARBCNTL, 2315 GEN11_ARBITRATION_PRIO_ORDER_MASK); 2316 2317 /* 2318 * Wa_1604223664:icl 2319 * Formerly known as WaL3BankAddressHashing 2320 */ 2321 wa_write_clr_set(wal, 2322 GEN8_GARBCNTL, 2323 GEN11_HASH_CTRL_EXCL_MASK, 2324 GEN11_HASH_CTRL_EXCL_BIT0); 2325 wa_write_clr_set(wal, 2326 GEN11_GLBLINVL, 2327 GEN11_BANK_HASH_ADDR_EXCL_MASK, 2328 GEN11_BANK_HASH_ADDR_EXCL_BIT0); 2329 2330 /* 2331 * Wa_1405733216:icl 2332 * Formerly known as WaDisableCleanEvicts 2333 */ 2334 wa_mcr_write_or(wal, 2335 GEN8_L3SQCREG4, 2336 GEN11_LQSC_CLEAN_EVICT_DISABLE); 2337 2338 /* Wa_1606682166:icl */ 2339 wa_write_or(wal, 2340 GEN7_SARCHKMD, 2341 GEN7_DISABLE_SAMPLER_PREFETCH); 2342 2343 /* Wa_1409178092:icl */ 2344 wa_mcr_write_clr_set(wal, 2345 GEN11_SCRATCH2, 2346 GEN11_COHERENT_PARTIAL_WRITE_MERGE_ENABLE, 2347 0); 2348 2349 /* WaEnable32PlaneMode:icl */ 2350 wa_masked_en(wal, GEN9_CSFE_CHICKEN1_RCS, 2351 GEN11_ENABLE_32_PLANE_MODE); 2352 2353 /* 2354 * Wa_1408767742:icl[a2..forever],ehl[all] 2355 * Wa_1605460711:icl[a0..c0] 2356 */ 2357 wa_write_or(wal, 2358 GEN7_FF_THREAD_MODE, 2359 GEN12_FF_TESSELATION_DOP_GATE_DISABLE); 2360 2361 /* Wa_22010271021 */ 2362 wa_masked_en(wal, 2363 GEN9_CS_DEBUG_MODE1, 2364 FF_DOP_CLOCK_GATE_DISABLE); 2365 } 2366 2367 /* 2368 * Intel platforms that support fine-grained preemption (i.e., gen9 and 2369 * beyond) allow the kernel-mode driver to choose between two different 2370 * options for controlling preemption granularity and behavior. 2371 * 2372 * Option 1 (hardware default): 2373 * Preemption settings are controlled in a global manner via 2374 * kernel-only register CS_DEBUG_MODE1 (0x20EC). Any granularity 2375 * and settings chosen by the kernel-mode driver will apply to all 2376 * userspace clients. 2377 * 2378 * Option 2: 2379 * Preemption settings are controlled on a per-context basis via 2380 * register CS_CHICKEN1 (0x2580). CS_CHICKEN1 is saved/restored on 2381 * context switch and is writable by userspace (e.g., via 2382 * MI_LOAD_REGISTER_IMMEDIATE instructions placed in a batch buffer) 2383 * which allows different userspace drivers/clients to select 2384 * different settings, or to change those settings on the fly in 2385 * response to runtime needs. This option was known by name 2386 * "FtrPerCtxtPreemptionGranularityControl" at one time, although 2387 * that name is somewhat misleading as other non-granularity 2388 * preemption settings are also impacted by this decision. 2389 * 2390 * On Linux, our policy has always been to let userspace drivers 2391 * control preemption granularity/settings (Option 2). This was 2392 * originally mandatory on gen9 to prevent ABI breakage (old gen9 2393 * userspace developed before object-level preemption was enabled would 2394 * not behave well if i915 were to go with Option 1 and enable that 2395 * preemption in a global manner). On gen9 each context would have 2396 * object-level preemption disabled by default (see 2397 * WaDisable3DMidCmdPreemption in gen9_ctx_workarounds_init), but 2398 * userspace drivers could opt-in to object-level preemption as they 2399 * saw fit. For post-gen9 platforms, we continue to utilize Option 2; 2400 * even though it is no longer necessary for ABI compatibility when 2401 * enabling a new platform, it does ensure that userspace will be able 2402 * to implement any workarounds that show up requiring temporary 2403 * adjustments to preemption behavior at runtime. 2404 * 2405 * Notes/Workarounds: 2406 * - Wa_14015141709: On DG2 and early steppings of MTL, 2407 * CS_CHICKEN1[0] does not disable object-level preemption as 2408 * it is supposed to (nor does CS_DEBUG_MODE1[0] if we had been 2409 * using Option 1). Effectively this means userspace is unable 2410 * to disable object-level preemption on these platforms/steppings 2411 * despite the setting here. 2412 * 2413 * - Wa_16013994831: May require that userspace program 2414 * CS_CHICKEN1[10] when certain runtime conditions are true. 2415 * Userspace requires Option 2 to be in effect for their update of 2416 * CS_CHICKEN1[10] to be effective. 2417 * 2418 * Other workarounds may appear in the future that will also require 2419 * Option 2 behavior to allow proper userspace implementation. 2420 */ 2421 if (GRAPHICS_VER(i915) >= 9) 2422 wa_masked_en(wal, 2423 GEN7_FF_SLICE_CS_CHICKEN1, 2424 GEN9_FFSC_PERCTX_PREEMPT_CTRL); 2425 2426 if (IS_SKYLAKE(i915) || 2427 IS_KABYLAKE(i915) || 2428 IS_COFFEELAKE(i915) || 2429 IS_COMETLAKE(i915)) { 2430 /* WaEnableGapsTsvCreditFix:skl,kbl,cfl */ 2431 wa_write_or(wal, 2432 GEN8_GARBCNTL, 2433 GEN9_GAPS_TSV_CREDIT_DISABLE); 2434 } 2435 2436 if (IS_BROXTON(i915)) { 2437 /* WaDisablePooledEuLoadBalancingFix:bxt */ 2438 wa_masked_en(wal, 2439 FF_SLICE_CS_CHICKEN2, 2440 GEN9_POOLED_EU_LOAD_BALANCING_FIX_DISABLE); 2441 } 2442 2443 if (GRAPHICS_VER(i915) == 9) { 2444 /* WaContextSwitchWithConcurrentTLBInvalidate:skl,bxt,kbl,glk,cfl */ 2445 wa_masked_en(wal, 2446 GEN9_CSFE_CHICKEN1_RCS, 2447 GEN9_PREEMPT_GPGPU_SYNC_SWITCH_DISABLE); 2448 2449 /* WaEnableLbsSlaRetryTimerDecrement:skl,bxt,kbl,glk,cfl */ 2450 wa_mcr_write_or(wal, 2451 BDW_SCRATCH1, 2452 GEN9_LBS_SLA_RETRY_TIMER_DECREMENT_ENABLE); 2453 2454 /* WaProgramL3SqcReg1DefaultForPerf:bxt,glk */ 2455 if (IS_GEN9_LP(i915)) 2456 wa_mcr_write_clr_set(wal, 2457 GEN8_L3SQCREG1, 2458 L3_PRIO_CREDITS_MASK, 2459 L3_GENERAL_PRIO_CREDITS(62) | 2460 L3_HIGH_PRIO_CREDITS(2)); 2461 2462 /* WaOCLCoherentLineFlush:skl,bxt,kbl,cfl */ 2463 wa_mcr_write_or(wal, 2464 GEN8_L3SQCREG4, 2465 GEN8_LQSC_FLUSH_COHERENT_LINES); 2466 2467 /* Disable atomics in L3 to prevent unrecoverable hangs */ 2468 wa_write_clr_set(wal, GEN9_SCRATCH_LNCF1, 2469 GEN9_LNCF_NONIA_COHERENT_ATOMICS_ENABLE, 0); 2470 wa_mcr_write_clr_set(wal, GEN8_L3SQCREG4, 2471 GEN8_LQSQ_NONIA_COHERENT_ATOMICS_ENABLE, 0); 2472 wa_mcr_write_clr_set(wal, GEN9_SCRATCH1, 2473 EVICTION_PERF_FIX_ENABLE, 0); 2474 } 2475 2476 if (IS_HASWELL(i915)) { 2477 /* WaSampleCChickenBitEnable:hsw */ 2478 wa_masked_en(wal, 2479 HSW_HALF_SLICE_CHICKEN3, HSW_SAMPLE_C_PERFORMANCE); 2480 2481 wa_masked_dis(wal, 2482 CACHE_MODE_0_GEN7, 2483 /* enable HiZ Raw Stall Optimization */ 2484 HIZ_RAW_STALL_OPT_DISABLE); 2485 } 2486 2487 if (IS_VALLEYVIEW(i915)) { 2488 /* WaDisableEarlyCull:vlv */ 2489 wa_masked_en(wal, 2490 _3D_CHICKEN3, 2491 _3D_CHICKEN_SF_DISABLE_OBJEND_CULL); 2492 2493 /* 2494 * WaVSThreadDispatchOverride:ivb,vlv 2495 * 2496 * This actually overrides the dispatch 2497 * mode for all thread types. 2498 */ 2499 wa_write_clr_set(wal, 2500 GEN7_FF_THREAD_MODE, 2501 GEN7_FF_SCHED_MASK, 2502 GEN7_FF_TS_SCHED_HW | 2503 GEN7_FF_VS_SCHED_HW | 2504 GEN7_FF_DS_SCHED_HW); 2505 2506 /* WaPsdDispatchEnable:vlv */ 2507 /* WaDisablePSDDualDispatchEnable:vlv */ 2508 wa_masked_en(wal, 2509 GEN7_HALF_SLICE_CHICKEN1, 2510 GEN7_MAX_PS_THREAD_DEP | 2511 GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE); 2512 } 2513 2514 if (IS_IVYBRIDGE(i915)) { 2515 /* WaDisableEarlyCull:ivb */ 2516 wa_masked_en(wal, 2517 _3D_CHICKEN3, 2518 _3D_CHICKEN_SF_DISABLE_OBJEND_CULL); 2519 2520 if (0) { /* causes HiZ corruption on ivb:gt1 */ 2521 /* enable HiZ Raw Stall Optimization */ 2522 wa_masked_dis(wal, 2523 CACHE_MODE_0_GEN7, 2524 HIZ_RAW_STALL_OPT_DISABLE); 2525 } 2526 2527 /* 2528 * WaVSThreadDispatchOverride:ivb,vlv 2529 * 2530 * This actually overrides the dispatch 2531 * mode for all thread types. 2532 */ 2533 wa_write_clr_set(wal, 2534 GEN7_FF_THREAD_MODE, 2535 GEN7_FF_SCHED_MASK, 2536 GEN7_FF_TS_SCHED_HW | 2537 GEN7_FF_VS_SCHED_HW | 2538 GEN7_FF_DS_SCHED_HW); 2539 2540 /* WaDisablePSDDualDispatchEnable:ivb */ 2541 if (IS_IVB_GT1(i915)) 2542 wa_masked_en(wal, 2543 GEN7_HALF_SLICE_CHICKEN1, 2544 GEN7_PSD_SINGLE_PORT_DISPATCH_ENABLE); 2545 } 2546 2547 if (GRAPHICS_VER(i915) == 7) { 2548 /* WaBCSVCSTlbInvalidationMode:ivb,vlv,hsw */ 2549 wa_masked_en(wal, 2550 RING_MODE_GEN7(RENDER_RING_BASE), 2551 GFX_TLB_INVALIDATE_EXPLICIT | GFX_REPLAY_MODE); 2552 2553 /* WaDisable_RenderCache_OperationalFlush:ivb,vlv,hsw */ 2554 wa_masked_dis(wal, CACHE_MODE_0_GEN7, RC_OP_FLUSH_ENABLE); 2555 2556 /* 2557 * BSpec says this must be set, even though 2558 * WaDisable4x2SubspanOptimization:ivb,hsw 2559 * WaDisable4x2SubspanOptimization isn't listed for VLV. 2560 */ 2561 wa_masked_en(wal, 2562 CACHE_MODE_1, 2563 PIXEL_SUBSPAN_COLLECT_OPT_DISABLE); 2564 2565 /* 2566 * BSpec recommends 8x4 when MSAA is used, 2567 * however in practice 16x4 seems fastest. 2568 * 2569 * Note that PS/WM thread counts depend on the WIZ hashing 2570 * disable bit, which we don't touch here, but it's good 2571 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). 2572 */ 2573 wa_masked_field_set(wal, 2574 GEN7_GT_MODE, 2575 GEN6_WIZ_HASHING_MASK, 2576 GEN6_WIZ_HASHING_16x4); 2577 } 2578 2579 if (IS_GRAPHICS_VER(i915, 6, 7)) 2580 /* 2581 * We need to disable the AsyncFlip performance optimisations in 2582 * order to use MI_WAIT_FOR_EVENT within the CS. It should 2583 * already be programmed to '1' on all products. 2584 * 2585 * WaDisableAsyncFlipPerfMode:snb,ivb,hsw,vlv 2586 */ 2587 wa_masked_en(wal, 2588 RING_MI_MODE(RENDER_RING_BASE), 2589 ASYNC_FLIP_PERF_DISABLE); 2590 2591 if (GRAPHICS_VER(i915) == 6) { 2592 /* 2593 * Required for the hardware to program scanline values for 2594 * waiting 2595 * WaEnableFlushTlbInvalidationMode:snb 2596 */ 2597 wa_masked_en(wal, 2598 GFX_MODE, 2599 GFX_TLB_INVALIDATE_EXPLICIT); 2600 2601 /* WaDisableHiZPlanesWhenMSAAEnabled:snb */ 2602 wa_masked_en(wal, 2603 _3D_CHICKEN, 2604 _3D_CHICKEN_HIZ_PLANE_DISABLE_MSAA_4X_SNB); 2605 2606 wa_masked_en(wal, 2607 _3D_CHICKEN3, 2608 /* WaStripsFansDisableFastClipPerformanceFix:snb */ 2609 _3D_CHICKEN3_SF_DISABLE_FASTCLIP_CULL | 2610 /* 2611 * Bspec says: 2612 * "This bit must be set if 3DSTATE_CLIP clip mode is set 2613 * to normal and 3DSTATE_SF number of SF output attributes 2614 * is more than 16." 2615 */ 2616 _3D_CHICKEN3_SF_DISABLE_PIPELINED_ATTR_FETCH); 2617 2618 /* 2619 * BSpec recommends 8x4 when MSAA is used, 2620 * however in practice 16x4 seems fastest. 2621 * 2622 * Note that PS/WM thread counts depend on the WIZ hashing 2623 * disable bit, which we don't touch here, but it's good 2624 * to keep in mind (see 3DSTATE_PS and 3DSTATE_WM). 2625 */ 2626 wa_masked_field_set(wal, 2627 GEN6_GT_MODE, 2628 GEN6_WIZ_HASHING_MASK, 2629 GEN6_WIZ_HASHING_16x4); 2630 2631 /* WaDisable_RenderCache_OperationalFlush:snb */ 2632 wa_masked_dis(wal, CACHE_MODE_0, RC_OP_FLUSH_ENABLE); 2633 2634 /* 2635 * From the Sandybridge PRM, volume 1 part 3, page 24: 2636 * "If this bit is set, STCunit will have LRA as replacement 2637 * policy. [...] This bit must be reset. LRA replacement 2638 * policy is not supported." 2639 */ 2640 wa_masked_dis(wal, 2641 CACHE_MODE_0, 2642 CM0_STC_EVICT_DISABLE_LRA_SNB); 2643 } 2644 2645 if (IS_GRAPHICS_VER(i915, 4, 6)) 2646 /* WaTimedSingleVertexDispatch:cl,bw,ctg,elk,ilk,snb */ 2647 wa_add(wal, RING_MI_MODE(RENDER_RING_BASE), 2648 0, _MASKED_BIT_ENABLE(VS_TIMER_DISPATCH), 2649 /* XXX bit doesn't stick on Broadwater */ 2650 IS_I965G(i915) ? 0 : VS_TIMER_DISPATCH, true); 2651 2652 if (GRAPHICS_VER(i915) == 4) 2653 /* 2654 * Disable CONSTANT_BUFFER before it is loaded from the context 2655 * image. For as it is loaded, it is executed and the stored 2656 * address may no longer be valid, leading to a GPU hang. 2657 * 2658 * This imposes the requirement that userspace reload their 2659 * CONSTANT_BUFFER on every batch, fortunately a requirement 2660 * they are already accustomed to from before contexts were 2661 * enabled. 2662 */ 2663 wa_add(wal, ECOSKPD(RENDER_RING_BASE), 2664 0, _MASKED_BIT_ENABLE(ECO_CONSTANT_BUFFER_SR_DISABLE), 2665 0 /* XXX bit doesn't stick on Broadwater */, 2666 true); 2667 } 2668 2669 static void 2670 xcs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2671 { 2672 struct drm_i915_private *i915 = engine->i915; 2673 2674 /* WaKBLVECSSemaphoreWaitPoll:kbl */ 2675 if (IS_KABYLAKE(i915) && IS_GRAPHICS_STEP(i915, STEP_A0, STEP_F0)) { 2676 wa_write(wal, 2677 RING_SEMA_WAIT_POLL(engine->mmio_base), 2678 1); 2679 } 2680 /* Wa_16018031267, Wa_16018063123 */ 2681 if (NEEDS_FASTCOLOR_BLT_WABB(engine)) 2682 wa_masked_field_set(wal, ECOSKPD(engine->mmio_base), 2683 XEHP_BLITTER_SCHEDULING_MODE_MASK, 2684 XEHP_BLITTER_ROUND_ROBIN_MODE); 2685 } 2686 2687 static void 2688 ccs_engine_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2689 { 2690 /* boilerplate for any CCS engine workaround */ 2691 } 2692 2693 /* 2694 * The bspec performance guide has recommended MMIO tuning settings. These 2695 * aren't truly "workarounds" but we want to program them with the same 2696 * workaround infrastructure to ensure that they're automatically added to 2697 * the GuC save/restore lists, re-applied at the right times, and checked for 2698 * any conflicting programming requested by real workarounds. 2699 * 2700 * Programming settings should be added here only if their registers are not 2701 * part of an engine's register state context. If a register is part of a 2702 * context, then any tuning settings should be programmed in an appropriate 2703 * function invoked by __intel_engine_init_ctx_wa(). 2704 */ 2705 static void 2706 add_render_compute_tuning_settings(struct intel_gt *gt, 2707 struct i915_wa_list *wal) 2708 { 2709 struct drm_i915_private *i915 = gt->i915; 2710 2711 if (IS_GFX_GT_IP_RANGE(gt, IP_VER(12, 70), IP_VER(12, 74)) || IS_DG2(i915)) 2712 wa_mcr_write_clr_set(wal, RT_CTRL, STACKID_CTRL, STACKID_CTRL_512); 2713 2714 /* 2715 * This tuning setting proves beneficial only on ATS-M designs; the 2716 * default "age based" setting is optimal on regular DG2 and other 2717 * platforms. 2718 */ 2719 if (INTEL_INFO(i915)->tuning_thread_rr_after_dep) 2720 wa_mcr_masked_field_set(wal, GEN9_ROW_CHICKEN4, THREAD_EX_ARB_MODE, 2721 THREAD_EX_ARB_MODE_RR_AFTER_DEP); 2722 2723 if (GRAPHICS_VER(i915) == 12 && GRAPHICS_VER_FULL(i915) < IP_VER(12, 55)) 2724 wa_write_clr(wal, GEN8_GARBCNTL, GEN12_BUS_HASH_CTL_BIT_EXC); 2725 } 2726 2727 static void ccs_engine_wa_mode(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2728 { 2729 struct intel_gt *gt = engine->gt; 2730 u32 mode; 2731 2732 if (!IS_DG2(gt->i915)) 2733 return; 2734 2735 /* 2736 * Wa_14019159160: This workaround, along with others, leads to 2737 * significant challenges in utilizing load balancing among the 2738 * CCS slices. Consequently, an architectural decision has been 2739 * made to completely disable automatic CCS load balancing. 2740 */ 2741 wa_masked_en(wal, GEN12_RCU_MODE, XEHP_RCU_MODE_FIXED_SLICE_CCS_MODE); 2742 2743 /* 2744 * After having disabled automatic load balancing we need to 2745 * assign all slices to a single CCS. We will call it CCS mode 1 2746 */ 2747 mode = intel_gt_apply_ccs_mode(gt); 2748 wa_masked_en(wal, XEHP_CCS_MODE, mode); 2749 } 2750 2751 /* 2752 * The workarounds in this function apply to shared registers in 2753 * the general render reset domain that aren't tied to a 2754 * specific engine. Since all render+compute engines get reset 2755 * together, and the contents of these registers are lost during 2756 * the shared render domain reset, we'll define such workarounds 2757 * here and then add them to just a single RCS or CCS engine's 2758 * workaround list (whichever engine has the XXXX flag). 2759 */ 2760 static void 2761 general_render_compute_wa_init(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2762 { 2763 struct drm_i915_private *i915 = engine->i915; 2764 struct intel_gt *gt = engine->gt; 2765 2766 add_render_compute_tuning_settings(gt, wal); 2767 2768 if (GRAPHICS_VER(i915) >= 11) { 2769 /* This is not a Wa (although referred to as 2770 * WaSetInidrectStateOverride in places), this allows 2771 * applications that reference sampler states through 2772 * the BindlessSamplerStateBaseAddress to have their 2773 * border color relative to DynamicStateBaseAddress 2774 * rather than BindlessSamplerStateBaseAddress. 2775 * 2776 * Otherwise SAMPLER_STATE border colors have to be 2777 * copied in multiple heaps (DynamicStateBaseAddress & 2778 * BindlessSamplerStateBaseAddress) 2779 * 2780 * BSpec: 46052 2781 */ 2782 wa_mcr_masked_en(wal, 2783 GEN10_SAMPLER_MODE, 2784 GEN11_INDIRECT_STATE_BASE_ADDR_OVERRIDE); 2785 } 2786 2787 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_B0, STEP_FOREVER) || 2788 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_B0, STEP_FOREVER) || 2789 IS_GFX_GT_IP_RANGE(gt, IP_VER(12, 74), IP_VER(12, 74))) { 2790 /* Wa_14017856879 */ 2791 wa_mcr_masked_en(wal, GEN9_ROW_CHICKEN3, MTL_DISABLE_FIX_FOR_EOT_FLUSH); 2792 2793 /* Wa_14020495402 */ 2794 wa_mcr_masked_en(wal, GEN8_ROW_CHICKEN2, XELPG_DISABLE_TDL_SVHS_GATING); 2795 } 2796 2797 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 2798 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0)) 2799 /* 2800 * Wa_14017066071 2801 * Wa_14017654203 2802 */ 2803 wa_mcr_masked_en(wal, GEN10_SAMPLER_MODE, 2804 MTL_DISABLE_SAMPLER_SC_OOO); 2805 2806 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0)) 2807 /* Wa_22015279794 */ 2808 wa_mcr_masked_en(wal, GEN10_CACHE_MODE_SS, 2809 DISABLE_PREFETCH_INTO_IC); 2810 2811 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 2812 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0) || 2813 IS_DG2(i915)) { 2814 /* Wa_22013037850 */ 2815 wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0_UDW, 2816 DISABLE_128B_EVICTION_COMMAND_UDW); 2817 2818 /* Wa_18017747507 */ 2819 wa_masked_en(wal, VFG_PREEMPTION_CHICKEN, POLYGON_TRIFAN_LINELOOP_DISABLE); 2820 } 2821 2822 if (IS_GFX_GT_IP_STEP(gt, IP_VER(12, 70), STEP_A0, STEP_B0) || 2823 IS_GFX_GT_IP_STEP(gt, IP_VER(12, 71), STEP_A0, STEP_B0) || 2824 IS_DG2(i915)) { 2825 /* Wa_22014226127 */ 2826 wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0, DISABLE_D8_D16_COASLESCE); 2827 } 2828 2829 if (IS_DG2(i915)) { 2830 /* Wa_14015227452:dg2,pvc */ 2831 wa_mcr_masked_en(wal, GEN9_ROW_CHICKEN4, XEHP_DIS_BBL_SYSPIPE); 2832 2833 /* 2834 * Wa_16011620976:dg2_g11 2835 * Wa_22015475538:dg2 2836 */ 2837 wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0_UDW, DIS_CHAIN_2XSIMD8); 2838 2839 /* Wa_18028616096 */ 2840 wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0_UDW, UGM_FRAGMENT_THRESHOLD_TO_3); 2841 } 2842 2843 if (IS_DG2_G11(i915)) { 2844 /* 2845 * Wa_22012826095:dg2 2846 * Wa_22013059131:dg2 2847 */ 2848 wa_mcr_write_clr_set(wal, LSC_CHICKEN_BIT_0_UDW, 2849 MAXREQS_PER_BANK, 2850 REG_FIELD_PREP(MAXREQS_PER_BANK, 2)); 2851 2852 /* Wa_22013059131:dg2 */ 2853 wa_mcr_write_or(wal, LSC_CHICKEN_BIT_0, 2854 FORCE_1_SUB_MESSAGE_PER_FRAGMENT); 2855 2856 /* 2857 * Wa_22012654132 2858 * 2859 * Note that register 0xE420 is write-only and cannot be read 2860 * back for verification on DG2 (due to Wa_14012342262), so 2861 * we need to explicitly skip the readback. 2862 */ 2863 wa_mcr_add(wal, GEN10_CACHE_MODE_SS, 0, 2864 _MASKED_BIT_ENABLE(ENABLE_PREFETCH_INTO_IC), 2865 0 /* write-only, so skip validation */, 2866 true); 2867 } 2868 } 2869 2870 static void 2871 engine_init_workarounds(struct intel_engine_cs *engine, struct i915_wa_list *wal) 2872 { 2873 if (GRAPHICS_VER(engine->i915) < 4) 2874 return; 2875 2876 engine_fake_wa_init(engine, wal); 2877 2878 /* 2879 * These are common workarounds that just need to applied 2880 * to a single RCS/CCS engine's workaround list since 2881 * they're reset as part of the general render domain reset. 2882 */ 2883 if (engine->flags & I915_ENGINE_FIRST_RENDER_COMPUTE) { 2884 general_render_compute_wa_init(engine, wal); 2885 ccs_engine_wa_mode(engine, wal); 2886 } 2887 2888 if (engine->class == COMPUTE_CLASS) 2889 ccs_engine_wa_init(engine, wal); 2890 else if (engine->class == RENDER_CLASS) 2891 rcs_engine_wa_init(engine, wal); 2892 else 2893 xcs_engine_wa_init(engine, wal); 2894 } 2895 2896 void intel_engine_init_workarounds(struct intel_engine_cs *engine) 2897 { 2898 struct i915_wa_list *wal = &engine->wa_list; 2899 2900 wa_init_start(wal, engine->gt, "engine", engine->name); 2901 engine_init_workarounds(engine, wal); 2902 wa_init_finish(wal); 2903 } 2904 2905 void intel_engine_apply_workarounds(struct intel_engine_cs *engine) 2906 { 2907 wa_list_apply(&engine->wa_list); 2908 } 2909 2910 static const struct i915_range mcr_ranges_gen8[] = { 2911 { .start = 0x5500, .end = 0x55ff }, 2912 { .start = 0x7000, .end = 0x7fff }, 2913 { .start = 0x9400, .end = 0x97ff }, 2914 { .start = 0xb000, .end = 0xb3ff }, 2915 { .start = 0xe000, .end = 0xe7ff }, 2916 {}, 2917 }; 2918 2919 static const struct i915_range mcr_ranges_gen12[] = { 2920 { .start = 0x8150, .end = 0x815f }, 2921 { .start = 0x9520, .end = 0x955f }, 2922 { .start = 0xb100, .end = 0xb3ff }, 2923 { .start = 0xde80, .end = 0xe8ff }, 2924 { .start = 0x24a00, .end = 0x24a7f }, 2925 {}, 2926 }; 2927 2928 static const struct i915_range mcr_ranges_xehp[] = { 2929 { .start = 0x4000, .end = 0x4aff }, 2930 { .start = 0x5200, .end = 0x52ff }, 2931 { .start = 0x5400, .end = 0x7fff }, 2932 { .start = 0x8140, .end = 0x815f }, 2933 { .start = 0x8c80, .end = 0x8dff }, 2934 { .start = 0x94d0, .end = 0x955f }, 2935 { .start = 0x9680, .end = 0x96ff }, 2936 { .start = 0xb000, .end = 0xb3ff }, 2937 { .start = 0xc800, .end = 0xcfff }, 2938 { .start = 0xd800, .end = 0xd8ff }, 2939 { .start = 0xdc00, .end = 0xffff }, 2940 { .start = 0x17000, .end = 0x17fff }, 2941 { .start = 0x24a00, .end = 0x24a7f }, 2942 {}, 2943 }; 2944 2945 static bool mcr_range(struct drm_i915_private *i915, u32 offset) 2946 { 2947 const struct i915_range *mcr_ranges; 2948 int i; 2949 2950 if (GRAPHICS_VER_FULL(i915) >= IP_VER(12, 55)) 2951 mcr_ranges = mcr_ranges_xehp; 2952 else if (GRAPHICS_VER(i915) >= 12) 2953 mcr_ranges = mcr_ranges_gen12; 2954 else if (GRAPHICS_VER(i915) >= 8) 2955 mcr_ranges = mcr_ranges_gen8; 2956 else 2957 return false; 2958 2959 /* 2960 * Registers in these ranges are affected by the MCR selector 2961 * which only controls CPU initiated MMIO. Routing does not 2962 * work for CS access so we cannot verify them on this path. 2963 */ 2964 for (i = 0; mcr_ranges[i].start; i++) 2965 if (offset >= mcr_ranges[i].start && 2966 offset <= mcr_ranges[i].end) 2967 return true; 2968 2969 return false; 2970 } 2971 2972 static int 2973 wa_list_srm(struct i915_request *rq, 2974 const struct i915_wa_list *wal, 2975 struct i915_vma *vma) 2976 { 2977 struct drm_i915_private *i915 = rq->i915; 2978 unsigned int i, count = 0; 2979 const struct i915_wa *wa; 2980 u32 srm, *cs; 2981 2982 srm = MI_STORE_REGISTER_MEM | MI_SRM_LRM_GLOBAL_GTT; 2983 if (GRAPHICS_VER(i915) >= 8) 2984 srm++; 2985 2986 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) { 2987 if (!mcr_range(i915, i915_mmio_reg_offset(wa->reg))) 2988 count++; 2989 } 2990 2991 cs = intel_ring_begin(rq, 4 * count); 2992 if (IS_ERR(cs)) 2993 return PTR_ERR(cs); 2994 2995 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) { 2996 u32 offset = i915_mmio_reg_offset(wa->reg); 2997 2998 if (mcr_range(i915, offset)) 2999 continue; 3000 3001 *cs++ = srm; 3002 *cs++ = offset; 3003 *cs++ = i915_ggtt_offset(vma) + sizeof(u32) * i; 3004 *cs++ = 0; 3005 } 3006 intel_ring_advance(rq, cs); 3007 3008 return 0; 3009 } 3010 3011 static int engine_wa_list_verify(struct intel_context *ce, 3012 const struct i915_wa_list * const wal, 3013 const char *from) 3014 { 3015 const struct i915_wa *wa; 3016 struct i915_request *rq; 3017 struct i915_vma *vma; 3018 struct i915_gem_ww_ctx ww; 3019 unsigned int i; 3020 u32 *results; 3021 int err; 3022 3023 if (!wal->count) 3024 return 0; 3025 3026 vma = __vm_create_scratch_for_read(&ce->engine->gt->ggtt->vm, 3027 wal->count * sizeof(u32)); 3028 if (IS_ERR(vma)) 3029 return PTR_ERR(vma); 3030 3031 intel_engine_pm_get(ce->engine); 3032 i915_gem_ww_ctx_init(&ww, false); 3033 retry: 3034 err = i915_gem_object_lock(vma->obj, &ww); 3035 if (err == 0) 3036 err = intel_context_pin_ww(ce, &ww); 3037 if (err) 3038 goto err_pm; 3039 3040 err = i915_vma_pin_ww(vma, &ww, 0, 0, 3041 i915_vma_is_ggtt(vma) ? PIN_GLOBAL : PIN_USER); 3042 if (err) 3043 goto err_unpin; 3044 3045 rq = i915_request_create(ce); 3046 if (IS_ERR(rq)) { 3047 err = PTR_ERR(rq); 3048 goto err_vma; 3049 } 3050 3051 err = i915_vma_move_to_active(vma, rq, EXEC_OBJECT_WRITE); 3052 if (err == 0) 3053 err = wa_list_srm(rq, wal, vma); 3054 3055 i915_request_get(rq); 3056 if (err) 3057 i915_request_set_error_once(rq, err); 3058 i915_request_add(rq); 3059 3060 if (err) 3061 goto err_rq; 3062 3063 if (i915_request_wait(rq, 0, HZ / 5) < 0) { 3064 err = -ETIME; 3065 goto err_rq; 3066 } 3067 3068 results = i915_gem_object_pin_map(vma->obj, I915_MAP_WB); 3069 if (IS_ERR(results)) { 3070 err = PTR_ERR(results); 3071 goto err_rq; 3072 } 3073 3074 err = 0; 3075 for (i = 0, wa = wal->list; i < wal->count; i++, wa++) { 3076 if (mcr_range(rq->i915, i915_mmio_reg_offset(wa->reg))) 3077 continue; 3078 3079 if (!wa_verify(wal->gt, wa, results[i], wal->name, from)) 3080 err = -ENXIO; 3081 } 3082 3083 i915_gem_object_unpin_map(vma->obj); 3084 3085 err_rq: 3086 i915_request_put(rq); 3087 err_vma: 3088 i915_vma_unpin(vma); 3089 err_unpin: 3090 intel_context_unpin(ce); 3091 err_pm: 3092 if (err == -EDEADLK) { 3093 err = i915_gem_ww_ctx_backoff(&ww); 3094 if (!err) 3095 goto retry; 3096 } 3097 i915_gem_ww_ctx_fini(&ww); 3098 intel_engine_pm_put(ce->engine); 3099 i915_vma_put(vma); 3100 return err; 3101 } 3102 3103 int intel_engine_verify_workarounds(struct intel_engine_cs *engine, 3104 const char *from) 3105 { 3106 return engine_wa_list_verify(engine->kernel_context, 3107 &engine->wa_list, 3108 from); 3109 } 3110 3111 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 3112 #include "selftest_workarounds.c" 3113 #endif 3114