adreno_a3xx_snapshot.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449
  1. // SPDX-License-Identifier: GPL-2.0-only
  2. /*
  3. * Copyright (c) 2012-2017,2019-2020, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #include <linux/io.h>
  7. #include "adreno.h"
  8. #include "adreno_a3xx.h"
  9. #include "adreno_snapshot.h"
  10. #include "kgsl_device.h"
  11. /*
  12. * Set of registers to dump for A3XX on snapshot.
  13. * Registers in pairs - first value is the start offset, second
  14. * is the stop offset (inclusive)
  15. */
  16. static const unsigned int a3xx_registers[] = {
  17. 0x0000, 0x0002, 0x0010, 0x0012, 0x0018, 0x0018, 0x0020, 0x0027,
  18. 0x0029, 0x002b, 0x002e, 0x0033, 0x0040, 0x0042, 0x0050, 0x005c,
  19. 0x0060, 0x006c, 0x0080, 0x0082, 0x0084, 0x0088, 0x0090, 0x00e5,
  20. 0x00ea, 0x00ed, 0x0100, 0x0100, 0x0110, 0x0123, 0x01c0, 0x01c1,
  21. 0x01c3, 0x01c5, 0x01c7, 0x01c7, 0x01d5, 0x01d9, 0x01dc, 0x01dd,
  22. 0x01ea, 0x01ea, 0x01ee, 0x01f1, 0x01f5, 0x01f6, 0x01f8, 0x01f9,
  23. 0x01fc, 0x01ff,
  24. 0x0440, 0x0440, 0x0443, 0x0443, 0x0445, 0x0445, 0x044d, 0x044f,
  25. 0x0452, 0x0452, 0x0454, 0x046f, 0x047c, 0x047c, 0x047f, 0x047f,
  26. 0x0578, 0x057f, 0x0600, 0x0602, 0x0605, 0x0607, 0x060a, 0x060e,
  27. 0x0612, 0x0614, 0x0c01, 0x0c02, 0x0c06, 0x0c1d, 0x0c3d, 0x0c3f,
  28. 0x0c48, 0x0c4b, 0x0c80, 0x0c80, 0x0c88, 0x0c8b, 0x0ca0, 0x0cb7,
  29. 0x0cc0, 0x0cc1, 0x0cc6, 0x0cc7, 0x0ce4, 0x0ce5,
  30. 0x0e41, 0x0e45, 0x0e64, 0x0e65,
  31. 0x0e80, 0x0e82, 0x0e84, 0x0e89, 0x0ea0, 0x0ea1, 0x0ea4, 0x0ea7,
  32. 0x0ec4, 0x0ecb, 0x0ee0, 0x0ee0, 0x0f00, 0x0f01, 0x0f03, 0x0f09,
  33. 0x2040, 0x2040, 0x2044, 0x2044, 0x2048, 0x204d, 0x2068, 0x2069,
  34. 0x206c, 0x206d, 0x2070, 0x2070, 0x2072, 0x2072, 0x2074, 0x2075,
  35. 0x2079, 0x207a, 0x20c0, 0x20d3, 0x20e4, 0x20ef, 0x2100, 0x2109,
  36. 0x210c, 0x210c, 0x210e, 0x210e, 0x2110, 0x2111, 0x2114, 0x2115,
  37. 0x21e4, 0x21e4, 0x21ea, 0x21ea, 0x21ec, 0x21ed, 0x21f0, 0x21f0,
  38. 0x2240, 0x227e,
  39. 0x2280, 0x228b, 0x22c0, 0x22c0, 0x22c4, 0x22ce, 0x22d0, 0x22d8,
  40. 0x22df, 0x22e6, 0x22e8, 0x22e9, 0x22ec, 0x22ec, 0x22f0, 0x22f7,
  41. 0x22ff, 0x22ff, 0x2340, 0x2343,
  42. 0x2440, 0x2440, 0x2444, 0x2444, 0x2448, 0x244d,
  43. 0x2468, 0x2469, 0x246c, 0x246d, 0x2470, 0x2470, 0x2472, 0x2472,
  44. 0x2474, 0x2475, 0x2479, 0x247a, 0x24c0, 0x24d3, 0x24e4, 0x24ef,
  45. 0x2500, 0x2509, 0x250c, 0x250c, 0x250e, 0x250e, 0x2510, 0x2511,
  46. 0x2514, 0x2515, 0x25e4, 0x25e4, 0x25ea, 0x25ea, 0x25ec, 0x25ed,
  47. 0x25f0, 0x25f0,
  48. 0x2640, 0x267e, 0x2680, 0x268b, 0x26c0, 0x26c0, 0x26c4, 0x26ce,
  49. 0x26d0, 0x26d8, 0x26df, 0x26e6, 0x26e8, 0x26e9, 0x26ec, 0x26ec,
  50. 0x26f0, 0x26f7, 0x26ff, 0x26ff, 0x2740, 0x2743,
  51. 0x300C, 0x300E, 0x301C, 0x301D,
  52. 0x302A, 0x302A, 0x302C, 0x302D, 0x3030, 0x3031, 0x3034, 0x3036,
  53. 0x303C, 0x303C, 0x305E, 0x305F,
  54. };
  55. /* Removed the following HLSQ register ranges from being read during
  56. * fault tolerance since reading the registers may cause the device to hang:
  57. */
  58. static const unsigned int a3xx_hlsq_registers[] = {
  59. 0x0e00, 0x0e05, 0x0e0c, 0x0e0c, 0x0e22, 0x0e23,
  60. 0x2200, 0x2212, 0x2214, 0x2217, 0x221a, 0x221a,
  61. 0x2600, 0x2612, 0x2614, 0x2617, 0x261a, 0x261a,
  62. };
  63. /* Shader memory size in words */
  64. #define SHADER_MEMORY_SIZE 0x4000
  65. /**
  66. * _rbbm_debug_bus_read - Helper function to read data from the RBBM
  67. * debug bus.
  68. * @device - GPU device to read/write registers
  69. * @block_id - Debug bus block to read from
  70. * @index - Index in the debug bus block to read
  71. * @ret - Value of the register read
  72. */
  73. static void _rbbm_debug_bus_read(struct kgsl_device *device,
  74. unsigned int block_id, unsigned int index, unsigned int *val)
  75. {
  76. unsigned int block = (block_id << 8) | 1 << 16;
  77. kgsl_regwrite(device, A3XX_RBBM_DEBUG_BUS_CTL, block | index);
  78. kgsl_regread(device, A3XX_RBBM_DEBUG_BUS_DATA_STATUS, val);
  79. }
  80. /**
  81. * a3xx_snapshot_shader_memory - Helper function to dump the GPU shader
  82. * memory to the snapshot buffer.
  83. * @device: GPU device whose shader memory is to be dumped
  84. * @buf: Pointer to binary snapshot data blob being made
  85. * @remain: Number of remaining bytes in the snapshot blob
  86. * @priv: Unused parameter
  87. *
  88. */
  89. static size_t a3xx_snapshot_shader_memory(struct kgsl_device *device,
  90. u8 *buf, size_t remain, void *priv)
  91. {
  92. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf;
  93. void *data = buf + sizeof(*header);
  94. unsigned int shader_read_len = SHADER_MEMORY_SIZE;
  95. if (remain < DEBUG_SECTION_SZ(shader_read_len)) {
  96. SNAPSHOT_ERR_NOMEM(device, "SHADER MEMORY");
  97. return 0;
  98. }
  99. header->type = SNAPSHOT_DEBUG_SHADER_MEMORY;
  100. header->size = shader_read_len;
  101. /* Map shader memory to kernel, for dumping */
  102. if (IS_ERR_OR_NULL(device->shader_mem_virt)) {
  103. struct resource *res;
  104. res = platform_get_resource_byname(device->pdev,
  105. IORESOURCE_MEM, "kgsl_3d0_shader_memory");
  106. if (res)
  107. device->shader_mem_virt =
  108. devm_ioremap_resource(&device->pdev->dev, res);
  109. }
  110. if (IS_ERR_OR_NULL(device->shader_mem_virt)) {
  111. dev_err(device->dev, "Unable to map the shader memory\n");
  112. return 0;
  113. }
  114. memcpy_fromio(data, device->shader_mem_virt, shader_read_len << 2);
  115. return DEBUG_SECTION_SZ(shader_read_len);
  116. }
  117. static size_t a3xx_snapshot_debugbus_block(struct kgsl_device *device,
  118. u8 *buf, size_t remain, void *priv)
  119. {
  120. struct kgsl_snapshot_debugbus *header
  121. = (struct kgsl_snapshot_debugbus *)buf;
  122. struct adreno_debugbus_block *block = priv;
  123. int i;
  124. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  125. size_t size;
  126. size = (0x40 * sizeof(unsigned int)) + sizeof(*header);
  127. if (remain < size) {
  128. SNAPSHOT_ERR_NOMEM(device, "DEBUGBUS");
  129. return 0;
  130. }
  131. header->id = block->block_id;
  132. header->count = 0x40;
  133. for (i = 0; i < 0x40; i++)
  134. _rbbm_debug_bus_read(device, block->block_id, i, &data[i]);
  135. return size;
  136. }
  137. static struct adreno_debugbus_block debugbus_blocks[] = {
  138. { RBBM_BLOCK_ID_CP, 0x52, },
  139. { RBBM_BLOCK_ID_RBBM, 0x40, },
  140. { RBBM_BLOCK_ID_VBIF, 0x40, },
  141. { RBBM_BLOCK_ID_HLSQ, 0x40, },
  142. { RBBM_BLOCK_ID_UCHE, 0x40, },
  143. { RBBM_BLOCK_ID_PC, 0x40, },
  144. { RBBM_BLOCK_ID_VFD, 0x40, },
  145. { RBBM_BLOCK_ID_VPC, 0x40, },
  146. { RBBM_BLOCK_ID_TSE, 0x40, },
  147. { RBBM_BLOCK_ID_RAS, 0x40, },
  148. { RBBM_BLOCK_ID_VSC, 0x40, },
  149. { RBBM_BLOCK_ID_SP_0, 0x40, },
  150. { RBBM_BLOCK_ID_SP_1, 0x40, },
  151. { RBBM_BLOCK_ID_SP_2, 0x40, },
  152. { RBBM_BLOCK_ID_SP_3, 0x40, },
  153. { RBBM_BLOCK_ID_TPL1_0, 0x40, },
  154. { RBBM_BLOCK_ID_TPL1_1, 0x40, },
  155. { RBBM_BLOCK_ID_TPL1_2, 0x40, },
  156. { RBBM_BLOCK_ID_TPL1_3, 0x40, },
  157. { RBBM_BLOCK_ID_RB_0, 0x40, },
  158. { RBBM_BLOCK_ID_RB_1, 0x40, },
  159. { RBBM_BLOCK_ID_RB_2, 0x40, },
  160. { RBBM_BLOCK_ID_RB_3, 0x40, },
  161. { RBBM_BLOCK_ID_MARB_0, 0x40, },
  162. { RBBM_BLOCK_ID_MARB_1, 0x40, },
  163. { RBBM_BLOCK_ID_MARB_2, 0x40, },
  164. { RBBM_BLOCK_ID_MARB_3, 0x40, },
  165. };
  166. static void a3xx_snapshot_debugbus(struct kgsl_device *device,
  167. struct kgsl_snapshot *snapshot)
  168. {
  169. int i;
  170. for (i = 0; i < ARRAY_SIZE(debugbus_blocks); i++) {
  171. kgsl_snapshot_add_section(device,
  172. KGSL_SNAPSHOT_SECTION_DEBUGBUS, snapshot,
  173. a3xx_snapshot_debugbus_block,
  174. (void *) &debugbus_blocks[i]);
  175. }
  176. }
  177. static void _snapshot_hlsq_regs(struct kgsl_device *device,
  178. struct kgsl_snapshot *snapshot)
  179. {
  180. unsigned int next_pif = 0;
  181. /*
  182. * Trying to read HLSQ registers when the HLSQ block is busy
  183. * will cause the device to hang. The RBBM_DEBUG_BUS has information
  184. * that will tell us if the HLSQ block is busy or not. Read values
  185. * from the debug bus to ensure the HLSQ block is not busy (this
  186. * is hardware dependent). If the HLSQ block is busy do not
  187. * dump the registers, otherwise dump the HLSQ registers.
  188. */
  189. /*
  190. * tpif status bits: RBBM_BLOCK_ID_HLSQ index 4 [4:0]
  191. * spif status bits: RBBM_BLOCK_ID_HLSQ index 7 [5:0]
  192. *
  193. * if ((tpif == 0, 1, 28) && (spif == 0, 1, 10))
  194. * then dump HLSQ registers
  195. */
  196. /* check tpif */
  197. _rbbm_debug_bus_read(device, RBBM_BLOCK_ID_HLSQ, 4, &next_pif);
  198. next_pif &= 0x1f;
  199. if (next_pif != 0 && next_pif != 1 && next_pif != 28)
  200. return;
  201. /* check spif */
  202. _rbbm_debug_bus_read(device, RBBM_BLOCK_ID_HLSQ, 7, &next_pif);
  203. next_pif &= 0x3f;
  204. if (next_pif != 0 && next_pif != 1 && next_pif != 10)
  205. return;
  206. SNAPSHOT_REGISTERS(device, snapshot, a3xx_hlsq_registers);
  207. }
  208. #define VPC_MEM_SIZE 512
  209. static size_t a3xx_snapshot_vpc_memory(struct kgsl_device *device, u8 *buf,
  210. size_t remain, void *priv)
  211. {
  212. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf;
  213. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  214. size_t size = 4 * VPC_MEM_SIZE;
  215. int bank, addr, i = 0;
  216. if (remain < DEBUG_SECTION_SZ(size)) {
  217. SNAPSHOT_ERR_NOMEM(device, "VPC MEMORY");
  218. return 0;
  219. }
  220. header->type = SNAPSHOT_DEBUG_VPC_MEMORY;
  221. header->size = size;
  222. for (bank = 0; bank < 4; bank++) {
  223. for (addr = 0; addr < VPC_MEM_SIZE; addr++) {
  224. unsigned int val = bank | (addr << 4);
  225. kgsl_regwrite(device, A3XX_VPC_VPC_DEBUG_RAM_SEL, val);
  226. kgsl_regread(device, A3XX_VPC_VPC_DEBUG_RAM_READ,
  227. &data[i++]);
  228. }
  229. }
  230. return DEBUG_SECTION_SZ(size);
  231. }
  232. static size_t a3xx_snapshot_cp_pm4_ram(struct kgsl_device *device, u8 *buf,
  233. size_t remain, void *priv)
  234. {
  235. struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  236. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf;
  237. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  238. struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_PM4);
  239. size_t size = fw->size - 1;
  240. if (remain < DEBUG_SECTION_SZ(size)) {
  241. SNAPSHOT_ERR_NOMEM(device, "CP PM4 RAM DEBUG");
  242. return 0;
  243. }
  244. header->type = SNAPSHOT_DEBUG_CP_PM4_RAM;
  245. header->size = size;
  246. /*
  247. * Read the firmware from the GPU rather than use our cache in order to
  248. * try to catch mis-programming or corruption in the hardware. We do
  249. * use the cached version of the size, however, instead of trying to
  250. * maintain always changing hardcoded constants
  251. */
  252. kgsl_regmap_read_indexed(&device->regmap, A3XX_CP_ME_RAM_RADDR,
  253. A3XX_CP_ME_RAM_DATA, data, size);
  254. return DEBUG_SECTION_SZ(size);
  255. }
  256. static size_t a3xx_snapshot_cp_pfp_ram(struct kgsl_device *device, u8 *buf,
  257. size_t remain, void *priv)
  258. {
  259. struct adreno_device *adreno_dev = ADRENO_DEVICE(device);
  260. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *)buf;
  261. unsigned int *data = (unsigned int *)(buf + sizeof(*header));
  262. struct adreno_firmware *fw = ADRENO_FW(adreno_dev, ADRENO_FW_PFP);
  263. int size = fw->size - 1;
  264. if (remain < DEBUG_SECTION_SZ(size)) {
  265. SNAPSHOT_ERR_NOMEM(device, "CP PFP RAM DEBUG");
  266. return 0;
  267. }
  268. header->type = SNAPSHOT_DEBUG_CP_PFP_RAM;
  269. header->size = size;
  270. /*
  271. * Read the firmware from the GPU rather than use our cache in order to
  272. * try to catch mis-programming or corruption in the hardware. We do
  273. * use the cached version of the size, however, instead of trying to
  274. * maintain always changing hardcoded constants
  275. */
  276. kgsl_regmap_read_indexed(&device->regmap, A3XX_CP_PFP_UCODE_ADDR,
  277. A3XX_CP_PFP_UCODE_DATA, data, size);
  278. return DEBUG_SECTION_SZ(size);
  279. }
  280. static size_t a3xx_snapshot_cp_roq(struct kgsl_device *device, u8 *buf,
  281. size_t remain, void *priv)
  282. {
  283. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *) buf;
  284. u32 *data = (u32 *) (buf + sizeof(*header));
  285. if (remain < DEBUG_SECTION_SZ(128)) {
  286. SNAPSHOT_ERR_NOMEM(device, "CP ROQ DEBUG");
  287. return 0;
  288. }
  289. header->type = SNAPSHOT_DEBUG_CP_ROQ;
  290. header->size = 128;
  291. kgsl_regmap_read_indexed(&device->regmap, A3XX_CP_ROQ_ADDR,
  292. A3XX_CP_ROQ_DATA, data, 128);
  293. return DEBUG_SECTION_SZ(128);
  294. }
  295. static size_t a3xx_snapshot_cp_meq(struct kgsl_device *device, u8 *buf,
  296. size_t remain, void *priv)
  297. {
  298. struct kgsl_snapshot_debug *header = (struct kgsl_snapshot_debug *) buf;
  299. u32 *data = (u32 *) (buf + sizeof(*header));
  300. if (remain < DEBUG_SECTION_SZ(16)) {
  301. SNAPSHOT_ERR_NOMEM(device, "CP MEQ DEBUG");
  302. return 0;
  303. }
  304. header->type = SNAPSHOT_DEBUG_CP_MEQ;
  305. header->size = 16;
  306. kgsl_regmap_read_indexed(&device->regmap, A3XX_CP_MEQ_ADDR,
  307. A3XX_CP_MEQ_DATA, data, 16);
  308. return DEBUG_SECTION_SZ(16);
  309. }
  310. /*
  311. * a3xx_snapshot() - A3XX GPU snapshot function
  312. * @adreno_dev: Device being snapshotted
  313. * @snapshot: Snapshot metadata
  314. * @remain: Amount of space left in snapshot memory
  315. *
  316. * This is where all of the A3XX specific bits and pieces are grabbed
  317. * into the snapshot memory
  318. */
  319. void a3xx_snapshot(struct adreno_device *adreno_dev,
  320. struct kgsl_snapshot *snapshot)
  321. {
  322. struct kgsl_device *device = KGSL_DEVICE(adreno_dev);
  323. unsigned int reg;
  324. /* Disable Clock gating temporarily for the debug bus to work */
  325. kgsl_regwrite(device, A3XX_RBBM_CLOCK_CTL, 0x0);
  326. /* Save some CP information that the generic snapshot uses */
  327. kgsl_regread(device, A3XX_CP_IB1_BASE, &reg);
  328. snapshot->ib1base = (u64) reg;
  329. kgsl_regread(device, A3XX_CP_IB2_BASE, &reg);
  330. snapshot->ib2base = (u64) reg;
  331. kgsl_regread(device, A3XX_CP_IB1_BUFSZ, &snapshot->ib1size);
  332. kgsl_regread(device, A3XX_CP_IB2_BUFSZ, &snapshot->ib2size);
  333. SNAPSHOT_REGISTERS(device, snapshot, a3xx_registers);
  334. _snapshot_hlsq_regs(device, snapshot);
  335. kgsl_snapshot_indexed_registers(device, snapshot,
  336. A3XX_CP_STATE_DEBUG_INDEX, A3XX_CP_STATE_DEBUG_DATA, 0, 0x14);
  337. /* CP_ME indexed registers */
  338. kgsl_snapshot_indexed_registers(device, snapshot,
  339. A3XX_CP_ME_CNTL, A3XX_CP_ME_STATUS, 64, 44);
  340. /* VPC memory */
  341. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  342. snapshot, a3xx_snapshot_vpc_memory, NULL);
  343. /* CP MEQ */
  344. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG, snapshot,
  345. a3xx_snapshot_cp_meq, NULL);
  346. /* Shader working/shadow memory */
  347. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  348. snapshot, a3xx_snapshot_shader_memory, NULL);
  349. /* CP PFP and PM4 */
  350. /*
  351. * Reading the microcode while the CP is running will
  352. * basically move the CP instruction pointer to
  353. * whatever address we read. Big badaboom ensues. Stop the CP
  354. * (if it isn't already stopped) to ensure that we are safe.
  355. * We do this here and not earlier to avoid corrupting the RBBM
  356. * status and CP registers - by the time we get here we don't
  357. * care about the contents of the CP anymore.
  358. */
  359. kgsl_regread(device, A3XX_CP_ME_CNTL, &reg);
  360. reg |= (1 << 27) | (1 << 28);
  361. kgsl_regwrite(device, A3XX_CP_ME_CNTL, reg);
  362. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  363. snapshot, a3xx_snapshot_cp_pfp_ram, NULL);
  364. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  365. snapshot, a3xx_snapshot_cp_pm4_ram, NULL);
  366. /* CP ROQ */
  367. kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_DEBUG,
  368. snapshot, a3xx_snapshot_cp_roq, NULL);
  369. a3xx_snapshot_debugbus(device, snapshot);
  370. }