1 /* $NetBSD: intel_timeline.h,v 1.2 2021/12/18 23:45:30 riastradh Exp $ */
2
3 /*
4 * Copyright © 2016 Intel Corporation
5 *
6 * Permission is hereby granted, free of charge, to any person obtaining a
7 * copy of this software and associated documentation files (the "Software"),
8 * to deal in the Software without restriction, including without limitation
9 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 * and/or sell copies of the Software, and to permit persons to whom the
11 * Software is furnished to do so, subject to the following conditions:
12 *
13 * The above copyright notice and this permission notice (including the next
14 * paragraph) shall be included in all copies or substantial portions of the
15 * Software.
16 *
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
22 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
23 * IN THE SOFTWARE.
24 *
25 */
26
27 #ifndef I915_TIMELINE_H
28 #define I915_TIMELINE_H
29
30 #include <linux/lockdep.h>
31
32 #include "i915_active.h"
33 #include "i915_syncmap.h"
34 #include "gt/intel_timeline_types.h"
35
36 int intel_timeline_init(struct intel_timeline *tl,
37 struct intel_gt *gt,
38 struct i915_vma *hwsp);
39 void intel_timeline_fini(struct intel_timeline *tl);
40
41 struct intel_timeline *
42 intel_timeline_create(struct intel_gt *gt, struct i915_vma *global_hwsp);
43
44 static inline struct intel_timeline *
intel_timeline_get(struct intel_timeline * timeline)45 intel_timeline_get(struct intel_timeline *timeline)
46 {
47 kref_get(&timeline->kref);
48 return timeline;
49 }
50
51 void __intel_timeline_free(struct kref *kref);
intel_timeline_put(struct intel_timeline * timeline)52 static inline void intel_timeline_put(struct intel_timeline *timeline)
53 {
54 kref_put(&timeline->kref, __intel_timeline_free);
55 }
56
__intel_timeline_sync_set(struct intel_timeline * tl,u64 context,u32 seqno)57 static inline int __intel_timeline_sync_set(struct intel_timeline *tl,
58 u64 context, u32 seqno)
59 {
60 return i915_syncmap_set(&tl->sync, context, seqno);
61 }
62
intel_timeline_sync_set(struct intel_timeline * tl,const struct dma_fence * fence)63 static inline int intel_timeline_sync_set(struct intel_timeline *tl,
64 const struct dma_fence *fence)
65 {
66 return __intel_timeline_sync_set(tl, fence->context, fence->seqno);
67 }
68
__intel_timeline_sync_is_later(struct intel_timeline * tl,u64 context,u32 seqno)69 static inline bool __intel_timeline_sync_is_later(struct intel_timeline *tl,
70 u64 context, u32 seqno)
71 {
72 return i915_syncmap_is_later(&tl->sync, context, seqno);
73 }
74
intel_timeline_sync_is_later(struct intel_timeline * tl,const struct dma_fence * fence)75 static inline bool intel_timeline_sync_is_later(struct intel_timeline *tl,
76 const struct dma_fence *fence)
77 {
78 return __intel_timeline_sync_is_later(tl, fence->context, fence->seqno);
79 }
80
81 int intel_timeline_pin(struct intel_timeline *tl);
82 void intel_timeline_enter(struct intel_timeline *tl);
83 int intel_timeline_get_seqno(struct intel_timeline *tl,
84 struct i915_request *rq,
85 u32 *seqno);
86 void intel_timeline_exit(struct intel_timeline *tl);
87 void intel_timeline_unpin(struct intel_timeline *tl);
88
89 int intel_timeline_read_hwsp(struct i915_request *from,
90 struct i915_request *until,
91 u32 *hwsp_offset);
92
93 void intel_gt_init_timelines(struct intel_gt *gt);
94 void intel_gt_fini_timelines(struct intel_gt *gt);
95
96 #endif
97