debug_hw.c 5.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199
  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 "../dev.h"
  18. #include "../debug.h"
  19. #include "../cdma.h"
  20. #include "../channel.h"
  21. #define HOST1X_DEBUG_MAX_PAGE_OFFSET 102400
  22. enum {
  23. HOST1X_OPCODE_SETCLASS = 0x00,
  24. HOST1X_OPCODE_INCR = 0x01,
  25. HOST1X_OPCODE_NONINCR = 0x02,
  26. HOST1X_OPCODE_MASK = 0x03,
  27. HOST1X_OPCODE_IMM = 0x04,
  28. HOST1X_OPCODE_RESTART = 0x05,
  29. HOST1X_OPCODE_GATHER = 0x06,
  30. HOST1X_OPCODE_EXTEND = 0x0e,
  31. };
  32. enum {
  33. HOST1X_OPCODE_EXTEND_ACQUIRE_MLOCK = 0x00,
  34. HOST1X_OPCODE_EXTEND_RELEASE_MLOCK = 0x01,
  35. };
  36. static unsigned int show_channel_command(struct output *o, u32 val)
  37. {
  38. unsigned int mask, subop, num;
  39. switch (val >> 28) {
  40. case HOST1X_OPCODE_SETCLASS:
  41. mask = val & 0x3f;
  42. if (mask) {
  43. host1x_debug_cont(o, "SETCL(class=%03x, offset=%03x, mask=%02x, [",
  44. val >> 6 & 0x3ff,
  45. val >> 16 & 0xfff, mask);
  46. return hweight8(mask);
  47. }
  48. host1x_debug_cont(o, "SETCL(class=%03x)\n", val >> 6 & 0x3ff);
  49. return 0;
  50. case HOST1X_OPCODE_INCR:
  51. num = val & 0xffff;
  52. host1x_debug_cont(o, "INCR(offset=%03x, [",
  53. val >> 16 & 0xfff);
  54. if (!num)
  55. host1x_debug_cont(o, "])\n");
  56. return num;
  57. case HOST1X_OPCODE_NONINCR:
  58. num = val & 0xffff;
  59. host1x_debug_cont(o, "NONINCR(offset=%03x, [",
  60. val >> 16 & 0xfff);
  61. if (!num)
  62. host1x_debug_cont(o, "])\n");
  63. return num;
  64. case HOST1X_OPCODE_MASK:
  65. mask = val & 0xffff;
  66. host1x_debug_cont(o, "MASK(offset=%03x, mask=%03x, [",
  67. val >> 16 & 0xfff, mask);
  68. if (!mask)
  69. host1x_debug_cont(o, "])\n");
  70. return hweight16(mask);
  71. case HOST1X_OPCODE_IMM:
  72. host1x_debug_cont(o, "IMM(offset=%03x, data=%03x)\n",
  73. val >> 16 & 0xfff, val & 0xffff);
  74. return 0;
  75. case HOST1X_OPCODE_RESTART:
  76. host1x_debug_cont(o, "RESTART(offset=%08x)\n", val << 4);
  77. return 0;
  78. case HOST1X_OPCODE_GATHER:
  79. host1x_debug_cont(o, "GATHER(offset=%03x, insert=%d, type=%d, count=%04x, addr=[",
  80. val >> 16 & 0xfff, val >> 15 & 0x1,
  81. val >> 14 & 0x1, val & 0x3fff);
  82. return 1;
  83. case HOST1X_OPCODE_EXTEND:
  84. subop = val >> 24 & 0xf;
  85. if (subop == HOST1X_OPCODE_EXTEND_ACQUIRE_MLOCK)
  86. host1x_debug_cont(o, "ACQUIRE_MLOCK(index=%d)\n",
  87. val & 0xff);
  88. else if (subop == HOST1X_OPCODE_EXTEND_RELEASE_MLOCK)
  89. host1x_debug_cont(o, "RELEASE_MLOCK(index=%d)\n",
  90. val & 0xff);
  91. else
  92. host1x_debug_cont(o, "EXTEND_UNKNOWN(%08x)\n", val);
  93. return 0;
  94. default:
  95. host1x_debug_cont(o, "UNKNOWN\n");
  96. return 0;
  97. }
  98. }
  99. static void show_gather(struct output *o, phys_addr_t phys_addr,
  100. unsigned int words, struct host1x_cdma *cdma,
  101. phys_addr_t pin_addr, u32 *map_addr)
  102. {
  103. /* Map dmaget cursor to corresponding mem handle */
  104. u32 offset = phys_addr - pin_addr;
  105. unsigned int data_count = 0, i;
  106. /*
  107. * Sometimes we're given different hardware address to the same
  108. * page - in these cases the offset will get an invalid number and
  109. * we just have to bail out.
  110. */
  111. if (offset > HOST1X_DEBUG_MAX_PAGE_OFFSET) {
  112. host1x_debug_output(o, "[address mismatch]\n");
  113. return;
  114. }
  115. for (i = 0; i < words; i++) {
  116. u32 addr = phys_addr + i * 4;
  117. u32 val = *(map_addr + offset / 4 + i);
  118. if (!data_count) {
  119. host1x_debug_output(o, "%08x: %08x: ", addr, val);
  120. data_count = show_channel_command(o, val);
  121. } else {
  122. host1x_debug_cont(o, "%08x%s", val,
  123. data_count > 1 ? ", " : "])\n");
  124. data_count--;
  125. }
  126. }
  127. }
  128. static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma)
  129. {
  130. struct host1x_job *job;
  131. list_for_each_entry(job, &cdma->sync_queue, list) {
  132. unsigned int i;
  133. host1x_debug_output(o, "\n%p: JOB, syncpt_id=%d, syncpt_val=%d, first_get=%08x, timeout=%d num_slots=%d, num_handles=%d\n",
  134. job, job->syncpt_id, job->syncpt_end,
  135. job->first_get, job->timeout,
  136. job->num_slots, job->num_unpins);
  137. for (i = 0; i < job->num_gathers; i++) {
  138. struct host1x_job_gather *g = &job->gathers[i];
  139. u32 *mapped;
  140. if (job->gather_copy_mapped)
  141. mapped = (u32 *)job->gather_copy_mapped;
  142. else
  143. mapped = host1x_bo_mmap(g->bo);
  144. if (!mapped) {
  145. host1x_debug_output(o, "[could not mmap]\n");
  146. continue;
  147. }
  148. host1x_debug_output(o, " GATHER at %pad+%#x, %d words\n",
  149. &g->base, g->offset, g->words);
  150. show_gather(o, g->base + g->offset, g->words, cdma,
  151. g->base, mapped);
  152. if (!job->gather_copy_mapped)
  153. host1x_bo_munmap(g->bo, mapped);
  154. }
  155. }
  156. }
  157. #if HOST1X_HW >= 6
  158. #include "debug_hw_1x06.c"
  159. #else
  160. #include "debug_hw_1x01.c"
  161. #endif
  162. static const struct host1x_debug_ops host1x_debug_ops = {
  163. .show_channel_cdma = host1x_debug_show_channel_cdma,
  164. .show_channel_fifo = host1x_debug_show_channel_fifo,
  165. .show_mlocks = host1x_debug_show_mlocks,
  166. };