diff mbox series

[v4,2/2] drm/mediatek: add devlink to cmdq dev

Message ID 20211202064039.20797-3-jason-jh.lin@mediatek.com (mailing list archive)
State New, archived
Headers show
Series Fix mediatek-drm suspend and resume issue | expand

Commit Message

Jason-JH Lin (林睿祥) Dec. 2, 2021, 6:40 a.m. UTC
Add devlink to cmdq to make sure the order of suspend and resume
is correct.

Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
---
 drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 43 ++++++++++++++++++-------
 1 file changed, 31 insertions(+), 12 deletions(-)

Comments

Chun-Kuang Hu Dec. 2, 2021, 11:28 p.m. UTC | #1
Hi, Jason:

jason-jh.lin <jason-jh.lin@mediatek.com> 於 2021年12月2日 週四 下午2:41寫道:
>
> Add devlink to cmdq to make sure the order of suspend and resume
> is correct.
>

Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>

> Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 43 ++++++++++++++++++-------
>  1 file changed, 31 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index 0b4012335e7a..612d1d69c16c 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -60,6 +60,7 @@ struct mtk_drm_crtc {
>  #endif
>
>         struct device                   *mmsys_dev;
> +       struct device                   *drm_dev;
>         struct mtk_mutex                *mutex;
>         unsigned int                    ddp_comp_nr;
>         struct mtk_ddp_comp             **ddp_comp;
> @@ -159,6 +160,7 @@ static void mtk_drm_crtc_destroy(struct drm_crtc *crtc)
>         mtk_drm_cmdq_pkt_destroy(&mtk_crtc->cmdq_handle);
>
>         if (mtk_crtc->cmdq_client.chan) {
> +               device_link_remove(mtk_crtc->drm_dev, mtk_crtc->cmdq_client.chan->mbox->dev);
>                 mbox_free_channel(mtk_crtc->cmdq_client.chan);
>                 mtk_crtc->cmdq_client.chan = NULL;
>         }
> @@ -902,6 +904,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>                 return -ENOMEM;
>
>         mtk_crtc->mmsys_dev = priv->mmsys_dev;
> +       mtk_crtc->drm_dev = priv->dev;
>         mtk_crtc->ddp_comp_nr = path_len;
>         mtk_crtc->ddp_comp = devm_kmalloc_array(dev, mtk_crtc->ddp_comp_nr,
>                                                 sizeof(*mtk_crtc->ddp_comp),
> @@ -969,6 +972,18 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>         }
>
>         if (mtk_crtc->cmdq_client.chan) {
> +               struct device_link *link;
> +
> +               /* add devlink to cmdq dev to make sure suspend/resume order is correct */
> +               link = device_link_add(priv->dev, mtk_crtc->cmdq_client.chan->mbox->dev,
> +                                      DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
> +               if (!link) {
> +                       dev_err(priv->dev, "Unable to link dev=%s\n",
> +                               dev_name(mtk_crtc->cmdq_client.chan->mbox->dev));
> +                       ret = -ENODEV;
> +                       goto cmdq_err;
> +               }
> +
>                 ret = of_property_read_u32_index(priv->mutex_node,
>                                                  "mediatek,gce-events",
>                                                  i,
> @@ -976,22 +991,26 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>                 if (ret) {
>                         dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
>                                 drm_crtc_index(&mtk_crtc->base));
> -                       mbox_free_channel(mtk_crtc->cmdq_client.chan);
> -                       mtk_crtc->cmdq_client.chan = NULL;
> -               } else {
> -                       ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
> -                                                     &mtk_crtc->cmdq_handle,
> -                                                     PAGE_SIZE);
> -                       if (ret) {
> -                               dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
> -                                       drm_crtc_index(&mtk_crtc->base));
> -                               mbox_free_channel(mtk_crtc->cmdq_client.chan);
> -                               mtk_crtc->cmdq_client.chan = NULL;
> -                       }
> +                       goto cmdq_err;
> +               }
> +
> +               ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
> +                                             &mtk_crtc->cmdq_handle,
> +                                             PAGE_SIZE);
> +               if (ret) {
> +                       dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
> +                               drm_crtc_index(&mtk_crtc->base));
> +                       goto cmdq_err;
>                 }
>
>                 /* for sending blocking cmd in crtc disable */
>                 init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
> +
> +cmdq_err:
> +               if (ret) {
> +                       mbox_free_channel(mtk_crtc->cmdq_client.chan);
> +                       mtk_crtc->cmdq_client.chan = NULL;
> +               }
>         }
>  #endif
>         return 0;
> --
> 2.18.0
>
Chun-Kuang Hu Feb. 27, 2022, 3:33 a.m. UTC | #2
Hi, Jason:

Build error:

../drivers/gpu/drm/mediatek/mtk_drm_crtc.c: In function ‘mtk_drm_crtc_create’:
../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:902:26: error: ‘struct
mtk_drm_private’ has no member named ‘dev’
  mtk_crtc->drm_dev = priv->dev;
                          ^
../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:974:30: error: ‘struct
mtk_drm_private’ has no member named ‘dev’
   link = device_link_add(priv->dev, mtk_crtc->cmdq_client.chan->mbox->dev,
                              ^
In file included from ../include/linux/device.h:15:0,
                 from ../include/linux/dma-mapping.h:7,
                 from ../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:7:
../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:977:16: error: ‘struct
mtk_drm_private’ has no member named ‘dev’
    dev_err(priv->dev, "Unable to link dev=%s\n",
                ^
Regards,
Chun-Kuang.

jason-jh.lin <jason-jh.lin@mediatek.com> 於 2021年12月2日 週四 下午2:41寫道:
>
> Add devlink to cmdq to make sure the order of suspend and resume
> is correct.
>
> Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 43 ++++++++++++++++++-------
>  1 file changed, 31 insertions(+), 12 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index 0b4012335e7a..612d1d69c16c 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -60,6 +60,7 @@ struct mtk_drm_crtc {
>  #endif
>
>         struct device                   *mmsys_dev;
> +       struct device                   *drm_dev;
>         struct mtk_mutex                *mutex;
>         unsigned int                    ddp_comp_nr;
>         struct mtk_ddp_comp             **ddp_comp;
> @@ -159,6 +160,7 @@ static void mtk_drm_crtc_destroy(struct drm_crtc *crtc)
>         mtk_drm_cmdq_pkt_destroy(&mtk_crtc->cmdq_handle);
>
>         if (mtk_crtc->cmdq_client.chan) {
> +               device_link_remove(mtk_crtc->drm_dev, mtk_crtc->cmdq_client.chan->mbox->dev);
>                 mbox_free_channel(mtk_crtc->cmdq_client.chan);
>                 mtk_crtc->cmdq_client.chan = NULL;
>         }
> @@ -902,6 +904,7 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>                 return -ENOMEM;
>
>         mtk_crtc->mmsys_dev = priv->mmsys_dev;
> +       mtk_crtc->drm_dev = priv->dev;
>         mtk_crtc->ddp_comp_nr = path_len;
>         mtk_crtc->ddp_comp = devm_kmalloc_array(dev, mtk_crtc->ddp_comp_nr,
>                                                 sizeof(*mtk_crtc->ddp_comp),
> @@ -969,6 +972,18 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>         }
>
>         if (mtk_crtc->cmdq_client.chan) {
> +               struct device_link *link;
> +
> +               /* add devlink to cmdq dev to make sure suspend/resume order is correct */
> +               link = device_link_add(priv->dev, mtk_crtc->cmdq_client.chan->mbox->dev,
> +                                      DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
> +               if (!link) {
> +                       dev_err(priv->dev, "Unable to link dev=%s\n",
> +                               dev_name(mtk_crtc->cmdq_client.chan->mbox->dev));
> +                       ret = -ENODEV;
> +                       goto cmdq_err;
> +               }
> +
>                 ret = of_property_read_u32_index(priv->mutex_node,
>                                                  "mediatek,gce-events",
>                                                  i,
> @@ -976,22 +991,26 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>                 if (ret) {
>                         dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
>                                 drm_crtc_index(&mtk_crtc->base));
> -                       mbox_free_channel(mtk_crtc->cmdq_client.chan);
> -                       mtk_crtc->cmdq_client.chan = NULL;
> -               } else {
> -                       ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
> -                                                     &mtk_crtc->cmdq_handle,
> -                                                     PAGE_SIZE);
> -                       if (ret) {
> -                               dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
> -                                       drm_crtc_index(&mtk_crtc->base));
> -                               mbox_free_channel(mtk_crtc->cmdq_client.chan);
> -                               mtk_crtc->cmdq_client.chan = NULL;
> -                       }
> +                       goto cmdq_err;
> +               }
> +
> +               ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
> +                                             &mtk_crtc->cmdq_handle,
> +                                             PAGE_SIZE);
> +               if (ret) {
> +                       dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
> +                               drm_crtc_index(&mtk_crtc->base));
> +                       goto cmdq_err;
>                 }
>
>                 /* for sending blocking cmd in crtc disable */
>                 init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
> +
> +cmdq_err:
> +               if (ret) {
> +                       mbox_free_channel(mtk_crtc->cmdq_client.chan);
> +                       mtk_crtc->cmdq_client.chan = NULL;
> +               }
>         }
>  #endif
>         return 0;
> --
> 2.18.0
>
Jason-JH Lin (林睿祥) March 1, 2022, 1:46 a.m. UTC | #3
Hi Chun-Kuang,

Thanks for the reviews.

I forgot to add the comment that the patch should be based on [1].
We can only apply it after applying [1].

So please apply it after that. Thank you very much!

Regards,
Jason-JH.Lin
---
[1] drm/mediatek: modify mediatek-drm for mt8195 multi mmsys support

https://patchwork.kernel.org/project/linux-mediatek/patch/20220222100741.30138-21-nancy.lin@mediatek.com/
---

On Sun, 2022-02-27 at 11:33 +0800, Chun-Kuang Hu wrote:
> Hi, Jason:
> 
> Build error:
> 
> ../drivers/gpu/drm/mediatek/mtk_drm_crtc.c: In function
> ‘mtk_drm_crtc_create’:
> ../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:902:26: error: ‘struct
> mtk_drm_private’ has no member named ‘dev’
>   mtk_crtc->drm_dev = priv->dev;
>                           ^
> ../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:974:30: error: ‘struct
> mtk_drm_private’ has no member named ‘dev’
>    link = device_link_add(priv->dev, mtk_crtc->cmdq_client.chan-
> >mbox->dev,
>                               ^
> In file included from ../include/linux/device.h:15:0,
>                  from ../include/linux/dma-mapping.h:7,
>                  from ../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:7:
> ../drivers/gpu/drm/mediatek/mtk_drm_crtc.c:977:16: error: ‘struct
> mtk_drm_private’ has no member named ‘dev’
>     dev_err(priv->dev, "Unable to link dev=%s\n",
>                 ^
> Regards,
> Chun-Kuang.
diff mbox series

Patch

diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
index 0b4012335e7a..612d1d69c16c 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -60,6 +60,7 @@  struct mtk_drm_crtc {
 #endif
 
 	struct device			*mmsys_dev;
+	struct device			*drm_dev;
 	struct mtk_mutex		*mutex;
 	unsigned int			ddp_comp_nr;
 	struct mtk_ddp_comp		**ddp_comp;
@@ -159,6 +160,7 @@  static void mtk_drm_crtc_destroy(struct drm_crtc *crtc)
 	mtk_drm_cmdq_pkt_destroy(&mtk_crtc->cmdq_handle);
 
 	if (mtk_crtc->cmdq_client.chan) {
+		device_link_remove(mtk_crtc->drm_dev, mtk_crtc->cmdq_client.chan->mbox->dev);
 		mbox_free_channel(mtk_crtc->cmdq_client.chan);
 		mtk_crtc->cmdq_client.chan = NULL;
 	}
@@ -902,6 +904,7 @@  int mtk_drm_crtc_create(struct drm_device *drm_dev,
 		return -ENOMEM;
 
 	mtk_crtc->mmsys_dev = priv->mmsys_dev;
+	mtk_crtc->drm_dev = priv->dev;
 	mtk_crtc->ddp_comp_nr = path_len;
 	mtk_crtc->ddp_comp = devm_kmalloc_array(dev, mtk_crtc->ddp_comp_nr,
 						sizeof(*mtk_crtc->ddp_comp),
@@ -969,6 +972,18 @@  int mtk_drm_crtc_create(struct drm_device *drm_dev,
 	}
 
 	if (mtk_crtc->cmdq_client.chan) {
+		struct device_link *link;
+
+		/* add devlink to cmdq dev to make sure suspend/resume order is correct */
+		link = device_link_add(priv->dev, mtk_crtc->cmdq_client.chan->mbox->dev,
+				       DL_FLAG_PM_RUNTIME | DL_FLAG_STATELESS);
+		if (!link) {
+			dev_err(priv->dev, "Unable to link dev=%s\n",
+				dev_name(mtk_crtc->cmdq_client.chan->mbox->dev));
+			ret = -ENODEV;
+			goto cmdq_err;
+		}
+
 		ret = of_property_read_u32_index(priv->mutex_node,
 						 "mediatek,gce-events",
 						 i,
@@ -976,22 +991,26 @@  int mtk_drm_crtc_create(struct drm_device *drm_dev,
 		if (ret) {
 			dev_dbg(dev, "mtk_crtc %d failed to get mediatek,gce-events property\n",
 				drm_crtc_index(&mtk_crtc->base));
-			mbox_free_channel(mtk_crtc->cmdq_client.chan);
-			mtk_crtc->cmdq_client.chan = NULL;
-		} else {
-			ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
-						      &mtk_crtc->cmdq_handle,
-						      PAGE_SIZE);
-			if (ret) {
-				dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
-					drm_crtc_index(&mtk_crtc->base));
-				mbox_free_channel(mtk_crtc->cmdq_client.chan);
-				mtk_crtc->cmdq_client.chan = NULL;
-			}
+			goto cmdq_err;
+		}
+
+		ret = mtk_drm_cmdq_pkt_create(&mtk_crtc->cmdq_client,
+					      &mtk_crtc->cmdq_handle,
+					      PAGE_SIZE);
+		if (ret) {
+			dev_dbg(dev, "mtk_crtc %d failed to create cmdq packet\n",
+				drm_crtc_index(&mtk_crtc->base));
+			goto cmdq_err;
 		}
 
 		/* for sending blocking cmd in crtc disable */
 		init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
+
+cmdq_err:
+		if (ret) {
+			mbox_free_channel(mtk_crtc->cmdq_client.chan);
+			mtk_crtc->cmdq_client.chan = NULL;
+		}
 	}
 #endif
 	return 0;