1 /* SPDX-License-Identifier: MIT */
3 * Copyright © 2019 Intel Corporation
6 #ifndef __INTEL_CONTEXT_TYPES__
7 #define __INTEL_CONTEXT_TYPES__
9 #include <linux/average.h>
10 #include <linux/kref.h>
11 #include <linux/list.h>
12 #include <linux/mutex.h>
13 #include <linux/types.h>
15 #include "i915_active_types.h"
16 #include "i915_sw_fence.h"
17 #include "i915_utils.h"
18 #include "intel_engine_types.h"
19 #include "intel_sseu.h"
21 #include "uc/intel_guc_fwif.h"
23 #define CONTEXT_REDZONE POISON_INUSE
24 DECLARE_EWMA(runtime, 3, 8);
26 struct i915_gem_context;
27 struct i915_gem_ww_ctx;
29 struct intel_breadcrumbs;
33 struct intel_context_ops {
35 #define COPS_HAS_INFLIGHT_BIT 0
36 #define COPS_HAS_INFLIGHT BIT(COPS_HAS_INFLIGHT_BIT)
38 #define COPS_RUNTIME_CYCLES_BIT 1
39 #define COPS_RUNTIME_CYCLES BIT(COPS_RUNTIME_CYCLES_BIT)
41 int (*alloc)(struct intel_context *ce);
43 void (*ban)(struct intel_context *ce, struct i915_request *rq);
45 int (*pre_pin)(struct intel_context *ce, struct i915_gem_ww_ctx *ww, void **vaddr);
46 int (*pin)(struct intel_context *ce, void *vaddr);
47 void (*unpin)(struct intel_context *ce);
48 void (*post_unpin)(struct intel_context *ce);
50 void (*cancel_request)(struct intel_context *ce,
51 struct i915_request *rq);
53 void (*enter)(struct intel_context *ce);
54 void (*exit)(struct intel_context *ce);
56 void (*sched_disable)(struct intel_context *ce);
58 void (*reset)(struct intel_context *ce);
59 void (*destroy)(struct kref *kref);
61 /* virtual/parallel engine/context interface */
62 struct intel_context *(*create_virtual)(struct intel_engine_cs **engine,
65 struct intel_context *(*create_parallel)(struct intel_engine_cs **engines,
66 unsigned int num_siblings,
68 struct intel_engine_cs *(*get_sibling)(struct intel_engine_cs *engine,
69 unsigned int sibling);
72 struct intel_context {
74 * Note: Some fields may be accessed under RCU.
76 * Unless otherwise noted a field can safely be assumed to be protected
77 * by strong reference counting.
80 struct kref ref; /* no kref_get_unless_zero()! */
84 struct intel_engine_cs *engine;
85 struct intel_engine_cs *inflight;
86 #define __intel_context_inflight(engine) ptr_mask_bits(engine, 3)
87 #define __intel_context_inflight_count(engine) ptr_unmask_bits(engine, 3)
88 #define intel_context_inflight(ce) \
89 __intel_context_inflight(READ_ONCE((ce)->inflight))
90 #define intel_context_inflight_count(ce) \
91 __intel_context_inflight_count(READ_ONCE((ce)->inflight))
93 struct i915_address_space *vm;
94 struct i915_gem_context __rcu *gem_context;
97 * @signal_lock protects the list of requests that need signaling,
98 * @signals. While there are any requests that need signaling,
99 * we add the context to the breadcrumbs worker, and remove it
100 * upon completion/cancellation of the last request.
102 struct list_head signal_link; /* Accessed under RCU */
103 struct list_head signals; /* Guarded by signal_lock */
104 spinlock_t signal_lock; /* protects signals, the list of requests */
106 struct i915_vma *state;
108 struct intel_ring *ring;
109 struct intel_timeline *timeline;
112 #define CONTEXT_BARRIER_BIT 0
113 #define CONTEXT_ALLOC_BIT 1
114 #define CONTEXT_INIT_BIT 2
115 #define CONTEXT_VALID_BIT 3
116 #define CONTEXT_CLOSED_BIT 4
117 #define CONTEXT_USE_SEMAPHORES 5
118 #define CONTEXT_BANNED 6
119 #define CONTEXT_FORCE_SINGLE_SUBMISSION 7
120 #define CONTEXT_NOPREEMPT 8
121 #define CONTEXT_LRCA_DIRTY 9
122 #define CONTEXT_GUC_INIT 10
123 #define CONTEXT_PERMA_PIN 11
124 #define CONTEXT_IS_PARKING 12
138 u32 tag; /* cookie passed to HW to track this context on submission */
140 /** stats: Context GPU engine busyness tracking. */
141 struct intel_context_stats {
144 /* Time on GPU as tracked by the hw. */
146 struct ewma_runtime avg;
149 I915_SELFTEST_DECLARE(u32 num_underflow);
150 I915_SELFTEST_DECLARE(u32 max_underflow);
154 unsigned int active_count; /* protected by timeline->mutex */
157 struct mutex pin_mutex; /* guards pinning and associated on-gpuing */
160 * active: Active tracker for the rq activity (inc. external) on this
161 * intel_context object.
163 struct i915_active active;
165 const struct intel_context_ops *ops;
167 /** sseu: Control eu/slice partitioning */
168 struct intel_sseu sseu;
171 * pinned_contexts_link: List link for the engine's pinned contexts.
172 * This is only used if this is a perma-pinned kernel context and
173 * the list is assumed to only be manipulated during driver load
174 * or unload time so no mutex protection currently.
176 struct list_head pinned_contexts_link;
178 u8 wa_bb_page; /* if set, page num reserved for context workarounds */
181 /** @lock: protects everything in guc_state */
184 * @sched_state: scheduling state of this context using GuC
189 * @fences: maintains a list of requests that are currently
190 * being fenced until a GuC operation completes
192 struct list_head fences;
194 * @blocked: fence used to signal when the blocking of a
195 * context's submissions is complete.
197 struct i915_sw_fence blocked;
198 /** @number_committed_requests: number of committed requests */
199 int number_committed_requests;
200 /** @requests: list of active requests on this context */
201 struct list_head requests;
202 /** @prio: the context's current guc priority */
205 * @prio_count: a counter of the number requests in flight in
206 * each priority bucket
208 u32 prio_count[GUC_CLIENT_PRIORITY_NUM];
213 * @id: handle which is used to uniquely identify this context
214 * with the GuC, protected by guc->submission_state.lock
218 * @ref: the number of references to the guc_id, when
219 * transitioning in and out of zero protected by
220 * guc->submission_state.lock
224 * @link: in guc->guc_id_list when the guc_id has no refs but is
225 * still valid, protected by guc->submission_state.lock
227 struct list_head link;
231 * @destroyed_link: link in guc->submission_state.destroyed_contexts, in
232 * list when context is pending to be destroyed (deregistered with the
233 * GuC), protected by guc->submission_state.lock
235 struct list_head destroyed_link;
237 /** @parallel: sub-structure for parallel submission members */
241 * @child_list: parent's list of children
242 * contexts, no protection as immutable after context
245 struct list_head child_list;
247 * @child_link: child's link into parent's list of
250 struct list_head child_link;
252 /** @parent: pointer to parent if child */
253 struct intel_context *parent;
255 * @last_rq: last request submitted on a parallel context, used
256 * to insert submit fences between requests in the parallel
259 struct i915_request *last_rq;
261 * @fence_context: fence context composite fence when doing
262 * parallel submission
266 * @seqno: seqno for composite fence when doing parallel
270 /** @number_children: number of children if parent */
272 /** @child_index: index into child_list if child */
274 /** @guc: GuC specific members for parallel submission */
276 /** @wqi_head: head pointer in work queue */
278 /** @wqi_tail: tail pointer in work queue */
281 * @parent_page: page in context state (ce->state) used
282 * by parent for work queue, process descriptor
288 #ifdef CONFIG_DRM_I915_SELFTEST
290 * @drop_schedule_enable: Force drop of schedule enable G2H for selftest
292 bool drop_schedule_enable;
295 * @drop_schedule_disable: Force drop of schedule disable G2H for
298 bool drop_schedule_disable;
301 * @drop_deregister: Force drop of deregister G2H for selftest
303 bool drop_deregister;
307 #endif /* __INTEL_CONTEXT_TYPES__ */