xref: /linux/Documentation/gpu/drm-kms.rst (revision da6c05969785a0f4108a089ef33c55f46ae21775)
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>`
2664a8e2292SDaniel Vetter  container. Again drivers can subclass that container for their own state
2674a8e2292SDaniel Vetter  structure tracking needs. Only when a state is committed is it applied to the
2684a8e2292SDaniel Vetter  driver and modeset objects. This way rolling back an update boils down to
2694a8e2292SDaniel Vetter  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
274*da6c0596SDaniel VetterHandling Driver Private State
275*da6c0596SDaniel Vetter-----------------------------
276*da6c0596SDaniel Vetter
277*da6c0596SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
278*da6c0596SDaniel Vetter   :doc: handling driver private state
279*da6c0596SDaniel 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
28928575f16SDaniel VetterCRTC Abstraction
29028575f16SDaniel Vetter================
29128575f16SDaniel Vetter
29228575f16SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
293d5d487ebSDaniel Vetter   :doc: overview
294d5d487ebSDaniel Vetter
295d5d487ebSDaniel VetterCRTC Functions Reference
296d5d487ebSDaniel Vetter--------------------------------
29728575f16SDaniel Vetter
29828575f16SDaniel Vetter.. kernel-doc:: include/drm/drm_crtc.h
29928575f16SDaniel Vetter   :internal:
30028575f16SDaniel Vetter
301d5d487ebSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_crtc.c
302d5d487ebSDaniel Vetter   :export:
303d5d487ebSDaniel Vetter
3042fa91d15SJani NikulaFrame Buffer Abstraction
305311b62d9SDaniel Vetter========================
3062fa91d15SJani Nikula
307750fb8c4SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
308750fb8c4SDaniel Vetter   :doc: overview
3092fa91d15SJani Nikula
3107520a277SDaniel VetterFrame Buffer Functions Reference
3117520a277SDaniel Vetter--------------------------------
3127520a277SDaniel Vetter
3137520a277SDaniel Vetter.. kernel-doc:: include/drm/drm_framebuffer.h
3147520a277SDaniel Vetter   :internal:
3157520a277SDaniel Vetter
3161ea35768SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_framebuffer.c
3171ea35768SDaniel Vetter   :export:
3181ea35768SDaniel Vetter
3192fa91d15SJani NikulaDRM Format Handling
320311b62d9SDaniel Vetter===================
3212fa91d15SJani Nikula
32284770cc2SLaurent Pinchart.. kernel-doc:: include/drm/drm_fourcc.h
32384770cc2SLaurent Pinchart   :internal:
32484770cc2SLaurent Pinchart
3252fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_fourcc.c
3262fa91d15SJani Nikula   :export:
3272fa91d15SJani Nikula
3282fa91d15SJani NikulaDumb Buffer Objects
329311b62d9SDaniel Vetter===================
3302fa91d15SJani Nikula
3314f93624eSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_dumb_buffers.c
3324f93624eSDaniel Vetter   :doc: overview
3332fa91d15SJani Nikula
33443968d7bSDaniel VetterPlane Abstraction
33543968d7bSDaniel Vetter=================
33643968d7bSDaniel Vetter
337532b3671SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_plane.c
338532b3671SDaniel Vetter   :doc: overview
339532b3671SDaniel Vetter
34043968d7bSDaniel VetterPlane Functions Reference
34143968d7bSDaniel Vetter-------------------------
34243968d7bSDaniel Vetter
34343968d7bSDaniel Vetter.. kernel-doc:: include/drm/drm_plane.h
34443968d7bSDaniel Vetter   :internal:
34543968d7bSDaniel Vetter
34643968d7bSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_plane.c
34743968d7bSDaniel Vetter   :export:
34843968d7bSDaniel Vetter
349311b62d9SDaniel VetterDisplay Modes Function Reference
350311b62d9SDaniel Vetter================================
3512fa91d15SJani Nikula
352311b62d9SDaniel Vetter.. kernel-doc:: include/drm/drm_modes.h
353311b62d9SDaniel Vetter   :internal:
354311b62d9SDaniel Vetter
355311b62d9SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_modes.c
356311b62d9SDaniel Vetter   :export:
3572fa91d15SJani Nikula
358ae2a6da8SDaniel VetterConnector Abstraction
359ae2a6da8SDaniel Vetter=====================
360ae2a6da8SDaniel Vetter
361ae2a6da8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
362ae2a6da8SDaniel Vetter   :doc: overview
363ae2a6da8SDaniel Vetter
364ae2a6da8SDaniel VetterConnector Functions Reference
365ae2a6da8SDaniel Vetter-----------------------------
36652217195SDaniel Vetter
36752217195SDaniel Vetter.. kernel-doc:: include/drm/drm_connector.h
36852217195SDaniel Vetter   :internal:
36952217195SDaniel Vetter
37052217195SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
37152217195SDaniel Vetter   :export:
37252217195SDaniel Vetter
373321a95aeSDaniel VetterEncoder Abstraction
374321a95aeSDaniel Vetter===================
375321a95aeSDaniel Vetter
376e03e6de0SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
377e03e6de0SDaniel Vetter   :doc: overview
378e03e6de0SDaniel Vetter
379e03e6de0SDaniel VetterEncoder Functions Reference
380e03e6de0SDaniel Vetter---------------------------
381e03e6de0SDaniel Vetter
382321a95aeSDaniel Vetter.. kernel-doc:: include/drm/drm_encoder.h
383321a95aeSDaniel Vetter   :internal:
384321a95aeSDaniel Vetter
385321a95aeSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_encoder.c
386321a95aeSDaniel Vetter   :export:
387321a95aeSDaniel Vetter
3882fa91d15SJani NikulaKMS Initialization and Cleanup
3892fa91d15SJani Nikula==============================
3902fa91d15SJani Nikula
3912fa91d15SJani NikulaA KMS device is abstracted and exposed as a set of planes, CRTCs,
3922fa91d15SJani Nikulaencoders and connectors. KMS drivers must thus create and initialize all
3932fa91d15SJani Nikulathose objects at load time after initializing mode setting.
3942fa91d15SJani Nikula
3952fa91d15SJani NikulaCRTCs (:c:type:`struct drm_crtc <drm_crtc>`)
3962fa91d15SJani Nikula--------------------------------------------
3972fa91d15SJani Nikula
3982fa91d15SJani NikulaA CRTC is an abstraction representing a part of the chip that contains a
3992fa91d15SJani Nikulapointer to a scanout buffer. Therefore, the number of CRTCs available
4002fa91d15SJani Nikuladetermines how many independent scanout buffers can be active at any
4012fa91d15SJani Nikulagiven time. The CRTC structure contains several fields to support this:
4022fa91d15SJani Nikulaa pointer to some video memory (abstracted as a frame buffer object), a
4032fa91d15SJani Nikuladisplay mode, and an (x, y) offset into the video memory to support
4042fa91d15SJani Nikulapanning or configurations where one piece of video memory spans multiple
4052fa91d15SJani NikulaCRTCs.
4062fa91d15SJani Nikula
4072fa91d15SJani NikulaCRTC Initialization
4082fa91d15SJani Nikula~~~~~~~~~~~~~~~~~~~
4092fa91d15SJani Nikula
4102fa91d15SJani NikulaA KMS device must create and register at least one struct
4112fa91d15SJani Nikula:c:type:`struct drm_crtc <drm_crtc>` instance. The instance is
4122fa91d15SJani Nikulaallocated and zeroed by the driver, possibly as part of a larger
4132fa91d15SJani Nikulastructure, and registered with a call to :c:func:`drm_crtc_init()`
4142fa91d15SJani Nikulawith a pointer to CRTC functions.
4152fa91d15SJani Nikula
4162fa91d15SJani Nikula
4172fa91d15SJani NikulaCleanup
4182fa91d15SJani Nikula-------
4192fa91d15SJani Nikula
4202fa91d15SJani NikulaThe DRM core manages its objects' lifetime. When an object is not needed
4212fa91d15SJani Nikulaanymore the core calls its destroy function, which must clean up and
4222fa91d15SJani Nikulafree every resource allocated for the object. Every
4232fa91d15SJani Nikula:c:func:`drm_\*_init()` call must be matched with a corresponding
4242fa91d15SJani Nikula:c:func:`drm_\*_cleanup()` call to cleanup CRTCs
4252fa91d15SJani Nikula(:c:func:`drm_crtc_cleanup()`), planes
4262fa91d15SJani Nikula(:c:func:`drm_plane_cleanup()`), encoders
4272fa91d15SJani Nikula(:c:func:`drm_encoder_cleanup()`) and connectors
4282fa91d15SJani Nikula(:c:func:`drm_connector_cleanup()`). Furthermore, connectors that
4292fa91d15SJani Nikulahave been added to sysfs must be removed by a call to
4302fa91d15SJani Nikula:c:func:`drm_connector_unregister()` before calling
4312fa91d15SJani Nikula:c:func:`drm_connector_cleanup()`.
4322fa91d15SJani Nikula
4332fa91d15SJani NikulaConnectors state change detection must be cleanup up with a call to
4342fa91d15SJani Nikula:c:func:`drm_kms_helper_poll_fini()`.
4352fa91d15SJani Nikula
4362fa91d15SJani NikulaOutput discovery and initialization example
4372fa91d15SJani Nikula-------------------------------------------
4382fa91d15SJani Nikula
43929849a69SJani Nikula.. code-block:: c
4402fa91d15SJani Nikula
4412fa91d15SJani Nikula    void intel_crt_init(struct drm_device *dev)
4422fa91d15SJani Nikula    {
4432fa91d15SJani Nikula        struct drm_connector *connector;
4442fa91d15SJani Nikula        struct intel_output *intel_output;
4452fa91d15SJani Nikula
4462fa91d15SJani Nikula        intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL);
4472fa91d15SJani Nikula        if (!intel_output)
4482fa91d15SJani Nikula            return;
4492fa91d15SJani Nikula
4502fa91d15SJani Nikula        connector = &intel_output->base;
4512fa91d15SJani Nikula        drm_connector_init(dev, &intel_output->base,
4522fa91d15SJani Nikula                   &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA);
4532fa91d15SJani Nikula
4542fa91d15SJani Nikula        drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs,
4552fa91d15SJani Nikula                 DRM_MODE_ENCODER_DAC);
4562fa91d15SJani Nikula
4572fa91d15SJani Nikula        drm_mode_connector_attach_encoder(&intel_output->base,
4582fa91d15SJani Nikula                          &intel_output->enc);
4592fa91d15SJani Nikula
4602fa91d15SJani Nikula        /* Set up the DDC bus. */
4612fa91d15SJani Nikula        intel_output->ddc_bus = intel_i2c_create(dev, GPIOA, "CRTDDC_A");
4622fa91d15SJani Nikula        if (!intel_output->ddc_bus) {
4632fa91d15SJani Nikula            dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration "
4642fa91d15SJani Nikula                   "failed.\n");
4652fa91d15SJani Nikula            return;
4662fa91d15SJani Nikula        }
4672fa91d15SJani Nikula
4682fa91d15SJani Nikula        intel_output->type = INTEL_OUTPUT_ANALOG;
4692fa91d15SJani Nikula        connector->interlace_allowed = 0;
4702fa91d15SJani Nikula        connector->doublescan_allowed = 0;
4712fa91d15SJani Nikula
4722fa91d15SJani Nikula        drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs);
4732fa91d15SJani Nikula        drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs);
4742fa91d15SJani Nikula
4752fa91d15SJani Nikula        drm_connector_register(connector);
4762fa91d15SJani Nikula    }
4772fa91d15SJani Nikula
4782fa91d15SJani NikulaIn the example above (taken from the i915 driver), a CRTC, connector and
4792fa91d15SJani Nikulaencoder combination is created. A device-specific i2c bus is also
4802fa91d15SJani Nikulacreated for fetching EDID data and performing monitor detection. Once
4812fa91d15SJani Nikulathe process is complete, the new connector is registered with sysfs to
4822fa91d15SJani Nikulamake its properties available to applications.
4832fa91d15SJani Nikula
4842fa91d15SJani NikulaKMS Locking
485311b62d9SDaniel Vetter===========
4862fa91d15SJani Nikula
4872fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
4882fa91d15SJani Nikula   :doc: kms locking
4892fa91d15SJani Nikula
4902fa91d15SJani Nikula.. kernel-doc:: include/drm/drm_modeset_lock.h
4912fa91d15SJani Nikula   :internal:
4922fa91d15SJani Nikula
4932fa91d15SJani Nikula.. kernel-doc:: drivers/gpu/drm/drm_modeset_lock.c
4942fa91d15SJani Nikula   :export:
4952fa91d15SJani Nikula
4962fa91d15SJani NikulaKMS Properties
4972fa91d15SJani Nikula==============
4982fa91d15SJani Nikula
49959e71ee7SDaniel VetterProperty Types and Blob Property Support
50059e71ee7SDaniel Vetter----------------------------------------
50159e71ee7SDaniel Vetter
502c8458c7eSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_property.c
503c8458c7eSDaniel Vetter   :doc: overview
504c8458c7eSDaniel Vetter
50559e71ee7SDaniel Vetter.. kernel-doc:: include/drm/drm_property.h
50659e71ee7SDaniel Vetter   :internal:
50759e71ee7SDaniel Vetter
50859e71ee7SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_property.c
50959e71ee7SDaniel Vetter   :export:
51059e71ee7SDaniel Vetter
5114ada6f22SDaniel VetterStandard Connector Properties
5124ada6f22SDaniel Vetter-----------------------------
5134ada6f22SDaniel Vetter
5144ada6f22SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
5154ada6f22SDaniel Vetter   :doc: standard connector properties
5164ada6f22SDaniel Vetter
5171e4d84c6SDaniel VetterPlane Composition Properties
5181e4d84c6SDaniel Vetter----------------------------
5191e4d84c6SDaniel Vetter
5201e4d84c6SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_blend.c
5211e4d84c6SDaniel Vetter   :doc: overview
52252a9fcdaSDaniel Vetter
52352a9fcdaSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_blend.c
52452a9fcdaSDaniel Vetter   :export:
52552a9fcdaSDaniel Vetter
526a6acccf8SDaniel VetterColor Management Properties
527a6acccf8SDaniel Vetter---------------------------
528a6acccf8SDaniel Vetter
529a6acccf8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
530a6acccf8SDaniel Vetter   :doc: overview
531a6acccf8SDaniel Vetter
532a6acccf8SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_color_mgmt.c
533a6acccf8SDaniel Vetter   :export:
534a6acccf8SDaniel Vetter
5359498c19bSDaniel VetterTile Group Property
5369498c19bSDaniel Vetter-------------------
5379498c19bSDaniel Vetter
5389498c19bSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_connector.c
5399498c19bSDaniel Vetter   :doc: Tile group
5409498c19bSDaniel Vetter
5419a83a71aSGustavo PadovanExplicit Fencing Properties
5429a83a71aSGustavo Padovan---------------------------
5439a83a71aSGustavo Padovan
5449a83a71aSGustavo Padovan.. kernel-doc:: drivers/gpu/drm/drm_atomic.c
5459a83a71aSGustavo Padovan   :doc: explicit fencing properties
5469a83a71aSGustavo Padovan
5472fa91d15SJani NikulaExisting KMS Properties
5482fa91d15SJani Nikula-----------------------
5492fa91d15SJani Nikula
5502fa91d15SJani NikulaThe following table gives description of drm properties exposed by
5512fa91d15SJani Nikulavarious modules/drivers.
5522fa91d15SJani Nikula
5532fa91d15SJani Nikula.. csv-table::
5542fa91d15SJani Nikula   :header-rows: 1
5552fa91d15SJani Nikula   :file: kms-properties.csv
5562fa91d15SJani Nikula
5572fa91d15SJani NikulaVertical Blanking
5582fa91d15SJani Nikula=================
5592fa91d15SJani Nikula
56057d30230SDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
56157d30230SDaniel Vetter   :doc: vblank handling
5622fa91d15SJani Nikula
5632fa91d15SJani NikulaVertical Blanking and Interrupt Handling Functions Reference
5642fa91d15SJani Nikula------------------------------------------------------------
5652fa91d15SJani Nikula
5663ed4351aSDaniel Vetter.. kernel-doc:: include/drm/drm_vblank.h
56734a67dd7SDaniel Vetter   :internal:
5681ea35768SDaniel Vetter
5693ed4351aSDaniel Vetter.. kernel-doc:: drivers/gpu/drm/drm_vblank.c
5701ea35768SDaniel Vetter   :export:
571