On Tue, Jul 14, 2026 at 7:45 PM AngeloGioacchino Del Regno
<[email protected]> wrote:
>
> In preparation for adding support for newer, more complex, display
> controllers like the ones found in the MediaTek Kompanio Ultra and
> Genio Pro 5100 (MT8196/MT8894), add support for multi-stage layers
> as in newer hardware, there is a special strategy using multiple
> hardware components of one (or multiple) display controller(s) to
> form one single layer.
>
> Multi-stage layers are one more step towards extra flexibility of
> the Display Subsystem, making it possible to change capabilities
> of Display Controller Pipelines depending on the final application
> of a board: for example, one board may choose to use fewer layers
> per pipeline to achieve more pipelines (more concurrent outputs),
> or more layers to achieve less, but more capable (as in offloading
> and in achievable bandwidth) concurrent outputs.
>
> This currently adds boilerplate to support this hardware, but does
> not yet implement the IP-specific support for MT8196/8894, which
> will be done after all preparation is done.
>
> Signed-off-by: AngeloGioacchino Del Regno 
> <[email protected]>
> ---
>  drivers/gpu/drm/mediatek/mtk_crtc.c           | 304 ++++++++++++------
>  drivers/gpu/drm/mediatek/mtk_ddp_comp.h       |  15 +-
>  drivers/gpu/drm/mediatek/mtk_disp_drv.h       |  12 +-
>  drivers/gpu/drm/mediatek/mtk_disp_ovl.c       |  12 +-
>  .../gpu/drm/mediatek/mtk_disp_ovl_adaptor.c   |   2 +-
>  drivers/gpu/drm/mediatek/mtk_disp_rdma.c      |   9 +-
>  drivers/gpu/drm/mediatek/mtk_disp_wdma.c      |   2 +-
>  7 files changed, 246 insertions(+), 110 deletions(-)
>
[snip]
> @@ -992,15 +974,15 @@ static int mtk_crtc_init_comp_planes(struct drm_device 
> *drm_dev,
>                                      struct mtk_crtc *mtk_crtc,
>                                      int comp_idx, int pipe)
>  {
> -       int num_planes = mtk_crtc_num_comp_planes(mtk_crtc, comp_idx);
>         struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[comp_idx];
> +       unsigned int num_planes = mtk_ddp_comp_layer_nr(comp, comp_idx);
>         int i, ret;
>
>         for (i = 0; i < num_planes; i++) {
> -               ret = mtk_plane_init(drm_dev,
> -                               &mtk_crtc->planes[mtk_crtc->layer_nr],
> -                               BIT(pipe),
> -                               mtk_crtc_plane_type(mtk_crtc->layer_nr, 
> num_planes),
> +               struct mtk_crtc_hw_layer *hwlayer = 
> &mtk_crtc->hwlayers[mtk_crtc->hwlayer_nr];
> +
> +               ret = mtk_plane_init(drm_dev, &hwlayer->plane, BIT(pipe),
> +                               mtk_crtc_plane_type(mtk_crtc->hwlayer_nr, 
> num_planes),

I hope it's not too late for new comments...

IIUC, mtk_crtc->hwlayer_nr is the CRTC-wide plane index, while
num_planes is only the plane count of the current component.
When a CRTC spans multiple 1-plane components (such as four EXDMA
blocks on MT8196), hwlayer_nr is 1..3 but num_planes - 1 is 0, so no
cursor plane is created.
You might need to forward the CRTC total num_comp_planes to
mtk_crtc_plane_type() instead.

>                                 mtk_ddp_comp_supported_rotations(comp),
>                                 mtk_ddp_comp_get_blend_modes(comp),
>                                 mtk_ddp_comp_get_formats(comp),
[snip]
> +static int mtk_crtc_init_layer_stages(struct mtk_crtc *mtk_crtc)
> +{
> +       unsigned int prev_master_layer_component = UINT_MAX;
> +       unsigned int master_layer_component = 0;
> +       unsigned int comp_idx;
> +
> +       for (comp_idx = 0; comp_idx < mtk_crtc->ddp_comp_nr; comp_idx++) {
> +               struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[comp_idx];
> +               struct mtk_crtc_hw_layer *hwlayer = NULL;
[snip]
> +               if (master_layer_component != prev_master_layer_component) {
> +                       hwlayer = mtk_crtc_find_hwlayer_with_comp(mtk_crtc, 
> master_layer_component);
> +                       if (!hwlayer) {
> +                               drm_err(mtk_crtc->base.dev,
> +                                       "Could not find layer master for 
> %d!\n",
> +                                       master_layer_component);
> +                               continue;
> +                       }
> +                       prev_master_layer_component = master_layer_component;
> +               }
> +
> +               /* Add the newly found layer stage to the correct layer 
> master */
> +               hwlayer->layer_stages[hwlayer->layer_stages_nr] = comp_idx;
> +               hwlayer->layer_stages_nr++;

hwlayer is declared as NULL inside the loop. On a second stage
component for the same master layer, the lookup above is skipped, so
dereferencing hwlayer leads to crashes. Declare hwlayer outside the
loop.

>         }
>         return 0;
>  }
> @@ -1039,6 +1112,7 @@ int mtk_crtc_create(struct drm_device *drm_dev,
>         struct mtk_ddp_comp *dma_comp;
>         struct mtk_crtc *mtk_crtc;
>         unsigned int num_comp_planes = 0;
> +       unsigned int max_comp_stages = 0;
>         int ret;
>         int i, j;
>         bool has_ctm = false;
> @@ -1121,20 +1195,54 @@ int mtk_crtc_create(struct drm_device *drm_dev,
>                                                 &mtk_crtc->base);
>         }
>
> -       for (i = 0; i < mtk_crtc->ddp_comp_nr; i++)
> -               num_comp_planes += mtk_crtc_num_comp_planes(mtk_crtc, i);
> +       for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
> +               struct mtk_ddp_comp *comp = mtk_crtc->ddp_comp[i];
> +
> +               num_comp_planes += mtk_ddp_comp_layer_nr(comp, 0);

Passing 0 instead of i here skips the `pipeline_index > 0` check in
mtk_rdma_layer_nr() and over-counts num_comp_planes (also carried into
patch 38/46).
Pass i (j in patch 38/46) as the pipeline index.

> +               max_comp_stages = MAX(mtk_ddp_comp_stage_nr(comp), 
> max_comp_stages);
> +       }
[snip]

Regards,
Fei

Reply via email to