]>
Commit | Line | Data |
---|---|---|
3ed4351a DV |
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 | ||
35 | struct drm_device; | |
36 | struct drm_crtc; | |
37 | ||
38 | /** | |
39 | * struct drm_pending_vblank_event - pending vblank event tracking | |
40 | */ | |
41 | struct 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; | |
570e8696 KP |
50 | /** |
51 | * @sequence: frame event should be triggered at | |
52 | */ | |
53 | u64 sequence; | |
3ed4351a DV |
54 | /** |
55 | * @event: Actual event which will be sent to userspace. | |
56 | */ | |
bd386e51 KP |
57 | union { |
58 | struct drm_event base; | |
59 | struct drm_event_vblank vbl; | |
60 | } event; | |
3ed4351a DV |
61 | }; |
62 | ||
63 | /** | |
64 | * struct drm_vblank_crtc - vblank tracking for a CRTC | |
65 | * | |
66 | * This structure tracks the vblank state for one CRTC. | |
67 | * | |
68 | * Note that for historical reasons - the vblank handling code is still shared | |
69 | * with legacy/non-kms drivers - this is a free-standing structure not directly | |
70 | * connected to &struct drm_crtc. But all public interface functions are taking | |
71 | * a &struct drm_crtc to hide this implementation detail. | |
72 | */ | |
73 | struct drm_vblank_crtc { | |
74 | /** | |
75 | * @dev: Pointer to the &drm_device. | |
76 | */ | |
77 | struct drm_device *dev; | |
78 | /** | |
79 | * @queue: Wait queue for vblank waiters. | |
80 | */ | |
81 | wait_queue_head_t queue; /**< VBLANK wait queue */ | |
82 | /** | |
83 | * @disable_timer: Disable timer for the delayed vblank disabling | |
84 | * hysteresis logic. Vblank disabling is controlled through the | |
85 | * drm_vblank_offdelay module option and the setting of the | |
86 | * &drm_device.max_vblank_count value. | |
87 | */ | |
88 | struct timer_list disable_timer; | |
89 | ||
90 | /** | |
91 | * @seqlock: Protect vblank count and time. | |
92 | */ | |
93 | seqlock_t seqlock; /* protects vblank count and time */ | |
94 | ||
95 | /** | |
96 | * @count: Current software vblank counter. | |
97 | */ | |
570e8696 | 98 | u64 count; |
3ed4351a DV |
99 | /** |
100 | * @time: Vblank timestamp corresponding to @count. | |
101 | */ | |
67680d3c | 102 | ktime_t time; |
3ed4351a DV |
103 | |
104 | /** | |
105 | * @refcount: Number of users/waiters of the vblank interrupt. Only when | |
106 | * this refcount reaches 0 can the hardware interrupt be disabled using | |
107 | * @disable_timer. | |
108 | */ | |
109 | atomic_t refcount; /* number of users of vblank interruptsper crtc */ | |
110 | /** | |
111 | * @last: Protected by &drm_device.vbl_lock, used for wraparound handling. | |
112 | */ | |
113 | u32 last; | |
114 | /** | |
115 | * @inmodeset: Tracks whether the vblank is disabled due to a modeset. | |
116 | * For legacy driver bit 2 additionally tracks whether an additional | |
117 | * temporary vblank reference has been acquired to paper over the | |
118 | * hardware counter resetting/jumping. KMS drivers should instead just | |
119 | * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly | |
120 | * save and restore the vblank count. | |
121 | */ | |
122 | unsigned int inmodeset; /* Display driver is setting mode */ | |
123 | /** | |
124 | * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this | |
125 | * structure. | |
126 | */ | |
127 | unsigned int pipe; | |
128 | /** | |
129 | * @framedur_ns: Frame/Field duration in ns, used by | |
130 | * drm_calc_vbltimestamp_from_scanoutpos() and computed by | |
131 | * drm_calc_timestamping_constants(). | |
132 | */ | |
133 | int framedur_ns; | |
134 | /** | |
135 | * @linedur_ns: Line duration in ns, used by | |
136 | * drm_calc_vbltimestamp_from_scanoutpos() and computed by | |
137 | * drm_calc_timestamping_constants(). | |
138 | */ | |
139 | int linedur_ns; | |
140 | ||
141 | /** | |
142 | * @hwmode: | |
143 | * | |
144 | * Cache of the current hardware display mode. Only valid when @enabled | |
145 | * is set. This is used by helpers like | |
146 | * drm_calc_vbltimestamp_from_scanoutpos(). We can't just access the | |
147 | * hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode, | |
148 | * because that one is really hard to get from interrupt context. | |
149 | */ | |
150 | struct drm_display_mode hwmode; | |
151 | ||
152 | /** | |
153 | * @enabled: Tracks the enabling state of the corresponding &drm_crtc to | |
154 | * avoid double-disabling and hence corrupting saved state. Needed by | |
155 | * drivers not using atomic KMS, since those might go through their CRTC | |
156 | * disabling functions multiple times. | |
157 | */ | |
158 | bool enabled; | |
159 | }; | |
160 | ||
161 | int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs); | |
570e8696 KP |
162 | u64 drm_crtc_vblank_count(struct drm_crtc *crtc); |
163 | u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, | |
67680d3c | 164 | ktime_t *vblanktime); |
3ed4351a DV |
165 | void drm_crtc_send_vblank_event(struct drm_crtc *crtc, |
166 | struct drm_pending_vblank_event *e); | |
167 | void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, | |
168 | struct drm_pending_vblank_event *e); | |
bd386e51 KP |
169 | void drm_vblank_set_event(struct drm_pending_vblank_event *e, |
170 | u64 *seq, | |
171 | ktime_t *now); | |
3ed4351a DV |
172 | bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe); |
173 | bool drm_crtc_handle_vblank(struct drm_crtc *crtc); | |
174 | int drm_crtc_vblank_get(struct drm_crtc *crtc); | |
175 | void drm_crtc_vblank_put(struct drm_crtc *crtc); | |
176 | void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe); | |
177 | void drm_crtc_wait_one_vblank(struct drm_crtc *crtc); | |
178 | void drm_crtc_vblank_off(struct drm_crtc *crtc); | |
179 | void drm_crtc_vblank_reset(struct drm_crtc *crtc); | |
180 | void drm_crtc_vblank_on(struct drm_crtc *crtc); | |
ca814b25 | 181 | u32 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc); |
3ed4351a DV |
182 | |
183 | bool drm_calc_vbltimestamp_from_scanoutpos(struct drm_device *dev, | |
184 | unsigned int pipe, int *max_error, | |
67680d3c | 185 | ktime_t *vblank_time, |
3ed4351a DV |
186 | bool in_vblank_irq); |
187 | void drm_calc_timestamping_constants(struct drm_crtc *crtc, | |
188 | const struct drm_display_mode *mode); | |
189 | wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc); | |
190 | #endif |