debugfs.h 11 KB

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