From patchwork Fri Dec 13 15:58:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291415 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 36D532D2C for ; Fri, 13 Dec 2019 21:25: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 8D46424693 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8D46424693 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 05C7F6EA2D; Fri, 13 Dec 2019 15:59:22 +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 3F33A6E915 for ; Fri, 13 Dec 2019 15:59:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 46B0C292C56 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 01/36] drm/framebuffer: Add optional modifier info Date: Fri, 13 Dec 2019 16:58:32 +0100 Message-Id: <20191213155907.16581-2-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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" modifier_info is a pointer to an optional modifier-related information. Managing the memory needed for that information is the responsibility of drivers. Signed-off-by: Andrzej Pietrasiewicz Reviewed-by: James Qian Wang --- include/drm/drm_framebuffer.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h index c0e0256e3e98..2b3341b526d7 100644 --- a/include/drm/drm_framebuffer.h +++ b/include/drm/drm_framebuffer.h @@ -29,6 +29,7 @@ #include +struct drm_afbc; struct drm_clip_rect; struct drm_device; struct drm_file; @@ -139,6 +140,21 @@ struct drm_framebuffer { * @format: framebuffer format information */ const struct drm_format_info *format; + + union { + /** + * @modifier_info: pointer to an optional modifier-related + * information. Managing the memory holding that information + * is driver's responsibility. + */ + void *modifier_info; + + /** + * @afbc_info: afbc-specific pointer + */ + struct drm_afbc *afbc_info; + }; + /** * @funcs: framebuffer vfunc table */ From patchwork Fri Dec 13 15:58:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291411 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 25FE318B8 for ; Fri, 13 Dec 2019 21:25: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 70FBB246BF for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 70FBB246BF 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 4622B6E915; Fri, 13 Dec 2019 15:59:21 +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 BEF5A6E929 for ; Fri, 13 Dec 2019 15:59:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id D7F66292C5A From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 02/36] drm/core: Add afbc helper functions Date: Fri, 13 Dec 2019 16:58:33 +0100 Message-Id: <20191213155907.16581-3-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 Fri Dec 13 15:58:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291383 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 2B6D81951 for ; Fri, 13 Dec 2019 21:24:58 +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 E240F24693 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E240F24693 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 BDDAD6EA18; Fri, 13 Dec 2019 15:59:21 +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 590156E915 for ; Fri, 13 Dec 2019 15:59:20 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 763E9292C7A From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 03/36] drm/gem-fb-helper: Allow drivers to allocate struct drm_framebuffer on their own Date: Fri, 13 Dec 2019 16:58:34 +0100 Message-Id: <20191213155907.16581-4-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 184 ++++++++++++++----- include/drm/drm_gem_framebuffer_helper.h | 17 ++ 2 files changed, 153 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index b9bcd310ca2d..787edb9a916b 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -54,6 +54,44 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, } EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj); +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, + unsigned int num_planes, + const struct drm_framebuffer_funcs *funcs) +{ + int ret, i; + + drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd); + + for (i = 0; i < num_planes; i++) + fb->obj[i] = obj[i]; + + ret = drm_framebuffer_init(dev, fb, funcs); + if (ret) + DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n", + ret); + + return ret; +} +EXPORT_SYMBOL_GPL(drm_gem_fb_init_with_funcs); + +static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { + .destroy = drm_gem_fb_destroy, + .create_handle = drm_gem_fb_create_handle, +}; + +int drm_gem_fb_init(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, unsigned int num_planes) +{ + return drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, + &drm_gem_fb_funcs); +} +EXPORT_SYMBOL_GPL(drm_gem_fb_init); + static struct drm_framebuffer * drm_gem_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, @@ -61,21 +99,15 @@ drm_gem_fb_alloc(struct drm_device *dev, const struct drm_framebuffer_funcs *funcs) { struct drm_framebuffer *fb; - int ret, i; + int ret; fb = kzalloc(sizeof(*fb), GFP_KERNEL); if (!fb) return ERR_PTR(-ENOMEM); - drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd); - - for (i = 0; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret = drm_framebuffer_init(dev, fb, funcs); + ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, + funcs); if (ret) { - DRM_DEV_ERROR(dev->dev, "Failed to init framebuffer: %d\n", - ret); kfree(fb); return ERR_PTR(ret); } @@ -124,79 +156,135 @@ int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, EXPORT_SYMBOL(drm_gem_fb_create_handle); /** - * drm_gem_fb_create_with_funcs() - Helper function for the - * &drm_mode_config_funcs.fb_create - * callback + * drm_gem_fb_lookup() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations * @dev: DRM device * @file: DRM file that holds the GEM handle(s) backing the framebuffer * @mode_cmd: Metadata from the userspace framebuffer creation request - * @funcs: vtable to be used for the new framebuffer object * - * This function can be used to set &drm_framebuffer_funcs for drivers that need - * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to - * change &drm_framebuffer_funcs. The function does buffer size validation. + * This function can be used to look up the objects for all planes. + * In case an error is returned all the objects are put by the + * function before returning. * * Returns: - * Pointer to a &drm_framebuffer on success or an error pointer on failure. + * Number of planes on success or a negative error code on failure. */ -struct drm_framebuffer * -drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd, - const struct drm_framebuffer_funcs *funcs) +int drm_gem_fb_lookup(struct drm_device *dev, + struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) { const struct drm_format_info *info; - struct drm_gem_object *objs[4]; - struct drm_framebuffer *fb; int ret, i; info = drm_get_format_info(dev, mode_cmd); if (!info) - return ERR_PTR(-EINVAL); + return -EINVAL; for (i = 0; i < info->num_planes; i++) { - unsigned int width = mode_cmd->width / (i ? info->hsub : 1); - unsigned int height = mode_cmd->height / (i ? info->vsub : 1); - unsigned int min_size; - objs[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); if (!objs[i]) { DRM_DEBUG_KMS("Failed to lookup GEM object\n"); ret = -ENOENT; goto err_gem_object_put; } + } + + return i; + +err_gem_object_put: + for (i--; i >= 0; i--) + drm_gem_object_put_unlocked(objs[i]); + + return ret; +} +EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); + +/** + * drm_gem_fb_size_check() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations + * @dev: DRM device + * @mode_cmd: Metadata from the userspace framebuffer creation request + * + * This function can be used to verify buffer sizes for all planes. + * It is caller's responsibility to put the objects on failure. + * + * Returns: + * Zero on success or a negative error code on failure. + */ +int drm_gem_fb_size_check(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) +{ + const struct drm_format_info *info; + int i; + + info = drm_get_format_info(dev, mode_cmd); + if (!info) + return -EINVAL; + + for (i = 0; i < info->num_planes; i++) { + unsigned int width = mode_cmd->width / (i ? info->hsub : 1); + unsigned int height = mode_cmd->height / (i ? info->vsub : 1); + unsigned int min_size; min_size = (height - 1) * mode_cmd->pitches[i] + drm_format_info_min_pitch(info, i, width) + mode_cmd->offsets[i]; - if (objs[i]->size < min_size) { - drm_gem_object_put_unlocked(objs[i]); - ret = -EINVAL; - goto err_gem_object_put; - } + if (objs[i]->size < min_size) + return -EINVAL; } - fb = drm_gem_fb_alloc(dev, mode_cmd, objs, i, funcs); - if (IS_ERR(fb)) { - ret = PTR_ERR(fb); - goto err_gem_object_put; - } + return 0; - return fb; +} +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check); -err_gem_object_put: - for (i--; i >= 0; i--) - drm_gem_object_put_unlocked(objs[i]); +/** + * drm_gem_fb_create_with_funcs() - Helper function for the + * &drm_mode_config_funcs.fb_create + * callback + * @dev: DRM device + * @file: DRM file that holds the GEM handle(s) backing the framebuffer + * @mode_cmd: Metadata from the userspace framebuffer creation request + * @funcs: vtable to be used for the new framebuffer object + * + * This function can be used to set &drm_framebuffer_funcs for drivers that need + * custom framebuffer callbacks. Use drm_gem_fb_create() if you don't need to + * change &drm_framebuffer_funcs. The function does buffer size validation. + * + * Returns: + * Pointer to a &drm_framebuffer on success or an error pointer on failure. + */ +struct drm_framebuffer * +drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_framebuffer_funcs *funcs) +{ + struct drm_gem_object *objs[4]; + struct drm_framebuffer *fb; + int ret, num_planes; + + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + return ERR_PTR(ret); + num_planes = ret; + + ret = drm_gem_fb_size_check(dev, mode_cmd, objs); + if (ret) + fb = ERR_PTR(ret); + else + fb = drm_gem_fb_alloc(dev, mode_cmd, objs, num_planes, funcs); - return ERR_PTR(ret); + if (IS_ERR(fb)) + for (num_planes--; num_planes >= 0; num_planes--) + drm_gem_object_put_unlocked(objs[num_planes]); + + return fb; } EXPORT_SYMBOL_GPL(drm_gem_fb_create_with_funcs); -static const struct drm_framebuffer_funcs drm_gem_fb_funcs = { - .destroy = drm_gem_fb_destroy, - .create_handle = drm_gem_fb_create_handle, -}; - /** * drm_gem_fb_create() - Helper function for the * &drm_mode_config_funcs.fb_create callback diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index d9f13fd25b0a..c85d4b152e91 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -14,10 +14,27 @@ struct drm_simple_display_pipe; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, unsigned int plane); +int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, + unsigned int num_planes, + const struct drm_framebuffer_funcs *funcs); +int drm_gem_fb_init(struct drm_framebuffer *fb, + struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **obj, unsigned int num_planes); void drm_gem_fb_destroy(struct drm_framebuffer *fb); int drm_gem_fb_create_handle(struct drm_framebuffer *fb, struct drm_file *file, unsigned int *handle); +int drm_gem_fb_lookup(struct drm_device *dev, + struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs); +int drm_gem_fb_size_check(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs); struct drm_framebuffer * drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, From patchwork Fri Dec 13 15:58:35 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291375 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 CAE37188B for ; Fri, 13 Dec 2019 21:24: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 A5C3A2467A for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A5C3A2467A 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 E875B6E9B9; Fri, 13 Dec 2019 15:59:26 +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 A85346E915 for ; Fri, 13 Dec 2019 15:59:19 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 16C70292C8C From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 04/36] drm/gem-fb-helper: Add special version of drm_gem_fb_size_check Date: Fri, 13 Dec 2019 16:58:35 +0100 Message-Id: <20191213155907.16581-5-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 --- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 47 ++++++++++++++++---- include/drm/drm_gem_framebuffer_helper.h | 16 +++++++ 2 files changed, 55 insertions(+), 8 deletions(-) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index 787edb9a916b..4201dc1f32a5 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -201,8 +201,9 @@ int drm_gem_fb_lookup(struct drm_device *dev, EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); /** - * drm_gem_fb_size_check() - Helper function for use in - * &drm_mode_config_funcs.fb_create implementations + * drm_gem_fb_size_check_special() - Helper function for use in + * &drm_mode_config_funcs.fb_create + * implementations * @dev: DRM device * @mode_cmd: Metadata from the userspace framebuffer creation request * @@ -212,9 +213,10 @@ EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); * Returns: * Zero on success or a negative error code on failure. */ -int drm_gem_fb_size_check(struct drm_device *dev, - const struct drm_mode_fb_cmd2 *mode_cmd, - struct drm_gem_object **objs) +int drm_gem_fb_size_check_special(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs) { const struct drm_format_info *info; int i; @@ -227,10 +229,19 @@ int drm_gem_fb_size_check(struct drm_device *dev, unsigned int width = mode_cmd->width / (i ? info->hsub : 1); unsigned int height = mode_cmd->height / (i ? info->vsub : 1); unsigned int min_size; + u32 pitch = mode_cmd->pitches[i]; + + if (check && check->use_pitch_multiplier) + if ((pitch * check->pitch_multiplier[i]) % + check->pitch_modulo) + return -EINVAL; - min_size = (height - 1) * mode_cmd->pitches[i] - + drm_format_info_min_pitch(info, i, width) - + mode_cmd->offsets[i]; + if (check && check->use_min_size) + min_size = check->min_size[i]; + else + min_size = (height - 1) * pitch + + drm_format_info_min_pitch(info, i, width) + + mode_cmd->offsets[i]; if (objs[i]->size < min_size) return -EINVAL; @@ -239,6 +250,26 @@ int drm_gem_fb_size_check(struct drm_device *dev, return 0; } +EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special); + +/** + * drm_gem_fb_size_check() - Helper function for use in + * &drm_mode_config_funcs.fb_create implementations + * @dev: DRM device + * @mode_cmd: Metadata from the userspace framebuffer creation request + * + * This function can be used to verify buffer sizes for all planes. + * It is caller's responsibility to put the objects on failure. + * + * Returns: + * Zero on success or a negative error code on failure. + */ +int drm_gem_fb_size_check(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_gem_object **objs) +{ + return drm_gem_fb_size_check_special(dev, mode_cmd, NULL, objs); +} EXPORT_SYMBOL_GPL(drm_gem_fb_size_check); /** diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index c85d4b152e91..74304a268694 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -11,6 +11,18 @@ struct drm_mode_fb_cmd2; struct drm_plane; struct drm_plane_state; struct drm_simple_display_pipe; +struct drm_size_check; + +/** + * struct drm_size_check - Description of special requirements for size checks. + */ +struct drm_size_check { + unsigned int min_size[4]; + bool use_min_size; + u32 pitch_multiplier[4]; + u32 pitch_modulo; + bool use_pitch_multiplier; +}; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, unsigned int plane); @@ -32,6 +44,10 @@ int drm_gem_fb_lookup(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); +int drm_gem_fb_size_check_special(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + const struct drm_size_check *check, + struct drm_gem_object **objs); int drm_gem_fb_size_check(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **objs); From patchwork Fri Dec 13 15:58:36 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291315 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 D49E01920 for ; Fri, 13 Dec 2019 21:19: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 B433B24689 for ; Fri, 13 Dec 2019 21:19:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B433B24689 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 DC50F6EAEE; Fri, 13 Dec 2019 16:00:20 +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 A1E286E9B9 for ; Fri, 13 Dec 2019 15:59:21 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id B45F0292C63 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 05/36] drm/gem-fb-helper: Add generic afbc size checks Date: Fri, 13 Dec 2019 16:58:36 +0100 Message-Id: <20191213155907.16581-6-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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_fourcc.c | 10 +++- drivers/gpu/drm/drm_framebuffer.c | 3 + drivers/gpu/drm/drm_gem_framebuffer_helper.c | 60 ++++++++++++++++++-- include/drm/drm_gem_framebuffer_helper.h | 16 ++++++ 4 files changed, 82 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index d14dd7c86020..9ac2175c5bee 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -323,8 +323,14 @@ drm_get_format_info(struct drm_device *dev, { const struct drm_format_info *info = NULL; - if (dev->mode_config.funcs->get_format_info) - info = dev->mode_config.funcs->get_format_info(mode_cmd); + /* bypass driver callback if afbc */ + if (!drm_is_afbc(mode_cmd->modifier[0])) + if (dev->mode_config.funcs->get_format_info) { + const struct drm_mode_config_funcs *funcs; + + funcs = dev->mode_config.funcs; + info = funcs->get_format_info(mode_cmd); + } if (!info) info = drm_format_info(mode_cmd->pixel_format); diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index 57564318ceea..33b741cc73e8 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -204,6 +204,9 @@ static int framebuffer_check(struct drm_device *dev, unsigned int block_size = info->char_per_block[i]; u64 min_pitch = drm_format_info_min_pitch(info, i, width); + if (drm_is_afbc(r->modifier[i])) + block_size = 0; + if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) { DRM_DEBUG_KMS("Format requires non-linear modifier for plane %d\n", i); return -EINVAL; diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index 4201dc1f32a5..e20f4d00b0a5 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -21,6 +21,11 @@ #include #include +#define AFBC_HEADER_SIZE 16 +#define AFBC_TH_LAYOUT_ALIGNMENT 8 +#define AFBC_SUPERBLOCK_PIXELS 256 +#define AFBC_SUPERBLOCK_ALIGNMENT 128 + /** * DOC: overview * @@ -200,6 +205,40 @@ int drm_gem_fb_lookup(struct drm_device *dev, } EXPORT_SYMBOL_GPL(drm_gem_fb_lookup); +static int drm_gem_afbc_min_size(struct drm_device *dev, + const struct drm_mode_fb_cmd2 *mode_cmd, + struct drm_afbc *afbc) +{ + u32 n_blocks; + + if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], + &afbc->block_width, + &afbc->block_height)) { + return -EINVAL; + } + + /* tiled header afbc */ + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { + afbc->block_width *= AFBC_TH_LAYOUT_ALIGNMENT; + afbc->block_height *= AFBC_TH_LAYOUT_ALIGNMENT; + } + + afbc->aligned_width = ALIGN(mode_cmd->width, afbc->block_width); + afbc->aligned_height = ALIGN(mode_cmd->height, afbc->block_height); + afbc->offset = mode_cmd->offsets[0]; + + n_blocks = (afbc->aligned_width * afbc->aligned_height) + / AFBC_SUPERBLOCK_PIXELS; + afbc->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, + afbc->alignment_header); + + afbc->afbc_size = afbc->offset_payload + n_blocks * + ALIGN(afbc->bpp * AFBC_SUPERBLOCK_PIXELS / 8, + AFBC_SUPERBLOCK_ALIGNMENT); + + return 0; +} + /** * drm_gem_fb_size_check_special() - Helper function for use in * &drm_mode_config_funcs.fb_create @@ -218,6 +257,7 @@ int drm_gem_fb_size_check_special(struct drm_device *dev, const struct drm_size_check *check, struct drm_gem_object **objs) { +#define CHECK_HAS(field) (check && check->field) const struct drm_format_info *info; int i; @@ -231,24 +271,34 @@ int drm_gem_fb_size_check_special(struct drm_device *dev, unsigned int min_size; u32 pitch = mode_cmd->pitches[i]; - if (check && check->use_pitch_multiplier) + if (CHECK_HAS(use_pitch_multiplier)) if ((pitch * check->pitch_multiplier[i]) % check->pitch_modulo) return -EINVAL; - if (check && check->use_min_size) + if (CHECK_HAS(use_min_size)) { min_size = check->min_size[i]; - else + } else if (CHECK_HAS(data) && + drm_is_afbc(mode_cmd->modifier[0])) { + struct drm_afbc *afbc; + int ret; + + afbc = check->data; + ret = drm_gem_afbc_min_size(dev, mode_cmd, afbc); + if (ret < 0) + return ret; + min_size = ret; + } else { min_size = (height - 1) * pitch + drm_format_info_min_pitch(info, i, width) + mode_cmd->offsets[i]; - + } if (objs[i]->size < min_size) return -EINVAL; } return 0; - +#undef CHECK_HAS } EXPORT_SYMBOL_GPL(drm_gem_fb_size_check_special); diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index 74304a268694..3d6015194b3c 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -22,6 +22,22 @@ struct drm_size_check { u32 pitch_multiplier[4]; u32 pitch_modulo; bool use_pitch_multiplier; + void *data; +}; + +/** + * struct drm_afbc - AFBC-specific data. + */ +struct drm_afbc { + u32 block_width; + u32 block_height; + u32 aligned_width; + u32 aligned_height; + u32 offset; + u32 alignment_header; + u32 afbc_size; + u32 offset_payload; + u32 bpp; }; struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, From patchwork Fri Dec 13 15:58:37 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291385 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 84BB31AA3 for ; Fri, 13 Dec 2019 21:24:58 +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 00F18246A0 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 00F18246A0 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 67FF96EA37; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 31D426EA30 for ; Fri, 13 Dec 2019 15:59:22 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 5AB4F292C76 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 06/36] drm/gem-fb-helper: Add method to allocate struct drm_framebuffer Date: Fri, 13 Dec 2019 16:58:37 +0100 Message-Id: <20191213155907.16581-7-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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" Some drivers might want to use the modifier_info field of struct drm_framebuffer to hold struct drm_afbc. The memory for the latter must be managed by the driver. To eliminate the need to modify existing invocations of kfree(fb), add a function to allocate struct drm_framebuffer and its associated struct drm_afbc in one chunk. Signed-off-by: Andrzej Pietrasiewicz --- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 32 ++++++++++++++++++++ include/drm/drm_gem_framebuffer_helper.h | 1 + 2 files changed, 33 insertions(+) diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index e20f4d00b0a5..0338f303f988 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -21,6 +21,13 @@ #include #include +#define DRM_ALIGN_MASK(type) \ + (__alignof__(type) - 1) +#define DRM_INFO_OFFSET(type1, type2) \ + ((sizeof(type1) + DRM_ALIGN_MASK(type2)) & ~DRM_ALIGN_MASK(type2)) +#define DRM_COMPOUND_SIZE(type1, type2) \ + (DRM_INFO_OFFSET(type1, type2) + sizeof(type2)) + #define AFBC_HEADER_SIZE 16 #define AFBC_TH_LAYOUT_ALIGNMENT 8 #define AFBC_SUPERBLOCK_PIXELS 256 @@ -59,6 +66,31 @@ struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, } EXPORT_SYMBOL_GPL(drm_gem_fb_get_obj); +/** + * drm_gem_fb_alloc_with_afbc() - Allocate struct drm_framebuffer together + * with a struct drm_afbc for easier freeing + * and assign drm_framebuffer's modifier_info + * + * Returns: + * Pointer to drm_framebuffer on success or NULL + */ +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc(void) +{ + struct drm_framebuffer *fb; + + /* alloc in one chunk to ease freeing */ + fb = kzalloc(DRM_COMPOUND_SIZE(struct drm_framebuffer, struct drm_afbc), + GFP_KERNEL); + if (!fb) + return NULL; + + fb->modifier_info = + fb + DRM_INFO_OFFSET(struct drm_framebuffer, struct drm_afbc); + + return fb; +} +EXPORT_SYMBOL_GPL(drm_gem_fb_alloc_with_afbc); + int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, diff --git a/include/drm/drm_gem_framebuffer_helper.h b/include/drm/drm_gem_framebuffer_helper.h index 3d6015194b3c..4e7b1e2c765b 100644 --- a/include/drm/drm_gem_framebuffer_helper.h +++ b/include/drm/drm_gem_framebuffer_helper.h @@ -42,6 +42,7 @@ struct drm_afbc { struct drm_gem_object *drm_gem_fb_get_obj(struct drm_framebuffer *fb, unsigned int plane); +struct drm_framebuffer *drm_gem_fb_alloc_with_afbc(void); int drm_gem_fb_init_with_funcs(struct drm_framebuffer *fb, struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, From patchwork Fri Dec 13 15:58:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291417 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 25A8F18B6 for ; Fri, 13 Dec 2019 21:25: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 62E2724696 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 62E2724696 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 F2F056EA73; Fri, 13 Dec 2019 15:59: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 2D8106E9B2 for ; Fri, 13 Dec 2019 15:59:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id EC8A0292CF0 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 07/36] drm/komeda: Use afbc helper Date: Fri, 13 Dec 2019 16:58:38 +0100 Message-Id: <20191213155907.16581-8-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 17 +++-------------- 1 file changed, 3 insertions(+), 14 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 1b01a625f40e..7487c6cf6636 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -52,20 +52,9 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, return -ENOENT; } - switch (fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK) { - case AFBC_FORMAT_MOD_BLOCK_SIZE_32x8: - alignment_w = 32; - alignment_h = 8; - break; - case AFBC_FORMAT_MOD_BLOCK_SIZE_16x16: - alignment_w = 16; - alignment_h = 16; - break; - default: - WARN(1, "Invalid AFBC_FORMAT_MOD_BLOCK_SIZE: %lld.\n", - fb->modifier & AFBC_FORMAT_MOD_BLOCK_SIZE_MASK); - break; - } + if (!drm_afbc_get_superblock_wh(fb->modifier, + &alignment_w, &alignment_h)) + return -EINVAL; /* tiled header afbc */ if (fb->modifier & AFBC_FORMAT_MOD_TILED) { From patchwork Fri Dec 13 15:58:39 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291045 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 8AE59138D for ; Fri, 13 Dec 2019 20:44: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 56D0D2468B for ; Fri, 13 Dec 2019 20:44:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 56D0D2468B 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 75B3F6EA81; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id BBF2F6E9B9 for ; Fri, 13 Dec 2019 15:59:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id BA5FD292D0C From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 08/36] drm/komeda: Move checking src coordinates to komeda_fb_create Date: Fri, 13 Dec 2019 16:58:39 +0100 Message-Id: <20191213155907.16581-9-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 7487c6cf6636..aa477d1dddc3 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -107,9 +107,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, u32 i, block_h; u64 min_size; - if (komeda_fb_check_src_coords(kfb, 0, 0, fb->width, fb->height)) - return -EINVAL; - for (i = 0; i < info->num_planes; i++) { obj = drm_gem_object_lookup(file, mode_cmd->handles[i]); if (!obj) { @@ -168,10 +165,17 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); - if (kfb->base.modifier) + if (kfb->base.modifier) { ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd); - else + } else { + if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, + kfb->base.height)) { + kfree(kfb); + return ERR_PTR(-EINVAL); + } + ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd); + } if (ret < 0) goto err_cleanup; From patchwork Fri Dec 13 15:58:40 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291413 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 262ED6C1 for ; Fri, 13 Dec 2019 21:25: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 6D430246BC for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6D430246BC 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 5C6276EA7C; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 712AE6E9B9 for ; Fri, 13 Dec 2019 15:59:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 5EA5F292C80 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 09/36] drm/komeda: Use the already available local variable Date: Fri, 13 Dec 2019 16:58:40 +0100 Message-Id: <20191213155907.16581-10-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 aa477d1dddc3..bb1b43a64685 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -131,7 +131,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, } } - if (fb->format->num_planes == 3) { + if (info->num_planes == 3) { if (fb->pitches[1] != fb->pitches[2]) { DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); return -EINVAL; From patchwork Fri Dec 13 15:58:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291403 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 ABE1D1B2A for ; Fri, 13 Dec 2019 21:24:58 +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 6052D2468D for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6052D2468D 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 533C56EA7A; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id B81446E9B2 for ; Fri, 13 Dec 2019 15:59:23 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id F0F8A292D1F From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 10/36] drm/komeda: Retrieve drm_format_info once Date: Fri, 13 Dec 2019 16:58:41 +0100 Message-Id: <20191213155907.16581-11-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 bb1b43a64685..ce96389e3c40 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -37,11 +37,12 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { }; static int -komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, +komeda_fb_afbc_size_check(struct komeda_fb *kfb, + const struct drm_format_info *info, + struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { struct drm_framebuffer *fb = &kfb->base; - const struct drm_format_info *info = fb->format; struct drm_gem_object *obj; u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; u64 min_size; @@ -97,12 +98,13 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, } static int -komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, +komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, + struct komeda_fb *kfb, + const struct drm_format_info *info, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { struct drm_framebuffer *fb = &kfb->base; - const struct drm_format_info *info = fb->format; struct drm_gem_object *obj; u32 i, block_h; u64 min_size; @@ -147,6 +149,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, { struct komeda_dev *mdev = dev->dev_private; struct komeda_fb *kfb; + const struct drm_format_info *info; int ret = 0, i; kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); @@ -164,9 +167,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); + info = kfb->base.format; if (kfb->base.modifier) { - ret = komeda_fb_afbc_size_check(kfb, file, mode_cmd); + ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); } else { if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height)) { @@ -174,7 +178,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(-EINVAL); } - ret = komeda_fb_none_afbc_size_check(mdev, kfb, file, mode_cmd); + ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file, + mode_cmd); } if (ret < 0) goto err_cleanup; From patchwork Fri Dec 13 15:58:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291433 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 27A142981 for ; Fri, 13 Dec 2019 21:25: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 696B6246BA for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 696B6246BA 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 45E606E9B2; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 505CD6E9B2 for ; Fri, 13 Dec 2019 15:59:24 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id BC538292D25 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 11/36] drm/komeda: Explicitly require 1 plane for AFBC Date: Fri, 13 Dec 2019 16:58:42 +0100 Message-Id: <20191213155907.16581-12-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 ce96389e3c40..157b73005ef8 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -170,6 +170,11 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format; if (kfb->base.modifier) { + if (info->num_planes != 1) { + DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); + kfree(kfb); + return ERR_PTR(-EINVAL); + } ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); } else { if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, From patchwork Fri Dec 13 15:58:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291397 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 A70CE14E3 for ; Fri, 13 Dec 2019 21:24:58 +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 5D4902469E for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5D4902469E 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 541EA6EA47; Fri, 13 Dec 2019 15:59:28 +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 454096E9B2 for ; Fri, 13 Dec 2019 15:59:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 5C74E292D2B From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 12/36] drm/komeda: Move pitches comparison to komeda_fb_create Date: Fri, 13 Dec 2019 16:58:43 +0100 Message-Id: <20191213155907.16581-13-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 157b73005ef8..4fa01b2e3f1c 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -133,13 +133,6 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, } } - if (info->num_planes == 3) { - if (fb->pitches[1] != fb->pitches[2]) { - DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); - return -EINVAL; - } - } - return 0; } @@ -189,6 +182,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret < 0) goto err_cleanup; + if (info->num_planes == 3) + if (kfb->base.pitches[1] != kfb->base.pitches[2]) { + DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); + ret = -EINVAL; + goto err_cleanup; + } + ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs); if (ret < 0) { DRM_DEBUG_KMS("failed to initialize fb\n"); From patchwork Fri Dec 13 15:58:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291371 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 073151902 for ; Fri, 13 Dec 2019 21:24:58 +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 D286C2468C for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D286C2468C 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 EB9276EA6E; Fri, 13 Dec 2019 15:59:33 +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 ED5CC6E9B2 for ; Fri, 13 Dec 2019 15:59:25 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 028AD292C92 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 13/36] drm/komeda: Provide and use komeda_fb_get_pixel_addr variant not requiring a fb Date: Fri, 13 Dec 2019 16:58:44 +0100 Message-Id: <20191213155907.16581-14-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 4fa01b2e3f1c..00860a66ebf1 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -124,7 +124,12 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, return -EINVAL; } - min_size = komeda_fb_get_pixel_addr(kfb, 0, fb->height, i) + min_size = komeda_fb_get_pixel_addr_nofb(info, + mode_cmd->modifier[0], + mode_cmd->pitches, + mode_cmd->offsets, + obj, + 0, mode_cmd->height, i) - to_drm_gem_cma_obj(obj)->paddr; if (obj->size < min_size) { DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n", @@ -238,12 +243,56 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb, return 0; } +dma_addr_t +komeda_fb_get_pixel_addr_impl(const struct drm_format_info *format, + u64 modifier, + const unsigned int *pitches, + const unsigned int *offsets, + const struct drm_gem_cma_object *obj, + int x, int y, int plane) +{ + u32 offset, plane_x, plane_y, block_w, block_sz; + + offset = offsets[plane]; + if (modifier) { + block_w = drm_format_info_block_width(format, plane); + block_sz = format->char_per_block[plane]; + plane_x = x / (plane ? format->hsub : 1); + plane_y = y / (plane ? format->vsub : 1); + + offset += (plane_x / block_w) * block_sz + + plane_y * pitches[plane]; + } + + return obj->paddr + offset; +} + +dma_addr_t +komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format, + u64 modifier, + const unsigned int *pitches, + const unsigned int *offsets, + struct drm_gem_object *obj, + int x, int y, int plane) +{ + const struct drm_gem_cma_object *cma_obj; + + if (plane >= format->num_planes) { + DRM_DEBUG_KMS("Out of max plane num.\n"); + return -EINVAL; + } + + cma_obj = to_drm_gem_cma_obj(obj); + + return komeda_fb_get_pixel_addr_impl(format, modifier, pitches, offsets, + cma_obj, x, y, plane); +} + dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) { struct drm_framebuffer *fb = &kfb->base; const struct drm_gem_cma_object *obj; - u32 offset, plane_x, plane_y, block_w, block_sz; if (plane >= fb->format->num_planes) { DRM_DEBUG_KMS("Out of max plane num.\n"); @@ -252,18 +301,9 @@ komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane) obj = drm_fb_cma_get_gem_obj(fb, plane); - offset = fb->offsets[plane]; - if (!fb->modifier) { - block_w = drm_format_info_block_width(fb->format, plane); - block_sz = fb->format->char_per_block[plane]; - plane_x = x / (plane ? fb->format->hsub : 1); - plane_y = y / (plane ? fb->format->vsub : 1); - - offset += (plane_x / block_w) * block_sz - + plane_y * fb->pitches[plane]; - } - - return obj->paddr + offset; + return komeda_fb_get_pixel_addr_impl(fb->format, fb->modifier, + fb->pitches, fb->offsets, + obj, x, y, plane); } /* if the fb can be supported by a specific layer */ diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h index c61ca98a3a63..2f1f421d3e7f 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h @@ -42,6 +42,13 @@ int komeda_fb_check_src_coords(const struct komeda_fb *kfb, u32 src_x, u32 src_y, u32 src_w, u32 src_h); dma_addr_t komeda_fb_get_pixel_addr(struct komeda_fb *kfb, int x, int y, int plane); +dma_addr_t +komeda_fb_get_pixel_addr_nofb(const struct drm_format_info *format, + u64 modifier, + const unsigned int *pitches, + const unsigned int *offsets, + struct drm_gem_object *obj, + int x, int y, int plane); bool komeda_fb_is_layer_supported(struct komeda_fb *kfb, u32 layer_type, u32 rot); From patchwork Fri Dec 13 15:58:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291399 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 8D2F826DD for ; Fri, 13 Dec 2019 21:24:58 +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 4D614246B0 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4D614246B0 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 52AC06EA77; Fri, 13 Dec 2019 15:59:41 +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 A70836E9B2 for ; Fri, 13 Dec 2019 15:59:26 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id DCEC2292C82 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 14/36] drm/komeda: Factor out object lookups for non-afbc case Date: Fri, 13 Dec 2019 16:58:45 +0100 Message-Id: <20191213155907.16581-15-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 00860a66ebf1..d4e0df00180e 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -101,6 +101,7 @@ static int komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, struct komeda_fb *kfb, const struct drm_format_info *info, + struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { @@ -110,12 +111,7 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, u64 min_size; for (i = 0; i < info->num_planes; i++) { - obj = drm_gem_object_lookup(file, mode_cmd->handles[i]); - if (!obj) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return -ENOENT; - } - fb->obj[i] = obj; + obj = objs[i]; block_h = drm_format_info_block_height(info, i); if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) { @@ -175,14 +171,23 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); } else { + struct drm_gem_object *objs[4]; + if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height)) { kfree(kfb); return ERR_PTR(-EINVAL); } + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) { + kfree(kfb); + return ERR_PTR(ret); + } - ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, file, - mode_cmd); + ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs, + file, mode_cmd); + for (i = 0; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; } if (ret < 0) goto err_cleanup; From patchwork Fri Dec 13 15:58:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Pietrasiewicz X-Patchwork-Id: 11291373 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 212CD1920 for ; Fri, 13 Dec 2019 21:24:58 +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 DDCF224690 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org DDCF224690 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 1C9CC6EA7B; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 48D5C6EA30 for ; Fri, 13 Dec 2019 15:59:27 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id B3841292D4A From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 15/36] drm/komeda: Make komeda_fb_none_size_check independent from framebuffer Date: Fri, 13 Dec 2019 16:58:46 +0100 Message-Id: <20191213155907.16581-16-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 d4e0df00180e..07520cec6fbd 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -99,13 +99,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, static int komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, - struct komeda_fb *kfb, const struct drm_format_info *info, struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_framebuffer *fb = &kfb->base; struct drm_gem_object *obj; u32 i, block_h; u64 min_size; @@ -114,9 +112,10 @@ komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, obj = objs[i]; block_h = drm_format_info_block_height(info, i); - if ((fb->pitches[i] * block_h) % mdev->chip.bus_width) { + if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) { DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n", - i, fb->pitches[i], mdev->chip.bus_width); + i, mode_cmd->pitches[i], + mdev->chip.bus_width); return -EINVAL; } @@ -184,7 +183,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(ret); } - ret = komeda_fb_none_afbc_size_check(mdev, kfb, info, objs, + ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); for (i = 0; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; From patchwork Fri Dec 13 15:58: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: 11291429 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 342A52D33 for ; Fri, 13 Dec 2019 21:25: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 8E296246AD for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8E296246AD 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 0F0E66EA75; Fri, 13 Dec 2019 15:59:34 +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 4415D6EA30 for ; Fri, 13 Dec 2019 15:59:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 54CE7292D59 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 16/36] drm/komeda: Factor out object lookups for afbc case Date: Fri, 13 Dec 2019 16:58:47 +0100 Message-Id: <20191213155907.16581-17-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 07520cec6fbd..4e29fa5bd342 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -39,6 +39,7 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { static int komeda_fb_afbc_size_check(struct komeda_fb *kfb, const struct drm_format_info *info, + struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { @@ -47,11 +48,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; u64 min_size; - obj = drm_gem_object_lookup(file, mode_cmd->handles[0]); - if (!obj) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return -ENOENT; - } + obj = objs[0]; if (!drm_afbc_get_superblock_wh(fb->modifier, &alignment_w, &alignment_h)) @@ -71,7 +68,7 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, if (fb->offsets[0] % alignment_header) { DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); - goto check_failed; + return -EINVAL; } n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS; @@ -86,15 +83,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, if (min_size > obj->size) { DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n", obj->size, min_size); - goto check_failed; + return -EINVAL; } - fb->obj[0] = obj; return 0; - -check_failed: - drm_gem_object_put_unlocked(obj); - return -EINVAL; } static int @@ -163,12 +155,24 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = kfb->base.format; if (kfb->base.modifier) { + struct drm_gem_object *objs[4]; + if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); kfree(kfb); return ERR_PTR(-EINVAL); } - ret = komeda_fb_afbc_size_check(kfb, info, file, mode_cmd); + + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) { + kfree(kfb); + return ERR_PTR(ret); + } + + ret = komeda_fb_afbc_size_check(kfb, info, objs, file, + mode_cmd); + for (i = 0; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; } else { struct drm_gem_object *objs[4]; From patchwork Fri Dec 13 15:58: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: 11291401 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 25A4C188B for ; Fri, 13 Dec 2019 21:25: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 60ED9246B7 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 60ED9246B7 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 5C6416EA71; Fri, 13 Dec 2019 15:59:33 +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 BCA6E6EA71 for ; Fri, 13 Dec 2019 15:59:28 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id E9235292CD6 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 17/36] drm/komeda: Free komeda_fb_afbc_size_check from framebuffer dependency Date: Fri, 13 Dec 2019 16:58:48 +0100 Message-Id: <20191213155907.16581-18-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 4e29fa5bd342..cc9dc8588e8d 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -43,19 +43,18 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_framebuffer *fb = &kfb->base; struct drm_gem_object *obj; u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; u64 min_size; obj = objs[0]; - if (!drm_afbc_get_superblock_wh(fb->modifier, + if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) return -EINVAL; /* tiled header afbc */ - if (fb->modifier & AFBC_FORMAT_MOD_TILED) { + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; alignment_header = AFBC_TH_BODY_START_ALIGNMENT; @@ -63,10 +62,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, alignment_header = AFBC_BODY_START_ALIGNMENT; } - kfb->aligned_w = ALIGN(fb->width, alignment_w); - kfb->aligned_h = ALIGN(fb->height, alignment_h); + kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); + kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); - if (fb->offsets[0] % alignment_header) { + if (mode_cmd->offsets[0] % alignment_header) { DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); return -EINVAL; } @@ -75,11 +74,11 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, alignment_header); - bpp = komeda_get_afbc_format_bpp(info, fb->modifier); + bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); kfb->afbc_size = kfb->offset_payload + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); - min_size = kfb->afbc_size + fb->offsets[0]; + min_size = kfb->afbc_size + mode_cmd->offsets[0]; if (min_size > obj->size) { DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n", obj->size, min_size); From patchwork Fri Dec 13 15:58: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: 11291423 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 26BBD2719 for ; Fri, 13 Dec 2019 21:25: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 6F83E246BE for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6F83E246BE 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 0F83D6EA78; Fri, 13 Dec 2019 15:59: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 52F636EA75 for ; Fri, 13 Dec 2019 15:59:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id BF80F292D65 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 18/36] drm/komeda: Simplify error handling Date: Fri, 13 Dec 2019 16:58:49 +0100 Message-Id: <20191213155907.16581-19-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 cc9dc8588e8d..6325b20e661d 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -146,8 +146,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (!kfb->format_caps) { DRM_DEBUG_KMS("FMT %x is not supported.\n", mode_cmd->pixel_format); - kfree(kfb); - return ERR_PTR(-EINVAL); + ret = -EINVAL; + goto err_free; } drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); @@ -158,15 +158,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); - kfree(kfb); - return ERR_PTR(-EINVAL); + ret = -EINVAL; + goto err_free; } ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) { - kfree(kfb); - return ERR_PTR(ret); - } + if (ret < 0) + goto err_free; ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); @@ -175,16 +173,14 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } else { struct drm_gem_object *objs[4]; - if (komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, - kfb->base.height)) { - kfree(kfb); - return ERR_PTR(-EINVAL); - } + ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, + kfb->base.height); + if (ret) + goto err_free; + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) { - kfree(kfb); - return ERR_PTR(ret); - } + if (ret < 0) + goto err_free; ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); @@ -215,7 +211,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup: for (i = 0; i < kfb->base.format->num_planes; i++) drm_gem_object_put_unlocked(kfb->base.obj[i]); - +err_free: kfree(kfb); return ERR_PTR(ret); } From patchwork Fri Dec 13 15:58: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: 11291377 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 E157418B8 for ; Fri, 13 Dec 2019 21:24: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 BC57821655 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC57821655 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 E04596EA82; Fri, 13 Dec 2019 15:59:44 +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 E8DFC6EA30 for ; Fri, 13 Dec 2019 15:59:29 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 601AB292D6A From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 19/36] drm/komeda: Move object lookup before size checks Date: Fri, 13 Dec 2019 16:58:50 +0100 Message-Id: <20191213155907.16581-20-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 6325b20e661d..b923e2b6c523 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -132,6 +132,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { struct komeda_dev *mdev = dev->dev_private; + struct drm_gem_object *objs[4]; struct komeda_fb *kfb; const struct drm_format_info *info; int ret = 0, i; @@ -150,37 +151,29 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free; } + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + goto err_free; + drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); info = kfb->base.format; if (kfb->base.modifier) { - struct drm_gem_object *objs[4]; - if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; - goto err_free; + goto err_cleanup; } - ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) - goto err_free; - ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); for (i = 0; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; } else { - struct drm_gem_object *objs[4]; - ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height); if (ret) - goto err_free; - - ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); - if (ret < 0) - goto err_free; + goto err_cleanup; ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); @@ -210,7 +203,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_cleanup: for (i = 0; i < kfb->base.format->num_planes; i++) - drm_gem_object_put_unlocked(kfb->base.obj[i]); + drm_gem_object_put_unlocked(objs[i]); err_free: kfree(kfb); return ERR_PTR(ret); From patchwork Fri Dec 13 15:58: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: 11291529 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 AB8611920 for ; Fri, 13 Dec 2019 21:34:58 +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 940022467F for ; Fri, 13 Dec 2019 21:34:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 940022467F 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 CE9676EA30; Fri, 13 Dec 2019 15:59:33 +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 874F46EA30 for ; Fri, 13 Dec 2019 15:59:30 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 00CFE292D71 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 20/36] drm/komeda: Move object assignments to framebuffer to after size checks Date: Fri, 13 Dec 2019 16:58:51 +0100 Message-Id: <20191213155907.16581-21-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 b923e2b6c523..4c78ae1a4845 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -167,8 +167,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); - for (i = 0; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; } else { ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, kfb->base.height); @@ -177,8 +175,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_none_afbc_size_check(mdev, info, objs, file, mode_cmd); - for (i = 0; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; } if (ret < 0) goto err_cleanup; @@ -190,6 +186,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } + for (i = 0; i < info->num_planes; ++i) + kfb->base.obj[i] = objs[i]; + ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs); if (ret < 0) { DRM_DEBUG_KMS("failed to initialize fb\n"); From patchwork Fri Dec 13 15:58: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: 11291381 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 055B618B6 for ; Fri, 13 Dec 2019 21:24:58 +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 D52B924680 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D52B924680 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 92E566EA76; Fri, 13 Dec 2019 15:59: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 6CA3A6EA30 for ; Fri, 13 Dec 2019 15:59:32 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 94D9C292D72 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 21/36] drm/komeda: Make the size checks independent from framebuffer structure Date: Fri, 13 Dec 2019 16:58:52 +0100 Message-Id: <20191213155907.16581-22-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 4c78ae1a4845..ab067f89533c 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -156,9 +156,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_free; drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); - info = kfb->base.format; + info = drm_get_format_info(dev, mode_cmd); - if (kfb->base.modifier) { + if (mode_cmd->modifier[0]) { if (info->num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; @@ -168,8 +168,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); } else { - ret = komeda_fb_check_src_coords(kfb, 0, 0, kfb->base.width, - kfb->base.height); + ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, + mode_cmd->height); if (ret) goto err_cleanup; @@ -180,7 +180,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; if (info->num_planes == 3) - if (kfb->base.pitches[1] != kfb->base.pitches[2]) { + if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) { DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); ret = -EINVAL; goto err_cleanup; From patchwork Fri Dec 13 15:58: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: 11291527 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 7CE21109A for ; Fri, 13 Dec 2019 21:34:58 +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 654952465A for ; Fri, 13 Dec 2019 21:34:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 654952465A 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 AACCE6EA9A; Fri, 13 Dec 2019 15:59:45 +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 2C3F66EA30 for ; Fri, 13 Dec 2019 15:59:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 4529F292CDF From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 22/36] drm/komeda: Move helper invocation to after size checks Date: Fri, 13 Dec 2019 16:58:53 +0100 Message-Id: <20191213155907.16581-23-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 ab067f89533c..1a03318ec73a 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -155,7 +155,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret < 0) goto err_free; - drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { @@ -186,6 +185,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } + drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); + for (i = 0; i < info->num_planes; ++i) kfb->base.obj[i] = objs[i]; @@ -201,7 +202,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return &kfb->base; err_cleanup: - for (i = 0; i < kfb->base.format->num_planes; i++) + for (i = 0; i < info->num_planes; i++) drm_gem_object_put_unlocked(objs[i]); err_free: kfree(kfb); From patchwork Fri Dec 13 15:58: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: 11291393 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 7F64A19A2 for ; Fri, 13 Dec 2019 21:24:58 +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 EDD252469B for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDD252469B 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 672ED6EA97; Fri, 13 Dec 2019 16:00:03 +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 035C46EA74 for ; Fri, 13 Dec 2019 15:59:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id D63E9292D76 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 23/36] drm/komeda: Use helper for common tasks Date: Fri, 13 Dec 2019 16:58:54 +0100 Message-Id: <20191213155907.16581-24-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 1a03318ec73a..74c0caa51bdf 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -185,17 +185,10 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - drm_helper_mode_fill_fb_struct(dev, &kfb->base, mode_cmd); - - for (i = 0; i < info->num_planes; ++i) - kfb->base.obj[i] = objs[i]; - - ret = drm_framebuffer_init(dev, &kfb->base, &komeda_fb_funcs); - if (ret < 0) { - DRM_DEBUG_KMS("failed to initialize fb\n"); - + ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs, + info->num_planes, &komeda_fb_funcs); + if (ret < 0) goto err_cleanup; - } kfb->is_va = mdev->iommu ? true : false; From patchwork Fri Dec 13 15:58: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: 11291307 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 8951D13B6 for ; Fri, 13 Dec 2019 21:19: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 6ACA020706 for ; Fri, 13 Dec 2019 21:19:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6ACA020706 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 73BC26EAE8; Fri, 13 Dec 2019 16:00:13 +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 5C0F06EA6E for ; Fri, 13 Dec 2019 15:59:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id BF418292D83 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 24/36] drm/komeda: Use return value of drm_gem_fb_lookup Date: Fri, 13 Dec 2019 16:58:55 +0100 Message-Id: <20191213155907.16581-25-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 74c0caa51bdf..6ac4a599ab5d 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -135,7 +135,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, struct drm_gem_object *objs[4]; struct komeda_fb *kfb; const struct drm_format_info *info; - int ret = 0, i; + int ret = 0, i, num_planes; kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); if (!kfb) @@ -154,11 +154,12 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); if (ret < 0) goto err_free; + num_planes = ret; info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { - if (info->num_planes != 1) { + if (num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; goto err_cleanup; @@ -178,7 +179,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret < 0) goto err_cleanup; - if (info->num_planes == 3) + if (num_planes == 3) if (mode_cmd->pitches[1] != mode_cmd->pitches[2]) { DRM_DEBUG_KMS("The pitch[1] and [2] are not same\n"); ret = -EINVAL; @@ -186,7 +187,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, } ret = drm_gem_fb_init_with_funcs(&kfb->base, dev, mode_cmd, objs, - info->num_planes, &komeda_fb_funcs); + num_planes, &komeda_fb_funcs); if (ret < 0) goto err_cleanup; @@ -195,7 +196,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, return &kfb->base; err_cleanup: - for (i = 0; i < info->num_planes; i++) + for (i = 0; i < num_planes; i++) drm_gem_object_put_unlocked(objs[i]); err_free: kfree(kfb); From patchwork Fri Dec 13 15:58: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: 11291425 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 322D92D32 for ; Fri, 13 Dec 2019 21:25: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 9ECCE246A9 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9ECCE246A9 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 2015D6EA99; Fri, 13 Dec 2019 16:00:04 +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 F11AC6EA73 for ; Fri, 13 Dec 2019 15:59:33 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 60FBA292D87 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 25/36] drm/komeda: Use special helper for non-afbc size checks Date: Fri, 13 Dec 2019 16:58:56 +0100 Message-Id: <20191213155907.16581-26-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 6ac4a599ab5d..77186f70bdf3 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -89,42 +89,38 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, } static int -komeda_fb_none_afbc_size_check(struct komeda_dev *mdev, +komeda_fb_none_afbc_size_check(struct drm_device *dev, const struct drm_format_info *info, struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + struct komeda_dev *mdev = dev->dev_private; + struct drm_size_check check = { 0 }; struct drm_gem_object *obj; - u32 i, block_h; - u64 min_size; + u32 i; for (i = 0; i < info->num_planes; i++) { obj = objs[i]; - block_h = drm_format_info_block_height(info, i); - if ((mode_cmd->pitches[i] * block_h) % mdev->chip.bus_width) { - DRM_DEBUG_KMS("Pitch[%d]: 0x%x doesn't align to 0x%x\n", - i, mode_cmd->pitches[i], - mdev->chip.bus_width); - return -EINVAL; - } - - min_size = komeda_fb_get_pixel_addr_nofb(info, - mode_cmd->modifier[0], - mode_cmd->pitches, - mode_cmd->offsets, - obj, - 0, mode_cmd->height, i) - - to_drm_gem_cma_obj(obj)->paddr; - if (obj->size < min_size) { - DRM_DEBUG_KMS("The fb->obj[%d] size: 0x%zx lower than the minimum requirement: 0x%llx.\n", - i, obj->size, min_size); - return -EINVAL; - } + check.pitch_multiplier[i] = + drm_format_info_block_height(info, i); + + check.min_size[i] = + komeda_fb_get_pixel_addr_nofb(info, + mode_cmd->modifier[0], + mode_cmd->pitches, + mode_cmd->offsets, + obj, + 0, mode_cmd->height, i) + - to_drm_gem_cma_obj(obj)->paddr; } - return 0; + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + + return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); } struct drm_framebuffer * @@ -173,7 +169,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, if (ret) goto err_cleanup; - ret = komeda_fb_none_afbc_size_check(mdev, info, objs, + ret = komeda_fb_none_afbc_size_check(dev, info, objs, file, mode_cmd); } if (ret < 0) From patchwork Fri Dec 13 15:58: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: 11291395 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 8672D13B6 for ; Fri, 13 Dec 2019 21:24:58 +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 2FA3E246A6 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 2FA3E246A6 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 6A1156EA7D; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id B17F86EA77 for ; Fri, 13 Dec 2019 15:59:34 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 06A59292CF2 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 26/36] drm/komeda: Factor in the invocation of special helper Date: Fri, 13 Dec 2019 16:58:57 +0100 Message-Id: <20191213155907.16581-27-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 58 +++++++------------ 1 file changed, 21 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 77186f70bdf3..6898407d1b63 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -88,41 +88,6 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, return 0; } -static int -komeda_fb_none_afbc_size_check(struct drm_device *dev, - const struct drm_format_info *info, - struct drm_gem_object **objs, - struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - struct komeda_dev *mdev = dev->dev_private; - struct drm_size_check check = { 0 }; - struct drm_gem_object *obj; - u32 i; - - for (i = 0; i < info->num_planes; i++) { - obj = objs[i]; - - check.pitch_multiplier[i] = - drm_format_info_block_height(info, i); - - check.min_size[i] = - komeda_fb_get_pixel_addr_nofb(info, - mode_cmd->modifier[0], - mode_cmd->pitches, - mode_cmd->offsets, - obj, - 0, mode_cmd->height, i) - - to_drm_gem_cma_obj(obj)->paddr; - } - - check.pitch_modulo = mdev->chip.bus_width; - check.use_pitch_multiplier = true; - check.use_min_size = true; - - return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); -} - struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -164,13 +129,32 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, ret = komeda_fb_afbc_size_check(kfb, info, objs, file, mode_cmd); } else { + struct drm_size_check check = { 0 }; + ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, mode_cmd->height); if (ret) goto err_cleanup; - ret = komeda_fb_none_afbc_size_check(dev, info, objs, - file, mode_cmd); + for (i = 0; i < num_planes; i++) { + check.pitch_multiplier[i] = + drm_format_info_block_height(info, i); + + check.min_size[i] = + komeda_fb_get_pixel_addr_nofb(info, + mode_cmd->modifier[0], + mode_cmd->pitches, + mode_cmd->offsets, objs[i], + 0, mode_cmd->height, i) + - to_drm_gem_cma_obj(objs[i])->paddr; + } + + check.pitch_modulo = mdev->chip.bus_width; + check.use_pitch_multiplier = true; + check.use_min_size = true; + + ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, + objs); } if (ret < 0) goto err_cleanup; From patchwork Fri Dec 13 15:58: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: 11291407 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 3F1322D38 for ; Fri, 13 Dec 2019 21:25: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 C7139246A7 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C7139246A7 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 CE3846EA74; Fri, 13 Dec 2019 15:59:44 +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 893E56EA85 for ; Fri, 13 Dec 2019 15:59:36 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id A5141292D92 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 27/36] drm/komeda: Use special helper for afbc case size check Date: Fri, 13 Dec 2019 16:58:58 +0100 Message-Id: <20191213155907.16581-28-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 6898407d1b63..e55ab6130e15 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -37,17 +37,15 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { }; static int -komeda_fb_afbc_size_check(struct komeda_fb *kfb, +komeda_fb_afbc_size_check(struct drm_device *dev, + struct komeda_fb *kfb, const struct drm_format_info *info, struct drm_gem_object **objs, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - struct drm_gem_object *obj; + struct drm_size_check check = { 0 }; u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; - u64 min_size; - - obj = objs[0]; if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], &alignment_w, &alignment_h)) @@ -78,14 +76,10 @@ komeda_fb_afbc_size_check(struct komeda_fb *kfb, kfb->afbc_size = kfb->offset_payload + n_blocks * ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, AFBC_SUPERBLK_ALIGNMENT); - min_size = kfb->afbc_size + mode_cmd->offsets[0]; - if (min_size > obj->size) { - DRM_DEBUG_KMS("afbc size check failed, obj_size: 0x%zx. min_size 0x%llx.\n", - obj->size, min_size); - return -EINVAL; - } + check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; + check.use_min_size = true; - return 0; + return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); } struct drm_framebuffer * @@ -126,8 +120,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, goto err_cleanup; } - ret = komeda_fb_afbc_size_check(kfb, info, objs, file, - mode_cmd); + ret = komeda_fb_afbc_size_check(dev, kfb, info, objs, + file, mode_cmd); } else { struct drm_size_check check = { 0 }; From patchwork Fri Dec 13 15:58: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: 11291409 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 27D712D2A for ; Fri, 13 Dec 2019 21:25: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 B76A1246B3 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org B76A1246B3 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 20A0A6EAE1; Fri, 13 Dec 2019 16:00:13 +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 7E9D26EA73 for ; Fri, 13 Dec 2019 15:59:37 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 47762292D97 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 28/36] drm/komeda: Factor in the invocation of special helper, afbc case Date: Fri, 13 Dec 2019 16:58:59 +0100 Message-Id: <20191213155907.16581-29-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 90 +++++++++---------- 1 file changed, 42 insertions(+), 48 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index e55ab6130e15..ac7e099435c9 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -36,52 +36,6 @@ static const struct drm_framebuffer_funcs komeda_fb_funcs = { .create_handle = komeda_fb_create_handle, }; -static int -komeda_fb_afbc_size_check(struct drm_device *dev, - struct komeda_fb *kfb, - const struct drm_format_info *info, - struct drm_gem_object **objs, - struct drm_file *file, - const struct drm_mode_fb_cmd2 *mode_cmd) -{ - struct drm_size_check check = { 0 }; - u32 alignment_w = 0, alignment_h = 0, alignment_header, n_blocks, bpp; - - if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], - &alignment_w, &alignment_h)) - return -EINVAL; - - /* tiled header afbc */ - if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { - alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_header = AFBC_TH_BODY_START_ALIGNMENT; - } else { - alignment_header = AFBC_BODY_START_ALIGNMENT; - } - - kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); - kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); - - if (mode_cmd->offsets[0] % alignment_header) { - DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); - return -EINVAL; - } - - n_blocks = (kfb->aligned_w * kfb->aligned_h) / AFBC_SUPERBLK_PIXELS; - kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, - alignment_header); - - bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); - kfb->afbc_size = kfb->offset_payload + n_blocks * - ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, - AFBC_SUPERBLK_ALIGNMENT); - check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; - check.use_min_size = true; - - return drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); -} - struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) @@ -114,14 +68,54 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { + struct drm_size_check check = { 0 }; + u32 alignment_w = 0, alignment_h = 0; + u32 alignment_header, n_blocks, bpp; + if (num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; goto err_cleanup; } - ret = komeda_fb_afbc_size_check(dev, kfb, info, objs, - file, mode_cmd); + if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], + &alignment_w, &alignment_h)) { + ret = -EINVAL; + goto err_cleanup; + } + + /* tiled header afbc */ + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { + alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; + alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; + alignment_header = AFBC_TH_BODY_START_ALIGNMENT; + } else { + alignment_header = AFBC_BODY_START_ALIGNMENT; + } + + kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); + kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); + + if (mode_cmd->offsets[0] % alignment_header) { + DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); + ret = -EINVAL; + goto err_cleanup; + } + + n_blocks = (kfb->aligned_w * kfb->aligned_h) + / AFBC_SUPERBLK_PIXELS; + kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, + alignment_header); + + bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); + kfb->afbc_size = kfb->offset_payload + n_blocks * + ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, + AFBC_SUPERBLK_ALIGNMENT); + check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; + check.use_min_size = true; + + ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, + objs); } else { struct drm_size_check check = { 0 }; From patchwork Fri Dec 13 15:59: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: 11291379 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 CCCA16C1 for ; Fri, 13 Dec 2019 21:24: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 AD8CD24682 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD8CD24682 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 E32C56EA86; Fri, 13 Dec 2019 15:59: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 [IPv6:2a00:1098:0:82:1000:25:2eeb:e3e3]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5205F6EA7A for ; Fri, 13 Dec 2019 15:59:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id DFBDE292D98 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 29/36] drm/komeda: Move special helper invocation outside if-else Date: Fri, 13 Dec 2019 16:59:00 +0100 Message-Id: <20191213155907.16581-30-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index ac7e099435c9..385df1fd776d 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -44,6 +44,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, struct drm_gem_object *objs[4]; struct komeda_fb *kfb; const struct drm_format_info *info; + struct drm_size_check check = { 0 }; + int ret = 0, i, num_planes; kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); @@ -68,7 +70,6 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { - struct drm_size_check check = { 0 }; u32 alignment_w = 0, alignment_h = 0; u32 alignment_header, n_blocks, bpp; @@ -113,12 +114,7 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, AFBC_SUPERBLK_ALIGNMENT); check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; check.use_min_size = true; - - ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, - objs); } else { - struct drm_size_check check = { 0 }; - ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, mode_cmd->height); if (ret) @@ -140,10 +136,8 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, check.pitch_modulo = mdev->chip.bus_width; check.use_pitch_multiplier = true; check.use_min_size = true; - - ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, - objs); } + ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); if (ret < 0) goto err_cleanup; From patchwork Fri Dec 13 15:59: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: 11291391 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 8AA0026D6 for ; Fri, 13 Dec 2019 21:24:58 +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 444B724681 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 444B724681 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 3F3456EA8F; Fri, 13 Dec 2019 16:00:02 +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 B10C26EA7D for ; Fri, 13 Dec 2019 15:59:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id CDCA3292DA1 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 30/36] drm/komeda: Move to helper checking afbc buffer size Date: Fri, 13 Dec 2019 16:59:01 +0100 Message-Id: <20191213155907.16581-31-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 7 ++- .../arm/display/komeda/komeda_framebuffer.c | 60 +++++++++---------- .../arm/display/komeda/komeda_framebuffer.h | 8 --- .../display/komeda/komeda_pipeline_state.c | 11 ++-- 4 files changed, 39 insertions(+), 47 deletions(-) diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c index 8a02ade369db..bab015f13ef3 100644 --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c @@ -4,6 +4,8 @@ * Author: James.Qian.Wang * */ +#include +#include #include "d71_dev.h" #include "komeda_kms.h" #include "malidp_io.h" @@ -234,9 +236,10 @@ static void d71_layer_update(struct komeda_component *c, st->afbc_crop_b)); /* afbc 1.2 wants payload, afbc 1.0/1.1 wants end_addr */ if (fb->modifier & AFBC_FORMAT_MOD_TILED) - addr = st->addr[0] + kfb->offset_payload; + addr = st->addr[0] + + kfb->base.afbc_info->offset_payload; else - addr = st->addr[0] + kfb->afbc_size - 1; + addr = st->addr[0] + kfb->base.afbc_info->afbc_size - 1; malidp_write32(reg, BLK_P1_PTR_LOW, lower_32_bits(addr)); malidp_write32(reg, BLK_P1_PTR_HIGH, upper_32_bits(addr)); diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c index 385df1fd776d..d3e0f2c0d924 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.c @@ -40,6 +40,13 @@ struct drm_framebuffer * komeda_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { +#define KFB_ALIGN_MASK(type) \ + (__alignof__(type) - 1) +#define KFB_INFO_OFFSET(type1, type2) \ + ((sizeof(type1) + KFB_ALIGN_MASK(type2)) & ~KFB_ALIGN_MASK(type2)) +#define KFB_COMPOUND_SIZE(type1, type2) \ + (KFB_INFO_OFFSET(type1, type2) + sizeof(type2)) + struct komeda_dev *mdev = dev->dev_private; struct drm_gem_object *objs[4]; struct komeda_fb *kfb; @@ -48,9 +55,13 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, int ret = 0, i, num_planes; - kfb = kzalloc(sizeof(*kfb), GFP_KERNEL); + /* alloc in one chunk to ease freeing */ + kfb = kzalloc(KFB_COMPOUND_SIZE(struct komeda_fb, struct drm_afbc), + GFP_KERNEL); if (!kfb) return ERR_PTR(-ENOMEM); + kfb->base.modifier_info = + kfb + KFB_INFO_OFFSET(struct komeda_fb, struct drm_afbc); kfb->format_caps = komeda_get_format_caps(&mdev->fmt_tbl, mode_cmd->pixel_format, @@ -70,50 +81,30 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, info = drm_get_format_info(dev, mode_cmd); if (mode_cmd->modifier[0]) { - u32 alignment_w = 0, alignment_h = 0; - u32 alignment_header, n_blocks, bpp; - if (num_planes != 1) { DRM_DEBUG_KMS("AFBC requires exactly 1 plane.\n"); ret = -EINVAL; goto err_cleanup; } - if (!drm_afbc_get_superblock_wh(mode_cmd->modifier[0], - &alignment_w, &alignment_h)) { - ret = -EINVAL; - goto err_cleanup; - } - /* tiled header afbc */ - if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) { - alignment_w *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_h *= AFBC_TH_LAYOUT_ALIGNMENT; - alignment_header = AFBC_TH_BODY_START_ALIGNMENT; - } else { - alignment_header = AFBC_BODY_START_ALIGNMENT; - } - - kfb->aligned_w = ALIGN(mode_cmd->width, alignment_w); - kfb->aligned_h = ALIGN(mode_cmd->height, alignment_h); - - if (mode_cmd->offsets[0] % alignment_header) { + if (mode_cmd->modifier[0] & AFBC_FORMAT_MOD_TILED) + kfb->base.afbc_info->alignment_header = + AFBC_TH_BODY_START_ALIGNMENT; + else + kfb->base.afbc_info->alignment_header = + AFBC_BODY_START_ALIGNMENT; + + if (mode_cmd->offsets[0] % + kfb->base.afbc_info->alignment_header) { DRM_DEBUG_KMS("afbc offset alignment check failed.\n"); ret = -EINVAL; goto err_cleanup; } - n_blocks = (kfb->aligned_w * kfb->aligned_h) - / AFBC_SUPERBLK_PIXELS; - kfb->offset_payload = ALIGN(n_blocks * AFBC_HEADER_SIZE, - alignment_header); - - bpp = komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); - kfb->afbc_size = kfb->offset_payload + n_blocks * - ALIGN(bpp * AFBC_SUPERBLK_PIXELS / 8, - AFBC_SUPERBLK_ALIGNMENT); - check.min_size[0] = kfb->afbc_size + mode_cmd->offsets[0]; - check.use_min_size = true; + kfb->base.afbc_info->bpp = + komeda_get_afbc_format_bpp(info, mode_cmd->modifier[0]); + check.data = kfb->base.afbc_info; } else { ret = komeda_fb_check_src_coords(kfb, 0, 0, mode_cmd->width, mode_cmd->height); @@ -163,6 +154,9 @@ komeda_fb_create(struct drm_device *dev, struct drm_file *file, err_free: kfree(kfb); return ERR_PTR(ret); +#undef KFB_ALIGN_MASK +#undef KFB_INFO_OFFSET +#undef KFB_COMPOUND_SIZE } int komeda_fb_check_src_coords(const struct komeda_fb *kfb, diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h index 2f1f421d3e7f..9e7af1cc0f12 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h +++ b/drivers/gpu/drm/arm/display/komeda/komeda_framebuffer.h @@ -23,14 +23,6 @@ struct komeda_fb { const struct komeda_format_caps *format_caps; /** @is_va: if smmu is enabled, it will be true */ bool is_va; - /** @aligned_w: aligned frame buffer width */ - u32 aligned_w; - /** @aligned_h: aligned frame buffer height */ - u32 aligned_h; - /** @afbc_size: minimum size of afbc */ - u32 afbc_size; - /** @offset_payload: start of afbc body buffer */ - u32 offset_payload; }; #define to_kfb(dfb) container_of(dfb, struct komeda_fb, base) diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c index 0930234abb9d..281ec5b8d722 100644 --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c @@ -6,6 +6,7 @@ */ #include +#include #include #include "komeda_dev.h" #include "komeda_kms.h" @@ -360,12 +361,14 @@ komeda_layer_validate(struct komeda_layer *layer, st->rot = dflow->rot; if (fb->modifier) { - st->hsize = kfb->aligned_w; - st->vsize = kfb->aligned_h; + st->hsize = kfb->base.afbc_info->aligned_width; + st->vsize = kfb->base.afbc_info->aligned_height; st->afbc_crop_l = dflow->in_x; - st->afbc_crop_r = kfb->aligned_w - dflow->in_x - dflow->in_w; + st->afbc_crop_r = kfb->base.afbc_info->aligned_width + - dflow->in_x - dflow->in_w; st->afbc_crop_t = dflow->in_y; - st->afbc_crop_b = kfb->aligned_h - dflow->in_y - dflow->in_h; + st->afbc_crop_b = kfb->base.afbc_info->aligned_height + - dflow->in_y - dflow->in_h; } else { st->hsize = dflow->in_w; st->vsize = dflow->in_h; From patchwork Fri Dec 13 15:59: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: 11291319 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 DB0FA19A2 for ; Fri, 13 Dec 2019 21:19: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 BC15F2469C for ; Fri, 13 Dec 2019 21:19:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org BC15F2469C 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 AE7A66EA9E; Fri, 13 Dec 2019 16:00:15 +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 0CDBF6EA77 for ; Fri, 13 Dec 2019 15:59:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 6B956292DA7 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 31/36] drm/arm/malidp: Make verify funcitons invocations independent Date: Fri, 13 Dec 2019 16:59:02 +0100 Message-Id: <20191213155907.16581-32-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 --- 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 Fri Dec 13 15:59: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: 11291369 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 C8A8F14E3 for ; Fri, 13 Dec 2019 21:24: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 A7D3F24681 for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A7D3F24681 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 8D7796EA87; Fri, 13 Dec 2019 15:59:41 +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 DAFB36EA7B for ; Fri, 13 Dec 2019 15:59:38 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 07F00292DAC From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 32/36] drm/arm/malidp: Integrate verify functions Date: Fri, 13 Dec 2019 16:59:03 +0100 Message-Id: <20191213155907.16581-33-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 Fri Dec 13 15:59: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: 11291421 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 26BFB2909 for ; Fri, 13 Dec 2019 21:25: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 9993A246A8 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 9993A246A8 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 D0B9B6EAE2; Fri, 13 Dec 2019 16:00:08 +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 7606A6EA82 for ; Fri, 13 Dec 2019 15:59:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id D7F50292DB2 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 33/36] drm/arm/malidp: Factor in afbc framebuffer verification Date: Fri, 13 Dec 2019 16:59:04 +0100 Message-Id: <20191213155907.16581-34-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 Fri Dec 13 15:59: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: 11291387 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 83AE819B6 for ; Fri, 13 Dec 2019 21:24:58 +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 EDEA12469C for ; Fri, 13 Dec 2019 21:24:57 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EDEA12469C 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 BC7AE6EA89; Fri, 13 Dec 2019 16:00:01 +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 9AB956EA77 for ; Fri, 13 Dec 2019 15:59:40 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 77AEB292DB8 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 34/36] drm/arm/malidp: Use generic helpers for afbc checks Date: Fri, 13 Dec 2019 16:59:05 +0100 Message-Id: <20191213155907.16581-35-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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..e49ce6d5d987 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -273,12 +273,17 @@ static struct drm_framebuffer * malidp_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + struct drm_size_check check = { 0 }; + struct drm_gem_object *objs[4]; + struct drm_framebuffer *fb; + int ret, i, num_planes; + + fb = drm_gem_fb_alloc_with_afbc(); + if (!fb) + return ERR_PTR(-ENOMEM); + if (mode_cmd->modifier[0]) { - int n_superblocks = 0; const struct drm_format_info *info; - struct drm_gem_object *objs = NULL; - u32 afbc_superblock_size = 0, afbc_superblock_height = 0; - u32 afbc_superblock_width = 0, afbc_size = 0; int bpp = 0; if (malidp_format_mod_supported(dev, mode_cmd->pixel_format, @@ -302,32 +307,9 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file, return ERR_PTR(-EINVAL); } - switch (mode_cmd->modifier[0] & AFBC_SIZE_MASK) { - case AFBC_SIZE_16X16: - afbc_superblock_height = 16; - afbc_superblock_width = 16; - break; - default: - DRM_DEBUG_KMS("AFBC superblock size is not supported\n"); - return ERR_PTR(-EINVAL); - } - info = drm_get_format_info(dev, mode_cmd); - - n_superblocks = (mode_cmd->width / afbc_superblock_width) * - (mode_cmd->height / afbc_superblock_height); - bpp = malidp_format_get_bpp(info->format); - afbc_superblock_size = - (bpp * afbc_superblock_width * afbc_superblock_height) - / BITS_PER_BYTE; - - afbc_size = ALIGN(n_superblocks * AFBC_HEADER_SIZE, - AFBC_SUPERBLK_ALIGNMENT); - afbc_size += n_superblocks - * ALIGN(afbc_superblock_size, AFBC_SUPERBLK_ALIGNMENT); - if ((mode_cmd->width * bpp) != (mode_cmd->pitches[0] * BITS_PER_BYTE)) { DRM_DEBUG_KMS("Invalid value of (pitch * BITS_PER_BYTE) (=%u) " @@ -336,24 +318,31 @@ malidp_fb_create(struct drm_device *dev, struct drm_file *file, mode_cmd->width, bpp); return ERR_PTR(-EINVAL); } + fb->afbc_info->bpp = bpp; + check.data = fb->afbc_info; + } - objs = drm_gem_object_lookup(file, mode_cmd->handles[0]); - if (!objs) { - DRM_DEBUG_KMS("Failed to lookup GEM object\n"); - return ERR_PTR(-EINVAL); - } + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + goto err_free; + num_planes = ret; - if (objs->size < afbc_size) { - DRM_DEBUG_KMS("buffer size (%zu) too small for AFBC buffer size = %u\n", - objs->size, afbc_size); - drm_gem_object_put_unlocked(objs); - return ERR_PTR(-EINVAL); - } + ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); + if (ret < 0) + goto err_cleanup; - drm_gem_object_put_unlocked(objs); - } + ret = drm_gem_fb_init(fb, dev, mode_cmd, objs, num_planes); + if (ret < 0) + goto err_cleanup; + + return fb; - return drm_gem_fb_create(dev, file, mode_cmd); +err_cleanup: + for (i = 0; i < num_planes; ++i) + drm_gem_object_put_unlocked(objs[i]); +err_free: + kfree(fb); + return ERR_PTR(ret); } static const struct drm_mode_config_funcs malidp_mode_config_funcs = { From patchwork Fri Dec 13 15:59: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: 11291427 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 279C5297F for ; Fri, 13 Dec 2019 21:25: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 A1A7024684 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A1A7024684 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 278526EA8C; Fri, 13 Dec 2019 16:00:02 +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 7A0156EA8C for ; Fri, 13 Dec 2019 15:59:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 7F045292DBF From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 35/36] drm/rockchip: Use helper for common task Date: Fri, 13 Dec 2019 16:59:06 +0100 Message-Id: <20191213155907.16581-36-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 221e72e71432..28ce3a335798 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -18,6 +18,7 @@ #include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" + static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, .create_handle = drm_gem_fb_create_handle, @@ -30,22 +31,14 @@ rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cm { struct drm_framebuffer *fb; int ret; - int i; fb = kzalloc(sizeof(*fb), GFP_KERNEL); if (!fb) return ERR_PTR(-ENOMEM); - drm_helper_mode_fill_fb_struct(dev, fb, mode_cmd); - - for (i = 0; i < num_planes; i++) - fb->obj[i] = obj[i]; - - ret = drm_framebuffer_init(dev, fb, &rockchip_drm_fb_funcs); + ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, + &rockchip_drm_fb_funcs); if (ret) { - DRM_DEV_ERROR(dev->dev, - "Failed to initialize framebuffer: %d\n", - ret); kfree(fb); return ERR_PTR(ret); } From patchwork Fri Dec 13 15:59: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: 11291389 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 84B0F1A2B for ; Fri, 13 Dec 2019 21:24:58 +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 1698224125 for ; Fri, 13 Dec 2019 21:24:58 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1698224125 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 6CB856EAE4; Fri, 13 Dec 2019 16:00:13 +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 2A4206EA89 for ; Fri, 13 Dec 2019 15:59:42 +0000 (UTC) Received: from [127.0.0.1] (localhost [127.0.0.1]) (Authenticated sender: andrzej.p) with ESMTPSA id 2544A292DC0 From: Andrzej Pietrasiewicz To: dri-devel@lists.freedesktop.org Subject: [PATCHv4 36/36] drm/rockchip: Add support for afbc Date: Fri, 13 Dec 2019 16:59:07 +0100 Message-Id: <20191213155907.16581-37-andrzej.p@collabora.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20191213155907.16581-1-andrzej.p@collabora.com> References: <20191213155907.16581-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 --- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 100 +++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 141 +++++++++++++++++++- drivers/gpu/drm/rockchip/rockchip_drm_vop.h | 12 ++ drivers/gpu/drm/rockchip/rockchip_vop_reg.c | 84 +++++++++++- 4 files changed, 331 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 28ce3a335798..0c4014763356 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -18,6 +18,7 @@ #include "rockchip_drm_fb.h" #include "rockchip_drm_gem.h" +#define ROCKCHIP_MAX_AFBC_WIDTH 2560 static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .destroy = drm_gem_fb_destroy, @@ -25,17 +26,60 @@ static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { .dirty = drm_atomic_helper_dirtyfb, }; +static int rockchip_afbc_post_check(struct drm_afbc *afbc) +{ + if (afbc->offset) { + DRM_WARN("AFBC plane offset must be zero!\n"); + return -EINVAL; + } + + if (afbc->block_width != 16 || afbc->block_height != 16) { + DRM_WARN("Unsupported AFBC block w/h [%d/%d]\n", + afbc->block_width, afbc->block_height); + return -EINVAL; + } + + if (afbc->aligned_width > ROCKCHIP_MAX_AFBC_WIDTH) { + DRM_WARN("Unsupported width %d>%d\n", + afbc->aligned_width, ROCKCHIP_MAX_AFBC_WIDTH); + return -EINVAL; + } + + return 0; +} + static struct drm_framebuffer * rockchip_fb_alloc(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **obj, unsigned int num_planes) { struct drm_framebuffer *fb; + struct drm_size_check check = { 0 }; int ret; - fb = kzalloc(sizeof(*fb), GFP_KERNEL); + fb = drm_gem_fb_alloc_with_afbc(); if (!fb) return ERR_PTR(-ENOMEM); + if (drm_is_afbc(mode_cmd->modifier[0])) { + const struct drm_format_info *info = + drm_get_format_info(dev, mode_cmd); + + fb->afbc_info->bpp = info->cpp[0] * 8; + check.data = fb->afbc_info; + } + + ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, obj); + if (ret) { + kfree(fb); + return ERR_PTR(ret); + } + + if (drm_is_afbc(mode_cmd->modifier[0])) + if (rockchip_afbc_post_check(fb->afbc_info)) { + kfree(fb); + return ERR_PTR(-EINVAL); + } + ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, obj, num_planes, &rockchip_drm_fb_funcs); if (ret) { @@ -50,8 +94,60 @@ static const struct drm_mode_config_helper_funcs rockchip_mode_config_helpers = .atomic_commit_tail = drm_atomic_helper_commit_tail_rpm, }; + +static struct drm_framebuffer * +rockchip_fb_create(struct drm_device *dev, struct drm_file *file, + const struct drm_mode_fb_cmd2 *mode_cmd) +{ + struct drm_framebuffer *fb; + struct drm_size_check check = { 0 }; + struct drm_gem_object *objs[4]; + int ret, i, num_planes; + + fb = drm_gem_fb_alloc_with_afbc(); + if (!fb) + return ERR_PTR(-ENOMEM); + + if (drm_is_afbc(mode_cmd->modifier[0])) { + const struct drm_format_info *info = + drm_get_format_info(dev, mode_cmd); + + fb->afbc_info->bpp = info->cpp[0] * 8; + check.data = fb->afbc_info; + } + + ret = drm_gem_fb_lookup(dev, file, mode_cmd, objs); + if (ret < 0) + goto err_free; + num_planes = ret; + + ret = drm_gem_fb_size_check_special(dev, mode_cmd, &check, objs); + if (ret) + goto err_cleanup; + + if (drm_is_afbc(mode_cmd->modifier[0])) + if (rockchip_afbc_post_check(fb->afbc_info)) { + ret = -EINVAL; + goto err_cleanup; + } + + ret = drm_gem_fb_init_with_funcs(fb, dev, mode_cmd, objs, num_planes, + &rockchip_drm_fb_funcs); + if (ret) + goto err_cleanup; + + return fb; + +err_cleanup: + for (i = 0; i < num_planes; ++i) + drm_gem_object_put_unlocked(objs[i]); +err_free: + kfree(fb); + return ERR_PTR(ret); +} + static const struct drm_mode_config_funcs rockchip_drm_mode_config_funcs = { - .fb_create = drm_gem_fb_create_with_dirty, + .fb_create = rockchip_fb_create, .output_poll_changed = drm_fb_helper_output_poll_changed, .atomic_check = drm_atomic_helper_check, .atomic_commit = drm_atomic_helper_commit, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index d04b3492bdac..745d1e8e6d3c 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -91,9 +91,22 @@ #define VOP_WIN_TO_INDEX(vop_win) \ ((vop_win) - (vop_win)->vop->win) +#define VOP_AFBC_SET(vop, name, v) \ + do { \ + if ((vop)->data->afbc) \ + vop_reg_set((vop), &(vop)->data->afbc->name, \ + 0, ~0, v, #name); \ + } while (0) + #define to_vop(x) container_of(x, struct vop, crtc) #define to_vop_win(x) container_of(x, struct vop_win, base) +#define AFBC_FMT_RGB565 0x0 +#define AFBC_FMT_U8U8U8U8 0x5 +#define AFBC_FMT_U8U8U8 0x4 + +#define AFBC_TILE_16x16 BIT(4) + /* * The coefficients of the following matrix are all fixed points. * The format is S2.10 for the 3x3 part of the matrix, and S9.12 for the offsets. @@ -166,6 +179,7 @@ struct vop { /* optional internal rgb encoder */ struct rockchip_rgb *rgb; + struct vop_win *afbc_win; struct vop_win win[]; }; @@ -274,6 +288,29 @@ static enum vop_data_format vop_convert_format(uint32_t format) } } +static int vop_convert_afbc_format(uint32_t format) +{ + switch (format) { + case DRM_FORMAT_XRGB8888: + case DRM_FORMAT_ARGB8888: + case DRM_FORMAT_XBGR8888: + case DRM_FORMAT_ABGR8888: + return AFBC_FMT_U8U8U8U8; + case DRM_FORMAT_RGB888: + case DRM_FORMAT_BGR888: + return AFBC_FMT_U8U8U8; + case DRM_FORMAT_RGB565: + case DRM_FORMAT_BGR565: + return AFBC_FMT_RGB565; + /* either of the below should not be reachable */ + default: + DRM_WARN_ONCE("unsupported AFBC format[%08x]\n", format); + return -EINVAL; + } + + return -EINVAL; +} + static uint16_t scl_vop_cal_scale(enum scale_mode mode, uint32_t src, uint32_t dst, bool is_horizontal, int vsu_mode, int *vskiplines) @@ -598,6 +635,15 @@ static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state) vop_win_disable(vop, vop_win); } } + + if (vop->data->afbc) { + /* + * Disable AFBC and forget there was a vop window with AFBC + */ + VOP_AFBC_SET(vop, enable, 0); + vop->afbc_win = NULL; + } + spin_unlock(&vop->reg_lock); vop_cfg_done(vop); @@ -710,6 +756,39 @@ static void vop_plane_destroy(struct drm_plane *plane) drm_plane_cleanup(plane); } +static bool rockchip_afbc(u64 modifier) +{ + return modifier == + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | + AFBC_FORMAT_MOD_SPARSE); +} + +static bool rockchip_mod_supported(struct drm_plane *plane, + u32 format, u64 modifier) +{ + const struct drm_format_info *info; + + if (WARN_ON(modifier == DRM_FORMAT_MOD_INVALID)) + return false; + + if (modifier == DRM_FORMAT_MOD_LINEAR) + return true; + + if (!rockchip_afbc(modifier)) { + DRM_DEBUG_KMS("Unsupported format modifer 0x%llx\n", modifier); + + return false; + } + + info = drm_format_info(format); + if (info->num_planes != 1) { + DRM_DEBUG_KMS("AFBC buffers expect one plane\n"); + return false; + } + + return true; +} + static int vop_plane_atomic_check(struct drm_plane *plane, struct drm_plane_state *state) { @@ -758,6 +837,32 @@ static int vop_plane_atomic_check(struct drm_plane *plane, return -EINVAL; } + if (rockchip_afbc(fb->modifier)) { + struct vop *vop = to_vop(crtc); + + if (!vop->data->afbc) { + DRM_ERROR("vop does not support AFBC\n"); + return -EINVAL; + } + + ret = vop_convert_afbc_format(fb->format->format); + if (ret < 0) + return ret; + + if (state->src.x1 || state->src.y1) { + DRM_ERROR("afbc does not support offset display\n"); + DRM_ERROR("xpos=%d, ypos=%d, offset=%d\n", + state->src.x1, state->src.y1, fb->offsets[0]); + return -EINVAL; + } + + if (state->rotation && state->rotation != DRM_MODE_ROTATE_0) { + DRM_ERROR("afbc does not support rotation\n"); + DRM_ERROR("rotation=%d\n", state->rotation); + return -EINVAL; + } + } + return 0; } @@ -773,6 +878,11 @@ static void vop_plane_atomic_disable(struct drm_plane *plane, spin_lock(&vop->reg_lock); vop_win_disable(vop, vop_win); + /* + * Forget about the AFBC window if it is being disabled + */ + if (vop_win == vop->afbc_win) + vop->afbc_win = NULL; spin_unlock(&vop->reg_lock); } @@ -812,6 +922,13 @@ static void vop_plane_atomic_update(struct drm_plane *plane, if (WARN_ON(!vop->is_enabled)) return; + /* + * If updating the AFBC window then assume that + * after the update there will be no AFBC window. + */ + if (vop_win == vop->afbc_win) + vop->afbc_win = NULL; + if (!state->visible) { vop_plane_atomic_disable(plane, old_state); return; @@ -846,6 +963,21 @@ static void vop_plane_atomic_update(struct drm_plane *plane, spin_lock(&vop->reg_lock); + if (rockchip_afbc(fb->modifier)) { + int afbc_format = vop_convert_afbc_format(fb->format->format); + + VOP_AFBC_SET(vop, format, afbc_format | AFBC_TILE_16x16); + VOP_AFBC_SET(vop, hreg_block_split, 0); + VOP_AFBC_SET(vop, win_sel, VOP_WIN_TO_INDEX(vop_win)); + VOP_AFBC_SET(vop, hdr_ptr, dma_addr); + VOP_AFBC_SET(vop, pic_size, act_info); + + /* + * The window being udated becomes the AFBC window + */ + vop->afbc_win = vop_win; + } + VOP_WIN_SET(vop, win, format, format); VOP_WIN_SET(vop, win, yrgb_vir, DIV_ROUND_UP(fb->pitches[0], 4)); VOP_WIN_SET(vop, win, yrgb_mst, dma_addr); @@ -1001,6 +1133,7 @@ static const struct drm_plane_funcs vop_plane_funcs = { .reset = drm_atomic_helper_plane_reset, .atomic_duplicate_state = drm_atomic_helper_plane_duplicate_state, .atomic_destroy_state = drm_atomic_helper_plane_destroy_state, + .format_mod_supported = rockchip_mod_supported, }; static int vop_crtc_enable_vblank(struct drm_crtc *crtc) @@ -1340,6 +1473,8 @@ static void vop_crtc_atomic_flush(struct drm_crtc *crtc, spin_lock(&vop->reg_lock); + /* Enable AFBC if there is some AFBC window, disable otherwise. */ + VOP_AFBC_SET(vop, enable, vop->afbc_win != NULL); vop_cfg_done(vop); spin_unlock(&vop->reg_lock); @@ -1634,7 +1769,8 @@ static int vop_create_crtc(struct vop *vop) 0, &vop_plane_funcs, win_data->phy->data_formats, win_data->phy->nformats, - NULL, win_data->type, NULL); + win_data->phy->format_modifiers, + win_data->type, NULL); if (ret) { DRM_DEV_ERROR(vop->dev, "failed to init plane %d\n", ret); @@ -1678,7 +1814,8 @@ static int vop_create_crtc(struct vop *vop) &vop_plane_funcs, win_data->phy->data_formats, win_data->phy->nformats, - NULL, win_data->type, NULL); + win_data->phy->format_modifiers, + win_data->type, NULL); if (ret) { DRM_DEV_ERROR(vop->dev, "failed to init overlay %d\n", ret); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h index 0b3d18c457b2..3f4e88a783d2 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.h +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.h @@ -34,6 +34,16 @@ struct vop_reg { bool relaxed; }; +struct vop_afbc { + struct vop_reg enable; + struct vop_reg win_sel; + struct vop_reg format; + struct vop_reg hreg_block_split; + struct vop_reg pic_size; + struct vop_reg hdr_ptr; + struct vop_reg rstn; +}; + struct vop_modeset { struct vop_reg htotal_pw; struct vop_reg hact_st_end; @@ -134,6 +144,7 @@ struct vop_win_phy { const struct vop_scl_regs *scl; const uint32_t *data_formats; uint32_t nformats; + const uint64_t *format_modifiers; struct vop_reg enable; struct vop_reg gate; @@ -173,6 +184,7 @@ struct vop_data { const struct vop_misc *misc; const struct vop_modeset *modeset; const struct vop_output *output; + const struct vop_afbc *afbc; const struct vop_win_yuv2yuv_data *win_yuv2yuv; const struct vop_win_data *win; unsigned int win_size; diff --git a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c index 7a9d979c8d5d..f0cf1b04591d 100644 --- a/drivers/gpu/drm/rockchip/rockchip_vop_reg.c +++ b/drivers/gpu/drm/rockchip/rockchip_vop_reg.c @@ -50,6 +50,18 @@ static const uint32_t formats_win_full[] = { DRM_FORMAT_NV24, }; +static const uint64_t format_modifiers_win_full[] = { + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + +static const uint64_t format_modifiers_win_full_afbc[] = { + DRM_FORMAT_MOD_ARM_AFBC(AFBC_FORMAT_MOD_BLOCK_SIZE_16x16 | + AFBC_FORMAT_MOD_SPARSE), + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + static const uint32_t formats_win_lite[] = { DRM_FORMAT_XRGB8888, DRM_FORMAT_ARGB8888, @@ -61,6 +73,11 @@ static const uint32_t formats_win_lite[] = { DRM_FORMAT_BGR565, }; +static const uint64_t format_modifiers_win_lite[] = { + DRM_FORMAT_MOD_LINEAR, + DRM_FORMAT_MOD_INVALID, +}; + static const struct vop_scl_regs rk3036_win_scl = { .scale_yrgb_x = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 0x0), .scale_yrgb_y = VOP_REG(RK3036_WIN0_SCL_FACTOR_YRGB, 0xffff, 16), @@ -72,6 +89,7 @@ static const struct vop_win_phy rk3036_win0_data = { .scl = &rk3036_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 0), .format = VOP_REG(RK3036_SYS_CTRL, 0x7, 3), .rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 15), @@ -87,6 +105,7 @@ static const struct vop_win_phy rk3036_win0_data = { static const struct vop_win_phy rk3036_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1), .format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6), .rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19), @@ -153,6 +172,7 @@ static const struct vop_data rk3036_vop = { static const struct vop_win_phy rk3126_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3036_SYS_CTRL, 0x1, 1), .format = VOP_REG(RK3036_SYS_CTRL, 0x7, 6), .rb_swap = VOP_REG(RK3036_SYS_CTRL, 0x1, 19), @@ -234,6 +254,7 @@ static const struct vop_win_phy px30_win0_data = { .scl = &px30_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(PX30_WIN0_CTRL0, 0x1, 0), .format = VOP_REG(PX30_WIN0_CTRL0, 0x7, 1), .rb_swap = VOP_REG(PX30_WIN0_CTRL0, 0x1, 12), @@ -249,6 +270,7 @@ static const struct vop_win_phy px30_win0_data = { static const struct vop_win_phy px30_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(PX30_WIN1_CTRL0, 0x1, 0), .format = VOP_REG(PX30_WIN1_CTRL0, 0x7, 4), .rb_swap = VOP_REG(PX30_WIN1_CTRL0, 0x1, 12), @@ -261,6 +283,7 @@ static const struct vop_win_phy px30_win1_data = { static const struct vop_win_phy px30_win2_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .gate = VOP_REG(PX30_WIN2_CTRL0, 0x1, 4), .enable = VOP_REG(PX30_WIN2_CTRL0, 0x1, 0), .format = VOP_REG(PX30_WIN2_CTRL0, 0x3, 5), @@ -316,6 +339,7 @@ static const struct vop_win_phy rk3066_win0_data = { .scl = &rk3066_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 0), .format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 4), .rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 19), @@ -332,6 +356,7 @@ static const struct vop_win_phy rk3066_win1_data = { .scl = &rk3066_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 1), .format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 7), .rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 23), @@ -347,6 +372,7 @@ static const struct vop_win_phy rk3066_win1_data = { static const struct vop_win_phy rk3066_win2_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3066_SYS_CTRL1, 0x1, 2), .format = VOP_REG(RK3066_SYS_CTRL0, 0x7, 10), .rb_swap = VOP_REG(RK3066_SYS_CTRL0, 0x1, 27), @@ -426,6 +452,7 @@ static const struct vop_win_phy rk3188_win0_data = { .scl = &rk3188_win_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 0), .format = VOP_REG(RK3188_SYS_CTRL, 0x7, 3), .rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 15), @@ -440,6 +467,7 @@ static const struct vop_win_phy rk3188_win0_data = { static const struct vop_win_phy rk3188_win1_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3188_SYS_CTRL, 0x1, 1), .format = VOP_REG(RK3188_SYS_CTRL, 0x7, 6), .rb_swap = VOP_REG(RK3188_SYS_CTRL, 0x1, 19), @@ -545,6 +573,7 @@ static const struct vop_win_phy rk3288_win01_data = { .scl = &rk3288_win_full_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0), .format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1), .rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12), @@ -563,6 +592,7 @@ static const struct vop_win_phy rk3288_win01_data = { static const struct vop_win_phy rk3288_win23_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .enable = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 4), .gate = VOP_REG(RK3288_WIN2_CTRL0, 0x1, 0), .format = VOP_REG(RK3288_WIN2_CTRL0, 0x7, 1), @@ -677,6 +707,7 @@ static const struct vop_win_phy rk3368_win01_data = { .scl = &rk3288_win_full_scl, .data_formats = formats_win_full, .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full, .enable = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 0), .format = VOP_REG(RK3368_WIN0_CTRL0, 0x7, 1), .rb_swap = VOP_REG(RK3368_WIN0_CTRL0, 0x1, 12), @@ -697,6 +728,7 @@ static const struct vop_win_phy rk3368_win01_data = { static const struct vop_win_phy rk3368_win23_data = { .data_formats = formats_win_lite, .nformats = ARRAY_SIZE(formats_win_lite), + .format_modifiers = format_modifiers_win_lite, .gate = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 0), .enable = VOP_REG(RK3368_WIN2_CTRL0, 0x1, 4), .format = VOP_REG(RK3368_WIN2_CTRL0, 0x3, 5), @@ -817,6 +849,53 @@ static const struct vop_win_yuv2yuv_data rk3399_vop_big_win_yuv2yuv_data[] = { .y2r_en = VOP_REG(RK3399_YUV2YUV_WIN, 0x1, 9) }, { .base = 0xC0, .phy = &rk3399_yuv2yuv_win23_data }, { .base = 0x120, .phy = &rk3399_yuv2yuv_win23_data }, + +}; + +static const struct vop_win_phy rk3399_win01_data = { + .scl = &rk3288_win_full_scl, + .data_formats = formats_win_full, + .nformats = ARRAY_SIZE(formats_win_full), + .format_modifiers = format_modifiers_win_full_afbc, + .enable = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 0), + .format = VOP_REG(RK3288_WIN0_CTRL0, 0x7, 1), + .rb_swap = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 12), + .y_mir_en = VOP_REG(RK3288_WIN0_CTRL0, 0x1, 22), + .act_info = VOP_REG(RK3288_WIN0_ACT_INFO, 0x1fff1fff, 0), + .dsp_info = VOP_REG(RK3288_WIN0_DSP_INFO, 0x0fff0fff, 0), + .dsp_st = VOP_REG(RK3288_WIN0_DSP_ST, 0x1fff1fff, 0), + .yrgb_mst = VOP_REG(RK3288_WIN0_YRGB_MST, 0xffffffff, 0), + .uv_mst = VOP_REG(RK3288_WIN0_CBR_MST, 0xffffffff, 0), + .yrgb_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 0), + .uv_vir = VOP_REG(RK3288_WIN0_VIR, 0x3fff, 16), + .src_alpha_ctl = VOP_REG(RK3288_WIN0_SRC_ALPHA_CTRL, 0xff, 0), + .dst_alpha_ctl = VOP_REG(RK3288_WIN0_DST_ALPHA_CTRL, 0xff, 0), +}; + +/* + * rk3399 vop big windows register layout is same as rk3288, but we + * have a separate rk3399 win data array here so that we can advertise + * AFBC on the primary plane. + */ +static const struct vop_win_data rk3399_vop_win_data[] = { + { .base = 0x00, .phy = &rk3399_win01_data, + .type = DRM_PLANE_TYPE_PRIMARY }, + { .base = 0x40, .phy = &rk3288_win01_data, + .type = DRM_PLANE_TYPE_OVERLAY }, + { .base = 0x00, .phy = &rk3288_win23_data, + .type = DRM_PLANE_TYPE_OVERLAY }, + { .base = 0x50, .phy = &rk3288_win23_data, + .type = DRM_PLANE_TYPE_CURSOR }, +}; + +static const struct vop_afbc rk3399_vop_afbc = { + .rstn = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 3), + .enable = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 0), + .win_sel = VOP_REG(RK3399_AFBCD0_CTRL, 0x3, 1), + .format = VOP_REG(RK3399_AFBCD0_CTRL, 0x1f, 16), + .hreg_block_split = VOP_REG(RK3399_AFBCD0_CTRL, 0x1, 21), + .hdr_ptr = VOP_REG(RK3399_AFBCD0_HDR_PTR, 0xffffffff, 0), + .pic_size = VOP_REG(RK3399_AFBCD0_PIC_SIZE, 0xffffffff, 0), }; static const struct vop_data rk3399_vop_big = { @@ -826,9 +905,10 @@ static const struct vop_data rk3399_vop_big = { .common = &rk3288_common, .modeset = &rk3288_modeset, .output = &rk3399_output, + .afbc = &rk3399_vop_afbc, .misc = &rk3368_misc, - .win = rk3368_vop_win_data, - .win_size = ARRAY_SIZE(rk3368_vop_win_data), + .win = rk3399_vop_win_data, + .win_size = ARRAY_SIZE(rk3399_vop_win_data), .win_yuv2yuv = rk3399_vop_big_win_yuv2yuv_data, };