debug_hw.c 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322
  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 <linux/debugfs.h>
  18. #include <linux/seq_file.h>
  19. #include <linux/mm.h>
  20. #include <linux/scatterlist.h>
  21. #include <linux/io.h>
  22. #include "dev.h"
  23. #include "debug.h"
  24. #include "cdma.h"
  25. #include "channel.h"
  26. #include "host1x_bo.h"
  27. #define HOST1X_DEBUG_MAX_PAGE_OFFSET 102400
  28. enum {
  29. HOST1X_OPCODE_SETCLASS = 0x00,
  30. HOST1X_OPCODE_INCR = 0x01,
  31. HOST1X_OPCODE_NONINCR = 0x02,
  32. HOST1X_OPCODE_MASK = 0x03,
  33. HOST1X_OPCODE_IMM = 0x04,
  34. HOST1X_OPCODE_RESTART = 0x05,
  35. HOST1X_OPCODE_GATHER = 0x06,
  36. HOST1X_OPCODE_EXTEND = 0x0e,
  37. };
  38. enum {
  39. HOST1X_OPCODE_EXTEND_ACQUIRE_MLOCK = 0x00,
  40. HOST1X_OPCODE_EXTEND_RELEASE_MLOCK = 0x01,
  41. };
  42. static unsigned int show_channel_command(struct output *o, u32 val)
  43. {
  44. unsigned mask;
  45. unsigned subop;
  46. switch (val >> 28) {
  47. case HOST1X_OPCODE_SETCLASS:
  48. mask = val & 0x3f;
  49. if (mask) {
  50. host1x_debug_output(o, "SETCL(class=%03x, offset=%03x, mask=%02x, [",
  51. val >> 6 & 0x3ff,
  52. val >> 16 & 0xfff, mask);
  53. return hweight8(mask);
  54. } else {
  55. host1x_debug_output(o, "SETCL(class=%03x)\n",
  56. val >> 6 & 0x3ff);
  57. return 0;
  58. }
  59. case HOST1X_OPCODE_INCR:
  60. host1x_debug_output(o, "INCR(offset=%03x, [",
  61. val >> 16 & 0xfff);
  62. return val & 0xffff;
  63. case HOST1X_OPCODE_NONINCR:
  64. host1x_debug_output(o, "NONINCR(offset=%03x, [",
  65. val >> 16 & 0xfff);
  66. return val & 0xffff;
  67. case HOST1X_OPCODE_MASK:
  68. mask = val & 0xffff;
  69. host1x_debug_output(o, "MASK(offset=%03x, mask=%03x, [",
  70. val >> 16 & 0xfff, mask);
  71. return hweight16(mask);
  72. case HOST1X_OPCODE_IMM:
  73. host1x_debug_output(o, "IMM(offset=%03x, data=%03x)\n",
  74. val >> 16 & 0xfff, val & 0xffff);
  75. return 0;
  76. case HOST1X_OPCODE_RESTART:
  77. host1x_debug_output(o, "RESTART(offset=%08x)\n", val << 4);
  78. return 0;
  79. case HOST1X_OPCODE_GATHER:
  80. host1x_debug_output(o, "GATHER(offset=%03x, insert=%d, type=%d, count=%04x, addr=[",
  81. val >> 16 & 0xfff, val >> 15 & 0x1,
  82. val >> 14 & 0x1, val & 0x3fff);
  83. return 1;
  84. case HOST1X_OPCODE_EXTEND:
  85. subop = val >> 24 & 0xf;
  86. if (subop == HOST1X_OPCODE_EXTEND_ACQUIRE_MLOCK)
  87. host1x_debug_output(o, "ACQUIRE_MLOCK(index=%d)\n",
  88. val & 0xff);
  89. else if (subop == HOST1X_OPCODE_EXTEND_RELEASE_MLOCK)
  90. host1x_debug_output(o, "RELEASE_MLOCK(index=%d)\n",
  91. val & 0xff);
  92. else
  93. host1x_debug_output(o, "EXTEND_UNKNOWN(%08x)\n", val);
  94. return 0;
  95. default:
  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_output(o, "%08x%s", val,
  123. data_count > 0 ? ", " : "])\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. 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 %08x+%04x, %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. static void host1x_debug_show_channel_cdma(struct host1x *host,
  158. struct host1x_channel *ch,
  159. struct output *o)
  160. {
  161. struct host1x_cdma *cdma = &ch->cdma;
  162. u32 dmaput, dmaget, dmactrl;
  163. u32 cbstat, cbread;
  164. u32 val, base, baseval;
  165. dmaput = host1x_ch_readl(ch, HOST1X_CHANNEL_DMAPUT);
  166. dmaget = host1x_ch_readl(ch, HOST1X_CHANNEL_DMAGET);
  167. dmactrl = host1x_ch_readl(ch, HOST1X_CHANNEL_DMACTRL);
  168. cbread = host1x_sync_readl(host, HOST1X_SYNC_CBREAD(ch->id));
  169. cbstat = host1x_sync_readl(host, HOST1X_SYNC_CBSTAT(ch->id));
  170. host1x_debug_output(o, "%d-%s: ", ch->id, dev_name(ch->dev));
  171. if (HOST1X_CHANNEL_DMACTRL_DMASTOP_V(dmactrl) ||
  172. !ch->cdma.push_buffer.mapped) {
  173. host1x_debug_output(o, "inactive\n\n");
  174. return;
  175. }
  176. if (HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat) == HOST1X_CLASS_HOST1X &&
  177. HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat) ==
  178. HOST1X_UCLASS_WAIT_SYNCPT)
  179. host1x_debug_output(o, "waiting on syncpt %d val %d\n",
  180. cbread >> 24, cbread & 0xffffff);
  181. else if (HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat) ==
  182. HOST1X_CLASS_HOST1X &&
  183. HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat) ==
  184. HOST1X_UCLASS_WAIT_SYNCPT_BASE) {
  185. base = (cbread >> 16) & 0xff;
  186. baseval =
  187. host1x_sync_readl(host, HOST1X_SYNC_SYNCPT_BASE(base));
  188. val = cbread & 0xffff;
  189. host1x_debug_output(o, "waiting on syncpt %d val %d (base %d = %d; offset = %d)\n",
  190. cbread >> 24, baseval + val, base,
  191. baseval, val);
  192. } else
  193. host1x_debug_output(o, "active class %02x, offset %04x, val %08x\n",
  194. HOST1X_SYNC_CBSTAT_CBCLASS_V(cbstat),
  195. HOST1X_SYNC_CBSTAT_CBOFFSET_V(cbstat),
  196. cbread);
  197. host1x_debug_output(o, "DMAPUT %08x, DMAGET %08x, DMACTL %08x\n",
  198. dmaput, dmaget, dmactrl);
  199. host1x_debug_output(o, "CBREAD %08x, CBSTAT %08x\n", cbread, cbstat);
  200. show_channel_gathers(o, cdma);
  201. host1x_debug_output(o, "\n");
  202. }
  203. static void host1x_debug_show_channel_fifo(struct host1x *host,
  204. struct host1x_channel *ch,
  205. struct output *o)
  206. {
  207. u32 val, rd_ptr, wr_ptr, start, end;
  208. unsigned int data_count = 0;
  209. host1x_debug_output(o, "%d: fifo:\n", ch->id);
  210. val = host1x_ch_readl(ch, HOST1X_CHANNEL_FIFOSTAT);
  211. host1x_debug_output(o, "FIFOSTAT %08x\n", val);
  212. if (HOST1X_CHANNEL_FIFOSTAT_CFEMPTY_V(val)) {
  213. host1x_debug_output(o, "[empty]\n");
  214. return;
  215. }
  216. host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
  217. host1x_sync_writel(host, HOST1X_SYNC_CFPEEK_CTRL_ENA_F(1) |
  218. HOST1X_SYNC_CFPEEK_CTRL_CHANNR_F(ch->id),
  219. HOST1X_SYNC_CFPEEK_CTRL);
  220. val = host1x_sync_readl(host, HOST1X_SYNC_CFPEEK_PTRS);
  221. rd_ptr = HOST1X_SYNC_CFPEEK_PTRS_CF_RD_PTR_V(val);
  222. wr_ptr = HOST1X_SYNC_CFPEEK_PTRS_CF_WR_PTR_V(val);
  223. val = host1x_sync_readl(host, HOST1X_SYNC_CF_SETUP(ch->id));
  224. start = HOST1X_SYNC_CF_SETUP_BASE_V(val);
  225. end = HOST1X_SYNC_CF_SETUP_LIMIT_V(val);
  226. do {
  227. host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
  228. host1x_sync_writel(host, HOST1X_SYNC_CFPEEK_CTRL_ENA_F(1) |
  229. HOST1X_SYNC_CFPEEK_CTRL_CHANNR_F(ch->id) |
  230. HOST1X_SYNC_CFPEEK_CTRL_ADDR_F(rd_ptr),
  231. HOST1X_SYNC_CFPEEK_CTRL);
  232. val = host1x_sync_readl(host, HOST1X_SYNC_CFPEEK_READ);
  233. if (!data_count) {
  234. host1x_debug_output(o, "%08x:", val);
  235. data_count = show_channel_command(o, val);
  236. } else {
  237. host1x_debug_output(o, "%08x%s", val,
  238. data_count > 0 ? ", " : "])\n");
  239. data_count--;
  240. }
  241. if (rd_ptr == end)
  242. rd_ptr = start;
  243. else
  244. rd_ptr++;
  245. } while (rd_ptr != wr_ptr);
  246. if (data_count)
  247. host1x_debug_output(o, ", ...])\n");
  248. host1x_debug_output(o, "\n");
  249. host1x_sync_writel(host, 0x0, HOST1X_SYNC_CFPEEK_CTRL);
  250. }
  251. static void host1x_debug_show_mlocks(struct host1x *host, struct output *o)
  252. {
  253. int i;
  254. host1x_debug_output(o, "---- mlocks ----\n");
  255. for (i = 0; i < host1x_syncpt_nb_mlocks(host); i++) {
  256. u32 owner =
  257. host1x_sync_readl(host, HOST1X_SYNC_MLOCK_OWNER(i));
  258. if (HOST1X_SYNC_MLOCK_OWNER_CH_OWNS_V(owner))
  259. host1x_debug_output(o, "%d: locked by channel %d\n",
  260. i, HOST1X_SYNC_MLOCK_OWNER_CHID_F(owner));
  261. else if (HOST1X_SYNC_MLOCK_OWNER_CPU_OWNS_V(owner))
  262. host1x_debug_output(o, "%d: locked by cpu\n", i);
  263. else
  264. host1x_debug_output(o, "%d: unlocked\n", i);
  265. }
  266. host1x_debug_output(o, "\n");
  267. }
  268. static const struct host1x_debug_ops host1x_debug_ops = {
  269. .show_channel_cdma = host1x_debug_show_channel_cdma,
  270. .show_channel_fifo = host1x_debug_show_channel_fifo,
  271. .show_mlocks = host1x_debug_show_mlocks,
  272. };