blob: 1c42448c7aae93a81a43438a1cb953efbbd8abbc [file] [log] [blame]
Jani Nikula2fa91d12016-06-21 14:49:02 +03001=========================
2Kernel Mode Setting (KMS)
3=========================
4
Jani Nikula2fa91d12016-06-21 14:49:02 +03005Drivers must initialize the mode setting core by calling
6:c:func:`drm_mode_config_init()` on the DRM device. The function
7initializes the :c:type:`struct drm_device <drm_device>`
8mode_config field and never fails. Once done, mode configuration must
9be setup by initializing the following fields.
10
11- int min_width, min_height; int max_width, max_height;
12 Minimum and maximum width and height of the frame buffers in pixel
13 units.
14
15- struct drm_mode_config_funcs \*funcs;
16 Mode setting functions.
17
Daniel Vetter2564d0b2017-03-02 16:16:35 +010018Overview
19========
20
21.. kernel-render:: DOT
22 :alt: KMS Display Pipeline
23 :caption: KMS Display Pipeline Overview
24
25 digraph "KMS" {
26 node [shape=box]
27
28 subgraph cluster_static {
29 style=dashed
30 label="Static Objects"
31
32 node [bgcolor=grey style=filled]
33 "drm_plane A" -> "drm_crtc"
34 "drm_plane B" -> "drm_crtc"
35 "drm_crtc" -> "drm_encoder A"
36 "drm_crtc" -> "drm_encoder B"
37 }
38
39 subgraph cluster_user_created {
40 style=dashed
41 label="Userspace-Created"
42
43 node [shape=oval]
44 "drm_framebuffer 1" -> "drm_plane A"
45 "drm_framebuffer 2" -> "drm_plane B"
46 }
47
48 subgraph cluster_connector {
49 style=dashed
50 label="Hotpluggable"
51
52 "drm_encoder A" -> "drm_connector A"
53 "drm_encoder B" -> "drm_connector B"
54 }
55 }
56
57The basic object structure KMS presents to userspace is fairly simple.
58Framebuffers (represented by :c:type:`struct drm_framebuffer <drm_framebuffer>`,
59see `Frame Buffer Abstraction`_) feed into planes. One or more (or even no)
60planes feed their pixel data into a CRTC (represented by :c:type:`struct
61drm_crtc <drm_crtc>`, see `CRTC Abstraction`_) for blending. The precise
62blending step is explained in more detail in `Plane Composition Properties`_ and
63related chapters.
64
65For the output routing the first step is encoders (represented by
66:c:type:`struct drm_encoder <drm_encoder>`, see `Encoder Abstraction`_). Those
67are really just internal artifacts of the helper libraries used to implement KMS
68drivers. Besides that they make it unecessarily more complicated for userspace
69to figure out which connections between a CRTC and a connector are possible, and
70what kind of cloning is supported, they serve no purpose in the userspace API.
71Unfortunately encoders have been exposed to userspace, hence can't remove them
72at this point. Futhermore the exposed restrictions are often wrongly set by
73drivers, and in many cases not powerful enough to express the real restrictions.
74A CRTC can be connected to multiple encoders, and for an active CRTC there must
75be at least one encoder.
76
77The final, and real, endpoint in the display chain is the connector (represented
78by :c:type:`struct drm_connector <drm_connector>`, see `Connector
79Abstraction`_). Connectors can have different possible encoders, but the kernel
80driver selects which encoder to use for each connector. The use case is DVI,
81which could switch between an analog and a digital encoder. Encoders can also
82drive multiple different connectors. There is exactly one active connector for
83every active encoder.
84
85Internally the output pipeline is a bit more complex and matches today's
86hardware more closely:
87
88.. kernel-render:: DOT
89 :alt: KMS Output Pipeline
90 :caption: KMS Output Pipeline
91
92 digraph "Output Pipeline" {
93 node [shape=box]
94
95 subgraph {
96 "drm_crtc" [bgcolor=grey style=filled]
97 }
98
99 subgraph cluster_internal {
100 style=dashed
101 label="Internal Pipeline"
102 {
103 node [bgcolor=grey style=filled]
104 "drm_encoder A";
105 "drm_encoder B";
106 "drm_encoder C";
107 }
108
109 {
110 node [bgcolor=grey style=filled]
111 "drm_encoder B" -> "drm_bridge B"
112 "drm_encoder C" -> "drm_bridge C1"
113 "drm_bridge C1" -> "drm_bridge C2";
114 }
115 }
116
117 "drm_crtc" -> "drm_encoder A"
118 "drm_crtc" -> "drm_encoder B"
119 "drm_crtc" -> "drm_encoder C"
120
121
122 subgraph cluster_output {
123 style=dashed
124 label="Outputs"
125
126 "drm_encoder A" -> "drm_connector A";
127 "drm_bridge B" -> "drm_connector B";
128 "drm_bridge C2" -> "drm_connector C";
129
130 "drm_panel"
131 }
132 }
133
134Internally two additional helper objects come into play. First, to be able to
135share code for encoders (sometimes on the same SoC, sometimes off-chip) one or
136more :ref:`drm_bridges` (represented by :c:type:`struct drm_bridge
137<drm_bridge>`) can be linked to an encoder. This link is static and cannot be
138changed, which means the cross-bar (if there is any) needs to be mapped between
139the CRTC and any encoders. Often for drivers with bridges there's no code left
140at the encoder level. Atomic drivers can leave out all the encoder callbacks to
141essentially only leave a dummy routing object behind, which is needed for
142backwards compatibility since encoders are exposed to userspace.
143
144The second object is for panels, represented by :c:type:`struct drm_panel
145<drm_panel>`, see :ref:`drm_panel_helper`. Panels do not have a fixed binding
146point, but are generally linked to the driver private structure that embeds
147:c:type:`struct drm_connector <drm_connector>`.
148
149Note that currently the bridge chaining and interactions with connectors and
150panels are still in-flux and not really fully sorted out yet.
Daniel Vetter28575f12016-11-14 12:58:23 +0100151
152KMS Core Structures and Functions
153=================================
154
Daniel Vetter28575f12016-11-14 12:58:23 +0100155.. kernel-doc:: include/drm/drm_mode_config.h
156 :internal:
157
Daniel Vetter1ea35762017-03-02 16:16:36 +0100158.. kernel-doc:: drivers/gpu/drm/drm_mode_config.c
159 :export:
160
Daniel Vetter949619f2016-08-29 10:27:51 +0200161Modeset Base Object Abstraction
162===============================
163
Daniel Vetterb2b82c22017-03-02 16:16:37 +0100164.. kernel-render:: DOT
165 :alt: Mode Objects and Properties
166 :caption: Mode Objects and Properties
167
168 digraph {
169 node [shape=box]
170
171 "drm_property A" -> "drm_mode_object A"
172 "drm_property A" -> "drm_mode_object B"
173 "drm_property B" -> "drm_mode_object A"
174 }
175
176The base structure for all KMS objects is :c:type:`struct drm_mode_object
177<drm_mode_object>`. One of the base services it provides is tracking properties,
178which are especially important for the atomic IOCTL (see `Atomic Mode
179Setting`_). The somewhat surprising part here is that properties are not
180directly instantiated on each object, but free-standing mode objects themselves,
181represented by :c:type:`struct drm_property <drm_property>`, which only specify
182the type and value range of a property. Any given property can be attached
183multiple times to different objects using :c:func:`drm_object_attach_property()
184<drm_object_attach_property>`.
185
Daniel Vetter949619f2016-08-29 10:27:51 +0200186.. kernel-doc:: include/drm/drm_mode_object.h
187 :internal:
188
189.. kernel-doc:: drivers/gpu/drm/drm_mode_object.c
190 :export:
191
Jani Nikula2fa91d12016-06-21 14:49:02 +0300192Atomic Mode Setting Function Reference
Daniel Vetter311b62d2016-08-12 22:48:41 +0200193======================================
Jani Nikula2fa91d12016-06-21 14:49:02 +0300194
Daniel Vetter5d070be2016-08-12 22:48:46 +0200195.. kernel-doc:: include/drm/drm_atomic.h
Jani Nikula2fa91d12016-06-21 14:49:02 +0300196 :internal:
197
Daniel Vetter1ea35762017-03-02 16:16:36 +0100198.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
199 :export:
200
Daniel Vetter28575f12016-11-14 12:58:23 +0100201CRTC Abstraction
202================
203
204.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
Daniel Vetterd5d487e2017-01-25 07:26:57 +0100205 :doc: overview
206
207CRTC Functions Reference
208--------------------------------
Daniel Vetter28575f12016-11-14 12:58:23 +0100209
210.. kernel-doc:: include/drm/drm_crtc.h
211 :internal:
212
Daniel Vetterd5d487e2017-01-25 07:26:57 +0100213.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
214 :export:
215
Jani Nikula2fa91d12016-06-21 14:49:02 +0300216Frame Buffer Abstraction
Daniel Vetter311b62d2016-08-12 22:48:41 +0200217========================
Jani Nikula2fa91d12016-06-21 14:49:02 +0300218
Daniel Vetter750fb8c2016-08-12 22:48:48 +0200219.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
220 :doc: overview
Jani Nikula2fa91d12016-06-21 14:49:02 +0300221
Daniel Vetter7520a272016-08-15 16:07:02 +0200222Frame Buffer Functions Reference
223--------------------------------
224
Daniel Vetter7520a272016-08-15 16:07:02 +0200225.. kernel-doc:: include/drm/drm_framebuffer.h
226 :internal:
227
Daniel Vetter1ea35762017-03-02 16:16:36 +0100228.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
229 :export:
230
Jani Nikula2fa91d12016-06-21 14:49:02 +0300231DRM Format Handling
Daniel Vetter311b62d2016-08-12 22:48:41 +0200232===================
Jani Nikula2fa91d12016-06-21 14:49:02 +0300233
Laurent Pinchart84770cc2016-10-18 01:41:09 +0300234.. kernel-doc:: include/drm/drm_fourcc.h
235 :internal:
236
Jani Nikula2fa91d12016-06-21 14:49:02 +0300237.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
238 :export:
239
240Dumb Buffer Objects
Daniel Vetter311b62d2016-08-12 22:48:41 +0200241===================
Jani Nikula2fa91d12016-06-21 14:49:02 +0300242
Daniel Vetter4f936242016-11-14 12:58:21 +0100243.. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
244 :doc: overview
Jani Nikula2fa91d12016-06-21 14:49:02 +0300245
Daniel Vetter43968d72016-09-21 10:59:24 +0200246Plane Abstraction
247=================
248
Daniel Vetter532b3672016-09-21 10:59:25 +0200249.. kernel-doc:: drivers/gpu/drm/drm_plane.c
250 :doc: overview
251
Daniel Vetter43968d72016-09-21 10:59:24 +0200252Plane Functions Reference
253-------------------------
254
255.. kernel-doc:: include/drm/drm_plane.h
256 :internal:
257
258.. kernel-doc:: drivers/gpu/drm/drm_plane.c
259 :export:
260
Daniel Vetter311b62d2016-08-12 22:48:41 +0200261Display Modes Function Reference
262================================
Jani Nikula2fa91d12016-06-21 14:49:02 +0300263
Daniel Vetter311b62d2016-08-12 22:48:41 +0200264.. kernel-doc:: include/drm/drm_modes.h
265 :internal:
266
267.. kernel-doc:: drivers/gpu/drm/drm_modes.c
268 :export:
Jani Nikula2fa91d12016-06-21 14:49:02 +0300269
Daniel Vetterae2a6da2016-08-12 22:48:53 +0200270Connector Abstraction
271=====================
272
273.. kernel-doc:: drivers/gpu/drm/drm_connector.c
274 :doc: overview
275
276Connector Functions Reference
277-----------------------------
Daniel Vetter52217192016-08-12 22:48:50 +0200278
279.. kernel-doc:: include/drm/drm_connector.h
280 :internal:
281
282.. kernel-doc:: drivers/gpu/drm/drm_connector.c
283 :export:
284
Daniel Vetter321a95a2016-08-29 10:27:49 +0200285Encoder Abstraction
286===================
287
Daniel Vettere03e6de2016-08-29 10:27:50 +0200288.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
289 :doc: overview
290
291Encoder Functions Reference
292---------------------------
293
Daniel Vetter321a95a2016-08-29 10:27:49 +0200294.. kernel-doc:: include/drm/drm_encoder.h
295 :internal:
296
297.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
298 :export:
299
Jani Nikula2fa91d12016-06-21 14:49:02 +0300300KMS Initialization and Cleanup
301==============================
302
303A KMS device is abstracted and exposed as a set of planes, CRTCs,
304encoders and connectors. KMS drivers must thus create and initialize all
305those objects at load time after initializing mode setting.
306
307CRTCs (:c:type:`struct drm_crtc <drm_crtc>`)
308--------------------------------------------
309
310A CRTC is an abstraction representing a part of the chip that contains a
311pointer to a scanout buffer. Therefore, the number of CRTCs available
312determines how many independent scanout buffers can be active at any
313given time. The CRTC structure contains several fields to support this:
314a pointer to some video memory (abstracted as a frame buffer object), a
315display mode, and an (x, y) offset into the video memory to support
316panning or configurations where one piece of video memory spans multiple
317CRTCs.
318
319CRTC Initialization
320~~~~~~~~~~~~~~~~~~~
321
322A KMS device must create and register at least one struct
323:c:type:`struct drm_crtc <drm_crtc>` instance. The instance is
324allocated and zeroed by the driver, possibly as part of a larger
325structure, and registered with a call to :c:func:`drm_crtc_init()`
326with a pointer to CRTC functions.
327
Jani Nikula2fa91d12016-06-21 14:49:02 +0300328
Jani Nikula2fa91d12016-06-21 14:49:02 +0300329Cleanup
330-------
331
332The DRM core manages its objects' lifetime. When an object is not needed
333anymore the core calls its destroy function, which must clean up and
334free every resource allocated for the object. Every
335:c:func:`drm_\*_init()` call must be matched with a corresponding
336:c:func:`drm_\*_cleanup()` call to cleanup CRTCs
337(:c:func:`drm_crtc_cleanup()`), planes
338(:c:func:`drm_plane_cleanup()`), encoders
339(:c:func:`drm_encoder_cleanup()`) and connectors
340(:c:func:`drm_connector_cleanup()`). Furthermore, connectors that
341have been added to sysfs must be removed by a call to
342:c:func:`drm_connector_unregister()` before calling
343:c:func:`drm_connector_cleanup()`.
344
345Connectors state change detection must be cleanup up with a call to
346:c:func:`drm_kms_helper_poll_fini()`.
347
348Output discovery and initialization example
349-------------------------------------------
350
Jani Nikula29849a62016-11-03 11:44:23 +0200351.. code-block:: c
Jani Nikula2fa91d12016-06-21 14:49:02 +0300352
353 void intel_crt_init(struct drm_device *dev)
354 {
355 struct drm_connector *connector;
356 struct intel_output *intel_output;
357
358 intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
359 if (!intel_output)
360 return;
361
362 connector = &intel_output->base;
363 drm_connector_init(dev, &intel_output->base,
364 &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
365
366 drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
367 DRM_MODE_ENCODER_DAC);
368
369 drm_mode_connector_attach_encoder(&intel_output->base,
370 &intel_output->enc);
371
372 /* Set up the DDC bus. */
373 intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
374 if (!intel_output->ddc_bus) {
375 dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
376 "failed.\n");
377 return;
378 }
379
380 intel_output->type = INTEL_OUTPUT_ANALOG;
381 connector->interlace_allowed = 0;
382 connector->doublescan_allowed = 0;
383
384 drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
385 drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
386
387 drm_connector_register(connector);
388 }
389
390In the example above (taken from the i915 driver), a CRTC, connector and
391encoder combination is created. A device-specific i2c bus is also
392created for fetching EDID data and performing monitor detection. Once
393the process is complete, the new connector is registered with sysfs to
394make its properties available to applications.
395
Jani Nikula2fa91d12016-06-21 14:49:02 +0300396KMS Locking
Daniel Vetter311b62d2016-08-12 22:48:41 +0200397===========
Jani Nikula2fa91d12016-06-21 14:49:02 +0300398
399.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
400 :doc: kms locking
401
402.. kernel-doc:: include/drm/drm_modeset_lock.h
403 :internal:
404
405.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
406 :export:
407
408KMS Properties
409==============
410
Daniel Vetter59e71ee2016-08-29 10:27:55 +0200411Property Types and Blob Property Support
412----------------------------------------
413
Daniel Vetterc8458c72016-08-29 10:27:57 +0200414.. kernel-doc:: drivers/gpu/drm/drm_property.c
415 :doc: overview
416
Daniel Vetter59e71ee2016-08-29 10:27:55 +0200417.. kernel-doc:: include/drm/drm_property.h
418 :internal:
419
420.. kernel-doc:: drivers/gpu/drm/drm_property.c
421 :export:
422
Daniel Vetter4ada6f22016-11-17 09:56:48 +0100423Standard Connector Properties
424-----------------------------
425
426.. kernel-doc:: drivers/gpu/drm/drm_connector.c
427 :doc: standard connector properties
428
Daniel Vetter1e4d84c2016-09-21 10:59:27 +0200429Plane Composition Properties
430----------------------------
431
432.. kernel-doc:: drivers/gpu/drm/drm_blend.c
433 :doc: overview
Daniel Vetter52a9fcd2016-08-12 22:48:51 +0200434
435.. kernel-doc:: drivers/gpu/drm/drm_blend.c
436 :export:
437
Daniel Vettera6acccf2016-09-21 10:59:29 +0200438Color Management Properties
439---------------------------
440
441.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
442 :doc: overview
443
444.. kernel-doc:: include/drm/drm_color_mgmt.h
445 :internal:
446
447.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
448 :export:
449
Daniel Vetter9498c192016-11-14 12:58:24 +0100450Tile Group Property
451-------------------
452
453.. kernel-doc:: drivers/gpu/drm/drm_connector.c
454 :doc: Tile group
455
Gustavo Padovan9a83a712016-11-22 09:11:28 +0900456Explicit Fencing Properties
457---------------------------
458
459.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
460 :doc: explicit fencing properties
461
Jani Nikula2fa91d12016-06-21 14:49:02 +0300462Existing KMS Properties
463-----------------------
464
465The following table gives description of drm properties exposed by
466various modules/drivers.
467
468.. csv-table::
469 :header-rows: 1
470 :file: kms-properties.csv
471
472Vertical Blanking
473=================
474
475Vertical blanking plays a major role in graphics rendering. To achieve
476tear-free display, users must synchronize page flips and/or rendering to
477vertical blanking. The DRM API offers ioctls to perform page flips
478synchronized to vertical blanking and wait for vertical blanking.
479
480The DRM core handles most of the vertical blanking management logic,
481which involves filtering out spurious interrupts, keeping race-free
482blanking counters, coping with counter wrap-around and resets and
483keeping use counts. It relies on the driver to generate vertical
484blanking interrupts and optionally provide a hardware vertical blanking
485counter. Drivers must implement the following operations.
486
487- int (\*enable_vblank) (struct drm_device \*dev, int crtc); void
488 (\*disable_vblank) (struct drm_device \*dev, int crtc);
489 Enable or disable vertical blanking interrupts for the given CRTC.
490
491- u32 (\*get_vblank_counter) (struct drm_device \*dev, int crtc);
492 Retrieve the value of the vertical blanking counter for the given
493 CRTC. If the hardware maintains a vertical blanking counter its value
494 should be returned. Otherwise drivers can use the
495 :c:func:`drm_vblank_count()` helper function to handle this
496 operation.
497
498Drivers must initialize the vertical blanking handling core with a call
499to :c:func:`drm_vblank_init()` in their load operation.
500
501Vertical blanking interrupts can be enabled by the DRM core or by
502drivers themselves (for instance to handle page flipping operations).
503The DRM core maintains a vertical blanking use count to ensure that the
504interrupts are not disabled while a user still needs them. To increment
505the use count, drivers call :c:func:`drm_vblank_get()`. Upon
506return vertical blanking interrupts are guaranteed to be enabled.
507
508To decrement the use count drivers call
509:c:func:`drm_vblank_put()`. Only when the use count drops to zero
510will the DRM core disable the vertical blanking interrupts after a delay
511by scheduling a timer. The delay is accessible through the
512vblankoffdelay module parameter or the ``drm_vblank_offdelay`` global
513variable and expressed in milliseconds. Its default value is 5000 ms.
514Zero means never disable, and a negative value means disable
515immediately. Drivers may override the behaviour by setting the
516:c:type:`struct drm_device <drm_device>`
517vblank_disable_immediate flag, which when set causes vblank interrupts
518to be disabled immediately regardless of the drm_vblank_offdelay
519value. The flag should only be set if there's a properly working
520hardware vblank counter present.
521
522When a vertical blanking interrupt occurs drivers only need to call the
523:c:func:`drm_handle_vblank()` function to account for the
524interrupt.
525
526Resources allocated by :c:func:`drm_vblank_init()` must be freed
527with a call to :c:func:`drm_vblank_cleanup()` in the driver unload
528operation handler.
529
530Vertical Blanking and Interrupt Handling Functions Reference
531------------------------------------------------------------
532
Daniel Vetter34a67dd2016-07-15 21:48:01 +0200533.. kernel-doc:: include/drm/drm_irq.h
534 :internal:
Daniel Vetter1ea35762017-03-02 16:16:36 +0100535
536.. kernel-doc:: drivers/gpu/drm/drm_irq.c
537 :export: