Skip to contentSkip to conversation

drm/sti: move commit work out of .atomic_check()

PATCH In review Minseo Park 2 participants 7 messages Nov 25 – Nov 26

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

cover drm/sti: move commit work out of .atomic_check()

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

Signature · 1 line
2.43.0
#1 lore raw

PATCH 1/3 drm/sti: cursor: do not resize the pixmap from .atomic_check()

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")
---
 drivers/gpu/drm/sti/sti_cursor.c | 65 ++++++++++++++------------------
 1 file changed, 28 insertions(+), 37 deletions(-)
drivers/gpu/drm/sti/sti_cursor.c +28 -37
index 66f56355309f..0f0d7405dfef 100644
@@ -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;
Signature · 1 line
2.43.0
#2 lore raw

Re: [PATCH 1/3] drm/sti: cursor: do not resize the pixmap from .atomic_check()

Hi

Am 25.11.26 um 15:23 schrieb Minseo Park:

Quoted 155 lines

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")
---
  drivers/gpu/drm/sti/sti_cursor.c | 65 ++++++++++++++------------------
  1 file changed, 28 insertions(+), 37 deletions(-)
drivers/gpu/drm/sti/sti_cursor.c +15 -36
index 66f56355309f..0f0d7405dfef 100644
@@ -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

drivers/gpu/drm/sti/sti_cursor.c struct drm_plane *sti_cursor_create(struct drm_device *drm_dev, · line 368

Quoted 10 lines
drivers/gpu/drm/sti/sti_cursor.c +10 -0
+	 * 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

Quoted 14 lines
drivers/gpu/drm/sti/sti_cursor.c +3 -1
+		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;
Signature · 6 lines
--
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)
#3 lore raw

PATCH 2/3 drm/sti: gdp: set the pixel clock from .atomic_update()

In reply to 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")
---
 drivers/gpu/drm/sti/sti_gdp.c | 52 +++++++++++++++++------------------
 1 file changed, 25 insertions(+), 27 deletions(-)
drivers/gpu/drm/sti/sti_gdp.c +25 -27
index d0c886029c57..09f8d3f936ca 100644
@@ -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);
Signature · 1 line
2.43.0
#4 lore raw

Re: [PATCH 2/3] drm/sti: gdp: set the pixel clock from .atomic_update()

Hi

Am 25.11.26 um 15:23 schrieb Minseo Park:

Quoted 51 lines

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")
---
  drivers/gpu/drm/sti/sti_gdp.c | 52 +++++++++++++++++------------------
  1 file changed, 25 insertions(+), 27 deletions(-)
drivers/gpu/drm/sti/sti_gdp.c +0 -17
index d0c886029c57..09f8d3f936ca 100644
@@ -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)

drivers/gpu/drm/sti/sti_gdp.c static int sti_gdp_atomic_check(struct drm_plane *drm_plane, · line 695

Quoted 10 lines
drivers/gpu/drm/sti/sti_gdp.c +0 -10
-			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?

Quoted 18 lines
drivers/gpu/drm/sti/sti_gdp.c +11 -0
  	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.
+		 */

drivers/gpu/drm/sti/sti_gdp.c static void sti_gdp_atomic_update(struct drm_plane *drm_plane, · line 753

Quoted 10 lines
drivers/gpu/drm/sti/sti_gdp.c +10 -0
+		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

Quoted 7 lines
drivers/gpu/drm/sti/sti_gdp.c +4 -0
+			return;
+		}
+	}
+
  	dst_x = newstate->crtc_x;
  	dst_y = newstate->crtc_y;
  	dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);
Signature · 6 lines
--
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)
#5 lore raw

PATCH 3/3 drm/sti: hqvdp: start the XP70 from .atomic_update()

In reply to 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")
---
 drivers/gpu/drm/sti/sti_hqvdp.c | 43 ++++++++++++++++-----------------
 1 file changed, 21 insertions(+), 22 deletions(-)
drivers/gpu/drm/sti/sti_hqvdp.c +21 -22
index 360d213f2094..66abbe4de864 100644
@@ -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);
Signature · 1 line
2.43.0
#6 lore raw

Re: [PATCH 3/3] drm/sti: hqvdp: start the XP70 from .atomic_update()

Hi

Am 25.11.26 um 15:23 schrieb Minseo Park:

Quoted 68 lines

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")
---
  drivers/gpu/drm/sti/sti_hqvdp.c | 43 ++++++++++++++++-----------------
  1 file changed, 21 insertions(+), 22 deletions(-)
drivers/gpu/drm/sti/sti_hqvdp.c +11 -22
index 360d213f2094..66abbe4de864 100644
@@ -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;
+		}

drivers/gpu/drm/sti/sti_hqvdp.c static void sti_hqvdp_atomic_update(struct drm_plane *drm_plane, · line 1153

Quoted 10 lines
drivers/gpu/drm/sti/sti_hqvdp.c +10 -0
+
+		/* 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

Quoted 3 lines
drivers/gpu/drm/sti/sti_hqvdp.c +0 -0
  	dst_x = newstate->crtc_x;
  	dst_y = newstate->crtc_y;
  	dst_w = clamp_val(newstate->crtc_w, 0, mode->hdisplay - dst_x);
Signature · 6 lines
--
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)