media: mediatek: vcodec: Use ctx vb2_queue mutex instead of device mutex
authorIrui Wang <irui.wang@mediatek.com>
Wed, 20 Jul 2022 08:57:31 +0000 (10:57 +0200)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Tue, 30 Aug 2022 12:32:39 +0000 (14:32 +0200)
There is only one device mutex to lock vb2_queue when running
multi-instance encoding, it can be set by each encoder context.

[hverkuil: fix q_mutex documentation in the header]

Signed-off-by: Irui Wang <irui.wang@mediatek.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/mediatek/vcodec/mtk_vcodec_drv.h
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc.c
drivers/media/platform/mediatek/vcodec/mtk_vcodec_enc_drv.c

index fe8ed6a..9acab54 100644 (file)
@@ -278,6 +278,7 @@ struct vdec_pic_info {
  * @hw_id: hardware index used to identify different hardware.
  *
  * @msg_queue: msg queue used to store lat buffer information.
+ * @q_mutex: vb2_queue mutex.
  */
 struct mtk_vcodec_ctx {
        enum mtk_instance_type type;
@@ -324,6 +325,8 @@ struct mtk_vcodec_ctx {
        int hw_id;
 
        struct vdec_msg_queue msg_queue;
+
+       struct mutex q_mutex;
 };
 
 /*
index c310bb1..63e7fe9 100644 (file)
@@ -1300,7 +1300,7 @@ void mtk_vcodec_enc_set_default_params(struct mtk_vcodec_ctx *ctx)
 {
        struct mtk_q_data *q_data;
 
-       ctx->m2m_ctx->q_lock = &ctx->dev->dev_mutex;
+       ctx->m2m_ctx->q_lock = &ctx->q_mutex;
        ctx->fh.m2m_ctx = ctx->m2m_ctx;
        ctx->fh.ctrl_handler = &ctx->ctrl_hdl;
        INIT_WORK(&ctx->encode_work, mtk_venc_worker);
@@ -1435,7 +1435,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,
        src_vq->ops             = &mtk_venc_vb2_ops;
        src_vq->mem_ops         = &vb2_dma_contig_memops;
        src_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
-       src_vq->lock            = &ctx->dev->dev_mutex;
+       src_vq->lock            = &ctx->q_mutex;
        src_vq->dev             = &ctx->dev->plat_dev->dev;
 
        ret = vb2_queue_init(src_vq);
@@ -1449,7 +1449,7 @@ int mtk_vcodec_enc_queue_init(void *priv, struct vb2_queue *src_vq,
        dst_vq->ops             = &mtk_venc_vb2_ops;
        dst_vq->mem_ops         = &vb2_dma_contig_memops;
        dst_vq->timestamp_flags = V4L2_BUF_FLAG_TIMESTAMP_COPY;
-       dst_vq->lock            = &ctx->dev->dev_mutex;
+       dst_vq->lock            = &ctx->q_mutex;
        dst_vq->dev             = &ctx->dev->plat_dev->dev;
 
        return vb2_queue_init(dst_vq);
index 6d8964f..0abe1da 100644 (file)
@@ -130,6 +130,7 @@ static int fops_vcodec_open(struct file *file)
        INIT_LIST_HEAD(&ctx->list);
        ctx->dev = dev;
        init_waitqueue_head(&ctx->queue[0]);
+       mutex_init(&ctx->q_mutex);
 
        ctx->type = MTK_INST_ENCODER;
        ret = mtk_vcodec_enc_ctrls_setup(ctx);