mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config()
@ 2024-07-03 10:33 Jason-JH.Lin
  2024-07-04  8:39 ` AngeloGioacchino Del Regno
  2024-08-16  4:03 ` Chun-Kuang Hu
  0 siblings, 2 replies; 4+ messages in thread
From: Jason-JH.Lin @ 2024-07-03 10:33 UTC (permalink / raw)
  To: Chun-Kuang Hu, AngeloGioacchino Del Regno
  Cc: dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel,
	Jason-JH . Lin, Singo Chang, Nancy Lin,
	Project_Global_Chrome_Upstream_Group, Jeffrey Kardatzke

In mtk_crtc_ddp_config(), mtk_crtc will use some configuration flags to
generate instructions to cmdq_handle, such as:
  state->pending_config
  mtk_crtc->pending_planes
  plane_state->pending.config
  mtk_crtc->pending_async_planes
  plane_state->pending.async_config

These configuration flags may be set to false when a GCE IRQ comes calling
ddp_cmdq_cb(). This may result in missing prepare instructions,
especially if mtk_crtc_update_config() with the flase need_vblank (no need
to wait for vblank) cases.

Therefore, use the mtk_crtc->config_updating flag set at the beginning of
mtk_crtc_update_config() to ensure that these configuration flags won't be
changed when the mtk_crtc_ddp_config() is preparing instructions.

Fixes: 7f82d9c43879 ("drm/mediatek: Clear pending flag when cmdq packet is done")
Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
---
 drivers/gpu/drm/mediatek/mtk_crtc.c | 34 +++++++++++++++--------------
 1 file changed, 18 insertions(+), 16 deletions(-)

diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
index 6f34f573e127..bc3bf0c3edd9 100644
--- a/drivers/gpu/drm/mediatek/mtk_crtc.c
+++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
@@ -314,30 +314,32 @@ static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
 
 	state = to_mtk_crtc_state(mtk_crtc->base.state);
 
-	state->pending_config = false;
+	if (!mtk_crtc->config_updating) {
+		state->pending_config = false;
 
-	if (mtk_crtc->pending_planes) {
-		for (i = 0; i < mtk_crtc->layer_nr; i++) {
-			struct drm_plane *plane = &mtk_crtc->planes[i];
-			struct mtk_plane_state *plane_state;
+		if (mtk_crtc->pending_planes) {
+			for (i = 0; i < mtk_crtc->layer_nr; i++) {
+				struct drm_plane *plane = &mtk_crtc->planes[i];
+				struct mtk_plane_state *plane_state;
 
-			plane_state = to_mtk_plane_state(plane->state);
+				plane_state = to_mtk_plane_state(plane->state);
 
-			plane_state->pending.config = false;
+				plane_state->pending.config = false;
+			}
+			mtk_crtc->pending_planes = false;
 		}
-		mtk_crtc->pending_planes = false;
-	}
 
-	if (mtk_crtc->pending_async_planes) {
-		for (i = 0; i < mtk_crtc->layer_nr; i++) {
-			struct drm_plane *plane = &mtk_crtc->planes[i];
-			struct mtk_plane_state *plane_state;
+		if (mtk_crtc->pending_async_planes) {
+			for (i = 0; i < mtk_crtc->layer_nr; i++) {
+				struct drm_plane *plane = &mtk_crtc->planes[i];
+				struct mtk_plane_state *plane_state;
 
-			plane_state = to_mtk_plane_state(plane->state);
+				plane_state = to_mtk_plane_state(plane->state);
 
-			plane_state->pending.async_config = false;
+				plane_state->pending.async_config = false;
+			}
+			mtk_crtc->pending_async_planes = false;
 		}
-		mtk_crtc->pending_async_planes = false;
 	}
 
 	mtk_crtc->cmdq_vblank_cnt = 0;
-- 
2.18.0


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

* Re: [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config()
  2024-07-03 10:33 [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config() Jason-JH.Lin
@ 2024-07-04  8:39 ` AngeloGioacchino Del Regno
  2024-08-16  4:03 ` Chun-Kuang Hu
  1 sibling, 0 replies; 4+ messages in thread
From: AngeloGioacchino Del Regno @ 2024-07-04  8:39 UTC (permalink / raw)
  To: Jason-JH.Lin, Chun-Kuang Hu
  Cc: dri-devel, linux-mediatek, linux-kernel, linux-arm-kernel,
	Singo Chang, Nancy Lin, Project_Global_Chrome_Upstream_Group,
	Jeffrey Kardatzke

Il 03/07/24 12:33, Jason-JH.Lin ha scritto:
> In mtk_crtc_ddp_config(), mtk_crtc will use some configuration flags to
> generate instructions to cmdq_handle, such as:
>    state->pending_config
>    mtk_crtc->pending_planes
>    plane_state->pending.config
>    mtk_crtc->pending_async_planes
>    plane_state->pending.async_config
> 
> These configuration flags may be set to false when a GCE IRQ comes calling
> ddp_cmdq_cb(). This may result in missing prepare instructions,
> especially if mtk_crtc_update_config() with the flase need_vblank (no need
> to wait for vblank) cases.
> 
> Therefore, use the mtk_crtc->config_updating flag set at the beginning of
> mtk_crtc_update_config() to ensure that these configuration flags won't be
> changed when the mtk_crtc_ddp_config() is preparing instructions.
> 
> Fixes: 7f82d9c43879 ("drm/mediatek: Clear pending flag when cmdq packet is done")
> Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>

Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>



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

* Re: [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config()
  2024-07-03 10:33 [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config() Jason-JH.Lin
  2024-07-04  8:39 ` AngeloGioacchino Del Regno
@ 2024-08-16  4:03 ` Chun-Kuang Hu
  2024-08-19 10:06   ` Jason-JH Lin (林睿祥)
  1 sibling, 1 reply; 4+ messages in thread
From: Chun-Kuang Hu @ 2024-08-16  4:03 UTC (permalink / raw)
  To: Jason-JH.Lin
  Cc: Chun-Kuang Hu, AngeloGioacchino Del Regno, dri-devel,
	linux-mediatek, linux-kernel, linux-arm-kernel, Singo Chang,
	Nancy Lin, Project_Global_Chrome_Upstream_Group,
	Jeffrey Kardatzke

Hi, Jason:

Jason-JH.Lin <jason-jh.lin@mediatek.com> 於 2024年7月3日 週三 下午6:33寫道:
>
> In mtk_crtc_ddp_config(), mtk_crtc will use some configuration flags to
> generate instructions to cmdq_handle, such as:
>   state->pending_config
>   mtk_crtc->pending_planes
>   plane_state->pending.config
>   mtk_crtc->pending_async_planes
>   plane_state->pending.async_config
>
> These configuration flags may be set to false when a GCE IRQ comes calling
> ddp_cmdq_cb(). This may result in missing prepare instructions,
> especially if mtk_crtc_update_config() with the flase need_vblank (no need
> to wait for vblank) cases.
>
> Therefore, use the mtk_crtc->config_updating flag set at the beginning of
> mtk_crtc_update_config() to ensure that these configuration flags won't be
> changed when the mtk_crtc_ddp_config() is preparing instructions.
>
> Fixes: 7f82d9c43879 ("drm/mediatek: Clear pending flag when cmdq packet is done")
> Signed-off-by: Jason-JH.Lin <jason-jh.lin@mediatek.com>
> ---
>  drivers/gpu/drm/mediatek/mtk_crtc.c | 34 +++++++++++++++--------------
>  1 file changed, 18 insertions(+), 16 deletions(-)
>
> diff --git a/drivers/gpu/drm/mediatek/mtk_crtc.c b/drivers/gpu/drm/mediatek/mtk_crtc.c
> index 6f34f573e127..bc3bf0c3edd9 100644
> --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> @@ -314,30 +314,32 @@ static void ddp_cmdq_cb(struct mbox_client *cl, void *mssg)
>
>         state = to_mtk_crtc_state(mtk_crtc->base.state);
>
> -       state->pending_config = false;
> +       if (!mtk_crtc->config_updating) {
> +               state->pending_config = false;

I think if mtk_crtc->config_updating == true, the whole clear job
could be skipped.
And use spin_lock to protect the clear job in irq.

/*
spin_lock():
if (mtk_crtc->config_updating) {
        spin_unlock();
        goto out;
}

/* clear job */

spin_unlock();
*/
out:

In mtk_crtc_config_update(), use spin_lock to protect mtk_crtc->config_updating:

spin_lock();
mtk_crtc->config_updating = true;
spin_unlock();
...
spin_lock();
mtk_crtc->config_updating = false;
spin_unlock();

Regards,
Chun-Kuang.


>
> -       if (mtk_crtc->pending_planes) {
> -               for (i = 0; i < mtk_crtc->layer_nr; i++) {
> -                       struct drm_plane *plane = &mtk_crtc->planes[i];
> -                       struct mtk_plane_state *plane_state;
> +               if (mtk_crtc->pending_planes) {
> +                       for (i = 0; i < mtk_crtc->layer_nr; i++) {
> +                               struct drm_plane *plane = &mtk_crtc->planes[i];
> +                               struct mtk_plane_state *plane_state;
>
> -                       plane_state = to_mtk_plane_state(plane->state);
> +                               plane_state = to_mtk_plane_state(plane->state);
>
> -                       plane_state->pending.config = false;
> +                               plane_state->pending.config = false;
> +                       }
> +                       mtk_crtc->pending_planes = false;
>                 }
> -               mtk_crtc->pending_planes = false;
> -       }
>
> -       if (mtk_crtc->pending_async_planes) {
> -               for (i = 0; i < mtk_crtc->layer_nr; i++) {
> -                       struct drm_plane *plane = &mtk_crtc->planes[i];
> -                       struct mtk_plane_state *plane_state;
> +               if (mtk_crtc->pending_async_planes) {
> +                       for (i = 0; i < mtk_crtc->layer_nr; i++) {
> +                               struct drm_plane *plane = &mtk_crtc->planes[i];
> +                               struct mtk_plane_state *plane_state;
>
> -                       plane_state = to_mtk_plane_state(plane->state);
> +                               plane_state = to_mtk_plane_state(plane->state);
>
> -                       plane_state->pending.async_config = false;
> +                               plane_state->pending.async_config = false;
> +                       }
> +                       mtk_crtc->pending_async_planes = false;
>                 }
> -               mtk_crtc->pending_async_planes = false;
>         }
>
>         mtk_crtc->cmdq_vblank_cnt = 0;
> --
> 2.18.0
>

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

* Re: [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config()
  2024-08-16  4:03 ` Chun-Kuang Hu
@ 2024-08-19 10:06   ` Jason-JH Lin (林睿祥)
  0 siblings, 0 replies; 4+ messages in thread
From: Jason-JH Lin (林睿祥) @ 2024-08-19 10:06 UTC (permalink / raw)
  To: chunkuang.hu
  Cc: linux-kernel, linux-mediatek,
	Singo Chang (張興國),
	Nancy Lin (林欣螢),
	jkardatzke, dri-devel, Project_Global_Chrome_Upstream_Group,
	linux-arm-kernel, angelogioacchino.delregno

Hi CK,

> > --- a/drivers/gpu/drm/mediatek/mtk_crtc.c
> > +++ b/drivers/gpu/drm/mediatek/mtk_crtc.c
> > @@ -314,30 +314,32 @@ static void ddp_cmdq_cb(struct mbox_client
> *cl, void *mssg)
> >
> >         state = to_mtk_crtc_state(mtk_crtc->base.state);
> >
> > -       state->pending_config = false;
> > +       if (!mtk_crtc->config_updating) {
> > +               state->pending_config = false;
> 
> I think if mtk_crtc->config_updating == true, the whole clear job
> could be skipped.
> And use spin_lock to protect the clear job in irq.
> 
> /*
> spin_lock():
> if (mtk_crtc->config_updating) {
>         spin_unlock();
>         goto out;
> }
> 
> /* clear job */
> 
> spin_unlock();
> */
> out:
> 
> In mtk_crtc_config_update(), use spin_lock to protect mtk_crtc-
> >config_updating:
> 
> spin_lock();
> mtk_crtc->config_updating = true;
> spin_unlock();
> ...
> spin_lock();
> mtk_crtc->config_updating = false;
> spin_unlock();
> 

Thanks for the reviews.

I think that's more solid to protect the updating config of cmd buffer.

I will also add spin_lock for the whole statement in
mtk_drm_finish_page_flip() because config_updating flag is covered the
pending_need_vblank flag.

Regards,
Jason-JH.Lin

> Regards,
> Chun-Kuang.
> 
> 
> >
> > -       if (mtk_crtc->pending_planes) {
> > -               for (i = 0; i < mtk_crtc->layer_nr; i++) {
> > -                       struct drm_plane *plane = &mtk_crtc-
> >planes[i];
> > -                       struct mtk_plane_state *plane_state;
> > +               if (mtk_crtc->pending_planes) {
> > +                       for (i = 0; i < mtk_crtc->layer_nr; i++) {
> > +                               struct drm_plane *plane =
> &mtk_crtc->planes[i];
> > +                               struct mtk_plane_state
> *plane_state;
> >
> > -                       plane_state = to_mtk_plane_state(plane-
> >state);
> > +                               plane_state =
> to_mtk_plane_state(plane->state);
> >
> > -                       plane_state->pending.config = false;
> > +                               plane_state->pending.config =
> false;
> > +                       }
> > +                       mtk_crtc->pending_planes = false;
> >                 }
> > -               mtk_crtc->pending_planes = false;
> > -       }
> >
> > -       if (mtk_crtc->pending_async_planes) {
> > -               for (i = 0; i < mtk_crtc->layer_nr; i++) {
> > -                       struct drm_plane *plane = &mtk_crtc-
> >planes[i];
> > -                       struct mtk_plane_state *plane_state;
> > +               if (mtk_crtc->pending_async_planes) {
> > +                       for (i = 0; i < mtk_crtc->layer_nr; i++) {
> > +                               struct drm_plane *plane =
> &mtk_crtc->planes[i];
> > +                               struct mtk_plane_state
> *plane_state;
> >
> > -                       plane_state = to_mtk_plane_state(plane-
> >state);
> > +                               plane_state =
> to_mtk_plane_state(plane->state);
> >
> > -                       plane_state->pending.async_config = false;
> > +                               plane_state->pending.async_config =
> false;
> > +                       }
> > +                       mtk_crtc->pending_async_planes = false;
> >                 }
> > -               mtk_crtc->pending_async_planes = false;
> >         }
> >
> >         mtk_crtc->cmdq_vblank_cnt = 0;
> > --
> > 2.18.0
> >

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

end of thread, other threads:[~2024-08-19 10:06 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-07-03 10:33 [PATCH] drm/mediatek: Fix missing configuration flags in mtk_crtc_ddp_config() Jason-JH.Lin
2024-07-04  8:39 ` AngeloGioacchino Del Regno
2024-08-16  4:03 ` Chun-Kuang Hu
2024-08-19 10:06   ` Jason-JH Lin (林睿祥)

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®