1 // SPDX-License-Identifier: GPL-2.0+
3 * Debugfs tracing for bitstream buffers. This is similar to VA-API's
4 * LIBVA_TRACE_BUFDATA in that the raw bitstream can be dumped as a debugging
7 * Produces one file per OUTPUT buffer. Files are automatically cleared on
8 * STREAMOFF unless the module parameter "keep_bitstream_buffers" is set.
11 #include <linux/debugfs.h>
12 #include <linux/list.h>
13 #include <linux/mutex.h>
14 #include <media/v4l2-mem2mem.h>
16 #include "visl-debugfs.h"
18 int visl_debugfs_init(struct visl_dev
*dev
)
20 dev
->debugfs_root
= debugfs_create_dir("visl", NULL
);
21 INIT_LIST_HEAD(&dev
->bitstream_blobs
);
22 mutex_init(&dev
->bitstream_lock
);
24 if (IS_ERR(dev
->debugfs_root
))
25 return PTR_ERR(dev
->debugfs_root
);
27 return visl_debugfs_bitstream_init(dev
);
30 int visl_debugfs_bitstream_init(struct visl_dev
*dev
)
32 dev
->bitstream_debugfs
= debugfs_create_dir("bitstream",
34 if (IS_ERR(dev
->bitstream_debugfs
))
35 return PTR_ERR(dev
->bitstream_debugfs
);
40 void visl_trace_bitstream(struct visl_ctx
*ctx
, struct visl_run
*run
)
42 u8
*vaddr
= vb2_plane_vaddr(&run
->src
->vb2_buf
, 0);
43 struct visl_blob
*blob
;
44 size_t data_sz
= vb2_get_plane_payload(&run
->src
->vb2_buf
, 0);
45 struct dentry
*dentry
;
48 blob
= kzalloc(sizeof(*blob
), GFP_KERNEL
);
52 blob
->blob
.data
= vzalloc(data_sz
);
56 blob
->blob
.size
= data_sz
;
57 snprintf(name
, 32, "bitstream%d", run
->src
->sequence
);
59 memcpy(blob
->blob
.data
, vaddr
, data_sz
);
61 dentry
= debugfs_create_blob(name
, 0444, ctx
->dev
->bitstream_debugfs
,
66 blob
->dentry
= dentry
;
68 mutex_lock(&ctx
->dev
->bitstream_lock
);
69 list_add_tail(&blob
->list
, &ctx
->dev
->bitstream_blobs
);
70 mutex_unlock(&ctx
->dev
->bitstream_lock
);
75 vfree(blob
->blob
.data
);
80 void visl_debugfs_clear_bitstream(struct visl_dev
*dev
)
82 struct visl_blob
*blob
;
83 struct visl_blob
*tmp
;
85 mutex_lock(&dev
->bitstream_lock
);
86 if (list_empty(&dev
->bitstream_blobs
))
89 list_for_each_entry_safe(blob
, tmp
, &dev
->bitstream_blobs
, list
) {
90 list_del(&blob
->list
);
91 debugfs_remove(blob
->dentry
);
92 vfree(blob
->blob
.data
);
97 mutex_unlock(&dev
->bitstream_lock
);
100 void visl_debugfs_bitstream_deinit(struct visl_dev
*dev
)
102 visl_debugfs_clear_bitstream(dev
);
103 debugfs_remove_recursive(dev
->bitstream_debugfs
);
104 dev
->bitstream_debugfs
= NULL
;
107 void visl_debugfs_deinit(struct visl_dev
*dev
)
109 visl_debugfs_bitstream_deinit(dev
);
110 debugfs_remove_recursive(dev
->debugfs_root
);
111 dev
->debugfs_root
= NULL
;