debugfs.h 10.5 KB
Newer Older
1
// SPDX-License-Identifier: GPL-2.0
Linus Torvalds's avatar
Linus Torvalds committed
2 3 4 5 6 7 8
/*
 *  debugfs.h - a tiny little debug file system
 *
 *  Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
 *  Copyright (C) 2004 IBM Inc.
 *
 *  debugfs is for people to use instead of /proc or /sys.
9
 *  See Documentation/filesystems/ for more details.
Linus Torvalds's avatar
Linus Torvalds committed
10 11 12 13 14 15
 */

#ifndef _DEBUGFS_H_
#define _DEBUGFS_H_

#include <linux/fs.h>
16
#include <linux/seq_file.h>
Linus Torvalds's avatar
Linus Torvalds committed
17

18
#include <linux/types.h>
19
#include <linux/compiler.h>
20

21
struct device;
22 23
struct file_operations;

24 25 26 27 28
struct debugfs_blob_wrapper {
	void *data;
	unsigned long size;
};

29 30 31 32 33 34
struct debugfs_reg32 {
	char *name;
	unsigned long offset;
};

struct debugfs_regset32 {
35
	const struct debugfs_reg32 *regs;
36 37 38 39
	int nregs;
	void __iomem *base;
};

40 41
extern struct dentry *arch_debugfs_dir;

42 43 44 45 46 47 48 49 50 51 52 53
#define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt)		\
static int __fops ## _open(struct inode *inode, struct file *file)	\
{									\
	__simple_attr_check_format(__fmt, 0ull);			\
	return simple_attr_open(inode, file, __get, __set, __fmt);	\
}									\
static const struct file_operations __fops = {				\
	.owner	 = THIS_MODULE,						\
	.open	 = __fops ## _open,					\
	.release = simple_attr_release,					\
	.read	 = debugfs_attr_read,					\
	.write	 = debugfs_attr_write,					\
54
	.llseek  = no_llseek,						\
55 56
}

Linus Torvalds's avatar
Linus Torvalds committed
57
#if defined(CONFIG_DEBUG_FS)
58

59 60
struct dentry *debugfs_lookup(const char *name, struct dentry *parent);

Al Viro's avatar
Al Viro committed
61
struct dentry *debugfs_create_file(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
62
				   struct dentry *parent, void *data,
63
				   const struct file_operations *fops);
64 65 66
struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
				   struct dentry *parent, void *data,
				   const struct file_operations *fops);
Linus Torvalds's avatar
Linus Torvalds committed
67

68 69 70 71 72
struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
					struct dentry *parent, void *data,
					const struct file_operations *fops,
					loff_t file_size);

Linus Torvalds's avatar
Linus Torvalds committed
73 74
struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);

75 76 77
struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
				      const char *dest);

78
typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
79 80
struct dentry *debugfs_create_automount(const char *name,
					struct dentry *parent,
81
					debugfs_automount_t f,
82 83
					void *data);

Linus Torvalds's avatar
Linus Torvalds committed
84
void debugfs_remove(struct dentry *dentry);
85
void debugfs_remove_recursive(struct dentry *dentry);
Linus Torvalds's avatar
Linus Torvalds committed
86

87
const struct file_operations *debugfs_real_fops(const struct file *filp);
88

89 90 91
int debugfs_file_get(struct dentry *dentry);
void debugfs_file_put(struct dentry *dentry);

92 93 94 95 96
ssize_t debugfs_attr_read(struct file *file, char __user *buf,
			size_t len, loff_t *ppos);
ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
			size_t len, loff_t *ppos);

97 98 99
struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
                struct dentry *new_dir, const char *new_name);

Al Viro's avatar
Al Viro committed
100
struct dentry *debugfs_create_u8(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
101
				 struct dentry *parent, u8 *value);
Al Viro's avatar
Al Viro committed
102
struct dentry *debugfs_create_u16(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
103
				  struct dentry *parent, u16 *value);
Al Viro's avatar
Al Viro committed
104
struct dentry *debugfs_create_u32(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
105
				  struct dentry *parent, u32 *value);
Al Viro's avatar
Al Viro committed
106
struct dentry *debugfs_create_u64(const char *name, umode_t mode,
107
				  struct dentry *parent, u64 *value);
108 109
struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
				    struct dentry *parent, unsigned long *value);
Al Viro's avatar
Al Viro committed
110
struct dentry *debugfs_create_x8(const char *name, umode_t mode,
111
				 struct dentry *parent, u8 *value);
Al Viro's avatar
Al Viro committed
112
struct dentry *debugfs_create_x16(const char *name, umode_t mode,
113
				  struct dentry *parent, u16 *value);
Al Viro's avatar
Al Viro committed
114
struct dentry *debugfs_create_x32(const char *name, umode_t mode,
115
				  struct dentry *parent, u32 *value);
Al Viro's avatar
Al Viro committed
116
struct dentry *debugfs_create_x64(const char *name, umode_t mode,
Huang Ying's avatar
Huang Ying committed
117
				  struct dentry *parent, u64 *value);
Al Viro's avatar
Al Viro committed
118
struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
119
				     struct dentry *parent, size_t *value);
120 121
struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
				     struct dentry *parent, atomic_t *value);
Al Viro's avatar
Al Viro committed
122
struct dentry *debugfs_create_bool(const char *name, umode_t mode,
123
				  struct dentry *parent, bool *value);
Linus Torvalds's avatar
Linus Torvalds committed
124

Al Viro's avatar
Al Viro committed
125
struct dentry *debugfs_create_blob(const char *name, umode_t mode,
126 127
				  struct dentry *parent,
				  struct debugfs_blob_wrapper *blob);
128

129
struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
130 131 132
				     struct dentry *parent,
				     struct debugfs_regset32 *regset);

133 134
void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
			  int nregs, void __iomem *base, char *prefix);
135

136 137 138 139
struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
					struct dentry *parent,
					u32 *array, u32 elements);

140 141 142 143 144
struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
					   struct dentry *parent,
					   int (*read_fn)(struct seq_file *s,
							  void *data));

145 146
bool debugfs_initialized(void);

147 148 149 150 151 152
ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
			       size_t count, loff_t *ppos);

ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
				size_t count, loff_t *ppos);

Linus Torvalds's avatar
Linus Torvalds committed
153
#else
154 155 156

#include <linux/err.h>

157
/*
Linus Torvalds's avatar
Linus Torvalds committed
158 159 160 161 162
 * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
 * so users have a chance to detect if there was a real error or not.  We don't
 * want to duplicate the design decision mistakes of procfs and devfs again.
 */

163 164 165 166 167 168
static inline struct dentry *debugfs_lookup(const char *name,
					    struct dentry *parent)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
169
static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
170 171
					struct dentry *parent, void *data,
					const struct file_operations *fops)
Linus Torvalds's avatar
Linus Torvalds committed
172 173 174 175
{
	return ERR_PTR(-ENODEV);
}

176 177 178 179 180 181 182 183
static inline struct dentry *debugfs_create_file_unsafe(const char *name,
					umode_t mode, struct dentry *parent,
					void *data,
					const struct file_operations *fops)
{
	return ERR_PTR(-ENODEV);
}

184 185 186 187 188 189 190 191
static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
					struct dentry *parent, void *data,
					const struct file_operations *fops,
					loff_t file_size)
{
	return ERR_PTR(-ENODEV);
}

Linus Torvalds's avatar
Linus Torvalds committed
192 193 194 195 196 197
static inline struct dentry *debugfs_create_dir(const char *name,
						struct dentry *parent)
{
	return ERR_PTR(-ENODEV);
}

198 199 200 201 202 203 204
static inline struct dentry *debugfs_create_symlink(const char *name,
						    struct dentry *parent,
						    const char *dest)
{
	return ERR_PTR(-ENODEV);
}

205 206 207 208 209 210 211 212
static inline struct dentry *debugfs_create_automount(const char *name,
					struct dentry *parent,
					struct vfsmount *(*f)(void *),
					void *data)
{
	return ERR_PTR(-ENODEV);
}

Linus Torvalds's avatar
Linus Torvalds committed
213 214 215
static inline void debugfs_remove(struct dentry *dentry)
{ }

216 217 218
static inline void debugfs_remove_recursive(struct dentry *dentry)
{ }

219 220
const struct file_operations *debugfs_real_fops(const struct file *filp);

221 222 223 224 225 226 227 228
static inline int debugfs_file_get(struct dentry *dentry)
{
	return 0;
}

static inline void debugfs_file_put(struct dentry *dentry)
{ }

229 230 231 232 233 234 235 236 237 238 239 240
static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf,
					size_t len, loff_t *ppos)
{
	return -ENODEV;
}

static inline ssize_t debugfs_attr_write(struct file *file,
					const char __user *buf,
					size_t len, loff_t *ppos)
{
	return -ENODEV;
}
241

242 243 244 245 246 247
static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
                struct dentry *new_dir, char *new_name)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
248
static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
249 250 251 252 253 254
					       struct dentry *parent,
					       u8 *value)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
255
static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
256
						struct dentry *parent,
257
						u16 *value)
Linus Torvalds's avatar
Linus Torvalds committed
258 259 260 261
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
262
static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
263
						struct dentry *parent,
264
						u32 *value)
Linus Torvalds's avatar
Linus Torvalds committed
265 266 267 268
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
269
static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
270 271 272 273 274 275
						struct dentry *parent,
						u64 *value)
{
	return ERR_PTR(-ENODEV);
}

276 277 278 279 280 281 282 283
static inline struct dentry *debugfs_create_ulong(const char *name,
						umode_t mode,
						struct dentry *parent,
						unsigned long *value)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
284
static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
285 286 287 288 289 290
					       struct dentry *parent,
					       u8 *value)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
291
static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
292 293 294 295 296 297
						struct dentry *parent,
						u16 *value)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
298
static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
299 300 301 302 303 304
						struct dentry *parent,
						u32 *value)
{
	return ERR_PTR(-ENODEV);
}

305 306 307 308 309 310 311
static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
						struct dentry *parent,
						u64 *value)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
312
static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
313 314 315 316 317 318
				     struct dentry *parent,
				     size_t *value)
{
	return ERR_PTR(-ENODEV);
}

319 320 321 322 323 324
static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
				     struct dentry *parent, atomic_t *value)
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
325
static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
Linus Torvalds's avatar
Linus Torvalds committed
326
						 struct dentry *parent,
327
						 bool *value)
Linus Torvalds's avatar
Linus Torvalds committed
328 329 330 331
{
	return ERR_PTR(-ENODEV);
}

Al Viro's avatar
Al Viro committed
332
static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
333 334 335 336 337 338
				  struct dentry *parent,
				  struct debugfs_blob_wrapper *blob)
{
	return ERR_PTR(-ENODEV);
}

339
static inline struct dentry *debugfs_create_regset32(const char *name,
340
				   umode_t mode, struct dentry *parent,
341 342 343 344 345
				   struct debugfs_regset32 *regset)
{
	return ERR_PTR(-ENODEV);
}

346
static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
347 348 349 350
			 int nregs, void __iomem *base, char *prefix)
{
}

351 352 353 354 355
static inline bool debugfs_initialized(void)
{
	return false;
}

356 357 358 359 360 361 362
static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
					struct dentry *parent,
					u32 *array, u32 elements)
{
	return ERR_PTR(-ENODEV);
}

363 364 365 366 367 368 369 370 371
static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
							 const char *name,
							 struct dentry *parent,
					   int (*read_fn)(struct seq_file *s,
							  void *data))
{
	return ERR_PTR(-ENODEV);
}

372 373 374 375 376 377 378 379 380 381 382 383 384 385
static inline ssize_t debugfs_read_file_bool(struct file *file,
					     char __user *user_buf,
					     size_t count, loff_t *ppos)
{
	return -ENODEV;
}

static inline ssize_t debugfs_write_file_bool(struct file *file,
					      const char __user *user_buf,
					      size_t count, loff_t *ppos)
{
	return -ENODEV;
}

Linus Torvalds's avatar
Linus Torvalds committed
386 387 388
#endif

#endif