VBlank event handling

The DRM core exposes two vertical blank related ioctls: DRM_IOCTL_WAIT_VBLANK and DRM_IOCTL_MODESET_CTL.

DRM_IOCTL_WAIT_VBLANK takes a struct drm_wait_vblank structure as its argument, and is used to block or request a signal when a specified vblank event occurs.

DRM_IOCTL_MODESET_CTL should be called by application level drivers before and after mode setting, since on many devices the vertical blank counter will be reset at that time. Internally, the DRM snapshots the last vblank count when the ioctl is called with the _DRM_PRE_MODESET command so that the counter won't go backwards (which is dealt with when _DRM_POST_MODESET is used).

To support the functions above, the DRM core provides several helper functions for tracking vertical blank counters, and requires drivers to provide several callbacks: get_vblank_counter(), enable_vblank() and disable_vblank(). The core uses get_vblank_counter() to keep the counter accurate across interrupt disable periods. It should return the current vertical blank event count, which is often tracked in a device register. The enable and disable vblank callbacks should enable and disable vertical blank interrupts, respectively. In the absence of DRM clients waiting on vblank events, the core DRM code will use the disable_vblank() function to disable interrupts, which saves power. They'll be re-enabled again when a client calls the vblank wait ioctl above.

Devices that don't provide a count register can simply use an internal atomic counter incremented on every vertical blank interrupt, and can make their enable and disable vblank functions into no-ops.