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