i915_gpu_error.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433
  1. /*
  2. * SPDX-License-Identifier: MIT
  3. *
  4. * Copyright © 2008-2018 Intel Corporation
  5. */
  6. #ifndef _I915_GPU_ERROR_H_
  7. #define _I915_GPU_ERROR_H_
  8. #include <linux/atomic.h>
  9. #include <linux/kref.h>
  10. #include <linux/ktime.h>
  11. #include <linux/sched.h>
  12. #include <drm/drm_mm.h>
  13. #include "display/intel_display_device.h"
  14. #include "display/intel_display_params.h"
  15. #include "gt/intel_engine.h"
  16. #include "gt/intel_engine_types.h"
  17. #include "gt/intel_gt_types.h"
  18. #include "gt/uc/intel_uc_fw.h"
  19. #include "intel_device_info.h"
  20. #include "i915_gem.h"
  21. #include "i915_gem_gtt.h"
  22. #include "i915_params.h"
  23. #include "i915_scheduler.h"
  24. struct drm_i915_private;
  25. struct i915_vma_compress;
  26. struct intel_engine_capture_vma;
  27. struct intel_overlay_error_state;
  28. struct i915_vma_coredump {
  29. struct i915_vma_coredump *next;
  30. char name[20];
  31. u64 gtt_offset;
  32. u64 gtt_size;
  33. u32 gtt_page_sizes;
  34. int unused;
  35. struct list_head page_list;
  36. };
  37. struct i915_request_coredump {
  38. unsigned long flags;
  39. pid_t pid;
  40. u32 context;
  41. u32 seqno;
  42. u32 head;
  43. u32 tail;
  44. struct i915_sched_attr sched_attr;
  45. };
  46. struct __guc_capture_parsed_output;
  47. struct intel_engine_coredump {
  48. const struct intel_engine_cs *engine;
  49. bool hung;
  50. bool simulated;
  51. u32 reset_count;
  52. /* position of active request inside the ring */
  53. u32 rq_head, rq_post, rq_tail;
  54. /* Register state */
  55. u32 ccid;
  56. u32 start;
  57. u32 tail;
  58. u32 head;
  59. u32 ctl;
  60. u32 mode;
  61. u32 hws;
  62. u32 ipeir;
  63. u32 ipehr;
  64. u32 esr;
  65. u32 bbstate;
  66. u32 instpm;
  67. u32 instps;
  68. u64 bbaddr;
  69. u64 acthd;
  70. u32 fault_reg;
  71. u64 faddr;
  72. u32 rc_psmi; /* sleep state */
  73. u32 nopid;
  74. u32 excc;
  75. u32 cmd_cctl;
  76. u32 cscmdop;
  77. u32 ctx_sr_ctl;
  78. u32 dma_faddr_hi;
  79. u32 dma_faddr_lo;
  80. struct intel_instdone instdone;
  81. /* GuC matched capture-lists info */
  82. struct intel_guc_state_capture *guc_capture;
  83. struct __guc_capture_parsed_output *guc_capture_node;
  84. struct i915_gem_context_coredump {
  85. char comm[TASK_COMM_LEN];
  86. u64 total_runtime;
  87. u64 avg_runtime;
  88. pid_t pid;
  89. int active;
  90. int guilty;
  91. struct i915_sched_attr sched_attr;
  92. u32 hwsp_seqno;
  93. } context;
  94. struct i915_vma_coredump *vma;
  95. struct i915_request_coredump execlist[EXECLIST_MAX_PORTS];
  96. unsigned int num_ports;
  97. struct {
  98. u32 gfx_mode;
  99. union {
  100. u64 pdp[4];
  101. u32 pp_dir_base;
  102. };
  103. } vm_info;
  104. struct intel_engine_coredump *next;
  105. };
  106. struct intel_ctb_coredump {
  107. u32 raw_head, head;
  108. u32 raw_tail, tail;
  109. u32 raw_status;
  110. u32 desc_offset;
  111. u32 cmds_offset;
  112. u32 size;
  113. };
  114. struct intel_gt_coredump {
  115. const struct intel_gt *_gt;
  116. bool awake;
  117. bool simulated;
  118. struct intel_gt_info info;
  119. /* Generic register state */
  120. u32 eir;
  121. u32 pgtbl_er;
  122. u32 ier;
  123. u32 gtier[6], ngtier;
  124. u32 forcewake;
  125. u32 error; /* gen6+ */
  126. u32 err_int; /* gen7 */
  127. u32 fault_data0; /* gen8, gen9 */
  128. u32 fault_data1; /* gen8, gen9 */
  129. u32 done_reg;
  130. u32 gac_eco;
  131. u32 gam_ecochk;
  132. u32 gab_ctl;
  133. u32 gfx_mode;
  134. u32 gtt_cache;
  135. u32 aux_err; /* gen12 */
  136. u32 gam_done; /* gen12 */
  137. u32 clock_frequency;
  138. u32 clock_period_ns;
  139. /* Display related */
  140. u32 derrmr;
  141. u32 sfc_done[I915_MAX_SFC]; /* gen12 */
  142. u32 nfence;
  143. u64 fence[I915_MAX_NUM_FENCES];
  144. struct intel_engine_coredump *engine;
  145. struct intel_uc_coredump {
  146. struct intel_uc_fw guc_fw;
  147. struct intel_uc_fw huc_fw;
  148. struct guc_info {
  149. struct intel_ctb_coredump ctb[2];
  150. struct i915_vma_coredump *vma_ctb;
  151. struct i915_vma_coredump *vma_log;
  152. u32 timestamp;
  153. u16 last_fence;
  154. bool is_guc_capture;
  155. } guc;
  156. } *uc;
  157. struct intel_gt_coredump *next;
  158. };
  159. struct i915_gpu_coredump {
  160. struct kref ref;
  161. ktime_t time;
  162. ktime_t boottime;
  163. ktime_t uptime;
  164. unsigned long capture;
  165. struct drm_i915_private *i915;
  166. struct intel_gt_coredump *gt;
  167. char error_msg[128];
  168. bool simulated;
  169. bool wakelock;
  170. bool suspended;
  171. int iommu;
  172. u32 reset_count;
  173. u32 suspend_count;
  174. struct intel_device_info device_info;
  175. struct intel_runtime_info runtime_info;
  176. struct intel_display_device_info display_device_info;
  177. struct intel_display_runtime_info display_runtime_info;
  178. struct intel_driver_caps driver_caps;
  179. struct i915_params params;
  180. struct intel_display_params display_params;
  181. struct intel_overlay_error_state *overlay;
  182. struct scatterlist *sgl, *fit;
  183. };
  184. struct i915_gpu_error {
  185. /* For reset and error_state handling. */
  186. spinlock_t lock;
  187. /* Protected by the above dev->gpu_error.lock. */
  188. struct i915_gpu_coredump *first_error;
  189. atomic_t pending_fb_pin;
  190. /** Number of times the device has been reset (global) */
  191. atomic_t reset_count;
  192. /** Number of times an engine has been reset */
  193. atomic_t reset_engine_count[MAX_ENGINE_CLASS];
  194. };
  195. struct drm_i915_error_state_buf {
  196. struct drm_i915_private *i915;
  197. struct scatterlist *sgl, *cur, *end;
  198. char *buf;
  199. size_t bytes;
  200. size_t size;
  201. loff_t iter;
  202. int err;
  203. };
  204. static inline u32 i915_reset_count(struct i915_gpu_error *error)
  205. {
  206. return atomic_read(&error->reset_count);
  207. }
  208. static inline u32 i915_reset_engine_count(struct i915_gpu_error *error,
  209. const struct intel_engine_cs *engine)
  210. {
  211. return atomic_read(&error->reset_engine_count[engine->class]);
  212. }
  213. static inline void
  214. i915_increase_reset_engine_count(struct i915_gpu_error *error,
  215. const struct intel_engine_cs *engine)
  216. {
  217. atomic_inc(&error->reset_engine_count[engine->class]);
  218. }
  219. #define CORE_DUMP_FLAG_NONE 0x0
  220. #define CORE_DUMP_FLAG_IS_GUC_CAPTURE BIT(0)
  221. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) && IS_ENABLED(CONFIG_DRM_I915_DEBUG_GEM)
  222. void intel_klog_error_capture(struct intel_gt *gt,
  223. intel_engine_mask_t engine_mask);
  224. #else
  225. static inline void intel_klog_error_capture(struct intel_gt *gt,
  226. intel_engine_mask_t engine_mask)
  227. {
  228. }
  229. #endif
  230. #if IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR)
  231. __printf(2, 3)
  232. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...);
  233. void i915_capture_error_state(struct intel_gt *gt,
  234. intel_engine_mask_t engine_mask, u32 dump_flags);
  235. struct i915_gpu_coredump *
  236. i915_gpu_coredump_alloc(struct drm_i915_private *i915, gfp_t gfp);
  237. struct intel_gt_coredump *
  238. intel_gt_coredump_alloc(struct intel_gt *gt, gfp_t gfp, u32 dump_flags);
  239. struct intel_engine_coredump *
  240. intel_engine_coredump_alloc(struct intel_engine_cs *engine, gfp_t gfp, u32 dump_flags);
  241. struct intel_engine_capture_vma *
  242. intel_engine_coredump_add_request(struct intel_engine_coredump *ee,
  243. struct i915_request *rq,
  244. gfp_t gfp);
  245. void intel_engine_coredump_add_vma(struct intel_engine_coredump *ee,
  246. struct intel_engine_capture_vma *capture,
  247. struct i915_vma_compress *compress);
  248. struct i915_vma_compress *
  249. i915_vma_capture_prepare(struct intel_gt_coredump *gt);
  250. void i915_vma_capture_finish(struct intel_gt_coredump *gt,
  251. struct i915_vma_compress *compress);
  252. void i915_error_state_store(struct i915_gpu_coredump *error);
  253. static inline struct i915_gpu_coredump *
  254. i915_gpu_coredump_get(struct i915_gpu_coredump *gpu)
  255. {
  256. kref_get(&gpu->ref);
  257. return gpu;
  258. }
  259. ssize_t
  260. i915_gpu_coredump_copy_to_buffer(struct i915_gpu_coredump *error,
  261. char *buf, loff_t offset, size_t count);
  262. void __i915_gpu_coredump_free(struct kref *kref);
  263. static inline void i915_gpu_coredump_put(struct i915_gpu_coredump *gpu)
  264. {
  265. if (gpu)
  266. kref_put(&gpu->ref, __i915_gpu_coredump_free);
  267. }
  268. void i915_reset_error_state(struct drm_i915_private *i915);
  269. void i915_disable_error_state(struct drm_i915_private *i915, int err);
  270. void i915_gpu_error_debugfs_register(struct drm_i915_private *i915);
  271. void i915_gpu_error_sysfs_setup(struct drm_i915_private *i915);
  272. void i915_gpu_error_sysfs_teardown(struct drm_i915_private *i915);
  273. #else
  274. __printf(2, 3)
  275. static inline void
  276. i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
  277. {
  278. }
  279. static inline void
  280. i915_capture_error_state(struct intel_gt *gt, intel_engine_mask_t engine_mask, u32 dump_flags)
  281. {
  282. }
  283. static inline struct i915_gpu_coredump *
  284. i915_gpu_coredump_alloc(struct drm_i915_private *i915, gfp_t gfp)
  285. {
  286. return NULL;
  287. }
  288. static inline struct intel_gt_coredump *
  289. intel_gt_coredump_alloc(struct intel_gt *gt, gfp_t gfp, u32 dump_flags)
  290. {
  291. return NULL;
  292. }
  293. static inline struct intel_engine_coredump *
  294. intel_engine_coredump_alloc(struct intel_engine_cs *engine, gfp_t gfp, u32 dump_flags)
  295. {
  296. return NULL;
  297. }
  298. static inline struct intel_engine_capture_vma *
  299. intel_engine_coredump_add_request(struct intel_engine_coredump *ee,
  300. struct i915_request *rq,
  301. gfp_t gfp)
  302. {
  303. return NULL;
  304. }
  305. static inline void
  306. intel_engine_coredump_add_vma(struct intel_engine_coredump *ee,
  307. struct intel_engine_capture_vma *capture,
  308. struct i915_vma_compress *compress)
  309. {
  310. }
  311. static inline struct i915_vma_compress *
  312. i915_vma_capture_prepare(struct intel_gt_coredump *gt)
  313. {
  314. return NULL;
  315. }
  316. static inline void
  317. i915_vma_capture_finish(struct intel_gt_coredump *gt,
  318. struct i915_vma_compress *compress)
  319. {
  320. }
  321. static inline void
  322. i915_error_state_store(struct i915_gpu_coredump *error)
  323. {
  324. }
  325. static inline void i915_gpu_coredump_put(struct i915_gpu_coredump *gpu)
  326. {
  327. }
  328. static inline void i915_reset_error_state(struct drm_i915_private *i915)
  329. {
  330. }
  331. static inline void i915_disable_error_state(struct drm_i915_private *i915,
  332. int err)
  333. {
  334. }
  335. static inline void i915_gpu_error_debugfs_register(struct drm_i915_private *i915)
  336. {
  337. }
  338. static inline void i915_gpu_error_sysfs_setup(struct drm_i915_private *i915)
  339. {
  340. }
  341. static inline void i915_gpu_error_sysfs_teardown(struct drm_i915_private *i915)
  342. {
  343. }
  344. #endif /* IS_ENABLED(CONFIG_DRM_I915_CAPTURE_ERROR) */
  345. #endif /* _I915_GPU_ERROR_H_ */