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 vchiq_dump_show(struct seq_file *f, void *offset)
45 struct vchiq_state *state = f->private;
47 vchiq_dump_state(f, state);
51 DEFINE_SHOW_ATTRIBUTE(vchiq_dump);
53 static int debugfs_trace_open(struct inode *inode, struct file *file)
55 return single_open(file, debugfs_trace_show, inode->i_private);
58 static ssize_t debugfs_trace_write(struct file *file,
59 const char __user *buffer,
60 size_t count, loff_t *ppos)
62 struct seq_file *f = (struct seq_file *)file->private_data;
63 struct vchiq_instance *instance = f->private;
66 if (copy_from_user(&firstchar, buffer, 1))
73 vchiq_instance_set_trace(instance, 1);
78 vchiq_instance_set_trace(instance, 0);
89 static const struct file_operations debugfs_trace_fops = {
91 .open = debugfs_trace_open,
92 .write = debugfs_trace_write,
95 .release = single_release,
98 /* add an instance (process) to the debugfs entries */
99 void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
104 snprintf(pidstr, sizeof(pidstr), "%d",
105 vchiq_instance_get_pid(instance));
107 top = debugfs_create_dir(pidstr, vchiq_dbg_clients);
109 debugfs_create_file("use_count", 0444, top, instance,
110 &debugfs_usecount_fops);
111 debugfs_create_file("trace", 0644, top, instance, &debugfs_trace_fops);
113 vchiq_instance_get_debugfs_node(instance)->dentry = top;
116 void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
118 struct vchiq_debugfs_node *node =
119 vchiq_instance_get_debugfs_node(instance);
121 debugfs_remove_recursive(node->dentry);
124 void vchiq_debugfs_init(struct vchiq_state *state)
126 vchiq_dbg_dir = debugfs_create_dir("vchiq", NULL);
127 vchiq_dbg_clients = debugfs_create_dir("clients", vchiq_dbg_dir);
129 debugfs_create_file("state", S_IFREG | 0444, vchiq_dbg_dir, state,
133 /* remove all the debugfs entries */
134 void vchiq_debugfs_deinit(void)
136 debugfs_remove_recursive(vchiq_dbg_dir);
139 #else /* CONFIG_DEBUG_FS */
141 void vchiq_debugfs_init(void)
145 void vchiq_debugfs_deinit(void)
149 void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
153 void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
157 #endif /* CONFIG_DEBUG_FS */