1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2022 Intel Corporation 4 */ 5 6 #include "xe_guc.h" 7 8 #include <linux/iopoll.h> 9 #include <drm/drm_managed.h> 10 11 #include <generated/xe_wa_oob.h> 12 13 #include "abi/guc_actions_abi.h" 14 #include "abi/guc_errors_abi.h" 15 #include "regs/xe_gt_regs.h" 16 #include "regs/xe_gtt_defs.h" 17 #include "regs/xe_guc_regs.h" 18 #include "regs/xe_irq_regs.h" 19 #include "xe_bo.h" 20 #include "xe_configfs.h" 21 #include "xe_device.h" 22 #include "xe_force_wake.h" 23 #include "xe_gt.h" 24 #include "xe_gt_printk.h" 25 #include "xe_gt_sriov_vf.h" 26 #include "xe_gt_throttle.h" 27 #include "xe_gt_sriov_pf_migration.h" 28 #include "xe_guc_ads.h" 29 #include "xe_guc_buf.h" 30 #include "xe_guc_capture.h" 31 #include "xe_guc_ct.h" 32 #include "xe_guc_db_mgr.h" 33 #include "xe_guc_engine_activity.h" 34 #include "xe_guc_hwconfig.h" 35 #include "xe_guc_klv_helpers.h" 36 #include "xe_guc_log.h" 37 #include "xe_guc_pc.h" 38 #include "xe_guc_rc.h" 39 #include "xe_guc_relay.h" 40 #include "xe_guc_submit.h" 41 #include "xe_memirq.h" 42 #include "xe_mmio.h" 43 #include "xe_platform_types.h" 44 #include "xe_sleep.h" 45 #include "xe_sriov.h" 46 #include "xe_sriov_pf_migration.h" 47 #include "xe_uc.h" 48 #include "xe_uc_fw.h" 49 #include "xe_wa.h" 50 #include "xe_wopcm.h" 51 52 static u32 guc_bo_ggtt_addr(struct xe_guc *guc, 53 struct xe_bo *bo) 54 { 55 struct xe_device *xe = guc_to_xe(guc); 56 u32 addr; 57 58 /* 59 * For most BOs, the address on the allocating tile is fine. However for 60 * some, e.g. G2G CTB, the address on a specific tile is required as it 61 * might be different for each tile. So, just always ask for the address 62 * on the target GuC. 63 */ 64 addr = __xe_bo_ggtt_addr(bo, gt_to_tile(guc_to_gt(guc))->id); 65 66 /* GuC addresses above GUC_GGTT_TOP don't map through the GTT */ 67 xe_assert(xe, addr >= xe_wopcm_size(guc_to_xe(guc))); 68 xe_assert(xe, addr < GUC_GGTT_TOP); 69 xe_assert(xe, xe_bo_size(bo) <= GUC_GGTT_TOP - addr); 70 71 return addr; 72 } 73 74 static u32 guc_ctl_debug_flags(struct xe_guc *guc) 75 { 76 u32 level = xe_guc_log_get_level(&guc->log); 77 u32 flags = 0; 78 79 if (!GUC_LOG_LEVEL_IS_VERBOSE(level)) 80 flags |= GUC_LOG_DISABLED; 81 else 82 flags |= FIELD_PREP(GUC_LOG_VERBOSITY, GUC_LOG_LEVEL_TO_VERBOSITY(level)); 83 84 return flags; 85 } 86 87 static u32 guc_ctl_feature_flags(struct xe_guc *guc) 88 { 89 struct xe_device *xe = guc_to_xe(guc); 90 u32 flags = GUC_CTL_ENABLE_LITE_RESTORE; 91 92 if (!xe->info.skip_guc_pc) 93 flags |= GUC_CTL_ENABLE_SLPC; 94 95 if (xe_configfs_get_psmi_enabled(to_pci_dev(xe->drm.dev))) 96 flags |= GUC_CTL_ENABLE_PSMI_LOGGING; 97 98 if (xe_guc_using_main_gamctrl_queues(guc)) 99 flags |= GUC_CTL_MAIN_GAMCTRL_QUEUES; 100 101 if (xe_device_is_l2_flush_optimized(xe) && xe_gt_is_media_type(guc_to_gt(guc))) 102 flags |= GUC_CTL_ENABLE_L2FLUSH_OPT; 103 104 return flags; 105 } 106 107 static u32 guc_ctl_log_params_flags(struct xe_guc *guc) 108 { 109 u32 offset = guc_bo_ggtt_addr(guc, guc->log.bo) >> PAGE_SHIFT; 110 u32 flags; 111 112 #if (((XE_GUC_LOG_CRASH_DUMP_BUFFER_SIZE) % SZ_1M) == 0) 113 #define LOG_UNIT SZ_1M 114 #define LOG_FLAG GUC_LOG_LOG_ALLOC_UNITS 115 #else 116 #define LOG_UNIT SZ_4K 117 #define LOG_FLAG 0 118 #endif 119 120 #if (((XE_GUC_LOG_STATE_CAPTURE_BUFFER_SIZE) % SZ_1M) == 0) 121 #define CAPTURE_UNIT SZ_1M 122 #define CAPTURE_FLAG GUC_LOG_CAPTURE_ALLOC_UNITS 123 #else 124 #define CAPTURE_UNIT SZ_4K 125 #define CAPTURE_FLAG 0 126 #endif 127 128 BUILD_BUG_ON(!XE_GUC_LOG_CRASH_DUMP_BUFFER_SIZE); 129 BUILD_BUG_ON(!IS_ALIGNED(XE_GUC_LOG_CRASH_DUMP_BUFFER_SIZE, LOG_UNIT)); 130 BUILD_BUG_ON(!XE_GUC_LOG_EVENT_DATA_BUFFER_SIZE); 131 BUILD_BUG_ON(!IS_ALIGNED(XE_GUC_LOG_EVENT_DATA_BUFFER_SIZE, LOG_UNIT)); 132 BUILD_BUG_ON(!XE_GUC_LOG_STATE_CAPTURE_BUFFER_SIZE); 133 BUILD_BUG_ON(!IS_ALIGNED(XE_GUC_LOG_STATE_CAPTURE_BUFFER_SIZE, CAPTURE_UNIT)); 134 135 flags = GUC_LOG_VALID | 136 GUC_LOG_NOTIFY_ON_HALF_FULL | 137 CAPTURE_FLAG | 138 LOG_FLAG | 139 FIELD_PREP(GUC_LOG_CRASH_DUMP, XE_GUC_LOG_CRASH_DUMP_BUFFER_SIZE / LOG_UNIT - 1) | 140 FIELD_PREP(GUC_LOG_EVENT_DATA, XE_GUC_LOG_EVENT_DATA_BUFFER_SIZE / LOG_UNIT - 1) | 141 FIELD_PREP(GUC_LOG_STATE_CAPTURE, XE_GUC_LOG_STATE_CAPTURE_BUFFER_SIZE / 142 CAPTURE_UNIT - 1) | 143 FIELD_PREP(GUC_LOG_BUF_ADDR, offset); 144 145 #undef LOG_UNIT 146 #undef LOG_FLAG 147 #undef CAPTURE_UNIT 148 #undef CAPTURE_FLAG 149 150 return flags; 151 } 152 153 static u32 guc_ctl_ads_flags(struct xe_guc *guc) 154 { 155 u32 ads = guc_bo_ggtt_addr(guc, guc->ads.bo) >> PAGE_SHIFT; 156 u32 flags = FIELD_PREP(GUC_ADS_ADDR, ads); 157 158 return flags; 159 } 160 161 static bool needs_wa_dual_queue(struct xe_gt *gt) 162 { 163 /* 164 * The DUAL_QUEUE_WA tells the GuC to not allow concurrent submissions 165 * on RCS and CCSes with different address spaces, which on DG2 is 166 * required as a WA for an HW bug. 167 */ 168 if (XE_GT_WA(gt, 22011391025)) 169 return true; 170 171 /* 172 * On newer platforms, the HW has been updated to not allow parallel 173 * execution of different address spaces, so the RCS/CCS will stall the 174 * context switch if one of the other RCS/CCSes is busy with a different 175 * address space. While functionally correct, having a submission 176 * stalled on the HW limits the GuC ability to shuffle things around and 177 * can cause complications if the non-stalled submission runs for a long 178 * time, because the GuC doesn't know that the stalled submission isn't 179 * actually running and might declare it as hung. Therefore, we enable 180 * the DUAL_QUEUE_WA on all newer platforms on GTs that have CCS engines 181 * to move management back to the GuC. 182 */ 183 if (CCS_INSTANCES(gt) && GRAPHICS_VERx100(gt_to_xe(gt)) >= 1270) 184 return true; 185 186 return false; 187 } 188 189 static u32 guc_ctl_wa_flags(struct xe_guc *guc) 190 { 191 struct xe_device *xe = guc_to_xe(guc); 192 struct xe_gt *gt = guc_to_gt(guc); 193 u32 flags = 0; 194 195 if (XE_GT_WA(gt, 22012773006)) 196 flags |= GUC_WA_POLLCS; 197 198 if (XE_GT_WA(gt, 14014475959)) 199 flags |= GUC_WA_HOLD_CCS_SWITCHOUT; 200 201 if (needs_wa_dual_queue(gt)) 202 flags |= GUC_WA_DUAL_QUEUE; 203 204 /* 205 * Wa_22011802037: FIXME - there's more to be done than simply setting 206 * this flag: make sure each CS is stopped when preparing for GT reset 207 * and wait for pending MI_FW. 208 */ 209 if (GRAPHICS_VERx100(xe) < 1270) 210 flags |= GUC_WA_PRE_PARSER; 211 212 if (XE_GT_WA(gt, 22012727170) || XE_GT_WA(gt, 22012727685)) 213 flags |= GUC_WA_CONTEXT_ISOLATION; 214 215 if (XE_GT_WA(gt, 18020744125) && 216 !xe_hw_engine_mask_per_class(gt, XE_ENGINE_CLASS_RENDER)) 217 flags |= GUC_WA_RCS_REGS_IN_CCS_REGS_LIST; 218 219 if (XE_GT_WA(gt, 14018913170)) 220 flags |= GUC_WA_ENABLE_TSC_CHECK_ON_RC6; 221 222 if (XE_GT_WA(gt, 16023683509)) 223 flags |= GUC_WA_SAVE_RESTORE_MCFG_REG_AT_MC6; 224 225 return flags; 226 } 227 228 static u32 guc_ctl_devid(struct xe_guc *guc) 229 { 230 struct xe_device *xe = guc_to_xe(guc); 231 232 return (((u32)xe->info.devid) << 16) | xe->info.revid; 233 } 234 235 static void guc_print_params(struct xe_guc *guc) 236 { 237 struct xe_gt *gt = guc_to_gt(guc); 238 u32 *params = guc->params; 239 int i; 240 241 BUILD_BUG_ON(sizeof(guc->params) != GUC_CTL_MAX_DWORDS * sizeof(u32)); 242 BUILD_BUG_ON(GUC_CTL_MAX_DWORDS + 2 != SOFT_SCRATCH_COUNT); 243 244 for (i = 0; i < GUC_CTL_MAX_DWORDS; i++) 245 xe_gt_dbg(gt, "GuC param[%2d] = 0x%08x\n", i, params[i]); 246 } 247 248 static void guc_init_params(struct xe_guc *guc) 249 { 250 u32 *params = guc->params; 251 252 params[GUC_CTL_LOG_PARAMS] = guc_ctl_log_params_flags(guc); 253 params[GUC_CTL_FEATURE] = 0; 254 params[GUC_CTL_DEBUG] = guc_ctl_debug_flags(guc); 255 params[GUC_CTL_ADS] = guc_ctl_ads_flags(guc); 256 params[GUC_CTL_WA] = 0; 257 params[GUC_CTL_DEVID] = guc_ctl_devid(guc); 258 259 guc_print_params(guc); 260 } 261 262 static void guc_init_params_post_hwconfig(struct xe_guc *guc) 263 { 264 u32 *params = guc->params; 265 266 params[GUC_CTL_LOG_PARAMS] = guc_ctl_log_params_flags(guc); 267 params[GUC_CTL_FEATURE] = guc_ctl_feature_flags(guc); 268 params[GUC_CTL_DEBUG] = guc_ctl_debug_flags(guc); 269 params[GUC_CTL_ADS] = guc_ctl_ads_flags(guc); 270 params[GUC_CTL_WA] = guc_ctl_wa_flags(guc); 271 params[GUC_CTL_DEVID] = guc_ctl_devid(guc); 272 273 guc_print_params(guc); 274 } 275 276 /* 277 * Initialize the GuC parameter block before starting the firmware 278 * transfer. These parameters are read by the firmware on startup 279 * and cannot be changed thereafter. 280 */ 281 static void guc_write_params(struct xe_guc *guc) 282 { 283 struct xe_gt *gt = guc_to_gt(guc); 284 int i; 285 286 xe_force_wake_assert_held(gt_to_fw(gt), XE_FW_GT); 287 288 xe_mmio_write32(>->mmio, SOFT_SCRATCH(0), 0); 289 290 for (i = 0; i < GUC_CTL_MAX_DWORDS; i++) 291 xe_mmio_write32(>->mmio, SOFT_SCRATCH(1 + i), guc->params[i]); 292 } 293 294 static int guc_action_register_g2g_buffer(struct xe_guc *guc, u32 type, u32 dst_tile, u32 dst_dev, 295 u32 desc_addr, u32 buff_addr, u32 size) 296 { 297 struct xe_gt *gt = guc_to_gt(guc); 298 struct xe_device *xe = gt_to_xe(gt); 299 u32 action[] = { 300 XE_GUC_ACTION_REGISTER_G2G, 301 FIELD_PREP(XE_G2G_REGISTER_SIZE, size / SZ_4K - 1) | 302 FIELD_PREP(XE_G2G_REGISTER_TYPE, type) | 303 FIELD_PREP(XE_G2G_REGISTER_TILE, dst_tile) | 304 FIELD_PREP(XE_G2G_REGISTER_DEVICE, dst_dev), 305 desc_addr, 306 buff_addr, 307 }; 308 309 xe_assert(xe, (type == XE_G2G_TYPE_IN) || (type == XE_G2G_TYPE_OUT)); 310 xe_assert(xe, !(size % SZ_4K)); 311 312 return xe_guc_ct_send_block(&guc->ct, action, ARRAY_SIZE(action)); 313 } 314 315 static int guc_action_deregister_g2g_buffer(struct xe_guc *guc, u32 type, u32 dst_tile, u32 dst_dev) 316 { 317 struct xe_gt *gt = guc_to_gt(guc); 318 struct xe_device *xe = gt_to_xe(gt); 319 u32 action[] = { 320 XE_GUC_ACTION_DEREGISTER_G2G, 321 FIELD_PREP(XE_G2G_DEREGISTER_TYPE, type) | 322 FIELD_PREP(XE_G2G_DEREGISTER_TILE, dst_tile) | 323 FIELD_PREP(XE_G2G_DEREGISTER_DEVICE, dst_dev), 324 }; 325 326 xe_assert(xe, (type == XE_G2G_TYPE_IN) || (type == XE_G2G_TYPE_OUT)); 327 328 return xe_guc_ct_send_block(&guc->ct, action, ARRAY_SIZE(action)); 329 } 330 331 #define G2G_DEV(gt) (((gt)->info.type == XE_GT_TYPE_MAIN) ? 0 : 1) 332 333 #define G2G_BUFFER_SIZE (SZ_4K) 334 #define G2G_DESC_SIZE (64) 335 #define G2G_DESC_AREA_SIZE (SZ_4K) 336 337 /* 338 * Generate a unique id for each bi-directional CTB for each pair of 339 * near and far tiles/devices. The id can then be used as an index into 340 * a single allocation that is sub-divided into multiple CTBs. 341 * 342 * For example, with two devices per tile and two tiles, the table should 343 * look like: 344 * Far <tile>.<dev> 345 * 0.0 0.1 1.0 1.1 346 * N 0.0 --/-- 00/01 02/03 04/05 347 * e 0.1 01/00 --/-- 06/07 08/09 348 * a 1.0 03/02 07/06 --/-- 10/11 349 * r 1.1 05/04 09/08 11/10 --/-- 350 * 351 * Where each entry is Rx/Tx channel id. 352 * 353 * So GuC #3 (tile 1, dev 1) talking to GuC #2 (tile 1, dev 0) would 354 * be reading from channel #11 and writing to channel #10. Whereas, 355 * GuC #2 talking to GuC #3 would be read on #10 and write to #11. 356 */ 357 static unsigned int g2g_slot(u32 near_tile, u32 near_dev, u32 far_tile, u32 far_dev, 358 u32 type, u32 max_inst, bool have_dev) 359 { 360 u32 near = near_tile, far = far_tile; 361 u32 idx = 0, x, y, direction; 362 int i; 363 364 if (have_dev) { 365 near = (near << 1) | near_dev; 366 far = (far << 1) | far_dev; 367 } 368 369 /* No need to send to one's self */ 370 if (far == near) 371 return -1; 372 373 if (far > near) { 374 /* Top right table half */ 375 x = far; 376 y = near; 377 378 /* T/R is 'forwards' direction */ 379 direction = type; 380 } else { 381 /* Bottom left table half */ 382 x = near; 383 y = far; 384 385 /* B/L is 'backwards' direction */ 386 direction = (1 - type); 387 } 388 389 /* Count the rows prior to the target */ 390 for (i = y; i > 0; i--) 391 idx += max_inst - i; 392 393 /* Count this row up to the target */ 394 idx += (x - 1 - y); 395 396 /* Slots are in Rx/Tx pairs */ 397 idx *= 2; 398 399 /* Pick Rx/Tx direction */ 400 idx += direction; 401 402 return idx; 403 } 404 405 static int guc_g2g_register(struct xe_guc *near_guc, struct xe_gt *far_gt, u32 type, bool have_dev) 406 { 407 struct xe_gt *near_gt = guc_to_gt(near_guc); 408 struct xe_device *xe = gt_to_xe(near_gt); 409 struct xe_bo *g2g_bo; 410 u32 near_tile = gt_to_tile(near_gt)->id; 411 u32 near_dev = G2G_DEV(near_gt); 412 u32 far_tile = gt_to_tile(far_gt)->id; 413 u32 far_dev = G2G_DEV(far_gt); 414 u32 max = xe->info.gt_count; 415 u32 base, desc, buf; 416 int slot; 417 418 /* G2G is not allowed between different cards */ 419 xe_assert(xe, xe == gt_to_xe(far_gt)); 420 421 g2g_bo = near_guc->g2g.bo; 422 xe_assert(xe, g2g_bo); 423 424 slot = g2g_slot(near_tile, near_dev, far_tile, far_dev, type, max, have_dev); 425 xe_assert(xe, slot >= 0); 426 427 base = guc_bo_ggtt_addr(near_guc, g2g_bo); 428 desc = base + slot * G2G_DESC_SIZE; 429 buf = base + G2G_DESC_AREA_SIZE + slot * G2G_BUFFER_SIZE; 430 431 xe_assert(xe, (desc - base + G2G_DESC_SIZE) <= G2G_DESC_AREA_SIZE); 432 xe_assert(xe, (buf - base + G2G_BUFFER_SIZE) <= xe_bo_size(g2g_bo)); 433 434 return guc_action_register_g2g_buffer(near_guc, type, far_tile, far_dev, 435 desc, buf, G2G_BUFFER_SIZE); 436 } 437 438 static void guc_g2g_deregister(struct xe_guc *guc, u32 far_tile, u32 far_dev, u32 type) 439 { 440 guc_action_deregister_g2g_buffer(guc, type, far_tile, far_dev); 441 } 442 443 static u32 guc_g2g_size(struct xe_guc *guc) 444 { 445 struct xe_gt *gt = guc_to_gt(guc); 446 struct xe_device *xe = gt_to_xe(gt); 447 unsigned int count = xe->info.gt_count; 448 u32 num_channels = (count * (count - 1)) / 2; 449 450 xe_assert(xe, num_channels * XE_G2G_TYPE_LIMIT * G2G_DESC_SIZE <= G2G_DESC_AREA_SIZE); 451 452 return num_channels * XE_G2G_TYPE_LIMIT * G2G_BUFFER_SIZE + G2G_DESC_AREA_SIZE; 453 } 454 455 static bool xe_guc_g2g_wanted(struct xe_device *xe) 456 { 457 /* Can't do GuC to GuC communication if there is only one GuC */ 458 if (xe->info.gt_count <= 1) 459 return false; 460 461 /* No current user */ 462 return false; 463 } 464 465 static int guc_g2g_alloc(struct xe_guc *guc) 466 { 467 struct xe_gt *gt = guc_to_gt(guc); 468 struct xe_device *xe = gt_to_xe(gt); 469 struct xe_tile *tile = gt_to_tile(gt); 470 struct xe_bo *bo; 471 u32 g2g_size; 472 473 if (guc->g2g.bo) 474 return 0; 475 476 if (gt->info.id != 0) { 477 struct xe_gt *root_gt = xe_device_get_gt(xe, 0); 478 struct xe_guc *root_guc = &root_gt->uc.guc; 479 struct xe_bo *bo; 480 481 bo = xe_bo_get(root_guc->g2g.bo); 482 if (!bo) 483 return -ENODEV; 484 485 guc->g2g.bo = bo; 486 guc->g2g.owned = false; 487 return 0; 488 } 489 490 g2g_size = guc_g2g_size(guc); 491 bo = xe_managed_bo_create_pin_map(xe, tile, g2g_size, 492 XE_BO_FLAG_VRAM_IF_DGFX(tile) | 493 XE_BO_FLAG_GGTT | 494 XE_BO_FLAG_GGTT_ALL | 495 XE_BO_FLAG_GGTT_INVALIDATE | 496 XE_BO_FLAG_PINNED_NORESTORE); 497 if (IS_ERR(bo)) 498 return PTR_ERR(bo); 499 500 xe_map_memset(xe, &bo->vmap, 0, 0, g2g_size); 501 guc->g2g.bo = bo; 502 guc->g2g.owned = true; 503 504 return 0; 505 } 506 507 static void guc_g2g_fini(struct xe_guc *guc) 508 { 509 if (!guc->g2g.bo) 510 return; 511 512 /* Unpinning the owned object is handled by generic shutdown */ 513 if (!guc->g2g.owned) 514 xe_bo_put(guc->g2g.bo); 515 516 guc->g2g.bo = NULL; 517 } 518 519 static int guc_g2g_start(struct xe_guc *guc) 520 { 521 struct xe_gt *far_gt, *gt = guc_to_gt(guc); 522 struct xe_device *xe = gt_to_xe(gt); 523 unsigned int i, j; 524 int t, err; 525 bool have_dev; 526 527 if (!guc->g2g.bo) { 528 int ret; 529 530 ret = guc_g2g_alloc(guc); 531 if (ret) 532 return ret; 533 } 534 535 /* GuC interface will need extending if more GT device types are ever created. */ 536 xe_gt_assert(gt, (gt->info.type == XE_GT_TYPE_MAIN) || (gt->info.type == XE_GT_TYPE_MEDIA)); 537 538 /* Channel numbering depends on whether there are multiple GTs per tile */ 539 have_dev = xe->info.gt_count > xe->info.tile_count; 540 541 for_each_gt(far_gt, xe, i) { 542 u32 far_tile, far_dev; 543 544 if (far_gt->info.id == gt->info.id) 545 continue; 546 547 far_tile = gt_to_tile(far_gt)->id; 548 far_dev = G2G_DEV(far_gt); 549 550 for (t = 0; t < XE_G2G_TYPE_LIMIT; t++) { 551 err = guc_g2g_register(guc, far_gt, t, have_dev); 552 if (err) { 553 while (--t >= 0) 554 guc_g2g_deregister(guc, far_tile, far_dev, t); 555 goto err_deregister; 556 } 557 } 558 } 559 560 return 0; 561 562 err_deregister: 563 for_each_gt(far_gt, xe, j) { 564 u32 tile, dev; 565 566 if (far_gt->info.id == gt->info.id) 567 continue; 568 569 if (j >= i) 570 break; 571 572 tile = gt_to_tile(far_gt)->id; 573 dev = G2G_DEV(far_gt); 574 575 for (t = 0; t < XE_G2G_TYPE_LIMIT; t++) 576 guc_g2g_deregister(guc, tile, dev, t); 577 } 578 579 return err; 580 } 581 582 static int __guc_opt_in_features_enable(struct xe_guc *guc, u64 addr, u32 num_dwords) 583 { 584 u32 action[] = { 585 XE_GUC_ACTION_OPT_IN_FEATURE_KLV, 586 lower_32_bits(addr), 587 upper_32_bits(addr), 588 num_dwords 589 }; 590 591 return xe_guc_ct_send_block(&guc->ct, action, ARRAY_SIZE(action)); 592 } 593 594 static bool supports_dynamic_ics(struct xe_guc *guc) 595 { 596 struct xe_device *xe = guc_to_xe(guc); 597 struct xe_gt *gt = guc_to_gt(guc); 598 599 /* Dynamic ICS is available for PVC and Xe2 and newer platforms. */ 600 if (xe->info.platform != XE_PVC && GRAPHICS_VER(xe) < 20) 601 return false; 602 603 /* 604 * The feature is currently not compatible with multi-lrc, so the GuC 605 * does not support it at all on the media engines (which are the main 606 * users of mlrc). On the primary GT side, to avoid it being used in 607 * conjunction with mlrc, we only enable it if we are in single CCS 608 * mode. 609 */ 610 if (xe_gt_is_media_type(gt) || gt->ccs_mode > 1) 611 return false; 612 613 /* 614 * Dynamic ICS requires GuC v70.40.1, which maps to compatibility 615 * version v1.18.4. 616 */ 617 return GUC_SUBMIT_VER(guc) >= MAKE_GUC_VER(1, 18, 4); 618 } 619 620 #define OPT_IN_MAX_DWORDS 16 621 int xe_guc_opt_in_features_enable(struct xe_guc *guc) 622 { 623 struct xe_device *xe = guc_to_xe(guc); 624 CLASS(xe_guc_buf, buf)(&guc->buf, OPT_IN_MAX_DWORDS); 625 u32 count = 0; 626 u32 *klvs; 627 int ret; 628 629 if (!xe_guc_buf_is_valid(buf)) 630 return -ENOBUFS; 631 632 klvs = xe_guc_buf_cpu_ptr(buf); 633 634 /* 635 * The extra CAT error type opt-in was added in GuC v70.17.0, which maps 636 * to compatibility version v1.7.0. 637 * Note that the GuC allows enabling this KLV even on platforms that do 638 * not support the extra type; in such case the returned type variable 639 * will be set to a known invalid value which we can check against. 640 */ 641 if (GUC_SUBMIT_VER(guc) >= MAKE_GUC_VER(1, 7, 0)) 642 klvs[count++] = PREP_GUC_KLV_TAG(OPT_IN_FEATURE_EXT_CAT_ERR_TYPE); 643 644 if (supports_dynamic_ics(guc)) 645 klvs[count++] = PREP_GUC_KLV_TAG(OPT_IN_FEATURE_DYNAMIC_INHIBIT_CONTEXT_SWITCH); 646 647 if (count) { 648 xe_assert(xe, count <= OPT_IN_MAX_DWORDS); 649 650 ret = __guc_opt_in_features_enable(guc, xe_guc_buf_flush(buf), count); 651 if (ret < 0) { 652 xe_gt_err(guc_to_gt(guc), 653 "failed to enable GuC opt-in features: %pe\n", 654 ERR_PTR(ret)); 655 return ret; 656 } 657 } 658 659 return 0; 660 } 661 662 static void guc_fini_hw(void *arg) 663 { 664 struct xe_guc *guc = arg; 665 struct xe_gt *gt = guc_to_gt(guc); 666 667 xe_with_force_wake(fw_ref, gt_to_fw(gt), XE_FORCEWAKE_ALL) 668 xe_uc_sanitize_reset(&guc_to_gt(guc)->uc); 669 670 guc_g2g_fini(guc); 671 } 672 673 static void vf_guc_fini_hw(void *arg) 674 { 675 struct xe_guc *guc = arg; 676 677 xe_gt_sriov_vf_reset(guc_to_gt(guc)); 678 } 679 680 /** 681 * xe_guc_comm_init_early - early initialization of GuC communication 682 * @guc: the &xe_guc to initialize 683 * 684 * Must be called prior to first MMIO communication with GuC firmware. 685 */ 686 void xe_guc_comm_init_early(struct xe_guc *guc) 687 { 688 struct xe_gt *gt = guc_to_gt(guc); 689 690 if (xe_gt_is_media_type(gt)) 691 guc->notify_reg = MED_GUC_HOST_INTERRUPT; 692 else 693 guc->notify_reg = GUC_HOST_INTERRUPT; 694 } 695 696 static int xe_guc_realloc_post_hwconfig(struct xe_guc *guc) 697 { 698 struct xe_tile *tile = gt_to_tile(guc_to_gt(guc)); 699 struct xe_device *xe = guc_to_xe(guc); 700 int ret; 701 702 if (!IS_DGFX(guc_to_xe(guc))) 703 return 0; 704 705 ret = xe_managed_bo_reinit_in_vram(xe, tile, &guc->fw.bo); 706 if (ret) 707 return ret; 708 709 ret = xe_managed_bo_reinit_in_vram(xe, tile, &guc->log.bo); 710 if (ret) 711 return ret; 712 713 ret = xe_managed_bo_reinit_in_vram(xe, tile, &guc->ads.bo); 714 if (ret) 715 return ret; 716 717 return 0; 718 } 719 720 static int vf_guc_init_noalloc(struct xe_guc *guc) 721 { 722 struct xe_gt *gt = guc_to_gt(guc); 723 int err; 724 725 err = xe_gt_sriov_vf_bootstrap(gt); 726 if (err) 727 return err; 728 729 err = xe_gt_sriov_vf_query_config(gt); 730 if (err) 731 return err; 732 733 return 0; 734 } 735 736 int xe_guc_init_noalloc(struct xe_guc *guc) 737 { 738 struct xe_device *xe = guc_to_xe(guc); 739 struct xe_gt *gt = guc_to_gt(guc); 740 int ret; 741 742 xe_guc_comm_init_early(guc); 743 744 ret = xe_guc_ct_init_noalloc(&guc->ct); 745 if (ret) 746 goto out; 747 748 ret = xe_guc_relay_init(&guc->relay); 749 if (ret) 750 goto out; 751 752 if (IS_SRIOV_VF(xe)) { 753 ret = vf_guc_init_noalloc(guc); 754 if (ret) 755 goto out; 756 } 757 758 return 0; 759 760 out: 761 xe_gt_err(gt, "GuC init failed with %pe\n", ERR_PTR(ret)); 762 return ret; 763 } 764 765 int xe_guc_init(struct xe_guc *guc) 766 { 767 struct xe_device *xe = guc_to_xe(guc); 768 struct xe_gt *gt = guc_to_gt(guc); 769 int ret; 770 771 guc->fw.type = XE_UC_FW_TYPE_GUC; 772 ret = xe_uc_fw_init(&guc->fw); 773 if (ret) 774 return ret; 775 776 if (!xe_uc_fw_is_enabled(&guc->fw)) 777 return 0; 778 779 /* Disable page reclaim if GuC FW does not support */ 780 if (GUC_SUBMIT_VER(guc) < MAKE_GUC_VER(1, 14, 0)) 781 xe->info.has_page_reclaim_hw_assist = false; 782 783 /* Disable indirect_ring_state if missing GuC 70.53+ WA 14025515070. */ 784 if (gt->info.has_indirect_ring_state && 785 XE_GT_WA(gt, 14025515070) && 786 GUC_SUBMIT_VER(guc) < MAKE_GUC_VER(1, 26, 0)) { 787 gt->info.has_indirect_ring_state = 0; 788 xe_gt_notice(gt, "indirect ring state requires WA in GuC submit ver 1.26+\n"); 789 } 790 791 if (IS_SRIOV_VF(xe)) { 792 ret = devm_add_action_or_reset(xe->drm.dev, vf_guc_fini_hw, guc); 793 if (ret) 794 goto out; 795 796 ret = xe_guc_ct_init(&guc->ct); 797 if (ret) 798 goto out; 799 return 0; 800 } 801 802 ret = xe_guc_log_init(&guc->log); 803 if (ret) 804 goto out; 805 806 ret = xe_guc_capture_init(guc); 807 if (ret) 808 goto out; 809 810 ret = xe_guc_ads_init(&guc->ads); 811 if (ret) 812 goto out; 813 814 ret = xe_guc_ct_init(&guc->ct); 815 if (ret) 816 goto out; 817 818 xe_uc_fw_change_status(&guc->fw, XE_UC_FIRMWARE_LOADABLE); 819 820 ret = devm_add_action_or_reset(xe->drm.dev, guc_fini_hw, guc); 821 if (ret) 822 goto out; 823 824 guc_init_params(guc); 825 826 return 0; 827 828 out: 829 xe_gt_err(gt, "GuC init failed with %pe\n", ERR_PTR(ret)); 830 return ret; 831 } 832 833 static int vf_guc_init_post_hwconfig(struct xe_guc *guc) 834 { 835 int err; 836 837 err = xe_guc_submit_init(guc, xe_gt_sriov_vf_guc_ids(guc_to_gt(guc))); 838 if (err) 839 return err; 840 841 err = xe_guc_buf_cache_init(&guc->buf); 842 if (err) 843 return err; 844 845 /* XXX xe_guc_db_mgr_init not needed for now */ 846 847 return 0; 848 } 849 850 static u32 guc_additional_cache_size(struct xe_device *xe) 851 { 852 if (IS_SRIOV_PF(xe) && xe_sriov_pf_migration_supported(xe)) 853 return XE_GT_SRIOV_PF_MIGRATION_GUC_DATA_MAX_SIZE; 854 else 855 return 0; /* Fallback to default size */ 856 } 857 858 /** 859 * xe_guc_init_post_hwconfig - initialize GuC post hwconfig load 860 * @guc: The GuC object 861 * 862 * Return: 0 on success, negative error code on error. 863 */ 864 int xe_guc_init_post_hwconfig(struct xe_guc *guc) 865 { 866 int ret; 867 868 if (IS_SRIOV_VF(guc_to_xe(guc))) 869 return vf_guc_init_post_hwconfig(guc); 870 871 ret = xe_guc_realloc_post_hwconfig(guc); 872 if (ret) 873 return ret; 874 875 ret = xe_guc_ct_init_post_hwconfig(&guc->ct); 876 if (ret) 877 return ret; 878 879 guc_init_params_post_hwconfig(guc); 880 881 ret = xe_guc_submit_init(guc, ~0); 882 if (ret) 883 return ret; 884 885 ret = xe_guc_db_mgr_init(&guc->dbm, ~0); 886 if (ret) 887 return ret; 888 889 ret = xe_guc_pc_init(&guc->pc); 890 if (ret) 891 return ret; 892 893 ret = xe_guc_rc_init(guc); 894 if (ret) 895 return ret; 896 897 ret = xe_guc_engine_activity_init(guc); 898 if (ret) 899 return ret; 900 901 ret = xe_guc_buf_cache_init_with_size(&guc->buf, 902 guc_additional_cache_size(guc_to_xe(guc))); 903 if (ret) 904 return ret; 905 906 return xe_guc_ads_init_post_hwconfig(&guc->ads); 907 } 908 909 int xe_guc_post_load_init(struct xe_guc *guc) 910 { 911 int ret; 912 913 xe_guc_ads_populate_post_load(&guc->ads); 914 915 ret = xe_guc_opt_in_features_enable(guc); 916 if (ret) 917 return ret; 918 919 if (xe_guc_g2g_wanted(guc_to_xe(guc))) { 920 ret = guc_g2g_start(guc); 921 if (ret) 922 return ret; 923 } 924 925 return xe_guc_submit_enable(guc); 926 } 927 928 /* 929 * Wa_14025883347: Prevent GuC firmware DMA failures during GuC-only reset by ensuring 930 * SRAM save/restore operations are complete before reset. 931 */ 932 static void guc_prevent_fw_dma_failure_on_reset(struct xe_guc *guc) 933 { 934 struct xe_gt *gt = guc_to_gt(guc); 935 u32 boot_hash_chk, guc_status, sram_status; 936 int ret; 937 938 guc_status = xe_mmio_read32(>->mmio, GUC_STATUS); 939 if (guc_status & GS_MIA_IN_RESET) 940 return; 941 942 boot_hash_chk = xe_mmio_read32(>->mmio, BOOT_HASH_CHK); 943 if (!(boot_hash_chk & GUC_BOOT_UKERNEL_VALID)) 944 return; 945 946 /* Disable idle flow during reset (GuC reset re-enables it automatically) */ 947 xe_mmio_rmw32(>->mmio, GUC_MAX_IDLE_COUNT, 0, GUC_IDLE_FLOW_DISABLE); 948 949 ret = xe_mmio_wait32(>->mmio, GUC_STATUS, GS_UKERNEL_MASK, 950 FIELD_PREP(GS_UKERNEL_MASK, XE_GUC_LOAD_STATUS_READY), 951 100000, &guc_status, false); 952 if (ret) 953 xe_gt_warn(gt, "GuC not ready after disabling idle flow (GUC_STATUS: 0x%x)\n", 954 guc_status); 955 956 ret = xe_mmio_wait32(>->mmio, GUC_SRAM_STATUS, GUC_SRAM_HANDLING_MASK, 957 0, 5000, &sram_status, false); 958 if (ret) 959 xe_gt_warn(gt, "SRAM handling not complete (GUC_SRAM_STATUS: 0x%x)\n", 960 sram_status); 961 } 962 963 int xe_guc_reset(struct xe_guc *guc) 964 { 965 struct xe_gt *gt = guc_to_gt(guc); 966 struct xe_mmio *mmio = >->mmio; 967 u32 guc_status, gdrst; 968 int ret; 969 970 xe_force_wake_assert_held(gt_to_fw(gt), XE_FW_GT); 971 972 if (IS_SRIOV_VF(gt_to_xe(gt))) 973 return xe_gt_sriov_vf_bootstrap(gt); 974 975 if (XE_GT_WA(gt, 14025883347)) 976 guc_prevent_fw_dma_failure_on_reset(guc); 977 978 xe_mmio_write32(mmio, GDRST, GRDOM_GUC); 979 980 ret = xe_mmio_wait32(mmio, GDRST, GRDOM_GUC, 0, 5000, &gdrst, false); 981 if (ret) { 982 xe_gt_err(gt, "GuC reset timed out, GDRST=%#x\n", gdrst); 983 goto err_out; 984 } 985 986 guc_status = xe_mmio_read32(mmio, GUC_STATUS); 987 if (!(guc_status & GS_MIA_IN_RESET)) { 988 xe_gt_err(gt, "GuC status: %#x, MIA core expected to be in reset\n", 989 guc_status); 990 ret = -EIO; 991 goto err_out; 992 } 993 994 return 0; 995 996 err_out: 997 998 return ret; 999 } 1000 1001 static void guc_prepare_xfer(struct xe_guc *guc) 1002 { 1003 struct xe_gt *gt = guc_to_gt(guc); 1004 struct xe_mmio *mmio = >->mmio; 1005 struct xe_device *xe = guc_to_xe(guc); 1006 u32 shim_flags = GUC_ENABLE_READ_CACHE_LOGIC | 1007 GUC_ENABLE_READ_CACHE_FOR_SRAM_DATA | 1008 GUC_ENABLE_READ_CACHE_FOR_WOPCM_DATA | 1009 GUC_ENABLE_MIA_CLOCK_GATING; 1010 1011 if (GRAPHICS_VERx100(xe) < 1250) 1012 shim_flags |= GUC_DISABLE_SRAM_INIT_TO_ZEROES | 1013 GUC_ENABLE_MIA_CACHING; 1014 1015 if (GRAPHICS_VER(xe) >= 20 || xe->info.platform == XE_PVC) 1016 shim_flags |= REG_FIELD_PREP(GUC_MOCS_INDEX_MASK, gt->mocs.uc_index); 1017 1018 /* Must program this register before loading the ucode with DMA */ 1019 xe_mmio_write32(mmio, GUC_SHIM_CONTROL, shim_flags); 1020 1021 xe_mmio_write32(mmio, GT_PM_CONFIG, GT_DOORBELL_ENABLE); 1022 1023 /* Make sure GuC receives ARAT interrupts */ 1024 xe_mmio_rmw32(mmio, PMINTRMSK, ARAT_EXPIRED_INTRMSK, 0); 1025 } 1026 1027 /* 1028 * Supporting MMIO & in memory RSA 1029 */ 1030 static int guc_xfer_rsa(struct xe_guc *guc) 1031 { 1032 struct xe_gt *gt = guc_to_gt(guc); 1033 u32 rsa[UOS_RSA_SCRATCH_COUNT]; 1034 size_t copied; 1035 int i; 1036 1037 if (guc->fw.rsa_size > 256) { 1038 u32 rsa_ggtt_addr = xe_bo_ggtt_addr(guc->fw.bo) + 1039 xe_uc_fw_rsa_offset(&guc->fw); 1040 xe_mmio_write32(>->mmio, UOS_RSA_SCRATCH(0), rsa_ggtt_addr); 1041 return 0; 1042 } 1043 1044 copied = xe_uc_fw_copy_rsa(&guc->fw, rsa, sizeof(rsa)); 1045 if (copied < sizeof(rsa)) 1046 return -ENOMEM; 1047 1048 for (i = 0; i < UOS_RSA_SCRATCH_COUNT; i++) 1049 xe_mmio_write32(>->mmio, UOS_RSA_SCRATCH(i), rsa[i]); 1050 1051 return 0; 1052 } 1053 1054 /* 1055 * Wait for the GuC to start up. 1056 * 1057 * Measurements indicate this should take no more than 20ms (assuming the GT 1058 * clock is at maximum frequency). However, thermal throttling and other issues 1059 * can prevent the clock hitting max and thus making the load take significantly 1060 * longer. Allow up to 3s as a safety margin in normal builds. For 1061 * CONFIG_DRM_XE_DEBUG allow up to 10s to account for slower execution, issues 1062 * in PCODE, driver, fan, etc. 1063 * 1064 * Keep checking the GUC_STATUS every 10ms with a debug message every 100 1065 * attempts as a "I'm slow, but alive" message. Regardless, if it takes more 1066 * than 200ms, emit a warning. 1067 */ 1068 1069 #if IS_ENABLED(CONFIG_DRM_XE_DEBUG) 1070 #define GUC_LOAD_TIMEOUT_SEC 20 1071 #else 1072 #define GUC_LOAD_TIMEOUT_SEC 3 1073 #endif 1074 #define GUC_LOAD_TIME_WARN_MSEC 200 1075 1076 static void print_load_status_err(struct xe_gt *gt, u32 status) 1077 { 1078 struct xe_mmio *mmio = >->mmio; 1079 u32 ukernel = REG_FIELD_GET(GS_UKERNEL_MASK, status); 1080 u32 bootrom = REG_FIELD_GET(GS_BOOTROM_MASK, status); 1081 1082 xe_gt_err(gt, "load failed: status: Reset = %d, BootROM = 0x%02X, UKernel = 0x%02X, MIA = 0x%02X, Auth = 0x%02X\n", 1083 REG_FIELD_GET(GS_MIA_IN_RESET, status), 1084 bootrom, ukernel, 1085 REG_FIELD_GET(GS_MIA_MASK, status), 1086 REG_FIELD_GET(GS_AUTH_STATUS_MASK, status)); 1087 1088 switch (bootrom) { 1089 case XE_BOOTROM_STATUS_NO_KEY_FOUND: 1090 xe_gt_err(gt, "invalid key requested, header = 0x%08X\n", 1091 xe_mmio_read32(mmio, GUC_HEADER_INFO)); 1092 break; 1093 case XE_BOOTROM_STATUS_RSA_FAILED: 1094 xe_gt_err(gt, "firmware signature verification failed\n"); 1095 break; 1096 case XE_BOOTROM_STATUS_PROD_KEY_CHECK_FAILURE: 1097 xe_gt_err(gt, "firmware production part check failure\n"); 1098 break; 1099 } 1100 1101 switch (ukernel) { 1102 case XE_GUC_LOAD_STATUS_HWCONFIG_START: 1103 xe_gt_err(gt, "still extracting hwconfig table.\n"); 1104 break; 1105 case XE_GUC_LOAD_STATUS_EXCEPTION: 1106 xe_gt_err(gt, "firmware exception. EIP: %#x\n", 1107 xe_mmio_read32(mmio, SOFT_SCRATCH(13))); 1108 break; 1109 case XE_GUC_LOAD_STATUS_INIT_DATA_INVALID: 1110 xe_gt_err(gt, "illegal init/ADS data\n"); 1111 break; 1112 case XE_GUC_LOAD_STATUS_INIT_MMIO_SAVE_RESTORE_INVALID: 1113 xe_gt_err(gt, "illegal register in save/restore workaround list\n"); 1114 break; 1115 case XE_GUC_LOAD_STATUS_KLV_WORKAROUND_INIT_ERROR: 1116 xe_gt_err(gt, "illegal workaround KLV data\n"); 1117 break; 1118 case XE_GUC_LOAD_STATUS_INVALID_FTR_FLAG: 1119 xe_gt_err(gt, "illegal feature flag specified\n"); 1120 break; 1121 } 1122 } 1123 1124 /* 1125 * Check GUC_STATUS looking for known terminal states (either completion or 1126 * failure) of either the microkernel status field or the boot ROM status field. 1127 * 1128 * Returns 1 for successful completion, -1 for failure and 0 for any 1129 * intermediate state. 1130 */ 1131 static int guc_load_done(struct xe_gt *gt, u32 *status, u32 *tries) 1132 { 1133 u32 ukernel, bootrom; 1134 1135 *status = xe_mmio_read32(>->mmio, GUC_STATUS); 1136 ukernel = REG_FIELD_GET(GS_UKERNEL_MASK, *status); 1137 bootrom = REG_FIELD_GET(GS_BOOTROM_MASK, *status); 1138 1139 switch (ukernel) { 1140 case XE_GUC_LOAD_STATUS_READY: 1141 return 1; 1142 case XE_GUC_LOAD_STATUS_ERROR_DEVID_BUILD_MISMATCH: 1143 case XE_GUC_LOAD_STATUS_GUC_PREPROD_BUILD_MISMATCH: 1144 case XE_GUC_LOAD_STATUS_ERROR_DEVID_INVALID_GUCTYPE: 1145 case XE_GUC_LOAD_STATUS_HWCONFIG_ERROR: 1146 case XE_GUC_LOAD_STATUS_BOOTROM_VERSION_MISMATCH: 1147 case XE_GUC_LOAD_STATUS_DPC_ERROR: 1148 case XE_GUC_LOAD_STATUS_EXCEPTION: 1149 case XE_GUC_LOAD_STATUS_INIT_DATA_INVALID: 1150 case XE_GUC_LOAD_STATUS_MPU_DATA_INVALID: 1151 case XE_GUC_LOAD_STATUS_INIT_MMIO_SAVE_RESTORE_INVALID: 1152 case XE_GUC_LOAD_STATUS_KLV_WORKAROUND_INIT_ERROR: 1153 case XE_GUC_LOAD_STATUS_INVALID_FTR_FLAG: 1154 return -1; 1155 } 1156 1157 switch (bootrom) { 1158 case XE_BOOTROM_STATUS_NO_KEY_FOUND: 1159 case XE_BOOTROM_STATUS_RSA_FAILED: 1160 case XE_BOOTROM_STATUS_PAVPC_FAILED: 1161 case XE_BOOTROM_STATUS_WOPCM_FAILED: 1162 case XE_BOOTROM_STATUS_LOADLOC_FAILED: 1163 case XE_BOOTROM_STATUS_JUMP_FAILED: 1164 case XE_BOOTROM_STATUS_RC6CTXCONFIG_FAILED: 1165 case XE_BOOTROM_STATUS_MPUMAP_INCORRECT: 1166 case XE_BOOTROM_STATUS_EXCEPTION: 1167 case XE_BOOTROM_STATUS_PROD_KEY_CHECK_FAILURE: 1168 return -1; 1169 } 1170 1171 if (++*tries >= 100) { 1172 struct xe_guc_pc *guc_pc = >->uc.guc.pc; 1173 1174 *tries = 0; 1175 xe_gt_dbg(gt, "GuC load still in progress, freq = %dMHz (req %dMHz), status = 0x%08X [0x%02X/%02X]\n", 1176 xe_guc_pc_get_act_freq(guc_pc), 1177 xe_guc_pc_get_cur_freq_fw(guc_pc), 1178 *status, ukernel, bootrom); 1179 } 1180 1181 return 0; 1182 } 1183 1184 static int guc_wait_ucode(struct xe_guc *guc) 1185 { 1186 struct xe_gt *gt = guc_to_gt(guc); 1187 struct xe_guc_pc *guc_pc = >->uc.guc.pc; 1188 u32 before_freq, act_freq, cur_freq; 1189 u32 status = 0, tries = 0; 1190 int load_result, ret; 1191 ktime_t before; 1192 u64 delta_ms; 1193 1194 before_freq = xe_guc_pc_get_act_freq(guc_pc); 1195 before = ktime_get(); 1196 1197 ret = poll_timeout_us(load_result = guc_load_done(gt, &status, &tries), load_result, 1198 10 * USEC_PER_MSEC, 1199 GUC_LOAD_TIMEOUT_SEC * USEC_PER_SEC, false); 1200 1201 delta_ms = ktime_to_ms(ktime_sub(ktime_get(), before)); 1202 act_freq = xe_guc_pc_get_act_freq(guc_pc); 1203 cur_freq = xe_guc_pc_get_cur_freq_fw(guc_pc); 1204 1205 if (ret || load_result <= 0) { 1206 xe_gt_err(gt, "load failed: status = 0x%08X, time = %lldms, freq = %dMHz (req %dMHz)\n", 1207 status, delta_ms, xe_guc_pc_get_act_freq(guc_pc), 1208 xe_guc_pc_get_cur_freq_fw(guc_pc)); 1209 print_load_status_err(gt, status); 1210 1211 return -EPROTO; 1212 } 1213 1214 if (delta_ms > GUC_LOAD_TIME_WARN_MSEC) { 1215 xe_gt_warn(gt, "GuC load: excessive init time: %lldms! [status = 0x%08X]\n", 1216 delta_ms, status); 1217 xe_gt_warn(gt, "GuC load: excessive init time: [freq = %dMHz (req = %dMHz), before = %dMHz, perf_limit_reasons = 0x%08X]\n", 1218 act_freq, cur_freq, before_freq, 1219 xe_gt_throttle_get_limit_reasons(gt)); 1220 } else { 1221 xe_gt_dbg(gt, "GuC load: init took %lldms, freq = %dMHz (req = %dMHz), before = %dMHz, status = 0x%08X\n", 1222 delta_ms, act_freq, cur_freq, before_freq, status); 1223 } 1224 1225 return 0; 1226 } 1227 ALLOW_ERROR_INJECTION(guc_wait_ucode, ERRNO); 1228 1229 static int __xe_guc_upload(struct xe_guc *guc) 1230 { 1231 int ret; 1232 1233 /* Raise GT freq to speed up HuC/GuC load */ 1234 xe_guc_pc_raise_unslice(&guc->pc); 1235 1236 guc_write_params(guc); 1237 guc_prepare_xfer(guc); 1238 1239 /* 1240 * Note that GuC needs the CSS header plus uKernel code to be copied 1241 * by the DMA engine in one operation, whereas the RSA signature is 1242 * loaded separately, either by copying it to the UOS_RSA_SCRATCH 1243 * register (if key size <= 256) or through a ggtt-pinned vma (if key 1244 * size > 256). The RSA size and therefore the way we provide it to the 1245 * HW is fixed for each platform and hard-coded in the bootrom. 1246 */ 1247 ret = guc_xfer_rsa(guc); 1248 if (ret) 1249 goto out; 1250 /* 1251 * Current uCode expects the code to be loaded at 8k; locations below 1252 * this are used for the stack. 1253 */ 1254 ret = xe_uc_fw_upload(&guc->fw, 0x2000, UOS_MOVE); 1255 if (ret) 1256 goto out; 1257 1258 /* Wait for authentication */ 1259 ret = guc_wait_ucode(guc); 1260 if (ret) 1261 goto out; 1262 1263 xe_uc_fw_change_status(&guc->fw, XE_UC_FIRMWARE_RUNNING); 1264 return 0; 1265 1266 out: 1267 xe_uc_fw_change_status(&guc->fw, XE_UC_FIRMWARE_LOAD_FAIL); 1268 return ret; 1269 } 1270 1271 static int vf_guc_min_load_for_hwconfig(struct xe_guc *guc) 1272 { 1273 struct xe_gt *gt = guc_to_gt(guc); 1274 int ret; 1275 1276 ret = xe_guc_hwconfig_init(guc); 1277 if (ret) 1278 return ret; 1279 1280 ret = xe_guc_enable_communication(guc); 1281 if (ret) 1282 return ret; 1283 1284 ret = xe_gt_sriov_vf_connect(gt); 1285 if (ret) 1286 goto err_out; 1287 1288 ret = xe_gt_sriov_vf_query_runtime(gt); 1289 if (ret) 1290 goto err_out; 1291 1292 return 0; 1293 1294 err_out: 1295 xe_guc_sanitize(guc); 1296 return ret; 1297 } 1298 1299 /** 1300 * xe_guc_min_load_for_hwconfig - load minimal GuC and read hwconfig table 1301 * @guc: The GuC object 1302 * 1303 * This function uploads a minimal GuC that does not support submissions but 1304 * in a state where the hwconfig table can be read. Next, it reads and parses 1305 * the hwconfig table so it can be used for subsequent steps in the driver load. 1306 * Lastly, it enables CT communication (XXX: this is needed for PFs/VFs only). 1307 * 1308 * Return: 0 on success, negative error code on error. 1309 */ 1310 int xe_guc_min_load_for_hwconfig(struct xe_guc *guc) 1311 { 1312 int ret; 1313 1314 if (IS_SRIOV_VF(guc_to_xe(guc))) 1315 return vf_guc_min_load_for_hwconfig(guc); 1316 1317 xe_guc_ads_populate_minimal(&guc->ads); 1318 1319 xe_guc_pc_init_early(&guc->pc); 1320 1321 ret = __xe_guc_upload(guc); 1322 if (ret) 1323 return ret; 1324 1325 ret = xe_guc_hwconfig_init(guc); 1326 if (ret) 1327 return ret; 1328 1329 ret = xe_guc_enable_communication(guc); 1330 if (ret) 1331 return ret; 1332 1333 return 0; 1334 } 1335 1336 int xe_guc_upload(struct xe_guc *guc) 1337 { 1338 struct xe_gt *gt = guc_to_gt(guc); 1339 1340 xe_guc_ads_populate(&guc->ads); 1341 1342 if (xe_guc_using_main_gamctrl_queues(guc)) 1343 xe_mmio_write32(>->mmio, MAIN_GAMCTRL_MODE, MAIN_GAMCTRL_QUEUE_SELECT); 1344 1345 return __xe_guc_upload(guc); 1346 } 1347 1348 static void guc_handle_mmio_msg(struct xe_guc *guc) 1349 { 1350 struct xe_gt *gt = guc_to_gt(guc); 1351 u32 msg; 1352 1353 if (IS_SRIOV_VF(guc_to_xe(guc))) 1354 return; 1355 1356 xe_force_wake_assert_held(gt_to_fw(gt), XE_FW_GT); 1357 1358 msg = xe_mmio_read32(>->mmio, SOFT_SCRATCH(15)); 1359 msg &= XE_GUC_RECV_MSG_EXCEPTION | 1360 XE_GUC_RECV_MSG_CRASH_DUMP_POSTED; 1361 xe_mmio_write32(>->mmio, SOFT_SCRATCH(15), 0); 1362 1363 if (msg & XE_GUC_RECV_MSG_CRASH_DUMP_POSTED) 1364 xe_gt_err(gt, "Received early GuC crash dump notification!\n"); 1365 1366 if (msg & XE_GUC_RECV_MSG_EXCEPTION) 1367 xe_gt_err(gt, "Received early GuC exception notification!\n"); 1368 } 1369 1370 static void guc_enable_irq(struct xe_guc *guc) 1371 { 1372 struct xe_gt *gt = guc_to_gt(guc); 1373 u32 events = xe_gt_is_media_type(gt) ? 1374 REG_FIELD_PREP(ENGINE0_MASK, GUC_INTR_GUC2HOST) : 1375 REG_FIELD_PREP(ENGINE1_MASK, GUC_INTR_GUC2HOST); 1376 1377 /* Primary GuC and media GuC share a single enable bit */ 1378 xe_mmio_write32(>->mmio, GUC_SG_INTR_ENABLE, 1379 REG_FIELD_PREP(ENGINE1_MASK, GUC_INTR_GUC2HOST)); 1380 1381 /* 1382 * There are separate mask bits for primary and media GuCs, so use 1383 * a RMW operation to avoid clobbering the other GuC's setting. 1384 */ 1385 xe_mmio_rmw32(>->mmio, GUC_SG_INTR_MASK, events, 0); 1386 } 1387 1388 int xe_guc_enable_communication(struct xe_guc *guc) 1389 { 1390 struct xe_device *xe = guc_to_xe(guc); 1391 int err; 1392 1393 if (IS_SRIOV_VF(xe) && xe_device_has_memirq(xe)) { 1394 struct xe_gt *gt = guc_to_gt(guc); 1395 struct xe_tile *tile = gt_to_tile(gt); 1396 1397 err = xe_memirq_init_guc(&tile->memirq, guc); 1398 if (err) 1399 return err; 1400 } else { 1401 guc_enable_irq(guc); 1402 } 1403 1404 err = xe_guc_ct_enable(&guc->ct); 1405 if (err) 1406 return err; 1407 1408 guc_handle_mmio_msg(guc); 1409 1410 return 0; 1411 } 1412 1413 /** 1414 * xe_guc_softreset() - Soft reset GuC 1415 * @guc: The GuC object 1416 * 1417 * Send soft reset command to GuC through mmio send. 1418 * 1419 * Return: 0 if success, otherwise error code 1420 */ 1421 int xe_guc_softreset(struct xe_guc *guc) 1422 { 1423 u32 action[] = { 1424 XE_GUC_ACTION_CLIENT_SOFT_RESET, 1425 }; 1426 int ret; 1427 1428 if (!xe_uc_fw_is_running(&guc->fw)) 1429 return 0; 1430 1431 ret = xe_guc_mmio_send(guc, action, ARRAY_SIZE(action)); 1432 if (ret) 1433 return ret; 1434 1435 return 0; 1436 } 1437 1438 int xe_guc_suspend(struct xe_guc *guc) 1439 { 1440 struct xe_gt *gt = guc_to_gt(guc); 1441 int ret; 1442 1443 ret = xe_guc_softreset(guc); 1444 if (ret) { 1445 xe_gt_err(gt, "GuC suspend failed: %pe\n", ERR_PTR(ret)); 1446 return ret; 1447 } 1448 1449 xe_guc_sanitize(guc); 1450 return 0; 1451 } 1452 1453 void xe_guc_notify(struct xe_guc *guc) 1454 { 1455 struct xe_gt *gt = guc_to_gt(guc); 1456 const u32 default_notify_data = 0; 1457 1458 /* 1459 * Both GUC_HOST_INTERRUPT and MED_GUC_HOST_INTERRUPT can pass 1460 * additional payload data to the GuC but this capability is not 1461 * used by the firmware yet. Use default value in the meantime. 1462 */ 1463 xe_mmio_write32(>->mmio, guc->notify_reg, default_notify_data); 1464 } 1465 1466 int xe_guc_auth_huc(struct xe_guc *guc, u32 rsa_addr) 1467 { 1468 u32 action[] = { 1469 XE_GUC_ACTION_AUTHENTICATE_HUC, 1470 rsa_addr 1471 }; 1472 1473 return xe_guc_ct_send_block(&guc->ct, action, ARRAY_SIZE(action)); 1474 } 1475 1476 #define MAX_RETRIES_ON_FLR 2 1477 #define MIN_SLEEP_MS_ON_FLR 256 1478 1479 int xe_guc_mmio_send_recv(struct xe_guc *guc, const u32 *request, 1480 u32 len, u32 *response_buf) 1481 { 1482 struct xe_device *xe = guc_to_xe(guc); 1483 struct xe_gt *gt = guc_to_gt(guc); 1484 struct xe_mmio *mmio = >->mmio; 1485 struct xe_reg reply_reg = xe_gt_is_media_type(gt) ? 1486 MED_VF_SW_FLAG(0) : VF_SW_FLAG(0); 1487 const u32 LAST_INDEX = VF_SW_FLAG_COUNT - 1; 1488 unsigned int sleep_period_ms = 1; 1489 unsigned int lost = 0; 1490 u32 header; 1491 int ret; 1492 int i; 1493 1494 BUILD_BUG_ON(VF_SW_FLAG_COUNT != MED_VF_SW_FLAG_COUNT); 1495 1496 xe_assert(xe, len); 1497 xe_assert(xe, len <= VF_SW_FLAG_COUNT); 1498 xe_assert(xe, len <= MED_VF_SW_FLAG_COUNT); 1499 xe_assert(xe, FIELD_GET(GUC_HXG_MSG_0_ORIGIN, request[0]) == 1500 GUC_HXG_ORIGIN_HOST); 1501 xe_assert(xe, FIELD_GET(GUC_HXG_MSG_0_TYPE, request[0]) == 1502 GUC_HXG_TYPE_REQUEST); 1503 1504 retry: 1505 /* Not in critical data-path, just do if else for GT type */ 1506 if (xe_gt_is_media_type(gt)) { 1507 for (i = 0; i < len; ++i) 1508 xe_mmio_write32(mmio, MED_VF_SW_FLAG(i), 1509 request[i]); 1510 xe_mmio_read32(mmio, MED_VF_SW_FLAG(LAST_INDEX)); 1511 } else { 1512 for (i = 0; i < len; ++i) 1513 xe_mmio_write32(mmio, VF_SW_FLAG(i), 1514 request[i]); 1515 xe_mmio_read32(mmio, VF_SW_FLAG(LAST_INDEX)); 1516 } 1517 1518 xe_guc_notify(guc); 1519 1520 ret = xe_mmio_wait32(mmio, reply_reg, GUC_HXG_MSG_0_ORIGIN, 1521 FIELD_PREP(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_GUC), 1522 50000, &header, false); 1523 if (ret) { 1524 /* scratch registers might be cleared during FLR, try once more */ 1525 if (!header) { 1526 if (++lost > MAX_RETRIES_ON_FLR) { 1527 xe_gt_err(gt, "GuC mmio request %#x: lost, too many retries %u\n", 1528 request[0], lost); 1529 return -ENOLINK; 1530 } 1531 xe_gt_dbg(gt, "GuC mmio request %#x: lost, trying again\n", request[0]); 1532 xe_sleep_relaxed_ms(MIN_SLEEP_MS_ON_FLR); 1533 goto retry; 1534 } 1535 timeout: 1536 xe_gt_err(gt, "GuC mmio request %#x: no reply %#x\n", 1537 request[0], header); 1538 return ret; 1539 } 1540 1541 if (FIELD_GET(GUC_HXG_MSG_0_TYPE, header) == 1542 GUC_HXG_TYPE_NO_RESPONSE_BUSY) { 1543 /* 1544 * Once we got a BUSY reply we must wait again for the final 1545 * response but this time we can't use ORIGIN mask anymore. 1546 * To spot a right change in the reply, we take advantage that 1547 * response SUCCESS and FAILURE differ only by the single bit 1548 * and all other bits are set and can be used as a new mask. 1549 */ 1550 u32 resp_bits = GUC_HXG_TYPE_RESPONSE_SUCCESS & GUC_HXG_TYPE_RESPONSE_FAILURE; 1551 u32 resp_mask = FIELD_PREP(GUC_HXG_MSG_0_TYPE, resp_bits); 1552 1553 BUILD_BUG_ON(FIELD_MAX(GUC_HXG_MSG_0_TYPE) != GUC_HXG_TYPE_RESPONSE_SUCCESS); 1554 BUILD_BUG_ON((GUC_HXG_TYPE_RESPONSE_SUCCESS ^ GUC_HXG_TYPE_RESPONSE_FAILURE) != 1); 1555 1556 ret = xe_mmio_wait32(mmio, reply_reg, resp_mask, resp_mask, 1557 2000000, &header, false); 1558 1559 if (unlikely(FIELD_GET(GUC_HXG_MSG_0_ORIGIN, header) != 1560 GUC_HXG_ORIGIN_GUC)) 1561 goto proto; 1562 if (unlikely(ret)) { 1563 if (FIELD_GET(GUC_HXG_MSG_0_TYPE, header) != 1564 GUC_HXG_TYPE_NO_RESPONSE_BUSY) 1565 goto proto; 1566 goto timeout; 1567 } 1568 } 1569 1570 if (FIELD_GET(GUC_HXG_MSG_0_TYPE, header) == 1571 GUC_HXG_TYPE_NO_RESPONSE_RETRY) { 1572 u32 reason = FIELD_GET(GUC_HXG_RETRY_MSG_0_REASON, header); 1573 1574 xe_gt_dbg(gt, "GuC mmio request %#x: retrying, reason %#x\n", 1575 request[0], reason); 1576 1577 xe_sleep_exponential_ms(&sleep_period_ms, 256); 1578 goto retry; 1579 } 1580 1581 if (FIELD_GET(GUC_HXG_MSG_0_TYPE, header) == 1582 GUC_HXG_TYPE_RESPONSE_FAILURE) { 1583 u32 hint = FIELD_GET(GUC_HXG_FAILURE_MSG_0_HINT, header); 1584 u32 error = FIELD_GET(GUC_HXG_FAILURE_MSG_0_ERROR, header); 1585 1586 if (unlikely(error == XE_GUC_RESPONSE_VF_MIGRATED)) { 1587 xe_gt_dbg(gt, "GuC mmio request %#x rejected due to MIGRATION (hint %#x)\n", 1588 request[0], hint); 1589 return -EREMCHG; 1590 } 1591 1592 xe_gt_err(gt, "GuC mmio request %#x: failure %#x hint %#x\n", 1593 request[0], error, hint); 1594 return -ENXIO; 1595 } 1596 1597 if (FIELD_GET(GUC_HXG_MSG_0_TYPE, header) != 1598 GUC_HXG_TYPE_RESPONSE_SUCCESS) { 1599 proto: 1600 xe_gt_err(gt, "GuC mmio request %#x: unexpected reply %#x\n", 1601 request[0], header); 1602 return -EPROTO; 1603 } 1604 1605 /* Just copy entire possible message response */ 1606 if (response_buf) { 1607 response_buf[0] = header; 1608 1609 for (i = 1; i < VF_SW_FLAG_COUNT; i++) { 1610 reply_reg.addr += sizeof(u32); 1611 response_buf[i] = xe_mmio_read32(mmio, reply_reg); 1612 } 1613 } 1614 1615 /* Use data from the GuC response as our return value */ 1616 return FIELD_GET(GUC_HXG_RESPONSE_MSG_0_DATA0, header); 1617 } 1618 ALLOW_ERROR_INJECTION(xe_guc_mmio_send_recv, ERRNO); 1619 1620 int xe_guc_mmio_send(struct xe_guc *guc, const u32 *request, u32 len) 1621 { 1622 return xe_guc_mmio_send_recv(guc, request, len, NULL); 1623 } 1624 1625 static int guc_self_cfg(struct xe_guc *guc, u16 key, u16 len, u64 val) 1626 { 1627 struct xe_device *xe = guc_to_xe(guc); 1628 u32 request[HOST2GUC_SELF_CFG_REQUEST_MSG_LEN] = { 1629 FIELD_PREP(GUC_HXG_MSG_0_ORIGIN, GUC_HXG_ORIGIN_HOST) | 1630 FIELD_PREP(GUC_HXG_MSG_0_TYPE, GUC_HXG_TYPE_REQUEST) | 1631 FIELD_PREP(GUC_HXG_REQUEST_MSG_0_ACTION, 1632 GUC_ACTION_HOST2GUC_SELF_CFG), 1633 FIELD_PREP(HOST2GUC_SELF_CFG_REQUEST_MSG_1_KLV_KEY, key) | 1634 FIELD_PREP(HOST2GUC_SELF_CFG_REQUEST_MSG_1_KLV_LEN, len), 1635 FIELD_PREP(HOST2GUC_SELF_CFG_REQUEST_MSG_2_VALUE32, 1636 lower_32_bits(val)), 1637 FIELD_PREP(HOST2GUC_SELF_CFG_REQUEST_MSG_3_VALUE64, 1638 upper_32_bits(val)), 1639 }; 1640 int ret; 1641 1642 xe_assert(xe, len <= 2); 1643 xe_assert(xe, len != 1 || !upper_32_bits(val)); 1644 1645 /* Self config must go over MMIO */ 1646 ret = xe_guc_mmio_send(guc, request, ARRAY_SIZE(request)); 1647 1648 if (unlikely(ret < 0)) 1649 return ret; 1650 if (unlikely(ret > 1)) 1651 return -EPROTO; 1652 if (unlikely(!ret)) 1653 return -ENOKEY; 1654 1655 return 0; 1656 } 1657 1658 int xe_guc_self_cfg32(struct xe_guc *guc, u16 key, u32 val) 1659 { 1660 return guc_self_cfg(guc, key, 1, val); 1661 } 1662 1663 int xe_guc_self_cfg64(struct xe_guc *guc, u16 key, u64 val) 1664 { 1665 return guc_self_cfg(guc, key, 2, val); 1666 } 1667 1668 static void xe_guc_sw_0_irq_handler(struct xe_guc *guc) 1669 { 1670 struct xe_gt *gt = guc_to_gt(guc); 1671 1672 if (IS_SRIOV_VF(gt_to_xe(gt))) 1673 xe_gt_sriov_vf_migrated_event_handler(gt); 1674 } 1675 1676 void xe_guc_irq_handler(struct xe_guc *guc, const u16 iir) 1677 { 1678 if (iir & GUC_INTR_GUC2HOST) 1679 xe_guc_ct_irq_handler(&guc->ct); 1680 1681 if (iir & GUC_INTR_SW_INT_0) 1682 xe_guc_sw_0_irq_handler(guc); 1683 } 1684 1685 void xe_guc_sanitize(struct xe_guc *guc) 1686 { 1687 xe_uc_fw_sanitize(&guc->fw); 1688 xe_guc_ct_disable(&guc->ct); 1689 xe_guc_submit_disable(guc); 1690 } 1691 1692 int xe_guc_reset_prepare(struct xe_guc *guc) 1693 { 1694 return xe_guc_submit_reset_prepare(guc); 1695 } 1696 1697 void xe_guc_reset_wait(struct xe_guc *guc) 1698 { 1699 xe_guc_submit_reset_wait(guc); 1700 } 1701 1702 void xe_guc_stop_prepare(struct xe_guc *guc) 1703 { 1704 if (!IS_SRIOV_VF(guc_to_xe(guc))) 1705 xe_guc_pc_stop(&guc->pc); 1706 } 1707 1708 void xe_guc_stop(struct xe_guc *guc) 1709 { 1710 xe_guc_ct_stop(&guc->ct); 1711 1712 xe_guc_submit_stop(guc); 1713 } 1714 1715 int xe_guc_start(struct xe_guc *guc) 1716 { 1717 return xe_guc_submit_start(guc); 1718 } 1719 1720 /** 1721 * xe_guc_runtime_suspend() - GuC runtime suspend 1722 * @guc: The GuC object 1723 * 1724 * Stop further runs of submission tasks on given GuC and runtime suspend 1725 * GuC CT. 1726 */ 1727 void xe_guc_runtime_suspend(struct xe_guc *guc) 1728 { 1729 xe_guc_submit_pause(guc); 1730 xe_guc_submit_disable(guc); 1731 xe_guc_ct_runtime_suspend(&guc->ct); 1732 } 1733 1734 /** 1735 * xe_guc_runtime_resume() - GuC runtime resume 1736 * @guc: The GuC object 1737 * 1738 * Runtime resume GuC CT and allow further runs of submission tasks on 1739 * given GuC. 1740 */ 1741 void xe_guc_runtime_resume(struct xe_guc *guc) 1742 { 1743 /* 1744 * Runtime PM flows are not applicable for VFs, so it's safe to 1745 * directly enable IRQ. 1746 */ 1747 guc_enable_irq(guc); 1748 1749 xe_guc_ct_runtime_resume(&guc->ct); 1750 xe_guc_submit_enable(guc); 1751 xe_guc_submit_unpause(guc); 1752 } 1753 1754 int xe_guc_print_info(struct xe_guc *guc, struct drm_printer *p) 1755 { 1756 struct xe_gt *gt = guc_to_gt(guc); 1757 u32 status; 1758 int i; 1759 1760 xe_uc_fw_print(&guc->fw, p); 1761 1762 if (!IS_SRIOV_VF(gt_to_xe(gt))) { 1763 CLASS(xe_force_wake, fw_ref)(gt_to_fw(gt), XE_FW_GT); 1764 if (!fw_ref.domains) 1765 return -EIO; 1766 1767 status = xe_mmio_read32(>->mmio, GUC_STATUS); 1768 1769 drm_printf(p, "\nGuC status 0x%08x:\n", status); 1770 drm_printf(p, "\tBootrom status = 0x%x\n", 1771 REG_FIELD_GET(GS_BOOTROM_MASK, status)); 1772 drm_printf(p, "\tuKernel status = 0x%x\n", 1773 REG_FIELD_GET(GS_UKERNEL_MASK, status)); 1774 drm_printf(p, "\tMIA Core status = 0x%x\n", 1775 REG_FIELD_GET(GS_MIA_MASK, status)); 1776 drm_printf(p, "\tLog level = %d\n", 1777 xe_guc_log_get_level(&guc->log)); 1778 1779 drm_puts(p, "\nScratch registers:\n"); 1780 for (i = 0; i < SOFT_SCRATCH_COUNT; i++) { 1781 drm_printf(p, "\t%2d: \t0x%x\n", 1782 i, xe_mmio_read32(>->mmio, SOFT_SCRATCH(i))); 1783 } 1784 } 1785 1786 drm_puts(p, "\n"); 1787 xe_guc_ct_print(&guc->ct, p, false); 1788 1789 drm_puts(p, "\n"); 1790 xe_guc_submit_print(guc, p); 1791 1792 return 0; 1793 } 1794 1795 /** 1796 * xe_guc_declare_wedged() - Declare GuC wedged 1797 * @guc: the GuC object 1798 * 1799 * Wedge the GuC which stops all submission, saves desired debug state, and 1800 * cleans up anything which could timeout. 1801 */ 1802 void xe_guc_declare_wedged(struct xe_guc *guc) 1803 { 1804 xe_gt_assert(guc_to_gt(guc), guc_to_xe(guc)->wedged.mode); 1805 1806 xe_guc_reset_prepare(guc); 1807 xe_guc_ct_stop(&guc->ct); 1808 xe_guc_submit_wedge(guc); 1809 } 1810 1811 /** 1812 * xe_guc_using_main_gamctrl_queues() - Detect which reporting queues to use. 1813 * @guc: The GuC object 1814 * 1815 * For Xe3p and beyond, we want to program the hardware to use the 1816 * "Main GAMCTRL queue" rather than the legacy queue before we upload 1817 * the GuC firmware. This will allow the GuC to use a new set of 1818 * registers for pagefault handling and avoid some unnecessary 1819 * complications with MCR register range handling. 1820 * 1821 * Return: true if can use new main gamctrl queues. 1822 */ 1823 bool xe_guc_using_main_gamctrl_queues(struct xe_guc *guc) 1824 { 1825 struct xe_gt *gt = guc_to_gt(guc); 1826 1827 /* 1828 * For Xe3p media gt (35), the GuC and the CS subunits may be still Xe3 1829 * that lacks the Main GAMCTRL support. Reserved bits from the GMD_ID 1830 * inform the IP version of the subunits. 1831 */ 1832 if (xe_gt_is_media_type(gt) && MEDIA_VER(gt_to_xe(gt)) == 35) { 1833 u32 val = xe_mmio_read32(>->mmio, GMD_ID); 1834 u32 subip = REG_FIELD_GET(GMD_ID_SUBIP_FLAG_MASK, val); 1835 1836 if (!subip) 1837 return true; 1838 1839 xe_gt_WARN(gt, subip != 1, 1840 "GMD_ID has unknown value in the SUBIP_FLAG field - 0x%x\n", 1841 subip); 1842 1843 return false; 1844 } 1845 1846 return GT_VER(gt) >= 35; 1847 } 1848 1849 #if IS_ENABLED(CONFIG_DRM_XE_KUNIT_TEST) 1850 #include "tests/xe_guc_g2g_test.c" 1851 #endif 1852