From nobody Sun Sep 22 15:22:04 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id C20C3C433F5 for ; Tue, 9 Nov 2021 12:51:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9F3C0610E9 for ; Tue, 9 Nov 2021 12:51:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1343943AbhKIMyZ (ORCPT ); Tue, 9 Nov 2021 07:54:25 -0500 Received: from mailgw02.mediatek.com ([210.61.82.184]:57174 "EHLO mailgw02.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1343696AbhKIMxg (ORCPT ); Tue, 9 Nov 2021 07:53:36 -0500 X-UUID: c9e7cdeda1934162a2febad72c52b816-20211109 X-UUID: c9e7cdeda1934162a2febad72c52b816-20211109 Received: from mtkmbs10n2.mediatek.inc [(172.21.101.183)] by mailgw02.mediatek.com (envelope-from ) (Generic MTA with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 799680164; Tue, 09 Nov 2021 20:50:45 +0800 Received: from mtkmbs10n2.mediatek.inc (172.21.101.183) by mtkmbs10n2.mediatek.inc (172.21.101.183) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.792.3; Tue, 9 Nov 2021 20:50:44 +0800 Received: from localhost.localdomain (10.17.3.154) by mtkmbs10n2.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.2.792.3 via Frontend Transport; Tue, 9 Nov 2021 20:50:43 +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: Hsin-Yi Wang , Fritz Koenig , Dafna Hirschfeld , Benjamin Gaignard , Daniel Vetter , dri-devel , Irui Wang , , , , , , , Subject: [PATCH v9, 09/19] media: mtk-vcodec: Add irq interface for multi hardware Date: Tue, 9 Nov 2021 20:50:20 +0800 Message-ID: <20211109125030.26299-10-yunfei.dong@mediatek.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211109125030.26299-1-yunfei.dong@mediatek.com> References: <20211109125030.26299-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 --- .../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 | 27 +++++++-------- .../platform/mtk-vcodec/mtk_vcodec_intr.h | 4 +-- .../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, 71 insertions(+), 36 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 eb2af42aa102..c1d08a2ac418 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_drv.c @@ -61,6 +61,20 @@ static int mtk_vcodec_subdev_device_check(struct mtk_vco= dec_ctx *ctx) return 0; } =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("not support hw arch:%d", + 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; @@ -92,7 +106,7 @@ static irqreturn_t mtk_vcodec_dec_irq_handler(int irq, v= oid *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", @@ -164,7 +178,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); @@ -178,7 +192,19 @@ 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); +=09 + if (ctx->dev->vdec_pdata->is_subdev_supported) { + hw_count =3D mtk_vcodec_get_hw_count(dev); + if (!hw_count) { + ret =3D -EINVAL; + goto err_init_queue; + } + for (i =3D 0; i < hw_count; i++) + init_waitqueue_head(&ctx->queue[i]); + } else { + init_waitqueue_head(&ctx->queue[0]); + } +=09 mutex_init(&ctx->lock); =20 ret =3D mtk_vcodec_subdev_device_check(ctx); @@ -241,6 +267,7 @@ static int fops_vcodec_open(struct file *file) err_m2m_ctx_init: v4l2_ctrl_handler_free(&ctx->ctrl_hdl); err_ctrls_setup: +err_init_queue: v4l2_fh_del(&ctx->fh); v4l2_fh_exit(&ctx->fh); kfree(ctx); 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 745be12548ef..615953b5b19a 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_dec_hw.c @@ -61,7 +61,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 d19d0893fe63..9b6ab592344f 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 +/** + * struct 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; @@ -506,11 +516,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 re= ason, + 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 7c3487fb3498..0f326d82dea0 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_enc_drv.c @@ -106,7 +106,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 @@ -132,7 +132,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..8147533da98b 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.c @@ -11,34 +11,31 @@ #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 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, + 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..2bf4cabfaa43 100644 --- a/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h +++ b/drivers/media/platform/mtk-vcodec/mtk_vcodec_intr.h @@ -12,7 +12,7 @@ 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 946c23088308..d402fc4bda69 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 b6a4f2074fa5..9ae1bd8dbc32 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 8267a9c4fd25..f96564277577 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