drm/format-helper: Pass destination pitch to drm_fb_memcpy_dstclip()
authorThomas Zimmermann <tzimmermann@suse.de>
Fri, 30 Apr 2021 10:58:32 +0000 (12:58 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Sat, 1 May 2021 10:45:03 +0000 (12:45 +0200)
The memcpy's destination buffer might have a different pitch than the
source. Support different pitches as function argument.

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Acked-by: Maxime Ripard <maxime@cerno.tech>
Tested-by: nerdopolis <bluescreen_avenger@verizon.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20210430105840.30515-2-tzimmermann@suse.de
drivers/gpu/drm/drm_format_helper.c
drivers/gpu/drm/mgag200/mgag200_mode.c
drivers/gpu/drm/tiny/cirrus.c
include/drm/drm_format_helper.h

index c043ca3..8d5a683 100644 (file)
@@ -52,6 +52,7 @@ EXPORT_SYMBOL(drm_fb_memcpy);
 /**
  * drm_fb_memcpy_dstclip - Copy clip buffer
  * @dst: Destination buffer (iomem)
+ * @dst_pitch: Number of bytes between two consecutive scanlines within dst
  * @vaddr: Source buffer
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
@@ -59,12 +60,12 @@ EXPORT_SYMBOL(drm_fb_memcpy);
  * This function applies clipping on dst, i.e. the destination is a
  * full (iomem) framebuffer but only the clip rect content is copied over.
  */
-void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
-                          struct drm_framebuffer *fb,
+void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch,
+                          void *vaddr, struct drm_framebuffer *fb,
                           struct drm_rect *clip)
 {
        unsigned int cpp = fb->format->cpp[0];
-       unsigned int offset = clip_offset(clip, fb->pitches[0], cpp);
+       unsigned int offset = clip_offset(clip, dst_pitch, cpp);
        size_t len = (clip->x2 - clip->x1) * cpp;
        unsigned int y, lines = clip->y2 - clip->y1;
 
@@ -73,7 +74,7 @@ void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
        for (y = 0; y < lines; y++) {
                memcpy_toio(dst, vaddr, len);
                vaddr += fb->pitches[0];
-               dst += fb->pitches[0];
+               dst += dst_pitch;
        }
 }
 EXPORT_SYMBOL(drm_fb_memcpy_dstclip);
index cece3e5..9d57624 100644 (file)
@@ -1554,7 +1554,7 @@ mgag200_handle_damage(struct mga_device *mdev, struct drm_framebuffer *fb,
 {
        void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
 
-       drm_fb_memcpy_dstclip(mdev->vram, vmap, fb, clip);
+       drm_fb_memcpy_dstclip(mdev->vram, fb->pitches[0], vmap, fb, clip);
 
        /* Always scanout image at VRAM offset 0 */
        mgag200_set_startadd(mdev, (u32)0);
index e3afb45..42611da 100644 (file)
@@ -324,7 +324,7 @@ static int cirrus_fb_blit_rect(struct drm_framebuffer *fb, const struct dma_buf_
                return -ENODEV;
 
        if (cirrus->cpp == fb->format->cpp[0])
-               drm_fb_memcpy_dstclip(cirrus->vram,
+               drm_fb_memcpy_dstclip(cirrus->vram, fb->pitches[0],
                                      vmap, fb, rect);
 
        else if (fb->format->cpp[0] == 4 && cirrus->cpp == 2)
index 5f9e370..2b5036a 100644 (file)
@@ -11,7 +11,7 @@ struct drm_rect;
 
 void drm_fb_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb,
                   struct drm_rect *clip);
-void drm_fb_memcpy_dstclip(void __iomem *dst, void *vaddr,
+void drm_fb_memcpy_dstclip(void __iomem *dst, unsigned int dst_pitch, void *vaddr,
                           struct drm_framebuffer *fb,
                           struct drm_rect *clip);
 void drm_fb_swab(void *dst, void *src, struct drm_framebuffer *fb,