]> git.baikalelectronics.ru Git - kernel.git/commitdiff
drm/format-helper: Merge drm_fb_memcpy() and drm_fb_memcpy_toio()
authorThomas Zimmermann <tzimmermann@suse.de>
Mon, 8 Aug 2022 12:53:55 +0000 (14:53 +0200)
committerThomas Zimmermann <tzimmermann@suse.de>
Wed, 10 Aug 2022 07:15:51 +0000 (09:15 +0200)
Merge drm_fb_memcpy() and drm_fb_memcpy_toio() into a drm_fb_memcpy()
that uses struct iosys_map for buffers. The new function also supports
multi-plane color formats. Convert all users of the original helpers.

v2:
* rebase onto refactored mgag200
* use drm_formap_info_bpp() (Sam)
* do static init in hyperv and mgag200 (Sam)
* update documentation (Sam)
* add TODO on vaddr location (Sam)

Signed-off-by: Thomas Zimmermann <tzimmermann@suse.de>
Reviewed-by: Sam Ravnborg <sam@ravnborg.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20220808125406.20752-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
drivers/gpu/drm/hyperv/hyperv_drm_modeset.c
drivers/gpu/drm/mgag200/mgag200_mode.c
drivers/gpu/drm/tiny/cirrus.c
include/drm/drm_format_helper.h

index 07f329f607a32efa4f7707add079d865248a15d4..7489c665a47c0e65254accc214720b64f8c2aa8e 100644 (file)
@@ -131,63 +131,57 @@ static int drm_fb_xfrm_toio(void __iomem *dst, unsigned long dst_pitch, unsigned
 
 /**
  * drm_fb_memcpy - Copy clip buffer
- * @dst: Destination buffer
- * @dst_pitch: Number of bytes between two consecutive scanlines within dst
- * @vaddr: Source buffer
+ * @dst: Array of 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.
+ * @vmap: Array of source buffers
  * @fb: DRM framebuffer
  * @clip: Clip rectangle area to copy
  *
- * This function does not apply clipping on dst, i.e. the destination
- * is at the top-left corner.
- */
-void drm_fb_memcpy(void *dst, unsigned int dst_pitch, const void *vaddr,
-                  const struct drm_framebuffer *fb, const struct drm_rect *clip)
-{
-       unsigned int cpp = fb->format->cpp[0];
-       size_t len = (clip->x2 - clip->x1) * cpp;
-       unsigned int y, lines = clip->y2 - clip->y1;
-
-       if (!dst_pitch)
-               dst_pitch = len;
-
-       vaddr += clip_offset(clip, fb->pitches[0], cpp);
-       for (y = 0; y < lines; y++) {
-               memcpy(dst, vaddr, len);
-               vaddr += fb->pitches[0];
-               dst += dst_pitch;
-       }
-}
-EXPORT_SYMBOL(drm_fb_memcpy);
-
-/**
- * drm_fb_memcpy_toio - 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
+ * This function copies parts of a framebuffer to display memory. Destination and
+ * framebuffer formats must match. No conversion takes place. The parameters @dst,
+ * @dst_pitch and @vmap 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.
+ * This function does not apply clipping on @dst (i.e. the destination is at the
+ * top-left corner).
  */
-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_memcpy(struct iosys_map *dst, const unsigned int *dst_pitch,
+                  const struct iosys_map *vmap, const struct drm_framebuffer *fb,
+                  const struct drm_rect *clip)
 {
-       unsigned int cpp = fb->format->cpp[0];
-       size_t len = (clip->x2 - clip->x1) * cpp;
-       unsigned int y, lines = clip->y2 - clip->y1;
+       static const unsigned int default_dst_pitch[DRM_FORMAT_MAX_PLANES] = {
+               0, 0, 0, 0
+       };
 
-       if (!dst_pitch)
-               dst_pitch = len;
+       const struct drm_format_info *format = fb->format;
+       unsigned int i, y, lines = drm_rect_height(clip);
 
-       vaddr += clip_offset(clip, fb->pitches[0], cpp);
-       for (y = 0; y < lines; y++) {
-               memcpy_toio(dst, vaddr, len);
-               vaddr += fb->pitches[0];
-               dst += dst_pitch;
+       if (!dst_pitch)
+               dst_pitch = default_dst_pitch;
+
+       for (i = 0; i < format->num_planes; ++i) {
+               unsigned int bpp_i = drm_format_info_bpp(format, i);
+               unsigned int cpp_i = DIV_ROUND_UP(bpp_i, 8);
+               size_t len_i = DIV_ROUND_UP(drm_rect_width(clip) * bpp_i, 8);
+               unsigned int dst_pitch_i = dst_pitch[i];
+               struct iosys_map dst_i = dst[i];
+               struct iosys_map vmap_i = vmap[i];
+
+               if (!dst_pitch_i)
+                       dst_pitch_i = len_i;
+
+               iosys_map_incr(&vmap_i, clip_offset(clip, fb->pitches[i], cpp_i));
+               for (y = 0; y < lines; y++) {
+                       /* TODO: handle vmap_i in I/O memory here */
+                       iosys_map_memcpy_to(&dst_i, 0, vmap_i.vaddr, len_i);
+                       iosys_map_incr(&vmap_i, fb->pitches[i]);
+                       iosys_map_incr(&dst_i, dst_pitch_i);
+               }
        }
 }
-EXPORT_SYMBOL(drm_fb_memcpy_toio);
+EXPORT_SYMBOL(drm_fb_memcpy);
 
 static void drm_fb_swab16_line(void *dbuf, const void *sbuf, unsigned int pixels)
 {
@@ -587,7 +581,7 @@ int drm_fb_blit(struct iosys_map *dst, const unsigned int *dst_pitch, uint32_t d
                dst_format = DRM_FORMAT_XRGB2101010;
 
        if (dst_format == fb_format) {
-               drm_fb_memcpy_toio(dst[0].vaddr_iomem, dst_pitch[0], vmap[0].vaddr, fb, clip);
+               drm_fb_memcpy(dst, dst_pitch, vmap, fb, clip);
                return 0;
 
        } else if (dst_format == DRM_FORMAT_RGB565) {
index 2ecaf3cb7afb36984d2eac57bb3c28d6837697e6..1ba506ca83e172192a7abe5d7e41a86bafab2fb6 100644 (file)
@@ -205,6 +205,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
        struct drm_gem_object *gem = drm_gem_fb_get_obj(fb, 0);
        struct iosys_map map[DRM_FORMAT_MAX_PLANES];
        struct iosys_map data[DRM_FORMAT_MAX_PLANES];
+       struct iosys_map dst_map = IOSYS_MAP_INIT_VADDR(dst);
        void *src;
        int ret;
 
@@ -222,7 +223,7 @@ int mipi_dbi_buf_copy(void *dst, struct drm_framebuffer *fb,
                if (swap)
                        drm_fb_swab(dst, 0, src, fb, clip, !gem->import_attach);
                else
-                       drm_fb_memcpy(dst, 0, src, fb, clip);
+                       drm_fb_memcpy(&dst_map, NULL, data, fb, clip);
                break;
        case DRM_FORMAT_XRGB8888:
                drm_fb_xrgb8888_to_rgb565(dst, 0, src, fb, clip, swap);
index d42592f6daab8b2a79c4bc9636440f81e914b979..449c95a4aee0bda618c88c989548810aa9a30d4f 100644 (file)
@@ -156,6 +156,7 @@ static int gud_prep_flush(struct gud_device *gdrm, struct drm_framebuffer *fb,
        u8 compression = gdrm->compression;
        struct iosys_map map[DRM_FORMAT_MAX_PLANES];
        struct iosys_map map_data[DRM_FORMAT_MAX_PLANES];
+       struct iosys_map dst;
        void *vaddr, *buf;
        size_t pitch, len;
        int ret = 0;
@@ -179,6 +180,7 @@ retry:
                buf = gdrm->compress_buf;
        else
                buf = gdrm->bulk_buf;
+       iosys_map_set_vaddr(&dst, buf);
 
        /*
         * Imported buffers are assumed to be write-combined and thus uncached
@@ -208,7 +210,7 @@ retry:
                /* can compress directly from the framebuffer */
                buf = vaddr + rect->y1 * pitch;
        } else {
-               drm_fb_memcpy(buf, 0, vaddr, fb, rect);
+               drm_fb_memcpy(&dst, NULL, map_data, fb, rect);
        }
 
        memset(req, 0, sizeof(*req));
index b8e64dd8d3a6068cf5cf7ea53b2f465f38ceae18..28e732f94bf2f4d4160b46c42f41d68bd8fa6b35 100644 (file)
 #include "hyperv_drm.h"
 
 static int hyperv_blit_to_vram_rect(struct drm_framebuffer *fb,
-                                   const struct iosys_map *map,
+                                   const struct iosys_map *vmap,
                                    struct drm_rect *rect)
 {
        struct hyperv_drm_device *hv = to_hv(fb->dev);
-       void __iomem *dst = hv->vram;
-       void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
+       struct iosys_map dst = IOSYS_MAP_INIT_VADDR_IOMEM(hv->vram);
        int idx;
 
        if (!drm_dev_enter(&hv->dev, &idx))
                return -ENODEV;
 
-       dst += drm_fb_clip_offset(fb->pitches[0], fb->format, rect);
-       drm_fb_memcpy_toio(dst, fb->pitches[0], vmap, fb, rect);
+       iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], fb->format, rect));
+       drm_fb_memcpy(&dst, fb->pitches, vmap, fb, rect);
 
        drm_dev_exit(idx);
 
index 1f26d47166793d83a70cc4e341d9839dec308a4b..bbab2549243abceebf5a4bf6a033b6edcebd925b 100644 (file)
@@ -430,13 +430,12 @@ static void mgag200_disable_display(struct mga_device *mdev)
 }
 
 static void mgag200_handle_damage(struct mga_device *mdev, const struct iosys_map *vmap,
-                                 struct drm_framebuffer *fb, const struct drm_rect *clip)
+                                 struct drm_framebuffer *fb, struct drm_rect *clip)
 {
-       void __iomem *dst = mdev->vram;
-       void *vaddr = vmap[0].vaddr; /* TODO: Use mapping abstraction properly */
+       struct iosys_map dst = IOSYS_MAP_INIT_VADDR_IOMEM(mdev->vram);
 
-       dst += drm_fb_clip_offset(fb->pitches[0], fb->format, clip);
-       drm_fb_memcpy_toio(dst, fb->pitches[0], vaddr, fb, clip);
+       iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], fb->format, clip));
+       drm_fb_memcpy(&dst, fb->pitches, vmap, fb, clip);
 }
 
 /*
index c4f5beea1f90a4a607ba8d4974c0a254df184e9b..73fb9f63d227f1be45b30bcd9764d507eb31a5cf 100644 (file)
@@ -316,28 +316,31 @@ static int cirrus_mode_set(struct cirrus_device *cirrus,
 }
 
 static int cirrus_fb_blit_rect(struct drm_framebuffer *fb,
-                              const struct iosys_map *map,
+                              const struct iosys_map *vmap,
                               struct drm_rect *rect)
 {
        struct cirrus_device *cirrus = to_cirrus(fb->dev);
-       void __iomem *dst = cirrus->vram;
-       void *vmap = map->vaddr; /* TODO: Use mapping abstraction properly */
+       struct iosys_map dst;
+       void *vaddr = vmap->vaddr; /* TODO: Use mapping abstraction properly */
        int idx;
 
        if (!drm_dev_enter(&cirrus->dev, &idx))
                return -ENODEV;
 
+       iosys_map_set_vaddr_iomem(&dst, cirrus->vram);
+
        if (cirrus->cpp == fb->format->cpp[0]) {
-               dst += drm_fb_clip_offset(fb->pitches[0], fb->format, rect);
-               drm_fb_memcpy_toio(dst, fb->pitches[0], vmap, fb, rect);
+               iosys_map_incr(&dst, drm_fb_clip_offset(fb->pitches[0], fb->format, rect));
+               drm_fb_memcpy(&dst, fb->pitches, vmap, fb, rect);
 
        } else if (fb->format->cpp[0] == 4 && cirrus->cpp == 2) {
-               dst += drm_fb_clip_offset(cirrus->pitch, fb->format, rect);
-               drm_fb_xrgb8888_to_rgb565_toio(dst, cirrus->pitch, vmap, fb, rect, false);
+               iosys_map_incr(&dst, drm_fb_clip_offset(cirrus->pitch, fb->format, rect));
+               drm_fb_xrgb8888_to_rgb565_toio(dst.vaddr_iomem, cirrus->pitch, vaddr, fb, rect,
+                                              false);
 
        } else if (fb->format->cpp[0] == 4 && cirrus->cpp == 3) {
-               dst += drm_fb_clip_offset(cirrus->pitch, fb->format, rect);
-               drm_fb_xrgb8888_to_rgb888_toio(dst, cirrus->pitch, vmap, fb, rect);
+               iosys_map_incr(&dst, drm_fb_clip_offset(cirrus->pitch, fb->format, rect));
+               drm_fb_xrgb8888_to_rgb888_toio(dst.vaddr_iomem, cirrus->pitch, vaddr, fb, rect);
 
        } else {
                WARN_ON_ONCE("cpp mismatch");
index 21daea7fda99cc0b2b1aea63d99ccb4f87af5bf1..8af6a2717bc9d594ce1108ba1630408247313286 100644 (file)
@@ -14,10 +14,9 @@ struct drm_rect;
 unsigned int drm_fb_clip_offset(unsigned int pitch, const struct drm_format_info *format,
                                const struct drm_rect *clip);
 
-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_memcpy(struct iosys_map *dst, const unsigned int *dst_pitch,
+                  const struct iosys_map *vmap, const struct drm_framebuffer *fb,
+                  const struct drm_rect *clip);
 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);