diff mbox series

[v4,1/2] drm/mediatek: add wait_for_event for crtc disable by cmdq

Message ID 20211202064039.20797-2-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
mtk_drm_crtc_atomic_disable will send an async cmd to cmdq driver,
so it may not finish when cmdq_suspend is called sometimes.

Add wait_for_event after sending async disable plane cmd to make
sure the lastest cmd is done before cmdq_suspend.

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

Comments

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

jason-jh.lin <jason-jh.lin@mediatek.com> 於 2021年12月2日 週四 下午2:41寫道:
>
> mtk_drm_crtc_atomic_disable will send an async cmd to cmdq driver,
> so it may not finish when cmdq_suspend is called sometimes.
>
> Add wait_for_event after sending async disable plane cmd to make
> sure the lastest cmd is done before cmdq_suspend.

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 | 12 ++++++++++++
>  1 file changed, 12 insertions(+)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> index 62529a954b62..0b4012335e7a 100644
> --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> @@ -56,6 +56,7 @@ struct mtk_drm_crtc {
>         struct cmdq_pkt                 cmdq_handle;
>         u32                             cmdq_event;
>         u32                             cmdq_vblank_cnt;
> +       wait_queue_head_t               cb_blocking_queue;
>  #endif
>
>         struct device                   *mmsys_dev;
> @@ -314,6 +315,7 @@ static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
>         }
>
>         mtk_crtc->cmdq_vblank_cnt = 0;
> +       wake_up(&mtk_crtc->cb_blocking_queue);
>  }
>  #endif
>
> @@ -700,6 +702,13 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
>         mtk_crtc->pending_planes = true;
>
>         mtk_drm_crtc_update_config(mtk_crtc, false);
> +#if IS_REACHABLE(CONFIG_MTK_CMDQ)
> +       /* Wait for planes to be disabled by cmdq */
> +       if (mtk_crtc->cmdq_client.chan)
> +               wait_event_timeout(mtk_crtc->cb_blocking_queue,
> +                                  mtk_crtc->cmdq_vblank_cnt == 0,
> +                                  msecs_to_jiffies(500));
> +#endif
>         /* Wait for planes to be disabled */
>         drm_crtc_wait_one_vblank(crtc);
>
> @@ -980,6 +989,9 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
>                                 mtk_crtc->cmdq_client.chan = NULL;
>                         }
>                 }
> +
> +               /* for sending blocking cmd in crtc disable */
> +               init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
>         }
>  #endif
>         return 0;
> --
> 2.18.0
>
Chun-Kuang Hu Feb. 27, 2022, 3:36 a.m. UTC | #2
Hi, Jason:

Chun-Kuang Hu <chunkuang.hu@kernel.org> 於 2021年12月3日 週五 上午7:21寫道:
>
> Hi, Jason:
>
> jason-jh.lin <jason-jh.lin@mediatek.com> 於 2021年12月2日 週四 下午2:41寫道:
> >
> > mtk_drm_crtc_atomic_disable will send an async cmd to cmdq driver,
> > so it may not finish when cmdq_suspend is called sometimes.
> >
> > Add wait_for_event after sending async disable plane cmd to make
> > sure the lastest cmd is done before cmdq_suspend.
>
> Reviewed-by: Chun-Kuang Hu <chunkuang.hu@kernel.org>

Applied to mediatek-drm-next[1], thanks.

[1] https://git.kernel.org/pub/scm/linux/kernel/git/chunkuang.hu/linux.git/log/?h=mediatek-drm-next

Regards,
Chun-Kuang

>
> >
> > Signed-off-by: jason-jh.lin <jason-jh.lin@mediatek.com>
> > ---
> >  drivers/gpu/drm/mediatek/mtk_drm_crtc.c | 12 ++++++++++++
> >  1 file changed, 12 insertions(+)
> >
> > diff --git a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > index 62529a954b62..0b4012335e7a 100644
> > --- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
> > @@ -56,6 +56,7 @@ struct mtk_drm_crtc {
> >         struct cmdq_pkt                 cmdq_handle;
> >         u32                             cmdq_event;
> >         u32                             cmdq_vblank_cnt;
> > +       wait_queue_head_t               cb_blocking_queue;
> >  #endif
> >
> >         struct device                   *mmsys_dev;
> > @@ -314,6 +315,7 @@ static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
> >         }
> >
> >         mtk_crtc->cmdq_vblank_cnt = 0;
> > +       wake_up(&mtk_crtc->cb_blocking_queue);
> >  }
> >  #endif
> >
> > @@ -700,6 +702,13 @@ static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
> >         mtk_crtc->pending_planes = true;
> >
> >         mtk_drm_crtc_update_config(mtk_crtc, false);
> > +#if IS_REACHABLE(CONFIG_MTK_CMDQ)
> > +       /* Wait for planes to be disabled by cmdq */
> > +       if (mtk_crtc->cmdq_client.chan)
> > +               wait_event_timeout(mtk_crtc->cb_blocking_queue,
> > +                                  mtk_crtc->cmdq_vblank_cnt == 0,
> > +                                  msecs_to_jiffies(500));
> > +#endif
> >         /* Wait for planes to be disabled */
> >         drm_crtc_wait_one_vblank(crtc);
> >
> > @@ -980,6 +989,9 @@ int mtk_drm_crtc_create(struct drm_device *drm_dev,
> >                                 mtk_crtc->cmdq_client.chan = NULL;
> >                         }
> >                 }
> > +
> > +               /* for sending blocking cmd in crtc disable */
> > +               init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
> >         }
> >  #endif
> >         return 0;
> > --
> > 2.18.0
> >
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 62529a954b62..0b4012335e7a 100644
--- a/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_drm_crtc.c
@@ -56,6 +56,7 @@  struct mtk_drm_crtc {
 	struct cmdq_pkt			cmdq_handle;
 	u32				cmdq_event;
 	u32				cmdq_vblank_cnt;
+	wait_queue_head_t		cb_blocking_queue;
 #endif
 
 	struct device			*mmsys_dev;
@@ -314,6 +315,7 @@  static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
 	}
 
 	mtk_crtc->cmdq_vblank_cnt = 0;
+	wake_up(&mtk_crtc->cb_blocking_queue);
 }
 #endif
 
@@ -700,6 +702,13 @@  static void mtk_drm_crtc_atomic_disable(struct drm_crtc *crtc,
 	mtk_crtc->pending_planes = true;
 
 	mtk_drm_crtc_update_config(mtk_crtc, false);
+#if IS_REACHABLE(CONFIG_MTK_CMDQ)
+	/* Wait for planes to be disabled by cmdq */
+	if (mtk_crtc->cmdq_client.chan)
+		wait_event_timeout(mtk_crtc->cb_blocking_queue,
+				   mtk_crtc->cmdq_vblank_cnt == 0,
+				   msecs_to_jiffies(500));
+#endif
 	/* Wait for planes to be disabled */
 	drm_crtc_wait_one_vblank(crtc);
 
@@ -980,6 +989,9 @@  int mtk_drm_crtc_create(struct drm_device *drm_dev,
 				mtk_crtc->cmdq_client.chan = NULL;
 			}
 		}
+
+		/* for sending blocking cmd in crtc disable */
+		init_waitqueue_head(&mtk_crtc->cb_blocking_queue);
 	}
 #endif
 	return 0;