xref: /linux/Documentation/gpu/drm-kms.rst (revision ba6096311ba6aed28fec237038ec986c9bf9b8e9)
12fa91d15SJani Nikula=========================
22fa91d15SJani NikulaKernel Mode Setting (KMS)
32fa91d15SJani Nikula=========================
42fa91d15SJani Nikula
52fa91d15SJani NikulaDrivers must initialize the mode setting core by calling
62fa91d15SJani Nikula:c:func:`drm_mode_config_init()` on the DRM device. The function
72fa91d15SJani Nikulainitializes the :c:type:`struct drm_device <drm_device>`
82fa91d15SJani Nikulamode_config field and never fails. Once done, mode configuration must
92fa91d15SJani Nikulabe setup by initializing the following fields.
102fa91d15SJani Nikula
112fa91d15SJani Nikula-  int min_width, min_height; int max_width, max_height;
122fa91d15SJani Nikula   Minimum and maximum width and height of the frame buffers in pixel
132fa91d15SJani Nikula   units.
142fa91d15SJani Nikula
152fa91d15SJani Nikula-  struct drm_mode_config_funcs \*funcs;
162fa91d15SJani Nikula   Mode setting functions.
172fa91d15SJani Nikula
182564d0b0SDaniel VetterOverview
192564d0b0SDaniel Vetter========
202564d0b0SDaniel Vetter
212564d0b0SDaniel Vetter.. kernel-render:: DOT
222564d0b0SDaniel Vetter   :alt: KMS Display Pipeline
232564d0b0SDaniel Vetter   :caption: KMS Display Pipeline Overview
242564d0b0SDaniel Vetter
252564d0b0SDaniel Vetter   digraph "KMS" {
262564d0b0SDaniel Vetter      node [shape=box]
272564d0b0SDaniel Vetter
282564d0b0SDaniel Vetter      subgraph cluster_static {
292564d0b0SDaniel Vetter          style=dashed
302564d0b0SDaniel Vetter          label="Static Objects"
312564d0b0SDaniel Vetter
322564d0b0SDaniel Vetter          node [bgcolor=grey style=filled]
332564d0b0SDaniel Vetter          "drm_plane A" -> "drm_crtc"
342564d0b0SDaniel Vetter          "drm_plane B" -> "drm_crtc"
352564d0b0SDaniel Vetter          "drm_crtc" -> "drm_encoder A"
362564d0b0SDaniel Vetter          "drm_crtc" -> "drm_encoder B"
372564d0b0SDaniel Vetter      }
382564d0b0SDaniel Vetter
392564d0b0SDaniel Vetter      subgraph cluster_user_created {
402564d0b0SDaniel Vetter          style=dashed
412564d0b0SDaniel Vetter          label="Userspace-Created"
422564d0b0SDaniel Vetter
432564d0b0SDaniel Vetter          node [shape=oval]
442564d0b0SDaniel Vetter          "drm_framebuffer 1" -> "drm_plane A"
452564d0b0SDaniel Vetter          "drm_framebuffer 2" -> "drm_plane B"
462564d0b0SDaniel Vetter      }
472564d0b0SDaniel Vetter
482564d0b0SDaniel Vetter      subgraph cluster_connector {
492564d0b0SDaniel Vetter          style=dashed
502564d0b0SDaniel Vetter          label="Hotpluggable"
512564d0b0SDaniel Vetter
522564d0b0SDaniel Vetter          "drm_encoder A" -> "drm_connector A"
532564d0b0SDaniel Vetter          "drm_encoder B" -> "drm_connector B"
542564d0b0SDaniel Vetter      }
552564d0b0SDaniel Vetter   }
562564d0b0SDaniel Vetter
572564d0b0SDaniel VetterThe basic object structure KMS presents to userspace is fairly simple.
582564d0b0SDaniel VetterFramebuffers (represented by :c:type:`struct drm_framebuffer <drm_framebuffer>`,
592564d0b0SDaniel Vettersee `Frame Buffer Abstraction`_) feed into planes. One or more (or even no)
602564d0b0SDaniel Vetterplanes feed their pixel data into a CRTC (represented by :c:type:`struct
612564d0b0SDaniel Vetterdrm_crtc <drm_crtc>`, see `CRTC Abstraction`_) for blending. The precise
622564d0b0SDaniel Vetterblending step is explained in more detail in `Plane Composition Properties`_ and
632564d0b0SDaniel Vetterrelated chapters.
642564d0b0SDaniel Vetter
652564d0b0SDaniel VetterFor the output routing the first step is encoders (represented by
662564d0b0SDaniel Vetter:c:type:`struct drm_encoder <drm_encoder>`, see `Encoder Abstraction`_). Those
672564d0b0SDaniel Vetterare really just internal artifacts of the helper libraries used to implement KMS
682564d0b0SDaniel Vetterdrivers. Besides that they make it unecessarily more complicated for userspace
692564d0b0SDaniel Vetterto figure out which connections between a CRTC and a connector are possible, and
702564d0b0SDaniel Vetterwhat kind of cloning is supported, they serve no purpose in the userspace API.
712564d0b0SDaniel VetterUnfortunately encoders have been exposed to userspace, hence can't remove them
722564d0b0SDaniel Vetterat this point.  Futhermore the exposed restrictions are often wrongly set by
732564d0b0SDaniel Vetterdrivers, and in many cases not powerful enough to express the real restrictions.
742564d0b0SDaniel VetterA CRTC can be connected to multiple encoders, and for an active CRTC there must
752564d0b0SDaniel Vetterbe at least one encoder.
762564d0b0SDaniel Vetter
772564d0b0SDaniel VetterThe final, and real, endpoint in the display chain is the connector (represented
782564d0b0SDaniel Vetterby :c:type:`struct drm_connector <drm_connector>`, see `Connector
792564d0b0SDaniel VetterAbstraction`_). Connectors can have different possible encoders, but the kernel
802564d0b0SDaniel Vetterdriver selects which encoder to use for each connector. The use case is DVI,
812564d0b0SDaniel Vetterwhich could switch between an analog and a digital encoder. Encoders can also
822564d0b0SDaniel Vetterdrive multiple different connectors. There is exactly one active connector for
832564d0b0SDaniel Vetterevery active encoder.
842564d0b0SDaniel Vetter
852564d0b0SDaniel VetterInternally the output pipeline is a bit more complex and matches today's
862564d0b0SDaniel Vetterhardware more closely:
872564d0b0SDaniel Vetter
882564d0b0SDaniel Vetter.. kernel-render:: DOT
892564d0b0SDaniel Vetter   :alt: KMS Output Pipeline
902564d0b0SDaniel Vetter   :caption: KMS Output Pipeline
912564d0b0SDaniel Vetter
922564d0b0SDaniel Vetter   digraph "Output Pipeline" {
932564d0b0SDaniel Vetter      node [shape=box]
942564d0b0SDaniel Vetter
952564d0b0SDaniel Vetter      subgraph {
962564d0b0SDaniel Vetter          "drm_crtc" [bgcolor=grey style=filled]
972564d0b0SDaniel Vetter      }
982564d0b0SDaniel Vetter
992564d0b0SDaniel Vetter      subgraph cluster_internal {
1002564d0b0SDaniel Vetter          style=dashed
1012564d0b0SDaniel Vetter          label="Internal Pipeline"
1022564d0b0SDaniel Vetter          {
1032564d0b0SDaniel Vetter              node [bgcolor=grey style=filled]
1042564d0b0SDaniel Vetter              "drm_encoder A";
1052564d0b0SDaniel Vetter              "drm_encoder B";
1062564d0b0SDaniel Vetter              "drm_encoder C";
1072564d0b0SDaniel Vetter          }
1082564d0b0SDaniel Vetter
1092564d0b0SDaniel Vetter          {
1102564d0b0SDaniel Vetter              node [bgcolor=grey style=filled]
1112564d0b0SDaniel Vetter              "drm_encoder B" -> "drm_bridge B"
1122564d0b0SDaniel Vetter              "drm_encoder C" -> "drm_bridge C1"
1132564d0b0SDaniel Vetter              "drm_bridge C1" -> "drm_bridge C2";
1142564d0b0SDaniel Vetter          }
1152564d0b0SDaniel Vetter      }
1162564d0b0SDaniel Vetter
1172564d0b0SDaniel Vetter      "drm_crtc" -> "drm_encoder A"
1182564d0b0SDaniel Vetter      "drm_crtc" -> "drm_encoder B"
1192564d0b0SDaniel Vetter      "drm_crtc" -> "drm_encoder C"
1202564d0b0SDaniel Vetter
1212564d0b0SDaniel Vetter
1222564d0b0SDaniel Vetter      subgraph cluster_output {
1232564d0b0SDaniel Vetter          style=dashed
1242564d0b0SDaniel Vetter          label="Outputs"
1252564d0b0SDaniel Vetter
1262564d0b0SDaniel Vetter          "drm_encoder A" -> "drm_connector A";
1272564d0b0SDaniel Vetter          "drm_bridge B" -> "drm_connector B";
1282564d0b0SDaniel Vetter          "drm_bridge C2" -> "drm_connector C";
1292564d0b0SDaniel Vetter
1302564d0b0SDaniel Vetter          "drm_panel"
1312564d0b0SDaniel Vetter      }
1322564d0b0SDaniel Vetter   }
1332564d0b0SDaniel Vetter
1342564d0b0SDaniel VetterInternally two additional helper objects come into play. First, to be able to
1352564d0b0SDaniel Vettershare code for encoders (sometimes on the same SoC, sometimes off-chip) one or
1362564d0b0SDaniel Vettermore :ref:`drm_bridges` (represented by :c:type:`struct drm_bridge
1372564d0b0SDaniel Vetter<drm_bridge>`) can be linked to an encoder. This link is static and cannot be
1382564d0b0SDaniel Vetterchanged, which means the cross-bar (if there is any) needs to be mapped between
1392564d0b0SDaniel Vetterthe CRTC and any encoders. Often for drivers with bridges there's no code left
1402564d0b0SDaniel Vetterat the encoder level. Atomic drivers can leave out all the encoder callbacks to
1412564d0b0SDaniel Vetteressentially only leave a dummy routing object behind, which is needed for
1422564d0b0SDaniel Vetterbackwards compatibility since encoders are exposed to userspace.
1432564d0b0SDaniel Vetter
1442564d0b0SDaniel VetterThe second object is for panels, represented by :c:type:`struct drm_panel
1452564d0b0SDaniel Vetter<drm_panel>`, see :ref:`drm_panel_helper`. Panels do not have a fixed binding
1462564d0b0SDaniel Vetterpoint, but are generally linked to the driver private structure that embeds
1472564d0b0SDaniel Vetter:c:type:`struct drm_connector <drm_connector>`.
1482564d0b0SDaniel Vetter
1492564d0b0SDaniel VetterNote that currently the bridge chaining and interactions with connectors and
1502564d0b0SDaniel Vetterpanels are still in-flux and not really fully sorted out yet.
15128575f16SDaniel Vetter
15228575f16SDaniel VetterKMS Core Structures and Functions
15328575f16SDaniel Vetter=================================
15428575f16SDaniel Vetter
15528575f16SDaniel Vetter.. kernel-doc:: include/drm/drm_mode_config.h
15628575f16SDaniel Vetter   :internal:
15728575f16SDaniel Vetter
1581ea35768SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_mode_config.c
1591ea35768SDaniel Vetter   :export:
1601ea35768SDaniel Vetter
161949619f3SDaniel VetterModeset Base Object Abstraction
162949619f3SDaniel Vetter===============================
163949619f3SDaniel Vetter
164b2b82c26SDaniel Vetter.. kernel-render:: DOT
165b2b82c26SDaniel Vetter   :alt: Mode Objects and Properties
166b2b82c26SDaniel Vetter   :caption: Mode Objects and Properties
167b2b82c26SDaniel Vetter
168b2b82c26SDaniel Vetter   digraph {
169b2b82c26SDaniel Vetter      node [shape=box]
170b2b82c26SDaniel Vetter
171b2b82c26SDaniel Vetter      "drm_property A" -> "drm_mode_object A"
172b2b82c26SDaniel Vetter      "drm_property A" -> "drm_mode_object B"
173b2b82c26SDaniel Vetter      "drm_property B" -> "drm_mode_object A"
174b2b82c26SDaniel Vetter   }
175b2b82c26SDaniel Vetter
176b2b82c26SDaniel VetterThe base structure for all KMS objects is :c:type:`struct drm_mode_object
177b2b82c26SDaniel Vetter<drm_mode_object>`. One of the base services it provides is tracking properties,
178b2b82c26SDaniel Vetterwhich are especially important for the atomic IOCTL (see `Atomic Mode
179b2b82c26SDaniel VetterSetting`_). The somewhat surprising part here is that properties are not
180b2b82c26SDaniel Vetterdirectly instantiated on each object, but free-standing mode objects themselves,
181b2b82c26SDaniel Vetterrepresented by :c:type:`struct drm_property <drm_property>`, which only specify
182b2b82c26SDaniel Vetterthe type and value range of a property. Any given property can be attached
183b2b82c26SDaniel Vettermultiple times to different objects using :c:func:`drm_object_attach_property()
184b2b82c26SDaniel Vetter<drm_object_attach_property>`.
185b2b82c26SDaniel Vetter
186949619f3SDaniel Vetter.. kernel-doc:: include/drm/drm_mode_object.h
187949619f3SDaniel Vetter   :internal:
188949619f3SDaniel Vetter
189949619f3SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_mode_object.c
190949619f3SDaniel Vetter   :export:
191949619f3SDaniel Vetter
1924a8e2292SDaniel VetterAtomic Mode Setting
1934a8e2292SDaniel Vetter===================
1944a8e2292SDaniel Vetter
1954a8e2292SDaniel Vetter
1964a8e2292SDaniel Vetter.. kernel-render:: DOT
1974a8e2292SDaniel Vetter   :alt: Mode Objects and Properties
1984a8e2292SDaniel Vetter   :caption: Mode Objects and Properties
1994a8e2292SDaniel Vetter
2004a8e2292SDaniel Vetter   digraph {
2014a8e2292SDaniel Vetter      node [shape=box]
2024a8e2292SDaniel Vetter
2034a8e2292SDaniel Vetter      subgraph cluster_state {
2044a8e2292SDaniel Vetter          style=dashed
2054a8e2292SDaniel Vetter          label="Free-standing state"
2064a8e2292SDaniel Vetter
2074a8e2292SDaniel Vetter          "drm_atomic_state" -> "duplicated drm_plane_state A"
2084a8e2292SDaniel Vetter          "drm_atomic_state" -> "duplicated drm_plane_state B"
2094a8e2292SDaniel Vetter          "drm_atomic_state" -> "duplicated drm_crtc_state"
2104a8e2292SDaniel Vetter          "drm_atomic_state" -> "duplicated drm_connector_state"
2114a8e2292SDaniel Vetter          "drm_atomic_state" -> "duplicated driver private state"
2124a8e2292SDaniel Vetter      }
2134a8e2292SDaniel Vetter
2144a8e2292SDaniel Vetter      subgraph cluster_current {
2154a8e2292SDaniel Vetter          style=dashed
2164a8e2292SDaniel Vetter          label="Current state"
2174a8e2292SDaniel Vetter
2184a8e2292SDaniel Vetter          "drm_device" -> "drm_plane A"
2194a8e2292SDaniel Vetter          "drm_device" -> "drm_plane B"
2204a8e2292SDaniel Vetter          "drm_device" -> "drm_crtc"
2214a8e2292SDaniel Vetter          "drm_device" -> "drm_connector"
2224a8e2292SDaniel Vetter          "drm_device" -> "driver private object"
2234a8e2292SDaniel Vetter
2244a8e2292SDaniel Vetter          "drm_plane A" -> "drm_plane_state A"
2254a8e2292SDaniel Vetter          "drm_plane B" -> "drm_plane_state B"
2264a8e2292SDaniel Vetter          "drm_crtc" -> "drm_crtc_state"
2274a8e2292SDaniel Vetter          "drm_connector" -> "drm_connector_state"
2284a8e2292SDaniel Vetter          "driver private object" -> "driver private state"
2294a8e2292SDaniel Vetter      }
2304a8e2292SDaniel Vetter
2314a8e2292SDaniel Vetter      "drm_atomic_state" -> "drm_device" [label="atomic_commit"]
2324a8e2292SDaniel Vetter      "duplicated drm_plane_state A" -> "drm_device"[style=invis]
2334a8e2292SDaniel Vetter   }
2344a8e2292SDaniel Vetter
2354a8e2292SDaniel VetterAtomic provides transactional modeset (including planes) updates, but a
2364a8e2292SDaniel Vetterbit differently from the usual transactional approach of try-commit and
2374a8e2292SDaniel Vetterrollback:
2384a8e2292SDaniel Vetter
2394a8e2292SDaniel Vetter- Firstly, no hardware changes are allowed when the commit would fail. This
2404a8e2292SDaniel Vetter  allows us to implement the DRM_MODE_ATOMIC_TEST_ONLY mode, which allows
2414a8e2292SDaniel Vetter  userspace to explore whether certain configurations would work or not.
2424a8e2292SDaniel Vetter
2434a8e2292SDaniel Vetter- This would still allow setting and rollback of just the software state,
2444a8e2292SDaniel Vetter  simplifying conversion of existing drivers. But auditing drivers for
2454a8e2292SDaniel Vetter  correctness of the atomic_check code becomes really hard with that: Rolling
2464a8e2292SDaniel Vetter  back changes in data structures all over the place is hard to get right.
2474a8e2292SDaniel Vetter
2484a8e2292SDaniel Vetter- Lastly, for backwards compatibility and to support all use-cases, atomic
2494a8e2292SDaniel Vetter  updates need to be incremental and be able to execute in parallel. Hardware
2504a8e2292SDaniel Vetter  doesn't always allow it, but where possible plane updates on different CRTCs
2514a8e2292SDaniel Vetter  should not interfere, and not get stalled due to output routing changing on
2524a8e2292SDaniel Vetter  different CRTCs.
2534a8e2292SDaniel Vetter
2544a8e2292SDaniel VetterTaken all together there's two consequences for the atomic design:
2554a8e2292SDaniel Vetter
2564a8e2292SDaniel Vetter- The overall state is split up into per-object state structures:
2574a8e2292SDaniel Vetter  :c:type:`struct drm_plane_state <drm_plane_state>` for planes, :c:type:`struct
2584a8e2292SDaniel Vetter  drm_crtc_state <drm_crtc_state>` for CRTCs and :c:type:`struct
2594a8e2292SDaniel Vetter  drm_connector_state <drm_connector_state>` for connectors. These are the only
2604a8e2292SDaniel Vetter  objects with userspace-visible and settable state. For internal state drivers
2614a8e2292SDaniel Vetter  can subclass these structures through embeddeding, or add entirely new state
2624a8e2292SDaniel Vetter  structures for their globally shared hardware functions.
2634a8e2292SDaniel Vetter
2644a8e2292SDaniel Vetter- An atomic update is assembled and validated as an entirely free-standing pile
2654a8e2292SDaniel Vetter  of structures within the :c:type:`drm_atomic_state <drm_atomic_state>`
2665fca5eceSDaniel Vetter  container. Driver private state structures are also tracked in the same
2675fca5eceSDaniel Vetter  structure; see the next chapter.  Only when a state is committed is it applied
2685fca5eceSDaniel Vetter  to the driver and modeset objects. This way rolling back an update boils down
2695fca5eceSDaniel Vetter  to releasing memory and unreferencing objects like framebuffers.
2704a8e2292SDaniel Vetter
2714a8e2292SDaniel VetterRead on in this chapter, and also in :ref:`drm_atomic_helper` for more detailed
2724a8e2292SDaniel Vettercoverage of specific topics.
2734a8e2292SDaniel Vetter
274da6c0596SDaniel VetterHandling Driver Private State
275da6c0596SDaniel Vetter-----------------------------
276da6c0596SDaniel Vetter
277da6c0596SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
278da6c0596SDaniel Vetter   :doc: handling driver private state
279da6c0596SDaniel Vetter
2802fa91d15SJani NikulaAtomic Mode Setting Function Reference
2814a8e2292SDaniel Vetter--------------------------------------
2822fa91d15SJani Nikula
2835d070be6SDaniel Vetter.. kernel-doc:: include/drm/drm_atomic.h
2842fa91d15SJani Nikula   :internal:
2852fa91d15SJani Nikula
2861ea35768SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
2871ea35768SDaniel Vetter   :export:
2881ea35768SDaniel Vetter
289d2a24edbSVille Syrjälä.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
290d2a24edbSVille Syrjälä   :internal:
291d2a24edbSVille Syrjälä
29228575f16SDaniel VetterCRTC Abstraction
29328575f16SDaniel Vetter================
29428575f16SDaniel Vetter
29528575f16SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
296d5d487ebSDaniel Vetter   :doc: overview
297d5d487ebSDaniel Vetter
298d5d487ebSDaniel VetterCRTC Functions Reference
299d5d487ebSDaniel Vetter--------------------------------
30028575f16SDaniel Vetter
30128575f16SDaniel Vetter.. kernel-doc:: include/drm/drm_crtc.h
30228575f16SDaniel Vetter   :internal:
30328575f16SDaniel Vetter
304d5d487ebSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
305d5d487ebSDaniel Vetter   :export:
306d5d487ebSDaniel Vetter
3072fa91d15SJani NikulaFrame Buffer Abstraction
308311b62d9SDaniel Vetter========================
3092fa91d15SJani Nikula
310750fb8c4SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
311750fb8c4SDaniel Vetter   :doc: overview
3122fa91d15SJani Nikula
3137520a277SDaniel VetterFrame Buffer Functions Reference
3147520a277SDaniel Vetter--------------------------------
3157520a277SDaniel Vetter
3167520a277SDaniel Vetter.. kernel-doc:: include/drm/drm_framebuffer.h
3177520a277SDaniel Vetter   :internal:
3187520a277SDaniel Vetter
3191ea35768SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
3201ea35768SDaniel Vetter   :export:
3211ea35768SDaniel Vetter
3222fa91d15SJani NikulaDRM Format Handling
323311b62d9SDaniel Vetter===================
3242fa91d15SJani Nikula
32584770cc2SLaurent Pinchart.. kernel-doc:: include/drm/drm_fourcc.h
32684770cc2SLaurent Pinchart   :internal:
32784770cc2SLaurent Pinchart
3282fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
3292fa91d15SJani Nikula   :export:
3302fa91d15SJani Nikula
3312fa91d15SJani NikulaDumb Buffer Objects
332311b62d9SDaniel Vetter===================
3332fa91d15SJani Nikula
3344f93624eSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
3354f93624eSDaniel Vetter   :doc: overview
3362fa91d15SJani Nikula
33743968d7bSDaniel VetterPlane Abstraction
33843968d7bSDaniel Vetter=================
33943968d7bSDaniel Vetter
340532b3671SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_plane.c
341532b3671SDaniel Vetter   :doc: overview
342532b3671SDaniel Vetter
34343968d7bSDaniel VetterPlane Functions Reference
34443968d7bSDaniel Vetter-------------------------
34543968d7bSDaniel Vetter
34643968d7bSDaniel Vetter.. kernel-doc:: include/drm/drm_plane.h
34743968d7bSDaniel Vetter   :internal:
34843968d7bSDaniel Vetter
34943968d7bSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_plane.c
35043968d7bSDaniel Vetter   :export:
35143968d7bSDaniel Vetter
352311b62d9SDaniel VetterDisplay Modes Function Reference
353311b62d9SDaniel Vetter================================
3542fa91d15SJani Nikula
355311b62d9SDaniel Vetter.. kernel-doc:: include/drm/drm_modes.h
356311b62d9SDaniel Vetter   :internal:
357311b62d9SDaniel Vetter
358311b62d9SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_modes.c
359311b62d9SDaniel Vetter   :export:
3602fa91d15SJani Nikula
361ae2a6da8SDaniel VetterConnector Abstraction
362ae2a6da8SDaniel Vetter=====================
363ae2a6da8SDaniel Vetter
364ae2a6da8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
365ae2a6da8SDaniel Vetter   :doc: overview
366ae2a6da8SDaniel Vetter
367ae2a6da8SDaniel VetterConnector Functions Reference
368ae2a6da8SDaniel Vetter-----------------------------
36952217195SDaniel Vetter
37052217195SDaniel Vetter.. kernel-doc:: include/drm/drm_connector.h
37152217195SDaniel Vetter   :internal:
37252217195SDaniel Vetter
37352217195SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
37452217195SDaniel Vetter   :export:
37552217195SDaniel Vetter
376935774cdSBrian StarkeyWriteback Connectors
377935774cdSBrian Starkey--------------------
378935774cdSBrian Starkey
379935774cdSBrian Starkey.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
380935774cdSBrian Starkey  :doc: overview
381935774cdSBrian Starkey
382935774cdSBrian Starkey.. kernel-doc:: drivers/gpu/drm/drm_writeback.c
383935774cdSBrian Starkey  :export:
384935774cdSBrian Starkey
385321a95aeSDaniel VetterEncoder Abstraction
386321a95aeSDaniel Vetter===================
387321a95aeSDaniel Vetter
388e03e6de0SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
389e03e6de0SDaniel Vetter   :doc: overview
390e03e6de0SDaniel Vetter
391e03e6de0SDaniel VetterEncoder Functions Reference
392e03e6de0SDaniel Vetter---------------------------
393e03e6de0SDaniel Vetter
394321a95aeSDaniel Vetter.. kernel-doc:: include/drm/drm_encoder.h
395321a95aeSDaniel Vetter   :internal:
396321a95aeSDaniel Vetter
397321a95aeSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
398321a95aeSDaniel Vetter   :export:
399321a95aeSDaniel Vetter
4002fa91d15SJani NikulaKMS Initialization and Cleanup
4012fa91d15SJani Nikula==============================
4022fa91d15SJani Nikula
4032fa91d15SJani NikulaA KMS device is abstracted and exposed as a set of planes, CRTCs,
4042fa91d15SJani Nikulaencoders and connectors. KMS drivers must thus create and initialize all
4052fa91d15SJani Nikulathose objects at load time after initializing mode setting.
4062fa91d15SJani Nikula
4072fa91d15SJani NikulaCRTCs (:c:type:`struct drm_crtc <drm_crtc>`)
4082fa91d15SJani Nikula--------------------------------------------
4092fa91d15SJani Nikula
4102fa91d15SJani NikulaA CRTC is an abstraction representing a part of the chip that contains a
4112fa91d15SJani Nikulapointer to a scanout buffer. Therefore, the number of CRTCs available
4122fa91d15SJani Nikuladetermines how many independent scanout buffers can be active at any
4132fa91d15SJani Nikulagiven time. The CRTC structure contains several fields to support this:
4142fa91d15SJani Nikulaa pointer to some video memory (abstracted as a frame buffer object), a
4152fa91d15SJani Nikuladisplay mode, and an (x, y) offset into the video memory to support
4162fa91d15SJani Nikulapanning or configurations where one piece of video memory spans multiple
4172fa91d15SJani NikulaCRTCs.
4182fa91d15SJani Nikula
4192fa91d15SJani NikulaCRTC Initialization
4202fa91d15SJani Nikula~~~~~~~~~~~~~~~~~~~
4212fa91d15SJani Nikula
4222fa91d15SJani NikulaA KMS device must create and register at least one struct
4232fa91d15SJani Nikula:c:type:`struct drm_crtc <drm_crtc>` instance. The instance is
4242fa91d15SJani Nikulaallocated and zeroed by the driver, possibly as part of a larger
4252fa91d15SJani Nikulastructure, and registered with a call to :c:func:`drm_crtc_init()`
4262fa91d15SJani Nikulawith a pointer to CRTC functions.
4272fa91d15SJani Nikula
4282fa91d15SJani Nikula
4292fa91d15SJani NikulaCleanup
4302fa91d15SJani Nikula-------
4312fa91d15SJani Nikula
4322fa91d15SJani NikulaThe DRM core manages its objects' lifetime. When an object is not needed
4332fa91d15SJani Nikulaanymore the core calls its destroy function, which must clean up and
4342fa91d15SJani Nikulafree every resource allocated for the object. Every
4352fa91d15SJani Nikula:c:func:`drm_\*_init()` call must be matched with a corresponding
4362fa91d15SJani Nikula:c:func:`drm_\*_cleanup()` call to cleanup CRTCs
4372fa91d15SJani Nikula(:c:func:`drm_crtc_cleanup()`), planes
4382fa91d15SJani Nikula(:c:func:`drm_plane_cleanup()`), encoders
4392fa91d15SJani Nikula(:c:func:`drm_encoder_cleanup()`) and connectors
4402fa91d15SJani Nikula(:c:func:`drm_connector_cleanup()`). Furthermore, connectors that
4412fa91d15SJani Nikulahave been added to sysfs must be removed by a call to
4422fa91d15SJani Nikula:c:func:`drm_connector_unregister()` before calling
4432fa91d15SJani Nikula:c:func:`drm_connector_cleanup()`.
4442fa91d15SJani Nikula
4452fa91d15SJani NikulaConnectors state change detection must be cleanup up with a call to
4462fa91d15SJani Nikula:c:func:`drm_kms_helper_poll_fini()`.
4472fa91d15SJani Nikula
4482fa91d15SJani NikulaOutput discovery and initialization example
4492fa91d15SJani Nikula-------------------------------------------
4502fa91d15SJani Nikula
45129849a69SJani Nikula.. code-block:: c
4522fa91d15SJani Nikula
4532fa91d15SJani Nikula    void intel_crt_init(struct drm_device *dev)
4542fa91d15SJani Nikula    {
4552fa91d15SJani Nikula        struct drm_connector *connector;
4562fa91d15SJani Nikula        struct intel_output *intel_output;
4572fa91d15SJani Nikula
4582fa91d15SJani Nikula        intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
4592fa91d15SJani Nikula        if (!intel_output)
4602fa91d15SJani Nikula            return;
4612fa91d15SJani Nikula
4622fa91d15SJani Nikula        connector = &intel_output->base;
4632fa91d15SJani Nikula        drm_connector_init(dev, &intel_output->base,
4642fa91d15SJani Nikula                   &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
4652fa91d15SJani Nikula
4662fa91d15SJani Nikula        drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
4672fa91d15SJani Nikula                 DRM_MODE_ENCODER_DAC);
4682fa91d15SJani Nikula
4692fa91d15SJani Nikula        drm_mode_connector_attach_encoder(&intel_output->base,
4702fa91d15SJani Nikula                          &intel_output->enc);
4712fa91d15SJani Nikula
4722fa91d15SJani Nikula        /* Set up the DDC bus. */
4732fa91d15SJani Nikula        intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
4742fa91d15SJani Nikula        if (!intel_output->ddc_bus) {
4752fa91d15SJani Nikula            dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
4762fa91d15SJani Nikula                   "failed.\n");
4772fa91d15SJani Nikula            return;
4782fa91d15SJani Nikula        }
4792fa91d15SJani Nikula
4802fa91d15SJani Nikula        intel_output->type = INTEL_OUTPUT_ANALOG;
4812fa91d15SJani Nikula        connector->interlace_allowed = 0;
4822fa91d15SJani Nikula        connector->doublescan_allowed = 0;
4832fa91d15SJani Nikula
4842fa91d15SJani Nikula        drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
4852fa91d15SJani Nikula        drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
4862fa91d15SJani Nikula
4872fa91d15SJani Nikula        drm_connector_register(connector);
4882fa91d15SJani Nikula    }
4892fa91d15SJani Nikula
4902fa91d15SJani NikulaIn the example above (taken from the i915 driver), a CRTC, connector and
4912fa91d15SJani Nikulaencoder combination is created. A device-specific i2c bus is also
4922fa91d15SJani Nikulacreated for fetching EDID data and performing monitor detection. Once
4932fa91d15SJani Nikulathe process is complete, the new connector is registered with sysfs to
4942fa91d15SJani Nikulamake its properties available to applications.
4952fa91d15SJani Nikula
4962fa91d15SJani NikulaKMS Locking
497311b62d9SDaniel Vetter===========
4982fa91d15SJani Nikula
4992fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
5002fa91d15SJani Nikula   :doc: kms locking
5012fa91d15SJani Nikula
5022fa91d15SJani Nikula.. kernel-doc:: include/drm/drm_modeset_lock.h
5032fa91d15SJani Nikula   :internal:
5042fa91d15SJani Nikula
5052fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
5062fa91d15SJani Nikula   :export:
5072fa91d15SJani Nikula
5082fa91d15SJani NikulaKMS Properties
5092fa91d15SJani Nikula==============
5102fa91d15SJani Nikula
51159e71ee7SDaniel VetterProperty Types and Blob Property Support
51259e71ee7SDaniel Vetter----------------------------------------
51359e71ee7SDaniel Vetter
514c8458c7eSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_property.c
515c8458c7eSDaniel Vetter   :doc: overview
516c8458c7eSDaniel Vetter
51759e71ee7SDaniel Vetter.. kernel-doc:: include/drm/drm_property.h
51859e71ee7SDaniel Vetter   :internal:
51959e71ee7SDaniel Vetter
52059e71ee7SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_property.c
52159e71ee7SDaniel Vetter   :export:
52259e71ee7SDaniel Vetter
5234ada6f22SDaniel VetterStandard Connector Properties
5244ada6f22SDaniel Vetter-----------------------------
5254ada6f22SDaniel Vetter
5264ada6f22SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
5274ada6f22SDaniel Vetter   :doc: standard connector properties
5284ada6f22SDaniel Vetter
52950525c33SStanislav LisovskiyHDMI Specific Connector Properties
530*ba609631SDaniel Vetter----------------------------------
53150525c33SStanislav Lisovskiy
53250525c33SStanislav Lisovskiy.. kernel-doc:: drivers/gpu/drm/drm_connector.c
53350525c33SStanislav Lisovskiy   :doc: HDMI connector properties
53450525c33SStanislav Lisovskiy
5351e4d84c6SDaniel VetterPlane Composition Properties
5361e4d84c6SDaniel Vetter----------------------------
5371e4d84c6SDaniel Vetter
5381e4d84c6SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_blend.c
5391e4d84c6SDaniel Vetter   :doc: overview
54052a9fcdaSDaniel Vetter
54152a9fcdaSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_blend.c
54252a9fcdaSDaniel Vetter   :export:
54352a9fcdaSDaniel Vetter
544a6acccf8SDaniel VetterColor Management Properties
545a6acccf8SDaniel Vetter---------------------------
546a6acccf8SDaniel Vetter
547a6acccf8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
548a6acccf8SDaniel Vetter   :doc: overview
549a6acccf8SDaniel Vetter
550a6acccf8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
551a6acccf8SDaniel Vetter   :export:
552a6acccf8SDaniel Vetter
5539498c19bSDaniel VetterTile Group Property
5549498c19bSDaniel Vetter-------------------
5559498c19bSDaniel Vetter
5569498c19bSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
5579498c19bSDaniel Vetter   :doc: Tile group
5589498c19bSDaniel Vetter
5599a83a71aSGustavo PadovanExplicit Fencing Properties
5609a83a71aSGustavo Padovan---------------------------
5619a83a71aSGustavo Padovan
5629a83a71aSGustavo Padovan.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
5639a83a71aSGustavo Padovan   :doc: explicit fencing properties
5649a83a71aSGustavo Padovan
5652fa91d15SJani NikulaExisting KMS Properties
5662fa91d15SJani Nikula-----------------------
5672fa91d15SJani Nikula
5683f0df756SDaniel VetterThe following table gives description of drm properties exposed by various
5693f0df756SDaniel Vettermodules/drivers. Because this table is very unwieldy, do not add any new
5703f0df756SDaniel Vetterproperties here. Instead document them in a section above.
5712fa91d15SJani Nikula
5722fa91d15SJani Nikula.. csv-table::
5732fa91d15SJani Nikula   :header-rows: 1
5742fa91d15SJani Nikula   :file: kms-properties.csv
5752fa91d15SJani Nikula
5762fa91d15SJani NikulaVertical Blanking
5772fa91d15SJani Nikula=================
5782fa91d15SJani Nikula
57957d30230SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
58057d30230SDaniel Vetter   :doc: vblank handling
5812fa91d15SJani Nikula
5822fa91d15SJani NikulaVertical Blanking and Interrupt Handling Functions Reference
5832fa91d15SJani Nikula------------------------------------------------------------
5842fa91d15SJani Nikula
5853ed4351aSDaniel Vetter.. kernel-doc:: include/drm/drm_vblank.h
58634a67dd7SDaniel Vetter   :internal:
5871ea35768SDaniel Vetter
5883ed4351aSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
5891ea35768SDaniel Vetter   :export:
590