debugfs.h 9.0 KB

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