2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
7 #ifndef __INTEL_ENGINE_TYPES__
8 #define __INTEL_ENGINE_TYPES__
10 #include <linux/average.h>
11 #include <linux/hashtable.h>
12 #include <linux/irq_work.h>
13 #include <linux/kref.h>
14 #include <linux/list.h>
15 #include <linux/llist.h>
16 #include <linux/rbtree.h>
17 #include <linux/timer.h>
18 #include <linux/types.h>
19 #include <linux/workqueue.h>
23 #include "i915_priolist_types.h"
24 #include "i915_selftest.h"
25 #include "intel_breadcrumbs_types.h"
26 #include "intel_sseu.h"
27 #include "intel_timeline_types.h"
28 #include "intel_uncore.h"
29 #include "intel_wakeref.h"
30 #include "intel_workarounds_types.h"
32 /* Legacy HW Engine ID */
43 /* Gen11+ HW Engine class + instance */
44 #define RENDER_CLASS 0
45 #define VIDEO_DECODE_CLASS 1
46 #define VIDEO_ENHANCEMENT_CLASS 2
47 #define COPY_ENGINE_CLASS 3
49 #define MAX_ENGINE_CLASS 4
50 #define MAX_ENGINE_INSTANCE 3
52 #define I915_MAX_SLICES 3
53 #define I915_MAX_SUBSLICES 8
55 #define I915_CMD_HASH_ORDER 9
58 struct drm_i915_gem_object;
59 struct drm_i915_reg_table;
60 struct i915_gem_context;
62 struct i915_sched_attr;
67 typedef u8 intel_engine_mask_t;
68 #define ALL_ENGINES ((intel_engine_mask_t)~0ul)
70 struct intel_hw_status_page {
75 struct intel_instdone {
77 /* The following exist only in the RCS engine */
79 u32 slice_common_extra[2];
80 u32 sampler[I915_MAX_SLICES][I915_MAX_SUBSLICES];
81 u32 row[I915_MAX_SLICES][I915_MAX_SUBSLICES];
85 * we use a single page to load ctx workarounds so all of these
86 * values are referred in terms of dwords
88 * struct i915_wa_ctx_bb:
89 * offset: specifies batch starting position, also helpful in case
90 * if we want to have multiple batches at different offsets based on
91 * some criteria. It is not a requirement at the moment but provides
92 * an option for future use.
93 * size: size of the batch in DWORDS
95 struct i915_ctx_workarounds {
96 struct i915_wa_ctx_bb {
99 } indirect_ctx, per_ctx;
100 struct i915_vma *vma;
103 #define I915_MAX_VCS 4
104 #define I915_MAX_VECS 2
107 * Engine IDs definitions.
108 * Keep instances of the same type engine together.
110 enum intel_engine_id {
117 #define _VCS(n) (VCS0 + (n))
120 #define _VECS(n) (VECS0 + (n))
122 #define INVALID_ENGINE ((enum intel_engine_id)-1)
125 /* A simple estimator for the round-trip latency of an engine */
126 DECLARE_EWMA(_engine_latency, 6, 4)
128 struct st_preempt_hang {
129 struct completion completion;
134 * struct intel_engine_execlists - execlist submission queue and port state
136 * The struct intel_engine_execlists represents the combined logical state of
137 * driver and the hardware state for execlist mode of submission.
139 struct intel_engine_execlists {
141 * @tasklet: softirq tasklet for bottom handler
143 struct tasklet_struct tasklet;
146 * @timer: kick the current context if its timeslice expires
148 struct timer_list timer;
151 * @preempt: reset the current context if it fails to give way
153 struct timer_list preempt;
156 * @default_priolist: priority list for I915_PRIORITY_NORMAL
158 struct i915_priolist default_priolist;
161 * @ccid: identifier for contexts submitted to this engine
166 * @yield: CCID at the time of the last semaphore-wait interrupt.
168 * Instead of leaving a semaphore busy-spinning on an engine, we would
169 * like to switch to another ready context, i.e. yielding the semaphore
175 * @error_interrupt: CS Master EIR
177 * The CS generates an interrupt when it detects an error. We capture
178 * the first error interrupt, record the EIR and schedule the tasklet.
179 * In the tasklet, we process the pending CS events to ensure we have
180 * the guilty request, and then reset the engine.
182 * Low 16b are used by HW, with the upper 16b used as the enabling mask.
183 * Reserve the upper 16b for tracking internal errors.
186 #define ERROR_CSB BIT(31)
189 * @reset_ccid: Active CCID [EXECLISTS_STATUS_HI] at the time of reset
194 * @no_priolist: priority lists disabled
199 * @submit_reg: gen-specific execlist submission register
200 * set to the ExecList Submission Port (elsp) register pre-Gen11 and to
201 * the ExecList Submission Queue Contents register array for Gen11+
203 u32 __iomem *submit_reg;
206 * @ctrl_reg: the enhanced execlists control register, used to load the
207 * submit queue on the HW and to request preemptions to idle
209 u32 __iomem *ctrl_reg;
211 #define EXECLIST_MAX_PORTS 2
213 * @active: the currently known context executing on HW
215 struct i915_request * const *active;
217 * @inflight: the set of contexts submitted and acknowleged by HW
219 * The set of inflight contexts is managed by reading CS events
220 * from the HW. On a context-switch event (not preemption), we
221 * know the HW has transitioned from port0 to port1, and we
222 * advance our inflight/active tracking accordingly.
224 struct i915_request *inflight[EXECLIST_MAX_PORTS + 1 /* sentinel */];
226 * @pending: the next set of contexts submitted to ELSP
228 * We store the array of contexts that we submit to HW (via ELSP) and
229 * promote them to the inflight array once HW has signaled the
230 * preemption or idle-to-active event.
232 struct i915_request *pending[EXECLIST_MAX_PORTS + 1];
235 * @port_mask: number of execlist ports - 1
237 unsigned int port_mask;
240 * @switch_priority_hint: Second context priority.
242 * We submit multiple contexts to the HW simultaneously and would
243 * like to occasionally switch between them to emulate timeslicing.
244 * To know when timeslicing is suitable, we track the priority of
245 * the context submitted second.
247 int switch_priority_hint;
250 * @queue_priority_hint: Highest pending priority.
252 * When we add requests into the queue, or adjust the priority of
253 * executing requests, we compute the maximum priority of those
254 * pending requests. We can then use this value to determine if
255 * we need to preempt the executing requests to service the queue.
256 * However, since the we may have recorded the priority of an inflight
257 * request we wanted to preempt but since completed, at the time of
258 * dequeuing the priority hint may no longer may match the highest
259 * available request priority.
261 int queue_priority_hint;
264 * @queue: queue of requests, in priority lists
266 struct rb_root_cached queue;
267 struct rb_root_cached virtual;
270 * @csb_write: control register for Context Switch buffer
272 * Note this register may be either mmio or HWSP shadow.
277 * @csb_status: status array for Context Switch buffer
279 * Note these register may be either mmio or HWSP shadow.
284 * @csb_size: context status buffer FIFO size
289 * @csb_head: context status buffer head
293 I915_SELFTEST_DECLARE(struct st_preempt_hang preempt_hang;)
296 #define INTEL_ENGINE_CS_MAX_NAME 8
298 struct intel_engine_cs {
299 struct drm_i915_private *i915;
301 struct intel_uncore *uncore;
302 char name[INTEL_ENGINE_CS_MAX_NAME];
304 enum intel_engine_id id;
305 enum intel_engine_id legacy_idx;
310 intel_engine_mask_t mask;
318 u32 uabi_capabilities;
323 * Some w/a require forcewake to be held (which prevents RC6) while
324 * a particular engine is active. If so, we set fw_domain to which
325 * domains need to be held for the duration of request activity,
326 * and 0 if none. We try to limit the duration of the hold as much
329 enum forcewake_domains fw_domain;
332 unsigned long context_tag;
334 struct rb_node uabi_node;
336 struct intel_sseu sseu;
340 struct list_head requests;
341 struct list_head hold; /* ready requests, but on hold */
344 /* keep a request in reserve for a [pm] barrier under oom */
345 struct i915_request *request_pool;
347 struct llist_head barrier_tasks;
349 struct intel_context *kernel_context; /* pinned */
351 intel_engine_mask_t saturated; /* submitting semaphores too late? */
354 struct delayed_work work;
355 struct i915_request *systole;
356 unsigned long blocked;
359 unsigned long serial;
361 unsigned long wakeref_serial;
362 struct intel_wakeref wakeref;
363 struct file *default_state;
366 struct intel_ring *ring;
367 struct intel_timeline *timeline;
371 * We track the average duration of the idle pulse on parking the
372 * engine to keep an estimate of the how the fast the engine is
373 * under ideal conditions.
375 struct ewma__engine_latency latency;
377 /* Keep track of all the seqno used, a trail of breadcrumbs */
378 struct intel_breadcrumbs *breadcrumbs;
380 struct intel_engine_pmu {
382 * @enable: Bitmask of enable sample events on this engine.
384 * Bits correspond to sample event types, for instance
385 * I915_SAMPLE_QUEUED is bit 0 etc.
389 * @enable_count: Reference count for the enabled samplers.
391 * Index number corresponds to @enum drm_i915_pmu_engine_sample.
393 unsigned int enable_count[I915_ENGINE_SAMPLE_COUNT];
395 * @sample: Counter values for sampling events.
397 * Our internal timer stores the current counters in this field.
399 * Index number corresponds to @enum drm_i915_pmu_engine_sample.
401 struct i915_pmu_sample sample[I915_ENGINE_SAMPLE_COUNT];
404 struct intel_hw_status_page status_page;
405 struct i915_ctx_workarounds wa_ctx;
406 struct i915_wa_list ctx_wa_list;
407 struct i915_wa_list wa_list;
408 struct i915_wa_list whitelist;
410 u32 irq_keep_mask; /* always keep these interrupts */
411 u32 irq_enable_mask; /* bitmask to enable ring interrupt */
412 void (*irq_enable)(struct intel_engine_cs *engine);
413 void (*irq_disable)(struct intel_engine_cs *engine);
415 void (*sanitize)(struct intel_engine_cs *engine);
416 int (*resume)(struct intel_engine_cs *engine);
419 void (*prepare)(struct intel_engine_cs *engine);
421 void (*rewind)(struct intel_engine_cs *engine, bool stalled);
422 void (*cancel)(struct intel_engine_cs *engine);
424 void (*finish)(struct intel_engine_cs *engine);
427 void (*park)(struct intel_engine_cs *engine);
428 void (*unpark)(struct intel_engine_cs *engine);
430 void (*set_default_submission)(struct intel_engine_cs *engine);
432 const struct intel_context_ops *cops;
434 int (*request_alloc)(struct i915_request *rq);
436 int (*emit_flush)(struct i915_request *request, u32 mode);
437 #define EMIT_INVALIDATE BIT(0)
438 #define EMIT_FLUSH BIT(1)
439 #define EMIT_BARRIER (EMIT_INVALIDATE | EMIT_FLUSH)
440 int (*emit_bb_start)(struct i915_request *rq,
441 u64 offset, u32 length,
442 unsigned int dispatch_flags);
443 #define I915_DISPATCH_SECURE BIT(0)
444 #define I915_DISPATCH_PINNED BIT(1)
445 int (*emit_init_breadcrumb)(struct i915_request *rq);
446 u32 *(*emit_fini_breadcrumb)(struct i915_request *rq,
448 unsigned int emit_fini_breadcrumb_dw;
450 /* Pass the request to the hardware queue (e.g. directly into
451 * the legacy ringbuffer or to the end of an execlist).
453 * This is called from an atomic context with irqs disabled; must
456 void (*submit_request)(struct i915_request *rq);
459 * Called on signaling of a SUBMIT_FENCE, passing along the signaling
460 * request down to the bonded pairs.
462 void (*bond_execute)(struct i915_request *rq,
463 struct dma_fence *signal);
466 * Call when the priority on a request has changed and it and its
467 * dependencies may need rescheduling. Note the request itself may
468 * not be ready to run!
470 void (*schedule)(struct i915_request *request,
471 const struct i915_sched_attr *attr);
473 void (*release)(struct intel_engine_cs *engine);
475 struct intel_engine_execlists execlists;
478 * Keep track of completed timelines on this engine for early
479 * retirement with the goal of quickly enabling powersaving as
480 * soon as the engine is idle.
482 struct intel_timeline *retire;
483 struct work_struct retire_work;
485 /* status_notifier: list of callbacks for context-switch changes */
486 struct atomic_notifier_head context_status_notifier;
488 #define I915_ENGINE_USING_CMD_PARSER BIT(0)
489 #define I915_ENGINE_SUPPORTS_STATS BIT(1)
490 #define I915_ENGINE_HAS_PREEMPTION BIT(2)
491 #define I915_ENGINE_HAS_SEMAPHORES BIT(3)
492 #define I915_ENGINE_HAS_TIMESLICES BIT(4)
493 #define I915_ENGINE_NEEDS_BREADCRUMB_TASKLET BIT(5)
494 #define I915_ENGINE_IS_VIRTUAL BIT(6)
495 #define I915_ENGINE_HAS_RELATIVE_MMIO BIT(7)
496 #define I915_ENGINE_REQUIRES_CMD_PARSER BIT(8)
500 * Table of commands the command parser needs to know about
503 DECLARE_HASHTABLE(cmd_hash, I915_CMD_HASH_ORDER);
506 * Table of registers allowed in commands that read/write registers.
508 const struct drm_i915_reg_table *reg_tables;
512 * Returns the bitmask for the length field of the specified command.
513 * Return 0 for an unrecognized/invalid command.
515 * If the command parser finds an entry for a command in the engine's
516 * cmd_tables, it gets the command's length based on the table entry.
517 * If not, it calls this function to determine the per-engine length
518 * field encoding for the command (i.e. different opcode ranges use
519 * certain bits to encode the command length in the header).
521 u32 (*get_cmd_length_mask)(u32 cmd_header);
525 * @active: Number of contexts currently scheduled in.
530 * @lock: Lock protecting the below fields.
535 * @total: Total time this engine was busy.
537 * Accumulated time not counting the most recent block in cases
538 * where engine is currently busy (active > 0).
543 * @start: Timestamp of the last idle to active transition.
545 * Idle is defined as active == 0, active is active > 0.
550 * @rps: Utilisation at last RPS sampling.
556 unsigned long heartbeat_interval_ms;
557 unsigned long max_busywait_duration_ns;
558 unsigned long preempt_timeout_ms;
559 unsigned long stop_timeout_ms;
560 unsigned long timeslice_duration_ms;
565 intel_engine_using_cmd_parser(const struct intel_engine_cs *engine)
567 return engine->flags & I915_ENGINE_USING_CMD_PARSER;
571 intel_engine_requires_cmd_parser(const struct intel_engine_cs *engine)
573 return engine->flags & I915_ENGINE_REQUIRES_CMD_PARSER;
577 intel_engine_supports_stats(const struct intel_engine_cs *engine)
579 return engine->flags & I915_ENGINE_SUPPORTS_STATS;
583 intel_engine_has_preemption(const struct intel_engine_cs *engine)
585 return engine->flags & I915_ENGINE_HAS_PREEMPTION;
589 intel_engine_has_semaphores(const struct intel_engine_cs *engine)
591 return engine->flags & I915_ENGINE_HAS_SEMAPHORES;
595 intel_engine_has_timeslices(const struct intel_engine_cs *engine)
597 if (!IS_ACTIVE(CONFIG_DRM_I915_TIMESLICE_DURATION))
600 return engine->flags & I915_ENGINE_HAS_TIMESLICES;
604 intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)
606 return engine->flags & I915_ENGINE_NEEDS_BREADCRUMB_TASKLET;
610 intel_engine_is_virtual(const struct intel_engine_cs *engine)
612 return engine->flags & I915_ENGINE_IS_VIRTUAL;
616 intel_engine_has_relative_mmio(const struct intel_engine_cs * const engine)
618 return engine->flags & I915_ENGINE_HAS_RELATIVE_MMIO;
621 #define instdone_has_slice(dev_priv___, sseu___, slice___) \
622 ((IS_GEN(dev_priv___, 7) ? 1 : ((sseu___)->slice_mask)) & BIT(slice___))
624 #define instdone_has_subslice(dev_priv__, sseu__, slice__, subslice__) \
625 (IS_GEN(dev_priv__, 7) ? (1 & BIT(subslice__)) : \
626 intel_sseu_has_subslice(sseu__, 0, subslice__))
628 #define for_each_instdone_slice_subslice(dev_priv_, sseu_, slice_, subslice_) \
629 for ((slice_) = 0, (subslice_) = 0; (slice_) < I915_MAX_SLICES; \
630 (subslice_) = ((subslice_) + 1) % I915_MAX_SUBSLICES, \
631 (slice_) += ((subslice_) == 0)) \
632 for_each_if((instdone_has_slice(dev_priv_, sseu_, slice_)) && \
633 (instdone_has_subslice(dev_priv_, sseu_, slice_, \
635 #endif /* __INTEL_ENGINE_TYPES_H__ */