debug.c 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (C) 2010 Google, Inc.
  4. * Author: Erik Gilling <[email protected]>
  5. *
  6. * Copyright (C) 2011-2013 NVIDIA Corporation
  7. */
  8. #include <linux/debugfs.h>
  9. #include <linux/pm_runtime.h>
  10. #include <linux/seq_file.h>
  11. #include <linux/uaccess.h>
  12. #include <linux/io.h>
  13. #include "dev.h"
  14. #include "debug.h"
  15. #include "channel.h"
  16. static DEFINE_MUTEX(debug_lock);
  17. unsigned int host1x_debug_trace_cmdbuf;
  18. static pid_t host1x_debug_force_timeout_pid;
  19. static u32 host1x_debug_force_timeout_val;
  20. static u32 host1x_debug_force_timeout_channel;
  21. void host1x_debug_output(struct output *o, const char *fmt, ...)
  22. {
  23. va_list args;
  24. int len;
  25. va_start(args, fmt);
  26. len = vsnprintf(o->buf, sizeof(o->buf), fmt, args);
  27. va_end(args);
  28. o->fn(o->ctx, o->buf, len, false);
  29. }
  30. void host1x_debug_cont(struct output *o, const char *fmt, ...)
  31. {
  32. va_list args;
  33. int len;
  34. va_start(args, fmt);
  35. len = vsnprintf(o->buf, sizeof(o->buf), fmt, args);
  36. va_end(args);
  37. o->fn(o->ctx, o->buf, len, true);
  38. }
  39. static int show_channel(struct host1x_channel *ch, void *data, bool show_fifo)
  40. {
  41. struct host1x *m = dev_get_drvdata(ch->dev->parent);
  42. struct output *o = data;
  43. int err;
  44. err = pm_runtime_resume_and_get(m->dev);
  45. if (err < 0)
  46. return err;
  47. mutex_lock(&ch->cdma.lock);
  48. mutex_lock(&debug_lock);
  49. if (show_fifo)
  50. host1x_hw_show_channel_fifo(m, ch, o);
  51. host1x_hw_show_channel_cdma(m, ch, o);
  52. mutex_unlock(&debug_lock);
  53. mutex_unlock(&ch->cdma.lock);
  54. pm_runtime_put(m->dev);
  55. return 0;
  56. }
  57. static void show_syncpts(struct host1x *m, struct output *o, bool show_all)
  58. {
  59. struct list_head *pos;
  60. unsigned int i;
  61. int err;
  62. host1x_debug_output(o, "---- syncpts ----\n");
  63. err = pm_runtime_resume_and_get(m->dev);
  64. if (err < 0)
  65. return;
  66. for (i = 0; i < host1x_syncpt_nb_pts(m); i++) {
  67. u32 max = host1x_syncpt_read_max(m->syncpt + i);
  68. u32 min = host1x_syncpt_load(m->syncpt + i);
  69. unsigned int waiters = 0;
  70. spin_lock(&m->syncpt[i].intr.lock);
  71. list_for_each(pos, &m->syncpt[i].intr.wait_head)
  72. waiters++;
  73. spin_unlock(&m->syncpt[i].intr.lock);
  74. if (!kref_read(&m->syncpt[i].ref))
  75. continue;
  76. if (!show_all && !min && !max && !waiters)
  77. continue;
  78. host1x_debug_output(o,
  79. "id %u (%s) min %d max %d (%d waiters)\n",
  80. i, m->syncpt[i].name, min, max, waiters);
  81. }
  82. for (i = 0; i < host1x_syncpt_nb_bases(m); i++) {
  83. u32 base_val;
  84. base_val = host1x_syncpt_load_wait_base(m->syncpt + i);
  85. if (base_val)
  86. host1x_debug_output(o, "waitbase id %u val %d\n", i,
  87. base_val);
  88. }
  89. pm_runtime_put(m->dev);
  90. host1x_debug_output(o, "\n");
  91. }
  92. static void show_all(struct host1x *m, struct output *o, bool show_fifo)
  93. {
  94. unsigned int i;
  95. host1x_hw_show_mlocks(m, o);
  96. show_syncpts(m, o, true);
  97. host1x_debug_output(o, "---- channels ----\n");
  98. for (i = 0; i < m->info->nb_channels; ++i) {
  99. struct host1x_channel *ch = host1x_channel_get_index(m, i);
  100. if (ch) {
  101. show_channel(ch, o, show_fifo);
  102. host1x_channel_put(ch);
  103. }
  104. }
  105. }
  106. static int host1x_debug_show_all(struct seq_file *s, void *unused)
  107. {
  108. struct output o = {
  109. .fn = write_to_seqfile,
  110. .ctx = s
  111. };
  112. show_all(s->private, &o, true);
  113. return 0;
  114. }
  115. static int host1x_debug_show(struct seq_file *s, void *unused)
  116. {
  117. struct output o = {
  118. .fn = write_to_seqfile,
  119. .ctx = s
  120. };
  121. show_all(s->private, &o, false);
  122. return 0;
  123. }
  124. static int host1x_debug_open_all(struct inode *inode, struct file *file)
  125. {
  126. return single_open(file, host1x_debug_show_all, inode->i_private);
  127. }
  128. static const struct file_operations host1x_debug_all_fops = {
  129. .open = host1x_debug_open_all,
  130. .read = seq_read,
  131. .llseek = seq_lseek,
  132. .release = single_release,
  133. };
  134. static int host1x_debug_open(struct inode *inode, struct file *file)
  135. {
  136. return single_open(file, host1x_debug_show, inode->i_private);
  137. }
  138. static const struct file_operations host1x_debug_fops = {
  139. .open = host1x_debug_open,
  140. .read = seq_read,
  141. .llseek = seq_lseek,
  142. .release = single_release,
  143. };
  144. static void host1x_debugfs_init(struct host1x *host1x)
  145. {
  146. struct dentry *de = debugfs_create_dir("tegra-host1x", NULL);
  147. /* Store the created entry */
  148. host1x->debugfs = de;
  149. debugfs_create_file("status", S_IRUGO, de, host1x, &host1x_debug_fops);
  150. debugfs_create_file("status_all", S_IRUGO, de, host1x,
  151. &host1x_debug_all_fops);
  152. debugfs_create_u32("trace_cmdbuf", S_IRUGO|S_IWUSR, de,
  153. &host1x_debug_trace_cmdbuf);
  154. host1x_hw_debug_init(host1x, de);
  155. debugfs_create_u32("force_timeout_pid", S_IRUGO|S_IWUSR, de,
  156. &host1x_debug_force_timeout_pid);
  157. debugfs_create_u32("force_timeout_val", S_IRUGO|S_IWUSR, de,
  158. &host1x_debug_force_timeout_val);
  159. debugfs_create_u32("force_timeout_channel", S_IRUGO|S_IWUSR, de,
  160. &host1x_debug_force_timeout_channel);
  161. }
  162. static void host1x_debugfs_exit(struct host1x *host1x)
  163. {
  164. debugfs_remove_recursive(host1x->debugfs);
  165. }
  166. void host1x_debug_init(struct host1x *host1x)
  167. {
  168. if (IS_ENABLED(CONFIG_DEBUG_FS))
  169. host1x_debugfs_init(host1x);
  170. }
  171. void host1x_debug_deinit(struct host1x *host1x)
  172. {
  173. if (IS_ENABLED(CONFIG_DEBUG_FS))
  174. host1x_debugfs_exit(host1x);
  175. }
  176. void host1x_debug_dump(struct host1x *host1x)
  177. {
  178. struct output o = {
  179. .fn = write_to_printk
  180. };
  181. show_all(host1x, &o, true);
  182. }
  183. void host1x_debug_dump_syncpts(struct host1x *host1x)
  184. {
  185. struct output o = {
  186. .fn = write_to_printk
  187. };
  188. show_syncpts(host1x, &o, false);
  189. }