From patchwork Tue Mar 19 21:57:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860435 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 4311E13B5 for ; Tue, 19 Mar 2019 21:57:40 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 279602959B for ; Tue, 19 Mar 2019 21:57:40 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 19844298FF; Tue, 19 Mar 2019 21:57:40 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E8281298A0 for ; Tue, 19 Mar 2019 21:57:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3484189B38; Tue, 19 Mar 2019 21:57:37 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by gabe.freedesktop.org (Postfix) with ESMTPS id 81BA589B33 for ; Tue, 19 Mar 2019 21:57:35 +0000 (UTC) Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id 6C712240002; Tue, 19 Mar 2019 21:57:30 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 01/20] drm: Remove users of drm_format_num_planes Date: Tue, 19 Mar 2019 22:57:06 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drm_format_num_planes() is basically a lookup in the drm_format_info table plus an access to the num_planes field of the appropriate entry. Most drivers are using this function while having access to the entry already, which means that we will perform an unnecessary lookup. Removing the call to drm_format_num_planes is therefore more efficient. Some drivers will not have access to that entry in the function, but in this case the overhead is minimal (we just have to call drm_format_info() to perform the lookup) and we can even avoid multiple, inefficient lookups in some places that need multiple fields from the drm_format_info structure. Signed-off-by: Maxime Ripard Reviewed-by: Paul Kocialkowski Reviewed-by: Emil Velikov --- drivers/gpu/drm/arm/malidp_mw.c | 2 +- drivers/gpu/drm/armada/armada_fb.c | 3 ++- drivers/gpu/drm/drm_fourcc.c | 16 ---------------- drivers/gpu/drm/mediatek/mtk_drm_fb.c | 6 ++++-- drivers/gpu/drm/meson/meson_overlay.c | 2 +- drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c | 9 ++++++--- drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c | 3 ++- drivers/gpu/drm/msm/msm_fb.c | 8 ++++++-- drivers/gpu/drm/omapdrm/omap_fb.c | 4 +++- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 6 +++--- drivers/gpu/drm/tegra/fb.c | 3 ++- drivers/gpu/drm/vc4/vc4_plane.c | 2 +- drivers/gpu/drm/zte/zx_plane.c | 4 +--- include/drm/drm_fourcc.h | 1 - 14 files changed, 32 insertions(+), 37 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_mw.c b/drivers/gpu/drm/arm/malidp_mw.c index 041a64dc7167..91580b7a3781 100644 --- a/drivers/gpu/drm/arm/malidp_mw.c +++ b/drivers/gpu/drm/arm/malidp_mw.c @@ -153,7 +153,7 @@ malidp_mw_encoder_atomic_check(struct drm_encoder *encoder, return -EINVAL; } - n_planes = drm_format_num_planes(fb->format->format); + n_planes = fb->format->num_planes; for (i = 0; i < n_planes; i++) { struct drm_gem_cma_object *obj = drm_fb_cma_get_gem_obj(fb, i); /* memory write buffers are never rotated */ diff --git a/drivers/gpu/drm/armada/armada_fb.c b/drivers/gpu/drm/armada/armada_fb.c index 058ac7d9920f..a2f6472eb482 100644 --- a/drivers/gpu/drm/armada/armada_fb.c +++ b/drivers/gpu/drm/armada/armada_fb.c @@ -87,6 +87,7 @@ struct armada_framebuffer *armada_framebuffer_create(struct drm_device *dev, struct drm_framebuffer *armada_fb_create(struct drm_device *dev, struct drm_file *dfile, const struct drm_mode_fb_cmd2 *mode) { + const struct drm_format_info *info = drm_get_format_info(dev, mode); struct armada_gem_object *obj; struct armada_framebuffer *dfb; int ret; @@ -97,7 +98,7 @@ struct drm_framebuffer *armada_fb_create(struct drm_device *dev, mode->pitches[2]); /* We can only handle a single plane at the moment */ - if (drm_format_num_planes(mode->pixel_format) > 1 && + if (info->num_planes > 1 && (mode->handles[0] != mode->handles[1] || mode->handles[0] != mode->handles[2])) { ret = -EINVAL; diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index ba7e19d4336c..22c7fa459f65 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -306,22 +306,6 @@ drm_get_format_info(struct drm_device *dev, EXPORT_SYMBOL(drm_get_format_info); /** - * drm_format_num_planes - get the number of planes for format - * @format: pixel format (DRM_FORMAT_*) - * - * Returns: - * The number of planes used by the specified pixel format. - */ -int drm_format_num_planes(uint32_t format) -{ - const struct drm_format_info *info; - - info = drm_format_info(format); - return info ? info->num_planes : 1; -} -EXPORT_SYMBOL(drm_format_num_planes); - -/** * drm_format_plane_cpp - determine the bytes per pixel value * @format: pixel format (DRM_FORMAT_*) * @plane: plane index diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c b/drivers/gpu/drm/mediatek/mtk_drm_fb.c index e20fcaef2851..68fdef8b12bd 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c @@ -32,10 +32,11 @@ static struct drm_framebuffer *mtk_drm_framebuffer_init(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode, struct drm_gem_object *obj) { + const struct drm_format_info *info = drm_get_format_info(dev, mode); struct drm_framebuffer *fb; int ret; - if (drm_format_num_planes(mode->pixel_format) != 1) + if (info->num_planes != 1) return ERR_PTR(-EINVAL); fb = kzalloc(sizeof(*fb), GFP_KERNEL); @@ -88,6 +89,7 @@ struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *cmd) { + const struct drm_format_info *info = drm_get_format_info(dev, cmd); struct drm_framebuffer *fb; struct drm_gem_object *gem; unsigned int width = cmd->width; @@ -95,7 +97,7 @@ struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev, unsigned int size, bpp; int ret; - if (drm_format_num_planes(cmd->pixel_format) != 1) + if (info->num_planes != 1) return ERR_PTR(-EINVAL); gem = drm_gem_object_lookup(file, cmd->handles[0]); diff --git a/drivers/gpu/drm/meson/meson_overlay.c b/drivers/gpu/drm/meson/meson_overlay.c index 691a9fd16b36..8ff15d01a8f9 100644 --- a/drivers/gpu/drm/meson/meson_overlay.c +++ b/drivers/gpu/drm/meson/meson_overlay.c @@ -466,7 +466,7 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, } /* Update Canvas with buffer address */ - priv->viu.vd1_planes = drm_format_num_planes(fb->format->format); + priv->viu.vd1_planes = fb->format->num_planes; switch (priv->viu.vd1_planes) { case 3: diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c index 0874f0a53bf9..1aed51b49be4 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c @@ -1040,10 +1040,11 @@ int dpu_format_check_modified_format( const struct drm_mode_fb_cmd2 *cmd, struct drm_gem_object **bos) { - int ret, i, num_base_fmt_planes; + const struct drm_format_info *info; const struct dpu_format *fmt; struct dpu_hw_fmt_layout layout; uint32_t bos_total_size = 0; + int ret, i; if (!msm_fmt || !cmd || !bos) { DRM_ERROR("invalid arguments\n"); @@ -1051,14 +1052,16 @@ int dpu_format_check_modified_format( } fmt = to_dpu_format(msm_fmt); - num_base_fmt_planes = drm_format_num_planes(fmt->base.pixel_format); + info = drm_format_info(fmt->base.pixel_format); + if (!info) + return -EINVAL; ret = dpu_format_get_plane_sizes(fmt, cmd->width, cmd->height, &layout, cmd->pitches); if (ret) return ret; - for (i = 0; i < num_base_fmt_planes; i++) { + for (i = 0; i < info->num_planes; i++) { if (!bos[i]) { DRM_ERROR("invalid handle for plane %d\n", i); return -EINVAL; diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c index 6153514db04c..72ab8d89efa4 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c @@ -127,13 +127,14 @@ uint32_t mdp5_smp_calculate(struct mdp5_smp *smp, const struct mdp_format *format, u32 width, bool hdecim) { + const struct drm_format_info *info = drm_format_info(format->base.pixel_format); struct mdp5_kms *mdp5_kms = get_kms(smp); int rev = mdp5_cfg_get_hw_rev(mdp5_kms->cfg); int i, hsub, nplanes, nlines; u32 fmt = format->base.pixel_format; uint32_t blkcfg = 0; - nplanes = drm_format_num_planes(fmt); + nplanes = info->num_planes; hsub = drm_format_horz_chroma_subsampling(fmt); /* different if BWC (compressed framebuffer?) enabled: */ diff --git a/drivers/gpu/drm/msm/msm_fb.c b/drivers/gpu/drm/msm/msm_fb.c index 136058978e0f..432beddafb9e 100644 --- a/drivers/gpu/drm/msm/msm_fb.c +++ b/drivers/gpu/drm/msm/msm_fb.c @@ -106,9 +106,11 @@ const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb) struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct drm_gem_object *bos[4] = {0}; struct drm_framebuffer *fb; - int ret, i, n = drm_format_num_planes(mode_cmd->pixel_format); + int ret, i, n = info->num_planes; for (i = 0; i < n; i++) { bos[i] = drm_gem_object_lookup(file, mode_cmd->handles[i]); @@ -135,6 +137,8 @@ struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev, static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct msm_drm_private *priv = dev->dev_private; struct msm_kms *kms = priv->kms; struct msm_framebuffer *msm_fb = NULL; @@ -147,7 +151,7 @@ static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, dev, mode_cmd, mode_cmd->width, mode_cmd->height, (char *)&mode_cmd->pixel_format); - n = drm_format_num_planes(mode_cmd->pixel_format); + n = info->num_planes; hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format); vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format); diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index 4f8eb9d08f99..cfb641363a32 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c @@ -298,7 +298,9 @@ void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m) struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - unsigned int num_planes = drm_format_num_planes(mode_cmd->pixel_format); + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); + unsigned int num_planes = info->num_planes; struct drm_gem_object *bos[4]; struct drm_framebuffer *fb; int i; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 97438bbbe389..606d176d5d96 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -74,19 +74,19 @@ static struct drm_framebuffer * rockchip_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct drm_framebuffer *fb; struct drm_gem_object *objs[ROCKCHIP_MAX_FB_BUFFER]; struct drm_gem_object *obj; unsigned int hsub; unsigned int vsub; - int num_planes; + int num_planes = min_t(int, info->num_planes, ROCKCHIP_MAX_FB_BUFFER); int ret; int i; hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format); vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format); - num_planes = min(drm_format_num_planes(mode_cmd->pixel_format), - ROCKCHIP_MAX_FB_BUFFER); for (i = 0; i < num_planes; i++) { unsigned int width = mode_cmd->width / (i ? hsub : 1); diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c index 0a4ce05e00ab..bc8f9afd1b5f 100644 --- a/drivers/gpu/drm/tegra/fb.c +++ b/drivers/gpu/drm/tegra/fb.c @@ -131,6 +131,7 @@ struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, struct drm_file *file, const struct drm_mode_fb_cmd2 *cmd) { + const struct drm_format_info *info = drm_get_format_info(dev, cmd); unsigned int hsub, vsub, i; struct tegra_bo *planes[4]; struct drm_gem_object *gem; @@ -140,7 +141,7 @@ struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, hsub = drm_format_horz_chroma_subsampling(cmd->pixel_format); vsub = drm_format_vert_chroma_subsampling(cmd->pixel_format); - for (i = 0; i < drm_format_num_planes(cmd->pixel_format); i++) { + for (i = 0; i < info->num_planes; i++) { unsigned int width = cmd->width / (i ? hsub : 1); unsigned int height = cmd->height / (i ? vsub : 1); unsigned int size, bpp; diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index 1babfeca0c92..138a9ff23b70 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -537,7 +537,7 @@ static int vc4_plane_mode_set(struct drm_plane *plane, u32 ctl0_offset = vc4_state->dlist_count; const struct hvs_format *format = vc4_get_hvs_format(fb->format->format); u64 base_format_mod = fourcc_mod_broadcom_mod(fb->modifier); - int num_planes = drm_format_num_planes(format->drm); + int num_planes = fb->format->num_planes; u32 h_subsample, v_subsample; bool mix_plane_alpha; bool covers_screen; diff --git a/drivers/gpu/drm/zte/zx_plane.c b/drivers/gpu/drm/zte/zx_plane.c index 83d236fd893c..c6a8be444300 100644 --- a/drivers/gpu/drm/zte/zx_plane.c +++ b/drivers/gpu/drm/zte/zx_plane.c @@ -199,7 +199,6 @@ static void zx_vl_plane_atomic_update(struct drm_plane *plane, u32 dst_x, dst_y, dst_w, dst_h; uint32_t format; int fmt; - int num_planes; int i; if (!fb) @@ -218,9 +217,8 @@ static void zx_vl_plane_atomic_update(struct drm_plane *plane, dst_h = drm_rect_height(dst); /* Set up data address registers for Y, Cb and Cr planes */ - num_planes = drm_format_num_planes(format); paddr_reg = layer + VL_Y; - for (i = 0; i < num_planes; i++) { + for (i = 0; i < fb->format->num_planes; i++) { cma_obj = drm_fb_cma_get_gem_obj(fb, i); paddr = cma_obj->paddr + fb->offsets[i]; paddr += src_y * fb->pitches[i]; diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index b3d9d88ab290..41779b327d91 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -268,7 +268,6 @@ drm_get_format_info(struct drm_device *dev, uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, uint32_t bpp, uint32_t depth); -int drm_format_num_planes(uint32_t format); int drm_format_plane_cpp(uint32_t format, int plane); int drm_format_horz_chroma_subsampling(uint32_t format); int drm_format_vert_chroma_subsampling(uint32_t format); From patchwork Tue Mar 19 21:57:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860437 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 225E26C2 for ; Tue, 19 Mar 2019 21:57:43 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 06DC628908 for ; Tue, 19 Mar 2019 21:57:43 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EEDCF2959B; Tue, 19 Mar 2019 21:57:42 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DF91028908 for ; Tue, 19 Mar 2019 21:57:41 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B1F0C89B84; Tue, 19 Mar 2019 21:57:40 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by gabe.freedesktop.org (Postfix) with ESMTPS id 9789189B48 for ; Tue, 19 Mar 2019 21:57:37 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 2B14DFF804; Tue, 19 Mar 2019 21:57:34 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 02/20] drm: Remove users of drm_format_(horz|vert)_chroma_subsampling Date: Tue, 19 Mar 2019 22:57:07 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drm_format_horz_chroma_subsampling and drm_format_vert_chroma_subsampling are basically a lookup in the drm_format_info table plus an access to the hsub and vsub fields of the appropriate entry. Most drivers are using this function while having access to the entry already, which means that we will perform an unnecessary lookup. Removing the call to these functions is therefore more efficient. Some drivers will not have access to that entry in the function, but in this case the overhead is minimal (we just have to call drm_format_info() to perform the lookup) and we can even avoid multiple, inefficient lookups in some places that need multiple fields from the drm_format_info structure. This is amplified by the fact that most of the time the callers will have to retrieve both the vsub and hsub fields, meaning that they would perform twice the lookup. Signed-off-by: Maxime Ripard Reviewed-by: Paul Kocialkowski --- drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 9 +---- drivers/gpu/drm/drm_fourcc.c | 34 +------------------ drivers/gpu/drm/imx/ipuv3-plane.c | 15 +++----- drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 9 +---- drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 24 +++++-------- drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c | 2 +- drivers/gpu/drm/msm/msm_fb.c | 8 +--- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 9 +---- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 13 ++----- drivers/gpu/drm/tegra/fb.c | 9 +---- drivers/gpu/drm/vc4/vc4_plane.c | 13 ++----- include/drm/drm_fourcc.h | 2 +- 12 files changed, 37 insertions(+), 110 deletions(-) diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c index e836e2de35ce..fdd607ad27fe 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c @@ -603,8 +603,6 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane *p, const struct drm_display_mode *mode; struct drm_crtc_state *crtc_state; unsigned int tmp; - int hsub = 1; - int vsub = 1; int ret; int i; @@ -642,13 +640,10 @@ static int atmel_hlcdc_plane_atomic_check(struct drm_plane *p, if (state->nplanes > ATMEL_HLCDC_LAYER_MAX_PLANES) return -EINVAL; - hsub = drm_format_horz_chroma_subsampling(fb->format->format); - vsub = drm_format_vert_chroma_subsampling(fb->format->format); - for (i = 0; i < state->nplanes; i++) { unsigned int offset = 0; - int xdiv = i ? hsub : 1; - int ydiv = i ? vsub : 1; + int xdiv = i ? fb->format->hsub : 1; + int ydiv = i ? fb->format->vsub : 1; state->bpp[i] = fb->format->cpp[i]; if (!state->bpp[i]) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 22c7fa459f65..04be330b7cae 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -326,40 +326,6 @@ int drm_format_plane_cpp(uint32_t format, int plane) EXPORT_SYMBOL(drm_format_plane_cpp); /** - * drm_format_horz_chroma_subsampling - get the horizontal chroma subsampling factor - * @format: pixel format (DRM_FORMAT_*) - * - * Returns: - * The horizontal chroma subsampling factor for the - * specified pixel format. - */ -int drm_format_horz_chroma_subsampling(uint32_t format) -{ - const struct drm_format_info *info; - - info = drm_format_info(format); - return info ? info->hsub : 1; -} -EXPORT_SYMBOL(drm_format_horz_chroma_subsampling); - -/** - * drm_format_vert_chroma_subsampling - get the vertical chroma subsampling factor - * @format: pixel format (DRM_FORMAT_*) - * - * Returns: - * The vertical chroma subsampling factor for the - * specified pixel format. - */ -int drm_format_vert_chroma_subsampling(uint32_t format) -{ - const struct drm_format_info *info; - - info = drm_format_info(format); - return info ? info->vsub : 1; -} -EXPORT_SYMBOL(drm_format_vert_chroma_subsampling); - -/** * drm_format_plane_width - width of the plane given the first plane * @width: width of the first plane * @format: pixel format diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c index 21e964f6ab5c..2530143281b2 100644 --- a/drivers/gpu/drm/imx/ipuv3-plane.c +++ b/drivers/gpu/drm/imx/ipuv3-plane.c @@ -115,8 +115,8 @@ drm_plane_state_to_ubo(struct drm_plane_state *state) cma_obj = drm_fb_cma_get_gem_obj(fb, 1); BUG_ON(!cma_obj); - x /= drm_format_horz_chroma_subsampling(fb->format->format); - y /= drm_format_vert_chroma_subsampling(fb->format->format); + x /= fb->format->hsub; + y /= fb->format->vsub; return cma_obj->paddr + fb->offsets[1] + fb->pitches[1] * y + fb->format->cpp[1] * x - eba; @@ -134,8 +134,8 @@ drm_plane_state_to_vbo(struct drm_plane_state *state) cma_obj = drm_fb_cma_get_gem_obj(fb, 2); BUG_ON(!cma_obj); - x /= drm_format_horz_chroma_subsampling(fb->format->format); - y /= drm_format_vert_chroma_subsampling(fb->format->format); + x /= fb->format->hsub; + y /= fb->format->vsub; return cma_obj->paddr + fb->offsets[2] + fb->pitches[2] * y + fb->format->cpp[2] * x - eba; @@ -348,7 +348,6 @@ static int ipu_plane_atomic_check(struct drm_plane *plane, struct drm_framebuffer *old_fb = old_state->fb; unsigned long eba, ubo, vbo, old_ubo, old_vbo, alpha_eba; bool can_position = (plane->type == DRM_PLANE_TYPE_OVERLAY); - int hsub, vsub; int ret; /* Ok to disable */ @@ -467,10 +466,8 @@ static int ipu_plane_atomic_check(struct drm_plane *plane, * The x/y offsets must be even in case of horizontal/vertical * chroma subsampling. */ - hsub = drm_format_horz_chroma_subsampling(fb->format->format); - vsub = drm_format_vert_chroma_subsampling(fb->format->format); - if (((state->src.x1 >> 16) & (hsub - 1)) || - ((state->src.y1 >> 16) & (vsub - 1))) + if (((state->src.x1 >> 16) & (fb->format->hsub - 1)) || + ((state->src.y1 >> 16) & (fb->format->vsub - 1))) return -EINVAL; break; case DRM_FORMAT_RGB565_A8: diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c index 6aefcd6db46b..a9492c488441 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c @@ -553,14 +553,9 @@ static void _dpu_plane_setup_scaler(struct dpu_plane *pdpu, struct dpu_plane_state *pstate, const struct dpu_format *fmt, bool color_fill) { - uint32_t chroma_subsmpl_h, chroma_subsmpl_v; + const struct drm_format_info *info = drm_format_info(fmt->base.pixel_format); /* don't chroma subsample if decimating */ - chroma_subsmpl_h = - drm_format_horz_chroma_subsampling(fmt->base.pixel_format); - chroma_subsmpl_v = - drm_format_vert_chroma_subsampling(fmt->base.pixel_format); - /* update scaler. calculate default config for QSEED3 */ _dpu_plane_setup_scaler3(pdpu, pstate, drm_rect_width(&pdpu->pipe_cfg.src_rect), @@ -568,7 +563,7 @@ static void _dpu_plane_setup_scaler(struct dpu_plane *pdpu, drm_rect_width(&pdpu->pipe_cfg.dst_rect), drm_rect_height(&pdpu->pipe_cfg.dst_rect), &pstate->scaler3_cfg, fmt, - chroma_subsmpl_h, chroma_subsmpl_v); + info->hsub, info->vsub); } /** diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c index be13140967b4..9d9fb6c5fd68 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c @@ -650,10 +650,10 @@ static int calc_scalex_steps(struct drm_plane *plane, uint32_t pixel_format, uint32_t src, uint32_t dest, uint32_t phasex_steps[COMP_MAX]) { + const struct drm_format_info *info = drm_format_info(pixel_format); struct mdp5_kms *mdp5_kms = get_kms(plane); struct device *dev = mdp5_kms->dev->dev; uint32_t phasex_step; - unsigned int hsub; int ret; ret = calc_phase_step(src, dest, &phasex_step); @@ -662,11 +662,9 @@ static int calc_scalex_steps(struct drm_plane *plane, return ret; } - hsub = drm_format_horz_chroma_subsampling(pixel_format); - phasex_steps[COMP_0] = phasex_step; phasex_steps[COMP_3] = phasex_step; - phasex_steps[COMP_1_2] = phasex_step / hsub; + phasex_steps[COMP_1_2] = phasex_step / info->hsub; return 0; } @@ -675,10 +673,10 @@ static int calc_scaley_steps(struct drm_plane *plane, uint32_t pixel_format, uint32_t src, uint32_t dest, uint32_t phasey_steps[COMP_MAX]) { + const struct drm_format_info *info = drm_format_info(pixel_format); struct mdp5_kms *mdp5_kms = get_kms(plane); struct device *dev = mdp5_kms->dev->dev; uint32_t phasey_step; - unsigned int vsub; int ret; ret = calc_phase_step(src, dest, &phasey_step); @@ -687,11 +685,9 @@ static int calc_scaley_steps(struct drm_plane *plane, return ret; } - vsub = drm_format_vert_chroma_subsampling(pixel_format); - phasey_steps[COMP_0] = phasey_step; phasey_steps[COMP_3] = phasey_step; - phasey_steps[COMP_1_2] = phasey_step / vsub; + phasey_steps[COMP_1_2] = phasey_step / info->vsub; return 0; } @@ -699,8 +695,9 @@ static int calc_scaley_steps(struct drm_plane *plane, static uint32_t get_scale_config(const struct mdp_format *format, uint32_t src, uint32_t dst, bool horz) { + const struct drm_format_info *info = drm_format_info(format->base.pixel_format); bool scaling = format->is_yuv ? true : (src != dst); - uint32_t sub, pix_fmt = format->base.pixel_format; + uint32_t sub; uint32_t ya_filter, uv_filter; bool yuv = format->is_yuv; @@ -708,8 +705,7 @@ static uint32_t get_scale_config(const struct mdp_format *format, return 0; if (yuv) { - sub = horz ? drm_format_horz_chroma_subsampling(pix_fmt) : - drm_format_vert_chroma_subsampling(pix_fmt); + sub = horz ? info->hsub : info->vsub; uv_filter = ((src / sub) <= dst) ? SCALE_FILTER_BIL : SCALE_FILTER_PCMN; } @@ -754,7 +750,7 @@ static void mdp5_write_pixel_ext(struct mdp5_kms *mdp5_kms, enum mdp5_pipe pipe, uint32_t src_w, int pe_left[COMP_MAX], int pe_right[COMP_MAX], uint32_t src_h, int pe_top[COMP_MAX], int pe_bottom[COMP_MAX]) { - uint32_t pix_fmt = format->base.pixel_format; + const struct drm_format_info *info = drm_format_info(format->base.pixel_format); uint32_t lr, tb, req; int i; @@ -763,8 +759,8 @@ static void mdp5_write_pixel_ext(struct mdp5_kms *mdp5_kms, enum mdp5_pipe pipe, uint32_t roi_h = src_h; if (format->is_yuv && i == COMP_1_2) { - roi_w /= drm_format_horz_chroma_subsampling(pix_fmt); - roi_h /= drm_format_vert_chroma_subsampling(pix_fmt); + roi_w /= info->hsub; + roi_h /= info->vsub; } lr = (pe_left[i] >= 0) ? diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c index 72ab8d89efa4..b30b2f4efc60 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c @@ -135,7 +135,7 @@ uint32_t mdp5_smp_calculate(struct mdp5_smp *smp, uint32_t blkcfg = 0; nplanes = info->num_planes; - hsub = drm_format_horz_chroma_subsampling(fmt); + hsub = info->hsub; /* different if BWC (compressed framebuffer?) enabled: */ nlines = 2; diff --git a/drivers/gpu/drm/msm/msm_fb.c b/drivers/gpu/drm/msm/msm_fb.c index 432beddafb9e..f69c0afd6ec6 100644 --- a/drivers/gpu/drm/msm/msm_fb.c +++ b/drivers/gpu/drm/msm/msm_fb.c @@ -145,16 +145,12 @@ static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, struct drm_framebuffer *fb; const struct msm_format *format; int ret, i, n; - unsigned int hsub, vsub; DBG("create framebuffer: dev=%p, mode_cmd=%p (%dx%d@%4.4s)", dev, mode_cmd, mode_cmd->width, mode_cmd->height, (char *)&mode_cmd->pixel_format); n = info->num_planes; - hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format); - vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format); - format = kms->funcs->get_format(kms, mode_cmd->pixel_format, mode_cmd->modifier[0]); if (!format) { @@ -180,8 +176,8 @@ static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, } for (i = 0; i < n; i++) { - unsigned int width = mode_cmd->width / (i ? hsub : 1); - unsigned int height = mode_cmd->height / (i ? vsub : 1); + 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] diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index 606d176d5d96..c318fae28581 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -79,18 +79,13 @@ rockchip_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, struct drm_framebuffer *fb; struct drm_gem_object *objs[ROCKCHIP_MAX_FB_BUFFER]; struct drm_gem_object *obj; - unsigned int hsub; - unsigned int vsub; int num_planes = min_t(int, info->num_planes, ROCKCHIP_MAX_FB_BUFFER); int ret; int i; - hsub = drm_format_horz_chroma_subsampling(mode_cmd->pixel_format); - vsub = drm_format_vert_chroma_subsampling(mode_cmd->pixel_format); - for (i = 0; i < num_planes; i++) { - unsigned int width = mode_cmd->width / (i ? hsub : 1); - unsigned int height = mode_cmd->height / (i ? vsub : 1); + unsigned int width = mode_cmd->width / (i ? info->hsub : 1); + unsigned int height = mode_cmd->height / (i ? info->vsub : 1); unsigned int min_size; obj = drm_gem_object_lookup(file_priv, mode_cmd->handles[i]); diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index c7d4c6073ea5..88c3902057f3 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -317,21 +317,18 @@ static void scl_vop_cal_scl_fac(struct vop *vop, const struct vop_win_data *win, uint32_t src_w, uint32_t src_h, uint32_t dst_w, uint32_t dst_h, uint32_t pixel_format) { + const struct drm_format_info *info = drm_format_info(pixel_format); uint16_t yrgb_hor_scl_mode, yrgb_ver_scl_mode; uint16_t cbcr_hor_scl_mode = SCALE_NONE; uint16_t cbcr_ver_scl_mode = SCALE_NONE; - int hsub = drm_format_horz_chroma_subsampling(pixel_format); - int vsub = drm_format_vert_chroma_subsampling(pixel_format); - const struct drm_format_info *info; bool is_yuv = false; - uint16_t cbcr_src_w = src_w / hsub; - uint16_t cbcr_src_h = src_h / vsub; + uint16_t cbcr_src_w = src_w / info->hsub; + uint16_t cbcr_src_h = src_h / info->vsub; uint16_t vsu_mode; uint16_t lb_mode; uint32_t val; int vskiplines; - info = drm_format_info(pixel_format); if (info->is_yuv) is_yuv = true; @@ -819,8 +816,8 @@ static void vop_plane_atomic_update(struct drm_plane *plane, (state->rotation & DRM_MODE_REFLECT_X) ? 1 : 0); if (is_yuv) { - int hsub = drm_format_horz_chroma_subsampling(fb->format->format); - int vsub = drm_format_vert_chroma_subsampling(fb->format->format); + int hsub = fb->format->hsub; + int vsub = fb->format->vsub; int bpp = fb->format->cpp[1]; uv_obj = fb->obj[1]; diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c index bc8f9afd1b5f..ddf2c764f24c 100644 --- a/drivers/gpu/drm/tegra/fb.c +++ b/drivers/gpu/drm/tegra/fb.c @@ -132,18 +132,15 @@ struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, const struct drm_mode_fb_cmd2 *cmd) { const struct drm_format_info *info = drm_get_format_info(dev, cmd); - unsigned int hsub, vsub, i; struct tegra_bo *planes[4]; struct drm_gem_object *gem; struct drm_framebuffer *fb; + unsigned int i; int err; - hsub = drm_format_horz_chroma_subsampling(cmd->pixel_format); - vsub = drm_format_vert_chroma_subsampling(cmd->pixel_format); - for (i = 0; i < info->num_planes; i++) { - unsigned int width = cmd->width / (i ? hsub : 1); - unsigned int height = cmd->height / (i ? vsub : 1); + unsigned int width = cmd->width / (i ? info->hsub : 1); + unsigned int height = cmd->height / (i ? info->vsub : 1); unsigned int size, bpp; gem = drm_gem_object_lookup(file, cmd->handles[i]); diff --git a/drivers/gpu/drm/vc4/vc4_plane.c b/drivers/gpu/drm/vc4/vc4_plane.c index 138a9ff23b70..6605c1b7370d 100644 --- a/drivers/gpu/drm/vc4/vc4_plane.c +++ b/drivers/gpu/drm/vc4/vc4_plane.c @@ -310,10 +310,10 @@ static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state) struct drm_framebuffer *fb = state->fb; struct drm_gem_cma_object *bo = drm_fb_cma_get_gem_obj(fb, 0); u32 subpixel_src_mask = (1 << 16) - 1; - u32 format = fb->format->format; int num_planes = fb->format->num_planes; struct drm_crtc_state *crtc_state; - u32 h_subsample, v_subsample; + u32 h_subsample = fb->format->hsub; + u32 v_subsample = fb->format->vsub; int i, ret; crtc_state = drm_atomic_get_existing_crtc_state(state->state, @@ -328,9 +328,6 @@ static int vc4_plane_setup_clipping_and_scaling(struct drm_plane_state *state) if (ret) return ret; - h_subsample = drm_format_horz_chroma_subsampling(format); - v_subsample = drm_format_vert_chroma_subsampling(format); - for (i = 0; i < num_planes; i++) vc4_state->offsets[i] = bo->paddr + fb->offsets[i]; @@ -538,7 +535,8 @@ static int vc4_plane_mode_set(struct drm_plane *plane, const struct hvs_format *format = vc4_get_hvs_format(fb->format->format); u64 base_format_mod = fourcc_mod_broadcom_mod(fb->modifier); int num_planes = fb->format->num_planes; - u32 h_subsample, v_subsample; + u32 h_subsample = fb->format->hsub; + u32 v_subsample = fb->format->vsub; bool mix_plane_alpha; bool covers_screen; u32 scl0, scl1, pitch0; @@ -568,9 +566,6 @@ static int vc4_plane_mode_set(struct drm_plane *plane, scl1 = vc4_get_scl_field(state, 0); } - h_subsample = drm_format_horz_chroma_subsampling(format->drm); - v_subsample = drm_format_vert_chroma_subsampling(format->drm); - rotation = drm_rotation_simplify(state->rotation, DRM_MODE_ROTATE_0 | DRM_MODE_REFLECT_X | diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 41779b327d91..eeec449d6c6a 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -269,8 +269,6 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, uint32_t bpp, uint32_t depth); int drm_format_plane_cpp(uint32_t format, int plane); -int drm_format_horz_chroma_subsampling(uint32_t format); -int drm_format_vert_chroma_subsampling(uint32_t format); int drm_format_plane_width(int width, uint32_t format, int plane); int drm_format_plane_height(int height, uint32_t format, int plane); unsigned int drm_format_info_block_width(const struct drm_format_info *info, From patchwork Tue Mar 19 21:57:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860439 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id DEE5313B5 for ; Tue, 19 Mar 2019 21:57:45 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C5AFE2894C for ; Tue, 19 Mar 2019 21:57:45 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B906C29901; Tue, 19 Mar 2019 21:57:45 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id CD4762894C for ; Tue, 19 Mar 2019 21:57:44 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B00CB89B48; Tue, 19 Mar 2019 21:57:43 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 044BE89B96 for ; Tue, 19 Mar 2019 21:57:41 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 13106C0008; Tue, 19 Mar 2019 21:57:36 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 03/20] drm/fourcc: Pass the format_info pointer to drm_format_plane_cpp Date: Tue, 19 Mar 2019 22:57:08 +0100 Message-Id: <6e5850afb02cc2851fe3229122fb3cb4869dc108.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP So far, the drm_format_plane_cpp function was operating on the format's fourcc and was doing a lookup to retrieve the drm_format_info structure and return the cpp. However, this is inefficient since in most cases, we will have the drm_format_info pointer already available so we shouldn't have to perform a new lookup. Some drm_fourcc functions also already operate on the drm_format_info pointer for that reason, so the API is quite inconsistent there. Let's follow the latter pattern and remove the extra lookup while being a bit more consistent. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c | 4 +++- drivers/gpu/drm/arm/malidp_hw.c | 4 +++- drivers/gpu/drm/cirrus/cirrus_fbdev.c | 4 +++- drivers/gpu/drm/cirrus/cirrus_main.c | 4 +++- drivers/gpu/drm/drm_client.c | 3 ++- drivers/gpu/drm/drm_fb_helper.c | 2 +- drivers/gpu/drm/drm_fourcc.c | 7 ++----- drivers/gpu/drm/i915/intel_sprite.c | 3 ++- drivers/gpu/drm/mediatek/mtk_drm_fb.c | 2 +- drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 3 ++- drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c | 2 +- drivers/gpu/drm/msm/msm_fb.c | 2 +- drivers/gpu/drm/radeon/radeon_fb.c | 4 +++- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 2 +- drivers/gpu/drm/stm/ltdc.c | 2 +- drivers/gpu/drm/tegra/fb.c | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 2 +- drivers/gpu/drm/zte/zx_plane.c | 2 +- include/drm/drm_fourcc.h | 2 +- 19 files changed, 33 insertions(+), 23 deletions(-) diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c index 5cbde74b97dd..48170a843b48 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c @@ -123,6 +123,8 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev, struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **gobj_p) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct amdgpu_device *adev = rfbdev->adev; struct drm_gem_object *gobj = NULL; struct amdgpu_bo *abo = NULL; @@ -133,7 +135,7 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev, int height = mode_cmd->height; u32 cpp; - cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0); + cpp = drm_format_plane_cpp(info, 0); /* need to align pitch with crtc limits */ mode_cmd->pitches[0] = amdgpu_align_pitch(adev, mode_cmd->width, cpp, diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_hw.c index b9bed1138fa3..07971ad53b29 100644 --- a/drivers/gpu/drm/arm/malidp_hw.c +++ b/drivers/gpu/drm/arm/malidp_hw.c @@ -326,12 +326,14 @@ static void malidp500_modeset(struct malidp_hw_device *hwdev, struct videomode * static int malidp500_rotmem_required(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt) { + const struct drm_format_info *info = drm_format_info(fmt); + /* * Each layer needs enough rotation memory to fit 8 lines * worth of pixel data. Required size is then: * size = rotated_width * (bpp / 8) * 8; */ - return w * drm_format_plane_cpp(fmt, 0) * 8; + return w * drm_format_plane_cpp(info, 0) * 8; } static void malidp500_se_write_pp_coefftab(struct malidp_hw_device *hwdev, diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c b/drivers/gpu/drm/cirrus/cirrus_fbdev.c index 39df62acac69..759847bafda8 100644 --- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c +++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c @@ -137,6 +137,8 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **gobj_p) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct drm_device *dev = afbdev->helper.dev; struct cirrus_device *cdev = dev->dev_private; u32 bpp; @@ -144,7 +146,7 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, struct drm_gem_object *gobj; int ret = 0; - bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0) * 8; + bpp = drm_format_plane_cpp(info, 0) * 8; if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height, bpp, mode_cmd->pitches[0])) diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c b/drivers/gpu/drm/cirrus/cirrus_main.c index 57f8fe6d020b..66d0d2c5211d 100644 --- a/drivers/gpu/drm/cirrus/cirrus_main.c +++ b/drivers/gpu/drm/cirrus/cirrus_main.c @@ -41,13 +41,15 @@ cirrus_user_framebuffer_create(struct drm_device *dev, struct drm_file *filp, const struct drm_mode_fb_cmd2 *mode_cmd) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct cirrus_device *cdev = dev->dev_private; struct drm_gem_object *obj; struct drm_framebuffer *fb; u32 bpp; int ret; - bpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0) * 8; + bpp = drm_format_plane_cpp(info, 0) * 8; if (!cirrus_check_framebuffer(cdev, mode_cmd->width, mode_cmd->height, bpp, mode_cmd->pitches[0])) diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index 9b2bd28dde0a..305d6dd5d201 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -242,6 +242,7 @@ static void drm_client_buffer_delete(struct drm_client_buffer *buffer) static struct drm_client_buffer * drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) { + const struct drm_format_info *info = drm_format_info(format); struct drm_mode_create_dumb dumb_args = { }; struct drm_device *dev = client->dev; struct drm_client_buffer *buffer; @@ -257,7 +258,7 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u dumb_args.width = width; dumb_args.height = height; - dumb_args.bpp = drm_format_plane_cpp(format, 0) * 8; + dumb_args.bpp = drm_format_plane_cpp(info, 0) * 8; ret = drm_mode_create_dumb(dev, &dumb_args, client->file); if (ret) goto err_delete; diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 04d23cb430bf..257a9c995057 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -768,7 +768,7 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, struct drm_clip_rect *clip) { struct drm_framebuffer *fb = fb_helper->fb; - unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0); + unsigned int cpp = drm_format_plane_cpp(fb->format, 0); size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; void *src = fb_helper->fbdev->screen_buffer + offset; void *dst = fb_helper->buffer->vaddr + offset; diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 04be330b7cae..d8ada4cb689e 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -307,17 +307,14 @@ EXPORT_SYMBOL(drm_get_format_info); /** * drm_format_plane_cpp - determine the bytes per pixel value - * @format: pixel format (DRM_FORMAT_*) + * @format: pixel format info * @plane: plane index * * Returns: * The bytes per pixel value for the specified plane. */ -int drm_format_plane_cpp(uint32_t format, int plane) +int drm_format_plane_cpp(const struct drm_format_info *info, int plane) { - const struct drm_format_info *info; - - info = drm_format_info(format); if (!info || plane >= info->num_planes) return 0; diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c index b56a1a9ad01d..ee0e99b13532 100644 --- a/drivers/gpu/drm/i915/intel_sprite.c +++ b/drivers/gpu/drm/i915/intel_sprite.c @@ -297,7 +297,8 @@ skl_plane_max_stride(struct intel_plane *plane, u32 pixel_format, u64 modifier, unsigned int rotation) { - int cpp = drm_format_plane_cpp(pixel_format, 0); + const struct drm_format_info *info = drm_format_info(pixel_format); + int cpp = drm_format_plane_cpp(info, 0); /* * "The stride in bytes must not exceed the diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c b/drivers/gpu/drm/mediatek/mtk_drm_fb.c index 68fdef8b12bd..af90c84e9e02 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c @@ -104,7 +104,7 @@ struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev, if (!gem) return ERR_PTR(-ENOENT); - bpp = drm_format_plane_cpp(cmd->pixel_format, 0); + bpp = drm_format_plane_cpp(info, 0); size = (height - 1) * cmd->pitches[0] + width * bpp; size += cmd->offsets[0]; diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c index b0cf63c4e3d7..aadae21f8818 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c @@ -782,6 +782,7 @@ static void get_roi(struct drm_crtc *crtc, uint32_t *roi_w, uint32_t *roi_h) static void mdp5_crtc_restore_cursor(struct drm_crtc *crtc) { + const struct drm_format_info *info = drm_format_info(DRM_FORMAT_ARGB8888); struct mdp5_crtc_state *mdp5_cstate = to_mdp5_crtc_state(crtc->state); struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc); struct mdp5_kms *mdp5_kms = get_kms(crtc); @@ -800,7 +801,7 @@ static void mdp5_crtc_restore_cursor(struct drm_crtc *crtc) width = mdp5_crtc->cursor.width; height = mdp5_crtc->cursor.height; - stride = width * drm_format_plane_cpp(DRM_FORMAT_ARGB8888, 0); + stride = width * drm_format_plane_cpp(info, 0); get_roi(crtc, &roi_w, &roi_h); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c index b30b2f4efc60..03d503d8c3ba 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c @@ -158,7 +158,7 @@ uint32_t mdp5_smp_calculate(struct mdp5_smp *smp, for (i = 0; i < nplanes; i++) { int n, fetch_stride, cpp; - cpp = drm_format_plane_cpp(fmt, i); + cpp = drm_format_plane_cpp(info, i); fetch_stride = width * cpp / (i ? hsub : 1); n = DIV_ROUND_UP(fetch_stride * nlines, smp->blk_size); diff --git a/drivers/gpu/drm/msm/msm_fb.c b/drivers/gpu/drm/msm/msm_fb.c index f69c0afd6ec6..ee91058c7974 100644 --- a/drivers/gpu/drm/msm/msm_fb.c +++ b/drivers/gpu/drm/msm/msm_fb.c @@ -181,7 +181,7 @@ static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, unsigned int min_size; min_size = (height - 1) * mode_cmd->pitches[i] - + width * drm_format_plane_cpp(mode_cmd->pixel_format, i) + + width * drm_format_plane_cpp(info, i) + mode_cmd->offsets[i]; if (bos[i]->size < min_size) { diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c index 1179034024ae..88fc1a6e2e43 100644 --- a/drivers/gpu/drm/radeon/radeon_fb.c +++ b/drivers/gpu/drm/radeon/radeon_fb.c @@ -125,6 +125,8 @@ static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev, struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **gobj_p) { + const struct drm_format_info *info = drm_get_format_info(dev, + mode_cmd); struct radeon_device *rdev = rfbdev->rdev; struct drm_gem_object *gobj = NULL; struct radeon_bo *rbo = NULL; @@ -135,7 +137,7 @@ static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev, int height = mode_cmd->height; u32 cpp; - cpp = drm_format_plane_cpp(mode_cmd->pixel_format, 0); + cpp = drm_format_plane_cpp(info, 0); /* need to align pitch with crtc limits */ mode_cmd->pitches[0] = radeon_align_pitch(rdev, mode_cmd->width, cpp, diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index c318fae28581..c602cb2f4d3c 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -98,7 +98,7 @@ rockchip_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, min_size = (height - 1) * mode_cmd->pitches[i] + mode_cmd->offsets[i] + - width * drm_format_plane_cpp(mode_cmd->pixel_format, i); + width * drm_format_plane_cpp(info, i); if (obj->size < min_size) { drm_gem_object_put_unlocked(obj); diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c index b1741a9d5be2..b226df7dbf6f 100644 --- a/drivers/gpu/drm/stm/ltdc.c +++ b/drivers/gpu/drm/stm/ltdc.c @@ -779,7 +779,7 @@ static void ltdc_plane_atomic_update(struct drm_plane *plane, /* Configures the color frame buffer pitch in bytes & line length */ pitch_in_bytes = fb->pitches[0]; - line_length = drm_format_plane_cpp(fb->format->format, 0) * + line_length = drm_format_plane_cpp(fb->format, 0) * (x1 - x0 + 1) + (ldev->caps.bus_width >> 3) - 1; val = ((pitch_in_bytes << 16) | line_length); reg_update_bits(ldev->regs, LTDC_L1CFBLR + lofs, diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c index ddf2c764f24c..0a97458b286a 100644 --- a/drivers/gpu/drm/tegra/fb.c +++ b/drivers/gpu/drm/tegra/fb.c @@ -149,7 +149,7 @@ struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, goto unreference; } - bpp = drm_format_plane_cpp(cmd->pixel_format, i); + bpp = drm_format_plane_cpp(info, i); size = (height - 1) * cmd->pitches[i] + width * bpp + cmd->offsets[i]; diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index 2737b6fdadc8..57dda9d1a45d 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c @@ -36,7 +36,7 @@ MODULE_PARM_DESC(spi_max, "Set a lower SPI max transfer size"); void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb, struct drm_rect *clip) { - unsigned int cpp = drm_format_plane_cpp(fb->format->format, 0); + unsigned int cpp = drm_format_plane_cpp(fb->format, 0); unsigned int pitch = fb->pitches[0]; void *src = vaddr + (clip->y1 * pitch) + (clip->x1 * cpp); size_t len = (clip->x2 - clip->x1) * cpp; diff --git a/drivers/gpu/drm/zte/zx_plane.c b/drivers/gpu/drm/zte/zx_plane.c index c6a8be444300..41bd0db4e876 100644 --- a/drivers/gpu/drm/zte/zx_plane.c +++ b/drivers/gpu/drm/zte/zx_plane.c @@ -222,7 +222,7 @@ static void zx_vl_plane_atomic_update(struct drm_plane *plane, cma_obj = drm_fb_cma_get_gem_obj(fb, i); paddr = cma_obj->paddr + fb->offsets[i]; paddr += src_y * fb->pitches[i]; - paddr += src_x * drm_format_plane_cpp(format, i); + paddr += src_x * drm_format_plane_cpp(fb->format, i); zx_writel(paddr_reg, paddr); paddr_reg += 4; } diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index eeec449d6c6a..97a58f3e7462 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -268,7 +268,7 @@ drm_get_format_info(struct drm_device *dev, uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, uint32_t bpp, uint32_t depth); -int drm_format_plane_cpp(uint32_t format, int plane); +int drm_format_plane_cpp(const struct drm_format_info *info, int plane); int drm_format_plane_width(int width, uint32_t format, int plane); int drm_format_plane_height(int height, uint32_t format, int plane); unsigned int drm_format_info_block_width(const struct drm_format_info *info, From patchwork Tue Mar 19 21:57:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860441 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9385F13B5 for ; Tue, 19 Mar 2019 21:57:48 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7A6E328908 for ; Tue, 19 Mar 2019 21:57:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6F14B298A0; Tue, 19 Mar 2019 21:57:48 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 07CB528908 for ; Tue, 19 Mar 2019 21:57:47 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E173289B8F; Tue, 19 Mar 2019 21:57:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6A67489B62 for ; Tue, 19 Mar 2019 21:57:45 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 377EE240003; Tue, 19 Mar 2019 21:57:39 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 04/20] drm/fourcc: Pass the format_info pointer to drm_format_plane_width/height Date: Tue, 19 Mar 2019 22:57:09 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP So far, the drm_format_plane_height/width functions were operating on the format's fourcc and was doing a lookup to retrieve the drm_format_info structure and return the cpp. However, this is inefficient since in most cases, we will have the drm_format_info pointer already available so we shouldn't have to perform a new lookup. Some drm_fourcc functions also already operate on the drm_format_info pointer for that reason, so the API is quite inconsistent there. Let's follow the latter pattern and remove the extra lookup while being a bit more consistent. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_fourcc.c | 16 ++++++---------- drivers/gpu/drm/meson/meson_overlay.c | 6 +++--- include/drm/drm_fourcc.h | 6 ++++-- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index d8ada4cb689e..57389b9753b2 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -325,17 +325,15 @@ EXPORT_SYMBOL(drm_format_plane_cpp); /** * drm_format_plane_width - width of the plane given the first plane * @width: width of the first plane - * @format: pixel format + * @format: pixel format info * @plane: plane index * * Returns: * The width of @plane, given that the width of the first plane is @width. */ -int drm_format_plane_width(int width, uint32_t format, int plane) +int drm_format_plane_width(int width, const struct drm_format_info *info, + int plane) { - const struct drm_format_info *info; - - info = drm_format_info(format); if (!info || plane >= info->num_planes) return 0; @@ -349,17 +347,15 @@ EXPORT_SYMBOL(drm_format_plane_width); /** * drm_format_plane_height - height of the plane given the first plane * @height: height of the first plane - * @format: pixel format + * @format: pixel format info * @plane: plane index * * Returns: * The height of @plane, given that the height of the first plane is @height. */ -int drm_format_plane_height(int height, uint32_t format, int plane) +int drm_format_plane_height(int height, const struct drm_format_info *info, + int plane) { - const struct drm_format_info *info; - - info = drm_format_info(format); if (!info || plane >= info->num_planes) return 0; diff --git a/drivers/gpu/drm/meson/meson_overlay.c b/drivers/gpu/drm/meson/meson_overlay.c index 8ff15d01a8f9..6987c15b6ab9 100644 --- a/drivers/gpu/drm/meson/meson_overlay.c +++ b/drivers/gpu/drm/meson/meson_overlay.c @@ -475,7 +475,7 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, priv->viu.vd1_stride2 = fb->pitches[2]; priv->viu.vd1_height2 = drm_format_plane_height(fb->height, - fb->format->format, 2); + fb->format, 2); DRM_DEBUG("plane 2 addr 0x%x stride %d height %d\n", priv->viu.vd1_addr2, priv->viu.vd1_stride2, @@ -487,7 +487,7 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, priv->viu.vd1_stride1 = fb->pitches[1]; priv->viu.vd1_height1 = drm_format_plane_height(fb->height, - fb->format->format, 1); + fb->format, 1); DRM_DEBUG("plane 1 addr 0x%x stride %d height %d\n", priv->viu.vd1_addr1, priv->viu.vd1_stride1, @@ -499,7 +499,7 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, priv->viu.vd1_stride0 = fb->pitches[0]; priv->viu.vd1_height0 = drm_format_plane_height(fb->height, - fb->format->format, 0); + fb->format, 0); DRM_DEBUG("plane 0 addr 0x%x stride %d height %d\n", priv->viu.vd1_addr0, priv->viu.vd1_stride0, diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 97a58f3e7462..2291f2618211 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -269,8 +269,10 @@ uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, uint32_t bpp, uint32_t depth); int drm_format_plane_cpp(const struct drm_format_info *info, int plane); -int drm_format_plane_width(int width, uint32_t format, int plane); -int drm_format_plane_height(int height, uint32_t format, int plane); +int drm_format_plane_width(int width, const struct drm_format_info *info, + int plane); +int drm_format_plane_height(int height, const struct drm_format_info *info, + int plane); unsigned int drm_format_info_block_width(const struct drm_format_info *info, int plane); unsigned int drm_format_info_block_height(const struct drm_format_info *info, From patchwork Tue Mar 19 21:57:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860443 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 94EFC6C2 for ; Tue, 19 Mar 2019 21:57:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7ACD22894C for ; Tue, 19 Mar 2019 21:57:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6E8B128A32; Tue, 19 Mar 2019 21:57:52 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 27BC928A32 for ; Tue, 19 Mar 2019 21:57:52 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3E49489B97; Tue, 19 Mar 2019 21:57:51 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id E923A89B96 for ; Tue, 19 Mar 2019 21:57:47 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id 3A8DC40008; Tue, 19 Mar 2019 21:57:43 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 05/20] drm: Replace instances of drm_format_info by drm_get_format_info Date: Tue, 19 Mar 2019 22:57:10 +0100 Message-Id: <2c4461e827cf9a64326962094f7420bfafc5e13b.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP drm_get_format_info directly calls into drm_format_info, but takes directly a struct drm_mode_fb_cmd2 pointer, instead of the fourcc directly. It's shorter to not dereference it, and we can customise the behaviour at the driver level if we want to, so let's switch to it where it makes sense. Signed-off-by: Maxime Ripard Reviewed-by: Paul Kocialkowski --- drivers/gpu/drm/gma500/framebuffer.c | 2 +- drivers/gpu/drm/omapdrm/omap_fb.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c index c934b3df1f81..46f0078f7a91 100644 --- a/drivers/gpu/drm/gma500/framebuffer.c +++ b/drivers/gpu/drm/gma500/framebuffer.c @@ -232,7 +232,7 @@ static int psb_framebuffer_init(struct drm_device *dev, * Reject unknown formats, YUV formats, and formats with more than * 4 bytes per pixel. */ - info = drm_format_info(mode_cmd->pixel_format); + info = drm_get_format_info(dev, mode_cmd); if (!info || !info->depth || info->cpp[0] > 4) return -EINVAL; diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index cfb641363a32..6557b2d6e16e 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c @@ -339,7 +339,7 @@ struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, dev, mode_cmd, mode_cmd->width, mode_cmd->height, (char *)&mode_cmd->pixel_format); - format = drm_format_info(mode_cmd->pixel_format); + format = drm_get_format_info(dev, mode_cmd); for (i = 0; i < ARRAY_SIZE(formats); i++) { if (formats[i] == mode_cmd->pixel_format) From patchwork Tue Mar 19 21:57:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860447 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7B0E613B5 for ; Tue, 19 Mar 2019 21:57:58 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5CF4C2892E for ; Tue, 19 Mar 2019 21:57:58 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5132229906; Tue, 19 Mar 2019 21:57:58 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 9C94B2892E for ; Tue, 19 Mar 2019 21:57:54 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8C03389B9E; Tue, 19 Mar 2019 21:57:53 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 6B94689B96 for ; Tue, 19 Mar 2019 21:57:49 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 0CE34240005; Tue, 19 Mar 2019 21:57:45 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 06/20] lib: Add video format information library Date: Tue, 19 Mar 2019 22:57:11 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Move the DRM formats API to turn this into a more generic image formats API to be able to leverage it into some other places of the kernel, such as v4l2 drivers. Signed-off-by: Maxime Ripard --- include/linux/image-formats.h | 240 +++++++++++- lib/Kconfig | 7 +- lib/Makefile | 3 +- lib/image-formats-selftests.c | 326 +++++++++++++++- lib/image-formats.c | 760 +++++++++++++++++++++++++++++++++++- 5 files changed, 1336 insertions(+) create mode 100644 include/linux/image-formats.h create mode 100644 lib/image-formats-selftests.c create mode 100644 lib/image-formats.c diff --git a/include/linux/image-formats.h b/include/linux/image-formats.h new file mode 100644 index 000000000000..53fd73a71b3d --- /dev/null +++ b/include/linux/image-formats.h @@ -0,0 +1,240 @@ +#ifndef _IMAGE_FORMATS_H_ +#define _IMAGE_FORMATS_H_ + +#include + +/** + * struct image_format_info - information about a image format + */ +struct image_format_info { + union { + /** + * @drm_fmt: + * + * DRM 4CC format identifier (DRM_FORMAT_*) + */ + u32 drm_fmt; + + /** + * @format: + * + * DRM 4CC format identifier (DRM_FORMAT_*). Kept + * around for compatibility reasons with the current + * DRM drivers. + */ + u32 format; + }; + + /** + * @depth: + * + * Color depth (number of bits per pixel excluding padding bits), + * valid for a subset of RGB formats only. This is a legacy field, do + * not use in new code and set to 0 for new formats. + */ + u8 depth; + + /** @num_planes: Number of color planes (1 to 3) */ + u8 num_planes; + + union { + /** + * @cpp: + * + * Number of bytes per pixel (per plane), this is aliased with + * @char_per_block. It is deprecated in favour of using the + * triplet @char_per_block, @block_w, @block_h for better + * describing the pixel format. + */ + u8 cpp[3]; + + /** + * @char_per_block: + * + * Number of bytes per block (per plane), where blocks are + * defined as a rectangle of pixels which are stored next to + * each other in a byte aligned memory region. Together with + * @block_w and @block_h this is used to properly describe tiles + * in tiled formats or to describe groups of pixels in packed + * formats for which the memory needed for a single pixel is not + * byte aligned. + * + * @cpp has been kept for historical reasons because there are + * a lot of places in drivers where it's used. In drm core for + * generic code paths the preferred way is to use + * @char_per_block, image_format_block_width() and + * image_format_block_height() which allows handling both + * block and non-block formats in the same way. + * + * For formats that are intended to be used only with non-linear + * modifiers both @cpp and @char_per_block must be 0 in the + * generic format table. Drivers could supply accurate + * information from their drm_mode_config.get_format_info hook + * if they want the core to be validating the pitch. + */ + u8 char_per_block[3]; + }; + + /** + * @block_w: + * + * Block width in pixels, this is intended to be accessed through + * image_format_block_width() + */ + u8 block_w[3]; + + /** + * @block_h: + * + * Block height in pixels, this is intended to be accessed through + * image_format_block_height() + */ + u8 block_h[3]; + + /** @hsub: Horizontal chroma subsampling factor */ + u8 hsub; + /** @vsub: Vertical chroma subsampling factor */ + u8 vsub; + + /** @has_alpha: Does the format embeds an alpha component? */ + bool has_alpha; + + /** @is_yuv: Is it a YUV format? */ + bool is_yuv; +}; + +/** + * image_format_info_is_yuv_packed - check that the format info matches a YUV + * format with data laid in a single plane + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a packed YUV format. + */ +static inline bool +image_format_info_is_yuv_packed(const struct image_format_info *info) +{ + return info->is_yuv && info->num_planes == 1; +} + +/** + * image_format_info_is_yuv_semiplanar - check that the format info matches a YUV + * format with data laid in two planes (luminance and chrominance) + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a semiplanar YUV format. + */ +static inline bool +image_format_info_is_yuv_semiplanar(const struct image_format_info *info) +{ + return info->is_yuv && info->num_planes == 2; +} + +/** + * image_format_info_is_yuv_planar - check that the format info matches a YUV + * format with data laid in three planes (one for each YUV component) + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a planar YUV format. + */ +static inline bool +image_format_info_is_yuv_planar(const struct image_format_info *info) +{ + return info->is_yuv && info->num_planes == 3; +} + +/** + * image_format_info_is_yuv_sampling_410 - check that the format info matches a + * YUV format with 4:1:0 sub-sampling + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a YUV format with 4:1:0 + * sub-sampling. + */ +static inline bool +image_format_info_is_yuv_sampling_410(const struct image_format_info *info) +{ + return info->is_yuv && info->hsub == 4 && info->vsub == 4; +} + +/** + * image_format_info_is_yuv_sampling_411 - check that the format info matches a + * YUV format with 4:1:1 sub-sampling + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a YUV format with 4:1:1 + * sub-sampling. + */ +static inline bool +image_format_info_is_yuv_sampling_411(const struct image_format_info *info) +{ + return info->is_yuv && info->hsub == 4 && info->vsub == 1; +} + +/** + * image_format_info_is_yuv_sampling_420 - check that the format info matches a + * YUV format with 4:2:0 sub-sampling + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a YUV format with 4:2:0 + * sub-sampling. + */ +static inline bool +image_format_info_is_yuv_sampling_420(const struct image_format_info *info) +{ + return info->is_yuv && info->hsub == 2 && info->vsub == 2; +} + +/** + * image_format_info_is_yuv_sampling_422 - check that the format info matches a + * YUV format with 4:2:2 sub-sampling + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a YUV format with 4:2:2 + * sub-sampling. + */ +static inline bool +image_format_info_is_yuv_sampling_422(const struct image_format_info *info) +{ + return info->is_yuv && info->hsub == 2 && info->vsub == 1; +} + +/** + * image_format_info_is_yuv_sampling_444 - check that the format info matches a + * YUV format with 4:4:4 sub-sampling + * @info: format info + * + * Returns: + * A boolean indicating whether the format info matches a YUV format with 4:4:4 + * sub-sampling. + */ +static inline bool +image_format_info_is_yuv_sampling_444(const struct image_format_info *info) +{ + return info->is_yuv && info->hsub == 1 && info->vsub == 1; +} + +const struct image_format_info *__image_format_drm_lookup(u32 drm); +const struct image_format_info *image_format_drm_lookup(u32 drm); +unsigned int image_format_plane_cpp(const struct image_format_info *format, + int plane); +unsigned int image_format_plane_width(int width, + const struct image_format_info *format, + int plane); +unsigned int image_format_plane_height(int height, + const struct image_format_info *format, + int plane); +unsigned int image_format_block_width(const struct image_format_info *format, + int plane); +unsigned int image_format_block_height(const struct image_format_info *format, + int plane); +uint64_t image_format_min_pitch(const struct image_format_info *info, + int plane, unsigned int buffer_width); + +#endif /* _IMAGE_FORMATS_H_ */ diff --git a/lib/Kconfig b/lib/Kconfig index a9e56539bd11..421acac83b13 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -635,3 +635,10 @@ config GENERIC_LIB_UCMPDI2 config OBJAGG tristate "objagg" if COMPILE_TEST + +config IMAGE_FORMATS + bool + +config IMAGE_FORMATS_SELFTESTS + tristate "Test image format functions" + depends on IMAGE_FORMATS diff --git a/lib/Makefile b/lib/Makefile index e1b59da71418..b1916e6d30da 100644 --- a/lib/Makefile +++ b/lib/Makefile @@ -276,3 +276,6 @@ obj-$(CONFIG_GENERIC_LIB_MULDI3) += muldi3.o obj-$(CONFIG_GENERIC_LIB_CMPDI2) += cmpdi2.o obj-$(CONFIG_GENERIC_LIB_UCMPDI2) += ucmpdi2.o obj-$(CONFIG_OBJAGG) += objagg.o + +obj-$(CONFIG_IMAGE_FORMATS) += image-formats.o +obj-$(CONFIG_IMAGE_FORMATS_SELFTESTS) += image-formats-selftests.o diff --git a/lib/image-formats-selftests.c b/lib/image-formats-selftests.c new file mode 100644 index 000000000000..8fdc50b15dcc --- /dev/null +++ b/lib/image-formats-selftests.c @@ -0,0 +1,326 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Test cases for the image_format functions + */ + +#define pr_fmt(fmt) "image_format: " fmt + +#include +#include +#include +#include + +#include + +#define FAIL(test, msg, ...) \ + do { \ + if (test) { \ + pr_err("%s/%u: " msg, __FUNCTION__, __LINE__, ##__VA_ARGS__); \ + return -EINVAL; \ + } \ + } while (0) + +#define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n") + +static int test_image_format_block_width(void) +{ + const struct image_format_info *info = NULL; + + /* Test invalid arguments */ + FAIL_ON(image_format_block_width(info, 0) != 0); + FAIL_ON(image_format_block_width(info, -1) != 0); + FAIL_ON(image_format_block_width(info, 1) != 0); + + /* Test 1 plane format */ + info = image_format_drm_lookup(DRM_FORMAT_XRGB4444); + FAIL_ON(!info); + FAIL_ON(image_format_block_width(info, 0) != 1); + FAIL_ON(image_format_block_width(info, 1) != 0); + FAIL_ON(image_format_block_width(info, -1) != 0); + + /* Test 2 planes format */ + info = image_format_drm_lookup(DRM_FORMAT_NV12); + FAIL_ON(!info); + FAIL_ON(image_format_block_width(info, 0) != 1); + FAIL_ON(image_format_block_width(info, 1) != 1); + FAIL_ON(image_format_block_width(info, 2) != 0); + FAIL_ON(image_format_block_width(info, -1) != 0); + + /* Test 3 planes format */ + info = image_format_drm_lookup(DRM_FORMAT_YUV422); + FAIL_ON(!info); + FAIL_ON(image_format_block_width(info, 0) != 1); + FAIL_ON(image_format_block_width(info, 1) != 1); + FAIL_ON(image_format_block_width(info, 2) != 1); + FAIL_ON(image_format_block_width(info, 3) != 0); + FAIL_ON(image_format_block_width(info, -1) != 0); + + /* Test a tiled format */ + info = image_format_drm_lookup(DRM_FORMAT_X0L0); + FAIL_ON(!info); + FAIL_ON(image_format_block_width(info, 0) != 2); + FAIL_ON(image_format_block_width(info, 1) != 0); + FAIL_ON(image_format_block_width(info, -1) != 0); + + return 0; +} + +static int test_image_format_block_height(void) +{ + const struct image_format_info *info = NULL; + + /* Test invalid arguments */ + FAIL_ON(image_format_block_height(info, 0) != 0); + FAIL_ON(image_format_block_height(info, -1) != 0); + FAIL_ON(image_format_block_height(info, 1) != 0); + + /* Test 1 plane format */ + info = image_format_drm_lookup(DRM_FORMAT_XRGB4444); + FAIL_ON(!info); + FAIL_ON(image_format_block_height(info, 0) != 1); + FAIL_ON(image_format_block_height(info, 1) != 0); + FAIL_ON(image_format_block_height(info, -1) != 0); + + /* Test 2 planes format */ + info = image_format_drm_lookup(DRM_FORMAT_NV12); + FAIL_ON(!info); + FAIL_ON(image_format_block_height(info, 0) != 1); + FAIL_ON(image_format_block_height(info, 1) != 1); + FAIL_ON(image_format_block_height(info, 2) != 0); + FAIL_ON(image_format_block_height(info, -1) != 0); + + /* Test 3 planes format */ + info = image_format_drm_lookup(DRM_FORMAT_YUV422); + FAIL_ON(!info); + FAIL_ON(image_format_block_height(info, 0) != 1); + FAIL_ON(image_format_block_height(info, 1) != 1); + FAIL_ON(image_format_block_height(info, 2) != 1); + FAIL_ON(image_format_block_height(info, 3) != 0); + FAIL_ON(image_format_block_height(info, -1) != 0); + + /* Test a tiled format */ + info = image_format_drm_lookup(DRM_FORMAT_X0L0); + FAIL_ON(!info); + FAIL_ON(image_format_block_height(info, 0) != 2); + FAIL_ON(image_format_block_height(info, 1) != 0); + FAIL_ON(image_format_block_height(info, -1) != 0); + + return 0; +} + +static int test_image_format_min_pitch(void) +{ + const struct image_format_info *info = NULL; + + /* Test invalid arguments */ + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + + /* Test 1 plane 8 bits per pixel format */ + info = image_format_drm_lookup(DRM_FORMAT_RGB332); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 1); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 2); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 640); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 1024); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 1920); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 4096); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 671); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX); + FAIL_ON(image_format_min_pitch(info, 0, (UINT_MAX - 1)) != + (uint64_t)(UINT_MAX - 1)); + + /* Test 1 plane 16 bits per pixel format */ + info = image_format_drm_lookup(DRM_FORMAT_XRGB4444); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 2); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 4); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 1280); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 2048); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 3840); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 8192); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 1342); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX * 2); + FAIL_ON(image_format_min_pitch(info, 0, (UINT_MAX - 1)) != + (uint64_t)(UINT_MAX - 1) * 2); + + /* Test 1 plane 24 bits per pixel format */ + info = image_format_drm_lookup(DRM_FORMAT_RGB888); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 3); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 6); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 1920); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 3072); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 5760); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 12288); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 2013); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX * 3); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX - 1) != + (uint64_t)(UINT_MAX - 1) * 3); + + /* Test 1 plane 32 bits per pixel format */ + info = image_format_drm_lookup(DRM_FORMAT_ABGR8888); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 4); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 8); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 2560); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 4096); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 7680); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 16384); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 2684); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX * 4); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX - 1) != + (uint64_t)(UINT_MAX - 1) * 4); + + /* Test 2 planes format */ + info = image_format_drm_lookup(DRM_FORMAT_NV12); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 2, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 1); + FAIL_ON(image_format_min_pitch(info, 1, 1) != 2); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 2); + FAIL_ON(image_format_min_pitch(info, 1, 1) != 2); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 640); + FAIL_ON(image_format_min_pitch(info, 1, 320) != 640); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 1024); + FAIL_ON(image_format_min_pitch(info, 1, 512) != 1024); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 1920); + FAIL_ON(image_format_min_pitch(info, 1, 960) != 1920); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 4096); + FAIL_ON(image_format_min_pitch(info, 1, 2048) != 4096); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 671); + FAIL_ON(image_format_min_pitch(info, 1, 336) != 672); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX); + FAIL_ON(image_format_min_pitch(info, 1, UINT_MAX / 2 + 1) != + (uint64_t)UINT_MAX + 1); + FAIL_ON(image_format_min_pitch(info, 0, (UINT_MAX - 1)) != + (uint64_t)(UINT_MAX - 1)); + FAIL_ON(image_format_min_pitch(info, 1, (UINT_MAX - 1) / 2) != + (uint64_t)(UINT_MAX - 1)); + + /* Test 3 planes 8 bits per pixel format */ + info = image_format_drm_lookup(DRM_FORMAT_YUV422); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 2, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 3, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 1); + FAIL_ON(image_format_min_pitch(info, 1, 1) != 1); + FAIL_ON(image_format_min_pitch(info, 2, 1) != 1); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 2); + FAIL_ON(image_format_min_pitch(info, 1, 2) != 2); + FAIL_ON(image_format_min_pitch(info, 2, 2) != 2); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 640); + FAIL_ON(image_format_min_pitch(info, 1, 320) != 320); + FAIL_ON(image_format_min_pitch(info, 2, 320) != 320); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 1024); + FAIL_ON(image_format_min_pitch(info, 1, 512) != 512); + FAIL_ON(image_format_min_pitch(info, 2, 512) != 512); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 1920); + FAIL_ON(image_format_min_pitch(info, 1, 960) != 960); + FAIL_ON(image_format_min_pitch(info, 2, 960) != 960); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 4096); + FAIL_ON(image_format_min_pitch(info, 1, 2048) != 2048); + FAIL_ON(image_format_min_pitch(info, 2, 2048) != 2048); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 671); + FAIL_ON(image_format_min_pitch(info, 1, 336) != 336); + FAIL_ON(image_format_min_pitch(info, 2, 336) != 336); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX); + FAIL_ON(image_format_min_pitch(info, 1, UINT_MAX / 2 + 1) != + (uint64_t)UINT_MAX / 2 + 1); + FAIL_ON(image_format_min_pitch(info, 2, UINT_MAX / 2 + 1) != + (uint64_t)UINT_MAX / 2 + 1); + FAIL_ON(image_format_min_pitch(info, 0, (UINT_MAX - 1) / 2) != + (uint64_t)(UINT_MAX - 1) / 2); + FAIL_ON(image_format_min_pitch(info, 1, (UINT_MAX - 1) / 2) != + (uint64_t)(UINT_MAX - 1) / 2); + FAIL_ON(image_format_min_pitch(info, 2, (UINT_MAX - 1) / 2) != + (uint64_t)(UINT_MAX - 1) / 2); + + /* Test tiled format */ + info = image_format_drm_lookup(DRM_FORMAT_X0L2); + FAIL_ON(!info); + FAIL_ON(image_format_min_pitch(info, 0, 0) != 0); + FAIL_ON(image_format_min_pitch(info, -1, 0) != 0); + FAIL_ON(image_format_min_pitch(info, 1, 0) != 0); + + FAIL_ON(image_format_min_pitch(info, 0, 1) != 2); + FAIL_ON(image_format_min_pitch(info, 0, 2) != 4); + FAIL_ON(image_format_min_pitch(info, 0, 640) != 1280); + FAIL_ON(image_format_min_pitch(info, 0, 1024) != 2048); + FAIL_ON(image_format_min_pitch(info, 0, 1920) != 3840); + FAIL_ON(image_format_min_pitch(info, 0, 4096) != 8192); + FAIL_ON(image_format_min_pitch(info, 0, 671) != 1342); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX) != + (uint64_t)UINT_MAX * 2); + FAIL_ON(image_format_min_pitch(info, 0, UINT_MAX - 1) != + (uint64_t)(UINT_MAX - 1) * 2); + + return 0; +} + +#define selftest(test) { .name = #test, .func = test, } + +static struct image_format_test { + char *name; + int (*func)(void); +} tests[] = { + selftest(test_image_format_block_height), + selftest(test_image_format_block_width), + selftest(test_image_format_min_pitch), +}; + +static int __init image_format_test_init(void) +{ + unsigned int i; + + for (i = 0; i < ARRAY_SIZE(tests); i++) { + struct image_format_test *test = &tests[i]; + int ret; + + ret = test->func(); + if (ret) { + pr_err("Failed test %s\n", test->name); + return ret; + } + } + + pr_info("All tests executed properly.\n"); + return 0; +} + +static void __exit image_format_test_exit(void) +{ +} +module_init(image_format_test_init); +module_exit(image_format_test_exit); diff --git a/lib/image-formats.c b/lib/image-formats.c new file mode 100644 index 000000000000..9b9a73220c5d --- /dev/null +++ b/lib/image-formats.c @@ -0,0 +1,760 @@ +#include +#include +#include +#include + +#include + +static const struct image_format_info formats[] = { + { + .drm_fmt = DRM_FORMAT_C8, + .depth = 8, + .num_planes = 1, + .cpp = { 1, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGB332, + .depth = 8, + .num_planes = 1, + .cpp = { 1, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGR233, + .depth = 8, + .num_planes = 1, + .cpp = { 1, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_XRGB4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_XBGR4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGBX4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGRX4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_ARGB4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_ABGR4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGBA4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGRA4444, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_XRGB1555, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_XBGR1555, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGBX5551, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGRX5551, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_ARGB1555, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_ABGR1555, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGBA5551, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGRA5551, + .depth = 15, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGB565, + .depth = 16, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGR565, + .depth = 16, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGB888, + .depth = 24, + .num_planes = 1, + .cpp = { 3, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGR888, + .depth = 24, + .num_planes = 1, + .cpp = { 3, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_XRGB8888, + .depth = 24, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_XBGR8888, + .depth = 24, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGBX8888, + .depth = 24, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGRX8888, + .depth = 24, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGB565_A8, + .depth = 24, + .num_planes = 2, + .cpp = { 2, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGR565_A8, + .depth = 24, + .num_planes = 2, + .cpp = { 2, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_XRGB2101010, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_XBGR2101010, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_RGBX1010102, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_BGRX1010102, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + }, { + .drm_fmt = DRM_FORMAT_ARGB2101010, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_ABGR2101010, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGBA1010102, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGRA1010102, + .depth = 30, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_ARGB8888, + .depth = 32, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_ABGR8888, + .depth = 32, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGBA8888, + .depth = 32, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGRA8888, + .depth = 32, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGB888_A8, + .depth = 32, + .num_planes = 2, + .cpp = { 3, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGR888_A8, + .depth = 32, + .num_planes = 2, + .cpp = { 3, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_XRGB8888_A8, + .depth = 32, + .num_planes = 2, + .cpp = { 4, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_XBGR8888_A8, + .depth = 32, + .num_planes = 2, + .cpp = { 4, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_RGBX8888_A8, + .depth = 32, + .num_planes = 2, + .cpp = { 4, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_BGRX8888_A8, + .depth = 32, + .num_planes = 2, + .cpp = { 4, 1, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + }, { + .drm_fmt = DRM_FORMAT_YUV410, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 4, + .vsub = 4, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YVU410, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 4, + .vsub = 4, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YUV411, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 4, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YVU411, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 4, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YUV420, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 2, + .vsub = 2, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YVU420, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 2, + .vsub = 2, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YUV422, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YVU422, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YUV444, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 1, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YVU444, + .depth = 0, + .num_planes = 3, + .cpp = { 1, 1, 1 }, + .hsub = 1, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_NV12, + .depth = 0, + .num_planes = 2, + .cpp = { 1, 2, 0 }, + .hsub = 2, + .vsub = 2, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_NV21, + .depth = 0, + .num_planes = 2, + .cpp = { 1, 2, 0 }, + .hsub = 2, + .vsub = 2, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_NV16, + .depth = 0, + .num_planes = 2, + .cpp = { 1, 2, 0 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_NV61, + .depth = 0, + .num_planes = 2, + .cpp = { 1, 2, 0 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_NV24, + .depth = 0, + .num_planes = 2, + .cpp = { 1, 2, 0 }, + .hsub = 1, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_NV42, + .depth = 0, + .num_planes = 2, + .cpp = { 1, 2, 0 }, + .hsub = 1, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YUYV, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_YVYU, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_UYVY, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_VYUY, + .depth = 0, + .num_planes = 1, + .cpp = { 2, 0, 0 }, + .hsub = 2, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_XYUV8888, + .depth = 0, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_AYUV, + .depth = 0, + .num_planes = 1, + .cpp = { 4, 0, 0 }, + .hsub = 1, + .vsub = 1, + .has_alpha = true, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_Y0L0, + .depth = 0, + .num_planes = 1, + .char_per_block = { 8, 0, 0 }, + .block_w = { 2, 0, 0 }, + .block_h = { 2, 0, 0 }, + .hsub = 2, + .vsub = 2, + .has_alpha = true, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_X0L0, + .depth = 0, + .num_planes = 1, + .char_per_block = { 8, 0, 0 }, + .block_w = { 2, 0, 0 }, + .block_h = { 2, 0, 0 }, + .hsub = 2, + .vsub = 2, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_Y0L2, + .depth = 0, + .num_planes = 1, + .char_per_block = { 8, 0, 0 }, + .block_w = { 2, 0, 0 }, + .block_h = { 2, 0, 0 }, + .hsub = 2, + .vsub = 2, + .has_alpha = true, + .is_yuv = true, + }, { + .drm_fmt = DRM_FORMAT_X0L2, + .depth = 0, + .num_planes = 1, + .char_per_block = { 8, 0, 0 }, + .block_w = { 2, 0, 0 }, + .block_h = { 2, 0, 0 }, + .hsub = 2, + .vsub = 2, + .is_yuv = true, + }, +}; + +#define __image_format_lookup(_field, _fmt) \ + ({ \ + const struct image_format_info *format = NULL; \ + unsigned i; \ + \ + for (i = 0; i < ARRAY_SIZE(formats); i++) \ + if (formats[i]._field == _fmt) \ + format = &formats[i]; \ + \ + format; \ + }) + +/** + * __image_format_drm_lookup - query information for a given format + * @drm: DRM fourcc pixel format (DRM_FORMAT_*) + * + * The caller should only pass a supported pixel format to this function. + * + * Returns: + * The instance of struct image_format_info that describes the pixel format, or + * NULL if the format is unsupported. + */ +const struct image_format_info *__image_format_drm_lookup(u32 drm) +{ + return __image_format_lookup(drm_fmt, drm); +} +EXPORT_SYMBOL(__image_format_drm_lookup); + +/** + * image_format_drm_lookup - query information for a given format + * @drm: DRM fourcc pixel format (DRM_FORMAT_*) + * + * The caller should only pass a supported pixel format to this function. + * Unsupported pixel formats will generate a warning in the kernel log. + * + * Returns: + * The instance of struct image_format_info that describes the pixel format, or + * NULL if the format is unsupported. + */ +const struct image_format_info *image_format_drm_lookup(u32 drm) +{ + const struct image_format_info *format; + + format = __image_format_drm_lookup(drm); + + WARN_ON(!format); + return format; +} +EXPORT_SYMBOL(image_format_drm_lookup); + +/** + * image_format_plane_cpp - determine the bytes per pixel value + * @format: pointer to the image_format + * @plane: plane index + * + * Returns: + * The bytes per pixel value for the specified plane. + */ +unsigned int image_format_plane_cpp(const struct image_format_info *format, + int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + return format->cpp[plane]; +} +EXPORT_SYMBOL(image_format_plane_cpp); + +/** + * image_format_plane_width - width of the plane given the first plane + * @format: pointer to the image_format + * @width: width of the first plane + * @plane: plane index + * + * Returns: + * The width of @plane, given that the width of the first plane is @width. + */ +unsigned int image_format_plane_width(int width, + const struct image_format_info *format, + int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + if (plane == 0) + return width; + + return width / format->hsub; +} +EXPORT_SYMBOL(image_format_plane_width); + +/** + * image_format_plane_height - height of the plane given the first plane + * @format: pointer to the image_format + * @height: height of the first plane + * @plane: plane index + * + * Returns: + * The height of @plane, given that the height of the first plane is @height. + */ +unsigned int image_format_plane_height(int height, + const struct image_format_info *format, + int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + if (plane == 0) + return height; + + return height / format->vsub; +} +EXPORT_SYMBOL(image_format_plane_height); + +/** + * image_format_block_width - width in pixels of block. + * @format: pointer to the image_format + * @plane: plane index + * + * Returns: + * The width in pixels of a block, depending on the plane index. + */ +unsigned int image_format_block_width(const struct image_format_info *format, + int plane) +{ + if (!format || plane < 0 || plane >= format->num_planes) + return 0; + + if (!format->block_w[plane]) + return 1; + + return format->block_w[plane]; +} +EXPORT_SYMBOL(image_format_block_width); + +/** + * image_format_block_height - height in pixels of a block + * @info: pointer to the image_format + * @plane: plane index + * + * Returns: + * The height in pixels of a block, depending on the plane index. + */ +unsigned int image_format_block_height(const struct image_format_info *format, + int plane) +{ + if (!format || plane < 0 || plane >= format->num_planes) + return 0; + + if (!format->block_h[plane]) + return 1; + + return format->block_h[plane]; +} +EXPORT_SYMBOL(image_format_block_height); + +/** + * image_format_min_pitch - computes the minimum required pitch in bytes + * @info: pixel format info + * @plane: plane index + * @buffer_width: buffer width in pixels + * + * Returns: + * The minimum required pitch in bytes for a buffer by taking into consideration + * the pixel format information and the buffer width. + */ +uint64_t image_format_min_pitch(const struct image_format_info *info, + int plane, unsigned int buffer_width) +{ + if (!info || plane < 0 || plane >= info->num_planes) + return 0; + + return DIV_ROUND_UP_ULL((u64)buffer_width * info->char_per_block[plane], + image_format_block_width(info, plane) * + image_format_block_height(info, plane)); +} +EXPORT_SYMBOL(image_format_min_pitch); From patchwork Tue Mar 19 21:57:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860463 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6E94A13B5 for ; Tue, 19 Mar 2019 21:58:17 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 517E32956D for ; Tue, 19 Mar 2019 21:58:17 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4FAAE29920; Tue, 19 Mar 2019 21:58:17 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EBCDA2956D for ; Tue, 19 Mar 2019 21:58:14 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id DED0389C18; Tue, 19 Mar 2019 21:58:13 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by gabe.freedesktop.org (Postfix) with ESMTPS id ACA3E89C07 for ; Tue, 19 Mar 2019 21:58:08 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 8C5201BF208; Tue, 19 Mar 2019 21:58:05 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 07/20] drm/fb: Move from drm_format_info to image_format_info Date: Tue, 19 Mar 2019 22:57:12 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Start converting the DRM drivers by changing the struct drm_framebuffer structure to hold a pointer to image_format_info instead, and converting everyone that depends on it. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/Kconfig | 1 +- drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c | 4 ++-- drivers/gpu/drm/arm/malidp_drv.c | 2 +- drivers/gpu/drm/arm/malidp_planes.c | 8 ++++---- drivers/gpu/drm/armada/armada_fb.c | 2 +- drivers/gpu/drm/armada/armada_overlay.c | 3 ++- drivers/gpu/drm/armada/armada_plane.c | 3 ++- drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c | 4 +++- drivers/gpu/drm/bochs/bochs.h | 4 +++- drivers/gpu/drm/bochs/bochs_hw.c | 3 ++- drivers/gpu/drm/cirrus/cirrus_fbdev.c | 4 ++-- drivers/gpu/drm/cirrus/cirrus_main.c | 4 ++-- drivers/gpu/drm/drm_atomic.c | 1 +- drivers/gpu/drm/drm_client.c | 1 +- drivers/gpu/drm/drm_crtc.c | 1 +- drivers/gpu/drm/drm_fb_cma_helper.c | 5 +++-- drivers/gpu/drm/drm_fb_helper.c | 15 +++++++------- drivers/gpu/drm/drm_fourcc.c | 8 ++++---- drivers/gpu/drm/drm_framebuffer.c | 11 +++++----- drivers/gpu/drm/drm_gem_framebuffer_helper.c | 5 +++-- drivers/gpu/drm/drm_plane.c | 1 +- drivers/gpu/drm/exynos/exynos_drm_fb.c | 3 ++- drivers/gpu/drm/gma500/framebuffer.c | 2 +- drivers/gpu/drm/i915/i915_drv.h | 6 ++++-- drivers/gpu/drm/i915/intel_display.c | 11 +++++----- drivers/gpu/drm/imx/ipuv3-plane.c | 5 +++-- drivers/gpu/drm/mediatek/mtk_drm_fb.c | 4 ++-- drivers/gpu/drm/meson/meson_overlay.c | 12 +++++------ drivers/gpu/drm/msm/msm_fb.c | 8 ++++---- drivers/gpu/drm/omapdrm/omap_fb.c | 6 +++--- drivers/gpu/drm/radeon/radeon_fb.c | 4 ++-- drivers/gpu/drm/rockchip/rockchip_drm_fb.c | 4 ++-- drivers/gpu/drm/stm/ltdc.c | 2 +- drivers/gpu/drm/sun4i/sun4i_backend.c | 7 ++++--- drivers/gpu/drm/sun4i/sun4i_frontend.c | 19 +++++++++--------- drivers/gpu/drm/sun4i/sun8i_ui_layer.c | 2 ++- drivers/gpu/drm/sun4i/sun8i_vi_layer.c | 6 ++++-- drivers/gpu/drm/sun4i/sun8i_vi_scaler.c | 6 ++++-- drivers/gpu/drm/sun4i/sun8i_vi_scaler.h | 5 +++-- drivers/gpu/drm/tegra/fb.c | 2 +- drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c | 2 +- drivers/gpu/drm/zte/zx_plane.c | 2 +- include/drm/drm_fourcc.h | 4 +++- include/drm/drm_framebuffer.h | 3 ++- include/drm/drm_mode_config.h | 4 ++-- 45 files changed, 126 insertions(+), 93 deletions(-) diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index bd943a71756c..7992a95ea965 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -12,6 +12,7 @@ menuconfig DRM select FB_CMDLINE select I2C select I2C_ALGOBIT + select IMAGE_FORMATS select DMA_SHARED_BUFFER select SYNC_FILE help diff --git a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c index 48170a843b48..2d2e091da19b 100644 --- a/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c +++ b/drivers/gpu/drm/amd/amdgpu/amdgpu_fb.c @@ -123,8 +123,8 @@ static int amdgpufb_create_pinned_object(struct amdgpu_fbdev *rfbdev, struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **gobj_p) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct amdgpu_device *adev = rfbdev->adev; struct drm_gem_object *gobj = NULL; struct amdgpu_bo *abo = NULL; diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index ab50ad06e271..fec4fe15a71b 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -264,7 +264,7 @@ static bool malidp_verify_afbc_framebuffer_caps(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info; + const struct image_format_info *info; if ((mode_cmd->modifier[0] >> 56) != DRM_FORMAT_MOD_VENDOR_ARM) { DRM_DEBUG_KMS("Unknown modifier (not Arm)\n"); diff --git a/drivers/gpu/drm/arm/malidp_planes.c b/drivers/gpu/drm/arm/malidp_planes.c index c9a6d3e0cada..6d2dad4642be 100644 --- a/drivers/gpu/drm/arm/malidp_planes.c +++ b/drivers/gpu/drm/arm/malidp_planes.c @@ -415,7 +415,7 @@ static int malidp_de_plane_check(struct drm_plane *plane, for (i = 0; i < ms->n_planes; i++) { u8 alignment = malidp_hw_get_pitch_align(mp->hwdev, rotated); - if ((fb->pitches[i] * drm_format_info_block_height(fb->format, i)) + if ((fb->pitches[i] * image_format_block_height(fb->format, i)) & (alignment - 1)) { DRM_DEBUG_KMS("Invalid pitch %u for plane %d\n", fb->pitches[i], i); @@ -423,8 +423,8 @@ static int malidp_de_plane_check(struct drm_plane *plane, } } - block_w = drm_format_info_block_width(fb->format, 0); - block_h = drm_format_info_block_height(fb->format, 0); + block_w = image_format_block_width(fb->format, 0); + block_h = image_format_block_height(fb->format, 0); if (fb->width % block_w || fb->height % block_h) { DRM_DEBUG_KMS("Buffer width/height needs to be a multiple of tile sizes"); return -EINVAL; @@ -512,7 +512,7 @@ static void malidp_de_set_plane_pitches(struct malidp_plane *mp, * in a tile. */ for (i = 0; i < num_strides; ++i) { - unsigned int block_h = drm_format_info_block_height(mp->base.state->fb->format, i); + unsigned int block_h = image_format_block_height(mp->base.state->fb->format, i); malidp_hw_write(mp->hwdev, pitches[i] * block_h, mp->layer->base + diff --git a/drivers/gpu/drm/armada/armada_fb.c b/drivers/gpu/drm/armada/armada_fb.c index a2f6472eb482..10e9ab534658 100644 --- a/drivers/gpu/drm/armada/armada_fb.c +++ b/drivers/gpu/drm/armada/armada_fb.c @@ -87,7 +87,7 @@ struct armada_framebuffer *armada_framebuffer_create(struct drm_device *dev, struct drm_framebuffer *armada_fb_create(struct drm_device *dev, struct drm_file *dfile, const struct drm_mode_fb_cmd2 *mode) { - const struct drm_format_info *info = drm_get_format_info(dev, mode); + const struct image_format_info *info = drm_get_format_info(dev, mode); struct armada_gem_object *obj; struct armada_framebuffer *dfb; int ret; diff --git a/drivers/gpu/drm/armada/armada_overlay.c b/drivers/gpu/drm/armada/armada_overlay.c index 8d770641fcc4..8574fa02879d 100644 --- a/drivers/gpu/drm/armada/armada_overlay.c +++ b/drivers/gpu/drm/armada/armada_overlay.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "armada_crtc.h" #include "armada_drm.h" #include "armada_fb.h" @@ -107,7 +108,7 @@ static void armada_drm_overlay_plane_atomic_update(struct drm_plane *plane, if (old_state->src.x1 != state->src.x1 || old_state->src.y1 != state->src.y1 || old_state->fb != state->fb) { - const struct drm_format_info *format; + const struct image_format_info *format; u16 src_x, pitches[3]; u32 addrs[2][3]; diff --git a/drivers/gpu/drm/armada/armada_plane.c b/drivers/gpu/drm/armada/armada_plane.c index 9f36423dd394..91cf01317098 100644 --- a/drivers/gpu/drm/armada/armada_plane.c +++ b/drivers/gpu/drm/armada/armada_plane.c @@ -10,6 +10,7 @@ #include #include #include +#include #include "armada_crtc.h" #include "armada_drm.h" #include "armada_fb.h" @@ -39,7 +40,7 @@ void armada_drm_plane_calc(struct drm_plane_state *state, u32 addrs[2][3], u16 pitches[3], bool interlaced) { struct drm_framebuffer *fb = state->fb; - const struct drm_format_info *format = fb->format; + const struct image_format_info *format = fb->format; unsigned int num_planes = format->num_planes; unsigned int x = state->src.x1 >> 16; unsigned int y = state->src.y1 >> 16; diff --git a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c index fdd607ad27fe..550a47c09408 100644 --- a/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c +++ b/drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_plane.c @@ -17,6 +17,8 @@ * this program. If not, see . */ +#include + #include "atmel_hlcdc_dc.h" /** @@ -360,7 +362,7 @@ atmel_hlcdc_plane_update_general_settings(struct atmel_hlcdc_plane *plane, { unsigned int cfg = ATMEL_HLCDC_LAYER_DMA_BLEN_INCR16 | state->ahb_id; const struct atmel_hlcdc_layer_desc *desc = plane->layer.desc; - const struct drm_format_info *format = state->base.fb->format; + const struct image_format_info *format = state->base.fb->format; /* * Rotation optimization is not working on RGB888 (rotation is still diff --git a/drivers/gpu/drm/bochs/bochs.h b/drivers/gpu/drm/bochs/bochs.h index 03711394f1ed..7dbcf664c0f1 100644 --- a/drivers/gpu/drm/bochs/bochs.h +++ b/drivers/gpu/drm/bochs/bochs.h @@ -110,6 +110,8 @@ static inline u64 bochs_bo_mmap_offset(struct bochs_bo *bo) /* ---------------------------------------------------------------------- */ +struct image_format_info; + /* bochs_hw.c */ int bochs_hw_init(struct drm_device *dev); void bochs_hw_fini(struct drm_device *dev); @@ -117,7 +119,7 @@ void bochs_hw_fini(struct drm_device *dev); void bochs_hw_setmode(struct bochs_device *bochs, struct drm_display_mode *mode); void bochs_hw_setformat(struct bochs_device *bochs, - const struct drm_format_info *format); + const struct image_format_info *format); void bochs_hw_setbase(struct bochs_device *bochs, int x, int y, u64 addr); int bochs_hw_load_edid(struct bochs_device *bochs); diff --git a/drivers/gpu/drm/bochs/bochs_hw.c b/drivers/gpu/drm/bochs/bochs_hw.c index 3e04b2f0ec08..8f6a04b2d373 100644 --- a/drivers/gpu/drm/bochs/bochs_hw.c +++ b/drivers/gpu/drm/bochs/bochs_hw.c @@ -5,6 +5,7 @@ * (at your option) any later version. */ +#include #include "bochs.h" /* ---------------------------------------------------------------------- */ @@ -234,7 +235,7 @@ void bochs_hw_setmode(struct bochs_device *bochs, } void bochs_hw_setformat(struct bochs_device *bochs, - const struct drm_format_info *format) + const struct image_format_info *format) { DRM_DEBUG_DRIVER("format %c%c%c%c\n", (format->format >> 0) & 0xff, diff --git a/drivers/gpu/drm/cirrus/cirrus_fbdev.c b/drivers/gpu/drm/cirrus/cirrus_fbdev.c index 759847bafda8..a0bef1337761 100644 --- a/drivers/gpu/drm/cirrus/cirrus_fbdev.c +++ b/drivers/gpu/drm/cirrus/cirrus_fbdev.c @@ -137,8 +137,8 @@ static int cirrusfb_create_object(struct cirrus_fbdev *afbdev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **gobj_p) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct drm_device *dev = afbdev->helper.dev; struct cirrus_device *cdev = dev->dev_private; u32 bpp; diff --git a/drivers/gpu/drm/cirrus/cirrus_main.c b/drivers/gpu/drm/cirrus/cirrus_main.c index 66d0d2c5211d..8afc6a351ecd 100644 --- a/drivers/gpu/drm/cirrus/cirrus_main.c +++ b/drivers/gpu/drm/cirrus/cirrus_main.c @@ -41,8 +41,8 @@ cirrus_user_framebuffer_create(struct drm_device *dev, struct drm_file *filp, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct cirrus_device *cdev = dev->dev_private; struct drm_gem_object *obj; struct drm_framebuffer *fb; diff --git a/drivers/gpu/drm/drm_atomic.c b/drivers/gpu/drm/drm_atomic.c index 5eb40130fafb..6a0aff2bd7f4 100644 --- a/drivers/gpu/drm/drm_atomic.c +++ b/drivers/gpu/drm/drm_atomic.c @@ -32,6 +32,7 @@ #include #include #include +#include #include #include "drm_crtc_internal.h" diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index 305d6dd5d201..9df52b7fd074 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -3,6 +3,7 @@ * Copyright 2018 Noralf Trønnes */ +#include #include #include #include diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c index 7dabbaf033a1..2a6d811b19df 100644 --- a/drivers/gpu/drm/drm_crtc.c +++ b/drivers/gpu/drm/drm_crtc.c @@ -30,6 +30,7 @@ * Jesse Barnes */ #include +#include #include #include #include diff --git a/drivers/gpu/drm/drm_fb_cma_helper.c b/drivers/gpu/drm/drm_fb_cma_helper.c index 5f8074ffe7d9..f6573a3ee90b 100644 --- a/drivers/gpu/drm/drm_fb_cma_helper.c +++ b/drivers/gpu/drm/drm_fb_cma_helper.c @@ -22,6 +22,7 @@ #include #include #include +#include #include /** @@ -74,8 +75,8 @@ dma_addr_t drm_fb_cma_get_gem_addr(struct drm_framebuffer *fb, struct drm_gem_cma_object *obj; dma_addr_t paddr; u8 h_div = 1, v_div = 1; - u32 block_w = drm_format_info_block_width(fb->format, plane); - u32 block_h = drm_format_info_block_height(fb->format, plane); + u32 block_w = image_format_block_width(fb->format, plane); + u32 block_h = image_format_block_height(fb->format, plane); u32 block_size = fb->format->char_per_block[plane]; u32 sample_x; u32 sample_y; diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c index 257a9c995057..c91200af3fdd 100644 --- a/drivers/gpu/drm/drm_fb_helper.c +++ b/drivers/gpu/drm/drm_fb_helper.c @@ -31,6 +31,7 @@ #include #include +#include #include #include #include @@ -768,7 +769,7 @@ static void drm_fb_helper_dirty_blit_real(struct drm_fb_helper *fb_helper, struct drm_clip_rect *clip) { struct drm_framebuffer *fb = fb_helper->fb; - unsigned int cpp = drm_format_plane_cpp(fb->format, 0); + unsigned int cpp = image_format_plane_cpp(fb->format, 0); size_t offset = clip->y1 * fb->pitches[0] + clip->x1 * cpp; void *src = fb_helper->fbdev->screen_buffer + offset; void *dst = fb_helper->buffer->vaddr + offset; @@ -1698,8 +1699,8 @@ int drm_fb_helper_check_var(struct fb_var_screeninfo *var, var->pixclock = 0; } - if ((drm_format_info_block_width(fb->format, 0) > 1) || - (drm_format_info_block_height(fb->format, 0) > 1)) + if ((image_format_block_width(fb->format, 0) > 1) || + (image_format_block_height(fb->format, 0) > 1)) return -EINVAL; /* @@ -1934,9 +1935,9 @@ static int drm_fb_helper_single_fb_probe(struct drm_fb_helper *fb_helper, DRM_DEBUG("test CRTC %d primary plane\n", i); for (j = 0; j < plane->format_count; j++) { - const struct drm_format_info *fmt; + const struct image_format_info *fmt; - fmt = drm_format_info(plane->format_types[j]); + fmt = image_format_drm_lookup(plane->format_types[j]); /* * Do not consider YUV or other complicated formats @@ -2086,8 +2087,8 @@ void drm_fb_helper_fill_var(struct fb_info *info, struct drm_fb_helper *fb_helpe { struct drm_framebuffer *fb = fb_helper->fb; - WARN_ON((drm_format_info_block_width(fb->format, 0) > 1) || - (drm_format_info_block_height(fb->format, 0) > 1)); + WARN_ON((image_format_block_width(fb->format, 0) > 1) || + (image_format_block_height(fb->format, 0) > 1)); info->pseudo_palette = fb_helper->pseudo_palette; info->var.xres_virtual = fb->width; info->var.yres_virtual = fb->height; diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 57389b9753b2..6ddb1c28be49 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -286,20 +286,20 @@ EXPORT_SYMBOL(drm_format_info); * @mode_cmd: metadata from the userspace fb creation request * * Returns: - * The instance of struct drm_format_info that describes the pixel format, or + * The instance of struct image_format_info that describes the pixel format, or * NULL if the format is unsupported. */ -const struct drm_format_info * +const struct image_format_info * drm_get_format_info(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info = NULL; + const struct image_format_info *info = NULL; if (dev->mode_config.funcs->get_format_info) info = dev->mode_config.funcs->get_format_info(mode_cmd); if (!info) - info = drm_format_info(mode_cmd->pixel_format); + info = image_format_drm_lookup(mode_cmd->pixel_format); return info; } diff --git a/drivers/gpu/drm/drm_framebuffer.c b/drivers/gpu/drm/drm_framebuffer.c index d8d75e25f6fb..90c77a6633be 100644 --- a/drivers/gpu/drm/drm_framebuffer.c +++ b/drivers/gpu/drm/drm_framebuffer.c @@ -21,6 +21,7 @@ */ #include +#include #include #include #include @@ -146,7 +147,7 @@ int drm_mode_addfb_ioctl(struct drm_device *dev, } static int fb_plane_width(int width, - const struct drm_format_info *format, int plane) + const struct image_format_info *format, int plane) { if (plane == 0) return width; @@ -155,7 +156,7 @@ static int fb_plane_width(int width, } static int fb_plane_height(int height, - const struct drm_format_info *format, int plane) + const struct image_format_info *format, int plane) { if (plane == 0) return height; @@ -166,11 +167,11 @@ static int fb_plane_height(int height, static int framebuffer_check(struct drm_device *dev, const struct drm_mode_fb_cmd2 *r) { - const struct drm_format_info *info; + const struct image_format_info *info; int i; /* check if the format is supported at all */ - info = __drm_format_info(r->pixel_format); + info = __image_format_drm_lookup(r->pixel_format); if (!info) { struct drm_format_name_buf format_name; @@ -197,7 +198,7 @@ static int framebuffer_check(struct drm_device *dev, unsigned int width = fb_plane_width(r->width, info, i); unsigned int height = fb_plane_height(r->height, info, i); unsigned int block_size = info->char_per_block[i]; - u64 min_pitch = drm_format_info_min_pitch(info, i, width); + u64 min_pitch = image_format_min_pitch(info, i, width); if (!block_size && (r->modifier[i] == DRM_FORMAT_MOD_LINEAR)) { DRM_DEBUG_KMS("Format requires non-linear modifier for plane %d\n", i); diff --git a/drivers/gpu/drm/drm_gem_framebuffer_helper.c b/drivers/gpu/drm/drm_gem_framebuffer_helper.c index 65edb1ccb185..a2a01afeba3e 100644 --- a/drivers/gpu/drm/drm_gem_framebuffer_helper.c +++ b/drivers/gpu/drm/drm_gem_framebuffer_helper.c @@ -11,6 +11,7 @@ #include #include +#include #include #include @@ -149,7 +150,7 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd, const struct drm_framebuffer_funcs *funcs) { - const struct drm_format_info *info; + const struct image_format_info *info; struct drm_gem_object *objs[4]; struct drm_framebuffer *fb; int ret, i; @@ -171,7 +172,7 @@ drm_gem_fb_create_with_funcs(struct drm_device *dev, struct drm_file *file, } min_size = (height - 1) * mode_cmd->pitches[i] - + drm_format_info_min_pitch(info, i, width) + + image_format_min_pitch(info, i, width) + mode_cmd->offsets[i]; if (objs[i]->size < min_size) { diff --git a/drivers/gpu/drm/drm_plane.c b/drivers/gpu/drm/drm_plane.c index 4cfb56893b7f..b67be56e71cc 100644 --- a/drivers/gpu/drm/drm_plane.c +++ b/drivers/gpu/drm/drm_plane.c @@ -20,6 +20,7 @@ * OF THIS SOFTWARE. */ +#include #include #include diff --git a/drivers/gpu/drm/exynos/exynos_drm_fb.c b/drivers/gpu/drm/exynos/exynos_drm_fb.c index 1f11ab0f8e9d..be41d986e481 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_fb.c +++ b/drivers/gpu/drm/exynos/exynos_drm_fb.c @@ -19,6 +19,7 @@ #include #include #include +#include #include #include "exynos_drm_drv.h" @@ -98,7 +99,7 @@ static struct drm_framebuffer * exynos_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, mode_cmd); struct exynos_drm_gem *exynos_gem[MAX_FB_BUFFER]; struct drm_framebuffer *fb; int i; diff --git a/drivers/gpu/drm/gma500/framebuffer.c b/drivers/gpu/drm/gma500/framebuffer.c index 46f0078f7a91..f160e3c257c1 100644 --- a/drivers/gpu/drm/gma500/framebuffer.c +++ b/drivers/gpu/drm/gma500/framebuffer.c @@ -225,7 +225,7 @@ static int psb_framebuffer_init(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct gtt_range *gt) { - const struct drm_format_info *info; + const struct image_format_info *info; int ret; /* diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h index 9adc7bb9e69c..6a085185e7fc 100644 --- a/drivers/gpu/drm/i915/i915_drv.h +++ b/drivers/gpu/drm/i915/i915_drv.h @@ -379,6 +379,8 @@ enum fb_op_origin { ORIGIN_DIRTYFB, }; +struct image_format_info; + struct intel_fbc { /* This is always the inner lock when overlapping with struct_mutex and * it's the outer lock when overlapping with stolen_lock. */ @@ -435,7 +437,7 @@ struct intel_fbc { } plane; struct { - const struct drm_format_info *format; + const struct image_format_info *format; unsigned int stride; } fb; } state_cache; @@ -458,7 +460,7 @@ struct intel_fbc { } crtc; struct { - const struct drm_format_info *format; + const struct image_format_info *format; unsigned int stride; } fb; diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index ccb616351bba..86febe2ee510 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -25,6 +25,7 @@ */ #include +#include #include #include #include @@ -2443,15 +2444,15 @@ static unsigned int intel_fb_modifier_to_tiling(u64 fb_modifier) * us a ratio of one byte in the CCS for each 8x16 pixels in the * main surface. */ -static const struct drm_format_info ccs_formats[] = { +static const struct image_format_info ccs_formats[] = { { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 2, .cpp = { 4, 1, }, .hsub = 8, .vsub = 16, }, }; -static const struct drm_format_info * -lookup_format_info(const struct drm_format_info formats[], +static const struct image_format_info * +lookup_format_info(const struct image_format_info formats[], int num_formats, u32 format) { int i; @@ -2464,7 +2465,7 @@ lookup_format_info(const struct drm_format_info formats[], return NULL; } -static const struct drm_format_info * +static const struct image_format_info * intel_get_format_info(const struct drm_mode_fb_cmd2 *cmd) { switch (cmd->modifier[0]) { @@ -4982,7 +4983,7 @@ static int skl_update_scaler(struct intel_crtc_state *crtc_state, bool force_detach, unsigned int scaler_user, int *scaler_id, int src_w, int src_h, int dst_w, int dst_h, - const struct drm_format_info *format, bool need_scaler) + const struct image_format_info *format, bool need_scaler) { struct intel_crtc_scaler_state *scaler_state = &crtc_state->scaler_state; diff --git a/drivers/gpu/drm/imx/ipuv3-plane.c b/drivers/gpu/drm/imx/ipuv3-plane.c index 2530143281b2..6bbacba90661 100644 --- a/drivers/gpu/drm/imx/ipuv3-plane.c +++ b/drivers/gpu/drm/imx/ipuv3-plane.c @@ -12,6 +12,7 @@ #include #include #include +#include #include "video/imx-ipu-v3.h" #include "imx-drm.h" @@ -549,7 +550,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane, unsigned long alpha_eba = 0; enum ipu_color_space ics; unsigned int axi_id = 0; - const struct drm_format_info *info; + const struct image_format_info *info; u8 burstsize, num_bursts; u32 width, height; int active; @@ -626,7 +627,7 @@ static void ipu_plane_atomic_update(struct drm_plane *plane, width = drm_rect_width(&state->src) >> 16; height = drm_rect_height(&state->src) >> 16; - info = drm_format_info(fb->format->format); + info = fb->format; ipu_calculate_bursts(width, info->cpp[0], fb->pitches[0], &burstsize, &num_bursts); diff --git a/drivers/gpu/drm/mediatek/mtk_drm_fb.c b/drivers/gpu/drm/mediatek/mtk_drm_fb.c index af90c84e9e02..ee71d96dc0cd 100644 --- a/drivers/gpu/drm/mediatek/mtk_drm_fb.c +++ b/drivers/gpu/drm/mediatek/mtk_drm_fb.c @@ -32,7 +32,7 @@ static struct drm_framebuffer *mtk_drm_framebuffer_init(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode, struct drm_gem_object *obj) { - const struct drm_format_info *info = drm_get_format_info(dev, mode); + const struct image_format_info *info = drm_get_format_info(dev, mode); struct drm_framebuffer *fb; int ret; @@ -89,7 +89,7 @@ struct drm_framebuffer *mtk_drm_mode_fb_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, cmd); + const struct image_format_info *info = drm_get_format_info(dev, cmd); struct drm_framebuffer *fb; struct drm_gem_object *gem; unsigned int width = cmd->width; diff --git a/drivers/gpu/drm/meson/meson_overlay.c b/drivers/gpu/drm/meson/meson_overlay.c index 6987c15b6ab9..b84187da6426 100644 --- a/drivers/gpu/drm/meson/meson_overlay.c +++ b/drivers/gpu/drm/meson/meson_overlay.c @@ -474,8 +474,8 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, priv->viu.vd1_addr2 = gem->paddr + fb->offsets[2]; priv->viu.vd1_stride2 = fb->pitches[2]; priv->viu.vd1_height2 = - drm_format_plane_height(fb->height, - fb->format, 2); + image_format_plane_height(fb->height, + fb->format, 2); DRM_DEBUG("plane 2 addr 0x%x stride %d height %d\n", priv->viu.vd1_addr2, priv->viu.vd1_stride2, @@ -486,8 +486,8 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, priv->viu.vd1_addr1 = gem->paddr + fb->offsets[1]; priv->viu.vd1_stride1 = fb->pitches[1]; priv->viu.vd1_height1 = - drm_format_plane_height(fb->height, - fb->format, 1); + image_format_plane_height(fb->height, + fb->format, 1); DRM_DEBUG("plane 1 addr 0x%x stride %d height %d\n", priv->viu.vd1_addr1, priv->viu.vd1_stride1, @@ -498,8 +498,8 @@ static void meson_overlay_atomic_update(struct drm_plane *plane, priv->viu.vd1_addr0 = gem->paddr + fb->offsets[0]; priv->viu.vd1_stride0 = fb->pitches[0]; priv->viu.vd1_height0 = - drm_format_plane_height(fb->height, - fb->format, 0); + image_format_plane_height(fb->height, + fb->format, 0); DRM_DEBUG("plane 0 addr 0x%x stride %d height %d\n", priv->viu.vd1_addr0, priv->viu.vd1_stride0, diff --git a/drivers/gpu/drm/msm/msm_fb.c b/drivers/gpu/drm/msm/msm_fb.c index ee91058c7974..296fb89cdbd0 100644 --- a/drivers/gpu/drm/msm/msm_fb.c +++ b/drivers/gpu/drm/msm/msm_fb.c @@ -106,8 +106,8 @@ const struct msm_format *msm_framebuffer_format(struct drm_framebuffer *fb) struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct drm_gem_object *bos[4] = {0}; struct drm_framebuffer *fb; int ret, i, n = info->num_planes; @@ -137,8 +137,8 @@ struct drm_framebuffer *msm_framebuffer_create(struct drm_device *dev, static struct drm_framebuffer *msm_framebuffer_init(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct msm_drm_private *priv = dev->dev_private; struct msm_kms *kms = priv->kms; struct msm_framebuffer *msm_fb = NULL; diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index 6557b2d6e16e..1d4143adf829 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c @@ -298,8 +298,8 @@ void omap_framebuffer_describe(struct drm_framebuffer *fb, struct seq_file *m) struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, struct drm_file *file, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); unsigned int num_planes = info->num_planes; struct drm_gem_object *bos[4]; struct drm_framebuffer *fb; @@ -329,7 +329,7 @@ struct drm_framebuffer *omap_framebuffer_create(struct drm_device *dev, struct drm_framebuffer *omap_framebuffer_init(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **bos) { - const struct drm_format_info *format = NULL; + const struct image_format_info *format = NULL; struct omap_framebuffer *omap_fb = NULL; struct drm_framebuffer *fb = NULL; unsigned int pitch = mode_cmd->pitches[0]; diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c index 88fc1a6e2e43..4c50166546ca 100644 --- a/drivers/gpu/drm/radeon/radeon_fb.c +++ b/drivers/gpu/drm/radeon/radeon_fb.c @@ -125,8 +125,8 @@ static int radeonfb_create_pinned_object(struct radeon_fbdev *rfbdev, struct drm_mode_fb_cmd2 *mode_cmd, struct drm_gem_object **gobj_p) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct radeon_device *rdev = rfbdev->rdev; struct drm_gem_object *gobj = NULL; struct radeon_bo *rbo = NULL; diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c index c602cb2f4d3c..abb6783eb38e 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_fb.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_fb.c @@ -74,8 +74,8 @@ static struct drm_framebuffer * rockchip_user_fb_create(struct drm_device *dev, struct drm_file *file_priv, const struct drm_mode_fb_cmd2 *mode_cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, - mode_cmd); + const struct image_format_info *info = drm_get_format_info(dev, + mode_cmd); struct drm_framebuffer *fb; struct drm_gem_object *objs[ROCKCHIP_MAX_FB_BUFFER]; struct drm_gem_object *obj; diff --git a/drivers/gpu/drm/stm/ltdc.c b/drivers/gpu/drm/stm/ltdc.c index b226df7dbf6f..6afd8dcb3fd9 100644 --- a/drivers/gpu/drm/stm/ltdc.c +++ b/drivers/gpu/drm/stm/ltdc.c @@ -779,7 +779,7 @@ static void ltdc_plane_atomic_update(struct drm_plane *plane, /* Configures the color frame buffer pitch in bytes & line length */ pitch_in_bytes = fb->pitches[0]; - line_length = drm_format_plane_cpp(fb->format, 0) * + line_length = image_format_plane_cpp(fb->format, 0) * (x1 - x0 + 1) + (ldev->caps.bus_width >> 3) - 1; val = ((pitch_in_bytes << 16) | line_length); reg_update_bits(ldev->regs, LTDC_L1CFBLR + lofs, diff --git a/drivers/gpu/drm/sun4i/sun4i_backend.c b/drivers/gpu/drm/sun4i/sun4i_backend.c index 4c0d51f73237..f84c5edb234a 100644 --- a/drivers/gpu/drm/sun4i/sun4i_backend.c +++ b/drivers/gpu/drm/sun4i/sun4i_backend.c @@ -20,6 +20,7 @@ #include #include +#include #include #include #include @@ -203,7 +204,7 @@ static int sun4i_backend_update_yuv_format(struct sun4i_backend *backend, { struct drm_plane_state *state = plane->state; struct drm_framebuffer *fb = state->fb; - const struct drm_format_info *format = fb->format; + const struct image_format_info *format = fb->format; const uint32_t fmt = format->format; u32 val = SUN4I_BACKEND_IYUVCTL_EN; int i; @@ -222,8 +223,8 @@ static int sun4i_backend_update_yuv_format(struct sun4i_backend *backend, SUN4I_BACKEND_ATTCTL_REG0_LAY_YUVEN); /* TODO: Add support for the multi-planar YUV formats */ - if (drm_format_info_is_yuv_packed(format) && - drm_format_info_is_yuv_sampling_422(format)) + if (image_format_info_is_yuv_packed(format) && + image_format_info_is_yuv_sampling_422(format)) val |= SUN4I_BACKEND_IYUVCTL_FBFMT_PACKED_YUV422; else DRM_DEBUG_DRIVER("Unsupported YUV format (0x%x)\n", fmt); diff --git a/drivers/gpu/drm/sun4i/sun4i_frontend.c b/drivers/gpu/drm/sun4i/sun4i_frontend.c index 346c8071bd38..389637e9ec9d 100644 --- a/drivers/gpu/drm/sun4i/sun4i_frontend.c +++ b/drivers/gpu/drm/sun4i/sun4i_frontend.c @@ -9,6 +9,7 @@ #include #include +#include #include #include #include @@ -241,18 +242,18 @@ void sun4i_frontend_update_buffer(struct sun4i_frontend *frontend, EXPORT_SYMBOL(sun4i_frontend_update_buffer); static int -sun4i_frontend_drm_format_to_input_fmt(const struct drm_format_info *format, +sun4i_frontend_drm_format_to_input_fmt(const struct image_format_info *format, u32 *val) { if (!format->is_yuv) *val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_RGB; - else if (drm_format_info_is_yuv_sampling_411(format)) + else if (image_format_info_is_yuv_sampling_411(format)) *val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV411; - else if (drm_format_info_is_yuv_sampling_420(format)) + else if (image_format_info_is_yuv_sampling_420(format)) *val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV420; - else if (drm_format_info_is_yuv_sampling_422(format)) + else if (image_format_info_is_yuv_sampling_422(format)) *val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV422; - else if (drm_format_info_is_yuv_sampling_444(format)) + else if (image_format_info_is_yuv_sampling_444(format)) *val = SUN4I_FRONTEND_INPUT_FMT_DATA_FMT_YUV444; else return -EINVAL; @@ -261,7 +262,7 @@ sun4i_frontend_drm_format_to_input_fmt(const struct drm_format_info *format, } static int -sun4i_frontend_drm_format_to_input_mode(const struct drm_format_info *format, +sun4i_frontend_drm_format_to_input_mode(const struct image_format_info *format, uint64_t modifier, u32 *val) { bool tiled = (modifier == DRM_FORMAT_MOD_ALLWINNER_TILED); @@ -287,11 +288,11 @@ sun4i_frontend_drm_format_to_input_mode(const struct drm_format_info *format, } static int -sun4i_frontend_drm_format_to_input_sequence(const struct drm_format_info *format, +sun4i_frontend_drm_format_to_input_sequence(const struct image_format_info *format, u32 *val) { /* Planar formats have an explicit input sequence. */ - if (drm_format_info_is_yuv_planar(format)) { + if (image_format_info_is_yuv_planar(format)) { *val = 0; return 0; } @@ -401,7 +402,7 @@ int sun4i_frontend_update_formats(struct sun4i_frontend *frontend, { struct drm_plane_state *state = plane->state; struct drm_framebuffer *fb = state->fb; - const struct drm_format_info *format = fb->format; + const struct image_format_info *format = fb->format; uint64_t modifier = fb->modifier; u32 out_fmt_val; u32 in_fmt_val, in_mod_val, in_ps_val; diff --git a/drivers/gpu/drm/sun4i/sun8i_ui_layer.c b/drivers/gpu/drm/sun4i/sun8i_ui_layer.c index a342ec8b131e..bbd4a2d34eb7 100644 --- a/drivers/gpu/drm/sun4i/sun8i_ui_layer.c +++ b/drivers/gpu/drm/sun4i/sun8i_ui_layer.c @@ -23,6 +23,8 @@ #include #include +#include + #include "sun8i_ui_layer.h" #include "sun8i_mixer.h" #include "sun8i_ui_scaler.h" diff --git a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c index 8a0616238467..85b1b55ef342 100644 --- a/drivers/gpu/drm/sun4i/sun8i_vi_layer.c +++ b/drivers/gpu/drm/sun4i/sun8i_vi_layer.c @@ -17,6 +17,8 @@ #include #include +#include + #include "sun8i_vi_layer.h" #include "sun8i_mixer.h" #include "sun8i_vi_scaler.h" @@ -75,7 +77,7 @@ static int sun8i_vi_layer_update_coord(struct sun8i_mixer *mixer, int channel, unsigned int zpos) { struct drm_plane_state *state = plane->state; - const struct drm_format_info *format = state->fb->format; + const struct image_format_info *format = state->fb->format; u32 src_w, src_h, dst_w, dst_h; u32 bld_base, ch_base; u32 outsize, insize; @@ -219,7 +221,7 @@ static int sun8i_vi_layer_update_buffer(struct sun8i_mixer *mixer, int channel, { struct drm_plane_state *state = plane->state; struct drm_framebuffer *fb = state->fb; - const struct drm_format_info *format = fb->format; + const struct image_format_info *format = fb->format; struct drm_gem_cma_object *gem; u32 dx, dy, src_x, src_y; dma_addr_t paddr; diff --git a/drivers/gpu/drm/sun4i/sun8i_vi_scaler.c b/drivers/gpu/drm/sun4i/sun8i_vi_scaler.c index 7ba75011adf9..1d22331af5fe 100644 --- a/drivers/gpu/drm/sun4i/sun8i_vi_scaler.c +++ b/drivers/gpu/drm/sun4i/sun8i_vi_scaler.c @@ -9,6 +9,8 @@ * warranty of any kind, whether express or implied. */ +#include + #include "sun8i_vi_scaler.h" static const u32 lan3coefftab32_left[480] = { @@ -869,7 +871,7 @@ static int sun8i_vi_scaler_coef_index(unsigned int step) static void sun8i_vi_scaler_set_coeff(struct regmap *map, u32 base, u32 hstep, u32 vstep, - const struct drm_format_info *format) + const struct image_format_info *format) { const u32 *ch_left, *ch_right, *cy; int offset, i; @@ -926,7 +928,7 @@ void sun8i_vi_scaler_enable(struct sun8i_mixer *mixer, int layer, bool enable) void sun8i_vi_scaler_setup(struct sun8i_mixer *mixer, int layer, u32 src_w, u32 src_h, u32 dst_w, u32 dst_h, u32 hscale, u32 vscale, u32 hphase, u32 vphase, - const struct drm_format_info *format) + const struct image_format_info *format) { u32 chphase, cvphase; u32 insize, outsize; diff --git a/drivers/gpu/drm/sun4i/sun8i_vi_scaler.h b/drivers/gpu/drm/sun4i/sun8i_vi_scaler.h index 68f6593b369a..878a689e532a 100644 --- a/drivers/gpu/drm/sun4i/sun8i_vi_scaler.h +++ b/drivers/gpu/drm/sun4i/sun8i_vi_scaler.h @@ -9,7 +9,6 @@ #ifndef _SUN8I_VI_SCALER_H_ #define _SUN8I_VI_SCALER_H_ -#include #include "sun8i_mixer.h" #define DE2_VI_SCALER_UNIT_BASE 0x20000 @@ -69,10 +68,12 @@ #define SUN50I_SCALER_VSU_ANGLE_SHIFT(x) (((x) << 16) & 0xF) #define SUN50I_SCALER_VSU_ANGLE_OFFSET(x) ((x) & 0xFF) +struct image_format_info; + void sun8i_vi_scaler_enable(struct sun8i_mixer *mixer, int layer, bool enable); void sun8i_vi_scaler_setup(struct sun8i_mixer *mixer, int layer, u32 src_w, u32 src_h, u32 dst_w, u32 dst_h, u32 hscale, u32 vscale, u32 hphase, u32 vphase, - const struct drm_format_info *format); + const struct image_format_info *format); #endif diff --git a/drivers/gpu/drm/tegra/fb.c b/drivers/gpu/drm/tegra/fb.c index 0a97458b286a..591a9ede5b9a 100644 --- a/drivers/gpu/drm/tegra/fb.c +++ b/drivers/gpu/drm/tegra/fb.c @@ -131,7 +131,7 @@ struct drm_framebuffer *tegra_fb_create(struct drm_device *drm, struct drm_file *file, const struct drm_mode_fb_cmd2 *cmd) { - const struct drm_format_info *info = drm_get_format_info(dev, cmd); + const struct image_format_info *info = drm_get_format_info(dev, cmd); struct tegra_bo *planes[4]; struct drm_gem_object *gem; struct drm_framebuffer *fb; diff --git a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c index 57dda9d1a45d..32f8d312b426 100644 --- a/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c +++ b/drivers/gpu/drm/tinydrm/core/tinydrm-helpers.c @@ -36,7 +36,7 @@ MODULE_PARM_DESC(spi_max, "Set a lower SPI max transfer size"); void tinydrm_memcpy(void *dst, void *vaddr, struct drm_framebuffer *fb, struct drm_rect *clip) { - unsigned int cpp = drm_format_plane_cpp(fb->format, 0); + unsigned int cpp = image_format_plane_cpp(fb->format, 0); unsigned int pitch = fb->pitches[0]; void *src = vaddr + (clip->y1 * pitch) + (clip->x1 * cpp); size_t len = (clip->x2 - clip->x1) * cpp; diff --git a/drivers/gpu/drm/zte/zx_plane.c b/drivers/gpu/drm/zte/zx_plane.c index 41bd0db4e876..054149b57410 100644 --- a/drivers/gpu/drm/zte/zx_plane.c +++ b/drivers/gpu/drm/zte/zx_plane.c @@ -222,7 +222,7 @@ static void zx_vl_plane_atomic_update(struct drm_plane *plane, cma_obj = drm_fb_cma_get_gem_obj(fb, i); paddr = cma_obj->paddr + fb->offsets[i]; paddr += src_y * fb->pitches[i]; - paddr += src_x * drm_format_plane_cpp(fb->format, i); + paddr += src_x * image_format_plane_cpp(fb->format, i); zx_writel(paddr_reg, paddr); paddr_reg += 4; } diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 2291f2618211..7cc7b99a6569 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -49,6 +49,7 @@ struct drm_device; struct drm_mode_fb_cmd2; +struct image_format_info; /** * struct drm_format_info - information about a DRM format @@ -262,7 +263,8 @@ drm_format_info_is_yuv_sampling_444(const struct drm_format_info *info) const struct drm_format_info *__drm_format_info(u32 format); const struct drm_format_info *drm_format_info(u32 format); -const struct drm_format_info * + +const struct image_format_info * drm_get_format_info(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd); uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); diff --git a/include/drm/drm_framebuffer.h b/include/drm/drm_framebuffer.h index f0b34c977ec5..dc7dc48c8580 100644 --- a/include/drm/drm_framebuffer.h +++ b/include/drm/drm_framebuffer.h @@ -24,6 +24,7 @@ #define __DRM_FRAMEBUFFER_H__ #include +#include #include #include @@ -134,7 +135,7 @@ struct drm_framebuffer { /** * @format: framebuffer format information */ - const struct drm_format_info *format; + const struct image_format_info *format; /** * @funcs: framebuffer vfunc table */ diff --git a/include/drm/drm_mode_config.h b/include/drm/drm_mode_config.h index 7f60e8eb269a..74421d2fefbc 100644 --- a/include/drm/drm_mode_config.h +++ b/include/drm/drm_mode_config.h @@ -35,7 +35,7 @@ struct drm_file; struct drm_device; struct drm_atomic_state; struct drm_mode_fb_cmd2; -struct drm_format_info; +struct image_format_info; struct drm_display_mode; /** @@ -89,7 +89,7 @@ struct drm_mode_config_funcs { * The format information specific to the given fb metadata, or * NULL if none is found. */ - const struct drm_format_info *(*get_format_info)(const struct drm_mode_fb_cmd2 *mode_cmd); + const struct image_format_info *(*get_format_info)(const struct drm_mode_fb_cmd2 *mode_cmd); /** * @output_poll_changed: From patchwork Tue Mar 19 21:57:13 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860445 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 6B4156C2 for ; Tue, 19 Mar 2019 21:57:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 53835298FF for ; Tue, 19 Mar 2019 21:57:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4796529901; Tue, 19 Mar 2019 21:57:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0079C2965F for ; Tue, 19 Mar 2019 21:57:56 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 1456489BA5; Tue, 19 Mar 2019 21:57:54 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay2-d.mail.gandi.net (relay2-d.mail.gandi.net [217.70.183.194]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3B78989B9E for ; Tue, 19 Mar 2019 21:57:52 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay2-d.mail.gandi.net (Postfix) with ESMTPSA id A42DE40006; Tue, 19 Mar 2019 21:57:48 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 08/20] drm/malidp: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:13 +0100 Message-Id: <93737da7ef4ae99082ac8735a7713f68c017c535.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/arm/malidp_drv.c | 3 ++- drivers/gpu/drm/arm/malidp_hw.c | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/arm/malidp_drv.c b/drivers/gpu/drm/arm/malidp_drv.c index fec4fe15a71b..1fcbe364a137 100644 --- a/drivers/gpu/drm/arm/malidp_drv.c +++ b/drivers/gpu/drm/arm/malidp_drv.c @@ -10,6 +10,7 @@ * ARM Mali DP500/DP550/DP650 KMS/DRM driver */ +#include #include #include #include @@ -314,7 +315,7 @@ malidp_verify_afbc_framebuffer_size(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd) { int n_superblocks = 0; - const struct drm_format_info *info; + const struct image_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; diff --git a/drivers/gpu/drm/arm/malidp_hw.c b/drivers/gpu/drm/arm/malidp_hw.c index 07971ad53b29..d25bc4af1bc9 100644 --- a/drivers/gpu/drm/arm/malidp_hw.c +++ b/drivers/gpu/drm/arm/malidp_hw.c @@ -326,14 +326,14 @@ static void malidp500_modeset(struct malidp_hw_device *hwdev, struct videomode * static int malidp500_rotmem_required(struct malidp_hw_device *hwdev, u16 w, u16 h, u32 fmt) { - const struct drm_format_info *info = drm_format_info(fmt); + const struct image_format_info *info = image_format_drm_lookup(fmt); /* * Each layer needs enough rotation memory to fit 8 lines * worth of pixel data. Required size is then: * size = rotated_width * (bpp / 8) * 8; */ - return w * drm_format_plane_cpp(info, 0) * 8; + return w * image_format_plane_cpp(info, 0) * 8; } static void malidp500_se_write_pp_coefftab(struct malidp_hw_device *hwdev, From patchwork Tue Mar 19 21:57:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860449 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0896113B5 for ; Tue, 19 Mar 2019 21:58:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E36BB298FF for ; Tue, 19 Mar 2019 21:57:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CFBAE29911; Tue, 19 Mar 2019 21:57:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8E16529905 for ; Tue, 19 Mar 2019 21:57:59 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 6420D89BDB; Tue, 19 Mar 2019 21:57:58 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7820A89BB3 for ; Tue, 19 Mar 2019 21:57:57 +0000 (UTC) Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id ED9DE100002; Tue, 19 Mar 2019 21:57:51 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 09/20] drm/client: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:14 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert the rest of the DRM core to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/drm_client.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/drm_client.c b/drivers/gpu/drm/drm_client.c index 9df52b7fd074..a48181e18934 100644 --- a/drivers/gpu/drm/drm_client.c +++ b/drivers/gpu/drm/drm_client.c @@ -243,7 +243,7 @@ static void drm_client_buffer_delete(struct drm_client_buffer *buffer) static struct drm_client_buffer * drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u32 format) { - const struct drm_format_info *info = drm_format_info(format); + const struct image_format_info *info = image_format_drm_lookup(format); struct drm_mode_create_dumb dumb_args = { }; struct drm_device *dev = client->dev; struct drm_client_buffer *buffer; @@ -259,7 +259,7 @@ drm_client_buffer_create(struct drm_client_dev *client, u32 width, u32 height, u dumb_args.width = width; dumb_args.height = height; - dumb_args.bpp = drm_format_plane_cpp(info, 0) * 8; + dumb_args.bpp = image_format_plane_cpp(info, 0) * 8; ret = drm_mode_create_dumb(dev, &dumb_args, client->file); if (ret) goto err_delete; @@ -319,10 +319,10 @@ static int drm_client_buffer_addfb(struct drm_client_buffer *buffer, { struct drm_client_dev *client = buffer->client; struct drm_mode_fb_cmd fb_req = { }; - const struct drm_format_info *info; + const struct image_format_info *info; int ret; - info = drm_format_info(format); + info = image_format_drm_lookup(format); fb_req.bpp = info->cpp[0] * 8; fb_req.depth = info->depth; fb_req.width = width; From patchwork Tue Mar 19 21:57:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860453 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B67191669 for ; Tue, 19 Mar 2019 21:58:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E364298FF for ; Tue, 19 Mar 2019 21:58:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9214329901; Tue, 19 Mar 2019 21:58:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 454E629917 for ; Tue, 19 Mar 2019 21:58:02 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 4AD1789BF8; Tue, 19 Mar 2019 21:58:01 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay10.mail.gandi.net (relay10.mail.gandi.net [217.70.178.230]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4B9F489BCD for ; Tue, 19 Mar 2019 21:57:58 +0000 (UTC) Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay10.mail.gandi.net (Postfix) with ESMTPSA id EEA5A240004; Tue, 19 Mar 2019 21:57:54 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 10/20] drm/exynos: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:15 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/exynos/exynos_drm_ipp.c | 2 +- drivers/gpu/drm/exynos/exynos_drm_ipp.h | 4 +++- drivers/gpu/drm/exynos/exynos_drm_scaler.c | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.c b/drivers/gpu/drm/exynos/exynos_drm_ipp.c index 23226a0212e8..ba012840fe07 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_ipp.c +++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.c @@ -562,7 +562,7 @@ static int exynos_drm_ipp_check_format(struct exynos_drm_ipp_task *task, if (buf->buf.width == 0 || buf->buf.height == 0) return -EINVAL; - buf->format = drm_format_info(buf->buf.fourcc); + buf->format = image_format_drm_lookup(buf->buf.fourcc); for (i = 0; i < buf->format->num_planes; i++) { unsigned int width = (i == 0) ? buf->buf.width : DIV_ROUND_UP(buf->buf.width, buf->format->hsub); diff --git a/drivers/gpu/drm/exynos/exynos_drm_ipp.h b/drivers/gpu/drm/exynos/exynos_drm_ipp.h index 0b27d4a9bf94..c6cd21f185e6 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_ipp.h +++ b/drivers/gpu/drm/exynos/exynos_drm_ipp.h @@ -71,12 +71,14 @@ struct exynos_drm_ipp { wait_queue_head_t done_wq; }; +struct image_format_info; + struct exynos_drm_ipp_buffer { struct drm_exynos_ipp_task_buffer buf; struct drm_exynos_ipp_task_rect rect; struct exynos_drm_gem *exynos_gem[MAX_FB_BUFFER]; - const struct drm_format_info *format; + const struct image_format_info *format; dma_addr_t dma_addr[MAX_FB_BUFFER]; }; diff --git a/drivers/gpu/drm/exynos/exynos_drm_scaler.c b/drivers/gpu/drm/exynos/exynos_drm_scaler.c index ed1dd1aec902..c9791a2013cf 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_scaler.c +++ b/drivers/gpu/drm/exynos/exynos_drm_scaler.c @@ -11,6 +11,7 @@ #include #include #include +#include #include #include #include @@ -301,7 +302,7 @@ static inline void scaler_set_rotation(struct scaler_context *scaler, } static inline void scaler_set_csc(struct scaler_context *scaler, - const struct drm_format_info *fmt) + const struct image_format_info *fmt) { static const u32 csc_mtx[2][3][3] = { { /* YCbCr to RGB */ From patchwork Tue Mar 19 21:57:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860455 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2CF786C2 for ; Tue, 19 Mar 2019 21:58:06 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1438E298FF for ; Tue, 19 Mar 2019 21:58:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 0866229905; Tue, 19 Mar 2019 21:58:06 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id BA8CB29901 for ; Tue, 19 Mar 2019 21:58:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id B344589BFC; Tue, 19 Mar 2019 21:58:04 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by gabe.freedesktop.org (Postfix) with ESMTPS id DD9AF89BCD for ; Tue, 19 Mar 2019 21:58:00 +0000 (UTC) Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 86C67100005; Tue, 19 Mar 2019 21:57:57 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 11/20] drm/i915: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:16 +0100 Message-Id: <37ad4786835372353c4479065e0f17f95e2d6953.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/i915/intel_display.c | 4 ++-- drivers/gpu/drm/i915/intel_sprite.c | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c index 86febe2ee510..37c7f6bbf650 100644 --- a/drivers/gpu/drm/i915/intel_display.c +++ b/drivers/gpu/drm/i915/intel_display.c @@ -7997,7 +7997,7 @@ i9xx_get_initial_plane_config(struct intel_crtc *crtc, pixel_format = val & DISPPLANE_PIXFORMAT_MASK; fourcc = i9xx_format_to_fourcc(pixel_format); - fb->format = drm_format_info(fourcc); + fb->format = image_format_drm_lookup(fourcc); if (IS_HASWELL(dev_priv) || IS_BROADWELL(dev_priv)) { offset = I915_READ(DSPOFFSET(i9xx_plane)); @@ -9078,7 +9078,7 @@ skylake_get_initial_plane_config(struct intel_crtc *crtc, fourcc = skl_format_to_fourcc(pixel_format, val & PLANE_CTL_ORDER_RGBX, alpha); - fb->format = drm_format_info(fourcc); + fb->format = image_format_drm_lookup(fourcc); tiling = val & PLANE_CTL_TILED_MASK; switch (tiling) { diff --git a/drivers/gpu/drm/i915/intel_sprite.c b/drivers/gpu/drm/i915/intel_sprite.c index ee0e99b13532..aaae2bd4ed05 100644 --- a/drivers/gpu/drm/i915/intel_sprite.c +++ b/drivers/gpu/drm/i915/intel_sprite.c @@ -297,8 +297,8 @@ skl_plane_max_stride(struct intel_plane *plane, u32 pixel_format, u64 modifier, unsigned int rotation) { - const struct drm_format_info *info = drm_format_info(pixel_format); - int cpp = drm_format_plane_cpp(info, 0); + const struct image_format_info *info = image_format_drm_lookup(pixel_format); + int cpp = image_format_plane_cpp(info, 0); /* * "The stride in bytes must not exceed the From patchwork Tue Mar 19 21:57:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860457 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 95A2F6C2 for ; Tue, 19 Mar 2019 21:58:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7D62829901 for ; Tue, 19 Mar 2019 21:58:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 722D729902; Tue, 19 Mar 2019 21:58:09 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 2AC9F29917 for ; Tue, 19 Mar 2019 21:58:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 02DD189C03; Tue, 19 Mar 2019 21:58:08 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay8-d.mail.gandi.net (relay8-d.mail.gandi.net [217.70.183.201]) by gabe.freedesktop.org (Postfix) with ESMTPS id 2AF6589BFE for ; Tue, 19 Mar 2019 21:58:05 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay8-d.mail.gandi.net (Postfix) with ESMTPSA id 5700B1BF207; Tue, 19 Mar 2019 21:57:59 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 12/20] drm/ipuv3: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:17 +0100 Message-Id: <56da0cae4bd0477930b355a5ddc511a570a587ee.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/ipu-v3/ipu-pre.c | 3 ++- drivers/gpu/ipu-v3/ipu-prg.c | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/drivers/gpu/ipu-v3/ipu-pre.c b/drivers/gpu/ipu-v3/ipu-pre.c index 4a28f3fbb0a2..d561295abee0 100644 --- a/drivers/gpu/ipu-v3/ipu-pre.c +++ b/drivers/gpu/ipu-v3/ipu-pre.c @@ -15,6 +15,7 @@ #include #include #include +#include #include #include #include @@ -174,7 +175,7 @@ void ipu_pre_configure(struct ipu_pre *pre, unsigned int width, unsigned int height, unsigned int stride, u32 format, uint64_t modifier, unsigned int bufaddr) { - const struct drm_format_info *info = drm_format_info(format); + const struct image_format_info *info = image_format_drm_lookup(format); u32 active_bpp = info->cpp[0] >> 1; u32 val; diff --git a/drivers/gpu/ipu-v3/ipu-prg.c b/drivers/gpu/ipu-v3/ipu-prg.c index 38a3a9764e49..608a9213025d 100644 --- a/drivers/gpu/ipu-v3/ipu-prg.c +++ b/drivers/gpu/ipu-v3/ipu-prg.c @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -132,7 +133,7 @@ EXPORT_SYMBOL_GPL(ipu_prg_present); bool ipu_prg_format_supported(struct ipu_soc *ipu, uint32_t format, uint64_t modifier) { - const struct drm_format_info *info = drm_format_info(format); + const struct image_format_info *info = image_format_drm_lookup(format); if (info->num_planes != 1) return false; From patchwork Tue Mar 19 21:57:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860461 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 084AF13B5 for ; Tue, 19 Mar 2019 21:58:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E299429902 for ; Tue, 19 Mar 2019 21:58:12 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D62C929905; Tue, 19 Mar 2019 21:58:12 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 548C129919 for ; Tue, 19 Mar 2019 21:58:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 43B2089C08; Tue, 19 Mar 2019 21:58:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by gabe.freedesktop.org (Postfix) with ESMTPS id 5C5FC89C03 for ; Tue, 19 Mar 2019 21:58:07 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 1131DFF804; Tue, 19 Mar 2019 21:58:02 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 13/20] drm/msm: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:18 +0100 Message-Id: <8784fe32eed0682db41a4fa9164d8298c28360ff.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c | 6 ++++-- drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c | 3 ++- drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c | 3 ++- drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c | 9 +++++---- drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c | 3 ++- 5 files changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c index 1aed51b49be4..8c3c953b05d9 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_formats.c @@ -12,6 +12,8 @@ #define pr_fmt(fmt) "[drm:%s:%d] " fmt, __func__, __LINE__ +#include + #include #include "msm_media_info.h" @@ -1040,7 +1042,7 @@ int dpu_format_check_modified_format( const struct drm_mode_fb_cmd2 *cmd, struct drm_gem_object **bos) { - const struct drm_format_info *info; + const struct image_format_info *info; const struct dpu_format *fmt; struct dpu_hw_fmt_layout layout; uint32_t bos_total_size = 0; @@ -1052,7 +1054,7 @@ int dpu_format_check_modified_format( } fmt = to_dpu_format(msm_fmt); - info = drm_format_info(fmt->base.pixel_format); + info = image_format_drm_lookup(fmt->base.pixel_format); if (!info) return -EINVAL; diff --git a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c index a9492c488441..1dfaa306ed4b 100644 --- a/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c +++ b/drivers/gpu/drm/msm/disp/dpu1/dpu_plane.c @@ -20,6 +20,7 @@ #include #include +#include #include @@ -553,7 +554,7 @@ static void _dpu_plane_setup_scaler(struct dpu_plane *pdpu, struct dpu_plane_state *pstate, const struct dpu_format *fmt, bool color_fill) { - const struct drm_format_info *info = drm_format_info(fmt->base.pixel_format); + const struct image_format_info *info = image_format_drm_lookup(fmt->base.pixel_format); /* don't chroma subsample if decimating */ /* update scaler. calculate default config for QSEED3 */ diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c index aadae21f8818..542c22c4febe 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_crtc.c @@ -16,6 +16,7 @@ * this program. If not, see . */ +#include #include #include #include @@ -782,7 +783,7 @@ static void get_roi(struct drm_crtc *crtc, uint32_t *roi_w, uint32_t *roi_h) static void mdp5_crtc_restore_cursor(struct drm_crtc *crtc) { - const struct drm_format_info *info = drm_format_info(DRM_FORMAT_ARGB8888); + const struct image_format_info *info = image_format_drm_lookup(DRM_FORMAT_ARGB8888); struct mdp5_crtc_state *mdp5_cstate = to_mdp5_crtc_state(crtc->state); struct mdp5_crtc *mdp5_crtc = to_mdp5_crtc(crtc); struct mdp5_kms *mdp5_kms = get_kms(crtc); diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c index 9d9fb6c5fd68..00091637a00c 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_plane.c @@ -17,6 +17,7 @@ */ #include +#include #include "mdp5_kms.h" struct mdp5_plane { @@ -650,7 +651,7 @@ static int calc_scalex_steps(struct drm_plane *plane, uint32_t pixel_format, uint32_t src, uint32_t dest, uint32_t phasex_steps[COMP_MAX]) { - const struct drm_format_info *info = drm_format_info(pixel_format); + const struct image_format_info *info = image_format_drm_lookup(pixel_format); struct mdp5_kms *mdp5_kms = get_kms(plane); struct device *dev = mdp5_kms->dev->dev; uint32_t phasex_step; @@ -673,7 +674,7 @@ static int calc_scaley_steps(struct drm_plane *plane, uint32_t pixel_format, uint32_t src, uint32_t dest, uint32_t phasey_steps[COMP_MAX]) { - const struct drm_format_info *info = drm_format_info(pixel_format); + const struct image_format_info *info = image_format_drm_lookup(pixel_format); struct mdp5_kms *mdp5_kms = get_kms(plane); struct device *dev = mdp5_kms->dev->dev; uint32_t phasey_step; @@ -695,7 +696,7 @@ static int calc_scaley_steps(struct drm_plane *plane, static uint32_t get_scale_config(const struct mdp_format *format, uint32_t src, uint32_t dst, bool horz) { - const struct drm_format_info *info = drm_format_info(format->base.pixel_format); + const struct image_format_info *info = image_format_drm_lookup(format->base.pixel_format); bool scaling = format->is_yuv ? true : (src != dst); uint32_t sub; uint32_t ya_filter, uv_filter; @@ -750,7 +751,7 @@ static void mdp5_write_pixel_ext(struct mdp5_kms *mdp5_kms, enum mdp5_pipe pipe, uint32_t src_w, int pe_left[COMP_MAX], int pe_right[COMP_MAX], uint32_t src_h, int pe_top[COMP_MAX], int pe_bottom[COMP_MAX]) { - const struct drm_format_info *info = drm_format_info(format->base.pixel_format); + const struct image_format_info *info = image_format_drm_lookup(format->base.pixel_format); uint32_t lr, tb, req; int i; diff --git a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c index 03d503d8c3ba..b96ff05d7909 100644 --- a/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c +++ b/drivers/gpu/drm/msm/disp/mdp5/mdp5_smp.c @@ -16,6 +16,7 @@ * this program. If not, see . */ +#include #include #include "mdp5_kms.h" @@ -127,7 +128,7 @@ uint32_t mdp5_smp_calculate(struct mdp5_smp *smp, const struct mdp_format *format, u32 width, bool hdecim) { - const struct drm_format_info *info = drm_format_info(format->base.pixel_format); + const struct image_format_info *info = image_format_drm_lookup(format->base.pixel_format); struct mdp5_kms *mdp5_kms = get_kms(smp); int rev = mdp5_cfg_get_hw_rev(mdp5_kms->cfg); int i, hsub, nplanes, nlines; From patchwork Tue Mar 19 21:57:19 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860477 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1F4B06C2 for ; Tue, 19 Mar 2019 21:58:32 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 061BE29918 for ; Tue, 19 Mar 2019 21:58:32 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id EE1102991C; Tue, 19 Mar 2019 21:58:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8CA1A2965F for ; Tue, 19 Mar 2019 21:58:31 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id CDF4289C51; Tue, 19 Mar 2019 21:58:29 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [217.70.183.193]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4853289C3F for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay1-d.mail.gandi.net (Postfix) with ESMTPSA id 30364240003; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 14/20] drm/omap: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:19 +0100 Message-Id: <49fd5e9fe1712ca4c6aee2e376ffda2cec11bc13.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/omapdrm/dss/dispc.c | 9 +++++---- drivers/gpu/drm/omapdrm/omap_fb.c | 7 ++++--- 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/drivers/gpu/drm/omapdrm/dss/dispc.c b/drivers/gpu/drm/omapdrm/dss/dispc.c index ba82d916719c..bf60d49ad6ca 100644 --- a/drivers/gpu/drm/omapdrm/dss/dispc.c +++ b/drivers/gpu/drm/omapdrm/dss/dispc.c @@ -25,6 +25,7 @@ #include #include #include +#include #include #include #include @@ -1898,9 +1899,9 @@ static void dispc_ovl_set_scaling_uv(struct dispc_device *dispc, int scale_x = out_width != orig_width; int scale_y = out_height != orig_height; bool chroma_upscale = plane != OMAP_DSS_WB; - const struct drm_format_info *info; + const struct image_format_info *info; - info = drm_format_info(fourcc); + info = image_format_drm_lookup(fourcc); if (!dispc_has_feature(dispc, FEAT_HANDLE_UV_SEPARATE)) return; @@ -2623,9 +2624,9 @@ static int dispc_ovl_setup_common(struct dispc_device *dispc, bool ilace = !!(vm->flags & DISPLAY_FLAGS_INTERLACED); unsigned long pclk = dispc_plane_pclk_rate(dispc, plane); unsigned long lclk = dispc_plane_lclk_rate(dispc, plane); - const struct drm_format_info *info; + const struct image_format_info *info; - info = drm_format_info(fourcc); + info = image_format_drm_lookup(fourcc); /* when setting up WB, dispc_plane_pclk_rate() returns 0 */ if (plane == OMAP_DSS_WB) diff --git a/drivers/gpu/drm/omapdrm/omap_fb.c b/drivers/gpu/drm/omapdrm/omap_fb.c index 1d4143adf829..8caecfc8d1db 100644 --- a/drivers/gpu/drm/omapdrm/omap_fb.c +++ b/drivers/gpu/drm/omapdrm/omap_fb.c @@ -15,6 +15,7 @@ * this program. If not, see . */ +#include #include #include @@ -60,7 +61,7 @@ struct plane { struct omap_framebuffer { struct drm_framebuffer base; int pin_count; - const struct drm_format_info *format; + const struct image_format_info *format; struct plane planes[2]; /* lock for pinning (pin_count and planes.dma_addr) */ struct mutex lock; @@ -72,7 +73,7 @@ static const struct drm_framebuffer_funcs omap_framebuffer_funcs = { }; static u32 get_linear_addr(struct drm_framebuffer *fb, - const struct drm_format_info *format, int n, int x, int y) + const struct image_format_info *format, int n, int x, int y) { struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); struct plane *plane = &omap_fb->planes[n]; @@ -126,7 +127,7 @@ void omap_framebuffer_update_scanout(struct drm_framebuffer *fb, struct drm_plane_state *state, struct omap_overlay_info *info) { struct omap_framebuffer *omap_fb = to_omap_framebuffer(fb); - const struct drm_format_info *format = omap_fb->format; + const struct image_format_info *format = omap_fb->format; struct plane *plane = &omap_fb->planes[0]; u32 x, y, orient = 0; From patchwork Tue Mar 19 21:57:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860467 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F004113B5 for ; Tue, 19 Mar 2019 21:58:19 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D81842965F for ; Tue, 19 Mar 2019 21:58:19 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D621C29912; Tue, 19 Mar 2019 21:58:19 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 95D1929902 for ; Tue, 19 Mar 2019 21:58:19 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 63F5B89C21; Tue, 19 Mar 2019 21:58:15 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by gabe.freedesktop.org (Postfix) with ESMTPS id 4C96F89C09 for ; Tue, 19 Mar 2019 21:58:11 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 0324CFF80D; Tue, 19 Mar 2019 21:58:07 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 15/20] drm/rockchip: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:20 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 88c3902057f3..8f4cfadfd6cd 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -317,7 +318,7 @@ static void scl_vop_cal_scl_fac(struct vop *vop, const struct vop_win_data *win, uint32_t src_w, uint32_t src_h, uint32_t dst_w, uint32_t dst_h, uint32_t pixel_format) { - const struct drm_format_info *info = drm_format_info(pixel_format); + const struct image_format_info *info = image_format_drm_lookup(pixel_format); uint16_t yrgb_hor_scl_mode, yrgb_ver_scl_mode; uint16_t cbcr_hor_scl_mode = SCALE_NONE; uint16_t cbcr_ver_scl_mode = SCALE_NONE; From patchwork Tue Mar 19 21:57:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860465 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3CBF26C2 for ; Tue, 19 Mar 2019 21:58:18 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 247D52956D for ; Tue, 19 Mar 2019 21:58:18 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 22F552965F; Tue, 19 Mar 2019 21:58:18 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id D468D29915 for ; Tue, 19 Mar 2019 21:58:17 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9E17589C1C; Tue, 19 Mar 2019 21:58:14 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id BE52189C17 for ; Tue, 19 Mar 2019 21:58:13 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id 702C0C0007; Tue, 19 Mar 2019 21:58:10 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 16/20] drm/tegra: Convert to generic image format library Date: Tue, 19 Mar 2019 22:57:21 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that we have a generic image format libary, let's convert drivers to use it so that we can deprecate the old DRM one. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/tegra/plane.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/gpu/drm/tegra/plane.c b/drivers/gpu/drm/tegra/plane.c index d068e8aa3553..e1d82cbdabe8 100644 --- a/drivers/gpu/drm/tegra/plane.c +++ b/drivers/gpu/drm/tegra/plane.c @@ -6,6 +6,8 @@ * published by the Free Software Foundation. */ +#include + #include #include #include @@ -76,7 +78,7 @@ static bool tegra_plane_format_mod_supported(struct drm_plane *plane, uint32_t format, uint64_t modifier) { - const struct drm_format_info *info = drm_format_info(format); + const struct image_format_info *info = image_format_drm_lookup(format); if (modifier == DRM_FORMAT_MOD_LINEAR) return true; From patchwork Tue Mar 19 21:57:22 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860469 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 0D83313B5 for ; Tue, 19 Mar 2019 21:58:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E408F29919 for ; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7A0C29902; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 8D3EF29901 for ; Tue, 19 Mar 2019 21:58:22 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 79A4A89C33; Tue, 19 Mar 2019 21:58:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay7-d.mail.gandi.net (relay7-d.mail.gandi.net [217.70.183.200]) by gabe.freedesktop.org (Postfix) with ESMTPS id 689AF89C27 for ; Tue, 19 Mar 2019 21:58:17 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay7-d.mail.gandi.net (Postfix) with ESMTPSA id 1680720002; Tue, 19 Mar 2019 21:58:12 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 17/20] drm/fourcc: Remove old DRM format API Date: Tue, 19 Mar 2019 22:57:22 +0100 Message-Id: <4ac66a937d2bc87984660ebe88a556369d00fae3.1553032382.git-series.maxime.ripard@bootlin.com> X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP Now that all the clients of the old drm_format* API have been converted to the generic one, let's remove it. Signed-off-by: Maxime Ripard --- drivers/gpu/drm/Kconfig | 1 +- drivers/gpu/drm/drm_fourcc.c | 253 +------------ drivers/gpu/drm/selftests/Makefile | 3 +- drivers/gpu/drm/selftests/drm_modeset_selftests.h | 3 +- drivers/gpu/drm/selftests/test-drm_format.c | 280 +------------- drivers/gpu/drm/selftests/test-drm_modeset_common.h | 3 +- include/drm/drm_fourcc.h | 216 +---------- 7 files changed, 2 insertions(+), 757 deletions(-) delete mode 100644 drivers/gpu/drm/selftests/test-drm_format.c diff --git a/drivers/gpu/drm/Kconfig b/drivers/gpu/drm/Kconfig index 7992a95ea965..cfc50fc92497 100644 --- a/drivers/gpu/drm/Kconfig +++ b/drivers/gpu/drm/Kconfig @@ -54,6 +54,7 @@ config DRM_DEBUG_SELFTEST tristate "kselftests for DRM" depends on DRM depends on DEBUG_KERNEL + select IMAGE_FORMATS_SELFTESTS select PRIME_NUMBERS select DRM_LIB_RANDOM select DRM_KMS_HELPER diff --git a/drivers/gpu/drm/drm_fourcc.c b/drivers/gpu/drm/drm_fourcc.c index 6ddb1c28be49..4f262e1a202a 100644 --- a/drivers/gpu/drm/drm_fourcc.c +++ b/drivers/gpu/drm/drm_fourcc.c @@ -150,136 +150,6 @@ const char *drm_get_format_name(uint32_t format, struct drm_format_name_buf *buf } EXPORT_SYMBOL(drm_get_format_name); -/* - * Internal function to query information for a given format. See - * drm_format_info() for the public API. - */ -const struct drm_format_info *__drm_format_info(u32 format) -{ - static const struct drm_format_info formats[] = { - { .format = DRM_FORMAT_C8, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGB332, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGR233, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_XRGB4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_XBGR4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGBX4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGRX4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_ARGB4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_ABGR4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGBA4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGRA4444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_XRGB1555, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_XBGR1555, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGBX5551, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGRX5551, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_ARGB1555, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_ABGR1555, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGBA5551, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGRA5551, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGB565, .depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGR565, .depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGB888, .depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGR888, .depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_XRGB8888, .depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_XBGR8888, .depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGBX8888, .depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGRX8888, .depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGB565_A8, .depth = 24, .num_planes = 2, .cpp = { 2, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGR565_A8, .depth = 24, .num_planes = 2, .cpp = { 2, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_XRGB2101010, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_XBGR2101010, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_RGBX1010102, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_BGRX1010102, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1 }, - { .format = DRM_FORMAT_ARGB2101010, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_ABGR2101010, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGBA1010102, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGRA1010102, .depth = 30, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_ARGB8888, .depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_ABGR8888, .depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGBA8888, .depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGRA8888, .depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGB888_A8, .depth = 32, .num_planes = 2, .cpp = { 3, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGR888_A8, .depth = 32, .num_planes = 2, .cpp = { 3, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_XRGB8888_A8, .depth = 32, .num_planes = 2, .cpp = { 4, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_XBGR8888_A8, .depth = 32, .num_planes = 2, .cpp = { 4, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_RGBX8888_A8, .depth = 32, .num_planes = 2, .cpp = { 4, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_BGRX8888_A8, .depth = 32, .num_planes = 2, .cpp = { 4, 1, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true }, - { .format = DRM_FORMAT_YUV410, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4, .is_yuv = true }, - { .format = DRM_FORMAT_YVU410, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 4, .is_yuv = true }, - { .format = DRM_FORMAT_YUV411, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YVU411, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 4, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YUV420, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2, .is_yuv = true }, - { .format = DRM_FORMAT_YVU420, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 2, .is_yuv = true }, - { .format = DRM_FORMAT_YUV422, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YVU422, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YUV444, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YVU444, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, .hsub = 1, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_NV12, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2, .is_yuv = true }, - { .format = DRM_FORMAT_NV21, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 2, .is_yuv = true }, - { .format = DRM_FORMAT_NV16, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_NV61, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_NV24, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_NV42, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, .hsub = 1, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YUYV, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_YVYU, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_UYVY, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_VYUY, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, .hsub = 2, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_XYUV8888, .depth = 0, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .is_yuv = true }, - { .format = DRM_FORMAT_AYUV, .depth = 0, .num_planes = 1, .cpp = { 4, 0, 0 }, .hsub = 1, .vsub = 1, .has_alpha = true, .is_yuv = true }, - { .format = DRM_FORMAT_Y0L0, .depth = 0, .num_planes = 1, - .char_per_block = { 8, 0, 0 }, .block_w = { 2, 0, 0 }, .block_h = { 2, 0, 0 }, - .hsub = 2, .vsub = 2, .has_alpha = true, .is_yuv = true }, - { .format = DRM_FORMAT_X0L0, .depth = 0, .num_planes = 1, - .char_per_block = { 8, 0, 0 }, .block_w = { 2, 0, 0 }, .block_h = { 2, 0, 0 }, - .hsub = 2, .vsub = 2, .is_yuv = true }, - { .format = DRM_FORMAT_Y0L2, .depth = 0, .num_planes = 1, - .char_per_block = { 8, 0, 0 }, .block_w = { 2, 0, 0 }, .block_h = { 2, 0, 0 }, - .hsub = 2, .vsub = 2, .has_alpha = true, .is_yuv = true }, - { .format = DRM_FORMAT_X0L2, .depth = 0, .num_planes = 1, - .char_per_block = { 8, 0, 0 }, .block_w = { 2, 0, 0 }, .block_h = { 2, 0, 0 }, - .hsub = 2, .vsub = 2, .is_yuv = true }, - { .format = DRM_FORMAT_P010, .depth = 0, .num_planes = 2, - .char_per_block = { 2, 4, 0 }, .block_w = { 1, 0, 0 }, .block_h = { 1, 0, 0 }, - .hsub = 2, .vsub = 2, .is_yuv = true}, - { .format = DRM_FORMAT_P012, .depth = 0, .num_planes = 2, - .char_per_block = { 2, 4, 0 }, .block_w = { 1, 0, 0 }, .block_h = { 1, 0, 0 }, - .hsub = 2, .vsub = 2, .is_yuv = true}, - { .format = DRM_FORMAT_P016, .depth = 0, .num_planes = 2, - .char_per_block = { 2, 4, 0 }, .block_w = { 1, 0, 0 }, .block_h = { 1, 0, 0 }, - .hsub = 2, .vsub = 2, .is_yuv = true}, - }; - - unsigned int i; - - for (i = 0; i < ARRAY_SIZE(formats); ++i) { - if (formats[i].format == format) - return &formats[i]; - } - - return NULL; -} - -/** - * drm_format_info - query information for a given format - * @format: pixel format (DRM_FORMAT_*) - * - * The caller should only pass a supported pixel format to this function. - * Unsupported pixel formats will generate a warning in the kernel log. - * - * Returns: - * The instance of struct drm_format_info that describes the pixel format, or - * NULL if the format is unsupported. - */ -const struct drm_format_info *drm_format_info(u32 format) -{ - const struct drm_format_info *info; - - info = __drm_format_info(format); - WARN_ON(!info); - return info; -} -EXPORT_SYMBOL(drm_format_info); - /** * drm_get_format_info - query information for a given framebuffer configuration * @dev: DRM device @@ -304,126 +174,3 @@ drm_get_format_info(struct drm_device *dev, return info; } EXPORT_SYMBOL(drm_get_format_info); - -/** - * drm_format_plane_cpp - determine the bytes per pixel value - * @format: pixel format info - * @plane: plane index - * - * Returns: - * The bytes per pixel value for the specified plane. - */ -int drm_format_plane_cpp(const struct drm_format_info *info, int plane) -{ - if (!info || plane >= info->num_planes) - return 0; - - return info->cpp[plane]; -} -EXPORT_SYMBOL(drm_format_plane_cpp); - -/** - * drm_format_plane_width - width of the plane given the first plane - * @width: width of the first plane - * @format: pixel format info - * @plane: plane index - * - * Returns: - * The width of @plane, given that the width of the first plane is @width. - */ -int drm_format_plane_width(int width, const struct drm_format_info *info, - int plane) -{ - if (!info || plane >= info->num_planes) - return 0; - - if (plane == 0) - return width; - - return width / info->hsub; -} -EXPORT_SYMBOL(drm_format_plane_width); - -/** - * drm_format_plane_height - height of the plane given the first plane - * @height: height of the first plane - * @format: pixel format info - * @plane: plane index - * - * Returns: - * The height of @plane, given that the height of the first plane is @height. - */ -int drm_format_plane_height(int height, const struct drm_format_info *info, - int plane) -{ - if (!info || plane >= info->num_planes) - return 0; - - if (plane == 0) - return height; - - return height / info->vsub; -} -EXPORT_SYMBOL(drm_format_plane_height); - -/** - * drm_format_info_block_width - width in pixels of block. - * @info: pixel format info - * @plane: plane index - * - * Returns: - * The width in pixels of a block, depending on the plane index. - */ -unsigned int drm_format_info_block_width(const struct drm_format_info *info, - int plane) -{ - if (!info || plane < 0 || plane >= info->num_planes) - return 0; - - if (!info->block_w[plane]) - return 1; - return info->block_w[plane]; -} -EXPORT_SYMBOL(drm_format_info_block_width); - -/** - * drm_format_info_block_height - height in pixels of a block - * @info: pixel format info - * @plane: plane index - * - * Returns: - * The height in pixels of a block, depending on the plane index. - */ -unsigned int drm_format_info_block_height(const struct drm_format_info *info, - int plane) -{ - if (!info || plane < 0 || plane >= info->num_planes) - return 0; - - if (!info->block_h[plane]) - return 1; - return info->block_h[plane]; -} -EXPORT_SYMBOL(drm_format_info_block_height); - -/** - * drm_format_info_min_pitch - computes the minimum required pitch in bytes - * @info: pixel format info - * @plane: plane index - * @buffer_width: buffer width in pixels - * - * Returns: - * The minimum required pitch in bytes for a buffer by taking into consideration - * the pixel format information and the buffer width. - */ -uint64_t drm_format_info_min_pitch(const struct drm_format_info *info, - int plane, unsigned int buffer_width) -{ - if (!info || plane < 0 || plane >= info->num_planes) - return 0; - - return DIV_ROUND_UP_ULL((u64)buffer_width * info->char_per_block[plane], - drm_format_info_block_width(info, plane) * - drm_format_info_block_height(info, plane)); -} -EXPORT_SYMBOL(drm_format_info_min_pitch); diff --git a/drivers/gpu/drm/selftests/Makefile b/drivers/gpu/drm/selftests/Makefile index 1bb73dc4c88c..e32921691662 100644 --- a/drivers/gpu/drm/selftests/Makefile +++ b/drivers/gpu/drm/selftests/Makefile @@ -1,5 +1,4 @@ test-drm_modeset-y := test-drm_modeset_common.o test-drm_plane_helper.o \ - test-drm_format.o test-drm_framebuffer.o \ - test-drm_damage_helper.o + test-drm_framebuffer.o test-drm_damage_helper.o obj-$(CONFIG_DRM_DEBUG_SELFTEST) += test-drm_mm.o test-drm_modeset.o diff --git a/drivers/gpu/drm/selftests/drm_modeset_selftests.h b/drivers/gpu/drm/selftests/drm_modeset_selftests.h index 464753746013..4a2ef84c2762 100644 --- a/drivers/gpu/drm/selftests/drm_modeset_selftests.h +++ b/drivers/gpu/drm/selftests/drm_modeset_selftests.h @@ -7,9 +7,6 @@ * Tests are executed in order by igt/drm_selftests_helper */ selftest(check_plane_state, igt_check_plane_state) -selftest(check_drm_format_block_width, igt_check_drm_format_block_width) -selftest(check_drm_format_block_height, igt_check_drm_format_block_height) -selftest(check_drm_format_min_pitch, igt_check_drm_format_min_pitch) selftest(check_drm_framebuffer_create, igt_check_drm_framebuffer_create) selftest(damage_iter_no_damage, igt_damage_iter_no_damage) selftest(damage_iter_no_damage_fractional_src, igt_damage_iter_no_damage_fractional_src) diff --git a/drivers/gpu/drm/selftests/test-drm_format.c b/drivers/gpu/drm/selftests/test-drm_format.c deleted file mode 100644 index c5e212afa27a..000000000000 --- a/drivers/gpu/drm/selftests/test-drm_format.c +++ /dev/null @@ -1,280 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 -/* - * Test cases for the drm_format functions - */ - -#define pr_fmt(fmt) "drm_format: " fmt - -#include -#include - -#include - -#include "test-drm_modeset_common.h" - -int igt_check_drm_format_block_width(void *ignored) -{ - const struct drm_format_info *info = NULL; - - /* Test invalid arguments */ - FAIL_ON(drm_format_info_block_width(info, 0) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - FAIL_ON(drm_format_info_block_width(info, 1) != 0); - - /* Test 1 plane format */ - info = drm_format_info(DRM_FORMAT_XRGB4444); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 1); - FAIL_ON(drm_format_info_block_width(info, 1) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - /* Test 2 planes format */ - info = drm_format_info(DRM_FORMAT_NV12); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 1); - FAIL_ON(drm_format_info_block_width(info, 1) != 1); - FAIL_ON(drm_format_info_block_width(info, 2) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - /* Test 3 planes format */ - info = drm_format_info(DRM_FORMAT_YUV422); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 1); - FAIL_ON(drm_format_info_block_width(info, 1) != 1); - FAIL_ON(drm_format_info_block_width(info, 2) != 1); - FAIL_ON(drm_format_info_block_width(info, 3) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - /* Test a tiled format */ - info = drm_format_info(DRM_FORMAT_X0L0); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_width(info, 0) != 2); - FAIL_ON(drm_format_info_block_width(info, 1) != 0); - FAIL_ON(drm_format_info_block_width(info, -1) != 0); - - return 0; -} - -int igt_check_drm_format_block_height(void *ignored) -{ - const struct drm_format_info *info = NULL; - - /* Test invalid arguments */ - FAIL_ON(drm_format_info_block_height(info, 0) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - FAIL_ON(drm_format_info_block_height(info, 1) != 0); - - /* Test 1 plane format */ - info = drm_format_info(DRM_FORMAT_XRGB4444); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 1); - FAIL_ON(drm_format_info_block_height(info, 1) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - /* Test 2 planes format */ - info = drm_format_info(DRM_FORMAT_NV12); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 1); - FAIL_ON(drm_format_info_block_height(info, 1) != 1); - FAIL_ON(drm_format_info_block_height(info, 2) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - /* Test 3 planes format */ - info = drm_format_info(DRM_FORMAT_YUV422); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 1); - FAIL_ON(drm_format_info_block_height(info, 1) != 1); - FAIL_ON(drm_format_info_block_height(info, 2) != 1); - FAIL_ON(drm_format_info_block_height(info, 3) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - /* Test a tiled format */ - info = drm_format_info(DRM_FORMAT_X0L0); - FAIL_ON(!info); - FAIL_ON(drm_format_info_block_height(info, 0) != 2); - FAIL_ON(drm_format_info_block_height(info, 1) != 0); - FAIL_ON(drm_format_info_block_height(info, -1) != 0); - - return 0; -} - -int igt_check_drm_format_min_pitch(void *ignored) -{ - const struct drm_format_info *info = NULL; - - /* Test invalid arguments */ - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - /* Test 1 plane 8 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_RGB332); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) != - (uint64_t)(UINT_MAX - 1)); - - /* Test 1 plane 16 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_XRGB4444); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX * 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) != - (uint64_t)(UINT_MAX - 1) * 2); - - /* Test 1 plane 24 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_RGB888); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 3); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 6); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 3072); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 5760); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 12288); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2013); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX * 3); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) != - (uint64_t)(UINT_MAX - 1) * 3); - - /* Test 1 plane 32 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_ABGR8888); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 8); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 2560); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 7680); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 16384); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 2684); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX * 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) != - (uint64_t)(UINT_MAX - 1) * 4); - - /* Test 2 planes format */ - info = drm_format_info(DRM_FORMAT_NV12); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671); - FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 672); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX); - FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) != - (uint64_t)UINT_MAX + 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1)) != - (uint64_t)(UINT_MAX - 1)); - FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2) != - (uint64_t)(UINT_MAX - 1)); - - /* Test 3 planes 8 bits per pixel format */ - info = drm_format_info(DRM_FORMAT_YUV422); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 2, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 3, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 1, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 2, 1) != 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 1, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 2, 2) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 640); - FAIL_ON(drm_format_info_min_pitch(info, 1, 320) != 320); - FAIL_ON(drm_format_info_min_pitch(info, 2, 320) != 320); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 1024); - FAIL_ON(drm_format_info_min_pitch(info, 1, 512) != 512); - FAIL_ON(drm_format_info_min_pitch(info, 2, 512) != 512); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 1920); - FAIL_ON(drm_format_info_min_pitch(info, 1, 960) != 960); - FAIL_ON(drm_format_info_min_pitch(info, 2, 960) != 960); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 4096); - FAIL_ON(drm_format_info_min_pitch(info, 1, 2048) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 2, 2048) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 671); - FAIL_ON(drm_format_info_min_pitch(info, 1, 336) != 336); - FAIL_ON(drm_format_info_min_pitch(info, 2, 336) != 336); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX); - FAIL_ON(drm_format_info_min_pitch(info, 1, UINT_MAX / 2 + 1) != - (uint64_t)UINT_MAX / 2 + 1); - FAIL_ON(drm_format_info_min_pitch(info, 2, UINT_MAX / 2 + 1) != - (uint64_t)UINT_MAX / 2 + 1); - FAIL_ON(drm_format_info_min_pitch(info, 0, (UINT_MAX - 1) / 2) != - (uint64_t)(UINT_MAX - 1) / 2); - FAIL_ON(drm_format_info_min_pitch(info, 1, (UINT_MAX - 1) / 2) != - (uint64_t)(UINT_MAX - 1) / 2); - FAIL_ON(drm_format_info_min_pitch(info, 2, (UINT_MAX - 1) / 2) != - (uint64_t)(UINT_MAX - 1) / 2); - - /* Test tiled format */ - info = drm_format_info(DRM_FORMAT_X0L2); - FAIL_ON(!info); - FAIL_ON(drm_format_info_min_pitch(info, 0, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, -1, 0) != 0); - FAIL_ON(drm_format_info_min_pitch(info, 1, 0) != 0); - - FAIL_ON(drm_format_info_min_pitch(info, 0, 1) != 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, 2) != 4); - FAIL_ON(drm_format_info_min_pitch(info, 0, 640) != 1280); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1024) != 2048); - FAIL_ON(drm_format_info_min_pitch(info, 0, 1920) != 3840); - FAIL_ON(drm_format_info_min_pitch(info, 0, 4096) != 8192); - FAIL_ON(drm_format_info_min_pitch(info, 0, 671) != 1342); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX) != - (uint64_t)UINT_MAX * 2); - FAIL_ON(drm_format_info_min_pitch(info, 0, UINT_MAX - 1) != - (uint64_t)(UINT_MAX - 1) * 2); - - return 0; -} diff --git a/drivers/gpu/drm/selftests/test-drm_modeset_common.h b/drivers/gpu/drm/selftests/test-drm_modeset_common.h index 8c76f09c12d1..fb2b8fbd7566 100644 --- a/drivers/gpu/drm/selftests/test-drm_modeset_common.h +++ b/drivers/gpu/drm/selftests/test-drm_modeset_common.h @@ -14,9 +14,6 @@ #define FAIL_ON(x) FAIL((x), "%s", "FAIL_ON(" __stringify(x) ")\n") int igt_check_plane_state(void *ignored); -int igt_check_drm_format_block_width(void *ignored); -int igt_check_drm_format_block_height(void *ignored); -int igt_check_drm_format_min_pitch(void *ignored); int igt_check_drm_framebuffer_create(void *ignored); int igt_damage_iter_no_damage(void *ignored); int igt_damage_iter_no_damage_fractional_src(void *ignored); diff --git a/include/drm/drm_fourcc.h b/include/drm/drm_fourcc.h index 7cc7b99a6569..8ca45b2be9ca 100644 --- a/include/drm/drm_fourcc.h +++ b/include/drm/drm_fourcc.h @@ -52,91 +52,6 @@ struct drm_mode_fb_cmd2; struct image_format_info; /** - * struct drm_format_info - information about a DRM format - */ -struct drm_format_info { - /** @format: 4CC format identifier (DRM_FORMAT_*) */ - u32 format; - - /** - * @depth: - * - * Color depth (number of bits per pixel excluding padding bits), - * valid for a subset of RGB formats only. This is a legacy field, do - * not use in new code and set to 0 for new formats. - */ - u8 depth; - - /** @num_planes: Number of color planes (1 to 3) */ - u8 num_planes; - - union { - /** - * @cpp: - * - * Number of bytes per pixel (per plane), this is aliased with - * @char_per_block. It is deprecated in favour of using the - * triplet @char_per_block, @block_w, @block_h for better - * describing the pixel format. - */ - u8 cpp[3]; - - /** - * @char_per_block: - * - * Number of bytes per block (per plane), where blocks are - * defined as a rectangle of pixels which are stored next to - * each other in a byte aligned memory region. Together with - * @block_w and @block_h this is used to properly describe tiles - * in tiled formats or to describe groups of pixels in packed - * formats for which the memory needed for a single pixel is not - * byte aligned. - * - * @cpp has been kept for historical reasons because there are - * a lot of places in drivers where it's used. In drm core for - * generic code paths the preferred way is to use - * @char_per_block, drm_format_info_block_width() and - * drm_format_info_block_height() which allows handling both - * block and non-block formats in the same way. - * - * For formats that are intended to be used only with non-linear - * modifiers both @cpp and @char_per_block must be 0 in the - * generic format table. Drivers could supply accurate - * information from their drm_mode_config.get_format_info hook - * if they want the core to be validating the pitch. - */ - u8 char_per_block[3]; - }; - - /** - * @block_w: - * - * Block width in pixels, this is intended to be accessed through - * drm_format_info_block_width() - */ - u8 block_w[3]; - - /** - * @block_h: - * - * Block height in pixels, this is intended to be accessed through - * drm_format_info_block_height() - */ - u8 block_h[3]; - - /** @hsub: Horizontal chroma subsampling factor */ - u8 hsub; - /** @vsub: Vertical chroma subsampling factor */ - u8 vsub; - - /** @has_alpha: Does the format embeds an alpha component? */ - bool has_alpha; - - /** @is_yuv: Is it a YUV format? */ - bool is_yuv; -}; - -/** * struct drm_format_name_buf - name of a DRM format * @str: string buffer containing the format name */ @@ -144,143 +59,12 @@ struct drm_format_name_buf { char str[32]; }; -/** - * drm_format_info_is_yuv_packed - check that the format info matches a YUV - * format with data laid in a single plane - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a packed YUV format. - */ -static inline bool -drm_format_info_is_yuv_packed(const struct drm_format_info *info) -{ - return info->is_yuv && info->num_planes == 1; -} - -/** - * drm_format_info_is_yuv_semiplanar - check that the format info matches a YUV - * format with data laid in two planes (luminance and chrominance) - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a semiplanar YUV format. - */ -static inline bool -drm_format_info_is_yuv_semiplanar(const struct drm_format_info *info) -{ - return info->is_yuv && info->num_planes == 2; -} - -/** - * drm_format_info_is_yuv_planar - check that the format info matches a YUV - * format with data laid in three planes (one for each YUV component) - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a planar YUV format. - */ -static inline bool -drm_format_info_is_yuv_planar(const struct drm_format_info *info) -{ - return info->is_yuv && info->num_planes == 3; -} - -/** - * drm_format_info_is_yuv_sampling_410 - check that the format info matches a - * YUV format with 4:1:0 sub-sampling - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a YUV format with 4:1:0 - * sub-sampling. - */ -static inline bool -drm_format_info_is_yuv_sampling_410(const struct drm_format_info *info) -{ - return info->is_yuv && info->hsub == 4 && info->vsub == 4; -} - -/** - * drm_format_info_is_yuv_sampling_411 - check that the format info matches a - * YUV format with 4:1:1 sub-sampling - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a YUV format with 4:1:1 - * sub-sampling. - */ -static inline bool -drm_format_info_is_yuv_sampling_411(const struct drm_format_info *info) -{ - return info->is_yuv && info->hsub == 4 && info->vsub == 1; -} - -/** - * drm_format_info_is_yuv_sampling_420 - check that the format info matches a - * YUV format with 4:2:0 sub-sampling - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a YUV format with 4:2:0 - * sub-sampling. - */ -static inline bool -drm_format_info_is_yuv_sampling_420(const struct drm_format_info *info) -{ - return info->is_yuv && info->hsub == 2 && info->vsub == 2; -} - -/** - * drm_format_info_is_yuv_sampling_422 - check that the format info matches a - * YUV format with 4:2:2 sub-sampling - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a YUV format with 4:2:2 - * sub-sampling. - */ -static inline bool -drm_format_info_is_yuv_sampling_422(const struct drm_format_info *info) -{ - return info->is_yuv && info->hsub == 2 && info->vsub == 1; -} - -/** - * drm_format_info_is_yuv_sampling_444 - check that the format info matches a - * YUV format with 4:4:4 sub-sampling - * @info: format info - * - * Returns: - * A boolean indicating whether the format info matches a YUV format with 4:4:4 - * sub-sampling. - */ -static inline bool -drm_format_info_is_yuv_sampling_444(const struct drm_format_info *info) -{ - return info->is_yuv && info->hsub == 1 && info->vsub == 1; -} - -const struct drm_format_info *__drm_format_info(u32 format); -const struct drm_format_info *drm_format_info(u32 format); - const struct image_format_info * drm_get_format_info(struct drm_device *dev, const struct drm_mode_fb_cmd2 *mode_cmd); uint32_t drm_mode_legacy_fb_format(uint32_t bpp, uint32_t depth); uint32_t drm_driver_legacy_fb_format(struct drm_device *dev, uint32_t bpp, uint32_t depth); -int drm_format_plane_cpp(const struct drm_format_info *info, int plane); -int drm_format_plane_width(int width, const struct drm_format_info *info, - int plane); -int drm_format_plane_height(int height, const struct drm_format_info *info, - int plane); -unsigned int drm_format_info_block_width(const struct drm_format_info *info, - int plane); -unsigned int drm_format_info_block_height(const struct drm_format_info *info, - int plane); -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); #endif /* __DRM_FOURCC_H__ */ From patchwork Tue Mar 19 21:57:23 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860471 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B930B6C2 for ; Tue, 19 Mar 2019 21:58:26 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9E37D2965F for ; Tue, 19 Mar 2019 21:58:26 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9293629912; Tue, 19 Mar 2019 21:58:26 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id EBD4F29911 for ; Tue, 19 Mar 2019 21:58:25 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 826E089B68; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by gabe.freedesktop.org (Postfix) with ESMTPS id 3B73389C2A for ; Tue, 19 Mar 2019 21:58:21 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 55FF2E0007; Tue, 19 Mar 2019 21:58:15 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 18/20] lib: image-formats: Add v4l2 formats support Date: Tue, 19 Mar 2019 22:57:23 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP V4L2 uses different fourcc's than DRM, and has a different set of formats. For now, let's add the v4l2 fourcc's for the already existing formats. Signed-off-by: Maxime Ripard --- include/linux/image-formats.h | 9 +++++- lib/image-formats.c | 67 ++++++++++++++++++++++++++++++++++++- 2 files changed, 76 insertions(+) diff --git a/include/linux/image-formats.h b/include/linux/image-formats.h index 53fd73a71b3d..fbc3a4501ebd 100644 --- a/include/linux/image-formats.h +++ b/include/linux/image-formats.h @@ -26,6 +26,13 @@ struct image_format_info { }; /** + * @v4l2_fmt: + * + * V4L2 4CC format identifier (V4L2_PIX_FMT_*) + */ + u32 v4l2_fmt; + + /** * @depth: * * Color depth (number of bits per pixel excluding padding bits), @@ -222,6 +229,8 @@ image_format_info_is_yuv_sampling_444(const struct image_format_info *info) const struct image_format_info *__image_format_drm_lookup(u32 drm); const struct image_format_info *image_format_drm_lookup(u32 drm); +const struct image_format_info *__image_format_v4l2_lookup(u32 v4l2); +const struct image_format_info *image_format_v4l2_lookup(u32 v4l2); unsigned int image_format_plane_cpp(const struct image_format_info *format, int plane); unsigned int image_format_plane_width(int width, diff --git a/lib/image-formats.c b/lib/image-formats.c index 9b9a73220c5d..39f1d38ae861 100644 --- a/lib/image-formats.c +++ b/lib/image-formats.c @@ -8,6 +8,7 @@ static const struct image_format_info formats[] = { { .drm_fmt = DRM_FORMAT_C8, + .v4l2_fmt = V4L2_PIX_FMT_GREY, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, @@ -15,6 +16,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_RGB332, + .v4l2_fmt = V4L2_PIX_FMT_RGB332, .depth = 8, .num_planes = 1, .cpp = { 1, 0, 0 }, @@ -29,6 +31,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_XRGB4444, + .v4l2_fmt = V4L2_PIX_FMT_XRGB444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -57,6 +60,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_ARGB4444, + .v4l2_fmt = V4L2_PIX_FMT_ARGB444, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -89,6 +93,7 @@ static const struct image_format_info formats[] = { .has_alpha = true, }, { .drm_fmt = DRM_FORMAT_XRGB1555, + .v4l2_fmt = V4L2_PIX_FMT_XRGB555, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -117,6 +122,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_ARGB1555, + .v4l2_fmt = V4L2_PIX_FMT_ARGB555, .depth = 15, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -149,6 +155,7 @@ static const struct image_format_info formats[] = { .has_alpha = true, }, { .drm_fmt = DRM_FORMAT_RGB565, + .v4l2_fmt = V4L2_PIX_FMT_RGB565, .depth = 16, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -163,6 +170,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_RGB888, + .v4l2_fmt = V4L2_PIX_FMT_RGB24, .depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, @@ -170,6 +178,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_BGR888, + .v4l2_fmt = V4L2_PIX_FMT_BGR24, .depth = 24, .num_planes = 1, .cpp = { 3, 0, 0 }, @@ -177,6 +186,7 @@ static const struct image_format_info formats[] = { .vsub = 1, }, { .drm_fmt = DRM_FORMAT_XRGB8888, + .v4l2_fmt = V4L2_PIX_FMT_XRGB32, .depth = 24, .num_planes = 1, .cpp = { 4, 0, 0 }, @@ -281,6 +291,7 @@ static const struct image_format_info formats[] = { .has_alpha = true, }, { .drm_fmt = DRM_FORMAT_ARGB8888, + .v4l2_fmt = V4L2_PIX_FMT_ARGB32, .depth = 32, .num_planes = 1, .cpp = { 4, 0, 0 }, @@ -361,6 +372,7 @@ static const struct image_format_info formats[] = { .has_alpha = true, }, { .drm_fmt = DRM_FORMAT_YUV410, + .v4l2_fmt = V4L2_PIX_FMT_YUV410, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -369,6 +381,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YVU410, + .v4l2_fmt = V4L2_PIX_FMT_YVU410, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -393,6 +406,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YUV420, + .v4l2_fmt = V4L2_PIX_FMT_YUV420M, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -401,6 +415,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YVU420, + .v4l2_fmt = V4L2_PIX_FMT_YVU420M, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -409,6 +424,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YUV422, + .v4l2_fmt = V4L2_PIX_FMT_YUV422M, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -417,6 +433,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YVU422, + .v4l2_fmt = V4L2_PIX_FMT_YVU422M, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -425,6 +442,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YUV444, + .v4l2_fmt = V4L2_PIX_FMT_YUV444M, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -433,6 +451,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YVU444, + .v4l2_fmt = V4L2_PIX_FMT_YVU444M, .depth = 0, .num_planes = 3, .cpp = { 1, 1, 1 }, @@ -441,6 +460,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_NV12, + .v4l2_fmt = V4L2_PIX_FMT_NV12, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, @@ -449,6 +469,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_NV21, + .v4l2_fmt = V4L2_PIX_FMT_NV21, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, @@ -457,6 +478,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_NV16, + .v4l2_fmt = V4L2_PIX_FMT_NV16, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, @@ -465,6 +487,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_NV61, + .v4l2_fmt = V4L2_PIX_FMT_NV61, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, @@ -473,6 +496,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_NV24, + .v4l2_fmt = V4L2_PIX_FMT_NV24, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, @@ -481,6 +505,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_NV42, + .v4l2_fmt = V4L2_PIX_FMT_NV42, .depth = 0, .num_planes = 2, .cpp = { 1, 2, 0 }, @@ -489,6 +514,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YUYV, + .v4l2_fmt = V4L2_PIX_FMT_YUYV, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -497,6 +523,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_YVYU, + .v4l2_fmt = V4L2_PIX_FMT_YVYU, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -505,6 +532,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_UYVY, + .v4l2_fmt = V4L2_PIX_FMT_UYVY, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -513,6 +541,7 @@ static const struct image_format_info formats[] = { .is_yuv = true, }, { .drm_fmt = DRM_FORMAT_VYUY, + .v4l2_fmt = V4L2_PIX_FMT_VYUY, .depth = 0, .num_planes = 1, .cpp = { 2, 0, 0 }, @@ -632,6 +661,44 @@ const struct image_format_info *image_format_drm_lookup(u32 drm) EXPORT_SYMBOL(image_format_drm_lookup); /** + * __image_format_v4l2_lookup - query information for a given format + * @v4l2: V4L2 fourcc pixel format (V4L2_PIX_FMT_*) + * + * The caller should only pass a supported pixel format to this function. + * + * Returns: + * The instance of struct image_format_info that describes the pixel format, or + * NULL if the format is unsupported. + */ +const struct image_format_info *__image_format_v4l2_lookup(u32 v4l2) +{ + return __image_format_lookup(v4l2_fmt, v4l2); +} +EXPORT_SYMBOL(__image_format_v4l2_lookup); + +/** + * image_format_v4l2_lookup - query information for a given format + * @v4l2: V4L2 fourcc pixel format (V4L2_PIX_FMT_*) + * + * The caller should only pass a supported pixel format to this function. + * Unsupported pixel formats will generate a warning in the kernel log. + * + * Returns: + * The instance of struct image_format_info that describes the pixel format, or + * NULL if the format is unsupported. + */ +const struct image_format_info *image_format_v4l2_lookup(u32 v4l2) +{ + const struct image_format_info *format; + + format = __image_format_v4l2_lookup(v4l2); + + WARN_ON(!format); + return format; +} +EXPORT_SYMBOL(image_format_v4l2_lookup); + +/** * image_format_plane_cpp - determine the bytes per pixel value * @format: pointer to the image_format * @plane: plane index From patchwork Tue Mar 19 21:57:24 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860473 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id F3DEC13B5 for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DCA002936B for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D133929913; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 775172936B for ; Tue, 19 Mar 2019 21:58:27 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id D0CB189C2A; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay9-d.mail.gandi.net (relay9-d.mail.gandi.net [217.70.183.199]) by gabe.freedesktop.org (Postfix) with ESMTPS id 834D789C2A for ; Tue, 19 Mar 2019 21:58:22 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay9-d.mail.gandi.net (Postfix) with ESMTPSA id 3A4EAFF80C; Tue, 19 Mar 2019 21:58:19 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 19/20] lib: image-formats: Add more functions Date: Tue, 19 Mar 2019 22:57:24 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP V4L2 drivers typically need a few more helpers compared to DRM drivers, so let's add them. Signed-off-by: Maxime Ripard --- include/linux/image-formats.h | 4 +++- lib/image-formats.c | 42 ++++++++++++++++++++++++++++++++++++- 2 files changed, 46 insertions(+) diff --git a/include/linux/image-formats.h b/include/linux/image-formats.h index fbc3a4501ebd..f1d4a2a03cc0 100644 --- a/include/linux/image-formats.h +++ b/include/linux/image-formats.h @@ -236,9 +236,13 @@ unsigned int image_format_plane_cpp(const struct image_format_info *format, unsigned int image_format_plane_width(int width, const struct image_format_info *format, int plane); +unsigned int image_format_plane_stride(const struct image_format_info *format, + int width, int plane); unsigned int image_format_plane_height(int height, const struct image_format_info *format, int plane); +unsigned int image_format_plane_size(const struct image_format_info *format, + int width, int height, int plane); unsigned int image_format_block_width(const struct image_format_info *format, int plane); unsigned int image_format_block_height(const struct image_format_info *format, diff --git a/lib/image-formats.c b/lib/image-formats.c index 39f1d38ae861..c4e213a89edb 100644 --- a/lib/image-formats.c +++ b/lib/image-formats.c @@ -740,6 +740,26 @@ unsigned int image_format_plane_width(int width, EXPORT_SYMBOL(image_format_plane_width); /** + * image_format_plane_stride - determine the stride value + * @format: pointer to the image_format + * @width: plane width + * @plane: plane index + * + * Returns: + * The bytes per pixel value for the specified plane. + */ +unsigned int image_format_plane_stride(const struct image_format_info *format, + unsigned int width, int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + return image_format_plane_width(width, format, plane) * + image_format_plane_cpp(format, plane); +} +EXPORT_SYMBOL(image_format_plane_stride); + +/** * image_format_plane_height - height of the plane given the first plane * @format: pointer to the image_format * @height: height of the first plane @@ -763,6 +783,28 @@ unsigned int image_format_plane_height(int height, EXPORT_SYMBOL(image_format_plane_height); /** + * image_format_plane_size - determine the size value + * @format: pointer to the image_format + * @width: plane width + * @height: plane width + * @plane: plane index + * + * Returns: + * The size of the plane buffer. + */ +unsigned int image_format_plane_size(const struct image_format_info *format, + unsigned int width, unsigned int height, + int plane) +{ + if (!format || plane >= format->num_planes) + return 0; + + return image_format_plane_stride(format, width, plane) * + image_format_plane_height(format, height, plane); +} +EXPORT_SYMBOL(image_format_plane_size); + +/** * image_format_block_width - width in pixels of block. * @format: pointer to the image_format * @plane: plane index From patchwork Tue Mar 19 21:57:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Maxime Ripard X-Patchwork-Id: 10860475 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 171D013B5 for ; Tue, 19 Mar 2019 21:58:30 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id F17242894C for ; Tue, 19 Mar 2019 21:58:29 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E55AC29911; Tue, 19 Mar 2019 21:58:29 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 7AAA32894C for ; Tue, 19 Mar 2019 21:58:29 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 5BC6889C49; Tue, 19 Mar 2019 21:58:28 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from relay6-d.mail.gandi.net (relay6-d.mail.gandi.net [217.70.183.198]) by gabe.freedesktop.org (Postfix) with ESMTPS id 08E8B89C3B for ; Tue, 19 Mar 2019 21:58:24 +0000 (UTC) X-Originating-IP: 90.89.68.76 Received: from localhost (lfbn-1-10718-76.w90-89.abo.wanadoo.fr [90.89.68.76]) (Authenticated sender: maxime.ripard@bootlin.com) by relay6-d.mail.gandi.net (Postfix) with ESMTPSA id ACC3FC0008; Tue, 19 Mar 2019 21:58:21 +0000 (UTC) From: Maxime Ripard To: Daniel Vetter , David Airlie , Maarten Lankhorst , Sean Paul , Maxime Ripard , Mauro Carvalho Chehab Subject: [RFC PATCH 20/20] media: sun6i: Convert to the image format API Date: Tue, 19 Mar 2019 22:57:25 +0100 Message-Id: X-Mailer: git-send-email 2.20.1 In-Reply-To: References: MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Sakari Ailus , linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Paul Kocialkowski , Hans Verkuil , Laurent Pinchart , Thomas Petazzoni , linux-media@vger.kernel.org Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP The image format API allows us to remove some of the computation we need to handle the various video formats. Signed-off-by: Maxime Ripard --- drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c | 88 +++------------ drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h | 46 +-------- 2 files changed, 22 insertions(+), 112 deletions(-) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c index 6950585edb5a..d4693efb9e02 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.c @@ -466,72 +466,27 @@ static void sun6i_csi_set_format(struct sun6i_csi_dev *sdev) static void sun6i_csi_set_window(struct sun6i_csi_dev *sdev) { struct sun6i_csi_config *config = &sdev->csi.config; - u32 bytesperline_y; - u32 bytesperline_c; + const struct image_format_info *info = + image_format_v4l2_lookup(config->pixelformat); int *planar_offset = sdev->planar_offset; - u32 width = config->width; - u32 height = config->height; - u32 hor_len = width; + u32 bytesperline_y = image_format_plane_stride(info, config->width, 0); + u32 bytesperline_c = image_format_plane_stride(info, config->width, 1); + unsigned int i; - switch (config->pixelformat) { - case V4L2_PIX_FMT_YUYV: - case V4L2_PIX_FMT_YVYU: - case V4L2_PIX_FMT_UYVY: - case V4L2_PIX_FMT_VYUY: - dev_dbg(sdev->dev, - "Horizontal length should be 2 times of width for packed YUV formats!\n"); - hor_len = width * 2; - break; - default: - break; + offset = 0; + for (i = 0; i < info->num_planes; i++) { + planar_offset[i] = offset; + + offset += info_format_plane_size(info, config->width, + config->height, i); } regmap_write(sdev->regmap, CSI_CH_HSIZE_REG, - CSI_CH_HSIZE_HOR_LEN(hor_len) | + CSI_CH_HSIZE_HOR_LEN(bytesperline_c) | CSI_CH_HSIZE_HOR_START(0)); regmap_write(sdev->regmap, CSI_CH_VSIZE_REG, - CSI_CH_VSIZE_VER_LEN(height) | + CSI_CH_VSIZE_VER_LEN(config->height) | CSI_CH_VSIZE_VER_START(0)); - - planar_offset[0] = 0; - switch (config->pixelformat) { - case V4L2_PIX_FMT_HM12: - case V4L2_PIX_FMT_NV12: - case V4L2_PIX_FMT_NV21: - case V4L2_PIX_FMT_NV16: - case V4L2_PIX_FMT_NV61: - bytesperline_y = width; - bytesperline_c = width; - planar_offset[1] = bytesperline_y * height; - planar_offset[2] = -1; - break; - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_YVU420: - bytesperline_y = width; - bytesperline_c = width / 2; - planar_offset[1] = bytesperline_y * height; - planar_offset[2] = planar_offset[1] + - bytesperline_c * height / 2; - break; - case V4L2_PIX_FMT_YUV422P: - bytesperline_y = width; - bytesperline_c = width / 2; - planar_offset[1] = bytesperline_y * height; - planar_offset[2] = planar_offset[1] + - bytesperline_c * height; - break; - default: /* raw */ - dev_dbg(sdev->dev, - "Calculating pixelformat(0x%x)'s bytesperline as a packed format\n", - config->pixelformat); - bytesperline_y = (sun6i_csi_get_bpp(config->pixelformat) * - config->width) / 8; - bytesperline_c = 0; - planar_offset[1] = -1; - planar_offset[2] = -1; - break; - } - regmap_write(sdev->regmap, CSI_CH_BUF_LEN_REG, CSI_CH_BUF_LEN_BUF_LEN_C(bytesperline_c) | CSI_CH_BUF_LEN_BUF_LEN_Y(bytesperline_y)); @@ -557,15 +512,16 @@ int sun6i_csi_update_config(struct sun6i_csi *csi, void sun6i_csi_update_buf_addr(struct sun6i_csi *csi, dma_addr_t addr) { struct sun6i_csi_dev *sdev = sun6i_csi_to_dev(csi); + struct sun6i_csi_config *config = &sdev->csi.config; + const struct image_format_info *info = + image_format_v4l2_lookup(config->pixelformat); + unsigned int i; + + for (i = 0; i < info->num_planes; i++) { + regmap_write(sdev->regmap, CSI_CH_BUF_REG(i, 0), + (addr + sdev->planar_offset[i]) >> 2); - regmap_write(sdev->regmap, CSI_CH_F0_BUFA_REG, - (addr + sdev->planar_offset[0]) >> 2); - if (sdev->planar_offset[1] != -1) - regmap_write(sdev->regmap, CSI_CH_F1_BUFA_REG, - (addr + sdev->planar_offset[1]) >> 2); - if (sdev->planar_offset[2] != -1) - regmap_write(sdev->regmap, CSI_CH_F2_BUFA_REG, - (addr + sdev->planar_offset[2]) >> 2); + } } void sun6i_csi_set_stream(struct sun6i_csi *csi, bool enable) diff --git a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h index 0bb000712c33..3c57ec89b108 100644 --- a/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h +++ b/drivers/media/platform/sunxi/sun6i-csi/sun6i_csi.h @@ -86,50 +86,4 @@ void sun6i_csi_update_buf_addr(struct sun6i_csi *csi, dma_addr_t addr); */ void sun6i_csi_set_stream(struct sun6i_csi *csi, bool enable); -/* get bpp form v4l2 pixformat */ -static inline int sun6i_csi_get_bpp(unsigned int pixformat) -{ - switch (pixformat) { - case V4L2_PIX_FMT_SBGGR8: - case V4L2_PIX_FMT_SGBRG8: - case V4L2_PIX_FMT_SGRBG8: - case V4L2_PIX_FMT_SRGGB8: - return 8; - case V4L2_PIX_FMT_SBGGR10: - case V4L2_PIX_FMT_SGBRG10: - case V4L2_PIX_FMT_SGRBG10: - case V4L2_PIX_FMT_SRGGB10: - return 10; - case V4L2_PIX_FMT_SBGGR12: - case V4L2_PIX_FMT_SGBRG12: - case V4L2_PIX_FMT_SGRBG12: - case V4L2_PIX_FMT_SRGGB12: - case V4L2_PIX_FMT_HM12: - case V4L2_PIX_FMT_NV12: - case V4L2_PIX_FMT_NV21: - case V4L2_PIX_FMT_YUV420: - case V4L2_PIX_FMT_YVU420: - return 12; - case V4L2_PIX_FMT_YUYV: - case V4L2_PIX_FMT_YVYU: - case V4L2_PIX_FMT_UYVY: - case V4L2_PIX_FMT_VYUY: - case V4L2_PIX_FMT_NV16: - case V4L2_PIX_FMT_NV61: - case V4L2_PIX_FMT_YUV422P: - return 16; - case V4L2_PIX_FMT_RGB24: - case V4L2_PIX_FMT_BGR24: - return 24; - case V4L2_PIX_FMT_RGB32: - case V4L2_PIX_FMT_BGR32: - return 32; - default: - WARN(1, "Unsupported pixformat: 0x%x\n", pixformat); - break; - } - - return 0; -} - #endif /* __SUN6I_CSI_H__ */