debug.c 4.7 KB

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