All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
To: dri-devel@lists.freedesktop.org
Cc: Ayan Halder <Ayan.Halder@arm.com>,
	kernel@collabora.com, David Airlie <airlied@linux.ie>,
	Liviu Dudau <liviu.dudau@arm.com>,
	linux-rockchip@lists.infradead.org,
	James Wang <james.qian.wang@arm.com>,
	Mihail Atanassov <mihail.atanassov@arm.com>,
	Sean Paul <sean@poorly.run>
Subject: [PATCHv2 2/4] drm/malidp: use afbc helpers
Date: Mon,  4 Nov 2019 23:12:26 +0100	[thread overview]
Message-ID: <20191104221228.3588-3-andrzej.p@collabora.com> (raw)
In-Reply-To: <20191104221228.3588-1-andrzej.p@collabora.com>

There are afbc helpers available.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/malidp_drv.c | 66 ++++++--------------------------
 1 file changed, 12 insertions(+), 54 deletions(-)

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 37d92a06318e..ab93588cc8eb 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -15,6 +15,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/debugfs.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
@@ -35,8 +36,6 @@
 #include "malidp_hw.h"
 
 #define MALIDP_CONF_VALID_TIMEOUT	250
-#define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 
 static void malidp_write_gamma_table(struct malidp_hw_device *hwdev,
 				     u32 data[MALIDP_COEFFTAB_NUM_COEFFS])
@@ -277,24 +276,8 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
 					mode_cmd->modifier[0]) == false)
 		return false;
 
-	if (mode_cmd->offsets[0] != 0) {
-		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
-		return false;
-	}
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
-			DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n");
-			return false;
-		}
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
-
-	return true;
+	return drm_afbc_check_offset(dev, mode_cmd) &&
+	       drm_afbc_check_size_align(dev, mode_cmd);
 }
 
 static bool
@@ -302,54 +285,29 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
 				    struct drm_file *file,
 				    const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	int n_superblocks = 0;
 	const struct drm_format_info *info;
 	struct drm_gem_object *objs = NULL;
-	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
-	u32 afbc_superblock_width = 0, afbc_size = 0;
 	int bpp = 0;
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		afbc_superblock_height = 16;
-		afbc_superblock_width = 16;
-		break;
-	default:
-		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
-		return false;
-	}
+	u32 w, h;
 
 	info = drm_get_format_info(dev, mode_cmd);
-
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
-
 	bpp = malidp_format_get_bpp(info->format);
 
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
-
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
-
-	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
-		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
-			      "should be same as width (=%u) * bpp (=%u)\n",
-			      (mode_cmd->pitches[0] * BITS_PER_BYTE),
-			      mode_cmd->width, bpp);
-		return false;
-	}
-
 	objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!objs) {
 		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
 		return false;
 	}
 
-	if (objs->size < afbc_size) {
-		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
-			      objs->size, afbc_size);
+	if (!drm_afbc_get_superblk_wh(mode_cmd->modifier[0], &w, &h))
+		return false;
+
+	if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+				    mode_cmd->width, mode_cmd->height, w, h,
+				    objs->size, mode_cmd->offsets[0],
+				    AFBC_SUPERBLK_ALIGNMENT)) {
 		drm_gem_object_put_unlocked(objs);
+
 		return false;
 	}
 
-- 
2.17.1

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2019-11-04 22:12 UTC|newest]

Thread overview: 63+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-11 11:18 [PATCH 0/2] AFBC for Rockchip Andrzej Pietrasiewicz
2019-10-11 11:18 ` Andrzej Pietrasiewicz
2019-10-11 11:18 ` [PATCH 1/2] drm/arm: Factor out generic afbc helpers Andrzej Pietrasiewicz
2019-10-11 11:18   ` Andrzej Pietrasiewicz
2019-10-21 13:50   ` Ayan Halder
2019-10-21 13:50     ` Ayan Halder
2019-10-21 13:50     ` Ayan Halder
2019-10-21 14:41     ` Mihail Atanassov
2019-10-21 14:41       ` Mihail Atanassov
2019-10-21 14:41       ` Mihail Atanassov
2019-11-04 22:12       ` [PATCHv2 0/4] AFBC support for Rockchip Andrzej Pietrasiewicz
2019-11-04 22:12         ` [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers Andrzej Pietrasiewicz
2019-11-05  9:22           ` Daniel Vetter
2019-11-06 12:45             ` Andrzej Pietrasiewicz
2019-11-07  8:27               ` Daniel Vetter
2019-11-05 23:26           ` Daniel Stone
2019-11-05 23:26             ` Daniel Stone
2019-11-06 10:28             ` Liviu Dudau
2019-11-07 17:20             ` Brian Starkey
2019-11-07 17:20               ` Brian Starkey
2019-11-07 17:32               ` Daniel Vetter
2019-11-07 17:32                 ` Daniel Vetter
2019-11-07 17:49                 ` Brian Starkey
2019-11-07 17:49                   ` Brian Starkey
2019-11-07 19:28                   ` Daniel Vetter
2019-11-07 19:28                     ` Daniel Vetter
2019-11-08  9:46                     ` Brian Starkey
2019-11-08  9:46                       ` Brian Starkey
2019-11-04 22:12         ` Andrzej Pietrasiewicz [this message]
2019-11-06 11:09           ` [PATCHv2 2/4] drm/malidp: use " Liviu Dudau
2019-11-04 22:12         ` [PATCHv2 3/4] drm/komeda: " Andrzej Pietrasiewicz
2019-11-08 16:09           ` Ayan Halder
2019-11-08 16:09             ` Ayan Halder
2019-11-13  2:01             ` james qian wang (Arm Technology China)
2019-11-13 11:39               ` Daniel Vetter
2019-11-14  1:52                 ` james qian wang (Arm Technology China)
2019-11-14 10:12                   ` Daniel Vetter
2019-11-18  7:09                     ` james qian wang (Arm Technology China)
2019-11-18  9:51                       ` Daniel Vetter
     [not found]                         ` <20191118095136.GC23790-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org>
2019-11-19  8:34                           ` james qian wang (Arm Technology China)
2019-11-19  8:34                             ` james qian wang (Arm Technology China)
2019-11-21 17:22                             ` [PATCHv3/RFC 0/4] AFBC rework and support for Rockchip Andrzej Pietrasiewicz
2019-11-21 17:22                               ` [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers Andrzej Pietrasiewicz
2019-11-23  7:13                                 ` Ezequiel Garcia
2019-11-23  7:13                                   ` Ezequiel Garcia
2019-11-24 10:11                                 ` kbuild test robot
2019-11-25  8:55                                 ` Daniel Vetter
2019-11-26 20:27                                   ` Andrzej Pietrasiewicz
2019-11-27  9:51                                     ` Daniel Vetter
2019-11-28 10:47                                   ` james qian wang (Arm Technology China)
2019-11-21 17:22                               ` [PATCHv3/RFC 2/4] drm/malidp: use " Andrzej Pietrasiewicz
2019-11-21 17:22                               ` [PATCHv3/RFC 3/4] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
2019-11-21 17:22                               ` [PATCHv3/RFC 4/4] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
2019-11-23  7:21                                 ` Ezequiel Garcia
2019-11-23  7:21                                   ` Ezequiel Garcia
2019-11-04 22:12         ` [PATCHv2 " Andrzej Pietrasiewicz
2019-11-05 23:34           ` Daniel Stone
2019-11-05 23:34             ` Daniel Stone
2019-10-11 11:18 ` [PATCH 2/2] " Andrzej Pietrasiewicz
2019-10-11 11:18   ` Andrzej Pietrasiewicz
2019-10-11 11:59   ` Daniel Stone
2019-10-11 11:59     ` Daniel Stone
2019-10-11 11:59     ` Daniel Stone

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191104221228.3588-3-andrzej.p@collabora.com \
    --to=andrzej.p@collabora.com \
    --cc=Ayan.Halder@arm.com \
    --cc=airlied@linux.ie \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=james.qian.wang@arm.com \
    --cc=kernel@collabora.com \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=liviu.dudau@arm.com \
    --cc=mihail.atanassov@arm.com \
    --cc=sean@poorly.run \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.