Merge branch 'core-objtool-for-linus' of git://git.kernel.org/pub/scm/linux/kernel...
[linux-block.git] / include / linux / debugfs.h
CommitLineData
3bce94fd 1// SPDX-License-Identifier: GPL-2.0
1da177e4
LT
2/*
3 * debugfs.h - a tiny little debug file system
4 *
5 * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
6 * Copyright (C) 2004 IBM Inc.
7 *
1da177e4 8 * debugfs is for people to use instead of /proc or /sys.
e1b4fc7a 9 * See Documentation/filesystems/ for more details.
1da177e4
LT
10 */
11
12#ifndef _DEBUGFS_H_
13#define _DEBUGFS_H_
14
15#include <linux/fs.h>
1a087c6a 16#include <linux/seq_file.h>
1da177e4 17
a7a76cef 18#include <linux/types.h>
49d200de 19#include <linux/compiler.h>
a7a76cef 20
f30d0a81 21struct device;
a7a76cef
RD
22struct file_operations;
23
dd308bc3
ME
24struct debugfs_blob_wrapper {
25 void *data;
26 unsigned long size;
27};
28
1a087c6a
AR
29struct debugfs_reg32 {
30 char *name;
31 unsigned long offset;
32};
33
34struct debugfs_regset32 {
833d6e01 35 const struct debugfs_reg32 *regs;
1a087c6a
AR
36 int nregs;
37 void __iomem *base;
38};
39
ae79cdaa 40extern struct dentry *arch_debugfs_dir;
41
7f847dd3
AB
42#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
43static int __fops ## _open(struct inode *inode, struct file *file) \
44{ \
45 __simple_attr_check_format(__fmt, 0ull); \
46 return simple_attr_open(inode, file, __get, __set, __fmt); \
47} \
48static 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 = debugfs_attr_write, \
895ce6c8 54 .llseek = no_llseek, \
7f847dd3
AB
55}
56
4250b047
KK
57typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
58
1da177e4 59#if defined(CONFIG_DEBUG_FS)
3634634e 60
a7c5437b
OS
61struct dentry *debugfs_lookup(const char *name, struct dentry *parent);
62
f4ae40a6 63struct dentry *debugfs_create_file(const char *name, umode_t mode,
1da177e4 64 struct dentry *parent, void *data,
99ac48f5 65 const struct file_operations *fops);
c6468808
NS
66struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
67 struct dentry *parent, void *data,
68 const struct file_operations *fops);
1da177e4 69
526ee72d
GKH
70void debugfs_create_file_size(const char *name, umode_t mode,
71 struct dentry *parent, void *data,
72 const struct file_operations *fops,
73 loff_t file_size);
e59b4e91 74
1da177e4
LT
75struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
76
66f54963
PO
77struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
78 const char *dest);
79
77b3da6e
AV
80struct dentry *debugfs_create_automount(const char *name,
81 struct dentry *parent,
93faccbb 82 debugfs_automount_t f,
77b3da6e
AV
83 void *data);
84
1da177e4 85void debugfs_remove(struct dentry *dentry);
a3d1e7eb 86#define debugfs_remove_recursive debugfs_remove
1da177e4 87
055ab8e3 88const struct file_operations *debugfs_real_fops(const struct file *filp);
7c8d4698 89
e9117a5a
NS
90int debugfs_file_get(struct dentry *dentry);
91void debugfs_file_put(struct dentry *dentry);
92
c6468808
NS
93ssize_t debugfs_attr_read(struct file *file, char __user *buf,
94 size_t len, loff_t *ppos);
95ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
96 size_t len, loff_t *ppos);
97
cfc94cdf
JK
98struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
99 struct dentry *new_dir, const char *new_name);
100
9655ac4a
GKH
101void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent,
102 u8 *value);
313f5dbb
GKH
103void debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent,
104 u16 *value);
f4ae40a6 105struct dentry *debugfs_create_u32(const char *name, umode_t mode,
1da177e4 106 struct dentry *parent, u32 *value);
ad26221f
GKH
107void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent,
108 u64 *value);
c23fe831
VK
109struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
110 struct dentry *parent, unsigned long *value);
c7c11689
GKH
111void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent,
112 u8 *value);
e40d38f2
GKH
113void debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent,
114 u16 *value);
f5cb0a7e
GKH
115void debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent,
116 u32 *value);
0864c408
GKH
117void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent,
118 u64 *value);
8e580263
GKH
119void debugfs_create_size_t(const char *name, umode_t mode,
120 struct dentry *parent, size_t *value);
9927c6fa
GKH
121void debugfs_create_atomic_t(const char *name, umode_t mode,
122 struct dentry *parent, atomic_t *value);
f4ae40a6 123struct dentry *debugfs_create_bool(const char *name, umode_t mode,
621a5f7a 124 struct dentry *parent, bool *value);
1da177e4 125
f4ae40a6 126struct dentry *debugfs_create_blob(const char *name, umode_t mode,
dd308bc3
ME
127 struct dentry *parent,
128 struct debugfs_blob_wrapper *blob);
c0f92ba9 129
ae91c925
GKH
130void debugfs_create_regset32(const char *name, umode_t mode,
131 struct dentry *parent,
132 struct debugfs_regset32 *regset);
1a087c6a 133
9761536e
JP
134void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
135 int nregs, void __iomem *base, char *prefix);
1a087c6a 136
c9c2c27d
GKH
137void debugfs_create_u32_array(const char *name, umode_t mode,
138 struct dentry *parent, u32 *array, u32 elements);
9fe2a701 139
98210b7f
AS
140struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
141 struct dentry *parent,
142 int (*read_fn)(struct seq_file *s,
143 void *data));
144
c0f92ba9
FW
145bool debugfs_initialized(void);
146
0642ef6f
RF
147ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
148 size_t count, loff_t *ppos);
149
150ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
151 size_t count, loff_t *ppos);
152
1da177e4 153#else
a7a76cef
RD
154
155#include <linux/err.h>
156
98210b7f 157/*
1da177e4
LT
158 * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
159 * so users have a chance to detect if there was a real error or not. We don't
160 * want to duplicate the design decision mistakes of procfs and devfs again.
161 */
162
a7c5437b
OS
163static inline struct dentry *debugfs_lookup(const char *name,
164 struct dentry *parent)
165{
166 return ERR_PTR(-ENODEV);
167}
168
f4ae40a6 169static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
bde11d79
JD
170 struct dentry *parent, void *data,
171 const struct file_operations *fops)
1da177e4
LT
172{
173 return ERR_PTR(-ENODEV);
174}
175
c2a737eb
VK
176static inline struct dentry *debugfs_create_file_unsafe(const char *name,
177 umode_t mode, struct dentry *parent,
178 void *data,
179 const struct file_operations *fops)
180{
181 return ERR_PTR(-ENODEV);
182}
183
526ee72d
GKH
184static inline void debugfs_create_file_size(const char *name, umode_t mode,
185 struct dentry *parent, void *data,
186 const struct file_operations *fops,
187 loff_t file_size)
188{ }
e59b4e91 189
1da177e4
LT
190static inline struct dentry *debugfs_create_dir(const char *name,
191 struct dentry *parent)
192{
193 return ERR_PTR(-ENODEV);
194}
195
66f54963
PO
196static inline struct dentry *debugfs_create_symlink(const char *name,
197 struct dentry *parent,
198 const char *dest)
199{
200 return ERR_PTR(-ENODEV);
201}
202
94e1dec7
JW
203static inline struct dentry *debugfs_create_automount(const char *name,
204 struct dentry *parent,
4250b047 205 debugfs_automount_t f,
94e1dec7
JW
206 void *data)
207{
208 return ERR_PTR(-ENODEV);
209}
210
1da177e4
LT
211static inline void debugfs_remove(struct dentry *dentry)
212{ }
213
9505e637
HS
214static inline void debugfs_remove_recursive(struct dentry *dentry)
215{ }
216
f50caa9b
AB
217const struct file_operations *debugfs_real_fops(const struct file *filp);
218
e9117a5a
NS
219static inline int debugfs_file_get(struct dentry *dentry)
220{
221 return 0;
222}
223
224static inline void debugfs_file_put(struct dentry *dentry)
225{ }
226
7f847dd3
AB
227static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf,
228 size_t len, loff_t *ppos)
229{
230 return -ENODEV;
231}
232
233static inline ssize_t debugfs_attr_write(struct file *file,
234 const char __user *buf,
235 size_t len, loff_t *ppos)
236{
237 return -ENODEV;
238}
c6468808 239
cfc94cdf
JK
240static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
241 struct dentry *new_dir, char *new_name)
242{
243 return ERR_PTR(-ENODEV);
244}
245
9655ac4a
GKH
246static inline void debugfs_create_u8(const char *name, umode_t mode,
247 struct dentry *parent, u8 *value) { }
1da177e4 248
313f5dbb
GKH
249static inline void debugfs_create_u16(const char *name, umode_t mode,
250 struct dentry *parent, u16 *value) { }
1da177e4 251
f4ae40a6 252static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
1da177e4 253 struct dentry *parent,
7b558637 254 u32 *value)
1da177e4
LT
255{
256 return ERR_PTR(-ENODEV);
257}
258
ad26221f
GKH
259static inline void debugfs_create_u64(const char *name, umode_t mode,
260 struct dentry *parent, u64 *value) { }
8447891f 261
c2a737eb
VK
262static inline struct dentry *debugfs_create_ulong(const char *name,
263 umode_t mode,
264 struct dentry *parent,
265 unsigned long *value)
266{
267 return ERR_PTR(-ENODEV);
268}
269
c7c11689
GKH
270static inline void debugfs_create_x8(const char *name, umode_t mode,
271 struct dentry *parent, u8 *value) { }
2ebefc50 272
e40d38f2
GKH
273static inline void debugfs_create_x16(const char *name, umode_t mode,
274 struct dentry *parent, u16 *value) { }
2ebefc50 275
f5cb0a7e
GKH
276static inline void debugfs_create_x32(const char *name, umode_t mode,
277 struct dentry *parent, u32 *value) { }
2ebefc50 278
0864c408
GKH
279static inline void debugfs_create_x64(const char *name, umode_t mode,
280 struct dentry *parent, u64 *value) { }
3159269e 281
8e580263
GKH
282static inline void debugfs_create_size_t(const char *name, umode_t mode,
283 struct dentry *parent, size_t *value)
284{ }
8adb711f 285
9927c6fa
GKH
286static inline void debugfs_create_atomic_t(const char *name, umode_t mode,
287 struct dentry *parent,
288 atomic_t *value)
289{ }
5b880214 290
f4ae40a6 291static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
1da177e4 292 struct dentry *parent,
621a5f7a 293 bool *value)
1da177e4
LT
294{
295 return ERR_PTR(-ENODEV);
296}
297
f4ae40a6 298static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
dd308bc3
ME
299 struct dentry *parent,
300 struct debugfs_blob_wrapper *blob)
301{
302 return ERR_PTR(-ENODEV);
303}
304
ae91c925
GKH
305static inline void debugfs_create_regset32(const char *name, umode_t mode,
306 struct dentry *parent,
307 struct debugfs_regset32 *regset)
1a087c6a 308{
1a087c6a
AR
309}
310
9761536e 311static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
5b880214
WY
312 int nregs, void __iomem *base, char *prefix)
313{
5b880214
WY
314}
315
c0f92ba9
FW
316static inline bool debugfs_initialized(void)
317{
318 return false;
319}
320
c9c2c27d
GKH
321static inline void debugfs_create_u32_array(const char *name, umode_t mode,
322 struct dentry *parent, u32 *array,
323 u32 elements)
9fe2a701 324{
9fe2a701
SV
325}
326
98210b7f
AS
327static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
328 const char *name,
329 struct dentry *parent,
330 int (*read_fn)(struct seq_file *s,
331 void *data))
332{
333 return ERR_PTR(-ENODEV);
334}
335
0642ef6f
RF
336static inline ssize_t debugfs_read_file_bool(struct file *file,
337 char __user *user_buf,
338 size_t count, loff_t *ppos)
339{
340 return -ENODEV;
341}
342
343static inline ssize_t debugfs_write_file_bool(struct file *file,
344 const char __user *user_buf,
345 size_t count, loff_t *ppos)
346{
347 return -ENODEV;
348}
349
1da177e4
LT
350#endif
351
d3504757
GU
352/**
353 * debugfs_create_xul - create a debugfs file that is used to read and write an
354 * unsigned long value, formatted in hexadecimal
355 * @name: a pointer to a string containing the name of the file to create.
356 * @mode: the permission that the file should have
357 * @parent: a pointer to the parent dentry for this file. This should be a
358 * directory dentry if set. If this parameter is %NULL, then the
359 * file will be created in the root of the debugfs filesystem.
360 * @value: a pointer to the variable that the file should read to and write
361 * from.
362 */
363static inline void debugfs_create_xul(const char *name, umode_t mode,
364 struct dentry *parent,
365 unsigned long *value)
366{
367 if (sizeof(*value) == sizeof(u32))
368 debugfs_create_x32(name, mode, parent, (u32 *)value);
369 else
370 debugfs_create_x64(name, mode, parent, (u64 *)value);
371}
372
1da177e4 373#endif