2 * SPDX-License-Identifier: MIT
4 * Copyright © 2019 Intel Corporation
7 #ifndef __INTEL_CONTEXT_TYPES__
8 #define __INTEL_CONTEXT_TYPES__
10 #include <linux/average.h>
11 #include <linux/kref.h>
12 #include <linux/list.h>
13 #include <linux/mutex.h>
14 #include <linux/types.h>
16 #include "i915_active_types.h"
17 #include "i915_utils.h"
18 #include "intel_engine_types.h"
19 #include "intel_sseu.h"
21 #define CONTEXT_REDZONE POISON_INUSE
23 DECLARE_EWMA(runtime, 3, 8);
25 struct i915_gem_context;
30 struct intel_context_ops {
31 int (*alloc)(struct intel_context *ce);
33 int (*pin)(struct intel_context *ce);
34 void (*unpin)(struct intel_context *ce);
36 void (*enter)(struct intel_context *ce);
37 void (*exit)(struct intel_context *ce);
39 void (*reset)(struct intel_context *ce);
40 void (*destroy)(struct kref *kref);
43 struct intel_context {
46 struct intel_engine_cs *engine;
47 struct intel_engine_cs *inflight;
48 #define intel_context_inflight(ce) ptr_mask_bits(READ_ONCE((ce)->inflight), 2)
49 #define intel_context_inflight_count(ce) ptr_unmask_bits(READ_ONCE((ce)->inflight), 2)
51 struct i915_address_space *vm;
52 struct i915_gem_context __rcu *gem_context;
54 struct list_head signal_link;
55 struct list_head signals;
57 struct i915_vma *state;
58 struct intel_ring *ring;
59 struct intel_timeline *timeline;
62 #define CONTEXT_BARRIER_BIT 0
63 #define CONTEXT_ALLOC_BIT 1
64 #define CONTEXT_VALID_BIT 2
65 #define CONTEXT_CLOSED_BIT 3
66 #define CONTEXT_USE_SEMAPHORES 4
67 #define CONTEXT_BANNED 5
68 #define CONTEXT_FORCE_SINGLE_SUBMISSION 6
69 #define CONTEXT_NOPREEMPT 7
73 u32 tag; /* cookie passed to HW to track this context on submission */
75 /* Time on GPU as tracked by the hw. */
77 struct ewma_runtime avg;
80 I915_SELFTEST_DECLARE(u32 num_underflow);
81 I915_SELFTEST_DECLARE(u32 max_underflow);
84 unsigned int active_count; /* protected by timeline->mutex */
87 struct mutex pin_mutex; /* guards pinning and associated on-gpuing */
90 * active: Active tracker for the rq activity (inc. external) on this
91 * intel_context object.
93 struct i915_active active;
95 const struct intel_context_ops *ops;
97 /** sseu: Control eu/slice partitioning */
98 struct intel_sseu sseu;
101 #endif /* __INTEL_CONTEXT_TYPES__ */