]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
drm/format-helper: Add generic conversion to 32-bit formats
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 28 Mar 2025 14:14:58 +0000 (15:14 +0100)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Thu, 28 Aug 2025 14:31:12 +0000 (16:31 +0200)
[ Upstream commit d55d0b066f4eedf030c9c1a67a2a0abffece3abc ]

Add drm_fb_xfrm_line_32to32() to implement conversion from 32-bit
pixels to 32-bit pixels. The pixel-conversion is specified by the
given callback parameter. Mark the helper as always_inline to avoid
overhead from function calls.

Then implement all existing line-conversion functions with the new
generic call and the respective pixel-conversion helper.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Jocelyn Falempe <jfalempe@redhat.com>
Link: https://lore.kernel.org/r/20250328141709.217283-3-tzimmermann@suse.de
Stable-dep-of: 05663d88fd0b ("drm/tests: Fix drm_test_fb_xrgb8888_to_xrgb2101010() on big-endian")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/gpu/drm/drm_format_helper.c

index 4f60c8d8f63e6c1c71c63f33ded6971dc3a5f790..4dcb78895581c8bbf22f100833b6f8ab5faf78df 100644 (file)
@@ -20,6 +20,8 @@
 #include <drm/drm_print.h>
 #include <drm/drm_rect.h>
 
+#include "drm_format_internal.h"
+
 /**
  * drm_format_conv_state_init - Initialize format-conversion state
  * @state: The state to initialize
@@ -244,6 +246,18 @@ static int drm_fb_xfrm(struct iosys_map *dst,
                                     xfrm_line);
 }
 
+static __always_inline void drm_fb_xfrm_line_32to32(void *dbuf, const void *sbuf,
+                                                   unsigned int pixels,
+                                                   u32 (*xfrm_pixel)(u32))
+{
+       __le32 *dbuf32 = dbuf;
+       const __le32 *sbuf32 = sbuf;
+       const __le32 *send32 = sbuf32 + pixels;
+
+       while (sbuf32 < send32)
+               *dbuf32++ = cpu_to_le32(xfrm_pixel(le32_to_cpup(sbuf32++)));
+}
+
 /**
  * drm_fb_memcpy - Copy clip buffer
  * @dst: Array of destination buffers
@@ -755,16 +769,7 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_bgr888);
 
 static void drm_fb_xrgb8888_to_argb8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
-       __le32 *dbuf32 = dbuf;
-       const __le32 *sbuf32 = sbuf;
-       unsigned int x;
-       u32 pix;
-
-       for (x = 0; x < pixels; x++) {
-               pix = le32_to_cpu(sbuf32[x]);
-               pix |= GENMASK(31, 24); /* fill alpha bits */
-               dbuf32[x] = cpu_to_le32(pix);
-       }
+       drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_argb8888);
 }
 
 /**
@@ -804,19 +809,7 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_argb8888);
 
 static void drm_fb_xrgb8888_to_abgr8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
-       __le32 *dbuf32 = dbuf;
-       const __le32 *sbuf32 = sbuf;
-       unsigned int x;
-       u32 pix;
-
-       for (x = 0; x < pixels; x++) {
-               pix = le32_to_cpu(sbuf32[x]);
-               pix = ((pix & 0x00ff0000) >> 16) <<  0 |
-                     ((pix & 0x0000ff00) >>  8) <<  8 |
-                     ((pix & 0x000000ff) >>  0) << 16 |
-                     GENMASK(31, 24); /* fill alpha bits */
-               *dbuf32++ = cpu_to_le32(pix);
-       }
+       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,
@@ -835,19 +828,7 @@ static void drm_fb_xrgb8888_to_abgr8888(struct iosys_map *dst, const unsigned in
 
 static void drm_fb_xrgb8888_to_xbgr8888_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
-       __le32 *dbuf32 = dbuf;
-       const __le32 *sbuf32 = sbuf;
-       unsigned int x;
-       u32 pix;
-
-       for (x = 0; x < pixels; x++) {
-               pix = le32_to_cpu(sbuf32[x]);
-               pix = ((pix & 0x00ff0000) >> 16) <<  0 |
-                     ((pix & 0x0000ff00) >>  8) <<  8 |
-                     ((pix & 0x000000ff) >>  0) << 16 |
-                     ((pix & 0xff000000) >> 24) << 24;
-               *dbuf32++ = cpu_to_le32(pix);
-       }
+       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,
@@ -866,20 +847,7 @@ static void drm_fb_xrgb8888_to_xbgr8888(struct iosys_map *dst, const unsigned in
 
 static void drm_fb_xrgb8888_to_xrgb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
-       __le32 *dbuf32 = dbuf;
-       const __le32 *sbuf32 = sbuf;
-       unsigned int x;
-       u32 val32;
-       u32 pix;
-
-       for (x = 0; x < pixels; x++) {
-               pix = le32_to_cpu(sbuf32[x]);
-               val32 = ((pix & 0x000000FF) << 2) |
-                       ((pix & 0x0000FF00) << 4) |
-                       ((pix & 0x00FF0000) << 6);
-               pix = val32 | ((val32 >> 8) & 0x00300C03);
-               *dbuf32++ = cpu_to_le32(pix);
-       }
+       drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_xrgb2101010);
 }
 
 /**
@@ -920,21 +888,7 @@ EXPORT_SYMBOL(drm_fb_xrgb8888_to_xrgb2101010);
 
 static void drm_fb_xrgb8888_to_argb2101010_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
-       __le32 *dbuf32 = dbuf;
-       const __le32 *sbuf32 = sbuf;
-       unsigned int x;
-       u32 val32;
-       u32 pix;
-
-       for (x = 0; x < pixels; x++) {
-               pix = le32_to_cpu(sbuf32[x]);
-               val32 = ((pix & 0x000000ff) << 2) |
-                       ((pix & 0x0000ff00) << 4) |
-                       ((pix & 0x00ff0000) << 6);
-               pix = GENMASK(31, 30) | /* set alpha bits */
-                     val32 | ((val32 >> 8) & 0x00300c03);
-               *dbuf32++ = cpu_to_le32(pix);
-       }
+       drm_fb_xfrm_line_32to32(dbuf, sbuf, pixels, drm_pixel_xrgb8888_to_argb2101010);
 }
 
 /**