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