dri-devel.lists.freedesktop.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] drm/tests: Update format-helper tests for sysfb
@ 2025-06-12 13:52 Thomas Zimmermann
  2025-06-12 13:52 ` [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests Thomas Zimmermann
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Thomas Zimmermann @ 2025-06-12 13:52 UTC (permalink / raw)
  To: arthurgrillo, jose.exposito89, javierm, maarten.lankhorst,
	mripard
  Cc: dri-devel, Thomas Zimmermann

The helpers drm_fb_blit() and drm_fb_build_fourcc_list() will be
integrated into sysfb helpers. Update the DRM format-helper tests
accordingly in patches 1 and 2.

The change to drm_fb_build_fourcc_list() is simple enough that we
can apply it here in patch 3.

v2:
- fix test filename (Maxime)
- fix dependencies (kernel test robot)

Thomas Zimmermann (3):
  drm/tests: Do not use drm_fb_blit() in format-helper tests
  drm/tests: Test drm_fb_build_fourcc_list() in separate test suite
  drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers

 drivers/gpu/drm/Kconfig.debug                 |   1 +
 drivers/gpu/drm/drm_format_helper.c           | 246 +++++++----------
 drivers/gpu/drm/drm_format_internal.h         |   8 +
 drivers/gpu/drm/sysfb/drm_sysfb_helper.h      |   4 +
 drivers/gpu/drm/sysfb/drm_sysfb_modeset.c     | 138 ++++++++++
 drivers/gpu/drm/sysfb/efidrm.c                |   4 +-
 drivers/gpu/drm/sysfb/ofdrm.c                 |   5 +-
 drivers/gpu/drm/sysfb/simpledrm.c             |   5 +-
 drivers/gpu/drm/sysfb/vesadrm.c               |   4 +-
 drivers/gpu/drm/tests/Makefile                |   3 +-
 .../gpu/drm/tests/drm_format_helper_test.c    | 250 ++----------------
 .../gpu/drm/tests/drm_sysfb_modeset_test.c    | 167 ++++++++++++
 include/drm/drm_format_helper.h               |  13 +-
 13 files changed, 451 insertions(+), 397 deletions(-)
 create mode 100644 drivers/gpu/drm/tests/drm_sysfb_modeset_test.c

-- 
2.49.0


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

* [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests
  2025-06-12 13:52 [PATCH v2 0/3] drm/tests: Update format-helper tests for sysfb Thomas Zimmermann
@ 2025-06-12 13:52 ` Thomas Zimmermann
  2025-06-13 14:00   ` José Expósito
  2025-06-12 13:52 ` [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite Thomas Zimmermann
  2025-06-12 13:52 ` [PATCH v2 3/3] drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers Thomas Zimmermann
  2 siblings, 1 reply; 8+ messages in thread
From: Thomas Zimmermann @ 2025-06-12 13:52 UTC (permalink / raw)
  To: arthurgrillo, jose.exposito89, javierm, maarten.lankhorst,
	mripard
  Cc: dri-devel, Thomas Zimmermann

Export additional helpers from the format-helper library and open-code
drm_fb_blit() in tests. Prepares for the removal of drm_fb_blit(). Only
sysfb drivers use drm_fb_blit(). The function will soon be removed from
format helpers and be refactored within sysfb helpers.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/drm_format_helper.c           | 108 ++++++++++++++++--
 drivers/gpu/drm/drm_format_internal.h         |   8 ++
 .../gpu/drm/tests/drm_format_helper_test.c    | 108 +++---------------
 include/drm/drm_format_helper.h               |   9 ++
 4 files changed, 131 insertions(+), 102 deletions(-)

diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
index d36e6cacc575..73b5a80771cc 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -857,11 +857,33 @@ static void drm_fb_xrgb8888_to_abgr8888_line(void *dbuf, const void *sbuf, unsig
 	drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_abgr8888);
 }
 
-static void drm_fb_xrgb8888_to_abgr8888(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)
+/**
+ * drm_fb_xrgb8888_to_abgr8888 - Convert XRGB8888 to ABGR8888 clip buffer
+ * @dst: Array of ABGR8888 destination buffers
+ * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
+ *             within @dst; can be NULL if scanlines are stored next to each other.
+ * @src: Array of XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @state: Transform and conversion state
+ *
+ * This function copies parts of a framebuffer to display memory and converts the
+ * color format during the process. The parameters @dst, @dst_pitch and @src refer
+ * to arrays. Each array must have at least as many entries as there are planes in
+ * @fb's format. Each entry stores the value for the format's respective color plane
+ * at the same index.
+ *
+ * This function does not apply clipping on @dst (i.e. the destination is at the
+ * top-left corner).
+ *
+ * Drivers can use this function for ABGR8888 devices that don't support XRGB8888
+ * natively. It sets an opaque alpha channel as part of the conversion.
+ */
+void drm_fb_xrgb8888_to_abgr8888(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)
 {
 	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
 		4,
@@ -870,17 +892,40 @@ static void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned in
 	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
 		    drm_fb_xrgb8888_to_abgr8888_line);
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_abgr8888);
 
 static void drm_fb_xrgb8888_to_xbgr8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
 	drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_xbgr8888);
 }
 
-static void drm_fb_xrgb8888_to_xbgr8888(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)
+/**
+ * drm_fb_xrgb8888_to_xbgr8888 - Convert XRGB8888 to XBGR8888 clip buffer
+ * @dst: Array of XBGR8888 destination buffers
+ * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
+ *             within @dst; can be NULL if scanlines are stored next to each other.
+ * @src: Array of XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @state: Transform and conversion state
+ *
+ * This function copies parts of a framebuffer to display memory and converts the
+ * color format during the process. The parameters @dst, @dst_pitch and @src refer
+ * to arrays. Each array must have at least as many entries as there are planes in
+ * @fb's format. Each entry stores the value for the format's respective color plane
+ * at the same index.
+ *
+ * This function does not apply clipping on @dst (i.e. the destination is at the
+ * top-left corner).
+ *
+ * Drivers can use this function for XBGR8888 devices that don't support XRGB8888
+ * natively.
+ */
+void drm_fb_xrgb8888_to_xbgr8888(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)
 {
 	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
 		4,
@@ -889,6 +934,49 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
 	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
 		    drm_fb_xrgb8888_to_xbgr8888_line);
 }
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_xbgr8888);
+
+static void drm_fb_xrgb8888_to_bgrx8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
+{
+	drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_bgrx8888);
+}
+
+/**
+ * drm_fb_xrgb8888_to_bgrx8888 - Convert XRGB8888 to BGRX8888 clip buffer
+ * @dst: Array of BGRX8888 destination buffers
+ * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
+ *             within @dst; can be NULL if scanlines are stored next to each other.
+ * @src: Array of XRGB8888 source buffer
+ * @fb: DRM framebuffer
+ * @clip: Clip rectangle area to copy
+ * @state: Transform and conversion state
+ *
+ * This function copies parts of a framebuffer to display memory and converts the
+ * color format during the process. The parameters @dst, @dst_pitch and @src refer
+ * to arrays. Each array must have at least as many entries as there are planes in
+ * @fb's format. Each entry stores the value for the format's respective color plane
+ * at the same index.
+ *
+ * This function does not apply clipping on @dst (i.e. the destination is at the
+ * top-left corner).
+ *
+ * Drivers can use this function for BGRX8888 devices that don't support XRGB8888
+ * natively.
+ */
+void drm_fb_xrgb8888_to_bgrx8888(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)
+{
+	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
+		4,
+	};
+
+	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
+		    drm_fb_xrgb8888_to_bgrx8888_line);
+}
+EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgrx8888);
 
 static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
diff --git a/drivers/gpu/drm/drm_format_internal.h b/drivers/gpu/drm/drm_format_internal.h
index 9f857bfa368d..0aa458b8a3e0 100644
--- a/drivers/gpu/drm/drm_format_internal.h
+++ b/drivers/gpu/drm/drm_format_internal.h
@@ -111,6 +111,14 @@ static inline u32 drm_pixel_xrgb8888_to_xbgr8888(u32 pix)
 	       ((pix & 0x000000ff) << 16);
 }
 
+static inline u32 drm_pixel_xrgb8888_to_bgrx8888(u32 pix)
+{
+	return ((pix & 0xff000000) >> 24) | /* also copy filler bits */
+	       ((pix & 0x00ff0000) >> 8) |
+	       ((pix & 0x0000ff00) << 8) |
+	       ((pix & 0x000000ff) << 24);
+}
+
 static inline u32 drm_pixel_xrgb8888_to_abgr8888(u32 pix)
 {
 	return GENMASK(31, 24) | /* fill alpha bits */
diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 35cd3405d045..8aacc1ffa93a 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -748,14 +748,9 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
 	buf = dst.vaddr;
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGB565, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_rgb565(&dst, dst_pitch, &src, &fb, &params->clip,
+				  &fmtcnv_state, false);
 	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -795,14 +790,8 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB1555, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_xrgb1555(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -842,14 +831,8 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB1555, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_argb1555(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -889,14 +872,8 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGBA5551, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_rgba5551(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -939,12 +916,7 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGB888, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
+	drm_fb_xrgb8888_to_rgb888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -985,12 +957,8 @@ static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, &result->dst_pitch, DRM_FORMAT_BGR888, &src, &fb, &params->clip,
+	drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, &params->clip,
 				  &fmtcnv_state);
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1030,14 +998,8 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB8888, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_argb8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1077,12 +1039,7 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB2101010, &src, &fb,
-				  &params->clip, &fmtcnv_state);
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
+	drm_fb_xrgb8888_to_xrgb2101010(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1122,14 +1079,8 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB2101010, &src, &fb,
-				  &params->clip, &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_argb2101010(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1202,23 +1153,15 @@ static void drm_test_fb_swab(struct kunit *test)
 	buf = dst.vaddr; /* restore original value of buf */
 	memset(buf, 0, dst_size);
 
-	int blit_result;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB8888 | DRM_FORMAT_BIG_ENDIAN,
-				  &src, &fb, &params->clip, &fmtcnv_state);
+	drm_fb_swab(&dst, dst_pitch, &src, &fb, &params->clip, false, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 
 	buf = dst.vaddr;
 	memset(buf, 0, dst_size);
 
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_BGRX8888, &src, &fb, &params->clip,
-				  &fmtcnv_state);
+	drm_fb_xrgb8888_to_bgrx8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 
 	buf = dst.vaddr;
@@ -1229,11 +1172,8 @@ static void drm_test_fb_swab(struct kunit *test)
 	mock_format.format |= DRM_FORMAT_BIG_ENDIAN;
 	fb.format = &mock_format;
 
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB8888, &src, &fb, &params->clip,
-				  &fmtcnv_state);
+	drm_fb_swab(&dst, dst_pitch, &src, &fb, &params->clip, false, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1266,14 +1206,8 @@ static void drm_test_fb_xrgb8888_to_abgr8888(struct kunit *test)
 	const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
 		NULL : &result->dst_pitch;
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ABGR8888, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_abgr8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1306,14 +1240,8 @@ static void drm_test_fb_xrgb8888_to_xbgr8888(struct kunit *test)
 	const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
 		NULL : &result->dst_pitch;
 
-	int blit_result = 0;
-
-	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XBGR8888, &src, &fb, &params->clip,
-				  &fmtcnv_state);
-
+	drm_fb_xrgb8888_to_xbgr8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
 	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
-
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
 }
 
@@ -1910,12 +1838,8 @@ static void drm_test_fb_memcpy(struct kunit *test)
 		memset(buf[i], 0, dst_size[i]);
 	}
 
-	int blit_result;
-
-	blit_result = drm_fb_blit(dst, dst_pitches, params->format, src, &fb, &params->clip,
-				  &fmtcnv_state);
+	drm_fb_memcpy(dst, dst_pitches, src, &fb, &params->clip);
 
-	KUNIT_EXPECT_FALSE(test, blit_result);
 	for (size_t i = 0; i < fb.format->num_planes; i++) {
 		expected[i] = cpubuf_to_le32(test, params->expected[i], TEST_BUF_SIZE);
 		KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i],
diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
index d8539174ca11..49a2e09155d1 100644
--- a/include/drm/drm_format_helper.h
+++ b/include/drm/drm_format_helper.h
@@ -102,6 +102,15 @@ void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pi
 void drm_fb_xrgb8888_to_argb8888(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_xrgb8888_to_abgr8888(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_xrgb8888_to_xbgr8888(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_xrgb8888_to_bgrx8888(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_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
 				    const struct iosys_map *src, const struct drm_framebuffer *fb,
 				    const struct drm_rect *clip,
-- 
2.49.0


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

* [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite
  2025-06-12 13:52 [PATCH v2 0/3] drm/tests: Update format-helper tests for sysfb Thomas Zimmermann
  2025-06-12 13:52 ` [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests Thomas Zimmermann
@ 2025-06-12 13:52 ` Thomas Zimmermann
  2025-06-13 14:03   ` José Expósito
  2025-06-12 13:52 ` [PATCH v2 3/3] drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers Thomas Zimmermann
  2 siblings, 1 reply; 8+ messages in thread
From: Thomas Zimmermann @ 2025-06-12 13:52 UTC (permalink / raw)
  To: arthurgrillo, jose.exposito89, javierm, maarten.lankhorst,
	mripard
  Cc: dri-devel, Thomas Zimmermann

Only sysfb drivers use drm_fb_build_fourcc_list(). The helper will
be moved from format helpers to sysfb helpers. Moving the related
tests to their own test suite.

v2:
- rename filename to match tested code (Maxime)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Maxime Ripard <mripard@kernel.org>
---
 drivers/gpu/drm/tests/Makefile                |   3 +-
 .../gpu/drm/tests/drm_format_helper_test.c    | 142 ---------------
 .../gpu/drm/tests/drm_sysfb_modeset_test.c    | 166 ++++++++++++++++++
 3 files changed, 168 insertions(+), 143 deletions(-)
 create mode 100644 drivers/gpu/drm/tests/drm_sysfb_modeset_test.c

diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile
index 3afd6587df08..c0e952293ad0 100644
--- a/drivers/gpu/drm/tests/Makefile
+++ b/drivers/gpu/drm/tests/Makefile
@@ -23,6 +23,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \
 	drm_modes_test.o \
 	drm_plane_helper_test.o \
 	drm_probe_helper_test.o \
-	drm_rect_test.o
+	drm_rect_test.o \
+	drm_sysfb_modeset_test.o
 
 CFLAGS_drm_mm_test.o := $(DISABLE_STRUCTLEAK_PLUGIN)
diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
index 8aacc1ffa93a..ef1cc3b28f1b 100644
--- a/drivers/gpu/drm/tests/drm_format_helper_test.c
+++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
@@ -1335,147 +1335,6 @@ static void drm_test_fb_clip_offset(struct kunit *test)
 	KUNIT_EXPECT_EQ(test, offset, params->expected_offset);
 }
 
-struct fb_build_fourcc_list_case {
-	const char *name;
-	u32 native_fourccs[TEST_BUF_SIZE];
-	size_t native_fourccs_size;
-	u32 expected[TEST_BUF_SIZE];
-	size_t expected_fourccs_size;
-};
-
-static struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
-	{
-		.name = "no native formats",
-		.native_fourccs = { },
-		.native_fourccs_size = 0,
-		.expected = { DRM_FORMAT_XRGB8888 },
-		.expected_fourccs_size = 1,
-	},
-	{
-		.name = "XRGB8888 as native format",
-		.native_fourccs = { DRM_FORMAT_XRGB8888 },
-		.native_fourccs_size = 1,
-		.expected = { DRM_FORMAT_XRGB8888 },
-		.expected_fourccs_size = 1,
-	},
-	{
-		.name = "remove duplicates",
-		.native_fourccs = {
-			DRM_FORMAT_XRGB8888,
-			DRM_FORMAT_XRGB8888,
-			DRM_FORMAT_RGB888,
-			DRM_FORMAT_RGB888,
-			DRM_FORMAT_RGB888,
-			DRM_FORMAT_XRGB8888,
-			DRM_FORMAT_RGB888,
-			DRM_FORMAT_RGB565,
-			DRM_FORMAT_RGB888,
-			DRM_FORMAT_XRGB8888,
-			DRM_FORMAT_RGB565,
-			DRM_FORMAT_RGB565,
-			DRM_FORMAT_XRGB8888,
-		},
-		.native_fourccs_size = 11,
-		.expected = {
-			DRM_FORMAT_XRGB8888,
-			DRM_FORMAT_RGB888,
-			DRM_FORMAT_RGB565,
-		},
-		.expected_fourccs_size = 3,
-	},
-	{
-		.name = "convert alpha formats",
-		.native_fourccs = {
-			DRM_FORMAT_ARGB1555,
-			DRM_FORMAT_ABGR1555,
-			DRM_FORMAT_RGBA5551,
-			DRM_FORMAT_BGRA5551,
-			DRM_FORMAT_ARGB8888,
-			DRM_FORMAT_ABGR8888,
-			DRM_FORMAT_RGBA8888,
-			DRM_FORMAT_BGRA8888,
-			DRM_FORMAT_ARGB2101010,
-			DRM_FORMAT_ABGR2101010,
-			DRM_FORMAT_RGBA1010102,
-			DRM_FORMAT_BGRA1010102,
-		},
-		.native_fourccs_size = 12,
-		.expected = {
-			DRM_FORMAT_XRGB1555,
-			DRM_FORMAT_XBGR1555,
-			DRM_FORMAT_RGBX5551,
-			DRM_FORMAT_BGRX5551,
-			DRM_FORMAT_XRGB8888,
-			DRM_FORMAT_XBGR8888,
-			DRM_FORMAT_RGBX8888,
-			DRM_FORMAT_BGRX8888,
-			DRM_FORMAT_XRGB2101010,
-			DRM_FORMAT_XBGR2101010,
-			DRM_FORMAT_RGBX1010102,
-			DRM_FORMAT_BGRX1010102,
-		},
-		.expected_fourccs_size = 12,
-	},
-	{
-		.name = "random formats",
-		.native_fourccs = {
-			DRM_FORMAT_Y212,
-			DRM_FORMAT_ARGB1555,
-			DRM_FORMAT_ABGR16161616F,
-			DRM_FORMAT_C8,
-			DRM_FORMAT_BGR888,
-			DRM_FORMAT_XRGB1555,
-			DRM_FORMAT_RGBA5551,
-			DRM_FORMAT_BGR565_A8,
-			DRM_FORMAT_R10,
-			DRM_FORMAT_XYUV8888,
-		},
-		.native_fourccs_size = 10,
-		.expected = {
-			DRM_FORMAT_Y212,
-			DRM_FORMAT_XRGB1555,
-			DRM_FORMAT_ABGR16161616F,
-			DRM_FORMAT_C8,
-			DRM_FORMAT_BGR888,
-			DRM_FORMAT_RGBX5551,
-			DRM_FORMAT_BGR565_A8,
-			DRM_FORMAT_R10,
-			DRM_FORMAT_XYUV8888,
-			DRM_FORMAT_XRGB8888,
-		},
-		.expected_fourccs_size = 10,
-	},
-};
-
-static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
-{
-	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
-}
-
-KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
-
-static void drm_test_fb_build_fourcc_list(struct kunit *test)
-{
-	const struct fb_build_fourcc_list_case *params = test->param_value;
-	u32 fourccs_out[TEST_BUF_SIZE] = {0};
-	size_t nfourccs_out;
-	struct drm_device *drm;
-	struct device *dev;
-
-	dev = drm_kunit_helper_alloc_device(test);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
-
-	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
-	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
-
-	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
-						params->native_fourccs_size,
-						fourccs_out, TEST_BUF_SIZE);
-
-	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
-	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
-}
-
 struct fb_memcpy_case {
 	const char *name;
 	u32 format;
@@ -1864,7 +1723,6 @@ static struct kunit_case drm_format_helper_test_cases[] = {
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xbgr8888, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_abgr8888, convert_xrgb8888_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params),
-	KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
 	KUNIT_CASE_PARAM(drm_test_fb_memcpy, fb_memcpy_gen_params),
 	{}
 };
diff --git a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
new file mode 100644
index 000000000000..88a4bf28c745
--- /dev/null
+++ b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
@@ -0,0 +1,166 @@
+// SPDX-License-Identifier: GPL-2.0+
+
+#include <kunit/test.h>
+
+#include <drm/drm_format_helper.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_kunit_helpers.h>
+
+#define TEST_BUF_SIZE 50
+
+struct fb_build_fourcc_list_case {
+	const char *name;
+	u32 native_fourccs[TEST_BUF_SIZE];
+	size_t native_fourccs_size;
+	u32 expected[TEST_BUF_SIZE];
+	size_t expected_fourccs_size;
+};
+
+static struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
+	{
+		.name = "no native formats",
+		.native_fourccs = { },
+		.native_fourccs_size = 0,
+		.expected = { DRM_FORMAT_XRGB8888 },
+		.expected_fourccs_size = 1,
+	},
+	{
+		.name = "XRGB8888 as native format",
+		.native_fourccs = { DRM_FORMAT_XRGB8888 },
+		.native_fourccs_size = 1,
+		.expected = { DRM_FORMAT_XRGB8888 },
+		.expected_fourccs_size = 1,
+	},
+	{
+		.name = "remove duplicates",
+		.native_fourccs = {
+			DRM_FORMAT_XRGB8888,
+			DRM_FORMAT_XRGB8888,
+			DRM_FORMAT_RGB888,
+			DRM_FORMAT_RGB888,
+			DRM_FORMAT_RGB888,
+			DRM_FORMAT_XRGB8888,
+			DRM_FORMAT_RGB888,
+			DRM_FORMAT_RGB565,
+			DRM_FORMAT_RGB888,
+			DRM_FORMAT_XRGB8888,
+			DRM_FORMAT_RGB565,
+			DRM_FORMAT_RGB565,
+			DRM_FORMAT_XRGB8888,
+		},
+		.native_fourccs_size = 11,
+		.expected = {
+			DRM_FORMAT_XRGB8888,
+			DRM_FORMAT_RGB888,
+			DRM_FORMAT_RGB565,
+		},
+		.expected_fourccs_size = 3,
+	},
+	{
+		.name = "convert alpha formats",
+		.native_fourccs = {
+			DRM_FORMAT_ARGB1555,
+			DRM_FORMAT_ABGR1555,
+			DRM_FORMAT_RGBA5551,
+			DRM_FORMAT_BGRA5551,
+			DRM_FORMAT_ARGB8888,
+			DRM_FORMAT_ABGR8888,
+			DRM_FORMAT_RGBA8888,
+			DRM_FORMAT_BGRA8888,
+			DRM_FORMAT_ARGB2101010,
+			DRM_FORMAT_ABGR2101010,
+			DRM_FORMAT_RGBA1010102,
+			DRM_FORMAT_BGRA1010102,
+		},
+		.native_fourccs_size = 12,
+		.expected = {
+			DRM_FORMAT_XRGB1555,
+			DRM_FORMAT_XBGR1555,
+			DRM_FORMAT_RGBX5551,
+			DRM_FORMAT_BGRX5551,
+			DRM_FORMAT_XRGB8888,
+			DRM_FORMAT_XBGR8888,
+			DRM_FORMAT_RGBX8888,
+			DRM_FORMAT_BGRX8888,
+			DRM_FORMAT_XRGB2101010,
+			DRM_FORMAT_XBGR2101010,
+			DRM_FORMAT_RGBX1010102,
+			DRM_FORMAT_BGRX1010102,
+		},
+		.expected_fourccs_size = 12,
+	},
+	{
+		.name = "random formats",
+		.native_fourccs = {
+			DRM_FORMAT_Y212,
+			DRM_FORMAT_ARGB1555,
+			DRM_FORMAT_ABGR16161616F,
+			DRM_FORMAT_C8,
+			DRM_FORMAT_BGR888,
+			DRM_FORMAT_XRGB1555,
+			DRM_FORMAT_RGBA5551,
+			DRM_FORMAT_BGR565_A8,
+			DRM_FORMAT_R10,
+			DRM_FORMAT_XYUV8888,
+		},
+		.native_fourccs_size = 10,
+		.expected = {
+			DRM_FORMAT_Y212,
+			DRM_FORMAT_XRGB1555,
+			DRM_FORMAT_ABGR16161616F,
+			DRM_FORMAT_C8,
+			DRM_FORMAT_BGR888,
+			DRM_FORMAT_RGBX5551,
+			DRM_FORMAT_BGR565_A8,
+			DRM_FORMAT_R10,
+			DRM_FORMAT_XYUV8888,
+			DRM_FORMAT_XRGB8888,
+		},
+		.expected_fourccs_size = 10,
+	},
+};
+
+static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
+{
+	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
+}
+
+KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
+
+static void drm_test_fb_build_fourcc_list(struct kunit *test)
+{
+	const struct fb_build_fourcc_list_case *params = test->param_value;
+	u32 fourccs_out[TEST_BUF_SIZE] = {0};
+	size_t nfourccs_out;
+	struct drm_device *drm;
+	struct device *dev;
+
+	dev = drm_kunit_helper_alloc_device(test);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
+
+	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
+	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
+
+	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
+						params->native_fourccs_size,
+						fourccs_out, TEST_BUF_SIZE);
+
+	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
+	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
+}
+
+static struct kunit_case drm_sysfb_helper_test_cases[] = {
+	KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
+	{}
+};
+
+static struct kunit_suite drm_sysfb_helper_test_suite = {
+	.name = "drm_sysfb_helper_test",
+	.test_cases = drm_sysfb_helper_test_cases,
+};
+
+kunit_test_suite(drm_sysfb_helper_test_suite);
+
+MODULE_DESCRIPTION("KUnit tests for the drm_sysfb_helper APIs");
+MODULE_LICENSE("GPL");
+MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>");
-- 
2.49.0


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

* [PATCH v2 3/3] drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers
  2025-06-12 13:52 [PATCH v2 0/3] drm/tests: Update format-helper tests for sysfb Thomas Zimmermann
  2025-06-12 13:52 ` [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests Thomas Zimmermann
  2025-06-12 13:52 ` [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite Thomas Zimmermann
@ 2025-06-12 13:52 ` Thomas Zimmermann
  2025-06-13 14:53   ` José Expósito
  2 siblings, 1 reply; 8+ messages in thread
From: Thomas Zimmermann @ 2025-06-12 13:52 UTC (permalink / raw)
  To: arthurgrillo, jose.exposito89, javierm, maarten.lankhorst,
	mripard
  Cc: dri-devel, Thomas Zimmermann

Only sysfb drivers use drm_fb_build_fourcc_list(). Move the function
to sysfb helpers and rename it accordingly. Update drivers and tests.

v2:
- select DRM_SYSFB_HELPER (kernel test robot)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Acked-by: Maxime Ripard <mripard@kernel.org>
Acked-by: Javier Martinez Canillas <javierm@redhat.com>
---
 drivers/gpu/drm/Kconfig.debug                 |   1 +
 drivers/gpu/drm/drm_format_helper.c           | 138 ------------------
 drivers/gpu/drm/sysfb/drm_sysfb_helper.h      |   4 +
 drivers/gpu/drm/sysfb/drm_sysfb_modeset.c     | 138 ++++++++++++++++++
 drivers/gpu/drm/sysfb/efidrm.c                |   4 +-
 drivers/gpu/drm/sysfb/ofdrm.c                 |   5 +-
 drivers/gpu/drm/sysfb/simpledrm.c             |   5 +-
 drivers/gpu/drm/sysfb/vesadrm.c               |   4 +-
 .../gpu/drm/tests/drm_sysfb_modeset_test.c    |   9 +-
 include/drm/drm_format_helper.h               |   4 -
 10 files changed, 156 insertions(+), 156 deletions(-)

diff --git a/drivers/gpu/drm/Kconfig.debug b/drivers/gpu/drm/Kconfig.debug
index fa6ee76f4d3c..05dc43c0b8c5 100644
--- a/drivers/gpu/drm/Kconfig.debug
+++ b/drivers/gpu/drm/Kconfig.debug
@@ -70,6 +70,7 @@ config DRM_KUNIT_TEST
 	select DRM_GEM_SHMEM_HELPER
 	select DRM_KUNIT_TEST_HELPERS
 	select DRM_LIB_RANDOM
+	select DRM_SYSFB_HELPER
 	select PRIME_NUMBERS
 	default KUNIT_ALL_TESTS
 	help
diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
index 73b5a80771cc..da79100895ff 100644
--- a/drivers/gpu/drm/drm_format_helper.c
+++ b/drivers/gpu/drm/drm_format_helper.c
@@ -1338,141 +1338,3 @@ void drm_fb_xrgb8888_to_mono(struct iosys_map *dst, const unsigned int *dst_pitc
 	}
 }
 EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono);
-
-static uint32_t drm_fb_nonalpha_fourcc(uint32_t fourcc)
-{
-	/* only handle formats with depth != 0 and alpha channel */
-	switch (fourcc) {
-	case DRM_FORMAT_ARGB1555:
-		return DRM_FORMAT_XRGB1555;
-	case DRM_FORMAT_ABGR1555:
-		return DRM_FORMAT_XBGR1555;
-	case DRM_FORMAT_RGBA5551:
-		return DRM_FORMAT_RGBX5551;
-	case DRM_FORMAT_BGRA5551:
-		return DRM_FORMAT_BGRX5551;
-	case DRM_FORMAT_ARGB8888:
-		return DRM_FORMAT_XRGB8888;
-	case DRM_FORMAT_ABGR8888:
-		return DRM_FORMAT_XBGR8888;
-	case DRM_FORMAT_RGBA8888:
-		return DRM_FORMAT_RGBX8888;
-	case DRM_FORMAT_BGRA8888:
-		return DRM_FORMAT_BGRX8888;
-	case DRM_FORMAT_ARGB2101010:
-		return DRM_FORMAT_XRGB2101010;
-	case DRM_FORMAT_ABGR2101010:
-		return DRM_FORMAT_XBGR2101010;
-	case DRM_FORMAT_RGBA1010102:
-		return DRM_FORMAT_RGBX1010102;
-	case DRM_FORMAT_BGRA1010102:
-		return DRM_FORMAT_BGRX1010102;
-	}
-
-	return fourcc;
-}
-
-static bool is_listed_fourcc(const uint32_t *fourccs, size_t nfourccs, uint32_t fourcc)
-{
-	const uint32_t *fourccs_end = fourccs + nfourccs;
-
-	while (fourccs < fourccs_end) {
-		if (*fourccs == fourcc)
-			return true;
-		++fourccs;
-	}
-	return false;
-}
-
-/**
- * drm_fb_build_fourcc_list - Filters a list of supported color formats against
- *                            the device's native formats
- * @dev: DRM device
- * @native_fourccs: 4CC codes of natively supported color formats
- * @native_nfourccs: The number of entries in @native_fourccs
- * @fourccs_out: Returns 4CC codes of supported color formats
- * @nfourccs_out: The number of available entries in @fourccs_out
- *
- * This function create a list of supported color format from natively
- * supported formats and additional emulated formats.
- * At a minimum, most userspace programs expect at least support for
- * XRGB8888 on the primary plane. Devices that have to emulate the
- * format, and possibly others, can use drm_fb_build_fourcc_list() to
- * create a list of supported color formats. The returned list can
- * be handed over to drm_universal_plane_init() et al. Native formats
- * will go before emulated formats. Native formats with alpha channel
- * will be replaced by such without, as primary planes usually don't
- * support alpha. Other heuristics might be applied
- * to optimize the order. Formats near the beginning of the list are
- * usually preferred over formats near the end of the list.
- *
- * Returns:
- * The number of color-formats 4CC codes returned in @fourccs_out.
- */
-size_t drm_fb_build_fourcc_list(struct drm_device *dev,
-				const u32 *native_fourccs, size_t native_nfourccs,
-				u32 *fourccs_out, size_t nfourccs_out)
-{
-	/*
-	 * XRGB8888 is the default fallback format for most of userspace
-	 * and it's currently the only format that should be emulated for
-	 * the primary plane. Only if there's ever another default fallback,
-	 * it should be added here.
-	 */
-	static const uint32_t extra_fourccs[] = {
-		DRM_FORMAT_XRGB8888,
-	};
-	static const size_t extra_nfourccs = ARRAY_SIZE(extra_fourccs);
-
-	u32 *fourccs = fourccs_out;
-	const u32 *fourccs_end = fourccs_out + nfourccs_out;
-	size_t i;
-
-	/*
-	 * The device's native formats go first.
-	 */
-
-	for (i = 0; i < native_nfourccs; ++i) {
-		/*
-		 * Several DTs, boot loaders and firmware report native
-		 * alpha formats that are non-alpha formats instead. So
-		 * replace alpha formats by non-alpha formats.
-		 */
-		u32 fourcc = drm_fb_nonalpha_fourcc(native_fourccs[i]);
-
-		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
-			continue; /* skip duplicate entries */
-		} else if (fourccs == fourccs_end) {
-			drm_warn(dev, "Ignoring native format %p4cc\n", &fourcc);
-			continue; /* end of available output buffer */
-		}
-
-		drm_dbg_kms(dev, "adding native format %p4cc\n", &fourcc);
-
-		*fourccs = fourcc;
-		++fourccs;
-	}
-
-	/*
-	 * The extra formats, emulated by the driver, go second.
-	 */
-
-	for (i = 0; (i < extra_nfourccs) && (fourccs < fourccs_end); ++i) {
-		u32 fourcc = extra_fourccs[i];
-
-		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
-			continue; /* skip duplicate and native entries */
-		} else if (fourccs == fourccs_end) {
-			drm_warn(dev, "Ignoring emulated format %p4cc\n", &fourcc);
-			continue; /* end of available output buffer */
-		}
-
-		drm_dbg_kms(dev, "adding emulated format %p4cc\n", &fourcc);
-
-		*fourccs = fourcc;
-		++fourccs;
-	}
-
-	return fourccs - fourccs_out;
-}
-EXPORT_SYMBOL(drm_fb_build_fourcc_list);
diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h
index cb08a88242cc..1424b63dde99 100644
--- a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h
+++ b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h
@@ -93,6 +93,10 @@ static inline struct drm_sysfb_device *to_drm_sysfb_device(struct drm_device *de
  * Plane
  */
 
+size_t drm_sysfb_build_fourcc_list(struct drm_device *dev,
+				   const u32 *native_fourccs, size_t native_nfourccs,
+				   u32 *fourccs_out, size_t nfourccs_out);
+
 int drm_sysfb_plane_helper_atomic_check(struct drm_plane *plane,
 					struct drm_atomic_state *new_state);
 void drm_sysfb_plane_helper_atomic_update(struct drm_plane *plane,
diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c b/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c
index ffaa2522ab96..1bcdb5ee8f09 100644
--- a/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c
+++ b/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c
@@ -47,6 +47,144 @@ EXPORT_SYMBOL(drm_sysfb_mode);
  * Plane
  */
 
+static u32 to_nonalpha_fourcc(u32 fourcc)
+{
+	/* only handle formats with depth != 0 and alpha channel */
+	switch (fourcc) {
+	case DRM_FORMAT_ARGB1555:
+		return DRM_FORMAT_XRGB1555;
+	case DRM_FORMAT_ABGR1555:
+		return DRM_FORMAT_XBGR1555;
+	case DRM_FORMAT_RGBA5551:
+		return DRM_FORMAT_RGBX5551;
+	case DRM_FORMAT_BGRA5551:
+		return DRM_FORMAT_BGRX5551;
+	case DRM_FORMAT_ARGB8888:
+		return DRM_FORMAT_XRGB8888;
+	case DRM_FORMAT_ABGR8888:
+		return DRM_FORMAT_XBGR8888;
+	case DRM_FORMAT_RGBA8888:
+		return DRM_FORMAT_RGBX8888;
+	case DRM_FORMAT_BGRA8888:
+		return DRM_FORMAT_BGRX8888;
+	case DRM_FORMAT_ARGB2101010:
+		return DRM_FORMAT_XRGB2101010;
+	case DRM_FORMAT_ABGR2101010:
+		return DRM_FORMAT_XBGR2101010;
+	case DRM_FORMAT_RGBA1010102:
+		return DRM_FORMAT_RGBX1010102;
+	case DRM_FORMAT_BGRA1010102:
+		return DRM_FORMAT_BGRX1010102;
+	}
+
+	return fourcc;
+}
+
+static bool is_listed_fourcc(const u32 *fourccs, size_t nfourccs, u32 fourcc)
+{
+	const u32 *fourccs_end = fourccs + nfourccs;
+
+	while (fourccs < fourccs_end) {
+		if (*fourccs == fourcc)
+			return true;
+		++fourccs;
+	}
+	return false;
+}
+
+/**
+ * drm_sysfb_build_fourcc_list - Filters a list of supported color formats against
+ *                               the device's native formats
+ * @dev: DRM device
+ * @native_fourccs: 4CC codes of natively supported color formats
+ * @native_nfourccs: The number of entries in @native_fourccs
+ * @fourccs_out: Returns 4CC codes of supported color formats
+ * @nfourccs_out: The number of available entries in @fourccs_out
+ *
+ * This function create a list of supported color format from natively
+ * supported formats and additional emulated formats.
+ * At a minimum, most userspace programs expect at least support for
+ * XRGB8888 on the primary plane. Sysfb devices that have to emulate
+ * the format should use drm_sysfb_build_fourcc_list() to create a list
+ * of supported color formats. The returned list can be handed over to
+ * drm_universal_plane_init() et al. Native formats will go before
+ * emulated formats. Native formats with alpha channel will be replaced
+ * by equal formats without alpha channel, as primary planes usually
+ * don't support alpha. Other heuristics might be applied to optimize
+ * the sorting order. Formats near the beginning of the list are usually
+ * preferred over formats near the end of the list.
+ *
+ * Returns:
+ * The number of color-formats 4CC codes returned in @fourccs_out.
+ */
+size_t drm_sysfb_build_fourcc_list(struct drm_device *dev,
+				   const u32 *native_fourccs, size_t native_nfourccs,
+				   u32 *fourccs_out, size_t nfourccs_out)
+{
+	/*
+	 * XRGB8888 is the default fallback format for most of userspace
+	 * and it's currently the only format that should be emulated for
+	 * the primary plane. Only if there's ever another default fallback,
+	 * it should be added here.
+	 */
+	static const u32 extra_fourccs[] = {
+		DRM_FORMAT_XRGB8888,
+	};
+	static const size_t extra_nfourccs = ARRAY_SIZE(extra_fourccs);
+
+	u32 *fourccs = fourccs_out;
+	const u32 *fourccs_end = fourccs_out + nfourccs_out;
+	size_t i;
+
+	/*
+	 * The device's native formats go first.
+	 */
+
+	for (i = 0; i < native_nfourccs; ++i) {
+		/*
+		 * Several DTs, boot loaders and firmware report native
+		 * alpha formats that are non-alpha formats instead. So
+		 * replace alpha formats by non-alpha formats.
+		 */
+		u32 fourcc = to_nonalpha_fourcc(native_fourccs[i]);
+
+		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
+			continue; /* skip duplicate entries */
+		} else if (fourccs == fourccs_end) {
+			drm_warn(dev, "Ignoring native format %p4cc\n", &fourcc);
+			continue; /* end of available output buffer */
+		}
+
+		drm_dbg_kms(dev, "adding native format %p4cc\n", &fourcc);
+
+		*fourccs = fourcc;
+		++fourccs;
+	}
+
+	/*
+	 * The extra formats, emulated by the driver, go second.
+	 */
+
+	for (i = 0; (i < extra_nfourccs) && (fourccs < fourccs_end); ++i) {
+		u32 fourcc = extra_fourccs[i];
+
+		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
+			continue; /* skip duplicate and native entries */
+		} else if (fourccs == fourccs_end) {
+			drm_warn(dev, "Ignoring emulated format %p4cc\n", &fourcc);
+			continue; /* end of available output buffer */
+		}
+
+		drm_dbg_kms(dev, "adding emulated format %p4cc\n", &fourcc);
+
+		*fourccs = fourcc;
+		++fourccs;
+	}
+
+	return fourccs - fourccs_out;
+}
+EXPORT_SYMBOL(drm_sysfb_build_fourcc_list);
+
 int drm_sysfb_plane_helper_atomic_check(struct drm_plane *plane,
 					struct drm_atomic_state *new_state)
 {
diff --git a/drivers/gpu/drm/sysfb/efidrm.c b/drivers/gpu/drm/sysfb/efidrm.c
index 46912924636a..9562f9dc7835 100644
--- a/drivers/gpu/drm/sysfb/efidrm.c
+++ b/drivers/gpu/drm/sysfb/efidrm.c
@@ -271,8 +271,8 @@ static struct efidrm_device *efidrm_device_create(struct drm_driver *drv,
 
 	/* Primary plane */
 
-	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
-					    efi->formats, ARRAY_SIZE(efi->formats));
+	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
+					       efi->formats, ARRAY_SIZE(efi->formats));
 
 	primary_plane = &efi->primary_plane;
 	ret = drm_universal_plane_init(dev, primary_plane, 0, &efidrm_primary_plane_funcs,
diff --git a/drivers/gpu/drm/sysfb/ofdrm.c b/drivers/gpu/drm/sysfb/ofdrm.c
index c9415f0cb3ed..8d8ab39c5f36 100644
--- a/drivers/gpu/drm/sysfb/ofdrm.c
+++ b/drivers/gpu/drm/sysfb/ofdrm.c
@@ -15,7 +15,6 @@
 #include <drm/drm_drv.h>
 #include <drm/drm_edid.h>
 #include <drm/drm_fbdev_shmem.h>
-#include <drm/drm_format_helper.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
@@ -1015,8 +1014,8 @@ static struct ofdrm_device *ofdrm_device_create(struct drm_driver *drv,
 
 	/* Primary plane */
 
-	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
-					    odev->formats, ARRAY_SIZE(odev->formats));
+	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
+					       odev->formats, ARRAY_SIZE(odev->formats));
 
 	primary_plane = &odev->primary_plane;
 	ret = drm_universal_plane_init(dev, primary_plane, 0, &ofdrm_primary_plane_funcs,
diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c
index a1c3119330de..8530a3ef8a7a 100644
--- a/drivers/gpu/drm/sysfb/simpledrm.c
+++ b/drivers/gpu/drm/sysfb/simpledrm.c
@@ -18,7 +18,6 @@
 #include <drm/drm_device.h>
 #include <drm/drm_drv.h>
 #include <drm/drm_fbdev_shmem.h>
-#include <drm/drm_format_helper.h>
 #include <drm/drm_framebuffer.h>
 #include <drm/drm_gem_atomic_helper.h>
 #include <drm/drm_gem_framebuffer_helper.h>
@@ -765,8 +764,8 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
 
 	/* Primary plane */
 
-	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
-					    sdev->formats, ARRAY_SIZE(sdev->formats));
+	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
+					       sdev->formats, ARRAY_SIZE(sdev->formats));
 
 	primary_plane = &sdev->primary_plane;
 	ret = drm_universal_plane_init(dev, primary_plane, 0, &simpledrm_primary_plane_funcs,
diff --git a/drivers/gpu/drm/sysfb/vesadrm.c b/drivers/gpu/drm/sysfb/vesadrm.c
index 7945544ba73e..86e0b88dd51b 100644
--- a/drivers/gpu/drm/sysfb/vesadrm.c
+++ b/drivers/gpu/drm/sysfb/vesadrm.c
@@ -402,8 +402,8 @@ static struct vesadrm_device *vesadrm_device_create(struct drm_driver *drv,
 
 	/* Primary plane */
 
-	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
-					    vesa->formats, ARRAY_SIZE(vesa->formats));
+	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
+					       vesa->formats, ARRAY_SIZE(vesa->formats));
 
 	primary_plane = &vesa->primary_plane;
 	ret = drm_universal_plane_init(dev, primary_plane, 0, &vesadrm_primary_plane_funcs,
diff --git a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
index 88a4bf28c745..33acd3f02dc6 100644
--- a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
+++ b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
@@ -2,10 +2,11 @@
 
 #include <kunit/test.h>
 
-#include <drm/drm_format_helper.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_kunit_helpers.h>
 
+#include "../sysfb/drm_sysfb_helper.h"
+
 #define TEST_BUF_SIZE 50
 
 struct fb_build_fourcc_list_case {
@@ -141,9 +142,9 @@ static void drm_test_fb_build_fourcc_list(struct kunit *test)
 	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
 	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
 
-	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
-						params->native_fourccs_size,
-						fourccs_out, TEST_BUF_SIZE);
+	nfourccs_out = drm_sysfb_build_fourcc_list(drm, params->native_fourccs,
+						   params->native_fourccs_size,
+						   fourccs_out, TEST_BUF_SIZE);
 
 	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
 	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
index 49a2e09155d1..0d3ee2a1313f 100644
--- a/include/drm/drm_format_helper.h
+++ b/include/drm/drm_format_helper.h
@@ -134,8 +134,4 @@ void drm_fb_xrgb8888_to_mono(struct iosys_map *dst, const unsigned int *dst_pitc
 			     const struct iosys_map *src, const struct drm_framebuffer *fb,
 			     const struct drm_rect *clip, struct drm_format_conv_state *state);
 
-size_t drm_fb_build_fourcc_list(struct drm_device *dev,
-				const u32 *native_fourccs, size_t native_nfourccs,
-				u32 *fourccs_out, size_t nfourccs_out);
-
 #endif /* __LINUX_DRM_FORMAT_HELPER_H */
-- 
2.49.0


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

* Re: [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests
  2025-06-12 13:52 ` [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests Thomas Zimmermann
@ 2025-06-13 14:00   ` José Expósito
  0 siblings, 0 replies; 8+ messages in thread
From: José Expósito @ 2025-06-13 14:00 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: arthurgrillo, javierm, maarten.lankhorst, mripard, dri-devel

Hi Thomas,

On Thu, Jun 12, 2025 at 03:52:22PM +0200, Thomas Zimmermann wrote:
> Export additional helpers from the format-helper library and open-code
> drm_fb_blit() in tests. Prepares for the removal of drm_fb_blit(). Only
> sysfb drivers use drm_fb_blit(). The function will soon be removed from
> format helpers and be refactored within sysfb helpers.
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Acked-by: Maxime Ripard <mripard@kernel.org>

Reviewed and run the tests, they work, thanks.

Reviewed-by: José Expósito <jose.exposito89@gmail.com>

> ---
>  drivers/gpu/drm/drm_format_helper.c           | 108 ++++++++++++++++--
>  drivers/gpu/drm/drm_format_internal.h         |   8 ++
>  .../gpu/drm/tests/drm_format_helper_test.c    | 108 +++---------------
>  include/drm/drm_format_helper.h               |   9 ++
>  4 files changed, 131 insertions(+), 102 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> index d36e6cacc575..73b5a80771cc 100644
> --- a/drivers/gpu/drm/drm_format_helper.c
> +++ b/drivers/gpu/drm/drm_format_helper.c
> @@ -857,11 +857,33 @@ static void drm_fb_xrgb8888_to_abgr8888_line(void *dbuf, const void *sbuf, unsig
>  	drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_abgr8888);
>  }
>  
> -static void drm_fb_xrgb8888_to_abgr8888(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)
> +/**
> + * drm_fb_xrgb8888_to_abgr8888 - Convert XRGB8888 to ABGR8888 clip buffer
> + * @dst: Array of ABGR8888 destination buffers
> + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
> + *             within @dst; can be NULL if scanlines are stored next to each other.
> + * @src: Array of XRGB8888 source buffer
> + * @fb: DRM framebuffer
> + * @clip: Clip rectangle area to copy
> + * @state: Transform and conversion state
> + *
> + * This function copies parts of a framebuffer to display memory and converts the
> + * color format during the process. The parameters @dst, @dst_pitch and @src refer
> + * to arrays. Each array must have at least as many entries as there are planes in
> + * @fb's format. Each entry stores the value for the format's respective color plane
> + * at the same index.
> + *
> + * This function does not apply clipping on @dst (i.e. the destination is at the
> + * top-left corner).
> + *
> + * Drivers can use this function for ABGR8888 devices that don't support XRGB8888
> + * natively. It sets an opaque alpha channel as part of the conversion.
> + */
> +void drm_fb_xrgb8888_to_abgr8888(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)
>  {
>  	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
>  		4,
> @@ -870,17 +892,40 @@ static void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned in
>  	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
>  		    drm_fb_xrgb8888_to_abgr8888_line);
>  }
> +EXPORT_SYMBOL(drm_fb_xrgb8888_to_abgr8888);
>  
>  static void drm_fb_xrgb8888_to_xbgr8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
>  {
>  	drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_xbgr8888);
>  }
>  
> -static void drm_fb_xrgb8888_to_xbgr8888(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)
> +/**
> + * drm_fb_xrgb8888_to_xbgr8888 - Convert XRGB8888 to XBGR8888 clip buffer
> + * @dst: Array of XBGR8888 destination buffers
> + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
> + *             within @dst; can be NULL if scanlines are stored next to each other.
> + * @src: Array of XRGB8888 source buffer
> + * @fb: DRM framebuffer
> + * @clip: Clip rectangle area to copy
> + * @state: Transform and conversion state
> + *
> + * This function copies parts of a framebuffer to display memory and converts the
> + * color format during the process. The parameters @dst, @dst_pitch and @src refer
> + * to arrays. Each array must have at least as many entries as there are planes in
> + * @fb's format. Each entry stores the value for the format's respective color plane
> + * at the same index.
> + *
> + * This function does not apply clipping on @dst (i.e. the destination is at the
> + * top-left corner).
> + *
> + * Drivers can use this function for XBGR8888 devices that don't support XRGB8888
> + * natively.
> + */
> +void drm_fb_xrgb8888_to_xbgr8888(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)
>  {
>  	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
>  		4,
> @@ -889,6 +934,49 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
>  	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
>  		    drm_fb_xrgb8888_to_xbgr8888_line);
>  }
> +EXPORT_SYMBOL(drm_fb_xrgb8888_to_xbgr8888);
> +
> +static void drm_fb_xrgb8888_to_bgrx8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
> +{
> +	drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_bgrx8888);
> +}
> +
> +/**
> + * drm_fb_xrgb8888_to_bgrx8888 - Convert XRGB8888 to BGRX8888 clip buffer
> + * @dst: Array of BGRX8888 destination buffers
> + * @dst_pitch: Array of numbers of bytes between the start of two consecutive scanlines
> + *             within @dst; can be NULL if scanlines are stored next to each other.
> + * @src: Array of XRGB8888 source buffer
> + * @fb: DRM framebuffer
> + * @clip: Clip rectangle area to copy
> + * @state: Transform and conversion state
> + *
> + * This function copies parts of a framebuffer to display memory and converts the
> + * color format during the process. The parameters @dst, @dst_pitch and @src refer
> + * to arrays. Each array must have at least as many entries as there are planes in
> + * @fb's format. Each entry stores the value for the format's respective color plane
> + * at the same index.
> + *
> + * This function does not apply clipping on @dst (i.e. the destination is at the
> + * top-left corner).
> + *
> + * Drivers can use this function for BGRX8888 devices that don't support XRGB8888
> + * natively.
> + */
> +void drm_fb_xrgb8888_to_bgrx8888(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)
> +{
> +	static const u8 dst_pixsize[DRM_FORMAT_MAX_PLANES] = {
> +		4,
> +	};
> +
> +	drm_fb_xfrm(dst, dst_pitch, dst_pixsize, src, fb, clip, false, state,
> +		    drm_fb_xrgb8888_to_bgrx8888_line);
> +}
> +EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgrx8888);
>  
>  static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
>  {
> diff --git a/drivers/gpu/drm/drm_format_internal.h b/drivers/gpu/drm/drm_format_internal.h
> index 9f857bfa368d..0aa458b8a3e0 100644
> --- a/drivers/gpu/drm/drm_format_internal.h
> +++ b/drivers/gpu/drm/drm_format_internal.h
> @@ -111,6 +111,14 @@ static inline u32 drm_pixel_xrgb8888_to_xbgr8888(u32 pix)
>  	       ((pix & 0x000000ff) << 16);
>  }
>  
> +static inline u32 drm_pixel_xrgb8888_to_bgrx8888(u32 pix)
> +{
> +	return ((pix & 0xff000000) >> 24) | /* also copy filler bits */
> +	       ((pix & 0x00ff0000) >> 8) |
> +	       ((pix & 0x0000ff00) << 8) |
> +	       ((pix & 0x000000ff) << 24);
> +}
> +
>  static inline u32 drm_pixel_xrgb8888_to_abgr8888(u32 pix)
>  {
>  	return GENMASK(31, 24) | /* fill alpha bits */
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 35cd3405d045..8aacc1ffa93a 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -748,14 +748,9 @@ static void drm_test_fb_xrgb8888_to_rgb565(struct kunit *test)
>  	buf = dst.vaddr;
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGB565, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_rgb565(&dst, dst_pitch, &src, &fb, &params->clip,
> +				  &fmtcnv_state, false);
>  	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -795,14 +790,8 @@ static void drm_test_fb_xrgb8888_to_xrgb1555(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB1555, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_xrgb1555(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -842,14 +831,8 @@ static void drm_test_fb_xrgb8888_to_argb1555(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB1555, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_argb1555(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -889,14 +872,8 @@ static void drm_test_fb_xrgb8888_to_rgba5551(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGBA5551, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_rgba5551(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le16buf_to_cpu(test, (__force const __le16 *)buf, dst_size / sizeof(__le16));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -939,12 +916,7 @@ static void drm_test_fb_xrgb8888_to_rgb888(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_RGB888, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
> +	drm_fb_xrgb8888_to_rgb888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -985,12 +957,8 @@ static void drm_test_fb_xrgb8888_to_bgr888(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, &result->dst_pitch, DRM_FORMAT_BGR888, &src, &fb, &params->clip,
> +	drm_fb_xrgb8888_to_bgr888(&dst, &result->dst_pitch, &src, &fb, &params->clip,
>  				  &fmtcnv_state);
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1030,14 +998,8 @@ static void drm_test_fb_xrgb8888_to_argb8888(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB8888, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_argb8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1077,12 +1039,7 @@ static void drm_test_fb_xrgb8888_to_xrgb2101010(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB2101010, &src, &fb,
> -				  &params->clip, &fmtcnv_state);
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
> +	drm_fb_xrgb8888_to_xrgb2101010(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1122,14 +1079,8 @@ static void drm_test_fb_xrgb8888_to_argb2101010(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ARGB2101010, &src, &fb,
> -				  &params->clip, &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_argb2101010(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1202,23 +1153,15 @@ static void drm_test_fb_swab(struct kunit *test)
>  	buf = dst.vaddr; /* restore original value of buf */
>  	memset(buf, 0, dst_size);
>  
> -	int blit_result;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB8888 | DRM_FORMAT_BIG_ENDIAN,
> -				  &src, &fb, &params->clip, &fmtcnv_state);
> +	drm_fb_swab(&dst, dst_pitch, &src, &fb, &params->clip, false, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  
>  	buf = dst.vaddr;
>  	memset(buf, 0, dst_size);
>  
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_BGRX8888, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> +	drm_fb_xrgb8888_to_bgrx8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  
>  	buf = dst.vaddr;
> @@ -1229,11 +1172,8 @@ static void drm_test_fb_swab(struct kunit *test)
>  	mock_format.format |= DRM_FORMAT_BIG_ENDIAN;
>  	fb.format = &mock_format;
>  
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XRGB8888, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> +	drm_fb_swab(&dst, dst_pitch, &src, &fb, &params->clip, false, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1266,14 +1206,8 @@ static void drm_test_fb_xrgb8888_to_abgr8888(struct kunit *test)
>  	const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
>  		NULL : &result->dst_pitch;
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_ABGR8888, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_abgr8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1306,14 +1240,8 @@ static void drm_test_fb_xrgb8888_to_xbgr8888(struct kunit *test)
>  	const unsigned int *dst_pitch = (result->dst_pitch == TEST_USE_DEFAULT_PITCH) ?
>  		NULL : &result->dst_pitch;
>  
> -	int blit_result = 0;
> -
> -	blit_result = drm_fb_blit(&dst, dst_pitch, DRM_FORMAT_XBGR8888, &src, &fb, &params->clip,
> -				  &fmtcnv_state);
> -
> +	drm_fb_xrgb8888_to_xbgr8888(&dst, dst_pitch, &src, &fb, &params->clip, &fmtcnv_state);
>  	buf = le32buf_to_cpu(test, (__force const __le32 *)buf, dst_size / sizeof(u32));
> -
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	KUNIT_EXPECT_MEMEQ(test, buf, result->expected, dst_size);
>  }
>  
> @@ -1910,12 +1838,8 @@ static void drm_test_fb_memcpy(struct kunit *test)
>  		memset(buf[i], 0, dst_size[i]);
>  	}
>  
> -	int blit_result;
> -
> -	blit_result = drm_fb_blit(dst, dst_pitches, params->format, src, &fb, &params->clip,
> -				  &fmtcnv_state);
> +	drm_fb_memcpy(dst, dst_pitches, src, &fb, &params->clip);
>  
> -	KUNIT_EXPECT_FALSE(test, blit_result);
>  	for (size_t i = 0; i < fb.format->num_planes; i++) {
>  		expected[i] = cpubuf_to_le32(test, params->expected[i], TEST_BUF_SIZE);
>  		KUNIT_EXPECT_MEMEQ_MSG(test, buf[i], expected[i], dst_size[i],
> diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
> index d8539174ca11..49a2e09155d1 100644
> --- a/include/drm/drm_format_helper.h
> +++ b/include/drm/drm_format_helper.h
> @@ -102,6 +102,15 @@ void drm_fb_xrgb8888_to_bgr888(struct iosys_map *dst, const unsigned int *dst_pi
>  void drm_fb_xrgb8888_to_argb8888(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_xrgb8888_to_abgr8888(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_xrgb8888_to_xbgr8888(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_xrgb8888_to_bgrx8888(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_xrgb8888_to_xrgb2101010(struct iosys_map *dst, const unsigned int *dst_pitch,
>  				    const struct iosys_map *src, const struct drm_framebuffer *fb,
>  				    const struct drm_rect *clip,
> -- 
> 2.49.0
> 

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

* Re: [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite
  2025-06-12 13:52 ` [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite Thomas Zimmermann
@ 2025-06-13 14:03   ` José Expósito
  2025-06-13 15:41     ` Thomas Zimmermann
  0 siblings, 1 reply; 8+ messages in thread
From: José Expósito @ 2025-06-13 14:03 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: arthurgrillo, javierm, maarten.lankhorst, mripard, dri-devel

On Thu, Jun 12, 2025 at 03:52:23PM +0200, Thomas Zimmermann wrote:
> Only sysfb drivers use drm_fb_build_fourcc_list(). The helper will
> be moved from format helpers to sysfb helpers. Moving the related
> tests to their own test suite.
> 
> v2:
> - rename filename to match tested code (Maxime)
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Acked-by: Maxime Ripard <mripard@kernel.org>
> ---
>  drivers/gpu/drm/tests/Makefile                |   3 +-
>  .../gpu/drm/tests/drm_format_helper_test.c    | 142 ---------------
>  .../gpu/drm/tests/drm_sysfb_modeset_test.c    | 166 ++++++++++++++++++
>  3 files changed, 168 insertions(+), 143 deletions(-)
>  create mode 100644 drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
> 
> diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile
> index 3afd6587df08..c0e952293ad0 100644
> --- a/drivers/gpu/drm/tests/Makefile
> +++ b/drivers/gpu/drm/tests/Makefile
> @@ -23,6 +23,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \
>  	drm_modes_test.o \
>  	drm_plane_helper_test.o \
>  	drm_probe_helper_test.o \
> -	drm_rect_test.o
> +	drm_rect_test.o \
> +	drm_sysfb_modeset_test.o
>  
>  CFLAGS_drm_mm_test.o := $(DISABLE_STRUCTLEAK_PLUGIN)
> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
> index 8aacc1ffa93a..ef1cc3b28f1b 100644
> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
> @@ -1335,147 +1335,6 @@ static void drm_test_fb_clip_offset(struct kunit *test)
>  	KUNIT_EXPECT_EQ(test, offset, params->expected_offset);
>  }
>  
> -struct fb_build_fourcc_list_case {
> -	const char *name;
> -	u32 native_fourccs[TEST_BUF_SIZE];
> -	size_t native_fourccs_size;
> -	u32 expected[TEST_BUF_SIZE];
> -	size_t expected_fourccs_size;
> -};
> -
> -static struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
> -	{
> -		.name = "no native formats",
> -		.native_fourccs = { },
> -		.native_fourccs_size = 0,
> -		.expected = { DRM_FORMAT_XRGB8888 },
> -		.expected_fourccs_size = 1,
> -	},
> -	{
> -		.name = "XRGB8888 as native format",
> -		.native_fourccs = { DRM_FORMAT_XRGB8888 },
> -		.native_fourccs_size = 1,
> -		.expected = { DRM_FORMAT_XRGB8888 },
> -		.expected_fourccs_size = 1,
> -	},
> -	{
> -		.name = "remove duplicates",
> -		.native_fourccs = {
> -			DRM_FORMAT_XRGB8888,
> -			DRM_FORMAT_XRGB8888,
> -			DRM_FORMAT_RGB888,
> -			DRM_FORMAT_RGB888,
> -			DRM_FORMAT_RGB888,
> -			DRM_FORMAT_XRGB8888,
> -			DRM_FORMAT_RGB888,
> -			DRM_FORMAT_RGB565,
> -			DRM_FORMAT_RGB888,
> -			DRM_FORMAT_XRGB8888,
> -			DRM_FORMAT_RGB565,
> -			DRM_FORMAT_RGB565,
> -			DRM_FORMAT_XRGB8888,
> -		},
> -		.native_fourccs_size = 11,
> -		.expected = {
> -			DRM_FORMAT_XRGB8888,
> -			DRM_FORMAT_RGB888,
> -			DRM_FORMAT_RGB565,
> -		},
> -		.expected_fourccs_size = 3,
> -	},
> -	{
> -		.name = "convert alpha formats",
> -		.native_fourccs = {
> -			DRM_FORMAT_ARGB1555,
> -			DRM_FORMAT_ABGR1555,
> -			DRM_FORMAT_RGBA5551,
> -			DRM_FORMAT_BGRA5551,
> -			DRM_FORMAT_ARGB8888,
> -			DRM_FORMAT_ABGR8888,
> -			DRM_FORMAT_RGBA8888,
> -			DRM_FORMAT_BGRA8888,
> -			DRM_FORMAT_ARGB2101010,
> -			DRM_FORMAT_ABGR2101010,
> -			DRM_FORMAT_RGBA1010102,
> -			DRM_FORMAT_BGRA1010102,
> -		},
> -		.native_fourccs_size = 12,
> -		.expected = {
> -			DRM_FORMAT_XRGB1555,
> -			DRM_FORMAT_XBGR1555,
> -			DRM_FORMAT_RGBX5551,
> -			DRM_FORMAT_BGRX5551,
> -			DRM_FORMAT_XRGB8888,
> -			DRM_FORMAT_XBGR8888,
> -			DRM_FORMAT_RGBX8888,
> -			DRM_FORMAT_BGRX8888,
> -			DRM_FORMAT_XRGB2101010,
> -			DRM_FORMAT_XBGR2101010,
> -			DRM_FORMAT_RGBX1010102,
> -			DRM_FORMAT_BGRX1010102,
> -		},
> -		.expected_fourccs_size = 12,
> -	},
> -	{
> -		.name = "random formats",
> -		.native_fourccs = {
> -			DRM_FORMAT_Y212,
> -			DRM_FORMAT_ARGB1555,
> -			DRM_FORMAT_ABGR16161616F,
> -			DRM_FORMAT_C8,
> -			DRM_FORMAT_BGR888,
> -			DRM_FORMAT_XRGB1555,
> -			DRM_FORMAT_RGBA5551,
> -			DRM_FORMAT_BGR565_A8,
> -			DRM_FORMAT_R10,
> -			DRM_FORMAT_XYUV8888,
> -		},
> -		.native_fourccs_size = 10,
> -		.expected = {
> -			DRM_FORMAT_Y212,
> -			DRM_FORMAT_XRGB1555,
> -			DRM_FORMAT_ABGR16161616F,
> -			DRM_FORMAT_C8,
> -			DRM_FORMAT_BGR888,
> -			DRM_FORMAT_RGBX5551,
> -			DRM_FORMAT_BGR565_A8,
> -			DRM_FORMAT_R10,
> -			DRM_FORMAT_XYUV8888,
> -			DRM_FORMAT_XRGB8888,
> -		},
> -		.expected_fourccs_size = 10,
> -	},
> -};
> -
> -static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
> -{
> -	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
> -}
> -
> -KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
> -
> -static void drm_test_fb_build_fourcc_list(struct kunit *test)
> -{
> -	const struct fb_build_fourcc_list_case *params = test->param_value;
> -	u32 fourccs_out[TEST_BUF_SIZE] = {0};
> -	size_t nfourccs_out;
> -	struct drm_device *drm;
> -	struct device *dev;
> -
> -	dev = drm_kunit_helper_alloc_device(test);
> -	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
> -
> -	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
> -	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
> -
> -	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
> -						params->native_fourccs_size,
> -						fourccs_out, TEST_BUF_SIZE);
> -
> -	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
> -	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
> -}
> -
>  struct fb_memcpy_case {
>  	const char *name;
>  	u32 format;
> @@ -1864,7 +1723,6 @@ static struct kunit_case drm_format_helper_test_cases[] = {
>  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xbgr8888, convert_xrgb8888_gen_params),
>  	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_abgr8888, convert_xrgb8888_gen_params),
>  	KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params),
> -	KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
>  	KUNIT_CASE_PARAM(drm_test_fb_memcpy, fb_memcpy_gen_params),
>  	{}
>  };
> diff --git a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
> new file mode 100644
> index 000000000000..88a4bf28c745
> --- /dev/null
> +++ b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
> @@ -0,0 +1,166 @@
> +// SPDX-License-Identifier: GPL-2.0+
> +
> +#include <kunit/test.h>
> +
> +#include <drm/drm_format_helper.h>
> +#include <drm/drm_fourcc.h>
> +#include <drm/drm_kunit_helpers.h>
> +
> +#define TEST_BUF_SIZE 50
> +
> +struct fb_build_fourcc_list_case {
> +	const char *name;
> +	u32 native_fourccs[TEST_BUF_SIZE];
> +	size_t native_fourccs_size;
> +	u32 expected[TEST_BUF_SIZE];
> +	size_t expected_fourccs_size;
> +};
> +
> +static struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
> +	{
> +		.name = "no native formats",
> +		.native_fourccs = { },
> +		.native_fourccs_size = 0,
> +		.expected = { DRM_FORMAT_XRGB8888 },
> +		.expected_fourccs_size = 1,
> +	},
> +	{
> +		.name = "XRGB8888 as native format",
> +		.native_fourccs = { DRM_FORMAT_XRGB8888 },
> +		.native_fourccs_size = 1,
> +		.expected = { DRM_FORMAT_XRGB8888 },
> +		.expected_fourccs_size = 1,
> +	},
> +	{
> +		.name = "remove duplicates",
> +		.native_fourccs = {
> +			DRM_FORMAT_XRGB8888,
> +			DRM_FORMAT_XRGB8888,
> +			DRM_FORMAT_RGB888,
> +			DRM_FORMAT_RGB888,
> +			DRM_FORMAT_RGB888,
> +			DRM_FORMAT_XRGB8888,
> +			DRM_FORMAT_RGB888,
> +			DRM_FORMAT_RGB565,
> +			DRM_FORMAT_RGB888,
> +			DRM_FORMAT_XRGB8888,
> +			DRM_FORMAT_RGB565,
> +			DRM_FORMAT_RGB565,
> +			DRM_FORMAT_XRGB8888,
> +		},
> +		.native_fourccs_size = 11,
> +		.expected = {
> +			DRM_FORMAT_XRGB8888,
> +			DRM_FORMAT_RGB888,
> +			DRM_FORMAT_RGB565,
> +		},
> +		.expected_fourccs_size = 3,
> +	},
> +	{
> +		.name = "convert alpha formats",
> +		.native_fourccs = {
> +			DRM_FORMAT_ARGB1555,
> +			DRM_FORMAT_ABGR1555,
> +			DRM_FORMAT_RGBA5551,
> +			DRM_FORMAT_BGRA5551,
> +			DRM_FORMAT_ARGB8888,
> +			DRM_FORMAT_ABGR8888,
> +			DRM_FORMAT_RGBA8888,
> +			DRM_FORMAT_BGRA8888,
> +			DRM_FORMAT_ARGB2101010,
> +			DRM_FORMAT_ABGR2101010,
> +			DRM_FORMAT_RGBA1010102,
> +			DRM_FORMAT_BGRA1010102,
> +		},
> +		.native_fourccs_size = 12,
> +		.expected = {
> +			DRM_FORMAT_XRGB1555,
> +			DRM_FORMAT_XBGR1555,
> +			DRM_FORMAT_RGBX5551,
> +			DRM_FORMAT_BGRX5551,
> +			DRM_FORMAT_XRGB8888,
> +			DRM_FORMAT_XBGR8888,
> +			DRM_FORMAT_RGBX8888,
> +			DRM_FORMAT_BGRX8888,
> +			DRM_FORMAT_XRGB2101010,
> +			DRM_FORMAT_XBGR2101010,
> +			DRM_FORMAT_RGBX1010102,
> +			DRM_FORMAT_BGRX1010102,
> +		},
> +		.expected_fourccs_size = 12,
> +	},
> +	{
> +		.name = "random formats",
> +		.native_fourccs = {
> +			DRM_FORMAT_Y212,
> +			DRM_FORMAT_ARGB1555,
> +			DRM_FORMAT_ABGR16161616F,
> +			DRM_FORMAT_C8,
> +			DRM_FORMAT_BGR888,
> +			DRM_FORMAT_XRGB1555,
> +			DRM_FORMAT_RGBA5551,
> +			DRM_FORMAT_BGR565_A8,
> +			DRM_FORMAT_R10,
> +			DRM_FORMAT_XYUV8888,
> +		},
> +		.native_fourccs_size = 10,
> +		.expected = {
> +			DRM_FORMAT_Y212,
> +			DRM_FORMAT_XRGB1555,
> +			DRM_FORMAT_ABGR16161616F,
> +			DRM_FORMAT_C8,
> +			DRM_FORMAT_BGR888,
> +			DRM_FORMAT_RGBX5551,
> +			DRM_FORMAT_BGR565_A8,
> +			DRM_FORMAT_R10,
> +			DRM_FORMAT_XYUV8888,
> +			DRM_FORMAT_XRGB8888,
> +		},
> +		.expected_fourccs_size = 10,
> +	},
> +};
> +
> +static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
> +{
> +	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
> +}
> +
> +KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
> +
> +static void drm_test_fb_build_fourcc_list(struct kunit *test)
> +{
> +	const struct fb_build_fourcc_list_case *params = test->param_value;
> +	u32 fourccs_out[TEST_BUF_SIZE] = {0};
> +	size_t nfourccs_out;
> +	struct drm_device *drm;
> +	struct device *dev;
> +
> +	dev = drm_kunit_helper_alloc_device(test);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
> +
> +	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
> +
> +	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
> +						params->native_fourccs_size,
> +						fourccs_out, TEST_BUF_SIZE);
> +
> +	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
> +	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
> +}
> +
> +static struct kunit_case drm_sysfb_helper_test_cases[] = {
> +	KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
> +	{}
> +};
> +
> +static struct kunit_suite drm_sysfb_helper_test_suite = {
> +	.name = "drm_sysfb_helper_test",

Other tests use the same name as the file live in, dropping or not
the "_test" suffix.

Is this a missing change from the rename in v1?

Other than that:

Reviewed-by: José Expósito <jose.exposito89@gmail.com>

> +	.test_cases = drm_sysfb_helper_test_cases,
> +};
> +
> +kunit_test_suite(drm_sysfb_helper_test_suite);
> +
> +MODULE_DESCRIPTION("KUnit tests for the drm_sysfb_helper APIs");
> +MODULE_LICENSE("GPL");
> +MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>");
> -- 
> 2.49.0
> 

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

* Re: [PATCH v2 3/3] drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers
  2025-06-12 13:52 ` [PATCH v2 3/3] drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers Thomas Zimmermann
@ 2025-06-13 14:53   ` José Expósito
  0 siblings, 0 replies; 8+ messages in thread
From: José Expósito @ 2025-06-13 14:53 UTC (permalink / raw)
  To: Thomas Zimmermann
  Cc: arthurgrillo, javierm, maarten.lankhorst, mripard, dri-devel

On Thu, Jun 12, 2025 at 03:52:24PM +0200, Thomas Zimmermann wrote:
> Only sysfb drivers use drm_fb_build_fourcc_list(). Move the function
> to sysfb helpers and rename it accordingly. Update drivers and tests.
> 
> v2:
> - select DRM_SYSFB_HELPER (kernel test robot)
> 
> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
> Acked-by: Maxime Ripard <mripard@kernel.org>
> Acked-by: Javier Martinez Canillas <javierm@redhat.com>

Reviewed-by: José Expósito <jose.exposito89@gmail.com

>
> ---
>  drivers/gpu/drm/Kconfig.debug                 |   1 +
>  drivers/gpu/drm/drm_format_helper.c           | 138 ------------------
>  drivers/gpu/drm/sysfb/drm_sysfb_helper.h      |   4 +
>  drivers/gpu/drm/sysfb/drm_sysfb_modeset.c     | 138 ++++++++++++++++++
>  drivers/gpu/drm/sysfb/efidrm.c                |   4 +-
>  drivers/gpu/drm/sysfb/ofdrm.c                 |   5 +-
>  drivers/gpu/drm/sysfb/simpledrm.c             |   5 +-
>  drivers/gpu/drm/sysfb/vesadrm.c               |   4 +-
>  .../gpu/drm/tests/drm_sysfb_modeset_test.c    |   9 +-
>  include/drm/drm_format_helper.h               |   4 -
>  10 files changed, 156 insertions(+), 156 deletions(-)
> 
> diff --git a/drivers/gpu/drm/Kconfig.debug b/drivers/gpu/drm/Kconfig.debug
> index fa6ee76f4d3c..05dc43c0b8c5 100644
> --- a/drivers/gpu/drm/Kconfig.debug
> +++ b/drivers/gpu/drm/Kconfig.debug
> @@ -70,6 +70,7 @@ config DRM_KUNIT_TEST
>  	select DRM_GEM_SHMEM_HELPER
>  	select DRM_KUNIT_TEST_HELPERS
>  	select DRM_LIB_RANDOM
> +	select DRM_SYSFB_HELPER
>  	select PRIME_NUMBERS
>  	default KUNIT_ALL_TESTS
>  	help
> diff --git a/drivers/gpu/drm/drm_format_helper.c b/drivers/gpu/drm/drm_format_helper.c
> index 73b5a80771cc..da79100895ff 100644
> --- a/drivers/gpu/drm/drm_format_helper.c
> +++ b/drivers/gpu/drm/drm_format_helper.c
> @@ -1338,141 +1338,3 @@ void drm_fb_xrgb8888_to_mono(struct iosys_map *dst, const unsigned int *dst_pitc
>  	}
>  }
>  EXPORT_SYMBOL(drm_fb_xrgb8888_to_mono);
> -
> -static uint32_t drm_fb_nonalpha_fourcc(uint32_t fourcc)
> -{
> -	/* only handle formats with depth != 0 and alpha channel */
> -	switch (fourcc) {
> -	case DRM_FORMAT_ARGB1555:
> -		return DRM_FORMAT_XRGB1555;
> -	case DRM_FORMAT_ABGR1555:
> -		return DRM_FORMAT_XBGR1555;
> -	case DRM_FORMAT_RGBA5551:
> -		return DRM_FORMAT_RGBX5551;
> -	case DRM_FORMAT_BGRA5551:
> -		return DRM_FORMAT_BGRX5551;
> -	case DRM_FORMAT_ARGB8888:
> -		return DRM_FORMAT_XRGB8888;
> -	case DRM_FORMAT_ABGR8888:
> -		return DRM_FORMAT_XBGR8888;
> -	case DRM_FORMAT_RGBA8888:
> -		return DRM_FORMAT_RGBX8888;
> -	case DRM_FORMAT_BGRA8888:
> -		return DRM_FORMAT_BGRX8888;
> -	case DRM_FORMAT_ARGB2101010:
> -		return DRM_FORMAT_XRGB2101010;
> -	case DRM_FORMAT_ABGR2101010:
> -		return DRM_FORMAT_XBGR2101010;
> -	case DRM_FORMAT_RGBA1010102:
> -		return DRM_FORMAT_RGBX1010102;
> -	case DRM_FORMAT_BGRA1010102:
> -		return DRM_FORMAT_BGRX1010102;
> -	}
> -
> -	return fourcc;
> -}
> -
> -static bool is_listed_fourcc(const uint32_t *fourccs, size_t nfourccs, uint32_t fourcc)
> -{
> -	const uint32_t *fourccs_end = fourccs + nfourccs;
> -
> -	while (fourccs < fourccs_end) {
> -		if (*fourccs == fourcc)
> -			return true;
> -		++fourccs;
> -	}
> -	return false;
> -}
> -
> -/**
> - * drm_fb_build_fourcc_list - Filters a list of supported color formats against
> - *                            the device's native formats
> - * @dev: DRM device
> - * @native_fourccs: 4CC codes of natively supported color formats
> - * @native_nfourccs: The number of entries in @native_fourccs
> - * @fourccs_out: Returns 4CC codes of supported color formats
> - * @nfourccs_out: The number of available entries in @fourccs_out
> - *
> - * This function create a list of supported color format from natively
> - * supported formats and additional emulated formats.
> - * At a minimum, most userspace programs expect at least support for
> - * XRGB8888 on the primary plane. Devices that have to emulate the
> - * format, and possibly others, can use drm_fb_build_fourcc_list() to
> - * create a list of supported color formats. The returned list can
> - * be handed over to drm_universal_plane_init() et al. Native formats
> - * will go before emulated formats. Native formats with alpha channel
> - * will be replaced by such without, as primary planes usually don't
> - * support alpha. Other heuristics might be applied
> - * to optimize the order. Formats near the beginning of the list are
> - * usually preferred over formats near the end of the list.
> - *
> - * Returns:
> - * The number of color-formats 4CC codes returned in @fourccs_out.
> - */
> -size_t drm_fb_build_fourcc_list(struct drm_device *dev,
> -				const u32 *native_fourccs, size_t native_nfourccs,
> -				u32 *fourccs_out, size_t nfourccs_out)
> -{
> -	/*
> -	 * XRGB8888 is the default fallback format for most of userspace
> -	 * and it's currently the only format that should be emulated for
> -	 * the primary plane. Only if there's ever another default fallback,
> -	 * it should be added here.
> -	 */
> -	static const uint32_t extra_fourccs[] = {
> -		DRM_FORMAT_XRGB8888,
> -	};
> -	static const size_t extra_nfourccs = ARRAY_SIZE(extra_fourccs);
> -
> -	u32 *fourccs = fourccs_out;
> -	const u32 *fourccs_end = fourccs_out + nfourccs_out;
> -	size_t i;
> -
> -	/*
> -	 * The device's native formats go first.
> -	 */
> -
> -	for (i = 0; i < native_nfourccs; ++i) {
> -		/*
> -		 * Several DTs, boot loaders and firmware report native
> -		 * alpha formats that are non-alpha formats instead. So
> -		 * replace alpha formats by non-alpha formats.
> -		 */
> -		u32 fourcc = drm_fb_nonalpha_fourcc(native_fourccs[i]);
> -
> -		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
> -			continue; /* skip duplicate entries */
> -		} else if (fourccs == fourccs_end) {
> -			drm_warn(dev, "Ignoring native format %p4cc\n", &fourcc);
> -			continue; /* end of available output buffer */
> -		}
> -
> -		drm_dbg_kms(dev, "adding native format %p4cc\n", &fourcc);
> -
> -		*fourccs = fourcc;
> -		++fourccs;
> -	}
> -
> -	/*
> -	 * The extra formats, emulated by the driver, go second.
> -	 */
> -
> -	for (i = 0; (i < extra_nfourccs) && (fourccs < fourccs_end); ++i) {
> -		u32 fourcc = extra_fourccs[i];
> -
> -		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
> -			continue; /* skip duplicate and native entries */
> -		} else if (fourccs == fourccs_end) {
> -			drm_warn(dev, "Ignoring emulated format %p4cc\n", &fourcc);
> -			continue; /* end of available output buffer */
> -		}
> -
> -		drm_dbg_kms(dev, "adding emulated format %p4cc\n", &fourcc);
> -
> -		*fourccs = fourcc;
> -		++fourccs;
> -	}
> -
> -	return fourccs - fourccs_out;
> -}
> -EXPORT_SYMBOL(drm_fb_build_fourcc_list);
> diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h
> index cb08a88242cc..1424b63dde99 100644
> --- a/drivers/gpu/drm/sysfb/drm_sysfb_helper.h
> +++ b/drivers/gpu/drm/sysfb/drm_sysfb_helper.h
> @@ -93,6 +93,10 @@ static inline struct drm_sysfb_device *to_drm_sysfb_device(struct drm_device *de
>   * Plane
>   */
>  
> +size_t drm_sysfb_build_fourcc_list(struct drm_device *dev,
> +				   const u32 *native_fourccs, size_t native_nfourccs,
> +				   u32 *fourccs_out, size_t nfourccs_out);
> +
>  int drm_sysfb_plane_helper_atomic_check(struct drm_plane *plane,
>  					struct drm_atomic_state *new_state);
>  void drm_sysfb_plane_helper_atomic_update(struct drm_plane *plane,
> diff --git a/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c b/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c
> index ffaa2522ab96..1bcdb5ee8f09 100644
> --- a/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c
> +++ b/drivers/gpu/drm/sysfb/drm_sysfb_modeset.c
> @@ -47,6 +47,144 @@ EXPORT_SYMBOL(drm_sysfb_mode);
>   * Plane
>   */
>  
> +static u32 to_nonalpha_fourcc(u32 fourcc)
> +{
> +	/* only handle formats with depth != 0 and alpha channel */
> +	switch (fourcc) {
> +	case DRM_FORMAT_ARGB1555:
> +		return DRM_FORMAT_XRGB1555;
> +	case DRM_FORMAT_ABGR1555:
> +		return DRM_FORMAT_XBGR1555;
> +	case DRM_FORMAT_RGBA5551:
> +		return DRM_FORMAT_RGBX5551;
> +	case DRM_FORMAT_BGRA5551:
> +		return DRM_FORMAT_BGRX5551;
> +	case DRM_FORMAT_ARGB8888:
> +		return DRM_FORMAT_XRGB8888;
> +	case DRM_FORMAT_ABGR8888:
> +		return DRM_FORMAT_XBGR8888;
> +	case DRM_FORMAT_RGBA8888:
> +		return DRM_FORMAT_RGBX8888;
> +	case DRM_FORMAT_BGRA8888:
> +		return DRM_FORMAT_BGRX8888;
> +	case DRM_FORMAT_ARGB2101010:
> +		return DRM_FORMAT_XRGB2101010;
> +	case DRM_FORMAT_ABGR2101010:
> +		return DRM_FORMAT_XBGR2101010;
> +	case DRM_FORMAT_RGBA1010102:
> +		return DRM_FORMAT_RGBX1010102;
> +	case DRM_FORMAT_BGRA1010102:
> +		return DRM_FORMAT_BGRX1010102;
> +	}
> +
> +	return fourcc;
> +}
> +
> +static bool is_listed_fourcc(const u32 *fourccs, size_t nfourccs, u32 fourcc)
> +{
> +	const u32 *fourccs_end = fourccs + nfourccs;
> +
> +	while (fourccs < fourccs_end) {
> +		if (*fourccs == fourcc)
> +			return true;
> +		++fourccs;
> +	}
> +	return false;
> +}
> +
> +/**
> + * drm_sysfb_build_fourcc_list - Filters a list of supported color formats against
> + *                               the device's native formats
> + * @dev: DRM device
> + * @native_fourccs: 4CC codes of natively supported color formats
> + * @native_nfourccs: The number of entries in @native_fourccs
> + * @fourccs_out: Returns 4CC codes of supported color formats
> + * @nfourccs_out: The number of available entries in @fourccs_out
> + *
> + * This function create a list of supported color format from natively
> + * supported formats and additional emulated formats.
> + * At a minimum, most userspace programs expect at least support for
> + * XRGB8888 on the primary plane. Sysfb devices that have to emulate
> + * the format should use drm_sysfb_build_fourcc_list() to create a list
> + * of supported color formats. The returned list can be handed over to
> + * drm_universal_plane_init() et al. Native formats will go before
> + * emulated formats. Native formats with alpha channel will be replaced
> + * by equal formats without alpha channel, as primary planes usually
> + * don't support alpha. Other heuristics might be applied to optimize
> + * the sorting order. Formats near the beginning of the list are usually
> + * preferred over formats near the end of the list.
> + *
> + * Returns:
> + * The number of color-formats 4CC codes returned in @fourccs_out.
> + */
> +size_t drm_sysfb_build_fourcc_list(struct drm_device *dev,
> +				   const u32 *native_fourccs, size_t native_nfourccs,
> +				   u32 *fourccs_out, size_t nfourccs_out)
> +{
> +	/*
> +	 * XRGB8888 is the default fallback format for most of userspace
> +	 * and it's currently the only format that should be emulated for
> +	 * the primary plane. Only if there's ever another default fallback,
> +	 * it should be added here.
> +	 */
> +	static const u32 extra_fourccs[] = {
> +		DRM_FORMAT_XRGB8888,
> +	};
> +	static const size_t extra_nfourccs = ARRAY_SIZE(extra_fourccs);
> +
> +	u32 *fourccs = fourccs_out;
> +	const u32 *fourccs_end = fourccs_out + nfourccs_out;
> +	size_t i;
> +
> +	/*
> +	 * The device's native formats go first.
> +	 */
> +
> +	for (i = 0; i < native_nfourccs; ++i) {
> +		/*
> +		 * Several DTs, boot loaders and firmware report native
> +		 * alpha formats that are non-alpha formats instead. So
> +		 * replace alpha formats by non-alpha formats.
> +		 */
> +		u32 fourcc = to_nonalpha_fourcc(native_fourccs[i]);
> +
> +		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
> +			continue; /* skip duplicate entries */
> +		} else if (fourccs == fourccs_end) {
> +			drm_warn(dev, "Ignoring native format %p4cc\n", &fourcc);
> +			continue; /* end of available output buffer */
> +		}
> +
> +		drm_dbg_kms(dev, "adding native format %p4cc\n", &fourcc);
> +
> +		*fourccs = fourcc;
> +		++fourccs;
> +	}
> +
> +	/*
> +	 * The extra formats, emulated by the driver, go second.
> +	 */
> +
> +	for (i = 0; (i < extra_nfourccs) && (fourccs < fourccs_end); ++i) {
> +		u32 fourcc = extra_fourccs[i];
> +
> +		if (is_listed_fourcc(fourccs_out, fourccs - fourccs_out, fourcc)) {
> +			continue; /* skip duplicate and native entries */
> +		} else if (fourccs == fourccs_end) {
> +			drm_warn(dev, "Ignoring emulated format %p4cc\n", &fourcc);
> +			continue; /* end of available output buffer */
> +		}
> +
> +		drm_dbg_kms(dev, "adding emulated format %p4cc\n", &fourcc);
> +
> +		*fourccs = fourcc;
> +		++fourccs;
> +	}
> +
> +	return fourccs - fourccs_out;
> +}
> +EXPORT_SYMBOL(drm_sysfb_build_fourcc_list);
> +
>  int drm_sysfb_plane_helper_atomic_check(struct drm_plane *plane,
>  					struct drm_atomic_state *new_state)
>  {
> diff --git a/drivers/gpu/drm/sysfb/efidrm.c b/drivers/gpu/drm/sysfb/efidrm.c
> index 46912924636a..9562f9dc7835 100644
> --- a/drivers/gpu/drm/sysfb/efidrm.c
> +++ b/drivers/gpu/drm/sysfb/efidrm.c
> @@ -271,8 +271,8 @@ static struct efidrm_device *efidrm_device_create(struct drm_driver *drv,
>  
>  	/* Primary plane */
>  
> -	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
> -					    efi->formats, ARRAY_SIZE(efi->formats));
> +	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
> +					       efi->formats, ARRAY_SIZE(efi->formats));
>  
>  	primary_plane = &efi->primary_plane;
>  	ret = drm_universal_plane_init(dev, primary_plane, 0, &efidrm_primary_plane_funcs,
> diff --git a/drivers/gpu/drm/sysfb/ofdrm.c b/drivers/gpu/drm/sysfb/ofdrm.c
> index c9415f0cb3ed..8d8ab39c5f36 100644
> --- a/drivers/gpu/drm/sysfb/ofdrm.c
> +++ b/drivers/gpu/drm/sysfb/ofdrm.c
> @@ -15,7 +15,6 @@
>  #include <drm/drm_drv.h>
>  #include <drm/drm_edid.h>
>  #include <drm/drm_fbdev_shmem.h>
> -#include <drm/drm_format_helper.h>
>  #include <drm/drm_framebuffer.h>
>  #include <drm/drm_gem_atomic_helper.h>
>  #include <drm/drm_gem_framebuffer_helper.h>
> @@ -1015,8 +1014,8 @@ static struct ofdrm_device *ofdrm_device_create(struct drm_driver *drv,
>  
>  	/* Primary plane */
>  
> -	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
> -					    odev->formats, ARRAY_SIZE(odev->formats));
> +	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
> +					       odev->formats, ARRAY_SIZE(odev->formats));
>  
>  	primary_plane = &odev->primary_plane;
>  	ret = drm_universal_plane_init(dev, primary_plane, 0, &ofdrm_primary_plane_funcs,
> diff --git a/drivers/gpu/drm/sysfb/simpledrm.c b/drivers/gpu/drm/sysfb/simpledrm.c
> index a1c3119330de..8530a3ef8a7a 100644
> --- a/drivers/gpu/drm/sysfb/simpledrm.c
> +++ b/drivers/gpu/drm/sysfb/simpledrm.c
> @@ -18,7 +18,6 @@
>  #include <drm/drm_device.h>
>  #include <drm/drm_drv.h>
>  #include <drm/drm_fbdev_shmem.h>
> -#include <drm/drm_format_helper.h>
>  #include <drm/drm_framebuffer.h>
>  #include <drm/drm_gem_atomic_helper.h>
>  #include <drm/drm_gem_framebuffer_helper.h>
> @@ -765,8 +764,8 @@ static struct simpledrm_device *simpledrm_device_create(struct drm_driver *drv,
>  
>  	/* Primary plane */
>  
> -	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
> -					    sdev->formats, ARRAY_SIZE(sdev->formats));
> +	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
> +					       sdev->formats, ARRAY_SIZE(sdev->formats));
>  
>  	primary_plane = &sdev->primary_plane;
>  	ret = drm_universal_plane_init(dev, primary_plane, 0, &simpledrm_primary_plane_funcs,
> diff --git a/drivers/gpu/drm/sysfb/vesadrm.c b/drivers/gpu/drm/sysfb/vesadrm.c
> index 7945544ba73e..86e0b88dd51b 100644
> --- a/drivers/gpu/drm/sysfb/vesadrm.c
> +++ b/drivers/gpu/drm/sysfb/vesadrm.c
> @@ -402,8 +402,8 @@ static struct vesadrm_device *vesadrm_device_create(struct drm_driver *drv,
>  
>  	/* Primary plane */
>  
> -	nformats = drm_fb_build_fourcc_list(dev, &format->format, 1,
> -					    vesa->formats, ARRAY_SIZE(vesa->formats));
> +	nformats = drm_sysfb_build_fourcc_list(dev, &format->format, 1,
> +					       vesa->formats, ARRAY_SIZE(vesa->formats));
>  
>  	primary_plane = &vesa->primary_plane;
>  	ret = drm_universal_plane_init(dev, primary_plane, 0, &vesadrm_primary_plane_funcs,
> diff --git a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
> index 88a4bf28c745..33acd3f02dc6 100644
> --- a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
> +++ b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
> @@ -2,10 +2,11 @@
>  
>  #include <kunit/test.h>
>  
> -#include <drm/drm_format_helper.h>
>  #include <drm/drm_fourcc.h>
>  #include <drm/drm_kunit_helpers.h>
>  
> +#include "../sysfb/drm_sysfb_helper.h"
> +
>  #define TEST_BUF_SIZE 50
>  
>  struct fb_build_fourcc_list_case {
> @@ -141,9 +142,9 @@ static void drm_test_fb_build_fourcc_list(struct kunit *test)
>  	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
>  	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
>  
> -	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
> -						params->native_fourccs_size,
> -						fourccs_out, TEST_BUF_SIZE);
> +	nfourccs_out = drm_sysfb_build_fourcc_list(drm, params->native_fourccs,
> +						   params->native_fourccs_size,
> +						   fourccs_out, TEST_BUF_SIZE);
>  
>  	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
>  	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
> diff --git a/include/drm/drm_format_helper.h b/include/drm/drm_format_helper.h
> index 49a2e09155d1..0d3ee2a1313f 100644
> --- a/include/drm/drm_format_helper.h
> +++ b/include/drm/drm_format_helper.h
> @@ -134,8 +134,4 @@ void drm_fb_xrgb8888_to_mono(struct iosys_map *dst, const unsigned int *dst_pitc
>  			     const struct iosys_map *src, const struct drm_framebuffer *fb,
>  			     const struct drm_rect *clip, struct drm_format_conv_state *state);
>  
> -size_t drm_fb_build_fourcc_list(struct drm_device *dev,
> -				const u32 *native_fourccs, size_t native_nfourccs,
> -				u32 *fourccs_out, size_t nfourccs_out);
> -
>  #endif /* __LINUX_DRM_FORMAT_HELPER_H */
> -- 
> 2.49.0
> 

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

* Re: [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite
  2025-06-13 14:03   ` José Expósito
@ 2025-06-13 15:41     ` Thomas Zimmermann
  0 siblings, 0 replies; 8+ messages in thread
From: Thomas Zimmermann @ 2025-06-13 15:41 UTC (permalink / raw)
  To: José Expósito
  Cc: arthurgrillo, javierm, maarten.lankhorst, mripard, dri-devel

Hi

Am 13.06.25 um 16:03 schrieb José Expósito:
> On Thu, Jun 12, 2025 at 03:52:23PM +0200, Thomas Zimmermann wrote:
>> Only sysfb drivers use drm_fb_build_fourcc_list(). The helper will
>> be moved from format helpers to sysfb helpers. Moving the related
>> tests to their own test suite.
>>
>> v2:
>> - rename filename to match tested code (Maxime)
>>
>> Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
>> Acked-by: Maxime Ripard <mripard@kernel.org>
>> ---
>>   drivers/gpu/drm/tests/Makefile                |   3 +-
>>   .../gpu/drm/tests/drm_format_helper_test.c    | 142 ---------------
>>   .../gpu/drm/tests/drm_sysfb_modeset_test.c    | 166 ++++++++++++++++++
>>   3 files changed, 168 insertions(+), 143 deletions(-)
>>   create mode 100644 drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
>>
>> diff --git a/drivers/gpu/drm/tests/Makefile b/drivers/gpu/drm/tests/Makefile
>> index 3afd6587df08..c0e952293ad0 100644
>> --- a/drivers/gpu/drm/tests/Makefile
>> +++ b/drivers/gpu/drm/tests/Makefile
>> @@ -23,6 +23,7 @@ obj-$(CONFIG_DRM_KUNIT_TEST) += \
>>   	drm_modes_test.o \
>>   	drm_plane_helper_test.o \
>>   	drm_probe_helper_test.o \
>> -	drm_rect_test.o
>> +	drm_rect_test.o \
>> +	drm_sysfb_modeset_test.o
>>   
>>   CFLAGS_drm_mm_test.o := $(DISABLE_STRUCTLEAK_PLUGIN)
>> diff --git a/drivers/gpu/drm/tests/drm_format_helper_test.c b/drivers/gpu/drm/tests/drm_format_helper_test.c
>> index 8aacc1ffa93a..ef1cc3b28f1b 100644
>> --- a/drivers/gpu/drm/tests/drm_format_helper_test.c
>> +++ b/drivers/gpu/drm/tests/drm_format_helper_test.c
>> @@ -1335,147 +1335,6 @@ static void drm_test_fb_clip_offset(struct kunit *test)
>>   	KUNIT_EXPECT_EQ(test, offset, params->expected_offset);
>>   }
>>   
>> -struct fb_build_fourcc_list_case {
>> -	const char *name;
>> -	u32 native_fourccs[TEST_BUF_SIZE];
>> -	size_t native_fourccs_size;
>> -	u32 expected[TEST_BUF_SIZE];
>> -	size_t expected_fourccs_size;
>> -};
>> -
>> -static struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
>> -	{
>> -		.name = "no native formats",
>> -		.native_fourccs = { },
>> -		.native_fourccs_size = 0,
>> -		.expected = { DRM_FORMAT_XRGB8888 },
>> -		.expected_fourccs_size = 1,
>> -	},
>> -	{
>> -		.name = "XRGB8888 as native format",
>> -		.native_fourccs = { DRM_FORMAT_XRGB8888 },
>> -		.native_fourccs_size = 1,
>> -		.expected = { DRM_FORMAT_XRGB8888 },
>> -		.expected_fourccs_size = 1,
>> -	},
>> -	{
>> -		.name = "remove duplicates",
>> -		.native_fourccs = {
>> -			DRM_FORMAT_XRGB8888,
>> -			DRM_FORMAT_XRGB8888,
>> -			DRM_FORMAT_RGB888,
>> -			DRM_FORMAT_RGB888,
>> -			DRM_FORMAT_RGB888,
>> -			DRM_FORMAT_XRGB8888,
>> -			DRM_FORMAT_RGB888,
>> -			DRM_FORMAT_RGB565,
>> -			DRM_FORMAT_RGB888,
>> -			DRM_FORMAT_XRGB8888,
>> -			DRM_FORMAT_RGB565,
>> -			DRM_FORMAT_RGB565,
>> -			DRM_FORMAT_XRGB8888,
>> -		},
>> -		.native_fourccs_size = 11,
>> -		.expected = {
>> -			DRM_FORMAT_XRGB8888,
>> -			DRM_FORMAT_RGB888,
>> -			DRM_FORMAT_RGB565,
>> -		},
>> -		.expected_fourccs_size = 3,
>> -	},
>> -	{
>> -		.name = "convert alpha formats",
>> -		.native_fourccs = {
>> -			DRM_FORMAT_ARGB1555,
>> -			DRM_FORMAT_ABGR1555,
>> -			DRM_FORMAT_RGBA5551,
>> -			DRM_FORMAT_BGRA5551,
>> -			DRM_FORMAT_ARGB8888,
>> -			DRM_FORMAT_ABGR8888,
>> -			DRM_FORMAT_RGBA8888,
>> -			DRM_FORMAT_BGRA8888,
>> -			DRM_FORMAT_ARGB2101010,
>> -			DRM_FORMAT_ABGR2101010,
>> -			DRM_FORMAT_RGBA1010102,
>> -			DRM_FORMAT_BGRA1010102,
>> -		},
>> -		.native_fourccs_size = 12,
>> -		.expected = {
>> -			DRM_FORMAT_XRGB1555,
>> -			DRM_FORMAT_XBGR1555,
>> -			DRM_FORMAT_RGBX5551,
>> -			DRM_FORMAT_BGRX5551,
>> -			DRM_FORMAT_XRGB8888,
>> -			DRM_FORMAT_XBGR8888,
>> -			DRM_FORMAT_RGBX8888,
>> -			DRM_FORMAT_BGRX8888,
>> -			DRM_FORMAT_XRGB2101010,
>> -			DRM_FORMAT_XBGR2101010,
>> -			DRM_FORMAT_RGBX1010102,
>> -			DRM_FORMAT_BGRX1010102,
>> -		},
>> -		.expected_fourccs_size = 12,
>> -	},
>> -	{
>> -		.name = "random formats",
>> -		.native_fourccs = {
>> -			DRM_FORMAT_Y212,
>> -			DRM_FORMAT_ARGB1555,
>> -			DRM_FORMAT_ABGR16161616F,
>> -			DRM_FORMAT_C8,
>> -			DRM_FORMAT_BGR888,
>> -			DRM_FORMAT_XRGB1555,
>> -			DRM_FORMAT_RGBA5551,
>> -			DRM_FORMAT_BGR565_A8,
>> -			DRM_FORMAT_R10,
>> -			DRM_FORMAT_XYUV8888,
>> -		},
>> -		.native_fourccs_size = 10,
>> -		.expected = {
>> -			DRM_FORMAT_Y212,
>> -			DRM_FORMAT_XRGB1555,
>> -			DRM_FORMAT_ABGR16161616F,
>> -			DRM_FORMAT_C8,
>> -			DRM_FORMAT_BGR888,
>> -			DRM_FORMAT_RGBX5551,
>> -			DRM_FORMAT_BGR565_A8,
>> -			DRM_FORMAT_R10,
>> -			DRM_FORMAT_XYUV8888,
>> -			DRM_FORMAT_XRGB8888,
>> -		},
>> -		.expected_fourccs_size = 10,
>> -	},
>> -};
>> -
>> -static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
>> -{
>> -	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
>> -}
>> -
>> -KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
>> -
>> -static void drm_test_fb_build_fourcc_list(struct kunit *test)
>> -{
>> -	const struct fb_build_fourcc_list_case *params = test->param_value;
>> -	u32 fourccs_out[TEST_BUF_SIZE] = {0};
>> -	size_t nfourccs_out;
>> -	struct drm_device *drm;
>> -	struct device *dev;
>> -
>> -	dev = drm_kunit_helper_alloc_device(test);
>> -	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
>> -
>> -	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
>> -	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
>> -
>> -	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
>> -						params->native_fourccs_size,
>> -						fourccs_out, TEST_BUF_SIZE);
>> -
>> -	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
>> -	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
>> -}
>> -
>>   struct fb_memcpy_case {
>>   	const char *name;
>>   	u32 format;
>> @@ -1864,7 +1723,6 @@ static struct kunit_case drm_format_helper_test_cases[] = {
>>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_xbgr8888, convert_xrgb8888_gen_params),
>>   	KUNIT_CASE_PARAM(drm_test_fb_xrgb8888_to_abgr8888, convert_xrgb8888_gen_params),
>>   	KUNIT_CASE_PARAM(drm_test_fb_clip_offset, clip_offset_gen_params),
>> -	KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
>>   	KUNIT_CASE_PARAM(drm_test_fb_memcpy, fb_memcpy_gen_params),
>>   	{}
>>   };
>> diff --git a/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
>> new file mode 100644
>> index 000000000000..88a4bf28c745
>> --- /dev/null
>> +++ b/drivers/gpu/drm/tests/drm_sysfb_modeset_test.c
>> @@ -0,0 +1,166 @@
>> +// SPDX-License-Identifier: GPL-2.0+
>> +
>> +#include <kunit/test.h>
>> +
>> +#include <drm/drm_format_helper.h>
>> +#include <drm/drm_fourcc.h>
>> +#include <drm/drm_kunit_helpers.h>
>> +
>> +#define TEST_BUF_SIZE 50
>> +
>> +struct fb_build_fourcc_list_case {
>> +	const char *name;
>> +	u32 native_fourccs[TEST_BUF_SIZE];
>> +	size_t native_fourccs_size;
>> +	u32 expected[TEST_BUF_SIZE];
>> +	size_t expected_fourccs_size;
>> +};
>> +
>> +static struct fb_build_fourcc_list_case fb_build_fourcc_list_cases[] = {
>> +	{
>> +		.name = "no native formats",
>> +		.native_fourccs = { },
>> +		.native_fourccs_size = 0,
>> +		.expected = { DRM_FORMAT_XRGB8888 },
>> +		.expected_fourccs_size = 1,
>> +	},
>> +	{
>> +		.name = "XRGB8888 as native format",
>> +		.native_fourccs = { DRM_FORMAT_XRGB8888 },
>> +		.native_fourccs_size = 1,
>> +		.expected = { DRM_FORMAT_XRGB8888 },
>> +		.expected_fourccs_size = 1,
>> +	},
>> +	{
>> +		.name = "remove duplicates",
>> +		.native_fourccs = {
>> +			DRM_FORMAT_XRGB8888,
>> +			DRM_FORMAT_XRGB8888,
>> +			DRM_FORMAT_RGB888,
>> +			DRM_FORMAT_RGB888,
>> +			DRM_FORMAT_RGB888,
>> +			DRM_FORMAT_XRGB8888,
>> +			DRM_FORMAT_RGB888,
>> +			DRM_FORMAT_RGB565,
>> +			DRM_FORMAT_RGB888,
>> +			DRM_FORMAT_XRGB8888,
>> +			DRM_FORMAT_RGB565,
>> +			DRM_FORMAT_RGB565,
>> +			DRM_FORMAT_XRGB8888,
>> +		},
>> +		.native_fourccs_size = 11,
>> +		.expected = {
>> +			DRM_FORMAT_XRGB8888,
>> +			DRM_FORMAT_RGB888,
>> +			DRM_FORMAT_RGB565,
>> +		},
>> +		.expected_fourccs_size = 3,
>> +	},
>> +	{
>> +		.name = "convert alpha formats",
>> +		.native_fourccs = {
>> +			DRM_FORMAT_ARGB1555,
>> +			DRM_FORMAT_ABGR1555,
>> +			DRM_FORMAT_RGBA5551,
>> +			DRM_FORMAT_BGRA5551,
>> +			DRM_FORMAT_ARGB8888,
>> +			DRM_FORMAT_ABGR8888,
>> +			DRM_FORMAT_RGBA8888,
>> +			DRM_FORMAT_BGRA8888,
>> +			DRM_FORMAT_ARGB2101010,
>> +			DRM_FORMAT_ABGR2101010,
>> +			DRM_FORMAT_RGBA1010102,
>> +			DRM_FORMAT_BGRA1010102,
>> +		},
>> +		.native_fourccs_size = 12,
>> +		.expected = {
>> +			DRM_FORMAT_XRGB1555,
>> +			DRM_FORMAT_XBGR1555,
>> +			DRM_FORMAT_RGBX5551,
>> +			DRM_FORMAT_BGRX5551,
>> +			DRM_FORMAT_XRGB8888,
>> +			DRM_FORMAT_XBGR8888,
>> +			DRM_FORMAT_RGBX8888,
>> +			DRM_FORMAT_BGRX8888,
>> +			DRM_FORMAT_XRGB2101010,
>> +			DRM_FORMAT_XBGR2101010,
>> +			DRM_FORMAT_RGBX1010102,
>> +			DRM_FORMAT_BGRX1010102,
>> +		},
>> +		.expected_fourccs_size = 12,
>> +	},
>> +	{
>> +		.name = "random formats",
>> +		.native_fourccs = {
>> +			DRM_FORMAT_Y212,
>> +			DRM_FORMAT_ARGB1555,
>> +			DRM_FORMAT_ABGR16161616F,
>> +			DRM_FORMAT_C8,
>> +			DRM_FORMAT_BGR888,
>> +			DRM_FORMAT_XRGB1555,
>> +			DRM_FORMAT_RGBA5551,
>> +			DRM_FORMAT_BGR565_A8,
>> +			DRM_FORMAT_R10,
>> +			DRM_FORMAT_XYUV8888,
>> +		},
>> +		.native_fourccs_size = 10,
>> +		.expected = {
>> +			DRM_FORMAT_Y212,
>> +			DRM_FORMAT_XRGB1555,
>> +			DRM_FORMAT_ABGR16161616F,
>> +			DRM_FORMAT_C8,
>> +			DRM_FORMAT_BGR888,
>> +			DRM_FORMAT_RGBX5551,
>> +			DRM_FORMAT_BGR565_A8,
>> +			DRM_FORMAT_R10,
>> +			DRM_FORMAT_XYUV8888,
>> +			DRM_FORMAT_XRGB8888,
>> +		},
>> +		.expected_fourccs_size = 10,
>> +	},
>> +};
>> +
>> +static void fb_build_fourcc_list_case_desc(struct fb_build_fourcc_list_case *t, char *desc)
>> +{
>> +	strscpy(desc, t->name, KUNIT_PARAM_DESC_SIZE);
>> +}
>> +
>> +KUNIT_ARRAY_PARAM(fb_build_fourcc_list, fb_build_fourcc_list_cases, fb_build_fourcc_list_case_desc);
>> +
>> +static void drm_test_fb_build_fourcc_list(struct kunit *test)
>> +{
>> +	const struct fb_build_fourcc_list_case *params = test->param_value;
>> +	u32 fourccs_out[TEST_BUF_SIZE] = {0};
>> +	size_t nfourccs_out;
>> +	struct drm_device *drm;
>> +	struct device *dev;
>> +
>> +	dev = drm_kunit_helper_alloc_device(test);
>> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, dev);
>> +
>> +	drm = __drm_kunit_helper_alloc_drm_device(test, dev, sizeof(*drm), 0, DRIVER_MODESET);
>> +	KUNIT_ASSERT_NOT_ERR_OR_NULL(test, drm);
>> +
>> +	nfourccs_out = drm_fb_build_fourcc_list(drm, params->native_fourccs,
>> +						params->native_fourccs_size,
>> +						fourccs_out, TEST_BUF_SIZE);
>> +
>> +	KUNIT_EXPECT_EQ(test, nfourccs_out, params->expected_fourccs_size);
>> +	KUNIT_EXPECT_MEMEQ(test, fourccs_out, params->expected, TEST_BUF_SIZE);
>> +}
>> +
>> +static struct kunit_case drm_sysfb_helper_test_cases[] = {
>> +	KUNIT_CASE_PARAM(drm_test_fb_build_fourcc_list, fb_build_fourcc_list_gen_params),
>> +	{}
>> +};
>> +
>> +static struct kunit_suite drm_sysfb_helper_test_suite = {
>> +	.name = "drm_sysfb_helper_test",
> Other tests use the same name as the file live in, dropping or not
> the "_test" suffix.
>
> Is this a missing change from the rename in v1?

I renamed the source file as suggested in an earlier rename, but forgot 
about those names. Sorry, I'm not really familiar with the conventions 
here. I'll fix this in the next iteration. Thanks for reviewing.

Best regards
Thomas

>
> Other than that:
>
> Reviewed-by: José Expósito <jose.exposito89@gmail.com>
>
>> +	.test_cases = drm_sysfb_helper_test_cases,
>> +};
>> +
>> +kunit_test_suite(drm_sysfb_helper_test_suite);
>> +
>> +MODULE_DESCRIPTION("KUnit tests for the drm_sysfb_helper APIs");
>> +MODULE_LICENSE("GPL");
>> +MODULE_AUTHOR("José Expósito <jose.exposito89@gmail.com>");
>> -- 
>> 2.49.0
>>

-- 
--
Thomas Zimmermann
Graphics Driver Developer
SUSE Software Solutions Germany GmbH
Frankenstrasse 146, 90461 Nuernberg, Germany
GF: Ivo Totev, Andrew Myers, Andrew McDonald, Boudien Moerman
HRB 36809 (AG Nuernberg)


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

end of thread, other threads:[~2025-06-13 15:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-06-12 13:52 [PATCH v2 0/3] drm/tests: Update format-helper tests for sysfb Thomas Zimmermann
2025-06-12 13:52 ` [PATCH v2 1/3] drm/tests: Do not use drm_fb_blit() in format-helper tests Thomas Zimmermann
2025-06-13 14:00   ` José Expósito
2025-06-12 13:52 ` [PATCH v2 2/3] drm/tests: Test drm_fb_build_fourcc_list() in separate test suite Thomas Zimmermann
2025-06-13 14:03   ` José Expósito
2025-06-13 15:41     ` Thomas Zimmermann
2025-06-12 13:52 ` [PATCH v2 3/3] drm/format-helper: Move drm_fb_build_fourcc_list() to sysfb helpers Thomas Zimmermann
2025-06-13 14:53   ` José Expósito

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).