brintos

brintos / linux-shallow public Read only

0
0
Text · 15.2 KiB · eaea40e Raw
489 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3==============================4 drm/komeda Arm display driver5==============================6 7The drm/komeda driver supports the Arm display processor D71 and later products,8this document gives a brief overview of driver design: how it works and why9design it like that.10 11Overview of D71 like display IPs12================================13 14From D71, Arm display IP begins to adopt a flexible and modularized15architecture. A display pipeline is made up of multiple individual and16functional pipeline stages called components, and every component has some17specific capabilities that can give the flowed pipeline pixel data a18particular processing.19 20Typical D71 components:21 22Layer23-----24Layer is the first pipeline stage, which prepares the pixel data for the next25stage. It fetches the pixel from memory, decodes it if it's AFBC, rotates the26source image, unpacks or converts YUV pixels to the device internal RGB pixels,27then adjusts the color_space of pixels if needed.28 29Scaler30------31As its name suggests, scaler takes responsibility for scaling, and D71 also32supports image enhancements by scaler.33The usage of scaler is very flexible and can be connected to layer output34for layer scaling, or connected to compositor and scale the whole display35frame and then feed the output data into wb_layer which will then write it36into memory.37 38Compositor (compiz)39-------------------40Compositor blends multiple layers or pixel data flows into one single display41frame. its output frame can be fed into post image processor for showing it on42the monitor or fed into wb_layer and written to memory at the same time.43user can also insert a scaler between compositor and wb_layer to down scale44the display frame first and then write to memory.45 46Writeback Layer (wb_layer)47--------------------------48Writeback layer does the opposite things of Layer, which connects to compiz49and writes the composition result to memory.50 51Post image processor (improc)52-----------------------------53Post image processor adjusts frame data like gamma and color space to fit the54requirements of the monitor.55 56Timing controller (timing_ctrlr)57--------------------------------58Final stage of display pipeline, Timing controller is not for the pixel59handling, but only for controlling the display timing.60 61Merger62------63D71 scaler mostly only has the half horizontal input/output capabilities64compared with Layer, like if Layer supports 4K input size, the scaler only can65support 2K input/output in the same time. To achieve the ful frame scaling, D7166introduces Layer Split, which splits the whole image to two half parts and feeds67them to two Layers A and B, and does the scaling independently. After scaling68the result need to be fed to merger to merge two part images together, and then69output merged result to compiz.70 71Splitter72--------73Similar to Layer Split, but Splitter is used for writeback, which splits the74compiz result to two parts and then feed them to two scalers.75 76Possible D71 Pipeline usage77===========================78 79Benefitting from the modularized architecture, D71 pipelines can be easily80adjusted to fit different usages. And D71 has two pipelines, which support two81types of working mode:82 83-   Dual display mode84    Two pipelines work independently and separately to drive two display outputs.85 86-   Single display mode87    Two pipelines work together to drive only one display output.88 89    On this mode, pipeline_B doesn't work independently, but outputs its90    composition result into pipeline_A, and its pixel timing also derived from91    pipeline_A.timing_ctrlr. The pipeline_B works just like a "slave" of92    pipeline_A(master)93 94Single pipeline data flow95-------------------------96 97.. kernel-render:: DOT98   :alt: Single pipeline digraph99   :caption: Single pipeline data flow100 101   digraph single_ppl {102      rankdir=LR;103 104      subgraph {105         "Memory";106         "Monitor";107      }108 109      subgraph cluster_pipeline {110          style=dashed111          node [shape=box]112          {113              node [bgcolor=grey style=dashed]114              "Scaler-0";115              "Scaler-1";116              "Scaler-0/1"117          }118 119         node [bgcolor=grey style=filled]120         "Layer-0" -> "Scaler-0"121         "Layer-1" -> "Scaler-0"122         "Layer-2" -> "Scaler-1"123         "Layer-3" -> "Scaler-1"124 125         "Layer-0" -> "Compiz"126         "Layer-1" -> "Compiz"127         "Layer-2" -> "Compiz"128         "Layer-3" -> "Compiz"129         "Scaler-0" -> "Compiz"130         "Scaler-1" -> "Compiz"131 132         "Compiz" -> "Scaler-0/1" -> "Wb_layer"133         "Compiz" -> "Improc" -> "Timing Controller"134      }135 136      "Wb_layer" -> "Memory"137      "Timing Controller" -> "Monitor"138   }139 140Dual pipeline with Slave enabled141--------------------------------142 143.. kernel-render:: DOT144   :alt: Slave pipeline digraph145   :caption: Slave pipeline enabled data flow146 147   digraph slave_ppl {148      rankdir=LR;149 150      subgraph {151         "Memory";152         "Monitor";153      }154      node [shape=box]155      subgraph cluster_pipeline_slave {156          style=dashed157          label="Slave Pipeline_B"158          node [shape=box]159          {160              node [bgcolor=grey style=dashed]161              "Slave.Scaler-0";162              "Slave.Scaler-1";163          }164 165         node [bgcolor=grey style=filled]166         "Slave.Layer-0" -> "Slave.Scaler-0"167         "Slave.Layer-1" -> "Slave.Scaler-0"168         "Slave.Layer-2" -> "Slave.Scaler-1"169         "Slave.Layer-3" -> "Slave.Scaler-1"170 171         "Slave.Layer-0" -> "Slave.Compiz"172         "Slave.Layer-1" -> "Slave.Compiz"173         "Slave.Layer-2" -> "Slave.Compiz"174         "Slave.Layer-3" -> "Slave.Compiz"175         "Slave.Scaler-0" -> "Slave.Compiz"176         "Slave.Scaler-1" -> "Slave.Compiz"177      }178 179      subgraph cluster_pipeline_master {180          style=dashed181          label="Master Pipeline_A"182          node [shape=box]183          {184              node [bgcolor=grey style=dashed]185              "Scaler-0";186              "Scaler-1";187              "Scaler-0/1"188          }189 190         node [bgcolor=grey style=filled]191         "Layer-0" -> "Scaler-0"192         "Layer-1" -> "Scaler-0"193         "Layer-2" -> "Scaler-1"194         "Layer-3" -> "Scaler-1"195 196         "Slave.Compiz" -> "Compiz"197         "Layer-0" -> "Compiz"198         "Layer-1" -> "Compiz"199         "Layer-2" -> "Compiz"200         "Layer-3" -> "Compiz"201         "Scaler-0" -> "Compiz"202         "Scaler-1" -> "Compiz"203 204         "Compiz" -> "Scaler-0/1" -> "Wb_layer"205         "Compiz" -> "Improc" -> "Timing Controller"206      }207 208      "Wb_layer" -> "Memory"209      "Timing Controller" -> "Monitor"210   }211 212Sub-pipelines for input and output213----------------------------------214 215A complete display pipeline can be easily divided into three sub-pipelines216according to the in/out usage.217 218Layer(input) pipeline219~~~~~~~~~~~~~~~~~~~~~220 221.. kernel-render:: DOT222   :alt: Layer data digraph223   :caption: Layer (input) data flow224 225   digraph layer_data_flow {226      rankdir=LR;227      node [shape=box]228 229      {230         node [bgcolor=grey style=dashed]231           "Scaler-n";232      }233 234      "Layer-n" -> "Scaler-n" -> "Compiz"235   }236 237.. kernel-render:: DOT238   :alt: Layer Split digraph239   :caption: Layer Split pipeline240 241   digraph layer_data_flow {242      rankdir=LR;243      node [shape=box]244 245      "Layer-0/1" -> "Scaler-0" -> "Merger"246      "Layer-2/3" -> "Scaler-1" -> "Merger"247      "Merger" -> "Compiz"248   }249 250Writeback(output) pipeline251~~~~~~~~~~~~~~~~~~~~~~~~~~252.. kernel-render:: DOT253   :alt: writeback digraph254   :caption: Writeback(output) data flow255 256   digraph writeback_data_flow {257      rankdir=LR;258      node [shape=box]259 260      {261         node [bgcolor=grey style=dashed]262           "Scaler-n";263      }264 265      "Compiz" -> "Scaler-n" -> "Wb_layer"266   }267 268.. kernel-render:: DOT269   :alt: split writeback digraph270   :caption: Writeback(output) Split data flow271 272   digraph writeback_data_flow {273      rankdir=LR;274      node [shape=box]275 276      "Compiz" -> "Splitter"277      "Splitter" -> "Scaler-0" -> "Merger"278      "Splitter" -> "Scaler-1" -> "Merger"279      "Merger" -> "Wb_layer"280   }281 282Display output pipeline283~~~~~~~~~~~~~~~~~~~~~~~284.. kernel-render:: DOT285   :alt: display digraph286   :caption: display output data flow287 288   digraph single_ppl {289      rankdir=LR;290      node [shape=box]291 292      "Compiz" -> "Improc" -> "Timing Controller"293   }294 295In the following section we'll see these three sub-pipelines will be handled296by KMS-plane/wb_conn/crtc respectively.297 298Komeda Resource abstraction299===========================300 301struct komeda_pipeline/component302--------------------------------303 304To fully utilize and easily access/configure the HW, the driver side also uses305a similar architecture: Pipeline/Component to describe the HW features and306capabilities, and a specific component includes two parts:307 308-  Data flow controlling.309-  Specific component capabilities and features.310 311So the driver defines a common header struct komeda_component to describe the312data flow control and all specific components are a subclass of this base313structure.314 315.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h316   :internal:317 318Resource discovery and initialization319=====================================320 321Pipeline and component are used to describe how to handle the pixel data. We322still need a @struct komeda_dev to describe the whole view of the device, and323the control-abilites of device.324 325We have &komeda_dev, &komeda_pipeline, &komeda_component. Now fill devices with326pipelines. Since komeda is not for D71 only but also intended for later products,327of course we’d better share as much as possible between different products. To328achieve this, split the komeda device into two layers: CORE and CHIP.329 330-   CORE: for common features and capabilities handling.331-   CHIP: for register programming and HW specific feature (limitation) handling.332 333CORE can access CHIP by three chip function structures:334 335-   struct komeda_dev_funcs336-   struct komeda_pipeline_funcs337-   struct komeda_component_funcs338 339.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_dev.h340   :internal:341 342Format handling343===============344 345.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h346   :internal:347.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h348   :internal:349 350Attach komeda_dev to DRM-KMS351============================352 353Komeda abstracts resources by pipeline/component, but DRM-KMS uses354crtc/plane/connector. One KMS-obj cannot represent only one single component,355since the requirements of a single KMS object cannot simply be achieved by a356single component, usually that needs multiple components to fit the requirement.357Like set mode, gamma, ctm for KMS all target on CRTC-obj, but komeda needs358compiz, improc and timing_ctrlr to work together to fit these requirements.359And a KMS-Plane may require multiple komeda resources: layer/scaler/compiz.360 361So, one KMS-Obj represents a sub-pipeline of komeda resources.362 363-   Plane: `Layer(input) pipeline`_364-   Wb_connector: `Writeback(output) pipeline`_365-   Crtc: `Display output pipeline`_366 367So, for komeda, we treat KMS crtc/plane/connector as users of pipeline and368component, and at any one time a pipeline/component only can be used by one369user. And pipeline/component will be treated as private object of DRM-KMS; the370state will be managed by drm_atomic_state as well.371 372How to map plane to Layer(input) pipeline373-----------------------------------------374 375Komeda has multiple Layer input pipelines, see:376-   `Single pipeline data flow`_377-   `Dual pipeline with Slave enabled`_378 379The easiest way is binding a plane to a fixed Layer pipeline, but consider the380komeda capabilities:381 382-   Layer Split, See `Layer(input) pipeline`_383 384    Layer_Split is quite complicated feature, which splits a big image into two385    parts and handles it by two layers and two scalers individually. But it386    imports an edge problem or effect in the middle of the image after the split.387    To avoid such a problem, it needs a complicated Split calculation and some388    special configurations to the layer and scaler. We'd better hide such HW389    related complexity to user mode.390 391-   Slave pipeline, See `Dual pipeline with Slave enabled`_392 393    Since the compiz component doesn't output alpha value, the slave pipeline394    only can be used for bottom layers composition. The komeda driver wants to395    hide this limitation to the user. The way to do this is to pick a suitable396    Layer according to plane_state->zpos.397 398So for komeda, the KMS-plane doesn't represent a fixed komeda layer pipeline,399but multiple Layers with same capabilities. Komeda will select one or more400Layers to fit the requirement of one KMS-plane.401 402Make component/pipeline to be drm_private_obj403---------------------------------------------404 405Add :c:type:`drm_private_obj` to :c:type:`komeda_component`, :c:type:`komeda_pipeline`406 407.. code-block:: c408 409    struct komeda_component {410        struct drm_private_obj obj;411        ...412    }413 414    struct komeda_pipeline {415        struct drm_private_obj obj;416        ...417    }418 419Tracking component_state/pipeline_state by drm_atomic_state420-----------------------------------------------------------421 422Add :c:type:`drm_private_state` and user to :c:type:`komeda_component_state`,423:c:type:`komeda_pipeline_state`424 425.. code-block:: c426 427    struct komeda_component_state {428        struct drm_private_state obj;429        void *binding_user;430        ...431    }432 433    struct komeda_pipeline_state {434        struct drm_private_state obj;435        struct drm_crtc *crtc;436        ...437    }438 439komeda component validation440---------------------------441 442Komeda has multiple types of components, but the process of validation are443similar, usually including the following steps:444 445.. code-block:: c446 447    int komeda_xxxx_validate(struct komeda_component_xxx xxx_comp,448                struct komeda_component_output *input_dflow,449                struct drm_plane/crtc/connector *user,450                struct drm_plane/crtc/connector_state, *user_state)451    {452         setup 1: check if component is needed, like the scaler is optional depending453                  on the user_state; if unneeded, just return, and the caller will454                  put the data flow into next stage.455         Setup 2: check user_state with component features and capabilities to see456                  if requirements can be met; if not, return fail.457         Setup 3: get component_state from drm_atomic_state, and try set to set458                  user to component; fail if component has been assigned to another459                  user already.460         Setup 3: configure the component_state, like set its input component,461                  convert user_state to component specific state.462         Setup 4: adjust the input_dflow and prepare it for the next stage.463    }464 465komeda_kms Abstraction466----------------------467 468.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_kms.h469   :internal:470 471komde_kms Functions472-------------------473.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_crtc.c474   :internal:475.. kernel-doc:: drivers/gpu/drm/arm/display/komeda/komeda_plane.c476   :internal:477 478Build komeda to be a Linux module driver479========================================480 481Now we have two level devices:482 483-   komeda_dev: describes the real display hardware.484-   komeda_kms_dev: attaches or connects komeda_dev to DRM-KMS.485 486All komeda operations are supplied or operated by komeda_dev or komeda_kms_dev,487the module driver is only a simple wrapper to pass the Linux command488(probe/remove/pm) into komeda_dev or komeda_kms_dev.489