kgsl_snapshot.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417
  1. /* SPDX-License-Identifier: GPL-2.0-only */
  2. /*
  3. * Copyright (c) 2012-2021, The Linux Foundation. All rights reserved.
  4. * Copyright (c) 2022-2024, Qualcomm Innovation Center, Inc. All rights reserved.
  5. */
  6. #ifndef _KGSL_SNAPSHOT_H_
  7. #define _KGSL_SNAPSHOT_H_
  8. #include <linux/types.h>
  9. /* Snapshot header */
  10. /* High word is static, low word is snapshot version ID */
  11. #define SNAPSHOT_MAGIC 0x504D0002
  12. /* GPU ID scheme:
  13. * [16:31] - core identifer (0x0002 for 2D or 0x0003 for 3D)
  14. * [00:16] - GPU specific identifier
  15. */
  16. struct kgsl_snapshot_header {
  17. __u32 magic; /* Magic identifier */
  18. __u32 gpuid; /* GPU ID - see above */
  19. /* Added in snapshot version 2 */
  20. __u32 chipid; /* Chip ID from the GPU */
  21. } __packed;
  22. /* Section header */
  23. #define SNAPSHOT_SECTION_MAGIC 0xABCD
  24. struct kgsl_snapshot_section_header {
  25. __u16 magic; /* Magic identifier */
  26. __u16 id; /* Type of section */
  27. __u32 size; /* Size of the section including this header */
  28. } __packed;
  29. /* Section identifiers */
  30. #define KGSL_SNAPSHOT_SECTION_OS 0x0101
  31. #define KGSL_SNAPSHOT_SECTION_REGS 0x0201
  32. #define KGSL_SNAPSHOT_SECTION_REGS_V2 0x0202
  33. #define KGSL_SNAPSHOT_SECTION_RB 0x0301
  34. #define KGSL_SNAPSHOT_SECTION_RB_V2 0x0302
  35. #define KGSL_SNAPSHOT_SECTION_IB 0x0401
  36. #define KGSL_SNAPSHOT_SECTION_IB_V2 0x0402
  37. #define KGSL_SNAPSHOT_SECTION_INDEXED_REGS 0x0501
  38. #define KGSL_SNAPSHOT_SECTION_INDEXED_REGS_V2 0x0502
  39. #define KGSL_SNAPSHOT_SECTION_ISTORE 0x0801
  40. #define KGSL_SNAPSHOT_SECTION_DEBUG 0x0901
  41. #define KGSL_SNAPSHOT_SECTION_DEBUGBUS 0x0A01
  42. #define KGSL_SNAPSHOT_SECTION_GPU_OBJECT 0x0B01
  43. #define KGSL_SNAPSHOT_SECTION_GPU_OBJECT_V2 0x0B02
  44. #define KGSL_SNAPSHOT_SECTION_MEMLIST 0x0E01
  45. #define KGSL_SNAPSHOT_SECTION_MEMLIST_V2 0x0E02
  46. #define KGSL_SNAPSHOT_SECTION_SHADER 0x1201
  47. #define KGSL_SNAPSHOT_SECTION_SHADER_V2 0x1202
  48. #define KGSL_SNAPSHOT_SECTION_SHADER_V3 0x1203
  49. #define KGSL_SNAPSHOT_SECTION_MVC 0x1501
  50. #define KGSL_SNAPSHOT_SECTION_MVC_V2 0x1502
  51. #define KGSL_SNAPSHOT_SECTION_MVC_V3 0x1503
  52. #define KGSL_SNAPSHOT_SECTION_GMU 0x1601
  53. #define KGSL_SNAPSHOT_SECTION_GMU_MEMORY 0x1701
  54. #define KGSL_SNAPSHOT_SECTION_SIDE_DEBUGBUS 0x1801
  55. #define KGSL_SNAPSHOT_SECTION_TRACE_BUFFER 0x1901
  56. #define KGSL_SNAPSHOT_SECTION_EVENTLOG 0x1A01
  57. #define KGSL_SNAPSHOT_SECTION_END 0xFFFF
  58. /* OS sub-section header */
  59. #define KGSL_SNAPSHOT_OS_LINUX 0x0001
  60. #define KGSL_SNAPSHOT_OS_LINUX_V3 0x00000202
  61. #define KGSL_SNAPSHOT_OS_LINUX_V4 0x00000203
  62. /* Linux OS specific information */
  63. struct kgsl_snapshot_linux {
  64. int osid; /* subsection OS identifier */
  65. int state; /* 1 if the thread is running, 0 for hung */
  66. __u32 seconds; /* Unix timestamp for the snapshot */
  67. __u32 power_flags; /* Current power flags */
  68. __u32 power_level; /* Current power level */
  69. __u32 power_interval_timeout; /* Power interval timeout */
  70. __u32 grpclk; /* Current GP clock value */
  71. __u32 busclk; /* Current busclk value */
  72. __u32 ptbase; /* Current ptbase */
  73. __u32 pid; /* PID of the process that owns the PT */
  74. __u32 current_context; /* ID of the current context */
  75. __u32 ctxtcount; /* Number of contexts appended to section */
  76. unsigned char release[32]; /* kernel release */
  77. unsigned char version[32]; /* kernel version */
  78. unsigned char comm[16]; /* Name of the process that owns the PT */
  79. } __packed;
  80. struct kgsl_snapshot_linux_v2 {
  81. int osid; /* subsection OS identifier */
  82. __u32 seconds; /* Unix timestamp for the snapshot */
  83. __u32 power_flags; /* Current power flags */
  84. __u32 power_level; /* Current power level */
  85. __u32 power_interval_timeout; /* Power interval timeout */
  86. __u32 grpclk; /* Current GP clock value */
  87. __u32 busclk; /* Current busclk value */
  88. __u64 ptbase; /* Current ptbase */
  89. __u32 pid; /* PID of the process that owns the PT */
  90. __u32 current_context; /* ID of the current context */
  91. __u32 ctxtcount; /* Number of contexts appended to section */
  92. unsigned char release[32]; /* kernel release */
  93. unsigned char version[32]; /* kernel version */
  94. unsigned char comm[16]; /* Name of the process that owns the PT */
  95. } __packed;
  96. struct kgsl_snapshot_linux_v4 {
  97. int osid; /* subsection OS identifier */
  98. __u32 seconds; /* Unix timestamp for the snapshot */
  99. __u32 power_flags; /* Current power flags */
  100. __u32 power_level; /* Current power level */
  101. __u32 power_interval_timeout; /* Power interval timeout */
  102. __u32 grpclk; /* Current GP clock value */
  103. __u32 busclk; /* Current busclk value */
  104. __u64 ptbase; /* Current ptbase */
  105. __u64 ptbase_lpac; /* Current LPAC ptbase */
  106. __u32 pid; /* PID of the process that owns the PT */
  107. __u32 pid_lpac; /* PID of the LPAC process that owns the PT */
  108. __u32 current_context; /* ID of the current context */
  109. __u32 current_context_lpac; /* ID of the current LPAC context */
  110. __u32 ctxtcount; /* Number of contexts appended to section */
  111. unsigned char release[32]; /* kernel release */
  112. unsigned char version[32]; /* kernel version */
  113. unsigned char comm[16]; /* Name of the process that owns the PT */
  114. unsigned char comm_lpac[16]; /* Name of the LPAC process that owns the PT */
  115. } __packed;
  116. /*
  117. * This structure contains a record of an active context.
  118. * These are appended one after another in the OS section below
  119. * the header above
  120. */
  121. struct kgsl_snapshot_linux_context {
  122. __u32 id; /* The context ID */
  123. __u32 timestamp_queued; /* The last queued timestamp */
  124. __u32 timestamp_retired; /* The last timestamp retired by HW */
  125. };
  126. struct kgsl_snapshot_linux_context_v2 {
  127. __u32 id; /* The context ID */
  128. __u32 timestamp_queued; /* The last queued timestamp */
  129. __u32 timestamp_consumed; /* The last timestamp consumed by HW */
  130. __u32 timestamp_retired; /* The last timestamp retired by HW */
  131. };
  132. /* Ringbuffer sub-section header */
  133. struct kgsl_snapshot_rb {
  134. int start; /* dword at the start of the dump */
  135. int end; /* dword at the end of the dump */
  136. int rbsize; /* Size (in dwords) of the ringbuffer */
  137. int wptr; /* Current index of the CPU write pointer */
  138. int rptr; /* Current index of the GPU read pointer */
  139. int count; /* Number of dwords in the dump */
  140. __u32 timestamp_queued; /* The last queued timestamp */
  141. __u32 timestamp_retired; /* The last timestamp retired by HW */
  142. } __packed;
  143. struct kgsl_snapshot_rb_v2 {
  144. int start; /* dword at the start of the dump */
  145. int end; /* dword at the end of the dump */
  146. int rbsize; /* Size (in dwords) of the ringbuffer */
  147. int wptr; /* Current index of the CPU write pointer */
  148. int rptr; /* Current index of the GPU read pointer */
  149. int count; /* Number of dwords in the dump */
  150. __u32 timestamp_queued; /* The last queued timestamp */
  151. __u32 timestamp_retired; /* The last timestamp retired by HW */
  152. __u64 gpuaddr; /* The GPU address of the ringbuffer */
  153. __u32 id; /* Ringbuffer identifier */
  154. } __packed;
  155. /* Replay or Memory list section, both sections have same header */
  156. struct kgsl_snapshot_replay_mem_list {
  157. /*
  158. * Number of IBs to replay for replay section or
  159. * number of memory list entries for mem list section
  160. */
  161. int num_entries;
  162. /* Pagetable base to which the replay IBs or memory entries belong */
  163. __u32 ptbase;
  164. } __packed;
  165. /* Replay or Memory list section, both sections have same header */
  166. struct kgsl_snapshot_mem_list_v2 {
  167. /*
  168. * Number of IBs to replay for replay section or
  169. * number of memory list entries for mem list section
  170. */
  171. int num_entries;
  172. /* Pagetable base to which the replay IBs or memory entries belong */
  173. __u64 ptbase;
  174. } __packed;
  175. /* Indirect buffer sub-section header */
  176. struct kgsl_snapshot_ib {
  177. __u32 gpuaddr; /* GPU address of the IB */
  178. __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
  179. int size; /* Size of the IB */
  180. } __packed;
  181. /* Indirect buffer sub-section header (v2) */
  182. struct kgsl_snapshot_ib_v2 {
  183. __u64 gpuaddr; /* GPU address of the IB */
  184. __u64 ptbase; /* Base for the pagetable the GPU address is valid in */
  185. __u64 size; /* Size of the IB */
  186. } __packed;
  187. /* GMU memory ID's */
  188. #define SNAPSHOT_GMU_MEM_UNKNOWN 0x00
  189. #define SNAPSHOT_GMU_MEM_HFI 0x01
  190. #define SNAPSHOT_GMU_MEM_LOG 0x02
  191. #define SNAPSHOT_GMU_MEM_BWTABLE 0x03
  192. #define SNAPSHOT_GMU_MEM_DEBUG 0x04
  193. #define SNAPSHOT_GMU_MEM_BIN_BLOCK 0x05
  194. #define SNAPSHOT_GMU_MEM_CONTEXT_QUEUE 0x06
  195. #define SNAPSHOT_GMU_MEM_HW_FENCE 0x07
  196. #define SNAPSHOT_GMU_MEM_WARMBOOT 0x08
  197. #define SNAPSHOT_GMU_MEM_VRB 0x09
  198. #define SNAPSHOT_GMU_MEM_TRACE 0x0a
  199. /* GMU memory section data */
  200. struct kgsl_snapshot_gmu_mem {
  201. int type;
  202. uint64_t hostaddr;
  203. uint64_t gmuaddr;
  204. uint64_t gpuaddr;
  205. } __packed;
  206. /* Register sub-section header */
  207. struct kgsl_snapshot_regs {
  208. __u32 count; /* Number of register pairs in the section */
  209. } __packed;
  210. /* Indexed register sub-section header */
  211. struct kgsl_snapshot_indexed_regs {
  212. __u32 index_reg; /* Offset of the index register for this section */
  213. __u32 data_reg; /* Offset of the data register for this section */
  214. int start; /* Starting index */
  215. int count; /* Number of dwords in the data */
  216. } __packed;
  217. struct kgsl_snapshot_indexed_regs_v2 {
  218. u32 index_reg; /* Offset of the index register for this section */
  219. u32 data_reg; /* Offset of the data register for this section */
  220. u32 start; /* Starting index */
  221. u32 count; /* Number of dwords in the data */
  222. u32 pipe_id; /* Id of pipe, BV, Br etc */
  223. u32 slice_id; /* Slice ID to be dumped */
  224. } __packed;
  225. /* MVC register sub-section header */
  226. struct kgsl_snapshot_mvc_regs {
  227. int ctxt_id;
  228. int cluster_id;
  229. } __packed;
  230. struct kgsl_snapshot_mvc_regs_v2 {
  231. int ctxt_id;
  232. int cluster_id;
  233. int pipe_id;
  234. int location_id;
  235. } __packed;
  236. struct kgsl_snapshot_mvc_regs_v3 {
  237. u32 ctxt_id;
  238. u32 cluster_id;
  239. u32 pipe_id;
  240. u32 location_id;
  241. u32 slice_id;
  242. u32 sp_id;
  243. u32 usptp_id;
  244. } __packed;
  245. /* Istore sub-section header */
  246. struct kgsl_snapshot_istore {
  247. int count; /* Number of instructions in the istore */
  248. } __packed;
  249. /* Debug data sub-section header */
  250. /* A2XX debug sections */
  251. #define SNAPSHOT_DEBUG_SX 1
  252. #define SNAPSHOT_DEBUG_CP 2
  253. #define SNAPSHOT_DEBUG_SQ 3
  254. #define SNAPSHOT_DEBUG_SQTHREAD 4
  255. #define SNAPSHOT_DEBUG_MIU 5
  256. /* A3XX debug sections */
  257. #define SNAPSHOT_DEBUG_VPC_MEMORY 6
  258. #define SNAPSHOT_DEBUG_CP_MEQ 7
  259. #define SNAPSHOT_DEBUG_CP_PM4_RAM 8
  260. #define SNAPSHOT_DEBUG_CP_PFP_RAM 9
  261. #define SNAPSHOT_DEBUG_CP_ROQ 10
  262. #define SNAPSHOT_DEBUG_SHADER_MEMORY 11
  263. #define SNAPSHOT_DEBUG_CP_MERCIU 12
  264. #define SNAPSHOT_DEBUG_SQE_VERSION 14
  265. /* GMU Version information */
  266. #define SNAPSHOT_DEBUG_GMU_CORE_VERSION 15
  267. #define SNAPSHOT_DEBUG_GMU_CORE_DEV_VERSION 16
  268. #define SNAPSHOT_DEBUG_GMU_PWR_VERSION 17
  269. #define SNAPSHOT_DEBUG_GMU_PWR_DEV_VERSION 18
  270. #define SNAPSHOT_DEBUG_GMU_HFI_VERSION 19
  271. #define SNAPSHOT_DEBUG_AQE_VERSION 20
  272. struct kgsl_snapshot_debug {
  273. int type; /* Type identifier for the attached tata */
  274. int size; /* Size of the section in dwords */
  275. } __packed;
  276. struct kgsl_snapshot_debugbus {
  277. int id; /* Debug bus ID */
  278. int count; /* Number of dwords in the dump */
  279. } __packed;
  280. struct kgsl_snapshot_side_debugbus {
  281. int id; /* Debug bus ID */
  282. int size; /* Number of dwords in the dump */
  283. int valid_data; /* Mask of valid bits of the side debugbus */
  284. } __packed;
  285. struct kgsl_snapshot_shader {
  286. int type; /* SP/TP statetype */
  287. int index; /* SP/TP index */
  288. int size; /* Number of dwords in the dump */
  289. } __packed;
  290. struct kgsl_snapshot_shader_v2 {
  291. int type; /* SP/TP statetype */
  292. int index; /* SP/TP index */
  293. int usptp; /* USPTP index */
  294. int pipe_id; /* Pipe id */
  295. int location; /* Location value */
  296. u32 size; /* Number of dwords in the dump */
  297. } __packed;
  298. struct kgsl_snapshot_shader_v3 {
  299. u32 type; /* SP/TP statetype */
  300. u32 slice_id; /* Slice ID */
  301. u32 sp_index; /* SP/TP index */
  302. u32 usptp; /* USPTP index */
  303. u32 pipe_id; /* Pipe id */
  304. u32 location; /* Location value */
  305. u32 ctxt_id; /* Context ID */
  306. u32 size; /* Number of dwords in the dump */
  307. } __packed;
  308. #define TRACE_BUF_NUM_SIG 4
  309. /**
  310. * enum trace_buffer_source - Bits to identify the source block of trace buffer information
  311. * GX_DBGC : Signals captured from GX block
  312. * CX_DBGC : Signals captured from CX block
  313. */
  314. enum trace_buffer_source {
  315. GX_DBGC = 1,
  316. CX_DBGC = 2,
  317. };
  318. /**
  319. * kgsl_snapshot_trace_buffer: Header Information for the tracebuffer in snapshot.
  320. */
  321. struct kgsl_snapshot_trace_buffer {
  322. /** @dbgc_ctrl: Identify source for trace */
  323. __u16 dbgc_ctrl;
  324. /** @dbgc_ctrl: Identify source for trace */
  325. __u16 segment;
  326. /** @granularity: The total number of segments in each packet */
  327. __u16 granularity;
  328. /** @ping_blk: Signal block */
  329. __u16 ping_blk[TRACE_BUF_NUM_SIG];
  330. /** @ping_idx: Signal Index */
  331. __u16 ping_idx[TRACE_BUF_NUM_SIG];
  332. /** @size: Number of bytes in the dump */
  333. __u32 size;
  334. } __packed;
  335. #define SNAPSHOT_GPU_OBJECT_SHADER 1
  336. #define SNAPSHOT_GPU_OBJECT_IB 2
  337. #define SNAPSHOT_GPU_OBJECT_GENERIC 3
  338. #define SNAPSHOT_GPU_OBJECT_DRAW 4
  339. #define SNAPSHOT_GPU_OBJECT_GLOBAL 5
  340. struct kgsl_snapshot_gpu_object {
  341. int type; /* Type of GPU object */
  342. __u32 gpuaddr; /* GPU address of the object */
  343. __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
  344. int size; /* Size of the object (in dwords) */
  345. };
  346. struct kgsl_snapshot_gpu_object_v2 {
  347. int type; /* Type of GPU object */
  348. __u64 gpuaddr; /* GPU address of the object */
  349. __u64 ptbase; /* Base for the pagetable the GPU address is valid in */
  350. __u64 size; /* Size of the object (in dwords) */
  351. } __packed;
  352. struct kgsl_snapshot_eventlog {
  353. /** @type: Type of the event log buffer */
  354. __u16 type;
  355. /** @version: Version of the event log buffer */
  356. __u16 version;
  357. /** @size: Size of the eventlog buffer in bytes */
  358. u32 size;
  359. } __packed;
  360. struct kgsl_device;
  361. struct kgsl_process_private;
  362. void kgsl_snapshot_push_object(struct kgsl_device *device,
  363. struct kgsl_process_private *process,
  364. uint64_t gpuaddr, uint64_t dwords);
  365. #endif