drivers/gpu/drm/drm_vblank.c
Source file repositories/reference/linux-study-clean/drivers/gpu/drm/drm_vblank.c
File Facts
- System
- Linux kernel
- Corpus path
drivers/gpu/drm/drm_vblank.c- Extension
.c- Size
- 74643 bytes
- Lines
- 2327
- Domain
- Driver Families
- Bucket
- drivers/gpu
- Inferred role
- Driver Families: exported/initcall integration point
- Status
- integration implementation candidate
Why This File Exists
Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Repeatable hardware-adapter layer. Deep compatibility for every driver is out of scope; this atlas records patterns, probe lifecycles, bus glue, IRQ/DMA usage, and links back to core abstractions.
- Exports symbols or registers init work; inspect boot/module ordering and who consumes the exported contract.
- Uses kernel synchronization; read lock ordering, sleepability, and interrupt context assumptions before translating.
- Allocates kernel memory; connect allocation flags and lifetime to context constraints.
- Defines or uses C structs; map object ownership, embedded links, reference counts, and lock ownership.
Dependency Surface
linux/export.hlinux/kthread.hlinux/moduleparam.hdrm/drm_crtc.hdrm/drm_drv.hdrm/drm_framebuffer.hdrm/drm_managed.hdrm/drm_modeset_helper_vtables.hdrm/drm_print.hdrm/drm_vblank.hdrm_internal.hdrm_trace.h
Detected Declarations
function drm_vblank_crtcfunction drm_crtc_vblank_crtcfunction store_vblankfunction drm_max_vblank_countfunction drm_vblank_no_hw_counterfunction __get_vblank_counterfunction get_vblank_counter_and_timestampfunction drm_crtc_vblank_onfunction drm_update_vblank_countfunction drm_vblank_countfunction drm_crtc_vblank_countfunction __disable_vblankfunction drm_vblank_disable_and_savefunction vblank_disable_fnfunction drm_vblank_init_releasefunction drmm_add_action_or_resetfunction drm_dev_has_vblankfunction wait_eventfunction drm_crtc_vblank_helper_get_vblank_timestampfunction drm_crtc_handle_vblankfunction drm_crtc_handle_vblankfunction drm_crtc_handle_vblankfunction drm_get_last_vbltimestampfunction interruptfunction drm_crtc_vblank_count_and_timefunction drm_crtc_handle_vblankfunction drm_crtc_next_vblank_startfunction send_vblank_eventfunction drm_crtc_arm_vblank_eventfunction drm_crtc_arm_vblank_eventfunction __enable_vblankfunction drm_vblank_enablefunction drm_vblank_getfunction drm_crtc_vblank_getfunction drm_vblank_putfunction drm_crtc_vblank_putfunction drm_crtc_wait_one_vblankfunction drm_crtc_vblank_offfunction drm_vblank_getfunction list_for_each_entry_safefunction drm_crtc_vblank_offfunction drm_vblank_getfunction drm_crtc_set_max_vblank_countfunction drm_crtc_vblank_onfunction drm_crtc_vblank_offfunction drm_vblank_restorefunction drm_crtc_vblank_restorefunction drm_queue_vblank_event
Annotated Snippet
if (!vbl_status) {
drm_dbg_core(dev,
"crtc %u : scanoutpos query failed.\n",
pipe);
return false;
}
/* Compute uncertainty in timestamp of scanout position query. */
duration_ns = ktime_to_ns(etime) - ktime_to_ns(stime);
/* Accept result with < max_error nsecs timing uncertainty. */
if (duration_ns <= *max_error)
break;
}
/* Noisy system timing? */
if (i == DRM_TIMESTAMP_MAXRETRIES) {
drm_dbg_core(dev,
"crtc %u: Noisy timestamp %d us > %d us [%d reps].\n",
pipe, duration_ns / 1000, *max_error / 1000, i);
}
/* Return upper bound of timestamp precision error. */
*max_error = duration_ns;
/* Convert scanout position into elapsed time at raw_time query
* since start of scanout at first display scanline. delta_ns
* can be negative if start of scanout hasn't happened yet.
*/
delta_ns = div_s64(1000000LL * (vpos * mode->crtc_htotal + hpos),
mode->crtc_clock);
/* Subtract time delta from raw timestamp to get final
* vblank_time timestamp for end of vblank.
*/
*vblank_time = ktime_sub_ns(etime, delta_ns);
if (!drm_debug_enabled(DRM_UT_VBL))
return true;
ts_etime = ktime_to_timespec64(etime);
ts_vblank_time = ktime_to_timespec64(*vblank_time);
drm_dbg_vbl(dev,
"crtc %u : v p(%d,%d)@ %ptSp -> %ptSp [e %d us, %d rep]\n",
pipe, hpos, vpos, &ts_etime, &ts_vblank_time,
duration_ns / 1000, i);
return true;
}
EXPORT_SYMBOL(drm_crtc_vblank_helper_get_vblank_timestamp_internal);
/**
* drm_crtc_vblank_helper_get_vblank_timestamp - precise vblank timestamp
* helper
* @crtc: CRTC whose vblank timestamp to retrieve
* @max_error: Desired maximum allowable error in timestamps (nanosecs)
* On return contains true maximum error of timestamp
* @vblank_time: Pointer to time which should receive the timestamp
* @in_vblank_irq:
* True when called from drm_crtc_handle_vblank(). Some drivers
* need to apply some workarounds for gpu-specific vblank irq quirks
* if flag is set.
*
* Implements calculation of exact vblank timestamps from given drm_display_mode
* timings and current video scanout position of a CRTC. This can be directly
* used as the &drm_crtc_funcs.get_vblank_timestamp implementation of a kms
* driver if &drm_crtc_helper_funcs.get_scanout_position is implemented.
*
* The current implementation only handles standard video modes. For double scan
* and interlaced modes the driver is supposed to adjust the hardware mode
* (taken from &drm_crtc_state.adjusted mode for atomic modeset drivers) to
* match the scanout position reported.
*
* Note that atomic drivers must call drm_calc_timestamping_constants() before
* enabling a CRTC. The atomic helpers already take care of that in
* drm_atomic_helper_calc_timestamping_constants().
*
* Returns:
* Returns true on success, and false on failure, i.e. when no accurate
* timestamp could be acquired.
*/
bool drm_crtc_vblank_helper_get_vblank_timestamp(struct drm_crtc *crtc,
int *max_error,
ktime_t *vblank_time,
bool in_vblank_irq)
{
return drm_crtc_vblank_helper_get_vblank_timestamp_internal(
crtc, max_error, vblank_time, in_vblank_irq,
crtc->helper_private->get_scanout_position);
Annotation
- Immediate include surface: `linux/export.h`, `linux/kthread.h`, `linux/moduleparam.h`, `drm/drm_crtc.h`, `drm/drm_drv.h`, `drm/drm_framebuffer.h`, `drm/drm_managed.h`, `drm/drm_modeset_helper_vtables.h`.
- Detected declarations: `function drm_vblank_crtc`, `function drm_crtc_vblank_crtc`, `function store_vblank`, `function drm_max_vblank_count`, `function drm_vblank_no_hw_counter`, `function __get_vblank_counter`, `function get_vblank_counter_and_timestamp`, `function drm_crtc_vblank_on`, `function drm_update_vblank_count`, `function drm_vblank_count`.
- Atlas domain: Driver Families / drivers/gpu.
- Implementation status: integration implementation candidate.
- Synchronization appears in or near this file; preserve lock ordering, sleepability, and interrupt-context constraints.
Implementation Notes
- This generated page is the file-by-file coverage layer; curated subsystem chapters should link here when they synthesize a multi-file control flow.
- Core OS pages should be promoted from atlas-only to deep-reviewed when they explain data structures, invariants, locking, lifecycle, and C implementation snippets.
- Driver-family pages are intentionally pattern-oriented unless they are part of the selected PCIe/NVMe representative device path.