debug_hw.c 9.0 KB

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