debugfs.h 8.4 KB

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