drm/i915/panel: Track temporary rpm wakeref
[linux-2.6-microblaze.git] / drivers / gpu / drm / i915 / i915_timeline.h
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
25 #ifndef I915_TIMELINE_H
26 #define I915_TIMELINE_H
27
28 #include <linux/list.h>
29 #include <linux/kref.h>
30
31 #include "i915_request.h"
32 #include "i915_syncmap.h"
33 #include "i915_utils.h"
34
35 struct i915_timeline {
36         u64 fence_context;
37         u32 seqno;
38
39         spinlock_t lock;
40 #define TIMELINE_CLIENT 0 /* default subclass */
41 #define TIMELINE_ENGINE 1
42
43         /**
44          * List of breadcrumbs associated with GPU requests currently
45          * outstanding.
46          */
47         struct list_head requests;
48
49         /* Contains an RCU guarded pointer to the last request. No reference is
50          * held to the request, users must carefully acquire a reference to
51          * the request using i915_gem_active_get_request_rcu(), or hold the
52          * struct_mutex.
53          */
54         struct i915_gem_active last_request;
55
56         /**
57          * We track the most recent seqno that we wait on in every context so
58          * that we only have to emit a new await and dependency on a more
59          * recent sync point. As the contexts may be executed out-of-order, we
60          * have to track each individually and can not rely on an absolute
61          * global_seqno. When we know that all tracked fences are completed
62          * (i.e. when the driver is idle), we know that the syncmap is
63          * redundant and we can discard it without loss of generality.
64          */
65         struct i915_syncmap *sync;
66
67         struct list_head link;
68         const char *name;
69
70         struct kref kref;
71 };
72
73 void i915_timeline_init(struct drm_i915_private *i915,
74                         struct i915_timeline *tl,
75                         const char *name);
76 void i915_timeline_fini(struct i915_timeline *tl);
77
78 static inline void
79 i915_timeline_set_subclass(struct i915_timeline *timeline,
80                            unsigned int subclass)
81 {
82         lockdep_set_subclass(&timeline->lock, subclass);
83
84         /*
85          * Due to an interesting quirk in lockdep's internal debug tracking,
86          * after setting a subclass we must ensure the lock is used. Otherwise,
87          * nr_unused_locks is incremented once too often.
88          */
89 #ifdef CONFIG_DEBUG_LOCK_ALLOC
90         local_irq_disable();
91         lock_map_acquire(&timeline->lock.dep_map);
92         lock_map_release(&timeline->lock.dep_map);
93         local_irq_enable();
94 #endif
95 }
96
97 struct i915_timeline *
98 i915_timeline_create(struct drm_i915_private *i915, const char *name);
99
100 static inline struct i915_timeline *
101 i915_timeline_get(struct i915_timeline *timeline)
102 {
103         kref_get(&timeline->kref);
104         return timeline;
105 }
106
107 void __i915_timeline_free(struct kref *kref);
108 static inline void i915_timeline_put(struct i915_timeline *timeline)
109 {
110         kref_put(&timeline->kref, __i915_timeline_free);
111 }
112
113 static inline int __i915_timeline_sync_set(struct i915_timeline *tl,
114                                            u64 context, u32 seqno)
115 {
116         return i915_syncmap_set(&tl->sync, context, seqno);
117 }
118
119 static inline int i915_timeline_sync_set(struct i915_timeline *tl,
120                                          const struct dma_fence *fence)
121 {
122         return __i915_timeline_sync_set(tl, fence->context, fence->seqno);
123 }
124
125 static inline bool __i915_timeline_sync_is_later(struct i915_timeline *tl,
126                                                  u64 context, u32 seqno)
127 {
128         return i915_syncmap_is_later(&tl->sync, context, seqno);
129 }
130
131 static inline bool i915_timeline_sync_is_later(struct i915_timeline *tl,
132                                                const struct dma_fence *fence)
133 {
134         return __i915_timeline_sync_is_later(tl, fence->context, fence->seqno);
135 }
136
137 void i915_timelines_park(struct drm_i915_private *i915);
138
139 #endif