All of lore.kernel.org
 help / color / mirror / Atom feed
From: Minseo Park <hiyoukou@gmail.com>
To: dri-devel@lists.freedesktop.org
Cc: tzimmermann@suse.de, alain.volmat@foss.st.com,
	rgallaispou@gmail.com, maarten.lankhorst@linux.intel.com,
	mripard@kernel.org, airlied@gmail.com, simona@ffwll.ch,
	benjamin.gaignard@collabora.com, Minseo Park <hiyoukou@gmail.com>
Subject: [PATCH v2 1/4] drm/sti: cursor: do not resize the pixmap from .atomic_check()
Date: Thu, 26 Nov 2026 11:47:07 +0900	[thread overview]
Message-ID: <20261126024710.33401-2-hiyoukou@gmail.com> (raw)
In-Reply-To: <20261126024710.33401-1-hiyoukou@gmail.com>

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..7295b6edb8ef 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_err(drm_dev, "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


  reply	other threads:[~2026-11-26  8:09 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-26  2:47 [PATCH v2 0/4] drm/sti: move commit work out of .atomic_check() Minseo Park
2026-11-26  2:47 ` Minseo Park [this message]
2026-11-26  8:32   ` [PATCH v2 1/4] drm/sti: cursor: do not resize the pixmap from .atomic_check() sashiko-bot
2026-11-26  2:47 ` [PATCH v2 2/4] drm/sti: gdp: set the pixel clock from .atomic_update() Minseo Park
2026-11-26  8:35   ` sashiko-bot
2026-11-26  2:47 ` [PATCH v2 3/4] drm/sti: hqvdp: start the XP70 from device init Minseo Park
2026-11-26  8:34   ` sashiko-bot
2026-11-26  2:47 ` [PATCH v2 4/4] drm/sti: hqvdp: register the VTG client from .atomic_update() Minseo Park

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261126024710.33401-2-hiyoukou@gmail.com \
    --to=hiyoukou@gmail.com \
    --cc=airlied@gmail.com \
    --cc=alain.volmat@foss.st.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=maarten.lankhorst@linux.intel.com \
    --cc=mripard@kernel.org \
    --cc=rgallaispou@gmail.com \
    --cc=simona@ffwll.ch \
    --cc=tzimmermann@suse.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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.