From patchwork Wed May 28 06:36:27 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 110842 X-Patchwork-Delegate: nicolas@ndufresne.ca Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKAPm-0005Uy-1W for patchwork@linuxtv.org; Wed, 28 May 2025 06:37:29 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 7FAF21899C96 for ; Wed, 28 May 2025 06:37:34 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id DC4E224469D; Wed, 28 May 2025 06:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="SU1pYMox" X-Original-To: linux-media@vger.kernel.org Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 127DB228C8D; Wed, 28 May 2025 06:36:50 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414214; cv=none; b=AEeb9W6twddqUi7KrhMq5RT4+a8f4P6L4hxtmoQATQAwtT1joiPVomuxSGkj9guoh2EpBScaa1eVL5/azyS9ZcDSrxJ2xsWfwqlrzxMbjNLmMRSwFSdeab98Jj2cpRn6IcYK1Zl1V5rJUM5W2hjMGqXQYq22WylBKVMCsyaOiiU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414214; c=relaxed/simple; bh=57TKgqYeC2ixAsN/JJ0kX/KRl7U40EUaS+na0ZLw6+I=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=AJyJDMyavCWqCyy2otYrQx/4xuxqeCaNrp+7OT4hyrb2WYmEAKFvGtG43gWRxdQdjD8R3mfd2MPnhCfSpXUL5++OfxS8CwcKTalSXmIDf8+BIMDKlVOyu2v5LYIOSx5cMWEDrcrXmBeb9kcY01Xdb8VgbqlXdj112FSgscq4nyA= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=SU1pYMox; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 1e5a3e9c3b8e11f082f7f7ac98dee637-20250528 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=u8b2CBv46yhu29l1dvZet6/bf2VoP/lZOxKl5hd+NUs=; b=SU1pYMoxm0K/I1T8QrA3L6gR3vo6ks36tbZsGBozgqu7He6B2GCWzvZHcpdOA1VmdZxlce5oezVm8od7xIHgtUGlnuo3SsLve2Mdr2L7pHE1/+sPn0YMBVb2b7xdqABTUTBRqrjfb9PTN0zkUx0aoSQmg0NpT21TJNIN5P0qwBo=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:7f83e036-6f61-4b2e-9298-03bf030946b7,IP:0,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-25 X-CID-META: VersionHash:0ef645f,CLOUDID:5b3e0f58-abad-4ac2-9923-3af0a8a9a079,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1e5a3e9c3b8e11f082f7f7ac98dee637-20250528 Received: from mtkmbs09n1.mediatek.inc [(172.21.101.35)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 985750532; Wed, 28 May 2025 14:36:42 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS09N2.mediatek.inc (172.21.101.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Wed, 28 May 2025 14:36:40 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Wed, 28 May 2025 14:36:40 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , , , CC: , , , , , , Yunfei Dong , Longfei Wang , Irui Wang Subject: [PATCH v2 1/6] media: mediatek: encoder: Add a new encoder driver interface Date: Wed, 28 May 2025 14:36:27 +0800 Message-ID: <20250528063633.14054-2-irui.wang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250528063633.14054-1-irui.wang@mediatek.com> References: <20250528063633.14054-1-irui.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no Introduce a new encoder kernel driver interface to ensure compatibility with the updated encoder software driver running in firmware. The new driver interface is expected to support more encoder formats, share more encode parameters between kernel and firmware. Signed-off-by: Irui Wang --- .../mediatek/vcodec/common/mtk_vcodec_fw.c | 13 + .../mediatek/vcodec/common/mtk_vcodec_fw.h | 1 + .../platform/mediatek/vcodec/encoder/Makefile | 1 + .../mediatek/vcodec/encoder/mtk_vcodec_enc.c | 14 +- .../vcodec/encoder/mtk_vcodec_enc_drv.h | 8 +- .../vcodec/encoder/venc/venc_common_if.c | 667 ++++++++++++++++++ .../vcodec/encoder/venc/venc_h264_if.c | 8 +- .../mediatek/vcodec/encoder/venc_drv_if.h | 11 +- 8 files changed, 705 insertions(+), 18 deletions(-) create mode 100644 drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c index 4ed7639dfa30..0381acceda25 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c @@ -18,6 +18,19 @@ int mtk_vcodec_fw_get_ipi(enum mtk_vcodec_fw_type type, int hw_id) } EXPORT_SYMBOL_GPL(mtk_vcodec_fw_get_ipi); +int mtk_vcodec_fw_get_venc_ipi(enum mtk_vcodec_fw_type type) +{ + switch (type) { + case SCP: + return SCP_IPI_VENC_H264; + case VCP: + return VCP_IPI_ENCODER; + default: + return -EINVAL; + } +} +EXPORT_SYMBOL_GPL(mtk_vcodec_fw_get_venc_ipi); + struct mtk_vcodec_fw *mtk_vcodec_fw_select(void *priv, enum mtk_vcodec_fw_type type, enum mtk_vcodec_fw_use fw_use) { diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h index 142e2e87905c..e7304a7dd3e0 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h @@ -42,5 +42,6 @@ int mtk_vcodec_fw_ipi_send(struct mtk_vcodec_fw *fw, int id, void *buf, unsigned int len, unsigned int wait); int mtk_vcodec_fw_get_type(struct mtk_vcodec_fw *fw); int mtk_vcodec_fw_get_ipi(enum mtk_vcodec_fw_type type, int hw_id); +int mtk_vcodec_fw_get_venc_ipi(enum mtk_vcodec_fw_type type); #endif /* _MTK_VCODEC_FW_H_ */ diff --git a/drivers/media/platform/mediatek/vcodec/encoder/Makefile b/drivers/media/platform/mediatek/vcodec/encoder/Makefile index e621b5b7e5e6..9d3229d56e39 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/Makefile +++ b/drivers/media/platform/mediatek/vcodec/encoder/Makefile @@ -4,6 +4,7 @@ obj-$(CONFIG_VIDEO_MEDIATEK_VCODEC) += mtk-vcodec-enc.o mtk-vcodec-enc-y := venc/venc_vp8_if.o \ venc/venc_h264_if.o \ + venc/venc_common_if.o \ mtk_vcodec_enc.o \ mtk_vcodec_enc_drv.o \ mtk_vcodec_enc_pm.o \ diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c index dcafb1303c29..03512bf7a072 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c @@ -81,11 +81,11 @@ static int vidioc_venc_s_ctrl(struct v4l2_ctrl *ctrl) break; case V4L2_CID_MPEG_VIDEO_H264_PROFILE: mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_PROFILE val = %d", ctrl->val); - p->h264_profile = ctrl->val; + p->profile = ctrl->val; break; case V4L2_CID_MPEG_VIDEO_H264_LEVEL: mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_LEVEL val = %d", ctrl->val); - p->h264_level = ctrl->val; + p->level = ctrl->val; break; case V4L2_CID_MPEG_VIDEO_H264_I_PERIOD: mtk_v4l2_venc_dbg(2, ctx, "V4L2_CID_MPEG_VIDEO_H264_I_PERIOD val = %d", ctrl->val); @@ -386,8 +386,8 @@ static void mtk_venc_set_param(struct mtk_vcodec_enc_ctx *ctx, mtk_v4l2_venc_err(ctx, "Unsupported fourcc =%d", q_data_src->fmt->fourcc); break; } - param->h264_profile = enc_params->h264_profile; - param->h264_level = enc_params->h264_level; + param->profile = enc_params->profile; + param->level = enc_params->level; /* Config visible resolution */ param->width = q_data_src->visible_width; @@ -403,8 +403,8 @@ static void mtk_venc_set_param(struct mtk_vcodec_enc_ctx *ctx, mtk_v4l2_venc_dbg(0, ctx, "fmt 0x%x, P/L %d/%d w/h %d/%d buf %d/%d fps/bps %d/%d gop %d i_per %d", - param->input_yuv_fmt, param->h264_profile, - param->h264_level, param->width, param->height, + param->input_yuv_fmt, param->profile, + param->level, param->width, param->height, param->buf_width, param->buf_height, param->frm_rate, param->bitrate, param->gop_size, param->intra_period); @@ -1174,6 +1174,8 @@ 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.num_planes = src_buf->vb2_buf.num_planes; + 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; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h index 0bd85d0fb379..b1277bcfcf53 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h @@ -69,8 +69,8 @@ enum mtk_encode_param { * @framerate_denom: frame rate denominator. ex: framerate_num=30 and * framerate_denom=1 means FPS is 30 * @h264_max_qp: Max value for H.264 quantization parameter - * @h264_profile: V4L2 defined H.264 profile - * @h264_level: V4L2 defined H.264 level + * @profile: V4L2 defined profile + * @level: V4L2 defined level * @force_intra: force/insert intra frame */ struct mtk_enc_params { @@ -84,8 +84,8 @@ struct mtk_enc_params { unsigned int framerate_num; unsigned int framerate_denom; unsigned int h264_max_qp; - unsigned int h264_profile; - unsigned int h264_level; + unsigned int profile; + unsigned int level; unsigned int force_intra; }; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c new file mode 100644 index 000000000000..8092929e9297 --- /dev/null +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c @@ -0,0 +1,667 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2025 MediaTek Inc. + */ + +#include "../mtk_vcodec_enc.h" +#include "../mtk_vcodec_enc_drv.h" +#include "../venc_drv_base.h" +#include "../venc_drv_if.h" +#include "../venc_vpu_if.h" +#include "../../common/mtk_vcodec_intr.h" +#include "../../common/mtk_vcodec_util.h" + +#define SEQ_HEADER_SIZE 1024 +#define PPS_SIZE 128 +#define MAX_DPB_SIZE 16 +#define MAX_VENC_CORE 3 +#define VENC_CONFIG_LENGTH 115 +#define VENC_CONFIG_DATA 128 +#define VENC_PIC_BITSTREAM_BYTE_CNT 0x0098 + +/** + * enum venc_bs_mode - encode bitstream mode + * @VENC_BS_MODE_SPS: encode sps + * @VENC_BS_MODE_PPS: encode pps + * @VENC_BS_MODE_VPS: encode vps + * @VENC_BS_MODE_SEQ_HDR: encode sequence header + * @VENC_BS_MODE_FRAME: encode frame + * @VENC_BS_MODE_FRAME_FINAL: encode final frame + * @VENC_BS_MODE_MAX: max value + */ +enum venc_bs_mode { + VENC_BS_MODE_SPS = 0, + VENC_BS_MODE_PPS, + VENC_BS_MODE_VPS, + VENC_BS_MODE_SEQ_HDR, + VENC_BS_MODE_FRAME, + VENC_BS_MODE_FRAME_FINAL, + VENC_BS_MODE_MAX +}; + +/** + * struct venc_config - Structure for encoder configuration + * AP-W/R : AP is writer/reader on this item + * MCU-W/R: MCU is write/reader on this item + * @input_fourcc: input format fourcc + * @bitrate: target bitrate (in bps) + * @pic_w: visible width of resolution + * @pic_h: visible height of resolution + * @buf_w: buffer alignment width of resolution + * @buf_h: buffer alignment height of resolution + * @gop_size: group of picture size (IDR frame period) + * @intra_period: I frame period + * @framerate: frame rate in fps + * @profile: profile_idc in SPS + * @level: level_idc in SPS + * @core_num: encoder core num + * @dpb_size: encode dpb size + * @reserved: reserved fields config + */ +struct venc_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 core_num; + __u32 dpb_size; + __u32 reserved[VENC_CONFIG_LENGTH]; +}; + +/** + * struct venc_config_data - Structure for configuration data + * @config_data: extended configuration data besides the basic configuration + */ +struct venc_config_data { + unsigned int config_data[VENC_CONFIG_DATA]; +}; + +/** + * struct venc_work_buf - Structure for working buffer information + * AP-W/R : AP is writer/reader on this item + * MCU-W/R: MCU is write/reader on this item + * @iova: IO virtual address + * @pa: physical address + * @pa_64: for 64bit pa padding + * @va: virtual address + * @va_padding: for 64bit va padding + * @size: buffer size + * @size_padding: for 64bit size padding + */ +struct venc_work_buf { + unsigned long long iova; + union { + unsigned int pa; + unsigned long long pa_64; + }; + union { + void *va; + unsigned long long va_padding; + }; + union { + unsigned int size; + unsigned long long size_padding; + }; +}; + +/** + * struct venc_work_buf_list - Structure for encode working buffer list + * @rc_code: RC code buffer + * @rc_info: RC info buffer + * @luma: luma buffer + * @chroma: chroma buffer + * @sub_luma: sub luma buffer + * @sub_write: sub write buffer + * @col_mv: col_mv buffer + * @wpp: wpp buffer + * @wpp_nbm: wpp nbm buffer + * @skip_frame: skip frame buffer + */ +struct venc_work_buf_list { + struct venc_work_buf rc_code; + struct venc_work_buf rc_info[MAX_VENC_CORE]; + struct venc_work_buf luma[MAX_DPB_SIZE]; + struct venc_work_buf chroma[MAX_DPB_SIZE]; + struct venc_work_buf sub_luma[MAX_DPB_SIZE]; + struct venc_work_buf sub_write[MAX_DPB_SIZE]; + struct venc_work_buf col_mv[MAX_DPB_SIZE]; + struct venc_work_buf wpp[MAX_VENC_CORE]; + struct venc_work_buf wpp_nbm[MAX_VENC_CORE]; + struct venc_work_buf skip_frame; +}; + +/** + * struct venc_info - Structure for encode frame and bs information + * @fb_addr: frame buffer address array + * @fb_size: frame buffer size array + * @bs_addr: bitstream buffer address + * @bs_size: bitstream buffer size + */ +struct venc_info { + unsigned long long fb_addr[VIDEO_MAX_PLANES]; + unsigned int fb_size[VIDEO_MAX_PLANES]; + unsigned long long bs_addr; + unsigned long long bs_size; +}; + +/** + * struct venc_vsi - Structure for VCP driver control and info share + * AP-W/R : AP is writer/reader on this item + * VCP-W/R: VCP is write/reader on this item + * @config: encoder configuration + * @data: encoder configuration data + * @bufs: encoder working buffers + * @venc: encoder information + */ +struct venc_vsi { + struct venc_config config; + struct venc_config_data data; + struct venc_work_buf_list bufs; + struct venc_info venc; +}; + +/** + * struct venc_inst - Structure for encoder instance + * @hw_base: hardware io address + * @pps_buf: PPS buffer + * @seq_buf: sequence header buffer + * @work_buf_allocated: work buffer allocated or not + * @frm_cnt: encoded frame count + * @skip_frm_cnt: encoded skip frame count + * @prepend_hdr: prepend header flag + * @vpu_inst: vpu instance + * @vsi: encode vsi + * @ctx: encoder context + */ +struct venc_inst { + void __iomem *hw_base; + struct mtk_vcodec_mem pps_buf; + struct mtk_vcodec_mem seq_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_vsi *vsi; + struct mtk_vcodec_enc_ctx *ctx; +}; + +static int venc_init(struct mtk_vcodec_enc_ctx *ctx) +{ + int ret = 0; + struct venc_inst *inst; + + inst = kzalloc(sizeof(*inst), GFP_KERNEL); + if (!inst) + return -ENOMEM; + + inst->ctx = ctx; + inst->vpu_inst.ctx = ctx; + inst->vpu_inst.id = mtk_vcodec_fw_get_venc_ipi(ctx->dev->fw_handler->type); + inst->hw_base = mtk_vcodec_get_reg_addr(inst->ctx->dev->reg_base, VENC_SYS); + + ret = vpu_enc_init(&inst->vpu_inst); + inst->vsi = (struct venc_vsi *)inst->vpu_inst.vsi; + + if (ret) + kfree(inst); + else + ctx->drv_handle = inst; + + return ret; +} + +static inline u32 venc_read_reg(struct venc_inst *inst, u32 addr) +{ + return readl(inst->hw_base + addr); +} + +static unsigned int venc_wait_encode_done(struct venc_inst *inst) +{ + unsigned int irq_status = 0; + struct mtk_vcodec_enc_ctx *ctx = (struct mtk_vcodec_enc_ctx *)inst->ctx; + + if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED, + WAIT_INTR_TIMEOUT_MS, 0)) { + irq_status = ctx->irq_status; + mtk_venc_debug(ctx, "irq_status %x <-", irq_status); + } + return irq_status; +} + +static void venc_set_bufs(struct venc_inst *inst, + struct venc_frm_buf *frm_buf, + struct mtk_vcodec_mem *bs_buf) +{ + unsigned int i; + + if (frm_buf) { + for (i = 0; i < frm_buf->num_planes; i++) { + inst->vsi->venc.fb_addr[i] = frm_buf->fb_addr[i].dma_addr; + inst->vsi->venc.fb_size[i] = frm_buf->fb_addr[i].size; + mtk_venc_debug(inst->ctx, "%s: fb_buf[%d]: %llx(%d)\n", + __func__, i, + inst->vsi->venc.fb_addr[i], + inst->vsi->venc.fb_size[i]); + } + } + + if (bs_buf) { + inst->vsi->venc.bs_addr = bs_buf->dma_addr; + inst->vsi->venc.bs_size = bs_buf->size; + mtk_venc_debug(inst->ctx, "%s: bs_buf: %llx(%d)\n", + __func__, + inst->vsi->venc.bs_addr, + (unsigned int)inst->vsi->venc.bs_size); + } +} + +static int venc_encode_sps(struct venc_inst *inst, + struct mtk_vcodec_mem *bs_buf, + unsigned int *bs_size) +{ + int ret = 0; + unsigned int irq_status; + + venc_set_bufs(inst, NULL, bs_buf); + ret = vpu_enc_encode(&inst->vpu_inst, VENC_BS_MODE_SPS, NULL, bs_buf, NULL); + if (ret) + return ret; + + irq_status = venc_wait_encode_done(inst); + if (irq_status != MTK_VENC_IRQ_STATUS_SPS) { + mtk_venc_err(inst->ctx, "expect irq status %d", MTK_VENC_IRQ_STATUS_SPS); + return -EINVAL; + } + + *bs_size = venc_read_reg(inst, VENC_PIC_BITSTREAM_BYTE_CNT); + mtk_venc_debug(inst->ctx, "sps bs size %d <-", *bs_size); + + return ret; +} + +static int venc_encode_pps(struct venc_inst *inst, + struct mtk_vcodec_mem *bs_buf, + unsigned int *bs_size) +{ + int ret = 0; + unsigned int irq_status; + + venc_set_bufs(inst, NULL, bs_buf); + ret = vpu_enc_encode(&inst->vpu_inst, VENC_BS_MODE_PPS, NULL, bs_buf, NULL); + if (ret) + return ret; + + irq_status = venc_wait_encode_done(inst); + if (irq_status != MTK_VENC_IRQ_STATUS_PPS) { + mtk_venc_err(inst->ctx, "expect irq status %d", MTK_VENC_IRQ_STATUS_PPS); + return -EINVAL; + } + + *bs_size = venc_read_reg(inst, VENC_PIC_BITSTREAM_BYTE_CNT); + mtk_venc_debug(inst->ctx, "pps bs size %d <-", *bs_size); + + return ret; +} + +static int venc_encode_header(struct venc_inst *inst, + struct mtk_vcodec_mem *bs_buf, + unsigned int *bs_size) +{ + int ret = 0; + unsigned int bs_size_sps; + unsigned int bs_size_pps; + + ret = venc_encode_sps(inst, bs_buf, &bs_size_sps); + if (ret) + return ret; + + ret = venc_encode_pps(inst, &inst->pps_buf, &bs_size_pps); + if (ret) + return ret; + + memcpy(bs_buf->va + bs_size_sps, inst->pps_buf.va, bs_size_pps); + *bs_size = bs_size_sps + bs_size_pps; + + return ret; +} + +static int venc_encode_frame(struct venc_inst *inst, + struct venc_frm_buf *frm_buf, + struct mtk_vcodec_mem *bs_buf, + unsigned int *bs_size) +{ + int ret = 0; + unsigned int irq_status; + + venc_set_bufs(inst, frm_buf, bs_buf); + ret = vpu_enc_encode(&inst->vpu_inst, VENC_BS_MODE_FRAME, frm_buf, bs_buf, NULL); + if (ret) + return ret; + + irq_status = venc_wait_encode_done(inst); + if (irq_status != MTK_VENC_IRQ_STATUS_FRM) { + mtk_venc_err(inst->ctx, "expect irq status %d", MTK_VENC_IRQ_STATUS_FRM); + return -EINVAL; + } + + *bs_size = venc_read_reg(inst, VENC_PIC_BITSTREAM_BYTE_CNT); + + ++inst->frm_cnt; + + return ret; +} + +static int venc_encode(void *handle, + enum venc_start_opt opt, + struct venc_frm_buf *frm_buf, + struct mtk_vcodec_mem *bs_buf, + struct venc_done_result *result) +{ + int ret = 0; + struct venc_inst *inst = (struct venc_inst *)handle; + struct mtk_vcodec_enc_ctx *ctx; + unsigned int bs_size_hdr; + + if (WARN_ON(!inst || !inst->vsi)) + return -EINVAL; + + ctx = inst->ctx; + + mtk_venc_debug(ctx, "%s: opt: %d\n", __func__, opt); + + enable_irq(ctx->dev->enc_irq); + switch (opt) { + case VENC_START_OPT_ENCODE_SEQUENCE_HEADER: { + ret = venc_encode_header(inst, bs_buf, &bs_size_hdr); + if (ret) + goto encode_err; + + result->bs_size = bs_size_hdr; + result->is_key_frm = false; + break; + } + + case VENC_START_OPT_ENCODE_FRAME: { + if (!inst->prepend_hdr) { + ret = venc_encode_frame(inst, frm_buf, bs_buf, &result->bs_size); + if (ret) + goto encode_err; + + result->is_key_frm = inst->vpu_inst.is_key_frm; + break; + } + + ret = venc_encode_header(inst, &inst->seq_buf, &bs_size_hdr); + if (ret) + goto encode_err; + + ret = venc_encode_frame(inst, frm_buf, bs_buf, &result->bs_size); + if (ret) + goto encode_err; + + memmove(bs_buf->va + bs_size_hdr, bs_buf->va, result->bs_size); + memcpy(bs_buf->va, inst->seq_buf.va, bs_size_hdr); + result->bs_size += bs_size_hdr; + + inst->prepend_hdr = 0; + result->is_key_frm = inst->vpu_inst.is_key_frm; + break; + } + + default: + mtk_venc_err(inst->ctx, "venc_opt %d not supported", opt); + ret = -EINVAL; + break; + } + +encode_err: + disable_irq(ctx->dev->enc_irq); + mtk_venc_debug(ctx, "opt %d, return %d", opt, ret); + + return ret; +} + +static int mtk_venc_mem_alloc(struct venc_inst *inst, + struct device *dev, + struct venc_work_buf *buf) +{ + dma_addr_t dma_addr; + + if (WARN_ON(!dev || !buf)) + return -EINVAL; + + if (buf->size == 0) + return 0; + + buf->va = dma_alloc_coherent(dev, buf->size, &dma_addr, GFP_KERNEL); + if (!buf->va) + return -ENOMEM; + + buf->iova = (unsigned long long)dma_addr; + + mtk_venc_debug(inst->ctx, "allocate buffer, size: %d, va: %p, iova: 0x%llx", + buf->size, buf->va, buf->iova); + + return 0; +} + +static void mtk_venc_mem_free(struct venc_inst *inst, + struct device *dev, + struct venc_work_buf *buf) +{ + if (WARN_ON(!dev || !buf)) + return; + + if (!buf->va) + return; + + mtk_venc_debug(inst->ctx, "free buffer, size: %d, va: %p, iova: 0x%llx", + buf->size, buf->va, buf->iova); + + dma_free_coherent(dev, buf->size, buf->va, buf->iova); + buf->va = NULL; + buf->iova = 0; + buf->size = 0; +} + +static void venc_free_rc_buf(struct venc_inst *inst, + struct venc_work_buf_list *bufs, + unsigned int core_num) +{ + int i; + struct device *dev; + + dev = &inst->ctx->dev->plat_dev->dev; + mtk_venc_mem_free(inst, dev, &bufs->rc_code); + + for (i = 0; i < core_num; i++) + mtk_venc_mem_free(inst, dev, &bufs->rc_info[i]); +} + +static void venc_free_work_buf(struct venc_inst *inst) +{ + int i; + struct venc_work_buf_list *bufs = &inst->vsi->bufs; + unsigned int core_num = inst->vsi->config.core_num; + unsigned int dpb_size = inst->vsi->config.dpb_size; + struct device *dev; + + if (bufs->rc_code.va) + venc_free_rc_buf(inst, bufs, core_num); + + dev = &inst->ctx->dev->plat_dev->dev; + + for (i = 0; i < core_num; i++) { + mtk_venc_mem_free(inst, dev, &bufs->wpp[i]); + mtk_venc_mem_free(inst, dev, &bufs->wpp_nbm[i]); + } + + for (i = 0; i < dpb_size; i++) { + mtk_venc_mem_free(inst, dev, &bufs->luma[i]); + mtk_venc_mem_free(inst, dev, &bufs->chroma[i]); + mtk_venc_mem_free(inst, dev, &bufs->sub_luma[i]); + mtk_venc_mem_free(inst, dev, &bufs->sub_write[i]); + mtk_venc_mem_free(inst, dev, &bufs->col_mv[i]); + } + + if (inst->pps_buf.va) + mtk_vcodec_mem_free(inst->ctx, &inst->pps_buf); + + if (inst->seq_buf.va) + mtk_vcodec_mem_free(inst->ctx, &inst->seq_buf); +} + +static int venc_alloc_rc_buf(struct venc_inst *inst, + struct venc_work_buf_list *bufs, + unsigned int core_num) +{ + int i; + struct mtk_vcodec_fw *fw = inst->ctx->dev->fw_handler; + struct device *dev; + void *tmp_va; + + dev = &inst->ctx->dev->plat_dev->dev; + if (mtk_venc_mem_alloc(inst, dev, &bufs->rc_code)) + return -ENOMEM; + + tmp_va = mtk_vcodec_fw_map_dm_addr(fw, bufs->rc_code.pa); + memcpy(bufs->rc_code.va, tmp_va, bufs->rc_code.size); + + for (i = 0; i < core_num; i++) { + if (mtk_venc_mem_alloc(inst, dev, &bufs->rc_info[i])) + return -ENOMEM; + } + + return 0; +} + +static int venc_alloc_work_buf(struct venc_inst *inst) +{ + int i, ret; + struct venc_work_buf_list *bufs = &inst->vsi->bufs; + unsigned int core_num = inst->vsi->config.core_num; + unsigned int dpb_size = inst->vsi->config.dpb_size; + struct device *dev; + + if (bufs->rc_code.size != 0) { + ret = venc_alloc_rc_buf(inst, bufs, core_num); + if (ret) { + mtk_venc_err(inst->ctx, "cannot allocate rc buf"); + goto err_alloc; + } + } + + dev = &inst->ctx->dev->plat_dev->dev; + + for (i = 0; i < core_num; i++) { + if (mtk_venc_mem_alloc(inst, dev, &bufs->wpp[i]) || + mtk_venc_mem_alloc(inst, dev, &bufs->wpp_nbm[i])) + goto err_alloc; + } + + for (i = 0; i < dpb_size; i++) { + if (mtk_venc_mem_alloc(inst, dev, &bufs->luma[i]) || + mtk_venc_mem_alloc(inst, dev, &bufs->chroma[i]) || + mtk_venc_mem_alloc(inst, dev, &bufs->sub_luma[i]) || + mtk_venc_mem_alloc(inst, dev, &bufs->sub_write[i]) || + mtk_venc_mem_alloc(inst, dev, &bufs->col_mv[i])) + goto err_alloc; + } + + /* the pps_buf and seq_buf are used by AP side only */ + inst->pps_buf.size = PPS_SIZE; + ret = mtk_vcodec_mem_alloc(inst->ctx, &inst->pps_buf); + if (ret) { + mtk_venc_err(inst->ctx, "cannot allocate pps_buf"); + goto err_alloc; + } + + inst->seq_buf.size = SEQ_HEADER_SIZE; + ret = mtk_vcodec_mem_alloc(inst->ctx, &inst->seq_buf); + if (ret) { + mtk_venc_err(inst->ctx, "cannot allocate seq_buf"); + goto err_alloc; + } + return 0; + +err_alloc: + venc_free_work_buf(inst); + return -ENOMEM; +} + +static int venc_set_param(void *handle, + enum venc_set_param_type type, + struct venc_enc_param *enc_prm) +{ + int ret = 0; + struct venc_inst *inst = (struct venc_inst *)handle; + + switch (type) { + case VENC_SET_PARAM_ENC: + if (WARN_ON(!inst->vsi)) + return -EINVAL; + inst->vsi->config.input_fourcc = enc_prm->input_yuv_fmt; + inst->vsi->config.bitrate = enc_prm->bitrate; + inst->vsi->config.pic_w = enc_prm->width; + inst->vsi->config.pic_h = enc_prm->height; + inst->vsi->config.buf_w = enc_prm->buf_width; + inst->vsi->config.buf_h = enc_prm->buf_height; + inst->vsi->config.gop_size = enc_prm->gop_size; + inst->vsi->config.framerate = enc_prm->frm_rate; + inst->vsi->config.intra_period = enc_prm->intra_period; + inst->vsi->config.profile = enc_prm->profile; + inst->vsi->config.level = enc_prm->level; + + ret = vpu_enc_set_param(&inst->vpu_inst, type, enc_prm); + if (ret) + break; + + if (inst->work_buf_allocated) { + venc_free_work_buf(inst); + inst->work_buf_allocated = false; + } + ret = venc_alloc_work_buf(inst); + if (ret) + break; + inst->work_buf_allocated = true; + break; + case VENC_SET_PARAM_PREPEND_HEADER: + inst->prepend_hdr = 1; + break; + default: + ret = vpu_enc_set_param(&inst->vpu_inst, type, enc_prm); + break; + } + + return ret; +} + +static int venc_deinit(void *handle) +{ + int ret = 0; + struct venc_inst *inst = (struct venc_inst *)handle; + + ret = vpu_enc_deinit(&inst->vpu_inst); + + if (inst->work_buf_allocated) + venc_free_work_buf(inst); + + kfree(inst); + + return ret; +} + +const struct venc_common_if venc_if = { + .init = venc_init, + .encode = venc_encode, + .set_param = venc_set_param, + .deinit = venc_deinit, +}; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c index 8522f71fc901..f201d116ed46 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_h264_if.c @@ -723,9 +723,9 @@ static void h264_enc_set_vsi_configs(struct venc_h264_inst *inst, inst->vsi->config.framerate = enc_prm->frm_rate; inst->vsi->config.intra_period = enc_prm->intra_period; inst->vsi->config.profile = - h264_get_profile(inst, enc_prm->h264_profile); + h264_get_profile(inst, enc_prm->profile); inst->vsi->config.level = - h264_get_level(inst, enc_prm->h264_level); + h264_get_level(inst, enc_prm->level); inst->vsi->config.wfd = 0; } @@ -742,9 +742,9 @@ static void h264_enc_set_vsi_34_configs(struct venc_h264_inst *inst, inst->vsi_34->config.framerate = enc_prm->frm_rate; inst->vsi_34->config.intra_period = enc_prm->intra_period; inst->vsi_34->config.profile = - h264_get_profile(inst, enc_prm->h264_profile); + h264_get_profile(inst, enc_prm->profile); inst->vsi_34->config.level = - h264_get_level(inst, enc_prm->h264_level); + h264_get_level(inst, enc_prm->level); inst->vsi_34->config.wfd = 0; } diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.h b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.h index 889440a436b6..3c2a1b5e9312 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.h @@ -66,8 +66,8 @@ enum venc_set_param_type { * struct venc_enc_prm - encoder settings for VENC_SET_PARAM_ENC used in * venc_if_set_param() * @input_fourcc: input yuv format - * @h264_profile: V4L2 defined H.264 profile - * @h264_level: V4L2 defined H.264 level + * @profile: V4L2 defined profile + * @level: V4L2 defined level * @width: image width * @height: image height * @buf_width: buffer width @@ -79,8 +79,8 @@ enum venc_set_param_type { */ struct venc_enc_param { enum venc_yuv_fmt input_yuv_fmt; - unsigned int h264_profile; - unsigned int h264_level; + unsigned int profile; + unsigned int level; unsigned int width; unsigned int height; unsigned int buf_width; @@ -107,9 +107,11 @@ struct venc_frame_info { /* * struct venc_frm_buf - frame buffer information used in venc_if_encode() * @fb_addr: plane frame buffer addresses + * @num_planes: number of planes */ struct venc_frm_buf { struct mtk_vcodec_fb fb_addr[MTK_VCODEC_MAX_PLANES]; + unsigned int num_planes; }; /* @@ -124,6 +126,7 @@ struct venc_done_result { extern const struct venc_common_if venc_h264_if; extern const struct venc_common_if venc_vp8_if; +extern const struct venc_common_if venc_if; /* * venc_if_init - Create the driver handle From patchwork Wed May 28 06:36:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 110839 X-Patchwork-Delegate: nicolas@ndufresne.ca Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKAPQ-0005SK-0E for patchwork@linuxtv.org; Wed, 28 May 2025 06:37:19 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 243084A0865 for ; Wed, 28 May 2025 06:37:03 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C8DD124397A; Wed, 28 May 2025 06:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="GWZli/gH" X-Original-To: linux-media@vger.kernel.org Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 668F61C8616; Wed, 28 May 2025 06:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414213; cv=none; b=AfNtHvHEEquuFzUYwfZYr3sBU9//hhyCRS9mq+aiioSS9q3VtpRl7Ax1g3s8YVk0Yqh35SygTLPieikO/54+WC/KVRzAY9KTqu5s8gzZ7KADjI1VCdex8Dncj687D04vDuSOLTbeUGxNbcEicpzR7CkJLHtz6M0+A7ZLSVa51so= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414213; c=relaxed/simple; bh=wGvf+lczpdF4tC5ZslexWPBTCpGNjWb5B5/tw7s3zw0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=taTz9Rmbjn+r9MbmnugoIfK5zNKMSir9Ke4vRsAQ4qGcGCSFQHCZBmbmswqCj2uY8Ydb3E1nCwqCyI8NGQJIfnBN5gtajSlEjrdYiGcHaJOr/bNWzHv2J3cpj+WQctwlq6ZAnE2L9XdQ6nEI2w2hwKJjRumOUwMZ+UlmFEQtKsw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=GWZli/gH; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 1ef564803b8e11f0813e4fe1310efc19-20250528 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=jY1dT6+giYhl1MgZwu+voEOCqO9fC3mI+6aTsCooKTQ=; b=GWZli/gH1vdTmC6lrxoidH7fLErYUSKNpip724MFFmjrZzAdzPz48v0vdAIYBKjCLLlAkG5ovv3Anip/TIQ91p8nrmKIL18MxlyxmwCr+wp1Jdbdzr8XhIbJ5Sse3GJRJmWokyp7gAxShUhtuOFYz1dxZzWCf0uWlQtwVYc8Hjc=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:d6f861b9-694b-4b37-bb04-98b358389abf,IP:0,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-25 X-CID-META: VersionHash:0ef645f,CLOUDID:40675df1-2ded-45ed-94e2-b3e9fa87100d,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1ef564803b8e11f0813e4fe1310efc19-20250528 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 166520434; Wed, 28 May 2025 14:36:43 +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.1258.39; Wed, 28 May 2025 14:36:41 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Wed, 28 May 2025 14:36:41 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , , , CC: , , , , , , Yunfei Dong , Longfei Wang , Irui Wang Subject: [PATCH v2 2/6] media: mediatek: encoder: Add support for common firmware interface Date: Wed, 28 May 2025 14:36:28 +0800 Message-ID: <20250528063633.14054-3-irui.wang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250528063633.14054-1-irui.wang@mediatek.com> References: <20250528063633.14054-1-irui.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no The existing encoder firmware interface implied just one type of codec: H.264. Future encoders may support additional codecs; however adding entire sets of interfaces for them is not scalable. Instead, a new "common" firmware interface is defined for non codec specific messages. The new messages encapsulate the old ones for backward compatibility. This patch adds support for these new messages. Signed-off-by: Irui Wang --- .../vcodec/encoder/mtk_vcodec_enc_drv.h | 3 ++ .../mediatek/vcodec/encoder/venc_drv_if.c | 3 +- .../mediatek/vcodec/encoder/venc_ipi_msg.h | 26 +++++++++++++ .../mediatek/vcodec/encoder/venc_vpu_if.c | 37 ++++++++++++------- 4 files changed, 54 insertions(+), 15 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h index b1277bcfcf53..426b1398f815 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h @@ -16,6 +16,7 @@ #define MTK_ENC_CTX_IS_EXT(ctx) ((ctx)->dev->venc_pdata->uses_ext) #define MTK_ENC_IOVA_IS_34BIT(ctx) ((ctx)->dev->venc_pdata->uses_34bit) +#define MTK_ENC_DRV_IS_COMM(ctx) (((ctx)->dev->venc_pdata->uses_common_fw_iface)) /** * struct mtk_vcodec_enc_pdata - compatible data for each IC @@ -29,6 +30,7 @@ * @num_output_formats: number of entries in output_formats * @core_id: stand for h264 or vp8 encode index * @uses_34bit: whether the encoder uses 34-bit iova + * @uses_common_fw_iface: whether the encoder uses common driver interface */ struct mtk_vcodec_enc_pdata { bool uses_ext; @@ -40,6 +42,7 @@ struct mtk_vcodec_enc_pdata { size_t num_output_formats; u8 core_id; bool uses_34bit; + bool uses_common_fw_iface; }; /* diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c index e83747b8d69a..f8c9349c18c0 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_drv_if.c @@ -19,13 +19,14 @@ int venc_if_init(struct mtk_vcodec_enc_ctx *ctx, unsigned int fourcc) { int ret = 0; + const bool uses_common_fw_iface = MTK_ENC_DRV_IS_COMM(ctx); switch (fourcc) { case V4L2_PIX_FMT_VP8: ctx->enc_if = &venc_vp8_if; break; case V4L2_PIX_FMT_H264: - ctx->enc_if = &venc_h264_if; + ctx->enc_if = uses_common_fw_iface ? &venc_if : &venc_h264_if; break; default: return -EINVAL; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_ipi_msg.h b/drivers/media/platform/mediatek/vcodec/encoder/venc_ipi_msg.h index bb16d96a7f57..ce3c2c8059fb 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_ipi_msg.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_ipi_msg.h @@ -45,6 +45,20 @@ struct venc_ap_ipi_msg_init { uint64_t venc_inst; }; +/** + * struct venc_ap_ipi_msg_init_comm - AP to VPU init cmd structure + * @base: AP to VPU init cmd structure + * @codec_type: encoder type + * @reserved: reserved field + * @shared_iova: shared iova + */ +struct venc_ap_ipi_msg_init_comm { + struct venc_ap_ipi_msg_init base; + u32 codec_type; + u32 reserved; + u64 shared_iova; +}; + /** * struct venc_ap_ipi_msg_set_param - AP to VPU set_param cmd structure * @msg_id: message id (AP_IPIMSG_XXX_ENC_SET_PARAM) @@ -175,6 +189,18 @@ struct venc_vpu_ipi_msg_init { uint32_t venc_abi_version; }; +/** + * struct venc_vpu_ipi_msg_init_comm - VPU ack AP init cmd structure + * @init_ack: AP init cmd structure + * @vpu_vsi_addr: VSI address from VPU + * @reserved: reserved field + */ +struct venc_vpu_ipi_msg_init_comm { + struct venc_vpu_ipi_msg_init init_ack; + u32 vpu_vsi_addr; + u32 reserved; +}; + /** * struct venc_vpu_ipi_msg_set_param - VPU ack AP set_param cmd structure * @msg_id: message id (VPU_IPIMSG_XXX_ENC_SET_PARAM_DONE) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c index 51bb7ee141b9..537b9955932e 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c @@ -10,24 +10,25 @@ static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data) { - const struct venc_vpu_ipi_msg_init *msg = data; + const struct venc_vpu_ipi_msg_init_comm *msg = data; + struct mtk_vcodec_fw *fw = vpu->ctx->dev->fw_handler; - vpu->inst_addr = msg->vpu_inst_addr; - vpu->vsi = mtk_vcodec_fw_map_dm_addr(vpu->ctx->dev->fw_handler, - msg->vpu_inst_addr); + vpu->inst_addr = msg->init_ack.vpu_inst_addr; + vpu->vsi = mtk_vcodec_fw_map_dm_addr(fw, vpu->inst_addr); /* Firmware version field value is unspecified on MT8173. */ - if (mtk_vcodec_fw_get_type(vpu->ctx->dev->fw_handler) == VPU) + if (mtk_vcodec_fw_get_type(fw) == VPU) return; /* Check firmware version. */ - mtk_venc_debug(vpu->ctx, "firmware version: 0x%x\n", msg->venc_abi_version); - switch (msg->venc_abi_version) { + mtk_venc_debug(vpu->ctx, "firmware version: 0x%x\n", + msg->init_ack.venc_abi_version); + switch (msg->init_ack.venc_abi_version) { case 1: break; default: mtk_venc_err(vpu->ctx, "unhandled firmware version 0x%x\n", - msg->venc_abi_version); + msg->init_ack.venc_abi_version); vpu->failure = 1; break; } @@ -132,7 +133,8 @@ static int vpu_enc_send_msg(struct venc_vpu_inst *vpu, void *msg, int vpu_enc_init(struct venc_vpu_inst *vpu) { int status; - struct venc_ap_ipi_msg_init out; + size_t msg_size; + struct venc_ap_ipi_msg_init_comm out; init_waitqueue_head(&vpu->wq_hd); vpu->signaled = 0; @@ -149,9 +151,16 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) } memset(&out, 0, sizeof(out)); - out.msg_id = AP_IPIMSG_ENC_INIT; - out.venc_inst = (unsigned long)vpu; - if (vpu_enc_send_msg(vpu, &out, sizeof(out))) { + out.base.msg_id = AP_IPIMSG_ENC_INIT; + out.base.venc_inst = (unsigned long)vpu; + if (MTK_ENC_DRV_IS_COMM(vpu->ctx)) { + out.codec_type = vpu->ctx->q_data[MTK_Q_DATA_DST].fmt->fourcc; + msg_size = sizeof(struct venc_ap_ipi_msg_init_comm); + } else { + msg_size = sizeof(struct venc_ap_ipi_msg_init); + } + + if (vpu_enc_send_msg(vpu, &out, msg_size)) { mtk_venc_err(vpu->ctx, "AP_IPIMSG_ENC_INIT fail"); return -EINVAL; } @@ -260,7 +269,7 @@ static int vpu_enc_encode_32bits(struct venc_vpu_inst *vpu, sizeof(struct venc_ap_ipi_msg_enc); struct venc_ap_ipi_msg_enc_ext out; - mtk_venc_debug(vpu->ctx, "bs_mode %d ->", bs_mode); + mtk_venc_debug(vpu->ctx, "%s, bs_mode %d ->", __func__, bs_mode); memset(&out, 0, sizeof(out)); out.base.msg_id = AP_IPIMSG_ENC_ENCODE; @@ -305,7 +314,7 @@ static int vpu_enc_encode_34bits(struct venc_vpu_inst *vpu, struct venc_ap_ipi_msg_enc_ext_34 out; size_t msg_size = sizeof(struct venc_ap_ipi_msg_enc_ext_34); - mtk_venc_debug(vpu->ctx, "bs_mode %d ->", bs_mode); + mtk_venc_debug(vpu->ctx, "%s, bs_mode %d ->", __func__, bs_mode); memset(&out, 0, sizeof(out)); out.msg_id = AP_IPIMSG_ENC_ENCODE; From patchwork Wed May 28 06:36:29 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 110836 X-Patchwork-Delegate: nicolas@ndufresne.ca Received: from sv.mirrors.kernel.org ([139.178.88.99]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKAPe-0005Tj-1G for patchwork@linuxtv.org; Wed, 28 May 2025 06:37:19 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id 107E03BDE19 for ; Wed, 28 May 2025 06:36:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 54CFB24467F; Wed, 28 May 2025 06:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="sLOmJioi" X-Original-To: linux-media@vger.kernel.org Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A0289242D95; Wed, 28 May 2025 06:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414214; cv=none; b=ZPuKHWmqypBP6wYb6sBDB/xfvoIVyrP0yJ1pT9KtOsSss5tQkb8UtoKOP+txj4fvQF/mRFhNK+HZfiOiIdFbEpU/O8LYEZvZrxF3r+foX2BX8d9aXcVT+LLF5QZR7NzRaZ3dqBVMwZ57ts2EtTi0MG1fUKTgy9CFiSMA4K1/h8w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414214; c=relaxed/simple; bh=NVtvXaRXtNvHrDorkEB9hhD+GQzYnAGLPyoP+eg3Lo0=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=M+hztVZkZQbUVVna8/0ZEJKmr9OhUXIOdAFYFeUsUSqgPNc0eus0TP4YUrTKtup8vjm3w8r4G8Pa/aDiTvaJT2FUAmZ3jnVYLF6Rb4dofyv1p7hMAqP3OPUebbCIeku0L8xTV3BmHW4Ge6T7daE81Evk/RyWmMAh3wieIHK8xLo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=sLOmJioi; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 1f8986a63b8e11f0813e4fe1310efc19-20250528 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=4+K1kG43cpeUg6Nb8vlFU7e5JfdbWrBV2+LwUCGOPio=; b=sLOmJioiooA2m5T19QUbxyjKB4es9i207sDfvUKMyE9UKeB+JsC8ZiAHykc6CvuFA/LGt9oGe8TVrmifynGQmXA/VQbQKPWpEwqGcYn7w0kcKpIy3xPM2aDJ0fKGkCtHWcJn2MBg6rrSvqrjI3JeP2KIjbV/qZceZ+95RCttvzQ=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:505ce058-130e-4b0f-b454-9ddc710dbe49,IP:0,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-25 X-CID-META: VersionHash:0ef645f,CLOUDID:6a3e0f58-abad-4ac2-9923-3af0a8a9a079,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 1f8986a63b8e11f0813e4fe1310efc19-20250528 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1719294131; Wed, 28 May 2025 14:36:44 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by MTKMBS09N2.mediatek.inc (172.21.101.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Wed, 28 May 2025 14:36:42 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Wed, 28 May 2025 14:36:42 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , , , CC: , , , , , , Yunfei Dong , Longfei Wang , Irui Wang Subject: [PATCH v2 3/6] media: mediatek: encoder: Add support for VCP encode process Date: Wed, 28 May 2025 14:36:29 +0800 Message-ID: <20250528063633.14054-4-irui.wang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250528063633.14054-1-irui.wang@mediatek.com> References: <20250528063633.14054-1-irui.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no When encoding by VCP interface, encoder driver need change to VCP path: Firstly, set encoder driver fw type to 'VCP'. Then, allocate RC buffers by the VCP device. Finally, send the shared memory address into VCP and map the encoder vsi address by the VCP shared memory address. Signed-off-by: Irui Wang --- .../mediatek/vcodec/common/mtk_vcodec_fw.c | 6 +++++ .../mediatek/vcodec/common/mtk_vcodec_fw.h | 1 + .../vcodec/common/mtk_vcodec_fw_priv.h | 1 + .../vcodec/common/mtk_vcodec_fw_vcp.c | 6 +++++ .../vcodec/encoder/mtk_vcodec_enc_drv.c | 3 +++ .../vcodec/encoder/venc/venc_common_if.c | 23 ++++++++++++++----- .../mediatek/vcodec/encoder/venc_vpu_if.c | 14 ++++++++++- 7 files changed, 47 insertions(+), 7 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c index 0381acceda25..7a504f093bd8 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.c @@ -105,3 +105,9 @@ int mtk_vcodec_fw_get_type(struct mtk_vcodec_fw *fw) return fw->type; } EXPORT_SYMBOL_GPL(mtk_vcodec_fw_get_type); + +struct device *mtk_vcodec_fw_get_dev(struct mtk_vcodec_fw *fw) +{ + return fw->ops->get_fw_dev(fw); +} +EXPORT_SYMBOL_GPL(mtk_vcodec_fw_get_dev); diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h index e7304a7dd3e0..56c26b91651e 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw.h @@ -43,5 +43,6 @@ int mtk_vcodec_fw_ipi_send(struct mtk_vcodec_fw *fw, int id, int mtk_vcodec_fw_get_type(struct mtk_vcodec_fw *fw); int mtk_vcodec_fw_get_ipi(enum mtk_vcodec_fw_type type, int hw_id); int mtk_vcodec_fw_get_venc_ipi(enum mtk_vcodec_fw_type type); +struct device *mtk_vcodec_fw_get_dev(struct mtk_vcodec_fw *fw); #endif /* _MTK_VCODEC_FW_H_ */ diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_priv.h b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_priv.h index 0a2a9b010244..710c83c871f4 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_priv.h +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_priv.h @@ -29,6 +29,7 @@ struct mtk_vcodec_fw_ops { int (*ipi_send)(struct mtk_vcodec_fw *fw, int id, void *buf, unsigned int len, unsigned int wait); void (*release)(struct mtk_vcodec_fw *fw); + struct device *(*get_fw_dev)(struct mtk_vcodec_fw *fw); }; #if IS_ENABLED(CONFIG_VIDEO_MEDIATEK_VCODEC_VPU) diff --git a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c index f6b93e1bcbf3..646e3944dd4f 100644 --- a/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c +++ b/drivers/media/platform/mediatek/vcodec/common/mtk_vcodec_fw_vcp.c @@ -432,6 +432,11 @@ static void mtk_vcodec_vcp_release(struct mtk_vcodec_fw *fw) { } +static struct device *mtk_vcodec_vcp_get_fw_dev(struct mtk_vcodec_fw *fw) +{ + return fw->vcp->vcp_device->dev; +} + static const struct mtk_vcodec_fw_ops mtk_vcodec_vcp_msg = { .load_firmware = mtk_vcodec_vcp_load_firmware, .get_vdec_capa = mtk_vcodec_vcp_get_vdec_capa, @@ -440,6 +445,7 @@ static const struct mtk_vcodec_fw_ops mtk_vcodec_vcp_msg = { .ipi_register = mtk_vcodec_vcp_set_ipi_register, .ipi_send = mtk_vcodec_vcp_ipi_send, .release = mtk_vcodec_vcp_release, + .get_fw_dev = mtk_vcodec_vcp_get_fw_dev, }; struct mtk_vcodec_fw *mtk_vcodec_fw_vcp_init(void *priv, enum mtk_vcodec_fw_use fw_use) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c index a1e4483abcdb..bb913dfe5f04 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c @@ -252,6 +252,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,scp", &rproc_phandle)) { fw_type = SCP; + } else if (!of_property_read_u32(pdev->dev.of_node, "mediatek,vcp", + &rproc_phandle)) { + fw_type = VCP; } else { dev_err(&pdev->dev, "[MTK VCODEC] Could not get venc IPI device"); return -ENODEV; diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c index 8092929e9297..61aa7d9d70c9 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc/venc_common_if.c @@ -478,8 +478,13 @@ static void venc_free_rc_buf(struct venc_inst *inst, { int i; struct device *dev; + struct mtk_vcodec_fw *fw = inst->ctx->dev->fw_handler; + + if (mtk_vcodec_fw_get_type(fw) == VCP) + dev = mtk_vcodec_fw_get_dev(fw); + else + dev = &inst->ctx->dev->plat_dev->dev; - dev = &inst->ctx->dev->plat_dev->dev; mtk_venc_mem_free(inst, dev, &bufs->rc_code); for (i = 0; i < core_num; i++) @@ -528,12 +533,18 @@ static int venc_alloc_rc_buf(struct venc_inst *inst, struct device *dev; void *tmp_va; - dev = &inst->ctx->dev->plat_dev->dev; - if (mtk_venc_mem_alloc(inst, dev, &bufs->rc_code)) - return -ENOMEM; + if (mtk_vcodec_fw_get_type(fw) == VCP) { + dev = mtk_vcodec_fw_get_dev(fw); + if (mtk_venc_mem_alloc(inst, dev, &bufs->rc_code)) + return -ENOMEM; + } else { + dev = &inst->ctx->dev->plat_dev->dev; + if (mtk_venc_mem_alloc(inst, dev, &bufs->rc_code)) + return -ENOMEM; - tmp_va = mtk_vcodec_fw_map_dm_addr(fw, bufs->rc_code.pa); - memcpy(bufs->rc_code.va, tmp_va, bufs->rc_code.size); + tmp_va = mtk_vcodec_fw_map_dm_addr(fw, bufs->rc_code.pa); + memcpy(bufs->rc_code.va, tmp_va, bufs->rc_code.size); + } for (i = 0; i < core_num; i++) { if (mtk_venc_mem_alloc(inst, dev, &bufs->rc_info[i])) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c index 537b9955932e..80db7d97ab3f 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/venc_vpu_if.c @@ -8,13 +8,23 @@ #include "venc_ipi_msg.h" #include "venc_vpu_if.h" +#define VSI_OFFSET_MASK 0x0FFFFFFF + static void handle_enc_init_msg(struct venc_vpu_inst *vpu, const void *data) { const struct venc_vpu_ipi_msg_init_comm *msg = data; struct mtk_vcodec_fw *fw = vpu->ctx->dev->fw_handler; + u64 pa_start, vsi_offset; vpu->inst_addr = msg->init_ack.vpu_inst_addr; - vpu->vsi = mtk_vcodec_fw_map_dm_addr(fw, vpu->inst_addr); + + if (mtk_vcodec_fw_get_type(fw) == VCP) { + pa_start = (u64)fw->vcp->iova_addr; + vsi_offset = (msg->vpu_vsi_addr & VSI_OFFSET_MASK) - (pa_start & VSI_OFFSET_MASK); + vpu->vsi = mtk_vcodec_fw_map_dm_addr(fw, ENCODER_MEM) + vsi_offset; + } else { + vpu->vsi = mtk_vcodec_fw_map_dm_addr(fw, vpu->inst_addr); + } /* Firmware version field value is unspecified on MT8173. */ if (mtk_vcodec_fw_get_type(fw) == VPU) @@ -155,6 +165,8 @@ int vpu_enc_init(struct venc_vpu_inst *vpu) out.base.venc_inst = (unsigned long)vpu; if (MTK_ENC_DRV_IS_COMM(vpu->ctx)) { out.codec_type = vpu->ctx->q_data[MTK_Q_DATA_DST].fmt->fourcc; + if (mtk_vcodec_fw_get_type(vpu->ctx->dev->fw_handler) == VCP) + out.shared_iova = vpu->ctx->dev->fw_handler->vcp->iova_addr; msg_size = sizeof(struct venc_ap_ipi_msg_init_comm); } else { msg_size = sizeof(struct venc_ap_ipi_msg_init); From patchwork Wed May 28 06:36:30 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 110851 X-Patchwork-Delegate: nicolas@ndufresne.ca Received: from am.mirrors.kernel.org ([147.75.80.249]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKAQW-0005ac-1K for patchwork@linuxtv.org; Wed, 28 May 2025 06:38:13 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id E0A50189DE57 for ; Wed, 28 May 2025 06:38:20 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C43A02472B5; Wed, 28 May 2025 06:36:57 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="VmiCj6Vt" X-Original-To: linux-media@vger.kernel.org Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 277C824501B; Wed, 28 May 2025 06:36:54 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414217; cv=none; b=q7meci2dkCJXxZDP46VaQLnxyDCiYYvyfRhnfZ0Et0XTXWXyBSm6Yldyd5SYERKYB0yNM2MzY2kdLGh8wumFsP0+gsiD4//ImU38SZV4THb9oLWv+6UOQoCBQNhAS4LJsl8p/E1335MywXzIdVVacsOo3iOynjsSweUnNS9n2rQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414217; c=relaxed/simple; bh=BvNKnEhufd+F6GRiYQaXbKD2MBUFxJFVwSyElw50TkU=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DJlTUobmwWT/OKISvInlD7twimpiUDxUHQvyuuO+Ch6ZGjUFbm8H0cRw3b7T8iXXJP2fqnjg14F25s9VSMPZ0xFCOkVQdP56SDWyOxk25tS0w6u9leQFjPkGR+HaDSM8rT+Amu3NAA8WWdEUnTRzoFi85TItTR6N7J6nqslRPo4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=VmiCj6Vt; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 2036c2b23b8e11f082f7f7ac98dee637-20250528 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=UyydQE6YDeAByew+ptZ/+RplCdDZOgzzk65SMk9HPXE=; b=VmiCj6VtUYb0khZ5J5BZi/TkAXw5aEYKXZbpjWTu71LRXxQD4hj9AqoBMkl82bYGZS1EAF20ajd4GIvlJai6n7922gBiNHoYSdiGSp/Sn7srmZ8x3Q22O9bcgfGLy696oWCXP2lZNez0TjCRRrNNbnN8zb2P8JZRaK9A8vIVjD8=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:98236805-061b-4582-82c8-88799363fb76,IP:0,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-25 X-CID-META: VersionHash:0ef645f,CLOUDID:3d02d047-ee4f-4716-aedb-66601021a588,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 2036c2b23b8e11f082f7f7ac98dee637-20250528 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 976073134; Wed, 28 May 2025 14:36: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.1258.39; Wed, 28 May 2025 14:36:43 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Wed, 28 May 2025 14:36:43 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , , , CC: , , , , , , Yunfei Dong , Longfei Wang , Irui Wang Subject: [PATCH v2 4/6] media: mediatek: encoder: Add a new platform data member Date: Wed, 28 May 2025 14:36:30 +0800 Message-ID: <20250528063633.14054-5-irui.wang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250528063633.14054-1-irui.wang@mediatek.com> References: <20250528063633.14054-1-irui.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no Add a new platform data member to indicate each encoder IC, so that the get chip name function by 'of_device_is_compatible' can be removed. Signed-off-by: Irui Wang --- .../mediatek/vcodec/encoder/mtk_vcodec_enc.c | 23 ++----------------- .../vcodec/encoder/mtk_vcodec_enc_drv.c | 6 +++++ .../vcodec/encoder/mtk_vcodec_enc_drv.h | 2 ++ 3 files changed, 10 insertions(+), 21 deletions(-) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c index 03512bf7a072..1a7be3e57eef 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc.c @@ -198,34 +198,15 @@ static int vidioc_enum_fmt_vid_out(struct file *file, void *priv, pdata->num_output_formats); } -static int mtk_vcodec_enc_get_chip_name(void *priv) -{ - struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv); - struct device *dev = &ctx->dev->plat_dev->dev; - - if (of_device_is_compatible(dev->of_node, "mediatek,mt8173-vcodec-enc")) - return 8173; - else if (of_device_is_compatible(dev->of_node, "mediatek,mt8183-vcodec-enc")) - return 8183; - else if (of_device_is_compatible(dev->of_node, "mediatek,mt8192-vcodec-enc")) - return 8192; - else if (of_device_is_compatible(dev->of_node, "mediatek,mt8195-vcodec-enc")) - return 8195; - else if (of_device_is_compatible(dev->of_node, "mediatek,mt8188-vcodec-enc")) - return 8188; - else - return 8173; -} - static int vidioc_venc_querycap(struct file *file, void *priv, struct v4l2_capability *cap) { struct mtk_vcodec_enc_ctx *ctx = fh_to_enc_ctx(priv); + const struct mtk_vcodec_enc_pdata *pdata = ctx->dev->venc_pdata; struct device *dev = &ctx->dev->plat_dev->dev; - int platform_name = mtk_vcodec_enc_get_chip_name(priv); strscpy(cap->driver, dev->driver->name, sizeof(cap->driver)); - snprintf(cap->card, sizeof(cap->card), "MT%d video encoder", platform_name); + snprintf(cap->card, sizeof(cap->card), "MT%d video encoder", pdata->venc_model_num); return 0; } diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c index bb913dfe5f04..50936949d527 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c @@ -380,6 +380,7 @@ static int mtk_vcodec_probe(struct platform_device *pdev) } static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = { + .venc_model_num = 8173, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_h264), .output_formats = mtk_video_formats_output, @@ -390,6 +391,7 @@ static const struct mtk_vcodec_enc_pdata mt8173_avc_pdata = { }; static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = { + .venc_model_num = 8173, .capture_formats = mtk_video_formats_capture_vp8, .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_vp8), .output_formats = mtk_video_formats_output, @@ -400,6 +402,7 @@ static const struct mtk_vcodec_enc_pdata mt8173_vp8_pdata = { }; static const struct mtk_vcodec_enc_pdata mt8183_pdata = { + .venc_model_num = 8183, .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_h264), @@ -411,6 +414,7 @@ static const struct mtk_vcodec_enc_pdata mt8183_pdata = { }; static const struct mtk_vcodec_enc_pdata mt8188_pdata = { + .venc_model_num = 8188, .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_h264), @@ -423,6 +427,7 @@ static const struct mtk_vcodec_enc_pdata mt8188_pdata = { }; static const struct mtk_vcodec_enc_pdata mt8192_pdata = { + .venc_model_num = 8192, .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_h264), @@ -434,6 +439,7 @@ static const struct mtk_vcodec_enc_pdata mt8192_pdata = { }; static const struct mtk_vcodec_enc_pdata mt8195_pdata = { + .venc_model_num = 8195, .uses_ext = true, .capture_formats = mtk_video_formats_capture_h264, .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_h264), diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h index 426b1398f815..b3206a7b592d 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h @@ -21,6 +21,7 @@ /** * struct mtk_vcodec_enc_pdata - compatible data for each IC * + * @venc_model_num: encoder model number * @uses_ext: whether the encoder uses the extended firmware messaging format * @min_bitrate: minimum supported encoding bitrate * @max_bitrate: maximum supported encoding bitrate @@ -33,6 +34,7 @@ * @uses_common_fw_iface: whether the encoder uses common driver interface */ struct mtk_vcodec_enc_pdata { + u16 venc_model_num; bool uses_ext; u64 min_bitrate; u64 max_bitrate; From patchwork Wed May 28 06:36:31 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 110848 X-Patchwork-Delegate: nicolas@ndufresne.ca Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKAQ7-0005X2-2O for patchwork@linuxtv.org; Wed, 28 May 2025 06:37:48 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 0D6C5162D4F for ; Wed, 28 May 2025 06:37:40 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08A652459F5; Wed, 28 May 2025 06:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="cxiNx2TT" X-Original-To: linux-media@vger.kernel.org Received: from mailgw02.mediatek.com (unknown [210.61.82.184]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 781D1243364; Wed, 28 May 2025 06:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=210.61.82.184 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414215; cv=none; b=TayqK6BfAeCf66QAAGfXNOj5qrRCTPnW/H8blxoX88tpKDs6bBCO1rVs4wG8w1fz2+sb1mD18D0fOxv78WFlAo2SGu3gwrBJSHnoopcLqtjyxoyL/3Z0AbO/cMrB/9z625fA+lt6zZ5p95x8zPjbkHlhXyOGGAC1xekgSmFliMc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414215; c=relaxed/simple; bh=xlwCThLAP2eOGW4RL4vnd1ykVmVFgBc2MN7o0xmVnKw=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=pThsI3MkJEWZf8SXDrKtwvnvR9zKPdmjpqf2hH395tEDY/LbAeCOppkCKx0dYA0IeK2rETtpvdj61kRCFpoz/IaHnF3wqU0M6WHdepai9spDXcpEJATkAf8guK4fv0jijpt9l8o9S89sMenMUpv/2OYaNrGTsb61blv8a3p80JM= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=cxiNx2TT; arc=none smtp.client-ip=210.61.82.184 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 20c8f5ba3b8e11f082f7f7ac98dee637-20250528 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=PPgLQxbZMPX+YEJqn6qREiV9HQdeWS+Rmggk937j+b8=; b=cxiNx2TTv0ehx26NZzPhEdwzA3RFMkcQqtj8YVtdK/kIdkPRsLvyswt+eAWxoViyTAr2QiqnFzSaRTVjNUSQpqp5HAszeWuV9O7NeWbwtKszqo7tn9Wss+XqswjkbnFywwc7rZATZcocJJEbFKos9oyJDs07mHXKwOpVc/zj6W4=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:b83ad55c-0e69-455a-bd2d-fb7fa727888a,IP:0,UR L:0,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION:r elease,TS:0 X-CID-META: VersionHash:0ef645f,CLOUDID:57675df1-2ded-45ed-94e2-b3e9fa87100d,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0 X-CID-BAS: 0,_,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 20c8f5ba3b8e11f082f7f7ac98dee637-20250528 Received: from mtkmbs14n1.mediatek.inc [(172.21.101.75)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 38019597; Wed, 28 May 2025 14:36:46 +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.1258.39; Wed, 28 May 2025 14:36:44 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Wed, 28 May 2025 14:36:44 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , , , CC: , , , , , , Yunfei Dong , Longfei Wang , Irui Wang Subject: [PATCH v2 5/6] dt-bindings: media: mediatek: encoder: Add encoder dt-bindings for MT8196 Date: Wed, 28 May 2025 14:36:31 +0800 Message-ID: <20250528063633.14054-6-irui.wang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250528063633.14054-1-irui.wang@mediatek.com> References: <20250528063633.14054-1-irui.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no Add MT8196 encoder compatible string, which will reference VCP device. Signed-off-by: Irui Wang --- .../bindings/media/mediatek,vcodec-encoder.yaml | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/Documentation/devicetree/bindings/media/mediatek,vcodec-encoder.yaml b/Documentation/devicetree/bindings/media/mediatek,vcodec-encoder.yaml index ebc615584f92..7675391d7eb0 100644 --- a/Documentation/devicetree/bindings/media/mediatek,vcodec-encoder.yaml +++ b/Documentation/devicetree/bindings/media/mediatek,vcodec-encoder.yaml @@ -24,6 +24,7 @@ properties: - mediatek,mt8188-vcodec-enc - mediatek,mt8192-vcodec-enc - mediatek,mt8195-vcodec-enc + - mediatek,mt8196-vcodec-enc - items: - const: mediatek,mt8186-vcodec-enc - const: mediatek,mt8183-vcodec-enc @@ -76,6 +77,17 @@ required: - iommus allOf: + - if: + properties: + compatible: + contains: + enum: + - mediatek,mt8196-vcodec-enc + + then: + required: + - mediatek,vcp + - if: properties: compatible: From patchwork Wed May 28 06:36:32 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Irui Wang X-Patchwork-Id: 110845 X-Patchwork-Delegate: nicolas@ndufresne.ca Received: from ny.mirrors.kernel.org ([147.75.199.223]) by linuxtv.org with esmtps (TLS1.3) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.96) (envelope-from ) id 1uKAQ6-0005Ww-3D for patchwork@linuxtv.org; Wed, 28 May 2025 06:37:47 +0000 Received: from smtp.subspace.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-ECDSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id A725A162A90 for ; Wed, 28 May 2025 06:37:39 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 08E572459F6; Wed, 28 May 2025 06:36:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b="jblcgATn" X-Original-To: linux-media@vger.kernel.org Received: from mailgw01.mediatek.com (unknown [60.244.123.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8046A229B1C; Wed, 28 May 2025 06:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=60.244.123.138 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414215; cv=none; b=ZiLhS4oGqxfarOBTCauYJl0H6briSQiSXhVtdHrdiBqccLrIvQtUkjmTxVccs//SjHcamuDu+erAZx4cexLtuonOoIZ3pdmswLySsKnBXdY5z87sz/O7IWW6yIWrRu7g5kXhqAhDGLCQhh7ZpkPgeBD755iWnhqXGIrdGMXu0jI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1748414215; c=relaxed/simple; bh=35GYQjavQGlJRckCxuoPoAMaWd/SOx57Du1/51RhsPo=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=DoM1yCFH2k+oXAK5m+dEA4i4ZalIsdOu9rmPXNU3D8mmez4YAANTqluWIRnrUnc+KNnpKh/70x7RokXJ6BGLcxpxnz5UFQ6zLUEUKvezzrCGm87/IJTUfUT6NxTwvOzXhNgEEkacf4fp5Zki+GsXaLhpeOttlpbYEsewWy0ga+w= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com; spf=pass smtp.mailfrom=mediatek.com; dkim=pass (1024-bit key) header.d=mediatek.com header.i=@mediatek.com header.b=jblcgATn; arc=none smtp.client-ip=60.244.123.138 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=mediatek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=mediatek.com X-UUID: 2161c5603b8e11f0813e4fe1310efc19-20250528 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=zgl5wOzqoA949rZ3T5Z9iviu+Wk5UKqm1QyNzhdR49U=; b=jblcgATn95RH2pBvpLqnUzYhIyvYeKLj2aPVJVEpBEa89rMkhhXwDhLJMrTAixFA5LuJWwXJ3XypmI5+fun12XiXHB1Msd+C0y9MJtNTGVY3XpFeEbUhY+9aysYR405Hs2mmS4HCluNaHT77I3ZpStOFiw34U1hVepU0hnyHsBk=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.2.1,REQID:9bf694ec-ea87-4c73-b8f7-3d16a76a94d1,IP:0,UR L:0,TC:0,Content:-25,EDM:0,RT:0,SF:0,FILE:0,BULK:0,RULE:Release_Ham,ACTION :release,TS:-25 X-CID-META: VersionHash:0ef645f,CLOUDID:ac5c3259-eac4-4b21-88a4-d582445d304a,B ulkID:nil,BulkQuantity:0,Recheck:0,SF:81|82|102,TC:nil,Content:0|50,EDM:-3 ,IP:nil,URL:0,File:nil,RT:nil,Bulk:nil,QS:nil,BEC:nil,COL:0,OSI:0,OSA:0,AV :0,LES:1,SPR:NO,DKR:0,DKP:0,BRR:0,BRE:0,ARC:0 X-CID-BVR: 0,NGT X-CID-BAS: 0,NGT,0,_ X-CID-FACTOR: TF_CID_SPAM_SNR X-UUID: 2161c5603b8e11f0813e4fe1310efc19-20250528 Received: from mtkmbs13n1.mediatek.inc [(172.21.101.193)] by mailgw01.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 1869768534; Wed, 28 May 2025 14:36:47 +0800 Received: from mtkmbs11n1.mediatek.inc (172.21.101.185) by mtkmbs11n1.mediatek.inc (172.21.101.185) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.39; Wed, 28 May 2025 14:36:45 +0800 Received: from mhfsdcap04.gcn.mediatek.inc (10.17.3.154) by mtkmbs11n1.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.1258.39 via Frontend Transport; Wed, 28 May 2025 14:36:45 +0800 From: Irui Wang To: Hans Verkuil , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Krzysztof Kozlowski , , , CC: , , , , , , Yunfei Dong , Longfei Wang , Irui Wang Subject: [PATCH v2 6/6] media: mediatek: encoder: Add MT8196 encoder compatible data Date: Wed, 28 May 2025 14:36:32 +0800 Message-ID: <20250528063633.14054-7-irui.wang@mediatek.com> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20250528063633.14054-1-irui.wang@mediatek.com> References: <20250528063633.14054-1-irui.wang@mediatek.com> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-MTK: N X-LSpam-Score: -8.6 (--------) X-LSpam-Report: No, score=-8.6 required=5.0 tests=ARC_SIGNED=0.001,ARC_VALID=-0.1,BAYES_00=-1.9,DKIM_SIGNED=0.1,DKIM_VALID=-0.1,DKIM_VALID_AU=-0.1,DMARC_PASS=-0.001,HEADER_FROM_DIFFERENT_DOMAINS=0.5,MAILING_LIST_MULTI=-1,RCVD_IN_DNSWL_MED=-2.3,RCVD_IN_VALIDITY_CERTIFIED=-3,RCVD_IN_VALIDITY_RPBL=1.31,RCVD_IN_VALIDITY_SAFE=-2,SPF_HELO_NONE=0.001,SPF_PASS=-0.001,UNPARSEABLE_RELAY=0.001 autolearn=unavailable autolearn_force=no MT8196 encoder use common firmware interface, add compatible data to support MT8196 encoding, and need set dma mask to support 34bit. Signed-off-by: Irui Wang --- .../vcodec/encoder/mtk_vcodec_enc_drv.c | 19 +++++++++++++++++++ .../vcodec/encoder/mtk_vcodec_enc_drv.h | 2 ++ 2 files changed, 21 insertions(+) diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c index 50936949d527..c869c4245ebc 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.c @@ -20,6 +20,8 @@ #include "mtk_vcodec_enc_pm.h" #include "../common/mtk_vcodec_intr.h" +#define VENC_DMA_BIT_MASK 34 + static const struct mtk_video_fmt mtk_video_formats_output[] = { { .fourcc = V4L2_PIX_FMT_NV12M, @@ -299,6 +301,9 @@ static int mtk_vcodec_probe(struct platform_device *pdev) goto err_res; } + if (dev->venc_pdata->set_dma_bit_mask) + dma_set_mask_and_coherent(&pdev->dev, DMA_BIT_MASK(VENC_DMA_BIT_MASK)); + mutex_init(&dev->enc_mutex); mutex_init(&dev->dev_mutex); mutex_init(&dev->dev_ctx_lock); @@ -450,6 +455,19 @@ static const struct mtk_vcodec_enc_pdata mt8195_pdata = { .core_id = VENC_SYS, }; +static const struct mtk_vcodec_enc_pdata mt8196_pdata = { + .venc_model_num = 8196, + .capture_formats = mtk_video_formats_capture_h264, + .num_capture_formats = ARRAY_SIZE(mtk_video_formats_capture_h264), + .output_formats = mtk_video_formats_output, + .num_output_formats = ARRAY_SIZE(mtk_video_formats_output), + .min_bitrate = 64, + .max_bitrate = 100000000, + .core_id = VENC_SYS, + .uses_common_fw_iface = true, + .set_dma_bit_mask = true, +}; + static const struct of_device_id mtk_vcodec_enc_match[] = { {.compatible = "mediatek,mt8173-vcodec-enc", .data = &mt8173_avc_pdata}, @@ -459,6 +477,7 @@ static const struct of_device_id mtk_vcodec_enc_match[] = { {.compatible = "mediatek,mt8188-vcodec-enc", .data = &mt8188_pdata}, {.compatible = "mediatek,mt8192-vcodec-enc", .data = &mt8192_pdata}, {.compatible = "mediatek,mt8195-vcodec-enc", .data = &mt8195_pdata}, + {.compatible = "mediatek,mt8196-vcodec-enc", .data = &mt8196_pdata}, {}, }; MODULE_DEVICE_TABLE(of, mtk_vcodec_enc_match); diff --git a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h index b3206a7b592d..ded794f1b37a 100644 --- a/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h +++ b/drivers/media/platform/mediatek/vcodec/encoder/mtk_vcodec_enc_drv.h @@ -32,6 +32,7 @@ * @core_id: stand for h264 or vp8 encode index * @uses_34bit: whether the encoder uses 34-bit iova * @uses_common_fw_iface: whether the encoder uses common driver interface + * @set_dma_bit_mask: whether the encoder need set extra DMA bit mask */ struct mtk_vcodec_enc_pdata { u16 venc_model_num; @@ -45,6 +46,7 @@ struct mtk_vcodec_enc_pdata { u8 core_id; bool uses_34bit; bool uses_common_fw_iface; + bool set_dma_bit_mask; }; /*