![]() |
|
|||
0001 /* 0002 * Copyright 2016 Intel Corp. 0003 * 0004 * Permission is hereby granted, free of charge, to any person obtaining a 0005 * copy of this software and associated documentation files (the "Software"), 0006 * to deal in the Software without restriction, including without limitation 0007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 0008 * and/or sell copies of the Software, and to permit persons to whom the 0009 * Software is furnished to do so, subject to the following conditions: 0010 * 0011 * The above copyright notice and this permission notice (including the next 0012 * paragraph) shall be included in all copies or substantial portions of the 0013 * Software. 0014 * 0015 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 0016 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 0017 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 0018 * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 0019 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 0020 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 0021 * OTHER DEALINGS IN THE SOFTWARE. 0022 */ 0023 0024 #ifndef _DRM_VBLANK_H_ 0025 #define _DRM_VBLANK_H_ 0026 0027 #include <linux/seqlock.h> 0028 #include <linux/idr.h> 0029 #include <linux/poll.h> 0030 #include <linux/kthread.h> 0031 0032 #include <drm/drm_file.h> 0033 #include <drm/drm_modes.h> 0034 0035 struct drm_device; 0036 struct drm_crtc; 0037 struct drm_vblank_work; 0038 0039 /** 0040 * struct drm_pending_vblank_event - pending vblank event tracking 0041 */ 0042 struct drm_pending_vblank_event { 0043 /** 0044 * @base: Base structure for tracking pending DRM events. 0045 */ 0046 struct drm_pending_event base; 0047 /** 0048 * @pipe: drm_crtc_index() of the &drm_crtc this event is for. 0049 */ 0050 unsigned int pipe; 0051 /** 0052 * @sequence: frame event should be triggered at 0053 */ 0054 u64 sequence; 0055 /** 0056 * @event: Actual event which will be sent to userspace. 0057 */ 0058 union { 0059 /** 0060 * @event.base: DRM event base class. 0061 */ 0062 struct drm_event base; 0063 0064 /** 0065 * @event.vbl: 0066 * 0067 * Event payload for vblank events, requested through 0068 * either the MODE_PAGE_FLIP or MODE_ATOMIC IOCTL. Also 0069 * generated by the legacy WAIT_VBLANK IOCTL, but new userspace 0070 * should use MODE_QUEUE_SEQUENCE and &event.seq instead. 0071 */ 0072 struct drm_event_vblank vbl; 0073 0074 /** 0075 * @event.seq: Event payload for the MODE_QUEUEU_SEQUENCE IOCTL. 0076 */ 0077 struct drm_event_crtc_sequence seq; 0078 } event; 0079 }; 0080 0081 /** 0082 * struct drm_vblank_crtc - vblank tracking for a CRTC 0083 * 0084 * This structure tracks the vblank state for one CRTC. 0085 * 0086 * Note that for historical reasons - the vblank handling code is still shared 0087 * with legacy/non-kms drivers - this is a free-standing structure not directly 0088 * connected to &struct drm_crtc. But all public interface functions are taking 0089 * a &struct drm_crtc to hide this implementation detail. 0090 */ 0091 struct drm_vblank_crtc { 0092 /** 0093 * @dev: Pointer to the &drm_device. 0094 */ 0095 struct drm_device *dev; 0096 /** 0097 * @queue: Wait queue for vblank waiters. 0098 */ 0099 wait_queue_head_t queue; 0100 /** 0101 * @disable_timer: Disable timer for the delayed vblank disabling 0102 * hysteresis logic. Vblank disabling is controlled through the 0103 * drm_vblank_offdelay module option and the setting of the 0104 * &drm_device.max_vblank_count value. 0105 */ 0106 struct timer_list disable_timer; 0107 0108 /** 0109 * @seqlock: Protect vblank count and time. 0110 */ 0111 seqlock_t seqlock; 0112 0113 /** 0114 * @count: 0115 * 0116 * Current software vblank counter. 0117 * 0118 * Note that for a given vblank counter value drm_crtc_handle_vblank() 0119 * and drm_crtc_vblank_count() or drm_crtc_vblank_count_and_time() 0120 * provide a barrier: Any writes done before calling 0121 * drm_crtc_handle_vblank() will be visible to callers of the later 0122 * functions, iff the vblank count is the same or a later one. 0123 * 0124 * IMPORTANT: This guarantee requires barriers, therefor never access 0125 * this field directly. Use drm_crtc_vblank_count() instead. 0126 */ 0127 atomic64_t count; 0128 /** 0129 * @time: Vblank timestamp corresponding to @count. 0130 */ 0131 ktime_t time; 0132 0133 /** 0134 * @refcount: Number of users/waiters of the vblank interrupt. Only when 0135 * this refcount reaches 0 can the hardware interrupt be disabled using 0136 * @disable_timer. 0137 */ 0138 atomic_t refcount; 0139 /** 0140 * @last: Protected by &drm_device.vbl_lock, used for wraparound handling. 0141 */ 0142 u32 last; 0143 /** 0144 * @max_vblank_count: 0145 * 0146 * Maximum value of the vblank registers for this crtc. This value +1 0147 * will result in a wrap-around of the vblank register. It is used 0148 * by the vblank core to handle wrap-arounds. 0149 * 0150 * If set to zero the vblank core will try to guess the elapsed vblanks 0151 * between times when the vblank interrupt is disabled through 0152 * high-precision timestamps. That approach is suffering from small 0153 * races and imprecision over longer time periods, hence exposing a 0154 * hardware vblank counter is always recommended. 0155 * 0156 * This is the runtime configurable per-crtc maximum set through 0157 * drm_crtc_set_max_vblank_count(). If this is used the driver 0158 * must leave the device wide &drm_device.max_vblank_count at zero. 0159 * 0160 * If non-zero, &drm_crtc_funcs.get_vblank_counter must be set. 0161 */ 0162 u32 max_vblank_count; 0163 /** 0164 * @inmodeset: Tracks whether the vblank is disabled due to a modeset. 0165 * For legacy driver bit 2 additionally tracks whether an additional 0166 * temporary vblank reference has been acquired to paper over the 0167 * hardware counter resetting/jumping. KMS drivers should instead just 0168 * call drm_crtc_vblank_off() and drm_crtc_vblank_on(), which explicitly 0169 * save and restore the vblank count. 0170 */ 0171 unsigned int inmodeset; 0172 /** 0173 * @pipe: drm_crtc_index() of the &drm_crtc corresponding to this 0174 * structure. 0175 */ 0176 unsigned int pipe; 0177 /** 0178 * @framedur_ns: Frame/Field duration in ns, used by 0179 * drm_crtc_vblank_helper_get_vblank_timestamp() and computed by 0180 * drm_calc_timestamping_constants(). 0181 */ 0182 int framedur_ns; 0183 /** 0184 * @linedur_ns: Line duration in ns, used by 0185 * drm_crtc_vblank_helper_get_vblank_timestamp() and computed by 0186 * drm_calc_timestamping_constants(). 0187 */ 0188 int linedur_ns; 0189 0190 /** 0191 * @hwmode: 0192 * 0193 * Cache of the current hardware display mode. Only valid when @enabled 0194 * is set. This is used by helpers like 0195 * drm_crtc_vblank_helper_get_vblank_timestamp(). We can't just access 0196 * the hardware mode by e.g. looking at &drm_crtc_state.adjusted_mode, 0197 * because that one is really hard to get from interrupt context. 0198 */ 0199 struct drm_display_mode hwmode; 0200 0201 /** 0202 * @enabled: Tracks the enabling state of the corresponding &drm_crtc to 0203 * avoid double-disabling and hence corrupting saved state. Needed by 0204 * drivers not using atomic KMS, since those might go through their CRTC 0205 * disabling functions multiple times. 0206 */ 0207 bool enabled; 0208 0209 /** 0210 * @worker: The &kthread_worker used for executing vblank works. 0211 */ 0212 struct kthread_worker *worker; 0213 0214 /** 0215 * @pending_work: A list of scheduled &drm_vblank_work items that are 0216 * waiting for a future vblank. 0217 */ 0218 struct list_head pending_work; 0219 0220 /** 0221 * @work_wait_queue: The wait queue used for signaling that a 0222 * &drm_vblank_work item has either finished executing, or was 0223 * cancelled. 0224 */ 0225 wait_queue_head_t work_wait_queue; 0226 }; 0227 0228 int drm_vblank_init(struct drm_device *dev, unsigned int num_crtcs); 0229 bool drm_dev_has_vblank(const struct drm_device *dev); 0230 u64 drm_crtc_vblank_count(struct drm_crtc *crtc); 0231 u64 drm_crtc_vblank_count_and_time(struct drm_crtc *crtc, 0232 ktime_t *vblanktime); 0233 void drm_crtc_send_vblank_event(struct drm_crtc *crtc, 0234 struct drm_pending_vblank_event *e); 0235 void drm_crtc_arm_vblank_event(struct drm_crtc *crtc, 0236 struct drm_pending_vblank_event *e); 0237 void drm_vblank_set_event(struct drm_pending_vblank_event *e, 0238 u64 *seq, 0239 ktime_t *now); 0240 bool drm_handle_vblank(struct drm_device *dev, unsigned int pipe); 0241 bool drm_crtc_handle_vblank(struct drm_crtc *crtc); 0242 int drm_crtc_vblank_get(struct drm_crtc *crtc); 0243 void drm_crtc_vblank_put(struct drm_crtc *crtc); 0244 void drm_wait_one_vblank(struct drm_device *dev, unsigned int pipe); 0245 void drm_crtc_wait_one_vblank(struct drm_crtc *crtc); 0246 void drm_crtc_vblank_off(struct drm_crtc *crtc); 0247 void drm_crtc_vblank_reset(struct drm_crtc *crtc); 0248 void drm_crtc_vblank_on(struct drm_crtc *crtc); 0249 u64 drm_crtc_accurate_vblank_count(struct drm_crtc *crtc); 0250 void drm_crtc_vblank_restore(struct drm_crtc *crtc); 0251 0252 void drm_calc_timestamping_constants(struct drm_crtc *crtc, 0253 const struct drm_display_mode *mode); 0254 wait_queue_head_t *drm_crtc_vblank_waitqueue(struct drm_crtc *crtc); 0255 void drm_crtc_set_max_vblank_count(struct drm_crtc *crtc, 0256 u32 max_vblank_count); 0257 0258 /* 0259 * Helpers for struct drm_crtc_funcs 0260 */ 0261 0262 typedef bool (*drm_vblank_get_scanout_position_func)(struct drm_crtc *crtc, 0263 bool in_vblank_irq, 0264 int *vpos, int *hpos, 0265 ktime_t *stime, 0266 ktime_t *etime, 0267 const struct drm_display_mode *mode); 0268 0269 bool 0270 drm_crtc_vblank_helper_get_vblank_timestamp_internal(struct drm_crtc *crtc, 0271 int *max_error, 0272 ktime_t *vblank_time, 0273 bool in_vblank_irq, 0274 drm_vblank_get_scanout_position_func get_scanout_position); 0275 bool drm_crtc_vblank_helper_get_vblank_timestamp(struct drm_crtc *crtc, 0276 int *max_error, 0277 ktime_t *vblank_time, 0278 bool in_vblank_irq); 0279 0280 #endif
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |