media: mediatek: vcodec: Add a debugfs file to get different useful information
authorYunfei Dong <yunfei.dong@mediatek.com>
Tue, 30 May 2023 12:29:03 +0000 (20:29 +0800)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Fri, 9 Jun 2023 15:38:44 +0000 (16:38 +0100)
In oder to get each instance information according to test command, adding
one file node "vdec".

Can use echo command to set different string value as
'echo -picinfo > vdec'.

Signed-off-by: Yunfei Dong <yunfei.dong@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
[hverkuil: drop unwanted dbgfs_inst NULL ptr check in mtk_vcodec_dbgfs_remove]
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h
drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c

index b5093e4e4aa20ac814d8d355d8ac281859d360c9..b0ce117378b09de846d0faf97ca82f04925517db 100644 (file)
 #include "mtk_vcodec_drv.h"
 #include "mtk_vcodec_util.h"
 
+static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
+                                   size_t count, loff_t *ppos)
+{
+       struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
+       struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
+
+       mutex_lock(&dbgfs->dbgfs_lock);
+       dbgfs->buf_size = simple_write_to_buffer(dbgfs->dbgfs_buf, sizeof(dbgfs->dbgfs_buf),
+                                                ppos, ubuf, count);
+       mutex_unlock(&dbgfs->dbgfs_lock);
+       if (dbgfs->buf_size > 0)
+               return count;
+
+       return dbgfs->buf_size;
+}
+
+static const struct file_operations vdec_fops = {
+       .open = simple_open,
+       .write = mtk_vdec_dbgfs_write,
+};
+
+void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx)
+{
+       struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
+       struct mtk_vcodec_dev *vcodec_dev = ctx->dev;
+
+       dbgfs_inst = kzalloc(sizeof(*dbgfs_inst), GFP_KERNEL);
+       if (!dbgfs_inst)
+               return;
+
+       list_add_tail(&dbgfs_inst->node, &vcodec_dev->dbgfs.dbgfs_head);
+
+       vcodec_dev->dbgfs.inst_count++;
+
+       dbgfs_inst->inst_id = ctx->id;
+       dbgfs_inst->vcodec_ctx = ctx;
+}
+EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_create);
+
+void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
+{
+       struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
+
+       list_for_each_entry(dbgfs_inst, &vcodec_dev->dbgfs.dbgfs_head, node) {
+               if (dbgfs_inst->inst_id == ctx_id) {
+                       vcodec_dev->dbgfs.inst_count--;
+                       break;
+               }
+       }
+
+       if (dbgfs_inst) {
+               list_del(&dbgfs_inst->node);
+               kfree(dbgfs_inst);
+       }
+}
+EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_remove);
+
 void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev)
 {
        struct dentry *vcodec_root;
@@ -22,6 +79,12 @@ void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev)
        vcodec_root = vcodec_dev->dbgfs.vcodec_root;
        debugfs_create_x32("mtk_v4l2_dbg_level", 0644, vcodec_root, &mtk_v4l2_dbg_level);
        debugfs_create_x32("mtk_vcodec_dbg", 0644, vcodec_root, &mtk_vcodec_dbg);
+
+       vcodec_dev->dbgfs.inst_count = 0;
+
+       INIT_LIST_HEAD(&vcodec_dev->dbgfs.dbgfs_head);
+       debugfs_create_file("vdec", 0200, vcodec_root, vcodec_dev, &vdec_fops);
+       mutex_init(&vcodec_dev->dbgfs.dbgfs_lock);
 }
 EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_init);
 
index 5eec2211cbbe5956abdea1b766495f0c32b55fa1..a563e656f42e57eea2755b34ec9695dbb6ac7839 100644 (file)
@@ -8,19 +8,52 @@
 #define __MTK_VCODEC_DBGFS_H__
 
 struct mtk_vcodec_dev;
+struct mtk_vcodec_ctx;
+
+/**
+ * struct mtk_vcodec_dbgfs_inst  - debugfs information for each inst
+ * @node:       list node for each inst
+ * @vcodec_ctx: struct mtk_vcodec_ctx
+ * @inst_id:    index of the context that the same with ctx->id
+ */
+struct mtk_vcodec_dbgfs_inst {
+       struct list_head node;
+       struct mtk_vcodec_ctx *vcodec_ctx;
+       int inst_id;
+};
 
 /**
  * struct mtk_vcodec_dbgfs  - dbgfs information
+ * @dbgfs_head:  list head used to link each instance
  * @vcodec_root: vcodec dbgfs entry
+ * @dbgfs_lock:  dbgfs lock used to protect dbgfs_buf
+ * @dbgfs_buf:   dbgfs buf used to store dbgfs cmd
+ * @buf_size:    buffer size of dbgfs
+ * @inst_count:  the count of total instance
  */
 struct mtk_vcodec_dbgfs {
+       struct list_head dbgfs_head;
        struct dentry *vcodec_root;
+       struct mutex dbgfs_lock;
+       char dbgfs_buf[1024];
+       int buf_size;
+       int inst_count;
 };
 
 #if defined(CONFIG_DEBUG_FS)
+void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx);
+void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id);
 void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev);
 void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev);
 #else
+static inline void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx)
+{
+}
+
+static inline void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
+{
+}
+
 static inline void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev)
 {
 }
index 51a9af193f9241b23e1b9be9be26f57da7f40bf7..b25943ac390989fcee56f893adf91b4fa8e465a6 100644 (file)
@@ -215,6 +215,7 @@ static int fops_vcodec_open(struct file *file)
        ctx->dev->vdec_pdata->init_vdec_params(ctx);
 
        list_add(&ctx->list, &dev->ctx_list);
+       mtk_vcodec_dbgfs_create(ctx);
 
        mutex_unlock(&dev->dev_mutex);
        mtk_v4l2_debug(0, "%s decoder [%d]", dev_name(&dev->plat_dev->dev),
@@ -256,6 +257,7 @@ static int fops_vcodec_release(struct file *file)
        v4l2_fh_exit(&ctx->fh);
        v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
 
+       mtk_vcodec_dbgfs_remove(dev, ctx->id);
        list_del_init(&ctx->list);
        kfree(ctx);
        mutex_unlock(&dev->dev_mutex);