Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 1 | /* |
| 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 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 25 | #ifndef I915_TIMELINE_H |
| 26 | #define I915_TIMELINE_H |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 27 | |
| 28 | #include <linux/list.h> |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 29 | #include <linux/kref.h> |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 30 | |
Chris Wilson | 21950ee | 2019-02-05 13:00:05 +0000 | [diff] [blame^] | 31 | #include "i915_active.h" |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 32 | #include "i915_request.h" |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 33 | #include "i915_syncmap.h" |
Chris Wilson | e61e0f5 | 2018-02-21 09:56:36 +0000 | [diff] [blame] | 34 | #include "i915_utils.h" |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 35 | |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 36 | struct i915_vma; |
Chris Wilson | 8ba306a | 2019-01-28 18:18:10 +0000 | [diff] [blame] | 37 | struct i915_timeline_hwsp; |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 38 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 39 | struct i915_timeline { |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 40 | u64 fence_context; |
Chris Wilson | 9b6586a | 2017-02-23 07:44:08 +0000 | [diff] [blame] | 41 | u32 seqno; |
| 42 | |
Chris Wilson | 80b204b | 2016-10-28 13:58:58 +0100 | [diff] [blame] | 43 | spinlock_t lock; |
Chris Wilson | 890fd18 | 2018-07-06 22:07:10 +0100 | [diff] [blame] | 44 | #define TIMELINE_CLIENT 0 /* default subclass */ |
| 45 | #define TIMELINE_ENGINE 1 |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 46 | |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 47 | unsigned int pin_count; |
| 48 | const u32 *hwsp_seqno; |
| 49 | struct i915_vma *hwsp_ggtt; |
| 50 | u32 hwsp_offset; |
| 51 | |
Chris Wilson | 8547444 | 2019-01-29 18:54:50 +0000 | [diff] [blame] | 52 | bool has_initial_breadcrumb; |
| 53 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 54 | /** |
| 55 | * List of breadcrumbs associated with GPU requests currently |
| 56 | * outstanding. |
| 57 | */ |
| 58 | struct list_head requests; |
| 59 | |
| 60 | /* Contains an RCU guarded pointer to the last request. No reference is |
| 61 | * held to the request, users must carefully acquire a reference to |
Chris Wilson | 21950ee | 2019-02-05 13:00:05 +0000 | [diff] [blame^] | 62 | * the request using i915_active_request_get_request_rcu(), or hold the |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 63 | * struct_mutex. |
| 64 | */ |
Chris Wilson | 21950ee | 2019-02-05 13:00:05 +0000 | [diff] [blame^] | 65 | struct i915_active_request last_request; |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 66 | |
| 67 | /** |
| 68 | * We track the most recent seqno that we wait on in every context so |
| 69 | * that we only have to emit a new await and dependency on a more |
| 70 | * recent sync point. As the contexts may be executed out-of-order, we |
| 71 | * have to track each individually and can not rely on an absolute |
| 72 | * global_seqno. When we know that all tracked fences are completed |
| 73 | * (i.e. when the driver is idle), we know that the syncmap is |
| 74 | * redundant and we can discard it without loss of generality. |
| 75 | */ |
| 76 | struct i915_syncmap *sync; |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 77 | |
Tvrtko Ursulin | 7810858 | 2019-02-05 09:50:30 +0000 | [diff] [blame] | 78 | /** |
| 79 | * Barrier provides the ability to serialize ordering between different |
| 80 | * timelines. |
| 81 | * |
| 82 | * Users can call i915_timeline_set_barrier which will make all |
| 83 | * subsequent submissions to this timeline be executed only after the |
| 84 | * barrier has been completed. |
| 85 | */ |
Chris Wilson | 21950ee | 2019-02-05 13:00:05 +0000 | [diff] [blame^] | 86 | struct i915_active_request barrier; |
Tvrtko Ursulin | 7810858 | 2019-02-05 09:50:30 +0000 | [diff] [blame] | 87 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 88 | struct list_head link; |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 89 | const char *name; |
Chris Wilson | 1e34556 | 2019-01-28 10:23:56 +0000 | [diff] [blame] | 90 | struct drm_i915_private *i915; |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 91 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 92 | struct kref kref; |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 93 | }; |
| 94 | |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 95 | int i915_timeline_init(struct drm_i915_private *i915, |
| 96 | struct i915_timeline *tl, |
| 97 | const char *name, |
| 98 | struct i915_vma *hwsp); |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 99 | void i915_timeline_fini(struct i915_timeline *tl); |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 100 | |
Chris Wilson | f911e72 | 2018-11-15 20:38:51 +0000 | [diff] [blame] | 101 | static inline void |
| 102 | i915_timeline_set_subclass(struct i915_timeline *timeline, |
| 103 | unsigned int subclass) |
| 104 | { |
| 105 | lockdep_set_subclass(&timeline->lock, subclass); |
| 106 | |
| 107 | /* |
| 108 | * Due to an interesting quirk in lockdep's internal debug tracking, |
| 109 | * after setting a subclass we must ensure the lock is used. Otherwise, |
| 110 | * nr_unused_locks is incremented once too often. |
| 111 | */ |
| 112 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 113 | local_irq_disable(); |
| 114 | lock_map_acquire(&timeline->lock.dep_map); |
| 115 | lock_map_release(&timeline->lock.dep_map); |
| 116 | local_irq_enable(); |
| 117 | #endif |
| 118 | } |
| 119 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 120 | struct i915_timeline * |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 121 | i915_timeline_create(struct drm_i915_private *i915, |
| 122 | const char *name, |
| 123 | struct i915_vma *global_hwsp); |
Chris Wilson | 65fcb80 | 2018-05-02 17:38:38 +0100 | [diff] [blame] | 124 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 125 | static inline struct i915_timeline * |
| 126 | i915_timeline_get(struct i915_timeline *timeline) |
| 127 | { |
| 128 | kref_get(&timeline->kref); |
| 129 | return timeline; |
| 130 | } |
| 131 | |
| 132 | void __i915_timeline_free(struct kref *kref); |
| 133 | static inline void i915_timeline_put(struct i915_timeline *timeline) |
| 134 | { |
| 135 | kref_put(&timeline->kref, __i915_timeline_free); |
| 136 | } |
| 137 | |
| 138 | static inline int __i915_timeline_sync_set(struct i915_timeline *tl, |
| 139 | u64 context, u32 seqno) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 140 | { |
| 141 | return i915_syncmap_set(&tl->sync, context, seqno); |
| 142 | } |
| 143 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 144 | static inline int i915_timeline_sync_set(struct i915_timeline *tl, |
| 145 | const struct dma_fence *fence) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 146 | { |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 147 | return __i915_timeline_sync_set(tl, fence->context, fence->seqno); |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 148 | } |
| 149 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 150 | static inline bool __i915_timeline_sync_is_later(struct i915_timeline *tl, |
| 151 | u64 context, u32 seqno) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 152 | { |
| 153 | return i915_syncmap_is_later(&tl->sync, context, seqno); |
| 154 | } |
| 155 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 156 | static inline bool i915_timeline_sync_is_later(struct i915_timeline *tl, |
| 157 | const struct dma_fence *fence) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 158 | { |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 159 | return __i915_timeline_sync_is_later(tl, fence->context, fence->seqno); |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 160 | } |
| 161 | |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 162 | int i915_timeline_pin(struct i915_timeline *tl); |
| 163 | void i915_timeline_unpin(struct i915_timeline *tl); |
| 164 | |
Chris Wilson | 1e34556 | 2019-01-28 10:23:56 +0000 | [diff] [blame] | 165 | void i915_timelines_init(struct drm_i915_private *i915); |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 166 | void i915_timelines_park(struct drm_i915_private *i915); |
Chris Wilson | 1e34556 | 2019-01-28 10:23:56 +0000 | [diff] [blame] | 167 | void i915_timelines_fini(struct drm_i915_private *i915); |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 168 | |
Tvrtko Ursulin | 7810858 | 2019-02-05 09:50:30 +0000 | [diff] [blame] | 169 | /** |
| 170 | * i915_timeline_set_barrier - orders submission between different timelines |
| 171 | * @timeline: timeline to set the barrier on |
| 172 | * @rq: request after which new submissions can proceed |
| 173 | * |
| 174 | * Sets the passed in request as the serialization point for all subsequent |
| 175 | * submissions on @timeline. Subsequent requests will not be submitted to GPU |
| 176 | * until the barrier has been completed. |
| 177 | */ |
Chris Wilson | 21950ee | 2019-02-05 13:00:05 +0000 | [diff] [blame^] | 178 | static inline int |
| 179 | i915_timeline_set_barrier(struct i915_timeline *tl, struct i915_request *rq) |
| 180 | { |
| 181 | return i915_active_request_set(&tl->barrier, rq); |
| 182 | } |
Tvrtko Ursulin | 7810858 | 2019-02-05 09:50:30 +0000 | [diff] [blame] | 183 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 184 | #endif |