kgsl_snapshot.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331
  1. /* Copyright (c) 2012, 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. #ifndef _KGSL_SNAPSHOT_H_
  14. #define _KGSL_SNAPSHOT_H_
  15. #include <linux/types.h>
  16. /* Snapshot header */
  17. /* High word is static, low word is snapshot version ID */
  18. #define SNAPSHOT_MAGIC 0x504D0002
  19. /* GPU ID scheme:
  20. * [16:31] - core identifer (0x0002 for 2D or 0x0003 for 3D)
  21. * [00:16] - GPU specific identifier
  22. */
  23. struct kgsl_snapshot_header {
  24. __u32 magic; /* Magic identifier */
  25. __u32 gpuid; /* GPU ID - see above */
  26. /* Added in snapshot version 2 */
  27. __u32 chipid; /* Chip ID from the GPU */
  28. } __packed;
  29. /* Section header */
  30. #define SNAPSHOT_SECTION_MAGIC 0xABCD
  31. struct kgsl_snapshot_section_header {
  32. __u16 magic; /* Magic identifier */
  33. __u16 id; /* Type of section */
  34. __u32 size; /* Size of the section including this header */
  35. } __packed;
  36. /* Section identifiers */
  37. #define KGSL_SNAPSHOT_SECTION_OS 0x0101
  38. #define KGSL_SNAPSHOT_SECTION_REGS 0x0201
  39. #define KGSL_SNAPSHOT_SECTION_RB 0x0301
  40. #define KGSL_SNAPSHOT_SECTION_IB 0x0401
  41. #define KGSL_SNAPSHOT_SECTION_INDEXED_REGS 0x0501
  42. #define KGSL_SNAPSHOT_SECTION_ISTORE 0x0801
  43. #define KGSL_SNAPSHOT_SECTION_DEBUG 0x0901
  44. #define KGSL_SNAPSHOT_SECTION_DEBUGBUS 0x0A01
  45. #define KGSL_SNAPSHOT_SECTION_GPU_OBJECT 0x0B01
  46. #define KGSL_SNAPSHOT_SECTION_MEMLIST 0x0E01
  47. #define KGSL_SNAPSHOT_SECTION_END 0xFFFF
  48. /* OS sub-section header */
  49. #define KGSL_SNAPSHOT_OS_LINUX 0x0001
  50. /* Linux OS specific information */
  51. #define SNAPSHOT_STATE_HUNG 0
  52. #define SNAPSHOT_STATE_RUNNING 1
  53. struct kgsl_snapshot_linux {
  54. int osid; /* subsection OS identifier */
  55. int state; /* 1 if the thread is running, 0 for hung */
  56. __u32 seconds; /* Unix timestamp for the snapshot */
  57. __u32 power_flags; /* Current power flags */
  58. __u32 power_level; /* Current power level */
  59. __u32 power_interval_timeout; /* Power interval timeout */
  60. __u32 grpclk; /* Current GP clock value */
  61. __u32 busclk; /* Current busclk value */
  62. __u32 ptbase; /* Current ptbase */
  63. __u32 pid; /* PID of the process that owns the PT */
  64. __u32 current_context; /* ID of the current context */
  65. __u32 ctxtcount; /* Number of contexts appended to section */
  66. unsigned char release[32]; /* kernel release */
  67. unsigned char version[32]; /* kernel version */
  68. unsigned char comm[16]; /* Name of the process that owns the PT */
  69. } __packed;
  70. /*
  71. * This structure contains a record of an active context.
  72. * These are appended one after another in the OS section below
  73. * the header above
  74. */
  75. struct kgsl_snapshot_linux_context {
  76. __u32 id; /* The context ID */
  77. __u32 timestamp_queued; /* The last queued timestamp */
  78. __u32 timestamp_retired; /* The last timestamp retired by HW */
  79. };
  80. /* Ringbuffer sub-section header */
  81. struct kgsl_snapshot_rb {
  82. int start; /* dword at the start of the dump */
  83. int end; /* dword at the end of the dump */
  84. int rbsize; /* Size (in dwords) of the ringbuffer */
  85. int wptr; /* Current index of the CPU write pointer */
  86. int rptr; /* Current index of the GPU read pointer */
  87. int count; /* Number of dwords in the dump */
  88. } __packed;
  89. /* Replay or Memory list section, both sections have same header */
  90. struct kgsl_snapshot_replay_mem_list {
  91. /*
  92. * Number of IBs to replay for replay section or
  93. * number of memory list entries for mem list section
  94. */
  95. int num_entries;
  96. /* Pagetable base to which the replay IBs or memory entries belong */
  97. __u32 ptbase;
  98. } __packed;
  99. /* Indirect buffer sub-section header */
  100. struct kgsl_snapshot_ib {
  101. __u32 gpuaddr; /* GPU address of the the IB */
  102. __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
  103. int size; /* Size of the IB */
  104. } __packed;
  105. /* Register sub-section header */
  106. struct kgsl_snapshot_regs {
  107. __u32 count; /* Number of register pairs in the section */
  108. } __packed;
  109. /* Indexed register sub-section header */
  110. struct kgsl_snapshot_indexed_regs {
  111. __u32 index_reg; /* Offset of the index register for this section */
  112. __u32 data_reg; /* Offset of the data register for this section */
  113. int start; /* Starting index */
  114. int count; /* Number of dwords in the data */
  115. } __packed;
  116. /* Istore sub-section header */
  117. struct kgsl_snapshot_istore {
  118. int count; /* Number of instructions in the istore */
  119. } __packed;
  120. /* Debug data sub-section header */
  121. /* A2XX debug sections */
  122. #define SNAPSHOT_DEBUG_SX 1
  123. #define SNAPSHOT_DEBUG_CP 2
  124. #define SNAPSHOT_DEBUG_SQ 3
  125. #define SNAPSHOT_DEBUG_SQTHREAD 4
  126. #define SNAPSHOT_DEBUG_MIU 5
  127. /* A3XX debug sections */
  128. #define SNAPSHOT_DEBUG_VPC_MEMORY 6
  129. #define SNAPSHOT_DEBUG_CP_MEQ 7
  130. #define SNAPSHOT_DEBUG_CP_PM4_RAM 8
  131. #define SNAPSHOT_DEBUG_CP_PFP_RAM 9
  132. #define SNAPSHOT_DEBUG_CP_ROQ 10
  133. #define SNAPSHOT_DEBUG_SHADER_MEMORY 11
  134. #define SNAPSHOT_DEBUG_CP_MERCIU 12
  135. struct kgsl_snapshot_debug {
  136. int type; /* Type identifier for the attached tata */
  137. int size; /* Size of the section in dwords */
  138. } __packed;
  139. struct kgsl_snapshot_debugbus {
  140. int id; /* Debug bus ID */
  141. int count; /* Number of dwords in the dump */
  142. } __packed;
  143. #define SNAPSHOT_GPU_OBJECT_SHADER 1
  144. #define SNAPSHOT_GPU_OBJECT_IB 2
  145. #define SNAPSHOT_GPU_OBJECT_GENERIC 3
  146. struct kgsl_snapshot_gpu_object {
  147. int type; /* Type of GPU object */
  148. __u32 gpuaddr; /* GPU address of the the object */
  149. __u32 ptbase; /* Base for the pagetable the GPU address is valid in */
  150. int size; /* Size of the object (in dwords) */
  151. };
  152. #ifdef __KERNEL__
  153. /* Allocate 512K for each device snapshot */
  154. #define KGSL_SNAPSHOT_MEMSIZE (512 * 1024)
  155. struct kgsl_device;
  156. /*
  157. * A helper macro to print out "not enough memory functions" - this
  158. * makes it easy to standardize the messages as well as cut down on
  159. * the number of strings in the binary
  160. */
  161. #define SNAPSHOT_ERR_NOMEM(_d, _s) \
  162. KGSL_DRV_ERR((_d), \
  163. "snapshot: not enough snapshot memory for section %s\n", (_s))
  164. /*
  165. * kgsl_snapshot_add_section - Add a new section to the GPU snapshot
  166. * @device - the KGSL device being snapshotted
  167. * @id - the section id
  168. * @snapshot - pointer to the memory for the snapshot
  169. * @remain - pointer to the number of bytes left in the snapshot region
  170. * @func - Function pointer to fill the section
  171. * @priv - Priv pointer to pass to the function
  172. *
  173. * Set up a KGSL snapshot header by filling the memory with the callback
  174. * function and adding the standard section header
  175. */
  176. static inline void *kgsl_snapshot_add_section(struct kgsl_device *device,
  177. u16 id, void *snapshot, int *remain,
  178. int (*func)(struct kgsl_device *, void *, int, void *), void *priv)
  179. {
  180. struct kgsl_snapshot_section_header *header = snapshot;
  181. void *data = snapshot + sizeof(*header);
  182. int ret = 0;
  183. /*
  184. * Sanity check to make sure there is enough for the header. The
  185. * callback will check to make sure there is enough for the rest
  186. * of the data. If there isn't enough room then don't advance the
  187. * pointer.
  188. */
  189. if (*remain < sizeof(*header))
  190. return snapshot;
  191. /* It is legal to have no function (i.e. - make an empty section) */
  192. if (func) {
  193. ret = func(device, data, *remain, priv);
  194. /*
  195. * If there wasn't enough room for the data then don't bother
  196. * setting up the header.
  197. */
  198. if (ret == 0)
  199. return snapshot;
  200. }
  201. header->magic = SNAPSHOT_SECTION_MAGIC;
  202. header->id = id;
  203. header->size = ret + sizeof(*header);
  204. /* Decrement the room left in the snapshot region */
  205. *remain -= header->size;
  206. /* Advance the pointer to the end of the next function */
  207. return snapshot + header->size;
  208. }
  209. /* A common helper function to dump a range of registers. This will be used in
  210. * the GPU specific devices like this:
  211. *
  212. * struct kgsl_snapshot_registers_list list;
  213. * struct kgsl_snapshot_registers priv[2];
  214. *
  215. * priv[0].regs = registers_array;;
  216. * priv[o].count = num_registers;
  217. * priv[1].regs = registers_array_new;;
  218. * priv[1].count = num_registers_new;
  219. *
  220. * list.registers = priv;
  221. * list.count = 2;
  222. *
  223. * kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_REGS, snapshot,
  224. * remain, kgsl_snapshot_dump_regs, &list).
  225. *
  226. * Pass in a struct pointing to a list of register definitions as described
  227. * below:
  228. *
  229. * Pass in an array of register range pairs in the form of:
  230. * start reg, stop reg
  231. * All the registers between start and stop inclusive will be dumped
  232. */
  233. struct kgsl_snapshot_registers {
  234. unsigned int *regs; /* Pointer to the array of register ranges */
  235. int count; /* Number of entries in the array */
  236. };
  237. struct kgsl_snapshot_registers_list {
  238. /* Pointer to an array of register lists */
  239. struct kgsl_snapshot_registers *registers;
  240. /* Number of registers lists in the array */
  241. int count;
  242. };
  243. int kgsl_snapshot_dump_regs(struct kgsl_device *device, void *snapshot,
  244. int remain, void *priv);
  245. /*
  246. * A common helper function to dump a set of indexed registers. Use it
  247. * like this:
  248. *
  249. * struct kgsl_snapshot_indexed_registers priv;
  250. * priv.index = REG_INDEX;
  251. * priv.data = REG_DATA;
  252. * priv.count = num_registers
  253. *
  254. * kgsl_snapshot_add_section(device, KGSL_SNAPSHOT_SECTION_INDEXED_REGS,
  255. * snapshot, remain, kgsl_snapshot_dump_indexed_regs, &priv).
  256. *
  257. * The callback function will write an index from 0 to priv.count to
  258. * the index register and read the data from the data register.
  259. */
  260. struct kgsl_snapshot_indexed_registers {
  261. unsigned int index; /* Offset of the index register */
  262. unsigned int data; /* Offset of the data register */
  263. unsigned int start; /* Index to start with */
  264. unsigned int count; /* Number of values to read from the pair */
  265. };
  266. /* Helper function to snapshot a section of indexed registers */
  267. void *kgsl_snapshot_indexed_registers(struct kgsl_device *device,
  268. void *snapshot, int *remain, unsigned int index,
  269. unsigned int data, unsigned int start, unsigned int count);
  270. /* Freeze a GPU buffer so it can be dumped in the snapshot */
  271. int kgsl_snapshot_get_object(struct kgsl_device *device, phys_addr_t ptbase,
  272. unsigned int gpuaddr, unsigned int size, unsigned int type);
  273. int kgsl_snapshot_have_object(struct kgsl_device *device, phys_addr_t ptbase,
  274. unsigned int gpuaddr, unsigned int size);
  275. #endif
  276. #endif