]> Git Repo - linux.git/blob - drivers/gpu/drm/i915/intel_guc_submission.c
Merge tag 'for-4.18/dm-changes-v2' of git://git.kernel.org/pub/scm/linux/kernel/git...
[linux.git] / drivers / gpu / drm / i915 / intel_guc_submission.c
1 /*
2  * Copyright © 2014 Intel Corporation
3  *
4  * Permission is hereby granted, free of charge, to any person obtaining a
5  * copy of this software and associated documentation files (the "Software"),
6  * to deal in the Software without restriction, including without limitation
7  * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8  * and/or sell copies of the Software, and to permit persons to whom the
9  * Software is furnished to do so, subject to the following conditions:
10  *
11  * The above copyright notice and this permission notice (including the next
12  * paragraph) shall be included in all copies or substantial portions of the
13  * Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16  * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17  * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
18  * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19  * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20  * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
21  * IN THE SOFTWARE.
22  *
23  */
24
25 #include <linux/circ_buf.h>
26 #include <trace/events/dma_fence.h>
27
28 #include "intel_guc_submission.h"
29 #include "intel_lrc_reg.h"
30 #include "i915_drv.h"
31
32 #define GUC_PREEMPT_FINISHED            0x1
33 #define GUC_PREEMPT_BREADCRUMB_DWORDS   0x8
34 #define GUC_PREEMPT_BREADCRUMB_BYTES    \
35         (sizeof(u32) * GUC_PREEMPT_BREADCRUMB_DWORDS)
36
37 /**
38  * DOC: GuC-based command submission
39  *
40  * GuC client:
41  * A intel_guc_client refers to a submission path through GuC. Currently, there
42  * are two clients. One of them (the execbuf_client) is charged with all
43  * submissions to the GuC, the other one (preempt_client) is responsible for
44  * preempting the execbuf_client. This struct is the owner of a doorbell, a
45  * process descriptor and a workqueue (all of them inside a single gem object
46  * that contains all required pages for these elements).
47  *
48  * GuC stage descriptor:
49  * During initialization, the driver allocates a static pool of 1024 such
50  * descriptors, and shares them with the GuC.
51  * Currently, there exists a 1:1 mapping between a intel_guc_client and a
52  * guc_stage_desc (via the client's stage_id), so effectively only one
53  * gets used. This stage descriptor lets the GuC know about the doorbell,
54  * workqueue and process descriptor. Theoretically, it also lets the GuC
55  * know about our HW contexts (context ID, etc...), but we actually
56  * employ a kind of submission where the GuC uses the LRCA sent via the work
57  * item instead (the single guc_stage_desc associated to execbuf client
58  * contains information about the default kernel context only, but this is
59  * essentially unused). This is called a "proxy" submission.
60  *
61  * The Scratch registers:
62  * There are 16 MMIO-based registers start from 0xC180. The kernel driver writes
63  * a value to the action register (SOFT_SCRATCH_0) along with any data. It then
64  * triggers an interrupt on the GuC via another register write (0xC4C8).
65  * Firmware writes a success/fail code back to the action register after
66  * processes the request. The kernel driver polls waiting for this update and
67  * then proceeds.
68  * See intel_guc_send()
69  *
70  * Doorbells:
71  * Doorbells are interrupts to uKernel. A doorbell is a single cache line (QW)
72  * mapped into process space.
73  *
74  * Work Items:
75  * There are several types of work items that the host may place into a
76  * workqueue, each with its own requirements and limitations. Currently only
77  * WQ_TYPE_INORDER is needed to support legacy submission via GuC, which
78  * represents in-order queue. The kernel driver packs ring tail pointer and an
79  * ELSP context descriptor dword into Work Item.
80  * See guc_add_request()
81  *
82  */
83
84 static inline struct i915_priolist *to_priolist(struct rb_node *rb)
85 {
86         return rb_entry(rb, struct i915_priolist, node);
87 }
88
89 static inline bool is_high_priority(struct intel_guc_client *client)
90 {
91         return (client->priority == GUC_CLIENT_PRIORITY_KMD_HIGH ||
92                 client->priority == GUC_CLIENT_PRIORITY_HIGH);
93 }
94
95 static int reserve_doorbell(struct intel_guc_client *client)
96 {
97         unsigned long offset;
98         unsigned long end;
99         u16 id;
100
101         GEM_BUG_ON(client->doorbell_id != GUC_DOORBELL_INVALID);
102
103         /*
104          * The bitmap tracks which doorbell registers are currently in use.
105          * It is split into two halves; the first half is used for normal
106          * priority contexts, the second half for high-priority ones.
107          */
108         offset = 0;
109         end = GUC_NUM_DOORBELLS / 2;
110         if (is_high_priority(client)) {
111                 offset = end;
112                 end += offset;
113         }
114
115         id = find_next_zero_bit(client->guc->doorbell_bitmap, end, offset);
116         if (id == end)
117                 return -ENOSPC;
118
119         __set_bit(id, client->guc->doorbell_bitmap);
120         client->doorbell_id = id;
121         DRM_DEBUG_DRIVER("client %u (high prio=%s) reserved doorbell: %d\n",
122                          client->stage_id, yesno(is_high_priority(client)),
123                          id);
124         return 0;
125 }
126
127 static bool has_doorbell(struct intel_guc_client *client)
128 {
129         if (client->doorbell_id == GUC_DOORBELL_INVALID)
130                 return false;
131
132         return test_bit(client->doorbell_id, client->guc->doorbell_bitmap);
133 }
134
135 static void unreserve_doorbell(struct intel_guc_client *client)
136 {
137         GEM_BUG_ON(!has_doorbell(client));
138
139         __clear_bit(client->doorbell_id, client->guc->doorbell_bitmap);
140         client->doorbell_id = GUC_DOORBELL_INVALID;
141 }
142
143 /*
144  * Tell the GuC to allocate or deallocate a specific doorbell
145  */
146
147 static int __guc_allocate_doorbell(struct intel_guc *guc, u32 stage_id)
148 {
149         u32 action[] = {
150                 INTEL_GUC_ACTION_ALLOCATE_DOORBELL,
151                 stage_id
152         };
153
154         return intel_guc_send(guc, action, ARRAY_SIZE(action));
155 }
156
157 static int __guc_deallocate_doorbell(struct intel_guc *guc, u32 stage_id)
158 {
159         u32 action[] = {
160                 INTEL_GUC_ACTION_DEALLOCATE_DOORBELL,
161                 stage_id
162         };
163
164         return intel_guc_send(guc, action, ARRAY_SIZE(action));
165 }
166
167 static struct guc_stage_desc *__get_stage_desc(struct intel_guc_client *client)
168 {
169         struct guc_stage_desc *base = client->guc->stage_desc_pool_vaddr;
170
171         return &base[client->stage_id];
172 }
173
174 /*
175  * Initialise, update, or clear doorbell data shared with the GuC
176  *
177  * These functions modify shared data and so need access to the mapped
178  * client object which contains the page being used for the doorbell
179  */
180
181 static void __update_doorbell_desc(struct intel_guc_client *client, u16 new_id)
182 {
183         struct guc_stage_desc *desc;
184
185         /* Update the GuC's idea of the doorbell ID */
186         desc = __get_stage_desc(client);
187         desc->db_id = new_id;
188 }
189
190 static struct guc_doorbell_info *__get_doorbell(struct intel_guc_client *client)
191 {
192         return client->vaddr + client->doorbell_offset;
193 }
194
195 static void __create_doorbell(struct intel_guc_client *client)
196 {
197         struct guc_doorbell_info *doorbell;
198
199         doorbell = __get_doorbell(client);
200         doorbell->db_status = GUC_DOORBELL_ENABLED;
201         doorbell->cookie = 0;
202 }
203
204 static void __destroy_doorbell(struct intel_guc_client *client)
205 {
206         struct drm_i915_private *dev_priv = guc_to_i915(client->guc);
207         struct guc_doorbell_info *doorbell;
208         u16 db_id = client->doorbell_id;
209
210         doorbell = __get_doorbell(client);
211         doorbell->db_status = GUC_DOORBELL_DISABLED;
212         doorbell->cookie = 0;
213
214         /* Doorbell release flow requires that we wait for GEN8_DRB_VALID bit
215          * to go to zero after updating db_status before we call the GuC to
216          * release the doorbell
217          */
218         if (wait_for_us(!(I915_READ(GEN8_DRBREGL(db_id)) & GEN8_DRB_VALID), 10))
219                 WARN_ONCE(true, "Doorbell never became invalid after disable\n");
220 }
221
222 static int create_doorbell(struct intel_guc_client *client)
223 {
224         int ret;
225
226         if (WARN_ON(!has_doorbell(client)))
227                 return -ENODEV; /* internal setup error, should never happen */
228
229         __update_doorbell_desc(client, client->doorbell_id);
230         __create_doorbell(client);
231
232         ret = __guc_allocate_doorbell(client->guc, client->stage_id);
233         if (ret) {
234                 __destroy_doorbell(client);
235                 __update_doorbell_desc(client, GUC_DOORBELL_INVALID);
236                 DRM_DEBUG_DRIVER("Couldn't create client %u doorbell: %d\n",
237                                  client->stage_id, ret);
238                 return ret;
239         }
240
241         return 0;
242 }
243
244 static int destroy_doorbell(struct intel_guc_client *client)
245 {
246         int ret;
247
248         GEM_BUG_ON(!has_doorbell(client));
249
250         __destroy_doorbell(client);
251         ret = __guc_deallocate_doorbell(client->guc, client->stage_id);
252         if (ret)
253                 DRM_ERROR("Couldn't destroy client %u doorbell: %d\n",
254                           client->stage_id, ret);
255
256         __update_doorbell_desc(client, GUC_DOORBELL_INVALID);
257
258         return ret;
259 }
260
261 static unsigned long __select_cacheline(struct intel_guc *guc)
262 {
263         unsigned long offset;
264
265         /* Doorbell uses a single cache line within a page */
266         offset = offset_in_page(guc->db_cacheline);
267
268         /* Moving to next cache line to reduce contention */
269         guc->db_cacheline += cache_line_size();
270
271         DRM_DEBUG_DRIVER("reserved cacheline 0x%lx, next 0x%x, linesize %u\n",
272                          offset, guc->db_cacheline, cache_line_size());
273         return offset;
274 }
275
276 static inline struct guc_process_desc *
277 __get_process_desc(struct intel_guc_client *client)
278 {
279         return client->vaddr + client->proc_desc_offset;
280 }
281
282 /*
283  * Initialise the process descriptor shared with the GuC firmware.
284  */
285 static void guc_proc_desc_init(struct intel_guc *guc,
286                                struct intel_guc_client *client)
287 {
288         struct guc_process_desc *desc;
289
290         desc = memset(__get_process_desc(client), 0, sizeof(*desc));
291
292         /*
293          * XXX: pDoorbell and WQVBaseAddress are pointers in process address
294          * space for ring3 clients (set them as in mmap_ioctl) or kernel
295          * space for kernel clients (map on demand instead? May make debug
296          * easier to have it mapped).
297          */
298         desc->wq_base_addr = 0;
299         desc->db_base_addr = 0;
300
301         desc->stage_id = client->stage_id;
302         desc->wq_size_bytes = GUC_WQ_SIZE;
303         desc->wq_status = WQ_STATUS_ACTIVE;
304         desc->priority = client->priority;
305 }
306
307 static int guc_stage_desc_pool_create(struct intel_guc *guc)
308 {
309         struct i915_vma *vma;
310         void *vaddr;
311
312         vma = intel_guc_allocate_vma(guc,
313                                      PAGE_ALIGN(sizeof(struct guc_stage_desc) *
314                                      GUC_MAX_STAGE_DESCRIPTORS));
315         if (IS_ERR(vma))
316                 return PTR_ERR(vma);
317
318         vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB);
319         if (IS_ERR(vaddr)) {
320                 i915_vma_unpin_and_release(&vma);
321                 return PTR_ERR(vaddr);
322         }
323
324         guc->stage_desc_pool = vma;
325         guc->stage_desc_pool_vaddr = vaddr;
326         ida_init(&guc->stage_ids);
327
328         return 0;
329 }
330
331 static void guc_stage_desc_pool_destroy(struct intel_guc *guc)
332 {
333         ida_destroy(&guc->stage_ids);
334         i915_gem_object_unpin_map(guc->stage_desc_pool->obj);
335         i915_vma_unpin_and_release(&guc->stage_desc_pool);
336 }
337
338 /*
339  * Initialise/clear the stage descriptor shared with the GuC firmware.
340  *
341  * This descriptor tells the GuC where (in GGTT space) to find the important
342  * data structures relating to this client (doorbell, process descriptor,
343  * write queue, etc).
344  */
345 static void guc_stage_desc_init(struct intel_guc *guc,
346                                 struct intel_guc_client *client)
347 {
348         struct drm_i915_private *dev_priv = guc_to_i915(guc);
349         struct intel_engine_cs *engine;
350         struct i915_gem_context *ctx = client->owner;
351         struct guc_stage_desc *desc;
352         unsigned int tmp;
353         u32 gfx_addr;
354
355         desc = __get_stage_desc(client);
356         memset(desc, 0, sizeof(*desc));
357
358         desc->attribute = GUC_STAGE_DESC_ATTR_ACTIVE |
359                           GUC_STAGE_DESC_ATTR_KERNEL;
360         if (is_high_priority(client))
361                 desc->attribute |= GUC_STAGE_DESC_ATTR_PREEMPT;
362         desc->stage_id = client->stage_id;
363         desc->priority = client->priority;
364         desc->db_id = client->doorbell_id;
365
366         for_each_engine_masked(engine, dev_priv, client->engines, tmp) {
367                 struct intel_context *ce = to_intel_context(ctx, engine);
368                 u32 guc_engine_id = engine->guc_id;
369                 struct guc_execlist_context *lrc = &desc->lrc[guc_engine_id];
370
371                 /* TODO: We have a design issue to be solved here. Only when we
372                  * receive the first batch, we know which engine is used by the
373                  * user. But here GuC expects the lrc and ring to be pinned. It
374                  * is not an issue for default context, which is the only one
375                  * for now who owns a GuC client. But for future owner of GuC
376                  * client, need to make sure lrc is pinned prior to enter here.
377                  */
378                 if (!ce->state)
379                         break;  /* XXX: continue? */
380
381                 /*
382                  * XXX: When this is a GUC_STAGE_DESC_ATTR_KERNEL client (proxy
383                  * submission or, in other words, not using a direct submission
384                  * model) the KMD's LRCA is not used for any work submission.
385                  * Instead, the GuC uses the LRCA of the user mode context (see
386                  * guc_add_request below).
387                  */
388                 lrc->context_desc = lower_32_bits(ce->lrc_desc);
389
390                 /* The state page is after PPHWSP */
391                 lrc->ring_lrca = intel_guc_ggtt_offset(guc, ce->state) +
392                                  LRC_STATE_PN * PAGE_SIZE;
393
394                 /* XXX: In direct submission, the GuC wants the HW context id
395                  * here. In proxy submission, it wants the stage id
396                  */
397                 lrc->context_id = (client->stage_id << GUC_ELC_CTXID_OFFSET) |
398                                 (guc_engine_id << GUC_ELC_ENGINE_OFFSET);
399
400                 lrc->ring_begin = intel_guc_ggtt_offset(guc, ce->ring->vma);
401                 lrc->ring_end = lrc->ring_begin + ce->ring->size - 1;
402                 lrc->ring_next_free_location = lrc->ring_begin;
403                 lrc->ring_current_tail_pointer_value = 0;
404
405                 desc->engines_used |= (1 << guc_engine_id);
406         }
407
408         DRM_DEBUG_DRIVER("Host engines 0x%x => GuC engines used 0x%x\n",
409                          client->engines, desc->engines_used);
410         WARN_ON(desc->engines_used == 0);
411
412         /*
413          * The doorbell, process descriptor, and workqueue are all parts
414          * of the client object, which the GuC will reference via the GGTT
415          */
416         gfx_addr = intel_guc_ggtt_offset(guc, client->vma);
417         desc->db_trigger_phy = sg_dma_address(client->vma->pages->sgl) +
418                                 client->doorbell_offset;
419         desc->db_trigger_cpu = ptr_to_u64(__get_doorbell(client));
420         desc->db_trigger_uk = gfx_addr + client->doorbell_offset;
421         desc->process_desc = gfx_addr + client->proc_desc_offset;
422         desc->wq_addr = gfx_addr + GUC_DB_SIZE;
423         desc->wq_size = GUC_WQ_SIZE;
424
425         desc->desc_private = ptr_to_u64(client);
426 }
427
428 static void guc_stage_desc_fini(struct intel_guc *guc,
429                                 struct intel_guc_client *client)
430 {
431         struct guc_stage_desc *desc;
432
433         desc = __get_stage_desc(client);
434         memset(desc, 0, sizeof(*desc));
435 }
436
437 /* Construct a Work Item and append it to the GuC's Work Queue */
438 static void guc_wq_item_append(struct intel_guc_client *client,
439                                u32 target_engine, u32 context_desc,
440                                u32 ring_tail, u32 fence_id)
441 {
442         /* wqi_len is in DWords, and does not include the one-word header */
443         const size_t wqi_size = sizeof(struct guc_wq_item);
444         const u32 wqi_len = wqi_size / sizeof(u32) - 1;
445         struct guc_process_desc *desc = __get_process_desc(client);
446         struct guc_wq_item *wqi;
447         u32 wq_off;
448
449         lockdep_assert_held(&client->wq_lock);
450
451         /* For now workqueue item is 4 DWs; workqueue buffer is 2 pages. So we
452          * should not have the case where structure wqi is across page, neither
453          * wrapped to the beginning. This simplifies the implementation below.
454          *
455          * XXX: if not the case, we need save data to a temp wqi and copy it to
456          * workqueue buffer dw by dw.
457          */
458         BUILD_BUG_ON(wqi_size != 16);
459
460         /* Free space is guaranteed. */
461         wq_off = READ_ONCE(desc->tail);
462         GEM_BUG_ON(CIRC_SPACE(wq_off, READ_ONCE(desc->head),
463                               GUC_WQ_SIZE) < wqi_size);
464         GEM_BUG_ON(wq_off & (wqi_size - 1));
465
466         /* WQ starts from the page after doorbell / process_desc */
467         wqi = client->vaddr + wq_off + GUC_DB_SIZE;
468
469         /* Now fill in the 4-word work queue item */
470         wqi->header = WQ_TYPE_INORDER |
471                       (wqi_len << WQ_LEN_SHIFT) |
472                       (target_engine << WQ_TARGET_SHIFT) |
473                       WQ_NO_WCFLUSH_WAIT;
474         wqi->context_desc = context_desc;
475         wqi->submit_element_info = ring_tail << WQ_RING_TAIL_SHIFT;
476         GEM_BUG_ON(ring_tail > WQ_RING_TAIL_MAX);
477         wqi->fence_id = fence_id;
478
479         /* Make the update visible to GuC */
480         WRITE_ONCE(desc->tail, (wq_off + wqi_size) & (GUC_WQ_SIZE - 1));
481 }
482
483 static void guc_reset_wq(struct intel_guc_client *client)
484 {
485         struct guc_process_desc *desc = __get_process_desc(client);
486
487         desc->head = 0;
488         desc->tail = 0;
489 }
490
491 static void guc_ring_doorbell(struct intel_guc_client *client)
492 {
493         struct guc_doorbell_info *db;
494         u32 cookie;
495
496         lockdep_assert_held(&client->wq_lock);
497
498         /* pointer of current doorbell cacheline */
499         db = __get_doorbell(client);
500
501         /*
502          * We're not expecting the doorbell cookie to change behind our back,
503          * we also need to treat 0 as a reserved value.
504          */
505         cookie = READ_ONCE(db->cookie);
506         WARN_ON_ONCE(xchg(&db->cookie, cookie + 1 ?: cookie + 2) != cookie);
507
508         /* XXX: doorbell was lost and need to acquire it again */
509         GEM_BUG_ON(db->db_status != GUC_DOORBELL_ENABLED);
510 }
511
512 static void guc_add_request(struct intel_guc *guc, struct i915_request *rq)
513 {
514         struct intel_guc_client *client = guc->execbuf_client;
515         struct intel_engine_cs *engine = rq->engine;
516         u32 ctx_desc = lower_32_bits(intel_lr_context_descriptor(rq->ctx,
517                                                                  engine));
518         u32 ring_tail = intel_ring_set_tail(rq->ring, rq->tail) / sizeof(u64);
519
520         spin_lock(&client->wq_lock);
521
522         guc_wq_item_append(client, engine->guc_id, ctx_desc,
523                            ring_tail, rq->global_seqno);
524         guc_ring_doorbell(client);
525
526         client->submissions[engine->id] += 1;
527
528         spin_unlock(&client->wq_lock);
529 }
530
531 /*
532  * When we're doing submissions using regular execlists backend, writing to
533  * ELSP from CPU side is enough to make sure that writes to ringbuffer pages
534  * pinned in mappable aperture portion of GGTT are visible to command streamer.
535  * Writes done by GuC on our behalf are not guaranteeing such ordering,
536  * therefore, to ensure the flush, we're issuing a POSTING READ.
537  */
538 static void flush_ggtt_writes(struct i915_vma *vma)
539 {
540         struct drm_i915_private *dev_priv = to_i915(vma->obj->base.dev);
541
542         if (i915_vma_is_map_and_fenceable(vma))
543                 POSTING_READ_FW(GUC_STATUS);
544 }
545
546 static void inject_preempt_context(struct work_struct *work)
547 {
548         struct guc_preempt_work *preempt_work =
549                 container_of(work, typeof(*preempt_work), work);
550         struct intel_engine_cs *engine = preempt_work->engine;
551         struct intel_guc *guc = container_of(preempt_work, typeof(*guc),
552                                              preempt_work[engine->id]);
553         struct intel_guc_client *client = guc->preempt_client;
554         struct guc_stage_desc *stage_desc = __get_stage_desc(client);
555         u32 ctx_desc = lower_32_bits(intel_lr_context_descriptor(client->owner,
556                                                                  engine));
557         u32 data[7];
558
559         /*
560          * The ring contains commands to write GUC_PREEMPT_FINISHED into HWSP.
561          * See guc_fill_preempt_context().
562          */
563         spin_lock_irq(&client->wq_lock);
564         guc_wq_item_append(client, engine->guc_id, ctx_desc,
565                            GUC_PREEMPT_BREADCRUMB_BYTES / sizeof(u64), 0);
566         spin_unlock_irq(&client->wq_lock);
567
568         /*
569          * If GuC firmware performs an engine reset while that engine had
570          * a preemption pending, it will set the terminated attribute bit
571          * on our preemption stage descriptor. GuC firmware retains all
572          * pending work items for a high-priority GuC client, unlike the
573          * normal-priority GuC client where work items are dropped. It
574          * wants to make sure the preempt-to-idle work doesn't run when
575          * scheduling resumes, and uses this bit to inform its scheduler
576          * and presumably us as well. Our job is to clear it for the next
577          * preemption after reset, otherwise that and future preemptions
578          * will never complete. We'll just clear it every time.
579          */
580         stage_desc->attribute &= ~GUC_STAGE_DESC_ATTR_TERMINATED;
581
582         data[0] = INTEL_GUC_ACTION_REQUEST_PREEMPTION;
583         data[1] = client->stage_id;
584         data[2] = INTEL_GUC_PREEMPT_OPTION_DROP_WORK_Q |
585                   INTEL_GUC_PREEMPT_OPTION_DROP_SUBMIT_Q;
586         data[3] = engine->guc_id;
587         data[4] = guc->execbuf_client->priority;
588         data[5] = guc->execbuf_client->stage_id;
589         data[6] = intel_guc_ggtt_offset(guc, guc->shared_data);
590
591         if (WARN_ON(intel_guc_send(guc, data, ARRAY_SIZE(data)))) {
592                 execlists_clear_active(&engine->execlists,
593                                        EXECLISTS_ACTIVE_PREEMPT);
594                 tasklet_schedule(&engine->execlists.tasklet);
595         }
596 }
597
598 /*
599  * We're using user interrupt and HWSP value to mark that preemption has
600  * finished and GPU is idle. Normally, we could unwind and continue similar to
601  * execlists submission path. Unfortunately, with GuC we also need to wait for
602  * it to finish its own postprocessing, before attempting to submit. Otherwise
603  * GuC may silently ignore our submissions, and thus we risk losing request at
604  * best, executing out-of-order and causing kernel panic at worst.
605  */
606 #define GUC_PREEMPT_POSTPROCESS_DELAY_MS 10
607 static void wait_for_guc_preempt_report(struct intel_engine_cs *engine)
608 {
609         struct intel_guc *guc = &engine->i915->guc;
610         struct guc_shared_ctx_data *data = guc->shared_data_vaddr;
611         struct guc_ctx_report *report =
612                 &data->preempt_ctx_report[engine->guc_id];
613
614         WARN_ON(wait_for_atomic(report->report_return_status ==
615                                 INTEL_GUC_REPORT_STATUS_COMPLETE,
616                                 GUC_PREEMPT_POSTPROCESS_DELAY_MS));
617         /*
618          * GuC is expecting that we're also going to clear the affected context
619          * counter, let's also reset the return status to not depend on GuC
620          * resetting it after recieving another preempt action
621          */
622         report->affected_count = 0;
623         report->report_return_status = INTEL_GUC_REPORT_STATUS_UNKNOWN;
624 }
625
626 /**
627  * guc_submit() - Submit commands through GuC
628  * @engine: engine associated with the commands
629  *
630  * The only error here arises if the doorbell hardware isn't functioning
631  * as expected, which really shouln't happen.
632  */
633 static void guc_submit(struct intel_engine_cs *engine)
634 {
635         struct intel_guc *guc = &engine->i915->guc;
636         struct intel_engine_execlists * const execlists = &engine->execlists;
637         struct execlist_port *port = execlists->port;
638         unsigned int n;
639
640         for (n = 0; n < execlists_num_ports(execlists); n++) {
641                 struct i915_request *rq;
642                 unsigned int count;
643
644                 rq = port_unpack(&port[n], &count);
645                 if (rq && count == 0) {
646                         port_set(&port[n], port_pack(rq, ++count));
647
648                         flush_ggtt_writes(rq->ring->vma);
649
650                         guc_add_request(guc, rq);
651                 }
652         }
653 }
654
655 static void port_assign(struct execlist_port *port, struct i915_request *rq)
656 {
657         GEM_BUG_ON(port_isset(port));
658
659         port_set(port, i915_request_get(rq));
660 }
661
662 static inline int rq_prio(const struct i915_request *rq)
663 {
664         return rq->sched.attr.priority;
665 }
666
667 static inline int port_prio(const struct execlist_port *port)
668 {
669         return rq_prio(port_request(port));
670 }
671
672 static bool __guc_dequeue(struct intel_engine_cs *engine)
673 {
674         struct intel_engine_execlists * const execlists = &engine->execlists;
675         struct execlist_port *port = execlists->port;
676         struct i915_request *last = NULL;
677         const struct execlist_port * const last_port =
678                 &execlists->port[execlists->port_mask];
679         bool submit = false;
680         struct rb_node *rb;
681
682         lockdep_assert_held(&engine->timeline.lock);
683
684         rb = execlists->first;
685         GEM_BUG_ON(rb_first(&execlists->queue) != rb);
686
687         if (port_isset(port)) {
688                 if (intel_engine_has_preemption(engine)) {
689                         struct guc_preempt_work *preempt_work =
690                                 &engine->i915->guc.preempt_work[engine->id];
691                         int prio = execlists->queue_priority;
692
693                         if (__execlists_need_preempt(prio, port_prio(port))) {
694                                 execlists_set_active(execlists,
695                                                      EXECLISTS_ACTIVE_PREEMPT);
696                                 queue_work(engine->i915->guc.preempt_wq,
697                                            &preempt_work->work);
698                                 return false;
699                         }
700                 }
701
702                 port++;
703                 if (port_isset(port))
704                         return false;
705         }
706         GEM_BUG_ON(port_isset(port));
707
708         while (rb) {
709                 struct i915_priolist *p = to_priolist(rb);
710                 struct i915_request *rq, *rn;
711
712                 list_for_each_entry_safe(rq, rn, &p->requests, sched.link) {
713                         if (last && rq->ctx != last->ctx) {
714                                 if (port == last_port) {
715                                         __list_del_many(&p->requests,
716                                                         &rq->sched.link);
717                                         goto done;
718                                 }
719
720                                 if (submit)
721                                         port_assign(port, last);
722                                 port++;
723                         }
724
725                         INIT_LIST_HEAD(&rq->sched.link);
726
727                         __i915_request_submit(rq);
728                         trace_i915_request_in(rq, port_index(port, execlists));
729                         last = rq;
730                         submit = true;
731                 }
732
733                 rb = rb_next(rb);
734                 rb_erase(&p->node, &execlists->queue);
735                 INIT_LIST_HEAD(&p->requests);
736                 if (p->priority != I915_PRIORITY_NORMAL)
737                         kmem_cache_free(engine->i915->priorities, p);
738         }
739 done:
740         execlists->queue_priority = rb ? to_priolist(rb)->priority : INT_MIN;
741         execlists->first = rb;
742         if (submit)
743                 port_assign(port, last);
744         if (last)
745                 execlists_user_begin(execlists, execlists->port);
746
747         /* We must always keep the beast fed if we have work piled up */
748         GEM_BUG_ON(port_isset(execlists->port) &&
749                    !execlists_is_active(execlists, EXECLISTS_ACTIVE_USER));
750         GEM_BUG_ON(execlists->first && !port_isset(execlists->port));
751
752         return submit;
753 }
754
755 static void guc_dequeue(struct intel_engine_cs *engine)
756 {
757         unsigned long flags;
758         bool submit;
759
760         local_irq_save(flags);
761
762         spin_lock(&engine->timeline.lock);
763         submit = __guc_dequeue(engine);
764         spin_unlock(&engine->timeline.lock);
765
766         if (submit)
767                 guc_submit(engine);
768
769         local_irq_restore(flags);
770 }
771
772 static void guc_submission_tasklet(unsigned long data)
773 {
774         struct intel_engine_cs * const engine = (struct intel_engine_cs *)data;
775         struct intel_engine_execlists * const execlists = &engine->execlists;
776         struct execlist_port *port = execlists->port;
777         struct i915_request *rq;
778
779         rq = port_request(port);
780         while (rq && i915_request_completed(rq)) {
781                 trace_i915_request_out(rq);
782                 i915_request_put(rq);
783
784                 port = execlists_port_complete(execlists, port);
785                 if (port_isset(port)) {
786                         execlists_user_begin(execlists, port);
787                         rq = port_request(port);
788                 } else {
789                         execlists_user_end(execlists);
790                         rq = NULL;
791                 }
792         }
793
794         if (execlists_is_active(execlists, EXECLISTS_ACTIVE_PREEMPT) &&
795             intel_read_status_page(engine, I915_GEM_HWS_PREEMPT_INDEX) ==
796             GUC_PREEMPT_FINISHED) {
797                 execlists_cancel_port_requests(&engine->execlists);
798                 execlists_unwind_incomplete_requests(execlists);
799
800                 wait_for_guc_preempt_report(engine);
801
802                 execlists_clear_active(execlists, EXECLISTS_ACTIVE_PREEMPT);
803                 intel_write_status_page(engine, I915_GEM_HWS_PREEMPT_INDEX, 0);
804         }
805
806         if (!execlists_is_active(execlists, EXECLISTS_ACTIVE_PREEMPT))
807                 guc_dequeue(engine);
808 }
809
810 /*
811  * Everything below here is concerned with setup & teardown, and is
812  * therefore not part of the somewhat time-critical batch-submission
813  * path of guc_submit() above.
814  */
815
816 /* Check that a doorbell register is in the expected state */
817 static bool doorbell_ok(struct intel_guc *guc, u16 db_id)
818 {
819         struct drm_i915_private *dev_priv = guc_to_i915(guc);
820         u32 drbregl;
821         bool valid;
822
823         GEM_BUG_ON(db_id >= GUC_DOORBELL_INVALID);
824
825         drbregl = I915_READ(GEN8_DRBREGL(db_id));
826         valid = drbregl & GEN8_DRB_VALID;
827
828         if (test_bit(db_id, guc->doorbell_bitmap) == valid)
829                 return true;
830
831         DRM_DEBUG_DRIVER("Doorbell %d has unexpected state (0x%x): valid=%s\n",
832                          db_id, drbregl, yesno(valid));
833
834         return false;
835 }
836
837 static bool guc_verify_doorbells(struct intel_guc *guc)
838 {
839         u16 db_id;
840
841         for (db_id = 0; db_id < GUC_NUM_DOORBELLS; ++db_id)
842                 if (!doorbell_ok(guc, db_id))
843                         return false;
844
845         return true;
846 }
847
848 static int guc_clients_doorbell_init(struct intel_guc *guc)
849 {
850         int ret;
851
852         ret = create_doorbell(guc->execbuf_client);
853         if (ret)
854                 return ret;
855
856         if (guc->preempt_client) {
857                 ret = create_doorbell(guc->preempt_client);
858                 if (ret) {
859                         destroy_doorbell(guc->execbuf_client);
860                         return ret;
861                 }
862         }
863
864         return 0;
865 }
866
867 static void guc_clients_doorbell_fini(struct intel_guc *guc)
868 {
869         /*
870          * By the time we're here, GuC has already been reset.
871          * Instead of trying (in vain) to communicate with it, let's just
872          * cleanup the doorbell HW and our internal state.
873          */
874         if (guc->preempt_client) {
875                 __destroy_doorbell(guc->preempt_client);
876                 __update_doorbell_desc(guc->preempt_client,
877                                        GUC_DOORBELL_INVALID);
878         }
879         __destroy_doorbell(guc->execbuf_client);
880         __update_doorbell_desc(guc->execbuf_client, GUC_DOORBELL_INVALID);
881 }
882
883 /**
884  * guc_client_alloc() - Allocate an intel_guc_client
885  * @dev_priv:   driver private data structure
886  * @engines:    The set of engines to enable for this client
887  * @priority:   four levels priority _CRITICAL, _HIGH, _NORMAL and _LOW
888  *              The kernel client to replace ExecList submission is created with
889  *              NORMAL priority. Priority of a client for scheduler can be HIGH,
890  *              while a preemption context can use CRITICAL.
891  * @ctx:        the context that owns the client (we use the default render
892  *              context)
893  *
894  * Return:      An intel_guc_client object if success, else NULL.
895  */
896 static struct intel_guc_client *
897 guc_client_alloc(struct drm_i915_private *dev_priv,
898                  u32 engines,
899                  u32 priority,
900                  struct i915_gem_context *ctx)
901 {
902         struct intel_guc_client *client;
903         struct intel_guc *guc = &dev_priv->guc;
904         struct i915_vma *vma;
905         void *vaddr;
906         int ret;
907
908         client = kzalloc(sizeof(*client), GFP_KERNEL);
909         if (!client)
910                 return ERR_PTR(-ENOMEM);
911
912         client->guc = guc;
913         client->owner = ctx;
914         client->engines = engines;
915         client->priority = priority;
916         client->doorbell_id = GUC_DOORBELL_INVALID;
917         spin_lock_init(&client->wq_lock);
918
919         ret = ida_simple_get(&guc->stage_ids, 0, GUC_MAX_STAGE_DESCRIPTORS,
920                              GFP_KERNEL);
921         if (ret < 0)
922                 goto err_client;
923
924         client->stage_id = ret;
925
926         /* The first page is doorbell/proc_desc. Two followed pages are wq. */
927         vma = intel_guc_allocate_vma(guc, GUC_DB_SIZE + GUC_WQ_SIZE);
928         if (IS_ERR(vma)) {
929                 ret = PTR_ERR(vma);
930                 goto err_id;
931         }
932
933         /* We'll keep just the first (doorbell/proc) page permanently kmap'd. */
934         client->vma = vma;
935
936         vaddr = i915_gem_object_pin_map(vma->obj, I915_MAP_WB);
937         if (IS_ERR(vaddr)) {
938                 ret = PTR_ERR(vaddr);
939                 goto err_vma;
940         }
941         client->vaddr = vaddr;
942
943         client->doorbell_offset = __select_cacheline(guc);
944
945         /*
946          * Since the doorbell only requires a single cacheline, we can save
947          * space by putting the application process descriptor in the same
948          * page. Use the half of the page that doesn't include the doorbell.
949          */
950         if (client->doorbell_offset >= (GUC_DB_SIZE / 2))
951                 client->proc_desc_offset = 0;
952         else
953                 client->proc_desc_offset = (GUC_DB_SIZE / 2);
954
955         guc_proc_desc_init(guc, client);
956         guc_stage_desc_init(guc, client);
957
958         ret = reserve_doorbell(client);
959         if (ret)
960                 goto err_vaddr;
961
962         DRM_DEBUG_DRIVER("new priority %u client %p for engine(s) 0x%x: stage_id %u\n",
963                          priority, client, client->engines, client->stage_id);
964         DRM_DEBUG_DRIVER("doorbell id %u, cacheline offset 0x%lx\n",
965                          client->doorbell_id, client->doorbell_offset);
966
967         return client;
968
969 err_vaddr:
970         i915_gem_object_unpin_map(client->vma->obj);
971 err_vma:
972         i915_vma_unpin_and_release(&client->vma);
973 err_id:
974         ida_simple_remove(&guc->stage_ids, client->stage_id);
975 err_client:
976         kfree(client);
977         return ERR_PTR(ret);
978 }
979
980 static void guc_client_free(struct intel_guc_client *client)
981 {
982         unreserve_doorbell(client);
983         guc_stage_desc_fini(client->guc, client);
984         i915_gem_object_unpin_map(client->vma->obj);
985         i915_vma_unpin_and_release(&client->vma);
986         ida_simple_remove(&client->guc->stage_ids, client->stage_id);
987         kfree(client);
988 }
989
990 static inline bool ctx_save_restore_disabled(struct intel_context *ce)
991 {
992         u32 sr = ce->lrc_reg_state[CTX_CONTEXT_CONTROL + 1];
993
994 #define SR_DISABLED \
995         _MASKED_BIT_ENABLE(CTX_CTRL_ENGINE_CTX_RESTORE_INHIBIT | \
996                            CTX_CTRL_ENGINE_CTX_SAVE_INHIBIT)
997
998         return (sr & SR_DISABLED) == SR_DISABLED;
999
1000 #undef SR_DISABLED
1001 }
1002
1003 static void guc_fill_preempt_context(struct intel_guc *guc)
1004 {
1005         struct drm_i915_private *dev_priv = guc_to_i915(guc);
1006         struct intel_guc_client *client = guc->preempt_client;
1007         struct intel_engine_cs *engine;
1008         enum intel_engine_id id;
1009
1010         for_each_engine(engine, dev_priv, id) {
1011                 struct intel_context *ce =
1012                         to_intel_context(client->owner, engine);
1013                 u32 addr = intel_hws_preempt_done_address(engine);
1014                 u32 *cs;
1015
1016                 GEM_BUG_ON(!ce->pin_count);
1017
1018                 /*
1019                  * We rely on this context image *not* being saved after
1020                  * preemption. This ensures that the RING_HEAD / RING_TAIL
1021                  * remain pointing at initial values forever.
1022                  */
1023                 GEM_BUG_ON(!ctx_save_restore_disabled(ce));
1024
1025                 cs = ce->ring->vaddr;
1026                 if (id == RCS) {
1027                         cs = gen8_emit_ggtt_write_rcs(cs,
1028                                                       GUC_PREEMPT_FINISHED,
1029                                                       addr);
1030                 } else {
1031                         cs = gen8_emit_ggtt_write(cs,
1032                                                   GUC_PREEMPT_FINISHED,
1033                                                   addr);
1034                         *cs++ = MI_NOOP;
1035                         *cs++ = MI_NOOP;
1036                 }
1037                 *cs++ = MI_USER_INTERRUPT;
1038                 *cs++ = MI_NOOP;
1039
1040                 GEM_BUG_ON((void *)cs - ce->ring->vaddr !=
1041                            GUC_PREEMPT_BREADCRUMB_BYTES);
1042
1043                 flush_ggtt_writes(ce->ring->vma);
1044         }
1045 }
1046
1047 static int guc_clients_create(struct intel_guc *guc)
1048 {
1049         struct drm_i915_private *dev_priv = guc_to_i915(guc);
1050         struct intel_guc_client *client;
1051
1052         GEM_BUG_ON(guc->execbuf_client);
1053         GEM_BUG_ON(guc->preempt_client);
1054
1055         client = guc_client_alloc(dev_priv,
1056                                   INTEL_INFO(dev_priv)->ring_mask,
1057                                   GUC_CLIENT_PRIORITY_KMD_NORMAL,
1058                                   dev_priv->kernel_context);
1059         if (IS_ERR(client)) {
1060                 DRM_ERROR("Failed to create GuC client for submission!\n");
1061                 return PTR_ERR(client);
1062         }
1063         guc->execbuf_client = client;
1064
1065         if (dev_priv->preempt_context) {
1066                 client = guc_client_alloc(dev_priv,
1067                                           INTEL_INFO(dev_priv)->ring_mask,
1068                                           GUC_CLIENT_PRIORITY_KMD_HIGH,
1069                                           dev_priv->preempt_context);
1070                 if (IS_ERR(client)) {
1071                         DRM_ERROR("Failed to create GuC client for preemption!\n");
1072                         guc_client_free(guc->execbuf_client);
1073                         guc->execbuf_client = NULL;
1074                         return PTR_ERR(client);
1075                 }
1076                 guc->preempt_client = client;
1077
1078                 guc_fill_preempt_context(guc);
1079         }
1080
1081         return 0;
1082 }
1083
1084 static void guc_clients_destroy(struct intel_guc *guc)
1085 {
1086         struct intel_guc_client *client;
1087
1088         client = fetch_and_zero(&guc->preempt_client);
1089         if (client)
1090                 guc_client_free(client);
1091
1092         client = fetch_and_zero(&guc->execbuf_client);
1093         guc_client_free(client);
1094 }
1095
1096 /*
1097  * Set up the memory resources to be shared with the GuC (via the GGTT)
1098  * at firmware loading time.
1099  */
1100 int intel_guc_submission_init(struct intel_guc *guc)
1101 {
1102         struct drm_i915_private *dev_priv = guc_to_i915(guc);
1103         struct intel_engine_cs *engine;
1104         enum intel_engine_id id;
1105         int ret;
1106
1107         if (guc->stage_desc_pool)
1108                 return 0;
1109
1110         ret = guc_stage_desc_pool_create(guc);
1111         if (ret)
1112                 return ret;
1113         /*
1114          * Keep static analysers happy, let them know that we allocated the
1115          * vma after testing that it didn't exist earlier.
1116          */
1117         GEM_BUG_ON(!guc->stage_desc_pool);
1118
1119         WARN_ON(!guc_verify_doorbells(guc));
1120         ret = guc_clients_create(guc);
1121         if (ret)
1122                 return ret;
1123
1124         for_each_engine(engine, dev_priv, id) {
1125                 guc->preempt_work[id].engine = engine;
1126                 INIT_WORK(&guc->preempt_work[id].work, inject_preempt_context);
1127         }
1128
1129         return 0;
1130
1131 }
1132
1133 void intel_guc_submission_fini(struct intel_guc *guc)
1134 {
1135         struct drm_i915_private *dev_priv = guc_to_i915(guc);
1136         struct intel_engine_cs *engine;
1137         enum intel_engine_id id;
1138
1139         for_each_engine(engine, dev_priv, id)
1140                 cancel_work_sync(&guc->preempt_work[id].work);
1141
1142         guc_clients_destroy(guc);
1143         WARN_ON(!guc_verify_doorbells(guc));
1144
1145         guc_stage_desc_pool_destroy(guc);
1146 }
1147
1148 static void guc_interrupts_capture(struct drm_i915_private *dev_priv)
1149 {
1150         struct intel_rps *rps = &dev_priv->gt_pm.rps;
1151         struct intel_engine_cs *engine;
1152         enum intel_engine_id id;
1153         int irqs;
1154
1155         /* tell all command streamers to forward interrupts (but not vblank)
1156          * to GuC
1157          */
1158         irqs = _MASKED_BIT_ENABLE(GFX_INTERRUPT_STEERING);
1159         for_each_engine(engine, dev_priv, id)
1160                 I915_WRITE(RING_MODE_GEN7(engine), irqs);
1161
1162         /* route USER_INTERRUPT to Host, all others are sent to GuC. */
1163         irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
1164                GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT;
1165         /* These three registers have the same bit definitions */
1166         I915_WRITE(GUC_BCS_RCS_IER, ~irqs);
1167         I915_WRITE(GUC_VCS2_VCS1_IER, ~irqs);
1168         I915_WRITE(GUC_WD_VECS_IER, ~irqs);
1169
1170         /*
1171          * The REDIRECT_TO_GUC bit of the PMINTRMSK register directs all
1172          * (unmasked) PM interrupts to the GuC. All other bits of this
1173          * register *disable* generation of a specific interrupt.
1174          *
1175          * 'pm_intrmsk_mbz' indicates bits that are NOT to be set when
1176          * writing to the PM interrupt mask register, i.e. interrupts
1177          * that must not be disabled.
1178          *
1179          * If the GuC is handling these interrupts, then we must not let
1180          * the PM code disable ANY interrupt that the GuC is expecting.
1181          * So for each ENABLED (0) bit in this register, we must SET the
1182          * bit in pm_intrmsk_mbz so that it's left enabled for the GuC.
1183          * GuC needs ARAT expired interrupt unmasked hence it is set in
1184          * pm_intrmsk_mbz.
1185          *
1186          * Here we CLEAR REDIRECT_TO_GUC bit in pm_intrmsk_mbz, which will
1187          * result in the register bit being left SET!
1188          */
1189         rps->pm_intrmsk_mbz |= ARAT_EXPIRED_INTRMSK;
1190         rps->pm_intrmsk_mbz &= ~GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
1191 }
1192
1193 static void guc_interrupts_release(struct drm_i915_private *dev_priv)
1194 {
1195         struct intel_rps *rps = &dev_priv->gt_pm.rps;
1196         struct intel_engine_cs *engine;
1197         enum intel_engine_id id;
1198         int irqs;
1199
1200         /*
1201          * tell all command streamers NOT to forward interrupts or vblank
1202          * to GuC.
1203          */
1204         irqs = _MASKED_FIELD(GFX_FORWARD_VBLANK_MASK, GFX_FORWARD_VBLANK_NEVER);
1205         irqs |= _MASKED_BIT_DISABLE(GFX_INTERRUPT_STEERING);
1206         for_each_engine(engine, dev_priv, id)
1207                 I915_WRITE(RING_MODE_GEN7(engine), irqs);
1208
1209         /* route all GT interrupts to the host */
1210         I915_WRITE(GUC_BCS_RCS_IER, 0);
1211         I915_WRITE(GUC_VCS2_VCS1_IER, 0);
1212         I915_WRITE(GUC_WD_VECS_IER, 0);
1213
1214         rps->pm_intrmsk_mbz |= GEN8_PMINTR_DISABLE_REDIRECT_TO_GUC;
1215         rps->pm_intrmsk_mbz &= ~ARAT_EXPIRED_INTRMSK;
1216 }
1217
1218 static void guc_submission_park(struct intel_engine_cs *engine)
1219 {
1220         intel_engine_unpin_breadcrumbs_irq(engine);
1221 }
1222
1223 static void guc_submission_unpark(struct intel_engine_cs *engine)
1224 {
1225         intel_engine_pin_breadcrumbs_irq(engine);
1226 }
1227
1228 int intel_guc_submission_enable(struct intel_guc *guc)
1229 {
1230         struct drm_i915_private *dev_priv = guc_to_i915(guc);
1231         struct intel_engine_cs *engine;
1232         enum intel_engine_id id;
1233         int err;
1234
1235         /*
1236          * We're using GuC work items for submitting work through GuC. Since
1237          * we're coalescing multiple requests from a single context into a
1238          * single work item prior to assigning it to execlist_port, we can
1239          * never have more work items than the total number of ports (for all
1240          * engines). The GuC firmware is controlling the HEAD of work queue,
1241          * and it is guaranteed that it will remove the work item from the
1242          * queue before our request is completed.
1243          */
1244         BUILD_BUG_ON(ARRAY_SIZE(engine->execlists.port) *
1245                      sizeof(struct guc_wq_item) *
1246                      I915_NUM_ENGINES > GUC_WQ_SIZE);
1247
1248         GEM_BUG_ON(!guc->execbuf_client);
1249
1250         guc_reset_wq(guc->execbuf_client);
1251         if (guc->preempt_client)
1252                 guc_reset_wq(guc->preempt_client);
1253
1254         err = intel_guc_sample_forcewake(guc);
1255         if (err)
1256                 return err;
1257
1258         err = guc_clients_doorbell_init(guc);
1259         if (err)
1260                 return err;
1261
1262         /* Take over from manual control of ELSP (execlists) */
1263         guc_interrupts_capture(dev_priv);
1264
1265         for_each_engine(engine, dev_priv, id) {
1266                 struct intel_engine_execlists * const execlists =
1267                         &engine->execlists;
1268
1269                 execlists->tasklet.func = guc_submission_tasklet;
1270                 engine->park = guc_submission_park;
1271                 engine->unpark = guc_submission_unpark;
1272
1273                 engine->flags &= ~I915_ENGINE_SUPPORTS_STATS;
1274         }
1275
1276         return 0;
1277 }
1278
1279 void intel_guc_submission_disable(struct intel_guc *guc)
1280 {
1281         struct drm_i915_private *dev_priv = guc_to_i915(guc);
1282
1283         GEM_BUG_ON(dev_priv->gt.awake); /* GT should be parked first */
1284
1285         guc_interrupts_release(dev_priv);
1286         guc_clients_doorbell_fini(guc);
1287
1288         /* Revert back to manual ELSP submission */
1289         intel_engines_reset_default_submission(dev_priv);
1290 }
1291
1292 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
1293 #include "selftests/intel_guc.c"
1294 #endif
This page took 0.106982 seconds and 4 git commands to generate.