From nobody Sun Sep 22 13:36:21 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BCC5DC433EF for ; Thu, 13 Jan 2022 04:13:14 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233034AbiAMENM (ORCPT ); Wed, 12 Jan 2022 23:13:12 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:45146 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S232498AbiAMELS (ORCPT ); Wed, 12 Jan 2022 23:11:18 -0500 X-UUID: 2ebd22e1b84b4f9db9d5e0a2146a5fda-20220113 X-UUID: 2ebd22e1b84b4f9db9d5e0a2146a5fda-20220113 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 9974991; Thu, 13 Jan 2022 12:11:14 +0800 Received: from mtkexhb02.mediatek.inc (172.21.101.103) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Thu, 13 Jan 2022 12:11:13 +0800 Received: from mtkcas10.mediatek.inc (172.21.101.39) by mtkexhb02.mediatek.inc (172.21.101.103) with Microsoft SMTP Server (TLS) id 15.0.1497.2; Thu, 13 Jan 2022 12:11:12 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkcas10.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Thu, 13 Jan 2022 12:11:11 +0800 From: Yunfei Dong To: Yunfei Dong , Alexandre Courbot , Hans Verkuil , "Tzung-Bi Shih" , Tiffany Lin , Andrew-CT Chen , Mauro Carvalho Chehab , Rob Herring , Matthias Brugger , Tomasz Figa CC: George Sun , Xiaoyong Lu , Hsin-Yi Wang , Fritz Koenig , Dafna Hirschfeld , Benjamin Gaignard , Daniel Vetter , dri-devel , Irui Wang , AngeloGioacchino Del Regno , Steve Cho , , , , , , , Subject: [PATCH v19, 10/19] media: mtk-vcodec: Add irq interface for multi hardware Date: Thu, 13 Jan 2022 12:10:46 +0800 Message-ID: <20220113041055.25213-11-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220113041055.25213-1-yunfei.dong@mediatek.com> References: <20220113041055.25213-1-yunfei.dong@mediatek.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-MTK: N Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Adds irq interface for multi hardware. Signed-off-by: Yunfei Dong Reviewed-by: AngeloGioacchino Del Regno --- .../platform/mtk-vcodec/mtk_vcodec_dec_drv.c | 33 ++++++++++++++++--- .../platform/mtk-vcodec/mtk_vcodec_dec_hw.c | 2 +- .../platform/mtk-vcodec/mtk_vcodec_drv.h | 25 ++++++++++---- .../platform/mtk-vcodec/mtk_vcodec_enc_drv.c | 4 +-- .../platform/mtk-vcodec/mtk_vcodec_intr.c | 30 ++++++++--------- .../platform/mtk-vcodec/mtk_vcodec_intr.h | 5 +-- .../platform/mtk-vcodec/vdec/vdec_h264_if.c | 2 +- .../mtk-vcodec/vdec/vdec_h264_req_if.c | 2 +- .../platform/mtk-vcodec/vdec/vdec_vp8_if.c | 2 +- .../platform/mtk-vcodec/vdec/vdec_vp9_if.c | 2 +- .../platform/mtk-vcodec/venc/venc_h264_if.c | 2 +- .../platform/mtk-vcodec/venc/venc_vp8_if.c | 2 +- 12 files changed, 72 insertions(+), 39 deletions(-) diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c index 7e2c9c381dd2..40d1f16a0a25 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -24,6 +24,19 @@ #include "mtk_vcodec_util.h" #include "mtk_vcodec_fw.h" =20 +static int mtk_vcodec_get_hw_count(struct mtk_vcodec_dev *dev) +{ + switch (dev->vdec_pdata->hw_arch) { + case MTK_VDEC_PURE_SINGLE_CORE: + return MTK_VDEC_ONE_CORE; + case MTK_VDEC_LAT_SINGLE_CORE: + return MTK_VDEC_ONE_LAT_ONE_CORE; + default: + mtk_v4l2_err("hw arch %d not supported", dev->vdec_pdata->hw_arch); + return MTK_VDEC_NO_HW; + } +} + static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, void *priv) { struct mtk_vcodec_dev *dev =3D priv; @@ -55,7 +68,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, vo= id *priv) writel((readl(vdec_misc_addr) & ~VDEC_IRQ_CLR), dev->reg_base[VDEC_MISC] + VDEC_IRQ_CFG_REG); =20 - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED); + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); =20 mtk_v4l2_debug(3, "mtk_vcodec_dec_irq_handler :wake up ctx %d, dec_done_status=3D%x", @@ -128,7 +141,7 @@ static int fops_vcodec_open(struct file *file) { struct mtk_vcodec_dev *dev =3D video_drvdata(file); struct mtk_vcodec_ctx *ctx =3D NULL; - int ret =3D 0; + int ret =3D 0, i, hw_count; struct vb2_queue *src_vq; =20 ctx =3D kzalloc(sizeof(*ctx), GFP_KERNEL); @@ -142,14 +155,24 @@ static int fops_vcodec_open(struct file *file) v4l2_fh_add(&ctx->fh); INIT_LIST_HEAD(&ctx->list); ctx->dev =3D dev; - init_waitqueue_head(&ctx->queue); - mutex_init(&ctx->lock); + if (ctx->dev->vdec_pdata->is_subdev_supported) { + hw_count =3D mtk_vcodec_get_hw_count(dev); + if (!hw_count || !dev->subdev_prob_done) { + ret =3D -EINVAL; + goto err_ctrls_setup; + } =20 - if (dev->vdec_pdata->is_subdev_supported && dev->subdev_prob_done) { ret =3D dev->subdev_prob_done(dev); if (ret) goto err_ctrls_setup; + + for (i =3D 0; i < hw_count; i++) + init_waitqueue_head(&ctx->queue[i]); + } else { + init_waitqueue_head(&ctx->queue[0]); } + mutex_init(&ctx->lock); + ctx->type =3D MTK_INST_DECODER; ret =3D dev->vdec_pdata->ctrls_setup(ctx); if (ret) { diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c b/driver= s/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c index cde9442e7ce6..6b248dd94dd3 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c @@ -84,7 +84,7 @@ static irqreturn_t mtk_vdec_hw_irq_handler(int irq, void = *priv) writel(dec_done_status | VDEC_IRQ_CFG, vdec_misc_addr); writel(dec_done_status & ~VDEC_IRQ_CLR, vdec_misc_addr); =20 - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED); + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, dev->hw_idx); =20 mtk_v4l2_debug(3, "wake up ctx %d, dec_done_status=3D%x", ctx->id, dec_done_status); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h b/drivers/m= edia/platform/mtk-vcodec/mtk_vcodec_drv.h index 17e7deee10b5..9667310cb55a 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_drv.h @@ -104,6 +104,16 @@ enum mtk_vdec_hw_id { MTK_VDEC_HW_MAX, }; =20 +/* + * enum mtk_vdec_hw_count - Supported hardware count + */ +enum mtk_vdec_hw_count { + MTK_VDEC_NO_HW =3D 0, + MTK_VDEC_ONE_CORE, + MTK_VDEC_ONE_LAT_ONE_CORE, + MTK_VDEC_MAX_HW_COUNT, +}; + /* * struct mtk_video_fmt - Structure used to store information about pixelf= ormats */ @@ -293,9 +303,9 @@ struct mtk_vcodec_ctx { struct vdec_pic_info picinfo; int dpb_size; =20 - int int_cond; - int int_type; - wait_queue_head_t queue; + int int_cond[MTK_VDEC_HW_MAX]; + int int_type[MTK_VDEC_HW_MAX]; + wait_queue_head_t queue[MTK_VDEC_HW_MAX]; unsigned int irq_status; =20 struct v4l2_ctrl_handler ctrl_hdl; @@ -504,11 +514,12 @@ static inline struct mtk_vcodec_ctx *ctrl_to_ctx(stru= ct v4l2_ctrl *ctrl) } =20 /* Wake up context wait_queue */ -static inline void wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int re= ason) +static inline void +wake_up_ctx(struct mtk_vcodec_ctx *ctx, unsigned int reason, unsigned int = hw_id) { - ctx->int_cond =3D 1; - ctx->int_type =3D reason; - wake_up_interruptible(&ctx->queue); + ctx->int_cond[hw_id] =3D 1; + ctx->int_type[hw_id] =3D reason; + wake_up_interruptible(&ctx->queue[hw_id]); } =20 #endif /* _MTK_VCODEC_DRV_H_ */ diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c b/drive= rs/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c index 027546108f44..347f0d87e2ff 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -103,7 +103,7 @@ static irqreturn_t mtk_vcodec_enc_irq_handler(int irq, = void *priv) =20 clean_irq_status(ctx->irq_status, addr); =20 - wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED); + wake_up_ctx(ctx, MTK_INST_IRQ_RECEIVED, 0); return IRQ_HANDLED; } =20 @@ -129,7 +129,7 @@ static int fops_vcodec_open(struct file *file) v4l2_fh_add(&ctx->fh); INIT_LIST_HEAD(&ctx->list); ctx->dev =3D dev; - init_waitqueue_head(&ctx->queue); + init_waitqueue_head(&ctx->queue[0]); =20 ctx->type =3D MTK_INST_ENCODER; ret =3D mtk_vcodec_enc_ctrls_setup(ctx); diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_intr.c index 70580c2525ba..552b4c93d972 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c @@ -11,34 +11,32 @@ #include "mtk_vcodec_intr.h" #include "mtk_vcodec_util.h" =20 -int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, int command, - unsigned int timeout_ms) +int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, + int command, unsigned int timeout_ms, + unsigned int hw_id) { - wait_queue_head_t *waitqueue; long timeout_jiff, ret; int status =3D 0; =20 - waitqueue =3D (wait_queue_head_t *)&ctx->queue; timeout_jiff =3D msecs_to_jiffies(timeout_ms); - - ret =3D wait_event_interruptible_timeout(*waitqueue, - ctx->int_cond, - timeout_jiff); + ret =3D wait_event_interruptible_timeout(ctx->queue[hw_id], + ctx->int_cond[hw_id], + timeout_jiff); =20 if (!ret) { status =3D -1; /* timeout */ - mtk_v4l2_err("[%d] ctx->type=3D%d, cmd=3D%d, wait_event_interruptible_ti= meout time=3D%ums out %d %d!", - ctx->id, ctx->type, command, timeout_ms, - ctx->int_cond, ctx->int_type); + mtk_v4l2_err("[%d] cmd=3D%d, type=3D%d, dec timeout=3D%ums (%d %d)", + ctx->id, command, ctx->type, timeout_ms, + ctx->int_cond[hw_id], ctx->int_type[hw_id]); } else if (-ERESTARTSYS =3D=3D ret) { - mtk_v4l2_err("[%d] ctx->type=3D%d, cmd=3D%d, wait_event_interruptible_ti= meout interrupted by a signal %d %d", - ctx->id, ctx->type, command, ctx->int_cond, - ctx->int_type); status =3D -1; + mtk_v4l2_err("[%d] cmd=3D%d, type=3D%d, dec inter fail (%d %d)", + ctx->id, command, ctx->type, + ctx->int_cond[hw_id], ctx->int_type[hw_id]); } =20 - ctx->int_cond =3D 0; - ctx->int_type =3D 0; + ctx->int_cond[hw_id] =3D 0; + ctx->int_type[hw_id] =3D 0; =20 return status; } diff --git a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h b/drivers/= media/platform/mtk-vcodec/mtk_vcodec_intr.h index 638cd1f3526a..9681f492813b 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h @@ -12,7 +12,8 @@ struct mtk_vcodec_ctx; =20 /* timeout is ms */ -int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *data, int command, - unsigned int timeout_ms); +int mtk_vcodec_wait_for_done_ctx(struct mtk_vcodec_ctx *ctx, + int command, unsigned int timeout_ms, + unsigned int hw_id); =20 #endif /* _MTK_VCODEC_INTR_H_ */ diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c b/driver= s/media/platform/mtk-vcodec/vdec/vdec_h264_if.c index 40d6e6c5ac7a..481655bb6016 100644 --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_if.c @@ -413,7 +413,7 @@ static int vdec_h264_decode(void *h_vdec, struct mtk_vc= odec_mem *bs, /* wait decoder done interrupt */ err =3D mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS); + WAIT_INTR_TIMEOUT_MS, 0); if (err) goto err_free_fb_out; =20 diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c b/dr= ivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c index fada4d146703..43542de11e9c 100644 --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_h264_req_if.c @@ -727,7 +727,7 @@ static int vdec_h264_slice_decode(void *h_vdec, struct = mtk_vcodec_mem *bs, /* wait decoder done interrupt */ err =3D mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS); + WAIT_INTR_TIMEOUT_MS, 0); if (err) goto err_free_fb_out; vpu_dec_end(vpu); diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c b/drivers= /media/platform/mtk-vcodec/vdec/vdec_vp8_if.c index e5393f841080..88c046731754 100644 --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp8_if.c @@ -488,7 +488,7 @@ static int vdec_vp8_decode(void *h_vdec, struct mtk_vco= dec_mem *bs, =20 /* wait decoder done interrupt */ mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS); + WAIT_INTR_TIMEOUT_MS, 0); =20 if (inst->vsi->load_data) load_dec_table(inst); diff --git a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c b/drivers= /media/platform/mtk-vcodec/vdec/vdec_vp9_if.c index 71cdc3ddafcb..70b8383f7c8e 100644 --- a/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c +++ b/drivers/media/platform/mtk-vcodec/vdec/vdec_vp9_if.c @@ -539,7 +539,7 @@ static bool vp9_wait_dec_end(struct vdec_vp9_inst *inst) =20 mtk_vcodec_wait_for_done_ctx(inst->ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS); + WAIT_INTR_TIMEOUT_MS, 0); =20 if (ctx->irq_status & MTK_VDEC_IRQ_STATUS_DEC_SUCCESS) return true; diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c b/driver= s/media/platform/mtk-vcodec/venc/venc_h264_if.c index bf03888a824f..4d9b8798dffe 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_h264_if.c @@ -335,7 +335,7 @@ static unsigned int h264_enc_wait_venc_done(struct venc= _h264_inst *inst) struct mtk_vcodec_ctx *ctx =3D (struct mtk_vcodec_ctx *)inst->ctx; =20 if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS)) { + WAIT_INTR_TIMEOUT_MS, 0)) { irq_status =3D ctx->irq_status; mtk_vcodec_debug(inst, "irq_status %x <-", irq_status); } diff --git a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c b/drivers= /media/platform/mtk-vcodec/venc/venc_vp8_if.c index 6b66957d5192..56ce58f761f1 100644 --- a/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c +++ b/drivers/media/platform/mtk-vcodec/venc/venc_vp8_if.c @@ -222,7 +222,7 @@ static unsigned int vp8_enc_wait_venc_done(struct venc_= vp8_inst *inst) struct mtk_vcodec_ctx *ctx =3D (struct mtk_vcodec_ctx *)inst->ctx; =20 if (!mtk_vcodec_wait_for_done_ctx(ctx, MTK_INST_IRQ_RECEIVED, - WAIT_INTR_TIMEOUT_MS)) { + WAIT_INTR_TIMEOUT_MS, 0)) { irq_status =3D ctx->irq_status; mtk_vcodec_debug(inst, "isr return %x", irq_status); } --=20 2.25.1