1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25#include "i915_drv.h"
26#include "i915_syncmap.h"
27
28static void __intel_timeline_init(struct intel_timeline *tl,
29 struct i915_gem_timeline *parent,
30 u64 context,
31 struct lock_class_key *lockclass,
32 const char *lockname)
33{
34 tl->fence_context = context;
35 tl->common = parent;
36 spin_lock_init(&tl->lock);
37 lockdep_set_class_and_name(&tl->lock, lockclass, lockname);
38 init_request_active(&tl->last_request, NULL);
39 INIT_LIST_HEAD(&tl->requests);
40 i915_syncmap_init(&tl->sync);
41}
42
43static void __intel_timeline_fini(struct intel_timeline *tl)
44{
45 GEM_BUG_ON(!list_empty(&tl->requests));
46
47 i915_syncmap_free(&tl->sync);
48}
49
50static int __i915_gem_timeline_init(struct drm_i915_private *i915,
51 struct i915_gem_timeline *timeline,
52 const char *name,
53 struct lock_class_key *lockclass,
54 const char *lockname)
55{
56 unsigned int i;
57 u64 fences;
58
59 lockdep_assert_held(&i915->drm.struct_mutex);
60
61
62
63
64
65
66
67 BUILD_BUG_ON(KSYNCMAP < I915_NUM_ENGINES);
68
69 timeline->i915 = i915;
70 timeline->name = kstrdup(name ?: "[kernel]", GFP_KERNEL);
71 if (!timeline->name)
72 return -ENOMEM;
73
74 list_add(&timeline->link, &i915->gt.timelines);
75
76
77 fences = dma_fence_context_alloc(ARRAY_SIZE(timeline->engine));
78 for (i = 0; i < ARRAY_SIZE(timeline->engine); i++)
79 __intel_timeline_init(&timeline->engine[i],
80 timeline, fences++,
81 lockclass, lockname);
82
83 return 0;
84}
85
86int i915_gem_timeline_init(struct drm_i915_private *i915,
87 struct i915_gem_timeline *timeline,
88 const char *name)
89{
90 static struct lock_class_key class;
91
92 return __i915_gem_timeline_init(i915, timeline, name,
93 &class, "&timeline->lock");
94}
95
96int i915_gem_timeline_init__global(struct drm_i915_private *i915)
97{
98 static struct lock_class_key class;
99
100 return __i915_gem_timeline_init(i915,
101 &i915->gt.global_timeline,
102 "[execution]",
103 &class, "&global_timeline->lock");
104}
105
106
107
108
109
110
111
112
113
114
115
116void i915_gem_timelines_park(struct drm_i915_private *i915)
117{
118 struct i915_gem_timeline *timeline;
119 int i;
120
121 lockdep_assert_held(&i915->drm.struct_mutex);
122
123 list_for_each_entry(timeline, &i915->gt.timelines, link) {
124 for (i = 0; i < ARRAY_SIZE(timeline->engine); i++) {
125 struct intel_timeline *tl = &timeline->engine[i];
126
127
128
129
130
131
132
133 i915_syncmap_free(&tl->sync);
134 }
135 }
136}
137
138void i915_gem_timeline_fini(struct i915_gem_timeline *timeline)
139{
140 int i;
141
142 lockdep_assert_held(&timeline->i915->drm.struct_mutex);
143
144 for (i = 0; i < ARRAY_SIZE(timeline->engine); i++)
145 __intel_timeline_fini(&timeline->engine[i]);
146
147 list_del(&timeline->link);
148 kfree(timeline->name);
149}
150
151#if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
152#include "selftests/mock_timeline.c"
153#include "selftests/i915_gem_timeline.c"
154#endif
155