xref: /linux/Documentation/gpu/drm-kms.rst (revision c06b6cde2a1c3bcbb561bd57bb6f34eae9030921)
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
290Handling Driver Private State
291-----------------------------
292
293.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
294   :doc: handling driver private state
295
296Atomic Mode Setting Function Reference
297--------------------------------------
298
299.. kernel-doc:: include/drm/drm_atomic.h
300   :internal:
301
302.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
303   :export:
304
305Atomic Mode Setting IOCTL and UAPI Functions
306--------------------------------------------
307
308.. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
309   :doc: overview
310
311.. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
312   :export:
313
314CRTC Abstraction
315================
316
317.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
318   :doc: overview
319
320CRTC Functions Reference
321--------------------------------
322
323.. kernel-doc:: include/drm/drm_crtc.h
324   :internal:
325
326.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
327   :export:
328
329Color Management Functions Reference
330------------------------------------
331
332.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
333   :export:
334
335.. kernel-doc:: include/drm/drm_color_mgmt.h
336   :internal:
337
338Frame Buffer Abstraction
339========================
340
341.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
342   :doc: overview
343
344Frame Buffer Functions Reference
345--------------------------------
346
347.. kernel-doc:: include/drm/drm_framebuffer.h
348   :internal:
349
350.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
351   :export:
352
353DRM Format Handling
354===================
355
356.. kernel-doc:: include/uapi/drm/drm_fourcc.h
357   :doc: overview
358
359Format Functions Reference
360--------------------------
361
362.. kernel-doc:: include/drm/drm_fourcc.h
363   :internal:
364
365.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
366   :export:
367
368.. _kms_dumb_buffer_objects:
369
370Dumb Buffer Objects
371===================
372
373.. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
374   :doc: overview
375
376Plane Abstraction
377=================
378
379.. kernel-doc:: drivers/gpu/drm/drm_plane.c
380   :doc: overview
381
382Plane Functions Reference
383-------------------------
384
385.. kernel-doc:: include/drm/drm_plane.h
386   :internal:
387
388.. kernel-doc:: drivers/gpu/drm/drm_plane.c
389   :export:
390
391Plane Composition Functions Reference
392-------------------------------------
393
394.. kernel-doc:: drivers/gpu/drm/drm_blend.c
395   :export:
396
397Plane Damage Tracking Functions Reference
398-----------------------------------------
399
400.. kernel-doc:: drivers/gpu/drm/drm_damage_helper.c
401   :export:
402
403.. kernel-doc:: include/drm/drm_damage_helper.h
404   :internal:
405
406Plane Panic Feature
407-------------------
408
409.. kernel-doc:: drivers/gpu/drm/drm_panic.c
410   :doc: overview
411
412Plane Panic Functions Reference
413-------------------------------
414
415.. kernel-doc:: include/drm/drm_panic.h
416   :internal:
417
418.. kernel-doc:: drivers/gpu/drm/drm_panic.c
419   :export:
420
421Colorop Abstraction
422===================
423
424.. kernel-doc:: drivers/gpu/drm/drm_colorop.c
425   :doc: overview
426
427Colorop Functions Reference
428---------------------------
429
430.. kernel-doc:: include/drm/drm_colorop.h
431   :internal:
432
433.. kernel-doc:: drivers/gpu/drm/drm_colorop.c
434   :export:
435
436Display Modes Function Reference
437================================
438
439.. kernel-doc:: include/drm/drm_modes.h
440   :internal:
441
442.. kernel-doc:: drivers/gpu/drm/drm_modes.c
443   :export:
444
445Connector Abstraction
446=====================
447
448.. kernel-doc:: drivers/gpu/drm/drm_connector.c
449   :doc: overview
450
451Connector Functions Reference
452-----------------------------
453
454.. kernel-doc:: include/drm/drm_connector.h
455   :internal:
456
457.. kernel-doc:: drivers/gpu/drm/drm_connector.c
458   :export:
459
460Writeback Connectors
461--------------------
462
463.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
464  :doc: overview
465
466.. kernel-doc:: include/drm/drm_writeback.h
467  :internal:
468
469.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
470  :export:
471
472Encoder Abstraction
473===================
474
475.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
476   :doc: overview
477
478Encoder Functions Reference
479---------------------------
480
481.. kernel-doc:: include/drm/drm_encoder.h
482   :internal:
483
484.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
485   :export:
486
487KMS Locking
488===========
489
490.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
491   :doc: kms locking
492
493.. kernel-doc:: include/drm/drm_modeset_lock.h
494   :internal:
495
496.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
497   :export:
498
499KMS Properties
500==============
501
502This section of the documentation is primarily aimed at user-space developers.
503For the driver APIs, see the other sections.
504
505Requirements
506------------
507
508KMS drivers might need to add extra properties to support new features. Each
509new property introduced in a driver needs to meet a few requirements, in
510addition to the one mentioned above:
511
512* It must be standardized, documenting:
513
514  * The full, exact, name string;
515  * If the property is an enum, all the valid value name strings;
516  * What values are accepted, and what these values mean;
517  * What the property does and how it can be used;
518  * How the property might interact with other, existing properties.
519
520* It must provide a generic helper in the core code to register that
521  property on the object it attaches to.
522
523* Its content must be decoded by the core and provided in the object's
524  associated state structure. That includes anything drivers might want
525  to precompute, like struct drm_clip_rect for planes.
526
527* Its initial state must match the behavior prior to the property
528  introduction. This might be a fixed value matching what the hardware
529  does, or it may be inherited from the state the firmware left the
530  system in during boot.
531
532* An IGT test must be submitted where reasonable.
533
534For historical reasons, non-standard, driver-specific properties exist. If a KMS
535driver wants to add support for one of those properties, the requirements for
536new properties apply where possible. Additionally, the documented behavior must
537match the de facto semantics of the existing property to ensure compatibility.
538Developers of the driver that first added the property should help with those
539tasks and must ACK the documented behavior if possible.
540
541Property Types and Blob Property Support
542----------------------------------------
543
544.. kernel-doc:: drivers/gpu/drm/drm_property.c
545   :doc: overview
546
547.. kernel-doc:: include/drm/drm_property.h
548   :internal:
549
550.. kernel-doc:: drivers/gpu/drm/drm_property.c
551   :export:
552
553.. _standard_connector_properties:
554
555Standard Connector Properties
556-----------------------------
557
558.. kernel-doc:: drivers/gpu/drm/drm_connector.c
559   :doc: standard connector properties
560
561HDMI Specific Connector Properties
562----------------------------------
563
564.. kernel-doc:: drivers/gpu/drm/drm_connector.c
565   :doc: HDMI connector properties
566
567Analog TV Specific Connector Properties
568---------------------------------------
569
570.. kernel-doc:: drivers/gpu/drm/drm_connector.c
571   :doc: Analog TV Connector Properties
572
573Standard CRTC Properties
574------------------------
575
576.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
577   :doc: standard CRTC properties
578
579Standard Plane Properties
580-------------------------
581
582.. kernel-doc:: drivers/gpu/drm/drm_plane.c
583   :doc: standard plane properties
584
585.. _plane_composition_properties:
586
587Plane Composition Properties
588----------------------------
589
590.. kernel-doc:: drivers/gpu/drm/drm_blend.c
591   :doc: overview
592
593.. _damage_tracking_properties:
594
595Damage Tracking Properties
596--------------------------
597
598.. kernel-doc:: drivers/gpu/drm/drm_plane.c
599   :doc: damage tracking
600
601Color Management Properties
602---------------------------
603
604.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
605   :doc: overview
606
607Tile Group Property
608-------------------
609
610.. kernel-doc:: drivers/gpu/drm/drm_connector.c
611   :doc: Tile group
612
613Explicit Fencing Properties
614---------------------------
615
616.. kernel-doc:: drivers/gpu/drm/drm_atomic_uapi.c
617   :doc: explicit fencing properties
618
619
620Variable Refresh Properties
621---------------------------
622
623.. kernel-doc:: drivers/gpu/drm/drm_connector.c
624   :doc: Variable refresh properties
625
626Cursor Hotspot Properties
627---------------------------
628
629.. kernel-doc:: drivers/gpu/drm/drm_plane.c
630   :doc: hotspot properties
631
632Existing KMS Properties
633-----------------------
634
635The following table gives description of drm properties exposed by various
636modules/drivers. Because this table is very unwieldy, do not add any new
637properties here. Instead document them in a section above.
638
639.. csv-table::
640   :header-rows: 1
641   :file: kms-properties.csv
642
643Vertical Blanking
644=================
645
646.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
647   :doc: vblank handling
648
649Vertical Blanking and Interrupt Handling Functions Reference
650------------------------------------------------------------
651
652.. kernel-doc:: include/drm/drm_vblank.h
653   :internal:
654
655.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
656   :export:
657
658Vertical Blank Work
659===================
660
661.. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
662   :doc: vblank works
663
664Vertical Blank Work Functions Reference
665---------------------------------------
666
667.. kernel-doc:: include/drm/drm_vblank_work.h
668   :internal:
669
670.. kernel-doc:: drivers/gpu/drm/drm_vblank_work.c
671   :export:
672