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