adreno_a2xx_snapshot.c 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384
  1. /* Copyright (c) 2012-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #include "kgsl.h"
  14. #include "adreno.h"
  15. #include "kgsl_snapshot.h"
  16. #define DEBUG_SECTION_SZ(_dwords) (((_dwords) * sizeof(unsigned int)) \
  17. + sizeof(struct kgsl_snapshot_debug))
  18. /* Dump the SX debug registers into a GPU snapshot debug section */
  19. #define SXDEBUG_COUNT 0x1B
  20. static int a2xx_snapshot_sxdebug(struct kgsl_device *device, void *snapshot,
  21. int remain, void *priv)
  22. {
  23. struct kgsl_snapshot_debug *header = snapshot;
  24. unsigned int *data = snapshot + sizeof(*header);
  25. int i;
  26. if (remain < DEBUG_SECTION_SZ(SXDEBUG_COUNT)) {
  27. SNAPSHOT_ERR_NOMEM(device, "SX DEBUG");
  28. return 0;
  29. }
  30. header->type = SNAPSHOT_DEBUG_SX;
  31. header->size = SXDEBUG_COUNT;
  32. for (i = 0; i < SXDEBUG_COUNT; i++) {
  33. kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0x1B00 | i);
  34. kgsl_regread(device, REG_RBBM_DEBUG_OUT, &data[i]);
  35. }
  36. kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0);
  37. return DEBUG_SECTION_SZ(SXDEBUG_COUNT);
  38. }
  39. #define CPDEBUG_COUNT 0x20
  40. static int a2xx_snapshot_cpdebug(struct kgsl_device *device, void *snapshot,
  41. int remain, void *priv)
  42. {
  43. struct kgsl_snapshot_debug *header = snapshot;
  44. unsigned int *data = snapshot + sizeof(*header);
  45. int i;
  46. if (remain < DEBUG_SECTION_SZ(CPDEBUG_COUNT)) {
  47. SNAPSHOT_ERR_NOMEM(device, "CP DEBUG");
  48. return 0;
  49. }
  50. header->type = SNAPSHOT_DEBUG_CP;
  51. header->size = CPDEBUG_COUNT;
  52. for (i = 0; i < CPDEBUG_COUNT; i++) {
  53. kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0x1628);
  54. kgsl_regread(device, REG_RBBM_DEBUG_OUT, &data[i]);
  55. }
  56. kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0);
  57. return DEBUG_SECTION_SZ(CPDEBUG_COUNT);
  58. }
  59. /*
  60. * The contents of the SQ debug sections are dword pairs:
  61. * [register offset]:[value]
  62. * This macro writes both dwords for the given register
  63. */
  64. #define SQ_DEBUG_WRITE(_device, _reg, _data, _offset) \
  65. do { _data[(_offset)++] = (_reg); \
  66. kgsl_regread(_device, (_reg), &_data[(_offset)++]); \
  67. } while (0)
  68. #define SQ_DEBUG_BANK_SIZE 23
  69. static int a2xx_snapshot_sqdebug(struct kgsl_device *device, void *snapshot,
  70. int remain, void *priv)
  71. {
  72. struct kgsl_snapshot_debug *header = snapshot;
  73. unsigned int *data = snapshot + sizeof(*header);
  74. int i, offset = 0;
  75. int size = SQ_DEBUG_BANK_SIZE * 2 * 2;
  76. if (remain < DEBUG_SECTION_SZ(size)) {
  77. SNAPSHOT_ERR_NOMEM(device, "SQ Debug");
  78. return 0;
  79. }
  80. header->type = SNAPSHOT_DEBUG_SQ;
  81. header->size = size;
  82. for (i = 0; i < 2; i++) {
  83. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_CONST_MGR_FSM+i*0x1000,
  84. data, offset);
  85. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_EXP_ALLOC+i*0x1000,
  86. data, offset);
  87. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_FSM_ALU_0+i*0x1000,
  88. data, offset);
  89. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_FSM_ALU_1+i*0x1000,
  90. data, offset);
  91. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_GPR_PIX+i*0x1000,
  92. data, offset);
  93. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_GPR_VTX+i*0x1000,
  94. data, offset);
  95. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_INPUT_FSM+i*0x1000,
  96. data, offset);
  97. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_MISC+i*0x1000,
  98. data, offset);
  99. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_MISC_0+i*0x1000,
  100. data, offset);
  101. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_MISC_1+i*0x1000,
  102. data, offset);
  103. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_0+i*0x1000,
  104. data, offset);
  105. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_STATE_MEM+i*0x1000,
  106. data, offset);
  107. SQ_DEBUG_WRITE(device,
  108. REG_SQ_DEBUG_PIX_TB_STATUS_REG_0+i*0x1000,
  109. data, offset);
  110. SQ_DEBUG_WRITE(device,
  111. REG_SQ_DEBUG_PIX_TB_STATUS_REG_1+i*0x1000,
  112. data, offset);
  113. SQ_DEBUG_WRITE(device,
  114. REG_SQ_DEBUG_PIX_TB_STATUS_REG_2+i*0x1000,
  115. data, offset);
  116. SQ_DEBUG_WRITE(device,
  117. REG_SQ_DEBUG_PIX_TB_STATUS_REG_3+i*0x1000,
  118. data, offset);
  119. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PTR_BUFF+i*0x1000,
  120. data, offset);
  121. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_TB_STATUS_SEL+i*0x1000,
  122. data, offset);
  123. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_TP_FSM+i*0x1000,
  124. data, offset);
  125. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_VTX_TB_0+i*0x1000,
  126. data, offset);
  127. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_VTX_TB_1+i*0x1000,
  128. data, offset);
  129. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_VTX_TB_STATE_MEM+i*0x1000,
  130. data, offset);
  131. }
  132. return DEBUG_SECTION_SZ(size);
  133. }
  134. #define SQ_DEBUG_THREAD_SIZE 7
  135. static int a2xx_snapshot_sqthreaddebug(struct kgsl_device *device,
  136. void *snapshot, int remain, void *priv)
  137. {
  138. struct kgsl_snapshot_debug *header = snapshot;
  139. unsigned int *data = snapshot + sizeof(*header);
  140. int i, offset = 0;
  141. int size = SQ_DEBUG_THREAD_SIZE * 2 * 16;
  142. if (remain < DEBUG_SECTION_SZ(size)) {
  143. SNAPSHOT_ERR_NOMEM(device, "SQ THREAD DEBUG");
  144. return 0;
  145. }
  146. header->type = SNAPSHOT_DEBUG_SQTHREAD;
  147. header->size = size;
  148. for (i = 0; i < 16; i++) {
  149. kgsl_regwrite(device, REG_SQ_DEBUG_TB_STATUS_SEL,
  150. i | (6<<4) | (i<<7) | (1<<11) | (1<<12)
  151. | (i<<16) | (6<<20) | (i<<23));
  152. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_VTX_TB_STATE_MEM,
  153. data, offset);
  154. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_VTX_TB_STATUS_REG,
  155. data, offset);
  156. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_STATE_MEM,
  157. data, offset);
  158. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_STATUS_REG_0,
  159. data, offset);
  160. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_STATUS_REG_1,
  161. data, offset);
  162. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_STATUS_REG_2,
  163. data, offset);
  164. SQ_DEBUG_WRITE(device, REG_SQ_DEBUG_PIX_TB_STATUS_REG_3,
  165. data, offset);
  166. }
  167. return DEBUG_SECTION_SZ(size);
  168. }
  169. #define MIUDEBUG_COUNT 0x10
  170. static int a2xx_snapshot_miudebug(struct kgsl_device *device, void *snapshot,
  171. int remain, void *priv)
  172. {
  173. struct kgsl_snapshot_debug *header = snapshot;
  174. unsigned int *data = snapshot + sizeof(*header);
  175. int i;
  176. if (remain < DEBUG_SECTION_SZ(MIUDEBUG_COUNT)) {
  177. SNAPSHOT_ERR_NOMEM(device, "MIU DEBUG");
  178. return 0;
  179. }
  180. header->type = SNAPSHOT_DEBUG_MIU;
  181. header->size = MIUDEBUG_COUNT;
  182. for (i = 0; i < MIUDEBUG_COUNT; i++) {
  183. kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0x1600 | i);
  184. kgsl_regread(device, REG_RBBM_DEBUG_OUT, &data[i]);
  185. }
  186. kgsl_regwrite(device, REG_RBBM_DEBUG_CNTL, 0);
  187. return DEBUG_SECTION_SZ(MIUDEBUG_COUNT);
  188. }
  189. /* Snapshot the istore memory */
  190. static int a2xx_snapshot_istore(struct kgsl_device *device, void *snapshot,
  191. int remain, void *priv)
  192. {
  193. struct kgsl_snapshot_istore *header = snapshot;
  194. unsigned int *data = snapshot + sizeof(*header);
  195. struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  196. int count, i;
  197. count = adreno_dev->istore_size * adreno_dev->instruction_size;
  198. if (remain < (count * 4) + sizeof(*header)) {
  199. KGSL_DRV_ERR(device,
  200. "snapshot: Not enough memory for the istore section");
  201. return 0;
  202. }
  203. header->count = adreno_dev->istore_size;
  204. for (i = 0; i < count; i++)
  205. kgsl_regread(device, ADRENO_ISTORE_START + i, &data[i]);
  206. return (count * 4) + sizeof(*header);
  207. }
  208. /* A2XX GPU snapshot function - this is where all of the A2XX specific
  209. * bits and pieces are grabbed into the snapshot memory
  210. */
  211. void *a2xx_snapshot(struct adreno_device *adreno_dev, void *snapshot,
  212. int *remain, int hang)
  213. {
  214. struct kgsl_device *device = &adreno_dev->dev;
  215. struct kgsl_snapshot_registers_list list;
  216. struct kgsl_snapshot_registers regs;
  217. unsigned int pmoverride;
  218. /* Choose the register set to dump */
  219. if (adreno_is_a20x(adreno_dev)) {
  220. regs.regs = (unsigned int *) a200_registers;
  221. regs.count = a200_registers_count;
  222. } else if (adreno_is_a220(adreno_dev)) {
  223. regs.regs = (unsigned int *) a220_registers;
  224. regs.count = a220_registers_count;
  225. } else if (adreno_is_a225(adreno_dev)) {
  226. regs.regs = (unsigned int *) a225_registers;
  227. regs.count = a225_registers_count;
  228. }
  229. list.registers = &regs;
  230. list.count = 1;
  231. /* Master set of (non debug) registers */
  232. snapshot = kgsl_snapshot_add_section(device,
  233. KGSL_SNAPSHOT_SECTION_REGS, snapshot, remain,
  234. kgsl_snapshot_dump_regs, &list);
  235. /* CP_STATE_DEBUG indexed registers */
  236. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  237. remain, REG_CP_STATE_DEBUG_INDEX,
  238. REG_CP_STATE_DEBUG_DATA, 0x0, 0x14);
  239. /* CP_ME indexed registers */
  240. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  241. remain, REG_CP_ME_CNTL, REG_CP_ME_STATUS,
  242. 64, 44);
  243. /*
  244. * Need to temporarily turn off clock gating for the debug bus to
  245. * work
  246. */
  247. kgsl_regread(device, REG_RBBM_PM_OVERRIDE2, &pmoverride);
  248. kgsl_regwrite(device, REG_RBBM_PM_OVERRIDE2, 0xFF);
  249. /* SX debug registers */
  250. snapshot = kgsl_snapshot_add_section(device,
  251. KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain,
  252. a2xx_snapshot_sxdebug, NULL);
  253. /* SU debug indexed registers (only for < 470) */
  254. if (!adreno_is_a22x(adreno_dev))
  255. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  256. remain, REG_PA_SU_DEBUG_CNTL,
  257. REG_PA_SU_DEBUG_DATA,
  258. 0, 0x1B);
  259. /* CP debug registers */
  260. snapshot = kgsl_snapshot_add_section(device,
  261. KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain,
  262. a2xx_snapshot_cpdebug, NULL);
  263. /* MH debug indexed registers */
  264. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  265. remain, MH_DEBUG_CTRL, MH_DEBUG_DATA, 0x0, 0x40);
  266. /* Leia only register sets */
  267. if (adreno_is_a22x(adreno_dev)) {
  268. /* RB DEBUG indexed regisers */
  269. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  270. remain, REG_RB_DEBUG_CNTL, REG_RB_DEBUG_DATA, 0, 8);
  271. /* RB DEBUG indexed registers bank 2 */
  272. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  273. remain, REG_RB_DEBUG_CNTL, REG_RB_DEBUG_DATA + 0x1000,
  274. 0, 8);
  275. /* PC_DEBUG indexed registers */
  276. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  277. remain, REG_PC_DEBUG_CNTL, REG_PC_DEBUG_DATA, 0, 8);
  278. /* GRAS_DEBUG indexed registers */
  279. snapshot = kgsl_snapshot_indexed_registers(device, snapshot,
  280. remain, REG_GRAS_DEBUG_CNTL, REG_GRAS_DEBUG_DATA, 0, 4);
  281. /* MIU debug registers */
  282. snapshot = kgsl_snapshot_add_section(device,
  283. KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain,
  284. a2xx_snapshot_miudebug, NULL);
  285. /* SQ DEBUG debug registers */
  286. snapshot = kgsl_snapshot_add_section(device,
  287. KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain,
  288. a2xx_snapshot_sqdebug, NULL);
  289. /*
  290. * Reading SQ THREAD causes bad things to happen on a running
  291. * system, so only read it if the GPU is already hung
  292. */
  293. if (hang) {
  294. /* SQ THREAD debug registers */
  295. snapshot = kgsl_snapshot_add_section(device,
  296. KGSL_SNAPSHOT_SECTION_DEBUG, snapshot, remain,
  297. a2xx_snapshot_sqthreaddebug, NULL);
  298. }
  299. }
  300. /*
  301. * Only dump the istore on a hang - reading it on a running system
  302. * has a non zero chance of hanging the GPU.
  303. */
  304. if (adreno_is_a2xx(adreno_dev) && hang) {
  305. snapshot = kgsl_snapshot_add_section(device,
  306. KGSL_SNAPSHOT_SECTION_ISTORE, snapshot, remain,
  307. a2xx_snapshot_istore, NULL);
  308. }
  309. /* Reset the clock gating */
  310. kgsl_regwrite(device, REG_RBBM_PM_OVERRIDE2, pmoverride);
  311. return snapshot;
  312. }