i915_gpu_error.c 35 KB

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