i915_gpu_error.c 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890
  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. #define PRINT_FLAG(x) err_printf(m, #x ": %s\n", yesno(info->x))
  465. DEV_INFO_FOR_EACH_FLAG(PRINT_FLAG);
  466. #undef PRINT_FLAG
  467. }
  468. static __always_inline void err_print_param(struct drm_i915_error_state_buf *m,
  469. const char *name,
  470. const char *type,
  471. const void *x)
  472. {
  473. if (!__builtin_strcmp(type, "bool"))
  474. err_printf(m, "i915.%s=%s\n", name, yesno(*(const bool *)x));
  475. else if (!__builtin_strcmp(type, "int"))
  476. err_printf(m, "i915.%s=%d\n", name, *(const int *)x);
  477. else if (!__builtin_strcmp(type, "unsigned int"))
  478. err_printf(m, "i915.%s=%u\n", name, *(const unsigned int *)x);
  479. else if (!__builtin_strcmp(type, "char *"))
  480. err_printf(m, "i915.%s=%s\n", name, *(const char **)x);
  481. else
  482. BUILD_BUG();
  483. }
  484. static void err_print_params(struct drm_i915_error_state_buf *m,
  485. const struct i915_params *p)
  486. {
  487. #define PRINT(T, x, ...) err_print_param(m, #x, #T, &p->x);
  488. I915_PARAMS_FOR_EACH(PRINT);
  489. #undef PRINT
  490. }
  491. static void err_print_pciid(struct drm_i915_error_state_buf *m,
  492. struct drm_i915_private *i915)
  493. {
  494. struct pci_dev *pdev = i915->drm.pdev;
  495. err_printf(m, "PCI ID: 0x%04x\n", pdev->device);
  496. err_printf(m, "PCI Revision: 0x%02x\n", pdev->revision);
  497. err_printf(m, "PCI Subsystem: %04x:%04x\n",
  498. pdev->subsystem_vendor,
  499. pdev->subsystem_device);
  500. }
  501. static void err_print_uc(struct drm_i915_error_state_buf *m,
  502. const struct i915_error_uc *error_uc)
  503. {
  504. struct drm_printer p = i915_error_printer(m);
  505. const struct i915_gpu_state *error =
  506. container_of(error_uc, typeof(*error), uc);
  507. if (!error->device_info.has_guc)
  508. return;
  509. intel_uc_fw_dump(&error_uc->guc_fw, &p);
  510. intel_uc_fw_dump(&error_uc->huc_fw, &p);
  511. print_error_obj(m, NULL, "GuC log buffer", error_uc->guc_log);
  512. }
  513. int i915_error_state_to_str(struct drm_i915_error_state_buf *m,
  514. const struct i915_gpu_state *error)
  515. {
  516. struct drm_i915_private *dev_priv = m->i915;
  517. struct drm_i915_error_object *obj;
  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. err_printf(m, "Time: %ld s %ld us\n",
  527. error->time.tv_sec, error->time.tv_usec);
  528. err_printf(m, "Boottime: %ld s %ld us\n",
  529. error->boottime.tv_sec, error->boottime.tv_usec);
  530. err_printf(m, "Uptime: %ld s %ld us\n",
  531. error->uptime.tv_sec, error->uptime.tv_usec);
  532. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  533. if (error->engine[i].hangcheck_stalled &&
  534. error->engine[i].context.pid) {
  535. err_printf(m, "Active process (on ring %s): %s [%d], score %d\n",
  536. engine_str(i),
  537. error->engine[i].context.comm,
  538. error->engine[i].context.pid,
  539. error->engine[i].context.ban_score);
  540. }
  541. }
  542. err_printf(m, "Reset count: %u\n", error->reset_count);
  543. err_printf(m, "Suspend count: %u\n", error->suspend_count);
  544. err_printf(m, "Platform: %s\n", intel_platform_name(error->device_info.platform));
  545. err_print_pciid(m, error->i915);
  546. err_printf(m, "IOMMU enabled?: %d\n", error->iommu);
  547. if (HAS_CSR(dev_priv)) {
  548. struct intel_csr *csr = &dev_priv->csr;
  549. err_printf(m, "DMC loaded: %s\n",
  550. yesno(csr->dmc_payload != NULL));
  551. err_printf(m, "DMC fw version: %d.%d\n",
  552. CSR_VERSION_MAJOR(csr->version),
  553. CSR_VERSION_MINOR(csr->version));
  554. }
  555. err_printf(m, "GT awake: %s\n", yesno(error->awake));
  556. err_printf(m, "RPM wakelock: %s\n", yesno(error->wakelock));
  557. err_printf(m, "PM suspended: %s\n", yesno(error->suspended));
  558. err_printf(m, "EIR: 0x%08x\n", error->eir);
  559. err_printf(m, "IER: 0x%08x\n", error->ier);
  560. for (i = 0; i < error->ngtier; i++)
  561. err_printf(m, "GTIER[%d]: 0x%08x\n", i, error->gtier[i]);
  562. err_printf(m, "PGTBL_ER: 0x%08x\n", error->pgtbl_er);
  563. err_printf(m, "FORCEWAKE: 0x%08x\n", error->forcewake);
  564. err_printf(m, "DERRMR: 0x%08x\n", error->derrmr);
  565. err_printf(m, "CCID: 0x%08x\n", error->ccid);
  566. err_printf(m, "Missed interrupts: 0x%08lx\n", dev_priv->gpu_error.missed_irq_rings);
  567. for (i = 0; i < error->nfence; i++)
  568. err_printf(m, " fence[%d] = %08llx\n", i, error->fence[i]);
  569. if (INTEL_GEN(dev_priv) >= 6) {
  570. err_printf(m, "ERROR: 0x%08x\n", error->error);
  571. if (INTEL_GEN(dev_priv) >= 8)
  572. err_printf(m, "FAULT_TLB_DATA: 0x%08x 0x%08x\n",
  573. error->fault_data1, error->fault_data0);
  574. err_printf(m, "DONE_REG: 0x%08x\n", error->done_reg);
  575. }
  576. if (IS_GEN7(dev_priv))
  577. err_printf(m, "ERR_INT: 0x%08x\n", error->err_int);
  578. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  579. if (error->engine[i].engine_id != -1)
  580. error_print_engine(m, &error->engine[i]);
  581. }
  582. for (i = 0; i < ARRAY_SIZE(error->active_vm); i++) {
  583. char buf[128];
  584. int len, first = 1;
  585. if (!error->active_vm[i])
  586. break;
  587. len = scnprintf(buf, sizeof(buf), "Active (");
  588. for (j = 0; j < ARRAY_SIZE(error->engine); j++) {
  589. if (error->engine[j].vm != error->active_vm[i])
  590. continue;
  591. len += scnprintf(buf + len, sizeof(buf), "%s%s",
  592. first ? "" : ", ",
  593. dev_priv->engine[j]->name);
  594. first = 0;
  595. }
  596. scnprintf(buf + len, sizeof(buf), ")");
  597. print_error_buffers(m, buf,
  598. error->active_bo[i],
  599. error->active_bo_count[i]);
  600. }
  601. print_error_buffers(m, "Pinned (global)",
  602. error->pinned_bo,
  603. error->pinned_bo_count);
  604. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  605. const struct drm_i915_error_engine *ee = &error->engine[i];
  606. obj = ee->batchbuffer;
  607. if (obj) {
  608. err_puts(m, dev_priv->engine[i]->name);
  609. if (ee->context.pid)
  610. err_printf(m, " (submitted by %s [%d], ctx %d [%d], score %d)",
  611. ee->context.comm,
  612. ee->context.pid,
  613. ee->context.handle,
  614. ee->context.hw_id,
  615. ee->context.ban_score);
  616. err_printf(m, " --- gtt_offset = 0x%08x %08x\n",
  617. upper_32_bits(obj->gtt_offset),
  618. lower_32_bits(obj->gtt_offset));
  619. print_error_obj(m, dev_priv->engine[i], NULL, obj);
  620. }
  621. for (j = 0; j < ee->user_bo_count; j++)
  622. print_error_obj(m, dev_priv->engine[i],
  623. "user", ee->user_bo[j]);
  624. if (ee->num_requests) {
  625. err_printf(m, "%s --- %d requests\n",
  626. dev_priv->engine[i]->name,
  627. ee->num_requests);
  628. for (j = 0; j < ee->num_requests; j++)
  629. error_print_request(m, " ", &ee->requests[j]);
  630. }
  631. if (IS_ERR(ee->waiters)) {
  632. err_printf(m, "%s --- ? waiters [unable to acquire spinlock]\n",
  633. dev_priv->engine[i]->name);
  634. } else if (ee->num_waiters) {
  635. err_printf(m, "%s --- %d waiters\n",
  636. dev_priv->engine[i]->name,
  637. ee->num_waiters);
  638. for (j = 0; j < ee->num_waiters; j++) {
  639. err_printf(m, " seqno 0x%08x for %s [%d]\n",
  640. ee->waiters[j].seqno,
  641. ee->waiters[j].comm,
  642. ee->waiters[j].pid);
  643. }
  644. }
  645. print_error_obj(m, dev_priv->engine[i],
  646. "ringbuffer", ee->ringbuffer);
  647. print_error_obj(m, dev_priv->engine[i],
  648. "HW Status", ee->hws_page);
  649. print_error_obj(m, dev_priv->engine[i],
  650. "HW context", ee->ctx);
  651. print_error_obj(m, dev_priv->engine[i],
  652. "WA context", ee->wa_ctx);
  653. print_error_obj(m, dev_priv->engine[i],
  654. "WA batchbuffer", ee->wa_batchbuffer);
  655. }
  656. print_error_obj(m, NULL, "Semaphores", error->semaphore);
  657. if (error->overlay)
  658. intel_overlay_print_error_state(m, error->overlay);
  659. if (error->display)
  660. intel_display_print_error_state(m, error->display);
  661. err_print_capabilities(m, &error->device_info);
  662. err_print_params(m, &error->params);
  663. err_print_uc(m, &error->uc);
  664. if (m->bytes == 0 && m->err)
  665. return m->err;
  666. return 0;
  667. }
  668. int i915_error_state_buf_init(struct drm_i915_error_state_buf *ebuf,
  669. struct drm_i915_private *i915,
  670. size_t count, loff_t pos)
  671. {
  672. memset(ebuf, 0, sizeof(*ebuf));
  673. ebuf->i915 = i915;
  674. /* We need to have enough room to store any i915_error_state printf
  675. * so that we can move it to start position.
  676. */
  677. ebuf->size = count + 1 > PAGE_SIZE ? count + 1 : PAGE_SIZE;
  678. ebuf->buf = kmalloc(ebuf->size,
  679. GFP_KERNEL | __GFP_NORETRY | __GFP_NOWARN);
  680. if (ebuf->buf == NULL) {
  681. ebuf->size = PAGE_SIZE;
  682. ebuf->buf = kmalloc(ebuf->size, GFP_KERNEL);
  683. }
  684. if (ebuf->buf == NULL) {
  685. ebuf->size = 128;
  686. ebuf->buf = kmalloc(ebuf->size, GFP_KERNEL);
  687. }
  688. if (ebuf->buf == NULL)
  689. return -ENOMEM;
  690. ebuf->start = pos;
  691. return 0;
  692. }
  693. static void i915_error_object_free(struct drm_i915_error_object *obj)
  694. {
  695. int page;
  696. if (obj == NULL)
  697. return;
  698. for (page = 0; page < obj->page_count; page++)
  699. free_page((unsigned long)obj->pages[page]);
  700. kfree(obj);
  701. }
  702. static __always_inline void free_param(const char *type, void *x)
  703. {
  704. if (!__builtin_strcmp(type, "char *"))
  705. kfree(*(void **)x);
  706. }
  707. static void cleanup_params(struct i915_gpu_state *error)
  708. {
  709. #define FREE(T, x, ...) free_param(#T, &error->params.x);
  710. I915_PARAMS_FOR_EACH(FREE);
  711. #undef FREE
  712. }
  713. static void cleanup_uc_state(struct i915_gpu_state *error)
  714. {
  715. struct i915_error_uc *error_uc = &error->uc;
  716. kfree(error_uc->guc_fw.path);
  717. kfree(error_uc->huc_fw.path);
  718. i915_error_object_free(error_uc->guc_log);
  719. }
  720. void __i915_gpu_state_free(struct kref *error_ref)
  721. {
  722. struct i915_gpu_state *error =
  723. container_of(error_ref, typeof(*error), ref);
  724. long i, j;
  725. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  726. struct drm_i915_error_engine *ee = &error->engine[i];
  727. for (j = 0; j < ee->user_bo_count; j++)
  728. i915_error_object_free(ee->user_bo[j]);
  729. kfree(ee->user_bo);
  730. i915_error_object_free(ee->batchbuffer);
  731. i915_error_object_free(ee->wa_batchbuffer);
  732. i915_error_object_free(ee->ringbuffer);
  733. i915_error_object_free(ee->hws_page);
  734. i915_error_object_free(ee->ctx);
  735. i915_error_object_free(ee->wa_ctx);
  736. kfree(ee->requests);
  737. if (!IS_ERR_OR_NULL(ee->waiters))
  738. kfree(ee->waiters);
  739. }
  740. i915_error_object_free(error->semaphore);
  741. for (i = 0; i < ARRAY_SIZE(error->active_bo); i++)
  742. kfree(error->active_bo[i]);
  743. kfree(error->pinned_bo);
  744. kfree(error->overlay);
  745. kfree(error->display);
  746. cleanup_params(error);
  747. cleanup_uc_state(error);
  748. kfree(error);
  749. }
  750. static struct drm_i915_error_object *
  751. i915_error_object_create(struct drm_i915_private *i915,
  752. struct i915_vma *vma)
  753. {
  754. struct i915_ggtt *ggtt = &i915->ggtt;
  755. const u64 slot = ggtt->error_capture.start;
  756. struct drm_i915_error_object *dst;
  757. struct compress compress;
  758. unsigned long num_pages;
  759. struct sgt_iter iter;
  760. dma_addr_t dma;
  761. if (!vma)
  762. return NULL;
  763. num_pages = min_t(u64, vma->size, vma->obj->base.size) >> PAGE_SHIFT;
  764. num_pages = DIV_ROUND_UP(10 * num_pages, 8); /* worstcase zlib growth */
  765. dst = kmalloc(sizeof(*dst) + num_pages * sizeof(u32 *),
  766. GFP_ATOMIC | __GFP_NOWARN);
  767. if (!dst)
  768. return NULL;
  769. dst->gtt_offset = vma->node.start;
  770. dst->gtt_size = vma->node.size;
  771. dst->page_count = 0;
  772. dst->unused = 0;
  773. if (!compress_init(&compress)) {
  774. kfree(dst);
  775. return NULL;
  776. }
  777. for_each_sgt_dma(dma, iter, vma->pages) {
  778. void __iomem *s;
  779. int ret;
  780. ggtt->base.insert_page(&ggtt->base, dma, slot,
  781. I915_CACHE_NONE, 0);
  782. s = io_mapping_map_atomic_wc(&ggtt->mappable, slot);
  783. ret = compress_page(&compress, (void __force *)s, dst);
  784. io_mapping_unmap_atomic(s);
  785. if (ret)
  786. goto unwind;
  787. }
  788. goto out;
  789. unwind:
  790. while (dst->page_count--)
  791. free_page((unsigned long)dst->pages[dst->page_count]);
  792. kfree(dst);
  793. dst = NULL;
  794. out:
  795. compress_fini(&compress, dst);
  796. ggtt->base.clear_range(&ggtt->base, slot, PAGE_SIZE);
  797. return dst;
  798. }
  799. /* The error capture is special as tries to run underneath the normal
  800. * locking rules - so we use the raw version of the i915_gem_active lookup.
  801. */
  802. static inline uint32_t
  803. __active_get_seqno(struct i915_gem_active *active)
  804. {
  805. struct drm_i915_gem_request *request;
  806. request = __i915_gem_active_peek(active);
  807. return request ? request->global_seqno : 0;
  808. }
  809. static inline int
  810. __active_get_engine_id(struct i915_gem_active *active)
  811. {
  812. struct drm_i915_gem_request *request;
  813. request = __i915_gem_active_peek(active);
  814. return request ? request->engine->id : -1;
  815. }
  816. static void capture_bo(struct drm_i915_error_buffer *err,
  817. struct i915_vma *vma)
  818. {
  819. struct drm_i915_gem_object *obj = vma->obj;
  820. int i;
  821. err->size = obj->base.size;
  822. err->name = obj->base.name;
  823. for (i = 0; i < I915_NUM_ENGINES; i++)
  824. err->rseqno[i] = __active_get_seqno(&vma->last_read[i]);
  825. err->wseqno = __active_get_seqno(&obj->frontbuffer_write);
  826. err->engine = __active_get_engine_id(&obj->frontbuffer_write);
  827. err->gtt_offset = vma->node.start;
  828. err->read_domains = obj->base.read_domains;
  829. err->write_domain = obj->base.write_domain;
  830. err->fence_reg = vma->fence ? vma->fence->id : -1;
  831. err->tiling = i915_gem_object_get_tiling(obj);
  832. err->dirty = obj->mm.dirty;
  833. err->purgeable = obj->mm.madv != I915_MADV_WILLNEED;
  834. err->userptr = obj->userptr.mm != NULL;
  835. err->cache_level = obj->cache_level;
  836. }
  837. static u32 capture_error_bo(struct drm_i915_error_buffer *err,
  838. int count, struct list_head *head,
  839. bool pinned_only)
  840. {
  841. struct i915_vma *vma;
  842. int i = 0;
  843. list_for_each_entry(vma, head, vm_link) {
  844. if (pinned_only && !i915_vma_is_pinned(vma))
  845. continue;
  846. capture_bo(err++, vma);
  847. if (++i == count)
  848. break;
  849. }
  850. return i;
  851. }
  852. /* Generate a semi-unique error code. The code is not meant to have meaning, The
  853. * code's only purpose is to try to prevent false duplicated bug reports by
  854. * grossly estimating a GPU error state.
  855. *
  856. * TODO Ideally, hashing the batchbuffer would be a very nice way to determine
  857. * the hang if we could strip the GTT offset information from it.
  858. *
  859. * It's only a small step better than a random number in its current form.
  860. */
  861. static uint32_t i915_error_generate_code(struct drm_i915_private *dev_priv,
  862. struct i915_gpu_state *error,
  863. int *engine_id)
  864. {
  865. uint32_t error_code = 0;
  866. int i;
  867. /* IPEHR would be an ideal way to detect errors, as it's the gross
  868. * measure of "the command that hung." However, has some very common
  869. * synchronization commands which almost always appear in the case
  870. * strictly a client bug. Use instdone to differentiate those some.
  871. */
  872. for (i = 0; i < I915_NUM_ENGINES; i++) {
  873. if (error->engine[i].hangcheck_stalled) {
  874. if (engine_id)
  875. *engine_id = i;
  876. return error->engine[i].ipehr ^
  877. error->engine[i].instdone.instdone;
  878. }
  879. }
  880. return error_code;
  881. }
  882. static void i915_gem_record_fences(struct drm_i915_private *dev_priv,
  883. struct i915_gpu_state *error)
  884. {
  885. int i;
  886. if (INTEL_GEN(dev_priv) >= 6) {
  887. for (i = 0; i < dev_priv->num_fence_regs; i++)
  888. error->fence[i] = I915_READ64(FENCE_REG_GEN6_LO(i));
  889. } else if (INTEL_GEN(dev_priv) >= 4) {
  890. for (i = 0; i < dev_priv->num_fence_regs; i++)
  891. error->fence[i] = I915_READ64(FENCE_REG_965_LO(i));
  892. } else {
  893. for (i = 0; i < dev_priv->num_fence_regs; i++)
  894. error->fence[i] = I915_READ(FENCE_REG(i));
  895. }
  896. error->nfence = i;
  897. }
  898. static inline u32
  899. gen8_engine_sync_index(struct intel_engine_cs *engine,
  900. struct intel_engine_cs *other)
  901. {
  902. int idx;
  903. /*
  904. * rcs -> 0 = vcs, 1 = bcs, 2 = vecs, 3 = vcs2;
  905. * vcs -> 0 = bcs, 1 = vecs, 2 = vcs2, 3 = rcs;
  906. * bcs -> 0 = vecs, 1 = vcs2. 2 = rcs, 3 = vcs;
  907. * vecs -> 0 = vcs2, 1 = rcs, 2 = vcs, 3 = bcs;
  908. * vcs2 -> 0 = rcs, 1 = vcs, 2 = bcs, 3 = vecs;
  909. */
  910. idx = (other - engine) - 1;
  911. if (idx < 0)
  912. idx += I915_NUM_ENGINES;
  913. return idx;
  914. }
  915. static void gen8_record_semaphore_state(struct i915_gpu_state *error,
  916. struct intel_engine_cs *engine,
  917. struct drm_i915_error_engine *ee)
  918. {
  919. struct drm_i915_private *dev_priv = engine->i915;
  920. struct intel_engine_cs *to;
  921. enum intel_engine_id id;
  922. if (!error->semaphore)
  923. return;
  924. for_each_engine(to, dev_priv, id) {
  925. int idx;
  926. u16 signal_offset;
  927. u32 *tmp;
  928. if (engine == to)
  929. continue;
  930. signal_offset =
  931. (GEN8_SIGNAL_OFFSET(engine, id) & (PAGE_SIZE - 1)) / 4;
  932. tmp = error->semaphore->pages[0];
  933. idx = gen8_engine_sync_index(engine, to);
  934. ee->semaphore_mboxes[idx] = tmp[signal_offset];
  935. }
  936. }
  937. static void gen6_record_semaphore_state(struct intel_engine_cs *engine,
  938. struct drm_i915_error_engine *ee)
  939. {
  940. struct drm_i915_private *dev_priv = engine->i915;
  941. ee->semaphore_mboxes[0] = I915_READ(RING_SYNC_0(engine->mmio_base));
  942. ee->semaphore_mboxes[1] = I915_READ(RING_SYNC_1(engine->mmio_base));
  943. if (HAS_VEBOX(dev_priv))
  944. ee->semaphore_mboxes[2] =
  945. I915_READ(RING_SYNC_2(engine->mmio_base));
  946. }
  947. static void error_record_engine_waiters(struct intel_engine_cs *engine,
  948. struct drm_i915_error_engine *ee)
  949. {
  950. struct intel_breadcrumbs *b = &engine->breadcrumbs;
  951. struct drm_i915_error_waiter *waiter;
  952. struct rb_node *rb;
  953. int count;
  954. ee->num_waiters = 0;
  955. ee->waiters = NULL;
  956. if (RB_EMPTY_ROOT(&b->waiters))
  957. return;
  958. if (!spin_trylock_irq(&b->rb_lock)) {
  959. ee->waiters = ERR_PTR(-EDEADLK);
  960. return;
  961. }
  962. count = 0;
  963. for (rb = rb_first(&b->waiters); rb != NULL; rb = rb_next(rb))
  964. count++;
  965. spin_unlock_irq(&b->rb_lock);
  966. waiter = NULL;
  967. if (count)
  968. waiter = kmalloc_array(count,
  969. sizeof(struct drm_i915_error_waiter),
  970. GFP_ATOMIC);
  971. if (!waiter)
  972. return;
  973. if (!spin_trylock_irq(&b->rb_lock)) {
  974. kfree(waiter);
  975. ee->waiters = ERR_PTR(-EDEADLK);
  976. return;
  977. }
  978. ee->waiters = waiter;
  979. for (rb = rb_first(&b->waiters); rb; rb = rb_next(rb)) {
  980. struct intel_wait *w = rb_entry(rb, typeof(*w), node);
  981. strcpy(waiter->comm, w->tsk->comm);
  982. waiter->pid = w->tsk->pid;
  983. waiter->seqno = w->seqno;
  984. waiter++;
  985. if (++ee->num_waiters == count)
  986. break;
  987. }
  988. spin_unlock_irq(&b->rb_lock);
  989. }
  990. static void error_record_engine_registers(struct i915_gpu_state *error,
  991. struct intel_engine_cs *engine,
  992. struct drm_i915_error_engine *ee)
  993. {
  994. struct drm_i915_private *dev_priv = engine->i915;
  995. if (INTEL_GEN(dev_priv) >= 6) {
  996. ee->rc_psmi = I915_READ(RING_PSMI_CTL(engine->mmio_base));
  997. if (INTEL_GEN(dev_priv) >= 8) {
  998. gen8_record_semaphore_state(error, engine, ee);
  999. ee->fault_reg = I915_READ(GEN8_RING_FAULT_REG);
  1000. } else {
  1001. gen6_record_semaphore_state(engine, ee);
  1002. ee->fault_reg = I915_READ(RING_FAULT_REG(engine));
  1003. }
  1004. }
  1005. if (INTEL_GEN(dev_priv) >= 4) {
  1006. ee->faddr = I915_READ(RING_DMA_FADD(engine->mmio_base));
  1007. ee->ipeir = I915_READ(RING_IPEIR(engine->mmio_base));
  1008. ee->ipehr = I915_READ(RING_IPEHR(engine->mmio_base));
  1009. ee->instps = I915_READ(RING_INSTPS(engine->mmio_base));
  1010. ee->bbaddr = I915_READ(RING_BBADDR(engine->mmio_base));
  1011. if (INTEL_GEN(dev_priv) >= 8) {
  1012. ee->faddr |= (u64) I915_READ(RING_DMA_FADD_UDW(engine->mmio_base)) << 32;
  1013. ee->bbaddr |= (u64) I915_READ(RING_BBADDR_UDW(engine->mmio_base)) << 32;
  1014. }
  1015. ee->bbstate = I915_READ(RING_BBSTATE(engine->mmio_base));
  1016. } else {
  1017. ee->faddr = I915_READ(DMA_FADD_I8XX);
  1018. ee->ipeir = I915_READ(IPEIR);
  1019. ee->ipehr = I915_READ(IPEHR);
  1020. }
  1021. intel_engine_get_instdone(engine, &ee->instdone);
  1022. ee->waiting = intel_engine_has_waiter(engine);
  1023. ee->instpm = I915_READ(RING_INSTPM(engine->mmio_base));
  1024. ee->acthd = intel_engine_get_active_head(engine);
  1025. ee->seqno = intel_engine_get_seqno(engine);
  1026. ee->last_seqno = intel_engine_last_submit(engine);
  1027. ee->start = I915_READ_START(engine);
  1028. ee->head = I915_READ_HEAD(engine);
  1029. ee->tail = I915_READ_TAIL(engine);
  1030. ee->ctl = I915_READ_CTL(engine);
  1031. if (INTEL_GEN(dev_priv) > 2)
  1032. ee->mode = I915_READ_MODE(engine);
  1033. if (!HWS_NEEDS_PHYSICAL(dev_priv)) {
  1034. i915_reg_t mmio;
  1035. if (IS_GEN7(dev_priv)) {
  1036. switch (engine->id) {
  1037. default:
  1038. case RCS:
  1039. mmio = RENDER_HWS_PGA_GEN7;
  1040. break;
  1041. case BCS:
  1042. mmio = BLT_HWS_PGA_GEN7;
  1043. break;
  1044. case VCS:
  1045. mmio = BSD_HWS_PGA_GEN7;
  1046. break;
  1047. case VECS:
  1048. mmio = VEBOX_HWS_PGA_GEN7;
  1049. break;
  1050. }
  1051. } else if (IS_GEN6(engine->i915)) {
  1052. mmio = RING_HWS_PGA_GEN6(engine->mmio_base);
  1053. } else {
  1054. /* XXX: gen8 returns to sanity */
  1055. mmio = RING_HWS_PGA(engine->mmio_base);
  1056. }
  1057. ee->hws = I915_READ(mmio);
  1058. }
  1059. ee->hangcheck_timestamp = engine->hangcheck.action_timestamp;
  1060. ee->hangcheck_action = engine->hangcheck.action;
  1061. ee->hangcheck_stalled = engine->hangcheck.stalled;
  1062. ee->reset_count = i915_reset_engine_count(&dev_priv->gpu_error,
  1063. engine);
  1064. if (USES_PPGTT(dev_priv)) {
  1065. int i;
  1066. ee->vm_info.gfx_mode = I915_READ(RING_MODE_GEN7(engine));
  1067. if (IS_GEN6(dev_priv))
  1068. ee->vm_info.pp_dir_base =
  1069. I915_READ(RING_PP_DIR_BASE_READ(engine));
  1070. else if (IS_GEN7(dev_priv))
  1071. ee->vm_info.pp_dir_base =
  1072. I915_READ(RING_PP_DIR_BASE(engine));
  1073. else if (INTEL_GEN(dev_priv) >= 8)
  1074. for (i = 0; i < 4; i++) {
  1075. ee->vm_info.pdp[i] =
  1076. I915_READ(GEN8_RING_PDP_UDW(engine, i));
  1077. ee->vm_info.pdp[i] <<= 32;
  1078. ee->vm_info.pdp[i] |=
  1079. I915_READ(GEN8_RING_PDP_LDW(engine, i));
  1080. }
  1081. }
  1082. }
  1083. static void record_request(struct drm_i915_gem_request *request,
  1084. struct drm_i915_error_request *erq)
  1085. {
  1086. erq->context = request->ctx->hw_id;
  1087. erq->priority = request->priotree.priority;
  1088. erq->ban_score = atomic_read(&request->ctx->ban_score);
  1089. erq->seqno = request->global_seqno;
  1090. erq->jiffies = request->emitted_jiffies;
  1091. erq->head = request->head;
  1092. erq->tail = request->tail;
  1093. rcu_read_lock();
  1094. erq->pid = request->ctx->pid ? pid_nr(request->ctx->pid) : 0;
  1095. rcu_read_unlock();
  1096. }
  1097. static void engine_record_requests(struct intel_engine_cs *engine,
  1098. struct drm_i915_gem_request *first,
  1099. struct drm_i915_error_engine *ee)
  1100. {
  1101. struct drm_i915_gem_request *request;
  1102. int count;
  1103. count = 0;
  1104. request = first;
  1105. list_for_each_entry_from(request, &engine->timeline->requests, link)
  1106. count++;
  1107. if (!count)
  1108. return;
  1109. ee->requests = kcalloc(count, sizeof(*ee->requests), GFP_ATOMIC);
  1110. if (!ee->requests)
  1111. return;
  1112. ee->num_requests = count;
  1113. count = 0;
  1114. request = first;
  1115. list_for_each_entry_from(request, &engine->timeline->requests, link) {
  1116. if (count >= ee->num_requests) {
  1117. /*
  1118. * If the ring request list was changed in
  1119. * between the point where the error request
  1120. * list was created and dimensioned and this
  1121. * point then just exit early to avoid crashes.
  1122. *
  1123. * We don't need to communicate that the
  1124. * request list changed state during error
  1125. * state capture and that the error state is
  1126. * slightly incorrect as a consequence since we
  1127. * are typically only interested in the request
  1128. * list state at the point of error state
  1129. * capture, not in any changes happening during
  1130. * the capture.
  1131. */
  1132. break;
  1133. }
  1134. record_request(request, &ee->requests[count++]);
  1135. }
  1136. ee->num_requests = count;
  1137. }
  1138. static void error_record_engine_execlists(struct intel_engine_cs *engine,
  1139. struct drm_i915_error_engine *ee)
  1140. {
  1141. const struct intel_engine_execlists * const execlists = &engine->execlists;
  1142. unsigned int n;
  1143. for (n = 0; n < execlists_num_ports(execlists); n++) {
  1144. struct drm_i915_gem_request *rq = port_request(&execlists->port[n]);
  1145. if (!rq)
  1146. break;
  1147. record_request(rq, &ee->execlist[n]);
  1148. }
  1149. ee->num_ports = n;
  1150. }
  1151. static void record_context(struct drm_i915_error_context *e,
  1152. struct i915_gem_context *ctx)
  1153. {
  1154. if (ctx->pid) {
  1155. struct task_struct *task;
  1156. rcu_read_lock();
  1157. task = pid_task(ctx->pid, PIDTYPE_PID);
  1158. if (task) {
  1159. strcpy(e->comm, task->comm);
  1160. e->pid = task->pid;
  1161. }
  1162. rcu_read_unlock();
  1163. }
  1164. e->handle = ctx->user_handle;
  1165. e->hw_id = ctx->hw_id;
  1166. e->priority = ctx->priority;
  1167. e->ban_score = atomic_read(&ctx->ban_score);
  1168. e->guilty = atomic_read(&ctx->guilty_count);
  1169. e->active = atomic_read(&ctx->active_count);
  1170. }
  1171. static void request_record_user_bo(struct drm_i915_gem_request *request,
  1172. struct drm_i915_error_engine *ee)
  1173. {
  1174. struct i915_gem_capture_list *c;
  1175. struct drm_i915_error_object **bo;
  1176. long count;
  1177. count = 0;
  1178. for (c = request->capture_list; c; c = c->next)
  1179. count++;
  1180. bo = NULL;
  1181. if (count)
  1182. bo = kcalloc(count, sizeof(*bo), GFP_ATOMIC);
  1183. if (!bo)
  1184. return;
  1185. count = 0;
  1186. for (c = request->capture_list; c; c = c->next) {
  1187. bo[count] = i915_error_object_create(request->i915, c->vma);
  1188. if (!bo[count])
  1189. break;
  1190. count++;
  1191. }
  1192. ee->user_bo = bo;
  1193. ee->user_bo_count = count;
  1194. }
  1195. static void i915_gem_record_rings(struct drm_i915_private *dev_priv,
  1196. struct i915_gpu_state *error)
  1197. {
  1198. struct i915_ggtt *ggtt = &dev_priv->ggtt;
  1199. int i;
  1200. error->semaphore =
  1201. i915_error_object_create(dev_priv, dev_priv->semaphore);
  1202. for (i = 0; i < I915_NUM_ENGINES; i++) {
  1203. struct intel_engine_cs *engine = dev_priv->engine[i];
  1204. struct drm_i915_error_engine *ee = &error->engine[i];
  1205. struct drm_i915_gem_request *request;
  1206. ee->engine_id = -1;
  1207. if (!engine)
  1208. continue;
  1209. ee->engine_id = i;
  1210. error_record_engine_registers(error, engine, ee);
  1211. error_record_engine_waiters(engine, ee);
  1212. error_record_engine_execlists(engine, ee);
  1213. request = i915_gem_find_active_request(engine);
  1214. if (request) {
  1215. struct intel_ring *ring;
  1216. ee->vm = request->ctx->ppgtt ?
  1217. &request->ctx->ppgtt->base : &ggtt->base;
  1218. record_context(&ee->context, request->ctx);
  1219. /* We need to copy these to an anonymous buffer
  1220. * as the simplest method to avoid being overwritten
  1221. * by userspace.
  1222. */
  1223. ee->batchbuffer =
  1224. i915_error_object_create(dev_priv,
  1225. request->batch);
  1226. if (HAS_BROKEN_CS_TLB(dev_priv))
  1227. ee->wa_batchbuffer =
  1228. i915_error_object_create(dev_priv,
  1229. engine->scratch);
  1230. request_record_user_bo(request, ee);
  1231. ee->ctx =
  1232. i915_error_object_create(dev_priv,
  1233. request->ctx->engine[i].state);
  1234. error->simulated |=
  1235. i915_gem_context_no_error_capture(request->ctx);
  1236. ee->rq_head = request->head;
  1237. ee->rq_post = request->postfix;
  1238. ee->rq_tail = request->tail;
  1239. ring = request->ring;
  1240. ee->cpu_ring_head = ring->head;
  1241. ee->cpu_ring_tail = ring->tail;
  1242. ee->ringbuffer =
  1243. i915_error_object_create(dev_priv, ring->vma);
  1244. engine_record_requests(engine, request, ee);
  1245. }
  1246. ee->hws_page =
  1247. i915_error_object_create(dev_priv,
  1248. engine->status_page.vma);
  1249. ee->wa_ctx =
  1250. i915_error_object_create(dev_priv, engine->wa_ctx.vma);
  1251. }
  1252. }
  1253. static void i915_gem_capture_vm(struct drm_i915_private *dev_priv,
  1254. struct i915_gpu_state *error,
  1255. struct i915_address_space *vm,
  1256. int idx)
  1257. {
  1258. struct drm_i915_error_buffer *active_bo;
  1259. struct i915_vma *vma;
  1260. int count;
  1261. count = 0;
  1262. list_for_each_entry(vma, &vm->active_list, vm_link)
  1263. count++;
  1264. active_bo = NULL;
  1265. if (count)
  1266. active_bo = kcalloc(count, sizeof(*active_bo), GFP_ATOMIC);
  1267. if (active_bo)
  1268. count = capture_error_bo(active_bo, count, &vm->active_list, false);
  1269. else
  1270. count = 0;
  1271. error->active_vm[idx] = vm;
  1272. error->active_bo[idx] = active_bo;
  1273. error->active_bo_count[idx] = count;
  1274. }
  1275. static void i915_capture_active_buffers(struct drm_i915_private *dev_priv,
  1276. struct i915_gpu_state *error)
  1277. {
  1278. int cnt = 0, i, j;
  1279. BUILD_BUG_ON(ARRAY_SIZE(error->engine) > ARRAY_SIZE(error->active_bo));
  1280. BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_vm));
  1281. BUILD_BUG_ON(ARRAY_SIZE(error->active_bo) != ARRAY_SIZE(error->active_bo_count));
  1282. /* Scan each engine looking for unique active contexts/vm */
  1283. for (i = 0; i < ARRAY_SIZE(error->engine); i++) {
  1284. struct drm_i915_error_engine *ee = &error->engine[i];
  1285. bool found;
  1286. if (!ee->vm)
  1287. continue;
  1288. found = false;
  1289. for (j = 0; j < i && !found; j++)
  1290. found = error->engine[j].vm == ee->vm;
  1291. if (!found)
  1292. i915_gem_capture_vm(dev_priv, error, ee->vm, cnt++);
  1293. }
  1294. }
  1295. static void i915_capture_pinned_buffers(struct drm_i915_private *dev_priv,
  1296. struct i915_gpu_state *error)
  1297. {
  1298. struct i915_address_space *vm = &dev_priv->ggtt.base;
  1299. struct drm_i915_error_buffer *bo;
  1300. struct i915_vma *vma;
  1301. int count_inactive, count_active;
  1302. count_inactive = 0;
  1303. list_for_each_entry(vma, &vm->active_list, vm_link)
  1304. count_inactive++;
  1305. count_active = 0;
  1306. list_for_each_entry(vma, &vm->inactive_list, vm_link)
  1307. count_active++;
  1308. bo = NULL;
  1309. if (count_inactive + count_active)
  1310. bo = kcalloc(count_inactive + count_active,
  1311. sizeof(*bo), GFP_ATOMIC);
  1312. if (!bo)
  1313. return;
  1314. count_inactive = capture_error_bo(bo, count_inactive,
  1315. &vm->active_list, true);
  1316. count_active = capture_error_bo(bo + count_inactive, count_active,
  1317. &vm->inactive_list, true);
  1318. error->pinned_bo_count = count_inactive + count_active;
  1319. error->pinned_bo = bo;
  1320. }
  1321. static void capture_uc_state(struct i915_gpu_state *error)
  1322. {
  1323. struct drm_i915_private *i915 = error->i915;
  1324. struct i915_error_uc *error_uc = &error->uc;
  1325. /* Capturing uC state won't be useful if there is no GuC */
  1326. if (!error->device_info.has_guc)
  1327. return;
  1328. error_uc->guc_fw = i915->guc.fw;
  1329. error_uc->huc_fw = i915->huc.fw;
  1330. /* Non-default firmware paths will be specified by the modparam.
  1331. * As modparams are generally accesible from the userspace make
  1332. * explicit copies of the firmware paths.
  1333. */
  1334. error_uc->guc_fw.path = kstrdup(i915->guc.fw.path, GFP_ATOMIC);
  1335. error_uc->huc_fw.path = kstrdup(i915->huc.fw.path, GFP_ATOMIC);
  1336. error_uc->guc_log = i915_error_object_create(i915, i915->guc.log.vma);
  1337. }
  1338. /* Capture all registers which don't fit into another category. */
  1339. static void i915_capture_reg_state(struct drm_i915_private *dev_priv,
  1340. struct i915_gpu_state *error)
  1341. {
  1342. int i;
  1343. /* General organization
  1344. * 1. Registers specific to a single generation
  1345. * 2. Registers which belong to multiple generations
  1346. * 3. Feature specific registers.
  1347. * 4. Everything else
  1348. * Please try to follow the order.
  1349. */
  1350. /* 1: Registers specific to a single generation */
  1351. if (IS_VALLEYVIEW(dev_priv)) {
  1352. error->gtier[0] = I915_READ(GTIER);
  1353. error->ier = I915_READ(VLV_IER);
  1354. error->forcewake = I915_READ_FW(FORCEWAKE_VLV);
  1355. }
  1356. if (IS_GEN7(dev_priv))
  1357. error->err_int = I915_READ(GEN7_ERR_INT);
  1358. if (INTEL_GEN(dev_priv) >= 8) {
  1359. error->fault_data0 = I915_READ(GEN8_FAULT_TLB_DATA0);
  1360. error->fault_data1 = I915_READ(GEN8_FAULT_TLB_DATA1);
  1361. }
  1362. if (IS_GEN6(dev_priv)) {
  1363. error->forcewake = I915_READ_FW(FORCEWAKE);
  1364. error->gab_ctl = I915_READ(GAB_CTL);
  1365. error->gfx_mode = I915_READ(GFX_MODE);
  1366. }
  1367. /* 2: Registers which belong to multiple generations */
  1368. if (INTEL_GEN(dev_priv) >= 7)
  1369. error->forcewake = I915_READ_FW(FORCEWAKE_MT);
  1370. if (INTEL_GEN(dev_priv) >= 6) {
  1371. error->derrmr = I915_READ(DERRMR);
  1372. error->error = I915_READ(ERROR_GEN6);
  1373. error->done_reg = I915_READ(DONE_REG);
  1374. }
  1375. if (INTEL_GEN(dev_priv) >= 5)
  1376. error->ccid = I915_READ(CCID);
  1377. /* 3: Feature specific registers */
  1378. if (IS_GEN6(dev_priv) || IS_GEN7(dev_priv)) {
  1379. error->gam_ecochk = I915_READ(GAM_ECOCHK);
  1380. error->gac_eco = I915_READ(GAC_ECO_BITS);
  1381. }
  1382. /* 4: Everything else */
  1383. if (INTEL_GEN(dev_priv) >= 8) {
  1384. error->ier = I915_READ(GEN8_DE_MISC_IER);
  1385. for (i = 0; i < 4; i++)
  1386. error->gtier[i] = I915_READ(GEN8_GT_IER(i));
  1387. error->ngtier = 4;
  1388. } else if (HAS_PCH_SPLIT(dev_priv)) {
  1389. error->ier = I915_READ(DEIER);
  1390. error->gtier[0] = I915_READ(GTIER);
  1391. error->ngtier = 1;
  1392. } else if (IS_GEN2(dev_priv)) {
  1393. error->ier = I915_READ16(IER);
  1394. } else if (!IS_VALLEYVIEW(dev_priv)) {
  1395. error->ier = I915_READ(IER);
  1396. }
  1397. error->eir = I915_READ(EIR);
  1398. error->pgtbl_er = I915_READ(PGTBL_ER);
  1399. }
  1400. static void i915_error_capture_msg(struct drm_i915_private *dev_priv,
  1401. struct i915_gpu_state *error,
  1402. u32 engine_mask,
  1403. const char *error_msg)
  1404. {
  1405. u32 ecode;
  1406. int engine_id = -1, len;
  1407. ecode = i915_error_generate_code(dev_priv, error, &engine_id);
  1408. len = scnprintf(error->error_msg, sizeof(error->error_msg),
  1409. "GPU HANG: ecode %d:%d:0x%08x",
  1410. INTEL_GEN(dev_priv), engine_id, ecode);
  1411. if (engine_id != -1 && error->engine[engine_id].context.pid)
  1412. len += scnprintf(error->error_msg + len,
  1413. sizeof(error->error_msg) - len,
  1414. ", in %s [%d]",
  1415. error->engine[engine_id].context.comm,
  1416. error->engine[engine_id].context.pid);
  1417. scnprintf(error->error_msg + len, sizeof(error->error_msg) - len,
  1418. ", reason: %s, action: %s",
  1419. error_msg,
  1420. engine_mask ? "reset" : "continue");
  1421. }
  1422. static void i915_capture_gen_state(struct drm_i915_private *dev_priv,
  1423. struct i915_gpu_state *error)
  1424. {
  1425. error->awake = dev_priv->gt.awake;
  1426. error->wakelock = atomic_read(&dev_priv->runtime_pm.wakeref_count);
  1427. error->suspended = dev_priv->runtime_pm.suspended;
  1428. error->iommu = -1;
  1429. #ifdef CONFIG_INTEL_IOMMU
  1430. error->iommu = intel_iommu_gfx_mapped;
  1431. #endif
  1432. error->reset_count = i915_reset_count(&dev_priv->gpu_error);
  1433. error->suspend_count = dev_priv->suspend_count;
  1434. memcpy(&error->device_info,
  1435. INTEL_INFO(dev_priv),
  1436. sizeof(error->device_info));
  1437. }
  1438. static __always_inline void dup_param(const char *type, void *x)
  1439. {
  1440. if (!__builtin_strcmp(type, "char *"))
  1441. *(void **)x = kstrdup(*(void **)x, GFP_ATOMIC);
  1442. }
  1443. static void capture_params(struct i915_gpu_state *error)
  1444. {
  1445. error->params = i915_modparams;
  1446. #define DUP(T, x, ...) dup_param(#T, &error->params.x);
  1447. I915_PARAMS_FOR_EACH(DUP);
  1448. #undef DUP
  1449. }
  1450. static int capture(void *data)
  1451. {
  1452. struct i915_gpu_state *error = data;
  1453. do_gettimeofday(&error->time);
  1454. error->boottime = ktime_to_timeval(ktime_get_boottime());
  1455. error->uptime =
  1456. ktime_to_timeval(ktime_sub(ktime_get(),
  1457. error->i915->gt.last_init_time));
  1458. capture_params(error);
  1459. capture_uc_state(error);
  1460. i915_capture_gen_state(error->i915, error);
  1461. i915_capture_reg_state(error->i915, error);
  1462. i915_gem_record_fences(error->i915, error);
  1463. i915_gem_record_rings(error->i915, error);
  1464. i915_capture_active_buffers(error->i915, error);
  1465. i915_capture_pinned_buffers(error->i915, error);
  1466. error->overlay = intel_overlay_capture_error_state(error->i915);
  1467. error->display = intel_display_capture_error_state(error->i915);
  1468. return 0;
  1469. }
  1470. #define DAY_AS_SECONDS(x) (24 * 60 * 60 * (x))
  1471. struct i915_gpu_state *
  1472. i915_capture_gpu_state(struct drm_i915_private *i915)
  1473. {
  1474. struct i915_gpu_state *error;
  1475. error = kzalloc(sizeof(*error), GFP_ATOMIC);
  1476. if (!error)
  1477. return NULL;
  1478. kref_init(&error->ref);
  1479. error->i915 = i915;
  1480. stop_machine(capture, error, NULL);
  1481. return error;
  1482. }
  1483. /**
  1484. * i915_capture_error_state - capture an error record for later analysis
  1485. * @dev: drm device
  1486. *
  1487. * Should be called when an error is detected (either a hang or an error
  1488. * interrupt) to capture error state from the time of the error. Fills
  1489. * out a structure which becomes available in debugfs for user level tools
  1490. * to pick up.
  1491. */
  1492. void i915_capture_error_state(struct drm_i915_private *dev_priv,
  1493. u32 engine_mask,
  1494. const char *error_msg)
  1495. {
  1496. static bool warned;
  1497. struct i915_gpu_state *error;
  1498. unsigned long flags;
  1499. if (!i915_modparams.error_capture)
  1500. return;
  1501. if (READ_ONCE(dev_priv->gpu_error.first_error))
  1502. return;
  1503. error = i915_capture_gpu_state(dev_priv);
  1504. if (!error) {
  1505. DRM_DEBUG_DRIVER("out of memory, not capturing error state\n");
  1506. return;
  1507. }
  1508. i915_error_capture_msg(dev_priv, error, engine_mask, error_msg);
  1509. DRM_INFO("%s\n", error->error_msg);
  1510. if (!error->simulated) {
  1511. spin_lock_irqsave(&dev_priv->gpu_error.lock, flags);
  1512. if (!dev_priv->gpu_error.first_error) {
  1513. dev_priv->gpu_error.first_error = error;
  1514. error = NULL;
  1515. }
  1516. spin_unlock_irqrestore(&dev_priv->gpu_error.lock, flags);
  1517. }
  1518. if (error) {
  1519. __i915_gpu_state_free(&error->ref);
  1520. return;
  1521. }
  1522. if (!warned &&
  1523. ktime_get_real_seconds() - DRIVER_TIMESTAMP < DAY_AS_SECONDS(180)) {
  1524. DRM_INFO("GPU hangs can indicate a bug anywhere in the entire gfx stack, including userspace.\n");
  1525. DRM_INFO("Please file a _new_ bug report on bugs.freedesktop.org against DRI -> DRM/Intel\n");
  1526. DRM_INFO("drm/i915 developers can then reassign to the right component if it's not a kernel issue.\n");
  1527. DRM_INFO("The gpu crash dump is required to analyze gpu hangs, so please always attach it.\n");
  1528. DRM_INFO("GPU crash dump saved to /sys/class/drm/card%d/error\n",
  1529. dev_priv->drm.primary->index);
  1530. warned = true;
  1531. }
  1532. }
  1533. struct i915_gpu_state *
  1534. i915_first_error_state(struct drm_i915_private *i915)
  1535. {
  1536. struct i915_gpu_state *error;
  1537. spin_lock_irq(&i915->gpu_error.lock);
  1538. error = i915->gpu_error.first_error;
  1539. if (error)
  1540. i915_gpu_state_get(error);
  1541. spin_unlock_irq(&i915->gpu_error.lock);
  1542. return error;
  1543. }
  1544. void i915_reset_error_state(struct drm_i915_private *i915)
  1545. {
  1546. struct i915_gpu_state *error;
  1547. spin_lock_irq(&i915->gpu_error.lock);
  1548. error = i915->gpu_error.first_error;
  1549. i915->gpu_error.first_error = NULL;
  1550. spin_unlock_irq(&i915->gpu_error.lock);
  1551. i915_gpu_state_put(error);
  1552. }