Lines Matching +full:ref +full:- +full:clock +full:- +full:period +full:- +full:ns

57  * For historical reference, the vertical blanking period was designed to
91 * "Physical top of display" is the reference point for the high-precision/
95 * vertical blanking period so that settings like gamma, the image buffer
109 * tear-free display, users must synchronize page flips and/or rendering to
114 * involves filtering out spurious interrupts, keeping race-free blanking
115 * counters, coping with counter wrap-around and resets and keeping use counts.
133 * On many hardware disabling the vblank interrupt cannot be done in a race-free
139 * Drivers for hardware without support for vertical-blanking interrupts
166 MODULE_PARM_DESC(vblankoffdelay, "Delay until vblank irq auto-disable [msecs] (0: never disable, <0…
172 return &dev->vblank[pipe]; in drm_vblank_crtc()
178 return drm_vblank_crtc(crtc->dev, drm_crtc_index(crtc)); in drm_crtc_vblank_crtc()
188 assert_spin_locked(&dev->vblank_time_lock); in store_vblank()
190 vblank->last = last; in store_vblank()
192 write_seqlock(&vblank->seqlock); in store_vblank()
193 vblank->time = t_vblank; in store_vblank()
194 atomic64_add(vblank_count_inc, &vblank->count); in store_vblank()
195 write_sequnlock(&vblank->seqlock); in store_vblank()
202 return vblank->max_vblank_count ?: dev->max_vblank_count; in drm_max_vblank_count()
223 if (crtc->funcs->get_vblank_counter) in __get_vblank_counter()
224 return crtc->funcs->get_vblank_counter(crtc); in __get_vblank_counter()
246 spin_lock(&dev->vblank_time_lock); in drm_reset_vblank_timestamp()
255 } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); in drm_reset_vblank_timestamp()
258 * Only reinitialize corresponding vblank timestamp if high-precision query in drm_reset_vblank_timestamp()
271 spin_unlock(&dev->vblank_time_lock); in drm_reset_vblank_timestamp()
280 * Only necessary when going from off->on, to account for frames we
294 int framedur_ns = vblank->framedur_ns; in drm_update_vblank_count()
300 * NOTE! It's possible we lost a full dev->max_vblank_count + 1 events in drm_update_vblank_count()
312 } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); in drm_update_vblank_count()
316 diff = (cur_vblank - vblank->last) & max_vblank_count; in drm_update_vblank_count()
318 u64 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time)); in drm_update_vblank_count()
341 * Within a drm_vblank_pre_modeset - drm_vblank_post_modeset in drm_update_vblank_count()
349 if (diff > 1 && (vblank->inmodeset & 0x2)) { in drm_update_vblank_count()
352 " due to pre-modeset.\n", pipe, diff); in drm_update_vblank_count()
358 pipe, (unsigned long long)atomic64_read(&vblank->count), in drm_update_vblank_count()
359 diff, cur_vblank, vblank->last); in drm_update_vblank_count()
362 drm_WARN_ON_ONCE(dev, cur_vblank != vblank->last); in drm_update_vblank_count()
367 * Only reinitialize corresponding vblank timestamp if high-precision query in drm_update_vblank_count()
383 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_vblank_count()
386 count = atomic64_read(&vblank->count); in drm_vblank_count()
401 * drm_crtc_accurate_vblank_count - retrieve the master vblank counter
413 struct drm_device *dev = crtc->dev; in drm_crtc_accurate_vblank_count()
419 !crtc->funcs->get_vblank_timestamp, in drm_crtc_accurate_vblank_count()
422 spin_lock_irqsave(&dev->vblank_time_lock, flags); in drm_crtc_accurate_vblank_count()
427 spin_unlock_irqrestore(&dev->vblank_time_lock, flags); in drm_crtc_accurate_vblank_count()
441 if (crtc->funcs->disable_vblank) in __disable_vblank()
442 crtc->funcs->disable_vblank(crtc); in __disable_vblank()
457 assert_spin_locked(&dev->vbl_lock); in drm_vblank_disable_and_save()
463 spin_lock_irqsave(&dev->vblank_time_lock, irqflags); in drm_vblank_disable_and_save()
467 * interrupts were enabled. This avoids calling the ->disable_vblank() in drm_vblank_disable_and_save()
471 if (!vblank->enabled) in drm_vblank_disable_and_save()
482 vblank->enabled = false; in drm_vblank_disable_and_save()
485 spin_unlock_irqrestore(&dev->vblank_time_lock, irqflags); in drm_vblank_disable_and_save()
491 struct drm_device *dev = vblank->dev; in vblank_disable_fn()
492 unsigned int pipe = vblank->pipe; in vblank_disable_fn()
495 spin_lock_irqsave(&dev->vbl_lock, irqflags); in vblank_disable_fn()
496 if (atomic_read(&vblank->refcount) == 0 && vblank->enabled) { in vblank_disable_fn()
500 spin_unlock_irqrestore(&dev->vbl_lock, irqflags); in vblank_disable_fn()
507 drm_WARN_ON(dev, READ_ONCE(vblank->enabled) && in drm_vblank_init_release()
511 del_timer_sync(&vblank->disable_timer); in drm_vblank_init_release()
515 * drm_vblank_init - initialize vblank support
531 spin_lock_init(&dev->vbl_lock); in drm_vblank_init()
532 spin_lock_init(&dev->vblank_time_lock); in drm_vblank_init()
534 dev->vblank = drmm_kcalloc(dev, num_crtcs, sizeof(*dev->vblank), GFP_KERNEL); in drm_vblank_init()
535 if (!dev->vblank) in drm_vblank_init()
536 return -ENOMEM; in drm_vblank_init()
538 dev->num_crtcs = num_crtcs; in drm_vblank_init()
541 struct drm_vblank_crtc *vblank = &dev->vblank[i]; in drm_vblank_init()
543 vblank->dev = dev; in drm_vblank_init()
544 vblank->pipe = i; in drm_vblank_init()
545 init_waitqueue_head(&vblank->queue); in drm_vblank_init()
546 timer_setup(&vblank->disable_timer, vblank_disable_fn, 0); in drm_vblank_init()
547 seqlock_init(&vblank->seqlock); in drm_vblank_init()
564 * drm_dev_has_vblank - test if vblanking has been initialized for
581 return dev->num_crtcs != 0; in drm_dev_has_vblank()
586 * drm_crtc_vblank_waitqueue - get vblank waitqueue for the CRTC
595 return &crtc->dev->vblank[drm_crtc_index(crtc)].queue; in drm_crtc_vblank_waitqueue()
601 * drm_calc_timestamping_constants - calculate vblank timestamp constants
606 * swap-completion timestamping, e.g, by
614 struct drm_device *dev = crtc->dev; in drm_calc_timestamping_constants()
618 int dotclock = mode->crtc_clock; in drm_calc_timestamping_constants()
623 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_calc_timestamping_constants()
628 int frame_size = mode->crtc_htotal * mode->crtc_vtotal; in drm_calc_timestamping_constants()
632 * dot clock to line duration and frame duration in drm_calc_timestamping_constants()
635 linedur_ns = div_u64((u64) mode->crtc_htotal * 1000000, dotclock); in drm_calc_timestamping_constants()
641 if (mode->flags & DRM_MODE_FLAG_INTERLACE) in drm_calc_timestamping_constants()
645 crtc->base.id); in drm_calc_timestamping_constants()
648 vblank->linedur_ns = linedur_ns; in drm_calc_timestamping_constants()
649 vblank->framedur_ns = framedur_ns; in drm_calc_timestamping_constants()
650 drm_mode_copy(&vblank->hwmode, mode); in drm_calc_timestamping_constants()
654 crtc->base.id, mode->crtc_htotal, in drm_calc_timestamping_constants()
655 mode->crtc_vtotal, mode->crtc_vdisplay); in drm_calc_timestamping_constants()
656 drm_dbg_core(dev, "crtc %u: clock %d kHz framedur %d linedur %d\n", in drm_calc_timestamping_constants()
657 crtc->base.id, dotclock, framedur_ns, linedur_ns); in drm_calc_timestamping_constants()
662 * drm_crtc_vblank_helper_get_vblank_timestamp_internal - precise vblank
670 * need to apply some workarounds for gpu-specific vblank irq quirks
698 struct drm_device *dev = crtc->dev; in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
699 unsigned int pipe = crtc->index; in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
700 struct drm_vblank_crtc *vblank = &dev->vblank[pipe]; in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
708 if (pipe >= dev->num_crtcs) { in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
720 mode = &vblank->hwmode; in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
722 mode = &crtc->hwmode; in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
724 /* If mode timing undefined, just return as no-op: in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
727 if (mode->crtc_clock == 0) { in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
751 /* Return as no-op if scanout query unsupported or failed. */ in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
760 duration_ns = ktime_to_ns(etime) - ktime_to_ns(stime); in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
781 delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos), in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
782 mode->crtc_clock); in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
796 "crtc %u : v p(%d,%d)@ %lld.%06ld -> %lld.%06ld [e %d us, %d rep]\n", in drm_crtc_vblank_helper_get_vblank_timestamp_internal()
807 * drm_crtc_vblank_helper_get_vblank_timestamp - precise vblank timestamp
815 * need to apply some workarounds for gpu-specific vblank irq quirks
843 crtc->helper_private->get_scanout_position); in drm_crtc_vblank_helper_get_vblank_timestamp()
848 * drm_crtc_get_last_vbltimestamp - retrieve raw timestamp for the most
854 * need to apply some workarounds for gpu-specific vblank irq quirks
858 * vblank interval on specified CRTC. May call into kms-driver to
859 * compute the timestamp with a high-precision GPU specific method.
877 if (crtc && crtc->funcs->get_vblank_timestamp && max_error > 0) { in drm_crtc_get_last_vbltimestamp()
878 ret = crtc->funcs->get_vblank_timestamp(crtc, &max_error, in drm_crtc_get_last_vbltimestamp()
901 * drm_crtc_vblank_count - retrieve "cooked" vblank counter value
908 * drm_crtc_accurate_vblank_count() for such use-cases.
923 return drm_vblank_count(crtc->dev, drm_crtc_index(crtc)); in drm_crtc_vblank_count()
928 * drm_vblank_count_and_time - retrieve "cooked" vblank counter value and the
948 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) { in drm_vblank_count_and_time()
954 seq = read_seqbegin(&vblank->seqlock); in drm_vblank_count_and_time()
955 vblank_count = atomic64_read(&vblank->count); in drm_vblank_count_and_time()
956 *vblanktime = vblank->time; in drm_vblank_count_and_time()
957 } while (read_seqretry(&vblank->seqlock, seq)); in drm_vblank_count_and_time()
963 * drm_crtc_vblank_count_and_time - retrieve "cooked" vblank counter value
984 return drm_vblank_count_and_time(crtc->dev, drm_crtc_index(crtc), in drm_crtc_vblank_count_and_time()
990 * drm_crtc_next_vblank_start - calculate the time of the next vblank
994 * Calculate the expected time of the start of the next vblank period,
1003 if (!drm_dev_has_vblank(crtc->dev)) in drm_crtc_next_vblank_start()
1004 return -EINVAL; in drm_crtc_next_vblank_start()
1007 mode = &vblank->hwmode; in drm_crtc_next_vblank_start()
1009 if (!vblank->framedur_ns || !vblank->linedur_ns) in drm_crtc_next_vblank_start()
1010 return -EINVAL; in drm_crtc_next_vblank_start()
1013 return -EINVAL; in drm_crtc_next_vblank_start()
1016 (u64)vblank->framedur_ns * mode->crtc_vblank_start, in drm_crtc_next_vblank_start()
1017 mode->crtc_vtotal); in drm_crtc_next_vblank_start()
1030 switch (e->event.base.type) { in send_vblank_event()
1034 e->event.vbl.sequence = seq; in send_vblank_event()
1036 * e->event is a user space structure, with hardcoded unsigned in send_vblank_event()
1037 * 32-bit seconds/microseconds. This is safe as we always use in send_vblank_event()
1038 * monotonic timestamps since linux-4.15 in send_vblank_event()
1040 e->event.vbl.tv_sec = tv.tv_sec; in send_vblank_event()
1041 e->event.vbl.tv_usec = tv.tv_nsec / 1000; in send_vblank_event()
1045 e->event.seq.sequence = seq; in send_vblank_event()
1046 e->event.seq.time_ns = ktime_to_ns(now); in send_vblank_event()
1049 trace_drm_vblank_event_delivered(e->base.file_priv, e->pipe, seq); in send_vblank_event()
1054 * retire-fence timestamp to match exactly with HW vsync as it uses it in send_vblank_event()
1057 drm_send_event_timestamp_locked(dev, &e->base, now); in send_vblank_event()
1061 * drm_crtc_arm_vblank_event - arm vblank event after pageflip
1068 * period. This helper function implements exactly the required vblank arming
1077 * 1. Driver commits new hardware state into vblank-synchronized registers.
1101 struct drm_device *dev = crtc->dev; in drm_crtc_arm_vblank_event()
1104 assert_spin_locked(&dev->event_lock); in drm_crtc_arm_vblank_event()
1106 e->pipe = pipe; in drm_crtc_arm_vblank_event()
1107 e->sequence = drm_crtc_accurate_vblank_count(crtc) + 1; in drm_crtc_arm_vblank_event()
1108 list_add_tail(&e->base.link, &dev->vblank_event_list); in drm_crtc_arm_vblank_event()
1113 * drm_crtc_send_vblank_event - helper to send vblank event after pageflip
1126 struct drm_device *dev = crtc->dev; in drm_crtc_send_vblank_event()
1138 e->pipe = pipe; in drm_crtc_send_vblank_event()
1151 if (crtc->funcs->enable_vblank) in __enable_vblank()
1152 return crtc->funcs->enable_vblank(crtc); in __enable_vblank()
1155 return -EINVAL; in __enable_vblank()
1163 assert_spin_locked(&dev->vbl_lock); in drm_vblank_enable()
1165 spin_lock(&dev->vblank_time_lock); in drm_vblank_enable()
1167 if (!vblank->enabled) { in drm_vblank_enable()
1173 * prevent double-accounting of same vblank interval. in drm_vblank_enable()
1179 atomic_dec(&vblank->refcount); in drm_vblank_enable()
1187 WRITE_ONCE(vblank->enabled, true); in drm_vblank_enable()
1191 spin_unlock(&dev->vblank_time_lock); in drm_vblank_enable()
1203 return -EINVAL; in drm_vblank_get()
1205 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_vblank_get()
1206 return -EINVAL; in drm_vblank_get()
1208 spin_lock_irqsave(&dev->vbl_lock, irqflags); in drm_vblank_get()
1209 /* Going from 0->1 means we have to enable interrupts again */ in drm_vblank_get()
1210 if (atomic_add_return(1, &vblank->refcount) == 1) { in drm_vblank_get()
1213 if (!vblank->enabled) { in drm_vblank_get()
1214 atomic_dec(&vblank->refcount); in drm_vblank_get()
1215 ret = -EINVAL; in drm_vblank_get()
1218 spin_unlock_irqrestore(&dev->vbl_lock, irqflags); in drm_vblank_get()
1224 * drm_crtc_vblank_get - get a reference count on vblank events
1235 return drm_vblank_get(crtc->dev, drm_crtc_index(crtc)); in drm_crtc_vblank_get()
1242 int vblank_offdelay = vblank->config.offdelay_ms; in drm_vblank_put()
1244 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_vblank_put()
1247 if (drm_WARN_ON(dev, atomic_read(&vblank->refcount) == 0)) in drm_vblank_put()
1251 if (atomic_dec_and_test(&vblank->refcount)) { in drm_vblank_put()
1255 vblank_disable_fn(&vblank->disable_timer); in drm_vblank_put()
1256 else if (!vblank->config.disable_immediate) in drm_vblank_put()
1257 mod_timer(&vblank->disable_timer, in drm_vblank_put()
1263 * drm_crtc_vblank_put - give up ownership of vblank events
1272 drm_vblank_put(crtc->dev, drm_crtc_index(crtc)); in drm_crtc_vblank_put()
1277 * drm_wait_one_vblank - wait for one vblank
1293 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_wait_one_vblank()
1303 ret = wait_event_timeout(vblank->queue, in drm_wait_one_vblank()
1314 * drm_crtc_wait_one_vblank - wait for one vblank
1323 drm_wait_one_vblank(crtc->dev, drm_crtc_index(crtc)); in drm_crtc_wait_one_vblank()
1328 * drm_crtc_vblank_off - disable vblank events on a CRTC
1340 struct drm_device *dev = crtc->dev; in drm_crtc_vblank_off()
1347 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_crtc_vblank_off()
1354 spin_lock_irq(&dev->event_lock); in drm_crtc_vblank_off()
1356 spin_lock(&dev->vbl_lock); in drm_crtc_vblank_off()
1358 pipe, vblank->enabled, vblank->inmodeset); in drm_crtc_vblank_off()
1362 if (drm_core_check_feature(dev, DRIVER_ATOMIC) || !vblank->inmodeset) in drm_crtc_vblank_off()
1365 wake_up(&vblank->queue); in drm_crtc_vblank_off()
1368 * Prevent subsequent drm_vblank_get() from re-enabling in drm_crtc_vblank_off()
1371 if (!vblank->inmodeset) { in drm_crtc_vblank_off()
1372 atomic_inc(&vblank->refcount); in drm_crtc_vblank_off()
1373 vblank->inmodeset = 1; in drm_crtc_vblank_off()
1375 spin_unlock(&dev->vbl_lock); in drm_crtc_vblank_off()
1380 list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { in drm_crtc_vblank_off()
1381 if (e->pipe != pipe) in drm_crtc_vblank_off()
1385 e->sequence, seq); in drm_crtc_vblank_off()
1386 list_del(&e->base.link); in drm_crtc_vblank_off()
1394 spin_unlock_irq(&dev->event_lock); in drm_crtc_vblank_off()
1396 /* Will be reset by the modeset helpers when re-enabling the crtc by in drm_crtc_vblank_off()
1398 vblank->hwmode.crtc_clock = 0; in drm_crtc_vblank_off()
1406 * drm_crtc_vblank_reset - reset vblank state to off on a CRTC
1419 struct drm_device *dev = crtc->dev; in drm_crtc_vblank_reset()
1422 spin_lock_irq(&dev->vbl_lock); in drm_crtc_vblank_reset()
1427 if (!vblank->inmodeset) { in drm_crtc_vblank_reset()
1428 atomic_inc(&vblank->refcount); in drm_crtc_vblank_reset()
1429 vblank->inmodeset = 1; in drm_crtc_vblank_reset()
1431 spin_unlock_irq(&dev->vbl_lock); in drm_crtc_vblank_reset()
1433 drm_WARN_ON(dev, !list_empty(&dev->vblank_event_list)); in drm_crtc_vblank_reset()
1434 drm_WARN_ON(dev, !list_empty(&vblank->pending_work)); in drm_crtc_vblank_reset()
1439 * drm_crtc_set_max_vblank_count - configure the hw max vblank counter value
1451 * maximum can again be set to the appropriate non-zero value.
1458 struct drm_device *dev = crtc->dev; in drm_crtc_set_max_vblank_count()
1461 drm_WARN_ON(dev, dev->max_vblank_count); in drm_crtc_set_max_vblank_count()
1462 drm_WARN_ON(dev, !READ_ONCE(vblank->inmodeset)); in drm_crtc_set_max_vblank_count()
1464 vblank->max_vblank_count = max_vblank_count; in drm_crtc_set_max_vblank_count()
1469 * drm_crtc_vblank_on_config - enable vblank events on a CRTC with custom
1484 struct drm_device *dev = crtc->dev; in drm_crtc_vblank_on_config()
1488 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_crtc_vblank_on_config()
1491 spin_lock_irq(&dev->vbl_lock); in drm_crtc_vblank_on_config()
1493 pipe, vblank->enabled, vblank->inmodeset); in drm_crtc_vblank_on_config()
1495 vblank->config = *config; in drm_crtc_vblank_on_config()
1498 if (vblank->inmodeset) { in drm_crtc_vblank_on_config()
1499 atomic_dec(&vblank->refcount); in drm_crtc_vblank_on_config()
1500 vblank->inmodeset = 0; in drm_crtc_vblank_on_config()
1506 * re-enable interrupts if there are users left, or the in drm_crtc_vblank_on_config()
1509 if (atomic_read(&vblank->refcount) != 0 || !vblank->config.offdelay_ms) in drm_crtc_vblank_on_config()
1511 spin_unlock_irq(&dev->vbl_lock); in drm_crtc_vblank_on_config()
1516 * drm_crtc_vblank_on - enable vblank events on a CRTC
1531 .disable_immediate = crtc->dev->vblank_disable_immediate in drm_crtc_vblank_on()
1548 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_vblank_restore()
1551 assert_spin_locked(&dev->vbl_lock); in drm_vblank_restore()
1552 assert_spin_locked(&dev->vblank_time_lock); in drm_vblank_restore()
1556 drm_debug_enabled(DRM_UT_VBL) && !vblank->framedur_ns, in drm_vblank_restore()
1558 framedur_ns = vblank->framedur_ns; in drm_vblank_restore()
1563 } while (cur_vblank != __get_vblank_counter(dev, pipe) && --count > 0); in drm_vblank_restore()
1565 diff_ns = ktime_to_ns(ktime_sub(t_vblank, vblank->time)); in drm_vblank_restore()
1571 "missed %d vblanks in %lld ns, frame duration=%d ns, hw_diff=%d\n", in drm_vblank_restore()
1572 diff, diff_ns, framedur_ns, cur_vblank - vblank->last); in drm_vblank_restore()
1573 vblank->last = (cur_vblank - diff) & max_vblank_count; in drm_vblank_restore()
1577 * drm_crtc_vblank_restore - estimate missed vblanks and update vblank count.
1586 * Note that drivers must have race-free high-precision timestamping support,
1589 * time-stamping functions are race-free against vblank hardware counter
1594 struct drm_device *dev = crtc->dev; in drm_crtc_vblank_restore()
1598 drm_WARN_ON_ONCE(dev, !crtc->funcs->get_vblank_timestamp); in drm_crtc_vblank_restore()
1599 drm_WARN_ON_ONCE(dev, vblank->inmodeset); in drm_crtc_vblank_restore()
1600 drm_WARN_ON_ONCE(dev, !vblank->config.disable_immediate); in drm_crtc_vblank_restore()
1619 ret = -ENOMEM; in drm_queue_vblank_event()
1623 e->pipe = pipe; in drm_queue_vblank_event()
1624 e->event.base.type = DRM_EVENT_VBLANK; in drm_queue_vblank_event()
1625 e->event.base.length = sizeof(e->event.vbl); in drm_queue_vblank_event()
1626 e->event.vbl.user_data = vblwait->request.signal; in drm_queue_vblank_event()
1627 e->event.vbl.crtc_id = 0; in drm_queue_vblank_event()
1632 e->event.vbl.crtc_id = crtc->base.id; in drm_queue_vblank_event()
1635 spin_lock_irq(&dev->event_lock); in drm_queue_vblank_event()
1643 if (!READ_ONCE(vblank->enabled)) { in drm_queue_vblank_event()
1644 ret = -EINVAL; in drm_queue_vblank_event()
1648 ret = drm_event_reserve_init_locked(dev, file_priv, &e->base, in drm_queue_vblank_event()
1649 &e->event.base); in drm_queue_vblank_event()
1661 e->sequence = req_seq; in drm_queue_vblank_event()
1665 vblwait->reply.sequence = seq; in drm_queue_vblank_event()
1668 list_add_tail(&e->base.link, &dev->vblank_event_list); in drm_queue_vblank_event()
1669 vblwait->reply.sequence = req_seq; in drm_queue_vblank_event()
1672 spin_unlock_irq(&dev->event_lock); in drm_queue_vblank_event()
1677 spin_unlock_irq(&dev->event_lock); in drm_queue_vblank_event()
1686 if (vblwait->request.sequence) in drm_wait_vblank_is_query()
1690 (vblwait->request.type & (_DRM_VBLANK_TYPES_MASK | in drm_wait_vblank_is_query()
1696 * Widen a 32-bit param to 64-bits.
1698 * \param narrow 32-bit value (missing upper 32 bits)
1699 * \param near 64-bit value that should be 'close' to near
1701 * This function returns a 64-bit value using the lower 32-bits from
1702 * 'narrow' and constructing the upper 32-bits so that the result is
1708 return near + (s32) (narrow - near); in widen_32_to_64()
1720 * timestamps since linux-4.15. in drm_wait_vblank_reply()
1722 reply->sequence = drm_vblank_count_and_time(dev, pipe, &now); in drm_wait_vblank_reply()
1724 reply->tval_sec = (u32)ts.tv_sec; in drm_wait_vblank_reply()
1725 reply->tval_usec = ts.tv_nsec / 1000; in drm_wait_vblank_reply()
1745 return -EOPNOTSUPP; in drm_wait_vblank_ioctl()
1747 if (vblwait->request.type & _DRM_VBLANK_SIGNAL) in drm_wait_vblank_ioctl()
1748 return -EINVAL; in drm_wait_vblank_ioctl()
1750 if (vblwait->request.type & in drm_wait_vblank_ioctl()
1755 vblwait->request.type, in drm_wait_vblank_ioctl()
1758 return -EINVAL; in drm_wait_vblank_ioctl()
1761 flags = vblwait->request.type & _DRM_VBLANK_FLAGS_MASK; in drm_wait_vblank_ioctl()
1762 high_pipe = (vblwait->request.type & _DRM_VBLANK_HIGH_CRTC_MASK); in drm_wait_vblank_ioctl()
1768 /* Convert lease-relative crtc index into global crtc index */ in drm_wait_vblank_ioctl()
1772 if (drm_lease_held(file_priv, crtc->base.id)) { in drm_wait_vblank_ioctl()
1775 pipe_index--; in drm_wait_vblank_ioctl()
1783 if (pipe >= dev->num_crtcs) in drm_wait_vblank_ioctl()
1784 return -EINVAL; in drm_wait_vblank_ioctl()
1786 vblank = &dev->vblank[pipe]; in drm_wait_vblank_ioctl()
1788 /* If the counter is currently enabled and accurate, short-circuit in drm_wait_vblank_ioctl()
1791 if (vblank->config.disable_immediate && in drm_wait_vblank_ioctl()
1793 READ_ONCE(vblank->enabled)) { in drm_wait_vblank_ioctl()
1794 drm_wait_vblank_reply(dev, pipe, &vblwait->reply); in drm_wait_vblank_ioctl()
1807 switch (vblwait->request.type & _DRM_VBLANK_TYPES_MASK) { in drm_wait_vblank_ioctl()
1809 req_seq = seq + vblwait->request.sequence; in drm_wait_vblank_ioctl()
1810 vblwait->request.sequence = req_seq; in drm_wait_vblank_ioctl()
1811 vblwait->request.type &= ~_DRM_VBLANK_RELATIVE; in drm_wait_vblank_ioctl()
1814 req_seq = widen_32_to_64(vblwait->request.sequence, seq); in drm_wait_vblank_ioctl()
1817 ret = -EINVAL; in drm_wait_vblank_ioctl()
1824 vblwait->request.type &= ~_DRM_VBLANK_NEXTONMISS; in drm_wait_vblank_ioctl()
1825 vblwait->request.sequence = req_seq; in drm_wait_vblank_ioctl()
1829 /* must hold on to the vblank ref until the event fires in drm_wait_vblank_ioctl()
1840 wait = wait_event_interruptible_timeout(vblank->queue, in drm_wait_vblank_ioctl()
1842 !READ_ONCE(vblank->enabled), in drm_wait_vblank_ioctl()
1848 ret = -EBUSY; in drm_wait_vblank_ioctl()
1850 case -ERESTARTSYS: in drm_wait_vblank_ioctl()
1852 ret = -EINTR; in drm_wait_vblank_ioctl()
1860 if (ret != -EINTR) { in drm_wait_vblank_ioctl()
1861 drm_wait_vblank_reply(dev, pipe, &vblwait->reply); in drm_wait_vblank_ioctl()
1864 pipe, vblwait->reply.sequence); in drm_wait_vblank_ioctl()
1883 assert_spin_locked(&dev->event_lock); in drm_handle_vblank_events()
1887 list_for_each_entry_safe(e, t, &dev->vblank_event_list, base.link) { in drm_handle_vblank_events()
1888 if (e->pipe != pipe) in drm_handle_vblank_events()
1890 if (!drm_vblank_passed(seq, e->sequence)) in drm_handle_vblank_events()
1894 e->sequence, seq); in drm_handle_vblank_events()
1896 list_del(&e->base.link); in drm_handle_vblank_events()
1901 if (crtc && crtc->funcs->get_vblank_timestamp) in drm_handle_vblank_events()
1908 * drm_handle_vblank - handle a vblank event
1926 if (drm_WARN_ON(dev, pipe >= dev->num_crtcs)) in drm_handle_vblank()
1929 spin_lock_irqsave(&dev->event_lock, irqflags); in drm_handle_vblank()
1935 spin_lock(&dev->vblank_time_lock); in drm_handle_vblank()
1938 if (!vblank->enabled) { in drm_handle_vblank()
1939 spin_unlock(&dev->vblank_time_lock); in drm_handle_vblank()
1940 spin_unlock_irqrestore(&dev->event_lock, irqflags); in drm_handle_vblank()
1946 spin_unlock(&dev->vblank_time_lock); in drm_handle_vblank()
1948 wake_up(&vblank->queue); in drm_handle_vblank()
1950 /* With instant-off, we defer disabling the interrupt until after in drm_handle_vblank()
1955 disable_irq = (vblank->config.disable_immediate && in drm_handle_vblank()
1956 vblank->config.offdelay_ms > 0 && in drm_handle_vblank()
1957 !atomic_read(&vblank->refcount)); in drm_handle_vblank()
1962 spin_unlock_irqrestore(&dev->event_lock, irqflags); in drm_handle_vblank()
1965 vblank_disable_fn(&vblank->disable_timer); in drm_handle_vblank()
1972 * drm_crtc_handle_vblank - handle a vblank event
1993 return drm_handle_vblank(crtc->dev, drm_crtc_index(crtc)); in drm_crtc_handle_vblank()
2017 return -EOPNOTSUPP; in drm_crtc_get_sequence_ioctl()
2020 return -EOPNOTSUPP; in drm_crtc_get_sequence_ioctl()
2022 crtc = drm_crtc_find(dev, file_priv, get_seq->crtc_id); in drm_crtc_get_sequence_ioctl()
2024 return -ENOENT; in drm_crtc_get_sequence_ioctl()
2029 vblank_enabled = READ_ONCE(vblank->config.disable_immediate) && in drm_crtc_get_sequence_ioctl()
2030 READ_ONCE(vblank->enabled); in drm_crtc_get_sequence_ioctl()
2041 drm_modeset_lock(&crtc->mutex, NULL); in drm_crtc_get_sequence_ioctl()
2042 if (crtc->state) in drm_crtc_get_sequence_ioctl()
2043 get_seq->active = crtc->state->enable; in drm_crtc_get_sequence_ioctl()
2045 get_seq->active = crtc->enabled; in drm_crtc_get_sequence_ioctl()
2046 drm_modeset_unlock(&crtc->mutex); in drm_crtc_get_sequence_ioctl()
2047 get_seq->sequence = drm_vblank_count_and_time(dev, pipe, &now); in drm_crtc_get_sequence_ioctl()
2048 get_seq->sequence_ns = ktime_to_ns(now); in drm_crtc_get_sequence_ioctl()
2077 return -EOPNOTSUPP; in drm_crtc_queue_sequence_ioctl()
2080 return -EOPNOTSUPP; in drm_crtc_queue_sequence_ioctl()
2082 crtc = drm_crtc_find(dev, file_priv, queue_seq->crtc_id); in drm_crtc_queue_sequence_ioctl()
2084 return -ENOENT; in drm_crtc_queue_sequence_ioctl()
2086 flags = queue_seq->flags; in drm_crtc_queue_sequence_ioctl()
2090 return -EINVAL; in drm_crtc_queue_sequence_ioctl()
2098 return -ENOMEM; in drm_crtc_queue_sequence_ioctl()
2109 req_seq = queue_seq->sequence; in drm_crtc_queue_sequence_ioctl()
2117 e->pipe = pipe; in drm_crtc_queue_sequence_ioctl()
2118 e->event.base.type = DRM_EVENT_CRTC_SEQUENCE; in drm_crtc_queue_sequence_ioctl()
2119 e->event.base.length = sizeof(e->event.seq); in drm_crtc_queue_sequence_ioctl()
2120 e->event.seq.user_data = queue_seq->user_data; in drm_crtc_queue_sequence_ioctl()
2122 spin_lock_irq(&dev->event_lock); in drm_crtc_queue_sequence_ioctl()
2130 if (!READ_ONCE(vblank->enabled)) { in drm_crtc_queue_sequence_ioctl()
2131 ret = -EINVAL; in drm_crtc_queue_sequence_ioctl()
2135 ret = drm_event_reserve_init_locked(dev, file_priv, &e->base, in drm_crtc_queue_sequence_ioctl()
2136 &e->event.base); in drm_crtc_queue_sequence_ioctl()
2141 e->sequence = req_seq; in drm_crtc_queue_sequence_ioctl()
2146 queue_seq->sequence = seq; in drm_crtc_queue_sequence_ioctl()
2149 list_add_tail(&e->base.link, &dev->vblank_event_list); in drm_crtc_queue_sequence_ioctl()
2150 queue_seq->sequence = req_seq; in drm_crtc_queue_sequence_ioctl()
2153 spin_unlock_irq(&dev->event_lock); in drm_crtc_queue_sequence_ioctl()
2157 spin_unlock_irq(&dev->event_lock); in drm_crtc_queue_sequence_ioctl()