Merge tag 'drm/tegra/for-4.8-rc1' of git://anongit.freedesktop.org/tegra/linux into...
[cascardo/linux.git] / Documentation / gpu / drm-kms.rst
1 =========================
2 Kernel Mode Setting (KMS)
3 =========================
4
5 Mode Setting
6 ============
7
8 Drivers must initialize the mode setting core by calling
9 :c:func:`drm_mode_config_init()` on the DRM device. The function
10 initializes the :c:type:`struct drm_device <drm_device>`
11 mode_config field and never fails. Once done, mode configuration must
12 be setup by initializing the following fields.
13
14 -  int min_width, min_height; int max_width, max_height;
15    Minimum and maximum width and height of the frame buffers in pixel
16    units.
17
18 -  struct drm_mode_config_funcs \*funcs;
19    Mode setting functions.
20
21 Display Modes Function Reference
22 --------------------------------
23
24 .. kernel-doc:: include/drm/drm_modes.h
25    :internal:
26
27 .. kernel-doc:: drivers/gpu/drm/drm_modes.c
28    :export:
29
30 Atomic Mode Setting Function Reference
31 --------------------------------------
32
33 .. kernel-doc:: drivers/gpu/drm/drm_atomic.c
34    :export:
35
36 .. kernel-doc:: drivers/gpu/drm/drm_atomic.c
37    :internal:
38
39 Frame Buffer Abstraction
40 ------------------------
41
42 Frame buffers are abstract memory objects that provide a source of
43 pixels to scanout to a CRTC. Applications explicitly request the
44 creation of frame buffers through the DRM_IOCTL_MODE_ADDFB(2) ioctls
45 and receive an opaque handle that can be passed to the KMS CRTC control,
46 plane configuration and page flip functions.
47
48 Frame buffers rely on the underneath memory manager for low-level memory
49 operations. When creating a frame buffer applications pass a memory
50 handle (or a list of memory handles for multi-planar formats) through
51 the ``drm_mode_fb_cmd2`` argument. For drivers using GEM as their
52 userspace buffer management interface this would be a GEM handle.
53 Drivers are however free to use their own backing storage object
54 handles, e.g. vmwgfx directly exposes special TTM handles to userspace
55 and so expects TTM handles in the create ioctl and not GEM handles.
56
57 The lifetime of a drm framebuffer is controlled with a reference count,
58 drivers can grab additional references with
59 :c:func:`drm_framebuffer_reference()`and drop them again with
60 :c:func:`drm_framebuffer_unreference()`. For driver-private
61 framebuffers for which the last reference is never dropped (e.g. for the
62 fbdev framebuffer when the struct :c:type:`struct drm_framebuffer
63 <drm_framebuffer>` is embedded into the fbdev helper struct)
64 drivers can manually clean up a framebuffer at module unload time with
65 :c:func:`drm_framebuffer_unregister_private()`.
66
67 DRM Format Handling
68 -------------------
69
70 .. kernel-doc:: include/drm/drm_fourcc.h
71    :internal:
72
73 .. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
74    :export:
75
76 Dumb Buffer Objects
77 -------------------
78
79 The KMS API doesn't standardize backing storage object creation and
80 leaves it to driver-specific ioctls. Furthermore actually creating a
81 buffer object even for GEM-based drivers is done through a
82 driver-specific ioctl - GEM only has a common userspace interface for
83 sharing and destroying objects. While not an issue for full-fledged
84 graphics stacks that include device-specific userspace components (in
85 libdrm for instance), this limit makes DRM-based early boot graphics
86 unnecessarily complex.
87
88 Dumb objects partly alleviate the problem by providing a standard API to
89 create dumb buffers suitable for scanout, which can then be used to
90 create KMS frame buffers.
91
92 To support dumb objects drivers must implement the dumb_create,
93 dumb_destroy and dumb_map_offset operations.
94
95 -  int (\*dumb_create)(struct drm_file \*file_priv, struct
96    drm_device \*dev, struct drm_mode_create_dumb \*args);
97    The dumb_create operation creates a driver object (GEM or TTM
98    handle) suitable for scanout based on the width, height and depth
99    from the struct :c:type:`struct drm_mode_create_dumb
100    <drm_mode_create_dumb>` argument. It fills the argument's
101    handle, pitch and size fields with a handle for the newly created
102    object and its line pitch and size in bytes.
103
104 -  int (\*dumb_destroy)(struct drm_file \*file_priv, struct
105    drm_device \*dev, uint32_t handle);
106    The dumb_destroy operation destroys a dumb object created by
107    dumb_create.
108
109 -  int (\*dumb_map_offset)(struct drm_file \*file_priv, struct
110    drm_device \*dev, uint32_t handle, uint64_t \*offset);
111    The dumb_map_offset operation associates an mmap fake offset with
112    the object given by the handle and returns it. Drivers must use the
113    :c:func:`drm_gem_create_mmap_offset()` function to associate
114    the fake offset as described in ?.
115
116 Note that dumb objects may not be used for gpu acceleration, as has been
117 attempted on some ARM embedded platforms. Such drivers really must have
118 a hardware-specific ioctl to allocate suitable buffer objects.
119
120 Output Polling
121 --------------
122
123 void (\*output_poll_changed)(struct drm_device \*dev);
124 This operation notifies the driver that the status of one or more
125 connectors has changed. Drivers that use the fb helper can just call the
126 :c:func:`drm_fb_helper_hotplug_event()` function to handle this
127 operation.
128
129 KMS Initialization and Cleanup
130 ==============================
131
132 A KMS device is abstracted and exposed as a set of planes, CRTCs,
133 encoders and connectors. KMS drivers must thus create and initialize all
134 those objects at load time after initializing mode setting.
135
136 CRTCs (:c:type:`struct drm_crtc <drm_crtc>`)
137 --------------------------------------------
138
139 A CRTC is an abstraction representing a part of the chip that contains a
140 pointer to a scanout buffer. Therefore, the number of CRTCs available
141 determines how many independent scanout buffers can be active at any
142 given time. The CRTC structure contains several fields to support this:
143 a pointer to some video memory (abstracted as a frame buffer object), a
144 display mode, and an (x, y) offset into the video memory to support
145 panning or configurations where one piece of video memory spans multiple
146 CRTCs.
147
148 CRTC Initialization
149 ~~~~~~~~~~~~~~~~~~~
150
151 A KMS device must create and register at least one struct
152 :c:type:`struct drm_crtc <drm_crtc>` instance. The instance is
153 allocated and zeroed by the driver, possibly as part of a larger
154 structure, and registered with a call to :c:func:`drm_crtc_init()`
155 with a pointer to CRTC functions.
156
157 Planes (:c:type:`struct drm_plane <drm_plane>`)
158 -----------------------------------------------
159
160 A plane represents an image source that can be blended with or overlayed
161 on top of a CRTC during the scanout process. Planes are associated with
162 a frame buffer to crop a portion of the image memory (source) and
163 optionally scale it to a destination size. The result is then blended
164 with or overlayed on top of a CRTC.
165
166 The DRM core recognizes three types of planes:
167
168 -  DRM_PLANE_TYPE_PRIMARY represents a "main" plane for a CRTC.
169    Primary planes are the planes operated upon by CRTC modesetting and
170    flipping operations described in the page_flip hook in
171    :c:type:`struct drm_crtc_funcs <drm_crtc_funcs>`.
172 -  DRM_PLANE_TYPE_CURSOR represents a "cursor" plane for a CRTC.
173    Cursor planes are the planes operated upon by the
174    DRM_IOCTL_MODE_CURSOR and DRM_IOCTL_MODE_CURSOR2 ioctls.
175 -  DRM_PLANE_TYPE_OVERLAY represents all non-primary, non-cursor
176    planes. Some drivers refer to these types of planes as "sprites"
177    internally.
178
179 For compatibility with legacy userspace, only overlay planes are made
180 available to userspace by default. Userspace clients may set the
181 DRM_CLIENT_CAP_UNIVERSAL_PLANES client capability bit to indicate
182 that they wish to receive a universal plane list containing all plane
183 types.
184
185 Plane Initialization
186 ~~~~~~~~~~~~~~~~~~~~
187
188 To create a plane, a KMS drivers allocates and zeroes an instances of
189 :c:type:`struct drm_plane <drm_plane>` (possibly as part of a
190 larger structure) and registers it with a call to
191 :c:func:`drm_universal_plane_init()`. The function takes a
192 bitmask of the CRTCs that can be associated with the plane, a pointer to
193 the plane functions, a list of format supported formats, and the type of
194 plane (primary, cursor, or overlay) being initialized.
195
196 Cursor and overlay planes are optional. All drivers should provide one
197 primary plane per CRTC (although this requirement may change in the
198 future); drivers that do not wish to provide special handling for
199 primary planes may make use of the helper functions described in ? to
200 create and register a primary plane with standard capabilities.
201
202 Encoders (:c:type:`struct drm_encoder <drm_encoder>`)
203 -----------------------------------------------------
204
205 An encoder takes pixel data from a CRTC and converts it to a format
206 suitable for any attached connectors. On some devices, it may be
207 possible to have a CRTC send data to more than one encoder. In that
208 case, both encoders would receive data from the same scanout buffer,
209 resulting in a "cloned" display configuration across the connectors
210 attached to each encoder.
211
212 Encoder Initialization
213 ~~~~~~~~~~~~~~~~~~~~~~
214
215 As for CRTCs, a KMS driver must create, initialize and register at least
216 one :c:type:`struct drm_encoder <drm_encoder>` instance. The
217 instance is allocated and zeroed by the driver, possibly as part of a
218 larger structure.
219
220 Drivers must initialize the :c:type:`struct drm_encoder
221 <drm_encoder>` possible_crtcs and possible_clones fields before
222 registering the encoder. Both fields are bitmasks of respectively the
223 CRTCs that the encoder can be connected to, and sibling encoders
224 candidate for cloning.
225
226 After being initialized, the encoder must be registered with a call to
227 :c:func:`drm_encoder_init()`. The function takes a pointer to the
228 encoder functions and an encoder type. Supported types are
229
230 -  DRM_MODE_ENCODER_DAC for VGA and analog on DVI-I/DVI-A
231 -  DRM_MODE_ENCODER_TMDS for DVI, HDMI and (embedded) DisplayPort
232 -  DRM_MODE_ENCODER_LVDS for display panels
233 -  DRM_MODE_ENCODER_TVDAC for TV output (Composite, S-Video,
234    Component, SCART)
235 -  DRM_MODE_ENCODER_VIRTUAL for virtual machine displays
236
237 Encoders must be attached to a CRTC to be used. DRM drivers leave
238 encoders unattached at initialization time. Applications (or the fbdev
239 compatibility layer when implemented) are responsible for attaching the
240 encoders they want to use to a CRTC.
241
242 Connectors (:c:type:`struct drm_connector <drm_connector>`)
243 -----------------------------------------------------------
244
245 A connector is the final destination for pixel data on a device, and
246 usually connects directly to an external display device like a monitor
247 or laptop panel. A connector can only be attached to one encoder at a
248 time. The connector is also the structure where information about the
249 attached display is kept, so it contains fields for display data, EDID
250 data, DPMS & connection status, and information about modes supported on
251 the attached displays.
252
253 Connector Initialization
254 ~~~~~~~~~~~~~~~~~~~~~~~~
255
256 Finally a KMS driver must create, initialize, register and attach at
257 least one :c:type:`struct drm_connector <drm_connector>`
258 instance. The instance is created as other KMS objects and initialized
259 by setting the following fields.
260
261 interlace_allowed
262     Whether the connector can handle interlaced modes.
263
264 doublescan_allowed
265     Whether the connector can handle doublescan.
266
267 display_info
268     Display information is filled from EDID information when a display
269     is detected. For non hot-pluggable displays such as flat panels in
270     embedded systems, the driver should initialize the
271     display_info.width_mm and display_info.height_mm fields with the
272     physical size of the display.
273
274 polled
275     Connector polling mode, a combination of
276
277     DRM_CONNECTOR_POLL_HPD
278         The connector generates hotplug events and doesn't need to be
279         periodically polled. The CONNECT and DISCONNECT flags must not
280         be set together with the HPD flag.
281
282     DRM_CONNECTOR_POLL_CONNECT
283         Periodically poll the connector for connection.
284
285     DRM_CONNECTOR_POLL_DISCONNECT
286         Periodically poll the connector for disconnection.
287
288     Set to 0 for connectors that don't support connection status
289     discovery.
290
291 The connector is then registered with a call to
292 :c:func:`drm_connector_init()` with a pointer to the connector
293 functions and a connector type, and exposed through sysfs with a call to
294 :c:func:`drm_connector_register()`.
295
296 Supported connector types are
297
298 -  DRM_MODE_CONNECTOR_VGA
299 -  DRM_MODE_CONNECTOR_DVII
300 -  DRM_MODE_CONNECTOR_DVID
301 -  DRM_MODE_CONNECTOR_DVIA
302 -  DRM_MODE_CONNECTOR_Composite
303 -  DRM_MODE_CONNECTOR_SVIDEO
304 -  DRM_MODE_CONNECTOR_LVDS
305 -  DRM_MODE_CONNECTOR_Component
306 -  DRM_MODE_CONNECTOR_9PinDIN
307 -  DRM_MODE_CONNECTOR_DisplayPort
308 -  DRM_MODE_CONNECTOR_HDMIA
309 -  DRM_MODE_CONNECTOR_HDMIB
310 -  DRM_MODE_CONNECTOR_TV
311 -  DRM_MODE_CONNECTOR_eDP
312 -  DRM_MODE_CONNECTOR_VIRTUAL
313
314 Connectors must be attached to an encoder to be used. For devices that
315 map connectors to encoders 1:1, the connector should be attached at
316 initialization time with a call to
317 :c:func:`drm_mode_connector_attach_encoder()`. The driver must
318 also set the :c:type:`struct drm_connector <drm_connector>`
319 encoder field to point to the attached encoder.
320
321 Finally, drivers must initialize the connectors state change detection
322 with a call to :c:func:`drm_kms_helper_poll_init()`. If at least
323 one connector is pollable but can't generate hotplug interrupts
324 (indicated by the DRM_CONNECTOR_POLL_CONNECT and
325 DRM_CONNECTOR_POLL_DISCONNECT connector flags), a delayed work will
326 automatically be queued to periodically poll for changes. Connectors
327 that can generate hotplug interrupts must be marked with the
328 DRM_CONNECTOR_POLL_HPD flag instead, and their interrupt handler must
329 call :c:func:`drm_helper_hpd_irq_event()`. The function will
330 queue a delayed work to check the state of all connectors, but no
331 periodic polling will be done.
332
333 Connector Operations
334 ~~~~~~~~~~~~~~~~~~~~
335
336     **Note**
337
338     Unless otherwise state, all operations are mandatory.
339
340 DPMS
341 ''''
342
343 void (\*dpms)(struct drm_connector \*connector, int mode);
344 The DPMS operation sets the power state of a connector. The mode
345 argument is one of
346
347 -  DRM_MODE_DPMS_ON
348
349 -  DRM_MODE_DPMS_STANDBY
350
351 -  DRM_MODE_DPMS_SUSPEND
352
353 -  DRM_MODE_DPMS_OFF
354
355 In all but DPMS_ON mode the encoder to which the connector is attached
356 should put the display in low-power mode by driving its signals
357 appropriately. If more than one connector is attached to the encoder
358 care should be taken not to change the power state of other displays as
359 a side effect. Low-power mode should be propagated to the encoders and
360 CRTCs when all related connectors are put in low-power mode.
361
362 Modes
363 '''''
364
365 int (\*fill_modes)(struct drm_connector \*connector, uint32_t
366 max_width, uint32_t max_height);
367 Fill the mode list with all supported modes for the connector. If the
368 ``max_width`` and ``max_height`` arguments are non-zero, the
369 implementation must ignore all modes wider than ``max_width`` or higher
370 than ``max_height``.
371
372 The connector must also fill in this operation its display_info
373 width_mm and height_mm fields with the connected display physical size
374 in millimeters. The fields should be set to 0 if the value isn't known
375 or is not applicable (for instance for projector devices).
376
377 Connection Status
378 '''''''''''''''''
379
380 The connection status is updated through polling or hotplug events when
381 supported (see ?). The status value is reported to userspace through
382 ioctls and must not be used inside the driver, as it only gets
383 initialized by a call to :c:func:`drm_mode_getconnector()` from
384 userspace.
385
386 enum drm_connector_status (\*detect)(struct drm_connector
387 \*connector, bool force);
388 Check to see if anything is attached to the connector. The ``force``
389 parameter is set to false whilst polling or to true when checking the
390 connector due to user request. ``force`` can be used by the driver to
391 avoid expensive, destructive operations during automated probing.
392
393 Return connector_status_connected if something is connected to the
394 connector, connector_status_disconnected if nothing is connected and
395 connector_status_unknown if the connection state isn't known.
396
397 Drivers should only return connector_status_connected if the
398 connection status has really been probed as connected. Connectors that
399 can't detect the connection status, or failed connection status probes,
400 should return connector_status_unknown.
401
402 Cleanup
403 -------
404
405 The DRM core manages its objects' lifetime. When an object is not needed
406 anymore the core calls its destroy function, which must clean up and
407 free every resource allocated for the object. Every
408 :c:func:`drm_\*_init()` call must be matched with a corresponding
409 :c:func:`drm_\*_cleanup()` call to cleanup CRTCs
410 (:c:func:`drm_crtc_cleanup()`), planes
411 (:c:func:`drm_plane_cleanup()`), encoders
412 (:c:func:`drm_encoder_cleanup()`) and connectors
413 (:c:func:`drm_connector_cleanup()`). Furthermore, connectors that
414 have been added to sysfs must be removed by a call to
415 :c:func:`drm_connector_unregister()` before calling
416 :c:func:`drm_connector_cleanup()`.
417
418 Connectors state change detection must be cleanup up with a call to
419 :c:func:`drm_kms_helper_poll_fini()`.
420
421 Output discovery and initialization example
422 -------------------------------------------
423
424 ::
425
426     void intel_crt_init(struct drm_device *dev)
427     {
428         struct drm_connector *connector;
429         struct intel_output *intel_output;
430
431         intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
432         if (!intel_output)
433             return;
434
435         connector = &intel_output->base;
436         drm_connector_init(dev, &intel_output->base,
437                    &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
438
439         drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
440                  DRM_MODE_ENCODER_DAC);
441
442         drm_mode_connector_attach_encoder(&intel_output->base,
443                           &intel_output->enc);
444
445         /* Set up the DDC bus. */
446         intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
447         if (!intel_output->ddc_bus) {
448             dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
449                    "failed.\n");
450             return;
451         }
452
453         intel_output->type = INTEL_OUTPUT_ANALOG;
454         connector->interlace_allowed = 0;
455         connector->doublescan_allowed = 0;
456
457         drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
458         drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
459
460         drm_connector_register(connector);
461     }
462
463 In the example above (taken from the i915 driver), a CRTC, connector and
464 encoder combination is created. A device-specific i2c bus is also
465 created for fetching EDID data and performing monitor detection. Once
466 the process is complete, the new connector is registered with sysfs to
467 make its properties available to applications.
468
469 KMS API Functions
470 -----------------
471
472 .. kernel-doc:: drivers/gpu/drm/drm_crtc.c
473    :export:
474
475 KMS Data Structures
476 -------------------
477
478 .. kernel-doc:: include/drm/drm_crtc.h
479    :internal:
480
481 KMS Locking
482 -----------
483
484 .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
485    :doc: kms locking
486
487 .. kernel-doc:: include/drm/drm_modeset_lock.h
488    :internal:
489
490 .. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
491    :export:
492
493 KMS Properties
494 ==============
495
496 Drivers may need to expose additional parameters to applications than
497 those described in the previous sections. KMS supports attaching
498 properties to CRTCs, connectors and planes and offers a userspace API to
499 list, get and set the property values.
500
501 Properties are identified by a name that uniquely defines the property
502 purpose, and store an associated value. For all property types except
503 blob properties the value is a 64-bit unsigned integer.
504
505 KMS differentiates between properties and property instances. Drivers
506 first create properties and then create and associate individual
507 instances of those properties to objects. A property can be instantiated
508 multiple times and associated with different objects. Values are stored
509 in property instances, and all other property information are stored in
510 the property and shared between all instances of the property.
511
512 Every property is created with a type that influences how the KMS core
513 handles the property. Supported property types are
514
515 DRM_MODE_PROP_RANGE
516     Range properties report their minimum and maximum admissible values.
517     The KMS core verifies that values set by application fit in that
518     range.
519
520 DRM_MODE_PROP_ENUM
521     Enumerated properties take a numerical value that ranges from 0 to
522     the number of enumerated values defined by the property minus one,
523     and associate a free-formed string name to each value. Applications
524     can retrieve the list of defined value-name pairs and use the
525     numerical value to get and set property instance values.
526
527 DRM_MODE_PROP_BITMASK
528     Bitmask properties are enumeration properties that additionally
529     restrict all enumerated values to the 0..63 range. Bitmask property
530     instance values combine one or more of the enumerated bits defined
531     by the property.
532
533 DRM_MODE_PROP_BLOB
534     Blob properties store a binary blob without any format restriction.
535     The binary blobs are created as KMS standalone objects, and blob
536     property instance values store the ID of their associated blob
537     object.
538
539     Blob properties are only used for the connector EDID property and
540     cannot be created by drivers.
541
542 To create a property drivers call one of the following functions
543 depending on the property type. All property creation functions take
544 property flags and name, as well as type-specific arguments.
545
546 -  struct drm_property \*drm_property_create_range(struct
547    drm_device \*dev, int flags, const char \*name, uint64_t min,
548    uint64_t max);
549    Create a range property with the given minimum and maximum values.
550
551 -  struct drm_property \*drm_property_create_enum(struct drm_device
552    \*dev, int flags, const char \*name, const struct
553    drm_prop_enum_list \*props, int num_values);
554    Create an enumerated property. The ``props`` argument points to an
555    array of ``num_values`` value-name pairs.
556
557 -  struct drm_property \*drm_property_create_bitmask(struct
558    drm_device \*dev, int flags, const char \*name, const struct
559    drm_prop_enum_list \*props, int num_values);
560    Create a bitmask property. The ``props`` argument points to an array
561    of ``num_values`` value-name pairs.
562
563 Properties can additionally be created as immutable, in which case they
564 will be read-only for applications but can be modified by the driver. To
565 create an immutable property drivers must set the
566 DRM_MODE_PROP_IMMUTABLE flag at property creation time.
567
568 When no array of value-name pairs is readily available at property
569 creation time for enumerated or range properties, drivers can create the
570 property using the :c:func:`drm_property_create()` function and
571 manually add enumeration value-name pairs by calling the
572 :c:func:`drm_property_add_enum()` function. Care must be taken to
573 properly specify the property type through the ``flags`` argument.
574
575 After creating properties drivers can attach property instances to CRTC,
576 connector and plane objects by calling the
577 :c:func:`drm_object_attach_property()`. The function takes a
578 pointer to the target object, a pointer to the previously created
579 property and an initial instance value.
580
581 Existing KMS Properties
582 -----------------------
583
584 The following table gives description of drm properties exposed by
585 various modules/drivers.
586
587 .. csv-table::
588    :header-rows: 1
589    :file: kms-properties.csv
590
591 Vertical Blanking
592 =================
593
594 Vertical blanking plays a major role in graphics rendering. To achieve
595 tear-free display, users must synchronize page flips and/or rendering to
596 vertical blanking. The DRM API offers ioctls to perform page flips
597 synchronized to vertical blanking and wait for vertical blanking.
598
599 The DRM core handles most of the vertical blanking management logic,
600 which involves filtering out spurious interrupts, keeping race-free
601 blanking counters, coping with counter wrap-around and resets and
602 keeping use counts. It relies on the driver to generate vertical
603 blanking interrupts and optionally provide a hardware vertical blanking
604 counter. Drivers must implement the following operations.
605
606 -  int (\*enable_vblank) (struct drm_device \*dev, int crtc); void
607    (\*disable_vblank) (struct drm_device \*dev, int crtc);
608    Enable or disable vertical blanking interrupts for the given CRTC.
609
610 -  u32 (\*get_vblank_counter) (struct drm_device \*dev, int crtc);
611    Retrieve the value of the vertical blanking counter for the given
612    CRTC. If the hardware maintains a vertical blanking counter its value
613    should be returned. Otherwise drivers can use the
614    :c:func:`drm_vblank_count()` helper function to handle this
615    operation.
616
617 Drivers must initialize the vertical blanking handling core with a call
618 to :c:func:`drm_vblank_init()` in their load operation.
619
620 Vertical blanking interrupts can be enabled by the DRM core or by
621 drivers themselves (for instance to handle page flipping operations).
622 The DRM core maintains a vertical blanking use count to ensure that the
623 interrupts are not disabled while a user still needs them. To increment
624 the use count, drivers call :c:func:`drm_vblank_get()`. Upon
625 return vertical blanking interrupts are guaranteed to be enabled.
626
627 To decrement the use count drivers call
628 :c:func:`drm_vblank_put()`. Only when the use count drops to zero
629 will the DRM core disable the vertical blanking interrupts after a delay
630 by scheduling a timer. The delay is accessible through the
631 vblankoffdelay module parameter or the ``drm_vblank_offdelay`` global
632 variable and expressed in milliseconds. Its default value is 5000 ms.
633 Zero means never disable, and a negative value means disable
634 immediately. Drivers may override the behaviour by setting the
635 :c:type:`struct drm_device <drm_device>`
636 vblank_disable_immediate flag, which when set causes vblank interrupts
637 to be disabled immediately regardless of the drm_vblank_offdelay
638 value. The flag should only be set if there's a properly working
639 hardware vblank counter present.
640
641 When a vertical blanking interrupt occurs drivers only need to call the
642 :c:func:`drm_handle_vblank()` function to account for the
643 interrupt.
644
645 Resources allocated by :c:func:`drm_vblank_init()` must be freed
646 with a call to :c:func:`drm_vblank_cleanup()` in the driver unload
647 operation handler.
648
649 Vertical Blanking and Interrupt Handling Functions Reference
650 ------------------------------------------------------------
651
652 .. kernel-doc:: drivers/gpu/drm/drm_irq.c
653    :export:
654
655 .. kernel-doc:: include/drm/drmP.h
656    :functions: drm_crtc_vblank_waitqueue