162306a36Sopenharmony_ci======================
262306a36Sopenharmony_ciAMDgpu Display Manager
362306a36Sopenharmony_ci======================
462306a36Sopenharmony_ci
562306a36Sopenharmony_ci.. contents:: Table of Contents
662306a36Sopenharmony_ci    :depth: 3
762306a36Sopenharmony_ci
862306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
962306a36Sopenharmony_ci   :doc: overview
1062306a36Sopenharmony_ci
1162306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.h
1262306a36Sopenharmony_ci   :internal:
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciLifecycle
1562306a36Sopenharmony_ci=========
1662306a36Sopenharmony_ci
1762306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
1862306a36Sopenharmony_ci   :doc: DM Lifecycle
1962306a36Sopenharmony_ci
2062306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
2162306a36Sopenharmony_ci   :functions: dm_hw_init dm_hw_fini
2262306a36Sopenharmony_ci
2362306a36Sopenharmony_ciInterrupts
2462306a36Sopenharmony_ci==========
2562306a36Sopenharmony_ci
2662306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
2762306a36Sopenharmony_ci   :doc: overview
2862306a36Sopenharmony_ci
2962306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_irq.c
3062306a36Sopenharmony_ci   :internal:
3162306a36Sopenharmony_ci
3262306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
3362306a36Sopenharmony_ci   :functions: register_hpd_handlers dm_crtc_high_irq dm_pflip_high_irq
3462306a36Sopenharmony_ci
3562306a36Sopenharmony_ciAtomic Implementation
3662306a36Sopenharmony_ci=====================
3762306a36Sopenharmony_ci
3862306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
3962306a36Sopenharmony_ci   :doc: atomic
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm.c
4262306a36Sopenharmony_ci   :functions: amdgpu_dm_atomic_check amdgpu_dm_atomic_commit_tail
4362306a36Sopenharmony_ci
4462306a36Sopenharmony_ciColor Management Properties
4562306a36Sopenharmony_ci===========================
4662306a36Sopenharmony_ci
4762306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
4862306a36Sopenharmony_ci   :doc: overview
4962306a36Sopenharmony_ci
5062306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/amdgpu_dm/amdgpu_dm_color.c
5162306a36Sopenharmony_ci   :internal:
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci
5462306a36Sopenharmony_ciDC Color Capabilities between DCN generations
5562306a36Sopenharmony_ci---------------------------------------------
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ciDRM/KMS framework defines three CRTC color correction properties: degamma,
5862306a36Sopenharmony_cicolor transformation matrix (CTM) and gamma, and two properties for degamma and
5962306a36Sopenharmony_cigamma LUT sizes. AMD DC programs some of the color correction features
6062306a36Sopenharmony_cipre-blending but DRM/KMS has not per-plane color correction properties.
6162306a36Sopenharmony_ci
6262306a36Sopenharmony_ciIn general, the DRM CRTC color properties are programmed to DC, as follows:
6362306a36Sopenharmony_ciCRTC gamma after blending, and CRTC degamma pre-blending. Although CTM is
6462306a36Sopenharmony_ciprogrammed after blending, it is mapped to DPP hw blocks (pre-blending). Other
6562306a36Sopenharmony_cicolor caps available in the hw is not currently exposed by DRM interface and
6662306a36Sopenharmony_ciare bypassed.
6762306a36Sopenharmony_ci
6862306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/dc/dc.h
6962306a36Sopenharmony_ci   :doc: color-management-caps
7062306a36Sopenharmony_ci
7162306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/dc/dc.h
7262306a36Sopenharmony_ci   :internal:
7362306a36Sopenharmony_ci
7462306a36Sopenharmony_ciThe color pipeline has undergone major changes between DCN hardware
7562306a36Sopenharmony_cigenerations. What's possible to do before and after blending depends on
7662306a36Sopenharmony_cihardware capabilities, as illustrated below by the DCN 2.0 and DCN 3.0 families
7762306a36Sopenharmony_cischemas.
7862306a36Sopenharmony_ci
7962306a36Sopenharmony_ci**DCN 2.0 family color caps and mapping**
8062306a36Sopenharmony_ci
8162306a36Sopenharmony_ci.. kernel-figure:: dcn2_cm_drm_current.svg
8262306a36Sopenharmony_ci
8362306a36Sopenharmony_ci**DCN 3.0 family color caps and mapping**
8462306a36Sopenharmony_ci
8562306a36Sopenharmony_ci.. kernel-figure:: dcn3_cm_drm_current.svg
8662306a36Sopenharmony_ci
8762306a36Sopenharmony_ciBlend Mode Properties
8862306a36Sopenharmony_ci=====================
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ciPixel blend mode is a DRM plane composition property of :c:type:`drm_plane` used to
9162306a36Sopenharmony_cidescribes how pixels from a foreground plane (fg) are composited with the
9262306a36Sopenharmony_cibackground plane (bg). Here, we present main concepts of DRM blend mode to help
9362306a36Sopenharmony_cito understand how this property is mapped to AMD DC interface. See more about
9462306a36Sopenharmony_cithis DRM property and the alpha blending equations in :ref:`DRM Plane
9562306a36Sopenharmony_ciComposition Properties <plane_composition_properties>`.
9662306a36Sopenharmony_ci
9762306a36Sopenharmony_ciBasically, a blend mode sets the alpha blending equation for plane
9862306a36Sopenharmony_cicomposition that fits the mode in which the alpha channel affects the state of
9962306a36Sopenharmony_cipixel color values and, therefore, the resulted pixel color. For
10062306a36Sopenharmony_ciexample, consider the following elements of the alpha blending equation:
10162306a36Sopenharmony_ci
10262306a36Sopenharmony_ci- *fg.rgb*: Each of the RGB component values from the foreground's pixel.
10362306a36Sopenharmony_ci- *fg.alpha*: Alpha component value from the foreground's pixel.
10462306a36Sopenharmony_ci- *bg.rgb*: Each of the RGB component values from the background.
10562306a36Sopenharmony_ci- *plane_alpha*: Plane alpha value set by the **plane "alpha" property**, see
10662306a36Sopenharmony_ci  more in :ref:`DRM Plane Composition Properties <plane_composition_properties>`.
10762306a36Sopenharmony_ci
10862306a36Sopenharmony_ciin the basic alpha blending equation::
10962306a36Sopenharmony_ci
11062306a36Sopenharmony_ci   out.rgb = alpha * fg.rgb + (1 - alpha) * bg.rgb
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_cithe alpha channel value of each pixel in a plane is ignored and only the plane
11362306a36Sopenharmony_cialpha affects the resulted pixel color values.
11462306a36Sopenharmony_ci
11562306a36Sopenharmony_ciDRM has three blend mode to define the blend formula in the plane composition:
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ci* **None**: Blend formula that ignores the pixel alpha.
11862306a36Sopenharmony_ci
11962306a36Sopenharmony_ci* **Pre-multiplied**: Blend formula that assumes the pixel color values in a
12062306a36Sopenharmony_ci  plane was already pre-multiplied by its own alpha channel before storage.
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ci* **Coverage**: Blend formula that assumes the pixel color values were not
12362306a36Sopenharmony_ci  pre-multiplied with the alpha channel values.
12462306a36Sopenharmony_ci
12562306a36Sopenharmony_ciand pre-multiplied is the default pixel blend mode, that means, when no blend
12662306a36Sopenharmony_cimode property is created or defined, DRM considers the plane's pixels has
12762306a36Sopenharmony_cipre-multiplied color values. On IGT GPU tools, the kms_plane_alpha_blend test
12862306a36Sopenharmony_ciprovides a set of subtests to verify plane alpha and blend mode properties.
12962306a36Sopenharmony_ci
13062306a36Sopenharmony_ciThe DRM blend mode and its elements are then mapped by AMDGPU display manager
13162306a36Sopenharmony_ci(DM) to program the blending configuration of the Multiple Pipe/Plane Combined
13262306a36Sopenharmony_ci(MPC), as follows:
13362306a36Sopenharmony_ci
13462306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/dc/inc/hw/mpc.h
13562306a36Sopenharmony_ci   :doc: mpc-overview
13662306a36Sopenharmony_ci
13762306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/dc/inc/hw/mpc.h
13862306a36Sopenharmony_ci   :functions: mpcc_blnd_cfg
13962306a36Sopenharmony_ci
14062306a36Sopenharmony_ciTherefore, the blending configuration for a single MPCC instance on the MPC
14162306a36Sopenharmony_citree is defined by :c:type:`mpcc_blnd_cfg`, where
14262306a36Sopenharmony_ci:c:type:`pre_multiplied_alpha` is the alpha pre-multiplied mode flag used to
14362306a36Sopenharmony_ciset :c:type:`MPCC_ALPHA_MULTIPLIED_MODE`. It controls whether alpha is
14462306a36Sopenharmony_cimultiplied (true/false), being only true for DRM pre-multiplied blend mode.
14562306a36Sopenharmony_ci:c:type:`mpcc_alpha_blend_mode` defines the alpha blend mode regarding pixel
14662306a36Sopenharmony_cialpha and plane alpha values. It sets one of the three modes for
14762306a36Sopenharmony_ci:c:type:`MPCC_ALPHA_BLND_MODE`, as described below.
14862306a36Sopenharmony_ci
14962306a36Sopenharmony_ci.. kernel-doc:: drivers/gpu/drm/amd/display/dc/inc/hw/mpc.h
15062306a36Sopenharmony_ci   :functions: mpcc_alpha_blend_mode
15162306a36Sopenharmony_ci
15262306a36Sopenharmony_ciDM then maps the elements of `enum mpcc_alpha_blend_mode` to those in the DRM
15362306a36Sopenharmony_ciblend formula, as follows:
15462306a36Sopenharmony_ci
15562306a36Sopenharmony_ci* *MPC pixel alpha* matches *DRM fg.alpha* as the alpha component value
15662306a36Sopenharmony_ci  from the plane's pixel
15762306a36Sopenharmony_ci* *MPC global alpha* matches *DRM plane_alpha* when the pixel alpha should
15862306a36Sopenharmony_ci  be ignored and, therefore, pixel values are not pre-multiplied
15962306a36Sopenharmony_ci* *MPC global gain* assumes *MPC global alpha* value when both *DRM
16062306a36Sopenharmony_ci  fg.alpha* and *DRM plane_alpha* participate in the blend equation
16162306a36Sopenharmony_ci
16262306a36Sopenharmony_ciIn short, *fg.alpha* is ignored by selecting
16362306a36Sopenharmony_ci:c:type:`MPCC_ALPHA_BLEND_MODE_GLOBAL_ALPHA`. On the other hand, (plane_alpha *
16462306a36Sopenharmony_cifg.alpha) component becomes available by selecting
16562306a36Sopenharmony_ci:c:type:`MPCC_ALPHA_BLEND_MODE_PER_PIXEL_ALPHA_COMBINED_GLOBAL_GAIN`. And the
16662306a36Sopenharmony_ci:c:type:`MPCC_ALPHA_MULTIPLIED_MODE` defines if the pixel color values are
16762306a36Sopenharmony_cipre-multiplied by alpha or not.
16862306a36Sopenharmony_ci
16962306a36Sopenharmony_ciBlend configuration flow
17062306a36Sopenharmony_ci------------------------
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ciThe alpha blending equation is configured from DRM to DC interface by the
17362306a36Sopenharmony_cifollowing path:
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci1. When updating a :c:type:`drm_plane_state <drm_plane_state>`, DM calls
17662306a36Sopenharmony_ci   :c:type:`amdgpu_dm_plane_fill_blending_from_plane_state()` that maps
17762306a36Sopenharmony_ci   :c:type:`drm_plane_state <drm_plane_state>` attributes to
17862306a36Sopenharmony_ci   :c:type:`dc_plane_info <dc_plane_info>` struct to be handled in the
17962306a36Sopenharmony_ci   OS-agnostic component (DC).
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ci2. On DC interface, :c:type:`struct mpcc_blnd_cfg <mpcc_blnd_cfg>` programs the
18262306a36Sopenharmony_ci   MPCC blend configuration considering the :c:type:`dc_plane_info
18362306a36Sopenharmony_ci   <dc_plane_info>` input from DPP.
184