debug.c 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. /*
  2. * Copyright (C) 2010 Google, Inc.
  3. * Author: Erik Gilling <konkers@android.com>
  4. *
  5. * Copyright (C) 2011-2013 NVIDIA Corporation
  6. *
  7. * This software is licensed under the terms of the GNU General Public
  8. * License version 2, as published by the Free Software Foundation, and
  9. * may be copied, distributed, and modified under those terms.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. */
  17. #include <linux/debugfs.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/uaccess.h>
  20. #include <linux/io.h>
  21. #include "dev.h"
  22. #include "debug.h"
  23. #include "channel.h"
  24. unsigned int host1x_debug_trace_cmdbuf;
  25. static pid_t host1x_debug_force_timeout_pid;
  26. static u32 host1x_debug_force_timeout_val;
  27. static u32 host1x_debug_force_timeout_channel;
  28. void host1x_debug_output(struct output *o, const char *fmt, ...)
  29. {
  30. va_list args;
  31. int len;
  32. va_start(args, fmt);
  33. len = vsnprintf(o->buf, sizeof(o->buf), fmt, args);
  34. va_end(args);
  35. o->fn(o->ctx, o->buf, len);
  36. }
  37. static int show_channels(struct host1x_channel *ch, void *data, bool show_fifo)
  38. {
  39. struct host1x *m = dev_get_drvdata(ch->dev->parent);
  40. struct output *o = data;
  41. mutex_lock(&ch->reflock);
  42. if (ch->refcount) {
  43. mutex_lock(&ch->cdma.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(&ch->cdma.lock);
  48. }
  49. mutex_unlock(&ch->reflock);
  50. return 0;
  51. }
  52. static void show_syncpts(struct host1x *m, struct output *o)
  53. {
  54. int i;
  55. host1x_debug_output(o, "---- syncpts ----\n");
  56. for (i = 0; i < host1x_syncpt_nb_pts(m); i++) {
  57. u32 max = host1x_syncpt_read_max(m->syncpt + i);
  58. u32 min = host1x_syncpt_load(m->syncpt + i);
  59. if (!min && !max)
  60. continue;
  61. host1x_debug_output(o, "id %d (%s) min %d max %d\n",
  62. i, m->syncpt[i].name, min, max);
  63. }
  64. for (i = 0; i < host1x_syncpt_nb_bases(m); i++) {
  65. u32 base_val;
  66. base_val = host1x_syncpt_load_wait_base(m->syncpt + i);
  67. if (base_val)
  68. host1x_debug_output(o, "waitbase id %d val %d\n", i,
  69. base_val);
  70. }
  71. host1x_debug_output(o, "\n");
  72. }
  73. static void show_all(struct host1x *m, struct output *o)
  74. {
  75. struct host1x_channel *ch;
  76. host1x_hw_show_mlocks(m, o);
  77. show_syncpts(m, o);
  78. host1x_debug_output(o, "---- channels ----\n");
  79. host1x_for_each_channel(m, ch)
  80. show_channels(ch, o, true);
  81. }
  82. #ifdef CONFIG_DEBUG_FS
  83. static void show_all_no_fifo(struct host1x *host1x, struct output *o)
  84. {
  85. struct host1x_channel *ch;
  86. host1x_hw_show_mlocks(host1x, o);
  87. show_syncpts(host1x, o);
  88. host1x_debug_output(o, "---- channels ----\n");
  89. host1x_for_each_channel(host1x, ch)
  90. show_channels(ch, o, false);
  91. }
  92. static int host1x_debug_show_all(struct seq_file *s, void *unused)
  93. {
  94. struct output o = {
  95. .fn = write_to_seqfile,
  96. .ctx = s
  97. };
  98. show_all(s->private, &o);
  99. return 0;
  100. }
  101. static int host1x_debug_show(struct seq_file *s, void *unused)
  102. {
  103. struct output o = {
  104. .fn = write_to_seqfile,
  105. .ctx = s
  106. };
  107. show_all_no_fifo(s->private, &o);
  108. return 0;
  109. }
  110. static int host1x_debug_open_all(struct inode *inode, struct file *file)
  111. {
  112. return single_open(file, host1x_debug_show_all, inode->i_private);
  113. }
  114. static const struct file_operations host1x_debug_all_fops = {
  115. .open = host1x_debug_open_all,
  116. .read = seq_read,
  117. .llseek = seq_lseek,
  118. .release = single_release,
  119. };
  120. static int host1x_debug_open(struct inode *inode, struct file *file)
  121. {
  122. return single_open(file, host1x_debug_show, inode->i_private);
  123. }
  124. static const struct file_operations host1x_debug_fops = {
  125. .open = host1x_debug_open,
  126. .read = seq_read,
  127. .llseek = seq_lseek,
  128. .release = single_release,
  129. };
  130. void host1x_debug_init(struct host1x *host1x)
  131. {
  132. struct dentry *de = debugfs_create_dir("tegra-host1x", NULL);
  133. if (!de)
  134. return;
  135. /* Store the created entry */
  136. host1x->debugfs = de;
  137. debugfs_create_file("status", S_IRUGO, de, host1x, &host1x_debug_fops);
  138. debugfs_create_file("status_all", S_IRUGO, de, host1x,
  139. &host1x_debug_all_fops);
  140. debugfs_create_u32("trace_cmdbuf", S_IRUGO|S_IWUSR, de,
  141. &host1x_debug_trace_cmdbuf);
  142. host1x_hw_debug_init(host1x, de);
  143. debugfs_create_u32("force_timeout_pid", S_IRUGO|S_IWUSR, de,
  144. &host1x_debug_force_timeout_pid);
  145. debugfs_create_u32("force_timeout_val", S_IRUGO|S_IWUSR, de,
  146. &host1x_debug_force_timeout_val);
  147. debugfs_create_u32("force_timeout_channel", S_IRUGO|S_IWUSR, de,
  148. &host1x_debug_force_timeout_channel);
  149. }
  150. void host1x_debug_deinit(struct host1x *host1x)
  151. {
  152. debugfs_remove_recursive(host1x->debugfs);
  153. }
  154. #else
  155. void host1x_debug_init(struct host1x *host1x)
  156. {
  157. }
  158. void host1x_debug_deinit(struct host1x *host1x)
  159. {
  160. }
  161. #endif
  162. void host1x_debug_dump(struct host1x *host1x)
  163. {
  164. struct output o = {
  165. .fn = write_to_printk
  166. };
  167. show_all(host1x, &o);
  168. }
  169. void host1x_debug_dump_syncpts(struct host1x *host1x)
  170. {
  171. struct output o = {
  172. .fn = write_to_printk
  173. };
  174. show_syncpts(host1x, &o);
  175. }