Lines Matching refs:vblank
2 * drm_irq.c IRQ and vblank support
43 * DOC: vblank handling
54 * scanlines is referred to as the vertical blanking region, or vblank for
98 * this programming has to both start and end in the same vblank. To help
101 * The interrupt is in this context named the vblank interrupt.
103 * The vblank interrupt may be fired at different points depending on the
122 * drm_crtc_handle_vblank() in its vblank interrupt handler for working vblank
129 * call drm_crtc_vblank_get() and release the vblank reference again with
130 * drm_crtc_vblank_put(). In between these two calls vblank interrupts are
133 * On many hardware disabling the vblank interrupt cannot be done in a race-free
135 * &drm_driver.max_vblank_count. In that case the vblank core only disables the
141 * automatically generate fake vblank events as part of the display update.
152 * vblank irq in drm_handle_vblank(). 1 msec should be ok.
166 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0: disable immediately)");
173 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
177 vblank->last = last;
179 write_seqlock(&vblank->seqlock);
180 vblank->time = t_vblank;
181 atomic64_add(vblank_count_inc, &vblank->count);
182 write_sequnlock(&vblank->seqlock);
187 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
189 return vblank->max_vblank_count ?: dev->max_vblank_count;
220 * Reset the stored timestamp for the current vblank count to correspond
221 * to the last vblank occurred.
226 * device vblank fields.
247 * Only reinitialize corresponding vblank timestamp if high-precision query
248 * available and didn't fail. Otherwise reinitialize delayed at next vblank
256 * vblank counter value before and after a modeset
264 * Call back into the driver to update the appropriate vblank counter
273 * device vblank fields.
278 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
283 int framedur_ns = vblank->framedur_ns;
290 * here if the register is small or we had vblank interrupts off for
293 * We repeat the hardware vblank counter & timestamp query until
296 * corresponding vblank timestamp.
305 diff = (cur_vblank - vblank->last) & max_vblank_count;
307 u64 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time));
331 * interval? If so then vblank irqs keep running and it will likely
332 * happen that the hardware vblank counter is not trustworthy as it
333 * might reset at some point in that interval and vblank timestamps
336 * random large forward jumps of the software vblank counter.
338 if (diff > 1 && (vblank->inmodeset & 0x2)) {
340 "clamping vblank bump to 1 on crtc %u: diffr=%u"
345 drm_dbg_vbl(dev, "updating vblank count on crtc %u:"
347 pipe, (unsigned long long)atomic64_read(&vblank->count),
348 diff, cur_vblank, vblank->last);
351 drm_WARN_ON_ONCE(dev, cur_vblank != vblank->last);
356 * Only reinitialize corresponding vblank timestamp if high-precision query
357 * available and didn't fail, or we were called from the vblank interrupt.
358 * Otherwise reinitialize delayed at next vblank interrupt and assign 0
369 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
375 count = atomic64_read(&vblank->count);
390 * drm_crtc_accurate_vblank_count - retrieve the master vblank counter
394 * interpolates to handle a race with vblank interrupts using the high precision
404 u64 vblank;
409 "This function requires support for accurate vblank timestamps.");
414 vblank = drm_vblank_count(dev, pipe);
418 return vblank;
438 * Disable vblank irq's on crtc, make sure that last vblank count
439 * of hardware and corresponding consistent software vblank counter
440 * are preserved, even if there are any spurious vblank irq's after
445 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
450 /* Prevent vblank irq processing while disabling vblank irqs,
457 * Update vblank count and disable vblank interrupts only if the
462 if (!vblank->enabled)
473 vblank->enabled = false;
481 struct drm_vblank_crtc *vblank = from_timer(vblank, t, disable_timer);
482 struct drm_device *dev = vblank->dev;
483 unsigned int pipe = vblank->pipe;
487 if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) {
488 drm_dbg_core(dev, "disabling vblank on crtc %u\n", pipe);
496 struct drm_vblank_crtc *vblank = ptr;
498 drm_WARN_ON(dev, READ_ONCE(vblank->enabled) &&
501 drm_vblank_destroy_worker(vblank);
502 del_timer_sync(&vblank->disable_timer);
506 * drm_vblank_init - initialize vblank support
510 * This function initializes vblank support for @num_crtcs display pipelines.
525 dev->vblank = drmm_kcalloc(dev, num_crtcs, sizeof(*dev->vblank), GFP_KERNEL);
526 if (!dev->vblank)
532 struct drm_vblank_crtc *vblank = &dev->vblank[i];
534 vblank->dev = dev;
535 vblank->pipe = i;
536 init_waitqueue_head(&vblank->queue);
537 timer_setup(&vblank->disable_timer, vblank_disable_fn, 0);
538 seqlock_init(&vblank->seqlock);
541 vblank);
545 ret = drm_vblank_worker_init(vblank);
559 * Drivers may call this function to test if vblank support is
577 * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
578 * @crtc: which CRTC's vblank waitqueue to retrieve
580 * This function returns a pointer to the vblank waitqueue for the CRTC.
581 * Drivers can use this to implement vblank waits using wait_event() and related
586 return &crtc->dev->vblank[drm_crtc_index(crtc)].queue;
592 * drm_calc_timestamping_constants - calculate vblank timestamp constants
596 * Calculate and store various constants which are later needed by vblank and
607 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
639 vblank->linedur_ns = linedur_ns;
640 vblank->framedur_ns = framedur_ns;
641 vblank->hwmode = *mode;
653 * drm_crtc_vblank_helper_get_vblank_timestamp_internal - precise vblank
655 * @crtc: CRTC whose vblank timestamp to retrieve
661 * need to apply some workarounds for gpu-specific vblank irq quirks
667 * Implements calculation of exact vblank timestamps from given drm_display_mode
692 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
712 mode = &vblank->hwmode;
777 * vblank_time timestamp for end of vblank.
799 * drm_crtc_vblank_helper_get_vblank_timestamp - precise vblank timestamp
801 * @crtc: CRTC whose vblank timestamp to retrieve
807 * need to apply some workarounds for gpu-specific vblank irq quirks
810 * Implements calculation of exact vblank timestamps from given drm_display_mode
842 * vblank interval
844 * @pipe: index of CRTC whose vblank timestamp to retrieve
848 * need to apply some workarounds for gpu-specific vblank irq quirks
852 * vblank interval on specified CRTC. May call into kms-driver to
856 * call, i.e., it isn't very precisely locked to the true vblank.
889 * drm_crtc_vblank_count - retrieve "cooked" vblank counter value
892 * Fetches the "cooked" vblank count value that represents the number of
893 * vblank events since the system was booted, including lost events due to
895 * vblank interrupt (since it only reports the software vblank counter), see
898 * Note that for a given vblank counter value drm_crtc_handle_vblank()
902 * functions, iff the vblank count is the same or a later one.
907 * The software vblank counter.
916 * drm_vblank_count_and_time - retrieve "cooked" vblank counter value and the
917 * system timestamp corresponding to that vblank counter value.
920 * @vblanktime: Pointer to ktime_t to receive the vblank timestamp.
922 * Fetches the "cooked" vblank count value that represents the number of
923 * vblank events since the system was booted, including lost events due to
925 * of the vblank interval that corresponds to the current vblank counter value.
932 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
942 seq = read_seqbegin(&vblank->seqlock);
943 vblank_count = atomic64_read(&vblank->count);
944 *vblanktime = vblank->time;
945 } while (read_seqretry(&vblank->seqlock, seq));
951 * drm_crtc_vblank_count_and_time - retrieve "cooked" vblank counter value
952 * and the system timestamp corresponding to that vblank counter value
954 * @vblanktime: Pointer to time to receive the vblank timestamp.
956 * Fetches the "cooked" vblank count value that represents the number of
957 * vblank events since the system was booted, including lost events due to
959 * of the vblank interval that corresponds to the current vblank counter value.
961 * Note that for a given vblank counter value drm_crtc_handle_vblank()
965 * functions, iff the vblank count is the same or a later one.
1007 * drm_crtc_arm_vblank_event - arm vblank event after pageflip
1008 * @crtc: the source CRTC of the vblank event
1011 * A lot of drivers need to generate vblank events for the very next vblank
1013 * flip gets armed, but not when it actually executes within the next vblank
1014 * period. This helper function implements exactly the required vblank arming
1018 * atomic commit must ensure that the next vblank happens at exactly the same
1020 * does **not** protect against the next vblank interrupt racing with either this
1023 * 1. Driver commits new hardware state into vblank-synchronized registers.
1024 * 2. A vblank happens, committing the hardware state. Also the corresponding
1025 * vblank interrupt is fired off and fully processed by the interrupt
1028 * 4. The event is only send out for the next vblank, which is wrong.
1033 * The only way to make this work safely is to prevent the vblank from firing
1041 * Caller must hold a vblank reference for the event @e acquired by a
1042 * drm_crtc_vblank_get(), which will be dropped when the next vblank arrives.
1059 * drm_crtc_send_vblank_event - helper to send vblank event after pageflip
1060 * @crtc: the source CRTC of the vblank event
1064 * vblank, and sends it to userspace. Caller must hold event lock.
1108 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1115 if (!vblank->enabled) {
1117 * Enable vblank irqs under vblank_time_lock protection.
1118 * All vblank count & timestamp updates are held off
1121 * prevent double-accounting of same vblank interval.
1124 drm_dbg_core(dev, "enabling vblank on crtc %u, ret: %d\n",
1127 atomic_dec(&vblank->refcount);
1132 * to mark the vblank as enabled after the call
1135 WRITE_ONCE(vblank->enabled, true);
1146 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1158 if (atomic_add_return(1, &vblank->refcount) == 1) {
1161 if (!vblank->enabled) {
1162 atomic_dec(&vblank->refcount);
1172 * drm_crtc_vblank_get - get a reference count on vblank events
1175 * Acquire a reference count on vblank events to avoid having them disabled
1189 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1194 if (drm_WARN_ON(dev, atomic_read(&vblank->refcount) == 0))
1198 if (atomic_dec_and_test(&vblank->refcount)) {
1202 vblank_disable_fn(&vblank->disable_timer);
1204 mod_timer(&vblank->disable_timer,
1210 * drm_crtc_vblank_put - give up ownership of vblank events
1213 * Release ownership of a given vblank counter, turning off interrupts
1223 * drm_wait_one_vblank - wait for one vblank
1227 * This waits for one vblank to pass on @pipe, using the irq driver interfaces.
1228 * It is a failure to call this when the vblank irq for @pipe is disabled, e.g.
1235 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1243 if (drm_WARN(dev, ret, "vblank not available on crtc %i, ret=%i\n",
1249 ret = wait_event_timeout(vblank->queue,
1253 drm_WARN(dev, ret == 0, "vblank wait timed out on crtc %i\n", pipe);
1260 * drm_crtc_wait_one_vblank - wait for one vblank
1263 * This waits for one vblank to pass on @crtc, using the irq driver interfaces.
1264 * It is a failure to call this when the vblank irq for @crtc is disabled, e.g.
1274 * drm_crtc_vblank_off - disable vblank events on a CRTC
1277 * Drivers can use this function to shut down the vblank interrupt handling when
1278 * disabling a crtc. This function ensures that the latest vblank frame count is
1281 * Drivers must use this function when the hardware vblank counter can get
1288 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1297 * Grab event_lock early to prevent vblank work from being scheduled
1298 * while we're in the middle of shutting down vblank interrupts
1303 drm_dbg_vbl(dev, "crtc %d, vblank enabled %d, inmodeset %d\n",
1304 pipe, vblank->enabled, vblank->inmodeset);
1306 /* Avoid redundant vblank disables without previous
1308 if (drm_core_check_feature(dev, DRIVER_ATOMIC) || !vblank->inmodeset)
1311 wake_up(&vblank->queue);
1315 * the vblank interrupt by bumping the refcount.
1317 if (!vblank->inmodeset) {
1318 atomic_inc(&vblank->refcount);
1319 vblank->inmodeset = 1;
1323 /* Send any queued vblank events, lest the natives grow disquiet */
1329 drm_dbg_core(dev, "Sending premature vblank event on disable: "
1337 /* Cancel any leftover pending vblank work */
1338 drm_vblank_cancel_pending_works(vblank);
1344 vblank->hwmode.crtc_clock = 0;
1346 /* Wait for any vblank work that's still executing to finish */
1347 drm_vblank_flush_worker(vblank);
1352 * drm_crtc_vblank_reset - reset vblank state to off on a CRTC
1355 * Drivers can use this function to reset the vblank state to off at load time.
1358 * drm_crtc_vblank_off() is that this function doesn't save the vblank counter
1367 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1371 * Prevent subsequent drm_vblank_get() from enabling the vblank
1374 if (!vblank->inmodeset) {
1375 atomic_inc(&vblank->refcount);
1376 vblank->inmodeset = 1;
1381 drm_WARN_ON(dev, !list_empty(&vblank->pending_work));
1386 * drm_crtc_set_max_vblank_count - configure the hw max vblank counter value
1388 * @max_vblank_count: max hardware vblank counter value
1390 * Update the maximum hardware vblank counter value for @crtc
1392 * hardware vblank counter depends on the currently active
1395 * For example, if the hardware vblank counter does not work
1407 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1410 drm_WARN_ON(dev, !READ_ONCE(vblank->inmodeset));
1412 vblank->max_vblank_count = max_vblank_count;
1417 * drm_crtc_vblank_on - enable vblank events on a CRTC
1420 * This functions restores the vblank interrupt state captured with
1430 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1436 drm_dbg_vbl(dev, "crtc %d, vblank enabled %d, inmodeset %d\n",
1437 pipe, vblank->enabled, vblank->inmodeset);
1440 if (vblank->inmodeset) {
1441 atomic_dec(&vblank->refcount);
1442 vblank->inmodeset = 0;
1449 * user wishes vblank interrupts to be enabled all the time.
1451 if (atomic_read(&vblank->refcount) != 0 || drm_vblank_offdelay == 0)
1458 * drm_vblank_restore - estimate missed vblanks and update vblank count.
1462 * Power manamement features can cause frame counter resets between vblank
1466 * vblank counter.
1473 struct drm_vblank_crtc *vblank;
1485 vblank = &dev->vblank[pipe];
1487 drm_debug_enabled(DRM_UT_VBL) && !vblank->framedur_ns,
1489 framedur_ns = vblank->framedur_ns;
1496 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time));
1503 diff, diff_ns, framedur_ns, cur_vblank - vblank->last);
1509 * drm_crtc_vblank_restore - estimate missed vblanks and update vblank count.
1512 * Power manamement features can cause frame counter resets between vblank
1516 * vblank counter.
1527 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1529 /* vblank is not initialized (IRQ not installed ?), or has been freed */
1543 if (!vblank->inmodeset) {
1544 vblank->inmodeset = 0x1;
1546 vblank->inmodeset |= 0x2;
1553 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1555 /* vblank is not initialized (IRQ not installed ?), or has been freed */
1562 if (vblank->inmodeset) {
1567 if (vblank->inmodeset & 0x2)
1570 vblank->inmodeset = 0;
1611 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1640 * vblank disable, so no need for further locking. The reference from
1641 * drm_vblank_get() protects against vblank disable from another source.
1643 if (!READ_ONCE(vblank->enabled)) {
1656 drm_dbg_core(dev, "event on vblank count %llu, current %llu, crtc %u\n",
1732 struct drm_vblank_crtc *vblank;
1781 vblank = &dev->vblank[pipe];
1784 * queries to return the cached timestamp of the last vblank.
1788 READ_ONCE(vblank->enabled)) {
1796 "crtc %d failed to acquire vblank counter, %d\n",
1824 /* must hold on to the vblank ref until the event fires
1833 drm_dbg_core(dev, "waiting on vblank count %llu, crtc %u\n",
1835 wait = wait_event_interruptible_timeout(vblank->queue,
1837 !READ_ONCE(vblank->enabled),
1861 drm_dbg_core(dev, "crtc %d vblank wait interrupted by signal\n",
1888 drm_dbg_core(dev, "vblank event on %llu, current %llu\n",
1903 * drm_handle_vblank - handle a vblank event
1907 * Drivers should call this routine in their vblank interrupt handlers to
1908 * update the vblank counter and send any signals that may be pending.
1914 struct drm_vblank_crtc *vblank = &dev->vblank[pipe];
1927 * vblank enable/disable, as this would cause inconsistent
1928 * or corrupted timestamps and vblank counts.
1933 if (!vblank->enabled) {
1943 wake_up(&vblank->queue);
1946 * we finish processing the following vblank after all events have
1952 !atomic_read(&vblank->refcount));
1955 drm_handle_vblank_works(vblank);
1960 vblank_disable_fn(&vblank->disable_timer);
1967 * drm_crtc_handle_vblank - handle a vblank event
1970 * Drivers should call this routine in their vblank interrupt handlers to
1971 * update the vblank counter and send any signals that may be pending.
1975 * Note that for a given vblank counter value drm_crtc_handle_vblank()
1979 * functions, iff the vblank count is the same or a later one.
2004 struct drm_vblank_crtc *vblank;
2023 vblank = &dev->vblank[pipe];
2024 vblank_enabled = dev->vblank_disable_immediate && READ_ONCE(vblank->enabled);
2030 "crtc %d failed to acquire vblank counter, %d\n",
2060 struct drm_vblank_crtc *vblank;
2088 vblank = &dev->vblank[pipe];
2097 "crtc %d failed to acquire vblank counter, %d\n",
2121 * vblank disable, so no need for further locking. The reference from
2122 * drm_crtc_vblank_get() protects against vblank disable from another source.
2124 if (!READ_ONCE(vblank->enabled)) {