Skip to content

Commit 5e488a4

Browse files
yunfei-mtkmchehab
authored andcommitted
media: mediatek: vcodec: Add a debugfs file to get different useful information
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>
1 parent 404500b commit 5e488a4

3 files changed

Lines changed: 98 additions & 0 deletions

File tree

drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.c

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,63 @@
1010
#include "mtk_vcodec_drv.h"
1111
#include "mtk_vcodec_util.h"
1212

13+
static ssize_t mtk_vdec_dbgfs_write(struct file *filp, const char __user *ubuf,
14+
size_t count, loff_t *ppos)
15+
{
16+
struct mtk_vcodec_dev *vcodec_dev = filp->private_data;
17+
struct mtk_vcodec_dbgfs *dbgfs = &vcodec_dev->dbgfs;
18+
19+
mutex_lock(&dbgfs->dbgfs_lock);
20+
dbgfs->buf_size = simple_write_to_buffer(dbgfs->dbgfs_buf, sizeof(dbgfs->dbgfs_buf),
21+
ppos, ubuf, count);
22+
mutex_unlock(&dbgfs->dbgfs_lock);
23+
if (dbgfs->buf_size > 0)
24+
return count;
25+
26+
return dbgfs->buf_size;
27+
}
28+
29+
static const struct file_operations vdec_fops = {
30+
.open = simple_open,
31+
.write = mtk_vdec_dbgfs_write,
32+
};
33+
34+
void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx)
35+
{
36+
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
37+
struct mtk_vcodec_dev *vcodec_dev = ctx->dev;
38+
39+
dbgfs_inst = kzalloc(sizeof(*dbgfs_inst), GFP_KERNEL);
40+
if (!dbgfs_inst)
41+
return;
42+
43+
list_add_tail(&dbgfs_inst->node, &vcodec_dev->dbgfs.dbgfs_head);
44+
45+
vcodec_dev->dbgfs.inst_count++;
46+
47+
dbgfs_inst->inst_id = ctx->id;
48+
dbgfs_inst->vcodec_ctx = ctx;
49+
}
50+
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_create);
51+
52+
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
53+
{
54+
struct mtk_vcodec_dbgfs_inst *dbgfs_inst;
55+
56+
list_for_each_entry(dbgfs_inst, &vcodec_dev->dbgfs.dbgfs_head, node) {
57+
if (dbgfs_inst->inst_id == ctx_id) {
58+
vcodec_dev->dbgfs.inst_count--;
59+
break;
60+
}
61+
}
62+
63+
if (dbgfs_inst) {
64+
list_del(&dbgfs_inst->node);
65+
kfree(dbgfs_inst);
66+
}
67+
}
68+
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_remove);
69+
1370
void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev)
1471
{
1572
struct dentry *vcodec_root;
@@ -22,6 +79,12 @@ void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev)
2279
vcodec_root = vcodec_dev->dbgfs.vcodec_root;
2380
debugfs_create_x32("mtk_v4l2_dbg_level", 0644, vcodec_root, &mtk_v4l2_dbg_level);
2481
debugfs_create_x32("mtk_vcodec_dbg", 0644, vcodec_root, &mtk_vcodec_dbg);
82+
83+
vcodec_dev->dbgfs.inst_count = 0;
84+
85+
INIT_LIST_HEAD(&vcodec_dev->dbgfs.dbgfs_head);
86+
debugfs_create_file("vdec", 0200, vcodec_root, vcodec_dev, &vdec_fops);
87+
mutex_init(&vcodec_dev->dbgfs.dbgfs_lock);
2588
}
2689
EXPORT_SYMBOL_GPL(mtk_vcodec_dbgfs_init);
2790

drivers/media/platform/mediatek/vcodec/mtk_vcodec_dbgfs.h

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,52 @@
88
#define __MTK_VCODEC_DBGFS_H__
99

1010
struct mtk_vcodec_dev;
11+
struct mtk_vcodec_ctx;
12+
13+
/**
14+
* struct mtk_vcodec_dbgfs_inst - debugfs information for each inst
15+
* @node: list node for each inst
16+
* @vcodec_ctx: struct mtk_vcodec_ctx
17+
* @inst_id: index of the context that the same with ctx->id
18+
*/
19+
struct mtk_vcodec_dbgfs_inst {
20+
struct list_head node;
21+
struct mtk_vcodec_ctx *vcodec_ctx;
22+
int inst_id;
23+
};
1124

1225
/**
1326
* struct mtk_vcodec_dbgfs - dbgfs information
27+
* @dbgfs_head: list head used to link each instance
1428
* @vcodec_root: vcodec dbgfs entry
29+
* @dbgfs_lock: dbgfs lock used to protect dbgfs_buf
30+
* @dbgfs_buf: dbgfs buf used to store dbgfs cmd
31+
* @buf_size: buffer size of dbgfs
32+
* @inst_count: the count of total instance
1533
*/
1634
struct mtk_vcodec_dbgfs {
35+
struct list_head dbgfs_head;
1736
struct dentry *vcodec_root;
37+
struct mutex dbgfs_lock;
38+
char dbgfs_buf[1024];
39+
int buf_size;
40+
int inst_count;
1841
};
1942

2043
#if defined(CONFIG_DEBUG_FS)
44+
void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx);
45+
void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id);
2146
void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev);
2247
void mtk_vcodec_dbgfs_deinit(struct mtk_vcodec_dev *vcodec_dev);
2348
#else
49+
static inline void mtk_vcodec_dbgfs_create(struct mtk_vcodec_ctx *ctx)
50+
{
51+
}
52+
53+
static inline void mtk_vcodec_dbgfs_remove(struct mtk_vcodec_dev *vcodec_dev, int ctx_id)
54+
{
55+
}
56+
2457
static inline void mtk_vcodec_dbgfs_init(struct mtk_vcodec_dev *vcodec_dev)
2558
{
2659
}

drivers/media/platform/mediatek/vcodec/mtk_vcodec_dec_drv.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -215,6 +215,7 @@ static int fops_vcodec_open(struct file *file)
215215
ctx->dev->vdec_pdata->init_vdec_params(ctx);
216216

217217
list_add(&ctx->list, &dev->ctx_list);
218+
mtk_vcodec_dbgfs_create(ctx);
218219

219220
mutex_unlock(&dev->dev_mutex);
220221
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)
256257
v4l2_fh_exit(&ctx->fh);
257258
v4l2_ctrl_handler_free(&ctx->ctrl_hdl);
258259

260+
mtk_vcodec_dbgfs_remove(dev, ctx->id);
259261
list_del_init(&ctx->list);
260262
kfree(ctx);
261263
mutex_unlock(&dev->dev_mutex);

0 commit comments

Comments
 (0)