debugfs.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389
  1. /*
  2. * debugfs.h - a tiny little debug file system
  3. *
  4. * Copyright (C) 2004 Greg Kroah-Hartman <greg@kroah.com>
  5. * Copyright (C) 2004 IBM Inc.
  6. *
  7. * This program is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU General Public License version
  9. * 2 as published by the Free Software Foundation.
  10. *
  11. * debugfs is for people to use instead of /proc or /sys.
  12. * See Documentation/DocBook/filesystems for more details.
  13. */
  14. #ifndef _DEBUGFS_H_
  15. #define _DEBUGFS_H_
  16. #include <linux/fs.h>
  17. #include <linux/seq_file.h>
  18. #include <linux/types.h>
  19. #include <linux/compiler.h>
  20. struct device;
  21. struct file_operations;
  22. struct srcu_struct;
  23. struct debugfs_blob_wrapper {
  24. void *data;
  25. unsigned long size;
  26. };
  27. struct debugfs_reg32 {
  28. char *name;
  29. unsigned long offset;
  30. };
  31. struct debugfs_regset32 {
  32. const struct debugfs_reg32 *regs;
  33. int nregs;
  34. void __iomem *base;
  35. };
  36. extern struct dentry *arch_debugfs_dir;
  37. extern struct srcu_struct debugfs_srcu;
  38. /**
  39. * debugfs_real_fops - getter for the real file operation
  40. * @filp: a pointer to a struct file
  41. *
  42. * Must only be called under the protection established by
  43. * debugfs_use_file_start().
  44. */
  45. static inline const struct file_operations *
  46. debugfs_real_fops(const struct file *filp)
  47. __must_hold(&debugfs_srcu)
  48. {
  49. /*
  50. * Neither the pointer to the struct file_operations, nor its
  51. * contents ever change -- srcu_dereference() is not needed here.
  52. */
  53. return filp->f_path.dentry->d_fsdata;
  54. }
  55. #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
  56. static int __fops ## _open(struct inode *inode, struct file *file) \
  57. { \
  58. __simple_attr_check_format(__fmt, 0ull); \
  59. return simple_attr_open(inode, file, __get, __set, __fmt); \
  60. } \
  61. static const struct file_operations __fops = { \
  62. .owner = THIS_MODULE, \
  63. .open = __fops ## _open, \
  64. .release = simple_attr_release, \
  65. .read = debugfs_attr_read, \
  66. .write = debugfs_attr_write, \
  67. .llseek = generic_file_llseek, \
  68. }
  69. #if defined(CONFIG_DEBUG_FS)
  70. struct dentry *debugfs_create_file(const char *name, umode_t mode,
  71. struct dentry *parent, void *data,
  72. const struct file_operations *fops);
  73. struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
  74. struct dentry *parent, void *data,
  75. const struct file_operations *fops);
  76. struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
  77. struct dentry *parent, void *data,
  78. const struct file_operations *fops,
  79. loff_t file_size);
  80. struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
  81. struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
  82. const char *dest);
  83. typedef struct vfsmount *(*debugfs_automount_t)(struct dentry *, void *);
  84. struct dentry *debugfs_create_automount(const char *name,
  85. struct dentry *parent,
  86. debugfs_automount_t f,
  87. void *data);
  88. void debugfs_remove(struct dentry *dentry);
  89. void debugfs_remove_recursive(struct dentry *dentry);
  90. int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx)
  91. __acquires(&debugfs_srcu);
  92. void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu);
  93. ssize_t debugfs_attr_read(struct file *file, char __user *buf,
  94. size_t len, loff_t *ppos);
  95. ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
  96. size_t len, loff_t *ppos);
  97. struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  98. struct dentry *new_dir, const char *new_name);
  99. struct dentry *debugfs_create_u8(const char *name, umode_t mode,
  100. struct dentry *parent, u8 *value);
  101. struct dentry *debugfs_create_u16(const char *name, umode_t mode,
  102. struct dentry *parent, u16 *value);
  103. struct dentry *debugfs_create_u32(const char *name, umode_t mode,
  104. struct dentry *parent, u32 *value);
  105. struct dentry *debugfs_create_u64(const char *name, umode_t mode,
  106. struct dentry *parent, u64 *value);
  107. struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
  108. struct dentry *parent, unsigned long *value);
  109. struct dentry *debugfs_create_x8(const char *name, umode_t mode,
  110. struct dentry *parent, u8 *value);
  111. struct dentry *debugfs_create_x16(const char *name, umode_t mode,
  112. struct dentry *parent, u16 *value);
  113. struct dentry *debugfs_create_x32(const char *name, umode_t mode,
  114. struct dentry *parent, u32 *value);
  115. struct dentry *debugfs_create_x64(const char *name, umode_t mode,
  116. struct dentry *parent, u64 *value);
  117. struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
  118. struct dentry *parent, size_t *value);
  119. struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  120. struct dentry *parent, atomic_t *value);
  121. struct dentry *debugfs_create_bool(const char *name, umode_t mode,
  122. struct dentry *parent, bool *value);
  123. struct dentry *debugfs_create_blob(const char *name, umode_t mode,
  124. struct dentry *parent,
  125. struct debugfs_blob_wrapper *blob);
  126. struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
  127. struct dentry *parent,
  128. struct debugfs_regset32 *regset);
  129. void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
  130. int nregs, void __iomem *base, char *prefix);
  131. struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  132. struct dentry *parent,
  133. u32 *array, u32 elements);
  134. struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
  135. struct dentry *parent,
  136. int (*read_fn)(struct seq_file *s,
  137. void *data));
  138. bool debugfs_initialized(void);
  139. ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
  140. size_t count, loff_t *ppos);
  141. ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
  142. size_t count, loff_t *ppos);
  143. #else
  144. #include <linux/err.h>
  145. /*
  146. * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
  147. * so users have a chance to detect if there was a real error or not. We don't
  148. * want to duplicate the design decision mistakes of procfs and devfs again.
  149. */
  150. static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
  151. struct dentry *parent, void *data,
  152. const struct file_operations *fops)
  153. {
  154. return ERR_PTR(-ENODEV);
  155. }
  156. static inline struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
  157. struct dentry *parent, void *data,
  158. const struct file_operations *fops,
  159. loff_t file_size)
  160. {
  161. return ERR_PTR(-ENODEV);
  162. }
  163. static inline struct dentry *debugfs_create_dir(const char *name,
  164. struct dentry *parent)
  165. {
  166. return ERR_PTR(-ENODEV);
  167. }
  168. static inline struct dentry *debugfs_create_symlink(const char *name,
  169. struct dentry *parent,
  170. const char *dest)
  171. {
  172. return ERR_PTR(-ENODEV);
  173. }
  174. static inline struct dentry *debugfs_create_automount(const char *name,
  175. struct dentry *parent,
  176. struct vfsmount *(*f)(void *),
  177. void *data)
  178. {
  179. return ERR_PTR(-ENODEV);
  180. }
  181. static inline void debugfs_remove(struct dentry *dentry)
  182. { }
  183. static inline void debugfs_remove_recursive(struct dentry *dentry)
  184. { }
  185. static inline int debugfs_use_file_start(const struct dentry *dentry,
  186. int *srcu_idx)
  187. __acquires(&debugfs_srcu)
  188. {
  189. return 0;
  190. }
  191. static inline void debugfs_use_file_finish(int srcu_idx)
  192. __releases(&debugfs_srcu)
  193. { }
  194. static inline ssize_t debugfs_attr_read(struct file *file, char __user *buf,
  195. size_t len, loff_t *ppos)
  196. {
  197. return -ENODEV;
  198. }
  199. static inline ssize_t debugfs_attr_write(struct file *file,
  200. const char __user *buf,
  201. size_t len, loff_t *ppos)
  202. {
  203. return -ENODEV;
  204. }
  205. static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  206. struct dentry *new_dir, char *new_name)
  207. {
  208. return ERR_PTR(-ENODEV);
  209. }
  210. static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
  211. struct dentry *parent,
  212. u8 *value)
  213. {
  214. return ERR_PTR(-ENODEV);
  215. }
  216. static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
  217. struct dentry *parent,
  218. u16 *value)
  219. {
  220. return ERR_PTR(-ENODEV);
  221. }
  222. static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
  223. struct dentry *parent,
  224. u32 *value)
  225. {
  226. return ERR_PTR(-ENODEV);
  227. }
  228. static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
  229. struct dentry *parent,
  230. u64 *value)
  231. {
  232. return ERR_PTR(-ENODEV);
  233. }
  234. static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
  235. struct dentry *parent,
  236. u8 *value)
  237. {
  238. return ERR_PTR(-ENODEV);
  239. }
  240. static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
  241. struct dentry *parent,
  242. u16 *value)
  243. {
  244. return ERR_PTR(-ENODEV);
  245. }
  246. static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
  247. struct dentry *parent,
  248. u32 *value)
  249. {
  250. return ERR_PTR(-ENODEV);
  251. }
  252. static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
  253. struct dentry *parent,
  254. u64 *value)
  255. {
  256. return ERR_PTR(-ENODEV);
  257. }
  258. static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
  259. struct dentry *parent,
  260. size_t *value)
  261. {
  262. return ERR_PTR(-ENODEV);
  263. }
  264. static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  265. struct dentry *parent, atomic_t *value)
  266. {
  267. return ERR_PTR(-ENODEV);
  268. }
  269. static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
  270. struct dentry *parent,
  271. bool *value)
  272. {
  273. return ERR_PTR(-ENODEV);
  274. }
  275. static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
  276. struct dentry *parent,
  277. struct debugfs_blob_wrapper *blob)
  278. {
  279. return ERR_PTR(-ENODEV);
  280. }
  281. static inline struct dentry *debugfs_create_regset32(const char *name,
  282. umode_t mode, struct dentry *parent,
  283. struct debugfs_regset32 *regset)
  284. {
  285. return ERR_PTR(-ENODEV);
  286. }
  287. static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
  288. int nregs, void __iomem *base, char *prefix)
  289. {
  290. }
  291. static inline bool debugfs_initialized(void)
  292. {
  293. return false;
  294. }
  295. static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  296. struct dentry *parent,
  297. u32 *array, u32 elements)
  298. {
  299. return ERR_PTR(-ENODEV);
  300. }
  301. static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
  302. const char *name,
  303. struct dentry *parent,
  304. int (*read_fn)(struct seq_file *s,
  305. void *data))
  306. {
  307. return ERR_PTR(-ENODEV);
  308. }
  309. static inline ssize_t debugfs_read_file_bool(struct file *file,
  310. char __user *user_buf,
  311. size_t count, loff_t *ppos)
  312. {
  313. return -ENODEV;
  314. }
  315. static inline ssize_t debugfs_write_file_bool(struct file *file,
  316. const char __user *user_buf,
  317. size_t count, loff_t *ppos)
  318. {
  319. return -ENODEV;
  320. }
  321. #endif
  322. #endif