From mboxrd@z Thu Jan 1 00:00:00 1970 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id AE53DC433EF for ; Mon, 25 Jul 2022 02:19:35 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Date:CC:To:From:Subject:Message-ID:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=F8c9IFVQ6h00r9OHr6vn0WNqSamRinsGf4ppHh0SJXY=; b=pdLpOW9QWpuQqK h1Bq6Os9BV918hfs4JGXW5fw9UeDUBTK18Gx/lj2XOYlMW7h1P5KE8dU9MGoL1E51SfB1zQQrlCLQ F3g8c8bqbIukzQ03i/29rrLRCxLrCenohKv+wmCfta5coEl9/md67bikVmn+VAdugwmTzEtRlcQnw jJh9BGrCJB3JO9BPl6dCDhTN1k6wkhheMKxtA+g2Tmw6yyQE7xmxyfS/irleHNSpjCbCF2w31An4m 3heuQs4INnacQnE0sNWNrSrph6q4JdyH26YzF+gb7t0QFRx2LY9yHalO0bkGWaiJJB0Ptdh+FHykS TDGqwoi73yrOo/YxLehQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFnfg-000lFT-S6; Mon, 25 Jul 2022 02:18:12 +0000 Received: from mailgw02.mediatek.com ([216.200.240.185]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oFnfc-000lAT-EY; Mon, 25 Jul 2022 02:18:10 +0000 X-UUID: c04d4dd6d06f4cb08823d5b5e53d48d4-20220724 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=mediatek.com; s=dk; h=Content-Transfer-Encoding:MIME-Version:Content-Type:References:In-Reply-To:Date:CC:To:From:Subject:Message-ID; bh=zZBJIlTXd9y8GL8SPh9h37vKY8MGc/FlEf8v1hT0I0A=; b=GSVjPut2+xfcvdUMkaa14GxIf923Er1CQJi96e8UadoUGn2Y0iOuAjZoVQugS3g0S+yiz6+iaj5JtUuE+FWX0OtqSLoIwoNOVawH/AoTdTxKRZelmM/xGFaRA65fFi7zaYYRdMrabFHCf35v7KMS+Do62P7io5BI8obyYflijko=; X-CID-P-RULE: Release_Ham X-CID-O-INFO: VERSION:1.1.8,REQID:ee44f82b-4ecb-4ddf-9b0c-8c29f4495442,OB:0,LO B:0,IP:0,URL:5,TC:0,Content:0,EDM:0,RT:0,SF:0,FILE:0,RULE:Release_Ham,ACTI ON:release,TS:5 X-CID-META: VersionHash:0f94e32,CLOUDID:8004b429-fd69-41f1-91fc-8b8a329d3a88,C OID:IGNORED,Recheck:0,SF:nil,TC:nil,Content:0,EDM:-3,IP:nil,URL:1,File:nil ,QS:nil,BEC:nil,COL:0 X-UUID: c04d4dd6d06f4cb08823d5b5e53d48d4-20220724 Received: from mtkmbs11n2.mediatek.inc [(172.21.101.187)] by mailgw02.mediatek.com (envelope-from ) (musrelay.mediatek.com ESMTP with TLSv1.2 ECDHE-RSA-AES256-GCM-SHA384 256/256) with ESMTP id 13595406; Sun, 24 Jul 2022 19:18:02 -0700 Received: from mtkcas11.mediatek.inc (172.21.101.40) by mtkmbs10n1.mediatek.inc (172.21.101.34) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384) id 15.2.792.15; Mon, 25 Jul 2022 10:17:27 +0800 Received: from mhfsdcap04 (10.17.3.154) by mtkcas11.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1497.2 via Frontend Transport; Mon, 25 Jul 2022 10:17:26 +0800 Message-ID: <1a5855af8d4f59c7f2ebd3cd779d38a77a5b324b.camel@mediatek.com> Subject: Re: [V5,5/8] media: mtk-jpegdec: add jpeg decode worker interface From: kyrie.wu To: AngeloGioacchino Del Regno , "Irui Wang" , Hans Verkuil , "Mauro Carvalho Chehab" , Rob Herring , Matthias Brugger , Tzung-Bi Shih , , CC: , , , , , , Tomasz Figa , , , Date: Mon, 25 Jul 2022 10:17:26 +0800 In-Reply-To: <499968a2-fbc6-230d-2ed4-cac2b9a98a17@collabora.com> References: <20220716093408.29734-1-irui.wang@mediatek.com> <20220716093408.29734-6-irui.wang@mediatek.com> <499968a2-fbc6-230d-2ed4-cac2b9a98a17@collabora.com> X-Mailer: Evolution 3.28.5-0ubuntu0.18.04.2 MIME-Version: 1.0 X-MTK: N X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220724_191808_520574_ACD1B50F X-CRM114-Status: GOOD ( 26.54 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, 2022-07-18 at 12:33 +0200, AngeloGioacchino Del Regno wrote: > Il 16/07/22 11:34, Irui Wang ha scritto: > > From: kyrie wu > > > > Add jpeg decoding worker to ensure that three HWs > > run in parallel in MT8195. > > > > Signed-off-by: kyrie wu > > Signed-off-by: irui wang > > > > --- > > .../platform/mediatek/jpeg/mtk_jpeg_core.c | 172 > > ++++++++++++++++++ > > .../platform/mediatek/jpeg/mtk_jpeg_core.h | 6 + > > .../platform/mediatek/jpeg/mtk_jpeg_dec_hw.c | 39 ++-- > > 3 files changed, 205 insertions(+), 12 deletions(-) > > > > diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > > b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > > index a9e8be976bb0..65b963ba0d6f 100644 > > --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > > +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.c > > @@ -1100,8 +1100,177 @@ static void > > mtk_jpeg_multicore_enc_device_run(void *priv) > > queue_work(jpeg->workqueue, &ctx->jpeg_work); > > } > > > > +static int mtk_jpegdec_get_hw(struct mtk_jpeg_ctx *ctx) > > +{ > > + struct mtk_jpegdec_comp_dev *comp_jpeg; > > + struct mtk_jpeg_dev *jpeg = ctx->jpeg; > > + unsigned long flags; > > + int hw_id = -1; > > + int i; > > + > > + spin_lock_irqsave(&jpeg->hw_lock, flags); > > + for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++) { > > + comp_jpeg = jpeg->dec_hw_dev[i]; > > + if (comp_jpeg->hw_state == MTK_JPEG_HW_IDLE) { > > + hw_id = i; > > + comp_jpeg->hw_state = MTK_JPEG_HW_BUSY; > > + break; > > + } > > + } > > + spin_unlock_irqrestore(&jpeg->hw_lock, flags); > > + > > + return hw_id; > > +} > > + > > +static int mtk_jpegdec_put_hw(struct mtk_jpeg_dev *jpeg, int > > hw_id) > > +{ > > + unsigned long flags; > > + > > + spin_lock_irqsave(&jpeg->hw_lock, flags); > > + jpeg->dec_hw_dev[hw_id]->hw_state = > > + MTK_JPEG_HW_IDLE; > > + spin_unlock_irqrestore(&jpeg->hw_lock, flags); > > + > > + return 0; > > +} > > + > > +static int mtk_jpegdec_set_hw_param(struct mtk_jpeg_ctx *ctx, > > + int hw_id, > > + struct vb2_v4l2_buffer *src_buf, > > + struct vb2_v4l2_buffer *dst_buf) > > +{ > > + struct mtk_jpegdec_comp_dev *jpeg = > > + ctx->jpeg->dec_hw_dev[hw_id]; > > + > > + jpeg->hw_param.curr_ctx = ctx; > > + jpeg->hw_param.src_buffer = src_buf; > > + jpeg->hw_param.dst_buffer = dst_buf; > > + > > + return 0; > > +} > > + > > +static void mtk_jpegdec_worker(struct work_struct *work) > > +{ > > + struct mtk_jpeg_ctx *ctx = container_of(work, struct > > mtk_jpeg_ctx, > > + jpeg_work); > > + struct mtk_jpegdec_comp_dev *comp_jpeg[MTK_JPEGDEC_HW_MAX]; > > + enum vb2_buffer_state buf_state = VB2_BUF_STATE_ERROR; > > + struct mtk_jpeg_src_buf *jpeg_src_buf, *jpeg_dst_buf; > > + struct vb2_v4l2_buffer *src_buf, *dst_buf; > > + struct mtk_jpeg_dev *jpeg = ctx->jpeg; > > + int ret, i, hw_id = 0; > > + struct mtk_jpeg_bs bs; > > + struct mtk_jpeg_fb fb; > > + unsigned long flags; > > + > > + for (i = 0; i < MTK_JPEGDEC_HW_MAX; i++) > > + comp_jpeg[i] = jpeg->dec_hw_dev[i]; > > + > > +retry_select: > > Please ensure that we have a max retries limit to avoid an infinite > loop. Your suggestion looks more reasonable. I will fix it. Thanks. > > > + hw_id = mtk_jpegdec_get_hw(ctx); > > + if (hw_id < 0) { > > + ret = wait_event_interruptible_timeout(jpeg->dec_hw_wq, > > + atomic_read(&jpe > > g->dechw_rdy) > 0, > > + MTK_JPEG_HW_TIME > > OUT_MSEC); > > + if (ret != 0) { > > + dev_err(jpeg->dev, "%s : %d, all HW are > > busy\n", > > + __func__, __LINE__); > > + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx- > > >fh.m2m_ctx); > > + return; > > + } > > + > + goto retry_select; > > + } > > + > > + atomic_dec(&jpeg->dechw_rdy); > > + src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx); > > + if (!src_buf) > > + goto getbuf_fail; > > + > > + dst_buf = v4l2_m2m_next_dst_buf(ctx->fh.m2m_ctx); > > + if (!dst_buf) > > + goto getbuf_fail; > > + > > + v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); > > + v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); > > + > > + v4l2_m2m_buf_copy_metadata(src_buf, dst_buf, true); > > + jpeg_src_buf = mtk_jpeg_vb2_to_srcbuf(&src_buf->vb2_buf); > > + jpeg_dst_buf = mtk_jpeg_vb2_to_srcbuf(&dst_buf->vb2_buf); > > + > > + if (mtk_jpeg_check_resolution_change(ctx, > > + &jpeg_src_buf->dec_param)) > > { > > + mtk_jpeg_queue_src_chg_event(ctx); > > + ctx->state = MTK_JPEG_SOURCE_CHANGE; > > + goto dec_end; > > + } > > + > > + jpeg_src_buf->curr_ctx = ctx; > > + jpeg_src_buf->frame_num = ctx->total_frame_num; > > + jpeg_dst_buf->curr_ctx = ctx; > > + jpeg_dst_buf->frame_num = ctx->total_frame_num; > > + ctx->total_frame_num++; > > + > > + mtk_jpegdec_set_hw_param(ctx, hw_id, src_buf, dst_buf); > > + ret = pm_runtime_get_sync(comp_jpeg[hw_id]->dev); > > + if (ret < 0) { > > + dev_err(jpeg->dev, "%s : %d, pm_runtime_get_sync fail > > !!!\n", > > + __func__, __LINE__); > > + goto dec_end; > > + } > > + > > + ret = clk_prepare_enable(comp_jpeg[hw_id]->jdec_clk.clks->clk); > > + if (ret) { > > + dev_err(jpeg->dev, "%s : %d, jpegdec clk_prepare_enable > > fail\n", > > + __func__, __LINE__); > > + goto clk_end; > > + } > > + > > + schedule_delayed_work(&comp_jpeg[hw_id]->job_timeout_work, > > + msecs_to_jiffies(MTK_JPEG_HW_TIMEOUT_MSEC > > )); > > + > > + mtk_jpeg_set_dec_src(ctx, &src_buf->vb2_buf, &bs); > > + if (mtk_jpeg_set_dec_dst(ctx, > > + &jpeg_src_buf->dec_param, > > + &dst_buf->vb2_buf, &fb)) { > > + dev_err(jpeg->dev, "%s : %d, mtk_jpeg_set_dec_dst > > fail\n", > > + __func__, __LINE__); > > + goto setdst_end; > > + } > > + > > + spin_lock_irqsave(&comp_jpeg[hw_id]->hw_lock, flags); > > + mtk_jpeg_dec_reset(comp_jpeg[hw_id]->reg_base); > > + mtk_jpeg_dec_set_config(jpeg->reg_base, > > + &jpeg_src_buf->dec_param, > > + &bs, > > + &fb); > > + mtk_jpeg_dec_start(comp_jpeg[hw_id]->reg_base); > > + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); > > + spin_unlock_irqrestore(&comp_jpeg[hw_id]->hw_lock, flags); > > + > > + return; > > + > > +setdst_end: > > + clk_disable_unprepare(comp_jpeg[hw_id]->jdec_clk.clks->clk); > > +clk_end: > > + pm_runtime_put(comp_jpeg[hw_id]->dev); > > +dec_end: > > + v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx); > > + v4l2_m2m_dst_buf_remove(ctx->fh.m2m_ctx); > > + v4l2_m2m_buf_done(src_buf, buf_state); > > + v4l2_m2m_buf_done(dst_buf, buf_state); > > +getbuf_fail: > > + atomic_inc(&jpeg->dechw_rdy); > > + mtk_jpegdec_put_hw(jpeg, hw_id); > > + v4l2_m2m_job_finish(jpeg->m2m_dev, ctx->fh.m2m_ctx); > > +} > > + > > static void mtk_jpeg_multicore_dec_device_run(void *priv) > > { > > + struct mtk_jpeg_ctx *ctx = priv; > > + struct mtk_jpeg_dev *jpeg = ctx->jpeg; > > + > > + queue_work(jpeg->workqueue, &ctx->jpeg_work); > > > In the previous commit, I asked why this function was empty: I see > you're > filling it in right now, so please add the MT8195 compatibles after > this > commit, or later. OK, thanks a lot. > > > } > > > > static void mtk_jpeg_dec_device_run(void *priv) > > @@ -1377,6 +1546,9 @@ static int mtk_jpeg_open(struct file *file) > > if (jpeg->is_jpgenc_multihw) > > INIT_WORK(&ctx->jpeg_work, mtk_jpegenc_worker); > > > > + if (jpeg->is_jpgdec_multihw) > > + INIT_WORK(&ctx->jpeg_work, mtk_jpegdec_worker); > > + > > INIT_LIST_HEAD(&ctx->dst_done_queue); > > spin_lock_init(&ctx->done_queue_lock); > > v4l2_fh_init(&ctx->fh, vfd); > > diff --git a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h > > b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h > > index ddfe2b4c48b3..ef9a3e1fdf60 100644 > > --- a/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h > > +++ b/drivers/media/platform/mediatek/jpeg/mtk_jpeg_core.h > > @@ -171,6 +171,9 @@ struct mtk_jpegdec_comp_dev { > > int jpegdec_irq; > > struct delayed_work job_timeout_work; > > struct mtk_jpeg_hw_param hw_param; > > + enum mtk_jpeg_hw_state hw_state; > > + //spinlock protecting the hw device resource > > C-style comments please. > > > + spinlock_t hw_lock; > > }; > > > > /** > > Regards, > Angelo > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel