debug_hw.c 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315
  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;
  39. switch (val >> 28) {
  40. case HOST1X_OPCODE_SETCLASS:
  41. mask = val & 0x3f;
  42. if (mask) {
  43. host1x_debug_output(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_output(o, "SETCL(class=%03x)\n", val >> 6 & 0x3ff);
  49. return 0;
  50. case HOST1X_OPCODE_INCR:
  51. host1x_debug_output(o, "INCR(offset=%03x, [",
  52. val >> 16 & 0xfff);
  53. return val & 0xffff;
  54. case HOST1X_OPCODE_NONINCR:
  55. host1x_debug_output(o, "NONINCR(offset=%03x, [",
  56. val >> 16 & 0xfff);
  57. return val & 0xffff;
  58. case HOST1X_OPCODE_MASK:
  59. mask = val & 0xffff;
  60. host1x_debug_output(o, "MASK(offset=%03x, mask=%03x, [",
  61. val >> 16 & 0xfff, mask);
  62. return hweight16(mask);
  63. case HOST1X_OPCODE_IMM:
  64. host1x_debug_output(o, "IMM(offset=%03x, data=%03x)\n",
  65. val >> 16 & 0xfff, val & 0xffff);
  66. return 0;
  67. case HOST1X_OPCODE_RESTART:
  68. host1x_debug_output(o, "RESTART(offset=%08x)\n", val << 4);
  69. return 0;
  70. case HOST1X_OPCODE_GATHER:
  71. host1x_debug_output(o, "GATHER(offset=%03x, insert=%d, type=%d, count=%04x, addr=[",
  72. val >> 16 & 0xfff, val >> 15 & 0x1,
  73. val >> 14 & 0x1, val & 0x3fff);
  74. return 1;
  75. case HOST1X_OPCODE_EXTEND:
  76. subop = val >> 24 & 0xf;
  77. if (subop == HOST1X_OPCODE_EXTEND_ACQUIRE_MLOCK)
  78. host1x_debug_output(o, "ACQUIRE_MLOCK(index=%d)\n",
  79. val & 0xff);
  80. else if (subop == HOST1X_OPCODE_EXTEND_RELEASE_MLOCK)
  81. host1x_debug_output(o, "RELEASE_MLOCK(index=%d)\n",
  82. val & 0xff);
  83. else
  84. host1x_debug_output(o, "EXTEND_UNKNOWN(%08x)\n", val);
  85. return 0;
  86. default:
  87. return 0;
  88. }
  89. }
  90. static void show_gather(struct output *o, phys_addr_t phys_addr,
  91. unsigned int words, struct host1x_cdma *cdma,
  92. phys_addr_t pin_addr, u32 *map_addr)
  93. {
  94. /* Map dmaget cursor to corresponding mem handle */
  95. u32 offset = phys_addr - pin_addr;
  96. unsigned int data_count = 0, i;
  97. /*
  98. * Sometimes we're given different hardware address to the same
  99. * page - in these cases the offset will get an invalid number and
  100. * we just have to bail out.
  101. */
  102. if (offset > HOST1X_DEBUG_MAX_PAGE_OFFSET) {
  103. host1x_debug_output(o, "[address mismatch]\n");
  104. return;
  105. }
  106. for (i = 0; i < words; i++) {
  107. u32 addr = phys_addr + i * 4;
  108. u32 val = *(map_addr + offset / 4 + i);
  109. if (!data_count) {
  110. host1x_debug_output(o, "%08x: %08x:", addr, val);
  111. data_count = show_channel_command(o, val);
  112. } else {
  113. host1x_debug_output(o, "%08x%s", val,
  114. data_count > 0 ? ", " : "])\n");
  115. data_count--;
  116. }
  117. }
  118. }
  119. static void show_channel_gathers(struct output *o, struct host1x_cdma *cdma)
  120. {
  121. struct host1x_job *job;
  122. list_for_each_entry(job, &cdma->sync_queue, list) {
  123. unsigned int i;
  124. 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",
  125. job, job->syncpt_id, job->syncpt_end,
  126. job->first_get, job->timeout,
  127. job->num_slots, job->num_unpins);
  128. for (i = 0; i < job->num_gathers; i++) {
  129. struct host1x_job_gather *g = &job->gathers[i];
  130. u32 *mapped;
  131. if (job->gather_copy_mapped)
  132. mapped = (u32 *)job->gather_copy_mapped;
  133. else
  134. mapped = host1x_bo_mmap(g->bo);
  135. if (!mapped) {
  136. host1x_debug_output(o, "[could not mmap]\n");
  137. continue;
  138. }
  139. host1x_debug_output(o, " GATHER at %pad+%#x, %d words\n",
  140. &g->base, g->offset, g->words);
  141. show_gather(o, g->base + g->offset, g->words, cdma,
  142. g->base, mapped);
  143. if (!job->gather_copy_mapped)
  144. host1x_bo_munmap(g->bo, mapped);
  145. }
  146. }
  147. }
  148. static void host1x_debug_show_channel_cdma(struct host1x *host,
  149. struct host1x_channel *ch,
  150. struct output *o)
  151. {
  152. struct host1x_cdma *cdma = &ch->cdma;
  153. u32 dmaput, dmaget, dmactrl;
  154. u32 cbstat, cbread;
  155. u32 val, base, baseval;
  156. dmaput = host1x_ch_readl(ch, HOST1X_CHANNEL_DMAPUT);
  157. dmaget = host1x_ch_readl(ch, HOST1X_CHANNEL_DMAGET);
  158. dmactrl = host1x_ch_readl(ch, HOST1X_CHANNEL_DMACTRL);
  159. cbread = host1x_sync_readl(host, HOST1X_SYNC_CBREAD(ch->id));
  160. cbstat = host1x_sync_readl(host, HOST1X_SYNC_CBSTAT(ch->id));
  161. host1x_debug_output(o, "%u-%s: ", ch->id, dev_name(ch->dev));
  162. if (HOST1X_CHANNEL_DMACTRL_DMASTOP_V(dmactrl) ||
  163. !ch->cdma.push_buffer.mapped) {
  164. host1x_debug_output(o, "inactive\n\n");
  165. return;
  166. }
  167. if (HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat) == HOST1X_CLASS_HOST1X &&
  168. HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat) ==
  169. HOST1X_UCLASS_WAIT_SYNCPT)
  170. host1x_debug_output(o, "waiting on syncpt %d val %d\n",
  171. cbread >> 24, cbread & 0xffffff);
  172. else if (HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat) ==
  173. HOST1X_CLASS_HOST1X &&
  174. HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat) ==
  175. HOST1X_UCLASS_WAIT_SYNCPT_BASE) {
  176. base = (cbread >> 16) & 0xff;
  177. baseval =
  178. host1x_sync_readl(host, HOST1X_SYNC_SYNCPT_BASE(base));
  179. val = cbread & 0xffff;
  180. host1x_debug_output(o, "waiting on syncpt %d val %d (base %d = %d; offset = %d)\n",
  181. cbread >> 24, baseval + val, base,
  182. baseval, val);
  183. } else
  184. host1x_debug_output(o, "active class %02x, offset %04x, val %08x\n",
  185. HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat),
  186. HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat),
  187. cbread);
  188. host1x_debug_output(o, "DMAPUT %08x, DMAGET %08x, DMACTL %08x\n",
  189. dmaput, dmaget, dmactrl);
  190. host1x_debug_output(o, "CBREAD %08x, CBSTAT %08x\n", cbread, cbstat);
  191. show_channel_gathers(o, cdma);
  192. host1x_debug_output(o, "\n");
  193. }
  194. static void host1x_debug_show_channel_fifo(struct host1x *host,
  195. struct host1x_channel *ch,
  196. struct output *o)
  197. {
  198. u32 val, rd_ptr, wr_ptr, start, end;
  199. unsigned int data_count = 0;
  200. host1x_debug_output(o, "%u: fifo:\n", ch->id);
  201. val = host1x_ch_readl(ch, HOST1X_CHANNEL_FIFOSTAT);
  202. host1x_debug_output(o, "FIFOSTAT %08x\n", val);
  203. if (HOST1X_CHANNEL_FIFOSTAT_CFEMPTY_V(val)) {
  204. host1x_debug_output(o, "[empty]\n");
  205. return;
  206. }
  207. host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
  208. host1x_sync_writel(host, HOST1X_SYNC_CFPEEK_CTRL_ENA_F(1) |
  209. HOST1X_SYNC_CFPEEK_CTRL_CHANNR_F(ch->id),
  210. HOST1X_SYNC_CFPEEK_CTRL);
  211. val = host1x_sync_readl(host, HOST1X_SYNC_CFPEEK_PTRS);
  212. rd_ptr = HOST1X_SYNC_CFPEEK_PTRS_CF_RD_PTR_V(val);
  213. wr_ptr = HOST1X_SYNC_CFPEEK_PTRS_CF_WR_PTR_V(val);
  214. val = host1x_sync_readl(host, HOST1X_SYNC_CF_SETUP(ch->id));
  215. start = HOST1X_SYNC_CF_SETUP_BASE_V(val);
  216. end = HOST1X_SYNC_CF_SETUP_LIMIT_V(val);
  217. do {
  218. host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
  219. host1x_sync_writel(host, HOST1X_SYNC_CFPEEK_CTRL_ENA_F(1) |
  220. HOST1X_SYNC_CFPEEK_CTRL_CHANNR_F(ch->id) |
  221. HOST1X_SYNC_CFPEEK_CTRL_ADDR_F(rd_ptr),
  222. HOST1X_SYNC_CFPEEK_CTRL);
  223. val = host1x_sync_readl(host, HOST1X_SYNC_CFPEEK_READ);
  224. if (!data_count) {
  225. host1x_debug_output(o, "%08x:", val);
  226. data_count = show_channel_command(o, val);
  227. } else {
  228. host1x_debug_output(o, "%08x%s", val,
  229. data_count > 0 ? ", " : "])\n");
  230. data_count--;
  231. }
  232. if (rd_ptr == end)
  233. rd_ptr = start;
  234. else
  235. rd_ptr++;
  236. } while (rd_ptr != wr_ptr);
  237. if (data_count)
  238. host1x_debug_output(o, ", ...])\n");
  239. host1x_debug_output(o, "\n");
  240. host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
  241. }
  242. static void host1x_debug_show_mlocks(struct host1x *host, struct output *o)
  243. {
  244. unsigned int i;
  245. host1x_debug_output(o, "---- mlocks ----\n");
  246. for (i = 0; i < host1x_syncpt_nb_mlocks(host); i++) {
  247. u32 owner =
  248. host1x_sync_readl(host, HOST1X_SYNC_MLOCK_OWNER(i));
  249. if (HOST1X_SYNC_MLOCK_OWNER_CH_OWNS_V(owner))
  250. host1x_debug_output(o, "%u: locked by channel %u\n",
  251. i, HOST1X_SYNC_MLOCK_OWNER_CHID_V(owner));
  252. else if (HOST1X_SYNC_MLOCK_OWNER_CPU_OWNS_V(owner))
  253. host1x_debug_output(o, "%u: locked by cpu\n", i);
  254. else
  255. host1x_debug_output(o, "%u: unlocked\n", i);
  256. }
  257. host1x_debug_output(o, "\n");
  258. }
  259. static const struct host1x_debug_ops host1x_debug_ops = {
  260. .show_channel_cdma = host1x_debug_show_channel_cdma,
  261. .show_channel_fifo = host1x_debug_show_channel_fifo,
  262. .show_mlocks = host1x_debug_show_mlocks,
  263. };