From patchwork Tue Dec 17 14:49:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297835 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4515F13B6 for ; Tue, 17 Dec 2019 14:53:03 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2D00C24655 for ; Tue, 17 Dec 2019 14:53:03 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2D00C24655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D48C26EA15; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3AF356E9FF for ; Tue, 17 Dec 2019 14:52:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 35D5F2927AE From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 01/34] drm/core: Add afbc helper functions Date: Tue, 17 Dec 2019 15:49:47 +0100 Message-Id: <20191217145020.14645-2-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add checking if a modifier is afbc and getting afbc block size. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/drm_fourcc.c | 53 ++++++++++++++++++++++++++++++++++++ include/drm/drm_fourcc.h | 4 +++ 2 files changed, 57 insertions(+) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index b234bfaeda06..d14dd7c86020 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -29,6 +29,7 @@ #include #include +#include static char printable_char(int c) { @@ -393,3 +394,55 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, drm_format_info_block_height(info, plane)); } EXPORT_SYMBOL(drm_format_info_min_pitch); + +/** + * drm_is_afbc - test if the modifier describes an afbc buffer + * @modifier - modifier to be tested + * + * Returns: true if the modifier describes an afbc buffer + */ +bool drm_is_afbc(u64 modifier) +{ + /* is it ARM AFBC? */ + if ((modifier & DRM_FORMAT_MOD_ARM_AFBC(0)) == 0) + return false; + + /* Block size must be known */ + if ((modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) == 0) + return false; + + return true; +} +EXPORT_SYMBOL_GPL(drm_is_afbc); + +/** + * drm_afbc_get_superblock_wh - extract afbc block width/height from modifier + * @modifier: the modifier to be looked at + * @w: address of a place to store the block width + * @h: address of a place to store the block height + * + * Returns: true if the modifier describes a supported block size + */ +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h) +{ + switch (modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) { + case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: + *w = 16; + *h = 16; + break; + case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: + *w = 32; + *h = 8; + break; + case AFBC_FORMAT_MOD_BLOCK_SIZE_64x4: + /* fall through */ + case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8_64x4: + /* fall through */ + default: + DRM_DEBUG_KMS("Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n", + modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK); + return false; + } + return true; +} +EXPORT_SYMBOL_GPL(drm_afbc_get_superblock_wh); diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 306d1efeb5e0..7eb23062bf45 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -320,4 +320,8 @@ uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, int plane, unsigned int buffer_width); const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf); +bool drm_is_afbc(u64 modifier); + +bool drm_afbc_get_superblock_wh(u64 modifier, u32 *w, u32 *h); + #endif /* __DRM_FOURCC_H__ */ From patchwork Tue Dec 17 14:49:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297813 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id BA69E138C for ; Tue, 17 Dec 2019 14:52:43 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id A253124655 for ; Tue, 17 Dec 2019 14:52:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A253124655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E613A6EA06; Tue, 17 Dec 2019 14:52:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 0B2556E9FF for ; Tue, 17 Dec 2019 14:52:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 33DBE292777 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 02/34] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Date: Tue, 17 Dec 2019 15:49:48 +0100 Message-Id: <20191217145020.14645-3-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Prepare tools for drivers which need to allocate a struct drm_framebuffer (or a container of struct drm_framebuffer) explicitly, before calling helpers. In such a case we need new helpers which omit allocating the struct drm_framebuffer and this patch provides them. Consequently, they are used also inside the helpers themselves. The interested drivers will likely need to be able to perform object lookups and size checks in separate invocations and this patch provides that as well. Helpers themselves are updated, too. Signed-off-by: Andrzej Pietrasiewicz Reviewed-by: James Qian Wang (Arm Technology China) --- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 216 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 181 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index b9bcd310ca2d..b3494f6b66bb 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -54,6 +54,69 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, } EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj); +/** + * drm_gem_fb_init_with_funcs() - Initialize an already allocated framebuffer + * @fb: Framebuffer + * @dev: DRM device + * @mode_cmd: Metadata from the userspace framebuffer creation request + * @obj: GEM objects to be assigned to the framebuffer + * @num_planes: number of planes + * @funcs: vtable to be used for the framebuffer object + * + * This variant of the function allows passing a custom vtable. + * + * Returns: + * 0 on success or a negative error code + */ +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, + unsigned int num_planes, + const struct drm_framebuffer_funcs *funcs) +{ + int ret, i; + + drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd); + + for (i = 0; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret = drm_framebuffer_init(dev, fb, funcs); + if (ret) + DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n", ret); + + return ret; +} +EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +}; + +/** + * drm_gem_fb_init() - Initialize an already allocated framebuffer + * @fb: Framebuffer + * @dev: DRM device + * @mode_cmd: Metadata from the userspace framebuffer creation request + * @obj: GEM objects to be assigned to the framebuffer + * @num_planes: number of planes + * + * This variant of the function uses a default vtable. + * + * Returns: + * 0 on success or a negative error code + */ +int drm_gem_fb_init(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, unsigned int num_planes) +{ + return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL(drm_gem_fb_init); + static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, @@ -61,21 +124,14 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) { struct drm_framebuffer *fb; - int ret, i; + int ret; fb = kzalloc(sizeof(*fb), GFP_KERNEL); if (!fb) return ERR_PTR(-ENOMEM); - drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd); - - for (i = 0; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret = drm_framebuffer_init(dev, fb, funcs); + ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, funcs); if (ret) { - DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n", - ret); kfree(fb); return ERR_PTR(ret); } @@ -144,59 +200,29 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, const struct drm_framebuffer_funcs *funcs) { - const struct drm_format_info *info; struct drm_gem_object *objs[4]; struct drm_framebuffer *fb; - int ret, i; - - info = drm_get_format_info(dev, mode_cmd); - if (!info) - return ERR_PTR(-EINVAL); - - for (i = 0; i < info->num_planes; i++) { - unsigned int width = mode_cmd->width / (i ? info->hsub : 1); - unsigned int height = mode_cmd->height / (i ? info->vsub : 1); - unsigned int min_size; + int ret, num_planes; - objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); - if (!objs[i]) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - ret = -ENOENT; - goto err_gem_object_put; - } - - min_size = (height - 1) * mode_cmd->pitches[i] - + drm_format_info_min_pitch(info, i, width) - + mode_cmd->offsets[i]; + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + return ERR_PTR(ret); + num_planes = ret; - if (objs[i]->size < min_size) { - drm_gem_object_put_unlocked(objs[i]); - ret = -EINVAL; - goto err_gem_object_put; - } - } + ret = drm_gem_fb_size_check(dev, mode_cmd, objs); + if (ret) + fb = ERR_PTR(ret); + else + fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs); - fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs); - if (IS_ERR(fb)) { - ret = PTR_ERR(fb); - goto err_gem_object_put; - } + if (IS_ERR(fb)) + for (num_planes--; num_planes >= 0; num_planes--) + drm_gem_object_put_unlocked(objs[num_planes]); return fb; - -err_gem_object_put: - for (i--; i >= 0; i--) - drm_gem_object_put_unlocked(objs[i]); - - return ERR_PTR(ret); } EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; - /** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback @@ -228,6 +254,92 @@ drm_gem_fb_create(struct drm_device *dev, struct drm_file *file, } EXPORT_SYMBOL_GPL(drm_gem_fb_create); +/** + * drm_gem_fb_lookup() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations + * @dev: DRM device + * @file: DRM file that holds the GEM handle(s) backing the framebuffer + * @mode_cmd: Metadata from the userspace framebuffer creation request + * + * This function can be used to look up the objects for all planes. + * In case an error is returned all the objects are put by the + * function before returning. + * + * Returns: + * Number of planes on success or a negative error code on failure. + */ +int drm_gem_fb_lookup(struct drm_device *dev, + struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) +{ + const struct drm_format_info *info; + int ret, i; + + info = drm_get_format_info(dev, mode_cmd); + if (!info) + return -EINVAL; + + for (i = 0; i < info->num_planes; i++) { + objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); + if (!objs[i]) { + DRM_DEBUG_KMS("Failed to lookup GEM object\n"); + ret = -ENOENT; + goto err_gem_object_put; + } + } + + return i; + +err_gem_object_put: + for (i--; i >= 0; i--) + drm_gem_object_put_unlocked(objs[i]); + + return ret; +} +EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); + +/** + * drm_gem_fb_size_check() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations + * @dev: DRM device + * @mode_cmd: Metadata from the userspace framebuffer creation request + * + * This function can be used to verify buffer sizes for all planes. + * It is caller's responsibility to put the objects on failure. + * + * Returns: + * Zero on success or a negative error code on failure. + */ +int drm_gem_fb_size_check(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) +{ + const struct drm_format_info *info; + int i; + + info = drm_get_format_info(dev, mode_cmd); + if (!info) + return -EINVAL; + + for (i = 0; i < info->num_planes; i++) { + unsigned int width = mode_cmd->width / (i ? info->hsub : 1); + unsigned int height = mode_cmd->height / (i ? info->vsub : 1); + unsigned int min_size; + + min_size = (height - 1) * mode_cmd->pitches[i] + + drm_format_info_min_pitch(info, i, width) + + mode_cmd->offsets[i]; + + if (objs[i]->size < min_size) + return -EINVAL; + } + + return 0; + +} +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check); + static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle, diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index d9f13fd25b0a..c85d4b152e91 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -14,10 +14,27 @@ struct drm_simple_display_pipe; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, unsigned int plane); +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, + unsigned int num_planes, + const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, unsigned int num_planes); void drm_gem_fb_destroy(struct drm_framebuffer *fb); int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, unsigned int *handle); +int drm_gem_fb_lookup(struct drm_device *dev, + struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs); +int drm_gem_fb_size_check(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs); struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, From patchwork Tue Dec 17 14:49:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297801 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 27E50138C for ; Tue, 17 Dec 2019 14:52:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0F8B72146E for ; Tue, 17 Dec 2019 14:52:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0F8B72146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 674AE6EA00; Tue, 17 Dec 2019 14:52:25 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id E8C196EA00 for ; Tue, 17 Dec 2019 14:52:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 12AD22927A8 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 03/34] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Date: Tue, 17 Dec 2019 15:49:49 +0100 Message-Id: <20191217145020.14645-4-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The new version accepts a struct describing deviations from standard way of doing the size checks. The caller must provide the respective values. Signed-off-by: Andrzej Pietrasiewicz Reviewed-by: James Qian Wang (Arm Technology China) --- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 46 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 54 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index b3494f6b66bb..d2fce1ec8f37 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -300,8 +300,8 @@ int drm_gem_fb_lookup(struct drm_device *dev, EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); /** - * drm_gem_fb_size_check() - Helper function for use in - * &drm_mode_config_funcs.fb_create implementations + * drm_gem_fb_size_check2() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request * @@ -311,9 +311,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); * Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check(struct drm_device *dev, - const struct drm_mode_fb_cmd2 *mode_cmd, - struct drm_gem_object **objs) +int drm_gem_fb_size_check2(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs) { const struct drm_format_info *info; int i; @@ -326,10 +327,19 @@ int drm_gem_fb_size_check(struct drm_device *dev, unsigned int width = mode_cmd->width / (i ? info->hsub : 1); unsigned int height = mode_cmd->height / (i ? info->vsub : 1); unsigned int min_size; + u32 pitch = mode_cmd->pitches[i]; + + if (check && check->use_pitch_multiplier) + if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) + return -EINVAL; - min_size = (height - 1) * mode_cmd->pitches[i] - + drm_format_info_min_pitch(info, i, width) - + mode_cmd->offsets[i]; + if (check && check->use_min_size) + min_size = check->min_size[i]; + else + min_size = (height - 1) * pitch + + drm_format_info_min_pitch(info, i, width) + + mode_cmd->offsets[i]; if (objs[i]->size < min_size) return -EINVAL; @@ -338,6 +348,26 @@ int drm_gem_fb_size_check(struct drm_device *dev, return 0; } +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check2); + +/** + * drm_gem_fb_size_check() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations + * @dev: DRM device + * @mode_cmd: Metadata from the userspace framebuffer creation request + * + * This function can be used to verify buffer sizes for all planes. + * It is caller's responsibility to put the objects on failure. + * + * Returns: + * Zero on success or a negative error code on failure. + */ +int drm_gem_fb_size_check(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) +{ + return drm_gem_fb_size_check2(dev, mode_cmd, NULL, objs); +} EXPORT_SYMBOL_GPL(drm_gem_fb_size_check); static const struct drm_framebuffer_funcs drm_gem_fb_funcs_dirtyfb = { diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index c85d4b152e91..4955af96d6c3 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2; struct drm_plane; struct drm_plane_state; struct drm_simple_display_pipe; +struct drm_size_check; + +/** + * struct drm_size_check - Description of special requirements for size checks. + */ +struct drm_size_check { + unsigned int min_size[4]; + bool use_min_size; + u32 pitch_multiplier[4]; + u32 pitch_modulo; + bool use_pitch_multiplier; +}; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, unsigned int plane); @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check2(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs); int drm_gem_fb_size_check(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); From patchwork Tue Dec 17 14:49:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297803 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 608F8138C for ; Tue, 17 Dec 2019 14:52:34 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 486732146E for ; Tue, 17 Dec 2019 14:52:34 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 486732146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B8BEE6EA01; Tue, 17 Dec 2019 14:52:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id E56316EA00 for ; Tue, 17 Dec 2019 14:52:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 0F8C42927C6 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 04/34] drm/gem-fb-helper: Add generic afbc size checks Date: Tue, 17 Dec 2019 15:49:50 +0100 Message-Id: <20191217145020.14645-5-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Extend the size-checking special function to handle afbc. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 49 +++++++++++++++++-- include/drm/drm_framebuffer.h | 50 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 1 + 3 files changed, 96 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index d2fce1ec8f37..5fe9032a5ee8 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -21,6 +21,11 @@ #include #include +#define AFBC_HEADER_SIZE 16 +#define AFBC_TH_LAYOUT_ALIGNMENT 8 +#define AFBC_SUPERBLOCK_PIXELS 256 +#define AFBC_SUPERBLOCK_ALIGNMENT 128 + /** * DOC: overview * @@ -299,6 +304,34 @@ int drm_gem_fb_lookup(struct drm_device *dev, } EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); +static int drm_gem_afbc_min_size(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_afbc_framebuffer *afbc_fb) +{ + u32 n_blocks; + + if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &afbc_fb->block_width, &afbc_fb->block_height)) + return -EINVAL; + + /* tiled header afbc */ + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { + afbc_fb->block_width *= AFBC_TH_LAYOUT_ALIGNMENT; + afbc_fb->block_height *= AFBC_TH_LAYOUT_ALIGNMENT; + } + + afbc_fb->aligned_width = ALIGN(mode_cmd->width, afbc_fb->block_width); + afbc_fb->aligned_height = ALIGN(mode_cmd->height, afbc_fb->block_height); + afbc_fb->offset = mode_cmd->offsets[0]; + + n_blocks = (afbc_fb->aligned_width * afbc_fb->aligned_height) / AFBC_SUPERBLOCK_PIXELS; + afbc_fb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, afbc_fb->alignment_header); + + afbc_fb->afbc_size = afbc_fb->offset_payload + + n_blocks * ALIGN(afbc_fb->bpp * AFBC_SUPERBLOCK_PIXELS / 8, AFBC_SUPERBLOCK_ALIGNMENT); + + return 0; +} + /** * drm_gem_fb_size_check2() - Helper function for use in * &drm_mode_config_funcs.fb_create implementations @@ -334,19 +367,27 @@ int drm_gem_fb_size_check2(struct drm_device *dev, check->pitch_modulo) return -EINVAL; - if (check && check->use_min_size) + if (check && check->use_min_size) { min_size = check->min_size[i]; - else + } else if (check && check->data && drm_is_afbc(mode_cmd->modifier[0])) { + struct drm_afbc_framebuffer *afbc_fb; + int ret; + + afbc_fb = check->data; + ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc_fb); + if (ret < 0) + return ret; + min_size = ret; + } else { min_size = (height - 1) * pitch + drm_format_info_min_pitch(info, i, width) + mode_cmd->offsets[i]; - + } if (objs[i]->size < min_size) return -EINVAL; } return 0; - } EXPORT_SYMBOL_GPL(drm_gem_fb_size_check2); diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h index c0e0256e3e98..c8a06e37585a 100644 --- a/include/drm/drm_framebuffer.h +++ b/include/drm/drm_framebuffer.h @@ -297,4 +297,54 @@ int drm_framebuffer_plane_width(int width, int drm_framebuffer_plane_height(int height, const struct drm_framebuffer *fb, int plane); +/** + * struct drm_afbc_framebuffer - a special afbc frame buffer object + * + * A derived class of struct drm_framebuffer, dedicated for afbc use cases. + */ +struct drm_afbc_framebuffer { + /** + * @base: base framebuffer structure. + */ + struct drm_framebuffer base; + /** + * @block_widht: width of a single afbc block + */ + u32 block_width; + /** + * @block_widht: height of a single afbc block + */ + u32 block_height; + /** + * @aligned_width: aligned frame buffer width + */ + u32 aligned_width; + /** + * @aligned_height: aligned frame buffer height + */ + u32 aligned_height; + /** + * @offset: offset of the first afbc header + */ + u32 offset; + /** + * @alignment_header: required alignment for afbc headers + */ + u32 alignment_header; + /** + * @afbc_size: minimum size of afbc buffer + */ + u32 afbc_size; + /** + * @offset_payload: start of afbc body buffer + */ + u32 offset_payload; + /** + * @bpp: bpp value for this afbc buffer + */ + u32 bpp; +}; + +#define fb_to_afbc_fb(x) container_of(x, struct drm_afbc_framebuffer, base) + #endif diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index 4955af96d6c3..17e3f849a0fb 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -22,6 +22,7 @@ struct drm_size_check { u32 pitch_multiplier[4]; u32 pitch_modulo; bool use_pitch_multiplier; + void *data; }; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, From patchwork Tue Dec 17 14:49:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297805 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 60EAB138C for ; Tue, 17 Dec 2019 14:52:36 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 48C9324655 for ; Tue, 17 Dec 2019 14:52:36 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 48C9324655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EDB3A6EA04; Tue, 17 Dec 2019 14:52:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id C5DF26EA00 for ; Tue, 17 Dec 2019 14:52:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id EE01B2927B2 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 05/34] drm/komeda: Use afbc helper Date: Tue, 17 Dec 2019 15:49:51 +0100 Message-Id: <20191217145020.14645-6-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Makes the code shorter and more readable. Signed-off-by: Andrzej Pietrasiewicz --- .../drm/arm/display/komeda/komeda_framebuffer.c | 16 ++-------------- 1 file changed, 2 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 1b01a625f40e..2f993a9cfb8b 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -52,20 +52,8 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, return -ENOENT; } - switch (fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) { - case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: - alignment_w = 32; - alignment_h = 8; - break; - case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: - alignment_w = 16; - alignment_h = 16; - break; - default: - WARN(1, "Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n", - fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK); - break; - } + if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h)) + return -EINVAL; /* tiled header afbc */ if (fb->modifier & AFBC_FORMAT_MOD_TILED) { From patchwork Tue Dec 17 14:49:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297817 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D15C613B6 for ; Tue, 17 Dec 2019 14:52:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B963824676 for ; Tue, 17 Dec 2019 14:52:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B963824676 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 96E406EA09; Tue, 17 Dec 2019 14:52:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id ABAC96EA01 for ; Tue, 17 Dec 2019 14:52:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id C923B2927DB From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 06/34] drm/komeda: Move checking src coordinates to komeda_fb_create Date: Tue, 17 Dec 2019 15:49:52 +0100 Message-Id: <20191217145020.14645-7-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Next step towards unifying afbc and non-afbc cases as much as possible. Signed-off-by: Andrzej Pietrasiewicz --- .../drm/arm/display/komeda/komeda_framebuffer.c | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 2f993a9cfb8b..5a1e5f621a8f 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -106,9 +106,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, u32 i, block_h; u64 min_size; - if (komeda_fb_check_src_coords(kfb, 0, 0, fb->width, fb->height)) - return -EINVAL; - for (i = 0; i < info->num_planes; i++) { obj = drm_gem_object_lookup(file, mode_cmd->handles[i]); if (!obj) { @@ -167,10 +164,17 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); - if (kfb->base.modifier) + if (kfb->base.modifier) { ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd); - else + } else { + if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, + kfb->base.height)) { + kfree(kfb); + return ERR_PTR(-EINVAL); + } + ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd); + } if (ret < 0) goto err_cleanup; From patchwork Tue Dec 17 14:49:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297807 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 26D45138C for ; Tue, 17 Dec 2019 14:52:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0EBD824655 for ; Tue, 17 Dec 2019 14:52:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0EBD824655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E488A6EA03; Tue, 17 Dec 2019 14:52:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id A0CC66EA01 for ; Tue, 17 Dec 2019 14:52:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id B61562927BA From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 07/34] drm/komeda: Use the already available local variable Date: Tue, 17 Dec 2019 15:49:53 +0100 Message-Id: <20191217145020.14645-8-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" There is a local "info" variable which is exactly fb->format, so use it. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 5a1e5f621a8f..33181bdab16b 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -130,7 +130,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, } } - if (fb->format->num_planes == 3) { + if (info->num_planes == 3) { if (fb->pitches[1] != fb->pitches[2]) { DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); return -EINVAL; From patchwork Tue Dec 17 14:49:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297843 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E7253138C for ; Tue, 17 Dec 2019 14:53:08 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id CEE7A2146E for ; Tue, 17 Dec 2019 14:53:08 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org CEE7A2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3EC316EA1A; Tue, 17 Dec 2019 14:52:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id CBEB76EA02 for ; Tue, 17 Dec 2019 14:52:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id B2F8F2927AE From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 08/34] drm/komeda: Retrieve drm_format_info once Date: Tue, 17 Dec 2019 15:49:54 +0100 Message-Id: <20191217145020.14645-9-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Next step towards unifying afbc and non-afbc cases as much as possible. Signed-off-by: Andrzej Pietrasiewicz --- .../drm/arm/display/komeda/komeda_framebuffer.c | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 33181bdab16b..7004c3c8f8de 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -37,11 +37,12 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { }; static int -komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, +komeda_fb_afbc_size_check(struct komeda_fb *kfb, + const struct drm_format_info *info, + struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { struct drm_framebuffer *fb = &kfb->base; - const struct drm_format_info *info = fb->format; struct drm_gem_object *obj; u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; u64 min_size; @@ -96,12 +97,13 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, } static int -komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, +komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, + struct komeda_fb *kfb, + const struct drm_format_info *info, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { struct drm_framebuffer *fb = &kfb->base; - const struct drm_format_info *info = fb->format; struct drm_gem_object *obj; u32 i, block_h; u64 min_size; @@ -146,6 +148,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, { struct komeda_dev *mdev = dev->dev_private; struct komeda_fb *kfb; + const struct drm_format_info *info; int ret = 0, i; kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); @@ -163,9 +166,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); + info = kfb->base.format; if (kfb->base.modifier) { - ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd); + ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); } else { if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height)) { @@ -173,7 +177,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(-EINVAL); } - ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd); + ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file, + mode_cmd); } if (ret < 0) goto err_cleanup; From patchwork Tue Dec 17 14:49:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297811 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3B1BB13B6 for ; Tue, 17 Dec 2019 14:52:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 22D1024655 for ; Tue, 17 Dec 2019 14:52:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 22D1024655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8BD3C6EA02; Tue, 17 Dec 2019 14:52:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id D3F436EA07 for ; Tue, 17 Dec 2019 14:52:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id C4548292765 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 09/34] drm/komeda: Explicitly require 1 plane for AFBC Date: Tue, 17 Dec 2019 15:49:55 +0100 Message-Id: <20191217145020.14645-10-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Apparently komeda silently assumes that there is only 1 plane in an AFBC buffer. Make this assumption explicit. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 7004c3c8f8de..c0bc499a9c29 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -169,6 +169,11 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format; if (kfb->base.modifier) { + if (info->num_planes != 1) { + DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); + kfree(kfb); + return ERR_PTR(-EINVAL); + } ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); } else { if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, From patchwork Tue Dec 17 14:49:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297821 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 59A2313B6 for ; Tue, 17 Dec 2019 14:52:53 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 415E92146E for ; Tue, 17 Dec 2019 14:52:53 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 415E92146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 887696EA05; Tue, 17 Dec 2019 14:52:48 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id C3B5F6EA02 for ; Tue, 17 Dec 2019 14:52:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id DB7B6292777 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 10/34] drm/komeda: Move pitches comparison to komeda_fb_create Date: Tue, 17 Dec 2019 15:49:56 +0100 Message-Id: <20191217145020.14645-11-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" For AFBC case num_planes equals 1 so the check will not affect it. Signed-off-by: Andrzej Pietrasiewicz --- .../drm/arm/display/komeda/komeda_framebuffer.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index c0bc499a9c29..5d035f6a76a6 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -132,13 +132,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, } } - if (info->num_planes == 3) { - if (fb->pitches[1] != fb->pitches[2]) { - DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); - return -EINVAL; - } - } - return 0; } @@ -188,6 +181,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret < 0) goto err_cleanup; + if (info->num_planes == 3) + if (kfb->base.pitches[1] != kfb->base.pitches[2]) { + DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); + ret = -EINVAL; + goto err_cleanup; + } + ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs); if (ret < 0) { DRM_DEBUG_KMS("failed to initialize fb\n"); From patchwork Tue Dec 17 14:49:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297815 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5085813B6 for ; Tue, 17 Dec 2019 14:52:45 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 37CA62146E for ; Tue, 17 Dec 2019 14:52:45 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 37CA62146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D9B0A6EA0A; Tue, 17 Dec 2019 14:52:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id DBB8F6EA02 for ; Tue, 17 Dec 2019 14:52:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id CCD422927C2 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 11/34] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Date: Tue, 17 Dec 2019 15:49:57 +0100 Message-Id: <20191217145020.14645-12-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Add a variant of the function which doesn't need neither struct drm_framebuffer nor container_of it. Maintain current interface for existing users. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 68 +++++++++++++++---- .../arm/display/komeda/komeda_framebuffer.h | 7 ++ 2 files changed, 61 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 5d035f6a76a6..08f31478c6a8 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -123,7 +123,12 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, return -EINVAL; } - min_size = komeda_fb_get_pixel_addr(kfb, 0, fb->height, i) + min_size = komeda_fb_get_pixel_addr_nofb(info, + mode_cmd->modifier[0], + mode_cmd->pitches, + mode_cmd->offsets, + obj, + 0, mode_cmd->height, i) - to_drm_gem_cma_obj(obj)->paddr; if (obj->size < min_size) { DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n", @@ -237,12 +242,56 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb, return 0; } +dma_addr_t +komeda_fb_get_pixel_addr_impl(const struct drm_format_info *format, + u64 modifier, + const unsigned int *pitches, + const unsigned int *offsets, + const struct drm_gem_cma_object *obj, + int x, int y, int plane) +{ + u32 offset, plane_x, plane_y, block_w, block_sz; + + offset = offsets[plane]; + if (modifier) { + block_w = drm_format_info_block_width(format, plane); + block_sz = format->char_per_block[plane]; + plane_x = x / (plane ? format->hsub : 1); + plane_y = y / (plane ? format->vsub : 1); + + offset += (plane_x / block_w) * block_sz + + plane_y * pitches[plane]; + } + + return obj->paddr + offset; +} + +dma_addr_t +komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format, + u64 modifier, + const unsigned int *pitches, + const unsigned int *offsets, + struct drm_gem_object *obj, + int x, int y, int plane) +{ + const struct drm_gem_cma_object *cma_obj; + + if (plane >= format->num_planes) { + DRM_DEBUG_KMS("Out of max plane num.\n"); + return -EINVAL; + } + + cma_obj = to_drm_gem_cma_obj(obj); + + return komeda_fb_get_pixel_addr_impl(format, modifier, pitches, offsets, + cma_obj, x, y, plane); +} + dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) { struct drm_framebuffer *fb = &kfb->base; const struct drm_gem_cma_object *obj; - u32 offset, plane_x, plane_y, block_w, block_sz; if (plane >= fb->format->num_planes) { DRM_DEBUG_KMS("Out of max plane num.\n"); @@ -251,18 +300,9 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) obj = drm_fb_cma_get_gem_obj(fb, plane); - offset = fb->offsets[plane]; - if (!fb->modifier) { - block_w = drm_format_info_block_width(fb->format, plane); - block_sz = fb->format->char_per_block[plane]; - plane_x = x / (plane ? fb->format->hsub : 1); - plane_y = y / (plane ? fb->format->vsub : 1); - - offset += (plane_x / block_w) * block_sz - + plane_y * fb->pitches[plane]; - } - - return obj->paddr + offset; + return komeda_fb_get_pixel_addr_impl(fb->format, fb->modifier, + fb->pitches, fb->offsets, + obj, x, y, plane); } /* if the fb can be supported by a specific layer */ diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h index c61ca98a3a63..2f1f421d3e7f 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h @@ -42,6 +42,13 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb, u32 src_x, u32 src_y, u32 src_w, u32 src_h); dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane); +dma_addr_t +komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format, + u64 modifier, + const unsigned int *pitches, + const unsigned int *offsets, + struct drm_gem_object *obj, + int x, int y, int plane); bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type, u32 rot); From patchwork Tue Dec 17 14:49:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297839 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CA4513B6 for ; Tue, 17 Dec 2019 14:53:06 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 142412146E for ; Tue, 17 Dec 2019 14:53:06 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 142412146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C36F6EA1C; Tue, 17 Dec 2019 14:52:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 278DB6EA02 for ; Tue, 17 Dec 2019 14:52:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 0D4FE2927BE From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 12/34] drm/komeda: Factor out object lookups for non-afbc case Date: Tue, 17 Dec 2019 15:49:58 +0100 Message-Id: <20191217145020.14645-13-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Ultimately we want lookups happening only once in komeda's fb_create implementation. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 21 ++++++++++++------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 08f31478c6a8..2014cd843aeb 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -100,6 +100,7 @@ static int komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, const struct drm_format_info *info, + struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { @@ -109,12 +110,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, u64 min_size; for (i = 0; i < info->num_planes; i++) { - obj = drm_gem_object_lookup(file, mode_cmd->handles[i]); - if (!obj) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return -ENOENT; - } - fb->obj[i] = obj; + obj = objs[i]; block_h = drm_format_info_block_height(info, i); if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) { @@ -174,14 +170,23 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); } else { + struct drm_gem_object *objs[4]; + if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height)) { kfree(kfb); return ERR_PTR(-EINVAL); } + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) { + kfree(kfb); + return ERR_PTR(ret); + } - ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file, - mode_cmd); + ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs, + file, mode_cmd); + for (i = 0; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; } if (ret < 0) goto err_cleanup; From patchwork Tue Dec 17 14:49:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297819 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 65EE2138C for ; Tue, 17 Dec 2019 14:52:48 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 482132146E for ; Tue, 17 Dec 2019 14:52:48 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 482132146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8B1736EA08; Tue, 17 Dec 2019 14:52:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1A6386EA02 for ; Tue, 17 Dec 2019 14:52:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 33CE82927CA From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 13/34] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Date: Tue, 17 Dec 2019 15:49:59 +0100 Message-Id: <20191217145020.14645-14-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" All necessary data is now available in other data structures. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 2014cd843aeb..43db95a76291 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -98,13 +98,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, static int komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, - struct komeda_fb *kfb, const struct drm_format_info *info, struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_framebuffer *fb = &kfb->base; struct drm_gem_object *obj; u32 i, block_h; u64 min_size; @@ -113,9 +111,10 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, obj = objs[i]; block_h = drm_format_info_block_height(info, i); - if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) { + if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) { DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n", - i, fb->pitches[i], mdev->chip.bus_width); + i, mode_cmd->pitches[i], + mdev->chip.bus_width); return -EINVAL; } @@ -183,7 +182,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(ret); } - ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs, + ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); for (i = 0; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; From patchwork Tue Dec 17 14:50:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B10914B7 for ; Tue, 17 Dec 2019 14:52:40 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5298C24655 for ; Tue, 17 Dec 2019 14:52:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5298C24655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E8A7E6EA07; Tue, 17 Dec 2019 14:52:36 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id E99E26EA02 for ; Tue, 17 Dec 2019 14:52:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 1A2DC2927D9 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 14/34] drm/komeda: Factor out object lookups for afbc case Date: Tue, 17 Dec 2019 15:50:00 +0100 Message-Id: <20191217145020.14645-15-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Ultimately we want lookups happening only once in komeda's fb_create implementation. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 30 +++++++++++-------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 43db95a76291..6b11a1b21ef6 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -39,6 +39,7 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { static int komeda_fb_afbc_size_check(struct komeda_fb *kfb, const struct drm_format_info *info, + struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { @@ -47,11 +48,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; u64 min_size; - obj = drm_gem_object_lookup(file, mode_cmd->handles[0]); - if (!obj) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return -ENOENT; - } + obj = objs[0]; if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h)) return -EINVAL; @@ -70,7 +67,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, if (fb->offsets[0] % alignment_header) { DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); - goto check_failed; + return -EINVAL; } n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS; @@ -85,15 +82,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, if (min_size > obj->size) { DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n", obj->size, min_size); - goto check_failed; + return -EINVAL; } - fb->obj[0] = obj; return 0; - -check_failed: - drm_gem_object_put_unlocked(obj); - return -EINVAL; } static int @@ -162,12 +154,24 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format; if (kfb->base.modifier) { + struct drm_gem_object *objs[4]; + if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); kfree(kfb); return ERR_PTR(-EINVAL); } - ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); + + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) { + kfree(kfb); + return ERR_PTR(ret); + } + + ret = komeda_fb_afbc_size_check(kfb, info, objs, file, + mode_cmd); + for (i = 0; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; } else { struct drm_gem_object *objs[4]; From patchwork Tue Dec 17 14:50:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297825 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2AA3114B7 for ; Tue, 17 Dec 2019 14:52:56 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1270E2146E for ; Tue, 17 Dec 2019 14:52:56 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1270E2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5C2DC6EA11; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7D89D6EA02 for ; Tue, 17 Dec 2019 14:52:35 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id EB0272927CE From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 15/34] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Date: Tue, 17 Dec 2019 15:50:01 +0100 Message-Id: <20191217145020.14645-16-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" It does still depend on komeda_fb, but only for komeda-specific parameters. Signed-off-by: Andrzej Pietrasiewicz --- .../drm/arm/display/komeda/komeda_framebuffer.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 6b11a1b21ef6..aa703aabbeee 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -43,18 +43,17 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_framebuffer *fb = &kfb->base; struct drm_gem_object *obj; u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; u64 min_size; obj = objs[0]; - if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h)) + if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) return -EINVAL; /* tiled header afbc */ - if (fb->modifier & AFBC_FORMAT_MOD_TILED) { + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; alignment_header = AFBC_TH_BODY_START_ALIGNMENT; @@ -62,10 +61,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, alignment_header = AFBC_BODY_START_ALIGNMENT; } - kfb->aligned_w = ALIGN(fb->width, alignment_w); - kfb->aligned_h = ALIGN(fb->height, alignment_h); + kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); + kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); - if (fb->offsets[0] % alignment_header) { + if (mode_cmd->offsets[0] % alignment_header) { DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); return -EINVAL; } @@ -74,11 +73,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, alignment_header); - bpp = komeda_get_afbc_format_bpp(info, fb->modifier); + bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); kfb->afbc_size = kfb->offset_payload + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); - min_size = kfb->afbc_size + fb->offsets[0]; + min_size = kfb->afbc_size + mode_cmd->offsets[0]; if (min_size > obj->size) { DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n", obj->size, min_size); From patchwork Tue Dec 17 14:50:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297831 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8632F138C for ; Tue, 17 Dec 2019 14:53:00 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6E5FF24655 for ; Tue, 17 Dec 2019 14:53:00 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6E5FF24655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3B6856EA10; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id B64896EA05 for ; Tue, 17 Dec 2019 14:52:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 98D892927C9 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 16/34] drm/komeda: Simplify error handling Date: Tue, 17 Dec 2019 15:50:02 +0100 Message-Id: <20191217145020.14645-17-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use less code to handle errors. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index aa703aabbeee..f50f83c68c70 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -145,8 +145,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (!kfb->format_caps) { DRM_DEBUG_KMS("FMT %x is not supported.\n", mode_cmd->pixel_format); - kfree(kfb); - return ERR_PTR(-EINVAL); + ret = -EINVAL; + goto err_free; } drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); @@ -157,15 +157,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); - kfree(kfb); - return ERR_PTR(-EINVAL); + ret = -EINVAL; + goto err_free; } ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) { - kfree(kfb); - return ERR_PTR(ret); - } + if (ret < 0) + goto err_free; ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); @@ -174,16 +172,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } else { struct drm_gem_object *objs[4]; - if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, - kfb->base.height)) { - kfree(kfb); - return ERR_PTR(-EINVAL); - } + ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, + kfb->base.height); + if (ret) + goto err_free; + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) { - kfree(kfb); - return ERR_PTR(ret); - } + if (ret < 0) + goto err_free; ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); @@ -214,7 +210,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup: for (i = 0; i < kfb->base.format->num_planes; i++) drm_gem_object_put_unlocked(kfb->base.obj[i]); - +err_free: kfree(kfb); return ERR_PTR(ret); } From patchwork Tue Dec 17 14:50:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297827 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8816813B6 for ; Tue, 17 Dec 2019 14:52:57 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 6FC7B2146E for ; Tue, 17 Dec 2019 14:52:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6FC7B2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C34F6EA0E; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id C911D6EA05 for ; Tue, 17 Dec 2019 14:52:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id B9B332927DD From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 17/34] drm/komeda: Move object lookup before size checks Date: Tue, 17 Dec 2019 15:50:03 +0100 Message-Id: <20191217145020.14645-18-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The lookup is performed the same way in both branches of the "if" statement, so move the lookup to before the "if". err_cleanup case is adjusted accordingly. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 23 +++++++------------ 1 file changed, 8 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index f50f83c68c70..acffceeb26f1 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -131,6 +131,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { struct komeda_dev *mdev = dev->dev_private; + struct drm_gem_object *objs[4]; struct komeda_fb *kfb; const struct drm_format_info *info; int ret = 0, i; @@ -149,37 +150,29 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free; } + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + goto err_free; + drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); info = kfb->base.format; if (kfb->base.modifier) { - struct drm_gem_object *objs[4]; - if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; - goto err_free; + goto err_cleanup; } - ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) - goto err_free; - ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); for (i = 0; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; } else { - struct drm_gem_object *objs[4]; - ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height); if (ret) - goto err_free; - - ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) - goto err_free; + goto err_cleanup; ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); @@ -209,7 +202,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup: for (i = 0; i < kfb->base.format->num_planes; i++) - drm_gem_object_put_unlocked(kfb->base.obj[i]); + drm_gem_object_put_unlocked(objs[i]); err_free: kfree(kfb); return ERR_PTR(ret); From patchwork Tue Dec 17 14:50:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297833 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DBB5F13B6 for ; Tue, 17 Dec 2019 14:53:01 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C2DF12146E for ; Tue, 17 Dec 2019 14:53:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C2DF12146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EA3B56EA16; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id C91A46EA05 for ; Tue, 17 Dec 2019 14:52:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id C09FD2927DF From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 18/34] drm/komeda: Move object assignments to framebuffer to after size checks Date: Tue, 17 Dec 2019 15:50:04 +0100 Message-Id: <20191217145020.14645-19-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The assignments are the same in both branches of the "if" statement and nothing depends on them between their original position and the new position, so this can be safely done. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index acffceeb26f1..d52278ca27fb 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -166,8 +166,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); - for (i = 0; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; } else { ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height); @@ -176,8 +174,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); - for (i = 0; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; } if (ret < 0) goto err_cleanup; @@ -189,6 +185,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } + for (i = 0; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; + ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs); if (ret < 0) { DRM_DEBUG_KMS("failed to initialize fb\n"); From patchwork Tue Dec 17 14:50:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297837 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD7E8138C for ; Tue, 17 Dec 2019 14:53:04 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 929E724655 for ; Tue, 17 Dec 2019 14:53:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 929E724655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 77D936EA13; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 018706EA05 for ; Tue, 17 Dec 2019 14:52:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id DE489292850 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 19/34] drm/komeda: Make the size checks independent from framebuffer structure Date: Tue, 17 Dec 2019 15:50:05 +0100 Message-Id: <20191217145020.14645-20-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The same data is available in mode_cmd. Signed-off-by: Andrzej Pietrasiewicz --- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index d52278ca27fb..42ccd4647919 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -155,9 +155,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free; drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); - info = kfb->base.format; + info = drm_get_format_info(dev, mode_cmd); - if (kfb->base.modifier) { + if (mode_cmd->modifier[0]) { if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; @@ -167,8 +167,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); } else { - ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, - kfb->base.height); + ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, + mode_cmd->height); if (ret) goto err_cleanup; @@ -179,7 +179,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; if (info->num_planes == 3) - if (kfb->base.pitches[1] != kfb->base.pitches[2]) { + if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) { DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); ret = -EINVAL; goto err_cleanup; From patchwork Tue Dec 17 14:50:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297823 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD8E413B6 for ; Tue, 17 Dec 2019 14:52:54 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C57372146E for ; Tue, 17 Dec 2019 14:52:54 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C57372146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 13E916EA0F; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5903E6EA0B for ; Tue, 17 Dec 2019 14:52:41 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 00C042927E3 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 20/34] drm/komeda: Move helper invocation to after size checks Date: Tue, 17 Dec 2019 15:50:06 +0100 Message-Id: <20191217145020.14645-21-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Between the old and new place nothing depends on data retrieved with the helper, so it is safe to move its invocation. The err_cleanup case is changed accordingly. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 42ccd4647919..c2b29d4e6fbb 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -154,7 +154,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret < 0) goto err_free; - drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { @@ -185,6 +184,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } + drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); + for (i = 0; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; @@ -200,7 +201,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return &kfb->base; err_cleanup: - for (i = 0; i < kfb->base.format->num_planes; i++) + for (i = 0; i < info->num_planes; i++) drm_gem_object_put_unlocked(objs[i]); err_free: kfree(kfb); From patchwork Tue Dec 17 14:50:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297849 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0548813B6 for ; Tue, 17 Dec 2019 14:53:13 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E135C2146E for ; Tue, 17 Dec 2019 14:53:12 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E135C2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id EF5036EA24; Tue, 17 Dec 2019 14:52:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 89EEC6EA05 for ; Tue, 17 Dec 2019 14:52:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 78001292871 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 21/34] drm/komeda: Use helper for common tasks Date: Tue, 17 Dec 2019 15:50:07 +0100 Message-Id: <20191217145020.14645-22-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The replaced fragment is 1:1 with the helper code. Signed-off-by: Andrzej Pietrasiewicz --- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index c2b29d4e6fbb..26d1a3cfb587 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -184,17 +184,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); - - for (i = 0; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; - - ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs); - if (ret < 0) { - DRM_DEBUG_KMS("failed to initialize fb\n"); - + ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs, + info->num_planes, &komeda_fb_funcs); + if (ret < 0) goto err_cleanup; - } kfb->is_va = mdev->iommu ? true : false; From patchwork Tue Dec 17 14:50:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297845 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 37AAA138C for ; Tue, 17 Dec 2019 14:53:10 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1F4C52146E for ; Tue, 17 Dec 2019 14:53:10 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1F4C52146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 53BAE6EA1B; Tue, 17 Dec 2019 14:52:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2602D6EA05 for ; Tue, 17 Dec 2019 14:52:44 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id ACC88292879 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 22/34] drm/komeda: Use return value of drm_gem_fb_lookup Date: Tue, 17 Dec 2019 15:50:08 +0100 Message-Id: <20191217145020.14645-23-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Reduce dependency of the function on the "info" variable as much as possible. Signed-off-by: Andrzej Pietrasiewicz --- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 26d1a3cfb587..9139fe5619be 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -134,7 +134,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, struct drm_gem_object *objs[4]; struct komeda_fb *kfb; const struct drm_format_info *info; - int ret = 0, i; + int ret = 0, i, num_planes; kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); if (!kfb) @@ -153,11 +153,12 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); if (ret < 0) goto err_free; + num_planes = ret; info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { - if (info->num_planes != 1) { + if (num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; goto err_cleanup; @@ -177,7 +178,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret < 0) goto err_cleanup; - if (info->num_planes == 3) + if (num_planes == 3) if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) { DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); ret = -EINVAL; @@ -185,7 +186,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs, - info->num_planes, &komeda_fb_funcs); + num_planes, &komeda_fb_funcs); if (ret < 0) goto err_cleanup; @@ -194,7 +195,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return &kfb->base; err_cleanup: - for (i = 0; i < info->num_planes; i++) + for (i = 0; i < num_planes; i++) drm_gem_object_put_unlocked(objs[i]); err_free: kfree(kfb); From patchwork Tue Dec 17 14:50:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297829 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0DC0C13B6 for ; Tue, 17 Dec 2019 14:52:59 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id E9AE32467E for ; Tue, 17 Dec 2019 14:52:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E9AE32467E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0C1E16EA0D; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 853FB6EA05 for ; Tue, 17 Dec 2019 14:52:45 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 41F9B292884 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 23/34] drm/komeda: Use special helper for non-afbc size checks Date: Tue, 17 Dec 2019 15:50:09 +0100 Message-Id: <20191217145020.14645-24-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use the generic helper code. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 46 +++++++++---------- 1 file changed, 21 insertions(+), 25 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 9139fe5619be..d75176e24f24 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -88,42 +88,38 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, } static int -komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, +komeda_fb_none_afbc_size_check(struct drm_device *dev, const struct drm_format_info *info, struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + struct komeda_dev *mdev = dev->dev_private; + struct drm_size_check check = { 0 }; struct drm_gem_object *obj; - u32 i, block_h; - u64 min_size; + u32 i; for (i = 0; i < info->num_planes; i++) { obj = objs[i]; - block_h = drm_format_info_block_height(info, i); - if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) { - DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n", - i, mode_cmd->pitches[i], - mdev->chip.bus_width); - return -EINVAL; - } - - min_size = komeda_fb_get_pixel_addr_nofb(info, - mode_cmd->modifier[0], - mode_cmd->pitches, - mode_cmd->offsets, - obj, - 0, mode_cmd->height, i) - - to_drm_gem_cma_obj(obj)->paddr; - if (obj->size < min_size) { - DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n", - i, obj->size, min_size); - return -EINVAL; - } + check.pitch_multiplier[i] = + drm_format_info_block_height(info, i); + + check.min_size[i] = + komeda_fb_get_pixel_addr_nofb(info, + mode_cmd->modifier[0], + mode_cmd->pitches, + mode_cmd->offsets, + obj, + 0, mode_cmd->height, i) + - to_drm_gem_cma_obj(obj)->paddr; } - return 0; + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + + return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); } struct drm_framebuffer * @@ -172,7 +168,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret) goto err_cleanup; - ret = komeda_fb_none_afbc_size_check(mdev, info, objs, + ret = komeda_fb_none_afbc_size_check(dev, info, objs, file, mode_cmd); } if (ret < 0) From patchwork Tue Dec 17 14:50:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297841 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7A7E413B6 for ; Tue, 17 Dec 2019 14:53:07 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 627702146E for ; Tue, 17 Dec 2019 14:53:07 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 627702146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 92B106EA14; Tue, 17 Dec 2019 14:52:50 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 997276EA05 for ; Tue, 17 Dec 2019 14:52:46 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 91A2E292890 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 24/34] drm/komeda: Factor in the invocation of special helper Date: Tue, 17 Dec 2019 15:50:10 +0100 Message-Id: <20191217145020.14645-25-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Don't use a separate function to call the helper. The ultimate goal is to unify non-afbc and afbc cases as much as possible and then moving the helper invocation outside the if-else clause. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 57 +++++++------------ 1 file changed, 20 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index d75176e24f24..766b6944c53c 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -87,41 +87,6 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, return 0; } -static int -komeda_fb_none_afbc_size_check(struct drm_device *dev, - const struct drm_format_info *info, - struct drm_gem_object **objs, - struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - struct komeda_dev *mdev = dev->dev_private; - struct drm_size_check check = { 0 }; - struct drm_gem_object *obj; - u32 i; - - for (i = 0; i < info->num_planes; i++) { - obj = objs[i]; - - check.pitch_multiplier[i] = - drm_format_info_block_height(info, i); - - check.min_size[i] = - komeda_fb_get_pixel_addr_nofb(info, - mode_cmd->modifier[0], - mode_cmd->pitches, - mode_cmd->offsets, - obj, - 0, mode_cmd->height, i) - - to_drm_gem_cma_obj(obj)->paddr; - } - - check.pitch_modulo = mdev->chip.bus_width; - check.use_pitch_multiplier = true; - check.use_min_size = true; - - return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); -} - struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -163,13 +128,31 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); } else { + struct drm_size_check check = { 0 }; + ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, mode_cmd->height); if (ret) goto err_cleanup; - ret = komeda_fb_none_afbc_size_check(dev, info, objs, - file, mode_cmd); + for (i = 0; i < num_planes; i++) { + check.pitch_multiplier[i] = + drm_format_info_block_height(info, i); + + check.min_size[i] = + komeda_fb_get_pixel_addr_nofb(info, + mode_cmd->modifier[0], + mode_cmd->pitches, + mode_cmd->offsets, objs[i], + 0, mode_cmd->height, i) + - to_drm_gem_cma_obj(objs[i])->paddr; + } + + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + + ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); } if (ret < 0) goto err_cleanup; From patchwork Tue Dec 17 14:50:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297847 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A05FD13B6 for ; Tue, 17 Dec 2019 14:53:11 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 885162146E for ; Tue, 17 Dec 2019 14:53:11 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 885162146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D0BB06EA19; Tue, 17 Dec 2019 14:52:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 99DAF6EA0B for ; Tue, 17 Dec 2019 14:52:48 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id BC4022927D0 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 25/34] drm/komeda: Use special helper for afbc case size check Date: Tue, 17 Dec 2019 15:50:11 +0100 Message-Id: <20191217145020.14645-26-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use generic helper code. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 22 +++++++------------ 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 766b6944c53c..2c9691b86cff 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -37,17 +37,15 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { }; static int -komeda_fb_afbc_size_check(struct komeda_fb *kfb, +komeda_fb_afbc_size_check(struct drm_device *dev, + struct komeda_fb *kfb, const struct drm_format_info *info, struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_gem_object *obj; + struct drm_size_check check = { 0 }; u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; - u64 min_size; - - obj = objs[0]; if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) return -EINVAL; @@ -77,14 +75,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->afbc_size = kfb->offset_payload + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); - min_size = kfb->afbc_size + mode_cmd->offsets[0]; - if (min_size > obj->size) { - DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n", - obj->size, min_size); - return -EINVAL; - } + check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; + check.use_min_size = true; - return 0; + return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); } struct drm_framebuffer * @@ -125,8 +119,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - ret = komeda_fb_afbc_size_check(kfb, info, objs, file, - mode_cmd); + ret = komeda_fb_afbc_size_check(dev, kfb, info, objs, + file, mode_cmd); } else { struct drm_size_check check = { 0 }; From patchwork Tue Dec 17 14:50:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297851 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 75897138C for ; Tue, 17 Dec 2019 14:53:32 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5D20724655 for ; Tue, 17 Dec 2019 14:53:32 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D20724655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id AC4736EA12; Tue, 17 Dec 2019 14:53:31 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 37BEA6EA19 for ; Tue, 17 Dec 2019 14:52:49 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 8DCF329289D From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 26/34] drm/komeda: Factor in the invocation of special helper, afbc case Date: Tue, 17 Dec 2019 15:50:12 +0100 Message-Id: <20191217145020.14645-27-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Prepare for unification with non-afbc case. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/komeda_framebuffer.c | 84 ++++++++----------- 1 file changed, 37 insertions(+), 47 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 2c9691b86cff..7e02a04cdd11 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -36,51 +36,6 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { .create_handle = komeda_fb_create_handle, }; -static int -komeda_fb_afbc_size_check(struct drm_device *dev, - struct komeda_fb *kfb, - const struct drm_format_info *info, - struct drm_gem_object **objs, - struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - struct drm_size_check check = { 0 }; - u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; - - if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) - return -EINVAL; - - /* tiled header afbc */ - if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { - alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_header = AFBC_TH_BODY_START_ALIGNMENT; - } else { - alignment_header = AFBC_BODY_START_ALIGNMENT; - } - - kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); - kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); - - if (mode_cmd->offsets[0] % alignment_header) { - DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); - return -EINVAL; - } - - n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS; - kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, - alignment_header); - - bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); - kfb->afbc_size = kfb->offset_payload + n_blocks * - ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, - AFBC_SUPERBLK_ALIGNMENT); - check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; - check.use_min_size = true; - - return drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); -} - struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -113,14 +68,49 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { + struct drm_size_check check = { 0 }; + u32 alignment_w = 0, alignment_h = 0; + u32 alignment_header, n_blocks, bpp; + if (num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; goto err_cleanup; } - ret = komeda_fb_afbc_size_check(dev, kfb, info, objs, - file, mode_cmd); + if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) { + ret = -EINVAL; + goto err_cleanup; + } + + /* tiled header afbc */ + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { + alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; + alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; + alignment_header = AFBC_TH_BODY_START_ALIGNMENT; + } else { + alignment_header = AFBC_BODY_START_ALIGNMENT; + } + + kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); + kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); + + if (mode_cmd->offsets[0] % alignment_header) { + DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); + ret = -EINVAL; + goto err_cleanup; + } + + n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS; + kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, alignment_header); + + bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); + kfb->afbc_size = kfb->offset_payload + + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); + check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; + check.use_min_size = true; + + ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); } else { struct drm_size_check check = { 0 }; From patchwork Tue Dec 17 14:50:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297861 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6577714B7 for ; Tue, 17 Dec 2019 14:53:43 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 4D50D2146E for ; Tue, 17 Dec 2019 14:53:43 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D50D2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E674E6EA22; Tue, 17 Dec 2019 14:53:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7FB8E6EA24 for ; Tue, 17 Dec 2019 14:52:51 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 037C029289E From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 27/34] drm/komeda: Move special helper invocation outside if-else Date: Tue, 17 Dec 2019 15:50:13 +0100 Message-Id: <20191217145020.14645-28-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The invocation is the same in both cases and is the last thing inside a block, so move it outside the if-else clause. Signed-off-by: Andrzej Pietrasiewicz --- .../gpu/drm/arm/display/komeda/komeda_framebuffer.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 7e02a04cdd11..bf4309b62d37 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -44,6 +44,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, struct drm_gem_object *objs[4]; struct komeda_fb *kfb; const struct drm_format_info *info; + struct drm_size_check check = { 0 }; + int ret = 0, i, num_planes; kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); @@ -68,7 +70,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { - struct drm_size_check check = { 0 }; u32 alignment_w = 0, alignment_h = 0; u32 alignment_header, n_blocks, bpp; @@ -109,11 +110,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; check.use_min_size = true; - - ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); } else { - struct drm_size_check check = { 0 }; - ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, mode_cmd->height); if (ret) @@ -135,9 +132,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, check.pitch_modulo = mdev->chip.bus_width; check.use_pitch_multiplier = true; check.use_min_size = true; - - ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); } + ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); if (ret < 0) goto err_cleanup; From patchwork Tue Dec 17 14:50:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297855 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8F40213B6 for ; Tue, 17 Dec 2019 14:53:38 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 76D602146E for ; Tue, 17 Dec 2019 14:53:38 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 76D602146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id BAEA46EA1E; Tue, 17 Dec 2019 14:53:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 40F566EA12 for ; Tue, 17 Dec 2019 14:52:56 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id AB8882928AD From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 28/34] drm/komeda: Move to helper checking afbc buffer size Date: Tue, 17 Dec 2019 15:50:14 +0100 Message-Id: <20191217145020.14645-29-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use generic helper code. Adapt struct komeda_fb users to new location of respective data members. Signed-off-by: Andrzej Pietrasiewicz --- .../arm/display/komeda/d71/d71_component.c | 6 +-- .../arm/display/komeda/komeda_framebuffer.c | 44 +++++-------------- .../arm/display/komeda/komeda_framebuffer.h | 14 ++---- .../display/komeda/komeda_pipeline_state.c | 14 +++--- 4 files changed, 26 insertions(+), 52 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c index 8a02ade369db..5131e51e56d4 100644 --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c @@ -186,7 +186,7 @@ static void d71_layer_update_fb(struct komeda_component *c, struct komeda_fb *kfb, dma_addr_t *addr) { - struct drm_framebuffer *fb = &kfb->base; + struct drm_framebuffer *fb = &kfb->base.base; const struct drm_format_info *info = fb->format; u32 __iomem *reg = c->reg; int block_h; @@ -234,9 +234,9 @@ static void d71_layer_update(struct komeda_component *c, st->afbc_crop_b)); /* afbc 1.2 wants payload, afbc 1.0/1.1 wants end_addr */ if (fb->modifier & AFBC_FORMAT_MOD_TILED) - addr = st->addr[0] + kfb->offset_payload; + addr = st->addr[0] + kfb->base.offset_payload; else - addr = st->addr[0] + kfb->afbc_size - 1; + addr = st->addr[0] + kfb->base.afbc_size - 1; malidp_write32(reg, BLK_P1_PTR_LOW, lower_32_bits(addr)); malidp_write32(reg, BLK_P1_PTR_HIGH, upper_32_bits(addr)); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index bf4309b62d37..45318ed052a9 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -70,46 +70,26 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { - u32 alignment_w = 0, alignment_h = 0; - u32 alignment_header, n_blocks, bpp; - if (num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; goto err_cleanup; } - if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) { - ret = -EINVAL; - goto err_cleanup; - } - /* tiled header afbc */ - if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { - alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_header = AFBC_TH_BODY_START_ALIGNMENT; - } else { - alignment_header = AFBC_BODY_START_ALIGNMENT; - } - - kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); - kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) + kfb->base.alignment_header = AFBC_TH_BODY_START_ALIGNMENT; + else + kfb->base.alignment_header = AFBC_BODY_START_ALIGNMENT; - if (mode_cmd->offsets[0] % alignment_header) { + if (mode_cmd->offsets[0] % kfb->base.alignment_header) { DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); ret = -EINVAL; goto err_cleanup; } - n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS; - kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, alignment_header); - - bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); - kfb->afbc_size = kfb->offset_payload - + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); - check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; - check.use_min_size = true; + kfb->base.bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); + check.data = &kfb->base; } else { ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, mode_cmd->height); @@ -144,14 +124,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs, + ret = drm_gem_fb_init_with_funcs(&kfb->base.base, dev, mode_cmd, objs, num_planes, &komeda_fb_funcs); if (ret < 0) goto err_cleanup; kfb->is_va = mdev->iommu ? true : false; - return &kfb->base; + return &kfb->base.base; err_cleanup: for (i = 0; i < num_planes; i++) @@ -164,7 +144,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, int komeda_fb_check_src_coords(const struct komeda_fb *kfb, u32 src_x, u32 src_y, u32 src_w, u32 src_h) { - const struct drm_framebuffer *fb = &kfb->base; + const struct drm_framebuffer *fb = &kfb->base.base; const struct drm_format_info *info = fb->format; u32 block_w = drm_format_info_block_width(fb->format, 0); u32 block_h = drm_format_info_block_height(fb->format, 0); @@ -239,7 +219,7 @@ komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format, dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) { - struct drm_framebuffer *fb = &kfb->base; + struct drm_framebuffer *fb = &kfb->base.base; const struct drm_gem_cma_object *obj; if (plane >= fb->format->num_planes) { @@ -258,7 +238,7 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type, u32 rot) { - struct drm_framebuffer *fb = &kfb->base; + struct drm_framebuffer *fb = &kfb->base.base; struct komeda_dev *mdev = fb->dev->dev_private; u32 fourcc = fb->format->format; u64 modifier = fb->modifier; diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h index 2f1f421d3e7f..6cb9d321b6d4 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h @@ -14,8 +14,8 @@ * struct komeda_fb - Entending drm_framebuffer with komeda attribute */ struct komeda_fb { - /** @base: &drm_framebuffer */ - struct drm_framebuffer base; + /** @base: &drm_afbc_framebuffer */ + struct drm_afbc_framebuffer base; /** * @format_caps: * extends drm_format_info for komeda specific information @@ -23,17 +23,9 @@ struct komeda_fb { const struct komeda_format_caps *format_caps; /** @is_va: if smmu is enabled, it will be true */ bool is_va; - /** @aligned_w: aligned frame buffer width */ - u32 aligned_w; - /** @aligned_h: aligned frame buffer height */ - u32 aligned_h; - /** @afbc_size: minimum size of afbc */ - u32 afbc_size; - /** @offset_payload: start of afbc body buffer */ - u32 offset_payload; }; -#define to_kfb(dfb) container_of(dfb, struct komeda_fb, base) +#define to_kfb(dfb) container_of(dfb, struct komeda_fb, base.base) struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c index 0930234abb9d..f7721244edad 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c @@ -320,7 +320,7 @@ komeda_layer_check_cfg(struct komeda_layer *layer, else line_sz = dflow->in_w; - if (kfb->base.format->hsub > 1) + if (kfb->base.base.format->hsub > 1) max_line_sz = layer->yuv_line_sz; else max_line_sz = layer->line_sz; @@ -360,12 +360,14 @@ komeda_layer_validate(struct komeda_layer *layer, st->rot = dflow->rot; if (fb->modifier) { - st->hsize = kfb->aligned_w; - st->vsize = kfb->aligned_h; + st->hsize = kfb->base.aligned_width; + st->vsize = kfb->base.aligned_height; st->afbc_crop_l = dflow->in_x; - st->afbc_crop_r = kfb->aligned_w - dflow->in_x - dflow->in_w; + st->afbc_crop_r = kfb->base.aligned_width + - dflow->in_x - dflow->in_w; st->afbc_crop_t = dflow->in_y; - st->afbc_crop_b = kfb->aligned_h - dflow->in_y - dflow->in_h; + st->afbc_crop_b = kfb->base.aligned_height + - dflow->in_y - dflow->in_h; } else { st->hsize = dflow->in_w; st->vsize = dflow->in_h; @@ -419,7 +421,7 @@ komeda_wb_layer_validate(struct komeda_layer *wb_layer, st->hsize = dflow->out_w; st->vsize = dflow->out_h; - for (i = 0; i < kfb->base.format->num_planes; i++) + for (i = 0; i < kfb->base.base.format->num_planes; i++) st->addr[i] = komeda_fb_get_pixel_addr(kfb, dflow->out_x, dflow->out_y, i); From patchwork Tue Dec 17 14:50:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297857 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 029CA13B6 for ; Tue, 17 Dec 2019 14:53:41 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DE1572146E for ; Tue, 17 Dec 2019 14:53:40 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DE1572146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D619C6EA1F; Tue, 17 Dec 2019 14:53:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 87D906EA1D for ; Tue, 17 Dec 2019 14:52:57 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 508EA2928BD From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 29/34] drm/arm/malidp: Make verify funcitons invocations independent Date: Tue, 17 Dec 2019 15:50:15 +0100 Message-Id: <20191217145020.14645-30-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This will make it easier to transition to generic afbc-aware helpers. Signed-off-by: Andrzej Pietrasiewicz Reviewed-by: Boris Brezillon --- drivers/gpu/drm/arm/malidp_drv.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 37d92a06318e..961e5a3f5b08 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -362,10 +362,10 @@ static bool malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - if (malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) - return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); + if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) + return false; - return false; + return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); } static struct drm_framebuffer * From patchwork Tue Dec 17 14:50:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297853 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CB34F138C for ; Tue, 17 Dec 2019 14:53:33 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id B313B2146E for ; Tue, 17 Dec 2019 14:53:33 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B313B2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 066A76EA1D; Tue, 17 Dec 2019 14:53:32 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id B93136EA12 for ; Tue, 17 Dec 2019 14:52:58 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 93A502928C6 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 30/34] drm/arm/malidp: Integrate verify functions Date: Tue, 17 Dec 2019 15:50:16 +0100 Message-Id: <20191217145020.14645-31-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The next step towards using generic afbc-aware helpers. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/malidp_drv.c | 36 ++++++++------------------------ 1 file changed, 9 insertions(+), 27 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index 961e5a3f5b08..e1502666bce0 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -270,9 +270,16 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { }; static bool -malidp_verify_afbc_framebuffer_caps(struct drm_device *dev, - const struct drm_mode_fb_cmd2 *mode_cmd) +malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd) { + int n_superblocks = 0; + const struct drm_format_info *info; + struct drm_gem_object *objs = NULL; + u32 afbc_superblock_size = 0, afbc_superblock_height = 0; + u32 afbc_superblock_width = 0, afbc_size = 0; + int bpp = 0; + if (malidp_format_mod_supported(dev, mode_cmd->pixel_format, mode_cmd->modifier[0]) == false) return false; @@ -294,21 +301,6 @@ malidp_verify_afbc_framebuffer_caps(struct drm_device *dev, return false; } - return true; -} - -static bool -malidp_verify_afbc_framebuffer_size(struct drm_device *dev, - struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - int n_superblocks = 0; - const struct drm_format_info *info; - struct drm_gem_object *objs = NULL; - u32 afbc_superblock_size = 0, afbc_superblock_height = 0; - u32 afbc_superblock_width = 0, afbc_size = 0; - int bpp = 0; - switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { case AFBC_SIZE_16X16: afbc_superblock_height = 16; @@ -358,16 +350,6 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev, return true; } -static bool -malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - if (!malidp_verify_afbc_framebuffer_caps(dev, mode_cmd)) - return false; - - return malidp_verify_afbc_framebuffer_size(dev, file, mode_cmd); -} - static struct drm_framebuffer * malidp_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) From patchwork Tue Dec 17 14:50:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297867 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6FA1B138C for ; Tue, 17 Dec 2019 14:53:47 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 576292146E for ; Tue, 17 Dec 2019 14:53:47 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 576292146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1B8006EA26; Tue, 17 Dec 2019 14:53:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id E04E46EA12 for ; Tue, 17 Dec 2019 14:52:59 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id C74642928D7 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 31/34] drm/arm/malidp: Factor in afbc framebuffer verification Date: Tue, 17 Dec 2019 15:50:17 +0100 Message-Id: <20191217145020.14645-32-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Prepare for using generic afbc-aware helpers. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/malidp_drv.c | 142 +++++++++++++++---------------- 1 file changed, 68 insertions(+), 74 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index e1502666bce0..b53fc01baf2b 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -269,94 +269,88 @@ static const struct drm_mode_config_helper_funcs malidp_mode_config_helpers = { .atomic_commit_tail = malidp_atomic_commit_tail, }; -static bool -malidp_verify_afbc_framebuffer(struct drm_device *dev, struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) +static struct drm_framebuffer * +malidp_fb_create(struct drm_device *dev, struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd) { - int n_superblocks = 0; - const struct drm_format_info *info; - struct drm_gem_object *objs = NULL; - u32 afbc_superblock_size = 0, afbc_superblock_height = 0; - u32 afbc_superblock_width = 0, afbc_size = 0; - int bpp = 0; - - if (malidp_format_mod_supported(dev, mode_cmd->pixel_format, - mode_cmd->modifier[0]) == false) - return false; - - if (mode_cmd->offsets[0] != 0) { - DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n"); - return false; - } + if (mode_cmd->modifier[0]) { + int n_superblocks = 0; + const struct drm_format_info *info; + struct drm_gem_object *objs = NULL; + u32 afbc_superblock_size = 0, afbc_superblock_height = 0; + u32 afbc_superblock_width = 0, afbc_size = 0; + int bpp = 0; + + if (malidp_format_mod_supported(dev, mode_cmd->pixel_format, + mode_cmd->modifier[0]) == false) + return ERR_PTR(-EINVAL); - switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { - case AFBC_SIZE_16X16: - if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) { - DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n"); - return false; + if (mode_cmd->offsets[0] != 0) { + DRM_DEBUG_KMS("AFBC buffers' plane offset should be 0\n"); + return ERR_PTR(-EINVAL); } - break; - default: - DRM_DEBUG_KMS("Unsupported AFBC block size\n"); - return false; - } - switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { - case AFBC_SIZE_16X16: - afbc_superblock_height = 16; - afbc_superblock_width = 16; - break; - default: - DRM_DEBUG_KMS("AFBC superblock size is not supported\n"); - return false; - } + switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { + case AFBC_SIZE_16X16: + if ((mode_cmd->width % 16) || (mode_cmd->height % 16)) { + DRM_DEBUG_KMS("AFBC buffers must be aligned to 16 pixels\n"); + return ERR_PTR(-EINVAL); + } + break; + default: + DRM_DEBUG_KMS("Unsupported AFBC block size\n"); + return ERR_PTR(-EINVAL); + } - info = drm_get_format_info(dev, mode_cmd); + switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { + case AFBC_SIZE_16X16: + afbc_superblock_height = 16; + afbc_superblock_width = 16; + break; + default: + DRM_DEBUG_KMS("AFBC superblock size is not supported\n"); + return ERR_PTR(-EINVAL); + } - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); + info = drm_get_format_info(dev, mode_cmd); - bpp = malidp_format_get_bpp(info->format); + n_superblocks = (mode_cmd->width / afbc_superblock_width) * + (mode_cmd->height / afbc_superblock_height); - afbc_superblock_size = (bpp * afbc_superblock_width * afbc_superblock_height) - / BITS_PER_BYTE; + bpp = malidp_format_get_bpp(info->format); - afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, AFBC_SUPERBLK_ALIGNMENT); - afbc_size += n_superblocks * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT); + afbc_superblock_size = + (bpp * afbc_superblock_width * afbc_superblock_height) + / BITS_PER_BYTE; - if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) { - DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " - "should be same as width (=%u) * bpp (=%u)\n", - (mode_cmd->pitches[0] * BITS_PER_BYTE), - mode_cmd->width, bpp); - return false; - } + afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, + AFBC_SUPERBLK_ALIGNMENT); + afbc_size += n_superblocks + * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT); - objs = drm_gem_object_lookup(file, mode_cmd->handles[0]); - if (!objs) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return false; - } - - if (objs->size < afbc_size) { - DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n", - objs->size, afbc_size); - drm_gem_object_put_unlocked(objs); - return false; - } - - drm_gem_object_put_unlocked(objs); + if ((mode_cmd->width * bpp) != + (mode_cmd->pitches[0] * BITS_PER_BYTE)) { + DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " + "should be same as width (=%u) * bpp (=%u)\n", + (mode_cmd->pitches[0] * BITS_PER_BYTE), + mode_cmd->width, bpp); + return ERR_PTR(-EINVAL); + } - return true; -} + objs = drm_gem_object_lookup(file, mode_cmd->handles[0]); + if (!objs) { + DRM_DEBUG_KMS("Failed to lookup GEM object\n"); + return ERR_PTR(-EINVAL); + } -static struct drm_framebuffer * -malidp_fb_create(struct drm_device *dev, struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - if (mode_cmd->modifier[0]) { - if (!malidp_verify_afbc_framebuffer(dev, file, mode_cmd)) + if (objs->size < afbc_size) { + DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n", + objs->size, afbc_size); + drm_gem_object_put_unlocked(objs); return ERR_PTR(-EINVAL); + } + + drm_gem_object_put_unlocked(objs); } return drm_gem_fb_create(dev, file, mode_cmd); From patchwork Tue Dec 17 14:50:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297865 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 46EE613B6 for ; Tue, 17 Dec 2019 14:53:46 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 2EB8724655 for ; Tue, 17 Dec 2019 14:53:46 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2EB8724655 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E20316EA23; Tue, 17 Dec 2019 14:53:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 1C8596EA12 for ; Tue, 17 Dec 2019 14:53:01 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id EAB09292803 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 32/34] drm/arm/malidp: Use generic helpers for afbc checks Date: Tue, 17 Dec 2019 15:50:18 +0100 Message-Id: <20191217145020.14645-33-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Helpers are now available for checking afbc buffer properties. Use those. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/arm/malidp_drv.c | 71 ++++++++++++++------------------ 1 file changed, 30 insertions(+), 41 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index b53fc01baf2b..4cbd920b48cd 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -273,12 +273,17 @@ static struct drm_framebuffer * malidp_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + struct drm_size_check check = { 0 }; + struct drm_gem_object *objs[4]; + struct drm_afbc_framebuffer *afbc_fb; + int ret, i, num_planes; + + afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL); + if (!afbc_fb) + return ERR_PTR(-ENOMEM); + if (mode_cmd->modifier[0]) { - int n_superblocks = 0; const struct drm_format_info *info; - struct drm_gem_object *objs = NULL; - u32 afbc_superblock_size = 0, afbc_superblock_height = 0; - u32 afbc_superblock_width = 0, afbc_size = 0; int bpp = 0; if (malidp_format_mod_supported(dev, mode_cmd->pixel_format, @@ -302,32 +307,9 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(-EINVAL); } - switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { - case AFBC_SIZE_16X16: - afbc_superblock_height = 16; - afbc_superblock_width = 16; - break; - default: - DRM_DEBUG_KMS("AFBC superblock size is not supported\n"); - return ERR_PTR(-EINVAL); - } - info = drm_get_format_info(dev, mode_cmd); - - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); - bpp = malidp_format_get_bpp(info->format); - afbc_superblock_size = - (bpp * afbc_superblock_width * afbc_superblock_height) - / BITS_PER_BYTE; - - afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, - AFBC_SUPERBLK_ALIGNMENT); - afbc_size += n_superblocks - * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT); - if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) { DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " @@ -336,24 +318,31 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file, mode_cmd->width, bpp); return ERR_PTR(-EINVAL); } + afbc_fb->bpp = bpp; + check.data = afbc_fb; + } - objs = drm_gem_object_lookup(file, mode_cmd->handles[0]); - if (!objs) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return ERR_PTR(-EINVAL); - } + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + goto err_free; + num_planes = ret; - if (objs->size < afbc_size) { - DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n", - objs->size, afbc_size); - drm_gem_object_put_unlocked(objs); - return ERR_PTR(-EINVAL); - } + ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); + if (ret < 0) + goto err_cleanup; - drm_gem_object_put_unlocked(objs); - } + ret = drm_gem_fb_init(&afbc_fb->base, dev, mode_cmd, objs, num_planes); + if (ret < 0) + goto err_cleanup; + + return &afbc_fb->base; - return drm_gem_fb_create(dev, file, mode_cmd); +err_cleanup: + for (i = 0; i < num_planes; ++i) + drm_gem_object_put_unlocked(objs[i]); +err_free: + kfree(afbc_fb); + return ERR_PTR(ret); } static const struct drm_mode_config_funcs malidp_mode_config_funcs = { From patchwork Tue Dec 17 14:50:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297863 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DF1B314B7 for ; Tue, 17 Dec 2019 14:53:44 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C6BFF2146E for ; Tue, 17 Dec 2019 14:53:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C6BFF2146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 0DA746EA25; Tue, 17 Dec 2019 14:53:39 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id D78CC6EA12 for ; Tue, 17 Dec 2019 14:53:02 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 554DE292905 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 33/34] drm/rockchip: Use helper for common task Date: Tue, 17 Dec 2019 15:50:19 +0100 Message-Id: <20191217145020.14645-34-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Use generic helper code. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 221e72e71432..5806f908aa53 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -18,6 +18,7 @@ #include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" + static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle, @@ -30,22 +31,13 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm { struct drm_framebuffer *fb; int ret; - int i; fb = kzalloc(sizeof(*fb), GFP_KERNEL); if (!fb) return ERR_PTR(-ENOMEM); - drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd); - - for (i = 0; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret = drm_framebuffer_init(dev, fb, &rockchip_drm_fb_funcs); + ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs); if (ret) { - DRM_DEV_ERROR(dev->dev, - "Failed to initialize framebuffer: %d\n", - ret); kfree(fb); return ERR_PTR(ret); } From patchwork Tue Dec 17 14:50:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11297859 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DD875138C for ; Tue, 17 Dec 2019 14:53:42 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C4FE12146E for ; Tue, 17 Dec 2019 14:53:42 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C4FE12146E Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=collabora.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D62146EA21; Tue, 17 Dec 2019 14:53:38 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from bhuna.collabora.co.uk (bhuna.collabora.co.uk [46.235.227.227]) by gabe.freedesktop.org (Postfix) with ESMTPS id 45E426EA1D for ; Tue, 17 Dec 2019 14:53:04 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id D2697292921 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv5 34/34] drm/rockchip: Add support for afbc Date: Tue, 17 Dec 2019 15:50:20 +0100 Message-Id: <20191217145020.14645-35-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191217145020.14645-1-andrzej.p@collabora.com> References: <20191213173350.GJ624164@phenom.ffwll.local> <20191217145020.14645-1-andrzej.p@collabora.com> X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ayan Halder , kernel@collabora.com, David Airlie , Liviu Dudau , Sandy Huang , Andrzej Pietrasiewicz , James Wang , Mihail Atanassov , Sean Paul MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" This patch adds support for afbc handling. afbc is a compressed format which reduces the necessary memory bandwidth. Co-developed-by: Mark Yao Signed-off-by: Mark Yao Signed-off-by: Andrzej Pietrasiewicz # Conflicts: # drivers/gpu/drm/rockchip/rockchip_drm_fb.c --- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 105 +++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 147 ++++++++++++++++++-- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 ++ drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 83 ++++++++++- 4 files changed, 329 insertions(+), 18 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 5806f908aa53..f26cbaa46135 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -18,6 +18,7 @@ #include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +#define ROCKCHIP_MAX_AFBC_WIDTH 2560 static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, @@ -25,32 +26,122 @@ static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .dirty = drm_atomic_helper_dirtyfb, }; +static int rockchip_afbc_post_check(struct drm_afbc_framebuffer *afbc_fb) +{ + if (afbc_fb->offset) { + DRM_WARN("AFBC plane offset must be zero!\n"); + return -EINVAL; + } + + if (afbc_fb->block_width != 16 || afbc_fb->block_height != 16) { + DRM_WARN("Unsupported AFBC block w/h [%d/%d]\n", afbc_fb->block_width, afbc_fb->block_height); + return -EINVAL; + } + + if (afbc_fb->aligned_width > ROCKCHIP_MAX_AFBC_WIDTH) { + DRM_WARN("Unsupported width %d>%d\n", afbc_fb->aligned_width, ROCKCHIP_MAX_AFBC_WIDTH); + return -EINVAL; + } + + return 0; +} + static struct drm_framebuffer * rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **obj, unsigned int num_planes) { - struct drm_framebuffer *fb; + struct drm_afbc_framebuffer *afbc_fb; + struct drm_size_check check = { 0 }; int ret; - fb = kzalloc(sizeof(*fb), GFP_KERNEL); - if (!fb) + afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL); + if (!afbc_fb) return ERR_PTR(-ENOMEM); - ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs); + if (drm_is_afbc(mode_cmd->modifier[0])) { + const struct drm_format_info *info = drm_get_format_info(dev, mode_cmd); + + afbc_fb->bpp = info->cpp[0] * 8; + check.data = afbc_fb; + } + + ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, obj); if (ret) { - kfree(fb); + kfree(afbc_fb); return ERR_PTR(ret); } - return fb; + if (drm_is_afbc(mode_cmd->modifier[0])) + if (rockchip_afbc_post_check(afbc_fb)) { + kfree(afbc_fb); + return ERR_PTR(-EINVAL); + } + + ret = drm_gem_fb_init_with_funcs(&afbc_fb->base, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs); + if (ret) { + kfree(afbc_fb); + return ERR_PTR(ret); + } + + return &afbc_fb->base; } static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers = { .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, }; + +static struct drm_framebuffer * +rockchip_fb_create(struct drm_device *dev, struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + struct drm_afbc_framebuffer *afbc_fb; + struct drm_size_check check = { 0 }; + struct drm_gem_object *objs[4]; + int ret, i, num_planes; + + afbc_fb = kzalloc(sizeof(*afbc_fb), GFP_KERNEL); + if (!afbc_fb) + return ERR_PTR(-ENOMEM); + + if (drm_is_afbc(mode_cmd->modifier[0])) { + const struct drm_format_info *info = drm_get_format_info(dev, mode_cmd); + + afbc_fb->bpp = info->cpp[0] * 8; + check.data = afbc_fb; + } + + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + goto err_free; + num_planes = ret; + + ret = drm_gem_fb_size_check2(dev, mode_cmd, &check, objs); + if (ret) + goto err_cleanup; + + if (drm_is_afbc(mode_cmd->modifier[0])) + if (rockchip_afbc_post_check(afbc_fb)) { + ret = -EINVAL; + goto err_cleanup; + } + + ret = drm_gem_fb_init_with_funcs(&afbc_fb->base, dev, mode_cmd, objs, num_planes, &rockchip_drm_fb_funcs); + if (ret) + goto err_cleanup; + + return &afbc_fb->base; + +err_cleanup: + for (i = 0; i < num_planes; ++i) + drm_gem_object_put_unlocked(objs[i]); +err_free: + kfree(afbc_fb); + return ERR_PTR(ret); +} + static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = { - .fb_create = drm_gem_fb_create_with_dirty, + .fb_create = rockchip_fb_create, .output_poll_changed = drm_fb_helper_output_poll_changed, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index d04b3492bdac..ffe1e4b9a9ca 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -91,9 +91,21 @@ #define VOP_WIN_TO_INDEX(vop_win) \ ((vop_win) - (vop_win)->vop->win) +#define VOP_AFBC_SET(vop, name, v) \ + do { \ + if ((vop)->data->afbc) \ + vop_reg_set((vop), &(vop)->data->afbc->name, 0, ~0, v, #name); \ + } while (0) + #define to_vop(x) container_of(x, struct vop, crtc) #define to_vop_win(x) container_of(x, struct vop_win, base) +#define AFBC_FMT_RGB565 0x0 +#define AFBC_FMT_U8U8U8U8 0x5 +#define AFBC_FMT_U8U8U8 0x4 + +#define AFBC_TILE_16x16 BIT(4) + /* * The coefficients of the following matrix are all fixed points. * The format is S2.10 for the 3x3 part of the matrix, and S9.12 for the offsets. @@ -166,6 +178,7 @@ struct vop { /* optional internal rgb encoder */ struct rockchip_rgb *rgb; + struct vop_win *afbc_win; struct vop_win win[]; }; @@ -274,6 +287,29 @@ static enum vop_data_format vop_convert_format(uint32_t format) } } +static int vop_convert_afbc_format(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_ABGR8888: + return AFBC_FMT_U8U8U8U8; + case DRM_FORMAT_RGB888: + case DRM_FORMAT_BGR888: + return AFBC_FMT_U8U8U8; + case DRM_FORMAT_RGB565: + case DRM_FORMAT_BGR565: + return AFBC_FMT_RGB565; + /* either of the below should not be reachable */ + default: + DRM_WARN_ONCE("unsupported AFBC format[%08x]\n", format); + return -EINVAL; + } + + return -EINVAL; +} + static uint16_t scl_vop_cal_scale(enum scale_mode mode, uint32_t src, uint32_t dst, bool is_horizontal, int vsu_mode, int *vskiplines) @@ -598,6 +634,15 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state) vop_win_disable(vop, vop_win); } } + + if (vop->data->afbc) { + /* + * Disable AFBC and forget there was a vop window with AFBC + */ + VOP_AFBC_SET(vop, enable, 0); + vop->afbc_win = NULL; + } + spin_unlock(&vop->reg_lock); vop_cfg_done(vop); @@ -710,6 +755,37 @@ static void vop_plane_destroy(struct drm_plane *plane) drm_plane_cleanup(plane); } +static bool rockchip_afbc(u64 modifier) +{ + return modifier == DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE); +} + +static bool rockchip_mod_supported(struct drm_plane *plane, + u32 format, u64 modifier) +{ + const struct drm_format_info *info; + + if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) + return false; + + if (modifier == DRM_FORMAT_MOD_LINEAR) + return true; + + if (!rockchip_afbc(modifier)) { + DRM_DEBUG_KMS("Unsupported format modifer 0x%llx\n", modifier); + + return false; + } + + info = drm_format_info(format); + if (info->num_planes != 1) { + DRM_DEBUG_KMS("AFBC buffers expect one plane\n"); + return false; + } + + return true; +} + static int vop_plane_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) { @@ -719,10 +795,8 @@ static int vop_plane_atomic_check(struct drm_plane *plane, struct vop_win *vop_win = to_vop_win(plane); const struct vop_win_data *win = vop_win->data; int ret; - int min_scale = win->phy->scl ? FRAC_16_16(1, 8) : - DRM_PLANE_HELPER_NO_SCALING; - int max_scale = win->phy->scl ? FRAC_16_16(8, 1) : - DRM_PLANE_HELPER_NO_SCALING; + int min_scale = win->phy->scl ? FRAC_16_16(1, 8) : DRM_PLANE_HELPER_NO_SCALING; + int max_scale = win->phy->scl ? FRAC_16_16(8, 1) : DRM_PLANE_HELPER_NO_SCALING; if (!crtc || !fb) return 0; @@ -731,9 +805,7 @@ static int vop_plane_atomic_check(struct drm_plane *plane, if (WARN_ON(!crtc_state)) return -EINVAL; - ret = drm_atomic_helper_check_plane_state(state, crtc_state, - min_scale, max_scale, - true, true); + ret = drm_atomic_helper_check_plane_state(state, crtc_state, min_scale, max_scale, true, true); if (ret) return ret; @@ -758,6 +830,31 @@ static int vop_plane_atomic_check(struct drm_plane *plane, return -EINVAL; } + if (rockchip_afbc(fb->modifier)) { + struct vop *vop = to_vop(crtc); + + if (!vop->data->afbc) { + DRM_ERROR("vop does not support AFBC\n"); + return -EINVAL; + } + + ret = vop_convert_afbc_format(fb->format->format); + if (ret < 0) + return ret; + + if (state->src.x1 || state->src.y1) { + DRM_ERROR("afbc does not support offset display\n"); + DRM_ERROR("xpos=%d, ypos=%d, offset=%d\n", state->src.x1, state->src.y1, fb->offsets[0]); + return -EINVAL; + } + + if (state->rotation && state->rotation != DRM_MODE_ROTATE_0) { + DRM_ERROR("afbc does not support rotation\n"); + DRM_ERROR("rotation=%d\n", state->rotation); + return -EINVAL; + } + } + return 0; } @@ -773,6 +870,11 @@ static void vop_plane_atomic_disable(struct drm_plane *plane, spin_lock(&vop->reg_lock); vop_win_disable(vop, vop_win); + /* + * Forget about the AFBC window if it is being disabled + */ + if (vop_win == vop->afbc_win) + vop->afbc_win = NULL; spin_unlock(&vop->reg_lock); } @@ -812,6 +914,13 @@ static void vop_plane_atomic_update(struct drm_plane *plane, if (WARN_ON(!vop->is_enabled)) return; + /* + * If updating the AFBC window then assume that + * after the update there will be no AFBC window. + */ + if (vop_win == vop->afbc_win) + vop->afbc_win = NULL; + if (!state->visible) { vop_plane_atomic_disable(plane, old_state); return; @@ -846,6 +955,21 @@ static void vop_plane_atomic_update(struct drm_plane *plane, spin_lock(&vop->reg_lock); + if (rockchip_afbc(fb->modifier)) { + int afbc_format = vop_convert_afbc_format(fb->format->format); + + VOP_AFBC_SET(vop, format, afbc_format | AFBC_TILE_16x16); + VOP_AFBC_SET(vop, hreg_block_split, 0); + VOP_AFBC_SET(vop, win_sel, VOP_WIN_TO_INDEX(vop_win)); + VOP_AFBC_SET(vop, hdr_ptr, dma_addr); + VOP_AFBC_SET(vop, pic_size, act_info); + + /* + * The window being udated becomes the AFBC window + */ + vop->afbc_win = vop_win; + } + VOP_WIN_SET(vop, win, format, format); VOP_WIN_SET(vop, win, yrgb_vir, DIV_ROUND_UP(fb->pitches[0], 4)); VOP_WIN_SET(vop, win, yrgb_mst, dma_addr); @@ -1001,6 +1125,7 @@ static const struct drm_plane_funcs vop_plane_funcs = { .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .format_mod_supported = rockchip_mod_supported, }; static int vop_crtc_enable_vblank(struct drm_crtc *crtc) @@ -1340,6 +1465,8 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc, spin_lock(&vop->reg_lock); + /* Enable AFBC if there is some AFBC window, disable otherwise. */ + VOP_AFBC_SET(vop, enable, vop->afbc_win != NULL); vop_cfg_done(vop); spin_unlock(&vop->reg_lock); @@ -1634,7 +1761,8 @@ static int vop_create_crtc(struct vop *vop) 0, &vop_plane_funcs, win_data->phy->data_formats, win_data->phy->nformats, - NULL, win_data->type, NULL); + win_data->phy->format_modifiers, + win_data->type, NULL); if (ret) { DRM_DEV_ERROR(vop->dev, "failed to init plane %d\n", ret); @@ -1678,7 +1806,8 @@ static int vop_create_crtc(struct vop *vop) &vop_plane_funcs, win_data->phy->data_formats, win_data->phy->nformats, - NULL, win_data->type, NULL); + win_data->phy->format_modifiers, + win_data->type, NULL); if (ret) { DRM_DEV_ERROR(vop->dev, "failed to init overlay %d\n", ret); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h index 0b3d18c457b2..3f4e88a783d2 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h @@ -34,6 +34,16 @@ struct vop_reg { bool relaxed; }; +struct vop_afbc { + struct vop_reg enable; + struct vop_reg win_sel; + struct vop_reg format; + struct vop_reg hreg_block_split; + struct vop_reg pic_size; + struct vop_reg hdr_ptr; + struct vop_reg rstn; +}; + struct vop_modeset { struct vop_reg htotal_pw; struct vop_reg hact_st_end; @@ -134,6 +144,7 @@ struct vop_win_phy { const struct vop_scl_regs *scl; const uint32_t *data_formats; uint32_t nformats; + const uint64_t *format_modifiers; struct vop_reg enable; struct vop_reg gate; @@ -173,6 +184,7 @@ struct vop_data { const struct vop_misc *misc; const struct vop_modeset *modeset; const struct vop_output *output; + const struct vop_afbc *afbc; const struct vop_win_yuv2yuv_data *win_yuv2yuv; const struct vop_win_data *win; unsigned int win_size; diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c index 7a9d979c8d5d..1f0b73c2e21e 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c @@ -50,6 +50,17 @@ static const uint32_t formats_win_full[] = { DRM_FORMAT_NV24, }; +static const uint64_t format_modifiers_win_full[] = { + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + +static const uint64_t format_modifiers_win_full_afbc[] = { + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | AFBC_FORMAT_MOD_SPARSE), + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + static const uint32_t formats_win_lite[] = { DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888, @@ -61,6 +72,11 @@ static const uint32_t formats_win_lite[] = { DRM_FORMAT_BGR565, }; +static const uint64_t format_modifiers_win_lite[] = { + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + static const struct vop_scl_regs rk3036_win_scl = { .scale_yrgb_x = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 0x0), .scale_yrgb_y = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 16), @@ -72,6 +88,7 @@ static const struct vop_win_phy rk3036_win0_data = { .scl = &rk3036_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 0), .format = VOP_REG(RK3036_SYS_CTRL, 0x7, 3), .rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 15), @@ -87,6 +104,7 @@ static const struct vop_win_phy rk3036_win0_data = { static const struct vop_win_phy rk3036_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1), .format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6), .rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19), @@ -153,6 +171,7 @@ static const struct vop_data rk3036_vop = { static const struct vop_win_phy rk3126_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1), .format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6), .rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19), @@ -234,6 +253,7 @@ static const struct vop_win_phy px30_win0_data = { .scl = &px30_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(PX30_WIN0_CTRL0, 0x1, 0), .format = VOP_REG(PX30_WIN0_CTRL0, 0x7, 1), .rb_swap = VOP_REG(PX30_WIN0_CTRL0, 0x1, 12), @@ -249,6 +269,7 @@ static const struct vop_win_phy px30_win0_data = { static const struct vop_win_phy px30_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(PX30_WIN1_CTRL0, 0x1, 0), .format = VOP_REG(PX30_WIN1_CTRL0, 0x7, 4), .rb_swap = VOP_REG(PX30_WIN1_CTRL0, 0x1, 12), @@ -261,6 +282,7 @@ static const struct vop_win_phy px30_win1_data = { static const struct vop_win_phy px30_win2_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .gate = VOP_REG(PX30_WIN2_CTRL0, 0x1, 4), .enable = VOP_REG(PX30_WIN2_CTRL0, 0x1, 0), .format = VOP_REG(PX30_WIN2_CTRL0, 0x3, 5), @@ -316,6 +338,7 @@ static const struct vop_win_phy rk3066_win0_data = { .scl = &rk3066_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 0), .format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 4), .rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 19), @@ -332,6 +355,7 @@ static const struct vop_win_phy rk3066_win1_data = { .scl = &rk3066_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 1), .format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 7), .rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 23), @@ -347,6 +371,7 @@ static const struct vop_win_phy rk3066_win1_data = { static const struct vop_win_phy rk3066_win2_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 2), .format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 10), .rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 27), @@ -426,6 +451,7 @@ static const struct vop_win_phy rk3188_win0_data = { .scl = &rk3188_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 0), .format = VOP_REG(RK3188_SYS_CTRL, 0x7, 3), .rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 15), @@ -440,6 +466,7 @@ static const struct vop_win_phy rk3188_win0_data = { static const struct vop_win_phy rk3188_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 1), .format = VOP_REG(RK3188_SYS_CTRL, 0x7, 6), .rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 19), @@ -545,6 +572,7 @@ static const struct vop_win_phy rk3288_win01_data = { .scl = &rk3288_win_full_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0), .format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1), .rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12), @@ -563,6 +591,7 @@ static const struct vop_win_phy rk3288_win01_data = { static const struct vop_win_phy rk3288_win23_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 4), .gate = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 0), .format = VOP_REG(RK3288_WIN2_CTRL0, 0x7, 1), @@ -677,6 +706,7 @@ static const struct vop_win_phy rk3368_win01_data = { .scl = &rk3288_win_full_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 0), .format = VOP_REG(RK3368_WIN0_CTRL0, 0x7, 1), .rb_swap = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 12), @@ -697,6 +727,7 @@ static const struct vop_win_phy rk3368_win01_data = { static const struct vop_win_phy rk3368_win23_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .gate = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 0), .enable = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 4), .format = VOP_REG(RK3368_WIN2_CTRL0, 0x3, 5), @@ -817,6 +848,53 @@ static const struct vop_win_yuv2yuv_data rk3399_vop_big_win_yuv2yuv_data[] = { .y2r_en = VOP_REG(RK3399_YUV2YUV_WIN, 0x1, 9) }, { .base = 0xC0, .phy = &rk3399_yuv2yuv_win23_data }, { .base = 0x120, .phy = &rk3399_yuv2yuv_win23_data }, + +}; + +static const struct vop_win_phy rk3399_win01_data = { + .scl = &rk3288_win_full_scl, + .data_formats = formats_win_full, + .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full_afbc, + .enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0), + .format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1), + .rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12), + .y_mir_en = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 22), + .act_info = VOP_REG(RK3288_WIN0_ACT_INFO, 0x1fff1fff, 0), + .dsp_info = VOP_REG(RK3288_WIN0_DSP_INFO, 0x0fff0fff, 0), + .dsp_st = VOP_REG(RK3288_WIN0_DSP_ST, 0x1fff1fff, 0), + .yrgb_mst = VOP_REG(RK3288_WIN0_YRGB_MST, 0xffffffff, 0), + .uv_mst = VOP_REG(RK3288_WIN0_CBR_MST, 0xffffffff, 0), + .yrgb_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 0), + .uv_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 16), + .src_alpha_ctl = VOP_REG(RK3288_WIN0_SRC_ALPHA_CTRL, 0xff, 0), + .dst_alpha_ctl = VOP_REG(RK3288_WIN0_DST_ALPHA_CTRL, 0xff, 0), +}; + +/* + * rk3399 vop big windows register layout is same as rk3288, but we + * have a separate rk3399 win data array here so that we can advertise + * AFBC on the primary plane. + */ +static const struct vop_win_data rk3399_vop_win_data[] = { + { .base = 0x00, .phy = &rk3399_win01_data, + .type = DRM_PLANE_TYPE_PRIMARY }, + { .base = 0x40, .phy = &rk3288_win01_data, + .type = DRM_PLANE_TYPE_OVERLAY }, + { .base = 0x00, .phy = &rk3288_win23_data, + .type = DRM_PLANE_TYPE_OVERLAY }, + { .base = 0x50, .phy = &rk3288_win23_data, + .type = DRM_PLANE_TYPE_CURSOR }, +}; + +static const struct vop_afbc rk3399_vop_afbc = { + .rstn = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 3), + .enable = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 0), + .win_sel = VOP_REG(RK3399_AFBCD0_CTRL, 0x3, 1), + .format = VOP_REG(RK3399_AFBCD0_CTRL, 0x1f, 16), + .hreg_block_split = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 21), + .hdr_ptr = VOP_REG(RK3399_AFBCD0_HDR_PTR, 0xffffffff, 0), + .pic_size = VOP_REG(RK3399_AFBCD0_PIC_SIZE, 0xffffffff, 0), }; static const struct vop_data rk3399_vop_big = { @@ -826,9 +904,10 @@ static const struct vop_data rk3399_vop_big = { .common = &rk3288_common, .modeset = &rk3288_modeset, .output = &rk3399_output, + .afbc = &rk3399_vop_afbc, .misc = &rk3368_misc, - .win = rk3368_vop_win_data, - .win_size = ARRAY_SIZE(rk3368_vop_win_data), + .win = rk3399_vop_win_data, + .win_size = ARRAY_SIZE(rk3399_vop_win_data), .win_yuv2yuv = rk3399_vop_big_win_yuv2yuv_data, };