vchiq_debugfs.c 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. // SPDX-License-Identifier: GPL-2.0 OR BSD-3-Clause
  2. /*
  3. * Copyright (c) 2014 Raspberry Pi (Trading) Ltd. All rights reserved.
  4. * Copyright (c) 2010-2012 Broadcom. All rights reserved.
  5. */
  6. #include <linux/debugfs.h>
  7. #include <linux/raspberrypi/vchiq_core.h>
  8. #include <linux/raspberrypi/vchiq_arm.h>
  9. #include <linux/raspberrypi/vchiq_debugfs.h>
  10. #ifdef CONFIG_DEBUG_FS
  11. #define DEBUGFS_WRITE_BUF_SIZE 256
  12. /* Global 'vchiq' debugfs and clients entry used by all instances */
  13. static struct dentry *vchiq_dbg_dir;
  14. static struct dentry *vchiq_dbg_clients;
  15. static int debugfs_usecount_show(struct seq_file *f, void *offset)
  16. {
  17. struct vchiq_instance *instance = f->private;
  18. int use_count;
  19. use_count = vchiq_instance_get_use_count(instance);
  20. seq_printf(f, "%d\n", use_count);
  21. return 0;
  22. }
  23. DEFINE_SHOW_ATTRIBUTE(debugfs_usecount);
  24. static int debugfs_trace_show(struct seq_file *f, void *offset)
  25. {
  26. struct vchiq_instance *instance = f->private;
  27. int trace;
  28. trace = vchiq_instance_get_trace(instance);
  29. seq_printf(f, "%s\n", trace ? "Y" : "N");
  30. return 0;
  31. }
  32. static int vchiq_dump_show(struct seq_file *f, void *offset)
  33. {
  34. struct vchiq_state *state = f->private;
  35. vchiq_dump_state(f, state);
  36. return 0;
  37. }
  38. DEFINE_SHOW_ATTRIBUTE(vchiq_dump);
  39. static int debugfs_trace_open(struct inode *inode, struct file *file)
  40. {
  41. return single_open(file, debugfs_trace_show, inode->i_private);
  42. }
  43. static ssize_t debugfs_trace_write(struct file *file,
  44. const char __user *buffer,
  45. size_t count, loff_t *ppos)
  46. {
  47. struct seq_file *f = (struct seq_file *)file->private_data;
  48. struct vchiq_instance *instance = f->private;
  49. char firstchar;
  50. if (copy_from_user(&firstchar, buffer, 1))
  51. return -EFAULT;
  52. switch (firstchar) {
  53. case 'Y':
  54. case 'y':
  55. case '1':
  56. vchiq_instance_set_trace(instance, 1);
  57. break;
  58. case 'N':
  59. case 'n':
  60. case '0':
  61. vchiq_instance_set_trace(instance, 0);
  62. break;
  63. default:
  64. break;
  65. }
  66. *ppos += count;
  67. return count;
  68. }
  69. static const struct file_operations debugfs_trace_fops = {
  70. .owner = THIS_MODULE,
  71. .open = debugfs_trace_open,
  72. .write = debugfs_trace_write,
  73. .read = seq_read,
  74. .llseek = seq_lseek,
  75. .release = single_release,
  76. };
  77. /* add an instance (process) to the debugfs entries */
  78. void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
  79. {
  80. char pidstr[16];
  81. struct dentry *top;
  82. snprintf(pidstr, sizeof(pidstr), "%d",
  83. vchiq_instance_get_pid(instance));
  84. top = debugfs_create_dir(pidstr, vchiq_dbg_clients);
  85. debugfs_create_file("use_count", 0444, top, instance,
  86. &debugfs_usecount_fops);
  87. debugfs_create_file("trace", 0644, top, instance, &debugfs_trace_fops);
  88. vchiq_instance_get_debugfs_node(instance)->dentry = top;
  89. }
  90. void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
  91. {
  92. struct vchiq_debugfs_node *node =
  93. vchiq_instance_get_debugfs_node(instance);
  94. debugfs_remove_recursive(node->dentry);
  95. }
  96. void vchiq_debugfs_init(struct vchiq_state *state)
  97. {
  98. vchiq_dbg_dir = debugfs_create_dir("vchiq", NULL);
  99. vchiq_dbg_clients = debugfs_create_dir("clients", vchiq_dbg_dir);
  100. debugfs_create_file("state", S_IFREG | 0444, vchiq_dbg_dir, state,
  101. &vchiq_dump_fops);
  102. }
  103. /* remove all the debugfs entries */
  104. void vchiq_debugfs_deinit(void)
  105. {
  106. debugfs_remove_recursive(vchiq_dbg_dir);
  107. }
  108. #else /* CONFIG_DEBUG_FS */
  109. void vchiq_debugfs_init(struct vchiq_state *state)
  110. {
  111. }
  112. void vchiq_debugfs_deinit(void)
  113. {
  114. }
  115. void vchiq_debugfs_add_instance(struct vchiq_instance *instance)
  116. {
  117. }
  118. void vchiq_debugfs_remove_instance(struct vchiq_instance *instance)
  119. {
  120. }
  121. #endif /* CONFIG_DEBUG_FS */