All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 0/3] drm/sti: move commit work out of .atomic_check()
@ 2026-11-25 14:23 Minseo Park
  2026-11-25 14:23 ` [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check() Minseo Park
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Minseo Park @ 2026-11-25 14:23 UTC (permalink / raw)
  To: dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, benjamin.gaignard, Minseo Park

The three plane .atomic_check() implementations in drivers/gpu/drm/sti
do work that belongs in the commit phase.  The cursor frees and
reallocates its pixmap, the GDP reparents and reclocks the pixel clock,
and the HQVDP boots its coprocessor and registers a VTG notifier.

DRM_MODE_ATOMIC_TEST_ONLY runs drm_atomic_check_only(), which calls the
plane .atomic_check() hooks and returns without ever calling
.atomic_update(), and a commit that fails a check on any other object is
dropped the same way.  Either path leaves the hardware changed by a
configuration that was never applied.

The cursor is the worst of the three.  The buffer it frees is the one
CUR_PML points at, so the display engine keeps reading it after it has
gone back to the DMA pool.

I do not have STiH4xx hardware, so this comes from reading the code
rather than from an observed failure.  The series builds warning free
with W=1 and COMPILE_TEST on x86_64.  Testing on a real board would be
appreciated.

Minseo Park (3):
  drm/sti: cursor: do not resize the pixmap from .atomic_check()
  drm/sti: gdp: set the pixel clock from .atomic_update()
  drm/sti: hqvdp: start the XP70 from .atomic_update()

 drivers/gpu/drm/sti/sti_cursor.c | 65 ++++++++++++++------------------
 drivers/gpu/drm/sti/sti_gdp.c    | 52 ++++++++++++-------------
 drivers/gpu/drm/sti/sti_hqvdp.c  | 43 +++++++++++----------
 3 files changed, 74 insertions(+), 86 deletions(-)


base-commit: 4dce97c6c265544342e716e62fd24bbb232590c5
-- 
2.43.0


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

* [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check()
  2026-11-25 14:23 [PATCH 0/3] drm/sti: move commit work out of .atomic_check() Minseo Park
@ 2026-11-25 14:23 ` Minseo Park
  2026-11-25 14:39   ` Thomas Zimmermann
  2026-11-25 14:23 ` [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update() Minseo Park
  2026-11-25 14:23 ` [PATCH 3/3] drm/sti: hqvdp: start the XP70 " Minseo Park
  2 siblings, 1 reply; 7+ messages in thread
From: Minseo Park @ 2026-11-25 14:23 UTC (permalink / raw)
  To: dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, benjamin.gaignard, Minseo Park

sti_cursor_atomic_check() resizes the cursor pixmap whenever the
requested size differs from the one it cached: it frees the buffer the
hardware is using and allocates a new one.

That is commit work done in the check phase.  An atomic commit with
DRM_MODE_ATOMIC_TEST_ONLY runs drm_atomic_check_only(), which calls the
plane .atomic_check() hooks and returns without ever calling
.atomic_update(), and a commit whose check fails on some other object is
dropped the same way.  In both cases the buffer is freed while CUR_PML
still points at it, so the display engine keeps fetching the cursor from
memory that has gone back to the DMA pool, until some later commit
reprograms the register.

.atomic_check() already rejects a cursor wider or taller than
STI_CURS_MAX_SIZE, and the pixmap is CLUT8, so it never needs to be
larger than 128 * 128 bytes.  Allocate it once when the plane is created
and keep it for the lifetime of the device, with the managed allocator
so that it is released on unbind.  Nothing has to be resized afterwards.

With the pixmap no longer resized, struct sti_cursor does not need to
cache the cursor size either.  .atomic_update() takes it from the plane
state it is handed, which is the state .atomic_check() validated.  The
dev member goes with them, it only had users in the code being removed.

Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
Signed-off-by: Minseo Park <hiyoukou@gmail.com>
---
 drivers/gpu/drm/sti/sti_cursor.c | 65 ++++++++++++++------------------
 1 file changed, 28 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_cursor.c b/drivers/gpu/drm/sti/sti_cursor.c
index 66f56355309f..0f0d7405dfef 100644
--- a/drivers/gpu/drm/sti/sti_cursor.c
+++ b/drivers/gpu/drm/sti/sti_cursor.c
@@ -53,20 +53,14 @@ struct dma_pixmap {
  * STI Cursor structure
  *
  * @sti_plane:    sti_plane structure
- * @dev:          driver device
  * @regs:         cursor registers
- * @width:        cursor width
- * @height:       cursor height
  * @clut:         color look up table
  * @clut_paddr:   color look up table physical address
  * @pixmap:       pixmap dma buffer (clut8-format cursor)
  */
 struct sti_cursor {
 	struct sti_plane plane;
-	struct device *dev;
 	void __iomem *regs;
-	unsigned int width;
-	unsigned int height;
 	unsigned short *clut;
 	dma_addr_t clut_paddr;
 	struct dma_pixmap pixmap;
@@ -146,14 +140,15 @@ static void cursor_debugfs_init(struct sti_cursor *cursor,
 				 minor->debugfs_root, minor);
 }
 
-static void sti_cursor_argb8888_to_clut8(struct sti_cursor *cursor, u32 *src)
+static void sti_cursor_argb8888_to_clut8(struct sti_cursor *cursor, u32 *src,
+					 unsigned int width, unsigned int height)
 {
 	u8  *dst = cursor->pixmap.base;
 	unsigned int i, j;
 	u32 a, r, g, b;
 
-	for (i = 0; i < cursor->height; i++) {
-		for (j = 0; j < cursor->width; j++) {
+	for (i = 0; i < height; i++) {
+		for (j = 0; j < width; j++) {
 			/* Pick the 2 higher bits of each component */
 			a = (*src >> 30) & 3;
 			r = (*src >> 22) & 3;
@@ -188,7 +183,6 @@ static int sti_cursor_atomic_check(struct drm_plane *drm_plane,
 	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
 										 drm_plane);
 	struct sti_plane *plane = to_sti_plane(drm_plane);
-	struct sti_cursor *cursor = to_sti_cursor(plane);
 	struct drm_crtc *crtc = new_plane_state->crtc;
 	struct drm_framebuffer *fb = new_plane_state->fb;
 	struct drm_crtc_state *crtc_state;
@@ -224,29 +218,6 @@ static int sti_cursor_atomic_check(struct drm_plane *drm_plane,
 		return -EINVAL;
 	}
 
-	/* If the cursor size has changed, re-allocated the pixmap */
-	if (!cursor->pixmap.base ||
-	    (cursor->width != src_w) ||
-	    (cursor->height != src_h)) {
-		cursor->width = src_w;
-		cursor->height = src_h;
-
-		if (cursor->pixmap.base)
-			dma_free_wc(cursor->dev, cursor->pixmap.size,
-				    cursor->pixmap.base, cursor->pixmap.paddr);
-
-		cursor->pixmap.size = cursor->width * cursor->height;
-
-		cursor->pixmap.base = dma_alloc_wc(cursor->dev,
-						   cursor->pixmap.size,
-						   &cursor->pixmap.paddr,
-						   GFP_KERNEL);
-		if (!cursor->pixmap.base) {
-			DRM_ERROR("Failed to allocate memory for pixmap\n");
-			return -EINVAL;
-		}
-	}
-
 	if (!drm_fb_dma_get_gem_obj(fb, 0)) {
 		DRM_ERROR("Can't get DMA GEM object for fb\n");
 		return -EINVAL;
@@ -271,6 +242,7 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
 	struct drm_framebuffer *fb = newstate->fb;
 	struct drm_display_mode *mode;
 	int dst_x, dst_y;
+	unsigned int src_w, src_h;
 	struct drm_gem_dma_object *dma_obj;
 	u32 y, x;
 	u32 val;
@@ -281,11 +253,15 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
 	mode = &crtc->mode;
 	dst_x = newstate->crtc_x;
 	dst_y = newstate->crtc_y;
+	/* src_w and src_h are in 16.16 format */
+	src_w = newstate->src_w >> 16;
+	src_h = newstate->src_h >> 16;
 
 	dma_obj = drm_fb_dma_get_gem_obj(fb, 0);
 
 	/* Convert ARGB8888 to CLUT8 */
-	sti_cursor_argb8888_to_clut8(cursor, (u32 *)dma_obj->vaddr);
+	sti_cursor_argb8888_to_clut8(cursor, (u32 *)dma_obj->vaddr,
+				     src_w, src_h);
 
 	/* AWS and AWE depend on the mode */
 	y = sti_vtg_get_line_number(*mode, 0);
@@ -299,8 +275,8 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
 
 	/* Set memory location, size, and position */
 	writel(cursor->pixmap.paddr, cursor->regs + CUR_PML);
-	writel(cursor->width, cursor->regs + CUR_PMP);
-	writel(cursor->height << 16 | cursor->width, cursor->regs + CUR_SIZE);
+	writel(src_w, cursor->regs + CUR_PMP);
+	writel(src_h << 16 | src_w, cursor->regs + CUR_SIZE);
 
 	y = sti_vtg_get_line_number(*mode, dst_y);
 	x = sti_vtg_get_pixel_number(*mode, dst_x);
@@ -377,6 +353,22 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
 		return NULL;
 	}
 
+	/*
+	 * Allocate the pixmap once, for the largest cursor the hardware
+	 * supports.  It used to be reallocated from .atomic_check(), which
+	 * freed a buffer the display engine could still be scanning out.
+	 * Use the managed helper so it is released with the device.
+	 */
+	cursor->pixmap.size = STI_CURS_MAX_SIZE * STI_CURS_MAX_SIZE;
+	cursor->pixmap.base = dmam_alloc_attrs(dev, cursor->pixmap.size,
+					       &cursor->pixmap.paddr,
+					       GFP_KERNEL,
+					       DMA_ATTR_WRITE_COMBINE);
+	if (!cursor->pixmap.base) {
+		DRM_ERROR("Failed to allocate memory for pixmap\n");
+		goto err_clut;
+	}
+
 	/* Allocate clut buffer */
 	size = 0x100 * sizeof(unsigned short);
 	cursor->clut = dma_alloc_wc(dev, size, &cursor->clut_paddr,
@@ -387,7 +379,6 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
 		goto err_clut;
 	}
 
-	cursor->dev = dev;
 	cursor->regs = baseaddr;
 	cursor->plane.desc = desc;
 	cursor->plane.status = STI_PLANE_DISABLED;
-- 
2.43.0


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

* [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update()
  2026-11-25 14:23 [PATCH 0/3] drm/sti: move commit work out of .atomic_check() Minseo Park
  2026-11-25 14:23 ` [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check() Minseo Park
@ 2026-11-25 14:23 ` Minseo Park
  2026-11-25 14:41   ` Thomas Zimmermann
  2026-11-25 14:23 ` [PATCH 3/3] drm/sti: hqvdp: start the XP70 " Minseo Park
  2 siblings, 1 reply; 7+ messages in thread
From: Minseo Park @ 2026-11-25 14:23 UTC (permalink / raw)
  To: dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, benjamin.gaignard, Minseo Park

sti_gdp_atomic_check() reparents the GDP pixel clock and calls
clk_set_rate() on it with the clock of the mode being checked.

.atomic_check() must not touch the hardware.  A commit with
DRM_MODE_ATOMIC_TEST_ONLY only runs the check hooks, and a commit that
fails a later check is dropped, so in both cases the clock of a mode
that was never applied is programmed on a display that is still scanning
out the previous one.

Move the clock setup to .atomic_update(), where the rest of the plane is
programmed.  A clk_set_rate() failure can no longer reject the commit,
so it is logged and the plane is left as it was.

Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
Signed-off-by: Minseo Park <hiyoukou@gmail.com>
---
 drivers/gpu/drm/sti/sti_gdp.c | 52 +++++++++++++++++------------------
 1 file changed, 25 insertions(+), 27 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
index d0c886029c57..09f8d3f936ca 100644
--- a/drivers/gpu/drm/sti/sti_gdp.c
+++ b/drivers/gpu/drm/sti/sti_gdp.c
@@ -623,7 +623,6 @@ static int sti_gdp_atomic_check(struct drm_plane *drm_plane,
 	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
 										 drm_plane);
 	struct sti_plane *plane = to_sti_plane(drm_plane);
-	struct sti_gdp *gdp = to_sti_gdp(plane);
 	struct drm_crtc *crtc = new_plane_state->crtc;
 	struct drm_framebuffer *fb =  new_plane_state->fb;
 	struct drm_crtc_state *crtc_state;
@@ -667,32 +666,6 @@ static int sti_gdp_atomic_check(struct drm_plane *drm_plane,
 		return -EINVAL;
 	}
 
-	/* Set gdp clock */
-	if (mode->clock && gdp->clk_pix) {
-		struct clk *clkp;
-		int rate = mode->clock * 1000;
-		int res;
-
-		/*
-		 * According to the mixer used, the gdp pixel clock
-		 * should have a different parent clock.
-		 */
-		if (mixer->id == STI_MIXER_MAIN)
-			clkp = gdp->clk_main_parent;
-		else
-			clkp = gdp->clk_aux_parent;
-
-		if (clkp)
-			clk_set_parent(gdp->clk_pix, clkp);
-
-		res = clk_set_rate(gdp->clk_pix, rate);
-		if (res < 0) {
-			DRM_ERROR("Cannot set rate (%dHz) for gdp\n",
-				  rate);
-			return -EINVAL;
-		}
-	}
-
 	DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
 		      crtc->base.id, sti_mixer_to_str(mixer),
 		      drm_plane->base.id, sti_plane_to_str(plane));
@@ -757,6 +730,31 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
 	}
 
 	mode = &crtc->mode;
+
+	/* Set gdp clock */
+	if (mode->clock && gdp->clk_pix) {
+		struct sti_mixer *mixer = to_sti_mixer(crtc);
+		int rate = mode->clock * 1000;
+		struct clk *clkp;
+
+		/*
+		 * According to the mixer used, the gdp pixel clock
+		 * should have a different parent clock.
+		 */
+		if (mixer->id == STI_MIXER_MAIN)
+			clkp = gdp->clk_main_parent;
+		else
+			clkp = gdp->clk_aux_parent;
+
+		if (clkp)
+			clk_set_parent(gdp->clk_pix, clkp);
+
+		if (clk_set_rate(gdp->clk_pix, rate) < 0) {
+			DRM_ERROR("Cannot set rate (%dHz) for gdp\n", rate);
+			return;
+		}
+	}
+
 	dst_x = newstate->crtc_x;
 	dst_y = newstate->crtc_y;
 	dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);
-- 
2.43.0


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

* [PATCH 3/3] drm/sti: hqvdp: start the XP70 from .atomic_update()
  2026-11-25 14:23 [PATCH 0/3] drm/sti: move commit work out of .atomic_check() Minseo Park
  2026-11-25 14:23 ` [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check() Minseo Park
  2026-11-25 14:23 ` [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update() Minseo Park
@ 2026-11-25 14:23 ` Minseo Park
  2026-11-25 14:44   ` Thomas Zimmermann
  2 siblings, 1 reply; 7+ messages in thread
From: Minseo Park @ 2026-11-25 14:23 UTC (permalink / raw)
  To: dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard,
	tzimmermann, airlied, simona, benjamin.gaignard, Minseo Park

sti_hqvdp_atomic_check() boots the XP70 coprocessor, which loads its
firmware, then enables the main pixel clock and registers a VTG vsync
notifier.

.atomic_check() must not touch the hardware.  A commit with
DRM_MODE_ATOMIC_TEST_ONLY only runs the check hooks, so a client asking
whether a configuration is possible ends up loading firmware and
enabling a clock.

Both are one-shot, guarded by hqvdp->xp70_initialized and
hqvdp->vtg_registered, so nothing leaks, but they belong in the commit
phase.  Move them to .atomic_update().  As with the GDP, the failure
paths now log and return instead of rejecting the commit.

Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
Signed-off-by: Minseo Park <hiyoukou@gmail.com>
---
 drivers/gpu/drm/sti/sti_hqvdp.c | 43 ++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/drivers/gpu/drm/sti/sti_hqvdp.c b/drivers/gpu/drm/sti/sti_hqvdp.c
index 360d213f2094..66abbe4de864 100644
--- a/drivers/gpu/drm/sti/sti_hqvdp.c
+++ b/drivers/gpu/drm/sti/sti_hqvdp.c
@@ -1081,28 +1081,6 @@ static int sti_hqvdp_atomic_check(struct drm_plane *drm_plane,
 		return -EINVAL;
 	}
 
-	if (!hqvdp->xp70_initialized)
-		/* Start HQVDP XP70 coprocessor */
-		sti_hqvdp_start_xp70(hqvdp);
-
-	if (!hqvdp->vtg_registered) {
-		/* Prevent VTG shutdown */
-		if (clk_prepare_enable(hqvdp->clk_pix_main)) {
-			DRM_ERROR("Failed to prepare/enable pix main clk\n");
-			return -EINVAL;
-		}
-
-		/* Register VTG Vsync callback to handle bottom fields */
-		if (sti_vtg_register_client(hqvdp->vtg,
-					    &hqvdp->vtg_nb,
-					    crtc)) {
-			DRM_ERROR("Cannot register VTG notifier\n");
-			clk_disable_unprepare(hqvdp->clk_pix_main);
-			return -EINVAL;
-		}
-		hqvdp->vtg_registered = true;
-	}
-
 	DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
 		      crtc->base.id, sti_mixer_to_str(to_sti_mixer(crtc)),
 		      drm_plane->base.id, sti_plane_to_str(plane));
@@ -1152,6 +1130,27 @@ static void sti_hqvdp_atomic_update(struct drm_plane *drm_plane,
 	}
 
 	mode = &crtc->mode;
+
+	if (!hqvdp->xp70_initialized)
+		/* Start HQVDP XP70 coprocessor */
+		sti_hqvdp_start_xp70(hqvdp);
+
+	if (!hqvdp->vtg_registered) {
+		/* Prevent VTG shutdown */
+		if (clk_prepare_enable(hqvdp->clk_pix_main)) {
+			DRM_ERROR("Failed to prepare/enable pix main clk\n");
+			return;
+		}
+
+		/* Register VTG Vsync callback to handle bottom fields */
+		if (sti_vtg_register_client(hqvdp->vtg, &hqvdp->vtg_nb, crtc)) {
+			DRM_ERROR("Cannot register VTG notifier\n");
+			clk_disable_unprepare(hqvdp->clk_pix_main);
+			return;
+		}
+		hqvdp->vtg_registered = true;
+	}
+
 	dst_x = newstate->crtc_x;
 	dst_y = newstate->crtc_y;
 	dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);
-- 
2.43.0


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

* Re: [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check()
  2026-11-25 14:23 ` [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check() Minseo Park
@ 2026-11-25 14:39   ` Thomas Zimmermann
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Zimmermann @ 2026-11-25 14:39 UTC (permalink / raw)
  To: Minseo Park, dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard, airlied,
	simona, benjamin.gaignard

Hi

Am 25.11.26 um 15:23 schrieb Minseo Park:
> sti_cursor_atomic_check() resizes the cursor pixmap whenever the
> requested size differs from the one it cached: it frees the buffer the
> hardware is using and allocates a new one.
>
> That is commit work done in the check phase.  An atomic commit with
> DRM_MODE_ATOMIC_TEST_ONLY runs drm_atomic_check_only(), which calls the
> plane .atomic_check() hooks and returns without ever calling
> .atomic_update(), and a commit whose check fails on some other object is
> dropped the same way.  In both cases the buffer is freed while CUR_PML
> still points at it, so the display engine keeps fetching the cursor from
> memory that has gone back to the DMA pool, until some later commit
> reprograms the register.
>
> .atomic_check() already rejects a cursor wider or taller than
> STI_CURS_MAX_SIZE, and the pixmap is CLUT8, so it never needs to be
> larger than 128 * 128 bytes.  Allocate it once when the plane is created
> and keep it for the lifetime of the device, with the managed allocator
> so that it is released on unbind.  Nothing has to be resized afterwards.
>
> With the pixmap no longer resized, struct sti_cursor does not need to
> cache the cursor size either.  .atomic_update() takes it from the plane
> state it is handed, which is the state .atomic_check() validated.  The
> dev member goes with them, it only had users in the code being removed.
>
> Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
> Signed-off-by: Minseo Park <hiyoukou@gmail.com>
> ---
>   drivers/gpu/drm/sti/sti_cursor.c | 65 ++++++++++++++------------------
>   1 file changed, 28 insertions(+), 37 deletions(-)
>
> diff --git a/drivers/gpu/drm/sti/sti_cursor.c b/drivers/gpu/drm/sti/sti_cursor.c
> index 66f56355309f..0f0d7405dfef 100644
> --- a/drivers/gpu/drm/sti/sti_cursor.c
> +++ b/drivers/gpu/drm/sti/sti_cursor.c
> @@ -53,20 +53,14 @@ struct dma_pixmap {
>    * STI Cursor structure
>    *
>    * @sti_plane:    sti_plane structure
> - * @dev:          driver device
>    * @regs:         cursor registers
> - * @width:        cursor width
> - * @height:       cursor height
>    * @clut:         color look up table
>    * @clut_paddr:   color look up table physical address
>    * @pixmap:       pixmap dma buffer (clut8-format cursor)
>    */
>   struct sti_cursor {
>   	struct sti_plane plane;
> -	struct device *dev;
>   	void __iomem *regs;
> -	unsigned int width;
> -	unsigned int height;
>   	unsigned short *clut;
>   	dma_addr_t clut_paddr;
>   	struct dma_pixmap pixmap;
> @@ -146,14 +140,15 @@ static void cursor_debugfs_init(struct sti_cursor *cursor,
>   				 minor->debugfs_root, minor);
>   }
>   
> -static void sti_cursor_argb8888_to_clut8(struct sti_cursor *cursor, u32 *src)
> +static void sti_cursor_argb8888_to_clut8(struct sti_cursor *cursor, u32 *src,
> +					 unsigned int width, unsigned int height)
>   {
>   	u8  *dst = cursor->pixmap.base;
>   	unsigned int i, j;
>   	u32 a, r, g, b;
>   
> -	for (i = 0; i < cursor->height; i++) {
> -		for (j = 0; j < cursor->width; j++) {
> +	for (i = 0; i < height; i++) {
> +		for (j = 0; j < width; j++) {
>   			/* Pick the 2 higher bits of each component */
>   			a = (*src >> 30) & 3;
>   			r = (*src >> 22) & 3;
> @@ -188,7 +183,6 @@ static int sti_cursor_atomic_check(struct drm_plane *drm_plane,
>   	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
>   										 drm_plane);
>   	struct sti_plane *plane = to_sti_plane(drm_plane);
> -	struct sti_cursor *cursor = to_sti_cursor(plane);
>   	struct drm_crtc *crtc = new_plane_state->crtc;
>   	struct drm_framebuffer *fb = new_plane_state->fb;
>   	struct drm_crtc_state *crtc_state;
> @@ -224,29 +218,6 @@ static int sti_cursor_atomic_check(struct drm_plane *drm_plane,
>   		return -EINVAL;
>   	}
>   
> -	/* If the cursor size has changed, re-allocated the pixmap */
> -	if (!cursor->pixmap.base ||
> -	    (cursor->width != src_w) ||
> -	    (cursor->height != src_h)) {
> -		cursor->width = src_w;
> -		cursor->height = src_h;
> -
> -		if (cursor->pixmap.base)
> -			dma_free_wc(cursor->dev, cursor->pixmap.size,
> -				    cursor->pixmap.base, cursor->pixmap.paddr);
> -
> -		cursor->pixmap.size = cursor->width * cursor->height;
> -
> -		cursor->pixmap.base = dma_alloc_wc(cursor->dev,
> -						   cursor->pixmap.size,
> -						   &cursor->pixmap.paddr,
> -						   GFP_KERNEL);
> -		if (!cursor->pixmap.base) {
> -			DRM_ERROR("Failed to allocate memory for pixmap\n");
> -			return -EINVAL;
> -		}
> -	}
> -
>   	if (!drm_fb_dma_get_gem_obj(fb, 0)) {
>   		DRM_ERROR("Can't get DMA GEM object for fb\n");
>   		return -EINVAL;
> @@ -271,6 +242,7 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
>   	struct drm_framebuffer *fb = newstate->fb;
>   	struct drm_display_mode *mode;
>   	int dst_x, dst_y;
> +	unsigned int src_w, src_h;
>   	struct drm_gem_dma_object *dma_obj;
>   	u32 y, x;
>   	u32 val;
> @@ -281,11 +253,15 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
>   	mode = &crtc->mode;
>   	dst_x = newstate->crtc_x;
>   	dst_y = newstate->crtc_y;
> +	/* src_w and src_h are in 16.16 format */
> +	src_w = newstate->src_w >> 16;
> +	src_h = newstate->src_h >> 16;
>   
>   	dma_obj = drm_fb_dma_get_gem_obj(fb, 0);
>   
>   	/* Convert ARGB8888 to CLUT8 */
> -	sti_cursor_argb8888_to_clut8(cursor, (u32 *)dma_obj->vaddr);
> +	sti_cursor_argb8888_to_clut8(cursor, (u32 *)dma_obj->vaddr,
> +				     src_w, src_h);
>   
>   	/* AWS and AWE depend on the mode */
>   	y = sti_vtg_get_line_number(*mode, 0);
> @@ -299,8 +275,8 @@ static void sti_cursor_atomic_update(struct drm_plane *drm_plane,
>   
>   	/* Set memory location, size, and position */
>   	writel(cursor->pixmap.paddr, cursor->regs + CUR_PML);
> -	writel(cursor->width, cursor->regs + CUR_PMP);
> -	writel(cursor->height << 16 | cursor->width, cursor->regs + CUR_SIZE);
> +	writel(src_w, cursor->regs + CUR_PMP);
> +	writel(src_h << 16 | src_w, cursor->regs + CUR_SIZE);
>   
>   	y = sti_vtg_get_line_number(*mode, dst_y);
>   	x = sti_vtg_get_pixel_number(*mode, dst_x);
> @@ -377,6 +353,22 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
>   		return NULL;
>   	}
>   
> +	/*
> +	 * Allocate the pixmap once, for the largest cursor the hardware
> +	 * supports.  It used to be reallocated from .atomic_check(), which
> +	 * freed a buffer the display engine could still be scanning out.
> +	 * Use the managed helper so it is released with the device.
> +	 */
> +	cursor->pixmap.size = STI_CURS_MAX_SIZE * STI_CURS_MAX_SIZE;
> +	cursor->pixmap.base = dmam_alloc_attrs(dev, cursor->pixmap.size,
> +					       &cursor->pixmap.paddr,
> +					       GFP_KERNEL,
> +					       DMA_ATTR_WRITE_COMBINE);
> +	if (!cursor->pixmap.base) {
> +		DRM_ERROR("Failed to allocate memory for pixmap\n");

This macro needs to become drm_err().

Best regards
Thomas

> +		goto err_clut;
> +	}
> +
>   	/* Allocate clut buffer */
>   	size = 0x100 * sizeof(unsigned short);
>   	cursor->clut = dma_alloc_wc(dev, size, &cursor->clut_paddr,
> @@ -387,7 +379,6 @@ struct drm_plane *sti_cursor_create(struct drm_device *drm_dev,
>   		goto err_clut;
>   	}
>   
> -	cursor->dev = dev;
>   	cursor->regs = baseaddr;
>   	cursor->plane.desc = desc;
>   	cursor->plane.status = STI_PLANE_DISABLED;

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)



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

* Re: [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update()
  2026-11-25 14:23 ` [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update() Minseo Park
@ 2026-11-25 14:41   ` Thomas Zimmermann
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Zimmermann @ 2026-11-25 14:41 UTC (permalink / raw)
  To: Minseo Park, dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard, airlied,
	simona, benjamin.gaignard

Hi

Am 25.11.26 um 15:23 schrieb Minseo Park:
> sti_gdp_atomic_check() reparents the GDP pixel clock and calls
> clk_set_rate() on it with the clock of the mode being checked.
>
> .atomic_check() must not touch the hardware.  A commit with
> DRM_MODE_ATOMIC_TEST_ONLY only runs the check hooks, and a commit that
> fails a later check is dropped, so in both cases the clock of a mode
> that was never applied is programmed on a display that is still scanning
> out the previous one.
>
> Move the clock setup to .atomic_update(), where the rest of the plane is
> programmed.  A clk_set_rate() failure can no longer reject the commit,
> so it is logged and the plane is left as it was.
>
> Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
> Signed-off-by: Minseo Park <hiyoukou@gmail.com>
> ---
>   drivers/gpu/drm/sti/sti_gdp.c | 52 +++++++++++++++++------------------
>   1 file changed, 25 insertions(+), 27 deletions(-)
>
> diff --git a/drivers/gpu/drm/sti/sti_gdp.c b/drivers/gpu/drm/sti/sti_gdp.c
> index d0c886029c57..09f8d3f936ca 100644
> --- a/drivers/gpu/drm/sti/sti_gdp.c
> +++ b/drivers/gpu/drm/sti/sti_gdp.c
> @@ -623,7 +623,6 @@ static int sti_gdp_atomic_check(struct drm_plane *drm_plane,
>   	struct drm_plane_state *new_plane_state = drm_atomic_get_new_plane_state(state,
>   										 drm_plane);
>   	struct sti_plane *plane = to_sti_plane(drm_plane);
> -	struct sti_gdp *gdp = to_sti_gdp(plane);
>   	struct drm_crtc *crtc = new_plane_state->crtc;
>   	struct drm_framebuffer *fb =  new_plane_state->fb;
>   	struct drm_crtc_state *crtc_state;
> @@ -667,32 +666,6 @@ static int sti_gdp_atomic_check(struct drm_plane *drm_plane,
>   		return -EINVAL;
>   	}
>   
> -	/* Set gdp clock */
> -	if (mode->clock && gdp->clk_pix) {
> -		struct clk *clkp;
> -		int rate = mode->clock * 1000;
> -		int res;
> -
> -		/*
> -		 * According to the mixer used, the gdp pixel clock
> -		 * should have a different parent clock.
> -		 */
> -		if (mixer->id == STI_MIXER_MAIN)
> -			clkp = gdp->clk_main_parent;
> -		else
> -			clkp = gdp->clk_aux_parent;
> -
> -		if (clkp)
> -			clk_set_parent(gdp->clk_pix, clkp);
> -
> -		res = clk_set_rate(gdp->clk_pix, rate);
> -		if (res < 0) {
> -			DRM_ERROR("Cannot set rate (%dHz) for gdp\n",
> -				  rate);
> -			return -EINVAL;
> -		}
> -	}
> -

Unfortunately, the clk api appears to have no interface for testing a 
rate change without setting it.  Do you have at least a minimal and 
maximum supported pixel clock to test mode->clock against?

>   	DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
>   		      crtc->base.id, sti_mixer_to_str(mixer),
>   		      drm_plane->base.id, sti_plane_to_str(plane));
> @@ -757,6 +730,31 @@ static void sti_gdp_atomic_update(struct drm_plane *drm_plane,
>   	}
>   
>   	mode = &crtc->mode;
> +
> +	/* Set gdp clock */
> +	if (mode->clock && gdp->clk_pix) {
> +		struct sti_mixer *mixer = to_sti_mixer(crtc);
> +		int rate = mode->clock * 1000;
> +		struct clk *clkp;
> +
> +		/*
> +		 * According to the mixer used, the gdp pixel clock
> +		 * should have a different parent clock.
> +		 */
> +		if (mixer->id == STI_MIXER_MAIN)
> +			clkp = gdp->clk_main_parent;
> +		else
> +			clkp = gdp->clk_aux_parent;
> +
> +		if (clkp)
> +			clk_set_parent(gdp->clk_pix, clkp);
> +
> +		if (clk_set_rate(gdp->clk_pix, rate) < 0) {
> +			DRM_ERROR("Cannot set rate (%dHz) for gdp\n", rate);

This macro needs to become drm_err_once() or drm_dbg().

Best regards
Thomas

> +			return;
> +		}
> +	}
> +
>   	dst_x = newstate->crtc_x;
>   	dst_y = newstate->crtc_y;
>   	dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)



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

* Re: [PATCH 3/3] drm/sti: hqvdp: start the XP70 from .atomic_update()
  2026-11-25 14:23 ` [PATCH 3/3] drm/sti: hqvdp: start the XP70 " Minseo Park
@ 2026-11-25 14:44   ` Thomas Zimmermann
  0 siblings, 0 replies; 7+ messages in thread
From: Thomas Zimmermann @ 2026-11-25 14:44 UTC (permalink / raw)
  To: Minseo Park, dri-devel
  Cc: alain.volmat, rgallaispou, maarten.lankhorst, mripard, airlied,
	simona, benjamin.gaignard

Hi

Am 25.11.26 um 15:23 schrieb Minseo Park:
> sti_hqvdp_atomic_check() boots the XP70 coprocessor, which loads its
> firmware, then enables the main pixel clock and registers a VTG vsync
> notifier.
>
> .atomic_check() must not touch the hardware.  A commit with
> DRM_MODE_ATOMIC_TEST_ONLY only runs the check hooks, so a client asking
> whether a configuration is possible ends up loading firmware and
> enabling a clock.
>
> Both are one-shot, guarded by hqvdp->xp70_initialized and
> hqvdp->vtg_registered, so nothing leaks, but they belong in the commit
> phase.  Move them to .atomic_update().  As with the GDP, the failure
> paths now log and return instead of rejecting the commit.
>
> Fixes: dd86dc2f9ae1 ("drm/sti: implement atomic_check for the planes")
> Signed-off-by: Minseo Park <hiyoukou@gmail.com>
> ---
>   drivers/gpu/drm/sti/sti_hqvdp.c | 43 ++++++++++++++++-----------------
>   1 file changed, 21 insertions(+), 22 deletions(-)
>
> diff --git a/drivers/gpu/drm/sti/sti_hqvdp.c b/drivers/gpu/drm/sti/sti_hqvdp.c
> index 360d213f2094..66abbe4de864 100644
> --- a/drivers/gpu/drm/sti/sti_hqvdp.c
> +++ b/drivers/gpu/drm/sti/sti_hqvdp.c
> @@ -1081,28 +1081,6 @@ static int sti_hqvdp_atomic_check(struct drm_plane *drm_plane,
>   		return -EINVAL;
>   	}
>   
> -	if (!hqvdp->xp70_initialized)
> -		/* Start HQVDP XP70 coprocessor */
> -		sti_hqvdp_start_xp70(hqvdp);
> -
> -	if (!hqvdp->vtg_registered) {
> -		/* Prevent VTG shutdown */
> -		if (clk_prepare_enable(hqvdp->clk_pix_main)) {
> -			DRM_ERROR("Failed to prepare/enable pix main clk\n");
> -			return -EINVAL;
> -		}
> -
> -		/* Register VTG Vsync callback to handle bottom fields */
> -		if (sti_vtg_register_client(hqvdp->vtg,
> -					    &hqvdp->vtg_nb,
> -					    crtc)) {
> -			DRM_ERROR("Cannot register VTG notifier\n");
> -			clk_disable_unprepare(hqvdp->clk_pix_main);
> -			return -EINVAL;
> -		}
> -		hqvdp->vtg_registered = true;
> -	}
> -
>   	DRM_DEBUG_KMS("CRTC:%d (%s) drm plane:%d (%s)\n",
>   		      crtc->base.id, sti_mixer_to_str(to_sti_mixer(crtc)),
>   		      drm_plane->base.id, sti_plane_to_str(plane));
> @@ -1152,6 +1130,27 @@ static void sti_hqvdp_atomic_update(struct drm_plane *drm_plane,
>   	}
>   
>   	mode = &crtc->mode;
> +
> +	if (!hqvdp->xp70_initialized)
> +		/* Start HQVDP XP70 coprocessor */
> +		sti_hqvdp_start_xp70(hqvdp);
> +
> +	if (!hqvdp->vtg_registered) {
> +		/* Prevent VTG shutdown */
> +		if (clk_prepare_enable(hqvdp->clk_pix_main)) {
> +			DRM_ERROR("Failed to prepare/enable pix main clk\n");
> +			return;
> +		}
> +
> +		/* Register VTG Vsync callback to handle bottom fields */
> +		if (sti_vtg_register_client(hqvdp->vtg, &hqvdp->vtg_nb, crtc)) {
> +			DRM_ERROR("Cannot register VTG notifier\n");
> +			clk_disable_unprepare(hqvdp->clk_pix_main);
> +			return;
> +		}
> +		hqvdp->vtg_registered = true;
> +	}
> +

This looks like it belongs int device init instead of plane updates.

Best regards
Thomas

>   	dst_x = newstate->crtc_x;
>   	dst_y = newstate->crtc_y;
>   	dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstr. 146, 90461 Nürnberg, Germany, www.suse.com
GF: Stefan Gaiser, Jochen Jaser, Abhinav Puri, (HRB 36809, AG Nürnberg)



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

end of thread, other threads:[~2026-11-26  8:11 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-25 14:23 [PATCH 0/3] drm/sti: move commit work out of .atomic_check() Minseo Park
2026-11-25 14:23 ` [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check() Minseo Park
2026-11-25 14:39   ` Thomas Zimmermann
2026-11-25 14:23 ` [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update() Minseo Park
2026-11-25 14:41   ` Thomas Zimmermann
2026-11-25 14:23 ` [PATCH 3/3] drm/sti: hqvdp: start the XP70 " Minseo Park
2026-11-25 14:44   ` Thomas Zimmermann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.