Skip to contentSkip to conversation

drm/ast: cursor: Improve format handling

PATCH New Thomas Zimmermann 1 participant 5 messages Feb 17, 2025

Subsystems (3)
lore
Share & tools
lore

Thomas Zimmermann

author maintainer
#0 lore raw

v2 cover drm/ast: cursor: Improve format handling

A number of generally useful updates to the cursor code.

The cursor code performs format conversion to the hardware's ARGB444 format and calculation of a checksum in a single function. Patch 1 splits this into two steps. Patch 2 then implements the format conversion with DRM's format helpers. Other drivers can now reuse the code.

With the format handling separated, patch 3 adds support for ARGB4444, which is the hardware's native format.

Patch 4 moves cursor handling into a separate source file.

Tested on AST2600.

v2:
- only minor style changes

Thomas Zimmermann (4):
drm/ast: cursor: Calculate checksum in helper drm/ast: cursor: Move format conversion to shared helper drm/ast: cursor: Add support for ARGB4444
drm/ast: cursor: Move implementation to separate source file

 drivers/gpu/drm/ast/Makefile        |   1 +
 drivers/gpu/drm/ast/ast_cursor.c    | 309 ++++++++++++++++++++++++++++
 drivers/gpu/drm/ast/ast_drv.h       |  41 ++--
 drivers/gpu/drm/ast/ast_mode.c      | 273 +-----------------------
 drivers/gpu/drm/drm_format_helper.c |  69 +++++++
 include/drm/drm_format_helper.h     |   3 +
 6 files changed, 418 insertions(+), 278 deletions(-)
 create mode 100644 drivers/gpu/drm/ast/ast_cursor.c
Signature · 1 line
2.48.1
author maintainer
#1 lore raw

PATCH v2 1/4 drm/ast: cursor: Calculate checksum in helper

Setting the cursor image requires a 32-bit checksum of the cursor image data. The current cursor code converts the image to ARGB4444 format and computes the checksum in a single step. Moving the checksum calculation into a separate helper will allow to move the format conversion into a shared helper.

v2:
- don't loop for checksum'ing final pixel (Jocelyn)
- fix typo in commit message (Jocelyn)

---
 drivers/gpu/drm/ast/ast_drv.h  | 13 +++++++-
 drivers/gpu/drm/ast/ast_mode.c | 61 +++++++++++++++++++++++++---------
 2 files changed, 58 insertions(+), 16 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +12 -1
index 022a8c070c1b..d3115b31b032 100644
@@ -142,6 +142,17 @@ static inline struct ast_plane *to_ast_plane(struct drm_plane *plane)
 	return container_of(plane, struct ast_plane, base);
 }
 
+struct ast_cursor_plane {
+	struct ast_plane base;
+
+	u8 argb4444[AST_HWC_SIZE];
+};
+
+static inline struct ast_cursor_plane *to_ast_cursor_plane(struct drm_plane *plane)
+{
+	return container_of(to_ast_plane(plane), struct ast_cursor_plane, base);
+}
+
 /*
  * Connector
  */
@@ -186,7 +197,7 @@ struct ast_device {
 	enum ast_tx_chip tx_chip;
 
 	struct ast_plane primary_plane;
-	struct ast_plane cursor_plane;
+	struct ast_cursor_plane cursor_plane;
 	struct drm_crtc crtc;
 	union {
 		struct {
drivers/gpu/drm/ast/ast_mode.c +46 -15

131 lines not on this page · raw message

Signature · 1 line
2.48.1
author maintainer
#2 lore raw

PATCH v2 2/4 drm/ast: cursor: Move format conversion to shared helper

In reply to Thomas Zimmermann

User-space cursor-image data is encoded in ARBG8888, while hardware supports ARGB4444. Implement the format conversion as part of the format-helper framework, so that other drivers can benefit.

This allows to respect the damage area of the cursor update. In previous code, all cursor image data had to be converted on each update. Now, only the changed areas require an update. The hardware image is always updated completely, as it is required for the checksum update.

The format-conversion helper still contains the old implementation's optimization of writing 2 output pixels at the same time.

---
 drivers/gpu/drm/ast/ast_drv.h       |  4 +-
 drivers/gpu/drm/ast/ast_mode.c      | 71 +++++++----------------------
 drivers/gpu/drm/drm_format_helper.c | 69 ++++++++++++++++++++++++++++
 include/drm/drm_format_helper.h     |  3 ++
 4 files changed, 92 insertions(+), 55 deletions(-)
drivers/gpu/drm/ast/ast_drv.h +3 -1
index d3115b31b032..973abd0cbd42 100644
@@ -113,7 +113,9 @@ enum ast_config_mode {
 #define AST_MAX_HWC_WIDTH	64
 #define AST_MAX_HWC_HEIGHT	64
 
-#define AST_HWC_SIZE		(AST_MAX_HWC_WIDTH * AST_MAX_HWC_HEIGHT * 2)
+#define AST_HWC_PITCH		(AST_MAX_HWC_WIDTH * SZ_2)
+#define AST_HWC_SIZE		(AST_MAX_HWC_HEIGHT * AST_HWC_PITCH)
+
 #define AST_HWC_SIGNATURE_SIZE	32
 
 /* define for signature structure */
drivers/gpu/drm/ast/ast_mode.c +17 -54

95 lines not on this page · raw message

drivers/gpu/drm/drm_format_helper.c +69 -0

75 lines not on this page · raw message

include/drm/drm_format_helper.h +3 -0
index 428d81afe215..a1347e47e9d5 100644
@@ -110,6 +110,9 @@ void drm_fb_xrgb8888_to_argb2101010(struct iosys_map *dst, const unsigned int *d
 void drm_fb_xrgb8888_to_gray8(struct iosys_map *dst, const unsigned int *dst_pitch,
 			      const struct iosys_map *src, const struct drm_framebuffer *fb,
 			      const struct drm_rect *clip, struct drm_format_conv_state *state);
+void drm_fb_argb8888_to_argb4444(struct iosys_map *dst, const unsigned int *dst_pitch,
+				 const struct iosys_map *src, const struct drm_framebuffer *fb,
+				 const struct drm_rect *clip, struct drm_format_conv_state *state);
 
 int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t dst_format,
 		const struct iosys_map *src, const struct drm_framebuffer *fb,
Signature · 1 line
2.48.1
author maintainer
#3 lore raw

PATCH v2 3/4 drm/ast: cursor: Add support for ARGB4444

In reply to Thomas Zimmermann

Add support for cursor image data in ARGB4444 format. This is the hardware's native format and requires no conversion.

---
 drivers/gpu/drm/ast/ast_mode.c | 34 +++++++++++++++++++++++-----------
 1 file changed, 23 insertions(+), 11 deletions(-)
drivers/gpu/drm/ast/ast_mode.c +23 -11
index 8ab006e6bc32..91da54a4d8a6 100644
@@ -720,6 +720,7 @@ static void ast_set_cursor_enabled(struct ast_device *ast, bool enabled)
 }
 
 static const uint32_t ast_cursor_plane_formats[] = {
+	DRM_FORMAT_ARGB4444,
 	DRM_FORMAT_ARGB8888,
 };
 
@@ -771,17 +772,28 @@ static void ast_cursor_plane_helper_atomic_update(struct drm_plane *plane,
 	 */
 
 	if (drm_atomic_helper_damage_merged(old_plane_state, plane_state, &damage)) {
-		u8 *argb4444 = ast_cursor_plane->argb4444;
-		struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES] = {
-			IOSYS_MAP_INIT_VADDR(argb4444),
-		};
-		unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES] = {
-			AST_HWC_PITCH,
-		};
-
-		drm_fb_argb8888_to_argb4444(argb4444_dst, argb4444_dst_pitch,
-					    shadow_plane_state->data, fb, &damage,
-					    &shadow_plane_state->fmtcnv_state);
+		u8 *argb4444;
+
+		switch (fb->format->format) {
+		case DRM_FORMAT_ARGB4444:
+			argb4444 = shadow_plane_state->data[0].vaddr;
+			break;
+		default:
+			argb4444 = ast_cursor_plane->argb4444;
+			{
+				struct iosys_map argb4444_dst[DRM_FORMAT_MAX_PLANES] = {
+					IOSYS_MAP_INIT_VADDR(argb4444),
+				};
+				unsigned int argb4444_dst_pitch[DRM_FORMAT_MAX_PLANES] = {
+					AST_HWC_PITCH,
+				};
+
+				drm_fb_argb8888_to_argb4444(argb4444_dst, argb4444_dst_pitch,
+							    shadow_plane_state->data, fb, &damage,
+							    &shadow_plane_state->fmtcnv_state);
+			}
+			break;
+		}
 		ast_set_cursor_image(ast, argb4444, fb->width, fb->height);
 		ast_set_cursor_base(ast, dst_off);
 	}
Signature · 1 line
2.48.1
author maintainer
#4 lore raw

PATCH v2 4/4 drm/ast: cursor: Move implementation to separate source file

In reply to Thomas Zimmermann

Move the cursor code into a separate source file for readability. No functional changes.

v2:
- include <linux/bits.h>

---
 drivers/gpu/drm/ast/Makefile     |   1 +
 drivers/gpu/drm/ast/ast_cursor.c | 309 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/ast/ast_drv.h    |  24 +--
 drivers/gpu/drm/ast/ast_mode.c   | 277 +--------------------------
 4 files changed, 330 insertions(+), 281 deletions(-)
 create mode 100644 drivers/gpu/drm/ast/ast_cursor.c
drivers/gpu/drm/ast/Makefile +1 -0
index 3107ea9c7bf5..8d09ba5d5889 100644
@@ -4,6 +4,7 @@
 # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
 
 ast-y := \
+	ast_cursor.o \
 	ast_ddc.o \
 	ast_dp501.o \
 	ast_dp.o \
drivers/gpu/drm/ast/ast_cursor.c new file +309 -0

309 lines not on this page · raw message

drivers/gpu/drm/ast/ast_drv.h +13 -11
index 973abd0cbd42..d2c2605d2728 100644
@@ -118,15 +118,6 @@ enum ast_config_mode {
 
 #define AST_HWC_SIGNATURE_SIZE	32
 
-/* define for signature structure */
-#define AST_HWC_SIGNATURE_CHECKSUM	0x00
-#define AST_HWC_SIGNATURE_SizeX		0x04
-#define AST_HWC_SIGNATURE_SizeY		0x08
-#define AST_HWC_SIGNATURE_X		0x0C
-#define AST_HWC_SIGNATURE_Y		0x10
-#define AST_HWC_SIGNATURE_HOTSPOTX	0x14
-#define AST_HWC_SIGNATURE_HOTSPOTY	0x18
-
 /*
  * Planes
  */
@@ -383,8 +374,6 @@ struct ast_crtc_state {
 
 #define to_ast_crtc_state(state) container_of(state, struct ast_crtc_state, base)
 
-int ast_mode_config_init(struct ast_device *ast);
-
 #define AST_MM_ALIGN_SHIFT 4
 #define AST_MM_ALIGN_MASK ((1 << AST_MM_ALIGN_SHIFT) - 1)
 
@@ -450,6 +439,9 @@ void ast_patch_ahb_2500(void __iomem *regs);
 int ast_vga_output_init(struct ast_device *ast);
 int ast_sil164_output_init(struct ast_device *ast);
 
+/* ast_cursor.c */
+int ast_cursor_plane_init(struct ast_device *ast);
+
 /* ast dp501 */
 bool ast_backup_fw(struct ast_device *ast, u8 *addr, u32 size);
 void ast_init_3rdtx(struct ast_device *ast);
@@ -459,4 +451,14 @@ int ast_dp501_output_init(struct ast_device *ast);
 int ast_dp_launch(struct ast_device *ast);
 int ast_astdp_output_init(struct ast_device *ast);
 
+/* ast_mode.c */
+int ast_mode_config_init(struct ast_device *ast);
+int ast_plane_init(struct drm_device *dev, struct ast_plane *ast_plane,
+		   void __iomem *vaddr, u64 offset, unsigned long size,
+		   uint32_t possible_crtcs,
+		   const struct drm_plane_funcs *funcs,
+		   const uint32_t *formats, unsigned int format_count,
+		   const uint64_t *format_modifiers,
+		   enum drm_plane_type type);
+
 #endif
drivers/gpu/drm/ast/ast_mode.c +7 -270

289 lines not on this page · raw message

Signature · 1 line
2.48.1