From patchwork Sat Oct 1 03:17:32 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 611478 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 2A5A5C4321E for ; Sat, 1 Oct 2022 03:26:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233288AbiJAD0f (ORCPT ); Fri, 30 Sep 2022 23:26:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48292 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233175AbiJADZn (ORCPT ); Fri, 30 Sep 2022 23:25:43 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E40BF80A6; Fri, 30 Sep 2022 20:17:52 -0700 (PDT) X-UUID: 1a4316dc2c9b471d863f015873e272fd-20221001 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=tVU561ie3mo1qOpQcZtWrSSXP0unSyosTSaMx2bhXHE=; b=Ux0MD2HjZgSl9ueJfSI5B1EMqMBM+xM9uMVXCG+Sr/Emp0nA6xGPhsAWx5V/mhj6k7PNbeF1KbbcfCuc9lH98zgdWwIqCy3VohS0pmvHs8qILseJl+vd7N+l0OU1wip3JvVqw6Xwk3a+rp0FKkkzasEJbcioVnOSle/JshDdYwI=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11, REQID:44f34caa-23b5-4d8e-8173-c48fd1448a0a, IP:0, U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:70 X-CID-INFO: VERSION:1.1.11, REQID:44f34caa-23b5-4d8e-8173-c48fd1448a0a, IP:0, URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTI ON:quarantine,TS:70 X-CID-META: VersionHash:39a5ff1, CLOUDID:963ed6e4-87f9-4bb0-97b6-34957dc0fbbe, B ulkID:221001111749B6OCBMAP,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48|823| 824,TC:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:n il,COL:0 X-UUID: 1a4316dc2c9b471d863f015873e272fd-20221001 Received: from mtkcas11.mediatek.inc [(172.21.101.40)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-SHA384 256/256) with ESMTP id 761456109; Sat, 01 Oct 2022 11:17:46 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Sat, 1 Oct 2022 11:17:44 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sat, 1 Oct 2022 11:17:43 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , Tzung-Bi Shih , , , Tiffany Lin CC: Yunfei Dong , Maoguang Meng , Longfei Wang , Irui Wang , , , , , , Subject: [PATCH v6, 3/8] media: mediatek: vcodec: Refactor venc power manage function Date: Sat, 1 Oct 2022 11:17:32 +0800 Message-ID: <20221001031737.18266-4-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221001031737.18266-1-irui.wang@mediatek.com> References: <20221001031737.18266-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org The args "struct mtk_vcodec_dev *" doesn't appropriate for init_clk functions because of sub-devices, sub-devices will init their own "pm/clk" instead, so refactor the pm function with args "platform_device *" and "mtk_vcodec_pm*". Signed-off-by: Irui Wang --- .../media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c | 2 +- .../media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c | 8 ++++++++ .../media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c | 9 +++------ .../media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h | 3 ++- 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c index 48f9f59516bd..5bfbf4eead13 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c @@ -257,7 +257,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) return PTR_ERR(dev->fw_handler); dev->venc_pdata = of_device_get_match_data(&pdev->dev); - ret = mtk_vcodec_init_enc_clk(dev); + ret = mtk_vcodec_init_enc_clk(dev->plat_dev, &dev->pm); if (ret < 0) { dev_err(&pdev->dev, "Failed to get mtk vcodec clock source!"); goto err_enc_pm; diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c index cc4938f027e0..1ed4279925b7 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c @@ -13,6 +13,7 @@ #include "mtk_vcodec_drv.h" #include "mtk_vcodec_enc.h" #include "mtk_vcodec_enc_hw.h" +#include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_intr.h" static const struct of_device_id mtk_venc_hw_ids[] = { @@ -115,6 +116,13 @@ static int mtk_venc_hw_probe(struct platform_device *pdev) return dev_err_probe(dev, (ret ? ret : -EINVAL), "Cannot parse hardware id"); + ret = mtk_vcodec_init_enc_clk(sub_core->plat_dev, &sub_core->pm); + if (ret < 0) + return dev_err_probe(dev, ret, + "Failed to get venc core clock source!"); + + pm_runtime_enable(&pdev->dev); + main_dev->enc_hw_dev[sub_core->hw_id] = sub_core; sub_core->main_dev = main_dev; diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c index 7055954eb2af..75de5031d292 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c @@ -12,17 +12,13 @@ #include "mtk_vcodec_enc_pm.h" #include "mtk_vcodec_util.h" -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 platform_device *pdev; - struct mtk_vcodec_pm *pm; struct mtk_vcodec_clk *enc_clk; struct mtk_vcodec_clk_info *clk_info; int ret, i; - pdev = mtkdev->plat_dev; - pm = &mtkdev->pm; - memset(pm, 0, sizeof(struct mtk_vcodec_pm)); pm->dev = &pdev->dev; enc_clk = &pm->venc_clk; @@ -58,6 +54,7 @@ int mtk_vcodec_init_enc_clk(struct mtk_vcodec_dev *mtkdev) return 0; } +EXPORT_SYMBOL_GPL(mtk_vcodec_init_enc_clk); void mtk_vcodec_enc_clock_on(struct mtk_vcodec_pm *pm) { diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h index bc455cefc0cd..361dec5be47f 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.h @@ -9,7 +9,8 @@ #include "mtk_vcodec_drv.h" -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); From patchwork Sat Oct 1 03:17:33 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 611479 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 2E385C433FE for ; Sat, 1 Oct 2022 03:26:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231576AbiJAD0b (ORCPT ); Fri, 30 Sep 2022 23:26:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42910 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233109AbiJADZk (ORCPT ); Fri, 30 Sep 2022 23:25:40 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 2108BF80A3; Fri, 30 Sep 2022 20:17:49 -0700 (PDT) X-UUID: 189f2903897642d585ab51ff4907afab-20221001 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=gQH1JyEktFOJV39yJWLnXwk1nF1Uwl2E7ka1LkvPm10=; b=Hd6W2J7GXQ7ILuBmxb3sXsi2uqGHFai6LIfz3zMgzE8uzQD5jTB020hA0aHjg0q5lizMZPNmWhlIME1sOQgc28WbikWm2uPAlMMQfjAyCllWssOWEDzk5wRnmYmEvzhXWMzKrEMY8I3DKm9VvnZr9Vbb/dyUfPBhDGfAWxjmTT0=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11, REQID:56c23a73-1160-4a54-82e2-1d75663274e5, IP:0, U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Release_Ham,ACTI ON:release,TS:70 X-CID-INFO: VERSION:1.1.11, REQID:56c23a73-1160-4a54-82e2-1d75663274e5, IP:0, URL :0,TC:0,Content:-25,EDM:0,RT:0,SF:95,FILE:0,BULK:0,RULE:Spam_GS981B3D,ACTI ON:quarantine,TS:70 X-CID-META: VersionHash:39a5ff1, CLOUDID:9e67afa3-dc04-435c-b19b-71e131a5fc35, B ulkID:221001111747BN0SKB6G,BulkQuantity:0,Recheck:0,SF:38|28|17|19|48|823| 824,TC:nil,Content:0,EDM:-3,IP:nil,URL:11|1,File:nil,Bulk:nil,QS:nil,BEC:n il,COL:0 X-UUID: 189f2903897642d585ab51ff4907afab-20221001 Received: from mtkmbs10n1.mediatek.inc [(172.21.101.34)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 278911089; Sat, 01 Oct 2022 11:17:47 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs13n1.mediatek.inc (172.21.101.193) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Sat, 1 Oct 2022 11:17:45 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sat, 1 Oct 2022 11:17:44 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , Tzung-Bi Shih , , , Tiffany Lin CC: Yunfei Dong , Maoguang Meng , Longfei Wang , Irui Wang , , , , , , Subject: [PATCH v6, 4/8] media: mediatek: vcodec: Add more extra processing for multi-core encoding Date: Sat, 1 Oct 2022 11:17:33 +0800 Message-ID: <20221001031737.18266-5-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221001031737.18266-1-irui.wang@mediatek.com> References: <20221001031737.18266-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org Add a bit for indicating support multi-core encoding, because multi-core encoding need more working buffers for encoder hardware. The working buffers are allocated from kernel side then pass to scp firmware side through shared memory, the struct definition must be kept align between kernel and scp firmware side. New another shared memory struct for multi-core encoding. Signed-off-by: Irui Wang --- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 2 + .../mediatek/vcodec/mtk_vcodec_util.c | 19 +++ .../mediatek/vcodec/mtk_vcodec_util.h | 2 + .../mediatek/vcodec/venc/venc_h264_if.c | 108 +++++++++++++++--- 4 files changed, 116 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h index 6faf9ccc940f..e074198a12ad 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h @@ -27,6 +27,8 @@ #define WAIT_INTR_TIMEOUT_MS 1000 #define IS_VDEC_LAT_ARCH(hw_arch) ((hw_arch) >= MTK_VDEC_LAT_SINGLE_CORE) #define IS_VDEC_INNER_RACING(capability) ((capability) & MTK_VCODEC_INNER_RACING) +#define MTK_VENC_MULTICORE_ENABLE BIT(1) +#define IS_VENC_MULTICORE(capability) ((capability) & MTK_VENC_MULTICORE_ENABLE) /* * enum mtk_hw_reg_idx - MTK hw register base index diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c index ace78c4b5b9e..a4c2cbf4040e 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.c @@ -11,6 +11,7 @@ #include "mtk_vcodec_dec_hw.h" #include "mtk_vcodec_drv.h" +#include "mtk_vcodec_enc_hw.h" #include "mtk_vcodec_util.h" 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); +void __iomem *mtk_venc_get_core_reg_addr(struct mtk_vcodec_ctx *ctx, + int hw_id) +{ + struct mtk_venc_hw_dev *sub_core; + + if (hw_id >= MTK_VENC_HW_MAX) { + mtk_v4l2_err("Invalid hw_id = %d", hw_id); + return NULL; + } + + sub_core = (struct mtk_venc_hw_dev *)ctx->dev->enc_hw_dev[hw_id]; + if (!sub_core) + return NULL; + + return sub_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/mediatek/vcodec/mtk_vcodec_util.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h index 71956627a0e2..0033c53d5589 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h @@ -50,6 +50,8 @@ struct mtk_vcodec_dev; 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, + int hw_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/mediatek/vcodec/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c index 13c4f860fa69..d7ed5c753a0e 100644 --- a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c @@ -50,6 +50,24 @@ enum venc_h264_vpu_work_buf { VENC_H264_VPU_WORK_BUF_MAX, }; +/* + * enum venc_multi_core_work_buf - h264 multi core encoder buffer index + */ +enum venc_multi_core_work_buf { + VENC_MULTI_CORE_WORK_BUF_RC_INFO_CORE0, + VENC_MULTI_CORE_WORK_BUF_RC_CODE, + VENC_MULTI_CORE_WORK_BUF_REC_LUMA, + VENC_MULTI_CORE_WORK_BUF_REC_CHROMA, + VENC_MULTI_CORE_WORK_BUF_REF_LUMA, + VENC_MULTI_CORE_WORK_BUF_REF_CHROMA, + VENC_MULTI_CORE_WORK_BUF_MV_INFO_1, + VENC_MULTI_CORE_WORK_BUF_MV_INFO_2, + VENC_MULTI_CORE_WORK_BUF_SKIP_FRAME, + VENC_MULTI_CORE_WORK_BUF_RC_INFO_CORE1, + VENC_MULTI_CORE_WORK_BUF_FR_RC_INFO, + VENC_MULTI_CORE_WORK_BUF_MAX, +}; + /* * enum venc_h264_bs_mode - for bs_mode argument in h264_enc_vpu_encode */ @@ -193,6 +211,17 @@ struct venc_h264_vsi_34 { struct venc_h264_vpu_buf_34 work_bufs[VENC_H264_VPU_WORK_BUF_MAX]; }; +/** + * struct venc_multi_core_vsi - Structure for VPU driver control and info share + * Used for multi-core encode sharing + * @config: h264 encoder configuration + * @work_bufs: working buffer information in VPU side + */ +struct venc_multi_core_vsi { + struct venc_h264_vpu_config_ext config; + struct venc_h264_vpu_buf work_bufs[VENC_MULTI_CORE_WORK_BUF_MAX]; +}; + /* * struct venc_h264_inst - h264 encoder AP driver instance * @hw_base: h264 encoder hardware register base @@ -208,25 +237,29 @@ struct venc_h264_vsi_34 { * control and info share * @vsi_34: driver structure allocated by VPU side and shared to AP side for * control and info share, used for 34-bit iova sharing. + * @core_vsi: used for multi-core encode info sharing. * @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_HW_MAX]; + struct mtk_vcodec_mem work_bufs[VENC_MULTI_CORE_WORK_BUF_MAX]; struct mtk_vcodec_mem pps_buf; bool work_buf_allocated; unsigned int frm_cnt; unsigned int skip_frm_cnt; unsigned int prepend_hdr; struct venc_vpu_inst vpu_inst; - struct venc_h264_vsi *vsi; - struct venc_h264_vsi_34 *vsi_34; + union { + struct venc_h264_vsi *vsi; + struct venc_h264_vsi_34 *vsi_34; + struct venc_multi_core_vsi *core_vsi; + }; struct mtk_vcodec_ctx *ctx; }; 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_CORE_0] + addr); } static unsigned int h264_get_profile(struct venc_h264_inst *inst, @@ -296,14 +329,20 @@ static unsigned int h264_get_level(struct venc_h264_inst *inst, static void h264_enc_free_work_buf(struct venc_h264_inst *inst) { - int i; + struct mtk_vcodec_ctx *ctx = inst->ctx; + int i, max_work_buf; mtk_vcodec_debug_enter(inst); + if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) + max_work_buf = VENC_MULTI_CORE_WORK_BUF_MAX; + else + max_work_buf = VENC_H264_VPU_WORK_BUF_MAX; + /* Except the SKIP_FRAME buffers, * other buffers need to be freed by AP. */ - for (i = 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) { + for (i = 0; i < max_work_buf; i++) { if (i != VENC_H264_VPU_WORK_BUF_SKIP_FRAME) mtk_vcodec_mem_free(inst->ctx, &inst->work_bufs[i]); } @@ -317,18 +356,25 @@ static int h264_enc_alloc_work_buf(struct venc_h264_inst *inst, bool is_34bit) { struct venc_h264_vpu_buf *wb = NULL; struct venc_h264_vpu_buf_34 *wb_34 = NULL; - int i; + struct mtk_vcodec_ctx *ctx = inst->ctx; + int i, max_work_buf; u32 vpua, wb_size; int ret = 0; mtk_vcodec_debug_enter(inst); - if (is_34bit) + if (is_34bit) { wb_34 = inst->vsi_34->work_bufs; - else + max_work_buf = VENC_H264_VPU_WORK_BUF_MAX; + } else if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) { + wb = inst->core_vsi->work_bufs; + max_work_buf = VENC_MULTI_CORE_WORK_BUF_MAX; + } else { wb = inst->vsi->work_bufs; + max_work_buf = VENC_H264_VPU_WORK_BUF_MAX; + } - for (i = 0; i < VENC_H264_VPU_WORK_BUF_MAX; i++) { + for (i = 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 @@ -537,6 +583,9 @@ static int h264_encode_frame(struct venc_h264_inst *inst, if (MTK_ENC_IOVA_IS_34BIT(ctx)) { gop_size = inst->vsi_34->config.gop_size; intra_period = inst->vsi_34->config.intra_period; + } else if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) { + gop_size = inst->core_vsi->config.gop_size; + intra_period = inst->core_vsi->config.intra_period; } else { gop_size = inst->vsi->config.gop_size; intra_period = inst->vsi->config.intra_period; @@ -602,8 +651,8 @@ static void h264_encode_filler(struct venc_h264_inst *inst, void *buf, static int h264_enc_init(struct mtk_vcodec_ctx *ctx) { const bool is_ext = MTK_ENC_CTX_IS_EXT(ctx); - int ret = 0; struct venc_h264_inst *inst; + int ret, i; inst = kzalloc(sizeof(*inst), GFP_KERNEL); if (!inst) @@ -612,16 +661,24 @@ static int h264_enc_init(struct mtk_vcodec_ctx *ctx) inst->ctx = ctx; inst->vpu_inst.ctx = ctx; inst->vpu_inst.id = is_ext ? SCP_IPI_VENC_H264 : IPI_VENC_H264; - inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx, VENC_SYS); + inst->hw_base[0] = mtk_vcodec_get_reg_addr(inst->ctx, VENC_SYS); mtk_vcodec_debug_enter(inst); ret = vpu_enc_init(&inst->vpu_inst); - if (MTK_ENC_IOVA_IS_34BIT(ctx)) + if (MTK_ENC_IOVA_IS_34BIT(ctx)) { inst->vsi_34 = (struct venc_h264_vsi_34 *)inst->vpu_inst.vsi; - else + } else if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) { + inst->core_vsi = + (struct venc_multi_core_vsi *)inst->vpu_inst.vsi; + + for (i = 1; i < MTK_VENC_HW_MAX; i++) + inst->hw_base[i] = + mtk_venc_get_core_reg_addr(inst->ctx, i); + } else { inst->vsi = (struct venc_h264_vsi *)inst->vpu_inst.vsi; + } mtk_vcodec_debug_leave(inst); @@ -766,6 +823,25 @@ static void h264_enc_set_vsi_34_configs(struct venc_h264_inst *inst, inst->vsi_34->config.wfd = 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 = enc_prm->input_yuv_fmt; + inst->core_vsi->config.bitrate = enc_prm->bitrate; + inst->core_vsi->config.pic_w = enc_prm->width; + inst->core_vsi->config.pic_h = enc_prm->height; + inst->core_vsi->config.buf_w = enc_prm->buf_width; + inst->core_vsi->config.buf_h = enc_prm->buf_height; + inst->core_vsi->config.gop_size = enc_prm->gop_size; + inst->core_vsi->config.framerate = enc_prm->frm_rate; + inst->core_vsi->config.intra_period = enc_prm->intra_period; + inst->core_vsi->config.profile = + h264_get_profile(inst, enc_prm->h264_profile); + inst->core_vsi->config.level = + h264_get_level(inst, enc_prm->h264_level); + inst->core_vsi->config.wfd = 0; +} + static int h264_enc_set_param(void *handle, enum venc_set_param_type type, struct venc_enc_param *enc_prm) @@ -781,6 +857,8 @@ static int h264_enc_set_param(void *handle, case VENC_SET_PARAM_ENC: if (is_34bit) h264_enc_set_vsi_34_configs(inst, enc_prm); + else if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) + h264_enc_set_core_configs(inst, enc_prm); else h264_enc_set_vsi_configs(inst, enc_prm); ret = vpu_enc_set_param(&inst->vpu_inst, type, enc_prm); From patchwork Sat Oct 1 03:17:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 611477 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 25E80C43217 for ; Sat, 1 Oct 2022 03:26:40 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233302AbiJAD0h (ORCPT ); Fri, 30 Sep 2022 23:26:37 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233213AbiJADZp (ORCPT ); Fri, 30 Sep 2022 23:25:45 -0400 Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3A5F2F80AC; Fri, 30 Sep 2022 20:17:55 -0700 (PDT) X-UUID: 5098f5f47bd443d6ba401e0c840e03b9-20221001 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=1nRZij7FBP7nArpzIx+WOULHnjCn1SIwkAQdsuKIz9w=; b=CXikUgcIhAQ9AE8WP1DhnWbke+fNtpRctiPDn92gh/wQ29PnWzImEsgkZOy4GAE1OeL0BhRvkj2mxUvbX7yn2NXgs+D8QagqqsrmEFffmWr4sBjyLT9WRfZmriASgi6sBo89RlZxot0mzgMIO3pf+KTIhW37f5+YH7jgFX5Ndl8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11, REQID:4c382812-cfc9-43ec-bfa9-eb212fe930d4, IP:0, U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:39a5ff1, CLOUDID:9aaba107-1cee-4c38-b21b-a45f9682fdc0, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: 5098f5f47bd443d6ba401e0c840e03b9-20221001 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 68640158; Sat, 01 Oct 2022 11:17:49 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Sat, 1 Oct 2022 11:17:48 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sat, 1 Oct 2022 11:17:47 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , "Tzung-Bi Shih" , , , Tiffany Lin CC: Yunfei Dong , Maoguang Meng , Longfei Wang , "Irui Wang" , , , , , , Subject: [PATCH v6, 7/8] media: mediatek: vcodec: Add multi-core encoding process Date: Sat, 1 Oct 2022 11:17:36 +0800 Message-ID: <20221001031737.18266-8-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221001031737.18266-1-irui.wang@mediatek.com> References: <20221001031737.18266-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org MT8195 has two encoder hardware cores, when enable multi-core encoding, it is possiable to trying to use the two cores. According to hardware requirements, input frame 0 uses core0, frame 1 uses core1, then frame 2 uses core0, lock the device and enable clock by used core, and for sequence header encoding, it always use core0. Signed-off-by: Irui Wang --- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 7 +- .../platform/mediatek/vcodec/mtk_vcodec_enc.c | 10 +-- .../platform/mediatek/vcodec/mtk_vcodec_enc.h | 4 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 8 ++- .../mediatek/vcodec/mtk_vcodec_enc_hw.c | 7 +- .../mediatek/vcodec/mtk_vcodec_enc_hw.h | 2 - .../mediatek/vcodec/venc/venc_h264_if.c | 15 ++-- .../mediatek/vcodec/venc/venc_vp8_if.c | 3 +- .../platform/mediatek/vcodec/venc_drv_if.c | 69 ++++++++++++++----- .../platform/mediatek/vcodec/venc_drv_if.h | 4 ++ .../platform/mediatek/vcodec/venc_vpu_if.c | 25 +++++-- .../platform/mediatek/vcodec/venc_vpu_if.h | 3 +- 12 files changed, 110 insertions(+), 47 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h index e074198a12ad..a75ba675f72b 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h @@ -290,6 +290,7 @@ struct vdec_pic_info { * * @msg_queue: msg queue used to store lat buffer information. * @q_mutex: vb2_queue mutex. + * @encoded_frame_cnt: number of encoded frames */ struct mtk_vcodec_ctx { enum mtk_instance_type type; @@ -338,6 +339,7 @@ struct mtk_vcodec_ctx { struct vdec_msg_queue msg_queue; struct mutex q_mutex; + int encoded_frame_cnt; }; /* @@ -482,6 +484,7 @@ struct mtk_vcodec_enc_pdata { * @vdec_racing_info: record register value * @dec_racing_info_mutex: mutex lock used for inner racing mode * @enc_hw_dev: used to store venc core device + * @curr_enc_ctx: used to store current used enc context */ struct mtk_vcodec_dev { struct v4l2_device v4l2_dev; @@ -515,7 +518,8 @@ struct mtk_vcodec_dev { /* decoder hardware mutex lock */ struct mutex dec_mutex[MTK_VDEC_HW_MAX]; - struct mutex enc_mutex; + /* encoder hardware mutex lock */ + struct mutex enc_mutex[MTK_VENC_HW_MAX]; struct mtk_vcodec_pm pm; unsigned int dec_capability; @@ -534,6 +538,7 @@ struct mtk_vcodec_dev { struct mutex dec_racing_info_mutex; void *enc_hw_dev[MTK_VENC_HW_MAX]; + struct mtk_vcodec_ctx *curr_enc_ctx[MTK_VENC_HW_MAX]; }; static inline struct mtk_vcodec_ctx *fh_to_ctx(struct v4l2_fh *fh) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c index 66e08e88dcc8..d15e106fb246 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c @@ -1242,6 +1242,8 @@ static void mtk_venc_worker(struct work_struct *work) enc_result.bs_size); } + ctx->encoded_frame_cnt++; + v4l2_m2m_job_finish(ctx->dev->m2m_dev_enc, ctx->m2m_ctx); mtk_v4l2_debug(1, "<=== src_buf[%d] dst_buf[%d] venc_if_encode ret=%d Size=%u===>", @@ -1451,19 +1453,19 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq, return vb2_queue_init(dst_vq); } -int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx) +int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx, int hw_id) { struct mtk_vcodec_dev *dev = ctx->dev; - mutex_unlock(&dev->enc_mutex); + mutex_unlock(&dev->enc_mutex[hw_id]); return 0; } -int mtk_venc_lock(struct mtk_vcodec_ctx *ctx) +int mtk_venc_lock(struct mtk_vcodec_ctx *ctx, int hw_id) { struct mtk_vcodec_dev *dev = ctx->dev; - mutex_lock(&dev->enc_mutex); + mutex_lock(&dev->enc_mutex[hw_id]); return 0; } diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h index 513ee7993e34..29f5c8d1b59f 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h +++ b/drivers/media/platform/mediatek/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; -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 hw_id); +int mtk_venc_lock(struct mtk_vcodec_ctx *ctx, int hw_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/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c index 5bfbf4eead13..ba9c19a4d2cc 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c @@ -91,7 +91,7 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv) void __iomem *addr; spin_lock_irqsave(&dev->irqlock, flags); - ctx = dev->curr_ctx; + ctx = dev->curr_enc_ctx[MTK_VENC_CORE_0]; spin_unlock_irqrestore(&dev->irqlock, flags); mtk_v4l2_debug(1, "id=%d coreid:%d", ctx->id, dev->venc_pdata->core_id); @@ -231,7 +231,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) struct video_device *vfd_enc; phandle rproc_phandle; enum mtk_vcodec_fw_type fw_type; - int ret; + int ret, i; dev = devm_kzalloc(&pdev->dev, sizeof(*dev), GFP_KERNEL); if (!dev) @@ -296,7 +296,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) goto err_res; } - mutex_init(&dev->enc_mutex); + for (i = 0; i < MTK_VENC_HW_MAX; i++) + mutex_init(&dev->enc_mutex[i]); + mutex_init(&dev->dev_mutex); spin_lock_init(&dev->irqlock); diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c index 1ed4279925b7..6df5221b742f 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c @@ -46,13 +46,14 @@ static void clean_hw_irq_status(unsigned int irq_status, void __iomem *addr) static irqreturn_t mtk_enc_hw_irq_handler(int irq, void *priv) { struct mtk_venc_hw_dev *dev = priv; + struct mtk_vcodec_dev *main_dev = dev->main_dev; struct mtk_vcodec_ctx *ctx; unsigned long flags; void __iomem *addr; - spin_lock_irqsave(&dev->main_dev->irqlock, flags); - ctx = dev->curr_ctx; - spin_unlock_irqrestore(&dev->main_dev->irqlock, flags); + spin_lock_irqsave(&main_dev->irqlock, flags); + ctx = main_dev->curr_enc_ctx[dev->hw_id]; + spin_unlock_irqrestore(&main_dev->irqlock, flags); if (!ctx) return IRQ_HANDLED; diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.h index 9daea9665659..e8dfd46b3b01 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.h @@ -14,7 +14,6 @@ * @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 hardware irq status * @enc_irq: venc device irq @@ -25,7 +24,6 @@ struct mtk_venc_hw_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; diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c index d7ed5c753a0e..32497a35afb1 100644 --- a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c @@ -500,7 +500,8 @@ static int h264_encode_sps(struct venc_h264_inst *inst, mtk_vcodec_debug_enter(inst); - ret = vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_SPS, NULL, bs_buf, NULL); + ret = vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_SPS, NULL, + bs_buf, NULL, MTK_VENC_CORE_0); if (ret) return ret; @@ -526,7 +527,8 @@ static int h264_encode_pps(struct venc_h264_inst *inst, mtk_vcodec_debug_enter(inst); - ret = vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_PPS, NULL, bs_buf, NULL); + ret = vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_PPS, NULL, + bs_buf, NULL, MTK_VENC_CORE_0); if (ret) return ret; @@ -568,7 +570,8 @@ static int h264_encode_header(struct venc_h264_inst *inst, 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 hw_id) { int ret = 0; unsigned int gop_size; @@ -599,7 +602,7 @@ static int h264_encode_frame(struct venc_h264_inst *inst, frame_info.frm_type); ret = vpu_enc_encode(&inst->vpu_inst, H264_BS_MODE_FRAME, - frm_buf, bs_buf, &frame_info); + frm_buf, bs_buf, &frame_info, hw_id); if (ret) return ret; @@ -728,7 +731,7 @@ static int h264_enc_encode(void *handle, if (!inst->prepend_hdr) { ret = h264_encode_frame(inst, frm_buf, bs_buf, - &result->bs_size); + &result->bs_size, ctx->hw_id); if (ret) goto encode_err; result->is_key_frm = inst->vpu_inst.is_key_frm; @@ -756,7 +759,7 @@ static int h264_enc_encode(void *handle, tmp_bs_buf.size = bs_buf->size - (hdr_sz + filler_sz); ret = h264_encode_frame(inst, frm_buf, &tmp_bs_buf, - &bs_size_frm); + &bs_size_frm, ctx->hw_id); if (ret) goto encode_err; diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c index 56ce58f761f1..9eed39a4faa2 100644 --- a/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c +++ b/drivers/media/platform/mediatek/vcodec/venc/venc_vp8_if.c @@ -302,7 +302,8 @@ static int vp8_enc_encode_frame(struct venc_vp8_inst *inst, mtk_vcodec_debug(inst, "->frm_cnt=%d", inst->frm_cnt); - ret = vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, bs_buf, NULL); + ret = vpu_enc_encode(&inst->vpu_inst, 0, frm_buf, + bs_buf, NULL, MTK_VENC_CORE_0); if (ret) return ret; diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.c b/drivers/media/platform/mediatek/vcodec/venc_drv_if.c index 6cbdb7e30bb3..53fa9a91d3fa 100644 --- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.c +++ b/drivers/media/platform/mediatek/vcodec/venc_drv_if.c @@ -16,6 +16,8 @@ #include "mtk_vcodec_enc.h" #include "mtk_vcodec_enc_pm.h" +#define ODD_VENC_FRAME 0x1 + int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) { int ret = 0; @@ -31,9 +33,9 @@ int venc_if_init(struct mtk_vcodec_ctx *ctx, unsigned int fourcc) return -EINVAL; } - mtk_venc_lock(ctx); + mtk_venc_lock(ctx, ctx->hw_id); ret = ctx->enc_if->init(ctx); - mtk_venc_unlock(ctx); + mtk_venc_unlock(ctx, ctx->hw_id); return ret; } @@ -43,9 +45,9 @@ int venc_if_set_param(struct mtk_vcodec_ctx *ctx, { int ret = 0; - mtk_venc_lock(ctx); + mtk_venc_lock(ctx, ctx->hw_id); ret = ctx->enc_if->set_param(ctx->drv_handle, type, in); - mtk_venc_unlock(ctx); + mtk_venc_unlock(ctx, ctx->hw_id); return ret; } @@ -56,24 +58,13 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx, struct venc_done_result *result) { int ret = 0; - unsigned long flags; - mtk_venc_lock(ctx); + venc_encode_prepare(ctx, opt); - spin_lock_irqsave(&ctx->dev->irqlock, flags); - ctx->dev->curr_ctx = ctx; - spin_unlock_irqrestore(&ctx->dev->irqlock, flags); - - mtk_vcodec_enc_clock_on(ctx->dev, 0); ret = ctx->enc_if->encode(ctx->drv_handle, opt, frm_buf, bs_buf, result); - mtk_vcodec_enc_clock_off(ctx->dev, 0); - - spin_lock_irqsave(&ctx->dev->irqlock, flags); - ctx->dev->curr_ctx = NULL; - spin_unlock_irqrestore(&ctx->dev->irqlock, flags); - mtk_venc_unlock(ctx); + venc_encode_unprepare(ctx, opt, ret); return ret; } @@ -84,11 +75,51 @@ int venc_if_deinit(struct mtk_vcodec_ctx *ctx) if (!ctx->drv_handle) return 0; - mtk_venc_lock(ctx); + mtk_venc_lock(ctx, ctx->hw_id); ret = ctx->enc_if->deinit(ctx->drv_handle); - mtk_venc_unlock(ctx); + mtk_venc_unlock(ctx, ctx->hw_id); ctx->drv_handle = NULL; return ret; } + +void venc_encode_prepare(struct mtk_vcodec_ctx *ctx, + enum venc_start_opt opt) +{ + unsigned long flags; + + if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) { + if (ctx->encoded_frame_cnt & ODD_VENC_FRAME) + ctx->hw_id = MTK_VENC_CORE_1; + else + ctx->hw_id = MTK_VENC_CORE_0; + } else { + ctx->hw_id = MTK_VENC_CORE_0; + } + + mtk_venc_lock(ctx, ctx->hw_id); + + spin_lock_irqsave(&ctx->dev->irqlock, flags); + ctx->dev->curr_enc_ctx[ctx->hw_id] = ctx; + spin_unlock_irqrestore(&ctx->dev->irqlock, flags); + + mtk_vcodec_enc_clock_on(ctx->dev, ctx->hw_id); +} + +void venc_encode_unprepare(struct mtk_vcodec_ctx *ctx, + enum venc_start_opt opt, int ret) +{ + unsigned long flags; + + if (ret || !IS_VENC_MULTICORE(ctx->dev->enc_capability) || + opt == VENC_START_OPT_ENCODE_SEQUENCE_HEADER) { + mtk_vcodec_enc_clock_off(ctx->dev, ctx->hw_id); + + spin_lock_irqsave(&ctx->dev->irqlock, flags); + ctx->dev->curr_enc_ctx[ctx->hw_id] = NULL; + spin_unlock_irqrestore(&ctx->dev->irqlock, flags); + + mtk_venc_unlock(ctx, ctx->hw_id); + } +} diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h index 0b04a1020873..e676ccf6bd25 100644 --- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h +++ b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h @@ -167,4 +167,8 @@ int venc_if_encode(struct mtk_vcodec_ctx *ctx, struct mtk_vcodec_mem *bs_buf, struct venc_done_result *result); +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, int ret); #endif /* _VENC_DRV_IF_H_ */ diff --git a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c index 09e7eaa25aab..fb1565a2ca49 100644 --- a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.c @@ -226,7 +226,8 @@ static int vpu_enc_encode_32bits(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 hw_id) { const bool is_ext = MTK_ENC_CTX_IS_EXT(vpu->ctx); size_t msg_size = is_ext ? @@ -262,6 +263,12 @@ static int vpu_enc_encode_32bits(struct venc_vpu_inst *vpu, out.data[1] = frame_info->skip_frm_count; out.data[2] = frame_info->frm_type; } + + if (IS_VENC_MULTICORE(vpu->ctx->dev->enc_capability)) { + out.data_item = 4; + out.data[3] = hw_id; + } + if (vpu_enc_send_msg(vpu, &out, msg_size)) { mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_ENCODE %d fail", bs_mode); @@ -275,7 +282,8 @@ static int vpu_enc_encode_34bits(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 hw_id) { struct venc_ap_ipi_msg_enc_ext_34 out; size_t msg_size = sizeof(struct venc_ap_ipi_msg_enc_ext_34); @@ -309,6 +317,12 @@ static int vpu_enc_encode_34bits(struct venc_vpu_inst *vpu, out.data[1] = frame_info->skip_frm_count; out.data[2] = frame_info->frm_type; } + + if (IS_VENC_MULTICORE(vpu->ctx->dev->enc_capability)) { + out.data_item = 4; + out.data[3] = hw_id; + } + if (vpu_enc_send_msg(vpu, &out, msg_size)) { mtk_vcodec_err(vpu, "AP_IPIMSG_ENC_ENCODE %d fail", bs_mode); @@ -321,16 +335,17 @@ static int vpu_enc_encode_34bits(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 hw_id) { int ret; if (MTK_ENC_IOVA_IS_34BIT(vpu->ctx)) ret = vpu_enc_encode_34bits(vpu, bs_mode, - frm_buf, bs_buf, frame_info); + frm_buf, bs_buf, frame_info, hw_id); else ret = vpu_enc_encode_32bits(vpu, bs_mode, - frm_buf, bs_buf, frame_info); + frm_buf, bs_buf, frame_info, hw_id); if (ret) return ret; diff --git a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h b/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h index f83bc1b3f2bf..23efcea8d510 100644 --- a/drivers/media/platform/mediatek/vcodec/venc_vpu_if.h +++ b/drivers/media/platform/mediatek/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 hw_id); int vpu_enc_deinit(struct venc_vpu_inst *vpu); #endif From patchwork Sat Oct 1 03:17:37 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 611476 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 6B6C6C4332F for ; Sat, 1 Oct 2022 03:26:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233321AbiJAD0q (ORCPT ); Fri, 30 Sep 2022 23:26:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52942 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233273AbiJADZq (ORCPT ); Fri, 30 Sep 2022 23:25:46 -0400 Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 208D9F80AE; Fri, 30 Sep 2022 20:17:55 -0700 (PDT) X-UUID: d1fa1afec6fe49afbf67a3593defbebe-20221001 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Type:Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID:Date:Subject:CC:To:From; bh=YXsaGgrWcfTxB6frm3Y9+mK7+MQIPFMyxzTV3FpAegI=; b=Yn15yPPeK8pQd6DZDmC/ZJSyb0nhWHE+7GVAbiYWR2iqOrEScJDyF44eSc8cDvsptBIaJrhjUfHu/D/BD6qGkhJ68hn5sDCufQ9e66M1NuXIj6mjaOoIbj7wBL3ZXqGOgZnUnzVwW69ewFaBRawoF66C/ztj8USXpD44Sho3O44=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.11, REQID:9929a7da-49ce-44b0-a5cf-348f7a3305f3, IP:0, U RL:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTIO N:release,TS:-25 X-CID-META: VersionHash:39a5ff1, CLOUDID:ababa107-1cee-4c38-b21b-a45f9682fdc0, B ulkID:nil,BulkQuantity:0,Recheck:0,SF:102,TC:nil,Content:0,EDM:-3,IP:nil,U RL:11|1,File:nil,Bulk:nil,QS:nil,BEC:nil,COL:0 X-UUID: d1fa1afec6fe49afbf67a3593defbebe-20221001 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 1048704068; Sat, 01 Oct 2022 11:17:51 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n2.mediatek.inc (172.21.101.187) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.15; Sat, 1 Oct 2022 11:17:49 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.15 via Frontend Transport; Sat, 1 Oct 2022 11:17:48 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , Tzung-Bi Shih , , , Tiffany Lin CC: Yunfei Dong , Maoguang Meng , Longfei Wang , Irui Wang , , , , , , Subject: [PATCH v6, 8/8] media: mediatek: vcodec: Return encoding result in asynchronous mode Date: Sat, 1 Oct 2022 11:17:37 +0800 Message-ID: <20221001031737.18266-9-irui.wang@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221001031737.18266-1-irui.wang@mediatek.com> References: <20221001031737.18266-1-irui.wang@mediatek.com> MIME-Version: 1.0 X-MTK: N Precedence: bulk List-ID: X-Mailing-List: devicetree@vger.kernel.org when enable multi-core encoding, the wait IRQ done synchronous function should not be called, so the encoding result can't return to client in device_run. Move the buffer done function in IRQ handler. Signed-off-by: Irui Wang --- .../platform/mediatek/vcodec/mtk_vcodec_drv.h | 6 ++ .../platform/mediatek/vcodec/mtk_vcodec_enc.c | 72 +++++++++++++++++-- .../platform/mediatek/vcodec/mtk_vcodec_enc.h | 7 +- .../mediatek/vcodec/mtk_vcodec_enc_drv.c | 28 +++++++- .../mediatek/vcodec/mtk_vcodec_enc_hw.c | 13 +++- .../mediatek/vcodec/mtk_vcodec_enc_pm.c | 1 + .../mediatek/vcodec/mtk_vcodec_util.h | 1 + .../mediatek/vcodec/venc/venc_h264_if.c | 20 ++++-- .../platform/mediatek/vcodec/venc_drv_if.h | 2 + 9 files changed, 137 insertions(+), 13 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h index a75ba675f72b..d9c27ebcf3c3 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h @@ -291,6 +291,9 @@ struct vdec_pic_info { * @msg_queue: msg queue used to store lat buffer information. * @q_mutex: vb2_queue mutex. * @encoded_frame_cnt: number of encoded frames + * @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; @@ -340,6 +343,9 @@ struct mtk_vcodec_ctx { struct mutex q_mutex; int encoded_frame_cnt; + struct vb2_v4l2_buffer *pfrm_buf[MTK_VENC_HW_MAX]; + struct vb2_v4l2_buffer *pbs_buf[MTK_VENC_HW_MAX]; + unsigned int hdr_size; }; /* diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c index d15e106fb246..3424da4aaa26 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c @@ -958,6 +958,8 @@ static void vb2ops_venc_stop_streaming(struct vb2_queue *q) mtk_v4l2_debug(2, "[%d]-> type=%d", ctx->id, q->type); + mtk_venc_lock_all(ctx); + if (q->type == V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE) { while ((dst_buf = v4l2_m2m_dst_buf_remove(ctx->m2m_ctx))) { vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); @@ -1193,6 +1195,7 @@ static void mtk_venc_worker(struct work_struct *work) * is dequeued. */ if (src_buf == &ctx->empty_flush_buf.vb) { + mtk_venc_lock_all(ctx); vb2_set_plane_payload(&dst_buf->vb2_buf, 0, 0); dst_buf->flags |= V4L2_BUF_FLAG_LAST; v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_DONE); @@ -1207,9 +1210,12 @@ static void mtk_venc_worker(struct work_struct *work) frm_buf.fb_addr[i].size = (size_t)src_buf->vb2_buf.planes[i].length; } + frm_buf.frm_addr = src_buf; + bs_buf.va = vb2_plane_vaddr(&dst_buf->vb2_buf, 0); bs_buf.dma_addr = vb2_dma_contig_plane_dma_addr(&dst_buf->vb2_buf, 0); bs_buf.size = (size_t)dst_buf->vb2_buf.planes[0].length; + bs_buf.buf = dst_buf; mtk_v4l2_debug(2, "Framebuf PA=%llx Size=0x%zx;PA=0x%llx Size=0x%zx;PA=0x%llx Size=%zu", @@ -1235,11 +1241,14 @@ static void mtk_venc_worker(struct work_struct *work) v4l2_m2m_buf_done(dst_buf, VB2_BUF_STATE_ERROR); mtk_v4l2_err("venc_if_encode failed=%d", ret); } else { - v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); - 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=%d", - enc_result.bs_size); + if (!IS_VENC_MULTICORE(ctx->dev->enc_capability)) { + v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE); + 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=%d", + enc_result.bs_size); + } } ctx->encoded_frame_cnt++; @@ -1453,6 +1462,34 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq, return vb2_queue_init(dst_vq); } +void mtk_venc_buf_done(struct mtk_vcodec_ctx *ctx, int hw_id, + unsigned int bs_size, bool time_out, bool key_frame) +{ + struct vb2_v4l2_buffer *src_vb2_v4l2 = NULL; + struct vb2_v4l2_buffer *dst_vb2_v4l2 = 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 = ctx->pfrm_buf[hw_id]; + dst_vb2_v4l2 = ctx->pbs_buf[hw_id]; + + if (src_vb2_v4l2 && dst_vb2_v4l2) { + dst_vb2_v4l2->vb2_buf.timestamp = + src_vb2_v4l2->vb2_buf.timestamp; + dst_vb2_v4l2->timecode = src_vb2_v4l2->timecode; + + if (key_frame) + dst_vb2_v4l2->flags |= 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 hw_id) { struct mtk_vcodec_dev *dev = ctx->dev; @@ -1460,6 +1497,7 @@ int mtk_venc_unlock(struct mtk_vcodec_ctx *ctx, int hw_id) mutex_unlock(&dev->enc_mutex[hw_id]); return 0; } +EXPORT_SYMBOL_GPL(mtk_venc_unlock); int mtk_venc_lock(struct mtk_vcodec_ctx *ctx, int hw_id) { @@ -1468,6 +1506,30 @@ int mtk_venc_lock(struct mtk_vcodec_ctx *ctx, int hw_id) mutex_lock(&dev->enc_mutex[hw_id]); return 0; } +EXPORT_SYMBOL_GPL(mtk_venc_lock); + +void mtk_venc_lock_all(struct mtk_vcodec_ctx *ctx) +{ + unsigned int i; + struct mtk_vcodec_dev *dev = ctx->dev; + + /* + * For multi-core 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 = 0; i < MTK_VENC_HW_MAX; i++) { + mutex_lock(&dev->enc_mutex[i]); + mutex_unlock(&dev->enc_mutex[i]); + } +} +EXPORT_SYMBOL_GPL(mtk_venc_lock_all); void mtk_vcodec_enc_release(struct mtk_vcodec_ctx *ctx) { diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h index 29f5c8d1b59f..5ab17381c7ba 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.h @@ -20,6 +20,9 @@ #define MTK_VENC_IRQ_STATUS_OFFSET 0x05C #define MTK_VENC_IRQ_ACK_OFFSET 0x060 +#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098 +#define VENC_PIC_FRM_TYPE 0x0010 +#define VENC_PIC_KEY_FRM 0x2 /** * struct mtk_video_enc_buf - Private data related to each VB2 buffer. @@ -46,5 +49,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *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 hw_id, + unsigned int bs_size, bool time_out, bool key_frame); +void mtk_venc_lock_all(struct mtk_vcodec_ctx *ctx); #endif /* _MTK_VCODEC_ENC_H_ */ diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c index ba9c19a4d2cc..b34d7583fccc 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c @@ -89,6 +89,9 @@ static irqreturn_t mtk_vcodec_enc_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 = 0; spin_lock_irqsave(&dev->irqlock, flags); ctx = dev->curr_enc_ctx[MTK_VENC_CORE_0]; @@ -101,8 +104,32 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, void *priv) ctx->irq_status = readl(dev->reg_base[dev->venc_pdata->core_id] + (MTK_VENC_IRQ_STATUS_OFFSET)); + bs_size = readl(dev->reg_base[dev->venc_pdata->core_id] + + (VENC_PIC_BITSTREAM_BYTE_CNT)); + frm_type = readl(dev->reg_base[dev->venc_pdata->core_id] + + (VENC_PIC_FRM_TYPE)); + clean_irq_status(ctx->irq_status, addr); + if (IS_VENC_MULTICORE(dev->enc_capability)) { + if (ctx->irq_status & MTK_VENC_IRQ_STATUS_FRM) { + if (ctx->hdr_size != 0) { + bs_size += ctx->hdr_size; + ctx->hdr_size = 0; + } + + if (frm_type & VENC_PIC_KEY_FRM) + is_key_frame = 1; + + mtk_venc_buf_done(ctx, 0, bs_size, 0, is_key_frame); + mtk_vcodec_enc_clock_off(dev, 0); + mtk_venc_unlock(ctx, 0); + } else { + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); + } + return IRQ_HANDLED; + } + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); return IRQ_HANDLED; } @@ -284,7 +311,6 @@ static int mtk_vcodec_probe(struct platform_device *pdev) goto err_res; } - irq_set_status_flags(dev->enc_irq, IRQ_NOAUTOEN); ret = devm_request_irq(&pdev->dev, dev->enc_irq, mtk_vcodec_enc_irq_handler, 0, pdev->name, dev); diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c index 6df5221b742f..0367e59b20a9 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_hw.c @@ -50,6 +50,9 @@ static irqreturn_t mtk_enc_hw_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 = 0; spin_lock_irqsave(&main_dev->irqlock, flags); ctx = main_dev->curr_enc_ctx[dev->hw_id]; @@ -61,9 +64,17 @@ static irqreturn_t mtk_enc_hw_irq_handler(int irq, void *priv) addr = dev->reg_base + MTK_VENC_IRQ_ACK_OFFSET; ctx->irq_status = readl(dev->reg_base + MTK_VENC_IRQ_STATUS_OFFSET); + bs_size = readl(dev->reg_base + VENC_PIC_BITSTREAM_BYTE_CNT); + frm_type = readl(dev->reg_base + VENC_PIC_FRM_TYPE); clean_hw_irq_status(ctx->irq_status, addr); - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); + if (frm_type & VENC_PIC_KEY_FRM) + is_key_frame = 1; + + mtk_venc_buf_done(ctx, dev->hw_id, bs_size, 0, is_key_frame); + mtk_vcodec_enc_clock_off(main_dev, dev->hw_id); + mtk_venc_unlock(ctx, dev->hw_id); + return IRQ_HANDLED; } diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c index 2f83aade779a..af2968a8d2e5 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c +++ b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_pm.c @@ -235,3 +235,4 @@ void mtk_vcodec_enc_clock_off(struct mtk_vcodec_dev *dev, for (i = enc_clk->clk_num - 1; i >= 0; i--) clk_disable(enc_clk->clk_info[i].vcodec_clk); } +EXPORT_SYMBOL_GPL(mtk_vcodec_enc_clock_off); diff --git a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h b/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h index 0033c53d5589..cecf78d6d4c6 100644 --- a/drivers/media/platform/mediatek/vcodec/mtk_vcodec_util.h +++ b/drivers/media/platform/mediatek/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; }; struct mtk_vcodec_fb { diff --git a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c index 32497a35afb1..a6990221d845 100644 --- a/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mediatek/vcodec/venc/venc_h264_if.c @@ -22,7 +22,6 @@ static const char h264_filler_marker[] = {0x0, 0x0, 0x0, 0x1, 0xc}; #define H264_FILLER_MARKER_SIZE ARRAY_SIZE(h264_filler_marker) -#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098 /* * enum venc_h264_frame_type - h264 encoder output bitstream frame type @@ -620,6 +619,11 @@ static int h264_encode_frame(struct venc_h264_inst *inst, return ret; } + if (IS_VENC_MULTICORE(ctx->dev->enc_capability)) { + ++inst->frm_cnt; + return ret; + } + irq_status = h264_enc_wait_venc_done(inst); if (irq_status != MTK_VENC_IRQ_STATUS_FRM) { mtk_vcodec_err(inst, "irq_status=%d failed", irq_status); @@ -705,8 +709,6 @@ static int h264_enc_encode(void *handle, mtk_vcodec_debug(inst, "opt %d ->", opt); - enable_irq(ctx->dev->enc_irq); - switch (opt) { case VENC_START_OPT_ENCODE_SEQUENCE_HEADER: { unsigned int bs_size_hdr; @@ -729,6 +731,13 @@ static int h264_enc_encode(void *handle, unsigned int bs_size_hdr; unsigned int bs_size_frm; + /* + * the frm_buf and bs_buf need to recorded into current ctx, + * when encoding done, the target buffers can be got from ctx. + */ + ctx->pfrm_buf[ctx->hw_id] = frm_buf->frm_addr; + ctx->pbs_buf[ctx->hw_id] = bs_buf->buf; + if (!inst->prepend_hdr) { ret = h264_encode_frame(inst, frm_buf, bs_buf, &result->bs_size, ctx->hw_id); @@ -763,7 +772,9 @@ static int h264_enc_encode(void *handle, if (ret) goto encode_err; - result->bs_size = hdr_sz + filler_sz + bs_size_frm; + ctx->hdr_size = hdr_sz + filler_sz; + + result->bs_size = ctx->hdr_size + bs_size_frm; mtk_vcodec_debug(inst, "hdr %d filler %d frame %d bs %d", hdr_sz, filler_sz, bs_size_frm, @@ -782,7 +793,6 @@ static int h264_enc_encode(void *handle, encode_err: - disable_irq(ctx->dev->enc_irq); mtk_vcodec_debug(inst, "opt %d <-", opt); return ret; diff --git a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h b/drivers/media/platform/mediatek/vcodec/venc_drv_if.h index e676ccf6bd25..7e24b7f573d7 100644 --- a/drivers/media/platform/mediatek/vcodec/venc_drv_if.h +++ b/drivers/media/platform/mediatek/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 + * @frm_addr: current v4l2 buffer address */ struct venc_frm_buf { struct mtk_vcodec_fb fb_addr[MTK_VCODEC_MAX_PLANES]; + void *frm_addr; }; /*