2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
7 #ifndef __INTEL_ENGINE_TYPES__
8 #define __INTEL_ENGINE_TYPES__
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>
18 #include "i915_gem_batch_pool.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"
27 #define I915_MAX_SLICES 3
28 #define I915_MAX_SUBSLICES 8
30 #define I915_CMD_HASH_ORDER 9
33 struct drm_i915_gem_object;
34 struct drm_i915_reg_table;
35 struct i915_gem_context;
37 struct i915_sched_attr;
40 typedef u8 intel_engine_mask_t;
41 #define ALL_ENGINES ((intel_engine_mask_t)~0ul)
43 struct intel_hw_status_page {
48 struct intel_instdone {
50 /* The following exist only in the RCS engine */
52 u32 sampler[I915_MAX_SLICES][I915_MAX_SUBSLICES];
53 u32 row[I915_MAX_SLICES][I915_MAX_SUBSLICES];
56 struct intel_engine_hangcheck {
60 unsigned long action_timestamp;
61 struct intel_instdone instdone;
69 struct i915_timeline *timeline;
70 struct list_head request_list;
71 struct list_head active_link;
83 * we use a single page to load ctx workarounds so all of these
84 * values are referred in terms of dwords
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
93 struct i915_ctx_workarounds {
94 struct i915_wa_ctx_bb {
97 } indirect_ctx, per_ctx;
101 #define I915_MAX_VCS 4
102 #define I915_MAX_VECS 2
105 * Engine IDs definitions.
106 * Keep instances of the same type engine together.
108 enum intel_engine_id {
115 #define _VCS(n) (VCS0 + (n))
118 #define _VECS(n) (VECS0 + (n))
122 struct st_preempt_hang {
123 struct completion completion;
129 * struct intel_engine_execlists - execlist submission queue and port state
131 * The struct intel_engine_execlists represents the combined logical state of
132 * driver and the hardware state for execlist mode of submission.
134 struct intel_engine_execlists {
136 * @tasklet: softirq tasklet for bottom handler
138 struct tasklet_struct tasklet;
141 * @default_priolist: priority list for I915_PRIORITY_NORMAL
143 struct i915_priolist default_priolist;
146 * @no_priolist: priority lists disabled
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+
155 u32 __iomem *submit_reg;
158 * @ctrl_reg: the enhanced execlists control register, used to load the
159 * submit queue on the HW and to request preemptions to idle
161 u32 __iomem *ctrl_reg;
164 * @port: execlist port states
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.
173 struct execlist_port {
175 * @request_count: combined request and submission count
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)
188 * @context_id: context ID for port
190 GEM_DEBUG_DECL(u32 context_id);
192 #define EXECLIST_MAX_PORTS 2
193 } port[EXECLIST_MAX_PORTS];
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.
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.
205 #define EXECLISTS_ACTIVE_USER 0
206 #define EXECLISTS_ACTIVE_PREEMPT 1
207 #define EXECLISTS_ACTIVE_HWACK 2
210 * @port_mask: number of execlist ports - 1
212 unsigned int port_mask;
215 * @queue_priority_hint: Highest pending priority.
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.
226 int queue_priority_hint;
229 * @queue: queue of requests, in priority lists
231 struct rb_root_cached queue;
232 struct rb_root_cached virtual;
235 * @csb_write: control register for Context Switch buffer
237 * Note this register may be either mmio or HWSP shadow.
242 * @csb_status: status array for Context Switch buffer
244 * Note these register may be either mmio or HWSP shadow.
249 * @preempt_complete_status: expected CSB upon completing preemption
251 u32 preempt_complete_status;
254 * @csb_size: context status buffer FIFO size
259 * @csb_head: context status buffer head
263 I915_SELFTEST_DECLARE(struct st_preempt_hang preempt_hang;)
266 #define INTEL_ENGINE_CS_MAX_NAME 8
268 struct intel_engine_cs {
269 struct drm_i915_private *i915;
270 struct intel_uncore *uncore;
271 char name[INTEL_ENGINE_CS_MAX_NAME];
273 enum intel_engine_id id;
276 intel_engine_mask_t mask;
285 u32 uabi_capabilities;
287 struct intel_sseu sseu;
289 struct intel_ring *buffer;
293 struct list_head requests;
296 struct llist_head barrier_tasks;
298 struct intel_context *kernel_context; /* pinned */
299 struct intel_context *preempt_context; /* pinned; optional */
301 intel_engine_mask_t saturated; /* submitting semaphores too late? */
303 unsigned long serial;
305 unsigned long wakeref_serial;
306 struct intel_wakeref wakeref;
307 struct drm_i915_gem_object *default_state;
308 void *pinned_default_state;
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.
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.
326 struct intel_breadcrumbs {
328 struct list_head signalers;
330 struct irq_work irq_work; /* for use from inside irq_lock */
332 unsigned int irq_enabled;
337 struct intel_engine_pmu {
339 * @enable: Bitmask of enable sample events on this engine.
341 * Bits correspond to sample event types, for instance
342 * I915_SAMPLE_QUEUED is bit 0 etc.
346 * @enable_count: Reference count for the enabled samplers.
348 * Index number corresponds to @enum drm_i915_pmu_engine_sample.
350 unsigned int enable_count[I915_ENGINE_SAMPLE_COUNT];
352 * @sample: Counter values for sampling events.
354 * Our internal timer stores the current counters in this field.
356 * Index number corresponds to @enum drm_i915_pmu_engine_sample.
358 struct i915_pmu_sample sample[I915_ENGINE_SAMPLE_COUNT];
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.
366 struct i915_gem_batch_pool batch_pool;
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;
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);
379 int (*resume)(struct intel_engine_cs *engine);
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);
387 void (*park)(struct intel_engine_cs *engine);
388 void (*unpark)(struct intel_engine_cs *engine);
390 void (*set_default_submission)(struct intel_engine_cs *engine);
392 const struct intel_context_ops *cops;
394 int (*request_alloc)(struct i915_request *rq);
395 int (*init_context)(struct i915_request *rq);
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,
409 unsigned int emit_fini_breadcrumb_dw;
411 /* Pass the request to the hardware queue (e.g. directly into
412 * the legacy ringbuffer or to the end of an execlist).
414 * This is called from an atomic context with irqs disabled; must
417 void (*submit_request)(struct i915_request *rq);
420 * Called on signaling of a SUBMIT_FENCE, passing along the signaling
421 * request down to the bonded pairs.
423 void (*bond_execute)(struct i915_request *rq,
424 struct dma_fence *signal);
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!
431 void (*schedule)(struct i915_request *request,
432 const struct i915_sched_attr *attr);
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.
440 void (*cancel_requests)(struct intel_engine_cs *engine);
442 void (*destroy)(struct intel_engine_cs *engine);
444 struct intel_engine_execlists execlists;
446 /* status_notifier: list of callbacks for context-switch changes */
447 struct atomic_notifier_head context_status_notifier;
449 struct intel_engine_hangcheck hangcheck;
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)
460 * Table of commands the command parser needs to know about
463 DECLARE_HASHTABLE(cmd_hash, I915_CMD_HASH_ORDER);
466 * Table of registers allowed in commands that read/write registers.
468 const struct drm_i915_reg_table *reg_tables;
472 * Returns the bitmask for the length field of the specified command.
473 * Return 0 for an unrecognized/invalid command.
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).
481 u32 (*get_cmd_length_mask)(u32 cmd_header);
485 * @lock: Lock protecting the below fields.
489 * @enabled: Reference count indicating number of listeners.
491 unsigned int enabled;
493 * @active: Number of contexts currently scheduled in.
497 * @enabled_at: Timestamp when busy stats were enabled.
501 * @start: Timestamp of the last idle to active transition.
503 * Idle is defined as active == 0, active is active > 0.
507 * @total: Total time this engine was busy.
509 * Accumulated time not counting the most recent block in cases
510 * where engine is currently busy (active > 0).
517 intel_engine_needs_cmd_parser(const struct intel_engine_cs *engine)
519 return engine->flags & I915_ENGINE_NEEDS_CMD_PARSER;
523 intel_engine_supports_stats(const struct intel_engine_cs *engine)
525 return engine->flags & I915_ENGINE_SUPPORTS_STATS;
529 intel_engine_has_preemption(const struct intel_engine_cs *engine)
531 return engine->flags & I915_ENGINE_HAS_PREEMPTION;
535 intel_engine_has_semaphores(const struct intel_engine_cs *engine)
537 return engine->flags & I915_ENGINE_HAS_SEMAPHORES;
541 intel_engine_needs_breadcrumb_tasklet(const struct intel_engine_cs *engine)
543 return engine->flags & I915_ENGINE_NEEDS_BREADCRUMB_TASKLET;
547 intel_engine_is_virtual(const struct intel_engine_cs *engine)
549 return engine->flags & I915_ENGINE_IS_VIRTUAL;
552 #define instdone_slice_mask(dev_priv__) \
553 (IS_GEN(dev_priv__, 7) ? \
554 1 : RUNTIME_INFO(dev_priv__)->sseu.slice_mask)
556 #define instdone_subslice_mask(dev_priv__) \
557 (IS_GEN(dev_priv__, 7) ? \
558 1 : RUNTIME_INFO(dev_priv__)->sseu.subslice_mask[0])
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__)))
568 #endif /* __INTEL_ENGINE_TYPES_H__ */