xref: /linux/Documentation/gpu/drm-kms.rst (revision 570f7e331f5febb30f1384817463c7e42b65ca7d)
1
2.. _drm-kms:
3
4=========================
5Kernel Mode Setting (KMS)
6=========================
7
8Drivers must initialize the mode setting core by calling
9drmm_mode_config_init() on the DRM device. The function
10initializes the :c:type:`struct drm_device <drm_device>`
11mode_config field and never fails. Once done, mode configuration must
12be 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.. contents::
22
23Overview
24========
25
26.. kernel-render:: DOT
27   :alt: KMS Display Pipeline
28   :caption: KMS Display Pipeline Overview
29
30   digraph "KMS" {
31      node [shape=box]
32
33      subgraph cluster_static {
34          style=dashed
35          label="Static Objects"
36
37          node [bgcolor=grey style=filled]
38          "drm_plane A" -> "drm_crtc"
39          "drm_plane B" -> "drm_crtc"
40          "drm_crtc" -> "drm_encoder A"
41          "drm_crtc" -> "drm_encoder B"
42      }
43
44      subgraph cluster_user_created {
45          style=dashed
46          label="Userspace-Created"
47
48          node [shape=oval]
49          "drm_framebuffer 1" -> "drm_plane A"
50          "drm_framebuffer 2" -> "drm_plane B"
51      }
52
53      subgraph cluster_connector {
54          style=dashed
55          label="Hotpluggable"
56
57          "drm_encoder A" -> "drm_connector A"
58          "drm_encoder B" -> "drm_connector B"
59      }
60   }
61
62The basic object structure KMS presents to userspace is fairly simple.
63Framebuffers (represented by :c:type:`struct drm_framebuffer <drm_framebuffer>`,
64see `Frame Buffer Abstraction`_) feed into planes. Planes are represented by
65:c:type:`struct drm_plane <drm_plane>`, see `Plane Abstraction`_ for more
66details. One or more (or even no) planes feed their pixel data into a CRTC
67(represented by :c:type:`struct drm_crtc <drm_crtc>`, see `CRTC Abstraction`_)
68for blending. The precise blending step is explained in more detail in `Plane
69Composition Properties`_ and related chapters.
70
71For the output routing the first step is encoders (represented by
72:c:type:`struct drm_encoder <drm_encoder>`, see `Encoder Abstraction`_). Those
73are really just internal artifacts of the helper libraries used to implement KMS
74drivers. Besides that they make it unnecessarily more complicated for userspace
75to figure out which connections between a CRTC and a connector are possible, and
76what kind of cloning is supported, they serve no purpose in the userspace API.
77Unfortunately encoders have been exposed to userspace, hence can't remove them
78at this point.  Furthermore the exposed restrictions are often wrongly set by
79drivers, and in many cases not powerful enough to express the real restrictions.
80A CRTC can be connected to multiple encoders, and for an active CRTC there must
81be at least one encoder.
82
83The final, and real, endpoint in the display chain is the connector (represented
84by :c:type:`struct drm_connector <drm_connector>`, see `Connector
85Abstraction`_). Connectors can have different possible encoders, but the kernel
86driver selects which encoder to use for each connector. The use case is DVI,
87which could switch between an analog and a digital encoder. Encoders can also
88drive multiple different connectors. There is exactly one active connector for
89every active encoder.
90
91Internally the output pipeline is a bit more complex and matches today's
92hardware more closely:
93
94.. kernel-render:: DOT
95   :alt: KMS Output Pipeline
96   :caption: KMS Output Pipeline
97
98   digraph "Output Pipeline" {
99      node [shape=box]
100
101      subgraph {
102          "drm_crtc" [bgcolor=grey style=filled]
103      }
104
105      subgraph cluster_internal {
106          style=dashed
107          label="Internal Pipeline"
108          {
109              node [bgcolor=grey style=filled]
110              "drm_encoder A";
111              "drm_encoder B";
112              "drm_encoder C";
113          }
114
115          {
116              node [bgcolor=grey style=filled]
117              "drm_encoder B" -> "drm_bridge B"
118              "drm_encoder C" -> "drm_bridge C1"
119              "drm_bridge C1" -> "drm_bridge C2";
120          }
121      }
122
123      "drm_crtc" -> "drm_encoder A"
124      "drm_crtc" -> "drm_encoder B"
125      "drm_crtc" -> "drm_encoder C"
126
127
128      subgraph cluster_output {
129          style=dashed
130          label="Outputs"
131
132          "drm_encoder A" -> "drm_connector A";
133          "drm_bridge B" -> "drm_connector B";
134          "drm_bridge C2" -> "drm_connector C";
135
136          "drm_panel"
137      }
138   }
139
140Internally two additional helper objects come into play. First, to be able to
141share code for encoders (sometimes on the same SoC, sometimes off-chip) one or
142more :ref:`drm_bridges` (represented by :c:type:`struct drm_bridge
143<drm_bridge>`) can be linked to an encoder. This link is static and cannot be
144changed, which means the cross-bar (if there is any) needs to be mapped between
145the CRTC and any encoders. Often for drivers with bridges there's no code left
146at the encoder level. Atomic drivers can leave out all the encoder callbacks to
147essentially only leave a dummy routing object behind, which is needed for
148backwards compatibility since encoders are exposed to userspace.
149
150The second object is for panels, represented by :c:type:`struct drm_panel
151<drm_panel>`, see :ref:`drm_panel_helper`. Panels do not have a fixed binding
152point, but are generally linked to the driver private structure that embeds
153:c:type:`struct drm_connector <drm_connector>`.
154
155Note that currently the bridge chaining and interactions with connectors and
156panels are still in-flux and not really fully sorted out yet.
157
158KMS Core Structures and Functions
159=================================
160
161.. kernel-doc:: include/drm/drm_mode_config.h
162   :internal:
163
164.. kernel-doc:: drivers/gpu/drm/drm_mode_config.c
165   :export:
166
167.. _kms_base_object_abstraction:
168
169Modeset Base Object Abstraction
170===============================
171
172.. kernel-render:: DOT
173   :alt: Mode Objects and Properties
174   :caption: Mode Objects and Properties
175
176   digraph {
177      node [shape=box]
178
179      "drm_property A" -> "drm_mode_object A"
180      "drm_property A" -> "drm_mode_object B"
181      "drm_property B" -> "drm_mode_object A"
182   }
183
184The base structure for all KMS objects is :c:type:`struct drm_mode_object
185<drm_mode_object>`. One of the base services it provides is tracking properties,
186which are especially important for the atomic IOCTL (see `Atomic Mode
187Setting`_). The somewhat surprising part here is that properties are not
188directly instantiated on each object, but free-standing mode objects themselves,
189represented by :c:type:`struct drm_property <drm_property>`, which only specify
190the type and value range of a property. Any given property can be attached
191multiple times to different objects using drm_object_attach_property().
192
193.. kernel-doc:: include/drm/drm_mode_object.h
194   :internal:
195
196.. kernel-doc:: drivers/gpu/drm/drm_mode_object.c
197   :export:
198
199Atomic Mode Setting
200===================
201
202
203.. kernel-render:: DOT
204   :alt: Mode Objects and Properties
205   :caption: Mode Objects and Properties
206
207   digraph {
208      node [shape=box]
209
210      subgraph cluster_state {
211          style=dashed
212          label="Free-standing state"
213
214          "drm_atomic_commit" -> "duplicated drm_plane_state A"
215          "drm_atomic_commit" -> "duplicated drm_plane_state B"
216          "drm_atomic_commit" -> "duplicated drm_crtc_state"
217          "drm_atomic_commit" -> "duplicated drm_connector_state"
218          "drm_atomic_commit" -> "duplicated driver private state"
219      }
220
221      subgraph cluster_current {
222          style=dashed
223          label="Current state"
224
225          "drm_device" -> "drm_plane A"
226          "drm_device" -> "drm_plane B"
227          "drm_device" -> "drm_crtc"
228          "drm_device" -> "drm_connector"
229          "drm_device" -> "driver private object"
230
231          "drm_plane A" -> "drm_plane_state A"
232          "drm_plane B" -> "drm_plane_state B"
233          "drm_crtc" -> "drm_crtc_state"
234          "drm_connector" -> "drm_connector_state"
235          "driver private object" -> "driver private state"
236      }
237
238      "drm_atomic_commit" -> "drm_device" [label="atomic_commit"]
239      "duplicated drm_plane_state A" -> "drm_device"[style=invis]
240   }
241
242Atomic provides transactional modeset (including planes) updates, but a
243bit differently from the usual transactional approach of try-commit and
244rollback:
245
246- Firstly, no hardware changes are allowed when the commit would fail. This
247  allows us to implement the DRM_MODE_ATOMIC_TEST_ONLY mode, which allows
248  userspace to explore whether certain configurations would work or not.
249
250- This would still allow setting and rollback of just the software state,
251  simplifying conversion of existing drivers. But auditing drivers for
252  correctness of the atomic_check code becomes really hard with that: Rolling
253  back changes in data structures all over the place is hard to get right.
254
255- Lastly, for backwards compatibility and to support all use-cases, atomic
256  updates need to be incremental and be able to execute in parallel. Hardware
257  doesn't always allow it, but where possible plane updates on different CRTCs
258  should not interfere, and not get stalled due to output routing changing on
259  different CRTCs.
260
261Taken all together there's two consequences for the atomic design:
262
263- The overall state is split up into per-object state structures:
264  :c:type:`struct drm_plane_state <drm_plane_state>` for planes, :c:type:`struct
265  drm_crtc_state <drm_crtc_state>` for CRTCs and :c:type:`struct
266  drm_connector_state <drm_connector_state>` for connectors. These are the only
267  objects with userspace-visible and settable state. For internal state drivers
268  can subclass these structures through embedding, or add entirely new state
269  structures for their globally shared hardware functions, see :c:type:`struct
270  drm_private_state<drm_private_state>`.
271
272- An atomic update is assembled and validated as an entirely free-standing pile
273  of structures within the :c:type:`drm_atomic_commit <drm_atomic_commit>`
274  container. Driver private state structures are also tracked in the same
275  structure; see the next chapter.  Only when a state is committed is it applied
276  to the driver and modeset objects. This way rolling back an update boils down
277  to releasing memory and unreferencing objects like framebuffers.
278
279Locking of atomic state structures is internally using :c:type:`struct
280drm_modeset_lock <drm_modeset_lock>`. As a general rule the locking shouldn't be
281exposed to drivers, instead the right locks should be automatically acquired by
282any function that duplicates or peeks into a state, like e.g.
283drm_atomic_get_crtc_state().  Locking only protects the software data
284structure, ordering of committing state changes to hardware is sequenced using
285:c:type:`struct drm_crtc_commit <drm_crtc_commit>`.
286
287Read on in this chapter, and also in :ref:`drm_atomic_helper` for more detailed
288coverage of specific topics.
289
290Atomic State Lifetime
291---------------------
292
293.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
294   :doc: state lifetime
295
296Handling Driver Private State
297-----------------------------
298
299.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
300   :doc: handling driver private state
301
302Atomic Mode Setting Function Reference
303--------------------------------------
304
305.. kernel-doc:: include/drm/drm_atomic.h
306   :internal:
307
308.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
309   :export:
310
311Atomic Mode Setting IOCTL and UAPI Functions
312--------------------------------------------
313
314.. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
315   :doc: overview
316
317.. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
318   :export:
319
320CRTC Abstraction
321================
322
323.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
324   :doc: overview
325
326CRTC Functions Reference
327--------------------------------
328
329.. kernel-doc:: include/drm/drm_crtc.h
330   :internal:
331
332.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
333   :export:
334
335Color Management Functions Reference
336------------------------------------
337
338.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
339   :export:
340
341.. kernel-doc:: include/drm/drm_color_mgmt.h
342   :internal:
343
344Frame Buffer Abstraction
345========================
346
347.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
348   :doc: overview
349
350Frame Buffer Functions Reference
351--------------------------------
352
353.. kernel-doc:: include/drm/drm_framebuffer.h
354   :internal:
355
356.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
357   :export:
358
359DRM Format Handling
360===================
361
362.. kernel-doc:: include/uapi/drm/drm_fourcc.h
363   :doc: overview
364
365Format Functions Reference
366--------------------------
367
368.. kernel-doc:: include/drm/drm_fourcc.h
369   :internal:
370
371.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
372   :export:
373
374.. _kms_dumb_buffer_objects:
375
376Dumb Buffer Objects
377===================
378
379.. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
380   :doc: overview
381
382Plane Abstraction
383=================
384
385.. kernel-doc:: drivers/gpu/drm/drm_plane.c
386   :doc: overview
387
388Plane Functions Reference
389-------------------------
390
391.. kernel-doc:: include/drm/drm_plane.h
392   :internal:
393
394.. kernel-doc:: drivers/gpu/drm/drm_plane.c
395   :export:
396
397Plane Composition Functions Reference
398-------------------------------------
399
400.. kernel-doc:: drivers/gpu/drm/drm_blend.c
401   :export:
402
403Plane Damage Tracking Functions Reference
404-----------------------------------------
405
406.. kernel-doc:: drivers/gpu/drm/drm_damage_helper.c
407   :export:
408
409.. kernel-doc:: include/drm/drm_damage_helper.h
410   :internal:
411
412Plane Panic Feature
413-------------------
414
415.. kernel-doc:: drivers/gpu/drm/drm_panic.c
416   :doc: overview
417
418Plane Panic Functions Reference
419-------------------------------
420
421.. kernel-doc:: include/drm/drm_panic.h
422   :internal:
423
424.. kernel-doc:: drivers/gpu/drm/drm_panic.c
425   :export:
426
427Colorop Abstraction
428===================
429
430.. kernel-doc:: drivers/gpu/drm/drm_colorop.c
431   :doc: overview
432
433Colorop Functions Reference
434---------------------------
435
436.. kernel-doc:: include/drm/drm_colorop.h
437   :internal:
438
439.. kernel-doc:: drivers/gpu/drm/drm_colorop.c
440   :export:
441
442Display Modes Function Reference
443================================
444
445.. kernel-doc:: include/drm/drm_modes.h
446   :internal:
447
448.. kernel-doc:: drivers/gpu/drm/drm_modes.c
449   :export:
450
451Connector Abstraction
452=====================
453
454.. kernel-doc:: drivers/gpu/drm/drm_connector.c
455   :doc: overview
456
457Connector Functions Reference
458-----------------------------
459
460.. kernel-doc:: include/drm/drm_connector.h
461   :internal:
462
463.. kernel-doc:: drivers/gpu/drm/drm_connector.c
464   :export:
465
466Writeback Connectors
467--------------------
468
469.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
470  :doc: overview
471
472.. kernel-doc:: include/drm/drm_writeback.h
473  :internal:
474
475.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
476  :export:
477
478Encoder Abstraction
479===================
480
481.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
482   :doc: overview
483
484Encoder Functions Reference
485---------------------------
486
487.. kernel-doc:: include/drm/drm_encoder.h
488   :internal:
489
490.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
491   :export:
492
493KMS Locking
494===========
495
496.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
497   :doc: kms locking
498
499.. kernel-doc:: include/drm/drm_modeset_lock.h
500   :internal:
501
502.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
503   :export:
504
505KMS Properties
506==============
507
508This section of the documentation is primarily aimed at user-space developers.
509For the driver APIs, see the other sections.
510
511Requirements
512------------
513
514KMS drivers might need to add extra properties to support new features. Each
515new property introduced in a driver needs to meet a few requirements, in
516addition to the one mentioned above:
517
518* It must be standardized, documenting:
519
520  * The full, exact, name string;
521  * If the property is an enum, all the valid value name strings;
522  * What values are accepted, and what these values mean;
523  * What the property does and how it can be used;
524  * How the property might interact with other, existing properties.
525
526* It must provide a generic helper in the core code to register that
527  property on the object it attaches to.
528
529* Its content must be decoded by the core and provided in the object's
530  associated state structure. That includes anything drivers might want
531  to precompute, like struct drm_clip_rect for planes.
532
533* Its initial state must match the behavior prior to the property
534  introduction. This might be a fixed value matching what the hardware
535  does, or it may be inherited from the state the firmware left the
536  system in during boot.
537
538* An IGT test must be submitted where reasonable.
539
540For historical reasons, non-standard, driver-specific properties exist. If a KMS
541driver wants to add support for one of those properties, the requirements for
542new properties apply where possible. Additionally, the documented behavior must
543match the de facto semantics of the existing property to ensure compatibility.
544Developers of the driver that first added the property should help with those
545tasks and must ACK the documented behavior if possible.
546
547Property Types and Blob Property Support
548----------------------------------------
549
550.. kernel-doc:: drivers/gpu/drm/drm_property.c
551   :doc: overview
552
553.. kernel-doc:: include/drm/drm_property.h
554   :internal:
555
556.. kernel-doc:: drivers/gpu/drm/drm_property.c
557   :export:
558
559.. _standard_connector_properties:
560
561Standard Connector Properties
562-----------------------------
563
564.. kernel-doc:: drivers/gpu/drm/drm_connector.c
565   :doc: standard connector properties
566
567HDMI Specific Connector Properties
568----------------------------------
569
570.. kernel-doc:: drivers/gpu/drm/drm_connector.c
571   :doc: HDMI connector properties
572
573Analog TV Specific Connector Properties
574---------------------------------------
575
576.. kernel-doc:: drivers/gpu/drm/drm_connector.c
577   :doc: Analog TV Connector Properties
578
579Standard CRTC Properties
580------------------------
581
582.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
583   :doc: standard CRTC properties
584
585Standard Plane Properties
586-------------------------
587
588.. kernel-doc:: drivers/gpu/drm/drm_plane.c
589   :doc: standard plane properties
590
591.. _plane_composition_properties:
592
593Plane Composition Properties
594----------------------------
595
596.. kernel-doc:: drivers/gpu/drm/drm_blend.c
597   :doc: overview
598
599.. _damage_tracking_properties:
600
601Damage Tracking Properties
602--------------------------
603
604.. kernel-doc:: drivers/gpu/drm/drm_plane.c
605   :doc: damage tracking
606
607Color Management Properties
608---------------------------
609
610.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
611   :doc: overview
612
613Color Format Property
614---------------------
615
616.. kernel-doc:: drivers/gpu/drm/drm_connector.c
617   :doc: Color format
618
619Tile Group Property
620-------------------
621
622.. kernel-doc:: drivers/gpu/drm/drm_connector.c
623   :doc: Tile group
624
625Explicit Fencing Properties
626---------------------------
627
628.. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
629   :doc: explicit fencing properties
630
631
632Variable Refresh Properties
633---------------------------
634
635.. kernel-doc:: drivers/gpu/drm/drm_connector.c
636   :doc: Variable refresh properties
637
638Cursor Hotspot Properties
639---------------------------
640
641.. kernel-doc:: drivers/gpu/drm/drm_plane.c
642   :doc: hotspot properties
643
644Existing KMS Properties
645-----------------------
646
647The following table gives description of drm properties exposed by various
648modules/drivers. Because this table is very unwieldy, do not add any new
649properties here. Instead document them in a section above.
650
651.. csv-table::
652   :header-rows: 1
653   :file: kms-properties.csv
654
655Vertical Blanking
656=================
657
658.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
659   :doc: vblank handling
660
661Vertical Blanking and Interrupt Handling Functions Reference
662------------------------------------------------------------
663
664.. kernel-doc:: include/drm/drm_vblank.h
665   :internal:
666
667.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
668   :export:
669
670Vertical Blank Work
671===================
672
673.. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
674   :doc: vblank works
675
676Vertical Blank Work Functions Reference
677---------------------------------------
678
679.. kernel-doc:: include/drm/drm_vblank_work.h
680   :internal:
681
682.. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
683   :export:
684