Skip to contentSkip to conversation

AFBC for Rockchip

PATCH Superseded Andrzej Pietrasiewicz 12 participants 43 messages Oct 11, 2019 – Nov 28, 2019 1 message not in the archive

Subsystems (6)

v1 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

cover AFBC for Rockchip

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

The first patch factors out some afbc helper functions from malidp, as they are useful in general. The second patch adds implementation proper of AFBC support for Rockchip.

Andrzej Pietrasiewicz (2):
drm/arm: Factor out generic afbc helpers
drm/rockchip: Add support for afbc

 drivers/gpu/drm/Kconfig                     |   4 +
 drivers/gpu/drm/Makefile                    |   1 +
 drivers/gpu/drm/arm/Kconfig                 |   1 +
 drivers/gpu/drm/arm/malidp_drv.c            |  58 +-------
 drivers/gpu/drm/drm_afbc.c                  | 114 ++++++++++++++++
 drivers/gpu/drm/rockchip/Kconfig            |   1 +
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  43 ++++++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 140 +++++++++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c |  86 +++++++++++-
 include/drm/drm_afbc.h                      |  25 ++++
 11 files changed, 427 insertions(+), 58 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
Signature · 1 line
2.17.1
#1 lore raw

PATCH 1/2 drm/arm: Factor out generic afbc helpers

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Kconfig          |   4 ++
 drivers/gpu/drm/Makefile         |   1 +
 drivers/gpu/drm/arm/Kconfig      |   1 +
 drivers/gpu/drm/arm/malidp_drv.c |  58 ++--------------
 drivers/gpu/drm/drm_afbc.c       | 114 +++++++++++++++++++++++++++++++
 include/drm/drm_afbc.h           |  25 +++++++
 6 files changed, 149 insertions(+), 54 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Kconfig +4 -0
index 3c88420e3497..00e3f90557f4 100644
@@ -195,6 +195,10 @@ config DRM_SCHED
 	tristate
 	depends on DRM
 
+config DRM_AFBC
+	tristate
+	depends on DRM
+
 source "drivers/gpu/drm/i2c/Kconfig"
 
 source "drivers/gpu/drm/arm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 9f0d2ee35794..55368b668355 100644
@@ -31,6 +31,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_AFBC) += drm_afbc.o
 
 drm_vram_helper-y := drm_gem_vram_helper.o \
 		     drm_vram_helper_common.o \
drivers/gpu/drm/arm/Kconfig +1 -0
index a204103b3efb..25c3dc408cda 100644
@@ -29,6 +29,7 @@ config DRM_MALI_DISPLAY
 	select DRM_KMS_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_GEM_CMA_HELPER
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you want to compile the ARM Mali Display
drivers/gpu/drm/arm/malidp_drv.c +4 -54

95 lines not on this page · raw message

drivers/gpu/drm/drm_afbc.c new file +114 -0

114 lines not on this page · raw message

include/drm/drm_afbc.h new file +25 -0
new file mode 100644
index 000000000000..ce39c850217b
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_fb_size(struct drm_device *dev,
+			    const struct drm_mode_fb_cmd2 *mode_cmd,
+			    struct drm_gem_object *objs, int bpp);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 1 line
2.17.1
#2 lore raw

Re: [PATCH 1/2] drm/arm: Factor out generic afbc helpers

Quoted 3 lines · Andrzej Pietrasiewicz

These are useful for other users of afbc, e.g. rockchip.

Hi Andrzej,

Thanks a lot for doing this. Much appreciated. :)
It was on our TODO list for a long time.

I have cc-ed [email protected], [email protected] for their comments as well.

Quoted 16 lines
---
 drivers/gpu/drm/Kconfig          |   4 ++
 drivers/gpu/drm/Makefile         |   1 +
 drivers/gpu/drm/arm/Kconfig      |   1 +
 drivers/gpu/drm/arm/malidp_drv.c |  58 ++--------------
 drivers/gpu/drm/drm_afbc.c       | 114 +++++++++++++++++++++++++++++++
 include/drm/drm_afbc.h           |  25 +++++++
 6 files changed, 149 insertions(+), 54 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Kconfig +0 -0
index 3c88420e3497..00e3f90557f4 100644

drivers/gpu/drm/Kconfig config DRM_SCHED · line 200

Quoted 6 lines
drivers/gpu/drm/Kconfig +3 -0
@@ -195,6 +195,10 @@ config DRM_SCHED
 	tristate
 	depends on DRM
 
+config DRM_AFBC
+	tristate
+	depends on DRM

Adding a 'help' would be great here. Stealing the first line from
https://www.kernel.org/doc/html/latest/gpu/afbc.html

"AFBC is a proprietary lossless image compression protocol and format. It provides fine-grained random access and minimizes the amount of data transferred between IP blocks."

Quoted 121 lines
drivers/gpu/drm/Kconfig +1 -0
+
 source "drivers/gpu/drm/i2c/Kconfig"
 
 source "drivers/gpu/drm/arm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 9f0d2ee35794..55368b668355 100644
@@ -31,6 +31,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_AFBC) += drm_afbc.o
 
 drm_vram_helper-y := drm_gem_vram_helper.o \
 		     drm_vram_helper_common.o \
drivers/gpu/drm/arm/Kconfig +1 -0
index a204103b3efb..25c3dc408cda 100644
@@ -29,6 +29,7 @@ config DRM_MALI_DISPLAY
 	select DRM_KMS_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_GEM_CMA_HELPER
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you want to compile the ARM Mali Display
drivers/gpu/drm/arm/malidp_drv.c +3 -51
index f25ec4382277..a67b69e08f63 100644
@@ -16,6 +16,7 @@
 #include <linux/debugfs.h>
 
 #include <drm/drmP.h>
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
@@ -33,8 +34,6 @@
 #include "malidp_hw.h"
 
 #define MALIDP_CONF_VALID_TIMEOUT	250
-#define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 
 static void malidp_write_gamma_table(struct malidp_hw_device *hwdev,
 				     u32 data[MALIDP_COEFFTAB_NUM_COEFFS])
@@ -275,24 +274,8 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
 					mode_cmd->modifier[0]) == false)
 		return false;
 
-	if (mode_cmd->offsets[0] != 0) {
-		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
-		return false;
-	}
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
-			DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n");
-			return false;
-		}
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
-
-	return true;
+	return drm_afbc_check_offset(dev, mode_cmd) &&
+	       drm_afbc_check_size_align(dev, mode_cmd);
 }
 
 static bool
@@ -300,53 +283,20 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
 				    struct drm_file *file,
 				    const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	int n_superblocks = 0;
 	const struct drm_format_info *info;
 	struct drm_gem_object *objs = NULL;
-	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
-	u32 afbc_superblock_width = 0, afbc_size = 0;
 	int bpp = 0;
 
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		afbc_superblock_height = 16;
-		afbc_superblock_width = 16;
-		break;
-	default:
-		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
-		return false;
-	}
-
 	info = drm_get_format_info(dev, mode_cmd);
-
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
-
 	bpp = malidp_format_get_bpp(info->format);
 
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
-
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
-
-	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
-		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
-			      "should be same as width (=%u) * bpp (=%u)\n",
-			      (mode_cmd->pitches[0] * BITS_PER_BYTE),
-			      mode_cmd->width, bpp);
-		return false;
-	}
-
 	objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!objs) {
 		DRM_DEBUG_KMS("Failed to lookup GEM object\n");

drivers/gpu/drm/arm/malidp_drv.c malidp_verify_afbc_framebuffer_size(struct drm_device *dev, · line 302

Quoted 10 lines
drivers/gpu/drm/arm/malidp_drv.c +1 -3
 		return false;
 	}
 
-	if (objs->size < afbc_size) {
-		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
-			      objs->size, afbc_size);
+	if (!drm_afbc_check_fb_size(dev, mode_cmd, objs, bpp)) {
 		drm_gem_object_put_unlocked(objs);
 		return false;
 	}

Also can you do the code refactoring for komeda driver as well. specifically komeda_fb_afbc_size_check(). I will let [email protected] and [email protected] have their opinion on this.

Quoted 69 lines
drivers/gpu/drm/drm_afbc.c new file +63 -0
new file mode 100644
index 000000000000..3e8a9225fd2e
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#include <linux/module.h>
+
+#include <drm/drm_afbc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_print.h>
+
+#define AFBC_HEADER_SIZE		16
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	if (mode_cmd->offsets[0] != 0) {
+		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+
+	switch (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
+			DRM_DEBUG_KMS(
+				"AFBC buffer must be aligned to 16 pixels\n"
+			);
+			return false;
+		}
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_size_align);
+
+bool drm_afbc_check_fb_size(struct drm_device *dev,
+			    const struct drm_mode_fb_cmd2 *mode_cmd,
+			    struct drm_gem_object *objs, int bpp)
+{

drivers/gpu/drm/drm_afbc.c line 73

Quoted 10 lines
drivers/gpu/drm/drm_afbc.c new file +10 -0
+	int n_superblocks = 0;
+	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
+	u32 afbc_superblock_width = 0, afbc_size = 0;
+
+	switch (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		afbc_superblock_height = 16;
+		afbc_superblock_width = 16;
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:

Copying from
https://cgit.freedesktop.org/drm/drm-tip/tree/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c#n60

                afbc_superblock_width = 32;
                afbc_superblock_height = 8;

drivers/gpu/drm/drm_afbc.c line 82

Quoted 9 lines
drivers/gpu/drm/drm_afbc.c new file +9 -0
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
+		return false;
+	}

Can you combine the two switch - case confitions (from this function and the one in drm_afbc_check_size_align()) and put it in a separate function (say drm_afbc_get_superblock_dimensions()) of its own ? This will help to avoid code repetition.

Quoted 66 lines
drivers/gpu/drm/drm_afbc.c new file +32 -0
+
+	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;
+
+	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE,
+			  AFBC_SUPERBLK_ALIGNMENT);
+	afbc_size += n_superblocks *
+		ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
+
+	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) should be same as width (=%u) * bpp (=%u)\n",
+			mode_cmd->pitches[0] * BITS_PER_BYTE,
+			mode_cmd->width, bpp
+		);
+		return false;
+	}
+
+	if (objs->size < afbc_size) {
+		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+			objs->size, afbc_size
+		);
+
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size);
include/drm/drm_afbc.h new file +25 -1
new file mode 100644
index 000000000000..ce39c850217b
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_fb_size(struct drm_device *dev,
+			    const struct drm_mode_fb_cmd2 *mode_cmd,
+			    struct drm_gem_object *objs, int bpp);
+
+#endif /* __DRM_AFBC_H__ */
--

2.17.1

Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#3 lore raw

Re: [PATCH 1/2] drm/arm: Factor out generic afbc helpers

Hi Andrzej,

Quoted 9 lines · On Monday, 21 October 2019 14:50:14 BST Ayan Halder wrote:
Quoted 3 lines · Andrzej Pietrasiewicz

These are useful for other users of afbc, e.g. rockchip.

Hi Andrzej,

Thanks a lot for doing this. Much appreciated. :)
It was on our TODO list for a long time.

Seconded, thanks for the patch!

Quoted 57 lines

I have cc-ed [email protected], [email protected] for their comments as well.

Quoted 16 lines
---
 drivers/gpu/drm/Kconfig          |   4 ++
 drivers/gpu/drm/Makefile         |   1 +
 drivers/gpu/drm/arm/Kconfig      |   1 +
 drivers/gpu/drm/arm/malidp_drv.c |  58 ++--------------
 drivers/gpu/drm/drm_afbc.c       | 114 +++++++++++++++++++++++++++++++
 include/drm/drm_afbc.h           |  25 +++++++
 6 files changed, 149 insertions(+), 54 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Kconfig +0 -0
index 3c88420e3497..00e3f90557f4 100644

drivers/gpu/drm/Kconfig config DRM_SCHED · line 200

Quoted 6 lines
drivers/gpu/drm/Kconfig +3 -0
@@ -195,6 +195,10 @@ config DRM_SCHED
 	tristate
 	depends on DRM
 
+config DRM_AFBC
+	tristate
+	depends on DRM

Adding a 'help' would be great here. Stealing the first line from
https://www.kernel.org/doc/html/latest/gpu/afbc.html

"AFBC is a proprietary lossless image compression protocol and format. It provides fine-grained random access and minimizes the amount of data transferred between IP blocks."

Quoted 24 lines
drivers/gpu/drm/Kconfig +1 -0
+
 source "drivers/gpu/drm/i2c/Kconfig"
 
 source "drivers/gpu/drm/arm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 9f0d2ee35794..55368b668355 100644
@@ -31,6 +31,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_AFBC) += drm_afbc.o
 
 drm_vram_helper-y := drm_gem_vram_helper.o \
 		     drm_vram_helper_common.o \
drivers/gpu/drm/arm/Kconfig +0 -0
index a204103b3efb..25c3dc408cda 100644
@@ -29,6 +29,7 @@ config DRM_MALI_DISPLAY
 	select DRM_KMS_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_GEM_CMA_HELPER
Quoted 8 lines

drivers/gpu/drm/arm/malidp_drv.c

Quoted 8 lines
drivers/gpu/drm/arm/Kconfig +1 -0
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you want to compile the ARM Mali Display
drivers/gpu/drm/arm/malidp_drv.c +0 -0
index f25ec4382277..a67b69e08f63 100644

This file is GPL-2.0-only. Shouldn't this be preserved when the substantive bit of the code in drm_afbc.c comes from here?

Quoted 92 lines
Quoted 92 lines
drivers/gpu/drm/arm/malidp_drv.c +3 -51
@@ -16,6 +16,7 @@
 #include <linux/debugfs.h>
 
 #include <drm/drmP.h>
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
@@ -33,8 +34,6 @@
 #include "malidp_hw.h"
 
 #define MALIDP_CONF_VALID_TIMEOUT	250
-#define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 
 static void malidp_write_gamma_table(struct malidp_hw_device *hwdev,
 				     u32 data[MALIDP_COEFFTAB_NUM_COEFFS])
@@ -275,24 +274,8 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
 					mode_cmd->modifier[0]) == false)
 		return false;
 
-	if (mode_cmd->offsets[0] != 0) {
-		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
-		return false;
-	}
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
-			DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n");
-			return false;
-		}
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
-
-	return true;
+	return drm_afbc_check_offset(dev, mode_cmd) &&
+	       drm_afbc_check_size_align(dev, mode_cmd);
 }
 
 static bool
@@ -300,53 +283,20 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
 				    struct drm_file *file,
 				    const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	int n_superblocks = 0;
 	const struct drm_format_info *info;
 	struct drm_gem_object *objs = NULL;
-	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
-	u32 afbc_superblock_width = 0, afbc_size = 0;
 	int bpp = 0;
 
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		afbc_superblock_height = 16;
-		afbc_superblock_width = 16;
-		break;
-	default:
-		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
-		return false;
-	}
-
 	info = drm_get_format_info(dev, mode_cmd);
-
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
-
 	bpp = malidp_format_get_bpp(info->format);
 
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
-
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
-
-	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
-		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
-			      "should be same as width (=%u) * bpp (=%u)\n",
-			      (mode_cmd->pitches[0] * BITS_PER_BYTE),
-			      mode_cmd->width, bpp);
-		return false;
-	}
-
 	objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!objs) {
 		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
 		return false;
 	}
 
Quoted 11 lines

drivers/gpu/drm/arm/malidp_drv.c malidp_verify_afbc_framebuffer_size(struct drm_device *dev, · line 302

Quoted 7 lines
drivers/gpu/drm/arm/malidp_drv.c +1 -3
-	if (objs->size < afbc_size) {
-		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
-			      objs->size, afbc_size);
+	if (!drm_afbc_check_fb_size(dev, mode_cmd, objs, bpp)) {
 		drm_gem_object_put_unlocked(objs);
 		return false;
 	}

Also can you do the code refactoring for komeda driver as well. specifically komeda_fb_afbc_size_check(). I will let [email protected] and [email protected] have their opinion on this.

I'd say that it'd be really nice to get this work done for us ;) but it doesn't have to be in this patch but rather in a follow-up.

Quoted 84 lines
Quoted 70 lines
drivers/gpu/drm/drm_afbc.c new file +63 -0
new file mode 100644
index 000000000000..3e8a9225fd2e
@@ -0,0 +1,114 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#include <linux/module.h>
+
+#include <drm/drm_afbc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_print.h>
+
+#define AFBC_HEADER_SIZE		16
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	if (mode_cmd->offsets[0] != 0) {
+		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+
+	switch (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
+			DRM_DEBUG_KMS(
+				"AFBC buffer must be aligned to 16 pixels\n"
+			);
+			return false;
+		}
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_size_align);
+
+bool drm_afbc_check_fb_size(struct drm_device *dev,
+			    const struct drm_mode_fb_cmd2 *mode_cmd,
+			    struct drm_gem_object *objs, int bpp)
+{

drivers/gpu/drm/drm_afbc.c line 73

Quoted 10 lines
drivers/gpu/drm/drm_afbc.c new file +10 -0
+	int n_superblocks = 0;
+	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
+	u32 afbc_superblock_width = 0, afbc_size = 0;
+
+	switch (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		afbc_superblock_height = 16;
+		afbc_superblock_width = 16;
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:

Copying from
https://cgit.freedesktop.org/drm/drm-tip/tree/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c#n60

                afbc_superblock_width = 32;
                afbc_superblock_height = 8;
Quoted 14 lines

drivers/gpu/drm/drm_afbc.c line 82

Quoted 9 lines
drivers/gpu/drm/drm_afbc.c new file +9 -0
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
+		return false;
+	}

Can you combine the two switch - case confitions (from this function and the one in drm_afbc_check_size_align()) and put it in a separate function (say drm_afbc_get_superblock_dimensions()) of its own ? This will help to avoid code repetition.

I'm personally a bit on the fence about this - functions should ideally do one thing. That shared helper would be both getting the dimensions _and_ checking the mode_cmd is valid, so one place cares about one half of the function's results, and the other - the second half. ¯\_O_/¯, opinions, everybody has them :).

Quoted 66 lines
Quoted 66 lines
drivers/gpu/drm/drm_afbc.c new file +32 -0
+
+	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;
+
+	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE,
+			  AFBC_SUPERBLK_ALIGNMENT);
+	afbc_size += n_superblocks *
+		ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
+
+	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) should be same as width (=%u) * bpp (=%u)\n",
+			mode_cmd->pitches[0] * BITS_PER_BYTE,
+			mode_cmd->width, bpp
+		);
+		return false;
+	}
+
+	if (objs->size < afbc_size) {
+		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+			objs->size, afbc_size
+		);
+
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size);
include/drm/drm_afbc.h new file +25 -1
new file mode 100644
index 000000000000..ce39c850217b
@@ -0,0 +1,25 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_fb_size(struct drm_device *dev,
+			    const struct drm_mode_fb_cmd2 *mode_cmd,
+			    struct drm_gem_object *objs, int bpp);
+
+#endif /* __DRM_AFBC_H__ */
--

2.17.1

Quoted 5 lines
Quoted 4 lines

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

Overall the patch LGTM as-is, nice and straightforward mostly-cut-n-paste, just let's sort out the SPDX identifier question I have, then I'll be happy.

Signature · 8 lines
Mihail



_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#4 lore raw

v2 cover AFBC support for Rockchip

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

The first patch factors out some afbc helper functions, as they are useful in general. The second and third patches use the helpers and the fourth patch adds implementation proper of AFBC support for Rockchip.

v1..v2:

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

Andrzej Pietrasiewicz (4):
drm/arm: Factor out generic afbc helpers
drm/malidp: use afbc helpers
drm/komeda: use afbc helpers
drm/rockchip: Add support for afbc

 drivers/gpu/drm/Kconfig                       |   8 +
 drivers/gpu/drm/Makefile                      |   1 +
 drivers/gpu/drm/arm/Kconfig                   |   1 +
 .../arm/display/komeda/komeda_format_caps.h   |   1 -
 .../arm/display/komeda/komeda_framebuffer.c   |  44 +++---
 drivers/gpu/drm/arm/malidp_drv.c              |  66 ++------
 drivers/gpu/drm/drm_afbc.c                    | 129 ++++++++++++++++
 drivers/gpu/drm/rockchip/Kconfig              |   1 +
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c    |  42 ++++++
 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_afbc.h                        |  36 +++++
 13 files changed, 480 insertions(+), 86 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#5 lore raw

PATCH v2 1/4 drm/arm: Factor out generic afbc helpers

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Kconfig     |   8 +++
 drivers/gpu/drm/Makefile    |   1 +
 drivers/gpu/drm/arm/Kconfig |   1 +
 drivers/gpu/drm/drm_afbc.c  | 129 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_afbc.h      |  36 ++++++++++
 5 files changed, 175 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Kconfig +8 -0
index 36357a36a281..ae1ca5e02bfe 100644
@@ -205,6 +205,14 @@ config DRM_SCHED
 	tristate
 	depends on DRM
 
+config DRM_AFBC
+	tristate
+	depends on DRM
+	help
+	  AFBC is a proprietary lossless image compression protocol and format.
+	  It provides fine-grained random access and minimizes the amount of
+	  data transferred between IP blocks.
+
 source "drivers/gpu/drm/i2c/Kconfig"
 
 source "drivers/gpu/drm/arm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 9f1c7c486f88..3a5d092ea514 100644
@@ -31,6 +31,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_AFBC) += drm_afbc.o
 
 drm_vram_helper-y := drm_gem_vram_helper.o \
 		     drm_vram_helper_common.o
drivers/gpu/drm/arm/Kconfig +1 -0
index a204103b3efb..25c3dc408cda 100644
@@ -29,6 +29,7 @@ config DRM_MALI_DISPLAY
 	select DRM_KMS_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_GEM_CMA_HELPER
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you want to compile the ARM Mali Display
drivers/gpu/drm/drm_afbc.c new file +129 -0

129 lines not on this page · raw message

include/drm/drm_afbc.h new file +36 -0
new file mode 100644
index 000000000000..b28ae2849f96
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+#include <linux/types.h>
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size);
+
+bool drm_afbc_check_fb_size(u32 pitch, int bpp,
+			    u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+			    size_t size, u32 offset, u32 hdr_align);
+
+bool drm_afbc_get_superblk_wh(u64 modifier, u32 *w, u32 *h);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#6 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Quoted 18 lines · Andrzej Pietrasiewicz

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Kconfig     |   8 +++
 drivers/gpu/drm/Makefile    |   1 +
 drivers/gpu/drm/arm/Kconfig |   1 +
 drivers/gpu/drm/drm_afbc.c  | 129 ++++++++++++++++++++++++++++++++++++
 include/drm/drm_afbc.h      |  36 ++++++++++
 5 files changed, 175 insertions(+)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Kconfig +0 -0
index 36357a36a281..ae1ca5e02bfe 100644

drivers/gpu/drm/Kconfig config DRM_SCHED · line 214

Quoted 10 lines
drivers/gpu/drm/Kconfig +7 -0
@@ -205,6 +205,14 @@ config DRM_SCHED
 	tristate
 	depends on DRM
 
+config DRM_AFBC
+	tristate
+	depends on DRM
+	help
+	  AFBC is a proprietary lossless image compression protocol and format.
+	  It provides fine-grained random access and minimizes the amount of
+	  data transferred between IP blocks.

Uh a module option for 2 functions ... seems like massive overkill. Please just put that into existing format helpers instead.

What's missing otoh is kernel doc for these.

Quoted 153 lines
drivers/gpu/drm/Kconfig +1 -0
+
 source "drivers/gpu/drm/i2c/Kconfig"
 
 source "drivers/gpu/drm/arm/Kconfig"
drivers/gpu/drm/Makefile +1 -0
index 9f1c7c486f88..3a5d092ea514 100644
@@ -31,6 +31,7 @@ drm-$(CONFIG_OF) += drm_of.o
 drm-$(CONFIG_AGP) += drm_agpsupport.o
 drm-$(CONFIG_DEBUG_FS) += drm_debugfs.o drm_debugfs_crc.o
 drm-$(CONFIG_DRM_LOAD_EDID_FIRMWARE) += drm_edid_load.o
+drm-$(CONFIG_DRM_AFBC) += drm_afbc.o
 
 drm_vram_helper-y := drm_gem_vram_helper.o \
 		     drm_vram_helper_common.o
drivers/gpu/drm/arm/Kconfig +1 -0
index a204103b3efb..25c3dc408cda 100644
@@ -29,6 +29,7 @@ config DRM_MALI_DISPLAY
 	select DRM_KMS_HELPER
 	select DRM_KMS_CMA_HELPER
 	select DRM_GEM_CMA_HELPER
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	help
 	  Choose this option if you want to compile the ARM Mali Display
drivers/gpu/drm/drm_afbc.c new file +119 -0
new file mode 100644
index 000000000000..010ca9eb0480
@@ -0,0 +1,129 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#include <linux/module.h>
+
+#include <drm/drm_afbc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_print.h>
+
+#define AFBC_HEADER_SIZE		16
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	if (mode_cmd->offsets[0] != 0) {
+		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	switch (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
+			DRM_DEBUG_KMS(
+				"AFBC buffer must be aligned to 16 pixels\n"
+			);
+			return false;
+		}
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4:
+		/* fall through */
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4:
+		/* fall through */
+	default:
+		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_size_align);
+
+bool drm_afbc_get_superblk_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_superblk_wh);
+
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size)
+{
+	int n_superblks = 0;
+	u32 superblk_sz = 0;
+	u32 afbc_size = 0;
+
+	n_superblks = (w / superblk_w) * (h / superblk_h);
+	superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+	afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+	*payload_off = afbc_size;
+
+	afbc_size += n_superblks * ALIGN(superblk_sz, AFBC_SUPERBLK_ALIGNMENT);
+	*total_size = afbc_size + offset;
+
+	if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) should be same as width (=%u) * bpp (=%u)\n",
+			      pitch * BITS_PER_BYTE, w, bpp
+		);
+		return false;
+	}
+
+	if (size < afbc_size) {
+		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+			      size, afbc_size
+		);
+
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size_ret);
+
+bool drm_afbc_check_fb_size(u32 pitch, int bpp,
+			    u32 w, u32 h, u32 superblk_w, u32 superblk_h,

drivers/gpu/drm/drm_afbc.c line 129

Quoted 10 lines
drivers/gpu/drm/drm_afbc.c new file +10 -0
+			    size_t size, u32 offset, u32 hdr_align)
+{
+	u32 payload_offset, total_size;
+
+	return drm_afbc_check_fb_size_ret(pitch, bpp, w, h,
+					  superblk_w, superblk_h,
+					  size, offset, hdr_align,
+					  &payload_offset, &total_size);
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size);

Why don't we have one overall "check afbc parameters against buffer" function?

Also would be kinda neat if we could wire up that check code directly into core addfb2 code, since afbc is a cross driver standard, everyone will have to use the same code. Doing it that way would also solve your kerneldoc need (since core code checks it directly). We already have an example for the tiled nv12 format, which is also checked in core.

Cheers, Daniel

Quoted 45 lines
include/drm/drm_afbc.h new file +36 -0
new file mode 100644
index 000000000000..b28ae2849f96
@@ -0,0 +1,36 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+#include <linux/types.h>
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd);
+
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size);
+
+bool drm_afbc_check_fb_size(u32 pitch, int bpp,
+			    u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+			    size_t size, u32 offset, u32 hdr_align);
+
+bool drm_afbc_get_superblk_wh(u64 modifier, u32 *w, u32 *h);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#7 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Hi Daniel,

Thank you for review,

W dniu 05.11.2019 o 10:22, Daniel Vetter pisze:

Quoted 3 lines · Andrzej Pietrasiewicz
Quoted 2 lines

These are useful for other users of afbc, e.g. rockchip.

<snip>

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/drm_afbc.c new file +44 -0
+
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size)
+{
+	int n_superblks = 0;
+	u32 superblk_sz = 0;
+	u32 afbc_size = 0;
+
+	n_superblks = (w / superblk_w) * (h / superblk_h);
+	superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+	afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+	*payload_off = afbc_size;
+
+	afbc_size += n_superblks * ALIGN(superblk_sz, AFBC_SUPERBLK_ALIGNMENT);
+	*total_size = afbc_size + offset;
+
+	if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) should be same as width (=%u) * bpp (=%u)\n",
+			      pitch * BITS_PER_BYTE, w, bpp
+		);
+		return false;
+	}
+
+	if (size < afbc_size) {
+		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+			      size, afbc_size
+		);
+
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size_ret);
+
+bool drm_afbc_check_fb_size(u32 pitch, int bpp,
+			    u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+			    size_t size, u32 offset, u32 hdr_align)
+{
+	u32 payload_offset, total_size;
+
+	return drm_afbc_check_fb_size_ret(pitch, bpp, w, h,
Quoted 9 lines

drivers/gpu/drm/drm_afbc.c line 129

Quoted 5 lines
drivers/gpu/drm/drm_afbc.c new file +5 -0
+					  superblk_w, superblk_h,
+					  size, offset, hdr_align,
+					  &payload_offset, &total_size);
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size);

Why don't we have one overall "check afbc parameters against buffer" function?

I noticed that different drivers have different needs (malidp and rockchip are kind of similar, but komeda is a bit different). That is why the helpers are only building blocks out of which each driver builds its own checking logic. In particular komeda wants some by-products of the check stored in its internal data structures, hence drm_afbc_check_fb_size_ret() and its wrapper drm_afbc_check_fb_size() which ignores the "out" parameters.

If I wanted to create one overall "check afbc parameters" I'd have to come up with a way to pass driver-specific requirements to it and then inside the function have some logic to decide what to check against what. Do you think it is worth it?

Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#8 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Quoted 73 lines · Andrzej Pietrasiewicz

Hi Daniel,

Thank you for review,

W dniu 05.11.2019 o 10:22, Daniel Vetter pisze:

Quoted 3 lines · Andrzej Pietrasiewicz
Quoted 2 lines

These are useful for other users of afbc, e.g. rockchip.

<snip>

Quoted 44 lines
Quoted 44 lines
drivers/gpu/drm/drm_afbc.c new file +44 -0
+
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size)
+{
+	int n_superblks = 0;
+	u32 superblk_sz = 0;
+	u32 afbc_size = 0;
+
+	n_superblks = (w / superblk_w) * (h / superblk_h);
+	superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+	afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+	*payload_off = afbc_size;
+
+	afbc_size += n_superblks * ALIGN(superblk_sz, AFBC_SUPERBLK_ALIGNMENT);
+	*total_size = afbc_size + offset;
+
+	if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) should be same as width (=%u) * bpp (=%u)\n",
+			      pitch * BITS_PER_BYTE, w, bpp
+		);
+		return false;
+	}
+
+	if (size < afbc_size) {
+		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
+			      size, afbc_size
+		);
+
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size_ret);
+
+bool drm_afbc_check_fb_size(u32 pitch, int bpp,
+			    u32 w, u32 h, u32 superblk_w, u32 superblk_h,
+			    size_t size, u32 offset, u32 hdr_align)
+{
+	u32 payload_offset, total_size;
+
+	return drm_afbc_check_fb_size_ret(pitch, bpp, w, h,
Quoted 9 lines

drivers/gpu/drm/drm_afbc.c line 129

Quoted 5 lines
drivers/gpu/drm/drm_afbc.c new file +5 -0
+					  superblk_w, superblk_h,
+					  size, offset, hdr_align,
+					  &payload_offset, &total_size);
+}
+EXPORT_SYMBOL(drm_afbc_check_fb_size);

Why don't we have one overall "check afbc parameters against buffer" function?

I noticed that different drivers have different needs (malidp and rockchip are kind of similar, but komeda is a bit different). That is why the helpers are only building blocks out of which each driver builds its own checking logic. In particular komeda wants some by-products of the check stored in its internal data structures, hence drm_afbc_check_fb_size_ret() and its wrapper drm_afbc_check_fb_size() which ignores the "out" parameters.

Quoted 4 lines

If I wanted to create one overall "check afbc parameters" I'd have to come up with a way to pass driver-specific requirements to it and then inside the function have some logic to decide what to check against what. Do you think it is worth it?

Hm I figured there's at least two parts of this:
- Generic checking of afbc against the fb parameters, i.e. is it big enough, correctly aligned, all that.
- Additional driver checks, which might need some of the same parameters again.

The idea behind asking for the first part is that maybe we should put that into the core as part of the addfb checks (like we do for the tiled NV12 thing already). Then drivers only need to do additional checks on top for their specific constraints. For that you could expose some helpers ofc (to get the payload_offset and anything else computed you might need).

But the basic drm_afbc_check_fb_size() should imo be done unconditionally for any afbc modifier. To make sure we don't have lots of drivers with different bugs in that thing.
-Daniel

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#9 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

In reply to Andrzej Pietrasiewicz

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	if (mode_cmd->offsets[0] != 0) {
+		DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

drivers/gpu/drm/drm_afbc.c line 44

Quoted 9 lines
(quoted diff) +2 -0
+			DRM_DEBUG_KMS(
+				"AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+			);
+			return false;
+		}
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		/* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size)
+{
+	int n_superblks = 0;
+	u32 superblk_sz = 0;
+	u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

drivers/gpu/drm/drm_afbc.c line 97

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+	n_superblks = (w / superblk_w) * (h / superblk_h);
+	superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+	afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+	*payload_off = afbc_size;
+
+	afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);

drivers/gpu/drm/drm_afbc.c new file +1 -0
+	*total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+	if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+			      pitch * BITS_PER_BYTE, w, bpp
+		);
+		return false;
+	}

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

Cheers,
Daniel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

maintainer
#10 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Hi Andrzej,

Quoted 35 lines · Daniel Stone

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+			   const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	if (mode_cmd->offsets[0] != 0) {
+		DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+		return false;
+	}
+
+	return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+			       const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+	switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+		if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

Quoted 2 lines

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

I agree with Daniel, for AFBC_FORMAT_MOD_BLOCK_SIZE_xxxx you need to check that the allocated framebuffer's width and height are divisible by block size, not what the resolution of the mode is.

Best regards,
Liviu

Quoted 73 lines

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

drivers/gpu/drm/drm_afbc.c line 44

Quoted 9 lines
(quoted diff) +2 -0
+			DRM_DEBUG_KMS(
+				"AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+			);
+			return false;
+		}
+		break;
+	case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+		/* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+				u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+				size_t size, u32 offset, u32 hdr_align,
+				u32 *payload_off, u32 *total_size)
+{
+	int n_superblks = 0;
+	u32 superblk_sz = 0;
+	u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

drivers/gpu/drm/drm_afbc.c line 97

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+	n_superblks = (w / superblk_w) * (h / superblk_h);
+	superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+	afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+	*payload_off = afbc_size;
+
+	afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);

drivers/gpu/drm/drm_afbc.c new file +1 -0
+	*total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+	if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+			      pitch * BITS_PER_BYTE, w, bpp
+		);
+		return false;
+	}

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

Cheers,
Daniel

Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#11 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

In reply to Daniel Stone

Hi Daniel,

Quoted 44 lines · Daniel Stone

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+                      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   if (mode_cmd->offsets[0] != 0) {
+           DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+           return false;
+   }
+
+   return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+                          const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+           if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

Quoted 3 lines

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

Well, sort of.

I agree with you that for horizontal padding, we can indeed use pitch.

However, the AFBC decoder(s) need to know exactly what the total _allocated_ size in pixels of the buffer is - as this influences the header size, and we need to know the header size to know where it ends and the body begins.

I see a couple of possible ways forwards:

- Keep it as-is. The restrictive checks ensure that there's no ambiguity and we use the fb width/height to determine the real allocated width/height. Userspace needs to be AFBC-aware and set up plane cropping to handle the alignment differences.

- Use pitch to determine the "real" width, and internally in the kernel align height up to the next alignment boundary. This works OK, so long as there's no additional padding at the bottom of the buffer. This would work, but I can't figure a way to check/enforce that there's no additional padding at the bottom.

- Something else...

The checks as-implemented were deliberately conservative, and don't preclude doing some relaxation in the future.

On Android, gralloc is used to store the "real" allocated width/height and this is used to set up the DRM API appropriately.

Quoted 3 lines

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

Well, nothing's going to get broken - it's just perhaps not ready to turn on AFBC yet.

Quoted 51 lines

drivers/gpu/drm/drm_afbc.c line 44

Quoted 10 lines
(quoted diff) +2 -0
+                   DRM_DEBUG_KMS(
+                           "AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                   );
+                   return false;
+           }
+           break;
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+           /* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+                           u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                           size_t size, u32 offset, u32 hdr_align,
+                           u32 *payload_off, u32 *total_size)
+{
+   int n_superblks = 0;
+   u32 superblk_sz = 0;
+   u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+   n_superblks = (w / superblk_w) * (h / superblk_h);
+   superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+   afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+   *payload_off = afbc_size;
+
+   afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);
+ *total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+   if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+           DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+                         pitch * BITS_PER_BYTE, w, bpp
+           );
+           return false;
+   }
Quoted 5 lines

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

The reason for forcing it to be exact is as I said above - we _must_ know what the "real" width and height is. Implementing this check to force (pitch == width * bpp) ensures that, and also leaves the option for us to relax to allow a larger pitch (as above) if that was the preferred approach for alignment.

In general the current checks are deliberately designed to leave the door open for future improvements without breaking anything.

Cheers,
-Brian

Quoted 4 lines

Cheers,
Daniel

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#12 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Quoted 74 lines · Brian Starkey

Hi Daniel,

Quoted 44 lines · Daniel Stone

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+                      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   if (mode_cmd->offsets[0] != 0) {
+           DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+           return false;
+   }
+
+   return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+                          const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+           if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

Quoted 3 lines

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

Well, sort of.

I agree with you that for horizontal padding, we can indeed use pitch.

However, the AFBC decoder(s) need to know exactly what the total _allocated_ size in pixels of the buffer is - as this influences the header size, and we need to know the header size to know where it ends and the body begins.

I see a couple of possible ways forwards:

- Keep it as-is. The restrictive checks ensure that there's no ambiguity and we use the fb width/height to determine the real allocated width/height. Userspace needs to be AFBC-aware and set up plane cropping to handle the alignment differences.

- Use pitch to determine the "real" width, and internally in the kernel align height up to the next alignment boundary. This works OK, so long as there's no additional padding at the bottom of the buffer. This would work, but I can't figure a way to check/enforce that there's no additional padding at the bottom.

Quoted 7 lines

- Something else...

The checks as-implemented were deliberately conservative, and don't preclude doing some relaxation in the future.

On Android, gralloc is used to store the "real" allocated width/height and this is used to set up the DRM API appropriately.

Fake stride + real visible h/w in the drmfb. Because that's how it works with all the tiled formats already, and expecting userspace to fudge this all correctly seems very backwards to me. In a way we had that entire fake stride discussion already for the block size format stuff already, but now in a different flavour.

Also I think that's more reasons why this should be no-opt-outable code that's done for all drivers when we check framebuffers in addfb. Plus then some helpers to get at computed values for any framebuffer we know to be valid.
-Daniel

Quoted 80 lines
Quoted 2 lines

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

Well, nothing's going to get broken - it's just perhaps not ready to turn on AFBC yet.

Quoted 51 lines

drivers/gpu/drm/drm_afbc.c line 44

Quoted 10 lines
(quoted diff) +2 -0
+                   DRM_DEBUG_KMS(
+                           "AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                   );
+                   return false;
+           }
+           break;
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+           /* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+                           u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                           size_t size, u32 offset, u32 hdr_align,
+                           u32 *payload_off, u32 *total_size)
+{
+   int n_superblks = 0;
+   u32 superblk_sz = 0;
+   u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+   n_superblks = (w / superblk_w) * (h / superblk_h);
+   superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+   afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+   *payload_off = afbc_size;
+
+   afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);
+ *total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+   if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+           DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+                         pitch * BITS_PER_BYTE, w, bpp
+           );
+           return false;
+   }
Quoted 5 lines

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

The reason for forcing it to be exact is as I said above - we _must_ know what the "real" width and height is. Implementing this check to force (pitch == width * bpp) ensures that, and also leaves the option for us to relax to allow a larger pitch (as above) if that was the preferred approach for alignment.

In general the current checks are deliberately designed to leave the door open for future improvements without breaking anything.

Cheers,
-Brian

Quoted 4 lines

Cheers,
Daniel

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#13 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Hi Daniel,

Quoted 80 lines · Daniel Vetter
Quoted 79 lines · Brian Starkey

Hi Daniel,

Quoted 44 lines · Daniel Stone

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+                      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   if (mode_cmd->offsets[0] != 0) {
+           DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+           return false;
+   }
+
+   return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+                          const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+           if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

Quoted 3 lines

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

Well, sort of.

I agree with you that for horizontal padding, we can indeed use pitch.

However, the AFBC decoder(s) need to know exactly what the total _allocated_ size in pixels of the buffer is - as this influences the header size, and we need to know the header size to know where it ends and the body begins.

I see a couple of possible ways forwards:

- Keep it as-is. The restrictive checks ensure that there's no ambiguity and we use the fb width/height to determine the real allocated width/height. Userspace needs to be AFBC-aware and set up plane cropping to handle the alignment differences.

- Use pitch to determine the "real" width, and internally in the kernel align height up to the next alignment boundary. This works OK, so long as there's no additional padding at the bottom of the buffer. This would work, but I can't figure a way to check/enforce that there's no additional padding at the bottom.

- Something else...

The checks as-implemented were deliberately conservative, and don't preclude doing some relaxation in the future.

Quoted 8 lines
Quoted 2 lines

On Android, gralloc is used to store the "real" allocated width/height and this is used to set up the DRM API appropriately.

Fake stride + real visible h/w in the drmfb. Because that's how it works with all the tiled formats already, and expecting userspace to fudge this all correctly seems very backwards to me. In a way we had that entire fake stride discussion already for the block size format stuff already, but now in a different flavour.

Fake stride - like I said, no problem; sounds good. That solves one dimension.

So do you have a proposal for how we determine what the allocated height is in that case? I don't really see a way.

Thanks,
-Brian

Quoted 87 lines

Also I think that's more reasons why this should be no-opt-outable code that's done for all drivers when we check framebuffers in addfb. Plus then some helpers to get at computed values for any framebuffer we know to be valid.
-Daniel

Quoted 80 lines
Quoted 2 lines

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

Well, nothing's going to get broken - it's just perhaps not ready to turn on AFBC yet.

Quoted 51 lines

drivers/gpu/drm/drm_afbc.c line 44

Quoted 10 lines
(quoted diff) +2 -0
+                   DRM_DEBUG_KMS(
+                           "AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                   );
+                   return false;
+           }
+           break;
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+           /* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+                           u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                           size_t size, u32 offset, u32 hdr_align,
+                           u32 *payload_off, u32 *total_size)
+{
+   int n_superblks = 0;
+   u32 superblk_sz = 0;
+   u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+   n_superblks = (w / superblk_w) * (h / superblk_h);
+   superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+   afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+   *payload_off = afbc_size;
+
+   afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);
+ *total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+   if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+           DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+                         pitch * BITS_PER_BYTE, w, bpp
+           );
+           return false;
+   }
Quoted 5 lines

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

The reason for forcing it to be exact is as I said above - we _must_ know what the "real" width and height is. Implementing this check to force (pitch == width * bpp) ensures that, and also leaves the option for us to relax to allow a larger pitch (as above) if that was the preferred approach for alignment.

In general the current checks are deliberately designed to leave the door open for future improvements without breaking anything.

Cheers,
-Brian

Quoted 4 lines

Cheers,
Daniel

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Not sure how that snuck in.

Quoted 7 lines
Signature · 4 lines
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#14 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Quoted 92 lines · Brian Starkey

Hi Daniel,

Quoted 80 lines · Daniel Vetter
Quoted 79 lines · Brian Starkey

Hi Daniel,

Quoted 44 lines · Daniel Stone

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+                      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   if (mode_cmd->offsets[0] != 0) {
+           DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+           return false;
+   }
+
+   return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+                          const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+           if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

Quoted 3 lines

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

Well, sort of.

I agree with you that for horizontal padding, we can indeed use pitch.

However, the AFBC decoder(s) need to know exactly what the total _allocated_ size in pixels of the buffer is - as this influences the header size, and we need to know the header size to know where it ends and the body begins.

I see a couple of possible ways forwards:

- Keep it as-is. The restrictive checks ensure that there's no ambiguity and we use the fb width/height to determine the real allocated width/height. Userspace needs to be AFBC-aware and set up plane cropping to handle the alignment differences.

- Use pitch to determine the "real" width, and internally in the kernel align height up to the next alignment boundary. This works OK, so long as there's no additional padding at the bottom of the buffer. This would work, but I can't figure a way to check/enforce that there's no additional padding at the bottom.

- Something else...

The checks as-implemented were deliberately conservative, and don't preclude doing some relaxation in the future.

Quoted 8 lines
Quoted 2 lines

On Android, gralloc is used to store the "real" allocated width/height and this is used to set up the DRM API appropriately.

Fake stride + real visible h/w in the drmfb. Because that's how it works with all the tiled formats already, and expecting userspace to fudge this all correctly seems very backwards to me. In a way we had that entire fake stride discussion already for the block size format stuff already, but now in a different flavour.

Quoted 5 lines

Fake stride - like I said, no problem; sounds good. That solves one dimension.

So do you have a proposal for how we determine what the allocated height is in that case? I don't really see a way.

Could you compute the height by looking at the buffer size? Or does that not help since the header stuff is generally rather small?

Otherwise I guess just round up height and hope it works. If we run into a use-case where that doesn't work anymore somehow, then we get to rev all the afbc modifiers and make them 2 planes. With that there's no such issue anymore (which is why the intel compressed stuff has 2 planes). -Daniel

Quoted 100 lines

Thanks,
-Brian

Quoted 87 lines

Also I think that's more reasons why this should be no-opt-outable code that's done for all drivers when we check framebuffers in addfb. Plus then some helpers to get at computed values for any framebuffer we know to be valid.
-Daniel

Quoted 80 lines
Quoted 2 lines

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

Well, nothing's going to get broken - it's just perhaps not ready to turn on AFBC yet.

Quoted 51 lines

drivers/gpu/drm/drm_afbc.c line 44

Quoted 10 lines
(quoted diff) +2 -0
+                   DRM_DEBUG_KMS(
+                           "AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                   );
+                   return false;
+           }
+           break;
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+           /* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+                           u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                           size_t size, u32 offset, u32 hdr_align,
+                           u32 *payload_off, u32 *total_size)
+{
+   int n_superblks = 0;
+   u32 superblk_sz = 0;
+   u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+   n_superblks = (w / superblk_w) * (h / superblk_h);
+   superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+   afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+   *payload_off = afbc_size;
+
+   afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);
+ *total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+   if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+           DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+                         pitch * BITS_PER_BYTE, w, bpp
+           );
+           return false;
+   }
Quoted 5 lines

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

The reason for forcing it to be exact is as I said above - we _must_ know what the "real" width and height is. Implementing this check to force (pitch == width * bpp) ensures that, and also leaves the option for us to relax to allow a larger pitch (as above) if that was the preferred approach for alignment.

In general the current checks are deliberately designed to leave the door open for future improvements without breaking anything.

Cheers,
-Brian

Quoted 4 lines

Cheers,
Daniel

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Not sure how that snuck in.

Quoted 7 lines
Signature · 4 lines
-- 
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#15 lore raw

Re: [PATCHv2 1/4] drm/arm: Factor out generic afbc helpers

Hi Daniel,

Quoted 93 lines · Daniel Vetter
Quoted 92 lines · Brian Starkey

Hi Daniel,

Quoted 88 lines · Daniel Vetter
Quoted 74 lines · Brian Starkey

Hi Daniel,

Quoted 44 lines · Daniel Stone

Hi Andrzej,
Thanks for taking this on! It's looking better than v1 for sure. A few things below:

drivers/gpu/drm/drm_afbc.c line 29

Quoted 12 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/drm_afbc.c new file +5 -0
+bool drm_afbc_check_offset(struct drm_device *dev,
+                      const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   if (mode_cmd->offsets[0] != 0) {
+           DRM_DEBUG_KMS("AFBC buffers' plane offset should be

0\n");

drivers/gpu/drm/drm_afbc.c new file +6 -0
+           return false;
+   }
+
+   return true;
+}
+EXPORT_SYMBOL_GPL(drm_afbc_check_offset);

Is this actually universally true? If the offset is sufficiently aligned for (e.g.) DMA transfers to succeed, is there any reason why it must be zero?

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +4 -0
+bool drm_afbc_check_size_align(struct drm_device *dev,
+                          const struct drm_mode_fb_cmd2 *mode_cmd)
+{
+   switch (mode_cmd->modifier[0] &

AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) {

(quoted diff) +2 -0
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16:
+           if ((mode_cmd->width % 16) || (mode_cmd->height % 16))

{

This is a dealbreaker for many resolutions: for example, 1366x768 isn't cleanly divisible by 16 in width. So this means that we would have to either use a larger buffer and crop, or scale, or something.

No userspace is prepared to align fb width/height to tile dimensions like this, so this check will basically fail everywhere.

However, overallocation relative to the declared width/height isn't a problem at all. In order to deal with horizontal alignment, you simply need to ensure that the stride is a multiple of the tile width; for vertical arrangement, that the buffer is large enough to contain sufficient 'lines' to the next tile boundary.

Quoted 3 lines

i.e. rather than checking width/height, you should check:
* fb_stride >= (ALIGN(fb_width, tile_width), bpp)
* buf_size >= fb_stride * ALIGN(fb_height, tile_height)

Well, sort of.

I agree with you that for horizontal padding, we can indeed use pitch.

However, the AFBC decoder(s) need to know exactly what the total _allocated_ size in pixels of the buffer is - as this influences the header size, and we need to know the header size to know where it ends and the body begins.

I see a couple of possible ways forwards:

- Keep it as-is. The restrictive checks ensure that there's no ambiguity and we use the fb width/height to determine the real allocated width/height. Userspace needs to be AFBC-aware and set up plane cropping to handle the alignment differences.

- Use pitch to determine the "real" width, and internally in the kernel align height up to the next alignment boundary. This works OK, so long as there's no additional padding at the bottom of the buffer. This would work, but I can't figure a way to check/enforce that there's no additional padding at the bottom.

Quoted 7 lines

- Something else...

The checks as-implemented were deliberately conservative, and don't preclude doing some relaxation in the future.

On Android, gralloc is used to store the "real" allocated width/height and this is used to set up the DRM API appropriately.

Fake stride + real visible h/w in the drmfb. Because that's how it works with all the tiled formats already, and expecting userspace to fudge this all correctly seems very backwards to me. In a way we had that entire fake stride discussion already for the block size format stuff already, but now in a different flavour.

Quoted 8 lines
Quoted 5 lines

Fake stride - like I said, no problem; sounds good. That solves one dimension.

So do you have a proposal for how we determine what the allocated height is in that case? I don't really see a way.

Could you compute the height by looking at the buffer size? Or does that not help since the header stuff is generally rather small?

I've wondered about that. We might be able to use it heuristically, but it does place certain assumptions on the allocator - for instance rounding up to a page order might cause problems.

Quoted 7 lines

Otherwise I guess just round up height and hope it works. If we run into a use-case where that doesn't work anymore somehow, then we get to rev all the afbc modifiers and make them 2 planes. With that there's no such issue anymore (which is why the intel compressed stuff has 2 planes). -Daniel

We considered exposing the header explicitly as a plane before originally submitting the modifiers; however the header and body are linked in such a way that they aren't separable, so they aren't really separate planes. Also we have multi-plane AFBC buffers, where each plane has its own header and thus we'd need at least 6 planes to describe it fully if we separate out the header.

I'm not entirely sure how a separate header plane would help with this issue anyway.

We could round up the height, which should cover the common case. It seem(ed) safest to start with the conservative restrictions.

My proposal for handling the case of additional vertical padding on top of that would be to add a field in the modifier which indicates how much additional vertical padding there is. I know the Broadcom SAND modifiers do a similar thing. It does make the modifiers a bit "non-opaque" though, as the modifier value can't be simply queried from the modifier list.

... all of that said, the kernel interface is already rich enough to support everything, if userspace understands that sometimes it needs to crop.

Thanks,
-Brian

Quoted 97 lines
Quoted 97 lines

Thanks,
-Brian

Quoted 87 lines

Also I think that's more reasons why this should be no-opt-outable code that's done for all drivers when we check framebuffers in addfb. Plus then some helpers to get at computed values for any framebuffer we know to be valid.
-Daniel

Quoted 80 lines
Quoted 2 lines

This may force us to do some silly cropping games inside the Rockchip KMS driver, but I feel it beats the alternative of breaking userspace.

Well, nothing's going to get broken - it's just perhaps not ready to turn on AFBC yet.

Quoted 51 lines

drivers/gpu/drm/drm_afbc.c line 44

Quoted 10 lines
(quoted diff) +2 -0
+                   DRM_DEBUG_KMS(
+                           "AFBC buffer must be aligned to 16

pixels\n"

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                   );
+                   return false;
+           }
+           break;
+   case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8:
+           /* fall through */

It's also incongruous that 32x8 is unsupported here, but has a section in get_superblk_wh; please harmonise them so this section either does the checks as above, or that get_superblk_wh doesn't support 32x8 either.

drivers/gpu/drm/drm_afbc.c line 89

Quoted 9 lines
(quoted diff) +2 -0
+bool drm_afbc_check_fb_size_ret(u32 pitch, int bpp,
+                           u32 w, u32 h, u32 superblk_w, u32

superblk_h,

drivers/gpu/drm/drm_afbc.c new file +6 -0
+                           size_t size, u32 offset, u32 hdr_align,
+                           u32 *payload_off, u32 *total_size)
+{
+   int n_superblks = 0;
+   u32 superblk_sz = 0;
+   u32 afbc_size = 0;

Please don't initialise the above three variables, given that you go on to immediately change their values. In this case, initialising to zero can only hide legitimate uninitialised-variable-use warnings.

Quoted 8 lines
drivers/gpu/drm/drm_afbc.c new file +6 -0
+   n_superblks = (w / superblk_w) * (h / superblk_h);
+   superblk_sz = (bpp * superblk_w * superblk_h) / BITS_PER_BYTE;
+   afbc_size = ALIGN(n_superblks * AFBC_HEADER_SIZE, hdr_align);
+   *payload_off = afbc_size;
+
+   afbc_size += n_superblks * ALIGN(superblk_sz,

AFBC_SUPERBLK_ALIGNMENT);
+ *total_size = afbc_size + offset;

Generally these are referred to as 'tiles' rather than 'superblocks', given that I would only expect one superblock per buffer, but if that's the terminology AFBC uses then it might be better to stick with it.

drivers/gpu/drm/drm_afbc.c line 104

Quoted 7 lines
(quoted diff) +2 -0
+   if ((w * bpp) != (pitch * BITS_PER_BYTE)) {
+           DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE)

(=%u) should be same as width (=%u) * bpp (=%u)\n",

drivers/gpu/drm/drm_afbc.c new file +4 -0
+                         pitch * BITS_PER_BYTE, w, bpp
+           );
+           return false;
+   }
Quoted 5 lines

Having a too-small pitch is obviously a problem and we should reject it. But is having a too-large pitch really a problem; does it need to be an exact match, or can we support the case where the pitch is too large but also tile-aligned? If we can, it would be very good to support that.

The reason for forcing it to be exact is as I said above - we _must_ know what the "real" width and height is. Implementing this check to force (pitch == width * bpp) ensures that, and also leaves the option for us to relax to allow a larger pitch (as above) if that was the preferred approach for alignment.

In general the current checks are deliberately designed to leave the door open for future improvements without breaking anything.

Cheers,
-Brian

Quoted 4 lines

Cheers,
Daniel

IMPORTANT NOTICE: The contents of this email and any attachments are confidential and may also be privileged. If you are not the intended recipient, please notify the sender immediately and do not disclose the contents to any other person, use it for any purpose, or store or copy the information in any medium. Thank you.

Not sure how that snuck in.

Quoted 3 lines
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#16 lore raw

PATCH v2 2/4 drm/malidp: use afbc helpers

In reply to Andrzej Pietrasiewicz

There are afbc helpers available.

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

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
maintainer
#17 lore raw

Re: [PATCHv2 2/4] drm/malidp: use afbc helpers

Hi Andrzej,

Quoted 43 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 drivers/gpu/drm/arm/malidp_drv.c | 66 ++++++--------------------------
 1 file changed, 12 insertions(+), 54 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +1 -13
index 37d92a06318e..ab93588cc8eb 100644
@@ -15,6 +15,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/debugfs.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
@@ -35,8 +36,6 @@
 #include "malidp_hw.h"
 
 #define MALIDP_CONF_VALID_TIMEOUT	250
-#define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 
 static void malidp_write_gamma_table(struct malidp_hw_device *hwdev,
 				     u32 data[MALIDP_COEFFTAB_NUM_COEFFS])
@@ -277,24 +276,8 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev,
 					mode_cmd->modifier[0]) == false)
 		return false;
 
-	if (mode_cmd->offsets[0] != 0) {
-		DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n");
-		return false;
-	}
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
-			DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n");
-			return false;
-		}

drivers/gpu/drm/arm/malidp_drv.c malidp_verify_afbc_framebuffer_caps(struct drm_device *dev, · line 281

Quoted 10 lines
drivers/gpu/drm/arm/malidp_drv.c +2 -7
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
-
-	return true;
+	return drm_afbc_check_offset(dev, mode_cmd) &&
+	       drm_afbc_check_size_align(dev, mode_cmd);
 }

Given that the content of this function gets copied pretty much verbatim into the new drm_afbc.c file, I suggest you make the change in the 1/4 patch and also update the copyright statement in that file to show that the code originated from here.

Best regards,
Liviu

Quoted 69 lines
drivers/gpu/drm/arm/malidp_drv.c +9 -34
 static bool
@@ -302,54 +285,29 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev,
 				    struct drm_file *file,
 				    const struct drm_mode_fb_cmd2 *mode_cmd)
 {
-	int n_superblocks = 0;
 	const struct drm_format_info *info;
 	struct drm_gem_object *objs = NULL;
-	u32 afbc_superblock_size = 0, afbc_superblock_height = 0;
-	u32 afbc_superblock_width = 0, afbc_size = 0;
 	int bpp = 0;
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		afbc_superblock_height = 16;
-		afbc_superblock_width = 16;
-		break;
-	default:
-		DRM_DEBUG_KMS("AFBC superblock size is not supported\n");
-		return false;
-	}
+	u32 w, h;
 
 	info = drm_get_format_info(dev, mode_cmd);
-
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
-
 	bpp = malidp_format_get_bpp(info->format);
 
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
-
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
-
-	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
-		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
-			      "should be same as width (=%u) * bpp (=%u)\n",
-			      (mode_cmd->pitches[0] * BITS_PER_BYTE),
-			      mode_cmd->width, bpp);
-		return false;
-	}
-
 	objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!objs) {
 		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
 		return false;
 	}
 
-	if (objs->size < afbc_size) {
-		DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n",
-			      objs->size, afbc_size);
+	if (!drm_afbc_get_superblk_wh(mode_cmd->modifier[0], &w, &h))
+		return false;
+
+	if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+				    mode_cmd->width, mode_cmd->height, w, h,
+				    objs->size, mode_cmd->offsets[0],
+				    AFBC_SUPERBLK_ALIGNMENT)) {
 		drm_gem_object_put_unlocked(objs);
+
 		return false;
 	}
 
Signature · 1 line
2.17.1
Signature · 12 lines
====================
| I would like to |
| fix the world,  |
| but they're not |
| giving me the   |
 \ source code!  /
  ---------------
    ¯\_(ツ)_/¯
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#18 lore raw

PATCH v2 3/4 drm/komeda: use afbc helpers

In reply to Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 #define AFBC_SUPERBLK_PIXELS		256
 #define AFBC_BODY_START_ALIGNMENT	1024
 #define AFBC_TH_BODY_START_ALIGNMENT	4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +17 -27

70 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#19 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 #define AFBC_SUPERBLK_PIXELS		256
 #define AFBC_BODY_START_ALIGNMENT	1024
 #define AFBC_TH_BODY_START_ALIGNMENT	4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 	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;
+	u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
 	obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-		break;
+	if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+		return -EINVAL;
+
+	if ((alignment_w != 16 || alignment_h != 16) &&
+	    (alignment_w != 32 || alignment_h != 8)) {
+		DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+			      alignment_w, alignment_h);
+
+		return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
 	}
 
 	/* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 		goto check_failed;
 	}
 
-	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-				    alignment_header);
-
 	bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-	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];
-	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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Thanks anyways for taking a stab at this.
-Ayan

Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -1
+
+	if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+				    mode_cmd->width, mode_cmd->height,
+				    alignment_w, alignment_h,
+				    obj->size, mode_cmd->offsets[0],
+				    AFBC_SUPERBLK_ALIGNMENT))
 		goto check_failed;
-	}
 
 	fb->obj[0] = obj;
 	return 0;
Signature · 1 line
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#20 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 #define AFBC_SUPERBLK_PIXELS		256
 #define AFBC_BODY_START_ALIGNMENT	1024
 #define AFBC_TH_BODY_START_ALIGNMENT	4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 	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;
+	u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
 	obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-		break;
+	if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+		return -EINVAL;
+
+	if ((alignment_w != 16 || alignment_h != 16) &&
+	    (alignment_w != 32 || alignment_h != 8)) {
+		DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+			      alignment_w, alignment_h);
+
+		return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
 	}
 
 	/* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 		goto check_failed;
 	}
 
-	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-				    alignment_header);
-
 	bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-	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];
-	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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

Thanks
James

Quoted 11 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -1
+
+	if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+				    mode_cmd->width, mode_cmd->height,
+				    alignment_w, alignment_h,
+				    obj->size, mode_cmd->offsets[0],
+				    AFBC_SUPERBLK_ALIGNMENT))
 		goto check_failed;
-	}
 
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -0
 	fb->obj[0] = obj;
 	return 0;
Signature · 1 line
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#21 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 104 lines · james qian wang (Arm Technology China)
Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 #define AFBC_SUPERBLK_PIXELS		256
 #define AFBC_BODY_START_ALIGNMENT	1024
 #define AFBC_TH_BODY_START_ALIGNMENT	4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 	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;
+	u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
 	obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-		break;
+	if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+		return -EINVAL;
+
+	if ((alignment_w != 16 || alignment_h != 16) &&
+	    (alignment_w != 32 || alignment_h != 8)) {
+		DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+			      alignment_w, alignment_h);
+
+		return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
 	}
 
 	/* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 		goto check_failed;
 	}
 
-	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-				    alignment_header);
-
 	bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-	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];
-	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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Quoted 7 lines

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

How expensive is it to recompute these from a struct drm_framebuffer?

I'd just go with one function which computes all these derived values, and stuffs them into a struct drm_afbc. Then drivers call that once or so.

For reworking drm_framebuffer itself I think it's probably a bit too earlier. And if we do it, we should maybe go a bit more bold, aiming to property-fy all the framebuffer settings, maybe even making it extensible, and have drivers handle a corresponding drm_framebuffer_state.

A third option would be to create a drm_afbc_framebuffer which embeds drm_framebuffer and which drivers would need to use. But also feels a bit like too much churn. Recomputing should be quick enough and much easier. -Daniel

Quoted 19 lines

Thanks
James

Quoted 15 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -1
+
+	if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+				    mode_cmd->width, mode_cmd->height,
+				    alignment_w, alignment_h,
+				    obj->size, mode_cmd->offsets[0],
+				    AFBC_SUPERBLK_ALIGNMENT))
 		goto check_failed;
-	}
 
 	fb->obj[0] = obj;
 	return 0;
Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#22 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 113 lines · Daniel Vetter
Quoted 104 lines · james qian wang (Arm Technology China)
Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT	8
 #define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 #define AFBC_SUPERBLK_PIXELS		256
 #define AFBC_BODY_START_ALIGNMENT	1024
 #define AFBC_TH_BODY_START_ALIGNMENT	4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 	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;
+	u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
 	obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
 	if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-		break;
+	if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+		return -EINVAL;
+
+	if ((alignment_w != 16 || alignment_h != 16) &&
+	    (alignment_w != 32 || alignment_h != 8)) {
+		DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+			      alignment_w, alignment_h);
+
+		return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
 	}
 
 	/* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
 		goto check_failed;
 	}
 
-	n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-	kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-				    alignment_header);
-
 	bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-	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];
-	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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Quoted 7 lines

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

Quoted 5 lines

How expensive is it to recompute these from a struct drm_framebuffer?

I'd just go with one function which computes all these derived values, and stuffs them into a struct drm_afbc. Then drivers call that once or so.

A struct drm_afbc, good idea, I like it. :-)

and we can compute it when do the afbc size check like

  drm_afbc_check_fb_size(..., &komeda_fb->drm_afbc);

Thanks.
James

Quoted 25 lines

For reworking drm_framebuffer itself I think it's probably a bit too earlier. And if we do it, we should maybe go a bit more bold, aiming to property-fy all the framebuffer settings, maybe even making it extensible, and have drivers handle a corresponding drm_framebuffer_state.

A third option would be to create a drm_afbc_framebuffer which embeds drm_framebuffer and which drivers would need to use. But also feels a bit like too much churn. Recomputing should be quick enough and much easier. -Daniel

Quoted 15 lines

Thanks
James

Quoted 11 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -1
+
+	if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+				    mode_cmd->width, mode_cmd->height,
+				    alignment_w, alignment_h,
+				    obj->size, mode_cmd->offsets[0],
+				    AFBC_SUPERBLK_ALIGNMENT))
 		goto check_failed;
-	}
 
Quoted 9 lines
Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -0
 	fb->obj[0] = obj;
 	return 0;
Signature · 1 line
2.17.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#23 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 120 lines · james qian wang (Arm Technology China)
Quoted 113 lines · Daniel Vetter
Quoted 104 lines · james qian wang (Arm Technology China)
Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT       8
 #define AFBC_HEADER_SIZE               16
-#define AFBC_SUPERBLK_ALIGNMENT                128
 #define AFBC_SUPERBLK_PIXELS           256
 #define AFBC_BODY_START_ALIGNMENT      1024
 #define AFBC_TH_BODY_START_ALIGNMENT   4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
        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;
+       u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
        obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
        if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-               break;
+       if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+               return -EINVAL;
+
+       if ((alignment_w != 16 || alignment_h != 16) &&
+           (alignment_w != 32 || alignment_h != 8)) {
+               DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+                             alignment_w, alignment_h);
+
+               return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
        }
 
        /* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
                goto check_failed;
        }
 
-       n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-       kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-                                   alignment_header);
-
        bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-       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];
-       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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Quoted 7 lines

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

Quoted 5 lines

How expensive is it to recompute these from a struct drm_framebuffer?

I'd just go with one function which computes all these derived values, and stuffs them into a struct drm_afbc. Then drivers call that once or so.

Quoted 5 lines

A struct drm_afbc, good idea, I like it. :-)

and we can compute it when do the afbc size check like

  drm_afbc_check_fb_size(..., &komeda_fb->drm_afbc);

Discussed this also with Andrzej on irc on where exactly to place stuff. I think ideally we'd be able to get rid of the custom malidp_fb_create completely, and komeda should also be able to get rid of most of the open-coded checks (it's largely reinveting drm_gem_fb_create_with_funcs, imo better to just call that first, then then do a few more calls of the specific things you need to have computed in addition).
-Daniel

Quoted 38 lines

Thanks.
James

Quoted 34 lines

For reworking drm_framebuffer itself I think it's probably a bit too earlier. And if we do it, we should maybe go a bit more bold, aiming to property-fy all the framebuffer settings, maybe even making it extensible, and have drivers handle a corresponding drm_framebuffer_state.

A third option would be to create a drm_afbc_framebuffer which embeds drm_framebuffer and which drivers would need to use. But also feels a bit like too much churn. Recomputing should be quick enough and much easier. -Daniel

Quoted 19 lines

Thanks
James

Quoted 15 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -2
+
+       if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+                                   mode_cmd->width, mode_cmd->height,
+                                   alignment_w, alignment_h,
+                                   obj->size, mode_cmd->offsets[0],
+                                   AFBC_SUPERBLK_ALIGNMENT))
                goto check_failed;
-       }
 
        fb->obj[0] = obj;
        return 0;
--

2.17.1

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

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#24 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 128 lines · Daniel Vetter
Quoted 120 lines · james qian wang (Arm Technology China)
Quoted 113 lines · Daniel Vetter
Quoted 104 lines · james qian wang (Arm Technology China)
Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT       8
 #define AFBC_HEADER_SIZE               16
-#define AFBC_SUPERBLK_ALIGNMENT                128
 #define AFBC_SUPERBLK_PIXELS           256
 #define AFBC_BODY_START_ALIGNMENT      1024
 #define AFBC_TH_BODY_START_ALIGNMENT   4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
        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;
+       u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
        obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
        if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-               break;
+       if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+               return -EINVAL;
+
+       if ((alignment_w != 16 || alignment_h != 16) &&
+           (alignment_w != 32 || alignment_h != 8)) {
+               DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+                             alignment_w, alignment_h);
+
+               return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
        }
 
        /* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
                goto check_failed;
        }
 
-       n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-       kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-                                   alignment_header);
-
        bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-       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];
-       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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Quoted 7 lines

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

Quoted 5 lines

How expensive is it to recompute these from a struct drm_framebuffer?

I'd just go with one function which computes all these derived values, and stuffs them into a struct drm_afbc. Then drivers call that once or so.

Quoted 5 lines

A struct drm_afbc, good idea, I like it. :-)

and we can compute it when do the afbc size check like

  drm_afbc_check_fb_size(..., &komeda_fb->drm_afbc);
Quoted 8 lines

Discussed this also with Andrzej on irc on where exactly to place stuff. I think ideally we'd be able to get rid of the custom malidp_fb_create completely, and komeda should also be able to get rid of most of the open-coded checks (it's largely reinveting drm_gem_fb_create_with_funcs, imo better to just call that first, then then do a few more calls of the specific things you need to have computed in addition).
-Daniel

The afbc support is the only reason why malidp/komeda define our own fb_create(), it is good for komeda and malidp if we put afbc support directly into the standard drm_gem_fb_create_with_funcs.

BTW:

can we add one more argument: fb_struct_size to

  drm_gem_fb_create_with_funcs(..., size_t fb_struct_size);

then driver can use it to extend its own fb struct and add some private infos.

Thanks
James

Quoted 34 lines
Quoted 34 lines

Thanks.
James

Quoted 30 lines

For reworking drm_framebuffer itself I think it's probably a bit too earlier. And if we do it, we should maybe go a bit more bold, aiming to property-fy all the framebuffer settings, maybe even making it extensible, and have drivers handle a corresponding drm_framebuffer_state.

A third option would be to create a drm_afbc_framebuffer which embeds drm_framebuffer and which drivers would need to use. But also feels a bit like too much churn. Recomputing should be quick enough and much easier. -Daniel

Quoted 19 lines

Thanks
James

Quoted 15 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -2
+
+       if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+                                   mode_cmd->width, mode_cmd->height,
+                                   alignment_w, alignment_h,
+                                   obj->size, mode_cmd->offsets[0],
+                                   AFBC_SUPERBLK_ALIGNMENT))
                goto check_failed;
-       }
 
        fb->obj[0] = obj;
        return 0;
--

2.17.1

Quoted 11 lines
Quoted 4 lines
Quoted 4 lines

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#25 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 142 lines · james qian wang (Arm Technology China)
Quoted 128 lines · Daniel Vetter
Quoted 120 lines · james qian wang (Arm Technology China)
Quoted 113 lines · Daniel Vetter
Quoted 104 lines · james qian wang (Arm Technology China)
Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT       8
 #define AFBC_HEADER_SIZE               16
-#define AFBC_SUPERBLK_ALIGNMENT                128
 #define AFBC_SUPERBLK_PIXELS           256
 #define AFBC_BODY_START_ALIGNMENT      1024
 #define AFBC_TH_BODY_START_ALIGNMENT   4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
        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;
+       u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
        obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
        if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-               break;
+       if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+               return -EINVAL;
+
+       if ((alignment_w != 16 || alignment_h != 16) &&
+           (alignment_w != 32 || alignment_h != 8)) {
+               DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+                             alignment_w, alignment_h);
+
+               return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
        }
 
        /* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
                goto check_failed;
        }
 
-       n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-       kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-                                   alignment_header);
-
        bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-       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];
-       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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Quoted 7 lines

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

Quoted 5 lines

How expensive is it to recompute these from a struct drm_framebuffer?

I'd just go with one function which computes all these derived values, and stuffs them into a struct drm_afbc. Then drivers call that once or so.

Quoted 5 lines

A struct drm_afbc, good idea, I like it. :-)

and we can compute it when do the afbc size check like

  drm_afbc_check_fb_size(..., &komeda_fb->drm_afbc);
Quoted 8 lines

Discussed this also with Andrzej on irc on where exactly to place stuff. I think ideally we'd be able to get rid of the custom malidp_fb_create completely, and komeda should also be able to get rid of most of the open-coded checks (it's largely reinveting drm_gem_fb_create_with_funcs, imo better to just call that first, then then do a few more calls of the specific things you need to have computed in addition).
-Daniel

The afbc support is the only reason why malidp/komeda define our own fb_create(), it is good for komeda and malidp if we put afbc support directly into the standard drm_gem_fb_create_with_funcs.

Quoted 8 lines

BTW:

can we add one more argument: fb_struct_size to

  drm_gem_fb_create_with_funcs(..., size_t fb_struct_size);

then driver can use it to extend its own fb struct and add some private infos.

Hm, this isn't how we usually do it for subclassing - the trouble with this is that the size of the allocation is very far away from where we actually allocate, automated checkers have a harder time with this pattern.

Usually what we do is split the kzalloc out from the _create function, leaving just _init behind. Then you have roughly (pseudo-code):

	drm_gem_fb_create_with_funcs(args) {
		struct drm_gem_fb *fb;

		fb = kzalloc(sizeof(*fb));
		if (!fb)
			return -ENOMEM;

		return drm_gem_fb_init_with_functions(fb, args);
	}

If you then need a bigger function, you just allocate that bigger function, and pass &fb->base to the _init function. Costs 3 additional lines (for the kzalloc and error checking), but easier to read&verify for both humans and compilers.

I guess what we could then do is create a drm_gem_afbc_create function which sets this all up for a

struct drm_gem_afbc_framebuffer {
	struct drm_gem_framebuffer base;
	/* afbc stuff */
};

and then also fills out all derived afbc values, so more than just calling drm_gem_fb_init_with_functions. And drivers could still have their own version with even more checks on top.

And all afbc supporting drivers could then use that. Feels a bit like overengineering to me, but if you feel like that's justified to do it's a good solution.

Cheers, Daniel

Quoted 48 lines

Thanks
James

Quoted 45 lines
Quoted 38 lines

Thanks.
James

Quoted 34 lines

For reworking drm_framebuffer itself I think it's probably a bit too earlier. And if we do it, we should maybe go a bit more bold, aiming to property-fy all the framebuffer settings, maybe even making it extensible, and have drivers handle a corresponding drm_framebuffer_state.

A third option would be to create a drm_afbc_framebuffer which embeds drm_framebuffer and which drivers would need to use. But also feels a bit like too much churn. Recomputing should be quick enough and much easier. -Daniel

Quoted 19 lines

Thanks
James

Quoted 15 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -2
+
+       if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+                                   mode_cmd->width, mode_cmd->height,
+                                   alignment_w, alignment_h,
+                                   obj->size, mode_cmd->offsets[0],
+                                   AFBC_SUPERBLK_ALIGNMENT))
                goto check_failed;
-       }
 
        fb->obj[0] = obj;
        return 0;
--

2.17.1

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

A message that is not in the archive (sent off-list or not yet received): 20191118095136.GC23790-dv86pmgwkMBes7Z6vYuT8azUEOm+Xw19@public.gmane.org

#27 lore raw

Re: [PATCHv2 3/4] drm/komeda: use afbc helpers

Quoted 183 lines · Daniel Vetter
Quoted 142 lines · james qian wang (Arm Technology China)
Quoted 128 lines · Daniel Vetter
Quoted 120 lines · james qian wang (Arm Technology China)
Quoted 113 lines · Daniel Vetter
Quoted 104 lines · james qian wang (Arm Technology China)
Quoted 96 lines · Ayan Halder
Quoted 58 lines · Andrzej Pietrasiewicz

There are afbc helpers available.

---
 .../arm/display/komeda/komeda_format_caps.h   |  1 -
 .../arm/display/komeda/komeda_framebuffer.c   | 44 +++++++------------
 2 files changed, 17 insertions(+), 28 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_format_caps.h +0 -1
index 32273cf18f7c..607eea80e60c 100644
@@ -33,7 +33,6 @@
 
 #define AFBC_TH_LAYOUT_ALIGNMENT       8
 #define AFBC_HEADER_SIZE               16
-#define AFBC_SUPERBLK_ALIGNMENT                128
 #define AFBC_SUPERBLK_PIXELS           256
 #define AFBC_BODY_START_ALIGNMENT      1024
 #define AFBC_TH_BODY_START_ALIGNMENT   4096
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +2 -14
index 1b01a625f40e..e9c87551a5b8 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -43,8 +44,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
        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;
+       u32 alignment_w = 0, alignment_h = 0, alignment_header, bpp;
 
        obj = drm_gem_object_lookup(file, mode_cmd->handles[0]);
        if (!obj) {
@@ -52,19 +52,15 @@ 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);

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 63

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +9 -1
-               break;
+       if (!drm_afbc_get_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+               return -EINVAL;
+
+       if ((alignment_w != 16 || alignment_h != 16) &&
+           (alignment_w != 32 || alignment_h != 8)) {
+               DRM_DEBUG_KMS("Unsupported afbc tile w/h [%d/%d]\n",
+                             alignment_w, alignment_h);
+
+               return -EINVAL;

To be honest, the previous code looks much more readable

Quoted 9 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -2
        }
 
        /* tiled header afbc */
@@ -84,20 +80,14 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file,
                goto check_failed;
        }
 
-       n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS;
-       kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE,

drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, · line 98

Quoted 10 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +0 -9
-                                   alignment_header);
-
        bpp = komeda_get_afbc_format_bpp(info, fb->modifier);
-       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];
-       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);

We need kfb->offset_payload and kfb->afbc_size to set some registers in d71_layer_update(). At this moment I feel like punching myself for making the suggestion to consider abstracting some of the komeda's afbc checks. To me it does not look like komeda(in the current shape) can take much advantage of the generic _afbc_fb_check() function (as was suggested previously by Danvet).

Quoted 4 lines

However, I will let [email protected], [email protected], [email protected] comment here to see if there could be a way of abstracting the afbc bits from komeda.

Hi all:

Quoted 7 lines

Since the current generic drm_afbc helpers only support afbc_1.1, but komeda needs support both afbc1.1/1.2, so I think we can:
- Add afbc1.2 support to drm afbc helpers.
- for the afbc_payload_offset, can we add this member to drm_framebuffer ?
- The aligned_w/h are important for afbc, so can we have them in drm_framebuffer ?

Quoted 5 lines

How expensive is it to recompute these from a struct drm_framebuffer?

I'd just go with one function which computes all these derived values, and stuffs them into a struct drm_afbc. Then drivers call that once or so.

Quoted 5 lines

A struct drm_afbc, good idea, I like it. :-)

and we can compute it when do the afbc size check like

  drm_afbc_check_fb_size(..., &komeda_fb->drm_afbc);
Quoted 8 lines

Discussed this also with Andrzej on irc on where exactly to place stuff. I think ideally we'd be able to get rid of the custom malidp_fb_create completely, and komeda should also be able to get rid of most of the open-coded checks (it's largely reinveting drm_gem_fb_create_with_funcs, imo better to just call that first, then then do a few more calls of the specific things you need to have computed in addition).
-Daniel

The afbc support is the only reason why malidp/komeda define our own fb_create(), it is good for komeda and malidp if we put afbc support directly into the standard drm_gem_fb_create_with_funcs.

Quoted 8 lines

BTW:

can we add one more argument: fb_struct_size to

  drm_gem_fb_create_with_funcs(..., size_t fb_struct_size);

then driver can use it to extend its own fb struct and add some private infos.

Hm, this isn't how we usually do it for subclassing - the trouble with this is that the size of the allocation is very far away from where we actually allocate, automated checkers have a harder time with this pattern.

Usually what we do is split the kzalloc out from the _create function, leaving just _init behind. Then you have roughly (pseudo-code):

	drm_gem_fb_create_with_funcs(args) {
		struct drm_gem_fb *fb;

		fb = kzalloc(sizeof(*fb));
		if (!fb)
			return -ENOMEM;

		return drm_gem_fb_init_with_functions(fb, args);
	}

If you then need a bigger function, you just allocate that bigger function, and pass &fb->base to the _init function. Costs 3 additional lines (for the kzalloc and error checking), but easier to read&verify for both humans and compilers.

I guess what we could then do is create a drm_gem_afbc_create function which sets this all up for a

struct drm_gem_afbc_framebuffer {
	struct drm_gem_framebuffer base;
	/* afbc stuff */
};
Quoted 7 lines

and then also fills out all derived afbc values, so more than just calling drm_gem_fb_init_with_functions. And drivers could still have their own version with even more checks on top.

And all afbc supporting drivers could then use that. Feels a bit like overengineering to me, but if you feel like that's justified to do it's a good solution.

Hi Daniel:

This solution looks good, it can fit all our requirement.

Thanks
James.

Quoted 54 lines

Cheers, Daniel

Quoted 48 lines

Thanks
James

Quoted 45 lines
Quoted 38 lines

Thanks.
James

Quoted 34 lines

For reworking drm_framebuffer itself I think it's probably a bit too earlier. And if we do it, we should maybe go a bit more bold, aiming to property-fy all the framebuffer settings, maybe even making it extensible, and have drivers handle a corresponding drm_framebuffer_state.

A third option would be to create a drm_afbc_framebuffer which embeds drm_framebuffer and which drivers would need to use. But also feels a bit like too much churn. Recomputing should be quick enough and much easier. -Daniel

Quoted 19 lines

Thanks
James

Quoted 15 lines

Thanks anyways for taking a stab at this.
-Ayan

Quoted 13 lines
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +6 -2
+
+       if (!drm_afbc_check_fb_size(mode_cmd->pitches[0], bpp,
+                                   mode_cmd->width, mode_cmd->height,
+                                   alignment_w, alignment_h,
+                                   obj->size, mode_cmd->offsets[0],
+                                   AFBC_SUPERBLK_ALIGNMENT))
                goto check_failed;
-       }
 
        fb->obj[0] = obj;
        return 0;
--

2.17.1

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

Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
+41 (0) 79 365 57 48 - http://blog.ffwll.ch
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
#28 lore raw

cover AFBC rework and support for Rockchip

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:

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

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

Andrzej Pietrasiewicz (4):
drm/arm: Factor out generic afbc helpers
drm/malidp: use afbc helpers
drm/komeda: Use afbc helper
drm/rockchip: Add support for afbc

 drivers/gpu/drm/Makefile                      |   2 +-
 .../arm/display/komeda/komeda_framebuffer.c   |  17 +--
 drivers/gpu/drm/arm/malidp_drv.c              | 121 +++------------
 drivers/gpu/drm/drm_afbc.c                    |  84 +++++++++++
 drivers/gpu/drm/drm_fourcc.c                  |  11 +-
 drivers/gpu/drm/drm_framebuffer.c             |  71 ++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c    |  29 ++++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c   | 142 +++++++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h   |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c   |  84 ++++++++++-
 include/drm/drm_afbc.h                        |  35 +++++
 11 files changed, 485 insertions(+), 123 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#29 lore raw

PATCH v2 1/4 drm/arm: Factor out generic afbc helpers

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Makefile          |  2 +-
 drivers/gpu/drm/drm_afbc.c        | 84 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_fourcc.c      | 11 +++-
 drivers/gpu/drm/drm_framebuffer.c | 71 +++++++++++++++++++++++++-
 include/drm/drm_afbc.h            | 35 +++++++++++++
 5 files changed, 199 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Makefile +1 -1
index d9bcc9f2a0a4..3a58f30b83a6 100644
@@ -44,7 +44,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper
 		drm_simple_kms_helper.o drm_modeset_helper.o \
 		drm_scdc_helper.o drm_gem_framebuffer_helper.o \
 		drm_atomic_state_helper.o drm_damage_helper.o \
-		drm_format_helper.o drm_self_refresh_helper.o
+		drm_format_helper.o drm_self_refresh_helper.o drm_afbc.o
 
 drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
drivers/gpu/drm/drm_afbc.c new file +84 -0

84 lines not on this page · raw message

drivers/gpu/drm/drm_fourcc.c +9 -2
index c630064ccf41..8d9f197cc0ab 100644
@@ -27,6 +27,7 @@
 #include <linux/export.h>
 #include <linux/kernel.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fourcc.h>
 
@@ -322,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);
drivers/gpu/drm/drm_framebuffer.c +70 -1

108 lines not on this page · raw message

include/drm/drm_afbc.h new file +35 -0
new file mode 100644
index 000000000000..fb4d4549f77e
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+#include <linux/types.h>
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+struct drm_afbc {
+	u32 tile_w;
+	u32 tile_h;
+	u32 width;
+	u32 height;
+	u32 offset;
+};
+
+#define AFBC_HEADER_SIZE		16
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_get_superblk_wh(u64 modifier, u32 *w, u32 *h);
+
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
+			     struct drm_afbc *afbc);
+
+bool drm_is_afbc(u64 modifier);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#30 lore raw

Re: [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers

Hi Andrzej,

Thanks for the series. It's certainly going well.

Please see some minor comments below.

Quoted 48 lines · Andrzej Pietrasiewicz

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Makefile          |  2 +-
 drivers/gpu/drm/drm_afbc.c        | 84 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_fourcc.c      | 11 +++-
 drivers/gpu/drm/drm_framebuffer.c | 71 +++++++++++++++++++++++++-
 include/drm/drm_afbc.h            | 35 +++++++++++++
 5 files changed, 199 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Makefile +1 -1
index d9bcc9f2a0a4..3a58f30b83a6 100644
@@ -44,7 +44,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper
 		drm_simple_kms_helper.o drm_modeset_helper.o \
 		drm_scdc_helper.o drm_gem_framebuffer_helper.o \
 		drm_atomic_state_helper.o drm_damage_helper.o \
-		drm_format_helper.o drm_self_refresh_helper.o
+		drm_format_helper.o drm_self_refresh_helper.o drm_afbc.o
 
 drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
drivers/gpu/drm/drm_afbc.c new file +16 -0
new file mode 100644
index 000000000000..f308c4719546
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#include <linux/module.h>
+
+#include <drm/drm_afbc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_print.h>
+

drivers/gpu/drm/drm_afbc.c line 26

Quoted 10 lines
drivers/gpu/drm/drm_afbc.c new file +10 -0
+/**
+ * drm_afbc_get_superblk_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_superblk_wh(u64 modifier, u32 *w, u32 *h)
+{

Name nitpicking: drm_afbc_get_superblock_size. The coding-style guide has a chapter on naming and suggests avoiding stuff like "superblk".

Quoted 29 lines
drivers/gpu/drm/drm_afbc.c new file +29 -0
+	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_superblk_wh);
+
+/**
+ * drm_afbc_get_parameters - extract afbc parameters from mode command
+ * @mode_cmd: mode command to be looked at
+ * @afbc: address of a struct to be filled in
+ */
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
+			     struct drm_afbc *afbc)

drivers/gpu/drm/drm_afbc.c line 65

Quoted 10 lines
drivers/gpu/drm/drm_afbc.c new file +10 -0
+{
+	drm_afbc_get_superblk_wh(mode_cmd->modifier[0],
+				 &afbc->tile_w, &afbc->tile_h);
+	afbc->width = mode_cmd->pitches[0];
+	afbc->height =
+		DIV_ROUND_UP(mode_cmd->height, afbc->tile_h) * afbc->tile_h;
+	afbc->offset = mode_cmd->offsets[0];
+}
+EXPORT_SYMBOL(drm_afbc_get_parameters);
+

Not sure if this was discussed before, but why some are EXPORT_SYMBOL and others are exported as _GPL?

Quoted 76 lines
drivers/gpu/drm/drm_afbc.c new file +19 -0
+/**
+ * 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);
drivers/gpu/drm/drm_fourcc.c +9 -2
index c630064ccf41..8d9f197cc0ab 100644
@@ -27,6 +27,7 @@
 #include <linux/export.h>
 #include <linux/kernel.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fourcc.h>
 
@@ -322,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);
drivers/gpu/drm/drm_framebuffer.c +6 -0
index 57564318ceea..303eea624a02 100644
@@ -23,6 +23,7 @@
 #include <linux/export.h>
 #include <linux/uaccess.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_uapi.h>
 #include <drm/drm_auth.h>
@@ -31,6 +32,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
 #include <drm/drm_print.h>
 #include <drm/drm_util.h>
 
@@ -168,7 +170,69 @@ static int fb_plane_height(int height,
 	return DIV_ROUND_UP(height, format->vsub);
 }
 
+static int afbc_check(struct drm_file *file_priv,
+		      const struct drm_mode_fb_cmd2 *r, int i,
+		      const struct drm_format_info *info)
+{

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 186

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+	struct drm_gem_object *obj;
+	int bpp = info->cpp[0] * 8;
+	int tiles;
+	u32 w, h, height, tile_sz, afbc_size;
+	int result = 0;
+
+	if (i) {
+		DRM_DEBUG_KMS("AFBC supported only for plane 0\n");
+
+		return 1;

Any reason to return 1, instead of an errno, or a boolean?

Quoted 95 lines
drivers/gpu/drm/drm_framebuffer.c +54 -1
+	}
+
+	/* get tile w/h */
+	if (!drm_afbc_get_superblk_wh(r->modifier[0], &w, &h))
+		return 1;
+
+	/* pitch must be divisible by tile width */
+	if (r->pitches[0] % w) {
+		DRM_DEBUG_KMS("Invalid pitch for plane %d\n", i);
+
+		return 1;
+	}
+
+	obj = drm_gem_object_lookup(file_priv, r->handles[0]);
+	if (!obj) {
+		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+
+		return 1;
+	}
+
+	/* estimate height based on tile size and height from userspace */
+	height = DIV_ROUND_UP(r->height, h) * h;
+
+	tiles = (r->pitches[0] / w) * (height / h);
+	afbc_size = ALIGN(tiles * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
+
+	tile_sz = (bpp * w * h) / BITS_PER_BYTE;
+	afbc_size += tiles * ALIGN(tile_sz, AFBC_SUPERBLK_ALIGNMENT);
+
+	result = obj->size < afbc_size;
+
+	drm_gem_object_put_unlocked(obj);
+
+	return result;
+}
+
+static int modifier_check(struct drm_file *file_priv,
+			  const struct drm_mode_fb_cmd2 *r, int i,
+			  const struct drm_format_info *info)
+{
+	/* non-afbc format */
+	if (!drm_is_afbc(r->modifier[i]))
+		return 0;
+
+	return afbc_check(file_priv, r, i, info);
+}
+
 static int framebuffer_check(struct drm_device *dev,
+			     struct drm_file *file_priv,
 			     const struct drm_mode_fb_cmd2 *r)
 {
 	const struct drm_format_info *info;
@@ -204,6 +268,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;
@@ -253,6 +320,8 @@ static int framebuffer_check(struct drm_device *dev,
 			break;
 
 		default:
+			if (modifier_check(file_priv, r, i, info))
+				return -EINVAL;
 			break;
 		}
 	}
@@ -317,7 +386,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	ret = framebuffer_check(dev, r);
+	ret = framebuffer_check(dev, file_priv, r);
 	if (ret)
 		return ERR_PTR(ret);
 
include/drm/drm_afbc.h new file +9 -0
new file mode 100644
index 000000000000..fb4d4549f77e
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__

include/drm/drm_afbc.h line 19

Quoted 10 lines
include/drm/drm_afbc.h new file +10 -0
+
+#include <linux/types.h>
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+struct drm_afbc {
+	u32 tile_w;
+	u32 tile_h;

I'd go with tile_width and tile_height.

include/drm/drm_afbc.h line 27

Quoted 8 lines
include/drm/drm_afbc.h new file +8 -0
+	u32 width;
+	u32 height;
+	u32 offset;
+};
+
+#define AFBC_HEADER_SIZE		16
+#define AFBC_SUPERBLK_ALIGNMENT		128
+

Ditto, s/SUPERBLK/SUPERBLOCK.

Quoted 12 lines
include/drm/drm_afbc.h new file +8 -0
+bool drm_afbc_get_superblk_wh(u64 modifier, u32 *w, u32 *h);
+
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
+			     struct drm_afbc *afbc);
+
+bool drm_is_afbc(u64 modifier);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 1 line
2.17.1

Thanks!
Eze

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#31 lore raw

Re: [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers

In reply to Andrzej Pietrasiewicz
[if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the base tree in git format-patch, please…

Hi Andrzej,

[FYI, it's a private test report for your RFC patch.]
[auto build test ERROR on next-20191122]
[also build test ERROR on v5.4-rc8]
[cannot apply to rockchip/for-next drm-exynos/exynos-drm-next linus/master v5.4-rc8 v5.4-rc7 v5.4-rc6] [if your patch is applied to the wrong git tree, please drop us a note to help improve the system. BTW, we also suggest to use '--base' option to specify the
base tree in git format-patch, please see https://stackoverflow.com/a/37406982]

url:    https://github.com/0day-ci/linux/commits/Andrzej-Pietrasiewicz/AFBC-rework-and-support-for-Rockchip/20191124-080522
base:    b9d3d01405061bb42358fe53f824e894a1922ced
config: x86_64-randconfig-a001-20191124 (attached as .config)
compiler: gcc-7 (Debian 7.4.0-14) 7.4.0
reproduce:
        # save the attached .config to linux build tree
        make ARCH=x86_64 

If you fix the issue, kindly add following tag

All errors (new ones prefixed by >>):

ld: drivers/gpu/drm/drm_fourcc.o: in function `drm_get_format_info':

>> drivers/gpu/drm/drm_fourcc.c:327: undefined reference to `drm_is_afbc'
   ld: drivers/gpu/drm/drm_framebuffer.o: in function `framebuffer_check':
>> drivers/gpu/drm/drm_framebuffer.c:271: undefined reference to `drm_is_afbc'
   ld: drivers/gpu/drm/drm_framebuffer.o: in function `modifier_check':
   drivers/gpu/drm/drm_framebuffer.c:228: undefined reference to `drm_is_afbc'
   ld: drivers/gpu/drm/drm_framebuffer.o: in function `afbc_check':
>> drivers/gpu/drm/drm_framebuffer.c:190: undefined reference to `drm_afbc_get_superblk_wh'

vim +327 drivers/gpu/drm/drm_fourcc.c

310
311 /**
312 * drm_get_format_info - query information for a given framebuffer configuration
313 * @dev: DRM device
314 * @mode_cmd: metadata from the userspace fb creation request
315 *
316 * Returns:
317 * The instance of struct drm_format_info that describes the pixel format, or
318 * NULL if the format is unsupported.
319 */
320 const struct drm_format_info *
321 drm_get_format_info(struct drm_device *dev,
322 const struct drm_mode_fb_cmd2 *mode_cmd)
323 {
324 const struct drm_format_info *info = NULL;
325
326 /* bypass driver callback if afbc */

 > 327		if (!drm_is_afbc(mode_cmd->modifier[0]))

328 if (dev->mode_config.funcs->get_format_info) {
329 const struct drm_mode_config_funcs *funcs;
330
331 funcs = dev->mode_config.funcs;
332 info = funcs->get_format_info(mode_cmd);
333 }
334
335 if (!info)
336 info = drm_format_info(mode_cmd->pixel_format);
337
338 return info;
339 }
340 EXPORT_SYMBOL(drm_get_format_info);
341

---
0-DAY kernel test infrastructure Open Source Technology Center
https://lists.01.org/hyperkitty/list/kbuild-all(a)lists.01.org Intel Corporation

#32 lore raw

Re: [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers

In reply to Andrzej Pietrasiewicz
Quoted 18 lines · Andrzej Pietrasiewicz

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Makefile          |  2 +-
 drivers/gpu/drm/drm_afbc.c        | 84 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_fourcc.c      | 11 +++-
 drivers/gpu/drm/drm_framebuffer.c | 71 +++++++++++++++++++++++++-
 include/drm/drm_afbc.h            | 35 +++++++++++++
 5 files changed, 199 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Makefile +0 -0
index d9bcc9f2a0a4..3a58f30b83a6 100644

drivers/gpu/drm/Makefile drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper · line 47

Quoted 5 lines
drivers/gpu/drm/Makefile +1 -1
@@ -44,7 +44,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper
 		drm_simple_kms_helper.o drm_modeset_helper.o \
 		drm_scdc_helper.o drm_gem_framebuffer_helper.o \
 		drm_atomic_state_helper.o drm_damage_helper.o \
-		drm_format_helper.o drm_self_refresh_helper.o
+		drm_format_helper.o drm_self_refresh_helper.o drm_afbc.o

Just a quick drive-by:
- you can't put this into helpers and call from core code. This should be core code. Also, I'd have just stuffed it into drm_format.c.

- If you want to keep your separate file, please include it in the doc template, next to the format handling functions.

Quoted 164 lines
drivers/gpu/drm/Makefile +0 -0
 drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
drivers/gpu/drm/drm_afbc.c new file +84 -0
new file mode 100644
index 000000000000..f308c4719546
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#include <linux/module.h>
+
+#include <drm/drm_afbc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_print.h>
+
+/**
+ * drm_afbc_get_superblk_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_superblk_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_superblk_wh);
+
+/**
+ * drm_afbc_get_parameters - extract afbc parameters from mode command
+ * @mode_cmd: mode command to be looked at
+ * @afbc: address of a struct to be filled in
+ */
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
+			     struct drm_afbc *afbc)
+{
+	drm_afbc_get_superblk_wh(mode_cmd->modifier[0],
+				 &afbc->tile_w, &afbc->tile_h);
+	afbc->width = mode_cmd->pitches[0];
+	afbc->height =
+		DIV_ROUND_UP(mode_cmd->height, afbc->tile_h) * afbc->tile_h;
+	afbc->offset = mode_cmd->offsets[0];
+}
+EXPORT_SYMBOL(drm_afbc_get_parameters);
+
+/**
+ * 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);
drivers/gpu/drm/drm_fourcc.c +9 -2
index c630064ccf41..8d9f197cc0ab 100644
@@ -27,6 +27,7 @@
 #include <linux/export.h>
 #include <linux/kernel.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fourcc.h>
 
@@ -322,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);
drivers/gpu/drm/drm_framebuffer.c +20 -0
index 57564318ceea..303eea624a02 100644
@@ -23,6 +23,7 @@
 #include <linux/export.h>
 #include <linux/uaccess.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_uapi.h>
 #include <drm/drm_auth.h>
@@ -31,6 +32,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
 #include <drm/drm_print.h>
 #include <drm/drm_util.h>
 
@@ -168,7 +170,69 @@ static int fb_plane_height(int height,
 	return DIV_ROUND_UP(height, format->vsub);
 }
 
+static int afbc_check(struct drm_file *file_priv,
+		      const struct drm_mode_fb_cmd2 *r, int i,
+		      const struct drm_format_info *info)
+{
+	struct drm_gem_object *obj;
+	int bpp = info->cpp[0] * 8;
+	int tiles;
+	u32 w, h, height, tile_sz, afbc_size;
+	int result = 0;
+
+	if (i) {
+		DRM_DEBUG_KMS("AFBC supported only for plane 0\n");
+
+		return 1;
+	}
+
+	/* get tile w/h */
+	if (!drm_afbc_get_superblk_wh(r->modifier[0], &w, &h))

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 200

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+		return 1;
+
+	/* pitch must be divisible by tile width */
+	if (r->pitches[0] % w) {
+		DRM_DEBUG_KMS("Invalid pitch for plane %d\n", i);
+
+		return 1;
+	}
+
+	obj = drm_gem_object_lookup(file_priv, r->handles[0]);

I think this is a bit ugly ... I'd split this into a new framebuffer_check_post() function which is called after fb_create, at that point you do have the objects already looked up.

Also I suggested that this could be done as a helper implementation for fb_create, wrapping it around the default gem implementation. That way you could keep all the afbc stuff in helpers entirely (but drivers could screw things up, so there's a tradeoff).

What's definitely not ok is calling drm_gem_object_lookup unconditionally from core code here. For consistency I think the helper approach would be good, since currently the size related checks are done in drm_gem_fb_create() - i.e. in the helpers, not in core. Otoh having checks split like this is also ugly, so maybe we should have a framebuffer_check_post for everyone, and move all the size checks into core (not just for afbc).
-Daniel

Quoted 110 lines
drivers/gpu/drm/drm_framebuffer.c +40 -1
+	if (!obj) {
+		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+
+		return 1;
+	}
+
+	/* estimate height based on tile size and height from userspace */
+	height = DIV_ROUND_UP(r->height, h) * h;
+
+	tiles = (r->pitches[0] / w) * (height / h);
+	afbc_size = ALIGN(tiles * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
+
+	tile_sz = (bpp * w * h) / BITS_PER_BYTE;
+	afbc_size += tiles * ALIGN(tile_sz, AFBC_SUPERBLK_ALIGNMENT);
+
+	result = obj->size < afbc_size;
+
+	drm_gem_object_put_unlocked(obj);
+
+	return result;
+}
+
+static int modifier_check(struct drm_file *file_priv,
+			  const struct drm_mode_fb_cmd2 *r, int i,
+			  const struct drm_format_info *info)
+{
+	/* non-afbc format */
+	if (!drm_is_afbc(r->modifier[i]))
+		return 0;
+
+	return afbc_check(file_priv, r, i, info);
+}
+
 static int framebuffer_check(struct drm_device *dev,
+			     struct drm_file *file_priv,
 			     const struct drm_mode_fb_cmd2 *r)
 {
 	const struct drm_format_info *info;
@@ -204,6 +268,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;
@@ -253,6 +320,8 @@ static int framebuffer_check(struct drm_device *dev,
 			break;
 
 		default:
+			if (modifier_check(file_priv, r, i, info))
+				return -EINVAL;
 			break;
 		}
 	}
@@ -317,7 +386,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	ret = framebuffer_check(dev, r);
+	ret = framebuffer_check(dev, file_priv, r);
 	if (ret)
 		return ERR_PTR(ret);
 
include/drm/drm_afbc.h new file +35 -0
new file mode 100644
index 000000000000..fb4d4549f77e
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+#include <linux/types.h>
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
+struct drm_afbc {
+	u32 tile_w;
+	u32 tile_h;
+	u32 width;
+	u32 height;
+	u32 offset;
+};
+
+#define AFBC_HEADER_SIZE		16
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_get_superblk_wh(u64 modifier, u32 *w, u32 *h);
+
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
+			     struct drm_afbc *afbc);
+
+bool drm_is_afbc(u64 modifier);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 1 line
2.17.1
Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#33 lore raw

Re: [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers

Hi Daniel,

Thanks for the comments, please see inline

W dniu 25.11.2019 o 09:55, Daniel Vetter pisze:

Quoted 14 lines · Andrzej Pietrasiewicz
Quoted 13 lines

These are useful for other users of afbc, e.g. rockchip.

---
  drivers/gpu/drm/Makefile          |  2 +-
  drivers/gpu/drm/drm_afbc.c        | 84 +++++++++++++++++++++++++++++++
  drivers/gpu/drm/drm_fourcc.c      | 11 +++-
  drivers/gpu/drm/drm_framebuffer.c | 71 +++++++++++++++++++++++++-
  include/drm/drm_afbc.h            | 35 +++++++++++++
  5 files changed, 199 insertions(+), 4 deletions(-)

create mode 100644 drivers/gpu/drm/drm_afbc.c
create mode 100644 include/drm/drm_afbc.h

Quoted 15 lines

drivers/gpu/drm/Makefile drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper · line 47

Quoted 10 lines
drivers/gpu/drm/Makefile +1 -1
index d9bcc9f2a0a4..3a58f30b83a6 100644
@@ -44,7 +44,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper
  		drm_simple_kms_helper.o drm_modeset_helper.o \
  		drm_scdc_helper.o drm_gem_framebuffer_helper.o \
  		drm_atomic_state_helper.o drm_damage_helper.o \
-		drm_format_helper.o drm_self_refresh_helper.o
+		drm_format_helper.o drm_self_refresh_helper.o drm_afbc.o

Just a quick drive-by:
- you can't put this into helpers and call from core code. This should be core code. Also, I'd have just stuffed it into drm_format.c.

drm_format.c does not exist. Did you mean drm_format_helper.c?

<snip>

Quoted 62 lines
Quoted 42 lines
drivers/gpu/drm/drm_framebuffer.c +20 -0
index 57564318ceea..303eea624a02 100644
@@ -23,6 +23,7 @@
  #include <linux/export.h>
  #include <linux/uaccess.h>
 
+#include <drm/drm_afbc.h>
  #include <drm/drm_atomic.h>
  #include <drm/drm_atomic_uapi.h>
  #include <drm/drm_auth.h>
@@ -31,6 +32,7 @@
  #include <drm/drm_file.h>
  #include <drm/drm_fourcc.h>
  #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
  #include <drm/drm_print.h>
  #include <drm/drm_util.h>
 
@@ -168,7 +170,69 @@ static int fb_plane_height(int height,
  	return DIV_ROUND_UP(height, format->vsub);
  }
 
+static int afbc_check(struct drm_file *file_priv,
+		      const struct drm_mode_fb_cmd2 *r, int i,
+		      const struct drm_format_info *info)
+{
+	struct drm_gem_object *obj;
+	int bpp = info->cpp[0] * 8;
+	int tiles;
+	u32 w, h, height, tile_sz, afbc_size;
+	int result = 0;
+
+	if (i) {
+		DRM_DEBUG_KMS("AFBC supported only for plane 0\n");
+
+		return 1;
+	}
+
+	/* get tile w/h */
+	if (!drm_afbc_get_superblk_wh(r->modifier[0], &w, &h))

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 200

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+		return 1;
+
+	/* pitch must be divisible by tile width */
+	if (r->pitches[0] % w) {
+		DRM_DEBUG_KMS("Invalid pitch for plane %d\n", i);
+
+		return 1;
+	}
+
+	obj = drm_gem_object_lookup(file_priv, r->handles[0]);

I think this is a bit ugly ... I'd split this into a new framebuffer_check_post() function which is called after fb_create, at that point you do have the objects already looked up.

Also I suggested that this could be done as a helper implementation for fb_create, wrapping it around the default gem implementation. That way you could keep all the afbc stuff in helpers entirely (but drivers could screw things up, so there's a tradeoff).

Quoted 8 lines

What's definitely not ok is calling drm_gem_object_lookup unconditionally from core code here. For consistency I think the helper approach would be good, since currently the size related checks are done in drm_gem_fb_create() - i.e. in the helpers, not in core. Otoh having checks split like this is also ugly, so maybe we should have a framebuffer_check_post for everyone, and move all the size checks into core (not just for afbc).
-Daniel

As far as I understand you see more than one way forward. Can you please comment on the below? And in particular, can you say if I understood you correctly? So, my understanding of what you said above is to either:

1) move the part of the code which requires objects to be looked up to a new framebuffer_check_post() called after fb_create, that is from drm_internal_framebuffer_create() after

fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);

because at that point the objects have already been looked up. How driver-specific checks can be done in this scheme?

or

2) Move the body of afbc_check() to a helper implementation to be used by driver-specific fb_create implementations. Sorry for my ignorance, it seems that "helpers" and "core" have precise meaning here but I don't quite understand what is what of what, so I also don't quite understand where to move the code to and why this would mean keeping all the afbc stuff entirely in helpers :O Can you explain?

Did you mean that all the checking code is called by specific drivers on an opt-in basis? I thought you were not in favor of drivers opting-in, as some of them might opt-in while some others opt-out, or use different subsets of available checks.

or

3) e.g. rockchip does not use drm_gem_fb_create(). It uses drm_gem_fb_create_handle(), though. Anyway, the third way forward is to have framebuffer_check_post() as in 1) and move the size checks to "core" - which I don't quite understand where exactly it is. What is the difference to 1)?

Quoted 12 lines

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 211

Quoted 12 lines
drivers/gpu/drm/drm_framebuffer.c +11 -0
+	if (!obj) {
+		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+
+		return 1;
+	}
+
+	/* estimate height based on tile size and height from userspace */
+	height = DIV_ROUND_UP(r->height, h) * h;
+
+	tiles = (r->pitches[0] / w) * (height / h);
+	afbc_size = ALIGN(tiles * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);

This computation is for malidp/rockchip, but for komeda the alignment is different. So it seems it is driver-specific. If so, we need some way for specific drivers to provide their specific checks and/or specific data for generic checking code to use.

Thanks

Andrzej
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#34 lore raw

Re: [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers

Quoted 35 lines · Andrzej Pietrasiewicz

Hi Daniel,

Thanks for the comments, please see inline

W dniu 25.11.2019 o 09:55, Daniel Vetter pisze:

Quoted 14 lines · Andrzej Pietrasiewicz
Quoted 13 lines

These are useful for other users of afbc, e.g. rockchip.

---
  drivers/gpu/drm/Makefile          |  2 +-
  drivers/gpu/drm/drm_afbc.c        | 84 +++++++++++++++++++++++++++++++
  drivers/gpu/drm/drm_fourcc.c      | 11 +++-
  drivers/gpu/drm/drm_framebuffer.c | 71 +++++++++++++++++++++++++-
  include/drm/drm_afbc.h            | 35 +++++++++++++
  5 files changed, 199 insertions(+), 4 deletions(-)

create mode 100644 drivers/gpu/drm/drm_afbc.c
create mode 100644 include/drm/drm_afbc.h

Quoted 15 lines

drivers/gpu/drm/Makefile drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper · line 47

Quoted 10 lines
drivers/gpu/drm/Makefile +1 -1
index d9bcc9f2a0a4..3a58f30b83a6 100644
@@ -44,7 +44,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper
  		drm_simple_kms_helper.o drm_modeset_helper.o \
  		drm_scdc_helper.o drm_gem_framebuffer_helper.o \
  		drm_atomic_state_helper.o drm_damage_helper.o \
-		drm_format_helper.o drm_self_refresh_helper.o
+		drm_format_helper.o drm_self_refresh_helper.o drm_afbc.o

Just a quick drive-by:
- you can't put this into helpers and call from core code. This should be core code. Also, I'd have just stuffed it into drm_format.c.

Quoted 1 line

drm_format.c does not exist. Did you mean drm_format_helper.c?

drm_fourcc.c. You can't put this into a helper and call it from core code, it wont link for modular builds.

Quoted 75 lines

<snip>

Quoted 59 lines
Quoted 39 lines
drivers/gpu/drm/drm_framebuffer.c +20 -0
index 57564318ceea..303eea624a02 100644
@@ -23,6 +23,7 @@
  #include <linux/export.h>
  #include <linux/uaccess.h>
+#include <drm/drm_afbc.h>
  #include <drm/drm_atomic.h>
  #include <drm/drm_atomic_uapi.h>
  #include <drm/drm_auth.h>
@@ -31,6 +32,7 @@
  #include <drm/drm_file.h>
  #include <drm/drm_fourcc.h>
  #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
  #include <drm/drm_print.h>
  #include <drm/drm_util.h>
@@ -168,7 +170,69 @@ static int fb_plane_height(int height,
  	return DIV_ROUND_UP(height, format->vsub);
  }
+static int afbc_check(struct drm_file *file_priv,
+		      const struct drm_mode_fb_cmd2 *r, int i,
+		      const struct drm_format_info *info)
+{
+	struct drm_gem_object *obj;
+	int bpp = info->cpp[0] * 8;
+	int tiles;
+	u32 w, h, height, tile_sz, afbc_size;
+	int result = 0;
+
+	if (i) {
+		DRM_DEBUG_KMS("AFBC supported only for plane 0\n");
+
+		return 1;
+	}
+
+	/* get tile w/h */
+	if (!drm_afbc_get_superblk_wh(r->modifier[0], &w, &h))

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 199

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+		return 1;
+
+	/* pitch must be divisible by tile width */
+	if (r->pitches[0] % w) {
+		DRM_DEBUG_KMS("Invalid pitch for plane %d\n", i);
+
+		return 1;
+	}
+
+	obj = drm_gem_object_lookup(file_priv, r->handles[0]);

I think this is a bit ugly ... I'd split this into a new framebuffer_check_post() function which is called after fb_create, at that point you do have the objects already looked up.

Also I suggested that this could be done as a helper implementation for fb_create, wrapping it around the default gem implementation. That way you could keep all the afbc stuff in helpers entirely (but drivers could screw things up, so there's a tradeoff).

Quoted 8 lines

What's definitely not ok is calling drm_gem_object_lookup unconditionally from core code here. For consistency I think the helper approach would be good, since currently the size related checks are done in drm_gem_fb_create() - i.e. in the helpers, not in core. Otoh having checks split like this is also ugly, so maybe we should have a framebuffer_check_post for everyone, and move all the size checks into core (not just for afbc).
-Daniel

As far as I understand you see more than one way forward. Can you please comment on the below? And in particular, can you say if I understood you correctly? So, my understanding of what you said above is to either:

Quoted 8 lines

1) move the part of the code which requires objects to be looked up to a new framebuffer_check_post() called after fb_create, that is from drm_internal_framebuffer_create() after

fb = dev->mode_config.funcs->fb_create(dev, file_priv, r);

because at that point the objects have already been looked up. How driver-specific checks can be done in this scheme?

Yup that's one way of doing it. Still feels a bit icky.

Quoted 8 lines

or

2) Move the body of afbc_check() to a helper implementation to be used by driver-specific fb_create implementations. Sorry for my ignorance, it seems that "helpers" and "core" have precise meaning here but I don't quite understand what is what of what, so I also don't quite understand where to move the code to and why this would mean keeping all the afbc stuff entirely in helpers :O Can you explain?

That's the 2nd option, where 2a would be putting the checks into drm_gem_fb_create_with_funcs(). That would at least be consistent with the existing placement of size related checks we have.

For more context on core vs midlayer:

https://blog.ffwll.ch/2016/12/midlayers-once-more-with-feeling.html

The first few paragraphs have a pile of links with what this means for kernel hackers.

In this case specifically the choice of using gem as backing storage for drm_framebuffer is up to drivers, and hence anything gem related should be in opt-in helpers. Although we only have 1 driver not using gem, so we standardized this a lot and somewhat muddied the core/helper separation here. Still, we should at least try to be consistent across the different formats and checks.

Quoted 5 lines

Did you mean that all the checking code is called by specific drivers on an opt-in basis? I thought you were not in favor of drivers opting-in, as some of them might opt-in while some others opt-out, or use different subsets of available checks.

Quoted 7 lines

or

3) e.g. rockchip does not use drm_gem_fb_create(). It uses drm_gem_fb_create_handle(), though. Anyway, the third way forward is to have framebuffer_check_post() as in 1) and move the size checks to "core" - which I don't quite understand where exactly it is. What is the difference to 1)?

create_handle is a different ioctl, it's called from the GETFB ioctl. We'd need to move the fb_create hook over to helpers for rockchip, and you're lucky, I have a patch for you:

"drm/rockchip: Use drm_gem_fb_create_with_dirty"

Can you pls review/test that one?

Thanks, Daniel

Quoted 22 lines
Quoted 13 lines

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 211

Quoted 13 lines
drivers/gpu/drm/drm_framebuffer.c +11 -0
+	if (!obj) {
+		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+
+		return 1;
+	}
+
+	/* estimate height based on tile size and height from userspace */
+	height = DIV_ROUND_UP(r->height, h) * h;
+
+	tiles = (r->pitches[0] / w) * (height / h);
+	afbc_size = ALIGN(tiles * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);

This computation is for malidp/rockchip, but for komeda the alignment is different. So it seems it is driver-specific. If so, we need some way for specific drivers to provide their specific checks and/or specific data for generic checking code to use.

Thanks

Andrzej

Signature · 7 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#35 lore raw

Re: [PATCHv3/RFC 1/4] drm/arm: Factor out generic afbc helpers

In reply to Daniel Vetter
Quoted 312 lines · Daniel Vetter
Quoted 18 lines · Andrzej Pietrasiewicz

These are useful for other users of afbc, e.g. rockchip.

---
 drivers/gpu/drm/Makefile          |  2 +-
 drivers/gpu/drm/drm_afbc.c        | 84 +++++++++++++++++++++++++++++++
 drivers/gpu/drm/drm_fourcc.c      | 11 +++-
 drivers/gpu/drm/drm_framebuffer.c | 71 +++++++++++++++++++++++++-
 include/drm/drm_afbc.h            | 35 +++++++++++++
 5 files changed, 199 insertions(+), 4 deletions(-)
 create mode 100644 drivers/gpu/drm/drm_afbc.c
 create mode 100644 include/drm/drm_afbc.h
drivers/gpu/drm/Makefile +0 -0
index d9bcc9f2a0a4..3a58f30b83a6 100644

drivers/gpu/drm/Makefile drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper · line 47

Quoted 5 lines
drivers/gpu/drm/Makefile +1 -1
@@ -44,7 +44,7 @@ drm_kms_helper-y := drm_crtc_helper.o drm_dp_helper.o drm_dsc.o drm_probe_helper
 		drm_simple_kms_helper.o drm_modeset_helper.o \
 		drm_scdc_helper.o drm_gem_framebuffer_helper.o \
 		drm_atomic_state_helper.o drm_damage_helper.o \
-		drm_format_helper.o drm_self_refresh_helper.o
+		drm_format_helper.o drm_self_refresh_helper.o drm_afbc.o

Just a quick drive-by:
- you can't put this into helpers and call from core code. This should be core code. Also, I'd have just stuffed it into drm_format.c.

- If you want to keep your separate file, please include it in the doc template, next to the format handling functions.

Quoted 164 lines
drivers/gpu/drm/Makefile +0 -0
 drm_kms_helper-$(CONFIG_DRM_PANEL_BRIDGE) += bridge/panel.o
 drm_kms_helper-$(CONFIG_DRM_FBDEV_EMULATION) += drm_fb_helper.o
drivers/gpu/drm/drm_afbc.c new file +84 -0
new file mode 100644
index 000000000000..f308c4719546
@@ -0,0 +1,84 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#include <linux/module.h>
+
+#include <drm/drm_afbc.h>
+#include <drm/drm_device.h>
+#include <drm/drm_fourcc.h>
+#include <drm/drm_gem.h>
+#include <drm/drm_mode.h>
+#include <drm/drm_print.h>
+
+/**
+ * drm_afbc_get_superblk_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_superblk_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_superblk_wh);
+
+/**
+ * drm_afbc_get_parameters - extract afbc parameters from mode command
+ * @mode_cmd: mode command to be looked at
+ * @afbc: address of a struct to be filled in
+ */
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
+			     struct drm_afbc *afbc)
+{
+	drm_afbc_get_superblk_wh(mode_cmd->modifier[0],
+				 &afbc->tile_w, &afbc->tile_h);
+	afbc->width = mode_cmd->pitches[0];
+	afbc->height =
+		DIV_ROUND_UP(mode_cmd->height, afbc->tile_h) * afbc->tile_h;
+	afbc->offset = mode_cmd->offsets[0];
+}
+EXPORT_SYMBOL(drm_afbc_get_parameters);
+
+/**
+ * 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);
drivers/gpu/drm/drm_fourcc.c +9 -2
index c630064ccf41..8d9f197cc0ab 100644
@@ -27,6 +27,7 @@
 #include <linux/export.h>
 #include <linux/kernel.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fourcc.h>
 
@@ -322,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);
drivers/gpu/drm/drm_framebuffer.c +20 -0
index 57564318ceea..303eea624a02 100644
@@ -23,6 +23,7 @@
 #include <linux/export.h>
 #include <linux/uaccess.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_uapi.h>
 #include <drm/drm_auth.h>
@@ -31,6 +32,7 @@
 #include <drm/drm_file.h>
 #include <drm/drm_fourcc.h>
 #include <drm/drm_framebuffer.h>
+#include <drm/drm_gem.h>
 #include <drm/drm_print.h>
 #include <drm/drm_util.h>
 
@@ -168,7 +170,69 @@ static int fb_plane_height(int height,
 	return DIV_ROUND_UP(height, format->vsub);
 }
 
+static int afbc_check(struct drm_file *file_priv,
+		      const struct drm_mode_fb_cmd2 *r, int i,
+		      const struct drm_format_info *info)
+{
+	struct drm_gem_object *obj;
+	int bpp = info->cpp[0] * 8;
+	int tiles;
+	u32 w, h, height, tile_sz, afbc_size;
+	int result = 0;
+
+	if (i) {
+		DRM_DEBUG_KMS("AFBC supported only for plane 0\n");
+
+		return 1;
+	}
+
+	/* get tile w/h */
+	if (!drm_afbc_get_superblk_wh(r->modifier[0], &w, &h))

drivers/gpu/drm/drm_framebuffer.c static int fb_plane_height(int height, · line 200

Quoted 10 lines
drivers/gpu/drm/drm_framebuffer.c +10 -0
+		return 1;
+
+	/* pitch must be divisible by tile width */
+	if (r->pitches[0] % w) {
+		DRM_DEBUG_KMS("Invalid pitch for plane %d\n", i);
+
+		return 1;
+	}
+
+	obj = drm_gem_object_lookup(file_priv, r->handles[0]);

I think this is a bit ugly ... I'd split this into a new framebuffer_check_post() function which is called after fb_create, at that point you do have the objects already looked up.

Also I suggested that this could be done as a helper implementation for fb_create, wrapping it around the default gem implementation. That way you could keep all the afbc stuff in helpers entirely (but drivers could screw things up, so there's a tradeoff).

What's definitely not ok is calling drm_gem_object_lookup unconditionally from core code here. For consistency I think the helper approach would be good, since currently the size related checks are done in drm_gem_fb_create() - i.e. in the helpers, not in core. Otoh having checks split like this is also ugly, so maybe we should have a framebuffer_check_post for everyone, and move all the size checks into core (not just for afbc).
-Daniel

Quoted 88 lines
drivers/gpu/drm/drm_framebuffer.c +40 -1
+	if (!obj) {
+		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
+
+		return 1;
+	}
+
+	/* estimate height based on tile size and height from userspace */
+	height = DIV_ROUND_UP(r->height, h) * h;
+
+	tiles = (r->pitches[0] / w) * (height / h);
+	afbc_size = ALIGN(tiles * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
+
+	tile_sz = (bpp * w * h) / BITS_PER_BYTE;
+	afbc_size += tiles * ALIGN(tile_sz, AFBC_SUPERBLK_ALIGNMENT);
+
+	result = obj->size < afbc_size;
+
+	drm_gem_object_put_unlocked(obj);
+
+	return result;
+}
+
+static int modifier_check(struct drm_file *file_priv,
+			  const struct drm_mode_fb_cmd2 *r, int i,
+			  const struct drm_format_info *info)
+{
+	/* non-afbc format */
+	if (!drm_is_afbc(r->modifier[i]))
+		return 0;
+
+	return afbc_check(file_priv, r, i, info);
+}
+
 static int framebuffer_check(struct drm_device *dev,
+			     struct drm_file *file_priv,
 			     const struct drm_mode_fb_cmd2 *r)
 {
 	const struct drm_format_info *info;
@@ -204,6 +268,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;
@@ -253,6 +320,8 @@ static int framebuffer_check(struct drm_device *dev,
 			break;
 
 		default:
+			if (modifier_check(file_priv, r, i, info))
+				return -EINVAL;
 			break;
 		}
 	}
@@ -317,7 +386,7 @@ drm_internal_framebuffer_create(struct drm_device *dev,
 		return ERR_PTR(-EINVAL);
 	}
 
-	ret = framebuffer_check(dev, r);
+	ret = framebuffer_check(dev, file_priv, r);
 	if (ret)
 		return ERR_PTR(ret);
 
include/drm/drm_afbc.h new file +16 -0
new file mode 100644
index 000000000000..fb4d4549f77e
@@ -0,0 +1,35 @@
+/* SPDX-License-Identifier: GPL-2.0+ */
+/*
+ * (C) 2019 Collabora Ltd.
+ *
+ * author: Andrzej Pietrasiewicz <[email protected]>
+ *
+ */
+#ifndef __DRM_AFBC_H__
+#define __DRM_AFBC_H__
+
+#include <linux/types.h>
+
+struct drm_device;
+struct drm_mode_fb_cmd2;
+struct drm_gem_object;
+
Quoted 8 lines

include/drm/drm_afbc.h line 24

Quoted 8 lines
include/drm/drm_afbc.h new file +8 -0
+struct drm_afbc {
+	u32 tile_w;
+	u32 tile_h;
+	u32 width;
+	u32 height;
+	u32 offset;
+};
+

Can we put a afbc ptr into drm_framebuffer, as the afbc extension if the fb is afbc.
Since mostly this drm_afbc is enough for afbc support, but no need to expose check func to driver, since per design the afbc modifier bits represent all the requrement, the check is like a sanity check between the modifier and fb info.

And we can also extend such afbc_info to all modifier which need an extra check or extra info. like.

struct drm_framebuffer {
    ...
    union {    
        struct drm_afbc *afbc_info;
        void *mod_info; //extra modifier extension.  
    }
    ...
}

and such modifier info can be returned modifier_check()

drm_gem_fb_create_with_funcs()

{
    void *mod_info;

    if (!modifier)
        none_modifier_size_check();
    else if (afbc)
        mod_info = drm_afbc_size_check();
    else if (mode_config->fb_modifier_check())
        // for vendor specific modifier check
        mod_info = mode_config->fb_modifier_check();

    fb = drm_gem_fb_alloc();

    fb->mod_info = mod_info;
}

And in specific driver, you can directly convert the fb->mod_info to your own modifier info. like current modifier is afbc, then

   struct drm_afbc *afbc_info = fb->mod_info;

Thanks
James

Quoted 6 lines
Quoted 6 lines
include/drm/drm_afbc.h new file +6 -0
+#define AFBC_HEADER_SIZE		16
+#define AFBC_SUPERBLK_ALIGNMENT		128
+
+bool drm_afbc_get_superblk_wh(u64 modifier, u32 *w, u32 *h);
+
+void drm_afbc_get_parameters(const struct drm_mode_fb_cmd2 *mode_cmd,
Quoted 13 lines
Quoted 8 lines
include/drm/drm_afbc.h new file +5 -0
+			     struct drm_afbc *afbc);
+
+bool drm_is_afbc(u64 modifier);
+
+#endif /* __DRM_AFBC_H__ */
Signature · 1 line
2.17.1
Signature · 3 lines
Daniel Vetter
Software Engineer, Intel Corporation
http://blog.ffwll.ch

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#36 lore raw

PATCH v2 2/4 drm/malidp: use afbc helpers

In reply to Andrzej Pietrasiewicz

There are afbc helpers available.

---
 drivers/gpu/drm/arm/malidp_drv.c | 121 +++++--------------------------
 1 file changed, 20 insertions(+), 101 deletions(-)
drivers/gpu/drm/arm/malidp_drv.c +20 -101
index 37d92a06318e..ff8364680676 100644
@@ -15,6 +15,7 @@
 #include <linux/pm_runtime.h>
 #include <linux/debugfs.h>
 
+#include <drm/drm_afbc.h>
 #include <drm/drm_atomic.h>
 #include <drm/drm_atomic_helper.h>
 #include <drm/drm_crtc.h>
@@ -35,8 +36,6 @@
 #include "malidp_hw.h"
 
 #define MALIDP_CONF_VALID_TIMEOUT	250
-#define AFBC_HEADER_SIZE		16
-#define AFBC_SUPERBLK_ALIGNMENT		128
 
 static void malidp_write_gamma_table(struct malidp_hw_device *hwdev,
 				     u32 data[MALIDP_COEFFTAB_NUM_COEFFS])
@@ -269,112 +268,32 @@ 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_caps(struct drm_device *dev,
-				    const struct drm_mode_fb_cmd2 *mode_cmd)
-{
-	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;
-	}
-
-	switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) {
-	case AFBC_SIZE_16X16:
-		if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) {
-			DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n");
-			return false;
-		}
-		break;
-	default:
-		DRM_DEBUG_KMS("Unsupported AFBC block size\n");
-		return false;
-	}
-
-	return true;
-}
-
-static bool
-malidp_verify_afbc_framebuffer_size(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;
-
-	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;
-	}
-
-	info = drm_get_format_info(dev, mode_cmd);
-
-	n_superblocks = (mode_cmd->width / afbc_superblock_width) *
-		(mode_cmd->height / afbc_superblock_height);
-
-	bpp = malidp_format_get_bpp(info->format);
-
-	afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height)
-				/ BITS_PER_BYTE;
-
-	afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT);
-	afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT);
-
-	if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) {
-		DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) "
-			      "should be same as width (=%u) * bpp (=%u)\n",
-			      (mode_cmd->pitches[0] * BITS_PER_BYTE),
-			      mode_cmd->width, bpp);
-		return false;
-	}
-
-	objs = drm_gem_object_lookup(file, mode_cmd->handles[0]);
-	if (!objs) {
-		DRM_DEBUG_KMS("Failed to lookup GEM object\n");
-		return false;
-	}
+	if (mode_cmd->modifier[0]) {
+		struct drm_afbc afbc;
 
-	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;
-	}
+		if (malidp_format_mod_supported(dev, mode_cmd->pixel_format,
+						mode_cmd->modifier[0]) == false)
+			return ERR_PTR(-EINVAL);
 
-	drm_gem_object_put_unlocked(objs);
+		drm_afbc_get_parameters(mode_cmd, &afbc);
 
-	return true;
-}
+		if (afbc.tile_w != 16 || afbc.tile_h != 16) {
+			DRM_DEV_DEBUG(dev->dev,
+				      "Unsupported AFBC block size %dx%d\n",
+				      afbc.tile_w, afbc.tile_h);
 
-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);
-
-	return false;
-}
+			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 (afbc.offset) {
+			DRM_DEV_ERROR(dev->dev,
+				"AFBC plane offset must be zero!\n");
 			return ERR_PTR(-EINVAL);
+		}
 	}
 
 	return drm_gem_fb_create(dev, file, mode_cmd);
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#37 lore raw

PATCH v2 3/4 drm/komeda: Use afbc helper

In reply to Andrzej Pietrasiewicz

AFBC helpers are available. Use those which increase code readability.

---
 .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)
drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +3 -14
index 1b01a625f40e..f7edde3ac319 100644
@@ -4,6 +4,7 @@
  * Author: James.Qian.Wang <[email protected]>
  *
  */
+#include <drm/drm_afbc.h>
 #include <drm/drm_device.h>
 #include <drm/drm_fb_cma_helper.h>
 #include <drm/drm_gem.h>
@@ -52,20 +53,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_superblk_wh(fb->modifier, &alignment_w, &alignment_h))
+		return -EINVAL;
 
 	/* tiled header afbc */
 	if (fb->modifier & AFBC_FORMAT_MOD_TILED) {
Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#38 lore raw

PATCH v2 4/4 drm/rockchip: Add support for afbc

In reply to Andrzej Pietrasiewicz

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

---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  29 ++++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 142 +++++++++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c |  84 +++++++++++-
 4 files changed, 263 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +29 -0
index ca01234c037c..7eaa3fdc03b2 100644
@@ -8,6 +8,7 @@
 
 #include <drm/drm.h>
 #include <drm/drm_atomic.h>
+#include <drm/drm_afbc.h>
 #include <drm/drm_damage_helper.h>
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_fourcc.h>
@@ -18,6 +19,8 @@
 #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,
 	.create_handle = drm_gem_fb_create_handle,
@@ -32,6 +35,32 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm
 	int ret;
 	int i;
 
+	if (drm_is_afbc(mode_cmd->modifier[0])) {
+		struct drm_afbc afbc;
+
+		drm_afbc_get_parameters(mode_cmd, &afbc);
+
+		if (afbc.offset) {
+			DRM_WARN("AFBC plane offset must be zero!\n");
+
+			return ERR_PTR(-EINVAL);
+		}
+
+		if (afbc.tile_w != 16 || afbc.tile_h != 16) {
+			DRM_WARN("Unsupported afbc tile w/h [%d/%d]\n",
+				 afbc.tile_w, afbc.tile_h);
+
+			return ERR_PTR(-EINVAL);
+		}
+
+		if (afbc.width > ROCKCHIP_MAX_AFBC_WIDTH) {
+			DRM_WARN("Unsupported width %d>%d\n",
+				 afbc.width, ROCKCHIP_MAX_AFBC_WIDTH);
+
+			return ERR_PTR(-EINVAL);
+		}
+	}
+
 	fb = kzalloc(sizeof(*fb), GFP_KERNEL);
 	if (!fb)
 		return ERR_PTR(-ENOMEM);
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +140 -2

223 lines not on this page · raw message

drivers/gpu/drm/rockchip/rockchip_drm_vop.h +12 -0
index 0b3d18c457b2..3f4e88a783d2 100644
@@ -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;
drivers/gpu/drm/rockchip/rockchip_vop_reg.c +82 -2

199 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Reviewed-by on v2 4/4
#39 lore raw

Re: [PATCHv3/RFC 4/4] drm/rockchip: Add support for afbc

Hello Andrzej,

Thanks a lot for the patch.

Quoted 43 lines · Andrzej Pietrasiewicz

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

---
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  29 ++++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 142 +++++++++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c |  84 +++++++++++-
 4 files changed, 263 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +8 -0
index ca01234c037c..7eaa3fdc03b2 100644
@@ -8,6 +8,7 @@
 
 #include <drm/drm.h>
 #include <drm/drm_atomic.h>
+#include <drm/drm_afbc.h>
 #include <drm/drm_damage_helper.h>
 #include <drm/drm_fb_helper.h>
 #include <drm/drm_fourcc.h>
@@ -18,6 +19,8 @@
 #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,
 	.create_handle = drm_gem_fb_create_handle,
@@ -32,6 +35,32 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm
 	int ret;
 	int i;
 
+	if (drm_is_afbc(mode_cmd->modifier[0])) {
+		struct drm_afbc afbc;
+
+		drm_afbc_get_parameters(mode_cmd, &afbc);
+

drivers/gpu/drm/rockchip/rockchip_drm_fb.c rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm · line 52

Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +10 -0
+		if (afbc.offset) {
+			DRM_WARN("AFBC plane offset must be zero!\n");
+
+			return ERR_PTR(-EINVAL);
+		}
+
+		if (afbc.tile_w != 16 || afbc.tile_h != 16) {
+			DRM_WARN("Unsupported afbc tile w/h [%d/%d]\n",
+				 afbc.tile_w, afbc.tile_h);
+

I think it's important to stick to using always "AFBC" or always ", i.e. to be consisten in user messages. Makes grepping easier.

[..]

drivers/gpu/drm/rockchip/rockchip_drm_fb.c static void vop_plane_atomic_update(struct drm_plane *plane, · line 965

Quoted 7 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +3 -0
@@ -846,6 +960,23 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
 
 	spin_lock(&vop->reg_lock);
 
+	if (fb->modifier ==
+		DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
+		AFBC_FORMAT_MOD_SPARSE)) {

You check this modifier condition a few times, how about having a helper for it?

Quoted 26 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +15 -0
+		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 +1132,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)

drivers/gpu/drm/rockchip/rockchip_drm_fb.c static void vop_crtc_atomic_flush(struct drm_crtc *crtc, · line 1477

Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +3 -0
@@ -1340,6 +1472,10 @@ 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
+	 */

Nitpick: no need for multi-line style comments, if the comment is a single line. Also, you might want to end the comment with a stop.

Thanks!
Eze

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#40 lore raw

PATCH v2 4/4 drm/rockchip: Add support for afbc

In reply to Andrzej Pietrasiewicz

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

---
 drivers/gpu/drm/rockchip/Kconfig            |   1 +
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  42 ++++++
 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 +++++++++++-
 5 files changed, 276 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/Kconfig +1 -0
index 6f4222f8beeb..ff491efc52a5 100644
@@ -5,6 +5,7 @@ config DRM_ROCKCHIP
 	select DRM_GEM_CMA_HELPER
 	select DRM_KMS_HELPER
 	select DRM_PANEL
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	select DRM_ANALOGIX_DP if ROCKCHIP_ANALOGIX_DP
 	select DRM_DW_HDMI if ROCKCHIP_DW_HDMI
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +42 -0

63 lines not on this page · raw message

drivers/gpu/drm/rockchip/rockchip_drm_vop.c +139 -2

222 lines not on this page · raw message

drivers/gpu/drm/rockchip/rockchip_drm_vop.h +12 -0
index 0b3d18c457b2..3f4e88a783d2 100644
@@ -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;
drivers/gpu/drm/rockchip/rockchip_vop_reg.c +82 -2

199 lines not on this page · raw message

Signature · 6 lines
2.17.1

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
#41 lore raw

Re: [PATCHv2 4/4] drm/rockchip: Add support for afbc

Hi Andrzej,

drivers/gpu/drm/rockchip/rockchip_drm_fb.c rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm · line 39

Quoted 1 line · Andrzej Pietrasiewicz
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +1 -0
+	if (mode_cmd->modifier[0]) {

I believe this can still be DRM_FORMAT_MOD_INVALID, which != 0. You probably want to explicitly check if it's an AFBC modifier.

Quoted 13 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +7 -0
+		const struct drm_format_info *info;
+		int bpp;
+
+		if (!drm_afbc_check_offset(dev, mode_cmd))
+			return ERR_PTR(-EINVAL);
+
+		if (!drm_afbc_get_superblk_wh(mode_cmd->modifier[0],

&w, &h))

drivers/gpu/drm/rockchip/rockchip_drm_fb.c +5 -0
+			return ERR_PTR(-EINVAL);
+
+		if (w != 16 || h != 16) {
+			DRM_DEV_ERROR(dev->dev,
+				"Unsupported afbc tile w/h [%d/%d]\n",
Quoted 1 line

w, h);

This can just be a WARN_ONCE() or something, since it indicates an impossible condition - the DRM core should've already rejected this modifier as unsupported.

drivers/gpu/drm/rockchip/rockchip_drm_fb.c rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm · line 63

Quoted 6 lines
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +6 -0
+		if (mode_cmd->width > ROCKCHIP_MAX_AFBC_WIDTH) {
+			DRM_DEV_ERROR(dev->dev,
+				      "Unsupported width %d>%d\n",
+				      mode_cmd->width,
+				      ROCKCHIP_MAX_AFBC_WIDTH
+			);

Userspace shouldn't be allowed to spam the log by triggering error messages; please make this debug instead. Whilst you're there, adding logs to the other error returns here might be useful.

drivers/gpu/drm/rockchip/rockchip_drm_vop.c struct vop { · line 182

Quoted 5 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +1 -0
@@ -166,6 +179,7 @@ struct vop {
 	/* optional internal rgb encoder */
 	struct rockchip_rgb *rgb;
 
+	struct vop_win *afbc_win;

It seems like everywhere afbc_win is used, it's not actually used for the window value, but rather just used as an is_afbc_enabled bool. In that case, it would be better as a real bool, and living in either the output or plane state.

This would eliminate the need to unset the variable as well.

Relatedly, can one VOP support multiple simultaneous windows using AFBC? If not, the check that only one window is using AFBC is missing from this patch.

Quoted 5 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +5 -0
+static int vop_convert_afbc_format(uint32_t format)
+{
+	switch (format) {
+	case DRM_FORMAT_XRGB8888:
+	case DRM_FORMAT_ARGB8888:

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static enum vop_data_format vop_convert_format(uint32_t format) · line 305

Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +10 -0
+	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 */

Unreachable can be WARN_ONCE() rather than a silent return.

Other than that, this is looking a _lot_ nicer than v1 though!

Cheers,
Daniel

_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel

#42 lore raw

PATCH 2/2 drm/rockchip: Add support for afbc

In reply to Andrzej Pietrasiewicz

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

---
 drivers/gpu/drm/rockchip/Kconfig            |   1 +
 drivers/gpu/drm/rockchip/rockchip_drm_fb.c  |  43 ++++++
 drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 140 +++++++++++++++++++-
 drivers/gpu/drm/rockchip/rockchip_drm_vop.h |  12 ++
 drivers/gpu/drm/rockchip/rockchip_vop_reg.c |  86 +++++++++++-
 5 files changed, 278 insertions(+), 4 deletions(-)
drivers/gpu/drm/rockchip/Kconfig +1 -0
index 6f4222f8beeb..ff491efc52a5 100644
@@ -5,6 +5,7 @@ config DRM_ROCKCHIP
 	select DRM_GEM_CMA_HELPER
 	select DRM_KMS_HELPER
 	select DRM_PANEL
+	select DRM_AFBC
 	select VIDEOMODE_HELPERS
 	select DRM_ANALOGIX_DP if ROCKCHIP_ANALOGIX_DP
 	select DRM_DW_HDMI if ROCKCHIP_DW_HDMI
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +43 -0

61 lines not on this page · raw message

drivers/gpu/drm/rockchip/rockchip_drm_vop.c +138 -2

221 lines not on this page · raw message

drivers/gpu/drm/rockchip/rockchip_drm_vop.h +12 -0
index 2149a889c29d..371b28b933a9 100644
@@ -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;
@@ -128,6 +138,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;
@@ -167,6 +178,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;
drivers/gpu/drm/rockchip/rockchip_vop_reg.c +84 -2

201 lines not on this page · raw message

Signature · 1 line
2.17.1
#43 lore raw

Re: [PATCH 2/2] drm/rockchip: Add support for afbc

Hi Andrzej,

drivers/gpu/drm/rockchip/rockchip_drm_fb.c rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm · line 42

Quoted 9 lines · Andrzej Pietrasiewicz
drivers/gpu/drm/rockchip/rockchip_drm_fb.c +5 -0
@@ -32,6 +35,46 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm
        int ret;
        int i;
 
+       if (mode_cmd->modifier[0]) {
+               const struct drm_format_info *info;
+               int bpp;
+
+               if (mode_cmd->modifier[0] &

Use != here, not &~.

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static enum vop_data_format vop_convert_format(uint32_t format) · line 301

Quoted 7 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +7 -0
+       case DRM_FORMAT_BGR888:
+               return AFBC_FMT_U8U8U8;
+       case DRM_FORMAT_RGB565:
+       case DRM_FORMAT_BGR565:
+               return AFBC_FMT_RGB565;
+       default:
+               DRM_ERROR("unsupported afbc format[%08x]\n", format);

This should not be reachable, because you shouldn't be able to create a framebuffer with an unsupported format/modifier combination.

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_destroy(struct drm_plane *plane) · line 727

Quoted 12 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +12 -0
+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 (modifier & ~DRM_FORMAT_MOD_ARM_AFBC(

Again use != here.

Quoted 4 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +4 -0
+                               AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 |
+                               AFBC_FORMAT_MOD_SPARSE
+                       )
+       ) {

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_destroy(struct drm_plane *plane) · line 741

Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +10 -0
+               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;
+       }

This is where you should reject unsupported format + AFBC combinations. Doing it here prevents it from ever being advertised to userspace in the first place.

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_atomic_update(struct drm_plane *plane, · line 926

Quoted 9 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +5 -0
@@ -808,6 +919,24 @@ static void vop_plane_atomic_update(struct drm_plane *plane,
 
        spin_lock(&vop->reg_lock);
 
+       if (fb->modifier == DRM_FORMAT_MOD_ARM_AFBC(
+               AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE)) {
+               int afbc_format = vop_convert_afbc_format(fb->format->format);
+
+               VOP_AFBC_SET(vop, format, afbc_format | 1 << 4);

I assume the (1 << 4) programs the 16x16 block size. Can we support other block sizes?

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_atomic_update(struct drm_plane *plane, · line 927

Quoted 1 line
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +1 -0
+               VOP_AFBC_SET(vop, hreg_block_split, 0);

Does this mean we can also support AFBC_FORMAT_MOD_SPLIT?

drivers/gpu/drm/rockchip/rockchip_drm_vop.c static void vop_plane_atomic_update(struct drm_plane *plane, · line 937

Quoted 10 lines
drivers/gpu/drm/rockchip/rockchip_drm_vop.c +10 -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;
+
+               pr_info("AFBC on plane %s\n", plane->name);

Please do not use pr_info() here. Userspace should not be able to trigger logging, apart from DRM_DEBUG.

drivers/gpu/drm/rockchip/rockchip_vop_reg.c static const uint32_t formats_win_full[] = { · line 48

Quoted 2 lines
drivers/gpu/drm/rockchip/rockchip_vop_reg.c +2 -0
+static const uint64_t format_modifiers_win_full[] = {
+       DRM_FORMAT_MOD_NONE,

*DRM_FORMAT_MOD_LINEAR

Cheers,
Daniel
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel