]> asedeno.scripts.mit.edu Git - linux.git/blob - drivers/gpu/drm/i915/gt/intel_engine_types.h
868b220214f81b23087d7d8641345fea137b6640
[linux.git] / drivers / gpu / drm / i915 / gt / intel_engine_types.h
1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2019 Intel Corporation
5  */
6
7 #ifndef __INTEL_ENGINE_TYPES__
8 #define __INTEL_ENGINE_TYPES__
9
10 #include <linux/hashtable.h>
11 #include <linux/irq_work.h>
12 #include <linux/kref.h>
13 #include <linux/list.h>
14 #include <linux/llist.h>
15 #include <linux/types.h>
16
17 #include "i915_gem.h"
18 #include "i915_gem_batch_pool.h"
19 #include "i915_pmu.h"
20 #include "i915_priolist_types.h"
21 #include "i915_selftest.h"
22 #include "i915_timeline_types.h"
23 #include "intel_sseu.h"
24 #include "intel_wakeref.h"
25 #include "intel_workarounds_types.h"
26
27 #define I915_MAX_SLICES 3
28 #define I915_MAX_SUBSLICES 8
29
30 #define I915_CMD_HASH_ORDER 9
31
32 struct dma_fence;
33 struct drm_i915_gem_object;
34 struct drm_i915_reg_table;
35 struct i915_gem_context;
36 struct i915_request;
37 struct i915_sched_attr;
38 struct intel_uncore;
39
40 typedef u8 intel_engine_mask_t;
41 #define ALL_ENGINES ((intel_engine_mask_t)~0ul)
42
43 struct intel_hw_status_page {
44         struct i915_vma *vma;
45         u32 *addr;
46 };
47
48 struct intel_instdone {
49         u32 instdone;
50         /* The following exist only in the RCS engine */
51         u32 slice_common;
52         u32 sampler[I915_MAX_SLICES][I915_MAX_SUBSLICES];
53         u32 row[I915_MAX_SLICES][I915_MAX_SUBSLICES];
54 };
55
56 struct intel_engine_hangcheck {
57         u64 acthd;
58         u32 last_ring;
59         u32 last_head;
60         unsigned long action_timestamp;
61         struct intel_instdone instdone;
62 };
63
64 struct intel_ring {
65         struct kref ref;
66         struct i915_vma *vma;
67         void *vaddr;
68
69         struct i915_timeline *timeline;
70         struct list_head request_list;
71         struct list_head active_link;
72
73         u32 head;
74         u32 tail;
75         u32 emit;
76
77         u32 space;
78         u32 size;
79         u32 effective_size;
80 };
81
82 /*
83  * we use a single page to load ctx workarounds so all of these
84  * values are referred in terms of dwords
85  *
86  * struct i915_wa_ctx_bb:
87  *  offset: specifies batch starting position, also helpful in case
88  *    if we want to have multiple batches at different offsets based on
89  *    some criteria. It is not a requirement at the moment but provides
90  *    an option for future use.
91  *  size: size of the batch in DWORDS
92  */
93 struct i915_ctx_workarounds {
94         struct i915_wa_ctx_bb {
95                 u32 offset;
96                 u32 size;
97         } indirect_ctx, per_ctx;
98         struct i915_vma *vma;
99 };
100
101 #define I915_MAX_VCS    4
102 #define I915_MAX_VECS   2
103
104 /*
105  * Engine IDs definitions.
106  * Keep instances of the same type engine together.
107  */
108 enum intel_engine_id {
109         RCS0 = 0,
110         BCS0,
111         VCS0,
112         VCS1,
113         VCS2,
114         VCS3,
115 #define _VCS(n) (VCS0 + (n))
116         VECS0,
117         VECS1,
118 #define _VECS(n) (VECS0 + (n))
119         I915_NUM_ENGINES
120 };
121
122 struct st_preempt_hang {
123         struct completion completion;
124         unsigned int count;
125         bool inject_hang;
126 };
127
128 /**
129  * struct intel_engine_execlists - execlist submission queue and port state
130  *
131  * The struct intel_engine_execlists represents the combined logical state of
132  * driver and the hardware state for execlist mode of submission.
133  */
134 struct intel_engine_execlists {
135         /**
136          * @tasklet: softirq tasklet for bottom handler
137          */
138         struct tasklet_struct tasklet;
139
140         /**
141          * @default_priolist: priority list for I915_PRIORITY_NORMAL
142          */
143         struct i915_priolist default_priolist;
144
145         /**
146          * @no_priolist: priority lists disabled
147          */
148         bool no_priolist;
149
150         /**
151          * @submit_reg: gen-specific execlist submission register
152          * set to the ExecList Submission Port (elsp) register pre-Gen11 and to
153          * the ExecList Submission Queue Contents register array for Gen11+
154          */
155         u32 __iomem *submit_reg;
156
157         /**
158          * @ctrl_reg: the enhanced execlists control register, used to load the
159          * submit queue on the HW and to request preemptions to idle
160          */
161         u32 __iomem *ctrl_reg;
162
163         /**
164          * @port: execlist port states
165          *
166          * For each hardware ELSP (ExecList Submission Port) we keep
167          * track of the last request and the number of times we submitted
168          * that port to hw. We then count the number of times the hw reports
169          * a context completion or preemption. As only one context can
170          * be active on hw, we limit resubmission of context to port[0]. This
171          * is called Lite Restore, of the context.
172          */
173         struct execlist_port {
174                 /**
175                  * @request_count: combined request and submission count
176                  */
177                 struct i915_request *request_count;
178 #define EXECLIST_COUNT_BITS 2
179 #define port_request(p) ptr_mask_bits((p)->request_count, EXECLIST_COUNT_BITS)
180 #define port_count(p) ptr_unmask_bits((p)->request_count, EXECLIST_COUNT_BITS)
181 #define port_pack(rq, count) ptr_pack_bits(rq, count, EXECLIST_COUNT_BITS)
182 #define port_unpack(p, count) ptr_unpack_bits((p)->request_count, count, EXECLIST_COUNT_BITS)
183 #define port_set(p, packed) ((p)->request_count = (packed))
184 #define port_isset(p) ((p)->request_count)
185 #define port_index(p, execlists) ((p) - (execlists)->port)
186
187                 /**
188                  * @context_id: context ID for port
189                  */
190                 GEM_DEBUG_DECL(u32 context_id);
191
192 #define EXECLIST_MAX_PORTS 2
193         } port[EXECLIST_MAX_PORTS];
194
195         /**
196          * @active: is the HW active? We consider the HW as active after
197          * submitting any context for execution and until we have seen the
198          * last context completion event. After that, we do not expect any
199          * more events until we submit, and so can park the HW.
200          *
201          * As we have a small number of different sources from which we feed
202          * the HW, we track the state of each inside a single bitfield.
203          */
204         unsigned int active;
205 #define EXECLISTS_ACTIVE_USER 0
206 #define EXECLISTS_ACTIVE_PREEMPT 1
207 #define EXECLISTS_ACTIVE_HWACK 2
208
209         /**
210          * @port_mask: number of execlist ports - 1
211          */
212         unsigned int port_mask;
213
214         /**
215          * @queue_priority_hint: Highest pending priority.
216          *
217          * When we add requests into the queue, or adjust the priority of
218          * executing requests, we compute the maximum priority of those
219          * pending requests. We can then use this value to determine if
220          * we need to preempt the executing requests to service the queue.
221          * However, since the we may have recorded the priority of an inflight
222          * request we wanted to preempt but since completed, at the time of
223          * dequeuing the priority hint may no longer may match the highest
224          * available request priority.
225          */
226         int queue_priority_hint;
227
228         /**
229          * @queue: queue of requests, in priority lists
230          */
231         struct rb_root_cached queue;
232         struct rb_root_cached virtual;
233
234         /**
235          * @csb_write: control register for Context Switch buffer
236          *
237          * Note this register may be either mmio or HWSP shadow.
238          */
239         u32 *csb_write;
240
241         /**
242          * @csb_status: status array for Context Switch buffer
243          *
244          * Note these register may be either mmio or HWSP shadow.
245          */
246         u32 *csb_status;
247
248         /**
249          * @preempt_complete_status: expected CSB upon completing preemption
250          */
251         u32 preempt_complete_status;
252
253         /**
254          * @csb_size: context status buffer FIFO size
255          */
256         u8 csb_size;
257
258         /**
259          * @csb_head: context status buffer head
260          */
261         u8 csb_head;
262
263         I915_SELFTEST_DECLARE(struct st_preempt_hang preempt_hang;)
264 };
265
266 #define INTEL_ENGINE_CS_MAX_NAME 8
267
268 struct intel_engine_cs {
269         struct drm_i915_private *i915;
270         struct intel_uncore *uncore;
271         char name[INTEL_ENGINE_CS_MAX_NAME];
272
273         enum intel_engine_id id;
274         unsigned int hw_id;
275         unsigned int guc_id;
276         intel_engine_mask_t mask;
277
278         u8 uabi_class;
279
280         u8 class;
281         u8 instance;
282         u32 context_size;
283         u32 mmio_base;
284
285         u32 uabi_capabilities;
286
287         struct intel_sseu sseu;
288
289         struct intel_ring *buffer;
290
291         struct {
292                 spinlock_t lock;
293                 struct list_head requests;
294         } active;
295
296         struct llist_head barrier_tasks;
297
298         struct intel_context *kernel_context; /* pinned */
299         struct intel_context *preempt_context; /* pinned; optional */
300
301         intel_engine_mask_t saturated; /* submitting semaphores too late? */
302
303         unsigned long serial;
304
305         unsigned long wakeref_serial;
306         struct intel_wakeref wakeref;
307         struct drm_i915_gem_object *default_state;
308         void *pinned_default_state;
309
310         /* Rather than have every client wait upon all user interrupts,
311          * with the herd waking after every interrupt and each doing the
312          * heavyweight seqno dance, we delegate the task (of being the
313          * bottom-half of the user interrupt) to the first client. After
314          * every interrupt, we wake up one client, who does the heavyweight
315          * coherent seqno read and either goes back to sleep (if incomplete),
316          * or wakes up all the completed clients in parallel, before then
317          * transferring the bottom-half status to the next client in the queue.
318          *
319          * Compared to walking the entire list of waiters in a single dedicated
320          * bottom-half, we reduce the latency of the first waiter by avoiding
321          * a context switch, but incur additional coherent seqno reads when
322          * following the chain of request breadcrumbs. Since it is most likely
323          * that we have a single client waiting on each seqno, then reducing
324          * the overhead of waking that client is much preferred.
325          */
326         struct intel_breadcrumbs {
327                 spinlock_t irq_lock;
328                 struct list_head signalers;
329
330                 struct irq_work irq_work; /* for use from inside irq_lock */
331
332                 unsigned int irq_enabled;
333
334                 bool irq_armed;
335         } breadcrumbs;
336
337         struct intel_engine_pmu {
338                 /**
339                  * @enable: Bitmask of enable sample events on this engine.
340                  *
341                  * Bits correspond to sample event types, for instance
342                  * I915_SAMPLE_QUEUED is bit 0 etc.
343                  */
344                 u32 enable;
345                 /**
346                  * @enable_count: Reference count for the enabled samplers.
347                  *
348                  * Index number corresponds to @enum drm_i915_pmu_engine_sample.
349                  */
350                 unsigned int enable_count[I915_ENGINE_SAMPLE_COUNT];
351                 /**
352                  * @sample: Counter values for sampling events.
353                  *
354                  * Our internal timer stores the current counters in this field.
355                  *
356                  * Index number corresponds to @enum drm_i915_pmu_engine_sample.
357                  */
358                 struct i915_pmu_sample sample[I915_ENGINE_SAMPLE_COUNT];
359         } pmu;
360
361         /*
362          * A pool of objects to use as shadow copies of client batch buffers
363          * when the command parser is enabled. Prevents the client from
364          * modifying the batch contents after software parsing.
365          */
366         struct i915_gem_batch_pool batch_pool;
367
368         struct intel_hw_status_page status_page;
369         struct i915_ctx_workarounds wa_ctx;
370         struct i915_wa_list ctx_wa_list;
371         struct i915_wa_list wa_list;
372         struct i915_wa_list whitelist;
373
374         u32             irq_keep_mask; /* always keep these interrupts */
375         u32             irq_enable_mask; /* bitmask to enable ring interrupt */
376         void            (*irq_enable)(struct intel_engine_cs *engine);
377         void            (*irq_disable)(struct intel_engine_cs *engine);
378
379         int             (*resume)(struct intel_engine_cs *engine);
380
381         struct {
382                 void (*prepare)(struct intel_engine_cs *engine);
383                 void (*reset)(struct intel_engine_cs *engine, bool stalled);
384                 void (*finish)(struct intel_engine_cs *engine);
385         } reset;
386
387         void            (*park)(struct intel_engine_cs *engine);
388         void            (*unpark)(struct intel_engine_cs *engine);
389
390         void            (*set_default_submission)(struct intel_engine_cs *engine);
391
392         const struct intel_context_ops *cops;
393
394         int             (*request_alloc)(struct i915_request *rq);
395         int             (*init_context)(struct i915_request *rq);
396
397         int             (*emit_flush)(struct i915_request *request, u32 mode);
398 #define EMIT_INVALIDATE BIT(0)
399 #define EMIT_FLUSH      BIT(1)
400 #define EMIT_BARRIER    (EMIT_INVALIDATE | EMIT_FLUSH)
401         int             (*emit_bb_start)(struct i915_request *rq,
402                                          u64 offset, u32 length,
403                                          unsigned int dispatch_flags);
404 #define I915_DISPATCH_SECURE BIT(0)
405 #define I915_DISPATCH_PINNED BIT(1)
406         int              (*emit_init_breadcrumb)(struct i915_request *rq);
407         u32             *(*emit_fini_breadcrumb)(struct i915_request *rq,
408                                                  u32 *cs);
409         unsigned int    emit_fini_breadcrumb_dw;
410
411         /* Pass the request to the hardware queue (e.g. directly into
412          * the legacy ringbuffer or to the end of an execlist).
413          *
414          * This is called from an atomic context with irqs disabled; must
415          * be irq safe.
416          */
417         void            (*submit_request)(struct i915_request *rq);
418
419         /*
420          * Called on signaling of a SUBMIT_FENCE, passing along the signaling
421          * request down to the bonded pairs.
422          */
423         void            (*bond_execute)(struct i915_request *rq,
424                                         struct dma_fence *signal);
425
426         /*
427          * Call when the priority on a request has changed and it and its
428          * dependencies may need rescheduling. Note the request itself may
429          * not be ready to run!
430          */
431         void            (*schedule)(struct i915_request *request,
432                                     const struct i915_sched_attr *attr);
433
434         /*
435          * Cancel all requests on the hardware, or queued for execution.
436          * This should only cancel the ready requests that have been
437          * submitted to the engine (via the engine->submit_request callback).
438          * This is called when marking the device as wedged.
439          */
440         void            (*cancel_requests)(struct intel_engine_cs *engine);
441
442         void            (*destroy)(struct intel_engine_cs *engine);
443
444         struct intel_engine_execlists execlists;
445
446         /* status_notifier: list of callbacks for context-switch changes */
447         struct atomic_notifier_head context_status_notifier;
448
449         struct intel_engine_hangcheck hangcheck;
450
451 #define I915_ENGINE_NEEDS_CMD_PARSER BIT(0)
452 #define I915_ENGINE_SUPPORTS_STATS   BIT(1)
453 #define I915_ENGINE_HAS_PREEMPTION   BIT(2)
454 #define I915_ENGINE_HAS_SEMAPHORES   BIT(3)
455 #define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(4)
456 #define I915_ENGINE_IS_VIRTUAL       BIT(5)
457         unsigned int flags;
458
459         /*
460          * Table of commands the command parser needs to know about
461          * for this engine.
462          */
463         DECLARE_HASHTABLE(cmd_hash, I915_CMD_HASH_ORDER);
464
465         /*
466          * Table of registers allowed in commands that read/write registers.
467          */
468         const struct drm_i915_reg_table *reg_tables;
469         int reg_table_count;
470
471         /*
472          * Returns the bitmask for the length field of the specified command.
473          * Return 0 for an unrecognized/invalid command.
474          *
475          * If the command parser finds an entry for a command in the engine's
476          * cmd_tables, it gets the command's length based on the table entry.
477          * If not, it calls this function to determine the per-engine length
478          * field encoding for the command (i.e. different opcode ranges use
479          * certain bits to encode the command length in the header).
480          */
481         u32 (*get_cmd_length_mask)(u32 cmd_header);
482
483         struct {
484                 /**
485                  * @lock: Lock protecting the below fields.
486                  */
487                 seqlock_t lock;
488                 /**
489                  * @enabled: Reference count indicating number of listeners.
490                  */
491                 unsigned int enabled;
492                 /**
493                  * @active: Number of contexts currently scheduled in.
494                  */
495                 unsigned int active;
496                 /**
497                  * @enabled_at: Timestamp when busy stats were enabled.
498                  */
499                 ktime_t enabled_at;
500                 /**
501                  * @start: Timestamp of the last idle to active transition.
502                  *
503                  * Idle is defined as active == 0, active is active > 0.
504                  */
505                 ktime_t start;
506                 /**
507                  * @total: Total time this engine was busy.
508                  *
509                  * Accumulated time not counting the most recent block in cases
510                  * where engine is currently busy (active > 0).
511                  */
512                 ktime_t total;
513         } stats;
514 };
515
516 static inline bool
517 intel_engine_needs_cmd_parser(const struct intel_engine_cs *engine)
518 {
519         return engine->flags & I915_ENGINE_NEEDS_CMD_PARSER;
520 }
521
522 static inline bool
523 intel_engine_supports_stats(const struct intel_engine_cs *engine)
524 {
525         return engine->flags & I915_ENGINE_SUPPORTS_STATS;
526 }
527
528 static inline bool
529 intel_engine_has_preemption(const struct intel_engine_cs *engine)
530 {
531         return engine->flags & I915_ENGINE_HAS_PREEMPTION;
532 }
533
534 static inline bool
535 intel_engine_has_semaphores(const struct intel_engine_cs *engine)
536 {
537         return engine->flags & I915_ENGINE_HAS_SEMAPHORES;
538 }
539
540 static inline bool
541 intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)
542 {
543         return engine->flags & I915_ENGINE_NEEDS_BREADCRUMB_TASKLET;
544 }
545
546 static inline bool
547 intel_engine_is_virtual(const struct intel_engine_cs *engine)
548 {
549         return engine->flags & I915_ENGINE_IS_VIRTUAL;
550 }
551
552 #define instdone_slice_mask(dev_priv__) \
553         (IS_GEN(dev_priv__, 7) ? \
554          1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)
555
556 #define instdone_subslice_mask(dev_priv__) \
557         (IS_GEN(dev_priv__, 7) ? \
558          1 : RUNTIME_INFO(dev_priv__)->sseu.subslice_mask[0])
559
560 #define for_each_instdone_slice_subslice(dev_priv__, slice__, subslice__) \
561         for ((slice__) = 0, (subslice__) = 0; \
562              (slice__) < I915_MAX_SLICES; \
563              (subslice__) = ((subslice__) + 1) < I915_MAX_SUBSLICES ? (subslice__) + 1 : 0, \
564                (slice__) += ((subslice__) == 0)) \
565                 for_each_if((BIT(slice__) & instdone_slice_mask(dev_priv__)) && \
566                             (BIT(subslice__) & instdone_subslice_mask(dev_priv__)))
567
568 #endif /* __INTEL_ENGINE_TYPES_H__ */