All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCHv4 00/36] AFBC support for Rockchip
@ 2019-12-13 15:58 Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 01/36] drm/framebuffer: Add optional modifier info Andrzej Pietrasiewicz
                   ` (35 more replies)
  0 siblings, 36 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

This series adds AFBC support for Rockchip. It is inspired by:

https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c

This is the fourth iteration of the afbc series. This time a lot of rework
has been done, the main goal of which is to move all afbc-related checks
to helpers, so that core does not deal with it.

Struct drm_framebuffer gains a new "modifier_info" pointer (overlaid in an
union). That member can be used to store driver-specific data, which, for
afbc, will be a struct drm_afbc. Because of that, in drivers that wish to
use this feature, the struct drm_framebuffer must be allocated directly in
the driver code rather than inside helpers, so the first portion of the
patchset does the necessary refactoring.

Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
the latter being the ultimate purpose of this work and the 3 subsequent
portions of the patchset move komeda and malidp to generic helpers and add
afbc support to rockchip.

The idea is to make all afbc users follow a similar pattern. In fb_create()
they allocate struct drm_framebuffer with struct drm_afbc in one chunk of
memory (to ease freeing later), do their specific checks which can be done
before object lookups, do object lookups and a special version of a size
check, which understands struct drm_afbc, followed by any other
driver-specific checks and initializing the gem object. The helpers for
the common parts are factored out so that drivers can use them.

The komeda driver has been the farthest away from such a pattern, so it
required most changes. However, due to the fact that I don't have any
komeda hardware I did the changes to komeda in an incremental fashion with
a series of (usually) very small, easy to understand steps. malidp was
pretty straightforward, and rockchip's afbc checks follow the pattern.

I kindly ask for reviewing the series. I need to mention that my ultimate
goal is merging afbc for rockchip and I don't have other hardware, so some
help from malidp and komeda developers/maintainers would be appreciated.

Rebased onto drm-misc-next.

v3..v4:

- addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel
Vetter and James Qian Wang - thank you for input
- refactored helpers to ease accommodating drivers with afbc needs
- moved afbc checks to helpers
- converted komeda, malidp and (the newly added) rockchip to use the afbc
helpers
- eliminated a separate, dedicated source code file

v2..v3:

- addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter
and Brian Starkey - thank you all

In this iteration some rework has been done. The checking logic is now moved
to framebuffer_check() so it is common to all drivers. But the common part
is not good for komeda, so this series is not good for merging yet.
I kindly ask for feedback whether the changes are in the right direction.
I also kindly ask for input on how to accommodate komeda.

The CONFIG_DRM_AFBC option has been eliminated in favour of adding
drm_afbc.c to drm_kms_helper.

v1..v2:

- addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
- coding style fixes

Andrzej Pietrasiewicz (36):
  drm/framebuffer: Add optional modifier info
  drm/core: Add afbc helper functions
  drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on
    their own
  drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  drm/gem-fb-helper: Add generic afbc size checks
  drm/gem-fb-helper: Add method to allocate struct drm_framebuffer
  drm/komeda: Use afbc helper
  drm/komeda: Move checking src coordinates to komeda_fb_create
  drm/komeda: Use the already available local variable
  drm/komeda: Retrieve drm_format_info once
  drm/komeda: Explicitly require 1 plane for AFBC
  drm/komeda: Move pitches comparison to komeda_fb_create
  drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not
    requiring a fb
  drm/komeda: Factor out object lookups for non-afbc case
  drm/komeda: Make komeda_fb_none_size_check independent from
    framebuffer
  drm/komeda: Factor out object lookups for afbc case
  drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
  drm/komeda: Simplify error handling
  drm/komeda: Move object lookup before size checks
  drm/komeda: Move object assignments to framebuffer to after size
    checks
  drm/komeda: Make the size checks independent from framebuffer
    structure
  drm/komeda: Move helper invocation to after size checks
  drm/komeda: Use helper for common tasks
  drm/komeda: Use return value of drm_gem_fb_lookup
  drm/komeda: Use special helper for non-afbc size checks
  drm/komeda: Factor in the invocation of special helper
  drm/komeda: Use special helper for afbc case size check
  drm/komeda: Factor in the invocation of special helper, afbc case
  drm/komeda: Move special helper invocation outside if-else
  drm/komeda: Move to helper checking afbc buffer size
  drm/arm/malidp: Make verify funcitons invocations independent
  drm/arm/malidp: Integrate verify functions
  drm/arm/malidp: Factor in afbc framebuffer verification
  drm/arm/malidp: Use generic helpers for afbc checks
  drm/rockchip: Use helper for common task
  drm/rockchip: Add support for afbc

 .../arm/display/komeda/d71/d71_component.c    |   7 +-
 .../arm/display/komeda/komeda_framebuffer.c   | 285 ++++++++---------
 .../arm/display/komeda/komeda_framebuffer.h   |  15 +-
 .../display/komeda/komeda_pipeline_state.c    |  11 +-
 drivers/gpu/drm/arm/malidp_drv.c              | 155 ++++-----
 drivers/gpu/drm/drm_fourcc.c                  |  63 +++-
 drivers/gpu/drm/drm_framebuffer.c             |   3 +
 drivers/gpu/drm/drm_gem_framebuffer_helper.c  | 301 +++++++++++++++---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c    | 109 ++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c   | 141 +++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h   |  12 +
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c   |  84 ++++-
 include/drm/drm_fourcc.h                      |   4 +
 include/drm/drm_framebuffer.h                 |  16 +
 include/drm/drm_gem_framebuffer_helper.h      |  50 +++
 15 files changed, 933 insertions(+), 323 deletions(-)

-- 
2.17.1

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* [PATCHv4 01/36] drm/framebuffer: Add optional modifier info
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2020-02-17  5:50   ` [PATCHv4,01/36] " james qian wang (Arm Technology China)
  2019-12-13 15:58 ` [PATCHv4 02/36] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
                   ` (34 subsequent siblings)
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

modifier_info is a pointer to an optional modifier-related information.
Managing the memory needed for that information is the responsibility
of drivers.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 include/drm/drm_framebuffer.h | 16 ++++++++++++++++
 1 file changed, 16 insertions(+)

diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index c0e0256e3e98..2b3341b526d7 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -29,6 +29,7 @@
 
 #include <drm/drm_mode_object.h>
 
+struct drm_afbc;
 struct drm_clip_rect;
 struct drm_device;
 struct drm_file;
@@ -139,6 +140,21 @@ struct drm_framebuffer {
 	 * @format: framebuffer format information
 	 */
 	const struct drm_format_info *format;
+
+	union {
+		/**
+		 * @modifier_info: pointer to an optional modifier-related
+		 * information. Managing the memory holding that information
+		 * is driver's responsibility.
+		 */
+		void *modifier_info;
+
+		/**
+		 * @afbc_info: afbc-specific pointer
+		 */
+		struct drm_afbc *afbc_info;
+	};
+
 	/**
 	 * @funcs: framebuffer vfunc table
 	 */
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 02/36] drm/core: Add afbc helper functions
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 01/36] drm/framebuffer: Add optional modifier info Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2020-02-17  6:09   ` [PATCHv4,02/36] " james qian wang (Arm Technology China)
  2019-12-13 15:58 ` [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
                   ` (33 subsequent siblings)
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Add checking if a modifier is afbc and getting afbc block size.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_fourcc.h     |  4 +++
 2 files changed, 57 insertions(+)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index b234bfaeda06..d14dd7c86020 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -29,6 +29,7 @@
 
 #include <drm/drm_device.h>
 #include <drm/drm_fourcc.h>
+#include <drm/drm_print.h>
 
 static char printable_char(int c)
 {
@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
 			    drm_format_info_block_height(info, plane));
 }
 EXPORT_SYMBOL(drm_format_info_min_pitch);
+
+/**
+ * drm_is_afbc - test if the modifier describes an afbc buffer
+ * @modifier - modifier to be tested
+ *
+ * Returns: true if the modifier describes an afbc buffer
+ */
+bool drm_is_afbc(u64 modifier)
+{
+	/* is it ARM AFBC? */
+	if ((modifier & DRM_FORMAT_MOD_ARM_AFBC(0)) == 0)
+		return false;
+
+	/* Block size must be known */
+	if ((modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) == 0)
+		return false;
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_is_afbc);
+
+/**
+ * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier
+ * @modifier: the modifier to be looked at
+ * @w: address of a place to store the block width
+ * @h: address of a place to store the block height
+ *
+ * Returns: true if the modifier describes a supported block size
+ */
+bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h)
+{
+	switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		*w = 16;
+		*h = 16;
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		*w = 32;
+		*h = 8;
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
+			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
+		return false;
+	}
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_get_superblock_wh);
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index 306d1efeb5e0..7eb23062bf45 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
 				   int plane, unsigned int buffer_width);
 const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
 
+bool drm_is_afbc(u64 modifier);
+
+bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h);
+
 #endif /* __DRM_FOURCC_H__ */
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 01/36] drm/framebuffer: Add optional modifier info Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 02/36] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-16 17:08   ` Liviu Dudau
  2020-02-17  6:39   ` [PATCHv4,03/36] " james qian wang (Arm Technology China)
  2019-12-13 15:58 ` [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
                   ` (32 subsequent siblings)
  35 siblings, 2 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Prepare tools for drivers which need to allocate a struct drm_framebuffer
(or a container of struct drm_framebuffer) explicitly, before calling
helpers. In such a case we need new helpers which omit allocating the
struct drm_framebuffer and this patch provides them. Consequently, they
are used also inside the helpers themselves.

The interested drivers will likely need to be able to perform object
lookups and size checks in separate invocations and this patch provides
that as well. Helpers themselves are updated, too.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 184 ++++++++++++++-----
 include/drm/drm_gem_framebuffer_helper.h     |  17 ++
 2 files changed, 153 insertions(+), 48 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index b9bcd310ca2d..787edb9a916b 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
 
+int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
+			       struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd,
+			       struct drm_gem_object **obj,
+			       unsigned int num_planes,
+			       const struct drm_framebuffer_funcs *funcs)
+{
+	int ret, i;
+
+	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
+
+	for (i = 0; i < num_planes; i++)
+		fb->obj[i] = obj[i];
+
+	ret = drm_framebuffer_init(dev, fb, funcs);
+	if (ret)
+		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
+			      ret);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
+
+static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
+	.destroy	= drm_gem_fb_destroy,
+	.create_handle	= drm_gem_fb_create_handle,
+};
+
+int drm_gem_fb_init(struct drm_framebuffer *fb,
+		    struct drm_device *dev,
+		    const struct drm_mode_fb_cmd2 *mode_cmd,
+		    struct drm_gem_object **obj, unsigned int num_planes)
+{
+	return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
+					  &drm_gem_fb_funcs);
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_init);
+
 static struct drm_framebuffer *
 drm_gem_fb_alloc(struct drm_device *dev,
 		 const struct drm_mode_fb_cmd2 *mode_cmd,
@@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev,
 		 const struct drm_framebuffer_funcs *funcs)
 {
 	struct drm_framebuffer *fb;
-	int ret, i;
+	int ret;
 
 	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
 	if (!fb)
 		return ERR_PTR(-ENOMEM);
 
-	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
-
-	for (i = 0; i < num_planes; i++)
-		fb->obj[i] = obj[i];
-
-	ret = drm_framebuffer_init(dev, fb, funcs);
+	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
+					 funcs);
 	if (ret) {
-		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
-			      ret);
 		kfree(fb);
 		return ERR_PTR(ret);
 	}
@@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
 EXPORT_SYMBOL(drm_gem_fb_create_handle);
 
 /**
- * drm_gem_fb_create_with_funcs() - Helper function for the
- *                                  &drm_mode_config_funcs.fb_create
- *                                  callback
+ * drm_gem_fb_lookup() - Helper function for use in
+ *			 &drm_mode_config_funcs.fb_create implementations
  * @dev: DRM device
  * @file: DRM file that holds the GEM handle(s) backing the framebuffer
  * @mode_cmd: Metadata from the userspace framebuffer creation request
- * @funcs: vtable to be used for the new framebuffer object
  *
- * This function can be used to set &drm_framebuffer_funcs for drivers that need
- * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
- * change &drm_framebuffer_funcs. The function does buffer size validation.
+ * This function can be used to look up the objects for all planes.
+ * In case an error is returned all the objects are put by the
+ * function before returning.
  *
  * Returns:
- * Pointer to a &drm_framebuffer on success or an error pointer on failure.
+ * Number of planes on success or a negative error code on failure.
  */
-struct drm_framebuffer *
-drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
-			     const struct drm_mode_fb_cmd2 *mode_cmd,
-			     const struct drm_framebuffer_funcs *funcs)
+int drm_gem_fb_lookup(struct drm_device *dev,
+		      struct drm_file *file,
+		      const struct drm_mode_fb_cmd2 *mode_cmd,
+		      struct drm_gem_object **objs)
 {
 	const struct drm_format_info *info;
-	struct drm_gem_object *objs[4];
-	struct drm_framebuffer *fb;
 	int ret, i;
 
 	info = drm_get_format_info(dev, mode_cmd);
 	if (!info)
-		return ERR_PTR(-EINVAL);
+		return -EINVAL;
 
 	for (i = 0; i < info->num_planes; i++) {
-		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
-		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
-		unsigned int min_size;
-
 		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
 		if (!objs[i]) {
 			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
 			ret = -ENOENT;
 			goto err_gem_object_put;
 		}
+	}
+
+	return i;
+
+err_gem_object_put:
+	for (i--; i >= 0; i--)
+		drm_gem_object_put_unlocked(objs[i]);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
+
+/**
+ * drm_gem_fb_size_check() - Helper function for use in
+ *			     &drm_mode_config_funcs.fb_create implementations
+ * @dev: DRM device
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ *
+ * This function can be used to verify buffer sizes for all planes.
+ * It is caller's responsibility to put the objects on failure.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int drm_gem_fb_size_check(struct drm_device *dev,
+			  const struct drm_mode_fb_cmd2 *mode_cmd,
+			  struct drm_gem_object **objs)
+{
+	const struct drm_format_info *info;
+	int i;
+
+	info = drm_get_format_info(dev, mode_cmd);
+	if (!info)
+		return -EINVAL;
+
+	for (i = 0; i < info->num_planes; i++) {
+		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
+		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
+		unsigned int min_size;
 
 		min_size = (height - 1) * mode_cmd->pitches[i]
 			 + drm_format_info_min_pitch(info, i, width)
 			 + mode_cmd->offsets[i];
 
-		if (objs[i]->size < min_size) {
-			drm_gem_object_put_unlocked(objs[i]);
-			ret = -EINVAL;
-			goto err_gem_object_put;
-		}
+		if (objs[i]->size < min_size)
+			return -EINVAL;
 	}
 
-	fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
-	if (IS_ERR(fb)) {
-		ret = PTR_ERR(fb);
-		goto err_gem_object_put;
-	}
+	return 0;
 
-	return fb;
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
 
-err_gem_object_put:
-	for (i--; i >= 0; i--)
-		drm_gem_object_put_unlocked(objs[i]);
+/**
+ * drm_gem_fb_create_with_funcs() - Helper function for the
+ *                                  &drm_mode_config_funcs.fb_create
+ *                                  callback
+ * @dev: DRM device
+ * @file: DRM file that holds the GEM handle(s) backing the framebuffer
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ * @funcs: vtable to be used for the new framebuffer object
+ *
+ * This function can be used to set &drm_framebuffer_funcs for drivers that need
+ * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
+ * change &drm_framebuffer_funcs. The function does buffer size validation.
+ *
+ * Returns:
+ * Pointer to a &drm_framebuffer on success or an error pointer on failure.
+ */
+struct drm_framebuffer *
+drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
+			     const struct drm_mode_fb_cmd2 *mode_cmd,
+			     const struct drm_framebuffer_funcs *funcs)
+{
+	struct drm_gem_object *objs[4];
+	struct drm_framebuffer *fb;
+	int ret, num_planes;
+
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		return ERR_PTR(ret);
+	num_planes = ret;
+
+	ret = drm_gem_fb_size_check(dev, mode_cmd, objs);
+	if (ret)
+		fb = ERR_PTR(ret);
+	else
+		fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs);
 
-	return ERR_PTR(ret);
+	if (IS_ERR(fb))
+		for (num_planes--; num_planes >= 0; num_planes--)
+			drm_gem_object_put_unlocked(objs[num_planes]);
+
+	return fb;
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
 
-static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
-	.destroy	= drm_gem_fb_destroy,
-	.create_handle	= drm_gem_fb_create_handle,
-};
-
 /**
  * drm_gem_fb_create() - Helper function for the
  *                       &drm_mode_config_funcs.fb_create callback
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index d9f13fd25b0a..c85d4b152e91 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 					  unsigned int plane);
+int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
+			       struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd,
+			       struct drm_gem_object **obj,
+			       unsigned int num_planes,
+			       const struct drm_framebuffer_funcs *funcs);
+int drm_gem_fb_init(struct drm_framebuffer *fb,
+		    struct drm_device *dev,
+		    const struct drm_mode_fb_cmd2 *mode_cmd,
+		    struct drm_gem_object **obj, unsigned int num_planes);
 void drm_gem_fb_destroy(struct drm_framebuffer *fb);
 int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
 			     unsigned int *handle);
 
+int drm_gem_fb_lookup(struct drm_device *dev,
+		      struct drm_file *file,
+		      const struct drm_mode_fb_cmd2 *mode_cmd,
+		      struct drm_gem_object **objs);
+int drm_gem_fb_size_check(struct drm_device *dev,
+			  const struct drm_mode_fb_cmd2 *mode_cmd,
+			  struct drm_gem_object **objs);
 struct drm_framebuffer *
 drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
 			     const struct drm_mode_fb_cmd2 *mode_cmd,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (2 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-16 17:11   ` Liviu Dudau
  2020-02-17  8:16   ` [PATCHv4,04/36] " james qian wang (Arm Technology China)
  2019-12-13 15:58 ` [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
                   ` (31 subsequent siblings)
  35 siblings, 2 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The new version accepts a struct describing deviations from standard way of
doing the size checks. The caller must provide the respective values.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++----
 include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
 2 files changed, 55 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index 787edb9a916b..4201dc1f32a5 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,
 EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
 
 /**
- * drm_gem_fb_size_check() - Helper function for use in
- *			     &drm_mode_config_funcs.fb_create implementations
+ * drm_gem_fb_size_check_special() - Helper function for use in
+ *				     &drm_mode_config_funcs.fb_create
+ *				     implementations
  * @dev: DRM device
  * @mode_cmd: Metadata from the userspace framebuffer creation request
  *
@@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
  * Returns:
  * Zero on success or a negative error code on failure.
  */
-int drm_gem_fb_size_check(struct drm_device *dev,
-			  const struct drm_mode_fb_cmd2 *mode_cmd,
-			  struct drm_gem_object **objs)
+int drm_gem_fb_size_check_special(struct drm_device *dev,
+				  const struct drm_mode_fb_cmd2 *mode_cmd,
+				  const struct drm_size_check *check,
+				  struct drm_gem_object **objs)
 {
 	const struct drm_format_info *info;
 	int i;
@@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
 		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
 		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
 		unsigned int min_size;
+		u32 pitch = mode_cmd->pitches[i];
+
+		if (check && check->use_pitch_multiplier)
+			if ((pitch * check->pitch_multiplier[i]) %
+			    check->pitch_modulo)
+				return -EINVAL;
 
-		min_size = (height - 1) * mode_cmd->pitches[i]
-			 + drm_format_info_min_pitch(info, i, width)
-			 + mode_cmd->offsets[i];
+		if (check && check->use_min_size)
+			min_size = check->min_size[i];
+		else
+			min_size = (height - 1) * pitch
+				 + drm_format_info_min_pitch(info, i, width)
+				 + mode_cmd->offsets[i];
 
 		if (objs[i]->size < min_size)
 			return -EINVAL;
@@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
 	return 0;
 
 }
+EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
+
+/**
+ * drm_gem_fb_size_check() - Helper function for use in
+ *			     &drm_mode_config_funcs.fb_create implementations
+ * @dev: DRM device
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ *
+ * This function can be used to verify buffer sizes for all planes.
+ * It is caller's responsibility to put the objects on failure.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int drm_gem_fb_size_check(struct drm_device *dev,
+			  const struct drm_mode_fb_cmd2 *mode_cmd,
+			  struct drm_gem_object **objs)
+{
+	return drm_gem_fb_size_check_special(dev, mode_cmd, NULL, objs);
+}
 EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
 
 /**
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index c85d4b152e91..74304a268694 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
 struct drm_plane;
 struct drm_plane_state;
 struct drm_simple_display_pipe;
+struct drm_size_check;
+
+/**
+ * struct drm_size_check - Description of special requirements for size checks.
+ */
+struct drm_size_check {
+	unsigned int min_size[4];
+	bool use_min_size;
+	u32 pitch_multiplier[4];
+	u32 pitch_modulo;
+	bool use_pitch_multiplier;
+};
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 					  unsigned int plane);
@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
 		      struct drm_file *file,
 		      const struct drm_mode_fb_cmd2 *mode_cmd,
 		      struct drm_gem_object **objs);
+int drm_gem_fb_size_check_special(struct drm_device *dev,
+				  const struct drm_mode_fb_cmd2 *mode_cmd,
+				  const struct drm_size_check *check,
+				  struct drm_gem_object **objs);
 int drm_gem_fb_size_check(struct drm_device *dev,
 			  const struct drm_mode_fb_cmd2 *mode_cmd,
 			  struct drm_gem_object **objs);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (3 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-16 17:19   ` Liviu Dudau
  2020-02-17 11:02   ` [PATCHv4,05/36] " james qian wang (Arm Technology China)
  2019-12-13 15:58 ` [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer Andrzej Pietrasiewicz
                   ` (30 subsequent siblings)
  35 siblings, 2 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Extend the size-checking special function to handle afbc.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_fourcc.c                 | 10 +++-
 drivers/gpu/drm/drm_framebuffer.c            |  3 +
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++--
 include/drm/drm_gem_framebuffer_helper.h     | 16 ++++++
 4 files changed, 82 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index d14dd7c86020..9ac2175c5bee 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev,
 {
 	const struct drm_format_info *info = NULL;
 
-	if (dev->mode_config.funcs->get_format_info)
-		info = dev->mode_config.funcs->get_format_info(mode_cmd);
+	/* bypass driver callback if afbc */
+	if (!drm_is_afbc(mode_cmd->modifier[0]))
+		if (dev->mode_config.funcs->get_format_info) {
+			const struct drm_mode_config_funcs *funcs;
+
+			funcs = dev->mode_config.funcs;
+			info = funcs->get_format_info(mode_cmd);
+		}
 
 	if (!info)
 		info = drm_format_info(mode_cmd->pixel_format);
diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
index 57564318ceea..33b741cc73e8 100644
--- a/drivers/gpu/drm/drm_framebuffer.c
+++ b/drivers/gpu/drm/drm_framebuffer.c
@@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev,
 		unsigned int block_size = info->char_per_block[i];
 		u64 min_pitch = drm_format_info_min_pitch(info, i, width);
 
+		if (drm_is_afbc(r->modifier[i]))
+			block_size = 0;
+
 		if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) {
 			DRM_DEBUG_KMS("Format requires non-linear modifier for plane %d\n", i);
 			return -EINVAL;
diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index 4201dc1f32a5..e20f4d00b0a5 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -21,6 +21,11 @@
 #include <drm/drm_modeset_helper.h>
 #include <drm/drm_simple_kms_helper.h>
 
+#define AFBC_HEADER_SIZE		16
+#define AFBC_TH_LAYOUT_ALIGNMENT	8
+#define AFBC_SUPERBLOCK_PIXELS		256
+#define AFBC_SUPERBLOCK_ALIGNMENT	128
+
 /**
  * DOC: overview
  *
@@ -200,6 +205,40 @@ int drm_gem_fb_lookup(struct drm_device *dev,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
 
+static int drm_gem_afbc_min_size(struct drm_device *dev,
+				 const struct drm_mode_fb_cmd2 *mode_cmd,
+				 struct drm_afbc *afbc)
+{
+	u32 n_blocks;
+
+	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
+					&afbc->block_width,
+					&afbc->block_height)) {
+		return -EINVAL;
+	}
+
+	/* tiled header afbc */
+	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
+		afbc->block_width *= AFBC_TH_LAYOUT_ALIGNMENT;
+		afbc->block_height *= AFBC_TH_LAYOUT_ALIGNMENT;
+	}
+
+	afbc->aligned_width = ALIGN(mode_cmd->width, afbc->block_width);
+	afbc->aligned_height = ALIGN(mode_cmd->height, afbc->block_height);
+	afbc->offset = mode_cmd->offsets[0];
+
+	n_blocks = (afbc->aligned_width * afbc->aligned_height)
+		 / AFBC_SUPERBLOCK_PIXELS;
+	afbc->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
+				     afbc->alignment_header);
+
+	afbc->afbc_size = afbc->offset_payload + n_blocks *
+			  ALIGN(afbc->bpp * AFBC_SUPERBLOCK_PIXELS / 8,
+				AFBC_SUPERBLOCK_ALIGNMENT);
+
+	return 0;
+}
+
 /**
  * drm_gem_fb_size_check_special() - Helper function for use in
  *				     &drm_mode_config_funcs.fb_create
@@ -218,6 +257,7 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,
 				  const struct drm_size_check *check,
 				  struct drm_gem_object **objs)
 {
+#define CHECK_HAS(field) (check && check->field)
 	const struct drm_format_info *info;
 	int i;
 
@@ -231,24 +271,34 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,
 		unsigned int min_size;
 		u32 pitch = mode_cmd->pitches[i];
 
-		if (check && check->use_pitch_multiplier)
+		if (CHECK_HAS(use_pitch_multiplier))
 			if ((pitch * check->pitch_multiplier[i]) %
 			    check->pitch_modulo)
 				return -EINVAL;
 
-		if (check && check->use_min_size)
+		if (CHECK_HAS(use_min_size)) {
 			min_size = check->min_size[i];
-		else
+		} else if (CHECK_HAS(data) &&
+				drm_is_afbc(mode_cmd->modifier[0])) {
+			struct drm_afbc *afbc;
+			int ret;
+
+			afbc = check->data;
+			ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc);
+			if (ret < 0)
+				return ret;
+			min_size = ret;
+		} else {
 			min_size = (height - 1) * pitch
 				 + drm_format_info_min_pitch(info, i, width)
 				 + mode_cmd->offsets[i];
-
+		}
 		if (objs[i]->size < min_size)
 			return -EINVAL;
 	}
 
 	return 0;
-
+#undef CHECK_HAS
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
 
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index 74304a268694..3d6015194b3c 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -22,6 +22,22 @@ struct drm_size_check {
 	u32 pitch_multiplier[4];
 	u32 pitch_modulo;
 	bool use_pitch_multiplier;
+	void *data;
+};
+
+/**
+ * struct drm_afbc - AFBC-specific data.
+ */
+struct drm_afbc {
+	u32 block_width;
+	u32 block_height;
+	u32 aligned_width;
+	u32 aligned_height;
+	u32 offset;
+	u32 alignment_header;
+	u32 afbc_size;
+	u32 offset_payload;
+	u32 bpp;
 };
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (4 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 17:33   ` Daniel Vetter
  2019-12-13 15:58 ` [PATCHv4 07/36] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
                   ` (29 subsequent siblings)
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Some drivers might want to use the modifier_info field of struct
drm_framebuffer to hold struct drm_afbc. The memory for the latter must
be managed by the driver. To eliminate the need to modify existing
invocations of kfree(fb), add a function to allocate struct drm_framebuffer
and its associated struct drm_afbc in one chunk.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 32 ++++++++++++++++++++
 include/drm/drm_gem_framebuffer_helper.h     |  1 +
 2 files changed, 33 insertions(+)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index e20f4d00b0a5..0338f303f988 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -21,6 +21,13 @@
 #include <drm/drm_modeset_helper.h>
 #include <drm/drm_simple_kms_helper.h>
 
+#define DRM_ALIGN_MASK(type) \
+	(__alignof__(type) - 1)
+#define DRM_INFO_OFFSET(type1, type2)	\
+	((sizeof(type1) + DRM_ALIGN_MASK(type2)) & ~DRM_ALIGN_MASK(type2))
+#define DRM_COMPOUND_SIZE(type1, type2) \
+	(DRM_INFO_OFFSET(type1, type2) + sizeof(type2))
+
 #define AFBC_HEADER_SIZE		16
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_SUPERBLOCK_PIXELS		256
@@ -59,6 +66,31 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
 
+/**
+ * drm_gem_fb_alloc_with_afbc() - Allocate struct drm_framebuffer together
+ *				  with a struct drm_afbc for easier freeing
+ *				  and assign drm_framebuffer's modifier_info
+ *
+ * Returns:
+ * Pointer to drm_framebuffer on success or NULL
+ */
+struct drm_framebuffer *drm_gem_fb_alloc_with_afbc(void)
+{
+	struct drm_framebuffer *fb;
+
+	/* alloc in one chunk to ease freeing */
+	fb = kzalloc(DRM_COMPOUND_SIZE(struct drm_framebuffer, struct drm_afbc),
+		     GFP_KERNEL);
+	if (!fb)
+		return NULL;
+
+	fb->modifier_info =
+		fb + DRM_INFO_OFFSET(struct drm_framebuffer, struct drm_afbc);
+
+	return fb;
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_alloc_with_afbc);
+
 int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
 			       struct drm_device *dev,
 			       const struct drm_mode_fb_cmd2 *mode_cmd,
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index 3d6015194b3c..4e7b1e2c765b 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -42,6 +42,7 @@ struct drm_afbc {
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 					  unsigned int plane);
+struct drm_framebuffer *drm_gem_fb_alloc_with_afbc(void);
 int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
 			       struct drm_device *dev,
 			       const struct drm_mode_fb_cmd2 *mode_cmd,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 07/36] drm/komeda: Use afbc helper
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (5 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 08/36] drm/komeda: Move checking src coordinates to komeda_fb_create Andrzej Pietrasiewicz
                   ` (28 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Makes the code shorter and more readable.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 1b01a625f40e..7487c6cf6636 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -52,20 +52,9 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 		return -ENOENT;
 	}
 
-	switch (fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
-	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
-		alignment_w = 32;
-		alignment_h = 8;
-		break;
-	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
-		alignment_w = 16;
-		alignment_h = 16;
-		break;
-	default:
-		WARN(1, "Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
-		     fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
-		break;
-	}
+	if (!drm_afbc_get_superblock_wh(fb->modifier,
+					&alignment_w, &alignment_h))
+		return -EINVAL;
 
 	/* tiled header afbc */
 	if (fb->modifier & AFBC_FORMAT_MOD_TILED) {
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 08/36] drm/komeda: Move checking src coordinates to komeda_fb_create
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (6 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 07/36] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 09/36] drm/komeda: Use the already available local variable Andrzej Pietrasiewicz
                   ` (27 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Next step towards unifying afbc and non-afbc cases as much as possible.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 7487c6cf6636..aa477d1dddc3 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -107,9 +107,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,
 	u32 i, block_h;
 	u64 min_size;
 
-	if (komeda_fb_check_src_coords(kfb, 0, 0, fb->width, fb->height))
-		return -EINVAL;
-
 	for (i = 0; i < info->num_planes; i++) {
 		obj = drm_gem_object_lookup(file, mode_cmd->handles[i]);
 		if (!obj) {
@@ -168,10 +165,17 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
 
-	if (kfb->base.modifier)
+	if (kfb->base.modifier) {
 		ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd);
-	else
+	} else {
+		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
+					       kfb->base.height)) {
+			kfree(kfb);
+			return ERR_PTR(-EINVAL);
+		}
+
 		ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd);
+	}
 	if (ret < 0)
 		goto err_cleanup;
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 09/36] drm/komeda: Use the already available local variable
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (7 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 08/36] drm/komeda: Move checking src coordinates to komeda_fb_create Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 10/36] drm/komeda: Retrieve drm_format_info once Andrzej Pietrasiewicz
                   ` (26 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

There is a local "info" variable which is exactly fb->format, so use it.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index aa477d1dddc3..bb1b43a64685 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -131,7 +131,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,
 		}
 	}
 
-	if (fb->format->num_planes == 3) {
+	if (info->num_planes == 3) {
 		if (fb->pitches[1] != fb->pitches[2]) {
 			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
 			return -EINVAL;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 10/36] drm/komeda: Retrieve drm_format_info once
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (8 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 09/36] drm/komeda: Use the already available local variable Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 11/36] drm/komeda: Explicitly require 1 plane for AFBC Andrzej Pietrasiewicz
                   ` (25 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Next step towards unifying afbc and non-afbc cases as much as possible.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index bb1b43a64685..ce96389e3c40 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -37,11 +37,12 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 };
 
 static int
-komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
+komeda_fb_afbc_size_check(struct komeda_fb *kfb,
+			  const struct drm_format_info *info,
+			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
 	struct drm_framebuffer *fb = &kfb->base;
-	const struct drm_format_info *info = fb->format;
 	struct drm_gem_object *obj;
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
 	u64 min_size;
@@ -97,12 +98,13 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 }
 
 static int
-komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,
+komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
+			       struct komeda_fb *kfb,
+			       const struct drm_format_info *info,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
 	struct drm_framebuffer *fb = &kfb->base;
-	const struct drm_format_info *info = fb->format;
 	struct drm_gem_object *obj;
 	u32 i, block_h;
 	u64 min_size;
@@ -147,6 +149,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 {
 	struct komeda_dev *mdev = dev->dev_private;
 	struct komeda_fb *kfb;
+	const struct drm_format_info *info;
 	int ret = 0, i;
 
 	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
@@ -164,9 +167,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	}
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
+	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
-		ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd);
+		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
 	} else {
 		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 					       kfb->base.height)) {
@@ -174,7 +178,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			return ERR_PTR(-EINVAL);
 		}
 
-		ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd);
+		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file,
+						     mode_cmd);
 	}
 	if (ret < 0)
 		goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 11/36] drm/komeda: Explicitly require 1 plane for AFBC
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (9 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 10/36] drm/komeda: Retrieve drm_format_info once Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 12/36] drm/komeda: Move pitches comparison to komeda_fb_create Andrzej Pietrasiewicz
                   ` (24 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Apparently komeda silently assumes that there is only 1 plane in an AFBC
buffer. Make this assumption explicit.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index ce96389e3c40..157b73005ef8 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -170,6 +170,11 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
+		if (info->num_planes != 1) {
+			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
+			kfree(kfb);
+			return ERR_PTR(-EINVAL);
+		}
 		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
 	} else {
 		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 12/36] drm/komeda: Move pitches comparison to komeda_fb_create
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (10 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 11/36] drm/komeda: Explicitly require 1 plane for AFBC Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 13/36] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Andrzej Pietrasiewicz
                   ` (23 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

For AFBC case num_planes equals 1 so the check will not affect it.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 157b73005ef8..4fa01b2e3f1c 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -133,13 +133,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 		}
 	}
 
-	if (info->num_planes == 3) {
-		if (fb->pitches[1] != fb->pitches[2]) {
-			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
-			return -EINVAL;
-		}
-	}
-
 	return 0;
 }
 
@@ -189,6 +182,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (ret < 0)
 		goto err_cleanup;
 
+	if (info->num_planes == 3)
+		if (kfb->base.pitches[1] != kfb->base.pitches[2]) {
+			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
 	ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs);
 	if (ret < 0) {
 		DRM_DEBUG_KMS("failed to initialize fb\n");
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 13/36] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (11 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 12/36] drm/komeda: Move pitches comparison to komeda_fb_create Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 14/36] drm/komeda: Factor out object lookups for non-afbc case Andrzej Pietrasiewicz
                   ` (22 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Add a variant of the function which doesn't need neither
struct drm_framebuffer nor container_of it. Maintain current interface
for existing users.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 68 +++++++++++++++----
 .../arm/display/komeda/komeda_framebuffer.h   |  7 ++
 2 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 4fa01b2e3f1c..00860a66ebf1 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -124,7 +124,12 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 			return -EINVAL;
 		}
 
-		min_size = komeda_fb_get_pixel_addr(kfb, 0, fb->height, i)
+		min_size = komeda_fb_get_pixel_addr_nofb(info,
+							 mode_cmd->modifier[0],
+							 mode_cmd->pitches,
+							 mode_cmd->offsets,
+							 obj,
+							 0, mode_cmd->height, i)
 			 - to_drm_gem_cma_obj(obj)->paddr;
 		if (obj->size < min_size) {
 			DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n",
@@ -238,12 +243,56 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb,
 	return 0;
 }
 
+dma_addr_t
+komeda_fb_get_pixel_addr_impl(const struct drm_format_info *format,
+			      u64 modifier,
+			      const unsigned int *pitches,
+			      const unsigned int *offsets,
+			      const struct drm_gem_cma_object *obj,
+			      int x, int y, int plane)
+{
+	u32 offset, plane_x, plane_y, block_w, block_sz;
+
+	offset = offsets[plane];
+	if (modifier) {
+		block_w = drm_format_info_block_width(format, plane);
+		block_sz = format->char_per_block[plane];
+		plane_x = x / (plane ? format->hsub : 1);
+		plane_y = y / (plane ? format->vsub : 1);
+
+		offset += (plane_x / block_w) * block_sz
+			+ plane_y * pitches[plane];
+	}
+
+	return obj->paddr + offset;
+}
+
+dma_addr_t
+komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format,
+			      u64 modifier,
+			      const unsigned int *pitches,
+			      const unsigned int *offsets,
+			      struct drm_gem_object *obj,
+			      int x, int y, int plane)
+{
+	const struct drm_gem_cma_object *cma_obj;
+
+	if (plane >= format->num_planes) {
+		DRM_DEBUG_KMS("Out of max plane num.\n");
+		return -EINVAL;
+	}
+
+	cma_obj = to_drm_gem_cma_obj(obj);
+
+	return komeda_fb_get_pixel_addr_impl(format, modifier, pitches, offsets,
+					     cma_obj, x, y, plane);
+}
+
 dma_addr_t
 komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane)
 {
 	struct drm_framebuffer *fb = &kfb->base;
 	const struct drm_gem_cma_object *obj;
-	u32 offset, plane_x, plane_y, block_w, block_sz;
 
 	if (plane >= fb->format->num_planes) {
 		DRM_DEBUG_KMS("Out of max plane num.\n");
@@ -252,18 +301,9 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane)
 
 	obj = drm_fb_cma_get_gem_obj(fb, plane);
 
-	offset = fb->offsets[plane];
-	if (!fb->modifier) {
-		block_w = drm_format_info_block_width(fb->format, plane);
-		block_sz = fb->format->char_per_block[plane];
-		plane_x = x / (plane ? fb->format->hsub : 1);
-		plane_y = y / (plane ? fb->format->vsub : 1);
-
-		offset += (plane_x / block_w) * block_sz
-			+ plane_y * fb->pitches[plane];
-	}
-
-	return obj->paddr + offset;
+	return komeda_fb_get_pixel_addr_impl(fb->format, fb->modifier,
+					     fb->pitches, fb->offsets,
+					     obj, x, y, plane);
 }
 
 /* if the fb can be supported by a specific layer */
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
index c61ca98a3a63..2f1f421d3e7f 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
@@ -42,6 +42,13 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb,
 			       u32 src_x, u32 src_y, u32 src_w, u32 src_h);
 dma_addr_t
 komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane);
+dma_addr_t
+komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format,
+			      u64 modifier,
+			      const unsigned int *pitches,
+			      const unsigned int *offsets,
+			      struct drm_gem_object *obj,
+			      int x, int y, int plane);
 bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type,
 		u32 rot);
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 14/36] drm/komeda: Factor out object lookups for non-afbc case
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (12 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 13/36] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 15/36] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Andrzej Pietrasiewicz
                   ` (21 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Ultimately we want lookups happening only once in komeda's fb_create
implementation.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 00860a66ebf1..d4e0df00180e 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -101,6 +101,7 @@ static int
 komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 			       struct komeda_fb *kfb,
 			       const struct drm_format_info *info,
+			       struct drm_gem_object **objs,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
@@ -110,12 +111,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 	u64 min_size;
 
 	for (i = 0; i < info->num_planes; i++) {
-		obj = drm_gem_object_lookup(file, mode_cmd->handles[i]);
-		if (!obj) {
-			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-			return -ENOENT;
-		}
-		fb->obj[i] = obj;
+		obj = objs[i];
 
 		block_h = drm_format_info_block_height(info, i);
 		if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) {
@@ -175,14 +171,23 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		}
 		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
 	} else {
+		struct drm_gem_object *objs[4];
+
 		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 					       kfb->base.height)) {
 			kfree(kfb);
 			return ERR_PTR(-EINVAL);
 		}
+		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+		if (ret < 0) {
+			kfree(kfb);
+			return ERR_PTR(ret);
+		}
 
-		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file,
-						     mode_cmd);
+		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs,
+						     file, mode_cmd);
+		for (i = 0; i < info->num_planes; ++i)
+			kfb->base.obj[i] = objs[i];
 	}
 	if (ret < 0)
 		goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 15/36] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (13 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 14/36] drm/komeda: Factor out object lookups for non-afbc case Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 16/36] drm/komeda: Factor out object lookups for afbc case Andrzej Pietrasiewicz
                   ` (20 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

All necessary data is now available in other data structures.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index d4e0df00180e..07520cec6fbd 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -99,13 +99,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 
 static int
 komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
-			       struct komeda_fb *kfb,
 			       const struct drm_format_info *info,
 			       struct drm_gem_object **objs,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	struct drm_framebuffer *fb = &kfb->base;
 	struct drm_gem_object *obj;
 	u32 i, block_h;
 	u64 min_size;
@@ -114,9 +112,10 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 		obj = objs[i];
 
 		block_h = drm_format_info_block_height(info, i);
-		if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) {
+		if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) {
 			DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n",
-				      i, fb->pitches[i], mdev->chip.bus_width);
+				      i, mode_cmd->pitches[i],
+				      mdev->chip.bus_width);
 			return -EINVAL;
 		}
 
@@ -184,7 +183,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			return ERR_PTR(ret);
 		}
 
-		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs,
+		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
 		for (i = 0; i < info->num_planes; ++i)
 			kfb->base.obj[i] = objs[i];
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 16/36] drm/komeda: Factor out object lookups for afbc case
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (14 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 15/36] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 17/36] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Andrzej Pietrasiewicz
                   ` (19 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Ultimately we want lookups happening only once in komeda's fb_create
implementation.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 30 +++++++++++--------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 07520cec6fbd..4e29fa5bd342 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -39,6 +39,7 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 static int
 komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 			  const struct drm_format_info *info,
+			  struct drm_gem_object **objs,
 			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
@@ -47,11 +48,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
 	u64 min_size;
 
-	obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
-	if (!obj) {
-		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-		return -ENOENT;
-	}
+	obj = objs[0];
 
 	if (!drm_afbc_get_superblock_wh(fb->modifier,
 					&alignment_w, &alignment_h))
@@ -71,7 +68,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 
 	if (fb->offsets[0] % alignment_header) {
 		DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
-		goto check_failed;
+		return -EINVAL;
 	}
 
 	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
@@ -86,15 +83,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	if (min_size > obj->size) {
 		DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n",
 			      obj->size, min_size);
-		goto check_failed;
+		return -EINVAL;
 	}
 
-	fb->obj[0] = obj;
 	return 0;
-
-check_failed:
-	drm_gem_object_put_unlocked(obj);
-	return -EINVAL;
 }
 
 static int
@@ -163,12 +155,24 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
+		struct drm_gem_object *objs[4];
+
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			kfree(kfb);
 			return ERR_PTR(-EINVAL);
 		}
-		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
+
+		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+		if (ret < 0) {
+			kfree(kfb);
+			return ERR_PTR(ret);
+		}
+
+		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
+						mode_cmd);
+		for (i = 0; i < info->num_planes; ++i)
+			kfb->base.obj[i] = objs[i];
 	} else {
 		struct drm_gem_object *objs[4];
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 17/36] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (15 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 16/36] drm/komeda: Factor out object lookups for afbc case Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 18/36] drm/komeda: Simplify error handling Andrzej Pietrasiewicz
                   ` (18 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

It does still depend on komeda_fb, but only for komeda-specific parameters.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c   | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 4e29fa5bd342..cc9dc8588e8d 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -43,19 +43,18 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	struct drm_framebuffer *fb = &kfb->base;
 	struct drm_gem_object *obj;
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
 	u64 min_size;
 
 	obj = objs[0];
 
-	if (!drm_afbc_get_superblock_wh(fb->modifier,
+	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
 					&alignment_w, &alignment_h))
 		return -EINVAL;
 
 	/* tiled header afbc */
-	if (fb->modifier & AFBC_FORMAT_MOD_TILED) {
+	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
 		alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
 		alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
 		alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
@@ -63,10 +62,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 		alignment_header = AFBC_BODY_START_ALIGNMENT;
 	}
 
-	kfb->aligned_w = ALIGN(fb->width, alignment_w);
-	kfb->aligned_h = ALIGN(fb->height, alignment_h);
+	kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
+	kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
 
-	if (fb->offsets[0] % alignment_header) {
+	if (mode_cmd->offsets[0] % alignment_header) {
 		DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
 		return -EINVAL;
 	}
@@ -75,11 +74,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
 				    alignment_header);
 
-	bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
+	bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
 	kfb->afbc_size = kfb->offset_payload + n_blocks *
 			 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
 			       AFBC_SUPERBLK_ALIGNMENT);
-	min_size = kfb->afbc_size + fb->offsets[0];
+	min_size = kfb->afbc_size + mode_cmd->offsets[0];
 	if (min_size > obj->size) {
 		DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n",
 			      obj->size, min_size);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 18/36] drm/komeda: Simplify error handling
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (16 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 17/36] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 19/36] drm/komeda: Move object lookup before size checks Andrzej Pietrasiewicz
                   ` (17 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use less code to handle errors.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 32 ++++++++-----------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index cc9dc8588e8d..6325b20e661d 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -146,8 +146,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (!kfb->format_caps) {
 		DRM_DEBUG_KMS("FMT %x is not supported.\n",
 			      mode_cmd->pixel_format);
-		kfree(kfb);
-		return ERR_PTR(-EINVAL);
+		ret = -EINVAL;
+		goto err_free;
 	}
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
@@ -158,15 +158,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
-			kfree(kfb);
-			return ERR_PTR(-EINVAL);
+			ret = -EINVAL;
+			goto err_free;
 		}
 
 		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0) {
-			kfree(kfb);
-			return ERR_PTR(ret);
-		}
+		if (ret < 0)
+			goto err_free;
 
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
@@ -175,16 +173,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	} else {
 		struct drm_gem_object *objs[4];
 
-		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
-					       kfb->base.height)) {
-			kfree(kfb);
-			return ERR_PTR(-EINVAL);
-		}
+		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
+						 kfb->base.height);
+		if (ret)
+			goto err_free;
+
 		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0) {
-			kfree(kfb);
-			return ERR_PTR(ret);
-		}
+		if (ret < 0)
+			goto err_free;
 
 		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
@@ -215,7 +211,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 err_cleanup:
 	for (i = 0; i < kfb->base.format->num_planes; i++)
 		drm_gem_object_put_unlocked(kfb->base.obj[i]);
-
+err_free:
 	kfree(kfb);
 	return ERR_PTR(ret);
 }
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 19/36] drm/komeda: Move object lookup before size checks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (17 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 18/36] drm/komeda: Simplify error handling Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 20/36] drm/komeda: Move object assignments to framebuffer to after " Andrzej Pietrasiewicz
                   ` (16 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The lookup is performed the same way in both branches of the "if"
statement, so move the lookup to before the "if". err_cleanup case
is adjusted accordingly.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 23 +++++++------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 6325b20e661d..b923e2b6c523 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -132,6 +132,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
 {
 	struct komeda_dev *mdev = dev->dev_private;
+	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
 	const struct drm_format_info *info;
 	int ret = 0, i;
@@ -150,37 +151,29 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		goto err_free;
 	}
 
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		goto err_free;
+
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
 	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
-		struct drm_gem_object *objs[4];
-
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
-			goto err_free;
+			goto err_cleanup;
 		}
 
-		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0)
-			goto err_free;
-
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
 		for (i = 0; i < info->num_planes; ++i)
 			kfb->base.obj[i] = objs[i];
 	} else {
-		struct drm_gem_object *objs[4];
-
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 						 kfb->base.height);
 		if (ret)
-			goto err_free;
-
-		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0)
-			goto err_free;
+			goto err_cleanup;
 
 		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
@@ -210,7 +203,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 err_cleanup:
 	for (i = 0; i < kfb->base.format->num_planes; i++)
-		drm_gem_object_put_unlocked(kfb->base.obj[i]);
+		drm_gem_object_put_unlocked(objs[i]);
 err_free:
 	kfree(kfb);
 	return ERR_PTR(ret);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 20/36] drm/komeda: Move object assignments to framebuffer to after size checks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (18 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 19/36] drm/komeda: Move object lookup before size checks Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 21/36] drm/komeda: Make the size checks independent from framebuffer structure Andrzej Pietrasiewicz
                   ` (15 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The assignments are the same in both branches of the "if" statement and
nothing depends on them between their original position and the new
position, so this can be safely done.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index b923e2b6c523..4c78ae1a4845 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -167,8 +167,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
-		for (i = 0; i < info->num_planes; ++i)
-			kfb->base.obj[i] = objs[i];
 	} else {
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 						 kfb->base.height);
@@ -177,8 +175,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
-		for (i = 0; i < info->num_planes; ++i)
-			kfb->base.obj[i] = objs[i];
 	}
 	if (ret < 0)
 		goto err_cleanup;
@@ -190,6 +186,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
+	for (i = 0; i < info->num_planes; ++i)
+		kfb->base.obj[i] = objs[i];
+
 	ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs);
 	if (ret < 0) {
 		DRM_DEBUG_KMS("failed to initialize fb\n");
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 21/36] drm/komeda: Make the size checks independent from framebuffer structure
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (19 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 20/36] drm/komeda: Move object assignments to framebuffer to after " Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 22/36] drm/komeda: Move helper invocation to after size checks Andrzej Pietrasiewicz
                   ` (14 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The same data is available in mode_cmd.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 4c78ae1a4845..ab067f89533c 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -156,9 +156,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		goto err_free;
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
-	info = kfb->base.format;
+	info = drm_get_format_info(dev, mode_cmd);
 
-	if (kfb->base.modifier) {
+	if (mode_cmd->modifier[0]) {
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
@@ -168,8 +168,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
 	} else {
-		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
-						 kfb->base.height);
+		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
+						 mode_cmd->height);
 		if (ret)
 			goto err_cleanup;
 
@@ -180,7 +180,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		goto err_cleanup;
 
 	if (info->num_planes == 3)
-		if (kfb->base.pitches[1] != kfb->base.pitches[2]) {
+		if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) {
 			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
 			ret = -EINVAL;
 			goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 22/36] drm/komeda: Move helper invocation to after size checks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (20 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 21/36] drm/komeda: Make the size checks independent from framebuffer structure Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 23/36] drm/komeda: Use helper for common tasks Andrzej Pietrasiewicz
                   ` (13 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Between the old and new place nothing depends on data retrieved with the
helper, so it is safe to move its invocation.
The err_cleanup case is changed accordingly.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index ab067f89533c..1a03318ec73a 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -155,7 +155,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (ret < 0)
 		goto err_free;
 
-	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
@@ -186,6 +185,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
+	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
+
 	for (i = 0; i < info->num_planes; ++i)
 		kfb->base.obj[i] = objs[i];
 
@@ -201,7 +202,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	return &kfb->base;
 
 err_cleanup:
-	for (i = 0; i < kfb->base.format->num_planes; i++)
+	for (i = 0; i < info->num_planes; i++)
 		drm_gem_object_put_unlocked(objs[i]);
 err_free:
 	kfree(kfb);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 23/36] drm/komeda: Use helper for common tasks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (21 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 22/36] drm/komeda: Move helper invocation to after size checks Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 24/36] drm/komeda: Use return value of drm_gem_fb_lookup Andrzej Pietrasiewicz
                   ` (12 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The replaced fragment is 1:1 with the helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 1a03318ec73a..74c0caa51bdf 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -185,17 +185,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
-	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
-
-	for (i = 0; i < info->num_planes; ++i)
-		kfb->base.obj[i] = objs[i];
-
-	ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs);
-	if (ret < 0) {
-		DRM_DEBUG_KMS("failed to initialize fb\n");
-
+	ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs,
+					 info->num_planes, &komeda_fb_funcs);
+	if (ret < 0)
 		goto err_cleanup;
-	}
 
 	kfb->is_va = mdev->iommu ? true : false;
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 24/36] drm/komeda: Use return value of drm_gem_fb_lookup
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (22 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 23/36] drm/komeda: Use helper for common tasks Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 25/36] drm/komeda: Use special helper for non-afbc size checks Andrzej Pietrasiewicz
                   ` (11 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Reduce dependency of the function on the "info" variable as much as
possible.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 74c0caa51bdf..6ac4a599ab5d 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -135,7 +135,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
 	const struct drm_format_info *info;
-	int ret = 0, i;
+	int ret = 0, i, num_planes;
 
 	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
 	if (!kfb)
@@ -154,11 +154,12 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
 	if (ret < 0)
 		goto err_free;
+	num_planes = ret;
 
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
-		if (info->num_planes != 1) {
+		if (num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
@@ -178,7 +179,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (ret < 0)
 		goto err_cleanup;
 
-	if (info->num_planes == 3)
+	if (num_planes == 3)
 		if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) {
 			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
 			ret = -EINVAL;
@@ -186,7 +187,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		}
 
 	ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs,
-					 info->num_planes, &komeda_fb_funcs);
+					 num_planes, &komeda_fb_funcs);
 	if (ret < 0)
 		goto err_cleanup;
 
@@ -195,7 +196,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	return &kfb->base;
 
 err_cleanup:
-	for (i = 0; i < info->num_planes; i++)
+	for (i = 0; i < num_planes; i++)
 		drm_gem_object_put_unlocked(objs[i]);
 err_free:
 	kfree(kfb);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 25/36] drm/komeda: Use special helper for non-afbc size checks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (23 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 24/36] drm/komeda: Use return value of drm_gem_fb_lookup Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 26/36] drm/komeda: Factor in the invocation of special helper Andrzej Pietrasiewicz
                   ` (10 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use the generic helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 46 +++++++++----------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 6ac4a599ab5d..77186f70bdf3 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -89,42 +89,38 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 }
 
 static int
-komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
+komeda_fb_none_afbc_size_check(struct drm_device *dev,
 			       const struct drm_format_info *info,
 			       struct drm_gem_object **objs,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+	struct komeda_dev *mdev = dev->dev_private;
+	struct drm_size_check check = { 0 };
 	struct drm_gem_object *obj;
-	u32 i, block_h;
-	u64 min_size;
+	u32 i;
 
 	for (i = 0; i < info->num_planes; i++) {
 		obj = objs[i];
 
-		block_h = drm_format_info_block_height(info, i);
-		if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) {
-			DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n",
-				      i, mode_cmd->pitches[i],
-				      mdev->chip.bus_width);
-			return -EINVAL;
-		}
-
-		min_size = komeda_fb_get_pixel_addr_nofb(info,
-							 mode_cmd->modifier[0],
-							 mode_cmd->pitches,
-							 mode_cmd->offsets,
-							 obj,
-							 0, mode_cmd->height, i)
-			 - to_drm_gem_cma_obj(obj)->paddr;
-		if (obj->size < min_size) {
-			DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n",
-				      i, obj->size, min_size);
-			return -EINVAL;
-		}
+		check.pitch_multiplier[i] =
+			drm_format_info_block_height(info, i);
+
+		check.min_size[i] =
+			komeda_fb_get_pixel_addr_nofb(info,
+						      mode_cmd->modifier[0],
+						      mode_cmd->pitches,
+						      mode_cmd->offsets,
+						      obj,
+						      0, mode_cmd->height, i)
+			- to_drm_gem_cma_obj(obj)->paddr;
 	}
 
-	return 0;
+	check.pitch_modulo = mdev->chip.bus_width;
+	check.use_pitch_multiplier = true;
+	check.use_min_size = true;
+
+	return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
 }
 
 struct drm_framebuffer *
@@ -173,7 +169,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		if (ret)
 			goto err_cleanup;
 
-		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
+		ret = komeda_fb_none_afbc_size_check(dev, info, objs,
 						     file, mode_cmd);
 	}
 	if (ret < 0)
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 26/36] drm/komeda: Factor in the invocation of special helper
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (24 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 25/36] drm/komeda: Use special helper for non-afbc size checks Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 27/36] drm/komeda: Use special helper for afbc case size check Andrzej Pietrasiewicz
                   ` (9 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Don't use a separate function to call the helper. The ultimate goal is
to unify non-afbc and afbc cases as much as possible and then moving the
helper invocation outside the if-else clause.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 58 +++++++------------
 1 file changed, 21 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 77186f70bdf3..6898407d1b63 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -88,41 +88,6 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	return 0;
 }
 
-static int
-komeda_fb_none_afbc_size_check(struct drm_device *dev,
-			       const struct drm_format_info *info,
-			       struct drm_gem_object **objs,
-			       struct drm_file *file,
-			       const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	struct komeda_dev *mdev = dev->dev_private;
-	struct drm_size_check check = { 0 };
-	struct drm_gem_object *obj;
-	u32 i;
-
-	for (i = 0; i < info->num_planes; i++) {
-		obj = objs[i];
-
-		check.pitch_multiplier[i] =
-			drm_format_info_block_height(info, i);
-
-		check.min_size[i] =
-			komeda_fb_get_pixel_addr_nofb(info,
-						      mode_cmd->modifier[0],
-						      mode_cmd->pitches,
-						      mode_cmd->offsets,
-						      obj,
-						      0, mode_cmd->height, i)
-			- to_drm_gem_cma_obj(obj)->paddr;
-	}
-
-	check.pitch_modulo = mdev->chip.bus_width;
-	check.use_pitch_multiplier = true;
-	check.use_min_size = true;
-
-	return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
-}
-
 struct drm_framebuffer *
 komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -164,13 +129,32 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
 	} else {
+		struct drm_size_check check = { 0 };
+
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
 						 mode_cmd->height);
 		if (ret)
 			goto err_cleanup;
 
-		ret = komeda_fb_none_afbc_size_check(dev, info, objs,
-						     file, mode_cmd);
+		for (i = 0; i < num_planes; i++) {
+			check.pitch_multiplier[i] =
+				drm_format_info_block_height(info, i);
+
+			check.min_size[i] =
+				komeda_fb_get_pixel_addr_nofb(info,
+					mode_cmd->modifier[0],
+					mode_cmd->pitches,
+					mode_cmd->offsets, objs[i],
+					0, mode_cmd->height, i)
+				- to_drm_gem_cma_obj(objs[i])->paddr;
+		}
+
+		check.pitch_modulo = mdev->chip.bus_width;
+		check.use_pitch_multiplier = true;
+		check.use_min_size = true;
+
+		ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check,
+						    objs);
 	}
 	if (ret < 0)
 		goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 27/36] drm/komeda: Use special helper for afbc case size check
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (25 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 26/36] drm/komeda: Factor in the invocation of special helper Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:58 ` [PATCHv4 28/36] drm/komeda: Factor in the invocation of special helper, afbc case Andrzej Pietrasiewicz
                   ` (8 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use generic helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 22 +++++++------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 6898407d1b63..e55ab6130e15 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -37,17 +37,15 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 };
 
 static int
-komeda_fb_afbc_size_check(struct komeda_fb *kfb,
+komeda_fb_afbc_size_check(struct drm_device *dev,
+			  struct komeda_fb *kfb,
 			  const struct drm_format_info *info,
 			  struct drm_gem_object **objs,
 			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	struct drm_gem_object *obj;
+	struct drm_size_check check = { 0 };
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
-	u64 min_size;
-
-	obj = objs[0];
 
 	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
 					&alignment_w, &alignment_h))
@@ -78,14 +76,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	kfb->afbc_size = kfb->offset_payload + n_blocks *
 			 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
 			       AFBC_SUPERBLK_ALIGNMENT);
-	min_size = kfb->afbc_size + mode_cmd->offsets[0];
-	if (min_size > obj->size) {
-		DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n",
-			      obj->size, min_size);
-		return -EINVAL;
-	}
+	check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
+	check.use_min_size = true;
 
-	return 0;
+	return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
 }
 
 struct drm_framebuffer *
@@ -126,8 +120,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
-		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
-						mode_cmd);
+		ret = komeda_fb_afbc_size_check(dev, kfb, info, objs,
+						file, mode_cmd);
 	} else {
 		struct drm_size_check check = { 0 };
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 28/36] drm/komeda: Factor in the invocation of special helper, afbc case
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (26 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 27/36] drm/komeda: Use special helper for afbc case size check Andrzej Pietrasiewicz
@ 2019-12-13 15:58 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 29/36] drm/komeda: Move special helper invocation outside if-else Andrzej Pietrasiewicz
                   ` (7 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:58 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Prepare for unification with non-afbc case.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 90 +++++++++----------
 1 file changed, 42 insertions(+), 48 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index e55ab6130e15..ac7e099435c9 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -36,52 +36,6 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 	.create_handle	= komeda_fb_create_handle,
 };
 
-static int
-komeda_fb_afbc_size_check(struct drm_device *dev,
-			  struct komeda_fb *kfb,
-			  const struct drm_format_info *info,
-			  struct drm_gem_object **objs,
-			  struct drm_file *file,
-			  const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	struct drm_size_check check = { 0 };
-	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
-
-	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
-					&alignment_w, &alignment_h))
-		return -EINVAL;
-
-	/* tiled header afbc */
-	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
-		alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
-		alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
-		alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
-	} else {
-		alignment_header = AFBC_BODY_START_ALIGNMENT;
-	}
-
-	kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
-	kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
-
-	if (mode_cmd->offsets[0] % alignment_header) {
-		DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
-		return -EINVAL;
-	}
-
-	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
-				    alignment_header);
-
-	bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
-	kfb->afbc_size = kfb->offset_payload + n_blocks *
-			 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
-			       AFBC_SUPERBLK_ALIGNMENT);
-	check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
-	check.use_min_size = true;
-
-	return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
-}
-
 struct drm_framebuffer *
 komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -114,14 +68,54 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
+		struct drm_size_check check = { 0 };
+		u32 alignment_w = 0, alignment_h = 0;
+		u32 alignment_header, n_blocks, bpp;
+
 		if (num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
 		}
 
-		ret = komeda_fb_afbc_size_check(dev, kfb, info, objs,
-						file, mode_cmd);
+		if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
+						&alignment_w, &alignment_h)) {
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+		/* tiled header afbc */
+		if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
+			alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
+			alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
+			alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
+		} else {
+			alignment_header = AFBC_BODY_START_ALIGNMENT;
+		}
+
+		kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
+		kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
+
+		if (mode_cmd->offsets[0] % alignment_header) {
+			DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+		n_blocks = (kfb->aligned_w * kfb->aligned_h)
+			 / AFBC_SUPERBLK_PIXELS;
+		kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
+					    alignment_header);
+
+		bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
+		kfb->afbc_size = kfb->offset_payload + n_blocks *
+				 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
+				       AFBC_SUPERBLK_ALIGNMENT);
+		check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
+		check.use_min_size = true;
+
+		ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check,
+						    objs);
 	} else {
 		struct drm_size_check check = { 0 };
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 29/36] drm/komeda: Move special helper invocation outside if-else
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (27 preceding siblings ...)
  2019-12-13 15:58 ` [PATCHv4 28/36] drm/komeda: Factor in the invocation of special helper, afbc case Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 30/36] drm/komeda: Move to helper checking afbc buffer size Andrzej Pietrasiewicz
                   ` (6 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The invocation is the same in both cases and is the last thing inside a
block, so move it outside the if-else clause.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c  | 12 +++---------
 1 file changed, 3 insertions(+), 9 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index ac7e099435c9..385df1fd776d 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -44,6 +44,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
 	const struct drm_format_info *info;
+	struct drm_size_check check = { 0 };
+
 	int ret = 0, i, num_planes;
 
 	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
@@ -68,7 +70,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
-		struct drm_size_check check = { 0 };
 		u32 alignment_w = 0, alignment_h = 0;
 		u32 alignment_header, n_blocks, bpp;
 
@@ -113,12 +114,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 				       AFBC_SUPERBLK_ALIGNMENT);
 		check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
 		check.use_min_size = true;
-
-		ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check,
-						    objs);
 	} else {
-		struct drm_size_check check = { 0 };
-
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
 						 mode_cmd->height);
 		if (ret)
@@ -140,10 +136,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		check.pitch_modulo = mdev->chip.bus_width;
 		check.use_pitch_multiplier = true;
 		check.use_min_size = true;
-
-		ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check,
-						    objs);
 	}
+	ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
 	if (ret < 0)
 		goto err_cleanup;
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 30/36] drm/komeda: Move to helper checking afbc buffer size
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (28 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 29/36] drm/komeda: Move special helper invocation outside if-else Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 31/36] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
                   ` (5 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use generic helper code. Adapt struct komeda_fb users to new location
of respective data members.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/d71/d71_component.c    |  7 ++-
 .../arm/display/komeda/komeda_framebuffer.c   | 60 +++++++++----------
 .../arm/display/komeda/komeda_framebuffer.h   |  8 ---
 .../display/komeda/komeda_pipeline_state.c    | 11 ++--
 4 files changed, 39 insertions(+), 47 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
index 8a02ade369db..bab015f13ef3 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
@@ -4,6 +4,8 @@
  * Author: James.Qian.Wang <james.qian.wang@arm.com>
  *
  */
+#include <linux/types.h>
+#include <drm/drm_gem_framebuffer_helper.h>
 #include "d71_dev.h"
 #include "komeda_kms.h"
 #include "malidp_io.h"
@@ -234,9 +236,10 @@ static void d71_layer_update(struct komeda_component *c,
 							     st->afbc_crop_b));
 		/* afbc 1.2 wants payload, afbc 1.0/1.1 wants end_addr */
 		if (fb->modifier & AFBC_FORMAT_MOD_TILED)
-			addr = st->addr[0] + kfb->offset_payload;
+			addr = st->addr[0]
+			     + kfb->base.afbc_info->offset_payload;
 		else
-			addr = st->addr[0] + kfb->afbc_size - 1;
+			addr = st->addr[0] + kfb->base.afbc_info->afbc_size - 1;
 
 		malidp_write32(reg, BLK_P1_PTR_LOW, lower_32_bits(addr));
 		malidp_write32(reg, BLK_P1_PTR_HIGH, upper_32_bits(addr));
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 385df1fd776d..d3e0f2c0d924 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -40,6 +40,13 @@ struct drm_framebuffer *
 komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+#define KFB_ALIGN_MASK(type) \
+	(__alignof__(type) - 1)
+#define KFB_INFO_OFFSET(type1, type2)	\
+	((sizeof(type1) + KFB_ALIGN_MASK(type2)) & ~KFB_ALIGN_MASK(type2))
+#define KFB_COMPOUND_SIZE(type1, type2) \
+	(KFB_INFO_OFFSET(type1, type2) + sizeof(type2))
+
 	struct komeda_dev *mdev = dev->dev_private;
 	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
@@ -48,9 +55,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 	int ret = 0, i, num_planes;
 
-	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
+	/* alloc in one chunk to ease freeing */
+	kfb = kzalloc(KFB_COMPOUND_SIZE(struct komeda_fb, struct drm_afbc),
+					GFP_KERNEL);
 	if (!kfb)
 		return ERR_PTR(-ENOMEM);
+	kfb->base.modifier_info =
+		kfb + KFB_INFO_OFFSET(struct komeda_fb, struct drm_afbc);
 
 	kfb->format_caps = komeda_get_format_caps(&mdev->fmt_tbl,
 						  mode_cmd->pixel_format,
@@ -70,50 +81,30 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
-		u32 alignment_w = 0, alignment_h = 0;
-		u32 alignment_header, n_blocks, bpp;
-
 		if (num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
 		}
 
-		if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
-						&alignment_w, &alignment_h)) {
-			ret = -EINVAL;
-			goto err_cleanup;
-		}
-
 		/* tiled header afbc */
-		if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
-			alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
-			alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
-			alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
-		} else {
-			alignment_header = AFBC_BODY_START_ALIGNMENT;
-		}
-
-		kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
-		kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
-
-		if (mode_cmd->offsets[0] % alignment_header) {
+		if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED)
+			kfb->base.afbc_info->alignment_header =
+				AFBC_TH_BODY_START_ALIGNMENT;
+		else
+			kfb->base.afbc_info->alignment_header =
+				AFBC_BODY_START_ALIGNMENT;
+
+		if (mode_cmd->offsets[0] %
+			kfb->base.afbc_info->alignment_header) {
 			DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
 		}
 
-		n_blocks = (kfb->aligned_w * kfb->aligned_h)
-			 / AFBC_SUPERBLK_PIXELS;
-		kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
-					    alignment_header);
-
-		bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
-		kfb->afbc_size = kfb->offset_payload + n_blocks *
-				 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
-				       AFBC_SUPERBLK_ALIGNMENT);
-		check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
-		check.use_min_size = true;
+		kfb->base.afbc_info->bpp =
+			komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
+		check.data = kfb->base.afbc_info;
 	} else {
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
 						 mode_cmd->height);
@@ -163,6 +154,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 err_free:
 	kfree(kfb);
 	return ERR_PTR(ret);
+#undef KFB_ALIGN_MASK
+#undef KFB_INFO_OFFSET
+#undef KFB_COMPOUND_SIZE
 }
 
 int komeda_fb_check_src_coords(const struct komeda_fb *kfb,
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
index 2f1f421d3e7f..9e7af1cc0f12 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
@@ -23,14 +23,6 @@ struct komeda_fb {
 	const struct komeda_format_caps *format_caps;
 	/** @is_va: if smmu is enabled, it will be true */
 	bool is_va;
-	/** @aligned_w: aligned frame buffer width */
-	u32 aligned_w;
-	/** @aligned_h: aligned frame buffer height */
-	u32 aligned_h;
-	/** @afbc_size: minimum size of afbc */
-	u32 afbc_size;
-	/** @offset_payload: start of afbc body buffer */
-	u32 offset_payload;
 };
 
 #define to_kfb(dfb)	container_of(dfb, struct komeda_fb, base)
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
index 0930234abb9d..281ec5b8d722 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
@@ -6,6 +6,7 @@
  */
 
 #include <drm/drm_print.h>
+#include <drm/drm_gem_framebuffer_helper.h>
 #include <linux/clk.h>
 #include "komeda_dev.h"
 #include "komeda_kms.h"
@@ -360,12 +361,14 @@ komeda_layer_validate(struct komeda_layer *layer,
 	st->rot = dflow->rot;
 
 	if (fb->modifier) {
-		st->hsize = kfb->aligned_w;
-		st->vsize = kfb->aligned_h;
+		st->hsize = kfb->base.afbc_info->aligned_width;
+		st->vsize = kfb->base.afbc_info->aligned_height;
 		st->afbc_crop_l = dflow->in_x;
-		st->afbc_crop_r = kfb->aligned_w - dflow->in_x - dflow->in_w;
+		st->afbc_crop_r = kfb->base.afbc_info->aligned_width
+				- dflow->in_x - dflow->in_w;
 		st->afbc_crop_t = dflow->in_y;
-		st->afbc_crop_b = kfb->aligned_h - dflow->in_y - dflow->in_h;
+		st->afbc_crop_b = kfb->base.afbc_info->aligned_height
+				- dflow->in_y - dflow->in_h;
 	} else {
 		st->hsize = dflow->in_w;
 		st->vsize = dflow->in_h;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 31/36] drm/arm/malidp: Make verify funcitons invocations independent
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (29 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 30/36] drm/komeda: Move to helper checking afbc buffer size Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 32/36] drm/arm/malidp: Integrate verify functions Andrzej Pietrasiewicz
                   ` (4 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

This will make it easier to transition to generic afbc-aware helpers.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 37d92a06318e..961e5a3f5b08 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -362,10 +362,10 @@ static bool
 malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
-		return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
+	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
+		return false;
 
-	return false;
+	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
 }
 
 static struct drm_framebuffer *
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 32/36] drm/arm/malidp: Integrate verify functions
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (30 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 31/36] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 33/36] drm/arm/malidp: Factor in afbc framebuffer verification Andrzej Pietrasiewicz
                   ` (3 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The next step towards using generic afbc-aware helpers.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 961e5a3f5b08..e1502666bce0 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -270,9 +270,16 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = {
 };
 
 static bool
-malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
-				    const struct drm_mode_fb_cmd2 *mode_cmd)
+malidp_verify_afbc_framebuffer(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;
+
 	if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
 					mode_cmd->modifier[0]) == false)
 		return false;
@@ -294,21 +301,6 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
 		return false;
 	}
 
-	return true;
-}
-
-static bool
-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;
@@ -358,16 +350,6 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
 	return true;
 }
 
-static bool
-malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
-			       const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
-		return false;
-
-	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
-}
-
 static struct drm_framebuffer *
 malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 33/36] drm/arm/malidp: Factor in afbc framebuffer verification
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (31 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 32/36] drm/arm/malidp: Integrate verify functions Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 34/36] drm/arm/malidp: Use generic helpers for afbc checks Andrzej Pietrasiewicz
                   ` (2 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Prepare for using generic afbc-aware helpers.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index e1502666bce0..b53fc01baf2b 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -269,94 +269,88 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = {
 	.atomic_commit_tail = malidp_atomic_commit_tail,
 };
 
-static bool
-malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
-			       const struct drm_mode_fb_cmd2 *mode_cmd)
+static struct drm_framebuffer *
+malidp_fb_create(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;
-
-	if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
-					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;
-	}
+	if (mode_cmd->modifier[0]) {
+		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;
+
+		if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
+						mode_cmd->modifier[0]) == false)
+			return ERR_PTR(-EINVAL);
 
-	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;
+		if (mode_cmd->offsets[0] != 0) {
+			DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
+			return ERR_PTR(-EINVAL);
 		}
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
 
-	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;
-	}
+		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 ERR_PTR(-EINVAL);
+			}
+			break;
+		default:
+			DRM_DEBUG_KMS("Unsupported AFBC block size\n");
+			return ERR_PTR(-EINVAL);
+		}
 
-	info = drm_get_format_info(dev, mode_cmd);
+		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 ERR_PTR(-EINVAL);
+		}
 
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
+		info = drm_get_format_info(dev, mode_cmd);
 
-	bpp = malidp_format_get_bpp(info->format);
+		n_superblocks = (mode_cmd->width / afbc_superblock_width) *
+			(mode_cmd->height / afbc_superblock_height);
 
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
+		bpp = malidp_format_get_bpp(info->format);
 
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
+		afbc_superblock_size =
+			(bpp * afbc_superblock_width * afbc_superblock_height)
+			/ BITS_PER_BYTE;
 
-	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;
-	}
+		afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE,
+				  AFBC_SUPERBLK_ALIGNMENT);
+		afbc_size += n_superblocks
+			* ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
 
-	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);
-		drm_gem_object_put_unlocked(objs);
-		return false;
-	}
-
-	drm_gem_object_put_unlocked(objs);
+		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 ERR_PTR(-EINVAL);
+		}
 
-	return true;
-}
+		objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
+		if (!objs) {
+			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+			return ERR_PTR(-EINVAL);
+		}
 
-static struct drm_framebuffer *
-malidp_fb_create(struct drm_device *dev, struct drm_file *file,
-		 const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	if (mode_cmd->modifier[0]) {
-		if (!malidp_verify_afbc_framebuffer(dev, file, mode_cmd))
+		if (objs->size < afbc_size) {
+			DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+				      objs->size, afbc_size);
+			drm_gem_object_put_unlocked(objs);
 			return ERR_PTR(-EINVAL);
+		}
+
+		drm_gem_object_put_unlocked(objs);
 	}
 
 	return drm_gem_fb_create(dev, file, mode_cmd);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 34/36] drm/arm/malidp: Use generic helpers for afbc checks
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (32 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 33/36] drm/arm/malidp: Factor in afbc framebuffer verification Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 35/36] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 36/36] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Helpers are now available for checking afbc buffer properties. Use those.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index b53fc01baf2b..e49ce6d5d987 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -273,12 +273,17 @@ static struct drm_framebuffer *
 malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+	struct drm_size_check check = { 0 };
+	struct drm_gem_object *objs[4];
+	struct drm_framebuffer *fb;
+	int ret, i, num_planes;
+
+	fb = drm_gem_fb_alloc_with_afbc();
+	if (!fb)
+		return ERR_PTR(-ENOMEM);
+
 	if (mode_cmd->modifier[0]) {
-		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;
 
 		if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
@@ -302,32 +307,9 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 			return ERR_PTR(-EINVAL);
 		}
 
-		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 ERR_PTR(-EINVAL);
-		}
-
 		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) "
@@ -336,24 +318,31 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 				      mode_cmd->width, bpp);
 			return ERR_PTR(-EINVAL);
 		}
+		fb->afbc_info->bpp = bpp;
+		check.data = fb->afbc_info;
+	}
 
-		objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
-		if (!objs) {
-			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-			return ERR_PTR(-EINVAL);
-		}
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		goto err_free;
+	num_planes = ret;
 
-		if (objs->size < afbc_size) {
-			DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
-				      objs->size, afbc_size);
-			drm_gem_object_put_unlocked(objs);
-			return ERR_PTR(-EINVAL);
-		}
+	ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
+	if (ret < 0)
+		goto err_cleanup;
 
-		drm_gem_object_put_unlocked(objs);
-	}
+	ret = drm_gem_fb_init(fb, dev, mode_cmd, objs, num_planes);
+	if (ret < 0)
+		goto err_cleanup;
+
+	return fb;
 
-	return drm_gem_fb_create(dev, file, mode_cmd);
+err_cleanup:
+	for (i = 0; i < num_planes; ++i)
+		drm_gem_object_put_unlocked(objs[i]);
+err_free:
+	kfree(fb);
+	return ERR_PTR(ret);
 }
 
 static const struct drm_mode_config_funcs malidp_mode_config_funcs = {
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 35/36] drm/rockchip: Use helper for common task
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (33 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 34/36] drm/arm/malidp: Use generic helpers for afbc checks Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  2019-12-13 15:59 ` [PATCHv4 36/36] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use generic helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
index 221e72e71432..28ce3a335798 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
@@ -18,6 +18,7 @@
 #include "rockchip_drm_fb.h"
 #include "rockchip_drm_gem.h"
 
+
 static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
 	.destroy       = drm_gem_fb_destroy,
 	.create_handle = drm_gem_fb_create_handle,
@@ -30,22 +31,14 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm
 {
 	struct drm_framebuffer *fb;
 	int ret;
-	int i;
 
 	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
 	if (!fb)
 		return ERR_PTR(-ENOMEM);
 
-	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
-
-	for (i = 0; i < num_planes; i++)
-		fb->obj[i] = obj[i];
-
-	ret = drm_framebuffer_init(dev, fb, &rockchip_drm_fb_funcs);
+	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
+					 &rockchip_drm_fb_funcs);
 	if (ret) {
-		DRM_DEV_ERROR(dev->dev,
-			      "Failed to initialize framebuffer: %d\n",
-			      ret);
 		kfree(fb);
 		return ERR_PTR(ret);
 	}
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv4 36/36] drm/rockchip: Add support for afbc
  2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
                   ` (34 preceding siblings ...)
  2019-12-13 15:59 ` [PATCHv4 35/36] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
@ 2019-12-13 15:59 ` Andrzej Pietrasiewicz
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-13 15:59 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

This patch adds support for afbc handling. afbc is a compressed format
which reduces the necessary memory bandwidth.

Co-developed-by: Mark Yao <mark.yao@rock-chips.com>
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  | 100 +++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 141 +++++++++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c |  84 +++++++++++-
 4 files changed, 331 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
index 28ce3a335798..0c4014763356 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
@@ -18,6 +18,7 @@
 #include "rockchip_drm_fb.h"
 #include "rockchip_drm_gem.h"
 
+#define ROCKCHIP_MAX_AFBC_WIDTH	2560
 
 static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
 	.destroy       = drm_gem_fb_destroy,
@@ -25,17 +26,60 @@ static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
 	.dirty	       = drm_atomic_helper_dirtyfb,
 };
 
+static int rockchip_afbc_post_check(struct drm_afbc *afbc)
+{
+	if (afbc->offset) {
+		DRM_WARN("AFBC plane offset must be zero!\n");
+		return -EINVAL;
+	}
+
+	if (afbc->block_width != 16 || afbc->block_height != 16) {
+		DRM_WARN("Unsupported AFBC block w/h [%d/%d]\n",
+			 afbc->block_width, afbc->block_height);
+		return -EINVAL;
+	}
+
+	if (afbc->aligned_width > ROCKCHIP_MAX_AFBC_WIDTH) {
+		DRM_WARN("Unsupported width %d>%d\n",
+			 afbc->aligned_width, ROCKCHIP_MAX_AFBC_WIDTH);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static struct drm_framebuffer *
 rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
 		  struct drm_gem_object **obj, unsigned int num_planes)
 {
 	struct drm_framebuffer *fb;
+	struct drm_size_check check = { 0 };
 	int ret;
 
-	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
+	fb = drm_gem_fb_alloc_with_afbc();
 	if (!fb)
 		return ERR_PTR(-ENOMEM);
 
+	if (drm_is_afbc(mode_cmd->modifier[0])) {
+		const struct drm_format_info *info =
+			drm_get_format_info(dev, mode_cmd);
+
+		fb->afbc_info->bpp = info->cpp[0] * 8;
+		check.data = fb->afbc_info;
+	}
+
+	ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, obj);
+	if (ret) {
+		kfree(fb);
+		return ERR_PTR(ret);
+	}
+
+	if (drm_is_afbc(mode_cmd->modifier[0]))
+		if (rockchip_afbc_post_check(fb->afbc_info)) {
+			kfree(fb);
+			return ERR_PTR(-EINVAL);
+		}
+
 	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
 					 &rockchip_drm_fb_funcs);
 	if (ret) {
@@ -50,8 +94,60 @@ static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers =
 	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
 };
 
+
+static struct drm_framebuffer *
+rockchip_fb_create(struct drm_device *dev, struct drm_file *file,
+		   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct drm_framebuffer *fb;
+	struct drm_size_check check = { 0 };
+	struct drm_gem_object *objs[4];
+	int ret, i, num_planes;
+
+	fb = drm_gem_fb_alloc_with_afbc();
+	if (!fb)
+		return ERR_PTR(-ENOMEM);
+
+	if (drm_is_afbc(mode_cmd->modifier[0])) {
+		const struct drm_format_info *info =
+			drm_get_format_info(dev, mode_cmd);
+
+		fb->afbc_info->bpp = info->cpp[0] * 8;
+		check.data = fb->afbc_info;
+	}
+
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		goto err_free;
+	num_planes = ret;
+
+	ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs);
+	if (ret)
+		goto err_cleanup;
+
+	if (drm_is_afbc(mode_cmd->modifier[0]))
+		if (rockchip_afbc_post_check(fb->afbc_info)) {
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, objs, num_planes,
+					 &rockchip_drm_fb_funcs);
+	if (ret)
+		goto err_cleanup;
+
+	return fb;
+
+err_cleanup:
+	for (i = 0; i < num_planes; ++i)
+		drm_gem_object_put_unlocked(objs[i]);
+err_free:
+	kfree(fb);
+	return ERR_PTR(ret);
+}
+
 static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = {
-	.fb_create = drm_gem_fb_create_with_dirty,
+	.fb_create = rockchip_fb_create,
 	.output_poll_changed = drm_fb_helper_output_poll_changed,
 	.atomic_check = drm_atomic_helper_check,
 	.atomic_commit = drm_atomic_helper_commit,
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index d04b3492bdac..745d1e8e6d3c 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -91,9 +91,22 @@
 #define VOP_WIN_TO_INDEX(vop_win) \
 	((vop_win) - (vop_win)->vop->win)
 
+#define VOP_AFBC_SET(vop, name, v) \
+	do { \
+		if ((vop)->data->afbc) \
+			vop_reg_set((vop), &(vop)->data->afbc->name, \
+				0, ~0, v, #name); \
+	} while (0)
+
 #define to_vop(x) container_of(x, struct vop, crtc)
 #define to_vop_win(x) container_of(x, struct vop_win, base)
 
+#define AFBC_FMT_RGB565		0x0
+#define AFBC_FMT_U8U8U8U8	0x5
+#define AFBC_FMT_U8U8U8		0x4
+
+#define AFBC_TILE_16x16		BIT(4)
+
 /*
  * The coefficients of the following matrix are all fixed points.
  * The format is S2.10 for the 3x3 part of the matrix, and S9.12 for the offsets.
@@ -166,6 +179,7 @@ struct vop {
 	/* optional internal rgb encoder */
 	struct rockchip_rgb *rgb;
 
+	struct vop_win *afbc_win;
 	struct vop_win win[];
 };
 
@@ -274,6 +288,29 @@ static enum vop_data_format vop_convert_format(uint32_t format)
 	}
 }
 
+static int vop_convert_afbc_format(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_ABGR8888:
+		return AFBC_FMT_U8U8U8U8;
+	case DRM_FORMAT_RGB888:
+	case DRM_FORMAT_BGR888:
+		return AFBC_FMT_U8U8U8;
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+		return AFBC_FMT_RGB565;
+	/* either of the below should not be reachable */
+	default:
+		DRM_WARN_ONCE("unsupported AFBC format[%08x]\n", format);
+		return -EINVAL;
+	}
+
+	return -EINVAL;
+}
+
 static uint16_t scl_vop_cal_scale(enum scale_mode mode, uint32_t src,
 				  uint32_t dst, bool is_horizontal,
 				  int vsu_mode, int *vskiplines)
@@ -598,6 +635,15 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
 			vop_win_disable(vop, vop_win);
 		}
 	}
+
+	if (vop->data->afbc) {
+		/*
+		 * Disable AFBC and forget there was a vop window with AFBC
+		 */
+		VOP_AFBC_SET(vop, enable, 0);
+		vop->afbc_win = NULL;
+	}
+
 	spin_unlock(&vop->reg_lock);
 
 	vop_cfg_done(vop);
@@ -710,6 +756,39 @@ static void vop_plane_destroy(struct drm_plane *plane)
 	drm_plane_cleanup(plane);
 }
 
+static bool rockchip_afbc(u64 modifier)
+{
+	return modifier ==
+		DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
+		AFBC_FORMAT_MOD_SPARSE);
+}
+
+static bool rockchip_mod_supported(struct drm_plane *plane,
+				   u32 format, u64 modifier)
+{
+	const struct drm_format_info *info;
+
+	if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
+		return false;
+
+	if (modifier == DRM_FORMAT_MOD_LINEAR)
+		return true;
+
+	if (!rockchip_afbc(modifier)) {
+		DRM_DEBUG_KMS("Unsupported format modifer 0x%llx\n", modifier);
+
+		return false;
+	}
+
+	info = drm_format_info(format);
+	if (info->num_planes != 1) {
+		DRM_DEBUG_KMS("AFBC buffers expect one plane\n");
+		return false;
+	}
+
+	return true;
+}
+
 static int vop_plane_atomic_check(struct drm_plane *plane,
 			   struct drm_plane_state *state)
 {
@@ -758,6 +837,32 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
 		return -EINVAL;
 	}
 
+	if (rockchip_afbc(fb->modifier)) {
+		struct vop *vop = to_vop(crtc);
+
+		if (!vop->data->afbc) {
+			DRM_ERROR("vop does not support AFBC\n");
+			return -EINVAL;
+		}
+
+		ret = vop_convert_afbc_format(fb->format->format);
+		if (ret < 0)
+			return ret;
+
+		if (state->src.x1 || state->src.y1) {
+			DRM_ERROR("afbc does not support offset display\n");
+			DRM_ERROR("xpos=%d, ypos=%d, offset=%d\n",
+				  state->src.x1, state->src.y1, fb->offsets[0]);
+			return -EINVAL;
+		}
+
+		if (state->rotation && state->rotation != DRM_MODE_ROTATE_0) {
+			DRM_ERROR("afbc does not support rotation\n");
+			DRM_ERROR("rotation=%d\n", state->rotation);
+			return -EINVAL;
+		}
+	}
+
 	return 0;
 }
 
@@ -773,6 +878,11 @@ static void vop_plane_atomic_disable(struct drm_plane *plane,
 	spin_lock(&vop->reg_lock);
 
 	vop_win_disable(vop, vop_win);
+	/*
+	 * Forget about the AFBC window if it is being disabled
+	 */
+	if (vop_win == vop->afbc_win)
+		vop->afbc_win = NULL;
 
 	spin_unlock(&vop->reg_lock);
 }
@@ -812,6 +922,13 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
 	if (WARN_ON(!vop->is_enabled))
 		return;
 
+	/*
+	 * If updating the AFBC window then assume that
+	 * after the update there will be no AFBC window.
+	 */
+	if (vop_win == vop->afbc_win)
+		vop->afbc_win = NULL;
+
 	if (!state->visible) {
 		vop_plane_atomic_disable(plane, old_state);
 		return;
@@ -846,6 +963,21 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
 
 	spin_lock(&vop->reg_lock);
 
+	if (rockchip_afbc(fb->modifier)) {
+		int afbc_format = vop_convert_afbc_format(fb->format->format);
+
+		VOP_AFBC_SET(vop, format, afbc_format | AFBC_TILE_16x16);
+		VOP_AFBC_SET(vop, hreg_block_split, 0);
+		VOP_AFBC_SET(vop, win_sel, VOP_WIN_TO_INDEX(vop_win));
+		VOP_AFBC_SET(vop, hdr_ptr, dma_addr);
+		VOP_AFBC_SET(vop, pic_size, act_info);
+
+		/*
+		 * The window being udated becomes the AFBC window
+		 */
+		vop->afbc_win = vop_win;
+	}
+
 	VOP_WIN_SET(vop, win, format, format);
 	VOP_WIN_SET(vop, win, yrgb_vir, DIV_ROUND_UP(fb->pitches[0], 4));
 	VOP_WIN_SET(vop, win, yrgb_mst, dma_addr);
@@ -1001,6 +1133,7 @@ static const struct drm_plane_funcs vop_plane_funcs = {
 	.reset = drm_atomic_helper_plane_reset,
 	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
+	.format_mod_supported = rockchip_mod_supported,
 };
 
 static int vop_crtc_enable_vblank(struct drm_crtc *crtc)
@@ -1340,6 +1473,8 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc,
 
 	spin_lock(&vop->reg_lock);
 
+	/* Enable AFBC if there is some AFBC window, disable otherwise. */
+	VOP_AFBC_SET(vop, enable, vop->afbc_win != NULL);
 	vop_cfg_done(vop);
 
 	spin_unlock(&vop->reg_lock);
@@ -1634,7 +1769,8 @@ static int vop_create_crtc(struct vop *vop)
 					       0, &vop_plane_funcs,
 					       win_data->phy->data_formats,
 					       win_data->phy->nformats,
-					       NULL, win_data->type, NULL);
+					       win_data->phy->format_modifiers,
+					       win_data->type, NULL);
 		if (ret) {
 			DRM_DEV_ERROR(vop->dev, "failed to init plane %d\n",
 				      ret);
@@ -1678,7 +1814,8 @@ static int vop_create_crtc(struct vop *vop)
 					       &vop_plane_funcs,
 					       win_data->phy->data_formats,
 					       win_data->phy->nformats,
-					       NULL, win_data->type, NULL);
+					       win_data->phy->format_modifiers,
+					       win_data->type, NULL);
 		if (ret) {
 			DRM_DEV_ERROR(vop->dev, "failed to init overlay %d\n",
 				      ret);
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h
index 0b3d18c457b2..3f4e88a783d2 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h
@@ -34,6 +34,16 @@ struct vop_reg {
 	bool relaxed;
 };
 
+struct vop_afbc {
+	struct vop_reg enable;
+	struct vop_reg win_sel;
+	struct vop_reg format;
+	struct vop_reg hreg_block_split;
+	struct vop_reg pic_size;
+	struct vop_reg hdr_ptr;
+	struct vop_reg rstn;
+};
+
 struct vop_modeset {
 	struct vop_reg htotal_pw;
 	struct vop_reg hact_st_end;
@@ -134,6 +144,7 @@ struct vop_win_phy {
 	const struct vop_scl_regs *scl;
 	const uint32_t *data_formats;
 	uint32_t nformats;
+	const uint64_t *format_modifiers;
 
 	struct vop_reg enable;
 	struct vop_reg gate;
@@ -173,6 +184,7 @@ struct vop_data {
 	const struct vop_misc *misc;
 	const struct vop_modeset *modeset;
 	const struct vop_output *output;
+	const struct vop_afbc *afbc;
 	const struct vop_win_yuv2yuv_data *win_yuv2yuv;
 	const struct vop_win_data *win;
 	unsigned int win_size;
diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
index 7a9d979c8d5d..f0cf1b04591d 100644
--- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
+++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
@@ -50,6 +50,18 @@ static const uint32_t formats_win_full[] = {
 	DRM_FORMAT_NV24,
 };
 
+static const uint64_t format_modifiers_win_full[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID,
+};
+
+static const uint64_t format_modifiers_win_full_afbc[] = {
+	DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
+				AFBC_FORMAT_MOD_SPARSE),
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID,
+};
+
 static const uint32_t formats_win_lite[] = {
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_ARGB8888,
@@ -61,6 +73,11 @@ static const uint32_t formats_win_lite[] = {
 	DRM_FORMAT_BGR565,
 };
 
+static const uint64_t format_modifiers_win_lite[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID,
+};
+
 static const struct vop_scl_regs rk3036_win_scl = {
 	.scale_yrgb_x = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 0x0),
 	.scale_yrgb_y = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 16),
@@ -72,6 +89,7 @@ static const struct vop_win_phy rk3036_win0_data = {
 	.scl = &rk3036_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 0),
 	.format = VOP_REG(RK3036_SYS_CTRL, 0x7, 3),
 	.rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 15),
@@ -87,6 +105,7 @@ static const struct vop_win_phy rk3036_win0_data = {
 static const struct vop_win_phy rk3036_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1),
 	.format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6),
 	.rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19),
@@ -153,6 +172,7 @@ static const struct vop_data rk3036_vop = {
 static const struct vop_win_phy rk3126_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1),
 	.format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6),
 	.rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19),
@@ -234,6 +254,7 @@ static const struct vop_win_phy px30_win0_data = {
 	.scl = &px30_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(PX30_WIN0_CTRL0, 0x1, 0),
 	.format = VOP_REG(PX30_WIN0_CTRL0, 0x7, 1),
 	.rb_swap = VOP_REG(PX30_WIN0_CTRL0, 0x1, 12),
@@ -249,6 +270,7 @@ static const struct vop_win_phy px30_win0_data = {
 static const struct vop_win_phy px30_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(PX30_WIN1_CTRL0, 0x1, 0),
 	.format = VOP_REG(PX30_WIN1_CTRL0, 0x7, 4),
 	.rb_swap = VOP_REG(PX30_WIN1_CTRL0, 0x1, 12),
@@ -261,6 +283,7 @@ static const struct vop_win_phy px30_win1_data = {
 static const struct vop_win_phy px30_win2_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.gate = VOP_REG(PX30_WIN2_CTRL0, 0x1, 4),
 	.enable = VOP_REG(PX30_WIN2_CTRL0, 0x1, 0),
 	.format = VOP_REG(PX30_WIN2_CTRL0, 0x3, 5),
@@ -316,6 +339,7 @@ static const struct vop_win_phy rk3066_win0_data = {
 	.scl = &rk3066_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 0),
 	.format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 4),
 	.rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 19),
@@ -332,6 +356,7 @@ static const struct vop_win_phy rk3066_win1_data = {
 	.scl = &rk3066_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 1),
 	.format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 7),
 	.rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 23),
@@ -347,6 +372,7 @@ static const struct vop_win_phy rk3066_win1_data = {
 static const struct vop_win_phy rk3066_win2_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 2),
 	.format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 10),
 	.rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 27),
@@ -426,6 +452,7 @@ static const struct vop_win_phy rk3188_win0_data = {
 	.scl = &rk3188_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 0),
 	.format = VOP_REG(RK3188_SYS_CTRL, 0x7, 3),
 	.rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 15),
@@ -440,6 +467,7 @@ static const struct vop_win_phy rk3188_win0_data = {
 static const struct vop_win_phy rk3188_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 1),
 	.format = VOP_REG(RK3188_SYS_CTRL, 0x7, 6),
 	.rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 19),
@@ -545,6 +573,7 @@ static const struct vop_win_phy rk3288_win01_data = {
 	.scl = &rk3288_win_full_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0),
 	.format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1),
 	.rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12),
@@ -563,6 +592,7 @@ static const struct vop_win_phy rk3288_win01_data = {
 static const struct vop_win_phy rk3288_win23_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 4),
 	.gate = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 0),
 	.format = VOP_REG(RK3288_WIN2_CTRL0, 0x7, 1),
@@ -677,6 +707,7 @@ static const struct vop_win_phy rk3368_win01_data = {
 	.scl = &rk3288_win_full_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 0),
 	.format = VOP_REG(RK3368_WIN0_CTRL0, 0x7, 1),
 	.rb_swap = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 12),
@@ -697,6 +728,7 @@ static const struct vop_win_phy rk3368_win01_data = {
 static const struct vop_win_phy rk3368_win23_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.gate = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 0),
 	.enable = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 4),
 	.format = VOP_REG(RK3368_WIN2_CTRL0, 0x3, 5),
@@ -817,6 +849,53 @@ static const struct vop_win_yuv2yuv_data rk3399_vop_big_win_yuv2yuv_data[] = {
 	  .y2r_en = VOP_REG(RK3399_YUV2YUV_WIN, 0x1, 9) },
 	{ .base = 0xC0, .phy = &rk3399_yuv2yuv_win23_data },
 	{ .base = 0x120, .phy = &rk3399_yuv2yuv_win23_data },
+
+};
+
+static const struct vop_win_phy rk3399_win01_data = {
+	.scl = &rk3288_win_full_scl,
+	.data_formats = formats_win_full,
+	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full_afbc,
+	.enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0),
+	.format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1),
+	.rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12),
+	.y_mir_en = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 22),
+	.act_info = VOP_REG(RK3288_WIN0_ACT_INFO, 0x1fff1fff, 0),
+	.dsp_info = VOP_REG(RK3288_WIN0_DSP_INFO, 0x0fff0fff, 0),
+	.dsp_st = VOP_REG(RK3288_WIN0_DSP_ST, 0x1fff1fff, 0),
+	.yrgb_mst = VOP_REG(RK3288_WIN0_YRGB_MST, 0xffffffff, 0),
+	.uv_mst = VOP_REG(RK3288_WIN0_CBR_MST, 0xffffffff, 0),
+	.yrgb_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 0),
+	.uv_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 16),
+	.src_alpha_ctl = VOP_REG(RK3288_WIN0_SRC_ALPHA_CTRL, 0xff, 0),
+	.dst_alpha_ctl = VOP_REG(RK3288_WIN0_DST_ALPHA_CTRL, 0xff, 0),
+};
+
+/*
+ * rk3399 vop big windows register layout is same as rk3288, but we
+ * have a separate rk3399 win data array here so that we can advertise
+ * AFBC on the primary plane.
+ */
+static const struct vop_win_data rk3399_vop_win_data[] = {
+	{ .base = 0x00, .phy = &rk3399_win01_data,
+	  .type = DRM_PLANE_TYPE_PRIMARY },
+	{ .base = 0x40, .phy = &rk3288_win01_data,
+	  .type = DRM_PLANE_TYPE_OVERLAY },
+	{ .base = 0x00, .phy = &rk3288_win23_data,
+	  .type = DRM_PLANE_TYPE_OVERLAY },
+	{ .base = 0x50, .phy = &rk3288_win23_data,
+	  .type = DRM_PLANE_TYPE_CURSOR },
+};
+
+static const struct vop_afbc rk3399_vop_afbc = {
+	.rstn = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 3),
+	.enable = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 0),
+	.win_sel = VOP_REG(RK3399_AFBCD0_CTRL, 0x3, 1),
+	.format = VOP_REG(RK3399_AFBCD0_CTRL, 0x1f, 16),
+	.hreg_block_split = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 21),
+	.hdr_ptr = VOP_REG(RK3399_AFBCD0_HDR_PTR, 0xffffffff, 0),
+	.pic_size = VOP_REG(RK3399_AFBCD0_PIC_SIZE, 0xffffffff, 0),
 };
 
 static const struct vop_data rk3399_vop_big = {
@@ -826,9 +905,10 @@ static const struct vop_data rk3399_vop_big = {
 	.common = &rk3288_common,
 	.modeset = &rk3288_modeset,
 	.output = &rk3399_output,
+	.afbc = &rk3399_vop_afbc,
 	.misc = &rk3368_misc,
-	.win = rk3368_vop_win_data,
-	.win_size = ARRAY_SIZE(rk3368_vop_win_data),
+	.win = rk3399_vop_win_data,
+	.win_size = ARRAY_SIZE(rk3399_vop_win_data),
 	.win_yuv2yuv = rk3399_vop_big_win_yuv2yuv_data,
 };
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer
  2019-12-13 15:58 ` [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer Andrzej Pietrasiewicz
@ 2019-12-13 17:33   ` Daniel Vetter
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
  0 siblings, 1 reply; 106+ messages in thread
From: Daniel Vetter @ 2019-12-13 17:33 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	James Wang, dri-devel, Mihail Atanassov, Sean Paul

On Fri, Dec 13, 2019 at 04:58:37PM +0100, Andrzej Pietrasiewicz wrote:
> Some drivers might want to use the modifier_info field of struct
> drm_framebuffer to hold struct drm_afbc. The memory for the latter must
> be managed by the driver. To eliminate the need to modify existing
> invocations of kfree(fb), add a function to allocate struct drm_framebuffer
> and its associated struct drm_afbc in one chunk.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 32 ++++++++++++++++++++
>  include/drm/drm_gem_framebuffer_helper.h     |  1 +
>  2 files changed, 33 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index e20f4d00b0a5..0338f303f988 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -21,6 +21,13 @@
>  #include <drm/drm_modeset_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
>  
> +#define DRM_ALIGN_MASK(type) \
> +	(__alignof__(type) - 1)
> +#define DRM_INFO_OFFSET(type1, type2)	\
> +	((sizeof(type1) + DRM_ALIGN_MASK(type2)) & ~DRM_ALIGN_MASK(type2))
> +#define DRM_COMPOUND_SIZE(type1, type2) \
> +	(DRM_INFO_OFFSET(type1, type2) + sizeof(type2))
> +
>  #define AFBC_HEADER_SIZE		16
>  #define AFBC_TH_LAYOUT_ALIGNMENT	8
>  #define AFBC_SUPERBLOCK_PIXELS		256
> @@ -59,6 +66,31 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
>  
> +/**
> + * drm_gem_fb_alloc_with_afbc() - Allocate struct drm_framebuffer together
> + *				  with a struct drm_afbc for easier freeing
> + *				  and assign drm_framebuffer's modifier_info
> + *
> + * Returns:
> + * Pointer to drm_framebuffer on success or NULL
> + */
> +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc(void)
> +{
> +	struct drm_framebuffer *fb;
> +
> +	/* alloc in one chunk to ease freeing */
> +	fb = kzalloc(DRM_COMPOUND_SIZE(struct drm_framebuffer, struct drm_afbc),
> +		     GFP_KERNEL);
> +	if (!fb)
> +		return NULL;
> +
> +	fb->modifier_info =
> +		fb + DRM_INFO_OFFSET(struct drm_framebuffer, struct drm_afbc);

That's not how we do subclassing in general ... (so also no on patch 1).
What I mean here is:

struct drm_afbc {
	struct drm_framebuffer base;
	/* additional afbc information goes here, _not_ into struct
	 * drm_framebuffer */
}

#define drm_framebuffer_to_afbc(fb) container_of(fb, struct drm_afbc, base)

Both probably best stuffed into drm_plane.h

Aside from that style issue I think the core/helper work of this patch
series is getting there. But I didn't read the details (and probably wont
get to that before the new year because stuff and vacations).

Cheers, Daniel

> +
> +	return fb;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_alloc_with_afbc);
> +
>  int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
>  			       struct drm_device *dev,
>  			       const struct drm_mode_fb_cmd2 *mode_cmd,
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index 3d6015194b3c..4e7b1e2c765b 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -42,6 +42,7 @@ struct drm_afbc {
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc(void);
>  int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
>  			       struct drm_device *dev,
>  			       const struct drm_mode_fb_cmd2 *mode_cmd,
> -- 
> 2.17.1
> 

-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-13 15:58 ` [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
@ 2019-12-16 17:08   ` Liviu Dudau
  2019-12-16 20:37     ` Andrzej Pietrasiewicz
  2020-02-17  6:39   ` [PATCHv4,03/36] " james qian wang (Arm Technology China)
  1 sibling, 1 reply; 106+ messages in thread
From: Liviu Dudau @ 2019-12-16 17:08 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Sandy Huang, James Wang,
	dri-devel, Mihail Atanassov, Sean Paul

Hi Andrzej,

On Fri, Dec 13, 2019 at 04:58:34PM +0100, Andrzej Pietrasiewicz wrote:
> Prepare tools for drivers which need to allocate a struct drm_framebuffer
> (or a container of struct drm_framebuffer) explicitly, before calling
> helpers. In such a case we need new helpers which omit allocating the
> struct drm_framebuffer and this patch provides them. Consequently, they
> are used also inside the helpers themselves.
> 
> The interested drivers will likely need to be able to perform object
> lookups and size checks in separate invocations and this patch provides
> that as well. Helpers themselves are updated, too.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 184 ++++++++++++++-----
>  include/drm/drm_gem_framebuffer_helper.h     |  17 ++
>  2 files changed, 153 insertions(+), 48 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index b9bcd310ca2d..787edb9a916b 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
>  
> +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
> +			       struct drm_device *dev,
> +			       const struct drm_mode_fb_cmd2 *mode_cmd,
> +			       struct drm_gem_object **obj,
> +			       unsigned int num_planes,
> +			       const struct drm_framebuffer_funcs *funcs)
> +{
> +	int ret, i;
> +
> +	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> +
> +	for (i = 0; i < num_planes; i++)
> +		fb->obj[i] = obj[i];
> +
> +	ret = drm_framebuffer_init(dev, fb, funcs);
> +	if (ret)
> +		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
> +			      ret);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
> +
> +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
> +	.destroy	= drm_gem_fb_destroy,
> +	.create_handle	= drm_gem_fb_create_handle,
> +};
> +
> +int drm_gem_fb_init(struct drm_framebuffer *fb,
> +		    struct drm_device *dev,
> +		    const struct drm_mode_fb_cmd2 *mode_cmd,
> +		    struct drm_gem_object **obj, unsigned int num_planes)
> +{
> +	return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
> +					  &drm_gem_fb_funcs);
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_init);

If you export these two function they should better have documentation associated with them.

> +
>  static struct drm_framebuffer *
>  drm_gem_fb_alloc(struct drm_device *dev,
>  		 const struct drm_mode_fb_cmd2 *mode_cmd,
> @@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev,
>  		 const struct drm_framebuffer_funcs *funcs)
>  {
>  	struct drm_framebuffer *fb;
> -	int ret, i;
> +	int ret;
>  
>  	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
>  	if (!fb)
>  		return ERR_PTR(-ENOMEM);
>  
> -	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> -
> -	for (i = 0; i < num_planes; i++)
> -		fb->obj[i] = obj[i];
> -
> -	ret = drm_framebuffer_init(dev, fb, funcs);
> +	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
> +					 funcs);
>  	if (ret) {
> -		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
> -			      ret);
>  		kfree(fb);
>  		return ERR_PTR(ret);
>  	}
> @@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
>  EXPORT_SYMBOL(drm_gem_fb_create_handle);
>  
>  /**
> - * drm_gem_fb_create_with_funcs() - Helper function for the
> - *                                  &drm_mode_config_funcs.fb_create
> - *                                  callback
> + * drm_gem_fb_lookup() - Helper function for use in
> + *			 &drm_mode_config_funcs.fb_create implementations
>   * @dev: DRM device
>   * @file: DRM file that holds the GEM handle(s) backing the framebuffer
>   * @mode_cmd: Metadata from the userspace framebuffer creation request
> - * @funcs: vtable to be used for the new framebuffer object
>   *
> - * This function can be used to set &drm_framebuffer_funcs for drivers that need
> - * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
> - * change &drm_framebuffer_funcs. The function does buffer size validation.
> + * This function can be used to look up the objects for all planes.
> + * In case an error is returned all the objects are put by the
> + * function before returning.
>   *
>   * Returns:
> - * Pointer to a &drm_framebuffer on success or an error pointer on failure.
> + * Number of planes on success or a negative error code on failure.
>   */
> -struct drm_framebuffer *
> -drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
> -			     const struct drm_mode_fb_cmd2 *mode_cmd,
> -			     const struct drm_framebuffer_funcs *funcs)
> +int drm_gem_fb_lookup(struct drm_device *dev,
> +		      struct drm_file *file,
> +		      const struct drm_mode_fb_cmd2 *mode_cmd,
> +		      struct drm_gem_object **objs)
>  {
>  	const struct drm_format_info *info;
> -	struct drm_gem_object *objs[4];
> -	struct drm_framebuffer *fb;
>  	int ret, i;
>  
>  	info = drm_get_format_info(dev, mode_cmd);
>  	if (!info)
> -		return ERR_PTR(-EINVAL);
> +		return -EINVAL;
>  
>  	for (i = 0; i < info->num_planes; i++) {
> -		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> -		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> -		unsigned int min_size;
> -
>  		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
>  		if (!objs[i]) {
>  			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
>  			ret = -ENOENT;
>  			goto err_gem_object_put;
>  		}
> +	}
> +
> +	return i;
> +
> +err_gem_object_put:
> +	for (i--; i >= 0; i--)
> +		drm_gem_object_put_unlocked(objs[i]);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);

I'm surprised git generated this mess of a diff. Given that you still have
drm_gem_fb_create_with_funcs() further down, maybe you can re-order the functions so
that Git creates a more sane diff?

> +
> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)
> +{
> +	const struct drm_format_info *info;
> +	int i;
> +
> +	info = drm_get_format_info(dev, mode_cmd);
> +	if (!info)
> +		return -EINVAL;
> +
> +	for (i = 0; i < info->num_planes; i++) {
> +		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> +		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> +		unsigned int min_size;
>  
>  		min_size = (height - 1) * mode_cmd->pitches[i]
>  			 + drm_format_info_min_pitch(info, i, width)
>  			 + mode_cmd->offsets[i];
>  
> -		if (objs[i]->size < min_size) {
> -			drm_gem_object_put_unlocked(objs[i]);
> -			ret = -EINVAL;
> -			goto err_gem_object_put;
> -		}
> +		if (objs[i]->size < min_size)
> +			return -EINVAL;
>  	}
>  
> -	fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
> -	if (IS_ERR(fb)) {
> -		ret = PTR_ERR(fb);
> -		goto err_gem_object_put;
> -	}
> +	return 0;
>  
> -	return fb;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
>  
> -err_gem_object_put:
> -	for (i--; i >= 0; i--)
> -		drm_gem_object_put_unlocked(objs[i]);
> +/**
> + * drm_gem_fb_create_with_funcs() - Helper function for the
> + *                                  &drm_mode_config_funcs.fb_create
> + *                                  callback
> + * @dev: DRM device
> + * @file: DRM file that holds the GEM handle(s) backing the framebuffer
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + * @funcs: vtable to be used for the new framebuffer object
> + *
> + * This function can be used to set &drm_framebuffer_funcs for drivers that need
> + * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
> + * change &drm_framebuffer_funcs. The function does buffer size validation.
> + *
> + * Returns:
> + * Pointer to a &drm_framebuffer on success or an error pointer on failure.
> + */
> +struct drm_framebuffer *
> +drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
> +			     const struct drm_mode_fb_cmd2 *mode_cmd,
> +			     const struct drm_framebuffer_funcs *funcs)
> +{
> +	struct drm_gem_object *objs[4];
> +	struct drm_framebuffer *fb;
> +	int ret, num_planes;
> +
> +	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
> +	if (ret < 0)
> +		return ERR_PTR(ret);
> +	num_planes = ret;
> +
> +	ret = drm_gem_fb_size_check(dev, mode_cmd, objs);

if drm_gem_fb_size_check() returns an error, then ...

> +	if (ret)
> +		fb = ERR_PTR(ret);
> +	else
> +		fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs);

.... the else part is not taken, but ...

>  
> -	return ERR_PTR(ret);
> +	if (IS_ERR(fb))
> +		for (num_planes--; num_planes >= 0; num_planes--)
> +			drm_gem_object_put_unlocked(objs[num_planes]);

... here you'll attempt to dereference the objs. I don't think that is correct.

> +
> +	return fb;
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
>  
> -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
> -	.destroy	= drm_gem_fb_destroy,
> -	.create_handle	= drm_gem_fb_create_handle,
> -};
> -
>  /**
>   * drm_gem_fb_create() - Helper function for the
>   *                       &drm_mode_config_funcs.fb_create callback
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index d9f13fd25b0a..c85d4b152e91 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -14,10 +14,27 @@ struct drm_simple_display_pipe;
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
> +			       struct drm_device *dev,
> +			       const struct drm_mode_fb_cmd2 *mode_cmd,
> +			       struct drm_gem_object **obj,
> +			       unsigned int num_planes,
> +			       const struct drm_framebuffer_funcs *funcs);
> +int drm_gem_fb_init(struct drm_framebuffer *fb,
> +		    struct drm_device *dev,
> +		    const struct drm_mode_fb_cmd2 *mode_cmd,
> +		    struct drm_gem_object **obj, unsigned int num_planes);
>  void drm_gem_fb_destroy(struct drm_framebuffer *fb);
>  int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
>  			     unsigned int *handle);
>  
> +int drm_gem_fb_lookup(struct drm_device *dev,
> +		      struct drm_file *file,
> +		      const struct drm_mode_fb_cmd2 *mode_cmd,
> +		      struct drm_gem_object **objs);
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs);
>  struct drm_framebuffer *
>  drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
>  			     const struct drm_mode_fb_cmd2 *mode_cmd,
> -- 
> 2.17.1
> 


Best regards,
Liviu

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2019-12-13 15:58 ` [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
@ 2019-12-16 17:11   ` Liviu Dudau
  2020-02-17  8:16   ` [PATCHv4,04/36] " james qian wang (Arm Technology China)
  1 sibling, 0 replies; 106+ messages in thread
From: Liviu Dudau @ 2019-12-16 17:11 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Sandy Huang, James Wang,
	dri-devel, Mihail Atanassov, Sean Paul

On Fri, Dec 13, 2019 at 04:58:35PM +0100, Andrzej Pietrasiewicz wrote:
> The new version accepts a struct describing deviations from standard way of
> doing the size checks. The caller must provide the respective values.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++----
>  include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
>  2 files changed, 55 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 787edb9a916b..4201dc1f32a5 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>  
>  /**
> - * drm_gem_fb_size_check() - Helper function for use in
> - *			     &drm_mode_config_funcs.fb_create implementations
> + * drm_gem_fb_size_check_special() - Helper function for use in
> + *				     &drm_mode_config_funcs.fb_create
> + *				     implementations
>   * @dev: DRM device
>   * @mode_cmd: Metadata from the userspace framebuffer creation request
>   *
> @@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>   * Returns:
>   * Zero on success or a negative error code on failure.
>   */
> -int drm_gem_fb_size_check(struct drm_device *dev,
> -			  const struct drm_mode_fb_cmd2 *mode_cmd,
> -			  struct drm_gem_object **objs)
> +int drm_gem_fb_size_check_special(struct drm_device *dev,
> +				  const struct drm_mode_fb_cmd2 *mode_cmd,
> +				  const struct drm_size_check *check,
> +				  struct drm_gem_object **objs)
>  {
>  	const struct drm_format_info *info;
>  	int i;
> @@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>  		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
>  		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
>  		unsigned int min_size;
> +		u32 pitch = mode_cmd->pitches[i];
> +
> +		if (check && check->use_pitch_multiplier)
> +			if ((pitch * check->pitch_multiplier[i]) %
> +			    check->pitch_modulo)
> +				return -EINVAL;
>  
> -		min_size = (height - 1) * mode_cmd->pitches[i]
> -			 + drm_format_info_min_pitch(info, i, width)
> -			 + mode_cmd->offsets[i];
> +		if (check && check->use_min_size)
> +			min_size = check->min_size[i];
> +		else
> +			min_size = (height - 1) * pitch
> +				 + drm_format_info_min_pitch(info, i, width)
> +				 + mode_cmd->offsets[i];
>  
>  		if (objs[i]->size < min_size)
>  			return -EINVAL;
> @@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>  	return 0;
>  
>  }
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);

Hmm, not a big fan of exporting something called foo_special. What about following
the tradition of calling it drm_gem_fb_size_check2() ?

Best regards,
Liviu

> +
> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)
> +{
> +	return drm_gem_fb_size_check_special(dev, mode_cmd, NULL, objs);
> +}
>  EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
>  
>  /**
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index c85d4b152e91..74304a268694 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
>  struct drm_plane;
>  struct drm_plane_state;
>  struct drm_simple_display_pipe;
> +struct drm_size_check;
> +
> +/**
> + * struct drm_size_check - Description of special requirements for size checks.
> + */
> +struct drm_size_check {
> +	unsigned int min_size[4];
> +	bool use_min_size;
> +	u32 pitch_multiplier[4];
> +	u32 pitch_modulo;
> +	bool use_pitch_multiplier;
> +};
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  		      struct drm_file *file,
>  		      const struct drm_mode_fb_cmd2 *mode_cmd,
>  		      struct drm_gem_object **objs);
> +int drm_gem_fb_size_check_special(struct drm_device *dev,
> +				  const struct drm_mode_fb_cmd2 *mode_cmd,
> +				  const struct drm_size_check *check,
> +				  struct drm_gem_object **objs);
>  int drm_gem_fb_size_check(struct drm_device *dev,
>  			  const struct drm_mode_fb_cmd2 *mode_cmd,
>  			  struct drm_gem_object **objs);
> -- 
> 2.17.1
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-13 15:58 ` [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
@ 2019-12-16 17:19   ` Liviu Dudau
  2019-12-16 18:41     ` Andrzej Pietrasiewicz
  2020-02-17 11:02   ` [PATCHv4,05/36] " james qian wang (Arm Technology China)
  1 sibling, 1 reply; 106+ messages in thread
From: Liviu Dudau @ 2019-12-16 17:19 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Sandy Huang, James Wang,
	dri-devel, Mihail Atanassov, Sean Paul

Hi Andrzej,

On Fri, Dec 13, 2019 at 04:58:36PM +0100, Andrzej Pietrasiewicz wrote:
> Extend the size-checking special function to handle afbc.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c                 | 10 +++-
>  drivers/gpu/drm/drm_framebuffer.c            |  3 +
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++--
>  include/drm/drm_gem_framebuffer_helper.h     | 16 ++++++
>  4 files changed, 82 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index d14dd7c86020..9ac2175c5bee 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev,
>  {
>  	const struct drm_format_info *info = NULL;
>  
> -	if (dev->mode_config.funcs->get_format_info)
> -		info = dev->mode_config.funcs->get_format_info(mode_cmd);
> +	/* bypass driver callback if afbc */
> +	if (!drm_is_afbc(mode_cmd->modifier[0]))
> +		if (dev->mode_config.funcs->get_format_info) {
> +			const struct drm_mode_config_funcs *funcs;
> +
> +			funcs = dev->mode_config.funcs;
> +			info = funcs->get_format_info(mode_cmd);
> +		}

What has this change to do with the rest of the patch? Also, I think this goes
against the idea that an AFBC-aware driver might return better data about the format
info than the drm_format_info() code.

As a bikeshed, I know it is useful for debugging to turn the oneliner into 3, but it
feels like not necessary here.

Best regards,
Liviu

>  
>  	if (!info)
>  		info = drm_format_info(mode_cmd->pixel_format);
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 57564318ceea..33b741cc73e8 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev,
>  		unsigned int block_size = info->char_per_block[i];
>  		u64 min_pitch = drm_format_info_min_pitch(info, i, width);
>  
> +		if (drm_is_afbc(r->modifier[i]))
> +			block_size = 0;
> +
>  		if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) {
>  			DRM_DEBUG_KMS("Format requires non-linear modifier for plane %d\n", i);
>  			return -EINVAL;
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 4201dc1f32a5..e20f4d00b0a5 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -21,6 +21,11 @@
>  #include <drm/drm_modeset_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
>  
> +#define AFBC_HEADER_SIZE		16
> +#define AFBC_TH_LAYOUT_ALIGNMENT	8
> +#define AFBC_SUPERBLOCK_PIXELS		256
> +#define AFBC_SUPERBLOCK_ALIGNMENT	128
> +
>  /**
>   * DOC: overview
>   *
> @@ -200,6 +205,40 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>  
> +static int drm_gem_afbc_min_size(struct drm_device *dev,
> +				 const struct drm_mode_fb_cmd2 *mode_cmd,
> +				 struct drm_afbc *afbc)
> +{
> +	u32 n_blocks;
> +
> +	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
> +					&afbc->block_width,
> +					&afbc->block_height)) {
> +		return -EINVAL;
> +	}
> +
> +	/* tiled header afbc */
> +	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
> +		afbc->block_width *= AFBC_TH_LAYOUT_ALIGNMENT;
> +		afbc->block_height *= AFBC_TH_LAYOUT_ALIGNMENT;
> +	}
> +
> +	afbc->aligned_width = ALIGN(mode_cmd->width, afbc->block_width);
> +	afbc->aligned_height = ALIGN(mode_cmd->height, afbc->block_height);
> +	afbc->offset = mode_cmd->offsets[0];
> +
> +	n_blocks = (afbc->aligned_width * afbc->aligned_height)
> +		 / AFBC_SUPERBLOCK_PIXELS;
> +	afbc->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
> +				     afbc->alignment_header);
> +
> +	afbc->afbc_size = afbc->offset_payload + n_blocks *
> +			  ALIGN(afbc->bpp * AFBC_SUPERBLOCK_PIXELS / 8,
> +				AFBC_SUPERBLOCK_ALIGNMENT);
> +
> +	return 0;
> +}
> +
>  /**
>   * drm_gem_fb_size_check_special() - Helper function for use in
>   *				     &drm_mode_config_funcs.fb_create
> @@ -218,6 +257,7 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,
>  				  const struct drm_size_check *check,
>  				  struct drm_gem_object **objs)
>  {
> +#define CHECK_HAS(field) (check && check->field)
>  	const struct drm_format_info *info;
>  	int i;
>  
> @@ -231,24 +271,34 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,
>  		unsigned int min_size;
>  		u32 pitch = mode_cmd->pitches[i];
>  
> -		if (check && check->use_pitch_multiplier)
> +		if (CHECK_HAS(use_pitch_multiplier))
>  			if ((pitch * check->pitch_multiplier[i]) %
>  			    check->pitch_modulo)
>  				return -EINVAL;
>  
> -		if (check && check->use_min_size)
> +		if (CHECK_HAS(use_min_size)) {
>  			min_size = check->min_size[i];
> -		else
> +		} else if (CHECK_HAS(data) &&
> +				drm_is_afbc(mode_cmd->modifier[0])) {
> +			struct drm_afbc *afbc;
> +			int ret;
> +
> +			afbc = check->data;
> +			ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc);
> +			if (ret < 0)
> +				return ret;
> +			min_size = ret;
> +		} else {
>  			min_size = (height - 1) * pitch
>  				 + drm_format_info_min_pitch(info, i, width)
>  				 + mode_cmd->offsets[i];
> -
> +		}
>  		if (objs[i]->size < min_size)
>  			return -EINVAL;
>  	}
>  
>  	return 0;
> -
> +#undef CHECK_HAS
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
>  
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index 74304a268694..3d6015194b3c 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -22,6 +22,22 @@ struct drm_size_check {
>  	u32 pitch_multiplier[4];
>  	u32 pitch_modulo;
>  	bool use_pitch_multiplier;
> +	void *data;
> +};
> +
> +/**
> + * struct drm_afbc - AFBC-specific data.
> + */
> +struct drm_afbc {
> +	u32 block_width;
> +	u32 block_height;
> +	u32 aligned_width;
> +	u32 aligned_height;
> +	u32 offset;
> +	u32 alignment_header;
> +	u32 afbc_size;
> +	u32 offset_payload;
> +	u32 bpp;
>  };
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
> -- 
> 2.17.1
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-16 17:19   ` Liviu Dudau
@ 2019-12-16 18:41     ` Andrzej Pietrasiewicz
  2019-12-17  9:18       ` Liviu Dudau
  0 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-16 18:41 UTC (permalink / raw)
  To: Liviu Dudau
  Cc: Ayan Halder, kernel, David Airlie, Sandy Huang, James Wang,
	dri-devel, Mihail Atanassov, Sean Paul

Hi Liviu,

W dniu 16.12.2019 o 18:19, Liviu Dudau pisze:
> Hi Andrzej,
> 
> On Fri, Dec 13, 2019 at 04:58:36PM +0100, Andrzej Pietrasiewicz wrote:
>> Extend the size-checking special function to handle afbc.
>>
>> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
>> ---
>>   drivers/gpu/drm/drm_fourcc.c                 | 10 +++-
>>   drivers/gpu/drm/drm_framebuffer.c            |  3 +
>>   drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++--
>>   include/drm/drm_gem_framebuffer_helper.h     | 16 ++++++
>>   4 files changed, 82 insertions(+), 7 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
>> index d14dd7c86020..9ac2175c5bee 100644
>> --- a/drivers/gpu/drm/drm_fourcc.c
>> +++ b/drivers/gpu/drm/drm_fourcc.c
>> @@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev,
>>   {
>>   	const struct drm_format_info *info = NULL;
>>   
>> -	if (dev->mode_config.funcs->get_format_info)
>> -		info = dev->mode_config.funcs->get_format_info(mode_cmd);
>> +	/* bypass driver callback if afbc */
>> +	if (!drm_is_afbc(mode_cmd->modifier[0]))
>> +		if (dev->mode_config.funcs->get_format_info) {
>> +			const struct drm_mode_config_funcs *funcs;
>> +
>> +			funcs = dev->mode_config.funcs;
>> +			info = funcs->get_format_info(mode_cmd);
>> +		}
> 
> What has this change to do with the rest of the patch? Also, I think this goes
> against the idea that an AFBC-aware driver might return better data about the format
> info than the drm_format_info() code.
> 

The reason is the conclusion of my talk with danvet on irc:

https://people.freedesktop.org/~cbrill/dri-log/?channel=dri-devel&highlight_names=&date=2019-11-13&show_html=true

I followed his advice - if I understood him correctly, that is.

> As a bikeshed, I know it is useful for debugging to turn the oneliner into 3, but it
> feels like not necessary here.

80 chars per line. If kept in one line, the limit is exceeded
with an additional indentation level present.

Regards,

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-16 17:08   ` Liviu Dudau
@ 2019-12-16 20:37     ` Andrzej Pietrasiewicz
  0 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-16 20:37 UTC (permalink / raw)
  To: Liviu Dudau
  Cc: kernel, Mihail Atanassov, David Airlie, Sandy Huang, dri-devel,
	James Wang, Ayan Halder, Sean Paul

Hi Liviu,

My way of thinking is explained below. Do you still find it problematic?

W dniu 16.12.2019 o 18:08, Liviu Dudau pisze:
> Hi Andrzej,
> 

<snip>

>> +struct drm_framebuffer *
>> +drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
>> +			     const struct drm_mode_fb_cmd2 *mode_cmd,
>> +			     const struct drm_framebuffer_funcs *funcs)
>> +{
>> +	struct drm_gem_object *objs[4];
>> +	struct drm_framebuffer *fb;
>> +	int ret, num_planes;
>> +
>> +	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
>> +	if (ret < 0)
>> +		return ERR_PTR(ret);

here objs is guaranteed to have been filled...

>> +	num_planes = ret;
>> +
>> +	ret = drm_gem_fb_size_check(dev, mode_cmd, objs);
> 
> if drm_gem_fb_size_check() returns an error, then ...
> 
>> +	if (ret)
>> +		fb = ERR_PTR(ret);
>> +	else
>> +		fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs);
> 
> .... the else part is not taken, but ...

... nonetheless objs have already been looked up...

> 
>>   
>> -	return ERR_PTR(ret);
>> +	if (IS_ERR(fb))
>> +		for (num_planes--; num_planes >= 0; num_planes--)
>> +			drm_gem_object_put_unlocked(objs[num_planes]);
> 
> ... here you'll attempt to dereference the objs. I don't think that is correct.

... so it is safe to dereference objs here

Regards,

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-16 18:41     ` Andrzej Pietrasiewicz
@ 2019-12-17  9:18       ` Liviu Dudau
  0 siblings, 0 replies; 106+ messages in thread
From: Liviu Dudau @ 2019-12-17  9:18 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Sandy Huang, James Wang,
	dri-devel, Mihail Atanassov, Sean Paul

On Mon, Dec 16, 2019 at 07:41:23PM +0100, Andrzej Pietrasiewicz wrote:
> Hi Liviu,
> 
> W dniu 16.12.2019 o 18:19, Liviu Dudau pisze:
> > Hi Andrzej,
> > 
> > On Fri, Dec 13, 2019 at 04:58:36PM +0100, Andrzej Pietrasiewicz wrote:
> > > Extend the size-checking special function to handle afbc.
> > > 
> > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> > > ---
> > >   drivers/gpu/drm/drm_fourcc.c                 | 10 +++-
> > >   drivers/gpu/drm/drm_framebuffer.c            |  3 +
> > >   drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++--
> > >   include/drm/drm_gem_framebuffer_helper.h     | 16 ++++++
> > >   4 files changed, 82 insertions(+), 7 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> > > index d14dd7c86020..9ac2175c5bee 100644
> > > --- a/drivers/gpu/drm/drm_fourcc.c
> > > +++ b/drivers/gpu/drm/drm_fourcc.c
> > > @@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev,
> > >   {
> > >   	const struct drm_format_info *info = NULL;
> > > -	if (dev->mode_config.funcs->get_format_info)
> > > -		info = dev->mode_config.funcs->get_format_info(mode_cmd);
> > > +	/* bypass driver callback if afbc */
> > > +	if (!drm_is_afbc(mode_cmd->modifier[0]))
> > > +		if (dev->mode_config.funcs->get_format_info) {
> > > +			const struct drm_mode_config_funcs *funcs;
> > > +
> > > +			funcs = dev->mode_config.funcs;
> > > +			info = funcs->get_format_info(mode_cmd);
> > > +		}
> > 
> > What has this change to do with the rest of the patch? Also, I think this goes
> > against the idea that an AFBC-aware driver might return better data about the format
> > info than the drm_format_info() code.
> > 
> 
> The reason is the conclusion of my talk with danvet on irc:
> 
> https://people.freedesktop.org/~cbrill/dri-log/?channel=dri-devel&highlight_names=&date=2019-11-13&show_html=true
> 
> I followed his advice - if I understood him correctly, that is.

Yeah, I don't necessarily agree with danvet here. I think a better approach is to
still let the driver have a say in getting the format info, but if the hook is not
present or if it returns NULL then apply the AFBC code before (or as an alternative to)
the rest of the generic code.

> 
> > As a bikeshed, I know it is useful for debugging to turn the oneliner into 3, but it
> > feels like not necessary here.
> 
> 80 chars per line. If kept in one line, the limit is exceeded
> with an additional indentation level present.

DRM subsystem has never enforced that and there are plenty of instances in the core DRM 
code where that rule gets ignored. We know that mode_config.funcs is never NULL and
that the get_format_info() hook is always populated, so we don't really gain anything
from splitting it into multiple lines.

Best regards,
Liviu

> 
> Regards,
> 
> Andrzej

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* [PATCHv5 00/34] Add AFBC support for Rockchip
  2019-12-13 17:33   ` Daniel Vetter
@ 2019-12-17 14:49     ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
                         ` (35 more replies)
  0 siblings, 36 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

This series adds AFBC support for Rockchip. It is inspired by:

https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c

This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
rework has been done, the main goal of which was to move all afbc-related
checks to helpers, so that core does not deal with it.

A new struct drm_afbc_framebuffer is added, which stores afbc-related
driver-specific data. Because of that, in drivers that wish to
use this feature, the struct must be allocated directly in the driver
code rather than inside helpers, so the first portion of the patchset
does the necessary refactoring.

Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
the latter being the ultimate purpose of this work and the 3 subsequent
portions of the patchset move komeda and malidp to generic helpers and add
afbc support to rockchip.

The idea is to make all afbc users follow a similar pattern. In fb_create()
they allocate struct drm_afbc_framebuffer, do their specific checks which
can be done before object lookups, do object lookups and a special version
of a size check, which understands struct drm_afbc_framebuffer, followed
by any other driver-specific checks and initializing the gem object.
The helpers for the common parts are factored out so that drivers
can use them.

The komeda driver has been the farthest away from such a pattern, so it
required most changes. However, due to the fact that I don't have any
komeda hardware I did the changes to komeda in an incremental fashion with
a series of (usually) very small, easy to understand steps. malidp was
pretty straightforward, and rockchip's afbc checks follow the pattern.

I kindly ask for reviewing the series. I need to mention that my ultimate
goal is merging afbc for rockchip and I don't have other hardware, so some
help from malidp and komeda developers/maintainers would be appreciated.

@Liviu, @James, @Mihail, @Brian: a kind request to you to have a look and
test the patchset, as I don't have appropriate hardware.

Rebased onto drm-misc-next.

v4..v5:
- used proper way of subclassing drm_framebuffer (Daniel Vetter)
- added documentation to exported functions (Liviu Dudau)
- reordered new functions in drm_gem_framebuffer_helper.c to make a saner
diff (Liviu Dudau)
- used "2" suffix instead of "_special" for the special version of size
checks (Liviu Dudau)
- dropped unnecessarily added condition in drm_get_format_info() (Liviu
Dudau)
- dropped "block_size = 0;" trick in framebuffer_check() (Daniel Vetter)
- relaxed sticking to 80 characters per line rule in some cases

v3..v4:

- addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel
Vetter and James Qian Wang - thank you for input
- refactored helpers to ease accommodating drivers with afbc needs
- moved afbc checks to helpers
- converted komeda, malidp and (the newly added) rockchip to use the afbc
helpers
- eliminated a separate, dedicated source code file

v2..v3:

- addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter
and Brian Starkey - thank you all

In this iteration some rework has been done. The checking logic is now moved
to framebuffer_check() so it is common to all drivers. But the common part
is not good for komeda, so this series is not good for merging yet.
I kindly ask for feedback whether the changes are in the right direction.
I also kindly ask for input on how to accommodate komeda.

The CONFIG_DRM_AFBC option has been eliminated in favour of adding
drm_afbc.c to drm_kms_helper.

v1..v2:

- addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
- coding style fixes** BLURB HERE ***


Andrzej Pietrasiewicz (34):
  drm/core: Add afbc helper functions
  drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on
    their own
  drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  drm/gem-fb-helper: Add generic afbc size checks
  drm/komeda: Use afbc helper
  drm/komeda: Move checking src coordinates to komeda_fb_create
  drm/komeda: Use the already available local variable
  drm/komeda: Retrieve drm_format_info once
  drm/komeda: Explicitly require 1 plane for AFBC
  drm/komeda: Move pitches comparison to komeda_fb_create
  drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not
    requiring a fb
  drm/komeda: Factor out object lookups for non-afbc case
  drm/komeda: Make komeda_fb_none_size_check independent from
    framebuffer
  drm/komeda: Factor out object lookups for afbc case
  drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
  drm/komeda: Simplify error handling
  drm/komeda: Move object lookup before size checks
  drm/komeda: Move object assignments to framebuffer to after size
    checks
  drm/komeda: Make the size checks independent from framebuffer
    structure
  drm/komeda: Move helper invocation to after size checks
  drm/komeda: Use helper for common tasks
  drm/komeda: Use return value of drm_gem_fb_lookup
  drm/komeda: Use special helper for non-afbc size checks
  drm/komeda: Factor in the invocation of special helper
  drm/komeda: Use special helper for afbc case size check
  drm/komeda: Factor in the invocation of special helper, afbc case
  drm/komeda: Move special helper invocation outside if-else
  drm/komeda: Move to helper checking afbc buffer size
  drm/arm/malidp: Make verify funcitons invocations independent
  drm/arm/malidp: Integrate verify functions
  drm/arm/malidp: Factor in afbc framebuffer verification
  drm/arm/malidp: Use generic helpers for afbc checks
  drm/rockchip: Use helper for common task
  drm/rockchip: Add support for afbc

 .../arm/display/komeda/d71/d71_component.c    |   6 +-
 .../arm/display/komeda/komeda_framebuffer.c   | 273 ++++++++---------
 .../arm/display/komeda/komeda_framebuffer.h   |  21 +-
 .../display/komeda/komeda_pipeline_state.c    |  14 +-
 drivers/gpu/drm/arm/malidp_drv.c              | 155 ++++------
 drivers/gpu/drm/drm_fourcc.c                  |  53 ++++
 drivers/gpu/drm/drm_gem_framebuffer_helper.c  | 287 ++++++++++++++----
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c    | 111 ++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c   | 147 ++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h   |  12 +
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c   |  83 ++++-
 include/drm/drm_fourcc.h                      |   4 +
 include/drm/drm_framebuffer.h                 |  50 +++
 include/drm/drm_gem_framebuffer_helper.h      |  34 +++
 14 files changed, 907 insertions(+), 343 deletions(-)

-- 
2.17.1

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* [PATCHv5 01/34] drm/core: Add afbc helper functions
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2020-02-18  3:13         ` james qian wang (Arm Technology China)
                           ` (2 more replies)
  2019-12-17 14:49       ` [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
                         ` (34 subsequent siblings)
  35 siblings, 3 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Add checking if a modifier is afbc and getting afbc block size.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_fourcc.h     |  4 +++
 2 files changed, 57 insertions(+)

diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
index b234bfaeda06..d14dd7c86020 100644
--- a/drivers/gpu/drm/drm_fourcc.c
+++ b/drivers/gpu/drm/drm_fourcc.c
@@ -29,6 +29,7 @@
 
 #include <drm/drm_device.h>
 #include <drm/drm_fourcc.h>
+#include <drm/drm_print.h>
 
 static char printable_char(int c)
 {
@@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
 			    drm_format_info_block_height(info, plane));
 }
 EXPORT_SYMBOL(drm_format_info_min_pitch);
+
+/**
+ * drm_is_afbc - test if the modifier describes an afbc buffer
+ * @modifier - modifier to be tested
+ *
+ * Returns: true if the modifier describes an afbc buffer
+ */
+bool drm_is_afbc(u64 modifier)
+{
+	/* is it ARM AFBC? */
+	if ((modifier & DRM_FORMAT_MOD_ARM_AFBC(0)) == 0)
+		return false;
+
+	/* Block size must be known */
+	if ((modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) == 0)
+		return false;
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_is_afbc);
+
+/**
+ * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier
+ * @modifier: the modifier to be looked at
+ * @w: address of a place to store the block width
+ * @h: address of a place to store the block height
+ *
+ * Returns: true if the modifier describes a supported block size
+ */
+bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h)
+{
+	switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		*w = 16;
+		*h = 16;
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		*w = 32;
+		*h = 8;
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
+			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
+		return false;
+	}
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_get_superblock_wh);
diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
index 306d1efeb5e0..7eb23062bf45 100644
--- a/include/drm/drm_fourcc.h
+++ b/include/drm/drm_fourcc.h
@@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
 				   int plane, unsigned int buffer_width);
 const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
 
+bool drm_is_afbc(u64 modifier);
+
+bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h);
+
 #endif /* __DRM_FOURCC_H__ */
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2020-02-18  3:34         ` james qian wang (Arm Technology China)
  2020-02-20  9:47         ` Boris Brezillon
  2019-12-17 14:49       ` [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
                         ` (33 subsequent siblings)
  35 siblings, 2 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Prepare tools for drivers which need to allocate a struct drm_framebuffer
(or a container of struct drm_framebuffer) explicitly, before calling
helpers. In such a case we need new helpers which omit allocating the
struct drm_framebuffer and this patch provides them. Consequently, they
are used also inside the helpers themselves.

The interested drivers will likely need to be able to perform object
lookups and size checks in separate invocations and this patch provides
that as well. Helpers themselves are updated, too.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 216 ++++++++++++++-----
 include/drm/drm_gem_framebuffer_helper.h     |  17 ++
 2 files changed, 181 insertions(+), 52 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index b9bcd310ca2d..b3494f6b66bb 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -54,6 +54,69 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
 
+/**
+ * drm_gem_fb_init_with_funcs() - Initialize an already allocated framebuffer
+ * @fb: Framebuffer
+ * @dev: DRM device
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ * @obj: GEM objects to be assigned to the framebuffer
+ * @num_planes: number of planes
+ * @funcs: vtable to be used for the framebuffer object
+ *
+ * This variant of the function allows passing a custom vtable.
+ *
+ * Returns:
+ * 0 on success or a negative error code
+ */
+int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
+			       struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd,
+			       struct drm_gem_object **obj,
+			       unsigned int num_planes,
+			       const struct drm_framebuffer_funcs *funcs)
+{
+	int ret, i;
+
+	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
+
+	for (i = 0; i < num_planes; i++)
+		fb->obj[i] = obj[i];
+
+	ret = drm_framebuffer_init(dev, fb, funcs);
+	if (ret)
+		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n", ret);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
+
+static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
+	.destroy	= drm_gem_fb_destroy,
+	.create_handle	= drm_gem_fb_create_handle,
+};
+
+/**
+ * drm_gem_fb_init() - Initialize an already allocated framebuffer
+ * @fb: Framebuffer
+ * @dev: DRM device
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ * @obj: GEM objects to be assigned to the framebuffer
+ * @num_planes: number of planes
+ *
+ * This variant of the function uses a default vtable.
+ *
+ * Returns:
+ * 0 on success or a negative error code
+ */
+int drm_gem_fb_init(struct drm_framebuffer *fb,
+		    struct drm_device *dev,
+		    const struct drm_mode_fb_cmd2 *mode_cmd,
+		    struct drm_gem_object **obj, unsigned int num_planes)
+{
+	return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &drm_gem_fb_funcs);
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_init);
+
 static struct drm_framebuffer *
 drm_gem_fb_alloc(struct drm_device *dev,
 		 const struct drm_mode_fb_cmd2 *mode_cmd,
@@ -61,21 +124,14 @@ drm_gem_fb_alloc(struct drm_device *dev,
 		 const struct drm_framebuffer_funcs *funcs)
 {
 	struct drm_framebuffer *fb;
-	int ret, i;
+	int ret;
 
 	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
 	if (!fb)
 		return ERR_PTR(-ENOMEM);
 
-	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
-
-	for (i = 0; i < num_planes; i++)
-		fb->obj[i] = obj[i];
-
-	ret = drm_framebuffer_init(dev, fb, funcs);
+	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, funcs);
 	if (ret) {
-		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
-			      ret);
 		kfree(fb);
 		return ERR_PTR(ret);
 	}
@@ -144,59 +200,29 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
 			     const struct drm_mode_fb_cmd2 *mode_cmd,
 			     const struct drm_framebuffer_funcs *funcs)
 {
-	const struct drm_format_info *info;
 	struct drm_gem_object *objs[4];
 	struct drm_framebuffer *fb;
-	int ret, i;
-
-	info = drm_get_format_info(dev, mode_cmd);
-	if (!info)
-		return ERR_PTR(-EINVAL);
-
-	for (i = 0; i < info->num_planes; i++) {
-		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
-		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
-		unsigned int min_size;
+	int ret, num_planes;
 
-		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
-		if (!objs[i]) {
-			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-			ret = -ENOENT;
-			goto err_gem_object_put;
-		}
-
-		min_size = (height - 1) * mode_cmd->pitches[i]
-			 + drm_format_info_min_pitch(info, i, width)
-			 + mode_cmd->offsets[i];
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		return ERR_PTR(ret);
+	num_planes = ret;
 
-		if (objs[i]->size < min_size) {
-			drm_gem_object_put_unlocked(objs[i]);
-			ret = -EINVAL;
-			goto err_gem_object_put;
-		}
-	}
+	ret = drm_gem_fb_size_check(dev, mode_cmd, objs);
+	if (ret)
+		fb = ERR_PTR(ret);
+	else
+		fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs);
 
-	fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
-	if (IS_ERR(fb)) {
-		ret = PTR_ERR(fb);
-		goto err_gem_object_put;
-	}
+	if (IS_ERR(fb))
+		for (num_planes--; num_planes >= 0; num_planes--)
+			drm_gem_object_put_unlocked(objs[num_planes]);
 
 	return fb;
-
-err_gem_object_put:
-	for (i--; i >= 0; i--)
-		drm_gem_object_put_unlocked(objs[i]);
-
-	return ERR_PTR(ret);
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
 
-static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
-	.destroy	= drm_gem_fb_destroy,
-	.create_handle	= drm_gem_fb_create_handle,
-};
-
 /**
  * drm_gem_fb_create() - Helper function for the
  *                       &drm_mode_config_funcs.fb_create callback
@@ -228,6 +254,92 @@ drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_create);
 
+/**
+ * drm_gem_fb_lookup() - Helper function for use in
+ *			 &drm_mode_config_funcs.fb_create implementations
+ * @dev: DRM device
+ * @file: DRM file that holds the GEM handle(s) backing the framebuffer
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ *
+ * This function can be used to look up the objects for all planes.
+ * In case an error is returned all the objects are put by the
+ * function before returning.
+ *
+ * Returns:
+ * Number of planes on success or a negative error code on failure.
+ */
+int drm_gem_fb_lookup(struct drm_device *dev,
+		      struct drm_file *file,
+		      const struct drm_mode_fb_cmd2 *mode_cmd,
+		      struct drm_gem_object **objs)
+{
+	const struct drm_format_info *info;
+	int ret, i;
+
+	info = drm_get_format_info(dev, mode_cmd);
+	if (!info)
+		return -EINVAL;
+
+	for (i = 0; i < info->num_planes; i++) {
+		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
+		if (!objs[i]) {
+			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+			ret = -ENOENT;
+			goto err_gem_object_put;
+		}
+	}
+
+	return i;
+
+err_gem_object_put:
+	for (i--; i >= 0; i--)
+		drm_gem_object_put_unlocked(objs[i]);
+
+	return ret;
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
+
+/**
+ * drm_gem_fb_size_check() - Helper function for use in
+ *			     &drm_mode_config_funcs.fb_create implementations
+ * @dev: DRM device
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ *
+ * This function can be used to verify buffer sizes for all planes.
+ * It is caller's responsibility to put the objects on failure.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int drm_gem_fb_size_check(struct drm_device *dev,
+			  const struct drm_mode_fb_cmd2 *mode_cmd,
+			  struct drm_gem_object **objs)
+{
+	const struct drm_format_info *info;
+	int i;
+
+	info = drm_get_format_info(dev, mode_cmd);
+	if (!info)
+		return -EINVAL;
+
+	for (i = 0; i < info->num_planes; i++) {
+		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
+		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
+		unsigned int min_size;
+
+		min_size = (height - 1) * mode_cmd->pitches[i]
+			 + drm_format_info_min_pitch(info, i, width)
+			 + mode_cmd->offsets[i];
+
+		if (objs[i]->size < min_size)
+			return -EINVAL;
+	}
+
+	return 0;
+
+}
+EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
+
 static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
 	.destroy	= drm_gem_fb_destroy,
 	.create_handle	= drm_gem_fb_create_handle,
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index d9f13fd25b0a..c85d4b152e91 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -14,10 +14,27 @@ struct drm_simple_display_pipe;
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 					  unsigned int plane);
+int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
+			       struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd,
+			       struct drm_gem_object **obj,
+			       unsigned int num_planes,
+			       const struct drm_framebuffer_funcs *funcs);
+int drm_gem_fb_init(struct drm_framebuffer *fb,
+		    struct drm_device *dev,
+		    const struct drm_mode_fb_cmd2 *mode_cmd,
+		    struct drm_gem_object **obj, unsigned int num_planes);
 void drm_gem_fb_destroy(struct drm_framebuffer *fb);
 int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
 			     unsigned int *handle);
 
+int drm_gem_fb_lookup(struct drm_device *dev,
+		      struct drm_file *file,
+		      const struct drm_mode_fb_cmd2 *mode_cmd,
+		      struct drm_gem_object **objs);
+int drm_gem_fb_size_check(struct drm_device *dev,
+			  const struct drm_mode_fb_cmd2 *mode_cmd,
+			  struct drm_gem_object **objs);
 struct drm_framebuffer *
 drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
 			     const struct drm_mode_fb_cmd2 *mode_cmd,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2020-02-18  3:42         ` james qian wang (Arm Technology China)
  2020-02-20  9:59         ` Boris Brezillon
  2019-12-17 14:49       ` [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
                         ` (32 subsequent siblings)
  35 siblings, 2 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The new version accepts a struct describing deviations from standard way of
doing the size checks. The caller must provide the respective values.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 46 ++++++++++++++++----
 include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
 2 files changed, 54 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index b3494f6b66bb..d2fce1ec8f37 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -300,8 +300,8 @@ int drm_gem_fb_lookup(struct drm_device *dev,
 EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
 
 /**
- * drm_gem_fb_size_check() - Helper function for use in
- *			     &drm_mode_config_funcs.fb_create implementations
+ * drm_gem_fb_size_check2() - Helper function for use in
+ *			      &drm_mode_config_funcs.fb_create implementations
  * @dev: DRM device
  * @mode_cmd: Metadata from the userspace framebuffer creation request
  *
@@ -311,9 +311,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
  * Returns:
  * Zero on success or a negative error code on failure.
  */
-int drm_gem_fb_size_check(struct drm_device *dev,
-			  const struct drm_mode_fb_cmd2 *mode_cmd,
-			  struct drm_gem_object **objs)
+int drm_gem_fb_size_check2(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd,
+			   const struct drm_size_check *check,
+			   struct drm_gem_object **objs)
 {
 	const struct drm_format_info *info;
 	int i;
@@ -326,10 +327,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
 		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
 		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
 		unsigned int min_size;
+		u32 pitch = mode_cmd->pitches[i];
+
+		if (check && check->use_pitch_multiplier)
+			if ((pitch * check->pitch_multiplier[i]) %
+			    check->pitch_modulo)
+				return -EINVAL;
 
-		min_size = (height - 1) * mode_cmd->pitches[i]
-			 + drm_format_info_min_pitch(info, i, width)
-			 + mode_cmd->offsets[i];
+		if (check && check->use_min_size)
+			min_size = check->min_size[i];
+		else
+			min_size = (height - 1) * pitch
+				 + drm_format_info_min_pitch(info, i, width)
+				 + mode_cmd->offsets[i];
 
 		if (objs[i]->size < min_size)
 			return -EINVAL;
@@ -338,6 +348,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
 	return 0;
 
 }
+EXPORT_SYMBOL_GPL(drm_gem_fb_size_check2);
+
+/**
+ * drm_gem_fb_size_check() - Helper function for use in
+ *			     &drm_mode_config_funcs.fb_create implementations
+ * @dev: DRM device
+ * @mode_cmd: Metadata from the userspace framebuffer creation request
+ *
+ * This function can be used to verify buffer sizes for all planes.
+ * It is caller's responsibility to put the objects on failure.
+ *
+ * Returns:
+ * Zero on success or a negative error code on failure.
+ */
+int drm_gem_fb_size_check(struct drm_device *dev,
+			  const struct drm_mode_fb_cmd2 *mode_cmd,
+			  struct drm_gem_object **objs)
+{
+	return drm_gem_fb_size_check2(dev, mode_cmd, NULL, objs);
+}
 EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
 
 static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index c85d4b152e91..4955af96d6c3 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
 struct drm_plane;
 struct drm_plane_state;
 struct drm_simple_display_pipe;
+struct drm_size_check;
+
+/**
+ * struct drm_size_check - Description of special requirements for size checks.
+ */
+struct drm_size_check {
+	unsigned int min_size[4];
+	bool use_min_size;
+	u32 pitch_multiplier[4];
+	u32 pitch_modulo;
+	bool use_pitch_multiplier;
+};
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
 					  unsigned int plane);
@@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
 		      struct drm_file *file,
 		      const struct drm_mode_fb_cmd2 *mode_cmd,
 		      struct drm_gem_object **objs);
+int drm_gem_fb_size_check2(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd,
+			   const struct drm_size_check *check,
+			   struct drm_gem_object **objs);
 int drm_gem_fb_size_check(struct drm_device *dev,
 			  const struct drm_mode_fb_cmd2 *mode_cmd,
 			  struct drm_gem_object **objs);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (2 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2020-02-18  5:02         ` james qian wang (Arm Technology China)
  2019-12-17 14:49       ` [PATCHv5 05/34] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
                         ` (31 subsequent siblings)
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Extend the size-checking special function to handle afbc.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/drm_gem_framebuffer_helper.c | 49 +++++++++++++++++--
 include/drm/drm_framebuffer.h                | 50 ++++++++++++++++++++
 include/drm/drm_gem_framebuffer_helper.h     |  1 +
 3 files changed, 96 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
index d2fce1ec8f37..5fe9032a5ee8 100644
--- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
+++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
@@ -21,6 +21,11 @@
 #include <drm/drm_modeset_helper.h>
 #include <drm/drm_simple_kms_helper.h>
 
+#define AFBC_HEADER_SIZE		16
+#define AFBC_TH_LAYOUT_ALIGNMENT	8
+#define AFBC_SUPERBLOCK_PIXELS		256
+#define AFBC_SUPERBLOCK_ALIGNMENT	128
+
 /**
  * DOC: overview
  *
@@ -299,6 +304,34 @@ int drm_gem_fb_lookup(struct drm_device *dev,
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
 
+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)
+{
+	u32 n_blocks;
+
+	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &afbc_fb->block_width, &afbc_fb->block_height))
+		return -EINVAL;
+
+	/* tiled header afbc */
+	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
+		afbc_fb->block_width *= AFBC_TH_LAYOUT_ALIGNMENT;
+		afbc_fb->block_height *= AFBC_TH_LAYOUT_ALIGNMENT;
+	}
+
+	afbc_fb->aligned_width = ALIGN(mode_cmd->width, afbc_fb->block_width);
+	afbc_fb->aligned_height = ALIGN(mode_cmd->height, afbc_fb->block_height);
+	afbc_fb->offset = mode_cmd->offsets[0];
+
+	n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height) / AFBC_SUPERBLOCK_PIXELS;
+	afbc_fb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, afbc_fb->alignment_header);
+
+	afbc_fb->afbc_size = afbc_fb->offset_payload
+			   + n_blocks * ALIGN(afbc_fb->bpp * AFBC_SUPERBLOCK_PIXELS / 8, AFBC_SUPERBLOCK_ALIGNMENT);
+
+	return 0;
+}
+
 /**
  * drm_gem_fb_size_check2() - Helper function for use in
  *			      &drm_mode_config_funcs.fb_create implementations
@@ -334,19 +367,27 @@ int drm_gem_fb_size_check2(struct drm_device *dev,
 			    check->pitch_modulo)
 				return -EINVAL;
 
-		if (check && check->use_min_size)
+		if (check && check->use_min_size) {
 			min_size = check->min_size[i];
-		else
+		} else if (check && check->data && drm_is_afbc(mode_cmd->modifier[0])) {
+			struct drm_afbc_framebuffer *afbc_fb;
+			int ret;
+
+			afbc_fb = check->data;
+			ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc_fb);
+			if (ret < 0)
+				return ret;
+			min_size = ret;
+		} else {
 			min_size = (height - 1) * pitch
 				 + drm_format_info_min_pitch(info, i, width)
 				 + mode_cmd->offsets[i];
-
+		}
 		if (objs[i]->size < min_size)
 			return -EINVAL;
 	}
 
 	return 0;
-
 }
 EXPORT_SYMBOL_GPL(drm_gem_fb_size_check2);
 
diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
index c0e0256e3e98..c8a06e37585a 100644
--- a/include/drm/drm_framebuffer.h
+++ b/include/drm/drm_framebuffer.h
@@ -297,4 +297,54 @@ int drm_framebuffer_plane_width(int width,
 int drm_framebuffer_plane_height(int height,
 				 const struct drm_framebuffer *fb, int plane);
 
+/**
+ * struct drm_afbc_framebuffer - a special afbc frame buffer object
+ *
+ * A derived class of struct drm_framebuffer, dedicated for afbc use cases.
+ */
+struct drm_afbc_framebuffer {
+	/**
+	 * @base: base framebuffer structure.
+	 */
+	struct drm_framebuffer base;
+	/**
+	 * @block_widht: width of a single afbc block
+	 */
+	u32 block_width;
+	/**
+	 * @block_widht: height of a single afbc block
+	 */
+	u32 block_height;
+	/**
+	 * @aligned_width: aligned frame buffer width
+	 */
+	u32 aligned_width;
+	/**
+	 * @aligned_height: aligned frame buffer height
+	 */
+	u32 aligned_height;
+	/**
+	 * @offset: offset of the first afbc header
+	 */
+	u32 offset;
+	/**
+	 * @alignment_header: required alignment for afbc headers
+	 */
+	u32 alignment_header;
+	/**
+	 * @afbc_size: minimum size of afbc buffer
+	 */
+	u32 afbc_size;
+	/**
+	 * @offset_payload: start of afbc body buffer
+	 */
+	u32 offset_payload;
+	/**
+	 * @bpp: bpp value for this afbc buffer
+	 */
+	u32 bpp;
+};
+
+#define fb_to_afbc_fb(x) container_of(x, struct drm_afbc_framebuffer, base)
+
 #endif
diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
index 4955af96d6c3..17e3f849a0fb 100644
--- a/include/drm/drm_gem_framebuffer_helper.h
+++ b/include/drm/drm_gem_framebuffer_helper.h
@@ -22,6 +22,7 @@ struct drm_size_check {
 	u32 pitch_multiplier[4];
 	u32 pitch_modulo;
 	bool use_pitch_multiplier;
+	void *data;
 };
 
 struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 05/34] drm/komeda: Use afbc helper
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (3 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 06/34] drm/komeda: Move checking src coordinates to komeda_fb_create Andrzej Pietrasiewicz
                         ` (30 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Makes the code shorter and more readable.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c  | 16 ++--------------
 1 file changed, 2 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 1b01a625f40e..2f993a9cfb8b 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -52,20 +52,8 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 		return -ENOENT;
 	}
 
-	switch (fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
-	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
-		alignment_w = 32;
-		alignment_h = 8;
-		break;
-	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
-		alignment_w = 16;
-		alignment_h = 16;
-		break;
-	default:
-		WARN(1, "Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
-		     fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
-		break;
-	}
+	if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h))
+		return -EINVAL;
 
 	/* tiled header afbc */
 	if (fb->modifier & AFBC_FORMAT_MOD_TILED) {
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 06/34] drm/komeda: Move checking src coordinates to komeda_fb_create
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (4 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 05/34] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 07/34] drm/komeda: Use the already available local variable Andrzej Pietrasiewicz
                         ` (29 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Next step towards unifying afbc and non-afbc cases as much as possible.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c    | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 2f993a9cfb8b..5a1e5f621a8f 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -106,9 +106,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,
 	u32 i, block_h;
 	u64 min_size;
 
-	if (komeda_fb_check_src_coords(kfb, 0, 0, fb->width, fb->height))
-		return -EINVAL;
-
 	for (i = 0; i < info->num_planes; i++) {
 		obj = drm_gem_object_lookup(file, mode_cmd->handles[i]);
 		if (!obj) {
@@ -167,10 +164,17 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
 
-	if (kfb->base.modifier)
+	if (kfb->base.modifier) {
 		ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd);
-	else
+	} else {
+		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
+					       kfb->base.height)) {
+			kfree(kfb);
+			return ERR_PTR(-EINVAL);
+		}
+
 		ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd);
+	}
 	if (ret < 0)
 		goto err_cleanup;
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 07/34] drm/komeda: Use the already available local variable
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (5 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 06/34] drm/komeda: Move checking src coordinates to komeda_fb_create Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 08/34] drm/komeda: Retrieve drm_format_info once Andrzej Pietrasiewicz
                         ` (28 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

There is a local "info" variable which is exactly fb->format, so use it.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 5a1e5f621a8f..33181bdab16b 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -130,7 +130,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,
 		}
 	}
 
-	if (fb->format->num_planes == 3) {
+	if (info->num_planes == 3) {
 		if (fb->pitches[1] != fb->pitches[2]) {
 			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
 			return -EINVAL;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 08/34] drm/komeda: Retrieve drm_format_info once
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (6 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 07/34] drm/komeda: Use the already available local variable Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 09/34] drm/komeda: Explicitly require 1 plane for AFBC Andrzej Pietrasiewicz
                         ` (27 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Next step towards unifying afbc and non-afbc cases as much as possible.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++++++++++------
 1 file changed, 11 insertions(+), 6 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 33181bdab16b..7004c3c8f8de 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -37,11 +37,12 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 };
 
 static int
-komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
+komeda_fb_afbc_size_check(struct komeda_fb *kfb,
+			  const struct drm_format_info *info,
+			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
 	struct drm_framebuffer *fb = &kfb->base;
-	const struct drm_format_info *info = fb->format;
 	struct drm_gem_object *obj;
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
 	u64 min_size;
@@ -96,12 +97,13 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 }
 
 static int
-komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb,
+komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
+			       struct komeda_fb *kfb,
+			       const struct drm_format_info *info,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
 	struct drm_framebuffer *fb = &kfb->base;
-	const struct drm_format_info *info = fb->format;
 	struct drm_gem_object *obj;
 	u32 i, block_h;
 	u64 min_size;
@@ -146,6 +148,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 {
 	struct komeda_dev *mdev = dev->dev_private;
 	struct komeda_fb *kfb;
+	const struct drm_format_info *info;
 	int ret = 0, i;
 
 	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
@@ -163,9 +166,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	}
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
+	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
-		ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd);
+		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
 	} else {
 		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 					       kfb->base.height)) {
@@ -173,7 +177,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			return ERR_PTR(-EINVAL);
 		}
 
-		ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd);
+		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file,
+						     mode_cmd);
 	}
 	if (ret < 0)
 		goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 09/34] drm/komeda: Explicitly require 1 plane for AFBC
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (7 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 08/34] drm/komeda: Retrieve drm_format_info once Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 10/34] drm/komeda: Move pitches comparison to komeda_fb_create Andrzej Pietrasiewicz
                         ` (26 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Apparently komeda silently assumes that there is only 1 plane in an AFBC
buffer. Make this assumption explicit.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 7004c3c8f8de..c0bc499a9c29 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -169,6 +169,11 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
+		if (info->num_planes != 1) {
+			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
+			kfree(kfb);
+			return ERR_PTR(-EINVAL);
+		}
 		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
 	} else {
 		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 10/34] drm/komeda: Move pitches comparison to komeda_fb_create
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (8 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 09/34] drm/komeda: Explicitly require 1 plane for AFBC Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 11/34] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Andrzej Pietrasiewicz
                         ` (25 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

For AFBC case num_planes equals 1 so the check will not affect it.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c    | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index c0bc499a9c29..5d035f6a76a6 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -132,13 +132,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 		}
 	}
 
-	if (info->num_planes == 3) {
-		if (fb->pitches[1] != fb->pitches[2]) {
-			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
-			return -EINVAL;
-		}
-	}
-
 	return 0;
 }
 
@@ -188,6 +181,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (ret < 0)
 		goto err_cleanup;
 
+	if (info->num_planes == 3)
+		if (kfb->base.pitches[1] != kfb->base.pitches[2]) {
+			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
 	ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs);
 	if (ret < 0) {
 		DRM_DEBUG_KMS("failed to initialize fb\n");
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 11/34] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (9 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 10/34] drm/komeda: Move pitches comparison to komeda_fb_create Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 12/34] drm/komeda: Factor out object lookups for non-afbc case Andrzej Pietrasiewicz
                         ` (24 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Add a variant of the function which doesn't need neither
struct drm_framebuffer nor container_of it. Maintain current interface
for existing users.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 68 +++++++++++++++----
 .../arm/display/komeda/komeda_framebuffer.h   |  7 ++
 2 files changed, 61 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 5d035f6a76a6..08f31478c6a8 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -123,7 +123,12 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 			return -EINVAL;
 		}
 
-		min_size = komeda_fb_get_pixel_addr(kfb, 0, fb->height, i)
+		min_size = komeda_fb_get_pixel_addr_nofb(info,
+							 mode_cmd->modifier[0],
+							 mode_cmd->pitches,
+							 mode_cmd->offsets,
+							 obj,
+							 0, mode_cmd->height, i)
 			 - to_drm_gem_cma_obj(obj)->paddr;
 		if (obj->size < min_size) {
 			DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n",
@@ -237,12 +242,56 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb,
 	return 0;
 }
 
+dma_addr_t
+komeda_fb_get_pixel_addr_impl(const struct drm_format_info *format,
+			      u64 modifier,
+			      const unsigned int *pitches,
+			      const unsigned int *offsets,
+			      const struct drm_gem_cma_object *obj,
+			      int x, int y, int plane)
+{
+	u32 offset, plane_x, plane_y, block_w, block_sz;
+
+	offset = offsets[plane];
+	if (modifier) {
+		block_w = drm_format_info_block_width(format, plane);
+		block_sz = format->char_per_block[plane];
+		plane_x = x / (plane ? format->hsub : 1);
+		plane_y = y / (plane ? format->vsub : 1);
+
+		offset += (plane_x / block_w) * block_sz
+			+ plane_y * pitches[plane];
+	}
+
+	return obj->paddr + offset;
+}
+
+dma_addr_t
+komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format,
+			      u64 modifier,
+			      const unsigned int *pitches,
+			      const unsigned int *offsets,
+			      struct drm_gem_object *obj,
+			      int x, int y, int plane)
+{
+	const struct drm_gem_cma_object *cma_obj;
+
+	if (plane >= format->num_planes) {
+		DRM_DEBUG_KMS("Out of max plane num.\n");
+		return -EINVAL;
+	}
+
+	cma_obj = to_drm_gem_cma_obj(obj);
+
+	return komeda_fb_get_pixel_addr_impl(format, modifier, pitches, offsets,
+					     cma_obj, x, y, plane);
+}
+
 dma_addr_t
 komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane)
 {
 	struct drm_framebuffer *fb = &kfb->base;
 	const struct drm_gem_cma_object *obj;
-	u32 offset, plane_x, plane_y, block_w, block_sz;
 
 	if (plane >= fb->format->num_planes) {
 		DRM_DEBUG_KMS("Out of max plane num.\n");
@@ -251,18 +300,9 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane)
 
 	obj = drm_fb_cma_get_gem_obj(fb, plane);
 
-	offset = fb->offsets[plane];
-	if (!fb->modifier) {
-		block_w = drm_format_info_block_width(fb->format, plane);
-		block_sz = fb->format->char_per_block[plane];
-		plane_x = x / (plane ? fb->format->hsub : 1);
-		plane_y = y / (plane ? fb->format->vsub : 1);
-
-		offset += (plane_x / block_w) * block_sz
-			+ plane_y * fb->pitches[plane];
-	}
-
-	return obj->paddr + offset;
+	return komeda_fb_get_pixel_addr_impl(fb->format, fb->modifier,
+					     fb->pitches, fb->offsets,
+					     obj, x, y, plane);
 }
 
 /* if the fb can be supported by a specific layer */
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
index c61ca98a3a63..2f1f421d3e7f 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
@@ -42,6 +42,13 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb,
 			       u32 src_x, u32 src_y, u32 src_w, u32 src_h);
 dma_addr_t
 komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane);
+dma_addr_t
+komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format,
+			      u64 modifier,
+			      const unsigned int *pitches,
+			      const unsigned int *offsets,
+			      struct drm_gem_object *obj,
+			      int x, int y, int plane);
 bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type,
 		u32 rot);
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 12/34] drm/komeda: Factor out object lookups for non-afbc case
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (10 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 11/34] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:49       ` [PATCHv5 13/34] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Andrzej Pietrasiewicz
                         ` (23 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Ultimately we want lookups happening only once in komeda's fb_create
implementation.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 21 ++++++++++++-------
 1 file changed, 13 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 08f31478c6a8..2014cd843aeb 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -100,6 +100,7 @@ static int
 komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 			       struct komeda_fb *kfb,
 			       const struct drm_format_info *info,
+			       struct drm_gem_object **objs,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
@@ -109,12 +110,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 	u64 min_size;
 
 	for (i = 0; i < info->num_planes; i++) {
-		obj = drm_gem_object_lookup(file, mode_cmd->handles[i]);
-		if (!obj) {
-			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-			return -ENOENT;
-		}
-		fb->obj[i] = obj;
+		obj = objs[i];
 
 		block_h = drm_format_info_block_height(info, i);
 		if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) {
@@ -174,14 +170,23 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		}
 		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
 	} else {
+		struct drm_gem_object *objs[4];
+
 		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 					       kfb->base.height)) {
 			kfree(kfb);
 			return ERR_PTR(-EINVAL);
 		}
+		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+		if (ret < 0) {
+			kfree(kfb);
+			return ERR_PTR(ret);
+		}
 
-		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file,
-						     mode_cmd);
+		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs,
+						     file, mode_cmd);
+		for (i = 0; i < info->num_planes; ++i)
+			kfb->base.obj[i] = objs[i];
 	}
 	if (ret < 0)
 		goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 13/34] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (11 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 12/34] drm/komeda: Factor out object lookups for non-afbc case Andrzej Pietrasiewicz
@ 2019-12-17 14:49       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 14/34] drm/komeda: Factor out object lookups for afbc case Andrzej Pietrasiewicz
                         ` (22 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:49 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

All necessary data is now available in other data structures.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 9 ++++-----
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 2014cd843aeb..43db95a76291 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -98,13 +98,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 
 static int
 komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
-			       struct komeda_fb *kfb,
 			       const struct drm_format_info *info,
 			       struct drm_gem_object **objs,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	struct drm_framebuffer *fb = &kfb->base;
 	struct drm_gem_object *obj;
 	u32 i, block_h;
 	u64 min_size;
@@ -113,9 +111,10 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
 		obj = objs[i];
 
 		block_h = drm_format_info_block_height(info, i);
-		if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) {
+		if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) {
 			DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n",
-				      i, fb->pitches[i], mdev->chip.bus_width);
+				      i, mode_cmd->pitches[i],
+				      mdev->chip.bus_width);
 			return -EINVAL;
 		}
 
@@ -183,7 +182,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			return ERR_PTR(ret);
 		}
 
-		ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs,
+		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
 		for (i = 0; i < info->num_planes; ++i)
 			kfb->base.obj[i] = objs[i];
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 14/34] drm/komeda: Factor out object lookups for afbc case
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (12 preceding siblings ...)
  2019-12-17 14:49       ` [PATCHv5 13/34] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 15/34] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Andrzej Pietrasiewicz
                         ` (21 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Ultimately we want lookups happening only once in komeda's fb_create
implementation.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 30 +++++++++++--------
 1 file changed, 17 insertions(+), 13 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 43db95a76291..6b11a1b21ef6 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -39,6 +39,7 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 static int
 komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 			  const struct drm_format_info *info,
+			  struct drm_gem_object **objs,
 			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
@@ -47,11 +48,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
 	u64 min_size;
 
-	obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
-	if (!obj) {
-		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-		return -ENOENT;
-	}
+	obj = objs[0];
 
 	if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h))
 		return -EINVAL;
@@ -70,7 +67,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 
 	if (fb->offsets[0] % alignment_header) {
 		DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
-		goto check_failed;
+		return -EINVAL;
 	}
 
 	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
@@ -85,15 +82,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	if (min_size > obj->size) {
 		DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n",
 			      obj->size, min_size);
-		goto check_failed;
+		return -EINVAL;
 	}
 
-	fb->obj[0] = obj;
 	return 0;
-
-check_failed:
-	drm_gem_object_put_unlocked(obj);
-	return -EINVAL;
 }
 
 static int
@@ -162,12 +154,24 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
+		struct drm_gem_object *objs[4];
+
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			kfree(kfb);
 			return ERR_PTR(-EINVAL);
 		}
-		ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd);
+
+		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+		if (ret < 0) {
+			kfree(kfb);
+			return ERR_PTR(ret);
+		}
+
+		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
+						mode_cmd);
+		for (i = 0; i < info->num_planes; ++i)
+			kfb->base.obj[i] = objs[i];
 	} else {
 		struct drm_gem_object *objs[4];
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 15/34] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (13 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 14/34] drm/komeda: Factor out object lookups for afbc case Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 16/34] drm/komeda: Simplify error handling Andrzej Pietrasiewicz
                         ` (20 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

It does still depend on komeda_fb, but only for komeda-specific parameters.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../drm/arm/display/komeda/komeda_framebuffer.c   | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 6b11a1b21ef6..aa703aabbeee 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -43,18 +43,17 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	struct drm_framebuffer *fb = &kfb->base;
 	struct drm_gem_object *obj;
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
 	u64 min_size;
 
 	obj = objs[0];
 
-	if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h))
+	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h))
 		return -EINVAL;
 
 	/* tiled header afbc */
-	if (fb->modifier & AFBC_FORMAT_MOD_TILED) {
+	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
 		alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
 		alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
 		alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
@@ -62,10 +61,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 		alignment_header = AFBC_BODY_START_ALIGNMENT;
 	}
 
-	kfb->aligned_w = ALIGN(fb->width, alignment_w);
-	kfb->aligned_h = ALIGN(fb->height, alignment_h);
+	kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
+	kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
 
-	if (fb->offsets[0] % alignment_header) {
+	if (mode_cmd->offsets[0] % alignment_header) {
 		DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
 		return -EINVAL;
 	}
@@ -74,11 +73,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
 				    alignment_header);
 
-	bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
+	bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
 	kfb->afbc_size = kfb->offset_payload + n_blocks *
 			 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
 			       AFBC_SUPERBLK_ALIGNMENT);
-	min_size = kfb->afbc_size + fb->offsets[0];
+	min_size = kfb->afbc_size + mode_cmd->offsets[0];
 	if (min_size > obj->size) {
 		DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n",
 			      obj->size, min_size);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 16/34] drm/komeda: Simplify error handling
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (14 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 15/34] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 17/34] drm/komeda: Move object lookup before size checks Andrzej Pietrasiewicz
                         ` (19 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use less code to handle errors.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 32 ++++++++-----------
 1 file changed, 14 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index aa703aabbeee..f50f83c68c70 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -145,8 +145,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (!kfb->format_caps) {
 		DRM_DEBUG_KMS("FMT %x is not supported.\n",
 			      mode_cmd->pixel_format);
-		kfree(kfb);
-		return ERR_PTR(-EINVAL);
+		ret = -EINVAL;
+		goto err_free;
 	}
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
@@ -157,15 +157,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
-			kfree(kfb);
-			return ERR_PTR(-EINVAL);
+			ret = -EINVAL;
+			goto err_free;
 		}
 
 		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0) {
-			kfree(kfb);
-			return ERR_PTR(ret);
-		}
+		if (ret < 0)
+			goto err_free;
 
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
@@ -174,16 +172,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	} else {
 		struct drm_gem_object *objs[4];
 
-		if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
-					       kfb->base.height)) {
-			kfree(kfb);
-			return ERR_PTR(-EINVAL);
-		}
+		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
+						 kfb->base.height);
+		if (ret)
+			goto err_free;
+
 		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0) {
-			kfree(kfb);
-			return ERR_PTR(ret);
-		}
+		if (ret < 0)
+			goto err_free;
 
 		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
@@ -214,7 +210,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 err_cleanup:
 	for (i = 0; i < kfb->base.format->num_planes; i++)
 		drm_gem_object_put_unlocked(kfb->base.obj[i]);
-
+err_free:
 	kfree(kfb);
 	return ERR_PTR(ret);
 }
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 17/34] drm/komeda: Move object lookup before size checks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (15 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 16/34] drm/komeda: Simplify error handling Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 18/34] drm/komeda: Move object assignments to framebuffer to after " Andrzej Pietrasiewicz
                         ` (18 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The lookup is performed the same way in both branches of the "if"
statement, so move the lookup to before the "if". err_cleanup case
is adjusted accordingly.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 23 +++++++------------
 1 file changed, 8 insertions(+), 15 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index f50f83c68c70..acffceeb26f1 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -131,6 +131,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
 {
 	struct komeda_dev *mdev = dev->dev_private;
+	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
 	const struct drm_format_info *info;
 	int ret = 0, i;
@@ -149,37 +150,29 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		goto err_free;
 	}
 
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		goto err_free;
+
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
 	info = kfb->base.format;
 
 	if (kfb->base.modifier) {
-		struct drm_gem_object *objs[4];
-
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
-			goto err_free;
+			goto err_cleanup;
 		}
 
-		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0)
-			goto err_free;
-
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
 		for (i = 0; i < info->num_planes; ++i)
 			kfb->base.obj[i] = objs[i];
 	} else {
-		struct drm_gem_object *objs[4];
-
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 						 kfb->base.height);
 		if (ret)
-			goto err_free;
-
-		ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
-		if (ret < 0)
-			goto err_free;
+			goto err_cleanup;
 
 		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
@@ -209,7 +202,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 err_cleanup:
 	for (i = 0; i < kfb->base.format->num_planes; i++)
-		drm_gem_object_put_unlocked(kfb->base.obj[i]);
+		drm_gem_object_put_unlocked(objs[i]);
 err_free:
 	kfree(kfb);
 	return ERR_PTR(ret);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 18/34] drm/komeda: Move object assignments to framebuffer to after size checks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (16 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 17/34] drm/komeda: Move object lookup before size checks Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 19/34] drm/komeda: Make the size checks independent from framebuffer structure Andrzej Pietrasiewicz
                         ` (17 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The assignments are the same in both branches of the "if" statement and
nothing depends on them between their original position and the new
position, so this can be safely done.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 7 +++----
 1 file changed, 3 insertions(+), 4 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index acffceeb26f1..d52278ca27fb 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -166,8 +166,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
-		for (i = 0; i < info->num_planes; ++i)
-			kfb->base.obj[i] = objs[i];
 	} else {
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
 						 kfb->base.height);
@@ -176,8 +174,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 
 		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
 						     file, mode_cmd);
-		for (i = 0; i < info->num_planes; ++i)
-			kfb->base.obj[i] = objs[i];
 	}
 	if (ret < 0)
 		goto err_cleanup;
@@ -189,6 +185,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
+	for (i = 0; i < info->num_planes; ++i)
+		kfb->base.obj[i] = objs[i];
+
 	ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs);
 	if (ret < 0) {
 		DRM_DEBUG_KMS("failed to initialize fb\n");
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 19/34] drm/komeda: Make the size checks independent from framebuffer structure
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (17 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 18/34] drm/komeda: Move object assignments to framebuffer to after " Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 20/34] drm/komeda: Move helper invocation to after size checks Andrzej Pietrasiewicz
                         ` (16 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The same data is available in mode_cmd.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c    | 10 +++++-----
 1 file changed, 5 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index d52278ca27fb..42ccd4647919 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -155,9 +155,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		goto err_free;
 
 	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
-	info = kfb->base.format;
+	info = drm_get_format_info(dev, mode_cmd);
 
-	if (kfb->base.modifier) {
+	if (mode_cmd->modifier[0]) {
 		if (info->num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
@@ -167,8 +167,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
 	} else {
-		ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width,
-						 kfb->base.height);
+		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
+						 mode_cmd->height);
 		if (ret)
 			goto err_cleanup;
 
@@ -179,7 +179,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		goto err_cleanup;
 
 	if (info->num_planes == 3)
-		if (kfb->base.pitches[1] != kfb->base.pitches[2]) {
+		if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) {
 			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
 			ret = -EINVAL;
 			goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 20/34] drm/komeda: Move helper invocation to after size checks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (18 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 19/34] drm/komeda: Make the size checks independent from framebuffer structure Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 21/34] drm/komeda: Use helper for common tasks Andrzej Pietrasiewicz
                         ` (15 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Between the old and new place nothing depends on data retrieved with the
helper, so it is safe to move its invocation.
The err_cleanup case is changed accordingly.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++--
 1 file changed, 3 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 42ccd4647919..c2b29d4e6fbb 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -154,7 +154,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (ret < 0)
 		goto err_free;
 
-	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
@@ -185,6 +184,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
+	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
+
 	for (i = 0; i < info->num_planes; ++i)
 		kfb->base.obj[i] = objs[i];
 
@@ -200,7 +201,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	return &kfb->base;
 
 err_cleanup:
-	for (i = 0; i < kfb->base.format->num_planes; i++)
+	for (i = 0; i < info->num_planes; i++)
 		drm_gem_object_put_unlocked(objs[i]);
 err_free:
 	kfree(kfb);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 21/34] drm/komeda: Use helper for common tasks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (19 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 20/34] drm/komeda: Move helper invocation to after size checks Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 22/34] drm/komeda: Use return value of drm_gem_fb_lookup Andrzej Pietrasiewicz
                         ` (14 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The replaced fragment is 1:1 with the helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 13 +++----------
 1 file changed, 3 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index c2b29d4e6fbb..26d1a3cfb587 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -184,17 +184,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
-	drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd);
-
-	for (i = 0; i < info->num_planes; ++i)
-		kfb->base.obj[i] = objs[i];
-
-	ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs);
-	if (ret < 0) {
-		DRM_DEBUG_KMS("failed to initialize fb\n");
-
+	ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs,
+					 info->num_planes, &komeda_fb_funcs);
+	if (ret < 0)
 		goto err_cleanup;
-	}
 
 	kfb->is_va = mdev->iommu ? true : false;
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 22/34] drm/komeda: Use return value of drm_gem_fb_lookup
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (20 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 21/34] drm/komeda: Use helper for common tasks Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 23/34] drm/komeda: Use special helper for non-afbc size checks Andrzej Pietrasiewicz
                         ` (13 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Reduce dependency of the function on the "info" variable as much as
possible.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c   | 11 ++++++-----
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 26d1a3cfb587..9139fe5619be 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -134,7 +134,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
 	const struct drm_format_info *info;
-	int ret = 0, i;
+	int ret = 0, i, num_planes;
 
 	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
 	if (!kfb)
@@ -153,11 +153,12 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
 	if (ret < 0)
 		goto err_free;
+	num_planes = ret;
 
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
-		if (info->num_planes != 1) {
+		if (num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
@@ -177,7 +178,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	if (ret < 0)
 		goto err_cleanup;
 
-	if (info->num_planes == 3)
+	if (num_planes == 3)
 		if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) {
 			DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n");
 			ret = -EINVAL;
@@ -185,7 +186,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		}
 
 	ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs,
-					 info->num_planes, &komeda_fb_funcs);
+					 num_planes, &komeda_fb_funcs);
 	if (ret < 0)
 		goto err_cleanup;
 
@@ -194,7 +195,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	return &kfb->base;
 
 err_cleanup:
-	for (i = 0; i < info->num_planes; i++)
+	for (i = 0; i < num_planes; i++)
 		drm_gem_object_put_unlocked(objs[i]);
 err_free:
 	kfree(kfb);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 23/34] drm/komeda: Use special helper for non-afbc size checks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (21 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 22/34] drm/komeda: Use return value of drm_gem_fb_lookup Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 24/34] drm/komeda: Factor in the invocation of special helper Andrzej Pietrasiewicz
                         ` (12 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use the generic helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 46 +++++++++----------
 1 file changed, 21 insertions(+), 25 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 9139fe5619be..d75176e24f24 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -88,42 +88,38 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 }
 
 static int
-komeda_fb_none_afbc_size_check(struct komeda_dev *mdev,
+komeda_fb_none_afbc_size_check(struct drm_device *dev,
 			       const struct drm_format_info *info,
 			       struct drm_gem_object **objs,
 			       struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+	struct komeda_dev *mdev = dev->dev_private;
+	struct drm_size_check check = { 0 };
 	struct drm_gem_object *obj;
-	u32 i, block_h;
-	u64 min_size;
+	u32 i;
 
 	for (i = 0; i < info->num_planes; i++) {
 		obj = objs[i];
 
-		block_h = drm_format_info_block_height(info, i);
-		if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) {
-			DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n",
-				      i, mode_cmd->pitches[i],
-				      mdev->chip.bus_width);
-			return -EINVAL;
-		}
-
-		min_size = komeda_fb_get_pixel_addr_nofb(info,
-							 mode_cmd->modifier[0],
-							 mode_cmd->pitches,
-							 mode_cmd->offsets,
-							 obj,
-							 0, mode_cmd->height, i)
-			 - to_drm_gem_cma_obj(obj)->paddr;
-		if (obj->size < min_size) {
-			DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n",
-				      i, obj->size, min_size);
-			return -EINVAL;
-		}
+		check.pitch_multiplier[i] =
+			drm_format_info_block_height(info, i);
+
+		check.min_size[i] =
+			komeda_fb_get_pixel_addr_nofb(info,
+						      mode_cmd->modifier[0],
+						      mode_cmd->pitches,
+						      mode_cmd->offsets,
+						      obj,
+						      0, mode_cmd->height, i)
+			- to_drm_gem_cma_obj(obj)->paddr;
 	}
 
-	return 0;
+	check.pitch_modulo = mdev->chip.bus_width;
+	check.use_pitch_multiplier = true;
+	check.use_min_size = true;
+
+	return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 }
 
 struct drm_framebuffer *
@@ -172,7 +168,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		if (ret)
 			goto err_cleanup;
 
-		ret = komeda_fb_none_afbc_size_check(mdev, info, objs,
+		ret = komeda_fb_none_afbc_size_check(dev, info, objs,
 						     file, mode_cmd);
 	}
 	if (ret < 0)
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 24/34] drm/komeda: Factor in the invocation of special helper
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (22 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 23/34] drm/komeda: Use special helper for non-afbc size checks Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 25/34] drm/komeda: Use special helper for afbc case size check Andrzej Pietrasiewicz
                         ` (11 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Don't use a separate function to call the helper. The ultimate goal is
to unify non-afbc and afbc cases as much as possible and then moving the
helper invocation outside the if-else clause.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 57 +++++++------------
 1 file changed, 20 insertions(+), 37 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index d75176e24f24..766b6944c53c 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -87,41 +87,6 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	return 0;
 }
 
-static int
-komeda_fb_none_afbc_size_check(struct drm_device *dev,
-			       const struct drm_format_info *info,
-			       struct drm_gem_object **objs,
-			       struct drm_file *file,
-			       const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	struct komeda_dev *mdev = dev->dev_private;
-	struct drm_size_check check = { 0 };
-	struct drm_gem_object *obj;
-	u32 i;
-
-	for (i = 0; i < info->num_planes; i++) {
-		obj = objs[i];
-
-		check.pitch_multiplier[i] =
-			drm_format_info_block_height(info, i);
-
-		check.min_size[i] =
-			komeda_fb_get_pixel_addr_nofb(info,
-						      mode_cmd->modifier[0],
-						      mode_cmd->pitches,
-						      mode_cmd->offsets,
-						      obj,
-						      0, mode_cmd->height, i)
-			- to_drm_gem_cma_obj(obj)->paddr;
-	}
-
-	check.pitch_modulo = mdev->chip.bus_width;
-	check.use_pitch_multiplier = true;
-	check.use_min_size = true;
-
-	return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
-}
-
 struct drm_framebuffer *
 komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -163,13 +128,31 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
 						mode_cmd);
 	} else {
+		struct drm_size_check check = { 0 };
+
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
 						 mode_cmd->height);
 		if (ret)
 			goto err_cleanup;
 
-		ret = komeda_fb_none_afbc_size_check(dev, info, objs,
-						     file, mode_cmd);
+		for (i = 0; i < num_planes; i++) {
+			check.pitch_multiplier[i] =
+				drm_format_info_block_height(info, i);
+
+			check.min_size[i] =
+				komeda_fb_get_pixel_addr_nofb(info,
+					mode_cmd->modifier[0],
+					mode_cmd->pitches,
+					mode_cmd->offsets, objs[i],
+					0, mode_cmd->height, i)
+				- to_drm_gem_cma_obj(objs[i])->paddr;
+		}
+
+		check.pitch_modulo = mdev->chip.bus_width;
+		check.use_pitch_multiplier = true;
+		check.use_min_size = true;
+
+		ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 	}
 	if (ret < 0)
 		goto err_cleanup;
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 25/34] drm/komeda: Use special helper for afbc case size check
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (23 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 24/34] drm/komeda: Factor in the invocation of special helper Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 26/34] drm/komeda: Factor in the invocation of special helper, afbc case Andrzej Pietrasiewicz
                         ` (10 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use generic helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 22 +++++++------------
 1 file changed, 8 insertions(+), 14 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 766b6944c53c..2c9691b86cff 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -37,17 +37,15 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 };
 
 static int
-komeda_fb_afbc_size_check(struct komeda_fb *kfb,
+komeda_fb_afbc_size_check(struct drm_device *dev,
+			  struct komeda_fb *kfb,
 			  const struct drm_format_info *info,
 			  struct drm_gem_object **objs,
 			  struct drm_file *file,
 			  const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	struct drm_gem_object *obj;
+	struct drm_size_check check = { 0 };
 	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
-	u64 min_size;
-
-	obj = objs[0];
 
 	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h))
 		return -EINVAL;
@@ -77,14 +75,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb,
 	kfb->afbc_size = kfb->offset_payload + n_blocks *
 			 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
 			       AFBC_SUPERBLK_ALIGNMENT);
-	min_size = kfb->afbc_size + mode_cmd->offsets[0];
-	if (min_size > obj->size) {
-		DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n",
-			      obj->size, min_size);
-		return -EINVAL;
-	}
+	check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
+	check.use_min_size = true;
 
-	return 0;
+	return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 }
 
 struct drm_framebuffer *
@@ -125,8 +119,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
-		ret = komeda_fb_afbc_size_check(kfb, info, objs, file,
-						mode_cmd);
+		ret = komeda_fb_afbc_size_check(dev, kfb, info, objs,
+						file, mode_cmd);
 	} else {
 		struct drm_size_check check = { 0 };
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 26/34] drm/komeda: Factor in the invocation of special helper, afbc case
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (24 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 25/34] drm/komeda: Use special helper for afbc case size check Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 27/34] drm/komeda: Move special helper invocation outside if-else Andrzej Pietrasiewicz
                         ` (9 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Prepare for unification with non-afbc case.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/komeda_framebuffer.c   | 84 ++++++++-----------
 1 file changed, 37 insertions(+), 47 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 2c9691b86cff..7e02a04cdd11 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -36,51 +36,6 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = {
 	.create_handle	= komeda_fb_create_handle,
 };
 
-static int
-komeda_fb_afbc_size_check(struct drm_device *dev,
-			  struct komeda_fb *kfb,
-			  const struct drm_format_info *info,
-			  struct drm_gem_object **objs,
-			  struct drm_file *file,
-			  const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	struct drm_size_check check = { 0 };
-	u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp;
-
-	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h))
-		return -EINVAL;
-
-	/* tiled header afbc */
-	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
-		alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
-		alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
-		alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
-	} else {
-		alignment_header = AFBC_BODY_START_ALIGNMENT;
-	}
-
-	kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
-	kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
-
-	if (mode_cmd->offsets[0] % alignment_header) {
-		DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
-		return -EINVAL;
-	}
-
-	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
-				    alignment_header);
-
-	bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
-	kfb->afbc_size = kfb->offset_payload + n_blocks *
-			 ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8,
-			       AFBC_SUPERBLK_ALIGNMENT);
-	check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
-	check.use_min_size = true;
-
-	return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
-}
-
 struct drm_framebuffer *
 komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
@@ -113,14 +68,49 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
+		struct drm_size_check check = { 0 };
+		u32 alignment_w = 0, alignment_h = 0;
+		u32 alignment_header, n_blocks, bpp;
+
 		if (num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
 		}
 
-		ret = komeda_fb_afbc_size_check(dev, kfb, info, objs,
-						file, mode_cmd);
+		if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) {
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+		/* tiled header afbc */
+		if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
+			alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
+			alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
+			alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
+		} else {
+			alignment_header = AFBC_BODY_START_ALIGNMENT;
+		}
+
+		kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
+		kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
+
+		if (mode_cmd->offsets[0] % alignment_header) {
+			DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+		n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
+		kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, alignment_header);
+
+		bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
+		kfb->afbc_size = kfb->offset_payload
+			       + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT);
+		check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
+		check.use_min_size = true;
+
+		ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 	} else {
 		struct drm_size_check check = { 0 };
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 27/34] drm/komeda: Move special helper invocation outside if-else
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (25 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 26/34] drm/komeda: Factor in the invocation of special helper, afbc case Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 28/34] drm/komeda: Move to helper checking afbc buffer size Andrzej Pietrasiewicz
                         ` (8 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The invocation is the same in both cases and is the last thing inside a
block, so move it outside the if-else clause.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../gpu/drm/arm/display/komeda/komeda_framebuffer.c    | 10 +++-------
 1 file changed, 3 insertions(+), 7 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index 7e02a04cdd11..bf4309b62d37 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -44,6 +44,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	struct drm_gem_object *objs[4];
 	struct komeda_fb *kfb;
 	const struct drm_format_info *info;
+	struct drm_size_check check = { 0 };
+
 	int ret = 0, i, num_planes;
 
 	kfb = kzalloc(sizeof(*kfb), GFP_KERNEL);
@@ -68,7 +70,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
-		struct drm_size_check check = { 0 };
 		u32 alignment_w = 0, alignment_h = 0;
 		u32 alignment_header, n_blocks, bpp;
 
@@ -109,11 +110,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			       + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT);
 		check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
 		check.use_min_size = true;
-
-		ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 	} else {
-		struct drm_size_check check = { 0 };
-
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
 						 mode_cmd->height);
 		if (ret)
@@ -135,9 +132,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 		check.pitch_modulo = mdev->chip.bus_width;
 		check.use_pitch_multiplier = true;
 		check.use_min_size = true;
-
-		ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 	}
+	ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
 	if (ret < 0)
 		goto err_cleanup;
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 28/34] drm/komeda: Move to helper checking afbc buffer size
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (26 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 27/34] drm/komeda: Move special helper invocation outside if-else Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
                         ` (7 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use generic helper code. Adapt struct komeda_fb users to new location
of respective data members.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 .../arm/display/komeda/d71/d71_component.c    |  6 +--
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++--------------
 .../arm/display/komeda/komeda_framebuffer.h   | 14 ++----
 .../display/komeda/komeda_pipeline_state.c    | 14 +++---
 4 files changed, 26 insertions(+), 52 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
index 8a02ade369db..5131e51e56d4 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
@@ -186,7 +186,7 @@ static void d71_layer_update_fb(struct komeda_component *c,
 				struct komeda_fb *kfb,
 				dma_addr_t *addr)
 {
-	struct drm_framebuffer *fb = &kfb->base;
+	struct drm_framebuffer *fb = &kfb->base.base;
 	const struct drm_format_info *info = fb->format;
 	u32 __iomem *reg = c->reg;
 	int block_h;
@@ -234,9 +234,9 @@ static void d71_layer_update(struct komeda_component *c,
 							     st->afbc_crop_b));
 		/* afbc 1.2 wants payload, afbc 1.0/1.1 wants end_addr */
 		if (fb->modifier & AFBC_FORMAT_MOD_TILED)
-			addr = st->addr[0] + kfb->offset_payload;
+			addr = st->addr[0] + kfb->base.offset_payload;
 		else
-			addr = st->addr[0] + kfb->afbc_size - 1;
+			addr = st->addr[0] + kfb->base.afbc_size - 1;
 
 		malidp_write32(reg, BLK_P1_PTR_LOW, lower_32_bits(addr));
 		malidp_write32(reg, BLK_P1_PTR_HIGH, upper_32_bits(addr));
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
index bf4309b62d37..45318ed052a9 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c
@@ -70,46 +70,26 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 	info = drm_get_format_info(dev, mode_cmd);
 
 	if (mode_cmd->modifier[0]) {
-		u32 alignment_w = 0, alignment_h = 0;
-		u32 alignment_header, n_blocks, bpp;
-
 		if (num_planes != 1) {
 			DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
 		}
 
-		if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) {
-			ret = -EINVAL;
-			goto err_cleanup;
-		}
-
 		/* tiled header afbc */
-		if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
-			alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT;
-			alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT;
-			alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
-		} else {
-			alignment_header = AFBC_BODY_START_ALIGNMENT;
-		}
-
-		kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w);
-		kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h);
+		if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED)
+			kfb->base.alignment_header = AFBC_TH_BODY_START_ALIGNMENT;
+		else
+			kfb->base.alignment_header = AFBC_BODY_START_ALIGNMENT;
 
-		if (mode_cmd->offsets[0] % alignment_header) {
+		if (mode_cmd->offsets[0] % kfb->base.alignment_header) {
 			DRM_DEBUG_KMS("afbc offset alignment check failed.\n");
 			ret = -EINVAL;
 			goto err_cleanup;
 		}
 
-		n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-		kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, alignment_header);
-
-		bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
-		kfb->afbc_size = kfb->offset_payload
-			       + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT);
-		check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0];
-		check.use_min_size = true;
+		kfb->base.bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]);
+		check.data = &kfb->base;
 	} else {
 		ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width,
 						 mode_cmd->height);
@@ -144,14 +124,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 			goto err_cleanup;
 		}
 
-	ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs,
+	ret = drm_gem_fb_init_with_funcs(&kfb->base.base, dev, mode_cmd, objs,
 					 num_planes, &komeda_fb_funcs);
 	if (ret < 0)
 		goto err_cleanup;
 
 	kfb->is_va = mdev->iommu ? true : false;
 
-	return &kfb->base;
+	return &kfb->base.base;
 
 err_cleanup:
 	for (i = 0; i < num_planes; i++)
@@ -164,7 +144,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file,
 int komeda_fb_check_src_coords(const struct komeda_fb *kfb,
 			       u32 src_x, u32 src_y, u32 src_w, u32 src_h)
 {
-	const struct drm_framebuffer *fb = &kfb->base;
+	const struct drm_framebuffer *fb = &kfb->base.base;
 	const struct drm_format_info *info = fb->format;
 	u32 block_w = drm_format_info_block_width(fb->format, 0);
 	u32 block_h = drm_format_info_block_height(fb->format, 0);
@@ -239,7 +219,7 @@ komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format,
 dma_addr_t
 komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane)
 {
-	struct drm_framebuffer *fb = &kfb->base;
+	struct drm_framebuffer *fb = &kfb->base.base;
 	const struct drm_gem_cma_object *obj;
 
 	if (plane >= fb->format->num_planes) {
@@ -258,7 +238,7 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane)
 bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type,
 				  u32 rot)
 {
-	struct drm_framebuffer *fb = &kfb->base;
+	struct drm_framebuffer *fb = &kfb->base.base;
 	struct komeda_dev *mdev = fb->dev->dev_private;
 	u32 fourcc = fb->format->format;
 	u64 modifier = fb->modifier;
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
index 2f1f421d3e7f..6cb9d321b6d4 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h
@@ -14,8 +14,8 @@
  * struct komeda_fb - Entending drm_framebuffer with komeda attribute
  */
 struct komeda_fb {
-	/** @base: &drm_framebuffer */
-	struct drm_framebuffer base;
+	/** @base: &drm_afbc_framebuffer */
+	struct drm_afbc_framebuffer base;
 	/**
 	 * @format_caps:
 	 * extends drm_format_info for komeda specific information
@@ -23,17 +23,9 @@ struct komeda_fb {
 	const struct komeda_format_caps *format_caps;
 	/** @is_va: if smmu is enabled, it will be true */
 	bool is_va;
-	/** @aligned_w: aligned frame buffer width */
-	u32 aligned_w;
-	/** @aligned_h: aligned frame buffer height */
-	u32 aligned_h;
-	/** @afbc_size: minimum size of afbc */
-	u32 afbc_size;
-	/** @offset_payload: start of afbc body buffer */
-	u32 offset_payload;
 };
 
-#define to_kfb(dfb)	container_of(dfb, struct komeda_fb, base)
+#define to_kfb(dfb)	container_of(dfb, struct komeda_fb, base.base)
 
 struct drm_framebuffer *
 komeda_fb_create(struct drm_device *dev, struct drm_file *file,
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
index 0930234abb9d..f7721244edad 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
@@ -320,7 +320,7 @@ komeda_layer_check_cfg(struct komeda_layer *layer,
 	else
 		line_sz = dflow->in_w;
 
-	if (kfb->base.format->hsub > 1)
+	if (kfb->base.base.format->hsub > 1)
 		max_line_sz = layer->yuv_line_sz;
 	else
 		max_line_sz = layer->line_sz;
@@ -360,12 +360,14 @@ komeda_layer_validate(struct komeda_layer *layer,
 	st->rot = dflow->rot;
 
 	if (fb->modifier) {
-		st->hsize = kfb->aligned_w;
-		st->vsize = kfb->aligned_h;
+		st->hsize = kfb->base.aligned_width;
+		st->vsize = kfb->base.aligned_height;
 		st->afbc_crop_l = dflow->in_x;
-		st->afbc_crop_r = kfb->aligned_w - dflow->in_x - dflow->in_w;
+		st->afbc_crop_r = kfb->base.aligned_width
+				- dflow->in_x - dflow->in_w;
 		st->afbc_crop_t = dflow->in_y;
-		st->afbc_crop_b = kfb->aligned_h - dflow->in_y - dflow->in_h;
+		st->afbc_crop_b = kfb->base.aligned_height
+				- dflow->in_y - dflow->in_h;
 	} else {
 		st->hsize = dflow->in_w;
 		st->vsize = dflow->in_h;
@@ -419,7 +421,7 @@ komeda_wb_layer_validate(struct komeda_layer *wb_layer,
 	st->hsize = dflow->out_w;
 	st->vsize = dflow->out_h;
 
-	for (i = 0; i < kfb->base.format->num_planes; i++)
+	for (i = 0; i < kfb->base.base.format->num_planes; i++)
 		st->addr[i] = komeda_fb_get_pixel_addr(kfb, dflow->out_x,
 						       dflow->out_y, i);
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (27 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 28/34] drm/komeda: Move to helper checking afbc buffer size Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2020-02-20 11:26         ` Boris Brezillon
  2019-12-17 14:50       ` [PATCHv5 30/34] drm/arm/malidp: Integrate verify functions Andrzej Pietrasiewicz
                         ` (6 subsequent siblings)
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

This will make it easier to transition to generic afbc-aware helpers.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 37d92a06318e..961e5a3f5b08 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -362,10 +362,10 @@ static bool
 malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
 			       const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
-		return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
+	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
+		return false;
 
-	return false;
+	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
 }
 
 static struct drm_framebuffer *
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 30/34] drm/arm/malidp: Integrate verify functions
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (28 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 31/34] drm/arm/malidp: Factor in afbc framebuffer verification Andrzej Pietrasiewicz
                         ` (5 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

The next step towards using generic afbc-aware helpers.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index 961e5a3f5b08..e1502666bce0 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -270,9 +270,16 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = {
 };
 
 static bool
-malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
-				    const struct drm_mode_fb_cmd2 *mode_cmd)
+malidp_verify_afbc_framebuffer(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;
+
 	if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
 					mode_cmd->modifier[0]) == false)
 		return false;
@@ -294,21 +301,6 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
 		return false;
 	}
 
-	return true;
-}
-
-static bool
-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;
@@ -358,16 +350,6 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
 	return true;
 }
 
-static bool
-malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
-			       const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
-		return false;
-
-	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
-}
-
 static struct drm_framebuffer *
 malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 31/34] drm/arm/malidp: Factor in afbc framebuffer verification
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (29 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 30/34] drm/arm/malidp: Integrate verify functions Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 32/34] drm/arm/malidp: Use generic helpers for afbc checks Andrzej Pietrasiewicz
                         ` (4 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Prepare for using generic afbc-aware helpers.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index e1502666bce0..b53fc01baf2b 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -269,94 +269,88 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = {
 	.atomic_commit_tail = malidp_atomic_commit_tail,
 };
 
-static bool
-malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
-			       const struct drm_mode_fb_cmd2 *mode_cmd)
+static struct drm_framebuffer *
+malidp_fb_create(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;
-
-	if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
-					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;
-	}
+	if (mode_cmd->modifier[0]) {
+		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;
+
+		if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
+						mode_cmd->modifier[0]) == false)
+			return ERR_PTR(-EINVAL);
 
-	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;
+		if (mode_cmd->offsets[0] != 0) {
+			DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
+			return ERR_PTR(-EINVAL);
 		}
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
 
-	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;
-	}
+		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 ERR_PTR(-EINVAL);
+			}
+			break;
+		default:
+			DRM_DEBUG_KMS("Unsupported AFBC block size\n");
+			return ERR_PTR(-EINVAL);
+		}
 
-	info = drm_get_format_info(dev, mode_cmd);
+		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 ERR_PTR(-EINVAL);
+		}
 
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
+		info = drm_get_format_info(dev, mode_cmd);
 
-	bpp = malidp_format_get_bpp(info->format);
+		n_superblocks = (mode_cmd->width / afbc_superblock_width) *
+			(mode_cmd->height / afbc_superblock_height);
 
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
+		bpp = malidp_format_get_bpp(info->format);
 
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
+		afbc_superblock_size =
+			(bpp * afbc_superblock_width * afbc_superblock_height)
+			/ BITS_PER_BYTE;
 
-	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;
-	}
+		afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE,
+				  AFBC_SUPERBLK_ALIGNMENT);
+		afbc_size += n_superblocks
+			* ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
 
-	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);
-		drm_gem_object_put_unlocked(objs);
-		return false;
-	}
-
-	drm_gem_object_put_unlocked(objs);
+		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 ERR_PTR(-EINVAL);
+		}
 
-	return true;
-}
+		objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
+		if (!objs) {
+			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+			return ERR_PTR(-EINVAL);
+		}
 
-static struct drm_framebuffer *
-malidp_fb_create(struct drm_device *dev, struct drm_file *file,
-		 const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	if (mode_cmd->modifier[0]) {
-		if (!malidp_verify_afbc_framebuffer(dev, file, mode_cmd))
+		if (objs->size < afbc_size) {
+			DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+				      objs->size, afbc_size);
+			drm_gem_object_put_unlocked(objs);
 			return ERR_PTR(-EINVAL);
+		}
+
+		drm_gem_object_put_unlocked(objs);
 	}
 
 	return drm_gem_fb_create(dev, file, mode_cmd);
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 32/34] drm/arm/malidp: Use generic helpers for afbc checks
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (30 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 31/34] drm/arm/malidp: Factor in afbc framebuffer verification Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2019-12-17 14:50       ` [PATCHv5 33/34] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
                         ` (3 subsequent siblings)
  35 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Helpers are now available for checking afbc buffer properties. Use those.

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

diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
index b53fc01baf2b..4cbd920b48cd 100644
--- a/drivers/gpu/drm/arm/malidp_drv.c
+++ b/drivers/gpu/drm/arm/malidp_drv.c
@@ -273,12 +273,17 @@ static struct drm_framebuffer *
 malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 		 const struct drm_mode_fb_cmd2 *mode_cmd)
 {
+	struct drm_size_check check = { 0 };
+	struct drm_gem_object *objs[4];
+	struct drm_afbc_framebuffer *afbc_fb;
+	int ret, i, num_planes;
+
+	afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL);
+	if (!afbc_fb)
+		return ERR_PTR(-ENOMEM);
+
 	if (mode_cmd->modifier[0]) {
-		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;
 
 		if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
@@ -302,32 +307,9 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 			return ERR_PTR(-EINVAL);
 		}
 
-		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 ERR_PTR(-EINVAL);
-		}
-
 		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) "
@@ -336,24 +318,31 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file,
 				      mode_cmd->width, bpp);
 			return ERR_PTR(-EINVAL);
 		}
+		afbc_fb->bpp = bpp;
+		check.data = afbc_fb;
+	}
 
-		objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
-		if (!objs) {
-			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-			return ERR_PTR(-EINVAL);
-		}
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		goto err_free;
+	num_planes = ret;
 
-		if (objs->size < afbc_size) {
-			DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
-				      objs->size, afbc_size);
-			drm_gem_object_put_unlocked(objs);
-			return ERR_PTR(-EINVAL);
-		}
+	ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
+	if (ret < 0)
+		goto err_cleanup;
 
-		drm_gem_object_put_unlocked(objs);
-	}
+	ret = drm_gem_fb_init(&afbc_fb->base, dev, mode_cmd, objs, num_planes);
+	if (ret < 0)
+		goto err_cleanup;
+
+	return &afbc_fb->base;
 
-	return drm_gem_fb_create(dev, file, mode_cmd);
+err_cleanup:
+	for (i = 0; i < num_planes; ++i)
+		drm_gem_object_put_unlocked(objs[i]);
+err_free:
+	kfree(afbc_fb);
+	return ERR_PTR(ret);
 }
 
 static const struct drm_mode_config_funcs malidp_mode_config_funcs = {
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 33/34] drm/rockchip: Use helper for common task
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (31 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 32/34] drm/arm/malidp: Use generic helpers for afbc checks Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2020-02-20 11:24         ` Boris Brezillon
  2019-12-17 14:50       ` [PATCHv5 34/34] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
                         ` (2 subsequent siblings)
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

Use generic helper code.

Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 12 ++----------
 1 file changed, 2 insertions(+), 10 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
index 221e72e71432..5806f908aa53 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
@@ -18,6 +18,7 @@
 #include "rockchip_drm_fb.h"
 #include "rockchip_drm_gem.h"
 
+
 static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
 	.destroy       = drm_gem_fb_destroy,
 	.create_handle = drm_gem_fb_create_handle,
@@ -30,22 +31,13 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm
 {
 	struct drm_framebuffer *fb;
 	int ret;
-	int i;
 
 	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
 	if (!fb)
 		return ERR_PTR(-ENOMEM);
 
-	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
-
-	for (i = 0; i < num_planes; i++)
-		fb->obj[i] = obj[i];
-
-	ret = drm_framebuffer_init(dev, fb, &rockchip_drm_fb_funcs);
+	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);
 	if (ret) {
-		DRM_DEV_ERROR(dev->dev,
-			      "Failed to initialize framebuffer: %d\n",
-			      ret);
 		kfree(fb);
 		return ERR_PTR(ret);
 	}
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* [PATCHv5 34/34] drm/rockchip: Add support for afbc
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (32 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 33/34] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
@ 2019-12-17 14:50       ` Andrzej Pietrasiewicz
  2020-02-20 11:20         ` Boris Brezillon
  2020-01-30  9:08       ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
  2020-02-20 16:54       ` Daniel Vetter
  35 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2019-12-17 14:50 UTC (permalink / raw)
  To: dri-devel
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	Andrzej Pietrasiewicz, James Wang, Mihail Atanassov, Sean Paul

This patch adds support for afbc handling. afbc is a compressed format
which reduces the necessary memory bandwidth.

Co-developed-by: Mark Yao <mark.yao@rock-chips.com>
Signed-off-by: Mark Yao <mark.yao@rock-chips.com>
Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>

# Conflicts:
#	drivers/gpu/drm/rockchip/rockchip_drm_fb.c
---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  | 105 +++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 147 ++++++++++++++++++--
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c |  83 ++++++++++-
 4 files changed, 329 insertions(+), 18 deletions(-)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
index 5806f908aa53..f26cbaa46135 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
@@ -18,6 +18,7 @@
 #include "rockchip_drm_fb.h"
 #include "rockchip_drm_gem.h"
 
+#define ROCKCHIP_MAX_AFBC_WIDTH	2560
 
 static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
 	.destroy       = drm_gem_fb_destroy,
@@ -25,32 +26,122 @@ static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
 	.dirty	       = drm_atomic_helper_dirtyfb,
 };
 
+static int rockchip_afbc_post_check(struct drm_afbc_framebuffer *afbc_fb)
+{
+	if (afbc_fb->offset) {
+		DRM_WARN("AFBC plane offset must be zero!\n");
+		return -EINVAL;
+	}
+
+	if (afbc_fb->block_width != 16 || afbc_fb->block_height != 16) {
+		DRM_WARN("Unsupported AFBC block w/h [%d/%d]\n", afbc_fb->block_width, afbc_fb->block_height);
+		return -EINVAL;
+	}
+
+	if (afbc_fb->aligned_width > ROCKCHIP_MAX_AFBC_WIDTH) {
+		DRM_WARN("Unsupported width %d>%d\n", afbc_fb->aligned_width, ROCKCHIP_MAX_AFBC_WIDTH);
+		return -EINVAL;
+	}
+
+	return 0;
+}
+
 static struct drm_framebuffer *
 rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd,
 		  struct drm_gem_object **obj, unsigned int num_planes)
 {
-	struct drm_framebuffer *fb;
+	struct drm_afbc_framebuffer *afbc_fb;
+	struct drm_size_check check = { 0 };
 	int ret;
 
-	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
-	if (!fb)
+	afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL);
+	if (!afbc_fb)
 		return ERR_PTR(-ENOMEM);
 
-	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);
+	if (drm_is_afbc(mode_cmd->modifier[0])) {
+		const struct drm_format_info *info = drm_get_format_info(dev, mode_cmd);
+
+		afbc_fb->bpp = info->cpp[0] * 8;
+		check.data = afbc_fb;
+	}
+
+	ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, obj);
 	if (ret) {
-		kfree(fb);
+		kfree(afbc_fb);
 		return ERR_PTR(ret);
 	}
 
-	return fb;
+	if (drm_is_afbc(mode_cmd->modifier[0]))
+		if (rockchip_afbc_post_check(afbc_fb)) {
+			kfree(afbc_fb);
+			return ERR_PTR(-EINVAL);
+		}
+
+	ret = drm_gem_fb_init_with_funcs(&afbc_fb->base, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);
+	if (ret) {
+		kfree(afbc_fb);
+		return ERR_PTR(ret);
+	}
+
+	return &afbc_fb->base;
 }
 
 static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers = {
 	.atomic_commit_tail = drm_atomic_helper_commit_tail_rpm,
 };
 
+
+static struct drm_framebuffer *
+rockchip_fb_create(struct drm_device *dev, struct drm_file *file,
+		   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	struct drm_afbc_framebuffer *afbc_fb;
+	struct drm_size_check check = { 0 };
+	struct drm_gem_object *objs[4];
+	int ret, i, num_planes;
+
+	afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL);
+	if (!afbc_fb)
+		return ERR_PTR(-ENOMEM);
+
+	if (drm_is_afbc(mode_cmd->modifier[0])) {
+		const struct drm_format_info *info = drm_get_format_info(dev, mode_cmd);
+
+		afbc_fb->bpp = info->cpp[0] * 8;
+		check.data = afbc_fb;
+	}
+
+	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
+	if (ret < 0)
+		goto err_free;
+	num_planes = ret;
+
+	ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs);
+	if (ret)
+		goto err_cleanup;
+
+	if (drm_is_afbc(mode_cmd->modifier[0]))
+		if (rockchip_afbc_post_check(afbc_fb)) {
+			ret = -EINVAL;
+			goto err_cleanup;
+		}
+
+	ret = drm_gem_fb_init_with_funcs(&afbc_fb->base, dev, mode_cmd, objs, num_planes, &rockchip_drm_fb_funcs);
+	if (ret)
+		goto err_cleanup;
+
+	return &afbc_fb->base;
+
+err_cleanup:
+	for (i = 0; i < num_planes; ++i)
+		drm_gem_object_put_unlocked(objs[i]);
+err_free:
+	kfree(afbc_fb);
+	return ERR_PTR(ret);
+}
+
 static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = {
-	.fb_create = drm_gem_fb_create_with_dirty,
+	.fb_create = rockchip_fb_create,
 	.output_poll_changed = drm_fb_helper_output_poll_changed,
 	.atomic_check = drm_atomic_helper_check,
 	.atomic_commit = drm_atomic_helper_commit,
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
index d04b3492bdac..ffe1e4b9a9ca 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
@@ -91,9 +91,21 @@
 #define VOP_WIN_TO_INDEX(vop_win) \
 	((vop_win) - (vop_win)->vop->win)
 
+#define VOP_AFBC_SET(vop, name, v) \
+	do { \
+		if ((vop)->data->afbc) \
+			vop_reg_set((vop), &(vop)->data->afbc->name, 0, ~0, v, #name); \
+	} while (0)
+
 #define to_vop(x) container_of(x, struct vop, crtc)
 #define to_vop_win(x) container_of(x, struct vop_win, base)
 
+#define AFBC_FMT_RGB565		0x0
+#define AFBC_FMT_U8U8U8U8	0x5
+#define AFBC_FMT_U8U8U8		0x4
+
+#define AFBC_TILE_16x16		BIT(4)
+
 /*
  * The coefficients of the following matrix are all fixed points.
  * The format is S2.10 for the 3x3 part of the matrix, and S9.12 for the offsets.
@@ -166,6 +178,7 @@ struct vop {
 	/* optional internal rgb encoder */
 	struct rockchip_rgb *rgb;
 
+	struct vop_win *afbc_win;
 	struct vop_win win[];
 };
 
@@ -274,6 +287,29 @@ static enum vop_data_format vop_convert_format(uint32_t format)
 	}
 }
 
+static int vop_convert_afbc_format(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_ARGB8888:
+	case DRM_FORMAT_XBGR8888:
+	case DRM_FORMAT_ABGR8888:
+		return AFBC_FMT_U8U8U8U8;
+	case DRM_FORMAT_RGB888:
+	case DRM_FORMAT_BGR888:
+		return AFBC_FMT_U8U8U8;
+	case DRM_FORMAT_RGB565:
+	case DRM_FORMAT_BGR565:
+		return AFBC_FMT_RGB565;
+	/* either of the below should not be reachable */
+	default:
+		DRM_WARN_ONCE("unsupported AFBC format[%08x]\n", format);
+		return -EINVAL;
+	}
+
+	return -EINVAL;
+}
+
 static uint16_t scl_vop_cal_scale(enum scale_mode mode, uint32_t src,
 				  uint32_t dst, bool is_horizontal,
 				  int vsu_mode, int *vskiplines)
@@ -598,6 +634,15 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
 			vop_win_disable(vop, vop_win);
 		}
 	}
+
+	if (vop->data->afbc) {
+		/*
+		 * Disable AFBC and forget there was a vop window with AFBC
+		 */
+		VOP_AFBC_SET(vop, enable, 0);
+		vop->afbc_win = NULL;
+	}
+
 	spin_unlock(&vop->reg_lock);
 
 	vop_cfg_done(vop);
@@ -710,6 +755,37 @@ static void vop_plane_destroy(struct drm_plane *plane)
 	drm_plane_cleanup(plane);
 }
 
+static bool rockchip_afbc(u64 modifier)
+{
+	return modifier == DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE);
+}
+
+static bool rockchip_mod_supported(struct drm_plane *plane,
+				   u32 format, u64 modifier)
+{
+	const struct drm_format_info *info;
+
+	if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
+		return false;
+
+	if (modifier == DRM_FORMAT_MOD_LINEAR)
+		return true;
+
+	if (!rockchip_afbc(modifier)) {
+		DRM_DEBUG_KMS("Unsupported format modifer 0x%llx\n", modifier);
+
+		return false;
+	}
+
+	info = drm_format_info(format);
+	if (info->num_planes != 1) {
+		DRM_DEBUG_KMS("AFBC buffers expect one plane\n");
+		return false;
+	}
+
+	return true;
+}
+
 static int vop_plane_atomic_check(struct drm_plane *plane,
 			   struct drm_plane_state *state)
 {
@@ -719,10 +795,8 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
 	struct vop_win *vop_win = to_vop_win(plane);
 	const struct vop_win_data *win = vop_win->data;
 	int ret;
-	int min_scale = win->phy->scl ? FRAC_16_16(1, 8) :
-					DRM_PLANE_HELPER_NO_SCALING;
-	int max_scale = win->phy->scl ? FRAC_16_16(8, 1) :
-					DRM_PLANE_HELPER_NO_SCALING;
+	int min_scale = win->phy->scl ? FRAC_16_16(1, 8) : DRM_PLANE_HELPER_NO_SCALING;
+	int max_scale = win->phy->scl ? FRAC_16_16(8, 1) : DRM_PLANE_HELPER_NO_SCALING;
 
 	if (!crtc || !fb)
 		return 0;
@@ -731,9 +805,7 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
 	if (WARN_ON(!crtc_state))
 		return -EINVAL;
 
-	ret = drm_atomic_helper_check_plane_state(state, crtc_state,
-						  min_scale, max_scale,
-						  true, true);
+	ret = drm_atomic_helper_check_plane_state(state, crtc_state, min_scale, max_scale, true, true);
 	if (ret)
 		return ret;
 
@@ -758,6 +830,31 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
 		return -EINVAL;
 	}
 
+	if (rockchip_afbc(fb->modifier)) {
+		struct vop *vop = to_vop(crtc);
+
+		if (!vop->data->afbc) {
+			DRM_ERROR("vop does not support AFBC\n");
+			return -EINVAL;
+		}
+
+		ret = vop_convert_afbc_format(fb->format->format);
+		if (ret < 0)
+			return ret;
+
+		if (state->src.x1 || state->src.y1) {
+			DRM_ERROR("afbc does not support offset display\n");
+			DRM_ERROR("xpos=%d, ypos=%d, offset=%d\n", state->src.x1, state->src.y1, fb->offsets[0]);
+			return -EINVAL;
+		}
+
+		if (state->rotation && state->rotation != DRM_MODE_ROTATE_0) {
+			DRM_ERROR("afbc does not support rotation\n");
+			DRM_ERROR("rotation=%d\n", state->rotation);
+			return -EINVAL;
+		}
+	}
+
 	return 0;
 }
 
@@ -773,6 +870,11 @@ static void vop_plane_atomic_disable(struct drm_plane *plane,
 	spin_lock(&vop->reg_lock);
 
 	vop_win_disable(vop, vop_win);
+	/*
+	 * Forget about the AFBC window if it is being disabled
+	 */
+	if (vop_win == vop->afbc_win)
+		vop->afbc_win = NULL;
 
 	spin_unlock(&vop->reg_lock);
 }
@@ -812,6 +914,13 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
 	if (WARN_ON(!vop->is_enabled))
 		return;
 
+	/*
+	 * If updating the AFBC window then assume that
+	 * after the update there will be no AFBC window.
+	 */
+	if (vop_win == vop->afbc_win)
+		vop->afbc_win = NULL;
+
 	if (!state->visible) {
 		vop_plane_atomic_disable(plane, old_state);
 		return;
@@ -846,6 +955,21 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
 
 	spin_lock(&vop->reg_lock);
 
+	if (rockchip_afbc(fb->modifier)) {
+		int afbc_format = vop_convert_afbc_format(fb->format->format);
+
+		VOP_AFBC_SET(vop, format, afbc_format | AFBC_TILE_16x16);
+		VOP_AFBC_SET(vop, hreg_block_split, 0);
+		VOP_AFBC_SET(vop, win_sel, VOP_WIN_TO_INDEX(vop_win));
+		VOP_AFBC_SET(vop, hdr_ptr, dma_addr);
+		VOP_AFBC_SET(vop, pic_size, act_info);
+
+		/*
+		 * The window being udated becomes the AFBC window
+		 */
+		vop->afbc_win = vop_win;
+	}
+
 	VOP_WIN_SET(vop, win, format, format);
 	VOP_WIN_SET(vop, win, yrgb_vir, DIV_ROUND_UP(fb->pitches[0], 4));
 	VOP_WIN_SET(vop, win, yrgb_mst, dma_addr);
@@ -1001,6 +1125,7 @@ static const struct drm_plane_funcs vop_plane_funcs = {
 	.reset = drm_atomic_helper_plane_reset,
 	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
 	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
+	.format_mod_supported = rockchip_mod_supported,
 };
 
 static int vop_crtc_enable_vblank(struct drm_crtc *crtc)
@@ -1340,6 +1465,8 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc,
 
 	spin_lock(&vop->reg_lock);
 
+	/* Enable AFBC if there is some AFBC window, disable otherwise. */
+	VOP_AFBC_SET(vop, enable, vop->afbc_win != NULL);
 	vop_cfg_done(vop);
 
 	spin_unlock(&vop->reg_lock);
@@ -1634,7 +1761,8 @@ static int vop_create_crtc(struct vop *vop)
 					       0, &vop_plane_funcs,
 					       win_data->phy->data_formats,
 					       win_data->phy->nformats,
-					       NULL, win_data->type, NULL);
+					       win_data->phy->format_modifiers,
+					       win_data->type, NULL);
 		if (ret) {
 			DRM_DEV_ERROR(vop->dev, "failed to init plane %d\n",
 				      ret);
@@ -1678,7 +1806,8 @@ static int vop_create_crtc(struct vop *vop)
 					       &vop_plane_funcs,
 					       win_data->phy->data_formats,
 					       win_data->phy->nformats,
-					       NULL, win_data->type, NULL);
+					       win_data->phy->format_modifiers,
+					       win_data->type, NULL);
 		if (ret) {
 			DRM_DEV_ERROR(vop->dev, "failed to init overlay %d\n",
 				      ret);
diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h
index 0b3d18c457b2..3f4e88a783d2 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h
@@ -34,6 +34,16 @@ struct vop_reg {
 	bool relaxed;
 };
 
+struct vop_afbc {
+	struct vop_reg enable;
+	struct vop_reg win_sel;
+	struct vop_reg format;
+	struct vop_reg hreg_block_split;
+	struct vop_reg pic_size;
+	struct vop_reg hdr_ptr;
+	struct vop_reg rstn;
+};
+
 struct vop_modeset {
 	struct vop_reg htotal_pw;
 	struct vop_reg hact_st_end;
@@ -134,6 +144,7 @@ struct vop_win_phy {
 	const struct vop_scl_regs *scl;
 	const uint32_t *data_formats;
 	uint32_t nformats;
+	const uint64_t *format_modifiers;
 
 	struct vop_reg enable;
 	struct vop_reg gate;
@@ -173,6 +184,7 @@ struct vop_data {
 	const struct vop_misc *misc;
 	const struct vop_modeset *modeset;
 	const struct vop_output *output;
+	const struct vop_afbc *afbc;
 	const struct vop_win_yuv2yuv_data *win_yuv2yuv;
 	const struct vop_win_data *win;
 	unsigned int win_size;
diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
index 7a9d979c8d5d..1f0b73c2e21e 100644
--- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
+++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c
@@ -50,6 +50,17 @@ static const uint32_t formats_win_full[] = {
 	DRM_FORMAT_NV24,
 };
 
+static const uint64_t format_modifiers_win_full[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID,
+};
+
+static const uint64_t format_modifiers_win_full_afbc[] = {
+	DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE),
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID,
+};
+
 static const uint32_t formats_win_lite[] = {
 	DRM_FORMAT_XRGB8888,
 	DRM_FORMAT_ARGB8888,
@@ -61,6 +72,11 @@ static const uint32_t formats_win_lite[] = {
 	DRM_FORMAT_BGR565,
 };
 
+static const uint64_t format_modifiers_win_lite[] = {
+	DRM_FORMAT_MOD_LINEAR,
+	DRM_FORMAT_MOD_INVALID,
+};
+
 static const struct vop_scl_regs rk3036_win_scl = {
 	.scale_yrgb_x = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 0x0),
 	.scale_yrgb_y = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 16),
@@ -72,6 +88,7 @@ static const struct vop_win_phy rk3036_win0_data = {
 	.scl = &rk3036_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 0),
 	.format = VOP_REG(RK3036_SYS_CTRL, 0x7, 3),
 	.rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 15),
@@ -87,6 +104,7 @@ static const struct vop_win_phy rk3036_win0_data = {
 static const struct vop_win_phy rk3036_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1),
 	.format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6),
 	.rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19),
@@ -153,6 +171,7 @@ static const struct vop_data rk3036_vop = {
 static const struct vop_win_phy rk3126_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1),
 	.format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6),
 	.rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19),
@@ -234,6 +253,7 @@ static const struct vop_win_phy px30_win0_data = {
 	.scl = &px30_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(PX30_WIN0_CTRL0, 0x1, 0),
 	.format = VOP_REG(PX30_WIN0_CTRL0, 0x7, 1),
 	.rb_swap = VOP_REG(PX30_WIN0_CTRL0, 0x1, 12),
@@ -249,6 +269,7 @@ static const struct vop_win_phy px30_win0_data = {
 static const struct vop_win_phy px30_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(PX30_WIN1_CTRL0, 0x1, 0),
 	.format = VOP_REG(PX30_WIN1_CTRL0, 0x7, 4),
 	.rb_swap = VOP_REG(PX30_WIN1_CTRL0, 0x1, 12),
@@ -261,6 +282,7 @@ static const struct vop_win_phy px30_win1_data = {
 static const struct vop_win_phy px30_win2_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.gate = VOP_REG(PX30_WIN2_CTRL0, 0x1, 4),
 	.enable = VOP_REG(PX30_WIN2_CTRL0, 0x1, 0),
 	.format = VOP_REG(PX30_WIN2_CTRL0, 0x3, 5),
@@ -316,6 +338,7 @@ static const struct vop_win_phy rk3066_win0_data = {
 	.scl = &rk3066_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 0),
 	.format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 4),
 	.rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 19),
@@ -332,6 +355,7 @@ static const struct vop_win_phy rk3066_win1_data = {
 	.scl = &rk3066_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 1),
 	.format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 7),
 	.rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 23),
@@ -347,6 +371,7 @@ static const struct vop_win_phy rk3066_win1_data = {
 static const struct vop_win_phy rk3066_win2_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 2),
 	.format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 10),
 	.rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 27),
@@ -426,6 +451,7 @@ static const struct vop_win_phy rk3188_win0_data = {
 	.scl = &rk3188_win_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 0),
 	.format = VOP_REG(RK3188_SYS_CTRL, 0x7, 3),
 	.rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 15),
@@ -440,6 +466,7 @@ static const struct vop_win_phy rk3188_win0_data = {
 static const struct vop_win_phy rk3188_win1_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 1),
 	.format = VOP_REG(RK3188_SYS_CTRL, 0x7, 6),
 	.rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 19),
@@ -545,6 +572,7 @@ static const struct vop_win_phy rk3288_win01_data = {
 	.scl = &rk3288_win_full_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0),
 	.format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1),
 	.rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12),
@@ -563,6 +591,7 @@ static const struct vop_win_phy rk3288_win01_data = {
 static const struct vop_win_phy rk3288_win23_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.enable = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 4),
 	.gate = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 0),
 	.format = VOP_REG(RK3288_WIN2_CTRL0, 0x7, 1),
@@ -677,6 +706,7 @@ static const struct vop_win_phy rk3368_win01_data = {
 	.scl = &rk3288_win_full_scl,
 	.data_formats = formats_win_full,
 	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full,
 	.enable = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 0),
 	.format = VOP_REG(RK3368_WIN0_CTRL0, 0x7, 1),
 	.rb_swap = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 12),
@@ -697,6 +727,7 @@ static const struct vop_win_phy rk3368_win01_data = {
 static const struct vop_win_phy rk3368_win23_data = {
 	.data_formats = formats_win_lite,
 	.nformats = ARRAY_SIZE(formats_win_lite),
+	.format_modifiers = format_modifiers_win_lite,
 	.gate = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 0),
 	.enable = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 4),
 	.format = VOP_REG(RK3368_WIN2_CTRL0, 0x3, 5),
@@ -817,6 +848,53 @@ static const struct vop_win_yuv2yuv_data rk3399_vop_big_win_yuv2yuv_data[] = {
 	  .y2r_en = VOP_REG(RK3399_YUV2YUV_WIN, 0x1, 9) },
 	{ .base = 0xC0, .phy = &rk3399_yuv2yuv_win23_data },
 	{ .base = 0x120, .phy = &rk3399_yuv2yuv_win23_data },
+
+};
+
+static const struct vop_win_phy rk3399_win01_data = {
+	.scl = &rk3288_win_full_scl,
+	.data_formats = formats_win_full,
+	.nformats = ARRAY_SIZE(formats_win_full),
+	.format_modifiers = format_modifiers_win_full_afbc,
+	.enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0),
+	.format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1),
+	.rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12),
+	.y_mir_en = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 22),
+	.act_info = VOP_REG(RK3288_WIN0_ACT_INFO, 0x1fff1fff, 0),
+	.dsp_info = VOP_REG(RK3288_WIN0_DSP_INFO, 0x0fff0fff, 0),
+	.dsp_st = VOP_REG(RK3288_WIN0_DSP_ST, 0x1fff1fff, 0),
+	.yrgb_mst = VOP_REG(RK3288_WIN0_YRGB_MST, 0xffffffff, 0),
+	.uv_mst = VOP_REG(RK3288_WIN0_CBR_MST, 0xffffffff, 0),
+	.yrgb_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 0),
+	.uv_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 16),
+	.src_alpha_ctl = VOP_REG(RK3288_WIN0_SRC_ALPHA_CTRL, 0xff, 0),
+	.dst_alpha_ctl = VOP_REG(RK3288_WIN0_DST_ALPHA_CTRL, 0xff, 0),
+};
+
+/*
+ * rk3399 vop big windows register layout is same as rk3288, but we
+ * have a separate rk3399 win data array here so that we can advertise
+ * AFBC on the primary plane.
+ */
+static const struct vop_win_data rk3399_vop_win_data[] = {
+	{ .base = 0x00, .phy = &rk3399_win01_data,
+	  .type = DRM_PLANE_TYPE_PRIMARY },
+	{ .base = 0x40, .phy = &rk3288_win01_data,
+	  .type = DRM_PLANE_TYPE_OVERLAY },
+	{ .base = 0x00, .phy = &rk3288_win23_data,
+	  .type = DRM_PLANE_TYPE_OVERLAY },
+	{ .base = 0x50, .phy = &rk3288_win23_data,
+	  .type = DRM_PLANE_TYPE_CURSOR },
+};
+
+static const struct vop_afbc rk3399_vop_afbc = {
+	.rstn = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 3),
+	.enable = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 0),
+	.win_sel = VOP_REG(RK3399_AFBCD0_CTRL, 0x3, 1),
+	.format = VOP_REG(RK3399_AFBCD0_CTRL, 0x1f, 16),
+	.hreg_block_split = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 21),
+	.hdr_ptr = VOP_REG(RK3399_AFBCD0_HDR_PTR, 0xffffffff, 0),
+	.pic_size = VOP_REG(RK3399_AFBCD0_PIC_SIZE, 0xffffffff, 0),
 };
 
 static const struct vop_data rk3399_vop_big = {
@@ -826,9 +904,10 @@ static const struct vop_data rk3399_vop_big = {
 	.common = &rk3288_common,
 	.modeset = &rk3288_modeset,
 	.output = &rk3399_output,
+	.afbc = &rk3399_vop_afbc,
 	.misc = &rk3368_misc,
-	.win = rk3368_vop_win_data,
-	.win_size = ARRAY_SIZE(rk3368_vop_win_data),
+	.win = rk3399_vop_win_data,
+	.win_size = ARRAY_SIZE(rk3399_vop_win_data),
 	.win_yuv2yuv = rk3399_vop_big_win_yuv2yuv_data,
 };
 
-- 
2.17.1

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

^ permalink raw reply related	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (33 preceding siblings ...)
  2019-12-17 14:50       ` [PATCHv5 34/34] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
@ 2020-01-30  9:08       ` Andrzej Pietrasiewicz
  2020-01-30 11:44         ` Liviu Dudau
  2020-02-07 11:44         ` Andrzej Pietrasiewicz
  2020-02-20 16:54       ` Daniel Vetter
  35 siblings, 2 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2020-01-30  9:08 UTC (permalink / raw)
  To: dri-devel
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	James Wang, Ayan Halder, Sean Paul

Hi All,

A gentle reminder.

Please also see inline:

W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
> This series adds AFBC support for Rockchip. It is inspired by:
> 
> https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> 
> This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
> rework has been done, the main goal of which was to move all afbc-related
> checks to helpers, so that core does not deal with it.
> 
> A new struct drm_afbc_framebuffer is added, which stores afbc-related
> driver-specific data. Because of that, in drivers that wish to
> use this feature, the struct must be allocated directly in the driver
> code rather than inside helpers, so the first portion of the patchset
> does the necessary refactoring.
> 
> Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
> the latter being the ultimate purpose of this work and the 3 subsequent
> portions of the patchset move komeda and malidp to generic helpers and add
> afbc support to rockchip.

If changes in komeda and malidp is too much to digest at a time I can
focus on rockchip only. This would amount to patches 1-4 and 33-34.
After all the ultimate purpose of this work and time spent on it
is landing afbc support for rockchip.

Regards,

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2020-01-30  9:08       ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
@ 2020-01-30 11:44         ` Liviu Dudau
  2020-01-30 11:57           ` Andrzej Pietrasiewicz
  2020-02-07 11:44         ` Andrzej Pietrasiewicz
  1 sibling, 1 reply; 106+ messages in thread
From: Liviu Dudau @ 2020-01-30 11:44 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Sandy Huang, dri-devel,
	James Wang, Ayan Halder, Sean Paul

Hi Andrzej,

Sorry for the delay in reviewing the patches. I am hoping to get through the review
early next week if that is OK with you.

Best regards,
Liviu

On Thu, Jan 30, 2020 at 10:08:15AM +0100, Andrzej Pietrasiewicz wrote:
> Hi All,
> 
> A gentle reminder.
> 
> Please also see inline:
> 
> W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
> > This series adds AFBC support for Rockchip. It is inspired by:
> > 
> > https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> > 
> > This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
> > rework has been done, the main goal of which was to move all afbc-related
> > checks to helpers, so that core does not deal with it.
> > 
> > A new struct drm_afbc_framebuffer is added, which stores afbc-related
> > driver-specific data. Because of that, in drivers that wish to
> > use this feature, the struct must be allocated directly in the driver
> > code rather than inside helpers, so the first portion of the patchset
> > does the necessary refactoring.
> > 
> > Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
> > the latter being the ultimate purpose of this work and the 3 subsequent
> > portions of the patchset move komeda and malidp to generic helpers and add
> > afbc support to rockchip.
> 
> If changes in komeda and malidp is too much to digest at a time I can
> focus on rockchip only. This would amount to patches 1-4 and 33-34.
> After all the ultimate purpose of this work and time spent on it
> is landing afbc support for rockchip.
> 
> Regards,
> 
> Andrzej

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2020-01-30 11:44         ` Liviu Dudau
@ 2020-01-30 11:57           ` Andrzej Pietrasiewicz
  0 siblings, 0 replies; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2020-01-30 11:57 UTC (permalink / raw)
  To: Liviu Dudau
  Cc: kernel, Mihail Atanassov, David Airlie, Sandy Huang, dri-devel,
	James Wang, Ayan Halder, Sean Paul

Hi Liviu,

W dniu 30.01.2020 o 12:44, Liviu Dudau pisze:
> Hi Andrzej,
> 
> Sorry for the delay in reviewing the patches. I am hoping to get through the review
> early next week if that is OK with you.

Thanks, that would be great.

Andrzej

> 
> Best regards,
> Liviu
> 
> On Thu, Jan 30, 2020 at 10:08:15AM +0100, Andrzej Pietrasiewicz wrote:
>> Hi All,
>>
>> A gentle reminder.
>>
>> Please also see inline:
>>
>> W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
>>> This series adds AFBC support for Rockchip. It is inspired by:
>>>
>>> https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
>>>
>>> This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
>>> rework has been done, the main goal of which was to move all afbc-related
>>> checks to helpers, so that core does not deal with it.
>>>
>>> A new struct drm_afbc_framebuffer is added, which stores afbc-related
>>> driver-specific data. Because of that, in drivers that wish to
>>> use this feature, the struct must be allocated directly in the driver
>>> code rather than inside helpers, so the first portion of the patchset
>>> does the necessary refactoring.
>>>
>>> Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
>>> the latter being the ultimate purpose of this work and the 3 subsequent
>>> portions of the patchset move komeda and malidp to generic helpers and add
>>> afbc support to rockchip.
>>
>> If changes in komeda and malidp is too much to digest at a time I can
>> focus on rockchip only. This would amount to patches 1-4 and 33-34.
>> After all the ultimate purpose of this work and time spent on it
>> is landing afbc support for rockchip.
>>
>> Regards,
>>
>> Andrzej
> 

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2020-01-30  9:08       ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
  2020-01-30 11:44         ` Liviu Dudau
@ 2020-02-07 11:44         ` Andrzej Pietrasiewicz
  2020-02-07 17:10           ` Liviu Dudau
  1 sibling, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2020-02-07 11:44 UTC (permalink / raw)
  To: dri-devel
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	James Wang, Ayan Halder, Sean Paul

Hi All again,

@malidp and komeda folks: I kindly ask you to have your say. If there is
no interest from you (which is ok with me) I will resend the series
dropping the komeda and malidp part.

Andrzej

W dniu 30.01.2020 o 10:08, Andrzej Pietrasiewicz pisze:
> Hi All,
> 
> A gentle reminder.
> 
> Please also see inline:
> 
> W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
>> This series adds AFBC support for Rockchip. It is inspired by:
>>
>> https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c 
>>
>>
>> This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
>> rework has been done, the main goal of which was to move all afbc-related
>> checks to helpers, so that core does not deal with it.
>>
>> A new struct drm_afbc_framebuffer is added, which stores afbc-related
>> driver-specific data. Because of that, in drivers that wish to
>> use this feature, the struct must be allocated directly in the driver
>> code rather than inside helpers, so the first portion of the patchset
>> does the necessary refactoring.
>>
>> Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
>> the latter being the ultimate purpose of this work and the 3 subsequent
>> portions of the patchset move komeda and malidp to generic helpers and add
>> afbc support to rockchip.
> 
> If changes in komeda and malidp is too much to digest at a time I can
> focus on rockchip only. This would amount to patches 1-4 and 33-34.
> After all the ultimate purpose of this work and time spent on it
> is landing afbc support for rockchip.
> 
> Regards,
> 
> Andrzej

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2020-02-07 11:44         ` Andrzej Pietrasiewicz
@ 2020-02-07 17:10           ` Liviu Dudau
  0 siblings, 0 replies; 106+ messages in thread
From: Liviu Dudau @ 2020-02-07 17:10 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Sandy Huang, dri-devel,
	James Wang, Ayan Halder, Sean Paul

On Fri, Feb 07, 2020 at 12:44:28PM +0100, Andrzej Pietrasiewicz wrote:
> Hi All again,

Hi Andrzej,

> 
> @malidp and komeda folks: I kindly ask you to have your say. If there is
> no interest from you (which is ok with me) I will resend the series
> dropping the komeda and malidp part.

I *am* trying to test your patches, unfortunately my colleagues in China have been
kept out of the office for longer than I thought they will, so it is a bit difficult
to coordinate.

As a backup, if I don't manage to give you feedback by end of Tuesday, please re-send
the patches with malidp and rockchip and skip the komeda ones.

Best regards,
Liviu

> 
> Andrzej
> 
> W dniu 30.01.2020 o 10:08, Andrzej Pietrasiewicz pisze:
> > Hi All,
> > 
> > A gentle reminder.
> > 
> > Please also see inline:
> > 
> > W dniu 17.12.2019 o 15:49, Andrzej Pietrasiewicz pisze:
> > > This series adds AFBC support for Rockchip. It is inspired by:
> > > 
> > > https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> > > 
> > > 
> > > This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
> > > rework has been done, the main goal of which was to move all afbc-related
> > > checks to helpers, so that core does not deal with it.
> > > 
> > > A new struct drm_afbc_framebuffer is added, which stores afbc-related
> > > driver-specific data. Because of that, in drivers that wish to
> > > use this feature, the struct must be allocated directly in the driver
> > > code rather than inside helpers, so the first portion of the patchset
> > > does the necessary refactoring.
> > > 
> > > Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
> > > the latter being the ultimate purpose of this work and the 3 subsequent
> > > portions of the patchset move komeda and malidp to generic helpers and add
> > > afbc support to rockchip.
> > 
> > If changes in komeda and malidp is too much to digest at a time I can
> > focus on rockchip only. This would amount to patches 1-4 and 33-34.
> > After all the ultimate purpose of this work and time spent on it
> > is landing afbc support for rockchip.
> > 
> > Regards,
> > 
> > Andrzej
> 

-- 
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,01/36] drm/framebuffer: Add optional modifier info
  2019-12-13 15:58 ` [PATCHv4 01/36] drm/framebuffer: Add optional modifier info Andrzej Pietrasiewicz
@ 2020-02-17  5:50   ` james qian wang (Arm Technology China)
  0 siblings, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-17  5:50 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

Hi Andrzej:

Sorry for late due to the outbreak of coronavirus in china.

Reviewed-by: James Qian Wang <james.qian.wang@arm.com>

James.

On Fri, Dec 13, 2019 at 04:58:32PM +0100, Andrzej Pietrasiewicz wrote:
> modifier_info is a pointer to an optional modifier-related information.
> Managing the memory needed for that information is the responsibility
> of drivers.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  include/drm/drm_framebuffer.h | 16 ++++++++++++++++
>  1 file changed, 16 insertions(+)
> 
> diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
> index c0e0256e3e98..2b3341b526d7 100644
> --- a/include/drm/drm_framebuffer.h
> +++ b/include/drm/drm_framebuffer.h
> @@ -29,6 +29,7 @@
>  
>  #include <drm/drm_mode_object.h>
>  
> +struct drm_afbc;
>  struct drm_clip_rect;
>  struct drm_device;
>  struct drm_file;
> @@ -139,6 +140,21 @@ struct drm_framebuffer {
>  	 * @format: framebuffer format information
>  	 */
>  	const struct drm_format_info *format;
> +
> +	union {
> +		/**
> +		 * @modifier_info: pointer to an optional modifier-related
> +		 * information. Managing the memory holding that information
> +		 * is driver's responsibility.
> +		 */
> +		void *modifier_info;
> +
> +		/**
> +		 * @afbc_info: afbc-specific pointer
> +		 */
> +		struct drm_afbc *afbc_info;
> +	};
> +
>  	/**
>  	 * @funcs: framebuffer vfunc table
>  	 */
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,02/36] drm/core: Add afbc helper functions
  2019-12-13 15:58 ` [PATCHv4 02/36] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
@ 2020-02-17  6:09   ` james qian wang (Arm Technology China)
  0 siblings, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-17  6:09 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

On Fri, Dec 13, 2019 at 04:58:33PM +0100, Andrzej Pietrasiewicz wrote:
> Add checking if a modifier is afbc and getting afbc block size.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++
>  include/drm/drm_fourcc.h     |  4 +++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index b234bfaeda06..d14dd7c86020 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -29,6 +29,7 @@
>  
>  #include <drm/drm_device.h>
>  #include <drm/drm_fourcc.h>
> +#include <drm/drm_print.h>
>  
>  static char printable_char(int c)
>  {
> @@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
>  			    drm_format_info_block_height(info, plane));
>  }
>  EXPORT_SYMBOL(drm_format_info_min_pitch);
> +
> +/**
> + * drm_is_afbc - test if the modifier describes an afbc buffer
> + * @modifier - modifier to be tested
> + *
> + * Returns: true if the modifier describes an afbc buffer
> + */
> +bool drm_is_afbc(u64 modifier)
> +{
> +	/* is it ARM AFBC? */
> +	if ((modifier & DRM_FORMAT_MOD_ARM_AFBC(0)) == 0)
> +		return false;
> +
> +	/* Block size must be known */
> +	if ((modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) == 0)
> +		return false;

Do we really need this block size check here ?
Since modifier with ARM AFBC modifier but have no BLOCK_SIZE which
should be an error, but this check returns such error to NONE-AFBC.
And i saw you already have such error check in func
get_superblock_wh(), so I think we can del this size check in this
func.

James.
> +
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(drm_is_afbc);
> +
> +/**
> + * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier
> + * @modifier: the modifier to be looked at
> + * @w: address of a place to store the block width
> + * @h: address of a place to store the block height
> + *
> + * Returns: true if the modifier describes a supported block size
> + */
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h)
> +{
> +	switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
> +		*w = 16;
> +		*h = 16;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
> +		*w = 32;
> +		*h = 8;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
> +		/* fall through */
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
> +		/* fall through */
> +	default:
> +		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
> +			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
> +		return false;
> +	}
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(drm_afbc_get_superblock_wh);
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index 306d1efeb5e0..7eb23062bf45 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
>  				   int plane, unsigned int buffer_width);
>  const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>  
> +bool drm_is_afbc(u64 modifier);
> +
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h);
> +
>  #endif /* __DRM_FOURCC_H__ */
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-13 15:58 ` [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
  2019-12-16 17:08   ` Liviu Dudau
@ 2020-02-17  6:39   ` james qian wang (Arm Technology China)
  1 sibling, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-17  6:39 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

Hi Andrzej:

Good work.

It's a real useful patch, with it seems most vendor-specific fb_create
can be simplified by these helper funcs.

On Fri, Dec 13, 2019 at 04:58:34PM +0100, Andrzej Pietrasiewicz wrote:
> Prepare tools for drivers which need to allocate a struct drm_framebuffer
> (or a container of struct drm_framebuffer) explicitly, before calling
> helpers. In such a case we need new helpers which omit allocating the
> struct drm_framebuffer and this patch provides them. Consequently, they
> are used also inside the helpers themselves.
> 
> The interested drivers will likely need to be able to perform object
> lookups and size checks in separate invocations and this patch provides
> that as well. Helpers themselves are updated, too.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 184 ++++++++++++++-----
>  include/drm/drm_gem_framebuffer_helper.h     |  17 ++
>  2 files changed, 153 insertions(+), 48 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index b9bcd310ca2d..787edb9a916b 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
>  
> +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
> +			       struct drm_device *dev,
> +			       const struct drm_mode_fb_cmd2 *mode_cmd,
> +			       struct drm_gem_object **obj,
> +			       unsigned int num_planes,
> +			       const struct drm_framebuffer_funcs *funcs)
> +{
> +	int ret, i;
> +
> +	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> +
> +	for (i = 0; i < num_planes; i++)
> +		fb->obj[i] = obj[i];
> +
> +	ret = drm_framebuffer_init(dev, fb, funcs);
> +	if (ret)
> +		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
> +			      ret);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
> +
> +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
> +	.destroy	= drm_gem_fb_destroy,
> +	.create_handle	= drm_gem_fb_create_handle,
> +};
> +
> +int drm_gem_fb_init(struct drm_framebuffer *fb,
> +		    struct drm_device *dev,
> +		    const struct drm_mode_fb_cmd2 *mode_cmd,
> +		    struct drm_gem_object **obj, unsigned int num_planes)
> +{
> +	return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
> +					  &drm_gem_fb_funcs);
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_init);
> +
>  static struct drm_framebuffer *
>  drm_gem_fb_alloc(struct drm_device *dev,
>  		 const struct drm_mode_fb_cmd2 *mode_cmd,
> @@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev,
>  		 const struct drm_framebuffer_funcs *funcs)
>  {
>  	struct drm_framebuffer *fb;
> -	int ret, i;
> +	int ret;
>  
>  	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
>  	if (!fb)
>  		return ERR_PTR(-ENOMEM);
>  
> -	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> -
> -	for (i = 0; i < num_planes; i++)
> -		fb->obj[i] = obj[i];
> -
> -	ret = drm_framebuffer_init(dev, fb, funcs);
> +	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes,
> +					 funcs);
>  	if (ret) {
> -		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
> -			      ret);
>  		kfree(fb);
>  		return ERR_PTR(ret);
>  	}
> @@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
>  EXPORT_SYMBOL(drm_gem_fb_create_handle);
>  
>  /**
> - * drm_gem_fb_create_with_funcs() - Helper function for the
> - *                                  &drm_mode_config_funcs.fb_create
> - *                                  callback
> + * drm_gem_fb_lookup() - Helper function for use in
> + *			 &drm_mode_config_funcs.fb_create implementations
>   * @dev: DRM device
>   * @file: DRM file that holds the GEM handle(s) backing the framebuffer
>   * @mode_cmd: Metadata from the userspace framebuffer creation request
> - * @funcs: vtable to be used for the new framebuffer object
>   *
> - * This function can be used to set &drm_framebuffer_funcs for drivers that need
> - * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
> - * change &drm_framebuffer_funcs. The function does buffer size validation.
> + * This function can be used to look up the objects for all planes.
> + * In case an error is returned all the objects are put by the
> + * function before returning.
>   *
>   * Returns:
> - * Pointer to a &drm_framebuffer on success or an error pointer on failure.
> + * Number of planes on success or a negative error code on failure.
>   */
> -struct drm_framebuffer *
> -drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
> -			     const struct drm_mode_fb_cmd2 *mode_cmd,
> -			     const struct drm_framebuffer_funcs *funcs)
> +int drm_gem_fb_lookup(struct drm_device *dev,

[nit-pick] Maybe name it to drm_gem_fb_objs_lookup()

> +		      struct drm_file *file,
> +		      const struct drm_mode_fb_cmd2 *mode_cmd,
> +		      struct drm_gem_object **objs)
>  {
>  	const struct drm_format_info *info;
> -	struct drm_gem_object *objs[4];
> -	struct drm_framebuffer *fb;
>  	int ret, i;
>  
>  	info = drm_get_format_info(dev, mode_cmd);
>  	if (!info)
> -		return ERR_PTR(-EINVAL);
> +		return -EINVAL;
>  
>  	for (i = 0; i < info->num_planes; i++) {
> -		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> -		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> -		unsigned int min_size;
> -
>  		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
>  		if (!objs[i]) {
>  			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
>  			ret = -ENOENT;
>  			goto err_gem_object_put;
>  		}
> +	}
> +
> +	return i;
> +
> +err_gem_object_put:
> +	for (i--; i >= 0; i--)
> +		drm_gem_object_put_unlocked(objs[i]);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
> +
> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)
> +{
> +	const struct drm_format_info *info;
> +	int i;
> +
> +	info = drm_get_format_info(dev, mode_cmd);
> +	if (!info)
> +		return -EINVAL;
> +
> +	for (i = 0; i < info->num_planes; i++) {
> +		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> +		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> +		unsigned int min_size;
>  
>  		min_size = (height - 1) * mode_cmd->pitches[i]
>  			 + drm_format_info_min_pitch(info, i, width)
>  			 + mode_cmd->offsets[i];
>  
> -		if (objs[i]->size < min_size) {
> -			drm_gem_object_put_unlocked(objs[i]);
> -			ret = -EINVAL;
> -			goto err_gem_object_put;
> -		}
> +		if (objs[i]->size < min_size)
> +			return -EINVAL;
>  	}
>  
> -	fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
> -	if (IS_ERR(fb)) {
> -		ret = PTR_ERR(fb);
> -		goto err_gem_object_put;
> -	}
> +	return 0;
>  
> -	return fb;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
>  
> -err_gem_object_put:
> -	for (i--; i >= 0; i--)
> -		drm_gem_object_put_unlocked(objs[i]);
> +/**
> + * drm_gem_fb_create_with_funcs() - Helper function for the
> + *                                  &drm_mode_config_funcs.fb_create
> + *                                  callback
> + * @dev: DRM device
> + * @file: DRM file that holds the GEM handle(s) backing the framebuffer
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + * @funcs: vtable to be used for the new framebuffer object
> + *
> + * This function can be used to set &drm_framebuffer_funcs for drivers that need
> + * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to
> + * change &drm_framebuffer_funcs. The function does buffer size validation.
> + *
> + * Returns:
> + * Pointer to a &drm_framebuffer on success or an error pointer on failure.
> + */
> +struct drm_framebuffer *
> +drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
> +			     const struct drm_mode_fb_cmd2 *mode_cmd,
> +			     const struct drm_framebuffer_funcs *funcs)
> +{
> +	struct drm_gem_object *objs[4];
> +	struct drm_framebuffer *fb;
> +	int ret, num_planes;
> +
> +	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
> +	if (ret < 0)
> +		return ERR_PTR(ret);
> +	num_planes = ret;
> +
> +	ret = drm_gem_fb_size_check(dev, mode_cmd, objs);
> +	if (ret)
> +		fb = ERR_PTR(ret);
> +	else
> +		fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs);
>  
> -	return ERR_PTR(ret);
> +	if (IS_ERR(fb))
> +		for (num_planes--; num_planes >= 0; num_planes--)
> +			drm_gem_object_put_unlocked(objs[num_planes]);
> +
> +	return fb;
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
>  
> -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
> -	.destroy	= drm_gem_fb_destroy,
> -	.create_handle	= drm_gem_fb_create_handle,
> -};
> -
>  /**
>   * drm_gem_fb_create() - Helper function for the
>   *                       &drm_mode_config_funcs.fb_create callback
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index d9f13fd25b0a..c85d4b152e91 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -14,10 +14,27 @@ struct drm_simple_display_pipe;
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
> +			       struct drm_device *dev,
> +			       const struct drm_mode_fb_cmd2 *mode_cmd,
> +			       struct drm_gem_object **obj,
> +			       unsigned int num_planes,
> +			       const struct drm_framebuffer_funcs *funcs);
> +int drm_gem_fb_init(struct drm_framebuffer *fb,
> +		    struct drm_device *dev,
> +		    const struct drm_mode_fb_cmd2 *mode_cmd,
> +		    struct drm_gem_object **obj, unsigned int num_planes);
>  void drm_gem_fb_destroy(struct drm_framebuffer *fb);
>  int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
>  			     unsigned int *handle);
>  
> +int drm_gem_fb_lookup(struct drm_device *dev,
> +		      struct drm_file *file,
> +		      const struct drm_mode_fb_cmd2 *mode_cmd,
> +		      struct drm_gem_object **objs);
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs);
>  struct drm_framebuffer *
>  drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
>  			     const struct drm_mode_fb_cmd2 *mode_cmd,

Reviewed-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2019-12-13 15:58 ` [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
  2019-12-16 17:11   ` Liviu Dudau
@ 2020-02-17  8:16   ` james qian wang (Arm Technology China)
  2020-02-17 10:55     ` Andrzej Pietrasiewicz
  1 sibling, 1 reply; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-17  8:16 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

Hi Andrzej:

Really a good idea for introducing this custom size check, it's very
useful for some Komeda/malidp format, espcially pitch_multiplier, maybe
in future we can add it into into the drm_format_info.    

On Fri, Dec 13, 2019 at 04:58:35PM +0100, Andrzej Pietrasiewicz wrote:
> The new version accepts a struct describing deviations from standard way of
> doing the size checks. The caller must provide the respective values.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++----
>  include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
>  2 files changed, 55 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 787edb9a916b..4201dc1f32a5 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>  
>  /**
> - * drm_gem_fb_size_check() - Helper function for use in
> - *			     &drm_mode_config_funcs.fb_create implementations
> + * drm_gem_fb_size_check_special() - Helper function for use in
> + *				     &drm_mode_config_funcs.fb_create
> + *				     implementations
>   * @dev: DRM device
>   * @mode_cmd: Metadata from the userspace framebuffer creation request
>   *
> @@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>   * Returns:
>   * Zero on success or a negative error code on failure.
>   */
> -int drm_gem_fb_size_check(struct drm_device *dev,
> -			  const struct drm_mode_fb_cmd2 *mode_cmd,
> -			  struct drm_gem_object **objs)
> +int drm_gem_fb_size_check_special(struct drm_device *dev,

How about name it to drm_gem_fb_custom_size_check()

> +				  const struct drm_mode_fb_cmd2 *mode_cmd,
> +				  const struct drm_size_check *check,
> +				  struct drm_gem_object **objs)
>  {
>  	const struct drm_format_info *info;
>  	int i;
> @@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>  		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
>  		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
>  		unsigned int min_size;
> +		u32 pitch = mode_cmd->pitches[i];
> +
> +		if (check && check->use_pitch_multiplier)
> +			if ((pitch * check->pitch_multiplier[i]) %
> +			    check->pitch_modulo)
> +				return -EINVAL;
>  
> -		min_size = (height - 1) * mode_cmd->pitches[i]
> -			 + drm_format_info_min_pitch(info, i, width)
> -			 + mode_cmd->offsets[i];
> +		if (check && check->use_min_size)
> +			min_size = check->min_size[i];
> +		else
> +			min_size = (height - 1) * pitch
> +				 + drm_format_info_min_pitch(info, i, width)
> +				 + mode_cmd->offsets[i];
>  
>  		if (objs[i]->size < min_size)
>  			return -EINVAL;
> @@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>  	return 0;
>  
>  }
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
> +
> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)
> +{
> +	return drm_gem_fb_size_check_special(dev, mode_cmd, NULL, objs);
> +}
>  EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
>  
>  /**
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index c85d4b152e91..74304a268694 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
>  struct drm_plane;
>  struct drm_plane_state;
>  struct drm_simple_display_pipe;
> +struct drm_size_check;
> +
> +/**
> + * struct drm_size_check - Description of special requirements for size checks.
> + */
> +struct drm_size_check {
> +	unsigned int min_size[4];
> +	bool use_min_size;
> +	u32 pitch_multiplier[4];
> +	u32 pitch_modulo;
> +	bool use_pitch_multiplier;
> +};
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  		      struct drm_file *file,
>  		      const struct drm_mode_fb_cmd2 *mode_cmd,
>  		      struct drm_gem_object **objs);
> +int drm_gem_fb_size_check_special(struct drm_device *dev,
> +				  const struct drm_mode_fb_cmd2 *mode_cmd,
> +				  const struct drm_size_check *check,
> +				  struct drm_gem_object **objs);
>  int drm_gem_fb_size_check(struct drm_device *dev,
>  			  const struct drm_mode_fb_cmd2 *mode_cmd,
>  			  struct drm_gem_object **objs);

For this common case can we just define it as a MACRO, or a inline
func here in this header.

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2020-02-17  8:16   ` [PATCHv4,04/36] " james qian wang (Arm Technology China)
@ 2020-02-17 10:55     ` Andrzej Pietrasiewicz
  2020-02-17 11:34       ` james qian wang (Arm Technology China)
  0 siblings, 1 reply; 106+ messages in thread
From: Andrzej Pietrasiewicz @ 2020-02-17 10:55 UTC (permalink / raw)
  To: james qian wang (Arm Technology China)
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

Hi James,

Thank you for the review.

Did you intentionally review patches from the v4 series or you simply
didn't notice the v5? There are some differences, the most notable one
is using proper way of subclassing a drm_framebuffer.
The v5 series was sent on 17th December 2019.

Andrzej

W dniu 17.02.2020 o 09:16, james qian wang (Arm Technology China) pisze:
> Hi Andrzej:
> 
> Really a good idea for introducing this custom size check, it's very
> useful for some Komeda/malidp format, espcially pitch_multiplier, maybe
> in future we can add it into into the drm_format_info.
> 
> On Fri, Dec 13, 2019 at 04:58:35PM +0100, Andrzej Pietrasiewicz wrote:
>> The new version accepts a struct describing deviations from standard way of
>> doing the size checks. The caller must provide the respective values.
>>
>> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
>> ---
>>   drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++----
>>   include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
>>   2 files changed, 55 insertions(+), 8 deletions(-)
>>
>> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
>> index 787edb9a916b..4201dc1f32a5 100644
>> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
>> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
>> @@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>>   EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>>   
>>   /**
>> - * drm_gem_fb_size_check() - Helper function for use in
>> - *			     &drm_mode_config_funcs.fb_create implementations
>> + * drm_gem_fb_size_check_special() - Helper function for use in
>> + *				     &drm_mode_config_funcs.fb_create
>> + *				     implementations
>>    * @dev: DRM device
>>    * @mode_cmd: Metadata from the userspace framebuffer creation request
>>    *
>> @@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>>    * Returns:
>>    * Zero on success or a negative error code on failure.
>>    */
>> -int drm_gem_fb_size_check(struct drm_device *dev,
>> -			  const struct drm_mode_fb_cmd2 *mode_cmd,
>> -			  struct drm_gem_object **objs)
>> +int drm_gem_fb_size_check_special(struct drm_device *dev,
> 
> How about name it to drm_gem_fb_custom_size_check()
> 
>> +				  const struct drm_mode_fb_cmd2 *mode_cmd,
>> +				  const struct drm_size_check *check,
>> +				  struct drm_gem_object **objs)
>>   {
>>   	const struct drm_format_info *info;
>>   	int i;
>> @@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>>   		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
>>   		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
>>   		unsigned int min_size;
>> +		u32 pitch = mode_cmd->pitches[i];
>> +
>> +		if (check && check->use_pitch_multiplier)
>> +			if ((pitch * check->pitch_multiplier[i]) %
>> +			    check->pitch_modulo)
>> +				return -EINVAL;
>>   
>> -		min_size = (height - 1) * mode_cmd->pitches[i]
>> -			 + drm_format_info_min_pitch(info, i, width)
>> -			 + mode_cmd->offsets[i];
>> +		if (check && check->use_min_size)
>> +			min_size = check->min_size[i];
>> +		else
>> +			min_size = (height - 1) * pitch
>> +				 + drm_format_info_min_pitch(info, i, width)
>> +				 + mode_cmd->offsets[i];
>>   
>>   		if (objs[i]->size < min_size)
>>   			return -EINVAL;
>> @@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>>   	return 0;
>>   
>>   }
>> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
>> +
>> +/**
>> + * drm_gem_fb_size_check() - Helper function for use in
>> + *			     &drm_mode_config_funcs.fb_create implementations
>> + * @dev: DRM device
>> + * @mode_cmd: Metadata from the userspace framebuffer creation request
>> + *
>> + * This function can be used to verify buffer sizes for all planes.
>> + * It is caller's responsibility to put the objects on failure.
>> + *
>> + * Returns:
>> + * Zero on success or a negative error code on failure.
>> + */
>> +int drm_gem_fb_size_check(struct drm_device *dev,
>> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
>> +			  struct drm_gem_object **objs)
>> +{
>> +	return drm_gem_fb_size_check_special(dev, mode_cmd, NULL, objs);
>> +}
>>   EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
>>   
>>   /**
>> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
>> index c85d4b152e91..74304a268694 100644
>> --- a/include/drm/drm_gem_framebuffer_helper.h
>> +++ b/include/drm/drm_gem_framebuffer_helper.h
>> @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
>>   struct drm_plane;
>>   struct drm_plane_state;
>>   struct drm_simple_display_pipe;
>> +struct drm_size_check;
>> +
>> +/**
>> + * struct drm_size_check - Description of special requirements for size checks.
>> + */
>> +struct drm_size_check {
>> +	unsigned int min_size[4];
>> +	bool use_min_size;
>> +	u32 pitch_multiplier[4];
>> +	u32 pitch_modulo;
>> +	bool use_pitch_multiplier;
>> +};
>>   
>>   struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>>   					  unsigned int plane);
>> @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>>   		      struct drm_file *file,
>>   		      const struct drm_mode_fb_cmd2 *mode_cmd,
>>   		      struct drm_gem_object **objs);
>> +int drm_gem_fb_size_check_special(struct drm_device *dev,
>> +				  const struct drm_mode_fb_cmd2 *mode_cmd,
>> +				  const struct drm_size_check *check,
>> +				  struct drm_gem_object **objs);
>>   int drm_gem_fb_size_check(struct drm_device *dev,
>>   			  const struct drm_mode_fb_cmd2 *mode_cmd,
>>   			  struct drm_gem_object **objs);
> 
> For this common case can we just define it as a MACRO, or a inline
> func here in this header.
> 
> Thanks
> James
> 

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,05/36] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-13 15:58 ` [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
  2019-12-16 17:19   ` Liviu Dudau
@ 2020-02-17 11:02   ` james qian wang (Arm Technology China)
  1 sibling, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-17 11:02 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

Hi Andrzej:

On Fri, Dec 13, 2019 at 04:58:36PM +0100, Andrzej Pietrasiewicz wrote:
> Extend the size-checking special function to handle afbc.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c                 | 10 +++-
>  drivers/gpu/drm/drm_framebuffer.c            |  3 +
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++--
>  include/drm/drm_gem_framebuffer_helper.h     | 16 ++++++
>  4 files changed, 82 insertions(+), 7 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index d14dd7c86020..9ac2175c5bee 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev,
>  {
>  	const struct drm_format_info *info = NULL;
>  
> -	if (dev->mode_config.funcs->get_format_info)
> -		info = dev->mode_config.funcs->get_format_info(mode_cmd);
> +	/* bypass driver callback if afbc */
> +	if (!drm_is_afbc(mode_cmd->modifier[0]))
> +		if (dev->mode_config.funcs->get_format_info) {
> +			const struct drm_mode_config_funcs *funcs;
> +
> +			funcs = dev->mode_config.funcs;
> +			info = funcs->get_format_info(mode_cmd);
> +		}
>  
>  	if (!info)
>  		info = drm_format_info(mode_cmd->pixel_format);
> diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c
> index 57564318ceea..33b741cc73e8 100644
> --- a/drivers/gpu/drm/drm_framebuffer.c
> +++ b/drivers/gpu/drm/drm_framebuffer.c
> @@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev,
>  		unsigned int block_size = info->char_per_block[i];
>  		u64 min_pitch = drm_format_info_min_pitch(info, i, width);
>  
> +		if (drm_is_afbc(r->modifier[i]))
> +			block_size = 0;
> +
>  		if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) {
>  			DRM_DEBUG_KMS("Format requires non-linear modifier for plane %d\n", i);
>  			return -EINVAL;
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index 4201dc1f32a5..e20f4d00b0a5 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -21,6 +21,11 @@
>  #include <drm/drm_modeset_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
>  
> +#define AFBC_HEADER_SIZE		16
> +#define AFBC_TH_LAYOUT_ALIGNMENT	8
> +#define AFBC_SUPERBLOCK_PIXELS		256
> +#define AFBC_SUPERBLOCK_ALIGNMENT	128
> +
>  /**
>   * DOC: overview
>   *
> @@ -200,6 +205,40 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>  
> +static int drm_gem_afbc_min_size(struct drm_device *dev,
> +				 const struct drm_mode_fb_cmd2 *mode_cmd,
> +				 struct drm_afbc *afbc)
> +{
> +	u32 n_blocks;
> +
> +	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0],
> +					&afbc->block_width,
> +					&afbc->block_height)) {
> +		return -EINVAL;
> +	}
> +
> +	/* tiled header afbc */
> +	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
> +		afbc->block_width *= AFBC_TH_LAYOUT_ALIGNMENT;
> +		afbc->block_height *= AFBC_TH_LAYOUT_ALIGNMENT;
> +	}
> +
> +	afbc->aligned_width = ALIGN(mode_cmd->width, afbc->block_width);
> +	afbc->aligned_height = ALIGN(mode_cmd->height, afbc->block_height);
> +	afbc->offset = mode_cmd->offsets[0];
> +
> +	n_blocks = (afbc->aligned_width * afbc->aligned_height)
> +		 / AFBC_SUPERBLOCK_PIXELS;
> +	afbc->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,
> +				     afbc->alignment_header);

After check the references in malidp, rockchip and komeda, seems this
afbc->alignment_header is dedicated for komeda only.

This is not true. Per afbc HW spec alignment is essential for
all afbc usage. according to the spec the requiremnt are:

  AFBC1.0/1.1: 64 byte alignment both for header and body buffer.
  AFBC1.2 (tiled header enabled): 4096 alignment.

So this alignement is not a vendor specific value, but afbc feature
requirement, can be determined by afbc modifier.
(malidp and komeda obeys this spec, not sure about Rockchip, but I
think it should be)

But you may see, komeda uses 1024 (not 64) for none-tiled-header afbc,
that's because GPU(MALI) changed this value to 1024 for bus
performance (sorry I don't know the detail), and komeda changed to
1024 to follow.

Back to display alignment, I think we can just follow the spec, use 64
for none-tiled-header, 4096 for tiled-header, but no need to caller to
pass a value.

> +
> +	afbc->afbc_size = afbc->offset_payload + n_blocks *
> +			  ALIGN(afbc->bpp * AFBC_SUPERBLOCK_PIXELS / 8,
> +				AFBC_SUPERBLOCK_ALIGNMENT);
> +
> +	return 0;
> +}
> +
>  /**
>   * drm_gem_fb_size_check_special() - Helper function for use in
>   *				     &drm_mode_config_funcs.fb_create
> @@ -218,6 +257,7 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,
>  				  const struct drm_size_check *check,
>  				  struct drm_gem_object **objs)
>  {
> +#define CHECK_HAS(field) (check && check->field)
>  	const struct drm_format_info *info;
>  	int i;
>  
> @@ -231,24 +271,34 @@ int drm_gem_fb_size_check_special(struct drm_device *dev,
>  		unsigned int min_size;
>  		u32 pitch = mode_cmd->pitches[i];
>  
> -		if (check && check->use_pitch_multiplier)
> +		if (CHECK_HAS(use_pitch_multiplier))
>  			if ((pitch * check->pitch_multiplier[i]) %
>  			    check->pitch_modulo)
>  				return -EINVAL;
>  
> -		if (check && check->use_min_size)
> +		if (CHECK_HAS(use_min_size)) {
>  			min_size = check->min_size[i];
> -		else
> +		} else if (CHECK_HAS(data) &&
> +				drm_is_afbc(mode_cmd->modifier[0])) {
> +			struct drm_afbc *afbc;
> +			int ret;
> +
> +			afbc = check->data;
> +			ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc);
> +			if (ret < 0)
> +				return ret;
> +			min_size = ret;
> +		} else {
>  			min_size = (height - 1) * pitch
>  				 + drm_format_info_min_pitch(info, i, width)
>  				 + mode_cmd->offsets[i];
> -
> +		}
>  		if (objs[i]->size < min_size)
>  			return -EINVAL;
>  	}
>  
>  	return 0;
> -
> +#undef CHECK_HAS
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
>  
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index 74304a268694..3d6015194b3c 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -22,6 +22,22 @@ struct drm_size_check {
>  	u32 pitch_multiplier[4];
>  	u32 pitch_modulo;
>  	bool use_pitch_multiplier;
> +	void *data;
> +};
> +
> +/**
> + * struct drm_afbc - AFBC-specific data.
> + */
> +struct drm_afbc {
> +	u32 block_width;
> +	u32 block_height;
> +	u32 aligned_width;
> +	u32 aligned_height;
> +	u32 offset;
> +	u32 alignment_header;
> +	u32 afbc_size;
> +	u32 offset_payload;
> +	u32 bpp;

Seems we can remove this bpp if we set the block_size (4x4) for these afbc
only formats like DRM_FORMAT_YUV420_8BIT/10BIT in drm_format_info, and then
we can calculate the bpp like the pitch calculation, then no need
caller to specify bpp anymore, and vendor specific get_bpp() likes in malidp
and komeda also can be removed.

for this change maybe we can put it into a new series.

Thanks
James

>  };
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv4,04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2020-02-17 10:55     ` Andrzej Pietrasiewicz
@ 2020-02-17 11:34       ` james qian wang (Arm Technology China)
  0 siblings, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-17 11:34 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, kernel, Mihail Atanassov, David Airlie, Liviu Dudau,
	Sandy Huang, dri-devel, Ayan Halder, Sean Paul

On Mon, Feb 17, 2020 at 11:55:50AM +0100, Andrzej Pietrasiewicz wrote:
> Hi James,
> 
> Thank you for the review.
> 
> Did you intentionally review patches from the v4 series or you simply
> didn't notice the v5? There are some differences, the most notable one
> is using proper way of subclassing a drm_framebuffer.
> The v5 series was sent on 17th December 2019.

Hi Andrzej:
Sorry, I did the review based pathwork:
https://patchwork.freedesktop.org/series/70889/#rev35
seems it has problem which only have V4.

I will re-do the review for V5 ASAP.

Sorry again.

James.

> Andrzej
> 
> W dniu 17.02.2020 o�09:16, james qian wang (Arm Technology China) pisze:
> > Hi Andrzej:
> > 
> > Really a good idea for introducing this custom size check, it's very
> > useful for some Komeda/malidp format, espcially pitch_multiplier, maybe
> > in future we can add it into into the drm_format_info.
> > 
> > On Fri, Dec 13, 2019 at 04:58:35PM +0100, Andrzej Pietrasiewicz wrote:
> > > The new version accepts a struct describing deviations from standard way of
> > > doing the size checks. The caller must provide the respective values.
> > > 
> > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> > > ---
> > >   drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++----
> > >   include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
> > >   2 files changed, 55 insertions(+), 8 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> > > index 787edb9a916b..4201dc1f32a5 100644
> > > --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> > > +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> > > @@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev,
> > >   EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
> > >   /**
> > > - * drm_gem_fb_size_check() - Helper function for use in
> > > - *			     &drm_mode_config_funcs.fb_create implementations
> > > + * drm_gem_fb_size_check_special() - Helper function for use in
> > > + *				     &drm_mode_config_funcs.fb_create
> > > + *				     implementations
> > >    * @dev: DRM device
> > >    * @mode_cmd: Metadata from the userspace framebuffer creation request
> > >    *
> > > @@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
> > >    * Returns:
> > >    * Zero on success or a negative error code on failure.
> > >    */
> > > -int drm_gem_fb_size_check(struct drm_device *dev,
> > > -			  const struct drm_mode_fb_cmd2 *mode_cmd,
> > > -			  struct drm_gem_object **objs)
> > > +int drm_gem_fb_size_check_special(struct drm_device *dev,
> > 
> > How about name it to drm_gem_fb_custom_size_check()
> > 
> > > +				  const struct drm_mode_fb_cmd2 *mode_cmd,
> > > +				  const struct drm_size_check *check,
> > > +				  struct drm_gem_object **objs)
> > >   {
> > >   	const struct drm_format_info *info;
> > >   	int i;
> > > @@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
> > >   		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> > >   		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> > >   		unsigned int min_size;
> > > +		u32 pitch = mode_cmd->pitches[i];
> > > +
> > > +		if (check && check->use_pitch_multiplier)
> > > +			if ((pitch * check->pitch_multiplier[i]) %
> > > +			    check->pitch_modulo)
> > > +				return -EINVAL;
> > > -		min_size = (height - 1) * mode_cmd->pitches[i]
> > > -			 + drm_format_info_min_pitch(info, i, width)
> > > -			 + mode_cmd->offsets[i];
> > > +		if (check && check->use_min_size)
> > > +			min_size = check->min_size[i];
> > > +		else
> > > +			min_size = (height - 1) * pitch
> > > +				 + drm_format_info_min_pitch(info, i, width)
> > > +				 + mode_cmd->offsets[i];
> > >   		if (objs[i]->size < min_size)
> > >   			return -EINVAL;
> > > @@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
> > >   	return 0;
> > >   }
> > > +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special);
> > > +
> > > +/**
> > > + * drm_gem_fb_size_check() - Helper function for use in
> > > + *			     &drm_mode_config_funcs.fb_create implementations
> > > + * @dev: DRM device
> > > + * @mode_cmd: Metadata from the userspace framebuffer creation request
> > > + *
> > > + * This function can be used to verify buffer sizes for all planes.
> > > + * It is caller's responsibility to put the objects on failure.
> > > + *
> > > + * Returns:
> > > + * Zero on success or a negative error code on failure.
> > > + */
> > > +int drm_gem_fb_size_check(struct drm_device *dev,
> > > +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> > > +			  struct drm_gem_object **objs)
> > > +{
> > > +	return drm_gem_fb_size_check_special(dev, mode_cmd, NULL, objs);
> > > +}
> > >   EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
> > >   /**
> > > diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> > > index c85d4b152e91..74304a268694 100644
> > > --- a/include/drm/drm_gem_framebuffer_helper.h
> > > +++ b/include/drm/drm_gem_framebuffer_helper.h
> > > @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
> > >   struct drm_plane;
> > >   struct drm_plane_state;
> > >   struct drm_simple_display_pipe;
> > > +struct drm_size_check;
> > > +
> > > +/**
> > > + * struct drm_size_check - Description of special requirements for size checks.
> > > + */
> > > +struct drm_size_check {
> > > +	unsigned int min_size[4];
> > > +	bool use_min_size;
> > > +	u32 pitch_multiplier[4];
> > > +	u32 pitch_modulo;
> > > +	bool use_pitch_multiplier;
> > > +};
> > >   struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
> > >   					  unsigned int plane);
> > > @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
> > >   		      struct drm_file *file,
> > >   		      const struct drm_mode_fb_cmd2 *mode_cmd,
> > >   		      struct drm_gem_object **objs);
> > > +int drm_gem_fb_size_check_special(struct drm_device *dev,
> > > +				  const struct drm_mode_fb_cmd2 *mode_cmd,
> > > +				  const struct drm_size_check *check,
> > > +				  struct drm_gem_object **objs);
> > >   int drm_gem_fb_size_check(struct drm_device *dev,
> > >   			  const struct drm_mode_fb_cmd2 *mode_cmd,
> > >   			  struct drm_gem_object **objs);
> > 
> > For this common case can we just define it as a MACRO, or a inline
> > func here in this header.
> > 
> > Thanks
> > James
> > 
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 01/34] drm/core: Add afbc helper functions
  2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
@ 2020-02-18  3:13         ` james qian wang (Arm Technology China)
  2020-02-20  9:19         ` Boris Brezillon
  2020-02-20 10:47         ` Boris Brezillon
  2 siblings, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-18  3:13 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, Mihail Atanassov, Sean Paul

Hi Andrzej:

On Tue, Dec 17, 2019 at 03:49:47PM +0100, Andrzej Pietrasiewicz wrote:
> Add checking if a modifier is afbc and getting afbc block size.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++
>  include/drm/drm_fourcc.h     |  4 +++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index b234bfaeda06..d14dd7c86020 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -29,6 +29,7 @@
>  
>  #include <drm/drm_device.h>
>  #include <drm/drm_fourcc.h>
> +#include <drm/drm_print.h>
>  
>  static char printable_char(int c)
>  {
> @@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
>  			    drm_format_info_block_height(info, plane));
>  }
>  EXPORT_SYMBOL(drm_format_info_min_pitch);
> +
> +/**
> + * drm_is_afbc - test if the modifier describes an afbc buffer
> + * @modifier - modifier to be tested
> + *
> + * Returns: true if the modifier describes an afbc buffer
> + */
> +bool drm_is_afbc(u64 modifier)
> +{
> +	/* is it ARM AFBC? */
> +	if ((modifier & DRM_FORMAT_MOD_ARM_AFBC(0)) == 0)
> +		return false;
> +
> +	/* Block size must be known */
> +	if ((modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) == 0)
> +		return false;

Do we really need this block size check here ?
Since modifier with ARM AFBC modifier but have no BLOCK_SIZE which
should be an error, but this check returns such error to NONE-AFBC.

And I saw you already have such error check in func
get_superblock_wh(), so I think we can del this size check in this
func.

James.

> +
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(drm_is_afbc);
> +
> +/**
> + * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier
> + * @modifier: the modifier to be looked at
> + * @w: address of a place to store the block width
> + * @h: address of a place to store the block height
> + *
> + * Returns: true if the modifier describes a supported block size
> + */
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h)
> +{
> +	switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
> +		*w = 16;
> +		*h = 16;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
> +		*w = 32;
> +		*h = 8;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
> +		/* fall through */
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
> +		/* fall through */
> +	default:
> +		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
> +			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
> +		return false;
> +	}
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(drm_afbc_get_superblock_wh);
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index 306d1efeb5e0..7eb23062bf45 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
>  				   int plane, unsigned int buffer_width);
>  const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>  
> +bool drm_is_afbc(u64 modifier);
> +
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h);
> +
>  #endif /* __DRM_FOURCC_H__ */
> -- 
> 2.17.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-17 14:49       ` [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
@ 2020-02-18  3:34         ` james qian wang (Arm Technology China)
  2020-02-20  9:47         ` Boris Brezillon
  1 sibling, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-18  3:34 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, Mihail Atanassov, Sean Paul

Hi Andrzej:
On Tue, Dec 17, 2019 at 03:49:48PM +0100, Andrzej Pietrasiewicz wrote:
> Prepare tools for drivers which need to allocate a struct drm_framebuffer
> (or a container of struct drm_framebuffer) explicitly, before calling
> helpers. In such a case we need new helpers which omit allocating the
> struct drm_framebuffer and this patch provides them. Consequently, they
> are used also inside the helpers themselves.
> 
> The interested drivers will likely need to be able to perform object
> lookups and size checks in separate invocations and this patch provides
> that as well. Helpers themselves are updated, too.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 216 ++++++++++++++-----
>  include/drm/drm_gem_framebuffer_helper.h     |  17 ++
>  2 files changed, 181 insertions(+), 52 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index b9bcd310ca2d..b3494f6b66bb 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -54,6 +54,69 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj);
>  
> +/**
> + * drm_gem_fb_init_with_funcs() - Initialize an already allocated framebuffer
> + * @fb: Framebuffer
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + * @obj: GEM objects to be assigned to the framebuffer
> + * @num_planes: number of planes
> + * @funcs: vtable to be used for the framebuffer object
> + *
> + * This variant of the function allows passing a custom vtable.
> + *
> + * Returns:
> + * 0 on success or a negative error code
> + */
> +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
> +			       struct drm_device *dev,
> +			       const struct drm_mode_fb_cmd2 *mode_cmd,
> +			       struct drm_gem_object **obj,
> +			       unsigned int num_planes,
> +			       const struct drm_framebuffer_funcs *funcs)
> +{
> +	int ret, i;
> +
> +	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> +
> +	for (i = 0; i < num_planes; i++)
> +		fb->obj[i] = obj[i];
> +
> +	ret = drm_framebuffer_init(dev, fb, funcs);
> +	if (ret)
> +		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n", ret);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs);
> +
> +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
> +	.destroy	= drm_gem_fb_destroy,
> +	.create_handle	= drm_gem_fb_create_handle,
> +};
> +
> +/**
> + * drm_gem_fb_init() - Initialize an already allocated framebuffer
> + * @fb: Framebuffer
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + * @obj: GEM objects to be assigned to the framebuffer
> + * @num_planes: number of planes
> + *
> + * This variant of the function uses a default vtable.
> + *
> + * Returns:
> + * 0 on success or a negative error code
> + */
> +int drm_gem_fb_init(struct drm_framebuffer *fb,
> +		    struct drm_device *dev,
> +		    const struct drm_mode_fb_cmd2 *mode_cmd,
> +		    struct drm_gem_object **obj, unsigned int num_planes)
> +{
> +	return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &drm_gem_fb_funcs);
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_init);
> +
>  static struct drm_framebuffer *
>  drm_gem_fb_alloc(struct drm_device *dev,
>  		 const struct drm_mode_fb_cmd2 *mode_cmd,
> @@ -61,21 +124,14 @@ drm_gem_fb_alloc(struct drm_device *dev,
>  		 const struct drm_framebuffer_funcs *funcs)
>  {
>  	struct drm_framebuffer *fb;
> -	int ret, i;
> +	int ret;
>  
>  	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
>  	if (!fb)
>  		return ERR_PTR(-ENOMEM);
>  
> -	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> -
> -	for (i = 0; i < num_planes; i++)
> -		fb->obj[i] = obj[i];
> -
> -	ret = drm_framebuffer_init(dev, fb, funcs);
> +	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, funcs);
>  	if (ret) {
> -		DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n",
> -			      ret);
>  		kfree(fb);
>  		return ERR_PTR(ret);
>  	}
> @@ -144,59 +200,29 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
>  			     const struct drm_mode_fb_cmd2 *mode_cmd,
>  			     const struct drm_framebuffer_funcs *funcs)
>  {
> -	const struct drm_format_info *info;
>  	struct drm_gem_object *objs[4];
>  	struct drm_framebuffer *fb;
> -	int ret, i;
> -
> -	info = drm_get_format_info(dev, mode_cmd);
> -	if (!info)
> -		return ERR_PTR(-EINVAL);
> -
> -	for (i = 0; i < info->num_planes; i++) {
> -		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> -		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> -		unsigned int min_size;
> +	int ret, num_planes;
>  
> -		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
> -		if (!objs[i]) {
> -			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
> -			ret = -ENOENT;
> -			goto err_gem_object_put;
> -		}
> -
> -		min_size = (height - 1) * mode_cmd->pitches[i]
> -			 + drm_format_info_min_pitch(info, i, width)
> -			 + mode_cmd->offsets[i];
> +	ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs);
> +	if (ret < 0)
> +		return ERR_PTR(ret);
> +	num_planes = ret;
>  
> -		if (objs[i]->size < min_size) {
> -			drm_gem_object_put_unlocked(objs[i]);
> -			ret = -EINVAL;
> -			goto err_gem_object_put;
> -		}
> -	}
> +	ret = drm_gem_fb_size_check(dev, mode_cmd, objs);
> +	if (ret)
> +		fb = ERR_PTR(ret);
> +	else
> +		fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs);
>  
> -	fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs);
> -	if (IS_ERR(fb)) {
> -		ret = PTR_ERR(fb);
> -		goto err_gem_object_put;
> -	}
> +	if (IS_ERR(fb))
> +		for (num_planes--; num_planes >= 0; num_planes--)
> +			drm_gem_object_put_unlocked(objs[num_planes]);
>  
>  	return fb;
> -
> -err_gem_object_put:
> -	for (i--; i >= 0; i--)
> -		drm_gem_object_put_unlocked(objs[i]);
> -
> -	return ERR_PTR(ret);
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs);
>  
> -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = {
> -	.destroy	= drm_gem_fb_destroy,
> -	.create_handle	= drm_gem_fb_create_handle,
> -};
> -
>  /**
>   * drm_gem_fb_create() - Helper function for the
>   *                       &drm_mode_config_funcs.fb_create callback
> @@ -228,6 +254,92 @@ drm_gem_fb_create(struct drm_device *dev, struct drm_file *file,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_create);
>  
> +/**
> + * drm_gem_fb_lookup() - Helper function for use in
> + *			 &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @file: DRM file that holds the GEM handle(s) backing the framebuffer
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to look up the objects for all planes.
> + * In case an error is returned all the objects are put by the
> + * function before returning.
> + *
> + * Returns:
> + * Number of planes on success or a negative error code on failure.
> + */
> +int drm_gem_fb_lookup(struct drm_device *dev,

[nit-pick] How about name it to drm_gem_fb_objs_lookup() ?

> +		      struct drm_file *file,
> +		      const struct drm_mode_fb_cmd2 *mode_cmd,
> +		      struct drm_gem_object **objs)
> +{
> +	const struct drm_format_info *info;
> +	int ret, i;
> +
> +	info = drm_get_format_info(dev, mode_cmd);
> +	if (!info)
> +		return -EINVAL;
> +
> +	for (i = 0; i < info->num_planes; i++) {
> +		objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]);
> +		if (!objs[i]) {
> +			DRM_DEBUG_KMS("Failed to lookup GEM object\n");
> +			ret = -ENOENT;
> +			goto err_gem_object_put;
> +		}
> +	}
> +
> +	return i;
> +
> +err_gem_object_put:
> +	for (i--; i >= 0; i--)
> +		drm_gem_object_put_unlocked(objs[i]);
> +
> +	return ret;
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
> +
> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)
> +{
> +	const struct drm_format_info *info;
> +	int i;
> +
> +	info = drm_get_format_info(dev, mode_cmd);
> +	if (!info)
> +		return -EINVAL;
> +
> +	for (i = 0; i < info->num_planes; i++) {
> +		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> +		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> +		unsigned int min_size;
> +
> +		min_size = (height - 1) * mode_cmd->pitches[i]
> +			 + drm_format_info_min_pitch(info, i, width)
> +			 + mode_cmd->offsets[i];
> +
> +		if (objs[i]->size < min_size)
> +			return -EINVAL;
> +	}
> +
> +	return 0;
> +
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
> +
>  static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
>  	.destroy	= drm_gem_fb_destroy,
>  	.create_handle	= drm_gem_fb_create_handle,
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index d9f13fd25b0a..c85d4b152e91 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -14,10 +14,27 @@ struct drm_simple_display_pipe;
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
> +			       struct drm_device *dev,
> +			       const struct drm_mode_fb_cmd2 *mode_cmd,
> +			       struct drm_gem_object **obj,
> +			       unsigned int num_planes,
> +			       const struct drm_framebuffer_funcs *funcs);
> +int drm_gem_fb_init(struct drm_framebuffer *fb,
> +		    struct drm_device *dev,
> +		    const struct drm_mode_fb_cmd2 *mode_cmd,
> +		    struct drm_gem_object **obj, unsigned int num_planes);
>  void drm_gem_fb_destroy(struct drm_framebuffer *fb);
>  int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file,
>  			     unsigned int *handle);
>  
> +int drm_gem_fb_lookup(struct drm_device *dev,
> +		      struct drm_file *file,
> +		      const struct drm_mode_fb_cmd2 *mode_cmd,
> +		      struct drm_gem_object **objs);
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs);
>  struct drm_framebuffer *
>  drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file,
>  			     const struct drm_mode_fb_cmd2 *mode_cmd,
Reviewed-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>

James.

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2019-12-17 14:49       ` [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
@ 2020-02-18  3:42         ` james qian wang (Arm Technology China)
  2020-02-20  9:59         ` Boris Brezillon
  1 sibling, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-18  3:42 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, Mihail Atanassov, Sean Paul

On Tue, Dec 17, 2019 at 03:49:49PM +0100, Andrzej Pietrasiewicz wrote:
> The new version accepts a struct describing deviations from standard way of
> doing the size checks. The caller must provide the respective values.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 46 ++++++++++++++++----
>  include/drm/drm_gem_framebuffer_helper.h     | 16 +++++++
>  2 files changed, 54 insertions(+), 8 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index b3494f6b66bb..d2fce1ec8f37 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -300,8 +300,8 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>  
>  /**
> - * drm_gem_fb_size_check() - Helper function for use in
> - *			     &drm_mode_config_funcs.fb_create implementations
> + * drm_gem_fb_size_check2() - Helper function for use in
> + *			      &drm_mode_config_funcs.fb_create implementations
>   * @dev: DRM device
>   * @mode_cmd: Metadata from the userspace framebuffer creation request
>   *
> @@ -311,9 +311,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>   * Returns:
>   * Zero on success or a negative error code on failure.
>   */
> -int drm_gem_fb_size_check(struct drm_device *dev,
> -			  const struct drm_mode_fb_cmd2 *mode_cmd,
> -			  struct drm_gem_object **objs)
> +int drm_gem_fb_size_check2(struct drm_device *dev,

[nit-pick]: how about name it to drm_gem_fb_custom_size_check()

Reviewed-by: James Qian Wang (Arm Technology China) <james.qian.wang@arm.com>
James.

> +			   const struct drm_mode_fb_cmd2 *mode_cmd,
> +			   const struct drm_size_check *check,
> +			   struct drm_gem_object **objs)
>  {
>  	const struct drm_format_info *info;
>  	int i;
> @@ -326,10 +327,19 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>  		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
>  		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
>  		unsigned int min_size;
> +		u32 pitch = mode_cmd->pitches[i];
> +
> +		if (check && check->use_pitch_multiplier)
> +			if ((pitch * check->pitch_multiplier[i]) %
> +			    check->pitch_modulo)
> +				return -EINVAL;
>  
> -		min_size = (height - 1) * mode_cmd->pitches[i]
> -			 + drm_format_info_min_pitch(info, i, width)
> -			 + mode_cmd->offsets[i];
> +		if (check && check->use_min_size)
> +			min_size = check->min_size[i];
> +		else
> +			min_size = (height - 1) * pitch
> +				 + drm_format_info_min_pitch(info, i, width)
> +				 + mode_cmd->offsets[i];
>  
>  		if (objs[i]->size < min_size)
>  			return -EINVAL;
> @@ -338,6 +348,26 @@ int drm_gem_fb_size_check(struct drm_device *dev,
>  	return 0;
>  
>  }
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check2);
> +
> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)
> +{
> +	return drm_gem_fb_size_check2(dev, mode_cmd, NULL, objs);
> +}
>  EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
>  
>  static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index c85d4b152e91..4955af96d6c3 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
>  struct drm_plane;
>  struct drm_plane_state;
>  struct drm_simple_display_pipe;
> +struct drm_size_check;
> +
> +/**
> + * struct drm_size_check - Description of special requirements for size checks.
> + */
> +struct drm_size_check {
> +	unsigned int min_size[4];
> +	bool use_min_size;
> +	u32 pitch_multiplier[4];
> +	u32 pitch_modulo;
> +	bool use_pitch_multiplier;
> +};
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
>  					  unsigned int plane);
> @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  		      struct drm_file *file,
>  		      const struct drm_mode_fb_cmd2 *mode_cmd,
>  		      struct drm_gem_object **objs);
> +int drm_gem_fb_size_check2(struct drm_device *dev,
> +			   const struct drm_mode_fb_cmd2 *mode_cmd,
> +			   const struct drm_size_check *check,
> +			   struct drm_gem_object **objs);
>  int drm_gem_fb_size_check(struct drm_device *dev,
>  			  const struct drm_mode_fb_cmd2 *mode_cmd,
>  			  struct drm_gem_object **objs);
> -- 
> 2.17.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks
  2019-12-17 14:49       ` [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
@ 2020-02-18  5:02         ` james qian wang (Arm Technology China)
  0 siblings, 0 replies; 106+ messages in thread
From: james qian wang (Arm Technology China) @ 2020-02-18  5:02 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: nd, Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, Mihail Atanassov, Sean Paul

Hi Andrzej:

On Tue, Dec 17, 2019 at 03:49:50PM +0100, Andrzej Pietrasiewicz wrote:
> Extend the size-checking special function to handle afbc.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c | 49 +++++++++++++++++--
>  include/drm/drm_framebuffer.h                | 50 ++++++++++++++++++++
>  include/drm/drm_gem_framebuffer_helper.h     |  1 +
>  3 files changed, 96 insertions(+), 4 deletions(-)
> 
> diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> index d2fce1ec8f37..5fe9032a5ee8 100644
> --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c
> @@ -21,6 +21,11 @@
>  #include <drm/drm_modeset_helper.h>
>  #include <drm/drm_simple_kms_helper.h>
>  
> +#define AFBC_HEADER_SIZE		16
> +#define AFBC_TH_LAYOUT_ALIGNMENT	8
> +#define AFBC_SUPERBLOCK_PIXELS		256
> +#define AFBC_SUPERBLOCK_ALIGNMENT	128
> +
>  /**
>   * DOC: overview
>   *
> @@ -299,6 +304,34 @@ int drm_gem_fb_lookup(struct drm_device *dev,
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_lookup);
>  
> +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)
> +{
> +	u32 n_blocks;
> +
> +	if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &afbc_fb->block_width, &afbc_fb->block_height))
> +		return -EINVAL;
> +
> +	/* tiled header afbc */
> +	if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) {
> +		afbc_fb->block_width *= AFBC_TH_LAYOUT_ALIGNMENT;
> +		afbc_fb->block_height *= AFBC_TH_LAYOUT_ALIGNMENT;
> +	}

TBH, here caculated afbc_fb->block_with/height are not
block_width/height, but fb w/h alignment.
Per my understanding, afbc only has block size: 16x16, 32x8, 64x4 ...
generally the afbc w/h alignment according the the block_size, but once the
tiled header enabled, since one tiled header describes 8x8 superblocks,
so the alignment of w/h need to mutiple 8.

So I think we'd better name the variable to width/height_alignment.


BTW: no matter block_w/h or w/h_alignmtent are only for size
calculation, seems no need to store them to afbc_fb.

> +
> +	afbc_fb->aligned_width = ALIGN(mode_cmd->width, afbc_fb->block_width);
> +	afbc_fb->aligned_height = ALIGN(mode_cmd->height, afbc_fb->block_height);
> +	afbc_fb->offset = mode_cmd->offsets[0];
> +
> +	n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height) / AFBC_SUPERBLOCK_PIXELS;
> +	afbc_fb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, afbc_fb->alignment_header);
> +

After check the references in malidp, rockchip and komeda, seems this
afbc->alignment_header is dedicated for komeda only and a pass in
argument.

This is not true. Per afbc HW spec alignment is essential for
all afbc usage. according to the spec the requiremnt are:

  AFBC1.0/1.1: 64 byte alignment both for header and body buffer.
  AFBC1.2 (tiled header enabled): 4096 alignment.

So this alignement is not a vendor specific value, but afbc feature
requirement, can be determined by afbc modifier.
(malidp and komeda obeys this spec, not sure about Rockchip, but I
think it should be)

But you may see, komeda uses 1024 (not 64) for none-tiled-header afbc,
that's because GPU(MALI) changed this value to 1024 for bus
performance (sorry I don't know the detail), and komeda changed to
1024 to follow.

Back to alignment_header here, I think we can just follow the spec, use 64
for none-tiled-header, 4096 for tiled-header, and no need to let the caller
to specify it

> +	afbc_fb->afbc_size = afbc_fb->offset_payload
> +			   + n_blocks * ALIGN(afbc_fb->bpp * AFBC_SUPERBLOCK_PIXELS / 8, AFBC_SUPERBLOCK_ALIGNMENT);
> +
> +	return 0;
> +}
> +
>  /**
>   * drm_gem_fb_size_check2() - Helper function for use in
>   *			      &drm_mode_config_funcs.fb_create implementations
> @@ -334,19 +367,27 @@ int drm_gem_fb_size_check2(struct drm_device *dev,
>  			    check->pitch_modulo)
>  				return -EINVAL;
>  
> -		if (check && check->use_min_size)
> +		if (check && check->use_min_size) {
>  			min_size = check->min_size[i];
> -		else
> +		} else if (check && check->data && drm_is_afbc(mode_cmd->modifier[0])) {
> +			struct drm_afbc_framebuffer *afbc_fb;
> +			int ret;
> +
> +			afbc_fb = check->data;
> +			ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc_fb);
> +			if (ret < 0)
> +				return ret;
> +			min_size = ret;
> +		} else {
>  			min_size = (height - 1) * pitch
>  				 + drm_format_info_min_pitch(info, i, width)
>  				 + mode_cmd->offsets[i];
> -
> +		}
>  		if (objs[i]->size < min_size)
>  			return -EINVAL;
>  	}
>  
>  	return 0;
> -
>  }
>  EXPORT_SYMBOL_GPL(drm_gem_fb_size_check2);
>  
> diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h
> index c0e0256e3e98..c8a06e37585a 100644
> --- a/include/drm/drm_framebuffer.h
> +++ b/include/drm/drm_framebuffer.h
> @@ -297,4 +297,54 @@ int drm_framebuffer_plane_width(int width,
>  int drm_framebuffer_plane_height(int height,
>  				 const struct drm_framebuffer *fb, int plane);
>  
> +/**
> + * struct drm_afbc_framebuffer - a special afbc frame buffer object
> + *
> + * A derived class of struct drm_framebuffer, dedicated for afbc use cases.
> + */
> +struct drm_afbc_framebuffer {
> +	/**
> +	 * @base: base framebuffer structure.
> +	 */
> +	struct drm_framebuffer base;
> +	/**
> +	 * @block_widht: width of a single afbc block
> +	 */
> +	u32 block_width;
> +	/**
> +	 * @block_widht: height of a single afbc block
> +	 */
> +	u32 block_height;
> +	/**
> +	 * @aligned_width: aligned frame buffer width
> +	 */
> +	u32 aligned_width;
> +	/**
> +	 * @aligned_height: aligned frame buffer height
> +	 */
> +	u32 aligned_height;
> +	/**
> +	 * @offset: offset of the first afbc header
> +	 */
> +	u32 offset;

Since malidp and komeda have no requirement for none-zero offset, so I
think we can reject none zero offset as error like did in rockchip in
afbc_size_check().

> +	/**
> +	 * @alignment_header: required alignment for afbc headers
> +	 */
> +	u32 alignment_header;
> +	/**
> +	 * @afbc_size: minimum size of afbc buffer
> +	 */
> +	u32 afbc_size;
> +	/**
> +	 * @offset_payload: start of afbc body buffer
> +	 */
> +	u32 offset_payload;
> +	/**
> +	 * @bpp: bpp value for this afbc buffer
> +	 */
> +	u32 bpp;

Seems we can remove this bpp or no need to define it as a pass in argument
for size check, maybe the komeda/malidp get_afbc_bpp() function mislead
you that afbc formats may have vendor specific bpp.

But the story is:

for afbc only formats like DRM_FORMAT_YUV420_8BIT/10BIT, we have set
nothing in drm_format_info, neither cpp nor block_size, so both malidp
or komeda introduce a get_bpp(), but actually the two funcs basically
are same.

So my suggestion is we can temporary use the get_afbc_bpp() in malidp
or komeda. and eventually I think we'd better set the block size
for these formats, then we can defines a common get_bpp() like pitch

Thanks
James

> +};
> +
> +#define fb_to_afbc_fb(x) container_of(x, struct drm_afbc_framebuffer, base)
> +
>  #endif
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index 4955af96d6c3..17e3f849a0fb 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -22,6 +22,7 @@ struct drm_size_check {
>  	u32 pitch_multiplier[4];
>  	u32 pitch_modulo;
>  	bool use_pitch_multiplier;
> +	void *data;
>  };
>  
>  struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb,
> -- 
> 2.17.1
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 01/34] drm/core: Add afbc helper functions
  2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
  2020-02-18  3:13         ` james qian wang (Arm Technology China)
@ 2020-02-20  9:19         ` Boris Brezillon
  2020-02-20 10:47         ` Boris Brezillon
  2 siblings, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20  9:19 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Tue, 17 Dec 2019 15:49:47 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

> Add checking if a modifier is afbc and getting afbc block size.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++
>  include/drm/drm_fourcc.h     |  4 +++
>  2 files changed, 57 insertions(+)
> 
> diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c
> index b234bfaeda06..d14dd7c86020 100644
> --- a/drivers/gpu/drm/drm_fourcc.c
> +++ b/drivers/gpu/drm/drm_fourcc.c
> @@ -29,6 +29,7 @@
>  
>  #include <drm/drm_device.h>
>  #include <drm/drm_fourcc.h>
> +#include <drm/drm_print.h>
>  
>  static char printable_char(int c)
>  {
> @@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
>  			    drm_format_info_block_height(info, plane));
>  }
>  EXPORT_SYMBOL(drm_format_info_min_pitch);
> +
> +/**
> + * drm_is_afbc - test if the modifier describes an afbc buffer
> + * @modifier - modifier to be tested
> + *
> + * Returns: true if the modifier describes an afbc buffer
> + */
> +bool drm_is_afbc(u64 modifier)
> +{
> +	/* is it ARM AFBC? */
> +	if ((modifier & DRM_FORMAT_MOD_ARM_AFBC(0)) == 0)

Hm, it's not doing what you describe. The test should be something like

#define VENDOR_AND_TYPE_MASK GENMASK_ULL(63, 52)

	if ((mod & VENDOR_AND_TYPE_MASK) == DRM_FORMAT_MOD_ARM_AFBC(0))

> +		return false;
> +
> +	/* Block size must be known */
> +	if ((modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) == 0)
> +		return false;
> +
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(drm_is_afbc);
> +
> +/**
> + * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier
> + * @modifier: the modifier to be looked at
> + * @w: address of a place to store the block width
> + * @h: address of a place to store the block height
> + *
> + * Returns: true if the modifier describes a supported block size
> + */
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h)
> +{
> +	switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
> +		*w = 16;
> +		*h = 16;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
> +		*w = 32;
> +		*h = 8;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
> +		/* fall through */
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
> +		/* fall through */

Any reason for not supporting those block sizes? It probably deserves a
comment, and a mention in the commit message.

> +	default:
> +		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
> +			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
> +		return false;
> +	}
> +	return true;
> +}
> +EXPORT_SYMBOL_GPL(drm_afbc_get_superblock_wh);
> diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h
> index 306d1efeb5e0..7eb23062bf45 100644
> --- a/include/drm/drm_fourcc.h
> +++ b/include/drm/drm_fourcc.h
> @@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info,
>  				   int plane, unsigned int buffer_width);
>  const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf);
>  
> +bool drm_is_afbc(u64 modifier);
> +
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h);
> +
>  #endif /* __DRM_FOURCC_H__ */

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own
  2019-12-17 14:49       ` [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
  2020-02-18  3:34         ` james qian wang (Arm Technology China)
@ 2020-02-20  9:47         ` Boris Brezillon
  1 sibling, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20  9:47 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Tue, 17 Dec 2019 15:49:48 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

> +/**
> + * drm_gem_fb_size_check() - Helper function for use in
> + *			     &drm_mode_config_funcs.fb_create implementations
> + * @dev: DRM device
> + * @mode_cmd: Metadata from the userspace framebuffer creation request
> + *
> + * This function can be used to verify buffer sizes for all planes.
> + * It is caller's responsibility to put the objects on failure.
> + *
> + * Returns:
> + * Zero on success or a negative error code on failure.
> + */
> +int drm_gem_fb_size_check(struct drm_device *dev,
> +			  const struct drm_mode_fb_cmd2 *mode_cmd,
> +			  struct drm_gem_object **objs)

Maybe we should rename that one drm_gem_fb_linear_size_check().

> +{
> +	const struct drm_format_info *info;
> +	int i;
> +
> +	info = drm_get_format_info(dev, mode_cmd);
> +	if (!info)
> +		return -EINVAL;
> +
> +	for (i = 0; i < info->num_planes; i++) {
> +		unsigned int width = mode_cmd->width / (i ? info->hsub : 1);
> +		unsigned int height = mode_cmd->height / (i ? info->vsub : 1);
> +		unsigned int min_size;
> +
> +		min_size = (height - 1) * mode_cmd->pitches[i]
> +			 + drm_format_info_min_pitch(info, i, width)
> +			 + mode_cmd->offsets[i];
> +
> +		if (objs[i]->size < min_size)
> +			return -EINVAL;
> +	}
> +
> +	return 0;
> +
> +}
> +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check);
> +
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
  2019-12-17 14:49       ` [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
  2020-02-18  3:42         ` james qian wang (Arm Technology China)
@ 2020-02-20  9:59         ` Boris Brezillon
  1 sibling, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20  9:59 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Tue, 17 Dec 2019 15:49:49 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

>  
>  static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = {
> diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h
> index c85d4b152e91..4955af96d6c3 100644
> --- a/include/drm/drm_gem_framebuffer_helper.h
> +++ b/include/drm/drm_gem_framebuffer_helper.h
> @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2;
>  struct drm_plane;
>  struct drm_plane_state;
>  struct drm_simple_display_pipe;
> +struct drm_size_check;
> +
> +/**
> + * struct drm_size_check - Description of special requirements for size checks.
> + */
> +struct drm_size_check {
> +	unsigned int min_size[4];
> +	bool use_min_size;
> +	u32 pitch_multiplier[4];
> +	u32 pitch_modulo;
> +	bool use_pitch_multiplier;
> +};

How about adding a ->size_check() hook to drm_framebuffer_funcs so that
each driver can provide its custom size_check logic. That sounds more
future-prood than trying to make all kind of size-checking fit in
this size-constraint descriptor, plus you wouldn't need this new
drm_gem_fb_size_check2 function.
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 01/34] drm/core: Add afbc helper functions
  2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
  2020-02-18  3:13         ` james qian wang (Arm Technology China)
  2020-02-20  9:19         ` Boris Brezillon
@ 2020-02-20 10:47         ` Boris Brezillon
  2 siblings, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20 10:47 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Tue, 17 Dec 2019 15:49:47 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

> +/**
> + * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier
> + * @modifier: the modifier to be looked at
> + * @w: address of a place to store the block width
> + * @h: address of a place to store the block height
> + *
> + * Returns: true if the modifier describes a supported block size
> + */
> +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h)

You should probably take the multiplane case into account now.
Maybe introduce the following struct and pass a pointer to such
a struct instead of the w/h pointers:

	struct afbc_block_size {
		struct {
			u32 w;
			u32 h;
		} plane[2];
	};

Note that you could also directly return a
const struct afbc_block_size * and consider the NULL case as
'invalid format'.

> +{
> +	switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
> +		*w = 16;
> +		*h = 16;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
> +		*w = 32;
> +		*h = 8;
> +		break;
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
> +		/* fall through */
> +	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
> +		/* fall through */

I guess display controllers might support a subset of what's actually
defined in the spec, so maybe it makes sense to pass a 'const u8
*supported_block_sizes' and then do something like:

	block_size_id = modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;

	for (i = 0; i < num_supported_block_sizes; i++) {
		if (supported_block_sizes[i] == block_size_id)
			break;
	}

	if (i == num_supported_block_sizes)
		return false;

The above switch-case can also be replaced by an array of structs
encoding the block size:

	static const struct afbc_block_size block_sizes[] = {
		[AFBC_FORMAT_MOD_BLOCK_SIZE_16x16] = { { 16, 16 } },
		[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8] = { { 32, 8 } },
		[AFBC_FORMAT_MOD_BLOCK_SIZE_64x4] = { { 64, 4 } },
		[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4] = { { 32, 8 }, { 64, 4} },
	};

	*block_size = block_sizes[block_size_id];

	return true;

> +	default:
> +		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
> +			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
> +		return false;
> +	}
> +	return true;
> +}

To sum-up, this would give something like (not even compile-tested):

struct afbc_block_size {
	struct {
		u32 width;
		u32 height;
	} plane[2];
};

static const struct afbc_block_size superblock_sizes[] = {
	[AFBC_FORMAT_MOD_BLOCK_SIZE_16x16] = { { 16, 16 } },
	[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8] = { { 32, 8 } },
	[AFBC_FORMAT_MOD_BLOCK_SIZE_64x4] = { { 64, 4 } },
	[AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4] = { { 32, 8 }, { 64, 4} },
};

const struct afbc_block_size *
drm_afbc_get_superblock_info(u64 modifier,
			     const u8 *supported_sb_sizes,
			     unsigned int num_supported_sb_sizes)
{
	u8 block_size_id = modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK;


	if (!block_size_id ||
	    block_size_id >= ARRAY_SIZE(superblock_sizes)) {
		DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
		return NULL;
	}

	for (i = 0; i < num_supported_sb_sizes; i++) {
		if (supported_sb_sizes[i] == block_size_id)
			break;
	}

	if (i == num_supported_sb_sizes) {
		DRM_DEBUG_KMS("Unsupported AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n",
			      modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK);
		return NULL;
	}

	return &superblock_sizes[block_size_id];
}
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 34/34] drm/rockchip: Add support for afbc
  2019-12-17 14:50       ` [PATCHv5 34/34] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
@ 2020-02-20 11:20         ` Boris Brezillon
  0 siblings, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20 11:20 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Tue, 17 Dec 2019 15:50:20 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

>  static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = {
> -	.fb_create = drm_gem_fb_create_with_dirty,
> +	.fb_create = rockchip_fb_create,
>  	.output_poll_changed = drm_fb_helper_output_poll_changed,
>  	.atomic_check = drm_atomic_helper_check,
>  	.atomic_commit = drm_atomic_helper_commit,
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> index d04b3492bdac..ffe1e4b9a9ca 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> @@ -91,9 +91,21 @@
>  #define VOP_WIN_TO_INDEX(vop_win) \
>  	((vop_win) - (vop_win)->vop->win)
>  
> +#define VOP_AFBC_SET(vop, name, v) \
> +	do { \
> +		if ((vop)->data->afbc) \
> +			vop_reg_set((vop), &(vop)->data->afbc->name, 0, ~0, v, #name); \
> +	} while (0)
> +
>  #define to_vop(x) container_of(x, struct vop, crtc)
>  #define to_vop_win(x) container_of(x, struct vop_win, base)
>  
> +#define AFBC_FMT_RGB565		0x0
> +#define AFBC_FMT_U8U8U8U8	0x5
> +#define AFBC_FMT_U8U8U8		0x4
> +
> +#define AFBC_TILE_16x16		BIT(4)
> +
>  /*
>   * The coefficients of the following matrix are all fixed points.
>   * The format is S2.10 for the 3x3 part of the matrix, and S9.12 for the offsets.
> @@ -166,6 +178,7 @@ struct vop {
>  	/* optional internal rgb encoder */
>  	struct rockchip_rgb *rgb;
>  
> +	struct vop_win *afbc_win;

Looks like something that should be in the VOP specialized crtc_state.
Also, do we really need a vop_win pointer or can it be replaced by an
index directly?

>  	struct vop_win win[];
>  };
>  
> @@ -274,6 +287,29 @@ static enum vop_data_format vop_convert_format(uint32_t format)
>  	}
>  }
>  
> +static int vop_convert_afbc_format(uint32_t format)
> +{
> +	switch (format) {
> +	case DRM_FORMAT_XRGB8888:
> +	case DRM_FORMAT_ARGB8888:
> +	case DRM_FORMAT_XBGR8888:
> +	case DRM_FORMAT_ABGR8888:
> +		return AFBC_FMT_U8U8U8U8;
> +	case DRM_FORMAT_RGB888:
> +	case DRM_FORMAT_BGR888:
> +		return AFBC_FMT_U8U8U8;
> +	case DRM_FORMAT_RGB565:
> +	case DRM_FORMAT_BGR565:
> +		return AFBC_FMT_RGB565;
> +	/* either of the below should not be reachable */
> +	default:
> +		DRM_WARN_ONCE("unsupported AFBC format[%08x]\n", format);
> +		return -EINVAL;
> +	}
> +
> +	return -EINVAL;
> +}
> +
>  static uint16_t scl_vop_cal_scale(enum scale_mode mode, uint32_t src,
>  				  uint32_t dst, bool is_horizontal,
>  				  int vsu_mode, int *vskiplines)
> @@ -598,6 +634,15 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
>  			vop_win_disable(vop, vop_win);
>  		}
>  	}
> +
> +	if (vop->data->afbc) {
> +		/*
> +		 * Disable AFBC and forget there was a vop window with AFBC
> +		 */
> +		VOP_AFBC_SET(vop, enable, 0);
> +		vop->afbc_win = NULL;
> +	}
> +
>  	spin_unlock(&vop->reg_lock);
>  
>  	vop_cfg_done(vop);
> @@ -710,6 +755,37 @@ static void vop_plane_destroy(struct drm_plane *plane)
>  	drm_plane_cleanup(plane);
>  }
>  
> +static bool rockchip_afbc(u64 modifier)
> +{
> +	return modifier == DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE);
> +}
> +
> +static bool rockchip_mod_supported(struct drm_plane *plane,
> +				   u32 format, u64 modifier)
> +{
> +	const struct drm_format_info *info;
> +
> +	if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID))
> +		return false;
> +
> +	if (modifier == DRM_FORMAT_MOD_LINEAR)
> +		return true;
> +
> +	if (!rockchip_afbc(modifier)) {
> +		DRM_DEBUG_KMS("Unsupported format modifer 0x%llx\n", modifier);
> +
> +		return false;
> +	}
> +
> +	info = drm_format_info(format);
> +	if (info->num_planes != 1) {
> +		DRM_DEBUG_KMS("AFBC buffers expect one plane\n");
> +		return false;
> +	}

Should we have a call to vop_convert_afbc_format() to make sure AFBC
can be applied to this specific format?

> +
> +	return true;
> +}
> +
>  static int vop_plane_atomic_check(struct drm_plane *plane,
>  			   struct drm_plane_state *state)
>  {
> @@ -719,10 +795,8 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
>  	struct vop_win *vop_win = to_vop_win(plane);
>  	const struct vop_win_data *win = vop_win->data;
>  	int ret;
> -	int min_scale = win->phy->scl ? FRAC_16_16(1, 8) :
> -					DRM_PLANE_HELPER_NO_SCALING;
> -	int max_scale = win->phy->scl ? FRAC_16_16(8, 1) :
> -					DRM_PLANE_HELPER_NO_SCALING;
> +	int min_scale = win->phy->scl ? FRAC_16_16(1, 8) : DRM_PLANE_HELPER_NO_SCALING;
> +	int max_scale = win->phy->scl ? FRAC_16_16(8, 1) : DRM_PLANE_HELPER_NO_SCALING;

Looks like those coding-style fixes have nothing to do in this patch :).

>  
>  	if (!crtc || !fb)
>  		return 0;
> @@ -731,9 +805,7 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
>  	if (WARN_ON(!crtc_state))
>  		return -EINVAL;
>  
> -	ret = drm_atomic_helper_check_plane_state(state, crtc_state,
> -						  min_scale, max_scale,
> -						  true, true);
> +	ret = drm_atomic_helper_check_plane_state(state, crtc_state, min_scale, max_scale, true, true);

Same here, plus, following the 80 char rule when it doesn't hurt
readability is a good thing I think.

>  	if (ret)
>  		return ret;
>  
> @@ -758,6 +830,31 @@ static int vop_plane_atomic_check(struct drm_plane *plane,
>  		return -EINVAL;
>  	}
>  
> +	if (rockchip_afbc(fb->modifier)) {
> +		struct vop *vop = to_vop(crtc);
> +
> +		if (!vop->data->afbc) {
> +			DRM_ERROR("vop does not support AFBC\n");
> +			return -EINVAL;
> +		}
> +
> +		ret = vop_convert_afbc_format(fb->format->format);
> +		if (ret < 0)
> +			return ret;
> +
> +		if (state->src.x1 || state->src.y1) {
> +			DRM_ERROR("afbc does not support offset display\n");
> +			DRM_ERROR("xpos=%d, ypos=%d, offset=%d\n", state->src.x1, state->src.y1, fb->offsets[0]);

Why splitting that in 2 error messages?

> +			return -EINVAL;
> +		}
> +
> +		if (state->rotation && state->rotation != DRM_MODE_ROTATE_0) {
> +			DRM_ERROR("afbc does not support rotation\n");
> +			DRM_ERROR("rotation=%d\n", state->rotation);

Ditto.

> +			return -EINVAL;
> +		}
> +	}
> +
>  	return 0;
>  }
>  
> @@ -773,6 +870,11 @@ static void vop_plane_atomic_disable(struct drm_plane *plane,
>  	spin_lock(&vop->reg_lock);
>  
>  	vop_win_disable(vop, vop_win);
> +	/*
> +	 * Forget about the AFBC window if it is being disabled
> +	 */
> +	if (vop_win == vop->afbc_win)
> +		vop->afbc_win = NULL;
>  
>  	spin_unlock(&vop->reg_lock);
>  }
> @@ -812,6 +914,13 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
>  	if (WARN_ON(!vop->is_enabled))
>  		return;
>  
> +	/*
> +	 * If updating the AFBC window then assume that
> +	 * after the update there will be no AFBC window.
> +	 */
> +	if (vop_win == vop->afbc_win)
> +		vop->afbc_win = NULL;
> +
>  	if (!state->visible) {
>  		vop_plane_atomic_disable(plane, old_state);
>  		return;
> @@ -846,6 +955,21 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
>  
>  	spin_lock(&vop->reg_lock);
>  
> +	if (rockchip_afbc(fb->modifier)) {
> +		int afbc_format = vop_convert_afbc_format(fb->format->format);
> +
> +		VOP_AFBC_SET(vop, format, afbc_format | AFBC_TILE_16x16);
> +		VOP_AFBC_SET(vop, hreg_block_split, 0);
> +		VOP_AFBC_SET(vop, win_sel, VOP_WIN_TO_INDEX(vop_win));

IIUC, only one plane can use AFBC at a given time, but you don't seem
to check the value of vop->afbc_win in your atomic_check. What happens
if the user tries to enable this modifier on 2+ planes?

> +		VOP_AFBC_SET(vop, hdr_ptr, dma_addr);
> +		VOP_AFBC_SET(vop, pic_size, act_info);
> +
> +		/*
> +		 * The window being udated becomes the AFBC window
> +		 */
> +		vop->afbc_win = vop_win;
> +	}
> +
>  	VOP_WIN_SET(vop, win, format, format);
>  	VOP_WIN_SET(vop, win, yrgb_vir, DIV_ROUND_UP(fb->pitches[0], 4));
>  	VOP_WIN_SET(vop, win, yrgb_mst, dma_addr);
> @@ -1001,6 +1125,7 @@ static const struct drm_plane_funcs vop_plane_funcs = {
>  	.reset = drm_atomic_helper_plane_reset,
>  	.atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state,
>  	.atomic_destroy_state = drm_atomic_helper_plane_destroy_state,
> +	.format_mod_supported = rockchip_mod_supported,
>  };
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 33/34] drm/rockchip: Use helper for common task
  2019-12-17 14:50       ` [PATCHv5 33/34] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
@ 2020-02-20 11:24         ` Boris Brezillon
  0 siblings, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20 11:24 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Tue, 17 Dec 2019 15:50:19 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

> Use generic helper code.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>
> ---
>  drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 12 ++----------
>  1 file changed, 2 insertions(+), 10 deletions(-)
> 
> diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
> index 221e72e71432..5806f908aa53 100644
> --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
> +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
> @@ -18,6 +18,7 @@
>  #include "rockchip_drm_fb.h"
>  #include "rockchip_drm_gem.h"
>  
> +

You can drop this blank line. Looks good otherwise, but I'll wait for v6
(with the new ->check_size() maybe) before giving my R-b.

>  static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
>  	.destroy       = drm_gem_fb_destroy,
>  	.create_handle = drm_gem_fb_create_handle,
> @@ -30,22 +31,13 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm
>  {
>  	struct drm_framebuffer *fb;
>  	int ret;
> -	int i;
>  
>  	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
>  	if (!fb)
>  		return ERR_PTR(-ENOMEM);
>  
> -	drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd);
> -
> -	for (i = 0; i < num_planes; i++)
> -		fb->obj[i] = obj[i];
> -
> -	ret = drm_framebuffer_init(dev, fb, &rockchip_drm_fb_funcs);
> +	ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs);
>  	if (ret) {
> -		DRM_DEV_ERROR(dev->dev,
> -			      "Failed to initialize framebuffer: %d\n",
> -			      ret);
>  		kfree(fb);
>  		return ERR_PTR(ret);
>  	}

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
  2019-12-17 14:50       ` [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
@ 2020-02-20 11:26         ` Boris Brezillon
  2020-02-20 11:29           ` Boris Brezillon
  0 siblings, 1 reply; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20 11:26 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: kernel, Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

In the subject: s/funcitons/functions/

On Tue, 17 Dec 2019 15:50:15 +0100
Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:

> This will make it easier to transition to generic afbc-aware helpers.
> 
> Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>

Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

> ---
>  drivers/gpu/drm/arm/malidp_drv.c | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
> index 37d92a06318e..961e5a3f5b08 100644
> --- a/drivers/gpu/drm/arm/malidp_drv.c
> +++ b/drivers/gpu/drm/arm/malidp_drv.c
> @@ -362,10 +362,10 @@ static bool
>  malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
>  			       const struct drm_mode_fb_cmd2 *mode_cmd)
>  {
> -	if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
> -		return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
> +	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
> +		return false;
>  
> -	return false;
> +	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
>  }
>  
>  static struct drm_framebuffer *

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
  2020-02-20 11:26         ` Boris Brezillon
@ 2020-02-20 11:29           ` Boris Brezillon
  2020-02-20 11:35             ` Boris Brezillon
  0 siblings, 1 reply; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20 11:29 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Mihail Atanassov, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, Ayan Halder, James Wang, kernel, Sean Paul

On Thu, 20 Feb 2020 12:26:01 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> In the subject: s/funcitons/functions/
> 
> On Tue, 17 Dec 2019 15:50:15 +0100
> Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:
> 
> > This will make it easier to transition to generic afbc-aware helpers.
> > 
> > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>  
> 
> Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>

Wait, patch 30 is this patch completely irrelevant, so I take R-b back
:-). You can just squash that one in patch 30.

> 
> > ---
> >  drivers/gpu/drm/arm/malidp_drv.c | 6 +++---
> >  1 file changed, 3 insertions(+), 3 deletions(-)
> > 
> > diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
> > index 37d92a06318e..961e5a3f5b08 100644
> > --- a/drivers/gpu/drm/arm/malidp_drv.c
> > +++ b/drivers/gpu/drm/arm/malidp_drv.c
> > @@ -362,10 +362,10 @@ static bool
> >  malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
> >  			       const struct drm_mode_fb_cmd2 *mode_cmd)
> >  {
> > -	if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
> > -		return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
> > +	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
> > +		return false;
> >  
> > -	return false;
> > +	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
> >  }
> >  
> >  static struct drm_framebuffer *  
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent
  2020-02-20 11:29           ` Boris Brezillon
@ 2020-02-20 11:35             ` Boris Brezillon
  0 siblings, 0 replies; 106+ messages in thread
From: Boris Brezillon @ 2020-02-20 11:35 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Mihail Atanassov, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	dri-devel, James Wang, Ayan Halder, Sean Paul

On Thu, 20 Feb 2020 12:29:13 +0100
Boris Brezillon <boris.brezillon@collabora.com> wrote:

> On Thu, 20 Feb 2020 12:26:01 +0100
> Boris Brezillon <boris.brezillon@collabora.com> wrote:
> 
> > In the subject: s/funcitons/functions/
> > 
> > On Tue, 17 Dec 2019 15:50:15 +0100
> > Andrzej Pietrasiewicz <andrzej.p@collabora.com> wrote:
> >   
> > > This will make it easier to transition to generic afbc-aware helpers.
> > > 
> > > Signed-off-by: Andrzej Pietrasiewicz <andrzej.p@collabora.com>    
> > 
> > Reviewed-by: Boris Brezillon <boris.brezillon@collabora.com>  
> 
> Wait, patch 30 is this patch completely irrelevant, so I take R-b back

s/patch 30 is this patch completely irrelevant/this patch is completely
irrelevant if patch 30 is applied/

> :-). You can just squash that one in patch 30.
> 
> >   
> > > ---
> > >  drivers/gpu/drm/arm/malidp_drv.c | 6 +++---
> > >  1 file changed, 3 insertions(+), 3 deletions(-)
> > > 
> > > diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c
> > > index 37d92a06318e..961e5a3f5b08 100644
> > > --- a/drivers/gpu/drm/arm/malidp_drv.c
> > > +++ b/drivers/gpu/drm/arm/malidp_drv.c
> > > @@ -362,10 +362,10 @@ static bool
> > >  malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file,
> > >  			       const struct drm_mode_fb_cmd2 *mode_cmd)
> > >  {
> > > -	if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
> > > -		return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
> > > +	if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd))
> > > +		return false;
> > >  
> > > -	return false;
> > > +	return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd);
> > >  }
> > >  
> > >  static struct drm_framebuffer *    
> > 
> > _______________________________________________
> > dri-devel mailing list
> > dri-devel@lists.freedesktop.org
> > https://lists.freedesktop.org/mailman/listinfo/dri-devel  
> 
> _______________________________________________
> dri-devel mailing list
> dri-devel@lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/dri-devel

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

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
                         ` (34 preceding siblings ...)
  2020-01-30  9:08       ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
@ 2020-02-20 16:54       ` Daniel Vetter
  2020-02-21 19:54         ` Daniel Vetter
  35 siblings, 1 reply; 106+ messages in thread
From: Daniel Vetter @ 2020-02-20 16:54 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	James Wang, dri-devel, Mihail Atanassov, Sean Paul

On Tue, Dec 17, 2019 at 03:49:46PM +0100, Andrzej Pietrasiewicz wrote:
> This series adds AFBC support for Rockchip. It is inspired by:
> 
> https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> 
> This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
> rework has been done, the main goal of which was to move all afbc-related
> checks to helpers, so that core does not deal with it.
> 
> A new struct drm_afbc_framebuffer is added, which stores afbc-related
> driver-specific data. Because of that, in drivers that wish to
> use this feature, the struct must be allocated directly in the driver
> code rather than inside helpers, so the first portion of the patchset
> does the necessary refactoring.
> 
> Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
> the latter being the ultimate purpose of this work and the 3 subsequent
> portions of the patchset move komeda and malidp to generic helpers and add
> afbc support to rockchip.
> 
> The idea is to make all afbc users follow a similar pattern. In fb_create()
> they allocate struct drm_afbc_framebuffer, do their specific checks which
> can be done before object lookups, do object lookups and a special version
> of a size check, which understands struct drm_afbc_framebuffer, followed
> by any other driver-specific checks and initializing the gem object.
> The helpers for the common parts are factored out so that drivers
> can use them.
> 
> The komeda driver has been the farthest away from such a pattern, so it
> required most changes. However, due to the fact that I don't have any
> komeda hardware I did the changes to komeda in an incremental fashion with
> a series of (usually) very small, easy to understand steps. malidp was
> pretty straightforward, and rockchip's afbc checks follow the pattern.
> 
> I kindly ask for reviewing the series. I need to mention that my ultimate
> goal is merging afbc for rockchip and I don't have other hardware, so some
> help from malidp and komeda developers/maintainers would be appreciated.
> 
> @Liviu, @James, @Mihail, @Brian: a kind request to you to have a look and
> test the patchset, as I don't have appropriate hardware.
> 
> Rebased onto drm-misc-next.
> 
> v4..v5:
> - used proper way of subclassing drm_framebuffer (Daniel Vetter)
> - added documentation to exported functions (Liviu Dudau)
> - reordered new functions in drm_gem_framebuffer_helper.c to make a saner
> diff (Liviu Dudau)
> - used "2" suffix instead of "_special" for the special version of size
> checks (Liviu Dudau)
> - dropped unnecessarily added condition in drm_get_format_info() (Liviu
> Dudau)
> - dropped "block_size = 0;" trick in framebuffer_check() (Daniel Vetter)
> - relaxed sticking to 80 characters per line rule in some cases
> 
> v3..v4:
> 
> - addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel
> Vetter and James Qian Wang - thank you for input
> - refactored helpers to ease accommodating drivers with afbc needs
> - moved afbc checks to helpers
> - converted komeda, malidp and (the newly added) rockchip to use the afbc
> helpers
> - eliminated a separate, dedicated source code file
> 
> v2..v3:
> 
> - addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter
> and Brian Starkey - thank you all
> 
> In this iteration some rework has been done. The checking logic is now moved
> to framebuffer_check() so it is common to all drivers. But the common part
> is not good for komeda, so this series is not good for merging yet.
> I kindly ask for feedback whether the changes are in the right direction.
> I also kindly ask for input on how to accommodate komeda.
> 
> The CONFIG_DRM_AFBC option has been eliminated in favour of adding
> drm_afbc.c to drm_kms_helper.
> 
> v1..v2:
> 
> - addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
> - coding style fixes** BLURB HERE ***
> 
> 
> Andrzej Pietrasiewicz (34):
>   drm/core: Add afbc helper functions
>   drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on
>     their own
>   drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
>   drm/gem-fb-helper: Add generic afbc size checks
>   drm/komeda: Use afbc helper
>   drm/komeda: Move checking src coordinates to komeda_fb_create
>   drm/komeda: Use the already available local variable
>   drm/komeda: Retrieve drm_format_info once
>   drm/komeda: Explicitly require 1 plane for AFBC
>   drm/komeda: Move pitches comparison to komeda_fb_create
>   drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not
>     requiring a fb
>   drm/komeda: Factor out object lookups for non-afbc case
>   drm/komeda: Make komeda_fb_none_size_check independent from
>     framebuffer
>   drm/komeda: Factor out object lookups for afbc case
>   drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
>   drm/komeda: Simplify error handling
>   drm/komeda: Move object lookup before size checks
>   drm/komeda: Move object assignments to framebuffer to after size
>     checks
>   drm/komeda: Make the size checks independent from framebuffer
>     structure
>   drm/komeda: Move helper invocation to after size checks
>   drm/komeda: Use helper for common tasks
>   drm/komeda: Use return value of drm_gem_fb_lookup
>   drm/komeda: Use special helper for non-afbc size checks
>   drm/komeda: Factor in the invocation of special helper
>   drm/komeda: Use special helper for afbc case size check
>   drm/komeda: Factor in the invocation of special helper, afbc case
>   drm/komeda: Move special helper invocation outside if-else
>   drm/komeda: Move to helper checking afbc buffer size
>   drm/arm/malidp: Make verify funcitons invocations independent
>   drm/arm/malidp: Integrate verify functions
>   drm/arm/malidp: Factor in afbc framebuffer verification
>   drm/arm/malidp: Use generic helpers for afbc checks
>   drm/rockchip: Use helper for common task
>   drm/rockchip: Add support for afbc
> 
>  .../arm/display/komeda/d71/d71_component.c    |   6 +-
>  .../arm/display/komeda/komeda_framebuffer.c   | 273 ++++++++---------
>  .../arm/display/komeda/komeda_framebuffer.h   |  21 +-
>  .../display/komeda/komeda_pipeline_state.c    |  14 +-
>  drivers/gpu/drm/arm/malidp_drv.c              | 155 ++++------
>  drivers/gpu/drm/drm_fourcc.c                  |  53 ++++
>  drivers/gpu/drm/drm_gem_framebuffer_helper.c  | 287 ++++++++++++++----
>  drivers/gpu/drm/rockchip/rockchip_drm_fb.c    | 111 ++++++-
>  drivers/gpu/drm/rockchip/rockchip_drm_vop.c   | 147 ++++++++-
>  drivers/gpu/drm/rockchip/rockchip_drm_vop.h   |  12 +
>  drivers/gpu/drm/rockchip/rockchip_vop_reg.c   |  83 ++++-
>  include/drm/drm_fourcc.h                      |   4 +
>  include/drm/drm_framebuffer.h                 |  50 +++
>  include/drm/drm_gem_framebuffer_helper.h      |  34 +++
>  14 files changed, 907 insertions(+), 343 deletions(-)

I think this isn't achieving it's goal. Even if we take out the rockchip
enabling patch at the ent it's still like 200 lines more for something
that's supposed to unify and clean code up.

Plus it looks enormously complicated, something that I missed in my
previous quick glance. Hence proposal for all the things you're going to
add to drm core/helpers, and not a bit more :-)

int
drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
			   struct drm_device *dev, struct drm_file *file,
			   const struct drm_mode_fb_cmd2 *mode_cmd,
			   const struct drm_framebuffer_funcs *funcs);

This is going to do _exactly_ what drm_gem_fb_create_with_funcs already
does, except it doesn't do the kzalloc (so that would need to be moved out
so we can share code). No other additional sub-parts exposed, I think
that's just not worth it in this case. So none of this size check stuff.

2nd piece, your drm_afbc_framebuffer as in patch 4, with the subclassing.

3rd piece, again in drm_gem_framebuffer_helper.c:

int drm_gem_afbc_init(struct drm_afbc_framebuffer *afbc_fb);

Drivers are supposed to call this after they've a) allocated their fb
structure, containing the drm_afbc_framebuffer somewhere and b) called
drm_gem_fb_init_with_funcs(). This function is going to fill out all the
additional fields, and this function is also going to do all the size
validation and everything else.

Nothing else, so no finer split up of helper check functions, or of afbc
computation functions, or of anything else. That mix of split-out stuff
and mix of computed values in drm_afbc_framebuffer but also functions that
compute afbc values from modifiers and fb sizes seems to just lead to a
huge confusion and not actually to a code reduction. So
- none of the functions exported in patch 1, just stuff them into
  drm_gem_framebuffer_helper.c.
- none of the helper subfunctions you export in patch 2, or adapt in patch
  3
- Also not this size check structure with the data pointer you add in
  patch 4.

The bikeshed I'm still seeing here is whether drm_afbc_framebuffer and the
drm_gem_afbc_init() function should be considered core stuff or not, I
guess you can make an argument for either.

This should also make conversion easier since as a first steps you'd do:

- Put the new drm_afbc_framebuffer in place and adjust all tha
  fb_to_komeda functions and upcasting (this should be mechanically)

- Add the call to drm_gem_afbc_init().

- Starting using the new values in drm_afbc_framebuffer and slowly delete
  code

- Optional, but would be nice to do: Convert driver over to
  drm_gem_fb_init_with_funcs().

Thoughts?

Cheers, Daniel
-- 
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

* Re: [PATCHv5 00/34] Add AFBC support for Rockchip
  2020-02-20 16:54       ` Daniel Vetter
@ 2020-02-21 19:54         ` Daniel Vetter
  0 siblings, 0 replies; 106+ messages in thread
From: Daniel Vetter @ 2020-02-21 19:54 UTC (permalink / raw)
  To: Andrzej Pietrasiewicz
  Cc: Ayan Halder, kernel, David Airlie, Liviu Dudau, Sandy Huang,
	James Wang, dri-devel, Mihail Atanassov, Sean Paul

On Thu, Feb 20, 2020 at 5:54 PM Daniel Vetter <daniel@ffwll.ch> wrote:
>
> On Tue, Dec 17, 2019 at 03:49:46PM +0100, Andrzej Pietrasiewicz wrote:
> > This series adds AFBC support for Rockchip. It is inspired by:
> >
> > https://chromium.googlesource.com/chromiumos/third_party/kernel/+/refs/heads/factory-gru-9017.B-chromeos-4.4/drivers/gpu/drm/rockchip/rockchip_drm_vop.c
> >
> > This is the fifth iteration of the afbc series. Between v3 and v4 a lot of
> > rework has been done, the main goal of which was to move all afbc-related
> > checks to helpers, so that core does not deal with it.
> >
> > A new struct drm_afbc_framebuffer is added, which stores afbc-related
> > driver-specific data. Because of that, in drivers that wish to
> > use this feature, the struct must be allocated directly in the driver
> > code rather than inside helpers, so the first portion of the patchset
> > does the necessary refactoring.
> >
> > Then, there are 3 users of afbc: komeda, malidp and, finally, rockchip,
> > the latter being the ultimate purpose of this work and the 3 subsequent
> > portions of the patchset move komeda and malidp to generic helpers and add
> > afbc support to rockchip.
> >
> > The idea is to make all afbc users follow a similar pattern. In fb_create()
> > they allocate struct drm_afbc_framebuffer, do their specific checks which
> > can be done before object lookups, do object lookups and a special version
> > of a size check, which understands struct drm_afbc_framebuffer, followed
> > by any other driver-specific checks and initializing the gem object.
> > The helpers for the common parts are factored out so that drivers
> > can use them.
> >
> > The komeda driver has been the farthest away from such a pattern, so it
> > required most changes. However, due to the fact that I don't have any
> > komeda hardware I did the changes to komeda in an incremental fashion with
> > a series of (usually) very small, easy to understand steps. malidp was
> > pretty straightforward, and rockchip's afbc checks follow the pattern.
> >
> > I kindly ask for reviewing the series. I need to mention that my ultimate
> > goal is merging afbc for rockchip and I don't have other hardware, so some
> > help from malidp and komeda developers/maintainers would be appreciated.
> >
> > @Liviu, @James, @Mihail, @Brian: a kind request to you to have a look and
> > test the patchset, as I don't have appropriate hardware.
> >
> > Rebased onto drm-misc-next.
> >
> > v4..v5:
> > - used proper way of subclassing drm_framebuffer (Daniel Vetter)
> > - added documentation to exported functions (Liviu Dudau)
> > - reordered new functions in drm_gem_framebuffer_helper.c to make a saner
> > diff (Liviu Dudau)
> > - used "2" suffix instead of "_special" for the special version of size
> > checks (Liviu Dudau)
> > - dropped unnecessarily added condition in drm_get_format_info() (Liviu
> > Dudau)
> > - dropped "block_size = 0;" trick in framebuffer_check() (Daniel Vetter)
> > - relaxed sticking to 80 characters per line rule in some cases
> >
> > v3..v4:
> >
> > - addressed (some) comments from Daniel Stone, Ezequiel Garcia, Daniel
> > Vetter and James Qian Wang - thank you for input
> > - refactored helpers to ease accommodating drivers with afbc needs
> > - moved afbc checks to helpers
> > - converted komeda, malidp and (the newly added) rockchip to use the afbc
> > helpers
> > - eliminated a separate, dedicated source code file
> >
> > v2..v3:
> >
> > - addressed (some) comments from Daniel Stone, Liviu Dudau, Daniel Vetter
> > and Brian Starkey - thank you all
> >
> > In this iteration some rework has been done. The checking logic is now moved
> > to framebuffer_check() so it is common to all drivers. But the common part
> > is not good for komeda, so this series is not good for merging yet.
> > I kindly ask for feedback whether the changes are in the right direction.
> > I also kindly ask for input on how to accommodate komeda.
> >
> > The CONFIG_DRM_AFBC option has been eliminated in favour of adding
> > drm_afbc.c to drm_kms_helper.
> >
> > v1..v2:
> >
> > - addressed comments from Daniel Stone, Ayan Halder, Mihail Atanassov
> > - coding style fixes** BLURB HERE ***
> >
> >
> > Andrzej Pietrasiewicz (34):
> >   drm/core: Add afbc helper functions
> >   drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on
> >     their own
> >   drm/gem-fb-helper: Add special version of drm_gem_fb_size_check
> >   drm/gem-fb-helper: Add generic afbc size checks
> >   drm/komeda: Use afbc helper
> >   drm/komeda: Move checking src coordinates to komeda_fb_create
> >   drm/komeda: Use the already available local variable
> >   drm/komeda: Retrieve drm_format_info once
> >   drm/komeda: Explicitly require 1 plane for AFBC
> >   drm/komeda: Move pitches comparison to komeda_fb_create
> >   drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not
> >     requiring a fb
> >   drm/komeda: Factor out object lookups for non-afbc case
> >   drm/komeda: Make komeda_fb_none_size_check independent from
> >     framebuffer
> >   drm/komeda: Factor out object lookups for afbc case
> >   drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency
> >   drm/komeda: Simplify error handling
> >   drm/komeda: Move object lookup before size checks
> >   drm/komeda: Move object assignments to framebuffer to after size
> >     checks
> >   drm/komeda: Make the size checks independent from framebuffer
> >     structure
> >   drm/komeda: Move helper invocation to after size checks
> >   drm/komeda: Use helper for common tasks
> >   drm/komeda: Use return value of drm_gem_fb_lookup
> >   drm/komeda: Use special helper for non-afbc size checks
> >   drm/komeda: Factor in the invocation of special helper
> >   drm/komeda: Use special helper for afbc case size check
> >   drm/komeda: Factor in the invocation of special helper, afbc case
> >   drm/komeda: Move special helper invocation outside if-else
> >   drm/komeda: Move to helper checking afbc buffer size
> >   drm/arm/malidp: Make verify funcitons invocations independent
> >   drm/arm/malidp: Integrate verify functions
> >   drm/arm/malidp: Factor in afbc framebuffer verification
> >   drm/arm/malidp: Use generic helpers for afbc checks
> >   drm/rockchip: Use helper for common task
> >   drm/rockchip: Add support for afbc
> >
> >  .../arm/display/komeda/d71/d71_component.c    |   6 +-
> >  .../arm/display/komeda/komeda_framebuffer.c   | 273 ++++++++---------
> >  .../arm/display/komeda/komeda_framebuffer.h   |  21 +-
> >  .../display/komeda/komeda_pipeline_state.c    |  14 +-
> >  drivers/gpu/drm/arm/malidp_drv.c              | 155 ++++------
> >  drivers/gpu/drm/drm_fourcc.c                  |  53 ++++
> >  drivers/gpu/drm/drm_gem_framebuffer_helper.c  | 287 ++++++++++++++----
> >  drivers/gpu/drm/rockchip/rockchip_drm_fb.c    | 111 ++++++-
> >  drivers/gpu/drm/rockchip/rockchip_drm_vop.c   | 147 ++++++++-
> >  drivers/gpu/drm/rockchip/rockchip_drm_vop.h   |  12 +
> >  drivers/gpu/drm/rockchip/rockchip_vop_reg.c   |  83 ++++-
> >  include/drm/drm_fourcc.h                      |   4 +
> >  include/drm/drm_framebuffer.h                 |  50 +++
> >  include/drm/drm_gem_framebuffer_helper.h      |  34 +++
> >  14 files changed, 907 insertions(+), 343 deletions(-)
>
> I think this isn't achieving it's goal. Even if we take out the rockchip
> enabling patch at the ent it's still like 200 lines more for something
> that's supposed to unify and clean code up.
>
> Plus it looks enormously complicated, something that I missed in my
> previous quick glance. Hence proposal for all the things you're going to
> add to drm core/helpers, and not a bit more :-)
>
> int
> drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb,
>                            struct drm_device *dev, struct drm_file *file,
>                            const struct drm_mode_fb_cmd2 *mode_cmd,
>                            const struct drm_framebuffer_funcs *funcs);
>
> This is going to do _exactly_ what drm_gem_fb_create_with_funcs already
> does, except it doesn't do the kzalloc (so that would need to be moved out
> so we can share code). No other additional sub-parts exposed, I think
> that's just not worth it in this case. So none of this size check stuff.
>
> 2nd piece, your drm_afbc_framebuffer as in patch 4, with the subclassing.
>
> 3rd piece, again in drm_gem_framebuffer_helper.c:
>
> int drm_gem_afbc_init(struct drm_afbc_framebuffer *afbc_fb);
>
> Drivers are supposed to call this after they've a) allocated their fb
> structure, containing the drm_afbc_framebuffer somewhere and b) called
> drm_gem_fb_init_with_funcs(). This function is going to fill out all the
> additional fields, and this function is also going to do all the size
> validation and everything else.
>
> Nothing else, so no finer split up of helper check functions, or of afbc
> computation functions, or of anything else. That mix of split-out stuff
> and mix of computed values in drm_afbc_framebuffer but also functions that
> compute afbc values from modifiers and fb sizes seems to just lead to a
> huge confusion and not actually to a code reduction. So
> - none of the functions exported in patch 1, just stuff them into
>   drm_gem_framebuffer_helper.c.
> - none of the helper subfunctions you export in patch 2, or adapt in patch
>   3
> - Also not this size check structure with the data pointer you add in
>   patch 4.
>
> The bikeshed I'm still seeing here is whether drm_afbc_framebuffer and the
> drm_gem_afbc_init() function should be considered core stuff or not, I
> guess you can make an argument for either.
>
> This should also make conversion easier since as a first steps you'd do:
>
> - Put the new drm_afbc_framebuffer in place and adjust all tha
>   fb_to_komeda functions and upcasting (this should be mechanically)
>
> - Add the call to drm_gem_afbc_init().
>
> - Starting using the new values in drm_afbc_framebuffer and slowly delete
>   code
>
> - Optional, but would be nice to do: Convert driver over to
>   drm_gem_fb_init_with_funcs().
>
> Thoughts?

I forgot to add that maybe we'll need a ->get_format_info
implementation which supplies a suitable structure (with block_size ==
0 to disable the checks). But I'm kinda assume that the buffer will be
bigger than a compressed one, since you also have the compression
metadata on top. So just keeping the size checks for uncompressed
buffer, and then doing the additional validation on top, might work
out.

But yeah if that fails we'll need a drm_afbc_gem_get_format_info()
hook that drivers can set up.
-Daniel

>
> Cheers, Daniel
> --
> Daniel Vetter
> Software Engineer, Intel Corporation
> http://blog.ffwll.ch



-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

^ permalink raw reply	[flat|nested] 106+ messages in thread

end of thread, other threads:[~2020-02-21 19:55 UTC | newest]

Thread overview: 106+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-12-13 15:58 [PATCHv4 00/36] AFBC support for Rockchip Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 01/36] drm/framebuffer: Add optional modifier info Andrzej Pietrasiewicz
2020-02-17  5:50   ` [PATCHv4,01/36] " james qian wang (Arm Technology China)
2019-12-13 15:58 ` [PATCHv4 02/36] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
2020-02-17  6:09   ` [PATCHv4,02/36] " james qian wang (Arm Technology China)
2019-12-13 15:58 ` [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
2019-12-16 17:08   ` Liviu Dudau
2019-12-16 20:37     ` Andrzej Pietrasiewicz
2020-02-17  6:39   ` [PATCHv4,03/36] " james qian wang (Arm Technology China)
2019-12-13 15:58 ` [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
2019-12-16 17:11   ` Liviu Dudau
2020-02-17  8:16   ` [PATCHv4,04/36] " james qian wang (Arm Technology China)
2020-02-17 10:55     ` Andrzej Pietrasiewicz
2020-02-17 11:34       ` james qian wang (Arm Technology China)
2019-12-13 15:58 ` [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
2019-12-16 17:19   ` Liviu Dudau
2019-12-16 18:41     ` Andrzej Pietrasiewicz
2019-12-17  9:18       ` Liviu Dudau
2020-02-17 11:02   ` [PATCHv4,05/36] " james qian wang (Arm Technology China)
2019-12-13 15:58 ` [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer Andrzej Pietrasiewicz
2019-12-13 17:33   ` Daniel Vetter
2019-12-17 14:49     ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 01/34] drm/core: Add afbc helper functions Andrzej Pietrasiewicz
2020-02-18  3:13         ` james qian wang (Arm Technology China)
2020-02-20  9:19         ` Boris Brezillon
2020-02-20 10:47         ` Boris Brezillon
2019-12-17 14:49       ` [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Andrzej Pietrasiewicz
2020-02-18  3:34         ` james qian wang (Arm Technology China)
2020-02-20  9:47         ` Boris Brezillon
2019-12-17 14:49       ` [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Andrzej Pietrasiewicz
2020-02-18  3:42         ` james qian wang (Arm Technology China)
2020-02-20  9:59         ` Boris Brezillon
2019-12-17 14:49       ` [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks Andrzej Pietrasiewicz
2020-02-18  5:02         ` james qian wang (Arm Technology China)
2019-12-17 14:49       ` [PATCHv5 05/34] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 06/34] drm/komeda: Move checking src coordinates to komeda_fb_create Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 07/34] drm/komeda: Use the already available local variable Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 08/34] drm/komeda: Retrieve drm_format_info once Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 09/34] drm/komeda: Explicitly require 1 plane for AFBC Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 10/34] drm/komeda: Move pitches comparison to komeda_fb_create Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 11/34] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 12/34] drm/komeda: Factor out object lookups for non-afbc case Andrzej Pietrasiewicz
2019-12-17 14:49       ` [PATCHv5 13/34] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 14/34] drm/komeda: Factor out object lookups for afbc case Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 15/34] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 16/34] drm/komeda: Simplify error handling Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 17/34] drm/komeda: Move object lookup before size checks Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 18/34] drm/komeda: Move object assignments to framebuffer to after " Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 19/34] drm/komeda: Make the size checks independent from framebuffer structure Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 20/34] drm/komeda: Move helper invocation to after size checks Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 21/34] drm/komeda: Use helper for common tasks Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 22/34] drm/komeda: Use return value of drm_gem_fb_lookup Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 23/34] drm/komeda: Use special helper for non-afbc size checks Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 24/34] drm/komeda: Factor in the invocation of special helper Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 25/34] drm/komeda: Use special helper for afbc case size check Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 26/34] drm/komeda: Factor in the invocation of special helper, afbc case Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 27/34] drm/komeda: Move special helper invocation outside if-else Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 28/34] drm/komeda: Move to helper checking afbc buffer size Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
2020-02-20 11:26         ` Boris Brezillon
2020-02-20 11:29           ` Boris Brezillon
2020-02-20 11:35             ` Boris Brezillon
2019-12-17 14:50       ` [PATCHv5 30/34] drm/arm/malidp: Integrate verify functions Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 31/34] drm/arm/malidp: Factor in afbc framebuffer verification Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 32/34] drm/arm/malidp: Use generic helpers for afbc checks Andrzej Pietrasiewicz
2019-12-17 14:50       ` [PATCHv5 33/34] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
2020-02-20 11:24         ` Boris Brezillon
2019-12-17 14:50       ` [PATCHv5 34/34] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz
2020-02-20 11:20         ` Boris Brezillon
2020-01-30  9:08       ` [PATCHv5 00/34] Add AFBC support for Rockchip Andrzej Pietrasiewicz
2020-01-30 11:44         ` Liviu Dudau
2020-01-30 11:57           ` Andrzej Pietrasiewicz
2020-02-07 11:44         ` Andrzej Pietrasiewicz
2020-02-07 17:10           ` Liviu Dudau
2020-02-20 16:54       ` Daniel Vetter
2020-02-21 19:54         ` Daniel Vetter
2019-12-13 15:58 ` [PATCHv4 07/36] drm/komeda: Use afbc helper Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 08/36] drm/komeda: Move checking src coordinates to komeda_fb_create Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 09/36] drm/komeda: Use the already available local variable Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 10/36] drm/komeda: Retrieve drm_format_info once Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 11/36] drm/komeda: Explicitly require 1 plane for AFBC Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 12/36] drm/komeda: Move pitches comparison to komeda_fb_create Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 13/36] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 14/36] drm/komeda: Factor out object lookups for non-afbc case Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 15/36] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 16/36] drm/komeda: Factor out object lookups for afbc case Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 17/36] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 18/36] drm/komeda: Simplify error handling Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 19/36] drm/komeda: Move object lookup before size checks Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 20/36] drm/komeda: Move object assignments to framebuffer to after " Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 21/36] drm/komeda: Make the size checks independent from framebuffer structure Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 22/36] drm/komeda: Move helper invocation to after size checks Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 23/36] drm/komeda: Use helper for common tasks Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 24/36] drm/komeda: Use return value of drm_gem_fb_lookup Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 25/36] drm/komeda: Use special helper for non-afbc size checks Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 26/36] drm/komeda: Factor in the invocation of special helper Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 27/36] drm/komeda: Use special helper for afbc case size check Andrzej Pietrasiewicz
2019-12-13 15:58 ` [PATCHv4 28/36] drm/komeda: Factor in the invocation of special helper, afbc case Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 29/36] drm/komeda: Move special helper invocation outside if-else Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 30/36] drm/komeda: Move to helper checking afbc buffer size Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 31/36] drm/arm/malidp: Make verify funcitons invocations independent Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 32/36] drm/arm/malidp: Integrate verify functions Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 33/36] drm/arm/malidp: Factor in afbc framebuffer verification Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 34/36] drm/arm/malidp: Use generic helpers for afbc checks Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 35/36] drm/rockchip: Use helper for common task Andrzej Pietrasiewicz
2019-12-13 15:59 ` [PATCHv4 36/36] drm/rockchip: Add support for afbc Andrzej Pietrasiewicz

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.