Lines Matching defs:vblank
4 * drm_irq.c IRQ and vblank support
46 * DOC: vblank handling
62 * drm_crtc_handle_vblank() in its vblank interrupt handler for working vblank
69 * call drm_crtc_vblank_get() and release the vblank reference again with
70 * drm_crtc_vblank_put(). In between these two calls vblank interrupts are
73 * On many hardware disabling the vblank interrupt cannot be done in a race-free
75 * &drm_driver.max_vblank_count. In that case the vblank core only disables the
88 * vblank irq in drm_handle_vblank(). 1 msec should be ok.
102 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately)");
109 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
113 vblank->last = last;
115 write_seqlock(&vblank->seqlock);
116 vblank->time = t_vblank;
117 atomic64_add(vblank_count_inc, &vblank->count);
118 write_sequnlock(&vblank->seqlock);
123 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
125 return vblank->max_vblank_count ?: dev->max_vblank_count;
157 * Reset the stored timestamp for the current vblank count to correspond
158 * to the last vblank occurred.
163 * device vblank fields.
186 * Only reinitialize corresponding vblank timestamp if high-precision query
187 * available and didn't fail. Otherwise reinitialize delayed at next vblank
195 * vblank counter value before and after a modeset
203 * Call back into the driver to update the appropriate vblank counter
212 * device vblank fields.
217 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
222 int framedur_ns = vblank->framedur_ns;
231 * here if the register is small or we had vblank interrupts off for
234 * We repeat the hardware vblank counter & timestamp query until
237 * corresponding vblank timestamp.
246 diff = (cur_vblank - vblank->last) & max_vblank_count;
248 u64 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time));
272 * interval? If so then vblank irqs keep running and it will likely
273 * happen that the hardware vblank counter is not trustworthy as it
274 * might reset at some point in that interval and vblank timestamps
277 * random large forward jumps of the software vblank counter.
279 if (diff > 1 && (vblank->inmodeset & 0x2)) {
280 DRM_DEBUG_VBL("clamping vblank bump to 1 on crtc %u: diffr=%u"
285 DRM_DEBUG_VBL("updating vblank count on crtc %u:"
287 pipe, atomic64_read(&vblank->count), diff,
288 cur_vblank, vblank->last);
291 WARN_ON_ONCE(cur_vblank != vblank->last);
296 * Only reinitialize corresponding vblank timestamp if high-precision query
297 * available and didn't fail, or we were called from the vblank interrupt.
298 * Otherwise reinitialize delayed at next vblank interrupt and assign 0
309 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
315 count = atomic64_read(&vblank->count);
330 * drm_crtc_accurate_vblank_count - retrieve the master vblank counter
334 * interpolates to handle a race with vblank interrupts using the high precision
344 u64 vblank;
350 "This function requires support for accurate vblank timestamps.");
355 vblank = drm_vblank_count(dev, pipe);
359 return vblank;
381 * Disable vblank irq's on crtc, make sure that last vblank count
382 * of hardware and corresponding consistent software vblank counter
383 * are preserved, even if there are any spurious vblank irq's after
388 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
393 /* Prevent vblank irq processing while disabling vblank irqs,
400 * Update vblank count and disable vblank interrupts only if the
405 if (!vblank->enabled)
416 vblank->enabled = false;
423 vblank_disable_locked(struct drm_vblank_crtc *vblank, struct drm_device *dev,
427 BUG_ON(vblank != &dev->vblank[pipe]);
430 if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) {
431 DRM_DEBUG("disabling vblank on crtc %u\n", pipe);
438 struct drm_vblank_crtc *vblank = from_timer(vblank, t, disable_timer);
439 struct drm_device *dev = vblank->dev;
440 unsigned int pipe = vblank->pipe;
444 if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) {
445 DRM_DEBUG("disabling vblank on crtc %u\n", pipe);
460 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
462 WARN_ON(READ_ONCE(vblank->enabled) &&
465 del_timer_sync(&vblank->disable_timer);
466 seqlock_destroy(&vblank->seqlock);
469 kfree(dev->vblank);
477 * drm_vblank_init - initialize vblank support
481 * This function initializes vblank support for @num_crtcs display pipelines.
497 dev->vblank = kcalloc(num_crtcs, sizeof(*dev->vblank), GFP_KERNEL);
498 if (!dev->vblank)
502 struct drm_vblank_crtc *vblank = &dev->vblank[i];
504 vblank->dev = dev;
505 vblank->pipe = i;
506 DRM_INIT_WAITQUEUE(&vblank
507 timer_setup(&vblank->disable_timer, vblank_disable_fn, 0);
508 seqlock_init(&vblank->seqlock);
511 DRM_INFO("Supports vblank timestamp caching Rev 2 (21.10.2013).\n");
513 /* Driver specific high-precision vblank timestamping supported? */
515 DRM_INFO("Driver supports precise vblank timestamp query.\n");
517 DRM_INFO("No driver support for vblank timestamp query.\n");
519 /* Must have precise timestamping for reliable vblank instant disable */
535 * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
536 * @crtc: which CRTC's vblank waitqueue to retrieve
538 * This function returns a pointer to the vblank waitqueue for the CRTC.
539 * Drivers can use this to implement vblank waits using wait_event() and related
544 return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
550 * drm_calc_timestamping_constants - calculate vblank timestamp constants
554 * Calculate and store various constants which are later needed by vblank and
565 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
596 vblank->linedur_ns = linedur_ns;
597 vblank->framedur_ns = framedur_ns;
598 vblank->hwmode = *mode;
609 * drm_calc_vbltimestamp_from_scanoutpos - precise vblank timestamp helper
611 * @pipe: index of CRTC whose vblank timestamp to retrieve
617 * need to apply some workarounds for gpu-specific vblank irq quirks
620 * Implements calculation of exact vblank timestamps from given drm_display_mode
650 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
671 mode = &vblank->hwmode;
735 * vblank_time timestamp for end of vblank.
757 * vblank interval
759 * @pipe: index of CRTC whose vblank timestamp to retrieve
763 * need to apply some workarounds for gpu-specific vblank irq quirks
767 * vblank interval on specified CRTC. May call into kms-driver to
771 * call, i.e., it isn't very precisely locked to the true vblank.
800 * drm_crtc_vblank_count - retrieve "cooked" vblank counter value
803 * Fetches the "cooked" vblank count value that represents the number of
804 * vblank events since the system was booted, including lost events due to
806 * vblank interrupt (since it only reports the software vblank counter), see
809 * Note that for a given vblank counter value drm_crtc_handle_vblank()
813 * functions, iff the vblank count is the same or a later one.
818 * The software vblank counter.
827 * drm_vblank_count_and_time - retrieve "cooked" vblank counter value and the
828 * system timestamp corresponding to that vblank counter value.
831 * @vblanktime: Pointer to ktime_t to receive the vblank timestamp.
833 * Fetches the "cooked" vblank count value that represents the number of
834 * vblank events since the system was booted, including lost events due to
836 * of the vblank interval that corresponds to the current vblank counter value.
843 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
853 seq = read_seqbegin(&vblank->seqlock);
854 vblank_count = atomic64_read(&vblank->count);
855 *vblanktime = vblank->time;
856 } while (read_seqretry(&vblank->seqlock, seq));
862 * drm_crtc_vblank_count_and_time - retrieve "cooked" vblank counter value
863 * and the system timestamp corresponding to that vblank counter value
865 * @vblanktime: Pointer to time to receive the vblank timestamp.
867 * Fetches the "cooked" vblank count value that represents the number of
868 * vblank events since the system was booted, including lost events due to
870 * of the vblank interval that corresponds to the current vblank counter value.
872 * Note that for a given vblank counter value drm_crtc_handle_vblank()
876 * functions, iff the vblank count is the same or a later one.
918 * drm_crtc_arm_vblank_event - arm vblank event after pageflip
919 * @crtc: the source CRTC of the vblank event
922 * A lot of drivers need to generate vblank events for the very next vblank
924 * flip gets armed, but not when it actually executes within the next vblank
925 * period. This helper function implements exactly the required vblank arming
929 * atomic commit must ensure that the next vblank happens at exactly the same
931 * does **not** protect against the next vblank interrupt racing with either this
934 * 1. Driver commits new hardware state into vblank-synchronized registers.
935 * 2. A vblank happens, committing the hardware state. Also the corresponding
936 * vblank interrupt is fired off and fully processed by the interrupt
939 * 4. The event is only send out for the next vblank, which is wrong.
944 * The only way to make this work safely is to prevent the vblank from firing
952 * Caller must hold a vblank reference for the event @e acquired by a
953 * drm_crtc_vblank_get(), which will be dropped when the next vblank arrives.
970 * drm_crtc_send_vblank_event - helper to send vblank
971 * @crtc: the source CRTC of the vblank event
975 * vblank, and sends it to userspace. Caller must hold event lock.
1017 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1024 if (!vblank->enabled) {
1026 * Enable vblank irqs under vblank_time_lock protection.
1027 * All vblank count & timestamp updates are held off
1030 * prevent double-accounting of same vblank interval.
1033 DRM_DEBUG("enabling vblank on crtc %u, ret: %d\n", pipe, ret);
1035 atomic_dec(&vblank->refcount);
1040 * to mark the vblank as enabled after the call
1043 WRITE_ONCE(vblank->enabled, true);
1054 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1066 if (atomic_add_return(1, &vblank->refcount) == 1) {
1069 if (!vblank->enabled) {
1070 atomic_dec(&vblank->refcount);
1090 * drm_crtc_vblank_get - get a reference count on vblank events
1093 * Acquire a reference count on vblank events to avoid having them disabled
1113 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1120 if (WARN_ON(atomic_read(&vblank->refcount) == 0))
1124 if (atomic_dec_and_test(&vblank->refcount)) {
1128 vblank_disable_locked(vblank, dev, pipe);
1130 mod_timer(&vblank->disable_timer,
1137 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1142 if (WARN_ON(atomic_read(&vblank->refcount) == 0))
1146 if (atomic_dec_and_test(&vblank->refcount)) {
1150 vblank_disable_fn(&vblank->disable_timer);
1152 mod_timer(&vblank->disable_timer,
1158 * drm_crtc_vblank_put - give up ownership of vblank events
1161 * Release ownership of a given vblank counter, turning off interrupts
1176 * drm_wait_one_vblank - wait for one vblank
1180 * This waits for one vblank to pass on @pipe, using the irq driver interfaces.
1181 * It is a failure to call this when the vblank irq for @pipe is disabled, e.g.
1188 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1198 if (WARN(ret, "vblank not available on crtc %i, ret=%i\n", pipe, ret))
1202 DRM_SPIN_TIMED_WAIT_UNTIL(ret, &vblank->queue, &dev->event_lock,
1206 WARN(ret == 0, "vblank wait timed out on crtc %i\n", pipe);
1214 * drm_crtc_wait_one_vblank - wait for one vblank
1217 * This waits for one vblank to pass on @crtc, using the irq driver interfaces.
1218 * It is a failure to call this when the vblank irq for @crtc is disabled, e.g.
1228 * drm_crtc_vblank_off - disable vblank events on a CRTC
1231 * Drivers can use this function to shut down the vblank interrupt handling when
1232 * disabling a crtc. This function ensures that the latest vblank frame count is
1235 * Drivers must use this function when the hardware vblank counter can get
1242 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1254 DRM_DEBUG_VBL("crtc %d, vblank enabled %d, inmodeset %d\n",
1255 pipe, vblank->enabled, vblank->inmodeset);
1257 /* Avoid redundant vblank disables without previous
1259 if (drm_core_check_feature(dev, DRIVER_ATOMIC) || !vblank->inmodeset)
1262 DRM_SPIN_WAKEUP_ONE(&vblank->queue, &dev->event_lock);
1266 * the vblank interrupt by bumping the refcount.
1268 if (!vblank->inmodeset) {
1269 atomic_inc(&vblank->refcount);
1270 vblank->inmodeset = 1;
1273 /* Send any queued vblank events, lest the natives grow disquiet */
1279 DRM_DEBUG("Sending premature vblank event on disable: "
1290 vblank->hwmode.crtc_clock = 0;
1295 * drm_crtc_vblank_reset - reset vblank state to off on a CRTC
1298 * Drivers can use this function to reset the vblank state to off at load time.
1301 * drm_crtc_vblank_off() is that this function doesn't save the vblank counter
1311 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1315 * Prevent subsequent drm_vblank_get() from enabling the vblank
1318 if (!vblank->inmodeset) {
1319 atomic_inc(&vblank->refcount);
1320 vblank->inmodeset = 1;
1328 * drm_crtc_set_max_vblank_count - configure the hw max vblank counter value
1330 * @max_vblank_count: max hardware vblank counter value
1332 * Update the maximum hardware vblank counter value for @crtc
1334 * hardware vblank counter depends on the currently active
1337 * For example, if the hardware vblank counter does not work
1349 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1352 WARN_ON(!READ_ONCE(vblank->inmodeset));
1354 vblank->max_vblank_count = max_vblank_count;
1359 * drm_crtc_vblank_on - enable vblank events on a CRTC
1362 * This functions restores the vblank interrupt state captured with
1372 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1379 DRM_DEBUG_VBL("crtc %d, vblank enabled %d, inmodeset %d\n",
1380 pipe, vblank->enabled, vblank->inmodeset);
1383 if (vblank->inmodeset) {
1384 atomic_dec(&vblank->refcount);
1385 vblank->inmodeset = 0;
1392 * user wishes vblank interrupts to be enabled all the time.
1394 if (atomic_read(&vblank->refcount) != 0 || drm_vblank_offdelay == 0)
1401 * drm_vblank_restore - estimate missed vblanks and update vblank count.
1405 * Power manamement features can cause frame counter resets between vblank
1409 * vblank counter.
1416 struct drm_vblank_crtc *vblank;
1428 vblank = &dev->vblank[pipe];
1429 WARN_ONCE(drm_debug_enabled(DRM_UT_VBL) && !vblank->framedur_ns,
1431 framedur_ns = vblank->framedur_ns;
1438 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time));
1444 diff, diff_ns, framedur_ns, cur_vblank - vblank->last);
1450 * drm_crtc_vblank_restore - estimate missed vblanks and update vblank count.
1453 * Power manamement features can cause frame counter resets between vblank
1457 * vblank counter.
1468 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1470 /* vblank is not initialized (IRQ not installed ?), or has been freed */
1484 if (!vblank->inmodeset) {
1485 vblank->inmodeset = 0x1;
1487 vblank->inmodeset |= 0x2;
1494 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1497 /* vblank is not initialized (IRQ not installed ?), or has been freed */
1504 if (vblank->inmodeset) {
1509 if (vblank->inmodeset & 0x2)
1512 vblank->inmodeset = 0;
1558 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1587 * vblank disable, so no need for further locking. The reference from
1588 * drm_vblank_get() protects against vblank disable from another source.
1590 if (!READ_ONCE(vblank->enabled)) {
1603 DRM_DEBUG("event on vblank count %"PRIu64", current %"PRIu64", crtc %u\n",
1679 struct drm_vblank_crtc *vblank;
1727 vblank = &dev->vblank[pipe];
1730 * queries to return the cached timestamp of the last vblank.
1734 READ_ONCE(vblank->enabled)) {
1741 DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret);
1768 /* must hold on to the vblank ref until the event fires
1777 DRM_DEBUG("waiting on vblank count %"PRIu64", crtc %u\n",
1780 DRM_SPIN_TIMED_WAIT_UNTIL(wait, &vblank->queue,
1783 !READ_ONCE(vblank->enabled)));
1807 DRM_DEBUG("crtc %d vblank wait interrupted by signal\n", pipe);
1831 DRM_DEBUG("vblank event on %"PRIu64", current %"PRIu64"\n",
1844 * drm_handle_vblank - handle a vblank event
1848 * Drivers should call this routine in their vblank interrupt handlers to
1849 * update the vblank counter and send any signals that may be pending.
1855 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1868 * vblank enable/disable, as this would cause inconsistent
1869 * or corrupted timestamps and vblank counts.
1873 /* Vblank irq handling disabled. Nothing to do. */
1874 if (!vblank->enabled) {
1884 DRM_SPIN_WAKEUP_ONE(&vblank->queue, &dev->event_lock);
1887 * we finish processing the following vblank after all events have
1893 !atomic_read(&vblank->refcount));
1900 vblank_disable_fn(&vblank->disable_timer);
1907 * drm_crtc_handle_vblank - handle a vblank event
1910 * Drivers should call this routine in their vblank interrupt handlers to
1911 * update the vblank counter and send any signals that may be pending.
1915 * Note that for a given vblank counter value drm_crtc_handle_vblank()
1919 * functions, iff the vblank count is the same or a later one.
1933 * Get crtc VBLANK count.
1944 struct drm_vblank_crtc *vblank;
1963 vblank = &dev->vblank[pipe];
1964 vblank_enabled = dev->vblank_disable_immediate && READ_ONCE(vblank->enabled);
1969 DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret);
1987 * Queue a event for VBLANK sequence
1998 struct drm_vblank_crtc *vblank;
2027 vblank = &dev->vblank[pipe];
2035 DRM_DEBUG("crtc %d failed to acquire vblank counter, %d\n", pipe, ret);
2058 * vblank disable, so no need for further locking. The reference from
2059 * drm_crtc_vblank_get() protects against vblank disable from another source.
2061 if (!READ_ONCE(vblank->enabled)) {