Linux Audio

Check our new training course

Loading...
v6.13.7
  1/*
  2 * Copyright 2016 Intel Corp.
  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 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 21 * OTHER DEALINGS IN THE SOFTWARE.
 22 */
 23
 24#ifndef _DRM_VBLANK_H_
 25#define _DRM_VBLANK_H_
 26
 27#include <linux/seqlock.h>
 28#include <linux/idr.h>
 29#include <linux/poll.h>
 30#include <linux/kthread.h>
 31
 32#include <drm/drm_file.h>
 33#include <drm/drm_modes.h>
 
 34
 35struct drm_device;
 36struct drm_crtc;
 37struct drm_vblank_work;
 38
 39/**
 40 * struct drm_pending_vblank_event - pending vblank event tracking
 41 */
 42struct drm_pending_vblank_event {
 43	/**
 44	 * @base: Base structure for tracking pending DRM events.
 45	 */
 46	struct drm_pending_event base;
 47	/**
 48	 * @pipe: drm_crtc_index() of the &drm_crtc this event is for.
 49	 */
 50	unsigned int pipe;
 51	/**
 52	 * @sequence: frame event should be triggered at
 53	 */
 54	u64 sequence;
 55	/**
 56	 * @event: Actual event which will be sent to userspace.
 57	 */
 58	union {
 59		/**
 60		 * @event.base: DRM event base class.
 61		 */
 62		struct drm_event base;
 63
 64		/**
 65		 * @event.vbl:
 66		 *
 67		 * Event payload for vblank events, requested through
 68		 * either the MODE_PAGE_FLIP or MODE_ATOMIC IOCTL. Also
 69		 * generated by the legacy WAIT_VBLANK IOCTL, but new userspace
 70		 * should use MODE_QUEUE_SEQUENCE and &event.seq instead.
 71		 */
 72		struct drm_event_vblank vbl;
 73
 74		/**
 75		 * @event.seq: Event payload for the MODE_QUEUEU_SEQUENCE IOCTL.
 76		 */
 77		struct drm_event_crtc_sequence seq;
 78	} event;
 79};
 80
 81/**
 82 * struct drm_vblank_crtc_config - vblank configuration for a CRTC
 83 */
 84struct drm_vblank_crtc_config {
 85	/**
 86	 * @offdelay_ms: Vblank off delay in ms, used to determine how long
 87	 * &drm_vblank_crtc.disable_timer waits before disabling.
 88	 *
 89	 * Defaults to the value of drm_vblank_offdelay in drm_crtc_vblank_on().
 90	 */
 91	int offdelay_ms;
 92
 93	/**
 94	 * @disable_immediate: See &drm_device.vblank_disable_immediate
 95	 * for the exact semantics of immediate vblank disabling.
 96	 *
 97	 * Additionally, this tracks the disable immediate value per crtc, just
 98	 * in case it needs to differ from the default value for a given device.
 99	 *
100	 * Defaults to the value of &drm_device.vblank_disable_immediate in
101	 * drm_crtc_vblank_on().
102	 */
103	bool disable_immediate;
104};
105
106/**
107 * struct drm_vblank_crtc - vblank tracking for a CRTC
108 *
109 * This structure tracks the vblank state for one CRTC.
110 *
111 * Note that for historical reasons - the vblank handling code is still shared
112 * with legacy/non-kms drivers - this is a free-standing structure not directly
113 * connected to &struct drm_crtc. But all public interface functions are taking
114 * a &struct drm_crtc to hide this implementation detail.
115 */
116struct drm_vblank_crtc {
117	/**
118	 * @dev: Pointer to the &drm_device.
119	 */
120	struct drm_device *dev;
121	/**
122	 * @queue: Wait queue for vblank waiters.
123	 */
124	wait_queue_head_t queue;
125	/**
126	 * @disable_timer: Disable timer for the delayed vblank disabling
127	 * hysteresis logic. Vblank disabling is controlled through
128	 * &drm_vblank_crtc_config.offdelay_ms and the setting of the
129	 * &drm_device.max_vblank_count value.
130	 */
131	struct timer_list disable_timer;
132
133	/**
134	 * @seqlock: Protect vblank count and time.
135	 */
136	seqlock_t seqlock;
137
138	/**
139	 * @count:
140	 *
141	 * Current software vblank counter.
142	 *
143	 * Note that for a given vblank counter value drm_crtc_handle_vblank()
144	 * and drm_crtc_vblank_count() or drm_crtc_vblank_count_and_time()
145	 * provide a barrier: Any writes done before calling
146	 * drm_crtc_handle_vblank() will be visible to callers of the later
147	 * functions, iff the vblank count is the same or a later one.
148	 *
149	 * IMPORTANT: This guarantee requires barriers, therefor never access
150	 * this field directly. Use drm_crtc_vblank_count() instead.
151	 */
152	atomic64_t count;
153	/**
154	 * @time: Vblank timestamp corresponding to @count.
155	 */
156	ktime_t time;
157
158	/**
159	 * @refcount: Number of users/waiters of the vblank interrupt. Only when
160	 * this refcount reaches 0 can the hardware interrupt be disabled using
161	 * @disable_timer.
162	 */
163	atomic_t refcount;
164	/**
165	 * @last: Protected by &drm_device.vbl_lock, used for wraparound handling.
166	 */
167	u32 last;
168	/**
169	 * @max_vblank_count:
170	 *
171	 * Maximum value of the vblank registers for this crtc. This value +1
172	 * will result in a wrap-around of the vblank register. It is used
173	 * by the vblank core to handle wrap-arounds.
174	 *
175	 * If set to zero the vblank core will try to guess the elapsed vblanks
176	 * between times when the vblank interrupt is disabled through
177	 * high-precision timestamps. That approach is suffering from small
178	 * races and imprecision over longer time periods, hence exposing a
179	 * hardware vblank counter is always recommended.
180	 *
181	 * This is the runtime configurable per-crtc maximum set through
182	 * drm_crtc_set_max_vblank_count(). If this is used the driver
183	 * must leave the device wide &drm_device.max_vblank_count at zero.
184	 *
185	 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set.
186	 */
187	u32 max_vblank_count;
188	/**
189	 * @inmodeset: Tracks whether the vblank is disabled due to a modeset.
190	 * For legacy driver bit 2 additionally tracks whether an additional
191	 * temporary vblank reference has been acquired to paper over the
192	 * hardware counter resetting/jumping. KMS drivers should instead just
193	 * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly
194	 * save and restore the vblank count.
195	 */
196	unsigned int inmodeset;
197	/**
198	 * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this
199	 * structure.
200	 */
201	unsigned int pipe;
202	/**
203	 * @framedur_ns: Frame/Field duration in ns, used by
204	 * drm_crtc_vblank_helper_get_vblank_timestamp() and computed by
205	 * drm_calc_timestamping_constants().
206	 */
207	int framedur_ns;
208	/**
209	 * @linedur_ns: Line duration in ns, used by
210	 * drm_crtc_vblank_helper_get_vblank_timestamp() and computed by
211	 * drm_calc_timestamping_constants().
212	 */
213	int linedur_ns;
214
215	/**
216	 * @hwmode:
217	 *
218	 * Cache of the current hardware display mode. Only valid when @enabled
219	 * is set. This is used by helpers like
220	 * drm_crtc_vblank_helper_get_vblank_timestamp(). We can't just access
221	 * the hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode,
222	 * because that one is really hard to get from interrupt context.
223	 */
224	struct drm_display_mode hwmode;
225
226	/**
227	 * @config: Stores vblank configuration values for a given CRTC.
228	 * Also, see drm_crtc_vblank_on_config().
229	 */
230	struct drm_vblank_crtc_config config;
231
232	/**
233	 * @enabled: Tracks the enabling state of the corresponding &drm_crtc to
234	 * avoid double-disabling and hence corrupting saved state. Needed by
235	 * drivers not using atomic KMS, since those might go through their CRTC
236	 * disabling functions multiple times.
237	 */
238	bool enabled;
239
240	/**
241	 * @worker: The &kthread_worker used for executing vblank works.
242	 */
243	struct kthread_worker *worker;
244
245	/**
246	 * @pending_work: A list of scheduled &drm_vblank_work items that are
247	 * waiting for a future vblank.
248	 */
249	struct list_head pending_work;
250
251	/**
252	 * @work_wait_queue: The wait queue used for signaling that a
253	 * &drm_vblank_work item has either finished executing, or was
254	 * cancelled.
255	 */
256	wait_queue_head_t work_wait_queue;
257};
258
259struct drm_vblank_crtc *drm_crtc_vblank_crtc(struct drm_crtc *crtc);
260int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
261bool drm_dev_has_vblank(const struct drm_device *dev);
262u64 drm_crtc_vblank_count(struct drm_crtc *crtc);
263u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
264				   ktime_t *vblanktime);
265int drm_crtc_next_vblank_start(struct drm_crtc *crtc, ktime_t *vblanktime);
266void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
267			       struct drm_pending_vblank_event *e);
268void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
269			      struct drm_pending_vblank_event *e);
270void drm_vblank_set_event(struct drm_pending_vblank_event *e,
271			  u64 *seq,
272			  ktime_t *now);
273bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
274bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
275int drm_crtc_vblank_get(struct drm_crtc *crtc);
276void drm_crtc_vblank_put(struct drm_crtc *crtc);
277void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
278void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
279void drm_crtc_vblank_off(struct drm_crtc *crtc);
280void drm_crtc_vblank_reset(struct drm_crtc *crtc);
281void drm_crtc_vblank_on_config(struct drm_crtc *crtc,
282			       const struct drm_vblank_crtc_config *config);
283void drm_crtc_vblank_on(struct drm_crtc *crtc);
284u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
 
285void drm_crtc_vblank_restore(struct drm_crtc *crtc);
286
 
 
 
 
287void drm_calc_timestamping_constants(struct drm_crtc *crtc,
288				     const struct drm_display_mode *mode);
289wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
290void drm_crtc_set_max_vblank_count(struct drm_crtc *crtc,
291				   u32 max_vblank_count);
292
293/*
294 * Helpers for struct drm_crtc_funcs
295 */
296
297typedef bool (*drm_vblank_get_scanout_position_func)(struct drm_crtc *crtc,
298						     bool in_vblank_irq,
299						     int *vpos, int *hpos,
300						     ktime_t *stime,
301						     ktime_t *etime,
302						     const struct drm_display_mode *mode);
303
304bool
305drm_crtc_vblank_helper_get_vblank_timestamp_internal(struct drm_crtc *crtc,
306						     int *max_error,
307						     ktime_t *vblank_time,
308						     bool in_vblank_irq,
309						     drm_vblank_get_scanout_position_func get_scanout_position);
310bool drm_crtc_vblank_helper_get_vblank_timestamp(struct drm_crtc *crtc,
311						 int *max_error,
312						 ktime_t *vblank_time,
313						 bool in_vblank_irq);
314
315#endif
v4.17
  1/*
  2 * Copyright 2016 Intel Corp.
  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 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
 19 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 20 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 21 * OTHER DEALINGS IN THE SOFTWARE.
 22 */
 23
 24#ifndef _DRM_VBLANK_H_
 25#define _DRM_VBLANK_H_
 26
 27#include <linux/seqlock.h>
 28#include <linux/idr.h>
 29#include <linux/poll.h>
 
 30
 31#include <drm/drm_file.h>
 32#include <drm/drm_modes.h>
 33#include <uapi/drm/drm.h>
 34
 35struct drm_device;
 36struct drm_crtc;
 
 37
 38/**
 39 * struct drm_pending_vblank_event - pending vblank event tracking
 40 */
 41struct drm_pending_vblank_event {
 42	/**
 43	 * @base: Base structure for tracking pending DRM events.
 44	 */
 45	struct drm_pending_event base;
 46	/**
 47	 * @pipe: drm_crtc_index() of the &drm_crtc this event is for.
 48	 */
 49	unsigned int pipe;
 50	/**
 51	 * @sequence: frame event should be triggered at
 52	 */
 53	u64 sequence;
 54	/**
 55	 * @event: Actual event which will be sent to userspace.
 56	 */
 57	union {
 58		/**
 59		 * @event.base: DRM event base class.
 60		 */
 61		struct drm_event base;
 62
 63		/**
 64		 * @event.vbl:
 65		 *
 66		 * Event payload for vblank events, requested through
 67		 * either the MODE_PAGE_FLIP or MODE_ATOMIC IOCTL. Also
 68		 * generated by the legacy WAIT_VBLANK IOCTL, but new userspace
 69		 * should use MODE_QUEUE_SEQUENCE and &event.seq instead.
 70		 */
 71		struct drm_event_vblank vbl;
 72
 73		/**
 74		 * @event.seq: Event payload for the MODE_QUEUEU_SEQUENCE IOCTL.
 75		 */
 76		struct drm_event_crtc_sequence seq;
 77	} event;
 78};
 79
 80/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 81 * struct drm_vblank_crtc - vblank tracking for a CRTC
 82 *
 83 * This structure tracks the vblank state for one CRTC.
 84 *
 85 * Note that for historical reasons - the vblank handling code is still shared
 86 * with legacy/non-kms drivers - this is a free-standing structure not directly
 87 * connected to &struct drm_crtc. But all public interface functions are taking
 88 * a &struct drm_crtc to hide this implementation detail.
 89 */
 90struct drm_vblank_crtc {
 91	/**
 92	 * @dev: Pointer to the &drm_device.
 93	 */
 94	struct drm_device *dev;
 95	/**
 96	 * @queue: Wait queue for vblank waiters.
 97	 */
 98	wait_queue_head_t queue;	/**< VBLANK wait queue */
 99	/**
100	 * @disable_timer: Disable timer for the delayed vblank disabling
101	 * hysteresis logic. Vblank disabling is controlled through the
102	 * drm_vblank_offdelay module option and the setting of the
103	 * &drm_device.max_vblank_count value.
104	 */
105	struct timer_list disable_timer;
106
107	/**
108	 * @seqlock: Protect vblank count and time.
109	 */
110	seqlock_t seqlock;		/* protects vblank count and time */
111
112	/**
113	 * @count: Current software vblank counter.
 
 
 
 
 
 
 
 
 
 
 
114	 */
115	u64 count;
116	/**
117	 * @time: Vblank timestamp corresponding to @count.
118	 */
119	ktime_t time;
120
121	/**
122	 * @refcount: Number of users/waiters of the vblank interrupt. Only when
123	 * this refcount reaches 0 can the hardware interrupt be disabled using
124	 * @disable_timer.
125	 */
126	atomic_t refcount;		/* number of users of vblank interruptsper crtc */
127	/**
128	 * @last: Protected by &drm_device.vbl_lock, used for wraparound handling.
129	 */
130	u32 last;
131	/**
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132	 * @inmodeset: Tracks whether the vblank is disabled due to a modeset.
133	 * For legacy driver bit 2 additionally tracks whether an additional
134	 * temporary vblank reference has been acquired to paper over the
135	 * hardware counter resetting/jumping. KMS drivers should instead just
136	 * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly
137	 * save and restore the vblank count.
138	 */
139	unsigned int inmodeset;		/* Display driver is setting mode */
140	/**
141	 * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this
142	 * structure.
143	 */
144	unsigned int pipe;
145	/**
146	 * @framedur_ns: Frame/Field duration in ns, used by
147	 * drm_calc_vbltimestamp_from_scanoutpos() and computed by
148	 * drm_calc_timestamping_constants().
149	 */
150	int framedur_ns;
151	/**
152	 * @linedur_ns: Line duration in ns, used by
153	 * drm_calc_vbltimestamp_from_scanoutpos() and computed by
154	 * drm_calc_timestamping_constants().
155	 */
156	int linedur_ns;
157
158	/**
159	 * @hwmode:
160	 *
161	 * Cache of the current hardware display mode. Only valid when @enabled
162	 * is set. This is used by helpers like
163	 * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the
164	 * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode,
165	 * because that one is really hard to get from interrupt context.
166	 */
167	struct drm_display_mode hwmode;
168
169	/**
 
 
 
 
 
 
170	 * @enabled: Tracks the enabling state of the corresponding &drm_crtc to
171	 * avoid double-disabling and hence corrupting saved state. Needed by
172	 * drivers not using atomic KMS, since those might go through their CRTC
173	 * disabling functions multiple times.
174	 */
175	bool enabled;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
176};
177
 
178int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs);
 
179u64 drm_crtc_vblank_count(struct drm_crtc *crtc);
180u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc,
181				   ktime_t *vblanktime);
 
182void drm_crtc_send_vblank_event(struct drm_crtc *crtc,
183			       struct drm_pending_vblank_event *e);
184void drm_crtc_arm_vblank_event(struct drm_crtc *crtc,
185			      struct drm_pending_vblank_event *e);
186void drm_vblank_set_event(struct drm_pending_vblank_event *e,
187			  u64 *seq,
188			  ktime_t *now);
189bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe);
190bool drm_crtc_handle_vblank(struct drm_crtc *crtc);
191int drm_crtc_vblank_get(struct drm_crtc *crtc);
192void drm_crtc_vblank_put(struct drm_crtc *crtc);
193void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe);
194void drm_crtc_wait_one_vblank(struct drm_crtc *crtc);
195void drm_crtc_vblank_off(struct drm_crtc *crtc);
196void drm_crtc_vblank_reset(struct drm_crtc *crtc);
 
 
197void drm_crtc_vblank_on(struct drm_crtc *crtc);
198u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc);
199void drm_vblank_restore(struct drm_device *dev, unsigned int pipe);
200void drm_crtc_vblank_restore(struct drm_crtc *crtc);
201
202bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev,
203					   unsigned int pipe, int *max_error,
204					   ktime_t *vblank_time,
205					   bool in_vblank_irq);
206void drm_calc_timestamping_constants(struct drm_crtc *crtc,
207				     const struct drm_display_mode *mode);
208wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc);
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209#endif