drm-kms.rst 16.2 KB

Kernel Mode Setting (KMS)

Drivers must initialize the mode setting core by calling drmm_mode_config_init() on the DRM device. The function initializes the :c:type:`struct drm_device <drm_device>` mode_config field and never fails. Once done, mode configuration must be setup by initializing the following fields.

  • int min_width, min_height; int max_width, max_height; Minimum and maximum width and height of the frame buffers in pixel units.
  • struct drm_mode_config_funcs *funcs; Mode setting functions.

Overview

The basic object structure KMS presents to userspace is fairly simple. Framebuffers (represented by :c:type:`struct drm_framebuffer <drm_framebuffer>`, see Frame Buffer Abstraction) feed into planes. Planes are represented by :c:type:`struct drm_plane <drm_plane>`, see Plane Abstraction for more details. One or more (or even no) planes feed their pixel data into a CRTC (represented by :c:type:`struct drm_crtc <drm_crtc>`, see CRTC Abstraction) for blending. The precise blending step is explained in more detail in Plane Composition Properties and related chapters.

For the output routing the first step is encoders (represented by :c:type:`struct drm_encoder <drm_encoder>`, see Encoder Abstraction). Those are really just internal artifacts of the helper libraries used to implement KMS drivers. Besides that they make it unecessarily more complicated for userspace to figure out which connections between a CRTC and a connector are possible, and what kind of cloning is supported, they serve no purpose in the userspace API. Unfortunately encoders have been exposed to userspace, hence can't remove them at this point. Futhermore the exposed restrictions are often wrongly set by drivers, and in many cases not powerful enough to express the real restrictions. A CRTC can be connected to multiple encoders, and for an active CRTC there must be at least one encoder.

The final, and real, endpoint in the display chain is the connector (represented by :c:type:`struct drm_connector <drm_connector>`, see Connector Abstraction). Connectors can have different possible encoders, but the kernel driver selects which encoder to use for each connector. The use case is DVI, which could switch between an analog and a digital encoder. Encoders can also drive multiple different connectors. There is exactly one active connector for every active encoder.

Internally the output pipeline is a bit more complex and matches today's hardware more closely:

Internally two additional helper objects come into play. First, to be able to share code for encoders (sometimes on the same SoC, sometimes off-chip) one or more :ref:`drm_bridges` (represented by :c:type:`struct drm_bridge <drm_bridge>`) can be linked to an encoder. This link is static and cannot be changed, which means the cross-bar (if there is any) needs to be mapped between the CRTC and any encoders. Often for drivers with bridges there's no code left at the encoder level. Atomic drivers can leave out all the encoder callbacks to essentially only leave a dummy routing object behind, which is needed for backwards compatibility since encoders are exposed to userspace.

The second object is for panels, represented by :c:type:`struct drm_panel <drm_panel>`, see :ref:`drm_panel_helper`. Panels do not have a fixed binding point, but are generally linked to the driver private structure that embeds :c:type:`struct drm_connector <drm_connector>`.

Note that currently the bridge chaining and interactions with connectors and panels are still in-flux and not really fully sorted out yet.

KMS Core Structures and Functions

Modeset Base Object Abstraction

The base structure for all KMS objects is :c:type:`struct drm_mode_object <drm_mode_object>`. One of the base services it provides is tracking properties, which are especially important for the atomic IOCTL (see Atomic Mode Setting). The somewhat surprising part here is that properties are not directly instantiated on each object, but free-standing mode objects themselves, represented by :c:type:`struct drm_property <drm_property>`, which only specify the type and value range of a property. Any given property can be attached multiple times to different objects using drm_object_attach_property().

Atomic Mode Setting

Atomic provides transactional modeset (including planes) updates, but a bit differently from the usual transactional approach of try-commit and rollback:

  • Firstly, no hardware changes are allowed when the commit would fail. This allows us to implement the DRM_MODE_ATOMIC_TEST_ONLY mode, which allows userspace to explore whether certain configurations would work or not.
  • This would still allow setting and rollback of just the software state, simplifying conversion of existing drivers. But auditing drivers for correctness of the atomic_check code becomes really hard with that: Rolling back changes in data structures all over the place is hard to get right.
  • Lastly, for backwards compatibility and to support all use-cases, atomic updates need to be incremental and be able to execute in parallel. Hardware doesn't always allow it, but where possible plane updates on different CRTCs should not interfere, and not get stalled due to output routing changing on different CRTCs.

Taken all together there's two consequences for the atomic design:

Locking of atomic state structures is internally using :c:type:`struct drm_modeset_lock <drm_modeset_lock>`. As a general rule the locking shouldn't be exposed to drivers, instead the right locks should be automatically acquired by any function that duplicates or peeks into a state, like e.g. drm_atomic_get_crtc_state(). Locking only protects the software data structure, ordering of committing state changes to hardware is sequenced using :c:type:`struct drm_crtc_commit <drm_crtc_commit>`.

Read on in this chapter, and also in :ref:`drm_atomic_helper` for more detailed coverage of specific topics.

Handling Driver Private State

Atomic Mode Setting Function Reference

Atomic Mode Setting IOCTL and UAPI Functions

CRTC Abstraction

CRTC Functions Reference

Frame Buffer Abstraction

Frame Buffer Functions Reference

DRM Format Handling

Format Functions Reference

Dumb Buffer Objects

Plane Abstraction

Plane Functions Reference

Display Modes Function Reference

Connector Abstraction

Connector Functions Reference

Writeback Connectors

Encoder Abstraction

Encoder Functions Reference

KMS Locking

KMS Properties

Property Types and Blob Property Support

Standard Connector Properties

HDMI Specific Connector Properties

Standard CRTC Properties

Plane Composition Properties

FB_DAMAGE_CLIPS

Color Management Properties

Tile Group Property

Explicit Fencing Properties

Variable Refresh Properties

Existing KMS Properties

The following table gives description of drm properties exposed by various modules/drivers. Because this table is very unwieldy, do not add any new properties here. Instead document them in a section above.

Vertical Blanking

Vertical Blanking and Interrupt Handling Functions Reference

Vertical Blank Work

Vertical Blank Work Functions Reference