drm/core: Calculate bpp in afbc helper
authorAndrzej Pietrasiewicz <andrzej.p@collabora.com>
Tue, 31 Mar 2020 15:53:08 +0000 (17:53 +0200)
committerAndrzej Pietrasiewicz <andrzej.p@collabora.com>
Wed, 1 Apr 2020 12:11:22 +0000 (14:11 +0200)
Some drivers (komeda, malidp) don't set anything in cpp. If that is the
case the right value can be inferred from the format. Then the "bpp" member
can be eliminated from struct drm_afbc_framebuffer.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/20200331155308.6345-3-andrzej.p@collabora.com
Documentation/gpu/todo.rst
drivers/gpu/drm/drm_gem_framebuffer_helper.c
include/drm/drm_framebuffer.h

index 37a3a023c11401b1a480359b9642576f9f8afbc1..439656f55c5da8ec957f2da313d1ca430bd59714 100644 (file)
@@ -404,21 +404,6 @@ Contact: Laurent Pinchart, respective driver maintainers
 
 Level: Intermediate
 
-Encode cpp properly in malidp
------------------------------
-
-cpp (chars per pixel) is not encoded properly in malidp, zero is
-used instead. afbc implementation needs bpp or cpp, but if it is
-zero it needs to be provided elsewhere, and so the bpp field exists
-in struct drm_afbc_framebuffer.
-
-Properly encode cpp in malidp and remove the bpp field in struct
-drm_afbc_framebuffer.
-
-Contact: malidp maintainers
-
-Level: Intermediate
-
 Core refactorings
 =================
 
index 6fb1841fa71cbe7c33383fd1bee248258fba17df..cac15294aef61119a7979bb7ee62e0c59c1f83af 100644 (file)
@@ -309,11 +309,37 @@ drm_gem_fb_create_with_dirty(struct drm_device *dev, struct drm_file *file,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_dirty);
 
+static __u32 drm_gem_afbc_get_bpp(struct drm_device *dev,
+                                 const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+       const struct drm_format_info *info;
+
+       info = drm_get_format_info(dev, mode_cmd);
+
+       /* use whatever a driver has set */
+       if (info->cpp[0])
+               return info->cpp[0] * 8;
+
+       /* guess otherwise */
+       switch (info->format) {
+       case DRM_FORMAT_YUV420_8BIT:
+               return 12;
+       case DRM_FORMAT_YUV420_10BIT:
+               return 15;
+       case DRM_FORMAT_VUY101010:
+               return 30;
+       default:
+               break;
+       }
+
+       /* all attempts failed */
+       return 0;
+}
+
 static int drm_gem_afbc_min_size(struct drm_device *dev,
                                 const struct drm_mode_fb_cmd2 *mode_cmd,
                                 struct drm_afbc_framebuffer *afbc_fb)
 {
-       const struct drm_format_info *info;
        __u32 n_blocks, w_alignment, h_alignment, hdr_alignment;
        /* remove bpp when all users properly encode cpp in drm_format_info */
        __u32 bpp;
@@ -351,12 +377,11 @@ static int drm_gem_afbc_min_size(struct drm_device *dev,
        afbc_fb->aligned_height = ALIGN(mode_cmd->height, h_alignment);
        afbc_fb->offset = mode_cmd->offsets[0];
 
-       info = drm_get_format_info(dev, mode_cmd);
-       /*
-        * Change to always using info->cpp[0]
-        * when all users properly encode it
-        */
-       bpp = info->cpp[0] ? info->cpp[0] * 8 : afbc_fb->bpp;
+       bpp = drm_gem_afbc_get_bpp(dev, mode_cmd);
+       if (!bpp) {
+               drm_dbg_kms(dev, "Invalid AFBC bpp value: %d\n", bpp);
+               return -EINVAL;
+       }
 
        n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height)
                   / AFBC_SUPERBLOCK_PIXELS;
index b53c0332f0405a2ed9cb76e1d90aa9277937d453..be658ebbec72b084c47d5f7ab8289a942d6f6632 100644 (file)
@@ -331,13 +331,6 @@ struct drm_afbc_framebuffer {
         * @afbc_size: minimum size of afbc buffer
         */
        u32 afbc_size;
-       /**
-        * @bpp: bpp value for this afbc buffer
-        * To be removed when users such as malidp
-        * properly store the cpp in drm_format_info.
-        * New users should not start using this field.
-        */
-       u32 bpp;
 };
 
 #define fb_to_afbc_fb(x) container_of(x, struct drm_afbc_framebuffer, base)