XenevaOS
Loading...
Searching...
No Matches
debugfs.h
Go to the documentation of this file.
1// SPDX-License-Identifier: GPL-2.0
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 *
8 * debugfs is for people to use instead of /proc or /sys.
9 * See Documentation/filesystems/ for more details.
10 */
11
12#ifndef _DEBUGFS_H_
13#define _DEBUGFS_H_
14
15#include <linux/fs.h>
16#include <linux/seq_file.h>
17
18/*
19 * mainline includes <linux/atomic.h> here and the port dropped it. The include
20 * is load-bearing for debugfs_create_atomic_t() below, whose only parameter is
21 * an atomic_t * -- with the include missing the parameter is an unknown type
22 * name, and because that function is itself only ever an empty stub in this
23 * tree the error surfaces as a parse failure at its declaration rather than
24 * anywhere a caller could have pointed at it.
25 */
26#include <linux/atomic.h>
27
28#include <linux/types.h>
29#include <linux/compiler.h>
30
31struct device;
32struct file_operations;
33
35 void *data;
36 unsigned long size;
37};
38
40 char *name;
41 unsigned long offset;
42};
43
45 const struct debugfs_reg32 *regs;
46 int nregs;
48 struct device *dev; /* Optional device for Runtime PM */
49};
50
55
56extern struct dentry *arch_debugfs_dir;
57
58#define DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, __is_signed) \
59static int __fops ## _open(struct inode *inode, struct file *file) \
60{ \
61 __simple_attr_check_format(__fmt, 0ull); \
62 return simple_attr_open(inode, file, __get, __set, __fmt); \
63} \
64static const struct file_operations __fops = { \
65 .owner = THIS_MODULE, \
66 .open = __fops ## _open, \
67 .release = simple_attr_release, \
68 .read = debugfs_attr_read, \
69 .write = (__is_signed) ? debugfs_attr_write_signed : debugfs_attr_write, \
70}
71
72#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
73 DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, false)
74
75#define DEFINE_DEBUGFS_ATTRIBUTE_SIGNED(__fops, __get, __set, __fmt) \
76 DEFINE_DEBUGFS_ATTRIBUTE_XSIGNED(__fops, __get, __set, __fmt, true)
77
78typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
79
81 ssize_t (*read)(struct file *, char __user *, size_t, loff_t *);
82 ssize_t (*write)(struct file *, const char __user *, size_t, loff_t *);
83 loff_t (*llseek) (struct file *, loff_t, int);
84};
85
86#if defined(CONFIG_DEBUG_FS)
87
88struct dentry *debugfs_lookup(const char *name, struct dentry *parent);
89
90struct dentry *debugfs_create_file_full(const char *name, umode_t mode,
91 struct dentry *parent, void *data,
92 const void *aux,
93 const struct file_operations *fops);
94struct dentry *debugfs_create_file_short(const char *name, umode_t mode,
95 struct dentry *parent, void *data,
96 const void *aux,
97 const struct debugfs_short_fops *fops);
98
135#define debugfs_create_file(name, mode, parent, data, fops) \
136 _Generic(fops, \
137 const struct file_operations *: debugfs_create_file_full, \
138 const struct debugfs_short_fops *: debugfs_create_file_short, \
139 struct file_operations *: debugfs_create_file_full, \
140 struct debugfs_short_fops *: debugfs_create_file_short) \
141 (name, mode, parent, data, NULL, fops)
142
143#define debugfs_create_file_aux(name, mode, parent, data, aux, fops) \
144 _Generic(fops, \
145 const struct file_operations *: debugfs_create_file_full, \
146 const struct debugfs_short_fops *: debugfs_create_file_short, \
147 struct file_operations *: debugfs_create_file_full, \
148 struct debugfs_short_fops *: debugfs_create_file_short) \
149 (name, mode, parent, data, aux, fops)
150
151struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
152 struct dentry *parent, void *data,
153 const struct file_operations *fops);
154
155void debugfs_create_file_size(const char *name, umode_t mode,
156 struct dentry *parent, void *data,
157 const struct file_operations *fops,
158 loff_t file_size);
159
160struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
161
162struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
163 const char *dest);
164
165struct dentry *debugfs_create_automount(const char *name,
166 struct dentry *parent,
168 void *data);
169
170void debugfs_remove(struct dentry *dentry);
171#define debugfs_remove_recursive debugfs_remove
172
173void debugfs_lookup_and_remove(const char *name, struct dentry *parent);
174
175void *debugfs_get_aux(const struct file *file);
176
177int debugfs_file_get(struct dentry *dentry);
178void debugfs_file_put(struct dentry *dentry);
179
180ssize_t debugfs_attr_read(struct file *file, char __user *buf,
181 size_t len, loff_t *ppos);
182ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
183 size_t len, loff_t *ppos);
184ssize_t debugfs_attr_write_signed(struct file *file, const char __user *buf,
185 size_t len, loff_t *ppos);
186
187int debugfs_change_name(struct dentry *dentry, const char *fmt, ...) __printf(2, 3);
188
189void debugfs_create_u8(const char *name, umode_t mode, struct dentry *parent,
190 u8 *value);
191void debugfs_create_u16(const char *name, umode_t mode, struct dentry *parent,
192 u16 *value);
193void debugfs_create_u32(const char *name, umode_t mode, struct dentry *parent,
194 u32 *value);
195void debugfs_create_u64(const char *name, umode_t mode, struct dentry *parent,
196 u64 *value);
197void debugfs_create_ulong(const char *name, umode_t mode, struct dentry *parent,
198 unsigned long *value);
199void debugfs_create_x8(const char *name, umode_t mode, struct dentry *parent,
200 u8 *value);
201void debugfs_create_x16(const char *name, umode_t mode, struct dentry *parent,
202 u16 *value);
203void debugfs_create_x32(const char *name, umode_t mode, struct dentry *parent,
204 u32 *value);
205void debugfs_create_x64(const char *name, umode_t mode, struct dentry *parent,
206 u64 *value);
207void debugfs_create_size_t(const char *name, umode_t mode,
208 struct dentry *parent, size_t *value);
209void debugfs_create_atomic_t(const char *name, umode_t mode,
210 struct dentry *parent, atomic_t *value);
211void debugfs_create_bool(const char *name, umode_t mode, struct dentry *parent,
212 bool *value);
213void debugfs_create_str(const char *name, umode_t mode,
214 struct dentry *parent, char **value);
215
216struct dentry *debugfs_create_blob(const char *name, umode_t mode,
217 struct dentry *parent,
218 struct debugfs_blob_wrapper *blob);
219
220void debugfs_create_regset32(const char *name, umode_t mode,
221 struct dentry *parent,
222 struct debugfs_regset32 *regset);
223
224void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
225 int nregs, void __iomem *base, char *prefix);
226
227void debugfs_create_u32_array(const char *name, umode_t mode,
228 struct dentry *parent,
229 struct debugfs_u32_array *array);
230
231void debugfs_create_devm_seqfile(struct device *dev, const char *name,
232 struct dentry *parent,
233 int (*read_fn)(struct seq_file *s, void *data));
234
235bool debugfs_initialized(void);
236
237ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
238 size_t count, loff_t *ppos);
239
240ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
241 size_t count, loff_t *ppos);
242
243ssize_t debugfs_read_file_str(struct file *file, char __user *user_buf,
244 size_t count, loff_t *ppos);
245
252context_lock_struct(debugfs_cancellation) {
253 struct list_head list;
254 void (*cancel)(struct dentry *, void *);
255 void *cancel_data;
256};
257
258void debugfs_enter_cancellation(struct file *file,
259 struct debugfs_cancellation *cancellation) __acquires(cancellation);
260void debugfs_leave_cancellation(struct file *file,
261 struct debugfs_cancellation *cancellation) __releases(cancellation);
262
263#else
264
265#include <linux/err.h>
266
267/*
268 * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
269 * so users have a chance to detect if there was a real error or not. We don't
270 * want to duplicate the design decision mistakes of procfs and devfs again.
271 */
272
273static inline struct dentry *debugfs_lookup(const char *name,
274 struct dentry *parent)
275{
276 return ERR_PTR(-ENODEV);
277}
278
279static inline struct dentry *debugfs_create_file_aux(const char *name,
280 umode_t mode, struct dentry *parent,
281 void *data, void *aux,
282 const void *fops)
283{
284 return ERR_PTR(-ENODEV);
285}
286
287static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
288 struct dentry *parent, void *data,
289 const void *fops)
290{
291 return ERR_PTR(-ENODEV);
292}
293
294static inline struct dentry *debugfs_create_file_unsafe(const char *name,
295 umode_t mode, struct dentry *parent,
296 void *data,
297 const struct file_operations *fops)
298{
299 return ERR_PTR(-ENODEV);
300}
301
302static inline void debugfs_create_file_size(const char *name, umode_t mode,
303 struct dentry *parent, void *data,
304 const struct file_operations *fops,
305 loff_t file_size)
306{ }
307
308static inline struct dentry *debugfs_create_dir(const char *name,
309 struct dentry *parent)
310{
311 return ERR_PTR(-ENODEV);
312}
313
314static inline struct dentry *debugfs_create_symlink(const char *name,
315 struct dentry *parent,
316 const char *dest)
317{
318 return ERR_PTR(-ENODEV);
319}
320
321static inline struct dentry *debugfs_create_automount(const char *name,
322 struct dentry *parent,
324 void *data)
325{
326 return ERR_PTR(-ENODEV);
327}
328
329static inline void debugfs_remove(struct dentry *dentry)
330{ }
331
332static inline void debugfs_remove_recursive(struct dentry *dentry)
333{ }
334
335static inline void debugfs_lookup_and_remove(const char *name,
336 struct dentry *parent)
337{ }
338
339void *debugfs_get_aux(const struct file *file);
340
341static inline int debugfs_file_get(struct dentry *dentry)
342{
343 return 0;
344}
345
346static inline void debugfs_file_put(struct dentry *dentry)
347{ }
348
349static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf,
350 size_t len, loff_t *ppos)
351{
352 return -ENODEV;
353}
354
355static inline ssize_t debugfs_attr_write(struct file *file,
356 const char __user *buf,
357 size_t len, loff_t *ppos)
358{
359 return -ENODEV;
360}
361
362static inline ssize_t debugfs_attr_write_signed(struct file *file,
363 const char __user *buf,
364 size_t len, loff_t *ppos)
365{
366 return -ENODEV;
367}
368
369static inline int __printf(2, 3) debugfs_change_name(struct dentry *dentry,
370 const char *fmt, ...)
371{
372 return -ENODEV;
373}
374
375static inline void debugfs_create_u8(const char *name, umode_t mode,
376 struct dentry *parent, u8 *value) { }
377
378static inline void debugfs_create_u16(const char *name, umode_t mode,
379 struct dentry *parent, u16 *value) { }
380
381static inline void debugfs_create_u32(const char *name, umode_t mode,
382 struct dentry *parent, u32 *value) { }
383
384static inline void debugfs_create_u64(const char *name, umode_t mode,
385 struct dentry *parent, u64 *value) { }
386
387static inline void debugfs_create_ulong(const char *name, umode_t mode,
388 struct dentry *parent,
389 unsigned long *value) { }
390
391static inline void debugfs_create_x8(const char *name, umode_t mode,
392 struct dentry *parent, u8 *value) { }
393
394static inline void debugfs_create_x16(const char *name, umode_t mode,
395 struct dentry *parent, u16 *value) { }
396
397static inline void debugfs_create_x32(const char *name, umode_t mode,
398 struct dentry *parent, u32 *value) { }
399
400static inline void debugfs_create_x64(const char *name, umode_t mode,
401 struct dentry *parent, u64 *value) { }
402
403static inline void debugfs_create_size_t(const char *name, umode_t mode,
404 struct dentry *parent, size_t *value)
405{ }
406
407static inline void debugfs_create_atomic_t(const char *name, umode_t mode,
408 struct dentry *parent,
409 atomic_t *value)
410{ }
411
412static inline void debugfs_create_bool(const char *name, umode_t mode,
413 struct dentry *parent, bool *value) { }
414
415static inline void debugfs_create_str(const char *name, umode_t mode,
416 struct dentry *parent,
417 char **value)
418{ }
419
420static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
421 struct dentry *parent,
422 struct debugfs_blob_wrapper *blob)
423{
424 return ERR_PTR(-ENODEV);
425}
426
427static inline void debugfs_create_regset32(const char *name, umode_t mode,
428 struct dentry *parent,
429 struct debugfs_regset32 *regset)
430{
431}
432
433static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
434 int nregs, void __iomem *base, char *prefix)
435{
436}
437
438static inline bool debugfs_initialized(void)
439{
440 return false;
441}
442
443static inline void debugfs_create_u32_array(const char *name, umode_t mode,
444 struct dentry *parent,
445 struct debugfs_u32_array *array)
446{
447}
448
449static inline void debugfs_create_devm_seqfile(struct device *dev,
450 const char *name,
451 struct dentry *parent,
452 int (*read_fn)(struct seq_file *s,
453 void *data))
454{
455}
456
457static inline ssize_t debugfs_read_file_bool(struct file *file,
458 char __user *user_buf,
459 size_t count, loff_t *ppos)
460{
461 return -ENODEV;
462}
463
464static inline ssize_t debugfs_write_file_bool(struct file *file,
465 const char __user *user_buf,
466 size_t count, loff_t *ppos)
467{
468 return -ENODEV;
469}
470
471static inline ssize_t debugfs_read_file_str(struct file *file,
472 char __user *user_buf,
473 size_t count, loff_t *ppos)
474{
475 return -ENODEV;
476}
477
478#endif
479
480#define debugfs_create_file_aux_num(name, mode, parent, data, n, fops) \
481 debugfs_create_file_aux(name, mode, parent, data, \
482 (void *)(unsigned long)n, fops)
483#define debugfs_get_aux_num(f) (unsigned long)debugfs_get_aux(f)
484
496static inline void debugfs_create_xul(const char *name, umode_t mode,
497 struct dentry *parent,
498 unsigned long *value)
499{
500 if (sizeof(*value) == sizeof(u32))
501 debugfs_create_x32(name, mode, parent, (u32 *)value);
502 else
503 debugfs_create_x64(name, mode, parent, (u64 *)value);
504}
505
506#endif
int64_t ssize_t
Definition stddef.h:38
uint64_t size_t
Definition stdint.h:104
XEProcessList * list
Definition main.cpp:27
#define ENODEV
Definition acclib.h:197
#define __iomem
Definition aclinux.h:312
#define __acquires(...)
Definition compiler-context-analysis.h:299
#define context_lock_struct(name,...)
Definition compiler-context-analysis.h:188
#define __releases(...)
Definition compiler-context-analysis.h:335
#define __printf(fmt_idx, arg_idx)
Definition compiler.h:144
#define __user
Definition compiler.h:63
struct vfsmount *(* debugfs_automount_t)(struct dentry *, void *)
Definition debugfs.h:78
struct dentry * arch_debugfs_dir
static int const char * fmt
Definition debugfs.h:370
void * debugfs_get_aux(const struct file *file)
struct drm_crtc struct drm_plane struct drm_plane const struct drm_crtc_funcs const char * name
Definition drm_crtc.h:1242
const struct device * dev
Definition drm_print.h:519
const char * f
Definition drm_print.h:205
#define ERR_PTR(err)
Definition err.h:51
struct i915_user_extension base
Definition i915_drm.h:0
size_t len
Definition initial.c:23
struct kobject * parent
Definition kobject.h:91
void * data
Definition kthread.h:30
uint64_t u64
Definition kernel.h:17
uint64_t loff_t
Definition kernel.h:49
uint8_t u8
Definition kernel.h:14
uint16_t u16
Definition kernel.h:15
unsigned int umode_t
Definition kernel.h:58
uint32_t u32
Definition kernel.h:16
Definition atomic.h:31
Definition debugfs.h:34
void * data
Definition debugfs.h:35
unsigned long size
Definition debugfs.h:36
Definition debugfs.h:39
unsigned long offset
Definition debugfs.h:41
char * name
Definition debugfs.h:40
Definition debugfs.h:44
const struct debugfs_reg32 * regs
Definition debugfs.h:45
struct device * dev
Definition debugfs.h:48
int nregs
Definition debugfs.h:46
void __iomem * base
Definition debugfs.h:47
Definition debugfs.h:80
ssize_t(* read)(struct file *, char __user *, size_t, loff_t *)
Definition debugfs.h:81
loff_t(* llseek)(struct file *, loff_t, int)
Definition debugfs.h:83
ssize_t(* write)(struct file *, const char __user *, size_t, loff_t *)
Definition debugfs.h:82
Definition debugfs.h:51
u32 n_elements
Definition debugfs.h:53
u32 * array
Definition debugfs.h:52
Definition fs.h:255
Definition fs.h:67
Definition fs.h:142
Definition list.h:11
Definition seq_file.h:47
Definition mount.h:53
#define mode(x)