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