1 // SPDX-License-Identifier: MIT 2 /* 3 * Copyright © 2014 Intel Corporation 4 */ 5 6 #include <linux/circ_buf.h> 7 8 #include "gem/i915_gem_context.h" 9 #include "gt/gen8_engine_cs.h" 10 #include "gt/intel_breadcrumbs.h" 11 #include "gt/intel_context.h" 12 #include "gt/intel_engine_pm.h" 13 #include "gt/intel_gt.h" 14 #include "gt/intel_gt_irq.h" 15 #include "gt/intel_gt_pm.h" 16 #include "gt/intel_lrc.h" 17 #include "gt/intel_mocs.h" 18 #include "gt/intel_ring.h" 19 20 #include "intel_guc_submission.h" 21 22 #include "i915_drv.h" 23 #include "i915_trace.h" 24 25 /** 26 * DOC: GuC-based command submission 27 * 28 * IMPORTANT NOTE: GuC submission is currently not supported in i915. The GuC 29 * firmware is moving to an updated submission interface and we plan to 30 * turn submission back on when that lands. The below documentation (and related 31 * code) matches the old submission model and will be updated as part of the 32 * upgrade to the new flow. 33 * 34 * GuC stage descriptor: 35 * During initialization, the driver allocates a static pool of 1024 such 36 * descriptors, and shares them with the GuC. Currently, we only use one 37 * descriptor. This stage descriptor lets the GuC know about the workqueue and 38 * process descriptor. Theoretically, it also lets the GuC know about our HW 39 * contexts (context ID, etc...), but we actually employ a kind of submission 40 * where the GuC uses the LRCA sent via the work item instead. This is called 41 * a "proxy" submission. 42 * 43 * The Scratch registers: 44 * There are 16 MMIO-based registers start from 0xC180. The kernel driver writes 45 * a value to the action register (SOFT_SCRATCH_0) along with any data. It then 46 * triggers an interrupt on the GuC via another register write (0xC4C8). 47 * Firmware writes a success/fail code back to the action register after 48 * processes the request. The kernel driver polls waiting for this update and 49 * then proceeds. 50 * 51 * Work Items: 52 * There are several types of work items that the host may place into a 53 * workqueue, each with its own requirements and limitations. Currently only 54 * WQ_TYPE_INORDER is needed to support legacy submission via GuC, which 55 * represents in-order queue. The kernel driver packs ring tail pointer and an 56 * ELSP context descriptor dword into Work Item. 57 * See guc_add_request() 58 * 59 */ 60 61 #define GUC_REQUEST_SIZE 64 /* bytes */ 62 63 static inline struct i915_priolist *to_priolist(struct rb_node *rb) 64 { 65 return rb_entry(rb, struct i915_priolist, node); 66 } 67 68 static struct guc_stage_desc *__get_stage_desc(struct intel_guc *guc, u32 id) 69 { 70 struct guc_stage_desc *base = guc->stage_desc_pool_vaddr; 71 72 return &base[id]; 73 } 74 75 static int guc_stage_desc_pool_create(struct intel_guc *guc) 76 { 77 u32 size = PAGE_ALIGN(sizeof(struct guc_stage_desc) * 78 GUC_MAX_STAGE_DESCRIPTORS); 79 80 return intel_guc_allocate_and_map_vma(guc, size, &guc->stage_desc_pool, 81 &guc->stage_desc_pool_vaddr); 82 } 83 84 static void guc_stage_desc_pool_destroy(struct intel_guc *guc) 85 { 86 i915_vma_unpin_and_release(&guc->stage_desc_pool, I915_VMA_RELEASE_MAP); 87 } 88 89 /* 90 * Initialise/clear the stage descriptor shared with the GuC firmware. 91 * 92 * This descriptor tells the GuC where (in GGTT space) to find the important 93 * data structures related to work submission (process descriptor, write queue, 94 * etc). 95 */ 96 static void guc_stage_desc_init(struct intel_guc *guc) 97 { 98 struct guc_stage_desc *desc; 99 100 /* we only use 1 stage desc, so hardcode it to 0 */ 101 desc = __get_stage_desc(guc, 0); 102 memset(desc, 0, sizeof(*desc)); 103 104 desc->attribute = GUC_STAGE_DESC_ATTR_ACTIVE | 105 GUC_STAGE_DESC_ATTR_KERNEL; 106 107 desc->stage_id = 0; 108 desc->priority = GUC_CLIENT_PRIORITY_KMD_NORMAL; 109 110 desc->wq_size = GUC_WQ_SIZE; 111 } 112 113 static void guc_stage_desc_fini(struct intel_guc *guc) 114 { 115 struct guc_stage_desc *desc; 116 117 desc = __get_stage_desc(guc, 0); 118 memset(desc, 0, sizeof(*desc)); 119 } 120 121 static void guc_add_request(struct intel_guc *guc, struct i915_request *rq) 122 { 123 /* Leaving stub as this function will be used in future patches */ 124 } 125 126 /* 127 * When we're doing submissions using regular execlists backend, writing to 128 * ELSP from CPU side is enough to make sure that writes to ringbuffer pages 129 * pinned in mappable aperture portion of GGTT are visible to command streamer. 130 * Writes done by GuC on our behalf are not guaranteeing such ordering, 131 * therefore, to ensure the flush, we're issuing a POSTING READ. 132 */ 133 static void flush_ggtt_writes(struct i915_vma *vma) 134 { 135 if (i915_vma_is_map_and_fenceable(vma)) 136 intel_uncore_posting_read_fw(vma->vm->gt->uncore, 137 GUC_STATUS); 138 } 139 140 static void guc_submit(struct intel_engine_cs *engine, 141 struct i915_request **out, 142 struct i915_request **end) 143 { 144 struct intel_guc *guc = &engine->gt->uc.guc; 145 146 do { 147 struct i915_request *rq = *out++; 148 149 flush_ggtt_writes(rq->ring->vma); 150 guc_add_request(guc, rq); 151 } while (out != end); 152 } 153 154 static inline int rq_prio(const struct i915_request *rq) 155 { 156 return rq->sched.attr.priority; 157 } 158 159 static struct i915_request *schedule_in(struct i915_request *rq, int idx) 160 { 161 trace_i915_request_in(rq, idx); 162 163 /* 164 * Currently we are not tracking the rq->context being inflight 165 * (ce->inflight = rq->engine). It is only used by the execlists 166 * backend at the moment, a similar counting strategy would be 167 * required if we generalise the inflight tracking. 168 */ 169 170 __intel_gt_pm_get(rq->engine->gt); 171 return i915_request_get(rq); 172 } 173 174 static void schedule_out(struct i915_request *rq) 175 { 176 trace_i915_request_out(rq); 177 178 intel_gt_pm_put_async(rq->engine->gt); 179 i915_request_put(rq); 180 } 181 182 static void __guc_dequeue(struct intel_engine_cs *engine) 183 { 184 struct intel_engine_execlists * const execlists = &engine->execlists; 185 struct i915_request **first = execlists->inflight; 186 struct i915_request ** const last_port = first + execlists->port_mask; 187 struct i915_request *last = first[0]; 188 struct i915_request **port; 189 bool submit = false; 190 struct rb_node *rb; 191 192 lockdep_assert_held(&engine->active.lock); 193 194 if (last) { 195 if (*++first) 196 return; 197 198 last = NULL; 199 } 200 201 /* 202 * We write directly into the execlists->inflight queue and don't use 203 * the execlists->pending queue, as we don't have a distinct switch 204 * event. 205 */ 206 port = first; 207 while ((rb = rb_first_cached(&execlists->queue))) { 208 struct i915_priolist *p = to_priolist(rb); 209 struct i915_request *rq, *rn; 210 211 priolist_for_each_request_consume(rq, rn, p) { 212 if (last && rq->context != last->context) { 213 if (port == last_port) 214 goto done; 215 216 *port = schedule_in(last, 217 port - execlists->inflight); 218 port++; 219 } 220 221 list_del_init(&rq->sched.link); 222 __i915_request_submit(rq); 223 submit = true; 224 last = rq; 225 } 226 227 rb_erase_cached(&p->node, &execlists->queue); 228 i915_priolist_free(p); 229 } 230 done: 231 execlists->queue_priority_hint = 232 rb ? to_priolist(rb)->priority : INT_MIN; 233 if (submit) { 234 *port = schedule_in(last, port - execlists->inflight); 235 *++port = NULL; 236 guc_submit(engine, first, port); 237 } 238 execlists->active = execlists->inflight; 239 } 240 241 static void guc_submission_tasklet(struct tasklet_struct *t) 242 { 243 struct intel_engine_cs * const engine = 244 from_tasklet(engine, t, execlists.tasklet); 245 struct intel_engine_execlists * const execlists = &engine->execlists; 246 struct i915_request **port, *rq; 247 unsigned long flags; 248 249 spin_lock_irqsave(&engine->active.lock, flags); 250 251 for (port = execlists->inflight; (rq = *port); port++) { 252 if (!i915_request_completed(rq)) 253 break; 254 255 schedule_out(rq); 256 } 257 if (port != execlists->inflight) { 258 int idx = port - execlists->inflight; 259 int rem = ARRAY_SIZE(execlists->inflight) - idx; 260 memmove(execlists->inflight, port, rem * sizeof(*port)); 261 } 262 263 __guc_dequeue(engine); 264 265 spin_unlock_irqrestore(&engine->active.lock, flags); 266 } 267 268 static void cs_irq_handler(struct intel_engine_cs *engine, u16 iir) 269 { 270 if (iir & GT_RENDER_USER_INTERRUPT) { 271 intel_engine_signal_breadcrumbs(engine); 272 tasklet_hi_schedule(&engine->execlists.tasklet); 273 } 274 } 275 276 static void guc_reset_prepare(struct intel_engine_cs *engine) 277 { 278 struct intel_engine_execlists * const execlists = &engine->execlists; 279 280 ENGINE_TRACE(engine, "\n"); 281 282 /* 283 * Prevent request submission to the hardware until we have 284 * completed the reset in i915_gem_reset_finish(). If a request 285 * is completed by one engine, it may then queue a request 286 * to a second via its execlists->tasklet *just* as we are 287 * calling engine->init_hw() and also writing the ELSP. 288 * Turning off the execlists->tasklet until the reset is over 289 * prevents the race. 290 */ 291 __tasklet_disable_sync_once(&execlists->tasklet); 292 } 293 294 static void guc_reset_state(struct intel_context *ce, 295 struct intel_engine_cs *engine, 296 u32 head, 297 bool scrub) 298 { 299 GEM_BUG_ON(!intel_context_is_pinned(ce)); 300 301 /* 302 * We want a simple context + ring to execute the breadcrumb update. 303 * We cannot rely on the context being intact across the GPU hang, 304 * so clear it and rebuild just what we need for the breadcrumb. 305 * All pending requests for this context will be zapped, and any 306 * future request will be after userspace has had the opportunity 307 * to recreate its own state. 308 */ 309 if (scrub) 310 lrc_init_regs(ce, engine, true); 311 312 /* Rerun the request; its payload has been neutered (if guilty). */ 313 lrc_update_regs(ce, engine, head); 314 } 315 316 static void guc_reset_rewind(struct intel_engine_cs *engine, bool stalled) 317 { 318 struct intel_engine_execlists * const execlists = &engine->execlists; 319 struct i915_request *rq; 320 unsigned long flags; 321 322 spin_lock_irqsave(&engine->active.lock, flags); 323 324 /* Push back any incomplete requests for replay after the reset. */ 325 rq = execlists_unwind_incomplete_requests(execlists); 326 if (!rq) 327 goto out_unlock; 328 329 if (!i915_request_started(rq)) 330 stalled = false; 331 332 __i915_request_reset(rq, stalled); 333 guc_reset_state(rq->context, engine, rq->head, stalled); 334 335 out_unlock: 336 spin_unlock_irqrestore(&engine->active.lock, flags); 337 } 338 339 static void guc_reset_cancel(struct intel_engine_cs *engine) 340 { 341 struct intel_engine_execlists * const execlists = &engine->execlists; 342 struct i915_request *rq, *rn; 343 struct rb_node *rb; 344 unsigned long flags; 345 346 ENGINE_TRACE(engine, "\n"); 347 348 /* 349 * Before we call engine->cancel_requests(), we should have exclusive 350 * access to the submission state. This is arranged for us by the 351 * caller disabling the interrupt generation, the tasklet and other 352 * threads that may then access the same state, giving us a free hand 353 * to reset state. However, we still need to let lockdep be aware that 354 * we know this state may be accessed in hardirq context, so we 355 * disable the irq around this manipulation and we want to keep 356 * the spinlock focused on its duties and not accidentally conflate 357 * coverage to the submission's irq state. (Similarly, although we 358 * shouldn't need to disable irq around the manipulation of the 359 * submission's irq state, we also wish to remind ourselves that 360 * it is irq state.) 361 */ 362 spin_lock_irqsave(&engine->active.lock, flags); 363 364 /* Mark all executing requests as skipped. */ 365 list_for_each_entry(rq, &engine->active.requests, sched.link) { 366 i915_request_set_error_once(rq, -EIO); 367 i915_request_mark_complete(rq); 368 } 369 370 /* Flush the queued requests to the timeline list (for retiring). */ 371 while ((rb = rb_first_cached(&execlists->queue))) { 372 struct i915_priolist *p = to_priolist(rb); 373 374 priolist_for_each_request_consume(rq, rn, p) { 375 list_del_init(&rq->sched.link); 376 __i915_request_submit(rq); 377 dma_fence_set_error(&rq->fence, -EIO); 378 i915_request_mark_complete(rq); 379 } 380 381 rb_erase_cached(&p->node, &execlists->queue); 382 i915_priolist_free(p); 383 } 384 385 /* Remaining _unready_ requests will be nop'ed when submitted */ 386 387 execlists->queue_priority_hint = INT_MIN; 388 execlists->queue = RB_ROOT_CACHED; 389 390 spin_unlock_irqrestore(&engine->active.lock, flags); 391 } 392 393 static void guc_reset_finish(struct intel_engine_cs *engine) 394 { 395 struct intel_engine_execlists * const execlists = &engine->execlists; 396 397 if (__tasklet_enable(&execlists->tasklet)) 398 /* And kick in case we missed a new request submission. */ 399 tasklet_hi_schedule(&execlists->tasklet); 400 401 ENGINE_TRACE(engine, "depth->%d\n", 402 atomic_read(&execlists->tasklet.count)); 403 } 404 405 /* 406 * Set up the memory resources to be shared with the GuC (via the GGTT) 407 * at firmware loading time. 408 */ 409 int intel_guc_submission_init(struct intel_guc *guc) 410 { 411 int ret; 412 413 if (guc->stage_desc_pool) 414 return 0; 415 416 ret = guc_stage_desc_pool_create(guc); 417 if (ret) 418 return ret; 419 /* 420 * Keep static analysers happy, let them know that we allocated the 421 * vma after testing that it didn't exist earlier. 422 */ 423 GEM_BUG_ON(!guc->stage_desc_pool); 424 425 return 0; 426 } 427 428 void intel_guc_submission_fini(struct intel_guc *guc) 429 { 430 if (guc->stage_desc_pool) { 431 guc_stage_desc_pool_destroy(guc); 432 } 433 } 434 435 static void guc_interrupts_capture(struct intel_gt *gt) 436 { 437 struct intel_uncore *uncore = gt->uncore; 438 u32 irqs = GT_CONTEXT_SWITCH_INTERRUPT; 439 u32 dmask = irqs << 16 | irqs; 440 441 GEM_BUG_ON(INTEL_GEN(gt->i915) < 11); 442 443 /* Don't handle the ctx switch interrupt in GuC submission mode */ 444 intel_uncore_rmw(uncore, GEN11_RENDER_COPY_INTR_ENABLE, dmask, 0); 445 intel_uncore_rmw(uncore, GEN11_VCS_VECS_INTR_ENABLE, dmask, 0); 446 } 447 448 static void guc_interrupts_release(struct intel_gt *gt) 449 { 450 struct intel_uncore *uncore = gt->uncore; 451 u32 irqs = GT_CONTEXT_SWITCH_INTERRUPT; 452 u32 dmask = irqs << 16 | irqs; 453 454 GEM_BUG_ON(INTEL_GEN(gt->i915) < 11); 455 456 /* Handle ctx switch interrupts again */ 457 intel_uncore_rmw(uncore, GEN11_RENDER_COPY_INTR_ENABLE, 0, dmask); 458 intel_uncore_rmw(uncore, GEN11_VCS_VECS_INTR_ENABLE, 0, dmask); 459 } 460 461 static int guc_context_alloc(struct intel_context *ce) 462 { 463 return lrc_alloc(ce, ce->engine); 464 } 465 466 static int guc_context_pre_pin(struct intel_context *ce, 467 struct i915_gem_ww_ctx *ww, 468 void **vaddr) 469 { 470 return lrc_pre_pin(ce, ce->engine, ww, vaddr); 471 } 472 473 static int guc_context_pin(struct intel_context *ce, void *vaddr) 474 { 475 return lrc_pin(ce, ce->engine, vaddr); 476 } 477 478 static const struct intel_context_ops guc_context_ops = { 479 .alloc = guc_context_alloc, 480 481 .pre_pin = guc_context_pre_pin, 482 .pin = guc_context_pin, 483 .unpin = lrc_unpin, 484 .post_unpin = lrc_post_unpin, 485 486 .enter = intel_context_enter_engine, 487 .exit = intel_context_exit_engine, 488 489 .reset = lrc_reset, 490 .destroy = lrc_destroy, 491 }; 492 493 static int guc_request_alloc(struct i915_request *request) 494 { 495 int ret; 496 497 GEM_BUG_ON(!intel_context_is_pinned(request->context)); 498 499 /* 500 * Flush enough space to reduce the likelihood of waiting after 501 * we start building the request - in which case we will just 502 * have to repeat work. 503 */ 504 request->reserved_space += GUC_REQUEST_SIZE; 505 506 /* 507 * Note that after this point, we have committed to using 508 * this request as it is being used to both track the 509 * state of engine initialisation and liveness of the 510 * golden renderstate above. Think twice before you try 511 * to cancel/unwind this request now. 512 */ 513 514 /* Unconditionally invalidate GPU caches and TLBs. */ 515 ret = request->engine->emit_flush(request, EMIT_INVALIDATE); 516 if (ret) 517 return ret; 518 519 request->reserved_space -= GUC_REQUEST_SIZE; 520 return 0; 521 } 522 523 static inline void queue_request(struct intel_engine_cs *engine, 524 struct i915_request *rq, 525 int prio) 526 { 527 GEM_BUG_ON(!list_empty(&rq->sched.link)); 528 list_add_tail(&rq->sched.link, 529 i915_sched_lookup_priolist(engine, prio)); 530 set_bit(I915_FENCE_FLAG_PQUEUE, &rq->fence.flags); 531 } 532 533 static void guc_submit_request(struct i915_request *rq) 534 { 535 struct intel_engine_cs *engine = rq->engine; 536 unsigned long flags; 537 538 /* Will be called from irq-context when using foreign fences. */ 539 spin_lock_irqsave(&engine->active.lock, flags); 540 541 queue_request(engine, rq, rq_prio(rq)); 542 543 GEM_BUG_ON(RB_EMPTY_ROOT(&engine->execlists.queue.rb_root)); 544 GEM_BUG_ON(list_empty(&rq->sched.link)); 545 546 tasklet_hi_schedule(&engine->execlists.tasklet); 547 548 spin_unlock_irqrestore(&engine->active.lock, flags); 549 } 550 551 static void sanitize_hwsp(struct intel_engine_cs *engine) 552 { 553 struct intel_timeline *tl; 554 555 list_for_each_entry(tl, &engine->status_page.timelines, engine_link) 556 intel_timeline_reset_seqno(tl); 557 } 558 559 static void guc_sanitize(struct intel_engine_cs *engine) 560 { 561 /* 562 * Poison residual state on resume, in case the suspend didn't! 563 * 564 * We have to assume that across suspend/resume (or other loss 565 * of control) that the contents of our pinned buffers has been 566 * lost, replaced by garbage. Since this doesn't always happen, 567 * let's poison such state so that we more quickly spot when 568 * we falsely assume it has been preserved. 569 */ 570 if (IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)) 571 memset(engine->status_page.addr, POISON_INUSE, PAGE_SIZE); 572 573 /* 574 * The kernel_context HWSP is stored in the status_page. As above, 575 * that may be lost on resume/initialisation, and so we need to 576 * reset the value in the HWSP. 577 */ 578 sanitize_hwsp(engine); 579 580 /* And scrub the dirty cachelines for the HWSP */ 581 clflush_cache_range(engine->status_page.addr, PAGE_SIZE); 582 } 583 584 static void setup_hwsp(struct intel_engine_cs *engine) 585 { 586 intel_engine_set_hwsp_writemask(engine, ~0u); /* HWSTAM */ 587 588 ENGINE_WRITE_FW(engine, 589 RING_HWS_PGA, 590 i915_ggtt_offset(engine->status_page.vma)); 591 } 592 593 static void start_engine(struct intel_engine_cs *engine) 594 { 595 ENGINE_WRITE_FW(engine, 596 RING_MODE_GEN7, 597 _MASKED_BIT_ENABLE(GEN11_GFX_DISABLE_LEGACY_MODE)); 598 599 ENGINE_WRITE_FW(engine, RING_MI_MODE, _MASKED_BIT_DISABLE(STOP_RING)); 600 ENGINE_POSTING_READ(engine, RING_MI_MODE); 601 } 602 603 static int guc_resume(struct intel_engine_cs *engine) 604 { 605 assert_forcewakes_active(engine->uncore, FORCEWAKE_ALL); 606 607 intel_mocs_init_engine(engine); 608 609 intel_breadcrumbs_reset(engine->breadcrumbs); 610 611 setup_hwsp(engine); 612 start_engine(engine); 613 614 return 0; 615 } 616 617 static void guc_set_default_submission(struct intel_engine_cs *engine) 618 { 619 engine->submit_request = guc_submit_request; 620 } 621 622 static void guc_release(struct intel_engine_cs *engine) 623 { 624 engine->sanitize = NULL; /* no longer in control, nothing to sanitize */ 625 626 tasklet_kill(&engine->execlists.tasklet); 627 628 intel_engine_cleanup_common(engine); 629 lrc_fini_wa_ctx(engine); 630 } 631 632 static void guc_default_vfuncs(struct intel_engine_cs *engine) 633 { 634 /* Default vfuncs which can be overridden by each engine. */ 635 636 engine->resume = guc_resume; 637 638 engine->cops = &guc_context_ops; 639 engine->request_alloc = guc_request_alloc; 640 641 engine->schedule = i915_schedule; 642 643 engine->reset.prepare = guc_reset_prepare; 644 engine->reset.rewind = guc_reset_rewind; 645 engine->reset.cancel = guc_reset_cancel; 646 engine->reset.finish = guc_reset_finish; 647 648 engine->emit_flush = gen8_emit_flush_xcs; 649 engine->emit_init_breadcrumb = gen8_emit_init_breadcrumb; 650 engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_xcs; 651 if (INTEL_GEN(engine->i915) >= 12) { 652 engine->emit_fini_breadcrumb = gen12_emit_fini_breadcrumb_xcs; 653 engine->emit_flush = gen12_emit_flush_xcs; 654 } 655 engine->set_default_submission = guc_set_default_submission; 656 657 engine->flags |= I915_ENGINE_HAS_PREEMPTION; 658 659 /* 660 * TODO: GuC supports timeslicing and semaphores as well, but they're 661 * handled by the firmware so some minor tweaks are required before 662 * enabling. 663 * 664 * engine->flags |= I915_ENGINE_HAS_TIMESLICES; 665 * engine->flags |= I915_ENGINE_HAS_SEMAPHORES; 666 */ 667 668 engine->emit_bb_start = gen8_emit_bb_start; 669 } 670 671 static void rcs_submission_override(struct intel_engine_cs *engine) 672 { 673 switch (INTEL_GEN(engine->i915)) { 674 case 12: 675 engine->emit_flush = gen12_emit_flush_rcs; 676 engine->emit_fini_breadcrumb = gen12_emit_fini_breadcrumb_rcs; 677 break; 678 case 11: 679 engine->emit_flush = gen11_emit_flush_rcs; 680 engine->emit_fini_breadcrumb = gen11_emit_fini_breadcrumb_rcs; 681 break; 682 default: 683 engine->emit_flush = gen8_emit_flush_rcs; 684 engine->emit_fini_breadcrumb = gen8_emit_fini_breadcrumb_rcs; 685 break; 686 } 687 } 688 689 static inline void guc_default_irqs(struct intel_engine_cs *engine) 690 { 691 engine->irq_keep_mask = GT_RENDER_USER_INTERRUPT; 692 intel_engine_set_irq_handler(engine, cs_irq_handler); 693 } 694 695 int intel_guc_submission_setup(struct intel_engine_cs *engine) 696 { 697 struct drm_i915_private *i915 = engine->i915; 698 699 /* 700 * The setup relies on several assumptions (e.g. irqs always enabled) 701 * that are only valid on gen11+ 702 */ 703 GEM_BUG_ON(INTEL_GEN(i915) < 11); 704 705 tasklet_setup(&engine->execlists.tasklet, guc_submission_tasklet); 706 707 guc_default_vfuncs(engine); 708 guc_default_irqs(engine); 709 710 if (engine->class == RENDER_CLASS) 711 rcs_submission_override(engine); 712 713 lrc_init_wa_ctx(engine); 714 715 /* Finally, take ownership and responsibility for cleanup! */ 716 engine->sanitize = guc_sanitize; 717 engine->release = guc_release; 718 719 return 0; 720 } 721 722 void intel_guc_submission_enable(struct intel_guc *guc) 723 { 724 guc_stage_desc_init(guc); 725 726 /* Take over from manual control of ELSP (execlists) */ 727 guc_interrupts_capture(guc_to_gt(guc)); 728 } 729 730 void intel_guc_submission_disable(struct intel_guc *guc) 731 { 732 struct intel_gt *gt = guc_to_gt(guc); 733 734 GEM_BUG_ON(gt->awake); /* GT should be parked first */ 735 736 /* Note: By the time we're here, GuC may have already been reset */ 737 738 guc_interrupts_release(gt); 739 740 guc_stage_desc_fini(guc); 741 } 742 743 static bool __guc_submission_selected(struct intel_guc *guc) 744 { 745 struct drm_i915_private *i915 = guc_to_gt(guc)->i915; 746 747 if (!intel_guc_submission_is_supported(guc)) 748 return false; 749 750 return i915->params.enable_guc & ENABLE_GUC_SUBMISSION; 751 } 752 753 void intel_guc_submission_init_early(struct intel_guc *guc) 754 { 755 guc->submission_selected = __guc_submission_selected(guc); 756 } 757