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