drm/format-helper: Add destination-buffer pitch to drm_fb_swab()
authorThomas Zimmermann <tzimmermann@suse.de>
Wed, 10 Nov 2021 10:36:56 +0000 (11:36 +0100)
committerThomas Zimmermann <tzimmermann@suse.de>
Thu, 11 Nov 2021 11:06:57 +0000 (12:06 +0100)
Add destination-buffer pitch as argument to drm_fb_swab(). Done for
consistency with the rest of the interface.

v2:
* update documentation (Noralf)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Tested-by: Noralf Trønnes <noralf@tronnes.org>
Reviewed-by: Noralf Trønnes <noralf@tronnes.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20211110103702.374-4-tzimmermann@suse.de
drivers/gpu/drm/drm_format_helper.c
drivers/gpu/drm/drm_mipi_dbi.c
drivers/gpu/drm/gud/gud_pipe.c
include/drm/drm_format_helper.h

index 32b4c9c..c6d4e78 100644 (file)
@@ -101,6 +101,7 @@ EXPORT_SYMBOL(drm_fb_memcpy_toio);
 /**
  * drm_fb_swab - Swap bytes into clip buffer
  * @dst: Destination buffer
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @src: Source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
@@ -110,21 +111,27 @@ EXPORT_SYMBOL(drm_fb_memcpy_toio);
  * time to speed up slow uncached reads.
  *
  * This function does not apply clipping on dst, i.e. the destination
- * is a small buffer containing the clip rect only.
+ * is at the top-left corner.
  */
-void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
-                struct drm_rect *clip, bool cached)
+void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
+                const struct drm_framebuffer *fb, const struct drm_rect *clip,
+                bool cached)
 {
        u8 cpp = fb->format->cpp[0];
        size_t len = drm_rect_width(clip) * cpp;
-       u16 *src16, *dst16 = dst;
-       u32 *src32, *dst32 = dst;
+       const u16 *src16;
+       const u32 *src32;
+       u16 *dst16;
+       u32 *dst32;
        unsigned int x, y;
        void *buf = NULL;
 
        if (WARN_ON_ONCE(cpp != 2 && cpp != 4))
                return;
 
+       if (!dst_pitch)
+               dst_pitch = len;
+
        if (!cached)
                buf = kmalloc(len, GFP_KERNEL);
 
@@ -140,6 +147,9 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
                        src32 = src;
                }
 
+               dst16 = dst;
+               dst32 = dst;
+
                for (x = clip->x1; x < clip->x2; x++) {
                        if (cpp == 4)
                                *dst32++ = swab32(*src32++);
@@ -148,6 +158,7 @@ void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
                }
 
                src += fb->pitches[0];
+               dst += dst_pitch;
        }
 
        kfree(buf);
index c09df8b..7ce8991 100644 (file)
@@ -211,7 +211,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
        switch (fb->format->format) {
        case DRM_FORMAT_RGB565:
                if (swap)
-                       drm_fb_swab(dst, src, fb, clip, !gem->import_attach);
+                       drm_fb_swab(dst, 0, src, fb, clip, !gem->import_attach);
                else
                        drm_fb_memcpy(dst, 0, src, fb, clip);
                break;
index a92112f..e0b117b 100644 (file)
@@ -201,7 +201,7 @@ retry:
                        len = gud_xrgb8888_to_color(buf, format, vaddr, fb, rect);
                }
        } else if (gud_is_big_endian() && format->cpp[0] > 1) {
-               drm_fb_swab(buf, vaddr, fb, rect, !import_attach);
+               drm_fb_swab(buf, 0, vaddr, fb, rect, !import_attach);
        } else if (compression && !import_attach && pitch == fb->pitches[0]) {
                /* can compress directly from the framebuffer */
                buf = vaddr + rect->y1 * pitch;
index 1fc3ba7..ddcba5a 100644 (file)
@@ -17,8 +17,9 @@ void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const void *vaddr,
                   const struct drm_framebuffer *fb, const struct drm_rect *clip);
 void drm_fb_memcpy_toio(void __iomem *dst, unsigned int dst_pitch, const void *vaddr,
                        const struct drm_framebuffer *fb, const struct drm_rect *clip);
-void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,
-                struct drm_rect *clip, bool cached);
+void drm_fb_swab(void *dst, unsigned int dst_pitch, const void *src,
+                const struct drm_framebuffer *fb, const struct drm_rect *clip,
+                bool cached);
 void drm_fb_xrgb8888_to_rgb332(void *dst, void *vaddr, struct drm_framebuffer *fb,
                               struct drm_rect *clip);
 void drm_fb_xrgb8888_to_rgb565(void *dst, void *vaddr,