1 /*
2  * SPDX-License-Identifier: MIT
3  *
4  * Copyright © 2019 Intel Corporation
5  */
6 
7 #ifndef __INTEL_CONTEXT_TYPES__
8 #define __INTEL_CONTEXT_TYPES__
9 
10 #include <linux/kref.h>
11 #include <linux/list.h>
12 #include <linux/mutex.h>
13 #include <linux/types.h>
14 
15 #include "i915_active_types.h"
16 #include "i915_utils.h"
17 #include "intel_engine_types.h"
18 #include "intel_sseu.h"
19 
20 #define CONTEXT_REDZONE POISON_INUSE
21 
22 struct i915_gem_context;
23 struct i915_vma;
24 struct intel_context;
25 struct intel_ring;
26 
27 struct intel_context_ops {
28 	int (*alloc)(struct intel_context *ce);
29 
30 	int (*pin)(struct intel_context *ce);
31 	void (*unpin)(struct intel_context *ce);
32 
33 	void (*enter)(struct intel_context *ce);
34 	void (*exit)(struct intel_context *ce);
35 
36 	void (*reset)(struct intel_context *ce);
37 	void (*destroy)(struct kref *kref);
38 };
39 
40 struct intel_context {
41 	struct kref ref;
42 
43 	struct intel_engine_cs *engine;
44 	struct intel_engine_cs *inflight;
45 #define intel_context_inflight(ce) ptr_mask_bits((ce)->inflight, 2)
46 #define intel_context_inflight_count(ce) ptr_unmask_bits((ce)->inflight, 2)
47 
48 	struct i915_address_space *vm;
49 	struct i915_gem_context __rcu *gem_context;
50 
51 	struct list_head signal_link;
52 	struct list_head signals;
53 
54 	struct i915_vma *state;
55 	struct intel_ring *ring;
56 	struct intel_timeline *timeline;
57 
58 	unsigned long flags;
59 #define CONTEXT_BARRIER_BIT		0
60 #define CONTEXT_ALLOC_BIT		1
61 #define CONTEXT_VALID_BIT		2
62 #define CONTEXT_USE_SEMAPHORES		3
63 #define CONTEXT_BANNED			4
64 #define CONTEXT_FORCE_SINGLE_SUBMISSION	5
65 #define CONTEXT_NOPREEMPT		6
66 
67 	u32 *lrc_reg_state;
68 	u64 lrc_desc;
69 	u32 tag; /* cookie passed to HW to track this context on submission */
70 
71 	unsigned int active_count; /* protected by timeline->mutex */
72 
73 	atomic_t pin_count;
74 	struct mutex pin_mutex; /* guards pinning and associated on-gpuing */
75 
76 	/**
77 	 * active: Active tracker for the rq activity (inc. external) on this
78 	 * intel_context object.
79 	 */
80 	struct i915_active active;
81 
82 	const struct intel_context_ops *ops;
83 
84 	/** sseu: Control eu/slice partitioning */
85 	struct intel_sseu sseu;
86 };
87 
88 #endif /* __INTEL_CONTEXT_TYPES__ */
89