hc
2024-05-10 10ebd8556b7990499c896a550e3d416b444211e6
kernel/include/drm/drm_vblank.h
....@@ -27,13 +27,14 @@
2727 #include <linux/seqlock.h>
2828 #include <linux/idr.h>
2929 #include <linux/poll.h>
30
+#include <linux/kthread.h>
3031
3132 #include <drm/drm_file.h>
3233 #include <drm/drm_modes.h>
33
-#include <uapi/drm/drm.h>
3434
3535 struct drm_device;
3636 struct drm_crtc;
37
+struct drm_vblank_work;
3738
3839 /**
3940 * struct drm_pending_vblank_event - pending vblank event tracking
....@@ -95,7 +96,7 @@
9596 /**
9697 * @queue: Wait queue for vblank waiters.
9798 */
98
- wait_queue_head_t queue; /**< VBLANK wait queue */
99
+ wait_queue_head_t queue;
99100 /**
100101 * @disable_timer: Disable timer for the delayed vblank disabling
101102 * hysteresis logic. Vblank disabling is controlled through the
....@@ -107,12 +108,23 @@
107108 /**
108109 * @seqlock: Protect vblank count and time.
109110 */
110
- seqlock_t seqlock; /* protects vblank count and time */
111
+ seqlock_t seqlock;
111112
112113 /**
113
- * @count: Current software vblank counter.
114
+ * @count:
115
+ *
116
+ * Current software vblank counter.
117
+ *
118
+ * Note that for a given vblank counter value drm_crtc_handle_vblank()
119
+ * and drm_crtc_vblank_count() or drm_crtc_vblank_count_and_time()
120
+ * provide a barrier: Any writes done before calling
121
+ * drm_crtc_handle_vblank() will be visible to callers of the later
122
+ * functions, iff the vblank count is the same or a later one.
123
+ *
124
+ * IMPORTANT: This guarantee requires barriers, therefor never access
125
+ * this field directly. Use drm_crtc_vblank_count() instead.
114126 */
115
- u64 count;
127
+ atomic64_t count;
116128 /**
117129 * @time: Vblank timestamp corresponding to @count.
118130 */
....@@ -123,7 +135,7 @@
123135 * this refcount reaches 0 can the hardware interrupt be disabled using
124136 * @disable_timer.
125137 */
126
- atomic_t refcount; /* number of users of vblank interruptsper crtc */
138
+ atomic_t refcount;
127139 /**
128140 * @last: Protected by &drm_device.vbl_lock, used for wraparound handling.
129141 */
....@@ -156,7 +168,7 @@
156168 * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly
157169 * save and restore the vblank count.
158170 */
159
- unsigned int inmodeset; /* Display driver is setting mode */
171
+ unsigned int inmodeset;
160172 /**
161173 * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this
162174 * structure.
....@@ -164,13 +176,13 @@
164176 unsigned int pipe;
165177 /**
166178 * @framedur_ns: Frame/Field duration in ns, used by
167
- * drm_calc_vbltimestamp_from_scanoutpos() and computed by
179
+ * drm_crtc_vblank_helper_get_vblank_timestamp() and computed by
168180 * drm_calc_timestamping_constants().
169181 */
170182 int framedur_ns;
171183 /**
172184 * @linedur_ns: Line duration in ns, used by
173
- * drm_calc_vbltimestamp_from_scanoutpos() and computed by
185
+ * drm_crtc_vblank_helper_get_vblank_timestamp() and computed by
174186 * drm_calc_timestamping_constants().
175187 */
176188 int linedur_ns;
....@@ -180,8 +192,8 @@
180192 *
181193 * Cache of the current hardware display mode. Only valid when @enabled
182194 * is set. This is used by helpers like
183
- * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the
184
- * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode,
195
+ * drm_crtc_vblank_helper_get_vblank_timestamp(). We can't just access
196
+ * the hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode,
185197 * because that one is really hard to get from interrupt context.
186198 */
187199 struct drm_display_mode hwmode;
....@@ -193,9 +205,28 @@
193205 * disabling functions multiple times.
194206 */
195207 bool enabled;
208
+
209
+ /**
210
+ * @worker: The &kthread_worker used for executing vblank works.
211
+ */
212
+ struct kthread_worker *worker;
213
+
214
+ /**
215
+ * @pending_work: A list of scheduled &drm_vblank_work items that are
216
+ * waiting for a future vblank.
217
+ */
218
+ struct list_head pending_work;
219
+
220
+ /**
221
+ * @work_wait_queue: The wait queue used for signaling that a
222
+ * &drm_vblank_work item has either finished executing, or was
223
+ * cancelled.
224
+ */
225
+ wait_queue_head_t work_wait_queue;
196226 };
197227
198228 int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
229
+bool drm_dev_has_vblank(const struct drm_device *dev);
199230 u64 drm_crtc_vblank_count(struct drm_crtc *crtc);
200231 u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
201232 ktime_t *vblanktime);
....@@ -219,13 +250,32 @@
219250 void drm_vblank_restore(struct drm_device *dev, unsigned int pipe);
220251 void drm_crtc_vblank_restore(struct drm_crtc *crtc);
221252
222
-bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
223
- unsigned int pipe, int *max_error,
224
- ktime_t *vblank_time,
225
- bool in_vblank_irq);
226253 void drm_calc_timestamping_constants(struct drm_crtc *crtc,
227254 const struct drm_display_mode *mode);
228255 wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
229256 void drm_crtc_set_max_vblank_count(struct drm_crtc *crtc,
230257 u32 max_vblank_count);
258
+
259
+/*
260
+ * Helpers for struct drm_crtc_funcs
261
+ */
262
+
263
+typedef bool (*drm_vblank_get_scanout_position_func)(struct drm_crtc *crtc,
264
+ bool in_vblank_irq,
265
+ int *vpos, int *hpos,
266
+ ktime_t *stime,
267
+ ktime_t *etime,
268
+ const struct drm_display_mode *mode);
269
+
270
+bool
271
+drm_crtc_vblank_helper_get_vblank_timestamp_internal(struct drm_crtc *crtc,
272
+ int *max_error,
273
+ ktime_t *vblank_time,
274
+ bool in_vblank_irq,
275
+ drm_vblank_get_scanout_position_func get_scanout_position);
276
+bool drm_crtc_vblank_helper_get_vblank_timestamp(struct drm_crtc *crtc,
277
+ int *max_error,
278
+ ktime_t *vblank_time,
279
+ bool in_vblank_irq);
280
+
231281 #endif