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