1 // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
3 * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
4 * Copyright (c) 2010-2012 Broadcom. All rights reserved.
7 #include <linux/debugfs.h>
8 #include "vchiq_core.h"
10 #include "vchiq_debugfs.h"
12 #ifdef CONFIG_DEBUG_FS
14 #define DEBUGFS_WRITE_BUF_SIZE 256
16 /* Global 'vchiq' debugfs and clients entry used by all instances */
17 static struct dentry *vchiq_dbg_dir;
18 static struct dentry *vchiq_dbg_clients;
20 static int debugfs_usecount_show(struct seq_file *f, void *offset)
22 struct vchiq_instance *instance = f->private;
25 use_count = vchiq_instance_get_use_count(instance);
26 seq_printf(f, "%d\n", use_count);
30 DEFINE_SHOW_ATTRIBUTE(debugfs_usecount);
32 static int debugfs_trace_show(struct seq_file *f, void *offset)
34 struct vchiq_instance *instance = f->private;
37 trace = vchiq_instance_get_trace(instance);
38 seq_printf(f, "%s\n", trace ? "Y" : "N");
43 static int debugfs_trace_open(struct inode *inode, struct file *file)
45 return single_open(file, debugfs_trace_show, inode->i_private);
48 static ssize_t debugfs_trace_write(struct file *file,
49 const char __user *buffer,
50 size_t count, loff_t *ppos)
52 struct seq_file *f = (struct seq_file *)file->private_data;
53 struct vchiq_instance *instance = f->private;
56 if (copy_from_user(&firstchar, buffer, 1))
63 vchiq_instance_set_trace(instance, 1);
68 vchiq_instance_set_trace(instance, 0);
79 static const struct file_operations debugfs_trace_fops = {
81 .open = debugfs_trace_open,
82 .write = debugfs_trace_write,
85 .release = single_release,
88 /* add an instance (process) to the debugfs entries */
89 void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
94 snprintf(pidstr, sizeof(pidstr), "%d",
95 vchiq_instance_get_pid(instance));
97 top = debugfs_create_dir(pidstr, vchiq_dbg_clients);
99 debugfs_create_file("use_count", 0444, top, instance,
100 &debugfs_usecount_fops);
101 debugfs_create_file("trace", 0644, top, instance, &debugfs_trace_fops);
103 vchiq_instance_get_debugfs_node(instance)->dentry = top;
106 void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
108 struct vchiq_debugfs_node *node =
109 vchiq_instance_get_debugfs_node(instance);
111 debugfs_remove_recursive(node->dentry);
114 void vchiq_debugfs_init(void)
116 vchiq_dbg_dir = debugfs_create_dir("vchiq", NULL);
117 vchiq_dbg_clients = debugfs_create_dir("clients", vchiq_dbg_dir);
120 /* remove all the debugfs entries */
121 void vchiq_debugfs_deinit(void)
123 debugfs_remove_recursive(vchiq_dbg_dir);
126 #else /* CONFIG_DEBUG_FS */
128 void vchiq_debugfs_init(void)
132 void vchiq_debugfs_deinit(void)
136 void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
140 void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
144 #endif /* CONFIG_DEBUG_FS */