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 | |
Chris Wilson | 39e2f50 | 2019-03-08 13:25:17 +0000 | [diff] [blame] | 28 | #include <linux/lockdep.h> |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 29 | |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 30 | #include "i915_syncmap.h" |
Chris Wilson | 39e2f50 | 2019-03-08 13:25:17 +0000 | [diff] [blame] | 31 | #include "i915_timeline_types.h" |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 32 | |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 33 | int i915_timeline_init(struct drm_i915_private *i915, |
| 34 | struct i915_timeline *tl, |
| 35 | const char *name, |
| 36 | struct i915_vma *hwsp); |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 37 | void i915_timeline_fini(struct i915_timeline *tl); |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 38 | |
Chris Wilson | f911e72 | 2018-11-15 20:38:51 +0000 | [diff] [blame] | 39 | static inline void |
| 40 | i915_timeline_set_subclass(struct i915_timeline *timeline, |
| 41 | unsigned int subclass) |
| 42 | { |
| 43 | lockdep_set_subclass(&timeline->lock, subclass); |
| 44 | |
| 45 | /* |
| 46 | * Due to an interesting quirk in lockdep's internal debug tracking, |
| 47 | * after setting a subclass we must ensure the lock is used. Otherwise, |
| 48 | * nr_unused_locks is incremented once too often. |
| 49 | */ |
| 50 | #ifdef CONFIG_DEBUG_LOCK_ALLOC |
| 51 | local_irq_disable(); |
| 52 | lock_map_acquire(&timeline->lock.dep_map); |
| 53 | lock_map_release(&timeline->lock.dep_map); |
| 54 | local_irq_enable(); |
| 55 | #endif |
| 56 | } |
| 57 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 58 | struct i915_timeline * |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 59 | i915_timeline_create(struct drm_i915_private *i915, |
| 60 | const char *name, |
| 61 | struct i915_vma *global_hwsp); |
Chris Wilson | 65fcb80 | 2018-05-02 17:38:38 +0100 | [diff] [blame] | 62 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 63 | static inline struct i915_timeline * |
| 64 | i915_timeline_get(struct i915_timeline *timeline) |
| 65 | { |
| 66 | kref_get(&timeline->kref); |
| 67 | return timeline; |
| 68 | } |
| 69 | |
| 70 | void __i915_timeline_free(struct kref *kref); |
| 71 | static inline void i915_timeline_put(struct i915_timeline *timeline) |
| 72 | { |
| 73 | kref_put(&timeline->kref, __i915_timeline_free); |
| 74 | } |
| 75 | |
| 76 | static inline int __i915_timeline_sync_set(struct i915_timeline *tl, |
| 77 | u64 context, u32 seqno) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 78 | { |
| 79 | return i915_syncmap_set(&tl->sync, context, seqno); |
| 80 | } |
| 81 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 82 | static inline int i915_timeline_sync_set(struct i915_timeline *tl, |
| 83 | const struct dma_fence *fence) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 84 | { |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 85 | return __i915_timeline_sync_set(tl, fence->context, fence->seqno); |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 86 | } |
| 87 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 88 | static inline bool __i915_timeline_sync_is_later(struct i915_timeline *tl, |
| 89 | u64 context, u32 seqno) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 90 | { |
| 91 | return i915_syncmap_is_later(&tl->sync, context, seqno); |
| 92 | } |
| 93 | |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 94 | static inline bool i915_timeline_sync_is_later(struct i915_timeline *tl, |
| 95 | const struct dma_fence *fence) |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 96 | { |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 97 | return __i915_timeline_sync_is_later(tl, fence->context, fence->seqno); |
Chris Wilson | 4797948 | 2017-05-03 10:39:21 +0100 | [diff] [blame] | 98 | } |
| 99 | |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 100 | int i915_timeline_pin(struct i915_timeline *tl); |
Chris Wilson | ebece75 | 2019-03-01 17:08:59 +0000 | [diff] [blame] | 101 | int i915_timeline_get_seqno(struct i915_timeline *tl, |
| 102 | struct i915_request *rq, |
| 103 | u32 *seqno); |
Chris Wilson | 52954ed | 2019-01-28 18:18:09 +0000 | [diff] [blame] | 104 | void i915_timeline_unpin(struct i915_timeline *tl); |
| 105 | |
Chris Wilson | ebece75 | 2019-03-01 17:08:59 +0000 | [diff] [blame] | 106 | int i915_timeline_read_hwsp(struct i915_request *from, |
| 107 | struct i915_request *until, |
| 108 | u32 *hwsp_offset); |
| 109 | |
Chris Wilson | 1e34556 | 2019-01-28 10:23:56 +0000 | [diff] [blame] | 110 | void i915_timelines_init(struct drm_i915_private *i915); |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 111 | void i915_timelines_park(struct drm_i915_private *i915); |
Chris Wilson | 1e34556 | 2019-01-28 10:23:56 +0000 | [diff] [blame] | 112 | void i915_timelines_fini(struct drm_i915_private *i915); |
Chris Wilson | a89d1f9 | 2018-05-02 17:38:39 +0100 | [diff] [blame] | 113 | |
Tvrtko Ursulin | 7810858 | 2019-02-05 09:50:30 +0000 | [diff] [blame] | 114 | /** |
| 115 | * i915_timeline_set_barrier - orders submission between different timelines |
| 116 | * @timeline: timeline to set the barrier on |
| 117 | * @rq: request after which new submissions can proceed |
| 118 | * |
| 119 | * Sets the passed in request as the serialization point for all subsequent |
| 120 | * submissions on @timeline. Subsequent requests will not be submitted to GPU |
| 121 | * until the barrier has been completed. |
| 122 | */ |
Chris Wilson | 21950ee | 2019-02-05 13:00:05 +0000 | [diff] [blame] | 123 | static inline int |
| 124 | i915_timeline_set_barrier(struct i915_timeline *tl, struct i915_request *rq) |
| 125 | { |
| 126 | return i915_active_request_set(&tl->barrier, rq); |
| 127 | } |
Tvrtko Ursulin | 7810858 | 2019-02-05 09:50:30 +0000 | [diff] [blame] | 128 | |
Chris Wilson | 73cb970 | 2016-10-28 13:58:46 +0100 | [diff] [blame] | 129 | #endif |