From patchwork Mon Jan 30 13:57:58 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 648835 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 941B8C54EED for ; Mon, 30 Jan 2023 13:58:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236757AbjA3N6e (ORCPT ); Mon, 30 Jan 2023 08:58:34 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38840 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234538AbjA3N6c (ORCPT ); Mon, 30 Jan 2023 08:58:32 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 9B8C43A869; Mon, 30 Jan 2023 05:58:13 -0800 (PST) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:e655:2335:9172:6e39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id A18BB6602E28; Mon, 30 Jan 2023 13:58:11 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1675087092; bh=WeghlRFY57k/XRhbZSebcHWkeNrEWgqxdzHNHRFL4B0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=hGHd/1fIa/fiHQw+gZPozUKn1REan6qdtb2P6kIlNO4kg+or97jIq2XqgEUwU975u XEdyIDwriPgCR3LD2apWphe27j+VO3ltuVg+lxcA2aI+gkpP2187UK29+Mh/eTTrM6 t2CPcDF6Yxb2+vm58ObPFWOVkyJBenqtaXQ4lsTvu1Y9SjdKeKho+n2a8tu5G5TuLb /ABGmjrSfiOJkJd6uV3eLVFKlAiyIWsE4d58j3AHTugp1LaCXyYEdf5y6bqk2WU08g +HuHpVhNRrWP7Lmph1kBwARKm8K8ULuKVEIAuBFumRk8Ax1g+31VFuh2gva4L+scvK 7zqI/LGJDUj8w== From: Benjamin Gaignard To: ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.co.uk Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v6 1/5] media: verisilicon: Do not set context src/dst formats in reset functions Date: Mon, 30 Jan 2023 14:57:58 +0100 Message-Id: <20230130135802.744743-2-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130135802.744743-1-benjamin.gaignard@collabora.com> References: <20230130135802.744743-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Setting context source and destination formats should only be done in hantro_set_fmt_out() and hantro_set_fmt_cap() after check that the targeted queue is not busy. Remove these calls from hantro_reset_encoded_fmt() and hantro_reset_raw_fmt() to clean the driver. Fixes: dc39473d0340 ("media: hantro: imx8m: Enable 10bit decoding") Signed-off-by: Benjamin Gaignard --- drivers/media/platform/verisilicon/hantro_v4l2.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 2c7a805289e7..33cb865238de 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -381,13 +381,10 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) vpu_fmt = hantro_get_default_fmt(ctx, true); - if (ctx->is_encoder) { - ctx->vpu_dst_fmt = vpu_fmt; + if (ctx->is_encoder) fmt = &ctx->dst_fmt; - } else { - ctx->vpu_src_fmt = vpu_fmt; + else fmt = &ctx->src_fmt; - } hantro_reset_fmt(fmt, vpu_fmt); fmt->width = vpu_fmt->frmsize.min_width; @@ -407,11 +404,9 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx) raw_vpu_fmt = hantro_get_default_fmt(ctx, false); if (ctx->is_encoder) { - ctx->vpu_src_fmt = raw_vpu_fmt; raw_fmt = &ctx->src_fmt; encoded_fmt = &ctx->dst_fmt; } else { - ctx->vpu_dst_fmt = raw_vpu_fmt; raw_fmt = &ctx->dst_fmt; encoded_fmt = &ctx->src_fmt; } From patchwork Mon Jan 30 13:57:59 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 648834 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 5E171C54EAA for ; Mon, 30 Jan 2023 13:58:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236767AbjA3N6g (ORCPT ); Mon, 30 Jan 2023 08:58:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38894 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236768AbjA3N6e (ORCPT ); Mon, 30 Jan 2023 08:58:34 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D935D39CC6; Mon, 30 Jan 2023 05:58:15 -0800 (PST) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:e655:2335:9172:6e39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 24DD66602EAD; Mon, 30 Jan 2023 13:58:12 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1675087092; bh=9xkh7Mz6B7KCpRaWkFO7AHPjQWKFgdQpvDXYN313zu0=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=cnTtZu1hrqPWEMA3JwJqr9UaY0ZzHDvJMFG2FJf7q/36pTxODy+Lrk/qMxbD+gacX RlFDGf6NVTuzRv7WgQRvyZAhN5EhJszH0Vyu146xLTwcDG7KQxy31or25pJNcNWysJ D05ME96oZD2YVvV+cZa9aRtTXyKaoYCzVewZa8Yt+A+QU8qzctIB/Icd78LYEDNviI /mAxVIlYjyE0fhcSryqhpOIptPT3y4vW8gPrltMzwiwMgwEh+Cxo4GRP1/HihD3z6Y LhJfgUhBQ9TYrSsG4OIaYCKaMq17EATBBvXXPtWyH2Zr0GtObJL1r0NJrs67iSoIaO wD8BGWv/gLo4g== From: Benjamin Gaignard To: ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.co.uk Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v6 2/5] media: verisilicon: Do not use ctx fields as format storage when resetting Date: Mon, 30 Jan 2023 14:57:59 +0100 Message-Id: <20230130135802.744743-3-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130135802.744743-1-benjamin.gaignard@collabora.com> References: <20230130135802.744743-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org Source and destination pixel formats fields of context structure should not be used as storage when resetting the format. Use local variables instead and let hantro_set_fmt_out() and hantro_set_fmt_cap() set them correctly later. Fixes: dc39473d0340 ("media: hantro: imx8m: Enable 10bit decoding") Signed-off-by: Benjamin Gaignard --- .../media/platform/verisilicon/hantro_v4l2.c | 40 +++++++++---------- 1 file changed, 18 insertions(+), 22 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index 33cb865238de..e60151a8a401 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -377,47 +377,43 @@ static void hantro_reset_encoded_fmt(struct hantro_ctx *ctx) { const struct hantro_fmt *vpu_fmt; - struct v4l2_pix_format_mplane *fmt; + struct v4l2_pix_format_mplane fmt; vpu_fmt = hantro_get_default_fmt(ctx, true); + if (!vpu_fmt) + return; + hantro_reset_fmt(&fmt, vpu_fmt); + fmt.width = vpu_fmt->frmsize.min_width; + fmt.height = vpu_fmt->frmsize.min_height; if (ctx->is_encoder) - fmt = &ctx->dst_fmt; - else - fmt = &ctx->src_fmt; - - hantro_reset_fmt(fmt, vpu_fmt); - fmt->width = vpu_fmt->frmsize.min_width; - fmt->height = vpu_fmt->frmsize.min_height; - if (ctx->is_encoder) - hantro_set_fmt_cap(ctx, fmt); + hantro_set_fmt_cap(ctx, &fmt); else - hantro_set_fmt_out(ctx, fmt); + hantro_set_fmt_out(ctx, &fmt); } static void hantro_reset_raw_fmt(struct hantro_ctx *ctx) { const struct hantro_fmt *raw_vpu_fmt; - struct v4l2_pix_format_mplane *raw_fmt, *encoded_fmt; + struct v4l2_pix_format_mplane raw_fmt, *encoded_fmt; raw_vpu_fmt = hantro_get_default_fmt(ctx, false); + if (!raw_vpu_fmt) + return; - if (ctx->is_encoder) { - raw_fmt = &ctx->src_fmt; + if (ctx->is_encoder) encoded_fmt = &ctx->dst_fmt; - } else { - raw_fmt = &ctx->dst_fmt; + else encoded_fmt = &ctx->src_fmt; - } - hantro_reset_fmt(raw_fmt, raw_vpu_fmt); - raw_fmt->width = encoded_fmt->width; - raw_fmt->height = encoded_fmt->height; + hantro_reset_fmt(&raw_fmt, raw_vpu_fmt); + raw_fmt.width = encoded_fmt->width; + raw_fmt.height = encoded_fmt->height; if (ctx->is_encoder) - hantro_set_fmt_out(ctx, raw_fmt); + hantro_set_fmt_out(ctx, &raw_fmt); else - hantro_set_fmt_cap(ctx, raw_fmt); + hantro_set_fmt_cap(ctx, &raw_fmt); } void hantro_reset_fmts(struct hantro_ctx *ctx) From patchwork Mon Jan 30 13:58:00 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 649098 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 230CCC636CD for ; Mon, 30 Jan 2023 13:58:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236787AbjA3N6f (ORCPT ); Mon, 30 Jan 2023 08:58:35 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38880 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236722AbjA3N6e (ORCPT ); Mon, 30 Jan 2023 08:58:34 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77B3F2799E; Mon, 30 Jan 2023 05:58:15 -0800 (PST) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:e655:2335:9172:6e39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 99C456602ECB; Mon, 30 Jan 2023 13:58:12 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1675087093; bh=C/QAyRDA/waqPf4kFAS8tK6asJ/IhGRhX08Vka5WQCc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=SfUSiJ2wJQ24d6ulRQN2KZk741WuDEwIFzdvGLpIrVhYp0K9qLF3a3YKV+fxA313D 9umQx9ogVFNwH31/1Uh1VVmbwyQICualFayd0be7aPpbtW6EED/+12WNMzVF3R+BRz rhkm0iTWl1bBNf6OMt3E19vu5DM76y2MxuYKUO0yX/dProNS+SxIQsH+BjB59KmqSR j1L0YvApI6cAviPm8YvkwvCkWJTkavUiBwD/GHCSdhfROXL1WrBUlCz/QV0V8QndOs e5LdNh4r6oXwkw1tr1U8eIFZyue8SQv3gXv8K5ucNbv3b6TlLbqmknOBs34Y1JLP3x 4EHxw5Hj8KzJg== From: Benjamin Gaignard To: ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.co.uk Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard Subject: [PATCH v6 3/5] media: verisilicon: Do not set ctx->bit_depth in hantro_try_ctrl() Date: Mon, 30 Jan 2023 14:58:00 +0100 Message-Id: <20230130135802.744743-4-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130135802.744743-1-benjamin.gaignard@collabora.com> References: <20230130135802.744743-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org In hantro_try_ctrl() we should only check the values inside control parameters and not set ctx->bit_depth. That must be done in controls set function. Create a set control function for hevc where ctx->bit_depth is set at the right time. Fixes: dc39473d0340 ("media: hantro: imx8m: Enable 10bit decoding") Signed-off-by: Benjamin Gaignard --- .../media/platform/verisilicon/hantro_drv.c | 27 ++++++++++++++++--- 1 file changed, 24 insertions(+), 3 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index 8cb4a68c9119..715075f15596 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -274,8 +274,6 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl) if (sps->bit_depth_luma_minus8 != 0 && sps->bit_depth_luma_minus8 != 2) /* Only 8-bit and 10-bit are supported */ return -EINVAL; - - ctx->bit_depth = sps->bit_depth_luma_minus8 + 8; } else if (ctrl->id == V4L2_CID_STATELESS_VP9_FRAME) { const struct v4l2_ctrl_vp9_frame *dec_params = ctrl->p_new.p_vp9_frame; @@ -324,6 +322,24 @@ static int hantro_vp9_s_ctrl(struct v4l2_ctrl *ctrl) return 0; } +static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl) +{ + struct hantro_ctx *ctx; + + ctx = container_of(ctrl->handler, + struct hantro_ctx, ctrl_handler); + + switch (ctrl->id) { + case V4L2_CID_STATELESS_HEVC_SPS: + ctx->bit_depth = ctrl->p_new.p_hevc_sps->bit_depth_luma_minus8 + 8; + break; + default: + return -EINVAL; + } + + return 0; +} + static const struct v4l2_ctrl_ops hantro_ctrl_ops = { .try_ctrl = hantro_try_ctrl, }; @@ -336,6 +352,11 @@ static const struct v4l2_ctrl_ops hantro_vp9_ctrl_ops = { .s_ctrl = hantro_vp9_s_ctrl, }; +static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = { + .try_ctrl = hantro_try_ctrl, + .s_ctrl = hantro_hevc_s_ctrl, +}; + #define HANTRO_JPEG_ACTIVE_MARKERS (V4L2_JPEG_ACTIVE_MARKER_APP0 | \ V4L2_JPEG_ACTIVE_MARKER_COM | \ V4L2_JPEG_ACTIVE_MARKER_DQT | \ @@ -470,7 +491,7 @@ static const struct hantro_ctrl controls[] = { .codec = HANTRO_HEVC_DECODER, .cfg = { .id = V4L2_CID_STATELESS_HEVC_SPS, - .ops = &hantro_ctrl_ops, + .ops = &hantro_hevc_ctrl_ops, }, }, { .codec = HANTRO_HEVC_DECODER, From patchwork Mon Jan 30 13:58:01 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 649097 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D2B6C61DA4 for ; Mon, 30 Jan 2023 13:58:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236808AbjA3N6i (ORCPT ); Mon, 30 Jan 2023 08:58:38 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38912 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236773AbjA3N6g (ORCPT ); Mon, 30 Jan 2023 08:58:36 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [46.235.227.172]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77FAF2B600; Mon, 30 Jan 2023 05:58:16 -0800 (PST) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:e655:2335:9172:6e39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 1C14A6602EEA; Mon, 30 Jan 2023 13:58:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1675087093; bh=hF/60MRYbbN9kX2Ov6nveGWMmChcDBlxRYTbNT3U1dU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=P3xuiRZqM1Uds2OoQ5WhKk+Taubq9oJe3xdLqCwnFVQLTTjj7eWiHXlHgaOpsFi+1 uc+Ko3HPM1GFSv+x/SQlkvPp6Qm3slx9fAfAlHP/ElHD3XYNzyjWrJbC7Js+CzMy6Z f+ildvh5maleEPtXCgwz06yQ7BZTO6vnc8xwNLar1+897ipydFnK6JdTXURlD4nDkD ukBaELAMFR8ATFojskaKgHTyMb7UF6I591ljseOCA6NGYcfxS9uMju8MiBfm9BoXK9 519NfToaLg4EOoZKrBL8nhLxetXQ93swbShAARk4BBZfIiWPzIUD5q1tPFBE4CtoxH pvTegi7yzOeHA== From: Benjamin Gaignard To: ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.co.uk Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard , Nicolas Dufresne Subject: [PATCH v6 4/5] media: verisilicon: Do not change context bit depth before validating the format Date: Mon, 30 Jan 2023 14:58:01 +0100 Message-Id: <20230130135802.744743-5-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130135802.744743-1-benjamin.gaignard@collabora.com> References: <20230130135802.744743-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org It is needed to check if the proposed pixels format is valid before updating context bit depth and other internal states. Stop using ctx->bit_depth to check format depth match and return result to the caller. Fixes: dc39473d0340 ("media: hantro: imx8m: Enable 10bit decoding") Signed-off-by: Benjamin Gaignard Reviewed-by: Nicolas Dufresne --- .../platform/verisilicon/hantro_postproc.c | 2 +- .../media/platform/verisilicon/hantro_v4l2.c | 45 ++++++++++--------- .../media/platform/verisilicon/hantro_v4l2.h | 3 +- 3 files changed, 26 insertions(+), 24 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_postproc.c b/drivers/media/platform/verisilicon/hantro_postproc.c index 09d8cf942689..6437423ccf3a 100644 --- a/drivers/media/platform/verisilicon/hantro_postproc.c +++ b/drivers/media/platform/verisilicon/hantro_postproc.c @@ -197,7 +197,7 @@ int hantro_postproc_alloc(struct hantro_ctx *ctx) unsigned int i, buf_size; /* this should always pick native format */ - fmt = hantro_get_default_fmt(ctx, false); + fmt = hantro_get_default_fmt(ctx, false, ctx->bit_depth); if (!fmt) return -EINVAL; v4l2_fill_pixfmt_mp(&pix_mp, fmt->fourcc, ctx->src_fmt.width, diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.c b/drivers/media/platform/verisilicon/hantro_v4l2.c index e60151a8a401..6c5f4351b257 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.c +++ b/drivers/media/platform/verisilicon/hantro_v4l2.c @@ -28,6 +28,8 @@ #include "hantro_hw.h" #include "hantro_v4l2.h" +#define HANTRO_DEFAULT_BIT_DEPTH 0 + static int hantro_set_fmt_out(struct hantro_ctx *ctx, struct v4l2_pix_format_mplane *pix_mp); static int hantro_set_fmt_cap(struct hantro_ctx *ctx, @@ -76,17 +78,16 @@ int hantro_get_format_depth(u32 fourcc) } static bool -hantro_check_depth_match(const struct hantro_ctx *ctx, - const struct hantro_fmt *fmt) +hantro_check_depth_match(const struct hantro_fmt *fmt, int bit_depth) { - int fmt_depth, ctx_depth = 8; + int fmt_depth, depth = 8; if (!fmt->match_depth && !fmt->postprocessed) return true; /* 0 means default depth, which is 8 */ - if (ctx->bit_depth) - ctx_depth = ctx->bit_depth; + if (bit_depth) + depth = bit_depth; fmt_depth = hantro_get_format_depth(fmt->fourcc); @@ -95,9 +96,9 @@ hantro_check_depth_match(const struct hantro_ctx *ctx, * It may be possible to relax that on some HW. */ if (!fmt->match_depth) - return fmt_depth <= ctx_depth; + return fmt_depth <= depth; - return fmt_depth == ctx_depth; + return fmt_depth == depth; } static const struct hantro_fmt * @@ -119,7 +120,7 @@ hantro_find_format(const struct hantro_ctx *ctx, u32 fourcc) } const struct hantro_fmt * -hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream) +hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream, int bit_depth) { const struct hantro_fmt *formats; unsigned int i, num_fmts; @@ -128,7 +129,7 @@ hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream) for (i = 0; i < num_fmts; i++) { if (bitstream == (formats[i].codec_mode != HANTRO_MODE_NONE) && - hantro_check_depth_match(ctx, &formats[i])) + hantro_check_depth_match(&formats[i], bit_depth)) return &formats[i]; } return NULL; @@ -203,7 +204,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv, if (skip_mode_none == mode_none) continue; - if (!hantro_check_depth_match(ctx, fmt)) + if (!hantro_check_depth_match(fmt, ctx->bit_depth)) continue; if (j == f->index) { f->pixelformat = fmt->fourcc; @@ -223,7 +224,7 @@ static int vidioc_enum_fmt(struct file *file, void *priv, for (i = 0; i < num_fmts; i++) { fmt = &formats[i]; - if (!hantro_check_depth_match(ctx, fmt)) + if (!hantro_check_depth_match(fmt, ctx->bit_depth)) continue; if (j == f->index) { f->pixelformat = fmt->fourcc; @@ -291,7 +292,7 @@ static int hantro_try_fmt(const struct hantro_ctx *ctx, fmt = hantro_find_format(ctx, pix_mp->pixelformat); if (!fmt) { - fmt = hantro_get_default_fmt(ctx, coded); + fmt = hantro_get_default_fmt(ctx, coded, HANTRO_DEFAULT_BIT_DEPTH); pix_mp->pixelformat = fmt->fourcc; } @@ -379,7 +380,7 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) const struct hantro_fmt *vpu_fmt; struct v4l2_pix_format_mplane fmt; - vpu_fmt = hantro_get_default_fmt(ctx, true); + vpu_fmt = hantro_get_default_fmt(ctx, true, HANTRO_DEFAULT_BIT_DEPTH); if (!vpu_fmt) return; @@ -392,15 +393,15 @@ hantro_reset_encoded_fmt(struct hantro_ctx *ctx) hantro_set_fmt_out(ctx, &fmt); } -static void -hantro_reset_raw_fmt(struct hantro_ctx *ctx) +int +hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth) { const struct hantro_fmt *raw_vpu_fmt; struct v4l2_pix_format_mplane raw_fmt, *encoded_fmt; - raw_vpu_fmt = hantro_get_default_fmt(ctx, false); + raw_vpu_fmt = hantro_get_default_fmt(ctx, false, bit_depth); if (!raw_vpu_fmt) - return; + return -EINVAL; if (ctx->is_encoder) encoded_fmt = &ctx->dst_fmt; @@ -411,15 +412,15 @@ hantro_reset_raw_fmt(struct hantro_ctx *ctx) raw_fmt.width = encoded_fmt->width; raw_fmt.height = encoded_fmt->height; if (ctx->is_encoder) - hantro_set_fmt_out(ctx, &raw_fmt); + return hantro_set_fmt_out(ctx, &raw_fmt); else - hantro_set_fmt_cap(ctx, &raw_fmt); + return hantro_set_fmt_cap(ctx, &raw_fmt); } void hantro_reset_fmts(struct hantro_ctx *ctx) { hantro_reset_encoded_fmt(ctx); - hantro_reset_raw_fmt(ctx); + hantro_reset_raw_fmt(ctx, HANTRO_DEFAULT_BIT_DEPTH); } static void @@ -519,7 +520,7 @@ static int hantro_set_fmt_out(struct hantro_ctx *ctx, * changes to the raw format. */ if (!ctx->is_encoder) - hantro_reset_raw_fmt(ctx); + hantro_reset_raw_fmt(ctx, hantro_get_format_depth(pix_mp->pixelformat)); /* Colorimetry information are always propagated. */ ctx->dst_fmt.colorspace = pix_mp->colorspace; @@ -582,7 +583,7 @@ static int hantro_set_fmt_cap(struct hantro_ctx *ctx, * changes to the raw format. */ if (ctx->is_encoder) - hantro_reset_raw_fmt(ctx); + hantro_reset_raw_fmt(ctx, HANTRO_DEFAULT_BIT_DEPTH); /* Colorimetry information are always propagated. */ ctx->src_fmt.colorspace = pix_mp->colorspace; diff --git a/drivers/media/platform/verisilicon/hantro_v4l2.h b/drivers/media/platform/verisilicon/hantro_v4l2.h index 64f6f57e9d7a..9ea2fef57dcd 100644 --- a/drivers/media/platform/verisilicon/hantro_v4l2.h +++ b/drivers/media/platform/verisilicon/hantro_v4l2.h @@ -21,9 +21,10 @@ extern const struct v4l2_ioctl_ops hantro_ioctl_ops; extern const struct vb2_ops hantro_queue_ops; +int hantro_reset_raw_fmt(struct hantro_ctx *ctx, int bit_depth); void hantro_reset_fmts(struct hantro_ctx *ctx); int hantro_get_format_depth(u32 fourcc); const struct hantro_fmt * -hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream); +hantro_get_default_fmt(const struct hantro_ctx *ctx, bool bitstream, int bit_depth); #endif /* HANTRO_V4L2_H_ */ From patchwork Mon Jan 30 13:58:02 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 648833 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id D5C6AC636CD for ; Mon, 30 Jan 2023 13:59:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236915AbjA3N7G (ORCPT ); Mon, 30 Jan 2023 08:59:06 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236800AbjA3N65 (ORCPT ); Mon, 30 Jan 2023 08:58:57 -0500 Received: from madras.collabora.co.uk (madras.collabora.co.uk [IPv6:2a00:1098:0:82:1000:25:2eeb:e5ab]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4EE4B36FEA; Mon, 30 Jan 2023 05:58:37 -0800 (PST) Received: from benjamin-XPS-13-9310.. (unknown [IPv6:2a01:e0a:120:3210:e655:2335:9172:6e39]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) (Authenticated sender: benjamin.gaignard) by madras.collabora.co.uk (Postfix) with ESMTPSA id 996E96602F10; Mon, 30 Jan 2023 13:58:13 +0000 (GMT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=collabora.com; s=mail; t=1675087094; bh=R5a/mEpnxaqGwC3EbPKXrQNBPFEzTc0n/5f90KTNBzU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UbeFUDJNjH+boCT1h8uJhzuLeqp2wTx96eCbu0JLaU1/SUDFSJmZWNun3sKp/eTq4 Z9JlKRyaD57WcD78uF34AkuL4sOnpO5Z3MVZlamrTDr3tmzPTyw1YWl+KIXuCgTAI6 7lb3WaYZMzVrkEqbZnpujWMWiVShNEVwqWfIJrQiEqXE97N6tfcj43R564dC3ItQcx zmy2wZlIUVs8qj+36vV8mwiqHQsXgvKW60WolHykjBDgCSiOPQDdciKy+YeU2pzgMn 6GkT3nEOV3N1sa53CZ1kdGaYOR+kP0PBQDNN6853mzqZbgKcxeOgP7l8+EIpYjtX4E PszSStAJgWSZg== From: Benjamin Gaignard To: ezequiel@vanguardiasur.com.ar, p.zabel@pengutronix.de, mchehab@kernel.org, shawnguo@kernel.org, s.hauer@pengutronix.de, kernel@pengutronix.de, festevam@gmail.com, linux-imx@nxp.com, hverkuil-cisco@xs4all.nl, nicolas.dufresne@collabora.co.uk Cc: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, kernel@collabora.com, Benjamin Gaignard , Nicolas Dufresne Subject: [PATCH v6 5/5] media: verisilicon: HEVC: Only propose 10 bitscompatible pixels formats Date: Mon, 30 Jan 2023 14:58:02 +0100 Message-Id: <20230130135802.744743-6-benjamin.gaignard@collabora.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230130135802.744743-1-benjamin.gaignard@collabora.com> References: <20230130135802.744743-1-benjamin.gaignard@collabora.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-media@vger.kernel.org When decoding a 10bits bitstreams HEVC driver should only expose 10bits pixel formats. To fulfill this requirement it is needed to call hantro_reset_raw_fmt() when bit depth change and to correctly set match_depth in pixel formats enumeration. Fixes: dc39473d0340 ("media: hantro: imx8m: Enable 10bit decoding") Signed-off-by: Benjamin Gaignard Reviewed-by: Nicolas Dufresne --- drivers/media/platform/verisilicon/hantro_drv.c | 16 ++++++++++++++-- .../media/platform/verisilicon/imx8m_vpu_hw.c | 2 ++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/drivers/media/platform/verisilicon/hantro_drv.c b/drivers/media/platform/verisilicon/hantro_drv.c index 715075f15596..e3656649c717 100644 --- a/drivers/media/platform/verisilicon/hantro_drv.c +++ b/drivers/media/platform/verisilicon/hantro_drv.c @@ -331,8 +331,20 @@ static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl) switch (ctrl->id) { case V4L2_CID_STATELESS_HEVC_SPS: - ctx->bit_depth = ctrl->p_new.p_hevc_sps->bit_depth_luma_minus8 + 8; - break; + { + const struct v4l2_ctrl_hevc_sps *sps = ctrl->p_new.p_hevc_sps; + int bit_depth = sps->bit_depth_luma_minus8 + 8; + int ret; + + if (ctx->bit_depth == bit_depth) + return 0; + + ret = hantro_reset_raw_fmt(ctx, bit_depth); + if (!ret) + ctx->bit_depth = bit_depth; + + return ret; + } default: return -EINVAL; } diff --git a/drivers/media/platform/verisilicon/imx8m_vpu_hw.c b/drivers/media/platform/verisilicon/imx8m_vpu_hw.c index b390228fd3b4..f850d8bddef6 100644 --- a/drivers/media/platform/verisilicon/imx8m_vpu_hw.c +++ b/drivers/media/platform/verisilicon/imx8m_vpu_hw.c @@ -152,6 +152,7 @@ static const struct hantro_fmt imx8m_vpu_g2_postproc_fmts[] = { { .fourcc = V4L2_PIX_FMT_NV12, .codec_mode = HANTRO_MODE_NONE, + .match_depth = true, .postprocessed = true, .frmsize = { .min_width = FMT_MIN_WIDTH, @@ -165,6 +166,7 @@ static const struct hantro_fmt imx8m_vpu_g2_postproc_fmts[] = { { .fourcc = V4L2_PIX_FMT_P010, .codec_mode = HANTRO_MODE_NONE, + .match_depth = true, .postprocessed = true, .frmsize = { .min_width = FMT_MIN_WIDTH,