mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy
@ 2024-02-01 12:53 AngeloGioacchino Del Regno
  2024-02-01 12:53 ` [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search AngeloGioacchino Del Regno
                   ` (3 more replies)
  0 siblings, 4 replies; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-02-01 12:53 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: p.zabel, airlied, daniel, matthias.bgg,
	angelogioacchino.delregno, ck.hu, nancy.lin, nathan.lu,
	dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel,
	kernel, wenst

This series performs some cleanups for DDP component CRTC search and
correctly iounmaps the previously of_iomap() calls from drm_ddp_comp.

Tested on MT8195 Cherry Tomato

AngeloGioacchino Del Regno (3):
  drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search
  drm/mediatek: Perform iounmap on simple DDP component destruction
  drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal
    helper

 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 113 +++++++++++++-------
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h |   1 +
 drivers/gpu/drm/mediatek/mtk_drm_drv.c      |   4 +-
 3 files changed, 80 insertions(+), 38 deletions(-)

-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search
  2024-02-01 12:53 [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
@ 2024-02-01 12:53 ` AngeloGioacchino Del Regno
  2024-03-22  7:30   ` CK Hu (胡俊光)
  2024-02-01 12:53 ` [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction AngeloGioacchino Del Regno
                   ` (2 subsequent siblings)
  3 siblings, 1 reply; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-02-01 12:53 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: p.zabel, airlied, daniel, matthias.bgg,
	angelogioacchino.delregno, ck.hu, nancy.lin, nathan.lu,
	dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel,
	kernel, wenst

Finding a possible CRTC by DDP component is done by first checking
static routes in three paths (main, external, third/extra path) and
then, if not found, we check for dynamic connection on a per-route
basis because, for example, on some SoCs the main route may output
to either a DSI display or DisplayPort and this is finally done by
assigning a CRTC mask to `possible_crtcs`, found with function
mtk_drm_find_comp_in_ddp_conn_path(): being that a mask the possible
values are BIT(x) and, if no CRTC is possible, zero.

Problem is, both mtk_drm_find_possible_crtc_by_comp() and the
aforementioned function are trying to return a negative error value
(but it's unsigned int!) if no CRTC was found, which is wrong for
multiple obvious reasons.

Cleanup both functions, so that:
 - mtk_drm_find_comp_in_ddp_conn_path() returns a signed integer
   with a negative number for error, or a bit/bitmask of the found
   possible CRTC; and
 - mtk_drm_find_possible_crtc_by_comp() always returns either a
   bitmask of the possible CRTC, or zero if none available.

Fixes: 01389b324c97 ("drm/mediatek: Add connector dynamic selection capability")
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 44 ++++++++++-----------
 1 file changed, 21 insertions(+), 23 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index a9b5a21cde2d..c13359eeb3cd 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -513,29 +513,25 @@ static bool mtk_drm_find_comp_in_ddp(struct device *dev,
 	return false;
 }
 
-static unsigned int mtk_drm_find_comp_in_ddp_conn_path(struct device *dev,
-						       const struct mtk_drm_route *routes,
-						       unsigned int num_routes,
-						       struct mtk_ddp_comp *ddp_comp)
+static int mtk_drm_find_comp_in_ddp_conn_path(struct device *dev,
+					      const struct mtk_drm_route *routes,
+					      unsigned int num_routes,
+					      struct mtk_ddp_comp *ddp_comp)
 {
-	int ret;
-	unsigned int i;
+	int i;
 
-	if (!routes) {
-		ret = -EINVAL;
-		goto err;
+	if (!routes || !num_routes) {
+		DRM_ERROR("No connection routes specified!\n");
+		return -EINVAL;
 	}
 
 	for (i = 0; i < num_routes; i++)
 		if (dev == ddp_comp[routes[i].route_ddp].dev)
 			return BIT(routes[i].crtc_id);
 
-	ret = -ENODEV;
-err:
-
-	DRM_INFO("Failed to find comp in ddp table, ret = %d\n", ret);
+	DRM_ERROR("Failed to find component in ddp table\n");
 
-	return 0;
+	return -ENODEV;
 }
 
 int mtk_ddp_comp_get_id(struct device_node *node,
@@ -557,22 +553,24 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
 						struct device *dev)
 {
 	struct mtk_drm_private *private = drm->dev_private;
-	unsigned int ret = 0;
+	int ret;
 
 	if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path, private->data->main_len,
 				     private->ddp_comp))
-		ret = BIT(0);
+		return BIT(0);
 	else if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path,
 					  private->data->ext_len, private->ddp_comp))
-		ret = BIT(1);
+		return BIT(1);
 	else if (mtk_drm_find_comp_in_ddp(dev, private->data->third_path,
 					  private->data->third_len, private->ddp_comp))
-		ret = BIT(2);
-	else
-		ret = mtk_drm_find_comp_in_ddp_conn_path(dev,
-							 private->data->conn_routes,
-							 private->data->num_conn_routes,
-							 private->ddp_comp);
+		return BIT(2);
+
+	ret = mtk_drm_find_comp_in_ddp_conn_path(dev, private->data->conn_routes,
+						 private->data->num_conn_routes,
+						 private->ddp_comp);
+	/* No CRTC is available: return a zero mask */
+	if (ret < 0)
+		return 0;
 
 	return ret;
 }
-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction
  2024-02-01 12:53 [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
  2024-02-01 12:53 ` [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search AngeloGioacchino Del Regno
@ 2024-02-01 12:53 ` AngeloGioacchino Del Regno
  2024-03-22  8:48   ` CK Hu (胡俊光)
  2024-02-01 12:53 ` [PATCH 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper AngeloGioacchino Del Regno
  2024-03-21  9:05 ` [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
  3 siblings, 1 reply; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-02-01 12:53 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: p.zabel, airlied, daniel, matthias.bgg,
	angelogioacchino.delregno, ck.hu, nancy.lin, nathan.lu,
	dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel,
	kernel, wenst

Add a new mtk_ddp_comp_destroy() function and call it in the teardown
path of mtk_drm_drv to make sure that we unmap the iospace of the
simple DDP components.

While at it, also fix iounmapping on mtk_ddp_comp_init() error path.

Fixes: ff1395609e20 ("drm/mediatek: Move mtk_ddp_comp_init() from sub driver to DRM driver")
Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 38 ++++++++++++++++++++-
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h |  1 +
 drivers/gpu/drm/mediatek/mtk_drm_drv.c      |  4 ++-
 3 files changed, 41 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index c13359eeb3cd..539b526a6b0a 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -626,8 +626,11 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
 
 	priv->regs = of_iomap(node, 0);
 	priv->clk = of_clk_get(node, 0);
-	if (IS_ERR(priv->clk))
+	if (IS_ERR(priv->clk)) {
+		iounmap(priv->regs);
+		priv->regs = NULL;
 		return PTR_ERR(priv->clk);
+	}
 
 #if IS_REACHABLE(CONFIG_MTK_CMDQ)
 	ret = cmdq_dev_get_client_reg(comp->dev, &priv->cmdq_reg, 0);
@@ -639,3 +642,36 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
 
 	return 0;
 }
+
+void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp)
+{
+	struct mtk_ddp_comp_dev *priv;
+
+	if (!comp || !comp->dev)
+		return;
+
+	/* Complex components are destroyed with their own remove callback */
+	if (type == MTK_DISP_AAL ||
+	    type == MTK_DISP_BLS ||
+	    type == MTK_DISP_CCORR ||
+	    type == MTK_DISP_COLOR ||
+	    type == MTK_DISP_GAMMA ||
+	    type == MTK_DISP_MERGE ||
+	    type == MTK_DISP_OVL ||
+	    type == MTK_DISP_OVL_2L ||
+	    type == MTK_DISP_PWM ||
+	    type == MTK_DISP_RDMA ||
+	    type == MTK_DPI ||
+	    type == MTK_DP_INTF ||
+	    type == MTK_DSI)
+		return;
+
+	priv = dev_get_drvdata(comp->dev);
+	if (!priv)
+		return;
+
+	if (priv->regs) {
+		iounmap(priv->regs);
+		priv->regs = NULL;
+	}
+}
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
index 15b2eafff438..43372b416a3f 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
@@ -318,6 +318,7 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
 						struct device *dev);
 int mtk_ddp_comp_init(struct device_node *comp_node, struct mtk_ddp_comp *comp,
 		      unsigned int comp_id);
+void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp);
 enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
 void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
 		   struct cmdq_client_reg *cmdq_reg, void __iomem *regs,
diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
index 14a1e0157cc4..89b6c31a1511 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
@@ -944,8 +944,10 @@ static void mtk_drm_remove(struct platform_device *pdev)
 	component_master_del(&pdev->dev, &mtk_drm_ops);
 	pm_runtime_disable(&pdev->dev);
 	of_node_put(private->mutex_node);
-	for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++)
+	for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++) {
+		mtk_ddp_comp_destroy(&private->ddp_comp[i]);
 		of_node_put(private->comp_node[i]);
+	}
 }
 
 static int mtk_drm_sys_prepare(struct device *dev)
-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* [PATCH 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper
  2024-02-01 12:53 [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
  2024-02-01 12:53 ` [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search AngeloGioacchino Del Regno
  2024-02-01 12:53 ` [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction AngeloGioacchino Del Regno
@ 2024-02-01 12:53 ` AngeloGioacchino Del Regno
  2024-03-22  8:57   ` CK Hu (胡俊光)
  2024-03-21  9:05 ` [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
  3 siblings, 1 reply; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-02-01 12:53 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: p.zabel, airlied, daniel, matthias.bgg,
	angelogioacchino.delregno, ck.hu, nancy.lin, nathan.lu,
	dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel,
	kernel, wenst

Move the simple component check to a new mtk_ddp_is_simple_comp()
internal helper to reduce code duplication.

Signed-off-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 57 +++++++++++----------
 1 file changed, 31 insertions(+), 26 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
index 539b526a6b0a..4ca2a02ada3c 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
@@ -575,6 +575,29 @@ unsigned int mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
 	return ret;
 }
 
+static bool mtk_ddp_is_simple_comp(enum mtk_ddp_comp_type type)
+{
+	switch (type) {
+	case MTK_DISP_AAL:
+	case MTK_DISP_BLS:
+	case MTK_DISP_CCORR:
+	case MTK_DISP_COLOR:
+	case MTK_DISP_GAMMA:
+	case MTK_DISP_MERGE:
+	case MTK_DISP_OVL:
+	case MTK_DISP_OVL_2L:
+	case MTK_DISP_OVL_ADAPTOR:
+	case MTK_DISP_PWM:
+	case MTK_DISP_RDMA:
+	case MTK_DP_INTF:
+	case MTK_DPI:
+	case MTK_DSI:
+		return false;
+	default:
+		return true;
+	}
+}
+
 int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
 		      unsigned int comp_id)
 {
@@ -605,19 +628,13 @@ int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp *comp,
 	}
 	comp->dev = &comp_pdev->dev;
 
-	if (type == MTK_DISP_AAL ||
-	    type == MTK_DISP_BLS ||
-	    type == MTK_DISP_CCORR ||
-	    type == MTK_DISP_COLOR ||
-	    type == MTK_DISP_GAMMA ||
-	    type == MTK_DISP_MERGE ||
-	    type == MTK_DISP_OVL ||
-	    type == MTK_DISP_OVL_2L ||
-	    type == MTK_DISP_PWM ||
-	    type == MTK_DISP_RDMA ||
-	    type == MTK_DPI ||
-	    type == MTK_DP_INTF ||
-	    type == MTK_DSI)
+	/*
+	 * Resources for simple components are retrieved here as those are
+	 * managed in here without the need of more complex drivers; for
+	 * the latter, their respective probe function will do the job, so
+	 * we must avoid getting their resources here.
+	 */
+	if (!mtk_ddp_is_simple_comp(type))
 		return 0;
 
 	priv = devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL);
@@ -651,19 +668,7 @@ void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp)
 		return;
 
 	/* Complex components are destroyed with their own remove callback */
-	if (type == MTK_DISP_AAL ||
-	    type == MTK_DISP_BLS ||
-	    type == MTK_DISP_CCORR ||
-	    type == MTK_DISP_COLOR ||
-	    type == MTK_DISP_GAMMA ||
-	    type == MTK_DISP_MERGE ||
-	    type == MTK_DISP_OVL ||
-	    type == MTK_DISP_OVL_2L ||
-	    type == MTK_DISP_PWM ||
-	    type == MTK_DISP_RDMA ||
-	    type == MTK_DPI ||
-	    type == MTK_DP_INTF ||
-	    type == MTK_DSI)
+	if (!mtk_ddp_is_simple_comp(mtk_ddp_matches[comp->id].type))
 		return;
 
 	priv = dev_get_drvdata(comp->dev);
-- 
2.43.0


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy
  2024-02-01 12:53 [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
                   ` (2 preceding siblings ...)
  2024-02-01 12:53 ` [PATCH 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper AngeloGioacchino Del Regno
@ 2024-03-21  9:05 ` AngeloGioacchino Del Regno
  3 siblings, 0 replies; 9+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-03-21  9:05 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: p.zabel, airlied, daniel, matthias.bgg, ck.hu, nancy.lin,
	nathan.lu, dri-devel, linux-mediatek, linux-kernel,
	linux-arm-kernel, kernel, wenst

Il 01/02/24 13:53, AngeloGioacchino Del Regno ha scritto:
> This series performs some cleanups for DDP component CRTC search and
> correctly iounmaps the previously of_iomap() calls from drm_ddp_comp.
> 
> Tested on MT8195 Cherry Tomato
> 

Hello CK,
gentle ping for this series.

Cheers,
Angelo

> AngeloGioacchino Del Regno (3):
>    drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search
>    drm/mediatek: Perform iounmap on simple DDP component destruction
>    drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal
>      helper
> 
>   drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 113 +++++++++++++-------
>   drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h |   1 +
>   drivers/gpu/drm/mediatek/mtk_drm_drv.c      |   4 +-
>   3 files changed, 80 insertions(+), 38 deletions(-)
> 


^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search
  2024-02-01 12:53 ` [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search AngeloGioacchino Del Regno
@ 2024-03-22  7:30   ` CK Hu (胡俊光)
  0 siblings, 0 replies; 9+ messages in thread
From: CK Hu (胡俊光) @ 2024-03-22  7:30 UTC (permalink / raw)
  To: angelogioacchino.delregno, chunkuang.hu
  Cc: linux-mediatek, linux-kernel, wenst, kernel,
	Nancy Lin (林欣螢),
	daniel, p.zabel, dri-devel, Nathan Lu (呂東霖),
	airlied, linux-arm-kernel, matthias.bgg

Hi, Angelo:

On Thu, 2024-02-01 at 13:53 +0100, AngeloGioacchino Del Regno wrote:
> Finding a possible CRTC by DDP component is done by first checking
> static routes in three paths (main, external, third/extra path) and
> then, if not found, we check for dynamic connection on a per-route
> basis because, for example, on some SoCs the main route may output
> to either a DSI display or DisplayPort and this is finally done by
> assigning a CRTC mask to `possible_crtcs`, found with function
> mtk_drm_find_comp_in_ddp_conn_path(): being that a mask the possible
> values are BIT(x) and, if no CRTC is possible, zero.
> 
> Problem is, both mtk_drm_find_possible_crtc_by_comp() and the
> aforementioned function are trying to return a negative error value
> (but it's unsigned int!) if no CRTC was found, which is wrong for
> multiple obvious reasons.

I does not find anywhere to return negative value. So this patch just
like a refine patch not bug fix.

Regards,
CK

> 
> Cleanup both functions, so that:
>  - mtk_drm_find_comp_in_ddp_conn_path() returns a signed integer
>    with a negative number for error, or a bit/bitmask of the found
>    possible CRTC; and
>  - mtk_drm_find_possible_crtc_by_comp() always returns either a
>    bitmask of the possible CRTC, or zero if none available.
> 
> Fixes: 01389b324c97 ("drm/mediatek: Add connector dynamic selection
> capability")
> Signed-off-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 44 ++++++++++---------
> --
>  1 file changed, 21 insertions(+), 23 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index a9b5a21cde2d..c13359eeb3cd 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -513,29 +513,25 @@ static bool mtk_drm_find_comp_in_ddp(struct
> device *dev,
>  	return false;
>  }
>  
> -static unsigned int mtk_drm_find_comp_in_ddp_conn_path(struct device
> *dev,
> -						       const struct
> mtk_drm_route *routes,
> -						       unsigned int
> num_routes,
> -						       struct
> mtk_ddp_comp *ddp_comp)
> +static int mtk_drm_find_comp_in_ddp_conn_path(struct device *dev,
> +					      const struct
> mtk_drm_route *routes,
> +					      unsigned int num_routes,
> +					      struct mtk_ddp_comp
> *ddp_comp)
>  {
> -	int ret;
> -	unsigned int i;
> +	int i;
>  
> -	if (!routes) {
> -		ret = -EINVAL;
> -		goto err;
> +	if (!routes || !num_routes) {
> +		DRM_ERROR("No connection routes specified!\n");
> +		return -EINVAL;
>  	}
>  
>  	for (i = 0; i < num_routes; i++)
>  		if (dev == ddp_comp[routes[i].route_ddp].dev)
>  			return BIT(routes[i].crtc_id);
>  
> -	ret = -ENODEV;
> -err:
> -
> -	DRM_INFO("Failed to find comp in ddp table, ret = %d\n", ret);
> +	DRM_ERROR("Failed to find component in ddp table\n");
>  
> -	return 0;
> +	return -ENODEV;
>  }
>  
>  int mtk_ddp_comp_get_id(struct device_node *node,
> @@ -557,22 +553,24 @@ unsigned int
> mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
>  						struct device *dev)
>  {
>  	struct mtk_drm_private *private = drm->dev_private;
> -	unsigned int ret = 0;
> +	int ret;
>  
>  	if (mtk_drm_find_comp_in_ddp(dev, private->data->main_path,
> private->data->main_len,
>  				     private->ddp_comp))
> -		ret = BIT(0);
> +		return BIT(0);
>  	else if (mtk_drm_find_comp_in_ddp(dev, private->data->ext_path,
>  					  private->data->ext_len,
> private->ddp_comp))
> -		ret = BIT(1);
> +		return BIT(1);
>  	else if (mtk_drm_find_comp_in_ddp(dev, private->data-
> >third_path,
>  					  private->data->third_len,
> private->ddp_comp))
> -		ret = BIT(2);
> -	else
> -		ret = mtk_drm_find_comp_in_ddp_conn_path(dev,
> -							 private->data-
> >conn_routes,
> -							 private->data-
> >num_conn_routes,
> -							 private-
> >ddp_comp);
> +		return BIT(2);
> +
> +	ret = mtk_drm_find_comp_in_ddp_conn_path(dev, private->data-
> >conn_routes,
> +						 private->data-
> >num_conn_routes,
> +						 private->ddp_comp);
> +	/* No CRTC is available: return a zero mask */
> +	if (ret < 0)
> +		return 0;
>  
>  	return ret;
>  }

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction
  2024-02-01 12:53 ` [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction AngeloGioacchino Del Regno
@ 2024-03-22  8:48   ` CK Hu (胡俊光)
  2024-04-01 14:18     ` Chun-Kuang Hu
  0 siblings, 1 reply; 9+ messages in thread
From: CK Hu (胡俊光) @ 2024-03-22  8:48 UTC (permalink / raw)
  To: angelogioacchino.delregno, chunkuang.hu
  Cc: linux-mediatek, linux-kernel, wenst, kernel,
	Nancy Lin (林欣螢),
	daniel, p.zabel, dri-devel, Nathan Lu (呂東霖),
	airlied, linux-arm-kernel, matthias.bgg

Hi, Angelo:

On Thu, 2024-02-01 at 13:53 +0100, AngeloGioacchino Del Regno wrote:
> Add a new mtk_ddp_comp_destroy() function and call it in the teardown
> path of mtk_drm_drv to make sure that we unmap the iospace of the
> simple DDP components.
> 
> While at it, also fix iounmapping on mtk_ddp_comp_init() error path.

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Fixes: ff1395609e20 ("drm/mediatek: Move mtk_ddp_comp_init() from sub
> driver to DRM driver")
> Signed-off-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 38
> ++++++++++++++++++++-
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h |  1 +
>  drivers/gpu/drm/mediatek/mtk_drm_drv.c      |  4 ++-
>  3 files changed, 41 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index c13359eeb3cd..539b526a6b0a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -626,8 +626,11 @@ int mtk_ddp_comp_init(struct device_node *node,
> struct mtk_ddp_comp *comp,
>  
>  	priv->regs = of_iomap(node, 0);
>  	priv->clk = of_clk_get(node, 0);
> -	if (IS_ERR(priv->clk))
> +	if (IS_ERR(priv->clk)) {
> +		iounmap(priv->regs);
> +		priv->regs = NULL;
>  		return PTR_ERR(priv->clk);
> +	}
>  
>  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
>  	ret = cmdq_dev_get_client_reg(comp->dev, &priv->cmdq_reg, 0);
> @@ -639,3 +642,36 @@ int mtk_ddp_comp_init(struct device_node *node,
> struct mtk_ddp_comp *comp,
>  
>  	return 0;
>  }
> +
> +void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp)
> +{
> +	struct mtk_ddp_comp_dev *priv;
> +
> +	if (!comp || !comp->dev)
> +		return;
> +
> +	/* Complex components are destroyed with their own remove
> callback */
> +	if (type == MTK_DISP_AAL ||
> +	    type == MTK_DISP_BLS ||
> +	    type == MTK_DISP_CCORR ||
> +	    type == MTK_DISP_COLOR ||
> +	    type == MTK_DISP_GAMMA ||
> +	    type == MTK_DISP_MERGE ||
> +	    type == MTK_DISP_OVL ||
> +	    type == MTK_DISP_OVL_2L ||
> +	    type == MTK_DISP_PWM ||
> +	    type == MTK_DISP_RDMA ||
> +	    type == MTK_DPI ||
> +	    type == MTK_DP_INTF ||
> +	    type == MTK_DSI)
> +		return;
> +
> +	priv = dev_get_drvdata(comp->dev);
> +	if (!priv)
> +		return;
> +
> +	if (priv->regs) {
> +		iounmap(priv->regs);
> +		priv->regs = NULL;
> +	}
> +}
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> index 15b2eafff438..43372b416a3f 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> @@ -318,6 +318,7 @@ unsigned int
> mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
>  						struct device *dev);
>  int mtk_ddp_comp_init(struct device_node *comp_node, struct
> mtk_ddp_comp *comp,
>  		      unsigned int comp_id);
> +void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp);
>  enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
>  void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
>  		   struct cmdq_client_reg *cmdq_reg, void __iomem
> *regs,
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> index 14a1e0157cc4..89b6c31a1511 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> @@ -944,8 +944,10 @@ static void mtk_drm_remove(struct
> platform_device *pdev)
>  	component_master_del(&pdev->dev, &mtk_drm_ops);
>  	pm_runtime_disable(&pdev->dev);
>  	of_node_put(private->mutex_node);
> -	for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++)
> +	for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++) {
> +		mtk_ddp_comp_destroy(&private->ddp_comp[i]);
>  		of_node_put(private->comp_node[i]);
> +	}
>  }
>  
>  static int mtk_drm_sys_prepare(struct device *dev)

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper
  2024-02-01 12:53 ` [PATCH 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper AngeloGioacchino Del Regno
@ 2024-03-22  8:57   ` CK Hu (胡俊光)
  0 siblings, 0 replies; 9+ messages in thread
From: CK Hu (胡俊光) @ 2024-03-22  8:57 UTC (permalink / raw)
  To: angelogioacchino.delregno, chunkuang.hu
  Cc: linux-mediatek, linux-kernel, wenst, kernel,
	Nancy Lin (林欣螢),
	daniel, p.zabel, dri-devel, Nathan Lu (呂東霖),
	airlied, linux-arm-kernel, matthias.bgg

Hi, Angelo:

On Thu, 2024-02-01 at 13:53 +0100, AngeloGioacchino Del Regno wrote:
> Move the simple component check to a new mtk_ddp_is_simple_comp()
> internal helper to reduce code duplication.

Reviewed-by: CK Hu <ck.hu@mediatek.com>

> 
> Signed-off-by: AngeloGioacchino Del Regno <
> angelogioacchino.delregno@collabora.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 57 +++++++++++------
> ----
>  1 file changed, 31 insertions(+), 26 deletions(-)
> 
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> index 539b526a6b0a..4ca2a02ada3c 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> @@ -575,6 +575,29 @@ unsigned int
> mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
>  	return ret;
>  }
>  
> +static bool mtk_ddp_is_simple_comp(enum mtk_ddp_comp_type type)
> +{
> +	switch (type) {
> +	case MTK_DISP_AAL:
> +	case MTK_DISP_BLS:
> +	case MTK_DISP_CCORR:
> +	case MTK_DISP_COLOR:
> +	case MTK_DISP_GAMMA:
> +	case MTK_DISP_MERGE:
> +	case MTK_DISP_OVL:
> +	case MTK_DISP_OVL_2L:
> +	case MTK_DISP_OVL_ADAPTOR:
> +	case MTK_DISP_PWM:
> +	case MTK_DISP_RDMA:
> +	case MTK_DP_INTF:
> +	case MTK_DPI:
> +	case MTK_DSI:
> +		return false;
> +	default:
> +		return true;
> +	}
> +}
> +
>  int mtk_ddp_comp_init(struct device_node *node, struct mtk_ddp_comp
> *comp,
>  		      unsigned int comp_id)
>  {
> @@ -605,19 +628,13 @@ int mtk_ddp_comp_init(struct device_node *node,
> struct mtk_ddp_comp *comp,
>  	}
>  	comp->dev = &comp_pdev->dev;
>  
> -	if (type == MTK_DISP_AAL ||
> -	    type == MTK_DISP_BLS ||
> -	    type == MTK_DISP_CCORR ||
> -	    type == MTK_DISP_COLOR ||
> -	    type == MTK_DISP_GAMMA ||
> -	    type == MTK_DISP_MERGE ||
> -	    type == MTK_DISP_OVL ||
> -	    type == MTK_DISP_OVL_2L ||
> -	    type == MTK_DISP_PWM ||
> -	    type == MTK_DISP_RDMA ||
> -	    type == MTK_DPI ||
> -	    type == MTK_DP_INTF ||
> -	    type == MTK_DSI)
> +	/*
> +	 * Resources for simple components are retrieved here as those
> are
> +	 * managed in here without the need of more complex drivers;
> for
> +	 * the latter, their respective probe function will do the job,
> so
> +	 * we must avoid getting their resources here.
> +	 */
> +	if (!mtk_ddp_is_simple_comp(type))
>  		return 0;
>  
>  	priv = devm_kzalloc(comp->dev, sizeof(*priv), GFP_KERNEL);
> @@ -651,19 +668,7 @@ void mtk_ddp_comp_destroy(struct mtk_ddp_comp
> *comp)
>  		return;
>  
>  	/* Complex components are destroyed with their own remove
> callback */
> -	if (type == MTK_DISP_AAL ||
> -	    type == MTK_DISP_BLS ||
> -	    type == MTK_DISP_CCORR ||
> -	    type == MTK_DISP_COLOR ||
> -	    type == MTK_DISP_GAMMA ||
> -	    type == MTK_DISP_MERGE ||
> -	    type == MTK_DISP_OVL ||
> -	    type == MTK_DISP_OVL_2L ||
> -	    type == MTK_DISP_PWM ||
> -	    type == MTK_DISP_RDMA ||
> -	    type == MTK_DPI ||
> -	    type == MTK_DP_INTF ||
> -	    type == MTK_DSI)
> +	if (!mtk_ddp_is_simple_comp(mtk_ddp_matches[comp->id].type))
>  		return;
>  
>  	priv = dev_get_drvdata(comp->dev);

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction
  2024-03-22  8:48   ` CK Hu (胡俊光)
@ 2024-04-01 14:18     ` Chun-Kuang Hu
  0 siblings, 0 replies; 9+ messages in thread
From: Chun-Kuang Hu @ 2024-04-01 14:18 UTC (permalink / raw)
  To: CK Hu (胡俊光)
  Cc: angelogioacchino.delregno, chunkuang.hu, linux-mediatek,
	linux-kernel, wenst, kernel, Nancy Lin (林欣螢),
	daniel, p.zabel, dri-devel, Nathan Lu (呂東霖),
	airlied, linux-arm-kernel, matthias.bgg

Hi, Angelo:

CK Hu (胡俊光) <ck.hu@mediatek.com> 於 2024年3月22日 週五 下午4:49寫道:
>
> Hi, Angelo:
>
> On Thu, 2024-02-01 at 13:53 +0100, AngeloGioacchino Del Regno wrote:
> > Add a new mtk_ddp_comp_destroy() function and call it in the teardown
> > path of mtk_drm_drv to make sure that we unmap the iospace of the
> > simple DDP components.
> >
> > While at it, also fix iounmapping on mtk_ddp_comp_init() error path.
>
> Reviewed-by: CK Hu <ck.hu@mediatek.com>
>
> >
> > Fixes: ff1395609e20 ("drm/mediatek: Move mtk_ddp_comp_init() from sub
> > driver to DRM driver")
> > Signed-off-by: AngeloGioacchino Del Regno <
> > angelogioacchino.delregno@collabora.com>
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c | 38
> > ++++++++++++++++++++-
> >  drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h |  1 +
> >  drivers/gpu/drm/mediatek/mtk_drm_drv.c      |  4 ++-
> >  3 files changed, 41 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> > b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> > index c13359eeb3cd..539b526a6b0a 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c
> > @@ -626,8 +626,11 @@ int mtk_ddp_comp_init(struct device_node *node,
> > struct mtk_ddp_comp *comp,
> >
> >       priv->regs = of_iomap(node, 0);
> >       priv->clk = of_clk_get(node, 0);
> > -     if (IS_ERR(priv->clk))
> > +     if (IS_ERR(priv->clk)) {
> > +             iounmap(priv->regs);
> > +             priv->regs = NULL;
> >               return PTR_ERR(priv->clk);
> > +     }
> >
> >  #if IS_REACHABLE(CONFIG_MTK_CMDQ)
> >       ret = cmdq_dev_get_client_reg(comp->dev, &priv->cmdq_reg, 0);
> > @@ -639,3 +642,36 @@ int mtk_ddp_comp_init(struct device_node *node,
> > struct mtk_ddp_comp *comp,
> >
> >       return 0;
> >  }
> > +
> > +void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp)
> > +{
> > +     struct mtk_ddp_comp_dev *priv;
> > +
> > +     if (!comp || !comp->dev)
> > +             return;
> > +
> > +     /* Complex components are destroyed with their own remove
> > callback */
> > +     if (type == MTK_DISP_AAL ||

Build error:

../drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c: In function
\u2018mtk_ddp_comp_destroy\u2019:
../drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c:657:13: error:
\u2018type\u2019 undeclared (first use in this function); did you mean
\u2018_ctype\u2019?
  657 |         if (type == MTK_DISP_AAL ||
      |             ^~~~
      |             _ctype
../drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.c:657:13: note: each
undeclared identifier is reported only once for each function it
appears in

Regards,
Chun-Kuang.

> > +         type == MTK_DISP_BLS ||
> > +         type == MTK_DISP_CCORR ||
> > +         type == MTK_DISP_COLOR ||
> > +         type == MTK_DISP_GAMMA ||
> > +         type == MTK_DISP_MERGE ||
> > +         type == MTK_DISP_OVL ||
> > +         type == MTK_DISP_OVL_2L ||
> > +         type == MTK_DISP_PWM ||
> > +         type == MTK_DISP_RDMA ||
> > +         type == MTK_DPI ||
> > +         type == MTK_DP_INTF ||
> > +         type == MTK_DSI)
> > +             return;
> > +
> > +     priv = dev_get_drvdata(comp->dev);
> > +     if (!priv)
> > +             return;
> > +
> > +     if (priv->regs) {
> > +             iounmap(priv->regs);
> > +             priv->regs = NULL;
> > +     }
> > +}
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> > b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> > index 15b2eafff438..43372b416a3f 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_ddp_comp.h
> > @@ -318,6 +318,7 @@ unsigned int
> > mtk_drm_find_possible_crtc_by_comp(struct drm_device *drm,
> >                                               struct device *dev);
> >  int mtk_ddp_comp_init(struct device_node *comp_node, struct
> > mtk_ddp_comp *comp,
> >                     unsigned int comp_id);
> > +void mtk_ddp_comp_destroy(struct mtk_ddp_comp *comp);
> >  enum mtk_ddp_comp_type mtk_ddp_comp_get_type(unsigned int comp_id);
> >  void mtk_ddp_write(struct cmdq_pkt *cmdq_pkt, unsigned int value,
> >                  struct cmdq_client_reg *cmdq_reg, void __iomem
> > *regs,
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > index 14a1e0157cc4..89b6c31a1511 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_drv.c
> > @@ -944,8 +944,10 @@ static void mtk_drm_remove(struct
> > platform_device *pdev)
> >       component_master_del(&pdev->dev, &mtk_drm_ops);
> >       pm_runtime_disable(&pdev->dev);
> >       of_node_put(private->mutex_node);
> > -     for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++)
> > +     for (i = 0; i < DDP_COMPONENT_DRM_ID_MAX; i++) {
> > +             mtk_ddp_comp_destroy(&private->ddp_comp[i]);
> >               of_node_put(private->comp_node[i]);
> > +     }
> >  }
> >
> >  static int mtk_drm_sys_prepare(struct device *dev)

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2024-04-01 14:18 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-01 12:53 [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno
2024-02-01 12:53 ` [PATCH 1/3] drm/mediatek: drm_ddp_comp: Fix and cleanup DDP component CRTC search AngeloGioacchino Del Regno
2024-03-22  7:30   ` CK Hu (胡俊光)
2024-02-01 12:53 ` [PATCH 2/3] drm/mediatek: Perform iounmap on simple DDP component destruction AngeloGioacchino Del Regno
2024-03-22  8:48   ` CK Hu (胡俊光)
2024-04-01 14:18     ` Chun-Kuang Hu
2024-02-01 12:53 ` [PATCH 3/3] drm/mediatek: drm_ddp_comp: Add mtk_ddp_is_simple_comp() internal helper AngeloGioacchino Del Regno
2024-03-22  8:57   ` CK Hu (胡俊光)
2024-03-21  9:05 ` [PATCH 0/3] drm/mediatek: Fixes for DDP component search/destroy AngeloGioacchino Del Regno

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®