i915_gpu_error.c 39 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435
  1. /*
  2. * Copyright (c) 2008 Intel Corporation
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice (including the next
  12. * paragraph) shall be included in all copies or substantial portions of the
  13. * Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  18. * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  20. * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  21. * IN THE SOFTWARE.
  22. *
  23. * Authors:
  24. * Eric Anholt <eric@anholt.net>
  25. * Keith Packard <keithp@keithp.com>
  26. * Mika Kuoppala <mika.kuoppala@intel.com>
  27. *
  28. */
  29. #include <generated/utsrelease.h>
  30. #include "i915_drv.h"
  31. static const char *ring_str(int ring)
  32. {
  33. switch (ring) {
  34. case RCS: return "render";
  35. case VCS: return "bsd";
  36. case BCS: return "blt";
  37. case VECS: return "vebox";
  38. case VCS2: return "bsd2";
  39. default: return "";
  40. }
  41. }
  42. static const char *pin_flag(int pinned)
  43. {
  44. if (pinned > 0)
  45. return " P";
  46. else if (pinned < 0)
  47. return " p";
  48. else
  49. return "";
  50. }
  51. static const char *tiling_flag(int tiling)
  52. {
  53. switch (tiling) {
  54. default:
  55. case I915_TILING_NONE: return "";
  56. case I915_TILING_X: return " X";
  57. case I915_TILING_Y: return " Y";
  58. }
  59. }
  60. static const char *dirty_flag(int dirty)
  61. {
  62. return dirty ? " dirty" : "";
  63. }
  64. static const char *purgeable_flag(int purgeable)
  65. {
  66. return purgeable ? " purgeable" : "";
  67. }
  68. static bool __i915_error_ok(struct drm_i915_error_state_buf *e)
  69. {
  70. if (!e->err && WARN(e->bytes > (e->size - 1), "overflow")) {
  71. e->err = -ENOSPC;
  72. return false;
  73. }
  74. if (e->bytes == e->size - 1 || e->err)
  75. return false;
  76. return true;
  77. }
  78. static bool __i915_error_seek(struct drm_i915_error_state_buf *e,
  79. unsigned len)
  80. {
  81. if (e->pos + len <= e->start) {
  82. e->pos += len;
  83. return false;
  84. }
  85. /* First vsnprintf needs to fit in its entirety for memmove */
  86. if (len >= e->size) {
  87. e->err = -EIO;
  88. return false;
  89. }
  90. return true;
  91. }
  92. static void __i915_error_advance(struct drm_i915_error_state_buf *e,
  93. unsigned len)
  94. {
  95. /* If this is first printf in this window, adjust it so that
  96. * start position matches start of the buffer
  97. */
  98. if (e->pos < e->start) {
  99. const size_t off = e->start - e->pos;
  100. /* Should not happen but be paranoid */
  101. if (off > len || e->bytes) {
  102. e->err = -EIO;
  103. return;
  104. }
  105. memmove(e->buf, e->buf + off, len - off);
  106. e->bytes = len - off;
  107. e->pos = e->start;
  108. return;
  109. }
  110. e->bytes += len;
  111. e->pos += len;
  112. }
  113. static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
  114. const char *f, va_list args)
  115. {
  116. unsigned len;
  117. if (!__i915_error_ok(e))
  118. return;
  119. /* Seek the first printf which is hits start position */
  120. if (e->pos < e->start) {
  121. va_list tmp;
  122. va_copy(tmp, args);
  123. len = vsnprintf(NULL, 0, f, tmp);
  124. va_end(tmp);
  125. if (!__i915_error_seek(e, len))
  126. return;
  127. }
  128. len = vsnprintf(e->buf + e->bytes, e->size - e->bytes, f, args);
  129. if (len >= e->size - e->bytes)
  130. len = e->size - e->bytes - 1;
  131. __i915_error_advance(e, len);
  132. }
  133. static void i915_error_puts(struct drm_i915_error_state_buf *e,
  134. const char *str)
  135. {
  136. unsigned len;
  137. if (!__i915_error_ok(e))
  138. return;
  139. len = strlen(str);
  140. /* Seek the first printf which is hits start position */
  141. if (e->pos < e->start) {
  142. if (!__i915_error_seek(e, len))
  143. return;
  144. }
  145. if (len >= e->size - e->bytes)
  146. len = e->size - e->bytes - 1;
  147. memcpy(e->buf + e->bytes, str, len);
  148. __i915_error_advance(e, len);
  149. }
  150. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  151. #define err_puts(e, s) i915_error_puts(e, s)
  152. static void print_error_buffers(struct drm_i915_error_state_buf *m,
  153. const char *name,
  154. struct drm_i915_error_buffer *err,
  155. int count)
  156. {
  157. int i;
  158. err_printf(m, " %s [%d]:\n", name, count);
  159. while (count--) {
  160. err_printf(m, " %08x_%08x %8u %02x %02x [ ",
  161. upper_32_bits(err->gtt_offset),
  162. lower_32_bits(err->gtt_offset),
  163. err->size,
  164. err->read_domains,
  165. err->write_domain);
  166. for (i = 0; i < I915_NUM_RINGS; i++)
  167. err_printf(m, "%02x ", err->rseqno[i]);
  168. err_printf(m, "] %02x", err->wseqno);
  169. err_puts(m, pin_flag(err->pinned));
  170. err_puts(m, tiling_flag(err->tiling));
  171. err_puts(m, dirty_flag(err->dirty));
  172. err_puts(m, purgeable_flag(err->purgeable));
  173. err_puts(m, err->userptr ? " userptr" : "");
  174. err_puts(m, err->ring != -1 ? " " : "");
  175. err_puts(m, ring_str(err->ring));
  176. err_puts(m, i915_cache_level_str(m->i915, err->cache_level));
  177. if (err->name)
  178. err_printf(m, " (name: %d)", err->name);
  179. if (err->fence_reg != I915_FENCE_REG_NONE)
  180. err_printf(m, " (fence: %d)", err->fence_reg);
  181. err_puts(m, "\n");
  182. err++;
  183. }
  184. }
  185. static const char *hangcheck_action_to_str(enum intel_ring_hangcheck_action a)
  186. {
  187. switch (a) {
  188. case HANGCHECK_IDLE:
  189. return "idle";
  190. case HANGCHECK_WAIT:
  191. return "wait";
  192. case HANGCHECK_ACTIVE:
  193. return "active";
  194. case HANGCHECK_ACTIVE_LOOP:
  195. return "active (loop)";
  196. case HANGCHECK_KICK:
  197. return "kick";
  198. case HANGCHECK_HUNG:
  199. return "hung";
  200. }
  201. return "unknown";
  202. }
  203. static void i915_ring_error_state(struct drm_i915_error_state_buf *m,
  204. struct drm_device *dev,
  205. struct drm_i915_error_state *error,
  206. int ring_idx)
  207. {
  208. struct drm_i915_error_ring *ring = &error->ring[ring_idx];
  209. if (!ring->valid)
  210. return;
  211. err_printf(m, "%s command stream:\n", ring_str(ring_idx));
  212. err_printf(m, " START: 0x%08x\n", ring->start);
  213. err_printf(m, " HEAD: 0x%08x\n", ring->head);
  214. err_printf(m, " TAIL: 0x%08x\n", ring->tail);
  215. err_printf(m, " CTL: 0x%08x\n", ring->ctl);
  216. err_printf(m, " HWS: 0x%08x\n", ring->hws);
  217. err_printf(m, " ACTHD: 0x%08x %08x\n", (u32)(ring->acthd>>32), (u32)ring->acthd);
  218. err_printf(m, " IPEIR: 0x%08x\n", ring->ipeir);
  219. err_printf(m, " IPEHR: 0x%08x\n", ring->ipehr);
  220. err_printf(m, " INSTDONE: 0x%08x\n", ring->instdone);
  221. if (INTEL_INFO(dev)->gen >= 4) {
  222. err_printf(m, " BBADDR: 0x%08x %08x\n", (u32)(ring->bbaddr>>32), (u32)ring->bbaddr);
  223. err_printf(m, " BB_STATE: 0x%08x\n", ring->bbstate);
  224. err_printf(m, " INSTPS: 0x%08x\n", ring->instps);
  225. }
  226. err_printf(m, " INSTPM: 0x%08x\n", ring->instpm);
  227. err_printf(m, " FADDR: 0x%08x %08x\n", upper_32_bits(ring->faddr),
  228. lower_32_bits(ring->faddr));
  229. if (INTEL_INFO(dev)->gen >= 6) {
  230. err_printf(m, " RC PSMI: 0x%08x\n", ring->rc_psmi);
  231. err_printf(m, " FAULT_REG: 0x%08x\n", ring->fault_reg);
  232. err_printf(m, " SYNC_0: 0x%08x [last synced 0x%08x]\n",
  233. ring->semaphore_mboxes[0],
  234. ring->semaphore_seqno[0]);
  235. err_printf(m, " SYNC_1: 0x%08x [last synced 0x%08x]\n",
  236. ring->semaphore_mboxes[1],
  237. ring->semaphore_seqno[1]);
  238. if (HAS_VEBOX(dev)) {
  239. err_printf(m, " SYNC_2: 0x%08x [last synced 0x%08x]\n",
  240. ring->semaphore_mboxes[2],
  241. ring->semaphore_seqno[2]);
  242. }
  243. }
  244. if (USES_PPGTT(dev)) {
  245. err_printf(m, " GFX_MODE: 0x%08x\n", ring->vm_info.gfx_mode);
  246. if (INTEL_INFO(dev)->gen >= 8) {
  247. int i;
  248. for (i = 0; i < 4; i++)
  249. err_printf(m, " PDP%d: 0x%016llx\n",
  250. i, ring->vm_info.pdp[i]);
  251. } else {
  252. err_printf(m, " PP_DIR_BASE: 0x%08x\n",
  253. ring->vm_info.pp_dir_base);
  254. }
  255. }
  256. err_printf(m, " seqno: 0x%08x\n", ring->seqno);
  257. err_printf(m, " waiting: %s\n", yesno(ring->waiting));
  258. err_printf(m, " ring->head: 0x%08x\n", ring->cpu_ring_head);
  259. err_printf(m, " ring->tail: 0x%08x\n", ring->cpu_ring_tail);
  260. err_printf(m, " hangcheck: %s [%d]\n",
  261. hangcheck_action_to_str(ring->hangcheck_action),
  262. ring->hangcheck_score);
  263. }
  264. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
  265. {
  266. va_list args;
  267. va_start(args, f);
  268. i915_error_vprintf(e, f, args);
  269. va_end(args);
  270. }
  271. static void print_error_obj(struct drm_i915_error_state_buf *m,
  272. struct drm_i915_error_object *obj)
  273. {
  274. int page, offset, elt;
  275. for (page = offset = 0; page < obj->page_count; page++) {
  276. for (elt = 0; elt < PAGE_SIZE/4; elt++) {
  277. err_printf(m, "%08x : %08x\n", offset,
  278. obj->pages[page][elt]);
  279. offset += 4;
  280. }
  281. }
  282. }
  283. int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
  284. const struct i915_error_state_file_priv *error_priv)
  285. {
  286. struct drm_device *dev = error_priv->dev;
  287. struct drm_i915_private *dev_priv = dev->dev_private;
  288. struct drm_i915_error_state *error = error_priv->error;
  289. struct drm_i915_error_object *obj;
  290. int i, j, offset, elt;
  291. int max_hangcheck_score;
  292. if (!error) {
  293. err_printf(m, "no error state collected\n");
  294. goto out;
  295. }
  296. err_printf(m, "%s\n", error->error_msg);
  297. err_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec,
  298. error->time.tv_usec);
  299. err_printf(m, "Kernel: " UTS_RELEASE "\n");
  300. max_hangcheck_score = 0;
  301. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  302. if (error->ring[i].hangcheck_score > max_hangcheck_score)
  303. max_hangcheck_score = error->ring[i].hangcheck_score;
  304. }
  305. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  306. if (error->ring[i].hangcheck_score == max_hangcheck_score &&
  307. error->ring[i].pid != -1) {
  308. err_printf(m, "Active process (on ring %s): %s [%d]\n",
  309. ring_str(i),
  310. error->ring[i].comm,
  311. error->ring[i].pid);
  312. }
  313. }
  314. err_printf(m, "Reset count: %u\n", error->reset_count);
  315. err_printf(m, "Suspend count: %u\n", error->suspend_count);
  316. err_printf(m, "PCI ID: 0x%04x\n", dev->pdev->device);
  317. err_printf(m, "PCI Revision: 0x%02x\n", dev->pdev->revision);
  318. err_printf(m, "PCI Subsystem: %04x:%04x\n",
  319. dev->pdev->subsystem_vendor,
  320. dev->pdev->subsystem_device);
  321. err_printf(m, "IOMMU enabled?: %d\n", error->iommu);
  322. if (HAS_CSR(dev)) {
  323. struct intel_csr *csr = &dev_priv->csr;
  324. err_printf(m, "DMC loaded: %s\n",
  325. yesno(csr->dmc_payload != NULL));
  326. err_printf(m, "DMC fw version: %d.%d\n",
  327. CSR_VERSION_MAJOR(csr->version),
  328. CSR_VERSION_MINOR(csr->version));
  329. }
  330. err_printf(m, "EIR: 0x%08x\n", error->eir);
  331. err_printf(m, "IER: 0x%08x\n", error->ier);
  332. if (INTEL_INFO(dev)->gen >= 8) {
  333. for (i = 0; i < 4; i++)
  334. err_printf(m, "GTIER gt %d: 0x%08x\n", i,
  335. error->gtier[i]);
  336. } else if (HAS_PCH_SPLIT(dev) || IS_VALLEYVIEW(dev))
  337. err_printf(m, "GTIER: 0x%08x\n", error->gtier[0]);
  338. err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
  339. err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
  340. err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
  341. err_printf(m, "CCID: 0x%08x\n", error->ccid);
  342. err_printf(m, "Missed interrupts: 0x%08lx\n", dev_priv->gpu_error.missed_irq_rings);
  343. for (i = 0; i < dev_priv->num_fence_regs; i++)
  344. err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
  345. for (i = 0; i < ARRAY_SIZE(error->extra_instdone); i++)
  346. err_printf(m, " INSTDONE_%d: 0x%08x\n", i,
  347. error->extra_instdone[i]);
  348. if (INTEL_INFO(dev)->gen >= 6) {
  349. err_printf(m, "ERROR: 0x%08x\n", error->error);
  350. if (INTEL_INFO(dev)->gen >= 8)
  351. err_printf(m, "FAULT_TLB_DATA: 0x%08x 0x%08x\n",
  352. error->fault_data1, error->fault_data0);
  353. err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
  354. }
  355. if (INTEL_INFO(dev)->gen == 7)
  356. err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
  357. for (i = 0; i < ARRAY_SIZE(error->ring); i++)
  358. i915_ring_error_state(m, dev, error, i);
  359. for (i = 0; i < error->vm_count; i++) {
  360. err_printf(m, "vm[%d]\n", i);
  361. print_error_buffers(m, "Active",
  362. error->active_bo[i],
  363. error->active_bo_count[i]);
  364. print_error_buffers(m, "Pinned",
  365. error->pinned_bo[i],
  366. error->pinned_bo_count[i]);
  367. }
  368. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  369. obj = error->ring[i].batchbuffer;
  370. if (obj) {
  371. err_puts(m, dev_priv->ring[i].name);
  372. if (error->ring[i].pid != -1)
  373. err_printf(m, " (submitted by %s [%d])",
  374. error->ring[i].comm,
  375. error->ring[i].pid);
  376. err_printf(m, " --- gtt_offset = 0x%08x %08x\n",
  377. upper_32_bits(obj->gtt_offset),
  378. lower_32_bits(obj->gtt_offset));
  379. print_error_obj(m, obj);
  380. }
  381. obj = error->ring[i].wa_batchbuffer;
  382. if (obj) {
  383. err_printf(m, "%s (w/a) --- gtt_offset = 0x%08x\n",
  384. dev_priv->ring[i].name,
  385. lower_32_bits(obj->gtt_offset));
  386. print_error_obj(m, obj);
  387. }
  388. if (error->ring[i].num_requests) {
  389. err_printf(m, "%s --- %d requests\n",
  390. dev_priv->ring[i].name,
  391. error->ring[i].num_requests);
  392. for (j = 0; j < error->ring[i].num_requests; j++) {
  393. err_printf(m, " seqno 0x%08x, emitted %ld, tail 0x%08x\n",
  394. error->ring[i].requests[j].seqno,
  395. error->ring[i].requests[j].jiffies,
  396. error->ring[i].requests[j].tail);
  397. }
  398. }
  399. if ((obj = error->ring[i].ringbuffer)) {
  400. err_printf(m, "%s --- ringbuffer = 0x%08x\n",
  401. dev_priv->ring[i].name,
  402. lower_32_bits(obj->gtt_offset));
  403. print_error_obj(m, obj);
  404. }
  405. if ((obj = error->ring[i].hws_page)) {
  406. u64 hws_offset = obj->gtt_offset;
  407. u32 *hws_page = &obj->pages[0][0];
  408. if (i915.enable_execlists) {
  409. hws_offset += LRC_PPHWSP_PN * PAGE_SIZE;
  410. hws_page = &obj->pages[LRC_PPHWSP_PN][0];
  411. }
  412. err_printf(m, "%s --- HW Status = 0x%08llx\n",
  413. dev_priv->ring[i].name, hws_offset);
  414. offset = 0;
  415. for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
  416. err_printf(m, "[%04x] %08x %08x %08x %08x\n",
  417. offset,
  418. hws_page[elt],
  419. hws_page[elt+1],
  420. hws_page[elt+2],
  421. hws_page[elt+3]);
  422. offset += 16;
  423. }
  424. }
  425. if ((obj = error->ring[i].ctx)) {
  426. err_printf(m, "%s --- HW Context = 0x%08x\n",
  427. dev_priv->ring[i].name,
  428. lower_32_bits(obj->gtt_offset));
  429. print_error_obj(m, obj);
  430. }
  431. }
  432. if ((obj = error->semaphore_obj)) {
  433. err_printf(m, "Semaphore page = 0x%08x\n",
  434. lower_32_bits(obj->gtt_offset));
  435. for (elt = 0; elt < PAGE_SIZE/16; elt += 4) {
  436. err_printf(m, "[%04x] %08x %08x %08x %08x\n",
  437. elt * 4,
  438. obj->pages[0][elt],
  439. obj->pages[0][elt+1],
  440. obj->pages[0][elt+2],
  441. obj->pages[0][elt+3]);
  442. }
  443. }
  444. if (error->overlay)
  445. intel_overlay_print_error_state(m, error->overlay);
  446. if (error->display)
  447. intel_display_print_error_state(m, dev, error->display);
  448. out:
  449. if (m->bytes == 0 && m->err)
  450. return m->err;
  451. return 0;
  452. }
  453. int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
  454. struct drm_i915_private *i915,
  455. size_t count, loff_t pos)
  456. {
  457. memset(ebuf, 0, sizeof(*ebuf));
  458. ebuf->i915 = i915;
  459. /* We need to have enough room to store any i915_error_state printf
  460. * so that we can move it to start position.
  461. */
  462. ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
  463. ebuf->buf = kmalloc(ebuf->size,
  464. GFP_TEMPORARY | __GFP_NORETRY | __GFP_NOWARN);
  465. if (ebuf->buf == NULL) {
  466. ebuf->size = PAGE_SIZE;
  467. ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
  468. }
  469. if (ebuf->buf == NULL) {
  470. ebuf->size = 128;
  471. ebuf->buf = kmalloc(ebuf->size, GFP_TEMPORARY);
  472. }
  473. if (ebuf->buf == NULL)
  474. return -ENOMEM;
  475. ebuf->start = pos;
  476. return 0;
  477. }
  478. static void i915_error_object_free(struct drm_i915_error_object *obj)
  479. {
  480. int page;
  481. if (obj == NULL)
  482. return;
  483. for (page = 0; page < obj->page_count; page++)
  484. kfree(obj->pages[page]);
  485. kfree(obj);
  486. }
  487. static void i915_error_state_free(struct kref *error_ref)
  488. {
  489. struct drm_i915_error_state *error = container_of(error_ref,
  490. typeof(*error), ref);
  491. int i;
  492. for (i = 0; i < ARRAY_SIZE(error->ring); i++) {
  493. i915_error_object_free(error->ring[i].batchbuffer);
  494. i915_error_object_free(error->ring[i].wa_batchbuffer);
  495. i915_error_object_free(error->ring[i].ringbuffer);
  496. i915_error_object_free(error->ring[i].hws_page);
  497. i915_error_object_free(error->ring[i].ctx);
  498. kfree(error->ring[i].requests);
  499. }
  500. i915_error_object_free(error->semaphore_obj);
  501. for (i = 0; i < error->vm_count; i++)
  502. kfree(error->active_bo[i]);
  503. kfree(error->active_bo);
  504. kfree(error->active_bo_count);
  505. kfree(error->pinned_bo);
  506. kfree(error->pinned_bo_count);
  507. kfree(error->overlay);
  508. kfree(error->display);
  509. kfree(error);
  510. }
  511. static struct drm_i915_error_object *
  512. i915_error_object_create(struct drm_i915_private *dev_priv,
  513. struct drm_i915_gem_object *src,
  514. struct i915_address_space *vm)
  515. {
  516. struct drm_i915_error_object *dst;
  517. struct i915_vma *vma = NULL;
  518. int num_pages;
  519. bool use_ggtt;
  520. int i = 0;
  521. u64 reloc_offset;
  522. if (src == NULL || src->pages == NULL)
  523. return NULL;
  524. num_pages = src->base.size >> PAGE_SHIFT;
  525. dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *), GFP_ATOMIC);
  526. if (dst == NULL)
  527. return NULL;
  528. if (i915_gem_obj_bound(src, vm))
  529. dst->gtt_offset = i915_gem_obj_offset(src, vm);
  530. else
  531. dst->gtt_offset = -1;
  532. reloc_offset = dst->gtt_offset;
  533. if (i915_is_ggtt(vm))
  534. vma = i915_gem_obj_to_ggtt(src);
  535. use_ggtt = (src->cache_level == I915_CACHE_NONE &&
  536. vma && (vma->bound & GLOBAL_BIND) &&
  537. reloc_offset + num_pages * PAGE_SIZE <= dev_priv->gtt.mappable_end);
  538. /* Cannot access stolen address directly, try to use the aperture */
  539. if (src->stolen) {
  540. use_ggtt = true;
  541. if (!(vma && vma->bound & GLOBAL_BIND))
  542. goto unwind;
  543. reloc_offset = i915_gem_obj_ggtt_offset(src);
  544. if (reloc_offset + num_pages * PAGE_SIZE > dev_priv->gtt.mappable_end)
  545. goto unwind;
  546. }
  547. /* Cannot access snooped pages through the aperture */
  548. if (use_ggtt && src->cache_level != I915_CACHE_NONE && !HAS_LLC(dev_priv->dev))
  549. goto unwind;
  550. dst->page_count = num_pages;
  551. while (num_pages--) {
  552. unsigned long flags;
  553. void *d;
  554. d = kmalloc(PAGE_SIZE, GFP_ATOMIC);
  555. if (d == NULL)
  556. goto unwind;
  557. local_irq_save(flags);
  558. if (use_ggtt) {
  559. void __iomem *s;
  560. /* Simply ignore tiling or any overlapping fence.
  561. * It's part of the error state, and this hopefully
  562. * captures what the GPU read.
  563. */
  564. s = io_mapping_map_atomic_wc(dev_priv->gtt.mappable,
  565. reloc_offset);
  566. memcpy_fromio(d, s, PAGE_SIZE);
  567. io_mapping_unmap_atomic(s);
  568. } else {
  569. struct page *page;
  570. void *s;
  571. page = i915_gem_object_get_page(src, i);
  572. drm_clflush_pages(&page, 1);
  573. s = kmap_atomic(page);
  574. memcpy(d, s, PAGE_SIZE);
  575. kunmap_atomic(s);
  576. drm_clflush_pages(&page, 1);
  577. }
  578. local_irq_restore(flags);
  579. dst->pages[i++] = d;
  580. reloc_offset += PAGE_SIZE;
  581. }
  582. return dst;
  583. unwind:
  584. while (i--)
  585. kfree(dst->pages[i]);
  586. kfree(dst);
  587. return NULL;
  588. }
  589. #define i915_error_ggtt_object_create(dev_priv, src) \
  590. i915_error_object_create((dev_priv), (src), &(dev_priv)->gtt.base)
  591. static void capture_bo(struct drm_i915_error_buffer *err,
  592. struct i915_vma *vma)
  593. {
  594. struct drm_i915_gem_object *obj = vma->obj;
  595. int i;
  596. err->size = obj->base.size;
  597. err->name = obj->base.name;
  598. for (i = 0; i < I915_NUM_RINGS; i++)
  599. err->rseqno[i] = i915_gem_request_get_seqno(obj->last_read_req[i]);
  600. err->wseqno = i915_gem_request_get_seqno(obj->last_write_req);
  601. err->gtt_offset = vma->node.start;
  602. err->read_domains = obj->base.read_domains;
  603. err->write_domain = obj->base.write_domain;
  604. err->fence_reg = obj->fence_reg;
  605. err->pinned = 0;
  606. if (i915_gem_obj_is_pinned(obj))
  607. err->pinned = 1;
  608. err->tiling = obj->tiling_mode;
  609. err->dirty = obj->dirty;
  610. err->purgeable = obj->madv != I915_MADV_WILLNEED;
  611. err->userptr = obj->userptr.mm != NULL;
  612. err->ring = obj->last_write_req ?
  613. i915_gem_request_get_ring(obj->last_write_req)->id : -1;
  614. err->cache_level = obj->cache_level;
  615. }
  616. static u32 capture_active_bo(struct drm_i915_error_buffer *err,
  617. int count, struct list_head *head)
  618. {
  619. struct i915_vma *vma;
  620. int i = 0;
  621. list_for_each_entry(vma, head, vm_link) {
  622. capture_bo(err++, vma);
  623. if (++i == count)
  624. break;
  625. }
  626. return i;
  627. }
  628. static u32 capture_pinned_bo(struct drm_i915_error_buffer *err,
  629. int count, struct list_head *head,
  630. struct i915_address_space *vm)
  631. {
  632. struct drm_i915_gem_object *obj;
  633. struct drm_i915_error_buffer * const first = err;
  634. struct drm_i915_error_buffer * const last = err + count;
  635. list_for_each_entry(obj, head, global_list) {
  636. struct i915_vma *vma;
  637. if (err == last)
  638. break;
  639. list_for_each_entry(vma, &obj->vma_list, obj_link)
  640. if (vma->vm == vm && vma->pin_count > 0)
  641. capture_bo(err++, vma);
  642. }
  643. return err - first;
  644. }
  645. /* Generate a semi-unique error code. The code is not meant to have meaning, The
  646. * code's only purpose is to try to prevent false duplicated bug reports by
  647. * grossly estimating a GPU error state.
  648. *
  649. * TODO Ideally, hashing the batchbuffer would be a very nice way to determine
  650. * the hang if we could strip the GTT offset information from it.
  651. *
  652. * It's only a small step better than a random number in its current form.
  653. */
  654. static uint32_t i915_error_generate_code(struct drm_i915_private *dev_priv,
  655. struct drm_i915_error_state *error,
  656. int *ring_id)
  657. {
  658. uint32_t error_code = 0;
  659. int i;
  660. /* IPEHR would be an ideal way to detect errors, as it's the gross
  661. * measure of "the command that hung." However, has some very common
  662. * synchronization commands which almost always appear in the case
  663. * strictly a client bug. Use instdone to differentiate those some.
  664. */
  665. for (i = 0; i < I915_NUM_RINGS; i++) {
  666. if (error->ring[i].hangcheck_action == HANGCHECK_HUNG) {
  667. if (ring_id)
  668. *ring_id = i;
  669. return error->ring[i].ipehr ^ error->ring[i].instdone;
  670. }
  671. }
  672. return error_code;
  673. }
  674. static void i915_gem_record_fences(struct drm_device *dev,
  675. struct drm_i915_error_state *error)
  676. {
  677. struct drm_i915_private *dev_priv = dev->dev_private;
  678. int i;
  679. if (IS_GEN3(dev) || IS_GEN2(dev)) {
  680. for (i = 0; i < dev_priv->num_fence_regs; i++)
  681. error->fence[i] = I915_READ(FENCE_REG(i));
  682. } else if (IS_GEN5(dev) || IS_GEN4(dev)) {
  683. for (i = 0; i < dev_priv->num_fence_regs; i++)
  684. error->fence[i] = I915_READ64(FENCE_REG_965_LO(i));
  685. } else if (INTEL_INFO(dev)->gen >= 6) {
  686. for (i = 0; i < dev_priv->num_fence_regs; i++)
  687. error->fence[i] = I915_READ64(FENCE_REG_GEN6_LO(i));
  688. }
  689. }
  690. static void gen8_record_semaphore_state(struct drm_i915_private *dev_priv,
  691. struct drm_i915_error_state *error,
  692. struct intel_engine_cs *ring,
  693. struct drm_i915_error_ring *ering)
  694. {
  695. struct intel_engine_cs *to;
  696. int i;
  697. if (!i915_semaphore_is_enabled(dev_priv->dev))
  698. return;
  699. if (!error->semaphore_obj)
  700. error->semaphore_obj =
  701. i915_error_ggtt_object_create(dev_priv,
  702. dev_priv->semaphore_obj);
  703. for_each_ring(to, dev_priv, i) {
  704. int idx;
  705. u16 signal_offset;
  706. u32 *tmp;
  707. if (ring == to)
  708. continue;
  709. signal_offset = (GEN8_SIGNAL_OFFSET(ring, i) & (PAGE_SIZE - 1))
  710. / 4;
  711. tmp = error->semaphore_obj->pages[0];
  712. idx = intel_ring_sync_index(ring, to);
  713. ering->semaphore_mboxes[idx] = tmp[signal_offset];
  714. ering->semaphore_seqno[idx] = ring->semaphore.sync_seqno[idx];
  715. }
  716. }
  717. static void gen6_record_semaphore_state(struct drm_i915_private *dev_priv,
  718. struct intel_engine_cs *ring,
  719. struct drm_i915_error_ring *ering)
  720. {
  721. ering->semaphore_mboxes[0] = I915_READ(RING_SYNC_0(ring->mmio_base));
  722. ering->semaphore_mboxes[1] = I915_READ(RING_SYNC_1(ring->mmio_base));
  723. ering->semaphore_seqno[0] = ring->semaphore.sync_seqno[0];
  724. ering->semaphore_seqno[1] = ring->semaphore.sync_seqno[1];
  725. if (HAS_VEBOX(dev_priv->dev)) {
  726. ering->semaphore_mboxes[2] =
  727. I915_READ(RING_SYNC_2(ring->mmio_base));
  728. ering->semaphore_seqno[2] = ring->semaphore.sync_seqno[2];
  729. }
  730. }
  731. static void i915_record_ring_state(struct drm_device *dev,
  732. struct drm_i915_error_state *error,
  733. struct intel_engine_cs *ring,
  734. struct drm_i915_error_ring *ering)
  735. {
  736. struct drm_i915_private *dev_priv = dev->dev_private;
  737. if (INTEL_INFO(dev)->gen >= 6) {
  738. ering->rc_psmi = I915_READ(RING_PSMI_CTL(ring->mmio_base));
  739. ering->fault_reg = I915_READ(RING_FAULT_REG(ring));
  740. if (INTEL_INFO(dev)->gen >= 8)
  741. gen8_record_semaphore_state(dev_priv, error, ring, ering);
  742. else
  743. gen6_record_semaphore_state(dev_priv, ring, ering);
  744. }
  745. if (INTEL_INFO(dev)->gen >= 4) {
  746. ering->faddr = I915_READ(RING_DMA_FADD(ring->mmio_base));
  747. ering->ipeir = I915_READ(RING_IPEIR(ring->mmio_base));
  748. ering->ipehr = I915_READ(RING_IPEHR(ring->mmio_base));
  749. ering->instdone = I915_READ(RING_INSTDONE(ring->mmio_base));
  750. ering->instps = I915_READ(RING_INSTPS(ring->mmio_base));
  751. ering->bbaddr = I915_READ(RING_BBADDR(ring->mmio_base));
  752. if (INTEL_INFO(dev)->gen >= 8) {
  753. ering->faddr |= (u64) I915_READ(RING_DMA_FADD_UDW(ring->mmio_base)) << 32;
  754. ering->bbaddr |= (u64) I915_READ(RING_BBADDR_UDW(ring->mmio_base)) << 32;
  755. }
  756. ering->bbstate = I915_READ(RING_BBSTATE(ring->mmio_base));
  757. } else {
  758. ering->faddr = I915_READ(DMA_FADD_I8XX);
  759. ering->ipeir = I915_READ(IPEIR);
  760. ering->ipehr = I915_READ(IPEHR);
  761. ering->instdone = I915_READ(GEN2_INSTDONE);
  762. }
  763. ering->waiting = waitqueue_active(&ring->irq_queue);
  764. ering->instpm = I915_READ(RING_INSTPM(ring->mmio_base));
  765. ering->seqno = ring->get_seqno(ring, false);
  766. ering->acthd = intel_ring_get_active_head(ring);
  767. ering->start = I915_READ_START(ring);
  768. ering->head = I915_READ_HEAD(ring);
  769. ering->tail = I915_READ_TAIL(ring);
  770. ering->ctl = I915_READ_CTL(ring);
  771. if (I915_NEED_GFX_HWS(dev)) {
  772. i915_reg_t mmio;
  773. if (IS_GEN7(dev)) {
  774. switch (ring->id) {
  775. default:
  776. case RCS:
  777. mmio = RENDER_HWS_PGA_GEN7;
  778. break;
  779. case BCS:
  780. mmio = BLT_HWS_PGA_GEN7;
  781. break;
  782. case VCS:
  783. mmio = BSD_HWS_PGA_GEN7;
  784. break;
  785. case VECS:
  786. mmio = VEBOX_HWS_PGA_GEN7;
  787. break;
  788. }
  789. } else if (IS_GEN6(ring->dev)) {
  790. mmio = RING_HWS_PGA_GEN6(ring->mmio_base);
  791. } else {
  792. /* XXX: gen8 returns to sanity */
  793. mmio = RING_HWS_PGA(ring->mmio_base);
  794. }
  795. ering->hws = I915_READ(mmio);
  796. }
  797. ering->hangcheck_score = ring->hangcheck.score;
  798. ering->hangcheck_action = ring->hangcheck.action;
  799. if (USES_PPGTT(dev)) {
  800. int i;
  801. ering->vm_info.gfx_mode = I915_READ(RING_MODE_GEN7(ring));
  802. if (IS_GEN6(dev))
  803. ering->vm_info.pp_dir_base =
  804. I915_READ(RING_PP_DIR_BASE_READ(ring));
  805. else if (IS_GEN7(dev))
  806. ering->vm_info.pp_dir_base =
  807. I915_READ(RING_PP_DIR_BASE(ring));
  808. else if (INTEL_INFO(dev)->gen >= 8)
  809. for (i = 0; i < 4; i++) {
  810. ering->vm_info.pdp[i] =
  811. I915_READ(GEN8_RING_PDP_UDW(ring, i));
  812. ering->vm_info.pdp[i] <<= 32;
  813. ering->vm_info.pdp[i] |=
  814. I915_READ(GEN8_RING_PDP_LDW(ring, i));
  815. }
  816. }
  817. }
  818. static void i915_gem_record_active_context(struct intel_engine_cs *ring,
  819. struct drm_i915_error_state *error,
  820. struct drm_i915_error_ring *ering)
  821. {
  822. struct drm_i915_private *dev_priv = ring->dev->dev_private;
  823. struct drm_i915_gem_object *obj;
  824. /* Currently render ring is the only HW context user */
  825. if (ring->id != RCS || !error->ccid)
  826. return;
  827. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
  828. if (!i915_gem_obj_ggtt_bound(obj))
  829. continue;
  830. if ((error->ccid & PAGE_MASK) == i915_gem_obj_ggtt_offset(obj)) {
  831. ering->ctx = i915_error_ggtt_object_create(dev_priv, obj);
  832. break;
  833. }
  834. }
  835. }
  836. static void i915_gem_record_rings(struct drm_device *dev,
  837. struct drm_i915_error_state *error)
  838. {
  839. struct drm_i915_private *dev_priv = dev->dev_private;
  840. struct drm_i915_gem_request *request;
  841. int i, count;
  842. for (i = 0; i < I915_NUM_RINGS; i++) {
  843. struct intel_engine_cs *ring = &dev_priv->ring[i];
  844. struct intel_ringbuffer *rbuf;
  845. error->ring[i].pid = -1;
  846. if (ring->dev == NULL)
  847. continue;
  848. error->ring[i].valid = true;
  849. i915_record_ring_state(dev, error, ring, &error->ring[i]);
  850. request = i915_gem_find_active_request(ring);
  851. if (request) {
  852. struct i915_address_space *vm;
  853. vm = request->ctx && request->ctx->ppgtt ?
  854. &request->ctx->ppgtt->base :
  855. &dev_priv->gtt.base;
  856. /* We need to copy these to an anonymous buffer
  857. * as the simplest method to avoid being overwritten
  858. * by userspace.
  859. */
  860. error->ring[i].batchbuffer =
  861. i915_error_object_create(dev_priv,
  862. request->batch_obj,
  863. vm);
  864. if (HAS_BROKEN_CS_TLB(dev_priv->dev))
  865. error->ring[i].wa_batchbuffer =
  866. i915_error_ggtt_object_create(dev_priv,
  867. ring->scratch.obj);
  868. if (request->pid) {
  869. struct task_struct *task;
  870. rcu_read_lock();
  871. task = pid_task(request->pid, PIDTYPE_PID);
  872. if (task) {
  873. strcpy(error->ring[i].comm, task->comm);
  874. error->ring[i].pid = task->pid;
  875. }
  876. rcu_read_unlock();
  877. }
  878. }
  879. if (i915.enable_execlists) {
  880. /* TODO: This is only a small fix to keep basic error
  881. * capture working, but we need to add more information
  882. * for it to be useful (e.g. dump the context being
  883. * executed).
  884. */
  885. if (request)
  886. rbuf = request->ctx->engine[ring->id].ringbuf;
  887. else
  888. rbuf = dev_priv->kernel_context->engine[ring->id].ringbuf;
  889. } else
  890. rbuf = ring->buffer;
  891. error->ring[i].cpu_ring_head = rbuf->head;
  892. error->ring[i].cpu_ring_tail = rbuf->tail;
  893. error->ring[i].ringbuffer =
  894. i915_error_ggtt_object_create(dev_priv, rbuf->obj);
  895. error->ring[i].hws_page =
  896. i915_error_ggtt_object_create(dev_priv, ring->status_page.obj);
  897. i915_gem_record_active_context(ring, error, &error->ring[i]);
  898. count = 0;
  899. list_for_each_entry(request, &ring->request_list, list)
  900. count++;
  901. error->ring[i].num_requests = count;
  902. error->ring[i].requests =
  903. kcalloc(count, sizeof(*error->ring[i].requests),
  904. GFP_ATOMIC);
  905. if (error->ring[i].requests == NULL) {
  906. error->ring[i].num_requests = 0;
  907. continue;
  908. }
  909. count = 0;
  910. list_for_each_entry(request, &ring->request_list, list) {
  911. struct drm_i915_error_request *erq;
  912. if (count >= error->ring[i].num_requests) {
  913. /*
  914. * If the ring request list was changed in
  915. * between the point where the error request
  916. * list was created and dimensioned and this
  917. * point then just exit early to avoid crashes.
  918. *
  919. * We don't need to communicate that the
  920. * request list changed state during error
  921. * state capture and that the error state is
  922. * slightly incorrect as a consequence since we
  923. * are typically only interested in the request
  924. * list state at the point of error state
  925. * capture, not in any changes happening during
  926. * the capture.
  927. */
  928. break;
  929. }
  930. erq = &error->ring[i].requests[count++];
  931. erq->seqno = request->seqno;
  932. erq->jiffies = request->emitted_jiffies;
  933. erq->tail = request->postfix;
  934. }
  935. }
  936. }
  937. /* FIXME: Since pin count/bound list is global, we duplicate what we capture per
  938. * VM.
  939. */
  940. static void i915_gem_capture_vm(struct drm_i915_private *dev_priv,
  941. struct drm_i915_error_state *error,
  942. struct i915_address_space *vm,
  943. const int ndx)
  944. {
  945. struct drm_i915_error_buffer *active_bo = NULL, *pinned_bo = NULL;
  946. struct drm_i915_gem_object *obj;
  947. struct i915_vma *vma;
  948. int i;
  949. i = 0;
  950. list_for_each_entry(vma, &vm->active_list, vm_link)
  951. i++;
  952. error->active_bo_count[ndx] = i;
  953. list_for_each_entry(obj, &dev_priv->mm.bound_list, global_list) {
  954. list_for_each_entry(vma, &obj->vma_list, obj_link)
  955. if (vma->vm == vm && vma->pin_count > 0)
  956. i++;
  957. }
  958. error->pinned_bo_count[ndx] = i - error->active_bo_count[ndx];
  959. if (i) {
  960. active_bo = kcalloc(i, sizeof(*active_bo), GFP_ATOMIC);
  961. if (active_bo)
  962. pinned_bo = active_bo + error->active_bo_count[ndx];
  963. }
  964. if (active_bo)
  965. error->active_bo_count[ndx] =
  966. capture_active_bo(active_bo,
  967. error->active_bo_count[ndx],
  968. &vm->active_list);
  969. if (pinned_bo)
  970. error->pinned_bo_count[ndx] =
  971. capture_pinned_bo(pinned_bo,
  972. error->pinned_bo_count[ndx],
  973. &dev_priv->mm.bound_list, vm);
  974. error->active_bo[ndx] = active_bo;
  975. error->pinned_bo[ndx] = pinned_bo;
  976. }
  977. static void i915_gem_capture_buffers(struct drm_i915_private *dev_priv,
  978. struct drm_i915_error_state *error)
  979. {
  980. struct i915_address_space *vm;
  981. int cnt = 0, i = 0;
  982. list_for_each_entry(vm, &dev_priv->vm_list, global_link)
  983. cnt++;
  984. error->active_bo = kcalloc(cnt, sizeof(*error->active_bo), GFP_ATOMIC);
  985. error->pinned_bo = kcalloc(cnt, sizeof(*error->pinned_bo), GFP_ATOMIC);
  986. error->active_bo_count = kcalloc(cnt, sizeof(*error->active_bo_count),
  987. GFP_ATOMIC);
  988. error->pinned_bo_count = kcalloc(cnt, sizeof(*error->pinned_bo_count),
  989. GFP_ATOMIC);
  990. if (error->active_bo == NULL ||
  991. error->pinned_bo == NULL ||
  992. error->active_bo_count == NULL ||
  993. error->pinned_bo_count == NULL) {
  994. kfree(error->active_bo);
  995. kfree(error->active_bo_count);
  996. kfree(error->pinned_bo);
  997. kfree(error->pinned_bo_count);
  998. error->active_bo = NULL;
  999. error->active_bo_count = NULL;
  1000. error->pinned_bo = NULL;
  1001. error->pinned_bo_count = NULL;
  1002. } else {
  1003. list_for_each_entry(vm, &dev_priv->vm_list, global_link)
  1004. i915_gem_capture_vm(dev_priv, error, vm, i++);
  1005. error->vm_count = cnt;
  1006. }
  1007. }
  1008. /* Capture all registers which don't fit into another category. */
  1009. static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
  1010. struct drm_i915_error_state *error)
  1011. {
  1012. struct drm_device *dev = dev_priv->dev;
  1013. int i;
  1014. /* General organization
  1015. * 1. Registers specific to a single generation
  1016. * 2. Registers which belong to multiple generations
  1017. * 3. Feature specific registers.
  1018. * 4. Everything else
  1019. * Please try to follow the order.
  1020. */
  1021. /* 1: Registers specific to a single generation */
  1022. if (IS_VALLEYVIEW(dev)) {
  1023. error->gtier[0] = I915_READ(GTIER);
  1024. error->ier = I915_READ(VLV_IER);
  1025. error->forcewake = I915_READ_FW(FORCEWAKE_VLV);
  1026. }
  1027. if (IS_GEN7(dev))
  1028. error->err_int = I915_READ(GEN7_ERR_INT);
  1029. if (INTEL_INFO(dev)->gen >= 8) {
  1030. error->fault_data0 = I915_READ(GEN8_FAULT_TLB_DATA0);
  1031. error->fault_data1 = I915_READ(GEN8_FAULT_TLB_DATA1);
  1032. }
  1033. if (IS_GEN6(dev)) {
  1034. error->forcewake = I915_READ_FW(FORCEWAKE);
  1035. error->gab_ctl = I915_READ(GAB_CTL);
  1036. error->gfx_mode = I915_READ(GFX_MODE);
  1037. }
  1038. /* 2: Registers which belong to multiple generations */
  1039. if (INTEL_INFO(dev)->gen >= 7)
  1040. error->forcewake = I915_READ_FW(FORCEWAKE_MT);
  1041. if (INTEL_INFO(dev)->gen >= 6) {
  1042. error->derrmr = I915_READ(DERRMR);
  1043. error->error = I915_READ(ERROR_GEN6);
  1044. error->done_reg = I915_READ(DONE_REG);
  1045. }
  1046. /* 3: Feature specific registers */
  1047. if (IS_GEN6(dev) || IS_GEN7(dev)) {
  1048. error->gam_ecochk = I915_READ(GAM_ECOCHK);
  1049. error->gac_eco = I915_READ(GAC_ECO_BITS);
  1050. }
  1051. /* 4: Everything else */
  1052. if (HAS_HW_CONTEXTS(dev))
  1053. error->ccid = I915_READ(CCID);
  1054. if (INTEL_INFO(dev)->gen >= 8) {
  1055. error->ier = I915_READ(GEN8_DE_MISC_IER);
  1056. for (i = 0; i < 4; i++)
  1057. error->gtier[i] = I915_READ(GEN8_GT_IER(i));
  1058. } else if (HAS_PCH_SPLIT(dev)) {
  1059. error->ier = I915_READ(DEIER);
  1060. error->gtier[0] = I915_READ(GTIER);
  1061. } else if (IS_GEN2(dev)) {
  1062. error->ier = I915_READ16(IER);
  1063. } else if (!IS_VALLEYVIEW(dev)) {
  1064. error->ier = I915_READ(IER);
  1065. }
  1066. error->eir = I915_READ(EIR);
  1067. error->pgtbl_er = I915_READ(PGTBL_ER);
  1068. i915_get_extra_instdone(dev, error->extra_instdone);
  1069. }
  1070. static void i915_error_capture_msg(struct drm_device *dev,
  1071. struct drm_i915_error_state *error,
  1072. bool wedged,
  1073. const char *error_msg)
  1074. {
  1075. struct drm_i915_private *dev_priv = dev->dev_private;
  1076. u32 ecode;
  1077. int ring_id = -1, len;
  1078. ecode = i915_error_generate_code(dev_priv, error, &ring_id);
  1079. len = scnprintf(error->error_msg, sizeof(error->error_msg),
  1080. "GPU HANG: ecode %d:%d:0x%08x",
  1081. INTEL_INFO(dev)->gen, ring_id, ecode);
  1082. if (ring_id != -1 && error->ring[ring_id].pid != -1)
  1083. len += scnprintf(error->error_msg + len,
  1084. sizeof(error->error_msg) - len,
  1085. ", in %s [%d]",
  1086. error->ring[ring_id].comm,
  1087. error->ring[ring_id].pid);
  1088. scnprintf(error->error_msg + len, sizeof(error->error_msg) - len,
  1089. ", reason: %s, action: %s",
  1090. error_msg,
  1091. wedged ? "reset" : "continue");
  1092. }
  1093. static void i915_capture_gen_state(struct drm_i915_private *dev_priv,
  1094. struct drm_i915_error_state *error)
  1095. {
  1096. error->iommu = -1;
  1097. #ifdef CONFIG_INTEL_IOMMU
  1098. error->iommu = intel_iommu_gfx_mapped;
  1099. #endif
  1100. error->reset_count = i915_reset_count(&dev_priv->gpu_error);
  1101. error->suspend_count = dev_priv->suspend_count;
  1102. }
  1103. /**
  1104. * i915_capture_error_state - capture an error record for later analysis
  1105. * @dev: drm device
  1106. *
  1107. * Should be called when an error is detected (either a hang or an error
  1108. * interrupt) to capture error state from the time of the error. Fills
  1109. * out a structure which becomes available in debugfs for user level tools
  1110. * to pick up.
  1111. */
  1112. void i915_capture_error_state(struct drm_device *dev, bool wedged,
  1113. const char *error_msg)
  1114. {
  1115. static bool warned;
  1116. struct drm_i915_private *dev_priv = dev->dev_private;
  1117. struct drm_i915_error_state *error;
  1118. unsigned long flags;
  1119. /* Account for pipe specific data like PIPE*STAT */
  1120. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  1121. if (!error) {
  1122. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  1123. return;
  1124. }
  1125. kref_init(&error->ref);
  1126. i915_capture_gen_state(dev_priv, error);
  1127. i915_capture_reg_state(dev_priv, error);
  1128. i915_gem_capture_buffers(dev_priv, error);
  1129. i915_gem_record_fences(dev, error);
  1130. i915_gem_record_rings(dev, error);
  1131. do_gettimeofday(&error->time);
  1132. error->overlay = intel_overlay_capture_error_state(dev);
  1133. error->display = intel_display_capture_error_state(dev);
  1134. i915_error_capture_msg(dev, error, wedged, error_msg);
  1135. DRM_INFO("%s\n", error->error_msg);
  1136. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1137. if (dev_priv->gpu_error.first_error == NULL) {
  1138. dev_priv->gpu_error.first_error = error;
  1139. error = NULL;
  1140. }
  1141. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1142. if (error) {
  1143. i915_error_state_free(&error->ref);
  1144. return;
  1145. }
  1146. if (!warned) {
  1147. DRM_INFO("GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.\n");
  1148. DRM_INFO("Please file a _new_ bug report on bugs.freedesktop.org against DRI -> DRM/Intel\n");
  1149. DRM_INFO("drm/i915 developers can then reassign to the right component if it's not a kernel issue.\n");
  1150. DRM_INFO("The gpu crash dump is required to analyze gpu hangs, so please always attach it.\n");
  1151. DRM_INFO("GPU crash dump saved to /sys/class/drm/card%d/error\n", dev->primary->index);
  1152. warned = true;
  1153. }
  1154. }
  1155. void i915_error_state_get(struct drm_device *dev,
  1156. struct i915_error_state_file_priv *error_priv)
  1157. {
  1158. struct drm_i915_private *dev_priv = dev->dev_private;
  1159. spin_lock_irq(&dev_priv->gpu_error.lock);
  1160. error_priv->error = dev_priv->gpu_error.first_error;
  1161. if (error_priv->error)
  1162. kref_get(&error_priv->error->ref);
  1163. spin_unlock_irq(&dev_priv->gpu_error.lock);
  1164. }
  1165. void i915_error_state_put(struct i915_error_state_file_priv *error_priv)
  1166. {
  1167. if (error_priv->error)
  1168. kref_put(&error_priv->error->ref, i915_error_state_free);
  1169. }
  1170. void i915_destroy_error_state(struct drm_device *dev)
  1171. {
  1172. struct drm_i915_private *dev_priv = dev->dev_private;
  1173. struct drm_i915_error_state *error;
  1174. spin_lock_irq(&dev_priv->gpu_error.lock);
  1175. error = dev_priv->gpu_error.first_error;
  1176. dev_priv->gpu_error.first_error = NULL;
  1177. spin_unlock_irq(&dev_priv->gpu_error.lock);
  1178. if (error)
  1179. kref_put(&error->ref, i915_error_state_free);
  1180. }
  1181. const char *i915_cache_level_str(struct drm_i915_private *i915, int type)
  1182. {
  1183. switch (type) {
  1184. case I915_CACHE_NONE: return " uncached";
  1185. case I915_CACHE_LLC: return HAS_LLC(i915) ? " LLC" : " snooped";
  1186. case I915_CACHE_L3_LLC: return " L3+LLC";
  1187. case I915_CACHE_WT: return " WT";
  1188. default: return "";
  1189. }
  1190. }
  1191. /* NB: please notice the memset */
  1192. void i915_get_extra_instdone(struct drm_device *dev, uint32_t *instdone)
  1193. {
  1194. struct drm_i915_private *dev_priv = dev->dev_private;
  1195. memset(instdone, 0, sizeof(*instdone) * I915_NUM_INSTDONE_REG);
  1196. if (IS_GEN2(dev) || IS_GEN3(dev))
  1197. instdone[0] = I915_READ(GEN2_INSTDONE);
  1198. else if (IS_GEN4(dev) || IS_GEN5(dev) || IS_GEN6(dev)) {
  1199. instdone[0] = I915_READ(RING_INSTDONE(RENDER_RING_BASE));
  1200. instdone[1] = I915_READ(GEN4_INSTDONE1);
  1201. } else if (INTEL_INFO(dev)->gen >= 7) {
  1202. instdone[0] = I915_READ(RING_INSTDONE(RENDER_RING_BASE));
  1203. instdone[1] = I915_READ(GEN7_SC_INSTDONE);
  1204. instdone[2] = I915_READ(GEN7_SAMPLER_INSTDONE);
  1205. instdone[3] = I915_READ(GEN7_ROW_INSTDONE);
  1206. }
  1207. }