i915_gpu_error.c 48 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861
  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 <linux/stop_machine.h>
  31. #include <linux/zlib.h>
  32. #include <drm/drm_print.h>
  33. #include "i915_drv.h"
  34. static const char *engine_str(int engine)
  35. {
  36. switch (engine) {
  37. case RCS: return "render";
  38. case VCS: return "bsd";
  39. case BCS: return "blt";
  40. case VECS: return "vebox";
  41. case VCS2: return "bsd2";
  42. default: return "";
  43. }
  44. }
  45. static const char *tiling_flag(int tiling)
  46. {
  47. switch (tiling) {
  48. default:
  49. case I915_TILING_NONE: return "";
  50. case I915_TILING_X: return " X";
  51. case I915_TILING_Y: return " Y";
  52. }
  53. }
  54. static const char *dirty_flag(int dirty)
  55. {
  56. return dirty ? " dirty" : "";
  57. }
  58. static const char *purgeable_flag(int purgeable)
  59. {
  60. return purgeable ? " purgeable" : "";
  61. }
  62. static bool __i915_error_ok(struct drm_i915_error_state_buf *e)
  63. {
  64. if (!e->err && WARN(e->bytes > (e->size - 1), "overflow")) {
  65. e->err = -ENOSPC;
  66. return false;
  67. }
  68. if (e->bytes == e->size - 1 || e->err)
  69. return false;
  70. return true;
  71. }
  72. static bool __i915_error_seek(struct drm_i915_error_state_buf *e,
  73. unsigned len)
  74. {
  75. if (e->pos + len <= e->start) {
  76. e->pos += len;
  77. return false;
  78. }
  79. /* First vsnprintf needs to fit in its entirety for memmove */
  80. if (len >= e->size) {
  81. e->err = -EIO;
  82. return false;
  83. }
  84. return true;
  85. }
  86. static void __i915_error_advance(struct drm_i915_error_state_buf *e,
  87. unsigned len)
  88. {
  89. /* If this is first printf in this window, adjust it so that
  90. * start position matches start of the buffer
  91. */
  92. if (e->pos < e->start) {
  93. const size_t off = e->start - e->pos;
  94. /* Should not happen but be paranoid */
  95. if (off > len || e->bytes) {
  96. e->err = -EIO;
  97. return;
  98. }
  99. memmove(e->buf, e->buf + off, len - off);
  100. e->bytes = len - off;
  101. e->pos = e->start;
  102. return;
  103. }
  104. e->bytes += len;
  105. e->pos += len;
  106. }
  107. __printf(2, 0)
  108. static void i915_error_vprintf(struct drm_i915_error_state_buf *e,
  109. const char *f, va_list args)
  110. {
  111. unsigned len;
  112. if (!__i915_error_ok(e))
  113. return;
  114. /* Seek the first printf which is hits start position */
  115. if (e->pos < e->start) {
  116. va_list tmp;
  117. va_copy(tmp, args);
  118. len = vsnprintf(NULL, 0, f, tmp);
  119. va_end(tmp);
  120. if (!__i915_error_seek(e, len))
  121. return;
  122. }
  123. len = vsnprintf(e->buf + e->bytes, e->size - e->bytes, f, args);
  124. if (len >= e->size - e->bytes)
  125. len = e->size - e->bytes - 1;
  126. __i915_error_advance(e, len);
  127. }
  128. static void i915_error_puts(struct drm_i915_error_state_buf *e,
  129. const char *str)
  130. {
  131. unsigned len;
  132. if (!__i915_error_ok(e))
  133. return;
  134. len = strlen(str);
  135. /* Seek the first printf which is hits start position */
  136. if (e->pos < e->start) {
  137. if (!__i915_error_seek(e, len))
  138. return;
  139. }
  140. if (len >= e->size - e->bytes)
  141. len = e->size - e->bytes - 1;
  142. memcpy(e->buf + e->bytes, str, len);
  143. __i915_error_advance(e, len);
  144. }
  145. #define err_printf(e, ...) i915_error_printf(e, __VA_ARGS__)
  146. #define err_puts(e, s) i915_error_puts(e, s)
  147. static void __i915_printfn_error(struct drm_printer *p, struct va_format *vaf)
  148. {
  149. i915_error_vprintf(p->arg, vaf->fmt, *vaf->va);
  150. }
  151. static inline struct drm_printer
  152. i915_error_printer(struct drm_i915_error_state_buf *e)
  153. {
  154. struct drm_printer p = {
  155. .printfn = __i915_printfn_error,
  156. .arg = e,
  157. };
  158. return p;
  159. }
  160. #ifdef CONFIG_DRM_I915_COMPRESS_ERROR
  161. struct compress {
  162. struct z_stream_s zstream;
  163. void *tmp;
  164. };
  165. static bool compress_init(struct compress *c)
  166. {
  167. struct z_stream_s *zstream = memset(&c->zstream, 0, sizeof(c->zstream));
  168. zstream->workspace =
  169. kmalloc(zlib_deflate_workspacesize(MAX_WBITS, MAX_MEM_LEVEL),
  170. GFP_ATOMIC | __GFP_NOWARN);
  171. if (!zstream->workspace)
  172. return false;
  173. if (zlib_deflateInit(zstream, Z_DEFAULT_COMPRESSION) != Z_OK) {
  174. kfree(zstream->workspace);
  175. return false;
  176. }
  177. c->tmp = NULL;
  178. if (i915_has_memcpy_from_wc())
  179. c->tmp = (void *)__get_free_page(GFP_ATOMIC | __GFP_NOWARN);
  180. return true;
  181. }
  182. static int compress_page(struct compress *c,
  183. void *src,
  184. struct drm_i915_error_object *dst)
  185. {
  186. struct z_stream_s *zstream = &c->zstream;
  187. zstream->next_in = src;
  188. if (c->tmp && i915_memcpy_from_wc(c->tmp, src, PAGE_SIZE))
  189. zstream->next_in = c->tmp;
  190. zstream->avail_in = PAGE_SIZE;
  191. do {
  192. if (zstream->avail_out == 0) {
  193. unsigned long page;
  194. page = __get_free_page(GFP_ATOMIC | __GFP_NOWARN);
  195. if (!page)
  196. return -ENOMEM;
  197. dst->pages[dst->page_count++] = (void *)page;
  198. zstream->next_out = (void *)page;
  199. zstream->avail_out = PAGE_SIZE;
  200. }
  201. if (zlib_deflate(zstream, Z_SYNC_FLUSH) != Z_OK)
  202. return -EIO;
  203. } while (zstream->avail_in);
  204. /* Fallback to uncompressed if we increase size? */
  205. if (0 && zstream->total_out > zstream->total_in)
  206. return -E2BIG;
  207. return 0;
  208. }
  209. static void compress_fini(struct compress *c,
  210. struct drm_i915_error_object *dst)
  211. {
  212. struct z_stream_s *zstream = &c->zstream;
  213. if (dst) {
  214. zlib_deflate(zstream, Z_FINISH);
  215. dst->unused = zstream->avail_out;
  216. }
  217. zlib_deflateEnd(zstream);
  218. kfree(zstream->workspace);
  219. if (c->tmp)
  220. free_page((unsigned long)c->tmp);
  221. }
  222. static void err_compression_marker(struct drm_i915_error_state_buf *m)
  223. {
  224. err_puts(m, ":");
  225. }
  226. #else
  227. struct compress {
  228. };
  229. static bool compress_init(struct compress *c)
  230. {
  231. return true;
  232. }
  233. static int compress_page(struct compress *c,
  234. void *src,
  235. struct drm_i915_error_object *dst)
  236. {
  237. unsigned long page;
  238. void *ptr;
  239. page = __get_free_page(GFP_ATOMIC | __GFP_NOWARN);
  240. if (!page)
  241. return -ENOMEM;
  242. ptr = (void *)page;
  243. if (!i915_memcpy_from_wc(ptr, src, PAGE_SIZE))
  244. memcpy(ptr, src, PAGE_SIZE);
  245. dst->pages[dst->page_count++] = ptr;
  246. return 0;
  247. }
  248. static void compress_fini(struct compress *c,
  249. struct drm_i915_error_object *dst)
  250. {
  251. }
  252. static void err_compression_marker(struct drm_i915_error_state_buf *m)
  253. {
  254. err_puts(m, "~");
  255. }
  256. #endif
  257. static void print_error_buffers(struct drm_i915_error_state_buf *m,
  258. const char *name,
  259. struct drm_i915_error_buffer *err,
  260. int count)
  261. {
  262. int i;
  263. err_printf(m, "%s [%d]:\n", name, count);
  264. while (count--) {
  265. err_printf(m, " %08x_%08x %8u %02x %02x [ ",
  266. upper_32_bits(err->gtt_offset),
  267. lower_32_bits(err->gtt_offset),
  268. err->size,
  269. err->read_domains,
  270. err->write_domain);
  271. for (i = 0; i < I915_NUM_ENGINES; i++)
  272. err_printf(m, "%02x ", err->rseqno[i]);
  273. err_printf(m, "] %02x", err->wseqno);
  274. err_puts(m, tiling_flag(err->tiling));
  275. err_puts(m, dirty_flag(err->dirty));
  276. err_puts(m, purgeable_flag(err->purgeable));
  277. err_puts(m, err->userptr ? " userptr" : "");
  278. err_puts(m, err->engine != -1 ? " " : "");
  279. err_puts(m, engine_str(err->engine));
  280. err_puts(m, i915_cache_level_str(m->i915, err->cache_level));
  281. if (err->name)
  282. err_printf(m, " (name: %d)", err->name);
  283. if (err->fence_reg != I915_FENCE_REG_NONE)
  284. err_printf(m, " (fence: %d)", err->fence_reg);
  285. err_puts(m, "\n");
  286. err++;
  287. }
  288. }
  289. static void error_print_instdone(struct drm_i915_error_state_buf *m,
  290. const struct drm_i915_error_engine *ee)
  291. {
  292. int slice;
  293. int subslice;
  294. err_printf(m, " INSTDONE: 0x%08x\n",
  295. ee->instdone.instdone);
  296. if (ee->engine_id != RCS || INTEL_GEN(m->i915) <= 3)
  297. return;
  298. err_printf(m, " SC_INSTDONE: 0x%08x\n",
  299. ee->instdone.slice_common);
  300. if (INTEL_GEN(m->i915) <= 6)
  301. return;
  302. for_each_instdone_slice_subslice(m->i915, slice, subslice)
  303. err_printf(m, " SAMPLER_INSTDONE[%d][%d]: 0x%08x\n",
  304. slice, subslice,
  305. ee->instdone.sampler[slice][subslice]);
  306. for_each_instdone_slice_subslice(m->i915, slice, subslice)
  307. err_printf(m, " ROW_INSTDONE[%d][%d]: 0x%08x\n",
  308. slice, subslice,
  309. ee->instdone.row[slice][subslice]);
  310. }
  311. static void error_print_request(struct drm_i915_error_state_buf *m,
  312. const char *prefix,
  313. const struct drm_i915_error_request *erq)
  314. {
  315. if (!erq->seqno)
  316. return;
  317. err_printf(m, "%s pid %d, ban score %d, seqno %8x:%08x, prio %d, emitted %dms ago, head %08x, tail %08x\n",
  318. prefix, erq->pid, erq->ban_score,
  319. erq->context, erq->seqno, erq->priority,
  320. jiffies_to_msecs(jiffies - erq->jiffies),
  321. erq->head, erq->tail);
  322. }
  323. static void error_print_context(struct drm_i915_error_state_buf *m,
  324. const char *header,
  325. const struct drm_i915_error_context *ctx)
  326. {
  327. err_printf(m, "%s%s[%d] user_handle %d hw_id %d, prio %d, ban score %d guilty %d active %d\n",
  328. header, ctx->comm, ctx->pid, ctx->handle, ctx->hw_id,
  329. ctx->priority, ctx->ban_score, ctx->guilty, ctx->active);
  330. }
  331. static void error_print_engine(struct drm_i915_error_state_buf *m,
  332. const struct drm_i915_error_engine *ee)
  333. {
  334. int n;
  335. err_printf(m, "%s command stream:\n", engine_str(ee->engine_id));
  336. err_printf(m, " START: 0x%08x\n", ee->start);
  337. err_printf(m, " HEAD: 0x%08x [0x%08x]\n", ee->head, ee->rq_head);
  338. err_printf(m, " TAIL: 0x%08x [0x%08x, 0x%08x]\n",
  339. ee->tail, ee->rq_post, ee->rq_tail);
  340. err_printf(m, " CTL: 0x%08x\n", ee->ctl);
  341. err_printf(m, " MODE: 0x%08x\n", ee->mode);
  342. err_printf(m, " HWS: 0x%08x\n", ee->hws);
  343. err_printf(m, " ACTHD: 0x%08x %08x\n",
  344. (u32)(ee->acthd>>32), (u32)ee->acthd);
  345. err_printf(m, " IPEIR: 0x%08x\n", ee->ipeir);
  346. err_printf(m, " IPEHR: 0x%08x\n", ee->ipehr);
  347. error_print_instdone(m, ee);
  348. if (ee->batchbuffer) {
  349. u64 start = ee->batchbuffer->gtt_offset;
  350. u64 end = start + ee->batchbuffer->gtt_size;
  351. err_printf(m, " batch: [0x%08x_%08x, 0x%08x_%08x]\n",
  352. upper_32_bits(start), lower_32_bits(start),
  353. upper_32_bits(end), lower_32_bits(end));
  354. }
  355. if (INTEL_GEN(m->i915) >= 4) {
  356. err_printf(m, " BBADDR: 0x%08x_%08x\n",
  357. (u32)(ee->bbaddr>>32), (u32)ee->bbaddr);
  358. err_printf(m, " BB_STATE: 0x%08x\n", ee->bbstate);
  359. err_printf(m, " INSTPS: 0x%08x\n", ee->instps);
  360. }
  361. err_printf(m, " INSTPM: 0x%08x\n", ee->instpm);
  362. err_printf(m, " FADDR: 0x%08x %08x\n", upper_32_bits(ee->faddr),
  363. lower_32_bits(ee->faddr));
  364. if (INTEL_GEN(m->i915) >= 6) {
  365. err_printf(m, " RC PSMI: 0x%08x\n", ee->rc_psmi);
  366. err_printf(m, " FAULT_REG: 0x%08x\n", ee->fault_reg);
  367. err_printf(m, " SYNC_0: 0x%08x\n",
  368. ee->semaphore_mboxes[0]);
  369. err_printf(m, " SYNC_1: 0x%08x\n",
  370. ee->semaphore_mboxes[1]);
  371. if (HAS_VEBOX(m->i915))
  372. err_printf(m, " SYNC_2: 0x%08x\n",
  373. ee->semaphore_mboxes[2]);
  374. }
  375. if (USES_PPGTT(m->i915)) {
  376. err_printf(m, " GFX_MODE: 0x%08x\n", ee->vm_info.gfx_mode);
  377. if (INTEL_GEN(m->i915) >= 8) {
  378. int i;
  379. for (i = 0; i < 4; i++)
  380. err_printf(m, " PDP%d: 0x%016llx\n",
  381. i, ee->vm_info.pdp[i]);
  382. } else {
  383. err_printf(m, " PP_DIR_BASE: 0x%08x\n",
  384. ee->vm_info.pp_dir_base);
  385. }
  386. }
  387. err_printf(m, " seqno: 0x%08x\n", ee->seqno);
  388. err_printf(m, " last_seqno: 0x%08x\n", ee->last_seqno);
  389. err_printf(m, " waiting: %s\n", yesno(ee->waiting));
  390. err_printf(m, " ring->head: 0x%08x\n", ee->cpu_ring_head);
  391. err_printf(m, " ring->tail: 0x%08x\n", ee->cpu_ring_tail);
  392. err_printf(m, " hangcheck stall: %s\n", yesno(ee->hangcheck_stalled));
  393. err_printf(m, " hangcheck action: %s\n",
  394. hangcheck_action_to_str(ee->hangcheck_action));
  395. err_printf(m, " hangcheck action timestamp: %lu, %u ms ago\n",
  396. ee->hangcheck_timestamp,
  397. jiffies_to_msecs(jiffies - ee->hangcheck_timestamp));
  398. err_printf(m, " engine reset count: %u\n", ee->reset_count);
  399. for (n = 0; n < ee->num_ports; n++) {
  400. err_printf(m, " ELSP[%d]:", n);
  401. error_print_request(m, " ", &ee->execlist[n]);
  402. }
  403. error_print_context(m, " Active context: ", &ee->context);
  404. }
  405. void i915_error_printf(struct drm_i915_error_state_buf *e, const char *f, ...)
  406. {
  407. va_list args;
  408. va_start(args, f);
  409. i915_error_vprintf(e, f, args);
  410. va_end(args);
  411. }
  412. static int
  413. ascii85_encode_len(int len)
  414. {
  415. return DIV_ROUND_UP(len, 4);
  416. }
  417. static bool
  418. ascii85_encode(u32 in, char *out)
  419. {
  420. int i;
  421. if (in == 0)
  422. return false;
  423. out[5] = '\0';
  424. for (i = 5; i--; ) {
  425. out[i] = '!' + in % 85;
  426. in /= 85;
  427. }
  428. return true;
  429. }
  430. static void print_error_obj(struct drm_i915_error_state_buf *m,
  431. struct intel_engine_cs *engine,
  432. const char *name,
  433. struct drm_i915_error_object *obj)
  434. {
  435. char out[6];
  436. int page;
  437. if (!obj)
  438. return;
  439. if (name) {
  440. err_printf(m, "%s --- %s = 0x%08x %08x\n",
  441. engine ? engine->name : "global", name,
  442. upper_32_bits(obj->gtt_offset),
  443. lower_32_bits(obj->gtt_offset));
  444. }
  445. err_compression_marker(m);
  446. for (page = 0; page < obj->page_count; page++) {
  447. int i, len;
  448. len = PAGE_SIZE;
  449. if (page == obj->page_count - 1)
  450. len -= obj->unused;
  451. len = ascii85_encode_len(len);
  452. for (i = 0; i < len; i++) {
  453. if (ascii85_encode(obj->pages[page][i], out))
  454. err_puts(m, out);
  455. else
  456. err_puts(m, "z");
  457. }
  458. }
  459. err_puts(m, "\n");
  460. }
  461. static void err_print_capabilities(struct drm_i915_error_state_buf *m,
  462. const struct intel_device_info *info)
  463. {
  464. struct drm_printer p = i915_error_printer(m);
  465. intel_device_info_dump_flags(info, &p);
  466. }
  467. static void err_print_params(struct drm_i915_error_state_buf *m,
  468. const struct i915_params *params)
  469. {
  470. struct drm_printer p = i915_error_printer(m);
  471. i915_params_dump(params, &p);
  472. }
  473. static void err_print_pciid(struct drm_i915_error_state_buf *m,
  474. struct drm_i915_private *i915)
  475. {
  476. struct pci_dev *pdev = i915->drm.pdev;
  477. err_printf(m, "PCI ID: 0x%04x\n", pdev->device);
  478. err_printf(m, "PCI Revision: 0x%02x\n", pdev->revision);
  479. err_printf(m, "PCI Subsystem: %04x:%04x\n",
  480. pdev->subsystem_vendor,
  481. pdev->subsystem_device);
  482. }
  483. static void err_print_uc(struct drm_i915_error_state_buf *m,
  484. const struct i915_error_uc *error_uc)
  485. {
  486. struct drm_printer p = i915_error_printer(m);
  487. const struct i915_gpu_state *error =
  488. container_of(error_uc, typeof(*error), uc);
  489. if (!error->device_info.has_guc)
  490. return;
  491. intel_uc_fw_dump(&error_uc->guc_fw, &p);
  492. intel_uc_fw_dump(&error_uc->huc_fw, &p);
  493. print_error_obj(m, NULL, "GuC log buffer", error_uc->guc_log);
  494. }
  495. int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
  496. const struct i915_gpu_state *error)
  497. {
  498. struct drm_i915_private *dev_priv = m->i915;
  499. struct drm_i915_error_object *obj;
  500. int i, j;
  501. if (!error) {
  502. err_printf(m, "No error state collected\n");
  503. return 0;
  504. }
  505. if (*error->error_msg)
  506. err_printf(m, "%s\n", error->error_msg);
  507. err_printf(m, "Kernel: " UTS_RELEASE "\n");
  508. err_printf(m, "Time: %ld s %ld us\n",
  509. error->time.tv_sec, error->time.tv_usec);
  510. err_printf(m, "Boottime: %ld s %ld us\n",
  511. error->boottime.tv_sec, error->boottime.tv_usec);
  512. err_printf(m, "Uptime: %ld s %ld us\n",
  513. error->uptime.tv_sec, error->uptime.tv_usec);
  514. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  515. if (error->engine[i].hangcheck_stalled &&
  516. error->engine[i].context.pid) {
  517. err_printf(m, "Active process (on ring %s): %s [%d], score %d\n",
  518. engine_str(i),
  519. error->engine[i].context.comm,
  520. error->engine[i].context.pid,
  521. error->engine[i].context.ban_score);
  522. }
  523. }
  524. err_printf(m, "Reset count: %u\n", error->reset_count);
  525. err_printf(m, "Suspend count: %u\n", error->suspend_count);
  526. err_printf(m, "Platform: %s\n", intel_platform_name(error->device_info.platform));
  527. err_print_pciid(m, error->i915);
  528. err_printf(m, "IOMMU enabled?: %d\n", error->iommu);
  529. if (HAS_CSR(dev_priv)) {
  530. struct intel_csr *csr = &dev_priv->csr;
  531. err_printf(m, "DMC loaded: %s\n",
  532. yesno(csr->dmc_payload != NULL));
  533. err_printf(m, "DMC fw version: %d.%d\n",
  534. CSR_VERSION_MAJOR(csr->version),
  535. CSR_VERSION_MINOR(csr->version));
  536. }
  537. err_printf(m, "GT awake: %s\n", yesno(error->awake));
  538. err_printf(m, "RPM wakelock: %s\n", yesno(error->wakelock));
  539. err_printf(m, "PM suspended: %s\n", yesno(error->suspended));
  540. err_printf(m, "EIR: 0x%08x\n", error->eir);
  541. err_printf(m, "IER: 0x%08x\n", error->ier);
  542. for (i = 0; i < error->ngtier; i++)
  543. err_printf(m, "GTIER[%d]: 0x%08x\n", i, error->gtier[i]);
  544. err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
  545. err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
  546. err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
  547. err_printf(m, "CCID: 0x%08x\n", error->ccid);
  548. err_printf(m, "Missed interrupts: 0x%08lx\n", dev_priv->gpu_error.missed_irq_rings);
  549. for (i = 0; i < error->nfence; i++)
  550. err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
  551. if (INTEL_GEN(dev_priv) >= 6) {
  552. err_printf(m, "ERROR: 0x%08x\n", error->error);
  553. if (INTEL_GEN(dev_priv) >= 8)
  554. err_printf(m, "FAULT_TLB_DATA: 0x%08x 0x%08x\n",
  555. error->fault_data1, error->fault_data0);
  556. err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
  557. }
  558. if (IS_GEN7(dev_priv))
  559. err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
  560. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  561. if (error->engine[i].engine_id != -1)
  562. error_print_engine(m, &error->engine[i]);
  563. }
  564. for (i = 0; i < ARRAY_SIZE(error->active_vm); i++) {
  565. char buf[128];
  566. int len, first = 1;
  567. if (!error->active_vm[i])
  568. break;
  569. len = scnprintf(buf, sizeof(buf), "Active (");
  570. for (j = 0; j < ARRAY_SIZE(error->engine); j++) {
  571. if (error->engine[j].vm != error->active_vm[i])
  572. continue;
  573. len += scnprintf(buf + len, sizeof(buf), "%s%s",
  574. first ? "" : ", ",
  575. dev_priv->engine[j]->name);
  576. first = 0;
  577. }
  578. scnprintf(buf + len, sizeof(buf), ")");
  579. print_error_buffers(m, buf,
  580. error->active_bo[i],
  581. error->active_bo_count[i]);
  582. }
  583. print_error_buffers(m, "Pinned (global)",
  584. error->pinned_bo,
  585. error->pinned_bo_count);
  586. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  587. const struct drm_i915_error_engine *ee = &error->engine[i];
  588. obj = ee->batchbuffer;
  589. if (obj) {
  590. err_puts(m, dev_priv->engine[i]->name);
  591. if (ee->context.pid)
  592. err_printf(m, " (submitted by %s [%d], ctx %d [%d], score %d)",
  593. ee->context.comm,
  594. ee->context.pid,
  595. ee->context.handle,
  596. ee->context.hw_id,
  597. ee->context.ban_score);
  598. err_printf(m, " --- gtt_offset = 0x%08x %08x\n",
  599. upper_32_bits(obj->gtt_offset),
  600. lower_32_bits(obj->gtt_offset));
  601. print_error_obj(m, dev_priv->engine[i], NULL, obj);
  602. }
  603. for (j = 0; j < ee->user_bo_count; j++)
  604. print_error_obj(m, dev_priv->engine[i],
  605. "user", ee->user_bo[j]);
  606. if (ee->num_requests) {
  607. err_printf(m, "%s --- %d requests\n",
  608. dev_priv->engine[i]->name,
  609. ee->num_requests);
  610. for (j = 0; j < ee->num_requests; j++)
  611. error_print_request(m, " ", &ee->requests[j]);
  612. }
  613. if (IS_ERR(ee->waiters)) {
  614. err_printf(m, "%s --- ? waiters [unable to acquire spinlock]\n",
  615. dev_priv->engine[i]->name);
  616. } else if (ee->num_waiters) {
  617. err_printf(m, "%s --- %d waiters\n",
  618. dev_priv->engine[i]->name,
  619. ee->num_waiters);
  620. for (j = 0; j < ee->num_waiters; j++) {
  621. err_printf(m, " seqno 0x%08x for %s [%d]\n",
  622. ee->waiters[j].seqno,
  623. ee->waiters[j].comm,
  624. ee->waiters[j].pid);
  625. }
  626. }
  627. print_error_obj(m, dev_priv->engine[i],
  628. "ringbuffer", ee->ringbuffer);
  629. print_error_obj(m, dev_priv->engine[i],
  630. "HW Status", ee->hws_page);
  631. print_error_obj(m, dev_priv->engine[i],
  632. "HW context", ee->ctx);
  633. print_error_obj(m, dev_priv->engine[i],
  634. "WA context", ee->wa_ctx);
  635. print_error_obj(m, dev_priv->engine[i],
  636. "WA batchbuffer", ee->wa_batchbuffer);
  637. print_error_obj(m, dev_priv->engine[i],
  638. "NULL context", ee->default_state);
  639. }
  640. if (error->overlay)
  641. intel_overlay_print_error_state(m, error->overlay);
  642. if (error->display)
  643. intel_display_print_error_state(m, error->display);
  644. err_print_capabilities(m, &error->device_info);
  645. err_print_params(m, &error->params);
  646. err_print_uc(m, &error->uc);
  647. if (m->bytes == 0 && m->err)
  648. return m->err;
  649. return 0;
  650. }
  651. int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
  652. struct drm_i915_private *i915,
  653. size_t count, loff_t pos)
  654. {
  655. memset(ebuf, 0, sizeof(*ebuf));
  656. ebuf->i915 = i915;
  657. /* We need to have enough room to store any i915_error_state printf
  658. * so that we can move it to start position.
  659. */
  660. ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
  661. ebuf->buf = kmalloc(ebuf->size,
  662. GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
  663. if (ebuf->buf == NULL) {
  664. ebuf->size = PAGE_SIZE;
  665. ebuf->buf = kmalloc(ebuf->size, GFP_KERNEL);
  666. }
  667. if (ebuf->buf == NULL) {
  668. ebuf->size = 128;
  669. ebuf->buf = kmalloc(ebuf->size, GFP_KERNEL);
  670. }
  671. if (ebuf->buf == NULL)
  672. return -ENOMEM;
  673. ebuf->start = pos;
  674. return 0;
  675. }
  676. static void i915_error_object_free(struct drm_i915_error_object *obj)
  677. {
  678. int page;
  679. if (obj == NULL)
  680. return;
  681. for (page = 0; page < obj->page_count; page++)
  682. free_page((unsigned long)obj->pages[page]);
  683. kfree(obj);
  684. }
  685. static __always_inline void free_param(const char *type, void *x)
  686. {
  687. if (!__builtin_strcmp(type, "char *"))
  688. kfree(*(void **)x);
  689. }
  690. static void cleanup_params(struct i915_gpu_state *error)
  691. {
  692. #define FREE(T, x, ...) free_param(#T, &error->params.x);
  693. I915_PARAMS_FOR_EACH(FREE);
  694. #undef FREE
  695. }
  696. static void cleanup_uc_state(struct i915_gpu_state *error)
  697. {
  698. struct i915_error_uc *error_uc = &error->uc;
  699. kfree(error_uc->guc_fw.path);
  700. kfree(error_uc->huc_fw.path);
  701. i915_error_object_free(error_uc->guc_log);
  702. }
  703. void __i915_gpu_state_free(struct kref *error_ref)
  704. {
  705. struct i915_gpu_state *error =
  706. container_of(error_ref, typeof(*error), ref);
  707. long i, j;
  708. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  709. struct drm_i915_error_engine *ee = &error->engine[i];
  710. for (j = 0; j < ee->user_bo_count; j++)
  711. i915_error_object_free(ee->user_bo[j]);
  712. kfree(ee->user_bo);
  713. i915_error_object_free(ee->batchbuffer);
  714. i915_error_object_free(ee->wa_batchbuffer);
  715. i915_error_object_free(ee->ringbuffer);
  716. i915_error_object_free(ee->hws_page);
  717. i915_error_object_free(ee->ctx);
  718. i915_error_object_free(ee->wa_ctx);
  719. kfree(ee->requests);
  720. if (!IS_ERR_OR_NULL(ee->waiters))
  721. kfree(ee->waiters);
  722. }
  723. for (i = 0; i < ARRAY_SIZE(error->active_bo); i++)
  724. kfree(error->active_bo[i]);
  725. kfree(error->pinned_bo);
  726. kfree(error->overlay);
  727. kfree(error->display);
  728. cleanup_params(error);
  729. cleanup_uc_state(error);
  730. kfree(error);
  731. }
  732. static struct drm_i915_error_object *
  733. i915_error_object_create(struct drm_i915_private *i915,
  734. struct i915_vma *vma)
  735. {
  736. struct i915_ggtt *ggtt = &i915->ggtt;
  737. const u64 slot = ggtt->error_capture.start;
  738. struct drm_i915_error_object *dst;
  739. struct compress compress;
  740. unsigned long num_pages;
  741. struct sgt_iter iter;
  742. dma_addr_t dma;
  743. if (!vma)
  744. return NULL;
  745. num_pages = min_t(u64, vma->size, vma->obj->base.size) >> PAGE_SHIFT;
  746. num_pages = DIV_ROUND_UP(10 * num_pages, 8); /* worstcase zlib growth */
  747. dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *),
  748. GFP_ATOMIC | __GFP_NOWARN);
  749. if (!dst)
  750. return NULL;
  751. dst->gtt_offset = vma->node.start;
  752. dst->gtt_size = vma->node.size;
  753. dst->page_count = 0;
  754. dst->unused = 0;
  755. if (!compress_init(&compress)) {
  756. kfree(dst);
  757. return NULL;
  758. }
  759. for_each_sgt_dma(dma, iter, vma->pages) {
  760. void __iomem *s;
  761. int ret;
  762. ggtt->base.insert_page(&ggtt->base, dma, slot,
  763. I915_CACHE_NONE, 0);
  764. s = io_mapping_map_atomic_wc(&ggtt->iomap, slot);
  765. ret = compress_page(&compress, (void __force *)s, dst);
  766. io_mapping_unmap_atomic(s);
  767. if (ret)
  768. goto unwind;
  769. }
  770. goto out;
  771. unwind:
  772. while (dst->page_count--)
  773. free_page((unsigned long)dst->pages[dst->page_count]);
  774. kfree(dst);
  775. dst = NULL;
  776. out:
  777. compress_fini(&compress, dst);
  778. ggtt->base.clear_range(&ggtt->base, slot, PAGE_SIZE);
  779. return dst;
  780. }
  781. /* The error capture is special as tries to run underneath the normal
  782. * locking rules - so we use the raw version of the i915_gem_active lookup.
  783. */
  784. static inline uint32_t
  785. __active_get_seqno(struct i915_gem_active *active)
  786. {
  787. struct drm_i915_gem_request *request;
  788. request = __i915_gem_active_peek(active);
  789. return request ? request->global_seqno : 0;
  790. }
  791. static inline int
  792. __active_get_engine_id(struct i915_gem_active *active)
  793. {
  794. struct drm_i915_gem_request *request;
  795. request = __i915_gem_active_peek(active);
  796. return request ? request->engine->id : -1;
  797. }
  798. static void capture_bo(struct drm_i915_error_buffer *err,
  799. struct i915_vma *vma)
  800. {
  801. struct drm_i915_gem_object *obj = vma->obj;
  802. int i;
  803. err->size = obj->base.size;
  804. err->name = obj->base.name;
  805. for (i = 0; i < I915_NUM_ENGINES; i++)
  806. err->rseqno[i] = __active_get_seqno(&vma->last_read[i]);
  807. err->wseqno = __active_get_seqno(&obj->frontbuffer_write);
  808. err->engine = __active_get_engine_id(&obj->frontbuffer_write);
  809. err->gtt_offset = vma->node.start;
  810. err->read_domains = obj->base.read_domains;
  811. err->write_domain = obj->base.write_domain;
  812. err->fence_reg = vma->fence ? vma->fence->id : -1;
  813. err->tiling = i915_gem_object_get_tiling(obj);
  814. err->dirty = obj->mm.dirty;
  815. err->purgeable = obj->mm.madv != I915_MADV_WILLNEED;
  816. err->userptr = obj->userptr.mm != NULL;
  817. err->cache_level = obj->cache_level;
  818. }
  819. static u32 capture_error_bo(struct drm_i915_error_buffer *err,
  820. int count, struct list_head *head,
  821. bool pinned_only)
  822. {
  823. struct i915_vma *vma;
  824. int i = 0;
  825. list_for_each_entry(vma, head, vm_link) {
  826. if (pinned_only && !i915_vma_is_pinned(vma))
  827. continue;
  828. capture_bo(err++, vma);
  829. if (++i == count)
  830. break;
  831. }
  832. return i;
  833. }
  834. /* Generate a semi-unique error code. The code is not meant to have meaning, The
  835. * code's only purpose is to try to prevent false duplicated bug reports by
  836. * grossly estimating a GPU error state.
  837. *
  838. * TODO Ideally, hashing the batchbuffer would be a very nice way to determine
  839. * the hang if we could strip the GTT offset information from it.
  840. *
  841. * It's only a small step better than a random number in its current form.
  842. */
  843. static uint32_t i915_error_generate_code(struct drm_i915_private *dev_priv,
  844. struct i915_gpu_state *error,
  845. int *engine_id)
  846. {
  847. uint32_t error_code = 0;
  848. int i;
  849. /* IPEHR would be an ideal way to detect errors, as it's the gross
  850. * measure of "the command that hung." However, has some very common
  851. * synchronization commands which almost always appear in the case
  852. * strictly a client bug. Use instdone to differentiate those some.
  853. */
  854. for (i = 0; i < I915_NUM_ENGINES; i++) {
  855. if (error->engine[i].hangcheck_stalled) {
  856. if (engine_id)
  857. *engine_id = i;
  858. return error->engine[i].ipehr ^
  859. error->engine[i].instdone.instdone;
  860. }
  861. }
  862. return error_code;
  863. }
  864. static void i915_gem_record_fences(struct drm_i915_private *dev_priv,
  865. struct i915_gpu_state *error)
  866. {
  867. int i;
  868. if (INTEL_GEN(dev_priv) >= 6) {
  869. for (i = 0; i < dev_priv->num_fence_regs; i++)
  870. error->fence[i] = I915_READ64(FENCE_REG_GEN6_LO(i));
  871. } else if (INTEL_GEN(dev_priv) >= 4) {
  872. for (i = 0; i < dev_priv->num_fence_regs; i++)
  873. error->fence[i] = I915_READ64(FENCE_REG_965_LO(i));
  874. } else {
  875. for (i = 0; i < dev_priv->num_fence_regs; i++)
  876. error->fence[i] = I915_READ(FENCE_REG(i));
  877. }
  878. error->nfence = i;
  879. }
  880. static inline u32
  881. gen8_engine_sync_index(struct intel_engine_cs *engine,
  882. struct intel_engine_cs *other)
  883. {
  884. int idx;
  885. /*
  886. * rcs -> 0 = vcs, 1 = bcs, 2 = vecs, 3 = vcs2;
  887. * vcs -> 0 = bcs, 1 = vecs, 2 = vcs2, 3 = rcs;
  888. * bcs -> 0 = vecs, 1 = vcs2. 2 = rcs, 3 = vcs;
  889. * vecs -> 0 = vcs2, 1 = rcs, 2 = vcs, 3 = bcs;
  890. * vcs2 -> 0 = rcs, 1 = vcs, 2 = bcs, 3 = vecs;
  891. */
  892. idx = (other - engine) - 1;
  893. if (idx < 0)
  894. idx += I915_NUM_ENGINES;
  895. return idx;
  896. }
  897. static void gen6_record_semaphore_state(struct intel_engine_cs *engine,
  898. struct drm_i915_error_engine *ee)
  899. {
  900. struct drm_i915_private *dev_priv = engine->i915;
  901. ee->semaphore_mboxes[0] = I915_READ(RING_SYNC_0(engine->mmio_base));
  902. ee->semaphore_mboxes[1] = I915_READ(RING_SYNC_1(engine->mmio_base));
  903. if (HAS_VEBOX(dev_priv))
  904. ee->semaphore_mboxes[2] =
  905. I915_READ(RING_SYNC_2(engine->mmio_base));
  906. }
  907. static void error_record_engine_waiters(struct intel_engine_cs *engine,
  908. struct drm_i915_error_engine *ee)
  909. {
  910. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  911. struct drm_i915_error_waiter *waiter;
  912. struct rb_node *rb;
  913. int count;
  914. ee->num_waiters = 0;
  915. ee->waiters = NULL;
  916. if (RB_EMPTY_ROOT(&b->waiters))
  917. return;
  918. if (!spin_trylock_irq(&b->rb_lock)) {
  919. ee->waiters = ERR_PTR(-EDEADLK);
  920. return;
  921. }
  922. count = 0;
  923. for (rb = rb_first(&b->waiters); rb != NULL; rb = rb_next(rb))
  924. count++;
  925. spin_unlock_irq(&b->rb_lock);
  926. waiter = NULL;
  927. if (count)
  928. waiter = kmalloc_array(count,
  929. sizeof(struct drm_i915_error_waiter),
  930. GFP_ATOMIC);
  931. if (!waiter)
  932. return;
  933. if (!spin_trylock_irq(&b->rb_lock)) {
  934. kfree(waiter);
  935. ee->waiters = ERR_PTR(-EDEADLK);
  936. return;
  937. }
  938. ee->waiters = waiter;
  939. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  940. struct intel_wait *w = rb_entry(rb, typeof(*w), node);
  941. strcpy(waiter->comm, w->tsk->comm);
  942. waiter->pid = w->tsk->pid;
  943. waiter->seqno = w->seqno;
  944. waiter++;
  945. if (++ee->num_waiters == count)
  946. break;
  947. }
  948. spin_unlock_irq(&b->rb_lock);
  949. }
  950. static void error_record_engine_registers(struct i915_gpu_state *error,
  951. struct intel_engine_cs *engine,
  952. struct drm_i915_error_engine *ee)
  953. {
  954. struct drm_i915_private *dev_priv = engine->i915;
  955. if (INTEL_GEN(dev_priv) >= 6) {
  956. ee->rc_psmi = I915_READ(RING_PSMI_CTL(engine->mmio_base));
  957. if (INTEL_GEN(dev_priv) >= 8) {
  958. ee->fault_reg = I915_READ(GEN8_RING_FAULT_REG);
  959. } else {
  960. gen6_record_semaphore_state(engine, ee);
  961. ee->fault_reg = I915_READ(RING_FAULT_REG(engine));
  962. }
  963. }
  964. if (INTEL_GEN(dev_priv) >= 4) {
  965. ee->faddr = I915_READ(RING_DMA_FADD(engine->mmio_base));
  966. ee->ipeir = I915_READ(RING_IPEIR(engine->mmio_base));
  967. ee->ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
  968. ee->instps = I915_READ(RING_INSTPS(engine->mmio_base));
  969. ee->bbaddr = I915_READ(RING_BBADDR(engine->mmio_base));
  970. if (INTEL_GEN(dev_priv) >= 8) {
  971. ee->faddr |= (u64) I915_READ(RING_DMA_FADD_UDW(engine->mmio_base)) << 32;
  972. ee->bbaddr |= (u64) I915_READ(RING_BBADDR_UDW(engine->mmio_base)) << 32;
  973. }
  974. ee->bbstate = I915_READ(RING_BBSTATE(engine->mmio_base));
  975. } else {
  976. ee->faddr = I915_READ(DMA_FADD_I8XX);
  977. ee->ipeir = I915_READ(IPEIR);
  978. ee->ipehr = I915_READ(IPEHR);
  979. }
  980. intel_engine_get_instdone(engine, &ee->instdone);
  981. ee->waiting = intel_engine_has_waiter(engine);
  982. ee->instpm = I915_READ(RING_INSTPM(engine->mmio_base));
  983. ee->acthd = intel_engine_get_active_head(engine);
  984. ee->seqno = intel_engine_get_seqno(engine);
  985. ee->last_seqno = intel_engine_last_submit(engine);
  986. ee->start = I915_READ_START(engine);
  987. ee->head = I915_READ_HEAD(engine);
  988. ee->tail = I915_READ_TAIL(engine);
  989. ee->ctl = I915_READ_CTL(engine);
  990. if (INTEL_GEN(dev_priv) > 2)
  991. ee->mode = I915_READ_MODE(engine);
  992. if (!HWS_NEEDS_PHYSICAL(dev_priv)) {
  993. i915_reg_t mmio;
  994. if (IS_GEN7(dev_priv)) {
  995. switch (engine->id) {
  996. default:
  997. case RCS:
  998. mmio = RENDER_HWS_PGA_GEN7;
  999. break;
  1000. case BCS:
  1001. mmio = BLT_HWS_PGA_GEN7;
  1002. break;
  1003. case VCS:
  1004. mmio = BSD_HWS_PGA_GEN7;
  1005. break;
  1006. case VECS:
  1007. mmio = VEBOX_HWS_PGA_GEN7;
  1008. break;
  1009. }
  1010. } else if (IS_GEN6(engine->i915)) {
  1011. mmio = RING_HWS_PGA_GEN6(engine->mmio_base);
  1012. } else {
  1013. /* XXX: gen8 returns to sanity */
  1014. mmio = RING_HWS_PGA(engine->mmio_base);
  1015. }
  1016. ee->hws = I915_READ(mmio);
  1017. }
  1018. ee->hangcheck_timestamp = engine->hangcheck.action_timestamp;
  1019. ee->hangcheck_action = engine->hangcheck.action;
  1020. ee->hangcheck_stalled = engine->hangcheck.stalled;
  1021. ee->reset_count = i915_reset_engine_count(&dev_priv->gpu_error,
  1022. engine);
  1023. if (USES_PPGTT(dev_priv)) {
  1024. int i;
  1025. ee->vm_info.gfx_mode = I915_READ(RING_MODE_GEN7(engine));
  1026. if (IS_GEN6(dev_priv))
  1027. ee->vm_info.pp_dir_base =
  1028. I915_READ(RING_PP_DIR_BASE_READ(engine));
  1029. else if (IS_GEN7(dev_priv))
  1030. ee->vm_info.pp_dir_base =
  1031. I915_READ(RING_PP_DIR_BASE(engine));
  1032. else if (INTEL_GEN(dev_priv) >= 8)
  1033. for (i = 0; i < 4; i++) {
  1034. ee->vm_info.pdp[i] =
  1035. I915_READ(GEN8_RING_PDP_UDW(engine, i));
  1036. ee->vm_info.pdp[i] <<= 32;
  1037. ee->vm_info.pdp[i] |=
  1038. I915_READ(GEN8_RING_PDP_LDW(engine, i));
  1039. }
  1040. }
  1041. }
  1042. static void record_request(struct drm_i915_gem_request *request,
  1043. struct drm_i915_error_request *erq)
  1044. {
  1045. erq->context = request->ctx->hw_id;
  1046. erq->priority = request->priotree.priority;
  1047. erq->ban_score = atomic_read(&request->ctx->ban_score);
  1048. erq->seqno = request->global_seqno;
  1049. erq->jiffies = request->emitted_jiffies;
  1050. erq->head = request->head;
  1051. erq->tail = request->tail;
  1052. rcu_read_lock();
  1053. erq->pid = request->ctx->pid ? pid_nr(request->ctx->pid) : 0;
  1054. rcu_read_unlock();
  1055. }
  1056. static void engine_record_requests(struct intel_engine_cs *engine,
  1057. struct drm_i915_gem_request *first,
  1058. struct drm_i915_error_engine *ee)
  1059. {
  1060. struct drm_i915_gem_request *request;
  1061. int count;
  1062. count = 0;
  1063. request = first;
  1064. list_for_each_entry_from(request, &engine->timeline->requests, link)
  1065. count++;
  1066. if (!count)
  1067. return;
  1068. ee->requests = kcalloc(count, sizeof(*ee->requests), GFP_ATOMIC);
  1069. if (!ee->requests)
  1070. return;
  1071. ee->num_requests = count;
  1072. count = 0;
  1073. request = first;
  1074. list_for_each_entry_from(request, &engine->timeline->requests, link) {
  1075. if (count >= ee->num_requests) {
  1076. /*
  1077. * If the ring request list was changed in
  1078. * between the point where the error request
  1079. * list was created and dimensioned and this
  1080. * point then just exit early to avoid crashes.
  1081. *
  1082. * We don't need to communicate that the
  1083. * request list changed state during error
  1084. * state capture and that the error state is
  1085. * slightly incorrect as a consequence since we
  1086. * are typically only interested in the request
  1087. * list state at the point of error state
  1088. * capture, not in any changes happening during
  1089. * the capture.
  1090. */
  1091. break;
  1092. }
  1093. record_request(request, &ee->requests[count++]);
  1094. }
  1095. ee->num_requests = count;
  1096. }
  1097. static void error_record_engine_execlists(struct intel_engine_cs *engine,
  1098. struct drm_i915_error_engine *ee)
  1099. {
  1100. const struct intel_engine_execlists * const execlists = &engine->execlists;
  1101. unsigned int n;
  1102. for (n = 0; n < execlists_num_ports(execlists); n++) {
  1103. struct drm_i915_gem_request *rq = port_request(&execlists->port[n]);
  1104. if (!rq)
  1105. break;
  1106. record_request(rq, &ee->execlist[n]);
  1107. }
  1108. ee->num_ports = n;
  1109. }
  1110. static void record_context(struct drm_i915_error_context *e,
  1111. struct i915_gem_context *ctx)
  1112. {
  1113. if (ctx->pid) {
  1114. struct task_struct *task;
  1115. rcu_read_lock();
  1116. task = pid_task(ctx->pid, PIDTYPE_PID);
  1117. if (task) {
  1118. strcpy(e->comm, task->comm);
  1119. e->pid = task->pid;
  1120. }
  1121. rcu_read_unlock();
  1122. }
  1123. e->handle = ctx->user_handle;
  1124. e->hw_id = ctx->hw_id;
  1125. e->priority = ctx->priority;
  1126. e->ban_score = atomic_read(&ctx->ban_score);
  1127. e->guilty = atomic_read(&ctx->guilty_count);
  1128. e->active = atomic_read(&ctx->active_count);
  1129. }
  1130. static void request_record_user_bo(struct drm_i915_gem_request *request,
  1131. struct drm_i915_error_engine *ee)
  1132. {
  1133. struct i915_gem_capture_list *c;
  1134. struct drm_i915_error_object **bo;
  1135. long count;
  1136. count = 0;
  1137. for (c = request->capture_list; c; c = c->next)
  1138. count++;
  1139. bo = NULL;
  1140. if (count)
  1141. bo = kcalloc(count, sizeof(*bo), GFP_ATOMIC);
  1142. if (!bo)
  1143. return;
  1144. count = 0;
  1145. for (c = request->capture_list; c; c = c->next) {
  1146. bo[count] = i915_error_object_create(request->i915, c->vma);
  1147. if (!bo[count])
  1148. break;
  1149. count++;
  1150. }
  1151. ee->user_bo = bo;
  1152. ee->user_bo_count = count;
  1153. }
  1154. static struct drm_i915_error_object *
  1155. capture_object(struct drm_i915_private *dev_priv,
  1156. struct drm_i915_gem_object *obj)
  1157. {
  1158. if (obj && i915_gem_object_has_pages(obj)) {
  1159. struct i915_vma fake = {
  1160. .node = { .start = U64_MAX, .size = obj->base.size },
  1161. .size = obj->base.size,
  1162. .pages = obj->mm.pages,
  1163. .obj = obj,
  1164. };
  1165. return i915_error_object_create(dev_priv, &fake);
  1166. } else {
  1167. return NULL;
  1168. }
  1169. }
  1170. static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
  1171. struct i915_gpu_state *error)
  1172. {
  1173. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  1174. int i;
  1175. for (i = 0; i < I915_NUM_ENGINES; i++) {
  1176. struct intel_engine_cs *engine = dev_priv->engine[i];
  1177. struct drm_i915_error_engine *ee = &error->engine[i];
  1178. struct drm_i915_gem_request *request;
  1179. ee->engine_id = -1;
  1180. if (!engine)
  1181. continue;
  1182. ee->engine_id = i;
  1183. error_record_engine_registers(error, engine, ee);
  1184. error_record_engine_waiters(engine, ee);
  1185. error_record_engine_execlists(engine, ee);
  1186. request = i915_gem_find_active_request(engine);
  1187. if (request) {
  1188. struct intel_ring *ring;
  1189. ee->vm = request->ctx->ppgtt ?
  1190. &request->ctx->ppgtt->base : &ggtt->base;
  1191. record_context(&ee->context, request->ctx);
  1192. /* We need to copy these to an anonymous buffer
  1193. * as the simplest method to avoid being overwritten
  1194. * by userspace.
  1195. */
  1196. ee->batchbuffer =
  1197. i915_error_object_create(dev_priv,
  1198. request->batch);
  1199. if (HAS_BROKEN_CS_TLB(dev_priv))
  1200. ee->wa_batchbuffer =
  1201. i915_error_object_create(dev_priv,
  1202. engine->scratch);
  1203. request_record_user_bo(request, ee);
  1204. ee->ctx =
  1205. i915_error_object_create(dev_priv,
  1206. request->ctx->engine[i].state);
  1207. error->simulated |=
  1208. i915_gem_context_no_error_capture(request->ctx);
  1209. ee->rq_head = request->head;
  1210. ee->rq_post = request->postfix;
  1211. ee->rq_tail = request->tail;
  1212. ring = request->ring;
  1213. ee->cpu_ring_head = ring->head;
  1214. ee->cpu_ring_tail = ring->tail;
  1215. ee->ringbuffer =
  1216. i915_error_object_create(dev_priv, ring->vma);
  1217. engine_record_requests(engine, request, ee);
  1218. }
  1219. ee->hws_page =
  1220. i915_error_object_create(dev_priv,
  1221. engine->status_page.vma);
  1222. ee->wa_ctx =
  1223. i915_error_object_create(dev_priv, engine->wa_ctx.vma);
  1224. ee->default_state =
  1225. capture_object(dev_priv, engine->default_state);
  1226. }
  1227. }
  1228. static void i915_gem_capture_vm(struct drm_i915_private *dev_priv,
  1229. struct i915_gpu_state *error,
  1230. struct i915_address_space *vm,
  1231. int idx)
  1232. {
  1233. struct drm_i915_error_buffer *active_bo;
  1234. struct i915_vma *vma;
  1235. int count;
  1236. count = 0;
  1237. list_for_each_entry(vma, &vm->active_list, vm_link)
  1238. count++;
  1239. active_bo = NULL;
  1240. if (count)
  1241. active_bo = kcalloc(count, sizeof(*active_bo), GFP_ATOMIC);
  1242. if (active_bo)
  1243. count = capture_error_bo(active_bo, count, &vm->active_list, false);
  1244. else
  1245. count = 0;
  1246. error->active_vm[idx] = vm;
  1247. error->active_bo[idx] = active_bo;
  1248. error->active_bo_count[idx] = count;
  1249. }
  1250. static void i915_capture_active_buffers(struct drm_i915_private *dev_priv,
  1251. struct i915_gpu_state *error)
  1252. {
  1253. int cnt = 0, i, j;
  1254. BUILD_BUG_ON(ARRAY_SIZE(error->engine) > ARRAY_SIZE(error->active_bo));
  1255. BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_vm));
  1256. BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_bo_count));
  1257. /* Scan each engine looking for unique active contexts/vm */
  1258. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  1259. struct drm_i915_error_engine *ee = &error->engine[i];
  1260. bool found;
  1261. if (!ee->vm)
  1262. continue;
  1263. found = false;
  1264. for (j = 0; j < i && !found; j++)
  1265. found = error->engine[j].vm == ee->vm;
  1266. if (!found)
  1267. i915_gem_capture_vm(dev_priv, error, ee->vm, cnt++);
  1268. }
  1269. }
  1270. static void i915_capture_pinned_buffers(struct drm_i915_private *dev_priv,
  1271. struct i915_gpu_state *error)
  1272. {
  1273. struct i915_address_space *vm = &dev_priv->ggtt.base;
  1274. struct drm_i915_error_buffer *bo;
  1275. struct i915_vma *vma;
  1276. int count_inactive, count_active;
  1277. count_inactive = 0;
  1278. list_for_each_entry(vma, &vm->active_list, vm_link)
  1279. count_inactive++;
  1280. count_active = 0;
  1281. list_for_each_entry(vma, &vm->inactive_list, vm_link)
  1282. count_active++;
  1283. bo = NULL;
  1284. if (count_inactive + count_active)
  1285. bo = kcalloc(count_inactive + count_active,
  1286. sizeof(*bo), GFP_ATOMIC);
  1287. if (!bo)
  1288. return;
  1289. count_inactive = capture_error_bo(bo, count_inactive,
  1290. &vm->active_list, true);
  1291. count_active = capture_error_bo(bo + count_inactive, count_active,
  1292. &vm->inactive_list, true);
  1293. error->pinned_bo_count = count_inactive + count_active;
  1294. error->pinned_bo = bo;
  1295. }
  1296. static void capture_uc_state(struct i915_gpu_state *error)
  1297. {
  1298. struct drm_i915_private *i915 = error->i915;
  1299. struct i915_error_uc *error_uc = &error->uc;
  1300. /* Capturing uC state won't be useful if there is no GuC */
  1301. if (!error->device_info.has_guc)
  1302. return;
  1303. error_uc->guc_fw = i915->guc.fw;
  1304. error_uc->huc_fw = i915->huc.fw;
  1305. /* Non-default firmware paths will be specified by the modparam.
  1306. * As modparams are generally accesible from the userspace make
  1307. * explicit copies of the firmware paths.
  1308. */
  1309. error_uc->guc_fw.path = kstrdup(i915->guc.fw.path, GFP_ATOMIC);
  1310. error_uc->huc_fw.path = kstrdup(i915->huc.fw.path, GFP_ATOMIC);
  1311. error_uc->guc_log = i915_error_object_create(i915, i915->guc.log.vma);
  1312. }
  1313. /* Capture all registers which don't fit into another category. */
  1314. static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
  1315. struct i915_gpu_state *error)
  1316. {
  1317. int i;
  1318. /* General organization
  1319. * 1. Registers specific to a single generation
  1320. * 2. Registers which belong to multiple generations
  1321. * 3. Feature specific registers.
  1322. * 4. Everything else
  1323. * Please try to follow the order.
  1324. */
  1325. /* 1: Registers specific to a single generation */
  1326. if (IS_VALLEYVIEW(dev_priv)) {
  1327. error->gtier[0] = I915_READ(GTIER);
  1328. error->ier = I915_READ(VLV_IER);
  1329. error->forcewake = I915_READ_FW(FORCEWAKE_VLV);
  1330. }
  1331. if (IS_GEN7(dev_priv))
  1332. error->err_int = I915_READ(GEN7_ERR_INT);
  1333. if (INTEL_GEN(dev_priv) >= 8) {
  1334. error->fault_data0 = I915_READ(GEN8_FAULT_TLB_DATA0);
  1335. error->fault_data1 = I915_READ(GEN8_FAULT_TLB_DATA1);
  1336. }
  1337. if (IS_GEN6(dev_priv)) {
  1338. error->forcewake = I915_READ_FW(FORCEWAKE);
  1339. error->gab_ctl = I915_READ(GAB_CTL);
  1340. error->gfx_mode = I915_READ(GFX_MODE);
  1341. }
  1342. /* 2: Registers which belong to multiple generations */
  1343. if (INTEL_GEN(dev_priv) >= 7)
  1344. error->forcewake = I915_READ_FW(FORCEWAKE_MT);
  1345. if (INTEL_GEN(dev_priv) >= 6) {
  1346. error->derrmr = I915_READ(DERRMR);
  1347. error->error = I915_READ(ERROR_GEN6);
  1348. error->done_reg = I915_READ(DONE_REG);
  1349. }
  1350. if (INTEL_GEN(dev_priv) >= 5)
  1351. error->ccid = I915_READ(CCID);
  1352. /* 3: Feature specific registers */
  1353. if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
  1354. error->gam_ecochk = I915_READ(GAM_ECOCHK);
  1355. error->gac_eco = I915_READ(GAC_ECO_BITS);
  1356. }
  1357. /* 4: Everything else */
  1358. if (INTEL_GEN(dev_priv) >= 8) {
  1359. error->ier = I915_READ(GEN8_DE_MISC_IER);
  1360. for (i = 0; i < 4; i++)
  1361. error->gtier[i] = I915_READ(GEN8_GT_IER(i));
  1362. error->ngtier = 4;
  1363. } else if (HAS_PCH_SPLIT(dev_priv)) {
  1364. error->ier = I915_READ(DEIER);
  1365. error->gtier[0] = I915_READ(GTIER);
  1366. error->ngtier = 1;
  1367. } else if (IS_GEN2(dev_priv)) {
  1368. error->ier = I915_READ16(IER);
  1369. } else if (!IS_VALLEYVIEW(dev_priv)) {
  1370. error->ier = I915_READ(IER);
  1371. }
  1372. error->eir = I915_READ(EIR);
  1373. error->pgtbl_er = I915_READ(PGTBL_ER);
  1374. }
  1375. static void i915_error_capture_msg(struct drm_i915_private *dev_priv,
  1376. struct i915_gpu_state *error,
  1377. u32 engine_mask,
  1378. const char *error_msg)
  1379. {
  1380. u32 ecode;
  1381. int engine_id = -1, len;
  1382. ecode = i915_error_generate_code(dev_priv, error, &engine_id);
  1383. len = scnprintf(error->error_msg, sizeof(error->error_msg),
  1384. "GPU HANG: ecode %d:%d:0x%08x",
  1385. INTEL_GEN(dev_priv), engine_id, ecode);
  1386. if (engine_id != -1 && error->engine[engine_id].context.pid)
  1387. len += scnprintf(error->error_msg + len,
  1388. sizeof(error->error_msg) - len,
  1389. ", in %s [%d]",
  1390. error->engine[engine_id].context.comm,
  1391. error->engine[engine_id].context.pid);
  1392. scnprintf(error->error_msg + len, sizeof(error->error_msg) - len,
  1393. ", reason: %s, action: %s",
  1394. error_msg,
  1395. engine_mask ? "reset" : "continue");
  1396. }
  1397. static void i915_capture_gen_state(struct drm_i915_private *dev_priv,
  1398. struct i915_gpu_state *error)
  1399. {
  1400. error->awake = dev_priv->gt.awake;
  1401. error->wakelock = atomic_read(&dev_priv->runtime_pm.wakeref_count);
  1402. error->suspended = dev_priv->runtime_pm.suspended;
  1403. error->iommu = -1;
  1404. #ifdef CONFIG_INTEL_IOMMU
  1405. error->iommu = intel_iommu_gfx_mapped;
  1406. #endif
  1407. error->reset_count = i915_reset_count(&dev_priv->gpu_error);
  1408. error->suspend_count = dev_priv->suspend_count;
  1409. memcpy(&error->device_info,
  1410. INTEL_INFO(dev_priv),
  1411. sizeof(error->device_info));
  1412. }
  1413. static __always_inline void dup_param(const char *type, void *x)
  1414. {
  1415. if (!__builtin_strcmp(type, "char *"))
  1416. *(void **)x = kstrdup(*(void **)x, GFP_ATOMIC);
  1417. }
  1418. static void capture_params(struct i915_gpu_state *error)
  1419. {
  1420. error->params = i915_modparams;
  1421. #define DUP(T, x, ...) dup_param(#T, &error->params.x);
  1422. I915_PARAMS_FOR_EACH(DUP);
  1423. #undef DUP
  1424. }
  1425. static int capture(void *data)
  1426. {
  1427. struct i915_gpu_state *error = data;
  1428. do_gettimeofday(&error->time);
  1429. error->boottime = ktime_to_timeval(ktime_get_boottime());
  1430. error->uptime =
  1431. ktime_to_timeval(ktime_sub(ktime_get(),
  1432. error->i915->gt.last_init_time));
  1433. capture_params(error);
  1434. capture_uc_state(error);
  1435. i915_capture_gen_state(error->i915, error);
  1436. i915_capture_reg_state(error->i915, error);
  1437. i915_gem_record_fences(error->i915, error);
  1438. i915_gem_record_rings(error->i915, error);
  1439. i915_capture_active_buffers(error->i915, error);
  1440. i915_capture_pinned_buffers(error->i915, error);
  1441. error->overlay = intel_overlay_capture_error_state(error->i915);
  1442. error->display = intel_display_capture_error_state(error->i915);
  1443. return 0;
  1444. }
  1445. #define DAY_AS_SECONDS(x) (24 * 60 * 60 * (x))
  1446. struct i915_gpu_state *
  1447. i915_capture_gpu_state(struct drm_i915_private *i915)
  1448. {
  1449. struct i915_gpu_state *error;
  1450. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  1451. if (!error)
  1452. return NULL;
  1453. kref_init(&error->ref);
  1454. error->i915 = i915;
  1455. stop_machine(capture, error, NULL);
  1456. return error;
  1457. }
  1458. /**
  1459. * i915_capture_error_state - capture an error record for later analysis
  1460. * @dev: drm device
  1461. *
  1462. * Should be called when an error is detected (either a hang or an error
  1463. * interrupt) to capture error state from the time of the error. Fills
  1464. * out a structure which becomes available in debugfs for user level tools
  1465. * to pick up.
  1466. */
  1467. void i915_capture_error_state(struct drm_i915_private *dev_priv,
  1468. u32 engine_mask,
  1469. const char *error_msg)
  1470. {
  1471. static bool warned;
  1472. struct i915_gpu_state *error;
  1473. unsigned long flags;
  1474. if (!i915_modparams.error_capture)
  1475. return;
  1476. if (READ_ONCE(dev_priv->gpu_error.first_error))
  1477. return;
  1478. error = i915_capture_gpu_state(dev_priv);
  1479. if (!error) {
  1480. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  1481. return;
  1482. }
  1483. i915_error_capture_msg(dev_priv, error, engine_mask, error_msg);
  1484. DRM_INFO("%s\n", error->error_msg);
  1485. if (!error->simulated) {
  1486. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1487. if (!dev_priv->gpu_error.first_error) {
  1488. dev_priv->gpu_error.first_error = error;
  1489. error = NULL;
  1490. }
  1491. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1492. }
  1493. if (error) {
  1494. __i915_gpu_state_free(&error->ref);
  1495. return;
  1496. }
  1497. if (!warned &&
  1498. ktime_get_real_seconds() - DRIVER_TIMESTAMP < DAY_AS_SECONDS(180)) {
  1499. DRM_INFO("GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.\n");
  1500. DRM_INFO("Please file a _new_ bug report on bugs.freedesktop.org against DRI -> DRM/Intel\n");
  1501. DRM_INFO("drm/i915 developers can then reassign to the right component if it's not a kernel issue.\n");
  1502. DRM_INFO("The gpu crash dump is required to analyze gpu hangs, so please always attach it.\n");
  1503. DRM_INFO("GPU crash dump saved to /sys/class/drm/card%d/error\n",
  1504. dev_priv->drm.primary->index);
  1505. warned = true;
  1506. }
  1507. }
  1508. struct i915_gpu_state *
  1509. i915_first_error_state(struct drm_i915_private *i915)
  1510. {
  1511. struct i915_gpu_state *error;
  1512. spin_lock_irq(&i915->gpu_error.lock);
  1513. error = i915->gpu_error.first_error;
  1514. if (error)
  1515. i915_gpu_state_get(error);
  1516. spin_unlock_irq(&i915->gpu_error.lock);
  1517. return error;
  1518. }
  1519. void i915_reset_error_state(struct drm_i915_private *i915)
  1520. {
  1521. struct i915_gpu_state *error;
  1522. spin_lock_irq(&i915->gpu_error.lock);
  1523. error = i915->gpu_error.first_error;
  1524. i915->gpu_error.first_error = NULL;
  1525. spin_unlock_irq(&i915->gpu_error.lock);
  1526. i915_gpu_state_put(error);
  1527. }