2 * Copyright © 2016 Intel Corporation
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice (including the next
12 * paragraph) shall be included in all copies or substantial portions of the
15 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
20 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
26 #include "i915_syncmap.h"
28 static void __intel_timeline_init(struct intel_timeline
*tl
,
29 struct i915_gem_timeline
*parent
,
31 struct lock_class_key
*lockclass
,
34 tl
->fence_context
= context
;
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
);
43 static void __intel_timeline_fini(struct intel_timeline
*tl
)
45 GEM_BUG_ON(!list_empty(&tl
->requests
));
47 i915_syncmap_free(&tl
->sync
);
50 static int __i915_gem_timeline_init(struct drm_i915_private
*i915
,
51 struct i915_gem_timeline
*timeline
,
53 struct lock_class_key
*lockclass
,
59 lockdep_assert_held(&i915
->drm
.struct_mutex
);
62 * Ideally we want a set of engines on a single leaf as we expect
63 * to mostly be tracking synchronisation between engines. It is not
64 * a huge issue if this is not the case, but we may want to mitigate
65 * any page crossing penalties if they become an issue.
67 BUILD_BUG_ON(KSYNCMAP
< I915_NUM_ENGINES
);
69 timeline
->i915
= i915
;
70 timeline
->name
= kstrdup(name
?: "[kernel]", GFP_KERNEL
);
74 list_add(&timeline
->link
, &i915
->gt
.timelines
);
76 /* Called during early_init before we know how many engines there are */
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
],
86 int i915_gem_timeline_init(struct drm_i915_private
*i915
,
87 struct i915_gem_timeline
*timeline
,
90 static struct lock_class_key
class;
92 return __i915_gem_timeline_init(i915
, timeline
, name
,
93 &class, "&timeline->lock");
96 int i915_gem_timeline_init__global(struct drm_i915_private
*i915
)
98 static struct lock_class_key
class;
100 return __i915_gem_timeline_init(i915
,
101 &i915
->gt
.global_timeline
,
103 &class, "&global_timeline->lock");
107 * i915_gem_timelines_park - called when the driver idles
108 * @i915: the drm_i915_private device
110 * When the driver is completely idle, we know that all of our sync points
111 * have been signaled and our tracking is then entirely redundant. Any request
112 * to wait upon an older sync point will be completed instantly as we know
113 * the fence is signaled and therefore we will not even look them up in the
116 void i915_gem_timelines_park(struct drm_i915_private
*i915
)
118 struct i915_gem_timeline
*timeline
;
121 lockdep_assert_held(&i915
->drm
.struct_mutex
);
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
];
128 * All known fences are completed so we can scrap
129 * the current sync point tracking and start afresh,
130 * any attempt to wait upon a previous sync point
131 * will be skipped as the fence was signaled.
133 i915_syncmap_free(&tl
->sync
);
138 void i915_gem_timeline_fini(struct i915_gem_timeline
*timeline
)
142 lockdep_assert_held(&timeline
->i915
->drm
.struct_mutex
);
144 for (i
= 0; i
< ARRAY_SIZE(timeline
->engine
); i
++)
145 __intel_timeline_fini(&timeline
->engine
[i
]);
147 list_del(&timeline
->link
);
148 kfree(timeline
->name
);
151 #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
152 #include "selftests/mock_timeline.c"
153 #include "selftests/i915_gem_timeline.c"