From nobody Sun Sep 22 09:33:11 2024 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 9AFA5C43217 for ; Mon, 17 Jan 2022 12:06:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239558AbiAQMGe (ORCPT ); Mon, 17 Jan 2022 07:06:34 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:48172 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239553AbiAQMGb (ORCPT ); Mon, 17 Jan 2022 07:06:31 -0500 X-UUID: eb5967ebca764f93bd260b5c256daf8e-20220117 X-UUID: eb5967ebca764f93bd260b5c256daf8e-20220117 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1679302506; Mon, 17 Jan 2022 20:06:28 +0800 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:27 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb02.mediatek.inc (172.21.101.103) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:26 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:25 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , "Tiffany Lin" , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 01/10] media: mtk-vcodec: Use core type to indicate h264 and vp8 enc Date: Mon, 17 Jan 2022 20:06:06 +0800 Message-ID: <20220117120615.21687-2-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" use core type variables to indicate h264 and vp8 encoder Signed-off-by: Irui Wang --- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 4 +-- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 30 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index cd2939b47790..f78463ff4551 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -419,7 +419,7 @@ struct mtk_vcodec_dec_pdata { * @num_capture_formats: number of entries in capture_formats * @output_formats: array of supported output formats * @num_output_formats: number of entries in output_formats - * @core_id: stand for h264 or vp8 encode index + * @core_type: stand for h264 or vp8 encode */ struct mtk_vcodec_enc_pdata { bool uses_ext; @@ -429,7 +429,7 @@ struct mtk_vcodec_enc_pdata { size_t num_capture_formats; const struct mtk_video_fmt *output_formats; size_t num_output_formats; - int core_id; + int core_type; }; =20 #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index 3ac6969c54c0..1f950310a3fb 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -95,11 +95,13 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, = void *priv) ctx =3D dev->curr_ctx; spin_unlock_irqrestore(&dev->irqlock, flags); =20 - mtk_v4l2_debug(1, "id=3D%d coreid:%d", ctx->id, dev->venc_pdata->core_id); - addr =3D dev->reg_base[dev->venc_pdata->core_id] + + mtk_v4l2_debug(1, "id: %d core type: %d", + ctx->id, dev->venc_pdata->core_type); + + addr =3D dev->reg_base[dev->venc_pdata->core_type] + MTK_VENC_IRQ_ACK_OFFSET; =20 - ctx->irq_status =3D readl(dev->reg_base[dev->venc_pdata->core_id] + + ctx->irq_status =3D readl(dev->reg_base[dev->venc_pdata->core_type] + (MTK_VENC_IRQ_STATUS_OFFSET)); =20 clean_irq_status(ctx->irq_status, addr); @@ -266,10 +268,10 @@ static int mtk_vcodec_probe(struct platform_device *p= dev) =20 pm_runtime_enable(&pdev->dev); =20 - dev->reg_base[dev->venc_pdata->core_id] =3D + dev->reg_base[dev->venc_pdata->core_type] =3D devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(dev->reg_base[dev->venc_pdata->core_id])) { - ret =3D PTR_ERR(dev->reg_base[dev->venc_pdata->core_id]); + if (IS_ERR(dev->reg_base[dev->venc_pdata->core_type])) { + ret =3D PTR_ERR(dev->reg_base[dev->venc_pdata->core_type]); goto err_res; } =20 @@ -287,8 +289,8 @@ static int mtk_vcodec_probe(struct platform_device *pde= v) 0, pdev->name, dev); if (ret) { dev_err(&pdev->dev, - "Failed to install dev->enc_irq %d (%d) core_id (%d)", - dev->enc_irq, ret, dev->venc_pdata->core_id); + "Failed to install dev->enc_irq %d (%d) core_type (%d)", + dev->enc_irq, ret, dev->venc_pdata->core_type); ret =3D -EINVAL; goto err_res; } @@ -357,7 +359,7 @@ static int mtk_vcodec_probe(struct platform_device *pde= v) } =20 mtk_v4l2_debug(0, "encoder %d registered as /dev/video%d", - dev->venc_pdata->core_id, vfd_enc->num); + dev->venc_pdata->core_type, vfd_enc->num); =20 return 0; =20 @@ -384,7 +386,7 @@ static const struct mtk_vcodec_enc_pdata mt8173_avc_pda= ta =3D { .num_output_formats =3D ARRAY_SIZE(mtk_video_formats_output), .min_bitrate =3D 64, .max_bitrate =3D 60000000, - .core_id =3D VENC_SYS, + .core_type =3D VENC_SYS, }; =20 static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata =3D { @@ -394,7 +396,7 @@ static const struct mtk_vcodec_enc_pdata mt8173_vp8_pda= ta =3D { .num_output_formats =3D ARRAY_SIZE(mtk_video_formats_output), .min_bitrate =3D 64, .max_bitrate =3D 9000000, - .core_id =3D VENC_LT_SYS, + .core_type =3D VENC_LT_SYS, }; =20 static const struct mtk_vcodec_enc_pdata mt8183_pdata =3D { @@ -405,7 +407,7 @@ static const struct mtk_vcodec_enc_pdata mt8183_pdata = =3D { .num_output_formats =3D ARRAY_SIZE(mtk_video_formats_output), .min_bitrate =3D 64, .max_bitrate =3D 40000000, - .core_id =3D VENC_SYS, + .core_type =3D VENC_SYS, }; =20 static const struct mtk_vcodec_enc_pdata mt8192_pdata =3D { @@ -416,7 +418,7 @@ static const struct mtk_vcodec_enc_pdata mt8192_pdata = =3D { .num_output_formats =3D ARRAY_SIZE(mtk_video_formats_output), .min_bitrate =3D 64, .max_bitrate =3D 100000000, - .core_id =3D VENC_SYS, + .core_type =3D VENC_SYS, }; =20 static const struct mtk_vcodec_enc_pdata mt8195_pdata =3D { @@ -427,7 +429,7 @@ static const struct mtk_vcodec_enc_pdata mt8195_pdata = =3D { .num_output_formats =3D ARRAY_SIZE(mtk_video_formats_output), .min_bitrate =3D 64, .max_bitrate =3D 100000000, - .core_id =3D VENC_SYS, + .core_type =3D VENC_SYS, }; =20 static const struct of_device_id mtk_vcodec_enc_match[] =3D { --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 4209FC433F5 for ; Mon, 17 Jan 2022 12:06:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239599AbiAQMGg (ORCPT ); Mon, 17 Jan 2022 07:06:36 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:36694 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239554AbiAQMGd (ORCPT ); Mon, 17 Jan 2022 07:06:33 -0500 X-UUID: 79eca5885b7c48bcbd8666ea03d3df5f-20220117 X-UUID: 79eca5885b7c48bcbd8666ea03d3df5f-20220117 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1089449713; Mon, 17 Jan 2022 20:06:30 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:28 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:27 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 02/10] media: mtk-vcodec: export encoder functions Date: Mon, 17 Jan 2022 20:06:07 +0800 Message-ID: <20220117120615.21687-3-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" mtk vcodec is built as a module, export some functions to make them visible by other modules. Signed-off-by: Irui Wang --- drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c | 2 ++ drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 3 +++ 2 files changed, 5 insertions(+) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index ffb046eec610..134dc53e4855 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -1432,6 +1432,7 @@ int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx) mutex_unlock(&dev->enc_mutex); return 0; } +EXPORT_SYMBOL_GPL(mtk_venc_unlock); =20 int mtk_venc_lock(struct mtk_vcodec_ctx *ctx) { @@ -1440,6 +1441,7 @@ int mtk_venc_lock(struct mtk_vcodec_ctx *ctx) mutex_lock(&dev->enc_mutex); return 0; } +EXPORT_SYMBOL_GPL(mtk_venc_lock); =20 void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *ctx) { diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c index 0825c6ec4eb7..7eba1a990ed7 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c @@ -85,6 +85,7 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *mtkdev) put_device(pm->larbvenc); return ret; } +EXPORT_SYMBOL_GPL(mtk_vcodec_init_enc_clk); =20 void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) { @@ -111,6 +112,7 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) for (i -=3D 1; i >=3D 0; i--) clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk); } +EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_on); =20 void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) { @@ -121,3 +123,4 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) for (i =3D enc_clk->clk_num - 1; i >=3D 0; i--) clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk); } +EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_off); --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 69F9DC4332F for ; Mon, 17 Jan 2022 12:06:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239605AbiAQMGi (ORCPT ); Mon, 17 Jan 2022 07:06:38 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:36818 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239581AbiAQMGg (ORCPT ); Mon, 17 Jan 2022 07:06:36 -0500 X-UUID: 0feedd9c73d44a5993b52a51963760df-20220117 X-UUID: 0feedd9c73d44a5993b52a51963760df-20220117 Received: from mtkcas10.mediatek.inc [(172.21.101.39)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 346831367; Mon, 17 Jan 2022 20:06:33 +0800 Received: from mtkexhb01.mediatek.inc (172.21.101.102) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:32 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb01.mediatek.inc (172.21.101.102) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:31 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:30 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , "Tiffany Lin" , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 03/10] dt-bindings: media: mtk-vcodec: Adds encoder cores dt-bindings for mt8195 Date: Mon, 17 Jan 2022 20:06:08 +0800 Message-ID: <20220117120615.21687-4-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adds encoder cores dt-bindings for mt8195 Signed-off-by: Irui Wang --- .../media/mediatek,vcodec-encoder-core.yaml | 214 ++++++++++++++++++ 1 file changed, 214 insertions(+) create mode 100644 Documentation/devicetree/bindings/media/mediatek,vcodec= -encoder-core.yaml diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-encode= r-core.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-encod= er-core.yaml new file mode 100644 index 000000000000..d1e7bfa50bce --- /dev/null +++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-encoder-core.= yaml @@ -0,0 +1,214 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) + +%YAML 1.2 +--- +$id: "http://devicetree.org/schemas/media/mediatek,vcodec-encoder-core.yam= l#" +$schema: "http://devicetree.org/meta-schemas/core.yaml#" + +title: Mediatek Video Encoder Accelerator With Multi Core + +maintainers: + - Irui Wang + +description: | + Mediatek Video Encode is the video encode hardware present in Mediatek + SoCs which supports high resolution encoding functionalities. Required + parent and child device node. + +properties: + compatible: + const: mediatek,mt8195-vcodec-enc + + mediatek,scp: + $ref: /schemas/types.yaml#/definitions/phandle + maxItems: 1 + description: | + The node of system control processor (SCP), using + the remoteproc & rpmsg framework. + + iommus: + minItems: 1 + maxItems: 32 + description: | + List of the hardware port in respective IOMMU block for current Socs. + Refer to bindings/iommu/mediatek,iommu.yaml. + + dma-ranges: + maxItems: 1 + description: | + Describes the physical address space of IOMMU maps to memory. + + "#address-cells": + const: 1 + + "#size-cells": + const: 1 + + ranges: true + +# Required child node: +patternProperties: + "venc_core0@1a020000": + type: object + + properties: + compatible: + const: mediatek,mtk-venc-core0 + + reg: + maxItems: 1 + + iommus: + minItems: 1 + maxItems: 32 + description: | + List of the hardware port in respective IOMMU block for current = Socs. + Refer to bindings/iommu/mediatek,iommu.yaml. + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: MT_CG_VENC0 + + assigned-clocks: + maxItems: 1 + + assigned-clock-parents: + maxItems: 1 + + power-domains: + maxItems: 1 + + required: + - compatible + - reg + - iommus + - interrupts + - clocks + - clock-names + - assigned-clocks + - assigned-clock-parents + - power-domains + + additionalProperties: false + + "venc_core1@1b020000": + type: object + + properties: + compatible: + const: mediatek,mtk-venc-core1 + + reg: + maxItems: 1 + + iommus: + minItems: 1 + maxItems: 32 + description: | + List of the hardware port in respective IOMMU block for current = Socs. + Refer to bindings/iommu/mediatek,iommu.yaml. + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: MT_CG_VENC1 + + assigned-clocks: + maxItems: 1 + + assigned-clock-parents: + maxItems: 1 + + power-domains: + maxItems: 1 + + required: + - compatible + - reg + - iommus + - interrupts + - clocks + - clock-names + - assigned-clocks + - assigned-clock-parents + - power-domains + + additionalProperties: false + +required: + - compatible + - mediatek,scp + - iommus + - dma-ranges + - ranges + +additionalProperties: false + +examples: + - | + #include + #include + #include + #include + #include + + venc { + compatible =3D "mediatek,mt8195-vcodec-enc"; + mediatek,scp =3D <&scp>; + iommus =3D <&iommu_vdo M4U_PORT_L19_VENC_RCPU>; + dma-ranges =3D <0x1 0x0 0x0 0x40000000 0x0 0xfff00000>; + #address-cells =3D <1>; + #size-cells =3D <1>; + ranges; + + venc_core0@1a020000 { + compatible =3D "mediatek,mtk-venc-core0"; + reg =3D <0x1a020000 0x10000>; + iommus =3D <&iommu_vdo M4U_PORT_L19_VENC_RCPU>, + <&iommu_vdo M4U_PORT_L19_VENC_REC>, + <&iommu_vdo M4U_PORT_L19_VENC_BSDMA>, + <&iommu_vdo M4U_PORT_L19_VENC_SV_COMV>, + <&iommu_vdo M4U_PORT_L19_VENC_RD_COMV>, + <&iommu_vdo M4U_PORT_L19_VENC_CUR_LUMA>, + <&iommu_vdo M4U_PORT_L19_VENC_CUR_CHROMA>, + <&iommu_vdo M4U_PORT_L19_VENC_REF_LUMA>, + <&iommu_vdo M4U_PORT_L19_VENC_REF_CHROMA>; + interrupts =3D ; + clocks =3D <&vencsys CLK_VENC_VENC>; + clock-names =3D "MT_CG_VENC0"; + assigned-clocks =3D <&topckgen CLK_TOP_VENC>; + assigned-clock-parents =3D <&topckgen CLK_TOP_UNIVPLL_D4>; + power-domains =3D <&spm MT8195_POWER_DOMAIN_VENC>; + }; + + venc_core1@1b020000 { + compatible =3D "mediatek,mtk-venc-core1"; + reg =3D <0x1b020000 0x10000>; + iommus =3D <&iommu_vpp M4U_PORT_L20_VENC_RCPU>, + <&iommu_vpp M4U_PORT_L20_VENC_REC>, + <&iommu_vpp M4U_PORT_L20_VENC_BSDMA>, + <&iommu_vpp M4U_PORT_L20_VENC_SV_COMV>, + <&iommu_vpp M4U_PORT_L20_VENC_RD_COMV>, + <&iommu_vpp M4U_PORT_L20_VENC_CUR_LUMA>, + <&iommu_vpp M4U_PORT_L20_VENC_CUR_CHROMA>, + <&iommu_vpp M4U_PORT_L20_VENC_REF_LUMA>, + <&iommu_vpp M4U_PORT_L20_VENC_REF_CHROMA>; + interrupts =3D ; + clocks =3D <&vencsys_core1 CLK_VENC_CORE1_VENC>; + clock-names =3D "MT_CG_VENC1"; + assigned-clocks =3D <&topckgen CLK_TOP_VENC>; + assigned-clock-parents =3D <&topckgen CLK_TOP_UNIVPLL_D4>; + power-domains =3D <&spm MT8195_POWER_DOMAIN_VENC_CORE1>; + }; + }; --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 0F6C0C4321E for ; Mon, 17 Jan 2022 12:06:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239634AbiAQMGn (ORCPT ); Mon, 17 Jan 2022 07:06:43 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:36888 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239606AbiAQMGj (ORCPT ); Mon, 17 Jan 2022 07:06:39 -0500 X-UUID: 10d3ae7e9f634065960712d5b7211fab-20220117 X-UUID: 10d3ae7e9f634065960712d5b7211fab-20220117 Received: from mtkexhb02.mediatek.inc [(172.21.101.103)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 1050059200; Mon, 17 Jan 2022 20:06:35 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Mon, 17 Jan 2022 20:06:33 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:32 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , "Tiffany Lin" , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 04/10] media: mtk-vcodec: Enable venc dual core usage Date: Mon, 17 Jan 2022 20:06:09 +0800 Message-ID: <20220117120615.21687-5-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adds new venc core mode to indicate different venc hardware mode: VENC_SINGLE_CORE_MODE means only one core, the device has its own power/clk/irq, init_clk/request_irq helper can be used. VENC_DUAL_CORE_MODE means more than one core inside, the core device can use the init_clk/request_irq helper to initialize their own power/clk/irq. And the main device doesn't need use these helper anymore. MT8195 has two H264 venc cores, enable dual_core_mode for it. Signed-off-by: Irui Wang --- drivers/media/platform/mtk-vcodec/Makefile | 4 +- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 22 +++ .../platform/mtk-vcodec/mtk_vcodec_enc_core.c | 153 ++++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_core.h | 36 +++++ .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 88 +++++----- 5 files changed, 266 insertions(+), 37 deletions(-) create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c create mode 100644 drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h diff --git a/drivers/media/platform/mtk-vcodec/Makefile b/drivers/media/pla= tform/mtk-vcodec/Makefile index 93e7a343b5b0..c472b221bd6b 100644 --- a/drivers/media/platform/mtk-vcodec/Makefile +++ b/drivers/media/platform/mtk-vcodec/Makefile @@ -3,7 +3,8 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) +=3D mtk-vcodec-dec.o \ mtk-vcodec-enc.o \ mtk-vcodec-common.o \ - mtk-vcodec-dec-hw.o + mtk-vcodec-dec-hw.o \ + mtk-vcodec-enc-core.o =20 mtk-vcodec-dec-y :=3D vdec/vdec_h264_if.o \ vdec/vdec_vp8_if.o \ @@ -32,6 +33,7 @@ mtk-vcodec-enc-y :=3D venc/venc_vp8_if.o \ venc_drv_if.o \ venc_vpu_if.o \ =20 +mtk-vcodec-enc-core-y :=3D mtk_vcodec_enc_core.o =20 mtk-vcodec-common-y :=3D mtk_vcodec_intr.o \ mtk_vcodec_util.o \ diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index f78463ff4551..9e4e4290a69a 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -117,6 +117,23 @@ enum mtk_vdec_hw_count { MTK_VDEC_MAX_HW_COUNT, }; =20 +/* + * enum mtk_venc_core_id -- encoder core id + */ +enum mtk_venc_core_id { + MTK_VENC_CORE0 =3D 0, + MTK_VENC_CORE1 =3D 1, + MTK_VENC_CORE_MAX, +}; + +/** + * enmu mtk_venc_core_mode - Used to indicate different encode mode + */ +enum mtk_venc_core_mode { + VENC_SINGLE_CORE_MODE =3D 0, + VENC_DUAL_CORE_MODE =3D 1, +}; + /* * struct mtk_video_fmt - Structure used to store information about pixelf= ormats */ @@ -420,6 +437,7 @@ struct mtk_vcodec_dec_pdata { * @output_formats: array of supported output formats * @num_output_formats: number of entries in output_formats * @core_type: stand for h264 or vp8 encode + * @core_mode: indicate encode core mode */ struct mtk_vcodec_enc_pdata { bool uses_ext; @@ -430,6 +448,7 @@ struct mtk_vcodec_enc_pdata { const struct mtk_video_fmt *output_formats; size_t num_output_formats; int core_type; + enum mtk_venc_core_mode core_mode; }; =20 #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext) @@ -479,6 +498,7 @@ struct mtk_vcodec_enc_pdata { * @subdev_dev: subdev hardware device * @subdev_prob_done: check whether all used hw device is prob done * @subdev_bitmap: used to record hardware is ready or not + * @enc_core_dev: used to store venc core device */ struct mtk_vcodec_dev { struct v4l2_device v4l2_dev; @@ -524,6 +544,8 @@ struct mtk_vcodec_dev { void *subdev_dev[MTK_VDEC_HW_MAX]; int (*subdev_prob_done)(struct mtk_vcodec_dev *vdec_dev); DECLARE_BITMAP(subdev_bitmap, MTK_VDEC_HW_MAX); + + void *enc_core_dev[MTK_VENC_CORE_MAX]; }; =20 static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c b/driv= ers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c new file mode 100644 index 000000000000..d84914f615a5 --- /dev/null +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2021 MediaTek Inc. + */ + +#include +#include +#include +#include +#include +#include + +#include "mtk_vcodec_drv.h" +#include "mtk_vcodec_enc.h" +#include "mtk_vcodec_enc_core.h" + +static const struct of_device_id mtk_venc_core_ids[] =3D { + { + .compatible =3D "mediatek,mtk-venc-core0", + .data =3D (void *)MTK_VENC_CORE0, + }, + { + .compatible =3D "mediatek,mtk-venc-core1", + .data =3D (void *)MTK_VENC_CORE1, + }, + {}, +}; +MODULE_DEVICE_TABLE(of, mtk_venc_core_ids); + +static void clean_irq_status(unsigned int irq_status, void __iomem *addr) +{ + if (irq_status & MTK_VENC_IRQ_STATUS_PAUSE) + writel(MTK_VENC_IRQ_STATUS_PAUSE, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_SWITCH) + writel(MTK_VENC_IRQ_STATUS_SWITCH, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_DRAM) + writel(MTK_VENC_IRQ_STATUS_DRAM, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_SPS) + writel(MTK_VENC_IRQ_STATUS_SPS, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_PPS) + writel(MTK_VENC_IRQ_STATUS_PPS, addr); + + if (irq_status & MTK_VENC_IRQ_STATUS_FRM) + writel(MTK_VENC_IRQ_STATUS_FRM, addr); +} + +static irqreturn_t mtk_enc_core_irq_handler(int irq, void *priv) +{ + struct mtk_venc_core_dev *core =3D priv; + struct mtk_vcodec_ctx *ctx; + unsigned long flags; + void __iomem *addr; + + spin_lock_irqsave(&core->main_dev->irqlock, flags); + ctx =3D core->curr_ctx; + spin_unlock_irqrestore(&core->main_dev->irqlock, flags); + if (!ctx) + return IRQ_HANDLED; + + mtk_v4l2_debug(1, "id=3D%d core :%d", ctx->id, core->core_id); + + addr =3D core->reg_base + MTK_VENC_IRQ_ACK_OFFSET; + ctx->irq_status =3D readl(core->reg_base + MTK_VENC_IRQ_STATUS_OFFSET); + clean_irq_status(ctx->irq_status, addr); + + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); + return IRQ_HANDLED; +} + +static int mtk_venc_core_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct mtk_venc_core_dev *core; + struct mtk_vcodec_dev *main_dev; + int ret; + + if (!dev->parent) { + dev_err(dev, "No parent for venc core device\n"); + return -ENODEV; + } + + main_dev =3D dev_get_drvdata(dev->parent); + if (!main_dev) { + dev_err(dev, "Failed to get parent driver data"); + return -EINVAL; + } + + core =3D devm_kzalloc(&pdev->dev, sizeof(*core), GFP_KERNEL); + if (!core) + return -ENOMEM; + + core->plat_dev =3D pdev; + + core->reg_base =3D devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(core->reg_base)) { + dev_err(&pdev->dev, "Failed to get reg base"); + ret =3D PTR_ERR(core->reg_base); + goto err; + } + + core->enc_irq =3D platform_get_irq(pdev, 0); + if (core->enc_irq < 0) { + dev_err(&pdev->dev, "Failed to get irq resource"); + ret =3D core->enc_irq; + goto err; + } + + ret =3D devm_request_irq(&pdev->dev, core->enc_irq, + mtk_enc_core_irq_handler, 0, + pdev->name, core); + if (ret) { + dev_err(&pdev->dev, + "Failed to install core->enc_irq %d (%d)", + core->enc_irq, ret); + ret =3D -EINVAL; + goto err; + } + + core->core_id =3D + (enum mtk_venc_core_id)of_device_get_match_data(&pdev->dev); + if (core->core_id < 0 || core->core_id >=3D MTK_VENC_CORE_MAX) { + ret =3D -EINVAL; + goto err; + } + + main_dev->enc_core_dev[core->core_id] =3D core; + core->main_dev =3D main_dev; + + platform_set_drvdata(pdev, core); + + dev_info(dev, "Venc core :%d probe done\n", core->core_id); + + return 0; + +err: + return ret; +} + +static struct platform_driver mtk_venc_core_driver =3D { + .probe =3D mtk_venc_core_probe, + .driver =3D { + .name =3D "mtk-venc-core", + .of_match_table =3D mtk_venc_core_ids, + }, +}; +module_platform_driver(mtk_venc_core_driver); + +MODULE_LICENSE("GPL v2"); +MODULE_DESCRIPTION("Mediatek video encoder core driver"); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h b/driv= ers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h new file mode 100644 index 000000000000..856681989869 --- /dev/null +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.h @@ -0,0 +1,36 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2021 MediaTek Inc. + */ + +#ifndef _MTK_VCODEC_ENC_CORE_H_ +#define _MTK_VCODEC_ENC_CORE_H_ + +#include +#include "mtk_vcodec_drv.h" + +/* + * struct mtk_venc_core_dev - driver data + * @plat_dev: platform_device + * @main_dev: main device + * @pm: power management data + * @curr_ctx: the context that is waiting for venc hardware + * @reg_base: mapped address of venc registers + * @irq_status: venc core irq status + * @enc_irq: venc device irq + * @core id: for venc core id: core#0, core#1... + */ +struct mtk_venc_core_dev { + struct platform_device *plat_dev; + struct mtk_vcodec_dev *main_dev; + + struct mtk_vcodec_pm pm; + struct mtk_vcodec_ctx *curr_ctx; + + void __iomem *reg_base; + unsigned int irq_status; + int enc_irq; + int core_id; +}; + +#endif /* _MTK_VCODEC_ENC_CORE_H_ */ diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index 1f950310a3fb..9d48c604bc54 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -231,10 +231,9 @@ static int mtk_vcodec_probe(struct platform_device *pd= ev) { struct mtk_vcodec_dev *dev; struct video_device *vfd_enc; - struct resource *res; phandle rproc_phandle; enum mtk_vcodec_fw_type fw_type; - int ret; + int ret, core_type; =20 dev =3D devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -260,39 +259,37 @@ static int mtk_vcodec_probe(struct platform_device *p= dev) return PTR_ERR(dev->fw_handler); =20 dev->venc_pdata =3D of_device_get_match_data(&pdev->dev); - ret =3D mtk_vcodec_init_enc_clk(dev); - if (ret < 0) { - dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!"); - goto err_enc_pm; - } + core_type =3D dev->venc_pdata->core_type; =20 - pm_runtime_enable(&pdev->dev); + if (dev->venc_pdata->core_mode =3D=3D VENC_SINGLE_CORE_MODE) { + ret =3D mtk_vcodec_init_enc_clk(dev); + if (ret < 0) { + dev_err(&pdev->dev, + "Failed to get mtk vcodec clock source!"); + goto err_enc_pm; + } =20 - dev->reg_base[dev->venc_pdata->core_type] =3D - devm_platform_ioremap_resource(pdev, 0); - if (IS_ERR(dev->reg_base[dev->venc_pdata->core_type])) { - ret =3D PTR_ERR(dev->reg_base[dev->venc_pdata->core_type]); - goto err_res; - } + pm_runtime_enable(&pdev->dev); =20 - res =3D platform_get_resource(pdev, IORESOURCE_IRQ, 0); - if (res =3D=3D NULL) { - dev_err(&pdev->dev, "failed to get irq resource"); - ret =3D -ENOENT; - goto err_res; - } + dev->reg_base[core_type] =3D + devm_platform_ioremap_resource(pdev, 0); + if (IS_ERR(dev->reg_base[core_type])) { + ret =3D PTR_ERR(dev->reg_base[core_type]); + goto err_res; + } =20 - dev->enc_irq =3D platform_get_irq(pdev, 0); - irq_set_status_flags(dev->enc_irq, IRQ_NOAUTOEN); - ret =3D devm_request_irq(&pdev->dev, dev->enc_irq, - mtk_vcodec_enc_irq_handler, - 0, pdev->name, dev); - if (ret) { - dev_err(&pdev->dev, - "Failed to install dev->enc_irq %d (%d) core_type (%d)", - dev->enc_irq, ret, dev->venc_pdata->core_type); - ret =3D -EINVAL; - goto err_res; + dev->enc_irq =3D platform_get_irq(pdev, 0); + irq_set_status_flags(dev->enc_irq, IRQ_NOAUTOEN); + ret =3D devm_request_irq(&pdev->dev, dev->enc_irq, + mtk_vcodec_enc_irq_handler, + 0, pdev->name, dev); + if (ret) { + dev_err(&pdev->dev, + "Failed to install irq %d (%d) core_type (%d)", + dev->enc_irq, ret, core_type); + ret =3D -EINVAL; + goto err_res; + } } =20 mutex_init(&dev->enc_mutex); @@ -358,8 +355,17 @@ static int mtk_vcodec_probe(struct platform_device *pd= ev) goto err_enc_reg; } =20 + if (dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + ret =3D of_platform_populate(pdev->dev.of_node, + NULL, NULL, &pdev->dev); + if (ret) { + mtk_v4l2_err("Venc main device populate failed"); + goto err_enc_reg; + } + } + mtk_v4l2_debug(0, "encoder %d registered as /dev/video%d", - dev->venc_pdata->core_type, vfd_enc->num); + core_type, vfd_enc->num); =20 return 0; =20 @@ -372,8 +378,10 @@ static int mtk_vcodec_probe(struct platform_device *pd= ev) err_enc_alloc: v4l2_device_unregister(&dev->v4l2_dev); err_res: - pm_runtime_disable(dev->pm.dev); - put_device(dev->pm.larbvenc); + if (dev->venc_pdata->core_mode =3D=3D VENC_SINGLE_CORE_MODE) { + pm_runtime_disable(dev->pm.dev); + put_device(dev->pm.larbvenc); + } err_enc_pm: mtk_vcodec_fw_release(dev->fw_handler); return ret; @@ -387,6 +395,7 @@ static const struct mtk_vcodec_enc_pdata mt8173_avc_pda= ta =3D { .min_bitrate =3D 64, .max_bitrate =3D 60000000, .core_type =3D VENC_SYS, + .core_mode =3D VENC_SINGLE_CORE_MODE, }; =20 static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata =3D { @@ -397,6 +406,7 @@ static const struct mtk_vcodec_enc_pdata mt8173_vp8_pda= ta =3D { .min_bitrate =3D 64, .max_bitrate =3D 9000000, .core_type =3D VENC_LT_SYS, + .core_mode =3D VENC_SINGLE_CORE_MODE, }; =20 static const struct mtk_vcodec_enc_pdata mt8183_pdata =3D { @@ -408,6 +418,7 @@ static const struct mtk_vcodec_enc_pdata mt8183_pdata = =3D { .min_bitrate =3D 64, .max_bitrate =3D 40000000, .core_type =3D VENC_SYS, + .core_mode =3D VENC_SINGLE_CORE_MODE, }; =20 static const struct mtk_vcodec_enc_pdata mt8192_pdata =3D { @@ -419,6 +430,7 @@ static const struct mtk_vcodec_enc_pdata mt8192_pdata = =3D { .min_bitrate =3D 64, .max_bitrate =3D 100000000, .core_type =3D VENC_SYS, + .core_mode =3D VENC_SINGLE_CORE_MODE, }; =20 static const struct mtk_vcodec_enc_pdata mt8195_pdata =3D { @@ -430,6 +442,7 @@ static const struct mtk_vcodec_enc_pdata mt8195_pdata = =3D { .min_bitrate =3D 64, .max_bitrate =3D 100000000, .core_type =3D VENC_SYS, + .core_mode =3D VENC_DUAL_CORE_MODE, }; =20 static const struct of_device_id mtk_vcodec_enc_match[] =3D { @@ -457,8 +470,11 @@ static int mtk_vcodec_enc_remove(struct platform_devic= e *pdev) video_unregister_device(dev->vfd_enc); =20 v4l2_device_unregister(&dev->v4l2_dev); - pm_runtime_disable(dev->pm.dev); - put_device(dev->pm.larbvenc); + + if (dev->venc_pdata->core_mode =3D=3D VENC_SINGLE_CORE_MODE) { + pm_runtime_disable(dev->pm.dev); + put_device(dev->pm.larbvenc); + } mtk_vcodec_fw_release(dev->fw_handler); return 0; } --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 A61DDC433F5 for ; Mon, 17 Jan 2022 12:06:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239648AbiAQMGp (ORCPT ); Mon, 17 Jan 2022 07:06:45 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:48376 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239612AbiAQMGk (ORCPT ); Mon, 17 Jan 2022 07:06:40 -0500 X-UUID: fefabd2c47f744a3b580c55ea3398224-20220117 X-UUID: fefabd2c47f744a3b580c55ea3398224-20220117 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 886296169; Mon, 17 Jan 2022 20:06:37 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:35 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:34 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 05/10] media: mtk-vcodec: mtk-vcodec: Rewrite venc power manage interface Date: Mon, 17 Jan 2022 20:06:10 +0800 Message-ID: <20220117120615.21687-6-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The args "struct mtk_vcodec_dev *" doesn't appropriate for init_clk functions because of sub-devices. For main device, it has no "pm/clk" properties in dtsi, sub-devices will init their own "pm/clk" instead. So rewrite the pm interface with args "platform_device *" and "mtk_vcodec_pm*". Signed-off-by: Irui Wang --- drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c | 9 +++++++++ drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 2 +- drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 9 ++------- drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 4 ++-- 4 files changed, 14 insertions(+), 10 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c b/driv= ers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c index d84914f615a5..3835b9f458bf 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c @@ -13,6 +13,7 @@ #include "mtk_vcodec_drv.h" #include "mtk_vcodec_enc.h" #include "mtk_vcodec_enc_core.h" +#include "mtk_vcodec_enc_pm.h" =20 static const struct of_device_id mtk_venc_core_ids[] =3D { { @@ -95,6 +96,13 @@ static int mtk_venc_core_probe(struct platform_device *p= dev) =20 core->plat_dev =3D pdev; =20 + ret =3D mtk_vcodec_init_enc_clk(core->plat_dev, &core->pm); + if (ret < 0) { + dev_err(&pdev->dev, "Failed to get venc core clock source!"); + return ret; + } + pm_runtime_enable(&pdev->dev); + core->reg_base =3D devm_platform_ioremap_resource(pdev, 0); if (IS_ERR(core->reg_base)) { dev_err(&pdev->dev, "Failed to get reg base"); @@ -137,6 +145,7 @@ static int mtk_venc_core_probe(struct platform_device *= pdev) return 0; =20 err: + pm_runtime_disable(core->pm.dev); return ret; } =20 diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index 9d48c604bc54..a601d534d26b 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -262,7 +262,7 @@ static int mtk_vcodec_probe(struct platform_device *pde= v) core_type =3D dev->venc_pdata->core_type; =20 if (dev->venc_pdata->core_mode =3D=3D VENC_SINGLE_CORE_MODE) { - ret =3D mtk_vcodec_init_enc_clk(dev); + ret =3D mtk_vcodec_init_enc_clk(dev->plat_dev, &dev->pm); if (ret < 0) { dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!"); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c index 7eba1a990ed7..c8a7042d7830 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c @@ -13,19 +13,15 @@ #include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_util.h" =20 -int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *mtkdev) +int mtk_vcodec_init_enc_clk(struct platform_device *pdev, + struct mtk_vcodec_pm *pm) { struct device_node *node; - struct platform_device *pdev; - struct mtk_vcodec_pm *pm; struct mtk_vcodec_clk *enc_clk; struct mtk_vcodec_clk_info *clk_info; int ret =3D 0, i =3D 0; struct device *dev; =20 - pdev =3D mtkdev->plat_dev; - pm =3D &mtkdev->pm; - memset(pm, 0, sizeof(struct mtk_vcodec_pm)); pm->dev =3D &pdev->dev; dev =3D &pdev->dev; enc_clk =3D &pm->venc_clk; @@ -42,7 +38,6 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *mtkdev) return -ENODEV; } pm->larbvenc =3D &pdev->dev; - pdev =3D mtkdev->plat_dev; pm->dev =3D &pdev->dev; =20 enc_clk->clk_num =3D of_property_count_strings(pdev->dev.of_node, diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h index bc455cefc0cd..97a394c68f4e 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h @@ -9,8 +9,8 @@ =20 #include "mtk_vcodec_drv.h" =20 -int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *dev); - +int mtk_vcodec_init_enc_clk(struct platform_device *pdev, + struct mtk_vcodec_pm *pm); void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm); void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm); =20 --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 3D514C433F5 for ; Mon, 17 Jan 2022 12:07:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239616AbiAQMHG (ORCPT ); Mon, 17 Jan 2022 07:07:06 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:48456 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239622AbiAQMGn (ORCPT ); Mon, 17 Jan 2022 07:06:43 -0500 X-UUID: 5b29f4de2f754f4ca724638f3879a06e-20220117 X-UUID: 5b29f4de2f754f4ca724638f3879a06e-20220117 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 78366877; Mon, 17 Jan 2022 20:06:40 +0800 Received: from mtkexhb01.mediatek.inc (172.21.101.102) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.3; Mon, 17 Jan 2022 20:06:38 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb01.mediatek.inc (172.21.101.102) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:38 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:36 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , "Tiffany Lin" , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 06/10] media: mtk-vcodec: Add venc power on/off interface Date: Mon, 17 Jan 2022 20:06:11 +0800 Message-ID: <20220117120615.21687-7-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Dual-core mode power on/off all venc available power, pm_runtime_xx helper is not appropriate called directly, add new power on/off interface for it. Signed-off-by: Irui Wang --- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 20 +---- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 7 ++ .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 83 +++++++++++++++++++ .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 5 ++ 4 files changed, 98 insertions(+), 17 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index 134dc53e4855..df231e67cdb2 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -13,6 +13,7 @@ =20 #include "mtk_vcodec_drv.h" #include "mtk_vcodec_enc.h" +#include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_intr.h" #include "mtk_vcodec_util.h" #include "venc_drv_if.h" @@ -850,7 +851,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue= *q, unsigned int count) { struct mtk_vcodec_ctx *ctx =3D vb2_get_drv_priv(q); struct venc_enc_param param; - int ret, pm_ret; + int ret; int i; =20 /* Once state turn into MTK_STATE_ABORT, we need stop_streaming @@ -858,7 +859,7 @@ static int vb2ops_venc_start_streaming(struct vb2_queue= *q, unsigned int count) */ if ((ctx->state =3D=3D MTK_STATE_ABORT) || (ctx->state =3D=3D MTK_STATE_F= REE)) { ret =3D -EIO; - goto err_start_stream; + goto err_set_param; } =20 /* Do the initialization when both start_streaming have been called */ @@ -870,12 +871,6 @@ static int vb2ops_venc_start_streaming(struct vb2_queu= e *q, unsigned int count) return 0; } =20 - ret =3D pm_runtime_resume_and_get(&ctx->dev->plat_dev->dev); - if (ret < 0) { - mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret); - goto err_start_stream; - } - mtk_venc_set_param(ctx, ¶m); ret =3D venc_if_set_param(ctx, VENC_SET_PARAM_ENC, ¶m); if (ret) { @@ -902,11 +897,6 @@ static int vb2ops_venc_start_streaming(struct vb2_queu= e *q, unsigned int count) return 0; =20 err_set_param: - pm_ret =3D pm_runtime_put(&ctx->dev->plat_dev->dev); - if (pm_ret < 0) - mtk_v4l2_err("pm_runtime_put fail %d", pm_ret); - -err_start_stream: for (i =3D 0; i < q->num_buffers; ++i) { struct vb2_buffer *buf =3D vb2_get_buffer(q, i); =20 @@ -989,10 +979,6 @@ static void vb2ops_venc_stop_streaming(struct vb2_queu= e *q) if (ret) mtk_v4l2_err("venc_if_deinit failed=3D%d", ret); =20 - ret =3D pm_runtime_put(&ctx->dev->plat_dev->dev); - if (ret < 0) - mtk_v4l2_err("pm_runtime_put fail %d", ret); - ctx->state =3D MTK_STATE_FREE; } =20 diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index a601d534d26b..cef134bb6e83 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -174,6 +174,12 @@ static int fops_vcodec_open(struct file *file) mtk_v4l2_debug(0, "encoder capability %x", dev->enc_capability); } =20 + ret =3D mtk_vcodec_enc_pw_on(dev); + if (ret < 0) { + mtk_v4l2_err("encoder power on failed %d", ret); + goto err_load_fw; + } + mtk_v4l2_debug(2, "Create instance [%d]@%p m2m_ctx=3D%p ", ctx->id, ctx, ctx->m2m_ctx); =20 @@ -208,6 +214,7 @@ static int fops_vcodec_release(struct file *file) =20 v4l2_m2m_ctx_release(ctx->m2m_ctx); mtk_vcodec_enc_release(ctx); + mtk_vcodec_enc_pw_off(dev); v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); v4l2_ctrl_handler_free(&ctx->ctrl_hdl); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c index c8a7042d7830..dfaef884e6e3 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c @@ -10,6 +10,7 @@ #include #include =20 +#include "mtk_vcodec_enc_core.h" #include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_util.h" =20 @@ -119,3 +120,85 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk); } EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_off); + +int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev) +{ + int i, ret; + struct mtk_venc_core_dev *core; + + /* power on all available venc cores */ + for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) { + core =3D (struct mtk_venc_core_dev *)dev->enc_core_dev[i]; + if (!core) + return 0; + + ret =3D pm_runtime_resume_and_get(&core->plat_dev->dev); + if (ret < 0) { + mtk_v4l2_err("power on core[%d] fail %d", i, ret); + goto pw_on_fail; + } + } + return 0; + +pw_on_fail: + for (i -=3D 1; i >=3D 0; i--) { + core =3D (struct mtk_venc_core_dev *)dev->enc_core_dev[i]; + pm_runtime_put_sync(&core->plat_dev->dev); + } + return ret; +} + +int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev) +{ + int i, ret; + struct mtk_venc_core_dev *core; + + /* power off all available venc cores */ + for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) { + core =3D (struct mtk_venc_core_dev *)dev->enc_core_dev[i]; + if (!core) + return 0; + + ret =3D pm_runtime_put_sync(&core->plat_dev->dev); + if (ret < 0) + mtk_v4l2_err("power off core[%d] fail %d", i, ret); + } + return ret; +} + +int mtk_vcodec_enc_pw_on(struct mtk_vcodec_dev *dev) +{ + int ret; + + if (dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + ret =3D mtk_venc_core_pw_on(dev); + if (ret < 0) { + mtk_v4l2_err("venc core power on fail: %d", ret); + return ret; + } + } else { + ret =3D pm_runtime_resume_and_get(&dev->plat_dev->dev); + if (ret < 0) { + mtk_v4l2_err("pm_runtime_resume_and_get fail %d", ret); + return ret; + } + } + return 0; +} + +int mtk_vcodec_enc_pw_off(struct mtk_vcodec_dev *dev) +{ + int ret; + + if (dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + ret =3D mtk_venc_core_pw_off(dev); + if (ret < 0) + mtk_v4l2_err("venc core power off fail: %d", ret); + + } else { + ret =3D pm_runtime_put_sync(&dev->plat_dev->dev); + if (ret < 0) + mtk_v4l2_err("pm_runtime_put_sync fail %d", ret); + } + return ret; +} diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h index 97a394c68f4e..99b6b6e29e35 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h @@ -14,4 +14,9 @@ int mtk_vcodec_init_enc_clk(struct platform_device *pdev, void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm); void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm); =20 +int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev); +int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev); +int mtk_vcodec_enc_pw_on(struct mtk_vcodec_dev *dev); +int mtk_vcodec_enc_pw_off(struct mtk_vcodec_dev *dev); + #endif /* _MTK_VCODEC_ENC_PM_H_ */ --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 9F9E9C433F5 for ; Mon, 17 Jan 2022 12:06:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239615AbiAQMGr (ORCPT ); Mon, 17 Jan 2022 07:06:47 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:37034 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239636AbiAQMGp (ORCPT ); Mon, 17 Jan 2022 07:06:45 -0500 X-UUID: 4231c94e96db4edf8439762bc09b432d-20220117 X-UUID: 4231c94e96db4edf8439762bc09b432d-20220117 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 813468978; Mon, 17 Jan 2022 20:06:41 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:39 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:38 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 07/10] media: mtk-vcodec: Rewrite venc clock interface Date: Mon, 17 Jan 2022 20:06:12 +0800 Message-ID: <20220117120615.21687-8-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Dual core mode need enable the specific core's clk, add an another param for clock_on/clock_off interface. Signed-off-by: Irui Wang --- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.c | 96 ++++++++++++++++--- .../platform/mtk-vcodec/mtk_vcodec_enc_pm.h | 4 +- .../media/platform/mtk-vcodec/venc_drv_if.c | 10 +- 3 files changed, 86 insertions(+), 24 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c index dfaef884e6e3..4e37d68f75dd 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.c @@ -83,17 +83,42 @@ int mtk_vcodec_init_enc_clk(struct platform_device *pde= v, } EXPORT_SYMBOL_GPL(mtk_vcodec_init_enc_clk); =20 -void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) +void mtk_vcodec_enc_clock_on(struct mtk_vcodec_dev *dev, int core_id) { - struct mtk_vcodec_clk *enc_clk =3D &pm->venc_clk; + struct mtk_venc_core_dev *core; + struct mtk_vcodec_pm *enc_pm; + struct mtk_vcodec_clk *enc_clk; + struct clk *clk; int ret, i =3D 0; =20 - for (i =3D 0; i < enc_clk->clk_num; i++) { - ret =3D clk_prepare_enable(enc_clk->clk_info[i].vcodec_clk); - if (ret) { - mtk_v4l2_err("venc clk_prepare_enable %d %s fail %d", i, - enc_clk->clk_info[i].clk_name, ret); - goto clkerr; + if (dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + core =3D (struct mtk_venc_core_dev *)dev->enc_core_dev[core_id]; + enc_pm =3D &core->pm; + enc_clk =3D &enc_pm->venc_clk; + + for (i =3D 0; i < enc_clk->clk_num; i++) { + clk =3D enc_clk->clk_info[i].vcodec_clk; + ret =3D clk_enable(clk); + if (ret) { + mtk_v4l2_err("clk_enable %d %s fail %d", i, + enc_clk->clk_info[i].clk_name, + ret); + goto core_clk_err; + } + } + } else { + enc_pm =3D &dev->pm; + enc_clk =3D &enc_pm->venc_clk; + + for (i =3D 0; i < enc_clk->clk_num; i++) { + clk =3D enc_clk->clk_info[i].vcodec_clk; + ret =3D clk_prepare_enable(clk); + if (ret) { + mtk_v4l2_err("clk_prepare %d %s fail %d", + i, enc_clk->clk_info[i].clk_name, + ret); + goto clkerr; + } } } =20 @@ -104,27 +129,49 @@ void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) } return; =20 +core_clk_err: + for (i -=3D 1; i >=3D 0; i--) + clk_disable(enc_clk->clk_info[i].vcodec_clk); + + return; + clkerr: for (i -=3D 1; i >=3D 0; i--) clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk); } EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_on); =20 -void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm) +void mtk_vcodec_enc_clock_off(struct mtk_vcodec_dev *dev, int core_id) { - struct mtk_vcodec_clk *enc_clk =3D &pm->venc_clk; + struct mtk_venc_core_dev *core; + struct mtk_vcodec_pm *enc_pm; + struct mtk_vcodec_clk *enc_clk; int i =3D 0; =20 mtk_smi_larb_put(pm->larbvenc); - for (i =3D enc_clk->clk_num - 1; i >=3D 0; i--) - clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk); + + if (dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + core =3D (struct mtk_venc_core_dev *)dev->enc_core_dev[core_id]; + enc_pm =3D &core->pm; + enc_clk =3D &enc_pm->venc_clk; + + for (i =3D enc_clk->clk_num - 1; i >=3D 0; i--) + clk_disable(enc_clk->clk_info[i].vcodec_clk); + } else { + enc_pm =3D &dev->pm; + enc_clk =3D &enc_pm->venc_clk; + + for (i =3D enc_clk->clk_num - 1; i >=3D 0; i--) + clk_disable_unprepare(enc_clk->clk_info[i].vcodec_clk); + } } EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_off); =20 int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev) { - int i, ret; + int i, ret, j =3D 0; struct mtk_venc_core_dev *core; + struct mtk_vcodec_clk *clk; =20 /* power on all available venc cores */ for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) { @@ -137,12 +184,28 @@ int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev) mtk_v4l2_err("power on core[%d] fail %d", i, ret); goto pw_on_fail; } + + clk =3D &core->pm.venc_clk; + for (j =3D 0; j < clk->clk_num; j++) { + ret =3D clk_prepare(clk->clk_info[j].vcodec_clk); + if (ret) { + mtk_v4l2_err("prepare clk [%s] fail %d", + clk->clk_info[j].clk_name, + ret); + goto pw_on_fail; + } + } } return 0; =20 pw_on_fail: for (i -=3D 1; i >=3D 0; i--) { core =3D (struct mtk_venc_core_dev *)dev->enc_core_dev[i]; + + clk =3D &core->pm.venc_clk; + for (j -=3D 1; j >=3D 0; j--) + clk_unprepare(clk->clk_info[j].vcodec_clk); + pm_runtime_put_sync(&core->plat_dev->dev); } return ret; @@ -150,8 +213,9 @@ int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev) =20 int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev) { - int i, ret; + int i, ret, j; struct mtk_venc_core_dev *core; + struct mtk_vcodec_clk *clk; =20 /* power off all available venc cores */ for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) { @@ -159,6 +223,10 @@ int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev) if (!core) return 0; =20 + clk =3D &core->pm.venc_clk; + for (j =3D clk->clk_num - 1; j >=3D 0; j--) + clk_unprepare(clk->clk_info[j].vcodec_clk); + ret =3D pm_runtime_put_sync(&core->plat_dev->dev); if (ret < 0) mtk_v4l2_err("power off core[%d] fail %d", i, ret); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h index 99b6b6e29e35..5113ed8a869e 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_pm.h @@ -11,8 +11,8 @@ =20 int mtk_vcodec_init_enc_clk(struct platform_device *pdev, struct mtk_vcodec_pm *pm); -void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm); -void mtk_vcodec_enc_clock_off(struct mtk_vcodec_pm *pm); +void mtk_vcodec_enc_clock_on(struct mtk_vcodec_dev *dev, int core_id); +void mtk_vcodec_enc_clock_off(struct mtk_vcodec_dev *dev, int core_id); =20 int mtk_venc_core_pw_on(struct mtk_vcodec_dev *dev); int mtk_venc_core_pw_off(struct mtk_vcodec_dev *dev); diff --git a/drivers/media/platform/mtk-vcodec/venc_drv_if.c b/drivers/medi= a/platform/mtk-vcodec/venc_drv_if.c index ce0bce811615..6cbdb7e30bb3 100644 --- a/drivers/media/platform/mtk-vcodec/venc_drv_if.c +++ b/drivers/media/platform/mtk-vcodec/venc_drv_if.c @@ -32,9 +32,7 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int= fourcc) } =20 mtk_venc_lock(ctx); - mtk_vcodec_enc_clock_on(&ctx->dev->pm); ret =3D ctx->enc_if->init(ctx); - mtk_vcodec_enc_clock_off(&ctx->dev->pm); mtk_venc_unlock(ctx); =20 return ret; @@ -46,9 +44,7 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx, int ret =3D 0; =20 mtk_venc_lock(ctx); - mtk_vcodec_enc_clock_on(&ctx->dev->pm); ret =3D ctx->enc_if->set_param(ctx->drv_handle, type, in); - mtk_vcodec_enc_clock_off(&ctx->dev->pm); mtk_venc_unlock(ctx); =20 return ret; @@ -68,10 +64,10 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx, ctx->dev->curr_ctx =3D ctx; spin_unlock_irqrestore(&ctx->dev->irqlock, flags); =20 - mtk_vcodec_enc_clock_on(&ctx->dev->pm); + mtk_vcodec_enc_clock_on(ctx->dev, 0); ret =3D ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf, bs_buf, result); - mtk_vcodec_enc_clock_off(&ctx->dev->pm); + mtk_vcodec_enc_clock_off(ctx->dev, 0); =20 spin_lock_irqsave(&ctx->dev->irqlock, flags); ctx->dev->curr_ctx =3D NULL; @@ -89,9 +85,7 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx) return 0; =20 mtk_venc_lock(ctx); - mtk_vcodec_enc_clock_on(&ctx->dev->pm); ret =3D ctx->enc_if->deinit(ctx->drv_handle); - mtk_vcodec_enc_clock_off(&ctx->dev->pm); mtk_venc_unlock(ctx); =20 ctx->drv_handle =3D NULL; --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 EDFD9C433FE for ; Mon, 17 Jan 2022 12:06:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239706AbiAQMGx (ORCPT ); Mon, 17 Jan 2022 07:06:53 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:48574 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239664AbiAQMGr (ORCPT ); Mon, 17 Jan 2022 07:06:47 -0500 X-UUID: fb6c3020c285472d8500345e07c2484b-20220117 X-UUID: fb6c3020c285472d8500345e07c2484b-20220117 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 895678421; Mon, 17 Jan 2022 20:06:43 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n2.mediatek.inc (172.21.101.141) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:41 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:40 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 08/10] media: mtk-vcodec: Add more extra processing for dual-core mode Date: Mon, 17 Jan 2022 20:06:13 +0800 Message-ID: <20220117120615.21687-9-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Dual core mode encoding need more venc working buffers, it will break the compatibility if we just add venc_vsi in AP-Kernel but not in firmware, so add more struct definition for it. Signed-off-by: Irui Wang --- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 1 + .../platform/mtk-vcodec/mtk_vcodec_util.c | 19 ++ .../platform/mtk-vcodec/mtk_vcodec_util.h | 4 + .../platform/mtk-vcodec/venc/venc_h264_if.c | 178 +++++++++++++++--- 4 files changed, 177 insertions(+), 25 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index 9e4e4290a69a..dc036279c42f 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -452,6 +452,7 @@ struct mtk_vcodec_enc_pdata { }; =20 #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext) +#define MTK_ENC_CORE_MODE(ctx) ((ctx)->dev->venc_pdata->core_mode) =20 /** * struct mtk_vcodec_dev - driver data diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_util.c index ace78c4b5b9e..059f665afa96 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.c @@ -11,6 +11,7 @@ =20 #include "mtk_vcodec_dec_hw.h" #include "mtk_vcodec_drv.h" +#include "mtk_vcodec_enc_core.h" #include "mtk_vcodec_util.h" =20 void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, @@ -26,6 +27,24 @@ void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_= ctx *data, } EXPORT_SYMBOL(mtk_vcodec_get_reg_addr); =20 +void __iomem *mtk_venc_get_core_reg_addr(struct mtk_vcodec_ctx *ctx, + unsigned int core_id) +{ + struct mtk_venc_core_dev *core; + + if (core_id >=3D MTK_VENC_CORE_MAX) { + mtk_v4l2_err("Invalid core_id =3D %d", core_id); + return NULL; + } + + core =3D (struct mtk_venc_core_dev *)ctx->dev->enc_core_dev[core_id]; + if (!core) + return NULL; + + return core->reg_base; +} +EXPORT_SYMBOL(mtk_venc_get_core_reg_addr); + int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, struct mtk_vcodec_mem *mem) { diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_util.h index 71956627a0e2..de9e18688842 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h @@ -50,6 +50,10 @@ struct mtk_vcodec_dev; =20 void __iomem *mtk_vcodec_get_reg_addr(struct mtk_vcodec_ctx *data, unsigned int reg_idx); + +void __iomem *mtk_venc_get_core_reg_addr(struct mtk_vcodec_ctx *data, + unsigned int core_id); + int mtk_vcodec_mem_alloc(struct mtk_vcodec_ctx *data, struct mtk_vcodec_mem *mem); void mtk_vcodec_mem_free(struct mtk_vcodec_ctx *data, diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c b/driver= s/media/platform/mtk-vcodec/venc/venc_h264_if.c index 4d9b8798dffe..023b6eb8b20c 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c @@ -50,6 +50,24 @@ enum venc_h264_vpu_work_buf { VENC_H264_VPU_WORK_BUF_MAX, }; =20 +/* + * enum venc_dual_core_work_buf - h264 dual core encoder buffer index + */ +enum venc_dual_core_work_buf { + VENC_DUAL_CORE_WORK_BUF_RC_INFO_CORE0, + VENC_DUAL_CORE_WORK_BUF_RC_CODE, + VENC_DUAL_CORE_WORK_BUF_REC_LUMA, + VENC_DUAL_CORE_WORK_BUF_REC_CHROMA, + VENC_DUAL_CORE_WORK_BUF_REF_LUMA, + VENC_DUAL_CORE_WORK_BUF_REF_CHROMA, + VENC_DUAL_CORE_WORK_BUF_MV_INFO_1, + VENC_DUAL_CORE_WORK_BUF_MV_INFO_2, + VENC_DUAL_CORE_WORK_BUF_SKIP_FRAME, + VENC_DUAL_CORE_WORK_BUF_RC_INFO_CORE1, + VENC_DUAL_CORE_WORK_BUF_FR_RC_INFO, + VENC_DUAL_CORE_WORK_BUF_MAX, +}; + /* * enum venc_h264_bs_mode - for bs_mode argument in h264_enc_vpu_encode */ @@ -94,6 +112,24 @@ struct venc_h264_vpu_config { u32 wfd; }; =20 +struct venc_dual_core_config { + u32 input_fourcc; + u32 bitrate; + u32 pic_w; + u32 pic_h; + u32 buf_w; + u32 buf_h; + u32 gop_size; + u32 intra_period; + u32 framerate; + u32 profile; + u32 level; + u32 wfd; + u32 max_qp; + u32 min_qp; + u32 reserved[8]; +}; + /* * struct venc_h264_vpu_buf - Structure for buffer information * AP-W/R : AP is writer/reader on this item @@ -127,6 +163,11 @@ struct venc_h264_vsi { struct venc_h264_vpu_buf work_bufs[VENC_H264_VPU_WORK_BUF_MAX]; }; =20 +struct venc_dual_core_vsi { + struct venc_dual_core_config config; + struct venc_h264_vpu_buf work_bufs[VENC_DUAL_CORE_WORK_BUF_MAX]; +}; + /* * struct venc_h264_inst - h264 encoder AP driver instance * @hw_base: h264 encoder hardware register base @@ -143,8 +184,8 @@ struct venc_h264_vsi { * @ctx: context for v4l2 layer integration */ struct venc_h264_inst { - void __iomem *hw_base; - struct mtk_vcodec_mem work_bufs[VENC_H264_VPU_WORK_BUF_MAX]; + void __iomem *hw_base[MTK_VENC_CORE_MAX]; + struct mtk_vcodec_mem work_bufs[VENC_DUAL_CORE_WORK_BUF_MAX]; struct mtk_vcodec_mem pps_buf; bool work_buf_allocated; unsigned int frm_cnt; @@ -152,12 +193,13 @@ struct venc_h264_inst { unsigned int prepend_hdr; struct venc_vpu_inst vpu_inst; struct venc_h264_vsi *vsi; + struct venc_dual_core_vsi *core_vsi; struct mtk_vcodec_ctx *ctx; }; =20 static inline u32 h264_read_reg(struct venc_h264_inst *inst, u32 addr) { - return readl(inst->hw_base + addr); + return readl(inst->hw_base[MTK_VENC_CORE0] + addr); } =20 static unsigned int h264_get_profile(struct venc_h264_inst *inst, @@ -228,13 +270,21 @@ static unsigned int h264_get_level(struct venc_h264_i= nst *inst, static void h264_enc_free_work_buf(struct venc_h264_inst *inst) { int i; + struct mtk_vcodec_ctx *ctx =3D inst->ctx; + int max_work_buf; + bool is_dual_core =3D (MTK_ENC_CORE_MODE(ctx) =3D=3D VENC_DUAL_CORE_MODE); =20 mtk_vcodec_debug_enter(inst); =20 + if (is_dual_core) + max_work_buf =3D VENC_DUAL_CORE_WORK_BUF_MAX; + else + max_work_buf =3D VENC_H264_VPU_WORK_BUF_MAX; + /* Except the SKIP_FRAME buffers, * other buffers need to be freed by AP. */ - for (i =3D 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) { + for (i =3D 0; i < max_work_buf; i++) { if (i !=3D VENC_H264_VPU_WORK_BUF_SKIP_FRAME) mtk_vcodec_mem_free(inst->ctx, &inst->work_bufs[i]); } @@ -248,11 +298,22 @@ static int h264_enc_alloc_work_buf(struct venc_h264_i= nst *inst) { int i; int ret =3D 0; - struct venc_h264_vpu_buf *wb =3D inst->vsi->work_bufs; + struct mtk_vcodec_ctx *ctx =3D inst->ctx; + struct venc_h264_vpu_buf *wb; + int max_work_buf; + bool is_dual_core =3D (MTK_ENC_CORE_MODE(ctx) =3D=3D VENC_DUAL_CORE_MODE); =20 mtk_vcodec_debug_enter(inst); =20 - for (i =3D 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) { + if (is_dual_core) { + wb =3D inst->core_vsi->work_bufs; + max_work_buf =3D VENC_DUAL_CORE_WORK_BUF_MAX; + } else { + wb =3D inst->vsi->work_bufs; + max_work_buf =3D VENC_H264_VPU_WORK_BUF_MAX; + } + + for (i =3D 0; i < max_work_buf; i++) { /* * This 'wb' structure is set by VPU side and shared to AP for * buffer allocation and IO virtual addr mapping. For most of @@ -358,6 +419,26 @@ static int h264_frame_type(struct venc_h264_inst *inst) return VENC_H264_P_FRM; /* Note: B frames are not supported */ } } + +static int h264_core_frame_type(struct venc_h264_inst *inst) +{ + struct venc_dual_core_vsi *vsi =3D inst->core_vsi; + + if ((vsi->config.gop_size !=3D 0 && + (inst->frm_cnt % vsi->config.gop_size) =3D=3D 0) || + (inst->frm_cnt =3D=3D 0 && vsi->config.gop_size =3D=3D 0)) { + /* IDR frame */ + return VENC_H264_IDR_FRM; + } else if ((vsi->config.intra_period !=3D 0 && + (inst->frm_cnt % vsi->config.intra_period) =3D=3D 0) || + (inst->frm_cnt =3D=3D 0 && vsi->config.intra_period =3D=3D 0)) { + /* I frame */ + return VENC_H264_I_FRM; + } else { + return VENC_H264_P_FRM; /* Note: B frames are not supported */ + } +} + static int h264_encode_sps(struct venc_h264_inst *inst, struct mtk_vcodec_mem *bs_buf, unsigned int *bs_size) @@ -440,12 +521,18 @@ static int h264_encode_frame(struct venc_h264_inst *i= nst, int ret =3D 0; unsigned int irq_status; struct venc_frame_info frame_info; + struct mtk_vcodec_ctx *ctx =3D inst->ctx; + bool is_dual_core =3D (MTK_ENC_CORE_MODE(ctx) =3D=3D VENC_DUAL_CORE_MODE); =20 mtk_vcodec_debug_enter(inst); mtk_vcodec_debug(inst, "frm_cnt =3D %d\n ", inst->frm_cnt); frame_info.frm_count =3D inst->frm_cnt; frame_info.skip_frm_count =3D inst->skip_frm_cnt; - frame_info.frm_type =3D h264_frame_type(inst); + if (is_dual_core) + frame_info.frm_type =3D h264_core_frame_type(inst); + else + frame_info.frm_type =3D h264_frame_type(inst); + mtk_vcodec_debug(inst, "frm_count =3D %d,skip_frm_count =3D%d,frm_type=3D= %d.\n", frame_info.frm_count, frame_info.skip_frm_count, frame_info.frm_type); @@ -501,7 +588,8 @@ static void h264_encode_filler(struct venc_h264_inst *i= nst, void *buf, static int h264_enc_init(struct mtk_vcodec_ctx *ctx) { const bool is_ext =3D MTK_ENC_CTX_IS_EXT(ctx); - int ret =3D 0; + bool is_dual_core =3D (MTK_ENC_CORE_MODE(ctx) =3D=3D VENC_DUAL_CORE_MODE); + int ret, i =3D 0; struct venc_h264_inst *inst; =20 inst =3D kzalloc(sizeof(*inst), GFP_KERNEL); @@ -511,13 +599,22 @@ static int h264_enc_init(struct mtk_vcodec_ctx *ctx) inst->ctx =3D ctx; inst->vpu_inst.ctx =3D ctx; inst->vpu_inst.id =3D is_ext ? SCP_IPI_VENC_H264 : IPI_VENC_H264; - inst->hw_base =3D mtk_vcodec_get_reg_addr(inst->ctx, VENC_SYS); =20 mtk_vcodec_debug_enter(inst); =20 ret =3D vpu_enc_init(&inst->vpu_inst); =20 - inst->vsi =3D (struct venc_h264_vsi *)inst->vpu_inst.vsi; + if (is_dual_core) { + inst->core_vsi =3D + (struct venc_dual_core_vsi *)inst->vpu_inst.vsi; + for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) + inst->hw_base[i] =3D + mtk_venc_get_core_reg_addr(inst->ctx, i); + + } else { + inst->vsi =3D (struct venc_h264_vsi *)inst->vpu_inst.vsi; + inst->hw_base[0] =3D mtk_vcodec_get_reg_addr(inst->ctx, VENC_SYS); + } =20 mtk_vcodec_debug_leave(inst); =20 @@ -624,31 +721,62 @@ static int h264_enc_encode(void *handle, return ret; } =20 +static void h264_enc_set_configs(struct venc_h264_inst *inst, + struct venc_enc_param *enc_prm) +{ + inst->vsi->config.input_fourcc =3D enc_prm->input_yuv_fmt; + inst->vsi->config.bitrate =3D enc_prm->bitrate; + inst->vsi->config.pic_w =3D enc_prm->width; + inst->vsi->config.pic_h =3D enc_prm->height; + inst->vsi->config.buf_w =3D enc_prm->buf_width; + inst->vsi->config.buf_h =3D enc_prm->buf_height; + inst->vsi->config.gop_size =3D enc_prm->gop_size; + inst->vsi->config.framerate =3D enc_prm->frm_rate; + inst->vsi->config.intra_period =3D enc_prm->intra_period; + inst->vsi->config.profile =3D + h264_get_profile(inst, enc_prm->h264_profile); + inst->vsi->config.level =3D + h264_get_level(inst, enc_prm->h264_level); + inst->vsi->config.wfd =3D 0; +} + +static void h264_enc_set_core_configs(struct venc_h264_inst *inst, + struct venc_enc_param *enc_prm) +{ + inst->core_vsi->config.input_fourcc =3D enc_prm->input_yuv_fmt; + inst->core_vsi->config.bitrate =3D enc_prm->bitrate; + inst->core_vsi->config.pic_w =3D enc_prm->width; + inst->core_vsi->config.pic_h =3D enc_prm->height; + inst->core_vsi->config.buf_w =3D enc_prm->buf_width; + inst->core_vsi->config.buf_h =3D enc_prm->buf_height; + inst->core_vsi->config.gop_size =3D enc_prm->gop_size; + inst->core_vsi->config.framerate =3D enc_prm->frm_rate; + inst->core_vsi->config.intra_period =3D enc_prm->intra_period; + inst->core_vsi->config.profile =3D + h264_get_profile(inst, enc_prm->h264_profile); + inst->core_vsi->config.level =3D + h264_get_level(inst, enc_prm->h264_level); + inst->core_vsi->config.wfd =3D 0; +} + static int h264_enc_set_param(void *handle, enum venc_set_param_type type, struct venc_enc_param *enc_prm) { int ret =3D 0; struct venc_h264_inst *inst =3D (struct venc_h264_inst *)handle; + struct mtk_vcodec_ctx *ctx =3D inst->ctx; + bool is_dual_core =3D (MTK_ENC_CORE_MODE(ctx) =3D=3D VENC_DUAL_CORE_MODE); =20 - mtk_vcodec_debug(inst, "->type=3D%d", type); + mtk_vcodec_debug(inst, "->type=3D%d, dual_core=3D%d", type, is_dual_core); =20 switch (type) { case VENC_SET_PARAM_ENC: - inst->vsi->config.input_fourcc =3D enc_prm->input_yuv_fmt; - inst->vsi->config.bitrate =3D enc_prm->bitrate; - inst->vsi->config.pic_w =3D enc_prm->width; - inst->vsi->config.pic_h =3D enc_prm->height; - inst->vsi->config.buf_w =3D enc_prm->buf_width; - inst->vsi->config.buf_h =3D enc_prm->buf_height; - inst->vsi->config.gop_size =3D enc_prm->gop_size; - inst->vsi->config.framerate =3D enc_prm->frm_rate; - inst->vsi->config.intra_period =3D enc_prm->intra_period; - inst->vsi->config.profile =3D - h264_get_profile(inst, enc_prm->h264_profile); - inst->vsi->config.level =3D - h264_get_level(inst, enc_prm->h264_level); - inst->vsi->config.wfd =3D 0; + if (is_dual_core) + h264_enc_set_core_configs(inst, enc_prm); + else + h264_enc_set_configs(inst, enc_prm); + ret =3D vpu_enc_set_param(&inst->vpu_inst, type, enc_prm); if (ret) break; --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 E313BC433F5 for ; Mon, 17 Jan 2022 12:07:04 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239760AbiAQMHD (ORCPT ); Mon, 17 Jan 2022 07:07:03 -0500 Received: from mailgw01.mediatek.com ([60.244.123.138]:48574 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239667AbiAQMGt (ORCPT ); Mon, 17 Jan 2022 07:06:49 -0500 X-UUID: 34f2768e457a4dc79579b52bfe8c1f1a-20220117 X-UUID: 34f2768e457a4dc79579b52bfe8c1f1a-20220117 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 633297809; Mon, 17 Jan 2022 20:06:46 +0800 Received: from mtkexhb01.mediatek.inc (172.21.101.102) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 17 Jan 2022 20:06:45 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb01.mediatek.inc (172.21.101.102) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:44 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:43 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , "Tiffany Lin" , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 09/10] media: mtk-vcodec: Add dual core mode encode process Date: Mon, 17 Jan 2022 20:06:14 +0800 Message-ID: <20220117120615.21687-10-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" The dual core mode encoding is tries to uses the two venc cores: frame#0 uses core#0, frame#1 uses core#1, frame#2 uses core#0..., Lock the device and enable the clock by used core, for sequence header encoding, it always uses core#0. Signed-off-by: Irui Wang --- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 11 ++- .../platform/mtk-vcodec/mtk_vcodec_enc.c | 23 +++--- .../platform/mtk-vcodec/mtk_vcodec_enc.h | 4 +- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 7 +- .../platform/mtk-vcodec/venc/venc_h264_if.c | 16 ++-- .../platform/mtk-vcodec/venc/venc_vp8_if.c | 3 +- .../media/platform/mtk-vcodec/venc_drv_if.c | 73 ++++++++++++++----- .../media/platform/mtk-vcodec/venc_drv_if.h | 5 ++ .../media/platform/mtk-vcodec/venc_vpu_if.c | 10 ++- .../media/platform/mtk-vcodec/venc_vpu_if.h | 3 +- 10 files changed, 113 insertions(+), 42 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index dc036279c42f..c3cf5904b4c6 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -308,6 +308,9 @@ struct vdec_pic_info { * @max_width: hardware supported max width * @max_height: hardware supported max height * @msg_queue: msg queue used to store lat buffer information. + * @q_mutex: src & dst vb2_queue mutex + * @enc_idx: used to record encoded frame count + * @core_id: used to reoord used core */ struct mtk_vcodec_ctx { enum mtk_instance_type type; @@ -356,6 +359,10 @@ struct mtk_vcodec_ctx { unsigned int max_width; unsigned int max_height; struct vdec_msg_queue msg_queue; + + struct mutex q_mutex; + int enc_idx; + int core_id; }; =20 /* @@ -533,7 +540,9 @@ struct mtk_vcodec_dev { =20 /* decoder hardware mutex lock */ struct mutex dec_mutex[MTK_VDEC_HW_MAX]; - struct mutex enc_mutex; + + /* encoder core mutex lock */ + struct mutex enc_mutex[MTK_VENC_CORE_MAX]; =20 struct mtk_vcodec_pm pm; unsigned int dec_capability; diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index df231e67cdb2..dc70d328fcd3 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -1198,14 +1198,17 @@ static void mtk_venc_worker(struct work_struct *wor= k) vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR); mtk_v4l2_err("venc_if_encode failed=3D%d", ret); - } else { + } else if (ctx->dev->venc_pdata->core_mode =3D=3D VENC_SINGLE_CORE_MODE) { v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); - vb2_set_plane_payload(&dst_buf->vb2_buf, 0, enc_result.bs_size); + vb2_set_plane_payload(&dst_buf->vb2_buf, 0, + enc_result.bs_size); v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); mtk_v4l2_debug(2, "venc_if_encode bs size=3D%d", - enc_result.bs_size); + enc_result.bs_size); } =20 + ctx->enc_idx++; + v4l2_m2m_job_finish(ctx->dev->m2m_dev_enc, ctx->m2m_ctx); =20 mtk_v4l2_debug(1, "<=3D=3D=3D src_buf[%d] dst_buf[%d] venc_if_encode ret= =3D%d Size=3D%u=3D=3D=3D>", @@ -1259,7 +1262,7 @@ void mtk_vcodec_enc_set_default_params(struct mtk_vco= dec_ctx *ctx) { struct mtk_q_data *q_data; =20 - ctx->m2m_ctx->q_lock =3D &ctx->dev->dev_mutex; + ctx->m2m_ctx->q_lock =3D &ctx->q_mutex; ctx->fh.m2m_ctx =3D ctx->m2m_ctx; ctx->fh.ctrl_handler =3D &ctx->ctrl_hdl; INIT_WORK(&ctx->encode_work, mtk_venc_worker); @@ -1391,7 +1394,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_= queue *src_vq, src_vq->ops =3D &mtk_venc_vb2_ops; src_vq->mem_ops =3D &vb2_dma_contig_memops; src_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; - src_vq->lock =3D &ctx->dev->dev_mutex; + src_vq->lock =3D &ctx->q_mutex; src_vq->dev =3D &ctx->dev->plat_dev->dev; =20 ret =3D vb2_queue_init(src_vq); @@ -1405,26 +1408,26 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb= 2_queue *src_vq, dst_vq->ops =3D &mtk_venc_vb2_ops; dst_vq->mem_ops =3D &vb2_dma_contig_memops; dst_vq->timestamp_flags =3D V4L2_BUF_FLAG_TIMESTAMP_COPY; - dst_vq->lock =3D &ctx->dev->dev_mutex; + dst_vq->lock =3D &ctx->q_mutex; dst_vq->dev =3D &ctx->dev->plat_dev->dev; =20 return vb2_queue_init(dst_vq); } =20 -int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx) +int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx, int core_id) { struct mtk_vcodec_dev *dev =3D ctx->dev; =20 - mutex_unlock(&dev->enc_mutex); + mutex_unlock(&dev->enc_mutex[core_id]); return 0; } EXPORT_SYMBOL_GPL(mtk_venc_unlock); =20 -int mtk_venc_lock(struct mtk_vcodec_ctx *ctx) +int mtk_venc_lock(struct mtk_vcodec_ctx *ctx, int core_id) { struct mtk_vcodec_dev *dev =3D ctx->dev; =20 - mutex_lock(&dev->enc_mutex); + mutex_lock(&dev->enc_mutex[core_id]); return 0; } EXPORT_SYMBOL_GPL(mtk_venc_lock); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.h index 513ee7993e34..434d91d36158 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h @@ -39,8 +39,8 @@ struct mtk_video_enc_buf { extern const struct v4l2_ioctl_ops mtk_venc_ioctl_ops; extern const struct v4l2_m2m_ops mtk_venc_m2m_ops; =20 -int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx); -int mtk_venc_lock(struct mtk_vcodec_ctx *ctx); +int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx, int core_id); +int mtk_venc_lock(struct mtk_vcodec_ctx *ctx, int core_id); int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq); void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *ctx); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index cef134bb6e83..cf42a5930b48 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -133,6 +133,7 @@ static int fops_vcodec_open(struct file *file) INIT_LIST_HEAD(&ctx->list); ctx->dev =3D dev; init_waitqueue_head(&ctx->queue[0]); + mutex_init(&ctx->q_mutex); =20 ctx->type =3D MTK_INST_ENCODER; ret =3D mtk_vcodec_enc_ctrls_setup(ctx); @@ -240,7 +241,7 @@ static int mtk_vcodec_probe(struct platform_device *pde= v) struct video_device *vfd_enc; phandle rproc_phandle; enum mtk_vcodec_fw_type fw_type; - int ret, core_type; + int ret, core_type, i; =20 dev =3D devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -299,7 +300,9 @@ static int mtk_vcodec_probe(struct platform_device *pde= v) } } =20 - mutex_init(&dev->enc_mutex); + for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) + mutex_init(&dev->enc_mutex[i]); + mutex_init(&dev->dev_mutex); spin_lock_init(&dev->irqlock); =20 diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c b/driver= s/media/platform/mtk-vcodec/venc/venc_h264_if.c index 023b6eb8b20c..fdecf1d24b25 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c @@ -448,7 +448,8 @@ static int h264_encode_sps(struct venc_h264_inst *inst, =20 mtk_vcodec_debug_enter(inst); =20 - ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_SPS, NULL, bs_buf, N= ULL); + ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_SPS, + NULL, bs_buf, NULL, MTK_VENC_CORE0); if (ret) return ret; =20 @@ -474,7 +475,8 @@ static int h264_encode_pps(struct venc_h264_inst *inst, =20 mtk_vcodec_debug_enter(inst); =20 - ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_PPS, NULL, bs_buf, N= ULL); + ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_PPS, + NULL, bs_buf, NULL, MTK_VENC_CORE0); if (ret) return ret; =20 @@ -516,7 +518,8 @@ static int h264_encode_header(struct venc_h264_inst *in= st, static int h264_encode_frame(struct venc_h264_inst *inst, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, - unsigned int *bs_size) + unsigned int *bs_size, + int core_id) { int ret =3D 0; unsigned int irq_status; @@ -536,7 +539,8 @@ static int h264_encode_frame(struct venc_h264_inst *ins= t, mtk_vcodec_debug(inst, "frm_count =3D %d,skip_frm_count =3D%d,frm_type=3D= %d.\n", frame_info.frm_count, frame_info.skip_frm_count, frame_info.frm_type); - ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_FRAME, frm_buf, bs_b= uf, &frame_info); + ret =3D vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_FRAME, + frm_buf, bs_buf, &frame_info, core_id); if (ret) return ret; =20 @@ -664,7 +668,7 @@ static int h264_enc_encode(void *handle, =20 if (!inst->prepend_hdr) { ret =3D h264_encode_frame(inst, frm_buf, bs_buf, - &result->bs_size); + &result->bs_size, ctx->core_id); if (ret) goto encode_err; result->is_key_frm =3D inst->vpu_inst.is_key_frm; @@ -692,7 +696,7 @@ static int h264_enc_encode(void *handle, tmp_bs_buf.size =3D bs_buf->size - (hdr_sz + filler_sz); =20 ret =3D h264_encode_frame(inst, frm_buf, &tmp_bs_buf, - &bs_size_frm); + &bs_size_frm, ctx->core_id); if (ret) goto encode_err; =20 diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers= /media/platform/mtk-vcodec/venc/venc_vp8_if.c index 56ce58f761f1..3b3471d90e21 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c @@ -302,7 +302,8 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *i= nst, =20 mtk_vcodec_debug(inst, "->frm_cnt=3D%d", inst->frm_cnt); =20 - ret =3D vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, NULL); + ret =3D vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, + NULL, MTK_VENC_CORE0); if (ret) return ret; =20 diff --git a/drivers/media/platform/mtk-vcodec/venc_drv_if.c b/drivers/medi= a/platform/mtk-vcodec/venc_drv_if.c index 6cbdb7e30bb3..5c5013d0f32e 100644 --- a/drivers/media/platform/mtk-vcodec/venc_drv_if.c +++ b/drivers/media/platform/mtk-vcodec/venc_drv_if.c @@ -14,6 +14,7 @@ #include "venc_drv_if.h" =20 #include "mtk_vcodec_enc.h" +#include "mtk_vcodec_enc_core.h" #include "mtk_vcodec_enc_pm.h" =20 int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) @@ -31,9 +32,9 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int= fourcc) return -EINVAL; } =20 - mtk_venc_lock(ctx); + mtk_venc_lock(ctx, ctx->core_id); ret =3D ctx->enc_if->init(ctx); - mtk_venc_unlock(ctx); + mtk_venc_unlock(ctx, ctx->core_id); =20 return ret; } @@ -43,9 +44,9 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx, { int ret =3D 0; =20 - mtk_venc_lock(ctx); + mtk_venc_lock(ctx, ctx->core_id); ret =3D ctx->enc_if->set_param(ctx->drv_handle, type, in); - mtk_venc_unlock(ctx); + mtk_venc_unlock(ctx, ctx->core_id); =20 return ret; } @@ -56,24 +57,14 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx, struct venc_done_result *result) { int ret =3D 0; - unsigned long flags; - - mtk_venc_lock(ctx); =20 - spin_lock_irqsave(&ctx->dev->irqlock, flags); - ctx->dev->curr_ctx =3D ctx; - spin_unlock_irqrestore(&ctx->dev->irqlock, flags); + venc_encode_prepare(ctx, opt); =20 - mtk_vcodec_enc_clock_on(ctx->dev, 0); ret =3D ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf, bs_buf, result); - mtk_vcodec_enc_clock_off(ctx->dev, 0); =20 - spin_lock_irqsave(&ctx->dev->irqlock, flags); - ctx->dev->curr_ctx =3D NULL; - spin_unlock_irqrestore(&ctx->dev->irqlock, flags); + venc_encode_unprepare(ctx, opt); =20 - mtk_venc_unlock(ctx); return ret; } =20 @@ -84,11 +75,57 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx) if (!ctx->drv_handle) return 0; =20 - mtk_venc_lock(ctx); + mtk_venc_lock(ctx, ctx->core_id); ret =3D ctx->enc_if->deinit(ctx->drv_handle); - mtk_venc_unlock(ctx); + mtk_venc_unlock(ctx, ctx->core_id); =20 ctx->drv_handle =3D NULL; =20 return ret; } + +void venc_encode_prepare(struct mtk_vcodec_ctx *ctx, + enum venc_start_opt opt) +{ + unsigned long flags; + struct mtk_venc_core_dev *core; + + if (ctx->dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + if (ctx->enc_idx & 0x01) + ctx->core_id =3D MTK_VENC_CORE1; + else + ctx->core_id =3D MTK_VENC_CORE0; + } else { + ctx->core_id =3D MTK_VENC_CORE0; + } + mtk_venc_lock(ctx, ctx->core_id); + + spin_lock_irqsave(&ctx->dev->irqlock, flags); + + if (ctx->dev->venc_pdata->core_mode =3D=3D VENC_DUAL_CORE_MODE) { + core =3D ctx->dev->enc_core_dev[ctx->core_id]; + + core->curr_ctx =3D ctx; + } else { + ctx->dev->curr_ctx =3D ctx; + } + + spin_unlock_irqrestore(&ctx->dev->irqlock, flags); + + mtk_vcodec_enc_clock_on(ctx->dev, ctx->core_id); +} + +void venc_encode_unprepare(struct mtk_vcodec_ctx *ctx, + enum venc_start_opt opt) +{ + unsigned long flags; + + if (ctx->dev->venc_pdata->core_mode =3D=3D VENC_SINGLE_CORE_MODE || + opt =3D=3D VENC_START_OPT_ENCODE_SEQUENCE_HEADER) { + mtk_vcodec_enc_clock_off(ctx->dev, ctx->core_id); + spin_lock_irqsave(&ctx->dev->irqlock, flags); + ctx->dev->curr_ctx =3D NULL; + spin_unlock_irqrestore(&ctx->dev->irqlock, flags); + mtk_venc_unlock(ctx, ctx->core_id); + } +} diff --git a/drivers/media/platform/mtk-vcodec/venc_drv_if.h b/drivers/medi= a/platform/mtk-vcodec/venc_drv_if.h index 0b04a1020873..15e9a2ab9cda 100644 --- a/drivers/media/platform/mtk-vcodec/venc_drv_if.h +++ b/drivers/media/platform/mtk-vcodec/venc_drv_if.h @@ -167,4 +167,9 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs_buf, struct venc_done_result *result); =20 +void venc_encode_prepare(struct mtk_vcodec_ctx *ctx, + enum venc_start_opt opt); +void venc_encode_unprepare(struct mtk_vcodec_ctx *ctx, + enum venc_start_opt opt); + #endif /* _VENC_DRV_IF_H_ */ diff --git a/drivers/media/platform/mtk-vcodec/venc_vpu_if.c b/drivers/medi= a/platform/mtk-vcodec/venc_vpu_if.c index d3570c4c177d..a7219c10013b 100644 --- a/drivers/media/platform/mtk-vcodec/venc_vpu_if.c +++ b/drivers/media/platform/mtk-vcodec/venc_vpu_if.c @@ -225,9 +225,11 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu, int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, - struct venc_frame_info *frame_info) + struct venc_frame_info *frame_info, + int core_id) { const bool is_ext =3D MTK_ENC_CTX_IS_EXT(vpu->ctx); + const int core_mode =3D MTK_ENC_CORE_MODE(vpu->ctx); size_t msg_size =3D is_ext ? sizeof(struct venc_ap_ipi_msg_enc_ext) : sizeof(struct venc_ap_ipi_msg_enc); @@ -261,6 +263,12 @@ int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned= int bs_mode, out.data[1] =3D frame_info->skip_frm_count; out.data[2] =3D frame_info->frm_type; } + + if (core_mode =3D=3D VENC_DUAL_CORE_MODE) { + out.data_item =3D 4; + out.data[3] =3D core_id; + } + if (vpu_enc_send_msg(vpu, &out, msg_size)) { mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_ENCODE %d fail", bs_mode); diff --git a/drivers/media/platform/mtk-vcodec/venc_vpu_if.h b/drivers/medi= a/platform/mtk-vcodec/venc_vpu_if.h index f83bc1b3f2bf..a8055eb62f7c 100644 --- a/drivers/media/platform/mtk-vcodec/venc_vpu_if.h +++ b/drivers/media/platform/mtk-vcodec/venc_vpu_if.h @@ -45,7 +45,8 @@ int vpu_enc_set_param(struct venc_vpu_inst *vpu, int vpu_enc_encode(struct venc_vpu_inst *vpu, unsigned int bs_mode, struct venc_frm_buf *frm_buf, struct mtk_vcodec_mem *bs_buf, - struct venc_frame_info *frame_info); + struct venc_frame_info *frame_info, + int core_id); int vpu_enc_deinit(struct venc_vpu_inst *vpu); =20 #endif --=20 2.18.0 From nobody Sun Sep 22 09:33:11 2024 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 E7840C433EF for ; Mon, 17 Jan 2022 12:07:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239688AbiAQMG7 (ORCPT ); Mon, 17 Jan 2022 07:06:59 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:37174 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S239654AbiAQMGv (ORCPT ); Mon, 17 Jan 2022 07:06:51 -0500 X-UUID: b7876d18f76141a18be2e2925111f3bb-20220117 X-UUID: b7876d18f76141a18be2e2925111f3bb-20220117 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1176916195; Mon, 17 Jan 2022 20:06:48 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkmbs07n1.mediatek.inc (172.21.101.16) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Mon, 17 Jan 2022 20:06:47 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 17 Jan 2022 20:06:45 +0800 From: Irui Wang To: Hans Verkuil , Tzung-Bi Shih , Alexandre Courbot , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa , Yong Wu , CC: Hsin-Yi Wang , Maoguang Meng , Longfei Wang , Yunfei Dong , Fritz Koenig , Irui Wang , , , , , , , Subject: [PATCH v2, 10/10] media: mtk-vcodec: Done encode result to client Date: Mon, 17 Jan 2022 20:06:15 +0800 Message-ID: <20220117120615.21687-11-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117120615.21687-1-irui.wang@mediatek.com> References: <20220117120615.21687-1-irui.wang@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" When enable dual core mode encoding, the wait IRQ done synchronous function should not be called, so the encode result can't return to client in device_run. device_run called to trigger encoding process, finish it, so another scheduled job can be ran. When encoding done, done the encode result to client in IRQ handler. Signed-off-by: Irui Wang --- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 6 ++ .../platform/mtk-vcodec/mtk_vcodec_enc.c | 64 ++++++++++++++++++- .../platform/mtk-vcodec/mtk_vcodec_enc.h | 3 + .../platform/mtk-vcodec/mtk_vcodec_enc_core.c | 27 +++++++- .../platform/mtk-vcodec/mtk_vcodec_util.h | 1 + .../platform/mtk-vcodec/venc/venc_h264_if.c | 22 ++++++- .../media/platform/mtk-vcodec/venc_drv_if.h | 2 + 7 files changed, 120 insertions(+), 5 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index c3cf5904b4c6..5faeffd397db 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -311,6 +311,9 @@ struct vdec_pic_info { * @q_mutex: src & dst vb2_queue mutex * @enc_idx: used to record encoded frame count * @core_id: used to reoord used core + * @pfrm_buf: used to store current ctx's frame buffer + * @pbs_buf: used to store current ctx's bitstream buffer + * @hdr_size: used to store prepend header size */ struct mtk_vcodec_ctx { enum mtk_instance_type type; @@ -363,6 +366,9 @@ struct mtk_vcodec_ctx { struct mutex q_mutex; int enc_idx; int core_id; + struct vb2_v4l2_buffer *pfrm_buf[MTK_VENC_CORE_MAX]; + struct vb2_v4l2_buffer *pbs_buf[MTK_VENC_CORE_MAX]; + unsigned int hdr_size; }; =20 /* diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.c index dc70d328fcd3..3056cbc4b3a3 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.c @@ -924,6 +924,8 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue= *q) =20 mtk_v4l2_debug(2, "[%d]-> type=3D%d", ctx->id, q->type); =20 + mtk_venc_lock_all(ctx); + if (q->type =3D=3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { while ((dst_buf =3D v4l2_m2m_dst_buf_remove(ctx->m2m_ctx))) { vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); @@ -1103,10 +1105,13 @@ static int mtk_venc_param_change(struct mtk_vcodec_= ctx *ctx) ctx->id, vb2_v4l2->vb2_buf.index, mtk_buf->enc_params.force_intra); - if (mtk_buf->enc_params.force_intra) + if (mtk_buf->enc_params.force_intra) { ret |=3D venc_if_set_param(ctx, VENC_SET_PARAM_FORCE_INTRA, NULL); + + ctx->enc_idx =3D 0; + } } =20 mtk_buf->param_change =3D MTK_ENCODE_PARAM_NONE; @@ -1157,6 +1162,7 @@ static void mtk_venc_worker(struct work_struct *work) * is dequeued. */ if (src_buf =3D=3D &ctx->empty_flush_buf.vb) { + mtk_venc_lock_all(ctx); vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); dst_buf->flags |=3D V4L2_BUF_FLAG_LAST; v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); @@ -1171,9 +1177,12 @@ static void mtk_venc_worker(struct work_struct *work) frm_buf.fb_addr[i].size =3D (size_t)src_buf->vb2_buf.planes[i].length; } + frm_buf.src_addr =3D src_buf; + bs_buf.va =3D vb2_plane_vaddr(&dst_buf->vb2_buf, 0); bs_buf.dma_addr =3D vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); bs_buf.size =3D (size_t)dst_buf->vb2_buf.planes[0].length; + bs_buf.buf =3D dst_buf; =20 mtk_v4l2_debug(2, "Framebuf PA=3D%llx Size=3D0x%zx;PA=3D0x%llx Size=3D0x%zx;PA=3D0x%llx S= ize=3D%zu", @@ -1220,6 +1229,8 @@ static void m2mops_venc_device_run(void *priv) { struct mtk_vcodec_ctx *ctx =3D priv; =20 + mtk_venc_param_change(ctx); + if ((ctx->q_data[MTK_Q_DATA_DST].fmt->fourcc =3D=3D V4L2_PIX_FMT_H264) && (ctx->state !=3D MTK_STATE_HEADER)) { /* encode h264 sps/pps header */ @@ -1228,7 +1239,6 @@ static void m2mops_venc_device_run(void *priv) return; } =20 - mtk_venc_param_change(ctx); queue_work(ctx->dev->encode_workqueue, &ctx->encode_work); } =20 @@ -1414,6 +1424,34 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2= _queue *src_vq, return vb2_queue_init(dst_vq); } =20 +void mtk_venc_buf_done(struct mtk_vcodec_ctx *ctx, int core_id, + unsigned int bs_size, bool time_out, bool key_frame) +{ + struct vb2_v4l2_buffer *src_vb2_v4l2 =3D NULL; + struct vb2_v4l2_buffer *dst_vb2_v4l2 =3D NULL; + + /* + * the frm_buf(src_buf) and bs_buf(dst_buf) can be obtained from ctx, + * then put them to done list, user can get them by dqbuf call + */ + src_vb2_v4l2 =3D ctx->pfrm_buf[core_id]; + dst_vb2_v4l2 =3D ctx->pbs_buf[core_id]; + + if (src_vb2_v4l2 && dst_vb2_v4l2) { + dst_vb2_v4l2->vb2_buf.timestamp =3D + src_vb2_v4l2->vb2_buf.timestamp; + dst_vb2_v4l2->timecode =3D src_vb2_v4l2->timecode; + + if (key_frame) + dst_vb2_v4l2->flags |=3D V4L2_BUF_FLAG_KEYFRAME; + + v4l2_m2m_buf_done(src_vb2_v4l2, VB2_BUF_STATE_DONE); + vb2_set_plane_payload(&dst_vb2_v4l2->vb2_buf, 0, bs_size); + v4l2_m2m_buf_done(dst_vb2_v4l2, VB2_BUF_STATE_DONE); + } +} +EXPORT_SYMBOL_GPL(mtk_venc_buf_done); + int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx, int core_id) { struct mtk_vcodec_dev *dev =3D ctx->dev; @@ -1441,3 +1479,25 @@ void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *c= tx) =20 ctx->state =3D MTK_STATE_FREE; } + +void mtk_venc_lock_all(struct mtk_vcodec_ctx *ctx) +{ + unsigned int i; + struct mtk_vcodec_dev *dev =3D ctx->dev; + + /* + * For frame-racing mode encoding, there are may be bufs being encoded + * when get the empty flush buffer or stop streaming, for example, the + * buffer with LAST flag will return to client before the encoding + * buffers, which will cause frame lost. + * The encoder device mutex will be locked during encoding process, + * when encode done, the mutex unlocked. So if all encoder device mutex + * can be locked, which means there are no bufs being encoded at this + * time, then the buffer with LAST flag can return to client properly. + */ + for (i =3D 0; i < MTK_VENC_CORE_MAX; i++) { + mutex_lock(&dev->enc_mutex[i]); + mutex_unlock(&dev->enc_mutex[i]); + } +} +EXPORT_SYMBOL_GPL(mtk_venc_lock_all); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_enc.h index 434d91d36158..1e22c77a2760 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc.h @@ -46,5 +46,8 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queu= e *src_vq, void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *ctx); int mtk_vcodec_enc_ctrls_setup(struct mtk_vcodec_ctx *ctx); void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx); +void mtk_venc_buf_done(struct mtk_vcodec_ctx *ctx, int core_id, + unsigned int bs_size, bool time_out, bool key_frame); +void mtk_venc_lock_all(struct mtk_vcodec_ctx *ctx); =20 #endif /* _MTK_VCODEC_ENC_H_ */ diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c b/driv= ers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c index 3835b9f458bf..6140b9bd4dd0 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_core.c @@ -14,6 +14,11 @@ #include "mtk_vcodec_enc.h" #include "mtk_vcodec_enc_core.h" #include "mtk_vcodec_enc_pm.h" +#include "mtk_vcodec_intr.h" + +#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098 +#define VENC_PIC_FRM_TYPE 0x0010 +#define VENC_PIC_KEY_FRM 0x2 =20 static const struct of_device_id mtk_venc_core_ids[] =3D { { @@ -47,6 +52,7 @@ static void clean_irq_status(unsigned int irq_status, voi= d __iomem *addr) =20 if (irq_status & MTK_VENC_IRQ_STATUS_FRM) writel(MTK_VENC_IRQ_STATUS_FRM, addr); + } =20 static irqreturn_t mtk_enc_core_irq_handler(int irq, void *priv) @@ -55,6 +61,9 @@ static irqreturn_t mtk_enc_core_irq_handler(int irq, void= *priv) struct mtk_vcodec_ctx *ctx; unsigned long flags; void __iomem *addr; + unsigned int bs_size; + unsigned int frm_type; + bool is_key_frame =3D 0; =20 spin_lock_irqsave(&core->main_dev->irqlock, flags); ctx =3D core->curr_ctx; @@ -66,9 +75,25 @@ static irqreturn_t mtk_enc_core_irq_handler(int irq, voi= d *priv) =20 addr =3D core->reg_base + MTK_VENC_IRQ_ACK_OFFSET; ctx->irq_status =3D readl(core->reg_base + MTK_VENC_IRQ_STATUS_OFFSET); + bs_size =3D readl(core->reg_base + VENC_PIC_BITSTREAM_BYTE_CNT); + frm_type =3D readl(core->reg_base + VENC_PIC_FRM_TYPE); clean_irq_status(ctx->irq_status, addr); =20 - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); + if (ctx->irq_status & MTK_VENC_IRQ_STATUS_FRM) { + if (ctx->hdr_size !=3D 0) { + bs_size +=3D ctx->hdr_size; + ctx->hdr_size =3D 0; + } + if (frm_type & VENC_PIC_KEY_FRM) + is_key_frame =3D 1; + + mtk_venc_buf_done(ctx, core->core_id, bs_size, 0, is_key_frame); + mtk_vcodec_enc_clock_off(core->main_dev, core->core_id); + mtk_venc_unlock(ctx, core->core_id); + } else { + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); + } + return IRQ_HANDLED; } =20 diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_util.h index de9e18688842..4436d8bc60a0 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_util.h @@ -15,6 +15,7 @@ struct mtk_vcodec_mem { size_t size; void *va; dma_addr_t dma_addr; + void *buf; }; =20 struct mtk_vcodec_fb { diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c b/driver= s/media/platform/mtk-vcodec/venc/venc_h264_if.c index fdecf1d24b25..733dbf431aae 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c @@ -558,6 +558,12 @@ static int h264_encode_frame(struct venc_h264_inst *in= st, return ret; } =20 + if (is_dual_core) { + ++inst->frm_cnt; + mtk_vcodec_debug(inst, "dual core : frm %d <-", inst->frm_cnt); + return ret; + } + irq_status =3D h264_enc_wait_venc_done(inst); if (irq_status !=3D MTK_VENC_IRQ_STATUS_FRM) { mtk_vcodec_err(inst, "irq_status=3D%d failed", irq_status); @@ -639,10 +645,12 @@ static int h264_enc_encode(void *handle, int ret =3D 0; struct venc_h264_inst *inst =3D (struct venc_h264_inst *)handle; struct mtk_vcodec_ctx *ctx =3D inst->ctx; + bool is_single_core =3D (MTK_ENC_CORE_MODE(ctx) =3D=3D VENC_SINGLE_CORE_M= ODE); =20 mtk_vcodec_debug(inst, "opt %d ->", opt); =20 - enable_irq(ctx->dev->enc_irq); + if (is_single_core) + enable_irq(ctx->dev->enc_irq); =20 switch (opt) { case VENC_START_OPT_ENCODE_SEQUENCE_HEADER: { @@ -666,6 +674,13 @@ static int h264_enc_encode(void *handle, unsigned int bs_size_hdr; unsigned int bs_size_frm; =20 + /* + * the frm_buf and bs_buf need to be recorded into ctx, + * when encoding done, the target buffer can be obtained + */ + ctx->pfrm_buf[ctx->core_id] =3D frm_buf->src_addr; + ctx->pbs_buf[ctx->core_id] =3D bs_buf->buf; + if (!inst->prepend_hdr) { ret =3D h264_encode_frame(inst, frm_buf, bs_buf, &result->bs_size, ctx->core_id); @@ -702,6 +717,8 @@ static int h264_enc_encode(void *handle, =20 result->bs_size =3D hdr_sz + filler_sz + bs_size_frm; =20 + ctx->hdr_size =3D hdr_sz + filler_sz; + mtk_vcodec_debug(inst, "hdr %d filler %d frame %d bs %d", hdr_sz, filler_sz, bs_size_frm, result->bs_size); @@ -718,8 +735,9 @@ static int h264_enc_encode(void *handle, } =20 encode_err: + if (is_single_core) + disable_irq(ctx->dev->enc_irq); =20 - disable_irq(ctx->dev->enc_irq); mtk_vcodec_debug(inst, "opt %d <-", opt); =20 return ret; diff --git a/drivers/media/platform/mtk-vcodec/venc_drv_if.h b/drivers/medi= a/platform/mtk-vcodec/venc_drv_if.h index 15e9a2ab9cda..3ad31abb7290 100644 --- a/drivers/media/platform/mtk-vcodec/venc_drv_if.h +++ b/drivers/media/platform/mtk-vcodec/venc_drv_if.h @@ -108,9 +108,11 @@ struct venc_frame_info { /* * struct venc_frm_buf - frame buffer information used in venc_if_encode() * @fb_addr: plane frame buffer addresses + * @src_addr: vb2_v4l2_buffer src buffer address */ struct venc_frm_buf { struct mtk_vcodec_fb fb_addr[MTK_VCODEC_MAX_PLANES]; + void *src_addr; }; =20 /* --=20 2.18.0