[PATCH v2] (drm/rockchip) Reject AFBC for resolutions >2560x1600

From: Konstantin Shabanov
Date: Mon Apr 14 2025 - 05:55:06 EST


As it isn't supported by hardware. At least, RK3399 doesn't support
it. From the datasheet[1]
("1.2.10 Video IN/OUT", "Display Interface", p. 17):

Support AFBC function co-operation with GPU
* support 2560x1600 UI

Manually tested on RockPro64 (rk3399):
- ARM_AFBC modifier is used for 1920x1080
- DRM_FORMAT_MOD_LINEAR modifier us used for 3840x2160
- No noise on the screen when sway is running in 4k
- Dynamic resolution switching works correctly in sway

Signed-off-by: Konstantin Shabanov <mail@xxxxxxxxxxx>
Cc: Daniel Stone <daniel@xxxxxxxxxxxxx>
Reported-by: Dan Callaghan <djc@xxxxxxxxx>
Closes: https://gitlab.freedesktop.org/mesa/mesa/-/issues/7968

[1]: https://opensource.rock-chips.com/images/d/d7/Rockchip_RK3399_Datasheet_V2.1-20200323.pdf
---
drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 9 +++++++++
1 file changed, 9 insertions(+)

diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
index dcc1f07632c3..1379bc3cd937 100644
--- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
+++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c
@@ -18,6 +18,8 @@
#include "rockchip_drm_fb.h"
#include "rockchip_drm_gem.h"

+#define ROCKCHIP_AFBC_MAX_WIDTH 2560
+
static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
.destroy = drm_gem_fb_destroy,
.create_handle = drm_gem_fb_create_handle,
@@ -52,6 +54,13 @@ rockchip_fb_create(struct drm_device *dev, struct drm_file *file,
}

if (drm_is_afbc(mode_cmd->modifier[0])) {
+ if (mode_cmd->width > ROCKCHIP_AFBC_MAX_WIDTH) {
+ DRM_DEBUG_KMS("AFBC is not supported for the width %d (max %d)\n",
+ mode_cmd->width,
+ ROCKCHIP_AFBC_MAX_WIDTH);
+ return ERR_PTR(-EINVAL);
+ };
+
int ret, i;

ret = drm_gem_fb_afbc_init(dev, mode_cmd, afbc_fb);

base-commit: e7bb7d44c3b97aea1f0e354c6499900154ac67f2
--
2.48.1