debugfs.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  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. #if defined(CONFIG_DEBUG_FS)
  56. struct dentry *debugfs_create_file(const char *name, umode_t mode,
  57. struct dentry *parent, void *data,
  58. const struct file_operations *fops);
  59. struct dentry *debugfs_create_file_unsafe(const char *name, umode_t mode,
  60. struct dentry *parent, void *data,
  61. const struct file_operations *fops);
  62. struct dentry *debugfs_create_file_size(const char *name, umode_t mode,
  63. struct dentry *parent, void *data,
  64. const struct file_operations *fops,
  65. loff_t file_size);
  66. struct dentry *debugfs_create_dir(const char *name, struct dentry *parent);
  67. struct dentry *debugfs_create_symlink(const char *name, struct dentry *parent,
  68. const char *dest);
  69. struct dentry *debugfs_create_automount(const char *name,
  70. struct dentry *parent,
  71. struct vfsmount *(*f)(void *),
  72. void *data);
  73. void debugfs_remove(struct dentry *dentry);
  74. void debugfs_remove_recursive(struct dentry *dentry);
  75. int debugfs_use_file_start(const struct dentry *dentry, int *srcu_idx)
  76. __acquires(&debugfs_srcu);
  77. void debugfs_use_file_finish(int srcu_idx) __releases(&debugfs_srcu);
  78. ssize_t debugfs_attr_read(struct file *file, char __user *buf,
  79. size_t len, loff_t *ppos);
  80. ssize_t debugfs_attr_write(struct file *file, const char __user *buf,
  81. size_t len, loff_t *ppos);
  82. #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
  83. static int __fops ## _open(struct inode *inode, struct file *file) \
  84. { \
  85. __simple_attr_check_format(__fmt, 0ull); \
  86. return simple_attr_open(inode, file, __get, __set, __fmt); \
  87. } \
  88. static const struct file_operations __fops = { \
  89. .owner = THIS_MODULE, \
  90. .open = __fops ## _open, \
  91. .release = simple_attr_release, \
  92. .read = debugfs_attr_read, \
  93. .write = debugfs_attr_write, \
  94. .llseek = generic_file_llseek, \
  95. }
  96. struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  97. struct dentry *new_dir, const char *new_name);
  98. struct dentry *debugfs_create_u8(const char *name, umode_t mode,
  99. struct dentry *parent, u8 *value);
  100. struct dentry *debugfs_create_u16(const char *name, umode_t mode,
  101. struct dentry *parent, u16 *value);
  102. struct dentry *debugfs_create_u32(const char *name, umode_t mode,
  103. struct dentry *parent, u32 *value);
  104. struct dentry *debugfs_create_u64(const char *name, umode_t mode,
  105. struct dentry *parent, u64 *value);
  106. struct dentry *debugfs_create_ulong(const char *name, umode_t mode,
  107. struct dentry *parent, unsigned long *value);
  108. struct dentry *debugfs_create_x8(const char *name, umode_t mode,
  109. struct dentry *parent, u8 *value);
  110. struct dentry *debugfs_create_x16(const char *name, umode_t mode,
  111. struct dentry *parent, u16 *value);
  112. struct dentry *debugfs_create_x32(const char *name, umode_t mode,
  113. struct dentry *parent, u32 *value);
  114. struct dentry *debugfs_create_x64(const char *name, umode_t mode,
  115. struct dentry *parent, u64 *value);
  116. struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
  117. struct dentry *parent, size_t *value);
  118. struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  119. struct dentry *parent, atomic_t *value);
  120. struct dentry *debugfs_create_bool(const char *name, umode_t mode,
  121. struct dentry *parent, bool *value);
  122. struct dentry *debugfs_create_blob(const char *name, umode_t mode,
  123. struct dentry *parent,
  124. struct debugfs_blob_wrapper *blob);
  125. struct dentry *debugfs_create_regset32(const char *name, umode_t mode,
  126. struct dentry *parent,
  127. struct debugfs_regset32 *regset);
  128. void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
  129. int nregs, void __iomem *base, char *prefix);
  130. struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  131. struct dentry *parent,
  132. u32 *array, u32 elements);
  133. struct dentry *debugfs_create_devm_seqfile(struct device *dev, const char *name,
  134. struct dentry *parent,
  135. int (*read_fn)(struct seq_file *s,
  136. void *data));
  137. bool debugfs_initialized(void);
  138. ssize_t debugfs_read_file_bool(struct file *file, char __user *user_buf,
  139. size_t count, loff_t *ppos);
  140. ssize_t debugfs_write_file_bool(struct file *file, const char __user *user_buf,
  141. size_t count, loff_t *ppos);
  142. #else
  143. #include <linux/err.h>
  144. /*
  145. * We do not return NULL from these functions if CONFIG_DEBUG_FS is not enabled
  146. * so users have a chance to detect if there was a real error or not. We don't
  147. * want to duplicate the design decision mistakes of procfs and devfs again.
  148. */
  149. static inline struct dentry *debugfs_create_file(const char *name, umode_t mode,
  150. struct dentry *parent, void *data,
  151. const struct file_operations *fops)
  152. {
  153. return ERR_PTR(-ENODEV);
  154. }
  155. static inline struct dentry *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. {
  160. return ERR_PTR(-ENODEV);
  161. }
  162. static inline struct dentry *debugfs_create_dir(const char *name,
  163. struct dentry *parent)
  164. {
  165. return ERR_PTR(-ENODEV);
  166. }
  167. static inline struct dentry *debugfs_create_symlink(const char *name,
  168. struct dentry *parent,
  169. const char *dest)
  170. {
  171. return ERR_PTR(-ENODEV);
  172. }
  173. static inline struct dentry *debugfs_create_automount(const char *name,
  174. struct dentry *parent,
  175. struct vfsmount *(*f)(void *),
  176. void *data)
  177. {
  178. return ERR_PTR(-ENODEV);
  179. }
  180. static inline void debugfs_remove(struct dentry *dentry)
  181. { }
  182. static inline void debugfs_remove_recursive(struct dentry *dentry)
  183. { }
  184. static inline int debugfs_use_file_start(const struct dentry *dentry,
  185. int *srcu_idx)
  186. __acquires(&debugfs_srcu)
  187. {
  188. return 0;
  189. }
  190. static inline void debugfs_use_file_finish(int srcu_idx)
  191. __releases(&debugfs_srcu)
  192. { }
  193. #define DEFINE_DEBUGFS_ATTRIBUTE(__fops, __get, __set, __fmt) \
  194. static const struct file_operations __fops = { 0 }
  195. static inline struct dentry *debugfs_rename(struct dentry *old_dir, struct dentry *old_dentry,
  196. struct dentry *new_dir, char *new_name)
  197. {
  198. return ERR_PTR(-ENODEV);
  199. }
  200. static inline struct dentry *debugfs_create_u8(const char *name, umode_t mode,
  201. struct dentry *parent,
  202. u8 *value)
  203. {
  204. return ERR_PTR(-ENODEV);
  205. }
  206. static inline struct dentry *debugfs_create_u16(const char *name, umode_t mode,
  207. struct dentry *parent,
  208. u16 *value)
  209. {
  210. return ERR_PTR(-ENODEV);
  211. }
  212. static inline struct dentry *debugfs_create_u32(const char *name, umode_t mode,
  213. struct dentry *parent,
  214. u32 *value)
  215. {
  216. return ERR_PTR(-ENODEV);
  217. }
  218. static inline struct dentry *debugfs_create_u64(const char *name, umode_t mode,
  219. struct dentry *parent,
  220. u64 *value)
  221. {
  222. return ERR_PTR(-ENODEV);
  223. }
  224. static inline struct dentry *debugfs_create_x8(const char *name, umode_t mode,
  225. struct dentry *parent,
  226. u8 *value)
  227. {
  228. return ERR_PTR(-ENODEV);
  229. }
  230. static inline struct dentry *debugfs_create_x16(const char *name, umode_t mode,
  231. struct dentry *parent,
  232. u16 *value)
  233. {
  234. return ERR_PTR(-ENODEV);
  235. }
  236. static inline struct dentry *debugfs_create_x32(const char *name, umode_t mode,
  237. struct dentry *parent,
  238. u32 *value)
  239. {
  240. return ERR_PTR(-ENODEV);
  241. }
  242. static inline struct dentry *debugfs_create_x64(const char *name, umode_t mode,
  243. struct dentry *parent,
  244. u64 *value)
  245. {
  246. return ERR_PTR(-ENODEV);
  247. }
  248. static inline struct dentry *debugfs_create_size_t(const char *name, umode_t mode,
  249. struct dentry *parent,
  250. size_t *value)
  251. {
  252. return ERR_PTR(-ENODEV);
  253. }
  254. static inline struct dentry *debugfs_create_atomic_t(const char *name, umode_t mode,
  255. struct dentry *parent, atomic_t *value)
  256. {
  257. return ERR_PTR(-ENODEV);
  258. }
  259. static inline struct dentry *debugfs_create_bool(const char *name, umode_t mode,
  260. struct dentry *parent,
  261. bool *value)
  262. {
  263. return ERR_PTR(-ENODEV);
  264. }
  265. static inline struct dentry *debugfs_create_blob(const char *name, umode_t mode,
  266. struct dentry *parent,
  267. struct debugfs_blob_wrapper *blob)
  268. {
  269. return ERR_PTR(-ENODEV);
  270. }
  271. static inline struct dentry *debugfs_create_regset32(const char *name,
  272. umode_t mode, struct dentry *parent,
  273. struct debugfs_regset32 *regset)
  274. {
  275. return ERR_PTR(-ENODEV);
  276. }
  277. static inline void debugfs_print_regs32(struct seq_file *s, const struct debugfs_reg32 *regs,
  278. int nregs, void __iomem *base, char *prefix)
  279. {
  280. }
  281. static inline bool debugfs_initialized(void)
  282. {
  283. return false;
  284. }
  285. static inline struct dentry *debugfs_create_u32_array(const char *name, umode_t mode,
  286. struct dentry *parent,
  287. u32 *array, u32 elements)
  288. {
  289. return ERR_PTR(-ENODEV);
  290. }
  291. static inline struct dentry *debugfs_create_devm_seqfile(struct device *dev,
  292. const char *name,
  293. struct dentry *parent,
  294. int (*read_fn)(struct seq_file *s,
  295. void *data))
  296. {
  297. return ERR_PTR(-ENODEV);
  298. }
  299. static inline ssize_t debugfs_read_file_bool(struct file *file,
  300. char __user *user_buf,
  301. size_t count, loff_t *ppos)
  302. {
  303. return -ENODEV;
  304. }
  305. static inline ssize_t debugfs_write_file_bool(struct file *file,
  306. const char __user *user_buf,
  307. size_t count, loff_t *ppos)
  308. {
  309. return -ENODEV;
  310. }
  311. #endif
  312. #endif