Re: [PATCH v2 36/46] drm/mediatek: mtk_crtc: Dynamically find suitable CRTC DMA device

From: Fei Shao

Date: Thu Nov 26 2026 - 06:06:31 EST


On Tue, Jul 14, 2026 at 7:46 PM AngeloGioacchino Del Regno
<angelogioacchino.delregno@xxxxxxxxxxxxx> wrote:
>
> Now that the vblank and config components are being dynamically
> selected, the only hardcoded strategy that is left is selecting
> a DMA device for a CRTC that is being created.
>
> In order to support pipelines including an embedded multimedia
> controller (like MDP3) chained with the display controller and
> pipelines chaining multiple display controllers together, stop
> assuming that the first component in the pipeline is suited to
> do DMA operations and implement support to dynamically find not
> only a suitable DMA device, but also the best one.
>
> This finds the first device that provides DMA and the first one
> that is also behind an IOMMU.
>
> The criteria for selecting the best device is to prefer a DMA
> device behind an IOMMU; if not found, the first DMA capable
> one is selected instead.
>
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@xxxxxxxxxxxxx>
> ---
> drivers/gpu/drm/mediatek/mtk_crtc.c | 68 ++++++++++++++++++++++++-----
> 1 file changed, 56 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index 3cb2d1a28987..16c9ff2cfe32 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -1132,6 +1132,60 @@ struct device *mtk_crtc_dma_dev_get(struct drm_crtc *crtc)
> return mtk_crtc->dma_dev;
> }
>
> +static int mtk_crtc_find_suitable_dma_dev(struct mtk_drm_private *priv,
> + struct mtk_crtc *mtk_crtc,
> + const struct mtk_drm_path_definition *path)
> +{
> + struct mtk_ddp_comp *dma_comp = NULL, *dma_comp_mmu = NULL;
> + int i;
> +
> + for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
> + const struct mtk_drm_comp_definition *cdef = path[i].comp;

`path` points to a single `mtk_drm_path_definition`, did you mean
`&path->comp[i]`? Or use `mtk_crtc->ddp_comp[i]` directly here since
patch 38/46 switches to it anyway.

> + struct mtk_ddp_comp *comp;
> +
> + comp = mtk_ddp_comp_find_by_id(&priv->hlist,
> + cdef->type, cdef->inst_id);
> + if (!comp)
> + continue;
> +
> + /*
> + * Check if this is a legacy OVL_ADAPTOR component and, if so, this
> + * has to forcefully be the DMA device for this CRTC: assign it to
> + * dma_comp_mmu to force that.
> + */
> + if (comp->type == MTK_DISP_OVL_ADAPTOR) {
> + dma_comp_mmu = comp;
> + break;
> + }
> +
> + if (!comp->dev || !comp->dev->of_node)
> + continue;
> +
> + /* Find the first device provides DMA... */
> + if (!dma_comp) {
> + if (of_property_present(comp->dev->of_node, "#dma-cells"))
> + dma_comp = comp;
> + }
> +
> + /* ...and check if that device is also behind an IOMMU */
> + if (!of_property_present(comp->dev->of_node, "iommus"))
> + continue;

Checking `#dma-cells` (a dmaengine provider property) and unscoped
`iommus` can be fragile: if the leading plane reader has no `iommus`,
this loop keeps scanning and can pick a downstream non-plane block
that has `iommus`.
Maybe filter by `mtk_ddp_comp_layer_nr(comp, i)` to skip non-plane
components instead:

if (!mtk_ddp_comp_layer_nr(comp, i))
continue;
if (!dma_comp)
dma_comp = comp;
if (of_property_present(comp->dev->of_node, "iommus")) {
dma_comp_mmu = comp;
break;
}

Regards,
Fei