Linux-ARM-Kernel Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: "CK Hu (胡俊光)" <ck.hu@mediatek.com>
To: AngeloGioacchino Del Regno
	<angelogioacchino.delregno@collabora.com>,
	"chunkuang.hu@kernel.org" <chunkuang.hu@kernel.org>
Cc: "robh@kernel.org" <robh@kernel.org>,
	"tzimmermann@suse.de" <tzimmermann@suse.de>,
	"simona@ffwll.ch" <simona@ffwll.ch>,
	"mripard@kernel.org" <mripard@kernel.org>,
	"kernel@collabora.com" <kernel@collabora.com>,
	"linux-mediatek@lists.infradead.org"
	<linux-mediatek@lists.infradead.org>,
	"maarten.lankhorst@linux.intel.com"
	<maarten.lankhorst@linux.intel.com>,
	"dri-devel@lists.freedesktop.org"
	<dri-devel@lists.freedesktop.org>,
	"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>,
	"conor+dt@kernel.org" <conor+dt@kernel.org>,
	"devicetree@vger.kernel.org" <devicetree@vger.kernel.org>,
	"krzk+dt@kernel.org" <krzk+dt@kernel.org>,
	"p.zabel@pengutronix.de" <p.zabel@pengutronix.de>,
	"airlied@gmail.com" <airlied@gmail.com>,
	"Justin Yeh (葉英茂)" <Justin.Yeh@mediatek.com>,
	"matthias.bgg@gmail.com" <matthias.bgg@gmail.com>,
	"linux-arm-kernel@lists.infradead.org"
	<linux-arm-kernel@lists.infradead.org>,
	"Jason-JH Lin (林睿祥)" <Jason-JH.Lin@mediatek.com>
Subject: Re: [PATCH 06/42] drm/mediatek: Use hashtable for components discovery and registration
Date: Mon, 6 Jul 2026 07:02:33 +0000	[thread overview]
Message-ID: <79f44c827c78fd823300509c22058f2b6f3600b6.camel@mediatek.com> (raw)
In-Reply-To: <20260701122057.19648-7-angelogioacchino.delregno@collabora.com>

On Wed, 2026-07-01 at 14:20 +0200, AngeloGioacchino Del Regno wrote:
> As a preparation for refactoring the concept of hardware component
> identification, search, and final usage, remove the ddp_comp array
> of components and replace it with a hashtable, indexed by ID.
> 
> Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_crtc.c     | 44 ++++++++++++++++-------
>  drivers/gpu/drm/mediatek/mtk_ddp_comp.c | 48 ++++++++++++++++++-------
>  drivers/gpu/drm/mediatek/mtk_ddp_comp.h | 23 +++++++++++-
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c  |  7 ++--
>  drivers/gpu/drm/mediatek/mtk_drm_drv.h  |  2 +-
>  5 files changed, 94 insertions(+), 30 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index f39f197057a7..3f4d6ab1bfc2 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -725,8 +725,12 @@ static void mtk_crtc_update_output(struct drm_crtc *crtc,
>  		crtc_state->connectors_changed, encoder_mask, crtc_index);
>  
>  	for (i = 0; i < mtk_crtc->num_conn_routes; i++) {
> -		unsigned int comp_id = mtk_crtc->conn_routes[i].route_ddp;
> -		struct mtk_ddp_comp *comp = &priv->ddp_comp[comp_id];
> +		const struct mtk_drm_route *conn_route = &mtk_crtc->conn_routes[i];
> +		struct mtk_ddp_comp *comp;
> +
> +		comp = mtk_ddp_comp_find_by_id(&priv->hlist, conn_route->route_ddp);

I don't know why you invent conn_route? Keep comp_id use it here looks the same.

> +		if (!comp)
> +			continue;

In original code, it never check comp is null or not.
I think it base on an assumption that it would not be null.
If it's null here, print error message and it's not necessary to do the rest thing.

>  
>  		if (comp->encoder_index >= 0 &&
>  		    (encoder_mask & BIT(comp->encoder_index))) {
> @@ -1028,10 +1032,11 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
>  {
>  	struct mtk_drm_private *priv = drm_dev->dev_private;
>  	struct device *dev = drm_dev->dev;
> +	struct mtk_ddp_comp *dma_comp;
>  	struct mtk_crtc *mtk_crtc;
>  	unsigned int num_comp_planes = 0;
>  	int ret;
> -	int i;
> +	int i, j;
>  	bool has_ctm = false;
>  	uint gamma_lut_size = 0;
>  	struct drm_crtc *tmp;
> @@ -1051,7 +1056,7 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
>  		struct mtk_ddp_comp *comp;
>  
>  		node = priv->comp_node[comp_id];
> -		comp = &priv->ddp_comp[comp_id];
> +		comp = mtk_ddp_comp_find_by_id(&priv->hlist, comp_id);
>  
>  		/* Not all drm components have a DTS device node, such as ovl_adaptor,
>  		 * which is the drm bring up sub driver
> @@ -1063,7 +1068,7 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
>  			return 0;
>  		}
>  
> -		if (!comp->dev) {
> +		if (!comp || !comp->dev) {
>  			dev_err(dev, "Component %pOF not initialized\n", node);

I think you should print other error message and return other value for !comp.

>  			return -ENODEV;
>  		}
> @@ -1089,12 +1094,17 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
>  		return ret;
>  	}
>  
> -	for (i = 0; i < mtk_crtc->ddp_comp_nr; i++) {
> +	for (i = 0, j = 0; i < mtk_crtc->ddp_comp_nr; i++, j++) {
>  		unsigned int comp_id = path[i];
>  		struct mtk_ddp_comp *comp;
>  
> -		comp = &priv->ddp_comp[comp_id];
> -		mtk_crtc->ddp_comp[i] = comp;
> +		comp = mtk_ddp_comp_find_by_id(&priv->hlist, comp_id);
> +		if (!comp) {

In original code, it never check comp is null or not.
I think it base on an assumption that it would not be null.
If it's null here, print error message and it's not necessary to do the rest thing.

> +			j--;
> +			dev_dbg(dev, "Cannot find component %d.\n", comp_id);
> +			continue;
> +		}
> +		mtk_crtc->ddp_comp[j] = comp;
>  
>  		if (comp->funcs) {
>  			if (comp->funcs->gamma_set && comp->funcs->gamma_get_lut_size) {
> @@ -1131,7 +1141,14 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
>  	 * In the case of ovl_adaptor sub driver, it needs to use the
>  	 * dma_dev_get function to get representative dma dev.
>  	 */
> -	mtk_crtc->dma_dev = mtk_ddp_comp_dma_dev_get(&priv->ddp_comp[path[0]]);
> +	dma_comp = mtk_ddp_comp_find_by_id(&priv->hlist, path[0]);
> +	if (dma_comp == NULL) {

if (!dma_comp) is more simple.

> +		dev_err(dev, "Could not find appropriate DMA device!\n");
> +		return -EINVAL;
> +	}
> +
> +	mtk_crtc->dma_dev = mtk_ddp_comp_dma_dev_get(dma_comp);
> +	dev_dbg(dev, "Using DMA device %pOF\n", mtk_crtc->dma_dev->of_node);
>  
>  	ret = mtk_crtc_init(drm_dev, mtk_crtc, crtc_i);
>  	if (ret < 0)
> @@ -1188,17 +1205,18 @@ int mtk_crtc_create(struct drm_device *drm_dev, const unsigned int *path,
>  		for (i = 0; i < num_conn_routes; i++) {
>  			unsigned int comp_id = conn_routes[i].route_ddp;
>  			struct device_node *node = priv->comp_node[comp_id];
> -			struct mtk_ddp_comp *comp = &priv->ddp_comp[comp_id];
> +			struct mtk_ddp_comp *comp = mtk_ddp_comp_find_by_id(&priv->hlist, comp_id);
>  
> -			if (!comp->dev) {
> +			if (!comp || !comp->dev) {

In original code, it never check comp is null or not.
I think it base on an assumption that it would not be null.
If it's null here, print error message and it's not necessary to do the rest thing.

>  				dev_dbg(dev, "comp_id:%d, Component %pOF not initialized\n",
>  					comp_id, node);
>  				/* mark encoder_index to -1, if route comp device is not enabled */
> -				comp->encoder_index = -1;
> +				if (comp)
> +					comp->encoder_index = -1;
>  				continue;
>  			}
>  
> -			mtk_ddp_comp_encoder_index_set(&priv->ddp_comp[comp_id]);
> +			mtk_ddp_comp_encoder_index_set(comp);
>  
> 

[snip]

> 		}
>  @@ -1116,8 +1118,7 @@ static int mtk_drm_probe(struct platform_device *pdev)
>  							    PLATFORM_DEVID_AUTO,
>  							    (void *)private->mmsys_dev,
>  							    sizeof(*private->mmsys_dev));
> -		private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR].dev = &ovl_adaptor->dev;
> -		mtk_ddp_comp_init(dev, NULL, &private->ddp_comp[DDP_COMPONENT_DRM_OVL_ADAPTOR],
> +		mtk_ddp_comp_init(&ovl_adaptor->dev, NULL, &private->hlist,

mtk_ddp_comp_init(dev, NULL, &private->hlist,

Regards,
CK

>  				  DDP_COMPONENT_DRM_OVL_ADAPTOR);
>  		component_match_add(dev, &match, compare_dev, &ovl_adaptor->dev);
>  	}
> 


  reply	other threads:[~2026-07-06  7:03 UTC|newest]

Thread overview: 58+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-07-01 12:20 [PATCH 00/42] drm/mediatek: The Huge Restructuring and MT8196 support AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 01/42] drm/mediatek: Rename OVL format naming AngeloGioacchino Del Regno
2026-07-02  7:30   ` CK Hu (胡俊光)
2026-07-01 12:20 ` [PATCH 02/42] drm/mediatek: Export OVL formats definitions and format conversion API AngeloGioacchino Del Regno
2026-07-02  9:36   ` CK Hu (胡俊光)
2026-07-01 12:20 ` [PATCH 03/42] drm/mediatek: Export OVL Blend function AngeloGioacchino Del Regno
2026-07-03  5:38   ` CK Hu (胡俊光)
2026-07-01 12:20 ` [PATCH 04/42] drm/mediatek: Move mtk_ddp_comp_type enumeration to mtk-mmsys.h AngeloGioacchino Del Regno
2026-07-03  6:03   ` CK Hu (胡俊光)
2026-07-01 12:20 ` [PATCH 05/42] drm/mediatek: Rename all display component type to have DISP_ prefix AngeloGioacchino Del Regno
2026-07-03  6:25   ` CK Hu (胡俊光)
2026-07-01 12:20 ` [PATCH 06/42] drm/mediatek: Use hashtable for components discovery and registration AngeloGioacchino Del Regno
2026-07-06  7:02   ` CK Hu (胡俊光) [this message]
2026-07-07 11:56     ` AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 07/42] drm/mediatek: ddp_comp: Move internal component register in function AngeloGioacchino Del Regno
2026-07-07  3:09   ` CK Hu (胡俊光)
2026-07-01 12:20 ` [PATCH 08/42] drm/mediatek: De-duplicate internal component checks AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 09/42] drm/mediatek: Introduce and use path/comp definition structures AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 10/42] drm/mediatek: Create new mtk_drm_legacy and move deprecated code AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 11/42] drm/mediatek: Add support for MuteX trigger-sources parsing AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 12/42] drm/mediatek: ovl_adaptor: Add special MERGE component check AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 13/42] drm/mediatek: mtk_hdmi_v2: Don't warn on RPM active during detach AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 14/42] drm/mediatek: Add support for hardware multi-stage layers AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 15/42] drm/mediatek: mtk_crtc: Complete documentation for struct mtk_crtc AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 16/42] drm/mediatek: mtk_crtc: Minimize spinlocked time in cmdq callback AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 17/42] drm/mediatek: mtk_crtc: Dynamically find vblank/cfg component indices AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 18/42] soc: mediatek: mtk-mmsys: Migrate to new Multimedia DDP HW indexing AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 19/42] drm/mediatek: Fully migrate to new Display Controller " AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 20/42] drm/mediatek: mtk_dpi: Pass parameters with new mtk_dpi_sync structure AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 21/42] drm/mediatek: mtk_dpi: Fully separate HW setup from common code AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 22/42] drm/mediatek: Create new mtk_dpi_common lib and move mtk_dpi code AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 23/42] dt-bindings: display: mediatek: Introduce Digital Video Output HW AngeloGioacchino Del Regno
2026-07-01 14:23   ` Rob Herring (Arm)
2026-07-01 16:53     ` AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 24/42] drm/mediatek: Add support for MediaTek Digital Video Output (DVO) AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 25/42] drm/mediatek: Pass mtk_ddp_comp in clk and config callbacks AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 26/42] dt-bindings: display: mediatek: Introduce MT8196 Layer Blender AngeloGioacchino Del Regno
2026-07-01 14:23   ` Rob Herring (Arm)
2026-07-01 12:20 ` [PATCH 27/42] drm/mediatek: Add support for Display Layer Blender component AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 28/42] dt-bindings: display: mediatek: Introduce MT8196 extended DMA Engine AngeloGioacchino Del Regno
2026-07-01 14:23   ` Rob Herring (Arm)
2026-07-01 12:20 ` [PATCH 29/42] drm/mediatek: Add support for Display Controller exDMA component AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 30/42] dt-bindings: display: mediatek: Introduce MT8196 Output Processor AngeloGioacchino Del Regno
2026-07-01 14:23   ` Rob Herring (Arm)
2026-07-01 12:20 ` [PATCH 31/42] drm/mediatek: Add support for Display Output Processor component AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 32/42] drm/mediatek: mtk_crtc: Dynamically find suitable CRTC DMA device AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 33/42] drm/mediatek: Prepare path builder for multi-controller architecture AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 34/42] drm/mediatek: Enable bring-up of multi-controller CRTC paths AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 35/42] drm/mediatek: Introduce MediaTek Asynchronous DirectLink Controller AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 36/42] drm/mediatek: Support registering disp controller device subnodes AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 37/42] soc: mediatek: mtk-mmsys: Populate multimedia subsystem subdevices AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 38/42] dt-bindings: display: mediatek: Introduce MT8196 2D Sharpness Processor AngeloGioacchino Del Regno
2026-07-01 14:23   ` Rob Herring (Arm)
2026-07-01 12:20 ` [PATCH 39/42] drm/mediatek: Add Two-Dimension Sharpness Processor (TDSHP) driver AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 40/42] dt-bindings: display: mediatek: Introduce MT8196 Image Resizer AngeloGioacchino Del Regno
2026-07-01 14:23   ` Rob Herring (Arm)
2026-07-01 12:20 ` [PATCH 41/42] drm/mediatek: Add support for Display Image Resizer (Scaler) AngeloGioacchino Del Regno
2026-07-01 12:20 ` [PATCH 42/42] drm/mediatek: mtk_drm_drv: Fail init only if all paths are invalid AngeloGioacchino Del Regno

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=79f44c827c78fd823300509c22058f2b6f3600b6.camel@mediatek.com \
    --to=ck.hu@mediatek.com \
    --cc=Jason-JH.Lin@mediatek.com \
    --cc=Justin.Yeh@mediatek.com \
    --cc=airlied@gmail.com \
    --cc=angelogioacchino.delregno@collabora.com \
    --cc=chunkuang.hu@kernel.org \
    --cc=conor+dt@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=kernel@collabora.com \
    --cc=krzk+dt@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-mediatek@lists.infradead.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=matthias.bgg@gmail.com \
    --cc=mripard@kernel.org \
    --cc=p.zabel@pengutronix.de \
    --cc=robh@kernel.org \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox