1 /* 2 * SPDX-License-Identifier: MIT 3 * 4 * Copyright © 2008-2018 Intel Corporation 5 */ 6 7 #include <linux/sched/mm.h> 8 #include <linux/stop_machine.h> 9 10 #include "display/intel_display_types.h" 11 #include "display/intel_overlay.h" 12 13 #include "gem/i915_gem_context.h" 14 15 #include "i915_drv.h" 16 #include "i915_gpu_error.h" 17 #include "i915_irq.h" 18 #include "intel_breadcrumbs.h" 19 #include "intel_engine_pm.h" 20 #include "intel_gt.h" 21 #include "intel_gt_pm.h" 22 #include "intel_gt_requests.h" 23 #include "intel_reset.h" 24 25 #include "uc/intel_guc.h" 26 #include "uc/intel_guc_submission.h" 27 28 #define RESET_MAX_RETRIES 3 29 30 /* XXX How to handle concurrent GGTT updates using tiling registers? */ 31 #define RESET_UNDER_STOP_MACHINE 0 32 33 static void rmw_set_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 set) 34 { 35 intel_uncore_rmw_fw(uncore, reg, 0, set); 36 } 37 38 static void rmw_clear_fw(struct intel_uncore *uncore, i915_reg_t reg, u32 clr) 39 { 40 intel_uncore_rmw_fw(uncore, reg, clr, 0); 41 } 42 43 static void engine_skip_context(struct i915_request *rq) 44 { 45 struct intel_engine_cs *engine = rq->engine; 46 struct intel_context *hung_ctx = rq->context; 47 48 if (!i915_request_is_active(rq)) 49 return; 50 51 lockdep_assert_held(&engine->active.lock); 52 list_for_each_entry_continue(rq, &engine->active.requests, sched.link) 53 if (rq->context == hung_ctx) { 54 i915_request_set_error_once(rq, -EIO); 55 __i915_request_skip(rq); 56 } 57 } 58 59 static void client_mark_guilty(struct i915_gem_context *ctx, bool banned) 60 { 61 struct drm_i915_file_private *file_priv = ctx->file_priv; 62 unsigned long prev_hang; 63 unsigned int score; 64 65 if (IS_ERR_OR_NULL(file_priv)) 66 return; 67 68 score = 0; 69 if (banned) 70 score = I915_CLIENT_SCORE_CONTEXT_BAN; 71 72 prev_hang = xchg(&file_priv->hang_timestamp, jiffies); 73 if (time_before(jiffies, prev_hang + I915_CLIENT_FAST_HANG_JIFFIES)) 74 score += I915_CLIENT_SCORE_HANG_FAST; 75 76 if (score) { 77 atomic_add(score, &file_priv->ban_score); 78 79 drm_dbg(&ctx->i915->drm, 80 "client %s: gained %u ban score, now %u\n", 81 ctx->name, score, 82 atomic_read(&file_priv->ban_score)); 83 } 84 } 85 86 static bool mark_guilty(struct i915_request *rq) 87 { 88 struct i915_gem_context *ctx; 89 unsigned long prev_hang; 90 bool banned; 91 int i; 92 93 if (intel_context_is_closed(rq->context)) { 94 intel_context_set_banned(rq->context); 95 return true; 96 } 97 98 rcu_read_lock(); 99 ctx = rcu_dereference(rq->context->gem_context); 100 if (ctx && !kref_get_unless_zero(&ctx->ref)) 101 ctx = NULL; 102 rcu_read_unlock(); 103 if (!ctx) 104 return intel_context_is_banned(rq->context); 105 106 atomic_inc(&ctx->guilty_count); 107 108 /* Cool contexts are too cool to be banned! (Used for reset testing.) */ 109 if (!i915_gem_context_is_bannable(ctx)) { 110 banned = false; 111 goto out; 112 } 113 114 drm_notice(&ctx->i915->drm, 115 "%s context reset due to GPU hang\n", 116 ctx->name); 117 118 /* Record the timestamp for the last N hangs */ 119 prev_hang = ctx->hang_timestamp[0]; 120 for (i = 0; i < ARRAY_SIZE(ctx->hang_timestamp) - 1; i++) 121 ctx->hang_timestamp[i] = ctx->hang_timestamp[i + 1]; 122 ctx->hang_timestamp[i] = jiffies; 123 124 /* If we have hung N+1 times in rapid succession, we ban the context! */ 125 banned = !i915_gem_context_is_recoverable(ctx); 126 if (time_before(jiffies, prev_hang + CONTEXT_FAST_HANG_JIFFIES)) 127 banned = true; 128 if (banned) { 129 drm_dbg(&ctx->i915->drm, "context %s: guilty %d, banned\n", 130 ctx->name, atomic_read(&ctx->guilty_count)); 131 intel_context_set_banned(rq->context); 132 } 133 134 client_mark_guilty(ctx, banned); 135 136 out: 137 i915_gem_context_put(ctx); 138 return banned; 139 } 140 141 static void mark_innocent(struct i915_request *rq) 142 { 143 struct i915_gem_context *ctx; 144 145 rcu_read_lock(); 146 ctx = rcu_dereference(rq->context->gem_context); 147 if (ctx) 148 atomic_inc(&ctx->active_count); 149 rcu_read_unlock(); 150 } 151 152 void __i915_request_reset(struct i915_request *rq, bool guilty) 153 { 154 RQ_TRACE(rq, "guilty? %s\n", yesno(guilty)); 155 156 GEM_BUG_ON(i915_request_completed(rq)); 157 158 rcu_read_lock(); /* protect the GEM context */ 159 if (guilty) { 160 i915_request_set_error_once(rq, -EIO); 161 __i915_request_skip(rq); 162 if (mark_guilty(rq)) 163 engine_skip_context(rq); 164 } else { 165 i915_request_set_error_once(rq, -EAGAIN); 166 mark_innocent(rq); 167 } 168 rcu_read_unlock(); 169 } 170 171 static bool i915_in_reset(struct pci_dev *pdev) 172 { 173 u8 gdrst; 174 175 pci_read_config_byte(pdev, I915_GDRST, &gdrst); 176 return gdrst & GRDOM_RESET_STATUS; 177 } 178 179 static int i915_do_reset(struct intel_gt *gt, 180 intel_engine_mask_t engine_mask, 181 unsigned int retry) 182 { 183 struct pci_dev *pdev = gt->i915->drm.pdev; 184 int err; 185 186 /* Assert reset for at least 20 usec, and wait for acknowledgement. */ 187 pci_write_config_byte(pdev, I915_GDRST, GRDOM_RESET_ENABLE); 188 udelay(50); 189 err = wait_for_atomic(i915_in_reset(pdev), 50); 190 191 /* Clear the reset request. */ 192 pci_write_config_byte(pdev, I915_GDRST, 0); 193 udelay(50); 194 if (!err) 195 err = wait_for_atomic(!i915_in_reset(pdev), 50); 196 197 return err; 198 } 199 200 static bool g4x_reset_complete(struct pci_dev *pdev) 201 { 202 u8 gdrst; 203 204 pci_read_config_byte(pdev, I915_GDRST, &gdrst); 205 return (gdrst & GRDOM_RESET_ENABLE) == 0; 206 } 207 208 static int g33_do_reset(struct intel_gt *gt, 209 intel_engine_mask_t engine_mask, 210 unsigned int retry) 211 { 212 struct pci_dev *pdev = gt->i915->drm.pdev; 213 214 pci_write_config_byte(pdev, I915_GDRST, GRDOM_RESET_ENABLE); 215 return wait_for_atomic(g4x_reset_complete(pdev), 50); 216 } 217 218 static int g4x_do_reset(struct intel_gt *gt, 219 intel_engine_mask_t engine_mask, 220 unsigned int retry) 221 { 222 struct pci_dev *pdev = gt->i915->drm.pdev; 223 struct intel_uncore *uncore = gt->uncore; 224 int ret; 225 226 /* WaVcpClkGateDisableForMediaReset:ctg,elk */ 227 rmw_set_fw(uncore, VDECCLK_GATE_D, VCP_UNIT_CLOCK_GATE_DISABLE); 228 intel_uncore_posting_read_fw(uncore, VDECCLK_GATE_D); 229 230 pci_write_config_byte(pdev, I915_GDRST, 231 GRDOM_MEDIA | GRDOM_RESET_ENABLE); 232 ret = wait_for_atomic(g4x_reset_complete(pdev), 50); 233 if (ret) { 234 drm_dbg(>->i915->drm, "Wait for media reset failed\n"); 235 goto out; 236 } 237 238 pci_write_config_byte(pdev, I915_GDRST, 239 GRDOM_RENDER | GRDOM_RESET_ENABLE); 240 ret = wait_for_atomic(g4x_reset_complete(pdev), 50); 241 if (ret) { 242 drm_dbg(>->i915->drm, "Wait for render reset failed\n"); 243 goto out; 244 } 245 246 out: 247 pci_write_config_byte(pdev, I915_GDRST, 0); 248 249 rmw_clear_fw(uncore, VDECCLK_GATE_D, VCP_UNIT_CLOCK_GATE_DISABLE); 250 intel_uncore_posting_read_fw(uncore, VDECCLK_GATE_D); 251 252 return ret; 253 } 254 255 static int ilk_do_reset(struct intel_gt *gt, intel_engine_mask_t engine_mask, 256 unsigned int retry) 257 { 258 struct intel_uncore *uncore = gt->uncore; 259 int ret; 260 261 intel_uncore_write_fw(uncore, ILK_GDSR, 262 ILK_GRDOM_RENDER | ILK_GRDOM_RESET_ENABLE); 263 ret = __intel_wait_for_register_fw(uncore, ILK_GDSR, 264 ILK_GRDOM_RESET_ENABLE, 0, 265 5000, 0, 266 NULL); 267 if (ret) { 268 drm_dbg(>->i915->drm, "Wait for render reset failed\n"); 269 goto out; 270 } 271 272 intel_uncore_write_fw(uncore, ILK_GDSR, 273 ILK_GRDOM_MEDIA | ILK_GRDOM_RESET_ENABLE); 274 ret = __intel_wait_for_register_fw(uncore, ILK_GDSR, 275 ILK_GRDOM_RESET_ENABLE, 0, 276 5000, 0, 277 NULL); 278 if (ret) { 279 drm_dbg(>->i915->drm, "Wait for media reset failed\n"); 280 goto out; 281 } 282 283 out: 284 intel_uncore_write_fw(uncore, ILK_GDSR, 0); 285 intel_uncore_posting_read_fw(uncore, ILK_GDSR); 286 return ret; 287 } 288 289 /* Reset the hardware domains (GENX_GRDOM_*) specified by mask */ 290 static int gen6_hw_domain_reset(struct intel_gt *gt, u32 hw_domain_mask) 291 { 292 struct intel_uncore *uncore = gt->uncore; 293 int err; 294 295 /* 296 * GEN6_GDRST is not in the gt power well, no need to check 297 * for fifo space for the write or forcewake the chip for 298 * the read 299 */ 300 intel_uncore_write_fw(uncore, GEN6_GDRST, hw_domain_mask); 301 302 /* Wait for the device to ack the reset requests */ 303 err = __intel_wait_for_register_fw(uncore, 304 GEN6_GDRST, hw_domain_mask, 0, 305 500, 0, 306 NULL); 307 if (err) 308 drm_dbg(>->i915->drm, 309 "Wait for 0x%08x engines reset failed\n", 310 hw_domain_mask); 311 312 return err; 313 } 314 315 static int gen6_reset_engines(struct intel_gt *gt, 316 intel_engine_mask_t engine_mask, 317 unsigned int retry) 318 { 319 static const u32 hw_engine_mask[] = { 320 [RCS0] = GEN6_GRDOM_RENDER, 321 [BCS0] = GEN6_GRDOM_BLT, 322 [VCS0] = GEN6_GRDOM_MEDIA, 323 [VCS1] = GEN8_GRDOM_MEDIA2, 324 [VECS0] = GEN6_GRDOM_VECS, 325 }; 326 struct intel_engine_cs *engine; 327 u32 hw_mask; 328 329 if (engine_mask == ALL_ENGINES) { 330 hw_mask = GEN6_GRDOM_FULL; 331 } else { 332 intel_engine_mask_t tmp; 333 334 hw_mask = 0; 335 for_each_engine_masked(engine, gt, engine_mask, tmp) { 336 GEM_BUG_ON(engine->id >= ARRAY_SIZE(hw_engine_mask)); 337 hw_mask |= hw_engine_mask[engine->id]; 338 } 339 } 340 341 return gen6_hw_domain_reset(gt, hw_mask); 342 } 343 344 static int gen11_lock_sfc(struct intel_engine_cs *engine, u32 *hw_mask) 345 { 346 struct intel_uncore *uncore = engine->uncore; 347 u8 vdbox_sfc_access = engine->gt->info.vdbox_sfc_access; 348 i915_reg_t sfc_forced_lock, sfc_forced_lock_ack; 349 u32 sfc_forced_lock_bit, sfc_forced_lock_ack_bit; 350 i915_reg_t sfc_usage; 351 u32 sfc_usage_bit; 352 u32 sfc_reset_bit; 353 int ret; 354 355 switch (engine->class) { 356 case VIDEO_DECODE_CLASS: 357 if ((BIT(engine->instance) & vdbox_sfc_access) == 0) 358 return 0; 359 360 sfc_forced_lock = GEN11_VCS_SFC_FORCED_LOCK(engine); 361 sfc_forced_lock_bit = GEN11_VCS_SFC_FORCED_LOCK_BIT; 362 363 sfc_forced_lock_ack = GEN11_VCS_SFC_LOCK_STATUS(engine); 364 sfc_forced_lock_ack_bit = GEN11_VCS_SFC_LOCK_ACK_BIT; 365 366 sfc_usage = GEN11_VCS_SFC_LOCK_STATUS(engine); 367 sfc_usage_bit = GEN11_VCS_SFC_USAGE_BIT; 368 sfc_reset_bit = GEN11_VCS_SFC_RESET_BIT(engine->instance); 369 break; 370 371 case VIDEO_ENHANCEMENT_CLASS: 372 sfc_forced_lock = GEN11_VECS_SFC_FORCED_LOCK(engine); 373 sfc_forced_lock_bit = GEN11_VECS_SFC_FORCED_LOCK_BIT; 374 375 sfc_forced_lock_ack = GEN11_VECS_SFC_LOCK_ACK(engine); 376 sfc_forced_lock_ack_bit = GEN11_VECS_SFC_LOCK_ACK_BIT; 377 378 sfc_usage = GEN11_VECS_SFC_USAGE(engine); 379 sfc_usage_bit = GEN11_VECS_SFC_USAGE_BIT; 380 sfc_reset_bit = GEN11_VECS_SFC_RESET_BIT(engine->instance); 381 break; 382 383 default: 384 return 0; 385 } 386 387 /* 388 * If the engine is using a SFC, tell the engine that a software reset 389 * is going to happen. The engine will then try to force lock the SFC. 390 * If SFC ends up being locked to the engine we want to reset, we have 391 * to reset it as well (we will unlock it once the reset sequence is 392 * completed). 393 */ 394 if (!(intel_uncore_read_fw(uncore, sfc_usage) & sfc_usage_bit)) 395 return 0; 396 397 rmw_set_fw(uncore, sfc_forced_lock, sfc_forced_lock_bit); 398 399 ret = __intel_wait_for_register_fw(uncore, 400 sfc_forced_lock_ack, 401 sfc_forced_lock_ack_bit, 402 sfc_forced_lock_ack_bit, 403 1000, 0, NULL); 404 405 /* Was the SFC released while we were trying to lock it? */ 406 if (!(intel_uncore_read_fw(uncore, sfc_usage) & sfc_usage_bit)) 407 return 0; 408 409 if (ret) { 410 drm_dbg(&engine->i915->drm, 411 "Wait for SFC forced lock ack failed\n"); 412 return ret; 413 } 414 415 *hw_mask |= sfc_reset_bit; 416 return 0; 417 } 418 419 static void gen11_unlock_sfc(struct intel_engine_cs *engine) 420 { 421 struct intel_uncore *uncore = engine->uncore; 422 u8 vdbox_sfc_access = engine->gt->info.vdbox_sfc_access; 423 i915_reg_t sfc_forced_lock; 424 u32 sfc_forced_lock_bit; 425 426 switch (engine->class) { 427 case VIDEO_DECODE_CLASS: 428 if ((BIT(engine->instance) & vdbox_sfc_access) == 0) 429 return; 430 431 sfc_forced_lock = GEN11_VCS_SFC_FORCED_LOCK(engine); 432 sfc_forced_lock_bit = GEN11_VCS_SFC_FORCED_LOCK_BIT; 433 break; 434 435 case VIDEO_ENHANCEMENT_CLASS: 436 sfc_forced_lock = GEN11_VECS_SFC_FORCED_LOCK(engine); 437 sfc_forced_lock_bit = GEN11_VECS_SFC_FORCED_LOCK_BIT; 438 break; 439 440 default: 441 return; 442 } 443 444 rmw_clear_fw(uncore, sfc_forced_lock, sfc_forced_lock_bit); 445 } 446 447 static int gen11_reset_engines(struct intel_gt *gt, 448 intel_engine_mask_t engine_mask, 449 unsigned int retry) 450 { 451 static const u32 hw_engine_mask[] = { 452 [RCS0] = GEN11_GRDOM_RENDER, 453 [BCS0] = GEN11_GRDOM_BLT, 454 [VCS0] = GEN11_GRDOM_MEDIA, 455 [VCS1] = GEN11_GRDOM_MEDIA2, 456 [VCS2] = GEN11_GRDOM_MEDIA3, 457 [VCS3] = GEN11_GRDOM_MEDIA4, 458 [VECS0] = GEN11_GRDOM_VECS, 459 [VECS1] = GEN11_GRDOM_VECS2, 460 }; 461 struct intel_engine_cs *engine; 462 intel_engine_mask_t tmp; 463 u32 hw_mask; 464 int ret; 465 466 if (engine_mask == ALL_ENGINES) { 467 hw_mask = GEN11_GRDOM_FULL; 468 } else { 469 hw_mask = 0; 470 for_each_engine_masked(engine, gt, engine_mask, tmp) { 471 GEM_BUG_ON(engine->id >= ARRAY_SIZE(hw_engine_mask)); 472 hw_mask |= hw_engine_mask[engine->id]; 473 ret = gen11_lock_sfc(engine, &hw_mask); 474 if (ret) 475 goto sfc_unlock; 476 } 477 } 478 479 ret = gen6_hw_domain_reset(gt, hw_mask); 480 481 sfc_unlock: 482 /* 483 * We unlock the SFC based on the lock status and not the result of 484 * gen11_lock_sfc to make sure that we clean properly if something 485 * wrong happened during the lock (e.g. lock acquired after timeout 486 * expiration). 487 */ 488 if (engine_mask != ALL_ENGINES) 489 for_each_engine_masked(engine, gt, engine_mask, tmp) 490 gen11_unlock_sfc(engine); 491 492 return ret; 493 } 494 495 static int gen8_engine_reset_prepare(struct intel_engine_cs *engine) 496 { 497 struct intel_uncore *uncore = engine->uncore; 498 const i915_reg_t reg = RING_RESET_CTL(engine->mmio_base); 499 u32 request, mask, ack; 500 int ret; 501 502 ack = intel_uncore_read_fw(uncore, reg); 503 if (ack & RESET_CTL_CAT_ERROR) { 504 /* 505 * For catastrophic errors, ready-for-reset sequence 506 * needs to be bypassed: HAS#396813 507 */ 508 request = RESET_CTL_CAT_ERROR; 509 mask = RESET_CTL_CAT_ERROR; 510 511 /* Catastrophic errors need to be cleared by HW */ 512 ack = 0; 513 } else if (!(ack & RESET_CTL_READY_TO_RESET)) { 514 request = RESET_CTL_REQUEST_RESET; 515 mask = RESET_CTL_READY_TO_RESET; 516 ack = RESET_CTL_READY_TO_RESET; 517 } else { 518 return 0; 519 } 520 521 intel_uncore_write_fw(uncore, reg, _MASKED_BIT_ENABLE(request)); 522 ret = __intel_wait_for_register_fw(uncore, reg, mask, ack, 523 700, 0, NULL); 524 if (ret) 525 drm_err(&engine->i915->drm, 526 "%s reset request timed out: {request: %08x, RESET_CTL: %08x}\n", 527 engine->name, request, 528 intel_uncore_read_fw(uncore, reg)); 529 530 return ret; 531 } 532 533 static void gen8_engine_reset_cancel(struct intel_engine_cs *engine) 534 { 535 intel_uncore_write_fw(engine->uncore, 536 RING_RESET_CTL(engine->mmio_base), 537 _MASKED_BIT_DISABLE(RESET_CTL_REQUEST_RESET)); 538 } 539 540 static int gen8_reset_engines(struct intel_gt *gt, 541 intel_engine_mask_t engine_mask, 542 unsigned int retry) 543 { 544 struct intel_engine_cs *engine; 545 const bool reset_non_ready = retry >= 1; 546 intel_engine_mask_t tmp; 547 int ret; 548 549 for_each_engine_masked(engine, gt, engine_mask, tmp) { 550 ret = gen8_engine_reset_prepare(engine); 551 if (ret && !reset_non_ready) 552 goto skip_reset; 553 554 /* 555 * If this is not the first failed attempt to prepare, 556 * we decide to proceed anyway. 557 * 558 * By doing so we risk context corruption and with 559 * some gens (kbl), possible system hang if reset 560 * happens during active bb execution. 561 * 562 * We rather take context corruption instead of 563 * failed reset with a wedged driver/gpu. And 564 * active bb execution case should be covered by 565 * stop_engines() we have before the reset. 566 */ 567 } 568 569 if (INTEL_GEN(gt->i915) >= 11) 570 ret = gen11_reset_engines(gt, engine_mask, retry); 571 else 572 ret = gen6_reset_engines(gt, engine_mask, retry); 573 574 skip_reset: 575 for_each_engine_masked(engine, gt, engine_mask, tmp) 576 gen8_engine_reset_cancel(engine); 577 578 return ret; 579 } 580 581 static int mock_reset(struct intel_gt *gt, 582 intel_engine_mask_t mask, 583 unsigned int retry) 584 { 585 return 0; 586 } 587 588 typedef int (*reset_func)(struct intel_gt *, 589 intel_engine_mask_t engine_mask, 590 unsigned int retry); 591 592 static reset_func intel_get_gpu_reset(const struct intel_gt *gt) 593 { 594 struct drm_i915_private *i915 = gt->i915; 595 596 if (is_mock_gt(gt)) 597 return mock_reset; 598 else if (INTEL_GEN(i915) >= 8) 599 return gen8_reset_engines; 600 else if (INTEL_GEN(i915) >= 6) 601 return gen6_reset_engines; 602 else if (INTEL_GEN(i915) >= 5) 603 return ilk_do_reset; 604 else if (IS_G4X(i915)) 605 return g4x_do_reset; 606 else if (IS_G33(i915) || IS_PINEVIEW(i915)) 607 return g33_do_reset; 608 else if (INTEL_GEN(i915) >= 3) 609 return i915_do_reset; 610 else 611 return NULL; 612 } 613 614 int __intel_gt_reset(struct intel_gt *gt, intel_engine_mask_t engine_mask) 615 { 616 const int retries = engine_mask == ALL_ENGINES ? RESET_MAX_RETRIES : 1; 617 reset_func reset; 618 int ret = -ETIMEDOUT; 619 int retry; 620 621 reset = intel_get_gpu_reset(gt); 622 if (!reset) 623 return -ENODEV; 624 625 /* 626 * If the power well sleeps during the reset, the reset 627 * request may be dropped and never completes (causing -EIO). 628 */ 629 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); 630 for (retry = 0; ret == -ETIMEDOUT && retry < retries; retry++) { 631 GT_TRACE(gt, "engine_mask=%x\n", engine_mask); 632 preempt_disable(); 633 ret = reset(gt, engine_mask, retry); 634 preempt_enable(); 635 } 636 intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL); 637 638 return ret; 639 } 640 641 bool intel_has_gpu_reset(const struct intel_gt *gt) 642 { 643 if (!gt->i915->params.reset) 644 return NULL; 645 646 return intel_get_gpu_reset(gt); 647 } 648 649 bool intel_has_reset_engine(const struct intel_gt *gt) 650 { 651 if (gt->i915->params.reset < 2) 652 return false; 653 654 return INTEL_INFO(gt->i915)->has_reset_engine; 655 } 656 657 int intel_reset_guc(struct intel_gt *gt) 658 { 659 u32 guc_domain = 660 INTEL_GEN(gt->i915) >= 11 ? GEN11_GRDOM_GUC : GEN9_GRDOM_GUC; 661 int ret; 662 663 GEM_BUG_ON(!HAS_GT_UC(gt->i915)); 664 665 intel_uncore_forcewake_get(gt->uncore, FORCEWAKE_ALL); 666 ret = gen6_hw_domain_reset(gt, guc_domain); 667 intel_uncore_forcewake_put(gt->uncore, FORCEWAKE_ALL); 668 669 return ret; 670 } 671 672 /* 673 * Ensure irq handler finishes, and not run again. 674 * Also return the active request so that we only search for it once. 675 */ 676 static void reset_prepare_engine(struct intel_engine_cs *engine) 677 { 678 /* 679 * During the reset sequence, we must prevent the engine from 680 * entering RC6. As the context state is undefined until we restart 681 * the engine, if it does enter RC6 during the reset, the state 682 * written to the powercontext is undefined and so we may lose 683 * GPU state upon resume, i.e. fail to restart after a reset. 684 */ 685 intel_uncore_forcewake_get(engine->uncore, FORCEWAKE_ALL); 686 if (engine->reset.prepare) 687 engine->reset.prepare(engine); 688 } 689 690 static void revoke_mmaps(struct intel_gt *gt) 691 { 692 int i; 693 694 for (i = 0; i < gt->ggtt->num_fences; i++) { 695 struct drm_vma_offset_node *node; 696 struct i915_vma *vma; 697 u64 vma_offset; 698 699 vma = READ_ONCE(gt->ggtt->fence_regs[i].vma); 700 if (!vma) 701 continue; 702 703 if (!i915_vma_has_userfault(vma)) 704 continue; 705 706 GEM_BUG_ON(vma->fence != >->ggtt->fence_regs[i]); 707 708 if (!vma->mmo) 709 continue; 710 711 node = &vma->mmo->vma_node; 712 vma_offset = vma->ggtt_view.partial.offset << PAGE_SHIFT; 713 714 unmap_mapping_range(gt->i915->drm.anon_inode->i_mapping, 715 drm_vma_node_offset_addr(node) + vma_offset, 716 vma->size, 717 1); 718 } 719 } 720 721 static intel_engine_mask_t reset_prepare(struct intel_gt *gt) 722 { 723 struct intel_engine_cs *engine; 724 intel_engine_mask_t awake = 0; 725 enum intel_engine_id id; 726 727 for_each_engine(engine, gt, id) { 728 if (intel_engine_pm_get_if_awake(engine)) 729 awake |= engine->mask; 730 reset_prepare_engine(engine); 731 } 732 733 intel_uc_reset_prepare(>->uc); 734 735 return awake; 736 } 737 738 static void gt_revoke(struct intel_gt *gt) 739 { 740 revoke_mmaps(gt); 741 } 742 743 static int gt_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask) 744 { 745 struct intel_engine_cs *engine; 746 enum intel_engine_id id; 747 int err; 748 749 /* 750 * Everything depends on having the GTT running, so we need to start 751 * there. 752 */ 753 err = i915_ggtt_enable_hw(gt->i915); 754 if (err) 755 return err; 756 757 for_each_engine(engine, gt, id) 758 __intel_engine_reset(engine, stalled_mask & engine->mask); 759 760 intel_ggtt_restore_fences(gt->ggtt); 761 762 return err; 763 } 764 765 static void reset_finish_engine(struct intel_engine_cs *engine) 766 { 767 if (engine->reset.finish) 768 engine->reset.finish(engine); 769 intel_uncore_forcewake_put(engine->uncore, FORCEWAKE_ALL); 770 771 intel_engine_signal_breadcrumbs(engine); 772 } 773 774 static void reset_finish(struct intel_gt *gt, intel_engine_mask_t awake) 775 { 776 struct intel_engine_cs *engine; 777 enum intel_engine_id id; 778 779 for_each_engine(engine, gt, id) { 780 reset_finish_engine(engine); 781 if (awake & engine->mask) 782 intel_engine_pm_put(engine); 783 } 784 } 785 786 static void nop_submit_request(struct i915_request *request) 787 { 788 struct intel_engine_cs *engine = request->engine; 789 unsigned long flags; 790 791 RQ_TRACE(request, "-EIO\n"); 792 i915_request_set_error_once(request, -EIO); 793 794 spin_lock_irqsave(&engine->active.lock, flags); 795 __i915_request_submit(request); 796 i915_request_mark_complete(request); 797 spin_unlock_irqrestore(&engine->active.lock, flags); 798 799 intel_engine_signal_breadcrumbs(engine); 800 } 801 802 static void __intel_gt_set_wedged(struct intel_gt *gt) 803 { 804 struct intel_engine_cs *engine; 805 intel_engine_mask_t awake; 806 enum intel_engine_id id; 807 808 if (test_bit(I915_WEDGED, >->reset.flags)) 809 return; 810 811 GT_TRACE(gt, "start\n"); 812 813 /* 814 * First, stop submission to hw, but do not yet complete requests by 815 * rolling the global seqno forward (since this would complete requests 816 * for which we haven't set the fence error to EIO yet). 817 */ 818 awake = reset_prepare(gt); 819 820 /* Even if the GPU reset fails, it should still stop the engines */ 821 if (!INTEL_INFO(gt->i915)->gpu_reset_clobbers_display) 822 __intel_gt_reset(gt, ALL_ENGINES); 823 824 for_each_engine(engine, gt, id) 825 engine->submit_request = nop_submit_request; 826 827 /* 828 * Make sure no request can slip through without getting completed by 829 * either this call here to intel_engine_write_global_seqno, or the one 830 * in nop_submit_request. 831 */ 832 synchronize_rcu_expedited(); 833 set_bit(I915_WEDGED, >->reset.flags); 834 835 /* Mark all executing requests as skipped */ 836 for_each_engine(engine, gt, id) 837 if (engine->reset.cancel) 838 engine->reset.cancel(engine); 839 840 reset_finish(gt, awake); 841 842 GT_TRACE(gt, "end\n"); 843 } 844 845 void intel_gt_set_wedged(struct intel_gt *gt) 846 { 847 intel_wakeref_t wakeref; 848 849 if (test_bit(I915_WEDGED, >->reset.flags)) 850 return; 851 852 wakeref = intel_runtime_pm_get(gt->uncore->rpm); 853 mutex_lock(>->reset.mutex); 854 855 if (GEM_SHOW_DEBUG()) { 856 struct drm_printer p = drm_debug_printer(__func__); 857 struct intel_engine_cs *engine; 858 enum intel_engine_id id; 859 860 drm_printf(&p, "called from %pS\n", (void *)_RET_IP_); 861 for_each_engine(engine, gt, id) { 862 if (intel_engine_is_idle(engine)) 863 continue; 864 865 intel_engine_dump(engine, &p, "%s\n", engine->name); 866 } 867 } 868 869 __intel_gt_set_wedged(gt); 870 871 mutex_unlock(>->reset.mutex); 872 intel_runtime_pm_put(gt->uncore->rpm, wakeref); 873 } 874 875 static bool __intel_gt_unset_wedged(struct intel_gt *gt) 876 { 877 struct intel_gt_timelines *timelines = >->timelines; 878 struct intel_timeline *tl; 879 bool ok; 880 881 if (!test_bit(I915_WEDGED, >->reset.flags)) 882 return true; 883 884 /* Never fully initialised, recovery impossible */ 885 if (intel_gt_has_unrecoverable_error(gt)) 886 return false; 887 888 GT_TRACE(gt, "start\n"); 889 890 /* 891 * Before unwedging, make sure that all pending operations 892 * are flushed and errored out - we may have requests waiting upon 893 * third party fences. We marked all inflight requests as EIO, and 894 * every execbuf since returned EIO, for consistency we want all 895 * the currently pending requests to also be marked as EIO, which 896 * is done inside our nop_submit_request - and so we must wait. 897 * 898 * No more can be submitted until we reset the wedged bit. 899 */ 900 spin_lock(&timelines->lock); 901 list_for_each_entry(tl, &timelines->active_list, link) { 902 struct dma_fence *fence; 903 904 fence = i915_active_fence_get(&tl->last_request); 905 if (!fence) 906 continue; 907 908 spin_unlock(&timelines->lock); 909 910 /* 911 * All internal dependencies (i915_requests) will have 912 * been flushed by the set-wedge, but we may be stuck waiting 913 * for external fences. These should all be capped to 10s 914 * (I915_FENCE_TIMEOUT) so this wait should not be unbounded 915 * in the worst case. 916 */ 917 dma_fence_default_wait(fence, false, MAX_SCHEDULE_TIMEOUT); 918 dma_fence_put(fence); 919 920 /* Restart iteration after droping lock */ 921 spin_lock(&timelines->lock); 922 tl = list_entry(&timelines->active_list, typeof(*tl), link); 923 } 924 spin_unlock(&timelines->lock); 925 926 /* We must reset pending GPU events before restoring our submission */ 927 ok = !HAS_EXECLISTS(gt->i915); /* XXX better agnosticism desired */ 928 if (!INTEL_INFO(gt->i915)->gpu_reset_clobbers_display) 929 ok = __intel_gt_reset(gt, ALL_ENGINES) == 0; 930 if (!ok) { 931 /* 932 * Warn CI about the unrecoverable wedged condition. 933 * Time for a reboot. 934 */ 935 add_taint_for_CI(gt->i915, TAINT_WARN); 936 return false; 937 } 938 939 /* 940 * Undo nop_submit_request. We prevent all new i915 requests from 941 * being queued (by disallowing execbuf whilst wedged) so having 942 * waited for all active requests above, we know the system is idle 943 * and do not have to worry about a thread being inside 944 * engine->submit_request() as we swap over. So unlike installing 945 * the nop_submit_request on reset, we can do this from normal 946 * context and do not require stop_machine(). 947 */ 948 intel_engines_reset_default_submission(gt); 949 950 GT_TRACE(gt, "end\n"); 951 952 smp_mb__before_atomic(); /* complete takeover before enabling execbuf */ 953 clear_bit(I915_WEDGED, >->reset.flags); 954 955 return true; 956 } 957 958 bool intel_gt_unset_wedged(struct intel_gt *gt) 959 { 960 bool result; 961 962 mutex_lock(>->reset.mutex); 963 result = __intel_gt_unset_wedged(gt); 964 mutex_unlock(>->reset.mutex); 965 966 return result; 967 } 968 969 static int do_reset(struct intel_gt *gt, intel_engine_mask_t stalled_mask) 970 { 971 int err, i; 972 973 gt_revoke(gt); 974 975 err = __intel_gt_reset(gt, ALL_ENGINES); 976 for (i = 0; err && i < RESET_MAX_RETRIES; i++) { 977 msleep(10 * (i + 1)); 978 err = __intel_gt_reset(gt, ALL_ENGINES); 979 } 980 if (err) 981 return err; 982 983 return gt_reset(gt, stalled_mask); 984 } 985 986 static int resume(struct intel_gt *gt) 987 { 988 struct intel_engine_cs *engine; 989 enum intel_engine_id id; 990 int ret; 991 992 for_each_engine(engine, gt, id) { 993 ret = intel_engine_resume(engine); 994 if (ret) 995 return ret; 996 } 997 998 return 0; 999 } 1000 1001 /** 1002 * intel_gt_reset - reset chip after a hang 1003 * @gt: #intel_gt to reset 1004 * @stalled_mask: mask of the stalled engines with the guilty requests 1005 * @reason: user error message for why we are resetting 1006 * 1007 * Reset the chip. Useful if a hang is detected. Marks the device as wedged 1008 * on failure. 1009 * 1010 * Procedure is fairly simple: 1011 * - reset the chip using the reset reg 1012 * - re-init context state 1013 * - re-init hardware status page 1014 * - re-init ring buffer 1015 * - re-init interrupt state 1016 * - re-init display 1017 */ 1018 void intel_gt_reset(struct intel_gt *gt, 1019 intel_engine_mask_t stalled_mask, 1020 const char *reason) 1021 { 1022 intel_engine_mask_t awake; 1023 int ret; 1024 1025 GT_TRACE(gt, "flags=%lx\n", gt->reset.flags); 1026 1027 might_sleep(); 1028 GEM_BUG_ON(!test_bit(I915_RESET_BACKOFF, >->reset.flags)); 1029 mutex_lock(>->reset.mutex); 1030 1031 /* Clear any previous failed attempts at recovery. Time to try again. */ 1032 if (!__intel_gt_unset_wedged(gt)) 1033 goto unlock; 1034 1035 if (reason) 1036 drm_notice(>->i915->drm, 1037 "Resetting chip for %s\n", reason); 1038 atomic_inc(>->i915->gpu_error.reset_count); 1039 1040 awake = reset_prepare(gt); 1041 1042 if (!intel_has_gpu_reset(gt)) { 1043 if (gt->i915->params.reset) 1044 drm_err(>->i915->drm, "GPU reset not supported\n"); 1045 else 1046 drm_dbg(>->i915->drm, "GPU reset disabled\n"); 1047 goto error; 1048 } 1049 1050 if (INTEL_INFO(gt->i915)->gpu_reset_clobbers_display) 1051 intel_runtime_pm_disable_interrupts(gt->i915); 1052 1053 if (do_reset(gt, stalled_mask)) { 1054 drm_err(>->i915->drm, "Failed to reset chip\n"); 1055 goto taint; 1056 } 1057 1058 if (INTEL_INFO(gt->i915)->gpu_reset_clobbers_display) 1059 intel_runtime_pm_enable_interrupts(gt->i915); 1060 1061 intel_overlay_reset(gt->i915); 1062 1063 /* 1064 * Next we need to restore the context, but we don't use those 1065 * yet either... 1066 * 1067 * Ring buffer needs to be re-initialized in the KMS case, or if X 1068 * was running at the time of the reset (i.e. we weren't VT 1069 * switched away). 1070 */ 1071 ret = intel_gt_init_hw(gt); 1072 if (ret) { 1073 drm_err(>->i915->drm, 1074 "Failed to initialise HW following reset (%d)\n", 1075 ret); 1076 goto taint; 1077 } 1078 1079 ret = resume(gt); 1080 if (ret) 1081 goto taint; 1082 1083 finish: 1084 reset_finish(gt, awake); 1085 unlock: 1086 mutex_unlock(>->reset.mutex); 1087 return; 1088 1089 taint: 1090 /* 1091 * History tells us that if we cannot reset the GPU now, we 1092 * never will. This then impacts everything that is run 1093 * subsequently. On failing the reset, we mark the driver 1094 * as wedged, preventing further execution on the GPU. 1095 * We also want to go one step further and add a taint to the 1096 * kernel so that any subsequent faults can be traced back to 1097 * this failure. This is important for CI, where if the 1098 * GPU/driver fails we would like to reboot and restart testing 1099 * rather than continue on into oblivion. For everyone else, 1100 * the system should still plod along, but they have been warned! 1101 */ 1102 add_taint_for_CI(gt->i915, TAINT_WARN); 1103 error: 1104 __intel_gt_set_wedged(gt); 1105 goto finish; 1106 } 1107 1108 static inline int intel_gt_reset_engine(struct intel_engine_cs *engine) 1109 { 1110 return __intel_gt_reset(engine->gt, engine->mask); 1111 } 1112 1113 /** 1114 * intel_engine_reset - reset GPU engine to recover from a hang 1115 * @engine: engine to reset 1116 * @msg: reason for GPU reset; or NULL for no drm_notice() 1117 * 1118 * Reset a specific GPU engine. Useful if a hang is detected. 1119 * Returns zero on successful reset or otherwise an error code. 1120 * 1121 * Procedure is: 1122 * - identifies the request that caused the hang and it is dropped 1123 * - reset engine (which will force the engine to idle) 1124 * - re-init/configure engine 1125 */ 1126 int intel_engine_reset(struct intel_engine_cs *engine, const char *msg) 1127 { 1128 struct intel_gt *gt = engine->gt; 1129 bool uses_guc = intel_engine_in_guc_submission_mode(engine); 1130 int ret; 1131 1132 ENGINE_TRACE(engine, "flags=%lx\n", gt->reset.flags); 1133 GEM_BUG_ON(!test_bit(I915_RESET_ENGINE + engine->id, >->reset.flags)); 1134 1135 if (!intel_engine_pm_get_if_awake(engine)) 1136 return 0; 1137 1138 reset_prepare_engine(engine); 1139 1140 if (msg) 1141 drm_notice(&engine->i915->drm, 1142 "Resetting %s for %s\n", engine->name, msg); 1143 atomic_inc(&engine->i915->gpu_error.reset_engine_count[engine->uabi_class]); 1144 1145 if (!uses_guc) 1146 ret = intel_gt_reset_engine(engine); 1147 else 1148 ret = intel_guc_reset_engine(&engine->gt->uc.guc, engine); 1149 if (ret) { 1150 /* If we fail here, we expect to fallback to a global reset */ 1151 drm_dbg(>->i915->drm, "%sFailed to reset %s, ret=%d\n", 1152 uses_guc ? "GuC " : "", engine->name, ret); 1153 goto out; 1154 } 1155 1156 /* 1157 * The request that caused the hang is stuck on elsp, we know the 1158 * active request and can drop it, adjust head to skip the offending 1159 * request to resume executing remaining requests in the queue. 1160 */ 1161 __intel_engine_reset(engine, true); 1162 1163 /* 1164 * The engine and its registers (and workarounds in case of render) 1165 * have been reset to their default values. Follow the init_ring 1166 * process to program RING_MODE, HWSP and re-enable submission. 1167 */ 1168 ret = intel_engine_resume(engine); 1169 1170 out: 1171 intel_engine_cancel_stop_cs(engine); 1172 reset_finish_engine(engine); 1173 intel_engine_pm_put_async(engine); 1174 return ret; 1175 } 1176 1177 static void intel_gt_reset_global(struct intel_gt *gt, 1178 u32 engine_mask, 1179 const char *reason) 1180 { 1181 struct kobject *kobj = >->i915->drm.primary->kdev->kobj; 1182 char *error_event[] = { I915_ERROR_UEVENT "=1", NULL }; 1183 char *reset_event[] = { I915_RESET_UEVENT "=1", NULL }; 1184 char *reset_done_event[] = { I915_ERROR_UEVENT "=0", NULL }; 1185 struct intel_wedge_me w; 1186 1187 kobject_uevent_env(kobj, KOBJ_CHANGE, error_event); 1188 1189 drm_dbg(>->i915->drm, "resetting chip, engines=%x\n", engine_mask); 1190 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_event); 1191 1192 /* Use a watchdog to ensure that our reset completes */ 1193 intel_wedge_on_timeout(&w, gt, 5 * HZ) { 1194 intel_display_prepare_reset(gt->i915); 1195 1196 /* Flush everyone using a resource about to be clobbered */ 1197 synchronize_srcu_expedited(>->reset.backoff_srcu); 1198 1199 intel_gt_reset(gt, engine_mask, reason); 1200 1201 intel_display_finish_reset(gt->i915); 1202 } 1203 1204 if (!test_bit(I915_WEDGED, >->reset.flags)) 1205 kobject_uevent_env(kobj, KOBJ_CHANGE, reset_done_event); 1206 } 1207 1208 /** 1209 * intel_gt_handle_error - handle a gpu error 1210 * @gt: the intel_gt 1211 * @engine_mask: mask representing engines that are hung 1212 * @flags: control flags 1213 * @fmt: Error message format string 1214 * 1215 * Do some basic checking of register state at error time and 1216 * dump it to the syslog. Also call i915_capture_error_state() to make 1217 * sure we get a record and make it available in debugfs. Fire a uevent 1218 * so userspace knows something bad happened (should trigger collection 1219 * of a ring dump etc.). 1220 */ 1221 void intel_gt_handle_error(struct intel_gt *gt, 1222 intel_engine_mask_t engine_mask, 1223 unsigned long flags, 1224 const char *fmt, ...) 1225 { 1226 struct intel_engine_cs *engine; 1227 intel_wakeref_t wakeref; 1228 intel_engine_mask_t tmp; 1229 char error_msg[80]; 1230 char *msg = NULL; 1231 1232 if (fmt) { 1233 va_list args; 1234 1235 va_start(args, fmt); 1236 vscnprintf(error_msg, sizeof(error_msg), fmt, args); 1237 va_end(args); 1238 1239 msg = error_msg; 1240 } 1241 1242 /* 1243 * In most cases it's guaranteed that we get here with an RPM 1244 * reference held, for example because there is a pending GPU 1245 * request that won't finish until the reset is done. This 1246 * isn't the case at least when we get here by doing a 1247 * simulated reset via debugfs, so get an RPM reference. 1248 */ 1249 wakeref = intel_runtime_pm_get(gt->uncore->rpm); 1250 1251 engine_mask &= gt->info.engine_mask; 1252 1253 if (flags & I915_ERROR_CAPTURE) { 1254 i915_capture_error_state(gt, engine_mask); 1255 intel_gt_clear_error_registers(gt, engine_mask); 1256 } 1257 1258 /* 1259 * Try engine reset when available. We fall back to full reset if 1260 * single reset fails. 1261 */ 1262 if (intel_has_reset_engine(gt) && !intel_gt_is_wedged(gt)) { 1263 for_each_engine_masked(engine, gt, engine_mask, tmp) { 1264 BUILD_BUG_ON(I915_RESET_MODESET >= I915_RESET_ENGINE); 1265 if (test_and_set_bit(I915_RESET_ENGINE + engine->id, 1266 >->reset.flags)) 1267 continue; 1268 1269 if (intel_engine_reset(engine, msg) == 0) 1270 engine_mask &= ~engine->mask; 1271 1272 clear_and_wake_up_bit(I915_RESET_ENGINE + engine->id, 1273 >->reset.flags); 1274 } 1275 } 1276 1277 if (!engine_mask) 1278 goto out; 1279 1280 /* Full reset needs the mutex, stop any other user trying to do so. */ 1281 if (test_and_set_bit(I915_RESET_BACKOFF, >->reset.flags)) { 1282 wait_event(gt->reset.queue, 1283 !test_bit(I915_RESET_BACKOFF, >->reset.flags)); 1284 goto out; /* piggy-back on the other reset */ 1285 } 1286 1287 /* Make sure i915_reset_trylock() sees the I915_RESET_BACKOFF */ 1288 synchronize_rcu_expedited(); 1289 1290 /* Prevent any other reset-engine attempt. */ 1291 for_each_engine(engine, gt, tmp) { 1292 while (test_and_set_bit(I915_RESET_ENGINE + engine->id, 1293 >->reset.flags)) 1294 wait_on_bit(>->reset.flags, 1295 I915_RESET_ENGINE + engine->id, 1296 TASK_UNINTERRUPTIBLE); 1297 } 1298 1299 intel_gt_reset_global(gt, engine_mask, msg); 1300 1301 for_each_engine(engine, gt, tmp) 1302 clear_bit_unlock(I915_RESET_ENGINE + engine->id, 1303 >->reset.flags); 1304 clear_bit_unlock(I915_RESET_BACKOFF, >->reset.flags); 1305 smp_mb__after_atomic(); 1306 wake_up_all(>->reset.queue); 1307 1308 out: 1309 intel_runtime_pm_put(gt->uncore->rpm, wakeref); 1310 } 1311 1312 int intel_gt_reset_trylock(struct intel_gt *gt, int *srcu) 1313 { 1314 might_lock(>->reset.backoff_srcu); 1315 might_sleep(); 1316 1317 rcu_read_lock(); 1318 while (test_bit(I915_RESET_BACKOFF, >->reset.flags)) { 1319 rcu_read_unlock(); 1320 1321 if (wait_event_interruptible(gt->reset.queue, 1322 !test_bit(I915_RESET_BACKOFF, 1323 >->reset.flags))) 1324 return -EINTR; 1325 1326 rcu_read_lock(); 1327 } 1328 *srcu = srcu_read_lock(>->reset.backoff_srcu); 1329 rcu_read_unlock(); 1330 1331 return 0; 1332 } 1333 1334 void intel_gt_reset_unlock(struct intel_gt *gt, int tag) 1335 __releases(>->reset.backoff_srcu) 1336 { 1337 srcu_read_unlock(>->reset.backoff_srcu, tag); 1338 } 1339 1340 int intel_gt_terminally_wedged(struct intel_gt *gt) 1341 { 1342 might_sleep(); 1343 1344 if (!intel_gt_is_wedged(gt)) 1345 return 0; 1346 1347 if (intel_gt_has_unrecoverable_error(gt)) 1348 return -EIO; 1349 1350 /* Reset still in progress? Maybe we will recover? */ 1351 if (wait_event_interruptible(gt->reset.queue, 1352 !test_bit(I915_RESET_BACKOFF, 1353 >->reset.flags))) 1354 return -EINTR; 1355 1356 return intel_gt_is_wedged(gt) ? -EIO : 0; 1357 } 1358 1359 void intel_gt_set_wedged_on_init(struct intel_gt *gt) 1360 { 1361 BUILD_BUG_ON(I915_RESET_ENGINE + I915_NUM_ENGINES > 1362 I915_WEDGED_ON_INIT); 1363 intel_gt_set_wedged(gt); 1364 set_bit(I915_WEDGED_ON_INIT, >->reset.flags); 1365 1366 /* Wedged on init is non-recoverable */ 1367 add_taint_for_CI(gt->i915, TAINT_WARN); 1368 } 1369 1370 void intel_gt_set_wedged_on_fini(struct intel_gt *gt) 1371 { 1372 intel_gt_set_wedged(gt); 1373 set_bit(I915_WEDGED_ON_FINI, >->reset.flags); 1374 intel_gt_retire_requests(gt); /* cleanup any wedged requests */ 1375 } 1376 1377 void intel_gt_init_reset(struct intel_gt *gt) 1378 { 1379 init_waitqueue_head(>->reset.queue); 1380 mutex_init(>->reset.mutex); 1381 init_srcu_struct(>->reset.backoff_srcu); 1382 1383 /* no GPU until we are ready! */ 1384 __set_bit(I915_WEDGED, >->reset.flags); 1385 } 1386 1387 void intel_gt_fini_reset(struct intel_gt *gt) 1388 { 1389 cleanup_srcu_struct(>->reset.backoff_srcu); 1390 } 1391 1392 static void intel_wedge_me(struct work_struct *work) 1393 { 1394 struct intel_wedge_me *w = container_of(work, typeof(*w), work.work); 1395 1396 drm_err(&w->gt->i915->drm, 1397 "%s timed out, cancelling all in-flight rendering.\n", 1398 w->name); 1399 intel_gt_set_wedged(w->gt); 1400 } 1401 1402 void __intel_init_wedge(struct intel_wedge_me *w, 1403 struct intel_gt *gt, 1404 long timeout, 1405 const char *name) 1406 { 1407 w->gt = gt; 1408 w->name = name; 1409 1410 INIT_DELAYED_WORK_ONSTACK(&w->work, intel_wedge_me); 1411 schedule_delayed_work(&w->work, timeout); 1412 } 1413 1414 void __intel_fini_wedge(struct intel_wedge_me *w) 1415 { 1416 cancel_delayed_work_sync(&w->work); 1417 destroy_delayed_work_on_stack(&w->work); 1418 w->gt = NULL; 1419 } 1420 1421 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST) 1422 #include "selftest_reset.c" 1423 #include "selftest_hangcheck.c" 1424 #endif 1425