debug.c 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218
  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/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. unsigned long irqflags;
  60. struct list_head *pos;
  61. unsigned int i;
  62. int err;
  63. host1x_debug_output(o, "---- syncpts ----\n");
  64. err = pm_runtime_resume_and_get(m->dev);
  65. if (err < 0)
  66. return;
  67. for (i = 0; i < host1x_syncpt_nb_pts(m); i++) {
  68. u32 max = host1x_syncpt_read_max(m->syncpt + i);
  69. u32 min = host1x_syncpt_load(m->syncpt + i);
  70. unsigned int waiters = 0;
  71. spin_lock_irqsave(&m->syncpt[i].fences.lock, irqflags);
  72. list_for_each(pos, &m->syncpt[i].fences.list)
  73. waiters++;
  74. spin_unlock_irqrestore(&m->syncpt[i].fences.lock, irqflags);
  75. if (!kref_read(&m->syncpt[i].ref))
  76. continue;
  77. if (!show_all && !min && !max && !waiters)
  78. continue;
  79. host1x_debug_output(o,
  80. "id %u (%s) min %d max %d (%d waiters)\n",
  81. i, m->syncpt[i].name, min, max, waiters);
  82. }
  83. for (i = 0; i < host1x_syncpt_nb_bases(m); i++) {
  84. u32 base_val;
  85. base_val = host1x_syncpt_load_wait_base(m->syncpt + i);
  86. if (base_val)
  87. host1x_debug_output(o, "waitbase id %u val %d\n", i,
  88. base_val);
  89. }
  90. pm_runtime_put(m->dev);
  91. host1x_debug_output(o, "\n");
  92. }
  93. static void show_all(struct host1x *m, struct output *o, bool show_fifo)
  94. {
  95. unsigned int i;
  96. host1x_hw_show_mlocks(m, o);
  97. show_syncpts(m, o, true);
  98. host1x_debug_output(o, "---- channels ----\n");
  99. for (i = 0; i < m->info->nb_channels; ++i) {
  100. struct host1x_channel *ch = host1x_channel_get_index(m, i);
  101. if (ch) {
  102. show_channel(ch, o, show_fifo);
  103. host1x_channel_put(ch);
  104. }
  105. }
  106. }
  107. static int host1x_debug_all_show(struct seq_file *s, void *unused)
  108. {
  109. struct output o = {
  110. .fn = write_to_seqfile,
  111. .ctx = s
  112. };
  113. show_all(s->private, &o, true);
  114. return 0;
  115. }
  116. DEFINE_SHOW_ATTRIBUTE(host1x_debug_all);
  117. static int host1x_debug_show(struct seq_file *s, void *unused)
  118. {
  119. struct output o = {
  120. .fn = write_to_seqfile,
  121. .ctx = s
  122. };
  123. show_all(s->private, &o, false);
  124. return 0;
  125. }
  126. DEFINE_SHOW_ATTRIBUTE(host1x_debug);
  127. static void host1x_debugfs_init(struct host1x *host1x)
  128. {
  129. struct dentry *de = debugfs_create_dir("tegra-host1x", NULL);
  130. /* Store the created entry */
  131. host1x->debugfs = de;
  132. debugfs_create_file("status", S_IRUGO, de, host1x, &host1x_debug_fops);
  133. debugfs_create_file("status_all", S_IRUGO, de, host1x,
  134. &host1x_debug_all_fops);
  135. debugfs_create_u32("trace_cmdbuf", S_IRUGO|S_IWUSR, de,
  136. &host1x_debug_trace_cmdbuf);
  137. host1x_hw_debug_init(host1x, de);
  138. debugfs_create_u32("force_timeout_pid", S_IRUGO|S_IWUSR, de,
  139. &host1x_debug_force_timeout_pid);
  140. debugfs_create_u32("force_timeout_val", S_IRUGO|S_IWUSR, de,
  141. &host1x_debug_force_timeout_val);
  142. debugfs_create_u32("force_timeout_channel", S_IRUGO|S_IWUSR, de,
  143. &host1x_debug_force_timeout_channel);
  144. }
  145. static void host1x_debugfs_exit(struct host1x *host1x)
  146. {
  147. debugfs_remove_recursive(host1x->debugfs);
  148. }
  149. void host1x_debug_init(struct host1x *host1x)
  150. {
  151. if (IS_ENABLED(CONFIG_DEBUG_FS))
  152. host1x_debugfs_init(host1x);
  153. }
  154. void host1x_debug_deinit(struct host1x *host1x)
  155. {
  156. if (IS_ENABLED(CONFIG_DEBUG_FS))
  157. host1x_debugfs_exit(host1x);
  158. }
  159. void host1x_debug_dump(struct host1x *host1x)
  160. {
  161. struct output o = {
  162. .fn = write_to_printk
  163. };
  164. show_all(host1x, &o, true);
  165. }