1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2016-2019 Intel Corporation 4 */ 5 6 #include <linux/string_helpers.h> 7 8 #include "gt/intel_gt.h" 9 #include "gt/intel_gt_print.h" 10 #include "gt/intel_reset.h" 11 #include "intel_gsc_fw.h" 12 #include "intel_gsc_uc.h" 13 #include "intel_guc.h" 14 #include "intel_guc_ads.h" 15 #include "intel_guc_print.h" 16 #include "intel_guc_submission.h" 17 #include "gt/intel_rps.h" 18 #include "intel_uc.h" 19 20 #include "i915_drv.h" 21 22 static const struct intel_uc_ops uc_ops_off; 23 static const struct intel_uc_ops uc_ops_on; 24 25 static void uc_expand_default_options(struct intel_uc *uc) 26 { 27 struct drm_i915_private *i915 = uc_to_gt(uc)->i915; 28 29 if (i915->params.enable_guc != -1) 30 return; 31 32 /* Don't enable GuC/HuC on pre-Gen12 */ 33 if (GRAPHICS_VER(i915) < 12) { 34 i915->params.enable_guc = 0; 35 return; 36 } 37 38 /* Don't enable GuC/HuC on older Gen12 platforms */ 39 if (IS_TIGERLAKE(i915) || IS_ROCKETLAKE(i915)) { 40 i915->params.enable_guc = 0; 41 return; 42 } 43 44 /* Intermediate platforms are HuC authentication only */ 45 if (IS_ALDERLAKE_S(i915) && !IS_ADLS_RPLS(i915)) { 46 i915->params.enable_guc = ENABLE_GUC_LOAD_HUC; 47 return; 48 } 49 50 /* Default: enable HuC authentication and GuC submission */ 51 i915->params.enable_guc = ENABLE_GUC_LOAD_HUC | ENABLE_GUC_SUBMISSION; 52 53 /* XEHPSDV and PVC do not use HuC */ 54 if (IS_XEHPSDV(i915) || IS_PONTEVECCHIO(i915)) 55 i915->params.enable_guc &= ~ENABLE_GUC_LOAD_HUC; 56 } 57 58 /* Reset GuC providing us with fresh state for both GuC and HuC. 59 */ 60 static int __intel_uc_reset_hw(struct intel_uc *uc) 61 { 62 struct intel_gt *gt = uc_to_gt(uc); 63 int ret; 64 u32 guc_status; 65 66 ret = i915_inject_probe_error(gt->i915, -ENXIO); 67 if (ret) 68 return ret; 69 70 ret = intel_reset_guc(gt); 71 if (ret) { 72 gt_err(gt, "Failed to reset GuC, ret = %d\n", ret); 73 return ret; 74 } 75 76 guc_status = intel_uncore_read(gt->uncore, GUC_STATUS); 77 gt_WARN(gt, !(guc_status & GS_MIA_IN_RESET), 78 "GuC status: 0x%x, MIA core expected to be in reset\n", 79 guc_status); 80 81 return ret; 82 } 83 84 static void __confirm_options(struct intel_uc *uc) 85 { 86 struct intel_gt *gt = uc_to_gt(uc); 87 struct drm_i915_private *i915 = gt->i915; 88 89 gt_dbg(gt, "enable_guc=%d (guc:%s submission:%s huc:%s slpc:%s)\n", 90 i915->params.enable_guc, 91 str_yes_no(intel_uc_wants_guc(uc)), 92 str_yes_no(intel_uc_wants_guc_submission(uc)), 93 str_yes_no(intel_uc_wants_huc(uc)), 94 str_yes_no(intel_uc_wants_guc_slpc(uc))); 95 96 if (i915->params.enable_guc == 0) { 97 GEM_BUG_ON(intel_uc_wants_guc(uc)); 98 GEM_BUG_ON(intel_uc_wants_guc_submission(uc)); 99 GEM_BUG_ON(intel_uc_wants_huc(uc)); 100 GEM_BUG_ON(intel_uc_wants_guc_slpc(uc)); 101 return; 102 } 103 104 if (!intel_uc_supports_guc(uc)) 105 gt_info(gt, "Incompatible option enable_guc=%d - %s\n", 106 i915->params.enable_guc, "GuC is not supported!"); 107 108 if (i915->params.enable_guc & ENABLE_GUC_LOAD_HUC && 109 !intel_uc_supports_huc(uc)) 110 gt_info(gt, "Incompatible option enable_guc=%d - %s\n", 111 i915->params.enable_guc, "HuC is not supported!"); 112 113 if (i915->params.enable_guc & ENABLE_GUC_SUBMISSION && 114 !intel_uc_supports_guc_submission(uc)) 115 gt_info(gt, "Incompatible option enable_guc=%d - %s\n", 116 i915->params.enable_guc, "GuC submission is N/A"); 117 118 if (i915->params.enable_guc & ~ENABLE_GUC_MASK) 119 gt_info(gt, "Incompatible option enable_guc=%d - %s\n", 120 i915->params.enable_guc, "undocumented flag"); 121 } 122 123 void intel_uc_init_early(struct intel_uc *uc) 124 { 125 uc_expand_default_options(uc); 126 127 intel_guc_init_early(&uc->guc); 128 intel_huc_init_early(&uc->huc); 129 intel_gsc_uc_init_early(&uc->gsc); 130 131 __confirm_options(uc); 132 133 if (intel_uc_wants_guc(uc)) 134 uc->ops = &uc_ops_on; 135 else 136 uc->ops = &uc_ops_off; 137 } 138 139 void intel_uc_init_late(struct intel_uc *uc) 140 { 141 intel_guc_init_late(&uc->guc); 142 } 143 144 void intel_uc_driver_late_release(struct intel_uc *uc) 145 { 146 } 147 148 /** 149 * intel_uc_init_mmio - setup uC MMIO access 150 * @uc: the intel_uc structure 151 * 152 * Setup minimal state necessary for MMIO accesses later in the 153 * initialization sequence. 154 */ 155 void intel_uc_init_mmio(struct intel_uc *uc) 156 { 157 intel_guc_init_send_regs(&uc->guc); 158 } 159 160 static void __uc_capture_load_err_log(struct intel_uc *uc) 161 { 162 struct intel_guc *guc = &uc->guc; 163 164 if (guc->log.vma && !uc->load_err_log) 165 uc->load_err_log = i915_gem_object_get(guc->log.vma->obj); 166 } 167 168 static void __uc_free_load_err_log(struct intel_uc *uc) 169 { 170 struct drm_i915_gem_object *log = fetch_and_zero(&uc->load_err_log); 171 172 if (log) 173 i915_gem_object_put(log); 174 } 175 176 void intel_uc_driver_remove(struct intel_uc *uc) 177 { 178 intel_uc_fini_hw(uc); 179 intel_uc_fini(uc); 180 __uc_free_load_err_log(uc); 181 } 182 183 /* 184 * Events triggered while CT buffers are disabled are logged in the SCRATCH_15 185 * register using the same bits used in the CT message payload. Since our 186 * communication channel with guc is turned off at this point, we can save the 187 * message and handle it after we turn it back on. 188 */ 189 static void guc_clear_mmio_msg(struct intel_guc *guc) 190 { 191 intel_uncore_write(guc_to_gt(guc)->uncore, SOFT_SCRATCH(15), 0); 192 } 193 194 static void guc_get_mmio_msg(struct intel_guc *guc) 195 { 196 u32 val; 197 198 spin_lock_irq(&guc->irq_lock); 199 200 val = intel_uncore_read(guc_to_gt(guc)->uncore, SOFT_SCRATCH(15)); 201 guc->mmio_msg |= val & guc->msg_enabled_mask; 202 203 /* 204 * clear all events, including the ones we're not currently servicing, 205 * to make sure we don't try to process a stale message if we enable 206 * handling of more events later. 207 */ 208 guc_clear_mmio_msg(guc); 209 210 spin_unlock_irq(&guc->irq_lock); 211 } 212 213 static void guc_handle_mmio_msg(struct intel_guc *guc) 214 { 215 /* we need communication to be enabled to reply to GuC */ 216 GEM_BUG_ON(!intel_guc_ct_enabled(&guc->ct)); 217 218 spin_lock_irq(&guc->irq_lock); 219 if (guc->mmio_msg) { 220 intel_guc_to_host_process_recv_msg(guc, &guc->mmio_msg, 1); 221 guc->mmio_msg = 0; 222 } 223 spin_unlock_irq(&guc->irq_lock); 224 } 225 226 static int guc_enable_communication(struct intel_guc *guc) 227 { 228 struct intel_gt *gt = guc_to_gt(guc); 229 struct drm_i915_private *i915 = gt->i915; 230 int ret; 231 232 GEM_BUG_ON(intel_guc_ct_enabled(&guc->ct)); 233 234 ret = i915_inject_probe_error(i915, -ENXIO); 235 if (ret) 236 return ret; 237 238 ret = intel_guc_ct_enable(&guc->ct); 239 if (ret) 240 return ret; 241 242 /* check for mmio messages received before/during the CT enable */ 243 guc_get_mmio_msg(guc); 244 guc_handle_mmio_msg(guc); 245 246 intel_guc_enable_interrupts(guc); 247 248 /* check for CT messages received before we enabled interrupts */ 249 spin_lock_irq(gt->irq_lock); 250 intel_guc_ct_event_handler(&guc->ct); 251 spin_unlock_irq(gt->irq_lock); 252 253 guc_dbg(guc, "communication enabled\n"); 254 255 return 0; 256 } 257 258 static void guc_disable_communication(struct intel_guc *guc) 259 { 260 /* 261 * Events generated during or after CT disable are logged by guc in 262 * via mmio. Make sure the register is clear before disabling CT since 263 * all events we cared about have already been processed via CT. 264 */ 265 guc_clear_mmio_msg(guc); 266 267 intel_guc_disable_interrupts(guc); 268 269 intel_guc_ct_disable(&guc->ct); 270 271 /* 272 * Check for messages received during/after the CT disable. We do not 273 * expect any messages to have arrived via CT between the interrupt 274 * disable and the CT disable because GuC should've been idle until we 275 * triggered the CT disable protocol. 276 */ 277 guc_get_mmio_msg(guc); 278 279 guc_dbg(guc, "communication disabled\n"); 280 } 281 282 static void __uc_fetch_firmwares(struct intel_uc *uc) 283 { 284 struct intel_gt *gt = uc_to_gt(uc); 285 int err; 286 287 GEM_BUG_ON(!intel_uc_wants_guc(uc)); 288 289 err = intel_uc_fw_fetch(&uc->guc.fw); 290 if (err) { 291 /* Make sure we transition out of transient "SELECTED" state */ 292 if (intel_uc_wants_huc(uc)) { 293 gt_dbg(gt, "Failed to fetch GuC fw (%pe) disabling HuC\n", ERR_PTR(err)); 294 intel_uc_fw_change_status(&uc->huc.fw, 295 INTEL_UC_FIRMWARE_ERROR); 296 } 297 298 if (intel_uc_wants_gsc_uc(uc)) { 299 gt_dbg(gt, "Failed to fetch GuC fw (%pe) disabling GSC\n", ERR_PTR(err)); 300 intel_uc_fw_change_status(&uc->gsc.fw, 301 INTEL_UC_FIRMWARE_ERROR); 302 } 303 304 return; 305 } 306 307 if (intel_uc_wants_huc(uc)) 308 intel_uc_fw_fetch(&uc->huc.fw); 309 310 if (intel_uc_wants_gsc_uc(uc)) 311 intel_uc_fw_fetch(&uc->gsc.fw); 312 } 313 314 static void __uc_cleanup_firmwares(struct intel_uc *uc) 315 { 316 intel_uc_fw_cleanup_fetch(&uc->gsc.fw); 317 intel_uc_fw_cleanup_fetch(&uc->huc.fw); 318 intel_uc_fw_cleanup_fetch(&uc->guc.fw); 319 } 320 321 static int __uc_init(struct intel_uc *uc) 322 { 323 struct intel_guc *guc = &uc->guc; 324 struct intel_huc *huc = &uc->huc; 325 int ret; 326 327 GEM_BUG_ON(!intel_uc_wants_guc(uc)); 328 329 if (!intel_uc_uses_guc(uc)) 330 return 0; 331 332 if (i915_inject_probe_failure(uc_to_gt(uc)->i915)) 333 return -ENOMEM; 334 335 ret = intel_guc_init(guc); 336 if (ret) 337 return ret; 338 339 if (intel_uc_uses_huc(uc)) 340 intel_huc_init(huc); 341 342 if (intel_uc_uses_gsc_uc(uc)) 343 intel_gsc_uc_init(&uc->gsc); 344 345 return 0; 346 } 347 348 static void __uc_fini(struct intel_uc *uc) 349 { 350 intel_gsc_uc_fini(&uc->gsc); 351 intel_huc_fini(&uc->huc); 352 intel_guc_fini(&uc->guc); 353 } 354 355 static int __uc_sanitize(struct intel_uc *uc) 356 { 357 struct intel_guc *guc = &uc->guc; 358 struct intel_huc *huc = &uc->huc; 359 360 GEM_BUG_ON(!intel_uc_supports_guc(uc)); 361 362 intel_huc_sanitize(huc); 363 intel_guc_sanitize(guc); 364 365 return __intel_uc_reset_hw(uc); 366 } 367 368 /* Initialize and verify the uC regs related to uC positioning in WOPCM */ 369 static int uc_init_wopcm(struct intel_uc *uc) 370 { 371 struct intel_gt *gt = uc_to_gt(uc); 372 struct intel_uncore *uncore = gt->uncore; 373 u32 base = intel_wopcm_guc_base(>->wopcm); 374 u32 size = intel_wopcm_guc_size(>->wopcm); 375 u32 huc_agent = intel_uc_uses_huc(uc) ? HUC_LOADING_AGENT_GUC : 0; 376 u32 mask; 377 int err; 378 379 if (unlikely(!base || !size)) { 380 gt_probe_error(gt, "Unsuccessful WOPCM partitioning\n"); 381 return -E2BIG; 382 } 383 384 GEM_BUG_ON(!intel_uc_supports_guc(uc)); 385 GEM_BUG_ON(!(base & GUC_WOPCM_OFFSET_MASK)); 386 GEM_BUG_ON(base & ~GUC_WOPCM_OFFSET_MASK); 387 GEM_BUG_ON(!(size & GUC_WOPCM_SIZE_MASK)); 388 GEM_BUG_ON(size & ~GUC_WOPCM_SIZE_MASK); 389 390 err = i915_inject_probe_error(gt->i915, -ENXIO); 391 if (err) 392 return err; 393 394 mask = GUC_WOPCM_SIZE_MASK | GUC_WOPCM_SIZE_LOCKED; 395 err = intel_uncore_write_and_verify(uncore, GUC_WOPCM_SIZE, size, mask, 396 size | GUC_WOPCM_SIZE_LOCKED); 397 if (err) 398 goto err_out; 399 400 mask = GUC_WOPCM_OFFSET_MASK | GUC_WOPCM_OFFSET_VALID | huc_agent; 401 err = intel_uncore_write_and_verify(uncore, DMA_GUC_WOPCM_OFFSET, 402 base | huc_agent, mask, 403 base | huc_agent | 404 GUC_WOPCM_OFFSET_VALID); 405 if (err) 406 goto err_out; 407 408 return 0; 409 410 err_out: 411 gt_probe_error(gt, "Failed to init uC WOPCM registers!\n"); 412 gt_probe_error(gt, "%s(%#x)=%#x\n", "DMA_GUC_WOPCM_OFFSET", 413 i915_mmio_reg_offset(DMA_GUC_WOPCM_OFFSET), 414 intel_uncore_read(uncore, DMA_GUC_WOPCM_OFFSET)); 415 gt_probe_error(gt, "%s(%#x)=%#x\n", "GUC_WOPCM_SIZE", 416 i915_mmio_reg_offset(GUC_WOPCM_SIZE), 417 intel_uncore_read(uncore, GUC_WOPCM_SIZE)); 418 419 return err; 420 } 421 422 static bool uc_is_wopcm_locked(struct intel_uc *uc) 423 { 424 struct intel_gt *gt = uc_to_gt(uc); 425 struct intel_uncore *uncore = gt->uncore; 426 427 return (intel_uncore_read(uncore, GUC_WOPCM_SIZE) & GUC_WOPCM_SIZE_LOCKED) || 428 (intel_uncore_read(uncore, DMA_GUC_WOPCM_OFFSET) & GUC_WOPCM_OFFSET_VALID); 429 } 430 431 static int __uc_check_hw(struct intel_uc *uc) 432 { 433 if (!intel_uc_supports_guc(uc)) 434 return 0; 435 436 /* 437 * We can silently continue without GuC only if it was never enabled 438 * before on this system after reboot, otherwise we risk GPU hangs. 439 * To check if GuC was loaded before we look at WOPCM registers. 440 */ 441 if (uc_is_wopcm_locked(uc)) 442 return -EIO; 443 444 return 0; 445 } 446 447 static void print_fw_ver(struct intel_gt *gt, struct intel_uc_fw *fw) 448 { 449 gt_info(gt, "%s firmware %s version %u.%u.%u\n", 450 intel_uc_fw_type_repr(fw->type), fw->file_selected.path, 451 fw->file_selected.ver.major, 452 fw->file_selected.ver.minor, 453 fw->file_selected.ver.patch); 454 } 455 456 static int __uc_init_hw(struct intel_uc *uc) 457 { 458 struct intel_gt *gt = uc_to_gt(uc); 459 struct drm_i915_private *i915 = gt->i915; 460 struct intel_guc *guc = &uc->guc; 461 struct intel_huc *huc = &uc->huc; 462 int ret, attempts; 463 464 GEM_BUG_ON(!intel_uc_supports_guc(uc)); 465 GEM_BUG_ON(!intel_uc_wants_guc(uc)); 466 467 print_fw_ver(gt, &guc->fw); 468 469 if (intel_uc_uses_huc(uc)) 470 print_fw_ver(gt, &huc->fw); 471 472 if (!intel_uc_fw_is_loadable(&guc->fw)) { 473 ret = __uc_check_hw(uc) || 474 intel_uc_fw_is_overridden(&guc->fw) || 475 intel_uc_wants_guc_submission(uc) ? 476 intel_uc_fw_status_to_error(guc->fw.status) : 0; 477 goto err_out; 478 } 479 480 ret = uc_init_wopcm(uc); 481 if (ret) 482 goto err_out; 483 484 intel_guc_reset_interrupts(guc); 485 486 /* WaEnableuKernelHeaderValidFix:skl */ 487 /* WaEnableGuCBootHashCheckNotSet:skl,bxt,kbl */ 488 if (GRAPHICS_VER(i915) == 9) 489 attempts = 3; 490 else 491 attempts = 1; 492 493 intel_rps_raise_unslice(&uc_to_gt(uc)->rps); 494 495 while (attempts--) { 496 /* 497 * Always reset the GuC just before (re)loading, so 498 * that the state and timing are fairly predictable 499 */ 500 ret = __uc_sanitize(uc); 501 if (ret) 502 goto err_out; 503 504 intel_huc_fw_upload(huc); 505 intel_guc_ads_reset(guc); 506 intel_guc_write_params(guc); 507 ret = intel_guc_fw_upload(guc); 508 if (ret == 0) 509 break; 510 511 gt_dbg(gt, "GuC fw load failed (%pe) will reset and retry %d more time(s)\n", 512 ERR_PTR(ret), attempts); 513 } 514 515 /* Did we succeded or run out of retries? */ 516 if (ret) 517 goto err_log_capture; 518 519 ret = guc_enable_communication(guc); 520 if (ret) 521 goto err_log_capture; 522 523 /* 524 * GSC-loaded HuC is authenticated by the GSC, so we don't need to 525 * trigger the auth here. However, given that the HuC loaded this way 526 * survive GT reset, we still need to update our SW bookkeeping to make 527 * sure it reflects the correct HW status. 528 */ 529 if (intel_huc_is_loaded_by_gsc(huc)) 530 intel_huc_update_auth_status(huc); 531 else 532 intel_huc_auth(huc); 533 534 if (intel_uc_uses_guc_submission(uc)) 535 intel_guc_submission_enable(guc); 536 537 if (intel_uc_uses_guc_slpc(uc)) { 538 ret = intel_guc_slpc_enable(&guc->slpc); 539 if (ret) 540 goto err_submission; 541 } else { 542 /* Restore GT back to RPn for non-SLPC path */ 543 intel_rps_lower_unslice(&uc_to_gt(uc)->rps); 544 } 545 546 intel_gsc_uc_load_start(&uc->gsc); 547 548 guc_info(guc, "submission %s\n", str_enabled_disabled(intel_uc_uses_guc_submission(uc))); 549 guc_info(guc, "SLPC %s\n", str_enabled_disabled(intel_uc_uses_guc_slpc(uc))); 550 551 return 0; 552 553 /* 554 * We've failed to load the firmware :( 555 */ 556 err_submission: 557 intel_guc_submission_disable(guc); 558 err_log_capture: 559 __uc_capture_load_err_log(uc); 560 err_out: 561 /* Return GT back to RPn */ 562 intel_rps_lower_unslice(&uc_to_gt(uc)->rps); 563 564 __uc_sanitize(uc); 565 566 if (!ret) { 567 gt_notice(gt, "GuC is uninitialized\n"); 568 /* We want to run without GuC submission */ 569 return 0; 570 } 571 572 gt_probe_error(gt, "GuC initialization failed %pe\n", ERR_PTR(ret)); 573 574 /* We want to keep KMS alive */ 575 return -EIO; 576 } 577 578 static void __uc_fini_hw(struct intel_uc *uc) 579 { 580 struct intel_guc *guc = &uc->guc; 581 582 if (!intel_guc_is_fw_running(guc)) 583 return; 584 585 if (intel_uc_uses_guc_submission(uc)) 586 intel_guc_submission_disable(guc); 587 588 __uc_sanitize(uc); 589 } 590 591 /** 592 * intel_uc_reset_prepare - Prepare for reset 593 * @uc: the intel_uc structure 594 * 595 * Preparing for full gpu reset. 596 */ 597 void intel_uc_reset_prepare(struct intel_uc *uc) 598 { 599 struct intel_guc *guc = &uc->guc; 600 601 uc->reset_in_progress = true; 602 603 /* Nothing to do if GuC isn't supported */ 604 if (!intel_uc_supports_guc(uc)) 605 return; 606 607 /* Firmware expected to be running when this function is called */ 608 if (!intel_guc_is_ready(guc)) 609 goto sanitize; 610 611 if (intel_uc_uses_guc_submission(uc)) 612 intel_guc_submission_reset_prepare(guc); 613 614 sanitize: 615 __uc_sanitize(uc); 616 } 617 618 void intel_uc_reset(struct intel_uc *uc, intel_engine_mask_t stalled) 619 { 620 struct intel_guc *guc = &uc->guc; 621 622 /* Firmware can not be running when this function is called */ 623 if (intel_uc_uses_guc_submission(uc)) 624 intel_guc_submission_reset(guc, stalled); 625 } 626 627 void intel_uc_reset_finish(struct intel_uc *uc) 628 { 629 struct intel_guc *guc = &uc->guc; 630 631 uc->reset_in_progress = false; 632 633 /* Firmware expected to be running when this function is called */ 634 if (intel_guc_is_fw_running(guc) && intel_uc_uses_guc_submission(uc)) 635 intel_guc_submission_reset_finish(guc); 636 } 637 638 void intel_uc_cancel_requests(struct intel_uc *uc) 639 { 640 struct intel_guc *guc = &uc->guc; 641 642 /* Firmware can not be running when this function is called */ 643 if (intel_uc_uses_guc_submission(uc)) 644 intel_guc_submission_cancel_requests(guc); 645 } 646 647 void intel_uc_runtime_suspend(struct intel_uc *uc) 648 { 649 struct intel_guc *guc = &uc->guc; 650 651 if (!intel_guc_is_ready(guc)) { 652 guc->interrupts.enabled = false; 653 return; 654 } 655 656 /* 657 * Wait for any outstanding CTB before tearing down communication /w the 658 * GuC. 659 */ 660 #define OUTSTANDING_CTB_TIMEOUT_PERIOD (HZ / 5) 661 intel_guc_wait_for_pending_msg(guc, &guc->outstanding_submission_g2h, 662 false, OUTSTANDING_CTB_TIMEOUT_PERIOD); 663 GEM_WARN_ON(atomic_read(&guc->outstanding_submission_g2h)); 664 665 guc_disable_communication(guc); 666 } 667 668 void intel_uc_suspend(struct intel_uc *uc) 669 { 670 struct intel_guc *guc = &uc->guc; 671 intel_wakeref_t wakeref; 672 int err; 673 674 /* flush the GSC worker */ 675 intel_gsc_uc_suspend(&uc->gsc); 676 677 if (!intel_guc_is_ready(guc)) { 678 guc->interrupts.enabled = false; 679 return; 680 } 681 682 with_intel_runtime_pm(&uc_to_gt(uc)->i915->runtime_pm, wakeref) { 683 err = intel_guc_suspend(guc); 684 if (err) 685 guc_dbg(guc, "Failed to suspend, %pe", ERR_PTR(err)); 686 } 687 } 688 689 static int __uc_resume(struct intel_uc *uc, bool enable_communication) 690 { 691 struct intel_guc *guc = &uc->guc; 692 struct intel_gt *gt = guc_to_gt(guc); 693 int err; 694 695 if (!intel_guc_is_fw_running(guc)) 696 return 0; 697 698 /* Make sure we enable communication if and only if it's disabled */ 699 GEM_BUG_ON(enable_communication == intel_guc_ct_enabled(&guc->ct)); 700 701 if (enable_communication) 702 guc_enable_communication(guc); 703 704 /* If we are only resuming GuC communication but not reloading 705 * GuC, we need to ensure the ARAT timer interrupt is enabled 706 * again. In case of GuC reload, it is enabled during SLPC enable. 707 */ 708 if (enable_communication && intel_uc_uses_guc_slpc(uc)) 709 intel_guc_pm_intrmsk_enable(gt); 710 711 err = intel_guc_resume(guc); 712 if (err) { 713 guc_dbg(guc, "Failed to resume, %pe", ERR_PTR(err)); 714 return err; 715 } 716 717 return 0; 718 } 719 720 int intel_uc_resume(struct intel_uc *uc) 721 { 722 /* 723 * When coming out of S3/S4 we sanitize and re-init the HW, so 724 * communication is already re-enabled at this point. 725 */ 726 return __uc_resume(uc, false); 727 } 728 729 int intel_uc_runtime_resume(struct intel_uc *uc) 730 { 731 /* 732 * During runtime resume we don't sanitize, so we need to re-init 733 * communication as well. 734 */ 735 return __uc_resume(uc, true); 736 } 737 738 static const struct intel_uc_ops uc_ops_off = { 739 .init_hw = __uc_check_hw, 740 .fini = __uc_fini, /* to clean-up the init_early initialization */ 741 }; 742 743 static const struct intel_uc_ops uc_ops_on = { 744 .sanitize = __uc_sanitize, 745 746 .init_fw = __uc_fetch_firmwares, 747 .fini_fw = __uc_cleanup_firmwares, 748 749 .init = __uc_init, 750 .fini = __uc_fini, 751 752 .init_hw = __uc_init_hw, 753 .fini_hw = __uc_fini_hw, 754 }; 755