1 // SPDX-License-Identifier: GPL-2.0
3 * debugfs.h - a tiny little debug file system
5 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2004 IBM Inc.
8 * debugfs is for people to use instead of /proc or /sys.
9 * See Documentation/filesystems/ for more details.
16 #include <linux/seq_file.h>
18 #include <linux/types.h>
19 #include <linux/compiler.h>
22 struct file_operations;
24 struct debugfs_blob_wrapper {
29 struct debugfs_reg32 {
34 struct debugfs_regset32 {
35 const struct debugfs_reg32 *regs;
40 extern struct dentry *arch_debugfs_dir;
42 #define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \
43 static int __fops ## _open(struct inode *inode, struct file *file) \
45 __simple_attr_check_format(__fmt, 0ull); \
46 return simple_attr_open(inode, file, __get, __set, __fmt); \
48 static const struct file_operations __fops = { \
49 .owner = THIS_MODULE, \
50 .open = __fops ## _open, \
51 .release = simple_attr_release, \
52 .read = debugfs_attr_read, \
53 .write = (__is_signed) ? debugfs_attr_write_signed : debugfs_attr_write, \
54 .llseek = no_llseek, \
57 #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
58 DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
60 #define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
61 DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
63 typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
65 #if defined(CONFIG_DEBUG_FS)
67 struct dentry *debugfs_lookup(const char *name, struct dentry *parent);
69 struct dentry *debugfs_create_file(const char *name, umode_t mode,
70 struct dentry *parent, void *data,
71 const struct file_operations *fops);
72 struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
73 struct dentry *parent, void *data,
74 const struct file_operations *fops);
76 struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
77 struct dentry *parent, void *data,
78 const struct file_operations *fops,
81 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
83 struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
86 struct dentry *debugfs_create_automount(const char *name,
87 struct dentry *parent,
88 debugfs_automount_t f,
91 void debugfs_remove(struct dentry *dentry);
92 void debugfs_remove_recursive(struct dentry *dentry);
94 void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
96 const struct file_operations *debugfs_real_fops(const struct file *filp);
98 int debugfs_file_get(struct dentry *dentry);
99 void debugfs_file_put(struct dentry *dentry);
101 ssize_t debugfs_attr_read(struct file *file, char __user *buf,
102 size_t len, loff_t *ppos);
103 ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
104 size_t len, loff_t *ppos);
105 ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
106 size_t len, loff_t *ppos);
108 struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
109 struct dentry *new_dir, const char *new_name);
111 struct dentry *debugfs_create_u8(const char *name, umode_t mode,
112 struct dentry *parent, u8 *value);
113 struct dentry *debugfs_create_u16(const char *name, umode_t mode,
114 struct dentry *parent, u16 *value);
115 struct dentry *debugfs_create_u32(const char *name, umode_t mode,
116 struct dentry *parent, u32 *value);
117 struct dentry *debugfs_create_u64(const char *name, umode_t mode,
118 struct dentry *parent, u64 *value);
119 struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
120 struct dentry *parent, unsigned long *value);
121 struct dentry *debugfs_create_x8(const char *name, umode_t mode,
122 struct dentry *parent, u8 *value);
123 struct dentry *debugfs_create_x16(const char *name, umode_t mode,
124 struct dentry *parent, u16 *value);
125 struct dentry *debugfs_create_x32(const char *name, umode_t mode,
126 struct dentry *parent, u32 *value);
127 struct dentry *debugfs_create_x64(const char *name, umode_t mode,
128 struct dentry *parent, u64 *value);
129 struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
130 struct dentry *parent, size_t *value);
131 struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
132 struct dentry *parent, atomic_t *value);
133 struct dentry *debugfs_create_bool(const char *name, umode_t mode,
134 struct dentry *parent, bool *value);
136 struct dentry *debugfs_create_blob(const char *name, umode_t mode,
137 struct dentry *parent,
138 struct debugfs_blob_wrapper *blob);
140 struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
141 struct dentry *parent,
142 struct debugfs_regset32 *regset);
144 void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
145 int nregs, void __iomem *base, char *prefix);
147 void debugfs_create_u32_array(const char *name, umode_t mode,
148 struct dentry *parent, u32 *array, u32 elements);
150 struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
151 struct dentry *parent,
152 int (*read_fn)(struct seq_file *s,
155 bool debugfs_initialized(void);
157 ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
158 size_t count, loff_t *ppos);
160 ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
161 size_t count, loff_t *ppos);
165 #include <linux/err.h>
168 * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
169 * so users have a chance to detect if there was a real error or not. We don't
170 * want to duplicate the design decision mistakes of procfs and devfs again.
173 static inline struct dentry *debugfs_lookup(const char *name,
174 struct dentry *parent)
176 return ERR_PTR(-ENODEV);
179 static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
180 struct dentry *parent, void *data,
181 const struct file_operations *fops)
183 return ERR_PTR(-ENODEV);
186 static inline struct dentry *debugfs_create_file_unsafe(const char *name,
187 umode_t mode, struct dentry *parent,
189 const struct file_operations *fops)
191 return ERR_PTR(-ENODEV);
194 static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
195 struct dentry *parent, void *data,
196 const struct file_operations *fops,
199 return ERR_PTR(-ENODEV);
202 static inline struct dentry *debugfs_create_dir(const char *name,
203 struct dentry *parent)
205 return ERR_PTR(-ENODEV);
208 static inline struct dentry *debugfs_create_symlink(const char *name,
209 struct dentry *parent,
212 return ERR_PTR(-ENODEV);
215 static inline struct dentry *debugfs_create_automount(const char *name,
216 struct dentry *parent,
217 debugfs_automount_t f,
220 return ERR_PTR(-ENODEV);
223 static inline void debugfs_remove(struct dentry *dentry)
226 static inline void debugfs_remove_recursive(struct dentry *dentry)
229 static inline void debugfs_lookup_and_remove(const char *name,
230 struct dentry *parent)
233 const struct file_operations *debugfs_real_fops(const struct file *filp);
235 static inline int debugfs_file_get(struct dentry *dentry)
240 static inline void debugfs_file_put(struct dentry *dentry)
243 static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf,
244 size_t len, loff_t *ppos)
249 static inline ssize_t debugfs_attr_write(struct file *file,
250 const char __user *buf,
251 size_t len, loff_t *ppos)
256 static inline ssize_t debugfs_attr_write_signed(struct file *file,
257 const char __user *buf,
258 size_t len, loff_t *ppos)
263 static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
264 struct dentry *new_dir, char *new_name)
266 return ERR_PTR(-ENODEV);
269 static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
270 struct dentry *parent,
273 return ERR_PTR(-ENODEV);
276 static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
277 struct dentry *parent,
280 return ERR_PTR(-ENODEV);
283 static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
284 struct dentry *parent,
287 return ERR_PTR(-ENODEV);
290 static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
291 struct dentry *parent,
294 return ERR_PTR(-ENODEV);
297 static inline struct dentry *debugfs_create_ulong(const char *name,
299 struct dentry *parent,
300 unsigned long *value)
302 return ERR_PTR(-ENODEV);
305 static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
306 struct dentry *parent,
309 return ERR_PTR(-ENODEV);
312 static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
313 struct dentry *parent,
316 return ERR_PTR(-ENODEV);
319 static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
320 struct dentry *parent,
323 return ERR_PTR(-ENODEV);
326 static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
327 struct dentry *parent,
330 return ERR_PTR(-ENODEV);
333 static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
334 struct dentry *parent,
337 return ERR_PTR(-ENODEV);
340 static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
341 struct dentry *parent, atomic_t *value)
343 return ERR_PTR(-ENODEV);
346 static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
347 struct dentry *parent,
350 return ERR_PTR(-ENODEV);
353 static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
354 struct dentry *parent,
355 struct debugfs_blob_wrapper *blob)
357 return ERR_PTR(-ENODEV);
360 static inline struct dentry *debugfs_create_regset32(const char *name,
361 umode_t mode, struct dentry *parent,
362 struct debugfs_regset32 *regset)
364 return ERR_PTR(-ENODEV);
367 static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
368 int nregs, void __iomem *base, char *prefix)
372 static inline bool debugfs_initialized(void)
377 static inline void debugfs_create_u32_array(const char *name, umode_t mode,
378 struct dentry *parent, u32 *array,
383 static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
385 struct dentry *parent,
386 int (*read_fn)(struct seq_file *s,
389 return ERR_PTR(-ENODEV);
392 static inline ssize_t debugfs_read_file_bool(struct file *file,
393 char __user *user_buf,
394 size_t count, loff_t *ppos)
399 static inline ssize_t debugfs_write_file_bool(struct file *file,
400 const char __user *user_buf,
401 size_t count, loff_t *ppos)