blob: fc8f13a79f8f997494e43ec41180797d26055b85 [file] [log] [blame]
Chris Wilson73cb9702016-10-28 13:58:46 +01001/*
2 * Copyright © 2016 Intel Corporation
3 *
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:
10 *
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
13 * Software.
14 *
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
21 * IN THE SOFTWARE.
22 *
23 */
24
25#include "i915_drv.h"
26
27int i915_gem_timeline_init(struct drm_i915_private *i915,
28 struct i915_gem_timeline *timeline,
29 const char *name)
30{
31 unsigned int i;
32 u64 fences;
33
34 lockdep_assert_held(&i915->drm.struct_mutex);
35
36 timeline->i915 = i915;
37 timeline->name = kstrdup(name ?: "[kernel]", GFP_KERNEL);
38 if (!timeline->name)
39 return -ENOMEM;
40
41 list_add(&timeline->link, &i915->gt.timelines);
42
43 /* Called during early_init before we know how many engines there are */
44 fences = dma_fence_context_alloc(ARRAY_SIZE(timeline->engine));
45 for (i = 0; i < ARRAY_SIZE(timeline->engine); i++) {
46 struct intel_timeline *tl = &timeline->engine[i];
47
48 tl->fence_context = fences++;
49 tl->common = timeline;
50
Chris Wilson80b204b2016-10-28 13:58:58 +010051 spin_lock_init(&tl->lock);
Chris Wilson73cb9702016-10-28 13:58:46 +010052 init_request_active(&tl->last_request, NULL);
53 INIT_LIST_HEAD(&tl->requests);
54 }
55
56 return 0;
57}
58
59void i915_gem_timeline_fini(struct i915_gem_timeline *tl)
60{
61 lockdep_assert_held(&tl->i915->drm.struct_mutex);
62
63 list_del(&tl->link);
64 kfree(tl->name);
65}