i915_gpu_error.c 48 KB

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